From 1311e997d405057e8352defd227f021c9fd41123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 30 Nov 2025 22:16:15 +0100 Subject: [PATCH] libc: add openbsd 7.8 headers This excludes all headers in /usr/include/dev because that directory is bonkers huge (18M). We can add these on an as-needed basis. --- .../aarch64-openbsd-none/arm64/_float.h | 96 + .../aarch64-openbsd-none/arm64/_types.h | 145 + .../aarch64-openbsd-none/arm64/acpiapm.h | 22 + .../aarch64-openbsd-none/arm64/apmvar.h | 127 + .../aarch64-openbsd-none/arm64/armreg.h | 973 +++ .../include/aarch64-openbsd-none/arm64/asm.h | 150 + .../aarch64-openbsd-none/arm64/atomic.h | 64 + .../aarch64-openbsd-none/arm64/bootconfig.h | 47 + .../include/aarch64-openbsd-none/arm64/bus.h | 536 ++ .../aarch64-openbsd-none/arm64/cdefs.h | 16 + .../include/aarch64-openbsd-none/arm64/conf.h | 61 + .../include/aarch64-openbsd-none/arm64/cpu.h | 360 + .../aarch64-openbsd-none/arm64/cpufunc.h | 56 + .../aarch64-openbsd-none/arm64/db_machdep.h | 80 + .../aarch64-openbsd-none/arm64/disklabel.h | 25 + .../aarch64-openbsd-none/arm64/efivar.h | 46 + .../include/aarch64-openbsd-none/arm64/elf.h | 121 + .../aarch64-openbsd-none/arm64/endian.h | 29 + .../include/aarch64-openbsd-none/arm64/exec.h | 33 + .../include/aarch64-openbsd-none/arm64/fdt.h | 59 + .../include/aarch64-openbsd-none/arm64/fenv.h | 95 + .../include/aarch64-openbsd-none/arm64/fpu.h | 29 + .../aarch64-openbsd-none/arm64/frame.h | 77 + .../aarch64-openbsd-none/arm64/hypervisor.h | 88 + .../include/aarch64-openbsd-none/arm64/ieee.h | 148 + .../aarch64-openbsd-none/arm64/ieeefp.h | 25 + .../include/aarch64-openbsd-none/arm64/intr.h | 226 + .../aarch64-openbsd-none/arm64/kcore.h | 15 + .../aarch64-openbsd-none/arm64/limits.h | 56 + .../arm64/loadfile_machdep.h | 53 + .../aarch64-openbsd-none/arm64/mplock.h | 10 + .../aarch64-openbsd-none/arm64/mutex.h | 3 + .../aarch64-openbsd-none/arm64/openpromio.h | 57 + .../aarch64-openbsd-none/arm64/param.h | 81 + .../include/aarch64-openbsd-none/arm64/pcb.h | 45 + .../aarch64-openbsd-none/arm64/pci_machdep.h | 145 + .../include/aarch64-openbsd-none/arm64/pmap.h | 143 + .../include/aarch64-openbsd-none/arm64/proc.h | 45 + .../aarch64-openbsd-none/arm64/profile.h | 68 + .../include/aarch64-openbsd-none/arm64/pte.h | 104 + .../aarch64-openbsd-none/arm64/ptrace.h | 27 + .../include/aarch64-openbsd-none/arm64/reg.h | 36 + .../aarch64-openbsd-none/arm64/reloc.h | 123 + .../aarch64-openbsd-none/arm64/setjmp.h | 83 + .../aarch64-openbsd-none/arm64/signal.h | 64 + .../aarch64-openbsd-none/arm64/simplebusvar.h | 37 + .../aarch64-openbsd-none/arm64/smbiosvar.h | 278 + .../aarch64-openbsd-none/arm64/spinlock.h | 25 + .../aarch64-openbsd-none/arm64/sysarch.h | 21 + .../include/aarch64-openbsd-none/arm64/tcb.h | 58 + .../aarch64-openbsd-none/arm64/timetc.h | 24 + .../aarch64-openbsd-none/arm64/vmmvar.h | 93 + .../aarch64-openbsd-none/arm64/vmparam.h | 108 + lib/libc/include/aarch64-openbsd-none/frame.h | 77 + .../aarch64-openbsd-none/machine/_float.h | 96 + .../aarch64-openbsd-none/machine/_types.h | 145 + .../aarch64-openbsd-none/machine/acpiapm.h | 22 + .../aarch64-openbsd-none/machine/apmvar.h | 127 + .../aarch64-openbsd-none/machine/armreg.h | 973 +++ .../aarch64-openbsd-none/machine/asm.h | 150 + .../aarch64-openbsd-none/machine/atomic.h | 64 + .../aarch64-openbsd-none/machine/bootconfig.h | 47 + .../aarch64-openbsd-none/machine/bus.h | 536 ++ .../aarch64-openbsd-none/machine/cdefs.h | 16 + .../aarch64-openbsd-none/machine/conf.h | 61 + .../aarch64-openbsd-none/machine/cpu.h | 360 + .../aarch64-openbsd-none/machine/cpufunc.h | 56 + .../aarch64-openbsd-none/machine/db_machdep.h | 80 + .../aarch64-openbsd-none/machine/disklabel.h | 25 + .../aarch64-openbsd-none/machine/efivar.h | 46 + .../aarch64-openbsd-none/machine/elf.h | 121 + .../aarch64-openbsd-none/machine/endian.h | 29 + .../aarch64-openbsd-none/machine/exec.h | 33 + .../aarch64-openbsd-none/machine/fdt.h | 59 + .../aarch64-openbsd-none/machine/fenv.h | 95 + .../aarch64-openbsd-none/machine/fpu.h | 29 + .../aarch64-openbsd-none/machine/frame.h | 77 + .../aarch64-openbsd-none/machine/hypervisor.h | 88 + .../aarch64-openbsd-none/machine/ieee.h | 148 + .../aarch64-openbsd-none/machine/ieeefp.h | 25 + .../aarch64-openbsd-none/machine/intr.h | 226 + .../aarch64-openbsd-none/machine/kcore.h | 15 + .../aarch64-openbsd-none/machine/limits.h | 56 + .../machine/loadfile_machdep.h | 53 + .../aarch64-openbsd-none/machine/mplock.h | 10 + .../aarch64-openbsd-none/machine/mutex.h | 3 + .../aarch64-openbsd-none/machine/openpromio.h | 57 + .../aarch64-openbsd-none/machine/param.h | 81 + .../aarch64-openbsd-none/machine/pcb.h | 45 + .../machine/pci_machdep.h | 145 + .../aarch64-openbsd-none/machine/pmap.h | 143 + .../aarch64-openbsd-none/machine/proc.h | 45 + .../aarch64-openbsd-none/machine/profile.h | 68 + .../aarch64-openbsd-none/machine/pte.h | 104 + .../aarch64-openbsd-none/machine/ptrace.h | 27 + .../aarch64-openbsd-none/machine/reg.h | 36 + .../aarch64-openbsd-none/machine/reloc.h | 123 + .../aarch64-openbsd-none/machine/setjmp.h | 83 + .../aarch64-openbsd-none/machine/signal.h | 64 + .../machine/simplebusvar.h | 37 + .../aarch64-openbsd-none/machine/smbiosvar.h | 278 + .../aarch64-openbsd-none/machine/spinlock.h | 25 + .../aarch64-openbsd-none/machine/sysarch.h | 21 + .../aarch64-openbsd-none/machine/tcb.h | 58 + .../aarch64-openbsd-none/machine/timetc.h | 24 + .../aarch64-openbsd-none/machine/vmmvar.h | 93 + .../aarch64-openbsd-none/machine/vmparam.h | 108 + .../include/arm-openbsd-eabi/arm/_float.h | 84 + .../include/arm-openbsd-eabi/arm/_types.h | 140 + .../include/arm-openbsd-eabi/arm/apmvar.h | 122 + .../include/arm-openbsd-eabi/arm/armreg.h | 392 + lib/libc/include/arm-openbsd-eabi/arm/asm.h | 97 + .../include/arm-openbsd-eabi/arm/atomic.h | 295 + lib/libc/include/arm-openbsd-eabi/arm/bus.h | 882 +++ lib/libc/include/arm-openbsd-eabi/arm/cdefs.h | 16 + lib/libc/include/arm-openbsd-eabi/arm/conf.h | 82 + lib/libc/include/arm-openbsd-eabi/arm/cpu.h | 338 + .../include/arm-openbsd-eabi/arm/cpuconf.h | 53 + .../include/arm-openbsd-eabi/arm/cpufunc.h | 339 + .../include/arm-openbsd-eabi/arm/db_machdep.h | 104 + .../include/arm-openbsd-eabi/arm/disklabel.h | 45 + lib/libc/include/arm-openbsd-eabi/arm/elf.h | 77 + .../include/arm-openbsd-eabi/arm/endian.h | 29 + lib/libc/include/arm-openbsd-eabi/arm/exec.h | 44 + lib/libc/include/arm-openbsd-eabi/arm/fdt.h | 59 + lib/libc/include/arm-openbsd-eabi/arm/fenv.h | 97 + lib/libc/include/arm-openbsd-eabi/arm/fiq.h | 69 + lib/libc/include/arm-openbsd-eabi/arm/frame.h | 297 + lib/libc/include/arm-openbsd-eabi/arm/ieee.h | 192 + .../include/arm-openbsd-eabi/arm/ieeefp.h | 41 + lib/libc/include/arm-openbsd-eabi/arm/kcore.h | 15 + .../include/arm-openbsd-eabi/arm/limits.h | 53 + .../include/arm-openbsd-eabi/arm/machdep.h | 20 + .../include/arm-openbsd-eabi/arm/mplock.h | 10 + lib/libc/include/arm-openbsd-eabi/arm/mutex.h | 3 + .../include/arm-openbsd-eabi/arm/openpromio.h | 57 + lib/libc/include/arm-openbsd-eabi/arm/param.h | 106 + lib/libc/include/arm-openbsd-eabi/arm/pcb.h | 91 + .../arm-openbsd-eabi/arm/pci_machdep.h | 109 + lib/libc/include/arm-openbsd-eabi/arm/pmap.h | 513 ++ lib/libc/include/arm-openbsd-eabi/arm/proc.h | 50 + .../include/arm-openbsd-eabi/arm/profile.h | 91 + lib/libc/include/arm-openbsd-eabi/arm/pte.h | 232 + .../include/arm-openbsd-eabi/arm/ptrace.h | 44 + lib/libc/include/arm-openbsd-eabi/arm/reg.h | 53 + lib/libc/include/arm-openbsd-eabi/arm/reloc.h | 53 + .../include/arm-openbsd-eabi/arm/setjmp.h | 67 + .../include/arm-openbsd-eabi/arm/signal.h | 93 + .../arm-openbsd-eabi/arm/simplebusvar.h | 37 + .../include/arm-openbsd-eabi/arm/spinlock.h | 10 + .../include/arm-openbsd-eabi/arm/sysarch.h | 62 + .../include/arm-openbsd-eabi/arm/sysreg.h | 272 + lib/libc/include/arm-openbsd-eabi/arm/tcb.h | 58 + lib/libc/include/arm-openbsd-eabi/arm/trap.h | 69 + .../include/arm-openbsd-eabi/arm/undefined.h | 87 + lib/libc/include/arm-openbsd-eabi/arm/vfp.h | 136 + .../include/arm-openbsd-eabi/arm/vmparam.h | 85 + .../include/arm-openbsd-eabi/armv7/_float.h | 3 + .../include/arm-openbsd-eabi/armv7/_types.h | 9 + .../include/arm-openbsd-eabi/armv7/apmvar.h | 2 + lib/libc/include/arm-openbsd-eabi/armv7/asm.h | 4 + .../include/arm-openbsd-eabi/armv7/atomic.h | 10 + .../arm-openbsd-eabi/armv7/bootconfig.h | 70 + lib/libc/include/arm-openbsd-eabi/armv7/bus.h | 4 + .../include/arm-openbsd-eabi/armv7/cdefs.h | 3 + .../include/arm-openbsd-eabi/armv7/conf.h | 10 + lib/libc/include/arm-openbsd-eabi/armv7/cpu.h | 4 + .../include/arm-openbsd-eabi/armv7/cpufunc.h | 16 + .../arm-openbsd-eabi/armv7/db_machdep.h | 4 + .../arm-openbsd-eabi/armv7/disklabel.h | 3 + lib/libc/include/arm-openbsd-eabi/armv7/elf.h | 3 + .../include/arm-openbsd-eabi/armv7/endian.h | 4 + .../include/arm-openbsd-eabi/armv7/exec.h | 3 + lib/libc/include/arm-openbsd-eabi/armv7/fdt.h | 3 + .../include/arm-openbsd-eabi/armv7/fenv.h | 3 + .../include/arm-openbsd-eabi/armv7/frame.h | 4 + .../include/arm-openbsd-eabi/armv7/ieee.h | 4 + .../include/arm-openbsd-eabi/armv7/ieeefp.h | 4 + .../include/arm-openbsd-eabi/armv7/intr.h | 229 + .../include/arm-openbsd-eabi/armv7/limits.h | 4 + .../arm-openbsd-eabi/armv7/loadfile_machdep.h | 53 + .../arm-openbsd-eabi/armv7/machine_reg.h | 57 + .../include/arm-openbsd-eabi/armv7/mplock.h | 3 + .../include/arm-openbsd-eabi/armv7/mutex.h | 3 + .../arm-openbsd-eabi/armv7/openpromio.h | 3 + .../include/arm-openbsd-eabi/armv7/param.h | 51 + lib/libc/include/arm-openbsd-eabi/armv7/pcb.h | 4 + .../arm-openbsd-eabi/armv7/pci_machdep.h | 3 + .../include/arm-openbsd-eabi/armv7/pmap.h | 4 + .../include/arm-openbsd-eabi/armv7/proc.h | 4 + .../include/arm-openbsd-eabi/armv7/profile.h | 4 + .../include/arm-openbsd-eabi/armv7/ptrace.h | 4 + lib/libc/include/arm-openbsd-eabi/armv7/reg.h | 4 + .../include/arm-openbsd-eabi/armv7/reloc.h | 2 + .../include/arm-openbsd-eabi/armv7/setjmp.h | 4 + .../include/arm-openbsd-eabi/armv7/signal.h | 4 + .../arm-openbsd-eabi/armv7/simplebusvar.h | 3 + .../include/arm-openbsd-eabi/armv7/spinlock.h | 3 + .../include/arm-openbsd-eabi/armv7/sysarch.h | 4 + lib/libc/include/arm-openbsd-eabi/armv7/tcb.h | 3 + .../include/arm-openbsd-eabi/armv7/timetc.h | 23 + .../include/arm-openbsd-eabi/armv7/trap.h | 4 + .../include/arm-openbsd-eabi/armv7/vmparam.h | 98 + lib/libc/include/arm-openbsd-eabi/frame.h | 4 + .../include/arm-openbsd-eabi/machine/_float.h | 3 + .../include/arm-openbsd-eabi/machine/_types.h | 9 + .../include/arm-openbsd-eabi/machine/apmvar.h | 2 + .../include/arm-openbsd-eabi/machine/asm.h | 4 + .../include/arm-openbsd-eabi/machine/atomic.h | 10 + .../arm-openbsd-eabi/machine/bootconfig.h | 70 + .../include/arm-openbsd-eabi/machine/bus.h | 4 + .../include/arm-openbsd-eabi/machine/cdefs.h | 3 + .../include/arm-openbsd-eabi/machine/conf.h | 10 + .../include/arm-openbsd-eabi/machine/cpu.h | 4 + .../arm-openbsd-eabi/machine/cpufunc.h | 16 + .../arm-openbsd-eabi/machine/db_machdep.h | 4 + .../arm-openbsd-eabi/machine/disklabel.h | 3 + .../include/arm-openbsd-eabi/machine/elf.h | 3 + .../include/arm-openbsd-eabi/machine/endian.h | 4 + .../include/arm-openbsd-eabi/machine/exec.h | 3 + .../include/arm-openbsd-eabi/machine/fdt.h | 3 + .../include/arm-openbsd-eabi/machine/fenv.h | 3 + .../include/arm-openbsd-eabi/machine/frame.h | 4 + .../include/arm-openbsd-eabi/machine/ieee.h | 4 + .../include/arm-openbsd-eabi/machine/ieeefp.h | 4 + .../include/arm-openbsd-eabi/machine/intr.h | 229 + .../include/arm-openbsd-eabi/machine/limits.h | 4 + .../machine/loadfile_machdep.h | 53 + .../arm-openbsd-eabi/machine/machine_reg.h | 57 + .../include/arm-openbsd-eabi/machine/mplock.h | 3 + .../include/arm-openbsd-eabi/machine/mutex.h | 3 + .../arm-openbsd-eabi/machine/openpromio.h | 3 + .../include/arm-openbsd-eabi/machine/param.h | 51 + .../include/arm-openbsd-eabi/machine/pcb.h | 4 + .../arm-openbsd-eabi/machine/pci_machdep.h | 3 + .../include/arm-openbsd-eabi/machine/pmap.h | 4 + .../include/arm-openbsd-eabi/machine/proc.h | 4 + .../arm-openbsd-eabi/machine/profile.h | 4 + .../include/arm-openbsd-eabi/machine/ptrace.h | 4 + .../include/arm-openbsd-eabi/machine/reg.h | 4 + .../include/arm-openbsd-eabi/machine/reloc.h | 2 + .../include/arm-openbsd-eabi/machine/setjmp.h | 4 + .../include/arm-openbsd-eabi/machine/signal.h | 4 + .../arm-openbsd-eabi/machine/simplebusvar.h | 3 + .../arm-openbsd-eabi/machine/spinlock.h | 3 + .../arm-openbsd-eabi/machine/sysarch.h | 4 + .../include/arm-openbsd-eabi/machine/tcb.h | 3 + .../include/arm-openbsd-eabi/machine/trap.h | 4 + .../arm-openbsd-eabi/machine/vmparam.h | 98 + lib/libc/include/generic-openbsd/a.out.h | 156 + lib/libc/include/generic-openbsd/ar.h | 66 + lib/libc/include/generic-openbsd/arpa/ftp.h | 108 + lib/libc/include/generic-openbsd/arpa/inet.h | 147 + .../include/generic-openbsd/arpa/nameser.h | 369 + .../include/generic-openbsd/arpa/telnet.h | 339 + lib/libc/include/generic-openbsd/arpa/tftp.h | 83 + lib/libc/include/generic-openbsd/asr.h | 90 + lib/libc/include/generic-openbsd/assert.h | 73 + lib/libc/include/generic-openbsd/ber.h | 153 + lib/libc/include/generic-openbsd/bitstring.h | 134 + lib/libc/include/generic-openbsd/blf.h | 79 + lib/libc/include/generic-openbsd/bsd_auth.h | 105 + lib/libc/include/generic-openbsd/complex.h | 120 + lib/libc/include/generic-openbsd/cpio.h | 59 + lib/libc/include/generic-openbsd/ctype.h | 309 + lib/libc/include/generic-openbsd/db.h | 161 + .../include/generic-openbsd/ddb/db_access.h | 40 + .../include/generic-openbsd/ddb/db_break.h | 61 + .../include/generic-openbsd/ddb/db_command.h | 62 + lib/libc/include/generic-openbsd/ddb/db_elf.h | 48 + .../include/generic-openbsd/ddb/db_extern.h | 64 + .../generic-openbsd/ddb/db_interface.h | 86 + lib/libc/include/generic-openbsd/ddb/db_lex.h | 66 + .../include/generic-openbsd/ddb/db_output.h | 65 + lib/libc/include/generic-openbsd/ddb/db_run.h | 66 + lib/libc/include/generic-openbsd/ddb/db_sym.h | 97 + lib/libc/include/generic-openbsd/ddb/db_var.h | 79 + .../generic-openbsd/ddb/db_variables.h | 62 + .../include/generic-openbsd/ddb/db_watch.h | 56 + lib/libc/include/generic-openbsd/dirent.h | 107 + lib/libc/include/generic-openbsd/dlfcn.h | 110 + lib/libc/include/generic-openbsd/elf.h | 12 + lib/libc/include/generic-openbsd/elf_abi.h | 33 + lib/libc/include/generic-openbsd/endian.h | 124 + lib/libc/include/generic-openbsd/err.h | 70 + lib/libc/include/generic-openbsd/errno.h | 59 + lib/libc/include/generic-openbsd/execinfo.h | 45 + lib/libc/include/generic-openbsd/fcntl.h | 231 + lib/libc/include/generic-openbsd/fenv.h | 60 + lib/libc/include/generic-openbsd/float.h | 95 + lib/libc/include/generic-openbsd/fnmatch.h | 57 + lib/libc/include/generic-openbsd/fstab.h | 78 + lib/libc/include/generic-openbsd/fts.h | 125 + lib/libc/include/generic-openbsd/ftw.h | 60 + lib/libc/include/generic-openbsd/getopt.h | 76 + lib/libc/include/generic-openbsd/glob.h | 103 + lib/libc/include/generic-openbsd/grp.h | 78 + lib/libc/include/generic-openbsd/icdb.h | 44 + lib/libc/include/generic-openbsd/ieeefp.h | 23 + lib/libc/include/generic-openbsd/ifaddrs.h | 56 + lib/libc/include/generic-openbsd/imsg.h | 175 + lib/libc/include/generic-openbsd/inttypes.h | 265 + lib/libc/include/generic-openbsd/iso646.h | 26 + .../isofs/cd9660/cd9660_extern.h | 109 + .../isofs/cd9660/cd9660_node.h | 130 + .../isofs/cd9660/cd9660_rrip.h | 139 + .../generic-openbsd/isofs/cd9660/iso.h | 282 + .../generic-openbsd/isofs/cd9660/iso_rrip.h | 82 + .../generic-openbsd/isofs/udf/ecma167-udf.h | 820 +++ .../include/generic-openbsd/isofs/udf/udf.h | 145 + .../generic-openbsd/isofs/udf/udf_extern.h | 69 + lib/libc/include/generic-openbsd/kvm.h | 79 + lib/libc/include/generic-openbsd/langinfo.h | 88 + lib/libc/include/generic-openbsd/libgen.h | 29 + lib/libc/include/generic-openbsd/limits.h | 117 + lib/libc/include/generic-openbsd/link.h | 148 + lib/libc/include/generic-openbsd/link_elf.h | 42 + lib/libc/include/generic-openbsd/locale.h | 112 + lib/libc/include/generic-openbsd/login_cap.h | 111 + .../include/generic-openbsd/machine/_float.h | 3 + .../include/generic-openbsd/machine/cdefs.h | 3 + .../generic-openbsd/machine/disklabel.h | 16 + .../include/generic-openbsd/machine/elf.h | 7 + .../include/generic-openbsd/machine/fenv.h | 3 + .../machine/loadfile_machdep.h | 49 + .../include/generic-openbsd/machine/mplock.h | 10 + .../include/generic-openbsd/machine/reloc.h | 5 + .../generic-openbsd/machine/smbiosvar.h | 281 + .../generic-openbsd/machine/spinlock.h | 10 + .../include/generic-openbsd/machine/tcb.h | 3 + .../include/generic-openbsd/machine/timetc.h | 23 + lib/libc/include/generic-openbsd/math.h | 497 ++ lib/libc/include/generic-openbsd/md5.h | 49 + lib/libc/include/generic-openbsd/memory.h | 35 + .../include/generic-openbsd/mips64/_float.h | 71 + .../include/generic-openbsd/mips64/_types.h | 154 + .../include/generic-openbsd/mips64/archtype.h | 77 + lib/libc/include/generic-openbsd/mips64/asm.h | 360 + .../include/generic-openbsd/mips64/atomic.h | 214 + .../include/generic-openbsd/mips64/autoconf.h | 37 + .../include/generic-openbsd/mips64/cache.h | 107 + .../include/generic-openbsd/mips64/cdefs.h | 43 + lib/libc/include/generic-openbsd/mips64/cpu.h | 552 ++ .../include/generic-openbsd/mips64/cpustate.h | 150 + .../generic-openbsd/mips64/db_machdep.h | 76 + lib/libc/include/generic-openbsd/mips64/elf.h | 7 + .../include/generic-openbsd/mips64/endian.h | 49 + .../include/generic-openbsd/mips64/exec.h | 137 + .../include/generic-openbsd/mips64/fenv.h | 94 + lib/libc/include/generic-openbsd/mips64/fpu.h | 73 + .../include/generic-openbsd/mips64/frame.h | 114 + .../include/generic-openbsd/mips64/ieee.h | 169 + .../include/generic-openbsd/mips64/ieeefp.h | 46 + .../include/generic-openbsd/mips64/kcore.h | 40 + .../include/generic-openbsd/mips64/limits.h | 53 + .../generic-openbsd/mips64/loongson2.h | 65 + .../generic-openbsd/mips64/loongson3.h | 108 + .../include/generic-openbsd/mips64/memconf.h | 48 + .../include/generic-openbsd/mips64/mips_cpu.h | 282 + .../generic-openbsd/mips64/mips_opcode.h | 347 + .../include/generic-openbsd/mips64/mplock.h | 10 + .../include/generic-openbsd/mips64/mutex.h | 3 + .../include/generic-openbsd/mips64/param.h | 82 + lib/libc/include/generic-openbsd/mips64/pcb.h | 58 + .../include/generic-openbsd/mips64/pmap.h | 228 + .../include/generic-openbsd/mips64/proc.h | 75 + .../include/generic-openbsd/mips64/profile.h | 85 + lib/libc/include/generic-openbsd/mips64/pte.h | 160 + .../include/generic-openbsd/mips64/ptrace.h | 46 + lib/libc/include/generic-openbsd/mips64/reg.h | 54 + .../include/generic-openbsd/mips64/regdef.h | 77 + .../include/generic-openbsd/mips64/regnum.h | 119 + .../include/generic-openbsd/mips64/reloc.h | 54 + .../include/generic-openbsd/mips64/setjmp.h | 15 + .../include/generic-openbsd/mips64/signal.h | 70 + .../include/generic-openbsd/mips64/spinlock.h | 11 + .../include/generic-openbsd/mips64/sysarch.h | 52 + lib/libc/include/generic-openbsd/mips64/tcb.h | 66 + .../include/generic-openbsd/mips64/timetc.h | 23 + .../include/generic-openbsd/mips64/trap.h | 127 + .../include/generic-openbsd/mips64/vmparam.h | 115 + .../generic-openbsd/miscfs/fifofs/fifo.h | 54 + .../generic-openbsd/miscfs/fuse/fusefs.h | 85 + .../generic-openbsd/miscfs/fuse/fusefs_node.h | 70 + .../generic-openbsd/msdosfs/bootsect.h | 97 + .../include/generic-openbsd/msdosfs/bpb.h | 187 + .../include/generic-openbsd/msdosfs/denode.h | 309 + .../generic-openbsd/msdosfs/direntry.h | 134 + .../include/generic-openbsd/msdosfs/fat.h | 105 + .../generic-openbsd/msdosfs/msdosfsmount.h | 211 + lib/libc/include/generic-openbsd/ndbm.h | 78 + lib/libc/include/generic-openbsd/net/art.h | 169 + lib/libc/include/generic-openbsd/net/bfd.h | 163 + lib/libc/include/generic-openbsd/net/bpf.h | 342 + .../include/generic-openbsd/net/bpfdesc.h | 128 + .../include/generic-openbsd/net/ethertypes.h | 325 + .../include/generic-openbsd/net/fq_codel.h | 51 + lib/libc/include/generic-openbsd/net/frame.h | 47 + lib/libc/include/generic-openbsd/net/hfsc.h | 122 + lib/libc/include/generic-openbsd/net/if.h | 576 ++ lib/libc/include/generic-openbsd/net/if_arp.h | 74 + lib/libc/include/generic-openbsd/net/if_bpe.h | 26 + .../include/generic-openbsd/net/if_bridge.h | 533 ++ lib/libc/include/generic-openbsd/net/if_dl.h | 101 + lib/libc/include/generic-openbsd/net/if_enc.h | 42 + .../generic-openbsd/net/if_etherbridge.h | 102 + .../include/generic-openbsd/net/if_etherip.h | 29 + lib/libc/include/generic-openbsd/net/if_gif.h | 43 + lib/libc/include/generic-openbsd/net/if_gre.h | 121 + lib/libc/include/generic-openbsd/net/if_llc.h | 145 + .../include/generic-openbsd/net/if_media.h | 972 +++ .../include/generic-openbsd/net/if_pflog.h | 72 + .../include/generic-openbsd/net/if_pflow.h | 285 + .../include/generic-openbsd/net/if_pfsync.h | 338 + lib/libc/include/generic-openbsd/net/if_ppp.h | 154 + .../include/generic-openbsd/net/if_pppoe.h | 75 + .../include/generic-openbsd/net/if_pppvar.h | 178 + lib/libc/include/generic-openbsd/net/if_sec.h | 44 + .../include/generic-openbsd/net/if_sppp.h | 245 + .../include/generic-openbsd/net/if_trunk.h | 255 + lib/libc/include/generic-openbsd/net/if_tun.h | 122 + .../include/generic-openbsd/net/if_types.h | 274 + lib/libc/include/generic-openbsd/net/if_var.h | 406 ++ .../include/generic-openbsd/net/if_vlan_var.h | 55 + lib/libc/include/generic-openbsd/net/if_wg.h | 109 + lib/libc/include/generic-openbsd/net/ifq.h | 507 ++ lib/libc/include/generic-openbsd/net/lldp.h | 67 + lib/libc/include/generic-openbsd/net/netisr.h | 78 + lib/libc/include/generic-openbsd/net/ofp.h | 897 +++ .../include/generic-openbsd/net/pfkeyv2.h | 473 ++ lib/libc/include/generic-openbsd/net/pfvar.h | 1883 +++++ .../include/generic-openbsd/net/pfvar_priv.h | 434 ++ lib/libc/include/generic-openbsd/net/pipex.h | 210 + .../include/generic-openbsd/net/pipex_local.h | 478 ++ .../include/generic-openbsd/net/ppp-comp.h | 173 + .../include/generic-openbsd/net/ppp_defs.h | 170 + lib/libc/include/generic-openbsd/net/radix.h | 112 + lib/libc/include/generic-openbsd/net/route.h | 525 ++ lib/libc/include/generic-openbsd/net/rtable.h | 82 + .../include/generic-openbsd/net/slcompress.h | 167 + .../include/generic-openbsd/net/toeplitz.h | 143 + .../include/generic-openbsd/net/trunklacp.h | 316 + .../include/generic-openbsd/net/wg_cookie.h | 132 + .../include/generic-openbsd/net/wg_noise.h | 197 + .../generic-openbsd/net80211/ieee80211.h | 1117 +++ .../generic-openbsd/net80211/ieee80211_amrr.h | 58 + .../net80211/ieee80211_crypto.h | 194 + .../net80211/ieee80211_ioctl.h | 429 ++ .../generic-openbsd/net80211/ieee80211_node.h | 676 ++ .../generic-openbsd/net80211/ieee80211_priv.h | 135 + .../net80211/ieee80211_proto.h | 189 + .../generic-openbsd/net80211/ieee80211_ra.h | 82 + .../net80211/ieee80211_ra_vht.h | 91 + .../net80211/ieee80211_radiotap.h | 215 + .../net80211/ieee80211_regdomain.h | 768 ++ .../net80211/ieee80211_rssadapt.h | 103 + .../generic-openbsd/net80211/ieee80211_var.h | 511 ++ lib/libc/include/generic-openbsd/netdb.h | 329 + lib/libc/include/generic-openbsd/netgroup.h | 62 + .../include/generic-openbsd/netinet/icmp6.h | 608 ++ .../generic-openbsd/netinet/icmp_var.h | 111 + .../generic-openbsd/netinet/if_ether.h | 398 ++ .../include/generic-openbsd/netinet/igmp.h | 97 + .../generic-openbsd/netinet/igmp_var.h | 116 + lib/libc/include/generic-openbsd/netinet/in.h | 833 +++ .../include/generic-openbsd/netinet/in_pcb.h | 383 + .../generic-openbsd/netinet/in_systm.h | 47 + .../include/generic-openbsd/netinet/in_var.h | 166 + lib/libc/include/generic-openbsd/netinet/ip.h | 233 + .../include/generic-openbsd/netinet/ip6.h | 293 + .../include/generic-openbsd/netinet/ip_ah.h | 134 + .../include/generic-openbsd/netinet/ip_carp.h | 228 + .../generic-openbsd/netinet/ip_divert.h | 93 + .../include/generic-openbsd/netinet/ip_ecn.h | 52 + .../include/generic-openbsd/netinet/ip_esp.h | 141 + .../generic-openbsd/netinet/ip_ether.h | 111 + .../include/generic-openbsd/netinet/ip_gre.h | 62 + .../include/generic-openbsd/netinet/ip_icmp.h | 246 + .../generic-openbsd/netinet/ip_ipcomp.h | 126 + .../include/generic-openbsd/netinet/ip_ipip.h | 124 + .../include/generic-openbsd/netinet/ip_ipsp.h | 737 ++ .../generic-openbsd/netinet/ip_mroute.h | 261 + .../include/generic-openbsd/netinet/ip_var.h | 289 + .../include/generic-openbsd/netinet/tcp.h | 222 + .../generic-openbsd/netinet/tcp_debug.h | 106 + .../include/generic-openbsd/netinet/tcp_fsm.h | 85 + .../include/generic-openbsd/netinet/tcp_seq.h | 66 + .../generic-openbsd/netinet/tcp_timer.h | 168 + .../include/generic-openbsd/netinet/tcp_var.h | 814 +++ .../include/generic-openbsd/netinet/udp.h | 49 + .../include/generic-openbsd/netinet/udp_var.h | 155 + .../include/generic-openbsd/netinet6/in6.h | 685 ++ .../generic-openbsd/netinet6/in6_ifattach.h | 42 + .../generic-openbsd/netinet6/in6_var.h | 372 + .../generic-openbsd/netinet6/ip6_mroute.h | 265 + .../generic-openbsd/netinet6/ip6_var.h | 380 + .../generic-openbsd/netinet6/ip6protosw.h | 112 + .../include/generic-openbsd/netinet6/mld6.h | 113 + .../generic-openbsd/netinet6/mld6_var.h | 53 + .../include/generic-openbsd/netinet6/nd6.h | 159 + .../generic-openbsd/netinet6/raw_ip6.h | 86 + .../include/generic-openbsd/netmpls/mpls.h | 166 + lib/libc/include/generic-openbsd/nfs/krpc.h | 28 + lib/libc/include/generic-openbsd/nfs/nfs.h | 317 + .../include/generic-openbsd/nfs/nfs_var.h | 202 + .../include/generic-openbsd/nfs/nfsdiskless.h | 68 + .../include/generic-openbsd/nfs/nfsm_subs.h | 185 + .../include/generic-openbsd/nfs/nfsmount.h | 94 + .../include/generic-openbsd/nfs/nfsnode.h | 141 + .../include/generic-openbsd/nfs/nfsproto.h | 415 ++ .../include/generic-openbsd/nfs/nfsrvcache.h | 81 + lib/libc/include/generic-openbsd/nfs/rpcv2.h | 101 + .../include/generic-openbsd/nfs/xdr_subs.h | 86 + lib/libc/include/generic-openbsd/nl_types.h | 91 + lib/libc/include/generic-openbsd/nlist.h | 87 + lib/libc/include/generic-openbsd/ntfs/ntfs.h | 315 + .../include/generic-openbsd/ntfs/ntfs_compr.h | 36 + .../include/generic-openbsd/ntfs/ntfs_ihash.h | 35 + .../include/generic-openbsd/ntfs/ntfs_inode.h | 98 + .../include/generic-openbsd/ntfs/ntfs_subr.h | 104 + .../generic-openbsd/ntfs/ntfs_vfsops.h | 40 + .../include/generic-openbsd/ntfs/ntfsmount.h | 33 + lib/libc/include/generic-openbsd/ohash.h | 74 + lib/libc/include/generic-openbsd/paths.h | 81 + lib/libc/include/generic-openbsd/poll.h | 9 + .../generic-openbsd/protocols/dumprestore.h | 159 + .../generic-openbsd/protocols/routed.h | 152 + .../include/generic-openbsd/protocols/rwhod.h | 67 + .../include/generic-openbsd/protocols/talkd.h | 120 + .../include/generic-openbsd/protocols/timed.h | 101 + lib/libc/include/generic-openbsd/pthread.h | 315 + lib/libc/include/generic-openbsd/pthread_np.h | 56 + lib/libc/include/generic-openbsd/pwd.h | 119 + lib/libc/include/generic-openbsd/radius.h | 572 ++ lib/libc/include/generic-openbsd/ranlib.h | 49 + .../include/generic-openbsd/readpassphrase.h | 40 + lib/libc/include/generic-openbsd/regex.h | 104 + lib/libc/include/generic-openbsd/resolv.h | 314 + lib/libc/include/generic-openbsd/rmd160.h | 60 + lib/libc/include/generic-openbsd/rpc/auth.h | 184 + .../include/generic-openbsd/rpc/auth_unix.h | 84 + lib/libc/include/generic-openbsd/rpc/clnt.h | 362 + .../include/generic-openbsd/rpc/pmap_clnt.h | 85 + .../include/generic-openbsd/rpc/pmap_prot.h | 106 + .../include/generic-openbsd/rpc/pmap_rmt.h | 65 + lib/libc/include/generic-openbsd/rpc/rpc.h | 108 + .../include/generic-openbsd/rpc/rpc_des.h | 134 + .../include/generic-openbsd/rpc/rpc_msg.h | 200 + lib/libc/include/generic-openbsd/rpc/svc.h | 326 + .../include/generic-openbsd/rpc/svc_auth.h | 1 + lib/libc/include/generic-openbsd/rpc/types.h | 66 + lib/libc/include/generic-openbsd/rpc/xdr.h | 316 + lib/libc/include/generic-openbsd/sched.h | 75 + lib/libc/include/generic-openbsd/scsi/cd.h | 273 + lib/libc/include/generic-openbsd/scsi/iscsi.h | 570 ++ .../include/generic-openbsd/scsi/mpathvar.h | 59 + lib/libc/include/generic-openbsd/scsi/safte.h | 171 + .../include/generic-openbsd/scsi/scsi_all.h | 663 ++ .../generic-openbsd/scsi/scsi_changer.h | 419 ++ .../include/generic-openbsd/scsi/scsi_debug.h | 76 + .../include/generic-openbsd/scsi/scsi_disk.h | 496 ++ .../generic-openbsd/scsi/scsi_message.h | 67 + .../include/generic-openbsd/scsi/scsi_tape.h | 240 + .../include/generic-openbsd/scsi/scsiconf.h | 579 ++ lib/libc/include/generic-openbsd/scsi/sdvar.h | 77 + lib/libc/include/generic-openbsd/scsi/ses.h | 235 + lib/libc/include/generic-openbsd/search.h | 57 + lib/libc/include/generic-openbsd/semaphore.h | 62 + lib/libc/include/generic-openbsd/setjmp.h | 67 + lib/libc/include/generic-openbsd/sha1.h | 57 + lib/libc/include/generic-openbsd/sha2.h | 156 + lib/libc/include/generic-openbsd/signal.h | 140 + lib/libc/include/generic-openbsd/siphash.h | 86 + lib/libc/include/generic-openbsd/sndio.h | 216 + lib/libc/include/generic-openbsd/soundcard.h | 317 + lib/libc/include/generic-openbsd/spawn.h | 103 + lib/libc/include/generic-openbsd/stdarg.h | 45 + lib/libc/include/generic-openbsd/stdbool.h | 45 + lib/libc/include/generic-openbsd/stddef.h | 84 + lib/libc/include/generic-openbsd/stdint.h | 231 + lib/libc/include/generic-openbsd/stdio.h | 308 + lib/libc/include/generic-openbsd/stdio_ext.h | 31 + lib/libc/include/generic-openbsd/stdlib.h | 324 + lib/libc/include/generic-openbsd/string.h | 141 + lib/libc/include/generic-openbsd/strings.h | 83 + .../include/generic-openbsd/sys/_endian.h | 179 + lib/libc/include/generic-openbsd/sys/_lock.h | 71 + lib/libc/include/generic-openbsd/sys/_null.h | 18 + lib/libc/include/generic-openbsd/sys/_time.h | 85 + lib/libc/include/generic-openbsd/sys/_types.h | 77 + lib/libc/include/generic-openbsd/sys/acct.h | 83 + lib/libc/include/generic-openbsd/sys/ataio.h | 48 + lib/libc/include/generic-openbsd/sys/atomic.h | 293 + .../include/generic-openbsd/sys/audioio.h | 231 + lib/libc/include/generic-openbsd/sys/auxv.h | 50 + lib/libc/include/generic-openbsd/sys/blist.h | 137 + lib/libc/include/generic-openbsd/sys/buf.h | 303 + lib/libc/include/generic-openbsd/sys/cdefs.h | 434 ++ lib/libc/include/generic-openbsd/sys/cdio.h | 435 ++ lib/libc/include/generic-openbsd/sys/chio.h | 177 + .../include/generic-openbsd/sys/clockintr.h | 144 + lib/libc/include/generic-openbsd/sys/conf.h | 620 ++ lib/libc/include/generic-openbsd/sys/core.h | 99 + lib/libc/include/generic-openbsd/sys/ctf.h | 186 + lib/libc/include/generic-openbsd/sys/device.h | 245 + lib/libc/include/generic-openbsd/sys/dir.h | 65 + lib/libc/include/generic-openbsd/sys/dirent.h | 100 + lib/libc/include/generic-openbsd/sys/disk.h | 158 + .../include/generic-openbsd/sys/disklabel.h | 482 ++ lib/libc/include/generic-openbsd/sys/dkio.h | 86 + lib/libc/include/generic-openbsd/sys/domain.h | 74 + lib/libc/include/generic-openbsd/sys/endian.h | 124 + lib/libc/include/generic-openbsd/sys/errno.h | 182 + .../include/generic-openbsd/sys/evcount.h | 56 + lib/libc/include/generic-openbsd/sys/event.h | 395 + .../include/generic-openbsd/sys/eventvar.h | 74 + lib/libc/include/generic-openbsd/sys/exec.h | 246 + .../include/generic-openbsd/sys/exec_elf.h | 843 +++ .../include/generic-openbsd/sys/exec_script.h | 43 + lib/libc/include/generic-openbsd/sys/extent.h | 132 + lib/libc/include/generic-openbsd/sys/fcntl.h | 231 + lib/libc/include/generic-openbsd/sys/file.h | 139 + .../include/generic-openbsd/sys/filedesc.h | 159 + lib/libc/include/generic-openbsd/sys/filio.h | 54 + .../include/generic-openbsd/sys/fusebuf.h | 148 + lib/libc/include/generic-openbsd/sys/futex.h | 45 + lib/libc/include/generic-openbsd/sys/gmon.h | 182 + lib/libc/include/generic-openbsd/sys/gpio.h | 80 + .../include/generic-openbsd/sys/hibernate.h | 162 + .../include/generic-openbsd/sys/hotplug.h | 40 + .../include/generic-openbsd/sys/intrmap.h | 33 + lib/libc/include/generic-openbsd/sys/ioccom.h | 68 + lib/libc/include/generic-openbsd/sys/ioctl.h | 55 + lib/libc/include/generic-openbsd/sys/ipc.h | 95 + lib/libc/include/generic-openbsd/sys/kcore.h | 60 + lib/libc/include/generic-openbsd/sys/kcov.h | 55 + lib/libc/include/generic-openbsd/sys/kernel.h | 61 + lib/libc/include/generic-openbsd/sys/kstat.h | 211 + .../include/generic-openbsd/sys/kthread.h | 50 + lib/libc/include/generic-openbsd/sys/ktrace.h | 277 + lib/libc/include/generic-openbsd/sys/limits.h | 125 + lib/libc/include/generic-openbsd/sys/lock.h | 55 + lib/libc/include/generic-openbsd/sys/lockf.h | 45 + lib/libc/include/generic-openbsd/sys/malloc.h | 399 ++ lib/libc/include/generic-openbsd/sys/mbuf.h | 571 ++ .../include/generic-openbsd/sys/memrange.h | 96 + lib/libc/include/generic-openbsd/sys/mman.h | 166 + lib/libc/include/generic-openbsd/sys/mount.h | 639 ++ lib/libc/include/generic-openbsd/sys/mplock.h | 74 + lib/libc/include/generic-openbsd/sys/msg.h | 146 + lib/libc/include/generic-openbsd/sys/msgbuf.h | 58 + lib/libc/include/generic-openbsd/sys/mtio.h | 147 + lib/libc/include/generic-openbsd/sys/mutex.h | 168 + lib/libc/include/generic-openbsd/sys/namei.h | 274 + lib/libc/include/generic-openbsd/sys/param.h | 223 + lib/libc/include/generic-openbsd/sys/pciio.h | 86 + lib/libc/include/generic-openbsd/sys/pclock.h | 49 + lib/libc/include/generic-openbsd/sys/percpu.h | 199 + lib/libc/include/generic-openbsd/sys/pipe.h | 98 + lib/libc/include/generic-openbsd/sys/pledge.h | 143 + lib/libc/include/generic-openbsd/sys/poll.h | 89 + lib/libc/include/generic-openbsd/sys/pool.h | 287 + lib/libc/include/generic-openbsd/sys/proc.h | 678 ++ .../include/generic-openbsd/sys/protosw.h | 407 ++ lib/libc/include/generic-openbsd/sys/ptrace.h | 137 + lib/libc/include/generic-openbsd/sys/queue.h | 633 ++ .../include/generic-openbsd/sys/radioio.h | 76 + lib/libc/include/generic-openbsd/sys/reboot.h | 109 + lib/libc/include/generic-openbsd/sys/refcnt.h | 59 + .../include/generic-openbsd/sys/resource.h | 128 + .../include/generic-openbsd/sys/resourcevar.h | 114 + lib/libc/include/generic-openbsd/sys/rwlock.h | 251 + lib/libc/include/generic-openbsd/sys/sched.h | 216 + lib/libc/include/generic-openbsd/sys/scsiio.h | 74 + lib/libc/include/generic-openbsd/sys/select.h | 137 + .../include/generic-openbsd/sys/selinfo.h | 51 + lib/libc/include/generic-openbsd/sys/sem.h | 192 + .../include/generic-openbsd/sys/sensors.h | 179 + lib/libc/include/generic-openbsd/sys/shm.h | 150 + .../include/generic-openbsd/sys/siginfo.h | 200 + lib/libc/include/generic-openbsd/sys/sigio.h | 95 + lib/libc/include/generic-openbsd/sys/signal.h | 202 + .../include/generic-openbsd/sys/signalvar.h | 140 + lib/libc/include/generic-openbsd/sys/smr.h | 440 ++ lib/libc/include/generic-openbsd/sys/socket.h | 617 ++ .../include/generic-openbsd/sys/socketvar.h | 443 ++ lib/libc/include/generic-openbsd/sys/sockio.h | 223 + .../include/generic-openbsd/sys/softintr.h | 41 + .../include/generic-openbsd/sys/specdev.h | 111 + lib/libc/include/generic-openbsd/sys/srp.h | 196 + .../include/generic-openbsd/sys/stacktrace.h | 41 + lib/libc/include/generic-openbsd/sys/stat.h | 222 + .../include/generic-openbsd/sys/statvfs.h | 48 + lib/libc/include/generic-openbsd/sys/stdarg.h | 45 + lib/libc/include/generic-openbsd/sys/stdint.h | 231 + lib/libc/include/generic-openbsd/sys/swap.h | 62 + .../include/generic-openbsd/sys/syscall.h | 728 ++ .../include/generic-openbsd/sys/syscall_mi.h | 259 + .../include/generic-openbsd/sys/syscallargs.h | 1419 ++++ lib/libc/include/generic-openbsd/sys/sysctl.h | 1100 +++ .../include/generic-openbsd/sys/syslimits.h | 83 + lib/libc/include/generic-openbsd/sys/syslog.h | 220 + lib/libc/include/generic-openbsd/sys/systm.h | 449 ++ lib/libc/include/generic-openbsd/sys/task.h | 62 + .../include/generic-openbsd/sys/termios.h | 304 + lib/libc/include/generic-openbsd/sys/time.h | 473 ++ .../include/generic-openbsd/sys/timeout.h | 126 + lib/libc/include/generic-openbsd/sys/times.h | 63 + lib/libc/include/generic-openbsd/sys/timetc.h | 124 + .../include/generic-openbsd/sys/tprintf.h | 41 + .../include/generic-openbsd/sys/tracepoint.h | 38 + lib/libc/include/generic-openbsd/sys/tree.h | 1004 +++ lib/libc/include/generic-openbsd/sys/tty.h | 332 + lib/libc/include/generic-openbsd/sys/ttycom.h | 151 + .../include/generic-openbsd/sys/ttydefaults.h | 95 + lib/libc/include/generic-openbsd/sys/types.h | 260 + lib/libc/include/generic-openbsd/sys/ucred.h | 85 + lib/libc/include/generic-openbsd/sys/uio.h | 107 + lib/libc/include/generic-openbsd/sys/un.h | 65 + lib/libc/include/generic-openbsd/sys/unistd.h | 106 + lib/libc/include/generic-openbsd/sys/unpcb.h | 145 + lib/libc/include/generic-openbsd/sys/user.h | 48 + .../include/generic-openbsd/sys/utsname.h | 59 + lib/libc/include/generic-openbsd/sys/uuid.h | 71 + .../include/generic-openbsd/sys/varargs.h | 51 + .../include/generic-openbsd/sys/videoio.h | 6328 +++++++++++++++++ .../include/generic-openbsd/sys/vmmeter.h | 97 + lib/libc/include/generic-openbsd/sys/vnode.h | 650 ++ lib/libc/include/generic-openbsd/sys/wait.h | 120 + .../include/generic-openbsd/sys/witness.h | 165 + lib/libc/include/generic-openbsd/sys/xcall.h | 84 + lib/libc/include/generic-openbsd/sysexits.h | 119 + lib/libc/include/generic-openbsd/syslog.h | 220 + lib/libc/include/generic-openbsd/tar.h | 66 + lib/libc/include/generic-openbsd/termios.h | 304 + lib/libc/include/generic-openbsd/tgmath.h | 169 + lib/libc/include/generic-openbsd/tib.h | 264 + lib/libc/include/generic-openbsd/time.h | 178 + lib/libc/include/generic-openbsd/ttyent.h | 73 + lib/libc/include/generic-openbsd/uchar.h | 40 + .../generic-openbsd/ufs/ext2fs/ext2fs.h | 449 ++ .../ufs/ext2fs/ext2fs_dinode.h | 166 + .../generic-openbsd/ufs/ext2fs/ext2fs_dir.h | 170 + .../ufs/ext2fs/ext2fs_extents.h | 99 + .../ufs/ext2fs/ext2fs_extern.h | 146 + .../generic-openbsd/ufs/ffs/ffs_extern.h | 170 + lib/libc/include/generic-openbsd/ufs/ffs/fs.h | 591 ++ .../generic-openbsd/ufs/mfs/mfs_extern.h | 63 + .../include/generic-openbsd/ufs/mfs/mfsnode.h | 53 + .../include/generic-openbsd/ufs/ufs/dinode.h | 156 + .../include/generic-openbsd/ufs/ufs/dir.h | 134 + .../include/generic-openbsd/ufs/ufs/dirhash.h | 132 + .../include/generic-openbsd/ufs/ufs/inode.h | 344 + .../include/generic-openbsd/ufs/ufs/quota.h | 149 + .../generic-openbsd/ufs/ufs/ufs_extern.h | 132 + .../generic-openbsd/ufs/ufs/ufsmount.h | 94 + lib/libc/include/generic-openbsd/unistd.h | 541 ++ lib/libc/include/generic-openbsd/usbhid.h | 100 + lib/libc/include/generic-openbsd/util.h | 129 + lib/libc/include/generic-openbsd/utime.h | 55 + lib/libc/include/generic-openbsd/utmp.h | 69 + lib/libc/include/generic-openbsd/uuid.h | 69 + lib/libc/include/generic-openbsd/uvm/uvm.h | 143 + .../include/generic-openbsd/uvm/uvm_addr.h | 115 + .../include/generic-openbsd/uvm/uvm_amap.h | 265 + .../include/generic-openbsd/uvm/uvm_anon.h | 103 + .../include/generic-openbsd/uvm/uvm_aobj.h | 77 + .../include/generic-openbsd/uvm/uvm_ddb.h | 46 + .../include/generic-openbsd/uvm/uvm_device.h | 71 + .../include/generic-openbsd/uvm/uvm_extern.h | 456 ++ .../include/generic-openbsd/uvm/uvm_fault.h | 83 + .../include/generic-openbsd/uvm/uvm_glue.h | 44 + lib/libc/include/generic-openbsd/uvm/uvm_km.h | 82 + .../include/generic-openbsd/uvm/uvm_map.h | 434 ++ .../include/generic-openbsd/uvm/uvm_object.h | 126 + .../include/generic-openbsd/uvm/uvm_page.h | 301 + .../include/generic-openbsd/uvm/uvm_pager.h | 173 + .../include/generic-openbsd/uvm/uvm_param.h | 91 + .../include/generic-openbsd/uvm/uvm_percpu.h | 48 + .../include/generic-openbsd/uvm/uvm_pmap.h | 195 + .../generic-openbsd/uvm/uvm_pmemrange.h | 165 + .../include/generic-openbsd/uvm/uvm_swap.h | 58 + .../generic-openbsd/uvm/uvm_swap_encrypt.h | 85 + .../include/generic-openbsd/uvm/uvm_vnode.h | 100 + lib/libc/include/generic-openbsd/uvm/uvmexp.h | 203 + lib/libc/include/generic-openbsd/varargs.h | 51 + lib/libc/include/generic-openbsd/vis.h | 93 + lib/libc/include/generic-openbsd/wchar.h | 253 + lib/libc/include/generic-openbsd/wctype.h | 107 + lib/libc/include/mips64-openbsd-none/frame.h | 3 + .../mips64-openbsd-none/machine/_types.h | 3 + .../include/mips64-openbsd-none/machine/asm.h | 9 + .../mips64-openbsd-none/machine/atomic.h | 45 + .../mips64-openbsd-none/machine/autoconf.h | 58 + .../include/mips64-openbsd-none/machine/bus.h | 510 ++ .../mips64-openbsd-none/machine/conf.h | 55 + .../include/mips64-openbsd-none/machine/cpu.h | 106 + .../mips64-openbsd-none/machine/cpustate.h | 3 + .../mips64-openbsd-none/machine/db_machdep.h | 3 + .../include/mips64-openbsd-none/machine/elf.h | 3 + .../mips64-openbsd-none/machine/endian.h | 3 + .../mips64-openbsd-none/machine/exec.h | 3 + .../include/mips64-openbsd-none/machine/fdt.h | 40 + .../include/mips64-openbsd-none/machine/fpu.h | 3 + .../mips64-openbsd-none/machine/frame.h | 3 + .../mips64-openbsd-none/machine/ieee.h | 3 + .../mips64-openbsd-none/machine/ieeefp.h | 3 + .../mips64-openbsd-none/machine/intr.h | 186 + .../mips64-openbsd-none/machine/kcore.h | 3 + .../mips64-openbsd-none/machine/limits.h | 3 + .../mips64-openbsd-none/machine/memconf.h | 3 + .../mips64-openbsd-none/machine/mips_opcode.h | 3 + .../mips64-openbsd-none/machine/mplock.h | 3 + .../mips64-openbsd-none/machine/mutex.h | 3 + .../mips64-openbsd-none/machine/octboot.h | 36 + .../machine/octeon_model.h | 87 + .../mips64-openbsd-none/machine/octeonreg.h | 198 + .../mips64-openbsd-none/machine/octeonvar.h | 498 ++ .../mips64-openbsd-none/machine/openpromio.h | 57 + .../mips64-openbsd-none/machine/param.h | 22 + .../include/mips64-openbsd-none/machine/pcb.h | 3 + .../mips64-openbsd-none/machine/pci_machdep.h | 133 + .../mips64-openbsd-none/machine/pmap.h | 3 + .../mips64-openbsd-none/machine/proc.h | 3 + .../mips64-openbsd-none/machine/profile.h | 3 + .../include/mips64-openbsd-none/machine/pte.h | 3 + .../mips64-openbsd-none/machine/ptrace.h | 3 + .../include/mips64-openbsd-none/machine/reg.h | 3 + .../mips64-openbsd-none/machine/regdef.h | 3 + .../mips64-openbsd-none/machine/regnum.h | 3 + .../mips64-openbsd-none/machine/setjmp.h | 3 + .../mips64-openbsd-none/machine/signal.h | 3 + .../machine/simplebusvar.h | 34 + .../mips64-openbsd-none/machine/spinlock.h | 3 + .../mips64-openbsd-none/machine/sysarch.h | 3 + .../mips64-openbsd-none/machine/timetc.h | 23 + .../mips64-openbsd-none/machine/trap.h | 3 + .../mips64-openbsd-none/machine/vmparam.h | 11 + .../mips64-openbsd-none/octeon/_float.h | 3 + .../mips64-openbsd-none/octeon/_types.h | 3 + .../include/mips64-openbsd-none/octeon/asm.h | 9 + .../mips64-openbsd-none/octeon/atomic.h | 45 + .../mips64-openbsd-none/octeon/autoconf.h | 58 + .../include/mips64-openbsd-none/octeon/bus.h | 510 ++ .../mips64-openbsd-none/octeon/cdefs.h | 3 + .../include/mips64-openbsd-none/octeon/conf.h | 55 + .../include/mips64-openbsd-none/octeon/cpu.h | 106 + .../mips64-openbsd-none/octeon/cpustate.h | 3 + .../mips64-openbsd-none/octeon/db_machdep.h | 3 + .../mips64-openbsd-none/octeon/disklabel.h | 16 + .../include/mips64-openbsd-none/octeon/elf.h | 3 + .../mips64-openbsd-none/octeon/endian.h | 3 + .../include/mips64-openbsd-none/octeon/exec.h | 3 + .../include/mips64-openbsd-none/octeon/fdt.h | 40 + .../include/mips64-openbsd-none/octeon/fenv.h | 3 + .../include/mips64-openbsd-none/octeon/fpu.h | 3 + .../mips64-openbsd-none/octeon/frame.h | 3 + .../include/mips64-openbsd-none/octeon/ieee.h | 3 + .../mips64-openbsd-none/octeon/ieeefp.h | 3 + .../include/mips64-openbsd-none/octeon/intr.h | 186 + .../mips64-openbsd-none/octeon/kcore.h | 3 + .../mips64-openbsd-none/octeon/limits.h | 3 + .../octeon/loadfile_machdep.h | 49 + .../mips64-openbsd-none/octeon/memconf.h | 3 + .../mips64-openbsd-none/octeon/mips_opcode.h | 3 + .../mips64-openbsd-none/octeon/mplock.h | 3 + .../mips64-openbsd-none/octeon/mutex.h | 3 + .../mips64-openbsd-none/octeon/octboot.h | 36 + .../mips64-openbsd-none/octeon/octeon_model.h | 87 + .../mips64-openbsd-none/octeon/octeonreg.h | 198 + .../mips64-openbsd-none/octeon/octeonvar.h | 498 ++ .../mips64-openbsd-none/octeon/openpromio.h | 57 + .../mips64-openbsd-none/octeon/param.h | 22 + .../include/mips64-openbsd-none/octeon/pcb.h | 3 + .../mips64-openbsd-none/octeon/pci_machdep.h | 133 + .../include/mips64-openbsd-none/octeon/pmap.h | 3 + .../include/mips64-openbsd-none/octeon/proc.h | 3 + .../mips64-openbsd-none/octeon/profile.h | 3 + .../include/mips64-openbsd-none/octeon/pte.h | 3 + .../mips64-openbsd-none/octeon/ptrace.h | 3 + .../include/mips64-openbsd-none/octeon/reg.h | 3 + .../mips64-openbsd-none/octeon/regdef.h | 3 + .../mips64-openbsd-none/octeon/regnum.h | 3 + .../mips64-openbsd-none/octeon/reloc.h | 5 + .../mips64-openbsd-none/octeon/setjmp.h | 3 + .../mips64-openbsd-none/octeon/signal.h | 3 + .../mips64-openbsd-none/octeon/simplebusvar.h | 34 + .../mips64-openbsd-none/octeon/spinlock.h | 3 + .../mips64-openbsd-none/octeon/sysarch.h | 3 + .../include/mips64-openbsd-none/octeon/tcb.h | 3 + .../mips64-openbsd-none/octeon/timetc.h | 23 + .../include/mips64-openbsd-none/octeon/trap.h | 3 + .../mips64-openbsd-none/octeon/vmparam.h | 11 + .../include/mips64el-openbsd-none/frame.h | 3 + .../mips64el-openbsd-none/loongson/_float.h | 3 + .../mips64el-openbsd-none/loongson/_types.h | 3 + .../mips64el-openbsd-none/loongson/apmvar.h | 127 + .../mips64el-openbsd-none/loongson/asm.h | 9 + .../mips64el-openbsd-none/loongson/atomic.h | 3 + .../mips64el-openbsd-none/loongson/autoconf.h | 124 + .../mips64el-openbsd-none/loongson/bus.h | 513 ++ .../mips64el-openbsd-none/loongson/cdefs.h | 3 + .../mips64el-openbsd-none/loongson/conf.h | 42 + .../mips64el-openbsd-none/loongson/cpu.h | 103 + .../mips64el-openbsd-none/loongson/cpustate.h | 3 + .../loongson/db_machdep.h | 3 + .../loongson/disklabel.h | 16 + .../mips64el-openbsd-none/loongson/elf.h | 3 + .../mips64el-openbsd-none/loongson/endian.h | 3 + .../mips64el-openbsd-none/loongson/exec.h | 3 + .../mips64el-openbsd-none/loongson/fenv.h | 3 + .../mips64el-openbsd-none/loongson/fpu.h | 3 + .../mips64el-openbsd-none/loongson/frame.h | 3 + .../loongson/hibernate.h | 33 + .../loongson/hibernate_var.h | 39 + .../mips64el-openbsd-none/loongson/ieee.h | 3 + .../mips64el-openbsd-none/loongson/ieeefp.h | 3 + .../mips64el-openbsd-none/loongson/intr.h | 193 + .../loongson/isa_machdep.h | 51 + .../mips64el-openbsd-none/loongson/kcore.h | 3 + .../mips64el-openbsd-none/loongson/limits.h | 3 + .../loongson/loadfile_machdep.h | 49 + .../loongson/loongson2.h | 3 + .../loongson/loongson3.h | 3 + .../mips64el-openbsd-none/loongson/memconf.h | 3 + .../loongson/mips_opcode.h | 3 + .../mips64el-openbsd-none/loongson/mplock.h | 3 + .../mips64el-openbsd-none/loongson/mutex.h | 3 + .../mips64el-openbsd-none/loongson/param.h | 31 + .../mips64el-openbsd-none/loongson/pcb.h | 3 + .../loongson/pci_machdep.h | 101 + .../mips64el-openbsd-none/loongson/pmap.h | 3 + .../mips64el-openbsd-none/loongson/pmon.h | 209 + .../mips64el-openbsd-none/loongson/proc.h | 3 + .../mips64el-openbsd-none/loongson/profile.h | 3 + .../mips64el-openbsd-none/loongson/pte.h | 3 + .../mips64el-openbsd-none/loongson/ptrace.h | 3 + .../mips64el-openbsd-none/loongson/reg.h | 3 + .../mips64el-openbsd-none/loongson/regdef.h | 3 + .../mips64el-openbsd-none/loongson/regnum.h | 3 + .../mips64el-openbsd-none/loongson/reloc.h | 5 + .../mips64el-openbsd-none/loongson/setjmp.h | 3 + .../mips64el-openbsd-none/loongson/signal.h | 3 + .../mips64el-openbsd-none/loongson/spinlock.h | 3 + .../mips64el-openbsd-none/loongson/sysarch.h | 3 + .../mips64el-openbsd-none/loongson/tcb.h | 3 + .../mips64el-openbsd-none/loongson/timetc.h | 23 + .../mips64el-openbsd-none/loongson/trap.h | 3 + .../mips64el-openbsd-none/loongson/vmparam.h | 11 + .../mips64el-openbsd-none/machine/_types.h | 3 + .../mips64el-openbsd-none/machine/apmvar.h | 127 + .../mips64el-openbsd-none/machine/asm.h | 9 + .../mips64el-openbsd-none/machine/atomic.h | 3 + .../mips64el-openbsd-none/machine/autoconf.h | 124 + .../mips64el-openbsd-none/machine/bus.h | 513 ++ .../mips64el-openbsd-none/machine/conf.h | 42 + .../mips64el-openbsd-none/machine/cpu.h | 103 + .../mips64el-openbsd-none/machine/cpustate.h | 3 + .../machine/db_machdep.h | 3 + .../mips64el-openbsd-none/machine/elf.h | 3 + .../mips64el-openbsd-none/machine/endian.h | 3 + .../mips64el-openbsd-none/machine/exec.h | 3 + .../mips64el-openbsd-none/machine/fpu.h | 3 + .../mips64el-openbsd-none/machine/frame.h | 3 + .../mips64el-openbsd-none/machine/hibernate.h | 33 + .../machine/hibernate_var.h | 39 + .../mips64el-openbsd-none/machine/ieee.h | 3 + .../mips64el-openbsd-none/machine/ieeefp.h | 3 + .../mips64el-openbsd-none/machine/intr.h | 193 + .../machine/isa_machdep.h | 51 + .../mips64el-openbsd-none/machine/kcore.h | 3 + .../mips64el-openbsd-none/machine/limits.h | 3 + .../mips64el-openbsd-none/machine/loongson2.h | 3 + .../mips64el-openbsd-none/machine/loongson3.h | 3 + .../mips64el-openbsd-none/machine/memconf.h | 3 + .../machine/mips_opcode.h | 3 + .../mips64el-openbsd-none/machine/mplock.h | 3 + .../mips64el-openbsd-none/machine/mutex.h | 3 + .../mips64el-openbsd-none/machine/param.h | 31 + .../mips64el-openbsd-none/machine/pcb.h | 3 + .../machine/pci_machdep.h | 101 + .../mips64el-openbsd-none/machine/pmap.h | 3 + .../mips64el-openbsd-none/machine/pmon.h | 209 + .../mips64el-openbsd-none/machine/proc.h | 3 + .../mips64el-openbsd-none/machine/profile.h | 3 + .../mips64el-openbsd-none/machine/pte.h | 3 + .../mips64el-openbsd-none/machine/ptrace.h | 3 + .../mips64el-openbsd-none/machine/reg.h | 3 + .../mips64el-openbsd-none/machine/regdef.h | 3 + .../mips64el-openbsd-none/machine/regnum.h | 3 + .../mips64el-openbsd-none/machine/setjmp.h | 3 + .../mips64el-openbsd-none/machine/signal.h | 3 + .../mips64el-openbsd-none/machine/spinlock.h | 3 + .../mips64el-openbsd-none/machine/sysarch.h | 3 + .../mips64el-openbsd-none/machine/timetc.h | 23 + .../mips64el-openbsd-none/machine/trap.h | 3 + .../mips64el-openbsd-none/machine/vmparam.h | 11 + .../include/powerpc-openbsd-eabihf/frame.h | 3 + .../powerpc-openbsd-eabihf/machine/_float.h | 3 + .../powerpc-openbsd-eabihf/machine/_types.h | 4 + .../powerpc-openbsd-eabihf/machine/apmvar.h | 122 + .../powerpc-openbsd-eabihf/machine/asm.h | 3 + .../powerpc-openbsd-eabihf/machine/atomic.h | 10 + .../powerpc-openbsd-eabihf/machine/autoconf.h | 72 + .../powerpc-openbsd-eabihf/machine/bus.h | 643 ++ .../powerpc-openbsd-eabihf/machine/cdefs.h | 3 + .../powerpc-openbsd-eabihf/machine/conf.h | 56 + .../powerpc-openbsd-eabihf/machine/cpu.h | 76 + .../machine/db_machdep.h | 3 + .../machine/disklabel.h | 90 + .../powerpc-openbsd-eabihf/machine/elf.h | 3 + .../powerpc-openbsd-eabihf/machine/endian.h | 3 + .../powerpc-openbsd-eabihf/machine/exec.h | 3 + .../powerpc-openbsd-eabihf/machine/fenv.h | 3 + .../powerpc-openbsd-eabihf/machine/fpu.h | 3 + .../powerpc-openbsd-eabihf/machine/frame.h | 3 + .../powerpc-openbsd-eabihf/machine/ieee.h | 3 + .../powerpc-openbsd-eabihf/machine/ieeefp.h | 3 + .../powerpc-openbsd-eabihf/machine/intr.h | 10 + .../powerpc-openbsd-eabihf/machine/kcore.h | 3 + .../powerpc-openbsd-eabihf/machine/limits.h | 3 + .../machine/loadfile_machdep.h | 49 + .../powerpc-openbsd-eabihf/machine/mplock.h | 3 + .../powerpc-openbsd-eabihf/machine/mutex.h | 3 + .../machine/openpromio.h | 57 + .../powerpc-openbsd-eabihf/machine/param.h | 52 + .../powerpc-openbsd-eabihf/machine/pcb.h | 3 + .../machine/pci_machdep.h | 108 + .../powerpc-openbsd-eabihf/machine/pio.h | 3 + .../powerpc-openbsd-eabihf/machine/pmap.h | 3 + .../powerpc-openbsd-eabihf/machine/proc.h | 3 + .../powerpc-openbsd-eabihf/machine/profile.h | 3 + .../powerpc-openbsd-eabihf/machine/psl.h | 3 + .../powerpc-openbsd-eabihf/machine/pte.h | 3 + .../powerpc-openbsd-eabihf/machine/ptrace.h | 3 + .../machine/rbus_machdep.h | 62 + .../powerpc-openbsd-eabihf/machine/reg.h | 3 + .../powerpc-openbsd-eabihf/machine/reloc.h | 3 + .../powerpc-openbsd-eabihf/machine/setjmp.h | 3 + .../powerpc-openbsd-eabihf/machine/signal.h | 3 + .../powerpc-openbsd-eabihf/machine/spinlock.h | 3 + .../powerpc-openbsd-eabihf/machine/tcb.h | 3 + .../powerpc-openbsd-eabihf/machine/timetc.h | 23 + .../powerpc-openbsd-eabihf/machine/trap.h | 3 + .../powerpc-openbsd-eabihf/machine/vmparam.h | 99 + .../powerpc-openbsd-eabihf/machine/z8530var.h | 152 + .../powerpc-openbsd-eabihf/macppc/_float.h | 3 + .../powerpc-openbsd-eabihf/macppc/_types.h | 4 + .../powerpc-openbsd-eabihf/macppc/apmvar.h | 122 + .../powerpc-openbsd-eabihf/macppc/asm.h | 3 + .../powerpc-openbsd-eabihf/macppc/atomic.h | 10 + .../powerpc-openbsd-eabihf/macppc/autoconf.h | 72 + .../powerpc-openbsd-eabihf/macppc/bus.h | 643 ++ .../powerpc-openbsd-eabihf/macppc/cdefs.h | 3 + .../powerpc-openbsd-eabihf/macppc/conf.h | 56 + .../powerpc-openbsd-eabihf/macppc/cpu.h | 76 + .../macppc/db_machdep.h | 3 + .../powerpc-openbsd-eabihf/macppc/disklabel.h | 90 + .../powerpc-openbsd-eabihf/macppc/elf.h | 3 + .../powerpc-openbsd-eabihf/macppc/endian.h | 3 + .../powerpc-openbsd-eabihf/macppc/exec.h | 3 + .../powerpc-openbsd-eabihf/macppc/fenv.h | 3 + .../powerpc-openbsd-eabihf/macppc/fpu.h | 3 + .../powerpc-openbsd-eabihf/macppc/frame.h | 3 + .../powerpc-openbsd-eabihf/macppc/ieee.h | 3 + .../powerpc-openbsd-eabihf/macppc/ieeefp.h | 3 + .../powerpc-openbsd-eabihf/macppc/intr.h | 10 + .../powerpc-openbsd-eabihf/macppc/kcore.h | 3 + .../powerpc-openbsd-eabihf/macppc/limits.h | 3 + .../macppc/loadfile_machdep.h | 49 + .../powerpc-openbsd-eabihf/macppc/mplock.h | 3 + .../powerpc-openbsd-eabihf/macppc/mutex.h | 3 + .../macppc/openpromio.h | 57 + .../powerpc-openbsd-eabihf/macppc/param.h | 52 + .../powerpc-openbsd-eabihf/macppc/pcb.h | 3 + .../macppc/pci_machdep.h | 108 + .../powerpc-openbsd-eabihf/macppc/pio.h | 3 + .../powerpc-openbsd-eabihf/macppc/pmap.h | 3 + .../powerpc-openbsd-eabihf/macppc/proc.h | 3 + .../powerpc-openbsd-eabihf/macppc/profile.h | 3 + .../powerpc-openbsd-eabihf/macppc/psl.h | 3 + .../powerpc-openbsd-eabihf/macppc/pte.h | 3 + .../powerpc-openbsd-eabihf/macppc/ptrace.h | 3 + .../macppc/rbus_machdep.h | 62 + .../powerpc-openbsd-eabihf/macppc/reg.h | 3 + .../powerpc-openbsd-eabihf/macppc/reloc.h | 3 + .../powerpc-openbsd-eabihf/macppc/setjmp.h | 3 + .../powerpc-openbsd-eabihf/macppc/signal.h | 3 + .../powerpc-openbsd-eabihf/macppc/spinlock.h | 3 + .../powerpc-openbsd-eabihf/macppc/tcb.h | 3 + .../powerpc-openbsd-eabihf/macppc/timetc.h | 23 + .../powerpc-openbsd-eabihf/macppc/trap.h | 3 + .../powerpc-openbsd-eabihf/macppc/vmparam.h | 99 + .../powerpc-openbsd-eabihf/macppc/z8530var.h | 152 + .../powerpc-openbsd-eabihf/powerpc/_float.h | 71 + .../powerpc-openbsd-eabihf/powerpc/_types.h | 141 + .../powerpc-openbsd-eabihf/powerpc/asm.h | 127 + .../powerpc-openbsd-eabihf/powerpc/atomic.h | 292 + .../powerpc-openbsd-eabihf/powerpc/bat.h | 72 + .../powerpc-openbsd-eabihf/powerpc/cdefs.h | 21 + .../powerpc-openbsd-eabihf/powerpc/cpu.h | 473 ++ .../powerpc/db_machdep.h | 102 + .../powerpc-openbsd-eabihf/powerpc/elf.h | 66 + .../powerpc-openbsd-eabihf/powerpc/endian.h | 37 + .../powerpc-openbsd-eabihf/powerpc/exec.h | 46 + .../powerpc-openbsd-eabihf/powerpc/fenv.h | 96 + .../powerpc-openbsd-eabihf/powerpc/fpu.h | 71 + .../powerpc-openbsd-eabihf/powerpc/frame.h | 79 + .../powerpc-openbsd-eabihf/powerpc/hid.h | 158 + .../powerpc-openbsd-eabihf/powerpc/ieee.h | 119 + .../powerpc-openbsd-eabihf/powerpc/ieeefp.h | 25 + .../powerpc-openbsd-eabihf/powerpc/intr.h | 170 + .../powerpc-openbsd-eabihf/powerpc/kcore.h | 46 + .../powerpc-openbsd-eabihf/powerpc/limits.h | 52 + .../powerpc-openbsd-eabihf/powerpc/mplock.h | 52 + .../powerpc-openbsd-eabihf/powerpc/mutex.h | 3 + .../powerpc-openbsd-eabihf/powerpc/param.h | 74 + .../powerpc-openbsd-eabihf/powerpc/pcb.h | 67 + .../powerpc-openbsd-eabihf/powerpc/pio.h | 181 + .../powerpc-openbsd-eabihf/powerpc/pmap.h | 186 + .../powerpc-openbsd-eabihf/powerpc/powerpc.h | 53 + .../powerpc-openbsd-eabihf/powerpc/proc.h | 45 + .../powerpc-openbsd-eabihf/powerpc/profile.h | 78 + .../powerpc-openbsd-eabihf/powerpc/psl.h | 78 + .../powerpc-openbsd-eabihf/powerpc/pte.h | 129 + .../powerpc-openbsd-eabihf/powerpc/ptrace.h | 45 + .../powerpc-openbsd-eabihf/powerpc/reg.h | 76 + .../powerpc-openbsd-eabihf/powerpc/reloc.h | 91 + .../powerpc-openbsd-eabihf/powerpc/setjmp.h | 4 + .../powerpc-openbsd-eabihf/powerpc/signal.h | 72 + .../powerpc-openbsd-eabihf/powerpc/spinlock.h | 10 + .../powerpc-openbsd-eabihf/powerpc/tcb.h | 42 + .../powerpc-openbsd-eabihf/powerpc/trap.h | 87 + .../include/powerpc64-openbsd-none/frame.h | 104 + .../powerpc64-openbsd-none/machine/_float.h | 71 + .../powerpc64-openbsd-none/machine/_types.h | 145 + .../powerpc64-openbsd-none/machine/apmvar.h | 122 + .../powerpc64-openbsd-none/machine/asm.h | 100 + .../powerpc64-openbsd-none/machine/atomic.h | 292 + .../powerpc64-openbsd-none/machine/bus.h | 532 ++ .../powerpc64-openbsd-none/machine/cdefs.h | 21 + .../powerpc64-openbsd-none/machine/conf.h | 24 + .../powerpc64-openbsd-none/machine/cpu.h | 234 + .../powerpc64-openbsd-none/machine/cpufunc.h | 222 + .../machine/db_machdep.h | 86 + .../machine/disklabel.h | 26 + .../powerpc64-openbsd-none/machine/elf.h | 66 + .../powerpc64-openbsd-none/machine/endian.h | 37 + .../powerpc64-openbsd-none/machine/exec.h | 36 + .../powerpc64-openbsd-none/machine/fdt.h | 39 + .../powerpc64-openbsd-none/machine/fenv.h | 96 + .../powerpc64-openbsd-none/machine/fpu.h | 17 + .../powerpc64-openbsd-none/machine/frame.h | 104 + .../powerpc64-openbsd-none/machine/ieee.h | 119 + .../powerpc64-openbsd-none/machine/ieeefp.h | 25 + .../powerpc64-openbsd-none/machine/intr.h | 135 + .../powerpc64-openbsd-none/machine/kcore.h | 1 + .../powerpc64-openbsd-none/machine/kexec.h | 36 + .../powerpc64-openbsd-none/machine/limits.h | 55 + .../powerpc64-openbsd-none/machine/mplock.h | 10 + .../powerpc64-openbsd-none/machine/mutex.h | 3 + .../powerpc64-openbsd-none/machine/opal.h | 238 + .../machine/openpromio.h | 57 + .../powerpc64-openbsd-none/machine/param.h | 80 + .../powerpc64-openbsd-none/machine/pcb.h | 37 + .../machine/pci_machdep.h | 134 + .../powerpc64-openbsd-none/machine/pmap.h | 98 + .../powerpc64-openbsd-none/machine/proc.h | 46 + .../powerpc64-openbsd-none/machine/profile.h | 70 + .../powerpc64-openbsd-none/machine/psl.h | 88 + .../powerpc64-openbsd-none/machine/pte.h | 80 + .../powerpc64-openbsd-none/machine/ptrace.h | 44 + .../powerpc64-openbsd-none/machine/reg.h | 39 + .../powerpc64-openbsd-none/machine/reloc.h | 148 + .../powerpc64-openbsd-none/machine/setjmp.h | 4 + .../powerpc64-openbsd-none/machine/signal.h | 65 + .../machine/smbiosvar.h | 278 + .../powerpc64-openbsd-none/machine/spinlock.h | 26 + .../powerpc64-openbsd-none/machine/tcb.h | 42 + .../powerpc64-openbsd-none/machine/timetc.h | 23 + .../powerpc64-openbsd-none/machine/trap.h | 158 + .../powerpc64-openbsd-none/machine/vmparam.h | 53 + .../powerpc64-openbsd-none/powerpc64/_float.h | 71 + .../powerpc64-openbsd-none/powerpc64/_types.h | 145 + .../powerpc64-openbsd-none/powerpc64/apmvar.h | 122 + .../powerpc64-openbsd-none/powerpc64/asm.h | 100 + .../powerpc64-openbsd-none/powerpc64/atomic.h | 292 + .../powerpc64-openbsd-none/powerpc64/bus.h | 532 ++ .../powerpc64-openbsd-none/powerpc64/cdefs.h | 21 + .../powerpc64-openbsd-none/powerpc64/conf.h | 24 + .../powerpc64-openbsd-none/powerpc64/cpu.h | 234 + .../powerpc64/cpufunc.h | 222 + .../powerpc64/db_machdep.h | 86 + .../powerpc64/disklabel.h | 26 + .../powerpc64-openbsd-none/powerpc64/elf.h | 66 + .../powerpc64-openbsd-none/powerpc64/endian.h | 37 + .../powerpc64-openbsd-none/powerpc64/exec.h | 36 + .../powerpc64-openbsd-none/powerpc64/fdt.h | 39 + .../powerpc64-openbsd-none/powerpc64/fenv.h | 96 + .../powerpc64-openbsd-none/powerpc64/fpu.h | 17 + .../powerpc64-openbsd-none/powerpc64/frame.h | 104 + .../powerpc64-openbsd-none/powerpc64/ieee.h | 119 + .../powerpc64-openbsd-none/powerpc64/ieeefp.h | 25 + .../powerpc64-openbsd-none/powerpc64/intr.h | 135 + .../powerpc64-openbsd-none/powerpc64/kcore.h | 1 + .../powerpc64-openbsd-none/powerpc64/kexec.h | 36 + .../powerpc64-openbsd-none/powerpc64/limits.h | 55 + .../powerpc64-openbsd-none/powerpc64/mplock.h | 10 + .../powerpc64-openbsd-none/powerpc64/mutex.h | 3 + .../powerpc64-openbsd-none/powerpc64/opal.h | 238 + .../powerpc64/openpromio.h | 57 + .../powerpc64-openbsd-none/powerpc64/param.h | 80 + .../powerpc64-openbsd-none/powerpc64/pcb.h | 37 + .../powerpc64/pci_machdep.h | 134 + .../powerpc64-openbsd-none/powerpc64/pmap.h | 98 + .../powerpc64-openbsd-none/powerpc64/proc.h | 46 + .../powerpc64/profile.h | 70 + .../powerpc64-openbsd-none/powerpc64/psl.h | 88 + .../powerpc64-openbsd-none/powerpc64/pte.h | 80 + .../powerpc64-openbsd-none/powerpc64/ptrace.h | 44 + .../powerpc64-openbsd-none/powerpc64/reg.h | 39 + .../powerpc64-openbsd-none/powerpc64/reloc.h | 148 + .../powerpc64-openbsd-none/powerpc64/setjmp.h | 4 + .../powerpc64-openbsd-none/powerpc64/signal.h | 65 + .../powerpc64/smbiosvar.h | 278 + .../powerpc64/spinlock.h | 26 + .../powerpc64-openbsd-none/powerpc64/tcb.h | 42 + .../powerpc64-openbsd-none/powerpc64/timetc.h | 23 + .../powerpc64-openbsd-none/powerpc64/trap.h | 158 + .../powerpc64/vmparam.h | 53 + lib/libc/include/riscv64-openbsd-none/frame.h | 99 + .../riscv64-openbsd-none/machine/_float.h | 96 + .../riscv64-openbsd-none/machine/_types.h | 146 + .../riscv64-openbsd-none/machine/apmvar.h | 122 + .../riscv64-openbsd-none/machine/asm.h | 129 + .../riscv64-openbsd-none/machine/atomic.h | 50 + .../riscv64-openbsd-none/machine/bootconfig.h | 47 + .../riscv64-openbsd-none/machine/bus.h | 544 ++ .../riscv64-openbsd-none/machine/cdefs.h | 16 + .../riscv64-openbsd-none/machine/conf.h | 50 + .../riscv64-openbsd-none/machine/cpu.h | 284 + .../riscv64-openbsd-none/machine/cpufunc.h | 103 + .../riscv64-openbsd-none/machine/db_machdep.h | 93 + .../riscv64-openbsd-none/machine/disklabel.h | 26 + .../riscv64-openbsd-none/machine/elf.h | 52 + .../riscv64-openbsd-none/machine/endian.h | 29 + .../riscv64-openbsd-none/machine/exec.h | 30 + .../riscv64-openbsd-none/machine/fdt.h | 59 + .../riscv64-openbsd-none/machine/fenv.h | 95 + .../riscv64-openbsd-none/machine/frame.h | 99 + .../riscv64-openbsd-none/machine/ieee.h | 148 + .../riscv64-openbsd-none/machine/ieeefp.h | 25 + .../riscv64-openbsd-none/machine/intr.h | 227 + .../riscv64-openbsd-none/machine/kcore.h | 16 + .../riscv64-openbsd-none/machine/limits.h | 56 + .../machine/loadfile_machdep.h | 53 + .../riscv64-openbsd-none/machine/mplock.h | 10 + .../riscv64-openbsd-none/machine/mutex.h | 3 + .../riscv64-openbsd-none/machine/openpromio.h | 57 + .../riscv64-openbsd-none/machine/param.h | 78 + .../riscv64-openbsd-none/machine/pcb.h | 41 + .../machine/pci_machdep.h | 140 + .../riscv64-openbsd-none/machine/pmap.h | 132 + .../riscv64-openbsd-none/machine/proc.h | 45 + .../riscv64-openbsd-none/machine/profile.h | 92 + .../riscv64-openbsd-none/machine/pte.h | 85 + .../riscv64-openbsd-none/machine/ptrace.h | 25 + .../riscv64-openbsd-none/machine/reg.h | 60 + .../riscv64-openbsd-none/machine/reloc.h | 19 + .../riscv64-openbsd-none/machine/riscvreg.h | 235 + .../riscv64-openbsd-none/machine/sbi.h | 267 + .../riscv64-openbsd-none/machine/setjmp.h | 8 + .../riscv64-openbsd-none/machine/signal.h | 70 + .../machine/simplebusvar.h | 38 + .../riscv64-openbsd-none/machine/spinlock.h | 10 + .../riscv64-openbsd-none/machine/sysarch.h | 43 + .../riscv64-openbsd-none/machine/syscall.h | 28 + .../riscv64-openbsd-none/machine/tcb.h | 52 + .../riscv64-openbsd-none/machine/timetc.h | 24 + .../riscv64-openbsd-none/machine/trap.h | 24 + .../riscv64-openbsd-none/machine/vmparam.h | 150 + .../riscv64-openbsd-none/riscv64/_float.h | 96 + .../riscv64-openbsd-none/riscv64/_types.h | 146 + .../riscv64-openbsd-none/riscv64/apmvar.h | 122 + .../riscv64-openbsd-none/riscv64/asm.h | 129 + .../riscv64-openbsd-none/riscv64/atomic.h | 50 + .../riscv64-openbsd-none/riscv64/bootconfig.h | 47 + .../riscv64-openbsd-none/riscv64/bus.h | 544 ++ .../riscv64-openbsd-none/riscv64/cdefs.h | 16 + .../riscv64-openbsd-none/riscv64/conf.h | 50 + .../riscv64-openbsd-none/riscv64/cpu.h | 284 + .../riscv64-openbsd-none/riscv64/cpufunc.h | 103 + .../riscv64-openbsd-none/riscv64/db_machdep.h | 93 + .../riscv64-openbsd-none/riscv64/disklabel.h | 26 + .../riscv64-openbsd-none/riscv64/elf.h | 52 + .../riscv64-openbsd-none/riscv64/endian.h | 29 + .../riscv64-openbsd-none/riscv64/exec.h | 30 + .../riscv64-openbsd-none/riscv64/fdt.h | 59 + .../riscv64-openbsd-none/riscv64/fenv.h | 95 + .../riscv64-openbsd-none/riscv64/frame.h | 99 + .../riscv64-openbsd-none/riscv64/ieee.h | 148 + .../riscv64-openbsd-none/riscv64/ieeefp.h | 25 + .../riscv64-openbsd-none/riscv64/intr.h | 227 + .../riscv64-openbsd-none/riscv64/kcore.h | 16 + .../riscv64-openbsd-none/riscv64/limits.h | 56 + .../riscv64/loadfile_machdep.h | 53 + .../riscv64-openbsd-none/riscv64/mplock.h | 10 + .../riscv64-openbsd-none/riscv64/mutex.h | 3 + .../riscv64-openbsd-none/riscv64/openpromio.h | 57 + .../riscv64-openbsd-none/riscv64/param.h | 78 + .../riscv64-openbsd-none/riscv64/pcb.h | 41 + .../riscv64/pci_machdep.h | 140 + .../riscv64-openbsd-none/riscv64/pmap.h | 132 + .../riscv64-openbsd-none/riscv64/proc.h | 45 + .../riscv64-openbsd-none/riscv64/profile.h | 92 + .../riscv64-openbsd-none/riscv64/pte.h | 85 + .../riscv64-openbsd-none/riscv64/ptrace.h | 25 + .../riscv64-openbsd-none/riscv64/reg.h | 60 + .../riscv64-openbsd-none/riscv64/reloc.h | 19 + .../riscv64-openbsd-none/riscv64/riscvreg.h | 235 + .../riscv64-openbsd-none/riscv64/sbi.h | 267 + .../riscv64-openbsd-none/riscv64/setjmp.h | 8 + .../riscv64-openbsd-none/riscv64/signal.h | 70 + .../riscv64/simplebusvar.h | 38 + .../riscv64-openbsd-none/riscv64/spinlock.h | 10 + .../riscv64-openbsd-none/riscv64/sysarch.h | 43 + .../riscv64-openbsd-none/riscv64/syscall.h | 28 + .../riscv64-openbsd-none/riscv64/tcb.h | 52 + .../riscv64-openbsd-none/riscv64/timetc.h | 24 + .../riscv64-openbsd-none/riscv64/trap.h | 24 + .../riscv64-openbsd-none/riscv64/vmparam.h | 150 + lib/libc/include/sparc64-openbsd-none/frame.h | 105 + .../sparc64-openbsd-none/machine/_float.h | 80 + .../sparc64-openbsd-none/machine/_types.h | 140 + .../sparc64-openbsd-none/machine/apmvar.h | 122 + .../sparc64-openbsd-none/machine/asm.h | 96 + .../sparc64-openbsd-none/machine/atomic.h | 154 + .../sparc64-openbsd-none/machine/autoconf.h | 159 + .../sparc64-openbsd-none/machine/boot_flag.h | 50 + .../sparc64-openbsd-none/machine/bppioctl.h | 59 + .../sparc64-openbsd-none/machine/bus.h | 649 ++ .../sparc64-openbsd-none/machine/cdefs.h | 16 + .../sparc64-openbsd-none/machine/conf.h | 101 + .../sparc64-openbsd-none/machine/cpu.h | 384 + .../sparc64-openbsd-none/machine/ctlreg.h | 715 ++ .../sparc64-openbsd-none/machine/db_machdep.h | 145 + .../sparc64-openbsd-none/machine/disklabel.h | 40 + .../sparc64-openbsd-none/machine/elf.h | 7 + .../sparc64-openbsd-none/machine/endian.h | 84 + .../sparc64-openbsd-none/machine/exec.h | 99 + .../sparc64-openbsd-none/machine/fbvar.h | 80 + .../sparc64-openbsd-none/machine/fenv.h | 108 + .../sparc64-openbsd-none/machine/frame.h | 105 + .../sparc64-openbsd-none/machine/fsr.h | 132 + .../sparc64-openbsd-none/machine/hypervisor.h | 348 + .../sparc64-openbsd-none/machine/idprom.h | 52 + .../sparc64-openbsd-none/machine/ieee.h | 148 + .../sparc64-openbsd-none/machine/ieeefp.h | 24 + .../sparc64-openbsd-none/machine/instr.h | 502 ++ .../sparc64-openbsd-none/machine/intr.h | 119 + .../sparc64-openbsd-none/machine/ioctl_fd.h | 130 + .../sparc64-openbsd-none/machine/kcore.h | 61 + .../sparc64-openbsd-none/machine/limits.h | 55 + .../machine/loadfile_machdep.h | 65 + .../sparc64-openbsd-none/machine/mdesc.h | 55 + .../sparc64-openbsd-none/machine/mutex.h | 3 + .../sparc64-openbsd-none/machine/openfirm.h | 65 + .../sparc64-openbsd-none/machine/openpromio.h | 57 + .../sparc64-openbsd-none/machine/param.h | 183 + .../sparc64-openbsd-none/machine/pcb.h | 152 + .../machine/pci_machdep.h | 137 + .../sparc64-openbsd-none/machine/pmap.h | 214 + .../sparc64-openbsd-none/machine/proc.h | 52 + .../sparc64-openbsd-none/machine/profile.h | 74 + .../sparc64-openbsd-none/machine/psl.h | 327 + .../sparc64-openbsd-none/machine/pte.h | 204 + .../sparc64-openbsd-none/machine/ptrace.h | 55 + .../machine/rbus_machdep.h | 39 + .../sparc64-openbsd-none/machine/reg.h | 92 + .../sparc64-openbsd-none/machine/reloc.h | 36 + .../sparc64-openbsd-none/machine/setjmp.h | 7 + .../sparc64-openbsd-none/machine/signal.h | 87 + .../sparc64-openbsd-none/machine/sparc64.h | 65 + .../sparc64-openbsd-none/machine/spinlock.h | 10 + .../sparc64-openbsd-none/machine/tcb.h | 44 + .../sparc64-openbsd-none/machine/timetc.h | 24 + .../sparc64-openbsd-none/machine/trap.h | 159 + .../sparc64-openbsd-none/machine/vmparam.h | 124 + .../sparc64-openbsd-none/machine/z8530var.h | 80 + .../sparc64-openbsd-none/sparc64/_float.h | 80 + .../sparc64-openbsd-none/sparc64/_types.h | 140 + .../sparc64-openbsd-none/sparc64/apmvar.h | 122 + .../sparc64-openbsd-none/sparc64/asm.h | 96 + .../sparc64-openbsd-none/sparc64/atomic.h | 154 + .../sparc64-openbsd-none/sparc64/autoconf.h | 159 + .../sparc64-openbsd-none/sparc64/boot_flag.h | 50 + .../sparc64-openbsd-none/sparc64/bppioctl.h | 59 + .../sparc64-openbsd-none/sparc64/bus.h | 649 ++ .../sparc64-openbsd-none/sparc64/cdefs.h | 16 + .../sparc64-openbsd-none/sparc64/conf.h | 101 + .../sparc64-openbsd-none/sparc64/cpu.h | 384 + .../sparc64-openbsd-none/sparc64/ctlreg.h | 715 ++ .../sparc64-openbsd-none/sparc64/db_machdep.h | 145 + .../sparc64-openbsd-none/sparc64/disklabel.h | 40 + .../sparc64-openbsd-none/sparc64/elf.h | 7 + .../sparc64-openbsd-none/sparc64/endian.h | 84 + .../sparc64-openbsd-none/sparc64/exec.h | 99 + .../sparc64-openbsd-none/sparc64/fbvar.h | 80 + .../sparc64-openbsd-none/sparc64/fenv.h | 108 + .../sparc64-openbsd-none/sparc64/frame.h | 105 + .../sparc64-openbsd-none/sparc64/fsr.h | 132 + .../sparc64-openbsd-none/sparc64/hypervisor.h | 348 + .../sparc64-openbsd-none/sparc64/idprom.h | 52 + .../sparc64-openbsd-none/sparc64/ieee.h | 148 + .../sparc64-openbsd-none/sparc64/ieeefp.h | 24 + .../sparc64-openbsd-none/sparc64/instr.h | 502 ++ .../sparc64-openbsd-none/sparc64/intr.h | 119 + .../sparc64-openbsd-none/sparc64/ioctl_fd.h | 130 + .../sparc64-openbsd-none/sparc64/kcore.h | 61 + .../sparc64-openbsd-none/sparc64/limits.h | 55 + .../sparc64/loadfile_machdep.h | 65 + .../sparc64-openbsd-none/sparc64/mdesc.h | 55 + .../sparc64-openbsd-none/sparc64/mplock.h | 10 + .../sparc64-openbsd-none/sparc64/mutex.h | 3 + .../sparc64-openbsd-none/sparc64/openfirm.h | 65 + .../sparc64-openbsd-none/sparc64/openpromio.h | 57 + .../sparc64-openbsd-none/sparc64/param.h | 183 + .../sparc64-openbsd-none/sparc64/pcb.h | 152 + .../sparc64/pci_machdep.h | 137 + .../sparc64-openbsd-none/sparc64/pmap.h | 214 + .../sparc64-openbsd-none/sparc64/proc.h | 52 + .../sparc64-openbsd-none/sparc64/profile.h | 74 + .../sparc64-openbsd-none/sparc64/psl.h | 327 + .../sparc64-openbsd-none/sparc64/pte.h | 204 + .../sparc64-openbsd-none/sparc64/ptrace.h | 55 + .../sparc64/rbus_machdep.h | 39 + .../sparc64-openbsd-none/sparc64/reg.h | 92 + .../sparc64-openbsd-none/sparc64/reloc.h | 36 + .../sparc64-openbsd-none/sparc64/setjmp.h | 7 + .../sparc64-openbsd-none/sparc64/signal.h | 87 + .../sparc64-openbsd-none/sparc64/sparc64.h | 65 + .../sparc64-openbsd-none/sparc64/spinlock.h | 10 + .../sparc64-openbsd-none/sparc64/tcb.h | 44 + .../sparc64-openbsd-none/sparc64/timetc.h | 24 + .../sparc64-openbsd-none/sparc64/trap.h | 159 + .../sparc64-openbsd-none/sparc64/vmparam.h | 124 + .../sparc64-openbsd-none/sparc64/z8530var.h | 80 + lib/libc/include/x86-openbsd-none/frame.h | 173 + .../include/x86-openbsd-none/i386/_float.h | 71 + .../include/x86-openbsd-none/i386/_types.h | 140 + .../include/x86-openbsd-none/i386/acpiapm.h | 22 + .../include/x86-openbsd-none/i386/amdmsr.h | 34 + .../include/x86-openbsd-none/i386/apicvar.h | 54 + .../include/x86-openbsd-none/i386/apmvar.h | 303 + lib/libc/include/x86-openbsd-none/i386/asm.h | 131 + .../include/x86-openbsd-none/i386/atomic.h | 316 + .../include/x86-openbsd-none/i386/biosvar.h | 306 + lib/libc/include/x86-openbsd-none/i386/bus.h | 701 ++ .../include/x86-openbsd-none/i386/cdefs.h | 21 + .../include/x86-openbsd-none/i386/codepatch.h | 52 + lib/libc/include/x86-openbsd-none/i386/conf.h | 60 + lib/libc/include/x86-openbsd-none/i386/cpu.h | 533 ++ .../include/x86-openbsd-none/i386/cpu_full.h | 67 + .../include/x86-openbsd-none/i386/cpufunc.h | 310 + .../include/x86-openbsd-none/i386/cputypes.h | 60 + .../include/x86-openbsd-none/i386/cpuvar.h | 98 + .../x86-openbsd-none/i386/db_machdep.h | 94 + .../include/x86-openbsd-none/i386/disklabel.h | 40 + lib/libc/include/x86-openbsd-none/i386/elf.h | 7 + .../include/x86-openbsd-none/i386/endian.h | 36 + lib/libc/include/x86-openbsd-none/i386/exec.h | 43 + lib/libc/include/x86-openbsd-none/i386/fenv.h | 115 + .../include/x86-openbsd-none/i386/frame.h | 173 + lib/libc/include/x86-openbsd-none/i386/gdt.h | 43 + .../include/x86-openbsd-none/i386/hibernate.h | 35 + .../x86-openbsd-none/i386/hibernate_var.h | 53 + .../include/x86-openbsd-none/i386/i82093reg.h | 118 + .../include/x86-openbsd-none/i386/i82093var.h | 99 + .../include/x86-openbsd-none/i386/i82489reg.h | 144 + .../include/x86-openbsd-none/i386/i82489var.h | 128 + .../include/x86-openbsd-none/i386/i8259.h | 144 + lib/libc/include/x86-openbsd-none/i386/ieee.h | 141 + .../include/x86-openbsd-none/i386/ieeefp.h | 26 + lib/libc/include/x86-openbsd-none/i386/intr.h | 149 + .../include/x86-openbsd-none/i386/intrdefs.h | 126 + .../include/x86-openbsd-none/i386/ioctl_fd.h | 131 + .../include/x86-openbsd-none/i386/joystick.h | 23 + .../include/x86-openbsd-none/i386/kcore.h | 25 + .../include/x86-openbsd-none/i386/limits.h | 53 + .../x86-openbsd-none/i386/loadfile_machdep.h | 55 + .../include/x86-openbsd-none/i386/mpbiosreg.h | 155 + .../include/x86-openbsd-none/i386/mpbiosvar.h | 86 + .../include/x86-openbsd-none/i386/mplock.h | 10 + .../include/x86-openbsd-none/i386/mutex.h | 3 + lib/libc/include/x86-openbsd-none/i386/npx.h | 158 + .../include/x86-openbsd-none/i386/param.h | 80 + lib/libc/include/x86-openbsd-none/i386/pcb.h | 78 + lib/libc/include/x86-openbsd-none/i386/pctr.h | 93 + lib/libc/include/x86-openbsd-none/i386/pic.h | 42 + lib/libc/include/x86-openbsd-none/i386/pio.h | 201 + lib/libc/include/x86-openbsd-none/i386/pmap.h | 480 ++ lib/libc/include/x86-openbsd-none/i386/proc.h | 45 + .../include/x86-openbsd-none/i386/profile.h | 76 + lib/libc/include/x86-openbsd-none/i386/psl.h | 98 + lib/libc/include/x86-openbsd-none/i386/pte.h | 92 + .../include/x86-openbsd-none/i386/ptrace.h | 50 + .../x86-openbsd-none/i386/rbus_machdep.h | 48 + lib/libc/include/x86-openbsd-none/i386/reg.h | 103 + .../include/x86-openbsd-none/i386/reloc.h | 52 + .../include/x86-openbsd-none/i386/segments.h | 229 + .../include/x86-openbsd-none/i386/setjmp.h | 18 + .../include/x86-openbsd-none/i386/signal.h | 88 + .../include/x86-openbsd-none/i386/smbiosvar.h | 281 + .../x86-openbsd-none/i386/specialreg.h | 812 +++ .../include/x86-openbsd-none/i386/spinlock.h | 10 + .../include/x86-openbsd-none/i386/sysarch.h | 38 + lib/libc/include/x86-openbsd-none/i386/tcb.h | 51 + .../include/x86-openbsd-none/i386/timetc.h | 23 + lib/libc/include/x86-openbsd-none/i386/trap.h | 65 + lib/libc/include/x86-openbsd-none/i386/tss.h | 74 + .../include/x86-openbsd-none/i386/vga_post.h | 43 + .../include/x86-openbsd-none/i386/vmmvar.h | 17 + .../include/x86-openbsd-none/i386/vmparam.h | 108 + .../include/x86-openbsd-none/machine/_float.h | 71 + .../include/x86-openbsd-none/machine/_types.h | 140 + .../x86-openbsd-none/machine/acpiapm.h | 22 + .../include/x86-openbsd-none/machine/amdmsr.h | 34 + .../x86-openbsd-none/machine/apicvar.h | 54 + .../include/x86-openbsd-none/machine/apmvar.h | 303 + .../include/x86-openbsd-none/machine/asm.h | 131 + .../include/x86-openbsd-none/machine/atomic.h | 316 + .../x86-openbsd-none/machine/biosvar.h | 306 + .../include/x86-openbsd-none/machine/bus.h | 701 ++ .../include/x86-openbsd-none/machine/cdefs.h | 21 + .../x86-openbsd-none/machine/codepatch.h | 52 + .../include/x86-openbsd-none/machine/conf.h | 60 + .../include/x86-openbsd-none/machine/cpu.h | 533 ++ .../x86-openbsd-none/machine/cpu_full.h | 67 + .../x86-openbsd-none/machine/cpufunc.h | 310 + .../x86-openbsd-none/machine/cputypes.h | 60 + .../include/x86-openbsd-none/machine/cpuvar.h | 98 + .../x86-openbsd-none/machine/db_machdep.h | 94 + .../x86-openbsd-none/machine/disklabel.h | 40 + .../include/x86-openbsd-none/machine/endian.h | 36 + .../include/x86-openbsd-none/machine/exec.h | 43 + .../include/x86-openbsd-none/machine/fenv.h | 115 + .../include/x86-openbsd-none/machine/frame.h | 173 + .../include/x86-openbsd-none/machine/gdt.h | 43 + .../x86-openbsd-none/machine/hibernate.h | 35 + .../x86-openbsd-none/machine/hibernate_var.h | 53 + .../x86-openbsd-none/machine/i82093reg.h | 118 + .../x86-openbsd-none/machine/i82093var.h | 99 + .../x86-openbsd-none/machine/i82489reg.h | 144 + .../x86-openbsd-none/machine/i82489var.h | 128 + .../include/x86-openbsd-none/machine/i8259.h | 144 + .../include/x86-openbsd-none/machine/ieee.h | 141 + .../include/x86-openbsd-none/machine/ieeefp.h | 26 + .../include/x86-openbsd-none/machine/intr.h | 149 + .../x86-openbsd-none/machine/intrdefs.h | 126 + .../x86-openbsd-none/machine/ioctl_fd.h | 131 + .../x86-openbsd-none/machine/joystick.h | 23 + .../include/x86-openbsd-none/machine/kcore.h | 25 + .../include/x86-openbsd-none/machine/limits.h | 53 + .../machine/loadfile_machdep.h | 55 + .../x86-openbsd-none/machine/mpbiosreg.h | 155 + .../x86-openbsd-none/machine/mpbiosvar.h | 86 + .../include/x86-openbsd-none/machine/mutex.h | 3 + .../include/x86-openbsd-none/machine/npx.h | 158 + .../include/x86-openbsd-none/machine/param.h | 80 + .../include/x86-openbsd-none/machine/pcb.h | 78 + .../include/x86-openbsd-none/machine/pctr.h | 93 + .../include/x86-openbsd-none/machine/pic.h | 42 + .../include/x86-openbsd-none/machine/pio.h | 201 + .../include/x86-openbsd-none/machine/pmap.h | 480 ++ .../include/x86-openbsd-none/machine/proc.h | 45 + .../x86-openbsd-none/machine/profile.h | 76 + .../include/x86-openbsd-none/machine/psl.h | 98 + .../include/x86-openbsd-none/machine/pte.h | 92 + .../include/x86-openbsd-none/machine/ptrace.h | 50 + .../x86-openbsd-none/machine/rbus_machdep.h | 48 + .../include/x86-openbsd-none/machine/reg.h | 103 + .../include/x86-openbsd-none/machine/reloc.h | 52 + .../x86-openbsd-none/machine/segments.h | 229 + .../include/x86-openbsd-none/machine/setjmp.h | 18 + .../include/x86-openbsd-none/machine/signal.h | 88 + .../x86-openbsd-none/machine/specialreg.h | 812 +++ .../x86-openbsd-none/machine/sysarch.h | 38 + .../include/x86-openbsd-none/machine/tcb.h | 51 + .../include/x86-openbsd-none/machine/trap.h | 65 + .../include/x86-openbsd-none/machine/tss.h | 74 + .../x86-openbsd-none/machine/vga_post.h | 43 + .../include/x86-openbsd-none/machine/vmmvar.h | 17 + .../x86-openbsd-none/machine/vmparam.h | 108 + .../x86_64-openbsd-none/amd64/_float.h | 71 + .../x86_64-openbsd-none/amd64/_types.h | 140 + .../x86_64-openbsd-none/amd64/apicvar.h | 54 + .../x86_64-openbsd-none/amd64/apmvar.h | 303 + .../include/x86_64-openbsd-none/amd64/asm.h | 196 + .../x86_64-openbsd-none/amd64/atomic.h | 325 + .../x86_64-openbsd-none/amd64/biosvar.h | 283 + .../include/x86_64-openbsd-none/amd64/bus.h | 706 ++ .../include/x86_64-openbsd-none/amd64/cdefs.h | 21 + .../x86_64-openbsd-none/amd64/codepatch.h | 120 + .../include/x86_64-openbsd-none/amd64/conf.h | 59 + .../include/x86_64-openbsd-none/amd64/cpu.h | 530 ++ .../x86_64-openbsd-none/amd64/cpu_full.h | 70 + .../x86_64-openbsd-none/amd64/cpufunc.h | 461 ++ .../x86_64-openbsd-none/amd64/cpuvar.h | 100 + .../x86_64-openbsd-none/amd64/db_machdep.h | 101 + .../x86_64-openbsd-none/amd64/disklabel.h | 40 + .../x86_64-openbsd-none/amd64/efifbvar.h | 40 + .../x86_64-openbsd-none/amd64/efivar.h | 42 + .../include/x86_64-openbsd-none/amd64/elf.h | 7 + .../x86_64-openbsd-none/amd64/endian.h | 36 + .../include/x86_64-openbsd-none/amd64/exec.h | 17 + .../include/x86_64-openbsd-none/amd64/fenv.h | 115 + .../include/x86_64-openbsd-none/amd64/fpu.h | 111 + .../include/x86_64-openbsd-none/amd64/frame.h | 174 + .../x86_64-openbsd-none/amd64/frameasm.h | 199 + .../include/x86_64-openbsd-none/amd64/gdt.h | 33 + .../include/x86_64-openbsd-none/amd64/ghcb.h | 251 + .../x86_64-openbsd-none/amd64/hibernate.h | 36 + .../x86_64-openbsd-none/amd64/hibernate_var.h | 75 + .../x86_64-openbsd-none/amd64/i82093reg.h | 135 + .../x86_64-openbsd-none/amd64/i82093var.h | 92 + .../x86_64-openbsd-none/amd64/i82489reg.h | 149 + .../x86_64-openbsd-none/amd64/i82489var.h | 124 + .../include/x86_64-openbsd-none/amd64/i8259.h | 144 + .../include/x86_64-openbsd-none/amd64/ieee.h | 142 + .../x86_64-openbsd-none/amd64/ieeefp.h | 26 + .../include/x86_64-openbsd-none/amd64/intr.h | 229 + .../x86_64-openbsd-none/amd64/intrdefs.h | 93 + .../x86_64-openbsd-none/amd64/ioctl_fd.h | 130 + .../x86_64-openbsd-none/amd64/isa_machdep.h | 163 + .../include/x86_64-openbsd-none/amd64/kcore.h | 47 + .../x86_64-openbsd-none/amd64/limits.h | 52 + .../amd64/loadfile_machdep.h | 61 + .../x86_64-openbsd-none/amd64/mpbiosreg.h | 156 + .../x86_64-openbsd-none/amd64/mpbiosvar.h | 57 + .../x86_64-openbsd-none/amd64/mpconfig.h | 49 + .../x86_64-openbsd-none/amd64/mplock.h | 10 + .../include/x86_64-openbsd-none/amd64/mutex.h | 3 + .../include/x86_64-openbsd-none/amd64/param.h | 81 + .../include/x86_64-openbsd-none/amd64/pcb.h | 93 + .../x86_64-openbsd-none/amd64/pci_machdep.h | 137 + .../include/x86_64-openbsd-none/amd64/pctr.h | 73 + .../include/x86_64-openbsd-none/amd64/pic.h | 45 + .../include/x86_64-openbsd-none/amd64/pio.h | 225 + .../include/x86_64-openbsd-none/amd64/pmap.h | 524 ++ .../include/x86_64-openbsd-none/amd64/proc.h | 52 + .../x86_64-openbsd-none/amd64/profile.h | 77 + .../include/x86_64-openbsd-none/amd64/psl.h | 76 + .../include/x86_64-openbsd-none/amd64/pte.h | 171 + .../x86_64-openbsd-none/amd64/ptrace.h | 56 + .../x86_64-openbsd-none/amd64/rbus_machdep.h | 48 + .../include/x86_64-openbsd-none/amd64/reg.h | 125 + .../include/x86_64-openbsd-none/amd64/reloc.h | 69 + .../x86_64-openbsd-none/amd64/segments.h | 279 + .../x86_64-openbsd-none/amd64/setjmp.h | 22 + .../x86_64-openbsd-none/amd64/signal.h | 89 + .../x86_64-openbsd-none/amd64/smbiosvar.h | 281 + .../x86_64-openbsd-none/amd64/specialreg.h | 1645 +++++ .../x86_64-openbsd-none/amd64/spinlock.h | 10 + .../x86_64-openbsd-none/amd64/sysarch.h | 28 + .../include/x86_64-openbsd-none/amd64/tcb.h | 53 + .../x86_64-openbsd-none/amd64/timetc.h | 24 + .../include/x86_64-openbsd-none/amd64/trap.h | 65 + .../include/x86_64-openbsd-none/amd64/tss.h | 62 + .../x86_64-openbsd-none/amd64/vga_post.h | 43 + .../x86_64-openbsd-none/amd64/vmmvar.h | 1075 +++ .../x86_64-openbsd-none/amd64/vmparam.h | 114 + lib/libc/include/x86_64-openbsd-none/frame.h | 174 + .../x86_64-openbsd-none/machine/_float.h | 71 + .../x86_64-openbsd-none/machine/_types.h | 140 + .../x86_64-openbsd-none/machine/apicvar.h | 54 + .../x86_64-openbsd-none/machine/apmvar.h | 303 + .../include/x86_64-openbsd-none/machine/asm.h | 196 + .../x86_64-openbsd-none/machine/atomic.h | 325 + .../x86_64-openbsd-none/machine/biosvar.h | 283 + .../include/x86_64-openbsd-none/machine/bus.h | 706 ++ .../x86_64-openbsd-none/machine/cdefs.h | 21 + .../x86_64-openbsd-none/machine/codepatch.h | 120 + .../x86_64-openbsd-none/machine/conf.h | 59 + .../include/x86_64-openbsd-none/machine/cpu.h | 530 ++ .../x86_64-openbsd-none/machine/cpu_full.h | 70 + .../x86_64-openbsd-none/machine/cpufunc.h | 461 ++ .../x86_64-openbsd-none/machine/cpuvar.h | 100 + .../x86_64-openbsd-none/machine/db_machdep.h | 101 + .../x86_64-openbsd-none/machine/disklabel.h | 40 + .../x86_64-openbsd-none/machine/efifbvar.h | 40 + .../x86_64-openbsd-none/machine/efivar.h | 42 + .../x86_64-openbsd-none/machine/endian.h | 36 + .../x86_64-openbsd-none/machine/exec.h | 17 + .../x86_64-openbsd-none/machine/fenv.h | 115 + .../include/x86_64-openbsd-none/machine/fpu.h | 111 + .../x86_64-openbsd-none/machine/frame.h | 174 + .../x86_64-openbsd-none/machine/frameasm.h | 199 + .../include/x86_64-openbsd-none/machine/gdt.h | 33 + .../x86_64-openbsd-none/machine/ghcb.h | 251 + .../x86_64-openbsd-none/machine/hibernate.h | 36 + .../machine/hibernate_var.h | 75 + .../x86_64-openbsd-none/machine/i82093reg.h | 135 + .../x86_64-openbsd-none/machine/i82093var.h | 92 + .../x86_64-openbsd-none/machine/i82489reg.h | 149 + .../x86_64-openbsd-none/machine/i82489var.h | 124 + .../x86_64-openbsd-none/machine/i8259.h | 144 + .../x86_64-openbsd-none/machine/ieee.h | 142 + .../x86_64-openbsd-none/machine/ieeefp.h | 26 + .../x86_64-openbsd-none/machine/intr.h | 229 + .../x86_64-openbsd-none/machine/intrdefs.h | 93 + .../x86_64-openbsd-none/machine/ioctl_fd.h | 130 + .../x86_64-openbsd-none/machine/isa_machdep.h | 163 + .../x86_64-openbsd-none/machine/kcore.h | 47 + .../x86_64-openbsd-none/machine/limits.h | 52 + .../machine/loadfile_machdep.h | 61 + .../x86_64-openbsd-none/machine/mpbiosreg.h | 156 + .../x86_64-openbsd-none/machine/mpbiosvar.h | 57 + .../x86_64-openbsd-none/machine/mpconfig.h | 49 + .../x86_64-openbsd-none/machine/mplock.h | 10 + .../x86_64-openbsd-none/machine/mutex.h | 3 + .../x86_64-openbsd-none/machine/param.h | 81 + .../include/x86_64-openbsd-none/machine/pcb.h | 93 + .../x86_64-openbsd-none/machine/pci_machdep.h | 137 + .../x86_64-openbsd-none/machine/pctr.h | 73 + .../include/x86_64-openbsd-none/machine/pic.h | 45 + .../include/x86_64-openbsd-none/machine/pio.h | 225 + .../x86_64-openbsd-none/machine/pmap.h | 524 ++ .../x86_64-openbsd-none/machine/proc.h | 52 + .../x86_64-openbsd-none/machine/profile.h | 77 + .../include/x86_64-openbsd-none/machine/psl.h | 76 + .../include/x86_64-openbsd-none/machine/pte.h | 171 + .../x86_64-openbsd-none/machine/ptrace.h | 56 + .../machine/rbus_machdep.h | 48 + .../include/x86_64-openbsd-none/machine/reg.h | 125 + .../x86_64-openbsd-none/machine/reloc.h | 69 + .../x86_64-openbsd-none/machine/segments.h | 279 + .../x86_64-openbsd-none/machine/setjmp.h | 22 + .../x86_64-openbsd-none/machine/signal.h | 89 + .../x86_64-openbsd-none/machine/specialreg.h | 1645 +++++ .../x86_64-openbsd-none/machine/sysarch.h | 28 + .../include/x86_64-openbsd-none/machine/tcb.h | 53 + .../x86_64-openbsd-none/machine/timetc.h | 24 + .../x86_64-openbsd-none/machine/trap.h | 65 + .../include/x86_64-openbsd-none/machine/tss.h | 62 + .../x86_64-openbsd-none/machine/vga_post.h | 43 + .../x86_64-openbsd-none/machine/vmmvar.h | 1075 +++ .../x86_64-openbsd-none/machine/vmparam.h | 114 + 1747 files changed, 211943 insertions(+) create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/_float.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/_types.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/acpiapm.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/apmvar.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/armreg.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/asm.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/atomic.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/bootconfig.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/bus.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/cdefs.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/conf.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/cpu.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/cpufunc.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/db_machdep.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/disklabel.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/efivar.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/elf.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/endian.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/exec.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/fdt.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/fenv.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/fpu.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/frame.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/hypervisor.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/ieee.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/ieeefp.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/intr.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/kcore.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/limits.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/loadfile_machdep.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/mplock.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/mutex.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/openpromio.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/param.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/pcb.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/pci_machdep.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/pmap.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/proc.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/profile.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/pte.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/ptrace.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/reg.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/reloc.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/setjmp.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/signal.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/simplebusvar.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/smbiosvar.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/spinlock.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/sysarch.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/tcb.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/timetc.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/vmmvar.h create mode 100644 lib/libc/include/aarch64-openbsd-none/arm64/vmparam.h create mode 100644 lib/libc/include/aarch64-openbsd-none/frame.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/_float.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/_types.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/acpiapm.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/apmvar.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/armreg.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/asm.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/atomic.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/bootconfig.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/bus.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/cdefs.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/conf.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/cpu.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/cpufunc.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/db_machdep.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/disklabel.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/efivar.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/elf.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/endian.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/exec.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/fdt.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/fenv.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/fpu.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/frame.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/hypervisor.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/ieee.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/ieeefp.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/intr.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/kcore.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/limits.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/loadfile_machdep.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/mplock.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/mutex.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/openpromio.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/param.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/pcb.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/pci_machdep.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/pmap.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/proc.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/profile.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/pte.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/ptrace.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/reg.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/reloc.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/setjmp.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/signal.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/simplebusvar.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/smbiosvar.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/spinlock.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/sysarch.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/tcb.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/timetc.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/vmmvar.h create mode 100644 lib/libc/include/aarch64-openbsd-none/machine/vmparam.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/_float.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/_types.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/apmvar.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/armreg.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/asm.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/atomic.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/bus.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/cdefs.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/conf.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/cpu.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/cpuconf.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/cpufunc.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/db_machdep.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/disklabel.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/elf.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/endian.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/exec.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/fdt.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/fenv.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/fiq.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/frame.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/ieee.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/ieeefp.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/kcore.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/limits.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/machdep.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/mplock.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/mutex.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/openpromio.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/param.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/pcb.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/pci_machdep.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/pmap.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/proc.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/profile.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/pte.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/ptrace.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/reg.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/reloc.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/setjmp.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/signal.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/simplebusvar.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/spinlock.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/sysarch.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/sysreg.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/tcb.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/trap.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/undefined.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/vfp.h create mode 100644 lib/libc/include/arm-openbsd-eabi/arm/vmparam.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/_float.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/_types.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/apmvar.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/asm.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/atomic.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/bootconfig.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/bus.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/cdefs.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/conf.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/cpu.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/cpufunc.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/db_machdep.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/disklabel.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/elf.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/endian.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/exec.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/fdt.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/fenv.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/frame.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/ieee.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/ieeefp.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/intr.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/limits.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/loadfile_machdep.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/machine_reg.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/mplock.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/mutex.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/openpromio.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/param.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/pcb.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/pci_machdep.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/pmap.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/proc.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/profile.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/ptrace.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/reg.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/reloc.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/setjmp.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/signal.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/simplebusvar.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/spinlock.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/sysarch.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/tcb.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/timetc.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/trap.h create mode 100644 lib/libc/include/arm-openbsd-eabi/armv7/vmparam.h create mode 100644 lib/libc/include/arm-openbsd-eabi/frame.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/_float.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/_types.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/apmvar.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/asm.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/atomic.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/bootconfig.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/bus.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/cdefs.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/conf.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/cpu.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/cpufunc.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/db_machdep.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/disklabel.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/elf.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/endian.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/exec.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/fdt.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/fenv.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/frame.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/ieee.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/ieeefp.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/intr.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/limits.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/loadfile_machdep.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/machine_reg.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/mplock.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/mutex.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/openpromio.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/param.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/pcb.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/pci_machdep.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/pmap.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/proc.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/profile.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/ptrace.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/reg.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/reloc.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/setjmp.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/signal.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/simplebusvar.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/spinlock.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/sysarch.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/tcb.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/trap.h create mode 100644 lib/libc/include/arm-openbsd-eabi/machine/vmparam.h create mode 100644 lib/libc/include/generic-openbsd/a.out.h create mode 100644 lib/libc/include/generic-openbsd/ar.h create mode 100644 lib/libc/include/generic-openbsd/arpa/ftp.h create mode 100644 lib/libc/include/generic-openbsd/arpa/inet.h create mode 100644 lib/libc/include/generic-openbsd/arpa/nameser.h create mode 100644 lib/libc/include/generic-openbsd/arpa/telnet.h create mode 100644 lib/libc/include/generic-openbsd/arpa/tftp.h create mode 100644 lib/libc/include/generic-openbsd/asr.h create mode 100644 lib/libc/include/generic-openbsd/assert.h create mode 100644 lib/libc/include/generic-openbsd/ber.h create mode 100644 lib/libc/include/generic-openbsd/bitstring.h create mode 100644 lib/libc/include/generic-openbsd/blf.h create mode 100644 lib/libc/include/generic-openbsd/bsd_auth.h create mode 100644 lib/libc/include/generic-openbsd/complex.h create mode 100644 lib/libc/include/generic-openbsd/cpio.h create mode 100644 lib/libc/include/generic-openbsd/ctype.h create mode 100644 lib/libc/include/generic-openbsd/db.h create mode 100644 lib/libc/include/generic-openbsd/ddb/db_access.h create mode 100644 lib/libc/include/generic-openbsd/ddb/db_break.h create mode 100644 lib/libc/include/generic-openbsd/ddb/db_command.h create mode 100644 lib/libc/include/generic-openbsd/ddb/db_elf.h create mode 100644 lib/libc/include/generic-openbsd/ddb/db_extern.h create mode 100644 lib/libc/include/generic-openbsd/ddb/db_interface.h create mode 100644 lib/libc/include/generic-openbsd/ddb/db_lex.h create mode 100644 lib/libc/include/generic-openbsd/ddb/db_output.h create mode 100644 lib/libc/include/generic-openbsd/ddb/db_run.h create mode 100644 lib/libc/include/generic-openbsd/ddb/db_sym.h create mode 100644 lib/libc/include/generic-openbsd/ddb/db_var.h create mode 100644 lib/libc/include/generic-openbsd/ddb/db_variables.h create mode 100644 lib/libc/include/generic-openbsd/ddb/db_watch.h create mode 100644 lib/libc/include/generic-openbsd/dirent.h create mode 100644 lib/libc/include/generic-openbsd/dlfcn.h create mode 100644 lib/libc/include/generic-openbsd/elf.h create mode 100644 lib/libc/include/generic-openbsd/elf_abi.h create mode 100644 lib/libc/include/generic-openbsd/endian.h create mode 100644 lib/libc/include/generic-openbsd/err.h create mode 100644 lib/libc/include/generic-openbsd/errno.h create mode 100644 lib/libc/include/generic-openbsd/execinfo.h create mode 100644 lib/libc/include/generic-openbsd/fcntl.h create mode 100644 lib/libc/include/generic-openbsd/fenv.h create mode 100644 lib/libc/include/generic-openbsd/float.h create mode 100644 lib/libc/include/generic-openbsd/fnmatch.h create mode 100644 lib/libc/include/generic-openbsd/fstab.h create mode 100644 lib/libc/include/generic-openbsd/fts.h create mode 100644 lib/libc/include/generic-openbsd/ftw.h create mode 100644 lib/libc/include/generic-openbsd/getopt.h create mode 100644 lib/libc/include/generic-openbsd/glob.h create mode 100644 lib/libc/include/generic-openbsd/grp.h create mode 100644 lib/libc/include/generic-openbsd/icdb.h create mode 100644 lib/libc/include/generic-openbsd/ieeefp.h create mode 100644 lib/libc/include/generic-openbsd/ifaddrs.h create mode 100644 lib/libc/include/generic-openbsd/imsg.h create mode 100644 lib/libc/include/generic-openbsd/inttypes.h create mode 100644 lib/libc/include/generic-openbsd/iso646.h create mode 100644 lib/libc/include/generic-openbsd/isofs/cd9660/cd9660_extern.h create mode 100644 lib/libc/include/generic-openbsd/isofs/cd9660/cd9660_node.h create mode 100644 lib/libc/include/generic-openbsd/isofs/cd9660/cd9660_rrip.h create mode 100644 lib/libc/include/generic-openbsd/isofs/cd9660/iso.h create mode 100644 lib/libc/include/generic-openbsd/isofs/cd9660/iso_rrip.h create mode 100644 lib/libc/include/generic-openbsd/isofs/udf/ecma167-udf.h create mode 100644 lib/libc/include/generic-openbsd/isofs/udf/udf.h create mode 100644 lib/libc/include/generic-openbsd/isofs/udf/udf_extern.h create mode 100644 lib/libc/include/generic-openbsd/kvm.h create mode 100644 lib/libc/include/generic-openbsd/langinfo.h create mode 100644 lib/libc/include/generic-openbsd/libgen.h create mode 100644 lib/libc/include/generic-openbsd/limits.h create mode 100644 lib/libc/include/generic-openbsd/link.h create mode 100644 lib/libc/include/generic-openbsd/link_elf.h create mode 100644 lib/libc/include/generic-openbsd/locale.h create mode 100644 lib/libc/include/generic-openbsd/login_cap.h create mode 100644 lib/libc/include/generic-openbsd/machine/_float.h create mode 100644 lib/libc/include/generic-openbsd/machine/cdefs.h create mode 100644 lib/libc/include/generic-openbsd/machine/disklabel.h create mode 100644 lib/libc/include/generic-openbsd/machine/elf.h create mode 100644 lib/libc/include/generic-openbsd/machine/fenv.h create mode 100644 lib/libc/include/generic-openbsd/machine/loadfile_machdep.h create mode 100644 lib/libc/include/generic-openbsd/machine/mplock.h create mode 100644 lib/libc/include/generic-openbsd/machine/reloc.h create mode 100644 lib/libc/include/generic-openbsd/machine/smbiosvar.h create mode 100644 lib/libc/include/generic-openbsd/machine/spinlock.h create mode 100644 lib/libc/include/generic-openbsd/machine/tcb.h create mode 100644 lib/libc/include/generic-openbsd/machine/timetc.h create mode 100644 lib/libc/include/generic-openbsd/math.h create mode 100644 lib/libc/include/generic-openbsd/md5.h create mode 100644 lib/libc/include/generic-openbsd/memory.h create mode 100644 lib/libc/include/generic-openbsd/mips64/_float.h create mode 100644 lib/libc/include/generic-openbsd/mips64/_types.h create mode 100644 lib/libc/include/generic-openbsd/mips64/archtype.h create mode 100644 lib/libc/include/generic-openbsd/mips64/asm.h create mode 100644 lib/libc/include/generic-openbsd/mips64/atomic.h create mode 100644 lib/libc/include/generic-openbsd/mips64/autoconf.h create mode 100644 lib/libc/include/generic-openbsd/mips64/cache.h create mode 100644 lib/libc/include/generic-openbsd/mips64/cdefs.h create mode 100644 lib/libc/include/generic-openbsd/mips64/cpu.h create mode 100644 lib/libc/include/generic-openbsd/mips64/cpustate.h create mode 100644 lib/libc/include/generic-openbsd/mips64/db_machdep.h create mode 100644 lib/libc/include/generic-openbsd/mips64/elf.h create mode 100644 lib/libc/include/generic-openbsd/mips64/endian.h create mode 100644 lib/libc/include/generic-openbsd/mips64/exec.h create mode 100644 lib/libc/include/generic-openbsd/mips64/fenv.h create mode 100644 lib/libc/include/generic-openbsd/mips64/fpu.h create mode 100644 lib/libc/include/generic-openbsd/mips64/frame.h create mode 100644 lib/libc/include/generic-openbsd/mips64/ieee.h create mode 100644 lib/libc/include/generic-openbsd/mips64/ieeefp.h create mode 100644 lib/libc/include/generic-openbsd/mips64/kcore.h create mode 100644 lib/libc/include/generic-openbsd/mips64/limits.h create mode 100644 lib/libc/include/generic-openbsd/mips64/loongson2.h create mode 100644 lib/libc/include/generic-openbsd/mips64/loongson3.h create mode 100644 lib/libc/include/generic-openbsd/mips64/memconf.h create mode 100644 lib/libc/include/generic-openbsd/mips64/mips_cpu.h create mode 100644 lib/libc/include/generic-openbsd/mips64/mips_opcode.h create mode 100644 lib/libc/include/generic-openbsd/mips64/mplock.h create mode 100644 lib/libc/include/generic-openbsd/mips64/mutex.h create mode 100644 lib/libc/include/generic-openbsd/mips64/param.h create mode 100644 lib/libc/include/generic-openbsd/mips64/pcb.h create mode 100644 lib/libc/include/generic-openbsd/mips64/pmap.h create mode 100644 lib/libc/include/generic-openbsd/mips64/proc.h create mode 100644 lib/libc/include/generic-openbsd/mips64/profile.h create mode 100644 lib/libc/include/generic-openbsd/mips64/pte.h create mode 100644 lib/libc/include/generic-openbsd/mips64/ptrace.h create mode 100644 lib/libc/include/generic-openbsd/mips64/reg.h create mode 100644 lib/libc/include/generic-openbsd/mips64/regdef.h create mode 100644 lib/libc/include/generic-openbsd/mips64/regnum.h create mode 100644 lib/libc/include/generic-openbsd/mips64/reloc.h create mode 100644 lib/libc/include/generic-openbsd/mips64/setjmp.h create mode 100644 lib/libc/include/generic-openbsd/mips64/signal.h create mode 100644 lib/libc/include/generic-openbsd/mips64/spinlock.h create mode 100644 lib/libc/include/generic-openbsd/mips64/sysarch.h create mode 100644 lib/libc/include/generic-openbsd/mips64/tcb.h create mode 100644 lib/libc/include/generic-openbsd/mips64/timetc.h create mode 100644 lib/libc/include/generic-openbsd/mips64/trap.h create mode 100644 lib/libc/include/generic-openbsd/mips64/vmparam.h create mode 100644 lib/libc/include/generic-openbsd/miscfs/fifofs/fifo.h create mode 100644 lib/libc/include/generic-openbsd/miscfs/fuse/fusefs.h create mode 100644 lib/libc/include/generic-openbsd/miscfs/fuse/fusefs_node.h create mode 100644 lib/libc/include/generic-openbsd/msdosfs/bootsect.h create mode 100644 lib/libc/include/generic-openbsd/msdosfs/bpb.h create mode 100644 lib/libc/include/generic-openbsd/msdosfs/denode.h create mode 100644 lib/libc/include/generic-openbsd/msdosfs/direntry.h create mode 100644 lib/libc/include/generic-openbsd/msdosfs/fat.h create mode 100644 lib/libc/include/generic-openbsd/msdosfs/msdosfsmount.h create mode 100644 lib/libc/include/generic-openbsd/ndbm.h create mode 100644 lib/libc/include/generic-openbsd/net/art.h create mode 100644 lib/libc/include/generic-openbsd/net/bfd.h create mode 100644 lib/libc/include/generic-openbsd/net/bpf.h create mode 100644 lib/libc/include/generic-openbsd/net/bpfdesc.h create mode 100644 lib/libc/include/generic-openbsd/net/ethertypes.h create mode 100644 lib/libc/include/generic-openbsd/net/fq_codel.h create mode 100644 lib/libc/include/generic-openbsd/net/frame.h create mode 100644 lib/libc/include/generic-openbsd/net/hfsc.h create mode 100644 lib/libc/include/generic-openbsd/net/if.h create mode 100644 lib/libc/include/generic-openbsd/net/if_arp.h create mode 100644 lib/libc/include/generic-openbsd/net/if_bpe.h create mode 100644 lib/libc/include/generic-openbsd/net/if_bridge.h create mode 100644 lib/libc/include/generic-openbsd/net/if_dl.h create mode 100644 lib/libc/include/generic-openbsd/net/if_enc.h create mode 100644 lib/libc/include/generic-openbsd/net/if_etherbridge.h create mode 100644 lib/libc/include/generic-openbsd/net/if_etherip.h create mode 100644 lib/libc/include/generic-openbsd/net/if_gif.h create mode 100644 lib/libc/include/generic-openbsd/net/if_gre.h create mode 100644 lib/libc/include/generic-openbsd/net/if_llc.h create mode 100644 lib/libc/include/generic-openbsd/net/if_media.h create mode 100644 lib/libc/include/generic-openbsd/net/if_pflog.h create mode 100644 lib/libc/include/generic-openbsd/net/if_pflow.h create mode 100644 lib/libc/include/generic-openbsd/net/if_pfsync.h create mode 100644 lib/libc/include/generic-openbsd/net/if_ppp.h create mode 100644 lib/libc/include/generic-openbsd/net/if_pppoe.h create mode 100644 lib/libc/include/generic-openbsd/net/if_pppvar.h create mode 100644 lib/libc/include/generic-openbsd/net/if_sec.h create mode 100644 lib/libc/include/generic-openbsd/net/if_sppp.h create mode 100644 lib/libc/include/generic-openbsd/net/if_trunk.h create mode 100644 lib/libc/include/generic-openbsd/net/if_tun.h create mode 100644 lib/libc/include/generic-openbsd/net/if_types.h create mode 100644 lib/libc/include/generic-openbsd/net/if_var.h create mode 100644 lib/libc/include/generic-openbsd/net/if_vlan_var.h create mode 100644 lib/libc/include/generic-openbsd/net/if_wg.h create mode 100644 lib/libc/include/generic-openbsd/net/ifq.h create mode 100644 lib/libc/include/generic-openbsd/net/lldp.h create mode 100644 lib/libc/include/generic-openbsd/net/netisr.h create mode 100644 lib/libc/include/generic-openbsd/net/ofp.h create mode 100644 lib/libc/include/generic-openbsd/net/pfkeyv2.h create mode 100644 lib/libc/include/generic-openbsd/net/pfvar.h create mode 100644 lib/libc/include/generic-openbsd/net/pfvar_priv.h create mode 100644 lib/libc/include/generic-openbsd/net/pipex.h create mode 100644 lib/libc/include/generic-openbsd/net/pipex_local.h create mode 100644 lib/libc/include/generic-openbsd/net/ppp-comp.h create mode 100644 lib/libc/include/generic-openbsd/net/ppp_defs.h create mode 100644 lib/libc/include/generic-openbsd/net/radix.h create mode 100644 lib/libc/include/generic-openbsd/net/route.h create mode 100644 lib/libc/include/generic-openbsd/net/rtable.h create mode 100644 lib/libc/include/generic-openbsd/net/slcompress.h create mode 100644 lib/libc/include/generic-openbsd/net/toeplitz.h create mode 100644 lib/libc/include/generic-openbsd/net/trunklacp.h create mode 100644 lib/libc/include/generic-openbsd/net/wg_cookie.h create mode 100644 lib/libc/include/generic-openbsd/net/wg_noise.h create mode 100644 lib/libc/include/generic-openbsd/net80211/ieee80211.h create mode 100644 lib/libc/include/generic-openbsd/net80211/ieee80211_amrr.h create mode 100644 lib/libc/include/generic-openbsd/net80211/ieee80211_crypto.h create mode 100644 lib/libc/include/generic-openbsd/net80211/ieee80211_ioctl.h create mode 100644 lib/libc/include/generic-openbsd/net80211/ieee80211_node.h create mode 100644 lib/libc/include/generic-openbsd/net80211/ieee80211_priv.h create mode 100644 lib/libc/include/generic-openbsd/net80211/ieee80211_proto.h create mode 100644 lib/libc/include/generic-openbsd/net80211/ieee80211_ra.h create mode 100644 lib/libc/include/generic-openbsd/net80211/ieee80211_ra_vht.h create mode 100644 lib/libc/include/generic-openbsd/net80211/ieee80211_radiotap.h create mode 100644 lib/libc/include/generic-openbsd/net80211/ieee80211_regdomain.h create mode 100644 lib/libc/include/generic-openbsd/net80211/ieee80211_rssadapt.h create mode 100644 lib/libc/include/generic-openbsd/net80211/ieee80211_var.h create mode 100644 lib/libc/include/generic-openbsd/netdb.h create mode 100644 lib/libc/include/generic-openbsd/netgroup.h create mode 100644 lib/libc/include/generic-openbsd/netinet/icmp6.h create mode 100644 lib/libc/include/generic-openbsd/netinet/icmp_var.h create mode 100644 lib/libc/include/generic-openbsd/netinet/if_ether.h create mode 100644 lib/libc/include/generic-openbsd/netinet/igmp.h create mode 100644 lib/libc/include/generic-openbsd/netinet/igmp_var.h create mode 100644 lib/libc/include/generic-openbsd/netinet/in.h create mode 100644 lib/libc/include/generic-openbsd/netinet/in_pcb.h create mode 100644 lib/libc/include/generic-openbsd/netinet/in_systm.h create mode 100644 lib/libc/include/generic-openbsd/netinet/in_var.h create mode 100644 lib/libc/include/generic-openbsd/netinet/ip.h create mode 100644 lib/libc/include/generic-openbsd/netinet/ip6.h create mode 100644 lib/libc/include/generic-openbsd/netinet/ip_ah.h create mode 100644 lib/libc/include/generic-openbsd/netinet/ip_carp.h create mode 100644 lib/libc/include/generic-openbsd/netinet/ip_divert.h create mode 100644 lib/libc/include/generic-openbsd/netinet/ip_ecn.h create mode 100644 lib/libc/include/generic-openbsd/netinet/ip_esp.h create mode 100644 lib/libc/include/generic-openbsd/netinet/ip_ether.h create mode 100644 lib/libc/include/generic-openbsd/netinet/ip_gre.h create mode 100644 lib/libc/include/generic-openbsd/netinet/ip_icmp.h create mode 100644 lib/libc/include/generic-openbsd/netinet/ip_ipcomp.h create mode 100644 lib/libc/include/generic-openbsd/netinet/ip_ipip.h create mode 100644 lib/libc/include/generic-openbsd/netinet/ip_ipsp.h create mode 100644 lib/libc/include/generic-openbsd/netinet/ip_mroute.h create mode 100644 lib/libc/include/generic-openbsd/netinet/ip_var.h create mode 100644 lib/libc/include/generic-openbsd/netinet/tcp.h create mode 100644 lib/libc/include/generic-openbsd/netinet/tcp_debug.h create mode 100644 lib/libc/include/generic-openbsd/netinet/tcp_fsm.h create mode 100644 lib/libc/include/generic-openbsd/netinet/tcp_seq.h create mode 100644 lib/libc/include/generic-openbsd/netinet/tcp_timer.h create mode 100644 lib/libc/include/generic-openbsd/netinet/tcp_var.h create mode 100644 lib/libc/include/generic-openbsd/netinet/udp.h create mode 100644 lib/libc/include/generic-openbsd/netinet/udp_var.h create mode 100644 lib/libc/include/generic-openbsd/netinet6/in6.h create mode 100644 lib/libc/include/generic-openbsd/netinet6/in6_ifattach.h create mode 100644 lib/libc/include/generic-openbsd/netinet6/in6_var.h create mode 100644 lib/libc/include/generic-openbsd/netinet6/ip6_mroute.h create mode 100644 lib/libc/include/generic-openbsd/netinet6/ip6_var.h create mode 100644 lib/libc/include/generic-openbsd/netinet6/ip6protosw.h create mode 100644 lib/libc/include/generic-openbsd/netinet6/mld6.h create mode 100644 lib/libc/include/generic-openbsd/netinet6/mld6_var.h create mode 100644 lib/libc/include/generic-openbsd/netinet6/nd6.h create mode 100644 lib/libc/include/generic-openbsd/netinet6/raw_ip6.h create mode 100644 lib/libc/include/generic-openbsd/netmpls/mpls.h create mode 100644 lib/libc/include/generic-openbsd/nfs/krpc.h create mode 100644 lib/libc/include/generic-openbsd/nfs/nfs.h create mode 100644 lib/libc/include/generic-openbsd/nfs/nfs_var.h create mode 100644 lib/libc/include/generic-openbsd/nfs/nfsdiskless.h create mode 100644 lib/libc/include/generic-openbsd/nfs/nfsm_subs.h create mode 100644 lib/libc/include/generic-openbsd/nfs/nfsmount.h create mode 100644 lib/libc/include/generic-openbsd/nfs/nfsnode.h create mode 100644 lib/libc/include/generic-openbsd/nfs/nfsproto.h create mode 100644 lib/libc/include/generic-openbsd/nfs/nfsrvcache.h create mode 100644 lib/libc/include/generic-openbsd/nfs/rpcv2.h create mode 100644 lib/libc/include/generic-openbsd/nfs/xdr_subs.h create mode 100644 lib/libc/include/generic-openbsd/nl_types.h create mode 100644 lib/libc/include/generic-openbsd/nlist.h create mode 100644 lib/libc/include/generic-openbsd/ntfs/ntfs.h create mode 100644 lib/libc/include/generic-openbsd/ntfs/ntfs_compr.h create mode 100644 lib/libc/include/generic-openbsd/ntfs/ntfs_ihash.h create mode 100644 lib/libc/include/generic-openbsd/ntfs/ntfs_inode.h create mode 100644 lib/libc/include/generic-openbsd/ntfs/ntfs_subr.h create mode 100644 lib/libc/include/generic-openbsd/ntfs/ntfs_vfsops.h create mode 100644 lib/libc/include/generic-openbsd/ntfs/ntfsmount.h create mode 100644 lib/libc/include/generic-openbsd/ohash.h create mode 100644 lib/libc/include/generic-openbsd/paths.h create mode 100644 lib/libc/include/generic-openbsd/poll.h create mode 100644 lib/libc/include/generic-openbsd/protocols/dumprestore.h create mode 100644 lib/libc/include/generic-openbsd/protocols/routed.h create mode 100644 lib/libc/include/generic-openbsd/protocols/rwhod.h create mode 100644 lib/libc/include/generic-openbsd/protocols/talkd.h create mode 100644 lib/libc/include/generic-openbsd/protocols/timed.h create mode 100644 lib/libc/include/generic-openbsd/pthread.h create mode 100644 lib/libc/include/generic-openbsd/pthread_np.h create mode 100644 lib/libc/include/generic-openbsd/pwd.h create mode 100644 lib/libc/include/generic-openbsd/radius.h create mode 100644 lib/libc/include/generic-openbsd/ranlib.h create mode 100644 lib/libc/include/generic-openbsd/readpassphrase.h create mode 100644 lib/libc/include/generic-openbsd/regex.h create mode 100644 lib/libc/include/generic-openbsd/resolv.h create mode 100644 lib/libc/include/generic-openbsd/rmd160.h create mode 100644 lib/libc/include/generic-openbsd/rpc/auth.h create mode 100644 lib/libc/include/generic-openbsd/rpc/auth_unix.h create mode 100644 lib/libc/include/generic-openbsd/rpc/clnt.h create mode 100644 lib/libc/include/generic-openbsd/rpc/pmap_clnt.h create mode 100644 lib/libc/include/generic-openbsd/rpc/pmap_prot.h create mode 100644 lib/libc/include/generic-openbsd/rpc/pmap_rmt.h create mode 100644 lib/libc/include/generic-openbsd/rpc/rpc.h create mode 100644 lib/libc/include/generic-openbsd/rpc/rpc_des.h create mode 100644 lib/libc/include/generic-openbsd/rpc/rpc_msg.h create mode 100644 lib/libc/include/generic-openbsd/rpc/svc.h create mode 100644 lib/libc/include/generic-openbsd/rpc/svc_auth.h create mode 100644 lib/libc/include/generic-openbsd/rpc/types.h create mode 100644 lib/libc/include/generic-openbsd/rpc/xdr.h create mode 100644 lib/libc/include/generic-openbsd/sched.h create mode 100644 lib/libc/include/generic-openbsd/scsi/cd.h create mode 100644 lib/libc/include/generic-openbsd/scsi/iscsi.h create mode 100644 lib/libc/include/generic-openbsd/scsi/mpathvar.h create mode 100644 lib/libc/include/generic-openbsd/scsi/safte.h create mode 100644 lib/libc/include/generic-openbsd/scsi/scsi_all.h create mode 100644 lib/libc/include/generic-openbsd/scsi/scsi_changer.h create mode 100644 lib/libc/include/generic-openbsd/scsi/scsi_debug.h create mode 100644 lib/libc/include/generic-openbsd/scsi/scsi_disk.h create mode 100644 lib/libc/include/generic-openbsd/scsi/scsi_message.h create mode 100644 lib/libc/include/generic-openbsd/scsi/scsi_tape.h create mode 100644 lib/libc/include/generic-openbsd/scsi/scsiconf.h create mode 100644 lib/libc/include/generic-openbsd/scsi/sdvar.h create mode 100644 lib/libc/include/generic-openbsd/scsi/ses.h create mode 100644 lib/libc/include/generic-openbsd/search.h create mode 100644 lib/libc/include/generic-openbsd/semaphore.h create mode 100644 lib/libc/include/generic-openbsd/setjmp.h create mode 100644 lib/libc/include/generic-openbsd/sha1.h create mode 100644 lib/libc/include/generic-openbsd/sha2.h create mode 100644 lib/libc/include/generic-openbsd/signal.h create mode 100644 lib/libc/include/generic-openbsd/siphash.h create mode 100644 lib/libc/include/generic-openbsd/sndio.h create mode 100644 lib/libc/include/generic-openbsd/soundcard.h create mode 100644 lib/libc/include/generic-openbsd/spawn.h create mode 100644 lib/libc/include/generic-openbsd/stdarg.h create mode 100644 lib/libc/include/generic-openbsd/stdbool.h create mode 100644 lib/libc/include/generic-openbsd/stddef.h create mode 100644 lib/libc/include/generic-openbsd/stdint.h create mode 100644 lib/libc/include/generic-openbsd/stdio.h create mode 100644 lib/libc/include/generic-openbsd/stdio_ext.h create mode 100644 lib/libc/include/generic-openbsd/stdlib.h create mode 100644 lib/libc/include/generic-openbsd/string.h create mode 100644 lib/libc/include/generic-openbsd/strings.h create mode 100644 lib/libc/include/generic-openbsd/sys/_endian.h create mode 100644 lib/libc/include/generic-openbsd/sys/_lock.h create mode 100644 lib/libc/include/generic-openbsd/sys/_null.h create mode 100644 lib/libc/include/generic-openbsd/sys/_time.h create mode 100644 lib/libc/include/generic-openbsd/sys/_types.h create mode 100644 lib/libc/include/generic-openbsd/sys/acct.h create mode 100644 lib/libc/include/generic-openbsd/sys/ataio.h create mode 100644 lib/libc/include/generic-openbsd/sys/atomic.h create mode 100644 lib/libc/include/generic-openbsd/sys/audioio.h create mode 100644 lib/libc/include/generic-openbsd/sys/auxv.h create mode 100644 lib/libc/include/generic-openbsd/sys/blist.h create mode 100644 lib/libc/include/generic-openbsd/sys/buf.h create mode 100644 lib/libc/include/generic-openbsd/sys/cdefs.h create mode 100644 lib/libc/include/generic-openbsd/sys/cdio.h create mode 100644 lib/libc/include/generic-openbsd/sys/chio.h create mode 100644 lib/libc/include/generic-openbsd/sys/clockintr.h create mode 100644 lib/libc/include/generic-openbsd/sys/conf.h create mode 100644 lib/libc/include/generic-openbsd/sys/core.h create mode 100644 lib/libc/include/generic-openbsd/sys/ctf.h create mode 100644 lib/libc/include/generic-openbsd/sys/device.h create mode 100644 lib/libc/include/generic-openbsd/sys/dir.h create mode 100644 lib/libc/include/generic-openbsd/sys/dirent.h create mode 100644 lib/libc/include/generic-openbsd/sys/disk.h create mode 100644 lib/libc/include/generic-openbsd/sys/disklabel.h create mode 100644 lib/libc/include/generic-openbsd/sys/dkio.h create mode 100644 lib/libc/include/generic-openbsd/sys/domain.h create mode 100644 lib/libc/include/generic-openbsd/sys/endian.h create mode 100644 lib/libc/include/generic-openbsd/sys/errno.h create mode 100644 lib/libc/include/generic-openbsd/sys/evcount.h create mode 100644 lib/libc/include/generic-openbsd/sys/event.h create mode 100644 lib/libc/include/generic-openbsd/sys/eventvar.h create mode 100644 lib/libc/include/generic-openbsd/sys/exec.h create mode 100644 lib/libc/include/generic-openbsd/sys/exec_elf.h create mode 100644 lib/libc/include/generic-openbsd/sys/exec_script.h create mode 100644 lib/libc/include/generic-openbsd/sys/extent.h create mode 100644 lib/libc/include/generic-openbsd/sys/fcntl.h create mode 100644 lib/libc/include/generic-openbsd/sys/file.h create mode 100644 lib/libc/include/generic-openbsd/sys/filedesc.h create mode 100644 lib/libc/include/generic-openbsd/sys/filio.h create mode 100644 lib/libc/include/generic-openbsd/sys/fusebuf.h create mode 100644 lib/libc/include/generic-openbsd/sys/futex.h create mode 100644 lib/libc/include/generic-openbsd/sys/gmon.h create mode 100644 lib/libc/include/generic-openbsd/sys/gpio.h create mode 100644 lib/libc/include/generic-openbsd/sys/hibernate.h create mode 100644 lib/libc/include/generic-openbsd/sys/hotplug.h create mode 100644 lib/libc/include/generic-openbsd/sys/intrmap.h create mode 100644 lib/libc/include/generic-openbsd/sys/ioccom.h create mode 100644 lib/libc/include/generic-openbsd/sys/ioctl.h create mode 100644 lib/libc/include/generic-openbsd/sys/ipc.h create mode 100644 lib/libc/include/generic-openbsd/sys/kcore.h create mode 100644 lib/libc/include/generic-openbsd/sys/kcov.h create mode 100644 lib/libc/include/generic-openbsd/sys/kernel.h create mode 100644 lib/libc/include/generic-openbsd/sys/kstat.h create mode 100644 lib/libc/include/generic-openbsd/sys/kthread.h create mode 100644 lib/libc/include/generic-openbsd/sys/ktrace.h create mode 100644 lib/libc/include/generic-openbsd/sys/limits.h create mode 100644 lib/libc/include/generic-openbsd/sys/lock.h create mode 100644 lib/libc/include/generic-openbsd/sys/lockf.h create mode 100644 lib/libc/include/generic-openbsd/sys/malloc.h create mode 100644 lib/libc/include/generic-openbsd/sys/mbuf.h create mode 100644 lib/libc/include/generic-openbsd/sys/memrange.h create mode 100644 lib/libc/include/generic-openbsd/sys/mman.h create mode 100644 lib/libc/include/generic-openbsd/sys/mount.h create mode 100644 lib/libc/include/generic-openbsd/sys/mplock.h create mode 100644 lib/libc/include/generic-openbsd/sys/msg.h create mode 100644 lib/libc/include/generic-openbsd/sys/msgbuf.h create mode 100644 lib/libc/include/generic-openbsd/sys/mtio.h create mode 100644 lib/libc/include/generic-openbsd/sys/mutex.h create mode 100644 lib/libc/include/generic-openbsd/sys/namei.h create mode 100644 lib/libc/include/generic-openbsd/sys/param.h create mode 100644 lib/libc/include/generic-openbsd/sys/pciio.h create mode 100644 lib/libc/include/generic-openbsd/sys/pclock.h create mode 100644 lib/libc/include/generic-openbsd/sys/percpu.h create mode 100644 lib/libc/include/generic-openbsd/sys/pipe.h create mode 100644 lib/libc/include/generic-openbsd/sys/pledge.h create mode 100644 lib/libc/include/generic-openbsd/sys/poll.h create mode 100644 lib/libc/include/generic-openbsd/sys/pool.h create mode 100644 lib/libc/include/generic-openbsd/sys/proc.h create mode 100644 lib/libc/include/generic-openbsd/sys/protosw.h create mode 100644 lib/libc/include/generic-openbsd/sys/ptrace.h create mode 100644 lib/libc/include/generic-openbsd/sys/queue.h create mode 100644 lib/libc/include/generic-openbsd/sys/radioio.h create mode 100644 lib/libc/include/generic-openbsd/sys/reboot.h create mode 100644 lib/libc/include/generic-openbsd/sys/refcnt.h create mode 100644 lib/libc/include/generic-openbsd/sys/resource.h create mode 100644 lib/libc/include/generic-openbsd/sys/resourcevar.h create mode 100644 lib/libc/include/generic-openbsd/sys/rwlock.h create mode 100644 lib/libc/include/generic-openbsd/sys/sched.h create mode 100644 lib/libc/include/generic-openbsd/sys/scsiio.h create mode 100644 lib/libc/include/generic-openbsd/sys/select.h create mode 100644 lib/libc/include/generic-openbsd/sys/selinfo.h create mode 100644 lib/libc/include/generic-openbsd/sys/sem.h create mode 100644 lib/libc/include/generic-openbsd/sys/sensors.h create mode 100644 lib/libc/include/generic-openbsd/sys/shm.h create mode 100644 lib/libc/include/generic-openbsd/sys/siginfo.h create mode 100644 lib/libc/include/generic-openbsd/sys/sigio.h create mode 100644 lib/libc/include/generic-openbsd/sys/signal.h create mode 100644 lib/libc/include/generic-openbsd/sys/signalvar.h create mode 100644 lib/libc/include/generic-openbsd/sys/smr.h create mode 100644 lib/libc/include/generic-openbsd/sys/socket.h create mode 100644 lib/libc/include/generic-openbsd/sys/socketvar.h create mode 100644 lib/libc/include/generic-openbsd/sys/sockio.h create mode 100644 lib/libc/include/generic-openbsd/sys/softintr.h create mode 100644 lib/libc/include/generic-openbsd/sys/specdev.h create mode 100644 lib/libc/include/generic-openbsd/sys/srp.h create mode 100644 lib/libc/include/generic-openbsd/sys/stacktrace.h create mode 100644 lib/libc/include/generic-openbsd/sys/stat.h create mode 100644 lib/libc/include/generic-openbsd/sys/statvfs.h create mode 100644 lib/libc/include/generic-openbsd/sys/stdarg.h create mode 100644 lib/libc/include/generic-openbsd/sys/stdint.h create mode 100644 lib/libc/include/generic-openbsd/sys/swap.h create mode 100644 lib/libc/include/generic-openbsd/sys/syscall.h create mode 100644 lib/libc/include/generic-openbsd/sys/syscall_mi.h create mode 100644 lib/libc/include/generic-openbsd/sys/syscallargs.h create mode 100644 lib/libc/include/generic-openbsd/sys/sysctl.h create mode 100644 lib/libc/include/generic-openbsd/sys/syslimits.h create mode 100644 lib/libc/include/generic-openbsd/sys/syslog.h create mode 100644 lib/libc/include/generic-openbsd/sys/systm.h create mode 100644 lib/libc/include/generic-openbsd/sys/task.h create mode 100644 lib/libc/include/generic-openbsd/sys/termios.h create mode 100644 lib/libc/include/generic-openbsd/sys/time.h create mode 100644 lib/libc/include/generic-openbsd/sys/timeout.h create mode 100644 lib/libc/include/generic-openbsd/sys/times.h create mode 100644 lib/libc/include/generic-openbsd/sys/timetc.h create mode 100644 lib/libc/include/generic-openbsd/sys/tprintf.h create mode 100644 lib/libc/include/generic-openbsd/sys/tracepoint.h create mode 100644 lib/libc/include/generic-openbsd/sys/tree.h create mode 100644 lib/libc/include/generic-openbsd/sys/tty.h create mode 100644 lib/libc/include/generic-openbsd/sys/ttycom.h create mode 100644 lib/libc/include/generic-openbsd/sys/ttydefaults.h create mode 100644 lib/libc/include/generic-openbsd/sys/types.h create mode 100644 lib/libc/include/generic-openbsd/sys/ucred.h create mode 100644 lib/libc/include/generic-openbsd/sys/uio.h create mode 100644 lib/libc/include/generic-openbsd/sys/un.h create mode 100644 lib/libc/include/generic-openbsd/sys/unistd.h create mode 100644 lib/libc/include/generic-openbsd/sys/unpcb.h create mode 100644 lib/libc/include/generic-openbsd/sys/user.h create mode 100644 lib/libc/include/generic-openbsd/sys/utsname.h create mode 100644 lib/libc/include/generic-openbsd/sys/uuid.h create mode 100644 lib/libc/include/generic-openbsd/sys/varargs.h create mode 100644 lib/libc/include/generic-openbsd/sys/videoio.h create mode 100644 lib/libc/include/generic-openbsd/sys/vmmeter.h create mode 100644 lib/libc/include/generic-openbsd/sys/vnode.h create mode 100644 lib/libc/include/generic-openbsd/sys/wait.h create mode 100644 lib/libc/include/generic-openbsd/sys/witness.h create mode 100644 lib/libc/include/generic-openbsd/sys/xcall.h create mode 100644 lib/libc/include/generic-openbsd/sysexits.h create mode 100644 lib/libc/include/generic-openbsd/syslog.h create mode 100644 lib/libc/include/generic-openbsd/tar.h create mode 100644 lib/libc/include/generic-openbsd/termios.h create mode 100644 lib/libc/include/generic-openbsd/tgmath.h create mode 100644 lib/libc/include/generic-openbsd/tib.h create mode 100644 lib/libc/include/generic-openbsd/time.h create mode 100644 lib/libc/include/generic-openbsd/ttyent.h create mode 100644 lib/libc/include/generic-openbsd/uchar.h create mode 100644 lib/libc/include/generic-openbsd/ufs/ext2fs/ext2fs.h create mode 100644 lib/libc/include/generic-openbsd/ufs/ext2fs/ext2fs_dinode.h create mode 100644 lib/libc/include/generic-openbsd/ufs/ext2fs/ext2fs_dir.h create mode 100644 lib/libc/include/generic-openbsd/ufs/ext2fs/ext2fs_extents.h create mode 100644 lib/libc/include/generic-openbsd/ufs/ext2fs/ext2fs_extern.h create mode 100644 lib/libc/include/generic-openbsd/ufs/ffs/ffs_extern.h create mode 100644 lib/libc/include/generic-openbsd/ufs/ffs/fs.h create mode 100644 lib/libc/include/generic-openbsd/ufs/mfs/mfs_extern.h create mode 100644 lib/libc/include/generic-openbsd/ufs/mfs/mfsnode.h create mode 100644 lib/libc/include/generic-openbsd/ufs/ufs/dinode.h create mode 100644 lib/libc/include/generic-openbsd/ufs/ufs/dir.h create mode 100644 lib/libc/include/generic-openbsd/ufs/ufs/dirhash.h create mode 100644 lib/libc/include/generic-openbsd/ufs/ufs/inode.h create mode 100644 lib/libc/include/generic-openbsd/ufs/ufs/quota.h create mode 100644 lib/libc/include/generic-openbsd/ufs/ufs/ufs_extern.h create mode 100644 lib/libc/include/generic-openbsd/ufs/ufs/ufsmount.h create mode 100644 lib/libc/include/generic-openbsd/unistd.h create mode 100644 lib/libc/include/generic-openbsd/usbhid.h create mode 100644 lib/libc/include/generic-openbsd/util.h create mode 100644 lib/libc/include/generic-openbsd/utime.h create mode 100644 lib/libc/include/generic-openbsd/utmp.h create mode 100644 lib/libc/include/generic-openbsd/uuid.h create mode 100644 lib/libc/include/generic-openbsd/uvm/uvm.h create mode 100644 lib/libc/include/generic-openbsd/uvm/uvm_addr.h create mode 100644 lib/libc/include/generic-openbsd/uvm/uvm_amap.h create mode 100644 lib/libc/include/generic-openbsd/uvm/uvm_anon.h create mode 100644 lib/libc/include/generic-openbsd/uvm/uvm_aobj.h create mode 100644 lib/libc/include/generic-openbsd/uvm/uvm_ddb.h create mode 100644 lib/libc/include/generic-openbsd/uvm/uvm_device.h create mode 100644 lib/libc/include/generic-openbsd/uvm/uvm_extern.h create mode 100644 lib/libc/include/generic-openbsd/uvm/uvm_fault.h create mode 100644 lib/libc/include/generic-openbsd/uvm/uvm_glue.h create mode 100644 lib/libc/include/generic-openbsd/uvm/uvm_km.h create mode 100644 lib/libc/include/generic-openbsd/uvm/uvm_map.h create mode 100644 lib/libc/include/generic-openbsd/uvm/uvm_object.h create mode 100644 lib/libc/include/generic-openbsd/uvm/uvm_page.h create mode 100644 lib/libc/include/generic-openbsd/uvm/uvm_pager.h create mode 100644 lib/libc/include/generic-openbsd/uvm/uvm_param.h create mode 100644 lib/libc/include/generic-openbsd/uvm/uvm_percpu.h create mode 100644 lib/libc/include/generic-openbsd/uvm/uvm_pmap.h create mode 100644 lib/libc/include/generic-openbsd/uvm/uvm_pmemrange.h create mode 100644 lib/libc/include/generic-openbsd/uvm/uvm_swap.h create mode 100644 lib/libc/include/generic-openbsd/uvm/uvm_swap_encrypt.h create mode 100644 lib/libc/include/generic-openbsd/uvm/uvm_vnode.h create mode 100644 lib/libc/include/generic-openbsd/uvm/uvmexp.h create mode 100644 lib/libc/include/generic-openbsd/varargs.h create mode 100644 lib/libc/include/generic-openbsd/vis.h create mode 100644 lib/libc/include/generic-openbsd/wchar.h create mode 100644 lib/libc/include/generic-openbsd/wctype.h create mode 100644 lib/libc/include/mips64-openbsd-none/frame.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/_types.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/asm.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/atomic.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/autoconf.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/bus.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/conf.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/cpu.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/cpustate.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/db_machdep.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/elf.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/endian.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/exec.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/fdt.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/fpu.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/frame.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/ieee.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/ieeefp.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/intr.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/kcore.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/limits.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/memconf.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/mips_opcode.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/mplock.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/mutex.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/octboot.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/octeon_model.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/octeonreg.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/octeonvar.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/openpromio.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/param.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/pcb.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/pci_machdep.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/pmap.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/proc.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/profile.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/pte.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/ptrace.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/reg.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/regdef.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/regnum.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/setjmp.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/signal.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/simplebusvar.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/spinlock.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/sysarch.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/timetc.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/trap.h create mode 100644 lib/libc/include/mips64-openbsd-none/machine/vmparam.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/_float.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/_types.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/asm.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/atomic.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/autoconf.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/bus.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/cdefs.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/conf.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/cpu.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/cpustate.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/db_machdep.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/disklabel.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/elf.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/endian.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/exec.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/fdt.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/fenv.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/fpu.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/frame.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/ieee.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/ieeefp.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/intr.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/kcore.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/limits.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/loadfile_machdep.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/memconf.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/mips_opcode.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/mplock.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/mutex.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/octboot.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/octeon_model.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/octeonreg.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/octeonvar.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/openpromio.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/param.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/pcb.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/pci_machdep.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/pmap.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/proc.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/profile.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/pte.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/ptrace.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/reg.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/regdef.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/regnum.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/reloc.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/setjmp.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/signal.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/simplebusvar.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/spinlock.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/sysarch.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/tcb.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/timetc.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/trap.h create mode 100644 lib/libc/include/mips64-openbsd-none/octeon/vmparam.h create mode 100644 lib/libc/include/mips64el-openbsd-none/frame.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/_float.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/_types.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/apmvar.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/asm.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/atomic.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/autoconf.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/bus.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/cdefs.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/conf.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/cpu.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/cpustate.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/db_machdep.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/disklabel.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/elf.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/endian.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/exec.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/fenv.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/fpu.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/frame.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/hibernate.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/hibernate_var.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/ieee.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/ieeefp.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/intr.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/isa_machdep.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/kcore.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/limits.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/loadfile_machdep.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/loongson2.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/loongson3.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/memconf.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/mips_opcode.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/mplock.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/mutex.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/param.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/pcb.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/pci_machdep.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/pmap.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/pmon.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/proc.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/profile.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/pte.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/ptrace.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/reg.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/regdef.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/regnum.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/reloc.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/setjmp.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/signal.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/spinlock.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/sysarch.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/tcb.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/timetc.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/trap.h create mode 100644 lib/libc/include/mips64el-openbsd-none/loongson/vmparam.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/_types.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/apmvar.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/asm.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/atomic.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/autoconf.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/bus.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/conf.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/cpu.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/cpustate.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/db_machdep.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/elf.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/endian.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/exec.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/fpu.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/frame.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/hibernate.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/hibernate_var.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/ieee.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/ieeefp.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/intr.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/isa_machdep.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/kcore.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/limits.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/loongson2.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/loongson3.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/memconf.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/mips_opcode.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/mplock.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/mutex.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/param.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/pcb.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/pci_machdep.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/pmap.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/pmon.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/proc.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/profile.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/pte.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/ptrace.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/reg.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/regdef.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/regnum.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/setjmp.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/signal.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/spinlock.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/sysarch.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/timetc.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/trap.h create mode 100644 lib/libc/include/mips64el-openbsd-none/machine/vmparam.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/frame.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/_float.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/_types.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/apmvar.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/asm.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/atomic.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/autoconf.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/bus.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/cdefs.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/conf.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/cpu.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/db_machdep.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/disklabel.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/elf.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/endian.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/exec.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/fenv.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/fpu.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/frame.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/ieee.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/ieeefp.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/intr.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/kcore.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/limits.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/loadfile_machdep.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/mplock.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/mutex.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/openpromio.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/param.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/pcb.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/pci_machdep.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/pio.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/pmap.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/proc.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/profile.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/psl.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/pte.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/ptrace.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/rbus_machdep.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/reg.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/reloc.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/setjmp.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/signal.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/spinlock.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/tcb.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/timetc.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/trap.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/vmparam.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/machine/z8530var.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/_float.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/_types.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/apmvar.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/asm.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/atomic.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/autoconf.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/bus.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/cdefs.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/conf.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/cpu.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/db_machdep.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/disklabel.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/elf.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/endian.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/exec.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/fenv.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/fpu.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/frame.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/ieee.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/ieeefp.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/intr.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/kcore.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/limits.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/loadfile_machdep.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/mplock.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/mutex.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/openpromio.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/param.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/pcb.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/pci_machdep.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/pio.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/pmap.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/proc.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/profile.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/psl.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/pte.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/ptrace.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/rbus_machdep.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/reg.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/reloc.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/setjmp.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/signal.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/spinlock.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/tcb.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/timetc.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/trap.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/vmparam.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/macppc/z8530var.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/_float.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/_types.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/asm.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/atomic.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/bat.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/cdefs.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/cpu.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/db_machdep.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/elf.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/endian.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/exec.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/fenv.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/fpu.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/frame.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/hid.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/ieee.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/ieeefp.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/intr.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/kcore.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/limits.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/mplock.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/mutex.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/param.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/pcb.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/pio.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/pmap.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/powerpc.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/proc.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/profile.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/psl.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/pte.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/ptrace.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/reg.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/reloc.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/setjmp.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/signal.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/spinlock.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/tcb.h create mode 100644 lib/libc/include/powerpc-openbsd-eabihf/powerpc/trap.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/frame.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/_float.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/_types.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/apmvar.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/asm.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/atomic.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/bus.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/cdefs.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/conf.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/cpu.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/cpufunc.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/db_machdep.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/disklabel.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/elf.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/endian.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/exec.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/fdt.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/fenv.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/fpu.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/frame.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/ieee.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/ieeefp.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/intr.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/kcore.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/kexec.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/limits.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/mplock.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/mutex.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/opal.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/openpromio.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/param.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/pcb.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/pci_machdep.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/pmap.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/proc.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/profile.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/psl.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/pte.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/ptrace.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/reg.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/reloc.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/setjmp.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/signal.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/smbiosvar.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/spinlock.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/tcb.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/timetc.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/trap.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/machine/vmparam.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/_float.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/_types.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/apmvar.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/asm.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/atomic.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/bus.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/cdefs.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/conf.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/cpu.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/cpufunc.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/db_machdep.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/disklabel.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/elf.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/endian.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/exec.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/fdt.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/fenv.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/fpu.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/frame.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/ieee.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/ieeefp.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/intr.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/kcore.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/kexec.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/limits.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/mplock.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/mutex.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/opal.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/openpromio.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/param.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/pcb.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/pci_machdep.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/pmap.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/proc.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/profile.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/psl.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/pte.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/ptrace.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/reg.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/reloc.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/setjmp.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/signal.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/smbiosvar.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/spinlock.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/tcb.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/timetc.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/trap.h create mode 100644 lib/libc/include/powerpc64-openbsd-none/powerpc64/vmparam.h create mode 100644 lib/libc/include/riscv64-openbsd-none/frame.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/_float.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/_types.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/apmvar.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/asm.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/atomic.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/bootconfig.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/bus.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/cdefs.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/conf.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/cpu.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/cpufunc.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/db_machdep.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/disklabel.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/elf.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/endian.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/exec.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/fdt.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/fenv.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/frame.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/ieee.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/ieeefp.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/intr.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/kcore.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/limits.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/loadfile_machdep.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/mplock.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/mutex.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/openpromio.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/param.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/pcb.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/pci_machdep.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/pmap.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/proc.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/profile.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/pte.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/ptrace.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/reg.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/reloc.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/riscvreg.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/sbi.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/setjmp.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/signal.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/simplebusvar.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/spinlock.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/sysarch.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/syscall.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/tcb.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/timetc.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/trap.h create mode 100644 lib/libc/include/riscv64-openbsd-none/machine/vmparam.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/_float.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/_types.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/apmvar.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/asm.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/atomic.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/bootconfig.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/bus.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/cdefs.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/conf.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/cpu.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/cpufunc.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/db_machdep.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/disklabel.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/elf.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/endian.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/exec.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/fdt.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/fenv.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/frame.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/ieee.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/ieeefp.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/intr.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/kcore.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/limits.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/loadfile_machdep.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/mplock.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/mutex.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/openpromio.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/param.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/pcb.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/pci_machdep.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/pmap.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/proc.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/profile.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/pte.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/ptrace.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/reg.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/reloc.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/riscvreg.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/sbi.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/setjmp.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/signal.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/simplebusvar.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/spinlock.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/sysarch.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/syscall.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/tcb.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/timetc.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/trap.h create mode 100644 lib/libc/include/riscv64-openbsd-none/riscv64/vmparam.h create mode 100644 lib/libc/include/sparc64-openbsd-none/frame.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/_float.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/_types.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/apmvar.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/asm.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/atomic.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/autoconf.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/boot_flag.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/bppioctl.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/bus.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/cdefs.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/conf.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/cpu.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/ctlreg.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/db_machdep.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/disklabel.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/elf.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/endian.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/exec.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/fbvar.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/fenv.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/frame.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/fsr.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/hypervisor.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/idprom.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/ieee.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/ieeefp.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/instr.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/intr.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/ioctl_fd.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/kcore.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/limits.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/loadfile_machdep.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/mdesc.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/mutex.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/openfirm.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/openpromio.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/param.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/pcb.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/pci_machdep.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/pmap.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/proc.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/profile.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/psl.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/pte.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/ptrace.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/rbus_machdep.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/reg.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/reloc.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/setjmp.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/signal.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/sparc64.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/spinlock.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/tcb.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/timetc.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/trap.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/vmparam.h create mode 100644 lib/libc/include/sparc64-openbsd-none/machine/z8530var.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/_float.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/_types.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/apmvar.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/asm.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/atomic.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/autoconf.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/boot_flag.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/bppioctl.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/bus.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/cdefs.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/conf.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/cpu.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/ctlreg.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/db_machdep.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/disklabel.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/elf.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/endian.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/exec.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/fbvar.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/fenv.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/frame.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/fsr.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/hypervisor.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/idprom.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/ieee.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/ieeefp.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/instr.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/intr.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/ioctl_fd.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/kcore.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/limits.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/loadfile_machdep.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/mdesc.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/mplock.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/mutex.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/openfirm.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/openpromio.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/param.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/pcb.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/pci_machdep.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/pmap.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/proc.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/profile.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/psl.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/pte.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/ptrace.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/rbus_machdep.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/reg.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/reloc.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/setjmp.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/signal.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/sparc64.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/spinlock.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/tcb.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/timetc.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/trap.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/vmparam.h create mode 100644 lib/libc/include/sparc64-openbsd-none/sparc64/z8530var.h create mode 100644 lib/libc/include/x86-openbsd-none/frame.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/_float.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/_types.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/acpiapm.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/amdmsr.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/apicvar.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/apmvar.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/asm.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/atomic.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/biosvar.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/bus.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/cdefs.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/codepatch.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/conf.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/cpu.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/cpu_full.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/cpufunc.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/cputypes.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/cpuvar.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/db_machdep.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/disklabel.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/elf.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/endian.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/exec.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/fenv.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/frame.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/gdt.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/hibernate.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/hibernate_var.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/i82093reg.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/i82093var.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/i82489reg.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/i82489var.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/i8259.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/ieee.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/ieeefp.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/intr.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/intrdefs.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/ioctl_fd.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/joystick.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/kcore.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/limits.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/loadfile_machdep.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/mpbiosreg.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/mpbiosvar.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/mplock.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/mutex.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/npx.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/param.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/pcb.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/pctr.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/pic.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/pio.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/pmap.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/proc.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/profile.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/psl.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/pte.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/ptrace.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/rbus_machdep.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/reg.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/reloc.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/segments.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/setjmp.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/signal.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/smbiosvar.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/specialreg.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/spinlock.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/sysarch.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/tcb.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/timetc.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/trap.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/tss.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/vga_post.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/vmmvar.h create mode 100644 lib/libc/include/x86-openbsd-none/i386/vmparam.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/_float.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/_types.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/acpiapm.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/amdmsr.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/apicvar.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/apmvar.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/asm.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/atomic.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/biosvar.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/bus.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/cdefs.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/codepatch.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/conf.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/cpu.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/cpu_full.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/cpufunc.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/cputypes.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/cpuvar.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/db_machdep.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/disklabel.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/endian.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/exec.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/fenv.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/frame.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/gdt.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/hibernate.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/hibernate_var.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/i82093reg.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/i82093var.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/i82489reg.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/i82489var.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/i8259.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/ieee.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/ieeefp.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/intr.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/intrdefs.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/ioctl_fd.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/joystick.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/kcore.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/limits.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/loadfile_machdep.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/mpbiosreg.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/mpbiosvar.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/mutex.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/npx.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/param.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/pcb.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/pctr.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/pic.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/pio.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/pmap.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/proc.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/profile.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/psl.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/pte.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/ptrace.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/rbus_machdep.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/reg.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/reloc.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/segments.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/setjmp.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/signal.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/specialreg.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/sysarch.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/tcb.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/trap.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/tss.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/vga_post.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/vmmvar.h create mode 100644 lib/libc/include/x86-openbsd-none/machine/vmparam.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/_float.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/_types.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/apicvar.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/apmvar.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/asm.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/atomic.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/biosvar.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/bus.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/cdefs.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/codepatch.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/conf.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/cpu.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/cpu_full.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/cpufunc.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/cpuvar.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/db_machdep.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/disklabel.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/efifbvar.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/efivar.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/elf.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/endian.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/exec.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/fenv.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/fpu.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/frame.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/frameasm.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/gdt.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/ghcb.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/hibernate.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/hibernate_var.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/i82093reg.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/i82093var.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/i82489reg.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/i82489var.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/i8259.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/ieee.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/ieeefp.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/intr.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/intrdefs.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/ioctl_fd.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/isa_machdep.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/kcore.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/limits.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/loadfile_machdep.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/mpbiosreg.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/mpbiosvar.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/mpconfig.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/mplock.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/mutex.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/param.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/pcb.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/pci_machdep.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/pctr.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/pic.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/pio.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/pmap.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/proc.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/profile.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/psl.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/pte.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/ptrace.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/rbus_machdep.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/reg.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/reloc.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/segments.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/setjmp.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/signal.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/smbiosvar.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/specialreg.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/spinlock.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/sysarch.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/tcb.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/timetc.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/trap.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/tss.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/vga_post.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/vmmvar.h create mode 100644 lib/libc/include/x86_64-openbsd-none/amd64/vmparam.h create mode 100644 lib/libc/include/x86_64-openbsd-none/frame.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/_float.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/_types.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/apicvar.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/apmvar.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/asm.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/atomic.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/biosvar.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/bus.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/cdefs.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/codepatch.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/conf.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/cpu.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/cpu_full.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/cpufunc.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/cpuvar.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/db_machdep.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/disklabel.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/efifbvar.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/efivar.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/endian.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/exec.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/fenv.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/fpu.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/frame.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/frameasm.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/gdt.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/ghcb.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/hibernate.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/hibernate_var.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/i82093reg.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/i82093var.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/i82489reg.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/i82489var.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/i8259.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/ieee.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/ieeefp.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/intr.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/intrdefs.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/ioctl_fd.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/isa_machdep.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/kcore.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/limits.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/loadfile_machdep.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/mpbiosreg.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/mpbiosvar.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/mpconfig.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/mplock.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/mutex.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/param.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/pcb.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/pci_machdep.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/pctr.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/pic.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/pio.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/pmap.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/proc.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/profile.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/psl.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/pte.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/ptrace.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/rbus_machdep.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/reg.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/reloc.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/segments.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/setjmp.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/signal.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/specialreg.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/sysarch.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/tcb.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/timetc.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/trap.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/tss.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/vga_post.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/vmmvar.h create mode 100644 lib/libc/include/x86_64-openbsd-none/machine/vmparam.h diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/_float.h b/lib/libc/include/aarch64-openbsd-none/arm64/_float.h new file mode 100644 index 0000000000..ea467e6f21 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/_float.h @@ -0,0 +1,96 @@ +/* $OpenBSD: _float.h,v 1.1 2016/12/17 23:38:33 patrick Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + */ + +#ifndef _MACHINE__FLOAT_H_ +#define _MACHINE__FLOAT_H_ + +#define __FLT_RADIX 2 /* b */ +#define __FLT_ROUNDS __flt_rounds() +#define __FLT_EVAL_METHOD 0 /* no promotions */ + +#define __FLT_MANT_DIG 24 /* p */ +#define __FLT_EPSILON 1.19209290E-7F /* b**(1-p) */ +#define __FLT_DIG 6 /* floor((p-1)*log10(b))+(b == 10) */ +#define __FLT_MIN_EXP (-125) /* emin */ +#define __FLT_MIN 1.17549435E-38F /* b**(emin-1) */ +#define __FLT_MIN_10_EXP (-37) /* ceil(log10(b**(emin-1))) */ +#define __FLT_MAX_EXP 128 /* emax */ +#define __FLT_MAX 3.40282347E+38F /* (1-b**(-p))*b**emax */ +#define __FLT_MAX_10_EXP 38 /* floor(log10((1-b**(-p))*b**emax)) */ + +#define __DBL_MANT_DIG 53 +#define __DBL_EPSILON 2.2204460492503131E-16 +#define __DBL_DIG 15 +#define __DBL_MIN_EXP (-1021) +#define __DBL_MIN 2.2250738585072014E-308 +#define __DBL_MIN_10_EXP (-307) +#define __DBL_MAX_EXP 1024 +#define __DBL_MAX 1.7976931348623157E+308 +#define __DBL_MAX_10_EXP 308 + +#ifdef __LDBL_MANT_DIG__ +#define __LDBL_MANT_DIG __LDBL_MANT_DIG__ +#define __LDBL_EPSILON __LDBL_EPSILON__ +#define __LDBL_DIG __LDBL_DIG__ +#define __LDBL_MIN_EXP __LDBL_MIN_EXP__ +#define __LDBL_MIN __LDBL_MIN__ +#define __LDBL_MIN_10_EXP __LDBL_MIN_10_EXP__ +#define __LDBL_MAX_EXP __LDBL_MAX_EXP__ +#define __LDBL_MAX __LDBL_MAX__ +#define __LDBL_MAX_10_EXP __LDBL_MAX_10_EXP__ +#else +#define __LDBL_MANT_DIG DBL_MANT_DIG +#define __LDBL_EPSILON DBL_EPSILON +#define __LDBL_DIG DBL_DIG +#define __LDBL_MIN_EXP DBL_MIN_EXP +#define __LDBL_MIN DBL_MIN +#define __LDBL_MIN_10_EXP DBL_MIN_10_EXP +#define __LDBL_MAX_EXP DBL_MAX_EXP +#define __LDBL_MAX DBL_MAX +#define __LDBL_MAX_10_EXP DBL_MAX_10_EXP +#endif + +#define __DECIMAL_DIG 17 + +#endif /* _MACHINE__FLOAT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/_types.h b/lib/libc/include/aarch64-openbsd-none/arm64/_types.h new file mode 100644 index 0000000000..2de0c9d512 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/_types.h @@ -0,0 +1,145 @@ +/* $OpenBSD: _types.h,v 1.6 2023/07/02 19:02:27 cheloha 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_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/acpiapm.h b/lib/libc/include/aarch64-openbsd-none/arm64/acpiapm.h new file mode 100644 index 0000000000..9664811d2b --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/acpiapm.h @@ -0,0 +1,22 @@ +/* $OpenBSD: acpiapm.h,v 1.1 2019/01/23 09:57:36 phessler Exp $ */ +/* + * Copyright (c) 2007 Ted Unangst + * + * 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. + */ + + +extern int (*acpiapm_open)(dev_t, int, int, struct proc *); +extern int (*acpiapm_close)(dev_t, int, int, struct proc *); +extern int (*acpiapm_ioctl)(dev_t, u_long, caddr_t, int, struct proc *); +extern int (*acpiapm_kqfilter)(dev_t, struct knote *); \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/apmvar.h b/lib/libc/include/aarch64-openbsd-none/arm64/apmvar.h new file mode 100644 index 0000000000..f824cfe204 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/apmvar.h @@ -0,0 +1,127 @@ +/* $OpenBSD: apmvar.h,v 1.3 2023/01/22 13:14:21 kettenis Exp $ */ + +/* + * Copyright (c) 2001 Alexander Guy + * Copyright (c) 1995 John T. Kohl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef _MACHINE_APMVAR_H_ +#define _MACHINE_APMVAR_H_ + +#include + +/* Advanced Power Management (v1.0 and v1.1 specification) + * functions/defines/etc. + */ + +/* These definitions make up the heart of the user-land interface + * to the APM devices. + */ + +#define APM_AC_OFF 0x00 +#define APM_AC_ON 0x01 +#define APM_AC_BACKUP 0x02 +#define APM_AC_UNKNOWN 0xff +#define APM_BATT_HIGH 0x00 +#define APM_BATT_LOW 0x01 +#define APM_BATT_CRITICAL 0x02 +#define APM_BATT_CHARGING 0x03 +#define APM_BATT_UNKNOWN 0xff +#define APM_BATT_LIFE_UNKNOWN 0xff + +#define APM_NOEVENT 0x0000 +#define APM_STANDBY_REQ 0x0001 +#define APM_SUSPEND_REQ 0x0002 +#define APM_NORMAL_RESUME 0x0003 +#define APM_CRIT_RESUME 0x0004 /* suspend/resume happened + without us */ +#define APM_BATTERY_LOW 0x0005 +#define APM_POWER_CHANGE 0x0006 +#define APM_UPDATE_TIME 0x0007 +#define APM_CRIT_SUSPEND_REQ 0x0008 +#define APM_USER_STANDBY_REQ 0x0009 +#define APM_USER_SUSPEND_REQ 0x000A +#define APM_SYS_STANDBY_RESUME 0x000B +#define APM_CAPABILITY_CHANGE 0x000C /* apm v1.2 */ +#define APM_USER_HIBERNATE_REQ 0x000D +#define APM_EVENT_MASK 0xffff + +#define APM_EVENT_COMPOSE(t,i) ((((i) & 0x7fff) << 16)|((t) & APM_EVENT_MASK)) +#define APM_EVENT_TYPE(e) ((e) & APM_EVENT_MASK) +#define APM_EVENT_INDEX(e) ((e) >> 16) + +/* + * LP (Laptop Package) + * + * Copyright (C) 1994 by HOSOKAWA Tatsumi + * + * This software may be used, modified, copied, and distributed, in + * both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + */ + +#define APM_BATTERY_ABSENT 4 + +struct apm_power_info { + u_char battery_state; + u_char ac_state; + u_char battery_life; + u_char spare1; + u_int minutes_left; /* estimate */ + u_int spare2[6]; +}; + +struct apm_ctl { + u_int dev; + u_int mode; +}; + +#define APM_IOC_REJECT _IOW('A', 0, struct apm_event_info) /* reject request # */ +#define APM_IOC_STANDBY _IO('A', 1) /* put system into standby */ +#define APM_IOC_SUSPEND _IO('A', 2) /* put system into suspend */ +#define APM_IOC_GETPOWER _IOR('A', 3, struct apm_power_info) /* fetch battery state */ +#define APM_IOC_DEV_CTL _IOW('A', 5, struct apm_ctl) /* put device into mode */ +#define APM_IOC_PRN_CTL _IOW('A', 6, int ) /* driver power status msg */ +#define APM_PRINT_ON 0 /* driver power status displayed */ +#define APM_PRINT_OFF 1 /* driver power status not displayed */ +#define APM_PRINT_PCT 2 /* driver power status only displayed + if the percentage changes */ +#define APM_IOC_STANDBY_REQ _IO('A', 7) /* request standby */ +#define APM_IOC_SUSPEND_REQ _IO('A', 8) /* request suspend */ +#define APM_IOC_HIBERNATE _IO('A', 9) /* put system into hibernate */ + +#ifdef _KERNEL +void apm_setinfohook(int (*)(struct apm_power_info *)); +int apm_record_event(u_int); +#endif + +#endif /* _MACHINE_APMVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/armreg.h b/lib/libc/include/aarch64-openbsd-none/arm64/armreg.h new file mode 100644 index 0000000000..7483ae8dd7 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/armreg.h @@ -0,0 +1,973 @@ +/* $OpenBSD: armreg.h,v 1.44 2025/07/22 09:20:41 kettenis Exp $ */ +/*- + * Copyright (c) 2013, 2014 Andrew Turner + * Copyright (c) 2015 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Andrew Turner under + * sponsorship from the FreeBSD Foundation. + * + * 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 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 AUTHOR 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. + * + * $FreeBSD: head/sys/arm64/include/armreg.h 309248 2016-11-28 14:24:07Z andrew $ + */ + +#ifndef _MACHINE_ARMREG_H_ +#define _MACHINE_ARMREG_H_ + +#define INSN_SIZE 4 + +#define READ_SPECIALREG(reg) \ +({ uint64_t val; \ + __asm volatile("mrs %0, " __STRING(reg) : "=&r" (val)); \ + val; \ +}) +#define WRITE_SPECIALREG(reg, val) \ + __asm volatile("msr " __STRING(reg) ", %0" : : "r"((uint64_t)val)) + +/* CCSIDR_EL1 - Current Cache Size ID Register */ +#define CCSIDR_SETS_MASK 0x0fffe000 +#define CCSIDR_SETS_SHIFT 13 +#define CCSIDR_SETS(reg) \ + ((((reg) & CCSIDR_SETS_MASK) >> CCSIDR_SETS_SHIFT) + 1) +#define CCSIDR_WAYS_MASK 0x00001ff8 +#define CCSIDR_WAYS_SHIFT 3 +#define CCSIDR_WAYS(reg) \ + ((((reg) & CCSIDR_WAYS_MASK) >> CCSIDR_WAYS_SHIFT) + 1) +#define CCSIDR_LINE_MASK 0x00000007 +#define CCSIDR_LINE_SIZE(reg) (1 << (((reg) & CCSIDR_LINE_MASK) + 4)) + +#define CCSIDR_CCIDX_SETS_MASK 0x00ffffff00000000ULL +#define CCSIDR_CCIDX_SETS_SHIFT 32 +#define CCSIDR_CCIDX_SETS(reg) \ + ((((reg) & CCSIDR_CCIDX_SETS_MASK) >> CCSIDR_CCIDX_SETS_SHIFT) + 1) +#define CCSIDR_CCIDX_WAYS_MASK 0x0000000000fffff8ULL +#define CCSIDR_CCIDX_WAYS_SHIFT 3 +#define CCSIDR_CCIDX_WAYS(reg) \ + ((((reg) & CCSIDR_CCIDX_WAYS_MASK) >> CCSIDR_CCIDX_WAYS_SHIFT) + 1) +#define CCSIDR_CCIDX_LINE_MASK 0x0000000000000007ULL +#define CCSIDR_CCIDX_LINE_SIZE(reg) \ + (1 << (((reg) & CCSIDR_CCIDX_LINE_MASK) + 4)) + +/* CLIDR_EL1 - Cache Level ID Register */ +#define CLIDR_CTYPE_MASK 0x7 +#define CLIDR_CTYPE_INSN 0x1 +#define CLIDR_CTYPE_DATA 0x2 +#define CLIDR_CTYPE_UNIFIED 0x4 + +/* CNTHCTL_EL2 - Counter-timer Hypervisor Control Register */ +#define CNTHCTL_EVNTI_MASK (0xf << 4) /* Bit to trigger event stream */ +#define CNTHCTL_EVNTDIR (1 << 3) /* Control transition trigger bit */ +#define CNTHCTL_EVNTEN (1 << 2) /* Enable event stream */ +#define CNTHCTL_EL1PCEN (1 << 1) /* Allow EL0/1 physical timer access */ +#define CNTHCTL_EL1PCTEN (1 << 0) /*Allow EL0/1 physical counter access*/ + +/* CNTKCTL_EL1 - Counter-timer Kernel Control Register */ +#define CNTKCTL_EL0VCTEN (1 << 1) /* Allow EL0 virtual counter access */ + +/* CNTV_CTL_EL0 */ +#define CNTV_CTL_ENABLE (1 << 0) +#define CNTV_CTL_IMASK (1 << 1) +#define CNTV_CTL_ISTATUS (1 << 2) + +/* CPACR_EL1 */ +#define CPACR_ZEN_MASK (0x3 << 16) +#define CPACR_ZEN_TRAP_ALL1 (0x0 << 16) /* Traps from EL0 and EL1 */ +#define CPACR_ZEN_TRAP_EL0 (0x1 << 16) /* Traps from EL0 */ +#define CPACR_ZEN_TRAP_ALL2 (0x2 << 16) /* Traps from EL0 and EL1 */ +#define CPACR_ZEN_TRAP_NONE (0x3 << 16) /* No traps */ +#define CPACR_FPEN_MASK (0x3 << 20) +#define CPACR_FPEN_TRAP_ALL1 (0x0 << 20) /* Traps from EL0 and EL1 */ +#define CPACR_FPEN_TRAP_EL0 (0x1 << 20) /* Traps from EL0 */ +#define CPACR_FPEN_TRAP_ALL2 (0x2 << 20) /* Traps from EL0 and EL1 */ +#define CPACR_FPEN_TRAP_NONE (0x3 << 20) /* No traps */ +#define CPACR_TTA (0x1 << 28) + +/* CSSELR_EL1 - Cache Size Selection Register */ +#define CSSELR_IND (1 << 0) +#define CSSELR_LEVEL_SHIFT 1 + +/* CTR_EL0 - Cache Type Register */ +#define CTR_DLINE_SHIFT 16 +#define CTR_DLINE_MASK (0xf << CTR_DLINE_SHIFT) +#define CTR_DLINE_SIZE(reg) (((reg) & CTR_DLINE_MASK) >> CTR_DLINE_SHIFT) +#define CTR_IL1P_SHIFT 14 +#define CTR_IL1P_MASK (0x3 << CTR_IL1P_SHIFT) +#define CTR_IL1P_AIVIVT (0x1 << CTR_IL1P_SHIFT) +#define CTR_IL1P_VIPT (0x2 << CTR_IL1P_SHIFT) +#define CTR_IL1P_PIPT (0x3 << CTR_IL1P_SHIFT) +#define CTR_ILINE_SHIFT 0 +#define CTR_ILINE_MASK (0xf << CTR_ILINE_SHIFT) +#define CTR_ILINE_SIZE(reg) (((reg) & CTR_ILINE_MASK) >> CTR_ILINE_SHIFT) + +/* MPIDR_EL1 - Multiprocessor Affinity Register */ +#define MPIDR_AFF3 (0xFFULL << 32) +#define MPIDR_AFF2 (0xFFULL << 16) +#define MPIDR_AFF1 (0xFFULL << 8) +#define MPIDR_AFF0 (0xFFULL << 0) +#define MPIDR_AFF (MPIDR_AFF3|MPIDR_AFF2|MPIDR_AFF1|MPIDR_AFF0) + +/* DCZID_EL0 - Data Cache Zero ID register */ +#define DCZID_DZP (1 << 4) /* DC ZVA prohibited if non-0 */ +#define DCZID_BS_SHIFT 0 +#define DCZID_BS_MASK (0xf << DCZID_BS_SHIFT) +#define DCZID_BS_SIZE(reg) (((reg) & DCZID_BS_MASK) >> DCZID_BS_SHIFT) + +/* ESR_ELx */ +#define ESR_ELx_ISS_MASK 0x00ffffff +#define ISS_INSN_FnV (0x01 << 10) +#define ISS_INSN_EA (0x01 << 9) +#define ISS_INSN_S1PTW (0x01 << 7) +#define ISS_INSN_IFSC_MASK (0x1f << 0) +#define ISS_DATA_ISV (0x01 << 24) +#define ISS_DATA_SAS_MASK (0x03 << 22) +#define ISS_DATA_SSE (0x01 << 21) +#define ISS_DATA_SRT_MASK (0x1f << 16) +#define ISS_DATA_SF (0x01 << 15) +#define ISS_DATA_AR (0x01 << 14) +#define ISS_DATA_FnV (0x01 << 10) +#define ISS_DATA_EA (0x01 << 9) +#define ISS_DATA_CM (0x01 << 8) +#define ISS_DATA_S1PTW (0x01 << 7) +#define ISS_DATA_WnR (0x01 << 6) +#define ISS_DATA_DFSC_MASK (0x3f << 0) +#define ISS_DATA_DFSC_ASF_L0 (0x00 << 0) +#define ISS_DATA_DFSC_ASF_L1 (0x01 << 0) +#define ISS_DATA_DFSC_ASF_L2 (0x02 << 0) +#define ISS_DATA_DFSC_ASF_L3 (0x03 << 0) +#define ISS_DATA_DFSC_TF_L0 (0x04 << 0) +#define ISS_DATA_DFSC_TF_L1 (0x05 << 0) +#define ISS_DATA_DFSC_TF_L2 (0x06 << 0) +#define ISS_DATA_DFSC_TF_L3 (0x07 << 0) +#define ISS_DATA_DFSC_AFF_L1 (0x09 << 0) +#define ISS_DATA_DFSC_AFF_L2 (0x0a << 0) +#define ISS_DATA_DFSC_AFF_L3 (0x0b << 0) +#define ISS_DATA_DFSC_PF_L1 (0x0d << 0) +#define ISS_DATA_DFSC_PF_L2 (0x0e << 0) +#define ISS_DATA_DFSC_PF_L3 (0x0f << 0) +#define ISS_DATA_DFSC_EXT (0x10 << 0) +#define ISS_DATA_DFSC_EXT_L0 (0x14 << 0) +#define ISS_DATA_DFSC_EXT_L1 (0x15 << 0) +#define ISS_DATA_DFSC_EXT_L2 (0x16 << 0) +#define ISS_DATA_DFSC_EXT_L3 (0x17 << 0) +#define ISS_DATA_DFSC_ECC (0x18 << 0) +#define ISS_DATA_DFSC_ECC_L0 (0x1c << 0) +#define ISS_DATA_DFSC_ECC_L1 (0x1d << 0) +#define ISS_DATA_DFSC_ECC_L2 (0x1e << 0) +#define ISS_DATA_DFSC_ECC_L3 (0x1f << 0) +#define ISS_DATA_DFSC_ALIGN (0x21 << 0) +#define ISS_DATA_DFSC_TLB_CONFLICT (0x30 << 0) +#define ISS_MSR_DIR_SHIFT 0 +#define ISS_MSR_DIR (0x01 << ISS_MSR_DIR_SHIFT) +#define ISS_MSR_Rt_SHIFT 5 +#define ISS_MSR_Rt_MASK (0x1f << ISS_MSR_Rt_SHIFT) +#define ISS_MSR_Rt(x) (((x) & ISS_MSR_Rt_MASK) >> ISS_MSR_Rt_SHIFT) +#define ISS_MSR_CRm_SHIFT 1 +#define ISS_MSR_CRm_MASK (0xf << ISS_MSR_CRm_SHIFT) +#define ISS_MSR_CRm(x) (((x) & ISS_MSR_CRm_MASK) >> ISS_MSR_CRm_SHIFT) +#define ISS_MSR_CRn_SHIFT 10 +#define ISS_MSR_CRn_MASK (0xf << ISS_MSR_CRn_SHIFT) +#define ISS_MSR_CRn(x) (((x) & ISS_MSR_CRn_MASK) >> ISS_MSR_CRn_SHIFT) +#define ISS_MSR_OP1_SHIFT 14 +#define ISS_MSR_OP1_MASK (0x7 << ISS_MSR_OP1_SHIFT) +#define ISS_MSR_OP1(x) (((x) & ISS_MSR_OP1_MASK) >> ISS_MSR_OP1_SHIFT) +#define ISS_MSR_OP2_SHIFT 17 +#define ISS_MSR_OP2_MASK (0x7 << ISS_MSR_OP2_SHIFT) +#define ISS_MSR_OP2(x) (((x) & ISS_MSR_OP2_MASK) >> ISS_MSR_OP2_SHIFT) +#define ISS_MSR_OP0_SHIFT 20 +#define ISS_MSR_OP0_MASK (0x3 << ISS_MSR_OP0_SHIFT) +#define ISS_MSR_OP0(x) (((x) & ISS_MSR_OP0_MASK) >> ISS_MSR_OP0_SHIFT) +#define ISS_BRK_COMMENT_MASK 0xffff +#define ESR_ELx_IL (0x01 << 25) +#define ESR_ELx_EC_SHIFT 26 +#define ESR_ELx_EC_MASK (0x3f << 26) +#define ESR_ELx_EXCEPTION(esr) (((esr) & ESR_ELx_EC_MASK) >> ESR_ELx_EC_SHIFT) +#define EXCP_UNKNOWN 0x00 /* Unkwn exception */ +#define EXCP_FP_SIMD 0x07 /* FP/SIMD trap */ +#define EXCP_BRANCH_TGT 0x0d /* Branch target exception */ +#define EXCP_ILL_STATE 0x0e /* Illegal execution state */ +#define EXCP_SVC 0x15 /* SVC trap */ +#define EXCP_MSR 0x18 /* MSR/MRS trap */ +#define EXCP_SVE 0x19 /* SVE trap */ +#define EXCP_FPAC 0x1c /* Faulting PAC trap */ +#define EXCP_INSN_ABORT_L 0x20 /* Instruction abort, from lower EL */ +#define EXCP_INSN_ABORT 0x21 /* Instruction abort, from same EL */ +#define EXCP_PC_ALIGN 0x22 /* PC alignment fault */ +#define EXCP_DATA_ABORT_L 0x24 /* Data abort, from lower EL */ +#define EXCP_DATA_ABORT 0x25 /* Data abort, from same EL */ +#define EXCP_SP_ALIGN 0x26 /* SP alignment fault */ +#define EXCP_TRAP_FP 0x2c /* Trapped FP exception */ +#define EXCP_SERROR 0x2f /* SError interrupt */ +#define EXCP_SOFTSTP_EL0 0x32 /* Software Step, from lower EL */ +#define EXCP_SOFTSTP_EL1 0x33 /* Software Step, from same EL */ +#define EXCP_WATCHPT_EL1 0x35 /* Watchpoint, from same EL */ +#define EXCP_BRK 0x3c /* Breakpoint */ + +/* ICC_CTLR_EL1 */ +#define ICC_CTLR_EL1_EOIMODE (1U << 1) +#define ICC_CTLR_EL1_PRIBITS_SHIFT 8 +#define ICC_CTLR_EL1_PRIBITS_MASK (0x7UL << 8) +#define ICC_CTLR_EL1_PRIBITS(reg) \ + (((reg) & ICC_CTLR_EL1_PRIBITS_MASK) >> ICC_CTLR_EL1_PRIBITS_SHIFT) + +/* ICC_IAR1_EL1 */ +#define ICC_IAR1_EL1_SPUR (0x03ff) + +/* ICC_IGRPEN0_EL1 */ +#define ICC_IGRPEN0_EL1_EN (1U << 0) + +/* ICC_PMR_EL1 */ +#define ICC_PMR_EL1_PRIO_MASK (0xFFUL) + +/* ICC_SGI1R_EL1 */ +#define ICC_SGI1R_EL1_TL_MASK 0xffffUL +#define ICC_SGI1R_EL1_AFF1_SHIFT 16 +#define ICC_SGI1R_EL1_SGIID_SHIFT 24 +#define ICC_SGI1R_EL1_AFF2_SHIFT 32 +#define ICC_SGI1R_EL1_AFF3_SHIFT 48 +#define ICC_SGI1R_EL1_SGIID_MASK 0xfUL +#define ICC_SGI1R_EL1_IRM (0x1UL << 40) + +/* ICC_SRE_EL1 */ +#define ICC_SRE_EL1_SRE (1U << 0) + +/* ICC_SRE_EL2 */ +#define ICC_SRE_EL2_SRE (1U << 0) +#define ICC_SRE_EL2_EN (1U << 3) + +/* ID_AA64DFR0_EL1 */ +#define ID_AA64DFR0_MASK 0x00000000f0f0ffffUL +#define ID_AA64DFR0_DEBUG_VER_SHIFT 0 +#define ID_AA64DFR0_DEBUG_VER_MASK (0xfULL << ID_AA64DFR0_DEBUG_VER_SHIFT) +#define ID_AA64DFR0_DEBUG_VER(x) ((x) & ID_AA64DFR0_DEBUG_VER_MASK) +#define ID_AA64DFR0_DEBUG_VER_8 (0x6ULL << ID_AA64DFR0_DEBUG_VER_SHIFT) +#define ID_AA64DFR0_DEBUG_VER_8_VHE (0x7ULL << ID_AA64DFR0_DEBUG_VER_SHIFT) +#define ID_AA64DFR0_TRACE_VER_SHIFT 4 +#define ID_AA64DFR0_TRACE_VER_MASK (0xfULL << ID_AA64DFR0_TRACE_VER_SHIFT) +#define ID_AA64DFR0_TRACE_VER(x) ((x) & ID_AA64DFR0_TRACE_VER_MASK) +#define ID_AA64DFR0_TRACE_VER_NONE (0x0ULL << ID_AA64DFR0_TRACE_VER_SHIFT) +#define ID_AA64DFR0_TRACE_VER_IMPL (0x1ULL << ID_AA64DFR0_TRACE_VER_SHIFT) +#define ID_AA64DFR0_PMU_VER_SHIFT 8 +#define ID_AA64DFR0_PMU_VER_MASK (0xfULL << ID_AA64DFR0_PMU_VER_SHIFT) +#define ID_AA64DFR0_PMU_VER(x) ((x) & ID_AA64DFR0_PMU_VER_MASK) +#define ID_AA64DFR0_PMU_VER_NONE (0x0ULL << ID_AA64DFR0_PMU_VER_SHIFT) +#define ID_AA64DFR0_PMU_VER_3 (0x1ULL << ID_AA64DFR0_PMU_VER_SHIFT) +#define ID_AA64DFR0_PMU_VER_3_1 (0x4ULL << ID_AA64DFR0_PMU_VER_SHIFT) +#define ID_AA64DFR0_PMU_VER_IMPL (0xfULL << ID_AA64DFR0_PMU_VER_SHIFT) +#define ID_AA64DFR0_BRPS_SHIFT 12 +#define ID_AA64DFR0_BRPS_MASK (0xfULL << ID_AA64DFR0_BRPS_SHIFT) +#define ID_AA64DFR0_BRPS(x) \ + ((((x) >> ID_AA64DFR0_BRPS_SHIFT) & 0xf) + 1) +#define ID_AA64DFR0_WRPS_SHIFT 20 +#define ID_AA64DFR0_WRPS_MASK (0xfULL << ID_AA64DFR0_WRPS_SHIFT) +#define ID_AA64DFR0_WRPS(x) \ + ((((x) >> ID_AA64DFR0_WRPS_SHIFT) & 0xf) + 1) +#define ID_AA64DFR0_CTX_CMPS_SHIFT 28 +#define ID_AA64DFR0_CTX_CMPS_MASK (0xfULL << ID_AA64DFR0_CTX_CMPS_SHIFT) +#define ID_AA64DFR0_CTX_CMPS(x) \ + ((((x) >> ID_AA64DFR0_CTX_CMPS_SHIFT) & 0xf) + 1) + +/* ID_AA64ISAR0_EL1 */ +#define ID_AA64ISAR0_MASK 0xfffffffff0fffff0ULL +#define ID_AA64ISAR0_AES_SHIFT 4 +#define ID_AA64ISAR0_AES_MASK (0xfULL << ID_AA64ISAR0_AES_SHIFT) +#define ID_AA64ISAR0_AES(x) ((x) & ID_AA64ISAR0_AES_MASK) +#define ID_AA64ISAR0_AES_NONE (0x0ULL << ID_AA64ISAR0_AES_SHIFT) +#define ID_AA64ISAR0_AES_BASE (0x1ULL << ID_AA64ISAR0_AES_SHIFT) +#define ID_AA64ISAR0_AES_PMULL (0x2ULL << ID_AA64ISAR0_AES_SHIFT) +#define ID_AA64ISAR0_SHA1_SHIFT 8 +#define ID_AA64ISAR0_SHA1_MASK (0xfULL << ID_AA64ISAR0_SHA1_SHIFT) +#define ID_AA64ISAR0_SHA1(x) ((x) & ID_AA64ISAR0_SHA1_MASK) +#define ID_AA64ISAR0_SHA1_NONE (0x0ULL << ID_AA64ISAR0_SHA1_SHIFT) +#define ID_AA64ISAR0_SHA1_BASE (0x1ULL << ID_AA64ISAR0_SHA1_SHIFT) +#define ID_AA64ISAR0_SHA2_SHIFT 12 +#define ID_AA64ISAR0_SHA2_MASK (0xfULL << ID_AA64ISAR0_SHA2_SHIFT) +#define ID_AA64ISAR0_SHA2(x) ((x) & ID_AA64ISAR0_SHA2_MASK) +#define ID_AA64ISAR0_SHA2_NONE (0x0ULL << ID_AA64ISAR0_SHA2_SHIFT) +#define ID_AA64ISAR0_SHA2_BASE (0x1ULL << ID_AA64ISAR0_SHA2_SHIFT) +#define ID_AA64ISAR0_SHA2_512 (0x2ULL << ID_AA64ISAR0_SHA2_SHIFT) +#define ID_AA64ISAR0_CRC32_SHIFT 16 +#define ID_AA64ISAR0_CRC32_MASK (0xfULL << ID_AA64ISAR0_CRC32_SHIFT) +#define ID_AA64ISAR0_CRC32(x) ((x) & ID_AA64ISAR0_CRC32_MASK) +#define ID_AA64ISAR0_CRC32_NONE (0x0ULL << ID_AA64ISAR0_CRC32_SHIFT) +#define ID_AA64ISAR0_CRC32_BASE (0x1ULL << ID_AA64ISAR0_CRC32_SHIFT) +#define ID_AA64ISAR0_ATOMIC_SHIFT 20 +#define ID_AA64ISAR0_ATOMIC_MASK (0xfULL << ID_AA64ISAR0_ATOMIC_SHIFT) +#define ID_AA64ISAR0_ATOMIC(x) ((x) & ID_AA64ISAR0_ATOMIC_MASK) +#define ID_AA64ISAR0_ATOMIC_NONE (0x0ULL << ID_AA64ISAR0_ATOMIC_SHIFT) +#define ID_AA64ISAR0_ATOMIC_IMPL (0x2ULL << ID_AA64ISAR0_ATOMIC_SHIFT) +#define ID_AA64ISAR0_RDM_SHIFT 28 +#define ID_AA64ISAR0_RDM_MASK (0xfULL << ID_AA64ISAR0_RDM_SHIFT) +#define ID_AA64ISAR0_RDM(x) ((x) & ID_AA64ISAR0_RDM_MASK) +#define ID_AA64ISAR0_RDM_NONE (0x0ULL << ID_AA64ISAR0_RDM_SHIFT) +#define ID_AA64ISAR0_RDM_IMPL (0x1ULL << ID_AA64ISAR0_RDM_SHIFT) +#define ID_AA64ISAR0_SHA3_SHIFT 32 +#define ID_AA64ISAR0_SHA3_MASK (0xfULL << ID_AA64ISAR0_SHA3_SHIFT) +#define ID_AA64ISAR0_SHA3(x) ((x) & ID_AA64ISAR0_SHA3_MASK) +#define ID_AA64ISAR0_SHA3_NONE (0x0ULL << ID_AA64ISAR0_SHA3_SHIFT) +#define ID_AA64ISAR0_SHA3_IMPL (0x1ULL << ID_AA64ISAR0_SHA3_SHIFT) +#define ID_AA64ISAR0_SM3_SHIFT 36 +#define ID_AA64ISAR0_SM3_MASK (0xfULL << ID_AA64ISAR0_SM3_SHIFT) +#define ID_AA64ISAR0_SM3(x) ((x) & ID_AA64ISAR0_SM3_MASK) +#define ID_AA64ISAR0_SM3_NONE (0x0ULL << ID_AA64ISAR0_SM3_SHIFT) +#define ID_AA64ISAR0_SM3_IMPL (0x1ULL << ID_AA64ISAR0_SM3_SHIFT) +#define ID_AA64ISAR0_SM4_SHIFT 40 +#define ID_AA64ISAR0_SM4_MASK (0xfULL << ID_AA64ISAR0_SM4_SHIFT) +#define ID_AA64ISAR0_SM4(x) ((x) & ID_AA64ISAR0_SM4_MASK) +#define ID_AA64ISAR0_SM4_NONE (0x0ULL << ID_AA64ISAR0_SM4_SHIFT) +#define ID_AA64ISAR0_SM4_IMPL (0x1ULL << ID_AA64ISAR0_SM4_SHIFT) +#define ID_AA64ISAR0_DP_SHIFT 44 +#define ID_AA64ISAR0_DP_MASK (0xfULL << ID_AA64ISAR0_DP_SHIFT) +#define ID_AA64ISAR0_DP(x) ((x) & ID_AA64ISAR0_DP_MASK) +#define ID_AA64ISAR0_DP_NONE (0x0ULL << ID_AA64ISAR0_DP_SHIFT) +#define ID_AA64ISAR0_DP_IMPL (0x1ULL << ID_AA64ISAR0_DP_SHIFT) +#define ID_AA64ISAR0_FHM_SHIFT 48 +#define ID_AA64ISAR0_FHM_MASK (0xfULL << ID_AA64ISAR0_FHM_SHIFT) +#define ID_AA64ISAR0_FHM(x) ((x) & ID_AA64ISAR0_FHM_MASK) +#define ID_AA64ISAR0_FHM_NONE (0x0ULL << ID_AA64ISAR0_FHM_SHIFT) +#define ID_AA64ISAR0_FHM_IMPL (0x1ULL << ID_AA64ISAR0_FHM_SHIFT) +#define ID_AA64ISAR0_TS_SHIFT 52 +#define ID_AA64ISAR0_TS_MASK (0xfULL << ID_AA64ISAR0_TS_SHIFT) +#define ID_AA64ISAR0_TS(x) ((x) & ID_AA64ISAR0_TS_MASK) +#define ID_AA64ISAR0_TS_NONE (0x0ULL << ID_AA64ISAR0_TS_SHIFT) +#define ID_AA64ISAR0_TS_BASE (0x1ULL << ID_AA64ISAR0_TS_SHIFT) +#define ID_AA64ISAR0_TS_AXFLAG (0x2ULL << ID_AA64ISAR0_TS_SHIFT) +#define ID_AA64ISAR0_TLB_SHIFT 56 +#define ID_AA64ISAR0_TLB_MASK (0xfULL << ID_AA64ISAR0_TLB_SHIFT) +#define ID_AA64ISAR0_TLB(x) ((x) & ID_AA64ISAR0_TLB_MASK) +#define ID_AA64ISAR0_TLB_NONE (0x0ULL << ID_AA64ISAR0_TLB_SHIFT) +#define ID_AA64ISAR0_TLB_IOS (0x1ULL << ID_AA64ISAR0_TLB_SHIFT) +#define ID_AA64ISAR0_TLB_IRANGE (0x2ULL << ID_AA64ISAR0_TLB_SHIFT) +#define ID_AA64ISAR0_RNDR_SHIFT 60 +#define ID_AA64ISAR0_RNDR_MASK (0xfULL << ID_AA64ISAR0_RNDR_SHIFT) +#define ID_AA64ISAR0_RNDR(x) ((x) & ID_AA64ISAR0_RNDR_MASK) +#define ID_AA64ISAR0_RNDR_NONE (0x0ULL << ID_AA64ISAR0_RNDR_SHIFT) +#define ID_AA64ISAR0_RNDR_IMPL (0x1ULL << ID_AA64ISAR0_RNDR_SHIFT) + +/* ID_AA64ISAR1_EL1 */ +#define ID_AA64ISAR1_MASK 0xffffffffffffffffULL +#define ID_AA64ISAR1_DPB_SHIFT 0 +#define ID_AA64ISAR1_DPB_MASK (0xfULL << ID_AA64ISAR1_DPB_SHIFT) +#define ID_AA64ISAR1_DPB(x) ((x) & ID_AA64ISAR1_DPB_MASK) +#define ID_AA64ISAR1_DPB_NONE (0x0ULL << ID_AA64ISAR1_DPB_SHIFT) +#define ID_AA64ISAR1_DPB_IMPL (0x1ULL << ID_AA64ISAR1_DPB_SHIFT) +#define ID_AA64ISAR1_DPB_DCCVADP (0x2ULL << ID_AA64ISAR1_DPB_SHIFT) +#define ID_AA64ISAR1_APA_SHIFT 4 +#define ID_AA64ISAR1_APA_MASK (0xfULL << ID_AA64ISAR1_APA_SHIFT) +#define ID_AA64ISAR1_APA(x) ((x) & ID_AA64ISAR1_APA_MASK) +#define ID_AA64ISAR1_APA_NONE (0x0ULL << ID_AA64ISAR1_APA_SHIFT) +#define ID_AA64ISAR1_APA_PAC (0x1ULL << ID_AA64ISAR1_APA_SHIFT) +#define ID_AA64ISAR1_APA_EPAC (0x2ULL << ID_AA64ISAR1_APA_SHIFT) +#define ID_AA64ISAR1_APA_EPAC2 (0x3ULL << ID_AA64ISAR1_APA_SHIFT) +#define ID_AA64ISAR1_APA_FPAC (0x4ULL << ID_AA64ISAR1_APA_SHIFT) +#define ID_AA64ISAR1_APA_FPAC_COMBINED (0x5ULL << ID_AA64ISAR1_APA_SHIFT) +#define ID_AA64ISAR1_API_SHIFT 8 +#define ID_AA64ISAR1_API_MASK (0xfULL << ID_AA64ISAR1_API_SHIFT) +#define ID_AA64ISAR1_API(x) ((x) & ID_AA64ISAR1_API_MASK) +#define ID_AA64ISAR1_API_NONE (0x0ULL << ID_AA64ISAR1_API_SHIFT) +#define ID_AA64ISAR1_API_PAC (0x1ULL << ID_AA64ISAR1_API_SHIFT) +#define ID_AA64ISAR1_API_EPAC (0x2ULL << ID_AA64ISAR1_API_SHIFT) +#define ID_AA64ISAR1_API_EPAC2 (0x3ULL << ID_AA64ISAR1_API_SHIFT) +#define ID_AA64ISAR1_API_FPAC (0x4ULL << ID_AA64ISAR1_API_SHIFT) +#define ID_AA64ISAR1_API_FPAC_COMBINED (0x5ULL << ID_AA64ISAR1_API_SHIFT) +#define ID_AA64ISAR1_JSCVT_SHIFT 12 +#define ID_AA64ISAR1_JSCVT_MASK (0xfULL << ID_AA64ISAR1_JSCVT_SHIFT) +#define ID_AA64ISAR1_JSCVT(x) ((x) & ID_AA64ISAR1_JSCVT_MASK) +#define ID_AA64ISAR1_JSCVT_NONE (0x0ULL << ID_AA64ISAR1_JSCVT_SHIFT) +#define ID_AA64ISAR1_JSCVT_IMPL (0x1ULL << ID_AA64ISAR1_JSCVT_SHIFT) +#define ID_AA64ISAR1_FCMA_SHIFT 16 +#define ID_AA64ISAR1_FCMA_MASK (0xfULL << ID_AA64ISAR1_FCMA_SHIFT) +#define ID_AA64ISAR1_FCMA(x) ((x) & ID_AA64ISAR1_FCMA_MASK) +#define ID_AA64ISAR1_FCMA_NONE (0x0ULL << ID_AA64ISAR1_FCMA_SHIFT) +#define ID_AA64ISAR1_FCMA_IMPL (0x1ULL << ID_AA64ISAR1_FCMA_SHIFT) +#define ID_AA64ISAR1_LRCPC_SHIFT 20 +#define ID_AA64ISAR1_LRCPC_MASK (0xfULL << ID_AA64ISAR1_LRCPC_SHIFT) +#define ID_AA64ISAR1_LRCPC(x) ((x) & ID_AA64ISAR1_LRCPC_MASK) +#define ID_AA64ISAR1_LRCPC_NONE (0x0ULL << ID_AA64ISAR1_LRCPC_SHIFT) +#define ID_AA64ISAR1_LRCPC_BASE (0x1ULL << ID_AA64ISAR1_LRCPC_SHIFT) +#define ID_AA64ISAR1_LRCPC_LDAPUR (0x2ULL << ID_AA64ISAR1_LRCPC_SHIFT) +#define ID_AA64ISAR1_GPA_SHIFT 24 +#define ID_AA64ISAR1_GPA_MASK (0xfULL << ID_AA64ISAR1_GPA_SHIFT) +#define ID_AA64ISAR1_GPA(x) ((x) & ID_AA64ISAR1_GPA_MASK) +#define ID_AA64ISAR1_GPA_NONE (0x0ULL << ID_AA64ISAR1_GPA_SHIFT) +#define ID_AA64ISAR1_GPA_IMPL (0x1ULL << ID_AA64ISAR1_GPA_SHIFT) +#define ID_AA64ISAR1_GPI_SHIFT 28 +#define ID_AA64ISAR1_GPI_MASK (0xfULL << ID_AA64ISAR1_GPI_SHIFT) +#define ID_AA64ISAR1_GPI(x) ((x) & ID_AA64ISAR1_GPI_MASK) +#define ID_AA64ISAR1_GPI_NONE (0x0ULL << ID_AA64ISAR1_GPI_SHIFT) +#define ID_AA64ISAR1_GPI_IMPL (0x1ULL << ID_AA64ISAR1_GPI_SHIFT) +#define ID_AA64ISAR1_FRINTTS_SHIFT 32 +#define ID_AA64ISAR1_FRINTTS_MASK (0xfULL << ID_AA64ISAR1_FRINTTS_SHIFT) +#define ID_AA64ISAR1_FRINTTS(x) ((x) & ID_AA64ISAR1_FRINTTS_MASK) +#define ID_AA64ISAR1_FRINTTS_NONE (0x0ULL << ID_AA64ISAR1_FRINTTS_SHIFT) +#define ID_AA64ISAR1_FRINTTS_IMPL (0x1ULL << ID_AA64ISAR1_FRINTTS_SHIFT) +#define ID_AA64ISAR1_SB_SHIFT 36 +#define ID_AA64ISAR1_SB_MASK (0xfULL << ID_AA64ISAR1_SB_SHIFT) +#define ID_AA64ISAR1_SB(x) ((x) & ID_AA64ISAR1_SB_MASK) +#define ID_AA64ISAR1_SB_NONE (0x0ULL << ID_AA64ISAR1_SB_SHIFT) +#define ID_AA64ISAR1_SB_IMPL (0x1ULL << ID_AA64ISAR1_SB_SHIFT) +#define ID_AA64ISAR1_SPECRES_SHIFT 40 +#define ID_AA64ISAR1_SPECRES_MASK (0xfULL << ID_AA64ISAR1_SPECRES_SHIFT) +#define ID_AA64ISAR1_SPECRES(x) ((x) & ID_AA64ISAR1_SPECRES_MASK) +#define ID_AA64ISAR1_SPECRES_NONE (0x0ULL << ID_AA64ISAR1_SPECRES_SHIFT) +#define ID_AA64ISAR1_SPECRES_IMPL (0x1ULL << ID_AA64ISAR1_SPECRES_SHIFT) +#define ID_AA64ISAR1_BF16_SHIFT 44 +#define ID_AA64ISAR1_BF16_MASK (0xfULL << ID_AA64ISAR1_BF16_SHIFT) +#define ID_AA64ISAR1_BF16(x) ((x) & ID_AA64ISAR1_BF16_MASK) +#define ID_AA64ISAR1_BF16_NONE (0x0ULL << ID_AA64ISAR1_BF16_SHIFT) +#define ID_AA64ISAR1_BF16_BASE (0x1ULL << ID_AA64ISAR1_BF16_SHIFT) +#define ID_AA64ISAR1_BF16_EBF (0x2ULL << ID_AA64ISAR1_BF16_SHIFT) +#define ID_AA64ISAR1_DGH_SHIFT 48 +#define ID_AA64ISAR1_DGH_MASK (0xfULL << ID_AA64ISAR1_DGH_SHIFT) +#define ID_AA64ISAR1_DGH(x) ((x) & ID_AA64ISAR1_DGH_MASK) +#define ID_AA64ISAR1_DGH_NONE (0x0ULL << ID_AA64ISAR1_DGH_SHIFT) +#define ID_AA64ISAR1_DGH_IMPL (0x1ULL << ID_AA64ISAR1_DGH_SHIFT) +#define ID_AA64ISAR1_I8MM_SHIFT 52 +#define ID_AA64ISAR1_I8MM_MASK (0xfULL << ID_AA64ISAR1_I8MM_SHIFT) +#define ID_AA64ISAR1_I8MM(x) ((x) & ID_AA64ISAR1_I8MM_MASK) +#define ID_AA64ISAR1_I8MM_NONE (0x0ULL << ID_AA64ISAR1_I8MM_SHIFT) +#define ID_AA64ISAR1_I8MM_IMPL (0x1ULL << ID_AA64ISAR1_I8MM_SHIFT) +#define ID_AA64ISAR1_XS_SHIFT 56 +#define ID_AA64ISAR1_XS_MASK (0xfULL << ID_AA64ISAR1_XS_SHIFT) +#define ID_AA64ISAR1_XS(x) ((x) & ID_AA64ISAR1_XS_MASK) +#define ID_AA64ISAR1_XS_NONE (0x0ULL << ID_AA64ISAR1_XS_SHIFT) +#define ID_AA64ISAR1_XS_IMPL (0x1ULL << ID_AA64ISAR1_XS_SHIFT) +#define ID_AA64ISAR1_LS64_SHIFT 60 +#define ID_AA64ISAR1_LS64_MASK (0xfULL << ID_AA64ISAR1_LS64_SHIFT) +#define ID_AA64ISAR1_LS64(x) ((x) & ID_AA64ISAR1_LS64_MASK) +#define ID_AA64ISAR1_LS64_NONE (0x0ULL << ID_AA64ISAR1_LS64_SHIFT) +#define ID_AA64ISAR1_LS64_BASE (0x1ULL << ID_AA64ISAR1_LS64_SHIFT) +#define ID_AA64ISAR1_LS64_V (0x2ULL << ID_AA64ISAR1_LS64_SHIFT) +#define ID_AA64ISAR1_LS64_ACCDATA (0x3ULL << ID_AA64ISAR1_LS64_SHIFT) + +/* ID_AA64ISAR2_EL1 */ +#define ID_AA64ISAR2_MASK 0x00ff0000f0ffffffULL +#define ID_AA64ISAR2_WFXT_SHIFT 0 +#define ID_AA64ISAR2_WFXT_MASK (0xfULL << ID_AA64ISAR2_WFXT_SHIFT) +#define ID_AA64ISAR2_WFXT(x) ((x) & ID_AA64ISAR2_WFXT_MASK) +#define ID_AA64ISAR2_WFXT_NONE (0x0ULL << ID_AA64ISAR2_WFXT_SHIFT) +#define ID_AA64ISAR2_WFXT_IMPL (0x2ULL << ID_AA64ISAR2_WFXT_SHIFT) +#define ID_AA64ISAR2_RPRES_SHIFT 4 +#define ID_AA64ISAR2_RPRES_MASK (0xfULL << ID_AA64ISAR2_RPRES_SHIFT) +#define ID_AA64ISAR2_RPRES(x) ((x) & ID_AA64ISAR2_RPRES_MASK) +#define ID_AA64ISAR2_RPRES_NONE (0x0ULL << ID_AA64ISAR2_RPRES_SHIFT) +#define ID_AA64ISAR2_RPRES_IMPL (0x1ULL << ID_AA64ISAR2_RPRES_SHIFT) +#define ID_AA64ISAR2_GPA3_SHIFT 8 +#define ID_AA64ISAR2_GPA3_WIDTH 4 +#define ID_AA64ISAR2_GPA3_MASK (0xfULL << ID_AA64ISAR2_GPA3_SHIFT) +#define ID_AA64ISAR2_GPA3(x) ((x) & ID_AA64ISAR2_GPA3_MASK) +#define ID_AA64ISAR2_GPA3_NONE (0x0ULL << ID_AA64ISAR2_GPA3_SHIFT) +#define ID_AA64ISAR2_GPA3_IMPL (0x1ULL << ID_AA64ISAR2_GPA3_SHIFT) +#define ID_AA64ISAR2_APA3_SHIFT 12 +#define ID_AA64ISAR2_APA3_WIDTH 4 +#define ID_AA64ISAR2_APA3_MASK (0xfULL << ID_AA64ISAR2_APA3_SHIFT) +#define ID_AA64ISAR2_APA3(x) ((x) & ID_AA64ISAR2_APA3_MASK) +#define ID_AA64ISAR2_APA3_NONE (0x0ULL << ID_AA64ISAR2_APA3_SHIFT) +#define ID_AA64ISAR2_APA3_PAC (0x1ULL << ID_AA64ISAR2_APA3_SHIFT) +#define ID_AA64ISAR2_APA3_EPAC (0x2ULL << ID_AA64ISAR2_APA3_SHIFT) +#define ID_AA64ISAR2_APA3_EPAC2 (0x3ULL << ID_AA64ISAR2_APA3_SHIFT) +#define ID_AA64ISAR2_APA3_FPAC (0x4ULL << ID_AA64ISAR2_APA3_SHIFT) +#define ID_AA64ISAR2_APA3_FPAC_COMBINED (0x5ULL << ID_AA64ISAR2_APA3_SHIFT) +#define ID_AA64ISAR2_MOPS_SHIFT 16 +#define ID_AA64ISAR2_MOPS_MASK (0xfULL << ID_AA64ISAR2_MOPS_SHIFT) +#define ID_AA64ISAR2_MOPS(x) ((x) & ID_AA64ISAR2_MOPS_MASK) +#define ID_AA64ISAR2_MOPS_NONE (0x0ULL << ID_AA64ISAR2_MOPS_SHIFT) +#define ID_AA64ISAR2_MOPS_IMPL (0x1ULL << ID_AA64ISAR2_MOPS_SHIFT) +#define ID_AA64ISAR2_BC_SHIFT 20 +#define ID_AA64ISAR2_BC_MASK (0xfULL << ID_AA64ISAR2_BC_SHIFT) +#define ID_AA64ISAR2_BC(x) ((x) & ID_AA64ISAR2_BC_MASK) +#define ID_AA64ISAR2_BC_NONE (0x0ULL << ID_AA64ISAR2_BC_SHIFT) +#define ID_AA64ISAR2_BC_IMPL (0x1ULL << ID_AA64ISAR2_BC_SHIFT) +#define ID_AA64ISAR2_CLRBHB_SHIFT 28 +#define ID_AA64ISAR2_CLRBHB_MASK (0xfULL << ID_AA64ISAR2_CLRBHB_SHIFT) +#define ID_AA64ISAR2_CLRBHB(x) ((x) & ID_AA64ISAR2_CLRBHB_MASK) +#define ID_AA64ISAR2_CLRBHB_NONE (0x0ULL << ID_AA64ISAR2_CLRBHB_SHIFT) +#define ID_AA64ISAR2_CLRBHB_IMPL (0x1ULL << ID_AA64ISAR2_CLRBHB_SHIFT) +#define ID_AA64ISAR2_RPRFM_SHIFT 48 +#define ID_AA64ISAR2_RPRFM_MASK (0xfULL << ID_AA64ISAR2_RPRFM_SHIFT) +#define ID_AA64ISAR2_RPRFM(x) ((x) & ID_AA64ISAR2_RPRFM_MASK) +#define ID_AA64ISAR2_RPRFM_NONE (0x0ULL << ID_AA64ISAR2_RPRFM_SHIFT) +#define ID_AA64ISAR2_RPRFM_IMPL (0x1ULL << ID_AA64ISAR2_RPRFM_SHIFT) +#define ID_AA64ISAR2_CSSC_SHIFT 52 +#define ID_AA64ISAR2_CSSC_MASK (0xfULL << ID_AA64ISAR2_CSSC_SHIFT) +#define ID_AA64ISAR2_CSSC(x) ((x) & ID_AA64ISAR2_CSSC_MASK) +#define ID_AA64ISAR2_CSSC_NONE (0x0ULL << ID_AA64ISAR2_CSSC_SHIFT) +#define ID_AA64ISAR2_CSSC_IMPL (0x1ULL << ID_AA64ISAR2_CSSC_SHIFT) + +/* ID_AA64MMFR0_EL1 */ +#define ID_AA64MMFR0_MASK 0xf0000000ffffffffULL +#define ID_AA64MMFR0_PA_RANGE_SHIFT 0 +#define ID_AA64MMFR0_PA_RANGE_MASK (0xfULL << ID_AA64MMFR0_PA_RANGE_SHIFT) +#define ID_AA64MMFR0_PA_RANGE(x) ((x) & ID_AA64MMFR0_PA_RANGE_MASK) +#define ID_AA64MMFR0_PA_RANGE_4G (0x0ULL << ID_AA64MMFR0_PA_RANGE_SHIFT) +#define ID_AA64MMFR0_PA_RANGE_64G (0x1ULL << ID_AA64MMFR0_PA_RANGE_SHIFT) +#define ID_AA64MMFR0_PA_RANGE_1T (0x2ULL << ID_AA64MMFR0_PA_RANGE_SHIFT) +#define ID_AA64MMFR0_PA_RANGE_4T (0x3ULL << ID_AA64MMFR0_PA_RANGE_SHIFT) +#define ID_AA64MMFR0_PA_RANGE_16T (0x4ULL << ID_AA64MMFR0_PA_RANGE_SHIFT) +#define ID_AA64MMFR0_PA_RANGE_256T (0x5ULL << ID_AA64MMFR0_PA_RANGE_SHIFT) +#define ID_AA64MMFR0_ASID_BITS_SHIFT 4 +#define ID_AA64MMFR0_ASID_BITS_MASK (0xfULL << ID_AA64MMFR0_ASID_BITS_SHIFT) +#define ID_AA64MMFR0_ASID_BITS(x) ((x) & ID_AA64MMFR0_ASID_BITS_MASK) +#define ID_AA64MMFR0_ASID_BITS_8 (0x0ULL << ID_AA64MMFR0_ASID_BITS_SHIFT) +#define ID_AA64MMFR0_ASID_BITS_16 (0x2ULL << ID_AA64MMFR0_ASID_BITS_SHIFT) +#define ID_AA64MMFR0_BIGEND_SHIFT 8 +#define ID_AA64MMFR0_BIGEND_MASK (0xfULL << ID_AA64MMFR0_BIGEND_SHIFT) +#define ID_AA64MMFR0_BIGEND(x) ((x) & ID_AA64MMFR0_BIGEND_MASK) +#define ID_AA64MMFR0_BIGEND_FIXED (0x0ULL << ID_AA64MMFR0_BIGEND_SHIFT) +#define ID_AA64MMFR0_BIGEND_MIXED (0x1ULL << ID_AA64MMFR0_BIGEND_SHIFT) +#define ID_AA64MMFR0_S_NS_MEM_SHIFT 12 +#define ID_AA64MMFR0_S_NS_MEM_MASK (0xfULL << ID_AA64MMFR0_S_NS_MEM_SHIFT) +#define ID_AA64MMFR0_S_NS_MEM(x) ((x) & ID_AA64MMFR0_S_NS_MEM_MASK) +#define ID_AA64MMFR0_S_NS_MEM_NONE (0x0ULL << ID_AA64MMFR0_S_NS_MEM_SHIFT) +#define ID_AA64MMFR0_S_NS_MEM_DISTINCT (0x1ULL << ID_AA64MMFR0_S_NS_MEM_SHIFT) +#define ID_AA64MMFR0_BIGEND_EL0_SHIFT 16 +#define ID_AA64MMFR0_BIGEND_EL0_MASK (0xfULL << ID_AA64MMFR0_BIGEND_EL0_SHIFT) +#define ID_AA64MMFR0_BIGEND_EL0(x) ((x) & ID_AA64MMFR0_BIGEND_EL0_MASK) +#define ID_AA64MMFR0_BIGEND_EL0_FIXED (0x0ULL << ID_AA64MMFR0_BIGEND_EL0_SHIFT) +#define ID_AA64MMFR0_BIGEND_EL0_MIXED (0x1ULL << ID_AA64MMFR0_BIGEND_EL0_SHIFT) +#define ID_AA64MMFR0_TGRAN16_SHIFT 20 +#define ID_AA64MMFR0_TGRAN16_MASK (0xfULL << ID_AA64MMFR0_TGRAN16_SHIFT) +#define ID_AA64MMFR0_TGRAN16(x) ((x) & ID_AA64MMFR0_TGRAN16_MASK) +#define ID_AA64MMFR0_TGRAN16_NONE (0x0ULL << ID_AA64MMFR0_TGRAN16_SHIFT) +#define ID_AA64MMFR0_TGRAN16_IMPL (0x1ULL << ID_AA64MMFR0_TGRAN16_SHIFT) +#define ID_AA64MMFR0_TGRAN64_SHIFT 24 +#define ID_AA64MMFR0_TGRAN64_MASK (0xfULL << ID_AA64MMFR0_TGRAN64_SHIFT) +#define ID_AA64MMFR0_TGRAN64(x) ((x) & ID_AA64MMFR0_TGRAN64_MASK) +#define ID_AA64MMFR0_TGRAN64_IMPL (0x0ULL << ID_AA64MMFR0_TGRAN64_SHIFT) +#define ID_AA64MMFR0_TGRAN64_NONE (0xfULL << ID_AA64MMFR0_TGRAN64_SHIFT) +#define ID_AA64MMFR0_TGRAN4_SHIFT 28 +#define ID_AA64MMFR0_TGRAN4_MASK (0xfULL << ID_AA64MMFR0_TGRAN4_SHIFT) +#define ID_AA64MMFR0_TGRAN4(x) ((x) & ID_AA64MMFR0_TGRAN4_MASK) +#define ID_AA64MMFR0_TGRAN4_IMPL (0x0ULL << ID_AA64MMFR0_TGRAN4_SHIFT) +#define ID_AA64MMFR0_TGRAN4_NONE (0xfULL << ID_AA64MMFR0_TGRAN4_SHIFT) +#define ID_AA64MMFR0_ECV_SHIFT 60 +#define ID_AA64MMFR0_ECV_MASK (0xfULL << ID_AA64MMFR0_ECV_SHIFT) +#define ID_AA64MMFR0_ECV(x) ((x) & ID_AA64MMFR0_ECV_MASK) +#define ID_AA64MMFR0_ECV_NONE (0x0ULL << ID_AA64MMFR0_ECV_SHIFT) +#define ID_AA64MMFR0_ECV_IMPL (0x1ULL << ID_AA64MMFR0_ECV_SHIFT) +#define ID_AA64MMFR0_ECV_CNTHCTL (0x2ULL << ID_AA64MMFR0_ECV_SHIFT) + +/* ID_AA64MMFR1_EL1 */ +#define ID_AA64MMFR1_MASK 0xf000f000ffffffffULL +#define ID_AA64MMFR1_HAFDBS_SHIFT 0 +#define ID_AA64MMFR1_HAFDBS_MASK (0xfULL << ID_AA64MMFR1_HAFDBS_SHIFT) +#define ID_AA64MMFR1_HAFDBS(x) ((x) & ID_AA64MMFR1_HAFDBS_MASK) +#define ID_AA64MMFR1_HAFDBS_NONE (0x0ULL << ID_AA64MMFR1_HAFDBS_SHIFT) +#define ID_AA64MMFR1_HAFDBS_AF (0x1ULL << ID_AA64MMFR1_HAFDBS_SHIFT) +#define ID_AA64MMFR1_HAFDBS_AF_DBS (0x2ULL << ID_AA64MMFR1_HAFDBS_SHIFT) +#define ID_AA64MMFR1_VMIDBITS_SHIFT 4 +#define ID_AA64MMFR1_VMIDBITS_MASK (0xfULL << ID_AA64MMFR1_VMIDBITS_SHIFT) +#define ID_AA64MMFR1_VMIDBITS(x) ((x) & ID_AA64MMFR1_VMIDBITS_MASK) +#define ID_AA64MMFR1_VMIDBITS_8 (0x0ULL << ID_AA64MMFR1_VMIDBITS_SHIFT) +#define ID_AA64MMFR1_VMIDBITS_16 (0x2ULL << ID_AA64MMFR1_VMIDBITS_SHIFT) +#define ID_AA64MMFR1_VH_SHIFT 8 +#define ID_AA64MMFR1_VH_MASK (0xfULL << ID_AA64MMFR1_VH_SHIFT) +#define ID_AA64MMFR1_VH(x) ((x) & ID_AA64MMFR1_VH_MASK) +#define ID_AA64MMFR1_VH_NONE (0x0ULL << ID_AA64MMFR1_VH_SHIFT) +#define ID_AA64MMFR1_VH_IMPL (0x1ULL << ID_AA64MMFR1_VH_SHIFT) +#define ID_AA64MMFR1_HPDS_SHIFT 12 +#define ID_AA64MMFR1_HPDS_MASK (0xfULL << ID_AA64MMFR1_HPDS_SHIFT) +#define ID_AA64MMFR1_HPDS(x) ((x) & ID_AA64MMFR1_HPDS_MASK) +#define ID_AA64MMFR1_HPDS_NONE (0x0ULL << ID_AA64MMFR1_HPDS_SHIFT) +#define ID_AA64MMFR1_HPDS_IMPL (0x1ULL << ID_AA64MMFR1_HPDS_SHIFT) +#define ID_AA64MMFR1_LO_SHIFT 16 +#define ID_AA64MMFR1_LO_MASK (0xfULL << ID_AA64MMFR1_LO_SHIFT) +#define ID_AA64MMFR1_LO(x) ((x) & ID_AA64MMFR1_LO_MASK) +#define ID_AA64MMFR1_LO_NONE (0x0ULL << ID_AA64MMFR1_LO_SHIFT) +#define ID_AA64MMFR1_LO_IMPL (0x1ULL << ID_AA64MMFR1_LO_SHIFT) +#define ID_AA64MMFR1_PAN_SHIFT 20 +#define ID_AA64MMFR1_PAN_MASK (0xfULL << ID_AA64MMFR1_PAN_SHIFT) +#define ID_AA64MMFR1_PAN(x) ((x) & ID_AA64MMFR1_PAN_MASK) +#define ID_AA64MMFR1_PAN_NONE (0x0ULL << ID_AA64MMFR1_PAN_SHIFT) +#define ID_AA64MMFR1_PAN_IMPL (0x1ULL << ID_AA64MMFR1_PAN_SHIFT) +#define ID_AA64MMFR1_PAN_ATS1E1 (0x2ULL << ID_AA64MMFR1_PAN_SHIFT) +#define ID_AA64MMFR1_PAN_EPAN (0x3ULL << ID_AA64MMFR1_PAN_SHIFT) +#define ID_AA64MMFR1_SPECSEI_SHIFT 24 +#define ID_AA64MMFR1_SPECSEI_MASK (0xfULL << ID_AA64MMFR1_SPECSEI_SHIFT) +#define ID_AA64MMFR1_SPECSEI(x) ((x) & ID_AA64MMFR1_SPECSEI_MASK) +#define ID_AA64MMFR1_SPECSEI_NONE (0x0ULL << ID_AA64MMFR1_SPECSEI_SHIFT) +#define ID_AA64MMFR1_SPECSEI_IMPL (0x1ULL << ID_AA64MMFR1_SPECSEI_SHIFT) +#define ID_AA64MMFR1_XNX_SHIFT 28 +#define ID_AA64MMFR1_XNX_MASK (0xfULL << ID_AA64MMFR1_XNX_SHIFT) +#define ID_AA64MMFR1_XNX(x) ((x) & ID_AA64MMFR1_XNX_MASK) +#define ID_AA64MMFR1_XNX_NONE (0x0ULL << ID_AA64MMFR1_XNX_SHIFT) +#define ID_AA64MMFR1_XNX_IMPL (0x1ULL << ID_AA64MMFR1_XNX_SHIFT) +#define ID_AA64MMFR1_AFP_SHIFT 44 +#define ID_AA64MMFR1_AFP_MASK (0xfULL << ID_AA64MMFR1_AFP_SHIFT) +#define ID_AA64MMFR1_AFP(x) ((x) & ID_AA64MMFR1_AFP_MASK) +#define ID_AA64MMFR1_AFP_NONE (0x0ULL << ID_AA64MMFR1_AFP_SHIFT) +#define ID_AA64MMFR1_AFP_IMPL (0x1ULL << ID_AA64MMFR1_AFP_SHIFT) +#define ID_AA64MMFR1_ECBHB_SHIFT 60 +#define ID_AA64MMFR1_ECBHB_MASK (0xfULL << ID_AA64MMFR1_ECBHB_SHIFT) +#define ID_AA64MMFR1_ECBHB(x) ((x) & ID_AA64MMFR1_ECBHB_MASK) +#define ID_AA64MMFR1_ECBHB_NONE (0x0ULL << ID_AA64MMFR1_ECBHB_SHIFT) +#define ID_AA64MMFR1_ECBHB_IMPL (0x1ULL << ID_AA64MMFR1_ECBHB_SHIFT) + +/* ID_AA64MMFR2_EL1 */ +#define ID_AA64MMFR2_MASK 0xffff0fffffffffffULL +#define ID_AA64MMFR2_CCIDX_SHIFT 20 +#define ID_AA64MMFR2_CCIDX_MASK (0xfULL << ID_AA64MMFR2_CCIDX_SHIFT) +#define ID_AA64MMFR2_CCIDX(x) ((x) & ID_AA64MMFR2_CCIDX_MASK) +#define ID_AA64MMFR2_CCIDX_IMPL (0x1ULL << ID_AA64MMFR2_CCIDX_SHIFT) +#define ID_AA64MMFR2_AT_SHIFT 32 +#define ID_AA64MMFR2_AT_MASK (0xfULL << ID_AA64MMFR2_AT_SHIFT) +#define ID_AA64MMFR2_AT(x) ((x) & ID_AA64MMFR2_AT_MASK) +#define ID_AA64MMFR2_AT_NONE (0x0ULL << ID_AA64MMFR2_AT_SHIFT) +#define ID_AA64MMFR2_AT_IMPL (0x1ULL << ID_AA64MMFR2_AT_SHIFT) +#define ID_AA64MMFR2_IDS_SHIFT 36 +#define ID_AA64MMFR2_IDS_MASK (0xfULL << ID_AA64MMFR2_IDS_SHIFT) +#define ID_AA64MMFR2_IDS(x) ((x) & ID_AA64MMFR2_IDS_MASK) +#define ID_AA64MMFR2_IDS_NONE (0x0ULL << ID_AA64MMFR2_IDS_SHIFT) +#define ID_AA64MMFR2_IDS_IMPL (0x1ULL << ID_AA64MMFR2_IDS_SHIFT) + +/* ID_AA64PFR0_EL1 */ +#define ID_AA64PFR0_MASK 0xff0fffffffffffffULL +#define ID_AA64PFR0_EL0_SHIFT 0 +#define ID_AA64PFR0_EL0_MASK (0xfULL << ID_AA64PFR0_EL0_SHIFT) +#define ID_AA64PFR0_EL0(x) ((x) & ID_AA64PFR0_EL0_MASK) +#define ID_AA64PFR0_EL0_64 (0x1ULL << ID_AA64PFR0_EL0_SHIFT) +#define ID_AA64PFR0_EL0_64_32 (0x2ULL << ID_AA64PFR0_EL0_SHIFT) +#define ID_AA64PFR0_EL1_SHIFT 4 +#define ID_AA64PFR0_EL1_MASK (0xfULL << ID_AA64PFR0_EL1_SHIFT) +#define ID_AA64PFR0_EL1(x) ((x) & ID_AA64PFR0_EL1_MASK) +#define ID_AA64PFR0_EL1_64 (0x1ULL << ID_AA64PFR0_EL1_SHIFT) +#define ID_AA64PFR0_EL1_64_32 (0x2ULL << ID_AA64PFR0_EL1_SHIFT) +#define ID_AA64PFR0_EL2_SHIFT 8 +#define ID_AA64PFR0_EL2_MASK (0xfULL << ID_AA64PFR0_EL2_SHIFT) +#define ID_AA64PFR0_EL2(x) ((x) & ID_AA64PFR0_EL2_MASK) +#define ID_AA64PFR0_EL2_NONE (0x0ULL << ID_AA64PFR0_EL2_SHIFT) +#define ID_AA64PFR0_EL2_64 (0x1ULL << ID_AA64PFR0_EL2_SHIFT) +#define ID_AA64PFR0_EL2_64_32 (0x2ULL << ID_AA64PFR0_EL2_SHIFT) +#define ID_AA64PFR0_EL3_SHIFT 12 +#define ID_AA64PFR0_EL3_MASK (0xfULL << ID_AA64PFR0_EL3_SHIFT) +#define ID_AA64PFR0_EL3(x) ((x) & ID_AA64PFR0_EL3_MASK) +#define ID_AA64PFR0_EL3_NONE (0x0ULL << ID_AA64PFR0_EL3_SHIFT) +#define ID_AA64PFR0_EL3_64 (0x1ULL << ID_AA64PFR0_EL3_SHIFT) +#define ID_AA64PFR0_EL3_64_32 (0x2ULL << ID_AA64PFR0_EL3_SHIFT) +#define ID_AA64PFR0_FP_SHIFT 16 +#define ID_AA64PFR0_FP_MASK (0xfULL << ID_AA64PFR0_FP_SHIFT) +#define ID_AA64PFR0_FP(x) ((x) & ID_AA64PFR0_FP_MASK) +#define ID_AA64PFR0_FP_IMPL (0x0ULL << ID_AA64PFR0_FP_SHIFT) +#define ID_AA64PFR0_FP_HP (0x1ULL << ID_AA64PFR0_FP_SHIFT) +#define ID_AA64PFR0_FP_NONE (0xfULL << ID_AA64PFR0_FP_SHIFT) +#define ID_AA64PFR0_ADV_SIMD_SHIFT 20 +#define ID_AA64PFR0_ADV_SIMD_MASK (0xfULL << ID_AA64PFR0_ADV_SIMD_SHIFT) +#define ID_AA64PFR0_ADV_SIMD(x) ((x) & ID_AA64PFR0_ADV_SIMD_MASK) +#define ID_AA64PFR0_ADV_SIMD_IMPL (0x0ULL << ID_AA64PFR0_ADV_SIMD_SHIFT) +#define ID_AA64PFR0_ADV_SIMD_HP (0x1ULL << ID_AA64PFR0_ADV_SIMD_SHIFT) +#define ID_AA64PFR0_ADV_SIMD_NONE (0xfULL << ID_AA64PFR0_ADV_SIMD_SHIFT) +#define ID_AA64PFR0_GIC_BITS 0x4 /* Number of bits in GIC field */ +#define ID_AA64PFR0_GIC_SHIFT 24 +#define ID_AA64PFR0_GIC_MASK (0xfULL << ID_AA64PFR0_GIC_SHIFT) +#define ID_AA64PFR0_GIC(x) ((x) & ID_AA64PFR0_GIC_MASK) +#define ID_AA64PFR0_GIC_CPUIF_NONE (0x0ULL << ID_AA64PFR0_GIC_SHIFT) +#define ID_AA64PFR0_GIC_CPUIF_EN (0x1ULL << ID_AA64PFR0_GIC_SHIFT) +#define ID_AA64PFR0_RAS_SHIFT 28 +#define ID_AA64PFR0_RAS_MASK (0xfULL << ID_AA64PFR0_RAS_SHIFT) +#define ID_AA64PFR0_RAS(x) ((x) & ID_AA64PFR0_RAS_MASK) +#define ID_AA64PFR0_RAS_NONE (0x0ULL << ID_AA64PFR0_RAS_SHIFT) +#define ID_AA64PFR0_RAS_IMPL (0x1ULL << ID_AA64PFR0_RAS_SHIFT) +#define ID_AA64PFR0_RAS_IMPL_V1P1 (0x2ULL << ID_AA64PFR0_RAS_SHIFT) +#define ID_AA64PFR0_SVE_SHIFT 32 +#define ID_AA64PFR0_SVE_MASK (0xfULL << ID_AA64PFR0_SVE_SHIFT) +#define ID_AA64PFR0_SVE(x) ((x) & ID_AA64PFR0_SVE_MASK) +#define ID_AA64PFR0_SVE_NONE (0x0ULL << ID_AA64PFR0_SVE_SHIFT) +#define ID_AA64PFR0_SVE_IMPL (0x1ULL << ID_AA64PFR0_SVE_SHIFT) +#define ID_AA64PFR0_SEL2_SHIFT 36 +#define ID_AA64PFR0_SEL2_MASK (0xfULL << ID_AA64PFR0_SEL2_SHIFT) +#define ID_AA64PFR0_SEL2(x) ((x) & ID_AA64PFR0_SEL2_MASK) +#define ID_AA64PFR0_SEL2_NONE (0x0ULL << ID_AA64PFR0_SEL2_SHIFT) +#define ID_AA64PFR0_SEL2_IMPL (0x1ULL << ID_AA64PFR0_SEL2_SHIFT) +#define ID_AA64PFR0_MPAM_SHIFT 40 +#define ID_AA64PFR0_MPAM_MASK (0xfULL << ID_AA64PFR0_MPAM_SHIFT) +#define ID_AA64PFR0_MPAM(x) ((x) & ID_AA64PFR0_MPAM_MASK) +#define ID_AA64PFR0_MPAM_NONE (0x0ULL << ID_AA64PFR0_MPAM_SHIFT) +#define ID_AA64PFR0_MPAM_IMPL (0x1ULL << ID_AA64PFR0_MPAM_SHIFT) +#define ID_AA64PFR0_AMU_SHIFT 44 +#define ID_AA64PFR0_AMU_MASK (0xfULL << ID_AA64PFR0_AMU_SHIFT) +#define ID_AA64PFR0_AMU(x) ((x) & ID_AA64PFR0_AMU_MASK) +#define ID_AA64PFR0_AMU_NONE (0x0ULL << ID_AA64PFR0_AMU_SHIFT) +#define ID_AA64PFR0_AMU_IMPL (0x1ULL << ID_AA64PFR0_AMU_SHIFT) +#define ID_AA64PFR0_AMU_IMPL_V1P1 (0x2ULL << ID_AA64PFR0_AMU_SHIFT) +#define ID_AA64PFR0_DIT_SHIFT 48 +#define ID_AA64PFR0_DIT_MASK (0xfULL << ID_AA64PFR0_DIT_SHIFT) +#define ID_AA64PFR0_DIT(x) ((x) & ID_AA64PFR0_DIT_MASK) +#define ID_AA64PFR0_DIT_UNKNOWN (0x0ULL << ID_AA64PFR0_DIT_SHIFT) +#define ID_AA64PFR0_DIT_IMPL (0x1ULL << ID_AA64PFR0_DIT_SHIFT) +#define ID_AA64PFR0_CSV2_SHIFT 56 +#define ID_AA64PFR0_CSV2_MASK (0xfULL << ID_AA64PFR0_CSV2_SHIFT) +#define ID_AA64PFR0_CSV2(x) ((x) & ID_AA64PFR0_CSV2_MASK) +#define ID_AA64PFR0_CSV2_UNKNOWN (0x0ULL << ID_AA64PFR0_CSV2_SHIFT) +#define ID_AA64PFR0_CSV2_IMPL (0x1ULL << ID_AA64PFR0_CSV2_SHIFT) +#define ID_AA64PFR0_CSV2_SCXT (0x2ULL << ID_AA64PFR0_CSV2_SHIFT) +#define ID_AA64PFR0_CSV2_HCXT (0x3ULL << ID_AA64PFR0_CSV2_SHIFT) +#define ID_AA64PFR0_CSV3_SHIFT 60 +#define ID_AA64PFR0_CSV3_MASK (0xfULL << ID_AA64PFR0_CSV3_SHIFT) +#define ID_AA64PFR0_CSV3(x) ((x) & ID_AA64PFR0_CSV3_MASK) +#define ID_AA64PFR0_CSV3_UNKNOWN (0x0ULL << ID_AA64PFR0_CSV3_SHIFT) +#define ID_AA64PFR0_CSV3_IMPL (0x1ULL << ID_AA64PFR0_CSV3_SHIFT) + +/* ID_AA64PFR1_EL1 */ +#define ID_AA64PFR1_MASK 0x000000000000ffffULL +#define ID_AA64PFR1_BT_SHIFT 0 +#define ID_AA64PFR1_BT_MASK (0xfULL << ID_AA64PFR1_BT_SHIFT) +#define ID_AA64PFR1_BT(x) ((x) & ID_AA64PFR1_BT_MASK) +#define ID_AA64PFR1_BT_NONE (0x0ULL << ID_AA64PFR1_BT_SHIFT) +#define ID_AA64PFR1_BT_IMPL (0x1ULL << ID_AA64PFR1_BT_SHIFT) +#define ID_AA64PFR1_SSBS_SHIFT 4 +#define ID_AA64PFR1_SSBS_MASK (0xfULL << ID_AA64PFR1_SSBS_SHIFT) +#define ID_AA64PFR1_SSBS(x) ((x) & ID_AA64PFR1_SSBS_MASK) +#define ID_AA64PFR1_SSBS_NONE (0x0ULL << ID_AA64PFR1_SSBS_SHIFT) +#define ID_AA64PFR1_SSBS_PSTATE (0x1ULL << ID_AA64PFR1_SSBS_SHIFT) +#define ID_AA64PFR1_SSBS_PSTATE_MSR (0x2ULL << ID_AA64PFR1_SSBS_SHIFT) +#define ID_AA64PFR1_MTE_SHIFT 8 +#define ID_AA64PFR1_MTE_MASK (0xfULL << ID_AA64PFR1_MTE_SHIFT) +#define ID_AA64PFR1_MTE(x) ((x) & ID_AA64PFR1_MTE_MASK) +#define ID_AA64PFR1_MTE_NONE (0x0ULL << ID_AA64PFR1_MTE_SHIFT) +#define ID_AA64PFR1_MTE_IMPL (0x1ULL << ID_AA64PFR1_MTE_SHIFT) +#define ID_AA64PFR1_RAS_FRAC_SHIFT 12 +#define ID_AA64PFR1_RAS_FRAC_MASK (0xfULL << ID_AA64PFR1_RAS_FRAC_SHIFT) +#define ID_AA64PFR1_RAS_FRAC(x) ((x) & ID_AA64PFR1_RAS_FRAC_MASK) +#define ID_AA64PFR1_RAS_FRAC_NONE (0x0ULL << ID_AA64PFR1_RAS_FRAC_SHIFT) +#define ID_AA64PFR1_RAS_FRAC_IMPL (0x1ULL << ID_AA64PFR1_RAS_FRAC_SHIFT) + +/* ID_AA64ZFR0_EL1 */ +#define ID_AA64ZFR0_MASK 0x0ff0ff0f00ff00ffULL +#define ID_AA64ZFR0_SVEVER_SHIFT 0 +#define ID_AA64ZFR0_SVEVER_MASK (0xfULL << ID_AA64ZFR0_SVEVER_SHIFT) +#define ID_AA64ZFR0_SVEVER(x) ((x) & ID_AA64ZFR0_SVEVER_MASK) +#define ID_AA64ZFR0_SVEVER_SVE1 (0x0ULL << ID_AA64ZFR0_SVEVER_SHIFT) +#define ID_AA64ZFR0_SVEVER_SVE2 (0x1ULL << ID_AA64ZFR0_SVEVER_SHIFT) +#define ID_AA64ZFR0_SVEVER_SVE2P1 (0x2ULL << ID_AA64ZFR0_SVEVER_SHIFT) +#define ID_AA64ZFR0_AES_SHIFT 4 +#define ID_AA64ZFR0_AES_MASK (0xfULL << ID_AA64ZFR0_AES_SHIFT) +#define ID_AA64ZFR0_AES(x) ((x) & ID_AA64ZFR0_AES_MASK) +#define ID_AA64ZFR0_AES_NONE (0x0ULL << ID_AA64ZFR0_AES_SHIFT) +#define ID_AA64ZFR0_AES_BASE (0x1ULL << ID_AA64ZFR0_AES_SHIFT) +#define ID_AA64ZFR0_AES_PMULL (0x2ULL << ID_AA64ZFR0_AES_SHIFT) +#define ID_AA64ZFR0_BITPERM_SHIFT 16 +#define ID_AA64ZFR0_BITPERM_MASK (0xfULL << ID_AA64ZFR0_BITPERM_SHIFT) +#define ID_AA64ZFR0_BITPERM(x) ((x) & ID_AA64ZFR0_BITPERM_MASK) +#define ID_AA64ZFR0_BITPERM_NONE (0x0ULL << ID_AA64ZFR0_BITPERM_SHIFT) +#define ID_AA64ZFR0_BITPERM_IMPL (0x1ULL << ID_AA64ZFR0_BITPERM_SHIFT) +#define ID_AA64ZFR0_BF16_SHIFT 20 +#define ID_AA64ZFR0_BF16_MASK (0xfULL << ID_AA64ZFR0_BF16_SHIFT) +#define ID_AA64ZFR0_BF16(x) ((x) & ID_AA64ZFR0_BF16_MASK) +#define ID_AA64ZFR0_BF16_NONE (0x0ULL << ID_AA64ZFR0_BF16_SHIFT) +#define ID_AA64ZFR0_BF16_BASE (0x1ULL << ID_AA64ZFR0_BF16_SHIFT) +#define ID_AA64ZFR0_BF16_EBF (0x2ULL << ID_AA64ZFR0_BF16_SHIFT) +#define ID_AA64ZFR0_SHA3_SHIFT 32 +#define ID_AA64ZFR0_SHA3_MASK (0xfULL << ID_AA64ZFR0_SHA3_SHIFT) +#define ID_AA64ZFR0_SHA3(x) ((x) & ID_AA64ZFR0_SHA3_MASK) +#define ID_AA64ZFR0_SHA3_NONE (0x0ULL << ID_AA64ZFR0_SHA3_SHIFT) +#define ID_AA64ZFR0_SHA3_IMPL (0x1ULL << ID_AA64ZFR0_SHA3_SHIFT) +#define ID_AA64ZFR0_SM4_SHIFT 40 +#define ID_AA64ZFR0_SM4_MASK (0xfULL << ID_AA64ZFR0_SM4_SHIFT) +#define ID_AA64ZFR0_SM4(x) ((x) & ID_AA64ZFR0_SM4_MASK) +#define ID_AA64ZFR0_SM4_NONE (0x0ULL << ID_AA64ZFR0_SM4_SHIFT) +#define ID_AA64ZFR0_SM4_IMPL (0x1ULL << ID_AA64ZFR0_SM4_SHIFT) +#define ID_AA64ZFR0_I8MM_SHIFT 44 +#define ID_AA64ZFR0_I8MM_MASK (0xfULL << ID_AA64ZFR0_I8MM_SHIFT) +#define ID_AA64ZFR0_I8MM(x) ((x) & ID_AA64ZFR0_I8MM_MASK) +#define ID_AA64ZFR0_I8MM_NONE (0x0ULL << ID_AA64ZFR0_I8MM_SHIFT) +#define ID_AA64ZFR0_I8MM_IMPL (0x1ULL << ID_AA64ZFR0_I8MM_SHIFT) +#define ID_AA64ZFR0_F32MM_SHIFT 52 +#define ID_AA64ZFR0_F32MM_MASK (0xfULL << ID_AA64ZFR0_F32MM_SHIFT) +#define ID_AA64ZFR0_F32MM(x) ((x) & ID_AA64ZFR0_F32MM_MASK) +#define ID_AA64ZFR0_F32MM_NONE (0x0ULL << ID_AA64ZFR0_F32MM_SHIFT) +#define ID_AA64ZFR0_F32MM_IMPL (0x1ULL << ID_AA64ZFR0_F32MM_SHIFT) +#define ID_AA64ZFR0_F64MM_SHIFT 56 +#define ID_AA64ZFR0_F64MM_MASK (0xfULL << ID_AA64ZFR0_F64MM_SHIFT) +#define ID_AA64ZFR0_F64MM(x) ((x) & ID_AA64ZFR0_F64MM_MASK) +#define ID_AA64ZFR0_F64MM_NONE (0x0ULL << ID_AA64ZFR0_F64MM_SHIFT) +#define ID_AA64ZFR0_F64MM_IMPL (0x1ULL << ID_AA64ZFR0_F64MM_SHIFT) + +/* MAIR_EL1 - Memory Attribute Indirection Register */ +#define MAIR_ATTR_MASK(idx) (0xff << ((n)* 8)) +#define MAIR_ATTR(attr, idx) ((attr) << ((idx) * 8)) +#define MAIR_DEVICE_nGnRnE 0x00 +#define MAIR_NORMAL_NC 0x44 +#define MAIR_NORMAL_WT 0x88 +#define MAIR_NORMAL_WB 0xff + +/* PAR_EL1 - Physical Address Register */ +#define PAR_F_SHIFT 0 +#define PAR_F (0x1 << PAR_F_SHIFT) +#define PAR_SUCCESS(x) (((x) & PAR_F) == 0) +/* When PAR_F == 0 (success) */ +#define PAR_SH_SHIFT 7 +#define PAR_SH_MASK (0x3 << PAR_SH_SHIFT) +#define PAR_NS_SHIFT 9 +#define PAR_NS_MASK (0x3 << PAR_NS_SHIFT) +#define PAR_PA_SHIFT 12 +#define PAR_PA_MASK 0x0000fffffffff000 +#define PAR_ATTR_SHIFT 56 +#define PAR_ATTR_MASK (0xff << PAR_ATTR_SHIFT) +/* When PAR_F == 1 (aborted) */ +#define PAR_FST_SHIFT 1 +#define PAR_FST_MASK (0x3f << PAR_FST_SHIFT) +#define PAR_PTW_SHIFT 8 +#define PAR_PTW_MASK (0x1 << PAR_PTW_SHIFT) +#define PAR_S_SHIFT 9 +#define PAR_S_MASK (0x1 << PAR_S_SHIFT) + +/* SCTLR_EL1 - System Control Register */ +#define SCTLR_RES0 0xffffffffc8222400 /* Reserved, write 0 */ +#define SCTLR_RES1 0x0000000030d00800 /* Reserved, write 1 */ + +#define SCTLR_M 0x0000000000000001 +#define SCTLR_A 0x0000000000000002 +#define SCTLR_C 0x0000000000000004 +#define SCTLR_SA 0x0000000000000008 +#define SCTLR_SA0 0x0000000000000010 +#define SCTLR_CP15BEN 0x0000000000000020 +#define SCTLR_THEE 0x0000000000000040 +#define SCTLR_ITD 0x0000000000000080 +#define SCTLR_SED 0x0000000000000100 +#define SCTLR_UMA 0x0000000000000200 +#define SCTLR_I 0x0000000000001000 +#define SCTLR_EnDB 0x0000000000002000 +#define SCTLR_DZE 0x0000000000004000 +#define SCTLR_UCT 0x0000000000008000 +#define SCTLR_nTWI 0x0000000000010000 +#define SCTLR_nTWE 0x0000000000040000 +#define SCTLR_WXN 0x0000000000080000 +#define SCTLR_SPAN 0x0000000000800000 +#define SCTLR_EOE 0x0000000001000000 +#define SCTLR_EE 0x0000000002000000 +#define SCTLR_UCI 0x0000000004000000 +#define SCTLR_EnDA 0x0000000008000000 +#define SCTLR_EnIB 0x0000000040000000 +#define SCTLR_EnIA 0x0000000080000000 +#define SCTLR_BT0 0x0000000800000000 +#define SCTLR_BT1 0x0000001000000000 +#define SCTLR_EPAN 0x0200000000000000 + +/* SPSR_EL1 */ +/* + * When the exception is taken in AArch64: + * M[4] is 0 for AArch64 mode + * M[3:2] is the exception level + * M[1] is unused + * M[0] is the SP select: + * 0: always SP0 + * 1: current ELs SP + */ +#define PSR_M_EL0t 0x00000000 +#define PSR_M_EL1t 0x00000004 +#define PSR_M_EL1h 0x00000005 +#define PSR_M_EL2t 0x00000008 +#define PSR_M_EL2h 0x00000009 +#define PSR_M_MASK 0x0000001f + +#define PSR_F 0x00000040 +#define PSR_I 0x00000080 +#define PSR_A 0x00000100 +#define PSR_D 0x00000200 +#define PSR_BTYPE 0x00000c00 +#define PSR_SSBS 0x00001000 +#define PSR_IL 0x00100000 +#define PSR_SS 0x00200000 +#define PSR_PAN 0x00400000 +#define PSR_UAO 0x00800000 +#define PSR_DIT 0x01000000 +#define PSR_TCO 0x02000000 +#define PSR_V 0x10000000 +#define PSR_C 0x20000000 +#define PSR_Z 0x40000000 +#define PSR_N 0x80000000 + +/* TCR_EL1 - Translation Control Register */ +#define TCR_AS (1UL << 36) + +#define TCR_IPS_SHIFT 32 +#define TCR_IPS_32BIT (0UL << TCR_IPS_SHIFT) +#define TCR_IPS_36BIT (1UL << TCR_IPS_SHIFT) +#define TCR_IPS_40BIT (2UL << TCR_IPS_SHIFT) +#define TCR_IPS_42BIT (3UL << TCR_IPS_SHIFT) +#define TCR_IPS_44BIT (4UL << TCR_IPS_SHIFT) +#define TCR_IPS_48BIT (5UL << TCR_IPS_SHIFT) + +#define TCR_TG1_SHIFT 30 +#define TCR_TG1_16K (1UL << TCR_TG1_SHIFT) +#define TCR_TG1_4K (2UL << TCR_TG1_SHIFT) +#define TCR_TG1_64K (3UL << TCR_TG1_SHIFT) + +#define TCR_SH1_SHIFT 28 +#define TCR_SH1_IS (0x3UL << TCR_SH1_SHIFT) +#define TCR_ORGN1_SHIFT 26 +#define TCR_ORGN1_WBWA (0x1UL << TCR_ORGN1_SHIFT) +#define TCR_IRGN1_SHIFT 24 +#define TCR_IRGN1_WBWA (0x1UL << TCR_IRGN1_SHIFT) + +#define TCR_A1 (1UL << 22) + +#define TCR_TG0_SHIFT 14 +#define TCR_TG0_4K (0UL << TCR_TG0_SHIFT) +#define TCR_TG0_64K (1UL << TCR_TG0_SHIFT) +#define TCR_TG0_16K (2UL << TCR_TG0_SHIFT) + +#define TCR_SH0_SHIFT 12 +#define TCR_SH0_IS (0x3UL << TCR_SH0_SHIFT) +#define TCR_ORGN0_SHIFT 10 +#define TCR_ORGN0_WBWA (0x1UL << TCR_ORGN0_SHIFT) +#define TCR_IRGN0_SHIFT 8 +#define TCR_IRGN0_WBWA (0x1UL << TCR_IRGN0_SHIFT) + +#define TCR_CACHE_ATTRS ((TCR_IRGN0_WBWA | TCR_IRGN1_WBWA) |\ + (TCR_ORGN0_WBWA | TCR_ORGN1_WBWA)) +#define TCR_SMP_ATTRS (TCR_SH0_IS | TCR_SH1_IS) + +#define TCR_T1SZ_SHIFT 16 +#define TCR_T0SZ_SHIFT 0 +#define TCR_T1SZ(x) ((x) << TCR_T1SZ_SHIFT) +#define TCR_T0SZ(x) ((x) << TCR_T0SZ_SHIFT) +#define TCR_TxSZ(x) (TCR_T1SZ(x) | TCR_T0SZ(x)) + +/* Monitor Debug System Control Register */ +#define DBG_MDSCR_SS (0x1 << 0) +#define DBG_MDSCR_TDCC (0x1 << 12) +#define DBG_MDSCR_KDE (0x1 << 13) +#define DBG_MDSCR_MDE (0x1 << 15) + +/* Performance Monitoring Counters */ +#define PMCR_E (1 << 0) /* Enable all counters */ +#define PMCR_P (1 << 1) /* Reset all counters */ +#define PMCR_C (1 << 2) /* Clock counter reset */ +#define PMCR_D (1 << 3) /* CNTR counts every 64 clk cycles */ +#define PMCR_X (1 << 4) /* Export to ext. monitoring (ETM) */ +#define PMCR_DP (1 << 5) /* Disable CCNT if non-invasive debug*/ +#define PMCR_LC (1 << 6) /* Long cycle count enable */ +#define PMCR_IMP_SHIFT 24 /* Implementer code */ +#define PMCR_IMP_MASK (0xff << PMCR_IMP_SHIFT) +#define PMCR_IDCODE_SHIFT 16 /* Identification code */ +#define PMCR_IDCODE_MASK (0xff << PMCR_IDCODE_SHIFT) +#define PMCR_IDCODE_CORTEX_A57 0x01 +#define PMCR_IDCODE_CORTEX_A72 0x02 +#define PMCR_IDCODE_CORTEX_A53 0x03 +#define PMCR_N_SHIFT 11 /* Number of counters implemented */ +#define PMCR_N_MASK (0x1f << PMCR_N_SHIFT) + +#define I_bit (1 << 7) /* IRQ disable */ +#define F_bit 0 /* FIQ disable - not actually used */ + +#endif /* !_MACHINE_ARMREG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/asm.h b/lib/libc/include/aarch64-openbsd-none/arm64/asm.h new file mode 100644 index 0000000000..e0ad18f38d --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/asm.h @@ -0,0 +1,150 @@ +/* $OpenBSD: asm.h,v 1.12 2023/03/27 19:02:48 kettenis Exp $ */ +/* $NetBSD: asm.h,v 1.4 2001/07/16 05:43:32 matt 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. + * + * from: @(#)asm.h 5.5 (Berkeley) 5/7/91 + */ + +#ifndef _MACHINE_ASM_H_ +#define _MACHINE_ASM_H_ + +#define _C_LABEL(x) x +#define _ASM_LABEL(x) x + +#ifdef __STDC__ +# define __CONCAT(x,y) x ## y +# define __STRING(x) #x +#else +# define __CONCAT(x,y) x/**/y +# define __STRING(x) "x" +#endif + +#ifndef _ALIGN_TEXT +# define _ALIGN_TEXT .align 0 +#endif + +/* + * gas/arm uses @ as a single comment character and thus cannot be used here + * Instead it recognised the # instead of an @ symbols in .type directives + * We define a couple of macros so that assembly code will not be dependant + * on one or the other. + */ +#define _ASM_TYPE_FUNCTION #function +#define _ASM_TYPE_OBJECT #object +/* NB == No Binding: use .globl or .weak as necessary */ +#define _ENTRY_NB(x) \ + .text; _ALIGN_TEXT; .type x,_ASM_TYPE_FUNCTION; x: +#define _ENTRY(x) .globl x; _ENTRY_NB(x) + +#if defined(PROF) || defined(GPROF) +# define _PROF_PROLOGUE \ + stp x29, x30, [sp, #-16]!; \ + mov fp, sp; \ + bl __mcount; \ + ldp x29, x30, [sp], #16; +#else +# define _PROF_PROLOGUE +#endif + +#if defined(_RET_PROTECTOR) +# define RETGUARD_CALC_COOKIE(reg) \ + eor reg, reg, x30 + +# define RETGUARD_LOAD_RANDOM(x, reg) \ + adrp reg, __CONCAT(__retguard_, x); \ + ldr reg, [reg, :lo12:__CONCAT(__retguard_, x)] + +# define RETGUARD_SETUP(x, reg) \ + RETGUARD_SYMBOL(x); \ + RETGUARD_LOAD_RANDOM(x, reg); \ + RETGUARD_CALC_COOKIE(reg) + +# define RETGUARD_CHECK(x, reg) \ + RETGUARD_CALC_COOKIE(reg); \ + RETGUARD_LOAD_RANDOM(x, x9); \ + subs reg, reg, x9; \ + cbz reg, 66f; \ + brk #0x1; \ +66: + +# define RETGUARD_PUSH(reg) \ + str reg, [sp, #-16]! + +# define RETGUARD_POP(reg) \ + ldr reg, [sp, #16]! + +# define RETGUARD_SYMBOL(x) \ + .ifndef __CONCAT(__retguard_, x); \ + .hidden __CONCAT(__retguard_, x); \ + .type __CONCAT(__retguard_, x),@object; \ + .pushsection .openbsd.randomdata.retguard,"aw",@progbits; \ + .weak __CONCAT(__retguard_, x); \ + .p2align 3; \ + __CONCAT(__retguard_, x): ; \ + .xword 0; \ + .size __CONCAT(__retguard_, x), 8; \ + .popsection; \ + .endif +#else +# define RETGUARD_CALC_COOKIE(reg) +# define RETGUARD_LOAD_RANDOM(x, reg) +# define RETGUARD_SETUP(x, reg) +# define RETGUARD_CHECK(x, reg) +# define RETGUARD_PUSH(reg) +# define RETGUARD_POP(reg) +# define RETGUARD_SYMBOL(x) +#endif + +#define ENTRY(y) _ENTRY(y); bti c; _PROF_PROLOGUE +#define ENTRY_NP(y) _ENTRY(y); bti c +#define ENTRY_NB(y) _ENTRY_NB(y); bti c; _PROF_PROLOGUE +#define ASENTRY(y) _ENTRY(y); bti c; _PROF_PROLOGUE +#define ASENTRY_NP(y) _ENTRY(y); bti c +#define END(y) .size y, . - y +#define EENTRY(sym) .globl sym; sym: +#define EEND(sym) + +#ifdef __PIC__ +#define PIC_SYM(x,y) x(y) +#else +#define PIC_SYM(x,y) x +#endif + +#define STRONG_ALIAS(alias,sym) \ + .global alias; \ + alias = sym +#define WEAK_ALIAS(alias,sym) \ + .weak alias; \ + alias = sym + +#endif /* !_MACHINE_ASM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/atomic.h b/lib/libc/include/aarch64-openbsd-none/arm64/atomic.h new file mode 100644 index 0000000000..7a66719a47 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/atomic.h @@ -0,0 +1,64 @@ +/* $OpenBSD: atomic.h,v 1.4 2022/08/29 02:01:18 jsg Exp $ */ + +/* Public Domain */ + +#ifndef _MACHINE_ATOMIC_H_ +#define _MACHINE_ATOMIC_H_ + +#define __membar(_f) do { __asm volatile(_f ::: "memory"); } while (0) + +#define membar_enter() __membar("dmb sy") +#define membar_exit() __membar("dmb sy") +#define membar_producer() __membar("dmb st") +#define membar_consumer() __membar("dmb ld") +#define membar_sync() __membar("dmb sy") + +#if defined(_KERNEL) + +/* virtio needs MP membars even on SP kernels */ +#define virtio_membar_producer() __membar("dmb st") +#define virtio_membar_consumer() __membar("dmb ld") +#define virtio_membar_sync() __membar("dmb sy") + +/* + * Set bits + * *p = *p | v + */ +static inline void +atomic_setbits_int(volatile unsigned int *p, unsigned int v) +{ + unsigned int modified, tmp; + + __asm volatile ( + "1: ldxr %w0, [%x3] \n\t" + " orr %w0, %w0, %w2 \n\t" + " stxr %w1, %w0, [%x3] \n\t" + " cbnz %w1, 1b \n\t" + : "=&r" (tmp), "=&r" (modified) + : "r" (v), "r" (p) + : "memory", "cc" + ); +} + +/* + * Clear bits + * *p = *p & (~v) + */ +static inline void +atomic_clearbits_int(volatile unsigned int *p, unsigned int v) +{ + unsigned int modified, tmp; + + __asm volatile ( + "1: ldxr %w0, [%x3] \n\t" + " bic %w0, %w0, %w2 \n\t" + " stxr %w1, %w0, [%x3] \n\t" + " cbnz %w1, 1b \n\t" + : "=&r" (tmp), "=&r" (modified) + : "r" (v), "r" (p) + : "memory", "cc" + ); +} + +#endif /* defined(_KERNEL) */ +#endif /* _MACHINE_ATOMIC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/bootconfig.h b/lib/libc/include/aarch64-openbsd-none/arm64/bootconfig.h new file mode 100644 index 0000000000..8767d1ab7f --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/bootconfig.h @@ -0,0 +1,47 @@ +/* $OpenBSD: bootconfig.h,v 1.4 2023/12/05 05:27:26 jsg Exp $ */ +/* $NetBSD: bootconfig.h,v 1.2 2001/06/21 22:08:28 chris Exp $ */ + +/*- + * Copyright (c) 2013 Andrew Turner + * 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 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 AUTHOR 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. + * + * $FreeBSD: head/sys/arm64/include/machdep.h 281494 2015-04-13 14:43:10Z andrew $ + */ + +#ifndef _MACHINE_BOOTCONFIG_H_ +#define _MACHINE_BOOTCONFIG_H_ + +struct arm64_bootparams { + vaddr_t modulep; + vaddr_t kern_l1pt; /* L1 page table for the kernel */ + uint64_t kern_delta; + vaddr_t kern_stack; + void *arg0; // passed to kernel in R0 + void *arg1; // passed to kernel in R1 + void *arg2; // passed to kernel in R2 +}; + +void initarm(struct arm64_bootparams *); + +#endif /* _MACHINE_BOOTCONFIG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/bus.h b/lib/libc/include/aarch64-openbsd-none/arm64/bus.h new file mode 100644 index 0000000000..70ad145593 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/bus.h @@ -0,0 +1,536 @@ +/* $OpenBSD: bus.h,v 1.11 2024/11/18 05:32:39 jsg Exp $ */ +/* + * Copyright (c) 2003-2004 Opsycon AB Sweden. 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_BUS_H_ +#define _MACHINE_BUS_H_ + +#ifdef __STDC__ +#define CAT(a,b) a##b +#define CAT3(a,b,c) a##b##c +#else +#define CAT(a,b) a/**/b +#define CAT3(a,b,c) a/**/b/**/c +#endif + +/* + * Bus access types. + */ +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; +typedef struct bus_space bus_space_t; + +struct bus_space { + bus_addr_t bus_base; + void *bus_private; + u_int8_t (*_space_read_1)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_1)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int8_t); + u_int16_t (*_space_read_2)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_2)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int16_t); + u_int32_t (*_space_read_4)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_4)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int32_t); + u_int64_t (*_space_read_8)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_8)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int64_t); + void (*_space_read_raw_2)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, u_int8_t *, bus_size_t); + void (*_space_write_raw_2)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const u_int8_t *, bus_size_t); + void (*_space_read_raw_4)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, u_int8_t *, bus_size_t); + void (*_space_write_raw_4)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const u_int8_t *, bus_size_t); + void (*_space_read_raw_8)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, u_int8_t *, bus_size_t); + void (*_space_write_raw_8)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const u_int8_t *, bus_size_t); + int (*_space_map)(bus_space_tag_t , bus_addr_t, + bus_size_t, int, bus_space_handle_t *); + void (*_space_unmap)(bus_space_tag_t, bus_space_handle_t, + bus_size_t); + int (*_space_subregion)(bus_space_tag_t, bus_space_handle_t, + bus_size_t, bus_size_t, bus_space_handle_t *); + void * (*_space_vaddr)(bus_space_tag_t, bus_space_handle_t); + paddr_t (*_space_mmap)(bus_space_tag_t, bus_addr_t, off_t, + int, int); +}; + +#define bus_space_read_1(t, h, o) (*(t)->_space_read_1)((t), (h), (o)) +#define bus_space_read_2(t, h, o) (*(t)->_space_read_2)((t), (h), (o)) +#define bus_space_read_4(t, h, o) (*(t)->_space_read_4)((t), (h), (o)) +#define bus_space_read_8(t, h, o) (*(t)->_space_read_8)((t), (h), (o)) + +#define bus_space_write_1(t, h, o, v) (*(t)->_space_write_1)((t), (h), (o), (v)) +#define bus_space_write_2(t, h, o, v) (*(t)->_space_write_2)((t), (h), (o), (v)) +#define bus_space_write_4(t, h, o, v) (*(t)->_space_write_4)((t), (h), (o), (v)) +#define bus_space_write_8(t, h, o, v) (*(t)->_space_write_8)((t), (h), (o), (v)) + +#define bus_space_read_raw_2(t, h, o) \ + (*(t)->_space_read_2)((t), (h), (o)) +#define bus_space_read_raw_4(t, h, o) \ + (*(t)->_space_read_4)((t), (h), (o)) +#define bus_space_read_raw_8(t, h, o) \ + (*(t)->_space_read_8)((t), (h), (o)) + +#define bus_space_write_raw_2(t, h, o, v) \ + (*(t)->_space_write_2)((t), (h), (o), (v)) +#define bus_space_write_raw_4(t, h, o, v) \ + (*(t)->_space_write_4)((t), (h), (o), (v)) +#define bus_space_write_raw_8(t, h, o, v) \ + (*(t)->_space_write_8)((t), (h), (o), (v)) + +#define bus_space_read_raw_multi_2(t, h, a, b, l) \ + (*(t)->_space_read_raw_2)((t), (h), (a), (b), (l)) +#define bus_space_read_raw_multi_4(t, h, a, b, l) \ + (*(t)->_space_read_raw_4)((t), (h), (a), (b), (l)) +#define bus_space_read_raw_multi_8(t, h, a, b, l) \ + (*(t)->_space_read_raw_8)((t), (h), (a), (b), (l)) + +#define bus_space_write_raw_multi_2(t, h, a, b, l) \ + (*(t)->_space_write_raw_2)((t), (h), (a), (b), (l)) +#define bus_space_write_raw_multi_4(t, h, a, b, l) \ + (*(t)->_space_write_raw_4)((t), (h), (a), (b), (l)) +#define bus_space_write_raw_multi_8(t, h, a, b, l) \ + (*(t)->_space_write_raw_8)((t), (h), (a), (b), (l)) + +#define bus_space_map(t, o, s, c, p) (*(t)->_space_map)((t), (o), (s), (c), (p)) +#define bus_space_unmap(t, h, s) (*(t)->_space_unmap)((t), (h), (s)) +#define bus_space_subregion(t, h, o, s, p) \ + (*(t)->_space_subregion)((t), (h), (o), (s), (p)) + +#define BUS_SPACE_MAP_CACHEABLE 0x01 +#define BUS_SPACE_MAP_POSTED 0x02 +#define BUS_SPACE_MAP_LINEAR 0x04 +#define BUS_SPACE_MAP_PREFETCHABLE 0x08 + +extern bus_space_t arm64_bs_tag; + +#define bus_space_vaddr(t, h) (*(t)->_space_vaddr)((t), (h)) +#define bus_space_mmap(t, a, o, p, f) \ + (*(t)->_space_mmap)((t), (a), (o), (p), (f)) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_multi(n,m) \ +static __inline void \ +CAT(bus_space_read_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_size_t o, CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) \ + *x++ = CAT(bus_space_read_,n)(bst, bsh, o); \ +} + +bus_space_read_multi(1,8) +bus_space_read_multi(2,16) +bus_space_read_multi(4,32) +bus_space_read_multi(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_region(n,m) \ +static __inline void \ +CAT(bus_space_read_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) { \ + *x++ = CAT(bus_space_read_,n)(bst, bsh, ba); \ + ba += (n); \ + } \ +} + +bus_space_read_region(1,8) +bus_space_read_region(2,16) +bus_space_read_region(4,32) +bus_space_read_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_raw_region(n,m) \ +static __inline void \ +CAT(bus_space_read_raw_region_,n)(bus_space_tag_t bst, \ + bus_space_handle_t bsh, \ + bus_addr_t ba, u_int8_t *x, size_t cnt) \ +{ \ + cnt >>= ((n) >> 1); \ + while (cnt--) { \ + CAT(bus_space_read_raw_multi_,n)(bst, bsh, ba, x, (n)); \ + ba += (n); \ + x += (n); \ + } \ +} + +bus_space_read_raw_region(2,16) +bus_space_read_raw_region(4,32) +bus_space_read_raw_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_multi(n,m) \ +static __inline void \ +CAT(bus_space_write_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_size_t o, const CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) \ + CAT(bus_space_write_,n)(bst, bsh, o, *x++); \ +} + +bus_space_write_multi(1,8) +bus_space_write_multi(2,16) +bus_space_write_multi(4,32) +bus_space_write_multi(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_region(n,m) \ +static __inline void \ +CAT(bus_space_write_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, const CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) { \ + CAT(bus_space_write_,n)(bst, bsh, ba, *x++); \ + ba += (n); \ + } \ +} + +bus_space_write_region(1,8) +bus_space_write_region(2,16) +bus_space_write_region(4,32) +bus_space_write_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_raw_region(n,m) \ +static __inline void \ +CAT(bus_space_write_raw_region_,n)(bus_space_tag_t bst, \ + bus_space_handle_t bsh, \ + bus_addr_t ba, const u_int8_t *x, size_t cnt) \ +{ \ + cnt >>= ((n) >> 1); \ + while (cnt--) { \ + CAT(bus_space_write_raw_multi_,n)(bst, bsh, ba, x, (n)); \ + ba += (n); \ + x += (n); \ + } \ +} + +bus_space_write_raw_region(2,16) +bus_space_write_raw_region(4,32) +bus_space_write_raw_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_set_region(n,m) \ +static __inline void \ +CAT(bus_space_set_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, CAT3(u_int,m,_t) x, size_t cnt) \ +{ \ + while (cnt--) { \ + CAT(bus_space_write_,n)(bst, bsh, ba, x); \ + ba += (n); \ + } \ +} + +bus_space_set_region(1,8) +bus_space_set_region(2,16) +bus_space_set_region(4,32) +bus_space_set_region(8,64) + +/*----------------------------------------------------------------------------*/ +static __inline void +bus_space_copy_1(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + char *s = (char *)(h1 + o1); + char *d = (char *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + + +static __inline void +bus_space_copy_2(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + short *s = (short *)(h1 + o1); + short *d = (short *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + +static __inline void +bus_space_copy_4(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + int *s = (int *)(h1 + o1); + int *d = (int *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + +static __inline void +bus_space_copy_8(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + int64_t *s = (int64_t *)(h1 + o1); + int64_t *d = (int64_t *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + +/*----------------------------------------------------------------------------*/ +/* + * Bus read/write barrier methods. + * + * void bus_space_barrier(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * bus_size_t len, int flags); + * + */ +static inline void +bus_space_barrier(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, + bus_size_t length, int flags) +{ + __asm__ volatile ("dsb sy" ::: "memory"); +} +#define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */ +#define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */ + +#define BUS_DMA_WAITOK 0x0000 +#define BUS_DMA_NOWAIT 0x0001 +#define BUS_DMA_ALLOCNOW 0x0002 +#define BUS_DMA_COHERENT 0x0008 +#define BUS_DMA_BUS1 0x0010 /* placeholders for bus functions... */ +#define BUS_DMA_BUS2 0x0020 +#define BUS_DMA_BUS3 0x0040 +#define BUS_DMA_BUS4 0x0080 +#define BUS_DMA_READ 0x0100 /* mapping is device -> memory only */ +#define BUS_DMA_WRITE 0x0200 /* mapping is memory -> device only */ +#define BUS_DMA_STREAMING 0x0400 /* hint: sequential, unidirectional */ +#define BUS_DMA_ZERO 0x0800 /* zero memory in dmamem_alloc */ +#define BUS_DMA_NOCACHE 0x1000 +#define BUS_DMA_64BIT 0x2000 /* device handles 64bit dva */ +#define BUS_DMA_FIXED 0x4000 /* place mapping at specified dva */ + +/* Forwards needed by prototypes below. */ +struct mbuf; +struct proc; +struct uio; + +#define BUS_DMASYNC_POSTREAD 0x0001 +#define BUS_DMASYNC_POSTWRITE 0x0002 +#define BUS_DMASYNC_PREREAD 0x0004 +#define BUS_DMASYNC_PREWRITE 0x0008 + +typedef struct machine_bus_dma_tag *bus_dma_tag_t; +typedef struct machine_bus_dmamap *bus_dmamap_t; + +/* + * bus_dma_segment_t + * + * Describes a single contiguous DMA transaction. Values + * are suitable for programming into DMA registers. + */ +struct machine_bus_dma_segment { + bus_addr_t ds_addr; /* DMA address */ + bus_size_t ds_len; /* length of transfer */ + + paddr_t _ds_paddr; /* CPU address */ + vaddr_t _ds_vaddr; /* CPU address */ +}; +typedef struct machine_bus_dma_segment bus_dma_segment_t; + +/* + * bus_dma_tag_t + * + * A machine-dependent opaque type describing the implementation of + * DMA for a given bus. + */ + +struct machine_bus_dma_tag { + void *_cookie; /* cookie used in the guts */ + int _flags; /* misc. flags */ + + /* + * DMA mapping methods. + */ + int (*_dmamap_create)(bus_dma_tag_t , bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); + void (*_dmamap_destroy)(bus_dma_tag_t , bus_dmamap_t); + int (*_dmamap_load)(bus_dma_tag_t , bus_dmamap_t, void *, + bus_size_t, struct proc *, int); + int (*_dmamap_load_mbuf)(bus_dma_tag_t , bus_dmamap_t, + struct mbuf *, int); + int (*_dmamap_load_uio)(bus_dma_tag_t , bus_dmamap_t, + struct uio *, int); + int (*_dmamap_load_raw)(bus_dma_tag_t , bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); + int (*_dmamap_load_buffer)(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int, paddr_t *, int *, int); + void (*_dmamap_unload)(bus_dma_tag_t , bus_dmamap_t); + void (*_dmamap_sync)(bus_dma_tag_t , bus_dmamap_t, + bus_addr_t, bus_size_t, int); + + /* + * DMA memory utility functions. + */ + int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); + int (*_dmamem_alloc_range)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int, + bus_addr_t, bus_addr_t); + void (*_dmamem_free)(bus_dma_tag_t, bus_dma_segment_t *, int); + int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); + void (*_dmamem_unmap)(bus_dma_tag_t, caddr_t, size_t); + paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *, + int, off_t, int, int); + + /* + * internal memory address translation information. + */ + bus_addr_t _dma_mask; +}; + +#define bus_dmamap_create(t, s, n, m, b, f, p) \ + (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p)) +#define bus_dmamap_destroy(t, p) \ + (*(t)->_dmamap_destroy)((t), (p)) +#define bus_dmamap_load(t, m, b, s, p, f) \ + (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f)) +#define bus_dmamap_load_mbuf(t, m, b, f) \ + (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f)) +#define bus_dmamap_load_uio(t, m, u, f) \ + (*(t)->_dmamap_load_uio)((t), (m), (u), (f)) +#define bus_dmamap_load_raw(t, m, sg, n, s, f) \ + (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f)) +#define bus_dmamap_unload(t, p) \ + (*(t)->_dmamap_unload)((t), (p)) +#define bus_dmamap_sync(t, p, a, l, o) \ + (void)((t)->_dmamap_sync ? \ + (*(t)->_dmamap_sync)((t), (p), (a), (l), (o)) : (void)0) + +#define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \ + (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f)) +#define bus_dmamem_alloc_range(t, s, a, b, sg, n, r, f, l, h) \ + (*(t)->_dmamem_alloc_range)((t), (s), (a), (b), (sg), \ + (n), (r), (f), (l), (h)) +#define bus_dmamem_free(t, sg, n) \ + (*(t)->_dmamem_free)((t), (sg), (n)) +#define bus_dmamem_map(t, sg, n, s, k, f) \ + (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f)) +#define bus_dmamem_unmap(t, k, s) \ + (*(t)->_dmamem_unmap)((t), (k), (s)) +#define bus_dmamem_mmap(t, sg, n, o, p, f) \ + (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f)) + +int _dmamap_create(bus_dma_tag_t, bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); +void _dmamap_destroy(bus_dma_tag_t, bus_dmamap_t); +int _dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int); +int _dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, struct mbuf *, int); +int _dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, struct uio *, int); +int _dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); +int _dmamap_load_buffer(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int, paddr_t *, int *, int); +void _dmamap_unload(bus_dma_tag_t, bus_dmamap_t); +void _dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, + bus_size_t, int); + +int _dmamem_alloc(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); +void _dmamem_free(bus_dma_tag_t, bus_dma_segment_t *, int); +int _dmamem_map(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); +void _dmamem_unmap(bus_dma_tag_t, caddr_t, size_t); +paddr_t _dmamem_mmap(bus_dma_tag_t, bus_dma_segment_t *, int, off_t, int, int); +int _dmamem_alloc_range(bus_dma_tag_t, bus_size_t, bus_size_t, bus_size_t, + bus_dma_segment_t *, int, int *, int, paddr_t, paddr_t); + +/* + * bus_dmamap_t + * + * Describes a DMA mapping. + */ +struct machine_bus_dmamap { + /* + * PRIVATE MEMBERS: not for use by machine-independent code. + */ + bus_size_t _dm_size; /* largest DMA transfer mappable */ + int _dm_segcnt; /* number of segs this map can map */ + bus_size_t _dm_maxsegsz; /* largest possible segment */ + bus_size_t _dm_boundary; /* don't cross this */ + int _dm_flags; /* misc. flags */ + + void *_dm_cookie; /* cookie for bus-specific functions */ + + /* + * PUBLIC MEMBERS: these are used by machine-independent code. + */ + bus_size_t dm_mapsize; /* size of the mapping */ + int dm_nsegs; /* # valid segments in mapping */ + bus_dma_segment_t dm_segs[1]; /* segments; variable length */ +}; + +int generic_space_map(bus_space_tag_t, bus_addr_t, bus_size_t, int, + bus_space_handle_t *); +void generic_space_unmap(bus_space_tag_t, bus_space_handle_t, bus_size_t); +int generic_space_region(bus_space_tag_t, bus_space_handle_t, bus_size_t, + bus_size_t, bus_space_handle_t *); +void *generic_space_vaddr(bus_space_tag_t, bus_space_handle_t); +paddr_t generic_space_mmap(bus_space_tag_t, bus_addr_t, off_t, int, int); +uint8_t generic_space_read_1(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint16_t generic_space_read_2(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint32_t generic_space_read_4(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint64_t generic_space_read_8(bus_space_tag_t, bus_space_handle_t, bus_size_t); +void generic_space_read_raw_2(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_1(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint8_t); +void generic_space_write_2(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint16_t); +void generic_space_write_4(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint32_t); +void generic_space_write_8(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint64_t); +void generic_space_write_raw_2(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); +void generic_space_read_raw_4(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_raw_4(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); +void generic_space_read_raw_8(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_raw_8(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); + +#endif /* _MACHINE_BUS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/cdefs.h b/lib/libc/include/aarch64-openbsd-none/arm64/cdefs.h new file mode 100644 index 0000000000..307f720db4 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/cdefs.h @@ -0,0 +1,16 @@ +/* $OpenBSD: cdefs.h,v 1.1 2016/12/17 23:38:33 patrick Exp $ */ + +#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_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/conf.h b/lib/libc/include/aarch64-openbsd-none/arm64/conf.h new file mode 100644 index 0000000000..9a9e0a1465 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/conf.h @@ -0,0 +1,61 @@ +/* $OpenBSD: conf.h,v 1.5 2024/06/12 02:50:25 jsg Exp $ */ +/* $NetBSD: conf.h,v 1.2 1996/05/05 19:28:34 christos Exp $ */ + +/* + * Copyright (c) 1996 Christos Zoulas. 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 Christos Zoulas. + * 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 _MACHINE_CONF_H_ +#define _MACHINE_CONF_H_ + +#include + +#define mmread mmrw +#define mmwrite mmrw +cdev_decl(mm); + +/* open, close, ioctl */ +#define cdev_openprom_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) nullop, 0, \ + (dev_type_mmap((*))) enodev } + +cdev_decl(openprom); + +/* open, close, write, ioctl, kqueue */ +#define cdev_acpiapm_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,n,kqfilter) } + +cdev_decl(apm); +cdev_decl(acpiapm); + +#endif /* _MACHINE_CONF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/cpu.h b/lib/libc/include/aarch64-openbsd-none/arm64/cpu.h new file mode 100644 index 0000000000..39cdc4ecd5 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/cpu.h @@ -0,0 +1,360 @@ +/* $OpenBSD: cpu.h,v 1.51 2025/02/11 22:27:09 kettenis Exp $ */ +/* + * Copyright (c) 2016 Dale Rahn + * + * 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_CPU_H_ +#define _MACHINE_CPU_H_ + +/* + * User-visible definitions + */ + +/* + * CTL_MACHDEP definitions. + */ +#define CPU_COMPATIBLE 1 /* compatible property */ +#define CPU_ID_AA64ISAR0 2 +#define CPU_ID_AA64ISAR1 3 +#define CPU_ID_AA64ISAR2 4 +#define CPU_ID_AA64MMFR0 5 +#define CPU_ID_AA64MMFR1 6 +#define CPU_ID_AA64MMFR2 7 +#define CPU_ID_AA64PFR0 8 +#define CPU_ID_AA64PFR1 9 +#define CPU_ID_AA64SMFR0 10 +#define CPU_ID_AA64ZFR0 11 +#define CPU_LIDACTION 12 +#define CPU_MAXID 13 /* number of valid machdep ids */ + +#define CTL_MACHDEP_NAMES { \ + { 0, 0 }, \ + { "compatible", CTLTYPE_STRING }, \ + { "id_aa64isar0", CTLTYPE_QUAD }, \ + { "id_aa64isar1", CTLTYPE_QUAD }, \ + { "id_aa64isar2", CTLTYPE_QUAD }, \ + { "id_aa64mmfr0", CTLTYPE_QUAD }, \ + { "id_aa64mmfr1", CTLTYPE_QUAD }, \ + { "id_aa64mmfr2", CTLTYPE_QUAD }, \ + { "id_aa64pfr0", CTLTYPE_QUAD }, \ + { "id_aa64pfr1", CTLTYPE_QUAD }, \ + { "id_aa64smfr0", CTLTYPE_QUAD }, \ + { "id_aa64zfr0", CTLTYPE_QUAD }, \ + { "lidaction", CTLTYPE_INT }, \ +} + +#ifdef _KERNEL + +/* + * Kernel-only definitions + */ + +extern uint64_t cpu_id_aa64isar0; +extern uint64_t cpu_id_aa64isar1; +extern uint64_t cpu_id_aa64isar2; +extern uint64_t cpu_id_aa64mmfr0; +extern uint64_t cpu_id_aa64mmfr1; +extern uint64_t cpu_id_aa64mmfr2; +extern uint64_t cpu_id_aa64pfr0; +extern uint64_t cpu_id_aa64pfr1; +extern uint64_t cpu_id_aa64zfr0; + +void cpu_identify_cleanup(void); + +#include +#include +#include + +/* All the CLKF_* macros take a struct clockframe * as an argument. */ + +#define clockframe trapframe +/* + * CLKF_USERMODE: Return TRUE/FALSE (1/0) depending on whether the + * frame came from USR mode or not. + */ +#define CLKF_USERMODE(frame) ((frame->tf_elr & (1ul << 63)) == 0) + +/* + * CLKF_INTR: True if we took the interrupt from inside another + * interrupt handler. + */ +#define CLKF_INTR(frame) (curcpu()->ci_idepth > 1) + +/* + * CLKF_PC: Extract the program counter from a clockframe + */ +#define CLKF_PC(frame) (frame->tf_elr) + +/* + * PROC_PC: Find out the program counter for the given process. + */ +#define PROC_PC(p) ((p)->p_addr->u_pcb.pcb_tf->tf_elr) +#define PROC_STACK(p) ((p)->p_addr->u_pcb.pcb_tf->tf_sp) + +/* + * Per-CPU information. For now we assume one CPU. + */ + +#include +#include +#include +#include +#include + +struct cpu_info { + struct device *ci_dev; /* Device corresponding to this CPU */ + struct cpu_info *ci_next; + struct schedstate_percpu ci_schedstate; /* scheduler state */ + + u_int32_t ci_cpuid; + uint64_t ci_mpidr; + uint64_t ci_midr; + u_int ci_acpi_proc_id; + int ci_node; + struct cpu_info *ci_self; + +#define __HAVE_CPU_TOPOLOGY + u_int32_t ci_smt_id; + u_int32_t ci_core_id; + u_int32_t ci_pkg_id; + + struct proc *ci_curproc; + struct pcb *ci_curpcb; + struct pmap *ci_curpm; + u_int32_t ci_randseed; + + u_int32_t ci_ctrl; /* The CPU control register */ + + u_int64_t ci_trampoline_vectors; + + uint32_t ci_cpl; + uint32_t ci_ipending; + uint32_t ci_idepth; +#ifdef DIAGNOSTIC + int ci_mutex_level; +#endif + int ci_want_resched; + + void (*ci_flush_bp)(void); + void (*ci_serror)(void); + + uint64_t ci_ttbr1; + vaddr_t ci_el1_stkend; + + uint32_t ci_psci_idle_latency; + uint32_t ci_psci_idle_param; + uint32_t ci_psci_suspend_param; + + struct opp_table *ci_opp_table; + volatile int ci_opp_idx; + volatile int ci_opp_max; + uint32_t ci_cpu_supply; + + u_long ci_prev_sleep; + u_long ci_last_itime; + +#ifdef MULTIPROCESSOR + struct srp_hazard ci_srp_hazards[SRP_HAZARD_NUM]; +#define __HAVE_UVM_PERCPU + struct uvm_pmr_cache ci_uvm; + volatile int ci_flags; + + volatile int ci_ddb_paused; +#define CI_DDB_RUNNING 0 +#define CI_DDB_SHOULDSTOP 1 +#define CI_DDB_STOPPED 2 +#define CI_DDB_ENTERDDB 3 +#define CI_DDB_INDDB 4 + +#endif + +#ifdef GPROF + struct gmonparam *ci_gmon; + struct clockintr ci_gmonclock; +#endif + struct clockqueue ci_queue; + char ci_panicbuf[512]; +}; + +#define CPUF_PRIMARY (1<<0) +#define CPUF_AP (1<<1) +#define CPUF_IDENTIFY (1<<2) +#define CPUF_IDENTIFIED (1<<3) +#define CPUF_PRESENT (1<<4) +#define CPUF_GO (1<<5) +#define CPUF_RUNNING (1<<6) + +static inline struct cpu_info * +curcpu(void) +{ + struct cpu_info *__ci = NULL; + __asm volatile("mrs %0, tpidr_el1" : "=r" (__ci)); + return (__ci); +} + +extern struct cpu_info cpu_info_primary; +extern struct cpu_info *cpu_info_list; + +#ifndef MULTIPROCESSOR +#define cpu_number() 0 +#define CPU_IS_PRIMARY(ci) 1 +#define CPU_IS_RUNNING(ci) 1 +#define CPU_INFO_ITERATOR int +#define CPU_INFO_FOREACH(cii, ci) \ + for (cii = 0, ci = curcpu(); ci != NULL; ci = NULL) +#define CPU_INFO_UNIT(ci) 0 +#define MAXCPUS 1 +#define cpu_unidle(ci) +#else +#define cpu_number() (curcpu()->ci_cpuid) +#define CPU_IS_PRIMARY(ci) ((ci) == &cpu_info_primary) +#define CPU_IS_RUNNING(ci) ((ci)->ci_flags & CPUF_RUNNING) +#define CPU_INFO_ITERATOR int +#define CPU_INFO_FOREACH(cii, ci) for (cii = 0, ci = cpu_info_list; \ + ci != NULL; ci = ci->ci_next) +#define CPU_INFO_UNIT(ci) ((ci)->ci_dev ? (ci)->ci_dev->dv_unit : 0) +#define MAXCPUS 256 + +extern struct cpu_info *cpu_info[MAXCPUS]; + +void cpu_boot_secondary_processors(void); +#endif /* !MULTIPROCESSOR */ + +#define CPU_BUSY_CYCLE() __asm volatile("yield" : : : "memory") + +#define curpcb curcpu()->ci_curpcb + +static inline unsigned int +cpu_rnd_messybits(void) +{ + uint64_t val, rval; + + __asm volatile("mrs %0, CNTVCT_EL0; rbit %1, %0;" + : "=r" (val), "=r" (rval)); + + return (val ^ rval); +} + +/* + * Scheduling glue + */ +#define aston(p) ((p)->p_md.md_astpending = 1) +#define setsoftast() aston(curcpu()->ci_curproc) + +/* + * Notify the current process (p) that it has a signal pending, + * process as soon as possible. + */ + +#ifdef MULTIPROCESSOR +void cpu_unidle(struct cpu_info *ci); +#define signotify(p) (aston(p), cpu_unidle((p)->p_cpu)) +void cpu_kick(struct cpu_info *); +#else +#define cpu_kick(ci) +#define cpu_unidle(ci) +#define signotify(p) setsoftast() +#endif + +/* + * Preempt the current process if in interrupt from user mode, + * or after the current trap/syscall if in system mode. + */ +void need_resched(struct cpu_info *); +#define clear_resched(ci) ((ci)->ci_want_resched = 0) + +/* + * Give a profiling tick to the current process when the user profiling + * buffer pages are invalid. On the i386, request an ast to send us + * through trap(), marking the proc as needing a profiling tick. + */ +#define need_proftick(p) aston(p) + +// asm code to start new kernel contexts. +void proc_trampoline(void); + +/* + * Random cruft + */ +void dumpconf(void); + +// syscall.c +void svc_handler (trapframe_t *); + +// functions to manipulate interrupt state +static __inline void +restore_daif(uint32_t daif) +{ + __asm volatile ("msr daif, %x0":: "r"(daif)); +} + +static __inline void +enable_irq_daif(void) +{ + __asm volatile ("msr daifclr, #3"); +} + +static __inline void +disable_irq_daif(void) +{ + __asm volatile ("msr daifset, #3"); +} + +static __inline uint32_t +disable_irq_daif_ret(void) +{ + uint32_t daif; + __asm volatile ("mrs %x0, daif": "=r"(daif)); + __asm volatile ("msr daifset, #3"); + return daif; +} + +static inline void +intr_enable(void) +{ + enable_irq_daif(); +} + +static inline u_long +intr_disable(void) +{ + return disable_irq_daif_ret(); +} + +static inline void +intr_restore(u_long daif) +{ + restore_daif(daif); +} + +void cpu_halt(void); +int cpu_suspend_primary(void); +void cpu_resume_secondary(struct cpu_info *); + +extern void (*cpu_idle_cycle_fcn)(void); +extern void (*cpu_suspend_cycle_fcn)(void); + +void cpu_wfi(void); + +void delay (unsigned); +#define DELAY(x) delay(x) + +#endif /* _KERNEL */ + +#ifdef MULTIPROCESSOR +#include +#endif /* MULTIPROCESSOR */ + +#endif /* !_MACHINE_CPU_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/cpufunc.h b/lib/libc/include/aarch64-openbsd-none/arm64/cpufunc.h new file mode 100644 index 0000000000..df2a91afc3 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/cpufunc.h @@ -0,0 +1,56 @@ +/* $OpenBSD: cpufunc.h,v 1.4 2018/05/02 15:17:30 patrick Exp $ */ +/*- + * Copyright (c) 2014 Andrew Turner + * 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 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 AUTHOR 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. + * + * $FreeBSD: head/sys/cpu/include/cpufunc.h 299683 2016-05-13 16:03:50Z andrew $ + */ + +#ifndef _MACHINE_CPUFUNC_H_ +#define _MACHINE_CPUFUNC_H_ + +#ifdef _KERNEL + +#include + +extern int64_t dcache_line_size; +extern int64_t icache_line_size; +extern int64_t idcache_line_size; +extern int64_t dczva_line_size; + +void cpu_setttb(int, paddr_t); +void cpu_tlb_flush(void); +void cpu_tlb_flush_asid(vaddr_t); +void cpu_tlb_flush_all_asid(vaddr_t); +void cpu_tlb_flush_asid_all(vaddr_t); +void cpu_icache_sync_range(vaddr_t, vsize_t); +void cpu_idcache_wbinv_range(vaddr_t, vsize_t); +void cpu_dcache_wbinv_range(vaddr_t, vsize_t); +void cpu_dcache_inv_range(vaddr_t, vsize_t); +void cpu_dcache_wb_range(vaddr_t, vsize_t); + +register_t smc_call(register_t, register_t, register_t, register_t); + +#endif /* _KERNEL */ +#endif /* _MACHINE_CPUFUNC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/db_machdep.h b/lib/libc/include/aarch64-openbsd-none/arm64/db_machdep.h new file mode 100644 index 0000000000..d930085c2d --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/db_machdep.h @@ -0,0 +1,80 @@ +/* $OpenBSD: db_machdep.h,v 1.8 2025/07/22 09:20:41 kettenis Exp $ */ +/* $NetBSD: db_machdep.h,v 1.5 2001/11/22 18:00:00 thorpej Exp $ */ + +/* + * Copyright (c) 1996 Scott K Stevens + * + * Mach Operating System + * Copyright (c) 1991,1990 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +#ifndef _MACHINE_DB_MACHDEP_H_ +#define _MACHINE_DB_MACHDEP_H_ + +/* + * Machine-dependent defines for new kernel debugger. + */ + +#include +#include +#include +#include + +/* end of mangling */ + +typedef long db_expr_t; /* expression - signed */ + +typedef trapframe_t db_regs_t; + +extern db_regs_t ddb_regs; /* register state */ +#define DDB_REGS (&ddb_regs) + +#define PC_REGS(regs) ((vaddr_t)(regs)->tf_elr) +#define SET_PC_REGS(regs, value) (regs)->tf_elr = (register_t)(value) + +#define BKPT_INST 0xd4200000 /* breakpoint instruction */ +#define BKPT_SIZE (INSN_SIZE) /* size of breakpoint inst */ +#define BKPT_SET(inst) (BKPT_INST) + +#define db_clear_single_step(regs) ((regs)->tf_spsr &= ~PSR_SS) +#define db_set_single_step(regs) ((regs)->tf_spsr |= PSR_SS) + +#define IS_BREAKPOINT_TRAP(type, code) ((type) == EXCP_BRK) +#define IS_WATCHPOINT_TRAP(type, code) ((type) == EXCP_WATCHPT_EL1) + +// 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 DB_MACHINE_COMMANDS + +int db_ktrap(int, db_regs_t *); +void db_machine_init (void); + +#define DDB_STATE_NOT_RUNNING 0 +#define DDB_STATE_RUNNING 1 +#define DDB_STATE_EXITING 2 + +#endif /* _MACHINE_DB_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/disklabel.h b/lib/libc/include/aarch64-openbsd-none/arm64/disklabel.h new file mode 100644 index 0000000000..6427b26604 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/disklabel.h @@ -0,0 +1,25 @@ +/* $OpenBSD: disklabel.h,v 1.1 2016/12/17 23:38:33 patrick Exp $ */ +/* + * Copyright (c) 2014 Patrick Wildt + * + * 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_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/efivar.h b/lib/libc/include/aarch64-openbsd-none/arm64/efivar.h new file mode 100644 index 0000000000..659349b12b --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/efivar.h @@ -0,0 +1,46 @@ +/* $OpenBSD: efivar.h,v 1.2 2024/07/10 10:53:55 kettenis Exp $ */ +/* + * Copyright (c) 2022 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_EFIVAR_H_ +#define _MACHINE_EFIVAR_H_ + +#include + +struct efi_softc { + struct device sc_dev; + struct pmap *sc_pm; + EFI_RUNTIME_SERVICES *sc_rs; + EFI_SYSTEM_RESOURCE_TABLE *sc_esrt; + u_long sc_psw; + + struct todr_chip_handle sc_todr; +}; + + +extern EFI_GET_VARIABLE efi_get_variable; +extern EFI_SET_VARIABLE efi_set_variable; +extern EFI_GET_NEXT_VARIABLE_NAME efi_get_next_variable_name; + +void efi_enter(struct efi_softc *); +void efi_leave(struct efi_softc *); + +extern label_t efi_jmpbuf; + +#define efi_enter_check(sc) (setjmp(&efi_jmpbuf) ? \ + (efi_leave(sc), EFAULT) : (efi_enter(sc), 0)) + +#endif /* _MACHINE_EFIVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/elf.h b/lib/libc/include/aarch64-openbsd-none/arm64/elf.h new file mode 100644 index 0000000000..7af1436a51 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/elf.h @@ -0,0 +1,121 @@ +/*- + * Copyright (c) 1996-1997 John D. Polstra. + * 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 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 AUTHOR 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_ELF_H_ +#define _MACHINE_ELF_H_ + +/* + * ELF definitions for the AArch64 architecture. + */ + +#ifdef _KERNEL +# define __HAVE_CPU_HWCAP +# define __HAVE_CPU_HWCAP2 +extern unsigned long hwcap, hwcap2; +#endif /* _KERNEL */ + +/* HWCAP */ +#define HWCAP_FP 0x00000001 +#define HWCAP_ASIMD 0x00000002 +#define HWCAP_EVTSTRM 0x00000004 +#define HWCAP_AES 0x00000008 +#define HWCAP_PMULL 0x00000010 +#define HWCAP_SHA1 0x00000020 +#define HWCAP_SHA2 0x00000040 +#define HWCAP_CRC32 0x00000080 +#define HWCAP_ATOMICS 0x00000100 +#define HWCAP_FPHP 0x00000200 +#define HWCAP_ASIMDHP 0x00000400 +#define HWCAP_CPUID 0x00000800 +#define HWCAP_ASIMDRDM 0x00001000 +#define HWCAP_JSCVT 0x00002000 +#define HWCAP_FCMA 0x00004000 +#define HWCAP_LRCPC 0x00008000 +#define HWCAP_DCPOP 0x00010000 +#define HWCAP_SHA3 0x00020000 +#define HWCAP_SM3 0x00040000 +#define HWCAP_SM4 0x00080000 +#define HWCAP_ASIMDDP 0x00100000 +#define HWCAP_SHA512 0x00200000 +#define HWCAP_SVE 0x00400000 +#define HWCAP_ASIMDFHM 0x00800000 +#define HWCAP_DIT 0x01000000 +#define HWCAP_USCAT 0x02000000 +#define HWCAP_ILRCPC 0x04000000 +#define HWCAP_FLAGM 0x08000000 +#define HWCAP_SSBS 0x10000000 +#define HWCAP_SB 0x20000000 +#define HWCAP_PACA 0x40000000 +#define HWCAP_PACG 0x80000000 + +/* HWCAP2 */ +#define HWCAP2_DCPODP 0x0000000000000001ul +#define HWCAP2_SVE2 0x0000000000000002ul +#define HWCAP2_SVEAES 0x0000000000000004ul +#define HWCAP2_SVEPMULL 0x0000000000000008ul +#define HWCAP2_SVEBITPERM 0x0000000000000010ul +#define HWCAP2_SVESHA3 0x0000000000000020ul +#define HWCAP2_SVESM4 0x0000000000000040ul +#define HWCAP2_FLAGM2 0x0000000000000080ul +#define HWCAP2_FRINT 0x0000000000000100ul +#define HWCAP2_SVEI8MM 0x0000000000000200ul +#define HWCAP2_SVEF32MM 0x0000000000000400ul +#define HWCAP2_SVEF64MM 0x0000000000000800ul +#define HWCAP2_SVEBF16 0x0000000000001000ul +#define HWCAP2_I8MM 0x0000000000002000ul +#define HWCAP2_BF16 0x0000000000004000ul +#define HWCAP2_DGH 0x0000000000008000ul +#define HWCAP2_RNG 0x0000000000010000ul +#define HWCAP2_BTI 0x0000000000020000ul +#define HWCAP2_MTE 0x0000000000040000ul +#define HWCAP2_ECV 0x0000000000080000ul +#define HWCAP2_AFP 0x0000000000100000ul +#define HWCAP2_RPRES 0x0000000000200000ul +#define HWCAP2_MTE3 0x0000000000400000ul +#define HWCAP2_SME 0x0000000000800000ul +#define HWCAP2_SME_I16I64 0x0000000001000000ul +#define HWCAP2_SME_F64F64 0x0000000002000000ul +#define HWCAP2_SME_I8I32 0x0000000004000000ul +#define HWCAP2_SME_F16F32 0x0000000008000000ul +#define HWCAP2_SME_B16F32 0x0000000010000000ul +#define HWCAP2_SME_F32F32 0x0000000020000000ul +#define HWCAP2_SME_FA64 0x0000000040000000ul +#define HWCAP2_WFXT 0x0000000080000000ul +#define HWCAP2_EBF16 0x0000000100000000ul +#define HWCAP2_SVE_EBF16 0x0000000200000000ul +#define HWCAP2_CSSC 0x0000000400000000ul +#define HWCAP2_RPRFM 0x0000000800000000ul +#define HWCAP2_SVE2P1 0x0000001000000000ul +#define HWCAP2_SME2 0x0000002000000000ul +#define HWCAP2_SME2P1 0x0000004000000000ul +#define HWCAP2_SME_I16I32 0x0000008000000000ul +#define HWCAP2_SME_BI32I32 0x0000010000000000ul +#define HWCAP2_SME_B16B16 0x0000020000000000ul +#define HWCAP2_SME_F16F16 0x0000040000000000ul +#define HWCAP2_MOPS 0x0000080000000000ul +#define HWCAP2_HBC 0x0000100000000000ul + +#endif /* !_MACHINE_ELF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/endian.h b/lib/libc/include/aarch64-openbsd-none/arm64/endian.h new file mode 100644 index 0000000000..1de95e0c62 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/endian.h @@ -0,0 +1,29 @@ +/* $OpenBSD: endian.h,v 1.4 2024/05/07 14:26:48 naddy Exp $ */ + +/* + * Copyright (c) 2015 David Gwynne + * + * 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_ENDIAN_H_ +#define _MACHINE_ENDIAN_H_ + +#define _BYTE_ORDER _LITTLE_ENDIAN +#define __STRICT_ALIGNMENT + +#ifndef __FROM_SYS__ENDIAN +#include +#endif + +#endif /* _MACHINE_ENDIAN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/exec.h b/lib/libc/include/aarch64-openbsd-none/arm64/exec.h new file mode 100644 index 0000000000..61fcd9797a --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/exec.h @@ -0,0 +1,33 @@ +/* $OpenBSD: exec.h,v 1.3 2025/07/31 16:09:59 kettenis Exp $ */ +/* + * Copyright (c) 2014 Patrick Wildt + * + * 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 + +#ifdef _KERNEL +#define __HAVE_COREDUMP_NOTE_ELF_MD +#endif + +#endif \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/fdt.h b/lib/libc/include/aarch64-openbsd-none/arm64/fdt.h new file mode 100644 index 0000000000..3ea355d9ad --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/fdt.h @@ -0,0 +1,59 @@ +/* $OpenBSD: fdt.h,v 1.7 2020/07/14 15:34:14 patrick Exp $ */ +/* + * Copyright (c) 2016 Patrick Wildt + * + * 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 __ARM_FDT_H__ +#define __ARM_FDT_H__ + +#define _ARM32_BUS_DMA_PRIVATE +#include + +struct fdt_attach_args { + const char *fa_name; + int fa_node; + bus_space_tag_t fa_iot; + bus_dma_tag_t fa_dmat; + struct fdt_reg *fa_reg; + int fa_nreg; + uint32_t *fa_intr; + int fa_nintr; + int fa_acells; + int fa_scells; +}; + +extern int stdout_node; +extern int stdout_speed; +extern bus_space_tag_t fdt_cons_bs_tag; + +void *fdt_find_cons(const char *); + +#define fdt_intr_enable arm_intr_enable +#define fdt_intr_establish arm_intr_establish_fdt +#define fdt_intr_establish_cpu arm_intr_establish_fdt_cpu +#define fdt_intr_establish_idx arm_intr_establish_fdt_idx +#define fdt_intr_establish_idx_cpu arm_intr_establish_fdt_idx_cpu +#define fdt_intr_establish_imap arm_intr_establish_fdt_imap +#define fdt_intr_establish_imap_cpu arm_intr_establish_fdt_imap_cpu +#define fdt_intr_establish_msi arm_intr_establish_fdt_msi +#define fdt_intr_establish_msi_cpu arm_intr_establish_fdt_msi_cpu +#define fdt_intr_disable arm_intr_disable +#define fdt_intr_disestablish arm_intr_disestablish_fdt +#define fdt_intr_get_parent arm_intr_get_parent +#define fdt_intr_parent_establish arm_intr_parent_establish_fdt +#define fdt_intr_parent_disestablish arm_intr_parent_disestablish_fdt +#define fdt_intr_register arm_intr_register_fdt + +#endif /* __ARM_FDT_H__ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/fenv.h b/lib/libc/include/aarch64-openbsd-none/arm64/fenv.h new file mode 100644 index 0000000000..db0eb47817 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/fenv.h @@ -0,0 +1,95 @@ +/* $OpenBSD: fenv.h,v 1.3 2019/03/12 22:14:50 patrick Exp $ */ + +/* + * Copyright (c) 2011 Martynas Venckus + * + * 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_FENV_H_ +#define _MACHINE_FENV_H_ + +/* + * Each symbol representing a floating point exception expands to an integer + * constant expression with values, such that bitwise-inclusive ORs of _all + * combinations_ of the constants result in distinct values. + * + * We use such values that allow direct bitwise operations on FPU registers. + */ +#define FE_INVALID 0x01 +#define FE_DIVBYZERO 0x02 +#define FE_OVERFLOW 0x04 +#define FE_UNDERFLOW 0x08 +#define FE_INEXACT 0x10 +#define FE_DENORMAL 0x80 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * exception constants defined above. + */ +#define FE_ALL_EXCEPT (FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | \ + FE_UNDERFLOW | FE_INEXACT | FE_DENORMAL) + +/* + * Each symbol representing the rounding direction, expands to an integer + * constant expression whose value is distinct non-negative value. + * + * We use such values that allow direct bitwise operations on FPU registers. + */ +#define FE_TONEAREST 0x0 +#define FE_UPWARD 0x1 +#define FE_DOWNWARD 0x2 +#define FE_TOWARDZERO 0x3 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * rounding direction constants defined above. + */ +#define _ROUND_MASK (FE_TONEAREST | FE_UPWARD | FE_DOWNWARD | \ + FE_TOWARDZERO) +#define _ROUND_SHIFT 22 + +/* + * fenv_t represents the entire floating-point environment. + */ +typedef unsigned long long fenv_t; + +/* + * The following constant represents the default floating-point environment + * (that is, the one installed at program startup) and has type pointer to + * const-qualified fenv_t. + * + * It can be used as an argument to the functions within the header + * that manage the floating-point environment, namely fesetenv() and + * feupdateenv(). + */ +__BEGIN_DECLS +extern fenv_t __fe_dfl_env; +__END_DECLS +#define FE_DFL_ENV ((const fenv_t *)&__fe_dfl_env) + +/* + * fexcept_t represents the floating-point status flags collectively, including + * any status the implementation associates with the flags. + * + * A floating-point status flag is a system variable whose value is set (but + * never cleared) when a floating-point exception is raised, which occurs as a + * side effect of exceptional floating-point arithmetic to provide auxiliary + * information. + * + * A floating-point control mode is a system variable whose value may be set by + * the user to affect the subsequent behavior of floating-point arithmetic. + */ +typedef unsigned long long fexcept_t; + +#endif /* !_MACHINE_FENV_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/fpu.h b/lib/libc/include/aarch64-openbsd-none/arm64/fpu.h new file mode 100644 index 0000000000..1c1afec45a --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/fpu.h @@ -0,0 +1,29 @@ +/* $OpenBSD: fpu.h,v 1.2 2025/02/11 22:27:09 kettenis Exp $ */ +/* + * Copyright (c) 2022 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_FPU_H +#define _MACHINE_FPU_H + +void fpu_save(struct proc *); +void fpu_load(struct proc *); +void sve_load(struct proc *); +void fpu_drop(void); + +void fpu_kernel_enter(void); +void fpu_kernel_exit(void); + +#endif /* !_MACHINE_FPU_H */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/frame.h b/lib/libc/include/aarch64-openbsd-none/arm64/frame.h new file mode 100644 index 0000000000..a169a9a1b9 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/frame.h @@ -0,0 +1,77 @@ +/* $OpenBSD: frame.h,v 1.3 2018/06/30 15:23:37 deraadt Exp $ */ +/* + * Copyright (c) 2016 Dale Rahn + * + * 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_FRAME_H_ +#define _MACHINE_FRAME_H_ + +#ifndef _LOCORE + +#include + + +/* + * Exception/Trap Stack Frame + */ +#define clockframe trapframe +typedef struct trapframe { + register_t tf_sp; + register_t tf_lr; + register_t tf_elr; + register_t tf_spsr; + register_t tf_x[30]; +} trapframe_t; + +/* + * pushed on stack for signal delivery + */ +struct sigframe { + int sf_signum; + struct sigcontext sf_sc; + siginfo_t sf_si; +}; + +/* + * System stack frames. + */ + +/* + * Stack frame inside cpu_switch() + */ + +struct switchframe { + register_t sf_x19; + register_t sf_x20; + register_t sf_x21; + register_t sf_x22; + register_t sf_x23; + register_t sf_x24; + register_t sf_x25; + register_t sf_x26; + register_t sf_x27; + register_t sf_x28; + register_t sf_x29; + register_t sf_lr; +}; + +struct callframe { + struct callframe *f_frame; + register_t f_lr; +}; + +#endif /* !_LOCORE */ + +#endif /* _MACHINE_FRAME_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/hypervisor.h b/lib/libc/include/aarch64-openbsd-none/arm64/hypervisor.h new file mode 100644 index 0000000000..71dce49532 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/hypervisor.h @@ -0,0 +1,88 @@ +/* $OpenBSD: hypervisor.h,v 1.5 2025/02/11 22:27:09 kettenis Exp $ */ +/*- + * Copyright (c) 2013, 2014 Andrew Turner + * 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 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 AUTHOR 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. + * + * $FreeBSD: head/sys/arm64/include/hypervisor.h 281494 2015-04-13 14:43:10Z andrew $ + */ + +#ifndef _MACHINE_HYPERVISOR_H_ +#define _MACHINE_HYPERVISOR_H_ + +/* + * These registers are only useful when in hypervisor context, + * e.g. specific to EL2, or controlling the hypervisor. + */ + +/* + * Architecture feature trap register + */ +#define CPTR_RES0 0x7fefc800 +#define CPTR_RES1 0x000032ff +#define CPTR_TFP 0x00000400 +#define CPTR_TTA 0x00100000 +#define CPTR_TCPAC 0x80000000 + +/* + * Hypervisor Config Register + */ + +#define HCR_VM 0x0000000000000001 +#define HCR_SWIO 0x0000000000000002 +#define HCR_PTW 0x0000000000000004 +#define HCR_FMO 0x0000000000000008 +#define HCR_IMO 0x0000000000000010 +#define HCR_AMO 0x0000000000000020 +#define HCR_VF 0x0000000000000040 +#define HCR_VI 0x0000000000000080 +#define HCR_VSE 0x0000000000000100 +#define HCR_FB 0x0000000000000200 +#define HCR_BSU_MASK 0x0000000000000c00 +#define HCR_DC 0x0000000000001000 +#define HCR_TWI 0x0000000000002000 +#define HCR_TWE 0x0000000000004000 +#define HCR_TID0 0x0000000000008000 +#define HCR_TID1 0x0000000000010000 +#define HCR_TID2 0x0000000000020000 +#define HCR_TID3 0x0000000000040000 +#define HCR_TSC 0x0000000000080000 +#define HCR_TIDCP 0x0000000000100000 +#define HCR_TACR 0x0000000000200000 +#define HCR_TSW 0x0000000000400000 +#define HCR_TPC 0x0000000000800000 +#define HCR_TPU 0x0000000001000000 +#define HCR_TTLB 0x0000000002000000 +#define HCR_TVM 0x0000000004000000 +#define HCR_TGE 0x0000000008000000 +#define HCR_TDZ 0x0000000010000000 +#define HCR_HCD 0x0000000020000000 +#define HCR_TRVM 0x0000000040000000 +#define HCR_RW 0x0000000080000000 +#define HCR_CD 0x0000000100000000 +#define HCR_ID 0x0000000200000000 +#define HCR_E2H 0x0000000400000000 +#define HCR_APK 0x0000010000000000 +#define HCR_API 0x0000020000000000 + +#endif \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/ieee.h b/lib/libc/include/aarch64-openbsd-none/arm64/ieee.h new file mode 100644 index 0000000000..d5f061fd54 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/ieee.h @@ -0,0 +1,148 @@ +/* $OpenBSD: ieee.h,v 1.3 2017/04/16 16:14:37 kettenis Exp $ */ +/* $NetBSD: ieee.h,v 1.1 1996/09/30 16:34:25 ws Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)ieee.h 8.1 (Berkeley) 6/11/93 + */ + +/* + * ieee.h defines the machine-dependent layout of the machine's IEEE + * floating point. It does *not* define (yet?) any of the rounding + * mode bits, exceptions, and so forth. + */ + +/* + * Define the number of bits in each fraction and exponent. + * + * k k+1 + * Note that 1.0 x 2 == 0.1 x 2 and that denorms are represented + * + * (-exp_bias+1) + * as fractions that look like 0.fffff x 2 . This means that + * + * -126 + * the number 0.10000 x 2 , for instance, is the same as the normalized + * + * -127 -128 + * float 1.0 x 2 . Thus, to represent 2 , we need one leading zero + * + * -129 + * in the fraction; to represent 2 , we need two, and so on. This + * + * (-exp_bias-fracbits+1) + * implies that the smallest denormalized number is 2 + * + * for whichever format we are talking about: for single precision, for + * + * -126 -149 + * instance, we get .00000000000000000000001 x 2 , or 1.0 x 2 , and + * + * -149 == -127 - 23 + 1. + */ +#define SNG_EXPBITS 8 +#define SNG_FRACBITS 23 + +#define DBL_EXPBITS 11 +#define DBL_FRACHBITS 20 +#define DBL_FRACLBITS 32 +#define DBL_FRACBITS 52 + +#define EXT_EXPBITS 15 +#define EXT_FRACHBITS 16 +#define EXT_FRACHMBITS 32 +#define EXT_FRACLMBITS 32 +#define EXT_FRACLBITS 32 +#define EXT_FRACBITS 112 + +#define EXT_IMPLICIT_NBIT + +#define EXT_TO_ARRAY32(p, a) do { \ + (a)[0] = (uint32_t)(p)->ext_fracl; \ + (a)[1] = (uint32_t)(p)->ext_fraclm; \ + (a)[2] = (uint32_t)(p)->ext_frachm; \ + (a)[3] = (uint32_t)(p)->ext_frach; \ +} while(0) + +struct ieee_single { + u_int sng_frac:23; + u_int sng_exp:8; + u_int sng_sign:1; +}; + +struct ieee_double { + u_int dbl_fracl; + u_int dbl_frach:20; + u_int dbl_exp:11; + u_int dbl_sign:1; +}; + +struct ieee_ext { + u_int ext_fracl; + u_int ext_fraclm; + u_int ext_frachm; + u_int ext_frach:16; + u_int ext_exp:15; + u_int ext_sign:1; +}; + +/* + * Floats whose exponent is in [1..INFNAN) (of whatever type) are + * `normal'. Floats whose exponent is INFNAN are either Inf or NaN. + * Floats whose exponent is zero are either zero (iff all fraction + * bits are zero) or subnormal values. + * + * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its + * high fraction; if the bit is set, it is a `quiet NaN'. + */ +#define SNG_EXP_INFNAN 255 +#define DBL_EXP_INFNAN 2047 +#define EXT_EXP_INFNAN 32767 + +#if 0 +#define SNG_QUIETNAN (1 << 22) +#define DBL_QUIETNAN (1 << 19) +#define EXT_QUIETNAN (1 << 15) +#endif + +/* + * Exponent biases. + */ +#define SNG_EXP_BIAS 127 +#define DBL_EXP_BIAS 1023 +#define EXT_EXP_BIAS 16383 \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/ieeefp.h b/lib/libc/include/aarch64-openbsd-none/arm64/ieeefp.h new file mode 100644 index 0000000000..b2c302da9a --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/ieeefp.h @@ -0,0 +1,25 @@ +/* $OpenBSD: ieeefp.h,v 1.2 2021/05/01 20:07:01 kettenis Exp $ */ + +/* + * Based on ieeefp.h written by J.T. Conklin, Apr 28, 1995 + * Public domain. + */ + +#ifndef _MACHINE_IEEEFP_H_ +#define _MACHINE_IEEEFP_H_ + +typedef int fp_except; +#define FP_X_INV 0x01 /* invalid operation exception */ +#define FP_X_DZ 0x02 /* divide-by-zero exception */ +#define FP_X_OFL 0x04 /* overflow exception */ +#define FP_X_UFL 0x08 /* underflow exception */ +#define FP_X_IMP 0x10 /* imprecise (loss of precision) */ + +typedef enum { + FP_RN=0, /* round to nearest representable number */ + FP_RP=1, /* round toward positive infinity */ + FP_RM=2, /* round toward negative infinity */ + FP_RZ=3 /* round to zero (truncate) */ +} fp_rnd; + +#endif /* _MACHINE_IEEEFP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/intr.h b/lib/libc/include/aarch64-openbsd-none/arm64/intr.h new file mode 100644 index 0000000000..8dbf0d06f8 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/intr.h @@ -0,0 +1,226 @@ +/* $OpenBSD: intr.h,v 1.25 2025/06/30 14:19:20 kettenis Exp $ */ + +/* + * Copyright (c) 2001-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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_INTR_H_ +#define _MACHINE_INTR_H_ + +/* + * The interrupt level ipl is a logical level; per-platform interrupt + * code will turn it into the appropriate hardware interrupt masks + * values. + * + * Interrupt sources on the CPU are kept enabled regardless of the + * current ipl value; individual hardware sources interrupting while + * logically masked are masked on the fly, remembered as pending, and + * unmasked at the first splx() opportunity. + */ +#ifdef _KERNEL + +/* Interrupt priority `levels'; not mutually exclusive. */ +#define IPL_NONE 0 /* nothing */ +#define IPL_SOFTCLOCK 2 /* soft clock interrupts */ +#define IPL_SOFTNET 3 /* soft network interrupts */ +#define IPL_SOFTTTY 4 /* soft terminal interrupts */ +#define IPL_BIO 5 /* block I/O */ +#define IPL_NET 6 /* network */ +#define IPL_TTY 7 /* terminal */ +#define IPL_VM 8 /* memory allocation */ +#define IPL_AUDIO 9 /* audio */ +#define IPL_CLOCK 10 /* clock */ +#define IPL_SCHED IPL_CLOCK +#define IPL_STATCLOCK IPL_CLOCK +#define IPL_HIGH 11 /* everything */ +#define IPL_IPI 12 /* interprocessor interrupt */ +#define NIPL 13 /* number of levels */ + +#define IPL_MPFLOOR IPL_TTY +/* Interrupt priority 'flags'. */ +#define IPL_IRQMASK 0xf /* priority only */ +#define IPL_FLAGMASK 0xf00 /* flags only*/ +#define IPL_MPSAFE 0x100 /* 'mpsafe' interrupt, no kernel lock */ +#define IPL_WAKEUP 0x200 /* 'wakeup' interrupt */ + +/* Interrupt sharing types. */ +#define IST_NONE 0 /* none */ +#define IST_PULSE 1 /* pulsed */ +#define IST_EDGE 2 /* edge-triggered */ +#define IST_LEVEL 3 /* level-triggered */ + +#define IST_LEVEL_LOW IST_LEVEL +#define IST_LEVEL_HIGH 4 +#define IST_EDGE_FALLING IST_EDGE +#define IST_EDGE_RISING 5 +#define IST_EDGE_BOTH 6 + +#define __USE_MI_SOFTINTR + +#include + +#ifndef _LOCORE +#include + +void softintr(int); + +int splraise(int); +int spllower(int); +void splx(int); + +void arm_do_pending_intr(int); +void arm_set_intr_handler(int (*)(int), int (*)(int), void (*)(int), + void (*)(int), void (*)(void *), void (*)(void *), + void (*)(void), void (*)(void)); + +struct machine_intr_handle { + struct interrupt_controller *ih_ic; + void *ih_ih; +}; + +struct arm_intr_func { + int (*raise)(int); + int (*lower)(int); + void (*x)(int); + void (*setipl)(int); + void (*enable_wakeup)(void); + void (*disable_wakeup)(void); +}; + +extern struct arm_intr_func arm_intr_func; + +#define splraise(cpl) (arm_intr_func.raise(cpl)) +#define _splraise(cpl) (arm_intr_func.raise(cpl)) +#define spllower(cpl) (arm_intr_func.lower(cpl)) +#define splx(cpl) (arm_intr_func.x(cpl)) + +#define splsoftclock() splraise(IPL_SOFTCLOCK) +#define splsoftnet() splraise(IPL_SOFTNET) +#define splsofttty() splraise(IPL_SOFTTTY) +#define splbio() splraise(IPL_BIO) +#define splnet() splraise(IPL_NET) +#define spltty() splraise(IPL_TTY) +#define splvm() splraise(IPL_VM) +#define splaudio() splraise(IPL_AUDIO) +#define splclock() splraise(IPL_CLOCK) +#define splsched() splraise(IPL_SCHED) +#define splstatclock() splraise(IPL_STATCLOCK) +#define splhigh() splraise(IPL_HIGH) + +#define spl0() spllower(IPL_NONE) + +void intr_barrier(void *); +void intr_set_wakeup(void *); +void intr_enable_wakeup(void); +void intr_disable_wakeup(void); + +void arm_init_smask(void); /* XXX */ +extern uint32_t arm_smask[NIPL]; + +/* XXX - this is probably the wrong location for this */ +void arm_clock_register(void (*)(void), void (*)(u_int), void (*)(int), + void (*)(void)); + +struct cpu_info; + +struct interrupt_controller { + int ic_node; + void *ic_cookie; + void *(*ic_establish)(void *, int *, int, struct cpu_info *, + int (*)(void *), void *, char *); + void *(*ic_establish_msi)(void *, uint64_t *, uint64_t *, int, + struct cpu_info *, int (*)(void *), void *, char *); + void (*ic_disestablish)(void *); + void (*ic_enable)(void *); + void (*ic_disable)(void *); + void (*ic_route)(void *, int, struct cpu_info *); + void (*ic_cpu_enable)(void); + void (*ic_barrier)(void *); + void (*ic_set_wakeup)(void *); + + LIST_ENTRY(interrupt_controller) ic_list; + uint32_t ic_phandle; + uint32_t ic_cells; + uint32_t ic_gic_its_id; +}; + +void arm_intr_init_fdt(void); +void arm_intr_register_fdt(struct interrupt_controller *); +void *arm_intr_establish_fdt(int, int, int (*)(void *), + void *, char *); +void *arm_intr_establish_fdt_cpu(int, int, struct cpu_info *, + int (*)(void *), void *, char *); +void *arm_intr_establish_fdt_idx(int, int, int, int (*)(void *), + void *, char *); +void *arm_intr_establish_fdt_idx_cpu(int, int, int, struct cpu_info *, + int (*)(void *), void *, char *); +void *arm_intr_establish_fdt_imap(int, int *, int, int, int (*)(void *), + void *, char *); +void *arm_intr_establish_fdt_imap_cpu(int, int *, int, int, + struct cpu_info *, int (*)(void *), void *, char *); +void *arm_intr_establish_fdt_msi(int, uint64_t *, uint64_t *, int, + int (*)(void *), void *, char *); +void *arm_intr_establish_fdt_msi_cpu(int, uint64_t *, uint64_t *, int, + struct cpu_info *, int (*)(void *), void *, char *); +void arm_intr_disestablish_fdt(void *); +void arm_intr_enable(void *); +void arm_intr_disable(void *); +void arm_intr_route(void *, int, struct cpu_info *); +void arm_intr_cpu_enable(void); +void *arm_intr_parent_establish_fdt(void *, int *, int, + struct cpu_info *ci, int (*)(void *), void *, char *); +void arm_intr_parent_disestablish_fdt(void *); + +void arm_send_ipi(struct cpu_info *, int); +extern void (*intr_send_ipi_func)(struct cpu_info *, int); + +#define ARM_IPI_NOP 0 +#define ARM_IPI_DDB 1 +#define ARM_IPI_HALT 2 + +#ifdef DIAGNOSTIC +/* + * Although this function is implemented in MI code, it must be in this MD + * header because we don't want this header to include MI includes. + */ +void splassert_fail(int, int, const char *); +extern int splassert_ctl; +void arm_splassert_check(int, const char *); +#define splassert(__wantipl) do { \ + if (splassert_ctl > 0) { \ + arm_splassert_check(__wantipl, __func__); \ + } \ +} while (0) +#define splsoftassert(wantipl) splassert(wantipl) +#else +#define splassert(wantipl) do { /* nothing */ } while (0) +#define splsoftassert(wantipl) do { /* nothing */ } while (0) +#endif + +#endif /* ! _LOCORE */ + +#endif /* _KERNEL */ + +#endif /* _MACHINE_INTR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/kcore.h b/lib/libc/include/aarch64-openbsd-none/arm64/kcore.h new file mode 100644 index 0000000000..a65c7257a0 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/kcore.h @@ -0,0 +1,15 @@ +/* $OpenBSD: kcore.h,v 1.1 2016/12/17 23:38:33 patrick Exp $ */ +/* public domain */ + +/* Make sure this is larger than DRAM_BLOCKS on all arm-based platforms */ +#define NPHYS_RAM_SEGS 8 + +typedef struct cpu_kcore_hdr { + u_int64_t kernelbase; /* value of KERNEL_BASE */ + u_int64_t kerneloffs; /* offset of kernel in RAM */ + u_int64_t staticsize; /* size of contiguous mapping */ + u_int64_t pmap_kernel_l1; /* pmap_kernel()->pm_l1 */ + u_int64_t pmap_kernel_l2; /* pmap_kernel()->pm_l2 */ + u_int64_t reserved[11]; + phys_ram_seg_t ram_segs[NPHYS_RAM_SEGS]; +} cpu_kcore_hdr_t; \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/limits.h b/lib/libc/include/aarch64-openbsd-none/arm64/limits.h new file mode 100644 index 0000000000..491b57a52a --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/limits.h @@ -0,0 +1,56 @@ +/* $OpenBSD: limits.h,v 1.1 2016/12/17 23:38:33 patrick Exp $ */ +/* $NetBSD: limits.h,v 1.4 2003/04/28 23:16:18 bjh21 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 + +#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_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/loadfile_machdep.h b/lib/libc/include/aarch64-openbsd-none/arm64/loadfile_machdep.h new file mode 100644 index 0000000000..59761f8b7e --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/loadfile_machdep.h @@ -0,0 +1,53 @@ +/* $OpenBSD: loadfile_machdep.h,v 1.2 2019/04/10 04:17:34 deraadt Exp $ */ +/* $NetBSD: loadfile_machdep.h,v 1.1 1999/04/29 03:17:12 tsubai Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * 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. + */ + +#define BOOT_ELF +#define ELFSIZE 64 + +#define LOAD_KERNEL (LOAD_ALL & ~LOAD_TEXTA) +#define COUNT_KERNEL (COUNT_ALL & ~COUNT_TEXTA) + +extern u_long efi_loadaddr; +#define LOADADDR(a) (((((u_long)(a)) + offset)&0x7fffffffff) + \ + efi_loadaddr) +#define ALIGNENTRY(a) ((u_long)(a)) +#define READ(f, b, c) read((f), (void *)LOADADDR(b), (c)) +#define BCOPY(s, d, c) memcpy((void *)LOADADDR(d), (void *)(s), (c)) +#define BZERO(d, c) memset((void *)LOADADDR(d), 0, (c)) +#define WARN(a) (void)(printf a, \ + printf((errno ? ": %s\n" : "\n"), \ + strerror(errno))) +#define PROGRESS(a) (void) printf a +#define ALLOC(a) alloc(a) +#define FREE(a, b) free(a, b) + +void run_loadfile(uint64_t *, int); \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/mplock.h b/lib/libc/include/aarch64-openbsd-none/arm64/mplock.h new file mode 100644 index 0000000000..36a2b125ab --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/mplock.h @@ -0,0 +1,10 @@ +/* $OpenBSD: mplock.h,v 1.3 2018/01/05 17:42:35 kettenis Exp $ */ + +/* public domain */ + +#ifndef _MACHINE_MPLOCK_H_ +#define _MACHINE_MPLOCK_H_ + +#define __USE_MI_MPLOCK + +#endif /* !_MACHINE_MPLOCK_H */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/mutex.h b/lib/libc/include/aarch64-openbsd-none/arm64/mutex.h new file mode 100644 index 0000000000..f5115c3084 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/mutex.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mutex.h,v 1.5 2018/01/25 15:06:29 mpi Exp $ */ + +#define __USE_MI_MUTEX \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/openpromio.h b/lib/libc/include/aarch64-openbsd-none/arm64/openpromio.h new file mode 100644 index 0000000000..3ad9149116 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/openpromio.h @@ -0,0 +1,57 @@ +/* $OpenBSD: openpromio.h,v 1.1 2017/01/23 12:34:06 kettenis Exp $ */ +/* $NetBSD: openpromio.h,v 1.1.1.1 1998/06/20 04:58:52 eeh Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)openpromio.h 8.1 (Berkeley) 6/11/93 + */ + +struct opiocdesc { + int op_nodeid; /* passed or returned node id */ + int op_namelen; /* length of op_name */ + char *op_name; /* pointer to field name */ + int op_buflen; /* length of op_buf (value-result) */ + char *op_buf; /* pointer to field value */ +}; + +#define OPIOCGET _IOWR('O', 1, struct opiocdesc) /* get openprom field */ +#define OPIOCSET _IOW('O', 2, struct opiocdesc) /* set openprom field */ +#define OPIOCNEXTPROP _IOWR('O', 3, struct opiocdesc) /* get next property */ +#define OPIOCGETOPTNODE _IOR('O', 4, int) /* get openprom field */ +#define OPIOCGETNEXT _IOWR('O', 5, int) /* get next node of node */ +#define OPIOCGETCHILD _IOWR('O', 6, int) /* get first child of node */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/param.h b/lib/libc/include/aarch64-openbsd-none/arm64/param.h new file mode 100644 index 0000000000..0d7eb0c796 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/param.h @@ -0,0 +1,81 @@ +/* $OpenBSD: param.h,v 1.8 2025/07/07 18:33:36 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 +#endif +#endif + +#define _MACHINE arm64 +#define MACHINE "arm64" +#define _MACHINE_ARCH aarch64 +#define MACHINE_ARCH "aarch64" +#define MID_MACHINE MID_ARM64 + +#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 6 /* pages of u-area */ +#define USPACE (UPAGES * PAGE_SIZE) /* total size of u-area */ +#define USPACE_ALIGN 0 /* u-area alignment 0-none */ +#define __HAVE_USPACE_GUARD + +#define NMBCLUSTERS (64 * 1024) /* max cluster allocation */ + +#ifndef MSGBUFSIZE +#define MSGBUFSIZE (16 * PAGE_SIZE) /* default message buffer size */ +#endif + +#define STACKALIGNBYTES (16 - 1) +#define STACKALIGN(p) ((u_long)(p) &~ STACKALIGNBYTES) + +#define __HAVE_ACPI +#define __HAVE_FDT + +#endif /* _KERNEL */ + +#endif /* _MACHINE_PARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/pcb.h b/lib/libc/include/aarch64-openbsd-none/arm64/pcb.h new file mode 100644 index 0000000000..9e4880b7a8 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/pcb.h @@ -0,0 +1,45 @@ +/* $OpenBSD: pcb.h,v 1.8 2025/02/24 13:18:01 jsg Exp $ */ +/* + * Copyright (c) 2016 Dale Rahn + * + * 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_PCB_H_ +#define _MACHINE_PCB_H_ + +#include +#include + +struct trapframe; + +/* + * Warning certain fields must be within 256 bytes of the beginning + * of this structure. + */ +struct pcb { + u_int pcb_flags; +#define PCB_FPU 0x00000001 /* Process had FPU initialized */ +#define PCB_SINGLESTEP 0x00000002 /* Single step process */ +#define PCB_SVE 0x00000004 /* Process had SVE initialized */ + struct trapframe *pcb_tf; + + register_t pcb_sp; /* stack pointer of switchframe */ + + caddr_t pcb_onfault; /* On fault handler */ + struct fpreg pcb_fpstate; /* Floating Point state */ + __uint16_t pcb_sve_p[16]; /* SVE predicate registers */ + __uint16_t pcb_sve_ffr; /* SVE first fault register */ + + void *pcb_tcb; +}; +#endif /* _MACHINE_PCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/pci_machdep.h b/lib/libc/include/aarch64-openbsd-none/arm64/pci_machdep.h new file mode 100644 index 0000000000..fec001a5f4 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/pci_machdep.h @@ -0,0 +1,145 @@ +/* $OpenBSD: pci_machdep.h,v 1.13 2025/01/23 11:24:34 kettenis Exp $ */ + +/* + * Copyright (c) 2003-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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. + * + */ + +typedef struct machine_pci_chipset *pci_chipset_tag_t; +typedef uint64_t pcitag_t; + +#define PCITAG_NODE(x) ((x) >> 32) +#define PCITAG_OFFSET(x) ((x) & 0xffffffff) + +/* Supported interrupt types. */ +#define PCI_NONE 0 +#define PCI_INTX 1 +#define PCI_MSI 2 +#define PCI_MSIX 3 + +typedef struct { + pci_chipset_tag_t ih_pc; + pcitag_t ih_tag; + int ih_intrpin; + int ih_type; + bus_dma_tag_t ih_dmat; +} pci_intr_handle_t; + +struct pci_attach_args; + +/* + * Machine-specific PCI structure and type definitions. + * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE. + */ +struct machine_pci_chipset { + void *pc_conf_v; + void (*pc_attach_hook)(struct device *, + struct device *, struct pcibus_attach_args *); + int (*pc_bus_maxdevs)(void *, int); + pcitag_t (*pc_make_tag)(void *, int, int, int); + void (*pc_decompose_tag)(void *, pcitag_t, int *, + int *, int *); + int (*pc_conf_size)(void *, pcitag_t); + pcireg_t (*pc_conf_read)(void *, pcitag_t, int); + void (*pc_conf_write)(void *, pcitag_t, int, pcireg_t); + int (*pc_probe_device_hook)(void *, struct pci_attach_args *); + + void *pc_intr_v; + int (*pc_intr_map)(struct pci_attach_args *, + pci_intr_handle_t *); + int (*pc_intr_map_msi)(struct pci_attach_args *, + pci_intr_handle_t *); + int (*pc_intr_map_msivec)(struct pci_attach_args *, + int, pci_intr_handle_t *); + int (*pc_intr_map_msix)(struct pci_attach_args *, + int, pci_intr_handle_t *); + const char *(*pc_intr_string)(void *, pci_intr_handle_t); + void *(*pc_intr_establish)(void *, pci_intr_handle_t, + int, struct cpu_info *, int (*)(void *), void *, + char *); + void (*pc_intr_disestablish)(void *, void *); +}; + +/* + * Functions provided to machine-independent PCI code. + */ +#define pci_attach_hook(p, s, pba) \ + (*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba)) +#define pci_bus_maxdevs(c, b) \ + (*(c)->pc_bus_maxdevs)((c)->pc_conf_v, (b)) +#define pci_make_tag(c, b, d, f) \ + (*(c)->pc_make_tag)((c)->pc_conf_v, (b), (d), (f)) +#define pci_decompose_tag(c, t, bp, dp, fp) \ + (*(c)->pc_decompose_tag)((c)->pc_conf_v, (t), (bp), (dp), (fp)) +#define pci_conf_size(c, t) \ + (*(c)->pc_conf_size)((c)->pc_conf_v, (t)) +#define pci_conf_read(c, t, r) \ + (*(c)->pc_conf_read)((c)->pc_conf_v, (t), (r)) +#define pci_conf_write(c, t, r, v) \ + (*(c)->pc_conf_write)((c)->pc_conf_v, (t), (r), (v)) +#define pci_probe_device_hook(c, a) \ + (*(c)->pc_probe_device_hook)((c)->pc_conf_v, (a)) +#define pci_intr_map(c, ihp) \ + (*(c)->pa_pc->pc_intr_map)((c), (ihp)) +#define pci_intr_map_msi(c, ihp) \ + (*(c)->pa_pc->pc_intr_map_msi)((c), (ihp)) +#define pci_intr_map_msivec(c, vec, ihp) \ + (*(c)->pa_pc->pc_intr_map_msivec)((c), (vec), (ihp)) +#define pci_intr_map_msix(c, vec, ihp) \ + (*(c)->pa_pc->pc_intr_map_msix)((c), (vec), (ihp)) +#define pci_intr_string(c, ih) \ + (*(c)->pc_intr_string)((c)->pc_intr_v, (ih)) +#define pci_intr_establish(c, ih, l, h, a, nm) \ + (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), NULL, (h), (a),\ + (nm)) +#define pci_intr_establish_cpu(c, ih, l, ci, h, a, nm) \ + (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), (ci), (h), (a),\ + (nm)) +#define pci_intr_disestablish(c, iv) \ + (*(c)->pc_intr_disestablish)((c)->pc_intr_v, (iv)) + +#define pci_min_powerstate(c, t) (PCI_PMCSR_STATE_D3) +#define pci_set_powerstate_md(c, t, s, p) + +#define pci_dev_postattach(a, b) + +void pci_mcfg_init(bus_space_tag_t, bus_addr_t, int, int, int); +pci_chipset_tag_t pci_lookup_segment(int, int); + +int pci_intr_enable_msivec(struct pci_attach_args *, int); + +void pci_msi_enable(pci_chipset_tag_t, pcitag_t, bus_addr_t, uint32_t); +void pci_msix_enable(pci_chipset_tag_t, pcitag_t, bus_space_tag_t, + int, bus_addr_t, uint32_t); +int _pci_intr_map_msi(struct pci_attach_args *, pci_intr_handle_t *); +int _pci_intr_map_msivec(struct pci_attach_args *, int, + pci_intr_handle_t *); +int _pci_intr_map_msix(struct pci_attach_args *, int, pci_intr_handle_t *); + +#define __HAVE_PCI_MSIX + +int pci_msix_table_map(pci_chipset_tag_t, pcitag_t, + bus_space_tag_t, bus_space_handle_t *); +void pci_msix_table_unmap(pci_chipset_tag_t, pcitag_t, + bus_space_tag_t, bus_space_handle_t); \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/pmap.h b/lib/libc/include/aarch64-openbsd-none/arm64/pmap.h new file mode 100644 index 0000000000..5f4d7bf5e1 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/pmap.h @@ -0,0 +1,143 @@ +/* $OpenBSD: pmap.h,v 1.29 2025/05/21 09:42:59 kettenis Exp $ */ +/* + * Copyright (c) 2008,2009,2014 Dale Rahn + * + * 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 _ARM64_PMAP_H_ +#define _ARM64_PMAP_H_ + +#ifndef _LOCORE +#include +#include +#include +#endif + + +/* V->P mapping data */ +#define VP_IDX0_CNT 512 +#define VP_IDX0_MASK (VP_IDX0_CNT-1) +#define VP_IDX0_POS 39 +#define VP_IDX1_CNT 512 +#define VP_IDX1_MASK (VP_IDX1_CNT-1) +#define VP_IDX1_POS 30 +#define VP_IDX2_CNT 512 +#define VP_IDX2_MASK (VP_IDX2_CNT-1) +#define VP_IDX2_POS 21 +#define VP_IDX3_CNT 512 +#define VP_IDX3_MASK (VP_IDX3_CNT-1) +#define VP_IDX3_POS 12 + +/* cache flags */ +#define PMAP_CACHE_CI (PMAP_MD0) /* cache inhibit */ +#define PMAP_CACHE_WT (PMAP_MD1) /* writethru */ +#define PMAP_CACHE_WB (PMAP_MD1|PMAP_MD0) /* writeback */ +#define PMAP_CACHE_DEV_NGNRNE (PMAP_MD2) /* device nGnRnE */ +#define PMAP_CACHE_DEV_NGNRE (PMAP_MD2|PMAP_MD0) /* device nGnRE */ +#define PMAP_CACHE_BITS (PMAP_MD0|PMAP_MD1|PMAP_MD2) + +#define PTED_VA_MANAGED_M (PMAP_MD3) +#define PTED_VA_WIRED_M (PMAP_MD3 << 1) + + +#if defined(_KERNEL) && !defined(_LOCORE) +/* + * Pmap stuff + */ + +typedef struct pmap *pmap_t; + +struct pmap { + struct mutex pm_mtx; + union { + struct pmapvp0 *l0; /* virtual to physical table 4 lvl */ + struct pmapvp1 *l1; /* virtual to physical table 3 lvl */ + } pm_vp; + uint64_t pm_pt0pa; + uint64_t pm_asid; + uint64_t pm_guarded; + int have_4_level_pt; + int pm_privileged; + volatile int pm_active; + int pm_refs; /* ref count */ + struct pmap_statistics pm_stats; /* pmap statistics */ + uint64_t pm_apiakey[2]; + uint64_t pm_apdakey[2]; + uint64_t pm_apibkey[2]; + uint64_t pm_apdbkey[2]; + uint64_t pm_apgakey[2]; +}; + +#define PMAP_PA_MASK ~((paddr_t)PAGE_MASK) /* to remove the flags */ +#define PMAP_NOCACHE 0x1 /* non-cacheable memory */ +#define PMAP_DEVICE 0x2 /* device memory */ +#define PMAP_WC PMAP_DEVICE + +#define PG_PMAP_MOD PG_PMAP0 +#define PG_PMAP_REF PG_PMAP1 +#define PG_PMAP_EXE PG_PMAP2 + +// [NCPUS] +extern paddr_t zero_page; +extern paddr_t copy_src_page; +extern paddr_t copy_dst_page; + +void pagezero_cache(vaddr_t); + +extern struct pmap kernel_pmap_; +#define pmap_kernel() (&kernel_pmap_) +#define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count) +#define pmap_wired_count(pmap) ((pmap)->pm_stats.wired_count) + +vaddr_t pmap_bootstrap(long kvo, paddr_t lpt1, long kernelstart, + long kernelend, long ram_start, long ram_end); +void pmap_postinit(void); +void pmap_init_percpu(void); + +void pmap_kenter_cache(vaddr_t va, paddr_t pa, vm_prot_t prot, int cacheable); +void pmap_page_ro(pmap_t pm, vaddr_t va, vm_prot_t prot); +void pmap_page_rw(pmap_t pm, vaddr_t va); + +void pmap_setpauthkeys(struct pmap *); + +paddr_t pmap_steal_avail(size_t size, int align, void **kva); +void pmap_avail_fixup(void); +void pmap_physload_avail(void); + +#define PMAP_GROWKERNEL + +struct pv_entry; + +/* investigate */ +#define pmap_unuse_final(p) do { /* nothing */ } while (0) +int pmap_fault_fixup(pmap_t, vaddr_t, vm_prot_t); + +#define __HAVE_PMAP_MPSAFE_ENTER_COW +#define __HAVE_PMAP_POPULATE +#define __HAVE_PMAP_PURGE + +#endif /* _KERNEL && !_LOCORE */ + +#ifndef _LOCORE +struct vm_page_md { + struct mutex pv_mtx; + LIST_HEAD(,pte_desc) pv_list; +}; + +#define VM_MDPAGE_INIT(pg) do { \ + mtx_init(&(pg)->mdpage.pv_mtx, IPL_VM); \ + LIST_INIT(&((pg)->mdpage.pv_list)); \ +} while (0) +#endif /* _LOCORE */ + +#endif /* _ARM64_PMAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/proc.h b/lib/libc/include/aarch64-openbsd-none/arm64/proc.h new file mode 100644 index 0000000000..0b694ab2f4 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/proc.h @@ -0,0 +1,45 @@ +/* $OpenBSD: proc.h,v 1.2 2017/04/13 03:52:25 guenther Exp $ */ +/* $NetBSD: proc.h,v 1.1 2003/04/26 18:39:46 fvdl 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_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/profile.h b/lib/libc/include/aarch64-openbsd-none/arm64/profile.h new file mode 100644 index 0000000000..65fa3c7bc5 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/profile.h @@ -0,0 +1,68 @@ +/* $OpenBSD: profile.h,v 1.2 2021/02/17 12:11:45 kettenis Exp $ */ +/* + * Copyright (c) 2015 Dale Rahn + * + * 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 _MCOUNT_DECL void _mcount + +#define MCOUNT_ASM_NAME "__mcount" + +#ifdef __PIC__ +#define PLTSYM "" /* XXX -aarch64 defaults to PLT? */ +#else +#define PLTSYM "" +#endif + +#define MCOUNT \ +__asm__ (".text;" \ + ".align 3;" \ + ".globl " MCOUNT_ASM_NAME ";" \ + ".type " MCOUNT_ASM_NAME ",@function;" \ + MCOUNT_ASM_NAME ":;" \ + " stp x0, x1, [sp, #-160]!;" \ + " stp x2, x3, [sp, #16];" \ + " stp x4, x5, [sp, #32];" \ + " stp x6, x7, [sp, #48];" \ + " stp x8, x9, [sp, #64];" \ + " stp x10,x11,[sp, #80];" \ + " stp x12,x13,[sp, #96];" \ + " stp x14,x15,[sp, #112];" \ + " stp x16,x17,[sp, #128];" \ + " stp x29,lr, [sp, #144];" \ + /* load from pc at 8 off frame pointer */ \ + " ldr x0, [x29, #8];" \ + " mov x1, lr;" \ + " bl " __STRING(_mcount) PLTSYM ";" \ + /* restore argument registers */ \ + " ldp x2, x3, [sp, #16];" \ + " ldp x4, x5, [sp, #32];" \ + " ldp x6, x7, [sp, #48];" \ + " ldp x8, x9, [sp, #64];" \ + " ldp x10,x11,[sp, #80];" \ + " ldp x12,x13,[sp, #96];" \ + " ldp x14,x15,[sp, #112];" \ + " ldp x16,x17,[sp, #128];" \ + " ldp x29,lr, [sp, #144];" \ + " ldp x0, x1, [sp], #160;" \ + " ret;"); + +#ifdef _KERNEL +// Change this to dair read/set, then restore. +#define MCOUNT_ENTER \ +__asm__ ("mrs %x0, daif; msr daifset, #0x3": "=r"(s)); +#define MCOUNT_EXIT \ +__asm__ ("msr daif, %x0":: "r"(s)); + +#endif // _KERNEL \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/pte.h b/lib/libc/include/aarch64-openbsd-none/arm64/pte.h new file mode 100644 index 0000000000..980230fc56 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/pte.h @@ -0,0 +1,104 @@ +/* $OpenBSD: pte.h,v 1.10 2024/10/14 12:02:16 jsg Exp $ */ +/* + * Copyright (c) 2014 Dale Rahn + * + * 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 _ARM_PTE_H_ +#define _ARM_PTE_H_ + +/* level X descriptor */ +#define Lx_TYPE_MASK (0x00000003) /* mask of type bits */ +#define Lx_TYPE_S (0x00000001) +#define Lx_TYPE_PT (0x00000003) +// XXX need to investigate use of these +#define Lx_PT_NS (1ULL<<63) +#define Lx_PT_AP00 (0ULL<<61) +#define Lx_PT_AP01 (1ULL<<61) +#define Lx_PT_AP10 (2ULL<<61) +#define Lx_PT_AP11 (3ULL<<61) +#define Lx_PT_XN (1ULL<<60) +#define Lx_PT_PXN (1ULL<<59) +#define Lx_TABLE_ALIGN (4096) + +/* Block and Page attributes */ +/* TODO: Add the upper attributes */ +#define ATTR_MASK_H (0xfff0000000000000ULL) +#define ATTR_MASK_L (0x0000000000000fffULL) +#define ATTR_MASK (ATTR_MASK_H | ATTR_MASK_L) +/* Bits 58:55 are reserved for software */ +#define ATTR_SW_MANAGED (1UL << 56) +#define ATTR_SW_WIRED (1UL << 55) +#define ATTR_UXN (1UL << 54) +#define ATTR_PXN (1UL << 53) +#define ATTR_GP (1UL << 50) +#define ATTR_nG (1 << 11) +#define ATTR_AF (1 << 10) +#define ATTR_SH(x) ((x) << 8) +#define ATTR_AP_RW_BIT (1 << 7) +#define ATTR_AP(x) ((x) << 6) +#define ATTR_AP_MASK ATTR_AP(3) +#define ATTR_NS (1 << 5) +#define ATTR_IDX(x) ((x) << 2) +#define ATTR_IDX_MASK (7 << 2) + +#define PTE_ATTR_DEV_NGNRNE 0 +#define PTE_ATTR_DEV_NGNRE 1 +#define PTE_ATTR_CI 2 +#define PTE_ATTR_WB 3 +#define PTE_ATTR_WT 4 + +#define PTE_MEMATTR_DEV_NGNRNE 0x0 +#define PTE_MEMATTR_DEV_NGNRE 0x1 +#define PTE_MEMATTR_CI 0x5 +#define PTE_MEMATTR_WB 0xf +#define PTE_MEMATTR_WT 0xa + +#define SH_INNER 3 +#define SH_OUTER 2 +#define SH_NONE 0 + +/* Level 0 table, 512GiB per entry */ +#define L0_SHIFT 39 +#define L0_INVAL 0x0 /* An invalid address */ +#define L0_BLOCK 0x1 /* A block */ + /* 0x2 also marks an invalid address */ +#define L0_TABLE 0x3 /* A next-level table */ + +/* Level 1 table, 1GiB per entry */ +#define L1_SHIFT 30 +#define L1_SIZE (1 << L1_SHIFT) +#define L1_OFFSET (L1_SIZE - 1) +#define L1_INVAL L0_INVAL +#define L1_BLOCK L0_BLOCK +#define L1_TABLE L0_TABLE + +/* Level 2 table, 2MiB per entry */ +#define L2_SHIFT 21 +#define L2_SIZE (1 << L2_SHIFT) +#define L2_OFFSET (L2_SIZE - 1) +#define L2_INVAL L0_INVAL +#define L2_BLOCK L0_BLOCK +#define L2_TABLE L0_TABLE + +/* page mapping */ +#define L3_P 0x3 + +#define Ln_ENTRIES (1 << 9) +#define Ln_ADDR_MASK (Ln_ENTRIES - 1) +#define Ln_TABLE_MASK ((1 << 12) - 1) + +/* physical page mask */ +#define PTE_RPGN (((1ULL << 48) - 1) & ~PAGE_MASK) + +#endif /* _ARM_PTE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/ptrace.h b/lib/libc/include/aarch64-openbsd-none/arm64/ptrace.h new file mode 100644 index 0000000000..c63c70f29d --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/ptrace.h @@ -0,0 +1,27 @@ +/* $OpenBSD: ptrace.h,v 1.2 2023/06/10 19:30:48 kettenis Exp $ */ +/* + * Copyright (c) 2014 Patrick Wildt + * + * 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 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) +#define PT_PACMASK (PT_FIRSTMACH + 5) + +#ifdef _KERNEL +register_t process_get_pacmask(struct proc *p); +#endif \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/reg.h b/lib/libc/include/aarch64-openbsd-none/arm64/reg.h new file mode 100644 index 0000000000..e8cda2d2dc --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/reg.h @@ -0,0 +1,36 @@ +/* $OpenBSD: reg.h,v 1.3 2017/04/11 06:52:13 kettenis Exp $ */ +/* + * Copyright (c) 2014 Patrick Wildt + * + * 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_REG_H_ +#define _MACHINE_REG_H_ + +struct reg { + uint64_t r_reg[30]; + uint64_t r_lr; + uint64_t r_sp; + uint64_t r_pc; + uint64_t r_spsr; + uint64_t r_tpidr; +}; + +struct fpreg { + __uint128_t fp_reg[32]; + uint32_t fp_sr; + uint32_t fp_cr; +}; + +#endif /* !_MACHINE_REG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/reloc.h b/lib/libc/include/aarch64-openbsd-none/arm64/reloc.h new file mode 100644 index 0000000000..73ea25bba7 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/reloc.h @@ -0,0 +1,123 @@ +/* $OpenBSD: reloc.h,v 1.2 2017/10/24 20:35:54 guenther Exp $ */ +/* + * AArch64 static relocation types. + */ + +/* Miscellaneous. */ +#define R_ARM_NONE 0 +#define R_AARCH64_TPOFF64 1 /// COMPLETELY WRONG - stub +#define R_AARCH64_NONE 0 + +/* Data. */ +#define R_AARCH64_ABS64 257 +#define R_AARCH64_ABS32 258 +#define R_AARCH64_ABS16 259 +#define R_AARCH64_PREL64 260 +#define R_AARCH64_PREL32 261 +#define R_AARCH64_PREL16 262 + +/* Instructions. */ +#define R_AARCH64_MOVW_UABS_G0 263 +#define R_AARCH64_MOVW_UABS_G0_NC 264 +#define R_AARCH64_MOVW_UABS_G1 265 +#define R_AARCH64_MOVW_UABS_G1_NC 266 +#define R_AARCH64_MOVW_UABS_G2 267 +#define R_AARCH64_MOVW_UABS_G2_NC 268 +#define R_AARCH64_MOVW_UABS_G3 269 + +#define R_AARCH64_MOVW_SABS_G0 270 +#define R_AARCH64_MOVW_SABS_G1 271 +#define R_AARCH64_MOVW_SABS_G2 272 + +#define R_AARCH64_LD_PREL_LO19 273 +#define R_AARCH64_ADR_PREL_LO21 274 +#define R_AARCH64_ADR_PREL_PG_HI21 275 +#define R_AARCH64_ADR_PREL_PG_HI21_NC 276 +#define R_AARCH64_ADD_ABS_LO12_NC 277 +#define R_AARCH64_LDST8_ABS_LO12_NC 278 + +#define R_AARCH64_TSTBR14 279 +#define R_AARCH64_CONDBR19 280 +#define R_AARCH64_JUMP26 282 +#define R_AARCH64_CALL26 283 +#define R_AARCH64_LDST16_ABS_LO12_NC 284 +#define R_AARCH64_LDST32_ABS_LO12_NC 285 +#define R_AARCH64_LDST64_ABS_LO12_NC 286 +#define R_AARCH64_LDST128_ABS_LO12_NC 299 + +#define R_AARCH64_MOVW_PREL_G0 287 +#define R_AARCH64_MOVW_PREL_G0_NC 288 +#define R_AARCH64_MOVW_PREL_G1 289 +#define R_AARCH64_MOVW_PREL_G1_NC 290 +#define R_AARCH64_MOVW_PREL_G2 291 +#define R_AARCH64_MOVW_PREL_G2_NC 292 +#define R_AARCH64_MOVW_PREL_G3 293 + + +#define R_AARCH64_COPY 1024 +#define R_AARCH64_GLOB_DAT 1025 // S + A +#define R_AARCH64_JUMP_SLOT 1026 // S + A +#define R_AARCH64_RELATIVE 1027 // Delta(S) + A +#define R_AARCH64_TLS_DTPREL64 1028 // DTPREL(S+A) +#define R_AARCH64_TLS_DTPMOD64 1029 // LDM(S) +#define R_AARCH64_TLS_TPREL64 1030 // TPREL(S+A) +#define R_AARCH64_TLSDESC 1031 // TLSDESC(S+A) TLS descriptor to be filled +#define R_AARCH64_IRELATIVE 1032 // Indirect(Delta(S) + A) + +// old arm32 defines. +/* Processor specific relocation types */ + +#define R_ARM_NONE 0 +#define R_ARM_PC24 1 +#define R_ARM_ABS32 2 +#define R_ARM_REL32 3 +#define R_ARM_PC13 4 +#define R_ARM_ABS16 5 +#define R_ARM_ABS12 6 +#define R_ARM_THM_ABS5 7 +#define R_ARM_ABS8 8 +#define R_ARM_SBREL32 9 +#define R_ARM_THM_PC22 10 +#define R_ARM_THM_PC8 11 +#define R_ARM_AMP_VCALL9 12 +#define R_ARM_SWI24 13 +#define R_ARM_THM_SWI8 14 +#define R_ARM_XPC25 15 +#define R_ARM_THM_XPC22 16 + +/* 17-31 are reserved for ARM Linux. */ +#define R_ARM_TLS_DTPMOD32 17 +#define R_ARM_TLS_DTPOFF32 18 +#define R_ARM_TLS_TPOFF32 19 + +#define R_ARM_COPY 20 +#define R_ARM_GLOB_DAT 21 +#define R_ARM_JUMP_SLOT 22 +#define R_ARM_RELATIVE 23 +#define R_ARM_GOTOFF 24 +#define R_ARM_GOTPC 25 +#define R_ARM_GOT32 26 +#define R_ARM_PLT32 27 + +#define R_ARM_ALU_PCREL_7_0 32 +#define R_ARM_ALU_PCREL_15_8 33 +#define R_ARM_ALU_PCREL_23_15 34 +#define R_ARM_ALU_SBREL_11_0 35 +#define R_ARM_ALU_SBREL_19_12 36 +#define R_ARM_ALU_SBREL_27_20 37 + +/* 96-111 are reserved to G++. */ +#define R_ARM_GNU_VTENTRY 100 +#define R_ARM_GNU_VTINHERIT 101 +#define R_ARM_THM_PC11 102 +#define R_ARM_THM_PC9 103 + +/* 112-127 are reserved for private experiments. */ + +#define R_ARM_RXPC25 249 +#define R_ARM_RSBREL32 250 +#define R_ARM_THM_RPC22 251 +#define R_ARM_RREL32 252 +#define R_ARM_RABS32 253 +#define R_ARM_RPC24 254 +#define R_ARM_RBASE 255 \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/setjmp.h b/lib/libc/include/aarch64-openbsd-none/arm64/setjmp.h new file mode 100644 index 0000000000..098e20281f --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/setjmp.h @@ -0,0 +1,83 @@ +/* $OpenBSD: setjmp.h,v 1.2 2023/04/11 00:45:07 jsg Exp $ */ +/* $NetBSD: setjmp.h,v 1.2 2001/08/25 14:45:59 bjh21 Exp $ */ + +/* + * machine/setjmp.h: machine dependent setjmp-related information. + */ + +#define _JBLEN 64 /* size, in longs, of a jmp_buf */ + +/* + * NOTE: The internal structure of a jmp_buf is *PRIVATE* + * This information is provided as there is software + * that fiddles with this with obtain the stack pointer + * (yes really ! and it's commercial !). + * + * Description of the setjmp buffer + * + * word 0 magic number (dependant on creator) + * 1 - 3 f4 fp register 4 + * 4 - 6 f5 fp register 5 + * 7 - 9 f6 fp register 6 + * 10 - 12 f7 fp register 7 + * 13 fpsr fp status register + * 14 r4 register 4 + * 15 r5 register 5 + * 16 r6 register 6 + * 17 r7 register 7 + * 18 r8 register 8 + * 19 r9 register 9 + * 20 r10 register 10 (sl) + * 21 r11 register 11 (fp) + * 22 r12 register 12 (ip) + * 23 r13 register 13 (sp) + * 24 r14 register 14 (lr) + * 25 signal mask (dependant on magic) + * 26 (con't) + * 27 (con't) + * 28 (con't) + * + * The magic number identifies the jmp_buf and + * how the buffer was created as well as providing + * a sanity check. + * + * A side note I should mention - please do not tamper + * with the floating point fields. While they are + * always saved and restored at the moment this cannot + * be guaranteed especially if the compiler happens + * to be generating soft-float code so no fp + * registers will be used. + * + * Whilst this can be seen an encouraging people to + * use the setjmp buffer in this way I think that it + * is for the best then if changes occur compiles will + * break rather than just having new builds falling over + * mysteriously. + */ + +#define _JB_MAGIC__SETJMP 0x4278f500 +#define _JB_MAGIC_SETJMP 0x4278f501 + +/* Valid for all jmp_buf's */ + +#define _JB_MAGIC 0 +#define _JB_REG_F4 1 +#define _JB_REG_F5 4 +#define _JB_REG_F6 7 +#define _JB_REG_F7 10 +#define _JB_REG_FPSR 13 +#define _JB_REG_R4 14 +#define _JB_REG_R5 15 +#define _JB_REG_R6 16 +#define _JB_REG_R7 17 +#define _JB_REG_R8 18 +#define _JB_REG_R9 19 +#define _JB_REG_R10 20 +#define _JB_REG_R11 21 +#define _JB_REG_R12 22 +#define _JB_REG_R13 23 +#define _JB_REG_R14 24 + +/* Only valid with the _JB_MAGIC_SETJMP magic */ + +#define _JB_SIGMASK 25 \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/signal.h b/lib/libc/include/aarch64-openbsd-none/arm64/signal.h new file mode 100644 index 0000000000..fede515def --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/signal.h @@ -0,0 +1,64 @@ +/* $OpenBSD: signal.h,v 1.2 2017/03/12 17:57:12 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. 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. + * + * @(#)signal.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _MACHINE_SIGNAL_H_ +#define _MACHINE_SIGNAL_H_ + +#include + +typedef int sig_atomic_t; + +#if __BSD_VISIBLE || __XPG_VISIBLE >= 420 +/* + * Information pushed on stack when a signal is delivered. + * This is used by the kernel to restore state following + * execution of the signal handler. It is also made available + * to the handler to allow it to restore state properly if + * a non-standard exit is performed. + */ +struct sigcontext { + int __sc_unused; + int sc_mask; /* signal mask to restore */ + + unsigned long sc_sp; + unsigned long sc_lr; + unsigned long sc_elr; + unsigned long sc_spsr; + unsigned long sc_x[30]; + + long sc_cookie; +}; +#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */ +#endif /* !_MACHINE_SIGNAL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/simplebusvar.h b/lib/libc/include/aarch64-openbsd-none/arm64/simplebusvar.h new file mode 100644 index 0000000000..be1336cf1f --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/simplebusvar.h @@ -0,0 +1,37 @@ +/* $OpenBSD: simplebusvar.h,v 1.1 2023/09/22 01:10:43 jsg Exp $ */ +/* + * Copyright (c) 2016 Patrick Wildt + * + * 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. + */ + +struct simplebus_softc { + struct device sc_dev; + int sc_node; + bus_space_tag_t sc_iot; + bus_dma_tag_t sc_dmat; + int sc_acells; + int sc_scells; + int sc_pacells; + int sc_pscells; + struct bus_space sc_bus; + struct machine_bus_dma_tag sc_dma; + int *sc_ranges; + int sc_rangeslen; + int *sc_dmaranges; + int sc_dmarangeslen; + int sc_early; + int sc_early_nodes[64]; +}; + +extern void simplebus_attach(struct device *, struct device *, void *); \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/smbiosvar.h b/lib/libc/include/aarch64-openbsd-none/arm64/smbiosvar.h new file mode 100644 index 0000000000..5905ff3af6 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/smbiosvar.h @@ -0,0 +1,278 @@ +/* $OpenBSD: smbiosvar.h,v 1.6 2025/07/15 01:09:32 jsg Exp $ */ +/* + * Copyright (c) 2006 Gordon Willem Klok + * Copyright (c) 2005 Jordan Hargrave + * 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 AUTHORS 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 AUTHORS 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_SMBIOSVAR_ +#define _MACHINE_SMBIOSVAR_ + +#define SMBIOS_UUID_NPRESENT 0x1 +#define SMBIOS_UUID_NSET 0x2 + +/* + * Section 3.5 of "UUIDs and GUIDs" found at + * http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt + * specifies the string representation of a UUID. + */ +#define SMBIOS_UUID_REP "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" +#define SMBIOS_UUID_REPLEN 37 /* 16 zero padded values, 4 hyphens, 1 null */ + +struct smbios_entry { + uint8_t mjr; + uint8_t min; + uint8_t *addr; + uint16_t len; + uint16_t count; +}; + +struct smbhdr { + uint32_t sig; /* "_SM_" */ + uint8_t checksum; /* Entry point checksum */ + uint8_t len; /* Entry point structure length */ + uint8_t majrev; /* Specification major revision */ + uint8_t minrev; /* Specification minor revision */ + uint16_t mss; /* Maximum Structure Size */ + uint8_t epr; /* Entry Point Revision */ + uint8_t fa[5]; /* value determined by EPR */ + uint8_t sasig[5]; /* Secondary Anchor "_DMI_" */ + uint8_t sachecksum; /* Secondary Checksum */ + uint16_t size; /* Length of structure table in bytes */ + uint32_t addr; /* Structure table address */ + uint16_t count; /* Number of SMBIOS structures */ + uint8_t rev; /* BCD revision */ +} __packed; + +struct smb3hdr { + uint8_t sig[5]; /* "_SM3_" */ + uint8_t checksum; /* Entry point structure checksum */ + uint8_t len; /* Entry point length */ + uint8_t majrev; /* SMBIOS major version */ + uint8_t minrev; /* SMBIOS minor version */ + uint8_t docrev; /* SMBIOS docrev */ + uint8_t epr; /* Entry point revision */ + uint8_t reserved; /* Reserved */ + uint32_t size; /* Structure table maximum size */ + uint64_t addr; /* Structure table address */ +} __packed; + +struct smbtblhdr { + uint8_t type; + uint8_t size; + uint16_t handle; +} __packed; + +struct smbtable { + struct smbtblhdr *hdr; + void *tblhdr; + uint32_t cookie; +}; + +#define SMBIOS_TYPE_BIOS 0 +#define SMBIOS_TYPE_SYSTEM 1 +#define SMBIOS_TYPE_BASEBOARD 2 +#define SMBIOS_TYPE_ENCLOSURE 3 +#define SMBIOS_TYPE_PROCESSOR 4 +#define SMBIOS_TYPE_MEMCTRL 5 +#define SMBIOS_TYPE_MEMMOD 6 +#define SMBIOS_TYPE_CACHE 7 +#define SMBIOS_TYPE_PORT 8 +#define SMBIOS_TYPE_SLOTS 9 +#define SMBIOS_TYPE_OBD 10 +#define SMBIOS_TYPE_OEM 11 +#define SMBIOS_TYPE_SYSCONFOPT 12 +#define SMBIOS_TYPE_BIOSLANG 13 +#define SMBIOS_TYPE_GROUPASSOC 14 +#define SMBIOS_TYPE_SYSEVENTLOG 15 +#define SMBIOS_TYPE_PHYMEM 16 +#define SMBIOS_TYPE_MEMDEV 17 +#define SMBIOS_TYPE_ECCINFO32 18 +#define SMBIOS_TYPE_MEMMAPARRAYADDR 19 +#define SMBIOS_TYPE_MEMMAPDEVADDR 20 +#define SMBIOS_TYPE_INBUILTPOINT 21 +#define SMBIOS_TYPE_PORTBATT 22 +#define SMBIOS_TYPE_SYSRESET 23 +#define SMBIOS_TYPE_HWSECUIRTY 24 +#define SMBIOS_TYPE_PWRCTRL 25 +#define SMBIOS_TYPE_VOLTPROBE 26 +#define SMBIOS_TYPE_COOLING 27 +#define SMBIOS_TYPE_TEMPPROBE 28 +#define SMBIOS_TYPE_CURRENTPROBE 29 +#define SMBIOS_TYPE_OOB_REMOTEACCESS 30 +#define SMBIOS_TYPE_BIS 31 +#define SMBIOS_TYPE_SBI 32 +#define SMBIOS_TYPE_ECCINFO64 33 +#define SMBIOS_TYPE_MGMTDEV 34 +#define SMBIOS_TYPE_MGTDEVCOMP 35 +#define SMBIOS_TYPE_MGTDEVTHRESH 36 +#define SMBIOS_TYPE_MEMCHANNEL 37 +#define SMBIOS_TYPE_IPMIDEV 38 +#define SMBIOS_TYPE_SPS 39 +#define SMBIOS_TYPE_INACTIVE 126 +#define SMBIOS_TYPE_EOT 127 + +/* + * SMBIOS Structure Type 0 "BIOS Information" + * DMTF Specification DSP0134 Section: 3.3.1 p.g. 34 + */ +struct smbios_struct_bios { + uint8_t vendor; /* string */ + uint8_t version; /* string */ + uint16_t startaddr; + uint8_t release; /* string */ + uint8_t romsize; + uint64_t characteristics; + uint32_t charext; + uint8_t major_rel; + uint8_t minor_rel; + uint8_t ecf_mjr_rel; /* embedded controller firmware */ + uint8_t ecf_min_rel; /* embedded controller firmware */ +} __packed; + +/* + * SMBIOS Structure Type 1 "System Information" + * DMTF Specification DSP0134 Section 3.3.2 p.g. 35 + */ + +struct smbios_sys { +/* SMBIOS spec 2.0+ */ + uint8_t vendor; /* string */ + uint8_t product; /* string */ + uint8_t version; /* string */ + uint8_t serial; /* string */ +/* SMBIOS spec 2.1+ */ + uint8_t uuid[16]; + uint8_t wakeup; +/* SMBIOS spec 2.4+ */ + uint8_t sku; /* string */ + uint8_t family; /* string */ +} __packed; + +/* + * SMBIOS Structure Type 2 "Base Board (Module) Information" + * DMTF Specification DSP0134 Section 3.3.3 p.g. 37 + */ +struct smbios_board { + uint8_t vendor; /* string */ + uint8_t product; /* string */ + uint8_t version; /* string */ + uint8_t serial; /* string */ + uint8_t asset; /* string */ + uint8_t feature; /* feature flags */ + uint8_t location; /* location in chassis */ + uint16_t handle; /* chassis handle */ + uint8_t type; /* board type */ + uint8_t noc; /* number of contained objects */ +} __packed; + +/* + * SMBIOS Structure Type 3 "System Enclosure or Chassis" + * DMTF Specification DSP0134 + */ +struct smbios_enclosure { + /* SMBIOS spec 2.0+ */ + uint8_t vendor; /* string */ + uint8_t type; + uint8_t version; /* string */ + uint8_t serial; /* string */ + uint8_t asset_tag; /* string */ + /* SMBIOS spec 2.1+ */ + uint8_t boot_state; + uint8_t psu_state; + uint8_t thermal_state; + uint8_t security_status; + /* SMBIOS spec 2.3+ */ + uint16_t oem_defined; + uint8_t height; + uint8_t no_power_cords; + uint8_t no_contained_element; + uint8_t reclen_contained_element; + uint8_t contained_elements; + /* SMBIOS spec 2.7+ */ + uint8_t sku; /* string */ +} __packed; + +/* + * SMBIOS Structure Type 4 "processor Information" + * DMTF Specification DSP0134 v2.5 Section 3.3.5 p.g. 24 + */ +struct smbios_cpu { + uint8_t cpu_socket_designation; /* string */ + uint8_t cpu_type; + uint8_t cpu_family; + uint8_t cpu_mfg; /* string */ + uint32_t cpu_id_eax; + uint32_t cpu_id_edx; + uint8_t cpu_version; /* string */ + uint8_t cpu_voltage; + uint16_t cpu_clock; + uint16_t cpu_max_speed; + uint16_t cpu_current_speed; + uint8_t cpu_status; +#define SMBIOS_CPUST_POPULATED (1<<6) +#define SMBIOS_CPUST_STATUSMASK (0x07) + uint8_t cpu_upgrade; + uint16_t cpu_l1_handle; + uint16_t cpu_l2_handle; + uint16_t cpu_l3_handle; + uint8_t cpu_serial; /* string */ + uint8_t cpu_asset_tag; /* string */ + uint8_t cpu_part_nr; /* string */ + /* following fields were added in smbios 2.5 */ + uint8_t cpu_core_count; + uint8_t cpu_core_enabled; + uint8_t cpu_thread_count; + uint16_t cpu_characteristics; +} __packed; + +/* + * SMBIOS Structure Type 38 "IPMI Information" + * DMTF Specification DSP0134 Section 3.3.39 p.g. 91 + */ +struct smbios_ipmi { + uint8_t smipmi_if_type; /* IPMI Interface Type */ + uint8_t smipmi_if_rev; /* BCD IPMI Revision */ + uint8_t smipmi_i2c_address; /* I2C address of BMC */ + uint8_t smipmi_nvram_address; /* I2C address of NVRAM + * storage */ + uint64_t smipmi_base_address; /* Base address of BMC (BAR + * format */ + uint8_t smipmi_base_flags; /* Flags field: + * bit 7:6 : register spacing + * 00 = byte + * 01 = dword + * 02 = word + * bit 4 : Lower bit BAR + * bit 3 : IRQ valid + * bit 2 : N/A + * bit 1 : Interrupt polarity + * bit 0 : Interrupt trigger */ + uint8_t smipmi_irq; /* IRQ if applicable */ +} __packed; + +int smbios_find_table(uint8_t, struct smbtable *); +char *smbios_get_string(struct smbtable *, uint8_t, char *, size_t); + +#endif \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/spinlock.h b/lib/libc/include/aarch64-openbsd-none/arm64/spinlock.h new file mode 100644 index 0000000000..01f502df0f --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/spinlock.h @@ -0,0 +1,25 @@ +/* $OpenBSD: spinlock.h,v 1.2 2017/09/05 02:40:54 guenther Exp $ */ +/* + * Copyright (c) 2014 Patrick Wildt + * + * 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 \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/sysarch.h b/lib/libc/include/aarch64-openbsd-none/arm64/sysarch.h new file mode 100644 index 0000000000..b2b0360289 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/sysarch.h @@ -0,0 +1,21 @@ +/* $OpenBSD: sysarch.h,v 1.1 2016/12/17 23:38:33 patrick Exp $ */ +/* + * Copyright (c) 2016 Dale Rahn + * + * 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_SYSARCH_H_ + +// aarch64 architecture has no libarch or arch specific syscalls. + +#endif /* !_MACHINE_SYSARCH_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/tcb.h b/lib/libc/include/aarch64-openbsd-none/arm64/tcb.h new file mode 100644 index 0000000000..6d129af20a --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/tcb.h @@ -0,0 +1,58 @@ +/* $OpenBSD: tcb.h,v 1.2 2017/01/10 13:13:12 patrick Exp $ */ + +/* + * Copyright (c) 2011 Philip Guenther + * + * 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 + +#include + +static inline void +__aarch64_set_tcb(void *tcb) +{ + __asm volatile("msr tpidr_el0, %x0" : : "r" (tcb)); +} + +#define TCB_GET(p) \ + ((struct pcb *)(p)->p_addr)->pcb_tcb + +#define TCB_SET(p, addr) \ + do { \ + ((struct pcb *)(p)->p_addr)->pcb_tcb = (addr); \ + __aarch64_set_tcb(addr); \ + } while (0) + +#else /* _KERNEL */ + +/* ELF TLS ABI calls for small TCB, with static TLS data after it */ +#define TLS_VARIANT 1 + +static inline void * +__aarch64_read_tcb(void) +{ + void *tcb; + __asm volatile("mrs %x0, tpidr_el0": "=r" (tcb)); + return tcb; +} + +#define TCB_GET() __aarch64_read_tcb() + +#endif /* _KERNEL */ + +#endif /* _MACHINE_TCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/timetc.h b/lib/libc/include/aarch64-openbsd-none/arm64/timetc.h new file mode 100644 index 0000000000..ef326e8aca --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/timetc.h @@ -0,0 +1,24 @@ +/* $OpenBSD: timetc.h,v 1.3 2023/01/09 15:22:53 kettenis Exp $ */ +/* + * Copyright (c) 2020 Paul Irofti + * + * 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_TIMETC_H_ +#define _MACHINE_TIMETC_H_ + +#define TC_AGTIMER 1 +#define TC_AGTIMER_SUN50I 2 + +#endif /* _MACHINE_TIMETC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/vmmvar.h b/lib/libc/include/aarch64-openbsd-none/arm64/vmmvar.h new file mode 100644 index 0000000000..7d15621280 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/vmmvar.h @@ -0,0 +1,93 @@ +/* $OpenBSD: vmmvar.h,v 1.3 2025/08/03 10:17:33 tb Exp $ */ +/* + * Copyright (c) 2014 Mike Larkin + * + * 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. + */ + +/* + * CPU capabilities for VMM operation + */ +#ifndef _MACHINE_VMMVAR_H_ +#define _MACHINE_VMMVAR_H_ + +#define VMM_HV_SIGNATURE "OpenBSDVMM58" + +/* Exit Reasons */ +#define VM_EXIT_TERMINATED 0xFFFE +#define VM_EXIT_NONE 0xFFFF + +struct vmm_softc_md { + /* Capabilities */ + uint32_t nr_cpus; /* [I] */ +}; + +/* + * struct vcpu_inject_event : describes an exception or interrupt to inject. + */ +struct vcpu_inject_event { + uint8_t vie_vector; /* Exception or interrupt vector. */ + uint32_t vie_errorcode; /* Optional error code. */ + uint8_t vie_type; +#define VCPU_INJECT_NONE 0 +#define VCPU_INJECT_INTR 1 /* External hardware interrupt. */ +#define VCPU_INJECT_EX 2 /* HW or SW Exception */ +#define VCPU_INJECT_NMI 3 /* Non-maskable Interrupt */ +}; + +#define VCPU_REGS_NGPRS 31 + +struct vcpu_reg_state { + uint64_t vrs_gprs[VCPU_REGS_NGPRS]; +}; + +/* + * struct vm_exit + * + * Contains VM exit information communicated to vmd(8). This information is + * gathered by vmm(4) from the CPU on each exit that requires help from vmd. + */ +struct vm_exit { + struct vcpu_reg_state vrs; +}; + +struct vm_intr_params { + /* Input parameters to VMM_IOC_INTR */ + uint32_t vip_vm_id; + uint32_t vip_vcpu_id; + uint16_t vip_intr; +}; + +#define VM_RWREGS_GPRS 0x1 /* read/write GPRs */ +#define VM_RWREGS_ALL (VM_RWREGS_GPRS) + +struct vm_rwregs_params { + /* + * Input/output parameters to VMM_IOC_READREGS / + * VMM_IOC_WRITEREGS + */ + uint32_t vrwp_vm_id; + uint32_t vrwp_vcpu_id; + uint64_t vrwp_mask; + struct vcpu_reg_state vrwp_regs; +}; + +enum { + VEI_DIR_OUT, + VEI_DIR_IN +}; + +/* IOCTL definitions */ +#define VMM_IOC_INTR _IOW('V', 6, struct vm_intr_params) /* Intr pending */ + +#endif /* ! _MACHINE_VMMVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/arm64/vmparam.h b/lib/libc/include/aarch64-openbsd-none/arm64/vmparam.h new file mode 100644 index 0000000000..94745e8e1c --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/arm64/vmparam.h @@ -0,0 +1,108 @@ +/* $OpenBSD: vmparam.h,v 1.9 2023/04/28 18:33:22 robert Exp $ */ +/* $NetBSD: vmparam.h,v 1.1 2003/04/26 18:39:49 fvdl 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. + * + * @(#)vmparam.h 5.9 (Berkeley) 5/12/91 + */ + +#ifndef _MACHINE_VMPARAM_H_ +#define _MACHINE_VMPARAM_H_ + +/* + * Machine dependent constants for arm64. + */ + +#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)64*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 + +/* + * Kernel base + */ +#define KERNEL_BASE 0xffffff8000000000ULL + +/* + * Mach derived constants + */ + +/* user/kernel map constants */ +#define VM_MIN_ADDRESS ((vaddr_t)PAGE_SIZE) +#define USER_SPACE_BITS 39 +#define VM_MAXUSER_ADDRESS ((1ULL << USER_SPACE_BITS) - 0x8000) +#define VM_MAX_ADDRESS VM_MAXUSER_ADDRESS +#ifdef _KERNEL +#define VM_MIN_STACK_ADDRESS (3ULL << (USER_SPACE_BITS - 2)) +#endif +#define VM_MIN_KERNEL_ADDRESS ((vaddr_t)0xffffff8000000000ULL) +#define VM_MAX_KERNEL_ADDRESS ((vaddr_t)0xffffff83ffffffffULL) + +/* virtual sizes (bytes) for various kernel submaps */ +#define VM_PHYS_SIZE (USRIOSIZE*PAGE_SIZE) + +#define VM_PHYSSEG_MAX 32 +#define VM_PHYSSEG_STRAT VM_PSTRAT_BSEARCH +#define VM_PHYSSEG_NOADD /* can't add RAM after vm_mem_init */ + +#endif /* _MACHINE_VMPARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/frame.h b/lib/libc/include/aarch64-openbsd-none/frame.h new file mode 100644 index 0000000000..a169a9a1b9 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/frame.h @@ -0,0 +1,77 @@ +/* $OpenBSD: frame.h,v 1.3 2018/06/30 15:23:37 deraadt Exp $ */ +/* + * Copyright (c) 2016 Dale Rahn + * + * 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_FRAME_H_ +#define _MACHINE_FRAME_H_ + +#ifndef _LOCORE + +#include + + +/* + * Exception/Trap Stack Frame + */ +#define clockframe trapframe +typedef struct trapframe { + register_t tf_sp; + register_t tf_lr; + register_t tf_elr; + register_t tf_spsr; + register_t tf_x[30]; +} trapframe_t; + +/* + * pushed on stack for signal delivery + */ +struct sigframe { + int sf_signum; + struct sigcontext sf_sc; + siginfo_t sf_si; +}; + +/* + * System stack frames. + */ + +/* + * Stack frame inside cpu_switch() + */ + +struct switchframe { + register_t sf_x19; + register_t sf_x20; + register_t sf_x21; + register_t sf_x22; + register_t sf_x23; + register_t sf_x24; + register_t sf_x25; + register_t sf_x26; + register_t sf_x27; + register_t sf_x28; + register_t sf_x29; + register_t sf_lr; +}; + +struct callframe { + struct callframe *f_frame; + register_t f_lr; +}; + +#endif /* !_LOCORE */ + +#endif /* _MACHINE_FRAME_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/_float.h b/lib/libc/include/aarch64-openbsd-none/machine/_float.h new file mode 100644 index 0000000000..ea467e6f21 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/_float.h @@ -0,0 +1,96 @@ +/* $OpenBSD: _float.h,v 1.1 2016/12/17 23:38:33 patrick Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + */ + +#ifndef _MACHINE__FLOAT_H_ +#define _MACHINE__FLOAT_H_ + +#define __FLT_RADIX 2 /* b */ +#define __FLT_ROUNDS __flt_rounds() +#define __FLT_EVAL_METHOD 0 /* no promotions */ + +#define __FLT_MANT_DIG 24 /* p */ +#define __FLT_EPSILON 1.19209290E-7F /* b**(1-p) */ +#define __FLT_DIG 6 /* floor((p-1)*log10(b))+(b == 10) */ +#define __FLT_MIN_EXP (-125) /* emin */ +#define __FLT_MIN 1.17549435E-38F /* b**(emin-1) */ +#define __FLT_MIN_10_EXP (-37) /* ceil(log10(b**(emin-1))) */ +#define __FLT_MAX_EXP 128 /* emax */ +#define __FLT_MAX 3.40282347E+38F /* (1-b**(-p))*b**emax */ +#define __FLT_MAX_10_EXP 38 /* floor(log10((1-b**(-p))*b**emax)) */ + +#define __DBL_MANT_DIG 53 +#define __DBL_EPSILON 2.2204460492503131E-16 +#define __DBL_DIG 15 +#define __DBL_MIN_EXP (-1021) +#define __DBL_MIN 2.2250738585072014E-308 +#define __DBL_MIN_10_EXP (-307) +#define __DBL_MAX_EXP 1024 +#define __DBL_MAX 1.7976931348623157E+308 +#define __DBL_MAX_10_EXP 308 + +#ifdef __LDBL_MANT_DIG__ +#define __LDBL_MANT_DIG __LDBL_MANT_DIG__ +#define __LDBL_EPSILON __LDBL_EPSILON__ +#define __LDBL_DIG __LDBL_DIG__ +#define __LDBL_MIN_EXP __LDBL_MIN_EXP__ +#define __LDBL_MIN __LDBL_MIN__ +#define __LDBL_MIN_10_EXP __LDBL_MIN_10_EXP__ +#define __LDBL_MAX_EXP __LDBL_MAX_EXP__ +#define __LDBL_MAX __LDBL_MAX__ +#define __LDBL_MAX_10_EXP __LDBL_MAX_10_EXP__ +#else +#define __LDBL_MANT_DIG DBL_MANT_DIG +#define __LDBL_EPSILON DBL_EPSILON +#define __LDBL_DIG DBL_DIG +#define __LDBL_MIN_EXP DBL_MIN_EXP +#define __LDBL_MIN DBL_MIN +#define __LDBL_MIN_10_EXP DBL_MIN_10_EXP +#define __LDBL_MAX_EXP DBL_MAX_EXP +#define __LDBL_MAX DBL_MAX +#define __LDBL_MAX_10_EXP DBL_MAX_10_EXP +#endif + +#define __DECIMAL_DIG 17 + +#endif /* _MACHINE__FLOAT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/_types.h b/lib/libc/include/aarch64-openbsd-none/machine/_types.h new file mode 100644 index 0000000000..2de0c9d512 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/_types.h @@ -0,0 +1,145 @@ +/* $OpenBSD: _types.h,v 1.6 2023/07/02 19:02:27 cheloha 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_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/acpiapm.h b/lib/libc/include/aarch64-openbsd-none/machine/acpiapm.h new file mode 100644 index 0000000000..9664811d2b --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/acpiapm.h @@ -0,0 +1,22 @@ +/* $OpenBSD: acpiapm.h,v 1.1 2019/01/23 09:57:36 phessler Exp $ */ +/* + * Copyright (c) 2007 Ted Unangst + * + * 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. + */ + + +extern int (*acpiapm_open)(dev_t, int, int, struct proc *); +extern int (*acpiapm_close)(dev_t, int, int, struct proc *); +extern int (*acpiapm_ioctl)(dev_t, u_long, caddr_t, int, struct proc *); +extern int (*acpiapm_kqfilter)(dev_t, struct knote *); \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/apmvar.h b/lib/libc/include/aarch64-openbsd-none/machine/apmvar.h new file mode 100644 index 0000000000..f824cfe204 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/apmvar.h @@ -0,0 +1,127 @@ +/* $OpenBSD: apmvar.h,v 1.3 2023/01/22 13:14:21 kettenis Exp $ */ + +/* + * Copyright (c) 2001 Alexander Guy + * Copyright (c) 1995 John T. Kohl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef _MACHINE_APMVAR_H_ +#define _MACHINE_APMVAR_H_ + +#include + +/* Advanced Power Management (v1.0 and v1.1 specification) + * functions/defines/etc. + */ + +/* These definitions make up the heart of the user-land interface + * to the APM devices. + */ + +#define APM_AC_OFF 0x00 +#define APM_AC_ON 0x01 +#define APM_AC_BACKUP 0x02 +#define APM_AC_UNKNOWN 0xff +#define APM_BATT_HIGH 0x00 +#define APM_BATT_LOW 0x01 +#define APM_BATT_CRITICAL 0x02 +#define APM_BATT_CHARGING 0x03 +#define APM_BATT_UNKNOWN 0xff +#define APM_BATT_LIFE_UNKNOWN 0xff + +#define APM_NOEVENT 0x0000 +#define APM_STANDBY_REQ 0x0001 +#define APM_SUSPEND_REQ 0x0002 +#define APM_NORMAL_RESUME 0x0003 +#define APM_CRIT_RESUME 0x0004 /* suspend/resume happened + without us */ +#define APM_BATTERY_LOW 0x0005 +#define APM_POWER_CHANGE 0x0006 +#define APM_UPDATE_TIME 0x0007 +#define APM_CRIT_SUSPEND_REQ 0x0008 +#define APM_USER_STANDBY_REQ 0x0009 +#define APM_USER_SUSPEND_REQ 0x000A +#define APM_SYS_STANDBY_RESUME 0x000B +#define APM_CAPABILITY_CHANGE 0x000C /* apm v1.2 */ +#define APM_USER_HIBERNATE_REQ 0x000D +#define APM_EVENT_MASK 0xffff + +#define APM_EVENT_COMPOSE(t,i) ((((i) & 0x7fff) << 16)|((t) & APM_EVENT_MASK)) +#define APM_EVENT_TYPE(e) ((e) & APM_EVENT_MASK) +#define APM_EVENT_INDEX(e) ((e) >> 16) + +/* + * LP (Laptop Package) + * + * Copyright (C) 1994 by HOSOKAWA Tatsumi + * + * This software may be used, modified, copied, and distributed, in + * both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + */ + +#define APM_BATTERY_ABSENT 4 + +struct apm_power_info { + u_char battery_state; + u_char ac_state; + u_char battery_life; + u_char spare1; + u_int minutes_left; /* estimate */ + u_int spare2[6]; +}; + +struct apm_ctl { + u_int dev; + u_int mode; +}; + +#define APM_IOC_REJECT _IOW('A', 0, struct apm_event_info) /* reject request # */ +#define APM_IOC_STANDBY _IO('A', 1) /* put system into standby */ +#define APM_IOC_SUSPEND _IO('A', 2) /* put system into suspend */ +#define APM_IOC_GETPOWER _IOR('A', 3, struct apm_power_info) /* fetch battery state */ +#define APM_IOC_DEV_CTL _IOW('A', 5, struct apm_ctl) /* put device into mode */ +#define APM_IOC_PRN_CTL _IOW('A', 6, int ) /* driver power status msg */ +#define APM_PRINT_ON 0 /* driver power status displayed */ +#define APM_PRINT_OFF 1 /* driver power status not displayed */ +#define APM_PRINT_PCT 2 /* driver power status only displayed + if the percentage changes */ +#define APM_IOC_STANDBY_REQ _IO('A', 7) /* request standby */ +#define APM_IOC_SUSPEND_REQ _IO('A', 8) /* request suspend */ +#define APM_IOC_HIBERNATE _IO('A', 9) /* put system into hibernate */ + +#ifdef _KERNEL +void apm_setinfohook(int (*)(struct apm_power_info *)); +int apm_record_event(u_int); +#endif + +#endif /* _MACHINE_APMVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/armreg.h b/lib/libc/include/aarch64-openbsd-none/machine/armreg.h new file mode 100644 index 0000000000..7483ae8dd7 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/armreg.h @@ -0,0 +1,973 @@ +/* $OpenBSD: armreg.h,v 1.44 2025/07/22 09:20:41 kettenis Exp $ */ +/*- + * Copyright (c) 2013, 2014 Andrew Turner + * Copyright (c) 2015 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Andrew Turner under + * sponsorship from the FreeBSD Foundation. + * + * 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 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 AUTHOR 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. + * + * $FreeBSD: head/sys/arm64/include/armreg.h 309248 2016-11-28 14:24:07Z andrew $ + */ + +#ifndef _MACHINE_ARMREG_H_ +#define _MACHINE_ARMREG_H_ + +#define INSN_SIZE 4 + +#define READ_SPECIALREG(reg) \ +({ uint64_t val; \ + __asm volatile("mrs %0, " __STRING(reg) : "=&r" (val)); \ + val; \ +}) +#define WRITE_SPECIALREG(reg, val) \ + __asm volatile("msr " __STRING(reg) ", %0" : : "r"((uint64_t)val)) + +/* CCSIDR_EL1 - Current Cache Size ID Register */ +#define CCSIDR_SETS_MASK 0x0fffe000 +#define CCSIDR_SETS_SHIFT 13 +#define CCSIDR_SETS(reg) \ + ((((reg) & CCSIDR_SETS_MASK) >> CCSIDR_SETS_SHIFT) + 1) +#define CCSIDR_WAYS_MASK 0x00001ff8 +#define CCSIDR_WAYS_SHIFT 3 +#define CCSIDR_WAYS(reg) \ + ((((reg) & CCSIDR_WAYS_MASK) >> CCSIDR_WAYS_SHIFT) + 1) +#define CCSIDR_LINE_MASK 0x00000007 +#define CCSIDR_LINE_SIZE(reg) (1 << (((reg) & CCSIDR_LINE_MASK) + 4)) + +#define CCSIDR_CCIDX_SETS_MASK 0x00ffffff00000000ULL +#define CCSIDR_CCIDX_SETS_SHIFT 32 +#define CCSIDR_CCIDX_SETS(reg) \ + ((((reg) & CCSIDR_CCIDX_SETS_MASK) >> CCSIDR_CCIDX_SETS_SHIFT) + 1) +#define CCSIDR_CCIDX_WAYS_MASK 0x0000000000fffff8ULL +#define CCSIDR_CCIDX_WAYS_SHIFT 3 +#define CCSIDR_CCIDX_WAYS(reg) \ + ((((reg) & CCSIDR_CCIDX_WAYS_MASK) >> CCSIDR_CCIDX_WAYS_SHIFT) + 1) +#define CCSIDR_CCIDX_LINE_MASK 0x0000000000000007ULL +#define CCSIDR_CCIDX_LINE_SIZE(reg) \ + (1 << (((reg) & CCSIDR_CCIDX_LINE_MASK) + 4)) + +/* CLIDR_EL1 - Cache Level ID Register */ +#define CLIDR_CTYPE_MASK 0x7 +#define CLIDR_CTYPE_INSN 0x1 +#define CLIDR_CTYPE_DATA 0x2 +#define CLIDR_CTYPE_UNIFIED 0x4 + +/* CNTHCTL_EL2 - Counter-timer Hypervisor Control Register */ +#define CNTHCTL_EVNTI_MASK (0xf << 4) /* Bit to trigger event stream */ +#define CNTHCTL_EVNTDIR (1 << 3) /* Control transition trigger bit */ +#define CNTHCTL_EVNTEN (1 << 2) /* Enable event stream */ +#define CNTHCTL_EL1PCEN (1 << 1) /* Allow EL0/1 physical timer access */ +#define CNTHCTL_EL1PCTEN (1 << 0) /*Allow EL0/1 physical counter access*/ + +/* CNTKCTL_EL1 - Counter-timer Kernel Control Register */ +#define CNTKCTL_EL0VCTEN (1 << 1) /* Allow EL0 virtual counter access */ + +/* CNTV_CTL_EL0 */ +#define CNTV_CTL_ENABLE (1 << 0) +#define CNTV_CTL_IMASK (1 << 1) +#define CNTV_CTL_ISTATUS (1 << 2) + +/* CPACR_EL1 */ +#define CPACR_ZEN_MASK (0x3 << 16) +#define CPACR_ZEN_TRAP_ALL1 (0x0 << 16) /* Traps from EL0 and EL1 */ +#define CPACR_ZEN_TRAP_EL0 (0x1 << 16) /* Traps from EL0 */ +#define CPACR_ZEN_TRAP_ALL2 (0x2 << 16) /* Traps from EL0 and EL1 */ +#define CPACR_ZEN_TRAP_NONE (0x3 << 16) /* No traps */ +#define CPACR_FPEN_MASK (0x3 << 20) +#define CPACR_FPEN_TRAP_ALL1 (0x0 << 20) /* Traps from EL0 and EL1 */ +#define CPACR_FPEN_TRAP_EL0 (0x1 << 20) /* Traps from EL0 */ +#define CPACR_FPEN_TRAP_ALL2 (0x2 << 20) /* Traps from EL0 and EL1 */ +#define CPACR_FPEN_TRAP_NONE (0x3 << 20) /* No traps */ +#define CPACR_TTA (0x1 << 28) + +/* CSSELR_EL1 - Cache Size Selection Register */ +#define CSSELR_IND (1 << 0) +#define CSSELR_LEVEL_SHIFT 1 + +/* CTR_EL0 - Cache Type Register */ +#define CTR_DLINE_SHIFT 16 +#define CTR_DLINE_MASK (0xf << CTR_DLINE_SHIFT) +#define CTR_DLINE_SIZE(reg) (((reg) & CTR_DLINE_MASK) >> CTR_DLINE_SHIFT) +#define CTR_IL1P_SHIFT 14 +#define CTR_IL1P_MASK (0x3 << CTR_IL1P_SHIFT) +#define CTR_IL1P_AIVIVT (0x1 << CTR_IL1P_SHIFT) +#define CTR_IL1P_VIPT (0x2 << CTR_IL1P_SHIFT) +#define CTR_IL1P_PIPT (0x3 << CTR_IL1P_SHIFT) +#define CTR_ILINE_SHIFT 0 +#define CTR_ILINE_MASK (0xf << CTR_ILINE_SHIFT) +#define CTR_ILINE_SIZE(reg) (((reg) & CTR_ILINE_MASK) >> CTR_ILINE_SHIFT) + +/* MPIDR_EL1 - Multiprocessor Affinity Register */ +#define MPIDR_AFF3 (0xFFULL << 32) +#define MPIDR_AFF2 (0xFFULL << 16) +#define MPIDR_AFF1 (0xFFULL << 8) +#define MPIDR_AFF0 (0xFFULL << 0) +#define MPIDR_AFF (MPIDR_AFF3|MPIDR_AFF2|MPIDR_AFF1|MPIDR_AFF0) + +/* DCZID_EL0 - Data Cache Zero ID register */ +#define DCZID_DZP (1 << 4) /* DC ZVA prohibited if non-0 */ +#define DCZID_BS_SHIFT 0 +#define DCZID_BS_MASK (0xf << DCZID_BS_SHIFT) +#define DCZID_BS_SIZE(reg) (((reg) & DCZID_BS_MASK) >> DCZID_BS_SHIFT) + +/* ESR_ELx */ +#define ESR_ELx_ISS_MASK 0x00ffffff +#define ISS_INSN_FnV (0x01 << 10) +#define ISS_INSN_EA (0x01 << 9) +#define ISS_INSN_S1PTW (0x01 << 7) +#define ISS_INSN_IFSC_MASK (0x1f << 0) +#define ISS_DATA_ISV (0x01 << 24) +#define ISS_DATA_SAS_MASK (0x03 << 22) +#define ISS_DATA_SSE (0x01 << 21) +#define ISS_DATA_SRT_MASK (0x1f << 16) +#define ISS_DATA_SF (0x01 << 15) +#define ISS_DATA_AR (0x01 << 14) +#define ISS_DATA_FnV (0x01 << 10) +#define ISS_DATA_EA (0x01 << 9) +#define ISS_DATA_CM (0x01 << 8) +#define ISS_DATA_S1PTW (0x01 << 7) +#define ISS_DATA_WnR (0x01 << 6) +#define ISS_DATA_DFSC_MASK (0x3f << 0) +#define ISS_DATA_DFSC_ASF_L0 (0x00 << 0) +#define ISS_DATA_DFSC_ASF_L1 (0x01 << 0) +#define ISS_DATA_DFSC_ASF_L2 (0x02 << 0) +#define ISS_DATA_DFSC_ASF_L3 (0x03 << 0) +#define ISS_DATA_DFSC_TF_L0 (0x04 << 0) +#define ISS_DATA_DFSC_TF_L1 (0x05 << 0) +#define ISS_DATA_DFSC_TF_L2 (0x06 << 0) +#define ISS_DATA_DFSC_TF_L3 (0x07 << 0) +#define ISS_DATA_DFSC_AFF_L1 (0x09 << 0) +#define ISS_DATA_DFSC_AFF_L2 (0x0a << 0) +#define ISS_DATA_DFSC_AFF_L3 (0x0b << 0) +#define ISS_DATA_DFSC_PF_L1 (0x0d << 0) +#define ISS_DATA_DFSC_PF_L2 (0x0e << 0) +#define ISS_DATA_DFSC_PF_L3 (0x0f << 0) +#define ISS_DATA_DFSC_EXT (0x10 << 0) +#define ISS_DATA_DFSC_EXT_L0 (0x14 << 0) +#define ISS_DATA_DFSC_EXT_L1 (0x15 << 0) +#define ISS_DATA_DFSC_EXT_L2 (0x16 << 0) +#define ISS_DATA_DFSC_EXT_L3 (0x17 << 0) +#define ISS_DATA_DFSC_ECC (0x18 << 0) +#define ISS_DATA_DFSC_ECC_L0 (0x1c << 0) +#define ISS_DATA_DFSC_ECC_L1 (0x1d << 0) +#define ISS_DATA_DFSC_ECC_L2 (0x1e << 0) +#define ISS_DATA_DFSC_ECC_L3 (0x1f << 0) +#define ISS_DATA_DFSC_ALIGN (0x21 << 0) +#define ISS_DATA_DFSC_TLB_CONFLICT (0x30 << 0) +#define ISS_MSR_DIR_SHIFT 0 +#define ISS_MSR_DIR (0x01 << ISS_MSR_DIR_SHIFT) +#define ISS_MSR_Rt_SHIFT 5 +#define ISS_MSR_Rt_MASK (0x1f << ISS_MSR_Rt_SHIFT) +#define ISS_MSR_Rt(x) (((x) & ISS_MSR_Rt_MASK) >> ISS_MSR_Rt_SHIFT) +#define ISS_MSR_CRm_SHIFT 1 +#define ISS_MSR_CRm_MASK (0xf << ISS_MSR_CRm_SHIFT) +#define ISS_MSR_CRm(x) (((x) & ISS_MSR_CRm_MASK) >> ISS_MSR_CRm_SHIFT) +#define ISS_MSR_CRn_SHIFT 10 +#define ISS_MSR_CRn_MASK (0xf << ISS_MSR_CRn_SHIFT) +#define ISS_MSR_CRn(x) (((x) & ISS_MSR_CRn_MASK) >> ISS_MSR_CRn_SHIFT) +#define ISS_MSR_OP1_SHIFT 14 +#define ISS_MSR_OP1_MASK (0x7 << ISS_MSR_OP1_SHIFT) +#define ISS_MSR_OP1(x) (((x) & ISS_MSR_OP1_MASK) >> ISS_MSR_OP1_SHIFT) +#define ISS_MSR_OP2_SHIFT 17 +#define ISS_MSR_OP2_MASK (0x7 << ISS_MSR_OP2_SHIFT) +#define ISS_MSR_OP2(x) (((x) & ISS_MSR_OP2_MASK) >> ISS_MSR_OP2_SHIFT) +#define ISS_MSR_OP0_SHIFT 20 +#define ISS_MSR_OP0_MASK (0x3 << ISS_MSR_OP0_SHIFT) +#define ISS_MSR_OP0(x) (((x) & ISS_MSR_OP0_MASK) >> ISS_MSR_OP0_SHIFT) +#define ISS_BRK_COMMENT_MASK 0xffff +#define ESR_ELx_IL (0x01 << 25) +#define ESR_ELx_EC_SHIFT 26 +#define ESR_ELx_EC_MASK (0x3f << 26) +#define ESR_ELx_EXCEPTION(esr) (((esr) & ESR_ELx_EC_MASK) >> ESR_ELx_EC_SHIFT) +#define EXCP_UNKNOWN 0x00 /* Unkwn exception */ +#define EXCP_FP_SIMD 0x07 /* FP/SIMD trap */ +#define EXCP_BRANCH_TGT 0x0d /* Branch target exception */ +#define EXCP_ILL_STATE 0x0e /* Illegal execution state */ +#define EXCP_SVC 0x15 /* SVC trap */ +#define EXCP_MSR 0x18 /* MSR/MRS trap */ +#define EXCP_SVE 0x19 /* SVE trap */ +#define EXCP_FPAC 0x1c /* Faulting PAC trap */ +#define EXCP_INSN_ABORT_L 0x20 /* Instruction abort, from lower EL */ +#define EXCP_INSN_ABORT 0x21 /* Instruction abort, from same EL */ +#define EXCP_PC_ALIGN 0x22 /* PC alignment fault */ +#define EXCP_DATA_ABORT_L 0x24 /* Data abort, from lower EL */ +#define EXCP_DATA_ABORT 0x25 /* Data abort, from same EL */ +#define EXCP_SP_ALIGN 0x26 /* SP alignment fault */ +#define EXCP_TRAP_FP 0x2c /* Trapped FP exception */ +#define EXCP_SERROR 0x2f /* SError interrupt */ +#define EXCP_SOFTSTP_EL0 0x32 /* Software Step, from lower EL */ +#define EXCP_SOFTSTP_EL1 0x33 /* Software Step, from same EL */ +#define EXCP_WATCHPT_EL1 0x35 /* Watchpoint, from same EL */ +#define EXCP_BRK 0x3c /* Breakpoint */ + +/* ICC_CTLR_EL1 */ +#define ICC_CTLR_EL1_EOIMODE (1U << 1) +#define ICC_CTLR_EL1_PRIBITS_SHIFT 8 +#define ICC_CTLR_EL1_PRIBITS_MASK (0x7UL << 8) +#define ICC_CTLR_EL1_PRIBITS(reg) \ + (((reg) & ICC_CTLR_EL1_PRIBITS_MASK) >> ICC_CTLR_EL1_PRIBITS_SHIFT) + +/* ICC_IAR1_EL1 */ +#define ICC_IAR1_EL1_SPUR (0x03ff) + +/* ICC_IGRPEN0_EL1 */ +#define ICC_IGRPEN0_EL1_EN (1U << 0) + +/* ICC_PMR_EL1 */ +#define ICC_PMR_EL1_PRIO_MASK (0xFFUL) + +/* ICC_SGI1R_EL1 */ +#define ICC_SGI1R_EL1_TL_MASK 0xffffUL +#define ICC_SGI1R_EL1_AFF1_SHIFT 16 +#define ICC_SGI1R_EL1_SGIID_SHIFT 24 +#define ICC_SGI1R_EL1_AFF2_SHIFT 32 +#define ICC_SGI1R_EL1_AFF3_SHIFT 48 +#define ICC_SGI1R_EL1_SGIID_MASK 0xfUL +#define ICC_SGI1R_EL1_IRM (0x1UL << 40) + +/* ICC_SRE_EL1 */ +#define ICC_SRE_EL1_SRE (1U << 0) + +/* ICC_SRE_EL2 */ +#define ICC_SRE_EL2_SRE (1U << 0) +#define ICC_SRE_EL2_EN (1U << 3) + +/* ID_AA64DFR0_EL1 */ +#define ID_AA64DFR0_MASK 0x00000000f0f0ffffUL +#define ID_AA64DFR0_DEBUG_VER_SHIFT 0 +#define ID_AA64DFR0_DEBUG_VER_MASK (0xfULL << ID_AA64DFR0_DEBUG_VER_SHIFT) +#define ID_AA64DFR0_DEBUG_VER(x) ((x) & ID_AA64DFR0_DEBUG_VER_MASK) +#define ID_AA64DFR0_DEBUG_VER_8 (0x6ULL << ID_AA64DFR0_DEBUG_VER_SHIFT) +#define ID_AA64DFR0_DEBUG_VER_8_VHE (0x7ULL << ID_AA64DFR0_DEBUG_VER_SHIFT) +#define ID_AA64DFR0_TRACE_VER_SHIFT 4 +#define ID_AA64DFR0_TRACE_VER_MASK (0xfULL << ID_AA64DFR0_TRACE_VER_SHIFT) +#define ID_AA64DFR0_TRACE_VER(x) ((x) & ID_AA64DFR0_TRACE_VER_MASK) +#define ID_AA64DFR0_TRACE_VER_NONE (0x0ULL << ID_AA64DFR0_TRACE_VER_SHIFT) +#define ID_AA64DFR0_TRACE_VER_IMPL (0x1ULL << ID_AA64DFR0_TRACE_VER_SHIFT) +#define ID_AA64DFR0_PMU_VER_SHIFT 8 +#define ID_AA64DFR0_PMU_VER_MASK (0xfULL << ID_AA64DFR0_PMU_VER_SHIFT) +#define ID_AA64DFR0_PMU_VER(x) ((x) & ID_AA64DFR0_PMU_VER_MASK) +#define ID_AA64DFR0_PMU_VER_NONE (0x0ULL << ID_AA64DFR0_PMU_VER_SHIFT) +#define ID_AA64DFR0_PMU_VER_3 (0x1ULL << ID_AA64DFR0_PMU_VER_SHIFT) +#define ID_AA64DFR0_PMU_VER_3_1 (0x4ULL << ID_AA64DFR0_PMU_VER_SHIFT) +#define ID_AA64DFR0_PMU_VER_IMPL (0xfULL << ID_AA64DFR0_PMU_VER_SHIFT) +#define ID_AA64DFR0_BRPS_SHIFT 12 +#define ID_AA64DFR0_BRPS_MASK (0xfULL << ID_AA64DFR0_BRPS_SHIFT) +#define ID_AA64DFR0_BRPS(x) \ + ((((x) >> ID_AA64DFR0_BRPS_SHIFT) & 0xf) + 1) +#define ID_AA64DFR0_WRPS_SHIFT 20 +#define ID_AA64DFR0_WRPS_MASK (0xfULL << ID_AA64DFR0_WRPS_SHIFT) +#define ID_AA64DFR0_WRPS(x) \ + ((((x) >> ID_AA64DFR0_WRPS_SHIFT) & 0xf) + 1) +#define ID_AA64DFR0_CTX_CMPS_SHIFT 28 +#define ID_AA64DFR0_CTX_CMPS_MASK (0xfULL << ID_AA64DFR0_CTX_CMPS_SHIFT) +#define ID_AA64DFR0_CTX_CMPS(x) \ + ((((x) >> ID_AA64DFR0_CTX_CMPS_SHIFT) & 0xf) + 1) + +/* ID_AA64ISAR0_EL1 */ +#define ID_AA64ISAR0_MASK 0xfffffffff0fffff0ULL +#define ID_AA64ISAR0_AES_SHIFT 4 +#define ID_AA64ISAR0_AES_MASK (0xfULL << ID_AA64ISAR0_AES_SHIFT) +#define ID_AA64ISAR0_AES(x) ((x) & ID_AA64ISAR0_AES_MASK) +#define ID_AA64ISAR0_AES_NONE (0x0ULL << ID_AA64ISAR0_AES_SHIFT) +#define ID_AA64ISAR0_AES_BASE (0x1ULL << ID_AA64ISAR0_AES_SHIFT) +#define ID_AA64ISAR0_AES_PMULL (0x2ULL << ID_AA64ISAR0_AES_SHIFT) +#define ID_AA64ISAR0_SHA1_SHIFT 8 +#define ID_AA64ISAR0_SHA1_MASK (0xfULL << ID_AA64ISAR0_SHA1_SHIFT) +#define ID_AA64ISAR0_SHA1(x) ((x) & ID_AA64ISAR0_SHA1_MASK) +#define ID_AA64ISAR0_SHA1_NONE (0x0ULL << ID_AA64ISAR0_SHA1_SHIFT) +#define ID_AA64ISAR0_SHA1_BASE (0x1ULL << ID_AA64ISAR0_SHA1_SHIFT) +#define ID_AA64ISAR0_SHA2_SHIFT 12 +#define ID_AA64ISAR0_SHA2_MASK (0xfULL << ID_AA64ISAR0_SHA2_SHIFT) +#define ID_AA64ISAR0_SHA2(x) ((x) & ID_AA64ISAR0_SHA2_MASK) +#define ID_AA64ISAR0_SHA2_NONE (0x0ULL << ID_AA64ISAR0_SHA2_SHIFT) +#define ID_AA64ISAR0_SHA2_BASE (0x1ULL << ID_AA64ISAR0_SHA2_SHIFT) +#define ID_AA64ISAR0_SHA2_512 (0x2ULL << ID_AA64ISAR0_SHA2_SHIFT) +#define ID_AA64ISAR0_CRC32_SHIFT 16 +#define ID_AA64ISAR0_CRC32_MASK (0xfULL << ID_AA64ISAR0_CRC32_SHIFT) +#define ID_AA64ISAR0_CRC32(x) ((x) & ID_AA64ISAR0_CRC32_MASK) +#define ID_AA64ISAR0_CRC32_NONE (0x0ULL << ID_AA64ISAR0_CRC32_SHIFT) +#define ID_AA64ISAR0_CRC32_BASE (0x1ULL << ID_AA64ISAR0_CRC32_SHIFT) +#define ID_AA64ISAR0_ATOMIC_SHIFT 20 +#define ID_AA64ISAR0_ATOMIC_MASK (0xfULL << ID_AA64ISAR0_ATOMIC_SHIFT) +#define ID_AA64ISAR0_ATOMIC(x) ((x) & ID_AA64ISAR0_ATOMIC_MASK) +#define ID_AA64ISAR0_ATOMIC_NONE (0x0ULL << ID_AA64ISAR0_ATOMIC_SHIFT) +#define ID_AA64ISAR0_ATOMIC_IMPL (0x2ULL << ID_AA64ISAR0_ATOMIC_SHIFT) +#define ID_AA64ISAR0_RDM_SHIFT 28 +#define ID_AA64ISAR0_RDM_MASK (0xfULL << ID_AA64ISAR0_RDM_SHIFT) +#define ID_AA64ISAR0_RDM(x) ((x) & ID_AA64ISAR0_RDM_MASK) +#define ID_AA64ISAR0_RDM_NONE (0x0ULL << ID_AA64ISAR0_RDM_SHIFT) +#define ID_AA64ISAR0_RDM_IMPL (0x1ULL << ID_AA64ISAR0_RDM_SHIFT) +#define ID_AA64ISAR0_SHA3_SHIFT 32 +#define ID_AA64ISAR0_SHA3_MASK (0xfULL << ID_AA64ISAR0_SHA3_SHIFT) +#define ID_AA64ISAR0_SHA3(x) ((x) & ID_AA64ISAR0_SHA3_MASK) +#define ID_AA64ISAR0_SHA3_NONE (0x0ULL << ID_AA64ISAR0_SHA3_SHIFT) +#define ID_AA64ISAR0_SHA3_IMPL (0x1ULL << ID_AA64ISAR0_SHA3_SHIFT) +#define ID_AA64ISAR0_SM3_SHIFT 36 +#define ID_AA64ISAR0_SM3_MASK (0xfULL << ID_AA64ISAR0_SM3_SHIFT) +#define ID_AA64ISAR0_SM3(x) ((x) & ID_AA64ISAR0_SM3_MASK) +#define ID_AA64ISAR0_SM3_NONE (0x0ULL << ID_AA64ISAR0_SM3_SHIFT) +#define ID_AA64ISAR0_SM3_IMPL (0x1ULL << ID_AA64ISAR0_SM3_SHIFT) +#define ID_AA64ISAR0_SM4_SHIFT 40 +#define ID_AA64ISAR0_SM4_MASK (0xfULL << ID_AA64ISAR0_SM4_SHIFT) +#define ID_AA64ISAR0_SM4(x) ((x) & ID_AA64ISAR0_SM4_MASK) +#define ID_AA64ISAR0_SM4_NONE (0x0ULL << ID_AA64ISAR0_SM4_SHIFT) +#define ID_AA64ISAR0_SM4_IMPL (0x1ULL << ID_AA64ISAR0_SM4_SHIFT) +#define ID_AA64ISAR0_DP_SHIFT 44 +#define ID_AA64ISAR0_DP_MASK (0xfULL << ID_AA64ISAR0_DP_SHIFT) +#define ID_AA64ISAR0_DP(x) ((x) & ID_AA64ISAR0_DP_MASK) +#define ID_AA64ISAR0_DP_NONE (0x0ULL << ID_AA64ISAR0_DP_SHIFT) +#define ID_AA64ISAR0_DP_IMPL (0x1ULL << ID_AA64ISAR0_DP_SHIFT) +#define ID_AA64ISAR0_FHM_SHIFT 48 +#define ID_AA64ISAR0_FHM_MASK (0xfULL << ID_AA64ISAR0_FHM_SHIFT) +#define ID_AA64ISAR0_FHM(x) ((x) & ID_AA64ISAR0_FHM_MASK) +#define ID_AA64ISAR0_FHM_NONE (0x0ULL << ID_AA64ISAR0_FHM_SHIFT) +#define ID_AA64ISAR0_FHM_IMPL (0x1ULL << ID_AA64ISAR0_FHM_SHIFT) +#define ID_AA64ISAR0_TS_SHIFT 52 +#define ID_AA64ISAR0_TS_MASK (0xfULL << ID_AA64ISAR0_TS_SHIFT) +#define ID_AA64ISAR0_TS(x) ((x) & ID_AA64ISAR0_TS_MASK) +#define ID_AA64ISAR0_TS_NONE (0x0ULL << ID_AA64ISAR0_TS_SHIFT) +#define ID_AA64ISAR0_TS_BASE (0x1ULL << ID_AA64ISAR0_TS_SHIFT) +#define ID_AA64ISAR0_TS_AXFLAG (0x2ULL << ID_AA64ISAR0_TS_SHIFT) +#define ID_AA64ISAR0_TLB_SHIFT 56 +#define ID_AA64ISAR0_TLB_MASK (0xfULL << ID_AA64ISAR0_TLB_SHIFT) +#define ID_AA64ISAR0_TLB(x) ((x) & ID_AA64ISAR0_TLB_MASK) +#define ID_AA64ISAR0_TLB_NONE (0x0ULL << ID_AA64ISAR0_TLB_SHIFT) +#define ID_AA64ISAR0_TLB_IOS (0x1ULL << ID_AA64ISAR0_TLB_SHIFT) +#define ID_AA64ISAR0_TLB_IRANGE (0x2ULL << ID_AA64ISAR0_TLB_SHIFT) +#define ID_AA64ISAR0_RNDR_SHIFT 60 +#define ID_AA64ISAR0_RNDR_MASK (0xfULL << ID_AA64ISAR0_RNDR_SHIFT) +#define ID_AA64ISAR0_RNDR(x) ((x) & ID_AA64ISAR0_RNDR_MASK) +#define ID_AA64ISAR0_RNDR_NONE (0x0ULL << ID_AA64ISAR0_RNDR_SHIFT) +#define ID_AA64ISAR0_RNDR_IMPL (0x1ULL << ID_AA64ISAR0_RNDR_SHIFT) + +/* ID_AA64ISAR1_EL1 */ +#define ID_AA64ISAR1_MASK 0xffffffffffffffffULL +#define ID_AA64ISAR1_DPB_SHIFT 0 +#define ID_AA64ISAR1_DPB_MASK (0xfULL << ID_AA64ISAR1_DPB_SHIFT) +#define ID_AA64ISAR1_DPB(x) ((x) & ID_AA64ISAR1_DPB_MASK) +#define ID_AA64ISAR1_DPB_NONE (0x0ULL << ID_AA64ISAR1_DPB_SHIFT) +#define ID_AA64ISAR1_DPB_IMPL (0x1ULL << ID_AA64ISAR1_DPB_SHIFT) +#define ID_AA64ISAR1_DPB_DCCVADP (0x2ULL << ID_AA64ISAR1_DPB_SHIFT) +#define ID_AA64ISAR1_APA_SHIFT 4 +#define ID_AA64ISAR1_APA_MASK (0xfULL << ID_AA64ISAR1_APA_SHIFT) +#define ID_AA64ISAR1_APA(x) ((x) & ID_AA64ISAR1_APA_MASK) +#define ID_AA64ISAR1_APA_NONE (0x0ULL << ID_AA64ISAR1_APA_SHIFT) +#define ID_AA64ISAR1_APA_PAC (0x1ULL << ID_AA64ISAR1_APA_SHIFT) +#define ID_AA64ISAR1_APA_EPAC (0x2ULL << ID_AA64ISAR1_APA_SHIFT) +#define ID_AA64ISAR1_APA_EPAC2 (0x3ULL << ID_AA64ISAR1_APA_SHIFT) +#define ID_AA64ISAR1_APA_FPAC (0x4ULL << ID_AA64ISAR1_APA_SHIFT) +#define ID_AA64ISAR1_APA_FPAC_COMBINED (0x5ULL << ID_AA64ISAR1_APA_SHIFT) +#define ID_AA64ISAR1_API_SHIFT 8 +#define ID_AA64ISAR1_API_MASK (0xfULL << ID_AA64ISAR1_API_SHIFT) +#define ID_AA64ISAR1_API(x) ((x) & ID_AA64ISAR1_API_MASK) +#define ID_AA64ISAR1_API_NONE (0x0ULL << ID_AA64ISAR1_API_SHIFT) +#define ID_AA64ISAR1_API_PAC (0x1ULL << ID_AA64ISAR1_API_SHIFT) +#define ID_AA64ISAR1_API_EPAC (0x2ULL << ID_AA64ISAR1_API_SHIFT) +#define ID_AA64ISAR1_API_EPAC2 (0x3ULL << ID_AA64ISAR1_API_SHIFT) +#define ID_AA64ISAR1_API_FPAC (0x4ULL << ID_AA64ISAR1_API_SHIFT) +#define ID_AA64ISAR1_API_FPAC_COMBINED (0x5ULL << ID_AA64ISAR1_API_SHIFT) +#define ID_AA64ISAR1_JSCVT_SHIFT 12 +#define ID_AA64ISAR1_JSCVT_MASK (0xfULL << ID_AA64ISAR1_JSCVT_SHIFT) +#define ID_AA64ISAR1_JSCVT(x) ((x) & ID_AA64ISAR1_JSCVT_MASK) +#define ID_AA64ISAR1_JSCVT_NONE (0x0ULL << ID_AA64ISAR1_JSCVT_SHIFT) +#define ID_AA64ISAR1_JSCVT_IMPL (0x1ULL << ID_AA64ISAR1_JSCVT_SHIFT) +#define ID_AA64ISAR1_FCMA_SHIFT 16 +#define ID_AA64ISAR1_FCMA_MASK (0xfULL << ID_AA64ISAR1_FCMA_SHIFT) +#define ID_AA64ISAR1_FCMA(x) ((x) & ID_AA64ISAR1_FCMA_MASK) +#define ID_AA64ISAR1_FCMA_NONE (0x0ULL << ID_AA64ISAR1_FCMA_SHIFT) +#define ID_AA64ISAR1_FCMA_IMPL (0x1ULL << ID_AA64ISAR1_FCMA_SHIFT) +#define ID_AA64ISAR1_LRCPC_SHIFT 20 +#define ID_AA64ISAR1_LRCPC_MASK (0xfULL << ID_AA64ISAR1_LRCPC_SHIFT) +#define ID_AA64ISAR1_LRCPC(x) ((x) & ID_AA64ISAR1_LRCPC_MASK) +#define ID_AA64ISAR1_LRCPC_NONE (0x0ULL << ID_AA64ISAR1_LRCPC_SHIFT) +#define ID_AA64ISAR1_LRCPC_BASE (0x1ULL << ID_AA64ISAR1_LRCPC_SHIFT) +#define ID_AA64ISAR1_LRCPC_LDAPUR (0x2ULL << ID_AA64ISAR1_LRCPC_SHIFT) +#define ID_AA64ISAR1_GPA_SHIFT 24 +#define ID_AA64ISAR1_GPA_MASK (0xfULL << ID_AA64ISAR1_GPA_SHIFT) +#define ID_AA64ISAR1_GPA(x) ((x) & ID_AA64ISAR1_GPA_MASK) +#define ID_AA64ISAR1_GPA_NONE (0x0ULL << ID_AA64ISAR1_GPA_SHIFT) +#define ID_AA64ISAR1_GPA_IMPL (0x1ULL << ID_AA64ISAR1_GPA_SHIFT) +#define ID_AA64ISAR1_GPI_SHIFT 28 +#define ID_AA64ISAR1_GPI_MASK (0xfULL << ID_AA64ISAR1_GPI_SHIFT) +#define ID_AA64ISAR1_GPI(x) ((x) & ID_AA64ISAR1_GPI_MASK) +#define ID_AA64ISAR1_GPI_NONE (0x0ULL << ID_AA64ISAR1_GPI_SHIFT) +#define ID_AA64ISAR1_GPI_IMPL (0x1ULL << ID_AA64ISAR1_GPI_SHIFT) +#define ID_AA64ISAR1_FRINTTS_SHIFT 32 +#define ID_AA64ISAR1_FRINTTS_MASK (0xfULL << ID_AA64ISAR1_FRINTTS_SHIFT) +#define ID_AA64ISAR1_FRINTTS(x) ((x) & ID_AA64ISAR1_FRINTTS_MASK) +#define ID_AA64ISAR1_FRINTTS_NONE (0x0ULL << ID_AA64ISAR1_FRINTTS_SHIFT) +#define ID_AA64ISAR1_FRINTTS_IMPL (0x1ULL << ID_AA64ISAR1_FRINTTS_SHIFT) +#define ID_AA64ISAR1_SB_SHIFT 36 +#define ID_AA64ISAR1_SB_MASK (0xfULL << ID_AA64ISAR1_SB_SHIFT) +#define ID_AA64ISAR1_SB(x) ((x) & ID_AA64ISAR1_SB_MASK) +#define ID_AA64ISAR1_SB_NONE (0x0ULL << ID_AA64ISAR1_SB_SHIFT) +#define ID_AA64ISAR1_SB_IMPL (0x1ULL << ID_AA64ISAR1_SB_SHIFT) +#define ID_AA64ISAR1_SPECRES_SHIFT 40 +#define ID_AA64ISAR1_SPECRES_MASK (0xfULL << ID_AA64ISAR1_SPECRES_SHIFT) +#define ID_AA64ISAR1_SPECRES(x) ((x) & ID_AA64ISAR1_SPECRES_MASK) +#define ID_AA64ISAR1_SPECRES_NONE (0x0ULL << ID_AA64ISAR1_SPECRES_SHIFT) +#define ID_AA64ISAR1_SPECRES_IMPL (0x1ULL << ID_AA64ISAR1_SPECRES_SHIFT) +#define ID_AA64ISAR1_BF16_SHIFT 44 +#define ID_AA64ISAR1_BF16_MASK (0xfULL << ID_AA64ISAR1_BF16_SHIFT) +#define ID_AA64ISAR1_BF16(x) ((x) & ID_AA64ISAR1_BF16_MASK) +#define ID_AA64ISAR1_BF16_NONE (0x0ULL << ID_AA64ISAR1_BF16_SHIFT) +#define ID_AA64ISAR1_BF16_BASE (0x1ULL << ID_AA64ISAR1_BF16_SHIFT) +#define ID_AA64ISAR1_BF16_EBF (0x2ULL << ID_AA64ISAR1_BF16_SHIFT) +#define ID_AA64ISAR1_DGH_SHIFT 48 +#define ID_AA64ISAR1_DGH_MASK (0xfULL << ID_AA64ISAR1_DGH_SHIFT) +#define ID_AA64ISAR1_DGH(x) ((x) & ID_AA64ISAR1_DGH_MASK) +#define ID_AA64ISAR1_DGH_NONE (0x0ULL << ID_AA64ISAR1_DGH_SHIFT) +#define ID_AA64ISAR1_DGH_IMPL (0x1ULL << ID_AA64ISAR1_DGH_SHIFT) +#define ID_AA64ISAR1_I8MM_SHIFT 52 +#define ID_AA64ISAR1_I8MM_MASK (0xfULL << ID_AA64ISAR1_I8MM_SHIFT) +#define ID_AA64ISAR1_I8MM(x) ((x) & ID_AA64ISAR1_I8MM_MASK) +#define ID_AA64ISAR1_I8MM_NONE (0x0ULL << ID_AA64ISAR1_I8MM_SHIFT) +#define ID_AA64ISAR1_I8MM_IMPL (0x1ULL << ID_AA64ISAR1_I8MM_SHIFT) +#define ID_AA64ISAR1_XS_SHIFT 56 +#define ID_AA64ISAR1_XS_MASK (0xfULL << ID_AA64ISAR1_XS_SHIFT) +#define ID_AA64ISAR1_XS(x) ((x) & ID_AA64ISAR1_XS_MASK) +#define ID_AA64ISAR1_XS_NONE (0x0ULL << ID_AA64ISAR1_XS_SHIFT) +#define ID_AA64ISAR1_XS_IMPL (0x1ULL << ID_AA64ISAR1_XS_SHIFT) +#define ID_AA64ISAR1_LS64_SHIFT 60 +#define ID_AA64ISAR1_LS64_MASK (0xfULL << ID_AA64ISAR1_LS64_SHIFT) +#define ID_AA64ISAR1_LS64(x) ((x) & ID_AA64ISAR1_LS64_MASK) +#define ID_AA64ISAR1_LS64_NONE (0x0ULL << ID_AA64ISAR1_LS64_SHIFT) +#define ID_AA64ISAR1_LS64_BASE (0x1ULL << ID_AA64ISAR1_LS64_SHIFT) +#define ID_AA64ISAR1_LS64_V (0x2ULL << ID_AA64ISAR1_LS64_SHIFT) +#define ID_AA64ISAR1_LS64_ACCDATA (0x3ULL << ID_AA64ISAR1_LS64_SHIFT) + +/* ID_AA64ISAR2_EL1 */ +#define ID_AA64ISAR2_MASK 0x00ff0000f0ffffffULL +#define ID_AA64ISAR2_WFXT_SHIFT 0 +#define ID_AA64ISAR2_WFXT_MASK (0xfULL << ID_AA64ISAR2_WFXT_SHIFT) +#define ID_AA64ISAR2_WFXT(x) ((x) & ID_AA64ISAR2_WFXT_MASK) +#define ID_AA64ISAR2_WFXT_NONE (0x0ULL << ID_AA64ISAR2_WFXT_SHIFT) +#define ID_AA64ISAR2_WFXT_IMPL (0x2ULL << ID_AA64ISAR2_WFXT_SHIFT) +#define ID_AA64ISAR2_RPRES_SHIFT 4 +#define ID_AA64ISAR2_RPRES_MASK (0xfULL << ID_AA64ISAR2_RPRES_SHIFT) +#define ID_AA64ISAR2_RPRES(x) ((x) & ID_AA64ISAR2_RPRES_MASK) +#define ID_AA64ISAR2_RPRES_NONE (0x0ULL << ID_AA64ISAR2_RPRES_SHIFT) +#define ID_AA64ISAR2_RPRES_IMPL (0x1ULL << ID_AA64ISAR2_RPRES_SHIFT) +#define ID_AA64ISAR2_GPA3_SHIFT 8 +#define ID_AA64ISAR2_GPA3_WIDTH 4 +#define ID_AA64ISAR2_GPA3_MASK (0xfULL << ID_AA64ISAR2_GPA3_SHIFT) +#define ID_AA64ISAR2_GPA3(x) ((x) & ID_AA64ISAR2_GPA3_MASK) +#define ID_AA64ISAR2_GPA3_NONE (0x0ULL << ID_AA64ISAR2_GPA3_SHIFT) +#define ID_AA64ISAR2_GPA3_IMPL (0x1ULL << ID_AA64ISAR2_GPA3_SHIFT) +#define ID_AA64ISAR2_APA3_SHIFT 12 +#define ID_AA64ISAR2_APA3_WIDTH 4 +#define ID_AA64ISAR2_APA3_MASK (0xfULL << ID_AA64ISAR2_APA3_SHIFT) +#define ID_AA64ISAR2_APA3(x) ((x) & ID_AA64ISAR2_APA3_MASK) +#define ID_AA64ISAR2_APA3_NONE (0x0ULL << ID_AA64ISAR2_APA3_SHIFT) +#define ID_AA64ISAR2_APA3_PAC (0x1ULL << ID_AA64ISAR2_APA3_SHIFT) +#define ID_AA64ISAR2_APA3_EPAC (0x2ULL << ID_AA64ISAR2_APA3_SHIFT) +#define ID_AA64ISAR2_APA3_EPAC2 (0x3ULL << ID_AA64ISAR2_APA3_SHIFT) +#define ID_AA64ISAR2_APA3_FPAC (0x4ULL << ID_AA64ISAR2_APA3_SHIFT) +#define ID_AA64ISAR2_APA3_FPAC_COMBINED (0x5ULL << ID_AA64ISAR2_APA3_SHIFT) +#define ID_AA64ISAR2_MOPS_SHIFT 16 +#define ID_AA64ISAR2_MOPS_MASK (0xfULL << ID_AA64ISAR2_MOPS_SHIFT) +#define ID_AA64ISAR2_MOPS(x) ((x) & ID_AA64ISAR2_MOPS_MASK) +#define ID_AA64ISAR2_MOPS_NONE (0x0ULL << ID_AA64ISAR2_MOPS_SHIFT) +#define ID_AA64ISAR2_MOPS_IMPL (0x1ULL << ID_AA64ISAR2_MOPS_SHIFT) +#define ID_AA64ISAR2_BC_SHIFT 20 +#define ID_AA64ISAR2_BC_MASK (0xfULL << ID_AA64ISAR2_BC_SHIFT) +#define ID_AA64ISAR2_BC(x) ((x) & ID_AA64ISAR2_BC_MASK) +#define ID_AA64ISAR2_BC_NONE (0x0ULL << ID_AA64ISAR2_BC_SHIFT) +#define ID_AA64ISAR2_BC_IMPL (0x1ULL << ID_AA64ISAR2_BC_SHIFT) +#define ID_AA64ISAR2_CLRBHB_SHIFT 28 +#define ID_AA64ISAR2_CLRBHB_MASK (0xfULL << ID_AA64ISAR2_CLRBHB_SHIFT) +#define ID_AA64ISAR2_CLRBHB(x) ((x) & ID_AA64ISAR2_CLRBHB_MASK) +#define ID_AA64ISAR2_CLRBHB_NONE (0x0ULL << ID_AA64ISAR2_CLRBHB_SHIFT) +#define ID_AA64ISAR2_CLRBHB_IMPL (0x1ULL << ID_AA64ISAR2_CLRBHB_SHIFT) +#define ID_AA64ISAR2_RPRFM_SHIFT 48 +#define ID_AA64ISAR2_RPRFM_MASK (0xfULL << ID_AA64ISAR2_RPRFM_SHIFT) +#define ID_AA64ISAR2_RPRFM(x) ((x) & ID_AA64ISAR2_RPRFM_MASK) +#define ID_AA64ISAR2_RPRFM_NONE (0x0ULL << ID_AA64ISAR2_RPRFM_SHIFT) +#define ID_AA64ISAR2_RPRFM_IMPL (0x1ULL << ID_AA64ISAR2_RPRFM_SHIFT) +#define ID_AA64ISAR2_CSSC_SHIFT 52 +#define ID_AA64ISAR2_CSSC_MASK (0xfULL << ID_AA64ISAR2_CSSC_SHIFT) +#define ID_AA64ISAR2_CSSC(x) ((x) & ID_AA64ISAR2_CSSC_MASK) +#define ID_AA64ISAR2_CSSC_NONE (0x0ULL << ID_AA64ISAR2_CSSC_SHIFT) +#define ID_AA64ISAR2_CSSC_IMPL (0x1ULL << ID_AA64ISAR2_CSSC_SHIFT) + +/* ID_AA64MMFR0_EL1 */ +#define ID_AA64MMFR0_MASK 0xf0000000ffffffffULL +#define ID_AA64MMFR0_PA_RANGE_SHIFT 0 +#define ID_AA64MMFR0_PA_RANGE_MASK (0xfULL << ID_AA64MMFR0_PA_RANGE_SHIFT) +#define ID_AA64MMFR0_PA_RANGE(x) ((x) & ID_AA64MMFR0_PA_RANGE_MASK) +#define ID_AA64MMFR0_PA_RANGE_4G (0x0ULL << ID_AA64MMFR0_PA_RANGE_SHIFT) +#define ID_AA64MMFR0_PA_RANGE_64G (0x1ULL << ID_AA64MMFR0_PA_RANGE_SHIFT) +#define ID_AA64MMFR0_PA_RANGE_1T (0x2ULL << ID_AA64MMFR0_PA_RANGE_SHIFT) +#define ID_AA64MMFR0_PA_RANGE_4T (0x3ULL << ID_AA64MMFR0_PA_RANGE_SHIFT) +#define ID_AA64MMFR0_PA_RANGE_16T (0x4ULL << ID_AA64MMFR0_PA_RANGE_SHIFT) +#define ID_AA64MMFR0_PA_RANGE_256T (0x5ULL << ID_AA64MMFR0_PA_RANGE_SHIFT) +#define ID_AA64MMFR0_ASID_BITS_SHIFT 4 +#define ID_AA64MMFR0_ASID_BITS_MASK (0xfULL << ID_AA64MMFR0_ASID_BITS_SHIFT) +#define ID_AA64MMFR0_ASID_BITS(x) ((x) & ID_AA64MMFR0_ASID_BITS_MASK) +#define ID_AA64MMFR0_ASID_BITS_8 (0x0ULL << ID_AA64MMFR0_ASID_BITS_SHIFT) +#define ID_AA64MMFR0_ASID_BITS_16 (0x2ULL << ID_AA64MMFR0_ASID_BITS_SHIFT) +#define ID_AA64MMFR0_BIGEND_SHIFT 8 +#define ID_AA64MMFR0_BIGEND_MASK (0xfULL << ID_AA64MMFR0_BIGEND_SHIFT) +#define ID_AA64MMFR0_BIGEND(x) ((x) & ID_AA64MMFR0_BIGEND_MASK) +#define ID_AA64MMFR0_BIGEND_FIXED (0x0ULL << ID_AA64MMFR0_BIGEND_SHIFT) +#define ID_AA64MMFR0_BIGEND_MIXED (0x1ULL << ID_AA64MMFR0_BIGEND_SHIFT) +#define ID_AA64MMFR0_S_NS_MEM_SHIFT 12 +#define ID_AA64MMFR0_S_NS_MEM_MASK (0xfULL << ID_AA64MMFR0_S_NS_MEM_SHIFT) +#define ID_AA64MMFR0_S_NS_MEM(x) ((x) & ID_AA64MMFR0_S_NS_MEM_MASK) +#define ID_AA64MMFR0_S_NS_MEM_NONE (0x0ULL << ID_AA64MMFR0_S_NS_MEM_SHIFT) +#define ID_AA64MMFR0_S_NS_MEM_DISTINCT (0x1ULL << ID_AA64MMFR0_S_NS_MEM_SHIFT) +#define ID_AA64MMFR0_BIGEND_EL0_SHIFT 16 +#define ID_AA64MMFR0_BIGEND_EL0_MASK (0xfULL << ID_AA64MMFR0_BIGEND_EL0_SHIFT) +#define ID_AA64MMFR0_BIGEND_EL0(x) ((x) & ID_AA64MMFR0_BIGEND_EL0_MASK) +#define ID_AA64MMFR0_BIGEND_EL0_FIXED (0x0ULL << ID_AA64MMFR0_BIGEND_EL0_SHIFT) +#define ID_AA64MMFR0_BIGEND_EL0_MIXED (0x1ULL << ID_AA64MMFR0_BIGEND_EL0_SHIFT) +#define ID_AA64MMFR0_TGRAN16_SHIFT 20 +#define ID_AA64MMFR0_TGRAN16_MASK (0xfULL << ID_AA64MMFR0_TGRAN16_SHIFT) +#define ID_AA64MMFR0_TGRAN16(x) ((x) & ID_AA64MMFR0_TGRAN16_MASK) +#define ID_AA64MMFR0_TGRAN16_NONE (0x0ULL << ID_AA64MMFR0_TGRAN16_SHIFT) +#define ID_AA64MMFR0_TGRAN16_IMPL (0x1ULL << ID_AA64MMFR0_TGRAN16_SHIFT) +#define ID_AA64MMFR0_TGRAN64_SHIFT 24 +#define ID_AA64MMFR0_TGRAN64_MASK (0xfULL << ID_AA64MMFR0_TGRAN64_SHIFT) +#define ID_AA64MMFR0_TGRAN64(x) ((x) & ID_AA64MMFR0_TGRAN64_MASK) +#define ID_AA64MMFR0_TGRAN64_IMPL (0x0ULL << ID_AA64MMFR0_TGRAN64_SHIFT) +#define ID_AA64MMFR0_TGRAN64_NONE (0xfULL << ID_AA64MMFR0_TGRAN64_SHIFT) +#define ID_AA64MMFR0_TGRAN4_SHIFT 28 +#define ID_AA64MMFR0_TGRAN4_MASK (0xfULL << ID_AA64MMFR0_TGRAN4_SHIFT) +#define ID_AA64MMFR0_TGRAN4(x) ((x) & ID_AA64MMFR0_TGRAN4_MASK) +#define ID_AA64MMFR0_TGRAN4_IMPL (0x0ULL << ID_AA64MMFR0_TGRAN4_SHIFT) +#define ID_AA64MMFR0_TGRAN4_NONE (0xfULL << ID_AA64MMFR0_TGRAN4_SHIFT) +#define ID_AA64MMFR0_ECV_SHIFT 60 +#define ID_AA64MMFR0_ECV_MASK (0xfULL << ID_AA64MMFR0_ECV_SHIFT) +#define ID_AA64MMFR0_ECV(x) ((x) & ID_AA64MMFR0_ECV_MASK) +#define ID_AA64MMFR0_ECV_NONE (0x0ULL << ID_AA64MMFR0_ECV_SHIFT) +#define ID_AA64MMFR0_ECV_IMPL (0x1ULL << ID_AA64MMFR0_ECV_SHIFT) +#define ID_AA64MMFR0_ECV_CNTHCTL (0x2ULL << ID_AA64MMFR0_ECV_SHIFT) + +/* ID_AA64MMFR1_EL1 */ +#define ID_AA64MMFR1_MASK 0xf000f000ffffffffULL +#define ID_AA64MMFR1_HAFDBS_SHIFT 0 +#define ID_AA64MMFR1_HAFDBS_MASK (0xfULL << ID_AA64MMFR1_HAFDBS_SHIFT) +#define ID_AA64MMFR1_HAFDBS(x) ((x) & ID_AA64MMFR1_HAFDBS_MASK) +#define ID_AA64MMFR1_HAFDBS_NONE (0x0ULL << ID_AA64MMFR1_HAFDBS_SHIFT) +#define ID_AA64MMFR1_HAFDBS_AF (0x1ULL << ID_AA64MMFR1_HAFDBS_SHIFT) +#define ID_AA64MMFR1_HAFDBS_AF_DBS (0x2ULL << ID_AA64MMFR1_HAFDBS_SHIFT) +#define ID_AA64MMFR1_VMIDBITS_SHIFT 4 +#define ID_AA64MMFR1_VMIDBITS_MASK (0xfULL << ID_AA64MMFR1_VMIDBITS_SHIFT) +#define ID_AA64MMFR1_VMIDBITS(x) ((x) & ID_AA64MMFR1_VMIDBITS_MASK) +#define ID_AA64MMFR1_VMIDBITS_8 (0x0ULL << ID_AA64MMFR1_VMIDBITS_SHIFT) +#define ID_AA64MMFR1_VMIDBITS_16 (0x2ULL << ID_AA64MMFR1_VMIDBITS_SHIFT) +#define ID_AA64MMFR1_VH_SHIFT 8 +#define ID_AA64MMFR1_VH_MASK (0xfULL << ID_AA64MMFR1_VH_SHIFT) +#define ID_AA64MMFR1_VH(x) ((x) & ID_AA64MMFR1_VH_MASK) +#define ID_AA64MMFR1_VH_NONE (0x0ULL << ID_AA64MMFR1_VH_SHIFT) +#define ID_AA64MMFR1_VH_IMPL (0x1ULL << ID_AA64MMFR1_VH_SHIFT) +#define ID_AA64MMFR1_HPDS_SHIFT 12 +#define ID_AA64MMFR1_HPDS_MASK (0xfULL << ID_AA64MMFR1_HPDS_SHIFT) +#define ID_AA64MMFR1_HPDS(x) ((x) & ID_AA64MMFR1_HPDS_MASK) +#define ID_AA64MMFR1_HPDS_NONE (0x0ULL << ID_AA64MMFR1_HPDS_SHIFT) +#define ID_AA64MMFR1_HPDS_IMPL (0x1ULL << ID_AA64MMFR1_HPDS_SHIFT) +#define ID_AA64MMFR1_LO_SHIFT 16 +#define ID_AA64MMFR1_LO_MASK (0xfULL << ID_AA64MMFR1_LO_SHIFT) +#define ID_AA64MMFR1_LO(x) ((x) & ID_AA64MMFR1_LO_MASK) +#define ID_AA64MMFR1_LO_NONE (0x0ULL << ID_AA64MMFR1_LO_SHIFT) +#define ID_AA64MMFR1_LO_IMPL (0x1ULL << ID_AA64MMFR1_LO_SHIFT) +#define ID_AA64MMFR1_PAN_SHIFT 20 +#define ID_AA64MMFR1_PAN_MASK (0xfULL << ID_AA64MMFR1_PAN_SHIFT) +#define ID_AA64MMFR1_PAN(x) ((x) & ID_AA64MMFR1_PAN_MASK) +#define ID_AA64MMFR1_PAN_NONE (0x0ULL << ID_AA64MMFR1_PAN_SHIFT) +#define ID_AA64MMFR1_PAN_IMPL (0x1ULL << ID_AA64MMFR1_PAN_SHIFT) +#define ID_AA64MMFR1_PAN_ATS1E1 (0x2ULL << ID_AA64MMFR1_PAN_SHIFT) +#define ID_AA64MMFR1_PAN_EPAN (0x3ULL << ID_AA64MMFR1_PAN_SHIFT) +#define ID_AA64MMFR1_SPECSEI_SHIFT 24 +#define ID_AA64MMFR1_SPECSEI_MASK (0xfULL << ID_AA64MMFR1_SPECSEI_SHIFT) +#define ID_AA64MMFR1_SPECSEI(x) ((x) & ID_AA64MMFR1_SPECSEI_MASK) +#define ID_AA64MMFR1_SPECSEI_NONE (0x0ULL << ID_AA64MMFR1_SPECSEI_SHIFT) +#define ID_AA64MMFR1_SPECSEI_IMPL (0x1ULL << ID_AA64MMFR1_SPECSEI_SHIFT) +#define ID_AA64MMFR1_XNX_SHIFT 28 +#define ID_AA64MMFR1_XNX_MASK (0xfULL << ID_AA64MMFR1_XNX_SHIFT) +#define ID_AA64MMFR1_XNX(x) ((x) & ID_AA64MMFR1_XNX_MASK) +#define ID_AA64MMFR1_XNX_NONE (0x0ULL << ID_AA64MMFR1_XNX_SHIFT) +#define ID_AA64MMFR1_XNX_IMPL (0x1ULL << ID_AA64MMFR1_XNX_SHIFT) +#define ID_AA64MMFR1_AFP_SHIFT 44 +#define ID_AA64MMFR1_AFP_MASK (0xfULL << ID_AA64MMFR1_AFP_SHIFT) +#define ID_AA64MMFR1_AFP(x) ((x) & ID_AA64MMFR1_AFP_MASK) +#define ID_AA64MMFR1_AFP_NONE (0x0ULL << ID_AA64MMFR1_AFP_SHIFT) +#define ID_AA64MMFR1_AFP_IMPL (0x1ULL << ID_AA64MMFR1_AFP_SHIFT) +#define ID_AA64MMFR1_ECBHB_SHIFT 60 +#define ID_AA64MMFR1_ECBHB_MASK (0xfULL << ID_AA64MMFR1_ECBHB_SHIFT) +#define ID_AA64MMFR1_ECBHB(x) ((x) & ID_AA64MMFR1_ECBHB_MASK) +#define ID_AA64MMFR1_ECBHB_NONE (0x0ULL << ID_AA64MMFR1_ECBHB_SHIFT) +#define ID_AA64MMFR1_ECBHB_IMPL (0x1ULL << ID_AA64MMFR1_ECBHB_SHIFT) + +/* ID_AA64MMFR2_EL1 */ +#define ID_AA64MMFR2_MASK 0xffff0fffffffffffULL +#define ID_AA64MMFR2_CCIDX_SHIFT 20 +#define ID_AA64MMFR2_CCIDX_MASK (0xfULL << ID_AA64MMFR2_CCIDX_SHIFT) +#define ID_AA64MMFR2_CCIDX(x) ((x) & ID_AA64MMFR2_CCIDX_MASK) +#define ID_AA64MMFR2_CCIDX_IMPL (0x1ULL << ID_AA64MMFR2_CCIDX_SHIFT) +#define ID_AA64MMFR2_AT_SHIFT 32 +#define ID_AA64MMFR2_AT_MASK (0xfULL << ID_AA64MMFR2_AT_SHIFT) +#define ID_AA64MMFR2_AT(x) ((x) & ID_AA64MMFR2_AT_MASK) +#define ID_AA64MMFR2_AT_NONE (0x0ULL << ID_AA64MMFR2_AT_SHIFT) +#define ID_AA64MMFR2_AT_IMPL (0x1ULL << ID_AA64MMFR2_AT_SHIFT) +#define ID_AA64MMFR2_IDS_SHIFT 36 +#define ID_AA64MMFR2_IDS_MASK (0xfULL << ID_AA64MMFR2_IDS_SHIFT) +#define ID_AA64MMFR2_IDS(x) ((x) & ID_AA64MMFR2_IDS_MASK) +#define ID_AA64MMFR2_IDS_NONE (0x0ULL << ID_AA64MMFR2_IDS_SHIFT) +#define ID_AA64MMFR2_IDS_IMPL (0x1ULL << ID_AA64MMFR2_IDS_SHIFT) + +/* ID_AA64PFR0_EL1 */ +#define ID_AA64PFR0_MASK 0xff0fffffffffffffULL +#define ID_AA64PFR0_EL0_SHIFT 0 +#define ID_AA64PFR0_EL0_MASK (0xfULL << ID_AA64PFR0_EL0_SHIFT) +#define ID_AA64PFR0_EL0(x) ((x) & ID_AA64PFR0_EL0_MASK) +#define ID_AA64PFR0_EL0_64 (0x1ULL << ID_AA64PFR0_EL0_SHIFT) +#define ID_AA64PFR0_EL0_64_32 (0x2ULL << ID_AA64PFR0_EL0_SHIFT) +#define ID_AA64PFR0_EL1_SHIFT 4 +#define ID_AA64PFR0_EL1_MASK (0xfULL << ID_AA64PFR0_EL1_SHIFT) +#define ID_AA64PFR0_EL1(x) ((x) & ID_AA64PFR0_EL1_MASK) +#define ID_AA64PFR0_EL1_64 (0x1ULL << ID_AA64PFR0_EL1_SHIFT) +#define ID_AA64PFR0_EL1_64_32 (0x2ULL << ID_AA64PFR0_EL1_SHIFT) +#define ID_AA64PFR0_EL2_SHIFT 8 +#define ID_AA64PFR0_EL2_MASK (0xfULL << ID_AA64PFR0_EL2_SHIFT) +#define ID_AA64PFR0_EL2(x) ((x) & ID_AA64PFR0_EL2_MASK) +#define ID_AA64PFR0_EL2_NONE (0x0ULL << ID_AA64PFR0_EL2_SHIFT) +#define ID_AA64PFR0_EL2_64 (0x1ULL << ID_AA64PFR0_EL2_SHIFT) +#define ID_AA64PFR0_EL2_64_32 (0x2ULL << ID_AA64PFR0_EL2_SHIFT) +#define ID_AA64PFR0_EL3_SHIFT 12 +#define ID_AA64PFR0_EL3_MASK (0xfULL << ID_AA64PFR0_EL3_SHIFT) +#define ID_AA64PFR0_EL3(x) ((x) & ID_AA64PFR0_EL3_MASK) +#define ID_AA64PFR0_EL3_NONE (0x0ULL << ID_AA64PFR0_EL3_SHIFT) +#define ID_AA64PFR0_EL3_64 (0x1ULL << ID_AA64PFR0_EL3_SHIFT) +#define ID_AA64PFR0_EL3_64_32 (0x2ULL << ID_AA64PFR0_EL3_SHIFT) +#define ID_AA64PFR0_FP_SHIFT 16 +#define ID_AA64PFR0_FP_MASK (0xfULL << ID_AA64PFR0_FP_SHIFT) +#define ID_AA64PFR0_FP(x) ((x) & ID_AA64PFR0_FP_MASK) +#define ID_AA64PFR0_FP_IMPL (0x0ULL << ID_AA64PFR0_FP_SHIFT) +#define ID_AA64PFR0_FP_HP (0x1ULL << ID_AA64PFR0_FP_SHIFT) +#define ID_AA64PFR0_FP_NONE (0xfULL << ID_AA64PFR0_FP_SHIFT) +#define ID_AA64PFR0_ADV_SIMD_SHIFT 20 +#define ID_AA64PFR0_ADV_SIMD_MASK (0xfULL << ID_AA64PFR0_ADV_SIMD_SHIFT) +#define ID_AA64PFR0_ADV_SIMD(x) ((x) & ID_AA64PFR0_ADV_SIMD_MASK) +#define ID_AA64PFR0_ADV_SIMD_IMPL (0x0ULL << ID_AA64PFR0_ADV_SIMD_SHIFT) +#define ID_AA64PFR0_ADV_SIMD_HP (0x1ULL << ID_AA64PFR0_ADV_SIMD_SHIFT) +#define ID_AA64PFR0_ADV_SIMD_NONE (0xfULL << ID_AA64PFR0_ADV_SIMD_SHIFT) +#define ID_AA64PFR0_GIC_BITS 0x4 /* Number of bits in GIC field */ +#define ID_AA64PFR0_GIC_SHIFT 24 +#define ID_AA64PFR0_GIC_MASK (0xfULL << ID_AA64PFR0_GIC_SHIFT) +#define ID_AA64PFR0_GIC(x) ((x) & ID_AA64PFR0_GIC_MASK) +#define ID_AA64PFR0_GIC_CPUIF_NONE (0x0ULL << ID_AA64PFR0_GIC_SHIFT) +#define ID_AA64PFR0_GIC_CPUIF_EN (0x1ULL << ID_AA64PFR0_GIC_SHIFT) +#define ID_AA64PFR0_RAS_SHIFT 28 +#define ID_AA64PFR0_RAS_MASK (0xfULL << ID_AA64PFR0_RAS_SHIFT) +#define ID_AA64PFR0_RAS(x) ((x) & ID_AA64PFR0_RAS_MASK) +#define ID_AA64PFR0_RAS_NONE (0x0ULL << ID_AA64PFR0_RAS_SHIFT) +#define ID_AA64PFR0_RAS_IMPL (0x1ULL << ID_AA64PFR0_RAS_SHIFT) +#define ID_AA64PFR0_RAS_IMPL_V1P1 (0x2ULL << ID_AA64PFR0_RAS_SHIFT) +#define ID_AA64PFR0_SVE_SHIFT 32 +#define ID_AA64PFR0_SVE_MASK (0xfULL << ID_AA64PFR0_SVE_SHIFT) +#define ID_AA64PFR0_SVE(x) ((x) & ID_AA64PFR0_SVE_MASK) +#define ID_AA64PFR0_SVE_NONE (0x0ULL << ID_AA64PFR0_SVE_SHIFT) +#define ID_AA64PFR0_SVE_IMPL (0x1ULL << ID_AA64PFR0_SVE_SHIFT) +#define ID_AA64PFR0_SEL2_SHIFT 36 +#define ID_AA64PFR0_SEL2_MASK (0xfULL << ID_AA64PFR0_SEL2_SHIFT) +#define ID_AA64PFR0_SEL2(x) ((x) & ID_AA64PFR0_SEL2_MASK) +#define ID_AA64PFR0_SEL2_NONE (0x0ULL << ID_AA64PFR0_SEL2_SHIFT) +#define ID_AA64PFR0_SEL2_IMPL (0x1ULL << ID_AA64PFR0_SEL2_SHIFT) +#define ID_AA64PFR0_MPAM_SHIFT 40 +#define ID_AA64PFR0_MPAM_MASK (0xfULL << ID_AA64PFR0_MPAM_SHIFT) +#define ID_AA64PFR0_MPAM(x) ((x) & ID_AA64PFR0_MPAM_MASK) +#define ID_AA64PFR0_MPAM_NONE (0x0ULL << ID_AA64PFR0_MPAM_SHIFT) +#define ID_AA64PFR0_MPAM_IMPL (0x1ULL << ID_AA64PFR0_MPAM_SHIFT) +#define ID_AA64PFR0_AMU_SHIFT 44 +#define ID_AA64PFR0_AMU_MASK (0xfULL << ID_AA64PFR0_AMU_SHIFT) +#define ID_AA64PFR0_AMU(x) ((x) & ID_AA64PFR0_AMU_MASK) +#define ID_AA64PFR0_AMU_NONE (0x0ULL << ID_AA64PFR0_AMU_SHIFT) +#define ID_AA64PFR0_AMU_IMPL (0x1ULL << ID_AA64PFR0_AMU_SHIFT) +#define ID_AA64PFR0_AMU_IMPL_V1P1 (0x2ULL << ID_AA64PFR0_AMU_SHIFT) +#define ID_AA64PFR0_DIT_SHIFT 48 +#define ID_AA64PFR0_DIT_MASK (0xfULL << ID_AA64PFR0_DIT_SHIFT) +#define ID_AA64PFR0_DIT(x) ((x) & ID_AA64PFR0_DIT_MASK) +#define ID_AA64PFR0_DIT_UNKNOWN (0x0ULL << ID_AA64PFR0_DIT_SHIFT) +#define ID_AA64PFR0_DIT_IMPL (0x1ULL << ID_AA64PFR0_DIT_SHIFT) +#define ID_AA64PFR0_CSV2_SHIFT 56 +#define ID_AA64PFR0_CSV2_MASK (0xfULL << ID_AA64PFR0_CSV2_SHIFT) +#define ID_AA64PFR0_CSV2(x) ((x) & ID_AA64PFR0_CSV2_MASK) +#define ID_AA64PFR0_CSV2_UNKNOWN (0x0ULL << ID_AA64PFR0_CSV2_SHIFT) +#define ID_AA64PFR0_CSV2_IMPL (0x1ULL << ID_AA64PFR0_CSV2_SHIFT) +#define ID_AA64PFR0_CSV2_SCXT (0x2ULL << ID_AA64PFR0_CSV2_SHIFT) +#define ID_AA64PFR0_CSV2_HCXT (0x3ULL << ID_AA64PFR0_CSV2_SHIFT) +#define ID_AA64PFR0_CSV3_SHIFT 60 +#define ID_AA64PFR0_CSV3_MASK (0xfULL << ID_AA64PFR0_CSV3_SHIFT) +#define ID_AA64PFR0_CSV3(x) ((x) & ID_AA64PFR0_CSV3_MASK) +#define ID_AA64PFR0_CSV3_UNKNOWN (0x0ULL << ID_AA64PFR0_CSV3_SHIFT) +#define ID_AA64PFR0_CSV3_IMPL (0x1ULL << ID_AA64PFR0_CSV3_SHIFT) + +/* ID_AA64PFR1_EL1 */ +#define ID_AA64PFR1_MASK 0x000000000000ffffULL +#define ID_AA64PFR1_BT_SHIFT 0 +#define ID_AA64PFR1_BT_MASK (0xfULL << ID_AA64PFR1_BT_SHIFT) +#define ID_AA64PFR1_BT(x) ((x) & ID_AA64PFR1_BT_MASK) +#define ID_AA64PFR1_BT_NONE (0x0ULL << ID_AA64PFR1_BT_SHIFT) +#define ID_AA64PFR1_BT_IMPL (0x1ULL << ID_AA64PFR1_BT_SHIFT) +#define ID_AA64PFR1_SSBS_SHIFT 4 +#define ID_AA64PFR1_SSBS_MASK (0xfULL << ID_AA64PFR1_SSBS_SHIFT) +#define ID_AA64PFR1_SSBS(x) ((x) & ID_AA64PFR1_SSBS_MASK) +#define ID_AA64PFR1_SSBS_NONE (0x0ULL << ID_AA64PFR1_SSBS_SHIFT) +#define ID_AA64PFR1_SSBS_PSTATE (0x1ULL << ID_AA64PFR1_SSBS_SHIFT) +#define ID_AA64PFR1_SSBS_PSTATE_MSR (0x2ULL << ID_AA64PFR1_SSBS_SHIFT) +#define ID_AA64PFR1_MTE_SHIFT 8 +#define ID_AA64PFR1_MTE_MASK (0xfULL << ID_AA64PFR1_MTE_SHIFT) +#define ID_AA64PFR1_MTE(x) ((x) & ID_AA64PFR1_MTE_MASK) +#define ID_AA64PFR1_MTE_NONE (0x0ULL << ID_AA64PFR1_MTE_SHIFT) +#define ID_AA64PFR1_MTE_IMPL (0x1ULL << ID_AA64PFR1_MTE_SHIFT) +#define ID_AA64PFR1_RAS_FRAC_SHIFT 12 +#define ID_AA64PFR1_RAS_FRAC_MASK (0xfULL << ID_AA64PFR1_RAS_FRAC_SHIFT) +#define ID_AA64PFR1_RAS_FRAC(x) ((x) & ID_AA64PFR1_RAS_FRAC_MASK) +#define ID_AA64PFR1_RAS_FRAC_NONE (0x0ULL << ID_AA64PFR1_RAS_FRAC_SHIFT) +#define ID_AA64PFR1_RAS_FRAC_IMPL (0x1ULL << ID_AA64PFR1_RAS_FRAC_SHIFT) + +/* ID_AA64ZFR0_EL1 */ +#define ID_AA64ZFR0_MASK 0x0ff0ff0f00ff00ffULL +#define ID_AA64ZFR0_SVEVER_SHIFT 0 +#define ID_AA64ZFR0_SVEVER_MASK (0xfULL << ID_AA64ZFR0_SVEVER_SHIFT) +#define ID_AA64ZFR0_SVEVER(x) ((x) & ID_AA64ZFR0_SVEVER_MASK) +#define ID_AA64ZFR0_SVEVER_SVE1 (0x0ULL << ID_AA64ZFR0_SVEVER_SHIFT) +#define ID_AA64ZFR0_SVEVER_SVE2 (0x1ULL << ID_AA64ZFR0_SVEVER_SHIFT) +#define ID_AA64ZFR0_SVEVER_SVE2P1 (0x2ULL << ID_AA64ZFR0_SVEVER_SHIFT) +#define ID_AA64ZFR0_AES_SHIFT 4 +#define ID_AA64ZFR0_AES_MASK (0xfULL << ID_AA64ZFR0_AES_SHIFT) +#define ID_AA64ZFR0_AES(x) ((x) & ID_AA64ZFR0_AES_MASK) +#define ID_AA64ZFR0_AES_NONE (0x0ULL << ID_AA64ZFR0_AES_SHIFT) +#define ID_AA64ZFR0_AES_BASE (0x1ULL << ID_AA64ZFR0_AES_SHIFT) +#define ID_AA64ZFR0_AES_PMULL (0x2ULL << ID_AA64ZFR0_AES_SHIFT) +#define ID_AA64ZFR0_BITPERM_SHIFT 16 +#define ID_AA64ZFR0_BITPERM_MASK (0xfULL << ID_AA64ZFR0_BITPERM_SHIFT) +#define ID_AA64ZFR0_BITPERM(x) ((x) & ID_AA64ZFR0_BITPERM_MASK) +#define ID_AA64ZFR0_BITPERM_NONE (0x0ULL << ID_AA64ZFR0_BITPERM_SHIFT) +#define ID_AA64ZFR0_BITPERM_IMPL (0x1ULL << ID_AA64ZFR0_BITPERM_SHIFT) +#define ID_AA64ZFR0_BF16_SHIFT 20 +#define ID_AA64ZFR0_BF16_MASK (0xfULL << ID_AA64ZFR0_BF16_SHIFT) +#define ID_AA64ZFR0_BF16(x) ((x) & ID_AA64ZFR0_BF16_MASK) +#define ID_AA64ZFR0_BF16_NONE (0x0ULL << ID_AA64ZFR0_BF16_SHIFT) +#define ID_AA64ZFR0_BF16_BASE (0x1ULL << ID_AA64ZFR0_BF16_SHIFT) +#define ID_AA64ZFR0_BF16_EBF (0x2ULL << ID_AA64ZFR0_BF16_SHIFT) +#define ID_AA64ZFR0_SHA3_SHIFT 32 +#define ID_AA64ZFR0_SHA3_MASK (0xfULL << ID_AA64ZFR0_SHA3_SHIFT) +#define ID_AA64ZFR0_SHA3(x) ((x) & ID_AA64ZFR0_SHA3_MASK) +#define ID_AA64ZFR0_SHA3_NONE (0x0ULL << ID_AA64ZFR0_SHA3_SHIFT) +#define ID_AA64ZFR0_SHA3_IMPL (0x1ULL << ID_AA64ZFR0_SHA3_SHIFT) +#define ID_AA64ZFR0_SM4_SHIFT 40 +#define ID_AA64ZFR0_SM4_MASK (0xfULL << ID_AA64ZFR0_SM4_SHIFT) +#define ID_AA64ZFR0_SM4(x) ((x) & ID_AA64ZFR0_SM4_MASK) +#define ID_AA64ZFR0_SM4_NONE (0x0ULL << ID_AA64ZFR0_SM4_SHIFT) +#define ID_AA64ZFR0_SM4_IMPL (0x1ULL << ID_AA64ZFR0_SM4_SHIFT) +#define ID_AA64ZFR0_I8MM_SHIFT 44 +#define ID_AA64ZFR0_I8MM_MASK (0xfULL << ID_AA64ZFR0_I8MM_SHIFT) +#define ID_AA64ZFR0_I8MM(x) ((x) & ID_AA64ZFR0_I8MM_MASK) +#define ID_AA64ZFR0_I8MM_NONE (0x0ULL << ID_AA64ZFR0_I8MM_SHIFT) +#define ID_AA64ZFR0_I8MM_IMPL (0x1ULL << ID_AA64ZFR0_I8MM_SHIFT) +#define ID_AA64ZFR0_F32MM_SHIFT 52 +#define ID_AA64ZFR0_F32MM_MASK (0xfULL << ID_AA64ZFR0_F32MM_SHIFT) +#define ID_AA64ZFR0_F32MM(x) ((x) & ID_AA64ZFR0_F32MM_MASK) +#define ID_AA64ZFR0_F32MM_NONE (0x0ULL << ID_AA64ZFR0_F32MM_SHIFT) +#define ID_AA64ZFR0_F32MM_IMPL (0x1ULL << ID_AA64ZFR0_F32MM_SHIFT) +#define ID_AA64ZFR0_F64MM_SHIFT 56 +#define ID_AA64ZFR0_F64MM_MASK (0xfULL << ID_AA64ZFR0_F64MM_SHIFT) +#define ID_AA64ZFR0_F64MM(x) ((x) & ID_AA64ZFR0_F64MM_MASK) +#define ID_AA64ZFR0_F64MM_NONE (0x0ULL << ID_AA64ZFR0_F64MM_SHIFT) +#define ID_AA64ZFR0_F64MM_IMPL (0x1ULL << ID_AA64ZFR0_F64MM_SHIFT) + +/* MAIR_EL1 - Memory Attribute Indirection Register */ +#define MAIR_ATTR_MASK(idx) (0xff << ((n)* 8)) +#define MAIR_ATTR(attr, idx) ((attr) << ((idx) * 8)) +#define MAIR_DEVICE_nGnRnE 0x00 +#define MAIR_NORMAL_NC 0x44 +#define MAIR_NORMAL_WT 0x88 +#define MAIR_NORMAL_WB 0xff + +/* PAR_EL1 - Physical Address Register */ +#define PAR_F_SHIFT 0 +#define PAR_F (0x1 << PAR_F_SHIFT) +#define PAR_SUCCESS(x) (((x) & PAR_F) == 0) +/* When PAR_F == 0 (success) */ +#define PAR_SH_SHIFT 7 +#define PAR_SH_MASK (0x3 << PAR_SH_SHIFT) +#define PAR_NS_SHIFT 9 +#define PAR_NS_MASK (0x3 << PAR_NS_SHIFT) +#define PAR_PA_SHIFT 12 +#define PAR_PA_MASK 0x0000fffffffff000 +#define PAR_ATTR_SHIFT 56 +#define PAR_ATTR_MASK (0xff << PAR_ATTR_SHIFT) +/* When PAR_F == 1 (aborted) */ +#define PAR_FST_SHIFT 1 +#define PAR_FST_MASK (0x3f << PAR_FST_SHIFT) +#define PAR_PTW_SHIFT 8 +#define PAR_PTW_MASK (0x1 << PAR_PTW_SHIFT) +#define PAR_S_SHIFT 9 +#define PAR_S_MASK (0x1 << PAR_S_SHIFT) + +/* SCTLR_EL1 - System Control Register */ +#define SCTLR_RES0 0xffffffffc8222400 /* Reserved, write 0 */ +#define SCTLR_RES1 0x0000000030d00800 /* Reserved, write 1 */ + +#define SCTLR_M 0x0000000000000001 +#define SCTLR_A 0x0000000000000002 +#define SCTLR_C 0x0000000000000004 +#define SCTLR_SA 0x0000000000000008 +#define SCTLR_SA0 0x0000000000000010 +#define SCTLR_CP15BEN 0x0000000000000020 +#define SCTLR_THEE 0x0000000000000040 +#define SCTLR_ITD 0x0000000000000080 +#define SCTLR_SED 0x0000000000000100 +#define SCTLR_UMA 0x0000000000000200 +#define SCTLR_I 0x0000000000001000 +#define SCTLR_EnDB 0x0000000000002000 +#define SCTLR_DZE 0x0000000000004000 +#define SCTLR_UCT 0x0000000000008000 +#define SCTLR_nTWI 0x0000000000010000 +#define SCTLR_nTWE 0x0000000000040000 +#define SCTLR_WXN 0x0000000000080000 +#define SCTLR_SPAN 0x0000000000800000 +#define SCTLR_EOE 0x0000000001000000 +#define SCTLR_EE 0x0000000002000000 +#define SCTLR_UCI 0x0000000004000000 +#define SCTLR_EnDA 0x0000000008000000 +#define SCTLR_EnIB 0x0000000040000000 +#define SCTLR_EnIA 0x0000000080000000 +#define SCTLR_BT0 0x0000000800000000 +#define SCTLR_BT1 0x0000001000000000 +#define SCTLR_EPAN 0x0200000000000000 + +/* SPSR_EL1 */ +/* + * When the exception is taken in AArch64: + * M[4] is 0 for AArch64 mode + * M[3:2] is the exception level + * M[1] is unused + * M[0] is the SP select: + * 0: always SP0 + * 1: current ELs SP + */ +#define PSR_M_EL0t 0x00000000 +#define PSR_M_EL1t 0x00000004 +#define PSR_M_EL1h 0x00000005 +#define PSR_M_EL2t 0x00000008 +#define PSR_M_EL2h 0x00000009 +#define PSR_M_MASK 0x0000001f + +#define PSR_F 0x00000040 +#define PSR_I 0x00000080 +#define PSR_A 0x00000100 +#define PSR_D 0x00000200 +#define PSR_BTYPE 0x00000c00 +#define PSR_SSBS 0x00001000 +#define PSR_IL 0x00100000 +#define PSR_SS 0x00200000 +#define PSR_PAN 0x00400000 +#define PSR_UAO 0x00800000 +#define PSR_DIT 0x01000000 +#define PSR_TCO 0x02000000 +#define PSR_V 0x10000000 +#define PSR_C 0x20000000 +#define PSR_Z 0x40000000 +#define PSR_N 0x80000000 + +/* TCR_EL1 - Translation Control Register */ +#define TCR_AS (1UL << 36) + +#define TCR_IPS_SHIFT 32 +#define TCR_IPS_32BIT (0UL << TCR_IPS_SHIFT) +#define TCR_IPS_36BIT (1UL << TCR_IPS_SHIFT) +#define TCR_IPS_40BIT (2UL << TCR_IPS_SHIFT) +#define TCR_IPS_42BIT (3UL << TCR_IPS_SHIFT) +#define TCR_IPS_44BIT (4UL << TCR_IPS_SHIFT) +#define TCR_IPS_48BIT (5UL << TCR_IPS_SHIFT) + +#define TCR_TG1_SHIFT 30 +#define TCR_TG1_16K (1UL << TCR_TG1_SHIFT) +#define TCR_TG1_4K (2UL << TCR_TG1_SHIFT) +#define TCR_TG1_64K (3UL << TCR_TG1_SHIFT) + +#define TCR_SH1_SHIFT 28 +#define TCR_SH1_IS (0x3UL << TCR_SH1_SHIFT) +#define TCR_ORGN1_SHIFT 26 +#define TCR_ORGN1_WBWA (0x1UL << TCR_ORGN1_SHIFT) +#define TCR_IRGN1_SHIFT 24 +#define TCR_IRGN1_WBWA (0x1UL << TCR_IRGN1_SHIFT) + +#define TCR_A1 (1UL << 22) + +#define TCR_TG0_SHIFT 14 +#define TCR_TG0_4K (0UL << TCR_TG0_SHIFT) +#define TCR_TG0_64K (1UL << TCR_TG0_SHIFT) +#define TCR_TG0_16K (2UL << TCR_TG0_SHIFT) + +#define TCR_SH0_SHIFT 12 +#define TCR_SH0_IS (0x3UL << TCR_SH0_SHIFT) +#define TCR_ORGN0_SHIFT 10 +#define TCR_ORGN0_WBWA (0x1UL << TCR_ORGN0_SHIFT) +#define TCR_IRGN0_SHIFT 8 +#define TCR_IRGN0_WBWA (0x1UL << TCR_IRGN0_SHIFT) + +#define TCR_CACHE_ATTRS ((TCR_IRGN0_WBWA | TCR_IRGN1_WBWA) |\ + (TCR_ORGN0_WBWA | TCR_ORGN1_WBWA)) +#define TCR_SMP_ATTRS (TCR_SH0_IS | TCR_SH1_IS) + +#define TCR_T1SZ_SHIFT 16 +#define TCR_T0SZ_SHIFT 0 +#define TCR_T1SZ(x) ((x) << TCR_T1SZ_SHIFT) +#define TCR_T0SZ(x) ((x) << TCR_T0SZ_SHIFT) +#define TCR_TxSZ(x) (TCR_T1SZ(x) | TCR_T0SZ(x)) + +/* Monitor Debug System Control Register */ +#define DBG_MDSCR_SS (0x1 << 0) +#define DBG_MDSCR_TDCC (0x1 << 12) +#define DBG_MDSCR_KDE (0x1 << 13) +#define DBG_MDSCR_MDE (0x1 << 15) + +/* Performance Monitoring Counters */ +#define PMCR_E (1 << 0) /* Enable all counters */ +#define PMCR_P (1 << 1) /* Reset all counters */ +#define PMCR_C (1 << 2) /* Clock counter reset */ +#define PMCR_D (1 << 3) /* CNTR counts every 64 clk cycles */ +#define PMCR_X (1 << 4) /* Export to ext. monitoring (ETM) */ +#define PMCR_DP (1 << 5) /* Disable CCNT if non-invasive debug*/ +#define PMCR_LC (1 << 6) /* Long cycle count enable */ +#define PMCR_IMP_SHIFT 24 /* Implementer code */ +#define PMCR_IMP_MASK (0xff << PMCR_IMP_SHIFT) +#define PMCR_IDCODE_SHIFT 16 /* Identification code */ +#define PMCR_IDCODE_MASK (0xff << PMCR_IDCODE_SHIFT) +#define PMCR_IDCODE_CORTEX_A57 0x01 +#define PMCR_IDCODE_CORTEX_A72 0x02 +#define PMCR_IDCODE_CORTEX_A53 0x03 +#define PMCR_N_SHIFT 11 /* Number of counters implemented */ +#define PMCR_N_MASK (0x1f << PMCR_N_SHIFT) + +#define I_bit (1 << 7) /* IRQ disable */ +#define F_bit 0 /* FIQ disable - not actually used */ + +#endif /* !_MACHINE_ARMREG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/asm.h b/lib/libc/include/aarch64-openbsd-none/machine/asm.h new file mode 100644 index 0000000000..e0ad18f38d --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/asm.h @@ -0,0 +1,150 @@ +/* $OpenBSD: asm.h,v 1.12 2023/03/27 19:02:48 kettenis Exp $ */ +/* $NetBSD: asm.h,v 1.4 2001/07/16 05:43:32 matt 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. + * + * from: @(#)asm.h 5.5 (Berkeley) 5/7/91 + */ + +#ifndef _MACHINE_ASM_H_ +#define _MACHINE_ASM_H_ + +#define _C_LABEL(x) x +#define _ASM_LABEL(x) x + +#ifdef __STDC__ +# define __CONCAT(x,y) x ## y +# define __STRING(x) #x +#else +# define __CONCAT(x,y) x/**/y +# define __STRING(x) "x" +#endif + +#ifndef _ALIGN_TEXT +# define _ALIGN_TEXT .align 0 +#endif + +/* + * gas/arm uses @ as a single comment character and thus cannot be used here + * Instead it recognised the # instead of an @ symbols in .type directives + * We define a couple of macros so that assembly code will not be dependant + * on one or the other. + */ +#define _ASM_TYPE_FUNCTION #function +#define _ASM_TYPE_OBJECT #object +/* NB == No Binding: use .globl or .weak as necessary */ +#define _ENTRY_NB(x) \ + .text; _ALIGN_TEXT; .type x,_ASM_TYPE_FUNCTION; x: +#define _ENTRY(x) .globl x; _ENTRY_NB(x) + +#if defined(PROF) || defined(GPROF) +# define _PROF_PROLOGUE \ + stp x29, x30, [sp, #-16]!; \ + mov fp, sp; \ + bl __mcount; \ + ldp x29, x30, [sp], #16; +#else +# define _PROF_PROLOGUE +#endif + +#if defined(_RET_PROTECTOR) +# define RETGUARD_CALC_COOKIE(reg) \ + eor reg, reg, x30 + +# define RETGUARD_LOAD_RANDOM(x, reg) \ + adrp reg, __CONCAT(__retguard_, x); \ + ldr reg, [reg, :lo12:__CONCAT(__retguard_, x)] + +# define RETGUARD_SETUP(x, reg) \ + RETGUARD_SYMBOL(x); \ + RETGUARD_LOAD_RANDOM(x, reg); \ + RETGUARD_CALC_COOKIE(reg) + +# define RETGUARD_CHECK(x, reg) \ + RETGUARD_CALC_COOKIE(reg); \ + RETGUARD_LOAD_RANDOM(x, x9); \ + subs reg, reg, x9; \ + cbz reg, 66f; \ + brk #0x1; \ +66: + +# define RETGUARD_PUSH(reg) \ + str reg, [sp, #-16]! + +# define RETGUARD_POP(reg) \ + ldr reg, [sp, #16]! + +# define RETGUARD_SYMBOL(x) \ + .ifndef __CONCAT(__retguard_, x); \ + .hidden __CONCAT(__retguard_, x); \ + .type __CONCAT(__retguard_, x),@object; \ + .pushsection .openbsd.randomdata.retguard,"aw",@progbits; \ + .weak __CONCAT(__retguard_, x); \ + .p2align 3; \ + __CONCAT(__retguard_, x): ; \ + .xword 0; \ + .size __CONCAT(__retguard_, x), 8; \ + .popsection; \ + .endif +#else +# define RETGUARD_CALC_COOKIE(reg) +# define RETGUARD_LOAD_RANDOM(x, reg) +# define RETGUARD_SETUP(x, reg) +# define RETGUARD_CHECK(x, reg) +# define RETGUARD_PUSH(reg) +# define RETGUARD_POP(reg) +# define RETGUARD_SYMBOL(x) +#endif + +#define ENTRY(y) _ENTRY(y); bti c; _PROF_PROLOGUE +#define ENTRY_NP(y) _ENTRY(y); bti c +#define ENTRY_NB(y) _ENTRY_NB(y); bti c; _PROF_PROLOGUE +#define ASENTRY(y) _ENTRY(y); bti c; _PROF_PROLOGUE +#define ASENTRY_NP(y) _ENTRY(y); bti c +#define END(y) .size y, . - y +#define EENTRY(sym) .globl sym; sym: +#define EEND(sym) + +#ifdef __PIC__ +#define PIC_SYM(x,y) x(y) +#else +#define PIC_SYM(x,y) x +#endif + +#define STRONG_ALIAS(alias,sym) \ + .global alias; \ + alias = sym +#define WEAK_ALIAS(alias,sym) \ + .weak alias; \ + alias = sym + +#endif /* !_MACHINE_ASM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/atomic.h b/lib/libc/include/aarch64-openbsd-none/machine/atomic.h new file mode 100644 index 0000000000..7a66719a47 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/atomic.h @@ -0,0 +1,64 @@ +/* $OpenBSD: atomic.h,v 1.4 2022/08/29 02:01:18 jsg Exp $ */ + +/* Public Domain */ + +#ifndef _MACHINE_ATOMIC_H_ +#define _MACHINE_ATOMIC_H_ + +#define __membar(_f) do { __asm volatile(_f ::: "memory"); } while (0) + +#define membar_enter() __membar("dmb sy") +#define membar_exit() __membar("dmb sy") +#define membar_producer() __membar("dmb st") +#define membar_consumer() __membar("dmb ld") +#define membar_sync() __membar("dmb sy") + +#if defined(_KERNEL) + +/* virtio needs MP membars even on SP kernels */ +#define virtio_membar_producer() __membar("dmb st") +#define virtio_membar_consumer() __membar("dmb ld") +#define virtio_membar_sync() __membar("dmb sy") + +/* + * Set bits + * *p = *p | v + */ +static inline void +atomic_setbits_int(volatile unsigned int *p, unsigned int v) +{ + unsigned int modified, tmp; + + __asm volatile ( + "1: ldxr %w0, [%x3] \n\t" + " orr %w0, %w0, %w2 \n\t" + " stxr %w1, %w0, [%x3] \n\t" + " cbnz %w1, 1b \n\t" + : "=&r" (tmp), "=&r" (modified) + : "r" (v), "r" (p) + : "memory", "cc" + ); +} + +/* + * Clear bits + * *p = *p & (~v) + */ +static inline void +atomic_clearbits_int(volatile unsigned int *p, unsigned int v) +{ + unsigned int modified, tmp; + + __asm volatile ( + "1: ldxr %w0, [%x3] \n\t" + " bic %w0, %w0, %w2 \n\t" + " stxr %w1, %w0, [%x3] \n\t" + " cbnz %w1, 1b \n\t" + : "=&r" (tmp), "=&r" (modified) + : "r" (v), "r" (p) + : "memory", "cc" + ); +} + +#endif /* defined(_KERNEL) */ +#endif /* _MACHINE_ATOMIC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/bootconfig.h b/lib/libc/include/aarch64-openbsd-none/machine/bootconfig.h new file mode 100644 index 0000000000..8767d1ab7f --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/bootconfig.h @@ -0,0 +1,47 @@ +/* $OpenBSD: bootconfig.h,v 1.4 2023/12/05 05:27:26 jsg Exp $ */ +/* $NetBSD: bootconfig.h,v 1.2 2001/06/21 22:08:28 chris Exp $ */ + +/*- + * Copyright (c) 2013 Andrew Turner + * 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 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 AUTHOR 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. + * + * $FreeBSD: head/sys/arm64/include/machdep.h 281494 2015-04-13 14:43:10Z andrew $ + */ + +#ifndef _MACHINE_BOOTCONFIG_H_ +#define _MACHINE_BOOTCONFIG_H_ + +struct arm64_bootparams { + vaddr_t modulep; + vaddr_t kern_l1pt; /* L1 page table for the kernel */ + uint64_t kern_delta; + vaddr_t kern_stack; + void *arg0; // passed to kernel in R0 + void *arg1; // passed to kernel in R1 + void *arg2; // passed to kernel in R2 +}; + +void initarm(struct arm64_bootparams *); + +#endif /* _MACHINE_BOOTCONFIG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/bus.h b/lib/libc/include/aarch64-openbsd-none/machine/bus.h new file mode 100644 index 0000000000..70ad145593 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/bus.h @@ -0,0 +1,536 @@ +/* $OpenBSD: bus.h,v 1.11 2024/11/18 05:32:39 jsg Exp $ */ +/* + * Copyright (c) 2003-2004 Opsycon AB Sweden. 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_BUS_H_ +#define _MACHINE_BUS_H_ + +#ifdef __STDC__ +#define CAT(a,b) a##b +#define CAT3(a,b,c) a##b##c +#else +#define CAT(a,b) a/**/b +#define CAT3(a,b,c) a/**/b/**/c +#endif + +/* + * Bus access types. + */ +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; +typedef struct bus_space bus_space_t; + +struct bus_space { + bus_addr_t bus_base; + void *bus_private; + u_int8_t (*_space_read_1)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_1)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int8_t); + u_int16_t (*_space_read_2)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_2)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int16_t); + u_int32_t (*_space_read_4)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_4)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int32_t); + u_int64_t (*_space_read_8)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_8)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int64_t); + void (*_space_read_raw_2)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, u_int8_t *, bus_size_t); + void (*_space_write_raw_2)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const u_int8_t *, bus_size_t); + void (*_space_read_raw_4)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, u_int8_t *, bus_size_t); + void (*_space_write_raw_4)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const u_int8_t *, bus_size_t); + void (*_space_read_raw_8)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, u_int8_t *, bus_size_t); + void (*_space_write_raw_8)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const u_int8_t *, bus_size_t); + int (*_space_map)(bus_space_tag_t , bus_addr_t, + bus_size_t, int, bus_space_handle_t *); + void (*_space_unmap)(bus_space_tag_t, bus_space_handle_t, + bus_size_t); + int (*_space_subregion)(bus_space_tag_t, bus_space_handle_t, + bus_size_t, bus_size_t, bus_space_handle_t *); + void * (*_space_vaddr)(bus_space_tag_t, bus_space_handle_t); + paddr_t (*_space_mmap)(bus_space_tag_t, bus_addr_t, off_t, + int, int); +}; + +#define bus_space_read_1(t, h, o) (*(t)->_space_read_1)((t), (h), (o)) +#define bus_space_read_2(t, h, o) (*(t)->_space_read_2)((t), (h), (o)) +#define bus_space_read_4(t, h, o) (*(t)->_space_read_4)((t), (h), (o)) +#define bus_space_read_8(t, h, o) (*(t)->_space_read_8)((t), (h), (o)) + +#define bus_space_write_1(t, h, o, v) (*(t)->_space_write_1)((t), (h), (o), (v)) +#define bus_space_write_2(t, h, o, v) (*(t)->_space_write_2)((t), (h), (o), (v)) +#define bus_space_write_4(t, h, o, v) (*(t)->_space_write_4)((t), (h), (o), (v)) +#define bus_space_write_8(t, h, o, v) (*(t)->_space_write_8)((t), (h), (o), (v)) + +#define bus_space_read_raw_2(t, h, o) \ + (*(t)->_space_read_2)((t), (h), (o)) +#define bus_space_read_raw_4(t, h, o) \ + (*(t)->_space_read_4)((t), (h), (o)) +#define bus_space_read_raw_8(t, h, o) \ + (*(t)->_space_read_8)((t), (h), (o)) + +#define bus_space_write_raw_2(t, h, o, v) \ + (*(t)->_space_write_2)((t), (h), (o), (v)) +#define bus_space_write_raw_4(t, h, o, v) \ + (*(t)->_space_write_4)((t), (h), (o), (v)) +#define bus_space_write_raw_8(t, h, o, v) \ + (*(t)->_space_write_8)((t), (h), (o), (v)) + +#define bus_space_read_raw_multi_2(t, h, a, b, l) \ + (*(t)->_space_read_raw_2)((t), (h), (a), (b), (l)) +#define bus_space_read_raw_multi_4(t, h, a, b, l) \ + (*(t)->_space_read_raw_4)((t), (h), (a), (b), (l)) +#define bus_space_read_raw_multi_8(t, h, a, b, l) \ + (*(t)->_space_read_raw_8)((t), (h), (a), (b), (l)) + +#define bus_space_write_raw_multi_2(t, h, a, b, l) \ + (*(t)->_space_write_raw_2)((t), (h), (a), (b), (l)) +#define bus_space_write_raw_multi_4(t, h, a, b, l) \ + (*(t)->_space_write_raw_4)((t), (h), (a), (b), (l)) +#define bus_space_write_raw_multi_8(t, h, a, b, l) \ + (*(t)->_space_write_raw_8)((t), (h), (a), (b), (l)) + +#define bus_space_map(t, o, s, c, p) (*(t)->_space_map)((t), (o), (s), (c), (p)) +#define bus_space_unmap(t, h, s) (*(t)->_space_unmap)((t), (h), (s)) +#define bus_space_subregion(t, h, o, s, p) \ + (*(t)->_space_subregion)((t), (h), (o), (s), (p)) + +#define BUS_SPACE_MAP_CACHEABLE 0x01 +#define BUS_SPACE_MAP_POSTED 0x02 +#define BUS_SPACE_MAP_LINEAR 0x04 +#define BUS_SPACE_MAP_PREFETCHABLE 0x08 + +extern bus_space_t arm64_bs_tag; + +#define bus_space_vaddr(t, h) (*(t)->_space_vaddr)((t), (h)) +#define bus_space_mmap(t, a, o, p, f) \ + (*(t)->_space_mmap)((t), (a), (o), (p), (f)) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_multi(n,m) \ +static __inline void \ +CAT(bus_space_read_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_size_t o, CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) \ + *x++ = CAT(bus_space_read_,n)(bst, bsh, o); \ +} + +bus_space_read_multi(1,8) +bus_space_read_multi(2,16) +bus_space_read_multi(4,32) +bus_space_read_multi(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_region(n,m) \ +static __inline void \ +CAT(bus_space_read_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) { \ + *x++ = CAT(bus_space_read_,n)(bst, bsh, ba); \ + ba += (n); \ + } \ +} + +bus_space_read_region(1,8) +bus_space_read_region(2,16) +bus_space_read_region(4,32) +bus_space_read_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_raw_region(n,m) \ +static __inline void \ +CAT(bus_space_read_raw_region_,n)(bus_space_tag_t bst, \ + bus_space_handle_t bsh, \ + bus_addr_t ba, u_int8_t *x, size_t cnt) \ +{ \ + cnt >>= ((n) >> 1); \ + while (cnt--) { \ + CAT(bus_space_read_raw_multi_,n)(bst, bsh, ba, x, (n)); \ + ba += (n); \ + x += (n); \ + } \ +} + +bus_space_read_raw_region(2,16) +bus_space_read_raw_region(4,32) +bus_space_read_raw_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_multi(n,m) \ +static __inline void \ +CAT(bus_space_write_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_size_t o, const CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) \ + CAT(bus_space_write_,n)(bst, bsh, o, *x++); \ +} + +bus_space_write_multi(1,8) +bus_space_write_multi(2,16) +bus_space_write_multi(4,32) +bus_space_write_multi(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_region(n,m) \ +static __inline void \ +CAT(bus_space_write_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, const CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) { \ + CAT(bus_space_write_,n)(bst, bsh, ba, *x++); \ + ba += (n); \ + } \ +} + +bus_space_write_region(1,8) +bus_space_write_region(2,16) +bus_space_write_region(4,32) +bus_space_write_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_raw_region(n,m) \ +static __inline void \ +CAT(bus_space_write_raw_region_,n)(bus_space_tag_t bst, \ + bus_space_handle_t bsh, \ + bus_addr_t ba, const u_int8_t *x, size_t cnt) \ +{ \ + cnt >>= ((n) >> 1); \ + while (cnt--) { \ + CAT(bus_space_write_raw_multi_,n)(bst, bsh, ba, x, (n)); \ + ba += (n); \ + x += (n); \ + } \ +} + +bus_space_write_raw_region(2,16) +bus_space_write_raw_region(4,32) +bus_space_write_raw_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_set_region(n,m) \ +static __inline void \ +CAT(bus_space_set_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, CAT3(u_int,m,_t) x, size_t cnt) \ +{ \ + while (cnt--) { \ + CAT(bus_space_write_,n)(bst, bsh, ba, x); \ + ba += (n); \ + } \ +} + +bus_space_set_region(1,8) +bus_space_set_region(2,16) +bus_space_set_region(4,32) +bus_space_set_region(8,64) + +/*----------------------------------------------------------------------------*/ +static __inline void +bus_space_copy_1(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + char *s = (char *)(h1 + o1); + char *d = (char *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + + +static __inline void +bus_space_copy_2(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + short *s = (short *)(h1 + o1); + short *d = (short *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + +static __inline void +bus_space_copy_4(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + int *s = (int *)(h1 + o1); + int *d = (int *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + +static __inline void +bus_space_copy_8(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + int64_t *s = (int64_t *)(h1 + o1); + int64_t *d = (int64_t *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + +/*----------------------------------------------------------------------------*/ +/* + * Bus read/write barrier methods. + * + * void bus_space_barrier(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * bus_size_t len, int flags); + * + */ +static inline void +bus_space_barrier(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, + bus_size_t length, int flags) +{ + __asm__ volatile ("dsb sy" ::: "memory"); +} +#define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */ +#define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */ + +#define BUS_DMA_WAITOK 0x0000 +#define BUS_DMA_NOWAIT 0x0001 +#define BUS_DMA_ALLOCNOW 0x0002 +#define BUS_DMA_COHERENT 0x0008 +#define BUS_DMA_BUS1 0x0010 /* placeholders for bus functions... */ +#define BUS_DMA_BUS2 0x0020 +#define BUS_DMA_BUS3 0x0040 +#define BUS_DMA_BUS4 0x0080 +#define BUS_DMA_READ 0x0100 /* mapping is device -> memory only */ +#define BUS_DMA_WRITE 0x0200 /* mapping is memory -> device only */ +#define BUS_DMA_STREAMING 0x0400 /* hint: sequential, unidirectional */ +#define BUS_DMA_ZERO 0x0800 /* zero memory in dmamem_alloc */ +#define BUS_DMA_NOCACHE 0x1000 +#define BUS_DMA_64BIT 0x2000 /* device handles 64bit dva */ +#define BUS_DMA_FIXED 0x4000 /* place mapping at specified dva */ + +/* Forwards needed by prototypes below. */ +struct mbuf; +struct proc; +struct uio; + +#define BUS_DMASYNC_POSTREAD 0x0001 +#define BUS_DMASYNC_POSTWRITE 0x0002 +#define BUS_DMASYNC_PREREAD 0x0004 +#define BUS_DMASYNC_PREWRITE 0x0008 + +typedef struct machine_bus_dma_tag *bus_dma_tag_t; +typedef struct machine_bus_dmamap *bus_dmamap_t; + +/* + * bus_dma_segment_t + * + * Describes a single contiguous DMA transaction. Values + * are suitable for programming into DMA registers. + */ +struct machine_bus_dma_segment { + bus_addr_t ds_addr; /* DMA address */ + bus_size_t ds_len; /* length of transfer */ + + paddr_t _ds_paddr; /* CPU address */ + vaddr_t _ds_vaddr; /* CPU address */ +}; +typedef struct machine_bus_dma_segment bus_dma_segment_t; + +/* + * bus_dma_tag_t + * + * A machine-dependent opaque type describing the implementation of + * DMA for a given bus. + */ + +struct machine_bus_dma_tag { + void *_cookie; /* cookie used in the guts */ + int _flags; /* misc. flags */ + + /* + * DMA mapping methods. + */ + int (*_dmamap_create)(bus_dma_tag_t , bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); + void (*_dmamap_destroy)(bus_dma_tag_t , bus_dmamap_t); + int (*_dmamap_load)(bus_dma_tag_t , bus_dmamap_t, void *, + bus_size_t, struct proc *, int); + int (*_dmamap_load_mbuf)(bus_dma_tag_t , bus_dmamap_t, + struct mbuf *, int); + int (*_dmamap_load_uio)(bus_dma_tag_t , bus_dmamap_t, + struct uio *, int); + int (*_dmamap_load_raw)(bus_dma_tag_t , bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); + int (*_dmamap_load_buffer)(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int, paddr_t *, int *, int); + void (*_dmamap_unload)(bus_dma_tag_t , bus_dmamap_t); + void (*_dmamap_sync)(bus_dma_tag_t , bus_dmamap_t, + bus_addr_t, bus_size_t, int); + + /* + * DMA memory utility functions. + */ + int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); + int (*_dmamem_alloc_range)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int, + bus_addr_t, bus_addr_t); + void (*_dmamem_free)(bus_dma_tag_t, bus_dma_segment_t *, int); + int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); + void (*_dmamem_unmap)(bus_dma_tag_t, caddr_t, size_t); + paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *, + int, off_t, int, int); + + /* + * internal memory address translation information. + */ + bus_addr_t _dma_mask; +}; + +#define bus_dmamap_create(t, s, n, m, b, f, p) \ + (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p)) +#define bus_dmamap_destroy(t, p) \ + (*(t)->_dmamap_destroy)((t), (p)) +#define bus_dmamap_load(t, m, b, s, p, f) \ + (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f)) +#define bus_dmamap_load_mbuf(t, m, b, f) \ + (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f)) +#define bus_dmamap_load_uio(t, m, u, f) \ + (*(t)->_dmamap_load_uio)((t), (m), (u), (f)) +#define bus_dmamap_load_raw(t, m, sg, n, s, f) \ + (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f)) +#define bus_dmamap_unload(t, p) \ + (*(t)->_dmamap_unload)((t), (p)) +#define bus_dmamap_sync(t, p, a, l, o) \ + (void)((t)->_dmamap_sync ? \ + (*(t)->_dmamap_sync)((t), (p), (a), (l), (o)) : (void)0) + +#define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \ + (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f)) +#define bus_dmamem_alloc_range(t, s, a, b, sg, n, r, f, l, h) \ + (*(t)->_dmamem_alloc_range)((t), (s), (a), (b), (sg), \ + (n), (r), (f), (l), (h)) +#define bus_dmamem_free(t, sg, n) \ + (*(t)->_dmamem_free)((t), (sg), (n)) +#define bus_dmamem_map(t, sg, n, s, k, f) \ + (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f)) +#define bus_dmamem_unmap(t, k, s) \ + (*(t)->_dmamem_unmap)((t), (k), (s)) +#define bus_dmamem_mmap(t, sg, n, o, p, f) \ + (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f)) + +int _dmamap_create(bus_dma_tag_t, bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); +void _dmamap_destroy(bus_dma_tag_t, bus_dmamap_t); +int _dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int); +int _dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, struct mbuf *, int); +int _dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, struct uio *, int); +int _dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); +int _dmamap_load_buffer(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int, paddr_t *, int *, int); +void _dmamap_unload(bus_dma_tag_t, bus_dmamap_t); +void _dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, + bus_size_t, int); + +int _dmamem_alloc(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); +void _dmamem_free(bus_dma_tag_t, bus_dma_segment_t *, int); +int _dmamem_map(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); +void _dmamem_unmap(bus_dma_tag_t, caddr_t, size_t); +paddr_t _dmamem_mmap(bus_dma_tag_t, bus_dma_segment_t *, int, off_t, int, int); +int _dmamem_alloc_range(bus_dma_tag_t, bus_size_t, bus_size_t, bus_size_t, + bus_dma_segment_t *, int, int *, int, paddr_t, paddr_t); + +/* + * bus_dmamap_t + * + * Describes a DMA mapping. + */ +struct machine_bus_dmamap { + /* + * PRIVATE MEMBERS: not for use by machine-independent code. + */ + bus_size_t _dm_size; /* largest DMA transfer mappable */ + int _dm_segcnt; /* number of segs this map can map */ + bus_size_t _dm_maxsegsz; /* largest possible segment */ + bus_size_t _dm_boundary; /* don't cross this */ + int _dm_flags; /* misc. flags */ + + void *_dm_cookie; /* cookie for bus-specific functions */ + + /* + * PUBLIC MEMBERS: these are used by machine-independent code. + */ + bus_size_t dm_mapsize; /* size of the mapping */ + int dm_nsegs; /* # valid segments in mapping */ + bus_dma_segment_t dm_segs[1]; /* segments; variable length */ +}; + +int generic_space_map(bus_space_tag_t, bus_addr_t, bus_size_t, int, + bus_space_handle_t *); +void generic_space_unmap(bus_space_tag_t, bus_space_handle_t, bus_size_t); +int generic_space_region(bus_space_tag_t, bus_space_handle_t, bus_size_t, + bus_size_t, bus_space_handle_t *); +void *generic_space_vaddr(bus_space_tag_t, bus_space_handle_t); +paddr_t generic_space_mmap(bus_space_tag_t, bus_addr_t, off_t, int, int); +uint8_t generic_space_read_1(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint16_t generic_space_read_2(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint32_t generic_space_read_4(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint64_t generic_space_read_8(bus_space_tag_t, bus_space_handle_t, bus_size_t); +void generic_space_read_raw_2(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_1(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint8_t); +void generic_space_write_2(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint16_t); +void generic_space_write_4(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint32_t); +void generic_space_write_8(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint64_t); +void generic_space_write_raw_2(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); +void generic_space_read_raw_4(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_raw_4(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); +void generic_space_read_raw_8(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_raw_8(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); + +#endif /* _MACHINE_BUS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/cdefs.h b/lib/libc/include/aarch64-openbsd-none/machine/cdefs.h new file mode 100644 index 0000000000..307f720db4 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/cdefs.h @@ -0,0 +1,16 @@ +/* $OpenBSD: cdefs.h,v 1.1 2016/12/17 23:38:33 patrick Exp $ */ + +#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_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/conf.h b/lib/libc/include/aarch64-openbsd-none/machine/conf.h new file mode 100644 index 0000000000..9a9e0a1465 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/conf.h @@ -0,0 +1,61 @@ +/* $OpenBSD: conf.h,v 1.5 2024/06/12 02:50:25 jsg Exp $ */ +/* $NetBSD: conf.h,v 1.2 1996/05/05 19:28:34 christos Exp $ */ + +/* + * Copyright (c) 1996 Christos Zoulas. 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 Christos Zoulas. + * 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 _MACHINE_CONF_H_ +#define _MACHINE_CONF_H_ + +#include + +#define mmread mmrw +#define mmwrite mmrw +cdev_decl(mm); + +/* open, close, ioctl */ +#define cdev_openprom_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) nullop, 0, \ + (dev_type_mmap((*))) enodev } + +cdev_decl(openprom); + +/* open, close, write, ioctl, kqueue */ +#define cdev_acpiapm_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,n,kqfilter) } + +cdev_decl(apm); +cdev_decl(acpiapm); + +#endif /* _MACHINE_CONF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/cpu.h b/lib/libc/include/aarch64-openbsd-none/machine/cpu.h new file mode 100644 index 0000000000..39cdc4ecd5 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/cpu.h @@ -0,0 +1,360 @@ +/* $OpenBSD: cpu.h,v 1.51 2025/02/11 22:27:09 kettenis Exp $ */ +/* + * Copyright (c) 2016 Dale Rahn + * + * 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_CPU_H_ +#define _MACHINE_CPU_H_ + +/* + * User-visible definitions + */ + +/* + * CTL_MACHDEP definitions. + */ +#define CPU_COMPATIBLE 1 /* compatible property */ +#define CPU_ID_AA64ISAR0 2 +#define CPU_ID_AA64ISAR1 3 +#define CPU_ID_AA64ISAR2 4 +#define CPU_ID_AA64MMFR0 5 +#define CPU_ID_AA64MMFR1 6 +#define CPU_ID_AA64MMFR2 7 +#define CPU_ID_AA64PFR0 8 +#define CPU_ID_AA64PFR1 9 +#define CPU_ID_AA64SMFR0 10 +#define CPU_ID_AA64ZFR0 11 +#define CPU_LIDACTION 12 +#define CPU_MAXID 13 /* number of valid machdep ids */ + +#define CTL_MACHDEP_NAMES { \ + { 0, 0 }, \ + { "compatible", CTLTYPE_STRING }, \ + { "id_aa64isar0", CTLTYPE_QUAD }, \ + { "id_aa64isar1", CTLTYPE_QUAD }, \ + { "id_aa64isar2", CTLTYPE_QUAD }, \ + { "id_aa64mmfr0", CTLTYPE_QUAD }, \ + { "id_aa64mmfr1", CTLTYPE_QUAD }, \ + { "id_aa64mmfr2", CTLTYPE_QUAD }, \ + { "id_aa64pfr0", CTLTYPE_QUAD }, \ + { "id_aa64pfr1", CTLTYPE_QUAD }, \ + { "id_aa64smfr0", CTLTYPE_QUAD }, \ + { "id_aa64zfr0", CTLTYPE_QUAD }, \ + { "lidaction", CTLTYPE_INT }, \ +} + +#ifdef _KERNEL + +/* + * Kernel-only definitions + */ + +extern uint64_t cpu_id_aa64isar0; +extern uint64_t cpu_id_aa64isar1; +extern uint64_t cpu_id_aa64isar2; +extern uint64_t cpu_id_aa64mmfr0; +extern uint64_t cpu_id_aa64mmfr1; +extern uint64_t cpu_id_aa64mmfr2; +extern uint64_t cpu_id_aa64pfr0; +extern uint64_t cpu_id_aa64pfr1; +extern uint64_t cpu_id_aa64zfr0; + +void cpu_identify_cleanup(void); + +#include +#include +#include + +/* All the CLKF_* macros take a struct clockframe * as an argument. */ + +#define clockframe trapframe +/* + * CLKF_USERMODE: Return TRUE/FALSE (1/0) depending on whether the + * frame came from USR mode or not. + */ +#define CLKF_USERMODE(frame) ((frame->tf_elr & (1ul << 63)) == 0) + +/* + * CLKF_INTR: True if we took the interrupt from inside another + * interrupt handler. + */ +#define CLKF_INTR(frame) (curcpu()->ci_idepth > 1) + +/* + * CLKF_PC: Extract the program counter from a clockframe + */ +#define CLKF_PC(frame) (frame->tf_elr) + +/* + * PROC_PC: Find out the program counter for the given process. + */ +#define PROC_PC(p) ((p)->p_addr->u_pcb.pcb_tf->tf_elr) +#define PROC_STACK(p) ((p)->p_addr->u_pcb.pcb_tf->tf_sp) + +/* + * Per-CPU information. For now we assume one CPU. + */ + +#include +#include +#include +#include +#include + +struct cpu_info { + struct device *ci_dev; /* Device corresponding to this CPU */ + struct cpu_info *ci_next; + struct schedstate_percpu ci_schedstate; /* scheduler state */ + + u_int32_t ci_cpuid; + uint64_t ci_mpidr; + uint64_t ci_midr; + u_int ci_acpi_proc_id; + int ci_node; + struct cpu_info *ci_self; + +#define __HAVE_CPU_TOPOLOGY + u_int32_t ci_smt_id; + u_int32_t ci_core_id; + u_int32_t ci_pkg_id; + + struct proc *ci_curproc; + struct pcb *ci_curpcb; + struct pmap *ci_curpm; + u_int32_t ci_randseed; + + u_int32_t ci_ctrl; /* The CPU control register */ + + u_int64_t ci_trampoline_vectors; + + uint32_t ci_cpl; + uint32_t ci_ipending; + uint32_t ci_idepth; +#ifdef DIAGNOSTIC + int ci_mutex_level; +#endif + int ci_want_resched; + + void (*ci_flush_bp)(void); + void (*ci_serror)(void); + + uint64_t ci_ttbr1; + vaddr_t ci_el1_stkend; + + uint32_t ci_psci_idle_latency; + uint32_t ci_psci_idle_param; + uint32_t ci_psci_suspend_param; + + struct opp_table *ci_opp_table; + volatile int ci_opp_idx; + volatile int ci_opp_max; + uint32_t ci_cpu_supply; + + u_long ci_prev_sleep; + u_long ci_last_itime; + +#ifdef MULTIPROCESSOR + struct srp_hazard ci_srp_hazards[SRP_HAZARD_NUM]; +#define __HAVE_UVM_PERCPU + struct uvm_pmr_cache ci_uvm; + volatile int ci_flags; + + volatile int ci_ddb_paused; +#define CI_DDB_RUNNING 0 +#define CI_DDB_SHOULDSTOP 1 +#define CI_DDB_STOPPED 2 +#define CI_DDB_ENTERDDB 3 +#define CI_DDB_INDDB 4 + +#endif + +#ifdef GPROF + struct gmonparam *ci_gmon; + struct clockintr ci_gmonclock; +#endif + struct clockqueue ci_queue; + char ci_panicbuf[512]; +}; + +#define CPUF_PRIMARY (1<<0) +#define CPUF_AP (1<<1) +#define CPUF_IDENTIFY (1<<2) +#define CPUF_IDENTIFIED (1<<3) +#define CPUF_PRESENT (1<<4) +#define CPUF_GO (1<<5) +#define CPUF_RUNNING (1<<6) + +static inline struct cpu_info * +curcpu(void) +{ + struct cpu_info *__ci = NULL; + __asm volatile("mrs %0, tpidr_el1" : "=r" (__ci)); + return (__ci); +} + +extern struct cpu_info cpu_info_primary; +extern struct cpu_info *cpu_info_list; + +#ifndef MULTIPROCESSOR +#define cpu_number() 0 +#define CPU_IS_PRIMARY(ci) 1 +#define CPU_IS_RUNNING(ci) 1 +#define CPU_INFO_ITERATOR int +#define CPU_INFO_FOREACH(cii, ci) \ + for (cii = 0, ci = curcpu(); ci != NULL; ci = NULL) +#define CPU_INFO_UNIT(ci) 0 +#define MAXCPUS 1 +#define cpu_unidle(ci) +#else +#define cpu_number() (curcpu()->ci_cpuid) +#define CPU_IS_PRIMARY(ci) ((ci) == &cpu_info_primary) +#define CPU_IS_RUNNING(ci) ((ci)->ci_flags & CPUF_RUNNING) +#define CPU_INFO_ITERATOR int +#define CPU_INFO_FOREACH(cii, ci) for (cii = 0, ci = cpu_info_list; \ + ci != NULL; ci = ci->ci_next) +#define CPU_INFO_UNIT(ci) ((ci)->ci_dev ? (ci)->ci_dev->dv_unit : 0) +#define MAXCPUS 256 + +extern struct cpu_info *cpu_info[MAXCPUS]; + +void cpu_boot_secondary_processors(void); +#endif /* !MULTIPROCESSOR */ + +#define CPU_BUSY_CYCLE() __asm volatile("yield" : : : "memory") + +#define curpcb curcpu()->ci_curpcb + +static inline unsigned int +cpu_rnd_messybits(void) +{ + uint64_t val, rval; + + __asm volatile("mrs %0, CNTVCT_EL0; rbit %1, %0;" + : "=r" (val), "=r" (rval)); + + return (val ^ rval); +} + +/* + * Scheduling glue + */ +#define aston(p) ((p)->p_md.md_astpending = 1) +#define setsoftast() aston(curcpu()->ci_curproc) + +/* + * Notify the current process (p) that it has a signal pending, + * process as soon as possible. + */ + +#ifdef MULTIPROCESSOR +void cpu_unidle(struct cpu_info *ci); +#define signotify(p) (aston(p), cpu_unidle((p)->p_cpu)) +void cpu_kick(struct cpu_info *); +#else +#define cpu_kick(ci) +#define cpu_unidle(ci) +#define signotify(p) setsoftast() +#endif + +/* + * Preempt the current process if in interrupt from user mode, + * or after the current trap/syscall if in system mode. + */ +void need_resched(struct cpu_info *); +#define clear_resched(ci) ((ci)->ci_want_resched = 0) + +/* + * Give a profiling tick to the current process when the user profiling + * buffer pages are invalid. On the i386, request an ast to send us + * through trap(), marking the proc as needing a profiling tick. + */ +#define need_proftick(p) aston(p) + +// asm code to start new kernel contexts. +void proc_trampoline(void); + +/* + * Random cruft + */ +void dumpconf(void); + +// syscall.c +void svc_handler (trapframe_t *); + +// functions to manipulate interrupt state +static __inline void +restore_daif(uint32_t daif) +{ + __asm volatile ("msr daif, %x0":: "r"(daif)); +} + +static __inline void +enable_irq_daif(void) +{ + __asm volatile ("msr daifclr, #3"); +} + +static __inline void +disable_irq_daif(void) +{ + __asm volatile ("msr daifset, #3"); +} + +static __inline uint32_t +disable_irq_daif_ret(void) +{ + uint32_t daif; + __asm volatile ("mrs %x0, daif": "=r"(daif)); + __asm volatile ("msr daifset, #3"); + return daif; +} + +static inline void +intr_enable(void) +{ + enable_irq_daif(); +} + +static inline u_long +intr_disable(void) +{ + return disable_irq_daif_ret(); +} + +static inline void +intr_restore(u_long daif) +{ + restore_daif(daif); +} + +void cpu_halt(void); +int cpu_suspend_primary(void); +void cpu_resume_secondary(struct cpu_info *); + +extern void (*cpu_idle_cycle_fcn)(void); +extern void (*cpu_suspend_cycle_fcn)(void); + +void cpu_wfi(void); + +void delay (unsigned); +#define DELAY(x) delay(x) + +#endif /* _KERNEL */ + +#ifdef MULTIPROCESSOR +#include +#endif /* MULTIPROCESSOR */ + +#endif /* !_MACHINE_CPU_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/cpufunc.h b/lib/libc/include/aarch64-openbsd-none/machine/cpufunc.h new file mode 100644 index 0000000000..df2a91afc3 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/cpufunc.h @@ -0,0 +1,56 @@ +/* $OpenBSD: cpufunc.h,v 1.4 2018/05/02 15:17:30 patrick Exp $ */ +/*- + * Copyright (c) 2014 Andrew Turner + * 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 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 AUTHOR 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. + * + * $FreeBSD: head/sys/cpu/include/cpufunc.h 299683 2016-05-13 16:03:50Z andrew $ + */ + +#ifndef _MACHINE_CPUFUNC_H_ +#define _MACHINE_CPUFUNC_H_ + +#ifdef _KERNEL + +#include + +extern int64_t dcache_line_size; +extern int64_t icache_line_size; +extern int64_t idcache_line_size; +extern int64_t dczva_line_size; + +void cpu_setttb(int, paddr_t); +void cpu_tlb_flush(void); +void cpu_tlb_flush_asid(vaddr_t); +void cpu_tlb_flush_all_asid(vaddr_t); +void cpu_tlb_flush_asid_all(vaddr_t); +void cpu_icache_sync_range(vaddr_t, vsize_t); +void cpu_idcache_wbinv_range(vaddr_t, vsize_t); +void cpu_dcache_wbinv_range(vaddr_t, vsize_t); +void cpu_dcache_inv_range(vaddr_t, vsize_t); +void cpu_dcache_wb_range(vaddr_t, vsize_t); + +register_t smc_call(register_t, register_t, register_t, register_t); + +#endif /* _KERNEL */ +#endif /* _MACHINE_CPUFUNC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/db_machdep.h b/lib/libc/include/aarch64-openbsd-none/machine/db_machdep.h new file mode 100644 index 0000000000..d930085c2d --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/db_machdep.h @@ -0,0 +1,80 @@ +/* $OpenBSD: db_machdep.h,v 1.8 2025/07/22 09:20:41 kettenis Exp $ */ +/* $NetBSD: db_machdep.h,v 1.5 2001/11/22 18:00:00 thorpej Exp $ */ + +/* + * Copyright (c) 1996 Scott K Stevens + * + * Mach Operating System + * Copyright (c) 1991,1990 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +#ifndef _MACHINE_DB_MACHDEP_H_ +#define _MACHINE_DB_MACHDEP_H_ + +/* + * Machine-dependent defines for new kernel debugger. + */ + +#include +#include +#include +#include + +/* end of mangling */ + +typedef long db_expr_t; /* expression - signed */ + +typedef trapframe_t db_regs_t; + +extern db_regs_t ddb_regs; /* register state */ +#define DDB_REGS (&ddb_regs) + +#define PC_REGS(regs) ((vaddr_t)(regs)->tf_elr) +#define SET_PC_REGS(regs, value) (regs)->tf_elr = (register_t)(value) + +#define BKPT_INST 0xd4200000 /* breakpoint instruction */ +#define BKPT_SIZE (INSN_SIZE) /* size of breakpoint inst */ +#define BKPT_SET(inst) (BKPT_INST) + +#define db_clear_single_step(regs) ((regs)->tf_spsr &= ~PSR_SS) +#define db_set_single_step(regs) ((regs)->tf_spsr |= PSR_SS) + +#define IS_BREAKPOINT_TRAP(type, code) ((type) == EXCP_BRK) +#define IS_WATCHPOINT_TRAP(type, code) ((type) == EXCP_WATCHPT_EL1) + +// 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 DB_MACHINE_COMMANDS + +int db_ktrap(int, db_regs_t *); +void db_machine_init (void); + +#define DDB_STATE_NOT_RUNNING 0 +#define DDB_STATE_RUNNING 1 +#define DDB_STATE_EXITING 2 + +#endif /* _MACHINE_DB_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/disklabel.h b/lib/libc/include/aarch64-openbsd-none/machine/disklabel.h new file mode 100644 index 0000000000..6427b26604 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/disklabel.h @@ -0,0 +1,25 @@ +/* $OpenBSD: disklabel.h,v 1.1 2016/12/17 23:38:33 patrick Exp $ */ +/* + * Copyright (c) 2014 Patrick Wildt + * + * 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_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/efivar.h b/lib/libc/include/aarch64-openbsd-none/machine/efivar.h new file mode 100644 index 0000000000..659349b12b --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/efivar.h @@ -0,0 +1,46 @@ +/* $OpenBSD: efivar.h,v 1.2 2024/07/10 10:53:55 kettenis Exp $ */ +/* + * Copyright (c) 2022 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_EFIVAR_H_ +#define _MACHINE_EFIVAR_H_ + +#include + +struct efi_softc { + struct device sc_dev; + struct pmap *sc_pm; + EFI_RUNTIME_SERVICES *sc_rs; + EFI_SYSTEM_RESOURCE_TABLE *sc_esrt; + u_long sc_psw; + + struct todr_chip_handle sc_todr; +}; + + +extern EFI_GET_VARIABLE efi_get_variable; +extern EFI_SET_VARIABLE efi_set_variable; +extern EFI_GET_NEXT_VARIABLE_NAME efi_get_next_variable_name; + +void efi_enter(struct efi_softc *); +void efi_leave(struct efi_softc *); + +extern label_t efi_jmpbuf; + +#define efi_enter_check(sc) (setjmp(&efi_jmpbuf) ? \ + (efi_leave(sc), EFAULT) : (efi_enter(sc), 0)) + +#endif /* _MACHINE_EFIVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/elf.h b/lib/libc/include/aarch64-openbsd-none/machine/elf.h new file mode 100644 index 0000000000..7af1436a51 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/elf.h @@ -0,0 +1,121 @@ +/*- + * Copyright (c) 1996-1997 John D. Polstra. + * 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 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 AUTHOR 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_ELF_H_ +#define _MACHINE_ELF_H_ + +/* + * ELF definitions for the AArch64 architecture. + */ + +#ifdef _KERNEL +# define __HAVE_CPU_HWCAP +# define __HAVE_CPU_HWCAP2 +extern unsigned long hwcap, hwcap2; +#endif /* _KERNEL */ + +/* HWCAP */ +#define HWCAP_FP 0x00000001 +#define HWCAP_ASIMD 0x00000002 +#define HWCAP_EVTSTRM 0x00000004 +#define HWCAP_AES 0x00000008 +#define HWCAP_PMULL 0x00000010 +#define HWCAP_SHA1 0x00000020 +#define HWCAP_SHA2 0x00000040 +#define HWCAP_CRC32 0x00000080 +#define HWCAP_ATOMICS 0x00000100 +#define HWCAP_FPHP 0x00000200 +#define HWCAP_ASIMDHP 0x00000400 +#define HWCAP_CPUID 0x00000800 +#define HWCAP_ASIMDRDM 0x00001000 +#define HWCAP_JSCVT 0x00002000 +#define HWCAP_FCMA 0x00004000 +#define HWCAP_LRCPC 0x00008000 +#define HWCAP_DCPOP 0x00010000 +#define HWCAP_SHA3 0x00020000 +#define HWCAP_SM3 0x00040000 +#define HWCAP_SM4 0x00080000 +#define HWCAP_ASIMDDP 0x00100000 +#define HWCAP_SHA512 0x00200000 +#define HWCAP_SVE 0x00400000 +#define HWCAP_ASIMDFHM 0x00800000 +#define HWCAP_DIT 0x01000000 +#define HWCAP_USCAT 0x02000000 +#define HWCAP_ILRCPC 0x04000000 +#define HWCAP_FLAGM 0x08000000 +#define HWCAP_SSBS 0x10000000 +#define HWCAP_SB 0x20000000 +#define HWCAP_PACA 0x40000000 +#define HWCAP_PACG 0x80000000 + +/* HWCAP2 */ +#define HWCAP2_DCPODP 0x0000000000000001ul +#define HWCAP2_SVE2 0x0000000000000002ul +#define HWCAP2_SVEAES 0x0000000000000004ul +#define HWCAP2_SVEPMULL 0x0000000000000008ul +#define HWCAP2_SVEBITPERM 0x0000000000000010ul +#define HWCAP2_SVESHA3 0x0000000000000020ul +#define HWCAP2_SVESM4 0x0000000000000040ul +#define HWCAP2_FLAGM2 0x0000000000000080ul +#define HWCAP2_FRINT 0x0000000000000100ul +#define HWCAP2_SVEI8MM 0x0000000000000200ul +#define HWCAP2_SVEF32MM 0x0000000000000400ul +#define HWCAP2_SVEF64MM 0x0000000000000800ul +#define HWCAP2_SVEBF16 0x0000000000001000ul +#define HWCAP2_I8MM 0x0000000000002000ul +#define HWCAP2_BF16 0x0000000000004000ul +#define HWCAP2_DGH 0x0000000000008000ul +#define HWCAP2_RNG 0x0000000000010000ul +#define HWCAP2_BTI 0x0000000000020000ul +#define HWCAP2_MTE 0x0000000000040000ul +#define HWCAP2_ECV 0x0000000000080000ul +#define HWCAP2_AFP 0x0000000000100000ul +#define HWCAP2_RPRES 0x0000000000200000ul +#define HWCAP2_MTE3 0x0000000000400000ul +#define HWCAP2_SME 0x0000000000800000ul +#define HWCAP2_SME_I16I64 0x0000000001000000ul +#define HWCAP2_SME_F64F64 0x0000000002000000ul +#define HWCAP2_SME_I8I32 0x0000000004000000ul +#define HWCAP2_SME_F16F32 0x0000000008000000ul +#define HWCAP2_SME_B16F32 0x0000000010000000ul +#define HWCAP2_SME_F32F32 0x0000000020000000ul +#define HWCAP2_SME_FA64 0x0000000040000000ul +#define HWCAP2_WFXT 0x0000000080000000ul +#define HWCAP2_EBF16 0x0000000100000000ul +#define HWCAP2_SVE_EBF16 0x0000000200000000ul +#define HWCAP2_CSSC 0x0000000400000000ul +#define HWCAP2_RPRFM 0x0000000800000000ul +#define HWCAP2_SVE2P1 0x0000001000000000ul +#define HWCAP2_SME2 0x0000002000000000ul +#define HWCAP2_SME2P1 0x0000004000000000ul +#define HWCAP2_SME_I16I32 0x0000008000000000ul +#define HWCAP2_SME_BI32I32 0x0000010000000000ul +#define HWCAP2_SME_B16B16 0x0000020000000000ul +#define HWCAP2_SME_F16F16 0x0000040000000000ul +#define HWCAP2_MOPS 0x0000080000000000ul +#define HWCAP2_HBC 0x0000100000000000ul + +#endif /* !_MACHINE_ELF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/endian.h b/lib/libc/include/aarch64-openbsd-none/machine/endian.h new file mode 100644 index 0000000000..1de95e0c62 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/endian.h @@ -0,0 +1,29 @@ +/* $OpenBSD: endian.h,v 1.4 2024/05/07 14:26:48 naddy Exp $ */ + +/* + * Copyright (c) 2015 David Gwynne + * + * 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_ENDIAN_H_ +#define _MACHINE_ENDIAN_H_ + +#define _BYTE_ORDER _LITTLE_ENDIAN +#define __STRICT_ALIGNMENT + +#ifndef __FROM_SYS__ENDIAN +#include +#endif + +#endif /* _MACHINE_ENDIAN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/exec.h b/lib/libc/include/aarch64-openbsd-none/machine/exec.h new file mode 100644 index 0000000000..61fcd9797a --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/exec.h @@ -0,0 +1,33 @@ +/* $OpenBSD: exec.h,v 1.3 2025/07/31 16:09:59 kettenis Exp $ */ +/* + * Copyright (c) 2014 Patrick Wildt + * + * 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 + +#ifdef _KERNEL +#define __HAVE_COREDUMP_NOTE_ELF_MD +#endif + +#endif \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/fdt.h b/lib/libc/include/aarch64-openbsd-none/machine/fdt.h new file mode 100644 index 0000000000..3ea355d9ad --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/fdt.h @@ -0,0 +1,59 @@ +/* $OpenBSD: fdt.h,v 1.7 2020/07/14 15:34:14 patrick Exp $ */ +/* + * Copyright (c) 2016 Patrick Wildt + * + * 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 __ARM_FDT_H__ +#define __ARM_FDT_H__ + +#define _ARM32_BUS_DMA_PRIVATE +#include + +struct fdt_attach_args { + const char *fa_name; + int fa_node; + bus_space_tag_t fa_iot; + bus_dma_tag_t fa_dmat; + struct fdt_reg *fa_reg; + int fa_nreg; + uint32_t *fa_intr; + int fa_nintr; + int fa_acells; + int fa_scells; +}; + +extern int stdout_node; +extern int stdout_speed; +extern bus_space_tag_t fdt_cons_bs_tag; + +void *fdt_find_cons(const char *); + +#define fdt_intr_enable arm_intr_enable +#define fdt_intr_establish arm_intr_establish_fdt +#define fdt_intr_establish_cpu arm_intr_establish_fdt_cpu +#define fdt_intr_establish_idx arm_intr_establish_fdt_idx +#define fdt_intr_establish_idx_cpu arm_intr_establish_fdt_idx_cpu +#define fdt_intr_establish_imap arm_intr_establish_fdt_imap +#define fdt_intr_establish_imap_cpu arm_intr_establish_fdt_imap_cpu +#define fdt_intr_establish_msi arm_intr_establish_fdt_msi +#define fdt_intr_establish_msi_cpu arm_intr_establish_fdt_msi_cpu +#define fdt_intr_disable arm_intr_disable +#define fdt_intr_disestablish arm_intr_disestablish_fdt +#define fdt_intr_get_parent arm_intr_get_parent +#define fdt_intr_parent_establish arm_intr_parent_establish_fdt +#define fdt_intr_parent_disestablish arm_intr_parent_disestablish_fdt +#define fdt_intr_register arm_intr_register_fdt + +#endif /* __ARM_FDT_H__ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/fenv.h b/lib/libc/include/aarch64-openbsd-none/machine/fenv.h new file mode 100644 index 0000000000..db0eb47817 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/fenv.h @@ -0,0 +1,95 @@ +/* $OpenBSD: fenv.h,v 1.3 2019/03/12 22:14:50 patrick Exp $ */ + +/* + * Copyright (c) 2011 Martynas Venckus + * + * 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_FENV_H_ +#define _MACHINE_FENV_H_ + +/* + * Each symbol representing a floating point exception expands to an integer + * constant expression with values, such that bitwise-inclusive ORs of _all + * combinations_ of the constants result in distinct values. + * + * We use such values that allow direct bitwise operations on FPU registers. + */ +#define FE_INVALID 0x01 +#define FE_DIVBYZERO 0x02 +#define FE_OVERFLOW 0x04 +#define FE_UNDERFLOW 0x08 +#define FE_INEXACT 0x10 +#define FE_DENORMAL 0x80 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * exception constants defined above. + */ +#define FE_ALL_EXCEPT (FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | \ + FE_UNDERFLOW | FE_INEXACT | FE_DENORMAL) + +/* + * Each symbol representing the rounding direction, expands to an integer + * constant expression whose value is distinct non-negative value. + * + * We use such values that allow direct bitwise operations on FPU registers. + */ +#define FE_TONEAREST 0x0 +#define FE_UPWARD 0x1 +#define FE_DOWNWARD 0x2 +#define FE_TOWARDZERO 0x3 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * rounding direction constants defined above. + */ +#define _ROUND_MASK (FE_TONEAREST | FE_UPWARD | FE_DOWNWARD | \ + FE_TOWARDZERO) +#define _ROUND_SHIFT 22 + +/* + * fenv_t represents the entire floating-point environment. + */ +typedef unsigned long long fenv_t; + +/* + * The following constant represents the default floating-point environment + * (that is, the one installed at program startup) and has type pointer to + * const-qualified fenv_t. + * + * It can be used as an argument to the functions within the header + * that manage the floating-point environment, namely fesetenv() and + * feupdateenv(). + */ +__BEGIN_DECLS +extern fenv_t __fe_dfl_env; +__END_DECLS +#define FE_DFL_ENV ((const fenv_t *)&__fe_dfl_env) + +/* + * fexcept_t represents the floating-point status flags collectively, including + * any status the implementation associates with the flags. + * + * A floating-point status flag is a system variable whose value is set (but + * never cleared) when a floating-point exception is raised, which occurs as a + * side effect of exceptional floating-point arithmetic to provide auxiliary + * information. + * + * A floating-point control mode is a system variable whose value may be set by + * the user to affect the subsequent behavior of floating-point arithmetic. + */ +typedef unsigned long long fexcept_t; + +#endif /* !_MACHINE_FENV_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/fpu.h b/lib/libc/include/aarch64-openbsd-none/machine/fpu.h new file mode 100644 index 0000000000..1c1afec45a --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/fpu.h @@ -0,0 +1,29 @@ +/* $OpenBSD: fpu.h,v 1.2 2025/02/11 22:27:09 kettenis Exp $ */ +/* + * Copyright (c) 2022 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_FPU_H +#define _MACHINE_FPU_H + +void fpu_save(struct proc *); +void fpu_load(struct proc *); +void sve_load(struct proc *); +void fpu_drop(void); + +void fpu_kernel_enter(void); +void fpu_kernel_exit(void); + +#endif /* !_MACHINE_FPU_H */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/frame.h b/lib/libc/include/aarch64-openbsd-none/machine/frame.h new file mode 100644 index 0000000000..a169a9a1b9 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/frame.h @@ -0,0 +1,77 @@ +/* $OpenBSD: frame.h,v 1.3 2018/06/30 15:23:37 deraadt Exp $ */ +/* + * Copyright (c) 2016 Dale Rahn + * + * 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_FRAME_H_ +#define _MACHINE_FRAME_H_ + +#ifndef _LOCORE + +#include + + +/* + * Exception/Trap Stack Frame + */ +#define clockframe trapframe +typedef struct trapframe { + register_t tf_sp; + register_t tf_lr; + register_t tf_elr; + register_t tf_spsr; + register_t tf_x[30]; +} trapframe_t; + +/* + * pushed on stack for signal delivery + */ +struct sigframe { + int sf_signum; + struct sigcontext sf_sc; + siginfo_t sf_si; +}; + +/* + * System stack frames. + */ + +/* + * Stack frame inside cpu_switch() + */ + +struct switchframe { + register_t sf_x19; + register_t sf_x20; + register_t sf_x21; + register_t sf_x22; + register_t sf_x23; + register_t sf_x24; + register_t sf_x25; + register_t sf_x26; + register_t sf_x27; + register_t sf_x28; + register_t sf_x29; + register_t sf_lr; +}; + +struct callframe { + struct callframe *f_frame; + register_t f_lr; +}; + +#endif /* !_LOCORE */ + +#endif /* _MACHINE_FRAME_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/hypervisor.h b/lib/libc/include/aarch64-openbsd-none/machine/hypervisor.h new file mode 100644 index 0000000000..71dce49532 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/hypervisor.h @@ -0,0 +1,88 @@ +/* $OpenBSD: hypervisor.h,v 1.5 2025/02/11 22:27:09 kettenis Exp $ */ +/*- + * Copyright (c) 2013, 2014 Andrew Turner + * 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 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 AUTHOR 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. + * + * $FreeBSD: head/sys/arm64/include/hypervisor.h 281494 2015-04-13 14:43:10Z andrew $ + */ + +#ifndef _MACHINE_HYPERVISOR_H_ +#define _MACHINE_HYPERVISOR_H_ + +/* + * These registers are only useful when in hypervisor context, + * e.g. specific to EL2, or controlling the hypervisor. + */ + +/* + * Architecture feature trap register + */ +#define CPTR_RES0 0x7fefc800 +#define CPTR_RES1 0x000032ff +#define CPTR_TFP 0x00000400 +#define CPTR_TTA 0x00100000 +#define CPTR_TCPAC 0x80000000 + +/* + * Hypervisor Config Register + */ + +#define HCR_VM 0x0000000000000001 +#define HCR_SWIO 0x0000000000000002 +#define HCR_PTW 0x0000000000000004 +#define HCR_FMO 0x0000000000000008 +#define HCR_IMO 0x0000000000000010 +#define HCR_AMO 0x0000000000000020 +#define HCR_VF 0x0000000000000040 +#define HCR_VI 0x0000000000000080 +#define HCR_VSE 0x0000000000000100 +#define HCR_FB 0x0000000000000200 +#define HCR_BSU_MASK 0x0000000000000c00 +#define HCR_DC 0x0000000000001000 +#define HCR_TWI 0x0000000000002000 +#define HCR_TWE 0x0000000000004000 +#define HCR_TID0 0x0000000000008000 +#define HCR_TID1 0x0000000000010000 +#define HCR_TID2 0x0000000000020000 +#define HCR_TID3 0x0000000000040000 +#define HCR_TSC 0x0000000000080000 +#define HCR_TIDCP 0x0000000000100000 +#define HCR_TACR 0x0000000000200000 +#define HCR_TSW 0x0000000000400000 +#define HCR_TPC 0x0000000000800000 +#define HCR_TPU 0x0000000001000000 +#define HCR_TTLB 0x0000000002000000 +#define HCR_TVM 0x0000000004000000 +#define HCR_TGE 0x0000000008000000 +#define HCR_TDZ 0x0000000010000000 +#define HCR_HCD 0x0000000020000000 +#define HCR_TRVM 0x0000000040000000 +#define HCR_RW 0x0000000080000000 +#define HCR_CD 0x0000000100000000 +#define HCR_ID 0x0000000200000000 +#define HCR_E2H 0x0000000400000000 +#define HCR_APK 0x0000010000000000 +#define HCR_API 0x0000020000000000 + +#endif \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/ieee.h b/lib/libc/include/aarch64-openbsd-none/machine/ieee.h new file mode 100644 index 0000000000..d5f061fd54 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/ieee.h @@ -0,0 +1,148 @@ +/* $OpenBSD: ieee.h,v 1.3 2017/04/16 16:14:37 kettenis Exp $ */ +/* $NetBSD: ieee.h,v 1.1 1996/09/30 16:34:25 ws Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)ieee.h 8.1 (Berkeley) 6/11/93 + */ + +/* + * ieee.h defines the machine-dependent layout of the machine's IEEE + * floating point. It does *not* define (yet?) any of the rounding + * mode bits, exceptions, and so forth. + */ + +/* + * Define the number of bits in each fraction and exponent. + * + * k k+1 + * Note that 1.0 x 2 == 0.1 x 2 and that denorms are represented + * + * (-exp_bias+1) + * as fractions that look like 0.fffff x 2 . This means that + * + * -126 + * the number 0.10000 x 2 , for instance, is the same as the normalized + * + * -127 -128 + * float 1.0 x 2 . Thus, to represent 2 , we need one leading zero + * + * -129 + * in the fraction; to represent 2 , we need two, and so on. This + * + * (-exp_bias-fracbits+1) + * implies that the smallest denormalized number is 2 + * + * for whichever format we are talking about: for single precision, for + * + * -126 -149 + * instance, we get .00000000000000000000001 x 2 , or 1.0 x 2 , and + * + * -149 == -127 - 23 + 1. + */ +#define SNG_EXPBITS 8 +#define SNG_FRACBITS 23 + +#define DBL_EXPBITS 11 +#define DBL_FRACHBITS 20 +#define DBL_FRACLBITS 32 +#define DBL_FRACBITS 52 + +#define EXT_EXPBITS 15 +#define EXT_FRACHBITS 16 +#define EXT_FRACHMBITS 32 +#define EXT_FRACLMBITS 32 +#define EXT_FRACLBITS 32 +#define EXT_FRACBITS 112 + +#define EXT_IMPLICIT_NBIT + +#define EXT_TO_ARRAY32(p, a) do { \ + (a)[0] = (uint32_t)(p)->ext_fracl; \ + (a)[1] = (uint32_t)(p)->ext_fraclm; \ + (a)[2] = (uint32_t)(p)->ext_frachm; \ + (a)[3] = (uint32_t)(p)->ext_frach; \ +} while(0) + +struct ieee_single { + u_int sng_frac:23; + u_int sng_exp:8; + u_int sng_sign:1; +}; + +struct ieee_double { + u_int dbl_fracl; + u_int dbl_frach:20; + u_int dbl_exp:11; + u_int dbl_sign:1; +}; + +struct ieee_ext { + u_int ext_fracl; + u_int ext_fraclm; + u_int ext_frachm; + u_int ext_frach:16; + u_int ext_exp:15; + u_int ext_sign:1; +}; + +/* + * Floats whose exponent is in [1..INFNAN) (of whatever type) are + * `normal'. Floats whose exponent is INFNAN are either Inf or NaN. + * Floats whose exponent is zero are either zero (iff all fraction + * bits are zero) or subnormal values. + * + * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its + * high fraction; if the bit is set, it is a `quiet NaN'. + */ +#define SNG_EXP_INFNAN 255 +#define DBL_EXP_INFNAN 2047 +#define EXT_EXP_INFNAN 32767 + +#if 0 +#define SNG_QUIETNAN (1 << 22) +#define DBL_QUIETNAN (1 << 19) +#define EXT_QUIETNAN (1 << 15) +#endif + +/* + * Exponent biases. + */ +#define SNG_EXP_BIAS 127 +#define DBL_EXP_BIAS 1023 +#define EXT_EXP_BIAS 16383 \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/ieeefp.h b/lib/libc/include/aarch64-openbsd-none/machine/ieeefp.h new file mode 100644 index 0000000000..b2c302da9a --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/ieeefp.h @@ -0,0 +1,25 @@ +/* $OpenBSD: ieeefp.h,v 1.2 2021/05/01 20:07:01 kettenis Exp $ */ + +/* + * Based on ieeefp.h written by J.T. Conklin, Apr 28, 1995 + * Public domain. + */ + +#ifndef _MACHINE_IEEEFP_H_ +#define _MACHINE_IEEEFP_H_ + +typedef int fp_except; +#define FP_X_INV 0x01 /* invalid operation exception */ +#define FP_X_DZ 0x02 /* divide-by-zero exception */ +#define FP_X_OFL 0x04 /* overflow exception */ +#define FP_X_UFL 0x08 /* underflow exception */ +#define FP_X_IMP 0x10 /* imprecise (loss of precision) */ + +typedef enum { + FP_RN=0, /* round to nearest representable number */ + FP_RP=1, /* round toward positive infinity */ + FP_RM=2, /* round toward negative infinity */ + FP_RZ=3 /* round to zero (truncate) */ +} fp_rnd; + +#endif /* _MACHINE_IEEEFP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/intr.h b/lib/libc/include/aarch64-openbsd-none/machine/intr.h new file mode 100644 index 0000000000..8dbf0d06f8 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/intr.h @@ -0,0 +1,226 @@ +/* $OpenBSD: intr.h,v 1.25 2025/06/30 14:19:20 kettenis Exp $ */ + +/* + * Copyright (c) 2001-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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_INTR_H_ +#define _MACHINE_INTR_H_ + +/* + * The interrupt level ipl is a logical level; per-platform interrupt + * code will turn it into the appropriate hardware interrupt masks + * values. + * + * Interrupt sources on the CPU are kept enabled regardless of the + * current ipl value; individual hardware sources interrupting while + * logically masked are masked on the fly, remembered as pending, and + * unmasked at the first splx() opportunity. + */ +#ifdef _KERNEL + +/* Interrupt priority `levels'; not mutually exclusive. */ +#define IPL_NONE 0 /* nothing */ +#define IPL_SOFTCLOCK 2 /* soft clock interrupts */ +#define IPL_SOFTNET 3 /* soft network interrupts */ +#define IPL_SOFTTTY 4 /* soft terminal interrupts */ +#define IPL_BIO 5 /* block I/O */ +#define IPL_NET 6 /* network */ +#define IPL_TTY 7 /* terminal */ +#define IPL_VM 8 /* memory allocation */ +#define IPL_AUDIO 9 /* audio */ +#define IPL_CLOCK 10 /* clock */ +#define IPL_SCHED IPL_CLOCK +#define IPL_STATCLOCK IPL_CLOCK +#define IPL_HIGH 11 /* everything */ +#define IPL_IPI 12 /* interprocessor interrupt */ +#define NIPL 13 /* number of levels */ + +#define IPL_MPFLOOR IPL_TTY +/* Interrupt priority 'flags'. */ +#define IPL_IRQMASK 0xf /* priority only */ +#define IPL_FLAGMASK 0xf00 /* flags only*/ +#define IPL_MPSAFE 0x100 /* 'mpsafe' interrupt, no kernel lock */ +#define IPL_WAKEUP 0x200 /* 'wakeup' interrupt */ + +/* Interrupt sharing types. */ +#define IST_NONE 0 /* none */ +#define IST_PULSE 1 /* pulsed */ +#define IST_EDGE 2 /* edge-triggered */ +#define IST_LEVEL 3 /* level-triggered */ + +#define IST_LEVEL_LOW IST_LEVEL +#define IST_LEVEL_HIGH 4 +#define IST_EDGE_FALLING IST_EDGE +#define IST_EDGE_RISING 5 +#define IST_EDGE_BOTH 6 + +#define __USE_MI_SOFTINTR + +#include + +#ifndef _LOCORE +#include + +void softintr(int); + +int splraise(int); +int spllower(int); +void splx(int); + +void arm_do_pending_intr(int); +void arm_set_intr_handler(int (*)(int), int (*)(int), void (*)(int), + void (*)(int), void (*)(void *), void (*)(void *), + void (*)(void), void (*)(void)); + +struct machine_intr_handle { + struct interrupt_controller *ih_ic; + void *ih_ih; +}; + +struct arm_intr_func { + int (*raise)(int); + int (*lower)(int); + void (*x)(int); + void (*setipl)(int); + void (*enable_wakeup)(void); + void (*disable_wakeup)(void); +}; + +extern struct arm_intr_func arm_intr_func; + +#define splraise(cpl) (arm_intr_func.raise(cpl)) +#define _splraise(cpl) (arm_intr_func.raise(cpl)) +#define spllower(cpl) (arm_intr_func.lower(cpl)) +#define splx(cpl) (arm_intr_func.x(cpl)) + +#define splsoftclock() splraise(IPL_SOFTCLOCK) +#define splsoftnet() splraise(IPL_SOFTNET) +#define splsofttty() splraise(IPL_SOFTTTY) +#define splbio() splraise(IPL_BIO) +#define splnet() splraise(IPL_NET) +#define spltty() splraise(IPL_TTY) +#define splvm() splraise(IPL_VM) +#define splaudio() splraise(IPL_AUDIO) +#define splclock() splraise(IPL_CLOCK) +#define splsched() splraise(IPL_SCHED) +#define splstatclock() splraise(IPL_STATCLOCK) +#define splhigh() splraise(IPL_HIGH) + +#define spl0() spllower(IPL_NONE) + +void intr_barrier(void *); +void intr_set_wakeup(void *); +void intr_enable_wakeup(void); +void intr_disable_wakeup(void); + +void arm_init_smask(void); /* XXX */ +extern uint32_t arm_smask[NIPL]; + +/* XXX - this is probably the wrong location for this */ +void arm_clock_register(void (*)(void), void (*)(u_int), void (*)(int), + void (*)(void)); + +struct cpu_info; + +struct interrupt_controller { + int ic_node; + void *ic_cookie; + void *(*ic_establish)(void *, int *, int, struct cpu_info *, + int (*)(void *), void *, char *); + void *(*ic_establish_msi)(void *, uint64_t *, uint64_t *, int, + struct cpu_info *, int (*)(void *), void *, char *); + void (*ic_disestablish)(void *); + void (*ic_enable)(void *); + void (*ic_disable)(void *); + void (*ic_route)(void *, int, struct cpu_info *); + void (*ic_cpu_enable)(void); + void (*ic_barrier)(void *); + void (*ic_set_wakeup)(void *); + + LIST_ENTRY(interrupt_controller) ic_list; + uint32_t ic_phandle; + uint32_t ic_cells; + uint32_t ic_gic_its_id; +}; + +void arm_intr_init_fdt(void); +void arm_intr_register_fdt(struct interrupt_controller *); +void *arm_intr_establish_fdt(int, int, int (*)(void *), + void *, char *); +void *arm_intr_establish_fdt_cpu(int, int, struct cpu_info *, + int (*)(void *), void *, char *); +void *arm_intr_establish_fdt_idx(int, int, int, int (*)(void *), + void *, char *); +void *arm_intr_establish_fdt_idx_cpu(int, int, int, struct cpu_info *, + int (*)(void *), void *, char *); +void *arm_intr_establish_fdt_imap(int, int *, int, int, int (*)(void *), + void *, char *); +void *arm_intr_establish_fdt_imap_cpu(int, int *, int, int, + struct cpu_info *, int (*)(void *), void *, char *); +void *arm_intr_establish_fdt_msi(int, uint64_t *, uint64_t *, int, + int (*)(void *), void *, char *); +void *arm_intr_establish_fdt_msi_cpu(int, uint64_t *, uint64_t *, int, + struct cpu_info *, int (*)(void *), void *, char *); +void arm_intr_disestablish_fdt(void *); +void arm_intr_enable(void *); +void arm_intr_disable(void *); +void arm_intr_route(void *, int, struct cpu_info *); +void arm_intr_cpu_enable(void); +void *arm_intr_parent_establish_fdt(void *, int *, int, + struct cpu_info *ci, int (*)(void *), void *, char *); +void arm_intr_parent_disestablish_fdt(void *); + +void arm_send_ipi(struct cpu_info *, int); +extern void (*intr_send_ipi_func)(struct cpu_info *, int); + +#define ARM_IPI_NOP 0 +#define ARM_IPI_DDB 1 +#define ARM_IPI_HALT 2 + +#ifdef DIAGNOSTIC +/* + * Although this function is implemented in MI code, it must be in this MD + * header because we don't want this header to include MI includes. + */ +void splassert_fail(int, int, const char *); +extern int splassert_ctl; +void arm_splassert_check(int, const char *); +#define splassert(__wantipl) do { \ + if (splassert_ctl > 0) { \ + arm_splassert_check(__wantipl, __func__); \ + } \ +} while (0) +#define splsoftassert(wantipl) splassert(wantipl) +#else +#define splassert(wantipl) do { /* nothing */ } while (0) +#define splsoftassert(wantipl) do { /* nothing */ } while (0) +#endif + +#endif /* ! _LOCORE */ + +#endif /* _KERNEL */ + +#endif /* _MACHINE_INTR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/kcore.h b/lib/libc/include/aarch64-openbsd-none/machine/kcore.h new file mode 100644 index 0000000000..a65c7257a0 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/kcore.h @@ -0,0 +1,15 @@ +/* $OpenBSD: kcore.h,v 1.1 2016/12/17 23:38:33 patrick Exp $ */ +/* public domain */ + +/* Make sure this is larger than DRAM_BLOCKS on all arm-based platforms */ +#define NPHYS_RAM_SEGS 8 + +typedef struct cpu_kcore_hdr { + u_int64_t kernelbase; /* value of KERNEL_BASE */ + u_int64_t kerneloffs; /* offset of kernel in RAM */ + u_int64_t staticsize; /* size of contiguous mapping */ + u_int64_t pmap_kernel_l1; /* pmap_kernel()->pm_l1 */ + u_int64_t pmap_kernel_l2; /* pmap_kernel()->pm_l2 */ + u_int64_t reserved[11]; + phys_ram_seg_t ram_segs[NPHYS_RAM_SEGS]; +} cpu_kcore_hdr_t; \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/limits.h b/lib/libc/include/aarch64-openbsd-none/machine/limits.h new file mode 100644 index 0000000000..491b57a52a --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/limits.h @@ -0,0 +1,56 @@ +/* $OpenBSD: limits.h,v 1.1 2016/12/17 23:38:33 patrick Exp $ */ +/* $NetBSD: limits.h,v 1.4 2003/04/28 23:16:18 bjh21 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 + +#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_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/loadfile_machdep.h b/lib/libc/include/aarch64-openbsd-none/machine/loadfile_machdep.h new file mode 100644 index 0000000000..59761f8b7e --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/loadfile_machdep.h @@ -0,0 +1,53 @@ +/* $OpenBSD: loadfile_machdep.h,v 1.2 2019/04/10 04:17:34 deraadt Exp $ */ +/* $NetBSD: loadfile_machdep.h,v 1.1 1999/04/29 03:17:12 tsubai Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * 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. + */ + +#define BOOT_ELF +#define ELFSIZE 64 + +#define LOAD_KERNEL (LOAD_ALL & ~LOAD_TEXTA) +#define COUNT_KERNEL (COUNT_ALL & ~COUNT_TEXTA) + +extern u_long efi_loadaddr; +#define LOADADDR(a) (((((u_long)(a)) + offset)&0x7fffffffff) + \ + efi_loadaddr) +#define ALIGNENTRY(a) ((u_long)(a)) +#define READ(f, b, c) read((f), (void *)LOADADDR(b), (c)) +#define BCOPY(s, d, c) memcpy((void *)LOADADDR(d), (void *)(s), (c)) +#define BZERO(d, c) memset((void *)LOADADDR(d), 0, (c)) +#define WARN(a) (void)(printf a, \ + printf((errno ? ": %s\n" : "\n"), \ + strerror(errno))) +#define PROGRESS(a) (void) printf a +#define ALLOC(a) alloc(a) +#define FREE(a, b) free(a, b) + +void run_loadfile(uint64_t *, int); \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/mplock.h b/lib/libc/include/aarch64-openbsd-none/machine/mplock.h new file mode 100644 index 0000000000..36a2b125ab --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/mplock.h @@ -0,0 +1,10 @@ +/* $OpenBSD: mplock.h,v 1.3 2018/01/05 17:42:35 kettenis Exp $ */ + +/* public domain */ + +#ifndef _MACHINE_MPLOCK_H_ +#define _MACHINE_MPLOCK_H_ + +#define __USE_MI_MPLOCK + +#endif /* !_MACHINE_MPLOCK_H */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/mutex.h b/lib/libc/include/aarch64-openbsd-none/machine/mutex.h new file mode 100644 index 0000000000..f5115c3084 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/mutex.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mutex.h,v 1.5 2018/01/25 15:06:29 mpi Exp $ */ + +#define __USE_MI_MUTEX \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/openpromio.h b/lib/libc/include/aarch64-openbsd-none/machine/openpromio.h new file mode 100644 index 0000000000..3ad9149116 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/openpromio.h @@ -0,0 +1,57 @@ +/* $OpenBSD: openpromio.h,v 1.1 2017/01/23 12:34:06 kettenis Exp $ */ +/* $NetBSD: openpromio.h,v 1.1.1.1 1998/06/20 04:58:52 eeh Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)openpromio.h 8.1 (Berkeley) 6/11/93 + */ + +struct opiocdesc { + int op_nodeid; /* passed or returned node id */ + int op_namelen; /* length of op_name */ + char *op_name; /* pointer to field name */ + int op_buflen; /* length of op_buf (value-result) */ + char *op_buf; /* pointer to field value */ +}; + +#define OPIOCGET _IOWR('O', 1, struct opiocdesc) /* get openprom field */ +#define OPIOCSET _IOW('O', 2, struct opiocdesc) /* set openprom field */ +#define OPIOCNEXTPROP _IOWR('O', 3, struct opiocdesc) /* get next property */ +#define OPIOCGETOPTNODE _IOR('O', 4, int) /* get openprom field */ +#define OPIOCGETNEXT _IOWR('O', 5, int) /* get next node of node */ +#define OPIOCGETCHILD _IOWR('O', 6, int) /* get first child of node */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/param.h b/lib/libc/include/aarch64-openbsd-none/machine/param.h new file mode 100644 index 0000000000..0d7eb0c796 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/param.h @@ -0,0 +1,81 @@ +/* $OpenBSD: param.h,v 1.8 2025/07/07 18:33:36 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 +#endif +#endif + +#define _MACHINE arm64 +#define MACHINE "arm64" +#define _MACHINE_ARCH aarch64 +#define MACHINE_ARCH "aarch64" +#define MID_MACHINE MID_ARM64 + +#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 6 /* pages of u-area */ +#define USPACE (UPAGES * PAGE_SIZE) /* total size of u-area */ +#define USPACE_ALIGN 0 /* u-area alignment 0-none */ +#define __HAVE_USPACE_GUARD + +#define NMBCLUSTERS (64 * 1024) /* max cluster allocation */ + +#ifndef MSGBUFSIZE +#define MSGBUFSIZE (16 * PAGE_SIZE) /* default message buffer size */ +#endif + +#define STACKALIGNBYTES (16 - 1) +#define STACKALIGN(p) ((u_long)(p) &~ STACKALIGNBYTES) + +#define __HAVE_ACPI +#define __HAVE_FDT + +#endif /* _KERNEL */ + +#endif /* _MACHINE_PARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/pcb.h b/lib/libc/include/aarch64-openbsd-none/machine/pcb.h new file mode 100644 index 0000000000..9e4880b7a8 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/pcb.h @@ -0,0 +1,45 @@ +/* $OpenBSD: pcb.h,v 1.8 2025/02/24 13:18:01 jsg Exp $ */ +/* + * Copyright (c) 2016 Dale Rahn + * + * 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_PCB_H_ +#define _MACHINE_PCB_H_ + +#include +#include + +struct trapframe; + +/* + * Warning certain fields must be within 256 bytes of the beginning + * of this structure. + */ +struct pcb { + u_int pcb_flags; +#define PCB_FPU 0x00000001 /* Process had FPU initialized */ +#define PCB_SINGLESTEP 0x00000002 /* Single step process */ +#define PCB_SVE 0x00000004 /* Process had SVE initialized */ + struct trapframe *pcb_tf; + + register_t pcb_sp; /* stack pointer of switchframe */ + + caddr_t pcb_onfault; /* On fault handler */ + struct fpreg pcb_fpstate; /* Floating Point state */ + __uint16_t pcb_sve_p[16]; /* SVE predicate registers */ + __uint16_t pcb_sve_ffr; /* SVE first fault register */ + + void *pcb_tcb; +}; +#endif /* _MACHINE_PCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/pci_machdep.h b/lib/libc/include/aarch64-openbsd-none/machine/pci_machdep.h new file mode 100644 index 0000000000..fec001a5f4 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/pci_machdep.h @@ -0,0 +1,145 @@ +/* $OpenBSD: pci_machdep.h,v 1.13 2025/01/23 11:24:34 kettenis Exp $ */ + +/* + * Copyright (c) 2003-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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. + * + */ + +typedef struct machine_pci_chipset *pci_chipset_tag_t; +typedef uint64_t pcitag_t; + +#define PCITAG_NODE(x) ((x) >> 32) +#define PCITAG_OFFSET(x) ((x) & 0xffffffff) + +/* Supported interrupt types. */ +#define PCI_NONE 0 +#define PCI_INTX 1 +#define PCI_MSI 2 +#define PCI_MSIX 3 + +typedef struct { + pci_chipset_tag_t ih_pc; + pcitag_t ih_tag; + int ih_intrpin; + int ih_type; + bus_dma_tag_t ih_dmat; +} pci_intr_handle_t; + +struct pci_attach_args; + +/* + * Machine-specific PCI structure and type definitions. + * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE. + */ +struct machine_pci_chipset { + void *pc_conf_v; + void (*pc_attach_hook)(struct device *, + struct device *, struct pcibus_attach_args *); + int (*pc_bus_maxdevs)(void *, int); + pcitag_t (*pc_make_tag)(void *, int, int, int); + void (*pc_decompose_tag)(void *, pcitag_t, int *, + int *, int *); + int (*pc_conf_size)(void *, pcitag_t); + pcireg_t (*pc_conf_read)(void *, pcitag_t, int); + void (*pc_conf_write)(void *, pcitag_t, int, pcireg_t); + int (*pc_probe_device_hook)(void *, struct pci_attach_args *); + + void *pc_intr_v; + int (*pc_intr_map)(struct pci_attach_args *, + pci_intr_handle_t *); + int (*pc_intr_map_msi)(struct pci_attach_args *, + pci_intr_handle_t *); + int (*pc_intr_map_msivec)(struct pci_attach_args *, + int, pci_intr_handle_t *); + int (*pc_intr_map_msix)(struct pci_attach_args *, + int, pci_intr_handle_t *); + const char *(*pc_intr_string)(void *, pci_intr_handle_t); + void *(*pc_intr_establish)(void *, pci_intr_handle_t, + int, struct cpu_info *, int (*)(void *), void *, + char *); + void (*pc_intr_disestablish)(void *, void *); +}; + +/* + * Functions provided to machine-independent PCI code. + */ +#define pci_attach_hook(p, s, pba) \ + (*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba)) +#define pci_bus_maxdevs(c, b) \ + (*(c)->pc_bus_maxdevs)((c)->pc_conf_v, (b)) +#define pci_make_tag(c, b, d, f) \ + (*(c)->pc_make_tag)((c)->pc_conf_v, (b), (d), (f)) +#define pci_decompose_tag(c, t, bp, dp, fp) \ + (*(c)->pc_decompose_tag)((c)->pc_conf_v, (t), (bp), (dp), (fp)) +#define pci_conf_size(c, t) \ + (*(c)->pc_conf_size)((c)->pc_conf_v, (t)) +#define pci_conf_read(c, t, r) \ + (*(c)->pc_conf_read)((c)->pc_conf_v, (t), (r)) +#define pci_conf_write(c, t, r, v) \ + (*(c)->pc_conf_write)((c)->pc_conf_v, (t), (r), (v)) +#define pci_probe_device_hook(c, a) \ + (*(c)->pc_probe_device_hook)((c)->pc_conf_v, (a)) +#define pci_intr_map(c, ihp) \ + (*(c)->pa_pc->pc_intr_map)((c), (ihp)) +#define pci_intr_map_msi(c, ihp) \ + (*(c)->pa_pc->pc_intr_map_msi)((c), (ihp)) +#define pci_intr_map_msivec(c, vec, ihp) \ + (*(c)->pa_pc->pc_intr_map_msivec)((c), (vec), (ihp)) +#define pci_intr_map_msix(c, vec, ihp) \ + (*(c)->pa_pc->pc_intr_map_msix)((c), (vec), (ihp)) +#define pci_intr_string(c, ih) \ + (*(c)->pc_intr_string)((c)->pc_intr_v, (ih)) +#define pci_intr_establish(c, ih, l, h, a, nm) \ + (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), NULL, (h), (a),\ + (nm)) +#define pci_intr_establish_cpu(c, ih, l, ci, h, a, nm) \ + (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), (ci), (h), (a),\ + (nm)) +#define pci_intr_disestablish(c, iv) \ + (*(c)->pc_intr_disestablish)((c)->pc_intr_v, (iv)) + +#define pci_min_powerstate(c, t) (PCI_PMCSR_STATE_D3) +#define pci_set_powerstate_md(c, t, s, p) + +#define pci_dev_postattach(a, b) + +void pci_mcfg_init(bus_space_tag_t, bus_addr_t, int, int, int); +pci_chipset_tag_t pci_lookup_segment(int, int); + +int pci_intr_enable_msivec(struct pci_attach_args *, int); + +void pci_msi_enable(pci_chipset_tag_t, pcitag_t, bus_addr_t, uint32_t); +void pci_msix_enable(pci_chipset_tag_t, pcitag_t, bus_space_tag_t, + int, bus_addr_t, uint32_t); +int _pci_intr_map_msi(struct pci_attach_args *, pci_intr_handle_t *); +int _pci_intr_map_msivec(struct pci_attach_args *, int, + pci_intr_handle_t *); +int _pci_intr_map_msix(struct pci_attach_args *, int, pci_intr_handle_t *); + +#define __HAVE_PCI_MSIX + +int pci_msix_table_map(pci_chipset_tag_t, pcitag_t, + bus_space_tag_t, bus_space_handle_t *); +void pci_msix_table_unmap(pci_chipset_tag_t, pcitag_t, + bus_space_tag_t, bus_space_handle_t); \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/pmap.h b/lib/libc/include/aarch64-openbsd-none/machine/pmap.h new file mode 100644 index 0000000000..5f4d7bf5e1 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/pmap.h @@ -0,0 +1,143 @@ +/* $OpenBSD: pmap.h,v 1.29 2025/05/21 09:42:59 kettenis Exp $ */ +/* + * Copyright (c) 2008,2009,2014 Dale Rahn + * + * 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 _ARM64_PMAP_H_ +#define _ARM64_PMAP_H_ + +#ifndef _LOCORE +#include +#include +#include +#endif + + +/* V->P mapping data */ +#define VP_IDX0_CNT 512 +#define VP_IDX0_MASK (VP_IDX0_CNT-1) +#define VP_IDX0_POS 39 +#define VP_IDX1_CNT 512 +#define VP_IDX1_MASK (VP_IDX1_CNT-1) +#define VP_IDX1_POS 30 +#define VP_IDX2_CNT 512 +#define VP_IDX2_MASK (VP_IDX2_CNT-1) +#define VP_IDX2_POS 21 +#define VP_IDX3_CNT 512 +#define VP_IDX3_MASK (VP_IDX3_CNT-1) +#define VP_IDX3_POS 12 + +/* cache flags */ +#define PMAP_CACHE_CI (PMAP_MD0) /* cache inhibit */ +#define PMAP_CACHE_WT (PMAP_MD1) /* writethru */ +#define PMAP_CACHE_WB (PMAP_MD1|PMAP_MD0) /* writeback */ +#define PMAP_CACHE_DEV_NGNRNE (PMAP_MD2) /* device nGnRnE */ +#define PMAP_CACHE_DEV_NGNRE (PMAP_MD2|PMAP_MD0) /* device nGnRE */ +#define PMAP_CACHE_BITS (PMAP_MD0|PMAP_MD1|PMAP_MD2) + +#define PTED_VA_MANAGED_M (PMAP_MD3) +#define PTED_VA_WIRED_M (PMAP_MD3 << 1) + + +#if defined(_KERNEL) && !defined(_LOCORE) +/* + * Pmap stuff + */ + +typedef struct pmap *pmap_t; + +struct pmap { + struct mutex pm_mtx; + union { + struct pmapvp0 *l0; /* virtual to physical table 4 lvl */ + struct pmapvp1 *l1; /* virtual to physical table 3 lvl */ + } pm_vp; + uint64_t pm_pt0pa; + uint64_t pm_asid; + uint64_t pm_guarded; + int have_4_level_pt; + int pm_privileged; + volatile int pm_active; + int pm_refs; /* ref count */ + struct pmap_statistics pm_stats; /* pmap statistics */ + uint64_t pm_apiakey[2]; + uint64_t pm_apdakey[2]; + uint64_t pm_apibkey[2]; + uint64_t pm_apdbkey[2]; + uint64_t pm_apgakey[2]; +}; + +#define PMAP_PA_MASK ~((paddr_t)PAGE_MASK) /* to remove the flags */ +#define PMAP_NOCACHE 0x1 /* non-cacheable memory */ +#define PMAP_DEVICE 0x2 /* device memory */ +#define PMAP_WC PMAP_DEVICE + +#define PG_PMAP_MOD PG_PMAP0 +#define PG_PMAP_REF PG_PMAP1 +#define PG_PMAP_EXE PG_PMAP2 + +// [NCPUS] +extern paddr_t zero_page; +extern paddr_t copy_src_page; +extern paddr_t copy_dst_page; + +void pagezero_cache(vaddr_t); + +extern struct pmap kernel_pmap_; +#define pmap_kernel() (&kernel_pmap_) +#define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count) +#define pmap_wired_count(pmap) ((pmap)->pm_stats.wired_count) + +vaddr_t pmap_bootstrap(long kvo, paddr_t lpt1, long kernelstart, + long kernelend, long ram_start, long ram_end); +void pmap_postinit(void); +void pmap_init_percpu(void); + +void pmap_kenter_cache(vaddr_t va, paddr_t pa, vm_prot_t prot, int cacheable); +void pmap_page_ro(pmap_t pm, vaddr_t va, vm_prot_t prot); +void pmap_page_rw(pmap_t pm, vaddr_t va); + +void pmap_setpauthkeys(struct pmap *); + +paddr_t pmap_steal_avail(size_t size, int align, void **kva); +void pmap_avail_fixup(void); +void pmap_physload_avail(void); + +#define PMAP_GROWKERNEL + +struct pv_entry; + +/* investigate */ +#define pmap_unuse_final(p) do { /* nothing */ } while (0) +int pmap_fault_fixup(pmap_t, vaddr_t, vm_prot_t); + +#define __HAVE_PMAP_MPSAFE_ENTER_COW +#define __HAVE_PMAP_POPULATE +#define __HAVE_PMAP_PURGE + +#endif /* _KERNEL && !_LOCORE */ + +#ifndef _LOCORE +struct vm_page_md { + struct mutex pv_mtx; + LIST_HEAD(,pte_desc) pv_list; +}; + +#define VM_MDPAGE_INIT(pg) do { \ + mtx_init(&(pg)->mdpage.pv_mtx, IPL_VM); \ + LIST_INIT(&((pg)->mdpage.pv_list)); \ +} while (0) +#endif /* _LOCORE */ + +#endif /* _ARM64_PMAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/proc.h b/lib/libc/include/aarch64-openbsd-none/machine/proc.h new file mode 100644 index 0000000000..0b694ab2f4 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/proc.h @@ -0,0 +1,45 @@ +/* $OpenBSD: proc.h,v 1.2 2017/04/13 03:52:25 guenther Exp $ */ +/* $NetBSD: proc.h,v 1.1 2003/04/26 18:39:46 fvdl 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_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/profile.h b/lib/libc/include/aarch64-openbsd-none/machine/profile.h new file mode 100644 index 0000000000..65fa3c7bc5 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/profile.h @@ -0,0 +1,68 @@ +/* $OpenBSD: profile.h,v 1.2 2021/02/17 12:11:45 kettenis Exp $ */ +/* + * Copyright (c) 2015 Dale Rahn + * + * 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 _MCOUNT_DECL void _mcount + +#define MCOUNT_ASM_NAME "__mcount" + +#ifdef __PIC__ +#define PLTSYM "" /* XXX -aarch64 defaults to PLT? */ +#else +#define PLTSYM "" +#endif + +#define MCOUNT \ +__asm__ (".text;" \ + ".align 3;" \ + ".globl " MCOUNT_ASM_NAME ";" \ + ".type " MCOUNT_ASM_NAME ",@function;" \ + MCOUNT_ASM_NAME ":;" \ + " stp x0, x1, [sp, #-160]!;" \ + " stp x2, x3, [sp, #16];" \ + " stp x4, x5, [sp, #32];" \ + " stp x6, x7, [sp, #48];" \ + " stp x8, x9, [sp, #64];" \ + " stp x10,x11,[sp, #80];" \ + " stp x12,x13,[sp, #96];" \ + " stp x14,x15,[sp, #112];" \ + " stp x16,x17,[sp, #128];" \ + " stp x29,lr, [sp, #144];" \ + /* load from pc at 8 off frame pointer */ \ + " ldr x0, [x29, #8];" \ + " mov x1, lr;" \ + " bl " __STRING(_mcount) PLTSYM ";" \ + /* restore argument registers */ \ + " ldp x2, x3, [sp, #16];" \ + " ldp x4, x5, [sp, #32];" \ + " ldp x6, x7, [sp, #48];" \ + " ldp x8, x9, [sp, #64];" \ + " ldp x10,x11,[sp, #80];" \ + " ldp x12,x13,[sp, #96];" \ + " ldp x14,x15,[sp, #112];" \ + " ldp x16,x17,[sp, #128];" \ + " ldp x29,lr, [sp, #144];" \ + " ldp x0, x1, [sp], #160;" \ + " ret;"); + +#ifdef _KERNEL +// Change this to dair read/set, then restore. +#define MCOUNT_ENTER \ +__asm__ ("mrs %x0, daif; msr daifset, #0x3": "=r"(s)); +#define MCOUNT_EXIT \ +__asm__ ("msr daif, %x0":: "r"(s)); + +#endif // _KERNEL \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/pte.h b/lib/libc/include/aarch64-openbsd-none/machine/pte.h new file mode 100644 index 0000000000..980230fc56 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/pte.h @@ -0,0 +1,104 @@ +/* $OpenBSD: pte.h,v 1.10 2024/10/14 12:02:16 jsg Exp $ */ +/* + * Copyright (c) 2014 Dale Rahn + * + * 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 _ARM_PTE_H_ +#define _ARM_PTE_H_ + +/* level X descriptor */ +#define Lx_TYPE_MASK (0x00000003) /* mask of type bits */ +#define Lx_TYPE_S (0x00000001) +#define Lx_TYPE_PT (0x00000003) +// XXX need to investigate use of these +#define Lx_PT_NS (1ULL<<63) +#define Lx_PT_AP00 (0ULL<<61) +#define Lx_PT_AP01 (1ULL<<61) +#define Lx_PT_AP10 (2ULL<<61) +#define Lx_PT_AP11 (3ULL<<61) +#define Lx_PT_XN (1ULL<<60) +#define Lx_PT_PXN (1ULL<<59) +#define Lx_TABLE_ALIGN (4096) + +/* Block and Page attributes */ +/* TODO: Add the upper attributes */ +#define ATTR_MASK_H (0xfff0000000000000ULL) +#define ATTR_MASK_L (0x0000000000000fffULL) +#define ATTR_MASK (ATTR_MASK_H | ATTR_MASK_L) +/* Bits 58:55 are reserved for software */ +#define ATTR_SW_MANAGED (1UL << 56) +#define ATTR_SW_WIRED (1UL << 55) +#define ATTR_UXN (1UL << 54) +#define ATTR_PXN (1UL << 53) +#define ATTR_GP (1UL << 50) +#define ATTR_nG (1 << 11) +#define ATTR_AF (1 << 10) +#define ATTR_SH(x) ((x) << 8) +#define ATTR_AP_RW_BIT (1 << 7) +#define ATTR_AP(x) ((x) << 6) +#define ATTR_AP_MASK ATTR_AP(3) +#define ATTR_NS (1 << 5) +#define ATTR_IDX(x) ((x) << 2) +#define ATTR_IDX_MASK (7 << 2) + +#define PTE_ATTR_DEV_NGNRNE 0 +#define PTE_ATTR_DEV_NGNRE 1 +#define PTE_ATTR_CI 2 +#define PTE_ATTR_WB 3 +#define PTE_ATTR_WT 4 + +#define PTE_MEMATTR_DEV_NGNRNE 0x0 +#define PTE_MEMATTR_DEV_NGNRE 0x1 +#define PTE_MEMATTR_CI 0x5 +#define PTE_MEMATTR_WB 0xf +#define PTE_MEMATTR_WT 0xa + +#define SH_INNER 3 +#define SH_OUTER 2 +#define SH_NONE 0 + +/* Level 0 table, 512GiB per entry */ +#define L0_SHIFT 39 +#define L0_INVAL 0x0 /* An invalid address */ +#define L0_BLOCK 0x1 /* A block */ + /* 0x2 also marks an invalid address */ +#define L0_TABLE 0x3 /* A next-level table */ + +/* Level 1 table, 1GiB per entry */ +#define L1_SHIFT 30 +#define L1_SIZE (1 << L1_SHIFT) +#define L1_OFFSET (L1_SIZE - 1) +#define L1_INVAL L0_INVAL +#define L1_BLOCK L0_BLOCK +#define L1_TABLE L0_TABLE + +/* Level 2 table, 2MiB per entry */ +#define L2_SHIFT 21 +#define L2_SIZE (1 << L2_SHIFT) +#define L2_OFFSET (L2_SIZE - 1) +#define L2_INVAL L0_INVAL +#define L2_BLOCK L0_BLOCK +#define L2_TABLE L0_TABLE + +/* page mapping */ +#define L3_P 0x3 + +#define Ln_ENTRIES (1 << 9) +#define Ln_ADDR_MASK (Ln_ENTRIES - 1) +#define Ln_TABLE_MASK ((1 << 12) - 1) + +/* physical page mask */ +#define PTE_RPGN (((1ULL << 48) - 1) & ~PAGE_MASK) + +#endif /* _ARM_PTE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/ptrace.h b/lib/libc/include/aarch64-openbsd-none/machine/ptrace.h new file mode 100644 index 0000000000..c63c70f29d --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/ptrace.h @@ -0,0 +1,27 @@ +/* $OpenBSD: ptrace.h,v 1.2 2023/06/10 19:30:48 kettenis Exp $ */ +/* + * Copyright (c) 2014 Patrick Wildt + * + * 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 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) +#define PT_PACMASK (PT_FIRSTMACH + 5) + +#ifdef _KERNEL +register_t process_get_pacmask(struct proc *p); +#endif \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/reg.h b/lib/libc/include/aarch64-openbsd-none/machine/reg.h new file mode 100644 index 0000000000..e8cda2d2dc --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/reg.h @@ -0,0 +1,36 @@ +/* $OpenBSD: reg.h,v 1.3 2017/04/11 06:52:13 kettenis Exp $ */ +/* + * Copyright (c) 2014 Patrick Wildt + * + * 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_REG_H_ +#define _MACHINE_REG_H_ + +struct reg { + uint64_t r_reg[30]; + uint64_t r_lr; + uint64_t r_sp; + uint64_t r_pc; + uint64_t r_spsr; + uint64_t r_tpidr; +}; + +struct fpreg { + __uint128_t fp_reg[32]; + uint32_t fp_sr; + uint32_t fp_cr; +}; + +#endif /* !_MACHINE_REG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/reloc.h b/lib/libc/include/aarch64-openbsd-none/machine/reloc.h new file mode 100644 index 0000000000..73ea25bba7 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/reloc.h @@ -0,0 +1,123 @@ +/* $OpenBSD: reloc.h,v 1.2 2017/10/24 20:35:54 guenther Exp $ */ +/* + * AArch64 static relocation types. + */ + +/* Miscellaneous. */ +#define R_ARM_NONE 0 +#define R_AARCH64_TPOFF64 1 /// COMPLETELY WRONG - stub +#define R_AARCH64_NONE 0 + +/* Data. */ +#define R_AARCH64_ABS64 257 +#define R_AARCH64_ABS32 258 +#define R_AARCH64_ABS16 259 +#define R_AARCH64_PREL64 260 +#define R_AARCH64_PREL32 261 +#define R_AARCH64_PREL16 262 + +/* Instructions. */ +#define R_AARCH64_MOVW_UABS_G0 263 +#define R_AARCH64_MOVW_UABS_G0_NC 264 +#define R_AARCH64_MOVW_UABS_G1 265 +#define R_AARCH64_MOVW_UABS_G1_NC 266 +#define R_AARCH64_MOVW_UABS_G2 267 +#define R_AARCH64_MOVW_UABS_G2_NC 268 +#define R_AARCH64_MOVW_UABS_G3 269 + +#define R_AARCH64_MOVW_SABS_G0 270 +#define R_AARCH64_MOVW_SABS_G1 271 +#define R_AARCH64_MOVW_SABS_G2 272 + +#define R_AARCH64_LD_PREL_LO19 273 +#define R_AARCH64_ADR_PREL_LO21 274 +#define R_AARCH64_ADR_PREL_PG_HI21 275 +#define R_AARCH64_ADR_PREL_PG_HI21_NC 276 +#define R_AARCH64_ADD_ABS_LO12_NC 277 +#define R_AARCH64_LDST8_ABS_LO12_NC 278 + +#define R_AARCH64_TSTBR14 279 +#define R_AARCH64_CONDBR19 280 +#define R_AARCH64_JUMP26 282 +#define R_AARCH64_CALL26 283 +#define R_AARCH64_LDST16_ABS_LO12_NC 284 +#define R_AARCH64_LDST32_ABS_LO12_NC 285 +#define R_AARCH64_LDST64_ABS_LO12_NC 286 +#define R_AARCH64_LDST128_ABS_LO12_NC 299 + +#define R_AARCH64_MOVW_PREL_G0 287 +#define R_AARCH64_MOVW_PREL_G0_NC 288 +#define R_AARCH64_MOVW_PREL_G1 289 +#define R_AARCH64_MOVW_PREL_G1_NC 290 +#define R_AARCH64_MOVW_PREL_G2 291 +#define R_AARCH64_MOVW_PREL_G2_NC 292 +#define R_AARCH64_MOVW_PREL_G3 293 + + +#define R_AARCH64_COPY 1024 +#define R_AARCH64_GLOB_DAT 1025 // S + A +#define R_AARCH64_JUMP_SLOT 1026 // S + A +#define R_AARCH64_RELATIVE 1027 // Delta(S) + A +#define R_AARCH64_TLS_DTPREL64 1028 // DTPREL(S+A) +#define R_AARCH64_TLS_DTPMOD64 1029 // LDM(S) +#define R_AARCH64_TLS_TPREL64 1030 // TPREL(S+A) +#define R_AARCH64_TLSDESC 1031 // TLSDESC(S+A) TLS descriptor to be filled +#define R_AARCH64_IRELATIVE 1032 // Indirect(Delta(S) + A) + +// old arm32 defines. +/* Processor specific relocation types */ + +#define R_ARM_NONE 0 +#define R_ARM_PC24 1 +#define R_ARM_ABS32 2 +#define R_ARM_REL32 3 +#define R_ARM_PC13 4 +#define R_ARM_ABS16 5 +#define R_ARM_ABS12 6 +#define R_ARM_THM_ABS5 7 +#define R_ARM_ABS8 8 +#define R_ARM_SBREL32 9 +#define R_ARM_THM_PC22 10 +#define R_ARM_THM_PC8 11 +#define R_ARM_AMP_VCALL9 12 +#define R_ARM_SWI24 13 +#define R_ARM_THM_SWI8 14 +#define R_ARM_XPC25 15 +#define R_ARM_THM_XPC22 16 + +/* 17-31 are reserved for ARM Linux. */ +#define R_ARM_TLS_DTPMOD32 17 +#define R_ARM_TLS_DTPOFF32 18 +#define R_ARM_TLS_TPOFF32 19 + +#define R_ARM_COPY 20 +#define R_ARM_GLOB_DAT 21 +#define R_ARM_JUMP_SLOT 22 +#define R_ARM_RELATIVE 23 +#define R_ARM_GOTOFF 24 +#define R_ARM_GOTPC 25 +#define R_ARM_GOT32 26 +#define R_ARM_PLT32 27 + +#define R_ARM_ALU_PCREL_7_0 32 +#define R_ARM_ALU_PCREL_15_8 33 +#define R_ARM_ALU_PCREL_23_15 34 +#define R_ARM_ALU_SBREL_11_0 35 +#define R_ARM_ALU_SBREL_19_12 36 +#define R_ARM_ALU_SBREL_27_20 37 + +/* 96-111 are reserved to G++. */ +#define R_ARM_GNU_VTENTRY 100 +#define R_ARM_GNU_VTINHERIT 101 +#define R_ARM_THM_PC11 102 +#define R_ARM_THM_PC9 103 + +/* 112-127 are reserved for private experiments. */ + +#define R_ARM_RXPC25 249 +#define R_ARM_RSBREL32 250 +#define R_ARM_THM_RPC22 251 +#define R_ARM_RREL32 252 +#define R_ARM_RABS32 253 +#define R_ARM_RPC24 254 +#define R_ARM_RBASE 255 \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/setjmp.h b/lib/libc/include/aarch64-openbsd-none/machine/setjmp.h new file mode 100644 index 0000000000..098e20281f --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/setjmp.h @@ -0,0 +1,83 @@ +/* $OpenBSD: setjmp.h,v 1.2 2023/04/11 00:45:07 jsg Exp $ */ +/* $NetBSD: setjmp.h,v 1.2 2001/08/25 14:45:59 bjh21 Exp $ */ + +/* + * machine/setjmp.h: machine dependent setjmp-related information. + */ + +#define _JBLEN 64 /* size, in longs, of a jmp_buf */ + +/* + * NOTE: The internal structure of a jmp_buf is *PRIVATE* + * This information is provided as there is software + * that fiddles with this with obtain the stack pointer + * (yes really ! and it's commercial !). + * + * Description of the setjmp buffer + * + * word 0 magic number (dependant on creator) + * 1 - 3 f4 fp register 4 + * 4 - 6 f5 fp register 5 + * 7 - 9 f6 fp register 6 + * 10 - 12 f7 fp register 7 + * 13 fpsr fp status register + * 14 r4 register 4 + * 15 r5 register 5 + * 16 r6 register 6 + * 17 r7 register 7 + * 18 r8 register 8 + * 19 r9 register 9 + * 20 r10 register 10 (sl) + * 21 r11 register 11 (fp) + * 22 r12 register 12 (ip) + * 23 r13 register 13 (sp) + * 24 r14 register 14 (lr) + * 25 signal mask (dependant on magic) + * 26 (con't) + * 27 (con't) + * 28 (con't) + * + * The magic number identifies the jmp_buf and + * how the buffer was created as well as providing + * a sanity check. + * + * A side note I should mention - please do not tamper + * with the floating point fields. While they are + * always saved and restored at the moment this cannot + * be guaranteed especially if the compiler happens + * to be generating soft-float code so no fp + * registers will be used. + * + * Whilst this can be seen an encouraging people to + * use the setjmp buffer in this way I think that it + * is for the best then if changes occur compiles will + * break rather than just having new builds falling over + * mysteriously. + */ + +#define _JB_MAGIC__SETJMP 0x4278f500 +#define _JB_MAGIC_SETJMP 0x4278f501 + +/* Valid for all jmp_buf's */ + +#define _JB_MAGIC 0 +#define _JB_REG_F4 1 +#define _JB_REG_F5 4 +#define _JB_REG_F6 7 +#define _JB_REG_F7 10 +#define _JB_REG_FPSR 13 +#define _JB_REG_R4 14 +#define _JB_REG_R5 15 +#define _JB_REG_R6 16 +#define _JB_REG_R7 17 +#define _JB_REG_R8 18 +#define _JB_REG_R9 19 +#define _JB_REG_R10 20 +#define _JB_REG_R11 21 +#define _JB_REG_R12 22 +#define _JB_REG_R13 23 +#define _JB_REG_R14 24 + +/* Only valid with the _JB_MAGIC_SETJMP magic */ + +#define _JB_SIGMASK 25 \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/signal.h b/lib/libc/include/aarch64-openbsd-none/machine/signal.h new file mode 100644 index 0000000000..fede515def --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/signal.h @@ -0,0 +1,64 @@ +/* $OpenBSD: signal.h,v 1.2 2017/03/12 17:57:12 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. 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. + * + * @(#)signal.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _MACHINE_SIGNAL_H_ +#define _MACHINE_SIGNAL_H_ + +#include + +typedef int sig_atomic_t; + +#if __BSD_VISIBLE || __XPG_VISIBLE >= 420 +/* + * Information pushed on stack when a signal is delivered. + * This is used by the kernel to restore state following + * execution of the signal handler. It is also made available + * to the handler to allow it to restore state properly if + * a non-standard exit is performed. + */ +struct sigcontext { + int __sc_unused; + int sc_mask; /* signal mask to restore */ + + unsigned long sc_sp; + unsigned long sc_lr; + unsigned long sc_elr; + unsigned long sc_spsr; + unsigned long sc_x[30]; + + long sc_cookie; +}; +#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */ +#endif /* !_MACHINE_SIGNAL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/simplebusvar.h b/lib/libc/include/aarch64-openbsd-none/machine/simplebusvar.h new file mode 100644 index 0000000000..be1336cf1f --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/simplebusvar.h @@ -0,0 +1,37 @@ +/* $OpenBSD: simplebusvar.h,v 1.1 2023/09/22 01:10:43 jsg Exp $ */ +/* + * Copyright (c) 2016 Patrick Wildt + * + * 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. + */ + +struct simplebus_softc { + struct device sc_dev; + int sc_node; + bus_space_tag_t sc_iot; + bus_dma_tag_t sc_dmat; + int sc_acells; + int sc_scells; + int sc_pacells; + int sc_pscells; + struct bus_space sc_bus; + struct machine_bus_dma_tag sc_dma; + int *sc_ranges; + int sc_rangeslen; + int *sc_dmaranges; + int sc_dmarangeslen; + int sc_early; + int sc_early_nodes[64]; +}; + +extern void simplebus_attach(struct device *, struct device *, void *); \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/smbiosvar.h b/lib/libc/include/aarch64-openbsd-none/machine/smbiosvar.h new file mode 100644 index 0000000000..5905ff3af6 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/smbiosvar.h @@ -0,0 +1,278 @@ +/* $OpenBSD: smbiosvar.h,v 1.6 2025/07/15 01:09:32 jsg Exp $ */ +/* + * Copyright (c) 2006 Gordon Willem Klok + * Copyright (c) 2005 Jordan Hargrave + * 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 AUTHORS 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 AUTHORS 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_SMBIOSVAR_ +#define _MACHINE_SMBIOSVAR_ + +#define SMBIOS_UUID_NPRESENT 0x1 +#define SMBIOS_UUID_NSET 0x2 + +/* + * Section 3.5 of "UUIDs and GUIDs" found at + * http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt + * specifies the string representation of a UUID. + */ +#define SMBIOS_UUID_REP "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" +#define SMBIOS_UUID_REPLEN 37 /* 16 zero padded values, 4 hyphens, 1 null */ + +struct smbios_entry { + uint8_t mjr; + uint8_t min; + uint8_t *addr; + uint16_t len; + uint16_t count; +}; + +struct smbhdr { + uint32_t sig; /* "_SM_" */ + uint8_t checksum; /* Entry point checksum */ + uint8_t len; /* Entry point structure length */ + uint8_t majrev; /* Specification major revision */ + uint8_t minrev; /* Specification minor revision */ + uint16_t mss; /* Maximum Structure Size */ + uint8_t epr; /* Entry Point Revision */ + uint8_t fa[5]; /* value determined by EPR */ + uint8_t sasig[5]; /* Secondary Anchor "_DMI_" */ + uint8_t sachecksum; /* Secondary Checksum */ + uint16_t size; /* Length of structure table in bytes */ + uint32_t addr; /* Structure table address */ + uint16_t count; /* Number of SMBIOS structures */ + uint8_t rev; /* BCD revision */ +} __packed; + +struct smb3hdr { + uint8_t sig[5]; /* "_SM3_" */ + uint8_t checksum; /* Entry point structure checksum */ + uint8_t len; /* Entry point length */ + uint8_t majrev; /* SMBIOS major version */ + uint8_t minrev; /* SMBIOS minor version */ + uint8_t docrev; /* SMBIOS docrev */ + uint8_t epr; /* Entry point revision */ + uint8_t reserved; /* Reserved */ + uint32_t size; /* Structure table maximum size */ + uint64_t addr; /* Structure table address */ +} __packed; + +struct smbtblhdr { + uint8_t type; + uint8_t size; + uint16_t handle; +} __packed; + +struct smbtable { + struct smbtblhdr *hdr; + void *tblhdr; + uint32_t cookie; +}; + +#define SMBIOS_TYPE_BIOS 0 +#define SMBIOS_TYPE_SYSTEM 1 +#define SMBIOS_TYPE_BASEBOARD 2 +#define SMBIOS_TYPE_ENCLOSURE 3 +#define SMBIOS_TYPE_PROCESSOR 4 +#define SMBIOS_TYPE_MEMCTRL 5 +#define SMBIOS_TYPE_MEMMOD 6 +#define SMBIOS_TYPE_CACHE 7 +#define SMBIOS_TYPE_PORT 8 +#define SMBIOS_TYPE_SLOTS 9 +#define SMBIOS_TYPE_OBD 10 +#define SMBIOS_TYPE_OEM 11 +#define SMBIOS_TYPE_SYSCONFOPT 12 +#define SMBIOS_TYPE_BIOSLANG 13 +#define SMBIOS_TYPE_GROUPASSOC 14 +#define SMBIOS_TYPE_SYSEVENTLOG 15 +#define SMBIOS_TYPE_PHYMEM 16 +#define SMBIOS_TYPE_MEMDEV 17 +#define SMBIOS_TYPE_ECCINFO32 18 +#define SMBIOS_TYPE_MEMMAPARRAYADDR 19 +#define SMBIOS_TYPE_MEMMAPDEVADDR 20 +#define SMBIOS_TYPE_INBUILTPOINT 21 +#define SMBIOS_TYPE_PORTBATT 22 +#define SMBIOS_TYPE_SYSRESET 23 +#define SMBIOS_TYPE_HWSECUIRTY 24 +#define SMBIOS_TYPE_PWRCTRL 25 +#define SMBIOS_TYPE_VOLTPROBE 26 +#define SMBIOS_TYPE_COOLING 27 +#define SMBIOS_TYPE_TEMPPROBE 28 +#define SMBIOS_TYPE_CURRENTPROBE 29 +#define SMBIOS_TYPE_OOB_REMOTEACCESS 30 +#define SMBIOS_TYPE_BIS 31 +#define SMBIOS_TYPE_SBI 32 +#define SMBIOS_TYPE_ECCINFO64 33 +#define SMBIOS_TYPE_MGMTDEV 34 +#define SMBIOS_TYPE_MGTDEVCOMP 35 +#define SMBIOS_TYPE_MGTDEVTHRESH 36 +#define SMBIOS_TYPE_MEMCHANNEL 37 +#define SMBIOS_TYPE_IPMIDEV 38 +#define SMBIOS_TYPE_SPS 39 +#define SMBIOS_TYPE_INACTIVE 126 +#define SMBIOS_TYPE_EOT 127 + +/* + * SMBIOS Structure Type 0 "BIOS Information" + * DMTF Specification DSP0134 Section: 3.3.1 p.g. 34 + */ +struct smbios_struct_bios { + uint8_t vendor; /* string */ + uint8_t version; /* string */ + uint16_t startaddr; + uint8_t release; /* string */ + uint8_t romsize; + uint64_t characteristics; + uint32_t charext; + uint8_t major_rel; + uint8_t minor_rel; + uint8_t ecf_mjr_rel; /* embedded controller firmware */ + uint8_t ecf_min_rel; /* embedded controller firmware */ +} __packed; + +/* + * SMBIOS Structure Type 1 "System Information" + * DMTF Specification DSP0134 Section 3.3.2 p.g. 35 + */ + +struct smbios_sys { +/* SMBIOS spec 2.0+ */ + uint8_t vendor; /* string */ + uint8_t product; /* string */ + uint8_t version; /* string */ + uint8_t serial; /* string */ +/* SMBIOS spec 2.1+ */ + uint8_t uuid[16]; + uint8_t wakeup; +/* SMBIOS spec 2.4+ */ + uint8_t sku; /* string */ + uint8_t family; /* string */ +} __packed; + +/* + * SMBIOS Structure Type 2 "Base Board (Module) Information" + * DMTF Specification DSP0134 Section 3.3.3 p.g. 37 + */ +struct smbios_board { + uint8_t vendor; /* string */ + uint8_t product; /* string */ + uint8_t version; /* string */ + uint8_t serial; /* string */ + uint8_t asset; /* string */ + uint8_t feature; /* feature flags */ + uint8_t location; /* location in chassis */ + uint16_t handle; /* chassis handle */ + uint8_t type; /* board type */ + uint8_t noc; /* number of contained objects */ +} __packed; + +/* + * SMBIOS Structure Type 3 "System Enclosure or Chassis" + * DMTF Specification DSP0134 + */ +struct smbios_enclosure { + /* SMBIOS spec 2.0+ */ + uint8_t vendor; /* string */ + uint8_t type; + uint8_t version; /* string */ + uint8_t serial; /* string */ + uint8_t asset_tag; /* string */ + /* SMBIOS spec 2.1+ */ + uint8_t boot_state; + uint8_t psu_state; + uint8_t thermal_state; + uint8_t security_status; + /* SMBIOS spec 2.3+ */ + uint16_t oem_defined; + uint8_t height; + uint8_t no_power_cords; + uint8_t no_contained_element; + uint8_t reclen_contained_element; + uint8_t contained_elements; + /* SMBIOS spec 2.7+ */ + uint8_t sku; /* string */ +} __packed; + +/* + * SMBIOS Structure Type 4 "processor Information" + * DMTF Specification DSP0134 v2.5 Section 3.3.5 p.g. 24 + */ +struct smbios_cpu { + uint8_t cpu_socket_designation; /* string */ + uint8_t cpu_type; + uint8_t cpu_family; + uint8_t cpu_mfg; /* string */ + uint32_t cpu_id_eax; + uint32_t cpu_id_edx; + uint8_t cpu_version; /* string */ + uint8_t cpu_voltage; + uint16_t cpu_clock; + uint16_t cpu_max_speed; + uint16_t cpu_current_speed; + uint8_t cpu_status; +#define SMBIOS_CPUST_POPULATED (1<<6) +#define SMBIOS_CPUST_STATUSMASK (0x07) + uint8_t cpu_upgrade; + uint16_t cpu_l1_handle; + uint16_t cpu_l2_handle; + uint16_t cpu_l3_handle; + uint8_t cpu_serial; /* string */ + uint8_t cpu_asset_tag; /* string */ + uint8_t cpu_part_nr; /* string */ + /* following fields were added in smbios 2.5 */ + uint8_t cpu_core_count; + uint8_t cpu_core_enabled; + uint8_t cpu_thread_count; + uint16_t cpu_characteristics; +} __packed; + +/* + * SMBIOS Structure Type 38 "IPMI Information" + * DMTF Specification DSP0134 Section 3.3.39 p.g. 91 + */ +struct smbios_ipmi { + uint8_t smipmi_if_type; /* IPMI Interface Type */ + uint8_t smipmi_if_rev; /* BCD IPMI Revision */ + uint8_t smipmi_i2c_address; /* I2C address of BMC */ + uint8_t smipmi_nvram_address; /* I2C address of NVRAM + * storage */ + uint64_t smipmi_base_address; /* Base address of BMC (BAR + * format */ + uint8_t smipmi_base_flags; /* Flags field: + * bit 7:6 : register spacing + * 00 = byte + * 01 = dword + * 02 = word + * bit 4 : Lower bit BAR + * bit 3 : IRQ valid + * bit 2 : N/A + * bit 1 : Interrupt polarity + * bit 0 : Interrupt trigger */ + uint8_t smipmi_irq; /* IRQ if applicable */ +} __packed; + +int smbios_find_table(uint8_t, struct smbtable *); +char *smbios_get_string(struct smbtable *, uint8_t, char *, size_t); + +#endif \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/spinlock.h b/lib/libc/include/aarch64-openbsd-none/machine/spinlock.h new file mode 100644 index 0000000000..01f502df0f --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/spinlock.h @@ -0,0 +1,25 @@ +/* $OpenBSD: spinlock.h,v 1.2 2017/09/05 02:40:54 guenther Exp $ */ +/* + * Copyright (c) 2014 Patrick Wildt + * + * 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 \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/sysarch.h b/lib/libc/include/aarch64-openbsd-none/machine/sysarch.h new file mode 100644 index 0000000000..b2b0360289 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/sysarch.h @@ -0,0 +1,21 @@ +/* $OpenBSD: sysarch.h,v 1.1 2016/12/17 23:38:33 patrick Exp $ */ +/* + * Copyright (c) 2016 Dale Rahn + * + * 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_SYSARCH_H_ + +// aarch64 architecture has no libarch or arch specific syscalls. + +#endif /* !_MACHINE_SYSARCH_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/tcb.h b/lib/libc/include/aarch64-openbsd-none/machine/tcb.h new file mode 100644 index 0000000000..6d129af20a --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/tcb.h @@ -0,0 +1,58 @@ +/* $OpenBSD: tcb.h,v 1.2 2017/01/10 13:13:12 patrick Exp $ */ + +/* + * Copyright (c) 2011 Philip Guenther + * + * 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 + +#include + +static inline void +__aarch64_set_tcb(void *tcb) +{ + __asm volatile("msr tpidr_el0, %x0" : : "r" (tcb)); +} + +#define TCB_GET(p) \ + ((struct pcb *)(p)->p_addr)->pcb_tcb + +#define TCB_SET(p, addr) \ + do { \ + ((struct pcb *)(p)->p_addr)->pcb_tcb = (addr); \ + __aarch64_set_tcb(addr); \ + } while (0) + +#else /* _KERNEL */ + +/* ELF TLS ABI calls for small TCB, with static TLS data after it */ +#define TLS_VARIANT 1 + +static inline void * +__aarch64_read_tcb(void) +{ + void *tcb; + __asm volatile("mrs %x0, tpidr_el0": "=r" (tcb)); + return tcb; +} + +#define TCB_GET() __aarch64_read_tcb() + +#endif /* _KERNEL */ + +#endif /* _MACHINE_TCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/timetc.h b/lib/libc/include/aarch64-openbsd-none/machine/timetc.h new file mode 100644 index 0000000000..ef326e8aca --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/timetc.h @@ -0,0 +1,24 @@ +/* $OpenBSD: timetc.h,v 1.3 2023/01/09 15:22:53 kettenis Exp $ */ +/* + * Copyright (c) 2020 Paul Irofti + * + * 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_TIMETC_H_ +#define _MACHINE_TIMETC_H_ + +#define TC_AGTIMER 1 +#define TC_AGTIMER_SUN50I 2 + +#endif /* _MACHINE_TIMETC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/vmmvar.h b/lib/libc/include/aarch64-openbsd-none/machine/vmmvar.h new file mode 100644 index 0000000000..7d15621280 --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/vmmvar.h @@ -0,0 +1,93 @@ +/* $OpenBSD: vmmvar.h,v 1.3 2025/08/03 10:17:33 tb Exp $ */ +/* + * Copyright (c) 2014 Mike Larkin + * + * 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. + */ + +/* + * CPU capabilities for VMM operation + */ +#ifndef _MACHINE_VMMVAR_H_ +#define _MACHINE_VMMVAR_H_ + +#define VMM_HV_SIGNATURE "OpenBSDVMM58" + +/* Exit Reasons */ +#define VM_EXIT_TERMINATED 0xFFFE +#define VM_EXIT_NONE 0xFFFF + +struct vmm_softc_md { + /* Capabilities */ + uint32_t nr_cpus; /* [I] */ +}; + +/* + * struct vcpu_inject_event : describes an exception or interrupt to inject. + */ +struct vcpu_inject_event { + uint8_t vie_vector; /* Exception or interrupt vector. */ + uint32_t vie_errorcode; /* Optional error code. */ + uint8_t vie_type; +#define VCPU_INJECT_NONE 0 +#define VCPU_INJECT_INTR 1 /* External hardware interrupt. */ +#define VCPU_INJECT_EX 2 /* HW or SW Exception */ +#define VCPU_INJECT_NMI 3 /* Non-maskable Interrupt */ +}; + +#define VCPU_REGS_NGPRS 31 + +struct vcpu_reg_state { + uint64_t vrs_gprs[VCPU_REGS_NGPRS]; +}; + +/* + * struct vm_exit + * + * Contains VM exit information communicated to vmd(8). This information is + * gathered by vmm(4) from the CPU on each exit that requires help from vmd. + */ +struct vm_exit { + struct vcpu_reg_state vrs; +}; + +struct vm_intr_params { + /* Input parameters to VMM_IOC_INTR */ + uint32_t vip_vm_id; + uint32_t vip_vcpu_id; + uint16_t vip_intr; +}; + +#define VM_RWREGS_GPRS 0x1 /* read/write GPRs */ +#define VM_RWREGS_ALL (VM_RWREGS_GPRS) + +struct vm_rwregs_params { + /* + * Input/output parameters to VMM_IOC_READREGS / + * VMM_IOC_WRITEREGS + */ + uint32_t vrwp_vm_id; + uint32_t vrwp_vcpu_id; + uint64_t vrwp_mask; + struct vcpu_reg_state vrwp_regs; +}; + +enum { + VEI_DIR_OUT, + VEI_DIR_IN +}; + +/* IOCTL definitions */ +#define VMM_IOC_INTR _IOW('V', 6, struct vm_intr_params) /* Intr pending */ + +#endif /* ! _MACHINE_VMMVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/aarch64-openbsd-none/machine/vmparam.h b/lib/libc/include/aarch64-openbsd-none/machine/vmparam.h new file mode 100644 index 0000000000..94745e8e1c --- /dev/null +++ b/lib/libc/include/aarch64-openbsd-none/machine/vmparam.h @@ -0,0 +1,108 @@ +/* $OpenBSD: vmparam.h,v 1.9 2023/04/28 18:33:22 robert Exp $ */ +/* $NetBSD: vmparam.h,v 1.1 2003/04/26 18:39:49 fvdl 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. + * + * @(#)vmparam.h 5.9 (Berkeley) 5/12/91 + */ + +#ifndef _MACHINE_VMPARAM_H_ +#define _MACHINE_VMPARAM_H_ + +/* + * Machine dependent constants for arm64. + */ + +#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)64*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 + +/* + * Kernel base + */ +#define KERNEL_BASE 0xffffff8000000000ULL + +/* + * Mach derived constants + */ + +/* user/kernel map constants */ +#define VM_MIN_ADDRESS ((vaddr_t)PAGE_SIZE) +#define USER_SPACE_BITS 39 +#define VM_MAXUSER_ADDRESS ((1ULL << USER_SPACE_BITS) - 0x8000) +#define VM_MAX_ADDRESS VM_MAXUSER_ADDRESS +#ifdef _KERNEL +#define VM_MIN_STACK_ADDRESS (3ULL << (USER_SPACE_BITS - 2)) +#endif +#define VM_MIN_KERNEL_ADDRESS ((vaddr_t)0xffffff8000000000ULL) +#define VM_MAX_KERNEL_ADDRESS ((vaddr_t)0xffffff83ffffffffULL) + +/* virtual sizes (bytes) for various kernel submaps */ +#define VM_PHYS_SIZE (USRIOSIZE*PAGE_SIZE) + +#define VM_PHYSSEG_MAX 32 +#define VM_PHYSSEG_STRAT VM_PSTRAT_BSEARCH +#define VM_PHYSSEG_NOADD /* can't add RAM after vm_mem_init */ + +#endif /* _MACHINE_VMPARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/_float.h b/lib/libc/include/arm-openbsd-eabi/arm/_float.h new file mode 100644 index 0000000000..3fa7289390 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/_float.h @@ -0,0 +1,84 @@ +/* $OpenBSD: _float.h,v 1.1 2012/06/26 16:12:43 deraadt Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + */ + +#ifndef _MACHINE__FLOAT_H_ +#define _MACHINE__FLOAT_H_ + +#define __FLT_RADIX 2 /* b */ +#define __FLT_ROUNDS __flt_rounds() +#define __FLT_EVAL_METHOD 0 /* no promotions */ + +#define __FLT_MANT_DIG 24 /* p */ +#define __FLT_EPSILON 1.19209290E-7F /* b**(1-p) */ +#define __FLT_DIG 6 /* floor((p-1)*log10(b))+(b == 10) */ +#define __FLT_MIN_EXP (-125) /* emin */ +#define __FLT_MIN 1.17549435E-38F /* b**(emin-1) */ +#define __FLT_MIN_10_EXP (-37) /* ceil(log10(b**(emin-1))) */ +#define __FLT_MAX_EXP 128 /* emax */ +#define __FLT_MAX 3.40282347E+38F /* (1-b**(-p))*b**emax */ +#define __FLT_MAX_10_EXP 38 /* floor(log10((1-b**(-p))*b**emax)) */ + +#define __DBL_MANT_DIG 53 +#define __DBL_EPSILON 2.2204460492503131E-16 +#define __DBL_DIG 15 +#define __DBL_MIN_EXP (-1021) +#define __DBL_MIN 2.2250738585072014E-308 +#define __DBL_MIN_10_EXP (-307) +#define __DBL_MAX_EXP 1024 +#define __DBL_MAX 1.7976931348623157E+308 +#define __DBL_MAX_10_EXP 308 + +#define __LDBL_MANT_DIG DBL_MANT_DIG +#define __LDBL_EPSILON DBL_EPSILON +#define __LDBL_DIG DBL_DIG +#define __LDBL_MIN_EXP DBL_MIN_EXP +#define __LDBL_MIN DBL_MIN +#define __LDBL_MIN_10_EXP DBL_MIN_10_EXP +#define __LDBL_MAX_EXP DBL_MAX_EXP +#define __LDBL_MAX DBL_MAX +#define __LDBL_MAX_10_EXP DBL_MAX_10_EXP + +#define __DECIMAL_DIG 17 + +#endif /* _MACHINE__FLOAT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/_types.h b/lib/libc/include/arm-openbsd-eabi/arm/_types.h new file mode 100644 index 0000000000..5693a7cce1 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/_types.h @@ -0,0 +1,140 @@ +/* $OpenBSD: _types.h,v 1.21 2023/07/02 19:02:27 cheloha 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 _ARM__TYPES_H_ +#define _ARM__TYPES_H_ + +#if defined(_KERNEL) +typedef struct label_t { + long val[11]; +} 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(double) - 1) +#define _STACKALIGNBYTES 7 +#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; +typedef long long __int64_t; +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 +typedef int __wchar_t; +#endif +typedef int __wint_t; +typedef int __rune_t; +typedef void * __wctrans_t; +typedef void * __wctype_t; + +#endif /* _ARM__TYPES_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/apmvar.h b/lib/libc/include/arm-openbsd-eabi/arm/apmvar.h new file mode 100644 index 0000000000..d4b6d11424 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/apmvar.h @@ -0,0 +1,122 @@ +/* $OpenBSD: apmvar.h,v 1.6 2019/01/22 02:36:30 phessler Exp $ */ + +/* + * Copyright (c) 2001 Alexander Guy + * Copyright (c) 1995 John T. Kohl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef _ARM_APMVAR_H_ +#define _ARM_APMVAR_H_ + +#include + +/* Advanced Power Management (v1.0 and v1.1 specification) + * functions/defines/etc. + */ + +/* These definitions make up the heart of the user-land interface + * to the APM devices. + */ + +#define APM_AC_OFF 0x00 +#define APM_AC_ON 0x01 +#define APM_AC_BACKUP 0x02 +#define APM_AC_UNKNOWN 0xff +#define APM_BATT_HIGH 0x00 +#define APM_BATT_LOW 0x01 +#define APM_BATT_CRITICAL 0x02 +#define APM_BATT_CHARGING 0x03 +#define APM_BATT_UNKNOWN 0xff +#define APM_BATT_LIFE_UNKNOWN 0xff + +#define APM_NOEVENT 0x0000 +#define APM_STANDBY_REQ 0x0001 +#define APM_SUSPEND_REQ 0x0002 +#define APM_NORMAL_RESUME 0x0003 +#define APM_CRIT_RESUME 0x0004 /* suspend/resume happened + without us */ +#define APM_BATTERY_LOW 0x0005 +#define APM_POWER_CHANGE 0x0006 +#define APM_UPDATE_TIME 0x0007 +#define APM_CRIT_SUSPEND_REQ 0x0008 +#define APM_USER_STANDBY_REQ 0x0009 +#define APM_USER_SUSPEND_REQ 0x000A +#define APM_SYS_STANDBY_RESUME 0x000B +#define APM_CAPABILITY_CHANGE 0x000C /* apm v1.2 */ +#define APM_USER_HIBERNATE_REQ 0x000D +#define APM_EVENT_MASK 0xffff + +#define APM_EVENT_COMPOSE(t,i) ((((i) & 0x7fff) << 16)|((t) & APM_EVENT_MASK)) +#define APM_EVENT_TYPE(e) ((e) & APM_EVENT_MASK) +#define APM_EVENT_INDEX(e) ((e) >> 16) + +/* + * LP (Laptop Package) + * + * Copyright (C) 1994 by HOSOKAWA Tatsumi + * + * This software may be used, modified, copied, and distributed, in + * both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + */ + +#define APM_BATTERY_ABSENT 4 + +struct apm_power_info { + u_char battery_state; + u_char ac_state; + u_char battery_life; + u_char spare1; + u_int minutes_left; /* estimate */ + u_int spare2[6]; +}; + +struct apm_ctl { + u_int dev; + u_int mode; +}; + +#define APM_IOC_REJECT _IOW('A', 0, struct apm_event_info) /* reject request # */ +#define APM_IOC_STANDBY _IO('A', 1) /* put system into standby */ +#define APM_IOC_SUSPEND _IO('A', 2) /* put system into suspend */ +#define APM_IOC_GETPOWER _IOR('A', 3, struct apm_power_info) /* fetch battery state */ +#define APM_IOC_DEV_CTL _IOW('A', 5, struct apm_ctl) /* put device into mode */ +#define APM_IOC_PRN_CTL _IOW('A', 6, int ) /* driver power status msg */ +#define APM_PRINT_ON 0 /* driver power status displayed */ +#define APM_PRINT_OFF 1 /* driver power status not displayed */ +#define APM_PRINT_PCT 2 /* driver power status only displayed + if the percentage changes */ +#define APM_IOC_STANDBY_REQ _IO('A', 7) /* request standby */ +#define APM_IOC_SUSPEND_REQ _IO('A', 8) /* request suspend */ +#define APM_IOC_HIBERNATE _IO('A', 9) /* put system into hibernate */ + +#endif /* _ARM_APMVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/armreg.h b/lib/libc/include/arm-openbsd-eabi/arm/armreg.h new file mode 100644 index 0000000000..ee51ae5616 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/armreg.h @@ -0,0 +1,392 @@ +/* $OpenBSD: armreg.h,v 1.43 2019/09/30 21:48:32 kettenis Exp $ */ +/* $NetBSD: armreg.h,v 1.27 2003/09/06 08:43:02 rearnsha Exp $ */ + +/* + * Copyright (c) 1998, 2001 Ben Harris + * Copyright (c) 1994-1996 Mark Brinicombe. + * Copyright (c) 1994 Brini. + * All rights reserved. + * + * This code is derived from software written for Brini by Mark Brinicombe + * + * 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 Brini. + * 4. The name of the company nor the name of the author may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY BRINI ``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 BRINI 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 _ARM_ARMREG_H +#define _ARM_ARMREG_H + +/* CCSIDR - Current Cache Size ID Register */ +#define CCSIDR_SETS_MASK 0x0fffe000 +#define CCSIDR_SETS_SHIFT 13 +#define CCSIDR_SETS(reg) \ + ((((reg) & CCSIDR_SETS_MASK) >> CCSIDR_SETS_SHIFT) + 1) +#define CCSIDR_WAYS_MASK 0x00001ff8 +#define CCSIDR_WAYS_SHIFT 3 +#define CCSIDR_WAYS(reg) \ + ((((reg) & CCSIDR_WAYS_MASK) >> CCSIDR_WAYS_SHIFT) + 1) +#define CCSIDR_LINE_MASK 0x00000007 +#define CCSIDR_LINE_SIZE(reg) (1 << (((reg) & CCSIDR_LINE_MASK) + 4)) + +/* CLIDR - Cache Level ID Register */ +#define CLIDR_CTYPE_MASK 0x7 +#define CLIDR_CTYPE_INSN 0x1 +#define CLIDR_CTYPE_DATA 0x2 +#define CLIDR_CTYPE_UNIFIED 0x4 + +/* CSSELR - Cache Size Selection Register */ +#define CSSELR_IND (1 << 0) +#define CSSELR_LEVEL_SHIFT 1 + +/* CTR - Cache Type Register */ +#define CTR_DLINE_SHIFT 16 +#define CTR_DLINE_MASK (0xf << CTR_DLINE_SHIFT) +#define CTR_DLINE_SIZE(reg) (((reg) & CTR_DLINE_MASK) >> CTR_DLINE_SHIFT) +#define CTR_IL1P_SHIFT 14 +#define CTR_IL1P_MASK (0x3 << CTR_IL1P_SHIFT) +#define CTR_IL1P_AIVIVT (0x1 << CTR_IL1P_SHIFT) +#define CTR_IL1P_VIPT (0x2 << CTR_IL1P_SHIFT) +#define CTR_IL1P_PIPT (0x3 << CTR_IL1P_SHIFT) +#define CTR_ILINE_SHIFT 0 +#define CTR_ILINE_MASK (0xf << CTR_ILINE_SHIFT) +#define CTR_ILINE_SIZE(reg) (((reg) & CTR_ILINE_MASK) >> CTR_ILINE_SHIFT) + +/* + * ARM Process Status Register + * + * The picture in early ARM manuals looks like this: + * 3 3 2 2 2 2 + * 1 0 9 8 7 6 8 7 6 5 4 0 + * +-+-+-+-+-+-------------------------------------+-+-+-+---------+ + * |N|Z|C|V|Q| reserved |I|F|T|M M M M M| + * | | | | | | | | | |4 3 2 1 0| + * +-+-+-+-+-+-------------------------------------+-+-+-+---------+ + * + * The picture in the ARMv7-A manuals looks like this: + * 3 3 2 2 2 2 2 2 2 2 1 1 1 1 + * 1 0 9 8 7 6 5 4 3 0 9 6 5 0 9 8 7 6 5 4 0 + * +-+-+-+-+-+---+-+-------+-------+-----------+-+-+-+-+-+---------+ + * |N|Z|C|V|Q|I I|J|reserv-|G G G G|I I I I I I|E|A|I|F|T|M M M M M| + * | | | | | |T T| |ed |E E E E|T T T T T T| | | | | | | + * | | | | | |1 0| | |3 2 1 0|7 6 5 4 3 2| | | | | |4 3 2 1 0| + * +-+-+-+-+-+---+-+-------+-------+-----------+-+-+-+-+-+---------+ + * | flags 'f' | status 's' | extension 'x' | control 'c' | + */ + +#define PSR_FLAGS 0xf0000000 /* flags */ +#define PSR_N (1U << 31) /* negative */ +#define PSR_Z (1 << 30) /* zero */ +#define PSR_C (1 << 29) /* carry */ +#define PSR_V (1 << 28) /* overflow */ + +#define PSR_Q (1 << 27) /* saturation */ + +#define PSR_A (1 << 8) /* Asynchronous abort disable */ +#define PSR_I (1 << 7) /* IRQ disable */ +#define PSR_F (1 << 6) /* FIQ disable */ + +#define PSR_T (1 << 5) /* Thumb state */ +#define PSR_J (1 << 24) /* Java mode */ + +#define PSR_MODE 0x0000001f /* mode mask */ +#define PSR_USR26_MODE 0x00000000 +#define PSR_FIQ26_MODE 0x00000001 +#define PSR_IRQ26_MODE 0x00000002 +#define PSR_SVC26_MODE 0x00000003 +#define PSR_USR32_MODE 0x00000010 +#define PSR_FIQ32_MODE 0x00000011 +#define PSR_IRQ32_MODE 0x00000012 +#define PSR_SVC32_MODE 0x00000013 +#define PSR_MON32_MODE 0x00000016 +#define PSR_ABT32_MODE 0x00000017 +#define PSR_HYP32_MODE 0x0000001a +#define PSR_UND32_MODE 0x0000001b +#define PSR_SYS32_MODE 0x0000001f +#define PSR_32_MODE 0x00000010 + +#define PSR_IN_USR_MODE(psr) (!((psr) & 3)) /* XXX */ + +/* + * Co-processor 15: The system control co-processor. + */ + +#define ARM_CP15_CPU_ID 0 + +/* + * The CPU ID register is theoretically structured, but the definitions of + * the fields keep changing. + */ + +/* The high-order byte is always the implementor */ +#define CPU_ID_IMPLEMENTOR_MASK 0xff000000 +#define CPU_ID_ARM_LTD 0x41000000 /* 'A' */ + +#define CPU_ID_ARCH_MASK 0x000f0000 +#define CPU_ID_ARCH_V6 0x00070000 +#define CPU_ID_ARCH_CPUID 0x000f0000 +#define CPU_ID_VARIANT_MASK 0x00f00000 + +/* Next three nybbles are part number */ +#define CPU_ID_PARTNO_MASK 0x0000fff0 + +/* And finally, the revision number. */ +#define CPU_ID_REVISION_MASK 0x0000000f + +/* Individual CPUs are probably best IDed by everything but the revision. */ +#define CPU_ID_CPU_MASK 0xfffffff0 +#define CPU_ID_CORTEX_MASK 0xff0ffff0 +#define CPU_ID_CORTEX_A5 0x410fc050 +#define CPU_ID_CORTEX_A5_MASK 0xff0ffff0 +#define CPU_ID_CORTEX_A7 0x410fc070 +#define CPU_ID_CORTEX_A7_MASK 0xff0ffff0 +#define CPU_ID_CORTEX_A8_R1 0x411fc080 +#define CPU_ID_CORTEX_A8_R2 0x412fc080 +#define CPU_ID_CORTEX_A8_R3 0x413fc080 +#define CPU_ID_CORTEX_A8 0x410fc080 +#define CPU_ID_CORTEX_A8_MASK 0xff0ffff0 +#define CPU_ID_CORTEX_A9 0x410fc090 +#define CPU_ID_CORTEX_A9_R1 0x411fc090 +#define CPU_ID_CORTEX_A9_R2 0x412fc090 +#define CPU_ID_CORTEX_A9_R3 0x413fc090 +#define CPU_ID_CORTEX_A9_R4 0x414fc090 +#define CPU_ID_CORTEX_A9_MASK 0xff0ffff0 +#define CPU_ID_CORTEX_A12 0x410fc0d0 +#define CPU_ID_CORTEX_A12_MASK 0xff0ffff0 +#define CPU_ID_CORTEX_A15 0x410fc0f0 +#define CPU_ID_CORTEX_A15_R1 0x411fc0f0 +#define CPU_ID_CORTEX_A15_R2 0x412fc0f0 +#define CPU_ID_CORTEX_A15_R3 0x413fc0f0 +#define CPU_ID_CORTEX_A15_R4 0x414fc0f0 +#define CPU_ID_CORTEX_A15_MASK 0xff0ffff0 +#define CPU_ID_CORTEX_A17 0x410fc0e0 +#define CPU_ID_CORTEX_A17_R1 0x411fc0e0 +#define CPU_ID_CORTEX_A17_MASK 0xff0ffff0 +#define CPU_ID_CORTEX_A32 0x410fd010 +#define CPU_ID_CORTEX_A32_MASK 0xff0ffff0 +#define CPU_ID_CORTEX_A35 0x410fd040 +#define CPU_ID_CORTEX_A35_MASK 0xff0ffff0 +#define CPU_ID_CORTEX_A53 0x410fd030 +#define CPU_ID_CORTEX_A53_R1 0x411fd030 +#define CPU_ID_CORTEX_A53_MASK 0xff0ffff0 +#define CPU_ID_CORTEX_A55 0x410fd050 +#define CPU_ID_CORTEX_A55_MASK 0xff0ffff0 +#define CPU_ID_CORTEX_A57 0x410fd070 +#define CPU_ID_CORTEX_A57_R1 0x411fd070 +#define CPU_ID_CORTEX_A57_MASK 0xff0ffff0 +#define CPU_ID_CORTEX_A72 0x410fd080 +#define CPU_ID_CORTEX_A72_R1 0x411fd080 +#define CPU_ID_CORTEX_A72_MASK 0xff0ffff0 +#define CPU_ID_CORTEX_A73 0x410fd090 +#define CPU_ID_CORTEX_A73_MASK 0xff0ffff0 +#define CPU_ID_CORTEX_A75 0x410fd0a0 +#define CPU_ID_CORTEX_A75_MASK 0xff0ffff0 + +/* CPUID on >= v7 */ +#define ID_MMFR0_VMSA_MASK 0x0000000f + +#define VMSA_V7 3 +#define VMSA_V7_PXN 4 +#define VMSA_V7_LDT 5 + +/* + * Post-ARM3 CP15 registers: + * + * 1 Control register + * + * 2 Translation Table Base + * + * 3 Domain Access Control + * + * 4 Reserved + * + * 5 Fault Status + * + * 6 Fault Address + * + * 7 Cache/write-buffer Control + * + * 8 TLB Control + * + * 9 Cache Lockdown + * + * 10 TLB Lockdown + * + * 11 Reserved + * + * 12 Reserved + * + * 13 Process ID (for FCSE) + * + * 14 Reserved + * + * 15 Implementation Dependent + */ + +/* Some of the definitions below need cleaning up for V3/V4 architectures */ + +/* CPU control register (CP15 register 1) */ +#define CPU_CONTROL_MMU_ENABLE 0x00000001 /* M: MMU/Protection unit enable */ +#define CPU_CONTROL_AFLT_ENABLE 0x00000002 /* A: Alignment fault enable */ +#define CPU_CONTROL_DC_ENABLE 0x00000004 /* C: IDC/DC enable */ +#define CPU_CONTROL_WBUF_ENABLE 0x00000008 /* W: Write buffer enable */ +#define CPU_CONTROL_32BP_ENABLE 0x00000010 /* P: 32-bit exception handlers */ +#define CPU_CONTROL_32BD_ENABLE 0x00000020 /* D: 32-bit addressing */ +#define CPU_CONTROL_LABT_ENABLE 0x00000040 /* L: Late abort enable */ +#define CPU_CONTROL_BEND_ENABLE 0x00000080 /* B: Big-endian mode */ +#define CPU_CONTROL_SYST_ENABLE 0x00000100 /* S: System protection bit */ +#define CPU_CONTROL_ROM_ENABLE 0x00000200 /* R: ROM protection bit */ +#define CPU_CONTROL_CPCLK 0x00000400 /* F: Implementation defined */ +#define CPU_CONTROL_BPRD_ENABLE 0x00000800 /* Z: Branch prediction enable */ +#define CPU_CONTROL_IC_ENABLE 0x00001000 /* I: IC enable */ +#define CPU_CONTROL_VECRELOC 0x00002000 /* V: Vector relocation */ +#define CPU_CONTROL_ROUNDROBIN 0x00004000 /* RR: Predictable replacement */ +#define CPU_CONTROL_V4COMPAT 0x00008000 /* L4: ARMv4 compat LDR R15 etc */ + +/* below were added by V6 */ +#define CPU_CONTROL_FI (1<<21) /* FI: fast interrupts */ +#define CPU_CONTROL_U (1<<22) /* U: Unaligned */ +#define CPU_CONTROL_VE (1<<24) /* VE: Vector enable */ +#define CPU_CONTROL_EE (1<<25) /* EE: Exception Endianness */ +#define CPU_CONTROL_L2 (1<<25) /* L2: L2 cache enable */ + +/* added with v7 */ +#define CPU_CONTROL_WXN (1<<19) /* WXN: Write implies XN */ +#define CPU_CONTROL_UWXN (1<<20) /* UWXN: Unpriv write implies XN */ +#define CPU_CONTROL_NMFI (1<<27) /* NMFI: Non Maskable fast interrupt */ +#define CPU_CONTROL_TRE (1<<28) /* TRE: TEX Remap Enable */ +#define CPU_CONTROL_AFE (1<<29) /* AFE: Access Flag Enable */ +#define CPU_CONTROL_TE (1<<30) /* TE: Thumb Exception Enable */ + +#define CPU_CONTROL_IDC_ENABLE CPU_CONTROL_DC_ENABLE + +/* Cortex-A9 Auxiliary Control Register (CP15 register 1, opcode 1) */ +#define CORTEXA9_AUXCTL_FW (1 << 0) /* Cache and TLB updates broadcast */ +#define CORTEXA9_AUXCTL_L2PE (1 << 1) /* Prefetch hint enable */ +#define CORTEXA9_AUXCTL_L1PE (1 << 2) /* Data prefetch hint enable */ +#define CORTEXA9_AUXCTL_WR_ZERO (1 << 3) /* Ena. write full line of 0s mode */ +#define CORTEXA9_AUXCTL_SMP (1 << 6) /* Coherency is active */ +#define CORTEXA9_AUXCTL_EXCL (1 << 7) /* Exclusive cache bit */ +#define CORTEXA9_AUXCTL_ONEWAY (1 << 8) /* Allocate in on cache way only */ +#define CORTEXA9_AUXCTL_PARITY (1 << 9) /* Support parity checking */ + +/* Cache type register definitions */ +#define CPU_CT_ISIZE(x) ((x) & 0xfff) /* I$ info */ +#define CPU_CT_DSIZE(x) (((x) >> 12) & 0xfff) /* D$ info */ +#define CPU_CT_S (1U << 24) /* split cache */ +#define CPU_CT_CTYPE(x) (((x) >> 25) & 0xf) /* cache type */ +/* Cache type register definitions for ARM v7 */ +#define CPU_CT_IMINLINE(x) ((x) & 0xf) /* I$ min line size */ +#define CPU_CT_DMINLINE(x) (((x) >> 16) & 0xf) /* D$ min line size */ + +#define CPU_CT_CTYPE_WT 0 /* write-through */ +#define CPU_CT_CTYPE_WB1 1 /* write-back, clean w/ read */ +#define CPU_CT_CTYPE_WB2 2 /* w/b, clean w/ cp15,7 */ +#define CPU_CT_CTYPE_WB6 6 /* w/b, cp15,7, lockdown fmt A */ +#define CPU_CT_CTYPE_WB7 7 /* w/b, cp15,7, lockdown fmt B */ + +#define CPU_CT_xSIZE_LEN(x) ((x) & 0x3) /* line size */ +#define CPU_CT_xSIZE_M (1U << 2) /* multiplier */ +#define CPU_CT_xSIZE_ASSOC(x) (((x) >> 3) & 0x7) /* associativity */ +#define CPU_CT_xSIZE_SIZE(x) (((x) >> 6) & 0x7) /* size */ + +/* MPIDR, Multiprocessor Affinity Register */ +#define MPIDR_AFF2 (0xffU << 16) +#define MPIDR_AFF1 (0xffU << 8) +#define MPIDR_AFF0 (0xffU << 0) +#define MPIDR_AFF (MPIDR_AFF2|MPIDR_AFF1|MPIDR_AFF0) + +/* Fault status register definitions */ + +#define FAULT_USER 0x20 + +#define FAULT_WRTBUF_0 0x00 /* Vector Exception */ +#define FAULT_WRTBUF_1 0x02 /* Terminal Exception */ +#define FAULT_BUSERR_0 0x04 /* External Abort on Linefetch -- Section */ +#define FAULT_BUSERR_1 0x06 /* External Abort on Linefetch -- Page */ +#define FAULT_BUSERR_2 0x08 /* External Abort on Non-linefetch -- Section */ +#define FAULT_BUSERR_3 0x0a /* External Abort on Non-linefetch -- Page */ +#define FAULT_BUSTRNL1 0x0c /* External abort on Translation -- Level 1 */ +#define FAULT_BUSTRNL2 0x0e /* External abort on Translation -- Level 2 */ +#define FAULT_ALIGN_0 0x01 /* Alignment */ +#define FAULT_ALIGN_1 0x03 /* Alignment */ +#define FAULT_TRANS_S 0x05 /* Translation -- Section */ +#define FAULT_TRANS_P 0x07 /* Translation -- Page */ +#define FAULT_DOMAIN_S 0x09 /* Domain -- Section */ +#define FAULT_DOMAIN_P 0x0b /* Domain -- Page */ +#define FAULT_PERM_S 0x0d /* Permission -- Section */ +#define FAULT_PERM_P 0x0f /* Permission -- Page */ + +/* Fault type definitions for ARM v7 */ +#define FAULT_ACCESS_1 0x03 /* Access flag fault -- Level 1 */ +#define FAULT_ACCESS_2 0x06 /* Access flag fault -- Level 2 */ + +#define FAULT_IMPRECISE 0x400 /* Imprecise exception (XSCALE) */ + +#define FAULT_EXT 0x00001000 /* external abort */ +#define FAULT_WNR 0x00000800 /* write fault */ + +#define FAULT_TYPE(fsr) ((fsr) & 0x0f) +#define FAULT_TYPE_V7(fsr) (((fsr) & 0x0f) | (((fsr) & 0x00000400) >> 6)) + +/* + * Address of the vector page, low and high versions. + */ +#define ARM_VECTORS_LOW 0x00000000U +#define ARM_VECTORS_HIGH 0xffff0000U + +/* + * ARM Instructions + * + * 3 3 2 2 2 + * 1 0 9 8 7 0 + * +-------+-------------------------------------------------------+ + * | cond | instruction dependant | + * |c c c c| | + * +-------+-------------------------------------------------------+ + */ + +#define INSN_SIZE 4 /* Always 4 bytes */ +#define INSN_COND_MASK 0xf0000000 /* Condition mask */ +#define INSN_COND_AL 0xe0000000 /* Always condition */ + +/* Translation Table Base Register */ +#define TTBR_C (1 << 0) /* without MPE */ +#define TTBR_S (1 << 1) +#define TTBR_IMP (1 << 2) +#define TTBR_RGN_MASK (3 << 3) +#define TTBR_RGN_NC (0 << 3) +#define TTBR_RGN_WBWA (1 << 3) +#define TTBR_RGN_WT (2 << 3) +#define TTBR_RGN_WBNWA (3 << 3) +#define TTBR_NOS (1 << 5) +#define TTBR_IRGN_MASK ((1 << 0) | (1 << 6)) +#define TTBR_IRGN_NC ((0 << 0) | (0 << 6)) +#define TTBR_IRGN_WBWA ((0 << 0) | (1 << 6)) +#define TTBR_IRGN_WT ((1 << 0) | (0 << 6)) +#define TTBR_IRGN_WBNWA ((1 << 0) | (1 << 6)) + +#endif \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/asm.h b/lib/libc/include/arm-openbsd-eabi/arm/asm.h new file mode 100644 index 0000000000..b39691115c --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/asm.h @@ -0,0 +1,97 @@ +/* $OpenBSD: asm.h,v 1.13 2022/12/08 01:25:44 guenther Exp $ */ +/* $NetBSD: asm.h,v 1.4 2001/07/16 05:43:32 matt 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. + * + * from: @(#)asm.h 5.5 (Berkeley) 5/7/91 + */ + +#ifndef _ARM_ASM_H_ +#define _ARM_ASM_H_ + +#define _C_LABEL(x) x +#define _ASM_LABEL(x) x + +#ifdef __STDC__ +# define __CONCAT(x,y) x ## y +# define __STRING(x) #x +#else +# define __CONCAT(x,y) x/**/y +# define __STRING(x) "x" +#endif + +#ifndef _ALIGN_TEXT +# define _ALIGN_TEXT .align 2 +#endif + +/* + * gas/arm uses @ as a single comment character and thus cannot be used here + * Instead it recognised the # instead of an @ symbols in .type directives + * We define a couple of macros so that assembly code will not be dependant + * on one or the other. + */ +#define _ASM_TYPE_FUNCTION #function +#define _ASM_TYPE_OBJECT #object + +/* NB == No Binding: use .globl or .weak as necessary */ +#define _ENTRY_NB(x) \ + .text; _ALIGN_TEXT; .type x,_ASM_TYPE_FUNCTION; x: +#define _ENTRY(x) .globl x; _ENTRY_NB(x) + +#if defined(PROF) || defined(GPROF) +# define _PROF_PROLOGUE \ + mov ip, lr; bl __mcount +#else +# define _PROF_PROLOGUE +#endif + +#define ENTRY(y) _ENTRY(y); _PROF_PROLOGUE +#define ENTRY_NP(y) _ENTRY(y) +#define ENTRY_NB(y) _ENTRY_NB(y); _PROF_PROLOGUE +#define ASENTRY(y) _ENTRY(y); _PROF_PROLOGUE +#define ASENTRY_NP(y) _ENTRY(y) +#define END(y) .size y, . - y + +#if defined(__PIC__) +#define PIC_SYM(x,y) x(y) +#else +#define PIC_SYM(x,y) x +#endif + +#define STRONG_ALIAS(alias,sym) \ + .global alias; \ + alias = sym +#define WEAK_ALIAS(alias,sym) \ + .weak alias; \ + alias = sym + +#endif /* !_ARM_ASM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/atomic.h b/lib/libc/include/arm-openbsd-eabi/arm/atomic.h new file mode 100644 index 0000000000..beef1c8519 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/atomic.h @@ -0,0 +1,295 @@ +/* $OpenBSD: atomic.h,v 1.19 2022/08/29 02:01:18 jsg Exp $ */ + +/* Public Domain */ + +#ifndef _ARM_ATOMIC_H_ +#define _ARM_ATOMIC_H_ + +/* + * Compare and set: + * ret = *ptr + * if (ret == expect) + * *ptr = new + * return (ret) + */ +#define _def_atomic_cas(_f, _t) \ +static inline _t \ +_f(volatile _t *p, _t e, _t n) \ +{ \ + _t ret, modified; \ + \ + __asm volatile ( \ + "1: ldrex %0, [%4] \n\t" \ + " cmp %0, %3 \n\t" \ + " bne 2f \n\t" \ + " strex %1, %2, [%4] \n\t" \ + " cmp %1, #0 \n\t" \ + " bne 1b \n\t" \ + " b 3f \n\t" \ + "2: clrex \n\t" \ + "3: \n\t" \ + : "=&r" (ret), "=&r" (modified) \ + : "r" (n), "r" (e), "r" (p) \ + : "memory", "cc" \ + ); \ + return (ret); \ +} +_def_atomic_cas(_atomic_cas_uint, unsigned int) +_def_atomic_cas(_atomic_cas_ulong, unsigned long) +#undef _def_atomic_cas + +#define atomic_cas_uint(_p, _e, _n) _atomic_cas_uint((_p), (_e), (_n)) +#define atomic_cas_ulong(_p, _e, _n) _atomic_cas_ulong((_p), (_e), (_n)) + +static inline void * +_atomic_cas_ptr(volatile void *p, void *e, void *n) +{ + void *ret; + unsigned long modified; + + __asm volatile ( + "1: ldrex %0, [%4] \n\t" + " cmp %0, %3 \n\t" + " bne 2f \n\t" + " strex %1, %2, [%4] \n\t" + " cmp %1, #0 \n\t" + " bne 1b \n\t" + " b 3f \n\t" + "2: clrex \n\t" + "3: \n\t" + : "=&r" (ret), "=&r" (modified) + : "r" (n), "r" (e), "r" (p) + : "memory", "cc" + ); + return (ret); +} +#define atomic_cas_ptr(_p, _e, _n) _atomic_cas_ptr((_p), (_e), (_n)) + +/* + * Swap: + * ret = *p + * *p = val + * return (ret) + */ +#define _def_atomic_swap(_f, _t) \ +static inline _t \ +_f(volatile _t *p, _t v) \ +{ \ + _t ret, modified; \ + \ + __asm volatile ( \ + "1: ldrex %0, [%3] \n\t" \ + " strex %1, %2, [%3] \n\t" \ + " cmp %1, #0 \n\t" \ + " bne 1b \n\t" \ + : "=&r" (ret), "=&r" (modified) \ + : "r" (v), "r" (p) \ + : "memory", "cc" \ + ); \ + return (ret); \ +} +_def_atomic_swap(_atomic_swap_uint, unsigned int) +_def_atomic_swap(_atomic_swap_ulong, unsigned long) +#undef _def_atomic_swap + +#define atomic_swap_uint(_p, _v) _atomic_swap_uint((_p), (_v)) +#define atomic_swap_ulong(_p, _v) _atomic_swap_ulong((_p), (_v)) + +static inline void * +_atomic_swap_ptr(volatile void *p, void *v) +{ + void *ret; + unsigned long modified; + + __asm volatile ( + "1: ldrex %0, [%3] \n\t" + " strex %1, %2, [%3] \n\t" + " cmp %1, #0 \n\t" + " bne 1b \n\t" + : "=&r" (ret), "=&r" (modified) + : "r" (v), "r" (p) + : "memory", "cc" + ); + return (ret); +} +#define atomic_swap_ptr(_p, _v) _atomic_swap_ptr((_p), (_v)) + +/* + * Increment returning the new value + * *p += 1 + * return (*p) + */ +#define _def_atomic_inc_nv(_f, _t) \ +static inline _t \ +_f(volatile _t *p) \ +{ \ + _t ret, modified; \ + \ + __asm volatile ( \ + "1: ldrex %0, [%2] \n\t" \ + " add %0, %0, #1 \n\t" \ + " strex %1, %0, [%2] \n\t" \ + " cmp %1, #0 \n\t" \ + " bne 1b \n\t" \ + : "=&r" (ret), "=&r" (modified) \ + : "r" (p) \ + : "memory", "cc" \ + ); \ + return (ret); \ +} +_def_atomic_inc_nv(_atomic_inc_int_nv, unsigned int) +_def_atomic_inc_nv(_atomic_inc_long_nv, unsigned long) +#undef _def_atomic_inc_nv + +#define atomic_inc_int_nv(_p) _atomic_inc_int_nv((_p)) +#define atomic_inc_long_nv(_p) _atomic_inc_long_nv((_p)) + +/* + * Decrement returning the new value + * *p -= 1 + * return (*p) + */ +#define _def_atomic_dec_nv(_f, _t) \ +static inline _t \ +_f(volatile _t *p) \ +{ \ + _t ret, modified; \ + \ + __asm volatile ( \ + "1: ldrex %0, [%2] \n\t" \ + " sub %0, %0, #1 \n\t" \ + " strex %1, %0, [%2] \n\t" \ + " cmp %1, #0 \n\t" \ + " bne 1b \n\t" \ + : "=&r" (ret), "=&r" (modified) \ + : "r" (p) \ + : "memory", "cc" \ + ); \ + return (ret); \ +} +_def_atomic_dec_nv(_atomic_dec_int_nv, unsigned int) +_def_atomic_dec_nv(_atomic_dec_long_nv, unsigned long) +#undef _def_atomic_dec_nv + +#define atomic_dec_int_nv(_p) _atomic_dec_int_nv((_p)) +#define atomic_dec_long_nv(_p) _atomic_dec_long_nv((_p)) + +/* + * Addition returning the new value + * *p += v + * return (*p) + */ +#define _def_atomic_add_nv(_f, _t) \ +static inline _t \ +_f(volatile _t *p, _t v) \ +{ \ + _t ret, modified; \ + \ + __asm volatile ( \ + "1: ldrex %0, [%2] \n\t" \ + " add %0, %0, %3 \n\t" \ + " strex %1, %0, [%2] \n\t" \ + " cmp %1, #0 \n\t" \ + " bne 1b \n\t" \ + : "=&r" (ret), "=&r" (modified) \ + : "r" (p), "r" (v) \ + : "memory", "cc" \ + ); \ + return (ret); \ +} +_def_atomic_add_nv(_atomic_add_int_nv, unsigned int) +_def_atomic_add_nv(_atomic_add_long_nv, unsigned long) +#undef _def_atomic_add_nv + +#define atomic_add_int_nv(_p, _v) _atomic_add_int_nv((_p), (_v)) +#define atomic_add_long_nv(_p, _v) _atomic_add_long_nv((_p), (_v)) + +/* + * Subtraction returning the new value + * *p -= v + * return (*p) + */ +#define _def_atomic_sub_nv(_f, _t) \ +static inline _t \ +_f(volatile _t *p, _t v) \ +{ \ + _t ret, modified; \ + \ + __asm volatile ( \ + "1: ldrex %0, [%2] \n\t" \ + " sub %0, %0, %3 \n\t" \ + " strex %1, %0, [%2] \n\t" \ + " cmp %1, #0 \n\t" \ + " bne 1b \n\t" \ + : "=&r" (ret), "=&r" (modified) \ + : "r" (p), "r" (v) \ + : "memory", "cc" \ + ); \ + return (ret); \ +} +_def_atomic_sub_nv(_atomic_sub_int_nv, unsigned int) +_def_atomic_sub_nv(_atomic_sub_long_nv, unsigned long) +#undef _def_atomic_sub_nv + +#define atomic_sub_int_nv(_p, _v) _atomic_sub_int_nv((_p), (_v)) +#define atomic_sub_long_nv(_p, _v) _atomic_sub_long_nv((_p), (_v)) + +#define __membar(_f) do { __asm volatile(_f ::: "memory"); } while (0) + +#define membar_enter() __membar("dmb sy") +#define membar_exit() __membar("dmb sy") +#define membar_producer() __membar("dmb st") +#define membar_consumer() __membar("dmb sy") +#define membar_sync() __membar("dmb sy") + +#if defined(_KERNEL) + +/* virtio needs MP membars even on SP kernels */ +#define virtio_membar_producer() __membar("dmb st") +#define virtio_membar_consumer() __membar("dmb sy") +#define virtio_membar_sync() __membar("dmb sy") + +/* + * Set bits + * *p = *p | v + */ +static inline void +atomic_setbits_int(volatile unsigned int *p, unsigned int v) +{ + unsigned int modified, tmp; + + __asm volatile ( + "1: ldrex %0, [%3] \n\t" + " orr %0, %0, %2 \n\t" + " strex %1, %0, [%3] \n\t" + " cmp %1, #0 \n\t" + " bne 1b \n\t" + : "=&r" (tmp), "=&r" (modified) + : "r" (v), "r" (p) + : "memory", "cc" + ); +} + +/* + * Clear bits + * *p = *p & (~v) + */ +static inline void +atomic_clearbits_int(volatile unsigned int *p, unsigned int v) +{ + unsigned int modified, tmp; + + __asm volatile ( + "1: ldrex %0, [%3] \n\t" + " bic %0, %0, %2 \n\t" + " strex %1, %0, [%3] \n\t" + " cmp %1, #0 \n\t" + " bne 1b \n\t" + : "=&r" (tmp), "=&r" (modified) + : "r" (v), "r" (p) + : "memory", "cc" + ); +} + +#endif /* defined(_KERNEL) */ +#endif /* _ARM_ATOMIC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/bus.h b/lib/libc/include/arm-openbsd-eabi/arm/bus.h new file mode 100644 index 0000000000..f31a6d2dd8 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/bus.h @@ -0,0 +1,882 @@ +/* $OpenBSD: bus.h,v 1.19 2025/08/11 07:18:40 miod Exp $ */ +/* $NetBSD: bus.h,v 1.12 2003/10/23 15:03:24 scw Exp $ */ + +/*- + * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 1996 Charles M. Hannum. All rights reserved. + * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christopher G. Demetriou + * for the NetBSD Project. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _ARM_BUS_H_ +#define _ARM_BUS_H_ + +/* + * Addresses (in bus space). + */ +typedef u_long bus_addr_t; +typedef u_long bus_size_t; + +/* + * Access methods for bus space. + */ +typedef struct bus_space *bus_space_tag_t; +typedef u_long bus_space_handle_t; + +/* + * int bus_space_map (bus_space_tag_t t, bus_addr_t addr, + * bus_size_t size, int flags, bus_space_handle_t *bshp); + * + * Map a region of bus space. + */ + +#define BUS_SPACE_MAP_CACHEABLE 0x01 +#define BUS_SPACE_MAP_LINEAR 0x02 +#define BUS_SPACE_MAP_PREFETCHABLE 0x04 + +struct bus_space { + /* cookie */ + void *bs_cookie; + + /* mapping/unmapping */ + int (*bs_map) (void *, uint64_t, bus_size_t, + int, bus_space_handle_t *); + void (*bs_unmap) (void *, bus_space_handle_t, + bus_size_t); + int (*bs_subregion) (void *, bus_space_handle_t, + bus_size_t, bus_size_t, bus_space_handle_t *); + + /* allocation/deallocation */ + int (*bs_alloc) (void *, bus_addr_t, bus_addr_t, + bus_size_t, bus_size_t, bus_size_t, int, + bus_addr_t *, bus_space_handle_t *); + void (*bs_free) (void *, bus_space_handle_t, + bus_size_t); + + /* get kernel virtual address */ + void * (*bs_vaddr) (void *, bus_space_handle_t); + + /* mmap bus space for user */ + paddr_t (*bs_mmap) (void *, bus_addr_t, off_t, int, int); + + /* barrier */ + void (*bs_barrier) (void *, bus_space_handle_t, + bus_size_t, bus_size_t, int); + + /* read (single) */ + u_int8_t (*bs_r_1) (void *, bus_space_handle_t, + bus_size_t); + u_int16_t (*bs_r_2) (void *, bus_space_handle_t, + bus_size_t); + u_int32_t (*bs_r_4) (void *, bus_space_handle_t, + bus_size_t); + u_int64_t (*bs_r_8) (void *, bus_space_handle_t, + bus_size_t); + + /* read multiple */ + void (*bs_rm_1) (void *, bus_space_handle_t, + bus_size_t, u_int8_t *, bus_size_t); + void (*bs_rm_2) (void *, bus_space_handle_t, + bus_size_t, u_int16_t *, bus_size_t); + void (*bs_rm_4) (void *, bus_space_handle_t, + bus_size_t, u_int32_t *, bus_size_t); + void (*bs_rm_8) (void *, bus_space_handle_t, + bus_size_t, u_int64_t *, bus_size_t); + + /* read region */ + void (*bs_rr_1) (void *, bus_space_handle_t, + bus_size_t, u_int8_t *, bus_size_t); + void (*bs_rr_2) (void *, bus_space_handle_t, + bus_size_t, u_int16_t *, bus_size_t); + void (*bs_rr_4) (void *, bus_space_handle_t, + bus_size_t, u_int32_t *, bus_size_t); + void (*bs_rr_8) (void *, bus_space_handle_t, + bus_size_t, u_int64_t *, bus_size_t); + + /* write (single) */ + void (*bs_w_1) (void *, bus_space_handle_t, + bus_size_t, u_int8_t); + void (*bs_w_2) (void *, bus_space_handle_t, + bus_size_t, u_int16_t); + void (*bs_w_4) (void *, bus_space_handle_t, + bus_size_t, u_int32_t); + void (*bs_w_8) (void *, bus_space_handle_t, + bus_size_t, u_int64_t); + + /* write multiple */ + void (*bs_wm_1) (void *, bus_space_handle_t, + bus_size_t, const u_int8_t *, bus_size_t); + void (*bs_wm_2) (void *, bus_space_handle_t, + bus_size_t, const u_int16_t *, bus_size_t); + void (*bs_wm_4) (void *, bus_space_handle_t, + bus_size_t, const u_int32_t *, bus_size_t); + void (*bs_wm_8) (void *, bus_space_handle_t, + bus_size_t, const u_int64_t *, bus_size_t); + + /* write region */ + void (*bs_wr_1) (void *, bus_space_handle_t, + bus_size_t, const u_int8_t *, bus_size_t); + void (*bs_wr_2) (void *, bus_space_handle_t, + bus_size_t, const u_int16_t *, bus_size_t); + void (*bs_wr_4) (void *, bus_space_handle_t, + bus_size_t, const u_int32_t *, bus_size_t); + void (*bs_wr_8) (void *, bus_space_handle_t, + bus_size_t, const u_int64_t *, bus_size_t); + + /* set multiple */ + void (*bs_sm_1) (void *, bus_space_handle_t, + bus_size_t, u_int8_t, bus_size_t); + void (*bs_sm_2) (void *, bus_space_handle_t, + bus_size_t, u_int16_t, bus_size_t); + void (*bs_sm_4) (void *, bus_space_handle_t, + bus_size_t, u_int32_t, bus_size_t); + void (*bs_sm_8) (void *, bus_space_handle_t, + bus_size_t, u_int64_t, bus_size_t); + + /* set region */ + void (*bs_sr_1) (void *, bus_space_handle_t, + bus_size_t, u_int8_t, bus_size_t); + void (*bs_sr_2) (void *, bus_space_handle_t, + bus_size_t, u_int16_t, bus_size_t); + void (*bs_sr_4) (void *, bus_space_handle_t, + bus_size_t, u_int32_t, bus_size_t); + void (*bs_sr_8) (void *, bus_space_handle_t, + bus_size_t, u_int64_t, bus_size_t); + + /* copy */ + void (*bs_c_1) (void *, bus_space_handle_t, bus_size_t, + bus_space_handle_t, bus_size_t, bus_size_t); + void (*bs_c_2) (void *, bus_space_handle_t, bus_size_t, + bus_space_handle_t, bus_size_t, bus_size_t); + void (*bs_c_4) (void *, bus_space_handle_t, bus_size_t, + bus_space_handle_t, bus_size_t, bus_size_t); + void (*bs_c_8) (void *, bus_space_handle_t, bus_size_t, + bus_space_handle_t, bus_size_t, bus_size_t); +}; + + +/* + * Utility macros; INTERNAL USE ONLY. + */ +#define __bs_c(a,b) __CONCAT(a,b) +#define __bs_opname(op,size) __bs_c(__bs_c(__bs_c(bs_,op),_),size) + +#define __bs_rs(sz, t, h, o) \ + (*(t)->__bs_opname(r,sz))((t)->bs_cookie, h, o) +#define __bs_ws(sz, t, h, o, v) \ + (*(t)->__bs_opname(w,sz))((t)->bs_cookie, h, o, v) +#define __bs_nonsingle(type, sz, t, h, o, a, c) \ + (*(t)->__bs_opname(type,sz))((t)->bs_cookie, h, o, a, c) +#define __bs_set(type, sz, t, h, o, v, c) \ + (*(t)->__bs_opname(type,sz))((t)->bs_cookie, h, o, v, c) +#define __bs_copy(sz, t, h1, o1, h2, o2, cnt) \ + (*(t)->__bs_opname(c,sz))((t)->bs_cookie, h1, o1, h2, o2, cnt) + +/* + * Mapping and unmapping operations. + */ +#define bus_space_map(t, a, s, c, hp) \ + (*(t)->bs_map)((t)->bs_cookie, (a), (s), (c), (hp)) +#define bus_space_unmap(t, h, s) \ + (*(t)->bs_unmap)((t)->bs_cookie, (h), (s)) +#define bus_space_subregion(t, h, o, s, hp) \ + (*(t)->bs_subregion)((t)->bs_cookie, (h), (o), (s), (hp)) + + +/* + * Allocation and deallocation operations. + */ +#define bus_space_alloc(t, rs, re, s, a, b, c, ap, hp) \ + (*(t)->bs_alloc)((t)->bs_cookie, (rs), (re), (s), (a), (b), \ + (c), (ap), (hp)) +#define bus_space_free(t, h, s) \ + (*(t)->bs_free)((t)->bs_cookie, (h), (s)) + +/* + * Get kernel virtual address for ranges mapped BUS_SPACE_MAP_LINEAR. + */ +#define bus_space_vaddr(t, h) \ + (*(t)->bs_vaddr)((t)->bs_cookie, (h)) + +/* + * MMap bus space for a user application. + */ +#define bus_space_mmap(t, a, o, p, f) \ + (*(t)->bs_mmap)((t)->bs_cookie, (a), (o), (p), (f)) + +/* + * Bus barrier operations. + */ +#define bus_space_barrier(t, h, o, l, f) \ + (*(t)->bs_barrier)((t)->bs_cookie, (h), (o), (l), (f)) + +#define BUS_SPACE_BARRIER_READ 0x01 +#define BUS_SPACE_BARRIER_WRITE 0x02 + +/* + * Bus read (single) operations. + */ +#define bus_space_read_1(t, h, o) __bs_rs(1,(t),(h),(o)) +#define bus_space_read_2(t, h, o) __bs_rs(2,(t),(h),(o)) +#define bus_space_read_4(t, h, o) __bs_rs(4,(t),(h),(o)) +#define bus_space_read_8(t, h, o) __bs_rs(8,(t),(h),(o)) + +/* + * Bus read multiple operations. + */ +#define bus_space_read_multi_1(t, h, o, a, c) \ + __bs_nonsingle(rm,1,(t),(h),(o),(a),(c)) +#define bus_space_read_multi_2(t, h, o, a, c) \ + __bs_nonsingle(rm,2,(t),(h),(o),(a),(c)) +#define bus_space_read_multi_4(t, h, o, a, c) \ + __bs_nonsingle(rm,4,(t),(h),(o),(a),(c)) +#define bus_space_read_multi_8(t, h, o, a, c) \ + __bs_nonsingle(rm,8,(t),(h),(o),(a),(c)) + +/* + * Bus read region operations. + */ +#define bus_space_read_region_1(t, h, o, a, c) \ + __bs_nonsingle(rr,1,(t),(h),(o),(a),(c)) +#define bus_space_read_region_2(t, h, o, a, c) \ + __bs_nonsingle(rr,2,(t),(h),(o),(a),(c)) +#define bus_space_read_region_4(t, h, o, a, c) \ + __bs_nonsingle(rr,4,(t),(h),(o),(a),(c)) +#define bus_space_read_region_8(t, h, o, a, c) \ + __bs_nonsingle(rr,8,(t),(h),(o),(a),(c)) + +/* + * Bus write (single) operations. + */ +#define bus_space_write_1(t, h, o, v) __bs_ws(1,(t),(h),(o),(v)) +#define bus_space_write_2(t, h, o, v) __bs_ws(2,(t),(h),(o),(v)) +#define bus_space_write_4(t, h, o, v) __bs_ws(4,(t),(h),(o),(v)) +#define bus_space_write_8(t, h, o, v) __bs_ws(8,(t),(h),(o),(v)) + +/* + * Bus write multiple operations. + */ +#define bus_space_write_multi_1(t, h, o, a, c) \ + __bs_nonsingle(wm,1,(t),(h),(o),(a),(c)) +#define bus_space_write_multi_2(t, h, o, a, c) \ + __bs_nonsingle(wm,2,(t),(h),(o),(a),(c)) +#define bus_space_write_multi_4(t, h, o, a, c) \ + __bs_nonsingle(wm,4,(t),(h),(o),(a),(c)) +#define bus_space_write_multi_8(t, h, o, a, c) \ + __bs_nonsingle(wm,8,(t),(h),(o),(a),(c)) + +/* + * Bus write region operations. + */ +#define bus_space_write_region_1(t, h, o, a, c) \ + __bs_nonsingle(wr,1,(t),(h),(o),(a),(c)) +#define bus_space_write_region_2(t, h, o, a, c) \ + __bs_nonsingle(wr,2,(t),(h),(o),(a),(c)) +#define bus_space_write_region_4(t, h, o, a, c) \ + __bs_nonsingle(wr,4,(t),(h),(o),(a),(c)) +#define bus_space_write_region_8(t, h, o, a, c) \ + __bs_nonsingle(wr,8,(t),(h),(o),(a),(c)) + +/* + * Set multiple operations. + */ +#define bus_space_set_multi_1(t, h, o, v, c) \ + __bs_set(sm,1,(t),(h),(o),(v),(c)) +#define bus_space_set_multi_2(t, h, o, v, c) \ + __bs_set(sm,2,(t),(h),(o),(v),(c)) +#define bus_space_set_multi_4(t, h, o, v, c) \ + __bs_set(sm,4,(t),(h),(o),(v),(c)) +#define bus_space_set_multi_8(t, h, o, v, c) \ + __bs_set(sm,8,(t),(h),(o),(v),(c)) + +/* + * Set region operations. + */ +#define bus_space_set_region_1(t, h, o, v, c) \ + __bs_set(sr,1,(t),(h),(o),(v),(c)) +#define bus_space_set_region_2(t, h, o, v, c) \ + __bs_set(sr,2,(t),(h),(o),(v),(c)) +#define bus_space_set_region_4(t, h, o, v, c) \ + __bs_set(sr,4,(t),(h),(o),(v),(c)) +#define bus_space_set_region_8(t, h, o, v, c) \ + __bs_set(sr,8,(t),(h),(o),(v),(c)) + +/* + * Copy operations. + */ +#define bus_space_copy_1(t, h1, o1, h2, o2, c) \ + __bs_copy(1, t, h1, o1, h2, o2, c) +#define bus_space_copy_2(t, h1, o1, h2, o2, c) \ + __bs_copy(2, t, h1, o1, h2, o2, c) +#define bus_space_copy_4(t, h1, o1, h2, o2, c) \ + __bs_copy(4, t, h1, o1, h2, o2, c) +#define bus_space_copy_8(t, h1, o1, h2, o2, c) \ + __bs_copy(8, t, h1, o1, h2, o2, c) + +/* + * Macros to provide prototypes for all the functions used in the + * bus_space structure + */ + +#define bs_map_proto(f) \ +int __bs_c(f,_bs_map) (void *t, uint64_t addr, \ + bus_size_t size, int flags, bus_space_handle_t *bshp); + +#define bs_unmap_proto(f) \ +void __bs_c(f,_bs_unmap) (void *t, bus_space_handle_t bsh, \ + bus_size_t size); + +#define bs_subregion_proto(f) \ +int __bs_c(f,_bs_subregion) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, bus_size_t size, \ + bus_space_handle_t *nbshp); + +#define bs_alloc_proto(f) \ +int __bs_c(f,_bs_alloc) (void *t, bus_addr_t rstart, \ + bus_addr_t rend, bus_size_t size, bus_size_t align, \ + bus_size_t boundary, int flags, bus_addr_t *addrp, \ + bus_space_handle_t *bshp); + +#define bs_free_proto(f) \ +void __bs_c(f,_bs_free) (void *t, bus_space_handle_t bsh, \ + bus_size_t size); + +#define bs_vaddr_proto(f) \ +void * __bs_c(f,_bs_vaddr) (void *t, bus_space_handle_t bsh); + +#define bs_mmap_proto(f) \ +paddr_t __bs_c(f,_bs_mmap) (void *, bus_addr_t, off_t, int, int); + +#define bs_barrier_proto(f) \ +void __bs_c(f,_bs_barrier) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, bus_size_t len, int flags); + +#define bs_r_1_proto(f) \ +u_int8_t __bs_c(f,_bs_r_1) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset); + +#define bs_r_2_proto(f) \ +u_int16_t __bs_c(f,_bs_r_2) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset); + +#define bs_r_4_proto(f) \ +u_int32_t __bs_c(f,_bs_r_4) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset); + +#define bs_r_8_proto(f) \ +u_int64_t __bs_c(f,_bs_r_8) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset); + +#define bs_w_1_proto(f) \ +void __bs_c(f,_bs_w_1) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, u_int8_t value); + +#define bs_w_2_proto(f) \ +void __bs_c(f,_bs_w_2) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, u_int16_t value); + +#define bs_w_4_proto(f) \ +void __bs_c(f,_bs_w_4) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, u_int32_t value); + +#define bs_w_8_proto(f) \ +void __bs_c(f,_bs_w_8) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, u_int64_t value); + +#define bs_rm_1_proto(f) \ +void __bs_c(f,_bs_rm_1) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, u_int8_t *addr, bus_size_t count); + +#define bs_rm_2_proto(f) \ +void __bs_c(f,_bs_rm_2) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, u_int16_t *addr, bus_size_t count); + +#define bs_rm_4_proto(f) \ +void __bs_c(f,_bs_rm_4) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, u_int32_t *addr, bus_size_t count); + +#define bs_rm_8_proto(f) \ +void __bs_c(f,_bs_rm_8) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, u_int64_t *addr, bus_size_t count); + +#define bs_wm_1_proto(f) \ +void __bs_c(f,_bs_wm_1) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, const u_int8_t *addr, bus_size_t count); + +#define bs_wm_2_proto(f) \ +void __bs_c(f,_bs_wm_2) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, const u_int16_t *addr, bus_size_t count); + +#define bs_wm_4_proto(f) \ +void __bs_c(f,_bs_wm_4) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, const u_int32_t *addr, bus_size_t count); + +#define bs_wm_8_proto(f) \ +void __bs_c(f,_bs_wm_8) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, const u_int64_t *addr, bus_size_t count); + +#define bs_rr_1_proto(f) \ +void __bs_c(f, _bs_rr_1) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, u_int8_t *addr, bus_size_t count); + +#define bs_rr_2_proto(f) \ +void __bs_c(f, _bs_rr_2) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, u_int16_t *addr, bus_size_t count); + +#define bs_rr_4_proto(f) \ +void __bs_c(f, _bs_rr_4) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, u_int32_t *addr, bus_size_t count); + +#define bs_rr_8_proto(f) \ +void __bs_c(f, _bs_rr_8) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, u_int64_t *addr, bus_size_t count); + +#define bs_wr_1_proto(f) \ +void __bs_c(f, _bs_wr_1) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, const u_int8_t *addr, bus_size_t count); + +#define bs_wr_2_proto(f) \ +void __bs_c(f, _bs_wr_2) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, const u_int16_t *addr, bus_size_t count); + +#define bs_wr_4_proto(f) \ +void __bs_c(f, _bs_wr_4) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, const u_int32_t *addr, bus_size_t count); + +#define bs_wr_8_proto(f) \ +void __bs_c(f, _bs_wr_8) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, const u_int64_t *addr, bus_size_t count); + +#define bs_sm_1_proto(f) \ +void __bs_c(f,_bs_sm_1) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, u_int8_t value, bus_size_t count); + +#define bs_sm_2_proto(f) \ +void __bs_c(f,_bs_sm_2) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, u_int16_t value, bus_size_t count); + +#define bs_sm_4_proto(f) \ +void __bs_c(f,_bs_sm_4) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, u_int32_t value, bus_size_t count); + +#define bs_sm_8_proto(f) \ +void __bs_c(f,_bs_sm_8) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, u_int64_t value, bus_size_t count); + +#define bs_sr_1_proto(f) \ +void __bs_c(f,_bs_sr_1) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, u_int8_t value, bus_size_t count); + +#define bs_sr_2_proto(f) \ +void __bs_c(f,_bs_sr_2) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, u_int16_t value, bus_size_t count); + +#define bs_sr_4_proto(f) \ +void __bs_c(f,_bs_sr_4) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, u_int32_t value, bus_size_t count); + +#define bs_sr_8_proto(f) \ +void __bs_c(f,_bs_sr_8) (void *t, bus_space_handle_t bsh, \ + bus_size_t offset, u_int64_t value, bus_size_t count); + +#define bs_c_1_proto(f) \ +void __bs_c(f,_bs_c_1) (void *t, bus_space_handle_t bsh1, \ + bus_size_t offset1, bus_space_handle_t bsh2, \ + bus_size_t offset2, bus_size_t count); + +#define bs_c_2_proto(f) \ +void __bs_c(f,_bs_c_2) (void *t, bus_space_handle_t bsh1, \ + bus_size_t offset1, bus_space_handle_t bsh2, \ + bus_size_t offset2, bus_size_t count); + +#define bs_c_4_proto(f) \ +void __bs_c(f,_bs_c_4) (void *t, bus_space_handle_t bsh1, \ + bus_size_t offset1, bus_space_handle_t bsh2, \ + bus_size_t offset2, bus_size_t count); + +#define bs_c_8_proto(f) \ +void __bs_c(f,_bs_c_8) (void *t, bus_space_handle_t bsh1, \ + bus_size_t offset1, bus_space_handle_t bsh2, \ + bus_size_t offset2, bus_size_t count); + +#define bs_protos(f) \ +bs_map_proto(f); \ +bs_unmap_proto(f); \ +bs_subregion_proto(f); \ +bs_alloc_proto(f); \ +bs_free_proto(f); \ +bs_vaddr_proto(f); \ +bs_mmap_proto(f); \ +bs_barrier_proto(f); \ +bs_r_1_proto(f); \ +bs_r_2_proto(f); \ +bs_r_4_proto(f); \ +bs_r_8_proto(f); \ +bs_w_1_proto(f); \ +bs_w_2_proto(f); \ +bs_w_4_proto(f); \ +bs_w_8_proto(f); \ +bs_rm_1_proto(f); \ +bs_rm_2_proto(f); \ +bs_rm_4_proto(f); \ +bs_rm_8_proto(f); \ +bs_wm_1_proto(f); \ +bs_wm_2_proto(f); \ +bs_wm_4_proto(f); \ +bs_wm_8_proto(f); \ +bs_rr_1_proto(f); \ +bs_rr_2_proto(f); \ +bs_rr_4_proto(f); \ +bs_rr_8_proto(f); \ +bs_wr_1_proto(f); \ +bs_wr_2_proto(f); \ +bs_wr_4_proto(f); \ +bs_wr_8_proto(f); \ +bs_sm_1_proto(f); \ +bs_sm_2_proto(f); \ +bs_sm_4_proto(f); \ +bs_sm_8_proto(f); \ +bs_sr_1_proto(f); \ +bs_sr_2_proto(f); \ +bs_sr_4_proto(f); \ +bs_sr_8_proto(f); \ +bs_c_1_proto(f); \ +bs_c_2_proto(f); \ +bs_c_4_proto(f); \ +bs_c_8_proto(f); + +/* Bus Space DMA macros */ + +/* + * Flags used in various bus DMA methods. + */ +#define BUS_DMA_WAITOK 0x0000 /* safe to sleep (pseudo-flag) */ +#define BUS_DMA_NOWAIT 0x0001 /* not safe to sleep */ +#define BUS_DMA_ALLOCNOW 0x0002 /* perform resource allocation now */ +#define BUS_DMA_COHERENT 0x0004 /* hint: map memory DMA coherent */ +#define BUS_DMA_STREAMING 0x0008 /* hint: sequential, unidirectional */ +#define BUS_DMA_BUS1 0x0010 /* placeholders for bus functions... */ +#define BUS_DMA_BUS2 0x0020 +#define BUS_DMA_BUS3 0x0040 +#define BUS_DMA_BUS4 0x0080 +#define BUS_DMA_READ 0x0100 /* mapping is device -> memory only */ +#define BUS_DMA_WRITE 0x0200 /* mapping is memory -> device only */ +#define BUS_DMA_NOCACHE 0x0400 /* hint: map non-cached memory */ +#define BUS_DMA_ZERO 0x0800 /* dmamem_alloc returns zeroed mem */ +#define BUS_DMA_64BIT 0x1000 /* device handles 64bit dva */ + +/* + * Private flags stored in the DMA map. + */ +#define ARM32_DMAMAP_COHERENT 0x10000 /* no cache flush necessary on sync */ + +/* Forwards needed by prototypes below. */ +struct mbuf; +struct uio; + +/* + * Operations performed by bus_dmamap_sync(). + */ +#define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */ +#define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */ +#define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */ +#define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */ + +typedef struct arm32_bus_dma_tag *bus_dma_tag_t; +typedef struct arm32_bus_dmamap *bus_dmamap_t; + +#define BUS_DMA_TAG_VALID(t) ((t) != (bus_dma_tag_t)0) + +/* + * bus_dma_segment_t + * + * Describes a single contiguous DMA transaction. Values + * are suitable for programming into DMA registers. + */ +struct arm32_bus_dma_segment { + /* + * PUBLIC MEMBERS: these are used by machine-independent code. + */ + bus_addr_t ds_addr; /* DMA address */ + bus_size_t ds_len; /* length of transfer */ + /* + * PRIVATE MEMBERS: not for use by machine-independent code. + */ + bus_addr_t _ds_vaddr; /* Virtual mapped address + * Used by bus_dmamem_sync() */ + int _ds_coherent; /* Coherently mapped */ +}; +typedef struct arm32_bus_dma_segment bus_dma_segment_t; + +/* + * bus_dma_tag_t + * + * A machine-dependent opaque type describing the implementation of + * DMA for a given bus. + */ + +struct arm32_bus_dma_tag { + /* + * Opaque cookie for use by back-end. + */ + void *_cookie; + + /* + * DMA mapping methods. + */ + int (*_dmamap_create) (bus_dma_tag_t, bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); + void (*_dmamap_destroy) (bus_dma_tag_t, bus_dmamap_t); + int (*_dmamap_load) (bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int); + int (*_dmamap_load_mbuf) (bus_dma_tag_t, bus_dmamap_t, + struct mbuf *, int); + int (*_dmamap_load_uio) (bus_dma_tag_t, bus_dmamap_t, + struct uio *, int); + int (*_dmamap_load_raw) (bus_dma_tag_t, bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); + int (*_dmamap_load_buffer)(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int, paddr_t *, int *, int); + void (*_dmamap_unload) (bus_dma_tag_t, bus_dmamap_t); + void (*_dmamap_sync) (bus_dma_tag_t, bus_dmamap_t, + bus_addr_t, bus_size_t, int); + + /* + * DMA memory utility functions. + */ + int (*_dmamem_alloc) (bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); + int (*_dmamem_alloc_range) (bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int, + paddr_t, paddr_t); + void (*_dmamem_free) (bus_dma_tag_t, + bus_dma_segment_t *, int); + int (*_dmamem_map) (bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); + void (*_dmamem_unmap) (bus_dma_tag_t, caddr_t, size_t); + paddr_t (*_dmamem_mmap) (bus_dma_tag_t, bus_dma_segment_t *, + int, off_t, int, int); +}; + +#define bus_dmamap_create(t, s, n, m, b, f, p) \ + (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p)) +#define bus_dmamap_destroy(t, p) \ + (*(t)->_dmamap_destroy)((t), (p)) +#define bus_dmamap_load(t, m, b, s, p, f) \ + (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f)) +#define bus_dmamap_load_mbuf(t, m, b, f) \ + (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f)) +#define bus_dmamap_load_uio(t, m, u, f) \ + (*(t)->_dmamap_load_uio)((t), (m), (u), (f)) +#define bus_dmamap_load_raw(t, m, sg, n, s, f) \ + (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f)) +#define bus_dmamap_unload(t, p) \ + (*(t)->_dmamap_unload)((t), (p)) +#define bus_dmamap_sync(t, p, o, l, ops) \ + (void)((t)->_dmamap_sync ? \ + (*(t)->_dmamap_sync)((t), (p), (o), (l), (ops)) : (void)0) + +#define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \ + (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f)) +#define bus_dmamem_alloc_range(t, s, a, b, sg, n, r, f, l, h) \ + (*(t)->_dmamem_alloc_range)((t), (s), (a), (b), (sg), \ + (n), (r), (f), (l), (h)) +#define bus_dmamem_free(t, sg, n) \ + (*(t)->_dmamem_free)((t), (sg), (n)) +#define bus_dmamem_map(t, sg, n, s, k, f) \ + (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f)) +#define bus_dmamem_unmap(t, k, s) \ + (*(t)->_dmamem_unmap)((t), (k), (s)) +#define bus_dmamem_mmap(t, sg, n, o, p, f) \ + (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f)) + +/* + * bus_dmamap_t + * + * Describes a DMA mapping. + */ +struct arm32_bus_dmamap { + /* + * PRIVATE MEMBERS: not for use by machine-independent code. + */ + bus_size_t _dm_size; /* largest DMA transfer mappable */ + int _dm_segcnt; /* number of segs this map can map */ + bus_size_t _dm_maxsegsz; /* largest possible segment */ + bus_size_t _dm_boundary; /* don't cross this */ + int _dm_flags; /* misc. flags */ + + void *_dm_origbuf; /* pointer to original buffer */ + int _dm_buftype; /* type of buffer */ + struct proc *_dm_proc; /* proc that owns the mapping */ + + void *_dm_cookie; /* cookie for bus-specific functions */ + + /* + * PUBLIC MEMBERS: these are used by machine-independent code. + */ + bus_size_t dm_mapsize; /* size of the mapping */ + int dm_nsegs; /* # valid segments in mapping */ + bus_dma_segment_t dm_segs[1]; /* segments; variable length */ +}; + +#ifdef _ARM32_BUS_DMA_PRIVATE + +/* _dm_buftype */ +#define ARM32_BUFTYPE_INVALID 0 +#define ARM32_BUFTYPE_LINEAR 1 +#define ARM32_BUFTYPE_MBUF 2 +#define ARM32_BUFTYPE_UIO 3 +#define ARM32_BUFTYPE_RAW 4 + +int _bus_dmamap_create (bus_dma_tag_t, bus_size_t, int, bus_size_t, + bus_size_t, int, bus_dmamap_t *); +void _bus_dmamap_destroy (bus_dma_tag_t, bus_dmamap_t); +int _bus_dmamap_load (bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int); +int _bus_dmamap_load_mbuf (bus_dma_tag_t, bus_dmamap_t, + struct mbuf *, int); +int _bus_dmamap_load_uio (bus_dma_tag_t, bus_dmamap_t, + struct uio *, int); +int _bus_dmamap_load_raw (bus_dma_tag_t, bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); +int _bus_dmamap_load_buffer(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int, paddr_t *, int *, int); +void _bus_dmamap_unload (bus_dma_tag_t, bus_dmamap_t); +void _bus_dmamap_sync (bus_dma_tag_t, bus_dmamap_t, bus_addr_t, + bus_size_t, int); + +int _bus_dmamem_alloc (bus_dma_tag_t tag, bus_size_t size, + bus_size_t alignment, bus_size_t boundary, + bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags); +void _bus_dmamem_free (bus_dma_tag_t tag, bus_dma_segment_t *segs, + int nsegs); +int _bus_dmamem_map (bus_dma_tag_t tag, bus_dma_segment_t *segs, + int nsegs, size_t size, caddr_t *kvap, int flags); +void _bus_dmamem_unmap (bus_dma_tag_t tag, caddr_t kva, + size_t size); +paddr_t _bus_dmamem_mmap (bus_dma_tag_t tag, bus_dma_segment_t *segs, + int nsegs, off_t off, int prot, int flags); + +int _bus_dmamem_alloc_range (bus_dma_tag_t tag, bus_size_t size, + bus_size_t alignment, bus_size_t boundary, + bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags, + vaddr_t low, vaddr_t high); +#endif /* _ARM32_BUS_DMA_PRIVATE */ +/* These are OpenBSD extensions to the general NetBSD bus interface. */ +void +bus_space_read_raw_multi_2(bus_space_tag_t bst, bus_space_handle_t bsh, + bus_addr_t ba, u_int8_t *dst, bus_size_t size); +void +bus_space_read_raw_multi_4(bus_space_tag_t bst, bus_space_handle_t bsh, + bus_addr_t ba, u_int8_t *dst, bus_size_t size); +#define bus_space_read_raw_multi_8 \ + !!! bus_space_read_raw_multi_8 not implemented !!! + +void +bus_space_write_raw_multi_2(bus_space_tag_t bst, bus_space_handle_t bsh, + bus_addr_t ba, const u_int8_t *src, bus_size_t size); +void +bus_space_write_raw_multi_4(bus_space_tag_t bst, bus_space_handle_t bsh, + bus_addr_t ba, const u_int8_t *src, bus_size_t size); +#define bus_space_write_raw_multi_8 \ + !!! bus_space_write_raw_multi_8 not implemented !!! + +/* + * void bus_space_read_raw_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_int8_t *addr, size_t count); + * + * Read `count' bytes in 2, 4 or 8 byte wide quantities from bus space + * described by tag/handle and starting at `offset' and copy into + * buffer provided. The buffer must have proper alignment for the N byte + * wide entities. Furthermore possible byte-swapping should be done by + * these functions. + */ + +#define bus_space_read_raw_region_2(t, h, o, a, c) \ + bus_space_read_region_2((t), (h), (o), (u_int16_t *)(a), (c) >> 1) +#define bus_space_read_raw_region_4(t, h, o, a, c) \ + bus_space_read_region_4((t), (h), (o), (u_int32_t *)(a), (c) >> 2) + +#if 0 /* Cause a link error for bus_space_read_raw_region_8 */ +#define bus_space_read_raw_region_8 \ + !!! bus_space_read_raw_region_8 unimplemented !!! +#endif + +/* + * void bus_space_write_raw_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * const u_int8_t *addr, size_t count); + * + * Write `count' bytes in 2, 4 or 8 byte wide quantities to bus space + * described by tag/handle and starting at `offset' from the + * buffer provided. The buffer must have proper alignment for the N byte + * wide entities. Furthermore possible byte-swapping should be done by + * these functions. + */ + +#define bus_space_write_raw_region_2(t, h, o, a, c) \ + bus_space_write_region_2((t), (h), (o), (const u_int16_t *)(a), (c) >> 1) +#define bus_space_write_raw_region_4(t, h, o, a, c) \ + bus_space_write_region_4((t), (h), (o), (const u_int32_t *)(a), (c) >> 2) + +#if 0 /* Cause a link error for bus_space_write_raw_region_8 */ +#define bus_space_write_raw_region_8 \ + !!! bus_space_write_raw_region_8 unimplemented !!! +#endif + +#endif /* _ARM_BUS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/cdefs.h b/lib/libc/include/arm-openbsd-eabi/arm/cdefs.h new file mode 100644 index 0000000000..b2d807a184 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/cdefs.h @@ -0,0 +1,16 @@ +/* $OpenBSD: cdefs.h,v 1.4 2013/03/28 17:30:45 martynas Exp $ */ + +#ifndef _ARM_CDEFS_H_ +#define _ARM_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 /* !_ARM_CDEFS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/conf.h b/lib/libc/include/arm-openbsd-eabi/arm/conf.h new file mode 100644 index 0000000000..ad76452696 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/conf.h @@ -0,0 +1,82 @@ +/* $OpenBSD: conf.h,v 1.12 2022/06/28 14:43:50 visa Exp $ */ +/* $NetBSD: conf.h,v 1.7 2002/04/19 01:04:39 wiz Exp $ */ + +/* + * Copyright (c) 1997 Mark Brinicombe. + * 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 Mark Brinicombe + * for the NetBSD Project. + * 4. The name of the company nor the name of the author may 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 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. + * + * RiscBSD kernel project + * + * conf.h + * + * Prototypes for device driver functions + */ + +#ifndef _ARM_CONF_H_ +#define _ARM_CONF_H_ + + +#include + +#define mmread mmrw +#define mmwrite mmrw +cdev_decl(mm); + +bdev_decl(wd); +cdev_decl(wd); +bdev_decl(fd); +cdev_decl(fd); + +/* Character device declarations */ + +/* open, close, ioctl, kqueue */ +#define cdev_apm_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,n,kqfilter) } + +cdev_decl(com); +cdev_decl(lpt); +cdev_decl(pci); +cdev_decl(apm); +cdev_decl(spkr); + +/* open, close, ioctl */ +#define cdev_openprom_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) nullop, 0, \ + (dev_type_mmap((*))) enodev } + +cdev_decl(openprom); + +#endif /* _ARM_CONF_H__ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/cpu.h b/lib/libc/include/arm-openbsd-eabi/arm/cpu.h new file mode 100644 index 0000000000..eb81d8ee82 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/cpu.h @@ -0,0 +1,338 @@ +/* $OpenBSD: cpu.h,v 1.67 2024/06/09 21:15:29 jca Exp $ */ +/* $NetBSD: cpu.h,v 1.34 2003/06/23 11:01:08 martin Exp $ */ + +/* + * Copyright (c) 1994-1996 Mark Brinicombe. + * Copyright (c) 1994 Brini. + * All rights reserved. + * + * This code is derived from software written for Brini by Mark Brinicombe + * + * 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 Brini. + * 4. The name of the company nor the name of the author may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY BRINI ``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 BRINI 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. + * + * RiscBSD kernel project + * + * cpu.h + * + * CPU specific symbols + * + * Created : 18/09/94 + * + * Based on kate/katelib/arm6.h + */ + +#ifndef _ARM_CPU_H_ +#define _ARM_CPU_H_ + +/* + * User-visible definitions + */ + +/* CTL_MACHDEP definitions. */ + /* 1 formerly int: CPU_DEBUG */ + /* 2 formerly string: CPU_BOOTED_DEVICE */ + /* 3 formerly string: CPU_BOOTED_KERNEL */ +#define CPU_CONSDEV 4 /* struct: dev_t of our console */ +#define CPU_POWERSAVE 5 /* int: use CPU powersave mode */ +#define CPU_ALLOWAPERTURE 6 /* int: allow mmap of /dev/xf86 */ + /* 7 formerly int: apmwarn */ + /* 8 formerly int: keyboard reset */ + /* 9 formerly int: CPU_ZTSRAWMODE */ + /* 10 formerly struct: CPU_ZTSSCALE */ +#define CPU_MAXSPEED 11 /* int: number of valid machdep ids */ + /* 12 formerly int: CPU_LIDSUSPEND */ +#define CPU_LIDACTION 13 /* action caused by lid close */ +#define CPU_COMPATIBLE 14 /* compatible property */ +#define CPU_MAXID 15 /* number of valid machdep ids */ + +#define CTL_MACHDEP_NAMES { \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "console_device", CTLTYPE_STRUCT }, \ + { "powersave", CTLTYPE_INT }, \ + { "allowaperture", CTLTYPE_INT }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "maxspeed", CTLTYPE_INT }, \ + { 0, 0 }, \ + { "lidaction", CTLTYPE_INT }, \ + { "compatible", CTLTYPE_STRING }, \ +} + +#ifdef _KERNEL + +/* + * Kernel-only definitions + */ + +#include + +#include +#include +#include +#include + +/* 1 == use cpu_sleep(), 0 == don't */ +extern int cpu_do_powersave; + +/* All the CLKF_* macros take a struct clockframe * as an argument. */ + +/* + * CLKF_USERMODE: Return TRUE/FALSE (1/0) depending on whether the + * frame came from USR mode or not. + */ +#define CLKF_USERMODE(frame) ((frame->if_spsr & PSR_MODE) == PSR_USR32_MODE) + +/* + * CLKF_INTR: True if we took the interrupt from inside another + * interrupt handler. + */ +#define CLKF_INTR(frame) (curcpu()->ci_idepth > 1) + +/* + * CLKF_PC: Extract the program counter from a clockframe + */ +#define CLKF_PC(frame) (frame->if_pc) + +/* + * PROC_PC: Find out the program counter for the given process. + */ +#define PROC_PC(p) ((p)->p_addr->u_pcb.pcb_tf->tf_pc) +#define PROC_STACK(p) ((p)->p_addr->u_pcb.pcb_tf->tf_usr_sp) + +/* The address of the vector page. */ +extern vaddr_t vector_page; +void arm32_vector_init(vaddr_t, int); + +#define ARM_VEC_RESET (1 << 0) +#define ARM_VEC_UNDEFINED (1 << 1) +#define ARM_VEC_SWI (1 << 2) +#define ARM_VEC_PREFETCH_ABORT (1 << 3) +#define ARM_VEC_DATA_ABORT (1 << 4) +#define ARM_VEC_ADDRESS_EXCEPTION (1 << 5) +#define ARM_VEC_IRQ (1 << 6) +#define ARM_VEC_FIQ (1 << 7) + +#define ARM_NVEC 8 +#define ARM_VEC_ALL 0xffffffff + +/* + * Per-CPU information. For now we assume one CPU. + */ + +#include +#include +#include +#include + +struct cpu_info { + struct device *ci_dev; /* Device corresponding to this CPU */ + struct cpu_info *ci_next; + struct schedstate_percpu ci_schedstate; /* scheduler state */ + + u_int32_t ci_cpuid; + uint64_t ci_mpidr; + int ci_node; + struct cpu_info *ci_self; + + struct proc *ci_curproc; + struct proc *ci_fpuproc; + u_int32_t ci_randseed; + + struct pcb *ci_curpcb; + struct pcb *ci_idle_pcb; + + uint32_t ci_cpl; + uint32_t ci_ipending; + uint32_t ci_idepth; +#ifdef DIAGNOSTIC + int ci_mutex_level; +#endif + int ci_want_resched; + + void (*ci_flush_bp)(void); + + struct opp_table *ci_opp_table; + volatile int ci_opp_idx; + volatile int ci_opp_max; + uint32_t ci_cpu_supply; + +#ifdef MULTIPROCESSOR + struct srp_hazard ci_srp_hazards[SRP_HAZARD_NUM]; + volatile int ci_flags; + uint32_t ci_ttbr0; + vaddr_t ci_pl1_stkend; + vaddr_t ci_irq_stkend; + vaddr_t ci_abt_stkend; + vaddr_t ci_und_stkend; +#endif + +#ifdef GPROF + struct gmonparam *ci_gmon; + struct clockintr ci_gmonclock; +#endif + struct clockqueue ci_queue; + char ci_panicbuf[512]; +}; + +#define CPUF_PRIMARY (1<<0) +#define CPUF_AP (1<<1) +#define CPUF_IDENTIFY (1<<2) +#define CPUF_IDENTIFIED (1<<3) +#define CPUF_PRESENT (1<<4) +#define CPUF_GO (1<<5) +#define CPUF_RUNNING (1<<6) + +static inline struct cpu_info * +curcpu(void) +{ + struct cpu_info *__ci; + __asm volatile("mrc p15, 0, %0, c13, c0, 4" : "=r" (__ci)); + return (__ci); +} + +extern struct cpu_info cpu_info_primary; +extern struct cpu_info *cpu_info_list; + +#ifndef MULTIPROCESSOR +#define cpu_number() 0 +#define CPU_IS_PRIMARY(ci) 1 +#define CPU_IS_RUNNING(ci) 1 +#define CPU_INFO_ITERATOR int +#define CPU_INFO_FOREACH(cii, ci) \ + for (cii = 0, ci = curcpu(); ci != NULL; ci = NULL) +#define CPU_INFO_UNIT(ci) 0 +#define MAXCPUS 1 +#define cpu_kick(ci) +#define cpu_unidle(ci) +#else +#define cpu_number() (curcpu()->ci_cpuid) +#define CPU_IS_PRIMARY(ci) ((ci) == &cpu_info_primary) +#define CPU_IS_RUNNING(ci) ((ci)->ci_flags & CPUF_RUNNING) +#define CPU_INFO_ITERATOR int +#define CPU_INFO_FOREACH(cii, ci) for (cii = 0, ci = cpu_info_list; \ + ci != NULL; ci = ci->ci_next) +#define CPU_INFO_UNIT(ci) ((ci)->ci_dev ? (ci)->ci_dev->dv_unit : 0) +#define MAXCPUS 4 +void cpu_kick(struct cpu_info *); +void cpu_unidle(struct cpu_info *ci); + +extern struct cpu_info *cpu_info[MAXCPUS]; + +void cpu_boot_secondary_processors(void); +#endif /* !MULTIPROCESSOR */ + +#define CPU_BUSY_CYCLE() __asm volatile ("" ::: "memory") + +#define curpcb curcpu()->ci_curpcb + +unsigned int cpu_rnd_messybits(void); + +/* + * Scheduling glue + */ + +extern int astpending; +#define setsoftast() (astpending = 1) + +/* + * Notify the current process (p) that it has a signal pending, + * process as soon as possible. + */ + +#define signotify(p) setsoftast() + +/* + * Preempt the current process if in interrupt from user mode, + * or after the current trap/syscall if in system mode. + */ +extern int want_resched; /* resched() was called */ +#define need_resched(ci) (want_resched = 1, setsoftast()) +#define clear_resched(ci) want_resched = 0 + +/* + * Give a profiling tick to the current process when the user profiling + * buffer pages are invalid. On the i386, request an ast to send us + * through trap(), marking the proc as needing a profiling tick. + */ +#define need_proftick(p) setsoftast() + +/* + * cpu device glue (belongs in cpuvar.h) + */ + +int cpu_alloc_idle_pcb(struct cpu_info *); + +/* + * Random cruft + */ + +/* cpuswitch.S */ +struct pcb; +void savectx (struct pcb *pcb); + +/* machdep.h */ +void bootsync (int); + +/* fault.c */ +int badaddr_read (void *, size_t, void *); + +/* syscall.c */ +void swi_handler (trapframe_t *); + +/* machine_machdep.c */ +void board_startup(void); + +static inline u_long +intr_disable(void) +{ + uint32_t cpsr; + + __asm volatile ("mrs %0, cpsr" : "=r"(cpsr)); + __asm volatile ("msr cpsr_c, %0" :: "r"(cpsr | PSR_I)); + + return cpsr; +} + +static inline void +intr_restore(u_long cpsr) +{ + __asm volatile ("msr cpsr_c, %0" :: "r"(cpsr)); +} + +#endif /* _KERNEL */ + +#ifdef MULTIPROCESSOR +#include +#endif /* MULTIPROCESSOR */ + +#endif /* !_ARM_CPU_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/cpuconf.h b/lib/libc/include/arm-openbsd-eabi/arm/cpuconf.h new file mode 100644 index 0000000000..a1576f6511 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/cpuconf.h @@ -0,0 +1,53 @@ +/* $OpenBSD: cpuconf.h,v 1.20 2024/11/07 08:12:12 miod Exp $ */ +/* $NetBSD: cpuconf.h,v 1.7 2003/05/23 00:57:24 ichiro Exp $ */ + +/* + * Copyright (c) 2002 Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Jason R. Thorpe for Wasabi Systems, Inc. + * + * 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 for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC + * 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 _ARM_CPUCONF_H_ +#define _ARM_CPUCONF_H_ + +/* + * Define which MMU classes are configured: + * + * ARM_MMU_V7 v6/v7 MMU with XP bit enabled subpage + * protection is not used, TEX/AP is used instead. + */ + +#define ARM_MMU_V7 1 + +#define ARM_NMMUS (ARM_MMU_V7) + +#endif /* _ARM_CPUCONF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/cpufunc.h b/lib/libc/include/arm-openbsd-eabi/arm/cpufunc.h new file mode 100644 index 0000000000..07d18177ae --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/cpufunc.h @@ -0,0 +1,339 @@ +/* $OpenBSD: cpufunc.h,v 1.34 2023/05/30 08:30:00 jsg Exp $ */ +/* $NetBSD: cpufunc.h,v 1.29 2003/09/06 09:08:35 rearnsha Exp $ */ + +/* + * Copyright (c) 1997 Mark Brinicombe. + * Copyright (c) 1997 Causality Limited + * 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 Causality Limited. + * 4. The name of Causality Limited may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY CAUSALITY LIMITED ``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 CAUSALITY LIMITED 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. + * + * RiscBSD kernel project + * + * cpufunc.h + * + * Prototypes for cpu, mmu and tlb related functions. + */ + +#ifndef _ARM_CPUFUNC_H_ +#define _ARM_CPUFUNC_H_ + +#ifdef _KERNEL + +#include +#include + +struct cpu_functions { + + /* CPU functions */ + + u_int (*cf_id) (void); + void (*cf_cpwait) (void); + + /* MMU functions */ + + u_int (*cf_control) (u_int clear, u_int set); + u_int (*cf_auxcontrol) (u_int clear, u_int set); + void (*cf_domains) (u_int domains); + void (*cf_setttb) (u_int ttb); + u_int (*cf_dfsr) (void); + u_int (*cf_dfar) (void); + u_int (*cf_ifsr) (void); + u_int (*cf_ifar) (void); + + /* TLB functions */ + + void (*cf_tlb_flushID) (void); + void (*cf_tlb_flushID_SE) (u_int va); + void (*cf_tlb_flushI) (void); + void (*cf_tlb_flushI_SE) (u_int va); + void (*cf_tlb_flushD) (void); + void (*cf_tlb_flushD_SE) (u_int va); + + /* + * Cache operations: + * + * We define the following primitives: + * + * icache_sync_all Synchronize I-cache + * icache_sync_range Synchronize I-cache range + * + * dcache_wbinv_all Write-back and Invalidate D-cache + * dcache_wbinv_range Write-back and Invalidate D-cache range + * dcache_inv_range Invalidate D-cache range + * dcache_wb_range Write-back D-cache range + * + * idcache_wbinv_all Write-back and Invalidate D-cache, + * Invalidate I-cache + * idcache_wbinv_range Write-back and Invalidate D-cache, + * Invalidate I-cache range + * + * Note that the ARM term for "write-back" is "clean". We use + * the term "write-back" since it's a more common way to describe + * the operation. + * + * There are some rules that must be followed: + * + * I-cache Synch (all or range): + * The goal is to synchronize the instruction stream, + * so you may need to write-back dirty D-cache blocks + * first. If a range is requested, and you can't + * synchronize just a range, you have to hit the whole + * thing. + * + * D-cache Write-Back and Invalidate range: + * If you can't WB-Inv a range, you must WB-Inv the + * entire D-cache. + * + * D-cache Invalidate: + * If you can't Inv the D-cache, you must Write-Back + * and Invalidate. Code that uses this operation + * MUST NOT assume that the D-cache will not be written + * back to memory. + * + * D-cache Write-Back: + * If you can't Write-back without doing an Inv, + * that's fine. Then treat this as a WB-Inv. + * Skipping the invalidate is merely an optimization. + * + * All operations: + * Valid virtual addresses must be passed to each + * cache operation. + */ + void (*cf_icache_sync_all) (void); + void (*cf_icache_sync_range) (vaddr_t, vsize_t); + + void (*cf_dcache_wbinv_all) (void); + void (*cf_dcache_wbinv_range) (vaddr_t, vsize_t); + void (*cf_dcache_inv_range) (vaddr_t, vsize_t); + void (*cf_dcache_wb_range) (vaddr_t, vsize_t); + + void (*cf_idcache_wbinv_all) (void); + void (*cf_idcache_wbinv_range) (vaddr_t, vsize_t); + + void (*cf_sdcache_wbinv_all) (void); + void (*cf_sdcache_wbinv_range) (vaddr_t, paddr_t, vsize_t); + void (*cf_sdcache_inv_range) (vaddr_t, paddr_t, vsize_t); + void (*cf_sdcache_wb_range) (vaddr_t, paddr_t, vsize_t); + void (*cf_sdcache_drain_writebuf) (void); + + /* Other functions */ + + void (*cf_flush_prefetchbuf) (void); + void (*cf_drain_writebuf) (void); + + void (*cf_sleep) (int mode); + + /* Soft functions */ + void (*cf_context_switch) (u_int); + void (*cf_setup) (void); +}; + +extern struct cpu_functions cpufuncs; +extern u_int cputype; + +#define cpu_id() cpufuncs.cf_id() +#define cpu_cpwait() cpufuncs.cf_cpwait() + +#define cpu_control(c, s) cpufuncs.cf_control(c, s) +#define cpu_auxcontrol(c, s) cpufuncs.cf_auxcontrol(c, s) +#define cpu_domains(d) cpufuncs.cf_domains(d) +#define cpu_setttb(t) cpufuncs.cf_setttb(t) +#define cpu_dfsr() cpufuncs.cf_dfsr() +#define cpu_dfar() cpufuncs.cf_dfar() +#define cpu_ifsr() cpufuncs.cf_ifsr() +#define cpu_ifar() cpufuncs.cf_ifar() + +#define cpu_tlb_flushID() cpufuncs.cf_tlb_flushID() +#define cpu_tlb_flushID_SE(e) cpufuncs.cf_tlb_flushID_SE(e) +#define cpu_tlb_flushI() cpufuncs.cf_tlb_flushI() +#define cpu_tlb_flushI_SE(e) cpufuncs.cf_tlb_flushI_SE(e) +#define cpu_tlb_flushD() cpufuncs.cf_tlb_flushD() +#define cpu_tlb_flushD_SE(e) cpufuncs.cf_tlb_flushD_SE(e) + +#define cpu_icache_sync_all() cpufuncs.cf_icache_sync_all() +#define cpu_icache_sync_range(a, s) cpufuncs.cf_icache_sync_range((a), (s)) + +#define cpu_dcache_wbinv_all() cpufuncs.cf_dcache_wbinv_all() +#define cpu_dcache_wbinv_range(a, s) cpufuncs.cf_dcache_wbinv_range((a), (s)) +#define cpu_dcache_inv_range(a, s) cpufuncs.cf_dcache_inv_range((a), (s)) +#define cpu_dcache_wb_range(a, s) cpufuncs.cf_dcache_wb_range((a), (s)) + +#define cpu_idcache_wbinv_all() cpufuncs.cf_idcache_wbinv_all() +#define cpu_idcache_wbinv_range(a, s) cpufuncs.cf_idcache_wbinv_range((a), (s)) + +#define cpu_sdcache_enabled() (cpufuncs.cf_sdcache_wbinv_all != cpufunc_nullop) +#define cpu_sdcache_wbinv_all() cpufuncs.cf_sdcache_wbinv_all() +#define cpu_sdcache_wbinv_range(va, pa, s) cpufuncs.cf_sdcache_wbinv_range((va), (pa), (s)) +#define cpu_sdcache_inv_range(va, pa, s) cpufuncs.cf_sdcache_inv_range((va), (pa), (s)) +#define cpu_sdcache_wb_range(va, pa, s) cpufuncs.cf_sdcache_wb_range((va), (pa), (s)) +#define cpu_sdcache_drain_writebuf() cpufuncs.cf_sdcache_drain_writebuf() + +#define cpu_flush_prefetchbuf() cpufuncs.cf_flush_prefetchbuf() +#define cpu_drain_writebuf() cpufuncs.cf_drain_writebuf() + +#define cpu_sleep(m) cpufuncs.cf_sleep(m) + +#define cpu_context_switch(a) cpufuncs.cf_context_switch(a) +#define cpu_setup(a) cpufuncs.cf_setup(a) + +int set_cpufuncs (void); +#define ARCHITECTURE_NOT_PRESENT 1 /* known but not configured */ +#define ARCHITECTURE_NOT_SUPPORTED 2 /* not known */ + +void cpufunc_nullop (void); +int early_abort_fixup (void *); +int late_abort_fixup (void *); +u_int cpufunc_id (void); +u_int cpufunc_control (u_int clear, u_int set); +u_int cpufunc_auxcontrol (u_int clear, u_int set); +void cpufunc_domains (u_int domains); +u_int cpufunc_dfsr (void); +u_int cpufunc_dfar (void); +u_int cpufunc_ifsr (void); +u_int cpufunc_ifar (void); + +void armv7_setttb (u_int); + +void armv7_tlb_flushID_SE (u_int); +void armv7_tlb_flushI_SE (u_int); + +void armv7_context_switch (u_int); + +void armv7_setup (void); +void armv7_tlb_flushID (void); +void armv7_tlb_flushI (void); +void armv7_tlb_flushD (void); +void armv7_tlb_flushD_SE (u_int va); + +void armv7_flush_bp(void); +void cortex_a15_flush_bp(void); + +void armv7_drain_writebuf (void); +void armv7_cpu_sleep (int mode); + +u_int armv7_periphbase (void); + +void armv7_icache_sync_all (void); +void armv7_icache_sync_range (vaddr_t, vsize_t); + +void armv7_dcache_wbinv_all (void); +void armv7_dcache_wbinv_range (vaddr_t, vsize_t); +void armv7_dcache_inv_range (vaddr_t, vsize_t); +void armv7_dcache_wb_range (vaddr_t, vsize_t); + +void armv7_idcache_wbinv_all (void); +void armv7_idcache_wbinv_range (vaddr_t, vsize_t); + +extern unsigned armv7_dcache_sets_max; +extern unsigned armv7_dcache_sets_inc; +extern unsigned armv7_dcache_index_max; +extern unsigned armv7_dcache_index_inc; + +#define tlb_flush cpu_tlb_flushID +#define setttb cpu_setttb +#define drain_writebuf cpu_drain_writebuf + +/* + * Macros for manipulating CPU interrupts + */ +/* Functions to manipulate the CPSR. */ +static __inline u_int32_t __set_cpsr_c(u_int bic, u_int eor); +static __inline u_int32_t __get_cpsr(void); + +static __inline u_int32_t +__set_cpsr_c(u_int bic, u_int eor) +{ + u_int32_t tmp, ret; + + __asm volatile( + "mrs %0, cpsr\n\t" /* Get the CPSR */ + "bic %1, %0, %2\n\t" /* Clear bits */ + "eor %1, %1, %3\n\t" /* XOR bits */ + "msr cpsr_c, %1" /* Set CPSR control field */ + : "=&r" (ret), "=&r" (tmp) + : "r" (bic), "r" (eor)); + + return ret; +} + +static __inline u_int32_t +__get_cpsr(void) +{ + u_int32_t ret; + + __asm volatile("mrs %0, cpsr" : "=&r" (ret)); + + return ret; +} + +#define disable_interrupts(mask) \ + (__set_cpsr_c((mask) & (PSR_I | PSR_F), \ + (mask) & (PSR_I | PSR_F))) + +#define enable_interrupts(mask) \ + (__set_cpsr_c((mask) & (PSR_I | PSR_F), 0)) + +#define restore_interrupts(old_cpsr) \ + (__set_cpsr_c((PSR_I | PSR_F), (old_cpsr) & (PSR_I | PSR_F))) + +/* + * Functions to manipulate cpu r13 + * (in arm/arm/setstack.S) + */ + +void set_stackptr (u_int mode, u_int address); +u_int get_stackptr (u_int mode); + +/* + * CPU functions from locore.S + */ + +void cpu_reset (void) __attribute__((__noreturn__)); + +/* + * Cache info variables. + */ + +/* PRIMARY CACHE VARIABLES */ +extern int arm_picache_size; +extern int arm_picache_line_size; +extern int arm_picache_ways; + +extern int arm_pdcache_size; /* and unified */ +extern int arm_pdcache_line_size; +extern int arm_pdcache_ways; + +extern int arm_pcache_type; +extern int arm_pcache_unified; + +extern int arm_dcache_align; +extern int arm_dcache_align_mask; + +#endif /* _KERNEL */ +#endif /* _ARM_CPUFUNC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/db_machdep.h b/lib/libc/include/arm-openbsd-eabi/arm/db_machdep.h new file mode 100644 index 0000000000..e5cb80c22d --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/db_machdep.h @@ -0,0 +1,104 @@ +/* $OpenBSD: db_machdep.h,v 1.13 2021/08/30 08:11:12 jasper Exp $ */ +/* $NetBSD: db_machdep.h,v 1.5 2001/11/22 18:00:00 thorpej Exp $ */ + +/* + * Copyright (c) 1996 Scott K Stevens + * + * Mach Operating System + * Copyright (c) 1991,1990 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +#ifndef _ARM_DB_MACHDEP_H_ +#define _ARM_DB_MACHDEP_H_ + +/* + * Machine-dependent defines for new kernel debugger. + */ + +#include +#include +#include +#include + +/* end of mangling */ + +typedef long db_expr_t; /* expression - signed */ + +typedef trapframe_t db_regs_t; + +extern db_regs_t ddb_regs; /* register state */ + +#define PC_REGS(regs) ((vaddr_t)(regs)->tf_pc) +#define SET_PC_REGS(regs, value) (regs)->tf_pc = (register_t)(value) + +#define BKPT_INST (KERNEL_BREAKPOINT) /* breakpoint instruction */ +#define BKPT_SIZE (INSN_SIZE) /* size of breakpoint inst */ +#define BKPT_SET(inst) (BKPT_INST) + +/*#define FIXUP_PC_AFTER_BREAK(regs) ((regs)->tf_pc -= BKPT_SIZE)*/ + +#define T_BREAKPOINT (1) + +#define IS_BREAKPOINT_TRAP(type, code) ((type) == T_BREAKPOINT) +#define IS_WATCHPOINT_TRAP(type, code) (0) + +#define inst_trap_return(ins) (0) +/* ldmxx reg, {..., pc} + 01800000 stack mode + 000f0000 register + 0000ffff register list */ +/* mov pc, reg + 0000000f register */ +#define inst_return(ins) (((ins) & 0x0e108000) == 0x08108000 || \ + ((ins) & 0x0ff0fff0) == 0x01a0f000) +/* bl ... + 00ffffff offset>>2 */ +#define inst_call(ins) (((ins) & 0x0f000000) == 0x0b000000) +/* b ... + 00ffffff offset>>2 */ +/* ldr pc, [pc, reg, lsl #2] + 0000000f register */ +#define inst_branch(ins) (((ins) & 0x0f000000) == 0x0a000000 || \ + ((ins) & 0x0fdffff0) == 0x079ff100) +#define inst_unconditional_flow_transfer(ins) \ + ((((ins) & INSN_COND_MASK) == INSN_COND_AL) && \ + (inst_branch(ins) || inst_call(ins) || inst_return(ins))) + +#define getreg_val (0) +#define next_instr_address(pc, bd) ((bd) ? (pc) : ((pc) + INSN_SIZE)) + +#define DB_MACHINE_COMMANDS + +#define SOFTWARE_SSTEP + +vaddr_t db_branch_taken(u_int inst, vaddr_t pc, db_regs_t *regs); +int db_ktrap (int, db_regs_t *); +void db_machine_init (void); + +#define branch_taken(ins, pc, fun, regs) \ + db_branch_taken((ins), (pc), (regs)) + +void db_show_frame_cmd(db_expr_t, int, db_expr_t, char *); + +#endif /* _ARM_DB_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/disklabel.h b/lib/libc/include/arm-openbsd-eabi/arm/disklabel.h new file mode 100644 index 0000000000..302bb55103 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/disklabel.h @@ -0,0 +1,45 @@ +/* $OpenBSD: disklabel.h,v 1.15 2015/09/30 15:35:30 krw Exp $ */ + +/* + * Copyright (c) 1994 Mark Brinicombe. + * Copyright (c) 1994 Brini. + * All rights reserved. + * + * This code is derived from software written for Brini by Mark Brinicombe + * + * 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 Brini. + * 4. The name of the company nor the name of the author may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY BRINI ``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 BRINI 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_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_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/elf.h b/lib/libc/include/arm-openbsd-eabi/arm/elf.h new file mode 100644 index 0000000000..2c9d2c87b6 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/elf.h @@ -0,0 +1,77 @@ +/* $OpenBSD: elf.h,v 1.1 2024/07/14 09:48:48 jca Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2001 David E. O'Brien + * Copyright (c) 1996-1997 John D. Polstra. + * 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 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 AUTHOR 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_ELF_H_ +#define _MACHINE_ELF_H_ + +/* + * ELF definitions for the ARM architecture. + */ + +#ifdef _KERNEL +# define __HAVE_CPU_HWCAP +# define __HAVE_CPU_HWCAP2 +extern unsigned long hwcap, hwcap2; +#endif /* _KERNEL */ + +/* Flags passed in AT_HWCAP. */ +#define HWCAP_SWP 0x00000001 /* Unsupported, never set. */ +#define HWCAP_HALF 0x00000002 /* Always set. */ +#define HWCAP_THUMB 0x00000004 +#define HWCAP_26BIT 0x00000008 /* Unsupported, never set. */ +#define HWCAP_FAST_MULT 0x00000010 /* Always set. */ +#define HWCAP_FPA 0x00000020 /* Unsupported, never set. */ +#define HWCAP_VFP 0x00000040 +#define HWCAP_EDSP 0x00000080 /* Always set for ARMv6+. */ +#define HWCAP_JAVA 0x00000100 /* Unsupported, never set. */ +#define HWCAP_IWMMXT 0x00000200 /* Unsupported, never set. */ +#define HWCAP_CRUNCH 0x00000400 /* Unsupported, never set. */ +#define HWCAP_THUMBEE 0x00000800 +#define HWCAP_NEON 0x00001000 +#define HWCAP_VFPv3 0x00002000 +#define HWCAP_VFPv3D16 0x00004000 +#define HWCAP_TLS 0x00008000 /* Always set for ARMv6+. */ +#define HWCAP_VFPv4 0x00010000 +#define HWCAP_IDIVA 0x00020000 +#define HWCAP_IDIVT 0x00040000 +#define HWCAP_VFPD32 0x00080000 +#define HWCAP_IDIV (HWCAP_IDIVA | HWCAP_IDIVT) +#define HWCAP_LPAE 0x00100000 +#define HWCAP_EVTSTRM 0x00200000 /* Not implemented yet. */ + +/* Flags passed in AT_HWCAP2. */ +#define HWCAP2_AES 0x00000001 +#define HWCAP2_PMULL 0x00000002 +#define HWCAP2_SHA1 0x00000004 +#define HWCAP2_SHA2 0x00000008 +#define HWCAP2_CRC32 0x00000010 + +#endif /* !_MACHINE_ELF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/endian.h b/lib/libc/include/arm-openbsd-eabi/arm/endian.h new file mode 100644 index 0000000000..5075fc1475 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/endian.h @@ -0,0 +1,29 @@ +/* $OpenBSD: endian.h,v 1.12 2024/05/07 14:26:48 naddy Exp $ */ + +/* + * Copyright (c) 2015 David Gwynne + * + * 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 _ARM_ENDIAN_H_ +#define _ARM_ENDIAN_H_ + +#define _BYTE_ORDER _LITTLE_ENDIAN +#define __STRICT_ALIGNMENT + +#ifndef __FROM_SYS__ENDIAN +#include +#endif + +#endif /* _ARM_ENDIAN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/exec.h b/lib/libc/include/arm-openbsd-eabi/arm/exec.h new file mode 100644 index 0000000000..52730e7d75 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/exec.h @@ -0,0 +1,44 @@ +/* $OpenBSD: exec.h,v 1.6 2017/02/08 05:09:25 guenther Exp $ */ +/* $NetBSD: exec.h,v 1.6 1994/10/27 04:16:05 cgd 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. 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 _ARM_EXEC_H_ +#define _ARM_EXEC_H_ + +#define __LDPGSZ 4096 + +#define ARCH_ELFSIZE 32 + +#define ELF_TARG_CLASS ELFCLASS32 +#define ELF_TARG_DATA ELFDATA2LSB +#define ELF_TARG_MACH EM_ARM + +#define PT_ARM_EXIDX 0x70000001 + +#endif /* _ARM_EXEC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/fdt.h b/lib/libc/include/arm-openbsd-eabi/arm/fdt.h new file mode 100644 index 0000000000..213caef44c --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/fdt.h @@ -0,0 +1,59 @@ +/* $OpenBSD: fdt.h,v 1.10 2020/07/14 15:34:14 patrick Exp $ */ +/* + * Copyright (c) 2016 Patrick Wildt + * + * 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 __ARM_FDT_H__ +#define __ARM_FDT_H__ + +#define _ARM32_BUS_DMA_PRIVATE +#include + +struct fdt_attach_args { + const char *fa_name; + int fa_node; + bus_space_tag_t fa_iot; + bus_dma_tag_t fa_dmat; + struct fdt_reg *fa_reg; + int fa_nreg; + uint32_t *fa_intr; + int fa_nintr; + int fa_acells; + int fa_scells; +}; + +extern int stdout_node; +extern int stdout_speed; +extern bus_space_tag_t fdt_cons_bs_tag; + +void *fdt_find_cons(const char *); + +#define fdt_intr_enable arm_intr_enable +#define fdt_intr_establish arm_intr_establish_fdt +#define fdt_intr_establish_cpu arm_intr_establish_fdt_cpu +#define fdt_intr_establish_idx arm_intr_establish_fdt_idx +#define fdt_intr_establish_idx_cpu arm_intr_establish_fdt_idx_cpu +#define fdt_intr_establish_imap arm_intr_establish_fdt_imap +#define fdt_intr_establish_imap_cpu arm_intr_establish_fdt_imap_cpu +#define fdt_intr_establish_msi arm_intr_establish_fdt_msi +#define fdt_intr_establish_msi_cpu arm_intr_establish_fdt_msi_cpu +#define fdt_intr_disable arm_intr_disable +#define fdt_intr_disestablish arm_intr_disestablish_fdt +#define fdt_intr_get_parent arm_intr_get_parent +#define fdt_intr_parent_establish arm_intr_parent_establish_fdt +#define fdt_intr_parent_disestablish arm_intr_parent_disestablish_fdt +#define fdt_intr_register arm_intr_register_fdt + +#endif /* __ARM_FDT_H__ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/fenv.h b/lib/libc/include/arm-openbsd-eabi/arm/fenv.h new file mode 100644 index 0000000000..c9c49d0ab1 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/fenv.h @@ -0,0 +1,97 @@ +/* $OpenBSD: fenv.h,v 1.3 2011/05/25 21:46:49 martynas Exp $ */ + +/* + * Copyright (c) 2011 Martynas Venckus + * + * 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 _ARM_FENV_H_ +#define _ARM_FENV_H_ + +/* + * Each symbol representing a floating point exception expands to an integer + * constant expression with values, such that bitwise-inclusive ORs of _all + * combinations_ of the constants result in distinct values. + * + * We use such values that allow direct bitwise operations on FPU registers. + */ +#define FE_INVALID 0x01 +#define FE_DIVBYZERO 0x02 +#define FE_OVERFLOW 0x04 +#define FE_UNDERFLOW 0x08 +#define FE_INEXACT 0x10 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * exception constants defined above. + */ +#define FE_ALL_EXCEPT (FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | \ + FE_UNDERFLOW | FE_INEXACT) + +/* + * Each symbol representing the rounding direction, expands to an integer + * constant expression whose value is distinct non-negative value. + * + * We use such values that allow direct bitwise operations on FPU registers. + */ +#define FE_TONEAREST 0x0 +#define FE_UPWARD 0x1 +#define FE_DOWNWARD 0x2 +#define FE_TOWARDZERO 0x3 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * rounding direction constants defined above. + */ +#define _ROUND_MASK (FE_TONEAREST | FE_UPWARD | FE_DOWNWARD | \ + FE_TOWARDZERO) + +/* + * fenv_t represents the entire floating-point environment. + */ +typedef struct { + unsigned int __sticky; + unsigned int __mask; + unsigned int __round; +} fenv_t; + +/* + * The following constant represents the default floating-point environment + * (that is, the one installed at program startup) and has type pointer to + * const-qualified fenv_t. + * + * It can be used as an argument to the functions within the header + * that manage the floating-point environment, namely fesetenv() and + * feupdateenv(). + */ +__BEGIN_DECLS +extern fenv_t __fe_dfl_env; +__END_DECLS +#define FE_DFL_ENV ((const fenv_t *)&__fe_dfl_env) + +/* + * fexcept_t represents the floating-point status flags collectively, including + * any status the implementation associates with the flags. + * + * A floating-point status flag is a system variable whose value is set (but + * never cleared) when a floating-point exception is raised, which occurs as a + * side effect of exceptional floating-point arithmetic to provide auxiliary + * information. + * + * A floating-point control mode is a system variable whose value may be set by + * the user to affect the subsequent behavior of floating-point arithmetic. + */ +typedef unsigned int fexcept_t; + +#endif /* !_ARM_FENV_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/fiq.h b/lib/libc/include/arm-openbsd-eabi/arm/fiq.h new file mode 100644 index 0000000000..4abafaa056 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/fiq.h @@ -0,0 +1,69 @@ +/* $OpenBSD: fiq.h,v 1.1 2004/02/01 05:09:49 drahn Exp $ */ +/* $NetBSD: fiq.h,v 1.1 2001/12/20 01:20:23 thorpej Exp $ */ + +/* + * Copyright (c) 2001 Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Jason R. Thorpe for Wasabi Systems, Inc. + * + * 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 for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC + * 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 _ARM_FIQ_H_ +#define _ARM_FIQ_H_ + +#include + +struct fiqregs { + u_int fr_r8; /* FIQ mode r8 */ + u_int fr_r9; /* FIQ mode r9 */ + u_int fr_r10; /* FIQ mode r10 */ + u_int fr_r11; /* FIQ mode r11 */ + u_int fr_r12; /* FIQ mode r12 */ + u_int fr_r13; /* FIQ mode r13 */ +}; + +struct fiqhandler { + TAILQ_ENTRY(fiqhandler) fh_list;/* link in the FIQ handler stack */ + void *fh_func; /* FIQ handler routine */ + size_t fh_size; /* size of FIQ handler */ + int fh_flags; /* flags; see below */ + struct fiqregs *fh_regs; /* pointer to regs structure */ +}; + +#define FH_CANPUSH 0x01 /* can push this handler out of the way */ + +int fiq_claim(struct fiqhandler *); +void fiq_release(struct fiqhandler *); + +void fiq_getregs(struct fiqregs *); +void fiq_setregs(struct fiqregs *); + +#endif /* _ARM_FIQ_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/frame.h b/lib/libc/include/arm-openbsd-eabi/arm/frame.h new file mode 100644 index 0000000000..cbd99bcc8c --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/frame.h @@ -0,0 +1,297 @@ +/* $OpenBSD: frame.h,v 1.14 2022/12/08 01:25:44 guenther Exp $ */ +/* $NetBSD: frame.h,v 1.9 2003/12/01 08:48:33 scw Exp $ */ + +/* + * Copyright (c) 1994-1997 Mark Brinicombe. + * Copyright (c) 1994 Brini. + * All rights reserved. + * + * This code is derived from software written for Brini by Mark Brinicombe + * + * 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 Brini. + * 4. The name of the company nor the name of the author may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY BRINI ``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 BRINI 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. + * + * RiscBSD kernel project + * + * frame.h + * + * Stack frames structures + * + * Created : 30/09/94 + */ + +#ifndef _ARM_FRAME_H_ +#define _ARM_FRAME_H_ + +#ifndef _LOCORE + +#include + +/* + * Trap frame. Pushed onto the kernel stack on a trap (synchronous exception). + */ + +typedef struct trapframe { + register_t tf_spsr; + register_t tf_r0; + register_t tf_r1; + register_t tf_r2; + register_t tf_r3; + register_t tf_r4; + register_t tf_r5; + register_t tf_r6; + register_t tf_r7; + register_t tf_r8; + register_t tf_r9; + register_t tf_r10; + register_t tf_r11; + register_t tf_r12; + register_t tf_usr_sp; + register_t tf_usr_lr; + register_t tf_svc_sp; + register_t tf_svc_lr; + register_t tf_pc; + register_t tf_pad; +} trapframe_t; + +/* Register numbers */ +#define tf_r13 tf_usr_sp +#define tf_r14 tf_usr_lr +#define tf_r15 tf_pc + +/* Determine if a fault came from user mode */ +#define TRAP_USERMODE(tf) ((tf->tf_spsr & PSR_MODE) == PSR_USR32_MODE) + +/* + * Signal frame. Pushed onto user stack before calling sigcode. + */ + +struct sigframe { + int sf_signum; + siginfo_t *sf_sip; + struct sigcontext *sf_scp; + sig_t sf_handler; + struct sigcontext sf_sc; + siginfo_t sf_si; +}; + +/* the pointers are used in the trampoline code to locate the ucontext */ +#if 0 +struct sigframe_siginfo { + siginfo_t sf_si; /* actual saved siginfo */ + ucontext_t sf_uc; /* actual saved ucontext */ +}; +#endif + +#if 0 +#ifdef _KERNEL +void sendsig_sigcontext(const ksiginfo_t *, const sigset_t *); +#endif +#endif + +#endif /* _LOCORE */ + +#ifndef _LOCORE + +/* + * System stack frames. + */ + +typedef struct irqframe { + unsigned int if_spsr; + unsigned int if_r0; + unsigned int if_r1; + unsigned int if_r2; + unsigned int if_r3; + unsigned int if_r4; + unsigned int if_r5; + unsigned int if_r6; + unsigned int if_r7; + unsigned int if_r8; + unsigned int if_r9; + unsigned int if_r10; + unsigned int if_r11; + unsigned int if_r12; + unsigned int if_usr_sp; + unsigned int if_usr_lr; + unsigned int if_svc_sp; + unsigned int if_svc_lr; + unsigned int if_pc; + unsigned int if_pad; +} irqframe_t; + +#define clockframe irqframe + +/* + * Switch frame + */ + +struct switchframe { + u_int sf_pad; + u_int sf_r4; + u_int sf_r5; + u_int sf_r6; + u_int sf_r7; + u_int sf_pc; +}; + +/* + * Stack frame. Used during stack traces (db_trace.c) + */ +struct frame { + u_int fr_fp; + u_int fr_sp; + u_int fr_lr; + u_int fr_pc; +}; + +#else /* _LOCORE */ + +#define AST_LOCALS \ +.Laflt_astpending: ;\ + .word astpending + +#define DO_AST \ + ldr r0, [sp] /* Get the SPSR from stack */ ;\ + mrs r4, cpsr /* save CPSR */ ;\ + and r0, r0, #(PSR_MODE) /* Returning to USR mode? */ ;\ + teq r0, #(PSR_USR32_MODE) ;\ + ldreq r5, .Laflt_astpending ;\ + bne 2f /* Nope, get out now */ ;\ + bic r4, r4, #(PSR_I) ;\ +1: orr r0, r4, #(PSR_I) /* Disable IRQs */ ;\ + msr cpsr_c, r0 ;\ + ldr r1, [r5] /* Pending AST? */ ;\ + teq r1, #0x00000000 ;\ + beq 2f /* Nope. Just bail */ ;\ + mov r1, #0x00000000 ;\ + str r1, [r5] /* Clear astpending */ ;\ + msr cpsr_c, r4 /* Restore interrupts */ ;\ + mov r0, sp ;\ + adr lr, 1b ;\ + b ast /* ast(frame) */ ;\ +2: + +/* + * ASM macros for pushing and pulling trapframes from the stack + * + * These macros are used to handle the irqframe and trapframe structures + * defined above. + */ + +/* + * CLREX - On ARMv7 machines that support atomic instructions, we need + * to clear the exclusive monitors on kernel exit, so that a userland + * atomic store can't succeed due to an unrelated outstanding atomic + * operation. ARM also highly recommends clearing the monitor on data + * aborts, as the monitor state after taking a data abort is unknown. + * Issuing a clrex on kernel entry and on kernel exit is the easiest + * way to take care of both issues and to make sure that the kernel + * and userland do not leave any outstanding reserves active. + */ + +/* + * PUSHFRAME - macro to push a trap frame on the stack in the current mode + * Since the current mode is used, the SVC lr field is not defined. + */ + +#define PUSHFRAME \ + clrex; \ + sub sp, sp, #4; /* Align the stack */ \ + str lr, [sp, #-4]!; /* Push the return address */ \ + sub sp, sp, #(4*17); /* Adjust the stack pointer */ \ + stmia sp, {r0-r14}^; /* Push the user mode registers */ \ + mov r0, r0; /* NOP for previous instruction */ \ + mrs r0, spsr; /* Put the SPSR on the stack */ \ + str r0, [sp, #-4]! + +/* + * PULLFRAME - macro to pull a trap frame from the stack in the current mode + * Since the current mode is used, the SVC lr field is ignored. + */ + +#define PULLFRAME \ + clrex; \ + ldr r0, [sp], #0x0004; /* Get the SPSR from stack */ \ + msr spsr_fsxc, r0; \ + ldmia sp, {r0-r14}^; /* Restore registers (usr mode) */ \ + mov r0, r0; /* NOP for previous instruction */ \ + add sp, sp, #(4*17); /* Adjust the stack pointer */ \ + ldr lr, [sp], #0x0004; /* Pull the return address */ \ + add sp, sp, #4 /* Align the stack */ + +/* + * PUSHFRAMEINSVC - macro to push a trap frame on the stack in SVC32 mode + * This should only be used if the processor is not currently in SVC32 + * mode. The processor mode is switched to SVC mode and the trap frame is + * stored. The SVC lr field is used to store the previous value of + * lr in SVC mode. + */ + +#define PUSHFRAMEINSVC \ + clrex; \ + stmdb sp, {r0-r3}; /* Save 4 registers */ \ + mov r0, lr; /* Save xxx32 r14 */ \ + mov r1, sp; /* Save xxx32 sp */ \ + mrs r3, spsr; /* Save xxx32 spsr */ \ + mrs r2, cpsr; /* Get the CPSR */ \ + bic r2, r2, #(PSR_MODE); /* Fix for SVC mode */ \ + orr r2, r2, #(PSR_SVC32_MODE); \ + msr cpsr_c, r2; /* Punch into SVC mode */ \ + mov r2, sp; /* Save SVC sp */ \ + bic sp, sp, #7; /* Align sp to an 8-byte address */ \ + sub sp, sp, #4; /* Pad trapframe to keep alignment */ \ + str r0, [sp, #-4]!; /* Push return address */ \ + str lr, [sp, #-4]!; /* Push SVC lr */ \ + str r2, [sp, #-4]!; /* Push SVC sp */ \ + msr spsr_fsxc, r3; /* Restore correct spsr */ \ + ldmdb r1, {r0-r3}; /* Restore 4 regs from xxx mode */ \ + sub sp, sp, #(4*15); /* Adjust the stack pointer */ \ + stmia sp, {r0-r14}^; /* Push the user mode registers */ \ + mov r0, r0; /* NOP for previous instruction */ \ + mrs r0, spsr; /* Put the SPSR on the stack */ \ + str r0, [sp, #-4]! + +/* + * PULLFRAMEFROMSVCANDEXIT - macro to pull a trap frame from the stack + * in SVC32 mode and restore the saved processor mode and PC. + * This should be used when the SVC lr register needs to be restored on + * exit. + */ + +#define PULLFRAMEFROMSVCANDEXIT \ + clrex; \ + ldr r0, [sp], #0x0004; /* Get the SPSR from stack */ \ + msr spsr_fsxc, r0; /* restore SPSR */ \ + ldmia sp, {r0-r14}^; /* Restore registers (usr mode) */ \ + mov r0, r0; /* NOP for previous instruction */ \ + add sp, sp, #(4*15); /* Adjust the stack pointer */ \ + ldmia sp, {sp, lr, pc}^ /* Restore lr and exit */ + +#endif /* _LOCORE */ + +#endif /* _ARM_FRAME_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/ieee.h b/lib/libc/include/arm-openbsd-eabi/arm/ieee.h new file mode 100644 index 0000000000..dc7998e8d1 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/ieee.h @@ -0,0 +1,192 @@ +/* $OpenBSD: ieee.h,v 1.4 2011/11/08 17:06:51 deraadt Exp $ */ +/* $NetBSD: ieee.h,v 1.2 2001/02/21 17:43:50 bjh21 Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)ieee.h 8.1 (Berkeley) 6/11/93 + */ + +/* + * ieee.h defines the machine-dependent layout of the machine's IEEE + * floating point. + */ + +/* + * Define the number of bits in each fraction and exponent. + * + * k k+1 + * Note that 1.0 x 2 == 0.1 x 2 and that denorms are represented + * + * (-exp_bias+1) + * as fractions that look like 0.fffff x 2 . This means that + * + * -126 + * the number 0.10000 x 2 , for instance, is the same as the normalized + * + * -127 -128 + * float 1.0 x 2 . Thus, to represent 2 , we need one leading zero + * + * -129 + * in the fraction; to represent 2 , we need two, and so on. This + * + * (-exp_bias-fracbits+1) + * implies that the smallest denormalized number is 2 + * + * for whichever format we are talking about: for single precision, for + * + * -126 -149 + * instance, we get .00000000000000000000001 x 2 , or 1.0 x 2 , and + * + * -149 == -127 - 23 + 1. + */ + +/* + * The ARM has two sets of FP data formats. The FPA supports 32-bit, 64-bit + * and 96-bit IEEE formats, with the words in big-endian order. VFP supports + * 32-bin and 64-bit IEEE formats with the words in the CPU's native byte + * order. + * + * The FPA also has two packed decimal formats, but we ignore them here. + */ + +#define SNG_EXPBITS 8 +#define SNG_FRACBITS 23 + +#define DBL_EXPBITS 11 +#define DBL_FRACHBITS 20 +#define DBL_FRACLBITS 32 +#define DBL_FRACBITS 52 + +#ifndef __VFP_FP__ +#define E80_EXPBITS 15 +#define E80_FRACHBITS 31 +#define E80_FRACLBITS 32 +#define E80_FRACBITS 64 + +#define EXT_EXPBITS 15 +#define EXT_FRACHBITS 16 +#define EXT_FRACHMBITS 32 +#define EXT_FRACLMBITS 32 +#define EXT_FRACLBITS 32 +#define EXT_FRACBITS 112 +#endif + +struct ieee_single { + u_int sng_frac:23; + u_int sng_exp:8; + u_int sng_sign:1; +}; + +#ifdef __VFP_FP__ +struct ieee_double { + u_int dbl_fracl; + u_int dbl_frach:20; + u_int dbl_exp:11; + u_int dbl_sign:1; +}; +#else /* !__VFP_FP__ */ +struct ieee_double { + u_int dbl_frach:20; + u_int dbl_exp:11; + u_int dbl_sign:1; + u_int dbl_fracl; +}; + +union ieee_double_u { + double dblu_d; + struct ieee_double dblu_dbl; +}; + + +struct ieee_e80 { + u_int e80_exp:15; + u_int e80_zero:16; + u_int e80_sign:1; + u_int e80_frach:31; + u_int e80_j:1; + u_int e80_fracl; +}; + +struct ieee_ext { + u_int ext_frach:16; + u_int ext_exp:15; + u_int ext_sign:1; + u_int ext_frachm; + u_int ext_fraclm; + u_int ext_fracl; +}; +#endif /* !__VFP_FP__ */ + +/* + * Floats whose exponent is in [1..INFNAN) (of whatever type) are + * `normal'. Floats whose exponent is INFNAN are either Inf or NaN. + * Floats whose exponent is zero are either zero (iff all fraction + * bits are zero) or subnormal values. + * + * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its + * high fraction; if the bit is set, it is a `quiet NaN'. + */ +#define SNG_EXP_INFNAN 255 +#define DBL_EXP_INFNAN 2047 +#ifndef __VFP_FP__ +#define E80_EXP_INFNAN 32767 +#define EXT_EXP_INFNAN 32767 +#endif /* !__VFP_FP__ */ + +#if 0 +#define SNG_QUIETNAN (1 << 22) +#define DBL_QUIETNAN (1 << 19) +#ifndef __VFP_FP__ +#define E80_QUIETNAN (1 << 15) +#define EXT_QUIETNAN (1 << 15) +#endif /* !__VFP_FP__ */ +#endif + +/* + * Exponent biases. + */ +#define SNG_EXP_BIAS 127 +#define DBL_EXP_BIAS 1023 +#ifndef __VFP_FP__ +#define E80_EXP_BIAS 16383 +#define EXT_EXP_BIAS 16383 +#endif /* !__VFP_FP__ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/ieeefp.h b/lib/libc/include/arm-openbsd-eabi/arm/ieeefp.h new file mode 100644 index 0000000000..cf2906b99b --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/ieeefp.h @@ -0,0 +1,41 @@ +/* $OpenBSD: ieeefp.h,v 1.2 2011/03/23 16:54:34 pirofti Exp $ */ +/* $NetBSD: ieeefp.h,v 1.1 2001/01/10 19:02:06 bjh21 Exp $ */ + +/* + * Based on ieeefp.h written by J.T. Conklin, Apr 28, 1995 + * Public domain. + */ + +#ifndef _ARM_IEEEFP_H_ +#define _ARM_IEEEFP_H_ + +/* FP exception codes */ + +#define FP_EXCEPT_INV 0 +#define FP_EXCEPT_DZ 1 +#define FP_EXCEPT_OFL 2 +#define FP_EXCEPT_UFL 3 +#define FP_EXCEPT_IMP 4 + +/* Exception type (used by fpsetmask() et al.) */ + +typedef int fp_except; + +/* Bit defines for fp_except */ + +#define FP_X_INV (1 << FP_EXCEPT_INV) /* invalid operation exception */ +#define FP_X_DZ (1 << FP_EXCEPT_DZ) /* divide-by-zero exception */ +#define FP_X_OFL (1 << FP_EXCEPT_OFL) /* overflow exception */ +#define FP_X_UFL (1 << FP_EXCEPT_UFL) /* underflow exception */ +#define FP_X_IMP (1 << FP_EXCEPT_IMP) /* imprecise (loss of precision; "inexact") */ + +/* Rounding modes */ + +typedef enum { + FP_RN=0, /* round to nearest representable number */ + FP_RP=1, /* round toward positive infinity */ + FP_RM=2, /* round toward negative infinity */ + FP_RZ=3 /* round to zero (truncate) */ +} fp_rnd; + +#endif /* _ARM_IEEEFP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/kcore.h b/lib/libc/include/arm-openbsd-eabi/arm/kcore.h new file mode 100644 index 0000000000..5371f10218 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/kcore.h @@ -0,0 +1,15 @@ +/* $OpenBSD: kcore.h,v 1.1 2007/05/19 15:49:05 miod Exp $ */ +/* public domain */ + +/* Make sure this is larger than DRAM_BLOCKS on all arm-based platforms */ +#define NPHYS_RAM_SEGS 8 + +typedef struct cpu_kcore_hdr { + u_int32_t kernelbase; /* value of KERNEL_BASE */ + u_int32_t kerneloffs; /* offset of kernel in RAM */ + u_int32_t staticsize; /* size of contiguous mapping */ + u_int32_t pmap_kernel_l1; /* pmap_kernel()->pm_l1 */ + u_int32_t pmap_kernel_l2; /* pmap_kernel()->pm_l2 */ + u_int32_t reserved[11]; + phys_ram_seg_t ram_segs[NPHYS_RAM_SEGS]; +} cpu_kcore_hdr_t; \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/limits.h b/lib/libc/include/arm-openbsd-eabi/arm/limits.h new file mode 100644 index 0000000000..822acbd3be --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/limits.h @@ -0,0 +1,53 @@ +/* $OpenBSD: limits.h,v 1.7 2015/04/30 13:42:08 millert Exp $ */ +/* $NetBSD: limits.h,v 1.4 2003/04/28 23:16:18 bjh21 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 _ARM_LIMITS_H_ +#define _ARM_LIMITS_H_ + +#include + +#if __POSIX_VISIBLE || __XPG_VISIBLE +#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 /* _ARM_LIMITS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/machdep.h b/lib/libc/include/arm-openbsd-eabi/arm/machdep.h new file mode 100644 index 0000000000..8dba386dc1 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/machdep.h @@ -0,0 +1,20 @@ +/* $OpenBSD: machdep.h,v 1.6 2024/04/29 12:24:46 jsg Exp $ */ +/* $NetBSD: machdep.h,v 1.7 2002/02/21 02:52:21 thorpej Exp $ */ + +#ifndef _ARM_MACHDEP_H_ +#define _ARM_MACHDEP_H_ + +/* misc prototypes used by the many arm machdeps */ +void halt (void); +void data_abort_handler (trapframe_t *); +void prefetch_abort_handler (trapframe_t *); +void undefinedinstruction_bounce (trapframe_t *); +void dumpsys (void); + +/* + * note that we use void * as all the platforms have different ideas on what + * the structure is + */ +u_int initarm (void *, void *, void *, paddr_t); + +#endif \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/mplock.h b/lib/libc/include/arm-openbsd-eabi/arm/mplock.h new file mode 100644 index 0000000000..f3981f16b1 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/mplock.h @@ -0,0 +1,10 @@ +/* $OpenBSD: mplock.h,v 1.1 2018/08/06 18:39:13 kettenis Exp $ */ + +/* public domain */ + +#ifndef _MACHINE_MPLOCK_H_ +#define _MACHINE_MPLOCK_H_ + +#define __USE_MI_MPLOCK + +#endif /* !_MACHINE_MPLOCK_H */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/mutex.h b/lib/libc/include/arm-openbsd-eabi/arm/mutex.h new file mode 100644 index 0000000000..c10ae2bcb4 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/mutex.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mutex.h,v 1.5 2018/02/10 12:44:20 mpi Exp $ */ + +#define __USE_MI_MUTEX \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/openpromio.h b/lib/libc/include/arm-openbsd-eabi/arm/openpromio.h new file mode 100644 index 0000000000..45e430e353 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/openpromio.h @@ -0,0 +1,57 @@ +/* $OpenBSD: openpromio.h,v 1.1 2016/05/21 21:24:36 kettenis Exp $ */ +/* $NetBSD: openpromio.h,v 1.1.1.1 1998/06/20 04:58:52 eeh Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)openpromio.h 8.1 (Berkeley) 6/11/93 + */ + +struct opiocdesc { + int op_nodeid; /* passed or returned node id */ + int op_namelen; /* length of op_name */ + char *op_name; /* pointer to field name */ + int op_buflen; /* length of op_buf (value-result) */ + char *op_buf; /* pointer to field value */ +}; + +#define OPIOCGET _IOWR('O', 1, struct opiocdesc) /* get openprom field */ +#define OPIOCSET _IOW('O', 2, struct opiocdesc) /* set openprom field */ +#define OPIOCNEXTPROP _IOWR('O', 3, struct opiocdesc) /* get next property */ +#define OPIOCGETOPTNODE _IOR('O', 4, int) /* get openprom field */ +#define OPIOCGETNEXT _IOWR('O', 5, int) /* get next node of node */ +#define OPIOCGETCHILD _IOWR('O', 6, int) /* get first child of node */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/param.h b/lib/libc/include/arm-openbsd-eabi/arm/param.h new file mode 100644 index 0000000000..8b542e1d4d --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/param.h @@ -0,0 +1,106 @@ +/* $OpenBSD: param.h,v 1.25 2023/12/14 13:26:49 claudio Exp $ */ + +/* + * Copyright (c) 1994,1995 Mark Brinicombe. + * 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 the RiscBSD team. + * 4. The name "RiscBSD" nor the name of the author may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY RISCBSD ``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 RISCBSD 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 _ARM_PARAM_H_ +#define _ARM_PARAM_H_ + +#define MACHINE_ARCH "arm" +#define _MACHINE_ARCH arm +#define MID_MACHINE MID_ARM6 + +#define PAGE_SHIFT 12 +#define PAGE_SIZE (1 << PAGE_SHIFT) +#define PAGE_MASK (PAGE_SIZE - 1) + +#ifdef _KERNEL + +#define NPTEPG (PAGE_SIZE/(sizeof (pt_entry_t))) + +#define NBPG PAGE_SIZE +#define PGSHIFT PAGE_SHIFT +#define PGOFSET PAGE_MASK + +#define UPAGES 2 /* 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 (32 * 1024) /* max cluster allocation */ + +/* Constants used to divide the USPACE area */ +/* + * The USPACE area contains : + * 1. the user structure for the process + * 2. the fp context for FP emulation + * 3. the kernel (svc) stack + * 4. the undefined instruction stack + * + * The layout of the area looks like this + * + * | user area | FP context | undefined stack | kernel stack | + * + * The size of the user area is known. + * The size of the FP context is variable depending of the FP emulator + * in use and whether there is hardware FP support. However we can put + * an upper limit on it. + * The undefined stack needs to be at least 512 bytes. This is a requirement + * of the FP emulators + * The kernel stack should be at least 4K in size. + * + * The stack top addresses are used to set the stack pointers. The stack bottom + * addresses are the addresses monitored by the diagnostic code for stack + * overflows. + */ + +#define FPCONTEXTSIZE (0x100) +#define USPACE_SVC_STACK_TOP (USPACE) +#define USPACE_SVC_STACK_BOTTOM (USPACE_SVC_STACK_TOP - 0x1000) +#define USPACE_UNDEF_STACK_TOP (USPACE_SVC_STACK_BOTTOM - 0x10) +#define USPACE_UNDEF_STACK_BOTTOM (sizeof(struct user) + FPCONTEXTSIZE + 10) + +#ifndef _LOCORE +void delay (unsigned); +#define DELAY(x) delay(x) +#endif + +#if !defined(_LOCORE) +#include +#endif + +/* ARM-specific macro to align a stack pointer (downwards). */ +#define STACKALIGNBYTES (8 - 1) +#define STACKALIGN(p) ((u_long)(p) &~ STACKALIGNBYTES) + +#endif /* _KERNEL */ + +#endif /* _ARM_PARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/pcb.h b/lib/libc/include/arm-openbsd-eabi/arm/pcb.h new file mode 100644 index 0000000000..066db42bb3 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/pcb.h @@ -0,0 +1,91 @@ +/* $OpenBSD: pcb.h,v 1.8 2018/01/26 16:22:20 kettenis Exp $ */ +/* $NetBSD: pcb.h,v 1.10 2003/10/13 21:46:39 scw Exp $ */ + +/* + * Copyright (c) 2001 Matt Thomas . + * Copyright (c) 1994 Mark Brinicombe. + * 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 the RiscBSD team. + * 4. The name "RiscBSD" nor the name of the author may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY RISCBSD ``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 RISCBSD 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 _ARM_PCB_H_ +#define _ARM_PCB_H_ + +#include + +#include +#include + +struct trapframe; + +struct pcb_arm32 { + paddr_t pcb32_pagedir; /* PT hooks */ + pd_entry_t *pcb32_pl1vec; /* PTR to vector_base L1 entry*/ + pd_entry_t pcb32_l1vec; /* Value to stuff on ctx sw */ + u_int pcb32_dacr; /* Domain Access Control Reg */ + void *pcb32_cstate; /* &pmap->pm_cstate */ + /* + * WARNING! + * cpuswitch.S relies on pcb32_r8 being quad-aligned in struct pcb + * (due to the use of "strd" when compiled for XSCALE) + */ + u_int pcb32_r8; /* used */ + u_int pcb32_r9; /* used */ + u_int pcb32_r10; /* used */ + u_int pcb32_r11; /* used */ + u_int pcb32_r12; /* used */ + u_int pcb32_sp; /* used */ + u_int pcb32_lr; + u_int pcb32_pc; + u_int pcb32_und_sp; +}; +#define pcb_pagedir pcb_un.un_32.pcb32_pagedir +#define pcb_pl1vec pcb_un.un_32.pcb32_pl1vec +#define pcb_l1vec pcb_un.un_32.pcb32_l1vec +#define pcb_dacr pcb_un.un_32.pcb32_dacr +#define pcb_cstate pcb_un.un_32.pcb32_cstate + +/* + * WARNING! + * See warning for struct pcb_arm32, above, before changing struct pcb! + */ +struct pcb { + u_int pcb_flags; +#define PCB_FPU 0x00000001 /* Process had FPU initialized */ + struct trapframe *pcb_tf; + caddr_t pcb_onfault; /* On fault handler */ + union { + struct pcb_arm32 un_32; + } pcb_un; + struct fpreg pcb_fpstate; /* Floating Point state */ + struct cpu_info *pcb_fpcpu; + void *pcb_tcb; +}; + +#endif /* _ARM_PCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/pci_machdep.h b/lib/libc/include/arm-openbsd-eabi/arm/pci_machdep.h new file mode 100644 index 0000000000..4d03f5b112 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/pci_machdep.h @@ -0,0 +1,109 @@ +/* $OpenBSD: pci_machdep.h,v 1.18 2022/01/06 08:46:50 kettenis Exp $ */ + +/* + * Copyright (c) 2003-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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. + * + */ + +typedef struct arm32_pci_chipset *pci_chipset_tag_t; +typedef uint64_t pcitag_t; + +#define PCITAG_NODE(x) ((x) >> 32) +#define PCITAG_OFFSET(x) ((x) & 0xffffffff) + +typedef u_long pci_intr_handle_t; + +struct pci_attach_args; + +/* + * arm32-specific PCI structure and type definitions. + * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE. + */ +struct arm32_pci_chipset { + void *pc_conf_v; + void (*pc_attach_hook)(struct device *, + struct device *, struct pcibus_attach_args *); + int (*pc_bus_maxdevs)(void *, int); + pcitag_t (*pc_make_tag)(void *, int, int, int); + void (*pc_decompose_tag)(void *, pcitag_t, int *, + int *, int *); + int (*pc_conf_size)(void *, pcitag_t); + pcireg_t (*pc_conf_read)(void *, pcitag_t, int); + void (*pc_conf_write)(void *, pcitag_t, int, pcireg_t); + int (*pc_probe_device_hook)(void *, struct pci_attach_args *); + + void *pc_intr_v; + int (*pc_intr_map)(struct pci_attach_args *, + pci_intr_handle_t *); + int (*pc_intr_map_msi)(struct pci_attach_args *, + pci_intr_handle_t *); + int (*pc_intr_map_msix)(struct pci_attach_args *, + int, pci_intr_handle_t *); + const char *(*pc_intr_string)(void *, pci_intr_handle_t); + void *(*pc_intr_establish)(void *, pci_intr_handle_t, + int, struct cpu_info *, int (*)(void *), void *, + char *); + void (*pc_intr_disestablish)(void *, void *); +}; + +/* + * Functions provided to machine-independent PCI code. + */ +#define pci_attach_hook(p, s, pba) \ + (*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba)) +#define pci_bus_maxdevs(c, b) \ + (*(c)->pc_bus_maxdevs)((c)->pc_conf_v, (b)) +#define pci_make_tag(c, b, d, f) \ + (*(c)->pc_make_tag)((c)->pc_conf_v, (b), (d), (f)) +#define pci_decompose_tag(c, t, bp, dp, fp) \ + (*(c)->pc_decompose_tag)((c)->pc_conf_v, (t), (bp), (dp), (fp)) +#define pci_conf_size(c, t) \ + (*(c)->pc_conf_size)((c)->pc_conf_v, (t)) +#define pci_conf_read(c, t, r) \ + (*(c)->pc_conf_read)((c)->pc_conf_v, (t), (r)) +#define pci_conf_write(c, t, r, v) \ + (*(c)->pc_conf_write)((c)->pc_conf_v, (t), (r), (v)) +#define pci_probe_device_hook(c, a) \ + (*(c)->pc_probe_device_hook)((c)->pc_conf_v, (a)) +#define pci_intr_map(c, ihp) \ + (*(c)->pa_pc->pc_intr_map)((c), (ihp)) +#define pci_intr_map_msi(c, ihp) \ + (*(c)->pa_pc->pc_intr_map_msi)((c), (ihp)) +#define pci_intr_map_msix(c, vec, ihp) \ + (*(c)->pa_pc->pc_intr_map_msix)((c), (vec), (ihp)) +#define pci_intr_string(c, ih) \ + (*(c)->pc_intr_string)((c)->pc_intr_v, (ih)) +#define pci_intr_establish(c, ih, l, h, a, nm) \ + (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), NULL, (h), (a),\ + (nm)) +#define pci_intr_establish_cpu(c, ih, l, ci, h, a, nm) \ + (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), (ci), (h), (a),\ + (nm)) +#define pci_intr_disestablish(c, iv) \ + (*(c)->pc_intr_disestablish)((c)->pc_intr_v, (iv)) + +#define pci_min_powerstate(c, t) (PCI_PMCSR_STATE_D3) +#define pci_set_powerstate_md(c, t, s, p) + +#define pci_dev_postattach(a, b) \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/pmap.h b/lib/libc/include/arm-openbsd-eabi/arm/pmap.h new file mode 100644 index 0000000000..4e717b13d1 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/pmap.h @@ -0,0 +1,513 @@ +/* $OpenBSD: pmap.h,v 1.57 2024/11/07 08:12:12 miod Exp $ */ +/* $NetBSD: pmap.h,v 1.76 2003/09/06 09:10:46 rearnsha Exp $ */ + +/* + * Copyright (c) 2002, 2003 Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Jason R. Thorpe & Steve C. Woodford for Wasabi Systems, Inc. + * + * 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 for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 1994,1995 Mark Brinicombe. + * 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 Mark Brinicombe + * 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 _ARM_PMAP_H_ +#define _ARM_PMAP_H_ + +#ifdef _KERNEL + +#include +#include +#ifndef _LOCORE +#include +#endif + +/* + * a pmap describes a processes' 4GB virtual address space. this + * virtual address space can be broken up into 4096 1MB regions which + * are described by L1 PTEs in the L1 table. + * + * There is a line drawn at KERNEL_BASE. Everything below that line + * changes when the VM context is switched. Everything above that line + * is the same no matter which VM context is running. This is achieved + * by making the L1 PTEs for those slots above KERNEL_BASE reference + * kernel L2 tables. + * + * The basic layout of the virtual address space thus looks like this: + * + * 0xffffffff + * . + * . + * . + * KERNEL_BASE + * -------------------- + * . + * . + * . + * 0x00000000 + */ + +/* + * The number of L2 descriptor tables which can be tracked by an l2_dtable. + * A bucket size of 16 provides for 16MB of contiguous virtual address + * space per l2_dtable. Most processes will, therefore, require only two or + * three of these to map their whole working set. + */ +#define L2_BUCKET_LOG2 4 +#define L2_BUCKET_SIZE (1 << L2_BUCKET_LOG2) + +/* + * Given the above "L2-descriptors-per-l2_dtable" constant, the number + * of l2_dtable structures required to track all possible page descriptors + * mappable by an L1 translation table is given by the following constants: + */ +#define L2_LOG2 ((32 - L1_S_SHIFT) - L2_BUCKET_LOG2) +#define L2_SIZE (1 << L2_LOG2) + +#ifndef _LOCORE + +struct l1_ttable; +struct l2_dtable; + +/* + * Track cache/tlb occupancy using the following structure + */ +union pmap_cache_state { + struct { + union { + u_int8_t csu_cache_b[2]; + u_int16_t csu_cache; + } cs_cache_u; + + union { + u_int8_t csu_tlb_b[2]; + u_int16_t csu_tlb; + } cs_tlb_u; + } cs_s; + u_int32_t cs_all; +}; +#define cs_cache_id cs_s.cs_cache_u.csu_cache_b[0] +#define cs_cache_d cs_s.cs_cache_u.csu_cache_b[1] +#define cs_cache cs_s.cs_cache_u.csu_cache +#define cs_tlb_id cs_s.cs_tlb_u.csu_tlb_b[0] +#define cs_tlb_d cs_s.cs_tlb_u.csu_tlb_b[1] +#define cs_tlb cs_s.cs_tlb_u.csu_tlb + +/* + * Assigned to cs_all to force cacheops to work for a particular pmap + */ +#define PMAP_CACHE_STATE_ALL 0xffffffffu + +/* + * The pmap structure itself + */ +struct pmap { + u_int8_t pm_domain; + int pm_remove_all; + struct l1_ttable *pm_l1; + union pmap_cache_state pm_cstate; + u_int pm_refs; + struct l2_dtable *pm_l2[L2_SIZE]; + struct pmap_statistics pm_stats; +}; + +typedef struct pmap *pmap_t; + +/* + * MD flags that we use for pmap_enter (in the pa): + */ +#define PMAP_PA_MASK ~((paddr_t)PAGE_MASK) /* to remove the flags */ +#define PMAP_NOCACHE 0x1 /* non-cacheable memory. */ +#define PMAP_DEVICE 0x2 /* device memory. */ + +/* + * Physical / virtual address structure. In a number of places (particularly + * during bootstrapping) we need to keep track of the physical and virtual + * addresses of various pages + */ +typedef struct pv_addr { + SLIST_ENTRY(pv_addr) pv_list; + paddr_t pv_pa; + vaddr_t pv_va; +} pv_addr_t; + +/* + * Determine various modes for PTEs (user vs. kernel, cacheable + * vs. non-cacheable). + */ +#define PTE_KERNEL 0 +#define PTE_USER 1 +#define PTE_NOCACHE 0 +#define PTE_CACHE 1 +#define PTE_PAGETABLE 2 + +/* + * Flags that indicate attributes of pages or mappings of pages. + * + * The PVF_MOD and PVF_REF flags are stored in the mdpage for each + * page. PVF_WIRED and PVF_WRITE are kept in individual pv_entry's + * for each page. They live in the same "namespace" so that we can + * clear multiple attributes at a time. + */ +#define PVF_MOD 0x01 /* page is modified */ +#define PVF_REF 0x02 /* page is referenced */ +#define PVF_WIRED 0x04 /* mapping is wired */ +#define PVF_WRITE 0x08 /* mapping is writable */ +#define PVF_EXEC 0x10 /* mapping is executable */ + +/* + * Commonly referenced structures + */ +extern struct pmap kernel_pmap_store; + +/* + * Macros that we need to export + */ +#define pmap_kernel() (&kernel_pmap_store) +#define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count) +#define pmap_wired_count(pmap) ((pmap)->pm_stats.wired_count) + +#define pmap_is_modified(pg) \ + (((pg)->mdpage.pvh_attrs & PVF_MOD) != 0) +#define pmap_is_referenced(pg) \ + (((pg)->mdpage.pvh_attrs & PVF_REF) != 0) + +#define pmap_deactivate(p) do { /* nothing */ } while (0) + +#define pmap_init_percpu() do { /* nothing */ } while (0) +#define pmap_unuse_final(p) do { /* nothing */ } while (0) +#define pmap_remove_holes(vm) do { /* nothing */ } while (0) + +#define PMAP_CHECK_COPYIN 1 + +#define PMAP_GROWKERNEL /* turn on pmap_growkernel interface */ + +/* Functions we use internally. */ +void pmap_bootstrap(pd_entry_t *, vaddr_t, vaddr_t); + +int pmap_get_pde_pte(pmap_t, vaddr_t, pd_entry_t **, pt_entry_t **); +int pmap_get_pde(pmap_t, vaddr_t, pd_entry_t **); +void pmap_set_pcb_pagedir(pmap_t, struct pcb *); + +void pmap_postinit(void); + +void vector_page_setprot(int); + +/* XXX */ +void pmap_kenter_cache(vaddr_t va, paddr_t pa, vm_prot_t prot, int cacheable); + +/* Bootstrapping routines. */ +void pmap_map_section(vaddr_t, vaddr_t, paddr_t, int, int); +void pmap_map_entry(vaddr_t, vaddr_t, paddr_t, int, int); +vsize_t pmap_map_chunk(vaddr_t, vaddr_t, paddr_t, vsize_t, int, int); +void pmap_link_l2pt(vaddr_t, vaddr_t, pv_addr_t *); + +/* + * The current top of kernel VM + */ +extern vaddr_t pmap_curmaxkvaddr; + +/* + * Useful macros and constants + */ + +/* Virtual address to page table entry */ +static __inline pt_entry_t * +vtopte(vaddr_t va) +{ + pd_entry_t *pdep; + pt_entry_t *ptep; + + if (pmap_get_pde_pte(pmap_kernel(), va, &pdep, &ptep) == FALSE) + return (NULL); + return (ptep); +} + +/* + * Page tables are always mapped write-through. + * Thus, on some platforms we can run fast and loose and avoid syncing PTEs + * on every change. + * + * Unfortunately, not all CPUs have a write-through cache mode. So we + * define PMAP_NEEDS_PTE_SYNC for C code to conditionally do PTE syncs. + */ +extern int pmap_needs_pte_sync; + +#define PMAP_NEEDS_PTE_SYNC pmap_needs_pte_sync + +#define PTE_SYNC(pte) \ +do { \ + cpu_drain_writebuf(); \ + if (PMAP_NEEDS_PTE_SYNC) { \ + paddr_t pa; \ + cpu_dcache_wb_range((vaddr_t)(pte), sizeof(pt_entry_t));\ + if (cpu_sdcache_enabled()) { \ + (void)pmap_extract(pmap_kernel(), (vaddr_t)(pte), &pa); \ + cpu_sdcache_wb_range((vaddr_t)(pte), (paddr_t)(pa), \ + sizeof(pt_entry_t)); \ + }; \ + cpu_drain_writebuf(); \ + } \ +} while (/*CONSTCOND*/0) + +#define PTE_SYNC_RANGE(pte, cnt) \ +do { \ + cpu_drain_writebuf(); \ + if (PMAP_NEEDS_PTE_SYNC) { \ + paddr_t pa; \ + cpu_dcache_wb_range((vaddr_t)(pte), \ + (cnt) << 2); /* * sizeof(pt_entry_t) */ \ + if (cpu_sdcache_enabled()) { \ + (void)pmap_extract(pmap_kernel(), (vaddr_t)(pte), &pa);\ + cpu_sdcache_wb_range((vaddr_t)(pte), (paddr_t)(pa), \ + (cnt) << 2); /* * sizeof(pt_entry_t) */ \ + }; \ + cpu_drain_writebuf(); \ + } \ +} while (/*CONSTCOND*/0) + +#define l1pte_valid(pde) (((pde) & L1_TYPE_MASK) != L1_TYPE_INV) +#define l1pte_section_p(pde) (((pde) & L1_TYPE_MASK) == L1_TYPE_S) +#define l1pte_page_p(pde) (((pde) & L1_TYPE_MASK) == L1_TYPE_C) +#define l1pte_fpage_p(pde) (((pde) & L1_TYPE_MASK) == L1_TYPE_F) + +#define l2pte_index(v) (((v) & L2_ADDR_BITS) >> L2_S_SHIFT) +#define l2pte_valid(pte) (((pte) & L2_TYPE_MASK) != L2_TYPE_INV) +#define l2pte_pa(pte) ((pte) & L2_S_FRAME) + +/* L1 and L2 page table macros */ +#define pmap_pde_v(pde) l1pte_valid(*(pde)) +#define pmap_pde_section(pde) l1pte_section_p(*(pde)) +#define pmap_pde_page(pde) l1pte_page_p(*(pde)) +#define pmap_pde_fpage(pde) l1pte_fpage_p(*(pde)) + +/************************* ARM MMU configuration *****************************/ + +void pmap_pte_init_armv7(void); + +#endif /* !_LOCORE */ + +/*****************************************************************************/ + +/* + * Definitions for MMU domains + */ +#define PMAP_DOMAINS 15 /* 15 'user' domains (0-14) */ +#define PMAP_DOMAIN_KERNEL 15 /* The kernel uses domain #15 */ + +/* + * These macros define the various bit masks in the PTE. + * + * We use these macros since we use different bits on different processor + * models. + */ +#define L1_S_PROT_UR_v7 (L1_S_V7_AP(AP_V7_KRUR)) +#define L1_S_PROT_UW_v7 (L1_S_V7_AP(AP_KRWURW)) +#define L1_S_PROT_KR_v7 (L1_S_V7_AP(AP_V7_KR)) +#define L1_S_PROT_KW_v7 (L1_S_V7_AP(AP_KRW)) +#define L1_S_PROT_MASK_v7 (L1_S_V7_AP(0x07)) + +#define L1_S_CACHE_MASK_v7 (L1_S_B|L1_S_C|L1_S_V7_TEX_MASK) + +#define L1_S_COHERENT_v7 (L1_S_C) + +#define L2_L_PROT_UR_v7 (L2_V7_AP(AP_V7_KRUR)) +#define L2_L_PROT_UW_v7 (L2_V7_AP(AP_KRWURW)) +#define L2_L_PROT_KR_v7 (L2_V7_AP(AP_V7_KR)) +#define L2_L_PROT_KW_v7 (L2_V7_AP(AP_KRW)) +#define L2_L_PROT_MASK_v7 (L2_V7_AP(0x07) | L2_V7_L_XN) + +#define L2_L_CACHE_MASK_v7 (L2_B|L2_C|L2_V7_L_TEX_MASK) + +#define L2_L_COHERENT_v7 (L2_C) + +#define L2_S_PROT_UR_v7 (L2_V7_AP(AP_V7_KRUR)) +#define L2_S_PROT_UW_v7 (L2_V7_AP(AP_KRWURW)) +#define L2_S_PROT_KR_v7 (L2_V7_AP(AP_V7_KR)) +#define L2_S_PROT_KW_v7 (L2_V7_AP(AP_KRW)) +#define L2_S_PROT_MASK_v7 (L2_V7_AP(0x07) | L2_V7_S_XN) + +#define L2_S_CACHE_MASK_v7 (L2_B|L2_C|L2_V7_S_TEX_MASK) + +#define L2_S_COHERENT_v7 (L2_C) + +#define L1_S_PROTO_v7 (L1_TYPE_S) + +#define L1_C_PROTO_v7 (L1_TYPE_C) + +#define L2_L_PROTO (L2_TYPE_L) + +#define L2_S_PROTO_v7 (L2_TYPE_S) + +#define L1_S_PROT_UR L1_S_PROT_UR_v7 +#define L1_S_PROT_UW L1_S_PROT_UW_v7 +#define L1_S_PROT_KR L1_S_PROT_KR_v7 +#define L1_S_PROT_KW L1_S_PROT_KW_v7 +#define L1_S_PROT_MASK L1_S_PROT_MASK_v7 + +#define L2_L_PROT_UR L2_L_PROT_UR_v7 +#define L2_L_PROT_UW L2_L_PROT_UW_v7 +#define L2_L_PROT_KR L2_L_PROT_KR_v7 +#define L2_L_PROT_KW L2_L_PROT_KW_v7 +#define L2_L_PROT_MASK L2_L_PROT_MASK_v7 + +#define L2_S_PROT_UR L2_S_PROT_UR_v7 +#define L2_S_PROT_UW L2_S_PROT_UW_v7 +#define L2_S_PROT_KR L2_S_PROT_KR_v7 +#define L2_S_PROT_KW L2_S_PROT_KW_v7 +#define L2_S_PROT_MASK L2_S_PROT_MASK_v7 + +#define L1_S_CACHE_MASK L1_S_CACHE_MASK_v7 +#define L2_L_CACHE_MASK L2_L_CACHE_MASK_v7 +#define L2_S_CACHE_MASK L2_S_CACHE_MASK_v7 + +#define L1_S_COHERENT L1_S_COHERENT_v7 +#define L2_L_COHERENT L2_L_COHERENT_v7 +#define L2_S_COHERENT L2_S_COHERENT_v7 + +#define L1_S_PROTO L1_S_PROTO_v7 +#define L1_C_PROTO L1_C_PROTO_v7 +#define L2_S_PROTO L2_S_PROTO_v7 + +/* + * These macros return various bits based on kernel/user and protection. + * Note that the compiler will usually fold these at compile time. + */ +#ifndef _LOCORE +static __inline pt_entry_t +L1_S_PROT(int ku, vm_prot_t pr) +{ + pt_entry_t pte; + + if (ku == PTE_USER) + pte = (pr & PROT_WRITE) ? L1_S_PROT_UW : L1_S_PROT_UR; + else + pte = (pr & PROT_WRITE) ? L1_S_PROT_KW : L1_S_PROT_KR; + + if ((pr & PROT_EXEC) == 0) + pte |= L1_S_V7_XN; + + return pte; +} +static __inline pt_entry_t +L2_L_PROT(int ku, vm_prot_t pr) +{ + pt_entry_t pte; + + if (ku == PTE_USER) + pte = (pr & PROT_WRITE) ? L2_L_PROT_UW : L2_L_PROT_UR; + else + pte = (pr & PROT_WRITE) ? L2_L_PROT_KW : L2_L_PROT_KR; + + if ((pr & PROT_EXEC) == 0) + pte |= L2_V7_L_XN; + + return pte; +} +static __inline pt_entry_t +L2_S_PROT(int ku, vm_prot_t pr) +{ + pt_entry_t pte; + + if (ku == PTE_USER) + pte = (pr & PROT_WRITE) ? L2_S_PROT_UW : L2_S_PROT_UR; + else + pte = (pr & PROT_WRITE) ? L2_S_PROT_KW : L2_S_PROT_KR; + + if ((pr & PROT_EXEC) == 0) + pte |= L2_V7_S_XN; + + return pte; +} + +static __inline int +l2pte_is_writeable(pt_entry_t pte, struct pmap *pm) +{ + return (pte & L2_V7_AP(0x4)) == 0; +} +#endif + +/* + * Macros to test if a mapping is mappable with an L1 Section mapping + * or an L2 Large Page mapping. + */ +#define L1_S_MAPPABLE_P(va, pa, size) \ + ((((va) | (pa)) & L1_S_OFFSET) == 0 && (size) >= L1_S_SIZE) + +#define L2_L_MAPPABLE_P(va, pa, size) \ + ((((va) | (pa)) & L2_L_OFFSET) == 0 && (size) >= L2_L_SIZE) + +#endif /* _KERNEL */ + +#ifndef _LOCORE +/* + * pmap-specific data store in the vm_page structure. + */ +struct vm_page_md { + struct pv_entry *pvh_list; /* pv_entry list */ + int pvh_attrs; /* page attributes */ +}; + +#define VM_MDPAGE_INIT(pg) \ +do { \ + (pg)->mdpage.pvh_list = NULL; \ + (pg)->mdpage.pvh_attrs = 0; \ +} while (/*CONSTCOND*/0) +#endif /* _LOCORE */ + +#endif /* _ARM_PMAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/proc.h b/lib/libc/include/arm-openbsd-eabi/arm/proc.h new file mode 100644 index 0000000000..ee878612c5 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/proc.h @@ -0,0 +1,50 @@ +/* $OpenBSD: proc.h,v 1.5 2017/04/13 03:52:25 guenther Exp $ */ +/* $NetBSD: proc.h,v 1.5 2003/03/01 04:36:39 thorpej Exp $ */ + +/* + * Copyright (c) 1994 Mark Brinicombe. + * 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 the RiscBSD team. + * 4. The name "RiscBSD" nor the name of the author may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY RISCBSD ``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 RISCBSD 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 _ARM_PROC_H_ +#define _ARM_PROC_H_ + +/* + * Machine-dependent part of the proc structure for arm. + */ + +struct trapframe; + +struct mdproc { + int pmc_enabled; /* bitfield of enabled counters */ + void *pmc_state; /* port-specific pmc state */ +}; + +#endif /* _ARM_PROC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/profile.h b/lib/libc/include/arm-openbsd-eabi/arm/profile.h new file mode 100644 index 0000000000..95f5300940 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/profile.h @@ -0,0 +1,91 @@ +/* $OpenBSD: profile.h,v 1.5 2016/09/21 11:33:05 kettenis Exp $ */ +/* $NetBSD: profile.h,v 1.5 2002/03/24 15:49:40 bjh21 Exp $ */ + +/* + * Copyright (c) 2001 Ben Harris + * Copyright (c) 1995-1996 Mark Brinicombe + * + * 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 Mark Brinicombe. + * 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. + */ + +#define _MCOUNT_DECL void _mcount + +/* + * Cannot implement mcount in C as GCC will trash the ip register when it + * pushes a trapframe. Pity we cannot insert assembly before the function + * prologue. + */ + +#define MCOUNT_ASM_NAME "__mcount" +#ifdef __PIC__ +#define PLTSYM "(PLT)" +#endif + +#ifndef PLTSYM +#define PLTSYM +#endif + +#define MCOUNT \ + __asm__(".text"); \ + __asm__(".align 2"); \ + __asm__(".type " MCOUNT_ASM_NAME ",%function"); \ + __asm__(".global " MCOUNT_ASM_NAME); \ + __asm__(MCOUNT_ASM_NAME ":"); \ + /* \ + * Preserve registers that are trashed during mcount \ + */ \ + __asm__("stmfd sp!, {r0-r3, ip, lr}"); \ + /* \ + * find the return address for mcount, \ + * and the return address for mcount's caller. \ + * \ + * frompcindex = pc pushed by call into self. \ + */ \ + __asm__("mov r0, ip"); \ + /* \ + * selfpc = pc pushed by mcount call \ + */ \ + __asm__("mov r1, lr"); \ + /* \ + * Call the real mcount code \ + */ \ + __asm__("bl " __STRING(_mcount) PLTSYM); \ + /* \ + * Restore registers that were trashed during mcount \ + */ \ + __asm__("ldmfd sp!, {r0-r3, lr, pc}"); + +#ifdef _KERNEL +#include +/* + * splhigh() and splx() are heavyweight, and call mcount(). Therefore + * we disabled interrupts (IRQ, but not FIQ) directly on the CPU. + * + * We're lucky that the CPSR and 's' both happen to be 'int's. + */ +#define MCOUNT_ENTER s = __set_cpsr_c(0x0080, 0x0080); /* kill IRQ */ +#define MCOUNT_EXIT __set_cpsr_c(0xffffffff, s); /* restore old value */ +#endif /* _KERNEL */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/pte.h b/lib/libc/include/arm-openbsd-eabi/arm/pte.h new file mode 100644 index 0000000000..cd9fd67ad6 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/pte.h @@ -0,0 +1,232 @@ +/* $OpenBSD: pte.h,v 1.10 2021/03/11 11:16:55 jsg Exp $ */ +/* $NetBSD: pte.h,v 1.6 2003/04/18 11:08:28 scw Exp $ */ + +/* + * Copyright (c) 2001, 2002 Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Jason R. Thorpe for Wasabi Systems, Inc. + * + * 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 for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC + * 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 _ARM_PTE_H_ +#define _ARM_PTE_H_ + +/* + * The ARM MMU architecture was introduced with ARM v3 (previous ARM + * architecture versions used an optional off-CPU memory controller + * to perform address translation). + * + * The ARM MMU consists of a TLB and translation table walking logic. + * There is typically one TLB per memory interface (or, put another + * way, one TLB per software-visible cache). + * + * The ARM MMU is capable of mapping memory in the following chunks: + * + * 1M Sections (L1 table) + * + * 64K Large Pages (L2 table) + * + * 4K Small Pages (L2 table) + * + * 1K Tiny Pages (L2 table) + * + * There are two types of L2 tables: Coarse Tables and Fine Tables. + * Coarse Tables can map Large and Small Pages. Fine Tables can + * map Tiny Pages. + * + * Coarse Tables can define 4 Subpages within Large and Small pages. + * Subpages define different permissions for each Subpage within + * a Page. + * + * Coarse Tables are 1K in length. Fine tables are 4K in length. + * + * The Translation Table Base register holds the pointer to the + * L1 Table. The L1 Table is a 16K contiguous chunk of memory + * aligned to a 16K boundary. Each entry in the L1 Table maps + * 1M of virtual address space, either via a Section mapping or + * via an L2 Table. + * + * In addition, the Fast Context Switching Extension (FCSE) is available + * on some ARM v4 and ARM v5 processors. FCSE is a way of eliminating + * TLB/cache flushes on context switch by use of a smaller address space + * and a "process ID" that modifies the virtual address before being + * presented to the translation logic. + */ + +#ifndef _LOCORE +typedef uint32_t pd_entry_t; /* L1 table entry */ +typedef uint32_t pt_entry_t; /* L2 table entry */ +#endif /* _LOCORE */ + +#define L1_S_SIZE 0x00100000 /* 1M */ +#define L1_S_OFFSET (L1_S_SIZE - 1) +#define L1_S_FRAME (~L1_S_OFFSET) +#define L1_S_SHIFT 20 + +#define L2_L_SIZE 0x00010000 /* 64K */ +#define L2_L_OFFSET (L2_L_SIZE - 1) +#define L2_L_FRAME (~L2_L_OFFSET) +#define L2_L_SHIFT 16 + +#define L2_S_SIZE 0x00001000 /* 4K */ +#define L2_S_OFFSET (L2_S_SIZE - 1) +#define L2_S_FRAME (~L2_S_OFFSET) +#define L2_S_SHIFT 12 + +#define L2_T_SIZE 0x00000400 /* 1K */ +#define L2_T_OFFSET (L2_T_SIZE - 1) +#define L2_T_FRAME (~L2_T_OFFSET) +#define L2_T_SHIFT 10 + +/* + * The NetBSD VM implementation only works on whole pages (4K), + * whereas the ARM MMU's Coarse tables are sized in terms of 1K + * (16K L1 table, 1K L2 table). + * + * So, we allocate L2 tables 4 at a time, thus yielding a 4K L2 + * table. + */ +#define L1_ADDR_BITS 0xfff00000 /* L1 PTE address bits */ +#define L2_ADDR_BITS 0x000ff000 /* L2 PTE address bits */ + +#define L1_TABLE_SIZE 0x4000 /* 16K */ +#define L2_TABLE_SIZE 0x1000 /* 4K */ +/* + * The new pmap deals with the 1KB coarse L2 tables by + * allocating them from a pool. Until every port has been converted, + * keep the old L2_TABLE_SIZE define lying around. Converted ports + * should use L2_TABLE_SIZE_REAL until then. + */ +#define L2_TABLE_SIZE_REAL 0x400 /* 1K */ + +/* + * ARM L1 Descriptors + */ + +#define L1_TYPE_INV 0x00 /* Invalid (fault) */ +#define L1_TYPE_C 0x01 /* Coarse L2 */ +#define L1_TYPE_S 0x02 /* Section or Supersection */ +#define L1_TYPE_F 0x03 /* Fine L2 (pre-V7) */ +#define L1_TYPE_MASK 0x03 /* mask of type bits */ + +/* L1 Section Descriptor */ +#define L1_S_B 0x00000004 /* bufferable Section */ +#define L1_S_C 0x00000008 /* cacheable Section */ +#define L1_S_IMP 0x00000010 /* implementation defined */ +#define L1_S_DOM(x) ((x) << 5) /* domain */ +#define L1_S_DOM_MASK L1_S_DOM(0xf) +#define L1_S_AP(x) ((x) << 10) /* access permissions */ +#define L1_S_ADDR_MASK 0xfff00000 /* phys address of section */ + +#define L1_S_V7_TEX(x) (((x) & 0x7) << 12) /* Type Extension */ +#define L1_S_V7_TEX_MASK (0x7 << 12) /* Type Extension */ +#define L1_S_V7_NS 0x00080000 /* Non-secure */ +#define L1_S_V7_SS 0x00040000 /* Supersection */ +#define L1_S_V7_nG 0x00020000 /* not Global */ +#define L1_S_V7_S 0x00010000 /* Shareable */ +#define L1_S_V7_AP(x) ((((x) & 0x4) << 13) | (((x) & 0x2) << 10)) /* AP */ +#define L1_S_V7_AF 0x00000400 /* Access Flag */ +#define L1_S_V7_IMP 0x00000200 /* implementation defined */ +#define L1_S_V7_XN 0x00000010 /* eXecute Never */ +#define L1_S_V7_PXN 0x00000001 /* Privileged eXecute Never */ + +/* L1 Coarse Descriptor */ +#define L1_C_IMP0 0x00000004 /* implementation defined */ +#define L1_C_IMP1 0x00000008 /* implementation defined */ +#define L1_C_IMP2 0x00000010 /* implementation defined */ +#define L1_C_DOM(x) ((x) << 5) /* domain */ +#define L1_C_DOM_MASK L1_C_DOM(0xf) +#define L1_C_ADDR_MASK 0xfffffc00 /* phys address of L2 Table */ + +#define L1_C_V7_IMP 0x00000200 /* implementation defined */ +#define L1_C_V7_NS 0x00000008 /* Non-secure */ +#define L1_C_V7_PXN 0x00000004 /* Privileged eXecute Never */ + +/* L1 Fine Descriptor */ +#define L1_F_IMP0 0x00000004 /* implementation defined */ +#define L1_F_IMP1 0x00000008 /* implementation defined */ +#define L1_F_IMP2 0x00000010 /* implementation defined */ +#define L1_F_DOM(x) ((x) << 5) /* domain */ +#define L1_F_DOM_MASK L1_F_DOM(0xf) +#define L1_F_ADDR_MASK 0xfffff000 /* phys address of L2 Table */ + +/* + * ARM L2 Descriptors + */ + +#define L2_TYPE_INV 0x00 /* Invalid (fault) */ +#define L2_TYPE_L 0x01 /* Large Page */ +#define L2_TYPE_S 0x02 /* Small Page */ +#define L2_TYPE_T 0x03 /* Tiny Page (pre-V7) */ +#define L2_TYPE_MASK 0x03 /* mask of type bits */ + +#define L2_B 0x00000004 /* Bufferable page */ +#define L2_C 0x00000008 /* Cacheable page */ +#define L2_AP0(x) ((x) << 4) /* access permissions (sp 0) */ +#define L2_AP1(x) ((x) << 6) /* access permissions (sp 1) */ +#define L2_AP2(x) ((x) << 8) /* access permissions (sp 2) */ +#define L2_AP3(x) ((x) << 10) /* access permissions (sp 3) */ +#define L2_AP(x) (L2_AP0(x) | L2_AP1(x) | L2_AP2(x) | L2_AP3(x)) + +#define L2_V7_L_TEX(x) (((x) & 0x7) << 12) /* Type Extension */ +#define L2_V7_L_TEX_MASK (0x7 << 12) /* Type Extension */ +#define L2_V7_L_XN 0x00008000 /* eXecute Never */ +#define L2_V7_S_TEX(x) (((x) & 0x7) << 6) /* Type Extension */ +#define L2_V7_S_TEX_MASK (0x7 << 6) /* Type Extension */ +#define L2_V7_S_XN 0x00000001 /* eXecute Never */ + +#define L2_V7_AP(x) ((((x) & 0x4) << 7) | (((x) & 0x2) << 4)) /* AP */ +#define L2_V7_AF 0x00000010 /* Access Flag */ +#define L2_V7_S 0x00000400 /* Shareable */ +#define L2_V7_nG 0x00000800 /* not Global */ + +/* + * Short-hand for common AP_* constants. + * + * Note: These values assume the S (System) bit is set and + * the R (ROM) bit is clear in CP15 register 1. + */ +#define AP_KR 0x00 /* kernel read */ +#define AP_V7_KR 0x05 +#define AP_KRW 0x01 /* kernel read/write */ +#define AP_KRWUR 0x02 /* kernel read/write usr read */ +#define AP_V7_KRUR 0x07 /* kernel read usr read */ +#define AP_KRWURW 0x03 /* kernel read/write usr read/write */ + +/* + * Domain Types for the Domain Access Control Register. + */ +#define DOMAIN_FAULT 0x00 /* no access */ +#define DOMAIN_CLIENT 0x01 /* client */ +#define DOMAIN_RESERVED 0x02 /* reserved */ +#define DOMAIN_MANAGER 0x03 /* manager */ + +#endif /* _ARM_PTE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/ptrace.h b/lib/libc/include/arm-openbsd-eabi/arm/ptrace.h new file mode 100644 index 0000000000..97bdac92c4 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/ptrace.h @@ -0,0 +1,44 @@ +/* $OpenBSD: ptrace.h,v 1.1 2004/02/01 05:09:49 drahn Exp $ */ +/* $NetBSD: ptrace.h,v 1.2 2001/10/19 00:18:20 bjh21 Exp $ */ + +/* + * Copyright (c) 1995 Frank Lancaster + * Copyright (c) 1995 Tools GmbH + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by 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 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. + */ + +/* + * arm-dependent ptrace definitions + */ +#ifndef _KERNEL +#define PT_STEP (PT_FIRSTMACH + 0) /* Not implemented */ +#endif +#define PT_GETREGS (PT_FIRSTMACH + 1) +#define PT_SETREGS (PT_FIRSTMACH + 2) +#define PT_GETFPREGS (PT_FIRSTMACH + 3) +#define PT_SETFPREGS (PT_FIRSTMACH + 4) \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/reg.h b/lib/libc/include/arm-openbsd-eabi/arm/reg.h new file mode 100644 index 0000000000..b456a86517 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/reg.h @@ -0,0 +1,53 @@ +/* $OpenBSD: reg.h,v 1.3 2018/01/23 12:38:14 kettenis Exp $ */ +/* $NetBSD: reg.h,v 1.1 2001/02/11 14:51:55 bjh21 Exp $ */ + +/* + * Copyright (C) 1994, 1995 Frank Lancaster + * Copyright (C) 1994, 1995 TooLs GmbH. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by TooLs GmbH. + * 4. The name of TooLs GmbH may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * @(#)reg.h 5.5 (Berkeley) 1/18/91 + */ + +#ifndef _ARM_REG_H_ +#define _ARM_REG_H_ + +struct reg { + unsigned int r[13]; + unsigned int r_sp; + unsigned int r_lr; + unsigned int r_pc; + unsigned int r_cpsr; +}; + +struct fpreg { + uint64_t fp_reg[32]; + uint32_t fp_scr; +}; + +#endif /* !_ARM_REG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/reloc.h b/lib/libc/include/arm-openbsd-eabi/arm/reloc.h new file mode 100644 index 0000000000..e7415bd50d --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/reloc.h @@ -0,0 +1,53 @@ +/* $OpenBSD: reloc.h,v 1.2 2006/05/26 20:22:04 miod Exp $ */ +/* Processor specific relocation types */ + +#define R_ARM_NONE 0 +#define R_ARM_PC24 1 +#define R_ARM_ABS32 2 +#define R_ARM_REL32 3 +#define R_ARM_PC13 4 +#define R_ARM_ABS16 5 +#define R_ARM_ABS12 6 +#define R_ARM_THM_ABS5 7 +#define R_ARM_ABS8 8 +#define R_ARM_SBREL32 9 +#define R_ARM_THM_PC22 10 +#define R_ARM_THM_PC8 11 +#define R_ARM_AMP_VCALL9 12 +#define R_ARM_SWI24 13 +#define R_ARM_THM_SWI8 14 +#define R_ARM_XPC25 15 +#define R_ARM_THM_XPC22 16 + +/* 17-31 are reserved for ARM Linux. */ +#define R_ARM_COPY 20 +#define R_ARM_GLOB_DAT 21 +#define R_ARM_JUMP_SLOT 22 +#define R_ARM_RELATIVE 23 +#define R_ARM_GOTOFF 24 +#define R_ARM_GOTPC 25 +#define R_ARM_GOT32 26 +#define R_ARM_PLT32 27 + +#define R_ARM_ALU_PCREL_7_0 32 +#define R_ARM_ALU_PCREL_15_8 33 +#define R_ARM_ALU_PCREL_23_15 34 +#define R_ARM_ALU_SBREL_11_0 35 +#define R_ARM_ALU_SBREL_19_12 36 +#define R_ARM_ALU_SBREL_27_20 37 + +/* 96-111 are reserved to G++. */ +#define R_ARM_GNU_VTENTRY 100 +#define R_ARM_GNU_VTINHERIT 101 +#define R_ARM_THM_PC11 102 +#define R_ARM_THM_PC9 103 + +/* 112-127 are reserved for private experiments. */ + +#define R_ARM_RXPC25 249 +#define R_ARM_RSBREL32 250 +#define R_ARM_THM_RPC22 251 +#define R_ARM_RREL32 252 +#define R_ARM_RABS32 253 +#define R_ARM_RPC24 254 +#define R_ARM_RBASE 255 \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/setjmp.h b/lib/libc/include/arm-openbsd-eabi/arm/setjmp.h new file mode 100644 index 0000000000..16c9118498 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/setjmp.h @@ -0,0 +1,67 @@ +/* $OpenBSD: setjmp.h,v 1.6 2023/04/11 00:45:07 jsg Exp $ */ +/* $NetBSD: setjmp.h,v 1.2 2001/08/25 14:45:59 bjh21 Exp $ */ + +/* + * machine/setjmp.h: machine dependent setjmp-related information. + */ + +#define _JBLEN 64 /* size, in longs, of a jmp_buf */ + +/* + * Description of the setjmp buffer + * + * word 0 magic number (dependant on creator) + * 1 fpscr fpscr + * 2 - 17 d8 - d15 vfp registers + * 18 r13 register 13 (sp) XOR cookie0 + * 19 r14 register 14 (lr) XOR cookie1 + * 20 r4 register 4 + * 21 r5 register 5 + * 22 r6 register 6 + * 23 r7 register 7 + * 24 r8 register 8 + * 25 r9 register 9 + * 26 r10 register 10 (sl) + * 27 r11 register 11 (fp) + * 28 unused unused + * 29 signal mask (dependant on magic) + * 30 (con't) + * 31 (con't) + * 32 (con't) + * + * The magic number identifies the jmp_buf and + * how the buffer was created as well as providing + * a sanity check. + * + * A side note I should mention - please do not tamper + * with the floating point fields. While they are + * always saved and restored at the moment this cannot + * be guaranteed especially if the compiler happens + * to be generating soft-float code so no fp + * registers will be used. + * + * Whilst this can be seen an encouraging people to + * use the setjmp buffer in this way I think that it + * is for the best then if changes occur compiles will + * break rather than just having new builds falling over + * mysteriously. + */ + +#define _JB_MAGIC__SETJMP 0x4278f500 +#define _JB_MAGIC_SETJMP 0x4278f501 + +/* Valid for all jmp_buf's */ + +#define _JB_MAGIC 0 +#define _JB_REG_R4 20 +#define _JB_REG_R5 21 +#define _JB_REG_R6 22 +#define _JB_REG_R7 23 +#define _JB_REG_R8 24 +#define _JB_REG_R9 25 +#define _JB_REG_R10 26 +#define _JB_REG_R11 27 + +/* Only valid with the _JB_MAGIC_SETJMP magic */ + +#define _JB_SIGMASK 29 \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/signal.h b/lib/libc/include/arm-openbsd-eabi/arm/signal.h new file mode 100644 index 0000000000..2b226ebd70 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/signal.h @@ -0,0 +1,93 @@ +/* $OpenBSD: signal.h,v 1.10 2018/06/23 22:15:14 kettenis Exp $ */ +/* $NetBSD: signal.h,v 1.5 2003/10/18 17:57:21 briggs Exp $ */ + +/* + * Copyright (c) 1994-1996 Mark Brinicombe. + * Copyright (c) 1994 Brini. + * All rights reserved. + * + * This code is derived from software written for Brini by Mark Brinicombe + * + * 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 Brini. + * 4. The name of the company nor the name of the author may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY BRINI ``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 BRINI 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. + * + * RiscBSD kernel project + * + * signal.h + * + * Architecture dependant signal types and structures + * + * Created : 30/09/94 + */ + +#ifndef _ARM_SIGNAL_H_ +#define _ARM_SIGNAL_H_ + +#ifndef _LOCORE +#include + +typedef int sig_atomic_t; + +#if __BSD_VISIBLE || __XPG_VISIBLE >= 420 +/* + * Information pushed on stack when a signal is delivered. + * This is used by the kernel to restore state following + * execution of the signal handler. It is also made available + * to the handler to allow it to restore state properly if + * a non-standard exit is performed. + */ +struct sigcontext { + long sc_cookie; + int sc_mask; /* signal mask to restore */ + + unsigned int sc_spsr; + unsigned int sc_r0; + unsigned int sc_r1; + unsigned int sc_r2; + unsigned int sc_r3; + unsigned int sc_r4; + unsigned int sc_r5; + unsigned int sc_r6; + unsigned int sc_r7; + unsigned int sc_r8; + unsigned int sc_r9; + unsigned int sc_r10; + unsigned int sc_r11; + unsigned int sc_r12; + unsigned int sc_usr_sp; + unsigned int sc_usr_lr; + unsigned int sc_svc_lr; + unsigned int sc_pc; + + unsigned int sc_fpused; + unsigned int sc_fpscr; + unsigned long long sc_fpreg[32]; +}; +#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */ +#endif /* !_LOCORE */ + +#endif /* !_ARM_SIGNAL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/simplebusvar.h b/lib/libc/include/arm-openbsd-eabi/arm/simplebusvar.h new file mode 100644 index 0000000000..4ed0e3f60a --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/simplebusvar.h @@ -0,0 +1,37 @@ +/* $OpenBSD: simplebusvar.h,v 1.1 2023/09/22 01:10:43 jsg Exp $ */ +/* + * Copyright (c) 2016 Patrick Wildt + * + * 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. + */ + +struct simplebus_softc { + struct device sc_dev; + int sc_node; + bus_space_tag_t sc_iot; + bus_dma_tag_t sc_dmat; + int sc_acells; + int sc_scells; + int sc_pacells; + int sc_pscells; + struct bus_space sc_bus; + struct arm32_bus_dma_tag sc_dma; + int *sc_ranges; + int sc_rangeslen; + int *sc_dmaranges; + int sc_dmarangeslen; + int sc_early; + int sc_early_nodes[64]; +}; + +extern void simplebus_attach(struct device *, struct device *, void *); \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/spinlock.h b/lib/libc/include/arm-openbsd-eabi/arm/spinlock.h new file mode 100644 index 0000000000..d8dbd0dc1c --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/spinlock.h @@ -0,0 +1,10 @@ +/* $OpenBSD: spinlock.h,v 1.3 2017/09/05 02:40:54 guenther Exp $ */ + +#ifndef _ARM_SPINLOCK_H_ +#define _ARM_SPINLOCK_H_ + +#define _ATOMIC_LOCK_UNLOCKED (0) +#define _ATOMIC_LOCK_LOCKED (1) +typedef int _atomic_lock_t; + +#endif \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/sysarch.h b/lib/libc/include/arm-openbsd-eabi/arm/sysarch.h new file mode 100644 index 0000000000..1f1f41c04d --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/sysarch.h @@ -0,0 +1,62 @@ +/* $OpenBSD: sysarch.h,v 1.3 2012/12/05 23:20:11 deraadt Exp $ */ +/* $NetBSD: sysarch.h,v 1.4 2002/03/30 06:23:39 thorpej Exp $ */ + +/* + * Copyright (c) 1996-1997 Mark Brinicombe. + * 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 Mark Brinicombe. + * 4. The name of the company nor the name of the author may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY 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 AUTHOR 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 _ARM_SYSARCH_H_ +#define _ARM_SYSARCH_H_ + +/* + * Architecture specific syscalls (arm) + */ + +#define ARM_SYNC_ICACHE 0 +#define ARM_DRAIN_WRITEBUF 1 + +struct arm_sync_icache_args { + u_int32_t addr; /* Virtual start address */ + size_t len; /* Region size */ +}; + +#ifndef _KERNEL + +#include + +__BEGIN_DECLS +int arm_sync_icache (u_int addr, int len); +int arm_drain_writebuf (void); +int sysarch (int, void *); +__END_DECLS +#endif + +#endif /* !_ARM_SYSARCH_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/sysreg.h b/lib/libc/include/arm-openbsd-eabi/arm/sysreg.h new file mode 100644 index 0000000000..5133ae186b --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/sysreg.h @@ -0,0 +1,272 @@ +/* $OpenBSD: sysreg.h,v 1.1 2016/04/25 04:25:36 jsg Exp $ */ +/*- + * Copyright 2014 Svatopluk Kraus + * Copyright 2014 Michal Meloun + * 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 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 AUTHOR 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. + * + * $FreeBSD: head/sys/arm/include/sysreg.h 294740 2016-01-25 18:02:28Z zbb $ + */ + +/* + * Macros to make working with the System Control Registers simpler. + * + * Note that when register r0 is hard-coded in these definitions it means the + * cp15 operation neither reads nor writes the register, and r0 is used only + * because some syntatically-valid register name has to appear at that point to + * keep the asm parser happy. + */ + +#ifndef MACHINE_SYSREG_H +#define MACHINE_SYSREG_H + +/* + * CP14 registers + */ + +#define CP14_DBGDIDR(rr) p14, 0, rr, c0, c0, 0 /* Debug ID Register */ +#define CP14_DBGDSCRext_V6(rr) p14, 0, rr, c0, c1, 0 /* Debug Status and Ctrl Register v6 */ +#define CP14_DBGDSCRext_V7(rr) p14, 0, rr, c0, c2, 2 /* Debug Status and Ctrl Register v7 */ +#define CP14_DBGVCR(rr) p14, 0, rr, c0, c7, 0 /* Vector Catch Register */ +#define CP14_DBGOSLAR(rr) p14, 0, rr, c1, c0, 4 /* OS Lock Access Register */ +#define CP14_DBGOSLSR(rr) p14, 0, rr, c1, c1, 4 /* OS Lock Status Register */ +#define CP14_DBGOSDLR(rr) p14, 0, rr, c1, c3, 4 /* OS Double Lock Register */ +#define CP14_DBGPRSR(rr) p14, 0, rr, c1, c5, 4 /* Device Powerdown and Reset Status */ + +#define CP14_DBGDSCRint(rr) CP14_DBGDSCRext_V6(rr) /* Debug Status and Ctrl internal view */ + + +/* + * CP15 C0 registers + */ +#define CP15_MIDR(rr) p15, 0, rr, c0, c0, 0 /* Main ID Register */ +#define CP15_CTR(rr) p15, 0, rr, c0, c0, 1 /* Cache Type Register */ +#define CP15_TCMTR(rr) p15, 0, rr, c0, c0, 2 /* TCM Type Register */ +#define CP15_TLBTR(rr) p15, 0, rr, c0, c0, 3 /* TLB Type Register */ +#define CP15_MPIDR(rr) p15, 0, rr, c0, c0, 5 /* Multiprocessor Affinity Register */ +#define CP15_REVIDR(rr) p15, 0, rr, c0, c0, 6 /* Revision ID Register */ + +#define CP15_ID_PFR0(rr) p15, 0, rr, c0, c1, 0 /* Processor Feature Register 0 */ +#define CP15_ID_PFR1(rr) p15, 0, rr, c0, c1, 1 /* Processor Feature Register 1 */ +#define CP15_ID_DFR0(rr) p15, 0, rr, c0, c1, 2 /* Debug Feature Register 0 */ +#define CP15_ID_AFR0(rr) p15, 0, rr, c0, c1, 3 /* Auxiliary Feature Register 0 */ +#define CP15_ID_MMFR0(rr) p15, 0, rr, c0, c1, 4 /* Memory Model Feature Register 0 */ +#define CP15_ID_MMFR1(rr) p15, 0, rr, c0, c1, 5 /* Memory Model Feature Register 1 */ +#define CP15_ID_MMFR2(rr) p15, 0, rr, c0, c1, 6 /* Memory Model Feature Register 2 */ +#define CP15_ID_MMFR3(rr) p15, 0, rr, c0, c1, 7 /* Memory Model Feature Register 3 */ + +#define CP15_ID_ISAR0(rr) p15, 0, rr, c0, c2, 0 /* Instruction Set Attribute Register 0 */ +#define CP15_ID_ISAR1(rr) p15, 0, rr, c0, c2, 1 /* Instruction Set Attribute Register 1 */ +#define CP15_ID_ISAR2(rr) p15, 0, rr, c0, c2, 2 /* Instruction Set Attribute Register 2 */ +#define CP15_ID_ISAR3(rr) p15, 0, rr, c0, c2, 3 /* Instruction Set Attribute Register 3 */ +#define CP15_ID_ISAR4(rr) p15, 0, rr, c0, c2, 4 /* Instruction Set Attribute Register 4 */ +#define CP15_ID_ISAR5(rr) p15, 0, rr, c0, c2, 5 /* Instruction Set Attribute Register 5 */ + +#define CP15_CCSIDR(rr) p15, 1, rr, c0, c0, 0 /* Cache Size ID Registers */ +#define CP15_CLIDR(rr) p15, 1, rr, c0, c0, 1 /* Cache Level ID Register */ +#define CP15_AIDR(rr) p15, 1, rr, c0, c0, 7 /* Auxiliary ID Register */ + +#define CP15_CSSELR(rr) p15, 2, rr, c0, c0, 0 /* Cache Size Selection Register */ + +/* + * CP15 C1 registers + */ +#define CP15_SCTLR(rr) p15, 0, rr, c1, c0, 0 /* System Control Register */ +#define CP15_ACTLR(rr) p15, 0, rr, c1, c0, 1 /* IMPLEMENTATION DEFINED Auxiliary Control Register */ +#define CP15_CPACR(rr) p15, 0, rr, c1, c0, 2 /* Coprocessor Access Control Register */ + +#define CP15_SCR(rr) p15, 0, rr, c1, c1, 0 /* Secure Configuration Register */ +#define CP15_SDER(rr) p15, 0, rr, c1, c1, 1 /* Secure Debug Enable Register */ +#define CP15_NSACR(rr) p15, 0, rr, c1, c1, 2 /* Non-Secure Access Control Register */ + +/* + * CP15 C2 registers + */ +#define CP15_TTBR0(rr) p15, 0, rr, c2, c0, 0 /* Translation Table Base Register 0 */ +#define CP15_TTBR1(rr) p15, 0, rr, c2, c0, 1 /* Translation Table Base Register 1 */ +#define CP15_TTBCR(rr) p15, 0, rr, c2, c0, 2 /* Translation Table Base Control Register */ + +/* + * CP15 C3 registers + */ +#define CP15_DACR(rr) p15, 0, rr, c3, c0, 0 /* Domain Access Control Register */ + +/* + * CP15 C5 registers + */ +#define CP15_DFSR(rr) p15, 0, rr, c5, c0, 0 /* Data Fault Status Register */ + +/* From ARMv6: */ +#define CP15_IFSR(rr) p15, 0, rr, c5, c0, 1 /* Instruction Fault Status Register */ +/* From ARMv7: */ +#define CP15_ADFSR(rr) p15, 0, rr, c5, c1, 0 /* Auxiliary Data Fault Status Register */ +#define CP15_AIFSR(rr) p15, 0, rr, c5, c1, 1 /* Auxiliary Instruction Fault Status Register */ + +/* + * CP15 C6 registers + */ +#define CP15_DFAR(rr) p15, 0, rr, c6, c0, 0 /* Data Fault Address Register */ + +/* From ARMv6k: */ +#define CP15_IFAR(rr) p15, 0, rr, c6, c0, 2 /* Instruction Fault Address Register */ + +/* + * CP15 C7 registers + */ +#ifdef MULTIPROCESSOR +/* From ARMv7: */ +#define CP15_ICIALLUIS p15, 0, r0, c7, c1, 0 /* Instruction cache invalidate all PoU, IS */ +#define CP15_BPIALLIS p15, 0, r0, c7, c1, 6 /* Branch predictor invalidate all IS */ +#endif + +#define CP15_PAR(rr) p15, 0, rr, c7, c4, 0 /* Physical Address Register */ + +#define CP15_ICIALLU p15, 0, r0, c7, c5, 0 /* Instruction cache invalidate all PoU */ +#define CP15_ICIMVAU(rr) p15, 0, rr, c7, c5, 1 /* Instruction cache invalidate */ +#define CP15_BPIALL p15, 0, r0, c7, c5, 6 /* Branch predictor invalidate all */ +#define CP15_BPIMVA p15, 0, r0, c7, c5, 7 /* Branch predictor invalidate by MVA */ + +#define CP15_DCIMVAC(rr) p15, 0, rr, c7, c6, 1 /* Data cache invalidate by MVA PoC */ +#define CP15_DCISW(rr) p15, 0, rr, c7, c6, 2 /* Data cache invalidate by set/way */ + +#define CP15_ATS1CPR(rr) p15, 0, rr, c7, c8, 0 /* Stage 1 Current state PL1 read */ +#define CP15_ATS1CPW(rr) p15, 0, rr, c7, c8, 1 /* Stage 1 Current state PL1 write */ +#define CP15_ATS1CUR(rr) p15, 0, rr, c7, c8, 2 /* Stage 1 Current state unprivileged read */ +#define CP15_ATS1CUW(rr) p15, 0, rr, c7, c8, 3 /* Stage 1 Current state unprivileged write */ + +/* From ARMv7: */ +#define CP15_ATS12NSOPR(rr) p15, 0, rr, c7, c8, 4 /* Stages 1 and 2 Non-secure only PL1 read */ +#define CP15_ATS12NSOPW(rr) p15, 0, rr, c7, c8, 5 /* Stages 1 and 2 Non-secure only PL1 write */ +#define CP15_ATS12NSOUR(rr) p15, 0, rr, c7, c8, 6 /* Stages 1 and 2 Non-secure only unprivileged read */ +#define CP15_ATS12NSOUW(rr) p15, 0, rr, c7, c8, 7 /* Stages 1 and 2 Non-secure only unprivileged write */ + +#define CP15_DCCMVAC(rr) p15, 0, rr, c7, c10, 1 /* Data cache clean by MVA PoC */ +#define CP15_DCCSW(rr) p15, 0, rr, c7, c10, 2 /* Data cache clean by set/way */ + +#define CP15_CP15DSB(rr) p15, 0, rr, c7, c10, 4 +#define CP15_CP15DMB(rr) p15, 0, rr, c7, c10, 5 + +/* From ARMv7: */ +#define CP15_DCCMVAU(rr) p15, 0, rr, c7, c11, 1 /* Data cache clean by MVA PoU */ + +#define CP15_DCCIMVAC(rr) p15, 0, rr, c7, c14, 1 /* Data cache clean and invalidate by MVA PoC */ +#define CP15_DCCISW(rr) p15, 0, rr, c7, c14, 2 /* Data cache clean and invalidate by set/way */ + +/* + * CP15 C8 registers + */ +#ifdef MULTIPROCESSOR +/* From ARMv7: */ +#define CP15_TLBIALLIS p15, 0, r0, c8, c3, 0 /* Invalidate entire unified TLB IS */ +#define CP15_TLBIMVAIS(rr) p15, 0, rr, c8, c3, 1 /* Invalidate unified TLB by MVA IS */ +#define CP15_TLBIASIDIS(rr) p15, 0, rr, c8, c3, 2 /* Invalidate unified TLB by ASID IS */ +#define CP15_TLBIMVAAIS(rr) p15, 0, rr, c8, c3, 3 /* Invalidate unified TLB by MVA, all ASID IS */ +#endif + +#define CP15_DTLBIALL p15, 0, r0, c8, c6, 0 /* flush D tlb */ +#define CP15_DTLBIMVA p15, 0, r0, c8, c6, 1 /* Invalidate D TLB by MVA */ +#define CP15_ITLBIALL p15, 0, r0, c8, c5, 0 /* flush I tlb */ +#define CP15_ITLBIMVA p15, 0, r0, c8, c5, 1 /* Invalidate I TLB by MVA */ + +#define CP15_TLBIALL(rr) p15, 0, rr, c8, c7, 0 /* Invalidate entire unified TLB */ +#define CP15_TLBIMVA(rr) p15, 0, rr, c8, c7, 1 /* Invalidate unified TLB by MVA */ +#define CP15_TLBIASID(rr) p15, 0, rr, c8, c7, 2 /* Invalidate unified TLB by ASID */ + +/* From ARMv6: */ +#define CP15_TLBIMVAA(rr) p15, 0, rr, c8, c7, 3 /* Invalidate unified TLB by MVA, all ASID */ + +/* + * CP15 C9 registers + */ +#define CP15_L2CTLR(rr) p15, 1, rr, c9, c0, 2 /* L2 Control Register */ +#define CP15_PMCR(rr) p15, 0, rr, c9, c12, 0 /* Performance Monitor Control Register */ +#define CP15_PMCNTENSET(rr) p15, 0, rr, c9, c12, 1 /* PM Count Enable Set Register */ +#define CP15_PMCNTENCLR(rr) p15, 0, rr, c9, c12, 2 /* PM Count Enable Clear Register */ +#define CP15_PMOVSR(rr) p15, 0, rr, c9, c12, 3 /* PM Overflow Flag Status Register */ +#define CP15_PMSWINC(rr) p15, 0, rr, c9, c12, 4 /* PM Software Increment Register */ +#define CP15_PMSELR(rr) p15, 0, rr, c9, c12, 5 /* PM Event Counter Selection Register */ +#define CP15_PMCCNTR(rr) p15, 0, rr, c9, c13, 0 /* PM Cycle Count Register */ +#define CP15_PMXEVTYPER(rr) p15, 0, rr, c9, c13, 1 /* PM Event Type Select Register */ +#define CP15_PMXEVCNTRR(rr) p15, 0, rr, c9, c13, 2 /* PM Event Count Register */ +#define CP15_PMUSERENR(rr) p15, 0, rr, c9, c14, 0 /* PM User Enable Register */ +#define CP15_PMINTENSET(rr) p15, 0, rr, c9, c14, 1 /* PM Interrupt Enable Set Register */ +#define CP15_PMINTENCLR(rr) p15, 0, rr, c9, c14, 2 /* PM Interrupt Enable Clear Register */ + +/* + * CP15 C10 registers + */ +/* Without LPAE this is PRRR, with LPAE it's MAIR0 */ +#define CP15_PRRR(rr) p15, 0, rr, c10, c2, 0 /* Primary Region Remap Register */ +#define CP15_MAIR0(rr) p15, 0, rr, c10, c2, 0 /* Memory Attribute Indirection Register 0 */ +/* Without LPAE this is NMRR, with LPAE it's MAIR1 */ +#define CP15_NMRR(rr) p15, 0, rr, c10, c2, 1 /* Normal Memory Remap Register */ +#define CP15_MAIR1(rr) p15, 0, rr, c10, c2, 1 /* Memory Attribute Indirection Register 1 */ + +#define CP15_AMAIR0(rr) p15, 0, rr, c10, c3, 0 /* Auxiliary Memory Attribute Indirection Register 0 */ +#define CP15_AMAIR1(rr) p15, 0, rr, c10, c3, 1 /* Auxiliary Memory Attribute Indirection Register 1 */ + +/* + * CP15 C12 registers + */ +#define CP15_VBAR(rr) p15, 0, rr, c12, c0, 0 /* Vector Base Address Register */ +#define CP15_MVBAR(rr) p15, 0, rr, c12, c0, 1 /* Monitor Vector Base Address Register */ + +#define CP15_ISR(rr) p15, 0, rr, c12, c1, 0 /* Interrupt Status Register */ + +/* + * CP15 C13 registers + */ +#define CP15_FCSEIDR(rr) p15, 0, rr, c13, c0, 0 /* FCSE Process ID Register */ +#define CP15_CONTEXTIDR(rr) p15, 0, rr, c13, c0, 1 /* Context ID Register */ +#define CP15_TPIDRURW(rr) p15, 0, rr, c13, c0, 2 /* User Read/Write Thread ID Register */ +#define CP15_TPIDRURO(rr) p15, 0, rr, c13, c0, 3 /* User Read-Only Thread ID Register */ +#define CP15_TPIDRPRW(rr) p15, 0, rr, c13, c0, 4 /* PL1 only Thread ID Register */ + +/* + * CP15 C14 registers + * These are the Generic Timer registers and may be unallocated on some SoCs. + * Only use these when you know the Generic Timer is available. + */ +#define CP15_CNTFRQ(rr) p15, 0, rr, c14, c0, 0 /* Counter Frequency Register */ +#define CP15_CNTKCTL(rr) p15, 0, rr, c14, c1, 0 /* Timer PL1 Control Register */ +#define CP15_CNTP_TVAL(rr) p15, 0, rr, c14, c2, 0 /* PL1 Physical Timer Value Register */ +#define CP15_CNTP_CTL(rr) p15, 0, rr, c14, c2, 1 /* PL1 Physical Timer Control Register */ +#define CP15_CNTV_TVAL(rr) p15, 0, rr, c14, c3, 0 /* Virtual Timer Value Register */ +#define CP15_CNTV_CTL(rr) p15, 0, rr, c14, c3, 1 /* Virtual Timer Control Register */ +#define CP15_CNTHCTL(rr) p15, 4, rr, c14, c1, 0 /* Timer PL2 Control Register */ +#define CP15_CNTHP_TVAL(rr) p15, 4, rr, c14, c2, 0 /* PL2 Physical Timer Value Register */ +#define CP15_CNTHP_CTL(rr) p15, 4, rr, c14, c2, 1 /* PL2 Physical Timer Control Register */ +/* 64-bit registers for use with mcrr/mrrc */ +#define CP15_CNTPCT(rq, rr) p15, 0, rq, rr, c14 /* Physical Count Register */ +#define CP15_CNTVCT(rq, rr) p15, 1, rq, rr, c14 /* Virtual Count Register */ +#define CP15_CNTP_CVAL(rq, rr) p15, 2, rq, rr, c14 /* PL1 Physical Timer Compare Value Register */ +#define CP15_CNTV_CVAL(rq, rr) p15, 3, rq, rr, c14 /* Virtual Timer Compare Value Register */ +#define CP15_CNTVOFF(rq, rr) p15, 4, rq, rr, c14 /* Virtual Offset Register */ +#define CP15_CNTHP_CVAL(rq, rr) p15, 6, rq, rr, c14 /* PL2 Physical Timer Compare Value Register */ + +/* + * CP15 C15 registers + */ +#define CP15_CBAR(rr) p15, 4, rr, c15, c0, 0 /* Configuration Base Address Register */ + +#endif /* !MACHINE_SYSREG_H */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/tcb.h b/lib/libc/include/arm-openbsd-eabi/arm/tcb.h new file mode 100644 index 0000000000..3cc74e0f27 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/tcb.h @@ -0,0 +1,58 @@ +/* $OpenBSD: tcb.h,v 1.3 2016/10/02 20:11:32 guenther Exp $ */ + +/* + * Copyright (c) 2011 Philip Guenther + * + * 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 + +#include + +static inline void +__arm_set_tcb(void *tcb) +{ + __asm volatile("mcr p15, 0, %0, c13, c0, 3\n" : : "r" (tcb)); +} + +#define TCB_GET(p) \ + ((struct pcb *)(p)->p_addr)->pcb_tcb + +#define TCB_SET(p, addr) \ + do { \ + ((struct pcb *)(p)->p_addr)->pcb_tcb = (addr); \ + __arm_set_tcb(addr); \ + } while (0) + +#else /* _KERNEL */ + +/* ELF TLS ABI calls for small TCB, with static TLS data after it */ +#define TLS_VARIANT 1 + +static inline void * +__arm_read_tcb(void) +{ + void *tcb; + __asm volatile("mrc p15, 0, %0, c13, c0, 3\n" : "=r" (tcb)); + return tcb; +} + +#define TCB_GET() __arm_read_tcb() + +#endif /* _KERNEL */ + +#endif /* _MACHINE_TCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/trap.h b/lib/libc/include/arm-openbsd-eabi/arm/trap.h new file mode 100644 index 0000000000..8b34cd2240 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/trap.h @@ -0,0 +1,69 @@ +/* $OpenBSD: trap.h,v 1.2 2018/06/30 15:23:37 deraadt Exp $ */ +/* $NetBSD: trap.h,v 1.4 2003/04/28 01:54:50 briggs Exp $ */ + +/* + * Copyright (c) 1995 Mark Brinicombe. + * 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 Mark Brinicombe. + * 4. The name of the company nor the name of the author may 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 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. + * + * RiscBSD kernel project + * + * trap.h + * + * Various trap definitions + */ + +/* + * Instructions used for breakpoints. + * + * These are undefined instructions. + * Technically the userspace breakpoint could be a SWI but we want to + * keep this the same as IPKDB which needs an undefined instruction as + * a break point. + * + * Ideally ARM would define several standard instruction sequences for + * use as breakpoints. + * + * The BKPT instruction isn't much use to us, since its behaviour is + * unpredictable on ARMv3 and lower. + * + * The ARM ARM says that for maximum compatibility, we should use undefined + * instructions that look like 0x.7f...f. . + */ + +#define GDB_BREAKPOINT 0xe6000011 /* Used by GDB 4.x */ +#define IPKDB_BREAKPOINT 0xe6000010 /* Used by IPKDB */ +#define GDB5_BREAKPOINT 0xe7ffdefe /* Used by GDB 5.0 */ +#define KERNEL_BREAKPOINT 0xe7ffffff /* Used by DDB */ + +#define KBPT_ASM ".word 0xe7ffdefe" + +#define USER_BREAKPOINT GDB_BREAKPOINT + +#define T_FAULT 1 \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/undefined.h b/lib/libc/include/arm-openbsd-eabi/arm/undefined.h new file mode 100644 index 0000000000..87fd59dd75 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/undefined.h @@ -0,0 +1,87 @@ +/* $OpenBSD: undefined.h,v 1.4 2019/03/13 09:28:21 patrick Exp $ */ +/* $NetBSD: undefined.h,v 1.4 2001/12/20 01:20:23 thorpej Exp $ */ + +/* + * Copyright (c) 1995-1996 Mark Brinicombe. + * Copyright (c) 1995 Brini. + * All rights reserved. + * + * This code is derived from software written for Brini by Mark Brinicombe + * + * 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 Brini. + * 4. The name of the company nor the name of the author may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY BRINI ``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 BRINI 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. + * + * RiscBSD kernel project + * + * undefined.h + * + * Undefined instruction types, symbols and prototypes + * + * Created : 08/02/95 + */ + + +#ifndef _ARM_UNDEFINED_H_ +#define _ARM_UNDEFINED_H_ +#ifdef _KERNEL + +#include + +typedef int (*undef_handler_t) (unsigned int, unsigned int, trapframe_t *, int, uint32_t); + +#define FP_COPROC 1 +#define FP_COPROC2 2 +#define MAX_COPROCS 16 + +/* Prototypes for undefined.c */ + +void *install_coproc_handler (int, undef_handler_t); +void remove_coproc_handler (void *); +void undefined_init (void); + +/* + * XXX Stuff below here is for use before malloc() is available. Most code + * shouldn't use it. + */ + +struct undefined_handler { + LIST_ENTRY(undefined_handler) uh_link; + undef_handler_t uh_handler; +}; + +/* + * Handlers installed using install_coproc_handler_static shouldn't be + * removed. + */ +void install_coproc_handler_static (int, struct undefined_handler *); + +/* Calls up to undefined.c from trap handlers */ +void undefinedinstruction(struct trapframe *); + +#endif + +#endif /* _ARM_UNDEFINED_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/vfp.h b/lib/libc/include/arm-openbsd-eabi/arm/vfp.h new file mode 100644 index 0000000000..eadfa46c58 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/vfp.h @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2012 Mark Tinguely + * + * 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 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 AUTHOR 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. + * $FreeBSD$ + */ + + +#ifndef _MACHINE__VFP_H_ +#define _MACHINE__VFP_H_ + +#ifdef _KERNEL +/* Only kernel defines exist here */ + +/* fpsid, fpscr, fpexc are defined in the newer gas */ +#define VFPSID cr0 +#define VFPSCR cr1 +#define VMVFR1 cr6 +#define VMVFR0 cr7 +#define VFPEXC cr8 +#define VFPINST cr9 /* vfp 1 and 2 except instruction */ +#define VFPINST2 cr10 /* vfp 2? */ + +/* VFPSID */ +#define VFPSID_IMPLEMENTOR_OFF 24 +#define VFPSID_IMPLEMENTOR_MASK (0xff000000) +#define VFPSID_HARDSOFT_IMP (0x00800000) +#define VFPSID_SINGLE_PREC 20 /* version 1 and 2 */ +#define VFPSID_SUBVERSION_OFF 16 +#define VFPSID_SUBVERSION2_MASK (0x000f0000) /* version 1 and 2 */ +#define VFPSID_SUBVERSION3_MASK (0x007f0000) /* version 3 */ +#define VFP_ARCH3 (0x00030000) +#define VFPSID_PARTNUMBER_OFF 8 +#define VFPSID_PARTNUMBER_MASK (0x0000ff00) +#define VFPSID_VARIANT_OFF 4 +#define VFPSID_VARIANT_MASK (0x000000f0) +#define VFPSID_REVISION_MASK 0x0f + +/* VFPSCR */ +#define VFPSCR_CC_N (0x80000000) /* comparison less than */ +#define VFPSCR_CC_Z (0x40000000) /* comparison equal */ +#define VFPSCR_CC_C (0x20000000) /* comparison = > unordered */ +#define VFPSCR_CC_V (0x10000000) /* comparison unordered */ +#define VFPSCR_QC (0x08000000) /* cumulative saturation */ +#define VFPSCR_DN (0x02000000) /* default NaN enable */ +#define VFPSCR_FZ (0x01000000) /* flush to zero enabled */ + +#define VFPSCR_RMODE_OFF 22 /* rounding mode offset */ +#define VFPSCR_RMODE_MASK (0x00c00000) /* rounding mode mask */ +#define VFPSCR_RMODE_RN (0x00000000) /* round nearest */ +#define VFPSCR_RMODE_RPI (0x00400000) /* round to plus infinity */ +#define VFPSCR_RMODE_RNI (0x00800000) /* round to neg infinity */ +#define VFPSCR_RMODE_RM (0x00c00000) /* round to zero */ + +#define VFPSCR_STRIDE_OFF 20 /* vector stride -1 */ +#define VFPSCR_STRIDE_MASK (0x00300000) +#define VFPSCR_LEN_OFF 16 /* vector length -1 */ +#define VFPSCR_LEN_MASK (0x00070000) +#define VFPSCR_IDE (0x00008000) /* input subnormal exc enable */ +#define VFPSCR_IXE (0x00001000) /* inexact exception enable */ +#define VFPSCR_UFE (0x00000800) /* underflow exception enable */ +#define VFPSCR_OFE (0x00000400) /* overflow exception enable */ +#define VFPSCR_DNZ (0x00000200) /* div by zero exception en */ +#define VFPSCR_IOE (0x00000100) /* invalid op exec enable */ +#define VFPSCR_IDC (0x00000080) /* input subnormal cumul */ +#define VFPSCR_IXC (0x00000010) /* Inexact cumulative flag */ +#define VFPSCR_UFC (0x00000008) /* underflow cumulative flag */ +#define VFPSCR_OFC (0x00000004) /* overflow cumulative flag */ +#define VFPSCR_DZC (0x00000002) /* division by zero flag */ +#define VFPSCR_IOC (0x00000001) /* invalid operation cumul */ + +/* VFPEXC */ +#define VFPEXC_EX (0x80000000) /* exception v1 v2 */ +#define VFPEXC_EN (0x40000000) /* vfp enable */ + +/* version 3 registers */ +/* VMVFR0 */ +#define VMVFR0_RM_OFF 28 +#define VMVFR0_RM_MASK (0xf0000000) /* VFP rounding modes */ + +#define VMVFR0_SV_OFF 24 +#define VMVFR0_SV_MASK (0x0f000000) /* VFP short vector supp */ +#define VMVFR0_SR_OFF 20 +#define VMVFR0_SR (0x00f00000) /* VFP hw sqrt supp */ +#define VMVFR0_D_OFF 16 +#define VMVFR0_D_MASK (0x000f0000) /* VFP divide supp */ +#define VMVFR0_TE_OFF 12 +#define VMVFR0_TE_MASK (0x0000f000) /* VFP trap exception supp */ +#define VMVFR0_DP_OFF 8 +#define VMVFR0_DP_MASK (0x00000f00) /* VFP double prec support */ +#define VMVFR0_SP_OFF 4 +#define VMVFR0_SP_MASK (0x000000f0) /* VFP single prec support */ +#define VMVFR0_RB_MASK (0x0000000f) /* VFP 64 bit media support */ + +/* VMVFR1 */ +#define VMVFR1_SP_OFF 16 +#define VMVFR1_SP_MASK (0x000f0000) /* Neon single prec support */ +#define VMVFR1_I_OFF 12 +#define VMVFR1_I_MASK (0x0000f000) /* Neon integer support */ +#define VMVFR1_LS_OFF 8 +#define VMVFR1_LS_MASK (0x00000f00) /* Neon ld/st instr support */ +#define VMVFR1_DN_OFF 4 +#define VMVFR1_DN_MASK (0x000000f0) /* Neon prop NaN support */ +#define VMVFR1_FZ_MASK (0x0000000f) /* Neon denormal arith supp */ + +#define COPROC10 (0x3 << 20) +#define COPROC11 (0x3 << 22) + +void vfp_init(void); +void vfp_discard(struct proc *); +uint32_t vfp_save(void); +void vfp_enable(void); + +#endif /* _KERNEL */ +#endif /* _MACHINE__VFP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/arm/vmparam.h b/lib/libc/include/arm-openbsd-eabi/arm/vmparam.h new file mode 100644 index 0000000000..6a93dd7378 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/arm/vmparam.h @@ -0,0 +1,85 @@ +/* $OpenBSD: vmparam.h,v 1.20 2024/02/01 00:39:57 deraadt Exp $ */ +/* $NetBSD: vmparam.h,v 1.18 2003/05/21 18:04:44 thorpej Exp $ */ + +/* + * Copyright (c) 2001, 2002 Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Jason R. Thorpe for Wasabi Systems, Inc. + * + * 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 for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC + * 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 _ARM_VMPARAM_H_ +#define _ARM_VMPARAM_H_ + +/* + * Virtual Memory parameters common to all arm32 platforms. + */ + +#define USRSTACK VM_MAXUSER_ADDRESS +#define KERNBASE VM_MAXUSER_ADDRESS + +#define MAXTSIZ (128*1024*1024) /* max text size */ + +#ifndef DFLDSIZ +#define DFLDSIZ (128*1024*1024) /* initial data size limit */ +#endif +#ifndef MAXDSIZ +#define MAXDSIZ (512*1024*1024) /* max data size */ +#endif +#ifndef BRKSIZ +#define BRKSIZ MAXDSIZ /* heap gap size */ +#endif +#ifndef DFLSSIZ +#define DFLSSIZ (2*1024*1024) /* initial stack size limit */ +#endif +#ifndef MAXSSIZ +#define MAXSSIZ (32*1024*1024) /* max stack size */ +#endif + +#define STACKGAP_RANDOM 256*1024 + +/* + * Size of SysV shared memory map + */ +#ifndef SHMMAXPGS +#define SHMMAXPGS 1024 +#endif + +/* + * Mach derived constants + */ +#define VM_MIN_ADDRESS ((vaddr_t) PAGE_SIZE) +#define VM_MAXUSER_ADDRESS ((vaddr_t) ARM_KERNEL_BASE) +#define VM_MAX_ADDRESS VM_MAXUSER_ADDRESS + +#define VM_MIN_KERNEL_ADDRESS ((vaddr_t) ARM_KERNEL_BASE) + +#endif /* _ARM_VMPARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/_float.h b/lib/libc/include/arm-openbsd-eabi/armv7/_float.h new file mode 100644 index 0000000000..0f250fbbe4 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/_float.h @@ -0,0 +1,3 @@ +/* $OpenBSD: _float.h,v 1.1 2013/09/04 14:38:26 patrick Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/_types.h b/lib/libc/include/arm-openbsd-eabi/armv7/_types.h new file mode 100644 index 0000000000..74ac2daf85 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/_types.h @@ -0,0 +1,9 @@ +/* $OpenBSD: _types.h,v 1.1 2013/09/04 14:38:26 patrick Exp $ */ +/* $NetBSD: types.h,v 1.4 2002/02/28 03:17:26 simonb Exp $ */ + +#ifndef _MACHINE__TYPES_H_ +#define _MACHINE__TYPES_H_ + +#include + +#endif /* _MACHINE__TYPES_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/apmvar.h b/lib/libc/include/arm-openbsd-eabi/armv7/apmvar.h new file mode 100644 index 0000000000..1919263102 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/apmvar.h @@ -0,0 +1,2 @@ +/* $OpenBSD: apmvar.h,v 1.1 2013/09/04 14:38:26 patrick Exp $ */ +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/asm.h b/lib/libc/include/arm-openbsd-eabi/armv7/asm.h new file mode 100644 index 0000000000..358368b17d --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/asm.h @@ -0,0 +1,4 @@ +/* $OpenBSD: asm.h,v 1.1 2013/09/04 14:38:26 patrick Exp $ */ +/* $NetBSD: asm.h,v 1.3 2001/11/25 15:55:54 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/atomic.h b/lib/libc/include/arm-openbsd-eabi/armv7/atomic.h new file mode 100644 index 0000000000..ec3b2814a4 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/atomic.h @@ -0,0 +1,10 @@ +/* $OpenBSD: atomic.h,v 1.1 2013/09/04 14:38:26 patrick Exp $ */ + +/* Public Domain */ + +#ifndef _MACHINE_ATOMIC_H_ +#define _MACHINE_ATOMIC_H_ + +#include + +#endif /* _MACHINE_ATOMIC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/bootconfig.h b/lib/libc/include/arm-openbsd-eabi/armv7/bootconfig.h new file mode 100644 index 0000000000..c806b7a421 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/bootconfig.h @@ -0,0 +1,70 @@ +/* $OpenBSD: bootconfig.h,v 1.2 2019/05/06 03:34:43 mlarkin Exp $ */ +/* $NetBSD: bootconfig.h,v 1.2 2001/06/21 22:08:28 chris Exp $ */ + +/* + * Copyright (c) 1994 Mark Brinicombe. + * Copyright (c) 1994 Brini. + * All rights reserved. + * + * This code is derived from software written for Brini by Mark Brinicombe + * + * 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 Mark Brinicombe + * for the NetBSD Project. + * 4. The name of the company nor the name of the author may 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 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * boot configuration structures + * + * Created : 12/09/94 + * + * Based on kate/boot/bootconfig.h + */ + +#if defined(_KERNEL) || defined(_STANDALONE) + +typedef struct _PhysMem { + u_int address; + u_int pages; +} PhysMem; + +#define DRAM_BLOCKS 2 +#define MAX_BOOT_STRING 255 + +typedef struct _BootConfig { + PhysMem dram[DRAM_BLOCKS]; + u_int dramblocks; + char bootstring[MAX_BOOT_STRING]; +} BootConfig; + +extern BootConfig bootconfig; + +#endif /* _KERNEL || _STANDALONE */ +#if defined(_KERNEL) +extern char *boot_args; +extern char *boot_file; +#endif /* _KERNEL */ + +/* End of bootconfig.h */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/bus.h b/lib/libc/include/arm-openbsd-eabi/armv7/bus.h new file mode 100644 index 0000000000..0a27ab9dd4 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/bus.h @@ -0,0 +1,4 @@ +/* $OpenBSD: bus.h,v 1.1 2013/09/04 14:38:26 patrick Exp $ */ +/* $NetBSD: bus.h,v 1.3 2001/11/25 15:55:55 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/cdefs.h b/lib/libc/include/arm-openbsd-eabi/armv7/cdefs.h new file mode 100644 index 0000000000..8ca96399b0 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/cdefs.h @@ -0,0 +1,3 @@ +/* $OpenBSD: cdefs.h,v 1.1 2013/09/04 14:38:26 patrick Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/conf.h b/lib/libc/include/arm-openbsd-eabi/armv7/conf.h new file mode 100644 index 0000000000..514e8d0262 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/conf.h @@ -0,0 +1,10 @@ +/* $OpenBSD: conf.h,v 1.2 2025/07/16 03:01:53 jsg Exp $ */ +/* $NetBSD: conf.h,v 1.8 2002/02/10 12:26:03 chris Exp $ */ + +#ifndef _MACHINE_CONF_H_ +#define _MACHINE_CONF_H_ + +#include +#include + +#endif /* _MACHINE_CONF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/cpu.h b/lib/libc/include/arm-openbsd-eabi/armv7/cpu.h new file mode 100644 index 0000000000..e9e7ffb3c6 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/cpu.h @@ -0,0 +1,4 @@ +/* $OpenBSD: cpu.h,v 1.1 2013/09/04 14:38:26 patrick Exp $ */ +/* $NetBSD: cpu.h,v 1.3 2001/11/25 15:55:55 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/cpufunc.h b/lib/libc/include/arm-openbsd-eabi/armv7/cpufunc.h new file mode 100644 index 0000000000..83545e6386 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/cpufunc.h @@ -0,0 +1,16 @@ +/* $OpenBSD: cpufunc.h,v 1.1 2020/11/29 12:54:36 kettenis Exp $ */ + +/* Public Domain */ + +#ifndef _MACHINE_CPUFUNC_H_ +#define _MACHINE_CPUFUNC_H_ + +#include + +#ifdef _KERNEL + +register_t smc_call(register_t, register_t, register_t, register_t); + +#endif /* _KERNEL */ + +#endif /* _MACHINE_CPUFUNC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/db_machdep.h b/lib/libc/include/arm-openbsd-eabi/armv7/db_machdep.h new file mode 100644 index 0000000000..0142ddba5e --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/db_machdep.h @@ -0,0 +1,4 @@ +/* $OpenBSD: db_machdep.h,v 1.1 2013/09/04 14:38:26 patrick Exp $ */ +/* $NetBSD: db_machdep.h,v 1.3 2001/11/25 15:55:55 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/disklabel.h b/lib/libc/include/arm-openbsd-eabi/armv7/disklabel.h new file mode 100644 index 0000000000..bb72317025 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/disklabel.h @@ -0,0 +1,3 @@ +/* $OpenBSD: disklabel.h,v 1.1 2013/09/04 14:38:27 patrick Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/elf.h b/lib/libc/include/arm-openbsd-eabi/armv7/elf.h new file mode 100644 index 0000000000..adbf226bf2 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/elf.h @@ -0,0 +1,3 @@ +/* $OpenBSD: elf.h,v 1.1 2024/07/14 19:33:59 miod Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/endian.h b/lib/libc/include/arm-openbsd-eabi/armv7/endian.h new file mode 100644 index 0000000000..a38e0819d6 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/endian.h @@ -0,0 +1,4 @@ +/* $OpenBSD: endian.h,v 1.1 2013/09/04 14:38:27 patrick Exp $ */ +/* $NetBSD: endian.h,v 1.3 2001/11/25 15:55:56 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/exec.h b/lib/libc/include/arm-openbsd-eabi/armv7/exec.h new file mode 100644 index 0000000000..6bb7f50e7e --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/exec.h @@ -0,0 +1,3 @@ +/* $OpenBSD: exec.h,v 1.1 2013/09/04 14:38:27 patrick Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/fdt.h b/lib/libc/include/arm-openbsd-eabi/armv7/fdt.h new file mode 100644 index 0000000000..386a6d31cf --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/fdt.h @@ -0,0 +1,3 @@ +/* $OpenBSD: fdt.h,v 1.1 2016/05/02 08:15:55 patrick Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/fenv.h b/lib/libc/include/arm-openbsd-eabi/armv7/fenv.h new file mode 100644 index 0000000000..1f648e1005 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/fenv.h @@ -0,0 +1,3 @@ +/* $OpenBSD: fenv.h,v 1.1 2013/09/04 14:38:27 patrick Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/frame.h b/lib/libc/include/arm-openbsd-eabi/armv7/frame.h new file mode 100644 index 0000000000..9ca41597fe --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/frame.h @@ -0,0 +1,4 @@ +/* $OpenBSD: frame.h,v 1.1 2013/09/04 14:38:27 patrick Exp $ */ +/* $NetBSD: frame.h,v 1.1 2001/06/08 22:23:00 chris Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/ieee.h b/lib/libc/include/arm-openbsd-eabi/armv7/ieee.h new file mode 100644 index 0000000000..cbd95dc298 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/ieee.h @@ -0,0 +1,4 @@ +/* $OpenBSD: ieee.h,v 1.1 2013/09/04 14:38:27 patrick Exp $ */ +/* $NetBSD: ieee.h,v 1.3 2001/11/25 15:55:56 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/ieeefp.h b/lib/libc/include/arm-openbsd-eabi/armv7/ieeefp.h new file mode 100644 index 0000000000..f4c270c690 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/ieeefp.h @@ -0,0 +1,4 @@ +/* $OpenBSD: ieeefp.h,v 1.1 2013/09/04 14:38:27 patrick Exp $ */ +/* $NetBSD: ieeefp.h,v 1.3 2001/11/25 15:55:56 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/intr.h b/lib/libc/include/arm-openbsd-eabi/armv7/intr.h new file mode 100644 index 0000000000..0f597a3f15 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/intr.h @@ -0,0 +1,229 @@ +/* $OpenBSD: intr.h,v 1.16 2025/05/10 10:11:02 visa Exp $ */ +/* $NetBSD: intr.h,v 1.12 2003/06/16 20:00:59 thorpej Exp $ */ + +/* + * Copyright (c) 2001, 2003 Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Jason R. Thorpe for Wasabi Systems, Inc. + * + * 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 for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC + * 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_INTR_H_ +#define _MACHINE_INTR_H_ + +#ifdef _KERNEL + +/* Interrupt priority `levels'; not mutually exclusive. */ +#define IPL_NONE 0 /* nothing */ +#define IPL_SOFTCLOCK 2 /* soft clock interrupts */ +#define IPL_SOFTNET 3 /* soft network interrupts */ +#define IPL_SOFTTTY 4 /* soft terminal interrupts */ +#define IPL_BIO 5 /* block I/O */ +#define IPL_NET 6 /* network */ +#define IPL_TTY 7 /* terminal */ +#define IPL_VM 8 /* memory allocation */ +#define IPL_AUDIO 9 /* audio */ +#define IPL_CLOCK 10 /* clock */ +#define IPL_SCHED IPL_CLOCK +#define IPL_STATCLOCK IPL_CLOCK +#define IPL_HIGH 11 /* everything */ +#define IPL_IPI 12 /* interprocessor interrupt */ +#define NIPL 13 /* number of levels */ + +#define IPL_MPFLOOR IPL_TTY +/* Interrupt priority 'flags'. */ +#define IPL_IRQMASK 0xf /* priority only */ +#define IPL_FLAGMASK 0xf00 /* flags only*/ +#define IPL_MPSAFE 0x100 /* 'mpsafe' interrupt, no kernel lock */ + +/* Interrupt sharing types. */ +#define IST_NONE 0 /* none */ +#define IST_PULSE 1 /* pulsed */ +#define IST_EDGE 2 /* edge-triggered */ +#define IST_LEVEL 3 /* level-triggered */ + +#define IST_LEVEL_LOW IST_LEVEL +#define IST_LEVEL_HIGH 4 +#define IST_EDGE_FALLING IST_EDGE +#define IST_EDGE_RISING 5 +#define IST_EDGE_BOTH 6 + +#define __USE_MI_SOFTINTR + +#include + +#ifndef _LOCORE +#include + +struct cpu_info; + +int splraise(int); +int spllower(int); +void splx(int); + +void arm_do_pending_intr(int); +void arm_set_intr_handler(int (*raise)(int), int (*lower)(int), + void (*x)(int), void (*setipl)(int), + void *(*intr_establish)(int irqno, int level, struct cpu_info *ci, + int (*func)(void *), void *cookie, char *name), + void (*intr_disestablish)(void *cookie), + const char *(*intr_string)(void *cookie), + void (*intr_handle)(void *)); + +struct arm_intr_func { + int (*raise)(int); + int (*lower)(int); + void (*x)(int); + void (*setipl)(int); + void *(*intr_establish)(int irqno, int level, struct cpu_info *, + int (*func)(void *), void *cookie, char *name); + void (*intr_disestablish)(void *cookie); + const char *(*intr_string)(void *cookie); +}; + +extern struct arm_intr_func arm_intr_func; + +#define splraise(cpl) (arm_intr_func.raise(cpl)) +#define _splraise(cpl) (arm_intr_func.raise(cpl)) +#define spllower(cpl) (arm_intr_func.lower(cpl)) +#define splx(cpl) (arm_intr_func.x(cpl)) + +#define splhigh() splraise(IPL_HIGH) +#define splsoftclock() splraise(IPL_SOFTCLOCK) +#define splsoftnet() splraise(IPL_SOFTNET) +#define splbio() splraise(IPL_BIO) +#define splnet() splraise(IPL_NET) +#define spltty() splraise(IPL_TTY) +#define splvm() splraise(IPL_VM) +#define splaudio() splraise(IPL_AUDIO) +#define splclock() splraise(IPL_CLOCK) +#define splstatclock() splraise(IPL_STATCLOCK) + +#define spl0() spllower(IPL_NONE) + +#define splsched() splhigh() + +void intr_barrier(void *); + +void arm_init_smask(void); /* XXX */ +extern uint32_t arm_smask[NIPL]; +void arm_setsoftintr(int si); + +#define softintr arm_setsoftintr + +void *arm_intr_establish(int irqno, int level, int (*func)(void *), + void *cookie, char *name); +void arm_intr_disestablish(void *cookie); +const char *arm_intr_string(void *cookie); + +/* XXX - this is probably the wrong location for this */ +void arm_clock_register(void (*)(void), void (*)(u_int), void (*)(int), + void (*)(void)); + +struct interrupt_controller { + int ic_node; + void *ic_cookie; + void *(*ic_establish)(void *, int *, int, struct cpu_info *, + int (*)(void *), void *, char *); + void *(*ic_establish_msi)(void *, uint64_t *, uint64_t *, int, + struct cpu_info *, int (*)(void *), void *, char *); + void (*ic_disestablish)(void *); + void (*ic_enable)(void *); + void (*ic_disable)(void *); + void (*ic_route)(void *, int, struct cpu_info *); + void (*ic_cpu_enable)(void); + void (*ic_barrier)(void *); + + LIST_ENTRY(interrupt_controller) ic_list; + uint32_t ic_phandle; + uint32_t ic_cells; +}; + +void arm_intr_init_fdt(void); +void arm_intr_register_fdt(struct interrupt_controller *); +void *arm_intr_establish_fdt(int, int, int (*)(void *), + void *, char *); +void *arm_intr_establish_fdt_cpu(int, int, struct cpu_info *, + int (*)(void *), void *, char *); +void *arm_intr_establish_fdt_idx(int, int, int, int (*)(void *), + void *, char *); +void *arm_intr_establish_fdt_idx_cpu(int, int, int, struct cpu_info *, + int (*)(void *), void *, char *); +void *arm_intr_establish_fdt_imap(int, int *, int, int, int (*)(void *), + void *, char *); +void *arm_intr_establish_fdt_imap_cpu(int, int *, int, int, + struct cpu_info *, int (*)(void *), void *, char *); +void *arm_intr_establish_fdt_msi(int, uint64_t *, uint64_t *, int, + int (*)(void *), void *, char *); +void *arm_intr_establish_fdt_msi_cpu(int, uint64_t *, uint64_t *, int, + struct cpu_info *, int (*)(void *), void *, char *); +void arm_intr_disestablish_fdt(void *); +void arm_intr_enable(void *); +void arm_intr_disable(void *); +void arm_intr_route(void *, int, struct cpu_info *); +void arm_intr_cpu_enable(void); + +void *arm_intr_parent_establish_fdt(void *, int *, int, + struct cpu_info *ci, int (*)(void *), void *, char *); +void arm_intr_parent_disestablish_fdt(void *); + +void arm_send_ipi(struct cpu_info *, int); +extern void (*intr_send_ipi_func)(struct cpu_info *, int); + +#define ARM_IPI_NOP 0 +#define ARM_IPI_DDB 1 + +#ifdef DIAGNOSTIC +/* + * Although this function is implemented in MI code, it must be in this MD + * header because we don't want this header to include MI includes. + */ +void splassert_fail(int, int, const char *); +extern int splassert_ctl; +void arm_splassert_check(int, const char *); +#define splassert(__wantipl) do { \ + if (splassert_ctl > 0) { \ + arm_splassert_check(__wantipl, __func__); \ + } \ +} while (0) +#define splsoftassert(wantipl) splassert(wantipl) +#else +#define splassert(wantipl) do { /* nothing */ } while (0) +#define splsoftassert(wantipl) do { /* nothing */ } while (0) +#endif + +#endif /* ! _LOCORE */ + +#define ARM_IRQ_HANDLER arm_intr + +#endif /* _KERNEL */ + +#endif /* _MACHINE_INTR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/limits.h b/lib/libc/include/arm-openbsd-eabi/armv7/limits.h new file mode 100644 index 0000000000..59a9c2820a --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/limits.h @@ -0,0 +1,4 @@ +/* $OpenBSD: limits.h,v 1.1 2013/09/04 14:38:27 patrick Exp $ */ +/* $NetBSD: limits.h,v 1.3 2001/11/25 15:55:57 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/loadfile_machdep.h b/lib/libc/include/arm-openbsd-eabi/armv7/loadfile_machdep.h new file mode 100644 index 0000000000..d4af12ff27 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/loadfile_machdep.h @@ -0,0 +1,53 @@ +/* $OpenBSD: loadfile_machdep.h,v 1.5 2019/04/10 04:17:34 deraadt Exp $ */ +/* $NetBSD: loadfile_machdep.h,v 1.1 1999/04/29 03:17:12 tsubai Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * 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. + */ + +#define BOOT_ELF +#define ELFSIZE 32 + +#define LOAD_KERNEL LOAD_ALL +#define COUNT_KERNEL COUNT_ALL + +extern u_long efi_loadaddr; +#define LOADADDR(a) (((((u_long)(a)) + offset)&0xfffffff) + \ + efi_loadaddr) +#define ALIGNENTRY(a) ((u_long)(a)) +#define READ(f, b, c) read((f), (void *)LOADADDR(b), (c)) +#define BCOPY(s, d, c) memcpy((void *)LOADADDR(d), (void *)(s), (c)) +#define BZERO(d, c) memset((void *)LOADADDR(d), 0, (c)) +#define WARN(a) (void)(printf a, \ + printf((errno ? ": %s\n" : "\n"), \ + strerror(errno))) +#define PROGRESS(a) (void) printf a +#define ALLOC(a) alloc(a) +#define FREE(a, b) free(a, b) + +void run_loadfile(uint64_t *, int); \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/machine_reg.h b/lib/libc/include/arm-openbsd-eabi/armv7/machine_reg.h new file mode 100644 index 0000000000..ef87538012 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/machine_reg.h @@ -0,0 +1,57 @@ +/* $OpenBSD: machine_reg.h,v 1.3 2019/05/06 03:34:43 mlarkin Exp $ */ + +/* + * Copyright (c) 2002, 2003 Genetec Corporation. All rights reserved. + * Written by Hiroyuki Bessho for Genetec Corporation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of Genetec Corporation may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``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 GENETEC CORPORATION + * 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_REG_H +#define _MACHINE_REG_H + +/* + * Logical mapping for onboard/integrated peripherals + */ +#define MACHINE_IO_AREA_VBASE 0xfd000000 +#define MACHINE_GPIO_VBASE 0xfd000000 +#define MACHINE_CLKMAN_VBASE 0xfd100000 +#define MACHINE_INTCTL_VBASE 0xfd200000 +#define MACHINE_AGPIO_VBASE 0xfd300000 +#define MACHINE_VBASE_FREE 0xfd400000 +/* FFUART and/or BTUART are mapped to this area when + used for console */ + +#define ioreg_read(a) (*(volatile unsigned *)(a)) +#define ioreg_write(a,v) (*(volatile unsigned *)(a)=(v)) + +#define ioreg16_read(a) (*(volatile uint16_t *)(a)) +#define ioreg16_write(a,v) (*(volatile uint16_t *)(a)=(v)) + +#define ioreg8_read(a) (*(volatile uint8_t *)(a)) +#define ioreg8_write(a,v) (*(volatile uint8_t *)(a)=(v)) + +#endif /* _MACHINE_REG_H */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/mplock.h b/lib/libc/include/arm-openbsd-eabi/armv7/mplock.h new file mode 100644 index 0000000000..d4ecdcd49f --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/mplock.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mplock.h,v 1.1 2018/08/06 18:39:13 kettenis Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/mutex.h b/lib/libc/include/arm-openbsd-eabi/armv7/mutex.h new file mode 100644 index 0000000000..1af94436f5 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/mutex.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mutex.h,v 1.1 2013/09/04 14:38:28 patrick Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/openpromio.h b/lib/libc/include/arm-openbsd-eabi/armv7/openpromio.h new file mode 100644 index 0000000000..39f68f71a5 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/openpromio.h @@ -0,0 +1,3 @@ +/* $OpenBSD: openpromio.h,v 1.1 2016/05/21 21:24:36 kettenis Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/param.h b/lib/libc/include/arm-openbsd-eabi/armv7/param.h new file mode 100644 index 0000000000..72d453ef46 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/param.h @@ -0,0 +1,51 @@ +/* $OpenBSD: param.h,v 1.3 2018/08/09 12:19:32 patrick Exp $ */ + +/* + * Copyright (c) 1994,1995 Mark Brinicombe. + * 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 the RiscBSD team. + * 4. The name "RiscBSD" nor the name of the author may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY RISCBSD ``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 RISCBSD 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_ + +#include + +#define _MACHINE armv7 +#define MACHINE "armv7" + +#ifndef MSGBUFSIZE +#define MSGBUFSIZE (8 * PAGE_SIZE) +#endif + +#ifdef _KERNEL +#define __HAVE_FDT +#endif + +#endif /* _MACHINE_PARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/pcb.h b/lib/libc/include/arm-openbsd-eabi/armv7/pcb.h new file mode 100644 index 0000000000..d2b73c6db5 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/pcb.h @@ -0,0 +1,4 @@ +/* $OpenBSD: pcb.h,v 1.1 2013/09/04 14:38:28 patrick Exp $ */ +/* $NetBSD: pcb.h,v 1.3 2001/11/25 15:55:57 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/pci_machdep.h b/lib/libc/include/arm-openbsd-eabi/armv7/pci_machdep.h new file mode 100644 index 0000000000..54442a8005 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/pci_machdep.h @@ -0,0 +1,3 @@ +/* $OpenBSD: pci_machdep.h,v 1.1 2018/07/09 09:53:06 patrick Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/pmap.h b/lib/libc/include/arm-openbsd-eabi/armv7/pmap.h new file mode 100644 index 0000000000..bc631302ef --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/pmap.h @@ -0,0 +1,4 @@ +/* $OpenBSD: pmap.h,v 1.1 2013/09/04 14:38:28 patrick Exp $ */ +/* $NetBSD: pmap.h,v 1.2 2001/11/23 17:29:01 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/proc.h b/lib/libc/include/arm-openbsd-eabi/armv7/proc.h new file mode 100644 index 0000000000..d92b1e2712 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/proc.h @@ -0,0 +1,4 @@ +/* $OpenBSD: proc.h,v 1.1 2013/09/04 14:38:28 patrick Exp $ */ +/* $NetBSD: proc.h,v 1.3 2001/11/25 15:55:57 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/profile.h b/lib/libc/include/arm-openbsd-eabi/armv7/profile.h new file mode 100644 index 0000000000..72aa69fcf3 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/profile.h @@ -0,0 +1,4 @@ +/* $OpenBSD: profile.h,v 1.1 2013/09/04 14:38:28 patrick Exp $ */ +/* $NetBSD: profile.h,v 1.3 2001/11/25 15:55:57 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/ptrace.h b/lib/libc/include/arm-openbsd-eabi/armv7/ptrace.h new file mode 100644 index 0000000000..fda3e95619 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/ptrace.h @@ -0,0 +1,4 @@ +/* $OpenBSD: ptrace.h,v 1.1 2013/09/04 14:38:28 patrick Exp $ */ +/* $NetBSD: ptrace.h,v 1.3 2001/11/25 15:55:58 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/reg.h b/lib/libc/include/arm-openbsd-eabi/armv7/reg.h new file mode 100644 index 0000000000..8bee9a0ffc --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/reg.h @@ -0,0 +1,4 @@ +/* $OpenBSD: reg.h,v 1.1 2013/09/04 14:38:28 patrick Exp $ */ +/* $NetBSD: reg.h,v 1.3 2001/11/25 15:55:58 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/reloc.h b/lib/libc/include/arm-openbsd-eabi/armv7/reloc.h new file mode 100644 index 0000000000..d4311b2f14 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/reloc.h @@ -0,0 +1,2 @@ +/* $OpenBSD: reloc.h,v 1.1 2013/09/04 14:38:29 patrick Exp $ */ +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/setjmp.h b/lib/libc/include/arm-openbsd-eabi/armv7/setjmp.h new file mode 100644 index 0000000000..5125b28bd3 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/setjmp.h @@ -0,0 +1,4 @@ +/* $OpenBSD: setjmp.h,v 1.1 2013/09/04 14:38:29 patrick Exp $ */ +/* $NetBSD: setjmp.h,v 1.3 2001/11/25 15:55:58 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/signal.h b/lib/libc/include/arm-openbsd-eabi/armv7/signal.h new file mode 100644 index 0000000000..0fc0632217 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/signal.h @@ -0,0 +1,4 @@ +/* $OpenBSD: signal.h,v 1.1 2013/09/04 14:38:29 patrick Exp $ */ +/* $NetBSD: signal.h,v 1.3 2001/11/25 15:55:58 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/simplebusvar.h b/lib/libc/include/arm-openbsd-eabi/armv7/simplebusvar.h new file mode 100644 index 0000000000..0620d80449 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/simplebusvar.h @@ -0,0 +1,3 @@ +/* $OpenBSD: simplebusvar.h,v 1.1 2023/09/22 01:10:43 jsg Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/spinlock.h b/lib/libc/include/arm-openbsd-eabi/armv7/spinlock.h new file mode 100644 index 0000000000..675d503f43 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/spinlock.h @@ -0,0 +1,3 @@ +/* $OpenBSD: spinlock.h,v 1.2 2017/01/05 16:52:42 patrick Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/sysarch.h b/lib/libc/include/arm-openbsd-eabi/armv7/sysarch.h new file mode 100644 index 0000000000..4a65320d70 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/sysarch.h @@ -0,0 +1,4 @@ +/* $OpenBSD: sysarch.h,v 1.1 2013/09/04 14:38:29 patrick Exp $ */ +/* $NetBSD: sysarch.h,v 1.3 2001/11/25 15:55:58 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/tcb.h b/lib/libc/include/arm-openbsd-eabi/armv7/tcb.h new file mode 100644 index 0000000000..a5a3f7799f --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/tcb.h @@ -0,0 +1,3 @@ +/* $OpenBSD: tcb.h,v 1.1 2013/09/04 14:38:29 patrick Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/timetc.h b/lib/libc/include/arm-openbsd-eabi/armv7/timetc.h new file mode 100644 index 0000000000..9af8a41ca2 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/timetc.h @@ -0,0 +1,23 @@ +/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:07 pirofti Exp $ */ +/* + * Copyright (c) 2020 Paul Irofti + * + * 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_TIMETC_H_ +#define _MACHINE_TIMETC_H_ + +#define TC_LAST 0 + +#endif /* _MACHINE_TIMETC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/trap.h b/lib/libc/include/arm-openbsd-eabi/armv7/trap.h new file mode 100644 index 0000000000..2904fcc7b5 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/trap.h @@ -0,0 +1,4 @@ +/* $OpenBSD: trap.h,v 1.1 2013/09/04 14:38:29 patrick Exp $ */ +/* $NetBSD: trap.h,v 1.3 2001/11/25 15:55:58 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/armv7/vmparam.h b/lib/libc/include/arm-openbsd-eabi/armv7/vmparam.h new file mode 100644 index 0000000000..fb4d068a38 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/armv7/vmparam.h @@ -0,0 +1,98 @@ +/* $OpenBSD: vmparam.h,v 1.8 2023/11/12 16:37:28 kettenis Exp $ */ +/* $NetBSD: vmparam.h,v 1.23 2003/05/22 05:47:07 thorpej 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. + */ + +#ifndef _MACHINE_VMPARAM_H_ +#define _MACHINE_VMPARAM_H_ + +#define ARM_KERNEL_BASE 0xc0000000U + +/* Allow armv7 to have bigger limits than generic arm, allow user to override */ +#ifndef MAXDSIZ +#define MAXDSIZ (2UL*1024*1024*1024) /* max data size */ +#endif +#ifndef BRKSIZ +#define BRKSIZ MAXDSIZ /* heap gap size */ +#endif +#ifndef DFLSSIZ +#define DFLSSIZ (4*1024*1024) /* initial stack size limit */ +#endif +#ifndef MAXSSIZ +#define MAXSSIZ (32*1024*1024) /* max stack size */ +#endif + +#include + +#ifdef _KERNEL +/* + * Address space constants + */ + +/* + * The line between user space and kernel space + * Mappings >= KERNEL_BASE are constant across all processes + */ +#define KERNEL_BASE ARM_KERNEL_BASE + +#define VM_KERNEL_SPACE_SIZE 0x20000000 + +/* + * Override the default pager_map size, there's not enough KVA. + */ +#define PAGER_MAP_SIZE (4 * 1024 * 1024) + +/* + * Size of User Raw I/O map + */ + +#define USRIOSIZE 300 + +/* virtual sizes (bytes) for various kernel submaps */ + +#define VM_PHYS_SIZE (USRIOSIZE*PAGE_SIZE) + +/* + * max number of non-contig chunks of physical RAM you can have + */ + +#define VM_PHYSSEG_MAX 32 +#define VM_PHYSSEG_STRAT VM_PSTRAT_BSEARCH + +/* + * this indicates that we can't add RAM to the VM system after the + * vm system is init'd. + */ + +#define VM_PHYSSEG_NOADD + +#endif /* _KERNEL */ + +#endif /* _MACHINE_VMPARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/frame.h b/lib/libc/include/arm-openbsd-eabi/frame.h new file mode 100644 index 0000000000..9ca41597fe --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/frame.h @@ -0,0 +1,4 @@ +/* $OpenBSD: frame.h,v 1.1 2013/09/04 14:38:27 patrick Exp $ */ +/* $NetBSD: frame.h,v 1.1 2001/06/08 22:23:00 chris Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/_float.h b/lib/libc/include/arm-openbsd-eabi/machine/_float.h new file mode 100644 index 0000000000..0f250fbbe4 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/_float.h @@ -0,0 +1,3 @@ +/* $OpenBSD: _float.h,v 1.1 2013/09/04 14:38:26 patrick Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/_types.h b/lib/libc/include/arm-openbsd-eabi/machine/_types.h new file mode 100644 index 0000000000..74ac2daf85 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/_types.h @@ -0,0 +1,9 @@ +/* $OpenBSD: _types.h,v 1.1 2013/09/04 14:38:26 patrick Exp $ */ +/* $NetBSD: types.h,v 1.4 2002/02/28 03:17:26 simonb Exp $ */ + +#ifndef _MACHINE__TYPES_H_ +#define _MACHINE__TYPES_H_ + +#include + +#endif /* _MACHINE__TYPES_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/apmvar.h b/lib/libc/include/arm-openbsd-eabi/machine/apmvar.h new file mode 100644 index 0000000000..1919263102 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/apmvar.h @@ -0,0 +1,2 @@ +/* $OpenBSD: apmvar.h,v 1.1 2013/09/04 14:38:26 patrick Exp $ */ +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/asm.h b/lib/libc/include/arm-openbsd-eabi/machine/asm.h new file mode 100644 index 0000000000..358368b17d --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/asm.h @@ -0,0 +1,4 @@ +/* $OpenBSD: asm.h,v 1.1 2013/09/04 14:38:26 patrick Exp $ */ +/* $NetBSD: asm.h,v 1.3 2001/11/25 15:55:54 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/atomic.h b/lib/libc/include/arm-openbsd-eabi/machine/atomic.h new file mode 100644 index 0000000000..ec3b2814a4 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/atomic.h @@ -0,0 +1,10 @@ +/* $OpenBSD: atomic.h,v 1.1 2013/09/04 14:38:26 patrick Exp $ */ + +/* Public Domain */ + +#ifndef _MACHINE_ATOMIC_H_ +#define _MACHINE_ATOMIC_H_ + +#include + +#endif /* _MACHINE_ATOMIC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/bootconfig.h b/lib/libc/include/arm-openbsd-eabi/machine/bootconfig.h new file mode 100644 index 0000000000..c806b7a421 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/bootconfig.h @@ -0,0 +1,70 @@ +/* $OpenBSD: bootconfig.h,v 1.2 2019/05/06 03:34:43 mlarkin Exp $ */ +/* $NetBSD: bootconfig.h,v 1.2 2001/06/21 22:08:28 chris Exp $ */ + +/* + * Copyright (c) 1994 Mark Brinicombe. + * Copyright (c) 1994 Brini. + * All rights reserved. + * + * This code is derived from software written for Brini by Mark Brinicombe + * + * 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 Mark Brinicombe + * for the NetBSD Project. + * 4. The name of the company nor the name of the author may 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 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * boot configuration structures + * + * Created : 12/09/94 + * + * Based on kate/boot/bootconfig.h + */ + +#if defined(_KERNEL) || defined(_STANDALONE) + +typedef struct _PhysMem { + u_int address; + u_int pages; +} PhysMem; + +#define DRAM_BLOCKS 2 +#define MAX_BOOT_STRING 255 + +typedef struct _BootConfig { + PhysMem dram[DRAM_BLOCKS]; + u_int dramblocks; + char bootstring[MAX_BOOT_STRING]; +} BootConfig; + +extern BootConfig bootconfig; + +#endif /* _KERNEL || _STANDALONE */ +#if defined(_KERNEL) +extern char *boot_args; +extern char *boot_file; +#endif /* _KERNEL */ + +/* End of bootconfig.h */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/bus.h b/lib/libc/include/arm-openbsd-eabi/machine/bus.h new file mode 100644 index 0000000000..0a27ab9dd4 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/bus.h @@ -0,0 +1,4 @@ +/* $OpenBSD: bus.h,v 1.1 2013/09/04 14:38:26 patrick Exp $ */ +/* $NetBSD: bus.h,v 1.3 2001/11/25 15:55:55 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/cdefs.h b/lib/libc/include/arm-openbsd-eabi/machine/cdefs.h new file mode 100644 index 0000000000..8ca96399b0 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/cdefs.h @@ -0,0 +1,3 @@ +/* $OpenBSD: cdefs.h,v 1.1 2013/09/04 14:38:26 patrick Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/conf.h b/lib/libc/include/arm-openbsd-eabi/machine/conf.h new file mode 100644 index 0000000000..514e8d0262 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/conf.h @@ -0,0 +1,10 @@ +/* $OpenBSD: conf.h,v 1.2 2025/07/16 03:01:53 jsg Exp $ */ +/* $NetBSD: conf.h,v 1.8 2002/02/10 12:26:03 chris Exp $ */ + +#ifndef _MACHINE_CONF_H_ +#define _MACHINE_CONF_H_ + +#include +#include + +#endif /* _MACHINE_CONF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/cpu.h b/lib/libc/include/arm-openbsd-eabi/machine/cpu.h new file mode 100644 index 0000000000..e9e7ffb3c6 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/cpu.h @@ -0,0 +1,4 @@ +/* $OpenBSD: cpu.h,v 1.1 2013/09/04 14:38:26 patrick Exp $ */ +/* $NetBSD: cpu.h,v 1.3 2001/11/25 15:55:55 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/cpufunc.h b/lib/libc/include/arm-openbsd-eabi/machine/cpufunc.h new file mode 100644 index 0000000000..83545e6386 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/cpufunc.h @@ -0,0 +1,16 @@ +/* $OpenBSD: cpufunc.h,v 1.1 2020/11/29 12:54:36 kettenis Exp $ */ + +/* Public Domain */ + +#ifndef _MACHINE_CPUFUNC_H_ +#define _MACHINE_CPUFUNC_H_ + +#include + +#ifdef _KERNEL + +register_t smc_call(register_t, register_t, register_t, register_t); + +#endif /* _KERNEL */ + +#endif /* _MACHINE_CPUFUNC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/db_machdep.h b/lib/libc/include/arm-openbsd-eabi/machine/db_machdep.h new file mode 100644 index 0000000000..0142ddba5e --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/db_machdep.h @@ -0,0 +1,4 @@ +/* $OpenBSD: db_machdep.h,v 1.1 2013/09/04 14:38:26 patrick Exp $ */ +/* $NetBSD: db_machdep.h,v 1.3 2001/11/25 15:55:55 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/disklabel.h b/lib/libc/include/arm-openbsd-eabi/machine/disklabel.h new file mode 100644 index 0000000000..bb72317025 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/disklabel.h @@ -0,0 +1,3 @@ +/* $OpenBSD: disklabel.h,v 1.1 2013/09/04 14:38:27 patrick Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/elf.h b/lib/libc/include/arm-openbsd-eabi/machine/elf.h new file mode 100644 index 0000000000..adbf226bf2 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/elf.h @@ -0,0 +1,3 @@ +/* $OpenBSD: elf.h,v 1.1 2024/07/14 19:33:59 miod Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/endian.h b/lib/libc/include/arm-openbsd-eabi/machine/endian.h new file mode 100644 index 0000000000..a38e0819d6 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/endian.h @@ -0,0 +1,4 @@ +/* $OpenBSD: endian.h,v 1.1 2013/09/04 14:38:27 patrick Exp $ */ +/* $NetBSD: endian.h,v 1.3 2001/11/25 15:55:56 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/exec.h b/lib/libc/include/arm-openbsd-eabi/machine/exec.h new file mode 100644 index 0000000000..6bb7f50e7e --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/exec.h @@ -0,0 +1,3 @@ +/* $OpenBSD: exec.h,v 1.1 2013/09/04 14:38:27 patrick Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/fdt.h b/lib/libc/include/arm-openbsd-eabi/machine/fdt.h new file mode 100644 index 0000000000..386a6d31cf --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/fdt.h @@ -0,0 +1,3 @@ +/* $OpenBSD: fdt.h,v 1.1 2016/05/02 08:15:55 patrick Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/fenv.h b/lib/libc/include/arm-openbsd-eabi/machine/fenv.h new file mode 100644 index 0000000000..1f648e1005 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/fenv.h @@ -0,0 +1,3 @@ +/* $OpenBSD: fenv.h,v 1.1 2013/09/04 14:38:27 patrick Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/frame.h b/lib/libc/include/arm-openbsd-eabi/machine/frame.h new file mode 100644 index 0000000000..9ca41597fe --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/frame.h @@ -0,0 +1,4 @@ +/* $OpenBSD: frame.h,v 1.1 2013/09/04 14:38:27 patrick Exp $ */ +/* $NetBSD: frame.h,v 1.1 2001/06/08 22:23:00 chris Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/ieee.h b/lib/libc/include/arm-openbsd-eabi/machine/ieee.h new file mode 100644 index 0000000000..cbd95dc298 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/ieee.h @@ -0,0 +1,4 @@ +/* $OpenBSD: ieee.h,v 1.1 2013/09/04 14:38:27 patrick Exp $ */ +/* $NetBSD: ieee.h,v 1.3 2001/11/25 15:55:56 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/ieeefp.h b/lib/libc/include/arm-openbsd-eabi/machine/ieeefp.h new file mode 100644 index 0000000000..f4c270c690 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/ieeefp.h @@ -0,0 +1,4 @@ +/* $OpenBSD: ieeefp.h,v 1.1 2013/09/04 14:38:27 patrick Exp $ */ +/* $NetBSD: ieeefp.h,v 1.3 2001/11/25 15:55:56 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/intr.h b/lib/libc/include/arm-openbsd-eabi/machine/intr.h new file mode 100644 index 0000000000..0f597a3f15 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/intr.h @@ -0,0 +1,229 @@ +/* $OpenBSD: intr.h,v 1.16 2025/05/10 10:11:02 visa Exp $ */ +/* $NetBSD: intr.h,v 1.12 2003/06/16 20:00:59 thorpej Exp $ */ + +/* + * Copyright (c) 2001, 2003 Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Jason R. Thorpe for Wasabi Systems, Inc. + * + * 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 for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC + * 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_INTR_H_ +#define _MACHINE_INTR_H_ + +#ifdef _KERNEL + +/* Interrupt priority `levels'; not mutually exclusive. */ +#define IPL_NONE 0 /* nothing */ +#define IPL_SOFTCLOCK 2 /* soft clock interrupts */ +#define IPL_SOFTNET 3 /* soft network interrupts */ +#define IPL_SOFTTTY 4 /* soft terminal interrupts */ +#define IPL_BIO 5 /* block I/O */ +#define IPL_NET 6 /* network */ +#define IPL_TTY 7 /* terminal */ +#define IPL_VM 8 /* memory allocation */ +#define IPL_AUDIO 9 /* audio */ +#define IPL_CLOCK 10 /* clock */ +#define IPL_SCHED IPL_CLOCK +#define IPL_STATCLOCK IPL_CLOCK +#define IPL_HIGH 11 /* everything */ +#define IPL_IPI 12 /* interprocessor interrupt */ +#define NIPL 13 /* number of levels */ + +#define IPL_MPFLOOR IPL_TTY +/* Interrupt priority 'flags'. */ +#define IPL_IRQMASK 0xf /* priority only */ +#define IPL_FLAGMASK 0xf00 /* flags only*/ +#define IPL_MPSAFE 0x100 /* 'mpsafe' interrupt, no kernel lock */ + +/* Interrupt sharing types. */ +#define IST_NONE 0 /* none */ +#define IST_PULSE 1 /* pulsed */ +#define IST_EDGE 2 /* edge-triggered */ +#define IST_LEVEL 3 /* level-triggered */ + +#define IST_LEVEL_LOW IST_LEVEL +#define IST_LEVEL_HIGH 4 +#define IST_EDGE_FALLING IST_EDGE +#define IST_EDGE_RISING 5 +#define IST_EDGE_BOTH 6 + +#define __USE_MI_SOFTINTR + +#include + +#ifndef _LOCORE +#include + +struct cpu_info; + +int splraise(int); +int spllower(int); +void splx(int); + +void arm_do_pending_intr(int); +void arm_set_intr_handler(int (*raise)(int), int (*lower)(int), + void (*x)(int), void (*setipl)(int), + void *(*intr_establish)(int irqno, int level, struct cpu_info *ci, + int (*func)(void *), void *cookie, char *name), + void (*intr_disestablish)(void *cookie), + const char *(*intr_string)(void *cookie), + void (*intr_handle)(void *)); + +struct arm_intr_func { + int (*raise)(int); + int (*lower)(int); + void (*x)(int); + void (*setipl)(int); + void *(*intr_establish)(int irqno, int level, struct cpu_info *, + int (*func)(void *), void *cookie, char *name); + void (*intr_disestablish)(void *cookie); + const char *(*intr_string)(void *cookie); +}; + +extern struct arm_intr_func arm_intr_func; + +#define splraise(cpl) (arm_intr_func.raise(cpl)) +#define _splraise(cpl) (arm_intr_func.raise(cpl)) +#define spllower(cpl) (arm_intr_func.lower(cpl)) +#define splx(cpl) (arm_intr_func.x(cpl)) + +#define splhigh() splraise(IPL_HIGH) +#define splsoftclock() splraise(IPL_SOFTCLOCK) +#define splsoftnet() splraise(IPL_SOFTNET) +#define splbio() splraise(IPL_BIO) +#define splnet() splraise(IPL_NET) +#define spltty() splraise(IPL_TTY) +#define splvm() splraise(IPL_VM) +#define splaudio() splraise(IPL_AUDIO) +#define splclock() splraise(IPL_CLOCK) +#define splstatclock() splraise(IPL_STATCLOCK) + +#define spl0() spllower(IPL_NONE) + +#define splsched() splhigh() + +void intr_barrier(void *); + +void arm_init_smask(void); /* XXX */ +extern uint32_t arm_smask[NIPL]; +void arm_setsoftintr(int si); + +#define softintr arm_setsoftintr + +void *arm_intr_establish(int irqno, int level, int (*func)(void *), + void *cookie, char *name); +void arm_intr_disestablish(void *cookie); +const char *arm_intr_string(void *cookie); + +/* XXX - this is probably the wrong location for this */ +void arm_clock_register(void (*)(void), void (*)(u_int), void (*)(int), + void (*)(void)); + +struct interrupt_controller { + int ic_node; + void *ic_cookie; + void *(*ic_establish)(void *, int *, int, struct cpu_info *, + int (*)(void *), void *, char *); + void *(*ic_establish_msi)(void *, uint64_t *, uint64_t *, int, + struct cpu_info *, int (*)(void *), void *, char *); + void (*ic_disestablish)(void *); + void (*ic_enable)(void *); + void (*ic_disable)(void *); + void (*ic_route)(void *, int, struct cpu_info *); + void (*ic_cpu_enable)(void); + void (*ic_barrier)(void *); + + LIST_ENTRY(interrupt_controller) ic_list; + uint32_t ic_phandle; + uint32_t ic_cells; +}; + +void arm_intr_init_fdt(void); +void arm_intr_register_fdt(struct interrupt_controller *); +void *arm_intr_establish_fdt(int, int, int (*)(void *), + void *, char *); +void *arm_intr_establish_fdt_cpu(int, int, struct cpu_info *, + int (*)(void *), void *, char *); +void *arm_intr_establish_fdt_idx(int, int, int, int (*)(void *), + void *, char *); +void *arm_intr_establish_fdt_idx_cpu(int, int, int, struct cpu_info *, + int (*)(void *), void *, char *); +void *arm_intr_establish_fdt_imap(int, int *, int, int, int (*)(void *), + void *, char *); +void *arm_intr_establish_fdt_imap_cpu(int, int *, int, int, + struct cpu_info *, int (*)(void *), void *, char *); +void *arm_intr_establish_fdt_msi(int, uint64_t *, uint64_t *, int, + int (*)(void *), void *, char *); +void *arm_intr_establish_fdt_msi_cpu(int, uint64_t *, uint64_t *, int, + struct cpu_info *, int (*)(void *), void *, char *); +void arm_intr_disestablish_fdt(void *); +void arm_intr_enable(void *); +void arm_intr_disable(void *); +void arm_intr_route(void *, int, struct cpu_info *); +void arm_intr_cpu_enable(void); + +void *arm_intr_parent_establish_fdt(void *, int *, int, + struct cpu_info *ci, int (*)(void *), void *, char *); +void arm_intr_parent_disestablish_fdt(void *); + +void arm_send_ipi(struct cpu_info *, int); +extern void (*intr_send_ipi_func)(struct cpu_info *, int); + +#define ARM_IPI_NOP 0 +#define ARM_IPI_DDB 1 + +#ifdef DIAGNOSTIC +/* + * Although this function is implemented in MI code, it must be in this MD + * header because we don't want this header to include MI includes. + */ +void splassert_fail(int, int, const char *); +extern int splassert_ctl; +void arm_splassert_check(int, const char *); +#define splassert(__wantipl) do { \ + if (splassert_ctl > 0) { \ + arm_splassert_check(__wantipl, __func__); \ + } \ +} while (0) +#define splsoftassert(wantipl) splassert(wantipl) +#else +#define splassert(wantipl) do { /* nothing */ } while (0) +#define splsoftassert(wantipl) do { /* nothing */ } while (0) +#endif + +#endif /* ! _LOCORE */ + +#define ARM_IRQ_HANDLER arm_intr + +#endif /* _KERNEL */ + +#endif /* _MACHINE_INTR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/limits.h b/lib/libc/include/arm-openbsd-eabi/machine/limits.h new file mode 100644 index 0000000000..59a9c2820a --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/limits.h @@ -0,0 +1,4 @@ +/* $OpenBSD: limits.h,v 1.1 2013/09/04 14:38:27 patrick Exp $ */ +/* $NetBSD: limits.h,v 1.3 2001/11/25 15:55:57 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/loadfile_machdep.h b/lib/libc/include/arm-openbsd-eabi/machine/loadfile_machdep.h new file mode 100644 index 0000000000..d4af12ff27 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/loadfile_machdep.h @@ -0,0 +1,53 @@ +/* $OpenBSD: loadfile_machdep.h,v 1.5 2019/04/10 04:17:34 deraadt Exp $ */ +/* $NetBSD: loadfile_machdep.h,v 1.1 1999/04/29 03:17:12 tsubai Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * 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. + */ + +#define BOOT_ELF +#define ELFSIZE 32 + +#define LOAD_KERNEL LOAD_ALL +#define COUNT_KERNEL COUNT_ALL + +extern u_long efi_loadaddr; +#define LOADADDR(a) (((((u_long)(a)) + offset)&0xfffffff) + \ + efi_loadaddr) +#define ALIGNENTRY(a) ((u_long)(a)) +#define READ(f, b, c) read((f), (void *)LOADADDR(b), (c)) +#define BCOPY(s, d, c) memcpy((void *)LOADADDR(d), (void *)(s), (c)) +#define BZERO(d, c) memset((void *)LOADADDR(d), 0, (c)) +#define WARN(a) (void)(printf a, \ + printf((errno ? ": %s\n" : "\n"), \ + strerror(errno))) +#define PROGRESS(a) (void) printf a +#define ALLOC(a) alloc(a) +#define FREE(a, b) free(a, b) + +void run_loadfile(uint64_t *, int); \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/machine_reg.h b/lib/libc/include/arm-openbsd-eabi/machine/machine_reg.h new file mode 100644 index 0000000000..ef87538012 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/machine_reg.h @@ -0,0 +1,57 @@ +/* $OpenBSD: machine_reg.h,v 1.3 2019/05/06 03:34:43 mlarkin Exp $ */ + +/* + * Copyright (c) 2002, 2003 Genetec Corporation. All rights reserved. + * Written by Hiroyuki Bessho for Genetec Corporation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of Genetec Corporation may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``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 GENETEC CORPORATION + * 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_REG_H +#define _MACHINE_REG_H + +/* + * Logical mapping for onboard/integrated peripherals + */ +#define MACHINE_IO_AREA_VBASE 0xfd000000 +#define MACHINE_GPIO_VBASE 0xfd000000 +#define MACHINE_CLKMAN_VBASE 0xfd100000 +#define MACHINE_INTCTL_VBASE 0xfd200000 +#define MACHINE_AGPIO_VBASE 0xfd300000 +#define MACHINE_VBASE_FREE 0xfd400000 +/* FFUART and/or BTUART are mapped to this area when + used for console */ + +#define ioreg_read(a) (*(volatile unsigned *)(a)) +#define ioreg_write(a,v) (*(volatile unsigned *)(a)=(v)) + +#define ioreg16_read(a) (*(volatile uint16_t *)(a)) +#define ioreg16_write(a,v) (*(volatile uint16_t *)(a)=(v)) + +#define ioreg8_read(a) (*(volatile uint8_t *)(a)) +#define ioreg8_write(a,v) (*(volatile uint8_t *)(a)=(v)) + +#endif /* _MACHINE_REG_H */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/mplock.h b/lib/libc/include/arm-openbsd-eabi/machine/mplock.h new file mode 100644 index 0000000000..d4ecdcd49f --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/mplock.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mplock.h,v 1.1 2018/08/06 18:39:13 kettenis Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/mutex.h b/lib/libc/include/arm-openbsd-eabi/machine/mutex.h new file mode 100644 index 0000000000..1af94436f5 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/mutex.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mutex.h,v 1.1 2013/09/04 14:38:28 patrick Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/openpromio.h b/lib/libc/include/arm-openbsd-eabi/machine/openpromio.h new file mode 100644 index 0000000000..39f68f71a5 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/openpromio.h @@ -0,0 +1,3 @@ +/* $OpenBSD: openpromio.h,v 1.1 2016/05/21 21:24:36 kettenis Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/param.h b/lib/libc/include/arm-openbsd-eabi/machine/param.h new file mode 100644 index 0000000000..72d453ef46 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/param.h @@ -0,0 +1,51 @@ +/* $OpenBSD: param.h,v 1.3 2018/08/09 12:19:32 patrick Exp $ */ + +/* + * Copyright (c) 1994,1995 Mark Brinicombe. + * 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 the RiscBSD team. + * 4. The name "RiscBSD" nor the name of the author may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY RISCBSD ``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 RISCBSD 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_ + +#include + +#define _MACHINE armv7 +#define MACHINE "armv7" + +#ifndef MSGBUFSIZE +#define MSGBUFSIZE (8 * PAGE_SIZE) +#endif + +#ifdef _KERNEL +#define __HAVE_FDT +#endif + +#endif /* _MACHINE_PARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/pcb.h b/lib/libc/include/arm-openbsd-eabi/machine/pcb.h new file mode 100644 index 0000000000..d2b73c6db5 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/pcb.h @@ -0,0 +1,4 @@ +/* $OpenBSD: pcb.h,v 1.1 2013/09/04 14:38:28 patrick Exp $ */ +/* $NetBSD: pcb.h,v 1.3 2001/11/25 15:55:57 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/pci_machdep.h b/lib/libc/include/arm-openbsd-eabi/machine/pci_machdep.h new file mode 100644 index 0000000000..54442a8005 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/pci_machdep.h @@ -0,0 +1,3 @@ +/* $OpenBSD: pci_machdep.h,v 1.1 2018/07/09 09:53:06 patrick Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/pmap.h b/lib/libc/include/arm-openbsd-eabi/machine/pmap.h new file mode 100644 index 0000000000..bc631302ef --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/pmap.h @@ -0,0 +1,4 @@ +/* $OpenBSD: pmap.h,v 1.1 2013/09/04 14:38:28 patrick Exp $ */ +/* $NetBSD: pmap.h,v 1.2 2001/11/23 17:29:01 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/proc.h b/lib/libc/include/arm-openbsd-eabi/machine/proc.h new file mode 100644 index 0000000000..d92b1e2712 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/proc.h @@ -0,0 +1,4 @@ +/* $OpenBSD: proc.h,v 1.1 2013/09/04 14:38:28 patrick Exp $ */ +/* $NetBSD: proc.h,v 1.3 2001/11/25 15:55:57 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/profile.h b/lib/libc/include/arm-openbsd-eabi/machine/profile.h new file mode 100644 index 0000000000..72aa69fcf3 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/profile.h @@ -0,0 +1,4 @@ +/* $OpenBSD: profile.h,v 1.1 2013/09/04 14:38:28 patrick Exp $ */ +/* $NetBSD: profile.h,v 1.3 2001/11/25 15:55:57 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/ptrace.h b/lib/libc/include/arm-openbsd-eabi/machine/ptrace.h new file mode 100644 index 0000000000..fda3e95619 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/ptrace.h @@ -0,0 +1,4 @@ +/* $OpenBSD: ptrace.h,v 1.1 2013/09/04 14:38:28 patrick Exp $ */ +/* $NetBSD: ptrace.h,v 1.3 2001/11/25 15:55:58 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/reg.h b/lib/libc/include/arm-openbsd-eabi/machine/reg.h new file mode 100644 index 0000000000..8bee9a0ffc --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/reg.h @@ -0,0 +1,4 @@ +/* $OpenBSD: reg.h,v 1.1 2013/09/04 14:38:28 patrick Exp $ */ +/* $NetBSD: reg.h,v 1.3 2001/11/25 15:55:58 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/reloc.h b/lib/libc/include/arm-openbsd-eabi/machine/reloc.h new file mode 100644 index 0000000000..d4311b2f14 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/reloc.h @@ -0,0 +1,2 @@ +/* $OpenBSD: reloc.h,v 1.1 2013/09/04 14:38:29 patrick Exp $ */ +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/setjmp.h b/lib/libc/include/arm-openbsd-eabi/machine/setjmp.h new file mode 100644 index 0000000000..5125b28bd3 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/setjmp.h @@ -0,0 +1,4 @@ +/* $OpenBSD: setjmp.h,v 1.1 2013/09/04 14:38:29 patrick Exp $ */ +/* $NetBSD: setjmp.h,v 1.3 2001/11/25 15:55:58 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/signal.h b/lib/libc/include/arm-openbsd-eabi/machine/signal.h new file mode 100644 index 0000000000..0fc0632217 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/signal.h @@ -0,0 +1,4 @@ +/* $OpenBSD: signal.h,v 1.1 2013/09/04 14:38:29 patrick Exp $ */ +/* $NetBSD: signal.h,v 1.3 2001/11/25 15:55:58 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/simplebusvar.h b/lib/libc/include/arm-openbsd-eabi/machine/simplebusvar.h new file mode 100644 index 0000000000..0620d80449 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/simplebusvar.h @@ -0,0 +1,3 @@ +/* $OpenBSD: simplebusvar.h,v 1.1 2023/09/22 01:10:43 jsg Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/spinlock.h b/lib/libc/include/arm-openbsd-eabi/machine/spinlock.h new file mode 100644 index 0000000000..675d503f43 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/spinlock.h @@ -0,0 +1,3 @@ +/* $OpenBSD: spinlock.h,v 1.2 2017/01/05 16:52:42 patrick Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/sysarch.h b/lib/libc/include/arm-openbsd-eabi/machine/sysarch.h new file mode 100644 index 0000000000..4a65320d70 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/sysarch.h @@ -0,0 +1,4 @@ +/* $OpenBSD: sysarch.h,v 1.1 2013/09/04 14:38:29 patrick Exp $ */ +/* $NetBSD: sysarch.h,v 1.3 2001/11/25 15:55:58 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/tcb.h b/lib/libc/include/arm-openbsd-eabi/machine/tcb.h new file mode 100644 index 0000000000..a5a3f7799f --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/tcb.h @@ -0,0 +1,3 @@ +/* $OpenBSD: tcb.h,v 1.1 2013/09/04 14:38:29 patrick Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/trap.h b/lib/libc/include/arm-openbsd-eabi/machine/trap.h new file mode 100644 index 0000000000..2904fcc7b5 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/trap.h @@ -0,0 +1,4 @@ +/* $OpenBSD: trap.h,v 1.1 2013/09/04 14:38:29 patrick Exp $ */ +/* $NetBSD: trap.h,v 1.3 2001/11/25 15:55:58 thorpej Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/arm-openbsd-eabi/machine/vmparam.h b/lib/libc/include/arm-openbsd-eabi/machine/vmparam.h new file mode 100644 index 0000000000..fb4d068a38 --- /dev/null +++ b/lib/libc/include/arm-openbsd-eabi/machine/vmparam.h @@ -0,0 +1,98 @@ +/* $OpenBSD: vmparam.h,v 1.8 2023/11/12 16:37:28 kettenis Exp $ */ +/* $NetBSD: vmparam.h,v 1.23 2003/05/22 05:47:07 thorpej 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. + */ + +#ifndef _MACHINE_VMPARAM_H_ +#define _MACHINE_VMPARAM_H_ + +#define ARM_KERNEL_BASE 0xc0000000U + +/* Allow armv7 to have bigger limits than generic arm, allow user to override */ +#ifndef MAXDSIZ +#define MAXDSIZ (2UL*1024*1024*1024) /* max data size */ +#endif +#ifndef BRKSIZ +#define BRKSIZ MAXDSIZ /* heap gap size */ +#endif +#ifndef DFLSSIZ +#define DFLSSIZ (4*1024*1024) /* initial stack size limit */ +#endif +#ifndef MAXSSIZ +#define MAXSSIZ (32*1024*1024) /* max stack size */ +#endif + +#include + +#ifdef _KERNEL +/* + * Address space constants + */ + +/* + * The line between user space and kernel space + * Mappings >= KERNEL_BASE are constant across all processes + */ +#define KERNEL_BASE ARM_KERNEL_BASE + +#define VM_KERNEL_SPACE_SIZE 0x20000000 + +/* + * Override the default pager_map size, there's not enough KVA. + */ +#define PAGER_MAP_SIZE (4 * 1024 * 1024) + +/* + * Size of User Raw I/O map + */ + +#define USRIOSIZE 300 + +/* virtual sizes (bytes) for various kernel submaps */ + +#define VM_PHYS_SIZE (USRIOSIZE*PAGE_SIZE) + +/* + * max number of non-contig chunks of physical RAM you can have + */ + +#define VM_PHYSSEG_MAX 32 +#define VM_PHYSSEG_STRAT VM_PSTRAT_BSEARCH + +/* + * this indicates that we can't add RAM to the VM system after the + * vm system is init'd. + */ + +#define VM_PHYSSEG_NOADD + +#endif /* _KERNEL */ + +#endif /* _MACHINE_VMPARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/a.out.h b/lib/libc/include/generic-openbsd/a.out.h new file mode 100644 index 0000000000..2b6574f4e6 --- /dev/null +++ b/lib/libc/include/generic-openbsd/a.out.h @@ -0,0 +1,156 @@ +/* $OpenBSD: a.out.h,v 1.4 2024/10/16 18:47:48 miod Exp $ */ +/* $NetBSD: a.out.h,v 1.15 1994/10/26 00:55:42 cgd Exp $ */ + +/*- + * Copyright (c) 1993 Theo de Raadt + * Copyright (c) 1991 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. + * + * @(#)a.out.h 5.6 (Berkeley) 4/30/91 + */ + +#ifndef _AOUT_H_ +#define _AOUT_H_ + +/* + * Legacy a.out structures and defines. + */ + +/* + * Header prepended to each a.out file. + * only manipulate the a_midmag field via the + * N_SETMAGIC/N_GET{MAGIC,MID,FLAG} macros below. + */ +struct exec { + u_int32_t a_midmag; /* htonl(flags<<26|mid<<16|magic) */ + u_int32_t a_text; /* text segment size */ + u_int32_t a_data; /* initialized data size */ + u_int32_t a_bss; /* uninitialized data size */ + u_int32_t a_syms; /* symbol table size */ + u_int32_t a_entry; /* entry point */ + u_int32_t a_trsize; /* text relocation size */ + u_int32_t a_drsize; /* data relocation size */ +}; + +/* a_magic */ +#define OMAGIC 0407 /* old impure format */ +#define NMAGIC 0410 /* read-only text */ +#define ZMAGIC 0413 /* demand load format */ +#define QMAGIC 0314 /* "compact" demand load format; deprecated */ + +/* + * a_flags + */ +#define EX_DYNAMIC 0x20 +#define EX_PIC 0x10 +#define EX_DPMASK 0x30 +/* + * Interpretation of the (a_flags & EX_DPMASK) bits: + * + * 00 traditional executable or object file + * 01 object file contains PIC code (set by `as -k') + * 10 dynamic executable + * 11 position independent executable image + * (eg. a shared library) + * + */ + +/* + * The a.out structure's a_midmag field is a network-byteorder encoding + * of this int + * FFFFFFmmmmmmmmmmMMMMMMMMMMMMMMMM + * Where `F' is 6 bits of flag like EX_DYNAMIC, + * `m' is 10 bits of machine-id like MID_I386, and + * `M' is 16 bits worth of magic number, ie. ZMAGIC. + * The macros below will set/get the needed fields. + */ +#define N_GETMAGIC(ex) \ + ( (((ex).a_midmag)&0xffff0000) ? (ntohl(((ex).a_midmag))&0xffff) : ((ex).a_midmag)) +#define N_GETMAGIC2(ex) \ + ( (((ex).a_midmag)&0xffff0000) ? (ntohl(((ex).a_midmag))&0xffff) : \ + (((ex).a_midmag) | 0x10000) ) +#define N_GETMID(ex) \ + ( (((ex).a_midmag)&0xffff0000) ? ((ntohl(((ex).a_midmag))>>16)&0x03ff) : MID_ZERO ) +#define N_GETFLAG(ex) \ + ( (((ex).a_midmag)&0xffff0000) ? ((ntohl(((ex).a_midmag))>>26)&0x3f) : 0 ) +#define N_SETMAGIC(ex,mag,mid,flag) \ + ( (ex).a_midmag = htonl( (((flag)&0x3f)<<26) | (((mid)&0x03ff)<<16) | \ + (((mag)&0xffff)) ) ) + +#define N_ALIGN(ex,x) \ + (N_GETMAGIC(ex) == ZMAGIC || N_GETMAGIC(ex) == QMAGIC ? \ + ((x) + __LDPGSZ - 1) & ~(__LDPGSZ - 1) : (x)) + +/* Valid magic number check. */ +#define N_BADMAG(ex) \ + (N_GETMAGIC(ex) != NMAGIC && N_GETMAGIC(ex) != OMAGIC && \ + N_GETMAGIC(ex) != ZMAGIC && N_GETMAGIC(ex) != QMAGIC) + +/* Address of the bottom of the text segment. */ +#define N_TXTADDR(ex) (N_GETMAGIC2(ex) == (ZMAGIC|0x10000) ? 0 : __LDPGSZ) + +/* Address of the bottom of the data segment. */ +#define N_DATADDR(ex) \ + (N_GETMAGIC(ex) == OMAGIC ? N_TXTADDR(ex) + (ex).a_text : \ + (N_TXTADDR(ex) + (ex).a_text + __LDPGSZ - 1) & ~(__LDPGSZ - 1)) + +/* Address of the bottom of the bss segment. */ +#define N_BSSADDR(ex) \ + (N_DATADDR(ex) + (ex).a_data) + +/* Text segment offset. */ +#define N_TXTOFF(ex) \ + ( N_GETMAGIC2(ex)==ZMAGIC || N_GETMAGIC2(ex)==(QMAGIC|0x10000) ? \ + 0 : (N_GETMAGIC2(ex)==(ZMAGIC|0x10000) ? __LDPGSZ : \ + sizeof(struct exec)) ) + +/* Data segment offset. */ +#define N_DATOFF(ex) \ + N_ALIGN(ex, N_TXTOFF(ex) + (ex).a_text) + +/* Text relocation table offset. */ +#define N_TRELOFF(ex) \ + (N_DATOFF(ex) + (ex).a_data) + +/* Data relocation table offset. */ +#define N_DRELOFF(ex) \ + (N_TRELOFF(ex) + (ex).a_trsize) + +/* Symbol table offset. */ +#define N_SYMOFF(ex) \ + (N_DRELOFF(ex) + (ex).a_drsize) + +/* String table offset. */ +#define N_STROFF(ex) \ + (N_SYMOFF(ex) + (ex).a_syms) + +#include + +#define _AOUT_INCLUDE_ +#include + +#endif /* !_AOUT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ar.h b/lib/libc/include/generic-openbsd/ar.h new file mode 100644 index 0000000000..f841ae8872 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ar.h @@ -0,0 +1,66 @@ +/* $OpenBSD: ar.h,v 1.3 2003/06/02 19:34:12 millert Exp $ */ +/* $NetBSD: ar.h,v 1.4 1994/10/26 00:55:43 cgd Exp $ */ + +/*- + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * This code is derived from software contributed to Berkeley by + * Hugh Smith at The University of Guelph. + * + * 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. + * + * @(#)ar.h 8.2 (Berkeley) 1/21/94 + */ + +#ifndef _AR_H_ +#define _AR_H_ + +/* Pre-4BSD archives had these magic numbers in them. */ +#define OARMAG1 0177555 +#define OARMAG2 0177545 + +#define ARMAG "!\n" /* ar "magic number" */ +#define SARMAG 8 /* strlen(ARMAG); */ + +#define AR_EFMT1 "#1/" /* extended format #1 */ + +struct ar_hdr { + char ar_name[16]; /* name */ + char ar_date[12]; /* modification time */ + char ar_uid[6]; /* user id */ + char ar_gid[6]; /* group id */ + char ar_mode[8]; /* octal file permissions */ + char ar_size[10]; /* size in bytes */ +#define ARFMAG "`\n" + char ar_fmag[2]; /* consistency check */ +}; + +#endif /* !_AR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/arpa/ftp.h b/lib/libc/include/generic-openbsd/arpa/ftp.h new file mode 100644 index 0000000000..49a3a72ca2 --- /dev/null +++ b/lib/libc/include/generic-openbsd/arpa/ftp.h @@ -0,0 +1,108 @@ +/* $OpenBSD: ftp.h,v 1.3 2003/06/02 19:34:12 millert Exp $ */ +/* $NetBSD: ftp.h,v 1.3 1994/10/26 00:56:43 cgd Exp $ */ + +/* + * Copyright (c) 1983, 1989 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. + * + * @(#)ftp.h 5.6 (Berkeley) 4/3/91 + */ + +#ifndef _FTP_H_ +#define _FTP_H_ + +/* Definitions for FTP; see RFC-765. */ + +/* + * Reply codes. + */ +#define PRELIM 1 /* positive preliminary */ +#define COMPLETE 2 /* positive completion */ +#define CONTINUE 3 /* positive intermediate */ +#define TRANSIENT 4 /* transient negative completion */ +#define ERROR 5 /* permanent negative completion */ + +/* + * Type codes + */ +#define TYPE_A 1 /* ASCII */ +#define TYPE_E 2 /* EBCDIC */ +#define TYPE_I 3 /* image */ +#define TYPE_L 4 /* local byte size */ + +#ifdef FTP_NAMES +char *typenames[] = {"0", "ASCII", "EBCDIC", "Image", "Local" }; +#endif + +/* + * Form codes + */ +#define FORM_N 1 /* non-print */ +#define FORM_T 2 /* telnet format effectors */ +#define FORM_C 3 /* carriage control (ASA) */ +#ifdef FTP_NAMES +char *formnames[] = {"0", "Nonprint", "Telnet", "Carriage-control" }; +#endif + +/* + * Structure codes + */ +#define STRU_F 1 /* file (no record structure) */ +#define STRU_R 2 /* record structure */ +#define STRU_P 3 /* page structure */ +#ifdef FTP_NAMES +char *strunames[] = {"0", "File", "Record", "Page" }; +#endif + +/* + * Mode types + */ +#define MODE_S 1 /* stream */ +#define MODE_B 2 /* block */ +#define MODE_C 3 /* compressed */ +#ifdef FTP_NAMES +char *modenames[] = {"0", "Stream", "Block", "Compressed" }; +#endif + +/* + * Record Tokens + */ +#define REC_ESC '\377' /* Record-mode Escape */ +#define REC_EOR '\001' /* Record-mode End-of-Record */ +#define REC_EOF '\002' /* Record-mode End-of-File */ + +/* + * Block Header + */ +#define BLK_EOR 0x80 /* Block is End-of-Record */ +#define BLK_EOF 0x40 /* Block is End-of-File */ +#define BLK_ERRORS 0x20 /* Block is suspected of containing errors */ +#define BLK_RESTART 0x10 /* Block is Restart Marker */ + +#define BLK_BYTECOUNT 2 /* Bytes in this block */ + +#endif /* !_FTP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/arpa/inet.h b/lib/libc/include/generic-openbsd/arpa/inet.h new file mode 100644 index 0000000000..85e665b8f7 --- /dev/null +++ b/lib/libc/include/generic-openbsd/arpa/inet.h @@ -0,0 +1,147 @@ +/* $OpenBSD: inet.h,v 1.21 2017/02/04 19:16:25 guenther Exp $ */ + +/* + * ++Copyright++ 1983, 1993 + * - + * Copyright (c) 1983, 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. + * - + * Portions Copyright (c) 1993 by Digital Equipment Corporation. + * + * 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, and that + * the name of Digital Equipment Corporation not be used in advertising or + * publicity pertaining to distribution of the document or software without + * specific, written prior permission. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT + * CORPORATION 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. + * - + * --Copyright-- + */ + +/* + * @(#)inet.h 8.1 (Berkeley) 6/2/93 + * $From: inet.h,v 8.6 1996/08/08 06:54:29 vixie Exp $ + */ + +#ifndef _INET_H_ +#define _INET_H_ + +/* External definitions for functions in inet(3) */ + +#include +#include + +#ifndef htons +#define htons(x) __htobe16(x) +#define htonl(x) __htobe32(x) +#define ntohs(x) __htobe16(x) +#define ntohl(x) __htobe32(x) +#endif + +#ifndef _UINT16_T_DEFINED_ +#define _UINT16_T_DEFINED_ +typedef __uint16_t uint16_t; +#endif + +#ifndef _UINT32_T_DEFINED_ +#define _UINT32_T_DEFINED_ +typedef __uint32_t uint32_t; +#endif + +#ifndef _SOCKLEN_T_DEFINED_ +#define _SOCKLEN_T_DEFINED_ +typedef __socklen_t socklen_t; /* length type for network syscalls */ +#endif + +#ifndef _IN_TYPES_DEFINED_ +#define _IN_TYPES_DEFINED_ +typedef __in_addr_t in_addr_t; /* base type for internet address */ +typedef __in_port_t in_port_t; /* IP port type */ +#endif + +/* + * Buffer lengths for strings containing printable IP addresses + */ +#ifndef INET_ADDRSTRLEN +#define INET_ADDRSTRLEN 16 +#endif +#ifndef INET6_ADDRSTRLEN +#define INET6_ADDRSTRLEN 46 +#endif + +#ifndef _IN_ADDR_DECLARED +#define _IN_ADDR_DECLARED +/* + * IP Version 4 Internet address (a structure for historical reasons) + */ +struct in_addr { + in_addr_t s_addr; +}; +#endif + + +#if __BSD_VISIBLE +/* need this for the non-standard stuff */ +#ifndef _SIZE_T_DEFINED_ +#define _SIZE_T_DEFINED_ +typedef __size_t size_t; +#endif +#endif + + +__BEGIN_DECLS +in_addr_t inet_addr(const char *); +char *inet_ntoa(struct in_addr); +const char *inet_ntop(int, const void *__restrict, char *__restrict, + socklen_t) __attribute__ ((__bounded__(__string__,3,4))); +int inet_pton(int, const char *__restrict, void *__restrict); + +#if __BSD_VISIBLE +int inet_aton(const char *, struct in_addr *); +in_addr_t inet_lnaof(struct in_addr); +struct in_addr inet_makeaddr(in_addr_t , in_addr_t); +char * inet_neta(in_addr_t, char *, size_t) + __attribute__((__bounded__(__string__,2,3))); +in_addr_t inet_netof(struct in_addr); +in_addr_t inet_network(const char *); +char *inet_net_ntop(int, const void *, int, char *, size_t) + __attribute__((__bounded__(__string__,4,5))); +int inet_net_pton(int, const char *, void *, size_t) + __attribute__((__bounded__(__string__,3,4))); +#endif /* __BSD_VISIBLE */ +__END_DECLS + +#endif /* !_INET_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/arpa/nameser.h b/lib/libc/include/generic-openbsd/arpa/nameser.h new file mode 100644 index 0000000000..6951642d6b --- /dev/null +++ b/lib/libc/include/generic-openbsd/arpa/nameser.h @@ -0,0 +1,369 @@ +/* $OpenBSD: nameser.h,v 1.15 2022/12/27 07:44:56 jmc Exp $ */ + +/* + * ++Copyright++ 1983, 1989, 1993 + * - + * Copyright (c) 1983, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * - + * Portions Copyright (c) 1993 by Digital Equipment Corporation. + * + * 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, and that + * the name of Digital Equipment Corporation not be used in advertising or + * publicity pertaining to distribution of the document or software without + * specific, written prior permission. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT + * CORPORATION 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. + * - + * Portions Copyright (c) 1995 by International Business Machines, Inc. + * + * International Business Machines, Inc. (hereinafter called IBM) grants + * permission under its copyrights to use, copy, modify, and distribute this + * Software with or without fee, provided that the above copyright notice and + * all paragraphs of this notice appear in all copies, and that the name of IBM + * not be used in connection with the marketing of any product incorporating + * the Software or modifications thereof, without specific, written prior + * permission. + * + * To the extent it has a right to do so, IBM grants an immunity from suit + * under its patents, if any, for the use, sale or manufacture of products to + * the extent that such products are used for performing Domain Name System + * dynamic updates in TCP/IP networks by means of the Software. No immunity is + * granted for any product per se or for any other function of any product. + * + * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, + * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN + * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES. + * --Copyright-- + */ + +/* + * @(#)nameser.h 8.1 (Berkeley) 6/2/93 + * $From: nameser.h,v 8.11 1996/10/08 04:51:02 vixie Exp $ + */ + +#ifndef _NAMESER_H_ +#define _NAMESER_H_ + +#include + +/* + * revision information. this is the release date in YYYYMMDD format. + * it can change every day so the right thing to do with it is use it + * in preprocessor commands such as "#if (__BIND > 19931104)". do not + * compare for equality; rather, use it to determine whether your resolver + * is new enough to contain a certain feature. + */ + +#define __BIND 19960801 /* interface version stamp */ + +/* + * Define constants based on rfc883 + */ +#define PACKETSZ 512 /* maximum packet size */ +#define MAXDNAME 1025 /* maximum presentation domain name */ +#define MAXCDNAME 255 /* maximum compressed domain name */ +#define MAXLABEL 63 /* maximum length of domain label */ +#define HFIXEDSZ 12 /* #/bytes of fixed data in header */ +#define QFIXEDSZ 4 /* #/bytes of fixed data in query */ +#define RRFIXEDSZ 10 /* #/bytes of fixed data in r record */ +#define INT32SZ 4 /* for systems without 32-bit ints */ +#define INT16SZ 2 /* for systems without 16-bit ints */ +#define INADDRSZ 4 /* IPv4 T_A */ +#define IN6ADDRSZ 16 /* IPv6 T_AAAA */ + +/* + * Internet nameserver port number + */ +#define NAMESERVER_PORT 53 + +/* + * Currently defined opcodes + */ +#define QUERY 0x0 /* standard query */ +#define IQUERY 0x1 /* inverse query */ +#define STATUS 0x2 /* nameserver status query */ +/*#define xxx 0x3*/ /* 0x3 reserved */ +#define NS_NOTIFY_OP 0x4 /* notify secondary of SOA change */ +/* + * Currently defined response codes + */ +#define NOERROR 0 /* no error */ +#define FORMERR 1 /* format error */ +#define SERVFAIL 2 /* server failure */ +#define NXDOMAIN 3 /* non existent domain */ +#define NOTIMP 4 /* not implemented */ +#define REFUSED 5 /* query refused */ + +/* + * Type values for resources and queries + */ +#define T_A 1 /* host address */ +#define T_NS 2 /* authoritative server */ +#define T_MD 3 /* mail destination */ +#define T_MF 4 /* mail forwarder */ +#define T_CNAME 5 /* canonical name */ +#define T_SOA 6 /* start of authority zone */ +#define T_MB 7 /* mailbox domain name */ +#define T_MG 8 /* mail group member */ +#define T_MR 9 /* mail rename name */ +#define T_NULL 10 /* null resource record */ +#define T_WKS 11 /* well known service */ +#define T_PTR 12 /* domain name pointer */ +#define T_HINFO 13 /* host information */ +#define T_MINFO 14 /* mailbox information */ +#define T_MX 15 /* mail routing information */ +#define T_TXT 16 /* text strings */ +#define T_RP 17 /* responsible person */ +#define T_AFSDB 18 /* AFS cell database */ +#define T_X25 19 /* X_25 calling address */ +#define T_ISDN 20 /* ISDN calling address */ +#define T_RT 21 /* router */ +#define T_NSAP 22 /* NSAP address */ +#define T_NSAP_PTR 23 /* reverse NSAP lookup (deprecated) */ +#define T_SIG 24 /* security signature */ +#define T_KEY 25 /* security key */ +#define T_PX 26 /* X.400 mail mapping */ +#define T_GPOS 27 /* geographical position (withdrawn) */ +#define T_AAAA 28 /* IP6 Address */ +#define T_LOC 29 /* Location Information */ +#define T_NXT 30 /* Next Valid Name in Zone */ +#define T_EID 31 /* Endpoint identifier */ +#define T_NIMLOC 32 /* Nimrod locator */ +#define T_SRV 33 /* Server selection */ +#define T_ATMA 34 /* ATM Address */ +#define T_NAPTR 35 /* Naming Authority PoinTeR */ +#define T_KX 36 /* Key Exchanger */ +#define T_CERT 37 /* CERT */ +#define T_A6 38 /* A6 */ +#define T_DNAME 39 /* DNAME */ +#define T_SINK 40 /* SINK */ +#define T_OPT 41 /* OPT pseudo-RR, RFC2671 */ +#define T_APL 42 /* APL */ +#define T_DS 43 /* Delegation Signer */ +#define T_SSHFP 44 /* SSH Key Fingerprint */ +#define T_RRSIG 46 /* RRSIG */ +#define T_NSEC 47 /* NSEC */ +#define T_DNSKEY 48 /* DNSKEY */ + /* non standard */ +#define T_UINFO 100 /* user (finger) information */ +#define T_UID 101 /* user ID */ +#define T_GID 102 /* group ID */ +#define T_UNSPEC 103 /* Unspecified format (binary data) */ + /* Query type values which do not appear in resource records */ +#define T_TKEY 249 /* Transaction Key */ +#define T_TSIG 250 /* Transaction Signature */ +#define T_IXFR 251 /* incremental zone transfer */ +#define T_AXFR 252 /* transfer zone of authority */ +#define T_MAILB 253 /* transfer mailbox records */ +#define T_MAILA 254 /* transfer mail agent records */ +#define T_ANY 255 /* wildcard match */ + +/* + * Values for class field + */ + +#define C_IN 1 /* the arpa internet */ +#define C_CHAOS 3 /* for chaos net (MIT) */ +#define C_HS 4 /* for Hesiod name server (MIT) (XXX) */ + /* Query class values which do not appear in resource records */ +#define C_ANY 255 /* wildcard match */ + +/* + * Flags field of the KEY RR rdata + */ +#define KEYFLAG_TYPEMASK 0xC000 /* Mask for "type" bits */ +#define KEYFLAG_TYPE_AUTH_CONF 0x0000 /* Key usable for both */ +#define KEYFLAG_TYPE_CONF_ONLY 0x8000 /* Key usable for confidentiality */ +#define KEYFLAG_TYPE_AUTH_ONLY 0x4000 /* Key usable for authentication */ +#define KEYFLAG_TYPE_NO_KEY 0xC000 /* No key usable for either; no key */ +/* The type bits can also be interpreted independently, as single bits: */ +#define KEYFLAG_NO_AUTH 0x8000 /* Key not usable for authentication */ +#define KEYFLAG_NO_CONF 0x4000 /* Key not usable for confidentiality */ + +#define KEYFLAG_EXPERIMENTAL 0x2000 /* Security is *mandatory* if bit=0 */ +#define KEYFLAG_RESERVED3 0x1000 /* reserved - must be zero */ +#define KEYFLAG_RESERVED4 0x0800 /* reserved - must be zero */ +#define KEYFLAG_USERACCOUNT 0x0400 /* key is assoc. with a user acct */ +#define KEYFLAG_ENTITY 0x0200 /* key is assoc. with entity eg host */ +#define KEYFLAG_ZONEKEY 0x0100 /* key is zone key for the zone named */ +#define KEYFLAG_IPSEC 0x0080 /* key is for IPsec use (host or user)*/ +#define KEYFLAG_EMAIL 0x0040 /* key is for email (MIME security) */ +#define KEYFLAG_RESERVED10 0x0020 /* reserved - must be zero */ +#define KEYFLAG_RESERVED11 0x0010 /* reserved - must be zero */ +#define KEYFLAG_SIGNATORYMASK 0x000F /* key can sign DNS RR's of same name */ + +#define KEYFLAG_RESERVED_BITMASK ( KEYFLAG_RESERVED3 | \ + KEYFLAG_RESERVED4 | \ + KEYFLAG_RESERVED10| KEYFLAG_RESERVED11) + +/* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */ +#define ALGORITHM_MD5RSA 1 /* MD5 with RSA */ +#define ALGORITHM_EXPIRE_ONLY 253 /* No alg, no security */ +#define ALGORITHM_PRIVATE_OID 254 /* Key begins with OID indicating alg */ + +/* Signatures */ + /* Size of a mod or exp in bits */ +#define MIN_MD5RSA_KEY_PART_BITS 512 +#define MAX_MD5RSA_KEY_PART_BITS 2552 + /* Total of binary mod and exp, bytes */ +#define MAX_MD5RSA_KEY_BYTES ((MAX_MD5RSA_KEY_PART_BITS+7/8)*2+3) + /* Max length of text sig block */ +#define MAX_KEY_BASE64 (((MAX_MD5RSA_KEY_BYTES+2)/3)*4) + +/* + * EDNS0 Z-field extended flags + */ +#define DNS_MESSAGEEXTFLAG_DO 0x8000U + +/* + * Status return codes for T_UNSPEC conversion routines + */ +#define CONV_SUCCESS 0 +#define CONV_OVERFLOW (-1) +#define CONV_BADFMT (-2) +#define CONV_BADCKSUM (-3) +#define CONV_BADBUFLEN (-4) + +#if !defined(_BYTE_ORDER) || \ + (_BYTE_ORDER != _BIG_ENDIAN && _BYTE_ORDER != _LITTLE_ENDIAN && \ + _BYTE_ORDER != _PDP_ENDIAN) + /* you must determine what the correct bit order is for + * your compiler - the next line is an intentional error + * which will force your compiles to bomb until you fix + * the above macros. + */ +#error "Undefined or invalid _BYTE_ORDER"; +#endif + +/* + * Structure for query header. The order of the fields is machine- and + * compiler-dependent, depending on the byte/bit order and the layout + * of bit fields. We use bit fields only in int variables, as this + * is all ANSI requires. This requires a somewhat confusing rearrangement. + */ + +typedef struct { + unsigned id :16; /* query identification number */ +#if _BYTE_ORDER == _BIG_ENDIAN + /* fields in third byte */ + unsigned qr: 1; /* response flag */ + unsigned opcode: 4; /* purpose of message */ + unsigned aa: 1; /* authoritative answer */ + unsigned tc: 1; /* truncated message */ + unsigned rd: 1; /* recursion desired */ + /* fields in fourth byte */ + unsigned ra: 1; /* recursion available */ + unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */ + unsigned ad: 1; /* authentic data from named */ + unsigned cd: 1; /* checking disabled by resolver */ + unsigned rcode :4; /* response code */ +#endif +#if _BYTE_ORDER == _LITTLE_ENDIAN || _BYTE_ORDER == _PDP_ENDIAN + /* fields in third byte */ + unsigned rd :1; /* recursion desired */ + unsigned tc :1; /* truncated message */ + unsigned aa :1; /* authoritative answer */ + unsigned opcode :4; /* purpose of message */ + unsigned qr :1; /* response flag */ + /* fields in fourth byte */ + unsigned rcode :4; /* response code */ + unsigned cd: 1; /* checking disabled by resolver */ + unsigned ad: 1; /* authentic data from named */ + unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */ + unsigned ra :1; /* recursion available */ +#endif + /* remaining bytes */ + unsigned qdcount :16; /* number of question entries */ + unsigned ancount :16; /* number of answer entries */ + unsigned nscount :16; /* number of authority entries */ + unsigned arcount :16; /* number of resource entries */ +} HEADER; + +/* + * Defines for handling compressed domain names + */ +#define INDIR_MASK 0xc0 + +extern u_int16_t _getshort(const unsigned char *); +extern u_int32_t _getlong(const unsigned char *); + +/* + * Inline versions of get/put short/long. Pointer is advanced. + * + * These macros demonstrate the property of C whereby it can be + * portable or it can be elegant but rarely both. + */ +#define GETSHORT(s, cp) { \ + unsigned char *t_cp = (unsigned char *)(cp); \ + (s) = ((u_int16_t)t_cp[0] << 8) \ + | ((u_int16_t)t_cp[1]) \ + ; \ + (cp) += INT16SZ; \ +} + +#define GETLONG(l, cp) { \ + unsigned char *t_cp = (unsigned char *)(cp); \ + (l) = ((u_int32_t)t_cp[0] << 24) \ + | ((u_int32_t)t_cp[1] << 16) \ + | ((u_int32_t)t_cp[2] << 8) \ + | ((u_int32_t)t_cp[3]) \ + ; \ + (cp) += INT32SZ; \ +} + +#define PUTSHORT(s, cp) { \ + u_int16_t t_s = (u_int16_t)(s); \ + unsigned char *t_cp = (unsigned char *)(cp); \ + *t_cp++ = t_s >> 8; \ + *t_cp = t_s; \ + (cp) += INT16SZ; \ +} + +#define PUTLONG(l, cp) { \ + u_int32_t t_l = (u_int32_t)(l); \ + unsigned char *t_cp = (unsigned char *)(cp); \ + *t_cp++ = t_l >> 24; \ + *t_cp++ = t_l >> 16; \ + *t_cp++ = t_l >> 8; \ + *t_cp = t_l; \ + (cp) += INT32SZ; \ +} + +#endif /* !_NAMESER_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/arpa/telnet.h b/lib/libc/include/generic-openbsd/arpa/telnet.h new file mode 100644 index 0000000000..f0094f2af2 --- /dev/null +++ b/lib/libc/include/generic-openbsd/arpa/telnet.h @@ -0,0 +1,339 @@ +/* $OpenBSD: telnet.h,v 1.7 2003/06/02 19:34:12 millert Exp $ */ +/* $NetBSD: telnet.h,v 1.4 1994/10/26 00:56:46 cgd Exp $ */ + +/* + * Copyright (c) 1983, 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. + * + * @(#)telnet.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _TELNET_H_ +#define _TELNET_H_ + +/* + * Definitions for the TELNET protocol. + */ +#define IAC 255 /* interpret as command: */ +#define DONT 254 /* you are not to use option */ +#define DO 253 /* please, you use option */ +#define WONT 252 /* I won't use option */ +#define WILL 251 /* I will use option */ +#define SB 250 /* interpret as subnegotiation */ +#define GA 249 /* you may reverse the line */ +#define EL 248 /* erase the current line */ +#define EC 247 /* erase the current character */ +#define AYT 246 /* are you there */ +#define AO 245 /* abort output--but let prog finish */ +#define IP 244 /* interrupt process--permanently */ +#define BREAK 243 /* break */ +#define DM 242 /* data mark--for connect. cleaning */ +#define NOP 241 /* nop */ +#define SE 240 /* end sub negotiation */ +#define EOR 239 /* end of record (transparent mode) */ +#define ABORT 238 /* Abort process */ +#define SUSP 237 /* Suspend process */ +#define xEOF 236 /* End of file: EOF is already used... */ + +#define SYNCH 242 /* for telfunc calls */ + +#ifdef TELCMDS +char *telcmds[] = { + "EOF", "SUSP", "ABORT", "EOR", + "SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC", + "EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC", + 0 +}; +#else +extern char *telcmds[]; +#endif + +#define TELCMD_FIRST xEOF +#define TELCMD_LAST IAC +#define TELCMD_OK(x) ((unsigned int)(x) <= TELCMD_LAST && \ + (unsigned int)(x) >= TELCMD_FIRST) +#define TELCMD(x) telcmds[(x)-TELCMD_FIRST] + +/* telnet options */ +#define TELOPT_BINARY 0 /* 8-bit data path */ +#define TELOPT_ECHO 1 /* echo */ +#define TELOPT_RCP 2 /* prepare to reconnect */ +#define TELOPT_SGA 3 /* suppress go ahead */ +#define TELOPT_NAMS 4 /* approximate message size */ +#define TELOPT_STATUS 5 /* give status */ +#define TELOPT_TM 6 /* timing mark */ +#define TELOPT_RCTE 7 /* remote controlled transmission and echo */ +#define TELOPT_NAOL 8 /* negotiate about output line width */ +#define TELOPT_NAOP 9 /* negotiate about output page size */ +#define TELOPT_NAOCRD 10 /* negotiate about CR disposition */ +#define TELOPT_NAOHTS 11 /* negotiate about horizontal tabstops */ +#define TELOPT_NAOHTD 12 /* negotiate about horizontal tab disposition */ +#define TELOPT_NAOFFD 13 /* negotiate about formfeed disposition */ +#define TELOPT_NAOVTS 14 /* negotiate about vertical tab stops */ +#define TELOPT_NAOVTD 15 /* negotiate about vertical tab disposition */ +#define TELOPT_NAOLFD 16 /* negotiate about output LF disposition */ +#define TELOPT_XASCII 17 /* extended ascic character set */ +#define TELOPT_LOGOUT 18 /* force logout */ +#define TELOPT_BM 19 /* byte macro */ +#define TELOPT_DET 20 /* data entry terminal */ +#define TELOPT_SUPDUP 21 /* supdup protocol */ +#define TELOPT_SUPDUPOUTPUT 22 /* supdup output */ +#define TELOPT_SNDLOC 23 /* send location */ +#define TELOPT_TTYPE 24 /* terminal type */ +#define TELOPT_EOR 25 /* end or record */ +#define TELOPT_TUID 26 /* TACACS user identification */ +#define TELOPT_OUTMRK 27 /* output marking */ +#define TELOPT_TTYLOC 28 /* terminal location number */ +#define TELOPT_3270REGIME 29 /* 3270 regime */ +#define TELOPT_X3PAD 30 /* X.3 PAD */ +#define TELOPT_NAWS 31 /* window size */ +#define TELOPT_TSPEED 32 /* terminal speed */ +#define TELOPT_LFLOW 33 /* remote flow control */ +#define TELOPT_LINEMODE 34 /* Linemode option */ +#define TELOPT_XDISPLOC 35 /* X Display Location */ +#define TELOPT_OLD_ENVIRON 36 /* Old - Environment variables */ +#define TELOPT_AUTHENTICATION 37/* Authenticate */ +#define TELOPT_ENCRYPT 38 /* Encryption option */ +#define TELOPT_NEW_ENVIRON 39 /* New - Environment variables */ +#define TELOPT_EXOPL 255 /* extended-options-list */ + + +#define NTELOPTS (1+TELOPT_NEW_ENVIRON) +#ifdef TELOPTS +char *telopts[NTELOPTS+1] = { + "BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME", + "STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP", + "NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS", + "NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO", + "DATA ENTRY TERMINAL", "SUPDUP", "SUPDUP OUTPUT", + "SEND LOCATION", "TERMINAL TYPE", "END OF RECORD", + "TACACS UID", "OUTPUT MARKING", "TTYLOC", + "3270 REGIME", "X.3 PAD", "NAWS", "TSPEED", "LFLOW", + "LINEMODE", "XDISPLOC", "OLD-ENVIRON", "AUTHENTICATION", + "ENCRYPT", "NEW-ENVIRON", + 0 +}; +#define TELOPT_FIRST TELOPT_BINARY +#define TELOPT_LAST TELOPT_NEW_ENVIRON +#define TELOPT_OK(x) ((unsigned int)(x) <= TELOPT_LAST) +#define TELOPT(x) telopts[(x)-TELOPT_FIRST] +#endif + +/* sub-option qualifiers */ +#define TELQUAL_IS 0 /* option is... */ +#define TELQUAL_SEND 1 /* send option */ +#define TELQUAL_INFO 2 /* ENVIRON: informational version of IS */ +#define TELQUAL_REPLY 2 /* AUTHENTICATION: client version of IS */ +#define TELQUAL_NAME 3 /* AUTHENTICATION: client version of IS */ + +#define LFLOW_OFF 0 /* Disable remote flow control */ +#define LFLOW_ON 1 /* Enable remote flow control */ +#define LFLOW_RESTART_ANY 2 /* Restart output on any char */ +#define LFLOW_RESTART_XON 3 /* Restart output only on XON */ + +/* + * LINEMODE suboptions + */ + +#define LM_MODE 1 +#define LM_FORWARDMASK 2 +#define LM_SLC 3 + +#define MODE_EDIT 0x01 +#define MODE_TRAPSIG 0x02 +#define MODE_ACK 0x04 +#define MODE_SOFT_TAB 0x08 +#define MODE_LIT_ECHO 0x10 + +#define MODE_MASK 0x1f + +/* Not part of protocol, but needed to simplify things... */ +#define MODE_FLOW 0x0100 +#define MODE_ECHO 0x0200 +#define MODE_INBIN 0x0400 +#define MODE_OUTBIN 0x0800 +#define MODE_FORCE 0x1000 + +#define SLC_SYNCH 1 +#define SLC_BRK 2 +#define SLC_IP 3 +#define SLC_AO 4 +#define SLC_AYT 5 +#define SLC_EOR 6 +#define SLC_ABORT 7 +#define SLC_EOF 8 +#define SLC_SUSP 9 +#define SLC_EC 10 +#define SLC_EL 11 +#define SLC_EW 12 +#define SLC_RP 13 +#define SLC_LNEXT 14 +#define SLC_XON 15 +#define SLC_XOFF 16 +#define SLC_FORW1 17 +#define SLC_FORW2 18 +#define SLC_MCL 19 +#define SLC_MCR 20 +#define SLC_MCWL 21 +#define SLC_MCWR 22 +#define SLC_MCBOL 23 +#define SLC_MCEOL 24 +#define SLC_INSRT 25 +#define SLC_OVER 26 +#define SLC_ECR 27 +#define SLC_EWR 28 +#define SLC_EBOL 29 +#define SLC_EEOL 30 + +#define NSLC 30 + +/* + * For backwards compatibility, we define SLC_NAMES to be the + * list of names if SLC_NAMES is not defined. + */ +#define SLC_NAMELIST "0", "SYNCH", "BRK", "IP", "AO", "AYT", "EOR", \ + "ABORT", "EOF", "SUSP", "EC", "EL", "EW", "RP", \ + "LNEXT", "XON", "XOFF", "FORW1", "FORW2", \ + "MCL", "MCR", "MCWL", "MCWR", "MCBOL", \ + "MCEOL", "INSRT", "OVER", "ECR", "EWR", \ + "EBOL", "EEOL", \ + 0 + +#ifdef SLC_NAMES +char *slc_names[] = { + SLC_NAMELIST +}; +#else +extern char *slc_names[]; +#define SLC_NAMES SLC_NAMELIST +#endif + +#define SLC_NAME_OK(x) ((unsigned)(x) > 0 && (unsigned)(x) <= NSLC) +#define SLC_NAME(x) slc_names[x] + +#define SLC_NOSUPPORT 0 +#define SLC_CANTCHANGE 1 +#define SLC_VARIABLE 2 +#define SLC_DEFAULT 3 +#define SLC_LEVELBITS 0x03 + +#define SLC_FUNC 0 +#define SLC_FLAGS 1 +#define SLC_VALUE 2 + +#define SLC_ACK 0x80 +#define SLC_FLUSHIN 0x40 +#define SLC_FLUSHOUT 0x20 + +#define OLD_ENV_VAR 1 +#define OLD_ENV_VALUE 0 +#define NEW_ENV_VAR 0 +#define NEW_ENV_VALUE 1 +#define ENV_ESC 2 +#define ENV_USERVAR 3 + +/* + * AUTHENTICATION suboptions + */ + +/* + * Who is authenticating who ... + */ +#define AUTH_WHO_CLIENT 0 /* Client authenticating server */ +#define AUTH_WHO_SERVER 1 /* Server authenticating client */ +#define AUTH_WHO_MASK 1 + +/* + * amount of authentication done + */ +#define AUTH_HOW_ONE_WAY 0 +#define AUTH_HOW_MUTUAL 2 +#define AUTH_HOW_MASK 2 + +#define AUTHTYPE_NULL 0 +#define AUTHTYPE_KERBEROS_V4 1 +#define AUTHTYPE_KERBEROS_V5 2 +#define AUTHTYPE_SPX 3 +#define AUTHTYPE_MINK 4 +#define AUTHTYPE_CNT 5 + +#define AUTHTYPE_TEST 99 + +#ifdef AUTH_NAMES +char *authtype_names[] = { + "NULL", "KERBEROS_V4", "KERBEROS_V5", "SPX", "MINK", + 0 +}; +#else +extern char *authtype_names[]; +#endif + +#define AUTHTYPE_NAME_OK(x) ((unsigned int)(x) < AUTHTYPE_CNT) +#define AUTHTYPE_NAME(x) authtype_names[x] + +/* + * ENCRYPTion suboptions + */ +#define ENCRYPT_IS 0 /* I pick encryption type ... */ +#define ENCRYPT_SUPPORT 1 /* I support encryption types ... */ +#define ENCRYPT_REPLY 2 /* Initial setup response */ +#define ENCRYPT_START 3 /* Am starting to send encrypted */ +#define ENCRYPT_END 4 /* Am ending encrypted */ +#define ENCRYPT_REQSTART 5 /* Request you start encrypting */ +#define ENCRYPT_REQEND 6 /* Request you end encrypting */ +#define ENCRYPT_ENC_KEYID 7 +#define ENCRYPT_DEC_KEYID 8 +#define ENCRYPT_CNT 9 + +#define ENCTYPE_ANY 0 +#define ENCTYPE_DES_CFB64 1 +#define ENCTYPE_DES_OFB64 2 +#define ENCTYPE_CNT 3 + +#ifdef ENCRYPT_NAMES +char *encrypt_names[] = { + "IS", "SUPPORT", "REPLY", "START", "END", + "REQUEST-START", "REQUEST-END", "ENC-KEYID", "DEC-KEYID", + 0 +}; +char *enctype_names[] = { + "ANY", "DES_CFB64", "DES_OFB64", + 0 +}; +#else +extern char *encrypt_names[]; +extern char *enctype_names[]; +#endif + + +#define ENCRYPT_NAME_OK(x) ((unsigned int)(x) < ENCRYPT_CNT) +#define ENCRYPT_NAME(x) encrypt_names[x] + +#define ENCTYPE_NAME_OK(x) ((unsigned int)(x) < ENCTYPE_CNT) +#define ENCTYPE_NAME(x) enctype_names[x] + +#endif /* !_TELNET_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/arpa/tftp.h b/lib/libc/include/generic-openbsd/arpa/tftp.h new file mode 100644 index 0000000000..83c5338cc6 --- /dev/null +++ b/lib/libc/include/generic-openbsd/arpa/tftp.h @@ -0,0 +1,83 @@ +/* $OpenBSD: tftp.h,v 1.8 2006/07/26 16:43:30 deraadt Exp $ */ +/* $NetBSD: tftp.h,v 1.3 1994/10/26 00:56:48 cgd Exp $ */ + +/* + * Copyright (c) 1983 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. + * + * @(#)tftp.h 5.4 (Berkeley) 4/3/91 + */ + +#ifndef _TFTP_H_ +#define _TFTP_H_ + +/* + * Trivial File Transfer Protocol (IEN-133) + */ +#define SEGSIZE 512 /* data segment size */ +#define SEGSIZE_MIN 8 /* minimal data segment size */ +#define SEGSIZE_MAX 65464 /* maximal data segment size */ + +/* + * Packet types. + */ +#define RRQ 01 /* read request */ +#define WRQ 02 /* write request */ +#define DATA 03 /* data packet */ +#define ACK 04 /* acknowledgement */ +#define ERROR 05 /* error code */ +#define OACK 06 /* option acknowledgement */ + +struct tftphdr { + u_int16_t th_opcode; /* packet type */ + union { + u_int16_t tu_block; /* block # */ + u_int16_t tu_code; /* error code */ + char tu_stuff[1]; /* request packet stuff */ + } th_u; + char th_data[1]; /* data or error string */ +}; + +#define th_block th_u.tu_block +#define th_code th_u.tu_code +#define th_stuff th_u.tu_stuff +#define th_msg th_data + +/* + * Error codes. + */ +#define EUNDEF 0 /* not defined */ +#define ENOTFOUND 1 /* file not found */ +#define EACCESS 2 /* access violation */ +#define ENOSPACE 3 /* disk full or allocation exceeded */ +#define EBADOP 4 /* illegal TFTP operation */ +#define EBADID 5 /* unknown transfer ID */ +#define EEXISTS 6 /* file already exists */ +#define ENOUSER 7 /* no such user */ +#define EOPTNEG 8 /* option negotiation failed */ + +#endif /* !_TFTP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/asr.h b/lib/libc/include/generic-openbsd/asr.h new file mode 100644 index 0000000000..cef6d6baf0 --- /dev/null +++ b/lib/libc/include/generic-openbsd/asr.h @@ -0,0 +1,90 @@ +/* $OpenBSD: asr.h,v 1.2 2019/10/24 05:57:41 otto Exp $ */ +/* + * Copyright (c) 2012-2014 Eric Faurot + * + * 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. + */ + +/* + * Expected fd conditions + */ +#define ASR_WANT_READ 1 +#define ASR_WANT_WRITE 2 + +/* + * Structure through which asynchronous query results are returned when + * calling asr_run(). + */ +struct asr_result { + /* Fields set if the query is not done yet (asr_run returns 0) */ + int ar_cond; /* ASR_WANT_READ or ASR_WANT_WRITE */ + int ar_fd; /* the fd waiting for io condition */ + int ar_timeout; /* time to wait for in milliseconds */ + + /* Error fields. Depends on the query type. */ + int ar_errno; + int ar_h_errno; + int ar_gai_errno; + int ar_rrset_errno; + + /* Result for res_*_async() calls */ + int ar_count; /* number of answers in the dns reply */ + int ar_rcode; /* response code in the dns reply */ + void *ar_data; /* raw reply packet (must be freed) */ + int ar_datalen; /* reply packet length */ + struct sockaddr_storage ar_ns; /* nameserver that responded */ + + /* Result for other calls. Must be freed properly. */ + struct addrinfo *ar_addrinfo; + struct rrsetinfo *ar_rrsetinfo; + struct hostent *ar_hostent; + struct netent *ar_netent; +}; + +/* + * Asynchronous query management. + */ + +/* Forward declaration. The API uses opaque pointers as query handles. */ +struct asr_query; + +void *asr_resolver_from_string(const char *); +void asr_resolver_free(void *); +int asr_run(struct asr_query *, struct asr_result *); +int asr_run_sync(struct asr_query *, struct asr_result *); +void asr_abort(struct asr_query *); + +/* + * Asynchronous version of the resolver functions. Similar prototypes, with + * an extra context parameter at the end which must currently be set to NULL. + * All functions return a handle suitable for use with the management functions + * above. + */ +struct asr_query *res_send_async(const unsigned char *, int, void *); +struct asr_query *res_query_async(const char *, int, int, void *); +struct asr_query *res_search_async(const char *, int, int, void *); + +struct asr_query *getrrsetbyname_async(const char *, unsigned int, unsigned int, + unsigned int, void *); + +struct asr_query *gethostbyname_async(const char *, void *); +struct asr_query *gethostbyname2_async(const char *, int, void *); +struct asr_query *gethostbyaddr_async(const void *, socklen_t, int, void *); + +struct asr_query *getnetbyname_async(const char *, void *); +struct asr_query *getnetbyaddr_async(in_addr_t, int, void *); + +struct asr_query *getaddrinfo_async(const char *, const char *, + const struct addrinfo *, void *); +struct asr_query *getnameinfo_async(const struct sockaddr *, socklen_t, char *, + size_t, char *, size_t, int, void *); \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/assert.h b/lib/libc/include/generic-openbsd/assert.h new file mode 100644 index 0000000000..88359e2459 --- /dev/null +++ b/lib/libc/include/generic-openbsd/assert.h @@ -0,0 +1,73 @@ +/* $OpenBSD: assert.h,v 1.15 2020/09/06 12:57:25 millert Exp $ */ +/* $NetBSD: assert.h,v 1.6 1994/10/26 00:55:44 cgd Exp $ */ + +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)assert.h 8.2 (Berkeley) 1/21/94 + */ + +/* + * Unlike other ANSI header files, may usefully be included + * multiple times, with and without NDEBUG defined. + */ + +#include + +#undef assert +#undef _assert + +#ifdef NDEBUG +# define assert(e) ((void)0) +# define _assert(e) ((void)0) +#else +# define _assert(e) assert(e) +# if __ISO_C_VISIBLE >= 1999 +# define assert(e) ((e) ? (void)0 : __assert2(__FILE__, __LINE__, __func__, #e)) +# else +# define assert(e) ((e) ? (void)0 : __assert(__FILE__, __LINE__, #e)) +# endif +#endif + +#ifndef _ASSERT_H_ +#define _ASSERT_H_ + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112 +#define static_assert _Static_assert +#endif + +__BEGIN_DECLS +__dead void __assert(const char *, int, const char *); +__dead void __assert2(const char *, int, const char *, const char *); +__END_DECLS +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ber.h b/lib/libc/include/generic-openbsd/ber.h new file mode 100644 index 0000000000..9638118862 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ber.h @@ -0,0 +1,153 @@ +/* $OpenBSD: ber.h,v 1.5 2021/10/31 16:42:08 tb Exp $ */ + +/* + * Copyright (c) 2007, 2012 Reyk Floeter + * Copyright (c) 2006, 2007 Claudio Jeker + * + * 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 _BER_H +#define _BER_H + +struct ber_octetstring { + size_t ostr_len; + const void *ostr_val; +}; + +struct ber_element { + struct ber_element *be_next; + unsigned int be_type; + unsigned int be_encoding; + size_t be_len; + off_t be_offs; + int be_free; + u_int8_t be_class; + void (*be_cb)(void *, size_t); + void *be_cbarg; + union { + struct ber_element *bv_sub; + void *bv_val; + long long bv_numeric; + } be_union; +#define be_sub be_union.bv_sub +#define be_val be_union.bv_val +#define be_numeric be_union.bv_numeric +}; + +struct ber { + off_t br_offs; + u_char *br_wbuf; + u_char *br_wptr; + u_char *br_wend; + u_char *br_rbuf; + u_char *br_rptr; + u_char *br_rend; + + unsigned int (*br_application)(struct ber_element *); +}; + +/* well-known ber_element types */ +#define BER_TYPE_DEFAULT ((unsigned int)-1) +#define BER_TYPE_EOC 0 +#define BER_TYPE_BOOLEAN 1 +#define BER_TYPE_INTEGER 2 +#define BER_TYPE_BITSTRING 3 +#define BER_TYPE_OCTETSTRING 4 +#define BER_TYPE_NULL 5 +#define BER_TYPE_OBJECT 6 +#define BER_TYPE_ENUMERATED 10 +#define BER_TYPE_SEQUENCE 16 +#define BER_TYPE_SET 17 + +/* ber classes */ +#define BER_CLASS_UNIVERSAL 0x0 +#define BER_CLASS_UNIV BER_CLASS_UNIVERSAL +#define BER_CLASS_APPLICATION 0x1 +#define BER_CLASS_APP BER_CLASS_APPLICATION +#define BER_CLASS_CONTEXT 0x2 +#define BER_CLASS_PRIVATE 0x3 +#define BER_CLASS_MASK 0x3 + +/* common definitions */ +#define BER_MIN_OID_LEN 2 /* X.690 section 8.19.5 */ +#define BER_MAX_OID_LEN 128 /* RFC 2578 section 7.1.3 */ +#define BER_MAX_SEQ_ELEMENTS USHRT_MAX /* 65535 */ + +struct ber_oid { + u_int32_t bo_id[BER_MAX_OID_LEN + 1]; + size_t bo_n; +}; + +__BEGIN_DECLS +struct ber_element *ober_get_element(unsigned int); +void ober_set_header(struct ber_element *, int, + unsigned int); +void ober_link_elements(struct ber_element *, + struct ber_element *); +struct ber_element *ober_unlink_elements(struct ber_element *); +void ober_replace_elements(struct ber_element *, + struct ber_element *); +struct ber_element *ober_add_sequence(struct ber_element *); +struct ber_element *ober_add_set(struct ber_element *); +struct ber_element *ober_add_integer(struct ber_element *, long long); +int ober_get_integer(struct ber_element *, long long *); +struct ber_element *ober_add_enumerated(struct ber_element *, long long); +int ober_get_enumerated(struct ber_element *, long long *); +struct ber_element *ober_add_boolean(struct ber_element *, int); +int ober_get_boolean(struct ber_element *, int *); +struct ber_element *ober_add_string(struct ber_element *, const char *); +struct ber_element *ober_add_nstring(struct ber_element *, const char *, + size_t); +struct ber_element *ober_add_ostring(struct ber_element *, + struct ber_octetstring *); +int ober_get_string(struct ber_element *, char **); +int ober_get_nstring(struct ber_element *, void **, + size_t *); +int ober_get_ostring(struct ber_element *, + struct ber_octetstring *); +struct ber_element *ober_add_bitstring(struct ber_element *, const void *, + size_t); +int ober_get_bitstring(struct ber_element *, void **, + size_t *); +struct ber_element *ober_add_null(struct ber_element *); +int ober_get_null(struct ber_element *); +struct ber_element *ober_add_eoc(struct ber_element *); +int ober_get_eoc(struct ber_element *); +struct ber_element *ober_add_oid(struct ber_element *, struct ber_oid *); +struct ber_element *ober_add_noid(struct ber_element *, struct ber_oid *, int); +struct ber_element *ober_add_oidstring(struct ber_element *, const char *); +int ober_get_oid(struct ber_element *, struct ber_oid *); +size_t ober_oid2ber(struct ber_oid *, u_int8_t *, size_t); +int ober_string2oid(const char *, struct ber_oid *); +struct ber_element *ober_printf_elements(struct ber_element *, char *, ...); +int ober_scanf_elements(struct ber_element *, char *, ...); +ssize_t ober_get_writebuf(struct ber *, void **); +ssize_t ober_write_elements(struct ber *, struct ber_element *); +void ober_set_readbuf(struct ber *, void *, size_t); +struct ber_element *ober_read_elements(struct ber *, struct ber_element *); +off_t ober_getpos(struct ber_element *); +struct ber_element *ober_dup(struct ber_element *); +void ober_free_element(struct ber_element *); +void ober_free_elements(struct ber_element *); +size_t ober_calc_len(struct ber_element *); +void ober_set_application(struct ber *, + unsigned int (*)(struct ber_element *)); +void ober_set_writecallback(struct ber_element *, + void (*)(void *, size_t), void *); +void ober_free(struct ber *); +int ober_oid_cmp(struct ber_oid *, struct ber_oid *); + +__END_DECLS + +#endif /* _BER_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/bitstring.h b/lib/libc/include/generic-openbsd/bitstring.h new file mode 100644 index 0000000000..2c30a30923 --- /dev/null +++ b/lib/libc/include/generic-openbsd/bitstring.h @@ -0,0 +1,134 @@ +/* $OpenBSD: bitstring.h,v 1.7 2024/08/26 11:52:54 bluhm Exp $ */ +/* $NetBSD: bitstring.h,v 1.5 1997/05/14 15:49:55 pk Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Vixie. + * + * 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. + * + * @(#)bitstring.h 8.1 (Berkeley) 7/19/93 + */ + +#ifndef _BITSTRING_H_ +#define _BITSTRING_H_ + +/* modified for SV/AT and bitstring bugfix by M.R.Murphy, 11oct91 + * bitstr_size changed gratuitously, but shorter + * bit_alloc spelling error fixed + * the following were efficient, but didn't work, they've been made to + * work, but are no longer as efficient :-) + * bit_nclear, bit_nset, bit_ffc, bit_ffs + */ +typedef unsigned char bitstr_t; + +/* internal macros */ + /* byte of the bitstring bit is in */ +#define _bit_byte(bit) \ + ((bit) >> 3) + + /* mask for the bit within its byte */ +#define _bit_mask(bit) \ + (1 << ((bit)&0x7)) + +/* external macros */ + /* bytes in a bitstring of nbits bits */ +#define bitstr_size(nbits) \ + (((nbits) + 7) >> 3) + + /* allocate a bitstring */ +#define bit_alloc(nbits) \ + (bitstr_t *)calloc((size_t)bitstr_size(nbits), sizeof(bitstr_t)) + + /* allocate a bitstring on the stack */ +#define bit_decl(name, nbits) \ + ((name)[bitstr_size(nbits)]) + + /* is bit N of bitstring name set? */ +#define bit_test(name, bit) ({ \ + register int __tbit = (bit); \ + ((name)[_bit_byte(__tbit)] & _bit_mask(__tbit)); \ +}) + + /* set bit N of bitstring name */ +#define bit_set(name, bit) do { \ + register int __sbit = (bit); \ + ((name)[_bit_byte(__sbit)] |= _bit_mask(__sbit)); \ +} while(0) + + /* clear bit N of bitstring name */ +#define bit_clear(name, bit) do { \ + register int __cbit = (bit); \ + ((name)[_bit_byte(__cbit)] &= ~_bit_mask(__cbit)); \ +} while(0) + + /* clear bits start ... stop in bitstring */ +#define bit_nclear(name, start, stop) do { \ + register bitstr_t *__name = (name); \ + register int __start = (start), __stop = (stop); \ + while (__start <= __stop) { \ + bit_clear(__name, __start); \ + __start++; \ + } \ +} while(0) + + /* set bits start ... stop in bitstring */ +#define bit_nset(name, start, stop) do { \ + register bitstr_t *__name = (name); \ + register int __start = (start), __stop = (stop); \ + while (__start <= __stop) { \ + bit_set(__name, __start); \ + __start++; \ + } \ +} while(0) + + /* find first bit clear in name */ +#define bit_ffc(name, nbits, value) do { \ + register bitstr_t *__name = (name); \ + register int __bit, __nbits = (nbits), __value = -1; \ + for (__bit = 0; __bit < __nbits; ++__bit) \ + if (!bit_test(__name, __bit)) { \ + __value = __bit; \ + break; \ + } \ + *(value) = __value; \ +} while(0) + + /* find first bit set in name */ +#define bit_ffs(name, nbits, value) do { \ + register bitstr_t *__name = (name); \ + register int __bit, __nbits = (nbits), __value = -1; \ + for (__bit = 0; __bit < __nbits; ++__bit) \ + if (bit_test(__name, __bit)) { \ + __value = __bit; \ + break; \ + } \ + *(value) = __value; \ +} while(0) + +#endif /* !_BITSTRING_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/blf.h b/lib/libc/include/generic-openbsd/blf.h new file mode 100644 index 0000000000..3e41647ce4 --- /dev/null +++ b/lib/libc/include/generic-openbsd/blf.h @@ -0,0 +1,79 @@ +/* $OpenBSD: blf.h,v 1.8 2021/11/29 01:04:45 djm Exp $ */ +/* + * Blowfish - a fast block cipher designed by Bruce Schneier + * + * Copyright 1997 Niels Provos + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _BLF_H_ +#define _BLF_H_ + +/* Schneier specifies a maximum key length of 56 bytes. + * This ensures that every key bit affects every cipher + * bit. However, the subkeys can hold up to 72 bytes. + * Warning: For normal blowfish encryption only 56 bytes + * of the key affect all cipherbits. + */ + +#define BLF_N 16 /* Number of Subkeys */ +#define BLF_MAXKEYLEN ((BLF_N-2)*4) /* 448 bits */ +#define BLF_MAXUTILIZED ((BLF_N+2)*4) /* 576 bits */ + +/* Blowfish context */ +typedef struct BlowfishContext { + u_int32_t S[4][256]; /* S-Boxes */ + u_int32_t P[BLF_N + 2]; /* Subkeys */ +} blf_ctx; + +/* Raw access to customized Blowfish + * blf_key is just: + * Blowfish_initstate( state ) + * Blowfish_expand0state( state, key, keylen ) + */ + +void Blowfish_encipher(blf_ctx *, u_int32_t *, u_int32_t *); +void Blowfish_decipher(blf_ctx *, u_int32_t *, u_int32_t *); +void Blowfish_initstate(blf_ctx *); +void Blowfish_expand0state(blf_ctx *, const u_int8_t *, u_int16_t); +void Blowfish_expandstate +(blf_ctx *, const u_int8_t *, u_int16_t, const u_int8_t *, u_int16_t); + +/* Standard Blowfish */ + +void blf_key(blf_ctx *, const u_int8_t *, u_int16_t); +void blf_enc(blf_ctx *, u_int32_t *, u_int16_t); +void blf_dec(blf_ctx *, u_int32_t *, u_int16_t); + +void blf_ecb_encrypt(blf_ctx *, u_int8_t *, u_int32_t); +void blf_ecb_decrypt(blf_ctx *, u_int8_t *, u_int32_t); + +void blf_cbc_encrypt(blf_ctx *, u_int8_t *, u_int8_t *, u_int32_t); +void blf_cbc_decrypt(blf_ctx *, u_int8_t *, u_int8_t *, u_int32_t); + +/* Converts u_int8_t to u_int32_t */ +u_int32_t Blowfish_stream2word(const u_int8_t *, u_int16_t , u_int16_t *); + +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/bsd_auth.h b/lib/libc/include/generic-openbsd/bsd_auth.h new file mode 100644 index 0000000000..34a09cc13f --- /dev/null +++ b/lib/libc/include/generic-openbsd/bsd_auth.h @@ -0,0 +1,105 @@ +/* $OpenBSD: bsd_auth.h,v 1.11 2017/03/09 10:13:03 fcambus Exp $ */ + +/*- + * Copyright (c) 1997 Berkeley Software Design, Inc. 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 Berkeley Software Design, + * Inc. + * 4. The name of Berkeley Software Design, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN, INC. ``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 BERKELEY SOFTWARE DESIGN, INC. 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. + * + * BSDI $From: bsd_auth.h,v 2.3 1999/09/08 22:13:08 prb Exp $ + */ + +#ifndef _BSD_AUTH_H_ +#define _BSD_AUTH_H_ + +#include /* for __va_list */ + +typedef struct auth_session_t auth_session_t; + +typedef enum { + AUTHV_ALL, + AUTHV_CHALLENGE, + AUTHV_CLASS, + AUTHV_NAME, + AUTHV_SERVICE, + AUTHV_STYLE, + AUTHV_INTERACTIVE +} auth_item_t; + +#include +__BEGIN_DECLS +struct passwd; +struct login_cap; + +char *auth_getitem(auth_session_t *, auth_item_t); +int auth_setitem(auth_session_t *, auth_item_t, char *); + +auth_session_t *auth_open(void); +auth_session_t *auth_verify(auth_session_t *, char *, char *, ...) + __attribute__((__sentinel__)); + +auth_session_t *auth_userchallenge(char *, char *, char *, char **); +auth_session_t *auth_usercheck(char *, char *, char *, char *); + +int auth_userresponse(auth_session_t *, char *, int); +int auth_userokay(char *, char *, char *, char *); +int auth_approval(auth_session_t *, struct login_cap *, char *, char *); + +int auth_close(auth_session_t *); +void auth_clean(auth_session_t *); + +char *auth_getvalue(auth_session_t *, char *); +int auth_getstate(auth_session_t *); +char *auth_challenge(auth_session_t *); +void auth_setenv(auth_session_t *); +void auth_clrenv(auth_session_t *); + +void auth_setstate(auth_session_t *, int); +int auth_call(auth_session_t *, char *, ...) + __attribute__((__sentinel__)); + +int auth_setdata(auth_session_t *, void *, size_t); +int auth_setoption(auth_session_t *, char *, char *); +int auth_setpwd(auth_session_t *, struct passwd *); +void auth_set_va_list(auth_session_t *, __va_list); + +struct passwd *auth_getpwd(auth_session_t *); + +quad_t auth_check_expire(auth_session_t *); +quad_t auth_check_change(auth_session_t *); + +void auth_clroptions(auth_session_t *); +void auth_clroption(auth_session_t *, char *); + +char *auth_mkvalue(char *); +void auth_checknologin(struct login_cap *); +int auth_cat(char *); + +__END_DECLS + +#endif /* _BSD_AUTH_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/complex.h b/lib/libc/include/generic-openbsd/complex.h new file mode 100644 index 0000000000..16f72cc34f --- /dev/null +++ b/lib/libc/include/generic-openbsd/complex.h @@ -0,0 +1,120 @@ +/* $OpenBSD: complex.h,v 1.5 2014/03/16 18:38:30 guenther Exp $ */ +/* + * Copyright (c) 2008 Martynas Venckus + * + * 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 _COMPLEX_H_ +#define _COMPLEX_H_ + +#include + +/* + * C99 + */ +#ifdef __GNUC__ +#if __STDC_VERSION__ < 199901 +#define _Complex __complex__ +#endif +#define _Complex_I 1.0fi +#endif + +#define complex _Complex + +/* XXX switch to _Imaginary_I */ +#undef I +#define I _Complex_I + +__BEGIN_DECLS +/* + * Double versions of C99 functions + */ +double complex cacos(double complex); +double complex casin(double complex); +double complex catan(double complex); +double complex ccos(double complex); +double complex csin(double complex); +double complex ctan(double complex); +double complex cacosh(double complex); +double complex casinh(double complex); +double complex catanh(double complex); +double complex ccosh(double complex); +double complex csinh(double complex); +double complex ctanh(double complex); +double complex cexp(double complex); +double complex clog(double complex); +double cabs(double complex); +double complex cpow(double complex, double complex); +double complex csqrt(double complex); +double carg(double complex); +double cimag(double complex); +double complex conj(double complex); +double complex cproj(double complex); +double creal(double complex); + +/* + * Float versions of C99 functions + */ +float complex cacosf(float complex); +float complex casinf(float complex); +float complex catanf(float complex); +float complex ccosf(float complex); +float complex csinf(float complex); +float complex ctanf(float complex); +float complex cacoshf(float complex); +float complex casinhf(float complex); +float complex catanhf(float complex); +float complex ccoshf(float complex); +float complex csinhf(float complex); +float complex ctanhf(float complex); +float complex cexpf(float complex); +float complex clogf(float complex); +float cabsf(float complex); +float complex cpowf(float complex, float complex); +float complex csqrtf(float complex); +float cargf(float complex); +float cimagf(float complex); +float complex conjf(float complex); +float complex cprojf(float complex); +float crealf(float complex); + +/* + * Long double versions of C99 functions + */ +long double complex cacosl(long double complex); +long double complex casinl(long double complex); +long double complex catanl(long double complex); +long double complex ccosl(long double complex); +long double complex csinl(long double complex); +long double complex ctanl(long double complex); +long double complex cacoshl(long double complex); +long double complex casinhl(long double complex); +long double complex catanhl(long double complex); +long double complex ccoshl(long double complex); +long double complex csinhl(long double complex); +long double complex ctanhl(long double complex); +long double complex cexpl(long double complex); +long double complex clogl(long double complex); +long double cabsl(long double complex); +long double complex cpowl(long double complex, + long double complex); +long double complex csqrtl(long double complex); +long double cargl(long double complex); +long double cimagl(long double complex); +long double complex conjl(long double complex); +long double complex cprojl(long double complex); +long double creall(long double complex); +__END_DECLS + +#endif /* !_COMPLEX_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/cpio.h b/lib/libc/include/generic-openbsd/cpio.h new file mode 100644 index 0000000000..b59bcaacb0 --- /dev/null +++ b/lib/libc/include/generic-openbsd/cpio.h @@ -0,0 +1,59 @@ +/* $OpenBSD: cpio.h,v 1.3 2008/06/26 05:42:04 ray Exp $ */ +/* $NetBSD: cpio.h,v 1.1 1996/02/05 22:34:11 jtc Exp $ */ + +/*- + * Copyright (c) 1996 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by J.T. Conklin. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _CPIO_H_ +#define _CPIO_H_ + +#define C_IRUSR 0000400 +#define C_IWUSR 0000200 +#define C_IXUSR 0000100 +#define C_IRGRP 0000040 +#define C_IWGRP 0000020 +#define C_IXGRP 0000010 +#define C_IROTH 0000004 +#define C_IWOTH 0000002 +#define C_IXOTH 0000001 +#define C_ISUID 0004000 +#define C_ISGID 0002000 +#define C_ISVTX 0001000 +#define C_ISDIR 0040000 +#define C_ISFIFO 0010000 +#define C_ISREG 0100000 +#define C_ISBLK 0060000 +#define C_ISCHR 0020000 +#define C_ISCTG 0110000 +#define C_ISLNK 0120000 +#define C_ISSOCK 0140000 + +#define MAGIC "070707" + +#endif /* _CPIO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ctype.h b/lib/libc/include/generic-openbsd/ctype.h new file mode 100644 index 0000000000..dacd82ae9c --- /dev/null +++ b/lib/libc/include/generic-openbsd/ctype.h @@ -0,0 +1,309 @@ +/* $OpenBSD: ctype.h,v 1.26 2024/02/04 13:03:18 jca Exp $ */ +/* $NetBSD: ctype.h,v 1.14 1994/10/26 00:55:47 cgd Exp $ */ + +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)ctype.h 5.3 (Berkeley) 4/3/91 + */ + +#ifndef _CTYPE_H_ +#define _CTYPE_H_ + +#include + +#define _CTYPE_U 0x01 +#define _CTYPE_L 0x02 +#define _CTYPE_N 0x04 +#define _CTYPE_S 0x08 +#define _CTYPE_P 0x10 +#define _CTYPE_C 0x20 +#define _CTYPE_X 0x40 +#define _CTYPE_B 0x80 + +#if __POSIX_VISIBLE >= 200809 +#ifndef _LOCALE_T_DEFINED_ +#define _LOCALE_T_DEFINED_ +typedef void *locale_t; +#endif +#endif + +__BEGIN_DECLS + +extern const char *_ctype_; +extern const short *_tolower_tab_; +extern const short *_toupper_tab_; + +#if defined(__GNUC__) || defined(_ANSI_LIBRARY) +int isalnum(int); +int isalpha(int); +int iscntrl(int); +int isdigit(int); +int isgraph(int); +int islower(int); +int isprint(int); +int ispunct(int); +int isspace(int); +int isupper(int); +int isxdigit(int); +int tolower(int); +int toupper(int); + +#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE > 200112 \ + || __XPG_VISIBLE > 600 +int isblank(int); +#endif + +#if __BSD_VISIBLE || __XPG_VISIBLE +int isascii(int); +int toascii(int); +int _tolower(int); +int _toupper(int); +#endif /* __BSD_VISIBLE || __XPG_VISIBLE */ + +#if __POSIX_VISIBLE >= 200809 +int isalnum_l(int, locale_t); +int isalpha_l(int, locale_t); +int isblank_l(int, locale_t); +int iscntrl_l(int, locale_t); +int isdigit_l(int, locale_t); +int isgraph_l(int, locale_t); +int islower_l(int, locale_t); +int isprint_l(int, locale_t); +int ispunct_l(int, locale_t); +int isspace_l(int, locale_t); +int isupper_l(int, locale_t); +int isxdigit_l(int, locale_t); +int tolower_l(int, locale_t); +int toupper_l(int, locale_t); +#endif + +#endif /* __GNUC__ || _ANSI_LIBRARY */ + +#if !defined(_ANSI_LIBRARY) && !defined(__cplusplus) + +__only_inline int isalnum(int _c) +{ + return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & + (_CTYPE_U|_CTYPE_L|_CTYPE_N))); +} + +__only_inline int isalpha(int _c) +{ + return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & + (_CTYPE_U|_CTYPE_L))); +} + +__only_inline int iscntrl(int _c) +{ + return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _CTYPE_C)); +} + +__only_inline int isdigit(int _c) +{ + return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _CTYPE_N)); +} + +__only_inline int isgraph(int _c) +{ + return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & + (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_N))); +} + +__only_inline int islower(int _c) +{ + return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _CTYPE_L)); +} + +__only_inline int isprint(int _c) +{ + return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & + (_CTYPE_P|_CTYPE_U|_CTYPE_L|_CTYPE_N|_CTYPE_B))); +} + +__only_inline int ispunct(int _c) +{ + return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _CTYPE_P)); +} + +__only_inline int isspace(int _c) +{ + return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _CTYPE_S)); +} + +__only_inline int isupper(int _c) +{ + return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _CTYPE_U)); +} + +__only_inline int isxdigit(int _c) +{ + return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & + (_CTYPE_N|_CTYPE_X))); +} + +__only_inline int tolower(int _c) +{ + if ((unsigned int)_c > 255) + return (_c); + return ((_tolower_tab_ + 1)[_c]); +} + +__only_inline int toupper(int _c) +{ + if ((unsigned int)_c > 255) + return (_c); + return ((_toupper_tab_ + 1)[_c]); +} + +#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE > 200112 \ + || __XPG_VISIBLE > 600 +__only_inline int isblank(int _c) +{ + return (_c == ' ' || _c == '\t'); +} +#endif + +#if __BSD_VISIBLE || __XPG_VISIBLE +__only_inline int isascii(int _c) +{ + return ((unsigned int)_c <= 0177); +} + +__only_inline int toascii(int _c) +{ + return (_c & 0177); +} + +__only_inline int _tolower(int _c) +{ + return (_c - 'A' + 'a'); +} + +__only_inline int _toupper(int _c) +{ + return (_c - 'a' + 'A'); +} +#endif /* __BSD_VISIBLE || __XPG_VISIBLE */ + +#if __POSIX_VISIBLE >= 200809 +__only_inline int +isalnum_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return isalnum(_c); +} + +__only_inline int +isalpha_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return isalpha(_c); +} + +__only_inline int +isblank_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return isblank(_c); +} + +__only_inline int +iscntrl_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return iscntrl(_c); +} + +__only_inline int +isdigit_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return isdigit(_c); +} + +__only_inline int +isgraph_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return isgraph(_c); +} + +__only_inline int +islower_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return islower(_c); +} + +__only_inline int +isprint_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return isprint(_c); +} + +__only_inline int +ispunct_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return ispunct(_c); +} + +__only_inline int +isspace_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return isspace(_c); +} + +__only_inline int +isupper_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return isupper(_c); +} + +__only_inline int +isxdigit_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return isxdigit(_c); +} + +__only_inline int +tolower_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return tolower(_c); +} + +__only_inline int +toupper_l(int _c, locale_t _l __attribute__((__unused__))) +{ + return toupper(_c); +} +#endif /* __POSIX_VISIBLE >= 200809 */ + +#endif /* !_ANSI_LIBRARY */ + +__END_DECLS + +#endif /* !_CTYPE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/db.h b/lib/libc/include/generic-openbsd/db.h new file mode 100644 index 0000000000..13678ac00b --- /dev/null +++ b/lib/libc/include/generic-openbsd/db.h @@ -0,0 +1,161 @@ +/* $OpenBSD: db.h,v 1.12 2015/10/17 21:48:42 guenther Exp $ */ +/* $NetBSD: db.h,v 1.13 1994/10/26 00:55:48 cgd Exp $ */ + +/*- + * Copyright (c) 1990, 1993, 1994 + * 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. + * + * @(#)db.h 8.7 (Berkeley) 6/16/94 + */ + +#ifndef _DB_H_ +#define _DB_H_ + +#include + +#include + +#define RET_ERROR -1 /* Return values. */ +#define RET_SUCCESS 0 +#define RET_SPECIAL 1 + +#define MAX_PAGE_NUMBER 0xffffffff /* >= # of pages in a file */ +typedef u_int32_t pgno_t; +#define MAX_PAGE_OFFSET 65535 /* >= # of bytes in a page */ +typedef u_int16_t indx_t; +#define MAX_REC_NUMBER 0xffffffff /* >= # of records in a tree */ +typedef u_int32_t recno_t; + +/* Key/data structure -- a Data-Base Thang. */ +typedef struct { + void *data; /* data */ + size_t size; /* data length */ +} DBT; + +/* Routine flags. */ +#define R_CURSOR 1 /* del, put, seq */ +#define __R_UNUSED 2 /* UNUSED */ +#define R_FIRST 3 /* seq */ +#define R_IAFTER 4 /* put (RECNO) */ +#define R_IBEFORE 5 /* put (RECNO) */ +#define R_LAST 6 /* seq (BTREE, RECNO) */ +#define R_NEXT 7 /* seq */ +#define R_NOOVERWRITE 8 /* put */ +#define R_PREV 9 /* seq (BTREE, RECNO) */ +#define R_SETCURSOR 10 /* put (RECNO) */ +#define R_RECNOSYNC 11 /* sync (RECNO) */ + +typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE; + +/* + * !!! + * The following flags are included in the dbopen(3) call as part of the + * open(2) flags. In order to avoid conflicts with the open flags, start + * at the top of the 16 or 32-bit number space and work our way down. If + * the open flags were significantly expanded in the future, it could be + * a problem. Wish I'd left another flags word in the dbopen call. + * + * !!! + * None of this stuff is implemented yet. The only reason that it's here + * is so that the access methods can skip copying the key/data pair when + * the DB_LOCK flag isn't set. + */ +#if UINT_MAX > 65535 +#define DB_LOCK 0x20000000 /* Do locking. */ +#define DB_SHMEM 0x40000000 /* Use shared memory. */ +#define DB_TXN 0x80000000 /* Do transactions. */ +#else +#define DB_LOCK 0x2000 /* Do locking. */ +#define DB_SHMEM 0x4000 /* Use shared memory. */ +#define DB_TXN 0x8000 /* Do transactions. */ +#endif + +/* Access method description structure. */ +typedef struct __db { + DBTYPE type; /* Underlying db type. */ + int (*close)(struct __db *); + int (*del)(const struct __db *, const DBT *, unsigned int); + int (*get)(const struct __db *, const DBT *, DBT *, unsigned int); + int (*put)(const struct __db *, DBT *, const DBT *, unsigned int); + int (*seq)(const struct __db *, DBT *, DBT *, unsigned int); + int (*sync)(const struct __db *, unsigned int); + void *internal; /* Access method private. */ + int (*fd)(const struct __db *); +} DB; + +#define BTREEMAGIC 0x053162 +#define BTREEVERSION 3 + +/* Structure used to pass parameters to the btree routines. */ +typedef struct { +#define R_DUP 0x01 /* duplicate keys */ + unsigned long flags; + unsigned int cachesize; /* bytes to cache */ + int maxkeypage; /* maximum keys per page */ + int minkeypage; /* minimum keys per page */ + unsigned int psize; /* page size */ + int (*compare) /* comparison function */ + (const DBT *, const DBT *); + size_t (*prefix) /* prefix function */ + (const DBT *, const DBT *); + int lorder; /* byte order */ +} BTREEINFO; + +#define HASHMAGIC 0x061561 +#define HASHVERSION 2 + +/* Structure used to pass parameters to the hashing routines. */ +typedef struct { + unsigned int bsize; /* bucket size */ + unsigned int ffactor; /* fill factor */ + unsigned int nelem; /* number of elements */ + unsigned int cachesize; /* bytes to cache */ + u_int32_t /* hash function */ + (*hash)(const void *, size_t); + int lorder; /* byte order */ +} HASHINFO; + +/* Structure used to pass parameters to the record routines. */ +typedef struct { +#define R_FIXEDLEN 0x01 /* fixed-length records */ +#define R_NOKEY 0x02 /* key not required */ +#define R_SNAPSHOT 0x04 /* snapshot the input */ + unsigned long flags; + unsigned int cachesize; /* bytes to cache */ + unsigned int psize; /* page size */ + int lorder; /* byte order */ + size_t reclen; /* record length + (fixed-length records) */ + unsigned char bval; /* delimiting byte + (variable-length records) */ + char *bfname; /* btree file name */ +} RECNOINFO; + +__BEGIN_DECLS +DB *dbopen(const char *, int, int, DBTYPE, const void *); +__END_DECLS +#endif /* !_DB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ddb/db_access.h b/lib/libc/include/generic-openbsd/ddb/db_access.h new file mode 100644 index 0000000000..6b5fa5d799 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ddb/db_access.h @@ -0,0 +1,40 @@ +/* $OpenBSD: db_access.h,v 1.12 2024/02/23 18:19:02 cheloha Exp $ */ +/* $NetBSD: db_access.h,v 1.6 1994/10/09 08:29:57 mycroft Exp $ */ + +/* + * Mach Operating System + * Copyright (c) 1993,1992,1991,1990 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + * + * Author: David B. Golub, Carnegie Mellon University + * Date: 7/90 + */ + +/* + * Data access functions for debugger. + */ +db_expr_t db_get_value(vaddr_t, size_t, int); +void db_put_value(vaddr_t, size_t, db_expr_t); + +void db_read_bytes(vaddr_t, size_t, void *); +void db_write_bytes(vaddr_t, size_t, void *); \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ddb/db_break.h b/lib/libc/include/generic-openbsd/ddb/db_break.h new file mode 100644 index 0000000000..63cbd0b59d --- /dev/null +++ b/lib/libc/include/generic-openbsd/ddb/db_break.h @@ -0,0 +1,61 @@ +/* $OpenBSD: db_break.h,v 1.12 2019/11/07 13:16:25 mpi Exp $ */ +/* $NetBSD: db_break.h,v 1.8 1996/02/05 01:56:52 christos Exp $ */ + +/* + * Mach Operating System + * Copyright (c) 1993,1992,1991,1990 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + * + * Author: David B. Golub, Carnegie Mellon University + * Date: 7/90 + */ + +#ifndef _DDB_DB_BREAK_H_ +#define _DDB_DB_BREAK_H_ + +#include + +/* + * Breakpoints. + */ +typedef struct db_breakpoint { + vaddr_t address; /* set here */ + int init_count; /* number of times to skip bkpt */ + int count; /* current count */ + int flags; /* flags: */ +#define BKPT_SINGLE_STEP 0x2 /* to simulate single step */ +#define BKPT_TEMP 0x4 /* temporary */ + int bkpt_inst; /* saved instruction at bkpt */ + struct db_breakpoint *link; /* link in in-use or free chain */ +} *db_breakpoint_t; + +db_breakpoint_t db_find_breakpoint(vaddr_t); +void db_set_breakpoints(void); +void db_clear_breakpoints(void); +db_breakpoint_t db_set_temp_breakpoint(vaddr_t); +void db_delete_temp_breakpoint(db_breakpoint_t); +void db_delete_cmd(db_expr_t, int, db_expr_t, char *); +void db_breakpoint_cmd(db_expr_t, int, db_expr_t, char *); +void db_listbreak_cmd(db_expr_t, int, db_expr_t, char *); + +#endif /* _DDB_DB_BREAK_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ddb/db_command.h b/lib/libc/include/generic-openbsd/ddb/db_command.h new file mode 100644 index 0000000000..3a8d81bd96 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ddb/db_command.h @@ -0,0 +1,62 @@ +/* $OpenBSD: db_command.h,v 1.35 2022/04/14 19:47:12 naddy Exp $ */ +/* $NetBSD: db_command.h,v 1.8 1996/02/05 01:56:55 christos Exp $ */ + +/* + * Mach Operating System + * Copyright (c) 1993,1992,1991,1990 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + * + * Author: David B. Golub, Carnegie Mellon University + * Date: 7/90 + */ + +/* + * Command loop declarations. + */ +struct db_command; + +void db_error(char *); +void db_skip_to_eol(void); +void db_command_loop(void); +void db_command(const struct db_command **, const struct db_command *); + +extern vaddr_t db_dot, db_last_addr, db_prev, db_next; + +/* + * Command table + */ +struct db_command { + char *name; /* command name */ + /* function to call */ + void (*fcn)(db_expr_t, int, db_expr_t, char *); + int flag; /* extra info: */ +#define CS_OWN 0x1 /* non-standard syntax */ +#define CS_MORE 0x2 /* standard syntax, but may have other + words at end */ +#define CS_SET_DOT 0x100 /* set dot after command */ + const struct db_command *more; /* another level of command */ +}; + +#ifdef DB_MACHINE_COMMANDS +extern const struct db_command db_machine_command_table[]; +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ddb/db_elf.h b/lib/libc/include/generic-openbsd/ddb/db_elf.h new file mode 100644 index 0000000000..a57ca0bfab --- /dev/null +++ b/lib/libc/include/generic-openbsd/ddb/db_elf.h @@ -0,0 +1,48 @@ +/* $OpenBSD: db_elf.h,v 1.3 2024/11/07 16:02:29 miod Exp $ */ +/* $NetBSD: db_elf.c,v 1.13 2000/07/07 21:55:18 jhawk Exp $ */ + +/*- + * Copyright (c) 1997 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +typedef struct { + const char *name; /* symtab name */ + char *start; /* symtab location */ + char *end; + char *private; /* optional machdep pointer */ +} db_symtab_t; + + +#define STAB_TO_SYMSTART(stab) ((Elf_Sym *)((stab)->start)) +#define STAB_TO_SYMEND(stab) ((Elf_Sym *)((stab)->end)) +#define STAB_TO_EHDR(stab) ((Elf_Ehdr *)((stab)->private)) +#define STAB_TO_SHDR(stab, e) ((Elf_Shdr *)((stab)->private + (e)->e_shoff)) + +const char *db_elf_find_strtab(db_symtab_t *); +const char *db_elf_find_section(db_symtab_t *, size_t *, const char *); \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ddb/db_extern.h b/lib/libc/include/generic-openbsd/ddb/db_extern.h new file mode 100644 index 0000000000..02a6650ced --- /dev/null +++ b/lib/libc/include/generic-openbsd/ddb/db_extern.h @@ -0,0 +1,64 @@ +/* $OpenBSD: db_extern.h,v 1.22 2024/05/13 01:15:50 jsg Exp $ */ +/* $NetBSD: db_extern.h,v 1.1 1996/02/05 01:57:00 christos Exp $ */ + +/* + * Copyright (c) 1995 Christos Zoulas. 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 Christos Zoulas. + * 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 _DDB_DB_EXTERN_H_ +#define _DDB_DB_EXTERN_H_ + +/* db_sym.c */ +void ddb_init(void); + +/* db_examine.c */ +void db_examine_cmd(db_expr_t, int, db_expr_t, char *); +void db_print_cmd(db_expr_t, int, db_expr_t, char *); +void db_search_cmd(db_expr_t, int, db_expr_t, char *); +void db_print_loc_and_inst(vaddr_t); +size_t db_strlcpy(char *, const char *, size_t); + +/* db_expr.c */ +int db_expression(db_expr_t *); + +/* db_hangman.c */ +void db_hangman(db_expr_t, int, db_expr_t, char *); + +/* db_input.c */ +int db_readline(char *, int); + +/* db_trap.c */ +void db_trap(int, int); + +/* db_prof.c */ +int db_prof_enable(void); +void db_prof_disable(void); + +/* db_ctf.c */ +void db_ctf_init(void); + +#endif /* _DDB_DB_EXTERN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ddb/db_interface.h b/lib/libc/include/generic-openbsd/ddb/db_interface.h new file mode 100644 index 0000000000..b13f0be9f3 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ddb/db_interface.h @@ -0,0 +1,86 @@ +/* $OpenBSD: db_interface.h,v 1.28 2024/09/05 08:52:27 bluhm Exp $ */ +/* $NetBSD: db_interface.h,v 1.1 1996/02/05 01:57:03 christos Exp $ */ + +/* + * Copyright (c) 1995 Christos Zoulas. 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 Christos Zoulas. + * 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 _DDB_DB_INTERFACE_H_ +#define _DDB_DB_INTERFACE_H_ + +/* arch///db_trace.c */ +void db_stack_trace_print(db_expr_t, int, db_expr_t, char *, + int (*)(const char *, ...)); + +/* arch///db_disasm.c */ +vaddr_t db_disasm(vaddr_t, int); + +/* kern/kern_proc.c */ +void db_kill_cmd(db_expr_t, int, db_expr_t, char *); +void db_show_all_procs(db_expr_t, int, db_expr_t, char *); + +/* kern/kern_clockintr.c */ +void db_show_all_clockintr(db_expr_t, int, db_expr_t, char *); + +/* kern/kern_timeout.c */ +void db_show_callout(db_expr_t, int, db_expr_t, char *); + +struct mount; + +/* kern/vfs_subr.c */ +void vfs_buf_print(void *, int, int (*)(const char *, ...)); +void vfs_vnode_print(void *, int, int (*)(const char *, ...)); +void vfs_mount_print(struct mount *, int, int (*)(const char *, ...)); + +/* kern/subr_pool.c */ +void db_show_all_pools(db_expr_t, int, db_expr_t, char *); + +/* kern/uipc_mbuf.c */ +void m_print(void *, int (*)(const char *, ...)); +void m_print_chain(void *, int, int (*)(const char *, ...)); +void m_print_packet(void *, int, int (*)(const char *, ...)); + +/* kern/uipc_socket.c */ +void so_print(void *, int (*)(const char *, ...)); + +struct rtentry; +int db_show_rtentry(struct rtentry *, void *, unsigned int); +int db_show_rtable(int, unsigned int); + +/* nfs/nfs_debug.c */ +void db_show_all_nfsreqs(db_expr_t, int, db_expr_t, char *); +void nfs_request_print(void *, int, int (*)(const char *, ...)); +void db_show_all_nfsnodes(db_expr_t, int, db_expr_t, char *); +void nfs_node_print(void *, int, int (*)(const char *, ...)); + +/* uvm/uvm_swap.c */ +void swap_print_all(int (*)(const char *, ...)); + +/* arch///db_interface.c */ +void db_machine_init(void); + +#endif /* _DDB_DB_INTERFACE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ddb/db_lex.h b/lib/libc/include/generic-openbsd/ddb/db_lex.h new file mode 100644 index 0000000000..5aeb188575 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ddb/db_lex.h @@ -0,0 +1,66 @@ +/* $OpenBSD: db_lex.h,v 1.9 2016/04/19 12:23:25 mpi Exp $ */ +/* $NetBSD: db_lex.h,v 1.7 1996/02/05 01:57:07 christos Exp $ */ + +/* + * Mach Operating System + * Copyright (c) 1993,1992,1991,1990 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + * + * Author: David B. Golub, Carnegie Mellon University + * Date: 7/90 + */ + +/* + * Lexical analyzer. + */ +int db_read_line(void); +void db_unread_token(int); +int db_read_token(void); +void db_flush_lex(void); +int db_lex(void); + +extern db_expr_t db_tok_number; +#define TOK_STRING_SIZE 120 +extern char db_tok_string[TOK_STRING_SIZE]; + +#define tEOF (-1) +#define tEOL 1 +#define tNUMBER 2 +#define tIDENT 3 +#define tPLUS 4 +#define tMINUS 5 +#define tDOT 6 +#define tSTAR 7 +#define tSLASH 8 +#define tEQ 9 +#define tLPAREN 10 +#define tRPAREN 11 +#define tPCT 12 +#define tHASH 13 +#define tCOMMA 14 +#define tDITTO 15 +#define tDOLLAR 16 +#define tEXCL 17 +#define tSHIFT_L 18 +#define tSHIFT_R 19 +#define tDOTDOT 20 \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ddb/db_output.h b/lib/libc/include/generic-openbsd/ddb/db_output.h new file mode 100644 index 0000000000..9c6aa0719d --- /dev/null +++ b/lib/libc/include/generic-openbsd/ddb/db_output.h @@ -0,0 +1,65 @@ +/* $OpenBSD: db_output.h,v 1.17 2021/02/09 14:37:13 jcs Exp $ */ +/* $NetBSD: db_output.h,v 1.9 1996/04/04 05:13:50 cgd Exp $ */ + +/* + * Mach Operating System + * Copyright (c) 1993,1992,1991,1990 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + * + * Author: David B. Golub, Carnegie Mellon University + * Date: 8/90 + */ + +/* + * Printing routines for kernel debugger. + */ +void db_force_whitespace(void); +void db_putchar(int); +int db_print_position(void); +int db_printf(const char *, ...) + __attribute__((__format__(__kprintf__,1,2))); +int db_vprintf(const char *, va_list) + __attribute__((__format__(__kprintf__,1,0))); +void db_end_line(int); +void db_resize(int, int); + +/* + * This is a replacement for the non-standard %z, %n and %r printf formats + * in db_printf. + * + * db_format(buf, bufsize, val, format, alt, width) + * + * val is the value we want printed. + * format is one of DB_FORMAT_[ZRN] + * alt specifies if we should provide an "alternate" format (# in the printf + * format). + * width is the field width. 0 is the same as no width specifier. + */ +#define DB_FORMAT_Z 1 +#define DB_FORMAT_R 2 +#define DB_FORMAT_N 3 +#define DB_FORMAT_BUF_SIZE 64 /* should be plenty for all formats */ +char *db_format(char *, size_t, long, int, int, int); + +/* XXX - this is the wrong place, but we have no better. */ +void db_stack_dump(void); \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ddb/db_run.h b/lib/libc/include/generic-openbsd/ddb/db_run.h new file mode 100644 index 0000000000..b5354473ac --- /dev/null +++ b/lib/libc/include/generic-openbsd/ddb/db_run.h @@ -0,0 +1,66 @@ +/* $OpenBSD: db_run.h,v 1.12 2019/11/06 07:30:08 mpi Exp $ */ +/* $NetBSD: db_run.h,v 1.3 1996/02/05 01:57:14 christos Exp $ */ + +/* + * Mach Operating System + * Copyright (c) 1993,1992,1991,1990 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + * + * Author: David B. Golub, Carnegie Mellon University + * Date: 7/90 + */ + +#ifndef _DDB_DB_RUN_ +#define _DDB_DB_RUN_ + +/* + * Commands to run process. + */ +extern int db_inst_count; +extern int db_cmd_loop_done; + +int db_stop_at_pc(db_regs_t *, int *); +void db_restart_at_pc(db_regs_t *, int); +void db_single_step(db_regs_t *); +#ifndef db_set_single_step +void db_set_single_step(db_regs_t *); +#endif +#ifndef db_clear_single_step +void db_clear_single_step(db_regs_t *); +#endif +void db_single_step_cmd(db_expr_t, int, db_expr_t, char *); +void db_trace_until_call_cmd(db_expr_t, int, db_expr_t, char *); +void db_trace_until_matching_cmd(db_expr_t, int, db_expr_t, char *); +void db_continue_cmd(db_expr_t, int, db_expr_t, char *); + +#ifdef SOFTWARE_SSTEP +/* + * I've seen this defined to (0) when it is not needed and then the proto will + * not be correct, so skip it then. + */ +#ifndef getreg_val +extern register_t getreg_val(db_regs_t *, int); +#endif +#endif /* SOFTWARE_SSTEP */ + +#endif /* _DDB_DB_RUN_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ddb/db_sym.h b/lib/libc/include/generic-openbsd/ddb/db_sym.h new file mode 100644 index 0000000000..4d91c1df20 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ddb/db_sym.h @@ -0,0 +1,97 @@ +/* $NetBSD: db_sym.h,v 1.13 2000/05/25 19:57:36 jhawk Exp $ */ + +/* + * Mach Operating System + * Copyright (c) 1993,1992,1991,1990 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + * + * Author: Alessandro Forin, Carnegie Mellon University + * Date: 8/90 + */ + +#ifndef _DDB_DB_SYM_H_ +#define _DDB_DB_SYM_H_ + +#include +#include + +/* + * Non-stripped symbol tables will have duplicates, for instance + * the same string could match a parameter name, a local var, a + * global var, etc. + * We are most concern with the following matches. + */ +typedef int db_strategy_t; /* search strategy */ + +#define DB_STGY_ANY 0 /* anything goes */ +#define DB_STGY_XTRN 1 /* only external symbols */ +#define DB_STGY_PROC 2 /* only procedures */ + + +/* + * Internal db_forall function calling convention: + * + * (*db_forall_func)(sym, name, suffix, arg); + * + * symbol is the (opaque) symbol pointer, name the name of the symbol, + * suffix a string representing the type, and arg an opaque argument to + * be passed in. + */ +typedef void (db_forall_func_t)(Elf_Sym *, const char *, const char *, void *); + +extern unsigned int db_maxoff; /* like gdb's "max-symbolic-offset" */ + +int db_eqname(const char *, const char *, int); + /* strcmp, modulo leading char */ + +Elf_Sym * db_symbol_by_name(const char *, db_expr_t *); + /* find symbol value given name */ + +Elf_Sym * db_search_symbol(vaddr_t, db_strategy_t, db_expr_t *); + /* find symbol given value */ + +void db_symbol_values(Elf_Sym *, const char **, db_expr_t *); + /* return name and value of symbol */ + +#define db_find_sym_and_offset(val,namep,offp) \ + db_symbol_values(db_search_symbol(val,DB_STGY_ANY,offp),namep,NULL) + /* find name&value given approx val */ + +#define db_find_xtrn_sym_and_offset(val,namep,offp) \ + db_symbol_values(db_search_symbol(val,DB_STGY_XTRN,offp),namep,NULL) + /* ditto, but no locals */ + +void db_printsym(db_expr_t, db_strategy_t, int (*)(const char *, ...)); + /* print closest symbol to a value */ + +int db_elf_sym_init(int, void *, void *, const char *); +Elf_Sym * db_elf_sym_search(vaddr_t, db_strategy_t, db_expr_t *); +int db_elf_line_at_pc(Elf_Sym *, const char **, int *, db_expr_t); +void db_elf_sym_forall(db_forall_func_t db_forall_func, void *); + +bool db_dwarf_line_at_pc(const char *, size_t, uintptr_t, + const char **, const char **, int *); + +int db_ctf_func_numargs(Elf_Sym *); + +#endif /* _DDB_DB_SYM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ddb/db_var.h b/lib/libc/include/generic-openbsd/ddb/db_var.h new file mode 100644 index 0000000000..29dbce1adc --- /dev/null +++ b/lib/libc/include/generic-openbsd/ddb/db_var.h @@ -0,0 +1,79 @@ +/* $OpenBSD: db_var.h,v 1.15 2025/05/19 21:48:28 kettenis Exp $ */ + +/* + * Copyright (c) 1996 Michael Shalayeff. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR 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. + */ + +/* + * Different parameters/structures/functions + */ + +#ifndef _DDB_DB_VAR_H_ +#define _DDB_DB_VAR_H_ + +#ifndef DB_HISTORY_SIZE +#define DB_HISTORY_SIZE 4000 +#endif + +#define DBCTL_RADIX 1 +#define DBCTL_MAXWIDTH 2 +#define DBCTL_MAXLINE 3 +#define DBCTL_TABSTOP 4 +#define DBCTL_PANIC 5 +#define DBCTL_CONSOLE 6 +#define DBCTL_LOG 7 +#define DBCTL_TRIGGER 8 +#define DBCTL_PROFILE 9 +#define DBCTL_SUSPEND 10 +#define DBCTL_MAXID 11 + +#define CTL_DDB_NAMES { \ + { NULL, 0 }, \ + { "radix", CTLTYPE_INT }, \ + { "max_width", CTLTYPE_INT }, \ + { "max_line", CTLTYPE_INT }, \ + { "tab_stop_width", CTLTYPE_INT },\ + { "panic", CTLTYPE_INT }, \ + { "console", CTLTYPE_INT }, \ + { "log", CTLTYPE_INT }, \ + { "trigger", CTLTYPE_INT }, \ + { "profile", CTLTYPE_INT }, \ + { "suspend", CTLTYPE_INT }, \ +} + +#ifdef _KERNEL +extern int db_radix; +extern int db_max_width; +extern int db_tab_stop_width; +extern int db_max_line; +extern int db_panic; +extern int db_console; +extern int db_log; +extern int db_profile; +extern int db_suspend; + +int ddb_sysctl(int *, u_int, void *, size_t *, void *, size_t, + struct proc *); +#endif + +#endif /* _DDB_DB_VAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ddb/db_variables.h b/lib/libc/include/generic-openbsd/ddb/db_variables.h new file mode 100644 index 0000000000..c3c5cbc67c --- /dev/null +++ b/lib/libc/include/generic-openbsd/ddb/db_variables.h @@ -0,0 +1,62 @@ +/* $OpenBSD: db_variables.h,v 1.8 2016/01/25 14:30:30 mpi Exp $ */ +/* $NetBSD: db_variables.h,v 1.5 1996/02/05 01:57:21 christos Exp $ */ + +/* + * Mach Operating System + * Copyright (c) 1993,1992,1991,1990 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + * + * Author: David B. Golub, Carnegie Mellon University + * Date: 7/90 + */ + +#ifndef _DB_VARIABLES_H_ +#define _DB_VARIABLES_H_ + +/* + * Debugger variables. + */ +struct db_variable { + char *name; /* Name of variable */ + long *valuep; /* value of variable */ + /* function to call when reading/writing */ + int (*fcn)(struct db_variable *, db_expr_t *, int); +#define DB_VAR_GET 0 +#define DB_VAR_SET 1 +}; +#define FCN_NULL ((int (*)(struct db_variable *, db_expr_t *, int))0) + +extern struct db_variable db_vars[]; /* debugger variables */ +extern struct db_variable *db_evars; +extern struct db_variable db_regs[]; /* machine registers */ +extern struct db_variable *db_eregs; + +int db_find_variable(struct db_variable **); +int db_get_variable(db_expr_t *); +int db_set_variable(db_expr_t); +void db_read_variable(struct db_variable *, db_expr_t *); +void db_write_variable(struct db_variable *, db_expr_t *); +void db_set_cmd(db_expr_t, int, db_expr_t, char *); +int db_var_rw_int(struct db_variable *, db_expr_t *, int); + +#endif /* _DB_VARIABLES_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ddb/db_watch.h b/lib/libc/include/generic-openbsd/ddb/db_watch.h new file mode 100644 index 0000000000..8d3c4e0d5e --- /dev/null +++ b/lib/libc/include/generic-openbsd/ddb/db_watch.h @@ -0,0 +1,56 @@ +/* $OpenBSD: db_watch.h,v 1.11 2019/11/07 13:16:25 mpi Exp $ */ +/* $NetBSD: db_watch.h,v 1.9 1996/02/05 01:57:24 christos Exp $ */ + +/* + * Mach Operating System + * Copyright (c) 1993,1992,1991,1990 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + * + * Author: David B. Golub, Carnegie Mellon University + * Date: 10/90 + */ + +#ifndef _DDB_DB_WATCH_ +#define _DDB_DB_WATCH_ + +/* + * Watchpoint. + */ +typedef struct db_watchpoint { + vaddr_t loaddr; /* from this address */ + vaddr_t hiaddr; /* to this address */ + struct db_watchpoint *link; /* link in in-use or free chain */ +} *db_watchpoint_t; + +db_watchpoint_t db_watchpoint_alloc(void); +void db_watchpoint_free(db_watchpoint_t); +void db_set_watchpoint(vaddr_t, vsize_t); +void db_delete_watchpoint(vaddr_t); +void db_list_watchpoints(void); +void db_deletewatch_cmd(db_expr_t, int, db_expr_t, char *); +void db_watchpoint_cmd(db_expr_t, int, db_expr_t, char *); +void db_listwatch_cmd(db_expr_t, int, db_expr_t, char *); +void db_set_watchpoints(void); +void db_clear_watchpoints(void); + +#endif /* _DDB_DB_WATCH_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/dirent.h b/lib/libc/include/generic-openbsd/dirent.h new file mode 100644 index 0000000000..895284c4b7 --- /dev/null +++ b/lib/libc/include/generic-openbsd/dirent.h @@ -0,0 +1,107 @@ +/* $OpenBSD: dirent.h,v 1.35 2024/04/15 15:47:58 florian Exp $ */ +/* $NetBSD: dirent.h,v 1.9 1995/03/26 20:13:37 jtc Exp $ */ + +/*- + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)dirent.h 8.2 (Berkeley) 7/28/94 + */ + +#ifndef _DIRENT_H_ +#define _DIRENT_H_ + +#include + +/* + * POSIX doesn't mandate this, but X/Open XPG 4.2 does. + */ +#if __BSD_VISIBLE || __XPG_VISIBLE >= 400 +#include +#else +#include +#endif + +/* + * The kernel defines the format of directory entries returned by + * the getdents(2) system call. + */ +#include + +#if __BSD_VISIBLE || __XPG_VISIBLE +#define d_ino d_fileno /* backward compatibility */ +#endif + +typedef struct _dirdesc DIR; + +#if __BSD_VISIBLE + +/* definitions for library routines operating on directories. */ +#define DIRBLKSIZ 1024 + +#include + +#endif /* __BSD_VISIBLE */ + +__BEGIN_DECLS +DIR *opendir(const char *); +#if __POSIX_VISIBLE >= 200809 +DIR *fdopendir(int); +#endif +struct dirent *readdir(DIR *); +void rewinddir(DIR *); +int closedir(DIR *); +#if __BSD_VISIBLE +int getdents(int, void *, size_t) + __attribute__ ((__bounded__(__string__,2,3))); +#endif /* __BSD_VISIBLE */ +#if __XPG_VISIBLE +long telldir(DIR *); +void seekdir(DIR *, long); +#endif +#if __POSIX_VISIBLE >= 199506 || __XPG_VISIBLE >= 500 +int readdir_r(DIR *__restrict, struct dirent *__restrict, + struct dirent **__restrict); +#endif +#if __POSIX_VISIBLE >= 200809 +int scandir(const char *, struct dirent ***, int (*)(const struct dirent *), + int (*)(const struct dirent **, const struct dirent **)); +int scandirat(int, const char *, struct dirent ***, + int (*)(const struct dirent *), + int (*)(const struct dirent **, const struct dirent **)); +int alphasort(const struct dirent **, const struct dirent **); +#elif __BSD_VISIBLE +int scandir(const char *, struct dirent ***, int (*)(struct dirent *), + int (*)(const void *, const void *)); +int alphasort(const void *, const void *); +#endif +#if __POSIX_VISIBLE >= 200809 || __XPG_VISIBLE > 600 +int dirfd(DIR *); +#endif +__END_DECLS + +#endif /* !_DIRENT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/dlfcn.h b/lib/libc/include/generic-openbsd/dlfcn.h new file mode 100644 index 0000000000..5097588e7b --- /dev/null +++ b/lib/libc/include/generic-openbsd/dlfcn.h @@ -0,0 +1,110 @@ +/* $OpenBSD: dlfcn.h,v 1.17 2024/09/01 04:27:45 guenther Exp $ */ +/* $NetBSD: dlfcn.h,v 1.2 1995/06/05 19:38:00 pk Exp $ */ + +/* + * Copyright (c) 1995 Paul Kranenburg + * 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 Paul Kranenburg. + * 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 _DLFCN_H_ +#define _DLFCN_H_ + +#include + +/* Values for dlopen `mode'. */ +#define RTLD_LAZY 1 +#define RTLD_NOW 2 +#define RTLD_GLOBAL 0x100 +#define RTLD_LOCAL 0x000 +#define RTLD_TRACE 0x200 +#define RTLD_NODELETE 0x400 +#define RTLD_NOLOAD 0x800 + +/* + * Special handle arguments for dlsym(). + */ +#define RTLD_NEXT ((void *) -1) /* Search subsequent objects. */ +#define RTLD_DEFAULT ((void *) -2) /* Use default search algorithm. */ +#define RTLD_SELF ((void *) -3) /* Search the caller itself. */ + +#if __BSD_VISIBLE || __POSIX_VISIBLE >= 202405 +/* + * Structure filled in by dladdr(). + */ +typedef struct +#if __BSD_VISIBLE + dl_info +#endif +{ + const char *dli_fname; /* Pathname of shared object. */ + void *dli_fbase; /* Base address of shared object. */ + const char *dli_sname; /* Name of nearest symbol. */ + void *dli_saddr; /* Address of nearest symbol. */ +} Dl_info_t; +#endif /* __BSD_VISIBLE || __POSIX_VISIBLE >= 202405 */ + +#if __BSD_VISIBLE +typedef Dl_info_t Dl_info; + +/* + * dlctl() commands + */ +#define DL_GETERRNO 1 +#define DL_SETSRCHPATH x +#define DL_GETLIST x +#define DL_GETREFCNT x +#define DL_GETLOADADDR x +#define DL_SETTHREADLCK 2 +#define DL_SETBINDLCK 3 +#define DL_REFERENCE 4 + +#define DL_LAZY RTLD_LAZY /* Compat */ + +#endif /* __BSD_VISIBLE */ + + +/* + * User interface to the run-time linker. + */ +__BEGIN_DECLS +void *dlopen(const char *, int); +int dlclose(void *); +void *dlsym(void *__restrict, const char *__restrict); +char *dlerror(void); + +#if __BSD_VISIBLE || __POSIX_VISIBLE >= 202405 +int dladdr(const void *__restrict, Dl_info_t *__restrict); +#endif + +#if __BSD_VISIBLE +int dlctl(void *, int, void *); +#endif /* __BSD_VISIBLE */ + +__END_DECLS + +#endif /* _DLFCN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/elf.h b/lib/libc/include/generic-openbsd/elf.h new file mode 100644 index 0000000000..3b09988830 --- /dev/null +++ b/lib/libc/include/generic-openbsd/elf.h @@ -0,0 +1,12 @@ +/* $OpenBSD: elf.h,v 1.1 2017/10/17 09:34:52 mpi Exp $ */ + +/* + * Public domain. + */ + +#ifndef _ELF_H_ +#define _ELF_H_ + +#include + +#endif /* _ELF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/elf_abi.h b/lib/libc/include/generic-openbsd/elf_abi.h new file mode 100644 index 0000000000..e722035d33 --- /dev/null +++ b/lib/libc/include/generic-openbsd/elf_abi.h @@ -0,0 +1,33 @@ +/* $OpenBSD: elf_abi.h,v 1.4 1996/05/22 07:46:22 etheisen Exp $ */ +/* + * Copyright (c) 1996 Erik Theisen + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef _ELF_ABI_H_ +#define _ELF_ABI_H_ + +#include + +#endif /* _ELF_ABI_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/endian.h b/lib/libc/include/generic-openbsd/endian.h new file mode 100644 index 0000000000..f4328aa9de --- /dev/null +++ b/lib/libc/include/generic-openbsd/endian.h @@ -0,0 +1,124 @@ +/* $OpenBSD: endian.h,v 1.25 2014/12/21 04:49:00 guenther 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. + */ + +/* + * Public definitions for little- and big-endian systems. + * This file should be included as in userspace and as + * in the kernel. + * + * System headers that need endian information but that can't or don't + * want to export the public names here should include + * and use the internal names: _BYTE_ORDER, _*_ENDIAN, etc. + */ + +#ifndef _SYS_ENDIAN_H_ +#define _SYS_ENDIAN_H_ + +#include +#include + +/* Public names */ +#define LITTLE_ENDIAN _LITTLE_ENDIAN +#define BIG_ENDIAN _BIG_ENDIAN +#define PDP_ENDIAN _PDP_ENDIAN +#define BYTE_ORDER _BYTE_ORDER + + +/* + * These are specified to be function-like macros to match the spec + */ +#define htobe16(x) __htobe16(x) +#define htobe32(x) __htobe32(x) +#define htobe64(x) __htobe64(x) +#define htole16(x) __htole16(x) +#define htole32(x) __htole32(x) +#define htole64(x) __htole64(x) + +/* POSIX names */ +#define be16toh(x) __htobe16(x) +#define be32toh(x) __htobe32(x) +#define be64toh(x) __htobe64(x) +#define le16toh(x) __htole16(x) +#define le32toh(x) __htole32(x) +#define le64toh(x) __htole64(x) + + +#if __BSD_VISIBLE +#define swap16(x) __swap16(x) +#define swap32(x) __swap32(x) +#define swap64(x) __swap64(x) + +#define swap16_multi(v, n) do { \ + __size_t __swap16_multi_n = (n); \ + __uint16_t *__swap16_multi_v = (v); \ + \ + while (__swap16_multi_n) { \ + *__swap16_multi_v = swap16(*__swap16_multi_v); \ + __swap16_multi_v++; \ + __swap16_multi_n--; \ + } \ +} while (0) + +/* original BSD names */ +#define betoh16(x) __htobe16(x) +#define betoh32(x) __htobe32(x) +#define betoh64(x) __htobe64(x) +#define letoh16(x) __htole16(x) +#define letoh32(x) __htole32(x) +#define letoh64(x) __htole64(x) + +#ifndef htons +/* these were exposed here before */ +#define htons(x) __htobe16(x) +#define htonl(x) __htobe32(x) +#define ntohs(x) __htobe16(x) +#define ntohl(x) __htobe32(x) +#endif + +/* ancient stuff */ +#define NTOHL(x) (x) = ntohl((u_int32_t)(x)) +#define NTOHS(x) (x) = ntohs((u_int16_t)(x)) +#define HTONL(x) (x) = htonl((u_int32_t)(x)) +#define HTONS(x) (x) = htons((u_int16_t)(x)) +#endif /* __BSD_VISIBLE */ + +#ifdef _KERNEL +/* to/from memory conversions */ +#define bemtoh16 __bemtoh16 +#define bemtoh32 __bemtoh32 +#define bemtoh64 __bemtoh64 +#define htobem16 __htobem16 +#define htobem32 __htobem32 +#define htobem64 __htobem64 +#define lemtoh16 __lemtoh16 +#define lemtoh32 __lemtoh32 +#define lemtoh64 __lemtoh64 +#define htolem16 __htolem16 +#define htolem32 __htolem32 +#define htolem64 __htolem64 +#endif /* _KERNEL */ + +#endif /* _SYS_ENDIAN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/err.h b/lib/libc/include/generic-openbsd/err.h new file mode 100644 index 0000000000..e5dda625bc --- /dev/null +++ b/lib/libc/include/generic-openbsd/err.h @@ -0,0 +1,70 @@ +/* $OpenBSD: err.h,v 1.13 2015/08/31 02:53:56 guenther Exp $ */ +/* $NetBSD: err.h,v 1.11 1994/10/26 00:55:52 cgd Exp $ */ + +/*- + * Copyright (c) 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. + * + * @(#)err.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _ERR_H_ +#define _ERR_H_ + +#include +#include /* for __va_list */ + +__BEGIN_DECLS + +__dead void err(int, const char *, ...) + __attribute__((__format__ (printf, 2, 3))); +__dead void verr(int, const char *, __va_list) + __attribute__((__format__ (printf, 2, 0))); +__dead void errc(int, int, const char *, ...) + __attribute__((__format__ (printf, 3, 4))); +__dead void verrc(int, int, const char *, __va_list) + __attribute__((__format__ (printf, 3, 0))); +__dead void errx(int, const char *, ...) + __attribute__((__format__ (printf, 2, 3))); +__dead void verrx(int, const char *, __va_list) + __attribute__((__format__ (printf, 2, 0))); +void warn(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); +void vwarn(const char *, __va_list) + __attribute__((__format__ (printf, 1, 0))); +void warnc(int, const char *, ...) + __attribute__((__format__ (printf, 2, 3))); +void vwarnc(int, const char *, __va_list) + __attribute__((__format__ (printf, 2, 0))); +void warnx(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); +void vwarnx(const char *, __va_list) + __attribute__((__format__ (printf, 1, 0))); + +__END_DECLS + +#endif /* !_ERR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/errno.h b/lib/libc/include/generic-openbsd/errno.h new file mode 100644 index 0000000000..a603438546 --- /dev/null +++ b/lib/libc/include/generic-openbsd/errno.h @@ -0,0 +1,59 @@ +/* $OpenBSD: errno.h,v 1.3 2017/08/10 13:34:46 guenther Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)errno.h 8.5 (Berkeley) 1/21/94 + */ + +#ifndef _ERRNO_H_ +#define _ERRNO_H_ + +#include + +__BEGIN_DECLS +#if __BSD_VISIBLE +#ifndef __SYS_ERRLIST +#define __SYS_ERRLIST +extern int sys_nerr; +extern char *sys_errlist[]; +#endif /* __SYS_ERRLIST */ +#endif /* __BSD_VISIBLE */ + +#ifndef errno +int *__errno(void); +#define errno (*__errno()) +#endif /* errno */ +__END_DECLS + +#endif /* _ERRNO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/execinfo.h b/lib/libc/include/generic-openbsd/execinfo.h new file mode 100644 index 0000000000..fd1bd83a11 --- /dev/null +++ b/lib/libc/include/generic-openbsd/execinfo.h @@ -0,0 +1,45 @@ +/* $OpenBSD: execinfo.h,v 1.1 2021/06/09 19:37:43 mortimer Exp $ */ + +/*- + * Copyright (c) 2012 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * 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 _EXECINFO_H_ +#define _EXECINFO_H_ + +#include +#include + +__BEGIN_DECLS +size_t backtrace(void **, size_t); +char **backtrace_symbols(void *const *, size_t); +int backtrace_symbols_fd(void *const *, size_t, int); +char **backtrace_symbols_fmt(void *const *, size_t, const char *); +int backtrace_symbols_fd_fmt(void *const *, size_t, int, const char *); +__END_DECLS + +#endif /* _EXECINFO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/fcntl.h b/lib/libc/include/generic-openbsd/fcntl.h new file mode 100644 index 0000000000..ddd098c940 --- /dev/null +++ b/lib/libc/include/generic-openbsd/fcntl.h @@ -0,0 +1,231 @@ +/* $OpenBSD: fcntl.h,v 1.23 2025/08/04 04:59:30 guenther Exp $ */ +/* $NetBSD: fcntl.h,v 1.8 1995/03/26 20:24:12 jtc Exp $ */ + +/*- + * Copyright (c) 1983, 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)fcntl.h 8.3 (Berkeley) 1/21/94 + */ + +#ifndef _SYS_FCNTL_H_ +#define _SYS_FCNTL_H_ + +/* + * This file includes the definitions for open and fcntl + * described by POSIX for ; it also includes + * related kernel definitions. + */ + +#include +#ifndef _KERNEL +#include +#endif + +/* + * File status flags: these are used by open(2), fcntl(2). + * They are also used (indirectly) in the kernel file structure f_flags, + * which is a superset of the open/fcntl flags. Open flags and f_flags + * are inter-convertible using OFLAGS(fflags) and FFLAGS(oflags). + * Open/fcntl flags begin with O_; kernel-internal flags begin with F. + */ +/* open-only flags */ +#define O_RDONLY 0x0000 /* open for reading only */ +#define O_WRONLY 0x0001 /* open for writing only */ +#define O_RDWR 0x0002 /* open for reading and writing */ +#define O_ACCMODE 0x0003 /* mask for above modes */ + +/* + * Kernel encoding of open mode; separate read and write bits that are + * independently testable: 1 greater than the above. + * + * XXX + * FREAD and FWRITE are excluded from the #ifdef _KERNEL so that TIOCFLUSH, + * which was documented to use FREAD/FWRITE, continues to work. + */ +#if __BSD_VISIBLE +#define FREAD 0x0001 +#define FWRITE 0x0002 +#endif +#define O_NONBLOCK 0x0004 /* no delay */ +#define O_APPEND 0x0008 /* set append mode */ +#if __BSD_VISIBLE +#define O_SHLOCK 0x0010 /* open with shared file lock */ +#define O_EXLOCK 0x0020 /* open with exclusive file lock */ +#define O_ASYNC 0x0040 /* signal pgrp when data ready */ +#define O_FSYNC 0x0080 /* backwards compatibility */ +#endif +#if __POSIX_VISIBLE >= 199309 || __XPG_VISIBLE >= 420 +#define O_SYNC 0x0080 /* synchronous writes */ +/* + * POSIX 1003.1 permits a higher granularity for synchronous operations + * than we support. Since synchronicity is all or nothing in OpenBSD + * we just define these to be the same as O_SYNC. + */ +#define O_DSYNC O_SYNC /* synchronous data writes */ +#define O_RSYNC O_SYNC /* synchronous reads */ +#endif + +/* defined by POSIX Issue 7 */ +#define O_NOFOLLOW 0x0100 /* if path is a symlink, don't follow */ + +#define O_CREAT 0x0200 /* create if nonexistent */ +#define O_TRUNC 0x0400 /* truncate to zero length */ +#define O_EXCL 0x0800 /* error if already exists */ + +/* defined by POSIX 1003.1; BSD default, this bit is not required */ +#define O_NOCTTY 0x8000 /* don't assign controlling terminal */ + +/* defined by POSIX Issue 7 */ +#define O_CLOEXEC 0x10000 /* atomically set FD_CLOEXEC */ +#define O_DIRECTORY 0x20000 /* fail if not a directory */ + +/* defined by POSIX Issue 8 */ +#define O_CLOFORK 0x40000 /* atomically set FD_CLOFORK */ + +#ifdef _KERNEL +/* + * convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE. + * For out-of-range values for the flags, be slightly careful (but lossy). + */ +#define FFLAGS(oflags) (((oflags) & ~O_ACCMODE) | (((oflags) + 1) & O_ACCMODE)) +#define OFLAGS(fflags) (((fflags) & ~O_ACCMODE) | (((fflags) - 1) & O_ACCMODE)) + +/* bits to save after open */ +#define FMASK (FREAD|FWRITE|FAPPEND|FASYNC|FFSYNC|FNONBLOCK) +/* bits settable by fcntl(F_SETFL, ...) */ +#define FCNTLFLAGS (FAPPEND|FASYNC|FFSYNC|FNONBLOCK) +#endif + +/* + * The O_* flags used to have only F* names, which were used in the kernel + * and by fcntl. We retain the F* names for the kernel f_flags field + * and for backward compatibility for fcntl. + */ +#if __BSD_VISIBLE +#define FAPPEND O_APPEND /* kernel/compat */ +#define FASYNC O_ASYNC /* kernel/compat */ +#define FFSYNC O_SYNC /* kernel */ +#define FNONBLOCK O_NONBLOCK /* kernel */ +#define FNDELAY O_NONBLOCK /* compat */ +#define O_NDELAY O_NONBLOCK /* compat */ +#endif + +/* + * Constants used for fcntl(2) + */ + +/* command values */ +#define F_DUPFD 0 /* duplicate file descriptor */ +#define F_GETFD 1 /* get file descriptor flags */ +#define F_SETFD 2 /* set file descriptor flags */ +#define F_GETFL 3 /* get file status flags */ +#define F_SETFL 4 /* set file status flags */ +#if __POSIX_VISIBLE >= 200112 || __XPG_VISIBLE >= 500 +#define F_GETOWN 5 /* get SIGIO/SIGURG proc/pgrp */ +#define F_SETOWN 6 /* set SIGIO/SIGURG proc/pgrp */ +#endif +#define F_GETLK 7 /* get record locking information */ +#define F_SETLK 8 /* set record locking information */ +#define F_SETLKW 9 /* F_SETLK; wait if blocked */ +#if __POSIX_VISIBLE >= 200809 +#define F_DUPFD_CLOEXEC 10 /* duplicate with FD_CLOEXEC set */ +#endif +#if __BSD_VISIBLE +#define F_ISATTY 11 /* used by isatty(3) */ +#endif +#if __POSIX_VISIBLE >= 202405 +#define F_DUPFD_CLOFORK 12 /* duplicate with FD_CLOFORK set */ +#endif + +/* file descriptor flags (F_GETFD, F_SETFD) */ +#define FD_CLOEXEC 1 /* close-on-exec flag */ +#if __POSIX_VISIBLE >= 202405 +#define FD_CLOFORK 4 /* close-on-fork flag */ +#endif + +/* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */ +#define F_RDLCK 1 /* shared or read lock */ +#define F_UNLCK 2 /* unlock */ +#define F_WRLCK 3 /* exclusive or write lock */ +#ifdef _KERNEL +#define F_WAIT 0x010 /* Wait until lock is granted */ +#define F_FLOCK 0x020 /* Use flock(2) semantics for lock */ +#define F_POSIX 0x040 /* Use POSIX semantics for lock */ +#define F_INTR 0x080 /* Lock operation interrupted */ +#endif + +/* + * Advisory file segment locking data type - + * information passed to system by user + */ +struct flock { + off_t l_start; /* starting offset */ + off_t l_len; /* len = 0 means until end of file */ + pid_t l_pid; /* lock owner */ + short l_type; /* lock type: read/write, etc. */ + short l_whence; /* type of l_start */ +}; + + +#if __BSD_VISIBLE +/* lock operations for flock(2) */ +#define LOCK_SH 0x01 /* shared file lock */ +#define LOCK_EX 0x02 /* exclusive file lock */ +#define LOCK_NB 0x04 /* don't block when locking */ +#define LOCK_UN 0x08 /* unlock file */ +#endif + +#if __POSIX_VISIBLE >= 200809 +#define AT_FDCWD -100 + +#define AT_EACCESS 0x01 +#define AT_SYMLINK_NOFOLLOW 0x02 +#define AT_SYMLINK_FOLLOW 0x04 +#define AT_REMOVEDIR 0x08 +#endif + +#ifndef _KERNEL +__BEGIN_DECLS +int open(const char *, int, ...); +int creat(const char *, mode_t); +int fcntl(int, int, ...); +#if __BSD_VISIBLE +int flock(int, int); +#endif +#if __POSIX_VISIBLE >= 200809 +int openat(int, const char *, int, ...); +#endif +__END_DECLS +#endif + +#endif /* !_SYS_FCNTL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/fenv.h b/lib/libc/include/generic-openbsd/fenv.h new file mode 100644 index 0000000000..3d6a2b35ad --- /dev/null +++ b/lib/libc/include/generic-openbsd/fenv.h @@ -0,0 +1,60 @@ +/* $OpenBSD: fenv.h,v 1.2 2011/05/25 21:46:49 martynas Exp $ */ +/* $NetBSD: fenv.h,v 1.2.4.1 2011/02/08 16:18:55 bouyer Exp $ */ + +/* + * Copyright (c) 2010 The NetBSD Foundation, Inc. + * 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 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 _FENV_H_ +#define _FENV_H_ + +#include +#include + +__BEGIN_DECLS + +int feclearexcept(int); +int fegetexceptflag(fexcept_t *, int); +int feraiseexcept(int); +int fesetexceptflag(const fexcept_t *, int); +int fetestexcept(int); + +int fegetround(void); +int fesetround(int); + +int fegetenv(fenv_t *); +int feholdexcept(fenv_t *); +int fesetenv(const fenv_t *); +int feupdateenv(const fenv_t *); + +#if __BSD_VISIBLE +int feenableexcept(int); +int fedisableexcept(int); +int fegetexcept(void); +#endif /* __BSD_VISIBLE */ + +__END_DECLS + +#endif /* ! _FENV_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/float.h b/lib/libc/include/generic-openbsd/float.h new file mode 100644 index 0000000000..e9fd9907c8 --- /dev/null +++ b/lib/libc/include/generic-openbsd/float.h @@ -0,0 +1,95 @@ +/* $OpenBSD: float.h,v 1.1 2012/06/26 16:16:16 deraadt Exp $ */ + +/* + * Copyright (c) 1989 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _FLOAT_H_ +#define _FLOAT_H_ + +#include +#include + +__BEGIN_DECLS +int __flt_rounds(void); +__END_DECLS + +#define FLT_RADIX __FLT_RADIX /* b */ +#define FLT_ROUNDS __FLT_ROUNDS + +#if __ISO_C_VISIBLE >= 1999 +#define FLT_EVAL_METHOD __FLT_EVAL_METHOD /* long double */ +#endif + +#define FLT_MANT_DIG __FLT_MANT_DIG /* p */ +#define FLT_EPSILON __FLT_EPSILON /* b**(1-p) */ +#ifndef FLT_DIG +#define FLT_DIG __FLT_DIG /* floor((p-1)*log10(b))+(b == 10) */ +#endif +#define FLT_MIN_EXP __FLT_MIN_EXP /* emin */ +#ifndef FLT_MIN +#define FLT_MIN __FLT_MIN /* b**(emin-1) */ +#endif +#define FLT_MIN_10_EXP __FLT_MIN_10_EXP /* ceil(log10(b**(emin-1))) */ +#define FLT_MAX_EXP __FLT_MAX_EXP /* emax */ +#ifndef FLT_MAX +#define FLT_MAX __FLT_MAX /* (1-b**(-p))*b**emax */ +#endif +#define FLT_MAX_10_EXP __FLT_MAX_10_EXP /* floor(log10((1-b**(-p))*b**emax)) */ + +#define DBL_MANT_DIG __DBL_MANT_DIG +#define DBL_EPSILON __DBL_EPSILON +#ifndef DBL_DIG +#define DBL_DIG __DBL_DIG +#endif +#define DBL_MIN_EXP __DBL_MIN_EXP +#ifndef DBL_MIN +#define DBL_MIN __DBL_MIN +#endif +#define DBL_MIN_10_EXP __DBL_MIN_10_EXP +#define DBL_MAX_EXP __DBL_MAX_EXP +#ifndef DBL_MAX +#define DBL_MAX __DBL_MAX +#endif +#define DBL_MAX_10_EXP __DBL_MAX_10_EXP + +#define LDBL_MANT_DIG __LDBL_MANT_DIG +#define LDBL_EPSILON __LDBL_EPSILON +#define LDBL_DIG __LDBL_DIG +#define LDBL_MIN_EXP __LDBL_MIN_EXP +#define LDBL_MIN __LDBL_MIN +#define LDBL_MIN_10_EXP __LDBL_MIN_10_EXP +#define LDBL_MAX_EXP __LDBL_MAX_EXP +#define LDBL_MAX __LDBL_MAX +#define LDBL_MAX_10_EXP __LDBL_MAX_10_EXP + +#if __ISO_C_VISIBLE >= 1999 +#define DECIMAL_DIG __DECIMAL_DIG +#endif + +#endif /* _FLOAT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/fnmatch.h b/lib/libc/include/generic-openbsd/fnmatch.h new file mode 100644 index 0000000000..bb0a769261 --- /dev/null +++ b/lib/libc/include/generic-openbsd/fnmatch.h @@ -0,0 +1,57 @@ +/* $OpenBSD: fnmatch.h,v 1.8 2005/12/13 00:35:22 millert Exp $ */ +/* $NetBSD: fnmatch.h,v 1.5 1994/10/26 00:55:53 cgd Exp $ */ + +/*- + * Copyright (c) 1992, 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. + * + * @(#)fnmatch.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _FNMATCH_H_ +#define _FNMATCH_H_ + +#include + +#define FNM_NOMATCH 1 /* Match failed. */ +#define FNM_NOSYS 2 /* Function not supported (unused). */ + +#define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */ +#define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */ +#define FNM_PERIOD 0x04 /* Period must be matched by period. */ +#if __BSD_VISIBLE +#define FNM_LEADING_DIR 0x08 /* Ignore / after Imatch. */ +#define FNM_CASEFOLD 0x10 /* Case insensitive search. */ +#define FNM_IGNORECASE FNM_CASEFOLD +#define FNM_FILE_NAME FNM_PATHNAME +#endif + +__BEGIN_DECLS +int fnmatch(const char *, const char *, int); +__END_DECLS + +#endif /* !_FNMATCH_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/fstab.h b/lib/libc/include/generic-openbsd/fstab.h new file mode 100644 index 0000000000..3e511cfcbe --- /dev/null +++ b/lib/libc/include/generic-openbsd/fstab.h @@ -0,0 +1,78 @@ +/* $OpenBSD: fstab.h,v 1.5 2003/06/02 19:34:12 millert Exp $ */ +/* $NetBSD: fstab.h,v 1.3 1994/10/26 00:55:53 cgd Exp $ */ + +/* + * Copyright (c) 1980 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. + * + * @(#)fstab.h 5.12 (Berkeley) 4/3/91 + */ + +#ifndef _FSTAB_H_ +#define _FSTAB_H_ + +/* + * File system table, see fstab(5). + * + * Used by dump, mount, umount, swapon, fsck, df, ... + * + * For ufs fs_spec field is the block special name. Programs that want to + * use the character special name must create that name by prepending a 'r' + * after the right most slash. Quota files are always named "quotas", so + * if type is "rq", then use concatenation of fs_file and "quotas" to locate + * quota file. + */ +#define _PATH_FSTAB "/etc/fstab" +#define FSTAB "/etc/fstab" /* deprecated */ + +#define FSTAB_RW "rw" /* read/write device */ +#define FSTAB_RQ "rq" /* read/write with quotas */ +#define FSTAB_RO "ro" /* read-only device */ +#define FSTAB_SW "sw" /* swap device */ +#define FSTAB_XX "xx" /* ignore totally */ + +struct fstab { + char *fs_spec; /* block special device name */ + char *fs_file; /* file system path prefix */ + char *fs_vfstype; /* File system type, ufs, nfs */ + char *fs_mntops; /* Mount options ala -o */ + char *fs_type; /* FSTAB_* from fs_mntops */ + int fs_freq; /* dump frequency, in days */ + int fs_passno; /* pass number on parallel fsck */ +}; + +#include + +__BEGIN_DECLS +struct fstab *getfsent(void); +struct fstab *getfsspec(const char *); +struct fstab *getfsfile(const char *); +int setfsent(void); +void endfsent(void); +__END_DECLS + +#endif /* !_FSTAB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/fts.h b/lib/libc/include/generic-openbsd/fts.h new file mode 100644 index 0000000000..b174dcda82 --- /dev/null +++ b/lib/libc/include/generic-openbsd/fts.h @@ -0,0 +1,125 @@ +/* $OpenBSD: fts.h,v 1.14 2012/12/05 23:19:57 deraadt Exp $ */ +/* $NetBSD: fts.h,v 1.5 1994/12/28 01:41:50 mycroft Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)fts.h 8.3 (Berkeley) 8/14/94 + */ + +#ifndef _FTS_H_ +#define _FTS_H_ + +typedef struct { + struct _ftsent *fts_cur; /* current node */ + struct _ftsent *fts_child; /* linked list of children */ + struct _ftsent **fts_array; /* sort array */ + dev_t fts_dev; /* starting device # */ + char *fts_path; /* path for this descent */ + int fts_rfd; /* fd for root */ + size_t fts_pathlen; /* sizeof(path) */ + int fts_nitems; /* elements in the sort array */ + int (*fts_compar)(); /* compare function */ + +#define FTS_COMFOLLOW 0x0001 /* follow command line symlinks */ +#define FTS_LOGICAL 0x0002 /* logical walk */ +#define FTS_NOCHDIR 0x0004 /* don't change directories */ +#define FTS_NOSTAT 0x0008 /* don't get stat info */ +#define FTS_PHYSICAL 0x0010 /* physical walk */ +#define FTS_SEEDOT 0x0020 /* return dot and dot-dot */ +#define FTS_XDEV 0x0040 /* don't cross devices */ +#define FTS_OPTIONMASK 0x00ff /* valid user option mask */ + +#define FTS_NAMEONLY 0x1000 /* (private) child names only */ +#define FTS_STOP 0x2000 /* (private) unrecoverable error */ + int fts_options; /* fts_open options, global flags */ +} FTS; + +typedef struct _ftsent { + struct _ftsent *fts_cycle; /* cycle node */ + struct _ftsent *fts_parent; /* parent directory */ + struct _ftsent *fts_link; /* next file in directory */ + long fts_number; /* local numeric value */ + void *fts_pointer; /* local address value */ + char *fts_accpath; /* access path */ + char *fts_path; /* root path */ + int fts_errno; /* errno for this node */ + int fts_symfd; /* fd for symlink */ + size_t fts_pathlen; /* strlen(fts_path) */ + size_t fts_namelen; /* strlen(fts_name) */ + + ino_t fts_ino; /* inode */ + dev_t fts_dev; /* device */ + nlink_t fts_nlink; /* link count */ + +#define FTS_ROOTPARENTLEVEL -1 +#define FTS_ROOTLEVEL 0 +#define FTS_MAXLEVEL 0x7fffffff + int fts_level; /* depth (-1 to N) */ + +#define FTS_D 1 /* preorder directory */ +#define FTS_DC 2 /* directory that causes cycles */ +#define FTS_DEFAULT 3 /* none of the above */ +#define FTS_DNR 4 /* unreadable directory */ +#define FTS_DOT 5 /* dot or dot-dot */ +#define FTS_DP 6 /* postorder directory */ +#define FTS_ERR 7 /* error; errno is set */ +#define FTS_F 8 /* regular file */ +#define FTS_INIT 9 /* initialized only */ +#define FTS_NS 10 /* stat(2) failed */ +#define FTS_NSOK 11 /* no stat(2) requested */ +#define FTS_SL 12 /* symbolic link */ +#define FTS_SLNONE 13 /* symbolic link without target */ + unsigned short fts_info; /* user flags for FTSENT structure */ + +#define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */ +#define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */ + unsigned short fts_flags; /* private flags for FTSENT structure */ + +#define FTS_AGAIN 1 /* read node again */ +#define FTS_FOLLOW 2 /* follow symbolic link */ +#define FTS_NOINSTR 3 /* no instructions */ +#define FTS_SKIP 4 /* discard node */ + unsigned short fts_instr; /* fts_set() instructions */ + + unsigned short fts_spare; /* unused */ + + struct stat *fts_statp; /* stat(2) information */ + char fts_name[1]; /* file name */ +} FTSENT; + +__BEGIN_DECLS +FTSENT *fts_children(FTS *, int); +int fts_close(FTS *); +FTS *fts_open(char * const *, int, + int (*)(const FTSENT **, const FTSENT **)); +FTSENT *fts_read(FTS *); +int fts_set(FTS *, FTSENT *, int); +__END_DECLS + +#endif /* !_FTS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ftw.h b/lib/libc/include/generic-openbsd/ftw.h new file mode 100644 index 0000000000..bed70565ab --- /dev/null +++ b/lib/libc/include/generic-openbsd/ftw.h @@ -0,0 +1,60 @@ +/* $OpenBSD: ftw.h,v 1.2 2019/01/25 00:19:25 millert Exp $ */ + +/* + * Copyright (c) 2003 Todd C. Miller + * + * 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. + * + * Sponsored in part by the Defense Advanced Research Projects + * Agency (DARPA) and Air Force Research Laboratory, Air Force + * Materiel Command, USAF, under agreement number F39502-99-1-0512. + */ + +#ifndef _FTW_H +#define _FTW_H + +#include +#include + +/* + * Valid flags for the 3rd argument to the function that is passed as the + * second argument to ftw(3) and nftw(3). Say it three times fast! + */ +#define FTW_F 0 /* File. */ +#define FTW_D 1 /* Directory. */ +#define FTW_DNR 2 /* Directory without read permission. */ +#define FTW_DP 3 /* Directory with subdirectories visited. */ +#define FTW_NS 4 /* Unknown type; stat() failed. */ +#define FTW_SL 5 /* Symbolic link. */ +#define FTW_SLN 6 /* Sym link that names a nonexistent file. */ + +/* + * Flags for use as the 4th argument to nftw(3). These may be ORed together. + */ +#define FTW_PHYS 0x01 /* Physical walk, don't follow sym links. */ +#define FTW_MOUNT 0x02 /* The walk does not cross a mount point. */ +#define FTW_DEPTH 0x04 /* Subdirs visited before the dir itself. */ +#define FTW_CHDIR 0x08 /* Change to a directory before reading it. */ + +struct FTW { + int base; + int level; +}; + +__BEGIN_DECLS +int ftw(const char *, int (*)(const char *, const struct stat *, int), int); +int nftw(const char *, int (*)(const char *, const struct stat *, int, + struct FTW *), int, int); +__END_DECLS + +#endif /* !_FTW_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/getopt.h b/lib/libc/include/generic-openbsd/getopt.h new file mode 100644 index 0000000000..d1c93e2d54 --- /dev/null +++ b/lib/libc/include/generic-openbsd/getopt.h @@ -0,0 +1,76 @@ +/* $OpenBSD: getopt.h,v 1.3 2013/11/22 21:32:49 millert Exp $ */ +/* $NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Dieter Baron and Thomas Klausner. + * + * 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 _GETOPT_H_ +#define _GETOPT_H_ + +#include + +/* + * GNU-like getopt_long() + */ +#define no_argument 0 +#define required_argument 1 +#define optional_argument 2 + +struct option { + /* name of long option */ + const char *name; + /* + * one of no_argument, required_argument, and optional_argument: + * whether option takes an argument + */ + int has_arg; + /* if not NULL, set *flag to val when option found */ + int *flag; + /* if flag not NULL, value to set *flag to; else return value */ + int val; +}; + +__BEGIN_DECLS +int getopt_long(int, char * const *, const char *, + const struct option *, int *); +int getopt_long_only(int, char * const *, const char *, + const struct option *, int *); +#ifndef _GETOPT_DEFINED_ +#define _GETOPT_DEFINED_ +int getopt(int, char * const *, const char *); + +extern char *optarg; /* getopt(3) external variables */ +extern int opterr; +extern int optind; +extern int optopt; +extern int optreset; +#endif +__END_DECLS + +#endif /* !_GETOPT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/glob.h b/lib/libc/include/generic-openbsd/glob.h new file mode 100644 index 0000000000..cfb2e3ee88 --- /dev/null +++ b/lib/libc/include/generic-openbsd/glob.h @@ -0,0 +1,103 @@ +/* $OpenBSD: glob.h,v 1.14 2019/02/04 16:45:40 millert Exp $ */ +/* $NetBSD: glob.h,v 1.5 1994/10/26 00:55:56 cgd Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Guido van Rossum. + * + * 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. + * + * @(#)glob.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _GLOB_H_ +#define _GLOB_H_ + +#include +#include + +#ifndef _SIZE_T_DEFINED_ +#define _SIZE_T_DEFINED_ +typedef __size_t size_t; +#endif + +struct stat; +typedef struct { + size_t gl_pathc; /* Count of total paths so far. */ + size_t gl_matchc; /* Count of paths matching pattern. */ + size_t gl_offs; /* Reserved at beginning of gl_pathv. */ + int gl_flags; /* Copy of flags parameter to glob. */ + char **gl_pathv; /* List of paths matching pattern. */ + struct stat **gl_statv; /* Stat entries corresponding to gl_pathv */ + /* Copy of errfunc parameter to glob. */ + int (*gl_errfunc)(const char *, int); + + /* + * Alternate filesystem access methods for glob; replacement + * versions of closedir(3), readdir(3), opendir(3), stat(2) + * and lstat(2). + */ + void (*gl_closedir)(void *); + struct dirent *(*gl_readdir)(void *); + void *(*gl_opendir)(const char *); + int (*gl_lstat)(const char *, struct stat *); + int (*gl_stat)(const char *, struct stat *); +} glob_t; + +#define GLOB_APPEND 0x0001 /* Append to output from previous call. */ +#define GLOB_DOOFFS 0x0002 /* Use gl_offs. */ +#define GLOB_ERR 0x0004 /* Return on error. */ +#define GLOB_MARK 0x0008 /* Append / to matching directories. */ +#define GLOB_NOCHECK 0x0010 /* Return pattern itself if nothing matches. */ +#define GLOB_NOSORT 0x0020 /* Don't sort. */ +#define GLOB_NOESCAPE 0x1000 /* Disable backslash escaping. */ + +#define GLOB_NOSPACE (-1) /* Malloc call failed. */ +#define GLOB_ABORTED (-2) /* Unignored error. */ +#define GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK not set. */ +#define GLOB_NOSYS (-4) /* Function not supported. */ + +#if __BSD_VISIBLE +#define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */ +#define GLOB_BRACE 0x0080 /* Expand braces ala csh. */ +#define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */ +#define GLOB_NOMAGIC 0x0200 /* GLOB_NOCHECK without magic chars (csh). */ +#define GLOB_QUOTE 0x0400 /* Quote special chars with \. */ +#define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */ +#define GLOB_LIMIT 0x2000 /* Limit pattern match output to ARG_MAX */ +#define GLOB_KEEPSTAT 0x4000 /* Retain stat data for paths in gl_statv. */ +#define GLOB_ABEND GLOB_ABORTED /* backward compatibility */ +#endif + +__BEGIN_DECLS +int glob(const char *__restrict, int, int (*)(const char *, int), + glob_t *__restrict); +void globfree(glob_t *); +__END_DECLS + +#endif /* !_GLOB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/grp.h b/lib/libc/include/generic-openbsd/grp.h new file mode 100644 index 0000000000..8fb76195d7 --- /dev/null +++ b/lib/libc/include/generic-openbsd/grp.h @@ -0,0 +1,78 @@ +/* $OpenBSD: grp.h,v 1.13 2018/09/13 12:31:15 millert Exp $ */ +/* $NetBSD: grp.h,v 1.7 1995/04/29 05:30:40 cgd Exp $ */ + +/*- + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)grp.h 8.2 (Berkeley) 1/21/94 + */ + +#ifndef _GRP_H_ +#define _GRP_H_ + +#include + +#if __BSD_VISIBLE +#define _PATH_GROUP "/etc/group" +#define _GR_BUF_LEN (1024+200*sizeof(char*)) +#endif + +struct group { + char *gr_name; /* group name */ + char *gr_passwd; /* group password */ + gid_t gr_gid; /* group id */ + char **gr_mem; /* group members */ +}; + +__BEGIN_DECLS +struct group *getgrgid(gid_t); +struct group *getgrnam(const char *); +#if __BSD_VISIBLE || __XPG_VISIBLE +struct group *getgrent(void); +void setgrent(void); +void endgrent(void); +#endif +#if __BSD_VISIBLE || __POSIX_VISIBLE >= 199506 || __XPG_VISIBLE +int getgrgid_r(gid_t, struct group *, char *, + size_t, struct group **); +int getgrnam_r(const char *, struct group *, char *, + size_t, struct group **); +#endif +#if __BSD_VISIBLE +int setgroupent(int); +int gid_from_group(const char *, gid_t *); +const char *group_from_gid(gid_t, int); +#endif +__END_DECLS + +#endif /* !_GRP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/icdb.h b/lib/libc/include/generic-openbsd/icdb.h new file mode 100644 index 0000000000..4136cd6e6d --- /dev/null +++ b/lib/libc/include/generic-openbsd/icdb.h @@ -0,0 +1,44 @@ +/* $OpenBSD: icdb.h,v 1.4 2016/09/04 14:51:39 nicm Exp $ */ +/* + * Copyright (c) 2015 Ted Unangst + * + * 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 _ICDB_H_ +#define _ICDB_H_ + +#include + +__BEGIN_DECLS + +struct icdb; + +struct icdb *icdb_new(uint32_t version, uint32_t nentries, uint32_t entrysize, + uint32_t nkeys, const uint32_t *keysizes, const uint32_t *keyoffsets); + +struct icdb *icdb_open(const char *name, int flags, uint32_t version); +int icdb_get(struct icdb *db, void *entry, uint32_t idx); +int icdb_lookup(struct icdb *db, int keynum, const void *key, void *entry, + uint32_t *idxp); +int icdb_nentries(struct icdb *db); +const void *icdb_entries(struct icdb *db); +int icdb_update(struct icdb *db, const void *entry, int offset); +int icdb_add(struct icdb *db, const void *entry); +int icdb_rehash(struct icdb *db); +int icdb_save(struct icdb *db, int fd); +int icdb_close(struct icdb *db); + +__END_DECLS + +#endif /* !_ICDB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ieeefp.h b/lib/libc/include/generic-openbsd/ieeefp.h new file mode 100644 index 0000000000..3f4c0019a6 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ieeefp.h @@ -0,0 +1,23 @@ +/* $OpenBSD: ieeefp.h,v 1.4 2009/09/27 21:23:55 martynas Exp $ */ + +/* + * Written by J.T. Conklin, Apr 6, 1995 + * Public domain. + */ + +#ifndef _IEEEFP_H_ +#define _IEEEFP_H_ + +#include +#include + +__BEGIN_DECLS +extern fp_rnd fpgetround(void); +extern fp_rnd fpsetround(fp_rnd); +extern fp_except fpgetmask(void); +extern fp_except fpsetmask(fp_except); +extern fp_except fpgetsticky(void); +extern fp_except fpsetsticky(fp_except); +__END_DECLS + +#endif /* _IEEEFP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ifaddrs.h b/lib/libc/include/generic-openbsd/ifaddrs.h new file mode 100644 index 0000000000..cffb0fe243 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ifaddrs.h @@ -0,0 +1,56 @@ +/* $OpenBSD: ifaddrs.h,v 1.4 2004/01/22 21:48:02 espie Exp $ */ + +/* + * Copyright (c) 1995, 1999 + * Berkeley Software Design, Inc. 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. + * + * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``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 Berkeley Software Design, Inc. 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. + * + * BSDI ifaddrs.h,v 2.5 2000/02/23 14:51:59 dab Exp + */ + +#ifndef _IFADDRS_H_ +#define _IFADDRS_H_ + +struct ifaddrs { + struct ifaddrs *ifa_next; + char *ifa_name; + unsigned int ifa_flags; + struct sockaddr *ifa_addr; + struct sockaddr *ifa_netmask; + struct sockaddr *ifa_dstaddr; + void *ifa_data; +}; + +/* + * This may have been defined in . Note that if is + * to be included it must be included before this header file. + */ +#ifndef ifa_broadaddr +#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ +#endif + +#include + +__BEGIN_DECLS +extern int getifaddrs(struct ifaddrs **); +extern void freeifaddrs(struct ifaddrs *); +__END_DECLS + +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/imsg.h b/lib/libc/include/generic-openbsd/imsg.h new file mode 100644 index 0000000000..bda67b7085 --- /dev/null +++ b/lib/libc/include/generic-openbsd/imsg.h @@ -0,0 +1,175 @@ +/* $OpenBSD: imsg.h,v 1.24 2025/06/05 08:55:07 tb Exp $ */ + +/* + * Copyright (c) 2023 Claudio Jeker + * Copyright (c) 2006, 2007 Pierre-Yves Ritschard + * Copyright (c) 2006, 2007, 2008 Reyk Floeter + * Copyright (c) 2003, 2004 Henning Brauer + * + * 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 _IMSG_H_ +#define _IMSG_H_ + +#include +#include +#include +#include + +#define IBUF_READ_SIZE 65535 +#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr) +#define MAX_IMSGSIZE 16384 + +struct ibuf { + TAILQ_ENTRY(ibuf) entry; + unsigned char *buf; + size_t size; + size_t max; + size_t wpos; + size_t rpos; + int fd; +}; + +struct ibufqueue; +struct msgbuf; + +struct imsgbuf { + struct msgbuf *w; + pid_t pid; + uint32_t maxsize; + int fd; + int flags; +}; + +struct imsg_hdr { + uint32_t type; + uint32_t len; + uint32_t peerid; + uint32_t pid; +}; + +struct imsg { + struct imsg_hdr hdr; + void *data; + struct ibuf *buf; +}; + +struct iovec; + +/* imsg-buffer.c */ +struct ibuf *ibuf_open(size_t); +struct ibuf *ibuf_dynamic(size_t, size_t); +int ibuf_add(struct ibuf *, const void *, size_t); +int ibuf_add_ibuf(struct ibuf *, const struct ibuf *); +int ibuf_add_zero(struct ibuf *, size_t); +int ibuf_add_n8(struct ibuf *, uint64_t); +int ibuf_add_n16(struct ibuf *, uint64_t); +int ibuf_add_n32(struct ibuf *, uint64_t); +int ibuf_add_n64(struct ibuf *, uint64_t); +int ibuf_add_h16(struct ibuf *, uint64_t); +int ibuf_add_h32(struct ibuf *, uint64_t); +int ibuf_add_h64(struct ibuf *, uint64_t); +int ibuf_add_strbuf(struct ibuf *, const char *, size_t); +void *ibuf_reserve(struct ibuf *, size_t); +void *ibuf_seek(struct ibuf *, size_t, size_t); +int ibuf_set(struct ibuf *, size_t, const void *, size_t); +int ibuf_set_n8(struct ibuf *, size_t, uint64_t); +int ibuf_set_n16(struct ibuf *, size_t, uint64_t); +int ibuf_set_n32(struct ibuf *, size_t, uint64_t); +int ibuf_set_n64(struct ibuf *, size_t, uint64_t); +int ibuf_set_h16(struct ibuf *, size_t, uint64_t); +int ibuf_set_h32(struct ibuf *, size_t, uint64_t); +int ibuf_set_h64(struct ibuf *, size_t, uint64_t); +int ibuf_set_maxsize(struct ibuf *, size_t); +void *ibuf_data(const struct ibuf *); +size_t ibuf_size(const struct ibuf *); +size_t ibuf_left(const struct ibuf *); +int ibuf_truncate(struct ibuf *, size_t); +void ibuf_rewind(struct ibuf *); +void ibuf_close(struct msgbuf *, struct ibuf *); +void ibuf_from_buffer(struct ibuf *, void *, size_t); +void ibuf_from_ibuf(struct ibuf *, const struct ibuf *); +int ibuf_get(struct ibuf *, void *, size_t); +int ibuf_get_ibuf(struct ibuf *, size_t, struct ibuf *); +int ibuf_get_n8(struct ibuf *, uint8_t *); +int ibuf_get_n16(struct ibuf *, uint16_t *); +int ibuf_get_n32(struct ibuf *, uint32_t *); +int ibuf_get_n64(struct ibuf *, uint64_t *); +int ibuf_get_h16(struct ibuf *, uint16_t *); +int ibuf_get_h32(struct ibuf *, uint32_t *); +int ibuf_get_h64(struct ibuf *, uint64_t *); +char *ibuf_get_string(struct ibuf *, size_t); +int ibuf_get_strbuf(struct ibuf *, char *, size_t); +int ibuf_skip(struct ibuf *, size_t); +void ibuf_free(struct ibuf *); +int ibuf_fd_avail(struct ibuf *); +int ibuf_fd_get(struct ibuf *); +void ibuf_fd_set(struct ibuf *, int); +struct msgbuf *msgbuf_new(void); +struct msgbuf *msgbuf_new_reader(size_t, + struct ibuf *(*)(struct ibuf *, void *, int *), void *); +void msgbuf_free(struct msgbuf *); +void msgbuf_clear(struct msgbuf *); +void msgbuf_concat(struct msgbuf *, struct ibufqueue *); +uint32_t msgbuf_queuelen(struct msgbuf *); +int ibuf_write(int, struct msgbuf *); +int msgbuf_write(int, struct msgbuf *); +int ibuf_read(int, struct msgbuf *); +int msgbuf_read(int, struct msgbuf *); +struct ibuf *msgbuf_get(struct msgbuf *); + +struct ibufqueue *ibufq_new(void); +void ibufq_free(struct ibufqueue *); +struct ibuf *ibufq_pop(struct ibufqueue *bufq); +void ibufq_push(struct ibufqueue *, struct ibuf *); +uint32_t ibufq_queuelen(struct ibufqueue *); +void ibufq_concat(struct ibufqueue *, struct ibufqueue *); +void ibufq_flush(struct ibufqueue *); + +/* imsg.c */ +int imsgbuf_init(struct imsgbuf *, int); +void imsgbuf_allow_fdpass(struct imsgbuf *imsgbuf); +int imsgbuf_set_maxsize(struct imsgbuf *, uint32_t); +int imsgbuf_read(struct imsgbuf *); +int imsgbuf_write(struct imsgbuf *); +int imsgbuf_flush(struct imsgbuf *); +void imsgbuf_clear(struct imsgbuf *); +uint32_t imsgbuf_queuelen(struct imsgbuf *); +int imsgbuf_get(struct imsgbuf *, struct imsg *); +ssize_t imsg_get(struct imsgbuf *, struct imsg *); +int imsg_ibufq_pop(struct ibufqueue *, struct imsg *); +void imsg_ibufq_push(struct ibufqueue *, struct imsg *); +int imsg_get_ibuf(struct imsg *, struct ibuf *); +int imsg_get_data(struct imsg *, void *, size_t); +int imsg_get_buf(struct imsg *, void *, size_t); +int imsg_get_strbuf(struct imsg *, char *, size_t); +int imsg_get_fd(struct imsg *); +uint32_t imsg_get_id(struct imsg *); +size_t imsg_get_len(struct imsg *); +pid_t imsg_get_pid(struct imsg *); +uint32_t imsg_get_type(struct imsg *); +int imsg_forward(struct imsgbuf *, struct imsg *); +int imsg_compose(struct imsgbuf *, uint32_t, uint32_t, pid_t, int, + const void *, size_t); +int imsg_composev(struct imsgbuf *, uint32_t, uint32_t, pid_t, int, + const struct iovec *, int); +int imsg_compose_ibuf(struct imsgbuf *, uint32_t, uint32_t, pid_t, + struct ibuf *); +struct ibuf *imsg_create(struct imsgbuf *, uint32_t, uint32_t, pid_t, size_t); +int imsg_add(struct ibuf *, const void *, size_t); +void imsg_close(struct imsgbuf *, struct ibuf *); +void imsg_free(struct imsg *); +int imsg_set_maxsize(struct ibuf *, size_t); + +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/inttypes.h b/lib/libc/include/generic-openbsd/inttypes.h new file mode 100644 index 0000000000..e1e5559473 --- /dev/null +++ b/lib/libc/include/generic-openbsd/inttypes.h @@ -0,0 +1,265 @@ +/* $OpenBSD: inttypes.h,v 1.14 2022/07/31 01:27:31 guenther Exp $ */ + +/* + * Copyright (c) 1997, 2005 Todd C. Miller + * + * 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 _INTTYPES_H_ +#define _INTTYPES_H_ + +#include + +#ifdef __cplusplus +#define __wchar_t wchar_t +#elif __POSIX_VISIBLE >= 200809 && !defined(_WCHAR_T_DEFINED_) +#define _WCHAR_T_DEFINED_ +typedef __wchar_t wchar_t; +#endif + +/* + * 7.8.1 Macros for format specifiers + * + * Each of the following object-like macros expands to a string + * literal containing a conversion specifier, possibly modified by + * a prefix such as hh, h, l, or ll, suitable for use within the + * format argument of a formatted input/output function when + * converting the corresponding integer type. These macro names + * have the general form of PRI (character string literals for the + * fprintf family) or SCN (character string literals for the fscanf + * family), followed by the conversion specifier, followed by a + * name corresponding to a similar typedef name. For example, + * PRIdFAST32 can be used in a format string to print the value of + * an integer of type int_fast32_t. + */ + +/* fprintf macros for signed integers */ +#define PRId8 "d" /* int8_t */ +#define PRId16 "d" /* int16_t */ +#define PRId32 "d" /* int32_t */ +#define PRId64 "lld" /* int64_t */ + +#define PRIdLEAST8 "d" /* int_least8_t */ +#define PRIdLEAST16 "d" /* int_least16_t */ +#define PRIdLEAST32 "d" /* int_least32_t */ +#define PRIdLEAST64 "lld" /* int_least64_t */ + +#define PRIdFAST8 "d" /* int_fast8_t */ +#define PRIdFAST16 "d" /* int_fast16_t */ +#define PRIdFAST32 "d" /* int_fast32_t */ +#define PRIdFAST64 "lld" /* int_fast64_t */ + +#define PRIdMAX "jd" /* intmax_t */ +#define PRIdPTR "ld" /* intptr_t */ + +#define PRIi8 "i" /* int8_t */ +#define PRIi16 "i" /* int16_t */ +#define PRIi32 "i" /* int32_t */ +#define PRIi64 "lli" /* int64_t */ + +#define PRIiLEAST8 "i" /* int_least8_t */ +#define PRIiLEAST16 "i" /* int_least16_t */ +#define PRIiLEAST32 "i" /* int_least32_t */ +#define PRIiLEAST64 "lli" /* int_least64_t */ + +#define PRIiFAST8 "i" /* int_fast8_t */ +#define PRIiFAST16 "i" /* int_fast16_t */ +#define PRIiFAST32 "i" /* int_fast32_t */ +#define PRIiFAST64 "lli" /* int_fast64_t */ + +#define PRIiMAX "ji" /* intmax_t */ +#define PRIiPTR "li" /* intptr_t */ + +/* fprintf macros for unsigned integers */ +#define PRIo8 "o" /* int8_t */ +#define PRIo16 "o" /* int16_t */ +#define PRIo32 "o" /* int32_t */ +#define PRIo64 "llo" /* int64_t */ + +#define PRIoLEAST8 "o" /* int_least8_t */ +#define PRIoLEAST16 "o" /* int_least16_t */ +#define PRIoLEAST32 "o" /* int_least32_t */ +#define PRIoLEAST64 "llo" /* int_least64_t */ + +#define PRIoFAST8 "o" /* int_fast8_t */ +#define PRIoFAST16 "o" /* int_fast16_t */ +#define PRIoFAST32 "o" /* int_fast32_t */ +#define PRIoFAST64 "llo" /* int_fast64_t */ + +#define PRIoMAX "jo" /* intmax_t */ +#define PRIoPTR "lo" /* intptr_t */ + +#define PRIu8 "u" /* uint8_t */ +#define PRIu16 "u" /* uint16_t */ +#define PRIu32 "u" /* uint32_t */ +#define PRIu64 "llu" /* uint64_t */ + +#define PRIuLEAST8 "u" /* uint_least8_t */ +#define PRIuLEAST16 "u" /* uint_least16_t */ +#define PRIuLEAST32 "u" /* uint_least32_t */ +#define PRIuLEAST64 "llu" /* uint_least64_t */ + +#define PRIuFAST8 "u" /* uint_fast8_t */ +#define PRIuFAST16 "u" /* uint_fast16_t */ +#define PRIuFAST32 "u" /* uint_fast32_t */ +#define PRIuFAST64 "llu" /* uint_fast64_t */ + +#define PRIuMAX "ju" /* uintmax_t */ +#define PRIuPTR "lu" /* uintptr_t */ + +#define PRIx8 "x" /* uint8_t */ +#define PRIx16 "x" /* uint16_t */ +#define PRIx32 "x" /* uint32_t */ +#define PRIx64 "llx" /* uint64_t */ + +#define PRIxLEAST8 "x" /* uint_least8_t */ +#define PRIxLEAST16 "x" /* uint_least16_t */ +#define PRIxLEAST32 "x" /* uint_least32_t */ +#define PRIxLEAST64 "llx" /* uint_least64_t */ + +#define PRIxFAST8 "x" /* uint_fast8_t */ +#define PRIxFAST16 "x" /* uint_fast16_t */ +#define PRIxFAST32 "x" /* uint_fast32_t */ +#define PRIxFAST64 "llx" /* uint_fast64_t */ + +#define PRIxMAX "jx" /* uintmax_t */ +#define PRIxPTR "lx" /* uintptr_t */ + +#define PRIX8 "X" /* uint8_t */ +#define PRIX16 "X" /* uint16_t */ +#define PRIX32 "X" /* uint32_t */ +#define PRIX64 "llX" /* uint64_t */ + +#define PRIXLEAST8 "X" /* uint_least8_t */ +#define PRIXLEAST16 "X" /* uint_least16_t */ +#define PRIXLEAST32 "X" /* uint_least32_t */ +#define PRIXLEAST64 "llX" /* uint_least64_t */ + +#define PRIXFAST8 "X" /* uint_fast8_t */ +#define PRIXFAST16 "X" /* uint_fast16_t */ +#define PRIXFAST32 "X" /* uint_fast32_t */ +#define PRIXFAST64 "llX" /* uint_fast64_t */ + +#define PRIXMAX "jX" /* uintmax_t */ +#define PRIXPTR "lX" /* uintptr_t */ + +/* fscanf macros for signed integers */ +#define SCNd8 "hhd" /* int8_t */ +#define SCNd16 "hd" /* int16_t */ +#define SCNd32 "d" /* int32_t */ +#define SCNd64 "lld" /* int64_t */ + +#define SCNdLEAST8 "hhd" /* int_least8_t */ +#define SCNdLEAST16 "hd" /* int_least16_t */ +#define SCNdLEAST32 "d" /* int_least32_t */ +#define SCNdLEAST64 "lld" /* int_least64_t */ + +#define SCNdFAST8 "d" /* int_fast8_t */ +#define SCNdFAST16 "d" /* int_fast16_t */ +#define SCNdFAST32 "d" /* int_fast32_t */ +#define SCNdFAST64 "lld" /* int_fast64_t */ + +#define SCNdMAX "jd" /* intmax_t */ +#define SCNdPTR "ld" /* intptr_t */ + +#define SCNi8 "hhi" /* int8_t */ +#define SCNi16 "hi" /* int16_t */ +#define SCNi32 "i" /* int32_t */ +#define SCNi64 "lli" /* int64_t */ + +#define SCNiLEAST8 "hhi" /* int_least8_t */ +#define SCNiLEAST16 "hi" /* int_least16_t */ +#define SCNiLEAST32 "i" /* int_least32_t */ +#define SCNiLEAST64 "lli" /* int_least64_t */ + +#define SCNiFAST8 "i" /* int_fast8_t */ +#define SCNiFAST16 "i" /* int_fast16_t */ +#define SCNiFAST32 "i" /* int_fast32_t */ +#define SCNiFAST64 "lli" /* int_fast64_t */ + +#define SCNiMAX "ji" /* intmax_t */ +#define SCNiPTR "li" /* intptr_t */ + +/* fscanf macros for unsigned integers */ +#define SCNo8 "hho" /* uint8_t */ +#define SCNo16 "ho" /* uint16_t */ +#define SCNo32 "o" /* uint32_t */ +#define SCNo64 "llo" /* uint64_t */ + +#define SCNoLEAST8 "hho" /* uint_least8_t */ +#define SCNoLEAST16 "ho" /* uint_least16_t */ +#define SCNoLEAST32 "o" /* uint_least32_t */ +#define SCNoLEAST64 "llo" /* uint_least64_t */ + +#define SCNoFAST8 "o" /* uint_fast8_t */ +#define SCNoFAST16 "o" /* uint_fast16_t */ +#define SCNoFAST32 "o" /* uint_fast32_t */ +#define SCNoFAST64 "llo" /* uint_fast64_t */ + +#define SCNoMAX "jo" /* uintmax_t */ +#define SCNoPTR "lo" /* uintptr_t */ + +#define SCNu8 "hhu" /* uint8_t */ +#define SCNu16 "hu" /* uint16_t */ +#define SCNu32 "u" /* uint32_t */ +#define SCNu64 "llu" /* uint64_t */ + +#define SCNuLEAST8 "hhu" /* uint_least8_t */ +#define SCNuLEAST16 "hu" /* uint_least16_t */ +#define SCNuLEAST32 "u" /* uint_least32_t */ +#define SCNuLEAST64 "llu" /* uint_least64_t */ + +#define SCNuFAST8 "u" /* uint_fast8_t */ +#define SCNuFAST16 "u" /* uint_fast16_t */ +#define SCNuFAST32 "u" /* uint_fast32_t */ +#define SCNuFAST64 "llu" /* uint_fast64_t */ + +#define SCNuMAX "ju" /* uintmax_t */ +#define SCNuPTR "lu" /* uintptr_t */ + +#define SCNx8 "hhx" /* uint8_t */ +#define SCNx16 "hx" /* uint16_t */ +#define SCNx32 "x" /* uint32_t */ +#define SCNx64 "llx" /* uint64_t */ + +#define SCNxLEAST8 "hhx" /* uint_least8_t */ +#define SCNxLEAST16 "hx" /* uint_least16_t */ +#define SCNxLEAST32 "x" /* uint_least32_t */ +#define SCNxLEAST64 "llx" /* uint_least64_t */ + +#define SCNxFAST8 "x" /* uint_fast8_t */ +#define SCNxFAST16 "x" /* uint_fast16_t */ +#define SCNxFAST32 "x" /* uint_fast32_t */ +#define SCNxFAST64 "llx" /* uint_fast64_t */ + +#define SCNxMAX "jx" /* uintmax_t */ +#define SCNxPTR "lx" /* uintptr_t */ + +typedef struct { + intmax_t quot; /* quotient */ + intmax_t rem; /* remainder */ +} imaxdiv_t; + +__BEGIN_DECLS +intmax_t imaxabs(intmax_t); +imaxdiv_t imaxdiv(intmax_t, intmax_t); +intmax_t strtoimax(const char *, char **, int); +uintmax_t strtoumax(const char *, char **, int); +intmax_t wcstoimax(const __wchar_t * __restrict, + __wchar_t ** __restrict, int); +uintmax_t wcstoumax(const __wchar_t * __restrict, + __wchar_t ** __restrict, int); +__END_DECLS + +#endif /* _INTTYPES_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/iso646.h b/lib/libc/include/generic-openbsd/iso646.h new file mode 100644 index 0000000000..6608a68a00 --- /dev/null +++ b/lib/libc/include/generic-openbsd/iso646.h @@ -0,0 +1,26 @@ +/* $OpenBSD: iso646.h,v 1.3 2001/10/11 00:05:21 espie Exp $ */ +/* $NetBSD: iso646.h,v 1.1 1995/02/17 09:08:10 jtc Exp $ */ + +/* + * Written by J.T. Conklin 02/16/95. + * Public domain. + */ + +#ifndef _ISO646_H_ +#define _ISO646_H_ + +#ifndef __cplusplus +#define and && +#define and_eq &= +#define bitand & +#define bitor | +#define compl ~ +#define not ! +#define not_eq != +#define or || +#define or_eq |= +#define xor ^ +#define xor_eq ^= +#endif + +#endif /* !_ISO646_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/isofs/cd9660/cd9660_extern.h b/lib/libc/include/generic-openbsd/isofs/cd9660/cd9660_extern.h new file mode 100644 index 0000000000..c8a8db6f8c --- /dev/null +++ b/lib/libc/include/generic-openbsd/isofs/cd9660/cd9660_extern.h @@ -0,0 +1,109 @@ +/* $OpenBSD: cd9660_extern.h,v 1.16 2023/07/17 09:41:20 semarie Exp $ */ +/* $NetBSD: cd9660_extern.h,v 1.1 1997/01/24 00:24:53 cgd Exp $ */ + +/*- + * Copyright (c) 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley + * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension + * Support code is derived from software contributed to Berkeley + * by Atsushi Murai (amurai@spec.co.jp). + * + * 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. + * + * @(#)iso.h 8.4 (Berkeley) 12/5/94 + */ + +/* + * Definitions used in the kernel for cd9660 file system support. + */ + +/* CD-ROM Format type */ +enum ISO_FTYPE { ISO_FTYPE_DEFAULT, ISO_FTYPE_9660, ISO_FTYPE_RRIP, ISO_FTYPE_ECMA }; + +#ifndef ISOFSMNT_ROOT +#define ISOFSMNT_ROOT 0 +#endif + +struct iso_mnt { + int im_flags; + + struct mount *im_mountp; + dev_t im_dev; + struct vnode *im_devvp; + + int logical_block_size; + int im_bshift; + int im_bmask; + + int volume_space_size; + struct netexport im_export; + + char root[ISODCL (157, 190)]; + int root_extent; + int root_size; + enum ISO_FTYPE iso_ftype; + + int rr_skip; + int rr_skip0; + + int joliet_level; +}; + +#define VFSTOISOFS(mp) ((struct iso_mnt *)((mp)->mnt_data)) + +#define blkoff(imp, loc) ((loc) & (imp)->im_bmask) +#define lblktosize(imp, blk) ((blk) << (imp)->im_bshift) +#define lblkno(imp, loc) ((loc) >> (imp)->im_bshift) +#define blksize(imp, ip, lbn) ((imp)->logical_block_size) + +int cd9660_mount(struct mount *, const char *, void *, + struct nameidata *, struct proc *); +int cd9660_start(struct mount *, int, struct proc *); +int cd9660_unmount(struct mount *, int, struct proc *); +int cd9660_root(struct mount *, struct vnode **); +int cd9660_quotactl(struct mount *, int, uid_t, caddr_t, struct proc *); +int cd9660_statfs(struct mount *, struct statfs *, struct proc *); +int cd9660_sync(struct mount *, int, int, struct ucred *, struct proc *); +int cd9660_vget(struct mount *, ino_t, struct vnode **); +int cd9660_fhtovp(struct mount *, struct fid *, struct vnode **); +int cd9660_vptofh(struct vnode *, struct fid *); +int cd9660_init(struct vfsconf *); +int cd9660_check_export(struct mount *, struct mbuf *, int *, + struct ucred **); + +int cd9660_mountroot(void); + +extern const struct vops cd9660_vops; +extern const struct vops cd9660_specvops; +#ifdef FIFO +extern const struct vops cd9660_fifovops; +#endif + +int isochar(const u_char *, const u_char *, int, u_char *); +int isofncmp(const u_char *, int, const u_char *, int, int); +void isofntrans(u_char *, int, u_char *, u_short *, int, int, int); +cdino_t isodirino(struct iso_directory_record *, struct iso_mnt *); \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/isofs/cd9660/cd9660_node.h b/lib/libc/include/generic-openbsd/isofs/cd9660/cd9660_node.h new file mode 100644 index 0000000000..186c61e239 --- /dev/null +++ b/lib/libc/include/generic-openbsd/isofs/cd9660/cd9660_node.h @@ -0,0 +1,130 @@ +/* $OpenBSD: cd9660_node.h,v 1.23 2024/05/13 01:15:53 jsg Exp $ */ +/* $NetBSD: cd9660_node.h,v 1.15 1997/04/11 21:52:01 kleink Exp $ */ + +/*- + * Copyright (c) 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley + * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension + * Support code is derived from software contributed to Berkeley + * by Atsushi Murai (amurai@spec.co.jp). + * + * 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. + * + * @(#)cd9660_node.h 8.4 (Berkeley) 12/5/94 + */ + +#include + +#define doff_t u_quad_t + +typedef struct { + struct timespec iso_atime; /* time of last access */ + struct timespec iso_mtime; /* time of last modification */ + struct timespec iso_ctime; /* time file changed */ + u_short iso_mode; /* files access mode and type */ + uid_t iso_uid; /* owner user id */ + gid_t iso_gid; /* owner group id */ + short iso_links; /* links of file */ + dev_t iso_rdev; /* Major/Minor number for special */ +} ISO_RRIP_INODE; + +struct iso_node { + struct iso_node *i_next, **i_prev; /* hash chain */ + struct vnode *i_vnode; /* vnode associated with this inode */ + struct vnode *i_devvp; /* vnode for block I/O */ + u_int i_flag; /* see below */ + dev_t i_dev; /* device where inode resides */ + cdino_t i_number; /* the identity of the inode */ + /* we use the actual starting block of the file */ + struct iso_mnt *i_mnt; /* filesystem associated with this inode */ + doff_t i_endoff; /* end of useful stuff in directory */ + doff_t i_diroff; /* offset in dir, where we found last entry */ + doff_t i_offset; /* offset of free space in directory */ + cdino_t i_ino; /* inode number of found directory */ + struct rrwlock i_lock; /* node lock */ + + doff_t iso_extent; /* extent of file */ + doff_t i_size; + /* + * Actual start of data file (may be different from iso_extent, if the + * file has extended attributes). + */ + doff_t iso_start; + + ISO_RRIP_INODE inode; + struct cluster_info i_ci; +}; + +#define i_forw i_chain[0] +#define i_back i_chain[1] + +/* flags */ +#define IN_ACCESS 0x0020 /* inode access time to be updated */ + +#define VTOI(vp) ((struct iso_node *)(vp)->v_data) +#define ITOV(ip) ((ip)->i_vnode) + +/* + * Prototypes for ISOFS vnode operations + */ +int cd9660_lookup(void *); +int cd9660_open(void *); +int cd9660_close(void *); +int cd9660_access(void *); +int cd9660_getattr(void *); +int cd9660_setattr(void *); +int cd9660_read(void *); +int cd9660_ioctl(void *); +int cd9660_mmap(void *); +int cd9660_seek(void *); +int cd9660_readdir(void *); +int cd9660_readlink(void *); +int cd9660_inactive(void *); +int cd9660_reclaim(void *); +int cd9660_link(void *); +int cd9660_symlink(void *); +int cd9660_bmap(void *); +int cd9660_lock(void *); +int cd9660_unlock(void *); +int cd9660_strategy(void *); +int cd9660_print(void *); +int cd9660_islocked(void *); +int cd9660_pathconf(void *); + +int cd9660_bufatoff(struct iso_node *, off_t, char **, struct buf **); + +void cd9660_defattr(struct iso_directory_record *, struct iso_node *, + struct buf *); +void cd9660_deftstamp(struct iso_directory_record *, struct iso_node *, + struct buf *); +struct vnode *cd9660_ihashget(dev_t, cdino_t); +int cd9660_ihashins(struct iso_node *); +void cd9660_ihashrem(struct iso_node *); +int cd9660_tstamp_conv7(u_char *, struct timespec *); +int cd9660_tstamp_conv17(u_char *, struct timespec *); +int cd9660_vget_internal(struct mount *, cdino_t, struct vnode **, int, + struct iso_directory_record *); \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/isofs/cd9660/cd9660_rrip.h b/lib/libc/include/generic-openbsd/isofs/cd9660/cd9660_rrip.h new file mode 100644 index 0000000000..9b3ecf9b94 --- /dev/null +++ b/lib/libc/include/generic-openbsd/isofs/cd9660/cd9660_rrip.h @@ -0,0 +1,139 @@ +/* $OpenBSD: cd9660_rrip.h,v 1.3 2003/06/02 23:28:05 millert Exp $ */ +/* $NetBSD: cd9660_rrip.h,v 1.6 1994/12/13 22:33:24 mycroft Exp $ */ + +/*- + * Copyright (c) 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley + * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension + * Support code is derived from software contributed to Berkeley + * by Atsushi Murai (amurai@spec.co.jp). + * + * 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. + * + * @(#)cd9660_rrip.h 8.2 (Berkeley) 12/5/94 + */ + +typedef struct { + char type [ISODCL ( 0, 1)]; + u_char length [ISODCL ( 2, 2)]; /* 711 */ + u_char version [ISODCL ( 3, 3)]; +} ISO_SUSP_HEADER; + +typedef struct { + ISO_SUSP_HEADER h; + char mode [ISODCL ( 4, 11)]; /* 733 */ + char links [ISODCL ( 12, 19)]; /* 733 */ + char uid [ISODCL ( 20, 27)]; /* 733 */ + char gid [ISODCL ( 28, 35)]; /* 733 */ +} ISO_RRIP_ATTR; + +typedef struct { + ISO_SUSP_HEADER h; + char dev_t_high [ISODCL ( 4, 11)]; /* 733 */ + char dev_t_low [ISODCL ( 12, 19)]; /* 733 */ +} ISO_RRIP_DEVICE; + +#define ISO_SUSP_CFLAG_CONTINUE 0x01 +#define ISO_SUSP_CFLAG_CURRENT 0x02 +#define ISO_SUSP_CFLAG_PARENT 0x04 +#define ISO_SUSP_CFLAG_ROOT 0x08 +#define ISO_SUSP_CFLAG_VOLROOT 0x10 +#define ISO_SUSP_CFLAG_HOST 0x20 + +typedef struct { + u_char cflag [ISODCL ( 1, 1)]; + u_char clen [ISODCL ( 2, 2)]; + u_char name [1]; /* XXX */ +} ISO_RRIP_SLINK_COMPONENT; +#define ISO_RRIP_SLSIZ 2 + +typedef struct { + ISO_SUSP_HEADER h; + u_char flags [ISODCL ( 4, 4)]; + u_char component [ISODCL ( 5, 5)]; +} ISO_RRIP_SLINK; + +typedef struct { + ISO_SUSP_HEADER h; + char flags [ISODCL ( 4, 4)]; +} ISO_RRIP_ALTNAME; + +typedef struct { + ISO_SUSP_HEADER h; + char dir_loc [ISODCL ( 4, 11)]; /* 733 */ +} ISO_RRIP_CLINK; + +typedef struct { + ISO_SUSP_HEADER h; + char dir_loc [ISODCL ( 4, 11)]; /* 733 */ +} ISO_RRIP_PLINK; + +typedef struct { + ISO_SUSP_HEADER h; +} ISO_RRIP_RELDIR; + +#define ISO_SUSP_TSTAMP_FORM17 0x80 +#define ISO_SUSP_TSTAMP_FORM7 0x00 +#define ISO_SUSP_TSTAMP_CREAT 0x01 +#define ISO_SUSP_TSTAMP_MODIFY 0x02 +#define ISO_SUSP_TSTAMP_ACCESS 0x04 +#define ISO_SUSP_TSTAMP_ATTR 0x08 +#define ISO_SUSP_TSTAMP_BACKUP 0x10 +#define ISO_SUSP_TSTAMP_EXPIRE 0x20 +#define ISO_SUSP_TSTAMP_EFFECT 0x40 + +typedef struct { + ISO_SUSP_HEADER h; + u_char flags [ISODCL ( 4, 4)]; + u_char time [ISODCL ( 5, 5)]; +} ISO_RRIP_TSTAMP; + +typedef struct { + ISO_SUSP_HEADER h; + u_char flags [ISODCL ( 4, 4)]; +} ISO_RRIP_IDFLAG; + +typedef struct { + ISO_SUSP_HEADER h; + char len_id [ISODCL ( 4, 4)]; + char len_des [ISODCL ( 5, 5)]; + char len_src [ISODCL ( 6, 6)]; + char version [ISODCL ( 7, 7)]; +} ISO_RRIP_EXTREF; + +typedef struct { + ISO_SUSP_HEADER h; + char check [ISODCL ( 4, 5)]; + char skip [ISODCL ( 6, 6)]; +} ISO_RRIP_OFFSET; + +typedef struct { + ISO_SUSP_HEADER h; + char location [ISODCL ( 4, 11)]; + char offset [ISODCL ( 12, 19)]; + char length [ISODCL ( 20, 27)]; +} ISO_RRIP_CONT; \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/isofs/cd9660/iso.h b/lib/libc/include/generic-openbsd/isofs/cd9660/iso.h new file mode 100644 index 0000000000..09b365117b --- /dev/null +++ b/lib/libc/include/generic-openbsd/isofs/cd9660/iso.h @@ -0,0 +1,282 @@ +/* $OpenBSD: iso.h,v 1.16 2021/03/05 07:01:36 jsg Exp $ */ +/* $NetBSD: iso.h,v 1.20 1997/07/07 22:45:34 cgd Exp $ */ + +/*- + * Copyright (c) 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley + * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension + * Support code is derived from software contributed to Berkeley + * by Atsushi Murai (amurai@spec.co.jp). + * + * 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. + * + * @(#)iso.h 8.4 (Berkeley) 12/5/94 + */ + +/* + * Definitions describing ISO9660 file system structure, as well as + * the functions necessary to access fields of ISO9660 file system + * structures. + */ + +typedef uint32_t cdino_t; + +#define ISODCL(from, to) (to - from + 1) + +struct iso_volume_descriptor { + char type[ISODCL(1,1)]; /* 711 */ + char id[ISODCL(2,6)]; + char version[ISODCL(7,7)]; + char data[ISODCL(8,2048)]; +}; + +/* volume descriptor types */ +#define ISO_VD_PRIMARY 1 +#define ISO_VD_SUPPLEMENTARY 2 +#define ISO_VD_END 255 + +#define ISO_STANDARD_ID "CD001" +#define ISO_ECMA_ID "CDW01" + +struct iso_primary_descriptor { + char type [ISODCL ( 1, 1)]; /* 711 */ + char id [ISODCL ( 2, 6)]; + char version [ISODCL ( 7, 7)]; /* 711 */ + char unused1 [ISODCL ( 8, 8)]; + char system_id [ISODCL ( 9, 40)]; /* achars */ + char volume_id [ISODCL ( 41, 72)]; /* dchars */ + char unused2 [ISODCL ( 73, 80)]; + char volume_space_size [ISODCL ( 81, 88)]; /* 733 */ + char unused3 [ISODCL ( 89, 120)]; + char volume_set_size [ISODCL (121, 124)]; /* 723 */ + char volume_sequence_number [ISODCL (125, 128)]; /* 723 */ + char logical_block_size [ISODCL (129, 132)]; /* 723 */ + char path_table_size [ISODCL (133, 140)]; /* 733 */ + char type_l_path_table [ISODCL (141, 144)]; /* 731 */ + char opt_type_l_path_table [ISODCL (145, 148)]; /* 731 */ + char type_m_path_table [ISODCL (149, 152)]; /* 732 */ + char opt_type_m_path_table [ISODCL (153, 156)]; /* 732 */ + char root_directory_record [ISODCL (157, 190)]; /* 9.1 */ + char volume_set_id [ISODCL (191, 318)]; /* dchars */ + char publisher_id [ISODCL (319, 446)]; /* achars */ + char preparer_id [ISODCL (447, 574)]; /* achars */ + char application_id [ISODCL (575, 702)]; /* achars */ + char copyright_file_id [ISODCL (703, 739)]; /* 7.5 dchars */ + char abstract_file_id [ISODCL (740, 776)]; /* 7.5 dchars */ + char bibliographic_file_id [ISODCL (777, 813)]; /* 7.5 dchars */ + char creation_date [ISODCL (814, 830)]; /* 8.4.26.1 */ + char modification_date [ISODCL (831, 847)]; /* 8.4.26.1 */ + char expiration_date [ISODCL (848, 864)]; /* 8.4.26.1 */ + char effective_date [ISODCL (865, 881)]; /* 8.4.26.1 */ + char file_structure_version [ISODCL (882, 882)]; /* 711 */ + char unused4 [ISODCL (883, 883)]; + char application_data [ISODCL (884, 1395)]; + char unused5 [ISODCL (1396, 2048)]; +}; +#define ISO_DEFAULT_BLOCK_SHIFT 11 +#define ISO_DEFAULT_BLOCK_SIZE (1< + * 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 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 AUTHOR 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. + * + * + * Extended and adapted for UDFv2.50+ bij Reinoud Zandijk based on the + * original by Scott Long. + * + * 20030508 Made some small typo and explanatory comments + * 20030510 Added UDF 2.01 structures + * 20030519 Added/correct comments on multi-partitioned logical volume space + * 20050616 Added pseudo overwrite + * 20050624 Added the missing extended attribute types and `magic values'. + * 20051106 Reworked some implementation use parts + * + */ + + +#ifndef _FS_UDF_ECMA167_UDF_H_ +#define _FS_UDF_ECMA167_UDF_H_ + + +/* ecma167-udf.h */ + +/* Volume recognition sequence ECMA 167 rev. 3 16.1 */ +struct vrs_desc { + uint8_t struct_type; + uint8_t identifier[5]; + uint8_t version; + uint8_t data[2041]; +} __packed; + + +#define VRS_NSR02 "NSR02" +#define VRS_NSR03 "NSR03" +#define VRS_BEA01 "BEA01" +#define VRS_TEA01 "TEA01" +#define VRS_CD001 "CD001" +#define VRS_CDW02 "CDW02" + + +/* Structure/definitions/constants a la ECMA 167 rev. 3 */ + + +#define MAX_TAGID_VOLUMES 9 +/* Tag identifiers */ +enum { + TAGID_SPARING_TABLE = 0, + TAGID_PRI_VOL = 1, + TAGID_ANCHOR = 2, + TAGID_VOL = 3, + TAGID_IMP_VOL = 4, + TAGID_PARTITION = 5, + TAGID_LOGVOL = 6, + TAGID_UNALLOC_SPACE = 7, + TAGID_TERM = 8, + TAGID_LOGVOL_INTEGRITY= 9, + TAGID_FSD = 256, + TAGID_FID = 257, + TAGID_ALLOCEXTENT = 258, + TAGID_INDIRECTENTRY = 259, + TAGID_ICB_TERM = 260, + TAGID_FENTRY = 261, + TAGID_EXTATTR_HDR = 262, + TAGID_UNALL_SP_ENTRY = 263, + TAGID_SPACE_BITMAP = 264, + TAGID_PART_INTEGRITY = 265, + TAGID_EXTFENTRY = 266, + TAGID_MAX = 266 +}; + + +enum { + UDF_DOMAIN_FLAG_HARD_WRITE_PROTECT = 1, + UDF_DOMAIN_FLAG_SOFT_WRITE_PROTECT = 2 +}; + + +enum { + UDF_ACCESSTYPE_NOT_SPECIFIED = 0, /* unknown */ + UDF_ACCESSTYPE_PSEUDO_OVERWITE = 0, /* pseudo overwritable, e.g. BD-R's LOW */ + UDF_ACCESSTYPE_READ_ONLY = 1, /* really only readable */ + UDF_ACCESSTYPE_WRITE_ONCE = 2, /* write once and you're done */ + UDF_ACCESSTYPE_REWRITABLE = 3, /* may need extra work to rewrite */ + UDF_ACCESSTYPE_OVERWRITABLE = 4 /* no limits on rewriting; e.g. harddisc*/ +}; + + +/* Descriptor tag [3/7.2] */ +struct desc_tag { + uint16_t id; + uint16_t descriptor_ver; + uint8_t cksum; + uint8_t reserved; + uint16_t serial_num; + uint16_t desc_crc; + uint16_t desc_crc_len; + uint32_t tag_loc; +} __packed; +#define UDF_DESC_TAG_LENGTH 16 + + +/* Recorded Address [4/7.1] */ +struct lb_addr { /* within partition space */ + uint32_t lb_num; + uint16_t part_num; +} __packed; + + +/* Extent Descriptor [3/7.1] */ +struct extent_ad { + uint32_t len; + uint32_t loc; +} __packed; + + +/* Short Allocation Descriptor [4/14.14.1] */ +struct short_ad { + uint32_t len; + uint32_t lb_num; +} __packed; + + +/* Long Allocation Descriptor [4/14.14.2] */ +struct UDF_ADImp_use { + uint16_t flags; + uint32_t unique_id; +} __packed; +#define UDF_ADIMP_FLAGS_EXTENT_ERASED 1 + + +struct long_ad { + uint32_t len; + struct lb_addr loc; /* within a logical volume mapped partition space !! */ + union { + uint8_t bytes[6]; + struct UDF_ADImp_use im_used; + } __packed impl; +} __packed; +#define longad_uniqueid impl.im_used.unique_id + + +/* Extended Allocation Descriptor [4/14.14.3] ; identifies an extent of allocation descriptors ; also in UDF ? */ +struct ext_ad { + uint32_t ex_len; + uint32_t rec_len; + uint32_t inf_len; + struct lb_addr ex_loc; + uint8_t reserved[2]; +} __packed; + + +/* ICB : Information Control Block; positioning */ +union icb { + struct short_ad s_ad; + struct long_ad l_ad; + struct ext_ad e_ad; +} __packed; + + +/* short/long/ext extent have flags encoded in length */ +#define UDF_EXT_ALLOCATED (0<<30) +#define UDF_EXT_FREED (1<<30) +#define UDF_EXT_ALLOCATED_BUT_NOT_USED (1<<30) +#define UDF_EXT_FREE (2<<30) +#define UDF_EXT_REDIRECT (3<<30) +#define UDF_EXT_FLAGS(len) ((len) & (3<<30)) +#define UDF_EXT_LEN(len) ((len) & ((1<<30)-1)) +#define UDF_EXT_MAXLEN ((1<<30)-1) + + +/* Character set spec [1/7.2.1] */ +struct charspec { + uint8_t type; + uint8_t inf[63]; +} __packed; + + +struct pathcomp { + uint8_t type; + uint8_t l_ci; + uint16_t comp_filever; + uint8_t ident[256]; +} __packed; +#define UDF_PATH_COMP_SIZE 4 +#define UDF_PATH_COMP_RESERVED 0 +#define UDF_PATH_COMP_ROOT 1 +#define UDF_PATH_COMP_MOUNTROOT 2 +#define UDF_PATH_COMP_PARENTDIR 3 +#define UDF_PATH_COMP_CURDIR 4 +#define UDF_PATH_COMP_NAME 5 + + +/* Timestamp [1/7.3] */ +struct timestamp { + uint16_t type_tz; + uint16_t year; + uint8_t month; + uint8_t day; + uint8_t hour; + uint8_t minute; + uint8_t second; + uint8_t centisec; + uint8_t hund_usec; + uint8_t usec; +} __packed; +#define UDF_TIMESTAMP_SIZE 12 + + +/* Entity Identifier [1/7.4] */ +#define UDF_REGID_ID_SIZE 23 +struct regid { + uint8_t flags; + uint8_t id[UDF_REGID_ID_SIZE]; + uint8_t id_suffix[8]; +} __packed; + + +/* ICB Tag [4/14.6] */ +struct icb_tag { + uint32_t prev_num_dirs; + uint16_t strat_type; + uint8_t strat_param[2]; + uint16_t max_num_entries; + uint8_t reserved; + uint8_t file_type; + struct lb_addr parent_icb; + uint16_t flags; +} __packed; +#define UDF_ICB_TAG_FLAGS_ALLOC_MASK 0x03 +#define UDF_ICB_SHORT_ALLOC 0x00 +#define UDF_ICB_LONG_ALLOC 0x01 +#define UDF_ICB_EXT_ALLOC 0x02 +#define UDF_ICB_INTERN_ALLOC 0x03 + +#define UDF_ICB_TAG_FLAGS_DIRORDERED (1<< 3) +#define UDF_ICB_TAG_FLAGS_NONRELOC (1<< 4) +#define UDF_ICB_TAG_FLAGS_CONTIGUOUS (1<< 9) +#define UDF_ICB_TAG_FLAGS_MULTIPLEVERS (1<<12) + +#define UDF_ICB_TAG_FLAGS_SETUID (1<< 6) +#define UDF_ICB_TAG_FLAGS_SETGID (1<< 7) +#define UDF_ICB_TAG_FLAGS_STICKY (1<< 8) + +#define UDF_ICB_FILETYPE_UNKNOWN 0 +#define UDF_ICB_FILETYPE_UNALLOCSPACE 1 +#define UDF_ICB_FILETYPE_PARTINTEGRITY 2 +#define UDF_ICB_FILETYPE_INDIRECTENTRY 3 +#define UDF_ICB_FILETYPE_DIRECTORY 4 +#define UDF_ICB_FILETYPE_RANDOMACCESS 5 +#define UDF_ICB_FILETYPE_BLOCKDEVICE 6 +#define UDF_ICB_FILETYPE_CHARDEVICE 7 +#define UDF_ICB_FILETYPE_EXTATTRREC 8 +#define UDF_ICB_FILETYPE_FIFO 9 +#define UDF_ICB_FILETYPE_SOCKET 10 +#define UDF_ICB_FILETYPE_TERM 11 +#define UDF_ICB_FILETYPE_SYMLINK 12 +#define UDF_ICB_FILETYPE_STREAMDIR 13 +#define UDF_ICB_FILETYPE_VAT 248 +#define UDF_ICB_FILETYPE_REALTIME 249 +#define UDF_ICB_FILETYPE_META_MAIN 250 +#define UDF_ICB_FILETYPE_META_MIRROR 251 + + +/* Anchor Volume Descriptor Pointer [3/10.2] */ +struct anchor_vdp { + struct desc_tag tag; + struct extent_ad main_vds_ex; /* to main volume descriptor set ; 16 sectors min */ + struct extent_ad reserve_vds_ex; /* copy of main volume descriptor set ; 16 sectors min */ +} __packed; + + +/* Volume Descriptor Pointer [3/10.3] */ +struct vol_desc_ptr { + struct desc_tag tag; /* use for extending the volume descriptor space */ + uint32_t vds_number; + struct extent_ad next_vds_ex; /* points to the next block for volume descriptor space */ +} __packed; + + +/* Primary Volume Descriptor [3/10.1] */ +struct pri_vol_desc { + struct desc_tag tag; + uint32_t seq_num; /* MAX prevail */ + uint32_t pvd_num; /* assigned by author; 0 is special as in it may only occur once */ + char vol_id[32]; /* KEY ; main identifier of this disc */ + uint16_t vds_num; /* volume descriptor number; i.e. what volume number is it */ + uint16_t max_vol_seq; /* maximum volume descriptor number known */ + uint16_t ichg_lvl; + uint16_t max_ichg_lvl; + uint32_t charset_list; + uint32_t max_charset_list; + char volset_id[128]; /* KEY ; if part of a multi-disc set or a band of volumes */ + struct charspec desc_charset; /* KEY according to ECMA 167 */ + struct charspec explanatory_charset; + struct extent_ad vol_abstract; + struct extent_ad vol_copyright; + struct regid app_id; + struct timestamp time; + struct regid imp_id; + uint8_t imp_use[64]; + uint32_t prev_vds_loc; /* location of predecessor _lov ? */ + uint16_t flags; /* bit 0 : if set indicates volume set name is meaningful */ + uint8_t reserved[22]; +} __packed; + + +/* UDF specific implementation use part of the implementation use volume descriptor */ +struct udf_lv_info { + struct charspec lvi_charset; + char logvol_id[128]; + + char lvinfo1[36]; + char lvinfo2[36]; + char lvinfo3[36]; + + struct regid impl_id; + uint8_t impl_use[128]; +} __packed; + + +/* Implementation use Volume Descriptor */ +struct impvol_desc { + struct desc_tag tag; + uint32_t seq_num; + struct regid impl_id; + union { + struct udf_lv_info lv_info; + char impl_use[460]; + } __packed _impl_use; +} __packed; + + +/* Logical Volume Descriptor [3/10.6] */ +struct logvol_desc { + struct desc_tag tag; + uint32_t seq_num; /* MAX prevail */ + struct charspec desc_charset; /* KEY */ + char logvol_id[128]; /* KEY */ + uint32_t lb_size; + struct regid domain_id; + union { + struct long_ad fsd_loc; /* to fileset descriptor SEQUENCE */ + uint8_t logvol_content_use[16]; + } __packed _lvd_use; + uint32_t mt_l; /* Partition map length */ + uint32_t n_pm; /* Number of partition maps */ + struct regid imp_id; + uint8_t imp_use[128]; + struct extent_ad integrity_seq_loc; + uint8_t maps[1]; +} __packed; +#define lv_fsd_loc _lvd_use.fsd_loc + +#define UDF_INTEGRITY_OPEN 0 +#define UDF_INTEGRITY_CLOSED 1 + + +#define UDF_PMAP_SIZE 64 + +/* Type 1 Partition Map [3/10.7.2] */ +struct part_map_1 { + uint8_t type; + uint8_t len; + uint16_t vol_seq_num; + uint16_t part_num; +} __packed; + + +/* Type 2 Partition Map [3/10.7.3] */ +struct part_map_2 { + uint8_t type; + uint8_t len; + uint8_t reserved[2]; + struct regid part_id; + uint16_t vol_seq_num; + uint16_t part_num; + uint8_t reserved2[24]; +} __packed; + + +/* Virtual Partition Map [UDF 2.01/2.2.8] */ +struct part_map_virt { + uint8_t type; + uint8_t len; + uint8_t reserved[2]; + struct regid id; + uint16_t vol_seq_num; + uint16_t part_num; + uint8_t reserved1[24]; +} __packed; + + +/* Sparable Partition Map [UDF 2.01/2.2.9] */ +struct part_map_spare { + uint8_t type; + uint8_t len; + uint8_t reserved[2]; + struct regid id; + uint16_t vol_seq_num; + uint16_t part_num; + uint16_t packet_len; + uint8_t n_st; /* Number of redundant sparing tables range 1-4 */ + uint8_t reserved1; + uint32_t st_size; /* size of EACH sparing table */ + uint32_t st_loc[1]; /* locations of sparing tables */ +} __packed; + + +/* Metadata Partition Map [UDF 2.50/2.2.10] */ +struct part_map_meta { + uint8_t type; + uint8_t len; + uint8_t reserved[2]; + struct regid id; + uint16_t vol_seq_num; + uint16_t part_num; + uint32_t meta_file_lbn; /* logical block number for file entry within part_num */ + uint32_t meta_mirror_file_lbn; + uint32_t meta_bitmap_file_lbn; + uint32_t alloc_unit_size; /* allocation unit size in blocks */ + uint16_t alignment_unit_size; /* alignment necessary in blocks */ + uint8_t flags; + uint8_t reserved1[5]; +} __packed; +#define METADATA_DUPLICATED 1 + + +union udf_pmap { + uint8_t data[UDF_PMAP_SIZE]; + struct part_map_1 pm1; + struct part_map_2 pm2; + struct part_map_virt pmv; + struct part_map_spare pms; + struct part_map_meta pmm; +} __packed; + + +/* Sparing Map Entry [UDF 2.01/2.2.11] */ +struct spare_map_entry { + uint32_t org; /* partition relative address */ + uint32_t map; /* absolute disc address (!) can be in partition, but doesn't have to be */ +} __packed; + + +/* Sparing Table [UDF 2.01/2.2.11] */ +struct udf_sparing_table { + struct desc_tag tag; + struct regid id; + uint16_t rt_l; /* Relocation Table len */ + uint8_t reserved[2]; + uint32_t seq_num; + struct spare_map_entry entries[1]; +} __packed; + + +#define UDF_NO_PREV_VAT 0xffffffff +/* UDF 1.50 VAT suffix [UDF 2.2.10 (UDF 1.50 spec)] */ +struct udf_oldvat_tail { + struct regid id; /* "*UDF Virtual Alloc Tbl" */ + uint32_t prev_vat; +} __packed; + + +/* VAT table [UDF 2.0.1/2.2.10] */ +struct udf_vat { + uint16_t header_len; + uint16_t impl_use_len; + char logvol_id[128]; /* newer version of the LVD one */ + uint32_t prev_vat; + uint32_t num_files; + uint32_t num_directories; + uint16_t min_udf_readver; + uint16_t min_udf_writever; + uint16_t max_udf_writever; + uint16_t reserved; + uint8_t data[1]; /* impl.use followed by VAT entries (uint32_t) */ +} __packed; + + +/* Space bitmap descriptor as found in the partition header descriptor */ +struct space_bitmap_desc { + struct desc_tag tag; /* TagId 264 */ + uint32_t num_bits; /* number of bits */ + uint32_t num_bytes; /* bytes that contain it */ + uint8_t data[1]; +} __packed; + + +/* Unalloc space entry as found in the partition header descriptor */ +struct space_entry_desc { + struct desc_tag tag; /* TagId 263 */ + struct icb_tag icbtag; /* type 1 */ + uint32_t l_ad; /* in bytes */ + uint8_t entry[1]; +} __packed; + + +/* Partition header descriptor; in the contents_use of part_desc */ +struct part_hdr_desc { + struct short_ad unalloc_space_table; + struct short_ad unalloc_space_bitmap; + struct short_ad part_integrity_table; /* has to be ZERO for UDF */ + struct short_ad freed_space_table; + struct short_ad freed_space_bitmap; + uint8_t reserved[88]; +} __packed; + + +/* Partition Descriptor [3/10.5] */ +struct part_desc { + struct desc_tag tag; + uint32_t seq_num; /* MAX prevailing */ + uint16_t flags; /* bit 0 : if set the space is allocated */ + uint16_t part_num; /* KEY */ + struct regid contents; + union { + struct part_hdr_desc part_hdr; + uint8_t contents_use[128]; + } _impl_use; + uint32_t access_type; /* R/W, WORM etc. */ + uint32_t start_loc; /* start of partition with given length */ + uint32_t part_len; + struct regid imp_id; + uint8_t imp_use[128]; + uint8_t reserved[156]; +} __packed; +#define pd_part_hdr _impl_use.part_hdr +#define UDF_PART_FLAG_ALLOCATED 1 + + +/* Unallocated Space Descriptor (UDF 2.01/2.2.5) */ +struct unalloc_sp_desc { + struct desc_tag tag; + uint32_t seq_num; /* MAX prevailing */ + uint32_t alloc_desc_num; + struct extent_ad alloc_desc[1]; +} __packed; + + +/* Logical Volume Integrity Descriptor [3/30.10] */ +struct logvolhdr { + uint64_t next_unique_id; + /* rest reserved */ +} __packed; + + +struct udf_logvol_info { + struct regid impl_id; + uint32_t num_files; + uint32_t num_directories; + uint16_t min_udf_readver; + uint16_t min_udf_writever; + uint16_t max_udf_writever; +} __packed; + + +struct logvol_int_desc { + struct desc_tag tag; + struct timestamp time; + uint32_t integrity_type; + struct extent_ad next_extent; + union { + struct logvolhdr logvolhdr; + int8_t reserved[32]; + } __packed _impl_use; + uint32_t num_part; + uint32_t l_iu; + uint32_t tables[1]; /* Freespace table, Sizetable, Implementation use */ +} __packed; +#define lvint_next_unique_id _impl_use.logvolhdr.next_unique_id + + +/* File Set Descriptor [4/14.1] */ +struct fileset_desc { + struct desc_tag tag; + struct timestamp time; + uint16_t ichg_lvl; + uint16_t max_ichg_lvl; + uint32_t charset_list; + uint32_t max_charset_list; + uint32_t fileset_num; /* key! */ + uint32_t fileset_desc_num; + struct charspec logvol_id_charset; + char logvol_id[128]; /* for recovery */ + struct charspec fileset_charset; + char fileset_id[32]; /* Mountpoint !! */ + char copyright_file_id[32]; + char abstract_file_id[32]; + struct long_ad rootdir_icb; /* to rootdir; icb->virtual ? */ + struct regid domain_id; + struct long_ad next_ex; /* to the next fileset_desc extent */ + struct long_ad streamdir_icb; /* streamdir; needed? */ + uint8_t reserved[32]; +} __packed; + + +/* File Identifier Descriptor [4/14.4] */ +struct fileid_desc { + struct desc_tag tag; + uint16_t file_version_num; + uint8_t file_char; + uint8_t l_fi; /* Length of file identifier area */ + struct long_ad icb; + uint16_t l_iu; /* Length of implementation use area */ + uint8_t data[0]; +} __packed; +#define UDF_FID_SIZE 38 +#define UDF_FILE_CHAR_VIS (1 << 0) /* Invisible */ +#define UDF_FILE_CHAR_DIR (1 << 1) /* Directory */ +#define UDF_FILE_CHAR_DEL (1 << 2) /* Deleted */ +#define UDF_FILE_CHAR_PAR (1 << 3) /* Parent Directory */ +#define UDF_FILE_CHAR_META (1 << 4) /* Stream metadata */ + + +/* Extended attributes [4/14.10.1] */ +struct extattrhdr_desc { + struct desc_tag tag; + uint32_t impl_attr_loc; /* offsets within this descriptor */ + uint32_t appl_attr_loc; /* ditto */ +} __packed; +#define UDF_IMPL_ATTR_LOC_NOT_PRESENT 0xffffffff +#define UDF_APPL_ATTR_LOC_NOT_PRESENT 0xffffffff + + +/* Extended attribute entry [4/48.10.2] */ +struct extattr_entry { + uint32_t type; + uint8_t subtype; + uint8_t reserved[3]; + uint32_t a_l; +} __packed; + + +/* Extended attribute entry; type 2048 [4/48.10.8] */ +struct impl_extattr_entry { + struct extattr_entry hdr; + uint32_t iu_l; + struct regid imp_id; + uint8_t data[1]; +} __packed; + + +/* Extended attribute entry; type 65 536 [4/48.10.9] */ +struct appl_extattr_entry { + struct extattr_entry hdr; + uint32_t au_l; + struct regid appl_id; + uint8_t data[1]; +} __packed; + + +/* File Times attribute entry; type 5 or type 6 [4/48.10.5], [4/48.10.6] */ +struct filetimes_extattr_entry { + struct extattr_entry hdr; + uint32_t d_l; /* length of times[] data following */ + uint32_t existence; /* bitmask */ + struct timestamp times[1]; /* in order of ascending bits */ +} __packed; +#define UDF_FILETIMES_ATTR_NO 5 +#define UDF_FILETIMES_FILE_CREATION 1 +#define UDF_FILETIMES_FILE_DELETION 4 +#define UDF_FILETIMES_FILE_EFFECTIVE 8 +#define UDF_FILETIMES_FILE_BACKUPED 16 +#define UDF_FILETIMES_ATTR_SIZE(no) (20 + (no)*sizeof(struct timestamp)) + + +/* Device Specification Extended Attribute [4/4.10.7] */ +struct device_extattr_entry { + struct extattr_entry hdr; + uint32_t iu_l; /* length of implementation use */ + uint32_t major; + uint32_t minor; + uint8_t data[1]; /* UDF: if nonzero length, contain developer ID regid */ +} __packed; +#define UDF_DEVICESPEC_ATTR_NO 12 + + +/* VAT LV extension Extended Attribute [UDF 3.3.4.5.1.3] 1.50 errata */ +struct vatlvext_extattr_entry { + uint64_t unique_id_chk; /* needs to be copy of ICB's */ + uint32_t num_files; + uint32_t num_directories; + char logvol_id[128]; /* replaces logvol name */ +} __packed; + + +/* File Entry [4/14.9] */ +struct file_entry { + struct desc_tag tag; + struct icb_tag icbtag; + uint32_t uid; + uint32_t gid; + uint32_t perm; + uint16_t link_cnt; + uint8_t rec_format; + uint8_t rec_disp_attr; + uint32_t rec_len; + uint64_t inf_len; + uint64_t logblks_rec; + struct timestamp atime; + struct timestamp mtime; + struct timestamp attrtime; + uint32_t ckpoint; + struct long_ad ex_attr_icb; + struct regid imp_id; + uint64_t unique_id; + uint32_t l_ea; /* Length of extended attribute area */ + uint32_t l_ad; /* Length of allocation descriptors */ + uint8_t data[1]; +} __packed; +#define UDF_FENTRY_SIZE 176 +#define UDF_FENTRY_PERM_USER_MASK 0x07 +#define UDF_FENTRY_PERM_GRP_MASK 0xE0 +#define UDF_FENTRY_PERM_OWNER_MASK 0x1C00 + + +/* Extended File Entry [4/48.17] */ +struct extfile_entry { + struct desc_tag tag; + struct icb_tag icbtag; + uint32_t uid; + uint32_t gid; + uint32_t perm; + uint16_t link_cnt; + uint8_t rec_format; + uint8_t rec_disp_attr; + uint32_t rec_len; + uint64_t inf_len; + uint64_t obj_size; + uint64_t logblks_rec; + struct timestamp atime; + struct timestamp mtime; + struct timestamp ctime; + struct timestamp attrtime; + uint32_t ckpoint; + uint32_t reserved1; + struct long_ad ex_attr_icb; + struct long_ad streamdir_icb; + struct regid imp_id; + uint64_t unique_id; + uint32_t l_ea; /* Length of extended attribute area */ + uint32_t l_ad; /* Length of allocation descriptors */ + uint8_t data[1]; +} __packed; +#define UDF_EXTFENTRY_SIZE 216 + + +/* Indirect entry [ecma 48.7] */ +struct indirect_entry { + struct desc_tag tag; + struct icb_tag icbtag; + struct long_ad indirect_icb; +} __packed; + + +/* Allocation extent descriptor [ecma 48.5] */ +struct alloc_ext_entry { + struct desc_tag tag; + uint32_t prev_entry; + uint32_t l_ad; + uint8_t data[1]; +} __packed; + + +union dscrptr { + struct desc_tag tag; + struct anchor_vdp avdp; + struct vol_desc_ptr vdp; + struct pri_vol_desc pvd; + struct logvol_desc lvd; + struct unalloc_sp_desc usd; + struct logvol_int_desc lvid; + struct impvol_desc ivd; + struct part_desc pd; + struct fileset_desc fsd; + struct fileid_desc fid; + struct file_entry fe; + struct extfile_entry efe; + struct extattrhdr_desc eahd; + struct indirect_entry inde; + struct alloc_ext_entry aee; + struct udf_sparing_table spt; + struct space_bitmap_desc sbd; + struct space_entry_desc sed; +} __packed; + +/* Useful defines */ + +#define GETICB(ad_type, fentry, offset) \ + (struct ad_type *)&fentry->data[offset] + +#define GETICBLEN(ad_type, icb) letoh32(((struct ad_type *)(icb))->len) + +#endif /* !_FS_UDF_ECMA167_UDF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/isofs/udf/udf.h b/lib/libc/include/generic-openbsd/isofs/udf/udf.h new file mode 100644 index 0000000000..41e0e5a82a --- /dev/null +++ b/lib/libc/include/generic-openbsd/isofs/udf/udf.h @@ -0,0 +1,145 @@ +/* $OpenBSD: udf.h,v 1.21 2016/06/19 11:54:33 natano Exp $ */ + +/* + * Copyright (c) 2001, 2002 Scott Long + * 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 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 AUTHOR 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. + * + * $FreeBSD: src/sys/fs/udf/udf.h,v 1.9 2004/10/29 10:40:58 phk Exp $ + */ + +/* + * Ported to OpenBSD by Pedro Martelletto in February 2005. + */ + +#define UDF_HASHTBLSIZE 100 + +typedef uint32_t udfino_t; + +struct unode { + LIST_ENTRY(unode) u_le; + struct vnode *u_vnode; + struct vnode *u_devvp; + struct umount *u_ump; + struct rrwlock u_lock; + dev_t u_dev; + udfino_t u_ino; + union { + long u_diroff; + long u_vatlen; + } un_u; + struct extfile_entry *u_fentry; +}; + +#define u_diroff un_u.u_diroff +#define u_vatlen un_u.u_vatlen + +struct umount { + int um_flags; + struct mount *um_mountp; + struct vnode *um_devvp; + dev_t um_dev; + int um_bsize; + int um_bshift; + int um_bmask; + uint32_t um_start; + uint32_t um_realstart; + uint32_t um_len; + uint32_t um_reallen; + uint32_t um_meta_start; + uint32_t um_meta_len; + struct unode *um_vat; + struct long_ad um_root_icb; + LIST_HEAD(udf_hash_lh, unode) *um_hashtbl; + SIPHASH_KEY um_hashkey; + u_long um_hashsz; + struct mutex um_hashmtx; + int um_psecs; + int um_stbl_len; + struct udf_sparing_table *um_stbl; +}; + +#define UDF_MNT_FIND_VAT 0x01 /* Indicates a VAT must be found */ +#define UDF_MNT_USES_VAT 0x02 /* Indicates a VAT must be used */ +#define UDF_MNT_USES_META 0x04 /* Indicates we are using a Metadata partition*/ + +#define VTOU(vp) ((struct unode *)((vp)->v_data)) + +#ifdef _KERNEL + +struct udf_dirstream { + struct unode *node; + struct umount *ump; + struct buf *bp; + uint8_t *data; + uint8_t *buf; + int fsize; + int off; + int this_off; + int offset; + int size; + int error; + int fid_fragment; +}; + +#define VFSTOUDFFS(mp) ((struct umount *)((mp)->mnt_data)) + +/* + * The block layer refers to things in terms of 512 byte blocks by default. + * btodb() is expensive, so speed things up. + * Can the block layer be forced to use a different block size? + */ +#define RDSECTOR(devvp, sector, size, bp) \ + bread(devvp, \ + ((daddr_t)(sector) << ump->um_bshift) / DEV_BSIZE, size, bp) + +static __inline int +udf_readlblks(struct umount *ump, int sector, int size, struct buf **bp) +{ + return (RDSECTOR(ump->um_devvp, sector, + (size + ump->um_bmask) & ~ump->um_bmask, bp)); +} + +/* + * Produce a suitable file number from an ICB. The passed in ICB is expected + * to be in little endian (meaning that it hasn't been swapped for big + * endian machines yet). + * If the fileno resolves to 0, we might be in big trouble. + * Assumes the ICB is a long_ad. This struct is compatible with short_ad, + * but not ext_ad. + */ +static __inline udfino_t +udf_getid(struct long_ad *icb) +{ + return (letoh32(icb->loc.lb_num)); +} + +int udf_allocv(struct mount *, struct vnode **, struct proc *); +int udf_hashlookup(struct umount *, udfino_t, int, struct vnode **); +int udf_hashins(struct unode *); +int udf_hashrem(struct unode *); +int udf_checktag(struct desc_tag *, uint16_t); + +typedef uint16_t unicode_t; + +#endif /* _KERNEL */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/isofs/udf/udf_extern.h b/lib/libc/include/generic-openbsd/isofs/udf/udf_extern.h new file mode 100644 index 0000000000..7af5a7a738 --- /dev/null +++ b/lib/libc/include/generic-openbsd/isofs/udf/udf_extern.h @@ -0,0 +1,69 @@ +/* $OpenBSD: udf_extern.h,v 1.16 2025/07/07 00:55:15 jsg Exp $ */ + +/* + * Written by Pedro Martelletto in February 2005. + * Public domain. + */ + +#ifdef _KERNEL + +/* + * udf_subr.c + */ +int udf_rawnametounicode(u_int len, char *, unicode_t *); +int udf_vat_get(struct umount *, uint32_t); +int udf_vat_map(struct umount *, uint32_t *); + +/* + * udf_vfsops.c + */ +int udf_init(struct vfsconf *); +int udf_mount(struct mount *, const char *, void *, struct nameidata *, + struct proc *); +int udf_unmount(struct mount *, int, struct proc *); +int udf_start(struct mount *, int, struct proc *); +int udf_root(struct mount *, struct vnode **); +int udf_quotactl(struct mount *, int, uid_t, caddr_t, struct proc *); +int udf_statfs(struct mount *, struct statfs *, struct proc *); +int udf_vget(struct mount *, ino_t, struct vnode **); +int udf_sync(struct mount *, int, int, struct ucred *, struct proc *); +int udf_checkexp(struct mount *, struct mbuf *, int *, struct ucred **); +int udf_fhtovp(struct mount *, struct fid *, struct vnode **); +int udf_vptofh(struct vnode *, struct fid *); + +/* + * udf_vnops.c + */ +int udf_access(void *v); +int udf_getattr(void *v); +int udf_open(void *v); +int udf_close(void *v); +int udf_ioctl(void *v); +int udf_read(void *v); +int udf_readdir(void *v); +int udf_readlink(void *v); +int udf_strategy(void *v); +int udf_bmap(void *v); +int udf_lookup(void *v); +int udf_inactive(void *v); +int udf_reclaim(void *v); +int udf_lock(void *v); +int udf_unlock(void *v); +int udf_pathconf(void *); +int udf_islocked(void *v); +int udf_print(void *v); +int udf_transname(char *, char *, int, struct umount *); +int udf_readatoffset(struct unode *, int *, off_t, struct buf **, + uint8_t **); + +/* + * Memory pools. + */ +extern struct pool udf_trans_pool; +extern struct pool unode_pool; +extern struct pool udf_ds_pool; + +/* Set of UDF vnode operations.*/ +extern const struct vops udf_vops; + +#endif /* _KERNEL */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/kvm.h b/lib/libc/include/generic-openbsd/kvm.h new file mode 100644 index 0000000000..8fd992cb1b --- /dev/null +++ b/lib/libc/include/generic-openbsd/kvm.h @@ -0,0 +1,79 @@ +/* $OpenBSD: kvm.h,v 1.18 2013/10/22 16:40:25 guenther Exp $ */ +/* $NetBSD: kvm.h,v 1.7 1996/04/19 12:02:50 leo Exp $ */ + +/*- + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)kvm.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _KVM_H_ +#define _KVM_H_ + +/* Default version symbol. */ +#define VRS_SYM "_version" +#define VRS_KEY "VERSION" + +/* + * Flag for kvm_open* that disables opening of any files. We're just + * interested in a handle to run sysctls. + */ +#define KVM_NO_FILES 0x80000000 + +#include +#include + +__BEGIN_DECLS + +typedef struct __kvm kvm_t; + +struct kinfo_proc; +int kvm_close(kvm_t *); +int kvm_dump_inval(kvm_t *); +int kvm_dump_mkheader(kvm_t *, off_t); +int kvm_dump_wrtheader(kvm_t *, FILE *, int); +char **kvm_getargv(kvm_t *, const struct kinfo_proc *, int); +char **kvm_getenvv(kvm_t *, const struct kinfo_proc *, int); +char *kvm_geterr(kvm_t *); +int kvm_getloadavg(kvm_t *, double [], int); +struct kinfo_file * + kvm_getfiles(kvm_t *, int, int, size_t, int *); +struct kinfo_proc * + kvm_getprocs(kvm_t *, int, int, size_t, int *); +int kvm_nlist(kvm_t *, struct nlist *); +kvm_t *kvm_open(const char *, const char *, const char *, int, const char *); +kvm_t *kvm_openfiles(const char *, const char *, const char *, + int, char *); +ssize_t kvm_read(kvm_t *, unsigned long, void *, size_t) + __attribute__((__bounded__(__buffer__,3,4))); +ssize_t kvm_write(kvm_t *, unsigned long, const void *, size_t) + __attribute__((__bounded__(__buffer__,3,4))); + +__END_DECLS + +#endif /* !_KVM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/langinfo.h b/lib/libc/include/generic-openbsd/langinfo.h new file mode 100644 index 0000000000..9009ee1d5b --- /dev/null +++ b/lib/libc/include/generic-openbsd/langinfo.h @@ -0,0 +1,88 @@ +/* $OpenBSD: langinfo.h,v 1.8 2017/09/05 03:16:13 schwarze Exp $ */ +/* $NetBSD: langinfo.h,v 1.3 1995/04/28 23:30:54 jtc Exp $ */ + +/* + * Written by J.T. Conklin + * Public domain. + */ + +#ifndef _LANGINFO_H_ +#define _LANGINFO_H_ + +#include + +#define D_T_FMT 0 /* String for formatting date and time */ +#define D_FMT 1 /* Date format string */ +#define T_FMT 2 /* Time format string */ +#define T_FMT_AMPM 3 /* Time format string with 12 hour clock */ +#define AM_STR 4 /* Ante Meridiem afix */ +#define PM_STR 5 /* Post Meridiem afix */ + +#define DAY_1 6 /* Name of the first day of the week */ +#define DAY_2 7 +#define DAY_3 8 +#define DAY_4 9 +#define DAY_5 10 +#define DAY_6 11 +#define DAY_7 12 + +#define ABDAY_1 13 /* Abbrev. name of the first day of the week */ +#define ABDAY_2 14 +#define ABDAY_3 15 +#define ABDAY_4 16 +#define ABDAY_5 17 +#define ABDAY_6 18 +#define ABDAY_7 19 + +#define MON_1 20 /* Name of the first month */ +#define MON_2 21 +#define MON_3 22 +#define MON_4 23 +#define MON_5 24 +#define MON_6 25 +#define MON_7 26 +#define MON_8 27 +#define MON_9 28 +#define MON_10 29 +#define MON_11 30 +#define MON_12 31 + +#define ABMON_1 32 /* Abbrev. name of the first month */ +#define ABMON_2 33 +#define ABMON_3 34 +#define ABMON_4 35 +#define ABMON_5 36 +#define ABMON_6 37 +#define ABMON_7 38 +#define ABMON_8 39 +#define ABMON_9 40 +#define ABMON_10 41 +#define ABMON_11 42 +#define ABMON_12 43 + +#define RADIXCHAR 44 /* Radix character */ +#define THOUSEP 45 /* Separator for thousands */ +#define YESSTR 46 /* Affirmative response for yes/no queries */ +#define YESEXPR 47 /* Affirmative response for yes/no queries */ +#define NOSTR 48 /* Negative response for yes/no queries */ +#define NOEXPR 49 /* Negative response for yes/no queries */ +#define CRNCYSTR 50 /* Currency symbol */ + +#define CODESET 51 /* Codeset name */ + +#if __POSIX_VISIBLE >= 200809 +#ifndef _LOCALE_T_DEFINED_ +#define _LOCALE_T_DEFINED_ +typedef void *locale_t; +#endif +#endif + +__BEGIN_DECLS +char *nl_langinfo(nl_item); + +#if __POSIX_VISIBLE >= 200809 +char *nl_langinfo_l(nl_item, locale_t); +#endif +__END_DECLS + +#endif /* _LANGINFO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/libgen.h b/lib/libc/include/generic-openbsd/libgen.h new file mode 100644 index 0000000000..c34a0f4088 --- /dev/null +++ b/lib/libc/include/generic-openbsd/libgen.h @@ -0,0 +1,29 @@ +/* $OpenBSD: libgen.h,v 1.10 2020/10/20 19:30:14 naddy Exp $ */ + +/* + * Copyright (c) 1997 Todd C. Miller + * + * 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 _LIBGEN_H_ +#define _LIBGEN_H_ + +#include + +__BEGIN_DECLS +char *basename(char *); +char *dirname(char *); +__END_DECLS + +#endif /* _LIBGEN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/limits.h b/lib/libc/include/generic-openbsd/limits.h new file mode 100644 index 0000000000..7b9702ce67 --- /dev/null +++ b/lib/libc/include/generic-openbsd/limits.h @@ -0,0 +1,117 @@ +/* $OpenBSD: limits.h,v 1.19 2015/01/20 22:09:50 tedu Exp $ */ +/* $NetBSD: limits.h,v 1.7 1994/10/26 00:56:00 cgd 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. + * + * @(#)limits.h 5.9 (Berkeley) 4/3/91 + */ + +#ifndef _LIMITS_H_ +#define _LIMITS_H_ + +#include + +#if __POSIX_VISIBLE +#define _POSIX_ARG_MAX 4096 +#define _POSIX_CHILD_MAX 25 +#define _POSIX_LINK_MAX 8 +#define _POSIX_MAX_CANON 255 +#define _POSIX_MAX_INPUT 255 +#define _POSIX_NAME_MAX 14 +#define _POSIX_PATH_MAX 256 +#define _POSIX_PIPE_BUF 512 +#define _POSIX_RE_DUP_MAX 255 +#define _POSIX_SEM_NSEMS_MAX 256 +#define _POSIX_SEM_VALUE_MAX 32767 +#define _POSIX_SSIZE_MAX 32767 +#define _POSIX_STREAM_MAX 8 +#define _POSIX_SYMLINK_MAX 255 +#define _POSIX_SYMLOOP_MAX 8 +#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 +#define _POSIX_THREAD_KEYS_MAX 128 +#define _POSIX_THREAD_THREADS_MAX 4 + +#if __POSIX_VISIBLE >= 200112 +#define _POSIX_CLOCKRES_MIN 20000000 +#define _POSIX_NGROUPS_MAX 8 +#define _POSIX_OPEN_MAX 20 +#define _POSIX_TZNAME_MAX 6 +#else +#define _POSIX_NGROUPS_MAX 0 +#define _POSIX_OPEN_MAX 16 +#define _POSIX_TZNAME_MAX 3 +#endif + +#define _POSIX2_BC_BASE_MAX 99 +#define _POSIX2_BC_DIM_MAX 2048 +#define _POSIX2_BC_SCALE_MAX 99 +#define _POSIX2_BC_STRING_MAX 1000 +#define _POSIX2_COLL_WEIGHTS_MAX 2 +#define _POSIX2_EXPR_NEST_MAX 32 +#define _POSIX2_LINE_MAX 2048 +#define _POSIX2_RE_DUP_MAX _POSIX_RE_DUP_MAX +#define _POSIX2_CHARCLASS_NAME_MAX 14 + +#if __POSIX_VISIBLE >= 200112 +#define _POSIX_HOST_NAME_MAX 255 +#define _POSIX_LOGIN_NAME_MAX 9 /* includes trailing NUL */ +#define _POSIX_TTY_NAME_MAX 9 /* includes trailing NUL */ +#endif /* __POSIX_VISIBLE >= 200112 */ +#endif /* __POSIX_VISIBLE */ + +#if __XPG_VISIBLE || __POSIX_VISIBLE >= 200809 +#define NL_ARGMAX 9 +#define NL_LANGMAX 14 +#define NL_MSGMAX 32767 +#define NL_SETMAX 255 +#define NL_TEXTMAX 255 +#endif + +#if __XPG_VISIBLE +# if __XPG_VISIBLE < 600 +# define PASS_MAX 128 /* _PASSWORD_LEN from */ +# define TMP_MAX 0x7fffffff /* more, but don't overflow int */ +# endif + +# if __XPG_VISIBLE < 700 +# define NL_NMAX 1 +# endif + +#define _XOPEN_IOV_MAX 16 +#define _XOPEN_NAME_MAX 255 +#define _XOPEN_PATH_MAX 1024 +#endif /* __XPG_VISIBLE */ + +#include + +#if __POSIX_VISIBLE +#include +#endif + +#endif /* !_LIMITS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/link.h b/lib/libc/include/generic-openbsd/link.h new file mode 100644 index 0000000000..bb80582810 --- /dev/null +++ b/lib/libc/include/generic-openbsd/link.h @@ -0,0 +1,148 @@ +/* $OpenBSD: link.h,v 1.15 2013/10/19 09:00:18 deraadt Exp $ */ +/* $NetBSD: link.h,v 1.10 1996/01/09 00:00:11 pk Exp $ */ + +/* + * Copyright (c) 1993 Paul Kranenburg + * 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 Paul Kranenburg. + * 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 _LINK_H_ +#define _LINK_H_ + +#ifdef __ELF__ +#include +#endif + +/* + * A `Shared Object Descriptor' describes a shared object that is needed + * to complete the link edit process of the object containing it. + * A list of such objects (chained through `sod_next') is pointed at + * by `sdt_sods' in the section_dispatch_table structure. + */ + +struct sod { /* Shared Object Descriptor */ + long sod_name; /* name (relative to load address) */ + unsigned int sod_library : 1,/* Searched for by library rules */ + sod_reserved : 31; + short sod_major; /* major version number */ + short sod_minor; /* minor version number */ + long sod_next; /* next sod */ +}; + +/* + * `Shared Object Map's are used by the run-time link editor (ld.so) to + * keep track of all shared objects loaded into a process' address space. + * These structures are only used at run-time and do not occur within + * the text or data segment of an executable or shared library. + */ +struct so_map { /* Shared Object Map */ + caddr_t som_addr; /* Address at which object mapped */ + char *som_path; /* Path to mmap'ed file */ + struct so_map *som_next; /* Next map in chain */ + struct sod *som_sod; /* Sod responsible for this map */ + caddr_t som_sodbase; /* Base address of this sod */ + unsigned int som_write : 1; /* Text is currently writable */ + struct _dynamic *som_dynamic; /* _dynamic structure */ + caddr_t som_spd; /* Private data */ +}; + + +/* + * Debug rendezvous struct. Pointer to this is set up in the + * target code pointed by the DT_DEBUG tag. If it is + * defined. + */ +struct r_debug { + int r_version; /* Protocol version. */ + struct link_map *r_map; /* Head of list of loaded objects. */ + + /* + * This is the address of a function internal to the run-time linker, + * that will always be called when the linker begins to map in a + * library or unmap it, and again when the mapping change is complete. + * The debugger can set a breakpoint at this address if it wants to + * notice shared object mapping changes. + */ + unsigned long r_brk; + enum { + /* + * This state value describes the mapping change taking place + * when the `r_brk' address is called. + */ + RT_CONSISTENT, /* Mapping change is complete. */ + RT_ADD, /* Adding a new object. */ + RT_DELETE /* Removing an object mapping. */ + } r_state; + + unsigned long r_ldbase; /* Base address the linker is loaded at. */ +}; + + + +/* + * Maximum number of recognized shared object version numbers. + */ +#define MAXDEWEY 8 + +/* + * Header of the hints file. + */ +struct hints_header { + long hh_magic; +#define HH_MAGIC 011421044151 + long hh_version; /* Interface version number */ +#define LD_HINTS_VERSION_1 1 +#define LD_HINTS_VERSION_2 2 + long hh_hashtab; /* Location of hash table */ + long hh_nbucket; /* Number of buckets in hashtab */ + long hh_strtab; /* Location of strings */ + long hh_strtab_sz; /* Size of strings */ + long hh_ehints; /* End of hints (max offset in file) */ + long hh_dirlist; /* Colon-separated list of srch dirs */ +}; + +#define HH_BADMAG(hdr) ((hdr).hh_magic != HH_MAGIC) + +/* + * Hash table element in hints file. + */ +struct hints_bucket { + /* namex and pathx are indices into the string table */ + int hi_namex; /* Library name */ + int hi_pathx; /* Full path */ + int hi_dewey[MAXDEWEY]; /* The versions */ + int hi_ndewey; /* Number of version numbers */ +#define hi_major hi_dewey[0] +#define hi_minor hi_dewey[1] + int hi_next; /* Next in this bucket */ +}; + +#define _PATH_LD_HINTS "/var/run/ld.so.hints" + +#endif /* _LINK_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/link_elf.h b/lib/libc/include/generic-openbsd/link_elf.h new file mode 100644 index 0000000000..c28b4243d1 --- /dev/null +++ b/lib/libc/include/generic-openbsd/link_elf.h @@ -0,0 +1,42 @@ +/* $OpenBSD: link_elf.h,v 1.8 2022/01/28 04:59:15 guenther Exp $ */ + +/* + * Public domain. + */ + +#ifndef _LINK_ELF_H +#define _LINK_ELF_H + +#include + +#ifndef DT_PROCNUM +#define DT_PROCNUM 0 +#endif + +/* + * struct link_map is a part of the protocol between the debugger and + * ld.so. ld.so may have additional fields in its version of this + * structure but those are ld.so private fields. + */ +struct link_map { + caddr_t l_addr; /* Base address of library */ + const char *l_name; /* Absolute path to library */ + void *l_ld; /* pointer to _DYNAMIC */ + struct link_map *l_next; + struct link_map *l_prev; +}; + +struct dl_phdr_info { + Elf_Addr dlpi_addr; + const char *dlpi_name; + const Elf_Phdr *dlpi_phdr; + Elf_Half dlpi_phnum; +}; + +__BEGIN_DECLS +int dl_iterate_phdr (int (*)(struct dl_phdr_info *, size_t, void *), + void *); +void *dl_unwind_find_exidx(const void *, int *); +__END_DECLS + +#endif /* !_LINK_ELF_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/locale.h b/lib/libc/include/generic-openbsd/locale.h new file mode 100644 index 0000000000..c66620acdd --- /dev/null +++ b/lib/libc/include/generic-openbsd/locale.h @@ -0,0 +1,112 @@ +/* $OpenBSD: locale.h,v 1.11 2017/09/05 03:16:13 schwarze Exp $ */ +/* $NetBSD: locale.h,v 1.6 1994/10/26 00:56:02 cgd Exp $ */ + +/* + * Copyright (c) 1991 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. + * + * @(#)locale.h 5.2 (Berkeley) 2/24/91 + */ + +#ifndef _LOCALE_H_ +#define _LOCALE_H_ + +#include + +struct lconv { + char *decimal_point; + char *thousands_sep; + char *grouping; + char *int_curr_symbol; + char *currency_symbol; + char *mon_decimal_point; + char *mon_thousands_sep; + char *mon_grouping; + char *positive_sign; + char *negative_sign; + char int_frac_digits; + char frac_digits; + char p_cs_precedes; + char p_sep_by_space; + char n_cs_precedes; + char n_sep_by_space; + char p_sign_posn; + char n_sign_posn; + char int_p_cs_precedes; + char int_p_sep_by_space; + char int_n_cs_precedes; + char int_n_sep_by_space; + char int_p_sign_posn; + char int_n_sign_posn; +}; + +#define LC_ALL 0 +#define LC_COLLATE 1 +#define LC_CTYPE 2 +#define LC_MONETARY 3 +#define LC_NUMERIC 4 +#define LC_TIME 5 +#define LC_MESSAGES 6 + +#define _LC_LAST 7 /* marks end */ + +#include + +#if __POSIX_VISIBLE >= 200809 + +#ifndef _LOCALE_T_DEFINED_ +#define _LOCALE_T_DEFINED_ +typedef void *locale_t; +#endif + +#define LC_COLLATE_MASK (1 << LC_COLLATE) +#define LC_CTYPE_MASK (1 << LC_CTYPE) +#define LC_MONETARY_MASK (1 << LC_MONETARY) +#define LC_NUMERIC_MASK (1 << LC_NUMERIC) +#define LC_TIME_MASK (1 << LC_TIME) +#define LC_MESSAGES_MASK (1 << LC_MESSAGES) + +#define LC_ALL_MASK ((1 << _LC_LAST) - 2) + +#define LC_GLOBAL_LOCALE ((locale_t)-1) + +#endif /* __POSIX_VISIBLE >= 200809 */ + + +__BEGIN_DECLS +struct lconv *localeconv(void); +char *setlocale(int, const char *); + +#if __POSIX_VISIBLE >= 200809 +locale_t duplocale(locale_t); +void freelocale(locale_t); +locale_t newlocale(int, const char *, locale_t); +locale_t uselocale(locale_t); +#endif +__END_DECLS + +#endif /* _LOCALE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/login_cap.h b/lib/libc/include/generic-openbsd/login_cap.h new file mode 100644 index 0000000000..d0c1169ee0 --- /dev/null +++ b/lib/libc/include/generic-openbsd/login_cap.h @@ -0,0 +1,111 @@ +/* $OpenBSD: login_cap.h,v 1.19 2022/03/01 01:22:11 tedu Exp $ */ + +/*- + * Copyright (c) 1995,1997 Berkeley Software Design, Inc. 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 Berkeley Software Design, + * Inc. + * 4. The name of Berkeley Software Design, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN, INC. ``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 BERKELEY SOFTWARE DESIGN, INC. 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. + * + * BSDI $From: login_cap.h,v 2.11 1999/09/08 18:11:57 prb Exp $ + */ + +#ifndef _LOGIN_CAP_H_ +#define _LOGIN_CAP_H_ + +#define LOGIN_DEFCLASS "default" +#define LOGIN_DEFSTYLE "passwd" +#define LOGIN_DEFSERVICE "login" +#define LOGIN_DEFUMASK 022 +#define _PATH_LOGIN_CONF "/etc/login.conf" +#define _PATH_LOGIN_CONF_D "/etc/login.conf.d" +#define _PATH_AUTHPROGDIR "/usr/libexec/auth" +#define _PATH_AUTHPROG "/usr/libexec/auth/login_" + +#define LOGIN_SETGROUP 0x0001 /* Set group */ +#define LOGIN_SETLOGIN 0x0002 /* Set login */ +#define LOGIN_SETPATH 0x0004 /* Set path */ +#define LOGIN_SETPRIORITY 0x0008 /* Set priority */ +#define LOGIN_SETRESOURCES 0x0010 /* Set resource limits */ +#define LOGIN_SETUMASK 0x0020 /* Set umask */ +#define LOGIN_SETUSER 0x0040 /* Set user */ +#define LOGIN_SETENV 0x0080 /* Set environment */ +#define LOGIN_SETRTABLE 0x0100 /* Set rtable */ +#define LOGIN_SETALL 0x01ff /* Set all. */ + +#define BI_AUTH "authorize" /* Accepted authentication */ +#define BI_REJECT "reject" /* Rejected authentication */ +#define BI_CHALLENGE "reject challenge" /* Reject with a challenge */ +#define BI_SILENT "reject silent" /* Reject silently */ +#define BI_REMOVE "remove" /* remove file on error */ +#define BI_ROOTOKAY "authorize root" /* root authenticated */ +#define BI_SECURE "authorize secure" /* okay on non-secure line */ +#define BI_SETENV "setenv" /* set environment variable */ +#define BI_UNSETENV "unsetenv" /* unset environment variable */ +#define BI_VALUE "value" /* set local variable */ +#define BI_EXPIRED "reject expired" /* account expired */ +#define BI_PWEXPIRED "reject pwexpired" /* password expired */ +#define BI_FDPASS "fd" /* child is passing an fd */ + +/* + * bits which can be returned by authenticate()/auth_scan() + */ +#define AUTH_OKAY 0x01 /* user authenticated */ +#define AUTH_ROOTOKAY 0x02 /* authenticated as root */ +#define AUTH_SECURE 0x04 /* secure login */ +#define AUTH_SILENT 0x08 /* silent rejection */ +#define AUTH_CHALLENGE 0x10 /* a challenge was given */ +#define AUTH_EXPIRED 0x20 /* account expired */ +#define AUTH_PWEXPIRED 0x40 /* password expired */ + +#define AUTH_ALLOW (AUTH_OKAY | AUTH_ROOTOKAY | AUTH_SECURE) + +typedef struct login_cap { + char *lc_class; + char *lc_cap; + char *lc_style; +} login_cap_t; + +#include +__BEGIN_DECLS +struct passwd; + +login_cap_t *login_getclass(char *); +void login_close(login_cap_t *); +int login_getcapbool(login_cap_t *, char *, unsigned int); +quad_t login_getcapnum(login_cap_t *, char *, quad_t, quad_t); +quad_t login_getcapsize(login_cap_t *, char *, quad_t, quad_t); +char *login_getcapstr(login_cap_t *, char *, char *, char *); +quad_t login_getcaptime(login_cap_t *, char *, quad_t, quad_t); +char *login_getstyle(login_cap_t *, char *, char *); + +int setclasscontext(char *, unsigned int); +int setusercontext(login_cap_t *, struct passwd *, uid_t, unsigned int); + +__END_DECLS + +#endif /* _LOGIN_CAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/machine/_float.h b/lib/libc/include/generic-openbsd/machine/_float.h new file mode 100644 index 0000000000..6c9717939f --- /dev/null +++ b/lib/libc/include/generic-openbsd/machine/_float.h @@ -0,0 +1,3 @@ +/* $OpenBSD: _float.h,v 1.1 2012/06/26 16:12:44 deraadt Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/machine/cdefs.h b/lib/libc/include/generic-openbsd/machine/cdefs.h new file mode 100644 index 0000000000..e44353fedf --- /dev/null +++ b/lib/libc/include/generic-openbsd/machine/cdefs.h @@ -0,0 +1,3 @@ +/* $OpenBSD: cdefs.h,v 1.2 2013/03/28 17:30:45 martynas Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/machine/disklabel.h b/lib/libc/include/generic-openbsd/machine/disklabel.h new file mode 100644 index 0000000000..e7758205f6 --- /dev/null +++ b/lib/libc/include/generic-openbsd/machine/disklabel.h @@ -0,0 +1,16 @@ +/* $OpenBSD: disklabel.h,v 1.3 2015/09/30 15:35:30 krw Exp $ */ +/* public domain */ + +/* + * Standard MBR partition scheme, with the label in the second sector + * of the OpenBSD partition. + */ + +#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_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/machine/elf.h b/lib/libc/include/generic-openbsd/machine/elf.h new file mode 100644 index 0000000000..1cd8fda26a --- /dev/null +++ b/lib/libc/include/generic-openbsd/machine/elf.h @@ -0,0 +1,7 @@ +/* $OpenBSD: elf.h,v 1.1 2024/07/14 09:48:48 jca Exp $ */ + +/* + * This file is in the public domain. + */ + +/* Nothing for now */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/machine/fenv.h b/lib/libc/include/generic-openbsd/machine/fenv.h new file mode 100644 index 0000000000..08e89fbf32 --- /dev/null +++ b/lib/libc/include/generic-openbsd/machine/fenv.h @@ -0,0 +1,3 @@ +/* $OpenBSD: fenv.h,v 1.2 2013/06/01 21:20:54 jasper Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/machine/loadfile_machdep.h b/lib/libc/include/generic-openbsd/machine/loadfile_machdep.h new file mode 100644 index 0000000000..1486f8ce5c --- /dev/null +++ b/lib/libc/include/generic-openbsd/machine/loadfile_machdep.h @@ -0,0 +1,49 @@ +/* $OpenBSD: loadfile_machdep.h,v 1.2 2015/07/17 20:44:39 miod Exp $ */ +/* $NetBSD: loadfile_machdep.h,v 1.2 2001/10/31 17:20:49 thorpej Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * 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. + */ + +#define BOOT_ELF +#define ELFSIZE 64 + +#define LOAD_KERNEL LOAD_ALL +#define COUNT_KERNEL COUNT_ALL + +#define LOADADDR(a) (((u_long)(a)) + offset) +#define ALIGNENTRY(a) ((u_long)(a)) +#define READ(f, b, c) read((f), (void *)LOADADDR(b), (c)) +#define BCOPY(s, d, c) memcpy((void *)LOADADDR(d), (void *)(s), (c)) +#define BZERO(d, c) memset((void *)LOADADDR(d), 0, (c)) +#define WARN(a) (void)(printf a, \ + printf((errno ? ": %s\n" : "\n"), \ + strerror(errno))) +#define PROGRESS(a) (void) printf a +#define ALLOC(a) alloc(a) +#define FREE(a, b) free(a, b) \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/machine/mplock.h b/lib/libc/include/generic-openbsd/machine/mplock.h new file mode 100644 index 0000000000..0630808c58 --- /dev/null +++ b/lib/libc/include/generic-openbsd/machine/mplock.h @@ -0,0 +1,10 @@ +/* $OpenBSD: mplock.h,v 1.4 2017/10/17 14:25:35 visa Exp $ */ + +/* public domain */ + +#ifndef _MACHINE_MPLOCK_H_ +#define _MACHINE_MPLOCK_H_ + +#define __USE_MI_MPLOCK + +#endif /* !_MACHINE_MPLOCK_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/machine/reloc.h b/lib/libc/include/generic-openbsd/machine/reloc.h new file mode 100644 index 0000000000..4eb8c01cf1 --- /dev/null +++ b/lib/libc/include/generic-openbsd/machine/reloc.h @@ -0,0 +1,5 @@ +/* $OpenBSD: reloc.h,v 1.1 2017/08/12 15:33:41 visa Exp $ */ + +/* public domain */ + +#include \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/machine/smbiosvar.h b/lib/libc/include/generic-openbsd/machine/smbiosvar.h new file mode 100644 index 0000000000..34349b6ec9 --- /dev/null +++ b/lib/libc/include/generic-openbsd/machine/smbiosvar.h @@ -0,0 +1,281 @@ +/* $OpenBSD: smbiosvar.h,v 1.14 2025/07/15 01:09:32 jsg Exp $ */ +/* + * Copyright (c) 2006 Gordon Willem Klok + * Copyright (c) 2005 Jordan Hargrave + * 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 AUTHORS 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 AUTHORS 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_SMBIOSVAR_ +#define _MACHINE_SMBIOSVAR_ + +#define SMBIOS_START 0xf0000 +#define SMBIOS_END 0xfffff + +#define SMBIOS_UUID_NPRESENT 0x1 +#define SMBIOS_UUID_NSET 0x2 + +/* + * Section 3.5 of "UUIDs and GUIDs" found at + * http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt + * specifies the string representation of a UUID. + */ +#define SMBIOS_UUID_REP "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" +#define SMBIOS_UUID_REPLEN 37 /* 16 zero padded values, 4 hyphens, 1 null */ + +struct smbios_entry { + uint8_t mjr; + uint8_t min; + uint8_t *addr; + uint16_t len; + uint16_t count; +}; + +struct smbhdr { + uint32_t sig; /* "_SM_" */ + uint8_t checksum; /* Entry point checksum */ + uint8_t len; /* Entry point structure length */ + uint8_t majrev; /* Specification major revision */ + uint8_t minrev; /* Specification minor revision */ + uint16_t mss; /* Maximum Structure Size */ + uint8_t epr; /* Entry Point Revision */ + uint8_t fa[5]; /* value determined by EPR */ + uint8_t sasig[5]; /* Secondary Anchor "_DMI_" */ + uint8_t sachecksum; /* Secondary Checksum */ + uint16_t size; /* Length of structure table in bytes */ + uint32_t addr; /* Structure table address */ + uint16_t count; /* Number of SMBIOS structures */ + uint8_t rev; /* BCD revision */ +} __packed; + +struct smb3hdr { + uint8_t sig[5]; /* "_SM3_" */ + uint8_t checksum; /* Entry point structure checksum */ + uint8_t len; /* Entry point length */ + uint8_t majrev; /* SMBIOS major version */ + uint8_t minrev; /* SMBIOS minor version */ + uint8_t docrev; /* SMBIOS docrev */ + uint8_t epr; /* Entry point revision */ + uint8_t reserved; /* Reserved */ + uint32_t size; /* Structure table maximum size */ + uint64_t addr; /* Structure table address */ +} __packed; + +struct smbtblhdr { + uint8_t type; + uint8_t size; + uint16_t handle; +} __packed; + +struct smbtable { + struct smbtblhdr *hdr; + void *tblhdr; + uint32_t cookie; +}; + +#define SMBIOS_TYPE_BIOS 0 +#define SMBIOS_TYPE_SYSTEM 1 +#define SMBIOS_TYPE_BASEBOARD 2 +#define SMBIOS_TYPE_ENCLOSURE 3 +#define SMBIOS_TYPE_PROCESSOR 4 +#define SMBIOS_TYPE_MEMCTRL 5 +#define SMBIOS_TYPE_MEMMOD 6 +#define SMBIOS_TYPE_CACHE 7 +#define SMBIOS_TYPE_PORT 8 +#define SMBIOS_TYPE_SLOTS 9 +#define SMBIOS_TYPE_OBD 10 +#define SMBIOS_TYPE_OEM 11 +#define SMBIOS_TYPE_SYSCONFOPT 12 +#define SMBIOS_TYPE_BIOSLANG 13 +#define SMBIOS_TYPE_GROUPASSOC 14 +#define SMBIOS_TYPE_SYSEVENTLOG 15 +#define SMBIOS_TYPE_PHYMEM 16 +#define SMBIOS_TYPE_MEMDEV 17 +#define SMBIOS_TYPE_ECCINFO32 18 +#define SMBIOS_TYPE_MEMMAPARRAYADDR 19 +#define SMBIOS_TYPE_MEMMAPDEVADDR 20 +#define SMBIOS_TYPE_INBUILTPOINT 21 +#define SMBIOS_TYPE_PORTBATT 22 +#define SMBIOS_TYPE_SYSRESET 23 +#define SMBIOS_TYPE_HWSECUIRTY 24 +#define SMBIOS_TYPE_PWRCTRL 25 +#define SMBIOS_TYPE_VOLTPROBE 26 +#define SMBIOS_TYPE_COOLING 27 +#define SMBIOS_TYPE_TEMPPROBE 28 +#define SMBIOS_TYPE_CURRENTPROBE 29 +#define SMBIOS_TYPE_OOB_REMOTEACCESS 30 +#define SMBIOS_TYPE_BIS 31 +#define SMBIOS_TYPE_SBI 32 +#define SMBIOS_TYPE_ECCINFO64 33 +#define SMBIOS_TYPE_MGMTDEV 34 +#define SMBIOS_TYPE_MGTDEVCOMP 35 +#define SMBIOS_TYPE_MGTDEVTHRESH 36 +#define SMBIOS_TYPE_MEMCHANNEL 37 +#define SMBIOS_TYPE_IPMIDEV 38 +#define SMBIOS_TYPE_SPS 39 +#define SMBIOS_TYPE_INACTIVE 126 +#define SMBIOS_TYPE_EOT 127 + +/* + * SMBIOS Structure Type 0 "BIOS Information" + * DMTF Specification DSP0134 Section: 3.3.1 p.g. 34 + */ +struct smbios_struct_bios { + uint8_t vendor; /* string */ + uint8_t version; /* string */ + uint16_t startaddr; + uint8_t release; /* string */ + uint8_t romsize; + uint64_t characteristics; + uint32_t charext; + uint8_t major_rel; + uint8_t minor_rel; + uint8_t ecf_mjr_rel; /* embedded controller firmware */ + uint8_t ecf_min_rel; /* embedded controller firmware */ +} __packed; + +/* + * SMBIOS Structure Type 1 "System Information" + * DMTF Specification DSP0134 Section 3.3.2 p.g. 35 + */ + +struct smbios_sys { +/* SMBIOS spec 2.0+ */ + uint8_t vendor; /* string */ + uint8_t product; /* string */ + uint8_t version; /* string */ + uint8_t serial; /* string */ +/* SMBIOS spec 2.1+ */ + uint8_t uuid[16]; + uint8_t wakeup; +/* SMBIOS spec 2.4+ */ + uint8_t sku; /* string */ + uint8_t family; /* string */ +} __packed; + +/* + * SMBIOS Structure Type 2 "Base Board (Module) Information" + * DMTF Specification DSP0134 Section 3.3.3 p.g. 37 + */ +struct smbios_board { + uint8_t vendor; /* string */ + uint8_t product; /* string */ + uint8_t version; /* string */ + uint8_t serial; /* string */ + uint8_t asset; /* string */ + uint8_t feature; /* feature flags */ + uint8_t location; /* location in chassis */ + uint16_t handle; /* chassis handle */ + uint8_t type; /* board type */ + uint8_t noc; /* number of contained objects */ +} __packed; + +/* + * SMBIOS Structure Type 3 "System Enclosure or Chassis" + * DMTF Specification DSP0134 + */ +struct smbios_enclosure { + /* SMBIOS spec 2.0+ */ + uint8_t vendor; /* string */ + uint8_t type; + uint8_t version; /* string */ + uint8_t serial; /* string */ + uint8_t asset_tag; /* string */ + /* SMBIOS spec 2.1+ */ + uint8_t boot_state; + uint8_t psu_state; + uint8_t thermal_state; + uint8_t security_status; + /* SMBIOS spec 2.3+ */ + uint16_t oem_defined; + uint8_t height; + uint8_t no_power_cords; + uint8_t no_contained_element; + uint8_t reclen_contained_element; + uint8_t contained_elements; + /* SMBIOS spec 2.7+ */ + uint8_t sku; /* string */ +} __packed; + +/* + * SMBIOS Structure Type 4 "processor Information" + * DMTF Specification DSP0134 v2.5 Section 3.3.5 p.g. 24 + */ +struct smbios_cpu { + uint8_t cpu_socket_designation; /* string */ + uint8_t cpu_type; + uint8_t cpu_family; + uint8_t cpu_mfg; /* string */ + uint32_t cpu_id_eax; + uint32_t cpu_id_edx; + uint8_t cpu_version; /* string */ + uint8_t cpu_voltage; + uint16_t cpu_clock; + uint16_t cpu_max_speed; + uint16_t cpu_current_speed; + uint8_t cpu_status; +#define SMBIOS_CPUST_POPULATED (1<<6) +#define SMBIOS_CPUST_STATUSMASK (0x07) + uint8_t cpu_upgrade; + uint16_t cpu_l1_handle; + uint16_t cpu_l2_handle; + uint16_t cpu_l3_handle; + uint8_t cpu_serial; /* string */ + uint8_t cpu_asset_tag; /* string */ + uint8_t cpu_part_nr; /* string */ + /* following fields were added in smbios 2.5 */ + uint8_t cpu_core_count; + uint8_t cpu_core_enabled; + uint8_t cpu_thread_count; + uint16_t cpu_characteristics; +} __packed; + +/* + * SMBIOS Structure Type 38 "IPMI Information" + * DMTF Specification DSP0134 Section 3.3.39 p.g. 91 + */ +struct smbios_ipmi { + uint8_t smipmi_if_type; /* IPMI Interface Type */ + uint8_t smipmi_if_rev; /* BCD IPMI Revision */ + uint8_t smipmi_i2c_address; /* I2C address of BMC */ + uint8_t smipmi_nvram_address; /* I2C address of NVRAM + * storage */ + uint64_t smipmi_base_address; /* Base address of BMC (BAR + * format */ + uint8_t smipmi_base_flags; /* Flags field: + * bit 7:6 : register spacing + * 00 = byte + * 01 = dword + * 02 = word + * bit 4 : Lower bit BAR + * bit 3 : IRQ valid + * bit 2 : N/A + * bit 1 : Interrupt polarity + * bit 0 : Interrupt trigger */ + uint8_t smipmi_irq; /* IRQ if applicable */ +} __packed; + +int smbios_find_table(uint8_t, struct smbtable *); +char *smbios_get_string(struct smbtable *, uint8_t, char *, size_t); + +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/machine/spinlock.h b/lib/libc/include/generic-openbsd/machine/spinlock.h new file mode 100644 index 0000000000..f3fe78c834 --- /dev/null +++ b/lib/libc/include/generic-openbsd/machine/spinlock.h @@ -0,0 +1,10 @@ +/* $OpenBSD: spinlock.h,v 1.3 2017/09/05 02:40:54 guenther Exp $ */ + +#ifndef _MACHINE_SPINLOCK_H_ +#define _MACHINE_SPINLOCK_H_ + +#define _ATOMIC_LOCK_UNLOCKED (0) +#define _ATOMIC_LOCK_LOCKED (1) +typedef int _atomic_lock_t; + +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/machine/tcb.h b/lib/libc/include/generic-openbsd/machine/tcb.h new file mode 100644 index 0000000000..427e19101a --- /dev/null +++ b/lib/libc/include/generic-openbsd/machine/tcb.h @@ -0,0 +1,3 @@ +/* $OpenBSD: tcb.h,v 1.2 2013/06/01 21:20:54 jasper Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/machine/timetc.h b/lib/libc/include/generic-openbsd/machine/timetc.h new file mode 100644 index 0000000000..9af8a41ca2 --- /dev/null +++ b/lib/libc/include/generic-openbsd/machine/timetc.h @@ -0,0 +1,23 @@ +/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:07 pirofti Exp $ */ +/* + * Copyright (c) 2020 Paul Irofti + * + * 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_TIMETC_H_ +#define _MACHINE_TIMETC_H_ + +#define TC_LAST 0 + +#endif /* _MACHINE_TIMETC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/math.h b/lib/libc/include/generic-openbsd/math.h new file mode 100644 index 0000000000..9cad4b0f74 --- /dev/null +++ b/lib/libc/include/generic-openbsd/math.h @@ -0,0 +1,497 @@ +/* $OpenBSD: math.h,v 1.36 2018/03/10 20:52:58 kettenis Exp $ */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * from: @(#)fdlibm.h 5.1 93/09/24 + */ + +#ifndef _MATH_H_ +#define _MATH_H_ + +#include +#include + +__BEGIN_DECLS +/* + * ANSI/POSIX + */ +extern char __infinity[]; +#if __GNUC_PREREQ__(3, 3) +#define HUGE_VAL __builtin_huge_val() +#else /* __GNUC_PREREQ__(3, 3) */ +#define HUGE_VAL (*(double *)(void *)__infinity) +#endif /* __GNUC_PREREQ__(3, 3) */ + +/* + * C99 + */ +#if __ISO_C_VISIBLE >= 1999 +typedef __double_t double_t; +typedef __float_t float_t; + +#if __GNUC_PREREQ__(3, 3) +#define HUGE_VALF __builtin_huge_valf() +#define HUGE_VALL __builtin_huge_vall() +#define INFINITY __builtin_inff() +#define NAN __builtin_nanf("") +#else /* __GNUC_PREREQ__(3, 3) */ +#define HUGE_VALF ((float)HUGE_VAL) +#define HUGE_VALL ((long double)HUGE_VAL) +#define INFINITY HUGE_VALF +extern char __nan[]; +#define NAN (*(float *)(void *)__nan) +#endif /* __GNUC_PREREQ__(3, 3) */ + +#define FP_INFINITE 0x01 +#define FP_NAN 0x02 +#define FP_NORMAL 0x04 +#define FP_SUBNORMAL 0x08 +#define FP_ZERO 0x10 + +#define FP_ILOGB0 (-INT_MAX) +#define FP_ILOGBNAN INT_MAX + +#ifdef __FP_FAST_FMA +#define FP_FAST_FMA 1 +#endif /* __FP_FAST_FMA */ + +#ifdef __FP_FAST_FMAF +#define FP_FAST_FMAF 1 +#endif /* __FP_FAST_FMAF */ + +#ifdef __FP_FAST_FMAL +#define FP_FAST_FMAL 1 +#endif /* __FP_FAST_FMAL */ + +#define MATH_ERRNO 1 +#define MATH_ERREXCEPT 2 +#define math_errhandling MATH_ERREXCEPT + +#define fpclassify(x) \ + ((sizeof (x) == sizeof (float)) ? \ + __fpclassifyf(x) \ + : (sizeof (x) == sizeof (double)) ? \ + __fpclassify(x) \ + : __fpclassifyl(x)) +#define isfinite(x) \ + ((sizeof (x) == sizeof (float)) ? \ + __isfinitef(x) \ + : (sizeof (x) == sizeof (double)) ? \ + __isfinite(x) \ + : __isfinitel(x)) +#define isnormal(x) \ + ((sizeof (x) == sizeof (float)) ? \ + __isnormalf(x) \ + : (sizeof (x) == sizeof (double)) ? \ + __isnormal(x) \ + : __isnormall(x)) +#define signbit(x) \ + ((sizeof (x) == sizeof (float)) ? \ + __signbitf(x) \ + : (sizeof (x) == sizeof (double)) ? \ + __signbit(x) \ + : __signbitl(x)) + +#define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y)) +#define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y)) +#define isless(x, y) (!isunordered((x), (y)) && (x) < (y)) +#define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y)) +#define islessgreater(x, y) (!isunordered((x), (y)) && \ + ((x) > (y) || (y) > (x))) +#define isunordered(x, y) (isnan(x) || isnan(y)) +#endif /* __ISO_C_VISIBLE >= 1999 */ + +#define isinf(x) \ + ((sizeof (x) == sizeof (float)) ? \ + __isinff(x) \ + : (sizeof (x) == sizeof (double)) ? \ + __isinf(x) \ + : __isinfl(x)) +#define isnan(x) \ + ((sizeof (x) == sizeof (float)) ? \ + __isnanf(x) \ + : (sizeof (x) == sizeof (double)) ? \ + __isnan(x) \ + : __isnanl(x)) + +/* + * XOPEN/SVID + */ +#if __BSD_VISIBLE || __XPG_VISIBLE +#define M_E ((double)2.7182818284590452354) /* e */ +#define M_LOG2E ((double)1.4426950408889634074) /* log 2e */ +#define M_LOG10E ((double)0.43429448190325182765) /* log 10e */ +#define M_LN2 ((double)0.69314718055994530942) /* log e2 */ +#define M_LN10 ((double)2.30258509299404568402) /* log e10 */ +#define M_PI ((double)3.14159265358979323846) /* pi */ +#define M_PI_2 ((double)1.57079632679489661923) /* pi/2 */ +#define M_PI_4 ((double)0.78539816339744830962) /* pi/4 */ +#define M_1_PI ((double)0.31830988618379067154) /* 1/pi */ +#define M_2_PI ((double)0.63661977236758134308) /* 2/pi */ +#define M_2_SQRTPI ((double)1.12837916709551257390) /* 2/sqrt(pi) */ +#define M_SQRT2 ((double)1.41421356237309504880) /* sqrt(2) */ +#define M_SQRT1_2 ((double)0.70710678118654752440) /* 1/sqrt(2) */ + +#define MAXFLOAT ((float)3.40282346638528860e+38) + +extern int signgam; +#endif /* __BSD_VISIBLE || __XPG_VISIBLE */ + +#if __POSIX_VISIBLE >= 201403 +#define M_El 2.718281828459045235360287471352662498L /* e */ +#define M_LOG2El 1.442695040888963407359924681001892137L /* log 2e */ +#define M_LOG10El 0.434294481903251827651128918916605082L /* log 10e */ +#define M_LN2l 0.693147180559945309417232121458176568L /* log e2 */ +#define M_LN10l 2.302585092994045684017991454684364208L /* log e10 */ +#define M_PIl 3.141592653589793238462643383279502884L /* pi */ +#define M_PI_2l 1.570796326794896619231321691639751442L /* pi/2 */ +#define M_PI_4l 0.785398163397448309615660845819875721L /* pi/4 */ +#define M_1_PIl 0.318309886183790671537767526745028724L /* 1/pi */ +#define M_2_PIl 0.636619772367581343075535053490057448L /* 2/pi */ +#define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(pi) */ +#define M_SQRT2l 1.414213562373095048801688724209698079L /* sqrt(2) */ +#define M_SQRT1_2l 0.707106781186547524400844362104849039L /* 1/sqrt(2) */ +#endif /* __POSIX_VISIBLE >= 201403 */ + +#if __BSD_VISIBLE +#define HUGE MAXFLOAT +#endif /* __BSD_VISIBLE */ + +/* + * ANSI/POSIX + */ +double acos(double); +double asin(double); +double atan(double); +double atan2(double, double); +double cos(double); +double sin(double); +double tan(double); + +double cosh(double); +double sinh(double); +double tanh(double); + +double exp(double); +double frexp(double, int *); +double ldexp(double, int); +double log(double); +double log10(double); +double modf(double, double *); + +double pow(double, double); +double sqrt(double); + +double ceil(double); +double fabs(double); +double floor(double); +double fmod(double, double); + +/* + * C99 + */ +#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XPG_VISIBLE +double acosh(double); +double asinh(double); +double atanh(double); + +double exp2(double); +double expm1(double); +int ilogb(double); +double log1p(double); +double log2(double); +double logb(double); +double scalbn(double, int); +double scalbln(double, long int); + +double cbrt(double); +double hypot(double, double); + +double erf(double); +double erfc(double); +double lgamma(double); +double tgamma(double); + +double nearbyint(double); +double rint(double); +long int lrint(double); +long long int llrint(double); +double round(double); +long int lround(double); +long long int llround(double); +double trunc(double); + +double remainder(double, double); +double remquo(double, double, int *); + +double copysign(double, double); +double nan(const char *); +double nextafter(double, double); +double nexttoward(double, long double); + +double fdim(double, double); +double fmax(double, double); +double fmin(double, double); + +double fma(double, double, double); +#endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XPG_VISIBLE */ + +#if __BSD_VISIBLE || __XPG_VISIBLE +double j0(double); +double j1(double); +double jn(int, double); +double scalb(double, double); +double y0(double); +double y1(double); +double yn(int, double); +#endif /* __BSD_VISIBLE || __XPG_VISIBLE */ + +#if __BSD_VISIBLE || __XPG_VISIBLE <= 500 +double gamma(double); +#endif /* __BSD_VISIBLE || __XPG_VISIBLE <= 500 */ + +/* + * BSD math library entry points + */ +#if __BSD_VISIBLE +double drem(double, double); +int finite(double); + +/* + * Reentrant version of gamma & lgamma; passes signgam back by reference + * as the second argument; user must allocate space for signgam. + */ +double gamma_r(double, int *); +double lgamma_r(double, int *); + +void sincos(double, double *, double *); + +/* + * IEEE Test Vector + */ +double significand(double); +#endif /* __BSD_VISIBLE */ + +/* + * Float versions of C99 functions + */ +#if __ISO_C_VISIBLE >= 1999 +float acosf(float); +float asinf(float); +float atanf(float); +float atan2f(float, float); +float cosf(float); +float sinf(float); +float tanf(float); + +float acoshf(float); +float asinhf(float); +float atanhf(float); +float coshf(float); +float sinhf(float); +float tanhf(float); + +float expf(float); +float exp2f(float); +float expm1f(float); +float frexpf(float, int *); +int ilogbf(float); +float ldexpf(float, int); +float logf(float); +float log10f(float); +float log1pf(float); +float log2f(float); +float logbf(float); +float modff(float, float *); +float scalbnf(float, int); +float scalblnf(float, long int); + +float cbrtf(float); +float fabsf(float); +float hypotf(float, float); +float powf(float, float); +float sqrtf(float); + +float erff(float); +float erfcf(float); +float lgammaf(float); +float tgammaf(float); + +float ceilf(float); +float floorf(float); +float nearbyintf(float); +float rintf(float); +long int lrintf(float); +long long int llrintf(float); +float roundf(float); +long int lroundf(float); +long long int llroundf(float); +float truncf(float); + +float fmodf(float, float); +float remainderf(float, float); +float remquof(float, float, int *); + +float copysignf(float, float); +float nanf(const char *); +float nextafterf(float, float); +float nexttowardf(float, long double); + +float fdimf(float, float); +float fmaxf(float, float); +float fminf(float, float); + +float fmaf(float, float, float); +#endif /* __ISO_C_VISIBLE >= 1999 */ + +#if __BSD_VISIBLE || __XPG_VISIBLE +float j0f(float); +float j1f(float); +float jnf(int, float); +float scalbf(float, float); +float y0f(float); +float y1f(float); +float ynf(int, float); +#endif /* __BSD_VISIBLE || __XPG_VISIBLE */ + +#if __BSD_VISIBLE || __XPG_VISIBLE <= 500 +float gammaf(float); +#endif /* __BSD_VISIBLE || __XPG_VISIBLE <= 500 */ + +/* + * Float versions of BSD math library entry points + */ +#if __BSD_VISIBLE +float dremf(float, float); +int finitef(float); +int isinff(float); +int isnanf(float); + +/* + * Float versions of reentrant version of gamma & lgamma; passes + * signgam back by reference as the second argument; user must + * allocate space for signgam. + */ +float gammaf_r(float, int *); +float lgammaf_r(float, int *); + +void sincosf(float, float *, float *); + +/* + * Float version of IEEE Test Vector + */ +float significandf(float); +#endif /* __BSD_VISIBLE */ + +/* + * Long double versions of C99 functions + */ +#if __ISO_C_VISIBLE >= 1999 +long double acosl(long double); +long double asinl(long double); +long double atanl(long double); +long double atan2l(long double, long double); +long double cosl(long double); +long double sinl(long double); +long double tanl(long double); + +long double acoshl(long double); +long double asinhl(long double); +long double atanhl(long double); +long double coshl(long double); +long double sinhl(long double); +long double tanhl(long double); + +long double expl(long double); +long double exp2l(long double); +long double expm1l(long double); +long double frexpl(long double, int *); +int ilogbl(long double); +long double ldexpl(long double, int); +long double logl(long double); +long double log10l(long double); +long double log1pl(long double); +long double log2l(long double); +long double logbl(long double); +long double modfl(long double, long double *); +long double scalbnl(long double, int); +long double scalblnl(long double, long int); + +long double cbrtl(long double); +long double fabsl(long double); +long double hypotl(long double, long double); +long double powl(long double, long double); +long double sqrtl(long double); + +long double erfl(long double); +long double erfcl(long double); +long double lgammal(long double); +long double tgammal(long double); + +long double ceill(long double); +long double floorl(long double); +long double nearbyintl(long double); +long double rintl(long double); +long int lrintl(long double); +long long int llrintl(long double); +long double roundl(long double); +long int lroundl(long double); +long long int llroundl(long double); +long double truncl(long double); + +long double fmodl(long double, long double); +long double remainderl(long double, long double); +long double remquol(long double, long double, int *); + +long double copysignl(long double, long double); +long double nanl(const char *); +long double nextafterl(long double, long double); +long double nexttowardl(long double, long double); + +long double fdiml(long double, long double); +long double fmaxl(long double, long double); +long double fminl(long double, long double); + +long double fmal(long double, long double, long double); +#endif /* __ISO_C_VISIBLE >= 1999 */ + +/* + * Long double versions of BSD math library entry points + */ +#if __BSD_VISIBLE +void sincosl(long double, long double *, long double *); +#endif + +/* + * Library implementation + */ +int __fpclassify(double); +int __fpclassifyf(float); +int __fpclassifyl(long double); +int __isfinite(double); +int __isfinitef(float); +int __isfinitel(long double); +int __isinf(double); +int __isinff(float); +int __isinfl(long double); +int __isnan(double); +int __isnanf(float); +int __isnanl(long double); +int __isnormal(double); +int __isnormalf(float); +int __isnormall(long double); +int __signbit(double); +int __signbitf(float); +int __signbitl(long double); +__END_DECLS + +#endif /* !_MATH_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/md5.h b/lib/libc/include/generic-openbsd/md5.h new file mode 100644 index 0000000000..a4623a50ef --- /dev/null +++ b/lib/libc/include/generic-openbsd/md5.h @@ -0,0 +1,49 @@ +/* $OpenBSD: md5.h,v 1.17 2012/12/05 23:19:57 deraadt Exp $ */ + +/* + * This code implements the MD5 message-digest algorithm. + * The algorithm is due to Ron Rivest. This code was + * written by Colin Plumb in 1993, no copyright is claimed. + * This code is in the public domain; do with it what you wish. + * + * Equivalent code is available from RSA Data Security, Inc. + * This code has been tested against that, and is equivalent, + * except that you don't need to include two pages of legalese + * with every copy. + */ + +#ifndef _MD5_H_ +#define _MD5_H_ + +#define MD5_BLOCK_LENGTH 64 +#define MD5_DIGEST_LENGTH 16 +#define MD5_DIGEST_STRING_LENGTH (MD5_DIGEST_LENGTH * 2 + 1) + +typedef struct MD5Context { + u_int32_t state[4]; /* state */ + u_int64_t count; /* number of bits, mod 2^64 */ + u_int8_t buffer[MD5_BLOCK_LENGTH]; /* input buffer */ +} MD5_CTX; + +__BEGIN_DECLS +void MD5Init(MD5_CTX *); +void MD5Update(MD5_CTX *, const u_int8_t *, size_t) + __attribute__((__bounded__(__string__,2,3))); +void MD5Pad(MD5_CTX *); +void MD5Final(u_int8_t [MD5_DIGEST_LENGTH], MD5_CTX *) + __attribute__((__bounded__(__minbytes__,1,MD5_DIGEST_LENGTH))); +void MD5Transform(u_int32_t [4], const u_int8_t [MD5_BLOCK_LENGTH]) + __attribute__((__bounded__(__minbytes__,1,4))) + __attribute__((__bounded__(__minbytes__,2,MD5_BLOCK_LENGTH))); +char *MD5End(MD5_CTX *, char *) + __attribute__((__bounded__(__minbytes__,2,MD5_DIGEST_STRING_LENGTH))); +char *MD5File(const char *, char *) + __attribute__((__bounded__(__minbytes__,2,MD5_DIGEST_STRING_LENGTH))); +char *MD5FileChunk(const char *, char *, off_t, off_t) + __attribute__((__bounded__(__minbytes__,2,MD5_DIGEST_STRING_LENGTH))); +char *MD5Data(const u_int8_t *, size_t, char *) + __attribute__((__bounded__(__string__,1,2))) + __attribute__((__bounded__(__minbytes__,3,MD5_DIGEST_STRING_LENGTH))); +__END_DECLS + +#endif /* _MD5_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/memory.h b/lib/libc/include/generic-openbsd/memory.h new file mode 100644 index 0000000000..c3228633f7 --- /dev/null +++ b/lib/libc/include/generic-openbsd/memory.h @@ -0,0 +1,35 @@ +/* $OpenBSD: memory.h,v 1.3 2003/06/02 19:34:12 millert Exp $ */ +/* $NetBSD: memory.h,v 1.3 1994/10/26 00:56:06 cgd Exp $ */ + +/* + * Copyright (c) 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. + * + * @(#)memory.h 5.5 (Berkeley) 6/1/90 + */ + +#include \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/_float.h b/lib/libc/include/generic-openbsd/mips64/_float.h new file mode 100644 index 0000000000..4bb91f4f9e --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/_float.h @@ -0,0 +1,71 @@ +/* $OpenBSD: _float.h,v 1.1 2012/06/26 16:12:44 deraadt Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _MACHINE__FLOAT_H_ +#define _MACHINE__FLOAT_H_ + +#define __FLT_RADIX 2 /* b */ +#define __FLT_ROUNDS __flt_rounds() +#define __FLT_EVAL_METHOD 0 /* no promotions */ + +#define __FLT_MANT_DIG 24 /* p */ +#define __FLT_EPSILON 1.19209290E-07F /* b**(1-p) */ +#define __FLT_DIG 6 /* floor((p-1)*log10(b))+(b == 10) */ +#define __FLT_MIN_EXP (-125) /* emin */ +#define __FLT_MIN 1.17549435E-38F /* b**(emin-1) */ +#define __FLT_MIN_10_EXP (-37) /* ceil(log10(b**(emin-1))) */ +#define __FLT_MAX_EXP 128 /* emax */ +#define __FLT_MAX 3.40282347E+38F /* (1-b**(-p))*b**emax */ +#define __FLT_MAX_10_EXP 38 /* floor(log10((1-b**(-p))*b**emax)) */ + +#define __DBL_MANT_DIG 53 +#define __DBL_EPSILON 2.2204460492503131E-16 +#define __DBL_DIG 15 +#define __DBL_MIN_EXP (-1021) +#define __DBL_MIN 2.2250738585072014E-308 +#define __DBL_MIN_10_EXP (-307) +#define __DBL_MAX_EXP 1024 +#define __DBL_MAX 1.7976931348623157E+308 +#define __DBL_MAX_10_EXP 308 + +#define __LDBL_MANT_DIG 113 +#define __LDBL_EPSILON 1.92592994438723585305597794258492732e-34L +#define __LDBL_DIG 33 +#define __LDBL_MIN_EXP (-16381) +#define __LDBL_MIN 3.36210314311209350626267781732175260e-4932L +#define __LDBL_MIN_10_EXP (-4931) +#define __LDBL_MAX_EXP 16384 +#define __LDBL_MAX 1.18973149535723176508575932662800702e+4932L +#define __LDBL_MAX_10_EXP 4932 + +#define __DECIMAL_DIG 36 + +#endif /* _MACHINE__FLOAT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/_types.h b/lib/libc/include/generic-openbsd/mips64/_types.h new file mode 100644 index 0000000000..ca5dbe7d7b --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/_types.h @@ -0,0 +1,154 @@ +/* $OpenBSD: _types.h,v 1.25 2023/07/02 19:02:28 cheloha Exp $ */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)types.h 8.3 (Berkeley) 1/5/94 + * @(#)ansi.h 8.2 (Berkeley) 1/4/94 + */ + +#ifndef _MIPS64__TYPES_H_ +#define _MIPS64__TYPES_H_ + +/* + * _ALIGN(p) rounds p (pointer or byte index) up to a correctly-aligned + * value for all data types (int, long, ...). The result is an + * unsigned long and must be cast to any desired pointer type. + * + * _ALIGNED_POINTER is a boolean macro that checks whether an address + * is valid to fetch data elements of type t from on this architecture. + * This does not reflect the optimal alignment, just the possibility + * (within reasonable limits). + */ +#define _ALIGNBYTES 7 +#define _STACKALIGNBYTES 15 +#define _ALIGN(p) (((unsigned long)(p) + _ALIGNBYTES) & ~_ALIGNBYTES) +#define _ALIGNED_POINTER(p,t) ((((unsigned long)(p)) & (sizeof(t) - 1)) == 0) +#define _MAX_PAGE_SHIFT 14 /* maximum possible PAGE_SHIFT */ + +/* + * We need to handle the various ISA levels for sizes. + */ +#define _MIPS_ISA_MIPS1 1 /* R2000/R3000 */ +#define _MIPS_ISA_MIPS2 2 /* R4000/R6000 */ +#define _MIPS_ISA_MIPS3 3 /* R4000 */ +#define _MIPS_ISA_MIPS4 4 /* TFP (R1x000) */ +#define _MIPS_ISA_MIPS32 32 /* MIPS32 */ +#define _MIPS_ISA_MIPS64 64 /* MIPS64 */ + +/* 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; +typedef long long __int64_t; +typedef unsigned long long __uint64_t; + +/* 7.18.1.2 Minimum-width integer types */ +typedef __int8_t __int_least8_t; +typedef __uint8_t __uint_least8_t; +typedef __int16_t __int_least16_t; +typedef __uint16_t __uint_least16_t; +typedef __int32_t __int_least32_t; +typedef __uint32_t __uint_least32_t; +typedef __int64_t __int_least64_t; +typedef __uint64_t __uint_least64_t; + +/* 7.18.1.3 Fastest minimum-width integer types */ +typedef __int32_t __int_fast8_t; +typedef __uint32_t __uint_fast8_t; +typedef __int32_t __int_fast16_t; +typedef __uint32_t __uint_fast16_t; +typedef __int32_t __int_fast32_t; +typedef __uint32_t __uint_fast32_t; +typedef __int64_t __int_fast64_t; +typedef __uint64_t __uint_fast64_t; +#define __INT_FAST8_MIN INT32_MIN +#define __INT_FAST16_MIN INT32_MIN +#define __INT_FAST32_MIN INT32_MIN +#define __INT_FAST64_MIN INT64_MIN +#define __INT_FAST8_MAX INT32_MAX +#define __INT_FAST16_MAX INT32_MAX +#define __INT_FAST32_MAX INT32_MAX +#define __INT_FAST64_MAX INT64_MAX +#define __UINT_FAST8_MAX UINT32_MAX +#define __UINT_FAST16_MAX UINT32_MAX +#define __UINT_FAST32_MAX UINT32_MAX +#define __UINT_FAST64_MAX UINT64_MAX + +/* 7.18.1.4 Integer types capable of holding object pointers */ +typedef long __intptr_t; +typedef unsigned long __uintptr_t; + +/* 7.18.1.5 Greatest-width integer types */ +typedef __int64_t __intmax_t; +typedef __uint64_t __uintmax_t; + +/* Register size */ +typedef long __register_t; +typedef long f_register_t; /* XXX */ + +/* VM system types */ +typedef unsigned long __vaddr_t; +typedef unsigned long __paddr_t; +typedef unsigned long __vsize_t; +typedef unsigned long __psize_t; + +/* Standard system types */ +typedef double __double_t; +typedef float __float_t; +typedef long __ptrdiff_t; +typedef unsigned long __size_t; +typedef long __ssize_t; +#if defined(__GNUC__) && __GNUC__ >= 3 +typedef __builtin_va_list __va_list; +#else +typedef char * __va_list; +#endif + +/* Wide character support types */ +#ifndef __cplusplus +typedef int __wchar_t; +#endif +typedef int __wint_t; +typedef int __rune_t; +typedef void * __wctrans_t; +typedef void * __wctype_t; + +#if defined(_KERNEL) +typedef struct label_t { + long val[14]; +} label_t; +#endif + +/* Feature test macros */ +#define __HAVE_EXEC_MD_MAP + +#endif /* _MIPS64__TYPES_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/archtype.h b/lib/libc/include/generic-openbsd/mips64/archtype.h new file mode 100644 index 0000000000..7ab1da2012 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/archtype.h @@ -0,0 +1,77 @@ +/* $OpenBSD: archtype.h,v 1.16 2012/10/03 21:44:51 miod Exp $ */ +/* + * Copyright (c) 1997-2004 Opsycon AB, Sweden (www.opsycon.se) + * + * 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 _MIPS64_ARCHTYPE_H_ +#define _MIPS64_ARCHTYPE_H_ +/* + * Define architectural identities for the different Mips machines. + */ +#define ACER_PICA_61 0x0001 /* Acer Labs Pica 61 */ +#define MAGNUM 0x0002 /* Mips MAGNUM R4000 */ +#define DESKSTATION_RPC44 0x0003 /* Deskstation rPC44 */ +#define DESKSTATION_TYNE 0x0004 /* Deskstation Tyne */ +#define NKK_AQUARIUS 0x0005 /* NKK R4{67}00 PC */ +#define NEC_R94 0x0006 /* NEC Magnum class */ +#define SNI_RM200 0x0007 /* Siemens Nixdorf RM200 */ + +#define SGI_IP17 0x0011 /* Crimson */ +#define SGI_IP19 0x0012 /* Onyx (!S model Challenge) */ +#define SGI_IP20 0x0013 /* Indigo */ +#define SGI_IP21 0x0014 /* POWER Challenge, POWER Onyx */ +#define SGI_IP22 0x0015 /* Indy, Indigo2, Challenge S */ +#define SGI_IP25 0x0016 /* POWER Challenge R10k */ +#define SGI_IP26 0x0017 /* POWER Indigo2 R8k */ +#define SGI_IP27 0x0018 /* IP27 Origin200/2000 */ +#define SGI_IP28 0x0019 /* POWER Indigo2 R10k */ +#define SGI_OCTANE 0x001a /* IP30 Octane */ +#define SGI_O2 0x001b /* IP32 O2 */ +#define SGI_IP35 0x001c /* IP35 Origin3x0/3x00/Fuel/Tezro */ + +#define ALGOR_P4032 0x0021 /* ALGORITHMICS P-4032 */ +#define ALGOR_P5064 0x0022 /* ALGORITHMICS P-5064 */ + +#define GALILEO_G9 0x0031 /* Galileo GT-64011 Eval board */ +#define GALILEO_EV64240 0x0032 /* Galileo EV64240 Eval board */ +#define GALILEO_EV64340 0x0033 /* Galileo EV64340 Eval board */ + +#define MOMENTUM_CP7000 0x0041 /* Momentum Ocelot */ +#define MOMENTUM_CP7000G 0x0042 /* Momentum Ocelot-G */ +#define MOMENTUM_JAGUAR 0x0043 /* Momentum Jaguar ATX */ + +#define WG4308 0x0052 /* Willowglen 4308 LMD */ +#define WG4309 0x0053 /* Willowglen 4309 LMD */ +#define WG4409 0x0054 /* Willowglen 4409 LMD */ +#define WG8138 0x0055 /* Willowglen 8138 523x VME card */ +#define WG8168 0x0056 /* Willowglen 8168 5231 VME card */ +#define WG6000 0x0057 /* Willowglen CPU-6000 */ +#define WG7000 0x0058 /* Willowglen CPU-7000 */ +#define WG8200 0x0059 /* Willowglen CPU-8200 */ +#define WG8232 0x005a /* Willowglen CPU-8232 */ + +#define LAGUNA 0x00f1 /* Heurikon Laguna VME board */ + +#endif /* !_MIPS64_ARCHTYPE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/asm.h b/lib/libc/include/generic-openbsd/mips64/asm.h new file mode 100644 index 0000000000..8bc7582551 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/asm.h @@ -0,0 +1,360 @@ +/* $OpenBSD: asm.h,v 1.27 2021/05/01 16:11:10 visa Exp $ */ + +/* + * Copyright (c) 2001-2002 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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 _MIPS64_ASM_H_ +#define _MIPS64_ASM_H_ + +#include + +#define _MIPS_ISA_MIPS1 1 /* R2000/R3000 */ +#define _MIPS_ISA_MIPS2 2 /* R4000/R6000 */ +#define _MIPS_ISA_MIPS3 3 /* R4000 */ +#define _MIPS_ISA_MIPS4 4 /* TFP (R1x000) */ +#define _MIPS_ISA_MIPS32 32 /* MIPS32 */ +#define _MIPS_ISA_MIPS64 64 /* MIPS64 */ + +#if !defined(ABICALLS) && !defined(_NO_ABICALLS) +#define ABICALLS .abicalls +#endif + +#if defined(ABICALLS) && !defined(_KERNEL) + ABICALLS +#endif + +#define _C_LABEL(x) x /* XXX Obsolete but keep for a while */ + +#if !defined(__MIPSEL__) && !defined(__MIPSEB__) +#error "__MIPSEL__ or __MIPSEB__ must be defined" +#endif +/* + * Define how to access unaligned data word + */ +#if defined(__MIPSEL__) +#define LWLO lwl +#define LWHI lwr +#define SWLO swl +#define SWHI swr +#define LDLO ldl +#define LDHI ldr +#define SDLO sdl +#define SDHI sdr +#endif +#if defined(__MIPSEB__) +#define LWLO lwr +#define LWHI lwl +#define SWLO swr +#define SWHI swl +#define LDLO ldr +#define LDHI ldl +#define SDLO sdr +#define SDHI sdl +#endif + +/* + * Define programming environment for ABI. + */ +#if defined(ABICALLS) && !defined(_KERNEL) && !defined(_STANDALONE) + +#ifndef _MIPS_SIM +#define _MIPS_SIM 1 +#define _ABIO32 1 +#endif +#ifndef _MIPS_ISA +#define _MIPS_ISA 2 +#define _MIPS_ISA_MIPS2 2 +#endif + +#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32) +#define NARGSAVE 4 + +#define SETUP_GP \ + .set noreorder; \ + .cpload t9; \ + .set reorder; + +#define SAVE_GP(x) \ + .cprestore x + +#define SETUP_GP64(gpoff, name) +#define RESTORE_GP64 +#endif + +#if (_MIPS_SIM == _ABI64) || (_MIPS_SIM == _ABIN32) +#define NARGSAVE 0 + +#define SETUP_GP +#define SAVE_GP(x) +#define SETUP_GP64(gpoff, name) \ + .cpsetup t9, gpoff, name +#define RESTORE_GP64 \ + .cpreturn +#endif + +#define MKFSIZ(narg,locals) (((narg+locals)*REGSZ+31)&(~31)) + +#else /* defined(ABICALLS) && !defined(_KERNEL) */ + +#define NARGSAVE 4 +#define SETUP_GP +#define SAVE_GP(x) + +#define ALIGNSZ 16 /* Stack layout alignment */ +#define FRAMESZ(sz) (((sz) + (ALIGNSZ-1)) & ~(ALIGNSZ-1)) + +#endif + +/* + * Basic register operations based on selected ISA + */ +#if (_MIPS_ISA == _MIPS_ISA_MIPS1 || _MIPS_ISA == _MIPS_ISA_MIPS2 || \ + _MIPS_ISA == _MIPS_ISA_MIPS32) +#define REGSZ 4 /* 32 bit mode register size */ +#define LOGREGSZ 2 /* log rsize */ +#define REG_S sw +#define REG_L lw +#define CF_SZ 24 /* Call frame size */ +#define CF_ARGSZ 16 /* Call frame arg size */ +#define CF_RA_OFFS 20 /* Call ra save offset */ +#endif + +#if (_MIPS_ISA == _MIPS_ISA_MIPS3 || _MIPS_ISA == _MIPS_ISA_MIPS4 || \ + _MIPS_ISA == _MIPS_ISA_MIPS64) +#define REGSZ 8 /* 64 bit mode register size */ +#define LOGREGSZ 3 /* log rsize */ +#define REG_S sd +#define REG_L ld +#define CF_SZ 48 /* Call frame size (multiple of ALIGNSZ) */ +#define CF_ARGSZ 32 /* Call frame arg size */ +#define CF_RA_OFFS 40 /* Call ra save offset */ +#endif + +#ifndef __LP64__ +#define PTR_L lw +#define PTR_S sw +#define PTR_SUB sub +#define PTR_ADD add +#define PTR_SUBU subu +#define PTR_ADDU addu +#define LI li +#define LA la +#define PTR_SLL sll +#define PTR_SRL srl +#define PTR_VAL .word +#else +#define PTR_L ld +#define PTR_S sd +#define PTR_ADD dadd +#define PTR_SUB dsub +#define PTR_SUBU dsubu +#define PTR_ADDU daddu +#define LI dli +#define LA dla +#define PTR_SLL dsll +#define PTR_SRL dsrl +#define PTR_VAL .dword +#endif + +#define NOP nop +#define DMFC0 dmfc0 +#define DMTC0 dmtc0 +#define MFC0 mfc0 +#define MTC0 mtc0 +#define ERET sync; eret + +/* + * Define -pg profile entry code. + */ +#if defined(XGPROF) || defined(XPROF) +#define MCOUNT \ + PTR_SUBU sp, sp, 64; \ + SAVE_GP(16); \ + sd ra, 56(sp); \ + sd gp, 48(sp); \ + .set noat; \ + .set noreorder; \ + move AT, ra; \ + jal _mcount; \ + PTR_SUBU sp, sp, 16; \ + ld ra, 56(sp); \ + PTR_ADDU sp, sp, 64; \ + .set reorder; \ + .set at; +#else +#define MCOUNT +#endif + +/* + * LEAF(x, fsize) + * + * Declare a leaf routine. + */ +#define LEAF(x, fsize) \ + .align 3; \ + .globl x; \ + .ent x, 0; \ +x: ; \ + .frame sp, fsize, ra; \ + SETUP_GP \ + MCOUNT + +#define ALEAF(x) \ + .globl x; \ +x: + +/* + * NLEAF(x) + * + * Declare a non-profiled leaf routine. + */ +#define NLEAF(x, fsize) \ + .align 3; \ + .globl x; \ + .ent x, 0; \ +x: ; \ + .frame sp, fsize, ra; \ + SETUP_GP + +/* + * NON_LEAF(x) + * + * Declare a non-leaf routine (a routine that makes other C calls). + */ +#define NON_LEAF(x, fsize, retpc) \ + .align 3; \ + .globl x; \ + .ent x, 0; \ +x: ; \ + .frame sp, fsize, retpc; \ + SETUP_GP \ + MCOUNT + +/* + * NNON_LEAF(x) + * + * Declare a non-profiled non-leaf routine + * (a routine that makes other C calls). + */ +#define NNON_LEAF(x, fsize, retpc) \ + .align 3; \ + .globl x; \ + .ent x, 0; \ +x: ; \ + .frame sp, fsize, retpc \ + SETUP_GP + +/* + * END(x) + * + * Mark end of a procedure. + */ +#define END(x) \ + .end x + +/* + * STRONG_ALIAS, WEAK_ALIAS + * Create a strong or weak alias. + */ +#define STRONG_ALIAS(alias,sym) \ + .global alias; alias = sym +#define WEAK_ALIAS(alias,sym) \ + .weak alias; alias = sym + + +/* + * Macros to panic and printf from assembly language. + */ +#define PANIC(msg) \ + LA a0, 9f; \ + jal panic; \ + nop ; \ + MSG(msg) + +#define PRINTF(msg) \ + LA a0, 9f; \ + jal printf; \ + nop ; \ + MSG(msg) + +#define MSG(msg) \ + .rdata; \ +9: .asciiz msg; \ + .text + +#define LOAD_XKPHYS(reg, cca) \ + li reg, cca | 0x10; \ + dsll reg, reg, 59 + +#ifdef MULTIPROCESSOR +#define GET_CPU_INFO(ci, tmp) HW_GET_CPU_INFO(ci, tmp) +#else /* MULTIPROCESSOR */ +#define GET_CPU_INFO(ci, tmp) \ + LA ci, cpu_info_primary +#endif /* MULTIPROCESSOR */ + +/* + * Hazards + */ + +#ifdef CPU_OCTEON +/* + * OCTEON clears hazards in hardware. + */ +#define MFC0_HAZARD /* nothing */ +#define MTC0_HAZARD /* nothing */ +#define MTC0_SR_IE_HAZARD /* nothing */ +#define MTC0_SR_CU_HAZARD /* nothing */ +#define TLB_HAZARD /* nothing */ +#endif + +/* Hazard between {d,}mfc0 of COP_0_VADDR */ +#ifndef PRE_MFC0_ADDR_HAZARD +#define PRE_MFC0_ADDR_HAZARD /* nothing */ +#endif + +/* Hazard after {d,}mfc0 from any register */ +#ifndef MFC0_HAZARD +#define MFC0_HAZARD /* nothing */ +#endif +/* Hazard after {d,}mtc0 to any register */ +#ifndef MTC0_HAZARD +#define MTC0_HAZARD NOP; NOP; NOP; NOP +#endif +/* Hazard after {d,}mtc0 to COP_0_SR affecting the state of interrupts */ +#ifndef MTC0_SR_IE_HAZARD +#define MTC0_SR_IE_HAZARD MTC0_HAZARD +#endif +/* Hazard after {d,}mtc0 to COP_0_SR affecting the state of coprocessors */ +#ifndef MTC0_SR_CU_HAZARD +#define MTC0_SR_CU_HAZARD NOP; NOP +#endif + +/* Hazard before and after a tlbp, tlbr, tlbwi or tlbwr instruction */ +#ifndef TLB_HAZARD +#define TLB_HAZARD NOP; NOP +#endif + +#endif /* !_MIPS64_ASM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/atomic.h b/lib/libc/include/generic-openbsd/mips64/atomic.h new file mode 100644 index 0000000000..a5b8737ccb --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/atomic.h @@ -0,0 +1,214 @@ +/* $OpenBSD: atomic.h,v 1.12 2019/10/28 09:41:37 visa Exp $ */ + +/* Public Domain */ + +#ifndef _MIPS64_ATOMIC_H_ +#define _MIPS64_ATOMIC_H_ + +#if defined(_KERNEL) + +/* wait until the bits to set are clear, and set them */ +static __inline void +atomic_wait_and_setbits_int(volatile unsigned int *uip, unsigned int v) +{ + unsigned int tmp0, tmp1; + + __asm__ volatile ( + "1: ll %0, 0(%2)\n" + " and %1, %0, %3\n" + " bnez %1, 1b\n" + " or %0, %3, %0\n" + " sc %0, 0(%2)\n" + " beqz %0, 1b\n" + " nop\n" : + "=&r"(tmp0), "=&r"(tmp1) : + "r"(uip), "r"(v) : "memory"); +} + +static __inline void +atomic_setbits_int(volatile unsigned int *uip, unsigned int v) +{ + unsigned int tmp; + + __asm__ volatile ( + "1: ll %0, 0(%1)\n" + " or %0, %2, %0\n" + " sc %0, 0(%1)\n" + " beqz %0, 1b\n" + " nop\n" : + "=&r"(tmp) : + "r"(uip), "r"(v) : "memory"); +} + +static __inline void +atomic_clearbits_int(volatile unsigned int *uip, unsigned int v) +{ + unsigned int tmp; + + __asm__ volatile ( + "1: ll %0, 0(%1)\n" + " and %0, %2, %0\n" + " sc %0, 0(%1)\n" + " beqz %0, 1b\n" + " nop\n" : + "=&r"(tmp) : + "r"(uip), "r"(~v) : "memory"); +} + +#endif /* defined(_KERNEL) */ + +static inline unsigned int +_atomic_cas_uint(volatile unsigned int *p, unsigned int o, unsigned int n) +{ + unsigned int rv, wv; + + __asm__ volatile ( + "1: ll %0, %1\n" + " bne %0, %4, 2f\n" + " move %2, %3\n" + " sc %2, %1\n" + " beqz %2, 1b\n" + "2: nop\n" + : "=&r" (rv), "+m" (*p), "=&r" (wv) + : "r" (n), "Ir" (o)); + + 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, wv; + + __asm__ volatile ( + "1: lld %0, %1\n" + " bne %0, %4, 2f\n" + " move %2, %3\n" + " scd %2, %1\n" + " beqz %2, 1b\n" + "2: nop\n" + : "=&r" (rv), "+m" (*p), "=&r" (wv) + : "r" (n), "Ir" (o)); + + 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, *wv; + + __asm__ volatile ( + "1: lld %0, %1\n" + " bne %0, %4, 2f\n" + " move %2, %3\n" + " scd %2, %1\n" + " beqz %2, 1b\n" + "2: nop\n" + : "=&r" (rv), "+m" (*p), "=&r" (wv) + : "r" (n), "Ir" (o)); + + 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 *uip, unsigned int v) +{ + unsigned int o, t; + + __asm__ volatile ( + "1: ll %0, %1\n" + " move %2, %3\n" + " sc %2, %1\n" + " beqz %2, 1b\n" + " nop\n" + : "=&r" (o), "+m" (*uip), "=&r" (t) + : "r" (v)); + + return (o); +} +#define atomic_swap_uint(_p, _v) _atomic_swap_uint((_p), (_v)) + +static inline unsigned long +_atomic_swap_ulong(volatile unsigned long *uip, unsigned long v) +{ + unsigned long o, t; + + __asm__ volatile ( + "1: lld %0, %1\n" + " move %2, %3\n" + " scd %2, %1\n" + " beqz %2, 1b\n" + " nop\n" + : "=&r" (o), "+m" (*uip), "=&r" (t) + : "r" (v)); + + return (o); +} +#define atomic_swap_ulong(_p, _v) _atomic_swap_ulong((_p), (_v)) + + +static inline void * +_atomic_swap_ptr(volatile void *uipp, void *n) +{ + void * volatile *uip = uipp; + void *o, *t; + + __asm__ volatile ( + "1: lld %0, %1\n" + " move %2, %3\n" + " scd %2, %1\n" + " beqz %2, 1b\n" + " nop\n" + : "=&r" (o), "+m" (*uip), "=&r" (t) + : "r" (n)); + + return (o); +} +#define atomic_swap_ptr(_p, _n) _atomic_swap_ptr((_p), (_n)) + +static inline unsigned int +_atomic_add_int_nv(volatile unsigned int *uip, unsigned int v) +{ + unsigned int rv, nv; + + __asm__ volatile ( + "1: ll %0, %1\n" + " addu %2, %0, %3\n" + " sc %2, %1\n" + " beqz %2, 1b\n" + " nop\n" + : "=&r" (rv), "+m" (*uip), "=&r" (nv) + : "Ir" (v)); + + return (rv + v); +} +#define atomic_add_int_nv(_uip, _v) _atomic_add_int_nv((_uip), (_v)) +#define atomic_sub_int_nv(_uip, _v) _atomic_add_int_nv((_uip), 0 - (_v)) + +static inline unsigned long +_atomic_add_long_nv(volatile unsigned long *uip, unsigned long v) +{ + unsigned long rv, nv; + + __asm__ volatile ( + "1: lld %0, %1\n" + " daddu %2, %0, %3\n" + " scd %2, %1\n" + " beqz %2, 1b\n" + " nop\n" + : "=&r" (rv), "+m" (*uip), "=&r" (nv) + : "Ir" (v)); + + return (rv + v); +} +#define atomic_add_long_nv(_uip, _v) _atomic_add_long_nv((_uip), (_v)) +#define atomic_sub_long_nv(_uip, _v) _atomic_add_long_nv((_uip), 0UL - (_v)) + +#endif /* _MIPS64_ATOMIC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/autoconf.h b/lib/libc/include/generic-openbsd/mips64/autoconf.h new file mode 100644 index 0000000000..8a518cca7f --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/autoconf.h @@ -0,0 +1,37 @@ +/* $OpenBSD: autoconf.h,v 1.2 2017/06/08 12:02:52 visa Exp $ */ + +/* + * Copyright (c) 2010 Miodrag Vallat. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * Common defines used by autoconf on all mips64-based platforms. + */ + +#ifndef _MIPS64_AUTOCONF_H_ +#define _MIPS64_AUTOCONF_H_ + +#include /* for struct cpu_hwinfo */ + +struct cpu_attach_args { + struct mainbus_attach_args caa_maa; + struct cpu_hwinfo *caa_hw; +}; + +extern struct cpu_hwinfo bootcpu_hwinfo; + +void unmap_startup(void); + +#endif /* _MIPS64_AUTOCONF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/cache.h b/lib/libc/include/generic-openbsd/mips64/cache.h new file mode 100644 index 0000000000..0f7ba84945 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/cache.h @@ -0,0 +1,107 @@ +/* $OpenBSD: cache.h,v 1.9 2016/12/21 13:59:57 visa Exp $ */ + +/* + * Copyright (c) 2012 Miodrag Vallat. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MIPS64_CACHE_H_ +#define _MIPS64_CACHE_H_ + +/* + * Declare canonical cache functions for a given processor. + * + * The following assumptions are made: + * - only L1 has split instruction and data caches. + * - L1 I$ is virtually indexed. + * + * Processor-specific routines will make extra assumptions. + */ + +#define CACHE_PROTOS(chip) \ +/* Figure out cache configuration */ \ +void chip##_ConfigCache(struct cpu_info *); \ +/* Writeback and invalidate all caches */ \ +void chip##_SyncCache(struct cpu_info *); \ +/* Invalidate all I$ for the given range */ \ +void chip##_InvalidateICache(struct cpu_info *, vaddr_t, size_t); \ +/* Register a given page for I$ invalidation */ \ +void chip##_InvalidateICachePage(struct cpu_info *, vaddr_t); \ +/* Perform postponed I$ invalidation */ \ +void chip##_SyncICache(struct cpu_info *); \ +/* Writeback all D$ for the given page */ \ +void chip##_SyncDCachePage(struct cpu_info *, vaddr_t, paddr_t); \ +/* Writeback all D$ for the (currently mapped) given page */ \ +void chip##_HitSyncDCachePage(struct cpu_info *, vaddr_t, paddr_t); \ +/* Writeback all D$ for the given range */ \ +void chip##_HitSyncDCache(struct cpu_info *, vaddr_t, size_t); \ +/* Invalidate all D$ for the given range */ \ +void chip##_HitInvalidateDCache(struct cpu_info *, vaddr_t, size_t); \ +/* Enforce coherency of the given range */ \ +void chip##_IOSyncDCache(struct cpu_info *, vaddr_t, size_t, int); + +/* + * Cavium Octeon. + */ +CACHE_PROTOS(Octeon) + +void Octeon_lock_secondary_cache(struct cpu_info *, paddr_t, size_t); +void Octeon_unlock_secondary_cache(struct cpu_info *, paddr_t, size_t); + +/* + * STC Loongson 2E and 2F. + */ +CACHE_PROTOS(Loongson2) + +/* + * Loongson 3A and 2Gq. + */ +CACHE_PROTOS(Loongson3) + +/* + * MIPS R4000 and R4400. + */ +CACHE_PROTOS(Mips4k) + +/* + * IDT/QED/PMC-Sierra R4600, R4700, R5000, RM52xx, RM7xxx, RM9xxx. + */ +CACHE_PROTOS(Mips5k) + +/* + * MIPS (SGI, really) R8000. + */ +CACHE_PROTOS(tfp) + +/* + * MIPS/NEC R10000/R120000/R140000/R16000. + */ +CACHE_PROTOS(Mips10k) + +/* + * mips64r2-compliant processors. + */ +CACHE_PROTOS(mips64r2) + +/* + * Values used by the IOSyncDCache routine [which acts as the backend of + * bus_dmamap_sync()]. + */ +#define CACHE_SYNC_R 0 /* WB invalidate, WT invalidate */ +#define CACHE_SYNC_W 1 /* WB writeback, WT unaffected */ +#define CACHE_SYNC_X 2 /* WB writeback + invalidate, WT invalidate */ + +extern vaddr_t cache_valias_mask; + +#endif /* _MIPS64_CACHE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/cdefs.h b/lib/libc/include/generic-openbsd/mips64/cdefs.h new file mode 100644 index 0000000000..685c9d51d5 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/cdefs.h @@ -0,0 +1,43 @@ +/* $OpenBSD: cdefs.h,v 1.6 2013/03/28 17:30:45 martynas Exp $ */ + +/* + * Copyright (c) 2002-2003 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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 _MIPS64_CDEFS_H_ +#define _MIPS64_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") +#define __indr_references(sym,msg) /* nothing */ + +#endif /* !_MIPS64_CDEFS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/cpu.h b/lib/libc/include/generic-openbsd/mips64/cpu.h new file mode 100644 index 0000000000..20177a2555 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/cpu.h @@ -0,0 +1,552 @@ +/* $OpenBSD: cpu.h,v 1.151 2025/06/06 00:07:58 deraadt 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 and Rick Macklem. + * + * 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. + * + * Copyright (C) 1989 Digital Equipment Corporation. + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby granted, + * provided that the above copyright notice appears in all copies. + * Digital Equipment Corporation makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * from: @(#)cpu.h 8.4 (Berkeley) 1/4/94 + */ + +#ifndef _MIPS64_CPU_H_ +#define _MIPS64_CPU_H_ + +#ifndef _LOCORE + +/* + * MIPS32-style segment definitions. + * They only cover the first 512MB of physical addresses. + */ +#define CKSEG0_BASE 0xffffffff80000000UL +#define CKSEG1_BASE 0xffffffffa0000000UL +#define CKSSEG_BASE 0xffffffffc0000000UL +#define CKSEG3_BASE 0xffffffffe0000000UL +#define CKSEG_SIZE 0x0000000020000000UL + +#define CKSEG0_TO_PHYS(x) ((u_long)(x) & (CKSEG_SIZE - 1)) +#define CKSEG1_TO_PHYS(x) ((u_long)(x) & (CKSEG_SIZE - 1)) +#define PHYS_TO_CKSEG0(x) ((u_long)(x) | CKSEG0_BASE) +#define PHYS_TO_CKSEG1(x) ((u_long)(x) | CKSEG1_BASE) + +/* + * MIPS64-style segment definitions. + * These allow for 36 bits of addressable physical memory, thus 64GB. + */ + +/* + * Cache Coherency Attributes. + */ +/* r8k only */ +#define CCA_NC_COPROCESSOR 0UL /* uncached, coprocessor ordered */ +/* common to r4, r5k, r8k and r1xk */ +#define CCA_NC 2UL /* uncached, write-around */ +#define CCA_NONCOHERENT 3UL /* cached, non-coherent, write-back */ +/* r8k, r1xk only */ +#define CCA_COHERENT_EXCL 4UL /* cached, coherent, exclusive */ +#define CCA_COHERENT_EXCLWRITE 5UL /* cached, coherent, exclusive write */ +/* r4k only */ +#define CCA_COHERENT_UPDWRITE 6UL /* cached, coherent, update on write */ +/* r1xk only */ +#define CCA_NC_ACCELERATED 7UL /* uncached accelerated */ + +#ifdef TGT_COHERENT +#define CCA_CACHED CCA_COHERENT_EXCLWRITE +#else +#define CCA_CACHED CCA_NONCOHERENT +#endif + +#define XKSSSEG_BASE 0x4000000000000000UL +#define XKPHYS_BASE 0x8000000000000000UL +#define XKSSEG_BASE 0xc000000000000000UL + +#define XKPHYS_TO_PHYS(x) ((paddr_t)(x) & 0x0000000fffffffffUL) +#define PHYS_TO_XKPHYS(x,c) ((paddr_t)(x) | XKPHYS_BASE | ((c) << 59)) +#define IS_XKPHYS(va) (((va) >> 62) == 2) +#define XKPHYS_TO_CCA(x) (((x) >> 59) & 0x07) + +#endif /* _LOCORE */ + +/* + * Exported definitions unique to mips cpu support. + */ + +#if defined(_KERNEL) && !defined(_LOCORE) + +#include +#include +#include +#include +#include +#include + +struct cpu_hwinfo { + uint32_t c0prid; + uint32_t c1prid; + uint32_t clock; /* Hz */ + uint32_t tlbsize; + uint type; + uint32_t l2size; +}; + +/* + * Cache memory configuration. One struct per cache. + */ +struct cache_info { + uint size; /* total cache size */ + uint linesize; /* line size */ + uint setsize; /* set size */ + uint sets; /* number of sets */ +}; + +struct cpu_info { + struct device *ci_dev; /* our device */ + struct cpu_info *ci_self; /* pointer to this structure */ + struct cpu_info *ci_next; /* next cpu */ + struct proc *ci_curproc; + struct user *ci_curprocpaddr; + struct proc *ci_fpuproc; /* pointer to last proc to use FP */ + uint32_t ci_delayconst; + struct cpu_hwinfo + ci_hw; + +#if defined(MULTIPROCESSOR) + struct srp_hazard ci_srp_hazards[SRP_HAZARD_NUM]; +#define __HAVE_UVM_PERCPU + struct uvm_pmr_cache ci_uvm; +#endif + + /* cache information and pending flush state */ + uint ci_cacheconfiguration; + uint64_t ci_cachepending_l1i; + struct cache_info + ci_l1inst, + ci_l1data, + ci_l2, + ci_l3; + + /* function pointers for the cache handling routines */ + void (*ci_SyncCache)(struct cpu_info *); + void (*ci_InvalidateICache)(struct cpu_info *, vaddr_t, + size_t); + void (*ci_InvalidateICachePage)(struct cpu_info *, vaddr_t); + void (*ci_SyncICache)(struct cpu_info *); + void (*ci_SyncDCachePage)(struct cpu_info *, vaddr_t, + paddr_t); + void (*ci_HitSyncDCachePage)(struct cpu_info *, vaddr_t, + paddr_t); + void (*ci_HitSyncDCache)(struct cpu_info *, vaddr_t, size_t); + void (*ci_HitInvalidateDCache)(struct cpu_info *, vaddr_t, + size_t); + void (*ci_IOSyncDCache)(struct cpu_info *, vaddr_t, size_t, + int); + + struct schedstate_percpu + ci_schedstate; + int ci_want_resched; /* need_resched() invoked */ + cpuid_t ci_cpuid; /* our CPU ID */ + uint32_t ci_randseed; /* per cpu random seed */ + volatile int ci_ipl; /* software IPL */ + uint32_t ci_softpending; /* pending soft interrupts */ + int ci_clock_started; + volatile int ci_clock_deferred; /* clock interrupt postponed */ + struct clockqueue + ci_queue; + + struct pmap *ci_curpmap; + uint ci_idepth; /* interrupt depth */ + volatile u_long ci_flags; /* flags; see below */ + volatile int ci_ddb; +#define CI_DDB_RUNNING 0 +#define CI_DDB_SHOULDSTOP 1 +#define CI_DDB_STOPPED 2 +#define CI_DDB_ENTERDDB 3 +#define CI_DDB_INDDB 4 + +#ifdef DIAGNOSTIC + int ci_mutex_level; +#endif +#ifdef GPROF + struct gmonparam *ci_gmon; + struct clockintr ci_gmonclock; +#endif + char ci_panicbuf[512]; +}; + +#define CPUF_PRIMARY 0x01 /* CPU is primary CPU */ +#define CPUF_PRESENT 0x02 /* CPU is present */ +#define CPUF_RUNNING 0x04 /* CPU is running */ + +extern struct cpu_info cpu_info_primary; +extern struct cpu_info *cpu_info_list; +#define CPU_INFO_ITERATOR int +#define CPU_INFO_FOREACH(cii, ci) for (cii = 0, ci = cpu_info_list; \ + ci != NULL; ci = ci->ci_next) + +#define CPU_INFO_UNIT(ci) ((ci)->ci_dev ? (ci)->ci_dev->dv_unit : 0) + +#define cpu_idle_enter() do { /* nothing */ } while (0) +#define cpu_idle_leave() do { /* nothing */ } while (0) +extern void (*cpu_idle_cycle_func)(void); +#define cpu_idle_cycle() (*cpu_idle_cycle_func)() + +#ifdef MULTIPROCESSOR +#define getcurcpu() hw_getcurcpu() +#define setcurcpu(ci) hw_setcurcpu(ci) +extern struct cpu_info *get_cpu_info(int); +#define curcpu() getcurcpu() +#define CPU_IS_PRIMARY(ci) ((ci)->ci_flags & CPUF_PRIMARY) +#define CPU_IS_RUNNING(ci) ((ci)->ci_flags & CPUF_RUNNING) +#define cpu_number() (curcpu()->ci_cpuid) + +void cpu_unidle(struct cpu_info *); +void cpu_boot_secondary_processors(void); +#define cpu_boot_secondary(ci) hw_cpu_boot_secondary(ci) +#define cpu_hatch(ci) hw_cpu_hatch(ci) + +vaddr_t alloc_contiguous_pages(size_t); + +#define MIPS64_IPI_NOP 0x00000001 +#define MIPS64_IPI_RENDEZVOUS 0x00000002 +#define MIPS64_IPI_DDB 0x00000004 +#define MIPS64_NIPIS 3 /* must not exceed 32 */ + +void mips64_ipi_init(void); +void mips64_send_ipi(unsigned int, unsigned int); +void smp_rendezvous_cpus(unsigned long, void (*)(void *), void *arg); + +#include +#else +#define MAXCPUS 1 +#define curcpu() (&cpu_info_primary) +#define CPU_IS_PRIMARY(ci) 1 +#define CPU_IS_RUNNING(ci) 1 +#define cpu_number() 0UL +#define cpu_unidle(ci) +#define get_cpu_info(i) (&cpu_info_primary) +#endif + +#define CPU_BUSY_CYCLE() __asm volatile ("" ::: "memory") + +extern void (*md_initclock)(void); +extern void (*md_startclock)(struct cpu_info *); +extern void (*md_triggerclock)(void); +void cp0_calibrate(struct cpu_info *); + +unsigned int cpu_rnd_messybits(void); + +#include + +/* + * Arguments to hardclock encapsulate the previous machine state in + * an opaque clockframe. + */ +#define clockframe trapframe /* Use normal trap frame */ + +#define SR_KSU_USER 0x00000010 +#define CLKF_USERMODE(framep) ((framep)->sr & SR_KSU_USER) +#define CLKF_PC(framep) ((framep)->pc) +#define CLKF_INTR(framep) (curcpu()->ci_idepth > 1) /* XXX */ + +/* + * This is used during profiling to integrate system time. + */ +#define PROC_PC(p) ((p)->p_md.md_regs->pc) +#define PROC_STACK(p) ((p)->p_md.md_regs->sp) + +/* + * Preempt the current process if in interrupt from user mode, + * or after the current trap/syscall if in system mode. + */ +void need_resched(struct cpu_info *); +#define clear_resched(ci) (ci)->ci_want_resched = 0 + +/* + * Give a profiling tick to the current process when the user profiling + * buffer pages are invalid. On MIPS designs, request an ast to send us + * through trap, marking the proc as needing a profiling tick. + */ +#define need_proftick(p) aston(p) + +/* + * Notify the current process (p) that it has a signal pending, + * process as soon as possible. + */ +void signotify(struct proc *); + +#define aston(p) ((p)->p_md.md_astpending = 1) + +#define mips_sync() __asm__ volatile ("sync" ::: "memory") + +#endif /* _KERNEL && !_LOCORE */ + +#ifdef _KERNEL +/* + * Values for the code field in a break instruction. + */ +#define BREAK_INSTR 0x0000000d +#define BREAK_VAL_MASK 0x03ff0000 +#define BREAK_VAL_SHIFT 16 +#define BREAK_KDB_VAL 512 +#define BREAK_SSTEP_VAL 513 +#define BREAK_BRKPT_VAL 514 +#define BREAK_SOVER_VAL 515 +#define BREAK_DDB_VAL 516 +#define BREAK_FPUEMUL_VAL 517 +#define BREAK_KDB (BREAK_INSTR | (BREAK_KDB_VAL << BREAK_VAL_SHIFT)) +#define BREAK_SSTEP (BREAK_INSTR | (BREAK_SSTEP_VAL << BREAK_VAL_SHIFT)) +#define BREAK_BRKPT (BREAK_INSTR | (BREAK_BRKPT_VAL << BREAK_VAL_SHIFT)) +#define BREAK_SOVER (BREAK_INSTR | (BREAK_SOVER_VAL << BREAK_VAL_SHIFT)) +#define BREAK_DDB (BREAK_INSTR | (BREAK_DDB_VAL << BREAK_VAL_SHIFT)) +#define BREAK_FPUEMUL (BREAK_INSTR | (BREAK_FPUEMUL_VAL << BREAK_VAL_SHIFT)) + +#endif /* _KERNEL */ + +/* + * CTL_MACHDEP definitions. + */ +#define CPU_ALLOWAPERTURE 1 /* allow mmap of /dev/xf86 */ + /* 2 formerly: keyboard reset */ + /* 3 formerly: CPU_LIDSUSPEND */ +#define CPU_LIDACTION 4 /* action caused by lid close */ +#define CPU_MAXID 5 /* number of valid machdep ids */ + +#define CTL_MACHDEP_NAMES { \ + { 0, 0 }, \ + { "allowaperture", CTLTYPE_INT }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "lidaction", CTLTYPE_INT }, \ +} + +/* + * MIPS CPU types (cp_imp). + */ +#define MIPS_R2000 0x01 /* MIPS R2000 CPU ISA I */ +#define MIPS_R3000 0x02 /* MIPS R3000 CPU ISA I */ +#define MIPS_R6000 0x03 /* MIPS R6000 CPU ISA II */ +#define MIPS_R4000 0x04 /* MIPS R4000/4400 CPU ISA III */ +#define MIPS_R3LSI 0x05 /* LSI Logic R3000 derivate ISA I */ +#define MIPS_R6000A 0x06 /* MIPS R6000A CPU ISA II */ +#define MIPS_CN50XX 0x06 /* Cavium OCTEON CN50xx MIPS64R2*/ +#define MIPS_R3IDT 0x07 /* IDT R3000 derivate ISA I */ +#define MIPS_R10000 0x09 /* MIPS R10000/T5 CPU ISA IV */ +#define MIPS_R4200 0x0a /* MIPS R4200 CPU (ICE) ISA III */ +#define MIPS_R4300 0x0b /* NEC VR4300 CPU ISA III */ +#define MIPS_R4100 0x0c /* NEC VR41xx CPU MIPS-16 ISA III */ +#define MIPS_R12000 0x0e /* MIPS R12000 ISA IV */ +#define MIPS_R14000 0x0f /* MIPS R14000 ISA IV */ +#define MIPS_R8000 0x10 /* MIPS R8000 Blackbird/TFP ISA IV */ +#define MIPS_R4600 0x20 /* PMCS R4600 Orion ISA III */ +#define MIPS_R4700 0x21 /* PMCS R4700 Orion ISA III */ +#define MIPS_R3TOSH 0x22 /* Toshiba R3000 based CPU ISA I */ +#define MIPS_R5000 0x23 /* MIPS R5000 CPU ISA IV */ +#define MIPS_RM7000 0x27 /* PMCS RM7000 CPU ISA IV */ +#define MIPS_RM52X0 0x28 /* PMCS RM52X0 CPU ISA IV */ +#define MIPS_RM9000 0x34 /* PMCS RM9000 CPU ISA IV */ +#define MIPS_LOONGSON 0x42 /* STC LoongSon CPU ISA III */ +#define MIPS_VR5400 0x54 /* NEC Vr5400 CPU ISA IV+ */ +#define MIPS_LOONGSON2 0x63 /* STC LoongSon2/3 CPU ISA III+ */ +#define MIPS_CN63XX 0x90 /* Cavium OCTEON II CN6[23]xx MIPS64R2 */ +#define MIPS_CN68XX 0x91 /* Cavium OCTEON II CN68xx MIPS64R2 */ +#define MIPS_CN66XX 0x92 /* Cavium OCTEON II CN66xx MIPS64R2 */ +#define MIPS_CN61XX 0x93 /* Cavium OCTEON II CN6[01]xx MIPS64R2 */ +#define MIPS_CN78XX 0x95 /* Cavium OCTEON III CN7[678]xx MIPS64R2 */ +#define MIPS_CN71XX 0x96 /* Cavium OCTEON III CN7[01]xx MIPS64R2 */ +#define MIPS_CN73XX 0x97 /* Cavium OCTEON III CN7[23]xx MIPS64R2 */ + +/* + * MIPS FPU types. Only soft, rest is the same as cpu type. + */ +#define MIPS_SOFT 0x00 /* Software emulation ISA I */ + + +#if defined(_KERNEL) && !defined(_LOCORE) + +extern register_t protosr; +extern int cpu_has_synced_cp0_count; +extern int cpu_has_userlocal; + +#ifdef FPUEMUL +#define CPU_HAS_FPU(ci) ((ci)->ci_hw.c1prid != 0) +#else +#define CPU_HAS_FPU(ci) 1 +#endif + +struct exec_package; +struct user; + +void tlb_asid_wrap(struct cpu_info *); +void tlb_flush(int); +void tlb_flush_addr(vaddr_t); +void tlb_init(unsigned int); +void tlb_set_page_mask(uint32_t); +void tlb_set_pid(u_int); +void tlb_set_wired(uint32_t); +int tlb_update(vaddr_t, register_t); + +void build_trampoline(vaddr_t, vaddr_t); +void cpu_switchto_asm(struct proc *, struct proc *); +int exec_md_map(struct proc *, struct exec_package *); +void savectx(struct user *, int); + +int copyinsn(struct proc *, vaddr_t, uint32_t *); +void enable_fpu(struct proc *); +void save_fpu(void); +int fpe_branch_emulate(struct proc *, struct trapframe *, uint32_t, + vaddr_t); +void MipsSaveCurFPState(struct proc *); +void MipsSaveCurFPState16(struct proc *); +void MipsSwitchFPState(struct proc *, struct trapframe *); +void MipsSwitchFPState16(struct proc *, struct trapframe *); + +void MipsFPTrap(struct trapframe *); +register_t MipsEmulateBranch(struct trapframe *, vaddr_t, uint32_t, uint32_t); + +int classify_insn(uint32_t); +#define INSNCLASS_NEUTRAL 0 +#define INSNCLASS_CALL 1 +#define INSNCLASS_BRANCH 2 + +/* + * Low level access routines to CPU registers + */ + +void setsoftintr0(void); +void clearsoftintr0(void); +void setsoftintr1(void); +void clearsoftintr1(void); +register_t enableintr(void); +register_t disableintr(void); +register_t getsr(void); +register_t setsr(register_t); + +uint32_t cp0_get_cause(void); +u_int cp0_get_count(void); +register_t cp0_get_config(void); +uint32_t cp0_get_config_1(void); +uint32_t cp0_get_config_2(void); +uint32_t cp0_get_config_3(void); +uint32_t cp0_get_config_4(void); +uint32_t cp0_get_pagegrain(void); +register_t cp0_get_prid(void); +void cp0_reset_cause(register_t); +void cp0_set_compare(u_int); +void cp0_set_config(register_t); +void cp0_set_pagegrain(uint32_t); +void cp0_set_trapbase(register_t); +u_int cp1_get_prid(void); + +static inline uint32_t +cp0_get_hwrena(void) +{ + uint32_t value; + __asm__ volatile ("mfc0 %0, $7" : "=r" (value)); + return value; +} + +static inline void +cp0_set_hwrena(uint32_t value) +{ + __asm__ volatile ("mtc0 %0, $7" : : "r" (value)); +} + +static inline void +cp0_set_userlocal(void *value) +{ + __asm__ volatile ( + " .set push\n" + " .set mips64r2\n" + " dmtc0 %0, $4, 2\n" + " .set pop\n" + : : "r" (value)); +} + +static inline u_long +intr_disable(void) +{ + return disableintr(); +} + +static inline void +intr_restore(u_long sr) +{ + setsr(sr); +} + +/* + * Cache routines (may be overridden) + */ + +#ifndef Mips_SyncCache +#define Mips_SyncCache(ci) \ + ((ci)->ci_SyncCache)(ci) +#endif +#ifndef Mips_InvalidateICache +#define Mips_InvalidateICache(ci, va, l) \ + ((ci)->ci_InvalidateICache)(ci, va, l) +#endif +#ifndef Mips_InvalidateICachePage +#define Mips_InvalidateICachePage(ci, va) \ + ((ci)->ci_InvalidateICachePage)(ci, va) +#endif +#ifndef Mips_SyncICache +#define Mips_SyncICache(ci) \ + ((ci)->ci_SyncICache)(ci) +#endif +#ifndef Mips_SyncDCachePage +#define Mips_SyncDCachePage(ci, va, pa) \ + ((ci)->ci_SyncDCachePage)(ci, va, pa) +#endif +#ifndef Mips_HitSyncDCachePage +#define Mips_HitSyncDCachePage(ci, va, pa) \ + ((ci)->ci_HitSyncDCachePage)(ci, va, pa) +#endif +#ifndef Mips_HitSyncDCache +#define Mips_HitSyncDCache(ci, va, l) \ + ((ci)->ci_HitSyncDCache)(ci, va, l) +#endif +#ifndef Mips_HitInvalidateDCache +#define Mips_HitInvalidateDCache(ci, va, l) \ + ((ci)->ci_HitInvalidateDCache)(ci, va, l) +#endif +#ifndef Mips_IOSyncDCache +#define Mips_IOSyncDCache(ci, va, l, h) \ + ((ci)->ci_IOSyncDCache)(ci, va, l, h) +#endif + +#endif /* _KERNEL && !_LOCORE */ +#endif /* !_MIPS64_CPU_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/cpustate.h b/lib/libc/include/generic-openbsd/mips64/cpustate.h new file mode 100644 index 0000000000..a6ad1d3676 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/cpustate.h @@ -0,0 +1,150 @@ +/* $OpenBSD: cpustate.h,v 1.11 2015/09/27 18:17:08 miod Exp $ */ + +/* + * Copyright (c) 2002-2003 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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. + * + */ + +#define KERN_REG_SIZE (NUMSAVEREGS * REGSZ) +#define KERN_EXC_FRAME_SIZE (CF_SZ + KERN_REG_SIZE + 16) + +#define SAVE_REG(reg, offs, base, bo) \ + REG_S reg, bo + (REGSZ * offs) (base) + +#define RESTORE_REG(reg, offs, base, bo) \ + REG_L reg, bo + (REGSZ * offs) (base) + +/* + * This macro saves the 'scratch' cpu state on stack. + * Macros are generic so no 'special' instructions! + * a0 will have a pointer to the 'frame' on return. + * a1 will have saved STATUS_REG on return. + * a3 will have the exception pc on 'return'. + * No traps, no interrupts if frame = k1 or k0! + * Temp regs are saved with their register number so + * branch emulation etc works properly. + */ +#define SAVE_CPU(frame, bo) \ + SAVE_REG(AT, AST, frame, bo) ;\ + SAVE_REG(v0, V0, frame, bo) ;\ + SAVE_REG(v1, V1, frame, bo) ;\ + SAVE_REG(a0, A0, frame, bo) ;\ + SAVE_REG(a1, A1, frame, bo) ;\ + SAVE_REG(a2, A2, frame, bo) ;\ + SAVE_REG(a3, A3, frame, bo) ;\ + MFC0 a0, COP_0_CAUSE_REG ;\ + MFC0_HAZARD ;\ + SAVE_REG(a4, A4, frame, bo) ;\ + SAVE_REG(a5, A5, frame, bo) ;\ + MFC0 a1, COP_0_STATUS_REG ;\ + MFC0_HAZARD ;\ + SAVE_REG(a6, A6, frame, bo) ;\ + SAVE_REG(a7, A7, frame, bo) ;\ + PRE_MFC0_ADDR_HAZARD ;\ + DMFC0 a2, COP_0_BAD_VADDR ;\ + MFC0_HAZARD ;\ + SAVE_REG(t0, T0, frame, bo) ;\ + SAVE_REG(t1, T1, frame, bo) ;\ + DMFC0 a3, COP_0_EXC_PC ;\ + MFC0_HAZARD ;\ + SAVE_REG(t2, T2, frame, bo) ;\ + SAVE_REG(t3, T3, frame, bo) ;\ + SAVE_REG(t8, T8, frame, bo) ;\ + SAVE_REG(t9, T9, frame, bo) ;\ + SAVE_REG(gp, GP, frame, bo) ;\ + SAVE_REG(ra, RA, frame, bo) ;\ + mflo v0 ;\ + mfhi v1 ;\ + SAVE_REG(v0, MULLO, frame, bo) ;\ + SAVE_REG(v1, MULHI, frame, bo) ;\ + SAVE_REG(a0, CAUSE, frame, bo) ;\ + SAVE_REG(a1, SR, frame, bo) ;\ + SAVE_REG(a2, BADVADDR, frame, bo) ;\ + SAVE_REG(a3, PC, frame, bo) ;\ + SAVE_REG(sp, SP, frame, bo) ;\ + PTR_ADDU a0, frame, bo ;\ + GET_CPU_INFO(v0, v1) ;\ + lw a2, CI_IPL(v0) ;\ + SAVE_REG(a2, CPL, frame, bo) + +/* + * Save 'callee save' registers in frame to aid DDB. + */ +#define SAVE_CPU_SREG(frame, bo) \ + SAVE_REG(s0, S0, frame, bo) ;\ + SAVE_REG(s1, S1, frame, bo) ;\ + SAVE_REG(s2, S2, frame, bo) ;\ + SAVE_REG(s3, S3, frame, bo) ;\ + SAVE_REG(s4, S4, frame, bo) ;\ + SAVE_REG(s5, S5, frame, bo) ;\ + SAVE_REG(s6, S6, frame, bo) ;\ + SAVE_REG(s7, S7, frame, bo) ;\ + SAVE_REG(s8, S8, frame, bo) + +/* + * Restore cpu state. When called a0 = EXC_PC. + */ +#define RESTORE_CPU(frame, bo) \ + RESTORE_REG(t1, SR, frame, bo) ;\ + RESTORE_REG(t2, MULLO, frame, bo) ;\ + RESTORE_REG(t3, MULHI, frame, bo) ;\ + MTC0 t1, COP_0_STATUS_REG ;\ + MTC0_SR_IE_HAZARD ;\ + mtlo t2 ;\ + mthi t3 ;\ + DMTC0 a0, COP_0_EXC_PC ;\ + MTC0_HAZARD ;\ + RESTORE_REG(AT, AST, frame, bo) ;\ + RESTORE_REG(v0, V0, frame, bo) ;\ + RESTORE_REG(v1, V1, frame, bo) ;\ + RESTORE_REG(a0, A0, frame, bo) ;\ + RESTORE_REG(a1, A1, frame, bo) ;\ + RESTORE_REG(a2, A2, frame, bo) ;\ + RESTORE_REG(a3, A3, frame, bo) ;\ + RESTORE_REG(a4, A4, frame, bo) ;\ + RESTORE_REG(a5, A5, frame, bo) ;\ + RESTORE_REG(a6, A6, frame, bo) ;\ + RESTORE_REG(a7, A7, frame, bo) ;\ + RESTORE_REG(t0, T0, frame, bo) ;\ + RESTORE_REG(t1, T1, frame, bo) ;\ + RESTORE_REG(t2, T2, frame, bo) ;\ + RESTORE_REG(t3, T3, frame, bo) ;\ + RESTORE_REG(t8, T8, frame, bo) ;\ + RESTORE_REG(t9, T9, frame, bo) ;\ + RESTORE_REG(gp, GP, frame, bo) ;\ + RESTORE_REG(ra, RA, frame, bo) + +/* + * Restore 'callee save' registers + */ +#define RESTORE_CPU_SREG(frame, bo) \ + RESTORE_REG(s0, S0, frame, bo) ;\ + RESTORE_REG(s1, S1, frame, bo) ;\ + RESTORE_REG(s2, S2, frame, bo) ;\ + RESTORE_REG(s3, S3, frame, bo) ;\ + RESTORE_REG(s4, S4, frame, bo) ;\ + RESTORE_REG(s5, S5, frame, bo) ;\ + RESTORE_REG(s6, S6, frame, bo) ;\ + RESTORE_REG(s7, S7, frame, bo) ;\ + RESTORE_REG(s8, S8, frame, bo) \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/db_machdep.h b/lib/libc/include/generic-openbsd/mips64/db_machdep.h new file mode 100644 index 0000000000..7dec17ccc2 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/db_machdep.h @@ -0,0 +1,76 @@ +/* $OpenBSD: db_machdep.h,v 1.21 2021/08/30 08:11:12 jasper Exp $ */ + +/* + * Copyright (c) 1998-2003 Opsycon AB (www.opsycon.se) + * + * 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 _MIPS64_DB_MACHDEP_H_ +#define _MIPS64_DB_MACHDEP_H_ + +#include +#include +#include + +#define DB_MACHINE_COMMANDS /* We have machine specific commands */ + +typedef struct trapframe db_regs_t; +extern db_regs_t ddb_regs; + +typedef long db_expr_t; + +#define SOFTWARE_SSTEP /* Need software single step */ +#define SOFTWARE_SSTEP_EMUL /* next_instr_address() emulates 100% */ +vaddr_t next_instr_address(vaddr_t, int); +#define BKPT_SIZE (4) +#define BKPT_SET(ins) (BREAK_DDB) +#define DB_VALID_BREAKPOINT(addr) (((addr) & 3) == 0) + +#define IS_BREAKPOINT_TRAP(type, code) ((type) == T_BREAK) +#define IS_WATCHPOINT_TRAP(type, code) (0) /* XXX mips3 watchpoint */ + +#define PC_REGS(regs) ((vaddr_t)(regs)->pc) +#define SET_PC_REGS(regs, value) (regs)->pc = (register_t)(value) + +/* + * Test of instructions to see class. + */ +#define inst_branch(i) (classify_insn(i) == INSNCLASS_BRANCH) +#define inst_trap_return(i) ((i) & 0) +#define inst_call(i) (classify_insn(i) == INSNCLASS_CALL) +#define inst_return(i) ((i) == 0x03e00008) + +void db_machine_init(void); + +int db_enter_ddb(void); +void db_startcpu(int); +void db_stopcpu(int); + +int dbmd_print_insn(uint32_t, vaddr_t, int (*)(const char *, ...)); + +#define DDB_STATE_NOT_RUNNING 0 +#define DDB_STATE_RUNNING 1 +#define DDB_STATE_EXITING 2 + +#endif /* !_MIPS64_DB_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/elf.h b/lib/libc/include/generic-openbsd/mips64/elf.h new file mode 100644 index 0000000000..1cd8fda26a --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/elf.h @@ -0,0 +1,7 @@ +/* $OpenBSD: elf.h,v 1.1 2024/07/14 09:48:48 jca Exp $ */ + +/* + * This file is in the public domain. + */ + +/* Nothing for now */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/endian.h b/lib/libc/include/generic-openbsd/mips64/endian.h new file mode 100644 index 0000000000..178466dc55 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/endian.h @@ -0,0 +1,49 @@ +/* $OpenBSD: endian.h,v 1.9 2014/07/12 16:25:08 guenther Exp $ */ + +/* + * Copyright (c) 2001-2002 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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 _MIPS64_ENDIAN_H_ +#define _MIPS64_ENDIAN_H_ + +#if defined(__MIPSEL__) +#define _BYTE_ORDER _LITTLE_ENDIAN +#endif +#if defined(__MIPSEB__) +#define _BYTE_ORDER _BIG_ENDIAN +#endif + +#if !defined(_BYTE_ORDER) +#error "__MIPSEL__ or __MIPSEB__ must be defined to define BYTE_ORDER!!!" +#endif + +#define __STRICT_ALIGNMENT + +#ifndef __FROM_SYS__ENDIAN +#include +#endif + +#endif /* _MIPS64_ENDIAN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/exec.h b/lib/libc/include/generic-openbsd/mips64/exec.h new file mode 100644 index 0000000000..f946e5fc68 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/exec.h @@ -0,0 +1,137 @@ +/* $OpenBSD: exec.h,v 1.10 2022/10/28 15:07:25 kettenis Exp $ */ + +/* + * Copyright (c) 1996-2004 Per Fogelstrom, Opsycon AB + * + * 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 _MIPS64_EXEC_H_ +#define _MIPS64_EXEC_H_ + +#define __LDPGSZ 16384 + +#define ARCH_ELFSIZE 64 +#define ELF_TARG_CLASS ELFCLASS64 + +#if defined(__MIPSEB__) +#define ELF_TARG_DATA ELFDATA2MSB +#else +#define ELF_TARG_DATA ELFDATA2LSB +#endif +#define ELF_TARG_MACH EM_MIPS + +/* Information taken from MIPS ABI supplement */ + +/* Architecture dependent Segment types - p_type */ +#define PT_MIPS_REGINFO 0x70000000 /* Register usage information */ + +/* Architecture dependent d_tag field for Elf32_Dyn. */ +#define DT_MIPS_RLD_VERSION 0x70000001 /* Runtime Linker Interface ID */ +#define DT_MIPS_TIME_STAMP 0x70000002 /* Timestamp */ +#define DT_MIPS_ICHECKSUM 0x70000003 /* Cksum of ext. str. and com. sizes */ +#define DT_MIPS_IVERSION 0x70000004 /* Version string (string tbl index) */ +#define DT_MIPS_FLAGS 0x70000005 /* Flags */ +#define DT_MIPS_BASE_ADDRESS 0x70000006 /* Segment base address */ +#define DT_MIPS_CONFLICT 0x70000008 /* Adr of .conflict section */ +#define DT_MIPS_LIBLIST 0x70000009 /* Address of .liblist section */ +#define DT_MIPS_LOCAL_GOTNO 0x7000000a /* Number of local .GOT entries */ +#define DT_MIPS_CONFLICTNO 0x7000000b /* Number of .conflict entries */ +#define DT_MIPS_LIBLISTNO 0x70000010 /* Number of .liblist entries */ +#define DT_MIPS_SYMTABNO 0x70000011 /* Number of .dynsym entries */ +#define DT_MIPS_UNREFEXTNO 0x70000012 /* First external DYNSYM */ +#define DT_MIPS_GOTSYM 0x70000013 /* First GOT entry in .dynsym */ +#define DT_MIPS_HIPAGENO 0x70000014 /* Number of GOT page table entries */ +#define DT_MIPS_RLD_MAP 0x70000016 /* Address of debug map pointer */ +#define DT_MIPS_RLD_MAP_REL 0x70000035 /* Relative address of debug map ptr */ + +#define DT_PROCNUM (DT_MIPS_RLD_MAP_REL - DT_LOPROC + 1) + +/* + * Legal values for e_flags field of Elf32_Ehdr. + */ +#define EF_MIPS_NOREORDER 0x00000001 /* .noreorder was used */ +#define EF_MIPS_PIC 0x00000002 /* Contains PIC code */ +#define EF_MIPS_CPIC 0x00000004 /* Uses PIC calling sequence */ +#define EF_MIPS_ABI2 0x00000020 /* -n32 on Irix 6 */ +#define EF_MIPS_32BITMODE 0x00000100 /* 64 bit in 32 bit mode... */ +#define EF_MIPS_ARCH 0xf0000000 /* MIPS architecture level */ +#define E_MIPS_ARCH_1 0x00000000 +#define E_MIPS_ARCH_2 0x10000000 +#define E_MIPS_ARCH_3 0x20000000 +#define E_MIPS_ARCH_4 0x30000000 +#define EF_MIPS_ABI 0x0000f000 /* ABI level */ +#define E_MIPS_ABI_NONE 0x00000000 /* ABI level not set */ +#define E_MIPS_ABI_O32 0x00001000 +#define E_MIPS_ABI_O64 0x00002000 +#define E_MIPS_ABI_EABI32 0x00004000 +#define E_MIPS_ABI_EABI64 0x00004000 + +/* + * Mips special sections. + */ +#define SHN_MIPS_ACOMMON 0xff00 /* Allocated common symbols */ +#define SHN_MIPS_SCOMMON 0xff03 /* Small common symbols */ +#define SHN_MIPS_SUNDEFINED 0xff04 /* Small undefined symbols */ + +/* + * Legal values for sh_type field of Elf32_Shdr. + */ +#define SHT_MIPS_LIBLIST 0x70000000 /* Shared objects used in link */ +#define SHT_MIPS_CONFLICT 0x70000002 /* Conflicting symbols */ +#define SHT_MIPS_GPTAB 0x70000003 /* Global data area sizes */ +#define SHT_MIPS_UCODE 0x70000004 /* Reserved for SGI/MIPS compilers */ +#define SHT_MIPS_DEBUG 0x70000005 /* MIPS ECOFF debugging information */ +#define SHT_MIPS_REGINFO 0x70000006 /* Register usage information */ + +/* + * Legal values for sh_flags field of Elf32_Shdr. + */ +#define SHF_MIPS_GPREL 0x10000000 /* Must be part of global data area */ + +#if 0 +/* + * Entries found in sections of type SHT_MIPS_GPTAB. + */ +typedef union { + struct { + Elf32_Word gt_current_g_value; /* -G val used in compilation */ + Elf32_Word gt_unused; /* Not used */ + } gt_header; /* First entry in section */ + struct { + Elf32_Word gt_g_value; /* If this val were used for -G */ + Elf32_Word gt_bytes; /* This many bytes would be used */ + } gt_entry; /* Subsequent entries in section */ +} Elf32_gptab; + +/* + * Entry found in sections of type SHT_MIPS_REGINFO. + */ +typedef struct { + Elf32_Word ri_gprmask; /* General registers used */ + Elf32_Word ri_cprmask[4]; /* Coprocessor registers used */ + Elf32_Sword ri_gp_value; /* $gp register value */ +} Elf32_RegInfo; +#endif + +#endif /* !_MIPS64_EXEC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/fenv.h b/lib/libc/include/generic-openbsd/mips64/fenv.h new file mode 100644 index 0000000000..6059d90066 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/fenv.h @@ -0,0 +1,94 @@ +/* $OpenBSD: fenv.h,v 1.3 2011/05/25 21:46:49 martynas Exp $ */ + +/* + * Copyright (c) 2011 Martynas Venckus + * + * 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 _MIPS64_FENV_H_ +#define _MIPS64_FENV_H_ + +/* + * Each symbol representing a floating point exception expands to an integer + * constant expression with values, such that bitwise-inclusive ORs of _all + * combinations_ of the constants result in distinct values. + * + * We use such values that allow direct bitwise operations on FPU registers. + */ +#define FE_INEXACT 0x04 +#define FE_UNDERFLOW 0x08 +#define FE_OVERFLOW 0x10 +#define FE_DIVBYZERO 0x20 +#define FE_INVALID 0x40 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * exception constants defined above. + */ +#define FE_ALL_EXCEPT (FE_INEXACT | FE_UNDERFLOW | FE_OVERFLOW | \ + FE_DIVBYZERO | FE_INVALID) +#define _MASK_SHIFT 5 + +/* + * Each symbol representing the rounding direction, expands to an integer + * constant expression whose value is distinct non-negative value. + * + * We use such values that allow direct bitwise operations on FPU registers. + */ +#define FE_TONEAREST 0x0 +#define FE_TOWARDZERO 0x1 +#define FE_UPWARD 0x2 +#define FE_DOWNWARD 0x3 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * rounding direction constants defined above. + */ +#define _ROUND_MASK (FE_TONEAREST | FE_TOWARDZERO | FE_UPWARD | \ + FE_DOWNWARD) + +/* + * fenv_t represents the entire floating-point environment. + */ +typedef unsigned int fenv_t; + +/* + * The following constant represents the default floating-point environment + * (that is, the one installed at program startup) and has type pointer to + * const-qualified fenv_t. + * + * It can be used as an argument to the functions within the header + * that manage the floating-point environment, namely fesetenv() and + * feupdateenv(). + */ +__BEGIN_DECLS +extern fenv_t __fe_dfl_env; +__END_DECLS +#define FE_DFL_ENV ((const fenv_t *)&__fe_dfl_env) + +/* + * fexcept_t represents the floating-point status flags collectively, including + * any status the implementation associates with the flags. + * + * A floating-point status flag is a system variable whose value is set (but + * never cleared) when a floating-point exception is raised, which occurs as a + * side effect of exceptional floating-point arithmetic to provide auxiliary + * information. + * + * A floating-point control mode is a system variable whose value may be set by + * the user to affect the subsequent behavior of floating-point arithmetic. + */ +typedef unsigned int fexcept_t; + +#endif /* !_MIPS64_FENV_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/fpu.h b/lib/libc/include/generic-openbsd/mips64/fpu.h new file mode 100644 index 0000000000..d670aed7bd --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/fpu.h @@ -0,0 +1,73 @@ +/* $OpenBSD: fpu.h,v 1.2 2012/12/04 05:00:40 deraadt Exp $ */ + +/* + * Copyright (c) 2010 Miodrag Vallat. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * Layout of the floating-point control/status register (FCR31) + */ + +/* flush denormalized results to zero instead of causing FPCSR_C_E */ +#define FPCSR_FS 0x01000000 + +/* compare condition bits: one bit for MIPS I/II/III, eight bits for MIPS IV */ +#define FPCSR_CONDBIT(c) ((c) == 0 ? 23 : 24 + (c)) +#define FPCSR_CONDVAL(c) (1U << FPCSR_CONDBIT(c)) + +/* cause bits */ +#define FPCSR_C_E 0x00020000 /* unimplemented operation */ +#define FPCSR_C_V 0x00010000 /* invalid operation */ +#define FPCSR_C_Z 0x00008000 /* division by zero */ +#define FPCSR_C_O 0x00004000 /* overflow */ +#define FPCSR_C_U 0x00002000 /* underflow */ +#define FPCSR_C_I 0x00001000 /* inexact */ + +/* enable bits */ +#define FPCSR_E_V 0x00000800 /* invalid operation */ +#define FPCSR_E_Z 0x00000400 /* division by zero */ +#define FPCSR_E_O 0x00000200 /* overflow */ +#define FPCSR_E_U 0x00000100 /* underflow */ +#define FPCSR_E_I 0x00000080 /* inexact */ + +/* flags bits */ +#define FPCSR_F_V 0x00000040 /* invalid operation */ +#define FPCSR_F_Z 0x00000020 /* division by zero */ +#define FPCSR_F_O 0x00000010 /* overflow */ +#define FPCSR_F_U 0x00000008 /* underflow */ +#define FPCSR_F_I 0x00000004 /* inexact */ + +#define FPCSR_C_MASK 0x0003f000 +#define FPCSR_C_SHIFT 12 +#define FPCSR_E_MASK 0x00000f80 +#define FPCSR_E_SHIFT 7 +#define FPCSR_F_MASK 0x0000007c +#define FPCSR_F_SHIFT 2 +#define FPCSR_RM_MASK 0x00000003 /* rounding mode */ + +#ifndef _KERNEL + +/* + * IRIX-compatible interfaces allowing userland to control the state + * of the floating-point control/status register. These are intended + * to let userland control the state of the FS bit. + */ +#include + +__BEGIN_DECLS +int get_fpc_csr(void); +int set_fpc_csr(int); +__END_DECLS +#endif /* _KERNEL */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/frame.h b/lib/libc/include/generic-openbsd/mips64/frame.h new file mode 100644 index 0000000000..233e911c36 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/frame.h @@ -0,0 +1,114 @@ +/* $OpenBSD: frame.h,v 1.8 2021/04/29 12:49:19 visa Exp $ */ + +/* + * Copyright (c) 1998-2003 Opsycon AB (www.opsycon.se) + * + * 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 _MIPS64_FRAME_H_ +#define _MIPS64_FRAME_H_ + +/* + * The layout of this *must* match with regnum.h or bad things + * will happen. libc setjmp/longjmp depends on this as well. + */ +struct trapframe { + register_t zero; + register_t ast; + register_t v0; + register_t v1; + register_t a0; + register_t a1; + register_t a2; + register_t a3; + register_t a4; /* ta0 */ + register_t a5; /* ta1 */ + register_t a6; /* ta2 */ + register_t a7; /* ta3 */ + register_t t0; + register_t t1; + register_t t2; + register_t t3; + register_t s0; + register_t s1; + register_t s2; + register_t s3; + register_t s4; + register_t s5; + register_t s6; + register_t s7; + register_t t8; + register_t t9; + register_t k0; + register_t k1; + register_t gp; + register_t sp; + register_t s8; + register_t ra; + register_t sr; + register_t mullo; + register_t mulhi; + register_t badvaddr; + register_t cause; + register_t pc; + register_t ic; /* unused, was RM7000 ICR */ + register_t ipl; + +/* From here and on, only saved user processes. */ + + f_register_t f0; + f_register_t f1; + f_register_t f2; + f_register_t f3; + f_register_t f4; + f_register_t f5; + f_register_t f6; + f_register_t f7; + f_register_t f8; + f_register_t f9; + f_register_t f10; + f_register_t f11; + f_register_t f12; + f_register_t f13; + f_register_t f14; + f_register_t f15; + f_register_t f16; + f_register_t f17; + f_register_t f18; + f_register_t f19; + f_register_t f20; + f_register_t f21; + f_register_t f22; + f_register_t f23; + f_register_t f24; + f_register_t f25; + f_register_t f26; + f_register_t f27; + f_register_t f28; + f_register_t f29; + f_register_t f30; + f_register_t f31; + register_t fsr; +}; + +#endif /* !_MIPS64_FRAME_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/ieee.h b/lib/libc/include/generic-openbsd/mips64/ieee.h new file mode 100644 index 0000000000..d96b3479fb --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/ieee.h @@ -0,0 +1,169 @@ +/* $OpenBSD: ieee.h,v 1.4 2010/01/23 19:11:21 miod Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)ieee.h 8.1 (Berkeley) 6/11/93 + */ + +/* + * ieee.h defines the machine-dependent layout of the machine's IEEE + * floating point. It does *not* define (yet?) any of the rounding + * mode bits, exceptions, and so forth. + */ + +/* + * Define the number of bits in each fraction and exponent. + * + * k k+1 + * Note that 1.0 x 2 == 0.1 x 2 and that denorms are represented + * + * (-exp_bias+1) + * as fractions that look like 0.fffff x 2 . This means that + * + * -126 + * the number 0.10000 x 2 , for instance, is the same as the normalized + * + * -127 -128 + * float 1.0 x 2 . Thus, to represent 2 , we need one leading zero + * + * -129 + * in the fraction; to represent 2 , we need two, and so on. This + * + * (-exp_bias-fracbits+1) + * implies that the smallest denormalized number is 2 + * + * for whichever format we are talking about: for single precision, for + * + * -126 -149 + * instance, we get .00000000000000000000001 x 2 , or 1.0 x 2 , and + * + * -149 == -127 - 23 + 1. + */ +#define SNG_EXPBITS 8 +#define SNG_FRACBITS 23 + +#define DBL_EXPBITS 11 +#define DBL_FRACHBITS 20 +#define DBL_FRACLBITS 32 +#define DBL_FRACBITS 52 + +#define EXT_EXPBITS 15 +#define EXT_FRACHBITS 16 +#define EXT_FRACHMBITS 32 +#define EXT_FRACLMBITS 32 +#define EXT_FRACLBITS 32 +#define EXT_FRACBITS 112 + +#define EXT_IMPLICIT_NBIT + +#define EXT_TO_ARRAY32(p, a) do { \ + (a)[0] = (uint32_t)(p)->ext_fracl; \ + (a)[1] = (uint32_t)(p)->ext_fraclm; \ + (a)[2] = (uint32_t)(p)->ext_frachm; \ + (a)[3] = (uint32_t)(p)->ext_frach; \ +} while(0) + +struct ieee_single { +#ifdef __MIPSEB__ + u_int sng_sign:1; + u_int sng_exp:8; + u_int sng_frac:23; +#else + u_int sng_frac:23; + u_int sng_exp:8; + u_int sng_sign:1; +#endif +}; + +struct ieee_double { +#ifdef __MIPSEB__ + u_int dbl_sign:1; + u_int dbl_exp:11; + u_int dbl_frach:20; + u_int dbl_fracl; +#else + u_int dbl_fracl; + u_int dbl_frach:20; + u_int dbl_exp:11; + u_int dbl_sign:1; +#endif +}; + +struct ieee_ext { +#ifdef __MIPSEB__ + u_int ext_sign:1; + u_int ext_exp:15; + u_int ext_frach:16; + u_int ext_frachm; + u_int ext_fraclm; + u_int ext_fracl; +#else + u_int ext_fracl; + u_int ext_fraclm; + u_int ext_frachm; + u_int ext_frach:16; + u_int ext_exp:15; + u_int ext_sign:1; +#endif +}; + +/* + * Floats whose exponent is in [1..INFNAN) (of whatever type) are + * `normal'. Floats whose exponent is INFNAN are either Inf or NaN. + * Floats whose exponent is zero are either zero (iff all fraction + * bits are zero) or subnormal values. + * + * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its + * high fraction; if the bit is set, it is a `quiet NaN'. + */ +#define SNG_EXP_INFNAN 255 +#define DBL_EXP_INFNAN 2047 +#define EXT_EXP_INFNAN 32767 + +#if 0 +#define SNG_QUIETNAN (1 << 22) +#define DBL_QUIETNAN (1 << 19) +#define EXT_QUIETNAN (1 << 15) +#endif + +/* + * Exponent biases. + */ +#define SNG_EXP_BIAS 127 +#define DBL_EXP_BIAS 1023 +#define EXT_EXP_BIAS 16383 \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/ieeefp.h b/lib/libc/include/generic-openbsd/mips64/ieeefp.h new file mode 100644 index 0000000000..e3521f45cd --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/ieeefp.h @@ -0,0 +1,46 @@ +/* $OpenBSD: ieeefp.h,v 1.4 2011/03/23 16:54:36 pirofti Exp $ */ + +/* + * Written by J.T. Conklin, Apr 11, 1995 + * Public domain. + */ + +#ifndef _MIPS64_IEEEFP_H_ +#define _MIPS64_IEEEFP_H_ + +typedef int fp_except; +#define FP_X_IMP 0x01 /* imprecise (loss of precision) */ +#define FP_X_UFL 0x02 /* underflow exception */ +#define FP_X_OFL 0x04 /* overflow exception */ +#define FP_X_DZ 0x08 /* divide-by-zero exception */ +#define FP_X_INV 0x10 /* invalid operation exception */ + +typedef enum { + FP_RN=0, /* round to nearest representable number */ + FP_RZ=1, /* round to zero (truncate) */ + FP_RP=2, /* round toward positive infinity */ + FP_RM=3 /* round toward negative infinity */ +} fp_rnd; + +#ifdef _KERNEL + +/* + * Defines for the floating-point completion/emulation code. + */ + +#include +#include +#include +#include + +#define float_raise(bits) \ + do { curproc->p_md.md_regs->fsr |= (bits) << FPCSR_C_SHIFT; } while (0) +#define float_set_inexact() float_raise(FP_X_IMP) +#define float_set_invalid() float_raise(FP_X_INV) + +#define float_get_round(csr) (csr & FPCSR_RM_MASK) +#define fpgetround() float_get_round(curproc->p_md.md_regs->fsr) + +#endif + +#endif /* !_MIPS64_IEEEFP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/kcore.h b/lib/libc/include/generic-openbsd/mips64/kcore.h new file mode 100644 index 0000000000..5a69401214 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/kcore.h @@ -0,0 +1,40 @@ +/* $OpenBSD: kcore.h,v 1.3 2023/01/04 10:59:34 jsg Exp $ */ +/* $NetBSD: kcore.h,v 1.1 1996/03/10 21:55:18 leo Exp $ */ + +/* + * Copyright (c) 1996 Leo Weppelman. + * 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 _MIPS64_KCORE_H_ +#define _MIPS64_KCORE_H_ + +#define NPHYS_RAM_SEGS 8 + +typedef struct cpu_kcore_hdr { + paddr_t kernel_pa; /* Phys. address of kernel VA 0 */ + int mmutype; + phys_ram_seg_t ram_segs[NPHYS_RAM_SEGS]; +} cpu_kcore_hdr_t; + +#endif /* !_MIPS64_KCORE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/limits.h b/lib/libc/include/generic-openbsd/mips64/limits.h new file mode 100644 index 0000000000..398deda852 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/limits.h @@ -0,0 +1,53 @@ +/* $OpenBSD: limits.h,v 1.8 2015/04/30 13:42:08 millert Exp $ */ + +/* + * Copyright (c) 1988, 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. + * + * @(#)limits.h 8.3 (Berkeley) 1/4/94 + */ + +#ifndef _MIPS64_LIMITS_H_ +#define _MIPS64_LIMITS_H_ + +#include + +#if __POSIX_VISIBLE || __XPG_VISIBLE +#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) */ + +/* Quads and longs are the same on mips64 */ +#define UQUAD_MAX (ULONG_MAX) /* max value for a uquad_t */ +#define QUAD_MAX (LONG_MAX) /* max value for a quad_t */ +#define QUAD_MIN (LONG_MIN) /* min value for a quad_t */ + +#endif /* __BSD_VISIBLE */ + +#endif /* !_MIPS64_LIMITS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/loongson2.h b/lib/libc/include/generic-openbsd/mips64/loongson2.h new file mode 100644 index 0000000000..ecfab55024 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/loongson2.h @@ -0,0 +1,65 @@ +/* $OpenBSD: loongson2.h,v 1.4 2013/01/16 20:28:06 miod Exp $ */ + +/* + * Copyright (c) 2009 Miodrag Vallat. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MIPS64_LOONGSON2_H_ +#define _MIPS64_LOONGSON2_H_ + +/* + * Loongson 2E/2F specific defines + */ + +/* + * Address Window registers physical addresses + * + * The Loongson 2F processor has an AXI crossbar with four possible bus + * masters, each one having four programmable address windows. + * + * Each window is defined with three 64-bit registers: + * - a base address register, defining the address in the master address + * space (base register). + * - an address mask register, defining which address bits are valid in this + * window. A given address matches a window if (addr & mask) == base. + * - the location of the window base in the target, as well at the target + * number itself (mmap register). The lower 20 bits of the address are + * forced as zeroes regardless of their value in this register. + * The translated address is thus (addr & ~mask) | (mmap & ~0xfffff). + */ + +#define LOONGSON_AWR_BASE_ADDRESS 0x3ff00000 + +#define LOONGSON_AWR_BASE(master, window) \ + (LOONGSON_AWR_BASE_ADDRESS + (window) * 0x08 + (master) * 0x60 + 0x00) +#define LOONGSON_AWR_SIZE(master, window) \ + (LOONGSON_AWR_BASE_ADDRESS + (window) * 0x08 + (master) * 0x60 + 0x20) +#define LOONGSON_AWR_MMAP(master, window) \ + (LOONGSON_AWR_BASE_ADDRESS + (window) * 0x08 + (master) * 0x60 + 0x40) + +/* + * Bits in the diagnostic register + */ + +#define COP_0_DIAG_ITLB_CLEAR 0x04 +#define COP_0_DIAG_BTB_CLEAR 0x02 +#define COP_0_DIAG_RAS_DISABLE 0x01 + +#if defined(_KERNEL) && !defined(_LOCORE) +int loongson2f_cpuspeed(int *); +void loongson2f_setperf(int); +#endif + +#endif /* _MIPS64_LOONGSON2_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/loongson3.h b/lib/libc/include/generic-openbsd/mips64/loongson3.h new file mode 100644 index 0000000000..8b8633e3a4 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/loongson3.h @@ -0,0 +1,108 @@ +/* $OpenBSD: loongson3.h,v 1.3 2017/05/10 16:04:21 visa Exp $ */ + +/* + * Copyright (c) 2016 Visa Hankala + * + * 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 _MIPS64_LOONGSON3_H_ +#define _MIPS64_LOONGSON3_H_ + +/* + * Definitions for Loongson 3A. + */ + +#define LS3_CFG_BASE(node) (0x100000004000ull*(node) + 0x3ff00000) +#define LS3_MEM_BASE(node) (0x100000000000ull*(node)) + +#define LS3_IPI_BASE(n, c) (LS3_CFG_BASE(n) + 0x1000 + 0x100*(c)) +#define LS3_IPI_ISR 0x00 +#define LS3_IPI_IMR 0x04 +#define LS3_IPI_SET 0x08 +#define LS3_IPI_CLEAR 0x0c +#define LS3_IPI_MBOX0 0x20 +#define LS3_IPI_MBOX1 0x28 +#define LS3_IPI_MBOX2 0x30 +#define LS3_IPI_MBOX3 0x38 + +static inline uint32_t +loongson3_get_cpuid(void) +{ + uint32_t tmp; + + asm volatile ( + " .set push\n" + " .set mips64\n" + " mfc0 %0, $15, 1\n" /* EBase */ + " .set pop\n" + : "=r" (tmp)); + + return tmp & 0xf; +} + +#define LS3_COREID(cpuid) ((cpuid) & 3) +#define LS3_NODEID(cpuid) ((cpuid) >> 2) + +/* + * Interrupt router registers + */ + +#define LS3_IRT_ENTRY(node, irq) (LS3_CFG_BASE(node) + 0x1400 + (irq)) +#define LS3_IRT_INTISR(node) (LS3_CFG_BASE(node) + 0x1420) +#define LS3_IRT_INTEN(node) (LS3_CFG_BASE(node) + 0x1424) +#define LS3_IRT_INTENSET(node) (LS3_CFG_BASE(node) + 0x1428) +#define LS3_IRT_INTENCLR(node) (LS3_CFG_BASE(node) + 0x142c) +#define LS3_IRT_INTISR_CORE(node, cpu) (LS3_CFG_BASE(node) + 0x1440 + (cpu)*8) + +/* sys int 0-3 */ +#define LS3_IRT_ENTRY_INT(node, x) LS3_IRT_ENTRY((node), (x)) +/* PCI int 0-3 */ +#define LS3_IRT_ENTRY_PCI(node, x) LS3_IRT_ENTRY((node), 0x04+(x)) +/* LPC int */ +#define LS3_IRT_ENTRY_LPC(node) LS3_IRT_ENTRY((node), 0x0a) +/* HT0 int 0-7 */ +#define LS3_IRT_ENTRY_HT0(node, x) LS3_IRT_ENTRY((node), 0x10+(x)) +/* HT1 int 0-7 */ +#define LS3_IRT_ENTRY_HT1(node, x) LS3_IRT_ENTRY((node), 0x18+(x)) + +#define LS3_IRT_ROUTE(core, intr) ((0x01 << (core)) | (0x10 << (intr))) + +#define LS3_IRQ_INT(x) (x) /* sys int 0-3 */ +#define LS3_IRQ_PCI(x) ((x) + 0x04) /* PCI int 0-3 */ +#define LS3_IRQ_LPC 0x0a /* LPC int */ +#define LS3_IRQ_HT0(x) ((x) + 0x10) /* HT0 int 0-7 */ +#define LS3_IRQ_HT1(x) ((x) + 0x18) /* HT1 int 0-7 */ +#define LS3_IRQ_NUM 32 + +#define LS3_IRQ_IS_HT(irq) ((irq) >= 0x10) + +#define LS3_IRQ_HT_MASK 0xffff0000u + +/* + * Number of HyperTransport interrupt vectors. In reality, each HT interface + * has 256 vectors, but the interrupt code uses only a subset of them. + */ +#define LS3_HT_IRQ_NUM 32 + +/* + * HyperTransport registers + */ + +#define LS3_HT1_MEM_BASE(n) (LS3_MEM_BASE(n)+0x00000e0000000000ull) +#define LS3_HT1_CFG_BASE(n) (LS3_MEM_BASE(n)+0x00000efdfb000000ull) + +#define LS3_HT_ISR_OFFSET(x) (0x80 + (x) * 4) +#define LS3_HT_IMR_OFFSET(x) (0xa0 + (x) * 4) + +#endif /* _MIPS64_LOONGSON3_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/memconf.h b/lib/libc/include/generic-openbsd/mips64/memconf.h new file mode 100644 index 0000000000..208a60d9c5 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/memconf.h @@ -0,0 +1,48 @@ +/* $OpenBSD: memconf.h,v 1.7 2011/05/30 22:25:21 oga Exp $ */ + +/* + * Copyright (c) 1996 Per Fogelstrom + * 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. + */ + +/* + * Memory config list used by pmap_bootstrap. + */ + +#ifndef _MIPS64_MEMCONF_H_ +#define _MIPS64_MEMCONF_H_ + +struct phys_mem_desc { + uint64_t mem_first_page; + uint64_t mem_last_page; +}; + +#ifdef _KERNEL +#ifndef MAXMEMSEGS +#define MAXMEMSEGS 16 +#endif +extern struct phys_mem_desc mem_layout[]; +int memrange_register(uint64_t, uint64_t, uint64_t); +#endif + +#endif /* !_MIPS64_MEMCONF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/mips_cpu.h b/lib/libc/include/generic-openbsd/mips64/mips_cpu.h new file mode 100644 index 0000000000..02b7f62d48 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/mips_cpu.h @@ -0,0 +1,282 @@ +/* $OpenBSD: mips_cpu.h,v 1.11 2022/12/11 05:07:25 visa 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 and Rick Macklem. + * + * 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. + * + * Copyright (C) 1989 Digital Equipment Corporation. + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby granted, + * provided that the above copyright notice appears in all copies. + * Digital Equipment Corporation makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * from: @(#)cpu.h 8.4 (Berkeley) 1/4/94 + */ + +#ifndef _MIPS64_CPUREGS_H_ +#define _MIPS64_CPUREGS_H_ + +#if defined(_KERNEL) || defined(_STANDALONE) + +/* + * Status register. + */ + +#define SR_COP_USABILITY 0x30000000 /* CP0 and CP1 only */ +#define SR_COP_0_BIT 0x10000000 +#define SR_COP_1_BIT 0x20000000 +#define SR_COP_2_BIT 0x40000000 +#define SR_RP 0x08000000 +#define SR_FR_32 0x04000000 +#define SR_RE 0x02000000 +#define SR_DSD 0x01000000 /* Only on R12000 */ +#define SR_BOOT_EXC_VEC 0x00400000 +#define SR_TLB_SHUTDOWN 0x00200000 +#define SR_SOFT_RESET 0x00100000 +#define SR_DIAG_CH 0x00040000 +#define SR_DIAG_CE 0x00020000 +#define SR_DIAG_DE 0x00010000 +#define SR_KX 0x00000080 +#define SR_SX 0x00000040 +#define SR_UX 0x00000020 +#define SR_ERL 0x00000004 +#define SR_EXL 0x00000002 +#define SR_INT_ENAB 0x00000001 + +#define SOFT_INT_MASK_0 0x00000100 +#define SOFT_INT_MASK_1 0x00000200 +#define SR_INT_MASK_0 0x00000400 +#define SR_INT_MASK_1 0x00000800 +#define SR_INT_MASK_2 0x00001000 +#define SR_INT_MASK_3 0x00002000 +#define SR_INT_MASK_4 0x00004000 +#define SR_INT_MASK_5 0x00008000 + +#define SR_XX 0x80000000 +#define SR_KSU_MASK 0x00000018 +#define SR_KSU_SUPER 0x00000008 +#define SR_KSU_KERNEL 0x00000000 +#define SR_INT_MASK 0x0000ff00 +/* SR_KSU_USER is in for CLKF_USERMODE() */ +#ifndef SR_KSU_USER +#define SR_KSU_USER 0x00000010 +#endif + +#define SOFT_INT_MASK (SOFT_INT_MASK_0 | SOFT_INT_MASK_1) + +/* + * Cause register. + */ + +#define CR_BR_DELAY 0x80000000 +#define CR_BR_DELAY_SHIFT 31 +#define CR_EXC_CODE 0x0000007c +#define CR_EXC_CODE_SHIFT 2 +#define CR_COP_ERR 0x30000000 +#define CR_COP1_ERR 0x10000000 +#define CR_COP2_ERR 0x20000000 +#define CR_COP3_ERR 0x20000000 +#define CR_INT_SOFT0 0x00000100 +#define CR_INT_SOFT1 0x00000200 +#define CR_INT_0 0x00000400 +#define CR_INT_1 0x00000800 +#define CR_INT_2 0x00001000 +#define CR_INT_3 0x00002000 +#define CR_INT_4 0x00004000 +#define CR_INT_5 0x00008000 + +#define CR_INT_MASK 0x003fff00 + +/* + * Config register. + */ + +#define CFGR_CCA_MASK 0x00000007 +#define CFGR_CU 0x00000008 +#define CFGR_ICE 0x0000000200000000 +#define CFGR_SMM 0x0000000400000000 + +/* + * Location of exception vectors. + */ + +#define RESET_EXC_VEC (CKSEG1_BASE + 0x1fc00000) +#define TLB_MISS_EXC_VEC (CKSEG1_BASE + 0x00000000) +#define XTLB_MISS_EXC_VEC (CKSEG1_BASE + 0x00000080) +#define CACHE_ERR_EXC_VEC (CKSEG1_BASE + 0x00000100) +#define GEN_EXC_VEC (CKSEG1_BASE + 0x00000180) + +/* + * Coprocessor 0 registers + */ + +/* Common subset */ +#define COP_0_COUNT $9 +#define COP_0_TLB_HI $10 +#define COP_0_STATUS_REG $12 +#define COP_0_CAUSE_REG $13 +#define COP_0_EXC_PC $14 +#define COP_0_PRID $15 +#define COP_0_CONFIG $16 + +/* MIPS64 release 2 */ +#define COP_0_USERLOCAL $4, 2 +#define COP_0_TLB_PG_GRAIN $5, 1 +#define COP_0_EBASE $15, 1 + +/* R4000/5000/10000 */ +#define COP_0_TLB_INDEX $0 +#define COP_0_TLB_RANDOM $1 +#define COP_0_TLB_LO0 $2 +#define COP_0_TLB_LO1 $3 +#define COP_0_TLB_CONTEXT $4 +#define COP_0_TLB_PG_MASK $5 +#define COP_0_TLB_WIRED $6 +#define COP_0_BAD_VADDR $8 +#define COP_0_COMPARE $11 +#define COP_0_LLADDR $17 +#define COP_0_WATCH_LO $18 +#define COP_0_WATCH_HI $19 +#define COP_0_TLB_XCONTEXT $20 +#define COP_0_ECC $26 +#define COP_0_CACHE_ERR $27 +#define COP_0_TAG_LO $28 +#define COP_0_TAG_HI $29 +#define COP_0_ERROR_PC $30 + +/* Loongson-2 specific */ +#define COP_0_DIAG $22 + +/* Octeon specific */ +#define COP_0_CVMCTL $9, 7 +#define COP_0_CVMMEMCTL $11, 7 + +/* + * COP_0_COUNT speed divider. + */ +#if defined(CPU_OCTEON) +#define CP0_CYCLE_DIVIDER 1 +#else +#define CP0_CYCLE_DIVIDER 2 +#endif + +/* + * The floating point version and status registers. + */ +#define FPC_ID $0 +#define FPC_CSR $31 + +/* + * Config1 register + */ +#define CONFIG1_M 0x80000000u +#define CONFIG1_MMUSize1 0x7e000000u +#define CONFIG1_MMUSize1_SHIFT 25 +#define CONFIG1_IS 0x01c00000u +#define CONFIG1_IS_SHIFT 22 +#define CONFIG1_IL 0x00380000u +#define CONFIG1_IL_SHIFT 19 +#define CONFIG1_IA 0x00070000u +#define CONFIG1_IA_SHIFT 16 +#define CONFIG1_DS 0x0000e000u +#define CONFIG1_DS_SHIFT 13 +#define CONFIG1_DL 0x00001c00u +#define CONFIG1_DL_SHIFT 10 +#define CONFIG1_DA 0x00000380u +#define CONFIG1_DA_SHIFT 7 +#define CONFIG1_C2 0x00000040u +#define CONFIG1_MD 0x00000020u +#define CONFIG1_PC 0x00000010u +#define CONFIG1_WR 0x00000008u +#define CONFIG1_CA 0x00000004u +#define CONFIG1_EP 0x00000002u +#define CONFIG1_FP 0x00000001u + +/* + * Config3 register + */ +#define CONFIG3_M 0x80000000 +#define CONFIG3_BPG 0x40000000 +#define CONFIG3_CMGCR 0x20000000 +#define CONFIG3_IPLW 0x00600000 +#define CONFIG3_MMAR 0x001c0000 +#define CONFIG3_MCU 0x00020000 +#define CONFIG3_ISAOnExc 0x00010000 +#define CONFIG3_ISA 0x0000c000 +#define CONFIG3_ULRI 0x00002000 +#define CONFIG3_RXI 0x00001000 +#define CONFIG3_DSP2P 0x00000800 +#define CONFIG3_DSPP 0x00000400 +#define CONFIG3_CTXTC 0x00000200 +#define CONFIG3_ITL 0x00000100 +#define CONFIG3_LPA 0x00000080 +#define CONFIG3_VEIC 0x00000040 +#define CONFIG3_VInt 0x00000020 +#define CONFIG3_SP 0x00000010 +#define CONFIG3_CDMM 0x00000008 +#define CONFIG3_MT 0x00000004 +#define CONFIG3_SM 0x00000002 +#define CONFIG3_TL 0x00000001 + +/* + * Config4 register + */ +#define CONFIG4_M 0x80000000u +#define CONFIG4_IE 0x60000000u +#define CONFIG4_AE 0x10000000u +#define CONFIG4_VTLBSizeExt 0x0f000000u /* when MMUExtDef=3 */ +#define CONFIG4_KScrExist 0x00ff0000u +#define CONFIG4_MMUExtDef 0x0000c000u +#define CONFIG4_MMUExtDef_SHIFT 14 +#define CONFIG4_FTLBPageSize 0x00001f00u /* when MMUExtDef=2 or 3 */ +#define CONFIG4_FTLBWays 0x000000f0u /* when MMUExtDef=2 or 3 */ +#define CONFIG4_FTLBSets 0x0000000fu /* when MMUExtDef=2 or 3 */ +#define CONFIG4_MMUSizeExt 0x000000ffu /* when MMUExtDef=1 */ + +/* + * PageGrain register + */ +#define PGRAIN_RIE 0x80000000 +#define PGRAIN_XIE 0x40000000 +#define PGRAIN_ELPA 0x20000000 +#define PGRAIN_ESP 0x10000000 +#define PGRAIN_IEC 0x08000000 + +/* + * HWREna register + */ +#define HWRENA_ULR 0x20000000u +#define HWRENA_CC 0x00000004u + +#endif /* _KERNEL || _STANDALONE */ + +#endif /* !_MIPS64_CPUREGS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/mips_opcode.h b/lib/libc/include/generic-openbsd/mips64/mips_opcode.h new file mode 100644 index 0000000000..f40d67885b --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/mips_opcode.h @@ -0,0 +1,347 @@ +/* $OpenBSD: mips_opcode.h,v 1.9 2017/04/20 15:42:26 visa Exp $ */ + +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Ralph Campbell. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)mips_opcode.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _MIPS64_MIPS_OPCODE_H_ +#define _MIPS64_MIPS_OPCODE_H_ + +/* + * Define the instruction formats and opcode values for the + * MIPS instruction set. + */ + +/* + * Define the instruction formats. + */ +typedef union { + unsigned word; + +#if BYTE_ORDER == BIG_ENDIAN + struct { + unsigned op: 6; + unsigned rs: 5; + unsigned rt: 5; + unsigned imm: 16; + } IType; + + struct { + unsigned op: 6; + unsigned target: 26; + } JType; + + struct { + unsigned op: 6; + unsigned rs: 5; + unsigned rt: 5; + unsigned rd: 5; + unsigned shamt: 5; + unsigned func: 6; + } RType; + + struct { + unsigned op: 6; /* COP1 */ + unsigned : 1; /* always '1' */ + unsigned fmt: 4; + unsigned ft: 5; + unsigned fs: 5; + unsigned fd: 5; + unsigned func: 6; + } FRType; + + struct { + unsigned op: 6; /* COP1X */ + unsigned fr: 5; + unsigned ft: 5; + unsigned fs: 5; + unsigned fd: 5; + unsigned op4: 3; + unsigned fmt3: 3; + } FQType; +#endif +#if BYTE_ORDER == LITTLE_ENDIAN + struct { + unsigned imm: 16; + unsigned rt: 5; + unsigned rs: 5; + unsigned op: 6; + } IType; + + struct { + unsigned target: 26; + unsigned op: 6; + } JType; + + struct { + unsigned func: 6; + unsigned shamt: 5; + unsigned rd: 5; + unsigned rt: 5; + unsigned rs: 5; + unsigned op: 6; + } RType; + + struct { + unsigned func: 6; + unsigned fd: 5; + unsigned fs: 5; + unsigned ft: 5; + unsigned fmt: 4; + unsigned : 1; /* always '1' */ + unsigned op: 6; /* COP1 */ + } FRType; + + struct { + unsigned fmt3: 3; + unsigned op4: 3; + unsigned fd: 5; + unsigned fs: 5; + unsigned ft: 5; + unsigned fr: 5; + unsigned op: 6; /* COP1X */ + } FQType; +#endif +} InstFmt; + +/* + * Values for the 'op' field. + */ +#define OP_SPECIAL 000 +#define OP_BCOND 001 +#define OP_J 002 +#define OP_JAL 003 +#define OP_BEQ 004 +#define OP_BNE 005 +#define OP_BLEZ 006 +#define OP_BGTZ 007 + +#define OP_ADDI 010 +#define OP_ADDIU 011 +#define OP_SLTI 012 +#define OP_SLTIU 013 +#define OP_ANDI 014 +#define OP_ORI 015 +#define OP_XORI 016 +#define OP_LUI 017 + +#define OP_COP0 020 +#define OP_COP1 021 +#define OP_COP2 022 +#define OP_COP3 023 +#define OP_COP1X 023 +#define OP_BEQL 024 +#define OP_BNEL 025 +#define OP_BLEZL 026 +#define OP_BGTZL 027 + +#define OP_DADDI 030 +#define OP_DADDIU 031 +#define OP_LDL 032 +#define OP_LDR 033 + +#define OP_SPECIAL3 037 + +#define OP_LB 040 +#define OP_LH 041 +#define OP_LWL 042 +#define OP_LW 043 +#define OP_LBU 044 +#define OP_LHU 045 +#define OP_LWR 046 +#define OP_LWU 047 + +#define OP_SB 050 +#define OP_SH 051 +#define OP_SWL 052 +#define OP_SW 053 +#define OP_SDL 054 +#define OP_SDR 055 +#define OP_SWR 056 +#define OP_CACHE 057 + +#define OP_LL 060 +#define OP_LWC1 061 +#define OP_LWC2 062 +#define OP_LWC3 063 +#define OP_PREF 063 +#define OP_LLD 064 +#define OP_LDC1 065 +#define OP_LDC2 066 +#define OP_LD 067 + +#define OP_SC 070 +#define OP_SWC1 071 +#define OP_SWC2 072 +#define OP_SWC3 073 +#define OP_SCD 074 +#define OP_SDC1 075 +#define OP_SDC2 076 +#define OP_SD 077 + +/* + * Values for the 'func' field when 'op' == OP_SPECIAL. + */ +#define OP_SLL 000 +#define OP_MOVCI 001 +#define OP_SRL 002 +#define OP_SRA 003 +#define OP_SLLV 004 +#define OP_SRLV 006 +#define OP_SRAV 007 + +#define OP_JR 010 +#define OP_JALR 011 +#define OP_MOVZ 012 +#define OP_MOVN 013 +#define OP_SYSCALL 014 +#define OP_BREAK 015 +#define OP_SYNC 017 + +#define OP_MFHI 020 +#define OP_MTHI 021 +#define OP_MFLO 022 +#define OP_MTLO 023 +#define OP_DSLLV 024 +#define OP_DSRLV 026 +#define OP_DSRAV 027 + +#define OP_MULT 030 +#define OP_MULTU 031 +#define OP_DIV 032 +#define OP_DIVU 033 +#define OP_DMULT 034 +#define OP_DMULTU 035 +#define OP_DDIV 036 +#define OP_DDIVU 037 + +#define OP_ADD 040 +#define OP_ADDU 041 +#define OP_SUB 042 +#define OP_SUBU 043 +#define OP_AND 044 +#define OP_OR 045 +#define OP_XOR 046 +#define OP_NOR 047 + +#define OP_SLT 052 +#define OP_SLTU 053 +#define OP_DADD 054 +#define OP_DADDU 055 +#define OP_DSUB 056 +#define OP_DSUBU 057 + +#define OP_TGE 060 +#define OP_TGEU 061 +#define OP_TLT 062 +#define OP_TLTU 063 +#define OP_TEQ 064 +#define OP_TNE 066 + +#define OP_DSLL 070 +#define OP_DSRL 072 +#define OP_DSRA 073 +#define OP_DSLL32 074 +#define OP_DSRL32 076 +#define OP_DSRA32 077 + +/* + * Values for the 'rt' field when 'op' == OP_BCOND. + */ +#define OP_BLTZ 000 +#define OP_BGEZ 001 +#define OP_BLTZL 002 +#define OP_BGEZL 003 + +#define OP_TGEI 010 +#define OP_TGEIU 011 +#define OP_TLTI 012 +#define OP_TLTIU 013 +#define OP_TEQI 014 +#define OP_TNEI 016 + +#define OP_BLTZAL 020 +#define OP_BGEZAL 021 +#define OP_BLTZALL 022 +#define OP_BGEZALL 023 + +/* + * Values for the 'rs' field when 'op' == OP_COPz. + */ +#define OP_MF 000 +#define OP_DMF 001 +#define OP_CF 002 +#define OP_MFH 003 +#define OP_MT 004 +#define OP_DMT 005 +#define OP_CT 006 +#define OP_MTH 007 +#define OP_BC 010 +#define OP_C0MISC 020 /* cop0 only */ +#define OP_TFP_C0MISC 030 /* cop0 only on R8000 */ + +/* + * Values for the 'rt' field when 'op' == OP_COPz. + */ +#define COPz_BC_TF_MASK 0x01 +#define COPz_BC_TRUE 0x01 +#define COPz_BC_FALSE 0x00 +#define COPz_BCL_TF_MASK 0x02 +#define COPz_BCL_TRUE 0x02 +#define COPz_BCL_FALSE 0x00 +#define COPz_BC_CC_MASK 0x1c +#define COPz_BC_CC_SHIFT 2 + +/* + * Values for the 'func' field when 'op' == OP_COP1X. + */ +#define OP_LWXC1 000 +#define OP_LDXC1 001 +#define OP_SWXC1 010 +#define OP_SDXC1 011 +#define OP_PREFX 017 + +/* + * Values for the 'op4' field when 'op' == OP_COP1X. + */ +#define OP_MADD 04 +#define OP_MSUB 05 +#define OP_NMADD 06 +#define OP_NMSUB 07 + +/* + * Values for the 'func' field when 'op' == OP_SPECIAL3. + */ +#define OP_RDHWR 073 + +#endif /* !_MIPS64_MIPS_OPCODE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/mplock.h b/lib/libc/include/generic-openbsd/mips64/mplock.h new file mode 100644 index 0000000000..a2c480761e --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/mplock.h @@ -0,0 +1,10 @@ +/* $OpenBSD: mplock.h,v 1.2 2017/10/21 06:11:22 visa Exp $ */ + +/* public domain */ + +#ifndef _MACHINE_MPLOCK_H_ +#define _MACHINE_MPLOCK_H_ + +#define __USE_MI_MPLOCK + +#endif /* !_MACHINE_MPLOCK_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/mutex.h b/lib/libc/include/generic-openbsd/mips64/mutex.h new file mode 100644 index 0000000000..f5115c3084 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/mutex.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mutex.h,v 1.5 2018/01/25 15:06:29 mpi Exp $ */ + +#define __USE_MI_MUTEX \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/param.h b/lib/libc/include/generic-openbsd/mips64/param.h new file mode 100644 index 0000000000..3420605a0d --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/param.h @@ -0,0 +1,82 @@ +/* $OpenBSD: param.h,v 1.37 2023/12/14 13:26:49 claudio Exp $ */ + +/* + * Copyright (c) 1988 University of Utah. + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department and Ralph Campbell. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _MIPS64_PARAM_H_ +#define _MIPS64_PARAM_H_ + +#ifdef _KERNEL +#include +#endif + +#define PAGE_SIZE (1 << PAGE_SHIFT) +#define PAGE_MASK (PAGE_SIZE - 1) + +#ifdef _KERNEL + +#ifndef KERNBASE +#define KERNBASE 0xffffffff80000000L /* start of kernel virtual */ +#endif + +#define NBPG PAGE_SIZE +#define PGSHIFT PAGE_SHIFT +#define PGOFSET PAGE_MASK + +#define USPACE 16384 +#define UPAGES (USPACE >> PAGE_SHIFT) +#if PAGE_SHIFT > 12 +#define USPACE_ALIGN 0 +#else +#define USPACE_ALIGN (2 * PAGE_SIZE) /* align to an even TLB boundary */ +#endif + +#define NMBCLUSTERS (64 * 1024) /* max cluster allocation */ + +#ifndef MSGBUFSIZE +#if PAGE_SHIFT > 12 +#define MSGBUFSIZE PAGE_SIZE +#else +#define MSGBUFSIZE 8192 +#endif +#endif + +#ifndef _LOCORE +#define DELAY(n) delay(n) +void delay(int); +#endif + +#endif /* _KERNEL */ + +#endif /* _MIPS64_PARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/pcb.h b/lib/libc/include/generic-openbsd/mips64/pcb.h new file mode 100644 index 0000000000..bef10d569c --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/pcb.h @@ -0,0 +1,58 @@ +/* $OpenBSD: pcb.h,v 1.10 2021/10/07 12:40:16 visa Exp $ */ + +/* + * Copyright (c) 1988 University of Utah. + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department and Ralph Campbell. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: Utah Hdr: pcb.h 1.13 89/04/23 + * from: @(#)pcb.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _MIPS64_PCB_H_ +#define _MIPS64_PCB_H_ + +#include + +/* + * MIPS process control block. This is first in the U-area. + */ +struct pcb { + struct trapframe pcb_regs; /* saved CPU and registers */ + struct { + /* val[12] is unused, was RM7000 ICR */ + register_t val[13]; + } pcb_context; /* kernel context for resume */ + int pcb_onfault; /* for copyin/copyout faults */ + void *pcb_segtab; /* copy of pmap pm_segtab */ +}; + +#endif /* !_MIPS64_PCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/pmap.h b/lib/libc/include/generic-openbsd/mips64/pmap.h new file mode 100644 index 0000000000..571adc77b8 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/pmap.h @@ -0,0 +1,228 @@ +/* $OpenBSD: pmap.h,v 1.55 2025/06/02 18:49:04 claudio Exp $ */ + +/* + * Copyright (c) 1987 Carnegie-Mellon University + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Ralph Campbell. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)pmap.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _MIPS64_PMAP_H_ +#define _MIPS64_PMAP_H_ + +#include + +#ifdef _KERNEL + +#include + +/* + * The user address space is currently limited to 1TB (0x0 - 0x10000000000). + * + * The user address space is mapped using a two level structure where + * the virtual addresses bits are split in three groups: + * segment:directory:page:offset + * where: + * - offset are the in-page offsets (PAGE_SHIFT bits) + * - page are the third level page table index + * (PMAP_PGSHIFT - Log2(pt_entry_t) bits) + * - directory are the second level page table (directory) index + * (PMAP_PGSHIFT - Log2(void *) bits) + * - segment are the first level page table (segment) index + * (PMAP_PGSHIFT - Log2(void *) bits) + * + * This scheme allows Segment, directory and page tables have the same size + * (1 << PMAP_PGSHIFT bytes, regardless of the pt_entry_t size) to be able to + * share the same allocator. + * + * Note: The kernel doesn't use the same data structures as user programs. + * All the PTE entries are stored in a single array in Sysmap which is + * dynamically allocated at boot time. + */ + +#if defined(MIPS_PTE64) && PAGE_SHIFT == 12 +#error "Cannot use MIPS_PTE64 with 4KB pages." +#endif + +/* + * Size of page table structs (page tables, page directories, + * and segment table) used by this pmap. + */ + +#define PMAP_PGSHIFT 12 +#define PMAP_PGSIZE (1UL << PMAP_PGSHIFT) + +#define NPDEPG (PMAP_PGSIZE / sizeof(void *)) +#define NPTEPG (PMAP_PGSIZE / sizeof(pt_entry_t)) + +/* + * Segment sizes + */ + +#define SEGSHIFT (PAGE_SHIFT+PMAP_PGSHIFT*2-PTE_LOG-3) +#define DIRSHIFT (PAGE_SHIFT+PMAP_PGSHIFT-PTE_LOG) +#define NBSEG (1UL << SEGSHIFT) +#define NBDIR (1UL << DIRSHIFT) +#define SEGOFSET (NBSEG - 1) +#define DIROFSET (NBDIR - 1) + +#define mips_trunc_seg(x) ((vaddr_t)(x) & ~SEGOFSET) +#define mips_trunc_dir(x) ((vaddr_t)(x) & ~DIROFSET) +#define mips_round_seg(x) (((vaddr_t)(x) + SEGOFSET) & ~SEGOFSET) +#define mips_round_dir(x) (((vaddr_t)(x) + DIROFSET) & ~DIROFSET) +#define pmap_segmap(m, v) ((m)->pm_segtab->seg_tab[((v) >> SEGSHIFT)]) + +/* number of segments entries */ +#define PMAP_SEGTABSIZE (PMAP_PGSIZE / sizeof(void *)) + +struct segtab { + pt_entry_t **seg_tab[PMAP_SEGTABSIZE]; +}; + +struct pmap_asid_info { + u_int pma_asid; /* address space tag */ + u_int pma_asidgen; /* TLB PID generation number */ +}; + +/* + * Machine dependent pmap structure. + */ +typedef struct pmap { + struct mutex pm_mtx; /* pmap lock */ + struct mutex pm_swmtx; /* pmap switch lock */ + int pm_count; /* pmap reference count */ + struct pmap_statistics pm_stats; /* pmap statistics */ + struct segtab *pm_segtab; /* pointers to pages of PTEs */ + struct pmap_asid_info pm_asid[1]; /* ASID information */ +} *pmap_t; + +/* + * Compute the sizeof of a pmap structure. Subtract one because one + * ASID info structure is already included in the pmap structure itself. + */ +#define PMAP_SIZEOF(x) \ + (ALIGN(sizeof(struct pmap) + \ + (sizeof(struct pmap_asid_info) * ((x) - 1)))) + +/* machine-dependent pg_flags */ +#define PGF_UNCACHED PG_PMAP0 /* Page is explicitly uncached */ +#define PGF_CACHED PG_PMAP1 /* Page is currently cached */ +#define PGF_ATTR_MOD PG_PMAP2 +#define PGF_ATTR_REF PG_PMAP3 +#define PGF_PRESERVE (PGF_ATTR_MOD | PGF_ATTR_REF) + +#define PMAP_NOCACHE PMAP_MD0 + +extern struct pmap *const kernel_pmap_ptr; + +#define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count) +#define pmap_wired_count(pmap) ((pmap)->pm_stats.wired_count) +#define pmap_kernel() (kernel_pmap_ptr) + +extern pt_entry_t pg_ri; +#define PMAP_CHECK_COPYIN (pg_ri == 0) + +#define PMAP_STEAL_MEMORY /* Enable 'stealing' during boot */ + +#define PMAP_PREFER +extern vaddr_t pmap_prefer_mask; +/* pmap prefer alignment */ +#define PMAP_PREFER_ALIGN() \ + (pmap_prefer_mask ? pmap_prefer_mask + 1 : 0) +/* pmap prefer offset in alignment */ +#define PMAP_PREFER_OFFSET(of) ((of) & pmap_prefer_mask) + +void pmap_bootstrap(void); +int pmap_copyinsn(pmap_t, vaddr_t, uint32_t *); +int pmap_emulate_modify(pmap_t, vaddr_t); +void pmap_page_cache(vm_page_t, u_int); + +#define pmap_init_percpu() do { /* nothing */ } while (0) +#define pmap_unuse_final(p) do { /* nothing yet */ } while (0) +#define pmap_remove_holes(vm) do { /* nothing */ } while (0) + +#define __HAVE_PMAP_DIRECT +vaddr_t pmap_map_direct(vm_page_t); +vm_page_t pmap_unmap_direct(vaddr_t); + +/* + * MD flags to pmap_enter: + */ + +#define PMAP_PA_MASK ~((paddr_t)PAGE_MASK) + +/* Kernel virtual address to page table entry */ +#define kvtopte(va) \ + (Sysmap + (((vaddr_t)(va) - VM_MIN_KERNEL_ADDRESS) >> PAGE_SHIFT)) +/* User virtual address to pte page entry */ +#define uvtopte(va) (((va) >> PAGE_SHIFT) & (NPTEPG -1)) +#define uvtopde(va) (((va) >> DIRSHIFT) & (NPDEPG - 1)) + +static inline pt_entry_t * +pmap_pte_lookup(struct pmap *pmap, vaddr_t va) +{ + pt_entry_t **pde, *pte; + + if ((pde = pmap_segmap(pmap, va)) == NULL) + return NULL; + if ((pte = pde[uvtopde(va)]) == NULL) + return NULL; + return pte + uvtopte(va); +} + +extern pt_entry_t *Sysmap; /* kernel pte table */ +extern u_int Sysmapsize; /* number of pte's in Sysmap */ + +#endif /* _KERNEL */ + +#if !defined(_LOCORE) +typedef struct pv_entry { + struct pv_entry *pv_next; /* next pv_entry */ + struct pmap *pv_pmap; /* pmap where mapping lies */ + vaddr_t pv_va; /* virtual address for mapping */ +} *pv_entry_t; + +struct vm_page_md { + struct mutex pv_mtx; /* pv list lock */ + struct pv_entry pv_ent; /* pv list of this seg */ +}; + +#define VM_MDPAGE_INIT(pg) \ + do { \ + mtx_init(&(pg)->mdpage.pv_mtx, IPL_VM); \ + (pg)->mdpage.pv_ent.pv_next = NULL; \ + (pg)->mdpage.pv_ent.pv_pmap = NULL; \ + (pg)->mdpage.pv_ent.pv_va = 0; \ + } while (0) + +#endif /* !_LOCORE */ + +#endif /* !_MIPS64_PMAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/proc.h b/lib/libc/include/generic-openbsd/mips64/proc.h new file mode 100644 index 0000000000..987d27cd4b --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/proc.h @@ -0,0 +1,75 @@ +/* $OpenBSD: proc.h,v 1.11 2017/04/13 03:52:25 guenther Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Ralph Campbell. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)proc.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _MIPS64_PROC_H_ +#define _MIPS64_PROC_H_ + +/* + * Machine-dependent part of the proc structure. + */ +struct mdproc { + struct trapframe *md_regs; /* registers on current frame */ + volatile int md_astpending; /* AST pending for this process */ + int md_flags; /* machine-dependent flags */ + vaddr_t md_uarea; /* allocated uarea virtual addr */ + void *md_tcb; /* user-space thread-control-block */ + + /* ptrace fields */ + vaddr_t md_ss_addr; /* single step address */ + uint32_t md_ss_instr; /* saved single step instruction */ + + /* fpu emulation fields */ + vaddr_t md_fppgva; /* vaddr of the branch emulation page */ + vaddr_t md_fpbranchva; /* vaddr of fp branch destination */ + vaddr_t md_fpslotva; /* initial vaddr of delay slot */ + + int32_t md_obsolete[10]; /* Were RM7000-specific data. */ +}; + +/* + * Values for md_flags. + * MDP_FPUSED has two meanings: if the floating point hardware (coprocessor + * #1) is available, it means it has been used; if there is no floating + * point hardware, it means the process is currently running a duplicated + * delay slot, created by the branch emulation logic. + */ +#define MDP_FPUSED 0x00000001 /* floating point coprocessor used */ +#define MDP_PERF 0x00010000 /* Performance counter used */ +#define MDP_WATCH1 0x00020000 /* Watch register 1 used */ +#define MDP_WATCH2 0x00040000 /* Watch register 1 used */ +#define MDP_FORKSAVE 0x0000ffff /* Flags to save when forking */ + +#endif /* !_MIPS64_PROC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/profile.h b/lib/libc/include/generic-openbsd/mips64/profile.h new file mode 100644 index 0000000000..09470a2561 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/profile.h @@ -0,0 +1,85 @@ +/* $OpenBSD: profile.h,v 1.5 2019/04/19 09:19:22 visa Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Ralph Campbell. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: @(#)profile.h 8.1 (Berkeley) 6/10/93 + */ +#ifndef _MIPS64_PROFILE_H_ +#define _MIPS64_PROFILE_H_ + +#define _MCOUNT_DECL static void ___mcount + +/*XXX The cprestore instruction is a "dummy" to shut up as(1). */ + +#define MCOUNT \ + __asm(".globl _mcount;" \ + ".type _mcount,@function;" \ + "_mcount:;" \ + ".set noreorder;" \ + ".set noat;" \ + ".cpload $25;" \ + ".cprestore 4;" \ + "sd $4,16($29);" \ + "sd $5,24($29);" \ + "sd $6,32($29);" \ + "sd $7,40($29);" \ + "sd $1,0($29);" \ + "sd $31,8($29);" \ + "move $5,$31;" \ + ".local ___mcount;" \ + "jal ___mcount;" \ + "move $4,$1;" \ + "ld $4,16($29);" \ + "ld $5,24($29);" \ + "ld $6,32($29);" \ + "ld $7,40($29);" \ + "ld $31,8($29);" \ + "ld $1,0($29);" \ + "daddu $29,$29,16;" \ + "j $31;" \ + "move $31,$1;" \ + ".set reorder;" \ + ".set at"); + +#ifdef _KERNEL +/* + * The following two macros do splhigh and splx respectively. + * They have to be defined this way because these are real + * functions on the MIPS, and we do not want to invoke mcount + * recursively. + */ +#define MCOUNT_ENTER s = _splhigh() + +#define MCOUNT_EXIT _splx(s) +#endif /* _KERNEL */ + +#endif /* !_MIPS64_PROFILE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/pte.h b/lib/libc/include/generic-openbsd/mips64/pte.h new file mode 100644 index 0000000000..cc5c5d0ba1 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/pte.h @@ -0,0 +1,160 @@ +/* $OpenBSD: pte.h,v 1.24 2023/01/11 03:17:56 visa Exp $ */ + +/* + * Copyright (c) 1988 University of Utah. + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department and Ralph Campbell. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: Utah Hdr: pte.h 1.11 89/09/03 + * from: @(#)pte.h 8.1 (Berkeley) 6/10/93 + */ + +/* + * R4000 and R8000 hardware page table entries + */ + +#ifndef _MIPS64_PTE_H_ +#define _MIPS64_PTE_H_ + +#ifndef _LOCORE + +/* + * Structure defining a TLB entry data set. + */ +struct tlb_entry { + u_int64_t tlb_mask; + u_int64_t tlb_hi; + u_int64_t tlb_lo0; + u_int64_t tlb_lo1; +}; + +u_int tlb_get_pid(void); +void tlb_read(unsigned int, struct tlb_entry *); + +#ifdef MIPS_PTE64 +typedef u_int64_t pt_entry_t; +#else +typedef u_int32_t pt_entry_t; +#endif + +#endif /* _LOCORE */ + +#ifdef MIPS_PTE64 +#define PTE_BITS 64 +#define PTE_LOAD ld +#define PTE_LOG 3 +#define PTE_OFFS 8 +#else +#define PTE_BITS 32 +#define PTE_LOAD lwu +#define PTE_LOG 2 +#define PTE_OFFS 4 +#endif + +#if defined(CPU_MIPS64R2) && !defined(CPU_LOONGSON2) +#define PTE_CLEAR_SWBITS(reg) \ + .set push; \ + .set mips64r2; \ + /* Clear SW bits between PG_XI and PG_FRAMEBITS. */ \ + dins reg, zero, PG_FRAMEBITS, (PTE_BITS - 2 - PG_FRAMEBITS); \ + .set pop +#else +#define PTE_CLEAR_SWBITS(reg) \ + /* Clear SW bits left of PG_FRAMEBITS. */ \ + dsll reg, reg, (64 - PG_FRAMEBITS); \ + dsrl reg, reg, (64 - PG_FRAMEBITS) +#endif + +/* entryhi values */ + +#define PG_HVPN (-2 * PAGE_SIZE) /* Hardware page number mask */ +#define PG_ODDPG PAGE_SIZE + +/* Address space ID */ +#define PG_ASID_MASK 0x00000000000000ff +#define PG_ASID_SHIFT 0 +#define MIN_USER_ASID 1 +#define PG_ASID_COUNT 256 /* Number of available ASID */ + +/* entrylo values */ + +#ifdef MIPS_PTE64 +#define PG_FRAMEBITS 60 +#else +#define PG_FRAMEBITS 28 +#endif +#define PG_FRAME ((1ULL << PG_FRAMEBITS) - (1ULL << PG_SHIFT)) +#define PG_SHIFT 6 + +/* software pte bits - not put in entrylo */ +#define PG_WIRED (1ULL << (PG_FRAMEBITS + 1)) +#define PG_RO (1ULL << (PG_FRAMEBITS + 0)) + +#ifdef CPU_MIPS64R2 +#define PG_RI (1ULL << (PG_FRAMEBITS + 3)) +#define PG_XI (1ULL << (PG_FRAMEBITS + 2)) +#else +#define PG_RI 0x00000000 +#define PG_XI 0x00000000 +#endif + +#define PG_NV 0x00000000 +#define PG_G 0x00000001 +#define PG_V 0x00000002 +#define PG_M 0x00000004 +#define PG_CCA_SHIFT 3 + +#define PG_UNCACHED (CCA_NC << PG_CCA_SHIFT) +#define PG_CACHED_NC (CCA_NONCOHERENT << PG_CCA_SHIFT) +#define PG_CACHED_CE (CCA_COHERENT_EXCL << PG_CCA_SHIFT) +#define PG_CACHED_CEW (CCA_COHERENT_EXCLWRITE << PG_CCA_SHIFT) +#define PG_CACHED (CCA_CACHED << PG_CCA_SHIFT) +#define PG_CACHEMODE (7 << PG_CCA_SHIFT) + +#define PG_PROTMASK (PG_M | PG_RO | PG_RI | PG_XI) + +#define pfn_to_pad(pa) ((((paddr_t)pa) & PG_FRAME) << PG_SHIFT) +#define vad_to_pfn(va) (((va) >> PG_SHIFT) & PG_FRAME) + +#define PG_SIZE_4K 0x00000000 +#define PG_SIZE_16K 0x00006000 +#define PG_SIZE_64K 0x0001e000 +#define PG_SIZE_256K 0x0007e000 +#define PG_SIZE_1M 0x001fe000 +#define PG_SIZE_4M 0x007fe000 +#define PG_SIZE_16M 0x01ffe000 +#if PAGE_SHIFT == 12 +#define TLB_PAGE_MASK PG_SIZE_4K +#elif PAGE_SHIFT == 14 +#define TLB_PAGE_MASK PG_SIZE_16K +#endif + +#endif /* !_MIPS64_PTE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/ptrace.h b/lib/libc/include/generic-openbsd/mips64/ptrace.h new file mode 100644 index 0000000000..000251046b --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/ptrace.h @@ -0,0 +1,46 @@ +/* $OpenBSD: ptrace.h,v 1.3 2011/03/23 16:54:36 pirofti Exp $ */ + +/* + * Copyright (c) 1992, 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. + * + * from: @(#)ptrace.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _MIPS64_PTRACE_H_ +#define _MIPS64_PTRACE_H_ + +/* + * Machine dependent trace commands. + * + */ + +#define PT_GETREGS (PT_FIRSTMACH+0) +#define PT_SETREGS (PT_FIRSTMACH+1) +#define PT_STEP (PT_FIRSTMACH+2) + +#endif /* !_MIPS64_PTRACE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/reg.h b/lib/libc/include/generic-openbsd/mips64/reg.h new file mode 100644 index 0000000000..38245604ff --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/reg.h @@ -0,0 +1,54 @@ +/* $OpenBSD: reg.h,v 1.5 2021/10/07 12:32:10 visa Exp $ */ + +/* + * Copyright (c) 1988 University of Utah. + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department and Ralph Campbell. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: Utah Hdr: reg.h 1.1 90/07/09 + * @(#)reg.h 8.2 (Berkeley) 1/11/94 + */ + +#ifndef _MIPS64_REG_H_ +#define _MIPS64_REG_H_ +/* + * Location of the users' stored + * registers relative to ZERO. + * Usage is p->p_regs[XX]. + * + * must be visible to assembly code. + */ +#include + +struct reg { + register_t r_regs[NREGS]; /* numbered as above */ +}; +#endif /* !_MIPS64_REG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/regdef.h b/lib/libc/include/generic-openbsd/mips64/regdef.h new file mode 100644 index 0000000000..27c56a035a --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/regdef.h @@ -0,0 +1,77 @@ +/* $OpenBSD: regdef.h,v 1.5 2014/03/10 21:10:36 miod 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. This file is derived from the MIPS RISC + * Architecture book by Gerry Kane. + * + * 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. + * + * @(#)regdef.h 8.1 (Berkeley) 6/10/93 + */ +#ifndef _MIPS64_REGDEF_H_ +#define _MIPS64_REGDEF_H_ + +#define zero $0 /* always zero */ +#define AT $at /* assembler temp */ +#define v0 $2 /* return value */ +#define v1 $3 +#define a0 $4 /* argument registers */ +#define a1 $5 +#define a2 $6 +#define a3 $7 +#define a4 $8 +#define a5 $9 +#define a6 $10 +#define a7 $11 +#define ta0 $8 /* alias */ +#define ta1 $9 +#define ta2 $10 +#define ta3 $11 +#define t0 $12 /* temp registers (not saved across subroutine calls) */ +#define t1 $13 +#define t2 $14 +#define t3 $15 +#define s0 $16 /* saved across subroutine calls (callee saved) */ +#define s1 $17 +#define s2 $18 +#define s3 $19 +#define s4 $20 +#define s5 $21 +#define s6 $22 +#define s7 $23 +#define t8 $24 /* two more temp registers */ +#define t9 $25 +#define k0 $26 /* kernel temporary */ +#define k1 $27 +#define gp $28 /* global pointer */ +#define sp $29 /* stack pointer */ +#define s8 $30 /* one more callee saved */ +#define ra $31 /* return address */ + +#endif /* !_MIPS64_REGDEF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/regnum.h b/lib/libc/include/generic-openbsd/mips64/regnum.h new file mode 100644 index 0000000000..f11f05e222 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/regnum.h @@ -0,0 +1,119 @@ +/* $OpenBSD: regnum.h,v 1.4 2014/07/09 12:58:08 miod Exp $ */ + +/* + * Copyright (c) 2001-2002 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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 _MIPS64_REGNUM_H_ +#define _MIPS64_REGNUM_H_ + +/* + * Location of the saved registers relative to ZERO. + * Usage is p->p_regs[XX]. + */ +#define ZERO 0 +#define AST 1 +#define V0 2 +#define V1 3 +#define A0 4 +#define A1 5 +#define A2 6 +#define A3 7 +#define A4 8 +#define A5 9 +#define A6 10 +#define A7 11 +#define T0 12 +#define T1 13 +#define T2 14 +#define T3 15 +#define S0 16 +#define S1 17 +#define S2 18 +#define S3 19 +#define S4 20 +#define S5 21 +#define S6 22 +#define S7 23 +#define T8 24 +#define T9 25 +#define K0 26 +#define K1 27 +#define GP 28 +#define SP 29 +#define S8 30 +#define RA 31 +#define SR 32 +#define PS SR /* alias for SR */ +#define MULLO 33 +#define MULHI 34 +#define BADVADDR 35 +#define CAUSE 36 +#define PC 37 +#define IC 38 +#define CPL 39 + +#define NUMSAVEREGS 40 /* Number of registers saved in trap */ + +#define FPBASE NUMSAVEREGS +#define F0 (FPBASE+0) +#define F1 (FPBASE+1) +#define F2 (FPBASE+2) +#define F3 (FPBASE+3) +#define F4 (FPBASE+4) +#define F5 (FPBASE+5) +#define F6 (FPBASE+6) +#define F7 (FPBASE+7) +#define F8 (FPBASE+8) +#define F9 (FPBASE+9) +#define F10 (FPBASE+10) +#define F11 (FPBASE+11) +#define F12 (FPBASE+12) +#define F13 (FPBASE+13) +#define F14 (FPBASE+14) +#define F15 (FPBASE+15) +#define F16 (FPBASE+16) +#define F17 (FPBASE+17) +#define F18 (FPBASE+18) +#define F19 (FPBASE+19) +#define F20 (FPBASE+20) +#define F21 (FPBASE+21) +#define F22 (FPBASE+22) +#define F23 (FPBASE+23) +#define F24 (FPBASE+24) +#define F25 (FPBASE+25) +#define F26 (FPBASE+26) +#define F27 (FPBASE+27) +#define F28 (FPBASE+28) +#define F29 (FPBASE+29) +#define F30 (FPBASE+30) +#define F31 (FPBASE+31) +#define FSR (FPBASE+32) + +#define NUMFPREGS 33 + +#define NREGS (NUMSAVEREGS + NUMFPREGS) + +#endif /* !_MIPS64_REGNUM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/reloc.h b/lib/libc/include/generic-openbsd/mips64/reloc.h new file mode 100644 index 0000000000..c25f3c163d --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/reloc.h @@ -0,0 +1,54 @@ +/* $OpenBSD: reloc.h,v 1.4 2017/08/13 14:56:09 visa Exp $ */ + +/* + * Copyright (c) 1996-2004 Per Fogelstrom, Opsycon AB + * + * 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 _MIPS64_RELOC_H_ +#define _MIPS64_RELOC_H_ + +/* + * Mips relocations. + */ + +#define R_MIPS_NONE 0 /* No reloc */ +#define R_MIPS_16 1 /* Direct 16 bit */ +#define R_MIPS_32 2 /* Direct 32 bit */ +#define R_MIPS_REL32 3 /* PC relative 32 bit */ +#define R_MIPS_26 4 /* Direct 26 bit shifted */ +#define R_MIPS_HI16 5 /* High 16 bit */ +#define R_MIPS_LO16 6 /* Low 16 bit */ +#define R_MIPS_GPREL16 7 /* GP relative 16 bit */ +#define R_MIPS_LITERAL 8 /* 16 bit literal entry */ +#define R_MIPS_GOT16 9 /* 16 bit GOT entry */ +#define R_MIPS_PC16 10 /* PC relative 16 bit */ +#define R_MIPS_CALL16 11 /* 16 bit GOT entry for function */ +#define R_MIPS_GPREL32 12 /* GP relative 32 bit */ + +#define R_MIPS_64 18 + +#define R_MIPS_REL32_64 ((R_MIPS_64 << 8) | R_MIPS_REL32) + +#endif /* !_MIPS64_RELOC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/setjmp.h b/lib/libc/include/generic-openbsd/mips64/setjmp.h new file mode 100644 index 0000000000..a7f81372b6 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/setjmp.h @@ -0,0 +1,15 @@ +/* $OpenBSD: setjmp.h,v 1.4 2018/01/08 16:44:32 visa Exp $ */ + +/* Public domain */ + +#ifndef _MIPS64_SETJMP_H_ +#define _MIPS64_SETJMP_H_ + +#define _JB_MASK (1 * REGSZ) +#define _JB_PC (2 * REGSZ) +#define _JB_REGS (3 * REGSZ) +#define _JB_FPREGS (37 * REGSZ) + +#define _JBLEN 83 /* size, in longs, of a jmp_buf */ + +#endif /* !_MIPS64_SETJMP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/signal.h b/lib/libc/include/generic-openbsd/mips64/signal.h new file mode 100644 index 0000000000..2d6f9c1ad8 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/signal.h @@ -0,0 +1,70 @@ +/* $OpenBSD: signal.h,v 1.13 2018/01/08 16:44:32 visa Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Ralph Campbell. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)signal.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _MIPS64_SIGNAL_H_ +#define _MIPS64_SIGNAL_H_ + +#include +#include + +/* + * Machine-dependent signal definitions + */ +typedef int sig_atomic_t; + +#if __BSD_VISIBLE || __XPG_VISIBLE >= 420 +/* + * Information pushed on stack when a signal is delivered. + * This is used by the kernel to restore state following + * execution of the signal handler. It is also made available + * to the handler to allow it to restore state properly if + * a non-standard exit is performed. + */ +struct sigcontext { + long sc_cookie; + long sc_mask; /* signal mask to restore XXX should be int */ + __register_t sc_pc; /* pc at time of signal */ + __register_t sc_regs[32]; /* processor regs 0 to 31 */ + __register_t mullo; /* mullo and mulhi registers... */ + __register_t mulhi; /* mullo and mulhi registers... */ + f_register_t sc_fpregs[33]; /* fp regs 0 to 31 and csr */ + long sc_fpused; /* fp has been used */ + long sc_fpc_eir; /* floating point exception instruction reg */ + long xxx[8]; /* XXX reserved */ +}; +#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */ + +#endif /* !_MIPS64_SIGNAL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/spinlock.h b/lib/libc/include/generic-openbsd/mips64/spinlock.h new file mode 100644 index 0000000000..4ca59f4517 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/spinlock.h @@ -0,0 +1,11 @@ +/* $OpenBSD: spinlock.h,v 1.5 2017/09/05 02:40:54 guenther Exp $ */ + /* Public domain */ + +#ifndef _MIPS64_SPINLOCK_H_ +#define _MIPS64_SPINLOCK_H_ + +#define _ATOMIC_LOCK_UNLOCKED (0) +#define _ATOMIC_LOCK_LOCKED (1) +typedef int _atomic_lock_t; + +#endif /* !_MIPS64_SPINLOCK_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/sysarch.h b/lib/libc/include/generic-openbsd/mips64/sysarch.h new file mode 100644 index 0000000000..04171b7d5d --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/sysarch.h @@ -0,0 +1,52 @@ +/* $OpenBSD: sysarch.h,v 1.2 2012/12/05 23:20:13 deraadt Exp $ */ + +/* + * Copyright (c) 2009 Miodrag Vallat. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MIPS64_SYSARCH_H_ +#define _MIPS64_SYSARCH_H_ + +/* + * Architecture specific syscalls (mips64) + */ + +#define MIPS64_CACHEFLUSH 0 + +/* + * Argument structure and defines to mimic IRIX cacheflush() system call + */ + +struct mips64_cacheflush_args { + vaddr_t va; + size_t sz; + int which; +#define ICACHE 0x01 +#define DCACHE 0x02 +#define BCACHE (ICACHE | DCACHE) +}; + +#ifndef _KERNEL + +#include + +__BEGIN_DECLS +int cacheflush(void *, int, int); +int _flush_cache(char *, int, int); +int sysarch(int, void *); +__END_DECLS +#endif /* _KERNEL */ + +#endif /* _MIPS64_SYSARCH_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/tcb.h b/lib/libc/include/generic-openbsd/mips64/tcb.h new file mode 100644 index 0000000000..eb7bf3bce5 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/tcb.h @@ -0,0 +1,66 @@ +/* $OpenBSD: tcb.h,v 1.4 2017/04/20 16:07:52 visa Exp $ */ + +/* + * Copyright (c) 2011 Philip Guenther + * + * 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 + +static inline void +__mips64_set_tcb(struct proc *p, void *tcb) +{ +#ifdef CPU_MIPS64R2 + extern int cpu_has_userlocal; + + if (cpu_has_userlocal) + cp0_set_userlocal(tcb); +#endif + + p->p_md.md_tcb = tcb; +} + +#define TCB_SET(p, addr) __mips64_set_tcb(p, addr) +#define TCB_GET(p) ((p)->p_md.md_tcb) + +#else /* _KERNEL */ + +/* ELF TLS ABI calls for small TCB, with static TLS data after it */ +#define TLS_VARIANT 1 + +static inline void * +__mips64_get_tcb(void) +{ + void *tcb; + + /* + * This invokes emulation in kernel if the system does not implement + * the RDHWR instruction or the UserLocal register. + */ + __asm__ volatile ( + " .set push\n" + " .set mips64r2\n" + " rdhwr %0, $29\n" + " .set pop\n" : "=r" (tcb)); + return tcb; +} + +#define TCB_GET() __mips64_get_tcb() + +#endif /* _KERNEL */ + +#endif /* _MACHINE_TCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/timetc.h b/lib/libc/include/generic-openbsd/mips64/timetc.h new file mode 100644 index 0000000000..8d7039b706 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/timetc.h @@ -0,0 +1,23 @@ +/* $OpenBSD: timetc.h,v 1.3 2020/07/18 08:37:43 visa Exp $ */ +/* + * Copyright (c) 2020 Paul Irofti + * + * 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 _MIPS64_TIMETC_H_ +#define _MIPS64_TIMETC_H_ + +#define TC_CP0_COUNT 1 + +#endif /* _MIPS64_TIMETC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/trap.h b/lib/libc/include/generic-openbsd/mips64/trap.h new file mode 100644 index 0000000000..2fff7cd584 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/trap.h @@ -0,0 +1,127 @@ +/* $OpenBSD: trap.h,v 1.17 2022/01/28 16:20:09 visa Exp $ */ + +/* + * Copyright (c) 1988 University of Utah. + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department and Ralph Campbell. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: Utah Hdr: trap.h 1.1 90/07/09 + * from: @(#)trap.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _MIPS64_TRAP_H_ +#define _MIPS64_TRAP_H_ + +/* + * Trap codes (ExcCode in the cause register); also known in trap.c for + * name strings. + */ + +#define T_INT 0 /* Interrupt pending */ +#define T_TLB_MOD 1 /* TLB modified fault */ +#define T_TLB_LD_MISS 2 /* TLB miss on load or ifetch */ +#define T_TLB_ST_MISS 3 /* TLB miss on a store */ +#define T_ADDR_ERR_LD 4 /* Address error on a load or ifetch */ +#define T_ADDR_ERR_ST 5 /* Address error on a store */ +#define T_BUS_ERR_IFETCH 6 /* Bus error on an ifetch */ +#define T_BUS_ERR_LD_ST 7 /* Bus error on a load or store */ +#define T_SYSCALL 8 /* System call */ +#define T_BREAK 9 /* Breakpoint */ +#define T_RES_INST 10 /* Reserved instruction exception */ +#define T_COP_UNUSABLE 11 /* Coprocessor unusable */ +#define T_OVFLOW 12 /* Arithmetic overflow */ +#define T_TRAP 13 /* Trap instruction */ +#define T_VCEI 14 /* R4k Virtual coherency instruction */ +#define T_FPE 15 /* Floating point exception */ +#define T_IWATCH 16 /* R4k Inst. Watch address reference */ +#define T_C2E 18 /* R5k Coprocessor 2 exception */ +#define T_MDMX 22 /* R5k MDMX unusable */ +#define T_DWATCH 23 /* Data Watch address reference */ +#define T_MCHECK 24 /* Machine check */ +#define T_CACHEERR 30 /* Cache error */ +#define T_VCED 31 /* R4k Virtual coherency data */ + +#define T_USER 0x20 /* user-mode flag or'ed with type */ + +/* + * Defines for trap handler catching kernel accessing memory. + */ +#define KT_COPYERR 1 /* User space copy error */ +#define KT_KCOPYERR 2 /* Kernel space copy error */ +#define KT_DDBERR 3 /* DDB access error */ + +#ifndef _LOCORE + +#if defined(DDB) || defined(DEBUG) + +struct trapdebug { /* trap history buffer for debugging */ + register_t status; + register_t cause; + register_t vadr; + register_t pc; + register_t ra; + register_t sp; + u_int code; + u_int ipl; +}; + +#define trapdebug_enter(ci, frame, cd) \ +do { \ + register_t sr = disableintr(); \ + u_long cpuid = ci->ci_cpuid; \ + struct trapdebug *t; \ + \ + t = trapdebug + TRAPSIZE * cpuid + trppos[cpuid]; \ + t->status = frame->sr; \ + t->cause = frame->cause; \ + t->vadr = frame->badvaddr; \ + t->pc = frame->pc; \ + t->sp = frame->sp; \ + t->ra = frame->ra; \ + t->ipl = frame->ipl; \ + t->code = cd; \ + if (++trppos[cpuid] == TRAPSIZE) \ + trppos[cpuid] = 0; \ + setsr(sr); \ +} while (0) + +#define TRAPSIZE 10 /* Trap log buffer length */ +extern struct trapdebug trapdebug[MAXCPUS * TRAPSIZE]; +extern uint trppos[MAXCPUS]; + +void trapDump(const char *, int (*)(const char *, ...)); + +#else +#define trapdebug_enter(ci, frame, code) +#endif +#endif /* _LOCORE */ + +#endif /* !_MIPS64_TRAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/mips64/vmparam.h b/lib/libc/include/generic-openbsd/mips64/vmparam.h new file mode 100644 index 0000000000..64dbaaabb8 --- /dev/null +++ b/lib/libc/include/generic-openbsd/mips64/vmparam.h @@ -0,0 +1,115 @@ +/* $OpenBSD: vmparam.h,v 1.31 2023/11/16 13:47:22 deraadt Exp $ */ +/* $NetBSD: vmparam.h,v 1.5 1994/10/26 21:10:10 cgd Exp $ */ + +/* + * Copyright (c) 1988 University of Utah. + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department and Ralph Campbell. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: Utah Hdr: vmparam.h 1.16 91/01/18 + * @(#)vmparam.h 8.2 (Berkeley) 4/22/94 + */ + +#ifndef _MIPS64_VMPARAM_H_ +#define _MIPS64_VMPARAM_H_ + +/* + * Machine dependent constants mips processors. + */ + +#define USRSTACK VM_MAXUSER_ADDRESS /* Start of user stack */ + +/* + * Virtual memory related constants, all in bytes + */ +#ifndef MAXTSIZ +#define MAXTSIZ (128*1024*1024) /* max text size */ +#endif +#ifndef DFLDSIZ +#define DFLDSIZ (128*1024*1024) /* initial data size limit */ +#endif +#ifndef MAXDSIZ +#define MAXDSIZ (16UL*1024*1024*1024) /* max data size */ +#endif +#ifndef BRKSIZ +#define BRKSIZ MAXDSIZ /* heap gap size */ +#endif +#ifndef DFLSSIZ +#define DFLSSIZ (2*1024*1024) /* initial stack size limit */ +#endif +#ifndef MAXSSIZ +#define MAXSSIZ (32*1024*1024) /* max stack size */ +#endif + +#define STACKGAP_RANDOM 256*1024 + +/* + * PTEs for mapping user space into the kernel for physio operations. + * 16 pte's are enough to cover 8 disks * MAXBSIZE. + */ +#ifndef USRIOSIZE +#define USRIOSIZE 32 +#endif + +/* + * PTEs for system V style shared memory. + * This is basically slop for kmempt which we actually allocate (malloc) from. + */ +#ifndef SHMMAXPGS +#define SHMMAXPGS 8192 /* 8mb */ +#endif + +#ifndef VM_PHYSSEG_MAX +#define VM_PHYSSEG_MAX 8 /* Max number of physical memory segments */ +#endif +#ifndef VM_PHYSSEG_STRAT +#define VM_PHYSSEG_STRAT VM_PSTRAT_BSEARCH +#endif +#define VM_PHYSSEG_NOADD + +/* user/kernel map constants */ +#define VM_MIN_ADDRESS ((vaddr_t)0x0000000000004000L) +#define VM_MAXUSER_ADDRESS ((vaddr_t)0x0000010000000000L) +#define VM_MAX_ADDRESS VM_MAXUSER_ADDRESS +#ifdef _KERNEL +#define VM_MIN_STACK_ADDRESS ((vaddr_t)0x000000c000000000L) +#endif +#define VM_MIN_KERNEL_ADDRESS ((vaddr_t)0xc000000000000000L) +#define VM_MAX_KERNEL_ADDRESS ((vaddr_t)0xc000000040000000L) + +/* map PIE into approximately the first quarter of user va space */ +#define VM_PIE_MIN_ADDR PAGE_SIZE +#define VM_PIE_MAX_ADDR (0x4000000000UL) + +/* virtual sizes (bytes) for various kernel submaps */ +#define VM_PHYS_SIZE (USRIOSIZE*PAGE_SIZE) + +#endif /* !_MIPS64_VMPARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/miscfs/fifofs/fifo.h b/lib/libc/include/generic-openbsd/miscfs/fifofs/fifo.h new file mode 100644 index 0000000000..d6345c63b7 --- /dev/null +++ b/lib/libc/include/generic-openbsd/miscfs/fifofs/fifo.h @@ -0,0 +1,54 @@ +/* $OpenBSD: fifo.h,v 1.24 2022/06/26 05:20:42 visa Exp $ */ +/* $NetBSD: fifo.h,v 1.10 1996/02/09 22:40:15 christos Exp $ */ + +/* + * Copyright (c) 1991, 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. + * + * @(#)fifo.h 8.3 (Berkeley) 8/10/94 + */ +#ifdef FIFO + +/* + * Prototypes for fifo operations on vnodes. + */ +int fifo_ebadf(void *); + +int fifo_open(void *); +int fifo_close(void *); +int fifo_read(void *); +int fifo_write(void *); +int fifo_ioctl(void *); +int fifo_kqfilter(void *); +int fifo_inactive(void *); +int fifo_reclaim(void *); +int fifo_print(void *); +int fifo_pathconf(void *); +int fifo_advlock(void *); + +void fifo_printinfo(struct vnode *); +#endif /* FIFO */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/miscfs/fuse/fusefs.h b/lib/libc/include/generic-openbsd/miscfs/fuse/fusefs.h new file mode 100644 index 0000000000..12210d6f60 --- /dev/null +++ b/lib/libc/include/generic-openbsd/miscfs/fuse/fusefs.h @@ -0,0 +1,85 @@ +/* $OpenBSD: fusefs.h,v 1.15 2025/09/08 17:25:46 helg Exp $ */ +/* + * Copyright (c) 2012-2013 Sylvestre Gallon + * + * 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 __FUSEFS_H__ +#define __FUSEFS_H__ + +/* sysctl defines */ +#define FUSEFS_OPENDEVS 1 /* # of fuse devices opened */ +#define FUSEFS_INFBUFS 2 /* # of in fbufs */ +#define FUSEFS_WAITFBUFS 3 /* # of fbufs waiting for a response */ +#define FUSEFS_POOL_NBPAGES 4 /* # total fusefs size */ +#define FUSEFS_MAXID 5 /* number of valid fusefs ids */ + +#define FUSEFS_NAMES { \ + { 0, 0}, \ + { "fusefs_open_devices", CTLTYPE_INT }, \ + { "fusefs_fbufs_in", CTLTYPE_INT }, \ + { "fusefs_fbufs_wait", CTLTYPE_INT }, \ + { "fusefs_pool_pages", CTLTYPE_INT }, \ +} + +#ifdef _KERNEL + +struct fuse_msg; + +struct fusefs_mnt { + struct mount *mp; + uint32_t undef_op; + int max_read; + int sess_init; + int allow_other; + dev_t dev; +}; + +#define UNDEF_ACCESS 1<<0 +#define UNDEF_MKDIR 1<<1 +#define UNDEF_CREATE 1<<2 +#define UNDEF_LINK 1<<3 +#define UNDEF_READLINK 1<<4 +#define UNDEF_RMDIR 1<<5 +#define UNDEF_REMOVE 1<<6 +#define UNDEF_SETATTR 1<<7 +#define UNDEF_RENAME 1<<8 +#define UNDEF_SYMLINK 1<<9 +#define UNDEF_MKNOD 1<<10 +#define UNDEF_FLUSH 1<<11 +#define UNDEF_FSYNC 1<<12 + +extern const struct vops fusefs_vops; +extern struct pool fusefs_fbuf_pool; + +/* files helpers. */ +int fusefs_file_open(struct fusefs_mnt *, struct fusefs_node *, enum fufh_type, + int, int, struct proc *); +int fusefs_file_close(struct fusefs_mnt *, struct fusefs_node *, + enum fufh_type, int, int, struct proc *); + +/* device helpers. */ +void fuse_device_cleanup(dev_t); +void fuse_device_queue_fbuf(dev_t, struct fusebuf *); +void fuse_device_set_fmp(struct fusefs_mnt *, int); + +/* + * The root inode is the root of the file system. Inode 0 can't be used for + * normal purposes. + */ +#define FUSE_ROOTINO ((ino_t)1) +#define VFSTOFUSEFS(mp) ((struct fusefs_mnt *)((mp)->mnt_data)) + +#endif /* _KERNEL */ +#endif /* __FUSEFS_H__ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/miscfs/fuse/fusefs_node.h b/lib/libc/include/generic-openbsd/miscfs/fuse/fusefs_node.h new file mode 100644 index 0000000000..c63d514470 --- /dev/null +++ b/lib/libc/include/generic-openbsd/miscfs/fuse/fusefs_node.h @@ -0,0 +1,70 @@ +/* $OpenBSD: fusefs_node.h,v 1.5 2024/10/31 13:55:21 claudio Exp $ */ +/* + * Copyright (c) 2012-2013 Sylvestre Gallon + * + * 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 _FUSEFS_NODE_H_ +#define _FUSEFS_NODE_H_ + +#include + +enum fufh_type { + FUFH_INVALID = -1, + FUFH_RDONLY = 0, + FUFH_WRONLY = 1, + FUFH_RDWR = 2, + FUFH_MAXTYPE = 3, +}; + +struct fusefs_filehandle { + uint64_t fh_id; + enum fufh_type fh_type; +}; + +struct fusefs_mnt; +struct fusefs_node { + LIST_ENTRY(fusefs_node) i_hash; /* Hash chain */ + struct vnode *i_vnode;/* Vnode associated with this inode. */ + struct fusefs_mnt *i_ump; + dev_t i_dev; /* Device associated with the inode. */ + ino_t i_number; /* The identity of the inode. */ + struct lockf_state *i_lockf; /* Byte-level lock state. */ + struct rrwlock i_lock; /* Inode lock */ + + /** I/O **/ + struct fusefs_filehandle fufh[FUFH_MAXTYPE]; + + /** meta **/ + off_t filesize; +}; + +#ifdef ITOV +# undef ITOV +#endif +#define ITOV(ip) ((ip)->i_vnode) + +#ifdef VTOI +# undef VTOI +#endif +#define VTOI(vp) ((struct fusefs_node *)(vp)->v_data) + +void fuse_ihashinit(void); +struct vnode *fuse_ihashget(dev_t, ino_t); +int fuse_ihashins(struct fusefs_node *); +void fuse_ihashrem(struct fusefs_node *); + +uint64_t fusefs_fd_get(struct fusefs_node *, enum fufh_type); + +#endif /* _FUSEFS_NODE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/msdosfs/bootsect.h b/lib/libc/include/generic-openbsd/msdosfs/bootsect.h new file mode 100644 index 0000000000..c820702684 --- /dev/null +++ b/lib/libc/include/generic-openbsd/msdosfs/bootsect.h @@ -0,0 +1,97 @@ +/* $OpenBSD: bootsect.h,v 1.8 2025/08/01 13:00:18 jsg Exp $ */ +/* $NetBSD: bootsect.h,v 1.8 1997/10/17 11:23:29 ws Exp $ */ + +/* + * Written by Paul Popelka (paulp@uts.amdahl.com) + * + * You can do anything you want with this software, just don't say you wrote + * it, and don't remove this notice. + * + * This software is provided "as is". + * + * The author supplies this software to be publicly redistributed on the + * understanding that the author is not responsible for the correct + * functioning of this software in any circumstances and is not liable for + * any damages caused by this software. + * + * October 1992 + */ + +/* + * Format of a boot sector. This is the first sector on a DOS floppy disk + * or the first sector of a partition on a hard disk. But, it is not the + * first sector of a partitioned hard disk. + */ +struct bootsector33 { + u_int8_t bsJump[3]; /* jump inst E9xxxx or EBxx90 */ + int8_t bsOemName[8]; /* OEM name and version */ + int8_t bsBPB[19]; /* BIOS parameter block */ + int8_t bsDriveNumber; /* drive number (0x80) */ + int8_t bsBootCode[479]; /* pad so struct is 512b */ + u_int8_t bsBootSectSig0; + u_int8_t bsBootSectSig1; +#define BOOTSIG0 0x55 +#define BOOTSIG1 0xaa +}; + +struct extboot { + int8_t exDriveNumber; /* drive number (0x80) */ + int8_t exReserved1; /* reserved */ + int8_t exBootSignature; /* ext. boot signature (0x29) */ +#define EXBOOTSIG 0x29 + int8_t exVolumeID[4]; /* volume ID number */ + int8_t exVolumeLabel[11]; /* volume label */ + int8_t exFileSysType[8]; /* fs type (FAT12 or FAT16) */ +}; + +struct bootsector50 { + u_int8_t bsJump[3]; /* jump inst E9xxxx or EBxx90 */ + int8_t bsOemName[8]; /* OEM name and version */ + int8_t bsBPB[25]; /* BIOS parameter block */ + int8_t bsExt[26]; /* Bootsector Extension */ + int8_t bsBootCode[448]; /* pad so structure is 512b */ + u_int8_t bsBootSectSig0; + u_int8_t bsBootSectSig1; +#define BOOTSIG0 0x55 +#define BOOTSIG1 0xaa +}; + +struct bootsector710 { + u_int8_t bsJump[3]; /* jump inst E9xxxx or EBxx90 */ + int8_t bsOEMName[8]; /* OEM name and version */ + int8_t bsBPB[53]; /* BIOS parameter block */ + int8_t bsExt[26]; /* Bootsector Extension */ + int8_t bsBootCode[418]; /* pad so structure is 512b */ + u_int8_t bsBootSectSig2; /* 2 & 3 are only defined for FAT32? */ + u_int8_t bsBootSectSig3; + u_int8_t bsBootSectSig0; + u_int8_t bsBootSectSig1; +#define BOOTSIG0 0x55 +#define BOOTSIG1 0xaa +#define BOOTSIG2 0 +#define BOOTSIG3 0 +}; + +union bootsector { + struct bootsector33 bs33; + struct bootsector50 bs50; + struct bootsector710 bs710; +}; + +#if 0 +/* + * Shorthand for fields in the bpb. + */ +#define bsBytesPerSec bsBPB.bpbBytesPerSec +#define bsSectPerClust bsBPB.bpbSectPerClust +#define bsResSectors bsBPB.bpbResSectors +#define bsFATS bsBPB.bpbFATS +#define bsRootDirEnts bsBPB.bpbRootDirEnts +#define bsSectors bsBPB.bpbSectors +#define bsMedia bsBPB.bpbMedia +#define bsFATsecs bsBPB.bpbFATsecs +#define bsSectPerTrack bsBPB.bpbSectPerTrack +#define bsHeads bsBPB.bpbHeads +#define bsHiddenSecs bsBPB.bpbHiddenSecs +#define bsHugeSectors bsBPB.bpbHugeSectors +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/msdosfs/bpb.h b/lib/libc/include/generic-openbsd/msdosfs/bpb.h new file mode 100644 index 0000000000..b97d271154 --- /dev/null +++ b/lib/libc/include/generic-openbsd/msdosfs/bpb.h @@ -0,0 +1,187 @@ +/* $OpenBSD: bpb.h,v 1.7 2015/10/23 10:45:31 krw Exp $ */ +/* $NetBSD: bpb.h,v 1.6 1997/10/17 11:23:35 ws Exp $ */ + +/* + * Written by Paul Popelka (paulp@uts.amdahl.com) + * + * You can do anything you want with this software, just don't say you wrote + * it, and don't remove this notice. + * + * This software is provided "as is". + * + * The author supplies this software to be publicly redistributed on the + * understanding that the author is not responsible for the correct + * functioning of this software in any circumstances and is not liable for + * any damages caused by this software. + * + * October 1992 + */ + +/* + * BIOS Parameter Block (BPB) for DOS 3.3 + */ +struct bpb33 { + u_int16_t bpbBytesPerSec; /* bytes per sector */ + u_int8_t bpbSecPerClust; /* sectors per cluster */ + u_int16_t bpbResSectors; /* number of reserved sectors */ + u_int8_t bpbFATs; /* number of FATs */ + u_int16_t bpbRootDirEnts; /* number of root directory entries */ + u_int16_t bpbSectors; /* total number of sectors */ + u_int8_t bpbMedia; /* media descriptor */ + u_int16_t bpbFATsecs; /* number of sectors per FAT */ + u_int16_t bpbSecPerTrack; /* sectors per track */ + u_int16_t bpbHeads; /* number of heads */ + u_int16_t bpbHiddenSecs; /* number of hidden sectors */ +}; + +/* + * BPB for DOS 5.0 The difference is bpbHiddenSecs is a short for DOS 3.3, + * and bpbHugeSectors is not in the 3.3 bpb. + */ +struct bpb50 { + u_int16_t bpbBytesPerSec; /* bytes per sector */ + u_int8_t bpbSecPerClust; /* sectors per cluster */ + u_int16_t bpbResSectors; /* number of reserved sectors */ + u_int8_t bpbFATs; /* number of FATs */ + u_int16_t bpbRootDirEnts; /* number of root directory entries */ + u_int16_t bpbSectors; /* total number of sectors */ + u_int8_t bpbMedia; /* media descriptor */ + u_int16_t bpbFATsecs; /* number of sectors per FAT */ + u_int16_t bpbSecPerTrack; /* sectors per track */ + u_int16_t bpbHeads; /* number of heads */ + u_int32_t bpbHiddenSecs; /* # of hidden sectors */ + u_int32_t bpbHugeSectors; /* # of sectors if bpbSectors == 0 */ +}; + +/* + * BPB for DOS 7.10 (FAT32). This one has a few extensions to bpb50. + */ +struct bpb710 { + u_int16_t bpbBytesPerSec; /* bytes per sector */ + u_int8_t bpbSecPerClust; /* sectors per cluster */ + u_int16_t bpbResSectors; /* number of reserved sectors */ + u_int8_t bpbFATs; /* number of FATs */ + u_int16_t bpbRootDirEnts; /* number of root directory entries */ + u_int16_t bpbSectors; /* total number of sectors */ + u_int8_t bpbMedia; /* media descriptor */ + u_int16_t bpbFATsecs; /* number of sectors per FAT */ + u_int16_t bpbSecPerTrack; /* sectors per track */ + u_int16_t bpbHeads; /* number of heads */ + u_int32_t bpbHiddenSecs; /* # of hidden sectors */ + u_int32_t bpbHugeSectors; /* # of sectors if bpbSectors == 0 */ + u_int32_t bpbBigFATsecs; /* like bpbFATsecs for FAT32 */ + u_int16_t bpbExtFlags; /* extended flags: */ +#define FATNUM 0xf /* mask for numbering active FAT */ +#define FATMIRROR 0x80 /* FAT is mirrored (like it always was) */ + u_int16_t bpbFSVers; /* filesystem version */ +#define FSVERS 0 /* currently only 0 is understood */ + u_int32_t bpbRootClust; /* start cluster for root directory */ + u_int16_t bpbFSInfo; /* filesystem info structure sector */ + u_int16_t bpbBackup; /* backup boot sector */ + /* There is a 12 byte filler here, but we ignore it */ +}; + +/* + * The following structures represent how the bpb's look on disk. shorts + * and longs are just character arrays of the appropriate length. This is + * because the compiler forces shorts and longs to align on word or + * halfword boundaries. + * + * XXX The little-endian code here assumes that the processor can access + * 16-bit and 32-bit quantities on byte boundaries. If this is not true, + * use the macros for the big-endian case. + */ +#include +#if (BYTE_ORDER == LITTLE_ENDIAN) && !defined(__STRICT_ALIGNMENT) +#define getushort(x) *((u_int16_t *)(x)) +#define getulong(x) *((u_int32_t *)(x)) +#define putushort(p, v) (*((u_int16_t *)(p)) = (v)) +#define putulong(p, v) (*((u_int32_t *)(p)) = (v)) +#else +#define getushort(x) (((u_int8_t *)(x))[0] + (((u_int8_t *)(x))[1] << 8)) +#define getulong(x) (((u_int8_t *)(x))[0] + (((u_int8_t *)(x))[1] << 8) \ + + (((u_int8_t *)(x))[2] << 16) \ + + (((u_int8_t *)(x))[3] << 24)) +#define putushort(p, v) (((u_int8_t *)(p))[0] = (v), \ + ((u_int8_t *)(p))[1] = (v) >> 8) +#define putulong(p, v) (((u_int8_t *)(p))[0] = (v), \ + ((u_int8_t *)(p))[1] = (v) >> 8, \ + ((u_int8_t *)(p))[2] = (v) >> 16,\ + ((u_int8_t *)(p))[3] = (v) >> 24) +#endif + +/* + * BIOS Parameter Block (BPB) for DOS 3.3 + */ +struct byte_bpb33 { + int8_t bpbBytesPerSec[2]; /* bytes per sector */ + int8_t bpbSecPerClust; /* sectors per cluster */ + int8_t bpbResSectors[2]; /* number of reserved sectors */ + int8_t bpbFATs; /* number of FATs */ + int8_t bpbRootDirEnts[2]; /* number of root directory entries */ + int8_t bpbSectors[2]; /* total number of sectors */ + int8_t bpbMedia; /* media descriptor */ + int8_t bpbFATsecs[2]; /* number of sectors per FAT */ + int8_t bpbSecPerTrack[2]; /* sectors per track */ + int8_t bpbHeads[2]; /* number of heads */ + int8_t bpbHiddenSecs[2]; /* number of hidden sectors */ +}; + +/* + * BPB for DOS 5.0 The difference is bpbHiddenSecs is a short for DOS 3.3, + * and bpbHugeSectors is not in the 3.3 bpb. + */ +struct byte_bpb50 { + int8_t bpbBytesPerSec[2]; /* bytes per sector */ + int8_t bpbSecPerClust; /* sectors per cluster */ + int8_t bpbResSectors[2]; /* number of reserved sectors */ + int8_t bpbFATs; /* number of FATs */ + int8_t bpbRootDirEnts[2]; /* number of root directory entries */ + int8_t bpbSectors[2]; /* total number of sectors */ + int8_t bpbMedia; /* media descriptor */ + int8_t bpbFATsecs[2]; /* number of sectors per FAT */ + int8_t bpbSecPerTrack[2]; /* sectors per track */ + int8_t bpbHeads[2]; /* number of heads */ + int8_t bpbHiddenSecs[4]; /* number of hidden sectors */ + int8_t bpbHugeSectors[4]; /* # of sectors if bpbSectors == 0 */ +}; + +/* + * BPB for DOS 7.10 (FAT32). This one has a few extensions to bpb50. + */ +struct byte_bpb710 { + u_int8_t bpbBytesPerSec[2]; /* bytes per sector */ + u_int8_t bpbSecPerClust; /* sectors per cluster */ + u_int8_t bpbResSectors[2]; /* number of reserved sectors */ + u_int8_t bpbFATs; /* number of FATs */ + u_int8_t bpbRootDirEnts[2]; /* number of root directory entries */ + u_int8_t bpbSectors[2]; /* total number of sectors */ + u_int8_t bpbMedia; /* media descriptor */ + u_int8_t bpbFATsecs[2]; /* number of sectors per FAT */ + u_int8_t bpbSecPerTrack[2]; /* sectors per track */ + u_int8_t bpbHeads[2]; /* number of heads */ + u_int8_t bpbHiddenSecs[4]; /* # of hidden sectors */ + u_int8_t bpbHugeSectors[4]; /* # of sectors if bpbSectors == 0 */ + u_int8_t bpbBigFATsecs[4]; /* like bpbFATsecs for FAT32 */ + u_int8_t bpbExtFlags[2]; /* extended flags: */ + u_int8_t bpbFSVers[2]; /* filesystem version */ + u_int8_t bpbRootClust[4]; /* start cluster for root directory */ + u_int8_t bpbFSInfo[2]; /* filesystem info structure sector */ + u_int8_t bpbBackup[2]; /* backup boot sector */ + /* There is a 12 byte filler here, but we ignore it */ +}; + +/* + * FAT32 FSInfo block. + */ +struct fsinfo { + u_int8_t fsisig1[4]; + u_int8_t fsifill1[480]; + u_int8_t fsisig2[4]; + u_int8_t fsinfree[4]; + u_int8_t fsinxtfree[4]; + u_int8_t fsifill2[12]; + u_int8_t fsisig3[4]; + u_int8_t fsifill3[508]; + u_int8_t fsisig4[4]; +}; \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/msdosfs/denode.h b/lib/libc/include/generic-openbsd/msdosfs/denode.h new file mode 100644 index 0000000000..9c9d548203 --- /dev/null +++ b/lib/libc/include/generic-openbsd/msdosfs/denode.h @@ -0,0 +1,309 @@ +/* $OpenBSD: denode.h,v 1.36 2022/08/15 01:47:09 jsg Exp $ */ +/* $NetBSD: denode.h,v 1.24 1997/10/17 11:23:39 ws Exp $ */ + +/*- + * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank. + * Copyright (C) 1994, 1995, 1997 TooLs GmbH. + * All rights reserved. + * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below). + * + * 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. + */ +/* + * Written by Paul Popelka (paulp@uts.amdahl.com) + * + * You can do anything you want with this software, just don't say you wrote + * it, and don't remove this notice. + * + * This software is provided "as is". + * + * The author supplies this software to be publicly redistributed on the + * understanding that the author is not responsible for the correct + * functioning of this software in any circumstances and is not liable for + * any damages caused by this software. + * + * October 1992 + */ + +/* + * This is the pc filesystem specific portion of the vnode structure. + * + * To describe a file uniquely the de_dirclust, de_diroffset, and + * de_StartCluster fields are used. + * + * de_dirclust contains the cluster number of the directory cluster + * containing the entry for a file or directory. + * de_diroffset is the index into the cluster for the entry describing + * a file or directory. + * de_StartCluster is the number of the first cluster of the file or directory. + * + * Now to describe the quirks of the pc filesystem. + * - Clusters 0 and 1 are reserved. + * - The first allocatable cluster is 2. + * - The root directory is of fixed size and all blocks that make it up + * are contiguous. + * - Cluster 0 refers to the root directory when it is found in the + * startcluster field of a directory entry that points to another directory. + * - Cluster 0 implies a 0 length file when found in the start cluster field + * of a directory entry that points to a file. + * - You can't use the cluster number 0 to derive the address of the root + * directory. + * - Multiple directory entries can point to a directory. The entry in the + * parent directory points to a child directory. Any directories in the + * child directory contain a ".." entry that points back to the parent. + * The child directory itself contains a "." entry that points to itself. + * - The root directory does not contain a "." or ".." entry. + * - Directory entries for directories are never changed once they are created + * (except when removed). The size stays 0, and the last modification time + * is never changed. This is because so many directory entries can point to + * the physical clusters that make up a directory. It would lead to an + * update nightmare. + * - The length field in a directory entry pointing to a directory contains 0 + * (always). The only way to find the end of a directory is to follow the + * cluster chain until the "last cluster" marker is found. + * + * My extensions to make this house of cards work. These apply only to the in + * memory copy of the directory entry. + * - A reference count for each denode will be kept since dos doesn't keep such + * things. + */ + +/* + * Internal pseudo-offset for (nonexistent) directory entry for the root + * dir in the root dir + */ +#define MSDOSFSROOT_OFS 0x1fffffff + +/* + * The fat cache structure. fc_fsrcn is the filesystem relative cluster + * number that corresponds to the file relative cluster number in this + * structure (fc_frcn). + */ +struct fatcache { + uint32_t fc_frcn; /* file relative cluster number */ + uint32_t fc_fsrcn; /* filesystem relative cluster number */ +}; + +/* + * The fat entry cache as it stands helps make extending files a "quick" + * operation by avoiding having to scan the fat to discover the last + * cluster of the file. The cache also helps sequential reads by + * remembering the last cluster read from the file. This also prevents us + * from having to rescan the fat to find the next cluster to read. This + * cache is probably pretty worthless if a file is opened by multiple + * processes. + */ +#define FC_SIZE 3 /* number of entries in the cache */ +#define FC_LASTMAP 0 /* entry the last call to pcbmap() resolved + * to */ +#define FC_LASTFC 1 /* entry for the last cluster in the file */ +#define FC_OLASTFC 2 /* entry for the previous last cluster */ + +#define FCE_EMPTY 0xffffffff /* doesn't represent an actual cluster # */ + +/* + * Set a slot in the fat cache. + */ +#define fc_setcache(dep, slot, frcn, fsrcn) \ + (dep)->de_fc[slot].fc_frcn = frcn; \ + (dep)->de_fc[slot].fc_fsrcn = fsrcn; + +/* + * This is the in memory variant of a dos directory entry. It is usually + * contained within a vnode. + */ +struct denode { + struct denode *de_next; /* Hash chain forward */ + struct denode **de_prev; /* Hash chain back */ + struct vnode *de_vnode; /* addr of vnode we are part of */ + struct vnode *de_devvp; /* vnode of blk dev we live on */ + uint32_t de_flag; /* flag bits */ + dev_t de_dev; /* device where direntry lives */ + uint32_t de_dirclust; /* cluster of the directory file containing this entry */ + uint32_t de_diroffset; /* offset of this entry in the directory cluster */ + uint32_t de_fndoffset; /* offset of found dir entry */ + int de_fndcnt; /* number of slots before de_fndoffset */ + long de_refcnt; /* reference count */ + struct msdosfsmount *de_pmp; /* addr of our mount struct */ + struct lockf_state *de_lockf; /* byte level lock list */ + struct rrwlock de_lock; /* denode lock */ + u_char de_Name[11]; /* name, from DOS directory entry */ + u_char de_Attributes; /* attributes, from directory entry */ + u_char de_CTimeHundredth; /* creation time, 1/100th of a sec */ + u_short de_CTime; /* creation time */ + u_short de_CDate; /* creation date */ + u_short de_ADate; /* access date */ + u_short de_MTime; /* modification time */ + u_short de_MDate; /* modification date */ + uint32_t de_StartCluster; /* starting cluster of file */ + uint32_t de_FileSize; /* size of file in bytes */ + struct fatcache de_fc[FC_SIZE]; /* fat cache */ +}; + +/* + * Values for the de_flag field of the denode. + */ +#define DE_UPDATE 0x0004 /* Modification time update request. */ +#define DE_CREATE 0x0008 /* Creation time update */ +#define DE_ACCESS 0x0010 /* Access time update */ +#define DE_MODIFIED 0x0020 /* Denode has been modified. */ +#define DE_RENAME 0x0040 /* Denode is in the process of being renamed */ + +/* + * Maximum filename length in Win95 + * Note: Must be < sizeof(dirent.d_name) + */ +#define WIN_MAXLEN 255 + +/* Maximum size of a file on a FAT filesystem */ +#define MSDOSFS_FILESIZE_MAX 0xFFFFFFFFLL + +/* + * Transfer directory entries between internal and external form. + * dep is a struct denode * (internal form), + * dp is a struct direntry * (external form). + */ +#define DE_INTERNALIZE32(dep, dp) \ + ((dep)->de_StartCluster |= getushort((dp)->deHighClust) << 16) +#define DE_INTERNALIZE(dep, dp) \ + (bcopy((dp)->deName, (dep)->de_Name, 8), \ + bcopy((dp)->deExtension, (dep)->de_Name + 8, 3), \ + (dep)->de_Attributes = (dp)->deAttributes, \ + (dep)->de_CTimeHundredth = (dp)->deCTimeHundredth, \ + (dep)->de_CTime = getushort((dp)->deCTime), \ + (dep)->de_CDate = getushort((dp)->deCDate), \ + (dep)->de_ADate = getushort((dp)->deADate), \ + (dep)->de_MTime = getushort((dp)->deMTime), \ + (dep)->de_MDate = getushort((dp)->deMDate), \ + (dep)->de_StartCluster = getushort((dp)->deStartCluster), \ + (dep)->de_FileSize = getulong((dp)->deFileSize), \ + (FAT32((dep)->de_pmp) ? DE_INTERNALIZE32((dep), (dp)) : 0)) + +#define DE_EXTERNALIZE(dp, dep) \ + (bcopy((dep)->de_Name, (dp)->deName, 8), \ + bcopy((dep)->de_Name + 8, (dp)->deExtension, 3), \ + (dp)->deAttributes = (dep)->de_Attributes, \ + (dp)->deLowerCase = CASE_LOWER_BASE | CASE_LOWER_EXT, \ + (dp)->deCTimeHundredth = (dep)->de_CTimeHundredth, \ + putushort((dp)->deCTime, (dep)->de_CTime), \ + putushort((dp)->deCDate, (dep)->de_CDate), \ + putushort((dp)->deADate, (dep)->de_ADate), \ + putushort((dp)->deMTime, (dep)->de_MTime), \ + putushort((dp)->deMDate, (dep)->de_MDate), \ + putushort((dp)->deStartCluster, (dep)->de_StartCluster), \ + putulong((dp)->deFileSize, \ + ((dep)->de_Attributes & ATTR_DIRECTORY) ? 0 : (dep)->de_FileSize),\ + putushort((dp)->deHighClust, \ + FAT32((dep)->de_pmp) ? (dep)->de_StartCluster >> 16 : 0)) + +#define de_forw de_chain[0] +#define de_back de_chain[1] + +#define VTODE(vp) ((struct denode *)(vp)->v_data) +#define DETOV(de) ((de)->de_vnode) + +#define DETIMES(dep, acc, mod, cre) \ + if ((dep)->de_flag & (DE_UPDATE | DE_CREATE | DE_ACCESS)) { \ + (dep)->de_flag |= DE_MODIFIED; \ + if ((dep)->de_flag & DE_UPDATE) { \ + unix2dostime((mod), &(dep)->de_MDate, &(dep)->de_MTime, NULL); \ + (dep)->de_Attributes |= ATTR_ARCHIVE; \ + } \ + if (!((dep)->de_pmp->pm_flags & MSDOSFSMNT_NOWIN95)) { \ + if ((dep)->de_flag & DE_ACCESS) \ + unix2dostime((acc), &(dep)->de_ADate, NULL, NULL); \ + if ((dep)->de_flag & DE_CREATE) \ + unix2dostime((cre), &(dep)->de_CDate, &(dep)->de_CTime, &(dep)->de_CTimeHundredth); \ + } \ + (dep)->de_flag &= ~(DE_UPDATE | DE_CREATE | DE_ACCESS); \ + } + +/* + * This overlays the fid structure (see mount.h) + */ +struct defid { + u_short defid_len; /* length of structure */ + u_short defid_pad; /* force long alignment */ + + uint32_t defid_dirclust; /* cluster this dir entry came from */ + uint32_t defid_dirofs; /* offset of entry within the cluster */ +#if 0 + uint32_t defid_gen; /* generation number */ +#endif +}; + + +#ifdef _KERNEL +/* + * Prototypes for MSDOSFS vnode operations + */ +int msdosfs_lookup(void *); +int msdosfs_create(void *); +int msdosfs_mknod(void *); +int msdosfs_open(void *); +int msdosfs_close(void *); +int msdosfs_access(void *); +int msdosfs_getattr(void *); +int msdosfs_setattr(void *); +int msdosfs_read(void *); +int msdosfs_write(void *); +int msdosfs_ioctl(void *); +int msdosfs_fsync(void *); +int msdosfs_remove(void *); +int msdosfs_link(void *); +int msdosfs_rename(void *); +int msdosfs_mkdir(void *); +int msdosfs_rmdir(void *); +int msdosfs_symlink(void *); +int msdosfs_readdir(void *); +int msdosfs_readlink(void *); +int msdosfs_inactive(void *); +int msdosfs_reclaim(void *); +int msdosfs_lock(void *); +int msdosfs_unlock(void *); +int msdosfs_bmap(void *); +int msdosfs_strategy(void *); +int msdosfs_print(void *); +int msdosfs_islocked(void *); +int msdosfs_advlock(void *); +int msdosfs_pathconf(void *); + +/* + * Internal service routine prototypes. + */ +int createde(struct denode *, struct denode *, struct denode **, struct componentname *); +int deextend(struct denode *, uint32_t, struct ucred *); +int deget(struct msdosfsmount *, uint32_t, uint32_t, struct denode **); +int detrunc(struct denode *, uint32_t, int, struct ucred *, struct proc *); +int deupdat(struct denode *, int); +int doscheckpath(struct denode *, struct denode *); +int dosdirempty(struct denode *); +int readde(struct denode *, struct buf **, struct direntry **); +int readep(struct msdosfsmount *, uint32_t, uint32_t, struct buf **, struct direntry **); +void reinsert(struct denode *); +int removede(struct denode *, struct denode *); +int uniqdosname(struct denode *, struct componentname *, u_char *); +#endif /* _KERNEL */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/msdosfs/direntry.h b/lib/libc/include/generic-openbsd/msdosfs/direntry.h new file mode 100644 index 0000000000..628bffa15f --- /dev/null +++ b/lib/libc/include/generic-openbsd/msdosfs/direntry.h @@ -0,0 +1,134 @@ +/* $OpenBSD: direntry.h,v 1.8 2021/12/23 02:12:52 jsg Exp $ */ +/* $NetBSD: direntry.h,v 1.13 1997/10/17 11:23:45 ws Exp $ */ + +/*- + * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank. + * Copyright (C) 1994, 1995, 1997 TooLs GmbH. + * All rights reserved. + * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below). + * + * 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. + */ +/* + * Written by Paul Popelka (paulp@uts.amdahl.com) + * + * You can do anything you want with this software, just don't say you wrote + * it, and don't remove this notice. + * + * This software is provided "as is". + * + * The author supplies this software to be publicly redistributed on the + * understanding that the author is not responsible for the correct + * functioning of this software in any circumstances and is not liable for + * any damages caused by this software. + * + * October 1992 + */ + +/* + * Structure of a dos directory entry. + */ +struct direntry { + u_int8_t deName[8]; /* filename, blank filled */ +#define SLOT_EMPTY 0x00 /* slot has never been used */ +#define SLOT_E5 0x05 /* the real value is 0xe5 */ +#define SLOT_DELETED 0xe5 /* file in this slot deleted */ + u_int8_t deExtension[3]; /* extension, blank filled */ + u_int8_t deAttributes; /* file attributes */ +#define ATTR_NORMAL 0x00 /* normal file */ +#define ATTR_READONLY 0x01 /* file is readonly */ +#define ATTR_HIDDEN 0x02 /* file is hidden */ +#define ATTR_SYSTEM 0x04 /* file is a system file */ +#define ATTR_VOLUME 0x08 /* entry is a volume label */ +#define ATTR_DIRECTORY 0x10 /* entry is a directory name */ +#define ATTR_ARCHIVE 0x20 /* file is new or modified */ + u_int8_t deLowerCase; /* case for base and extension */ +#define CASE_LOWER_BASE 0x08 /* base is lower case */ +#define CASE_LOWER_EXT 0x10 /* extension is lower case */ + u_int8_t deCTimeHundredth; /* create time, 1/100th of a sec */ + u_int8_t deCTime[2]; /* create time */ + u_int8_t deCDate[2]; /* create date */ + u_int8_t deADate[2]; /* access date */ + u_int8_t deHighClust[2]; /* high byte of cluster number */ + u_int8_t deMTime[2]; /* last update time */ + u_int8_t deMDate[2]; /* last update date */ + u_int8_t deStartCluster[2]; /* starting cluster of file */ + u_int8_t deFileSize[4]; /* size of file in bytes */ +}; + +/* + * Structure of a Win95 long name directory entry + */ +struct winentry { + u_int8_t weCnt; +#define WIN_LAST 0x40 +#define WIN_CNT 0x3f + u_int8_t wePart1[10]; + u_int8_t weAttributes; +#define ATTR_WIN95 0x0f + u_int8_t weReserved1; + u_int8_t weChksum; + u_int8_t wePart2[12]; + u_int16_t weReserved2; + u_int8_t wePart3[4]; +}; +#define WIN_CHARS 13 /* Number of chars per winentry */ + +/* + * This is the format of the contents of the deTime field in the direntry + * structure. + * We don't use bitfields because we don't know how compilers for + * arbitrary machines will lay them out. + */ +#define DT_2SECONDS_MASK 0x1F /* seconds divided by 2 */ +#define DT_2SECONDS_SHIFT 0 +#define DT_MINUTES_MASK 0x7E0 /* minutes */ +#define DT_MINUTES_SHIFT 5 +#define DT_HOURS_MASK 0xF800 /* hours */ +#define DT_HOURS_SHIFT 11 + +/* + * This is the format of the contents of the deDate field in the direntry + * structure. + */ +#define DD_DAY_MASK 0x1F /* day of month */ +#define DD_DAY_SHIFT 0 +#define DD_MONTH_MASK 0x1E0 /* month */ +#define DD_MONTH_SHIFT 5 +#define DD_YEAR_MASK 0xFE00 /* year - 1980 */ +#define DD_YEAR_SHIFT 9 + +#ifdef _KERNEL +void unix2dostime(struct timespec *tsp, u_int16_t *ddp, u_int16_t *dtp, u_int8_t *dhp); +void dos2unixtime(u_int dd, u_int dt, u_int dh, struct timespec *tsp); +int dos2unixfn(u_char dn[11], u_char *un, int lower); +int unix2dosfn(u_char *un, u_char dn[11], int unlen, u_int gen); +int unix2winfn(u_char *un, int unlen, struct winentry *wep, int cnt, int chksum); +int winChkName(u_char *un, int unlen, struct winentry *wep, int chksum); +int win2unixfn(struct winentry *wep, struct dirent *dp, int chksum); +u_int8_t winChksum(u_int8_t *name); +int winSlotCnt(u_char *un, int unlen); +#endif /* _KERNEL */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/msdosfs/fat.h b/lib/libc/include/generic-openbsd/msdosfs/fat.h new file mode 100644 index 0000000000..08ee18a5cb --- /dev/null +++ b/lib/libc/include/generic-openbsd/msdosfs/fat.h @@ -0,0 +1,105 @@ +/* $OpenBSD: fat.h,v 1.13 2021/07/11 04:34:13 jsg Exp $ */ +/* $NetBSD: fat.h,v 1.11 1997/10/17 11:23:49 ws Exp $ */ + +/*- + * Copyright (C) 1994, 1997 Wolfgang Solfrank. + * Copyright (C) 1994, 1997 TooLs GmbH. + * All rights reserved. + * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below). + * + * 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. + */ +/* + * Written by Paul Popelka (paulp@uts.amdahl.com) + * + * You can do anything you want with this software, just don't say you wrote + * it, and don't remove this notice. + * + * This software is provided "as is". + * + * The author supplies this software to be publicly redistributed on the + * understanding that the author is not responsible for the correct + * functioning of this software in any circumstances and is not liable for + * any damages caused by this software. + * + * October 1992 + */ + +/* + * Some useful cluster numbers. + */ +#define MSDOSFSROOT 0 /* cluster 0 means the root dir */ +#define CLUST_FREE 0 /* cluster 0 also means a free cluster */ +#define MSDOSFSFREE CLUST_FREE +#define CLUST_FIRST 2 /* first legal cluster number */ +#define CLUST_RSRVD 0xfffffff6 /* reserved cluster range */ +#define CLUST_BAD 0xfffffff7 /* a cluster with a defect */ +#define CLUST_EOFS 0xfffffff8 /* start of eof cluster range */ +#define CLUST_EOFE 0xffffffff /* end of eof cluster range */ +#define CLUST_END CLUST_EOFE /* bigger than any valid cluster */ + +#define FAT12_MASK 0x00000fff /* mask for 12 bit cluster numbers */ +#define FAT16_MASK 0x0000ffff /* mask for 16 bit cluster numbers */ +#define FAT32_MASK 0x0fffffff /* mask for FAT32 cluster numbers */ + +/* + * MSDOSFS: + * Return true if filesystem uses 12 bit fats. Microsoft Programmer's + * Reference says if the maximum cluster number in a filesystem is greater + * than 4084 ((CLUST_RSRVD - CLUST_FIRST) & FAT12_MASK) then we've got a + * 16 bit fat filesystem. While mounting, the result of this test is stored + * in pm_fatentrysize. + */ +#define FAT12(pmp) (pmp->pm_fatmask == FAT12_MASK) +#define FAT16(pmp) (pmp->pm_fatmask == FAT16_MASK) +#define FAT32(pmp) (pmp->pm_fatmask == FAT32_MASK) + +#define MSDOSFSEOF(pmp, cn) ((((cn) | ~(pmp)->pm_fatmask) & CLUST_EOFS) == CLUST_EOFS) + +#ifdef _KERNEL +/* + * These are the values for the function argument to the function + * fatentry(). + */ +#define FAT_GET 0x0001 /* get a fat entry */ +#define FAT_SET 0x0002 /* set a fat entry */ +#define FAT_GET_AND_SET (FAT_GET | FAT_SET) + +/* + * Flags to extendfile: + */ +#define DE_CLEAR 1 /* Zero out the blocks allocated */ + +int pcbmap(struct denode *, uint32_t, daddr_t *, uint32_t *, int *); +int clusterfree(struct msdosfsmount *, uint32_t, uint32_t *); +int clusteralloc(struct msdosfsmount *, uint32_t, uint32_t, uint32_t *, uint32_t *); +int extendfile(struct denode *, uint32_t, struct buf **, uint32_t *, int); +int fatentry(int, struct msdosfsmount *, uint32_t, uint32_t *, uint32_t); +void fc_purge(struct denode *, u_int); +void fc_lookup(struct denode *, uint32_t, uint32_t *, uint32_t *); +int fillinusemap(struct msdosfsmount *); +int freeclusterchain(struct msdosfsmount *, uint32_t); +#endif /* _KERNEL */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/msdosfs/msdosfsmount.h b/lib/libc/include/generic-openbsd/msdosfs/msdosfsmount.h new file mode 100644 index 0000000000..245ef0d471 --- /dev/null +++ b/lib/libc/include/generic-openbsd/msdosfs/msdosfsmount.h @@ -0,0 +1,211 @@ +/* $OpenBSD: msdosfsmount.h,v 1.23 2024/05/13 01:15:53 jsg Exp $ */ +/* $NetBSD: msdosfsmount.h,v 1.16 1997/10/17 11:24:24 ws Exp $ */ + +/*- + * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank. + * Copyright (C) 1994, 1995, 1997 TooLs GmbH. + * All rights reserved. + * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below). + * + * 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. + */ +/* + * Written by Paul Popelka (paulp@uts.amdahl.com) + * + * You can do anything you want with this software, just don't say you wrote + * it, and don't remove this notice. + * + * This software is provided "as is". + * + * The author supplies this software to be publicly redistributed on the + * understanding that the author is not responsible for the correct + * functioning of this software in any circumstances and is not liable for + * any damages caused by this software. + * + * October 1992 + */ + +/* + * Layout of the mount control block for a msdos file system. + */ +struct msdosfsmount { + struct mount *pm_mountp;/* vfs mount struct for this fs */ + dev_t pm_dev; /* block special device mounted */ + uid_t pm_uid; /* uid to set as owner of the files */ + gid_t pm_gid; /* gid to set as owner of the files */ + mode_t pm_mask; /* mask to and with file protection bits */ + struct vnode *pm_devvp; /* vnode for block device mntd */ + struct bpb50 pm_bpb; /* BIOS parameter blk for this fs */ + uint32_t pm_BlkPerSec; /* # of DEV_BSIZE blocks in MSDOSFS sector */ + uint32_t pm_FATsecs; /* actual number of fat sectors */ + uint32_t pm_fatblk; /* block # of first FAT */ + uint32_t pm_rootdirblk; /* block # (cluster # for FAT32) of root directory number */ + uint32_t pm_rootdirsize; /* size in blocks (not clusters) */ + uint32_t pm_firstcluster; /* block number of first cluster */ + uint32_t pm_nmbrofclusters; /* # of clusters in filesystem */ + uint32_t pm_maxcluster; /* maximum cluster number */ + uint32_t pm_freeclustercount; /* number of free clusters */ + uint32_t pm_cnshift; /* shift file offset right this amount to get a cluster number */ + uint32_t pm_crbomask; /* and a file offset with this mask to get cluster rel offset */ + uint32_t pm_bnshift; /* shift file offset right this amount to get a block number */ + uint32_t pm_bpcluster; /* bytes per cluster */ + uint32_t pm_fmod; /* ~0 if fs is modified, this can rollover to 0 */ + uint32_t pm_fatblocksize; /* size of fat blocks in bytes */ + uint32_t pm_fatblocksec; /* size of fat blocks in sectors */ + uint32_t pm_fatsize; /* size of fat in bytes */ + uint32_t pm_fatmask; /* mask to use for fat numbers */ + uint32_t pm_fsinfo; /* fsinfo block number */ + u_int pm_fatmult; /* these 2 values are used in fat */ + u_int pm_fatdiv; /* offset computation */ + u_int pm_curfat; /* current fat for FAT32 (0 otherwise) */ + u_int *pm_inusemap; /* ptr to bitmap of in-use clusters */ + u_int pm_flags; /* see below */ + struct netexport pm_export; /* export information */ +}; +/* Byte offset in FAT on filesystem pmp, cluster cn */ +#define FATOFS(pmp, cn) ((cn) * (pmp)->pm_fatmult / (pmp)->pm_fatdiv) + +/* + * Mount point flags: + */ +#if 0 + /* Defined in */ +#define MSDOSFSMNT_SHORTNAME 0x01 +#define MSDOSFSMNT_LONGNAME 0x02 +#define MSDOSFSMNT_NOWIN95 0x04 +#endif + +/* All flags above: */ +#define MSDOSFSMNT_MNTOPT \ + (MSDOSFSMNT_SHORTNAME|MSDOSFSMNT_LONGNAME|MSDOSFSMNT_NOWIN95) +#define MSDOSFSMNT_RONLY 0x80000000 /* mounted read-only */ +#define MSDOSFSMNT_WAITONFAT 0x40000000 /* mounted synchronous */ +#define MSDOSFS_FATMIRROR 0x20000000 /* FAT is mirrored */ + +#define VFSTOMSDOSFS(mp) ((struct msdosfsmount *)mp->mnt_data) + +/* Number of bits in one pm_inusemap item: */ +#define N_INUSEBITS (8 * sizeof(u_int)) + +/* + * Shorthand for fields in the bpb contained in the msdosfsmount structure. + */ +#define pm_BytesPerSec pm_bpb.bpbBytesPerSec +#define pm_ResSectors pm_bpb.bpbResSectors +#define pm_FATs pm_bpb.bpbFATs +#define pm_RootDirEnts pm_bpb.bpbRootDirEnts +#define pm_Sectors pm_bpb.bpbSectors +#define pm_Media pm_bpb.bpbMedia +#define pm_SecPerTrack pm_bpb.bpbSecPerTrack +#define pm_Heads pm_bpb.bpbHeads +#define pm_HiddenSects pm_bpb.bpbHiddenSecs +#define pm_HugeSectors pm_bpb.bpbHugeSectors + +/* + * Convert pointer to buffer -> pointer to direntry + */ +#define bptoep(pmp, bp, dirofs) \ + ((struct direntry *)(((bp)->b_data) \ + + ((dirofs) & (pmp)->pm_crbomask))) + +/* + * Convert block number to cluster number + */ +#define de_bn2cn(pmp, bn) \ + ((bn) >> ((pmp)->pm_cnshift - (pmp)->pm_bnshift)) + +/* + * Convert cluster number to block number + */ +#define de_cn2bn(pmp, cn) \ + ((cn) << ((pmp)->pm_cnshift - (pmp)->pm_bnshift)) + +/* + * Convert file offset to cluster number + */ +#define de_cluster(pmp, off) \ + ((off) >> (pmp)->pm_cnshift) + +/* + * Clusters required to hold size bytes + */ +#define de_clcount(pmp, size) \ + (((size) + (pmp)->pm_bpcluster - 1) >> (pmp)->pm_cnshift) + +/* + * Convert file offset to block number + */ +#define de_blk(pmp, off) \ + (de_cn2bn(pmp, de_cluster((pmp), (off)))) + +/* + * Convert cluster number to file offset + */ +#define de_cn2off(pmp, cn) \ + ((cn) << (pmp)->pm_cnshift) + +/* + * Convert block number to file offset + */ +#define de_bn2off(pmp, bn) \ + ((bn) << (pmp)->pm_bnshift) +/* + * Map a cluster number into a filesystem relative block number. + */ +#define cntobn(pmp, cn) \ + (de_cn2bn((pmp), (cn)-CLUST_FIRST) + (pmp)->pm_firstcluster) + +/* + * Calculate block number for directory entry in root dir, offset dirofs + */ +#define roottobn(pmp, dirofs) \ + (de_blk((pmp), (dirofs)) + (pmp)->pm_rootdirblk) + +/* + * Calculate block number for directory entry at cluster dirclu, offset + * dirofs + */ +#define detobn(pmp, dirclu, dirofs) \ + ((dirclu) == MSDOSFSROOT \ + ? roottobn((pmp), (dirofs)) \ + : cntobn((pmp), (dirclu))) + +/* Calculate size of fsinfo block */ +#define fsi_size(pmp) \ + (1024 << ((pmp)->pm_BlkPerSec >> 2)) + +/* + * Prototypes for MSDOSFS virtual filesystem operations + */ +int msdosfs_mount(struct mount *, const char *, void *, struct nameidata *, struct proc *); +int msdosfs_start(struct mount *, int, struct proc *); +int msdosfs_unmount(struct mount *, int, struct proc *); +int msdosfs_root(struct mount *, struct vnode **); +int msdosfs_statfs(struct mount *, struct statfs *, struct proc *); +int msdosfs_sync(struct mount *, int, int, struct ucred *, struct proc *); +int msdosfs_fhtovp(struct mount *, struct fid *, struct vnode **); +int msdosfs_vptofh(struct vnode *, struct fid *); +int msdosfs_init(struct vfsconf *); \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ndbm.h b/lib/libc/include/generic-openbsd/ndbm.h new file mode 100644 index 0000000000..e0cb4db158 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ndbm.h @@ -0,0 +1,78 @@ +/* $OpenBSD: ndbm.h,v 1.6 2004/05/03 17:27:50 millert Exp $ */ +/* $NetBSD: ndbm.h,v 1.6 1995/07/20 23:31:11 jtc Exp $ */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Margo Seltzer. + * + * 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. + * + * @(#)ndbm.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _NDBM_H_ +#define _NDBM_H_ + +#include + +/* Map dbm interface onto db(3). */ +#define DBM_RDONLY O_RDONLY + +/* Flags to dbm_store(). */ +#define DBM_INSERT 0 +#define DBM_REPLACE 1 + +/* + * The db(3) support for ndbm(3) always appends this suffix to the + * file name to avoid overwriting the user's original database. + */ +#define DBM_SUFFIX ".db" + +typedef struct { + void *dptr; + size_t dsize; +} datum; + +typedef DB DBM; +#define dbm_pagfno(a) DBM_PAGFNO_NOT_AVAILABLE + +__BEGIN_DECLS +int dbm_clearerr(DBM *); +void dbm_close(DBM *); +int dbm_delete(DBM *, datum); +int dbm_error(DBM *); +datum dbm_fetch(DBM *, datum); +datum dbm_firstkey(DBM *); +datum dbm_nextkey(DBM *); +DBM *dbm_open(const char *, int, mode_t); +int dbm_store(DBM *, datum, datum, int); +int dbm_dirfno(DBM *); +int dbm_rdonly(DBM *); +__END_DECLS + +#endif /* !_NDBM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/art.h b/lib/libc/include/generic-openbsd/net/art.h new file mode 100644 index 0000000000..bf621de830 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/art.h @@ -0,0 +1,169 @@ +/* $OpenBSD: art.h,v 1.28 2025/07/10 05:28:13 dlg 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 _NET_ART_H_ +#define _NET_ART_H_ + +/* + * Allotment Routing Table (ART) + * + * Yoichi Hariguchi paper can be found at: + * http://www.hariguchi.org/art/art.pdf + * + * Locking: + * + * Modification (ie, art_insert or art_delete) and iteration + * (art_iter_next, etc) over the ART must be serialised by the caller. + * Lookups (ie, art_match and art_lookup) run within an SMR critical + * section. + * + * Iteration requires serialisation as it manipulates the reference + * counts on tables as it traverses the tree. The iterator maintains + * these references until it runs out of entries. This allows code + * iterating over the ART to release locks in between calls to + * art_iter_open and art_iter_next. The references may be dropped + * early with art_iter_close. + * + * Note, the iterator does not hold a reference to the art_node + * structure or the data hanging off the an_value pointer, they must + * be accounted for separately or their use must be serialised with + * art_delete. + */ + +typedef uintptr_t art_heap_entry; + +/* + * Root of the ART, equivalent to the radix head. + */ + +struct art { + art_heap_entry *art_root; + const unsigned int *art_levels; + unsigned int art_nlevels; + unsigned int art_alen; +}; + +/* + * Allotment Table. + */ +struct art_table { + art_heap_entry *at_heap; + struct art_table *at_parent; /* Parent table */ + + unsigned int at_index; /* Index in the parent table */ + unsigned int at_minfringe; /* Index that fringe begins */ + + unsigned int at_level; /* Level of the table */ + unsigned int at_bits; /* Stride length of the table */ + unsigned int at_offset; /* Sum of parents' stride len */ + + unsigned int at_refcnt; +}; + +#define ART_HEAP_IDX_TABLE 0 +#define ART_HEAP_IDX_DEFAULT 1 + +#define AT_HEAPSIZE(bits) ((1 << ((bits) + 1)) * sizeof(art_heap_entry)) + +/* + * A node is the internal representation of a route entry. + */ +struct art_node { + void *an_value; + union { + struct art_node *an__gc; + uint8_t an__addr[16]; + } an__u; +#define an_gc an__u.an__gc +#define an_addr an__u.an__addr + unsigned int an_plen; +}; + +static inline struct art_table * +art_heap_to_table(art_heap_entry *heap) +{ + return ((struct art_table *)heap[ART_HEAP_IDX_TABLE]); +} + +static inline int +art_heap_entry_is_node(art_heap_entry ahe) +{ + return ((ahe & 1UL) == 0); +} + +static inline struct art_node * +art_heap_entry_to_node(art_heap_entry ahe) +{ + return ((struct art_node *)ahe); +} + +static inline art_heap_entry * +art_heap_entry_to_heap(art_heap_entry ahe) +{ + return ((art_heap_entry *)(ahe & ~1UL)); +} + +static inline art_heap_entry +art_node_to_heap_entry(struct art_node *an) +{ + return ((art_heap_entry)an); +} + +static inline art_heap_entry +art_heap_to_heap_entry(art_heap_entry *heap) +{ + return ((art_heap_entry)heap | 1UL); +} + +#ifdef _KERNEL +void art_boot(void); +struct art *art_alloc(unsigned int); +void art_init(struct art *, unsigned int); +struct art_node *art_insert(struct art *, struct art_node *); +struct art_node *art_delete(struct art *, const void *, unsigned int); +struct art_node *art_match(struct art *, const void *); +struct art_node *art_lookup(struct art *, const void *, unsigned int); +int art_is_empty(struct art *); + +struct art_node *art_get(const uint8_t *, unsigned int); +void art_node_init(struct art_node *, + const uint8_t *, unsigned int); +void art_put(struct art_node *); + +struct art_iter { + struct art *ai_art; + struct art_table *ai_table; + unsigned int ai_j; + unsigned int ai_i; +}; + +struct art_node *art_iter_open(struct art *, struct art_iter *); +struct art_node *art_iter_next(struct art_iter *); +void art_iter_close(struct art_iter *); + +#define ART_FOREACH(_an, _art, _ai) \ + for ((_an) = art_iter_open((_art), (_ai)); \ + (_an) != NULL; \ + (_an) = art_iter_next((_ai))) + +int art_walk(struct art *, + int (*)(struct art_node *, void *), void *); + +#endif /* _KERNEL */ + +#endif /* _NET_ART_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/bfd.h b/lib/libc/include/generic-openbsd/net/bfd.h new file mode 100644 index 0000000000..5319f356a2 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/bfd.h @@ -0,0 +1,163 @@ +/* $OpenBSD: bfd.h,v 1.14 2025/07/24 00:49:22 jsg Exp $ */ + +/* + * Copyright (c) 2016 Peter Hessler + * + * 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. + */ + +/* + * Support for Bi-directional Forwarding Detection (RFC 5880 / 5881) + */ + +#ifndef _NET_BFD_H_ +#define _NET_BFD_H_ + +/* Public Interface */ + +#define BFD_MODE_ASYNC 1 +#define BFD_MODE_DEMAND 2 + +/* Diagnostic Code (RFC 5880 Page 8) */ +#define BFD_DIAG_NONE 0 +#define BFD_DIAG_EXPIRED 1 +#define BFD_DIAG_ECHO_FAILED 2 +#define BFD_DIAG_NEIGHBOR_SIGDOWN 3 +#define BFD_DIAG_FIB_RESET 4 +#define BFD_DIAG_PATH_DOWN 5 +#define BFD_DIAG_CONCAT_PATH_DOWN 6 +#define BFD_DIAG_ADMIN_DOWN 7 +#define BFD_DIAG_CONCAT_REVERSE_DOWN 8 + +/* State (RFC 5880 Page 8) */ +#define BFD_STATE_ADMINDOWN 0 +#define BFD_STATE_DOWN 1 +#define BFD_STATE_INIT 2 +#define BFD_STATE_UP 3 + +/* Flags (RFC 5880 Page 8) */ +#define BFD_FLAG_P 0x20 +#define BFD_FLAG_F 0x10 +#define BFD_FLAG_C 0x08 +#define BFD_FLAG_A 0x04 +#define BFD_FLAG_D 0x02 +#define BFD_FLAG_M 0x01 + +struct sockaddr_bfd { + uint8_t bs_len; /* total length */ + uint8_t bs_family; /* address family */ + /* above matches sockaddr_storage */ + + /* Sorted for bit boundaries */ + uint16_t bs_mode; + uint32_t bs_localdiscr; + + int64_t bs_uptime; + + int64_t bs_lastuptime; + + uint32_t bs_mintx; + uint32_t bs_minrx; + + uint32_t bs_minecho; + uint32_t bs_localdiag; + + uint32_t bs_remotediscr; + uint32_t bs_remotediag; + + uint16_t bs_multiplier; + uint16_t bs_pad0; + unsigned int bs_state; + unsigned int bs_remotestate; + unsigned int bs_laststate; + unsigned int bs_error; + + /* add padding to reach a power of two */ + uint64_t bs_pad1; +}; + +struct bfd_msghdr { + uint16_t bm_msglen; + uint8_t bm_version; + uint8_t bm_type; + uint16_t bm_hdrlen; + uint16_t bm_index; + + uint16_t bm_tableid; + uint8_t bm_priority; + uint8_t bm_mpls; + int bm_addrs; + int bm_flags; + /* above matches rt_msghdr */ + uint16_t bm_pad0; /* for 4 byte boundary */ + + struct sockaddr_bfd bm_sa; /* bfd msg for userland */ +}; + +#ifdef _KERNEL +/* state machine from RFC 5880 6.8.1*/ +struct bfd_neighbor { + uint32_t bn_lstate; /* SessionState */ + uint32_t bn_rstate; /* RemoteSessionState */ + uint32_t bn_ldiscr; /* LocalDiscr */ + uint32_t bn_rdiscr; /* RemoteDiscr */ + uint32_t bn_ldiag; /* LocalDiag */ + uint32_t bn_rdiag; /* RemoteDiag */ + uint32_t bn_mintx; /* DesiredMinTxInterval */ + uint32_t bn_req_minrx; /* RequiredMinRxInterval */ + uint32_t bn_rminrx; /* RemoteMinRxInterval */ + uint32_t bn_demand; /* DemandMode */ + uint32_t bn_rdemand; /* RemoteDemandMode */ + uint32_t bn_authtype; /* AuthType */ + uint32_t bn_rauthseq; /* RcvAuthSeq */ + uint32_t bn_lauthseq; /* XmitAuthSeq */ + uint32_t bn_authseqknown; /* AuthSeqKnown */ + uint16_t bn_mult; /* DetectMult */ +}; + +struct bfd_config { + TAILQ_ENTRY(bfd_config) bc_entry; + struct socket *bc_so; + struct socket *bc_upcallso; + struct socket *bc_soecho; + struct socket *bc_sosend; + struct rtentry *bc_rt; + struct bfd_neighbor *bc_neighbor; + struct timeval *bc_time; + struct task bc_bfd_task; + struct task bc_bfd_send_task; + struct task bc_upcall_task; + struct task bc_clear_task; + struct timeout bc_timo_rx; + struct timeout bc_timo_tx; + time_t bc_lastuptime; + unsigned int bc_laststate; + unsigned int bc_state; + unsigned int bc_poll; + unsigned int bc_error; + uint32_t bc_minrx; + uint32_t bc_mintx; + uint32_t bc_minecho; + uint16_t bc_multiplier; + uint16_t bc_mode; +}; + +struct sockaddr *bfd2sa(const struct rtentry *, struct sockaddr_bfd *); + +int bfdset(struct rtentry *); +void bfdclear(struct rtentry *); +void bfdinit(void); + +#endif /* _KERNEL */ + +#endif /* _NET_BFD_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/bpf.h b/lib/libc/include/generic-openbsd/net/bpf.h new file mode 100644 index 0000000000..d549a0b2e3 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/bpf.h @@ -0,0 +1,342 @@ +/* $OpenBSD: bpf.h,v 1.74 2025/03/04 01:01:25 dlg Exp $ */ +/* $NetBSD: bpf.h,v 1.15 1996/12/13 07:57:33 mikel Exp $ */ + +/* + * Copyright (c) 1990, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from the Stanford/CMU enet packet filter, + * (net/enet.c) distributed as part of 4.3BSD, and code contributed + * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence + * Berkeley Laboratory. + * + * 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. + * + * @(#)bpf.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NET_BPF_H_ +#define _NET_BPF_H_ + +/* BSD style release date */ +#define BPF_RELEASE 199606 + +typedef int32_t bpf_int32; +typedef u_int32_t bpf_u_int32; +/* + * Alignment macros. BPF_WORDALIGN rounds up to the next even multiple of + * BPF_ALIGNMENT (which is at least as much as what a timeval needs). + */ +#define BPF_ALIGNMENT sizeof(u_int32_t) +#define BPF_WORDALIGN(x) (((x) + (BPF_ALIGNMENT - 1)) & ~(BPF_ALIGNMENT - 1)) + +#define BPF_MAXINSNS 512 +#define BPF_MAXBUFSIZE (2 * 1024 * 1024) +#define BPF_MINBUFSIZE 32 + +/* + * Structure for BIOCSETF. + */ +struct bpf_program { + u_int bf_len; + struct bpf_insn *bf_insns; +}; + +/* + * Struct returned by BIOCGSTATS. + */ +struct bpf_stat { + u_int bs_recv; /* number of packets received */ + u_int bs_drop; /* number of packets dropped */ +}; + +/* + * Struct return by BIOCVERSION. This represents the version number of + * the filter language described by the instruction encodings below. + * bpf understands a program iff kernel_major == filter_major && + * kernel_minor >= filter_minor, that is, if the value returned by the + * running kernel has the same major number and a minor number equal + * equal to or less than the filter being downloaded. Otherwise, the + * results are undefined, meaning an error may be returned or packets + * may be accepted haphazardly. + * It has nothing to do with the source code version. + */ +struct bpf_version { + u_short bv_major; + u_short bv_minor; +}; +/* Current version number of filter architecture. */ +#define BPF_MAJOR_VERSION 1 +#define BPF_MINOR_VERSION 1 + +/* + * BPF ioctls + */ +#define BIOCGBLEN _IOR('B',102, u_int) +#define BIOCSBLEN _IOWR('B',102, u_int) +#define BIOCSETF _IOW('B',103, struct bpf_program) +#define BIOCFLUSH _IO('B',104) +#define BIOCPROMISC _IO('B',105) +#define BIOCGDLT _IOR('B',106, u_int) +#define BIOCGETIF _IOR('B',107, struct ifreq) +#define BIOCSETIF _IOW('B',108, struct ifreq) +#define BIOCSRTIMEOUT _IOW('B',109, struct timeval) +#define BIOCGRTIMEOUT _IOR('B',110, struct timeval) +#define BIOCGSTATS _IOR('B',111, struct bpf_stat) +#define BIOCIMMEDIATE _IOW('B',112, u_int) +#define BIOCVERSION _IOR('B',113, struct bpf_version) +#define BIOCSRSIG _IOW('B',114, u_int) +#define BIOCGRSIG _IOR('B',115, u_int) +#define BIOCGHDRCMPLT _IOR('B',116, u_int) +#define BIOCSHDRCMPLT _IOW('B',117, u_int) +#define BIOCLOCK _IO('B',118) +#define BIOCSETWF _IOW('B',119, struct bpf_program) +#define BIOCGFILDROP _IOR('B',120, u_int) +#define BIOCSFILDROP _IOW('B',121, u_int) +#define BIOCSDLT _IOW('B',122, u_int) +#define BIOCGDLTLIST _IOWR('B',123, struct bpf_dltlist) +#define BIOCGDIRFILT _IOR('B',124, u_int) +#define BIOCSDIRFILT _IOW('B',125, u_int) +#define BIOCSWTIMEOUT _IOW('B',126, struct timeval) +#define BIOCGWTIMEOUT _IOR('B',126, struct timeval) +#define BIOCDWTIMEOUT _IO('B',126) +#define BIOCSETFNR _IOW('B',127, struct bpf_program) + +/* + * Direction filters for BIOCSDIRFILT/BIOCGDIRFILT + */ +#define BPF_DIRECTION_IN (1 << 0) +#define BPF_DIRECTION_OUT (1 << 1) + +/* + * Values for BIOCGFILDROP/BIOCSFILDROP + */ +#define BPF_FILDROP_PASS 0 /* capture, pass */ +#define BPF_FILDROP_CAPTURE 1 /* capture, drop */ +#define BPF_FILDROP_DROP 2 /* no capture, drop */ + +struct bpf_timeval { + u_int32_t tv_sec; + u_int32_t tv_usec; +}; + +/* + * Structure prepended to each packet. + */ +struct bpf_hdr { + struct bpf_timeval bh_tstamp; /* time stamp */ + u_int32_t bh_caplen; /* length of captured portion */ + u_int32_t bh_datalen; /* original length of packet */ + u_int16_t bh_hdrlen; /* length of bpf header (this struct + plus alignment padding) */ + u_int16_t bh_ifidx; /* receive interface index */ + + u_int16_t bh_flowid; + u_int8_t bh_flags; +#define BPF_F_PRI_MASK 0x07 +#define BPF_F_FLOWID 0x08 +#define BPF_F_DIR_SHIFT 4 +#define BPF_F_DIR_MASK (0x3 << BPF_F_DIR_SHIFT) +#define BPF_F_DIR_IN (BPF_DIRECTION_IN << BPF_F_DIR_SHIFT) +#define BPF_F_DIR_OUT (BPF_DIRECTION_OUT << BPF_F_DIR_SHIFT) + u_int8_t bh_drops; + u_int16_t bh_csumflags; /* checksum flags */ +}; + +#ifdef _KERNEL +#define SIZEOF_BPF_HDR sizeof(struct bpf_hdr) +#endif + +/* + * Data-link level type codes. + */ +#define DLT_NULL 0 /* no link-layer encapsulation */ +#define DLT_EN10MB 1 /* Ethernet (10Mb) */ +#define DLT_EN3MB 2 /* Experimental Ethernet (3Mb) */ +#define DLT_AX25 3 /* Amateur Radio AX.25 */ +#define DLT_PRONET 4 /* Proteon ProNET Token Ring */ +#define DLT_CHAOS 5 /* Chaos */ +#define DLT_IEEE802 6 /* IEEE 802 Networks */ +#define DLT_ARCNET 7 /* ARCNET */ +#define DLT_SLIP 8 /* Serial Line IP */ +#define DLT_PPP 9 /* Point-to-point Protocol */ +#define DLT_FDDI 10 /* FDDI */ +#define DLT_ATM_RFC1483 11 /* LLC/SNAP encapsulated atm */ +#define DLT_LOOP 12 /* loopback type (af header) */ +#define DLT_ENC 13 /* IPSEC enc type (af header, spi, flags) */ +#define DLT_RAW 14 /* raw IP */ +#define DLT_SLIP_BSDOS 15 /* BSD/OS Serial Line IP */ +#define DLT_PPP_BSDOS 16 /* BSD/OS Point-to-point Protocol */ +#define DLT_PFSYNC 18 /* Packet filter state syncing */ +#define DLT_PPP_SERIAL 50 /* PPP over Serial with HDLC */ +#define DLT_PPP_ETHER 51 /* PPP over Ethernet; session only w/o ether header */ +#define DLT_C_HDLC 104 /* Cisco HDLC */ +#define DLT_IEEE802_11 105 /* IEEE 802.11 wireless */ +#define DLT_PFLOG 117 /* Packet filter logging, by pcap people */ +#define DLT_IEEE802_11_RADIO 127 /* IEEE 802.11 plus WLAN header */ +#define DLT_USER0 147 /* Reserved for private use */ +#define DLT_USER1 148 /* Reserved for private use */ +#define DLT_USER2 149 /* Reserved for private use */ +#define DLT_USER3 150 /* Reserved for private use */ +#define DLT_USER4 151 /* Reserved for private use */ +#define DLT_USER5 152 /* Reserved for private use */ +#define DLT_USER6 153 /* Reserved for private use */ +#define DLT_USER7 154 /* Reserved for private use */ +#define DLT_USER8 155 /* Reserved for private use */ +#define DLT_USER9 156 /* Reserved for private use */ +#define DLT_USER10 157 /* Reserved for private use */ +#define DLT_USER11 158 /* Reserved for private use */ +#define DLT_USER12 159 /* Reserved for private use */ +#define DLT_USER13 160 /* Reserved for private use */ +#define DLT_USER14 161 /* Reserved for private use */ +#define DLT_USER15 162 /* Reserved for private use */ +#define DLT_USBPCAP 249 /* USBPcap */ +#define DLT_MPLS 219 /* MPLS Provider Edge header */ +#define DLT_OPENFLOW 267 /* in-kernel OpenFlow, by pcap */ + +/* + * The instruction encodings. + */ +/* instruction classes */ +#define BPF_CLASS(code) ((code) & 0x07) +#define BPF_LD 0x00 +#define BPF_LDX 0x01 +#define BPF_ST 0x02 +#define BPF_STX 0x03 +#define BPF_ALU 0x04 +#define BPF_JMP 0x05 +#define BPF_RET 0x06 +#define BPF_MISC 0x07 + +/* ld/ldx fields */ +#define BPF_SIZE(code) ((code) & 0x18) +#define BPF_W 0x00 +#define BPF_H 0x08 +#define BPF_B 0x10 +#define BPF_MODE(code) ((code) & 0xe0) +#define BPF_IMM 0x00 +#define BPF_ABS 0x20 +#define BPF_IND 0x40 +#define BPF_MEM 0x60 +#define BPF_LEN 0x80 +#define BPF_MSH 0xa0 +#define BPF_RND 0xc0 + +/* alu/jmp fields */ +#define BPF_OP(code) ((code) & 0xf0) +#define BPF_ADD 0x00 +#define BPF_SUB 0x10 +#define BPF_MUL 0x20 +#define BPF_DIV 0x30 +#define BPF_OR 0x40 +#define BPF_AND 0x50 +#define BPF_LSH 0x60 +#define BPF_RSH 0x70 +#define BPF_NEG 0x80 +#define BPF_JA 0x00 +#define BPF_JEQ 0x10 +#define BPF_JGT 0x20 +#define BPF_JGE 0x30 +#define BPF_JSET 0x40 +#define BPF_SRC(code) ((code) & 0x08) +#define BPF_K 0x00 +#define BPF_X 0x08 + +/* ret - BPF_K and BPF_X also apply */ +#define BPF_RVAL(code) ((code) & 0x18) +#define BPF_A 0x10 + +/* misc */ +#define BPF_MISCOP(code) ((code) & 0xf8) +#define BPF_TAX 0x00 +#define BPF_TXA 0x80 + +/* + * The instruction data structure. + */ +struct bpf_insn { + u_int16_t code; + u_char jt; + u_char jf; + u_int32_t k; +}; + +/* + * Structure to retrieve available DLTs for the interface. + */ +struct bpf_dltlist { + u_int bfl_len; /* number of bfd_list array */ + u_int *bfl_list; /* array of DLTs */ +}; + +/* + * Load operations for _bpf_filter to use against the packet pointer. + */ +struct bpf_ops { + u_int32_t (*ldw)(const void *, u_int32_t, int *); + u_int32_t (*ldh)(const void *, u_int32_t, int *); + u_int32_t (*ldb)(const void *, u_int32_t, int *); +}; + +/* + * Macros for insn array initializers. + */ +#define BPF_STMT(code, k) { (u_int16_t)(code), 0, 0, k } +#define BPF_JUMP(code, k, jt, jf) { (u_int16_t)(code), jt, jf, k } + +__BEGIN_DECLS +u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int) + __bounded((__buffer__, 2, 4)); + +u_int _bpf_filter(const struct bpf_insn *, const struct bpf_ops *, + const void *, u_int); +__END_DECLS + +#ifdef _KERNEL +struct ifnet; +struct mbuf; + +int bpf_validate(struct bpf_insn *, int); +int bpf_mtap(caddr_t, const struct mbuf *, u_int); +int bpf_mtap_hdr(caddr_t, const void *, u_int, const struct mbuf *, u_int); +int bpf_mtap_af(caddr_t, u_int32_t, const struct mbuf *, u_int); +int bpf_mtap_ether(caddr_t, const struct mbuf *, u_int); +int bpf_tap_hdr(caddr_t, const void *, u_int, const void *, u_int, u_int); +void bpfattach(caddr_t *, struct ifnet *, u_int, u_int); +void bpfdetach(struct ifnet *); +void *bpfsattach(caddr_t *, const char *, u_int, u_int); +void *bpfxattach(caddr_t *, const char *, struct ifnet *, u_int, u_int); +void bpfsdetach(void *); +void bpfilterattach(int); + +u_int bpf_mfilter(const struct bpf_insn *, const struct mbuf *, u_int); +#endif /* _KERNEL */ + +/* + * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST). + */ +#define BPF_MEMWORDS 16 + +#endif /* _NET_BPF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/bpfdesc.h b/lib/libc/include/generic-openbsd/net/bpfdesc.h new file mode 100644 index 0000000000..61be132f2b --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/bpfdesc.h @@ -0,0 +1,128 @@ +/* $OpenBSD: bpfdesc.h,v 1.50 2024/11/19 23:26:35 dlg Exp $ */ +/* $NetBSD: bpfdesc.h,v 1.11 1995/09/27 18:30:42 thorpej Exp $ */ + +/* + * Copyright (c) 1990, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from the Stanford/CMU enet packet filter, + * (net/enet.c) distributed as part of 4.3BSD, and code contributed + * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence + * Berkeley Laboratory. + * + * 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. + * + * @(#)bpfdesc.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NET_BPFDESC_H_ +#define _NET_BPFDESC_H_ + +#ifdef _KERNEL + +/* + * Locks used to protect struct members in this file: + * + * m the per-descriptor mutex (bpf_d.bd_mtx) + */ + +struct bpf_program_smr { + struct bpf_program bps_bf; + struct smr_entry bps_smr; +}; + +/* + * Descriptor associated with each open bpf file. + */ +struct bpf_d { + SMR_SLIST_ENTRY(bpf_d) bd_next; /* Linked list of descriptors */ + /* + * Buffer slots: two mbuf clusters buffer the incoming packets. + * The model has three slots. Sbuf is always occupied. + * sbuf (store) - Receive interrupt puts packets here. + * hbuf (hold) - When sbuf is full, put cluster here and + * wakeup read (replace sbuf with fbuf). + * fbuf (free) - When read is done, put cluster here. + * On receiving, if sbuf is full and fbuf is 0, packet is dropped. + */ + struct mutex bd_mtx; /* protect buffer slots below */ + caddr_t bd_sbuf; /* store slot */ + caddr_t bd_hbuf; /* hold slot */ + caddr_t bd_fbuf; /* free slot */ + int bd_slen; /* current length of store buffer */ + int bd_hlen; /* current length of hold buffer */ + int bd_bufsize; /* absolute length of buffers */ + + int bd_in_uiomove; /* for debugging purpose */ + + struct bpf_if *bd_bif; /* interface descriptor */ + uint64_t bd_rtout; /* [m] Read timeout in nanoseconds */ + uint64_t bd_wtout; /* [m] Wait time in nanoseconds */ + u_long bd_nreaders; /* [m] # threads asleep in bpfread() */ + struct bpf_program_smr + *bd_rfilter; /* read filter code */ + struct bpf_program_smr + *bd_wfilter; /* write filter code */ + u_long bd_rcount; /* number of packets received */ + u_long bd_dcount; /* number of packets dropped */ + + u_char bd_promisc; /* true if listening promiscuously */ + u_char bd_state; /* [m] idle, waiting, or timed out */ + u_char bd_locked; /* true if descriptor is locked */ + u_char bd_fildrop; /* true if filtered packets will be dropped */ + u_char bd_dirfilt; /* direction filter */ + int bd_hdrcmplt; /* false to fill in src lladdr automatically */ + int bd_async; /* non-zero if packet reception should generate signal */ + int bd_sig; /* signal to send upon packet reception */ + struct sigio_ref + bd_sigio; /* async I/O registration */ + struct refcnt bd_refcnt; /* reference count */ + struct klist bd_klist; /* list of knotes */ + int bd_unit; /* logical unit number */ + LIST_ENTRY(bpf_d) bd_list; /* descriptor list */ + + struct task bd_wake_task; /* defer pgsigio() and selwakeup() */ + struct timeout bd_wait_tmo; /* delay wakeup after catching pkt */ + + struct smr_entry + bd_smr; +}; + +/* + * Descriptor associated with each attached hardware interface. + */ +struct bpf_if { + TAILQ_ENTRY(bpf_if) bif_next; /* list of all interfaces */ + SMR_SLIST_HEAD(, bpf_d) bif_dlist; /* descriptor list */ + struct bpf_if **bif_driverp; /* pointer into softc */ + u_int bif_dlt; /* link layer type */ + u_int bif_hdrlen; /* length of header (with padding) */ + const char *bif_name; /* name of "subsystem" */ + struct ifnet *bif_ifp; /* corresponding interface */ +}; + +int bpf_setf(struct bpf_d *, struct bpf_program *, u_long); +#endif /* _KERNEL */ +#endif /* _NET_BPFDESC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/ethertypes.h b/lib/libc/include/generic-openbsd/net/ethertypes.h new file mode 100644 index 0000000000..713ae8d958 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/ethertypes.h @@ -0,0 +1,325 @@ +/* $OpenBSD: ethertypes.h,v 1.20 2025/05/18 04:10:49 dlg Exp $ */ +/* $NetBSD: ethertypes.h,v 1.13 2002/02/10 01:28:32 thorpej Exp $ */ + +/* + * Copyright (c) 1982, 1986, 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. + * + * @(#)if_ether.h 8.1 (Berkeley) 6/10/93 + */ + +/* + * Ethernet protocol types. + * + * According to "assigned numbers", the Ethernet protocol numbers are also + * used as ARP protocol type numbers. + * + * I factor them out here to avoid pulling all the Ethernet header file + * into the hardware independent ARP code. -is + * + * Additional sources of information: + * http://standards.ieee.org/regauth/ethertype/eth.txt + * http://www.mit.edu/~map/Ethernet/Ethernet.txt + * + */ + +#ifndef _NET_ETHERTYPES_H_ +#define _NET_ETHERTYPES_H_ + +/* + * NOTE: 0x0000-0x05DC (0..1500) are generally IEEE 802.3 length fields. + * However, there are some conflicts. + */ + +#define ETHERTYPE_8023 0x0004 /* IEEE 802.3 packet */ + /* 0x0101 .. 0x1FF Experimental */ +#define ETHERTYPE_PUP 0x0200 /* Xerox PUP protocol - see 0A00 */ +#define ETHERTYPE_PUPAT 0x0200 /* PUP Address Translation - see 0A01 */ +#define ETHERTYPE_SPRITE 0x0500 /* ??? */ + /* 0x0400 Nixdorf */ +#define ETHERTYPE_NS 0x0600 /* XNS */ +#define ETHERTYPE_NSAT 0x0601 /* XNS Address Translation (3Mb only) */ +#define ETHERTYPE_DLOG1 0x0660 /* DLOG (?) */ +#define ETHERTYPE_DLOG2 0x0661 /* DLOG (?) */ +#define ETHERTYPE_IP 0x0800 /* IP protocol */ +#define ETHERTYPE_X75 0x0801 /* X.75 Internet */ +#define ETHERTYPE_NBS 0x0802 /* NBS Internet */ +#define ETHERTYPE_ECMA 0x0803 /* ECMA Internet */ +#define ETHERTYPE_CHAOS 0x0804 /* CHAOSnet */ +#define ETHERTYPE_X25 0x0805 /* X.25 Level 3 */ +#define ETHERTYPE_ARP 0x0806 /* Address resolution protocol */ +#define ETHERTYPE_NSCOMPAT 0x0807 /* XNS Compatibility */ +#define ETHERTYPE_FRARP 0x0808 /* Frame Relay ARP (RFC1701) */ + /* 0x081C Symbolics Private */ + /* 0x0888 - 0x088A Xyplex */ +#define ETHERTYPE_UBDEBUG 0x0900 /* Ungermann-Bass network debugger */ +#define ETHERTYPE_IEEEPUP 0x0A00 /* Xerox IEEE802.3 PUP */ +#define ETHERTYPE_IEEEPUPAT 0x0A01 /* Xerox IEEE802.3 PUP Address Translation */ +#define ETHERTYPE_VINES 0x0BAD /* Banyan VINES */ +#define ETHERTYPE_VINESLOOP 0x0BAE /* Banyan VINES Loopback */ +#define ETHERTYPE_VINESECHO 0x0BAF /* Banyan VINES Echo */ + +/* 0x1000 - 0x100F Berkeley Trailer */ +/* + * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have + * (type-ETHERTYPE_TRAIL)*512 bytes of data followed + * by an ETHER type (as given above) and then the (variable-length) header. + */ +#define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */ +#define ETHERTYPE_NTRAILER 16 + +#define ETHERTYPE_DCA 0x1234 /* DCA - Multicast */ +#define ETHERTYPE_VALID 0x1600 /* VALID system protocol */ +#define ETHERTYPE_DOGFIGHT 0x1989 /* Artificial Horizons ("Aviator" dogfight simulator [on Sun]) */ +#define ETHERTYPE_RCL 0x1995 /* Datapoint Corporation (RCL lan protocol) */ +#define ETHERTYPE_NHRP 0x2001 /* NBMA Next Hop Resolution Protocol (RFC2332) */ + + /* The following 3C0x types + are unregistered: */ +#define ETHERTYPE_NBPVCD 0x3C00 /* 3Com NBP virtual circuit datagram (like XNS SPP) not registered */ +#define ETHERTYPE_NBPSCD 0x3C01 /* 3Com NBP System control datagram not registered */ +#define ETHERTYPE_NBPCREQ 0x3C02 /* 3Com NBP Connect request (virtual cct) not registered */ +#define ETHERTYPE_NBPCRSP 0x3C03 /* 3Com NBP Connect response not registered */ +#define ETHERTYPE_NBPCC 0x3C04 /* 3Com NBP Connect complete not registered */ +#define ETHERTYPE_NBPCLREQ 0x3C05 /* 3Com NBP Close request (virtual cct) not registered */ +#define ETHERTYPE_NBPCLRSP 0x3C06 /* 3Com NBP Close response not registered */ +#define ETHERTYPE_NBPDG 0x3C07 /* 3Com NBP Datagram (like XNS IDP) not registered */ +#define ETHERTYPE_NBPDGB 0x3C08 /* 3Com NBP Datagram broadcast not registered */ +#define ETHERTYPE_NBPCLAIM 0x3C09 /* 3Com NBP Claim NetBIOS name not registered */ +#define ETHERTYPE_NBPDLTE 0x3C0A /* 3Com NBP Delete Netbios name not registered */ +#define ETHERTYPE_NBPRAS 0x3C0B /* 3Com NBP Remote adaptor status request not registered */ +#define ETHERTYPE_NBPRAR 0x3C0C /* 3Com NBP Remote adaptor response not registered */ +#define ETHERTYPE_NBPRST 0x3C0D /* 3Com NBP Reset not registered */ + +#define ETHERTYPE_PCS 0x4242 /* PCS Basic Block Protocol */ +#define ETHERTYPE_IMLBLDIAG 0x424C /* Information Modes Little Big LAN diagnostic */ +#define ETHERTYPE_DIDDLE 0x4321 /* THD - Diddle */ +#define ETHERTYPE_IMLBL 0x4C42 /* Information Modes Little Big LAN */ +#define ETHERTYPE_SIMNET 0x5208 /* BBN Simnet Private */ +#define ETHERTYPE_DECEXPER 0x6000 /* DEC Unassigned, experimental */ +#define ETHERTYPE_MOPDL 0x6001 /* DEC MOP dump/load */ +#define ETHERTYPE_MOPRC 0x6002 /* DEC MOP remote console */ +#define ETHERTYPE_DECnet 0x6003 /* DEC DECNET Phase IV route */ +#define ETHERTYPE_DN ETHERTYPE_DECnet /* libpcap, tcpdump */ +#define ETHERTYPE_LAT 0x6004 /* DEC LAT */ +#define ETHERTYPE_DECDIAG 0x6005 /* DEC diagnostic protocol (at interface initialization?) */ +#define ETHERTYPE_DECCUST 0x6006 /* DEC customer protocol */ +#define ETHERTYPE_SCA 0x6007 /* DEC LAVC, SCA */ +#define ETHERTYPE_AMBER 0x6008 /* DEC AMBER */ +#define ETHERTYPE_DECMUMPS 0x6009 /* DEC MUMPS */ + /* 0x6010 - 0x6014 3Com Corporation */ +#define ETHERTYPE_TRANSETHER 0x6558 /* Trans Ether Bridging (RFC1701)*/ +#define ETHERTYPE_RAWFR 0x6559 /* Raw Frame Relay (RFC1701) */ +#define ETHERTYPE_UBDL 0x7000 /* Ungermann-Bass download */ +#define ETHERTYPE_UBNIU 0x7001 /* Ungermann-Bass NIUs */ +#define ETHERTYPE_UBDIAGLOOP 0x7002 /* Ungermann-Bass diagnostic/loopback */ +#define ETHERTYPE_UBNMC 0x7003 /* Ungermann-Bass ??? (NMC to/from UB Bridge) */ +#define ETHERTYPE_UBBST 0x7005 /* Ungermann-Bass Bridge Spanning Tree */ +#define ETHERTYPE_OS9 0x7007 /* OS/9 Microware */ +#define ETHERTYPE_OS9NET 0x7009 /* OS/9 Net? */ + /* 0x7020 - 0x7029 LRT (England) (now Sintrom) */ +#define ETHERTYPE_RACAL 0x7030 /* Racal-Interlan */ +#define ETHERTYPE_PRIMENTS 0x7031 /* Prime NTS (Network Terminal Service) */ +#define ETHERTYPE_CABLETRON 0x7034 /* Cabletron */ +#define ETHERTYPE_CRONUSVLN 0x8003 /* Cronus VLN */ +#define ETHERTYPE_CRONUS 0x8004 /* Cronus Direct */ +#define ETHERTYPE_HP 0x8005 /* HP Probe */ +#define ETHERTYPE_NESTAR 0x8006 /* Nestar */ +#define ETHERTYPE_ATTSTANFORD 0x8008 /* AT&T/Stanford (local use) */ +#define ETHERTYPE_EXCELAN 0x8010 /* Excelan */ +#define ETHERTYPE_SG_DIAG 0x8013 /* SGI diagnostic type */ +#define ETHERTYPE_SG_NETGAMES 0x8014 /* SGI network games */ +#define ETHERTYPE_SG_RESV 0x8015 /* SGI reserved type */ +#define ETHERTYPE_SG_BOUNCE 0x8016 /* SGI bounce server */ +#define ETHERTYPE_APOLLODOMAIN 0x8019 /* Apollo DOMAIN */ +#define ETHERTYPE_TYMSHARE 0x802E /* Tymeshare */ +#define ETHERTYPE_TIGAN 0x802F /* Tigan, Inc. */ +#define ETHERTYPE_REVARP 0x8035 /* Reverse addr resolution protocol */ +#define ETHERTYPE_AEONIC 0x8036 /* Aeonic Systems */ +#define ETHERTYPE_IPXNEW 0x8037 /* IPX (Novell Netware?) */ +#define ETHERTYPE_LANBRIDGE 0x8038 /* DEC LANBridge */ +#define ETHERTYPE_DSMD 0x8039 /* DEC DSM/DDP */ +#define ETHERTYPE_ARGONAUT 0x803A /* DEC Argonaut Console */ +#define ETHERTYPE_VAXELN 0x803B /* DEC VAXELN */ +#define ETHERTYPE_DECDNS 0x803C /* DEC DNS Naming Service */ +#define ETHERTYPE_ENCRYPT 0x803D /* DEC Ethernet Encryption */ +#define ETHERTYPE_DECDTS 0x803E /* DEC Distributed Time Service */ +#define ETHERTYPE_DECLTM 0x803F /* DEC LAN Traffic Monitor */ +#define ETHERTYPE_DECNETBIOS 0x8040 /* DEC PATHWORKS DECnet NETBIOS Emulation */ +#define ETHERTYPE_DECLAST 0x8041 /* DEC Local Area System Transport */ + /* 0x8042 DEC Unassigned */ +#define ETHERTYPE_PLANNING 0x8044 /* Planning Research Corp. */ + /* 0x8046 - 0x8047 AT&T */ +#define ETHERTYPE_DECAM 0x8048 /* DEC Availability Manager for Distributed Systems DECamds (but someone at DEC says not) */ +#define ETHERTYPE_EXPERDATA 0x8049 /* ExperData */ +#define ETHERTYPE_VEXP 0x805B /* Stanford V Kernel exp. */ +#define ETHERTYPE_VPROD 0x805C /* Stanford V Kernel prod. */ +#define ETHERTYPE_ES 0x805D /* Evans & Sutherland */ +#define ETHERTYPE_LITTLE 0x8060 /* Little Machines */ +#define ETHERTYPE_COUNTERPOINT 0x8062 /* Counterpoint Computers */ + /* 0x8065 - 0x8066 Univ. of Mass @ Amherst */ +#define ETHERTYPE_VEECO 0x8067 /* Veeco Integrated Auto. */ +#define ETHERTYPE_GENDYN 0x8068 /* General Dynamics */ +#define ETHERTYPE_ATT 0x8069 /* AT&T */ +#define ETHERTYPE_AUTOPHON 0x806A /* Autophon */ +#define ETHERTYPE_COMDESIGN 0x806C /* ComDesign */ +#define ETHERTYPE_COMPUGRAPHIC 0x806D /* Compugraphic Corporation */ + /* 0x806E - 0x8077 Landmark Graphics Corp. */ +#define ETHERTYPE_MATRA 0x807A /* Matra */ +#define ETHERTYPE_DDE 0x807B /* Dansk Data Elektronik */ +#define ETHERTYPE_MERIT 0x807C /* Merit Internodal (or Univ of Michigan?) */ + /* 0x807D - 0x807F Vitalink Communications */ +#define ETHERTYPE_VLTLMAN 0x8080 /* Vitalink TransLAN III Management */ + /* 0x8081 - 0x8083 Counterpoint Computers */ + /* 0x8088 - 0x808A Xyplex */ +#define ETHERTYPE_ATALK 0x809B /* AppleTalk */ +#define ETHERTYPE_AT ETHERTYPE_ATALK /* old NetBSD */ +#define ETHERTYPE_APPLETALK ETHERTYPE_ATALK /* HP-UX */ + /* 0x809C - 0x809E Datability */ +#define ETHERTYPE_SPIDER 0x809F /* Spider Systems Ltd. */ + /* 0x80A3 Nixdorf */ + /* 0x80A4 - 0x80B3 Siemens Gammasonics Inc. */ + /* 0x80C0 - 0x80C3 DCA (Digital Comm. Assoc.) Data Exchange Cluster */ + /* 0x80C4 - 0x80C5 Banyan Systems */ +#define ETHERTYPE_PACER 0x80C6 /* Pacer Software */ +#define ETHERTYPE_APPLITEK 0x80C7 /* Applitek Corporation */ + /* 0x80C8 - 0x80CC Intergraph Corporation */ + /* 0x80CD - 0x80CE Harris Corporation */ + /* 0x80CF - 0x80D2 Taylor Instrument */ + /* 0x80D3 - 0x80D4 Rosemount Corporation */ +#define ETHERTYPE_SNA 0x80D5 /* IBM SNA Services over Ethernet */ +#define ETHERTYPE_VARIAN 0x80DD /* Varian Associates */ + /* 0x80DE - 0x80DF TRFS (Integrated Solutions Transparent Remote File System) */ + /* 0x80E0 - 0x80E3 Allen-Bradley */ + /* 0x80E4 - 0x80F0 Datability */ +#define ETHERTYPE_RETIX 0x80F2 /* Retix */ +#define ETHERTYPE_AARP 0x80F3 /* AppleTalk AARP */ + /* 0x80F4 - 0x80F5 Kinetics */ +#define ETHERTYPE_APOLLO 0x80F7 /* Apollo Computer */ +#define ETHERTYPE_VLAN 0x8100 /* IEEE 802.1Q VLAN tagging (XXX conflicts) */ + /* 0x80FF - 0x8101 Wellfleet Communications (XXX conflicts) */ +#define ETHERTYPE_BOFL 0x8102 /* Wellfleet; BOFL (Breath OF Life) pkts [every 5-10 secs.] */ +#define ETHERTYPE_WELLFLEET 0x8103 /* Wellfleet Communications */ + /* 0x8107 - 0x8109 Symbolics Private */ +#define ETHERTYPE_TALARIS 0x812B /* Talaris */ +#define ETHERTYPE_WATERLOO 0x8130 /* Waterloo Microsystems Inc. (XXX which?) */ +#define ETHERTYPE_HAYES 0x8130 /* Hayes Microcomputers (XXX which?) */ +#define ETHERTYPE_VGLAB 0x8131 /* VG Laboratory Systems */ + /* 0x8132 - 0x8137 Bridge Communications */ +#define ETHERTYPE_IPX 0x8137 /* Novell (old) NetWare IPX (ECONFIG E option) */ +#define ETHERTYPE_NOVELL 0x8138 /* Novell, Inc. */ + /* 0x8139 - 0x813D KTI */ +#define ETHERTYPE_MUMPS 0x813F /* M/MUMPS data sharing */ +#define ETHERTYPE_AMOEBA 0x8145 /* Vrije Universiteit (NL) Amoeba 4 RPC (obsolete) */ +#define ETHERTYPE_FLIP 0x8146 /* Vrije Universiteit (NL) FLIP (Fast Local Internet Protocol) */ +#define ETHERTYPE_VURESERVED 0x8147 /* Vrije Universiteit (NL) [reserved] */ +#define ETHERTYPE_LOGICRAFT 0x8148 /* Logicraft */ +#define ETHERTYPE_NCD 0x8149 /* Network Computing Devices */ +#define ETHERTYPE_ALPHA 0x814A /* Alpha Micro */ +#define ETHERTYPE_SNMP 0x814C /* SNMP over Ethernet (see RFC1089) */ + /* 0x814D - 0x814E BIIN */ +#define ETHERTYPE_TEC 0x814F /* Technically Elite Concepts */ +#define ETHERTYPE_RATIONAL 0x8150 /* Rational Corp */ + /* 0x8151 - 0x8153 Qualcomm */ + /* 0x815C - 0x815E Computer Protocol Pty Ltd */ + /* 0x8164 - 0x8166 Charles River Data Systems */ +#define ETHERTYPE_XTP 0x817D /* Protocol Engines XTP */ +#define ETHERTYPE_SGITW 0x817E /* SGI/Time Warner prop. */ +#define ETHERTYPE_HIPPI_FP 0x8180 /* HIPPI-FP encapsulation */ +#define ETHERTYPE_STP 0x8181 /* Scheduled Transfer STP, HIPPI-ST */ + /* 0x8182 - 0x8183 Reserved for HIPPI-6400 */ + /* 0x8184 - 0x818C SGI prop. */ +#define ETHERTYPE_MOTOROLA 0x818D /* Motorola */ +#define ETHERTYPE_NETBEUI 0x8191 /* PowerLAN NetBIOS/NetBEUI (PC) */ + /* 0x819A - 0x81A3 RAD Network Devices */ + /* 0x81B7 - 0x81B9 Xyplex */ + /* 0x81CC - 0x81D5 Apricot Computers */ + /* 0x81D6 - 0x81DD Artisoft Lantastic */ + /* 0x81E6 - 0x81EF Polygon */ + /* 0x81F0 - 0x81F2 Comsat Labs */ + /* 0x81F3 - 0x81F5 SAIC */ + /* 0x81F6 - 0x81F8 VG Analytical */ + /* 0x8203 - 0x8205 QNX Software Systems Ltd. */ + /* 0x8221 - 0x8222 Ascom Banking Systems */ + /* 0x823E - 0x8240 Advanced Encryption Systems */ + /* 0x8263 - 0x826A Charles River Data Systems */ + /* 0x827F - 0x8282 Athena Programming */ + /* 0x829A - 0x829B Inst Ind Info Tech */ + /* 0x829C - 0x82AB Taurus Controls */ + /* 0x82AC - 0x8693 Walker Richer & Quinn */ +#define ETHERTYPE_ACCTON 0x8390 /* Accton Technologies (unregistered) */ +#define ETHERTYPE_TALARISMC 0x852B /* Talaris multicast */ +#define ETHERTYPE_KALPANA 0x8582 /* Kalpana */ + /* 0x8694 - 0x869D Idea Courier */ + /* 0x869E - 0x86A1 Computer Network Tech */ + /* 0x86A3 - 0x86AC Gateway Communications */ +#define ETHERTYPE_SECTRA 0x86DB /* SECTRA */ +#define ETHERTYPE_IPV6 0x86DD /* IP protocol version 6 */ +#define ETHERTYPE_DELTACON 0x86DE /* Delta Controls */ +#define ETHERTYPE_ATOMIC 0x86DF /* ATOMIC */ + /* 0x86E0 - 0x86EF Landis & Gyr Powers */ + /* 0x8700 - 0x8710 Motorola */ +#define ETHERTYPE_RDP 0x8739 /* Control Technology Inc. RDP Without IP */ +#define ETHERTYPE_MICP 0x873A /* Control Technology Inc. Mcast Industrial Ctrl Proto. */ + /* 0x873B - 0x873C Control Technology Inc. Proprietary */ +#define ETHERTYPE_TCPCOMP 0x876B /* TCP/IP Compression (RFC1701) */ +#define ETHERTYPE_IPAS 0x876C /* IP Autonomous Systems (RFC1701) */ +#define ETHERTYPE_SECUREDATA 0x876D /* Secure Data (RFC1701) */ +#define ETHERTYPE_FLOWCONTROL 0x8808 /* 802.3x flow control packet */ +#define ETHERTYPE_SLOW 0x8809 /* 803.3ad slow protocols (LACP/Marker) */ +#define ETHERTYPE_PPP 0x880B /* PPP (obsolete by PPPOE) */ +#define ETHERTYPE_HITACHI 0x8820 /* Hitachi Cable (Optoelectronic Systems Laboratory) */ +#define ETHERTYPE_MPLS 0x8847 /* MPLS Unicast */ +#define ETHERTYPE_MPLS_MCAST 0x8848 /* MPLS Multicast */ +#define ETHERTYPE_AXIS 0x8856 /* Axis Communications AB proprietary bootstrap/config */ +#define ETHERTYPE_PPPOEDISC 0x8863 /* PPP Over Ethernet Discovery Stage */ +#define ETHERTYPE_PPPOE 0x8864 /* PPP Over Ethernet Session Stage */ +#define ETHERTYPE_LANPROBE 0x8888 /* HP LanProbe test? */ +#define ETHERTYPE_EAPOL 0x888E /* 802.1X EAP over LAN */ +#define ETHERTYPE_AOE 0x88A2 /* ATA over Ethernet */ +#define ETHERTYPE_QINQ 0x88A8 /* 802.1ad VLAN stacking */ +#define ETHERTYPE_LLDP 0x88CC /* Link Layer Discovery Protocol */ +#define ETHERTYPE_802_EX1 0x88B5 /* IEEE Std 802 - Local Experimental */ +#define ETHERTYPE_802_EX2 0x88B6 /* IEEE Std 802 - Local Experimental */ +#define ETHERTYPE_MACSEC 0x88e5 /* 802.1AE MACsec */ +#define ETHERTYPE_PBB 0x88e7 /* 802.1Q Provider Backbone Bridging */ +#define ETHERTYPE_PTP 0x88F7 /* IEEE 1588 Precision Time Protocol */ +#define ETHERTYPE_CFM 0x8902 /* 802.1ag Connectivity Fault Management */ +#define ETHERTYPE_NSH 0x894F /* Network Service Header (RFC8300) */ +#define ETHERTYPE_LOOPBACK 0x9000 /* Loopback */ +#define ETHERTYPE_LBACK ETHERTYPE_LOOPBACK /* DEC MOP loopback */ +#define ETHERTYPE_XNSSM 0x9001 /* 3Com (Formerly Bridge Communications), XNS Systems Management */ +#define ETHERTYPE_TCPSM 0x9002 /* 3Com (Formerly Bridge Communications), TCP/IP Systems Management */ +#define ETHERTYPE_BCLOOP 0x9003 /* 3Com (Formerly Bridge Communications), loopback detection */ +#define ETHERTYPE_DEBNI 0xAAAA /* DECNET? Used by VAX 6220 DEBNI */ +#define ETHERTYPE_SONIX 0xFAF5 /* Sonix Arpeggio */ +#define ETHERTYPE_VITAL 0xFF00 /* BBN VITAL-LanBridge cache wakeups */ + /* 0xFF00 - 0xFFOF ISC Bunker Ramo */ + +#define ETHERTYPE_MAX 0xFFFF /* Maximum valid ethernet type, reserved */ + +#endif /* _NET_ETHERTYPES_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/fq_codel.h b/lib/libc/include/generic-openbsd/net/fq_codel.h new file mode 100644 index 0000000000..4564164ae4 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/fq_codel.h @@ -0,0 +1,51 @@ +/* $OpenBSD: fq_codel.h,v 1.4 2020/06/18 23:29:59 dlg Exp $ */ + +/* + * Copyright (c) 2017 Mike Belopuhov + * + * 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 _NET_FQ_CODEL_H_ +#define _NET_FQ_CODEL_H_ + +/* compatible with hfsc_pktcntr */ +struct fqcodel_pktcntr { + uint64_t packets; + uint64_t bytes; +}; + +struct fqcodel_stats { + struct fqcodel_pktcntr xmit_cnt; + struct fqcodel_pktcntr drop_cnt; + + uint32_t qlength; + uint32_t qlimit; + + uint32_t flows; + uint32_t _unused; /* padding */ + + uint32_t target; + uint32_t interval; + + /* the values below are used to calculate standard deviation */ + uint64_t delaysum; /* sum of delays, us */ + uint64_t delaysumsq;/* sum of squared delays, us */ +}; + +#ifdef _KERNEL +extern const struct ifq_ops * const ifq_fqcodel_ops; +extern const struct pfq_ops * const pfq_fqcodel_ops; +#endif /* _KERNEL */ + +#endif /* _NET_FQ_CODEL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/frame.h b/lib/libc/include/generic-openbsd/net/frame.h new file mode 100644 index 0000000000..52625a59ea --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/frame.h @@ -0,0 +1,47 @@ +/* $OpenBSD: frame.h,v 1.1 2024/12/15 11:00:05 dlg Exp $ */ + +/* + * Copyright (c) 2024 David Gwynne + * + * 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 _NET_FRAME_H_ +#define _NET_FRAME_H_ + +#define FRAME_ADDRLEN 8 /* big enough for Ethernet */ +#define FRAME_DATALEN 32 + +struct sockaddr_frame { + uint8_t sfrm_len; + uint8_t sfrm_family; /* AF_FRAME */ + uint16_t sfrm_proto; + unsigned int sfrm_ifindex; + uint8_t sfrm_addr[FRAME_ADDRLEN]; + char sfrm_ifname[IFNAMSIZ]; + uint8_t sfrm_data[FRAME_DATALEN]; +}; + +#define FRAME_RECVDSTADDR 0 /* int */ +#define FRAME_RECVPRIO 1 /* int */ +#define FRAME_ADD_MEMBERSHIP 64 /* struct frame_mreq */ +#define FRAME_DEL_MEMBERSHIP 65 /* struct frame_mreq */ +#define FRAME_SENDPRIO 66 /* int: IF_HDRPRIO_{MIN-MAX,PACKET} */ + +struct frame_mreq { + unsigned int fmr_ifindex; + uint8_t fmr_addr[FRAME_ADDRLEN]; + char fmr_ifname[IFNAMSIZ]; +}; + +#endif /* _NET_FRAME_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/hfsc.h b/lib/libc/include/generic-openbsd/net/hfsc.h new file mode 100644 index 0000000000..0e2864cc05 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/hfsc.h @@ -0,0 +1,122 @@ +/* $OpenBSD: hfsc.h,v 1.14 2025/07/07 00:55:15 jsg Exp $ */ + +/* + * Copyright (c) 2012-2013 Henning Brauer + * Copyright (c) 1997-1999 Carnegie Mellon University. All Rights Reserved. + * + * Permission to use, copy, modify, and distribute this software and + * its documentation is hereby granted (including for commercial or + * for-profit use), provided that both the copyright notice and this + * permission notice appear in all copies of the software, derivative + * works, or modified versions, and any portions thereof. + * + * THIS SOFTWARE IS EXPERIMENTAL AND IS KNOWN TO HAVE BUGS, SOME OF + * WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON PROVIDES THIS + * SOFTWARE IN ITS ``AS IS'' CONDITION, 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 CARNEGIE MELLON UNIVERSITY 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. + * + * Carnegie Mellon encourages (but does not require) users of this + * software to return any improvements or extensions that they make, + * and to grant Carnegie Mellon the rights to redistribute these + * changes without encumbrance. + */ +#ifndef _HFSC_H_ +#define _HFSC_H_ + +/* hfsc class flags */ +#define HFSC_DEFAULTCLASS 0x1000 /* default class */ + +struct hfsc_pktcntr { + u_int64_t packets; + u_int64_t bytes; +}; + +#define PKTCNTR_INC(cntr, len) \ + do { (cntr)->packets++; (cntr)->bytes += len; } while (0) + +struct hfsc_sc { + u_int m1; /* slope of the first segment in bits/sec */ + u_int d; /* the x-projection of the first segment in msec */ + u_int m2; /* slope of the second segment in bits/sec */ +}; + +/* special class handles */ +#define HFSC_ROOT_CLASS 0x10000 +#define HFSC_DEFAULT_CLASSES 64 +#define HFSC_MAX_CLASSES 65535 + +/* service curve types */ +#define HFSC_REALTIMESC 1 +#define HFSC_LINKSHARINGSC 2 +#define HFSC_UPPERLIMITSC 4 +#define HFSC_DEFAULTSC (HFSC_REALTIMESC|HFSC_LINKSHARINGSC) + +struct hfsc_class_stats { + struct hfsc_pktcntr xmit_cnt; + struct hfsc_pktcntr drop_cnt; + + u_int qlength; + u_int qlimit; + u_int period; + + u_int class_id; + u_int32_t class_handle; + struct hfsc_sc rsc; + struct hfsc_sc fsc; + struct hfsc_sc usc; /* upper limit service curve */ + + u_int64_t total; /* total work in bytes */ + u_int64_t cumul; /* cumulative work in bytes + done by real-time criteria */ + u_int64_t d; /* deadline */ + u_int64_t e; /* eligible time */ + u_int64_t vt; /* virtual time */ + u_int64_t f; /* fit time for upper-limit */ + + /* info helpful for debugging */ + u_int64_t initvt; /* init virtual time */ + u_int64_t vtoff; /* cl_vt_ipoff */ + u_int64_t cvtmax; /* cl_maxvt */ + u_int64_t myf; /* cl_myf */ + u_int64_t cfmin; /* cl_mincf */ + u_int64_t cvtmin; /* cl_mincvt */ + u_int64_t myfadj; /* cl_myfadj */ + u_int64_t vtadj; /* cl_vtadj */ + u_int64_t cur_time; + u_int32_t machclk_freq; + + u_int vtperiod; /* vt period sequence no */ + u_int parentperiod; /* parent's vt period seqno */ + int nactive; /* number of active children */ + + /* red and rio related info */ + int qtype; +/* struct redstats red[3]; */ +}; + +#ifdef _KERNEL +struct ifnet; +struct ifqueue; +struct pf_queuespec; +struct hfsc_if; + +extern const struct ifq_ops * const ifq_hfsc_ops; +extern const struct pfq_ops * const pfq_hfsc_ops; + +#define HFSC_ENABLED(ifq) ((ifq)->ifq_ops == ifq_hfsc_ops) +#define HFSC_DEFAULT_QLIMIT 50 + +void hfsc_initialize(void); + +#endif /* _KERNEL */ +#endif /* _HFSC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/if.h b/lib/libc/include/generic-openbsd/net/if.h new file mode 100644 index 0000000000..f6ccd8ad0e --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/if.h @@ -0,0 +1,576 @@ +/* $OpenBSD: if.h,v 1.221 2025/09/09 09:16:18 bluhm Exp $ */ +/* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)if.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NET_IF_H_ +#define _NET_IF_H_ + +#include + +/* + * Length of interface external name, including terminating '\0'. + * Note: this is the same size as a generic device's external name. + */ +#define IF_NAMESIZE 16 + +struct if_nameindex { + unsigned int if_index; + char *if_name; +}; + +#ifndef _KERNEL +__BEGIN_DECLS +unsigned int if_nametoindex(const char *); +char *if_indextoname(unsigned int, char *); +struct if_nameindex *if_nameindex(void); +void if_freenameindex(struct if_nameindex *); +__END_DECLS +#endif + +#if __BSD_VISIBLE + +#include +#include +#include + +/* + * Structure used to query names of interface cloners. + */ +struct if_clonereq { + int ifcr_total; /* total cloners (out) */ + int ifcr_count; /* room for this many in user buffer */ + char *ifcr_buffer; /* buffer for cloner names */ +}; + +#define MCLPOOLS 8 /* number of cluster pools */ + +struct if_rxring { + int rxr_adjusted; + u_int rxr_alive; + u_int rxr_cwm; + u_int rxr_lwm; + u_int rxr_hwm; +}; + +struct if_rxring_info { + char ifr_name[16]; /* name of the ring */ + u_int ifr_size; /* size of the packets on the ring */ + struct if_rxring ifr_info; +}; + +/* Structure used in SIOCGIFRXR request. */ +struct if_rxrinfo { + u_int ifri_total; + struct if_rxring_info *ifri_entries; +}; + +/* + * Structure defining statistics and other data kept regarding a network + * interface. + */ +struct if_data { + /* generic interface information */ + u_char ifi_type; /* ethernet, tokenring, etc. */ + u_char ifi_addrlen; /* media address length */ + u_char ifi_hdrlen; /* media header length */ + u_char ifi_link_state; /* current link state */ + u_int32_t ifi_mtu; /* maximum transmission unit */ + u_int32_t ifi_metric; /* routing metric (external only) */ + u_int32_t ifi_rdomain; /* routing instance */ + u_int64_t ifi_baudrate; /* linespeed */ + /* volatile statistics */ + u_int64_t ifi_ipackets; /* packets received on interface */ + u_int64_t ifi_ierrors; /* input errors on interface */ + u_int64_t ifi_opackets; /* packets sent on interface */ + u_int64_t ifi_oerrors; /* output errors on interface */ + u_int64_t ifi_collisions; /* collisions on csma interfaces */ + u_int64_t ifi_ibytes; /* total number of octets received */ + u_int64_t ifi_obytes; /* total number of octets sent */ + u_int64_t ifi_imcasts; /* packets received via multicast */ + u_int64_t ifi_omcasts; /* packets sent via multicast */ + u_int64_t ifi_iqdrops; /* dropped on input, this interface */ + u_int64_t ifi_oqdrops; /* dropped on output, this interface */ + u_int64_t ifi_noproto; /* destined for unsupported protocol */ + u_int32_t ifi_capabilities; /* interface capabilities */ + struct timeval ifi_lastchange; /* last operational state change */ +}; + +#define IFQ_NQUEUES 8 +#define IFQ_MINPRIO 0 +#define IFQ_MAXPRIO IFQ_NQUEUES - 1 +#define IFQ_DEFPRIO 3 +#define IFQ_PRIO2TOS(_p) ((_p) << 5) +#define IFQ_TOS2PRIO(_t) ((_t) >> 5) + +/* + * Values for if_link_state. + */ +#define LINK_STATE_UNKNOWN 0 /* link unknown */ +#define LINK_STATE_INVALID 1 /* link invalid */ +#define LINK_STATE_DOWN 2 /* link is down */ +#define LINK_STATE_KALIVE_DOWN 3 /* keepalive reports down */ +#define LINK_STATE_UP 4 /* link is up */ +#define LINK_STATE_HALF_DUPLEX 5 /* link is up and half duplex */ +#define LINK_STATE_FULL_DUPLEX 6 /* link is up and full duplex */ + +#define LINK_STATE_IS_UP(_s) \ + ((_s) >= LINK_STATE_UP || (_s) == LINK_STATE_UNKNOWN) + +/* + * Status bit descriptions for the various interface types. + */ +struct if_status_description { + u_char ifs_type; + u_char ifs_state; + const char *ifs_string; +}; + +#define LINK_STATE_DESC_MATCH(_ifs, _t, _s) \ + (((_ifs)->ifs_type == (_t) || (_ifs)->ifs_type == 0) && \ + (_ifs)->ifs_state == (_s)) + + +#define LINK_STATE_DESCRIPTIONS { \ + { IFT_ETHER, LINK_STATE_DOWN, "no carrier" }, \ + \ + { IFT_IEEE80211, LINK_STATE_DOWN, "no network" }, \ + \ + { IFT_PPP, LINK_STATE_DOWN, "no carrier" }, \ + \ + { IFT_CARP, LINK_STATE_DOWN, "backup" }, \ + { IFT_CARP, LINK_STATE_UP, "master" }, \ + { IFT_CARP, LINK_STATE_HALF_DUPLEX, "master" }, \ + { IFT_CARP, LINK_STATE_FULL_DUPLEX, "master" }, \ + \ + { 0, LINK_STATE_UP, "active" }, \ + { 0, LINK_STATE_HALF_DUPLEX, "active" }, \ + { 0, LINK_STATE_FULL_DUPLEX, "active" }, \ + \ + { 0, LINK_STATE_UNKNOWN, "unknown" }, \ + { 0, LINK_STATE_INVALID, "invalid" }, \ + { 0, LINK_STATE_DOWN, "down" }, \ + { 0, LINK_STATE_KALIVE_DOWN, "keepalive down" }, \ + { 0, 0, NULL } \ +} + +/* Traditional BSD name for length of interface external name. */ +#define IFNAMSIZ IF_NAMESIZE + +/* + * Length of interface description, including terminating '\0'. + */ +#define IFDESCRSIZE 64 + +/* + * Interface flags can be either owned by the stack or the driver. The + * symbols below document who is toggling which flag. + * + * I immutable after creation + * N written by the stack (upon user request) + * d written by the driver + * c for userland compatibility only + */ +#define IFF_UP 0x1 /* [N] interface is up */ +#define IFF_BROADCAST 0x2 /* [I] broadcast address valid */ +#define IFF_DEBUG 0x4 /* [N] turn on debugging */ +#define IFF_LOOPBACK 0x8 /* [I] is a loopback net */ +#define IFF_POINTOPOINT 0x10 /* [I] is point-to-point link */ +#define IFF_STATICARP 0x20 /* [N] only static ARP */ +#define IFF_RUNNING 0x40 /* [d] resources allocated */ +#define IFF_NOARP 0x80 /* [N] no address resolution protocol */ +#define IFF_PROMISC 0x100 /* [N] receive all packets */ +#define IFF_ALLMULTI 0x200 /* [d] receive all multicast packets */ +#define IFF_OACTIVE 0x400 /* [c] transmission in progress */ +#define IFF_SIMPLEX 0x800 /* [I] can't hear own transmissions */ +#define IFF_LINK0 0x1000 /* [N] per link layer defined bit */ +#define IFF_LINK1 0x2000 /* [N] per link layer defined bit */ +#define IFF_LINK2 0x4000 /* [N] per link layer defined bit */ +#define IFF_MULTICAST 0x8000 /* [I] supports multicast */ + +/* flags set internally only: */ +#define IFF_CANTCHANGE \ + (IFF_BROADCAST|IFF_LOOPBACK|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\ + IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI) + +#define IFXF_MPSAFE 0x1 /* [I] if_start is mpsafe */ +#define IFXF_CLONED 0x2 /* [I] pseudo interface */ +#define IFXF_AUTOCONF6TEMP 0x4 /* [N] v6 temporary addrs enabled */ +#define IFXF_MPLS 0x8 /* [N] supports MPLS */ +#define IFXF_WOL 0x10 /* [N] wake on lan enabled */ +#define IFXF_AUTOCONF6 0x20 /* [N] v6 autoconf enabled */ +#define IFXF_INET6_NOSOII 0x40 /* [N] don't do RFC 7217 */ +#define IFXF_AUTOCONF4 0x80 /* [N] v4 autoconf (aka dhcp) enabled */ +#define IFXF_MONITOR 0x100 /* [N] only used for bpf */ +#define IFXF_LRO 0x200 /* [N] TCP large recv offload */ + +#define IFXF_CANTCHANGE \ + (IFXF_MPSAFE|IFXF_CLONED) + +/* + * Some convenience macros used for setting ifi_baudrate. + */ +#define IF_Kbps(x) ((x) * 1000ULL) /* kilobits/sec. */ +#define IF_Mbps(x) (IF_Kbps((x) * 1000ULL)) /* megabits/sec. */ +#define IF_Gbps(x) (IF_Mbps((x) * 1000ULL)) /* gigabits/sec. */ + +/* Capabilities that interfaces can advertise. */ +#define IFCAP_CSUM_IPv4 0x00000001 /* can do IPv4 header csum */ +#define IFCAP_CSUM_TCPv4 0x00000002 /* can do IPv4/TCP csum */ +#define IFCAP_CSUM_UDPv4 0x00000004 /* can do IPv4/UDP csum */ +#define IFCAP_VLAN_MTU 0x00000010 /* VLAN-compatible MTU */ +#define IFCAP_VLAN_HWTAGGING 0x00000020 /* hardware VLAN tag support */ +#define IFCAP_VLAN_HWOFFLOAD 0x00000040 /* hw offload w/ inline tag */ +#define IFCAP_CSUM_TCPv6 0x00000080 /* can do IPv6/TCP checksums */ +#define IFCAP_CSUM_UDPv6 0x00000100 /* can do IPv6/UDP checksums */ +#define IFCAP_TSOv4 0x00001000 /* IPv4/TCP segment offload */ +#define IFCAP_TSOv6 0x00002000 /* IPv6/TCP segment offload */ +#define IFCAP_LRO 0x00004000 /* TCP large recv offload */ +#define IFCAP_WOL 0x00008000 /* can do wake on lan */ + +#define IFCAP_CSUM_MASK (IFCAP_CSUM_IPv4 | IFCAP_CSUM_TCPv4 | \ + IFCAP_CSUM_UDPv4 | IFCAP_CSUM_TCPv6 | IFCAP_CSUM_UDPv6) + +/* symbolic names for terminal (per-protocol) CTL_IFQ_ nodes */ +#define IFQCTL_LEN 1 +#define IFQCTL_MAXLEN 2 +#define IFQCTL_DROPS 3 +#define IFQCTL_CONGESTION 4 +#define IFQCTL_MAXID 5 + +/* sysctl for ifq (per-protocol packet input queue variant of ifqueue) */ +#define CTL_IFQ_NAMES { \ + { 0, 0 }, \ + { "len", CTLTYPE_INT }, \ + { "maxlen", CTLTYPE_INT }, \ + { "drops", CTLTYPE_INT }, \ + { "congestion", CTLTYPE_INT }, \ +} + +/* + * Message format for use in obtaining information about interfaces + * from sysctl and the routing socket. + */ +struct if_msghdr { + u_short ifm_msglen; /* to skip over non-understood messages */ + u_char ifm_version; /* future binary compatibility */ + u_char ifm_type; /* message type */ + u_short ifm_hdrlen; /* sizeof(if_msghdr) to skip over the header */ + u_short ifm_index; /* index for associated ifp */ + u_short ifm_tableid; /* routing table id */ + u_char ifm_pad1; + u_char ifm_pad2; + int ifm_addrs; /* like rtm_addrs */ + int ifm_flags; /* value of if_flags */ + int ifm_xflags; + struct if_data ifm_data;/* statistics and other data about if */ +}; + +/* + * Message format for use in obtaining information about interface addresses + * from sysctl and the routing socket. + */ +struct ifa_msghdr { + u_short ifam_msglen; /* to skip over non-understood messages */ + u_char ifam_version; /* future binary compatibility */ + u_char ifam_type; /* message type */ + u_short ifam_hdrlen; /* sizeof(ifa_msghdr) to skip over the header */ + u_short ifam_index; /* index for associated ifp */ + u_short ifam_tableid; /* routing table id */ + u_char ifam_pad1; + u_char ifam_pad2; + int ifam_addrs; /* like rtm_addrs */ + int ifam_flags; /* value of ifa_flags */ + int ifam_metric; /* value of ifa_metric */ +}; + +/* + * Message format announcing the arrival or departure of a network interface. + */ +struct if_announcemsghdr { + u_short ifan_msglen; /* to skip over non-understood messages */ + u_char ifan_version; /* future binary compatibility */ + u_char ifan_type; /* message type */ + u_short ifan_hdrlen; /* sizeof(if_announcemsghdr) to skip header */ + u_short ifan_index; /* index for associated ifp */ + u_short ifan_what; /* what type of announcement */ + char ifan_name[IFNAMSIZ]; /* if name, e.g. "en0" */ +}; + +#define IFAN_ARRIVAL 0 /* interface arrival */ +#define IFAN_DEPARTURE 1 /* interface departure */ + +/* message format used to pass 80211 interface info */ +struct if_ieee80211_data { + uint8_t ifie_channel; /* IEEE80211_CHAN_MAX == 255 */ + uint8_t ifie_nwid_len; + uint32_t ifie_flags; /* ieee80211com.ic_flags */ + uint32_t ifie_xflags; /* ieee80211com.ic xflags */ + uint8_t ifie_nwid[32]; /* IEEE80211_NWID_LEN */ + uint8_t ifie_addr[6]; /* IEEE80211_ADDR_LEN */ +}; + +struct if_ieee80211_msghdr { + uint16_t ifim_msglen; + uint8_t ifim_version; + uint8_t ifim_type; + uint16_t ifim_hdrlen; + uint16_t ifim_index; + uint16_t ifim_tableid; + + struct if_ieee80211_data ifim_ifie; +}; + +/* message format used to pass interface name to index mappings */ +struct if_nameindex_msg { + unsigned int if_index; + char if_name[IFNAMSIZ]; +}; + +/* + * interface groups + */ + +#define IFG_ALL "all" /* group contains all interfaces */ +#define IFG_EGRESS "egress" /* if(s) default route(s) point to */ + +struct ifg_req { + union { + char ifgrqu_group[IFNAMSIZ]; + char ifgrqu_member[IFNAMSIZ]; + } ifgrq_ifgrqu; +#define ifgrq_group ifgrq_ifgrqu.ifgrqu_group +#define ifgrq_member ifgrq_ifgrqu.ifgrqu_member +}; + +struct ifg_attrib { + int ifg_carp_demoted; +}; + +/* + * Used to lookup groups for an interface + */ +struct ifgroupreq { + char ifgr_name[IFNAMSIZ]; + u_int ifgr_len; + union { + char ifgru_group[IFNAMSIZ]; + struct ifg_req *ifgru_groups; + struct ifg_attrib ifgru_attrib; + } ifgr_ifgru; +#define ifgr_group ifgr_ifgru.ifgru_group +#define ifgr_groups ifgr_ifgru.ifgru_groups +#define ifgr_attrib ifgr_ifgru.ifgru_attrib +}; + +/* + * Interface request structure used for socket + * ioctl's. All interface ioctl's must have parameter + * definitions which begin with ifr_name. The + * remainder may be interface specific. + */ +struct ifreq { + char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */ + union { + struct sockaddr ifru_addr; + struct sockaddr ifru_dstaddr; + struct sockaddr ifru_broadaddr; + short ifru_flags; + int ifru_metric; + int64_t ifru_vnetid; + uint64_t ifru_media; + caddr_t ifru_data; + unsigned int ifru_index; + } ifr_ifru; +#define ifr_addr ifr_ifru.ifru_addr /* address */ +#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */ +#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */ +#define ifr_flags ifr_ifru.ifru_flags /* flags */ +#define ifr_metric ifr_ifru.ifru_metric /* metric */ +#define ifr_mtu ifr_ifru.ifru_metric /* mtu (overload) */ +#define ifr_hardmtu ifr_ifru.ifru_metric /* hardmtu (overload) */ +#define ifr_media ifr_ifru.ifru_media /* media options */ +#define ifr_rdomainid ifr_ifru.ifru_metric /* VRF instance (overload) */ +#define ifr_vnetid ifr_ifru.ifru_vnetid /* Virtual Net Id */ +#define ifr_ttl ifr_ifru.ifru_metric /* tunnel TTL (overload) */ +#define ifr_df ifr_ifru.ifru_metric /* tunnel DF (overload) */ +#define ifr_data ifr_ifru.ifru_data /* for use by interface */ +#define ifr_index ifr_ifru.ifru_index /* interface index */ +#define ifr_llprio ifr_ifru.ifru_metric /* link layer priority */ +#define ifr_hdrprio ifr_ifru.ifru_metric /* header prio field config */ +#define ifr_pwe3 ifr_ifru.ifru_metric /* PWE3 type */ +}; + +#define IF_HDRPRIO_MIN IFQ_MINPRIO +#define IF_HDRPRIO_MAX IFQ_MAXPRIO +#define IF_HDRPRIO_PACKET -1 /* use mbuf prio */ +#define IF_HDRPRIO_PAYLOAD -2 /* copy payload prio */ +#define IF_HDRPRIO_OUTER -3 /* use outer prio */ + +#define IF_PWE3_ETHERNET 1 /* ethernet or ethernet tagged */ +#define IF_PWE3_IP 2 /* IP layer 2 */ + +struct ifaliasreq { + char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */ + union { + struct sockaddr ifrau_addr; + int ifrau_align; + } ifra_ifrau; +#ifndef ifra_addr +#define ifra_addr ifra_ifrau.ifrau_addr +#endif + struct sockaddr ifra_dstaddr; +#define ifra_broadaddr ifra_dstaddr + struct sockaddr ifra_mask; +}; + +struct ifmediareq { + char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */ + uint64_t ifm_current; /* get/set current media options */ + uint64_t ifm_mask; /* don't care mask */ + uint64_t ifm_status; /* media status */ + uint64_t ifm_active; /* active options */ + int ifm_count; /* # entries in ifm_ulist array */ + uint64_t *ifm_ulist; /* media words */ +}; + +struct ifkalivereq { + char ikar_name[IFNAMSIZ]; /* if name, e.g. "en0" */ + int ikar_timeo; + int ikar_cnt; +}; + +/* + * Structure used in SIOCGIFCONF request. + * Used to retrieve interface configuration + * for machine (useful for programs which + * must know all networks accessible). + */ +struct ifconf { + int ifc_len; /* size of associated buffer */ + union { + caddr_t ifcu_buf; + struct ifreq *ifcu_req; + } ifc_ifcu; +#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */ +#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */ +}; + +/* + * Structure for SIOC[AGD]LIFADDR + */ +struct if_laddrreq { + char iflr_name[IFNAMSIZ]; + unsigned int flags; +#define IFLR_PREFIX 0x8000 /* in: prefix given out: kernel fills id */ + unsigned int prefixlen; /* in/out */ + struct sockaddr_storage addr; /* in/out */ + struct sockaddr_storage dstaddr; /* out */ +}; + +/* SIOCIFAFDETACH */ +struct if_afreq { + char ifar_name[IFNAMSIZ]; + sa_family_t ifar_af; +}; + +/* SIOC[SG]IFPARENT */ +struct if_parent { + char ifp_name[IFNAMSIZ]; + char ifp_parent[IFNAMSIZ]; +}; + +/* SIOCGIFSFFPAGE */ + +#define IFSFF_ADDR_EEPROM 0xa0 +#define IFSFF_ADDR_DDM 0xa2 + +#define IFSFF_DATA_LEN 256 + +struct if_sffpage { + char sff_ifname[IFNAMSIZ]; /* u -> k */ + uint8_t sff_addr; /* u -> k */ + uint8_t sff_page; /* u -> k */ + uint8_t sff_data[IFSFF_DATA_LEN]; /* k -> u */ +}; + +#include + +#ifdef _KERNEL +struct socket; +struct ifnet; +struct ifq_ops; + +void if_alloc_sadl(struct ifnet *); +void if_free_sadl(struct ifnet *); +void if_attach(struct ifnet *); +void if_attach_queues(struct ifnet *, unsigned int); +void if_attach_iqueues(struct ifnet *, unsigned int); +void if_attach_ifq(struct ifnet *, const struct ifq_ops *, void *); +void if_attachhead(struct ifnet *); +void if_deactivate(struct ifnet *); +void if_detach(struct ifnet *); +void if_down(struct ifnet *); +void if_downall(void); +void if_link_state_change(struct ifnet *); +void if_up(struct ifnet *); +void if_getdata(struct ifnet *, struct if_data *); +void ifinit(void); +int ifioctl(struct socket *, u_long, caddr_t, struct proc *); +int ifpromisc(struct ifnet *, int); +int ifsetlro(struct ifnet *, int); +struct ifg_group *if_creategroup(const char *); +int if_addgroup(struct ifnet *, const char *); +int if_delgroup(struct ifnet *, const char *); +void if_group_routechange(const struct sockaddr *, const struct sockaddr *); +struct ifnet *if_unit(const char *); +struct ifnet *if_get(unsigned int); +struct ifnet *if_ref(struct ifnet *); +void if_put(struct ifnet *); +void ifnewlladdr(struct ifnet *); +void if_congestion(void); +int if_congested(void); +__dead void unhandled_af(int); +int if_setlladdr(struct ifnet *, const uint8_t *); +void softnet_init(void); +void softnet_percpu(void); +unsigned int + softnet_count(void); +struct taskq * + net_tq(unsigned int); +void net_tq_barriers(const char *); + +#endif /* _KERNEL */ + +#endif /* __BSD_VISIBLE */ + +#endif /* _NET_IF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/if_arp.h b/lib/libc/include/generic-openbsd/net/if_arp.h new file mode 100644 index 0000000000..a9d69b750d --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/if_arp.h @@ -0,0 +1,74 @@ +/* $OpenBSD: if_arp.h,v 1.8 2024/10/15 00:41:40 jsg Exp $ */ +/* $NetBSD: if_arp.h,v 1.8 1995/03/08 02:56:52 cgd Exp $ */ + +/* + * Copyright (c) 1986, 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. + * + * @(#)if_arp.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NET_IF_ARP_H_ +#define _NET_IF_ARP_H_ +/* + * Address Resolution Protocol. + * + * See RFC 826 for protocol description. ARP packets are variable + * in size; the arphdr structure defines the fixed-length portion. + * Protocol type values are the same as those for 10 Mb/s Ethernet. + * It is followed by the variable-sized fields ar_sha, arp_spa, + * arp_tha and arp_tpa in that order, according to the lengths + * specified. Field names used correspond to RFC 826. + */ +struct arphdr { + u_int16_t ar_hrd; /* format of hardware address */ +#define ARPHRD_ETHER 1 /* ethernet hardware format */ +#define ARPHRD_IEEE802 6 /* IEEE 802 hardware format */ +#define ARPHRD_FRELAY 15 /* frame relay hardware format */ +#define ARPHRD_IEEE1394 24 /* IEEE 1394 (FireWire) hardware format */ + u_int16_t ar_pro; /* format of protocol address */ + u_int8_t ar_hln; /* length of hardware address */ + u_int8_t ar_pln; /* length of protocol address */ + u_int16_t ar_op; /* one of: */ +#define ARPOP_REQUEST 1 /* request to resolve address */ +#define ARPOP_REPLY 2 /* response to previous request */ +#define ARPOP_REVREQUEST 3 /* request protocol address given hardware */ +#define ARPOP_REVREPLY 4 /* response giving protocol address */ +#define ARPOP_INVREQUEST 8 /* request to identify peer */ +#define ARPOP_INVREPLY 9 /* response identifying peer */ +/* + * The remaining fields are variable in size, + * according to the sizes above. + */ +#ifdef COMMENT_ONLY + u_int8_t ar_sha[]; /* sender hardware address */ + u_int8_t ar_spa[]; /* sender protocol address */ + u_int8_t ar_tha[]; /* target hardware address */ + u_int8_t ar_tpa[]; /* target protocol address */ +#endif +}; +#endif /* _NET_IF_ARP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/if_bpe.h b/lib/libc/include/generic-openbsd/net/if_bpe.h new file mode 100644 index 0000000000..1e3d93b7ea --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/if_bpe.h @@ -0,0 +1,26 @@ +/* $OpenBSD: if_bpe.h,v 1.2 2025/03/02 21:28:31 bluhm Exp $ */ + +/* + * Copyright (c) 2018 David Gwynne + * + * 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 _NET_IF_BPE_H +#define _NET_IF_BPE_H + +#ifdef _KERNEL +void bpe_input(struct ifnet *, struct mbuf *, struct netstack *); +#endif + +#endif /* _NET_IF_GRE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/if_bridge.h b/lib/libc/include/generic-openbsd/net/if_bridge.h new file mode 100644 index 0000000000..f946c66949 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/if_bridge.h @@ -0,0 +1,533 @@ +/* $OpenBSD: if_bridge.h,v 1.73 2021/11/11 10:03:10 claudio Exp $ */ + +/* + * Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net) + * Copyright (c) 2006 Andrew Thompson (thompsa@FreeBSD.org) + * 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. + * + * Effort sponsored in part by the Defense Advanced Research Projects + * Agency (DARPA) and Air Force Research Laboratory, Air Force + * Materiel Command, USAF, under agreement number F30602-01-2-0537. + * + */ + +#ifndef _NET_IF_BRIDGE_H_ +#define _NET_IF_BRIDGE_H_ + +#include +#include +#include + +/* + * Bridge control request: add/delete member interfaces. + */ +struct ifbreq { + char ifbr_name[IFNAMSIZ]; /* bridge ifs name */ + char ifbr_ifsname[IFNAMSIZ]; /* member ifs name */ + u_int32_t ifbr_ifsflags; /* member ifs flags */ + u_int32_t ifbr_portno; /* member port number */ + u_int32_t ifbr_protected; /* protected domains */ + + u_int8_t ifbr_state; /* member stp state */ + u_int8_t ifbr_priority; /* member stp priority */ + u_int32_t ifbr_path_cost; /* member stp path cost */ + u_int32_t ifbr_stpflags; /* member stp flags */ + u_int8_t ifbr_proto; /* member stp protocol */ + u_int8_t ifbr_role; /* member stp role */ + u_int32_t ifbr_fwd_trans; /* member stp fwd transitions */ + u_int64_t ifbr_desg_bridge; /* member stp designated bridge */ + u_int32_t ifbr_desg_port; /* member stp designated port */ + u_int64_t ifbr_root_bridge; /* member stp root bridge */ + u_int32_t ifbr_root_cost; /* member stp root cost */ + u_int32_t ifbr_root_port; /* member stp root port */ +}; + +/* SIOCBRDGIFFLGS, SIOCBRDGIFFLGS */ +#define IFBIF_LEARNING 0x0001 /* ifs can learn */ +#define IFBIF_DISCOVER 0x0002 /* ifs sends packets w/unknown dest */ +#define IFBIF_BLOCKNONIP 0x0004 /* ifs blocks non-IP/ARP in/out */ +#define IFBIF_STP 0x0008 /* ifs participates in spanning tree */ +#define IFBIF_BSTP_EDGE 0x0010 /* member stp edge port */ +#define IFBIF_BSTP_AUTOEDGE 0x0020 /* member stp autoedge enabled */ +#define IFBIF_BSTP_PTP 0x0040 /* member stp ptp */ +#define IFBIF_BSTP_AUTOPTP 0x0080 /* member stp autoptp enabled */ +#define IFBIF_SPAN 0x0100 /* ifs is a span port (ro) */ +#define IFBIF_LOCAL 0x1000 /* local port in switch(4) */ +#define IFBIF_RO_MASK 0x0f00 /* read only bits */ + +/* SIOCBRDGFLUSH */ +#define IFBF_FLUSHDYN 0x0 /* flush dynamic addresses only */ +#define IFBF_FLUSHALL 0x1 /* flush all addresses from cache */ + +/* port states */ +#define BSTP_IFSTATE_DISABLED 0 +#define BSTP_IFSTATE_LISTENING 1 +#define BSTP_IFSTATE_LEARNING 2 +#define BSTP_IFSTATE_FORWARDING 3 +#define BSTP_IFSTATE_BLOCKING 4 +#define BSTP_IFSTATE_DISCARDING 5 + +#define BSTP_TCSTATE_ACTIVE 1 +#define BSTP_TCSTATE_DETECTED 2 +#define BSTP_TCSTATE_INACTIVE 3 +#define BSTP_TCSTATE_LEARNING 4 +#define BSTP_TCSTATE_PROPAG 5 +#define BSTP_TCSTATE_ACK 6 +#define BSTP_TCSTATE_TC 7 +#define BSTP_TCSTATE_TCN 8 + +#define BSTP_ROLE_DISABLED 0 +#define BSTP_ROLE_ROOT 1 +#define BSTP_ROLE_DESIGNATED 2 +#define BSTP_ROLE_ALTERNATE 3 +#define BSTP_ROLE_BACKUP 4 + +/* + * Interface list structure + */ +struct ifbifconf { + char ifbic_name[IFNAMSIZ]; /* bridge ifs name */ + u_int32_t ifbic_len; /* buffer size */ + union { + caddr_t ifbicu_buf; + struct ifbreq *ifbicu_req; + } ifbic_ifbicu; +#define ifbic_buf ifbic_ifbicu.ifbicu_buf +#define ifbic_req ifbic_ifbicu.ifbicu_req +}; + +/* + * Bridge address request + */ +struct ifbareq { + char ifba_name[IFNAMSIZ]; /* bridge name */ + char ifba_ifsname[IFNAMSIZ]; /* destination ifs */ + u_int8_t ifba_age; /* address age */ + u_int8_t ifba_flags; /* address flags */ + struct ether_addr ifba_dst; /* destination addr */ + struct sockaddr_storage ifba_dstsa; /* tunnel endpoint */ +}; + +#define IFBAF_TYPEMASK 0x03 /* address type mask */ +#define IFBAF_DYNAMIC 0x00 /* dynamically learned */ +#define IFBAF_STATIC 0x01 /* static address */ + +struct ifbaconf { + char ifbac_name[IFNAMSIZ]; /* bridge ifs name */ + u_int32_t ifbac_len; /* buffer size */ + union { + caddr_t ifbacu_buf; /* buffer */ + struct ifbareq *ifbacu_req; /* request pointer */ + } ifbac_ifbacu; +#define ifbac_buf ifbac_ifbacu.ifbacu_buf +#define ifbac_req ifbac_ifbacu.ifbacu_req +}; + +struct ifbrparam { + char ifbrp_name[IFNAMSIZ]; + union { + u_int32_t ifbrpu_csize; /* cache size */ + int ifbrpu_ctime; /* cache time (sec) */ + u_int16_t ifbrpu_prio; /* bridge priority */ + u_int8_t ifbrpu_hellotime; /* hello time (sec) */ + u_int8_t ifbrpu_fwddelay; /* fwd delay (sec) */ + u_int8_t ifbrpu_maxage; /* max age (sec) */ + u_int8_t ifbrpu_proto; /* bridge protocol */ + u_int8_t ifbrpu_txhc; /* bpdu tx holdcount */ + } ifbrp_ifbrpu; +}; +#define ifbrp_csize ifbrp_ifbrpu.ifbrpu_csize +#define ifbrp_ctime ifbrp_ifbrpu.ifbrpu_ctime +#define ifbrp_prio ifbrp_ifbrpu.ifbrpu_prio +#define ifbrp_proto ifbrp_ifbrpu.ifbrpu_proto +#define ifbrp_txhc ifbrp_ifbrpu.ifbrpu_txhc +#define ifbrp_hellotime ifbrp_ifbrpu.ifbrpu_hellotime +#define ifbrp_fwddelay ifbrp_ifbrpu.ifbrpu_fwddelay +#define ifbrp_maxage ifbrp_ifbrpu.ifbrpu_maxage + +/* Protocol versions */ +#define BSTP_PROTO_ID 0x00 +#define BSTP_PROTO_STP 0x00 +#define BSTP_PROTO_RSTP 0x02 +#define BSTP_PROTO_MAX BSTP_PROTO_RSTP + +/* + * Bridge current operational parameters structure. + */ +struct ifbropreq { + char ifbop_name[IFNAMSIZ]; + u_int8_t ifbop_holdcount; + u_int8_t ifbop_maxage; + u_int8_t ifbop_hellotime; + u_int8_t ifbop_fwddelay; + u_int8_t ifbop_protocol; + u_int16_t ifbop_priority; + u_int64_t ifbop_root_bridge; + u_int16_t ifbop_root_port; + u_int32_t ifbop_root_path_cost; + u_int64_t ifbop_desg_bridge; + struct timeval ifbop_last_tc_time; +}; + +/* + * Bridge mac rules + */ +struct ifbrarpf { + u_int16_t brla_flags; + u_int16_t brla_op; + struct ether_addr brla_sha; + struct in_addr brla_spa; + struct ether_addr brla_tha; + struct in_addr brla_tpa; +}; +#define BRLA_ARP 0x01 +#define BRLA_RARP 0x02 +#define BRLA_SHA 0x10 +#define BRLA_SPA 0x20 +#define BRLA_THA 0x40 +#define BRLA_TPA 0x80 + +struct ifbrlreq { + char ifbr_name[IFNAMSIZ]; /* bridge ifs name */ + char ifbr_ifsname[IFNAMSIZ]; /* member ifs name */ + u_int8_t ifbr_action; /* disposition */ + u_int8_t ifbr_flags; /* flags */ + struct ether_addr ifbr_src; /* source mac */ + struct ether_addr ifbr_dst; /* destination mac */ + char ifbr_tagname[PF_TAG_NAME_SIZE]; /* pf tagname */ + struct ifbrarpf ifbr_arpf; /* arp filter */ +}; +#define BRL_ACTION_BLOCK 0x01 /* block frame */ +#define BRL_ACTION_PASS 0x02 /* pass frame */ +#define BRL_FLAG_IN 0x08 /* input rule */ +#define BRL_FLAG_OUT 0x04 /* output rule */ +#define BRL_FLAG_SRCVALID 0x02 /* src valid */ +#define BRL_FLAG_DSTVALID 0x01 /* dst valid */ + +struct ifbrlconf { + char ifbrl_name[IFNAMSIZ]; /* bridge ifs name */ + char ifbrl_ifsname[IFNAMSIZ];/* member ifs name */ + u_int32_t ifbrl_len; /* buffer size */ + union { + caddr_t ifbrlu_buf; + struct ifbrlreq *ifbrlu_req; + } ifbrl_ifbrlu; +#define ifbrl_buf ifbrl_ifbrlu.ifbrlu_buf +#define ifbrl_req ifbrl_ifbrlu.ifbrlu_req +}; + +#ifdef _KERNEL + +#include + +/* STP port flags */ +#define BSTP_PORT_CANMIGRATE 0x0001 +#define BSTP_PORT_NEWINFO 0x0002 +#define BSTP_PORT_DISPUTED 0x0004 +#define BSTP_PORT_ADMCOST 0x0008 +#define BSTP_PORT_AUTOEDGE 0x0010 +#define BSTP_PORT_AUTOPTP 0x0020 + +/* BPDU priority */ +#define BSTP_PDU_SUPERIOR 1 +#define BSTP_PDU_REPEATED 2 +#define BSTP_PDU_INFERIOR 3 +#define BSTP_PDU_INFERIORALT 4 +#define BSTP_PDU_OTHER 5 + +/* BPDU flags */ +#define BSTP_PDU_PRMASK 0x0c /* Port Role */ +#define BSTP_PDU_PRSHIFT 2 /* Port Role offset */ +#define BSTP_PDU_F_UNKN 0x00 /* Unknown port (00) */ +#define BSTP_PDU_F_ALT 0x01 /* Alt/Backup port (01) */ +#define BSTP_PDU_F_ROOT 0x02 /* Root port (10) */ +#define BSTP_PDU_F_DESG 0x03 /* Designated port (11) */ + +#define BSTP_PDU_STPMASK 0x81 /* strip unused STP flags */ +#define BSTP_PDU_RSTPMASK 0x7f /* strip unused RSTP flags */ +#define BSTP_PDU_F_TC 0x01 /* Topology change */ +#define BSTP_PDU_F_P 0x02 /* Proposal flag */ +#define BSTP_PDU_F_L 0x10 /* Learning flag */ +#define BSTP_PDU_F_F 0x20 /* Forwarding flag */ +#define BSTP_PDU_F_A 0x40 /* Agreement flag */ +#define BSTP_PDU_F_TCA 0x80 /* Topology change ack */ + +/* + * Bridge filtering rules + */ +SIMPLEQ_HEAD(brl_head, brl_node); + +struct brl_node { + SIMPLEQ_ENTRY(brl_node) brl_next; /* next rule */ + struct ether_addr brl_src; /* source mac address */ + struct ether_addr brl_dst; /* destination mac address */ + u_int16_t brl_tag; /* pf tag ID */ + u_int8_t brl_action; /* what to do with match */ + u_int8_t brl_flags; /* comparison flags */ + struct ifbrarpf brl_arpf; /* arp filter */ +}; + +struct bstp_timer { + u_int16_t active; + u_int16_t value; + u_int32_t latched; +}; + +struct bstp_pri_vector { + u_int64_t pv_root_id; + u_int32_t pv_cost; + u_int64_t pv_dbridge_id; + u_int16_t pv_dport_id; + u_int16_t pv_port_id; +}; + +struct bstp_config_unit { + struct bstp_pri_vector cu_pv; + u_int16_t cu_message_age; + u_int16_t cu_max_age; + u_int16_t cu_forward_delay; + u_int16_t cu_hello_time; + u_int8_t cu_message_type; + u_int8_t cu_topology_change_ack; + u_int8_t cu_topology_change; + u_int8_t cu_proposal; + u_int8_t cu_agree; + u_int8_t cu_learning; + u_int8_t cu_forwarding; + u_int8_t cu_role; +}; + +struct bstp_tcn_unit { + u_int8_t tu_message_type; +}; + +struct bstp_port { + LIST_ENTRY(bstp_port) bp_next; + unsigned int bp_ifindex; /* parent interface index */ + struct bstp_state *bp_bs; + struct task bp_ltask; /* if linkstate hook */ + u_int8_t bp_active; + u_int8_t bp_protover; + u_int32_t bp_flags; + u_int32_t bp_path_cost; + u_int16_t bp_port_msg_age; + u_int16_t bp_port_max_age; + u_int16_t bp_port_fdelay; + u_int16_t bp_port_htime; + u_int16_t bp_desg_msg_age; + u_int16_t bp_desg_max_age; + u_int16_t bp_desg_fdelay; + u_int16_t bp_desg_htime; + struct bstp_timer bp_edge_delay_timer; + struct bstp_timer bp_forward_delay_timer; + struct bstp_timer bp_hello_timer; + struct bstp_timer bp_message_age_timer; + struct bstp_timer bp_migrate_delay_timer; + struct bstp_timer bp_recent_backup_timer; + struct bstp_timer bp_recent_root_timer; + struct bstp_timer bp_tc_timer; + struct bstp_config_unit bp_msg_cu; + struct bstp_pri_vector bp_desg_pv; + struct bstp_pri_vector bp_port_pv; + u_int16_t bp_port_id; + u_int8_t bp_state; + u_int8_t bp_tcstate; + u_int8_t bp_role; + u_int8_t bp_infois; + u_int8_t bp_tc_ack; + u_int8_t bp_tc_prop; + u_int8_t bp_fdbflush; + u_int8_t bp_priority; + u_int8_t bp_ptp_link; + u_int8_t bp_agree; + u_int8_t bp_agreed; + u_int8_t bp_sync; + u_int8_t bp_synced; + u_int8_t bp_proposing; + u_int8_t bp_proposed; + u_int8_t bp_operedge; + u_int8_t bp_reroot; + u_int8_t bp_rcvdtc; + u_int8_t bp_rcvdtca; + u_int8_t bp_rcvdtcn; + u_int32_t bp_forward_transitions; + u_int8_t bp_txcount; +}; + +/* + * Software state for each bridge STP. + */ +struct bstp_state { + unsigned int bs_ifindex; + struct bstp_pri_vector bs_bridge_pv; + struct bstp_pri_vector bs_root_pv; + struct bstp_port *bs_root_port; + u_int8_t bs_protover; + u_int16_t bs_migration_delay; + u_int16_t bs_edge_delay; + u_int16_t bs_bridge_max_age; + u_int16_t bs_bridge_fdelay; + u_int16_t bs_bridge_htime; + u_int16_t bs_root_msg_age; + u_int16_t bs_root_max_age; + u_int16_t bs_root_fdelay; + u_int16_t bs_root_htime; + u_int16_t bs_hold_time; + u_int16_t bs_bridge_priority; + u_int8_t bs_txholdcount; + u_int8_t bs_allsynced; + struct timeout bs_bstptimeout; /* stp timeout */ + struct bstp_timer bs_link_timer; + struct timeval bs_last_tc_time; + LIST_HEAD(, bstp_port) bs_bplist; +}; + +/* + * Bridge interface list + * + * Locks used to protect struct members in this file: + * I immutable after creation + * k kernel lock + */ +struct bridge_iflist { + SMR_SLIST_ENTRY(bridge_iflist) bif_next; /* [k] next in list */ + struct bridge_softc *bridge_sc; /* [I] sc backpointer */ + struct bstp_port *bif_stp; /* [I] STP port state */ + struct brl_head bif_brlin; /* [k] input rules */ + struct brl_head bif_brlout; /* [k] output rules */ + struct ifnet *ifp; /* [I] net interface */ + u_int32_t bif_flags; /* member flags */ + u_int32_t bif_protected; /* protected domains */ + struct task bif_dtask; +}; +#define bif_state bif_stp->bp_state + +/* + * XXX ip_ipsp.h's sockaddr_union should be converted to sockaddr * + * passing with correct sa_len, then a good approach for cleaning this + * will become more clear. + */ +union brsockaddr_union { + struct sockaddr sa; + struct sockaddr_in sin; + struct sockaddr_in6 sin6; +}; + +/* + * Bridge tunnel tagging + */ +struct bridge_tunneltag { + union brsockaddr_union brtag_peer; + union brsockaddr_union brtag_local; + u_int32_t brtag_id; +}; + +/* + * Bridge route node + */ +struct bridge_rtnode { + LIST_ENTRY(bridge_rtnode) brt_next; /* next in list */ + unsigned int brt_ifidx; /* destination ifs */ + u_int8_t brt_flags; /* address flags */ + u_int8_t brt_age; /* age counter */ + struct ether_addr brt_addr; /* dst addr */ + struct bridge_tunneltag brt_tunnel; /* tunnel endpoint */ +}; +#define brt_family brt_tunnel.brtag_peer.sa.sa_family + +#ifndef BRIDGE_RTABLE_SIZE +#define BRIDGE_RTABLE_SIZE 1024 +#endif +#define BRIDGE_RTABLE_MASK (BRIDGE_RTABLE_SIZE - 1) + +/* + * Software state for each bridge + * + * Locks used to protect struct members in this file: + * I immutable after creation + * m per-softc mutex + * k kernel lock + */ +struct bridge_softc { + struct ifnet sc_if; /* the interface */ + uint32_t sc_brtmax; /* [m] max # addresses */ + uint32_t sc_brtcnt; /* [m] current # addrs */ + int sc_brttimeout; /* timeout ticks */ + uint64_t sc_hashkey[2]; /* [I] siphash key */ + struct timeout sc_brtimeout; /* timeout state */ + struct bstp_state *sc_stp; /* stp state */ + SMR_SLIST_HEAD(, bridge_iflist) sc_iflist; /* [k] interface list */ + SMR_SLIST_HEAD(, bridge_iflist) sc_spanlist; /* [k] span ports */ + struct mutex sc_mtx; /* mutex */ + LIST_HEAD(, bridge_rtnode) sc_rts[BRIDGE_RTABLE_SIZE]; /* [m] hash table */ +}; + +extern const u_int8_t bstp_etheraddr[]; +struct llc; + +int bridge_enqueue(struct ifnet *, struct mbuf *); +void bridge_update(struct ifnet *, struct ether_addr *, int); +void bridge_rtdelete(struct bridge_softc *, struct ifnet *, int); +void bridge_rtagenode(struct ifnet *, int); +struct bridge_tunneltag *bridge_tunnel(struct mbuf *); +struct bridge_tunneltag *bridge_tunneltag(struct mbuf *); +void bridge_tunneluntag(struct mbuf *); +void bridge_copyaddr(struct sockaddr *, struct sockaddr *); +void bridge_copytag(struct bridge_tunneltag *, struct bridge_tunneltag *); + +struct bstp_state *bstp_create(void); +void bstp_enable(struct bstp_state *bs, unsigned int); +void bstp_disable(struct bstp_state *bs); +void bstp_destroy(struct bstp_state *); +void bstp_initialization(struct bstp_state *); +void bstp_stop(struct bstp_state *); +int bstp_ioctl(struct ifnet *, u_long, caddr_t); +struct bstp_port *bstp_add(struct bstp_state *, struct ifnet *); +void bstp_delete(struct bstp_port *); +struct mbuf *bstp_input(struct bstp_state *, struct bstp_port *, + struct ether_header *, struct mbuf *); +void bstp_ifstate(void *); +u_int8_t bstp_getstate(struct bstp_state *, struct bstp_port *); +void bstp_ifsflags(struct bstp_port *, u_int); + +int bridgectl_ioctl(struct ifnet *, u_long, caddr_t); +int bridge_rtupdate(struct bridge_softc *, + struct ether_addr *, struct ifnet *, int, u_int8_t, struct mbuf *); +unsigned int bridge_rtlookup(struct ifnet *, + struct ether_addr *, struct mbuf *); +void bridge_rtflush(struct bridge_softc *, int); +void bridge_rtage(void *); + +u_int8_t bridge_filterrule(struct brl_head *, struct ether_header *, + struct mbuf *); +void bridge_flushrule(struct bridge_iflist *); + +void bridge_fragment(struct ifnet *, struct ifnet *, struct ether_header *, + struct mbuf *); +struct bridge_iflist *bridge_getbif(struct ifnet *); +int bridge_findbif(struct bridge_softc *, const char *, + struct bridge_iflist **); + +#endif /* _KERNEL */ +#endif /* _NET_IF_BRIDGE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/if_dl.h b/lib/libc/include/generic-openbsd/net/if_dl.h new file mode 100644 index 0000000000..6ea4a24620 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/if_dl.h @@ -0,0 +1,101 @@ +/* $OpenBSD: if_dl.h,v 1.13 2023/11/12 17:51:40 bluhm Exp $ */ +/* $NetBSD: if_dl.h,v 1.8 1995/03/26 20:30:13 jtc 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. + * + * @(#)if_dl.h 8.1 (Berkeley) 6/10/93 + */ + +/* + * A Link-Level Sockaddr may specify the interface in one of two + * ways: either by means of a system-provided index number (computed + * anew and possibly differently on every reboot), or by a human-readable + * string such as "il0" (for managerial convenience). + * + * Census taking actions, such as something akin to SIOCGCONF would return + * both the index and the human name. + * + * High volume transactions (such as giving a link-level ``from'' address + * in a recvfrom or recvmsg call) may be likely only to provide the indexed + * form, (which requires fewer copy operations and less space). + * + * The form and interpretation of the link-level address is purely a matter + * of convention between the device driver and its consumers; however, it is + * expected that all drivers for an interface of a given if_type will agree. + */ + +#ifndef _NET_IF_DL_H_ +#define _NET_IF_DL_H_ + +/* + * Structure of a Link-Level sockaddr: + */ +struct sockaddr_dl { + u_char sdl_len; /* Total length of sockaddr */ + u_char sdl_family; /* AF_LINK */ + u_int16_t sdl_index; /* if != 0, system given index for interface */ + u_char sdl_type; /* interface type */ + u_char sdl_nlen; /* interface name length, no trailing 0 reqd. */ + u_char sdl_alen; /* link level address length */ + u_char sdl_slen; /* link layer selector length, mostly 0 */ + char sdl_data[24]; /* minimum work area, can be larger; + contains both if name and ll address; + big enough for IFNAMSIZ plus 8byte ll addr */ +}; + +#define LLADDR(s) ((caddr_t)((s)->sdl_data + (s)->sdl_nlen)) + +#ifdef _KERNEL + +static inline struct sockaddr_dl * +satosdl(struct sockaddr *sa) +{ + return ((struct sockaddr_dl *)(sa)); +} + +static inline const struct sockaddr_dl * +satosdl_const(const struct sockaddr *sa) +{ + return ((const struct sockaddr_dl *)(sa)); +} + +static inline struct sockaddr * +sdltosa(struct sockaddr_dl *sdl) +{ + return ((struct sockaddr *)(sdl)); +} + +#else /* _KERNEL */ + +__BEGIN_DECLS +char *link_ntoa(const struct sockaddr_dl *); +__END_DECLS + +#endif /* _KERNEL */ +#endif /* _NET_IF_DL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/if_enc.h b/lib/libc/include/generic-openbsd/net/if_enc.h new file mode 100644 index 0000000000..b2b875f1ae --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/if_enc.h @@ -0,0 +1,42 @@ +/* $OpenBSD: if_enc.h,v 1.13 2021/12/01 21:48:00 deraadt Exp $ */ + +/* + * Copyright (c) 2010 Reyk Floeter + * + * 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 _NET_ENC_H +#define _NET_ENC_H + +#define ENCMTU 1536 /* XXX should be bigger, maybe LOMTU */ +#define ENC_HDRLEN 12 + +struct enchdr { + u_int32_t af; + u_int32_t spi; + u_int32_t flags; /* similar to mbuf m_flags */ +}; + +#ifdef _KERNEL +struct enc_softc { + struct ifnet sc_if; /* virtual interface */ + u_int sc_unit; + struct ifaddr sc_ifa; /* needed to attach rtentry */ +}; + +struct ifnet *enc_getif(u_int, u_int); +struct ifaddr *enc_getifa(u_int, u_int); +#endif /* _KERNEL */ + +#endif /* _NET_ENC_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/if_etherbridge.h b/lib/libc/include/generic-openbsd/net/if_etherbridge.h new file mode 100644 index 0000000000..57bfe0ad58 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/if_etherbridge.h @@ -0,0 +1,102 @@ +/* $OpenBSD: if_etherbridge.h,v 1.5 2024/11/04 00:13:15 jsg Exp $ */ + +/* + * Copyright (c) 2018, 2021 David Gwynne + * + * 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 _NET_ETHERBRIDGE_H_ +#define _NET_ETHERBRIDGE_H_ + +#define ETHERBRIDGE_TABLE_BITS 8 +#define ETHERBRIDGE_TABLE_SIZE (1U << ETHERBRIDGE_TABLE_BITS) +#define ETHERBRIDGE_TABLE_MASK (ETHERBRIDGE_TABLE_SIZE - 1) + +struct etherbridge_ops { + int (*eb_op_port_eq)(void *, void *, void *); + void *(*eb_op_port_take)(void *, void *); + void (*eb_op_port_rele)(void *, void *); + size_t (*eb_op_port_ifname)(void *, char *, size_t, void *); + void (*eb_op_port_sa)(void *, struct sockaddr_storage *, void *); +}; + +struct etherbridge; + +struct eb_entry { + SMR_TAILQ_ENTRY(eb_entry) ebe_lentry; + union { + RBT_ENTRY(eb_entry) _ebe_tentry; + TAILQ_ENTRY(eb_entry) _ebe_qentry; + } _ebe_entries; +#define ebe_tentry _ebe_entries._ebe_tentry +#define ebe_qentry _ebe_entries._ebe_qentry + + uint64_t ebe_addr; + void *ebe_port; + unsigned int ebe_type; +#define EBE_DYNAMIC 0x0 +#define EBE_STATIC 0x1 +#define EBE_DEAD 0xdead + time_t ebe_age; + + struct etherbridge *ebe_etherbridge; + struct smr_entry ebe_smr_entry; +}; + +SMR_TAILQ_HEAD(eb_list, eb_entry); +RBT_HEAD(eb_tree, eb_entry); +TAILQ_HEAD(eb_queue, eb_entry); + +struct etherbridge { + const char *eb_name; + const struct etherbridge_ops *eb_ops; + void *eb_cookie; + + struct mutex eb_lock; + unsigned int eb_num; + unsigned int eb_max; + int eb_max_age; /* seconds */ + struct timeout eb_tmo_age; + + struct eb_list *eb_table; + struct eb_tree eb_tree; + +}; + +int etherbridge_init(struct etherbridge *, const char *, + const struct etherbridge_ops *, void *); +int etherbridge_up(struct etherbridge *); +int etherbridge_down(struct etherbridge *); +void etherbridge_destroy(struct etherbridge *); + +void etherbridge_map(struct etherbridge *, void *, uint64_t); +void etherbridge_map_ea(struct etherbridge *, void *, + const struct ether_addr *); +void *etherbridge_resolve(struct etherbridge *, uint64_t); +void *etherbridge_resolve_ea(struct etherbridge *, + const struct ether_addr *); +void etherbridge_detach_port(struct etherbridge *, void *); + +/* ioctl support */ +int etherbridge_set_max(struct etherbridge *, struct ifbrparam *); +int etherbridge_get_max(struct etherbridge *, struct ifbrparam *); +int etherbridge_set_tmo(struct etherbridge *, struct ifbrparam *); +int etherbridge_get_tmo(struct etherbridge *, struct ifbrparam *); +int etherbridge_rtfind(struct etherbridge *, struct ifbaconf *); +int etherbridge_add_addr(struct etherbridge *, void *, + const struct ether_addr *, unsigned int); +int etherbridge_del_addr(struct etherbridge *, const struct ether_addr *); +void etherbridge_flush(struct etherbridge *, uint32_t); + +#endif /* _NET_ETHERBRIDGE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/if_etherip.h b/lib/libc/include/generic-openbsd/net/if_etherip.h new file mode 100644 index 0000000000..0f310db102 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/if_etherip.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2015 Kazuya GODA + * + * 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 _NET_IF_ETHERIP_H_ +#define _NET_IF_ETHERIP_H_ + +int etherip_sysctl(int *, uint, void *, size_t *, void *, size_t); +int ip_etherip_output(struct ifnet *, struct mbuf *); +int ip_etherip_input(struct mbuf **, int *, int, int, struct netstack *); + +#ifdef INET6 +int ip6_etherip_output(struct ifnet *, struct mbuf *); +int ip6_etherip_input(struct mbuf **, int *, int, int, struct netstack *); +#endif /* INET6 */ + +#endif /* _NET_IF_ETHERIP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/if_gif.h b/lib/libc/include/generic-openbsd/net/if_gif.h new file mode 100644 index 0000000000..65f8895b3d --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/if_gif.h @@ -0,0 +1,43 @@ +/* $OpenBSD: if_gif.h,v 1.19 2025/03/02 21:28:31 bluhm Exp $ */ +/* $KAME: if_gif.h,v 1.17 2000/09/11 11:36:41 sumikawa Exp $ */ + +/* + * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. + * 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 project 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 PROJECT 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 PROJECT 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. + */ + +/* + * if_gif.h + */ + +#ifndef _NET_IF_GIF_H_ +#define _NET_IF_GIF_H_ + +int in_gif_input(struct mbuf **, int *, int, int, struct netstack *); +int in6_gif_input(struct mbuf **, int *, int, int, struct netstack *); + +#endif /* _NET_IF_GIF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/if_gre.h b/lib/libc/include/generic-openbsd/net/if_gre.h new file mode 100644 index 0000000000..01e65156fb --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/if_gre.h @@ -0,0 +1,121 @@ +/* $OpenBSD: if_gre.h,v 1.17 2025/03/02 21:28:31 bluhm Exp $ */ +/* $NetBSD: if_gre.h,v 1.5 1999/11/19 20:41:19 thorpej Exp $ */ + +/* + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved + * + * This code is derived from software contributed to The NetBSD Foundation + * by Heiko W.Rupp + * + * 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 _NET_IF_GRE_H +#define _NET_IF_GRE_H + +struct gre_h { + u_int16_t flags; /* GRE flags */ + u_int16_t ptype; /* protocol type of payload typically + Ether protocol type*/ +/* + * from here on: fields are optional, presence indicated by flags + * + u_int_16 checksum checksum (one-complements of GRE header + and payload + Present if (ck_pres | rt_pres == 1). + Valid if (ck_pres == 1). + u_int_16 offset offset from start of routing filed to + first octet of active SRE (see below). + Present if (ck_pres | rt_pres == 1). + Valid if (rt_pres == 1). + u_int_32 key inserted by encapsulator e.g. for + authentication + Present if (key_pres ==1 ). + u_int_32 seq_num Sequence number to allow for packet order + Present if (seq_pres ==1 ). + + struct gre_sre[] routing Routing fields (see below) + Present if (rt_pres == 1) +*/ +} __packed; + +struct greip { + struct ip gi_i; + struct gre_h gi_g; +} __packed; + +#define gi_pr gi_i.ip_p +#define gi_len gi_i.ip_len +#define gi_src gi_i.ip_src +#define gi_dst gi_i.ip_dst +#define gi_ptype gi_g.ptype +#define gi_flags gi_g.flags + +#define GRE_CP 0x8000 /* Checksum Present */ +#define GRE_RP 0x4000 /* Routing Present */ +#define GRE_KP 0x2000 /* Key Present */ +#define GRE_SP 0x1000 /* Sequence Present */ +#define GRE_SS 0x0800 /* Strict Source Route */ + +/* gre_sre defines a Source route Entry. These are needed if packets + * should be routed over more than one tunnel hop by hop + */ + +struct gre_sre { + u_int16_t sre_family; /* address family */ + u_char sre_offset; /* offset to first octet of active entry */ + u_char sre_length; /* number of octets in the SRE. + sre_lengthl==0 -> last entry. */ + u_char *sre_rtinfo; /* the routing information */ +}; + +struct greioctl { + int unit; + struct in_addr addr; +}; + +/* for mobile encaps */ + +struct mobile_h { + u_int16_t proto; /* protocol and S-bit */ + u_int16_t hcrc; /* header checksum */ + u_int32_t odst; /* original destination address */ + u_int32_t osrc; /* original source addr, if S-bit set */ +} __packed; + +struct mobip_h { + struct ip mi; + struct mobile_h mh; +} __packed; + + +#define MOB_H_SIZ_S (sizeof(struct mobile_h) - sizeof(u_int32_t)) +#define MOB_H_SIZ_L (sizeof(struct mobile_h)) +#define MOB_H_SBIT 0x0080 + +#ifdef _KERNEL +int gre_sysctl(int *, u_int, void *, size_t *, void *, size_t); +int gre_input(struct mbuf **, int *, int, int, struct netstack *); +int gre_input6(struct mbuf **, int *, int, int, struct netstack *); +#endif +#endif /* _NET_IF_GRE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/if_llc.h b/lib/libc/include/generic-openbsd/net/if_llc.h new file mode 100644 index 0000000000..82be68f534 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/if_llc.h @@ -0,0 +1,145 @@ +/* $OpenBSD: if_llc.h,v 1.8 2013/01/17 00:48:04 henning Exp $ */ +/* $NetBSD: if_llc.h,v 1.6 1995/03/08 02:56:57 cgd Exp $ */ + +/* + * Copyright (c) 1988, 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. + * + * @(#)if_llc.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NET_IF_LLC_H_ +#define _NET_IF_LLC_H_ + +/* + * IEEE 802.2 Link Level Control headers, for use in conjunction with + * 802.{3,4,5} media access control methods. + * + * Headers here do not use bit fields due to shortcomings in many + * compilers. + */ + +struct llc { + u_int8_t llc_dsap; + u_int8_t llc_ssap; + union { + struct { + u_int8_t control; + u_int8_t format_id; + u_int8_t class; + u_int8_t window_x2; + } type_u; + struct { + u_int8_t num_snd_x2; + u_int8_t num_rcv_x2; + } type_i; + struct { + u_int8_t control; + u_int8_t num_rcv_x2; + } type_s; + struct { + u_int8_t control; + struct frmrinfo { + u_int8_t rej_pdu_0; + u_int8_t rej_pdu_1; + u_int8_t frmr_control; + u_int8_t frmr_control_ext; + u_int8_t frmr_cause; + } frmrinfo; + } type_frmr; + struct { + u_int8_t control; + u_int8_t org_code[3]; + u_int16_t ether_type; + } type_snap; + struct { + u_int8_t control; + u_int8_t control_ext; + } type_raw; + } llc_un; +}; +#define llc_control llc_un.type_u.control +#define llc_control_ext llc_un.type_raw.control_ext +#define llc_fid llc_un.type_u.format_id +#define llc_class llc_un.type_u.class +#define llc_window llc_un.type_u.window_x2 +#define llc_frmrinfo llc_un.type_frmr.frmrinfo +#define llc_frmr_pdu0 llc_un.type_frmr.frmrinfo.rej_pdu0 +#define llc_frmr_pdu1 llc_un.type_frmr.frmrinfo.rej_pdu1 +#define llc_frmr_control llc_un.type_frmr.frmrinfo.frmr_control +#define llc_frmr_control_ext llc_un.type_frmr.frmrinfo.frmr_control_ext +#define llc_frmr_cause llc_un.type_frmr.frmrinfo.frmr_control_ext +#define llc_snap llc_un.type_snap + +/* + * Don't use sizeof(struct llc_un) for LLC header sizes + */ +#define LLC_UFRAMELEN 3 +#define LLC_ISFRAMELEN 4 +#define LLC_FRMRLEN 7 +#define LLC_SNAPFRAMELEN 8 + +/* + * Unnumbered LLC format commands + */ +#define LLC_UI 0x3 +#define LLC_UI_P 0x13 +#define LLC_DISC 0x43 +#define LLC_DISC_P 0x53 +#define LLC_UA 0x63 +#define LLC_UA_P 0x73 +#define LLC_TEST 0xe3 +#define LLC_TEST_P 0xf3 +#define LLC_FRMR 0x87 +#define LLC_FRMR_P 0x97 +#define LLC_DM 0x0f +#define LLC_DM_P 0x1f +#define LLC_XID 0xaf +#define LLC_XID_P 0xbf +#define LLC_SABME 0x6f +#define LLC_SABME_P 0x7f + +/* + * Supervisory LLC commands + */ +#define LLC_RR 0x01 +#define LLC_RNR 0x05 +#define LLC_REJ 0x09 + +/* + * Info format - dummy only + */ +#define LLC_INFO 0x00 + +/* + * ISO PDTR 10178 contains among others + */ +#define LLC_8021D_LSAP 0x42 +#define LLC_X25_LSAP 0x7e +#define LLC_SNAP_LSAP 0xaa +#define LLC_ISO_LSAP 0xfe +#endif /* _NET_IF_LLC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/if_media.h b/lib/libc/include/generic-openbsd/net/if_media.h new file mode 100644 index 0000000000..a365fd1349 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/if_media.h @@ -0,0 +1,972 @@ +/* $OpenBSD: if_media.h,v 1.46 2025/06/13 00:08:16 jsg Exp $ */ +/* $NetBSD: if_media.h,v 1.22 2000/02/17 21:53:16 sommerfeld Exp $ */ + +/*- + * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 1997 + * Jonathan Stone and Jason R. Thorpe. All rights reserved. + * + * This software is derived from information provided by Matt Thomas. + * + * 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 Jonathan Stone + * and Jason R. Thorpe for the NetBSD Project. + * 4. The names of the authors may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``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 _NET_IF_MEDIA_H_ +#define _NET_IF_MEDIA_H_ + +#ifdef _KERNEL + +struct ifnet; +extern struct mutex ifmedia_mtx; + +#include +/* + * Driver callbacks for media status and change requests. + */ +typedef int (*ifm_change_cb_t)(struct ifnet *); +typedef void (*ifm_stat_cb_t)(struct ifnet *, struct ifmediareq *); + +/* + * Locks used to protect struct members in this file: + * M ifmedia_mtx interface media mutex + */ + +/* + * In-kernel representation of a single supported media type. + */ +struct ifmedia_entry { + TAILQ_ENTRY(ifmedia_entry) ifm_list; + uint64_t ifm_media; /* description of this media attachment */ + u_int ifm_data; /* for driver-specific use */ + void *ifm_aux; /* for driver-specific use */ +}; + +TAILQ_HEAD(ifmedia_list, ifmedia_entry); +/* + * One of these goes into a network interface's softc structure. + * It is used to keep general media state. + */ +struct ifmedia { + uint64_t ifm_mask; /* mask of changes we don't care about */ + uint64_t ifm_media; /* current user-set media word */ + struct ifmedia_entry *ifm_cur; /* [M] currently selected media */ + struct ifmedia_list ifm_list; /* [M] list of all supported media */ + size_t ifm_nwords; /* [M] number of ifm_list entries */ + ifm_change_cb_t ifm_change_cb; /* media change driver callback */ + ifm_stat_cb_t ifm_status_cb; /* media status driver callback */ +}; + +/* Initialize an interface's struct if_media field. */ +void ifmedia_init(struct ifmedia *, uint64_t, ifm_change_cb_t, + ifm_stat_cb_t); + +/* Add one supported medium to a struct ifmedia. */ +void ifmedia_add(struct ifmedia *, uint64_t, int, void *); + +/* Set default media type on initialization. */ +void ifmedia_set(struct ifmedia *, uint64_t); + +/* Common ioctl function for getting/setting media, called by driver. */ +int ifmedia_ioctl(struct ifnet *, struct ifreq *, struct ifmedia *, + u_long); + +/* Locate a media entry */ +int ifmedia_match(struct ifmedia *, uint64_t, uint64_t); + +/* Delete all media for a given media instance */ +void ifmedia_delete_instance(struct ifmedia *, uint64_t); + +/* Compute baudrate for a given media. */ +uint64_t ifmedia_baudrate(uint64_t); +#endif /*_KERNEL */ + +/* + * if_media Options word: + * Bits Use + * ---- ------- + * 0-7 Media subtype MAX SUBTYPE == 255! + * 8-15 Media type + * 16-31 Type specific options + * 32-39 Mode (for multi-mode devices) + * 40-55 Shared (global) options + * 56-63 Instance + */ + +/* + * Ethernet + */ +#define IFM_ETHER 0x0000000000000100ULL +#define IFM_10_T 3 /* 10BaseT - RJ45 */ +#define IFM_10_2 4 /* 10Base2 - Thinnet */ +#define IFM_10_5 5 /* 10Base5 - AUI */ +#define IFM_100_TX 6 /* 100BaseTX - RJ45 */ +#define IFM_100_FX 7 /* 100BaseFX - Fiber */ +#define IFM_100_T4 8 /* 100BaseT4 - 4 pair cat 3 */ +#define IFM_100_VG 9 /* 100VG-AnyLAN */ +#define IFM_100_T2 10 /* 100BaseT2 */ +#define IFM_1000_SX 11 /* 1000BaseSX - multi-mode fiber */ +#define IFM_10_STP 12 /* 10BaseT over shielded TP */ +#define IFM_10_FL 13 /* 10BaseFL - Fiber */ +#define IFM_1000_LX 14 /* 1000baseLX - single-mode fiber */ +#define IFM_1000_CX 15 /* 1000baseCX - 150ohm STP */ +#define IFM_1000_T 16 /* 1000baseT - 4 pair cat 5 */ +#define IFM_1000_TX IFM_1000_T /* for backwards compatibility */ +#define IFM_HPNA_1 17 /* HomePNA 1.0 (1Mb/s) */ +#define IFM_10G_LR 18 /* 10GBase-LR - single-mode fiber */ +#define IFM_10G_SR 19 /* 10GBase-SR - multi-mode fiber */ +#define IFM_10G_CX4 20 /* 10GBase-CX4 - copper */ +#define IFM_2500_SX 21 /* 2500baseSX - multi-mode fiber */ +#define IFM_10G_T 22 /* 10GbaseT cat 6 */ +#define IFM_10G_SFP_CU 23 /* 10G SFP+ direct attached cable */ +#define IFM_10G_LRM 24 /* 10GBase-LRM 850nm Multi-mode */ +#define IFM_40G_CR4 25 /* 40GBase-CR4 */ +#define IFM_40G_SR4 26 /* 40GBase-SR4 */ +#define IFM_40G_LR4 27 /* 40GBase-LR4 */ +#define IFM_1000_KX 28 /* 1000Base-KX backplane */ +#define IFM_10G_KX4 29 /* 10GBase-KX4 backplane */ +#define IFM_10G_KR 30 /* 10GBase-KR backplane */ +#define IFM_10G_CR1 31 /* 10GBase-CR1 Twinax splitter */ +#define IFM_20G_KR2 32 /* 20GBase-KR2 backplane */ +#define IFM_2500_KX 33 /* 2500Base-KX backplane */ +#define IFM_2500_T 34 /* 2500Base-T - RJ45 (NBaseT) */ +#define IFM_5000_T 35 /* 5000Base-T - RJ45 (NBaseT) */ +#define IFM_1000_SGMII 36 /* 1G media interface */ +#define IFM_10G_SFI 37 /* 10G media interface */ +#define IFM_40G_XLPPI 38 /* 40G media interface */ +#define IFM_1000_CX_SGMII 39 /* 1000Base-CX-SGMII */ +#define IFM_40G_KR4 40 /* 40GBase-KR4 */ +#define IFM_10G_ER 41 /* 10GBase-ER */ +#define IFM_100G_CR4 42 /* 100GBase-CR4 */ +#define IFM_100G_SR4 43 /* 100GBase-SR4 */ +#define IFM_100G_KR4 44 /* 100GBase-KR4 */ +#define IFM_100G_LR4 45 /* 100GBase-LR4 */ +#define IFM_56G_R4 46 /* 56GBase-R4 */ +#define IFM_25G_CR 47 /* 25GBase-CR */ +#define IFM_25G_KR 48 /* 25GBase-KR */ +#define IFM_25G_SR 49 /* 25GBase-SR */ +#define IFM_50G_CR2 50 /* 50GBase-CR2 */ +#define IFM_50G_KR2 51 /* 50GBase-KR2 */ +#define IFM_25G_LR 52 /* 25GBase-LR */ +#define IFM_25G_ER 53 /* 25GBase-ER */ +#define IFM_10G_AOC 54 /* 10G Active Optical Cable */ +#define IFM_25G_AOC 55 /* 25G Active Optical Cable */ +#define IFM_40G_AOC 56 /* 40G Active Optical Cable */ +#define IFM_100G_AOC 57 /* 100G Active Optical Cable */ + +#define IFM_ETH_MASTER 0x0000000000010000ULL /* master mode (1000baseT) */ +#define IFM_ETH_RXPAUSE 0x0000000000020000ULL /* receive PAUSE frames */ +#define IFM_ETH_TXPAUSE 0x0000000000040000ULL /* transmit PAUSE frames */ + +/* + * FDDI + */ +#define IFM_FDDI 0x0000000000000300ULL +#define IFM_FDDI_SMF 3 /* Single-mode fiber */ +#define IFM_FDDI_MMF 4 /* Multi-mode fiber */ +#define IFM_FDDI_UTP 5 /* CDDI / UTP */ +#define IFM_FDDI_DA 0x00000100 /* Dual attach / single attach */ + +/* + * IEEE 802.11 Wireless + */ +#define IFM_IEEE80211 0x0000000000000400ULL +#define IFM_IEEE80211_FH1 3 /* Frequency Hopping 1Mbps */ +#define IFM_IEEE80211_FH2 4 /* Frequency Hopping 2Mbps */ +#define IFM_IEEE80211_DS2 5 /* Direct Sequence 2Mbps */ +#define IFM_IEEE80211_DS5 6 /* Direct Sequence 5Mbps*/ +#define IFM_IEEE80211_DS11 7 /* Direct Sequence 11Mbps*/ +#define IFM_IEEE80211_DS1 8 /* Direct Sequence 1Mbps*/ +#define IFM_IEEE80211_DS22 9 /* Direct Sequence 22Mbps */ +#define IFM_IEEE80211_OFDM6 10 /* OFDM 6Mbps */ +#define IFM_IEEE80211_OFDM9 11 /* OFDM 9Mbps */ +#define IFM_IEEE80211_OFDM12 12 /* OFDM 12Mbps */ +#define IFM_IEEE80211_OFDM18 13 /* OFDM 18Mbps */ +#define IFM_IEEE80211_OFDM24 14 /* OFDM 24Mbps */ +#define IFM_IEEE80211_OFDM36 15 /* OFDM 36Mbps */ +#define IFM_IEEE80211_OFDM48 16 /* OFDM 48Mbps */ +#define IFM_IEEE80211_OFDM54 17 /* OFDM 54Mbps */ +#define IFM_IEEE80211_OFDM72 18 /* OFDM 72Mbps */ +#define IFM_IEEE80211_HT_MCS0 19 /* 11n MCS 0 */ +#define IFM_IEEE80211_HT_MCS1 20 /* 11n MCS 1 */ +#define IFM_IEEE80211_HT_MCS2 21 /* 11n MCS 2 */ +#define IFM_IEEE80211_HT_MCS3 22 /* 11n MCS 3 */ +#define IFM_IEEE80211_HT_MCS4 23 /* 11n MCS 4 */ +#define IFM_IEEE80211_HT_MCS5 24 /* 11n MCS 5 */ +#define IFM_IEEE80211_HT_MCS6 25 /* 11n MCS 6 */ +#define IFM_IEEE80211_HT_MCS7 26 /* 11n MCS 7 */ +#define IFM_IEEE80211_HT_MCS8 27 /* 11n MCS 8 */ +#define IFM_IEEE80211_HT_MCS9 28 /* 11n MCS 9 */ +#define IFM_IEEE80211_HT_MCS10 29 /* 11n MCS 10 */ +#define IFM_IEEE80211_HT_MCS11 30 /* 11n MCS 11 */ +#define IFM_IEEE80211_HT_MCS12 31 /* 11n MCS 12 */ +#define IFM_IEEE80211_HT_MCS13 32 /* 11n MCS 13 */ +#define IFM_IEEE80211_HT_MCS14 33 /* 11n MCS 14 */ +#define IFM_IEEE80211_HT_MCS15 34 /* 11n MCS 15 */ +#define IFM_IEEE80211_HT_MCS16 35 /* 11n MCS 16 */ +#define IFM_IEEE80211_HT_MCS17 36 /* 11n MCS 17 */ +#define IFM_IEEE80211_HT_MCS18 37 /* 11n MCS 18 */ +#define IFM_IEEE80211_HT_MCS19 38 /* 11n MCS 19 */ +#define IFM_IEEE80211_HT_MCS20 39 /* 11n MCS 20 */ +#define IFM_IEEE80211_HT_MCS21 40 /* 11n MCS 21 */ +#define IFM_IEEE80211_HT_MCS22 41 /* 11n MCS 22 */ +#define IFM_IEEE80211_HT_MCS23 42 /* 11n MCS 23 */ +#define IFM_IEEE80211_HT_MCS24 43 /* 11n MCS 24 */ +#define IFM_IEEE80211_HT_MCS25 44 /* 11n MCS 25 */ +#define IFM_IEEE80211_HT_MCS26 45 /* 11n MCS 26 */ +#define IFM_IEEE80211_HT_MCS27 46 /* 11n MCS 27 */ +#define IFM_IEEE80211_HT_MCS28 47 /* 11n MCS 28 */ +#define IFM_IEEE80211_HT_MCS29 48 /* 11n MCS 29 */ +#define IFM_IEEE80211_HT_MCS30 49 /* 11n MCS 30 */ +#define IFM_IEEE80211_HT_MCS31 50 /* 11n MCS 31 */ +#define IFM_IEEE80211_HT_MCS32 51 /* 11n MCS 32 */ +#define IFM_IEEE80211_HT_MCS33 52 /* 11n MCS 33 */ +#define IFM_IEEE80211_HT_MCS34 53 /* 11n MCS 34 */ +#define IFM_IEEE80211_HT_MCS35 54 /* 11n MCS 35 */ +#define IFM_IEEE80211_HT_MCS36 55 /* 11n MCS 36 */ +#define IFM_IEEE80211_HT_MCS37 56 /* 11n MCS 37 */ +#define IFM_IEEE80211_HT_MCS38 57 /* 11n MCS 38 */ +#define IFM_IEEE80211_HT_MCS39 58 /* 11n MCS 39 */ +#define IFM_IEEE80211_HT_MCS40 59 /* 11n MCS 40 */ +#define IFM_IEEE80211_HT_MCS41 60 /* 11n MCS 41 */ +#define IFM_IEEE80211_HT_MCS42 61 /* 11n MCS 42 */ +#define IFM_IEEE80211_HT_MCS43 62 /* 11n MCS 43 */ +#define IFM_IEEE80211_HT_MCS44 63 /* 11n MCS 44 */ +#define IFM_IEEE80211_HT_MCS45 64 /* 11n MCS 45 */ +#define IFM_IEEE80211_HT_MCS46 65 /* 11n MCS 46 */ +#define IFM_IEEE80211_HT_MCS47 66 /* 11n MCS 47 */ +#define IFM_IEEE80211_HT_MCS48 67 /* 11n MCS 48 */ +#define IFM_IEEE80211_HT_MCS49 68 /* 11n MCS 49 */ +#define IFM_IEEE80211_HT_MCS50 69 /* 11n MCS 50 */ +#define IFM_IEEE80211_HT_MCS51 70 /* 11n MCS 51 */ +#define IFM_IEEE80211_HT_MCS52 71 /* 11n MCS 52 */ +#define IFM_IEEE80211_HT_MCS53 72 /* 11n MCS 53 */ +#define IFM_IEEE80211_HT_MCS54 73 /* 11n MCS 54 */ +#define IFM_IEEE80211_HT_MCS55 74 /* 11n MCS 55 */ +#define IFM_IEEE80211_HT_MCS56 75 /* 11n MCS 56 */ +#define IFM_IEEE80211_HT_MCS57 76 /* 11n MCS 57 */ +#define IFM_IEEE80211_HT_MCS58 77 /* 11n MCS 58 */ +#define IFM_IEEE80211_HT_MCS59 78 /* 11n MCS 59 */ +#define IFM_IEEE80211_HT_MCS60 79 /* 11n MCS 60 */ +#define IFM_IEEE80211_HT_MCS61 80 /* 11n MCS 61 */ +#define IFM_IEEE80211_HT_MCS62 81 /* 11n MCS 62 */ +#define IFM_IEEE80211_HT_MCS63 82 /* 11n MCS 63 */ +#define IFM_IEEE80211_HT_MCS64 83 /* 11n MCS 64 */ +#define IFM_IEEE80211_HT_MCS65 84 /* 11n MCS 65 */ +#define IFM_IEEE80211_HT_MCS66 85 /* 11n MCS 66 */ +#define IFM_IEEE80211_HT_MCS67 86 /* 11n MCS 67 */ +#define IFM_IEEE80211_HT_MCS68 87 /* 11n MCS 68 */ +#define IFM_IEEE80211_HT_MCS69 88 /* 11n MCS 69 */ +#define IFM_IEEE80211_HT_MCS70 89 /* 11n MCS 70 */ +#define IFM_IEEE80211_HT_MCS71 90 /* 11n MCS 71 */ +#define IFM_IEEE80211_HT_MCS72 91 /* 11n MCS 72 */ +#define IFM_IEEE80211_HT_MCS73 92 /* 11n MCS 73 */ +#define IFM_IEEE80211_HT_MCS74 93 /* 11n MCS 74 */ +#define IFM_IEEE80211_HT_MCS75 94 /* 11n MCS 75 */ +#define IFM_IEEE80211_HT_MCS76 95 /* 11n MCS 76 */ +#define IFM_IEEE80211_VHT_MCS0 96 /* 11ac MCS 0 */ +#define IFM_IEEE80211_VHT_MCS1 97 /* 11ac MCS 1 */ +#define IFM_IEEE80211_VHT_MCS2 98 /* 11ac MCS 2 */ +#define IFM_IEEE80211_VHT_MCS3 99 /* 11ac MCS 3 */ +#define IFM_IEEE80211_VHT_MCS4 100 /* 11ac MCS 4 */ +#define IFM_IEEE80211_VHT_MCS5 101 /* 11ac MCS 5 */ +#define IFM_IEEE80211_VHT_MCS6 102 /* 11ac MCS 6 */ +#define IFM_IEEE80211_VHT_MCS7 103 /* 11ac MCS 7 */ +#define IFM_IEEE80211_VHT_MCS8 104 /* 11ac MCS 8 */ +#define IFM_IEEE80211_VHT_MCS9 105 /* 11ac MCS 9 */ + +#define IFM_IEEE80211_ADHOC 0x0000000000010000ULL /* Operate in Adhoc mode */ +#define IFM_IEEE80211_HOSTAP 0x0000000000020000ULL /* Operate in Host AP mode */ +#define IFM_IEEE80211_IBSS 0x0000000000040000ULL /* Operate in IBSS mode */ +#define IFM_IEEE80211_IBSSMASTER 0x0000000000080000ULL /* Operate as an IBSS master */ +#define IFM_IEEE80211_MONITOR 0x0000000000100000ULL /* Operate in Monitor mode */ + +/* operating mode for multi-mode devices */ +#define IFM_IEEE80211_11A 0x0000000100000000ULL /* 5GHz, OFDM mode */ +#define IFM_IEEE80211_11B 0x0000000200000000ULL /* Direct Sequence mode */ +#define IFM_IEEE80211_11G 0x0000000300000000ULL /* 2GHz, CCK mode */ +#define IFM_IEEE80211_FH 0x0000000400000000ULL /* 2GHz, GFSK mode */ +#define IFM_IEEE80211_11N 0x0000000800000000ULL /* 11n/HT 2GHz/5GHz */ +#define IFM_IEEE80211_11AC 0x0000001000000000ULL /* 11ac/VHT 5GHz */ + +/* + * Digitally multiplexed "Carrier" Serial Interfaces + */ +#define IFM_TDM 0x0000000000000500ULL +#define IFM_TDM_T1 3 /* T1 B8ZS+ESF 24 ts */ +#define IFM_TDM_T1_AMI 4 /* T1 AMI+SF 24 ts */ +#define IFM_TDM_E1 5 /* E1 HDB3+G.703 clearchannel 32 ts */ +#define IFM_TDM_E1_G704 6 /* E1 HDB3+G.703+G.704 channelized 31 ts */ +#define IFM_TDM_E1_AMI 7 /* E1 AMI+G.703 32 ts */ +#define IFM_TDM_E1_AMI_G704 8 /* E1 AMI+G.703+G.704 31 ts */ +#define IFM_TDM_T3 9 /* T3 B3ZS+C-bit 672 ts */ +#define IFM_TDM_T3_M13 10 /* T3 B3ZS+M13 672 ts */ +#define IFM_TDM_E3 11 /* E3 HDB3+G.751 512? ts */ +#define IFM_TDM_E3_G751 12 /* E3 G.751 512 ts */ +#define IFM_TDM_E3_G832 13 /* E3 G.832 512 ts */ +#define IFM_TDM_E1_G704_CRC4 14 /* E1 HDB3+G.703+G.704 31 ts + CRC4 */ +/* + * 6 major ways that networks talk: Drivers enforce independent selection, + * meaning, a driver will ensure that only one of these is set at a time. + * Default is cisco hdlc mode with 32 bit CRC. + */ +#define IFM_TDM_HDLC_CRC16 0x0100 /* Use 16-bit CRC for HDLC instead */ +#define IFM_TDM_PPP 0x0200 /* SPPP (dumb) */ +#define IFM_TDM_FR_ANSI 0x0400 /* Frame Relay + LMI ANSI "Annex D" */ +#define IFM_TDM_FR_CISCO 0x0800 /* Frame Relay + LMI Cisco */ +#define IFM_TDM_FR_ITU 0x1000 /* Frame Relay + LMI ITU "Q933A" */ + +/* operating mode */ +#define IFM_TDM_MASTER 0x0000000100000000ULL /* aka clock source internal */ + +/* + * Common Access Redundancy Protocol + */ +#define IFM_CARP 0x0000000000000600ULL + +/* + * Shared media sub-types + */ +#define IFM_AUTO 0ULL /* Autoselect best media */ +#define IFM_MANUAL 1ULL /* Jumper/dipswitch selects media */ +#define IFM_NONE 2ULL /* Deselect all media */ + +/* + * Shared options + */ +#define IFM_FDX 0x0000010000000000ULL /* Force full duplex */ +#define IFM_HDX 0x0000020000000000ULL /* Force half duplex */ +#define IFM_FLOW 0x0000040000000000ULL /* enable hardware flow control */ +#define IFM_FLAG0 0x0000100000000000ULL /* Driver defined flag */ +#define IFM_FLAG1 0x0000200000000000ULL /* Driver defined flag */ +#define IFM_FLAG2 0x0000400000000000ULL /* Driver defined flag */ +#define IFM_LOOP 0x0000800000000000ULL /* Put hardware in loopback */ + +/* + * Masks + */ +#define IFM_NMASK 0x000000000000ff00ULL /* Network type */ +#define IFM_NSHIFT 8 /* Network type shift */ +#define IFM_TMASK 0x00000000000000ffULL /* Media sub-type */ +#define IFM_TSHIFT 0 /* Sub-type shift */ +#define IFM_IMASK 0xff00000000000000ULL /* Instance */ +#define IFM_ISHIFT 56 /* Instance shift */ +#define IFM_OMASK 0x00000000ffff0000ULL /* Type specific options */ +#define IFM_OSHIFT 16 /* Specific options shift */ +#define IFM_MMASK 0x000000ff00000000ULL /* Mode */ +#define IFM_MSHIFT 32 /* Mode shift */ +#define IFM_GMASK 0x00ffff0000000000ULL /* Global options */ +#define IFM_GSHIFT 40 /* Global options shift */ + +/* Ethernet flow control mask */ +#define IFM_ETH_FMASK (IFM_FLOW|IFM_ETH_RXPAUSE|IFM_ETH_TXPAUSE) + +#define IFM_NMIN IFM_ETHER /* lowest Network type */ +#define IFM_NMAX IFM_NMASK /* highest Network type */ + +/* + * Status bits + */ +#define IFM_AVALID 0x0000000000000001ULL /* Active bit valid */ +#define IFM_ACTIVE 0x0000000000000002ULL /* Interface attached to working net */ + +/* Mask of "status valid" bits, for ifconfig(8). */ +#define IFM_STATUS_VALID IFM_AVALID + +/* List of "status valid" bits, for ifconfig(8). */ +#define IFM_STATUS_VALID_LIST { \ + IFM_AVALID, \ + 0 \ +} + +/* + * Macros to extract various bits of information from the media word. + */ +#define IFM_TYPE(x) ((x) & IFM_NMASK) +#define IFM_SUBTYPE(x) ((x) & IFM_TMASK) +#define IFM_INST(x) (((x) & IFM_IMASK) >> IFM_ISHIFT) +#define IFM_OPTIONS(x) ((x) & (IFM_OMASK|IFM_GMASK)) +#define IFM_MODE(x) ((x) & IFM_MMASK) + +#define IFM_INST_MAX IFM_INST(IFM_IMASK) +#define IFM_INST_ANY ((uint64_t) -1) + +/* + * Macro to create a media word. + * All arguments are IFM_* macros, except 'instance' which is a 64-bit integer. + * XXX 'operating mode' is not included here?!? + */ +#define IFM_MAKEWORD(type, subtype, options, instance) \ + ((type) | (subtype) | (options) | \ + ((uint64_t)(instance) << IFM_ISHIFT)) + +/* + * NetBSD extension not defined in the BSDI API. This is used in various + * places to get the canonical description for a given type/subtype. + * + * In the subtype and mediaopt descriptions, the valid TYPE bits are OR'd + * in to indicate which TYPE the subtype/option corresponds to. If no + * TYPE is present, it is a shared media/mediaopt. + * + * Note that these are parsed case-insensitive. + * + * Order is important. The first matching entry is the canonical name + * for a media type; subsequent matches are aliases. + */ +struct ifmedia_description { + uint64_t ifmt_word; /* word value; may be masked */ + const char *ifmt_string; /* description */ +}; + +#define IFM_TYPE_DESCRIPTIONS { \ + { IFM_ETHER, "Ethernet" }, \ + { IFM_ETHER, "ether" }, \ + { IFM_FDDI, "FDDI" }, \ + { IFM_IEEE80211, "IEEE802.11" }, \ + { IFM_TDM, "TDM" }, \ + { IFM_CARP, "CARP" }, \ + { 0, NULL }, \ +} + +#define IFM_TYPE_MATCH(dt, t) \ + (IFM_TYPE((dt)) == 0 || IFM_TYPE((dt)) == IFM_TYPE((t))) + +#define IFM_SUBTYPE_DESCRIPTIONS { \ + { IFM_AUTO, "autoselect" }, \ + { IFM_AUTO, "auto" }, \ + { IFM_MANUAL, "manual" }, \ + { IFM_NONE, "none" }, \ + \ + { IFM_ETHER|IFM_10_T, "10baseT" }, \ + { IFM_ETHER|IFM_10_T, "10baseT/UTP" }, \ + { IFM_ETHER|IFM_10_T, "UTP" }, \ + { IFM_ETHER|IFM_10_T, "10UTP" }, \ + { IFM_ETHER|IFM_10_2, "10base2" }, \ + { IFM_ETHER|IFM_10_2, "10base2/BNC" }, \ + { IFM_ETHER|IFM_10_2, "BNC" }, \ + { IFM_ETHER|IFM_10_2, "10BNC" }, \ + { IFM_ETHER|IFM_10_5, "10base5" }, \ + { IFM_ETHER|IFM_10_5, "10base5/AUI" }, \ + { IFM_ETHER|IFM_10_5, "AUI" }, \ + { IFM_ETHER|IFM_10_5, "10AUI" }, \ + { IFM_ETHER|IFM_100_TX, "100baseTX" }, \ + { IFM_ETHER|IFM_100_TX, "100TX" }, \ + { IFM_ETHER|IFM_100_FX, "100baseFX" }, \ + { IFM_ETHER|IFM_100_FX, "100FX" }, \ + { IFM_ETHER|IFM_100_T4, "100baseT4" }, \ + { IFM_ETHER|IFM_100_T4, "100T4" }, \ + { IFM_ETHER|IFM_100_VG, "100baseVG" }, \ + { IFM_ETHER|IFM_100_VG, "100VG" }, \ + { IFM_ETHER|IFM_100_T2, "100baseT2" }, \ + { IFM_ETHER|IFM_100_T2, "100T2" }, \ + { IFM_ETHER|IFM_1000_SX, "1000baseSX" }, \ + { IFM_ETHER|IFM_1000_SX, "1000SX" }, \ + { IFM_ETHER|IFM_10_STP, "10baseSTP" }, \ + { IFM_ETHER|IFM_10_STP, "STP" }, \ + { IFM_ETHER|IFM_10_STP, "10STP" }, \ + { IFM_ETHER|IFM_10_FL, "10baseFL" }, \ + { IFM_ETHER|IFM_10_FL, "FL" }, \ + { IFM_ETHER|IFM_10_FL, "10FL" }, \ + { IFM_ETHER|IFM_1000_LX, "1000baseLX" }, \ + { IFM_ETHER|IFM_1000_LX, "1000LX" }, \ + { IFM_ETHER|IFM_1000_CX, "1000baseCX" }, \ + { IFM_ETHER|IFM_1000_CX, "1000CX" }, \ + { IFM_ETHER|IFM_1000_T, "1000baseT" }, \ + { IFM_ETHER|IFM_1000_T, "1000T" }, \ + { IFM_ETHER|IFM_1000_T, "1000baseTX" }, \ + { IFM_ETHER|IFM_1000_T, "1000TX" }, \ + { IFM_ETHER|IFM_HPNA_1, "HomePNA1" }, \ + { IFM_ETHER|IFM_HPNA_1, "HPNA1" }, \ + { IFM_ETHER|IFM_10G_LR, "10GbaseLR" }, \ + { IFM_ETHER|IFM_10G_LR, "10GLR" }, \ + { IFM_ETHER|IFM_10G_LR, "10GBASE-LR" }, \ + { IFM_ETHER|IFM_10G_SR, "10GbaseSR" }, \ + { IFM_ETHER|IFM_10G_SR, "10GSR" }, \ + { IFM_ETHER|IFM_10G_SR, "10GBASE-SR" }, \ + { IFM_ETHER|IFM_10G_CX4, "10GbaseCX4" }, \ + { IFM_ETHER|IFM_10G_CX4, "10GCX4" }, \ + { IFM_ETHER|IFM_10G_CX4, "10GBASE-CX4" }, \ + { IFM_ETHER|IFM_2500_SX, "2500baseSX" }, \ + { IFM_ETHER|IFM_2500_SX, "2500SX" }, \ + { IFM_ETHER|IFM_10G_T, "10GbaseT" }, \ + { IFM_ETHER|IFM_10G_T, "10GT" }, \ + { IFM_ETHER|IFM_10G_T, "10GBASE-T" }, \ + { IFM_ETHER|IFM_10G_SFP_CU, "10GSFP+Cu" }, \ + { IFM_ETHER|IFM_10G_SFP_CU, "10GCu" }, \ + { IFM_ETHER|IFM_10G_LRM, "10GbaseLRM" }, \ + { IFM_ETHER|IFM_10G_LRM, "10GBASE-LRM" }, \ + { IFM_ETHER|IFM_40G_CR4, "40GbaseCR4" }, \ + { IFM_ETHER|IFM_40G_CR4, "40GBASE-CR4" }, \ + { IFM_ETHER|IFM_40G_SR4, "40GbaseSR4" }, \ + { IFM_ETHER|IFM_40G_SR4, "40GBASE-SR4" }, \ + { IFM_ETHER|IFM_40G_LR4, "40GbaseLR4" }, \ + { IFM_ETHER|IFM_40G_LR4, "40GBASE-LR4" }, \ + { IFM_ETHER|IFM_1000_KX, "1000base-KX" }, \ + { IFM_ETHER|IFM_1000_KX, "1000BASE-KX" }, \ + { IFM_ETHER|IFM_10G_KX4, "10GbaseKX4" }, \ + { IFM_ETHER|IFM_10G_KX4, "10GBASE-KX4" }, \ + { IFM_ETHER|IFM_10G_KR, "10GbaseKR" }, \ + { IFM_ETHER|IFM_10G_KR, "10GBASE-KR" }, \ + { IFM_ETHER|IFM_10G_CR1, "10GbaseCR1" }, \ + { IFM_ETHER|IFM_10G_CR1, "10GBASE-CR1" }, \ + { IFM_ETHER|IFM_10G_AOC, "10G-AOC" }, \ + { IFM_ETHER|IFM_20G_KR2, "20GbaseKR2" }, \ + { IFM_ETHER|IFM_20G_KR2, "20GBASE-KR2" }, \ + { IFM_ETHER|IFM_2500_KX, "2500baseKX" }, \ + { IFM_ETHER|IFM_2500_KX, "2500BASE-KX" }, \ + { IFM_ETHER|IFM_2500_T, "2500baseT" }, \ + { IFM_ETHER|IFM_2500_T, "2500BASE-T" }, \ + { IFM_ETHER|IFM_5000_T, "5000baseT" }, \ + { IFM_ETHER|IFM_5000_T, "5000BASE-T" }, \ + { IFM_ETHER|IFM_1000_SGMII, "1000base-SGMII" }, \ + { IFM_ETHER|IFM_1000_SGMII, "1000BASE-SGMII" }, \ + { IFM_ETHER|IFM_10G_SFI, "10GbaseSFI" }, \ + { IFM_ETHER|IFM_10G_SFI, "10GBASE-SFI" }, \ + { IFM_ETHER|IFM_40G_XLPPI, "40GbaseXLPPI" }, \ + { IFM_ETHER|IFM_40G_XLPPI, "40GBASE-XLPPI" }, \ + { IFM_ETHER|IFM_1000_CX_SGMII, "1000baseCX-SGMII" }, \ + { IFM_ETHER|IFM_1000_CX_SGMII, "1000BASE-CX-SGMII" }, \ + { IFM_ETHER|IFM_40G_KR4, "40GbaseKR4" }, \ + { IFM_ETHER|IFM_40G_KR4, "40GBASE-KR4" }, \ + { IFM_ETHER|IFM_40G_AOC, "40G-AOC" }, \ + { IFM_ETHER|IFM_10G_ER, "10GbaseER" }, \ + { IFM_ETHER|IFM_10G_ER, "10GBASE-ER" }, \ + { IFM_ETHER|IFM_100G_CR4, "100GbaseCR4" }, \ + { IFM_ETHER|IFM_100G_CR4, "100GBASE-CR4" }, \ + { IFM_ETHER|IFM_100G_SR4, "100GbaseSR4" }, \ + { IFM_ETHER|IFM_100G_SR4, "100GBASE-SR4" }, \ + { IFM_ETHER|IFM_100G_KR4, "100GbaseKR4" }, \ + { IFM_ETHER|IFM_100G_KR4, "100GBASE-KR4" }, \ + { IFM_ETHER|IFM_100G_LR4, "100GbaseLR4" }, \ + { IFM_ETHER|IFM_100G_LR4, "100GBASE-LR4" }, \ + { IFM_ETHER|IFM_100G_AOC, "100G-AOC" }, \ + { IFM_ETHER|IFM_56G_R4, "56GbaseR4" }, \ + { IFM_ETHER|IFM_56G_R4, "56GBASE-R4" }, \ + { IFM_ETHER|IFM_25G_CR, "25GbaseCR" }, \ + { IFM_ETHER|IFM_25G_CR, "25GBASE-CR" }, \ + { IFM_ETHER|IFM_25G_KR, "25GbaseKR" }, \ + { IFM_ETHER|IFM_25G_KR, "25GBASE-KR" }, \ + { IFM_ETHER|IFM_25G_SR, "25GbaseSR" }, \ + { IFM_ETHER|IFM_25G_SR, "25GBASE-SR" }, \ + { IFM_ETHER|IFM_25G_LR, "25GbaseLR" }, \ + { IFM_ETHER|IFM_25G_LR, "25GBASE-LR" }, \ + { IFM_ETHER|IFM_25G_ER, "25GbaseER" }, \ + { IFM_ETHER|IFM_25G_ER, "25GBASE-ER" }, \ + { IFM_ETHER|IFM_25G_AOC, "25G-AOC" }, \ + { IFM_ETHER|IFM_50G_CR2, "50GbaseCR2" }, \ + { IFM_ETHER|IFM_50G_CR2, "50GBASE-CR2" }, \ + { IFM_ETHER|IFM_50G_KR2, "50GbaseKR2" }, \ + { IFM_ETHER|IFM_50G_KR2, "50GBASE-KR2" }, \ + \ + { IFM_FDDI|IFM_FDDI_SMF, "Single-mode" }, \ + { IFM_FDDI|IFM_FDDI_SMF, "SMF" }, \ + { IFM_FDDI|IFM_FDDI_MMF, "Multi-mode" }, \ + { IFM_FDDI|IFM_FDDI_MMF, "MMF" }, \ + { IFM_FDDI|IFM_FDDI_UTP, "UTP" }, \ + { IFM_FDDI|IFM_FDDI_UTP, "CDDI" }, \ + \ + { IFM_IEEE80211|IFM_IEEE80211_FH1, "FH1" }, \ + { IFM_IEEE80211|IFM_IEEE80211_FH2, "FH2" }, \ + { IFM_IEEE80211|IFM_IEEE80211_DS2, "DS2" }, \ + { IFM_IEEE80211|IFM_IEEE80211_DS5, "DS5" }, \ + { IFM_IEEE80211|IFM_IEEE80211_DS11, "DS11" }, \ + { IFM_IEEE80211|IFM_IEEE80211_DS1, "DS1" }, \ + { IFM_IEEE80211|IFM_IEEE80211_DS22, "DS22" }, \ + { IFM_IEEE80211|IFM_IEEE80211_OFDM6, "OFDM6" }, \ + { IFM_IEEE80211|IFM_IEEE80211_OFDM9, "OFDM9" }, \ + { IFM_IEEE80211|IFM_IEEE80211_OFDM12, "OFDM12" }, \ + { IFM_IEEE80211|IFM_IEEE80211_OFDM18, "OFDM18" }, \ + { IFM_IEEE80211|IFM_IEEE80211_OFDM24, "OFDM24" }, \ + { IFM_IEEE80211|IFM_IEEE80211_OFDM36, "OFDM36" }, \ + { IFM_IEEE80211|IFM_IEEE80211_OFDM48, "OFDM48" }, \ + { IFM_IEEE80211|IFM_IEEE80211_OFDM54, "OFDM54" }, \ + { IFM_IEEE80211|IFM_IEEE80211_OFDM72, "OFDM72" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS0, "HT-MCS0" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS1, "HT-MCS1" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS2, "HT-MCS2" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS3, "HT-MCS3" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS4, "HT-MCS4" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS5, "HT-MCS5" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS6, "HT-MCS6" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS7, "HT-MCS7" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS8, "HT-MCS8" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS9, "HT-MCS9" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS10, "HT-MCS10" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS11, "HT-MCS11" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS12, "HT-MCS12" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS13, "HT-MCS13" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS14, "HT-MCS14" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS15, "HT-MCS15" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS16, "HT-MCS16" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS17, "HT-MCS17" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS18, "HT-MCS18" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS19, "HT-MCS19" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS20, "HT-MCS20" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS21, "HT-MCS21" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS22, "HT-MCS22" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS23, "HT-MCS23" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS24, "HT-MCS24" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS25, "HT-MCS25" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS26, "HT-MCS26" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS27, "HT-MCS27" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS28, "HT-MCS28" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS29, "HT-MCS29" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS30, "HT-MCS30" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS31, "HT-MCS31" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS32, "HT-MCS32" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS33, "HT-MCS33" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS34, "HT-MCS34" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS35, "HT-MCS35" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS36, "HT-MCS36" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS37, "HT-MCS37" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS38, "HT-MCS38" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS39, "HT-MCS39" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS40, "HT-MCS40" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS41, "HT-MCS41" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS42, "HT-MCS42" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS43, "HT-MCS43" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS44, "HT-MCS44" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS45, "HT-MCS45" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS46, "HT-MCS46" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS47, "HT-MCS47" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS48, "HT-MCS48" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS49, "HT-MCS49" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS50, "HT-MCS50" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS51, "HT-MCS51" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS52, "HT-MCS52" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS53, "HT-MCS53" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS54, "HT-MCS54" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS55, "HT-MCS55" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS56, "HT-MCS56" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS57, "HT-MCS57" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS58, "HT-MCS58" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS59, "HT-MCS59" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS60, "HT-MCS60" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS61, "HT-MCS61" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS62, "HT-MCS62" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS63, "HT-MCS63" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS64, "HT-MCS64" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS65, "HT-MCS65" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS66, "HT-MCS66" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS67, "HT-MCS67" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS68, "HT-MCS68" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS69, "HT-MCS69" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS70, "HT-MCS70" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS71, "HT-MCS71" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS72, "HT-MCS72" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS73, "HT-MCS73" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS74, "HT-MCS74" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS75, "HT-MCS75" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS76, "HT-MCS76" }, \ + { IFM_IEEE80211|IFM_IEEE80211_VHT_MCS0, "VHT-MCS0" }, \ + { IFM_IEEE80211|IFM_IEEE80211_VHT_MCS1, "VHT-MCS1" }, \ + { IFM_IEEE80211|IFM_IEEE80211_VHT_MCS2, "VHT-MCS2" }, \ + { IFM_IEEE80211|IFM_IEEE80211_VHT_MCS3, "VHT-MCS3" }, \ + { IFM_IEEE80211|IFM_IEEE80211_VHT_MCS4, "VHT-MCS4" }, \ + { IFM_IEEE80211|IFM_IEEE80211_VHT_MCS5, "VHT-MCS5" }, \ + { IFM_IEEE80211|IFM_IEEE80211_VHT_MCS6, "VHT-MCS6" }, \ + { IFM_IEEE80211|IFM_IEEE80211_VHT_MCS7, "VHT-MCS7" }, \ + { IFM_IEEE80211|IFM_IEEE80211_VHT_MCS8, "VHT-MCS8" }, \ + { IFM_IEEE80211|IFM_IEEE80211_VHT_MCS9, "VHT-MCS9" }, \ + \ + { IFM_TDM|IFM_TDM_T1, "t1" }, \ + { IFM_TDM|IFM_TDM_T1_AMI, "t1-ami" }, \ + { IFM_TDM|IFM_TDM_E1, "e1" }, \ + { IFM_TDM|IFM_TDM_E1_G704, "e1-g.704" }, \ + { IFM_TDM|IFM_TDM_E1_AMI, "e1-ami" }, \ + { IFM_TDM|IFM_TDM_E1_AMI_G704, "e1-ami-g.704" }, \ + { IFM_TDM|IFM_TDM_T3, "t3" }, \ + { IFM_TDM|IFM_TDM_T3_M13, "t3-m13" }, \ + { IFM_TDM|IFM_TDM_E3, "e3" }, \ + { IFM_TDM|IFM_TDM_E3_G751, "e3-g.751" }, \ + { IFM_TDM|IFM_TDM_E3_G832, "e3-g.832" }, \ + { IFM_TDM|IFM_TDM_E1_G704_CRC4, "e1-g.704-crc4" }, \ + \ + { 0, NULL }, \ +} + +#define IFM_MODE_DESCRIPTIONS { \ + { IFM_AUTO, "autoselect" }, \ + { IFM_AUTO, "auto" }, \ + { IFM_IEEE80211|IFM_IEEE80211_11A, "11a" }, \ + { IFM_IEEE80211|IFM_IEEE80211_11B, "11b" }, \ + { IFM_IEEE80211|IFM_IEEE80211_11G, "11g" }, \ + { IFM_IEEE80211|IFM_IEEE80211_FH, "fh" }, \ + { IFM_IEEE80211|IFM_IEEE80211_11N, "11n" }, \ + { IFM_IEEE80211|IFM_IEEE80211_11AC, "11ac" }, \ + { IFM_TDM|IFM_TDM_MASTER, "master" }, \ + { 0, NULL }, \ +} + +#define IFM_OPTION_DESCRIPTIONS { \ + { IFM_FDX, "full-duplex" }, \ + { IFM_FDX, "fdx" }, \ + { IFM_HDX, "half-duplex" }, \ + { IFM_HDX, "hdx" }, \ + { IFM_FLAG0, "flag0" }, \ + { IFM_FLAG1, "flag1" }, \ + { IFM_FLAG2, "flag2" }, \ + { IFM_LOOP, "loopback" }, \ + { IFM_LOOP, "hw-loopback"}, \ + { IFM_LOOP, "loop" }, \ + \ + { IFM_ETHER|IFM_ETH_MASTER, "master" }, \ + { IFM_ETHER|IFM_ETH_RXPAUSE, "rxpause" }, \ + { IFM_ETHER|IFM_ETH_TXPAUSE, "txpause" }, \ + \ + { IFM_FDDI|IFM_FDDI_DA, "dual-attach" }, \ + { IFM_FDDI|IFM_FDDI_DA, "das" }, \ + \ + { IFM_IEEE80211|IFM_IEEE80211_ADHOC, "adhoc" }, \ + { IFM_IEEE80211|IFM_IEEE80211_HOSTAP, "hostap" }, \ + { IFM_IEEE80211|IFM_IEEE80211_IBSS, "ibss" }, \ + { IFM_IEEE80211|IFM_IEEE80211_IBSSMASTER, "ibss-master" }, \ + { IFM_IEEE80211|IFM_IEEE80211_MONITOR, "monitor" }, \ + \ + { IFM_TDM|IFM_TDM_HDLC_CRC16, "hdlc-crc16" }, \ + { IFM_TDM|IFM_TDM_PPP, "ppp" }, \ + { IFM_TDM|IFM_TDM_FR_ANSI, "framerelay-ansi" }, \ + { IFM_TDM|IFM_TDM_FR_CISCO, "framerelay-cisco" }, \ + { IFM_TDM|IFM_TDM_FR_ANSI, "framerelay-itu" }, \ + \ + { 0, NULL }, \ +} + +/* + * Baudrate descriptions for the various media types. + */ +struct ifmedia_baudrate { + uint64_t ifmb_word; /* media word */ + uint64_t ifmb_baudrate; /* corresponding baudrate */ +}; + +#define IFM_BAUDRATE_DESCRIPTIONS { \ + { IFM_ETHER|IFM_10_T, IF_Mbps(10) }, \ + { IFM_ETHER|IFM_10_2, IF_Mbps(10) }, \ + { IFM_ETHER|IFM_10_5, IF_Mbps(10) }, \ + { IFM_ETHER|IFM_100_TX, IF_Mbps(100) }, \ + { IFM_ETHER|IFM_100_FX, IF_Mbps(100) }, \ + { IFM_ETHER|IFM_100_T4, IF_Mbps(100) }, \ + { IFM_ETHER|IFM_100_VG, IF_Mbps(100) }, \ + { IFM_ETHER|IFM_100_T2, IF_Mbps(100) }, \ + { IFM_ETHER|IFM_1000_SX, IF_Mbps(1000) }, \ + { IFM_ETHER|IFM_10_STP, IF_Mbps(10) }, \ + { IFM_ETHER|IFM_10_FL, IF_Mbps(10) }, \ + { IFM_ETHER|IFM_1000_LX, IF_Mbps(1000) }, \ + { IFM_ETHER|IFM_1000_CX, IF_Mbps(1000) }, \ + { IFM_ETHER|IFM_1000_T, IF_Mbps(1000) }, \ + { IFM_ETHER|IFM_HPNA_1, IF_Mbps(1) }, \ + { IFM_ETHER|IFM_10G_LR, IF_Gbps(10) }, \ + { IFM_ETHER|IFM_10G_SR, IF_Gbps(10) }, \ + { IFM_ETHER|IFM_10G_CX4, IF_Gbps(10) }, \ + { IFM_ETHER|IFM_2500_SX, IF_Mbps(2500) }, \ + { IFM_ETHER|IFM_10G_T, IF_Gbps(10) }, \ + { IFM_ETHER|IFM_10G_SFP_CU, IF_Gbps(10) }, \ + \ + { IFM_FDDI|IFM_FDDI_SMF, IF_Mbps(100) }, \ + { IFM_FDDI|IFM_FDDI_MMF, IF_Mbps(100) }, \ + { IFM_FDDI|IFM_FDDI_UTP, IF_Mbps(100) }, \ + \ + { IFM_IEEE80211|IFM_IEEE80211_FH1, IF_Mbps(1) }, \ + { IFM_IEEE80211|IFM_IEEE80211_FH2, IF_Mbps(2) }, \ + { IFM_IEEE80211|IFM_IEEE80211_DS1, IF_Mbps(1) }, \ + { IFM_IEEE80211|IFM_IEEE80211_DS2, IF_Mbps(2) }, \ + { IFM_IEEE80211|IFM_IEEE80211_DS5, IF_Mbps(5) }, \ + { IFM_IEEE80211|IFM_IEEE80211_DS11, IF_Mbps(11) }, \ + { IFM_IEEE80211|IFM_IEEE80211_DS22, IF_Mbps(22) }, \ + { IFM_IEEE80211|IFM_IEEE80211_OFDM6, IF_Mbps(6) }, \ + { IFM_IEEE80211|IFM_IEEE80211_OFDM9, IF_Mbps(9) }, \ + { IFM_IEEE80211|IFM_IEEE80211_OFDM12, IF_Mbps(12) }, \ + { IFM_IEEE80211|IFM_IEEE80211_OFDM18, IF_Mbps(18) }, \ + { IFM_IEEE80211|IFM_IEEE80211_OFDM24, IF_Mbps(24) }, \ + { IFM_IEEE80211|IFM_IEEE80211_OFDM36, IF_Mbps(36) }, \ + { IFM_IEEE80211|IFM_IEEE80211_OFDM48, IF_Mbps(48) }, \ + { IFM_IEEE80211|IFM_IEEE80211_OFDM54, IF_Mbps(54) }, \ + { IFM_IEEE80211|IFM_IEEE80211_OFDM72, IF_Mbps(72) }, \ + /* These HT rates correspond to 20 MHz channel with no SGI. */ \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS0, IF_Kbps(6500) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS1, IF_Mbps(13) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS2, IF_Kbps(19500) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS3, IF_Mbps(26) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS4, IF_Mbps(39) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS5, IF_Mbps(52) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS6, IF_Kbps(58500) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS7, IF_Mbps(65) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS8, IF_Mbps(13) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS9, IF_Mbps(26) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS10, IF_Mbps(39) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS11, IF_Mbps(52) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS12, IF_Mbps(78) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS13, IF_Mbps(104) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS14, IF_Mbps(117) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS15, IF_Mbps(130) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS16, IF_Kbps(19500) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS17, IF_Mbps(39) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS18, IF_Kbps(58500) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS19, IF_Mbps(78) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS20, IF_Mbps(117) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS21, IF_Mbps(156) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS22, IF_Kbps(175500) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS23, IF_Mbps(195) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS24, IF_Mbps(26) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS25, IF_Mbps(52) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS26, IF_Mbps(78) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS27, IF_Mbps(104) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS28, IF_Mbps(156) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS29, IF_Mbps(208) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS30, IF_Mbps(234) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS31, IF_Mbps(260) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS32, IF_Mbps(0) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS33, IF_Mbps(39) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS34, IF_Mbps(52) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS35, IF_Mbps(65) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS36, IF_Kbps(58500) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS37, IF_Mbps(78) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS38, IF_Kbps(97500) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS39, IF_Mbps(52) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS40, IF_Mbps(65) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS41, IF_Mbps(65) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS42, IF_Mbps(78) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS43, IF_Mbps(91) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS44, IF_Mbps(91) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS45, IF_Mbps(104) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS46, IF_Mbps(78) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS47, IF_Kbps(97500) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS48, IF_Kbps(97500) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS49, IF_Mbps(117) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS50, IF_Kbps(136500) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS51, IF_Kbps(136500) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS52, IF_Mbps(156) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS53, IF_Mbps(65) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS54, IF_Mbps(78) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS55, IF_Mbps(91) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS56, IF_Mbps(78) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS57, IF_Mbps(91) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS58, IF_Mbps(104) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS59, IF_Mbps(117) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS60, IF_Mbps(104) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS61, IF_Mbps(117) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS62, IF_Mbps(130) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS63, IF_Mbps(130) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS64, IF_Mbps(143) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS65, IF_Kbps(97500) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS66, IF_Mbps(117) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS67, IF_Kbps(136500) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS68, IF_Mbps(117) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS69, IF_Kbps(136500) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS70, IF_Mbps(156) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS71, IF_Kbps(175500) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS72, IF_Mbps(156) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS73, IF_Kbps(175500) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS74, IF_Mbps(195) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS75, IF_Mbps(195) }, \ + { IFM_IEEE80211|IFM_IEEE80211_HT_MCS76, IF_Kbps(214500) }, \ + /* These VHT rates correspond to 1 SS, no SGI, 40 MHz channel.*/\ + { IFM_IEEE80211|IFM_IEEE80211_VHT_MCS0, IF_Kbps(13500) }, \ + { IFM_IEEE80211|IFM_IEEE80211_VHT_MCS1, IF_Mbps(27) }, \ + { IFM_IEEE80211|IFM_IEEE80211_VHT_MCS2, IF_Kbps(40500) }, \ + { IFM_IEEE80211|IFM_IEEE80211_VHT_MCS3, IF_Mbps(54) }, \ + { IFM_IEEE80211|IFM_IEEE80211_VHT_MCS4, IF_Mbps(81) }, \ + { IFM_IEEE80211|IFM_IEEE80211_VHT_MCS5, IF_Mbps(108) }, \ + { IFM_IEEE80211|IFM_IEEE80211_VHT_MCS6, IF_Kbps(121500) }, \ + { IFM_IEEE80211|IFM_IEEE80211_VHT_MCS7, IF_Mbps(135) }, \ + { IFM_IEEE80211|IFM_IEEE80211_VHT_MCS8, IF_Mbps(162) }, \ + { IFM_IEEE80211|IFM_IEEE80211_VHT_MCS9, IF_Mbps(180) }, \ + \ + { IFM_TDM|IFM_TDM_T1, IF_Kbps(1536) }, \ + { IFM_TDM|IFM_TDM_T1_AMI, IF_Kbps(1536) }, \ + { IFM_TDM|IFM_TDM_E1, IF_Kbps(2048) }, \ + { IFM_TDM|IFM_TDM_E1_G704, IF_Kbps(2048) }, \ + { IFM_TDM|IFM_TDM_E1_AMI, IF_Kbps(2048) }, \ + { IFM_TDM|IFM_TDM_E1_AMI_G704, IF_Kbps(2048) }, \ + { IFM_TDM|IFM_TDM_T3, IF_Kbps(44736) }, \ + { IFM_TDM|IFM_TDM_T3_M13, IF_Kbps(44736) }, \ + { IFM_TDM|IFM_TDM_E3, IF_Kbps(34368) }, \ + { IFM_TDM|IFM_TDM_E3_G751, IF_Kbps(34368) }, \ + { IFM_TDM|IFM_TDM_E3_G832, IF_Kbps(34368) }, \ + { IFM_TDM|IFM_TDM_E1_G704_CRC4, IF_Kbps(2048) }, \ + \ + { 0, 0 }, \ +} + +/* + * Status bit descriptions for the various media types. + */ +struct ifmedia_status_description { + uint64_t ifms_type; + uint64_t ifms_valid; + uint64_t ifms_bit; + const char *ifms_string[2]; +}; + +#define IFM_STATUS_DESC(ifms, bit) \ + (ifms)->ifms_string[((ifms)->ifms_bit & (bit)) ? 1 : 0] + +#define IFM_STATUS_DESCRIPTIONS { \ + { IFM_ETHER, IFM_AVALID, IFM_ACTIVE, \ + { "no carrier", "active" } }, \ + { IFM_FDDI, IFM_AVALID, IFM_ACTIVE, \ + { "no ring", "inserted" } }, \ + { IFM_IEEE80211, IFM_AVALID, IFM_ACTIVE, \ + { "no network", "active" } }, \ + { IFM_TDM, IFM_AVALID, IFM_ACTIVE, \ + { "no carrier", "active" } }, \ + { IFM_CARP, IFM_AVALID, IFM_ACTIVE, \ + { "backup", "master" } }, \ + { 0, 0, 0, \ + { NULL, NULL } } \ +} +#endif /* _NET_IF_MEDIA_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/if_pflog.h b/lib/libc/include/generic-openbsd/net/if_pflog.h new file mode 100644 index 0000000000..6579d887a3 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/if_pflog.h @@ -0,0 +1,72 @@ +/* $OpenBSD: if_pflog.h,v 1.29 2021/01/13 09:13:30 mvs Exp $ */ +/* + * Copyright 2001 Niels Provos + * 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 _NET_IF_PFLOG_H_ +#define _NET_IF_PFLOG_H_ + +#include +#include + +#define PFLOG_RULESET_NAME_SIZE 16 + +struct pfloghdr { + u_int8_t length; + sa_family_t af; + u_int8_t action; + u_int8_t reason; + char ifname[IFNAMSIZ]; + char ruleset[PFLOG_RULESET_NAME_SIZE]; + u_int32_t rulenr; + u_int32_t subrulenr; + uid_t uid; + pid_t pid; + uid_t rule_uid; + pid_t rule_pid; + u_int8_t dir; + u_int8_t rewritten; + sa_family_t naf; + u_int8_t pad[1]; + struct pf_addr saddr; + struct pf_addr daddr; + u_int16_t sport; + u_int16_t dport; +}; + +#define PFLOG_HDRLEN sizeof(struct pfloghdr) +/* used to be minus pad, also used as a signature */ +#define PFLOG_REAL_HDRLEN PFLOG_HDRLEN +#define PFLOG_OLD_HDRLEN offsetof(struct pfloghdr, pad) + +#ifdef _KERNEL + +struct pflog_softc { + LIST_ENTRY(pflog_softc) sc_entry; + struct ifnet sc_if; /* the interface */ + int sc_unit; +}; + +#endif /* _KERNEL */ +#endif /* _NET_IF_PFLOG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/if_pflow.h b/lib/libc/include/generic-openbsd/net/if_pflow.h new file mode 100644 index 0000000000..389e5bf0eb --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/if_pflow.h @@ -0,0 +1,285 @@ +/* $OpenBSD: if_pflow.h,v 1.23 2023/12/16 22:16:02 mvs Exp $ */ + +/* + * Copyright (c) 2008 Henning Brauer + * Copyright (c) 2008 Joerg Goltermann + * + * 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 MIND, 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 _NET_IF_PFLOW_H_ +#define _NET_IF_PFLOW_H_ + +#define PFLOW_ID_LEN sizeof(u_int64_t) + +#define PFLOW_MAXFLOWS 30 +#define PFLOW_ENGINE_TYPE 42 +#define PFLOW_ENGINE_ID 42 +#define PFLOW_MAXBYTES 0xffffffff +#define PFLOW_TIMEOUT 30 +#define PFLOW_TMPL_TIMEOUT 30 /* rfc 5101 10.3.6 (p.40) recommends 600 */ + +#define PFLOW_IPFIX_TMPL_SET_ID 2 + +/* RFC 5102 Information Element Identifiers */ + +#define PFIX_IE_octetDeltaCount 1 +#define PFIX_IE_packetDeltaCount 2 +#define PFIX_IE_protocolIdentifier 4 +#define PFIX_IE_ipClassOfService 5 +#define PFIX_IE_sourceTransportPort 7 +#define PFIX_IE_sourceIPv4Address 8 +#define PFIX_IE_ingressInterface 10 +#define PFIX_IE_destinationTransportPort 11 +#define PFIX_IE_destinationIPv4Address 12 +#define PFIX_IE_egressInterface 14 +#define PFIX_IE_flowEndSysUpTime 21 +#define PFIX_IE_flowStartSysUpTime 22 +#define PFIX_IE_sourceIPv6Address 27 +#define PFIX_IE_destinationIPv6Address 28 +#define PFIX_IE_flowStartMilliseconds 152 +#define PFIX_IE_flowEndMilliseconds 153 + +struct pflow_flow { + u_int32_t src_ip; + u_int32_t dest_ip; + u_int32_t nexthop_ip; + u_int16_t if_index_in; + u_int16_t if_index_out; + u_int32_t flow_packets; + u_int32_t flow_octets; + u_int32_t flow_start; + u_int32_t flow_finish; + u_int16_t src_port; + u_int16_t dest_port; + u_int8_t pad1; + u_int8_t tcp_flags; + u_int8_t protocol; + u_int8_t tos; + u_int16_t src_as; + u_int16_t dest_as; + u_int8_t src_mask; + u_int8_t dest_mask; + u_int16_t pad2; +} __packed; + +struct pflow_set_header { + u_int16_t set_id; + u_int16_t set_length; /* total length of the set, + in octets, including the set header */ +} __packed; + +#define PFLOW_SET_HDRLEN sizeof(struct pflow_set_header) + +struct pflow_tmpl_hdr { + u_int16_t tmpl_id; + u_int16_t field_count; +} __packed; + +struct pflow_tmpl_fspec { + u_int16_t field_id; + u_int16_t len; +} __packed; + +/* update pflow_clone_create() when changing pflow_ipfix_tmpl_ipv4 */ +struct pflow_ipfix_tmpl_ipv4 { + struct pflow_tmpl_hdr h; + struct pflow_tmpl_fspec src_ip; + struct pflow_tmpl_fspec dest_ip; + struct pflow_tmpl_fspec if_index_in; + struct pflow_tmpl_fspec if_index_out; + struct pflow_tmpl_fspec packets; + struct pflow_tmpl_fspec octets; + struct pflow_tmpl_fspec start; + struct pflow_tmpl_fspec finish; + struct pflow_tmpl_fspec src_port; + struct pflow_tmpl_fspec dest_port; + struct pflow_tmpl_fspec tos; + struct pflow_tmpl_fspec protocol; +#define PFLOW_IPFIX_TMPL_IPV4_FIELD_COUNT 12 +#define PFLOW_IPFIX_TMPL_IPV4_ID 256 +} __packed; + +/* update pflow_clone_create() when changing pflow_ipfix_tmpl_v6 */ +struct pflow_ipfix_tmpl_ipv6 { + struct pflow_tmpl_hdr h; + struct pflow_tmpl_fspec src_ip; + struct pflow_tmpl_fspec dest_ip; + struct pflow_tmpl_fspec if_index_in; + struct pflow_tmpl_fspec if_index_out; + struct pflow_tmpl_fspec packets; + struct pflow_tmpl_fspec octets; + struct pflow_tmpl_fspec start; + struct pflow_tmpl_fspec finish; + struct pflow_tmpl_fspec src_port; + struct pflow_tmpl_fspec dest_port; + struct pflow_tmpl_fspec tos; + struct pflow_tmpl_fspec protocol; +#define PFLOW_IPFIX_TMPL_IPV6_FIELD_COUNT 12 +#define PFLOW_IPFIX_TMPL_IPV6_ID 257 +} __packed; + +struct pflow_ipfix_tmpl { + struct pflow_set_header set_header; + struct pflow_ipfix_tmpl_ipv4 ipv4_tmpl; + struct pflow_ipfix_tmpl_ipv6 ipv6_tmpl; +} __packed; + +struct pflow_ipfix_flow4 { + u_int32_t src_ip; /* sourceIPv4Address*/ + u_int32_t dest_ip; /* destinationIPv4Address */ + u_int32_t if_index_in; /* ingressInterface */ + u_int32_t if_index_out; /* egressInterface */ + u_int64_t flow_packets; /* packetDeltaCount */ + u_int64_t flow_octets; /* octetDeltaCount */ + int64_t flow_start; /* flowStartMilliseconds */ + int64_t flow_finish; /* flowEndMilliseconds */ + u_int16_t src_port; /* sourceTransportPort */ + u_int16_t dest_port; /* destinationTransportPort */ + u_int8_t tos; /* ipClassOfService */ + u_int8_t protocol; /* protocolIdentifier */ + /* XXX padding needed? */ +} __packed; + +struct pflow_ipfix_flow6 { + struct in6_addr src_ip; /* sourceIPv6Address */ + struct in6_addr dest_ip; /* destinationIPv6Address */ + u_int32_t if_index_in; /* ingressInterface */ + u_int32_t if_index_out; /* egressInterface */ + u_int64_t flow_packets; /* packetDeltaCount */ + u_int64_t flow_octets; /* octetDeltaCount */ + int64_t flow_start; /* flowStartMilliseconds */ + int64_t flow_finish; /* flowEndMilliseconds */ + u_int16_t src_port; /* sourceTransportPort */ + u_int16_t dest_port; /* destinationTransportPort */ + u_int8_t tos; /* ipClassOfService */ + u_int8_t protocol; /* protocolIdentifier */ + /* XXX padding needed? */ +} __packed; + +#ifdef _KERNEL + +#include + +/* + * Locks used to protect struct members and global data + * I immutable after creation + * m this pflow_softc' `sc_mtx' + * p this pflow_softc' `sc_lock' + */ + +struct pflow_softc { + struct mutex sc_mtx; + struct rwlock sc_lock; + + int sc_dying; /* [p] */ + struct ifnet sc_if; + + unsigned int sc_count; /* [m] */ + unsigned int sc_count4; /* [m] */ + unsigned int sc_count6; /* [m] */ + unsigned int sc_maxcount; /* [m] */ + unsigned int sc_maxcount4; /* [m] */ + unsigned int sc_maxcount6; /* [m] */ + u_int32_t sc_gcounter; /* [m] */ + u_int32_t sc_sequence; /* [m] */ + struct timeout sc_tmo; + struct timeout sc_tmo6; + struct timeout sc_tmo_tmpl; + struct mbuf_queue sc_outputqueue; + struct task sc_outputtask; + struct socket *so; /* [p] */ + struct mbuf *send_nam; /* [p] */ + struct sockaddr *sc_flowsrc; /* [p] */ + struct sockaddr *sc_flowdst; /* [p] */ + struct pflow_ipfix_tmpl sc_tmpl_ipfix; /* [I] */ + u_int8_t sc_version; /* [m] */ + struct mbuf *sc_mbuf; /* [m] current cumulative + mbuf */ + struct mbuf *sc_mbuf6; /* [m] current cumulative + mbuf */ + SMR_SLIST_ENTRY(pflow_softc) sc_next; +}; + +extern struct pflow_softc *pflowif; + +#endif /* _KERNEL */ + +struct pflow_header { + u_int16_t version; + u_int16_t count; + u_int32_t uptime_ms; + u_int32_t time_sec; + u_int32_t time_nanosec; + u_int32_t flow_sequence; + u_int8_t engine_type; + u_int8_t engine_id; + u_int8_t reserved1; + u_int8_t reserved2; +} __packed; + +#define PFLOW_HDRLEN sizeof(struct pflow_header) + +struct pflow_v10_header { + u_int16_t version; + u_int16_t length; + u_int32_t time_sec; + u_int32_t flow_sequence; + u_int32_t observation_dom; +} __packed; + +#define PFLOW_IPFIX_HDRLEN sizeof(struct pflow_v10_header) + +struct pflowstats { + u_int64_t pflow_flows; + u_int64_t pflow_packets; + u_int64_t pflow_onomem; + u_int64_t pflow_oerrors; +}; + +/* Supported flow protocols */ +#define PFLOW_PROTO_5 5 /* original pflow */ +#define PFLOW_PROTO_10 10 /* ipfix */ +#define PFLOW_PROTO_MAX 11 + +#define PFLOW_PROTO_DEFAULT PFLOW_PROTO_5 + +struct pflow_protos { + const char *ppr_name; + u_int8_t ppr_proto; +}; + +#define PFLOW_PROTOS { \ + { "5", PFLOW_PROTO_5 }, \ + { "10", PFLOW_PROTO_10 }, \ +} + +/* + * Configuration structure for SIOCSETPFLOW SIOCGETPFLOW + */ +struct pflowreq { + struct sockaddr_storage flowsrc; + struct sockaddr_storage flowdst; + u_int16_t addrmask; + u_int8_t version; +#define PFLOW_MASK_SRCIP 0x01 +#define PFLOW_MASK_DSTIP 0x02 +#define PFLOW_MASK_VERSION 0x04 +}; + +#ifdef _KERNEL +int export_pflow(struct pf_state *); +int pflow_sysctl(int *, u_int, void *, size_t *, void *, size_t); +#endif /* _KERNEL */ + +#endif /* _NET_IF_PFLOW_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/if_pfsync.h b/lib/libc/include/generic-openbsd/net/if_pfsync.h new file mode 100644 index 0000000000..70445c4146 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/if_pfsync.h @@ -0,0 +1,338 @@ +/* $OpenBSD: if_pfsync.h,v 1.65 2025/07/07 00:55:15 jsg Exp $ */ + +/* + * Copyright (c) 2001 Michael Shalayeff + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 2008 David Gwynne + * + * 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 _NET_IF_PFSYNC_H_ +#define _NET_IF_PFSYNC_H_ + +#define PFSYNC_VERSION 6 +#define PFSYNC_DFLTTL 255 + +#define PFSYNC_ACT_CLR 0 /* clear all states */ +#define PFSYNC_ACT_OINS 1 /* old insert state */ +#define PFSYNC_ACT_INS_ACK 2 /* ack of inserted state */ +#define PFSYNC_ACT_OUPD 3 /* old update state */ +#define PFSYNC_ACT_UPD_C 4 /* "compressed" update state */ +#define PFSYNC_ACT_UPD_REQ 5 /* request "uncompressed" state */ +#define PFSYNC_ACT_DEL 6 /* delete state */ +#define PFSYNC_ACT_DEL_C 7 /* "compressed" delete state */ +#define PFSYNC_ACT_INS_F 8 /* insert fragment */ +#define PFSYNC_ACT_DEL_F 9 /* delete fragments */ +#define PFSYNC_ACT_BUS 10 /* bulk update status */ +#define PFSYNC_ACT_OTDB 11 /* old TDB replay counter update */ +#define PFSYNC_ACT_EOF 12 /* end of frame - DEPRECATED */ +#define PFSYNC_ACT_INS 13 /* insert state */ +#define PFSYNC_ACT_UPD 14 /* update state */ +#define PFSYNC_ACT_TDB 15 /* TDB replay counter update */ +#define PFSYNC_ACT_MAX 16 + +#define PFSYNC_ACTIONS "CLR ST", \ + "INS ST OLD", \ + "INS ST ACK", \ + "UPD ST OLD", \ + "UPD ST COMP", \ + "UPD ST REQ", \ + "DEL ST", \ + "DEL ST COMP", \ + "INS FR", \ + "DEL FR", \ + "BULK UPD STAT", \ + "UPD TDB OLD", \ + "EOF", \ + "INS ST", \ + "UPD ST", \ + "UPD TDB" + +/* + * A pfsync frame is built from a header followed by several sections which + * are all prefixed with their own subheaders. + * + * | ... | + * | IP header | + * +============================+ + * | pfsync_header | + * +----------------------------+ + * | pfsync_subheader | + * +----------------------------+ + * | first action fields | + * | ... | + * +----------------------------+ + * | pfsync_subheader | + * +----------------------------+ + * | second action fields | + * | ... | + * +============================+ + */ + +/* + * Frame header + */ + +struct pfsync_header { + u_int8_t version; + u_int8_t _pad; + u_int16_t len; /* in bytes */ + u_int8_t pfcksum[PF_MD5_DIGEST_LENGTH]; +} __packed; + +/* + * Frame region subheader + */ + +struct pfsync_subheader { + u_int8_t action; + u_int8_t len; /* in dwords */ + u_int16_t count; +} __packed; + +/* + * CLR + */ + +struct pfsync_clr { + char ifname[IFNAMSIZ]; + u_int32_t creatorid; +} __packed; + +/* + * OINS, OUPD + */ + +/* these messages are deprecated */ + +/* + * INS, UPD, DEL + */ + +/* these use struct pfsync_state in pfvar.h */ + +/* + * INS_ACK + */ + +struct pfsync_ins_ack { + u_int64_t id; + u_int32_t creatorid; +} __packed; + +/* + * UPD_C + */ + +struct pfsync_upd_c { + u_int64_t id; + struct pfsync_state_peer src; + struct pfsync_state_peer dst; + u_int32_t creatorid; + u_int32_t expire; + u_int8_t timeout; + u_int8_t state_flags; + u_int8_t _pad[2]; +} __packed; + +/* + * UPD_REQ + */ + +struct pfsync_upd_req { + u_int64_t id; + u_int32_t creatorid; +} __packed __aligned(4); + +/* + * DEL_C + */ + +struct pfsync_del_c { + u_int64_t id; + u_int32_t creatorid; +} __packed; + +/* + * INS_F, DEL_F + */ + +/* not implemented (yet) */ + +/* + * BUS + */ + +struct pfsync_bus { + u_int32_t creatorid; + u_int32_t endtime; + u_int8_t status; +#define PFSYNC_BUS_START 1 +#define PFSYNC_BUS_END 2 + u_int8_t _pad[3]; +} __packed; + +/* + * TDB + */ +struct pfsync_tdb { + u_int32_t spi; + union sockaddr_union dst; + u_int64_t rpl; + u_int64_t cur_bytes; + u_int8_t sproto; + u_int8_t updates; + u_int16_t rdomain; +} __packed; + +/* + * EOF + */ + +/* this message is deprecated */ + + +#define PFSYNC_HDRLEN sizeof(struct pfsync_header) + + +/* + * Names for PFSYNC sysctl objects + */ +#define PFSYNCCTL_STATS 1 /* PFSYNC stats */ +#define PFSYNCCTL_MAXID 2 + +#define PFSYNCCTL_NAMES { \ + { 0, 0 }, \ + { "stats", CTLTYPE_STRUCT }, \ +} + +struct pfsyncstats { + u_int64_t pfsyncs_ipackets; /* total input packets, IPv4 */ + u_int64_t pfsyncs_ipackets6; /* total input packets, IPv6 */ + u_int64_t pfsyncs_badif; /* not the right interface */ + u_int64_t pfsyncs_badttl; /* TTL is not PFSYNC_DFLTTL */ + u_int64_t pfsyncs_hdrops; /* packets shorter than hdr */ + u_int64_t pfsyncs_badver; /* bad (incl unsupp) version */ + u_int64_t pfsyncs_badact; /* bad action */ + u_int64_t pfsyncs_badlen; /* data length does not match */ + u_int64_t pfsyncs_badauth; /* bad authentication */ + u_int64_t pfsyncs_stale; /* stale state */ + u_int64_t pfsyncs_badval; /* bad values */ + u_int64_t pfsyncs_badstate; /* insert/lookup failed */ + + u_int64_t pfsyncs_opackets; /* total output packets, IPv4 */ + u_int64_t pfsyncs_opackets6; /* total output packets, IPv6 */ + u_int64_t pfsyncs_onomem; /* no memory for an mbuf */ + u_int64_t pfsyncs_oerrors; /* ip output error */ +}; + +/* + * Configuration structure for SIOCSETPFSYNC SIOCGETPFSYNC + */ +struct pfsyncreq { + char pfsyncr_syncdev[IFNAMSIZ]; + struct in_addr pfsyncr_syncpeer; + int pfsyncr_maxupdates; + int pfsyncr_defer; +}; + +#ifdef _KERNEL + +enum pfsync_counters { + pfsyncs_ipackets, + pfsyncs_ipackets6, + pfsyncs_badif, + pfsyncs_badttl, + pfsyncs_hdrops, + pfsyncs_badver, + pfsyncs_badact, + pfsyncs_badlen, + pfsyncs_badauth, + pfsyncs_stale, + pfsyncs_badval, + pfsyncs_badstate, + pfsyncs_opackets, + pfsyncs_opackets6, + pfsyncs_onomem, + pfsyncs_oerrors, + pfsyncs_ncounters, +}; + +/* + * this shows where a pf state is with respect to the syncing. + */ +#define PFSYNC_S_IACK 0x00 +#define PFSYNC_S_UPD_C 0x01 +#define PFSYNC_S_DEL 0x02 +#define PFSYNC_S_INS 0x03 +#define PFSYNC_S_UPD 0x04 +#define PFSYNC_S_COUNT 0x05 + +#define PFSYNC_S_NONE 0xd0 +#define PFSYNC_S_SYNC 0xd1 +#define PFSYNC_S_PFSYNC 0xd2 +#define PFSYNC_S_DEAD 0xde + +int pfsync_input4(struct mbuf **, int *, int, int, + struct netstack *); +int pfsync_sysctl(int *, u_int, void *, size_t *, + void *, size_t); + +#define PFSYNC_SI_IOCTL 0x01 +#define PFSYNC_SI_CKSUM 0x02 +#define PFSYNC_SI_ACK 0x04 +#define PFSYNC_SI_PFSYNC 0x08 + +void pfsync_init_state(struct pf_state *, + const struct pf_state_key *, + const struct pf_state_key *, int); +void pfsync_insert_state(struct pf_state *); +void pfsync_update_state(struct pf_state *); +void pfsync_delete_state(struct pf_state *); +void pfsync_clear_states(u_int32_t, const char *); + +void pfsync_update_tdb(struct tdb *, int); +void pfsync_delete_tdb(struct tdb *); + +int pfsync_defer(struct pf_state *, struct mbuf *); + +int pfsync_is_up(void); +int pfsync_state_in_use(struct pf_state *); +#endif /* _KERNEL */ + +#endif /* _NET_IF_PFSYNC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/if_ppp.h b/lib/libc/include/generic-openbsd/net/if_ppp.h new file mode 100644 index 0000000000..75f3eb5918 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/if_ppp.h @@ -0,0 +1,154 @@ +/* $OpenBSD: if_ppp.h,v 1.10 2022/01/02 22:36:03 jsg Exp $ */ +/* $NetBSD: if_ppp.h,v 1.11 1996/03/15 02:28:05 paulus Exp $ */ + +/* + * if_ppp.h - Point-to-Point Protocol definitions. + * + * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The name "Carnegie Mellon University" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For permission or any legal + * details, please contact + * Office of Technology Transfer + * Carnegie Mellon University + * 5000 Forbes Avenue + * Pittsburgh, PA 15213-3890 + * (412) 268-4387, fax: (412) 268-7395 + * tech-transfer@andrew.cmu.edu + * + * 4. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by Computing Services + * at Carnegie Mellon University (http://www.cmu.edu/computing/)." + * + * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE + * FOR ANY SPECIAL, 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 _NET_IF_PPP_H_ +#define _NET_IF_PPP_H_ + +/* + * Packet sizes + */ +#define PPP_MTU 1500 /* Default MTU (size of Info field) */ +#define PPP_MAXMRU 65000 /* Largest MRU we allow */ + +/* + * Bit definitions for flags. + */ +#define SC_COMP_PROT 0x00000001 /* protocol compression (output) */ +#define SC_COMP_AC 0x00000002 /* header compression (output) */ +#define SC_COMP_TCP 0x00000004 /* TCP (VJ) compression (output) */ +#define SC_NO_TCP_CCID 0x00000008 /* disable VJ connection-id comp. */ +#define SC_REJ_COMP_AC 0x00000010 /* reject adrs/ctrl comp. on input */ +#define SC_REJ_COMP_TCP 0x00000020 /* reject TCP (VJ) comp. on input */ +#define SC_CCP_OPEN 0x00000040 /* Look at CCP packets */ +#define SC_CCP_UP 0x00000080 /* May send/recv compressed packets */ +#define SC_DEBUG 0x00010000 /* enable debug messages */ +#define SC_LOG_INPKT 0x00020000 /* log contents of good pkts recvd */ +#define SC_LOG_OUTPKT 0x00040000 /* log contents of pkts sent */ +#define SC_LOG_RAWIN 0x00080000 /* log all chars received */ +#define SC_LOG_FLUSH 0x00100000 /* log all chars flushed */ +#define SC_RCV_B7_0 0x01000000 /* have rcvd char with bit 7 = 0 */ +#define SC_RCV_B7_1 0x02000000 /* have rcvd char with bit 7 = 1 */ +#define SC_RCV_EVNP 0x04000000 /* have rcvd char with even parity */ +#define SC_RCV_ODDP 0x08000000 /* have rcvd char with odd parity */ +#define SC_MASK 0x0fff00ff /* bits that user can change */ + +/* + * State bits in sc_flags, not changeable by user. + */ +#define SC_TIMEOUT 0x00000400 /* timeout is currently pending */ +#define SC_VJ_RESET 0x00000800 /* need to reset VJ decomp */ +#define SC_COMP_RUN 0x00001000 /* compressor has been inited */ +#define SC_DECOMP_RUN 0x00002000 /* decompressor has been inited */ +#define SC_DC_ERROR 0x00004000 /* non-fatal decomp error detected */ +#define SC_DC_FERROR 0x00008000 /* fatal decomp error detected */ +#define SC_TBUSY 0x10000000 /* xmitter doesn't need a packet yet */ +#define SC_PKTLOST 0x20000000 /* have lost or dropped a packet */ +#define SC_FLUSH 0x40000000 /* flush input until next PPP_FLAG */ +#define SC_ESCAPED 0x80000000 /* saw a PPP_ESCAPE */ + +/* + * Ioctl definitions. + */ + +struct npioctl { + int protocol; /* PPP protocol, e.g. PPP_IP */ + enum NPmode mode; +}; + +/* Structure describing a CCP configuration option, for PPPIOCSCOMPRESS */ +struct ppp_option_data { + u_char *ptr; + u_int length; + int transmit; +}; + +struct ifpppstatsreq { + char ifr_name[IFNAMSIZ]; + struct ppp_stats stats; +}; + +struct ifpppcstatsreq { + char ifr_name[IFNAMSIZ]; + struct ppp_comp_stats stats; +}; + +/* + * Ioctl definitions. + */ + +#define PPPIOCGFLAGS _IOR('t', 90, int) /* get configuration flags */ +#define PPPIOCSFLAGS _IOW('t', 89, int) /* set configuration flags */ +#define PPPIOCGASYNCMAP _IOR('t', 88, int) /* get async map */ +#define PPPIOCSASYNCMAP _IOW('t', 87, int) /* set async map */ +#define PPPIOCGUNIT _IOR('t', 86, int) /* get ppp unit number */ +#define PPPIOCGRASYNCMAP _IOR('t', 85, int) /* get receive async map */ +#define PPPIOCSRASYNCMAP _IOW('t', 84, int) /* set receive async map */ +#define PPPIOCGMRU _IOR('t', 83, int) /* get max receive unit */ +#define PPPIOCSMRU _IOW('t', 82, int) /* set max receive unit */ +#define PPPIOCSMAXCID _IOW('t', 81, int) /* set VJ max slot ID */ +#define PPPIOCGXASYNCMAP _IOR('t', 80, ext_accm) /* get extended ACCM */ +#define PPPIOCSXASYNCMAP _IOW('t', 79, ext_accm) /* set extended ACCM */ +#define PPPIOCXFERUNIT _IO('t', 78) /* transfer PPP unit */ +#define PPPIOCSCOMPRESS _IOW('t', 77, struct ppp_option_data) +#define PPPIOCGNPMODE _IOWR('t', 76, struct npioctl) /* get NP mode */ +#define PPPIOCSNPMODE _IOW('t', 75, struct npioctl) /* set NP mode */ +#define PPPIOCGIDLE _IOR('t', 74, struct ppp_idle) /* get idle time */ +#define PPPIOCSPASS _IOW('t', 71, struct bpf_program) /* set pass filter */ +#define PPPIOCSACTIVE _IOW('t', 70, struct bpf_program) /* set active filt */ + +/* + * These two are interface ioctls so that pppstats can do them on + * a socket without having to open the serial device. + */ +#define SIOCGPPPSTATS _IOWR('i', 123, struct ifpppstatsreq) +#define SIOCGPPPCSTATS _IOWR('i', 122, struct ifpppcstatsreq) + +#ifdef _KERNEL +void pppattach(void); +int pppoutput(struct ifnet *, struct mbuf *, struct sockaddr *, + struct rtentry *); +void pppintr(void); +#endif +#endif /* _NET_IF_PPP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/if_pppoe.h b/lib/libc/include/generic-openbsd/net/if_pppoe.h new file mode 100644 index 0000000000..1eca1f8bb6 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/if_pppoe.h @@ -0,0 +1,75 @@ +/* $OpenBSD: if_pppoe.h,v 1.11 2025/07/06 23:34:50 jsg Exp $ */ +/* $NetBSD: if_pppoe.h,v 1.5 2003/11/28 08:56:48 keihan Exp $ */ + +/* + * Copyright (c) 2002 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Martin Husemann . + * + * 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 _NET_IF_PPPOE_H_ +#define _NET_IF_PPPOE_H_ + +#define PPPOE_NAMELEN 512 /* should be enough */ +struct pppoediscparms { + char ifname[IFNAMSIZ]; /* pppoe interface name */ + char eth_ifname[IFNAMSIZ]; /* external ethernet interface name */ + char ac_name[PPPOE_NAMELEN]; /* access concentrator name */ + char service_name[PPPOE_NAMELEN]; /* service name */ +}; + +#define PPPOESETPARMS _IOW('i', 110, struct pppoediscparms) +#define PPPOEGETPARMS _IOWR('i', 111, struct pppoediscparms) + +#define PPPOE_STATE_INITIAL 0 +#define PPPOE_STATE_PADI_SENT 1 +#define PPPOE_STATE_PADR_SENT 2 +#define PPPOE_STATE_SESSION 3 +#define PPPOE_STATE_CLOSING 4 +/* passive */ +#define PPPOE_STATE_PADO_SENT 1 + +struct pppoeconnectionstate { + char ifname[IFNAMSIZ]; /* pppoe interface name */ + u_int state; /* one of the PPPOE_STATE_ states above */ + u_int session_id; /* if state == PPPOE_STATE_SESSION */ + u_int padi_retry_no; /* number of retries already sent */ + u_int padr_retry_no; + + struct timeval session_time; /* time the session was established */ +}; + +#define PPPOEGETSESSION _IOWR('i', 112, struct pppoeconnectionstate) + +#ifdef _KERNEL + +extern struct mbuf_queue pppoediscinq; +extern struct mbuf_queue pppoeinq; + +struct mbuf *pppoe_vinput(struct ifnet *, struct mbuf *, struct netstack *); + +#endif /* _KERNEL */ +#endif /* _NET_IF_PPPOE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/if_pppvar.h b/lib/libc/include/generic-openbsd/net/if_pppvar.h new file mode 100644 index 0000000000..41c06d6d42 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/if_pppvar.h @@ -0,0 +1,178 @@ +/* $OpenBSD: if_pppvar.h,v 1.21 2024/02/28 16:08:34 denis Exp $ */ +/* $NetBSD: if_pppvar.h,v 1.5 1997/01/03 07:23:29 mikel Exp $ */ +/* + * if_pppvar.h - private structures and declarations for PPP. + * + * Copyright (c) 1989-2002 Paul Mackerras. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The name(s) of the authors of this software must not be used to + * endorse or promote products derived from this software without + * prior written permission. + * + * 4. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by Paul Mackerras + * ". + * + * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + * SPECIAL, 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. + * + * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The name "Carnegie Mellon University" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For permission or any legal + * details, please contact + * Office of Technology Transfer + * Carnegie Mellon University + * 5000 Forbes Avenue + * Pittsburgh, PA 15213-3890 + * (412) 268-4387, fax: (412) 268-7395 + * tech-transfer@andrew.cmu.edu + * + * 4. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by Computing Services + * at Carnegie Mellon University (http://www.cmu.edu/computing/)." + * + * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE + * FOR ANY SPECIAL, 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 _NET_IF_PPPVAR_H_ +#define _NET_IF_PPPVAR_H_ + +/* + * Supported network protocols. These values are used for + * indexing sc_npmode. + */ +#define NP_IP 0 /* Internet Protocol */ +#define NP_IPV6 1 /* Internet Protocol v6 */ +#define NUM_NP 2 /* Number of NPs. */ + +struct ppp_pkt; + +struct ppp_pkt_list { + struct mutex pl_mtx; + struct ppp_pkt *pl_head; + struct ppp_pkt *pl_tail; + u_int pl_count; + u_int pl_limit; +}; + +/* + * Structure describing each ppp unit. + */ +struct ppp_softc { + struct ifnet sc_if; /* network-visible interface */ + struct timeout sc_timo; /* timeout control (for ptys) */ + int sc_unit; /* XXX unit number */ + u_int sc_flags; /* control/status bits; see if_ppp.h */ + void *sc_devp; /* pointer to device-dep structure */ + void (*sc_start)(struct ppp_softc *); /* start output proc */ + void (*sc_ctlp)(struct ppp_softc *); /* rcvd control pkt */ + void (*sc_relinq)(struct ppp_softc *); /* relinquish ifunit */ + u_int16_t sc_mru; /* max receive unit */ + pid_t sc_xfer; /* used in transferring unit */ + struct ppp_pkt_list sc_rawq; /* received packets */ + struct mbuf_queue sc_inq; /* queue of input packets for daemon */ + struct ifqueue sc_fastq; /* interactive output packet q */ + struct mbuf *sc_togo; /* output packet ready to go */ + struct mbuf_list sc_npqueue; /* output packets not to be sent yet */ + struct pppstat sc_stats; /* count of bytes/pkts sent/rcvd */ + enum NPmode sc_npmode[NUM_NP]; /* what to do with each NP */ + struct compressor *sc_xcomp; /* transmit compressor */ + void *sc_xc_state; /* transmit compressor state */ + struct compressor *sc_rcomp; /* receive decompressor */ + void *sc_rc_state; /* receive decompressor state */ + time_t sc_last_sent; /* time (secs) last NP pkt sent */ + time_t sc_last_recv; /* time (secs) last NP pkt rcvd */ + struct bpf_program sc_pass_filt; /* filter for packets to pass */ + struct bpf_program sc_active_filt; /* filter for "non-idle" packets */ +#ifdef VJC + struct slcompress *sc_comp; /* vjc control buffer */ +#endif + + /* Device-dependent part for async lines. */ + ext_accm sc_asyncmap; /* async control character map */ + u_int32_t sc_rasyncmap; /* receive async control char map */ + struct mbuf *sc_outm; /* mbuf chain currently being output */ + struct ppp_pkt *sc_pkt; /* pointer to input pkt chain */ + struct ppp_pkt *sc_pktc; /* pointer to current input pkt */ + uint8_t *sc_pktp; /* ptr to next char in input pkt */ + u_int16_t sc_ilen; /* length of input packet so far */ + u_int16_t sc_fcs; /* FCS so far (input) */ + u_int16_t sc_outfcs; /* FCS so far for output packet */ + u_char sc_rawin[16]; /* chars as received */ + int sc_rawin_count; /* # in sc_rawin */ + LIST_ENTRY(ppp_softc) sc_list; /* all ppp interfaces */ +}; + +#ifdef _KERNEL + +struct ppp_pkt_hdr { + struct ppp_pkt *ph_next; /* next in pkt chain */ + struct ppp_pkt *ph_pkt; /* prev in chain or next in list */ + uint16_t ph_len; + uint16_t ph_errmark; +}; + +struct ppp_pkt { + struct ppp_pkt_hdr p_hdr; + uint8_t p_buf[MCLBYTES - sizeof(struct ppp_pkt_hdr)]; +}; + +void ppp_pkt_free(struct ppp_pkt *); + +#define PKT_NEXT(_p) ((_p)->p_hdr.ph_next) +#define PKT_PREV(_p) ((_p)->p_hdr.ph_pkt) +#define PKT_NEXTPKT(_p) ((_p)->p_hdr.ph_pkt) +#define PKT_LEN(_p) ((_p)->p_hdr.ph_len) + +extern struct ppp_softc ppp_softc[]; + +struct ppp_softc *pppalloc(pid_t pid); +void pppdealloc(struct ppp_softc *sc); +int pppioctl(struct ppp_softc *sc, u_long cmd, caddr_t data, + int flag, struct proc *p); +void ppppktin(struct ppp_softc *sc, struct ppp_pkt *pkt, int lost); +struct mbuf *ppp_dequeue(struct ppp_softc *sc); +void ppp_restart(struct ppp_softc *sc); +int pppoutput(struct ifnet *, struct mbuf *, + struct sockaddr *, struct rtentry *); +#endif /* _KERNEL */ +#endif /* _NET_IF_PPPVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/if_sec.h b/lib/libc/include/generic-openbsd/net/if_sec.h new file mode 100644 index 0000000000..d6892b0d0a --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/if_sec.h @@ -0,0 +1,44 @@ +/* $OpenBSD: if_sec.h,v 1.2 2025/03/04 15:11:30 bluhm Exp $ */ + +/* + * Copyright (c) 2023 David Gwynne + * + * 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 _NET_IF_SEC_H +#define _NET_IF_SEC_H + +#ifdef _KERNEL +struct sec_softc; +struct tdb; + +/* + * let the IPsec stack hand packets to sec(4) for input + */ + +struct sec_softc *sec_get(unsigned int); +void sec_input(struct sec_softc * , int, int, + struct mbuf *, struct netstack *); +void sec_put(struct sec_softc *); + +/* + * let the IPsec stack give tdbs to sec(4) for output + */ + +void sec_tdb_insert(struct tdb *); +void sec_tdb_remove(struct tdb *); + +#endif /* _KERNEL */ + +#endif /* _NET_IF_SEC_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/if_sppp.h b/lib/libc/include/generic-openbsd/net/if_sppp.h new file mode 100644 index 0000000000..e730e79597 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/if_sppp.h @@ -0,0 +1,245 @@ +/* $OpenBSD: if_sppp.h,v 1.31 2025/01/15 06:15:44 dlg Exp $ */ +/* $NetBSD: if_sppp.h,v 1.2.2.1 1999/04/04 06:57:39 explorer Exp $ */ + +/* + * Defines for synchronous PPP link level subroutines. + * + * Copyright (C) 1994 Cronyx Ltd. + * Author: Serge Vakulenko, + * + * Heavily revamped to conform to RFC 1661. + * Copyright (C) 1997, Joerg Wunsch. + * + * 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 FREEBSD PROJECT ``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 FREEBSD PROJECT 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: Version 2.0, Fri Oct 6 20:39:21 MSK 1995 + * + * From: if_sppp.h,v 1.8 1997/10/11 11:25:20 joerg Exp + * + * From: Id: if_sppp.h,v 1.7 1998/12/01 20:20:19 hm Exp + */ + +#ifndef _NET_IF_SPPP_H_ +#define _NET_IF_SPPP_H_ + +#define AUTHFLAG_NOCALLOUT 1 /* don't require authentication on callouts */ +#define AUTHFLAG_NORECHALLENGE 2 /* don't re-challenge CHAP */ + +/* + * Don't change the order of this. Ordering the phases this way allows + * for a comparison of ``pp_phase >= PHASE_AUTHENTICATE'' in order to + * know whether LCP is up. + */ +enum ppp_phase { + PHASE_DEAD, PHASE_ESTABLISH, PHASE_TERMINATE, + PHASE_AUTHENTICATE, PHASE_NETWORK +}; + + +#define AUTHMAXLEN 256 /* including terminating '\0' */ +#define AUTHCHALEN 16 /* length of the challenge we send */ + +/* + * Definitions to pass struct sppp data down into the kernel using the + * SIOC[SG]IFGENERIC ioctl interface. + * + * In order to use this, create a struct spppreq, fill in the cmd + * field with SPPPIOGDEFS, and put the address of this structure into + * the ifr_data portion of a struct ifreq. Pass this struct to a + * SIOCGIFGENERIC ioctl. Then replace the cmd field by SPPPIOSDEFS, + * modify the defs field as desired, and pass the struct ifreq now + * to a SIOCSIFGENERIC ioctl. + */ + +struct sauthreq { + int cmd; + u_short proto; /* authentication protocol to use */ + u_short flags; + u_char name[AUTHMAXLEN]; /* system identification name */ + u_char secret[AUTHMAXLEN]; /* secret password */ +}; + +struct spppreq { + int cmd; + enum ppp_phase phase; /* phase we're currently in */ +}; + +#include + +#define IPCP_MAX_DNSSRV 2 +struct sdnsreq { + int cmd; + struct in_addr dns[IPCP_MAX_DNSSRV]; +}; + +#define SPPPIOGDEFS ((int)(('S' << 24) + (1 << 16) + sizeof(struct spppreq))) +#define SPPPIOSDEFS ((int)(('S' << 24) + (2 << 16) + sizeof(struct spppreq))) +#define SPPPIOGMAUTH ((int)(('S' << 24) + (3 << 16) + sizeof(struct sauthreq))) +#define SPPPIOSMAUTH ((int)(('S' << 24) + (4 << 16) + sizeof(struct sauthreq))) +#define SPPPIOGHAUTH ((int)(('S' << 24) + (5 << 16) + sizeof(struct sauthreq))) +#define SPPPIOSHAUTH ((int)(('S' << 24) + (6 << 16) + sizeof(struct sauthreq))) +#define SPPPIOGDNS ((int)(('S' << 24) + (7 << 16) + sizeof(struct sdnsreq))) + + +#ifdef _KERNEL + +#include +#include + +#ifdef INET6 +#include +#endif + +#define IDX_LCP 0 /* idx into state table */ + +struct slcp { + u_long opts; /* LCP options to send (bitfield) */ + u_long magic; /* local magic number */ + u_long mru; /* our max receive unit */ + u_long their_mru; /* their max receive unit */ + u_long protos; /* bitmask of protos that are started */ + u_char echoid; /* id of last keepalive echo request */ + /* restart max values, see RFC 1661 */ + int timeout; /* seconds */ + int max_terminate; + int max_configure; + int max_failure; +}; + +#define IDX_IPCP 1 /* idx into state table */ +#define IDX_IPV6CP 2 + +struct sipcp { + u_long opts; /* IPCP options to send (bitfield) */ + u_int flags; +#define IPCP_HISADDR_SEEN 1 /* have seen his address already */ +#define IPCP_MYADDR_DYN 2 /* my address is dynamically assigned */ +#define IPCP_MYADDR_SEEN 4 /* have seen my address already */ +#define IPCP_HISADDR_DYN 8 /* his address is dynamically assigned */ +#define IPV6CP_MYIFID_DYN 1 /* my ifid is dynamically assigned */ +#define IPV6CP_MYIFID_SEEN 2 /* have seen my suggested ifid */ + u_int32_t saved_hisaddr; /* if hisaddr (IPv4) is dynamic, save + * original one here, in network byte order */ + u_int32_t req_hisaddr; /* remote address requested (IPv4) */ + u_int32_t req_myaddr; /* local address requested (IPv4) */ + struct in_addr dns[IPCP_MAX_DNSSRV]; /* IPv4 DNS servers (RFC 1877) */ +#ifdef INET6 + struct in6_aliasreq req_ifid; /* local ifid requested (IPv6) */ +#endif + struct task set_addr_task; /* set address from process context */ + struct task clear_addr_task; /* clear address from process context */ +}; + +struct sauth { + u_short proto; /* authentication protocol to use */ + u_short flags; + u_char *name; /* system identification name */ + u_char *secret; /* secret password */ +}; + +#define IDX_PAP 3 +#define IDX_CHAP 4 + +#define IDX_COUNT (IDX_CHAP + 1) /* bump this when adding cp's! */ + +struct sppp { + /* NB: pp_if _must_ be first */ + struct ifnet pp_if; /* network interface data */ + struct mbuf_queue pp_cpq; /* PPP control protocol queue */ + struct sppp *pp_next; /* next interface in keepalive list */ + u_int pp_flags; + u_int pp_framebytes; /* number of bytes added by hardware framing */ + u_short pp_alivecnt; /* keepalive packets counter */ + u_short pp_loopcnt; /* loopback detection counter */ + u_int32_t pp_seq; /* local sequence number */ + u_int32_t pp_rseq; /* remote sequence number */ + time_t pp_last_receive; /* peer's last "sign of life" */ + time_t pp_last_activity; /* second of last payload data s/r */ + enum ppp_phase pp_phase; /* phase we're currently in */ + int state[IDX_COUNT]; /* state machine */ + u_char confid[IDX_COUNT]; /* id of last configuration request */ + int rst_counter[IDX_COUNT]; /* restart counter */ + int fail_counter[IDX_COUNT]; /* negotiation failure counter */ + struct timeout ch[IDX_COUNT]; + struct timeout pap_my_to_ch; + struct slcp lcp; /* LCP params */ + struct sipcp ipcp; /* IPCP params */ + struct sipcp ipv6cp; /* IPV6CP params */ + struct sauth myauth; /* auth params, i'm peer */ + struct sauth hisauth; /* auth params, i'm authenticator */ + u_char chap_challenge[AUTHCHALEN]; /* random challenge used by CHAP */ + + /* + * These functions are filled in by sppp_attach(), and are + * expected to be used by the lower layer (hardware) drivers + * in order to communicate the (un)availability of the + * communication link. Lower layer drivers that are always + * ready to communicate (like hardware HDLC) can shortcut + * pp_up from pp_tls, and pp_down from pp_tlf. + */ + void (*pp_up)(struct sppp *sp); + void (*pp_down)(struct sppp *sp); + /* + * These functions need to be filled in by the lower layer + * (hardware) drivers if they request notification from the + * PPP layer whether the link is actually required. They + * correspond to the tls and tlf actions. + */ + void (*pp_tls)(struct sppp *sp); + void (*pp_tlf)(struct sppp *sp); + /* + * These (optional) functions may be filled by the hardware + * driver if any notification of established connections + * (currently: IPCP up) is desired (pp_con) or any internal + * state change of the interface state machine should be + * signaled for monitoring purposes (pp_chg). + */ + void (*pp_con)(struct sppp *sp); + void (*pp_chg)(struct sppp *sp, int new_state); +}; + +#define PP_KEEPALIVE 0x01 /* use keepalive protocol */ + /* 0x02 was PP_CISCO */ + /* 0x04 was PP_TIMO */ +#define PP_CALLIN 0x08 /* we are being called */ +#define PP_NEEDAUTH 0x10 /* remote requested authentication */ +#define PP_NOFRAMING 0x20 /* do not add/expect encapsulation + around PPP frames (i.e. the serial + HDLC like encapsulation, RFC1662) */ + +#define PP_MIN_MRU IP_MSS /* minimal MRU */ +#define PP_MTU 1500 /* default MTU */ +#define PP_MAX_MRU 2048 /* maximal MRU we want to negotiate */ + +void sppp_attach (struct ifnet *ifp); +void sppp_detach (struct ifnet *ifp); +void sppp_input (struct ifnet *ifp, struct mbuf *m); +int sppp_proto_up(struct ifnet *ifp, uint16_t); + +/* Workaround */ +void spppattach (struct ifnet *ifp); +int sppp_ioctl(struct ifnet *ifp, u_long cmd, void *data); + +struct mbuf *sppp_dequeue (struct ifnet *ifp); +int sppp_isempty (struct ifnet *ifp); +void sppp_flush (struct ifnet *ifp); +#endif /* _KERNEL */ +#endif /* _NET_IF_SPPP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/if_trunk.h b/lib/libc/include/generic-openbsd/net/if_trunk.h new file mode 100644 index 0000000000..eb5c51916f --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/if_trunk.h @@ -0,0 +1,255 @@ +/* $OpenBSD: if_trunk.h,v 1.32 2025/03/02 21:28:32 bluhm Exp $ */ + +/* + * Copyright (c) 2005, 2006, 2007 Reyk Floeter + * + * 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 _NET_TRUNK_H +#define _NET_TRUNK_H + +/* + * Global definitions + */ + +#define TRUNK_MAX_PORTS 32 /* logically */ +#define TRUNK_MAX_NAMESIZE 32 /* name of a protocol */ +#define TRUNK_MAX_STACKING 4 /* maximum number of stacked trunks */ + +/* Port flags */ +#define TRUNK_PORT_SLAVE 0x00000000 /* normal enslaved port */ +#define TRUNK_PORT_MASTER 0x00000001 /* primary port */ +#define TRUNK_PORT_STACK 0x00000002 /* stacked trunk port */ +#define TRUNK_PORT_ACTIVE 0x00000004 /* port is active */ +#define TRUNK_PORT_COLLECTING 0x00000008 /* port is receiving frames */ +#define TRUNK_PORT_DISTRIBUTING 0x00000010 /* port is sending frames */ +#define TRUNK_PORT_DISABLED 0x00000020 /* port is disabled */ +#define TRUNK_PORT_GLOBAL 0x80000000 /* IOCTL: global flag */ +#define TRUNK_PORT_BITS "\20\01MASTER\02STACK\03ACTIVE" \ + "\04COLLECTING\05DISTRIBUTING\06DISABLED" + +/* Supported trunk PROTOs */ +enum trunk_proto { + TRUNK_PROTO_NONE = 0, /* no trunk protocol defined */ + TRUNK_PROTO_ROUNDROBIN = 1, /* simple round robin */ + TRUNK_PROTO_FAILOVER = 2, /* active failover */ + TRUNK_PROTO_LOADBALANCE = 3, /* loadbalance */ + TRUNK_PROTO_BROADCAST = 4, /* broadcast */ + TRUNK_PROTO_LACP = 5, /* 802.3ad LACP */ + TRUNK_PROTO_MAX = 6 +}; + +struct trunk_protos { + const char *tpr_name; + enum trunk_proto tpr_proto; +}; + +#define TRUNK_PROTO_DEFAULT TRUNK_PROTO_ROUNDROBIN +#define TRUNK_PROTOS { \ + { "roundrobin", TRUNK_PROTO_ROUNDROBIN }, \ + { "failover", TRUNK_PROTO_FAILOVER }, \ + { "lacp", TRUNK_PROTO_LACP }, \ + { "loadbalance", TRUNK_PROTO_LOADBALANCE }, \ + { "broadcast", TRUNK_PROTO_BROADCAST }, \ + { "none", TRUNK_PROTO_NONE }, \ + { "default", TRUNK_PROTO_DEFAULT } \ +} + +/* + * Trunk ioctls. + */ + +/* + * LACP current operational parameters structure. + */ +struct lacp_opreq { + u_int16_t actor_prio; + u_int8_t actor_mac[ETHER_ADDR_LEN]; + u_int16_t actor_key; + u_int16_t actor_portprio; + u_int16_t actor_portno; + u_int8_t actor_state; + u_int16_t partner_prio; + u_int8_t partner_mac[ETHER_ADDR_LEN]; + u_int16_t partner_key; + u_int16_t partner_portprio; + u_int16_t partner_portno; + u_int8_t partner_state; +}; + +/* Trunk port settings */ +struct trunk_reqport { + char rp_ifname[IFNAMSIZ]; /* name of the trunk */ + char rp_portname[IFNAMSIZ]; /* name of the port */ + u_int32_t rp_prio; /* port priority */ + u_int32_t rp_flags; /* port flags */ + union { + struct lacp_opreq rpsc_lacp; + } rp_psc; +#define rp_lacpreq rp_psc.rpsc_lacp +}; + +#define SIOCGTRUNKPORT _IOWR('i', 140, struct trunk_reqport) +#define SIOCSTRUNKPORT _IOW('i', 141, struct trunk_reqport) +#define SIOCSTRUNKDELPORT _IOW('i', 142, struct trunk_reqport) + +/* Trunk, ports and options */ +struct trunk_reqall { + char ra_ifname[IFNAMSIZ]; /* name of the trunk */ + u_int ra_proto; /* trunk protocol */ + + size_t ra_size; /* size of buffer */ + struct trunk_reqport *ra_port; /* allocated buffer */ + int ra_ports; /* total port count */ + union { + struct lacp_opreq rpsc_lacp; + } ra_psc; +#define ra_lacpreq ra_psc.rpsc_lacp +}; + +#define SIOCGTRUNK _IOWR('i', 143, struct trunk_reqall) +#define SIOCSTRUNK _IOW('i', 144, struct trunk_reqall) + +/* LACP administrative options */ +struct lacp_adminopts { + u_int8_t lacp_mode; /* active or passive */ + u_int8_t lacp_timeout; /* fast or slow */ + u_int16_t lacp_prio; /* system priority */ + u_int16_t lacp_portprio; /* port priority */ + u_int8_t lacp_ifqprio; /* ifq priority */ +}; + +/* Trunk administrative options */ +struct trunk_opts { + char to_ifname[IFNAMSIZ]; /* name of the trunk */ + u_int to_proto; /* trunk protocol */ + int to_opts; /* option bitmap */ +#define TRUNK_OPT_NONE 0x00 +#define TRUNK_OPT_LACP_MODE 0x01 /* set active bit */ +#define TRUNK_OPT_LACP_TIMEOUT 0x02 /* set timeout bit */ +#define TRUNK_OPT_LACP_SYS_PRIO 0x04 /* set sys_prio bit */ +#define TRUNK_OPT_LACP_PORT_PRIO 0x08 /* set port_prio bit */ +#define TRUNK_OPT_LACP_IFQ_PRIO 0x10 /* set ifq_prio bit */ + + union { + struct lacp_adminopts rpsc_lacp; + } to_psc; +#define to_lacpopts to_psc.rpsc_lacp +}; + +#define SIOCGTRUNKOPTS _IOWR('i', 145, struct trunk_opts) +#define SIOCSTRUNKOPTS _IOW('i', 146, struct trunk_opts) + +#ifdef _KERNEL +/* + * Internal kernel part + */ +struct trunk_softc; +struct trunk_port { + struct ifnet *tp_if; /* physical interface */ + struct trunk_softc *tp_trunk; /* parent trunk */ + u_int8_t tp_lladdr[ETHER_ADDR_LEN]; + caddr_t tp_psc; /* protocol data */ + + u_char tp_iftype; /* interface type */ + u_int32_t tp_prio; /* port priority */ + u_int32_t tp_flags; /* port flags */ + struct task tp_ltask; /* if state hook */ + struct task tp_dtask; /* if detach hook */ + + /* Redirected callbacks */ + int (*tp_ioctl)(struct ifnet *, u_long, caddr_t); + int (*tp_output)(struct ifnet *, struct mbuf *, struct sockaddr *, + struct rtentry *); + void (*tp_input)(struct ifnet *, struct mbuf *, struct netstack *); + + SLIST_ENTRY(trunk_port) tp_entries; +}; + +#define tp_ifname tp_if->if_xname /* interface name */ +#define tp_ifflags tp_if->if_flags /* interface flags */ +#define tp_link_state tp_if->if_link_state /* link state */ +#define tp_capabilities tp_if->if_capabilities /* capabilities */ + +#define TRUNK_PORTACTIVE(_tp) ( \ + LINK_STATE_IS_UP((_tp)->tp_link_state) && \ + (_tp)->tp_ifflags & IFF_UP) + +struct trunk_mc { + union { + struct ether_multi *mcu_enm; + } mc_u; + struct sockaddr_storage mc_addr; + + SLIST_ENTRY(trunk_mc) mc_entries; +}; + +#define mc_enm mc_u.mcu_enm + +struct trunk_ifreq { + union { + struct ifreq ifreq; + struct { + char ifr_name[IFNAMSIZ]; + struct sockaddr_storage ifr_ss; + } ifreq_storage; + } ifreq; +}; + +struct trunk_softc { + struct arpcom tr_ac; /* virtual interface */ + enum trunk_proto tr_proto; /* trunk protocol */ + u_int tr_count; /* number of ports */ + struct trunk_port *tr_primary; /* primary port */ + struct ifmedia tr_media; /* media config */ + caddr_t tr_psc; /* protocol data */ + + SLIST_HEAD(__tplhd, trunk_port) tr_ports; /* list of interfaces */ + SLIST_ENTRY(trunk_softc) tr_entries; + + SLIST_HEAD(__mclhd, trunk_mc) tr_mc_head; /* multicast addresses */ + + /* Trunk protocol callbacks */ + int (*tr_detach)(struct trunk_softc *); + int (*tr_start)(struct trunk_softc *, struct mbuf *); + int (*tr_input)(struct trunk_softc *, struct trunk_port *, + struct mbuf *); + int (*tr_port_create)(struct trunk_port *); + void (*tr_port_destroy)(struct trunk_port *); + void (*tr_linkstate)(struct trunk_port *); + void (*tr_init)(struct trunk_softc *); + void (*tr_stop)(struct trunk_softc *); + void (*tr_req)(struct trunk_softc *, caddr_t); + void (*tr_portreq)(struct trunk_port *, caddr_t); +}; + +#define tr_ifflags tr_ac.ac_if.if_flags /* flags */ +#define tr_ifname tr_ac.ac_if.if_xname /* name */ +#define tr_capabilities tr_ac.ac_if.if_capabilities /* capabilities */ +#define tr_ifindex tr_ac.ac_if.if_index /* int index */ +#define tr_lladdr tr_ac.ac_enaddr /* lladdr */ + +#define IFCAP_TRUNK_MASK 0xffff0000 /* private capabilities */ +#define IFCAP_TRUNK_FULLDUPLEX 0x00010000 /* full duplex with >1 ports */ + +/* Private data used by the loadbalancing protocol */ +struct trunk_lb { + SIPHASH_KEY lb_key; + struct trunk_port *lb_ports[TRUNK_MAX_PORTS]; +}; + +u_int32_t trunk_hashmbuf(struct mbuf *, SIPHASH_KEY *); +#endif /* _KERNEL */ + +#endif /* _NET_TRUNK_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/if_tun.h b/lib/libc/include/generic-openbsd/net/if_tun.h new file mode 100644 index 0000000000..cb00921975 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/if_tun.h @@ -0,0 +1,122 @@ +/* $OpenBSD: if_tun.h,v 1.18 2024/11/17 00:25:07 dlg Exp $ */ + +/* + * Copyright (c) 1988, Julian Onions + * Nottingham University 1987. + * 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 _NET_IF_TUN_H_ +#define _NET_IF_TUN_H_ + +#include + +/* + * tun_hdr is a multiple of 4 bytes, but is built out of uint16_t + * fields. This allows it to sit on a 2 byte boundary in front of + * either IP (and MPLS) or Ethernet packets for tun(4) and tap(4) + * interfaces respectively while maintaining the alignment of their + * payloads. + * + * Userland can request the use of the tun_hdr using the TUNSCAP + * ioctl. This ioctl also allows userland to specify which "offload" + * capabilities it is able to accept in packets it will read from the + * kernel. It is acceptable to enable tun_hdr without enabling any + * interface offload capabilities. + * + * Once the tap_hdr is enabled, userland can write packets into the + * kernel with any of the supported features. tun(4)/tap(4) reads + * will unconditionally handle any features specified on the packet, + * regardless of what capabilities were specified by the TUNSCAP + * ioctl. + * + * The tun_hdr can be read from one interface and written directly + * to another without interpretation or modification. + * + * Use of tun_hdr and the associated capabilities are reset when a + * tun(4)/tap(4) device is closed. + */ + +struct tun_hdr { + uint16_t th_flags; +#define TUN_H_PRIO_MASK 0x7 +#define TUN_H_VTAG (1 << 4) /* th_vtag is set */ +#define TUN_H_TCP_MSS (1 << 5) /* Cut TCP frame up by th_mss */ + +#define TUN_H_IPV4_CSUM (1 << 8) +#define TUN_H_TCP_CSUM (1 << 9) +#define TUN_H_UDP_CSUM (1 << 10) +#define TUN_H_ICMP_CSUM (1 << 11) + + uint16_t th_pad; + + uint16_t th_vtag; + uint16_t th_mss; +}; + +#define TUN_OPEN 0x0001 +#define TUN_INITED 0x0002 +#define TUN_RCOLL 0x0004 /* unused */ +#define TUN_IASET 0x0008 +#define TUN_DSTADDR 0x0010 +#define TUN_RWAIT 0x0040 +#define TUN_ASYNC 0x0080 +#define TUN_NBIO 0x0100 +#define TUN_BRDADDR 0x0200 +#define TUN_STAYUP 0x0400 +#define TUN_LAYER2 0x0800 + +#define TUN_READY (TUN_OPEN | TUN_INITED) + +/* Maximum packet size */ +#define TUNMTU 3000 + +/* Maximum receive packet size (hard limit) */ +#define TUNMRU 16384 + +/* iface info */ +struct tuninfo { + u_int mtu; + u_short type; + u_short flags; + u_int baudrate; +}; +#define TUNSIFINFO _IOW('t', 91, struct tuninfo) +#define TUNGIFINFO _IOR('t', 92, struct tuninfo) + +/* ioctl for changing the broadcast/point-to-point status */ +#define TUNSIFMODE _IOW('t', 93, int) + +/* ioctl's for get/set debug */ +#define TUNSDEBUG _IOW('t', 94, int) +#define TUNGDEBUG _IOR('t', 95, int) + +struct tun_capabilities { + uint32_t tun_if_capabilities; /* IFCAP_* from net/if.h */ +}; + +#define TUNSCAP _IOW('t', 196, struct tun_capabilities) +#define TUNGCAP _IOR('t', 196, struct tun_capabilities) +#define TUNDCAP _IO('t', 196) + +#endif /* _NET_IF_TUN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/if_types.h b/lib/libc/include/generic-openbsd/net/if_types.h new file mode 100644 index 0000000000..e2603d366a --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/if_types.h @@ -0,0 +1,274 @@ +/* $OpenBSD: if_types.h,v 1.24 2022/01/02 22:36:04 jsg Exp $ */ +/* $NetBSD: if_types.h,v 1.17 2000/10/26 06:51:31 onoe Exp $ */ + +/* + * Copyright (c) 1989, 1993, 1994 + * 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. + * + * @(#)if_types.h 8.3 (Berkeley) 4/28/95 + */ + +#ifndef _NET_IF_TYPES_H_ +#define _NET_IF_TYPES_H_ + +/* + * Interface types for benefit of parsing media address headers. + * This list is derived from the SNMP list of ifTypes, originally + * documented in RFC1573, now maintained as: + * + * https://www.iana.org/assignments/ianaiftype-mib + */ + +#define IFT_OTHER 0x01 /* none of the following */ +#define IFT_1822 0x02 /* old-style arpanet imp */ +#define IFT_HDH1822 0x03 /* HDH arpanet imp */ +#define IFT_X25DDN 0x04 /* x25 to imp */ +#define IFT_X25 0x05 /* PDN X25 interface (RFC877) */ +#define IFT_ETHER 0x06 /* Ethernet CSMA/CD */ +#define IFT_ISO88023 0x07 /* CSMA/CD */ +#define IFT_ISO88024 0x08 /* Token Bus */ +#define IFT_ISO88025 0x09 /* Token Ring */ +#define IFT_ISO88026 0x0a /* MAN */ +#define IFT_STARLAN 0x0b +#define IFT_P10 0x0c /* Proteon 10MBit ring */ +#define IFT_P80 0x0d /* Proteon 80MBit ring */ +#define IFT_HY 0x0e /* Hyperchannel */ +#define IFT_FDDI 0x0f +#define IFT_LAPB 0x10 +#define IFT_SDLC 0x11 +#define IFT_T1 0x12 +#define IFT_CEPT 0x13 /* E1 - european T1 */ +#define IFT_ISDNBASIC 0x14 +#define IFT_ISDNPRIMARY 0x15 +#define IFT_PTPSERIAL 0x16 /* Proprietary PTP serial */ +#define IFT_PPP 0x17 /* RFC 1331 */ +#define IFT_LOOP 0x18 /* loopback */ +#define IFT_EON 0x19 /* ISO over IP */ +#define IFT_XETHER 0x1a /* obsolete 3MB experimental ethernet */ +#define IFT_NSIP 0x1b /* XNS over IP */ +#define IFT_SLIP 0x1c /* IP over generic TTY */ +#define IFT_ULTRA 0x1d /* Ultra Technologies */ +#define IFT_DS3 0x1e /* Generic T3 */ +#define IFT_SIP 0x1f /* SMDS */ +#define IFT_FRELAY 0x20 /* Frame Relay DTE only */ +#define IFT_RS232 0x21 +#define IFT_PARA 0x22 /* parallel-port */ +#define IFT_ARCNET 0x23 +#define IFT_ARCNETPLUS 0x24 +#define IFT_ATM 0x25 /* ATM cells */ +#define IFT_MIOX25 0x26 +#define IFT_SONET 0x27 /* SONET or SDH */ +#define IFT_X25PLE 0x28 +#define IFT_ISO88022LLC 0x29 +#define IFT_LOCALTALK 0x2a +#define IFT_SMDSDXI 0x2b +#define IFT_FRELAYDCE 0x2c /* Frame Relay DCE */ +#define IFT_V35 0x2d +#define IFT_HSSI 0x2e +#define IFT_HIPPI 0x2f +#define IFT_MODEM 0x30 /* Generic Modem */ +#define IFT_AAL5 0x31 /* AAL5 over ATM */ +#define IFT_SONETPATH 0x32 +#define IFT_SONETVT 0x33 +#define IFT_SMDSICIP 0x34 /* SMDS InterCarrier Interface */ +#define IFT_PROPVIRTUAL 0x35 /* Proprietary Virtual/internal */ +#define IFT_PROPMUX 0x36 /* Proprietary Multiplexing */ +#define IFT_IEEE80212 0x37 /* 100BaseVG */ +#define IFT_FIBRECHANNEL 0x38 /* Fibre Channel */ +#define IFT_HIPPIINTERFACE 0x39 /* HIPPI interfaces */ +#define IFT_FRAMERELAYINTERCONNECT 0x3a /* Obsolete, use either 0x20 or 0x2c */ +#define IFT_AFLANE8023 0x3b /* ATM Emulated LAN for 802.3 */ +#define IFT_AFLANE8025 0x3c /* ATM Emulated LAN for 802.5 */ +#define IFT_CCTEMUL 0x3d /* ATM Emulated circuit */ +#define IFT_FASTETHER 0x3e /* Fast Ethernet (100BaseT) */ +#define IFT_ISDN 0x3f /* ISDN and X.25 */ +#define IFT_V11 0x40 /* CCITT V.11/X.21 */ +#define IFT_V36 0x41 /* CCITT V.36 */ +#define IFT_G703AT64K 0x42 /* CCITT G703 at 64Kbps */ +#define IFT_G703AT2MB 0x43 /* Obsolete see DS1-MIB */ +#define IFT_QLLC 0x44 /* SNA QLLC */ +#define IFT_FASTETHERFX 0x45 /* Fast Ethernet (100BaseFX) */ +#define IFT_CHANNEL 0x46 /* channel */ +#define IFT_IEEE80211 0x47 /* radio spread spectrum */ +#define IFT_IBM370PARCHAN 0x48 /* IBM System 360/370 OEMI Channel */ +#define IFT_ESCON 0x49 /* IBM Enterprise Systems Connection */ +#define IFT_DLSW 0x4a /* Data Link Switching */ +#define IFT_ISDNS 0x4b /* ISDN S/T interface */ +#define IFT_ISDNU 0x4c /* ISDN U interface */ +#define IFT_LAPD 0x4d /* Link Access Protocol D */ +#define IFT_IPSWITCH 0x4e /* IP Switching Objects */ +#define IFT_RSRB 0x4f /* Remote Source Route Bridging */ +#define IFT_ATMLOGICAL 0x50 /* ATM Logical Port */ +#define IFT_DS0 0x51 /* Digital Signal Level 0 */ +#define IFT_DS0BUNDLE 0x52 /* group of ds0s on the same ds1 */ +#define IFT_BSC 0x53 /* Bisynchronous Protocol */ +#define IFT_ASYNC 0x54 /* Asynchronous Protocol */ +#define IFT_CNR 0x55 /* Combat Net Radio */ +#define IFT_ISO88025DTR 0x56 /* ISO 802.5r DTR */ +#define IFT_EPLRS 0x57 /* Ext Pos Loc Report Sys */ +#define IFT_ARAP 0x58 /* Appletalk Remote Access Protocol */ +#define IFT_PROPCNLS 0x59 /* Proprietary Connectionless Protocol*/ +#define IFT_HOSTPAD 0x5a /* CCITT-ITU X.29 PAD Protocol */ +#define IFT_TERMPAD 0x5b /* CCITT-ITU X.3 PAD Facility */ +#define IFT_FRAMERELAYMPI 0x5c /* Multiproto Interconnect over FR */ +#define IFT_X213 0x5d /* CCITT-ITU X213 */ +#define IFT_ADSL 0x5e /* Asymmetric Digital Subscriber Loop */ +#define IFT_RADSL 0x5f /* Rate-Adapt. Digital Subscriber Loop*/ +#define IFT_SDSL 0x60 /* Symmetric Digital Subscriber Loop */ +#define IFT_VDSL 0x61 /* Very H-Speed Digital Subscrib. Loop*/ +#define IFT_ISO88025CRFPINT 0x62 /* ISO 802.5 CRFP */ +#define IFT_MYRINET 0x63 /* Myricom Myrinet */ +#define IFT_VOICEEM 0x64 /* voice recEive and transMit */ +#define IFT_VOICEFXO 0x65 /* voice Foreign Exchange Office */ +#define IFT_VOICEFXS 0x66 /* voice Foreign Exchange Station */ +#define IFT_VOICEENCAP 0x67 /* voice encapsulation */ +#define IFT_VOICEOVERIP 0x68 /* voice over IP encapsulation */ +#define IFT_ATMDXI 0x69 /* ATM DXI */ +#define IFT_ATMFUNI 0x6a /* ATM FUNI */ +#define IFT_ATMIMA 0x6b /* ATM IMA */ +#define IFT_PPPMULTILINKBUNDLE 0x6c /* PPP Multilink Bundle */ +#define IFT_IPOVERCDLC 0x6d /* IBM ipOverCdlc */ +#define IFT_IPOVERCLAW 0x6e /* IBM Common Link Access to Workstn */ +#define IFT_STACKTOSTACK 0x6f /* IBM stackToStack */ +#define IFT_VIRTUALIPADDRESS 0x70 /* IBM VIPA */ +#define IFT_MPC 0x71 /* IBM multi-protocol channel support */ +#define IFT_IPOVERATM 0x72 /* IBM ipOverAtm */ +#define IFT_ISO88025FIBER 0x73 /* ISO 802.5j Fiber Token Ring */ +#define IFT_TDLC 0x74 /* IBM twinaxial data link control */ +#define IFT_GIGABITETHERNET 0x75 /* Gigabit Ethernet */ +#define IFT_HDLC 0x76 /* HDLC */ +#define IFT_LAPF 0x77 /* LAP F */ +#define IFT_V37 0x78 /* V.37 */ +#define IFT_X25MLP 0x79 /* Multi-Link Protocol */ +#define IFT_X25HUNTGROUP 0x7a /* X25 Hunt Group */ +#define IFT_TRANSPHDLC 0x7b /* Transp HDLC */ +#define IFT_INTERLEAVE 0x7c /* Interleave channel */ +#define IFT_FAST 0x7d /* Fast channel */ +#define IFT_IP 0x7e /* IP (for APPN HPR in IP networks) */ +#define IFT_DOCSCABLEMACLAYER 0x7f /* CATV Mac Layer */ +#define IFT_DOCSCABLEDOWNSTREAM 0x80 /* CATV Downstream interface */ +#define IFT_DOCSCABLEUPSTREAM 0x81 /* CATV Upstream interface */ +#define IFT_A12MPPSWITCH 0x82 /* Avalon Parallel Processor */ +#define IFT_TUNNEL 0x83 /* Encapsulation interface */ +#define IFT_COFFEE 0x84 /* coffee pot */ +#define IFT_CES 0x85 /* Circiut Emulation Service */ +#define IFT_ATMSUBINTERFACE 0x86 /* (x) ATM Sub Interface */ +#define IFT_L2VLAN 0x87 /* Layer 2 Virtual LAN using 802.1Q */ +#define IFT_L3IPVLAN 0x88 /* Layer 3 Virtual LAN - IP Protocol */ +#define IFT_L3IPXVLAN 0x89 /* Layer 3 Virtual LAN - IPX Prot. */ +#define IFT_DIGITALPOWERLINE 0x8a /* IP over Power Lines */ +#define IFT_MEDIAMAILOVERIP 0x8b /* (xxx) Multimedia Mail over IP */ +#define IFT_DTM 0x8c /* Dynamic synchronous Transfer Mode */ +#define IFT_DCN 0x8d /* Data Communications Network */ +#define IFT_IPFORWARD 0x8e /* IP Forwarding Interface */ +#define IFT_MSDSL 0x8f /* Multi-rate Symmetric DSL */ +#define IFT_IEEE1394 0x90 /* IEEE1394 High Performance SerialBus*/ +#define IFT_IFGSN 0x91 /* HIPPI-6400 */ +#define IFT_DVBRCCMACLAYER 0x92 /* DVB-RCC MAC Layer */ +#define IFT_DVBRCCDOWNSTREAM 0x93 /* DVB-RCC Downstream Channel */ +#define IFT_DVBRCCUPSTREAM 0x94 /* DVB-RCC Upstream Channel */ +#define IFT_ATMVIRTUAL 0x95 /* ATM Virtual Interface */ +#define IFT_MPLSTUNNEL 0x96 /* MPLS Tunnel Virtual Interface */ +#define IFT_SRP 0x97 /* Spatial Reuse Protocol */ +#define IFT_VOICEOVERATM 0x98 /* Voice over ATM */ +#define IFT_VOICEOVERFRAMERELAY 0x99 /* Voice Over Frame Relay */ +#define IFT_IDSL 0x9a /* Digital Subscriber Loop over ISDN */ +#define IFT_COMPOSITELINK 0x9b /* Avici Composite Link Interface */ +#define IFT_SS7SIGLINK 0x9c /* SS7 Signaling Link */ +#define IFT_PROPWIRELESSP2P 0x9d /* Prop. P2P wireless interface */ +#define IFT_FRFORWARD 0x9e /* Frame forward Interface */ +#define IFT_RFC1483 0x9f /* Multiprotocol over ATM AAL5 */ +#define IFT_USB 0xa0 /* USB Interface */ +#define IFT_IEEE8023ADLAG 0xa1 /* IEEE 802.3ad Link Aggregate*/ +#define IFT_BGPPOLICYACCOUNTING 0xa2 /* BGP Policy Accounting */ +#define IFT_FRF16MFRBUNDLE 0xa3 /* FRF.16 Multilink Frame Relay*/ +#define IFT_H323GATEKEEPER 0xa4 /* H323 Gatekeeper */ +#define IFT_H323PROXY 0xa5 /* H323 Voice and Video Proxy */ +#define IFT_MPLS 0xa6 /* MPLS */ +#define IFT_MFSIGLINK 0xa7 /* Multi-frequency signaling link */ +#define IFT_HDSL2 0xa8 /* High Bit-Rate DSL, 2nd gen. */ +#define IFT_SHDSL 0xa9 /* Multirate HDSL2 */ +#define IFT_DS1FDL 0xaa /* Facility Data Link (4Kbps) on a DS1*/ +#define IFT_POS 0xab /* Packet over SONET/SDH Interface */ +#define IFT_DVBASILN 0xac /* DVB-ASI Input */ +#define IFT_DVBASIOUT 0xad /* DVB-ASI Output */ +#define IFT_PLC 0xae /* Power Line Communications */ +#define IFT_NFAS 0xaf /* Non-Facility Associated Signaling */ +#define IFT_TR008 0xb0 /* TROO8 */ +#define IFT_GR303RDT 0xb1 /* Remote Digital Terminal */ +#define IFT_GR303IDT 0xb2 /* Integrated Digital Terminal */ +#define IFT_ISUP 0xb3 /* ISUP */ +#define IFT_PROPDOCSWIRELESSMACLAYER 0xb4 /* prop/Wireless MAC Layer */ +#define IFT_PROPDOCSWIRELESSDOWNSTREAM 0xb5 /* prop/Wireless Downstream */ +#define IFT_PROPDOCSWIRELESSUPSTREAM 0xb6 /* prop/Wireless Upstream */ +#define IFT_HIPERLAN2 0xb7 /* HIPERLAN Type 2 Radio Interface */ +#define IFT_PROPBWAP2MP 0xb8 /* PropBroadbandWirelessAccess P2MP*/ +#define IFT_SONETOVERHEADCHANNEL 0xb9 /* SONET Overhead Channel */ +#define IFT_DIGITALWRAPPEROVERHEADCHANNEL 0xba /* Digital Wrapper Overhead */ +#define IFT_AAL2 0xbb /* ATM adaptation layer 2 */ +#define IFT_RADIOMAC 0xbc /* MAC layer over radio links */ +#define IFT_ATMRADIO 0xbd /* ATM over radio links */ +#define IFT_IMT 0xbe /* Inter-Machine Trunks */ +#define IFT_MVL 0xbf /* Multiple Virtual Lines DSL */ +#define IFT_REACHDSL 0xc0 /* Long Reach DSL */ +#define IFT_FRDLCIENDPT 0xc1 /* Frame Relay DLCI End Point */ +#define IFT_ATMVCIENDPT 0xc2 /* ATM VCI End Point */ +#define IFT_OPTICALCHANNEL 0xc3 /* Optical Channel */ +#define IFT_OPTICALTRANSPORT 0xc4 /* Optical Transport */ +#define IFT_PROPATM 0xc5 /* Proprietary ATM */ +#define IFT_VOICEOVERCABLE 0xc6 /* Voice Over Cable Interface */ +#define IFT_INFINIBAND 0xc7 /* Infiniband */ +#define IFT_TELINK 0xc8 /* TE Link */ +#define IFT_Q2931 0xc9 /* Q.2931 */ +#define IFT_VIRTUALTG 0xca /* Virtual Trunk Group */ +#define IFT_SIPTG 0xcb /* SIP Trunk Group */ +#define IFT_SIPSIG 0xcc /* SIP Signaling */ +#define IFT_DOCSCABLEUPSTREAMCHANNEL 0xcd /* CATV Upstream Channel */ +#define IFT_ECONET 0xce /* Acorn Econet */ +#define IFT_PON155 0xcf /* FSAN 155Mb Symmetrical PON interface */ +#define IFT_PON622 0xd0 /* FSAN 622Mb Symmetrical PON interface */ +#define IFT_BRIDGE 0xd1 /* Transparent bridge interface */ +#define IFT_LINEGROUP 0xd2 /* Interface common to multiple lines */ +#define IFT_VOICEEMFGD 0xd3 /* voice E&M Feature Group D */ +#define IFT_VOICEFGDEANA 0xd4 /* voice FGD Exchange Access North American */ +#define IFT_VOICEDID 0xd5 /* voice Direct Inward Dialing */ + +/* private usage... how should we define these? */ +#define IFT_GIF 0xf0 +#define IFT_DUMMY 0xf1 +#define IFT_PVC 0xf2 +#define IFT_FAITH 0xf3 +#define IFT_ENC 0xf4 /* Encapsulation */ +#define IFT_PFLOG 0xf5 /* Packet filter logging */ +#define IFT_PFSYNC 0xf6 /* Packet filter state syncing */ +#define IFT_CARP 0xf7 /* Common Address Redundancy Protocol */ +#define IFT_BLUETOOTH 0xf8 /* Bluetooth */ +#define IFT_PFLOW 0xf9 /* pflow */ +#define IFT_MBIM 0xfa /* Mobile Broadband Interface Model */ +#define IFT_WIREGUARD 0xfb /* WireGuard tunnel */ + +#endif /* _NET_IF_TYPES_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/if_var.h b/lib/libc/include/generic-openbsd/net/if_var.h new file mode 100644 index 0000000000..f1fb1fb1cd --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/if_var.h @@ -0,0 +1,406 @@ +/* $OpenBSD: if_var.h,v 1.139 2025/07/19 16:40:40 mvs Exp $ */ +/* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */ + +/* + * Copyright (c) 2012-2013 Henning Brauer + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)if.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NET_IF_VAR_H_ +#define _NET_IF_VAR_H_ + +#ifdef _KERNEL + +#include +#include +#include +#include +#include +#include + +#include +#include + +/* + * Structures defining a network interface, providing a packet + * transport mechanism (ala level 0 of the PUP protocols). + * + * Each interface accepts output datagrams of a specified maximum + * length, and provides higher level routines with input datagrams + * received from its medium. + * + * Output occurs when the routine if_output is called, with four parameters: + * (*ifp->if_output)(ifp, m, dst, rt) + * Here m is the mbuf chain to be sent and dst is the destination address. + * The output routine encapsulates the supplied datagram if necessary, + * and then transmits it on its medium. + * + * On input, each interface unwraps the data received by it, and either + * places it on the input queue of an internetwork datagram routine + * and posts the associated software interrupt, or passes the datagram to a raw + * packet input routine. + * + * Routines exist for locating interfaces by their addresses + * or for locating an interface on a certain network, as well as more general + * routing and gateway routines maintaining information used to locate + * interfaces. These routines live in the files if.c and route.c + */ + +/* + * Locks used to protect struct members in this file: + * I immutable after creation + * d protection left to the driver + * c only used in ioctl or routing socket contexts (kernel lock) + * K kernel lock + * N net lock + * T if_tmplist_lock + * + * For SRP related structures that allow lock-free reads, the write lock + * is indicated below. + */ + +struct rtentry; +struct ifnet; +struct task; +struct cpumem; + +struct netstack { + struct route ns_route; + struct mbuf_list ns_tcp_ml; + struct mbuf_list ns_tcp6_ml; +}; + +/* + * Structure describing a `cloning' interface. + */ +struct if_clone { + LIST_ENTRY(if_clone) ifc_list; /* [I] on list of cloners */ + const char *ifc_name; /* name of device, e.g. `gif' */ + size_t ifc_namelen; /* length of name */ + + int (*ifc_create)(struct if_clone *, int); + int (*ifc_destroy)(struct ifnet *); +}; + +#define IF_CLONE_INITIALIZER(name, create, destroy) \ +{ \ + .ifc_list = { NULL, NULL }, \ + .ifc_name = name, \ + .ifc_namelen = sizeof(name) - 1, \ + .ifc_create = create, \ + .ifc_destroy = destroy, \ +} + +enum if_counters { + ifc_ipackets, /* packets received on interface */ + ifc_ierrors, /* input errors on interface */ + ifc_opackets, /* packets sent on interface */ + ifc_oerrors, /* output errors on interface */ + ifc_collisions, /* collisions on csma interfaces */ + ifc_ibytes, /* total number of octets received */ + ifc_obytes, /* total number of octets sent */ + ifc_imcasts, /* packets received via multicast */ + ifc_omcasts, /* packets sent via multicast */ + ifc_iqdrops, /* dropped on input, this interface */ + ifc_oqdrops, /* dropped on output, this interface */ + ifc_noproto, /* destined for unsupported protocol */ + + ifc_ncounters +}; + +/* + * Structure defining a queue for a network interface. + * + * (Would like to call this struct ``if'', but C isn't PL/1.) + */ +TAILQ_HEAD(ifnet_head, ifnet); /* the actual queue head */ + +struct ifnet { /* and the entries */ + void *if_softc; /* [I] lower-level data for this if */ + struct refcnt if_refcnt; + TAILQ_ENTRY(ifnet) if_list; /* [NK] all struct ifnets are chained */ + TAILQ_ENTRY(ifnet) if_tmplist; /* [T] temporary list */ + TAILQ_HEAD(, ifaddr) if_addrlist; /* [N] list of addresses per if */ + TAILQ_HEAD(, ifmaddr) if_maddrlist; /* [N] list of multicast records */ + TAILQ_HEAD(, ifg_list) if_groups; /* [N] list of groups per if */ + struct task_list if_addrhooks; /* [I] address change callbacks */ + struct task_list if_linkstatehooks; /* [I] link change callbacks*/ + struct task_list if_detachhooks; /* [I] detach callbacks */ + /* [I] check or clean routes (+ or -)'d */ + void (*if_rtrequest)(struct ifnet *, int, struct rtentry *); + char if_xname[IFNAMSIZ]; /* [I] external name (name + unit) */ + int if_pcount; /* [N] # of promiscuous listeners */ + unsigned int if_bridgeidx; /* [K] used by bridge ports */ + caddr_t if_bpf; /* packet filter structure */ + caddr_t if_mcast; /* used by multicast code */ + caddr_t if_mcast6; /* used by IPv6 multicast code */ + caddr_t if_pf_kif; /* pf interface abstraction */ + union { + struct srpl carp_s; /* carp if list (used by !carp ifs) */ + unsigned int carp_idx; /* index of carpdev (used by carp + ifs) */ + } if_carp_ptr; +#define if_carp if_carp_ptr.carp_s +#define if_carpdevidx if_carp_ptr.carp_idx + unsigned int if_index; /* [I] unique index for this if */ + short if_timer; /* time 'til if_watchdog called */ + unsigned short if_flags; /* [N] up/down, broadcast, etc. */ + int if_xflags; /* [N] extra softnet flags */ + + /* Stats and other data about if. Should be in sync with if_data. */ + u_char if_type; + u_char if_addrlen; + u_char if_hdrlen; + u_char if_link_state; + uint32_t if_mtu; + uint32_t if_metric; + uint64_t if_baudrate; + uint32_t if_capabilities; + uint32_t if_rdomain; + struct timeval if_lastchange; /* [c] last op. state change */ + uint64_t if_data_counters[ifc_ncounters]; + + struct cpumem *if_counters; /* per cpu stats */ + uint32_t if_hardmtu; /* [d] maximum MTU device supports */ + char if_description[IFDESCRSIZE]; /* [c] interface description */ + u_short if_rtlabelid; /* [c] next route label */ + uint8_t if_priority; /* [c] route priority offset */ + uint8_t if_llprio; /* [N] link layer priority */ + struct timeout if_slowtimo; /* [I] watchdog timeout */ + struct task if_watchdogtask; /* [I] watchdog task */ + struct task if_linkstatetask; /* [I] task to do route updates */ + + /* procedure handles */ + void (*if_input)(struct ifnet *, struct mbuf *, struct netstack *); + int (*if_bpf_mtap)(caddr_t, const struct mbuf *, u_int); + int (*if_output)(struct ifnet *, struct mbuf *, struct sockaddr *, + struct rtentry *); /* output routine (enqueue) */ + /* link level output function */ + int (*if_ll_output)(struct ifnet *, struct mbuf *, + struct sockaddr *, struct rtentry *); + int (*if_enqueue)(struct ifnet *, struct mbuf *); + void (*if_start)(struct ifnet *); /* initiate output */ + int (*if_ioctl)(struct ifnet *, u_long, caddr_t); /* ioctl hook */ + void (*if_watchdog)(struct ifnet *); /* timer routine */ + int (*if_wol)(struct ifnet *, int); /* WoL routine **/ + + /* queues */ + struct ifqueue if_snd; /* transmit queue */ + struct ifqueue **if_ifqs; /* [I] pointer to an array of sndqs */ + void (*if_qstart)(struct ifqueue *); + unsigned int if_nifqs; /* [I] number of output queues */ + unsigned int if_txmit; /* [c] txmitigation amount */ + + struct ifiqueue if_rcv; /* rx/input queue */ + struct ifiqueue **if_iqs; /* [I] pointer to the array of iqs */ + unsigned int if_niqs; /* [I] number of input queues */ + + struct sockaddr_dl *if_sadl; /* [N] pointer to our sockaddr_dl */ + + struct nd_ifinfo *if_nd; /* [I] IPv6 Neighbor Discovery info */ +}; + +#define if_ipackets if_data_counters[ifc_ipackets] +#define if_ierrors if_data_counters[ifc_ierrors] +#define if_opackets if_data_counters[ifc_opackets] +#define if_oerrors if_data_counters[ifc_oerrors] +#define if_collisions if_data_counters[ifc_collisions] +#define if_ibytes if_data_counters[ifc_ibytes] +#define if_obytes if_data_counters[ifc_obytes] +#define if_imcasts if_data_counters[ifc_imcasts] +#define if_omcasts if_data_counters[ifc_omcasts] +#define if_iqdrops if_data_counters[ifc_iqdrops] +#define if_oqdrops if_data_counters[ifc_oqdrops] +#define if_noproto if_data_counters[ifc_noproto] + +/* + * The ifaddr structure contains information about one address + * of an interface. They are maintained by the different address families, + * are allocated and attached when an address is set, and are linked + * together so all addresses for an interface can be located. + */ +struct ifaddr { + struct sockaddr *ifa_addr; /* address of interface */ + struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */ +#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ + struct sockaddr *ifa_netmask; /* used to determine subnet */ + struct ifnet *ifa_ifp; /* back-pointer to interface */ + TAILQ_ENTRY(ifaddr) ifa_list; /* [N] list of addresses for + interface */ + u_int ifa_flags; /* interface flags, see below */ + struct refcnt ifa_refcnt; /* number of `rt_ifa` references */ + int ifa_metric; /* cost of going out this interface */ +}; + +#define IFA_ROUTE 0x01 /* Auto-magically installed route */ + +/* + * Interface multicast address. + */ +struct ifmaddr { + struct sockaddr *ifma_addr; /* Protocol address */ + unsigned int ifma_ifidx; /* Index of the interface */ + struct refcnt ifma_refcnt; /* Count of references */ + TAILQ_ENTRY(ifmaddr) ifma_list; /* Per-interface list */ +}; + +/* + * interface groups + */ + +struct ifg_group { + char ifg_group[IFNAMSIZ]; /* [I] group name */ + u_int ifg_refcnt; /* [N] group reference count */ + caddr_t ifg_pf_kif; /* [I] pf interface group */ + int ifg_carp_demoted; /* [K] carp demotion counter */ + TAILQ_HEAD(, ifg_member) ifg_members; /* [N] list of members per group */ + TAILQ_ENTRY(ifg_group) ifg_next; /* [N] all groups are chained */ + + struct refcnt ifg_tmprefcnt; + TAILQ_ENTRY(ifg_group) ifg_tmplist; /* [T] temporary list */ +}; + +struct ifg_member { + TAILQ_ENTRY(ifg_member) ifgm_next; /* [N] all members are chained */ + struct ifnet *ifgm_ifp; /* [I] member interface */ +}; + +struct ifg_list { + struct ifg_group *ifgl_group; /* [I] interface group */ + TAILQ_ENTRY(ifg_list) ifgl_next; /* [N] all groups are chained */ +}; + +#define IFNET_SLOWTIMO 1 /* granularity is 1 second */ + +#define IF_TXMIT_MIN 1 +#define IF_TXMIT_DEFAULT 16 + +/* default interface priorities */ +#define IF_WIRED_DEFAULT_PRIORITY 0 +#define IF_WIRELESS_DEFAULT_PRIORITY 4 +#define IF_WWAN_DEFAULT_PRIORITY 6 +#define IF_CARP_DEFAULT_PRIORITY 15 + +/* + * Network stack input queues. + */ +struct niqueue { + struct mbuf_queue ni_q; + u_int ni_isr; +}; + +#define NIQUEUE_INITIALIZER(_len, _isr) \ + { MBUF_QUEUE_INITIALIZER((_len), IPL_NET), (_isr) } + +int niq_enqueue(struct niqueue *, struct mbuf *); + +#define niq_dequeue(_q) mq_dequeue(&(_q)->ni_q) +#define niq_delist(_q, _ml) mq_delist(&(_q)->ni_q, (_ml)) +#define niq_len(_q) mq_len(&(_q)->ni_q) +#define niq_drops(_q) mq_drops(&(_q)->ni_q) +#define sysctl_niq(_n, _l, _op, _olp, _np, _nl, _niq) \ + sysctl_mq((_n), (_l), (_op), (_olp), (_np), (_nl), &(_niq)->ni_q) + +extern struct rwlock if_tmplist_lock; +extern struct ifnet_head ifnetlist; + +void if_start(struct ifnet *); +int if_enqueue(struct ifnet *, struct mbuf *); +int if_enqueue_ifq(struct ifnet *, struct mbuf *); +void if_input(struct ifnet *, struct mbuf_list *); +void if_vinput(struct ifnet *, struct mbuf *, struct netstack *); +void if_input_process(struct ifnet *, struct mbuf_list *, unsigned int); +int if_input_local(struct ifnet *, struct mbuf *, sa_family_t, + struct netstack *); +int if_output_ml(struct ifnet *, struct mbuf_list *, + struct sockaddr *, struct rtentry *); +int if_output_mq(struct ifnet *, struct mbuf_queue *, unsigned int *, + struct sockaddr *, struct rtentry *); +int if_output_tso(struct ifnet *, struct mbuf **, struct sockaddr *, + struct rtentry *, u_int); +int if_output_local(struct ifnet *, struct mbuf *, sa_family_t); +void if_rtrequest_dummy(struct ifnet *, int, struct rtentry *); +void p2p_rtrequest(struct ifnet *, int, struct rtentry *); +void p2p_input(struct ifnet *, struct mbuf *, struct netstack *); +int p2p_bpf_mtap(caddr_t, const struct mbuf *, u_int); + +struct ifaddr *ifa_ifwithaddr(const struct sockaddr *, u_int); +struct ifaddr *ifa_ifwithdstaddr(const struct sockaddr *, u_int); +struct ifaddr *ifaof_ifpforaddr(const struct sockaddr *, struct ifnet *); +struct ifaddr *ifaref(struct ifaddr *); +void ifafree(struct ifaddr *); + +int if_isconnected(const struct ifnet *, unsigned int); + +void if_clone_attach(struct if_clone *); + +int if_clone_create(const char *, int); +int if_clone_destroy(const char *); + +struct if_clone * + if_clone_lookup(const char *, int *); + +void ifa_add(struct ifnet *, struct ifaddr *); +void ifa_del(struct ifnet *, struct ifaddr *); +void ifa_update_broadaddr(struct ifnet *, struct ifaddr *, + struct sockaddr *); + +void if_addrhook_add(struct ifnet *, struct task *); +void if_addrhook_del(struct ifnet *, struct task *); +void if_addrhooks_run(struct ifnet *); +void if_linkstatehook_add(struct ifnet *, struct task *); +void if_linkstatehook_del(struct ifnet *, struct task *); +void if_detachhook_add(struct ifnet *, struct task *); +void if_detachhook_del(struct ifnet *, struct task *); + +void if_rxr_livelocked(struct if_rxring *); +void if_rxr_init(struct if_rxring *, u_int, u_int); +u_int if_rxr_get(struct if_rxring *, u_int); + +#define if_rxr_put(_r, _c) do { (_r)->rxr_alive -= (_c); } while (0) +#define if_rxr_needrefill(_r) ((_r)->rxr_alive < (_r)->rxr_lwm) +#define if_rxr_inuse(_r) ((_r)->rxr_alive) +#define if_rxr_cwm(_r) ((_r)->rxr_cwm) + +int if_rxr_info_ioctl(struct if_rxrinfo *, u_int, struct if_rxring_info *); +int if_rxr_ioctl(struct if_rxrinfo *, const char *, u_int, + struct if_rxring *); + +void if_counters_alloc(struct ifnet *); +void if_counters_free(struct ifnet *); + +int if_txhprio_l2_check(int); +int if_txhprio_l3_check(int); +int if_rxhprio_l2_check(int); +int if_rxhprio_l3_check(int); + +#endif /* _KERNEL */ + +#endif /* _NET_IF_VAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/if_vlan_var.h b/lib/libc/include/generic-openbsd/net/if_vlan_var.h new file mode 100644 index 0000000000..fa7b985beb --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/if_vlan_var.h @@ -0,0 +1,55 @@ +/* $OpenBSD: if_vlan_var.h,v 1.48 2025/03/02 21:28:32 bluhm Exp $ */ + +/* + * Copyright 1998 Massachusetts Institute of Technology + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby + * granted, provided that both the above copyright notice and this + * permission notice appear in all copies, that both the above + * copyright notice and this permission notice appear in all + * supporting documentation, and that the name of M.I.T. not be used + * in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. M.I.T. makes + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS + * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + * SHALL M.I.T. 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. + * + * $FreeBSD: src/sys/net/if_vlan_var.h,v 1.3 1999/08/28 00:48:24 peter Exp $ + */ + +#ifndef _NET_IF_VLAN_VAR_H_ +#define _NET_IF_VLAN_VAR_H_ + +/* sysctl(3) tags, for compatibility purposes */ +#define VLANCTL_PROTO 1 +#define VLANCTL_MAX 2 + +/* + * Configuration structure for SIOCSETVLAN and SIOCGETVLAN ioctls. + */ +struct vlanreq { + char vlr_parent[IFNAMSIZ]; + u_short vlr_tag; +}; + +#ifdef _KERNEL +struct mbuf *vlan_input(struct ifnet *, struct mbuf *, unsigned int *, + struct netstack *); +struct mbuf *vlan_inject(struct mbuf *, uint16_t, uint16_t); +#endif /* _KERNEL */ + +#endif /* _NET_IF_VLAN_VAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/if_wg.h b/lib/libc/include/generic-openbsd/net/if_wg.h new file mode 100644 index 0000000000..5a0534f770 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/if_wg.h @@ -0,0 +1,109 @@ +/* $OpenBSD: if_wg.h,v 1.7 2025/07/10 05:28:13 dlg Exp $ */ + +/* + * Copyright (C) 2015-2020 Jason A. Donenfeld . All Rights Reserved. + * Copyright (C) 2019-2020 Matt Dunwoodie + * + * 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 __IF_WG_H__ +#define __IF_WG_H__ + +#include +#include + + +/* + * This is the public interface to the WireGuard network interface. + * + * It is designed to be used by tools such as ifconfig(8) and wg(8). + */ + +#define WG_KEY_LEN 32 + +/* + * These ioctls do not need a NETLOCK as they use their own locks to serialise + * access. + */ +#define SIOCSWG _IOWR('i', 210, struct wg_data_io) +#define SIOCGWG _IOWR('i', 211, struct wg_data_io) + +#define a_ipv4 a_addr.addr_ipv4 +#define a_ipv6 a_addr.addr_ipv6 + +struct wg_aip_io { + sa_family_t a_af; + int a_cidr; + union wg_aip_addr { + uint8_t addr_bytes; + struct in_addr addr_ipv4; + struct in6_addr addr_ipv6; + } a_addr; +}; + +#define WG_PEER_HAS_PUBLIC (1 << 0) +#define WG_PEER_HAS_PSK (1 << 1) +#define WG_PEER_HAS_PKA (1 << 2) +#define WG_PEER_HAS_ENDPOINT (1 << 3) +#define WG_PEER_REPLACE_AIPS (1 << 4) +#define WG_PEER_REMOVE (1 << 5) +#define WG_PEER_UPDATE (1 << 6) +#define WG_PEER_SET_DESCRIPTION (1 << 7) + +#define p_sa p_endpoint.sa_sa +#define p_sin p_endpoint.sa_sin +#define p_sin6 p_endpoint.sa_sin6 + +struct wg_peer_io { + int p_flags; + int p_protocol_version; + uint8_t p_public[WG_KEY_LEN]; + uint8_t p_psk[WG_KEY_LEN]; + uint16_t p_pka; + union wg_peer_endpoint { + struct sockaddr sa_sa; + struct sockaddr_in sa_sin; + struct sockaddr_in6 sa_sin6; + } p_endpoint; + uint64_t p_txbytes; + uint64_t p_rxbytes; + struct timespec p_last_handshake; /* nanotime */ + char p_description[IFDESCRSIZE]; + size_t p_aips_count; + struct wg_aip_io p_aips[]; +}; + +#define WG_INTERFACE_HAS_PUBLIC (1 << 0) +#define WG_INTERFACE_HAS_PRIVATE (1 << 1) +#define WG_INTERFACE_HAS_PORT (1 << 2) +#define WG_INTERFACE_HAS_RTABLE (1 << 3) +#define WG_INTERFACE_REPLACE_PEERS (1 << 4) + +struct wg_interface_io { + uint8_t i_flags; + in_port_t i_port; + int i_rtable; + uint8_t i_public[WG_KEY_LEN]; + uint8_t i_private[WG_KEY_LEN]; + size_t i_peers_count; + struct wg_peer_io i_peers[]; +}; + +struct wg_data_io { + char wgd_name[IFNAMSIZ]; + size_t wgd_size; /* total size of the memory pointed to by wgd_interface */ + struct wg_interface_io *wgd_interface; +}; + +#endif /* __IF_WG_H__ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/ifq.h b/lib/libc/include/generic-openbsd/net/ifq.h new file mode 100644 index 0000000000..fe5ea079f9 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/ifq.h @@ -0,0 +1,507 @@ +/* $OpenBSD: ifq.h,v 1.44 2025/03/04 01:13:37 dlg Exp $ */ + +/* + * Copyright (c) 2015 David Gwynne + * + * 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 _NET_IFQ_H_ +#define _NET_IFQ_H_ + +struct ifnet; +struct kstat; + +struct ifq_ops; + +struct ifqueue { + struct ifnet *ifq_if; + struct taskq *ifq_softnet; + union { + void *_ifq_softc; + /* + * a rings sndq is found by looking up an array of pointers. + * by default we only have one sndq and the default drivers + * dont use ifq_softc, so we can borrow it for the map until + * we need to allocate a proper map. + */ + struct ifqueue *_ifq_ifqs[1]; + } _ifq_ptr; +#define ifq_softc _ifq_ptr._ifq_softc +#define ifq_ifqs _ifq_ptr._ifq_ifqs + + /* mbuf handling */ + struct mutex ifq_mtx; + const struct ifq_ops *ifq_ops; + void *ifq_q; + struct mbuf_list ifq_free; + unsigned int ifq_len; + unsigned int ifq_oactive; + + /* statistics */ + uint64_t ifq_packets; + uint64_t ifq_bytes; + uint64_t ifq_qdrops; + uint64_t ifq_errors; + uint64_t ifq_mcasts; + uint32_t ifq_oactives; + + struct kstat *ifq_kstat; + + /* work serialisation */ + struct mutex ifq_task_mtx; + struct task_list ifq_task_list; + void *ifq_serializer; + struct task ifq_bundle; + + /* work to be serialised */ + struct task ifq_start; + struct task ifq_restart; + + /* properties */ + unsigned int ifq_maxlen; + unsigned int ifq_idx; +}; + +struct ifiqueue { + struct ifnet *ifiq_if; + caddr_t *ifiq_bpfp; + struct taskq *ifiq_softnet; + union { + void *_ifiq_softc; + struct ifiqueue *_ifiq_ifiqs[1]; + } _ifiq_ptr; +#define ifiq_softc _ifiq_ptr._ifiq_softc +#define ifiq_ifiqs _ifiq_ptr._ifiq_ifiqs + + struct mutex ifiq_mtx; + struct mbuf_list ifiq_ml; + struct task ifiq_task; + unsigned int ifiq_pressure; + + /* counters */ + uint64_t ifiq_packets; + uint64_t ifiq_bytes; + uint64_t ifiq_fdrops; + uint64_t ifiq_qdrops; + uint64_t ifiq_errors; + uint64_t ifiq_mcasts; + uint64_t ifiq_noproto; + + /* number of times a list of packets were put on ifiq_ml */ + uint64_t ifiq_enqueues; + /* number of times a list of packets were pulled off ifiq_ml */ + uint64_t ifiq_dequeues; + + struct kstat *ifiq_kstat; + + /* properties */ + unsigned int ifiq_idx; +}; + +#ifdef _KERNEL + +#define IFQ_MAXLEN 256 + +/* + * + * Interface Send Queues + * + * struct ifqueue sits between the network stack and a drivers + * transmission of packets. The high level view is that when the stack + * has finished generating a packet it hands it to a driver for + * transmission. It does this by queueing the packet on an ifqueue and + * notifying the driver to start transmission of the queued packets. + * + * A network device may have multiple contexts for the transmission + * of packets, ie, independent transmit rings. Such a network device, + * represented by a struct ifnet, would then have multiple ifqueue + * structures, each of which maps to an independent transmit ring. + * + * struct ifqueue also provides the point where conditioning of + * traffic (ie, priq and hfsc) is implemented, and provides some + * infrastructure to assist in the implementation of network drivers. + * + * = ifq API + * + * The ifq API provides functions for three distinct consumers: + * + * 1. The network stack + * 2. Traffic QoS/conditioning implementations + * 3. Network drivers + * + * == Network Stack API + * + * The network stack is responsible for initialising and destroying + * the ifqueue structures, changing the traffic conditioner on an + * interface, enqueuing packets for transmission, and notifying + * the driver to start transmission of a particular ifqueue. + * + * === ifq_init() + * + * During if_attach(), the network stack calls ifq_init to initialise + * the ifqueue structure. By default it configures the priq traffic + * conditioner. + * + * === ifq_destroy() + * + * The network stack calls ifq_destroy() during if_detach to tear down + * the ifqueue structure. It frees the traffic conditioner state, and + * frees any mbufs that were left queued. + * + * === ifq_attach() + * + * ifq_attach() is used to replace the current traffic conditioner on + * the ifqueue. All the pending mbufs are removed from the previous + * conditioner and requeued on the new. + * + * === ifq_idx() + * + * ifq_idx() selects a specific ifqueue from the current ifnet + * structure for use in the transmission of the mbuf. + * + * === ifq_enqueue() + * + * ifq_enqueue() attempts to fit an mbuf onto the ifqueue. The + * current traffic conditioner may drop a packet to make space on the + * queue. + * + * === ifq_start() + * + * Once a packet has been successfully queued with ifq_enqueue(), + * the network card is notified with a call to ifq_start(). + * Calls to ifq_start() run in the ifqueue serialisation context, + * guaranteeing that only one instance of ifp->if_qstart() will be + * running on behalf of a specific ifqueue in the system at any point + * in time. + * + * == Traffic conditioners API + * + * The majority of interaction between struct ifqueue and a traffic + * conditioner occurs via the callbacks a traffic conditioner provides + * in an instance of struct ifq_ops. + * + * XXX document ifqop_* + * + * The ifqueue API implements the locking on behalf of the conditioning + * implementations so conditioners only have to reject or keep mbufs. + * If something needs to inspect a conditioners internals, the queue lock + * needs to be taken to allow for a consistent or safe view. The queue + * lock may be taken and released with ifq_q_enter() and ifq_q_leave(). + * + * === ifq_q_enter() + * + * Code wishing to access a conditioners internals may take the queue + * lock with ifq_q_enter(). The caller must pass a reference to the + * conditioners ifq_ops structure so the infrastructure can ensure the + * caller is able to understand the internals. ifq_q_enter() returns + * a pointer to the conditioners internal structures, or NULL if the + * ifq_ops did not match the current conditioner. + * + * === ifq_q_leave() + * + * The queue lock acquired with ifq_q_enter() is released with + * ifq_q_leave(). + * + * === ifq_mfreem() and ifq_mfreeml() + * + * A goal of the API is to avoid freeing an mbuf while mutexes are + * held. Because the ifq API manages the lock on behalf of the backend + * ifqops, the backend should not directly free mbufs. If a conditioner + * backend needs to drop a packet during the handling of ifqop_deq_begin, + * it may free it by calling ifq_mfreem(). This accounts for the drop, + * and schedules the free of the mbuf outside the hold of ifq_mtx. + * ifq_mfreeml() takes an mbuf list as an argument instead. + * + * + * == Network Driver API + * + * The API used by network drivers is mostly documented in the + * ifq_dequeue(9) manpage except for ifq_serialize(). + * + * === ifq_serialize() + * + * A driver may run arbitrary work in the ifqueue serialiser context + * via ifq_serialize(). The work to be done is represented by a task + * that has been prepared with task_set. + * + * The work will be run in series with any other work dispatched by + * ifq_start(), ifq_restart(), or other ifq_serialize() calls. + * + * Because the work may be run on another CPU, the lifetime of the + * task and the work it represents can extend beyond the end of the + * call to ifq_serialize() that dispatched it. + * + * + * = ifqueue work serialisation + * + * ifqueues provide a mechanism to dispatch work to be run in a single + * context. Work in this mechanism is represented by task structures. + * + * The tasks are run in a context similar to a taskq serviced by a + * single kernel thread, except the work is run immediately by the + * first CPU that dispatches work. If a second CPU attempts to dispatch + * additional tasks while the first is still running, it will be queued + * to be run by the first CPU. The second CPU will return immediately. + * + * = MP Safe Network Drivers + * + * An MP safe network driver is one in which its start routine can be + * called by the network stack without holding the big kernel lock. + * + * == Attach + * + * A driver advertises its ability to run its start routine without + * the kernel lock by setting the IFXF_MPSAFE flag in ifp->if_xflags + * before calling if_attach(). Advertising an MPSAFE start routine + * also implies that the driver understands that a network card can + * have multiple rings or transmit queues, and therefore provides + * if_qstart function (which takes an ifqueue pointer) instead of an + * if_start function (which takes an ifnet pointer). + * + * If the hardware supports multiple transmit rings, it advertises + * support for multiple rings to the network stack with if_attach_queues() + * after the call to if_attach(). if_attach_queues allocates a struct + * ifqueue for each hardware ring, which can then be initialised by + * the driver with data for each ring. + * + * void drv_start(struct ifqueue *); + * + * void + * drv_attach() + * { + * ... + * ifp->if_xflags = IFXF_MPSAFE; + * ifp->if_qstart = drv_start; + * if_attach(ifp); + * + * if_attach_queues(ifp, DRV_NUM_TX_RINGS); + * for (i = 0; i < DRV_NUM_TX_RINGS; i++) { + * struct ifqueue *ifq = ifp->if_ifqs[i]; + * struct drv_tx_ring *ring = &sc->sc_tx_rings[i]; + * + * ifq->ifq_softc = ring; + * ring->ifq = ifq; + * } + * } + * + * The network stack will then call ifp->if_qstart via ifq_start() + * to guarantee there is only one instance of that function running + * for each ifq in the system, and to serialise it with other work + * the driver may provide. + * + * == Initialise + * + * When the stack requests an interface be brought up (ie, drv_ioctl() + * is called to handle SIOCSIFFLAGS with IFF_UP set in ifp->if_flags) + * drivers should set IFF_RUNNING in ifp->if_flags, and then call + * ifq_clr_oactive() against each ifq. + * + * == if_start + * + * ifq_start() checks that IFF_RUNNING is set in ifp->if_flags, that + * ifq_is_oactive() does not return true, and that there are pending + * packets to transmit via a call to ifq_len(). Therefore, drivers are + * no longer responsible for doing this themselves. + * + * If a driver should not transmit packets while its link is down, use + * ifq_purge() to flush pending packets from the transmit queue. + * + * Drivers for hardware should use the following pattern to transmit + * packets: + * + * void + * drv_start(struct ifqueue *ifq) + * { + * struct drv_tx_ring *ring = ifq->ifq_softc; + * struct ifnet *ifp = ifq->ifq_if; + * struct drv_softc *sc = ifp->if_softc; + * struct mbuf *m; + * int kick = 0; + * + * if (NO_LINK) { + * ifq_purge(ifq); + * return; + * } + * + * for (;;) { + * if (NO_SPACE(ring)) { + * ifq_set_oactive(ifq); + * break; + * } + * + * m = ifq_dequeue(ifq); + * if (m == NULL) + * break; + * + * if (drv_encap(sc, ring, m) != 0) { // map and fill ring + * m_freem(m); + * continue; + * } + * + * bpf_mtap(); + * } + * + * drv_kick(ring); // notify hw of new descriptors on the ring + * } + * + * == Transmission completion + * + * The following pattern should be used for transmit queue interrupt + * processing: + * + * void + * drv_txeof(struct drv_tx_ring *ring) + * { + * struct ifqueue *ifq = ring->ifq; + * + * while (COMPLETED_PKTS(ring)) { + * // unmap packets, m_freem() the mbufs. + * } + * + * if (ifq_is_oactive(ifq)) + * ifq_restart(ifq); + * } + * + * == Stop + * + * Bringing an interface down (ie, IFF_UP was cleared in ifp->if_flags) + * should clear IFF_RUNNING in ifp->if_flags, and guarantee the start + * routine is not running before freeing any resources it uses: + * + * void + * drv_down(struct drv_softc *sc) + * { + * struct ifnet *ifp = &sc->sc_if; + * struct ifqueue *ifq; + * int i; + * + * CLR(ifp->if_flags, IFF_RUNNING); + * DISABLE_INTERRUPTS(); + * + * for (i = 0; i < sc->sc_num_queues; i++) { + * ifq = ifp->if_ifqs[i]; + * ifq_barrier(ifq); + * } + * + * intr_barrier(sc->sc_ih); + * + * FREE_RESOURCES(); + * + * for (i = 0; i < sc->sc_num_queues; i++) { + * ifq = ifp->if_ifqs[i]; + * ifq_clr_oactive(ifq); + * } + * } + * + */ + +struct ifq_ops { + unsigned int (*ifqop_idx)(unsigned int, + const struct mbuf *); + struct mbuf *(*ifqop_enq)(struct ifqueue *, struct mbuf *); + struct mbuf *(*ifqop_deq_begin)(struct ifqueue *, void **); + void (*ifqop_deq_commit)(struct ifqueue *, + struct mbuf *, void *); + void (*ifqop_purge)(struct ifqueue *, + struct mbuf_list *); + void *(*ifqop_alloc)(unsigned int, void *); + void (*ifqop_free)(unsigned int, void *); +}; + +extern const struct ifq_ops * const ifq_priq_ops; + +/* + * Interface send queues. + */ + +void ifq_init(struct ifqueue *, struct ifnet *, unsigned int); +void ifq_attach(struct ifqueue *, const struct ifq_ops *, void *); +void ifq_destroy(struct ifqueue *); +void ifq_add_data(struct ifqueue *, struct if_data *); +int ifq_enqueue(struct ifqueue *, struct mbuf *); +void ifq_start(struct ifqueue *); +struct mbuf *ifq_deq_begin(struct ifqueue *); +void ifq_deq_commit(struct ifqueue *, struct mbuf *); +void ifq_deq_rollback(struct ifqueue *, struct mbuf *); +struct mbuf *ifq_dequeue(struct ifqueue *); +int ifq_hdatalen(struct ifqueue *); +void ifq_init_maxlen(struct ifqueue *, unsigned int); +void ifq_mfreem(struct ifqueue *, struct mbuf *); +void ifq_mfreeml(struct ifqueue *, struct mbuf_list *); +unsigned int ifq_purge(struct ifqueue *); +void *ifq_q_enter(struct ifqueue *, const struct ifq_ops *); +void ifq_q_leave(struct ifqueue *, void *); +void ifq_serialize(struct ifqueue *, struct task *); +void ifq_barrier(struct ifqueue *); +void ifq_set_oactive(struct ifqueue *); +void ifq_deq_set_oactive(struct ifqueue *); + +int ifq_deq_sleep(struct ifqueue *, struct mbuf **, int, int, + const char *, volatile unsigned int *, + volatile unsigned int *); + +#define ifq_len(_ifq) READ_ONCE((_ifq)->ifq_len) +#define ifq_empty(_ifq) (ifq_len(_ifq) == 0) + +static inline int +ifq_is_priq(struct ifqueue *ifq) +{ + return (ifq->ifq_ops == ifq_priq_ops); +} + +static inline void +ifq_clr_oactive(struct ifqueue *ifq) +{ + ifq->ifq_oactive = 0; +} + +static inline unsigned int +ifq_is_oactive(struct ifqueue *ifq) +{ + return (ifq->ifq_oactive); +} + +static inline void +ifq_restart(struct ifqueue *ifq) +{ + ifq_serialize(ifq, &ifq->ifq_restart); +} + +static inline unsigned int +ifq_idx(struct ifqueue *ifq, unsigned int nifqs, const struct mbuf *m) +{ + return ((*ifq->ifq_ops->ifqop_idx)(nifqs, m)); +} + +/* ifiq */ + +void ifiq_init(struct ifiqueue *, struct ifnet *, unsigned int); +void ifiq_destroy(struct ifiqueue *); +int ifiq_input(struct ifiqueue *, struct mbuf_list *); +int ifiq_enqueue_qlim(struct ifiqueue *, struct mbuf *, + unsigned int); +void ifiq_add_data(struct ifiqueue *, struct if_data *); + +#define ifiq_len(_ifiq) READ_ONCE(ml_len(&(_ifiq)->ifiq_ml)) +#define ifiq_empty(_ifiq) (ifiq_len(_ifiq) == 0) + +static inline int +ifiq_enqueue(struct ifiqueue *ifiq, struct mbuf *m) +{ + return ifiq_enqueue_qlim(ifiq, m, 0); +} + +#endif /* _KERNEL */ + +#endif /* _NET_IFQ_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/lldp.h b/lib/libc/include/generic-openbsd/net/lldp.h new file mode 100644 index 0000000000..ef3085391d --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/lldp.h @@ -0,0 +1,67 @@ +/* $OpenBSD: lldp.h,v 1.1 2025/05/02 05:57:02 dlg Exp $ */ + +/* + * Copyright (c) 2025 David Gwynne + * + * 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 _NET_LLDP_H_ +#define _NET_LLDP_H_ + +#define LLDP_TLV_END 0 +#define LLDP_TLV_CHASSIS_ID 1 +#define LLDP_TLV_PORT_ID 2 +#define LLDP_TLV_TTL 3 +#define LLDP_TLV_PORT_DESCR 4 +#define LLDP_TLV_SYSTEM_NAME 5 +#define LLDP_TLV_SYSTEM_DESCR 6 +#define LLDP_TLV_SYSTEM_CAP 7 +#define LLDP_TLV_MANAGEMENT_ADDR 8 +#define LLDP_TLV_ORG 127 + +/* + * Chassis ID subtype enumeration + */ +#define LLDP_CHASSIS_ID_CHASSIS 1 /* Chassis component */ +#define LLDP_CHASSIS_ID_IFALIAS 2 /* Interface alias */ +#define LLDP_CHASSIS_ID_PORT 3 /* Port component */ +#define LLDP_CHASSIS_ID_MACADDR 4 /* MAC address */ +#define LLDP_CHASSIS_ID_ADDR 5 /* Network address */ +#define LLDP_CHASSIS_ID_IFNAME 6 /* Interface name */ +#define LLDP_CHASSIS_ID_LOCAL 7 /* Locally assigned */ + +/* + * Port ID subtype enumeration + */ +#define LLDP_PORT_ID_IFALIAS 1 /* Interface alias */ +#define LLDP_PORT_ID_PORT 2 /* Port component */ +#define LLDP_PORT_ID_MACADDR 3 /* MAC address */ +#define LLDP_PORT_ID_ADDR 4 /* Network address */ +#define LLDP_PORT_ID_IFNAME 5 /* Interface name */ +#define LLDP_PORT_ID_AGENTCID 6 /* Agent circuit ID */ +#define LLDP_PORT_ID_LOCAL 7 /* Locally assigned */ + +/* + * System Capabilities bits + */ +#define LLDP_SYSTEM_CAP_OTHER (1 << 0) +#define LLDP_SYSTEM_CAP_REPEATER (1 << 1) +#define LLDP_SYSTEM_CAP_BRIDGE (1 << 2) +#define LLDP_SYSTEM_CAP_WLAN (1 << 3) +#define LLDP_SYSTEM_CAP_ROUTER (1 << 4) +#define LLDP_SYSTEM_CAP_TELEPHONE (1 << 5) +#define LLDP_SYSTEM_CAP_DOCSIS (1 << 6) +#define LLDP_SYSTEM_CAP_STATION (1 << 7) + +#endif /* _NET_LLDP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/netisr.h b/lib/libc/include/generic-openbsd/net/netisr.h new file mode 100644 index 0000000000..1e515d8b55 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/netisr.h @@ -0,0 +1,78 @@ +/* $OpenBSD: netisr.h,v 1.61 2023/07/06 04:55:05 dlg Exp $ */ +/* $NetBSD: netisr.h,v 1.12 1995/08/12 23:59:24 mycroft Exp $ */ + +/* + * Copyright (c) 1980, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)netisr.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NET_NETISR_H_ +#define _NET_NETISR_H_ + +/* + * Each ``pup-level-1'' input queue has a bit in a ``netisr'' status + * word which is used to de-multiplex a single software + * interrupt used for scheduling the network code to calls + * on the lowest level routine of each protocol. + */ +#define NETISR_IP 2 /* same as AF_INET */ +#define NETISR_ARP 18 /* same as AF_LINK */ +#define NETISR_IPV6 24 /* same as AF_INET6 */ +#define NETISR_PIPEX 27 /* for pipex processing */ +#define NETISR_PPP 28 /* for PPP processing */ +#define NETISR_BRIDGE 29 /* for bridge processing */ +#define NETISR_PPPOE 30 /* for pppoe processing */ + +#ifndef _LOCORE +#ifdef _KERNEL + +#include +#include + +extern int netisr; /* scheduling bits for network */ +extern struct task if_input_task_locked; + +void arpintr(void); +void ipintr(void); +void ip6intr(void); +void pppintr(void); +void bridgeintr(void); +void pipexintr(void); +void pppoeintr(void); + +#define schednetisr(anisr) \ +do { \ + atomic_setbits_int(&netisr, (1 << (anisr))); \ + task_add(net_tq(0), &if_input_task_locked); \ +} while (/* CONSTCOND */0) + +#endif /* _KERNEL */ +#endif /*_LOCORE */ + +#endif /* _NET_NETISR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/ofp.h b/lib/libc/include/generic-openbsd/net/ofp.h new file mode 100644 index 0000000000..4ba0e60176 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/ofp.h @@ -0,0 +1,897 @@ +/* $OpenBSD: ofp.h,v 1.15 2023/04/11 00:45:09 jsg Exp $ */ + +/* + * Copyright (c) 2013-2016 Reyk Floeter + * Copyright (c) 2016 Kazuya GODA + * + * 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 _NET_OFP_H_ +#define _NET_OFP_H_ + +#include +#include + +#include +#include +#include + +#define OFP_IFNAMSIZ 16 /* on-wire (not IF_NAMSIZE) */ +#define OFP_ALIGNMENT 8 /* OFP alignment */ +#define OFP_ALIGN(_x) (((_x) + (OFP_ALIGNMENT - 1)) & ~(OFP_ALIGNMENT - 1)) + +struct ofp_header { + uint8_t oh_version; /* OpenFlow version */ + uint8_t oh_type; /* message type */ + uint16_t oh_length; /* message length */ + uint32_t oh_xid; /* transaction Id */ +} __packed; + +/* OpenFlow version */ +#define OFP_V_0 0x00 /* OpenFlow 0.0 */ +#define OFP_V_1_0 0x01 /* OpenFlow 1.0 */ +#define OFP_V_1_1 0x02 /* OpenFlow 1.1 */ +#define OFP_V_1_2 0x03 /* OpenFlow 1.2 */ +#define OFP_V_1_3 0x04 /* OpenFlow 1.3 */ +#define OFP_V_1_4 0x05 /* OpenFlow 1.4 */ +#define OFP_V_1_5 0x06 /* OpenFlow 1.5 */ + +/* OpenFlow message type */ +#define OFP_T_HELLO 0 /* Hello */ +#define OFP_T_ERROR 1 /* Error */ +#define OFP_T_ECHO_REQUEST 2 /* Echo Request */ +#define OFP_T_ECHO_REPLY 3 /* Echo Reply */ +#define OFP_T_EXPERIMENTER 4 /* Vendor/Experimenter */ +#define OFP_T_FEATURES_REQUEST 5 /* Features Request (switch) */ +#define OFP_T_FEATURES_REPLY 6 /* Features Reply (switch) */ +#define OFP_T_GET_CONFIG_REQUEST 7 /* Get Config Request (switch) */ +#define OFP_T_GET_CONFIG_REPLY 8 /* Get Config Reply (switch) */ +#define OFP_T_SET_CONFIG 9 /* Set Config (switch) */ +#define OFP_T_PACKET_IN 10 /* Packet In (async) */ +#define OFP_T_FLOW_REMOVED 11 /* Flow Removed (async) */ +#define OFP_T_PORT_STATUS 12 /* Port Status (async) */ +#define OFP_T_PACKET_OUT 13 /* Packet Out (controller) */ +#define OFP_T_FLOW_MOD 14 /* Flow Mod (controller) */ +#define OFP_T_GROUP_MOD 15 /* Group Mod (controller) */ +#define OFP_T_PORT_MOD 16 /* Port Mod (controller) */ +#define OFP_T_TABLE_MOD 17 /* Table Mod (controller) */ +#define OFP_T_MULTIPART_REQUEST 18 /* Multipart Message Request */ +#define OFP_T_MULTIPART_REPLY 19 /* Multipart Message Request */ +#define OFP_T_BARRIER_REQUEST 20 /* Barrier Request */ +#define OFP_T_BARRIER_REPLY 21 /* Barrier Reply */ +#define OFP_T_QUEUE_GET_CONFIG_REQUEST 22 /* Queue Get Config Request */ +#define OFP_T_QUEUE_GET_CONFIG_REPLY 23 /* Queue Get Config Reply */ +#define OFP_T_ROLE_REQUEST 24 /* Role Request */ +#define OFP_T_ROLE_REPLY 25 /* Role Reply */ +#define OFP_T_GET_ASYNC_REQUEST 26 /* Get Async Request */ +#define OFP_T_GET_ASYNC_REPLY 27 /* Get Async Reply */ +#define OFP_T_SET_ASYNC 28 /* Set Async */ +#define OFP_T_METER_MOD 29 /* Meter Mod */ +#define OFP_T_TYPE_MAX 30 + +/* OpenFlow Hello Message */ +struct ofp_hello_element_header { + uint16_t he_type; + uint16_t he_length; +} __packed; + +#define OFP_HELLO_T_VERSION_BITMAP 1 /* Supported version bitmap */ + +struct ofp_hello_element_versionbitmap { + uint16_t hev_type; + uint16_t hev_length; +} __packed; + +/* Ports */ +#define OFP_PORT_MAX 0xffffff00 /* Maximum number of physical ports */ +#define OFP_PORT_INPUT 0xfffffff8 /* Send back to input port */ +#define OFP_PORT_FLOWTABLE 0xfffffff9 /* Perform actions in flow table */ +#define OFP_PORT_NORMAL 0xfffffffa /* Let switch decide */ +#define OFP_PORT_FLOOD 0xfffffffb /* All non-block ports except input */ +#define OFP_PORT_ALL 0xfffffffc /* All ports except input */ +#define OFP_PORT_CONTROLLER 0xfffffffd /* Send to controller */ +#define OFP_PORT_LOCAL 0xfffffffe /* Local virtual OpenFlow port */ +#define OFP_PORT_ANY 0xffffffff /* No port */ + +/* Switch Config Message (reply) */ +struct ofp_switch_config { + struct ofp_header cfg_oh; /* OpenFlow header */ + uint16_t cfg_flags; /* Configuration flags */ + uint16_t cfg_miss_send_len; /* Max bytes from datapath */ +} __packed; + +/* Switch Config */ +#define OFP_CONFIG_FRAG_NORMAL 0x0000 /* No special frag handling */ +#define OFP_CONFIG_FRAG_DROP 0x0001 /* Drop fragments */ +#define OFP_CONFIG_FRAG_REASM 0x0002 /* Reassemble fragments */ +#define OFP_CONFIG_FRAG_MASK 0x0003 /* Fragment mask */ + +/* Switch port description */ +struct ofp_switch_port { + uint32_t swp_number; /* Switch port number */ + uint8_t swp_pad[4]; /* Padding */ + uint8_t swp_macaddr[ETHER_ADDR_LEN]; /* Port MAC address */ + uint8_t swp_pad2[2]; /* Padding */ + char swp_name[OFP_IFNAMSIZ]; /* Switch port name */ + uint32_t swp_config; /* Configuration flags */ + uint32_t swp_state; /* State flags */ + uint32_t swp_cur; /* Current features */ + uint32_t swp_advertised; /* Advertised by the port */ + uint32_t swp_supported; /* Supported by the port */ + uint32_t swp_peer; /* Advertised by peer */ + uint32_t swp_cur_speed; /* Current port speed in Kbps*/ + uint32_t swp_max_speed; /* Support port max speed in Kbps*/ +} __packed; + +/* Physical port configuration */ +#define OFP_PORTCONFIG_PORT_DOWN 0x1 /* Port is down */ +#define OFP_PORTCONFIG_NO_STP 0x2 /* Disable STP on port */ +#define OFP_PORTCONFIG_NO_RECV 0x4 /* Drop everything except STP */ +#define OFP_PORTCONFIG_NO_RECV_STP 0x8 /* Drop received STP */ +#define OFP_PORTCONFIG_NO_FLOOD 0x10 /* Do not flood to this port */ +#define OFP_PORTCONFIG_NO_FWD 0x20 /* Drop packets to port */ +#define OFP_PORTCONFIG_NO_PACKET_IN 0x40 /* NO PACKET_IN on port */ + +/* Physical port state */ +#define OFP_PORTSTATE_LINK_DOWN 0x1 /* Link not active */ +#define OFP_PORTSTATE_STP_LISTEN 0x000 /* Not learning or forwarding */ +#define OFP_PORTSTATE_STP_LEARN 0x100 /* Learning but not forwarding */ +#define OFP_PORTSTATE_STP_FORWARD 0x200 /* Learning and forwarding */ +#define OFP_PORTSTATE_STP_BLOCK 0x300 /* Not part of spanning tree */ +#define OFP_PORTSTATE_STP_MASK 0x300 /* Spanning tree values */ + +/* Physical port media types */ +#define OFP_PORTMEDIA_10MB_HD 0x1 /* 10 Mb half-duplex */ +#define OFP_PORTMEDIA_10MB_FD 0x2 /* 10 Mb full-duplex */ +#define OFP_PORTMEDIA_100MB_HD 0x4 /* 100 Mb half-duplex */ +#define OFP_PORTMEDIA_100MB_FD 0x8 /* 100 Mb full-duplex */ +#define OFP_PORTMEDIA_1GB_HD 0x10 /* 1 Gb half-duplex */ +#define OFP_PORTMEDIA_1GB_FD 0x20 /* 1 Gb full-duplex */ +#define OFP_PORTMEDIA_10GB_FD 0x40 /* 10 Gb full-duplex */ +#define OFP_PORTMEDIA_COPPER 0x80 /* Copper */ +#define OFP_PORTMEDIA_FIBER 0x100 /* Fiber */ +#define OFP_PORTMEDIA_AUTONEG 0x200 /* Auto-negotiation */ +#define OFP_PORTMEDIA_PAUSE 0x400 /* Pause */ +#define OFP_PORTMEDIA_PAUSE_ASYM 0x800 /* Asymmetric pause */ + +/* Switch Features Message (reply) */ +struct ofp_switch_features { + struct ofp_header swf_oh; /* OpenFlow header */ + uint64_t swf_datapath_id; /* Datapath unique ID */ + uint32_t swf_nbuffers; /* Max packets buffered */ + uint8_t swf_ntables; /* Number of supported tables */ + uint8_t swf_aux_id; /* Identify auxiliary connections */ + uint8_t swf_pad[2]; /* Align to 64 bits */ + uint32_t swf_capabilities; /* Capability flags */ + uint32_t swf_actions; /* Supported action flags */ +} __packed; + +/* Switch capabilities */ +#define OFP_SWCAP_FLOW_STATS 0x1 /* Flow statistics */ +#define OFP_SWCAP_TABLE_STATS 0x2 /* Table statistics */ +#define OFP_SWCAP_PORT_STATS 0x4 /* Port statistics */ +#define OFP_SWCAP_GROUP_STATS 0x8 /* Group statistics */ +#define OFP_SWCAP_IP_REASM 0x20 /* Can reassemble IP frags */ +#define OFP_SWCAP_QUEUE_STATS 0x40 /* Queue statistics */ +#define OFP_SWCAP_ARP_MATCH_IP 0x80 /* Match IP addresses in ARP pkts */ +#define OFP_SWCAP_PORT_BLOCKED 0x100 /* Switch will block ports */ + +/* Flow matching */ +struct ofp_match { + uint16_t om_type; + uint16_t om_length; +} __packed; + +/* Flow matching type */ +#define OFP_MATCH_STANDARD 0 /* Standard match deprecated */ +#define OFP_MATCH_OXM 1 /* OpenFlow Extensible Match */ + +/* Packet-In Message */ +struct ofp_packet_in { + struct ofp_header pin_oh; /* OpenFlow header */ + uint32_t pin_buffer_id; + uint16_t pin_total_len; + uint8_t pin_reason; + uint8_t pin_table_id; + uint64_t pin_cookie; + struct ofp_match pin_match; +} __packed; + +/* Reason */ +#define OFP_PKTIN_REASON_NO_MATCH 0 /* No matching flow */ +#define OFP_PKTIN_REASON_ACTION 1 /* Explicit output */ +#define OFP_PKTIN_REASON_TTL 2 /* Packet has invalid TTL */ + +/* Flow Instruction */ +struct ofp_instruction { + uint16_t i_type; + uint16_t i_len; +} __packed; + +/* Instruction types */ +#define OFP_INSTRUCTION_T_GOTO_TABLE 1 /* Goto-Table */ +#define OFP_INSTRUCTION_T_WRITE_META 2 /* Write-Metadata */ +#define OFP_INSTRUCTION_T_WRITE_ACTIONS 3 /* Write-Actions */ +#define OFP_INSTRUCTION_T_APPLY_ACTIONS 4 /* Apply-Actions */ +#define OFP_INSTRUCTION_T_CLEAR_ACTIONS 5 /* Clear-Actions */ +#define OFP_INSTRUCTION_T_METER 6 /* Meter */ +#define OFP_INSTRUCTION_T_EXPERIMENTER 0xffff /* Experimenter */ + +/* Write-Metadata instruction */ +struct ofp_instruction_write_metadata { + uint16_t iwm_type; + uint16_t iwm_len; + uint8_t iwm_pad[4]; + uint64_t iwm_metadata; + uint64_t iwm_metadata_mask; +} __packed; + +/* Goto-Table instruction */ +struct ofp_instruction_goto_table { + uint16_t igt_type; + uint16_t igt_len; + uint8_t igt_table_id; + uint8_t igt_pad[3]; +} __packed; + +/* Apply-Actions instruction */ +struct ofp_instruction_actions { + uint16_t ia_type; + uint16_t ia_len; + uint8_t ia_pad[4]; +} __packed; + +/* Meter instruction */ +struct ofp_instruction_meter { + uint16_t im_type; + uint16_t im_len; + uint32_t im_meter_id; +} __packed; + +/* Experimenter instruction */ +struct ofp_instruction_experimenter { + uint16_t ie_type; + uint16_t ie_len; + uint32_t ie_experimenter; +} __packed; + +/* Actions */ +#define OFP_ACTION_OUTPUT 0 /* Output to switch port */ +#define OFP_ACTION_COPY_TTL_OUT 11 /* Copy TTL outwards */ +#define OFP_ACTION_COPY_TTL_IN 12 /* Copy TTL inwards */ +#define OFP_ACTION_SET_MPLS_TTL 15 /* MPLS TTL */ +#define OFP_ACTION_DEC_MPLS_TTL 16 /* Decrement MPLS TTL */ +#define OFP_ACTION_PUSH_VLAN 17 /* Push a new VLAN tag */ +#define OFP_ACTION_POP_VLAN 18 /* Pop the outer VLAN tag */ +#define OFP_ACTION_PUSH_MPLS 19 /* Push a new MPLS tag */ +#define OFP_ACTION_POP_MPLS 20 /* Pop the outer MPLS tag */ +#define OFP_ACTION_SET_QUEUE 21 /* Set queue id when outputting to a port */ +#define OFP_ACTION_GROUP 22 /* Apply group */ +#define OFP_ACTION_SET_NW_TTL 23 /* Set IP TTL */ +#define OFP_ACTION_DEC_NW_TTL 24 /* Decrement IP TTL */ +#define OFP_ACTION_SET_FIELD 25 /* Set a header field using OXM TLV format */ +#define OFP_ACTION_PUSH_PBB 26 /* Push a new PBB service tag (I-TAG) */ +#define OFP_ACTION_POP_PBB 27 /* Pop the outer PBB service tag (I-TAG) */ +#define OFP_ACTION_EXPERIMENTER 0xffff /* Vendor-specific action */ + +/* Action Header */ +struct ofp_action_header { + uint16_t ah_type; + uint16_t ah_len; + uint32_t ah_pad; +} __packed; + +/* Output Action */ +struct ofp_action_output { + uint16_t ao_type; + uint16_t ao_len; + uint32_t ao_port; + uint16_t ao_max_len; + uint8_t ao_pad[6]; +} __packed; + +/* Buffer configuration */ +#define OFP_CONTROLLER_MAXLEN_MAX 0xffe5 /* maximum buffer length */ +#define OFP_CONTROLLER_MAXLEN_NO_BUFFER 0xffff /* don't do any buffering */ + +struct ofp_action_mpls_ttl { + uint16_t amt_type; + uint16_t amt_len; + uint8_t amt_ttl; + uint8_t amt_pad[3]; +} __packed; + +struct ofp_action_push { + uint16_t ap_type; + uint16_t ap_len; + uint16_t ap_ethertype; + uint8_t ap_pad[2]; +} __packed; + +struct ofp_action_pop_mpls { + uint16_t apm_type; + uint16_t apm_len; + uint16_t apm_ethertype; + uint8_t apm_pad[2]; +} __packed; + +struct ofp_action_group { + uint16_t ag_type; + uint16_t ag_len; + uint32_t ag_group_id; +} __packed; + +struct ofp_action_nw_ttl { + uint16_t ant_type; + uint16_t ant_len; + uint8_t ant_ttl; + uint8_t ant_pad[3]; +} __packed; + +struct ofp_action_set_field { + uint16_t asf_type; + uint16_t asf_len; + uint8_t asf_field[4]; +} __packed; + +struct ofp_action_set_queue { + uint16_t asq_type; + uint16_t asq_len; + uint32_t asq_queue_id; +} __packed; + +/* Packet-Out Message */ +struct ofp_packet_out { + struct ofp_header pout_oh; /* OpenFlow header */ + uint32_t pout_buffer_id; + uint32_t pout_in_port; + uint16_t pout_actions_len; + uint8_t pout_pad[6]; + struct ofp_action_header pout_actions[0]; + /* Followed by optional packet data if buffer_id == 0xffffffff */ +} __packed; + +/* Special buffer id */ +#define OFP_PKTOUT_NO_BUFFER 0xffffffff /* No buffer id */ + +/* Flow match fields for basic class */ +#define OFP_XM_T_IN_PORT 0 /* Switch input port */ +#define OFP_XM_T_IN_PHY_PORT 1 /* Switch physical input port */ +#define OFP_XM_T_META 2 /* Metadata passed between tables */ +#define OFP_XM_T_ETH_DST 3 /* Ethernet destination address */ +#define OFP_XM_T_ETH_SRC 4 /* Ethernet source address */ +#define OFP_XM_T_ETH_TYPE 5 /* Ethernet frame type */ +#define OFP_XM_T_VLAN_VID 6 /* VLAN id */ +#define OFP_XM_T_VLAN_PCP 7 /* VLAN priority */ +#define OFP_XM_T_IP_DSCP 8 /* IP DSCP (6 bits in ToS field) */ +#define OFP_XM_T_IP_ECN 9 /* IP ECN (2 bits in ToS field) */ +#define OFP_XM_T_IP_PROTO 10 /* IP protocol */ +#define OFP_XM_T_IPV4_SRC 11 /* IPv4 source address */ +#define OFP_XM_T_IPV4_DST 12 /* IPv4 destination address */ +#define OFP_XM_T_TCP_SRC 13 /* TCP source port */ +#define OFP_XM_T_TCP_DST 14 /* TCP destination port */ +#define OFP_XM_T_UDP_SRC 15 /* UDP source port */ +#define OFP_XM_T_UDP_DST 16 /* UDP destination port */ +#define OFP_XM_T_SCTP_SRC 17 /* SCTP source port */ +#define OFP_XM_T_SCTP_DST 18 /* SCTP destination port */ +#define OFP_XM_T_ICMPV4_TYPE 19 /* ICMP type */ +#define OFP_XM_T_ICMPV4_CODE 20 /* ICMP code */ +#define OFP_XM_T_ARP_OP 21 /* ARP opcode */ +#define OFP_XM_T_ARP_SPA 22 /* ARP source IPv4 address */ +#define OFP_XM_T_ARP_TPA 23 /* ARP target IPv4 address */ +#define OFP_XM_T_ARP_SHA 24 /* ARP source hardware address */ +#define OFP_XM_T_ARP_THA 25 /* ARP target hardware address */ +#define OFP_XM_T_IPV6_SRC 26 /* IPv6 source address */ +#define OFP_XM_T_IPV6_DST 27 /* IPv6 destination address */ +#define OFP_XM_T_IPV6_FLABEL 28 /* IPv6 Flow Label */ +#define OFP_XM_T_ICMPV6_TYPE 29 /* ICMPv6 type */ +#define OFP_XM_T_ICMPV6_CODE 30 /* ICMPv6 code */ +#define OFP_XM_T_IPV6_ND_TARGET 31 /* Target address for ND */ +#define OFP_XM_T_IPV6_ND_SLL 32 /* Source link-layer for ND */ +#define OFP_XM_T_IPV6_ND_TLL 33 /* Target link-layer for ND */ +#define OFP_XM_T_MPLS_LABEL 34 /* MPLS label */ +#define OFP_XM_T_MPLS_TC 35 /* MPLS TC */ +#define OFP_XM_T_MPLS_BOS 36 /* MPLS BoS bit */ +#define OFP_XM_T_PBB_ISID 37 /* PBB I-SID */ +#define OFP_XM_T_TUNNEL_ID 38 /* Logical Port Metadata */ +#define OFP_XM_T_IPV6_EXTHDR 39 /* IPv6 Extension Header pseudo-field */ +#define OFP_XM_T_MAX 40 + +/* Flow match fields for nxm1 class */ +#define OFP_XM_NXMT_TUNNEL_ID 38 /* Tunnel Logical Port Metadata */ +#define OFP_XM_NXMT_TUNNEL_IPV4_SRC 31 /* Tunnel IPv4 source address */ +#define OFP_XM_NXMT_TUNNEL_IPV4_DST 32 /* Tunnel IPv4 destination address */ +#define OFP_XM_NXMT_TUNNEL_IPV6_SRC 109 /* Tunnel IPv6 source address */ +#define OFP_XM_NXMT_TUNNEL_IPV6_DST 110 /* Tunnel IPv6 destination address */ + +/* OXM class */ +#define OFP_OXM_C_NXM_0 0x0000 /* NXM 0 */ +#define OFP_OXM_C_NXM_1 0x0001 /* NXM 1 */ +#define OFP_OXM_C_OPENFLOW_BASIC 0x8000 /* OpenFlow Basic */ +#define OFP_OXM_C_OPENFLOW_EXPERIMENTER 0xffff /* OpenFlow Experimenter */ + +/* VLAN matching flag */ +#define OFP_XM_VID_PRESENT 0x1000 /* VLAN ID present */ +#define OFP_XM_VID_NONE 0x0000 /* No VLAN ID */ + +/* IPv6 Extension header pseudo-field flags */ +#define OFP_XM_IPV6_EXTHDR_NONEXT 0x0001 /* "No next header" encountered */ +#define OFP_XM_IPV6_EXTHDR_ESP 0x0002 /* Encrypted Sec Payload header present */ +#define OFP_XM_IPV6_EXTHDR_AUTH 0x0004 /* Authentication header present. */ +#define OFP_XM_IPV6_EXTHDR_DEST 0x0008 /* 1 or 2 dest headers present. */ +#define OFP_XM_IPV6_EXTHDR_FRAG 0x0010 /* Fragment header present. */ +#define OFP_XM_IPV6_EXTHDR_ROUTER 0x0020 /* Router header present. */ +#define OFP_XM_IPV6_EXTHDR_HOP 0x0040 /* Hop-by-hop header present. */ +#define OFP_XM_IPV6_EXTHDR_UNREP 0x0080 /* Unexpected repeats encountered. */ +#define OFP_XM_IPV6_EXTHDR_UNSEQ 0x0100 /* Unexpected sequencing encountered. */ + +struct ofp_ox_match { + uint16_t oxm_class; + uint8_t oxm_fh; + uint8_t oxm_length; + uint8_t oxm_value[0]; +} __packed; + +#define OFP_OXM_GET_FIELD(o) (((o)->oxm_fh) >> 1) +#define OFP_OXM_GET_HASMASK(o) (((o)->oxm_fh) & 0x1) +#define OFP_OXM_SET_FIELD(o, t) (((o)->oxm_fh) = ((t) << 1)) +#define OFP_OXM_SET_HASMASK(o) (((o)->oxm_fh) |= 0x1) + +/* Flow modification commands */ +#define OFP_FLOWCMD_ADD 0 /* Add new flow */ +#define OFP_FLOWCMD_MODIFY 1 /* Modify flow */ +#define OFP_FLOWCMD_MODIFY_STRICT 2 /* Modify flow w/o wildcard */ +#define OFP_FLOWCMD_DELETE 3 /* Delete flow */ +#define OFP_FLOWCMD_DELETE_STRICT 4 /* Delete flow w/o wildcard */ + +/* Flow modification flags */ +#define OFP_FLOWFLAG_SEND_FLOW_REMOVED 0x0001 /* Send flow removed message */ +#define OFP_FLOWFLAG_CHECK_OVERLAP 0x0002 /* Check flow overlap first */ +#define OFP_FLOWFLAG_RESET_COUNTS 0x0004 /* Reset flow packet and byte counters */ +#define OFP_FLOWFLAG_NO_PACKET_COUNTS 0x0008 /* Don't keep track of packet count */ +#define OFP_FLOWFLAG_NO_BYTE_COUNTS 0x0010 /* Don't keep track of byte count */ + +/* Flow modification message */ +struct ofp_flow_mod { + struct ofp_header fm_oh; /* OpenFlow header */ + uint64_t fm_cookie; + uint64_t fm_cookie_mask; + uint8_t fm_table_id; + uint8_t fm_command; + uint16_t fm_idle_timeout; + uint16_t fm_hard_timeout; + uint16_t fm_priority; + uint32_t fm_buffer_id; + uint32_t fm_out_port; + uint32_t fm_out_group; + uint16_t fm_flags; + uint8_t fm_pad[2]; + struct ofp_match fm_match; +} __packed; + +/* Flow removed reasons */ +#define OFP_FLOWREM_REASON_IDLE_TIMEOUT 0 /* Flow idle time exceeded idle_timeout */ +#define OFP_FLOWREM_REASON_HARD_TIMEOUT 1 /* Time exceeded hard_timeout */ +#define OFP_FLOWREM_REASON_DELETE 2 /* Evicted by a DELETE flow mod */ +#define OFP_FLOWREM_REASON_GROUP_DELETE 3 /* Group was removed */ + +/* Flow removed message */ +struct ofp_flow_removed { + struct ofp_header fr_oh; + uint64_t fr_cookie; + uint16_t fr_priority; + uint8_t fr_reason; + uint8_t fr_table_id; + uint32_t fr_duration_sec; + uint32_t fr_duration_nsec; + uint16_t fr_idle_timeout; + uint16_t fr_hard_timeout; + uint64_t fr_packet_count; + uint64_t fr_byte_count; + struct ofp_match fr_match; +} __packed; + +/* Error message */ +struct ofp_error { + struct ofp_header err_oh; + uint16_t err_type; + uint16_t err_code; + uint8_t err_data[0]; + /* Followed by optional data */ +} __packed; +#define OFP_ERRDATA_MAX 64 + +/* Error types */ +#define OFP_ERRTYPE_HELLO_FAILED 0 /* Hello protocol failed */ +#define OFP_ERRTYPE_BAD_REQUEST 1 /* Request was not understood */ +#define OFP_ERRTYPE_BAD_ACTION 2 /* Error in action */ +#define OFP_ERRTYPE_BAD_INSTRUCTION 3 /* Error in instruction list */ +#define OFP_ERRTYPE_BAD_MATCH 4 /* Error in match */ +#define OFP_ERRTYPE_FLOW_MOD_FAILED 5 /* Problem modifying flow */ +#define OFP_ERRTYPE_GROUP_MOD_FAILED 6 /* Problem modifying group */ +#define OFP_ERRTYPE_PORT_MOD_FAILED 7 /* Port mod request failed */ +#define OFP_ERRTYPE_TABLE_MOD_FAILED 8 /* Port mod request failed */ +#define OFP_ERRTYPE_QUEUE_OP_FAILED 9 /* Queue operation failed */ +#define OFP_ERRTYPE_SWITCH_CFG_FAILED 10 /* Switch Config request failed */ +#define OFP_ERRTYPE_ROLE_REQUEST_FAILED 11 /* Controller role request failed */ +#define OFP_ERRTYPE_METER_MOD_FAILED 12 /* Error in meter */ +#define OFP_ERRTYPE_TABLE_FEATURES_FAILED 13 /* Setting table features failed */ +#define OFP_ERRTYPE_EXPERIMENTER 0xffff /* Experimenter error message */ + +/* HELLO error codes */ +#define OFP_ERRHELLO_INCOMPATIBLE 0 /* No compatible version */ +#define OFP_ERRHELLO_EPERM 1 /* Permissions error */ + +/* REQUEST error codes */ +#define OFP_ERRREQ_VERSION 0 /* Version not supported */ +#define OFP_ERRREQ_TYPE 1 /* Type not supported */ +#define OFP_ERRREQ_MULTIPART 2 /* Multipart type not supported */ +#define OFP_ERRREQ_EXPERIMENTER 3 /* Experimenter id not supported */ +#define OFP_ERRREQ_EXP_TYPE 4 /* Experimenter type not supported */ +#define OFP_ERRREQ_EPERM 5 /* Permission error */ +#define OFP_ERRREQ_BAD_LEN 6 /* Wrong request length for type */ +#define OFP_ERRREQ_BUFFER_EMPTY 7 /* Specified buffer has already been used */ +#define OFP_ERRREQ_BUFFER_UNKNOWN 8 /* Specified buffer does not exist */ +#define OFP_ERRREQ_TABLE_ID 9 /* Specified table-id invalid or does not exit */ +#define OFP_ERRREQ_IS_SLAVE 10 /* Denied because controller is slave */ +#define OFP_ERRREQ_PORT 11 /* Invalid port */ +#define OFP_ERRREQ_PACKET 12 /* Invalid packet in packet-out */ +#define OFP_ERRREQ_MULTIPART_OVERFLOW 13 /* Multipart overflowed the assigned buffer */ + +/* ACTION error codes */ +#define OFP_ERRACTION_TYPE 0 /* Unknown or unsupported action type */ +#define OFP_ERRACTION_LEN 1 /* Length problem in actions */ +#define OFP_ERRACTION_EXPERIMENTER 2 /* Unknown experimenter id specified */ +#define OFP_ERRACTION_EXP_TYPE 3 /* Unknown action for experimenter id */ +#define OFP_ERRACTION_OUT_PORT 4 /* Problem validating output port */ +#define OFP_ERRACTION_ARGUMENT 5 /* Bad action argument */ +#define OFP_ERRACTION_EPERM 6 /* Permission error */ +#define OFP_ERRACTION_TOO_MANY 7 /* Can't handle this many actions */ +#define OFP_ERRACTION_BAD_QUEUE 8 /* Problem validating output queue */ +#define OFP_ERRACTION_BAD_OUT_GROUP 9 /* Invalid group id in forward action */ +#define OFP_ERRACTION_MATCH_INCONSISTENT 10 /* Action can't apply or Set-Field failed */ +#define OFP_ERRACTION_UNSUPPORTED_ORDER 11 /* Action order is unsupported for Apply-Actions */ +#define OFP_ERRACTION_TAG 12 /* Actions uses an unsupported tag/encap */ +#define OFP_ERRACTION_SET_TYPE 13 /* Unsupported type in SET_FIELD action */ +#define OFP_ERRACTION_SET_LEN 14 /* Length problem in SET_FIELD action */ +#define OFP_ERRACTION_SET_ARGUMENT 15 /* Bad argument in SET_FIELD action */ + +/* INSTRUCTION error codes */ +#define OFP_ERRINST_UNKNOWN_INST 0 /* Unknown instruction */ +#define OFP_ERRINST_UNSUPPORTED_INST 1 /* Switch or table does not support */ +#define OFP_ERRINST_TABLE_ID 2 /* Invalid Table-ID specified */ +#define OFP_ERRINST_UNSUPP_META 3 /* Metadata value unsupported by datapath */ +#define OFP_ERRINST_UNSUPP_META_MASK 4 /* Metadata mask value unsupported by datapath */ +#define OFP_ERRINST_BAD_EXPERIMENTER 5 /* Unknown experimenter id specified */ +#define OFP_ERRINST_BAD_EXPERIMENTER_TYPE 6 /* Unknown instruction for experimenter id */ +#define OFP_ERRINST_BAD_LEN 7 /* Length problem in instructions */ +#define OFP_ERRINST_EPERM 8 /* Permissions error */ + +/* MATCH error codes */ +#define OFP_ERRMATCH_BAD_TYPE 0 /* Unsupported match type */ +#define OFP_ERRMATCH_BAD_LEN 1 /* Length problem in match */ +#define OFP_ERRMATCH_BAD_TAG 2 /* Match uses an unsupported tag/encap */ +#define OFP_ERRMATCH_BAD_DL_ADDR_MASK 3 /* Unsupported datalink addr mask */ +#define OFP_ERRMATCH_BAD_NW_ADDR_MASK 4 /* Unsupported network addr mask */ +#define OFP_ERRMATCH_BAD_WILDCARDS 5 /* Unsupported combination of fields */ +#define OFP_ERRMATCH_BAD_FIELD 6 /* Unsupported field type in the match */ +#define OFP_ERRMATCH_BAD_VALUE 7 /* Unsupported value in a match field */ +#define OFP_ERRMATCH_BAD_MASK 8 /* Unsupported mask specified in match */ +#define OFP_ERRMATCH_BAD_PREREQ 9 /* A prerequisite was not met */ +#define OFP_ERRMATCH_DUP_FIELD 10 /* A field type was duplicated */ +#define OFP_ERRMATCH_EPERM 11 /* Permissions error */ + +/* FLOW MOD error codes */ +#define OFP_ERRFLOWMOD_UNKNOWN 0 /* Unknown */ +#define OFP_ERRFLOWMOD_TABLE_FULL 1 /* Table is full */ +#define OFP_ERRFLOWMOD_TABLE_ID 2 /* Invalid table id */ +#define OFP_ERRFLOWMOD_OVERLAP 3 /* Overlapping flow */ +#define OFP_ERRFLOWMOD_EPERM 4 /* Permissions error */ +#define OFP_ERRFLOWMOD_BAD_TIMEOUT 5 /* non-zero idle/hard timeout */ +#define OFP_ERRFLOWMOD_BAD_COMMAND 6 /* Unsupported or Unknown command */ +#define OFP_ERRFLOWMOD_BAD_FLAGS 7 /* Unsupported or Unknown flags */ + +/* GROUP MOD error codes */ +#define OFP_ERRGROUPMOD_GROUP_EXISTS 0 /* Already present group */ +#define OFP_ERRGROUPMOD_INVALID_GROUP 1 /* Group specified is invalid */ +#define OFP_ERRGROUPMOD_WEIGHT_UNSUPP 2 /* Switch does not support unequal load sharing */ +#define OFP_ERRGROUPMOD_OUT_OF_GROUPS 3 /* The Group table is full */ +#define OFP_ERRGROUPMOD_OUT_OF_BUCKETS 4 /* The maximum number of action buckets */ +#define OFP_ERRGROUPMOD_CHAINING_UNSUPP 5 /* Switch does not support groups forwarding to groups */ +#define OFP_ERRGROUPMOD_WATCH_UNSUPP 6 /* This group cannot watch the watch_port */ +#define OFP_ERRGROUPMOD_LOOP 7 /* Group entry would cause a loop */ +#define OFP_ERRGROUPMOD_UNKNOWN_GROUP 8 /* MODIFY attempted to modify a non-existent group */ +#define OFP_ERRGROUPMOD_CHAINED_GROUP 9 /* Group not deleted because another group is forwarding to it */ +#define OFP_ERRGROUPMOD_BAD_TYPE 10 /* Unsupported or unknown group type */ +#define OFP_ERRGROUPMOD_BAD_COMMAND 11 /* Unsupported or unknown command */ +#define OFP_ERRGROUPMOD_BAD_BUCKET 12 /* Error in bucket */ +#define OFP_ERRGROUPMOD_BAD_WATCH 13 /* Error in watch port/group */ +#define OFP_ERRGROUPMOD_EPERM 14 /* Permission error */ + +/* GROUP MOD message */ +#define OFP_GROUPCMD_ADD 0 /* Add group */ +#define OFP_GROUPCMD_MODIFY 1 /* Modify group */ +#define OFP_GROUPCMD_DELETE 2 /* Delete group */ + +/* Group types */ +#define OFP_GROUP_T_ALL 0 /* All (multicast/broadcast) group */ +#define OFP_GROUP_T_SELECT 1 /* Select group */ +#define OFP_GROUP_T_INDIRECT 2 /* Indirect group */ +#define OFP_GROUP_T_FAST_FAILOVER 3 /* Fast failover group */ + +/* Special group identifiers */ +#define OFP_GROUP_ID_MAX 0xffffff00 /* Last usable group number */ +#define OFP_GROUP_ID_ALL 0xfffffffc /* Represents all groups for delete command */ +#define OFP_GROUP_ID_ANY 0xffffffff /* Special wildcard: no group specified */ + +struct ofp_bucket { + uint16_t b_len; + uint16_t b_weight; + uint32_t b_watch_port; + uint32_t b_watch_group; + uint8_t b_pad[4]; + struct ofp_action_header b_actions[0]; +} __packed; + +struct ofp_group_mod { + struct ofp_header gm_oh; + uint16_t gm_command; + uint8_t gm_type; + uint8_t gm_pad; + uint32_t gm_group_id; + struct ofp_bucket gm_buckets[0]; +} __packed; + +struct ofp_multipart { + struct ofp_header mp_oh; + uint16_t mp_type; + uint16_t mp_flags; + uint8_t mp_pad[4]; +} __packed; + +#define OFP_MP_FLAG_REQ_MORE 1 /* More requests to follow */ +#define OFP_MP_FLAG_REPLY_MORE 1 /* More replies to follow */ + +/* Multipart types */ +#define OFP_MP_T_DESC 0 /* Description of the switch */ +#define OFP_MP_T_FLOW 1 /* Individual flow statistics */ +#define OFP_MP_T_AGGREGATE 2 /* Aggregate flow statistics */ +#define OFP_MP_T_TABLE 3 /* Flow table statistics */ +#define OFP_MP_T_PORT_STATS 4 /* Port statistics */ +#define OFP_MP_T_QUEUE 5 /* Queue statistics for a port */ +#define OFP_MP_T_GROUP 6 /* Group counter statistics */ +#define OFP_MP_T_GROUP_DESC 7 /* Group description */ +#define OFP_MP_T_GROUP_FEATURES 8 /* Group features */ +#define OFP_MP_T_METER 9 /* Meter statistics */ +#define OFP_MP_T_METER_CONFIG 10 /* Meter configuration */ +#define OFP_MP_T_METER_FEATURES 11 /* Meter features */ +#define OFP_MP_T_TABLE_FEATURES 12 /* Table features */ +#define OFP_MP_T_PORT_DESC 13 /* Port description */ +#define OFP_MP_T_EXPERIMENTER 0xffff /* Experimenter extension */ + +#define OFP_DESC_STR_LEN 256 +#define OFP_SERIAL_NUM_LEN 32 + +struct ofp_desc { + char d_mfr_desc[OFP_DESC_STR_LEN]; + char d_hw_desc[OFP_DESC_STR_LEN]; + char d_sw_desc[OFP_DESC_STR_LEN]; + char d_serial_num[OFP_SERIAL_NUM_LEN]; + char d_dp_desc[OFP_DESC_STR_LEN]; +} __packed; + +/* Flow stats request */ +struct ofp_flow_stats_request { + uint8_t fsr_table_id; + uint8_t fsr_pad[3]; + uint32_t fsr_out_port; + uint32_t fsr_out_group; + uint8_t fsr_pad2[4]; + uint64_t fsr_cookie; + uint64_t fsr_cookie_mask; + struct ofp_match fsr_match; +} __packed; + +/* Flow stats */ +struct ofp_flow_stats { + uint16_t fs_length; + uint8_t fs_table_id; + uint8_t fs_pad; + uint32_t fs_duration_sec; + uint32_t fs_duration_nsec; + uint16_t fs_priority; + uint16_t fs_idle_timeout; + uint16_t fs_hard_timeout; + uint16_t fs_flags; + uint8_t fs_pad2[4]; + uint64_t fs_cookie; + uint64_t fs_packet_count; + uint64_t fs_byte_count; + struct ofp_match fs_match; +} __packed; + +/* Aggregate flow stats request */ +struct ofp_aggregate_stats_request { + uint8_t asr_table_id; + uint8_t asr_pad[3]; + uint32_t asr_out_port; + uint32_t asr_out_group; + uint8_t asr_pad2[4]; + uint64_t asr_cookie; + uint64_t asr_cookie_mask; + struct ofp_match asr_match; +} __packed; + +struct ofp_aggregate_stats { + uint64_t as_packet_count; + uint64_t as_byte_count; + uint32_t as_flow_count; + uint8_t as_pad[4]; +} __packed; + +/* Special table id */ +#define OFP_TABLE_ID_MAX 0xfe /* Last usable table */ +#define OFP_TABLE_ID_ALL 0xff /* Wildcard table */ + +struct ofp_table_stats { + uint8_t ts_table_id; + uint8_t ts_pad[3]; + uint32_t ts_active_count; + uint64_t ts_lookup_count; + uint64_t ts_matched_count; +} __packed; + +/* Table features */ +#define OFP_TABLE_FEATPROP_INSTRUCTION 0 /* Instruction property */ +#define OFP_TABLE_FEATPROP_INSTRUCTION_MISS 1 /* Instruction for table-miss */ +#define OFP_TABLE_FEATPROP_NEXT_TABLES 2 /* Next table property */ +#define OFP_TABLE_FEATPROP_NEXT_TABLES_MISS 3 /* Next table for table-miss */ +#define OFP_TABLE_FEATPROP_WRITE_ACTIONS 4 /* Write actions property */ +#define OFP_TABLE_FEATPROP_WRITE_ACTIONS_MISS 5 /* Write actions for table-miss */ +#define OFP_TABLE_FEATPROP_APPLY_ACTIONS 6 /* Apply actions property */ +#define OFP_TABLE_FEATPROP_APPLY_ACTIONS_MISS 7 /* Apply actions for table-miss */ +#define OFP_TABLE_FEATPROP_MATCH 8 /* Match property */ +#define OFP_TABLE_FEATPROP_WILDCARDS 10 /* Wildcards property */ +#define OFP_TABLE_FEATPROP_WRITE_SETFIELD 12 /* Write set-field property */ +#define OFP_TABLE_FEATPROP_WRITE_SETFIELD_MISS 13 /* Write set-field for table-miss */ +#define OFP_TABLE_FEATPROP_APPLY_SETFIELD 14 /* Apply set-field property */ +#define OFP_TABLE_FEATPROP_APPLY_SETFIELD_MISS 15 /* Apply set-field for table-miss */ +#define OFP_TABLE_FEATPROP_EXPERIMENTER 0xfffe /* Experimenter property */ +#define OFP_TABLE_FEATPROP_EXPERIMENTER_MISS 0xffff /* Experimenter for table-miss */ + +#define OFP_TABLE_MAX_NAME_LEN 32 + +struct ofp_table_features { + uint16_t tf_length; + uint8_t tf_tableid; + uint8_t tf_pad[5]; + char tf_name[OFP_TABLE_MAX_NAME_LEN]; + uint64_t tf_metadata_match; + uint64_t tf_metadata_write; + uint32_t tf_config; + uint32_t tf_max_entries; +} __packed; + +struct ofp_table_feature_property { + uint16_t tp_type; + uint16_t tp_length; +} __packed; + +struct ofp_table_feature_property_instruction { + uint16_t tpi_type; + uint16_t tpi_length; + struct ofp_instruction tpi_instructions[0]; +} __packed; + +struct ofp_table_feature_property_next_tables { + uint16_t tpnt_type; + uint16_t tpnt_length; + uint8_t tpnt_tables[0]; +} __packed; + +struct ofp_table_feature_property_actions { + uint16_t tpa_type; + uint16_t tpa_length; + struct ofp_action_header tpa_actions[0]; +} __packed; + +struct ofp_table_feature_property_oxm { + uint16_t tpoxm_type; + uint16_t tpoxm_length; + uint32_t tpoxm_oxm[0]; +} __packed; + +struct ofp_table_feature_property_experimenter { + uint16_t tfpexp_type; + uint16_t tfpexp_length; + uint32_t tfpexp_experimenter; + uint32_t tfpexp_exp_type; + uint32_t tfpexp_experimenter_data[0]; +} __packed; + +struct ofp_port_stats { + uint32_t pt_port_no; + uint8_t pt_pad[4]; + uint64_t pt_rx_packets; + uint64_t pt_tx_packets; + uint64_t pt_rx_bytes; + uint64_t pt_tx_bytes; + uint64_t pt_rx_dropped; + uint64_t pt_tx_dropped; + uint64_t pt_rx_errors; + uint64_t pt_tx_errors; + uint64_t pt_rx_frame_err; + uint64_t pt_rx_over_err; + uint64_t pt_rx_crc_err; + uint64_t pt_collision; + uint32_t pt_duration_sec; + uint32_t pt_duration_nsec; +} __packed; + +/* Groups stats request */ +struct ofp_group_stats_request { + uint32_t gsr_group_id; + uint8_t gsr_pad[4]; +} __packed; + +struct ofp_bucket_counter { + uint64_t gs_packet_count; + uint64_t gs_byte_count; +} __packed; + +/* Group stats */ +struct ofp_group_stats { + uint16_t gs_length; + uint8_t gs_pad[2]; + uint32_t gs_group_id; + uint32_t gs_ref_count; + uint8_t gs_pad2[4]; + uint64_t gs_packet_count; + uint64_t gs_byte_count; + uint32_t gs_duration_sec; + uint32_t gs_duration_nsec; + struct ofp_bucket_counter gs_bucket_stats[0]; +} __packed; + +/* Group description */ +struct ofp_group_desc { + uint16_t gd_length; + uint8_t gd_type; + uint8_t gd_pad; + uint32_t gd_group_id; + struct ofp_bucket gd_buckets[0]; +} __packed; + +/* + * Implementation-specific definitions that are not part of the spec + */ + +/* OpenFlow finite state machine */ +enum ofp_state { + OFP_STATE_CLOSED, + OFP_STATE_HELLO_WAIT, + OFP_STATE_FEATURE_WAIT, + OFP_STATE_ESTABLISHED +}; + +/* Used by the bpf for DLT_OPENFLOW */ +struct dlt_openflow_hdr { + uint32_t of_direction; + uint64_t of_datapath_id; +} __packed; + +#define DLT_OPENFLOW_TO_SWITCH 1 +#define DLT_OPENFLOW_TO_CONTROLLER 2 + +#endif /* _NET_OFP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/pfkeyv2.h b/lib/libc/include/generic-openbsd/net/pfkeyv2.h new file mode 100644 index 0000000000..5934ba742f --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/pfkeyv2.h @@ -0,0 +1,473 @@ +/* $OpenBSD: pfkeyv2.h,v 1.95 2024/05/13 01:15:53 jsg Exp $ */ +/* + * @(#)COPYRIGHT 1.1 (NRL) January 1998 + * + * NRL grants permission for redistribution and use in source and binary + * forms, with or without modification, of the software and documentation + * created at NRL 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 acknowledgements: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * This product includes software developed at the Information + * Technology Division, US Naval Research Laboratory. + * 4. Neither the name of the NRL nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THE SOFTWARE PROVIDED BY NRL IS PROVIDED BY NRL 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 NRL 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. + * + * The views and conclusions contained in the software and documentation + * are those of the authors and should not be interpreted as representing + * official policies, either expressed or implied, of the US Naval + * Research Laboratory (NRL). + */ + +#ifndef _NET_PFKEY_V2_H_ +#define _NET_PFKEY_V2_H_ + +#define PF_KEY_V2 2 +#define PFKEYV2_REVISION 199806L + +/* This should be updated whenever the API is altered. */ +#define _OPENBSD_IPSEC_API_VERSION 2 + +#define SADB_RESERVED 0 +#define SADB_GETSPI 1 +#define SADB_UPDATE 2 +#define SADB_ADD 3 +#define SADB_DELETE 4 +#define SADB_GET 5 +#define SADB_ACQUIRE 6 +#define SADB_REGISTER 7 +#define SADB_EXPIRE 8 +#define SADB_FLUSH 9 +#define SADB_DUMP 10 +#define SADB_X_PROMISC 11 +#define SADB_X_ADDFLOW 12 +#define SADB_X_DELFLOW 13 +#define SADB_X_GRPSPIS 14 +#define SADB_X_ASKPOLICY 15 +#define SADB_X_SPDDUMP 16 +#define SADB_MAX 16 + +struct sadb_msg { + uint8_t sadb_msg_version; + uint8_t sadb_msg_type; + uint8_t sadb_msg_errno; + uint8_t sadb_msg_satype; + uint16_t sadb_msg_len; + uint16_t sadb_msg_reserved; + uint32_t sadb_msg_seq; + uint32_t sadb_msg_pid; +}; + +struct sadb_ext { + uint16_t sadb_ext_len; + uint16_t sadb_ext_type; +}; + +struct sadb_sa { + uint16_t sadb_sa_len; + uint16_t sadb_sa_exttype; + uint32_t sadb_sa_spi; + uint8_t sadb_sa_replay; + uint8_t sadb_sa_state; + uint8_t sadb_sa_auth; + uint8_t sadb_sa_encrypt; + uint32_t sadb_sa_flags; +}; + +struct sadb_lifetime { + uint16_t sadb_lifetime_len; + uint16_t sadb_lifetime_exttype; + uint32_t sadb_lifetime_allocations; + uint64_t sadb_lifetime_bytes; + uint64_t sadb_lifetime_addtime; + uint64_t sadb_lifetime_usetime; +}; + +struct sadb_address { + uint16_t sadb_address_len; + uint16_t sadb_address_exttype; + uint32_t sadb_address_reserved; +}; + +struct sadb_key { + uint16_t sadb_key_len; + uint16_t sadb_key_exttype; + uint16_t sadb_key_bits; + uint16_t sadb_key_reserved; +}; + +struct sadb_ident { + uint16_t sadb_ident_len; + uint16_t sadb_ident_exttype; + uint16_t sadb_ident_type; + uint16_t sadb_ident_reserved; + uint64_t sadb_ident_id; +}; + +struct sadb_sens { + uint16_t sadb_sens_len; + uint16_t sadb_sens_exttype; + uint32_t sadb_sens_dpd; + uint8_t sadb_sens_sens_level; + uint8_t sadb_sens_sens_len; + uint8_t sadb_sens_integ_level; + uint8_t sadb_sens_integ_len; + uint32_t sadb_sens_reserved; +}; + +struct sadb_prop { + uint16_t sadb_prop_len; + uint16_t sadb_prop_exttype; + uint8_t sadb_prop_num; + uint8_t sadb_prop_replay; + uint16_t sadb_prop_reserved; +}; + +struct sadb_comb { + uint8_t sadb_comb_auth; + uint8_t sadb_comb_encrypt; + uint16_t sadb_comb_flags; + uint16_t sadb_comb_auth_minbits; + uint16_t sadb_comb_auth_maxbits; + uint16_t sadb_comb_encrypt_minbits; + uint16_t sadb_comb_encrypt_maxbits; + uint32_t sadb_comb_reserved; + uint32_t sadb_comb_soft_allocations; + uint32_t sadb_comb_hard_allocations; + uint64_t sadb_comb_soft_bytes; + uint64_t sadb_comb_hard_bytes; + uint64_t sadb_comb_soft_addtime; + uint64_t sadb_comb_hard_addtime; + uint64_t sadb_comb_soft_usetime; + uint64_t sadb_comb_hard_usetime; +}; + +struct sadb_supported { + uint16_t sadb_supported_len; + uint16_t sadb_supported_exttype; + uint32_t sadb_supported_reserved; +}; + +struct sadb_alg { + uint8_t sadb_alg_id; + uint8_t sadb_alg_ivlen; + uint16_t sadb_alg_minbits; + uint16_t sadb_alg_maxbits; + uint16_t sadb_alg_reserved; +}; + +struct sadb_spirange { + uint16_t sadb_spirange_len; + uint16_t sadb_spirange_exttype; + uint32_t sadb_spirange_min; + uint32_t sadb_spirange_max; + uint32_t sadb_spirange_reserved; +}; + +struct sadb_protocol { + uint16_t sadb_protocol_len; + uint16_t sadb_protocol_exttype; + uint8_t sadb_protocol_proto; + uint8_t sadb_protocol_direction; + uint8_t sadb_protocol_flags; + uint8_t sadb_protocol_reserved2; +}; + +struct sadb_x_policy { + uint16_t sadb_x_policy_len; + uint16_t sadb_x_policy_exttype; + uint32_t sadb_x_policy_seq; +}; + +struct sadb_x_udpencap { + uint16_t sadb_x_udpencap_len; + uint16_t sadb_x_udpencap_exttype; + uint16_t sadb_x_udpencap_port; + uint16_t sadb_x_udpencap_reserved; +}; + +struct sadb_x_tag { + uint16_t sadb_x_tag_len; + uint16_t sadb_x_tag_exttype; + uint32_t sadb_x_tag_taglen; +}; + +struct sadb_x_replay { + uint16_t sadb_x_replay_len; + uint16_t sadb_x_replay_exttype; + uint32_t sadb_x_replay_reserved; + uint64_t sadb_x_replay_count; +}; + +struct sadb_x_rdomain { + uint16_t sadb_x_rdomain_len; + uint16_t sadb_x_rdomain_exttype; + uint16_t sadb_x_rdomain_dom1; + uint16_t sadb_x_rdomain_dom2; +}; + +struct sadb_x_tap { + uint16_t sadb_x_tap_len; + uint16_t sadb_x_tap_exttype; + uint32_t sadb_x_tap_unit; +}; + +struct sadb_x_counter { + uint16_t sadb_x_counter_len; + uint16_t sadb_x_counter_exttype; + uint32_t sadb_x_counter_pad; + uint64_t sadb_x_counter_ipackets; /* Input IPsec packets */ + uint64_t sadb_x_counter_opackets; /* Output IPsec packets */ + uint64_t sadb_x_counter_ibytes; /* Input bytes */ + uint64_t sadb_x_counter_obytes; /* Output bytes */ + uint64_t sadb_x_counter_idrops; /* Dropped on input */ + uint64_t sadb_x_counter_odrops; /* Dropped on output */ + uint64_t sadb_x_counter_idecompbytes; /* Input bytes, decompressed */ + uint64_t sadb_x_counter_ouncompbytes; /* Output bytes, uncompressed */ +}; + +struct sadb_x_mtu { + uint16_t sadb_x_mtu_len; + uint16_t sadb_x_mtu_exttype; + uint32_t sadb_x_mtu_mtu; +}; + +struct sadb_x_iface { + uint16_t sadb_x_iface_len; + uint16_t sadb_x_iface_exttype; + uint32_t sadb_x_iface_unit; + uint8_t sadb_x_iface_direction; + uint8_t sadb_x_iface_reserved[7]; +}; + +#ifdef _KERNEL +#define SADB_X_GETSPROTO(x) \ + ( (x) == SADB_SATYPE_AH ? IPPROTO_AH :\ + (x) == SADB_SATYPE_ESP ? IPPROTO_ESP :\ + (x) == SADB_X_SATYPE_TCPSIGNATURE ? IPPROTO_TCP :\ + (x) == SADB_X_SATYPE_IPCOMP ? IPPROTO_IPCOMP: IPPROTO_IPIP ) +#endif + +#define SADB_EXT_RESERVED 0 +#define SADB_EXT_SA 1 +#define SADB_EXT_LIFETIME_CURRENT 2 +#define SADB_EXT_LIFETIME_HARD 3 +#define SADB_EXT_LIFETIME_SOFT 4 +#define SADB_EXT_ADDRESS_SRC 5 +#define SADB_EXT_ADDRESS_DST 6 +#define SADB_EXT_ADDRESS_PROXY 7 +#define SADB_EXT_KEY_AUTH 8 +#define SADB_EXT_KEY_ENCRYPT 9 +#define SADB_EXT_IDENTITY_SRC 10 +#define SADB_EXT_IDENTITY_DST 11 +#define SADB_EXT_SENSITIVITY 12 +#define SADB_EXT_PROPOSAL 13 +#define SADB_EXT_SUPPORTED_AUTH 14 +#define SADB_EXT_SUPPORTED_ENCRYPT 15 +#define SADB_EXT_SPIRANGE 16 +#define SADB_X_EXT_SRC_MASK 17 +#define SADB_X_EXT_DST_MASK 18 +#define SADB_X_EXT_PROTOCOL 19 +#define SADB_X_EXT_FLOW_TYPE 20 +#define SADB_X_EXT_SRC_FLOW 21 +#define SADB_X_EXT_DST_FLOW 22 +#define SADB_X_EXT_SA2 23 +#define SADB_X_EXT_DST2 24 +#define SADB_X_EXT_POLICY 25 +#define SADB_X_EXT_LOCAL_CREDENTIALS 26 +#define SADB_X_EXT_REMOTE_CREDENTIALS 27 +#define SADB_X_EXT_LOCAL_AUTH 28 +#define SADB_X_EXT_REMOTE_AUTH 29 +#define SADB_X_EXT_SUPPORTED_COMP 30 +#define SADB_X_EXT_UDPENCAP 31 +#define SADB_X_EXT_LIFETIME_LASTUSE 32 +#define SADB_X_EXT_TAG 33 +#define SADB_X_EXT_TAP 34 +#define SADB_X_EXT_SATYPE2 35 +#define SADB_X_EXT_COUNTER 36 +#define SADB_X_EXT_RDOMAIN 37 +#define SADB_X_EXT_MTU 38 +#define SADB_X_EXT_REPLAY 39 +#define SADB_X_EXT_IFACE 40 +#define SADB_EXT_MAX 40 + +/* Fix pfkeyv2.c struct pfkeyv2_socket if SATYPE_MAX > 31 */ +#define SADB_SATYPE_UNSPEC 0 +#define SADB_SATYPE_AH 1 +#define SADB_SATYPE_ESP 2 +#define SADB_SATYPE_RSVP 3 +#define SADB_SATYPE_OSPFV2 4 +#define SADB_SATYPE_RIPV2 5 +#define SADB_SATYPE_MIP 6 +#define SADB_X_SATYPE_IPIP 7 +#define SADB_X_SATYPE_TCPSIGNATURE 8 +#define SADB_X_SATYPE_IPCOMP 9 +#define SADB_SATYPE_MAX 9 + +#define SADB_SASTATE_LARVAL 0 +#define SADB_SASTATE_MATURE 1 +#define SADB_SASTATE_DYING 2 +#define SADB_SASTATE_DEAD 3 +#define SADB_SASTATE_MAX 3 + +#define SADB_AALG_NONE 0 +#define SADB_AALG_MD5HMAC 2 +#define SADB_AALG_SHA1HMAC 3 +#define SADB_X_AALG_SHA2_256 5 +#define SADB_X_AALG_SHA2_384 6 +#define SADB_X_AALG_SHA2_512 7 +#define SADB_X_AALG_RIPEMD160HMAC 8 +#define SADB_X_AALG_AES128GMAC 9 +#define SADB_X_AALG_AES192GMAC 10 +#define SADB_X_AALG_AES256GMAC 11 +#define SADB_X_AALG_CHACHA20POLY1305 12 +#define SADB_AALG_MAX 12 + +#define SADB_EALG_NONE 0 +#define SADB_EALG_3DESCBC 3 +#define SADB_X_EALG_CAST 6 +#define SADB_X_EALG_BLF 7 +#define SADB_EALG_NULL 11 +#define SADB_X_EALG_AES 12 +#define SADB_X_EALG_AESCTR 13 +#define SADB_X_EALG_AESGCM8 18 +#define SADB_X_EALG_AESGCM12 19 +#define SADB_X_EALG_AESGCM16 20 +#define SADB_X_EALG_AESGMAC 21 +#define SADB_X_EALG_CHACHA20POLY1305 22 +#define SADB_EALG_MAX 22 + +#define SADB_X_CALG_NONE 0 +#define SADB_X_CALG_OUI 1 +#define SADB_X_CALG_DEFLATE 2 +#define SADB_X_CALG_MAX 2 + +#define SADB_SAFLAGS_PFS 0x001 /* perfect forward secrecy */ +#define SADB_X_SAFLAGS_TUNNEL 0x004 /* Force tunneling */ +#define SADB_X_SAFLAGS_CHAINDEL 0x008 /* Delete whole SA chain */ +#define SADB_X_SAFLAGS_UDPENCAP 0x200 /* ESP in UDP */ +#define SADB_X_SAFLAGS_ESN 0x400 /* Extended Sequence Number */ + +#define SADB_X_POLICYFLAGS_POLICY 0x0001 /* This is a static policy */ + +#define SADB_IDENTTYPE_RESERVED 0 +#define SADB_IDENTTYPE_PREFIX 1 +#define SADB_IDENTTYPE_FQDN 2 +#define SADB_IDENTTYPE_USERFQDN 3 +#define SADB_IDENTTYPE_ASN1_DN 4 +#define SADB_IDENTTYPE_MAX 4 + +#define SADB_KEY_FLAGS_MAX 0 + +#ifdef _KERNEL +#define PFKEYV2_LIFETIME_HARD 0 +#define PFKEYV2_LIFETIME_SOFT 1 +#define PFKEYV2_LIFETIME_CURRENT 2 +#define PFKEYV2_LIFETIME_LASTUSE 3 + +#define PFKEYV2_IDENTITY_SRC 0 +#define PFKEYV2_IDENTITY_DST 1 + +#define PFKEYV2_ENCRYPTION_KEY 0 +#define PFKEYV2_AUTHENTICATION_KEY 1 + +#define PFKEYV2_SOCKETFLAGS_REGISTERED 1 +#define PFKEYV2_SOCKETFLAGS_PROMISC 2 + +#define PFKEYV2_SENDMESSAGE_UNICAST 1 +#define PFKEYV2_SENDMESSAGE_REGISTERED 2 +#define PFKEYV2_SENDMESSAGE_BROADCAST 3 +#endif /* _KERNEL */ + +#define SADB_X_FLOW_TYPE_USE 1 +#define SADB_X_FLOW_TYPE_ACQUIRE 2 +#define SADB_X_FLOW_TYPE_REQUIRE 3 +#define SADB_X_FLOW_TYPE_BYPASS 4 +#define SADB_X_FLOW_TYPE_DENY 5 +#define SADB_X_FLOW_TYPE_DONTACQ 6 + +#ifdef _KERNEL +struct tdb; +struct socket; +struct mbuf; + +#define EXTLEN(x) (((struct sadb_ext *)(x))->sadb_ext_len * sizeof(uint64_t)) +#define PADUP(x) (((x) + sizeof(uint64_t) - 1) & ~(sizeof(uint64_t) - 1)) + +int pfkeyv2_parsemessage(void *, int, void **); +int pfkeyv2_expire(struct tdb *, u_int16_t); +int pfkeyv2_acquire(struct ipsec_policy *, union sockaddr_union *, + union sockaddr_union *, u_int32_t *, struct sockaddr_encap *); + +int pfkeyv2_get(struct tdb *, void **, void **, int *, int *); +int pfkeyv2_policy(struct ipsec_acquire *, void **, void **, int *); +int pfkeyv2_dosend(struct socket *, void *, int); +int pfkeyv2_sendmessage(void **, int, struct socket *, u_int8_t, int, u_int); +int pfkeyv2_dump_policy(struct ipsec_policy *, void **, void **, int *); +int pfkeyv2_dump_walker(struct tdb *, void *, int); +int pfkeyv2_get_proto_alg(u_int8_t, u_int8_t *, int *); +int pfkeyv2_sysctl(int *, u_int, void *, size_t *, void *, size_t); +int pfkeyv2_sysctl_walker(struct tdb *, void *, int); + +int pfdatatopacket(void *, int, struct mbuf **); + +void export_address(void **, struct sockaddr *); +void export_identities(void **, struct ipsec_ids *, int, void **); +void export_lifetime(void **, struct tdb *, int); +void export_sa(void **, struct tdb *); +void export_flow(void **, u_int8_t, struct sockaddr_encap *, + struct sockaddr_encap *, void **); +void export_key(void **, struct tdb *, int); +void export_udpencap(void **, struct tdb *); +void export_tag(void **, struct tdb *); +void export_replay(void **, struct tdb *); +void export_rdomain(void **, struct tdb *); +void export_mtu(void **, struct tdb *); +void export_tap(void **, struct tdb *); +void export_satype(void **, struct tdb *); +void export_counter(void **, struct tdb *); +void export_iface(void **, struct tdb *); + +void import_address(struct sockaddr *, struct sadb_address *); +void import_identities(struct ipsec_ids **, int, struct sadb_ident *, + struct sadb_ident *); +void import_key(struct ipsecinit *, struct sadb_key *, int); +void import_lifetime(struct tdb *, struct sadb_lifetime *, int); +void import_sa(struct tdb *, struct sadb_sa *, struct ipsecinit *); +int import_flow(struct sockaddr_encap *, struct sockaddr_encap *, + struct sadb_address *, struct sadb_address *, struct sadb_address *, + struct sadb_address *, struct sadb_protocol *, struct sadb_protocol *); +void import_udpencap(struct tdb *, struct sadb_x_udpencap *); +void import_tag(struct tdb *, struct sadb_x_tag *); +void import_rdomain(struct tdb *, struct sadb_x_rdomain *); +void import_tap(struct tdb *, struct sadb_x_tap *); +void import_iface(struct tdb *, struct sadb_x_iface *); + +extern const uint64_t sadb_exts_allowed_out[SADB_MAX+1]; +extern const uint64_t sadb_exts_required_out[SADB_MAX+1]; + +extern struct pool ipsec_policy_pool; +extern struct pool ipsec_acquire_pool; +#endif /* _KERNEL */ + +#endif /* _NET_PFKEY_V2_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/pfvar.h b/lib/libc/include/generic-openbsd/net/pfvar.h new file mode 100644 index 0000000000..96654afc9d --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/pfvar.h @@ -0,0 +1,1883 @@ +/* $OpenBSD: pfvar.h,v 1.543 2025/04/14 20:02:34 sf Exp $ */ + +/* + * Copyright (c) 2001 Daniel Hartmeier + * Copyright (c) 2002 - 2013 Henning Brauer + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT HOLDERS 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 _NET_PFVAR_H_ +#define _NET_PFVAR_H_ + +#include +#include +#include +#include +#include + +#include + +#include +#include + +struct ip; +struct ip6_hdr; +struct mbuf_list; + +#define PF_TCPS_PROXY_SRC ((TCP_NSTATES)+0) +#define PF_TCPS_PROXY_DST ((TCP_NSTATES)+1) + +#define PF_MD5_DIGEST_LENGTH 16 +#ifdef MD5_DIGEST_LENGTH +#if PF_MD5_DIGEST_LENGTH != MD5_DIGEST_LENGTH +#error md5 digest length mismatch +#endif +#endif + +typedef struct refcnt pf_refcnt_t; +#define PF_REF_INIT(_x) refcnt_init(&(_x)) +#define PF_REF_TAKE(_x) refcnt_take(&(_x)) +#define PF_REF_RELE(_x) refcnt_rele(&(_x)) + +enum { PF_INOUT, PF_IN, PF_OUT, PF_FWD }; +enum { PF_PASS, PF_DROP, PF_SCRUB, PF_NOSCRUB, PF_NAT, PF_NONAT, + PF_BINAT, PF_NOBINAT, PF_RDR, PF_NORDR, PF_SYNPROXY_DROP, PF_DEFER, + PF_MATCH, PF_DIVERT, PF_RT, PF_AFRT }; +enum { PF_TRANS_RULESET, PF_TRANS_TABLE }; +enum { PF_OP_NONE, PF_OP_IRG, PF_OP_EQ, PF_OP_NE, PF_OP_LT, + PF_OP_LE, PF_OP_GT, PF_OP_GE, PF_OP_XRG, PF_OP_RRG }; +enum { PF_CHANGE_NONE, PF_CHANGE_ADD_HEAD, PF_CHANGE_ADD_TAIL, + PF_CHANGE_ADD_BEFORE, PF_CHANGE_ADD_AFTER, + PF_CHANGE_REMOVE, PF_CHANGE_GET_TICKET }; +enum { PF_GET_NONE, PF_GET_CLR_CNTR }; +enum { PF_SK_WIRE, PF_SK_STACK, PF_SK_BOTH }; +enum { PF_PEER_SRC, PF_PEER_DST, PF_PEER_BOTH }; + +/* + * Note about PFTM_*: real indices into pf_rule.timeout[] come before + * PFTM_MAX, special cases afterwards. See pf_state_expires(). + */ +enum { PFTM_TCP_FIRST_PACKET, PFTM_TCP_OPENING, PFTM_TCP_ESTABLISHED, + PFTM_TCP_CLOSING, PFTM_TCP_FIN_WAIT, PFTM_TCP_CLOSED, + PFTM_UDP_FIRST_PACKET, PFTM_UDP_SINGLE, PFTM_UDP_MULTIPLE, + PFTM_ICMP_FIRST_PACKET, PFTM_ICMP_ERROR_REPLY, + PFTM_OTHER_FIRST_PACKET, PFTM_OTHER_SINGLE, + PFTM_OTHER_MULTIPLE, PFTM_FRAG, PFTM_INTERVAL, + PFTM_ADAPTIVE_START, PFTM_ADAPTIVE_END, PFTM_SRC_NODE, + PFTM_TS_DIFF, PFTM_MAX, PFTM_PURGE, PFTM_UNLINKED }; + +/* PFTM default values */ +#define PFTM_TCP_FIRST_PACKET_VAL 120 /* First TCP packet */ +#define PFTM_TCP_OPENING_VAL 30 /* No response yet */ +#define PFTM_TCP_ESTABLISHED_VAL 24*60*60/* Established */ +#define PFTM_TCP_CLOSING_VAL 15 * 60 /* Half closed */ +#define PFTM_TCP_FIN_WAIT_VAL 45 /* Got both FINs */ +#define PFTM_TCP_CLOSED_VAL 90 /* Got a RST */ +#define PFTM_UDP_FIRST_PACKET_VAL 60 /* First UDP packet */ +#define PFTM_UDP_SINGLE_VAL 30 /* Unidirectional */ +#define PFTM_UDP_MULTIPLE_VAL 60 /* Bidirectional */ +#define PFTM_ICMP_FIRST_PACKET_VAL 20 /* First ICMP packet */ +#define PFTM_ICMP_ERROR_REPLY_VAL 10 /* Got error response */ +#define PFTM_OTHER_FIRST_PACKET_VAL 60 /* First packet */ +#define PFTM_OTHER_SINGLE_VAL 30 /* Unidirectional */ +#define PFTM_OTHER_MULTIPLE_VAL 60 /* Bidirectional */ +#define PFTM_FRAG_VAL 60 /* Fragment expire */ +#define PFTM_INTERVAL_VAL 10 /* Expire interval */ +#define PFTM_SRC_NODE_VAL 0 /* Source tracking */ +#define PFTM_TS_DIFF_VAL 30 /* Allowed TS diff */ + +/* + * For each connection (combination of proto,src,dst,af) the number + * of fragments is limited. Over the PFTM_FRAG interval the average + * rate must be less than PF_FRAG_STALE fragments per second. + * Otherwise older fragments are considered stale and are dropped. + */ +#define PF_FRAG_STALE 200 + +/* + * Limit the length of the fragment queue traversal. Remember + * search entry points based on the fragment offset. + */ +#define PF_FRAG_ENTRY_POINTS 16 + +/* + * The number of entries in the fragment queue must be limited + * to avoid DoS by linear searching. Instead of a global limit, + * use a limit per entry point. For large packets these sum up. + */ +#define PF_FRAG_ENTRY_LIMIT 64 + +enum { PF_NOPFROUTE, PF_ROUTETO, PF_DUPTO, PF_REPLYTO }; +enum { PF_LIMIT_STATES, PF_LIMIT_SRC_NODES, PF_LIMIT_FRAGS, + PF_LIMIT_TABLES, PF_LIMIT_TABLE_ENTRIES, PF_LIMIT_PKTDELAY_PKTS, + PF_LIMIT_ANCHORS, PF_LIMIT_MAX }; +#define PF_POOL_IDMASK 0x0f +enum { PF_POOL_NONE, PF_POOL_BITMASK, PF_POOL_RANDOM, + PF_POOL_SRCHASH, PF_POOL_ROUNDROBIN, PF_POOL_LEASTSTATES }; +enum { PF_ADDR_ADDRMASK, PF_ADDR_NOROUTE, PF_ADDR_DYNIFTL, + PF_ADDR_TABLE, PF_ADDR_RTLABEL, PF_ADDR_URPFFAILED, + PF_ADDR_RANGE, PF_ADDR_NONE }; +#define PF_POOL_TYPEMASK 0x0f +#define PF_POOL_STICKYADDR 0x20 +#define PF_WSCALE_FLAG 0x80 +#define PF_WSCALE_MASK 0x0f + +#define PF_POOL_DYNTYPE(_o) \ + ((((_o) & PF_POOL_TYPEMASK) == PF_POOL_ROUNDROBIN) || \ + (((_o) & PF_POOL_TYPEMASK) == PF_POOL_LEASTSTATES) || \ + (((_o) & PF_POOL_TYPEMASK) == PF_POOL_RANDOM) || \ + (((_o) & PF_POOL_TYPEMASK) == PF_POOL_SRCHASH)) + +#define PF_LOG 0x01 +#define PF_LOG_ALL 0x02 +#define PF_LOG_USER 0x04 +#define PF_LOG_FORCE 0x08 +#define PF_LOG_MATCHES 0x10 + +struct pf_addr { + union { + struct in_addr v4; + struct in6_addr v6; + u_int8_t addr8[16]; + u_int16_t addr16[8]; + u_int32_t addr32[4]; + } pfa; /* 128-bit address */ +#define v4 pfa.v4 +#define v6 pfa.v6 +#define addr8 pfa.addr8 +#define addr16 pfa.addr16 +#define addr32 pfa.addr32 +}; + +#define PF_TABLE_NAME_SIZE 32 + +#define PFI_AFLAG_NETWORK 0x01 +#define PFI_AFLAG_BROADCAST 0x02 +#define PFI_AFLAG_PEER 0x04 +#define PFI_AFLAG_MODEMASK 0x07 +#define PFI_AFLAG_NOALIAS 0x08 + +struct pf_addr_wrap { + union { + struct { + struct pf_addr addr; + struct pf_addr mask; + } a; + char ifname[IFNAMSIZ]; + char tblname[PF_TABLE_NAME_SIZE]; + char rtlabelname[RTLABEL_LEN]; + u_int32_t rtlabel; + } v; + union { + struct pfi_dynaddr *dyn; + struct pfr_ktable *tbl; + int dyncnt; + int tblcnt; + } p; + u_int8_t type; /* PF_ADDR_* */ + u_int8_t iflags; /* PFI_AFLAG_* */ +}; + +#ifdef _KERNEL +struct pfi_dynaddr { + TAILQ_ENTRY(pfi_dynaddr) entry; + struct pf_addr pfid_addr4; + struct pf_addr pfid_mask4; + struct pf_addr pfid_addr6; + struct pf_addr pfid_mask6; + struct pfr_ktable *pfid_kt; + struct pfi_kif *pfid_kif; + void *pfid_hook_cookie; + int pfid_net; /* mask or 128 */ + int pfid_acnt4; /* address count IPv4 */ + int pfid_acnt6; /* address count IPv6 */ + sa_family_t pfid_af; /* rule af */ + u_int8_t pfid_iflags; /* PFI_AFLAG_* */ +}; +#endif /* _KERNEL */ + + +/* + * Logging macros + */ + +#ifndef PF_DEBUGNAME +#define PF_DEBUGNAME "pf: " +#endif + +#ifdef _KERNEL +#define DPFPRINTF(n, format, x...) \ + do { \ + if (pf_status.debug >= (n)) { \ + log(n, PF_DEBUGNAME); \ + addlog(format, ##x); \ + addlog("\n"); \ + } \ + } while (0) +#else +#ifdef PFDEBUG +#define DPFPRINTF(n, format, x...) \ + do { \ + fprintf(stderr, format, ##x); \ + fprintf(stderr, "\n"); \ + } while (0) +#else +#define DPFPRINTF(n, format, x...) ((void)0) +#endif /* PFDEBUG */ +#endif /* _KERNEL */ + + +/* + * Address manipulation macros + */ + +#define PF_AEQ(a, b, c) \ + ((c == AF_INET && (a)->addr32[0] == (b)->addr32[0]) || \ + (c == AF_INET6 && \ + (a)->addr32[3] == (b)->addr32[3] && \ + (a)->addr32[2] == (b)->addr32[2] && \ + (a)->addr32[1] == (b)->addr32[1] && \ + (a)->addr32[0] == (b)->addr32[0])) \ + +#define PF_ANEQ(a, b, c) \ + ((c == AF_INET && (a)->addr32[0] != (b)->addr32[0]) || \ + (c == AF_INET6 && \ + ((a)->addr32[3] != (b)->addr32[3] || \ + (a)->addr32[2] != (b)->addr32[2] || \ + (a)->addr32[1] != (b)->addr32[1] || \ + (a)->addr32[0] != (b)->addr32[0]))) \ + +#define PF_AZERO(a, c) \ + ((c == AF_INET && !(a)->addr32[0]) || \ + (c == AF_INET6 && \ + !(a)->addr32[0] && !(a)->addr32[1] && \ + !(a)->addr32[2] && !(a)->addr32[3] )) \ + +#define PF_MISMATCHAW(aw, x, af, neg, ifp, rtid) \ + ( \ + (((aw)->type == PF_ADDR_NOROUTE && \ + pf_routable((x), (af), NULL, (rtid))) || \ + (((aw)->type == PF_ADDR_URPFFAILED && (ifp) != NULL && \ + pf_routable((x), (af), (ifp), (rtid))) || \ + ((aw)->type == PF_ADDR_RTLABEL && \ + !pf_rtlabel_match((x), (af), (aw), (rtid))) || \ + ((aw)->type == PF_ADDR_TABLE && \ + !pfr_match_addr((aw)->p.tbl, (x), (af))) || \ + ((aw)->type == PF_ADDR_DYNIFTL && \ + !pfi_match_addr((aw)->p.dyn, (x), (af))) || \ + ((aw)->type == PF_ADDR_RANGE && \ + !pf_match_addr_range(&(aw)->v.a.addr, \ + &(aw)->v.a.mask, (x), (af))) || \ + ((aw)->type == PF_ADDR_ADDRMASK && \ + !PF_AZERO(&(aw)->v.a.mask, (af)) && \ + !pf_match_addr(0, &(aw)->v.a.addr, \ + &(aw)->v.a.mask, (x), (af))))) != \ + (neg) \ + ) + +struct pf_rule_uid { + uid_t uid[2]; + u_int8_t op; +}; + +struct pf_rule_gid { + uid_t gid[2]; + u_int8_t op; +}; + +struct pf_rule_addr { + struct pf_addr_wrap addr; + u_int16_t port[2]; + u_int8_t neg; + u_int8_t port_op; + u_int16_t weight; +}; + +struct pf_threshold { + u_int32_t limit; +#define PF_THRESHOLD_MULT 1000 +#define PF_THRESHOLD_MAX 0xffffffff / PF_THRESHOLD_MULT + u_int32_t seconds; + u_int32_t count; + u_int32_t last; +}; + +struct pf_poolhashkey { + union { + u_int8_t key8[16]; + u_int16_t key16[8]; + u_int32_t key32[4]; + } pfk; /* 128-bit hash key */ +#define key8 pfk.key8 +#define key16 pfk.key16 +#define key32 pfk.key32 +}; + +struct pf_pool { + struct pf_addr_wrap addr; + struct pf_poolhashkey key; + struct pf_addr counter; + char ifname[IFNAMSIZ]; + struct pfi_kif *kif; + int tblidx; + u_int64_t states; + int curweight; + u_int16_t weight; + u_int16_t proxy_port[2]; + u_int8_t port_op; + u_int8_t opts; +}; + +/* A packed Operating System description for fingerprinting */ +typedef u_int32_t pf_osfp_t; +#define PF_OSFP_ANY ((pf_osfp_t)0) +#define PF_OSFP_UNKNOWN ((pf_osfp_t)-1) +#define PF_OSFP_NOMATCH ((pf_osfp_t)-2) + +struct pf_osfp_entry { + SLIST_ENTRY(pf_osfp_entry) fp_entry; + pf_osfp_t fp_os; + int fp_enflags; +#define PF_OSFP_EXPANDED 0x001 /* expanded entry */ +#define PF_OSFP_GENERIC 0x002 /* generic signature */ +#define PF_OSFP_NODETAIL 0x004 /* no p0f details */ +#define PF_OSFP_LEN 32 + u_char fp_class_nm[PF_OSFP_LEN]; + u_char fp_version_nm[PF_OSFP_LEN]; + u_char fp_subtype_nm[PF_OSFP_LEN]; +}; +#define PF_OSFP_ENTRY_EQ(a, b) \ + ((a)->fp_os == (b)->fp_os && \ + memcmp((a)->fp_class_nm, (b)->fp_class_nm, PF_OSFP_LEN) == 0 && \ + memcmp((a)->fp_version_nm, (b)->fp_version_nm, PF_OSFP_LEN) == 0 && \ + memcmp((a)->fp_subtype_nm, (b)->fp_subtype_nm, PF_OSFP_LEN) == 0) + +/* handle pf_osfp_t packing */ +#define _FP_RESERVED_BIT 1 /* For the special negative #defines */ +#define _FP_UNUSED_BITS 1 +#define _FP_CLASS_BITS 10 /* OS Class (Windows, Linux) */ +#define _FP_VERSION_BITS 10 /* OS version (95, 98, NT, 2.4.54, 3.2) */ +#define _FP_SUBTYPE_BITS 10 /* patch level (NT SP4, SP3, ECN patch) */ +#define PF_OSFP_UNPACK(osfp, class, version, subtype) do { \ + (class) = ((osfp) >> (_FP_VERSION_BITS+_FP_SUBTYPE_BITS)) & \ + ((1 << _FP_CLASS_BITS) - 1); \ + (version) = ((osfp) >> _FP_SUBTYPE_BITS) & \ + ((1 << _FP_VERSION_BITS) - 1);\ + (subtype) = (osfp) & ((1 << _FP_SUBTYPE_BITS) - 1); \ +} while(0) +#define PF_OSFP_PACK(osfp, class, version, subtype) do { \ + (osfp) = ((class) & ((1 << _FP_CLASS_BITS) - 1)) << (_FP_VERSION_BITS \ + + _FP_SUBTYPE_BITS); \ + (osfp) |= ((version) & ((1 << _FP_VERSION_BITS) - 1)) << \ + _FP_SUBTYPE_BITS; \ + (osfp) |= (subtype) & ((1 << _FP_SUBTYPE_BITS) - 1); \ +} while(0) + +/* the fingerprint of an OSes TCP SYN packet */ +typedef u_int64_t pf_tcpopts_t; +struct pf_os_fingerprint { + SLIST_HEAD(pf_osfp_enlist, pf_osfp_entry) fp_oses; /* list of matches */ + pf_tcpopts_t fp_tcpopts; /* packed TCP options */ + u_int16_t fp_wsize; /* TCP window size */ + u_int16_t fp_psize; /* ip->ip_len */ + u_int16_t fp_mss; /* TCP MSS */ + u_int16_t fp_flags; +#define PF_OSFP_WSIZE_MOD 0x0001 /* Window modulus */ +#define PF_OSFP_WSIZE_DC 0x0002 /* Window don't care */ +#define PF_OSFP_WSIZE_MSS 0x0004 /* Window multiple of MSS */ +#define PF_OSFP_WSIZE_MTU 0x0008 /* Window multiple of MTU */ +#define PF_OSFP_PSIZE_MOD 0x0010 /* packet size modulus */ +#define PF_OSFP_PSIZE_DC 0x0020 /* packet size don't care */ +#define PF_OSFP_WSCALE 0x0040 /* TCP window scaling */ +#define PF_OSFP_WSCALE_MOD 0x0080 /* TCP window scale modulus */ +#define PF_OSFP_WSCALE_DC 0x0100 /* TCP window scale dont-care */ +#define PF_OSFP_MSS 0x0200 /* TCP MSS */ +#define PF_OSFP_MSS_MOD 0x0400 /* TCP MSS modulus */ +#define PF_OSFP_MSS_DC 0x0800 /* TCP MSS dont-care */ +#define PF_OSFP_DF 0x1000 /* IPv4 don't fragment bit */ +#define PF_OSFP_TS0 0x2000 /* Zero timestamp */ +#define PF_OSFP_INET6 0x4000 /* IPv6 */ + u_int8_t fp_optcnt; /* TCP option count */ + u_int8_t fp_wscale; /* TCP window scaling */ + u_int8_t fp_ttl; /* IPv4 TTL */ +#define PF_OSFP_MAXTTL_OFFSET 40 +/* TCP options packing */ +#define PF_OSFP_TCPOPT_NOP 0x0 /* TCP NOP option */ +#define PF_OSFP_TCPOPT_WSCALE 0x1 /* TCP window scaling option */ +#define PF_OSFP_TCPOPT_MSS 0x2 /* TCP max segment size opt */ +#define PF_OSFP_TCPOPT_SACK 0x3 /* TCP SACK OK option */ +#define PF_OSFP_TCPOPT_TS 0x4 /* TCP timestamp option */ +#define PF_OSFP_TCPOPT_BITS 3 /* bits used by each option */ +#define PF_OSFP_MAX_OPTS \ + (sizeof(((struct pf_os_fingerprint *)0)->fp_tcpopts) * 8) \ + / PF_OSFP_TCPOPT_BITS + + SLIST_ENTRY(pf_os_fingerprint) fp_next; +}; + +struct pf_osfp_ioctl { + struct pf_osfp_entry fp_os; + pf_tcpopts_t fp_tcpopts; /* packed TCP options */ + u_int16_t fp_wsize; /* TCP window size */ + u_int16_t fp_psize; /* ip->ip_len */ + u_int16_t fp_mss; /* TCP MSS */ + u_int16_t fp_flags; + u_int8_t fp_optcnt; /* TCP option count */ + u_int8_t fp_wscale; /* TCP window scaling */ + u_int8_t fp_ttl; /* IPv4 TTL */ + + int fp_getnum; /* DIOCOSFPGET number */ +}; + +struct pf_rule_actions { + int rtableid; + u_int16_t qid; + u_int16_t pqid; + u_int16_t max_mss; + u_int16_t flags; + u_int16_t delay; + u_int8_t log; + u_int8_t set_tos; + u_int8_t min_ttl; + u_int8_t set_prio[2]; + u_int8_t pad[1]; +}; + +union pf_rule_ptr { + struct pf_rule *ptr; + u_int32_t nr; +}; + +#define PF_ANCHOR_STACK_MAX 64 +#define PF_ANCHOR_NAME_SIZE 64 +#define PF_ANCHOR_MAXPATH (PATH_MAX - PF_ANCHOR_NAME_SIZE - 1) +#define PF_ANCHOR_HIWAT 512 +#define PF_OPTIMIZER_TABLE_PFX "__automatic_" + +struct pf_rule { + struct pf_rule_addr src; + struct pf_rule_addr dst; +#define PF_SKIP_IFP 0 +#define PF_SKIP_DIR 1 +#define PF_SKIP_RDOM 2 +#define PF_SKIP_AF 3 +#define PF_SKIP_PROTO 4 +#define PF_SKIP_SRC_ADDR 5 +#define PF_SKIP_DST_ADDR 6 +#define PF_SKIP_SRC_PORT 7 +#define PF_SKIP_DST_PORT 8 +#define PF_SKIP_COUNT 9 + union pf_rule_ptr skip[PF_SKIP_COUNT]; +#define PF_RULE_LABEL_SIZE 64 + char label[PF_RULE_LABEL_SIZE]; +#define PF_QNAME_SIZE 64 + char ifname[IFNAMSIZ]; + char rcv_ifname[IFNAMSIZ]; + char qname[PF_QNAME_SIZE]; + char pqname[PF_QNAME_SIZE]; +#define PF_TAG_NAME_SIZE 64 + char tagname[PF_TAG_NAME_SIZE]; + char match_tagname[PF_TAG_NAME_SIZE]; + + char overload_tblname[PF_TABLE_NAME_SIZE]; + + TAILQ_ENTRY(pf_rule) entries; + struct pf_pool nat; + struct pf_pool rdr; + struct pf_pool route; + struct pf_threshold pktrate; + + u_int64_t evaluations; + u_int64_t packets[2]; + u_int64_t bytes[2]; + + struct pfi_kif *kif; + struct pfi_kif *rcv_kif; + struct pf_anchor *anchor; + struct pfr_ktable *overload_tbl; + + pf_osfp_t os_fingerprint; + + int rtableid; + int onrdomain; + u_int32_t timeout[PFTM_MAX]; + u_int32_t states_cur; + u_int32_t states_tot; + u_int32_t max_states; + u_int32_t src_nodes; + u_int32_t max_src_nodes; + u_int32_t max_src_states; + u_int32_t max_src_conn; + struct { + u_int32_t limit; + u_int32_t seconds; + } max_src_conn_rate; + u_int32_t qid; + u_int32_t pqid; + u_int32_t rt_listid; + u_int32_t nr; + u_int32_t prob; + uid_t cuid; + pid_t cpid; + + u_int16_t return_icmp; + u_int16_t return_icmp6; + u_int16_t max_mss; + u_int16_t tag; + u_int16_t match_tag; + u_int16_t scrub_flags; + u_int16_t delay; + + struct pf_rule_uid uid; + struct pf_rule_gid gid; + + u_int32_t rule_flag; + u_int8_t action; + u_int8_t direction; + u_int8_t log; + u_int8_t logif; + u_int8_t quick; + u_int8_t ifnot; + u_int8_t match_tag_not; + +#define PF_STATE_NORMAL 0x1 +#define PF_STATE_MODULATE 0x2 +#define PF_STATE_SYNPROXY 0x3 + u_int8_t keep_state; + sa_family_t af; + u_int8_t proto; + u_int16_t type; /* aux. value 256 is legit */ + u_int16_t code; /* aux. value 256 is legit */ + u_int8_t flags; + u_int8_t flagset; + u_int8_t min_ttl; + u_int8_t allow_opts; + u_int8_t rt; + u_int8_t return_ttl; + u_int8_t tos; + u_int8_t set_tos; + u_int8_t anchor_relative; + u_int8_t anchor_wildcard; + +#define PF_FLUSH 0x01 +#define PF_FLUSH_GLOBAL 0x02 + u_int8_t flush; + u_int8_t prio; + u_int8_t set_prio[2]; + sa_family_t naf; + u_int8_t rcvifnot; + + struct { + struct pf_addr addr; + u_int16_t port; + u_int8_t type; + } divert; + + time_t exptime; +}; + +/* rule flags */ +#define PFRULE_DROP 0x0000 +#define PFRULE_RETURNRST 0x0001 +#define PFRULE_FRAGMENT 0x0002 +#define PFRULE_RETURNICMP 0x0004 +#define PFRULE_RETURN 0x0008 +#define PFRULE_NOSYNC 0x0010 +#define PFRULE_SRCTRACK 0x0020 /* track source states */ +#define PFRULE_RULESRCTRACK 0x0040 /* per rule */ +#define PFRULE_SETDELAY 0x0080 + +/* rule flags again */ +#define PFRULE_IFBOUND 0x00010000 /* if-bound */ +#define PFRULE_STATESLOPPY 0x00020000 /* sloppy state tracking */ +#define PFRULE_PFLOW 0x00040000 +#define PFRULE_ONCE 0x00100000 /* one shot rule */ +#define PFRULE_AFTO 0x00200000 /* af-to rule */ +#define PFRULE_EXPIRED 0x00400000 /* one shot rule hit by pkt */ + +#define PFSTATE_HIWAT 100000 /* default state table size */ +#define PFSTATE_ADAPT_START 60000 /* default adaptive timeout start */ +#define PFSTATE_ADAPT_END 120000 /* default adaptive timeout end */ +#define PF_PKTDELAY_MAXPKTS 10000 /* max # of pkts held in delay queue */ + +struct pf_rule_item { + SLIST_ENTRY(pf_rule_item) entry; + struct pf_rule *r; +}; + +SLIST_HEAD(pf_rule_slist, pf_rule_item); + +enum pf_sn_types { PF_SN_NONE, PF_SN_NAT, PF_SN_RDR, PF_SN_ROUTE, PF_SN_MAX }; + +struct pf_src_node { + RB_ENTRY(pf_src_node) entry; + struct pf_addr addr; + struct pf_addr raddr; + union pf_rule_ptr rule; + struct pfi_kif *kif; + u_int64_t bytes[2]; + u_int64_t packets[2]; + u_int32_t states; + u_int32_t conn; + struct pf_threshold conn_rate; + int32_t creation; + int32_t expire; + sa_family_t af; + sa_family_t naf; + u_int8_t type; +}; + +struct pf_sn_item { + SLIST_ENTRY(pf_sn_item) next; + struct pf_src_node *sn; +}; + +SLIST_HEAD(pf_sn_head, pf_sn_item); + +#define PFSNODE_HIWAT 10000 /* default source node table size */ + +struct pf_state_scrub { + struct timeval pfss_last; /* time received last packet */ + u_int32_t pfss_tsecr; /* last echoed timestamp */ + u_int32_t pfss_tsval; /* largest timestamp */ + u_int32_t pfss_tsval0; /* original timestamp */ + u_int16_t pfss_flags; +#define PFSS_TIMESTAMP 0x0001 /* modulate timestamp */ +#define PFSS_PAWS 0x0010 /* stricter PAWS checks */ +#define PFSS_PAWS_IDLED 0x0020 /* was idle too long. no PAWS */ +#define PFSS_DATA_TS 0x0040 /* timestamp on data packets */ +#define PFSS_DATA_NOTS 0x0080 /* no timestamp on data packets */ + u_int8_t pfss_ttl; /* stashed TTL */ + u_int8_t pad; + u_int32_t pfss_ts_mod; /* timestamp modulation */ +}; + +struct pf_state_host { + struct pf_addr addr; + u_int16_t port; + u_int16_t pad; +}; + +struct pf_state_peer { + struct pf_state_scrub *scrub; /* state is scrubbed */ + u_int32_t seqlo; /* Max sequence number sent */ + u_int32_t seqhi; /* Max the other end ACKd + win */ + u_int32_t seqdiff; /* Sequence number modulator */ + u_int16_t max_win; /* largest window (pre scaling) */ + u_int16_t mss; /* Maximum segment size option */ + u_int8_t state; /* active state level */ + u_int8_t wscale; /* window scaling factor */ + u_int8_t tcp_est; /* Did we reach TCPS_ESTABLISHED */ + u_int8_t pad[1]; +}; + +TAILQ_HEAD(pf_state_queue, pf_state); + +/* keep synced with struct pf_state_key, used in RB_FIND */ +struct pf_state_key_cmp { + struct pf_addr addr[2]; + u_int16_t port[2]; + u_int16_t rdomain; + u_int16_t hash; + sa_family_t af; + u_int8_t proto; +}; + +/* keep synced with struct pf_state, used in RB_FIND */ +struct pf_state_cmp { + u_int64_t id; + u_int32_t creatorid; + u_int8_t direction; + u_int8_t pad[3]; +}; + +/* struct pf_state.state_flags */ +#define PFSTATE_ALLOWOPTS 0x0001 +#define PFSTATE_SLOPPY 0x0002 +#define PFSTATE_PFLOW 0x0004 +#define PFSTATE_NOSYNC 0x0008 +#define PFSTATE_ACK 0x0010 +#define PFSTATE_NODF 0x0020 +#define PFSTATE_SETTOS 0x0040 +#define PFSTATE_RANDOMID 0x0080 +#define PFSTATE_SCRUB_TCP 0x0100 +#define PFSTATE_SETPRIO 0x0200 +#define PFSTATE_INP_UNLINKED 0x0400 +#define PFSTATE_SCRUBMASK (PFSTATE_NODF|PFSTATE_RANDOMID|PFSTATE_SCRUB_TCP) +#define PFSTATE_SETMASK (PFSTATE_SETTOS|PFSTATE_SETPRIO) + +/* + * Unified state structures for pulling states out of the kernel + * used by pfsync(4) and the pf(4) ioctl. + */ +struct pfsync_state_scrub { + u_int16_t pfss_flags; + u_int8_t pfss_ttl; /* stashed TTL */ +#define PFSYNC_SCRUB_FLAG_VALID 0x01 + u_int8_t scrub_flag; + u_int32_t pfss_ts_mod; /* timestamp modulation */ +} __packed; + +struct pfsync_state_peer { + struct pfsync_state_scrub scrub; /* state is scrubbed */ + u_int32_t seqlo; /* Max sequence number sent */ + u_int32_t seqhi; /* Max the other end ACKd + win */ + u_int32_t seqdiff; /* Sequence number modulator */ + u_int16_t max_win; /* largest window (pre scaling) */ + u_int16_t mss; /* Maximum segment size option */ + u_int8_t state; /* active state level */ + u_int8_t wscale; /* window scaling factor */ + u_int8_t pad[6]; +} __packed; + +struct pfsync_state_key { + struct pf_addr addr[2]; + u_int16_t port[2]; + u_int16_t rdomain; + sa_family_t af; + u_int8_t pad; +}; + +struct pfsync_state { + u_int64_t id; + char ifname[IFNAMSIZ]; + struct pfsync_state_key key[2]; + struct pfsync_state_peer src; + struct pfsync_state_peer dst; + struct pf_addr rt_addr; + u_int32_t rule; + u_int32_t anchor; + u_int32_t nat_rule; + u_int32_t creation; + u_int32_t expire; + u_int32_t packets[2][2]; + u_int32_t bytes[2][2]; + u_int32_t creatorid; + int32_t rtableid[2]; + u_int16_t max_mss; + sa_family_t af; + u_int8_t proto; + u_int8_t direction; + u_int8_t log; + u_int8_t rt; + u_int8_t timeout; + u_int8_t sync_flags; + u_int8_t updates; + u_int8_t min_ttl; + u_int8_t set_tos; + u_int16_t state_flags; + u_int8_t set_prio[2]; +} __packed; + +#define PFSYNC_FLAG_SRCNODE 0x04 +#define PFSYNC_FLAG_NATSRCNODE 0x08 + +#define pf_state_counter_hton(s,d) do { \ + d[0] = htonl((s>>32)&0xffffffff); \ + d[1] = htonl(s&0xffffffff); \ +} while (0) + +#define pf_state_counter_from_pfsync(s) \ + (((u_int64_t)(s[0])<<32) | (u_int64_t)(s[1])) + +#define pf_state_counter_ntoh(s,d) do { \ + d = ntohl(s[0]); \ + d = d<<32; \ + d += ntohl(s[1]); \ +} while (0) + +TAILQ_HEAD(pf_rulequeue, pf_rule); + +struct pf_anchor; + +struct pf_ruleset { + struct { + struct pf_rulequeue queues[2]; + struct { + struct pf_rulequeue *ptr; + u_int32_t rcount; + u_int32_t version; + int open; + } active, inactive; + } rules; + struct pf_anchor *anchor; + u_int32_t tticket; + int tables; + int topen; +}; + +RB_HEAD(pf_anchor_global, pf_anchor); +RB_HEAD(pf_anchor_node, pf_anchor); +struct pf_anchor { + RB_ENTRY(pf_anchor) entry_global; + RB_ENTRY(pf_anchor) entry_node; + struct pf_anchor *parent; + struct pf_anchor_node children; + char name[PF_ANCHOR_NAME_SIZE]; + char path[PATH_MAX]; + struct pf_ruleset ruleset; + int refcnt; /* anchor rules */ + int match; + struct refcnt ref; /* for transactions */ +}; +RB_PROTOTYPE(pf_anchor_global, pf_anchor, entry_global, pf_anchor_compare) +RB_PROTOTYPE(pf_anchor_node, pf_anchor, entry_node, pf_anchor_compare) + +#define PF_RESERVED_ANCHOR "_pf" + +#define PFR_TFLAG_PERSIST 0x00000001 +#define PFR_TFLAG_CONST 0x00000002 +#define PFR_TFLAG_ACTIVE 0x00000004 +#define PFR_TFLAG_INACTIVE 0x00000008 +#define PFR_TFLAG_REFERENCED 0x00000010 +#define PFR_TFLAG_REFDANCHOR 0x00000020 +#define PFR_TFLAG_COUNTERS 0x00000040 +/* Adjust masks below when adding flags. */ +#define PFR_TFLAG_USRMASK 0x00000043 +#define PFR_TFLAG_SETMASK 0x0000003C +#define PFR_TFLAG_ALLMASK 0x0000007F + +struct pfr_table { + char pfrt_anchor[PATH_MAX]; + char pfrt_name[PF_TABLE_NAME_SIZE]; + u_int32_t pfrt_flags; + u_int8_t pfrt_fback; +}; + +enum { PFR_FB_NONE, PFR_FB_MATCH, PFR_FB_ADDED, PFR_FB_DELETED, + PFR_FB_CHANGED, PFR_FB_CLEARED, PFR_FB_DUPLICATE, + PFR_FB_NOTMATCH, PFR_FB_CONFLICT, PFR_FB_NOCOUNT, PFR_FB_MAX }; + +struct pfr_addr { + union { + struct in_addr _pfra_ip4addr; + struct in6_addr _pfra_ip6addr; + } pfra_u; + char pfra_ifname[IFNAMSIZ]; + u_int32_t pfra_states; + u_int16_t pfra_weight; + u_int8_t pfra_af; + u_int8_t pfra_net; + u_int8_t pfra_not; + u_int8_t pfra_fback; + u_int8_t pfra_type; + u_int8_t pad[7]; +}; +#define pfra_ip4addr pfra_u._pfra_ip4addr +#define pfra_ip6addr pfra_u._pfra_ip6addr + +enum { PFR_DIR_IN, PFR_DIR_OUT, PFR_DIR_MAX }; +enum { PFR_OP_BLOCK, PFR_OP_MATCH, PFR_OP_PASS, PFR_OP_ADDR_MAX, + PFR_OP_TABLE_MAX }; +#define PFR_OP_XPASS PFR_OP_ADDR_MAX + +struct pfr_astats { + struct pfr_addr pfras_a; + u_int64_t pfras_packets[PFR_DIR_MAX][PFR_OP_ADDR_MAX]; + u_int64_t pfras_bytes[PFR_DIR_MAX][PFR_OP_ADDR_MAX]; + time_t pfras_tzero; +}; + +enum { PFR_REFCNT_RULE, PFR_REFCNT_ANCHOR, PFR_REFCNT_MAX }; + +struct pfr_tstats { + struct pfr_table pfrts_t; + u_int64_t pfrts_packets[PFR_DIR_MAX][PFR_OP_TABLE_MAX]; + u_int64_t pfrts_bytes[PFR_DIR_MAX][PFR_OP_TABLE_MAX]; + u_int64_t pfrts_match; + u_int64_t pfrts_nomatch; + time_t pfrts_tzero; + int pfrts_cnt; + int pfrts_refcnt[PFR_REFCNT_MAX]; +}; +#define pfrts_name pfrts_t.pfrt_name +#define pfrts_flags pfrts_t.pfrt_flags + +struct pfr_kcounters { + u_int64_t pfrkc_packets[PFR_DIR_MAX][PFR_OP_ADDR_MAX]; + u_int64_t pfrkc_bytes[PFR_DIR_MAX][PFR_OP_ADDR_MAX]; + u_int64_t states; +}; + +/* + * XXX ip_ipsp.h's sockaddr_union should be converted to sockaddr * + * passing with correct sa_len, then a good approach for cleaning this + * will become more clear. + */ +union pfsockaddr_union { + struct sockaddr sa; + struct sockaddr_in sin; + struct sockaddr_in6 sin6; +}; + +SLIST_HEAD(pfr_kentryworkq, pfr_kentry); +struct _pfr_kentry { + struct radix_node _pfrke_node[2]; + union pfsockaddr_union _pfrke_sa; + SLIST_ENTRY(pfr_kentry) _pfrke_workq; + SLIST_ENTRY(pfr_kentry) _pfrke_ioq; + struct pfr_kcounters *_pfrke_counters; + time_t _pfrke_tzero; + u_int8_t _pfrke_af; + u_int8_t _pfrke_net; + u_int8_t _pfrke_flags; + u_int8_t _pfrke_type; + u_int8_t _pfrke_fb; +}; +#define PFRKE_FLAG_NOT 0x01 +#define PFRKE_FLAG_MARK 0x02 + +/* pfrke_type */ +enum { PFRKE_PLAIN, PFRKE_ROUTE, PFRKE_COST, PFRKE_MAX }; + +struct pfr_kentry { + union { + struct _pfr_kentry _ke; + } u; +}; +#define pfrke_node u._ke._pfrke_node +#define pfrke_sa u._ke._pfrke_sa +#define pfrke_workq u._ke._pfrke_workq +#define pfrke_ioq u._ke._pfrke_ioq +#define pfrke_counters u._ke._pfrke_counters +#define pfrke_tzero u._ke._pfrke_tzero +#define pfrke_af u._ke._pfrke_af +#define pfrke_net u._ke._pfrke_net +#define pfrke_flags u._ke._pfrke_flags +#define pfrke_type u._ke._pfrke_type +#define pfrke_fb u._ke._pfrke_fb + +struct pfr_kentry_route { + union { + struct _pfr_kentry _ke; + } u; + + struct pfi_kif *kif; + char ifname[IFNAMSIZ]; +}; + +struct pfr_kentry_cost { + union { + struct _pfr_kentry _ke; + } u; + + struct pfi_kif *kif; + char ifname[IFNAMSIZ]; + /* Above overlaps with pfr_kentry route */ + + u_int16_t weight; +}; + +struct pfr_kentry_all { + union { + struct _pfr_kentry _ke; + struct pfr_kentry_route kr; + struct pfr_kentry_cost kc; + } u; +}; +#define pfrke_rkif u.kr.kif +#define pfrke_rifname u.kr.ifname + +SLIST_HEAD(pfr_ktableworkq, pfr_ktable); +RB_HEAD(pfr_ktablehead, pfr_ktable); +struct pfr_ktable { + struct pfr_tstats pfrkt_ts; + RB_ENTRY(pfr_ktable) pfrkt_tree; + SLIST_ENTRY(pfr_ktable) pfrkt_workq; + struct radix_node_head *pfrkt_ip4; + struct radix_node_head *pfrkt_ip6; + struct pfr_ktable *pfrkt_shadow; + struct pfr_ktable *pfrkt_root; + struct pf_ruleset *pfrkt_rs; + long pfrkt_larg; + int pfrkt_nflags; + u_int64_t pfrkt_refcntcost; + u_int16_t pfrkt_gcdweight; + u_int16_t pfrkt_maxweight; +}; +#define pfrkt_t pfrkt_ts.pfrts_t +#define pfrkt_name pfrkt_t.pfrt_name +#define pfrkt_anchor pfrkt_t.pfrt_anchor +#define pfrkt_ruleset pfrkt_t.pfrt_ruleset +#define pfrkt_flags pfrkt_t.pfrt_flags +#define pfrkt_cnt pfrkt_ts.pfrts_cnt +#define pfrkt_refcnt pfrkt_ts.pfrts_refcnt +#define pfrkt_packets pfrkt_ts.pfrts_packets +#define pfrkt_bytes pfrkt_ts.pfrts_bytes +#define pfrkt_match pfrkt_ts.pfrts_match +#define pfrkt_nomatch pfrkt_ts.pfrts_nomatch +#define pfrkt_tzero pfrkt_ts.pfrts_tzero + +RB_HEAD(pfi_ifhead, pfi_kif); + +/* state tables */ +extern struct pf_state_tree pf_statetbl; + +/* keep synced with pfi_kif, used in RB_FIND */ +struct pfi_kif_cmp { + char pfik_name[IFNAMSIZ]; +}; + +struct ifnet; +struct ifg_group; + +struct pfi_kif { + char pfik_name[IFNAMSIZ]; + RB_ENTRY(pfi_kif) pfik_tree; + u_int64_t pfik_packets[2][2][2]; + u_int64_t pfik_bytes[2][2][2]; + time_t pfik_tzero; + int pfik_flags; + int pfik_flags_new; + void *pfik_ah_cookie; + struct ifnet *pfik_ifp; + struct ifg_group *pfik_group; + int pfik_states; + int pfik_rules; + int pfik_routes; + int pfik_srcnodes; + int pfik_flagrefs; + TAILQ_HEAD(, pfi_dynaddr) pfik_dynaddrs; +}; + +enum pfi_kif_refs { + PFI_KIF_REF_NONE, + PFI_KIF_REF_STATE, + PFI_KIF_REF_RULE, + PFI_KIF_REF_ROUTE, + PFI_KIF_REF_SRCNODE, + PFI_KIF_REF_FLAG +}; + +#define PFI_IFLAG_SKIP 0x0100 /* skip filtering on interface */ +#define PFI_IFLAG_ANY 0x0200 /* match any non-loopback interface */ + +/* flags for RDR options */ +#define PF_DPORT_RANGE 0x01 /* Dest port uses range */ +#define PF_RPORT_RANGE 0x02 /* RDR'ed port uses range */ + +/* Reasons code for passing/dropping a packet */ +#define PFRES_MATCH 0 /* Explicit match of a rule */ +#define PFRES_BADOFF 1 /* Bad offset for pull_hdr */ +#define PFRES_FRAG 2 /* Dropping following fragment */ +#define PFRES_SHORT 3 /* Dropping short packet */ +#define PFRES_NORM 4 /* Dropping by normalizer */ +#define PFRES_MEMORY 5 /* Dropped due to lacking mem */ +#define PFRES_TS 6 /* Bad TCP Timestamp (RFC1323) */ +#define PFRES_CONGEST 7 /* Congestion */ +#define PFRES_IPOPTIONS 8 /* IP option */ +#define PFRES_PROTCKSUM 9 /* Protocol checksum invalid */ +#define PFRES_BADSTATE 10 /* State mismatch */ +#define PFRES_STATEINS 11 /* State insertion failure */ +#define PFRES_MAXSTATES 12 /* State limit */ +#define PFRES_SRCLIMIT 13 /* Source node/conn limit */ +#define PFRES_SYNPROXY 14 /* SYN proxy */ +#define PFRES_TRANSLATE 15 /* No translation address available */ +#define PFRES_NOROUTE 16 /* No route found for PBR action */ +#define PFRES_MAX 17 /* total+1 */ + +#define PFRES_NAMES { \ + "match", \ + "bad-offset", \ + "fragment", \ + "short", \ + "normalize", \ + "memory", \ + "bad-timestamp", \ + "congestion", \ + "ip-option", \ + "proto-cksum", \ + "state-mismatch", \ + "state-insert", \ + "state-limit", \ + "src-limit", \ + "synproxy", \ + "translate", \ + "no-route", \ + NULL \ +} + +/* Counters for other things we want to keep track of */ +#define LCNT_STATES 0 /* states */ +#define LCNT_SRCSTATES 1 /* max-src-states */ +#define LCNT_SRCNODES 2 /* max-src-nodes */ +#define LCNT_SRCCONN 3 /* max-src-conn */ +#define LCNT_SRCCONNRATE 4 /* max-src-conn-rate */ +#define LCNT_OVERLOAD_TABLE 5 /* entry added to overload table */ +#define LCNT_OVERLOAD_FLUSH 6 /* state entries flushed */ +#define LCNT_SYNFLOODS 7 /* synfloods detected */ +#define LCNT_SYNCOOKIES_SENT 8 /* syncookies sent */ +#define LCNT_SYNCOOKIES_VALID 9 /* syncookies validated */ +#define LCNT_MAX 10 /* total+1 */ + +#define LCNT_NAMES { \ + "max states per rule", \ + "max-src-states", \ + "max-src-nodes", \ + "max-src-conn", \ + "max-src-conn-rate", \ + "overload table insertion", \ + "overload flush states", \ + "synfloods detected", \ + "syncookies sent", \ + "syncookies validated", \ + NULL \ +} + +/* UDP state enumeration */ +#define PFUDPS_NO_TRAFFIC 0 +#define PFUDPS_SINGLE 1 +#define PFUDPS_MULTIPLE 2 + +#define PFUDPS_NSTATES 3 /* number of state levels */ + +#define PFUDPS_NAMES { \ + "NO_TRAFFIC", \ + "SINGLE", \ + "MULTIPLE", \ + NULL \ +} + +/* Other protocol state enumeration */ +#define PFOTHERS_NO_TRAFFIC 0 +#define PFOTHERS_SINGLE 1 +#define PFOTHERS_MULTIPLE 2 + +#define PFOTHERS_NSTATES 3 /* number of state levels */ + +#define PFOTHERS_NAMES { \ + "NO_TRAFFIC", \ + "SINGLE", \ + "MULTIPLE", \ + NULL \ +} + +#define FCNT_STATE_SEARCH 0 +#define FCNT_STATE_INSERT 1 +#define FCNT_STATE_REMOVALS 2 +#define FCNT_MAX 3 + +#define SCNT_SRC_NODE_SEARCH 0 +#define SCNT_SRC_NODE_INSERT 1 +#define SCNT_SRC_NODE_REMOVALS 2 +#define SCNT_MAX 3 + +#define NCNT_FRAG_SEARCH 0 +#define NCNT_FRAG_INSERT 1 +#define NCNT_FRAG_REMOVALS 2 +#define NCNT_MAX 3 + +#define REASON_SET(a, x) \ + do { \ + if ((void *)(a) != NULL) { \ + *(a) = (x); \ + if (x < PFRES_MAX) \ + pf_status.counters[x]++; \ + } \ + } while (0) + +struct pf_status { + u_int64_t counters[PFRES_MAX]; + u_int64_t lcounters[LCNT_MAX]; /* limit counters */ + u_int64_t fcounters[FCNT_MAX]; + u_int64_t scounters[SCNT_MAX]; + u_int64_t ncounters[NCNT_MAX]; + u_int64_t pcounters[2][2][3]; + u_int64_t bcounters[2][2]; + u_int64_t stateid; + u_int64_t syncookies_inflight[2]; /* unACKed SYNcookies */ + time_t since; + u_int32_t running; + u_int32_t states; + u_int32_t states_halfopen; + u_int32_t src_nodes; + u_int32_t fragments; + u_int32_t debug; + u_int32_t hostid; + u_int32_t reass; /* reassembly */ + u_int8_t syncookies_active; + u_int8_t syncookies_mode; /* never/always/adaptive */ + u_int8_t pad[2]; + char ifname[IFNAMSIZ]; + u_int8_t pf_chksum[PF_MD5_DIGEST_LENGTH]; +}; + +#define PF_REASS_ENABLED 0x01 +#define PF_REASS_NODF 0x02 + +#define PF_SYNCOOKIES_NEVER 0 +#define PF_SYNCOOKIES_ALWAYS 1 +#define PF_SYNCOOKIES_ADAPTIVE 2 +#define PF_SYNCOOKIES_MODE_MAX PF_SYNCOOKIES_ADAPTIVE + +#define PF_SYNCOOKIES_HIWATPCT 25 +#define PF_SYNCOOKIES_LOWATPCT PF_SYNCOOKIES_HIWATPCT/2 + +#define PF_PRIO_ZERO 0xff /* match "prio 0" packets */ + +struct pf_queue_bwspec { + uint64_t absolute; + u_int percent; +}; + +struct pf_queue_scspec { + struct pf_queue_bwspec m1; + struct pf_queue_bwspec m2; + u_int d; +}; + +struct pf_queue_fqspec { + u_int flows; + u_int quantum; + u_int target; + u_int interval; +}; + +struct pf_queuespec { + TAILQ_ENTRY(pf_queuespec) entries; + char qname[PF_QNAME_SIZE]; + char parent[PF_QNAME_SIZE]; + char ifname[IFNAMSIZ]; + struct pf_queue_scspec realtime; + struct pf_queue_scspec linkshare; + struct pf_queue_scspec upperlimit; + struct pf_queue_fqspec flowqueue; + struct pfi_kif *kif; + u_int flags; + u_int qlimit; + u_int32_t qid; + u_int32_t parent_qid; +}; + +#define PFQS_FLOWQUEUE 0x0001 +#define PFQS_ROOTCLASS 0x0002 +#define PFQS_DEFAULT 0x1000 /* maps to HFSC_DEFAULTCLASS */ + +struct priq_opts { + int flags; +}; + +struct hfsc_opts { + /* real-time service curve */ + u_int rtsc_m1; /* slope of the 1st segment in bps */ + u_int rtsc_d; /* the x-projection of m1 in msec */ + u_int rtsc_m2; /* slope of the 2nd segment in bps */ + /* link-sharing service curve */ + u_int lssc_m1; + u_int lssc_d; + u_int lssc_m2; + /* upper-limit service curve */ + u_int ulsc_m1; + u_int ulsc_d; + u_int ulsc_m2; + int flags; +}; + +struct pfq_ops { + void * (*pfq_alloc)(struct ifnet *); + int (*pfq_addqueue)(void *, struct pf_queuespec *); + void (*pfq_free)(void *); + int (*pfq_qstats)(struct pf_queuespec *, void *, int *); + /* Queue manager ops */ + unsigned int (*pfq_qlength)(void *); + struct mbuf * (*pfq_enqueue)(void *, struct mbuf *); + struct mbuf * (*pfq_deq_begin)(void *, void **, struct mbuf_list *); + void (*pfq_deq_commit)(void *, struct mbuf *, void *); + void (*pfq_purge)(void *, struct mbuf_list *); +}; + +struct pf_tagname { + TAILQ_ENTRY(pf_tagname) entries; + char name[PF_TAG_NAME_SIZE]; + u_int16_t tag; + int ref; +}; + +struct pf_divert { + struct pf_addr addr; + u_int16_t port; + u_int16_t rdomain; + u_int8_t type; +}; + +enum pf_divert_types { + PF_DIVERT_NONE, + PF_DIVERT_TO, + PF_DIVERT_REPLY, + PF_DIVERT_PACKET +}; + +struct pf_pktdelay { + struct timeout to; + struct mbuf *m; + u_int ifidx; +}; + +/* Fragment entries reference mbuf clusters, so base the default on that. */ +#define PFFRAG_FRENT_HIWAT (NMBCLUSTERS / 16) /* Number of entries */ +#define PFFRAG_FRAG_HIWAT (NMBCLUSTERS / 32) /* Number of packets */ + +#define PFR_KTABLE_HIWAT 1000 /* Number of tables */ +#define PFR_KENTRY_HIWAT 200000 /* Number of table entries */ +#define PFR_KENTRY_HIWAT_SMALL 100000 /* Number of entries for tiny hosts */ + +/* + * ioctl parameter structures + */ + +struct pfioc_rule { + u_int32_t action; + u_int32_t ticket; + u_int32_t nr; + char anchor[PATH_MAX]; + char anchor_call[PATH_MAX]; + struct pf_rule rule; +}; + +struct pfioc_natlook { + struct pf_addr saddr; + struct pf_addr daddr; + struct pf_addr rsaddr; + struct pf_addr rdaddr; + u_int16_t rdomain; + u_int16_t rrdomain; + u_int16_t sport; + u_int16_t dport; + u_int16_t rsport; + u_int16_t rdport; + sa_family_t af; + u_int8_t proto; + u_int8_t direction; +}; + +struct pfioc_state { + struct pfsync_state state; +}; + +struct pfioc_src_node_kill { + sa_family_t psnk_af; + struct pf_rule_addr psnk_src; + struct pf_rule_addr psnk_dst; + u_int psnk_killed; +}; + +struct pfioc_state_kill { + struct pf_state_cmp psk_pfcmp; + sa_family_t psk_af; + int psk_proto; + struct pf_rule_addr psk_src; + struct pf_rule_addr psk_dst; + char psk_ifname[IFNAMSIZ]; + char psk_label[PF_RULE_LABEL_SIZE]; + u_int psk_killed; + u_int16_t psk_rdomain; +}; + +struct pfioc_states { + size_t ps_len; + union { + caddr_t psu_buf; + struct pfsync_state *psu_states; + } ps_u; +#define ps_buf ps_u.psu_buf +#define ps_states ps_u.psu_states +}; + +struct pfioc_src_nodes { + size_t psn_len; + union { + caddr_t psu_buf; + struct pf_src_node *psu_src_nodes; + } psn_u; +#define psn_buf psn_u.psu_buf +#define psn_src_nodes psn_u.psu_src_nodes +}; + +struct pfioc_tm { + int timeout; + int seconds; +}; + +struct pfioc_limit { + int index; + unsigned limit; +}; + +struct pfioc_ruleset { + u_int32_t nr; + char path[PATH_MAX]; + char name[PF_ANCHOR_NAME_SIZE]; +}; + +struct pfioc_trans { + int size; /* number of elements */ + int esize; /* size of each element in bytes */ + struct pfioc_trans_e { + int type; + char anchor[PATH_MAX]; + u_int32_t ticket; + } *array; +}; + +struct pfioc_queue { + u_int32_t ticket; + u_int nr; + struct pf_queuespec queue; +}; + +struct pfioc_qstats { + u_int32_t ticket; + u_int32_t nr; + struct pf_queuespec queue; + void *buf; + int nbytes; +}; + +#define PFR_FLAG_DUMMY 0x00000002 +#define PFR_FLAG_FEEDBACK 0x00000004 +#define PFR_FLAG_CLSTATS 0x00000008 +#define PFR_FLAG_ADDRSTOO 0x00000010 +#define PFR_FLAG_REPLACE 0x00000020 +#define PFR_FLAG_ALLRSETS 0x00000040 +#define PFR_FLAG_ALLMASK 0x0000007F +#ifdef _KERNEL +#define PFR_FLAG_USERIOCTL 0x10000000 +#endif + +struct pfioc_table { + struct pfr_table pfrio_table; + void *pfrio_buffer; + int pfrio_esize; + int pfrio_size; + int pfrio_size2; + int pfrio_nadd; + int pfrio_ndel; + int pfrio_nchange; + int pfrio_flags; + u_int32_t pfrio_ticket; +}; +#define pfrio_exists pfrio_nadd +#define pfrio_nzero pfrio_nadd +#define pfrio_nmatch pfrio_nadd +#define pfrio_naddr pfrio_size2 +#define pfrio_setflag pfrio_size2 +#define pfrio_clrflag pfrio_nadd + +struct pfioc_iface { + char pfiio_name[IFNAMSIZ]; + void *pfiio_buffer; + int pfiio_esize; + int pfiio_size; + int pfiio_nzero; + int pfiio_flags; +}; + +struct pfioc_synflwats { + u_int32_t hiwat; + u_int32_t lowat; +}; + +/* + * ioctl operations + */ + +#define DIOCSTART _IO ('D', 1) +#define DIOCSTOP _IO ('D', 2) +#define DIOCADDRULE _IOWR('D', 4, struct pfioc_rule) +#define DIOCGETRULES _IOWR('D', 6, struct pfioc_rule) +#define DIOCGETRULE _IOWR('D', 7, struct pfioc_rule) +/* cut 8 - 17 */ +#define DIOCCLRSTATES _IOWR('D', 18, struct pfioc_state_kill) +#define DIOCGETSTATE _IOWR('D', 19, struct pfioc_state) +#define DIOCSETSTATUSIF _IOWR('D', 20, struct pfioc_iface) +#define DIOCGETSTATUS _IOWR('D', 21, struct pf_status) +#define DIOCCLRSTATUS _IOWR('D', 22, struct pfioc_iface) +#define DIOCNATLOOK _IOWR('D', 23, struct pfioc_natlook) +#define DIOCSETDEBUG _IOWR('D', 24, u_int32_t) +#define DIOCGETSTATES _IOWR('D', 25, struct pfioc_states) +#define DIOCCHANGERULE _IOWR('D', 26, struct pfioc_rule) +/* cut 27 - 28 */ +#define DIOCSETTIMEOUT _IOWR('D', 29, struct pfioc_tm) +#define DIOCGETTIMEOUT _IOWR('D', 30, struct pfioc_tm) +#define DIOCADDSTATE _IOWR('D', 37, struct pfioc_state) +/* cut 38 */ +#define DIOCGETLIMIT _IOWR('D', 39, struct pfioc_limit) +#define DIOCSETLIMIT _IOWR('D', 40, struct pfioc_limit) +#define DIOCKILLSTATES _IOWR('D', 41, struct pfioc_state_kill) +/* cut 42 - 57 */ +#define DIOCGETRULESETS _IOWR('D', 58, struct pfioc_ruleset) +#define DIOCGETRULESET _IOWR('D', 59, struct pfioc_ruleset) +#define DIOCRCLRTABLES _IOWR('D', 60, struct pfioc_table) +#define DIOCRADDTABLES _IOWR('D', 61, struct pfioc_table) +#define DIOCRDELTABLES _IOWR('D', 62, struct pfioc_table) +#define DIOCRGETTABLES _IOWR('D', 63, struct pfioc_table) +#define DIOCRGETTSTATS _IOWR('D', 64, struct pfioc_table) +#define DIOCRCLRTSTATS _IOWR('D', 65, struct pfioc_table) +#define DIOCRCLRADDRS _IOWR('D', 66, struct pfioc_table) +#define DIOCRADDADDRS _IOWR('D', 67, struct pfioc_table) +#define DIOCRDELADDRS _IOWR('D', 68, struct pfioc_table) +#define DIOCRSETADDRS _IOWR('D', 69, struct pfioc_table) +#define DIOCRGETADDRS _IOWR('D', 70, struct pfioc_table) +#define DIOCRGETASTATS _IOWR('D', 71, struct pfioc_table) +#define DIOCRCLRASTATS _IOWR('D', 72, struct pfioc_table) +#define DIOCRTSTADDRS _IOWR('D', 73, struct pfioc_table) +#define DIOCRSETTFLAGS _IOWR('D', 74, struct pfioc_table) +#define DIOCRINADEFINE _IOWR('D', 77, struct pfioc_table) +#define DIOCOSFPFLUSH _IO('D', 78) +#define DIOCOSFPADD _IOWR('D', 79, struct pf_osfp_ioctl) +#define DIOCOSFPGET _IOWR('D', 80, struct pf_osfp_ioctl) +#define DIOCXBEGIN _IOWR('D', 81, struct pfioc_trans) +#define DIOCXCOMMIT _IOWR('D', 82, struct pfioc_trans) +#define DIOCXROLLBACK _IOWR('D', 83, struct pfioc_trans) +#define DIOCGETSRCNODES _IOWR('D', 84, struct pfioc_src_nodes) +#define DIOCCLRSRCNODES _IO('D', 85) +#define DIOCSETHOSTID _IOWR('D', 86, u_int32_t) +#define DIOCIGETIFACES _IOWR('D', 87, struct pfioc_iface) +#define DIOCSETIFFLAG _IOWR('D', 89, struct pfioc_iface) +#define DIOCCLRIFFLAG _IOWR('D', 90, struct pfioc_iface) +#define DIOCKILLSRCNODES _IOWR('D', 91, struct pfioc_src_node_kill) +#define DIOCSETREASS _IOWR('D', 92, u_int32_t) +#define DIOCADDQUEUE _IOWR('D', 93, struct pfioc_queue) +#define DIOCGETQUEUES _IOWR('D', 94, struct pfioc_queue) +#define DIOCGETQUEUE _IOWR('D', 95, struct pfioc_queue) +#define DIOCGETQSTATS _IOWR('D', 96, struct pfioc_qstats) +#define DIOCSETSYNFLWATS _IOWR('D', 97, struct pfioc_synflwats) +#define DIOCSETSYNCOOKIES _IOWR('D', 98, u_int8_t) +#define DIOCGETSYNFLWATS _IOWR('D', 99, struct pfioc_synflwats) +#define DIOCXEND _IOWR('D', 100, u_int32_t) + +#ifdef _KERNEL + +struct pf_pdesc; + +RB_HEAD(pf_src_tree, pf_src_node); +RB_PROTOTYPE(pf_src_tree, pf_src_node, entry, pf_src_compare); +extern struct pf_src_tree tree_src_tracking; + +extern struct pf_state_list pf_state_list; + +TAILQ_HEAD(pf_queuehead, pf_queuespec); +extern struct pf_queuehead pf_queues[2]; +extern struct pf_queuehead *pf_queues_active, *pf_queues_inactive; + +extern struct pool pf_src_tree_pl, pf_sn_item_pl, pf_rule_pl; +extern struct pool pf_state_pl, pf_state_key_pl, pf_state_item_pl, + pf_rule_item_pl, pf_queue_pl, + pf_pktdelay_pl, pf_anchor_pl; +extern struct pool pf_state_scrub_pl; +extern struct pf_rule pf_default_rule; + +extern int pf_tbladdr_setup(struct pf_ruleset *, + struct pf_addr_wrap *, int); +extern void pf_tbladdr_remove(struct pf_addr_wrap *); +extern void pf_tbladdr_copyout(struct pf_addr_wrap *); +extern void pf_calc_skip_steps(struct pf_rulequeue *); +extern void pf_purge_expired_src_nodes(void); +extern void pf_remove_state(struct pf_state *); +extern void pf_remove_divert_state(struct inpcb *); +extern void pf_free_state(struct pf_state *); +int pf_insert_src_node(struct pf_src_node **, + struct pf_rule *, enum pf_sn_types, + sa_family_t, struct pf_addr *, + struct pf_addr *, struct pfi_kif *); +void pf_remove_src_node(struct pf_src_node *); +struct pf_src_node *pf_get_src_node(struct pf_state *, + enum pf_sn_types); +void pf_src_tree_remove_state(struct pf_state *); +void pf_state_rm_src_node(struct pf_state *, + struct pf_src_node *); + +extern struct pf_state *pf_find_state_byid(struct pf_state_cmp *); +extern struct pf_state *pf_find_state_all(struct pf_state_key_cmp *, + u_int, int *); +extern void pf_state_export(struct pfsync_state *, + struct pf_state *); +int pf_state_import(const struct pfsync_state *, + int); +int pf_state_alloc_scrub_memory( + const struct pfsync_state_peer *, + struct pf_state_peer *); +extern void pf_print_state(struct pf_state *); +extern void pf_print_flags(u_int8_t); +extern void pf_addrcpy(struct pf_addr *, struct pf_addr *, + sa_family_t); +extern void pf_cksum_fixup(u_int16_t *, u_int16_t, + u_int16_t, u_int8_t); +void pf_rm_rule(struct pf_rulequeue *, + struct pf_rule *); +struct pf_divert *pf_find_divert(struct mbuf *); +int pf_setup_pdesc(struct pf_pdesc *, sa_family_t, + int, struct pfi_kif *, struct mbuf *, + u_short *); + +int pf_test(sa_family_t, int, struct ifnet *, struct mbuf **); + +void pf_poolmask(struct pf_addr *, struct pf_addr*, + struct pf_addr *, struct pf_addr *, sa_family_t); +void pf_addr_inc(struct pf_addr *, sa_family_t); + +void *pf_pull_hdr(struct mbuf *, int, void *, int, u_short *, sa_family_t); +#define PF_HI (true) +#define PF_LO (!PF_HI) +#define PF_ALGNMNT(off) (((off) % 2) == 0 ? PF_HI : PF_LO) +int pf_patch_8(struct pf_pdesc *, u_int8_t *, u_int8_t, bool); +int pf_patch_16(struct pf_pdesc *, u_int16_t *, u_int16_t); +int pf_patch_16_unaligned(struct pf_pdesc *, void *, u_int16_t, bool); +int pf_patch_32(struct pf_pdesc *, u_int32_t *, u_int32_t); +int pf_patch_32_unaligned(struct pf_pdesc *, void *, u_int32_t, bool); +int pflog_packet(struct pf_pdesc *, u_int8_t, struct pf_rule *, + struct pf_rule *, struct pf_ruleset *, struct pf_rule *); +int pf_match_addr(u_int8_t, struct pf_addr *, struct pf_addr *, + struct pf_addr *, sa_family_t); +int pf_match_addr_range(struct pf_addr *, struct pf_addr *, + struct pf_addr *, sa_family_t); +int pf_match(u_int8_t, u_int32_t, u_int32_t, u_int32_t); +int pf_match_port(u_int8_t, u_int16_t, u_int16_t, u_int16_t); +int pf_match_uid(u_int8_t, uid_t, uid_t, uid_t); +int pf_match_gid(u_int8_t, gid_t, gid_t, gid_t); + +struct pf_state_scrub * + pf_state_scrub_get(void); +void pf_state_scrub_put(struct pf_state_scrub *); + +int pf_refragment6(struct mbuf **, struct m_tag *mtag, + struct sockaddr_in6 *, struct ifnet *, struct rtentry *); +void pf_normalize_init(void); +int pf_normalize_ip(struct pf_pdesc *, u_short *); +int pf_normalize_ip6(struct pf_pdesc *, u_short *); +int pf_normalize_tcp(struct pf_pdesc *); +void pf_normalize_tcp_cleanup(struct pf_state *); +int pf_normalize_tcp_init(struct pf_pdesc *, struct pf_state_peer *); +int pf_normalize_tcp_alloc(struct pf_state_peer *); +int pf_normalize_tcp_stateful(struct pf_pdesc *, u_short *, + struct pf_state *, struct pf_state_peer *, struct pf_state_peer *, + int *); +int pf_normalize_mss(struct pf_pdesc *, u_int16_t); +void pf_scrub(struct mbuf *, u_int16_t, sa_family_t, u_int8_t, u_int8_t); +void pf_purge_expired_fragments(void); +int pf_routable(struct pf_addr *addr, sa_family_t af, struct pfi_kif *, + int); +int pf_rtlabel_match(struct pf_addr *, sa_family_t, struct pf_addr_wrap *, + int); +int pf_socket_lookup(struct pf_pdesc *); +struct pf_state_key *pf_alloc_state_key(int); +int pf_ouraddr(struct mbuf *); +void pf_pkt_addr_changed(struct mbuf *); +struct inpcb *pf_inp_lookup(struct mbuf *); +void pf_inp_link(struct mbuf *, struct inpcb *); +void pf_inp_unlink(struct inpcb *); +int pf_translate(struct pf_pdesc *, struct pf_addr *, u_int16_t, + struct pf_addr *, u_int16_t, u_int16_t, int); +int pf_translate_af(struct pf_pdesc *); +void pf_route(struct pf_pdesc *, struct pf_state *); +void pf_route6(struct pf_pdesc *, struct pf_state *); +void pf_init_threshold(struct pf_threshold *, u_int32_t, u_int32_t); +int pf_delay_pkt(struct mbuf *, u_int); + +void pfr_initialize(void); +int pfr_match_addr(struct pfr_ktable *, struct pf_addr *, sa_family_t); +void pfr_update_stats(struct pfr_ktable *, struct pf_addr *, + struct pf_pdesc *, int, int); +int pfr_pool_get(struct pf_pool *, struct pf_addr **, + struct pf_addr **, sa_family_t); +int pfr_states_increase(struct pfr_ktable *, struct pf_addr *, int); +int pfr_states_decrease(struct pfr_ktable *, struct pf_addr *, int); +struct pfr_kentry * + pfr_kentry_byaddr(struct pfr_ktable *, struct pf_addr *, sa_family_t, + int); +void pfr_dynaddr_update(struct pfr_ktable *, struct pfi_dynaddr *); +struct pfr_ktable * + pfr_attach_table(struct pf_ruleset *, char *, int); +void pfr_detach_table(struct pfr_ktable *); +int pfr_clr_tables(struct pfr_table *, int *, int); +int pfr_add_tables(struct pfr_table *, int, int *, int); +int pfr_del_tables(struct pfr_table *, int, int *, int); +int pfr_get_tables(struct pfr_table *, struct pfr_table *, int *, int); +int pfr_get_tstats(struct pfr_table *, struct pfr_tstats *, int *, int); +int pfr_clr_tstats(struct pfr_table *, int, int *, int); +int pfr_set_tflags(struct pfr_table *, int, int, int, int *, int *, int); +int pfr_clr_addrs(struct pfr_table *, int *, int); +int pfr_insert_kentry(struct pfr_ktable *, struct pfr_addr *, time_t); +int pfr_add_addrs(struct pfr_table *, struct pfr_addr *, int, int *, + int); +int pfr_del_addrs(struct pfr_table *, struct pfr_addr *, int, int *, + int); +int pfr_set_addrs(struct pfr_table *, struct pfr_addr *, int, int *, + int *, int *, int *, int, u_int32_t); +int pfr_get_addrs(struct pfr_table *, struct pfr_addr *, int *, int); +int pfr_get_astats(struct pfr_table *, struct pfr_astats *, int *, int); +int pfr_clr_astats(struct pfr_table *, struct pfr_addr *, int, int *, + int); +int pfr_tst_addrs(struct pfr_table *, struct pfr_addr *, int, int *, + int); +int pfr_ina_begin(struct pfr_table *, u_int32_t *, int *, int); +int pfr_ina_rollback(struct pfr_table *, u_int32_t, int *, int); +int pfr_ina_commit(struct pfr_table *, u_int32_t, int *, int *, int); +int pfr_ina_define(struct pfr_table *, struct pfr_addr *, int, int *, + int *, u_int32_t, int); +struct pfr_ktable + *pfr_ktable_select_active(struct pfr_ktable *); + +extern struct pfi_kif *pfi_all; + +void pfi_initialize(void); +struct pfi_kif *pfi_kif_alloc(const char *, int); +void pfi_kif_free(struct pfi_kif *); +struct pfi_kif *pfi_kif_find(const char *); +struct pfi_kif *pfi_kif_get(const char *, struct pfi_kif **); +void pfi_kif_ref(struct pfi_kif *, enum pfi_kif_refs); +void pfi_kif_unref(struct pfi_kif *, enum pfi_kif_refs); +int pfi_kif_match(struct pfi_kif *, struct pfi_kif *); +void pfi_attach_ifnet(struct ifnet *); +void pfi_detach_ifnet(struct ifnet *); +void pfi_attach_ifgroup(struct ifg_group *); +void pfi_detach_ifgroup(struct ifg_group *); +void pfi_group_addmember(const char *); +void pfi_group_delmember(const char *); +int pfi_match_addr(struct pfi_dynaddr *, struct pf_addr *, + sa_family_t); +int pfi_dynaddr_setup(struct pf_addr_wrap *, sa_family_t, int); +void pfi_dynaddr_remove(struct pf_addr_wrap *); +void pfi_dynaddr_copyout(struct pf_addr_wrap *); +void pfi_update_status(const char *, struct pf_status *); +void pfi_get_ifaces(const char *, struct pfi_kif *, int *); +int pfi_set_flags(const char *, int); +int pfi_clear_flags(const char *, int); +void pfi_xcommit(void); + +int pf_match_tag(struct mbuf *, struct pf_rule *, int *); +u_int16_t pf_tagname2tag(char *, int); +void pf_tag2tagname(u_int16_t, char *); +void pf_tag_ref(u_int16_t); +void pf_tag_unref(u_int16_t); +void pf_tag_packet(struct mbuf *, int, int); +int pf_addr_compare(const struct pf_addr *, + const struct pf_addr *, sa_family_t); + +const struct pfq_ops + *pf_queue_manager(struct pf_queuespec *); + +extern struct pf_status pf_status; +extern struct pool pf_frent_pl, pf_frag_pl; + +/* + * Protection/ownership of pf_pool_limit: + * I immutable after pfattach() + * p pf_lock + */ + +struct pf_pool_limit { + void *pp; /* [I] */ + unsigned limit; /* [p] */ + unsigned limit_new; /* [p] */ +}; +extern struct pf_pool_limit pf_pool_limits[PF_LIMIT_MAX]; + +#endif /* _KERNEL */ + +extern struct pf_anchor_global pf_anchors; +extern struct pf_anchor pf_main_anchor; +#define pf_main_ruleset pf_main_anchor.ruleset + +struct tcphdr; + +/* these ruleset functions can be linked into userland programs (pfctl) */ +void pf_init_ruleset(struct pf_ruleset *); +int pf_anchor_setup(struct pf_rule *, + const struct pf_ruleset *, const char *); +int pf_anchor_copyout(const struct pf_ruleset *, + const struct pf_rule *, struct pfioc_rule *); +void pf_remove_anchor(struct pf_rule *); +void pf_remove_if_empty_ruleset(struct pf_ruleset *); +struct pf_anchor *pf_find_anchor(const char *); +struct pf_ruleset *pf_find_ruleset(const char *); +struct pf_ruleset *pf_get_leaf_ruleset(char *, char **); +struct pf_anchor *pf_create_anchor(struct pf_anchor *, const char *); +struct pf_ruleset *pf_find_or_create_ruleset(const char *); +void pf_anchor_rele(struct pf_anchor *); +struct pf_anchor *pf_anchor_take(struct pf_anchor *); + +/* The fingerprint functions can be linked into userland programs (tcpdump) */ +int pf_osfp_add(struct pf_osfp_ioctl *); +#ifdef _KERNEL +struct pf_osfp_enlist * + pf_osfp_fingerprint(struct pf_pdesc *); +#endif /* _KERNEL */ +struct pf_osfp_enlist * + pf_osfp_fingerprint_hdr(const struct ip *, const struct ip6_hdr *, + const struct tcphdr *); +void pf_osfp_flush(void); +int pf_osfp_get(struct pf_osfp_ioctl *); +void pf_osfp_initialize(void); +int pf_osfp_match(struct pf_osfp_enlist *, pf_osfp_t); +struct pf_os_fingerprint * + pf_osfp_validate(void); + +#ifdef _KERNEL +void pf_print_host(struct pf_addr *, u_int16_t, + sa_family_t); +int pf_get_transaddr(struct pf_rule *, struct pf_pdesc *, + struct pf_src_node **, struct pf_rule **); +int pf_map_addr(sa_family_t, struct pf_rule *, + struct pf_addr *, struct pf_addr *, + struct pf_addr *, struct pf_src_node **, + struct pf_pool *, enum pf_sn_types); +int pf_postprocess_addr(struct pf_state *); + +void pf_mbuf_link_state_key(struct mbuf *, + struct pf_state_key *); +void pf_mbuf_unlink_state_key(struct mbuf *); +void pf_mbuf_link_inpcb(struct mbuf *, struct inpcb *); +void pf_mbuf_unlink_inpcb(struct mbuf *); + +u_int8_t* pf_find_tcpopt(u_int8_t *, u_int8_t *, size_t, + u_int8_t, u_int8_t); +u_int8_t pf_get_wscale(struct pf_pdesc *); +u_int16_t pf_get_mss(struct pf_pdesc *, uint16_t); +struct mbuf * pf_build_tcp(const struct pf_rule *, sa_family_t, + const struct pf_addr *, const struct pf_addr *, + u_int16_t, u_int16_t, u_int32_t, u_int32_t, + u_int8_t, u_int16_t, u_int16_t, u_int8_t, int, + u_int16_t, u_int, u_int, u_short *); +void pf_send_tcp(const struct pf_rule *, sa_family_t, + const struct pf_addr *, const struct pf_addr *, + u_int16_t, u_int16_t, u_int32_t, u_int32_t, + u_int8_t, u_int16_t, u_int16_t, u_int8_t, int, + u_int16_t, u_int, u_short *); +void pf_syncookies_init(void); +int pf_syncookies_setmode(u_int8_t); +int pf_syncookies_setwats(u_int32_t, u_int32_t); +int pf_syncookies_getwats(struct pfioc_synflwats *); +int pf_synflood_check(struct pf_pdesc *); +void pf_syncookie_send(struct pf_pdesc *, u_short *); +u_int8_t pf_syncookie_validate(struct pf_pdesc *); +struct mbuf * pf_syncookie_recreate_syn(struct pf_pdesc *, + u_short *); +#endif /* _KERNEL */ + +#endif /* _NET_PFVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/pfvar_priv.h b/lib/libc/include/generic-openbsd/net/pfvar_priv.h new file mode 100644 index 0000000000..a005b8511a --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/pfvar_priv.h @@ -0,0 +1,434 @@ +/* $OpenBSD: pfvar_priv.h,v 1.38 2024/09/07 22:41:55 aisha Exp $ */ + +/* + * Copyright (c) 2001 Daniel Hartmeier + * Copyright (c) 2002 - 2013 Henning Brauer + * Copyright (c) 2016 Alexander Bluhm + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT HOLDERS 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 _NET_PFVAR_PRIV_H_ +#define _NET_PFVAR_PRIV_H_ + +#ifdef _KERNEL + +#include +#include +#include + +/* + * Locks used to protect struct members in this file: + * L pf_inp_mtx link pf to inp mutex + */ + +struct pfsync_deferral; + +/* + * pf state items - links from pf_state_key to pf_states + */ + +struct pf_state_item { + TAILQ_ENTRY(pf_state_item) + si_entry; + struct pf_state *si_st; +}; + +TAILQ_HEAD(pf_statelisthead, pf_state_item); + +/* + * pf state keys - look up states by address + */ + +struct pf_state_key { + struct pf_addr addr[2]; + u_int16_t port[2]; + u_int16_t rdomain; + u_int16_t hash; + sa_family_t af; + u_int8_t proto; + + RBT_ENTRY(pf_state_key) sk_entry; + struct pf_statelisthead sk_states; + struct pf_state_key *sk_reverse; + struct inpcb *sk_inp; /* [L] */ + pf_refcnt_t sk_refcnt; + u_int8_t sk_removed; +}; + +RBT_HEAD(pf_state_tree, pf_state_key); +RBT_PROTOTYPE(pf_state_tree, pf_state_key, sk_entry, pf_state_compare_key); + +#define PF_REVERSED_KEY(key, family) \ + ((key[PF_SK_WIRE]->af != key[PF_SK_STACK]->af) && \ + (key[PF_SK_WIRE]->af != (family))) + +/* + * pf state + * + * Protection/ownership of pf_state members: + * I immutable after pf_state_insert() + * M pf_state mtx + * P PF_STATE_LOCK + * S pfsync + * L pf_state_list + * g pf_purge gc + */ + +struct pf_state { + u_int64_t id; /* [I] */ + u_int32_t creatorid; /* [I] */ + u_int8_t direction; /* [I] */ + u_int8_t pad[3]; + + TAILQ_ENTRY(pf_state) sync_list; /* [S] */ + struct pfsync_deferral *sync_defer; /* [S] */ + TAILQ_ENTRY(pf_state) entry_list; /* [L] */ + SLIST_ENTRY(pf_state) gc_list; /* [g] */ + RBT_ENTRY(pf_state) entry_id; /* [P] */ + struct pf_state_peer src; + struct pf_state_peer dst; + struct pf_rule_slist match_rules; /* [I] */ + union pf_rule_ptr rule; /* [I] */ + union pf_rule_ptr anchor; /* [I] */ + union pf_rule_ptr natrule; /* [I] */ + struct pf_addr rt_addr; /* [I] */ + struct pf_sn_head src_nodes; /* [I] */ + struct pf_state_key *key[2]; /* [I] stack and wire */ + struct pfi_kif *kif; /* [I] */ + struct mutex mtx; + pf_refcnt_t refcnt; + u_int64_t packets[2]; + u_int64_t bytes[2]; + int32_t creation; /* [I] */ + int32_t expire; + int32_t pfsync_time; /* [S] */ + int rtableid[2]; /* [I] stack and wire */ + u_int16_t qid; /* [I] */ + u_int16_t pqid; /* [I] */ + u_int16_t tag; /* [I] */ + u_int16_t state_flags; /* [M] */ + u_int8_t log; /* [I] */ + u_int8_t timeout; + u_int8_t sync_state; /* [S] PFSYNC_S_x */ + u_int8_t sync_updates; /* [S] */ + u_int8_t min_ttl; /* [I] */ + u_int8_t set_tos; /* [I] */ + u_int8_t set_prio[2]; /* [I] */ + u_int16_t max_mss; /* [I] */ + u_int16_t if_index_in; /* [I] */ + u_int16_t if_index_out; /* [I] */ + u_int16_t delay; /* [I] */ + u_int8_t rt; /* [I] */ +}; + +RBT_HEAD(pf_state_tree_id, pf_state); +RBT_PROTOTYPE(pf_state_tree_id, pf_state, entry_id, pf_state_compare_id); +extern struct pf_state_tree_id tree_id; + +/* + * states are linked into a global list to support the following + * functionality: + * + * - garbage collection + * - pfsync bulk send operations + * - bulk state fetches via the DIOCGETSTATES ioctl + * - bulk state clearing via the DIOCCLRSTATES ioctl + * + * states are inserted into the global pf_state_list once it has also + * been successfully added to the various trees that make up the state + * table. states are only removed from the pf_state_list by the garbage + * collection process. + * + * the pf_state_list head and tail pointers (ie, the pfs_list TAILQ_HEAD + * structure) and the pointers between the entries on the pf_state_list + * are locked separately. at a high level, this allows for insertion + * of new states into the pf_state_list while other contexts (eg, the + * ioctls) are traversing the state items in the list. for garbage + * collection to remove items from the pf_state_list, it has to exclude + * both modifications to the list head and tail pointers, and traversal + * of the links between the states. + * + * the head and tail pointers are protected by a mutex. the pointers + * between states are protected by an rwlock. + * + * because insertions are only made to the end of the list, if we get + * a snapshot of the head and tail of the list and prevent modifications + * to the links between states, we can safely traverse between the + * head and tail entries. subsequent insertions can add entries after + * our view of the tail, but we don't look past our view. + * + * if both locks must be taken, the rwlock protecting the links between + * states is taken before the mutex protecting the head and tail + * pointer. + * + * insertion into the list follows this pattern: + * + * // serialise list head/tail modifications + * mtx_enter(&pf_state_list.pfs_mtx); + * TAILQ_INSERT_TAIL(&pf_state_list.pfs_list, state, entry_list); + * mtx_leave(&pf_state_list.pfs_mtx); + * + * traversal of the list: + * + * // lock against the gc removing an item from the list + * rw_enter_read(&pf_state_list.pfs_rwl); + * + * // get a snapshot view of the ends of the list + * mtx_enter(&pf_state_list.pfs_mtx); + * head = TAILQ_FIRST(&pf_state_list.pfs_list); + * tail = TAILQ_LAST(&pf_state_list.pfs_list, pf_state_queue); + * mtx_leave(&pf_state_list.pfs_mtx); + * + * state = NULL; + * next = head; + * + * while (state != tail) { + * state = next; + * next = TAILQ_NEXT(state, entry_list); + * + * // look at the state + * } + * + * rw_exit_read(&pf_state_list.pfs_rwl); + * + * removing an item from the list: + * + * // wait for iterators (readers) to get out + * rw_enter_write(&pf_state_list.pfs_rwl); + * + * // serialise list head/tail modifications + * mtx_enter(&pf_state_list.pfs_mtx); + * TAILQ_REMOVE(&pf_state_list.pfs_list, state, entry_list); + * mtx_leave(&pf_state_list.pfs_mtx); + * + * rw_exit_write(&pf_state_list.pfs_rwl); + * + * the lock ordering for pf_state_list locks and the rest of the pf + * locks are: + * + * 1. KERNEL_LOCK + * 2. NET_LOCK + * 3. pf_state_list.pfs_rwl + * 4. PF_LOCK + * 5. PF_STATE_LOCK + * 6. pf_state_list.pfs_mtx + */ + +struct pf_state_list { + /* the list of states in the system */ + struct pf_state_queue pfs_list; + + /* serialise pfs_list head/tail access */ + struct mutex pfs_mtx; + + /* serialise access to pointers between pfs_list entries */ + struct rwlock pfs_rwl; +}; + +#define PF_STATE_LIST_INITIALIZER(_pfs) { \ + .pfs_list = TAILQ_HEAD_INITIALIZER(_pfs.pfs_list), \ + .pfs_mtx = MUTEX_INITIALIZER(IPL_SOFTNET), \ + .pfs_rwl = RWLOCK_INITIALIZER("pfstates"), \ +} + +extern struct rwlock pf_lock; + +struct pf_pdesc { + struct { + int done; + uid_t uid; + gid_t gid; + pid_t pid; + } lookup; + u_int64_t tot_len; /* Make Mickey money */ + + struct pf_addr nsaddr; /* src address after NAT */ + struct pf_addr ndaddr; /* dst address after NAT */ + + struct pfi_kif *kif; /* incoming interface */ + struct mbuf *m; /* mbuf containing the packet */ + struct pf_addr *src; /* src address */ + struct pf_addr *dst; /* dst address */ + u_int16_t *pcksum; /* proto cksum */ + u_int16_t *sport; + u_int16_t *dport; + u_int16_t osport; + u_int16_t odport; + u_int16_t hash; + u_int16_t nsport; /* src port after NAT */ + u_int16_t ndport; /* dst port after NAT */ + + u_int32_t off; /* protocol header offset */ + u_int32_t hdrlen; /* protocol header length */ + u_int32_t p_len; /* length of protocol payload */ + u_int32_t extoff; /* extension header offset */ + u_int32_t fragoff; /* fragment header offset */ + u_int32_t jumbolen; /* length from v6 jumbo header */ + u_int32_t badopts; /* v4 options or v6 routing headers */ +#define PF_OPT_OTHER 0x0001 +#define PF_OPT_JUMBO 0x0002 +#define PF_OPT_ROUTER_ALERT 0x0004 + + u_int16_t rdomain; /* original routing domain */ + u_int16_t virtual_proto; +#define PF_VPROTO_FRAGMENT 256 + sa_family_t af; + sa_family_t naf; + u_int8_t proto; + u_int8_t tos; + u_int8_t ttl; + u_int8_t dir; /* direction */ + u_int8_t sidx; /* key index for source */ + u_int8_t didx; /* key index for destination */ + u_int8_t destchg; /* flag set when destination changed */ + u_int8_t pflog; /* flags for packet logging */ + union { + struct tcphdr tcp; + struct udphdr udp; + struct icmp icmp; +#ifdef INET6 + struct icmp6_hdr icmp6; + struct mld_hdr mld; + struct nd_neighbor_solicit nd_ns; +#endif /* INET6 */ + } hdr; +}; + +struct pf_anchor_stackframe { + struct pf_ruleset *sf_rs; + struct pf_rule *sf_anchor; + union { + struct pf_rule *u_r; + struct pf_anchor_stackframe *u_stack_top; + } u; + struct pf_anchor *sf_child; + int sf_jump_target; +}; +#define sf_r u.u_r +#define sf_stack_top u.u_stack_top +enum { + PF_NEXT_RULE, + PF_NEXT_CHILD +}; + +extern struct cpumem *pf_anchor_stack; + +enum pf_trans_type { + PF_TRANS_NONE, + PF_TRANS_GETRULE, + PF_TRANS_MAX +}; + +struct pf_trans { + LIST_ENTRY(pf_trans) pft_entry; + uint32_t pft_unit; /* process id */ + uint64_t pft_ticket; + enum pf_trans_type pft_type; + union { + struct { + u_int32_t gr_version; + struct pf_anchor *gr_anchor; + struct pf_rule *gr_rule; + } u_getrule; + } u; +}; + +#define pftgr_version u.u_getrule.gr_version +#define pftgr_anchor u.u_getrule.gr_anchor +#define pftgr_rule u.u_getrule.gr_rule + +extern struct timeout pf_purge_states_to; +extern struct task pf_purge_task; +extern struct timeout pf_purge_to; + +struct pf_state *pf_state_ref(struct pf_state *); +void pf_state_unref(struct pf_state *); + +extern struct rwlock pf_lock; +extern struct rwlock pf_state_lock; +extern struct mutex pf_frag_mtx; +extern struct mutex pf_inp_mtx; + +#define PF_LOCK() do { \ + rw_enter_write(&pf_lock); \ + } while (0) + +#define PF_UNLOCK() do { \ + PF_ASSERT_LOCKED(); \ + rw_exit_write(&pf_lock); \ + } while (0) + +#define PF_ASSERT_LOCKED() do { \ + if (rw_status(&pf_lock) != RW_WRITE) \ + splassert_fail(RW_WRITE, \ + rw_status(&pf_lock),__func__);\ + } while (0) + +#define PF_ASSERT_UNLOCKED() do { \ + if (rw_status(&pf_lock) == RW_WRITE) \ + splassert_fail(0, rw_status(&pf_lock), __func__);\ + } while (0) + +#define PF_STATE_ENTER_READ() do { \ + rw_enter_read(&pf_state_lock); \ + } while (0) + +#define PF_STATE_EXIT_READ() do { \ + rw_exit_read(&pf_state_lock); \ + } while (0) + +#define PF_STATE_ENTER_WRITE() do { \ + rw_enter_write(&pf_state_lock); \ + } while (0) + +#define PF_STATE_EXIT_WRITE() do { \ + PF_STATE_ASSERT_LOCKED(); \ + rw_exit_write(&pf_state_lock); \ + } while (0) + +#define PF_STATE_ASSERT_LOCKED() do { \ + if (rw_status(&pf_state_lock) != RW_WRITE)\ + splassert_fail(RW_WRITE, \ + rw_status(&pf_state_lock), __func__);\ + } while (0) + +#define PF_FRAG_LOCK() mtx_enter(&pf_frag_mtx) +#define PF_FRAG_UNLOCK() mtx_leave(&pf_frag_mtx) + +/* for copies to/from network byte order */ +void pf_state_peer_hton(const struct pf_state_peer *, + struct pfsync_state_peer *); +void pf_state_peer_ntoh(const struct pfsync_state_peer *, + struct pf_state_peer *); +u_int16_t pf_pkt_hash(sa_family_t, uint8_t, + const struct pf_addr *, const struct pf_addr *, + uint16_t, uint16_t); + +#endif /* _KERNEL */ + +#endif /* _NET_PFVAR_PRIV_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/pipex.h b/lib/libc/include/generic-openbsd/net/pipex.h new file mode 100644 index 0000000000..c6b56abf9a --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/pipex.h @@ -0,0 +1,210 @@ +/* $OpenBSD: pipex.h,v 1.35 2025/03/02 21:28:32 bluhm Exp $ */ + +/* + * Copyright (c) 2009 Internet Initiative Japan Inc. + * 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 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 AUTHOR 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 NET_PIPEX_H +#define NET_PIPEX_H 1 + +/* + * Names for pipex sysctl objects + */ +#define PIPEXCTL_ENABLE 1 +#define PIPEXCTL_MAXID 2 + +#define PIPEXCTL_NAMES { \ + { 0, 0 }, \ + { "enable", CTLTYPE_INT }, \ +} + +#define PIPEX_PROTO_L2TP 1 /* protocol L2TP */ +#define PIPEX_PROTO_PPTP 2 /* protocol PPTP */ +#define PIPEX_PROTO_PPPOE 3 /* protocol PPPoE */ +#define PIPEX_MAX_LISTREQ 128 /* list request size */ +#define PIPEX_MPPE_KEYLEN 16 + +/* pipex_mppe */ +struct pipex_mppe_req { + int16_t stateless; /* mppe key mode. + 1 for stateless */ + int16_t keylenbits; /* mppe key length(in bits)*/ + u_char master_key[PIPEX_MPPE_KEYLEN]; /* mppe master key */ +}; + +/* pipex statistics */ +struct pipex_statistics { + uint32_t ipackets; /* packets received from tunnel */ + uint32_t ierrors; /* error packets received from tunnel */ + uint64_t ibytes; /* number of received bytes from tunnel */ + uint32_t opackets; /* packets sent to tunnel */ + uint32_t oerrors; /* error packets on sending to tunnel */ + uint64_t obytes; /* number of sent bytes to tunnel */ + + uint32_t idle_time; /* idle time in seconds */ +}; + +struct pipex_session_req { + int pr_protocol; /* tunnel protocol */ +/* u_int pr_rdomain; */ /* rdomain id */ + uint16_t pr_session_id; /* session-id */ + uint16_t pr_peer_session_id; /* peer's session-id */ + uint32_t pr_ppp_flags; /* PPP configuration flags */ +#define PIPEX_PPP_ACFC_ACCEPTED 0x0001 /* ACFC accepted */ +#define PIPEX_PPP_PFC_ACCEPTED 0x0002 /* PFC accepted */ +#define PIPEX_PPP_ACFC_ENABLED 0x0004 /* ACFC enabled */ +#define PIPEX_PPP_PFC_ENABLED 0x0008 /* PFC enabled */ +#define PIPEX_PPP_MPPE_ACCEPTED 0x0010 /* MPPE accepted */ +#define PIPEX_PPP_MPPE_ENABLED 0x0020 /* MPPE enabled */ +#define PIPEX_PPP_MPPE_REQUIRED 0x0040 /* MPPE is required */ +#define PIPEX_PPP_HAS_ACF 0x0080 /* has ACF */ +#define PIPEX_PPP_ADJUST_TCPMSS 0x0100 /* do tcpmss adjustment */ +#define PIPEX_PPP_INGRESS_FILTER 0x0200 /* do ingress filter */ + int8_t pr_ccp_id; /* CCP current packet id */ + int pr_ppp_id; /* PPP Id. */ + uint16_t pr_peer_mru; /* Peer's MRU */ + uint32_t pr_timeout_sec; /* Idle Timer */ + + struct in_addr pr_ip_srcaddr; /* local framed IP-Address */ + struct in_addr pr_ip_address; /* framed IP-Address */ + struct in_addr pr_ip_netmask; /* framed IP-Netmask */ + struct sockaddr_in6 pr_ip6_address; /* framed IPv6-Address */ + int pr_ip6_prefixlen; /* framed IPv6-Prefixlen */ + union { + struct { + uint32_t snd_nxt; /* send next */ + uint32_t rcv_nxt; /* receive next */ + uint32_t snd_una; /* unacked */ + uint32_t rcv_acked; /* recv acked */ + int winsz; /* window size */ + int maxwinsz; /* max window size */ + int peer_maxwinsz; /* peer's max window size */ + } pptp; + struct { + uint32_t option_flags; +#define PIPEX_L2TP_USE_SEQUENCING 0x00000001 + + uint16_t tunnel_id; /* our tunnel-id */ + uint16_t peer_tunnel_id;/* peer's tunnel-id */ + uint32_t ns_nxt; /* send next */ + uint32_t nr_nxt; /* receive next */ + uint32_t ns_una; /* unacked */ + uint32_t nr_acked; /* recv acked */ + uint32_t ipsecflowinfo; /* IPsec flow id for NAT-T */ + } l2tp; + struct { + char over_ifname[IF_NAMESIZE]; /* ethernet ifname */ + } pppoe; + } pr_proto; + struct sockaddr_storage pr_peer_address; /* peer address of tunnel */ + struct sockaddr_storage pr_local_address; /* our address of tunnel */ + struct pipex_mppe_req pr_mppe_recv; /* mppe key for receive */ + struct pipex_mppe_req pr_mppe_send; /* mppe key for send */ +}; + +struct pipex_session_stat_req { + int psr_protocol; /* tunnel protocol */ + uint16_t psr_session_id; /* session-id */ + struct pipex_statistics psr_stat; /* statistics */ +}; +struct pipex_session_close_req { + int psr_protocol; /* tunnel protocol */ + uint16_t psr_session_id; /* session-id */ + struct pipex_statistics psr_stat; /* statistics */ +}; +#define pcr_protocol psr_protocol +#define pcr_session_id psr_session_id +#define pcr_stat psr_stat + +struct pipex_session_list_req { + uint8_t plr_flags; +#define PIPEX_LISTREQ_MORE 0x01 + int plr_ppp_id_count; /* count of PPP id */ + int plr_ppp_id[PIPEX_MAX_LISTREQ]; /* PPP id */ +}; + +/* for pppx(4) */ +struct pppx_hdr { + u_int32_t pppx_proto; /* write: protocol in PIPEX_PROTO_ */ + u_int32_t pppx_id; /* write: session_id, read: ppp_id */ +}; + +struct pipex_session_descr_req { + int pdr_protocol; /* tunnel protocol */ + uint16_t pdr_session_id; /* session-id */ + char pdr_descr[IFDESCRSIZE]; /* description */ +}; + + +/* PIPEX ioctls */ +#define PIPEXASESSION _IOW ('p', 3, struct pipex_session_req) +#define PIPEXDSESSION _IOWR('p', 4, struct pipex_session_close_req) +#define PIPEXGSTAT _IOWR('p', 6, struct pipex_session_stat_req) +#define PIPEXGCLOSED _IOR ('p', 7, struct pipex_session_list_req) +#define PIPEXSIFDESCR _IOW ('p', 8, struct pipex_session_descr_req) + +#ifdef _KERNEL +extern int pipex_enable; + +struct pipex_session; + +__BEGIN_DECLS +void pipex_init(void); + +struct pipex_session *pipex_pppoe_lookup_session(struct mbuf *); +struct mbuf *pipex_pppoe_input(struct mbuf *, + struct pipex_session *, struct netstack *); +struct pipex_session *pipex_pptp_lookup_session(struct mbuf *); +struct mbuf *pipex_pptp_input(struct mbuf *, + struct pipex_session *, struct netstack *); +struct pipex_session *pipex_pptp_userland_lookup_session_ipv4(struct mbuf *, + struct in_addr); +struct pipex_session *pipex_pptp_userland_lookup_session_ipv6(struct mbuf *, + struct in6_addr); +struct pipex_session *pipex_l2tp_userland_lookup_session(struct mbuf *, + struct sockaddr *); +struct mbuf *pipex_pptp_userland_output(struct mbuf *, + struct pipex_session *); +struct pipex_session *pipex_l2tp_lookup_session(struct mbuf *, int, + struct sockaddr *); +struct mbuf *pipex_l2tp_input(struct mbuf *, int off, + struct pipex_session *, uint32_t, + struct netstack *); +struct pipex_session *pipex_l2tp_userland_lookup_session_ipv4(struct mbuf *, + struct in_addr); +struct pipex_session *pipex_l2tp_userland_lookup_session_ipv6(struct mbuf *, + struct in6_addr); +struct mbuf *pipex_l2tp_userland_output(struct mbuf *, + struct pipex_session *); +void pipex_rele_session(struct pipex_session *); +int pipex_ioctl(void *, u_long, caddr_t); +void pipex_session_init_mppe_recv(struct pipex_session *, + int, int, u_char *); +void pipex_session_init_mppe_send(struct pipex_session *, + int, int, u_char *); +__END_DECLS + +#endif /* _KERNEL */ +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/pipex_local.h b/lib/libc/include/generic-openbsd/net/pipex_local.h new file mode 100644 index 0000000000..9fe5ec3d67 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/pipex_local.h @@ -0,0 +1,478 @@ +/* $OpenBSD: pipex_local.h,v 1.54 2025/03/02 21:28:32 bluhm Exp $ */ + +/* + * Copyright (c) 2009 Internet Initiative Japan Inc. + * 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 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 AUTHOR 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 +#include + +extern struct mutex pipex_list_mtx; + +#define PIPEX_PPTP 1 +#define PIPEX_L2TP 1 +#define PIPEX_PPPOE 1 +#define PIPEX_MPPE 1 + +#define PIPEX_REWIND_LIMIT 64 + +#define PIPEX_ENABLED 0x0001 + +/* compile time option constants */ +#ifndef PIPEX_MAX_SESSION +#define PIPEX_MAX_SESSION 512 +#endif +#define PIPEX_HASH_DIV 8 +#define PIPEX_HASH_SIZE (PIPEX_MAX_SESSION/PIPEX_HASH_DIV) +#define PIPEX_HASH_MASK (PIPEX_HASH_SIZE-1) +#define PIPEX_CLOSE_TIMEOUT 30 +#define PIPEX_PPPMINLEN 5 + /* minimum PPP header length is 1 and minimum ppp payload length is 4 */ + +#define PIPEX_MPPE_NOLDKEY 64 /* should be power of two */ +#define PIPEX_MPPE_OLDKEYMASK (PIPEX_MPPE_NOLDKEY - 1) + +/* + * Locks used to protect struct members: + * A atomic operation + * I immutable after creation + * L pipex_list_mtx + * s this pipex_session' `pxs_mtx' + * m this pipex_mppe' `pxm_mtx' + */ + +#ifdef PIPEX_MPPE +/* mppe rc4 key */ +struct pipex_mppe { + struct mutex pxm_mtx; + u_int flags; /* [m] flags, see below */ +#define PIPEX_MPPE_STATELESS 0x01 /* [I] key change mode */ +#define PIPEX_MPPE_RESETREQ 0x02 /* [m] */ + + int16_t keylenbits; /* [I] key length */ + int16_t keylen; /* [I] */ + uint16_t coher_cnt; /* [m] coherency counter */ + struct rc4_ctx rc4ctx; /* [m] */ + u_char master_key[PIPEX_MPPE_KEYLEN]; /* [m] master key of MPPE */ + u_char session_key[PIPEX_MPPE_KEYLEN]; /* [m] session key of MPPE */ + u_char (*old_session_keys)[PIPEX_MPPE_KEYLEN]; + /* [m] old session keys */ +}; +#endif /* PIPEX_MPPE */ + +#ifdef PIPEX_PPPOE +struct pipex_pppoe_session { + u_int over_ifidx; /* [I] ether interface */ +}; +#endif /* PIPEX_PPPOE */ + +#ifdef PIPEX_PPTP +struct pipex_pptp_session { + /* sequence number gap between pipex and userland */ + int32_t snd_gap; /* [s] gap of our sequence */ + int32_t rcv_gap; /* [s] gap of peer's sequence */ + int32_t ul_snd_una; /* [s] userland send acked seq */ + + uint32_t snd_nxt; /* [s] send next */ + uint32_t rcv_nxt; /* [s] receive next */ + uint32_t snd_una; /* [s] send acked sequence */ + uint32_t rcv_acked; /* [s] recv acked sequence */ + + int winsz; /* [I] windows size */ + int maxwinsz; /* [I] max windows size */ + int peer_maxwinsz; /* [I] peer's max windows size */ +}; +#endif /* PIPEX_PPTP */ + +#ifdef PIPEX_L2TP +/* + * L2TP Packet headers + * + * +----+---+----+---+----+--------+ + * |IPv4|UDP|L2TP|PPP|IPv4|Data....| + * +----+---+----+---+----+--------+ + * + * Session Data + * + * IPv4 IP_SRC <-- required for encap. + * IP_DST <-- required for encap. + * + * UDP SPort <-- required for encap. + * DPort <-- required for encap. + * + * L2TP FLAGS <-- only handle TYPE=0 (data) + * Tunnel ID <-- ID per tunnel(NOT a key: differed from RFC) + * Session ID <-- ID per PPP session(KEY to look up session) + * Ns(SEND SEQ) <-- sequence number of packet to send(opt.) + * Nr(RECV SEQ) <-- sequence number of packet to recv(opt.) + * + * - Recv Session lookup key is (Tunnnel ID, Session ID) in RFC. + * - BUT (Session ID) in PIPEX. SESSION ID MUST BE UNIQ. + * + * - We must update (Ns, Nr) of data channel. and we must adjust (Ns, Nr) + * in packets from/to userland. + */ +struct pipex_l2tp_session { + /* KEYS for session lookup (host byte order) */ + uint16_t tunnel_id; /* [I] our tunnel-id */ + uint16_t peer_tunnel_id; /* [I] peer's tunnel-id */ + + uint32_t option_flags; /* [I] protocol options */ + uint32_t ipsecflowinfo; /* [I] IPsec SA flow id for NAT-T */ + + int16_t ns_gap; /* [s] gap between userland and pipex */ + int16_t nr_gap; /* [s] gap between userland and pipex */ + uint16_t ul_ns_una; /* [s] unacked sequence number (userland) */ + + uint16_t ns_nxt; /* [s] next sequence number to send */ + uint16_t ns_una; /* [s] unacked sequence number to send */ + + uint16_t nr_nxt; /* [s] next sequence number to recv */ + uint16_t nr_acked; /* [s] acked sequence number to recv */ +}; +#endif /* PIPEX_L2TP */ + +struct cpumem; + +/* special iterator session */ +struct pipex_session_iterator { + /* Fields below should be in sync with pipex_session structure */ + struct radix_node ps4_rn[2]; + u_int flags; /* [I] flags, see below */ + LIST_ENTRY(pipex_session) session_list; /* [L] all session chain */ +}; + +/* pppac ip-extension session table */ +struct pipex_session { + struct radix_node ps4_rn[2]; + /* [L] tree glue, and other values */ + u_int flags; /* [I] flags, see below */ +#define PIPEX_SFLAGS_MULTICAST 0x01 /* virtual entry for multicast */ +#define PIPEX_SFLAGS_PPPX 0x02 /* interface is + point2point(pppx) */ +#define PIPEX_SFLAGS_ITERATOR 0x04 /* iterator session */ + + LIST_ENTRY(pipex_session) session_list; /* [L] all session chain */ + LIST_ENTRY(pipex_session) state_list; /* [L] state list chain */ + LIST_ENTRY(pipex_session) id_chain; /* [L] id hash chain */ + LIST_ENTRY(pipex_session) peer_addr_chain; + /* [L] peer's address hash chain */ + struct refcnt pxs_refcnt; + struct mutex pxs_mtx; + + u_int state; /* [L] pipex session state */ +#define PIPEX_STATE_INITIAL 0x0000 +#define PIPEX_STATE_OPENED 0x0001 +#define PIPEX_STATE_CLOSE_WAIT 0x0002 +#define PIPEX_STATE_CLOSE_WAIT2 0x0003 +#define PIPEX_STATE_CLOSED 0x0004 + + uint32_t idle_time; /* [L] idle time in seconds */ + + uint16_t protocol; /* [I] tunnel protocol (PK) */ + uint16_t session_id; /* [I] session-id (PK) */ + uint16_t peer_session_id; /* [I] peer's session-id */ + uint16_t peer_mru; /* [I] peer's MRU */ + uint32_t timeout_sec; /* [I] idle timeout */ + int ppp_id; /* [I] PPP id */ + + struct sockaddr_in ip_address; /* [I] remote address (AK) */ + struct sockaddr_in ip_netmask; /* [I] remote address mask (AK) */ + struct sockaddr_in6 ip6_address; /* [I] remote IPv6 address */ + int ip6_prefixlen; /* [I] remote IPv6 prefixlen */ + + u_int ifindex; /* [A] interface index */ + void *ownersc; /* [I] owner context */ + + uint32_t ppp_flags; /* [I] configure flags */ +#ifdef PIPEX_MPPE + int ccp_id; /* [s] CCP packet id */ + struct pipex_mppe + mppe_recv, /* MPPE context for incoming */ + mppe_send; /* MPPE context for outgoing */ +#endif /*PIPEXMPPE */ + + struct cpumem *stat_counters; + + union { +#ifdef PIPEX_PPPOE + struct pipex_pppoe_session pppoe; /* context for PPPoE */ +#endif /* PIPEX_PPPOE */ +#ifdef PIPEX_PPTP + struct pipex_pptp_session pptp; /* context for PPTP */ +#endif /* PIPEX_PPTP */ +#ifdef PIPEX_L2TP + struct pipex_l2tp_session l2tp; +#endif + char _proto_unknown[0]; + } proto; + union { + struct sockaddr sa; + struct sockaddr_in sin4; + struct sockaddr_in6 sin6; + struct sockaddr_dl sdl; + } peer, local; /* [I] */ +}; + +enum pipex_counters { + pxc_ipackets, /* packets received from tunnel */ + pxc_ierrors, /* error packets received from tunnel */ + pxc_ibytes, /* number of received bytes from tunnel */ + pxc_opackets, /* packets sent to tunnel */ + pxc_oerrors, /* error packets on sending to tunnel */ + pxc_obytes, /* number of sent bytes to tunnel */ + pxc_ncounters +}; + +/* gre header */ +struct pipex_gre_header { + uint16_t flags; /* flags and version*/ +#define PIPEX_GRE_KFLAG 0x2000 /* keys present */ +#define PIPEX_GRE_SFLAG 0x1000 /* seq present */ +#define PIPEX_GRE_AFLAG 0x0080 /* ack present */ +#define PIPEX_GRE_VER 0x0001 /* gre version code */ +#define PIPEX_GRE_VERMASK 0x0007 /* gre version mask */ +#define PIPEX_GRE_UNUSEDFLAGS 0xcf78 /* unused at pptp. set 0 in rfc2637 */ + + uint16_t type; +#define PIPEX_GRE_PROTO_PPP 0x880b /* gre/ppp */ + + uint16_t len; /* length not include gre header */ + uint16_t call_id; /* call_id */ +} __packed; + +/* pppoe header */ +struct pipex_pppoe_header { + uint8_t vertype; /* version and type */ +#define PIPEX_PPPOE_VERTYPE 0x11 /* version and type code */ + + uint8_t code; /* code */ +#define PIPEX_PPPOE_CODE_SESSION 0x00 /* code session */ + + uint16_t session_id; /* session id */ + uint16_t length; /* length */ +} __packed; + +/* l2tp header */ +struct pipex_l2tp_header { + uint16_t flagsver; +#define PIPEX_L2TP_FLAG_MASK 0xfff0 +#define PIPEX_L2TP_FLAG_TYPE 0x8000 +#define PIPEX_L2TP_FLAG_LENGTH 0x4000 +#define PIPEX_L2TP_FLAG_SEQUENCE 0x0800 +#define PIPEX_L2TP_FLAG_OFFSET 0x0200 +#define PIPEX_L2TP_FLAG_PRIORITY 0x0100 +#define PIPEX_L2TP_VER_MASK 0x000f +#define PIPEX_L2TP_VER 2 + uint16_t length; /* optional */ + uint16_t tunnel_id; + uint16_t session_id; + /* can be followed by option header */ +} __packed; + +/* l2tp option header */ +struct pipex_l2tp_seq_header { + uint16_t ns; + uint16_t nr; +} __packed; + +struct pipex_l2tp_offset_header { + uint16_t offset_size; + /* uint8_t offset_pad[] */ +} __packed; + +#ifdef PIPEX_DEBUG +#define PIPEX_DBG(a) if (pipex_debug & 1) pipex_session_log a +/* #define PIPEX_MPPE_DBG(a) if (pipex_debug & 1) pipex_session_log a */ +#define PIPEX_MPPE_DBG(a) +#else +#define PIPEX_DBG(a) +#define PIPEX_MPPE_DBG(a) +#endif /* PIPEX_DEBUG */ + +LIST_HEAD(pipex_hash_head, pipex_session); + +extern struct pipex_hash_head pipex_session_list; +extern struct pipex_hash_head pipex_close_wait_list; +extern struct pipex_hash_head pipex_peer_addr_hashtable[]; +extern struct pipex_hash_head pipex_id_hashtable[]; +extern struct pool pipex_session_pool; + + +#define PIPEX_ID_HASHTABLE(key) \ + (&pipex_id_hashtable[(key) & PIPEX_HASH_MASK]) +#define PIPEX_PEER_ADDR_HASHTABLE(key) \ + (&pipex_peer_addr_hashtable[(key) & PIPEX_HASH_MASK]) + +#define GETCHAR(c, cp) do { \ + (c) = *(cp)++; \ +} while (0) + +#define PUTCHAR(s, cp) do { \ + *(cp)++ = (u_char)(s); \ +} while (0) + +#define GETSHORT(s, cp) do { \ + (s) = *(cp)++ << 8; \ + (s) |= *(cp)++; \ +} while (0) + +#define PUTSHORT(s, cp) do { \ + *(cp)++ = (u_char) ((s) >> 8); \ + *(cp)++ = (u_char) (s); \ +} while (0) + +#define GETLONG(l, cp) do { \ + (l) = *(cp)++ << 8; \ + (l) |= *(cp)++; (l) <<= 8; \ + (l) |= *(cp)++; (l) <<= 8; \ + (l) |= *(cp)++; \ +} while (0) + +#define PUTLONG(l, cp) do { \ + *(cp)++ = (u_char) ((l) >> 24); \ + *(cp)++ = (u_char) ((l) >> 16); \ + *(cp)++ = (u_char) ((l) >> 8); \ + *(cp)++ = (u_char) (l); \ +} while (0) + +#define PIPEX_PULLUP(m0, l) \ + if ((m0)->m_len < (l)) { \ + if ((m0)->m_pkthdr.len < (l)) { \ + PIPEX_DBG((NULL, LOG_DEBUG, \ + "<%s> received packet is too short.", \ + __func__)); \ + m_freem(m0); \ + (m0) = NULL; \ + } else { \ + (m0) = m_pullup((m0), (l)); \ + KASSERT((m0) != NULL); \ + } \ + } +#define PIPEX_SEEK_NEXTHDR(ptr, len, t) \ + ((t) (((char *)ptr) + len)) +#define SEQ32_LT(a,b) ((int32_t)((a) - (b)) < 0) +#define SEQ32_LE(a,b) ((int32_t)((a) - (b)) <= 0) +#define SEQ32_GT(a,b) ((int32_t)((a) - (b)) > 0) +#define SEQ32_GE(a,b) ((int32_t)((a) - (b)) >= 0) +#define SEQ32_SUB(a,b) ((int32_t)((a) - (b))) + +#define SEQ16_LT(a,b) ((int16_t)((a) - (b)) < 0) +#define SEQ16_LE(a,b) ((int16_t)((a) - (b)) <= 0) +#define SEQ16_GT(a,b) ((int16_t)((a) - (b)) > 0) +#define SEQ16_GE(a,b) ((int16_t)((a) - (b)) >= 0) +#define SEQ16_SUB(a,b) ((int16_t)((a) - (b))) + +#define pipex_session_is_acfc_accepted(s) \ + (((s)->ppp_flags & PIPEX_PPP_ACFC_ACCEPTED)? 1 : 0) +#define pipex_session_is_pfc_accepted(s) \ + (((s)->ppp_flags & PIPEX_PPP_PFC_ACCEPTED)? 1 : 0) +#define pipex_session_is_acfc_enabled(s) \ + (((s)->ppp_flags & PIPEX_PPP_ACFC_ENABLED)? 1 : 0) +#define pipex_session_is_pfc_enabled(s) \ + (((s)->ppp_flags & PIPEX_PPP_PFC_ENABLED)? 1 : 0) +#define pipex_session_has_acf(s) \ + (((s)->ppp_flags & PIPEX_PPP_HAS_ACF)? 1 : 0) +#define pipex_session_is_mppe_accepted(s) \ + (((s)->ppp_flags & PIPEX_PPP_MPPE_ACCEPTED)? 1 : 0) +#define pipex_session_is_mppe_enabled(s) \ + (((s)->ppp_flags & PIPEX_PPP_MPPE_ENABLED)? 1 : 0) +#define pipex_session_is_mppe_required(s) \ + (((s)->ppp_flags & PIPEX_PPP_MPPE_REQUIRED)? 1 : 0) +#define pipex_mppe_rc4_keybits(r) ((r)->keylen << 3) +#define pipex_session_is_l2tp_data_sequencing_on(s) \ + (((s)->proto.l2tp.option_flags & PIPEX_L2TP_USE_SEQUENCING) ? 1 : 0) + +#define PIPEX_IPGRE_HDRLEN (sizeof(struct ip) + sizeof(struct pipex_gre_header)) +#define PIPEX_TCP_OPTLEN 40 +#define PIPEX_L2TP_MINLEN 8 + +void pipex_destroy_all_sessions (void *); +int pipex_init_session(struct pipex_session **, + struct pipex_session_req *); +int pipex_link_session(struct pipex_session *, + struct ifnet *, void *); +void pipex_unlink_session(struct pipex_session *); +void pipex_unlink_session_locked(struct pipex_session *); +void pipex_export_session_stats(struct pipex_session *, + struct pipex_statistics *); +int pipex_get_stat (struct pipex_session_stat_req *, + void *); +int pipex_get_closed (struct pipex_session_list_req *, + void *); +struct pipex_session *pipex_lookup_by_ip_address_locked (struct in_addr); +struct pipex_session *pipex_lookup_by_ip_address (struct in_addr); +struct pipex_session *pipex_lookup_by_session_id_locked (int, int); +struct pipex_session *pipex_lookup_by_session_id (int, int); +void pipex_ip_output(struct mbuf *, struct pipex_session *); +void pipex_ppp_output(struct mbuf *, struct pipex_session *, + int); +int pipex_ppp_proto(struct mbuf *, struct pipex_session *, + int, int *); +void pipex_ppp_input(struct mbuf *, struct pipex_session *, + int, struct netstack *); +void pipex_ip_input(struct mbuf *, struct pipex_session *, + struct netstack *); +void pipex_ip6_input(struct mbuf *, struct pipex_session *, + struct netstack *); +struct mbuf *pipex_common_input(struct pipex_session *, + struct mbuf *, int, int, int, struct netstack *); + +#ifdef PIPEX_PPPOE +void pipex_pppoe_output (struct mbuf *, struct pipex_session *); +#endif + +#ifdef PIPEX_PPTP +void pipex_pptp_output (struct mbuf *, struct pipex_session *, int, int); +struct pipex_session *pipex_pptp_userland_lookup_session(struct mbuf *, struct sockaddr *); +#endif + +#ifdef PIPEX_L2TP +void pipex_l2tp_output (struct mbuf *, struct pipex_session *); +#endif + +#ifdef PIPEX_MPPE +void pipex_mppe_init (struct pipex_mppe *, int, int, u_char *, int); +void GetNewKeyFromSHA (u_char *, u_char *, int, u_char *); +void pipex_mppe_reduce_key (struct pipex_mppe *); +void mppe_key_change (struct pipex_mppe *); +struct mbuf *pipex_mppe_input (struct mbuf *, + struct pipex_session *); +struct mbuf *pipex_mppe_output (struct mbuf *, + struct pipex_session *, uint16_t); +void pipex_ccp_input (struct mbuf *, struct pipex_session *); +int pipex_ccp_output (struct pipex_session *, int, int); +#endif + +struct mbuf *adjust_tcp_mss (struct mbuf *, int); +struct mbuf *ip_is_idle_packet (struct mbuf *, int *); +void pipex_session_log (struct pipex_session *, int, const char *, ...) __attribute__((__format__(__printf__,3,4))); +uint32_t pipex_sockaddr_hash_key(struct sockaddr *); +int pipex_sockaddr_compar_addr(struct sockaddr *, struct sockaddr *); +void pipex_timer_start (void); +void pipex_timer_stop (void); +void pipex_timer (void *); +struct pipex_session *pipex_iterator(struct pipex_session *, + struct pipex_session_iterator *, void *); \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/ppp-comp.h b/lib/libc/include/generic-openbsd/net/ppp-comp.h new file mode 100644 index 0000000000..c798a8f904 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/ppp-comp.h @@ -0,0 +1,173 @@ +/* $OpenBSD: ppp-comp.h,v 1.8 2002/09/13 00:12:07 deraadt Exp $ */ + +/* + * ppp-comp.h - Definitions for doing PPP packet compression. + * + * Copyright (c) 1989-2002 Paul Mackerras. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The name(s) of the authors of this software must not be used to + * endorse or promote products derived from this software without + * prior written permission. + * + * 4. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by Paul Mackerras + * ". + * + * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + * SPECIAL, 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 _NET_PPP_COMP_H_ +#define _NET_PPP_COMP_H_ + +/* + * The following symbols control whether we include code for + * various compression methods. + */ +#ifndef DO_BSD_COMPRESS +#define DO_BSD_COMPRESS 1 /* by default, include BSD-Compress */ +#endif +#ifndef DO_DEFLATE +#define DO_DEFLATE 1 /* by default, include Deflate */ +#endif +#define DO_PREDICTOR_1 0 +#define DO_PREDICTOR_2 0 + +/* + * Structure giving methods for compression/decompression. + */ +#ifdef PACKETPTR +struct compressor { + int compress_proto; /* CCP compression protocol number */ + + /* Allocate space for a compressor (transmit side) */ + void *(*comp_alloc)(u_char *options, int opt_len); + /* Free space used by a compressor */ + void (*comp_free)(void *state); + /* Initialize a compressor */ + int (*comp_init)(void *state, u_char *options, int opt_len, + int unit, int hdrlen, int debug); + /* Reset a compressor */ + void (*comp_reset)(void *state); + /* Compress a packet */ + int (*compress)(void *state, PACKETPTR *mret, + PACKETPTR mp, int orig_len, int max_len); + /* Return compression statistics */ + void (*comp_stat)(void *state, struct compstat *stats); + + /* Allocate space for a decompressor (receive side) */ + void *(*decomp_alloc)(u_char *options, int opt_len); + /* Free space used by a decompressor */ + void (*decomp_free)(void *state); + /* Initialize a decompressor */ + int (*decomp_init)(void *state, u_char *options, int opt_len, + int unit, int hdrlen, int mru, int debug); + /* Reset a decompressor */ + void (*decomp_reset)(void *state); + /* Decompress a packet. */ + int (*decompress)(void *state, PACKETPTR mp, + PACKETPTR *dmpp); + /* Update state for an incompressible packet received */ + void (*incomp)(void *state, PACKETPTR mp); + /* Return decompression statistics */ + void (*decomp_stat)(void *state, struct compstat *stats); +}; +#endif /* PACKETPTR */ + +/* + * Return values for decompress routine. + * We need to make these distinctions so that we can disable certain + * useful functionality, namely sending a CCP reset-request as a result + * of an error detected after decompression. This is to avoid infringing + * a patent held by Motorola. + * Don't you just lurve software patents. + */ +#define DECOMP_OK 0 /* everything went OK */ +#define DECOMP_ERROR 1 /* error detected before decomp. */ +#define DECOMP_FATALERROR 2 /* error detected after decomp. */ + +/* + * CCP codes. + */ +#define CCP_CONFREQ 1 +#define CCP_CONFACK 2 +#define CCP_TERMREQ 5 +#define CCP_TERMACK 6 +#define CCP_RESETREQ 14 +#define CCP_RESETACK 15 + +/* + * Max # bytes for a CCP option + */ +#define CCP_MAX_OPTION_LENGTH 32 + +/* + * Parts of a CCP packet. + */ +#define CCP_CODE(dp) ((dp)[0]) +#define CCP_ID(dp) ((dp)[1]) +#define CCP_LENGTH(dp) (((dp)[2] << 8) + (dp)[3]) +#define CCP_HDRLEN 4 + +#define CCP_OPT_CODE(dp) ((dp)[0]) +#define CCP_OPT_LENGTH(dp) ((dp)[1]) +#define CCP_OPT_MINLEN 2 + +/* + * Definitions for BSD-Compress. + */ +#define CI_BSD_COMPRESS 21 /* config. option for BSD-Compress */ +#define CILEN_BSD_COMPRESS 3 /* length of config. option */ + +/* Macros for handling the 3rd byte of the BSD-Compress config option. */ +#define BSD_NBITS(x) ((x) & 0x1F) /* number of bits requested */ +#define BSD_VERSION(x) ((x) >> 5) /* version of option format */ +#define BSD_CURRENT_VERSION 1 /* current version number */ +#define BSD_MAKE_OPT(v, n) (((v) << 5) | (n)) + +#define BSD_MIN_BITS 9 /* smallest code size supported */ +#define BSD_MAX_BITS 15 /* largest code size supported */ + +/* + * Definitions for Deflate. + */ +#define CI_DEFLATE 26 /* config option for Deflate */ +#define CI_DEFLATE_DRAFT 24 /* value used in original draft RFC */ +#define CILEN_DEFLATE 4 /* length of its config option */ + +#define DEFLATE_MIN_SIZE 8 +#define DEFLATE_MAX_SIZE 15 +#define DEFLATE_METHOD_VAL 8 +#define DEFLATE_SIZE(x) (((x) >> 4) + DEFLATE_MIN_SIZE) +#define DEFLATE_METHOD(x) ((x) & 0x0F) +#define DEFLATE_MAKE_OPT(w) ((((w) - DEFLATE_MIN_SIZE) << 4) \ + + DEFLATE_METHOD_VAL) +#define DEFLATE_CHK_SEQUENCE 0 + +/* + * Definitions for other, as yet unsupported, compression methods. + */ +#define CI_PREDICTOR_1 1 /* config option for Predictor-1 */ +#define CILEN_PREDICTOR_1 2 /* length of its config option */ +#define CI_PREDICTOR_2 2 /* config option for Predictor-2 */ +#define CILEN_PREDICTOR_2 2 /* length of its config option */ + +#endif /* _NET_PPP_COMP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/ppp_defs.h b/lib/libc/include/generic-openbsd/net/ppp_defs.h new file mode 100644 index 0000000000..ac5bee937b --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/ppp_defs.h @@ -0,0 +1,170 @@ +/* $OpenBSD: ppp_defs.h,v 1.13 2002/09/13 00:12:07 deraadt Exp $ */ +/* $NetBSD: ppp_defs.h,v 1.1 1995/07/04 06:28:26 paulus Exp $ */ + +/* + * ppp_defs.h - PPP definitions. + * + * Copyright (c) 1989-2002 Paul Mackerras. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The name(s) of the authors of this software must not be used to + * endorse or promote products derived from this software without + * prior written permission. + * + * 4. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by Paul Mackerras + * ". + * + * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + * SPECIAL, 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 _PPP_DEFS_H_ +#define _PPP_DEFS_H_ + +/* + * The basic PPP frame. + */ +#define PPP_HDRLEN 4 /* octets for standard ppp header */ +#define PPP_FCSLEN 2 /* octets for FCS */ +#define PPP_MRU 1500 /* default MRU = max length of info field */ + +#define PPP_ADDRESS(p) (((u_char *)(p))[0]) +#define PPP_CONTROL(p) (((u_char *)(p))[1]) +#define PPP_PROTOCOL(p) ((((u_char *)(p))[2] << 8) + ((u_char *)(p))[3]) + +/* + * Significant octet values. + */ +#define PPP_ALLSTATIONS 0xff /* All-Stations broadcast address */ +#define PPP_UI 0x03 /* Unnumbered Information */ +#define PPP_FLAG 0x7e /* Flag Sequence */ +#define PPP_ESCAPE 0x7d /* Asynchronous Control Escape */ +#define PPP_TRANS 0x20 /* Asynchronous transparency modifier */ + +/* + * Protocol field values. + */ +#define PPP_IP 0x21 /* Internet Protocol */ +#define PPP_XNS 0x25 /* Xerox NS */ +#define PPP_AT 0x29 /* AppleTalk Protocol */ +#define PPP_IPX 0x2b /* Internetwork Packet Exchange */ +#define PPP_VJC_COMP 0x2d /* VJ compressed TCP */ +#define PPP_VJC_UNCOMP 0x2f /* VJ uncompressed TCP */ +#define PPP_IPV6 0x57 /* Internet Protocol Version 6 */ +#define PPP_COMP 0xfd /* compressed packet */ +#define PPP_IPCP 0x8021 /* IP Control Protocol */ +#define PPP_ATCP 0x8029 /* AppleTalk Control Protocol */ +#define PPP_IPXCP 0x802b /* IPX Control Protocol */ +#define PPP_IPV6CP 0x8057 /* IPv6 Control Protocol */ +#define PPP_CCP 0x80fd /* Compression Control Protocol */ +#define PPP_LCP 0xc021 /* Link Control Protocol */ +#define PPP_PAP 0xc023 /* Password Authentication Protocol */ +#define PPP_LQR 0xc025 /* Link Quality Report protocol */ +#define PPP_CHAP 0xc223 /* Cryptographic Handshake Auth. Protocol */ +#define PPP_CBCP 0xc029 /* Callback Control Protocol */ + +/* + * Values for FCS calculations. + */ +#define PPP_INITFCS 0xffff /* Initial FCS value */ +#define PPP_GOODFCS 0xf0b8 /* Good final FCS value */ +#define PPP_FCS(fcs, c) (((fcs) >> 8) ^ fcstab[((fcs) ^ (c)) & 0xff]) + +/* + * A 32-bit unsigned integral type. + */ +#ifndef __BIT_TYPES_DEFINED__ +#ifdef UINT32_T +typedef UINT32_T u_int32_t; +#else +typedef unsigned int u_int32_t; +typedef unsigned short u_int16_t; +#endif +#endif + +/* + * Extended asyncmap - allows any character to be escaped. + */ +typedef u_int32_t ext_accm[8]; + +/* + * What to do with network protocol (NP) packets. + */ +enum NPmode { + NPMODE_PASS, /* pass the packet through */ + NPMODE_DROP, /* silently drop the packet */ + NPMODE_ERROR, /* return an error */ + NPMODE_QUEUE /* save it up for later. */ +}; + +/* + * Statistics. + */ +struct pppstat { + u_int ppp_ibytes; /* bytes received */ + u_int ppp_ipackets; /* packets received */ + u_int ppp_ierrors; /* receive errors */ + u_int ppp_obytes; /* bytes sent */ + u_int ppp_opackets; /* packets sent */ + u_int ppp_oerrors; /* transmit errors */ +}; + +struct vjstat { + u_int vjs_packets; /* outbound packets */ + u_int vjs_compressed; /* outbound compressed packets */ + u_int vjs_searches; /* searches for connection state */ + u_int vjs_misses; /* times couldn't find conn. state */ + u_int vjs_uncompressedin; /* inbound uncompressed packets */ + u_int vjs_compressedin; /* inbound compressed packets */ + u_int vjs_errorin; /* inbound unknown type packets */ + u_int vjs_tossed; /* inbound packets tossed because of error */ +}; + +struct ppp_stats { + struct pppstat p; /* basic PPP statistics */ + struct vjstat vj; /* VJ header compression statistics */ +}; + +struct compstat { + u_int unc_bytes; /* total uncompressed bytes */ + u_int unc_packets; /* total uncompressed packets */ + u_int comp_bytes; /* compressed bytes */ + u_int comp_packets; /* compressed packets */ + u_int inc_bytes; /* incompressible bytes */ + u_int inc_packets; /* incompressible packets */ + u_int ratio; /* recent compression ratio << 8 */ +}; + +struct ppp_comp_stats { + struct compstat c; /* packet compression statistics */ + struct compstat d; /* packet decompression statistics */ +}; + +/* + * The following structure records the time in seconds since + * the last NP packet was sent or received. + */ +struct ppp_idle { + time_t xmit_idle; /* time since last NP packet sent */ + time_t recv_idle; /* time since last NP packet received */ +}; + +#endif /* _PPP_DEFS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/radix.h b/lib/libc/include/generic-openbsd/net/radix.h new file mode 100644 index 0000000000..b16ea54f86 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/radix.h @@ -0,0 +1,112 @@ +/* $OpenBSD: radix.h,v 1.30 2017/06/19 09:42:45 mpi Exp $ */ +/* $NetBSD: radix.h,v 1.8 1996/02/13 22:00:37 christos Exp $ */ + +/* + * Copyright (c) 1988, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)radix.h 8.2 (Berkeley) 10/31/94 + */ + +#ifndef _NET_RADIX_H_ +#define _NET_RADIX_H_ + +/* + * Radix search tree node layout. + */ + +struct radix_node { + struct radix_mask *rn_mklist; /* list of masks contained in subtree */ + struct radix_node *rn_p; /* parent */ + short rn_b; /* bit offset; -1-index(netmask) */ + char rn_bmask; /* node: mask for bit test*/ + u_char rn_flags; /* enumerated next */ +#define RNF_NORMAL 1 /* leaf contains normal route */ +#define RNF_ROOT 2 /* leaf is root leaf for tree */ +#define RNF_ACTIVE 4 /* This node is alive (for rtfree) */ + union { + struct { /* leaf only data: */ + caddr_t rn_Key; /* object of search */ + caddr_t rn_Mask; /* netmask, if present */ + struct radix_node *rn_Dupedkey; + } rn_leaf; + struct { /* node only data: */ + int rn_Off; /* where to start compare */ + struct radix_node *rn_L;/* progeny */ + struct radix_node *rn_R;/* progeny */ + } rn_node; + } rn_u; +}; + +#define rn_dupedkey rn_u.rn_leaf.rn_Dupedkey +#define rn_key rn_u.rn_leaf.rn_Key +#define rn_mask rn_u.rn_leaf.rn_Mask +#define rn_off rn_u.rn_node.rn_Off +#define rn_l rn_u.rn_node.rn_L +#define rn_r rn_u.rn_node.rn_R + +/* + * Annotations to tree concerning potential routes applying to subtrees. + */ + +struct radix_mask { + short rm_b; /* bit offset; -1-index(netmask) */ + char rm_unused; /* cf. rn_bmask */ + u_char rm_flags; /* cf. rn_flags */ + struct radix_mask *rm_mklist; /* more masks to try */ + union { + caddr_t rmu_mask; /* the mask */ + struct radix_node *rmu_leaf; /* for normal routes */ + } rm_rmu; + int rm_refs; /* # of references to this struct */ +}; + +#define rm_mask rm_rmu.rmu_mask +#define rm_leaf rm_rmu.rmu_leaf /* extra field would make 32 bytes */ + +struct radix_node_head { + struct radix_node *rnh_treetop; + int rnh_addrsize; /* permit, but not require fixed keys */ + int rnh_pktsize; /* permit, but not require fixed keys */ + struct radix_node rnh_nodes[3];/* empty tree for common case */ + u_int rnh_rtableid; +}; + +void rn_init(unsigned int); +int rn_inithead(void **, int); + +int rn_walktree(struct radix_node_head *, + int (*)(struct radix_node *, void *, u_int), void *); + +struct radix_node *rn_addroute(void *, void *, struct radix_node_head *, + struct radix_node [2], u_int8_t); +struct radix_node *rn_delete(void *, void *, struct radix_node_head *, + struct radix_node *); +struct radix_node *rn_lookup(void *, void *, struct radix_node_head *); +struct radix_node *rn_match(void *, struct radix_node_head *); + +#endif /* _NET_RADIX_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/route.h b/lib/libc/include/generic-openbsd/net/route.h new file mode 100644 index 0000000000..b37f7156dc --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/route.h @@ -0,0 +1,525 @@ +/* $OpenBSD: route.h,v 1.218 2025/07/14 08:48:51 dlg Exp $ */ +/* $NetBSD: route.h,v 1.9 1996/02/13 22:00:49 christos Exp $ */ + +/* + * Copyright (c) 1980, 1986, 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. + * + * @(#)route.h 8.3 (Berkeley) 4/19/94 + */ + +#ifndef _NET_ROUTE_H_ +#define _NET_ROUTE_H_ + +/* + * Locks used to protect struct members in this file: + * I immutable after creation + * N net lock + * X exclusive net lock, or shared net lock + kernel lock + * R rtable lock + * r per route entry mutex rt_mtx + * L arp/nd6/etc lock for updates, net lock for reads + * T rttimer_mtx route timer lists + */ + +/* + * Kernel resident routing tables. + * + * The routing tables are initialized when interface addresses + * are set by making entries for all directly connected interfaces. + */ + +#ifdef _KERNEL +/* + * These numbers are used by reliable protocols for determining + * retransmission behavior and are included in the routing structure. + */ +struct rt_kmetrics { + u_int64_t rmx_pksent; /* packets sent using this route */ + int64_t rmx_expire; /* lifetime for route, e.g. redirect */ + u_int rmx_locks; /* Kernel must leave these values */ + u_int rmx_mtu; /* [a] MTU for this path */ +}; +#endif + +/* + * Huge version for userland compatibility. + */ +struct rt_metrics { + u_int64_t rmx_pksent; /* packets sent using this route */ + int64_t rmx_expire; /* lifetime for route, e.g. redirect */ + u_int rmx_locks; /* Kernel must leave these values */ + u_int rmx_mtu; /* MTU for this path */ + u_int rmx_refcnt; /* # references hold */ + /* some apps may still need these no longer used metrics */ + u_int rmx_hopcount; /* max hops expected */ + u_int rmx_recvpipe; /* inbound delay-bandwidth product */ + u_int rmx_sendpipe; /* outbound delay-bandwidth product */ + u_int rmx_ssthresh; /* outbound gateway buffer limit */ + u_int rmx_rtt; /* estimated round trip time */ + u_int rmx_rttvar; /* estimated rtt variance */ + u_int rmx_pad; +}; + +#ifdef _KERNEL +/* + * rmx_rtt and rmx_rttvar are stored as microseconds; + * RTTTOPRHZ(rtt) converts to a value suitable for use + * by a protocol slowtimo counter. + */ +#define RTM_RTTUNIT 1000000 /* units for rtt, rttvar, as units per sec */ +#define RTTTOPRHZ(r) ((r) / (RTM_RTTUNIT / PR_SLOWHZ)) + +#include +#include +#include + +struct rttimer; + +/* + * We distinguish between routes to hosts and routes to networks, + * preferring the former if available. For each route we infer + * the interface to use from the gateway address supplied when + * the route was entered. Routes that forward packets through + * gateways are marked with RTF_GATEWAY so that the output routines + * know to address the gateway rather than the ultimate destination. + * + * How the RT_gw union is used also depends on RTF_GATEWAY. With + * RTF_GATEWAY set, rt_gwroute points at the rtentry for the rt_gateway + * address. If RTF_GATEWAY is not set, rt_cachecnt contains the + * number of RTF_GATEWAY rtentry structs with their rt_gwroute pointing + * at this rtentry. + */ + +struct rtentry { + struct sockaddr *rt_dest; /* [I] destination */ + struct rtentry *rt_next; /* [R] next mpath entry to our dst */ + struct sockaddr *rt_gateway; /* [X] gateway address */ + struct ifaddr *rt_ifa; /* [N] interface addr to use */ + caddr_t rt_llinfo; /* [L] pointer to link level info or + an MPLS structure */ + struct rtentry *rt_gwroute; /* [X] rtentry for rt_gateway */ + struct rtentry *rt_parent; /* [N] if cloned, parent rtentry */ + LIST_HEAD(, rttimer) rt_timer; /* queue of timeouts for misc funcs */ + struct mutex rt_mtx; /* lock members of this struct */ + struct refcnt rt_refcnt; /* # held references */ + struct rt_kmetrics rt_rmx; /* metrics used by rx'ing protocols */ + unsigned int rt_cachecnt; /* [r] # gateway rtentry refs */ + unsigned int rt_ifidx; /* [N] interface to use */ + unsigned int rt_flags; /* [X] up/down?, host/net */ + int rt_plen; /* [I] prefix length */ + uint16_t rt_labelid; /* [N] route label ID */ + uint8_t rt_priority; /* [N] routing priority to use */ +}; +#define rt_use rt_rmx.rmx_pksent +#define rt_expire rt_rmx.rmx_expire +#define rt_locks rt_rmx.rmx_locks +#define rt_mtu rt_rmx.rmx_mtu + +#endif /* _KERNEL */ + +/* bitmask values for rtm_flags */ +#define RTF_UP 0x1 /* route usable */ +#define RTF_GATEWAY 0x2 /* destination is a gateway */ +#define RTF_HOST 0x4 /* host entry (net otherwise) */ +#define RTF_REJECT 0x8 /* host or net unreachable */ +#define RTF_DYNAMIC 0x10 /* created dynamically (by redirect) */ +#define RTF_MODIFIED 0x20 /* modified dynamically (by redirect) */ +#define RTF_DONE 0x40 /* message confirmed */ +#define RTF_CLONING 0x100 /* generate new routes on use */ +#define RTF_MULTICAST 0x200 /* route associated to a mcast addr. */ +#define RTF_LLINFO 0x400 /* generated by ARP or ND */ +#define RTF_STATIC 0x800 /* manually added */ +#define RTF_BLACKHOLE 0x1000 /* just discard pkts (during updates) */ +#define RTF_PROTO3 0x2000 /* protocol specific routing flag */ +#define RTF_PROTO2 0x4000 /* protocol specific routing flag */ +#define RTF_ANNOUNCE RTF_PROTO2 /* announce L2 entry */ +#define RTF_PROTO1 0x8000 /* protocol specific routing flag */ +#define RTF_CLONED 0x10000 /* this is a cloned route */ +#define RTF_CACHED 0x20000 /* cached by a RTF_GATEWAY entry */ +#define RTF_MPATH 0x40000 /* multipath route or operation */ +#define RTF_MPLS 0x100000 /* MPLS additional infos */ +#define RTF_LOCAL 0x200000 /* route to a local address */ +#define RTF_BROADCAST 0x400000 /* route associated to a bcast addr. */ +#define RTF_CONNECTED 0x800000 /* interface route */ +#define RTF_BFD 0x1000000 /* Link state controlled by BFD */ + +/* mask of RTF flags that are allowed to be modified by RTM_CHANGE */ +#define RTF_FMASK \ + (RTF_LLINFO | RTF_PROTO1 | RTF_PROTO2 | RTF_PROTO3 | RTF_BLACKHOLE | \ + RTF_REJECT | RTF_STATIC | RTF_MPLS | RTF_BFD) + +/* Routing priorities used by the different routing protocols */ +#define RTP_NONE 0 /* unset priority use sane default */ +#define RTP_LOCAL 1 /* local address routes (must be the highest) */ +#define RTP_CONNECTED 4 /* directly connected routes */ +#define RTP_STATIC 8 /* static routes base priority */ +#define RTP_EIGRP 28 /* EIGRP routes */ +#define RTP_OSPF 32 /* OSPF routes */ +#define RTP_ISIS 36 /* IS-IS routes */ +#define RTP_RIP 40 /* RIP routes */ +#define RTP_BGP 48 /* BGP routes */ +#define RTP_DEFAULT 56 /* routes that have nothing set */ +#define RTP_PROPOSAL_STATIC 57 +#define RTP_PROPOSAL_DHCLIENT 58 +#define RTP_PROPOSAL_SLAAC 59 +#define RTP_PROPOSAL_UMB 60 +#define RTP_PROPOSAL_PPP 61 +#define RTP_PROPOSAL_SOLICIT 62 /* request reply of all RTM_PROPOSAL */ +#define RTP_MAX 63 /* maximum priority */ +#define RTP_ANY 64 /* any of the above */ +#define RTP_MASK 0x7f +#define RTP_DOWN 0x80 /* route/link is down */ + +/* + * Routing statistics. + */ +struct rtstat { + u_int32_t rts_badredirect; /* bogus redirect calls */ + u_int32_t rts_dynamic; /* routes created by redirects */ + u_int32_t rts_newgateway; /* routes modified by redirects */ + u_int32_t rts_unreach; /* lookups which failed */ + u_int32_t rts_wildcard; /* lookups satisfied by a wildcard */ +}; + +/* + * Routing Table Info. + */ +struct rt_tableinfo { + u_short rti_tableid; /* routing table id */ + u_short rti_domainid; /* routing domain id */ +}; + +/* + * Structures for routing messages. + */ +struct rt_msghdr { + u_short rtm_msglen; /* to skip over non-understood messages */ + u_char rtm_version; /* future binary compatibility */ + u_char rtm_type; /* message type */ + u_short rtm_hdrlen; /* sizeof(rt_msghdr) to skip over the header */ + u_short rtm_index; /* index for associated ifp */ + u_short rtm_tableid; /* routing table id */ + u_char rtm_priority; /* routing priority */ + u_char rtm_mpls; /* MPLS additional infos */ + int rtm_addrs; /* bitmask identifying sockaddrs in msg */ + int rtm_flags; /* flags, incl. kern & message, e.g. DONE */ + int rtm_fmask; /* bitmask used in RTM_CHANGE message */ + pid_t rtm_pid; /* identify sender */ + int rtm_seq; /* for sender to identify action */ + int rtm_errno; /* why failed */ + u_int rtm_inits; /* which metrics we are initializing */ + struct rt_metrics rtm_rmx; /* metrics themselves */ +}; +/* overload no longer used field */ +#define rtm_use rtm_rmx.rmx_pksent + +#define RTM_VERSION 5 /* Up the ante and ignore older versions */ + +#define RTM_MAXSIZE 2048 /* Maximum size of an accepted route msg */ + +/* values for rtm_type */ +#define RTM_ADD 0x1 /* Add Route */ +#define RTM_DELETE 0x2 /* Delete Route */ +#define RTM_CHANGE 0x3 /* Change Metrics or flags */ +#define RTM_GET 0x4 /* Report Metrics */ +#define RTM_LOSING 0x5 /* Kernel Suspects Partitioning */ +#define RTM_REDIRECT 0x6 /* Told to use different route */ +#define RTM_MISS 0x7 /* Lookup failed on this address */ +#define RTM_RESOLVE 0xb /* req to resolve dst to LL addr */ +#define RTM_NEWADDR 0xc /* address being added to iface */ +#define RTM_DELADDR 0xd /* address being removed from iface */ +#define RTM_IFINFO 0xe /* iface going up/down etc. */ +#define RTM_IFANNOUNCE 0xf /* iface arrival/departure */ +#define RTM_DESYNC 0x10 /* route socket buffer overflow */ +#define RTM_INVALIDATE 0x11 /* Invalidate cache of L2 route */ +#define RTM_BFD 0x12 /* bidirectional forwarding detection */ +#define RTM_PROPOSAL 0x13 /* proposal for resolvd(8) */ +#define RTM_CHGADDRATTR 0x14 /* address attribute change */ +#define RTM_80211INFO 0x15 /* 80211 iface change */ +#define RTM_SOURCE 0x16 /* set source address */ + +#define RTV_MTU 0x1 /* init or lock _mtu */ +#define RTV_HOPCOUNT 0x2 /* init or lock _hopcount */ +#define RTV_EXPIRE 0x4 /* init or lock _expire */ +#define RTV_RPIPE 0x8 /* init or lock _recvpipe */ +#define RTV_SPIPE 0x10 /* init or lock _sendpipe */ +#define RTV_SSTHRESH 0x20 /* init or lock _ssthresh */ +#define RTV_RTT 0x40 /* init or lock _rtt */ +#define RTV_RTTVAR 0x80 /* init or lock _rttvar */ + +/* + * Bitmask values for rtm_addrs. + */ +#define RTA_DST 0x1 /* destination sockaddr present */ +#define RTA_GATEWAY 0x2 /* gateway sockaddr present */ +#define RTA_NETMASK 0x4 /* netmask sockaddr present */ +#define RTA_GENMASK 0x8 /* cloning mask sockaddr present */ +#define RTA_IFP 0x10 /* interface name sockaddr present */ +#define RTA_IFA 0x20 /* interface addr sockaddr present */ +#define RTA_AUTHOR 0x40 /* sockaddr for author of redirect */ +#define RTA_BRD 0x80 /* for NEWADDR, broadcast or p-p dest addr */ +#define RTA_SRC 0x100 /* source sockaddr present */ +#define RTA_SRCMASK 0x200 /* source netmask present */ +#define RTA_LABEL 0x400 /* route label present */ +#define RTA_BFD 0x800 /* bfd present */ +#define RTA_DNS 0x1000 /* DNS Servers sockaddr present */ +#define RTA_STATIC 0x2000 /* RFC 3442 encoded static routes present */ +#define RTA_SEARCH 0x4000 /* RFC 3397 encoded search path present */ + +/* + * Index offsets for sockaddr array for alternate internal encoding. + */ +#define RTAX_DST 0 /* destination sockaddr present */ +#define RTAX_GATEWAY 1 /* gateway sockaddr present */ +#define RTAX_NETMASK 2 /* netmask sockaddr present */ +#define RTAX_GENMASK 3 /* cloning mask sockaddr present */ +#define RTAX_IFP 4 /* interface name sockaddr present */ +#define RTAX_IFA 5 /* interface addr sockaddr present */ +#define RTAX_AUTHOR 6 /* sockaddr for author of redirect */ +#define RTAX_BRD 7 /* for NEWADDR, broadcast or p-p dest addr */ +#define RTAX_SRC 8 /* source sockaddr present */ +#define RTAX_SRCMASK 9 /* source netmask present */ +#define RTAX_LABEL 10 /* route label present */ +#define RTAX_BFD 11 /* bfd present */ +#define RTAX_DNS 12 /* DNS Server(s) sockaddr present */ +#define RTAX_STATIC 13 /* RFC 3442 encoded static routes present */ +#define RTAX_SEARCH 14 /* RFC 3397 encoded search path present */ +#define RTAX_MAX 15 /* size of array to allocate */ + +/* + * setsockopt defines used for the filtering. + */ +#define ROUTE_MSGFILTER 1 /* bitmask to specify which types should be + sent to the client. */ +#define ROUTE_TABLEFILTER 2 /* change routing table the socket is listening + on, RTABLE_ANY listens on all tables. */ +#define ROUTE_PRIOFILTER 3 /* only pass updates with a priority higher or + equal (actual value lower) to the specified + priority. */ +#define ROUTE_FLAGFILTER 4 /* do not pass updates for routes with flags + in this bitmask. */ + +#define ROUTE_FILTER(m) (1 << (m)) +#define RTABLE_ANY 0xffffffff + +#define RTLABEL_LEN 32 + +struct sockaddr_rtlabel { + u_int8_t sr_len; /* total length */ + sa_family_t sr_family; /* address family */ + char sr_label[RTLABEL_LEN]; +}; + +#define RTDNS_LEN 128 + +struct sockaddr_rtdns { + u_int8_t sr_len; /* total length */ + sa_family_t sr_family; /* address family */ + char sr_dns[RTDNS_LEN]; +}; + +#ifdef _KERNEL + +static inline struct sockaddr * +srtdnstosa(struct sockaddr_rtdns *sdns) +{ + return ((struct sockaddr *)(sdns)); +} + +#endif + +#define RTSTATIC_LEN 128 + +struct sockaddr_rtstatic { + u_int8_t sr_len; /* total length */ + sa_family_t sr_family; /* address family */ + char sr_static[RTSTATIC_LEN]; +}; + +#define RTSEARCH_LEN 128 + +struct sockaddr_rtsearch { + u_int8_t sr_len; /* total length */ + sa_family_t sr_family; /* address family */ + char sr_search[RTSEARCH_LEN]; +}; + +struct rt_addrinfo { + int rti_addrs; + const struct sockaddr *rti_info[RTAX_MAX]; + int rti_flags; + struct ifaddr *rti_ifa; + struct rt_msghdr *rti_rtm; + u_char rti_mpls; +}; + +#ifdef __BSD_VISIBLE + +#include + +/* + * A route consists of a destination address and a reference + * to a routing entry. These are often held by protocols + * in their control blocks, e.g. inpcb. + */ +struct route { + struct rtentry *ro_rt; + u_long ro_generation; + u_long ro_tableid; /* u_long because of alignment */ + union { + struct sockaddr ro_dstsa; + struct sockaddr_in ro_dstsin; + struct sockaddr_in6 ro_dstsin6; + }; + union { + struct in_addr ro_srcin; + struct in6_addr ro_srcin6; + }; +}; + +#endif /* __BSD_VISIBLE */ + +#ifdef _KERNEL + +#include + +enum rtstat_counters { + rts_badredirect, /* bogus redirect calls */ + rts_dynamic, /* routes created by redirects */ + rts_newgateway, /* routes modified by redirects */ + rts_unreach, /* lookups which failed */ + rts_wildcard, /* lookups satisfied by a wildcard */ + + rts_ncounters +}; + +static inline void +rtstat_inc(enum rtstat_counters c) +{ + extern struct cpumem *rtcounters; + + counters_inc(rtcounters, c); +} + +/* + * This structure, and the prototypes for the rt_timer_{init,remove_all, + * add,timer} functions all used with the kind permission of BSDI. + * These allow functions to be called for routes at specific times. + */ +struct rttimer_queue { + TAILQ_HEAD(, rttimer) rtq_head; /* [T] */ + LIST_ENTRY(rttimer_queue) rtq_link; /* [T] */ + void (*rtq_func) /* [I] callback */ + (struct rtentry *, u_int); + unsigned long rtq_count; /* [T] */ + int rtq_timeout; /* [T] */ +}; + +const char *rtlabel_id2name_locked(u_int16_t); +const char *rtlabel_id2name(u_int16_t, char *, size_t); +u_int16_t rtlabel_name2id(const char *); +struct sockaddr *rtlabel_id2sa(u_int16_t, struct sockaddr_rtlabel *); +void rtlabel_unref(u_int16_t); + +/* + * Values for additional argument to rtalloc() + */ +#define RT_RESOLVE 1 + +extern struct rtstat rtstat; +extern u_long rtgeneration; + +struct mbuf; +struct socket; +struct ifnet; +struct sockaddr_in6; +struct if_ieee80211_data; +struct bfd_config; + +void route_init(void); +int route_cache(struct route *, const struct in_addr *, + const struct in_addr *, u_int); +struct rtentry *route_mpath(struct route *, const struct in_addr *, + const struct in_addr *, u_int); +int route6_cache(struct route *, const struct in6_addr *, + const struct in6_addr *, u_int); +struct rtentry *route6_mpath(struct route *, const struct in6_addr *, + const struct in6_addr *, u_int); +void rtm_ifchg(struct ifnet *); +void rtm_ifannounce(struct ifnet *, int); +void rtm_bfd(struct bfd_config *); +void rtm_80211info(struct ifnet *, struct if_ieee80211_data *); +void rt_maskedcopy(struct sockaddr *, + struct sockaddr *, struct sockaddr *); +struct sockaddr *rt_plen2mask(const struct rtentry *, struct sockaddr_in6 *); +void rtm_send(struct rtentry *, int, int, unsigned int); +void rtm_addr(int, struct ifaddr *); +void rtm_miss(int, struct rt_addrinfo *, int, uint8_t, u_int, int, u_int); +void rtm_proposal(struct ifnet *, struct rt_addrinfo *, int, uint8_t); +int rt_setgate(struct rtentry *, const struct sockaddr *, u_int); +struct rtentry *rt_getll(struct rtentry *); + +void rt_timer_init(void); +int rt_timer_add(struct rtentry *, + struct rttimer_queue *, u_int); +void rt_timer_remove_all(struct rtentry *); +time_t rt_timer_get_expire(const struct rtentry *); +void rt_timer_queue_init(struct rttimer_queue *, int, + void(*)(struct rtentry *, u_int)); +void rt_timer_queue_change(struct rttimer_queue *, int); +void rt_timer_queue_flush(struct rttimer_queue *); +unsigned long rt_timer_queue_count(struct rttimer_queue *); +void rt_timer_timer(void *); + +int rt_mpls_set(struct rtentry *, const struct sockaddr *, uint8_t); +void rt_mpls_clear(struct rtentry *); + +int rtisvalid(struct rtentry *); +int rt_hash(struct rtentry *, const struct sockaddr *, uint32_t *); +struct rtentry *rtalloc_mpath(const struct sockaddr *, uint32_t *, u_int); +struct rtentry *rtalloc(const struct sockaddr *, int, unsigned int); +void rtref(struct rtentry *); +void rtfree(struct rtentry *); + +int rt_ifa_add(struct ifaddr *, int, struct sockaddr *, unsigned int); +int rt_ifa_del(struct ifaddr *, int, struct sockaddr *, unsigned int); +void rt_ifa_purge(struct ifaddr *); +int rt_ifa_addlocal(struct ifaddr *); +int rt_ifa_dellocal(struct ifaddr *); +void rtredirect(struct sockaddr *, struct sockaddr *, struct sockaddr *, + struct rtentry **, unsigned int); +int rtrequest(int, struct rt_addrinfo *, u_int8_t, struct rtentry **, + u_int); +int rtrequest_delete(struct rt_addrinfo *, u_int8_t, struct ifnet *, + struct rtentry **, u_int); +int rt_if_track(struct ifnet *); +int rt_if_linkstate_change(struct rtentry *, void *, u_int); +int rtdeletemsg(struct rtentry *, struct ifnet *, u_int); +#endif /* _KERNEL */ + +#endif /* _NET_ROUTE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/rtable.h b/lib/libc/include/generic-openbsd/net/rtable.h new file mode 100644 index 0000000000..23ba0b4a24 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/rtable.h @@ -0,0 +1,82 @@ +/* $OpenBSD: rtable.h,v 1.36 2025/07/15 09:55:49 dlg Exp $ */ + +/* + * Copyright (c) 2014-2016 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 _NET_RTABLE_H_ +#define _NET_RTABLE_H_ + +#include + +struct art; + +/* + * Locks used to protect struct members in this file: + * I immutable after creation + * N net lock + */ + +struct rtable { + struct rwlock r_lock; + struct art *r_art; /* [I] */ + unsigned int r_off; /* [I] Offset of key in bytes */ + + struct sockaddr *r_source; /* [N] use optional src addr */ +}; + +/* + * Newer routing table implementation based on ART (Allotment Routing + * Table). + */ + +#define rt_key(rt) ((rt)->rt_dest) +#define rt_plen(rt) ((rt)->rt_plen) +#define RT_ROOT(rt) (0) + +int rtable_satoplen(sa_family_t, const struct sockaddr *); + +void rtable_init(void); +int rtable_exists(unsigned int); +int rtable_empty(unsigned int); +int rtable_add(unsigned int); +unsigned int rtable_l2(unsigned int); +unsigned int rtable_loindex(unsigned int); +void rtable_l2set(unsigned int, unsigned int, unsigned int); + +int rtable_setsource(unsigned int, int, struct sockaddr *); +struct sockaddr *rtable_getsource(unsigned int, int); +void rtable_clearsource(unsigned int, struct sockaddr *); +struct rtentry *rtable_lookup(unsigned int, const struct sockaddr *, + const struct sockaddr *, const struct sockaddr *, uint8_t); +struct rtentry *rtable_match(unsigned int, const struct sockaddr *, + uint32_t *); +struct rtentry *rtable_iterate(struct rtentry *); +int rtable_insert(unsigned int, struct sockaddr *, + const struct sockaddr *, const struct sockaddr *, uint8_t, + struct rtentry *); +int rtable_delete(unsigned int, const struct sockaddr *, + const struct sockaddr *, struct rtentry *); +int rtable_walk(unsigned int, sa_family_t, struct rtentry **, + int (*)(struct rtentry *, void *, unsigned int), void *); +int rtable_read(unsigned int, sa_family_t, + int (*)(const struct rtentry *, void *, unsigned int), + void *); + +int rtable_mpath_capable(unsigned int, sa_family_t); +int rtable_mpath_reprio(unsigned int, struct sockaddr *, int, + uint8_t, struct rtentry *); + +#endif /* _NET_RTABLE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/slcompress.h b/lib/libc/include/generic-openbsd/net/slcompress.h new file mode 100644 index 0000000000..ee2a6e6258 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/slcompress.h @@ -0,0 +1,167 @@ +/* $OpenBSD: slcompress.h,v 1.10 2017/01/24 10:08:30 krw Exp $ */ +/* $NetBSD: slcompress.h,v 1.11 1997/05/17 21:12:11 christos Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)slcompress.h 8.1 (Berkeley) 6/10/93 + */ + +/* + * Definitions for tcp compression routines. + * + * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989: + * - Initial distribution. + */ + +#ifndef _NET_SLCOMPRESS_H_ +#define _NET_SLCOMPRESS_H_ + +#define MAX_STATES 16 /* must be > 2 and < 256 */ +#define MAX_HDR MLEN /* XXX 4bsd-ism: should really be 128 */ + +/* + * Compressed packet format: + * + * The first octet contains the packet type (top 3 bits), TCP + * 'push' bit, and flags that indicate which of the 4 TCP sequence + * numbers have changed (bottom 5 bits). The next octet is a + * conversation number that associates a saved IP/TCP header with + * the compressed packet. The next two octets are the TCP checksum + * from the original datagram. The next 0 to 15 octets are + * sequence number changes, one change per bit set in the header + * (there may be no changes and there are two special cases where + * the receiver implicitly knows what changed -- see below). + * + * There are 5 numbers which can change (they are always inserted + * in the following order): TCP urgent pointer, window, + * acknowledgement, sequence number and IP ID. (The urgent pointer + * is different from the others in that its value is sent, not the + * change in value.) Since typical use of SLIP links is biased + * toward small packets (see comments on MTU/MSS below), changes + * use a variable length coding with one octet for numbers in the + * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the + * range 256 - 65535 or 0. (If the change in sequence number or + * ack is more than 65535, an uncompressed packet is sent.) + */ + +/* + * Packet types (must not conflict with IP protocol version) + * + * The top nibble of the first octet is the packet type. There are + * three possible types: IP (not proto TCP or tcp with one of the + * control flags set); uncompressed TCP (a normal IP/TCP packet but + * with the 8-bit protocol field replaced by an 8-bit connection id -- + * this type of packet syncs the sender & receiver); and compressed + * TCP (described above). + * + * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and + * is logically part of the 4-bit "changes" field that follows. Top + * three bits are actual packet type. For backward compatibility + * and in the interest of conserving bits, numbers are chosen so the + * IP protocol version number (4) which normally appears in this nibble + * means "IP packet". + */ + +/* packet types */ +#define TYPE_IP 0x40 +#define TYPE_UNCOMPRESSED_TCP 0x70 +#define TYPE_COMPRESSED_TCP 0x80 +#define TYPE_ERROR 0x00 + +/* Bits in first octet of compressed packet */ +#define NEW_C 0x40 /* flag bits for what changed in a packet */ +#define NEW_I 0x20 +#define NEW_S 0x08 +#define NEW_A 0x04 +#define NEW_W 0x02 +#define NEW_U 0x01 + +/* reserved, special-case values of above */ +#define SPECIAL_I (NEW_S|NEW_W|NEW_U) /* echoed interactive traffic */ +#define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U) /* unidirectional data */ +#define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U) + +#define TCP_PUSH_BIT 0x10 + +#ifdef _KERNEL + +/* + * "state" data for each active tcp conversation on the wire. This is + * basically a copy of the entire IP/TCP header from the last packet + * we saw from the conversation together with a small identifier + * the transmit & receive ends of the line use to locate saved header. + */ +struct cstate { + struct cstate *cs_next; /* next most recently used cstate (xmit only) */ + u_int16_t cs_hlen; /* size of hdr (receive only) */ + u_char cs_id; /* connection # associated with this state */ + u_char cs_filler; + union { + char csu_hdr[MAX_HDR]; + struct ip csu_ip; /* ip/tcp hdr from most recent packet */ + } slcs_u; +}; +#define cs_ip slcs_u.csu_ip +#define cs_hdr slcs_u.csu_hdr + +/* + * all the state data for one serial line (we need one of these + * per line). + */ +struct slcompress { + struct cstate *last_cs; /* most recently used tstate */ + u_char last_recv; /* last rcvd conn. id */ + u_char last_xmit; /* last sent conn. id */ + u_int16_t flags; +#ifndef SL_NO_STATS + int sls_packets; /* outbound packets */ + int sls_compressed; /* outbound compressed packets */ + int sls_searches; /* searches for connection state */ + int sls_misses; /* times couldn't find conn. state */ + int sls_uncompressedin; /* inbound uncompressed packets */ + int sls_compressedin; /* inbound compressed packets */ + int sls_errorin; /* inbound unknown type packets */ + int sls_tossed; /* inbound packets tossed because of error */ +#endif + struct cstate tstate[MAX_STATES]; /* xmit connection states */ + struct cstate rstate[MAX_STATES]; /* receive connection states */ +}; +/* flag values */ +#define SLF_TOSS 1 /* tossing rcvd frames because of input err */ + +void sl_compress_init(struct slcompress *); +void sl_compress_setup(struct slcompress *, int); +u_int sl_compress_tcp(struct mbuf *, + struct ip *, struct slcompress *, int); +int sl_uncompress_tcp(u_char **, int, u_int, struct slcompress *); +int sl_uncompress_tcp_core(u_char *, int, int, u_int, + struct slcompress *, u_char **, u_int *); +#endif /* _KERNEL */ + +#endif /* _NET_SLCOMPRESS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/toeplitz.h b/lib/libc/include/generic-openbsd/net/toeplitz.h new file mode 100644 index 0000000000..91a079d6f8 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/toeplitz.h @@ -0,0 +1,143 @@ +/* $OpenBSD: toeplitz.h,v 1.11 2023/05/17 10:22:17 dlg Exp $ */ + +/* + * Copyright (c) 2019 David Gwynne + * + * 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 _SYS_NET_TOEPLITZ_H_ +#define _SYS_NET_TOEPLITZ_H_ + +#include + +/* + * symmetric toeplitz + */ + +typedef uint16_t stoeplitz_key; + +struct stoeplitz_cache { + uint16_t bytes[256]; +}; + +static __unused inline uint16_t +stoeplitz_cache_entry(const struct stoeplitz_cache *scache, uint8_t byte) +{ + return (scache->bytes[byte]); +} + +void stoeplitz_cache_init(struct stoeplitz_cache *, stoeplitz_key); + +uint16_t stoeplitz_hash_ip4(const struct stoeplitz_cache *, + uint32_t, uint32_t); +uint16_t stoeplitz_hash_ip4port(const struct stoeplitz_cache *, + uint32_t, uint32_t, uint16_t, uint16_t); + +#ifdef INET6 +struct in6_addr; +uint16_t stoeplitz_hash_ip6(const struct stoeplitz_cache *, + const struct in6_addr *, const struct in6_addr *); +uint16_t stoeplitz_hash_ip6port(const struct stoeplitz_cache *, + const struct in6_addr *, const struct in6_addr *, + uint16_t, uint16_t); +#endif + +uint16_t stoeplitz_hash_eaddr(const struct stoeplitz_cache *, + const uint8_t *); + +/* hash a uint16_t in network byte order */ +static __unused inline uint16_t +stoeplitz_hash_n16(const struct stoeplitz_cache *scache, uint16_t n16) +{ + uint16_t hi, lo; + + hi = stoeplitz_cache_entry(scache, n16 >> 8); + lo = stoeplitz_cache_entry(scache, n16); + + return (hi ^ swap16(lo)); +} + +/* hash a uint32_t in network byte order */ +static __unused inline uint16_t +stoeplitz_hash_n32(const struct stoeplitz_cache *scache, uint32_t n32) +{ + return (stoeplitz_hash_n16(scache, n32 ^ (n32 >> 16))); +} + +/* hash a uint16_t in host byte order */ +static __unused inline uint16_t +stoeplitz_hash_h16(const struct stoeplitz_cache *scache, uint16_t h16) +{ + uint16_t lo, hi; + + lo = stoeplitz_cache_entry(scache, h16); + hi = stoeplitz_cache_entry(scache, h16 >> 8); + +#if _BYTE_ORDER == _BIG_ENDIAN + return (hi ^ swap16(lo)); +#else + return (swap16(hi) ^ lo); +#endif +} + +static __unused inline uint16_t +stoeplitz_hash_h32(const struct stoeplitz_cache *scache, uint32_t h32) +{ + return (stoeplitz_hash_h16(scache, h32 ^ (h32 >> 16))); +} + +static __unused inline uint16_t +stoeplitz_hash_h64(const struct stoeplitz_cache *scache, uint64_t h64) +{ + return (stoeplitz_hash_h32(scache, h64 ^ (h64 >> 32))); +} + +/* + * system provided symmetric toeplitz + */ + +#define STOEPLITZ_KEYSEED 0x6d5a + +void stoeplitz_init(void); + +void stoeplitz_to_key(void *, size_t) + __bounded((__buffer__, 1, 2)); + +extern const struct stoeplitz_cache *const stoeplitz_cache; + +#define stoeplitz_n16(_n16) \ + stoeplitz_hash_n16(stoeplitz_cache, (_n16)) +#define stoeplitz_n32(_n32) \ + stoeplitz_hash_n32(stoeplitz_cache, (_n32)) +#define stoeplitz_h16(_h16) \ + stoeplitz_hash_h16(stoeplitz_cache, (_h16)) +#define stoeplitz_h32(_h32) \ + stoeplitz_hash_h32(stoeplitz_cache, (_h32)) +#define stoeplitz_h64(_h64) \ + stoeplitz_hash_h64(stoeplitz_cache, (_h64)) +#define stoeplitz_port(_p) stoeplitz_n16((_p)) +#define stoeplitz_ip4(_sa4, _da4) \ + stoeplitz_hash_ip4(stoeplitz_cache, (_sa4), (_da4)) +#define stoeplitz_ip4port(_sa4, _da4, _sp, _dp) \ + stoeplitz_hash_ip4port(stoeplitz_cache, (_sa4), (_da4), (_sp), (_dp)) +#ifdef INET6 +#define stoeplitz_ip6(_sa6, _da6) \ + stoeplitz_hash_ip6(stoeplitz_cache, (_sa6), (_da6)) +#define stoeplitz_ip6port(_sa6, _da6, _sp, _dp) \ + stoeplitz_hash_ip6port(stoeplitz_cache, (_sa6), (_da6), (_sp), (_dp)) +#endif +#define stoeplitz_eaddr(_ea) \ + stoeplitz_hash_eaddr(stoeplitz_cache, (_ea)) + +#endif /* _SYS_NET_TOEPLITZ_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/trunklacp.h b/lib/libc/include/generic-openbsd/net/trunklacp.h new file mode 100644 index 0000000000..597e804bbc --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/trunklacp.h @@ -0,0 +1,316 @@ +/* $OpenBSD: trunklacp.h,v 1.14 2018/08/12 23:50:31 ccardenas Exp $ */ +/* $NetBSD: ieee8023ad_impl.h,v 1.2 2005/12/10 23:21:39 elad Exp $ */ + +/* + * Copyright (c)2005 YAMAMOTO Takashi, + * 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 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 AUTHOR 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. + * + * $FreeBSD: src/sys/net/ieee8023ad_lacp.h,v 1.11 2008/03/17 01:26:44 thompsa Exp $ + */ + +#ifndef _NET_TRUNKLACP_H_ +#define _NET_TRUNKLACP_H_ + +/* + * IEEE802.3 slow protocols (on-wire) definitions. + * XXX should be elsewhere. + */ +#define SLOWPROTOCOLS_SUBTYPE_LACP 1 +#define SLOWPROTOCOLS_SUBTYPE_MARKER 2 + +/* + * default administrative values + */ +#define LACP_DEFAULT_MODE 1 /* Active Mode */ +#define LACP_DEFAULT_TIMEOUT 0 /* Slow Timeout */ +#define LACP_DEFAULT_SYSTEM_PRIO 0x8000 /* Medium Priority */ +#define LACP_LOW_SYSTEM_PRIO 0xffff +#define LACP_HIGH_SYSTEM_PRIO 0x0001 +#define LACP_DEFAULT_PORT_PRIO 0x8000 /* Medium Priority */ +#define LACP_LOW_PORT_PRIO 0xffff +#define LACP_HIGH_PORT_PRIO 0x0001 +#define LACP_DEFAULT_IFQ_PRIO 6 + +struct slowprothdr { + u_int8_t sph_subtype; + u_int8_t sph_version; +} __packed; + +/* TLV on-wire structure. */ +struct tlvhdr { + u_int8_t tlv_type; + u_int8_t tlv_length; + /* u_int8_t tlv_value[]; */ +} __packed; + +/* ... and our implementation. */ +#define TLV_SET(tlv, type, length) \ + do { \ + (tlv)->tlv_type = (type); \ + (tlv)->tlv_length = sizeof(*tlv) + (length); \ + } while (/*CONSTCOND*/0) + +struct tlv_template { + u_int8_t tmpl_type; + u_int8_t tmpl_length; +}; + +struct lacp_systemid { + u_int16_t lsi_prio; + u_int8_t lsi_mac[6]; +} __packed; + +struct lacp_portid { + u_int16_t lpi_prio; + u_int16_t lpi_portno; +} __packed; + +struct lacp_peerinfo { + struct lacp_systemid lip_systemid; + u_int16_t lip_key; + struct lacp_portid lip_portid; + u_int8_t lip_state; + u_int8_t lip_resv[3]; +} __packed; + +struct lacp_collectorinfo { + u_int16_t lci_maxdelay; + u_int8_t lci_resv[12]; +} __packed; + +struct lacpdu { + struct ether_header ldu_eh; + struct slowprothdr ldu_sph; + + struct tlvhdr ldu_tlv_actor; + struct lacp_peerinfo ldu_actor; + struct tlvhdr ldu_tlv_partner; + struct lacp_peerinfo ldu_partner; + struct tlvhdr ldu_tlv_collector; + struct lacp_collectorinfo ldu_collector; + struct tlvhdr ldu_tlv_term; + u_int8_t ldu_resv[50]; +} __packed; + +/* + * IEEE802.3ad marker protocol (on-wire) definitions. + */ +struct lacp_markerinfo { + u_int16_t mi_rq_port; + u_int8_t mi_rq_system[ETHER_ADDR_LEN]; + u_int32_t mi_rq_xid; + u_int8_t mi_pad[2]; +} __packed; + +#define LACP_STATE_BITS \ + "\020" \ + "\001ACTIVITY" \ + "\002TIMEOUT" \ + "\003AGGREGATION" \ + "\004SYNC" \ + "\005COLLECTING" \ + "\006DISTRIBUTING" \ + "\007DEFAULTED" \ + "\010EXPIRED" + +#ifdef _KERNEL + +/* + * IEEE802.3ad LACP implementation details. + */ +#define LACP_TIMER_CURRENT_WHILE 0 +#define LACP_TIMER_PERIODIC 1 +#define LACP_TIMER_WAIT_WHILE 2 +#define LACP_NTIMER 3 + +#define LACP_TIMER_ARM(port, timer, val) \ + (port)->lp_timer[(timer)] = (val) +#define LACP_TIMER_DISARM(port, timer) \ + (port)->lp_timer[(timer)] = 0 +#define LACP_TIMER_ISARMED(port, timer) \ + ((port)->lp_timer[(timer)] > 0) + +/* + * IEEE802.3ad LACP protocol definitions. + */ +#define LACP_STATE_ACTIVITY (1<<0) +#define LACP_STATE_TIMEOUT (1<<1) +#define LACP_STATE_AGGREGATION (1<<2) +#define LACP_STATE_SYNC (1<<3) +#define LACP_STATE_COLLECTING (1<<4) +#define LACP_STATE_DISTRIBUTING (1<<5) +#define LACP_STATE_DEFAULTED (1<<6) +#define LACP_STATE_EXPIRED (1<<7) + +#define LACP_PORT_NTT 0x00000001 +#define LACP_PORT_MARK 0x00000002 + +struct markerdu { + struct ether_header mdu_eh; + struct slowprothdr mdu_sph; + + struct tlvhdr mdu_tlv; + struct lacp_markerinfo mdu_info; + struct tlvhdr mdu_tlv_term; + u_int8_t mdu_resv[90]; +} __packed; + +#define MARKER_TYPE_INFO 0x01 +#define MARKER_TYPE_RESPONSE 0x02 + +enum lacp_selected { + LACP_UNSELECTED, + LACP_STANDBY, /* not used in this implementation */ + LACP_SELECTED, +}; + +enum lacp_mux_state { + LACP_MUX_DETACHED, + LACP_MUX_WAITING, + LACP_MUX_ATTACHED, + LACP_MUX_COLLECTING, + LACP_MUX_DISTRIBUTING, +}; + +#define LACP_MAX_PORTS 32 + +struct lacp_portmap { + int pm_count; + struct lacp_port *pm_map[LACP_MAX_PORTS]; +}; + +struct lacp_port { + TAILQ_ENTRY(lacp_port) lp_dist_q; + LIST_ENTRY(lacp_port) lp_next; + struct lacp_softc *lp_lsc; + struct trunk_port *lp_trunk; + struct ifnet *lp_ifp; + struct lacp_peerinfo lp_partner; + struct lacp_peerinfo lp_actor; + struct lacp_markerinfo lp_marker; +#define lp_state lp_actor.lip_state +#define lp_key lp_actor.lip_key +#define lp_systemid lp_actor.lip_systemid + struct timeval lp_last_lacpdu; + int lp_lacpdu_sent; + enum lacp_mux_state lp_mux_state; + enum lacp_selected lp_selected; + int lp_flags; + u_int lp_media; /* XXX redundant */ + int lp_timer[LACP_NTIMER]; + struct mbuf_queue lp_mq; + + struct lacp_aggregator *lp_aggregator; +}; + +struct lacp_aggregator { + TAILQ_ENTRY(lacp_aggregator) la_q; + int la_refcnt; /* num of ports which selected us */ + int la_nports; /* num of distributing ports */ + TAILQ_HEAD(, lacp_port) la_ports; /* distributing ports */ + struct lacp_peerinfo la_partner; + struct lacp_peerinfo la_actor; + int la_pending; /* number of ports in wait_while */ +}; + +struct lacp_admin_def { + u_int8_t lad_mode; /* active or passive */ + u_int8_t lad_timeout; /* fast or slow */ + u_int16_t lad_prio; /* system priority */ + u_int16_t lad_portprio; /* port priority */ + u_int8_t lad_ifqprio; /* ifq priority */ +}; + +struct lacp_softc { + struct trunk_softc *lsc_softc; + struct lacp_aggregator *lsc_active_aggregator; + TAILQ_HEAD(, lacp_aggregator) lsc_aggregators; + int lsc_suppress_distributing; + struct timeout lsc_transit_callout; + struct timeout lsc_callout; + LIST_HEAD(, lacp_port) lsc_ports; + struct lacp_portmap lsc_pmap[2]; + volatile u_int lsc_activemap; + SIPHASH_KEY lsc_hashkey; + struct task lsc_input; + struct lacp_admin_def lsc_admin_defaults; +#define lsc_mode lsc_admin_defaults.lad_mode +#define lsc_timeout lsc_admin_defaults.lad_timeout +#define lsc_sys_prio lsc_admin_defaults.lad_prio +#define lsc_port_prio lsc_admin_defaults.lad_portprio +#define lsc_ifq_prio lsc_admin_defaults.lad_ifqprio +}; + +#define LACP_TYPE_ACTORINFO 1 +#define LACP_TYPE_PARTNERINFO 2 +#define LACP_TYPE_COLLECTORINFO 3 + +/* timeout values (in sec) */ +#define LACP_FAST_PERIODIC_TIME (1) +#define LACP_SLOW_PERIODIC_TIME (30) +#define LACP_SHORT_TIMEOUT_TIME (3 * LACP_FAST_PERIODIC_TIME) +#define LACP_LONG_TIMEOUT_TIME (3 * LACP_SLOW_PERIODIC_TIME) +#define LACP_CHURN_DETECTION_TIME (60) +#define LACP_AGGREGATE_WAIT_TIME (2) +#define LACP_TRANSIT_DELAY 3000 /* in msec */ + +#define LACP_STATE_EQ(s1, s2, mask) \ + ((((s1) ^ (s2)) & (mask)) == 0) + +#define LACP_SYS_PRI(peer) (peer).lip_systemid.lsi_prio + +#define LACP_PORT(_lp) ((struct lacp_port *)(_lp)->tp_psc) +#define LACP_SOFTC(_sc) ((struct lacp_softc *)(_sc)->tr_psc) + +int lacp_input(struct trunk_port *, struct mbuf *); +struct trunk_port *lacp_select_tx_port(struct trunk_softc *, struct mbuf *); +int lacp_attach(struct trunk_softc *); +int lacp_detach(struct trunk_softc *); +void lacp_init(struct trunk_softc *); +void lacp_stop(struct trunk_softc *); +int lacp_port_create(struct trunk_port *); +void lacp_port_destroy(struct trunk_port *); +void lacp_linkstate(struct trunk_port *); +void lacp_req(struct trunk_softc *, caddr_t); +void lacp_portreq(struct trunk_port *, caddr_t); +u_int lacp_port_status(struct trunk_port *); + +/* following constants don't include terminating NUL */ +#define LACP_MACSTR_MAX (2*6 + 5) +#define LACP_SYSTEMPRIOSTR_MAX (4) +#define LACP_SYSTEMIDSTR_MAX (LACP_SYSTEMPRIOSTR_MAX + 1 + LACP_MACSTR_MAX) +#define LACP_PORTPRIOSTR_MAX (4) +#define LACP_PORTNOSTR_MAX (4) +#define LACP_PORTIDSTR_MAX (LACP_PORTPRIOSTR_MAX + 1 + LACP_PORTNOSTR_MAX) +#define LACP_KEYSTR_MAX (4) +#define LACP_PARTNERSTR_MAX \ + (1 + LACP_SYSTEMIDSTR_MAX + 1 + LACP_KEYSTR_MAX + 1 \ + + LACP_PORTIDSTR_MAX + 1) +#define LACP_LAGIDSTR_MAX \ + (1 + LACP_PARTNERSTR_MAX + 1 + LACP_PARTNERSTR_MAX + 1) +#define LACP_STATESTR_MAX (255) /* XXX */ + +#endif /* _KERNEL */ + +#endif /* _NET_TRUNKLACP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/wg_cookie.h b/lib/libc/include/generic-openbsd/net/wg_cookie.h new file mode 100644 index 0000000000..518b18a14a --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/wg_cookie.h @@ -0,0 +1,132 @@ +/* $OpenBSD: wg_cookie.h,v 1.2 2020/12/09 05:53:33 tb Exp $ */ +/* + * Copyright (C) 2015-2020 Jason A. Donenfeld . All Rights Reserved. + * Copyright (C) 2019-2020 Matt Dunwoodie + * + * 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 __COOKIE_H__ +#define __COOKIE_H__ + +#include +#include +#include +#include + +#include + +#include +#include +#include + +#define COOKIE_MAC_SIZE 16 +#define COOKIE_KEY_SIZE 32 +#define COOKIE_NONCE_SIZE XCHACHA20POLY1305_NONCE_SIZE +#define COOKIE_COOKIE_SIZE 16 +#define COOKIE_SECRET_SIZE 32 +#define COOKIE_INPUT_SIZE 32 +#define COOKIE_ENCRYPTED_SIZE (COOKIE_COOKIE_SIZE + COOKIE_MAC_SIZE) + +#define COOKIE_MAC1_KEY_LABEL "mac1----" +#define COOKIE_COOKIE_KEY_LABEL "cookie--" +#define COOKIE_SECRET_MAX_AGE 120 +#define COOKIE_SECRET_LATENCY 5 + +/* Constants for initiation rate limiting */ +#define RATELIMIT_SIZE (1 << 13) +#define RATELIMIT_SIZE_MAX (RATELIMIT_SIZE * 8) +#define NSEC_PER_SEC 1000000000LL +#define INITIATIONS_PER_SECOND 20 +#define INITIATIONS_BURSTABLE 5 +#define INITIATION_COST (NSEC_PER_SEC / INITIATIONS_PER_SECOND) +#define TOKEN_MAX (INITIATION_COST * INITIATIONS_BURSTABLE) +#define ELEMENT_TIMEOUT 1 +#define IPV4_MASK_SIZE 4 /* Use all 4 bytes of IPv4 address */ +#define IPV6_MASK_SIZE 8 /* Use top 8 bytes (/64) of IPv6 address */ + +struct cookie_macs { + uint8_t mac1[COOKIE_MAC_SIZE]; + uint8_t mac2[COOKIE_MAC_SIZE]; +}; + +struct ratelimit_entry { + LIST_ENTRY(ratelimit_entry) r_entry; + sa_family_t r_af; + union { + struct in_addr r_in; +#ifdef INET6 + struct in6_addr r_in6; +#endif + }; + struct timespec r_last_time; /* nanouptime */ + uint64_t r_tokens; +}; + +struct ratelimit { + SIPHASH_KEY rl_secret; + struct pool *rl_pool; + + struct rwlock rl_lock; + LIST_HEAD(, ratelimit_entry) *rl_table; + u_long rl_table_mask; + size_t rl_table_num; + struct timespec rl_last_gc; /* nanouptime */ +}; + +struct cookie_maker { + uint8_t cp_mac1_key[COOKIE_KEY_SIZE]; + uint8_t cp_cookie_key[COOKIE_KEY_SIZE]; + + struct rwlock cp_lock; + uint8_t cp_cookie[COOKIE_COOKIE_SIZE]; + struct timespec cp_birthdate; /* nanouptime */ + int cp_mac1_valid; + uint8_t cp_mac1_last[COOKIE_MAC_SIZE]; +}; + +struct cookie_checker { + struct ratelimit cc_ratelimit_v4; +#ifdef INET6 + struct ratelimit cc_ratelimit_v6; +#endif + + struct rwlock cc_key_lock; + uint8_t cc_mac1_key[COOKIE_KEY_SIZE]; + uint8_t cc_cookie_key[COOKIE_KEY_SIZE]; + + struct rwlock cc_secret_lock; + struct timespec cc_secret_birthdate; /* nanouptime */ + uint8_t cc_secret[COOKIE_SECRET_SIZE]; +}; + +void cookie_maker_init(struct cookie_maker *, uint8_t[COOKIE_INPUT_SIZE]); +int cookie_checker_init(struct cookie_checker *, struct pool *); +void cookie_checker_update(struct cookie_checker *, + uint8_t[COOKIE_INPUT_SIZE]); +void cookie_checker_deinit(struct cookie_checker *); +void cookie_checker_create_payload(struct cookie_checker *, + struct cookie_macs *cm, uint8_t[COOKIE_NONCE_SIZE], + uint8_t [COOKIE_ENCRYPTED_SIZE], struct sockaddr *); +int cookie_maker_consume_payload(struct cookie_maker *, + uint8_t[COOKIE_NONCE_SIZE], uint8_t[COOKIE_ENCRYPTED_SIZE]); +void cookie_maker_mac(struct cookie_maker *, struct cookie_macs *, + void *, size_t); +int cookie_checker_validate_macs(struct cookie_checker *, + struct cookie_macs *, void *, size_t, int, struct sockaddr *); + +#ifdef WGTEST +void cookie_test(); +#endif /* WGTEST */ + +#endif /* __COOKIE_H__ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net/wg_noise.h b/lib/libc/include/generic-openbsd/net/wg_noise.h new file mode 100644 index 0000000000..0e4fe016e7 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net/wg_noise.h @@ -0,0 +1,197 @@ +/* $OpenBSD: wg_noise.h,v 1.3 2024/03/05 17:48:01 mvs Exp $ */ +/* + * Copyright (C) 2015-2020 Jason A. Donenfeld . All Rights Reserved. + * Copyright (C) 2019-2020 Matt Dunwoodie + * + * 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 __NOISE_H__ +#define __NOISE_H__ + +#include +#include +#include +#include + +#include +#include +#include + +#define NOISE_PUBLIC_KEY_LEN CURVE25519_KEY_SIZE +#define NOISE_SYMMETRIC_KEY_LEN CHACHA20POLY1305_KEY_SIZE +#define NOISE_TIMESTAMP_LEN (sizeof(uint64_t) + sizeof(uint32_t)) +#define NOISE_AUTHTAG_LEN CHACHA20POLY1305_AUTHTAG_SIZE +#define NOISE_HASH_LEN BLAKE2S_HASH_SIZE + +/* Protocol string constants */ +#define NOISE_HANDSHAKE_NAME "Noise_IKpsk2_25519_ChaChaPoly_BLAKE2s" +#define NOISE_IDENTIFIER_NAME "WireGuard v1 zx2c4 Jason@zx2c4.com" + +/* Constants for the counter */ +#define COUNTER_BITS_TOTAL 8192 +#define COUNTER_BITS (sizeof(unsigned long) * 8) +#define COUNTER_NUM (COUNTER_BITS_TOTAL / COUNTER_BITS) +#define COUNTER_WINDOW_SIZE (COUNTER_BITS_TOTAL - COUNTER_BITS) + +/* Constants for the keypair */ +#define REKEY_AFTER_MESSAGES (1ull << 60) +#define REJECT_AFTER_MESSAGES (UINT64_MAX - COUNTER_WINDOW_SIZE - 1) +#define REKEY_AFTER_TIME 120 +#define REKEY_AFTER_TIME_RECV 165 +#define REJECT_AFTER_TIME 180 +#define REJECT_INTERVAL (1000000000 / 50) /* fifty times per sec */ +/* 24 = floor(log2(REJECT_INTERVAL)) */ +#define REJECT_INTERVAL_MASK (~((1ull<<24)-1)) + +enum noise_state_hs { + HS_ZEROED = 0, + CREATED_INITIATION, + CONSUMED_INITIATION, + CREATED_RESPONSE, + CONSUMED_RESPONSE, +}; + +struct noise_handshake { + enum noise_state_hs hs_state; + uint32_t hs_local_index; + uint32_t hs_remote_index; + uint8_t hs_e[NOISE_PUBLIC_KEY_LEN]; + uint8_t hs_hash[NOISE_HASH_LEN]; + uint8_t hs_ck[NOISE_HASH_LEN]; +}; + +struct noise_counter { + struct mutex c_mtx; + uint64_t c_send; + uint64_t c_recv; + unsigned long c_backtrack[COUNTER_NUM]; +}; + +struct noise_keypair { + SLIST_ENTRY(noise_keypair) kp_entry; + int kp_valid; + int kp_is_initiator; + uint32_t kp_local_index; + uint32_t kp_remote_index; + uint8_t kp_send[NOISE_SYMMETRIC_KEY_LEN]; + uint8_t kp_recv[NOISE_SYMMETRIC_KEY_LEN]; + struct timespec kp_birthdate; /* nanouptime */ + struct noise_counter kp_ctr; +}; + +struct noise_remote { + uint8_t r_public[NOISE_PUBLIC_KEY_LEN]; + struct noise_local *r_local; + uint8_t r_ss[NOISE_PUBLIC_KEY_LEN]; + + struct rwlock r_handshake_lock; + struct noise_handshake r_handshake; + uint8_t r_psk[NOISE_SYMMETRIC_KEY_LEN]; + uint8_t r_timestamp[NOISE_TIMESTAMP_LEN]; + struct timespec r_last_init; /* nanouptime */ + + struct mutex r_keypair_mtx; + SLIST_HEAD(,noise_keypair) r_unused_keypairs; + struct noise_keypair *r_next, *r_current, *r_previous; + struct noise_keypair r_keypair[3]; /* 3: next, current, previous. */ + +}; + +struct noise_local { + struct rwlock l_identity_lock; + int l_has_identity; + uint8_t l_public[NOISE_PUBLIC_KEY_LEN]; + uint8_t l_private[NOISE_PUBLIC_KEY_LEN]; + + struct noise_upcall { + void *u_arg; + struct noise_remote * + (*u_remote_get)(void *, uint8_t[NOISE_PUBLIC_KEY_LEN]); + uint32_t + (*u_index_set)(void *, struct noise_remote *); + void (*u_index_drop)(void *, uint32_t); + } l_upcall; +}; + +/* Set/Get noise parameters */ +void noise_local_init(struct noise_local *, struct noise_upcall *); +void noise_local_lock_identity(struct noise_local *); +void noise_local_unlock_identity(struct noise_local *); +int noise_local_set_private(struct noise_local *, uint8_t[NOISE_PUBLIC_KEY_LEN]); +int noise_local_keys(struct noise_local *, uint8_t[NOISE_PUBLIC_KEY_LEN], + uint8_t[NOISE_PUBLIC_KEY_LEN]); + +void noise_remote_init(struct noise_remote *, uint8_t[NOISE_PUBLIC_KEY_LEN], + struct noise_local *); +int noise_remote_set_psk(struct noise_remote *, uint8_t[NOISE_SYMMETRIC_KEY_LEN]); +int noise_remote_keys(struct noise_remote *, uint8_t[NOISE_PUBLIC_KEY_LEN], + uint8_t[NOISE_SYMMETRIC_KEY_LEN]); + +/* Should be called anytime noise_local_set_private is called */ +void noise_remote_precompute(struct noise_remote *); + +/* Cryptographic functions */ +int noise_create_initiation( + struct noise_remote *, + uint32_t *s_idx, + uint8_t ue[NOISE_PUBLIC_KEY_LEN], + uint8_t es[NOISE_PUBLIC_KEY_LEN + NOISE_AUTHTAG_LEN], + uint8_t ets[NOISE_TIMESTAMP_LEN + NOISE_AUTHTAG_LEN]); + +int noise_consume_initiation( + struct noise_local *, + struct noise_remote **, + uint32_t s_idx, + uint8_t ue[NOISE_PUBLIC_KEY_LEN], + uint8_t es[NOISE_PUBLIC_KEY_LEN + NOISE_AUTHTAG_LEN], + uint8_t ets[NOISE_TIMESTAMP_LEN + NOISE_AUTHTAG_LEN]); + +int noise_create_response( + struct noise_remote *, + uint32_t *s_idx, + uint32_t *r_idx, + uint8_t ue[NOISE_PUBLIC_KEY_LEN], + uint8_t en[0 + NOISE_AUTHTAG_LEN]); + +int noise_consume_response( + struct noise_remote *, + uint32_t s_idx, + uint32_t r_idx, + uint8_t ue[NOISE_PUBLIC_KEY_LEN], + uint8_t en[0 + NOISE_AUTHTAG_LEN]); + +int noise_remote_begin_session(struct noise_remote *); +void noise_remote_clear(struct noise_remote *); +void noise_remote_expire_current(struct noise_remote *); + +int noise_remote_ready(struct noise_remote *); + +int noise_remote_encrypt( + struct noise_remote *, + uint32_t *r_idx, + uint64_t *nonce, + uint8_t *buf, + size_t buflen); +int noise_remote_decrypt( + struct noise_remote *, + uint32_t r_idx, + uint64_t nonce, + uint8_t *buf, + size_t buflen); + +#ifdef WGTEST +void noise_test(); +#endif /* WGTEST */ + +#endif /* __NOISE_H__ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net80211/ieee80211.h b/lib/libc/include/generic-openbsd/net80211/ieee80211.h new file mode 100644 index 0000000000..12e9748e9f --- /dev/null +++ b/lib/libc/include/generic-openbsd/net80211/ieee80211.h @@ -0,0 +1,1117 @@ +/* $OpenBSD: ieee80211.h,v 1.64 2025/08/04 11:39:50 stsp Exp $ */ +/* $NetBSD: ieee80211.h,v 1.6 2004/04/30 23:51:53 dyoung Exp $ */ + +/*- + * Copyright (c) 2001 Atsushi Onoe + * Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting + * 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 _NET80211_IEEE80211_H_ +#define _NET80211_IEEE80211_H_ + +/* + * 802.11 protocol definitions. + */ + +#define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */ +/* is 802.11 address multicast/broadcast? */ +#define IEEE80211_IS_MULTICAST(_a) (*(_a) & 0x01) + +/* + * Generic definitions for IEEE 802.11 frames. + */ +struct ieee80211_frame { + u_int8_t i_fc[2]; + u_int8_t i_dur[2]; + u_int8_t i_addr1[IEEE80211_ADDR_LEN]; + u_int8_t i_addr2[IEEE80211_ADDR_LEN]; + u_int8_t i_addr3[IEEE80211_ADDR_LEN]; + u_int8_t i_seq[2]; +} __packed; + +struct ieee80211_qosframe { + u_int8_t i_fc[2]; + u_int8_t i_dur[2]; + u_int8_t i_addr1[IEEE80211_ADDR_LEN]; + u_int8_t i_addr2[IEEE80211_ADDR_LEN]; + u_int8_t i_addr3[IEEE80211_ADDR_LEN]; + u_int8_t i_seq[2]; + u_int8_t i_qos[2]; +} __packed; + +struct ieee80211_htframe { /* 11n */ + u_int8_t i_fc[2]; + u_int8_t i_dur[2]; + u_int8_t i_addr1[IEEE80211_ADDR_LEN]; + u_int8_t i_addr2[IEEE80211_ADDR_LEN]; + u_int8_t i_addr3[IEEE80211_ADDR_LEN]; + u_int8_t i_seq[2]; + u_int8_t i_qos[2]; + u_int8_t i_ht[4]; +} __packed; + +struct ieee80211_frame_addr4 { + u_int8_t i_fc[2]; + u_int8_t i_dur[2]; + u_int8_t i_addr1[IEEE80211_ADDR_LEN]; + u_int8_t i_addr2[IEEE80211_ADDR_LEN]; + u_int8_t i_addr3[IEEE80211_ADDR_LEN]; + u_int8_t i_seq[2]; + u_int8_t i_addr4[IEEE80211_ADDR_LEN]; +} __packed; + +struct ieee80211_qosframe_addr4 { + u_int8_t i_fc[2]; + u_int8_t i_dur[2]; + u_int8_t i_addr1[IEEE80211_ADDR_LEN]; + u_int8_t i_addr2[IEEE80211_ADDR_LEN]; + u_int8_t i_addr3[IEEE80211_ADDR_LEN]; + u_int8_t i_seq[2]; + u_int8_t i_addr4[IEEE80211_ADDR_LEN]; + u_int8_t i_qos[2]; +} __packed; + +struct ieee80211_htframe_addr4 { /* 11n */ + u_int8_t i_fc[2]; + u_int8_t i_dur[2]; + u_int8_t i_addr1[IEEE80211_ADDR_LEN]; + u_int8_t i_addr2[IEEE80211_ADDR_LEN]; + u_int8_t i_addr3[IEEE80211_ADDR_LEN]; + u_int8_t i_seq[2]; + u_int8_t i_addr4[IEEE80211_ADDR_LEN]; + u_int8_t i_qos[2]; + u_int8_t i_ht[4]; +} __packed; + +#define IEEE80211_MAX_FRAME_HDR_LEN (sizeof(struct ieee80211_htframe_addr4)) + +#define IEEE80211_FC0_VERSION_MASK 0x03 +#define IEEE80211_FC0_VERSION_SHIFT 0 +#define IEEE80211_FC0_VERSION_0 0x00 +#define IEEE80211_FC0_TYPE_MASK 0x0c +#define IEEE80211_FC0_TYPE_SHIFT 2 +#define IEEE80211_FC0_TYPE_MGT 0x00 +#define IEEE80211_FC0_TYPE_CTL 0x04 +#define IEEE80211_FC0_TYPE_DATA 0x08 + +#define IEEE80211_FC0_SUBTYPE_MASK 0xf0 +#define IEEE80211_FC0_SUBTYPE_SHIFT 4 +/* for TYPE_MGT */ +#define IEEE80211_FC0_SUBTYPE_ASSOC_REQ 0x00 +#define IEEE80211_FC0_SUBTYPE_ASSOC_RESP 0x10 +#define IEEE80211_FC0_SUBTYPE_REASSOC_REQ 0x20 +#define IEEE80211_FC0_SUBTYPE_REASSOC_RESP 0x30 +#define IEEE80211_FC0_SUBTYPE_PROBE_REQ 0x40 +#define IEEE80211_FC0_SUBTYPE_PROBE_RESP 0x50 +#define IEEE80211_FC0_SUBTYPE_BEACON 0x80 +#define IEEE80211_FC0_SUBTYPE_ATIM 0x90 +#define IEEE80211_FC0_SUBTYPE_DISASSOC 0xa0 +#define IEEE80211_FC0_SUBTYPE_AUTH 0xb0 +#define IEEE80211_FC0_SUBTYPE_DEAUTH 0xc0 +#define IEEE80211_FC0_SUBTYPE_ACTION 0xd0 +#define IEEE80211_FC0_SUBTYPE_ACTION_NOACK 0xe0 /* 11n */ +/* for TYPE_CTL */ +#define IEEE80211_FC0_SUBTYPE_WRAPPER 0x70 /* 11n */ +#define IEEE80211_FC0_SUBTYPE_BAR 0x80 +#define IEEE80211_FC0_SUBTYPE_BA 0x90 +#define IEEE80211_FC0_SUBTYPE_PS_POLL 0xa0 +#define IEEE80211_FC0_SUBTYPE_RTS 0xb0 +#define IEEE80211_FC0_SUBTYPE_CTS 0xc0 +#define IEEE80211_FC0_SUBTYPE_ACK 0xd0 +#define IEEE80211_FC0_SUBTYPE_CF_END 0xe0 +#define IEEE80211_FC0_SUBTYPE_CF_END_ACK 0xf0 +/* for TYPE_DATA (bit combination) */ +#define IEEE80211_FC0_SUBTYPE_DATA 0x00 +#define IEEE80211_FC0_SUBTYPE_DATA_CF_ACK 0x10 +#define IEEE80211_FC0_SUBTYPE_DATA_CF_POLL 0x20 +#define IEEE80211_FC0_SUBTYPE_DATA_CF_ACKPOLL 0x30 +#define IEEE80211_FC0_SUBTYPE_NODATA 0x40 +#define IEEE80211_FC0_SUBTYPE_NODATA_CF_ACK 0x50 +#define IEEE80211_FC0_SUBTYPE_NODATA_CF_POLL 0x60 +#define IEEE80211_FC0_SUBTYPE_NODATA_CF_ACKPOLL 0x70 +#define IEEE80211_FC0_SUBTYPE_QOS 0x80 + +#define IEEE80211_FC1_DIR_MASK 0x03 +#define IEEE80211_FC1_DIR_NODS 0x00 /* STA->STA */ +#define IEEE80211_FC1_DIR_TODS 0x01 /* STA->AP */ +#define IEEE80211_FC1_DIR_FROMDS 0x02 /* AP ->STA */ +#define IEEE80211_FC1_DIR_DSTODS 0x03 /* AP ->AP */ + +#define IEEE80211_FC1_MORE_FRAG 0x04 +#define IEEE80211_FC1_RETRY 0x08 +#define IEEE80211_FC1_PWR_MGT 0x10 +#define IEEE80211_FC1_MORE_DATA 0x20 +#define IEEE80211_FC1_PROTECTED 0x40 +#define IEEE80211_FC1_WEP 0x40 /* pre-RSNA compat */ +#define IEEE80211_FC1_ORDER 0x80 +#define IEEE80211_FC1_BITS \ + "\20\03MORE_FRAG\04RETRY\05PWR_MGT\06MORE_DATA" \ + "\07PROTECTED\08ORDER" + +/* + * Sequence Control field (see 802.11-2012 8.2.4.4). + */ +#define IEEE80211_SEQ_FRAG_MASK 0x000f +#define IEEE80211_SEQ_FRAG_SHIFT 0 +#define IEEE80211_SEQ_SEQ_MASK 0xfff0 +#define IEEE80211_SEQ_SEQ_SHIFT 4 + +#define IEEE80211_NWID_LEN 32 +#define IEEE80211_MMIE_LEN 18 /* 11w */ + +/* + * QoS Control field (see 802.11-2012 8.2.4.5). + */ +#define IEEE80211_QOS_TXOP 0xff00 +#define IEEE80211_QOS_AMSDU 0x0080 /* 11n */ +#define IEEE80211_QOS_ACK_POLICY_NORMAL 0x0000 +#define IEEE80211_QOS_ACK_POLICY_NOACK 0x0020 +#define IEEE80211_QOS_ACK_POLICY_NOEXPLACK 0x0040 +#define IEEE80211_QOS_ACK_POLICY_BA 0x0060 +#define IEEE80211_QOS_ACK_POLICY_MASK 0x0060 +#define IEEE80211_QOS_ACK_POLICY_SHIFT 5 +#define IEEE80211_QOS_EOSP 0x0010 +#define IEEE80211_QOS_TID 0x000f + +/* + * Control frames. + */ +struct ieee80211_frame_min { + u_int8_t i_fc[2]; + u_int8_t i_dur[2]; + u_int8_t i_addr1[IEEE80211_ADDR_LEN]; + u_int8_t i_addr2[IEEE80211_ADDR_LEN]; + /* FCS */ +} __packed; + +struct ieee80211_frame_rts { + u_int8_t i_fc[2]; + u_int8_t i_dur[2]; + u_int8_t i_ra[IEEE80211_ADDR_LEN]; + u_int8_t i_ta[IEEE80211_ADDR_LEN]; + /* FCS */ +} __packed; + +struct ieee80211_frame_cts { + u_int8_t i_fc[2]; + u_int8_t i_dur[2]; + u_int8_t i_ra[IEEE80211_ADDR_LEN]; + /* FCS */ +} __packed; + +struct ieee80211_frame_ack { + u_int8_t i_fc[2]; + u_int8_t i_dur[2]; + u_int8_t i_ra[IEEE80211_ADDR_LEN]; + /* FCS */ +} __packed; + +struct ieee80211_frame_pspoll { + u_int8_t i_fc[2]; + u_int8_t i_aid[2]; + u_int8_t i_bssid[IEEE80211_ADDR_LEN]; + u_int8_t i_ta[IEEE80211_ADDR_LEN]; + /* FCS */ +} __packed; + +struct ieee80211_frame_cfend { /* NB: also CF-End+CF-Ack */ + u_int8_t i_fc[2]; + u_int8_t i_dur[2]; /* should be zero */ + u_int8_t i_ra[IEEE80211_ADDR_LEN]; + u_int8_t i_bssid[IEEE80211_ADDR_LEN]; + /* FCS */ +} __packed; + +#ifdef _KERNEL +static __inline int +ieee80211_has_seq(const struct ieee80211_frame *wh) +{ + return (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) != + IEEE80211_FC0_TYPE_CTL; +} + +static __inline int +ieee80211_has_addr4(const struct ieee80211_frame *wh) +{ + return (wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) == + IEEE80211_FC1_DIR_DSTODS; +} + +static __inline int +ieee80211_has_qos(const struct ieee80211_frame *wh) +{ + return (wh->i_fc[0] & + (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_QOS)) == + (IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_QOS); +} + +static __inline int +ieee80211_has_htc(const struct ieee80211_frame *wh) +{ + return (wh->i_fc[1] & IEEE80211_FC1_ORDER) && + (ieee80211_has_qos(wh) || + (wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) == + IEEE80211_FC0_TYPE_MGT); +} + +static __inline u_int16_t +ieee80211_get_qos(const struct ieee80211_frame *wh) +{ + const u_int8_t *frm; + + if (ieee80211_has_addr4(wh)) + frm = ((const struct ieee80211_qosframe_addr4 *)wh)->i_qos; + else + frm = ((const struct ieee80211_qosframe *)wh)->i_qos; + + return letoh16(*(const u_int16_t *)frm); +} +#endif /* _KERNEL */ + +/* + * Capability Information field (see 802.11-2012 8.4.1.4). + */ +#define IEEE80211_CAPINFO_ESS 0x0001 +#define IEEE80211_CAPINFO_IBSS 0x0002 +#define IEEE80211_CAPINFO_CF_POLLABLE 0x0004 +#define IEEE80211_CAPINFO_CF_POLLREQ 0x0008 +#define IEEE80211_CAPINFO_PRIVACY 0x0010 +#define IEEE80211_CAPINFO_SHORT_PREAMBLE 0x0020 +#define IEEE80211_CAPINFO_PBCC 0x0040 +#define IEEE80211_CAPINFO_CHNL_AGILITY 0x0080 +#define IEEE80211_CAPINFO_SPECTRUM_MGMT 0x0100 +#define IEEE80211_CAPINFO_QOS 0x0200 +#define IEEE80211_CAPINFO_SHORT_SLOTTIME 0x0400 +#define IEEE80211_CAPINFO_APSD 0x0800 +#define IEEE80211_CAPINFO_RADIO_MEASUREMENT 0x1000 +#define IEEE80211_CAPINFO_DSSSOFDM 0x2000 +#define IEEE80211_CAPINFO_DELAYED_B_ACK 0x4000 +#define IEEE80211_CAPINFO_IMMEDIATE_B_ACK 0x8000 +#define IEEE80211_CAPINFO_BITS \ + "\10\01ESS\02IBSS\03CF_POLLABLE\04CF_POLLREQ" \ + "\05PRIVACY\06SHORT_PREAMBLE\07PBCC\10CHNL_AGILITY" \ + "\11SPECTRUM_MGMT\12QOS\13SHORT_SLOTTIME\14APSD" \ + "\15RADIO_MEASUREMENT\16DSSSOFDM\17DELAYED_B_ACK\20IMMEDIATE_B_ACK" + +/* + * Information element IDs (see 802.11-2012 Table 8.4.2). + */ +enum { + IEEE80211_ELEMID_SSID = 0, + IEEE80211_ELEMID_RATES = 1, + IEEE80211_ELEMID_FHPARMS = 2, + IEEE80211_ELEMID_DSPARMS = 3, + IEEE80211_ELEMID_CFPARMS = 4, + IEEE80211_ELEMID_TIM = 5, + IEEE80211_ELEMID_IBSSPARMS = 6, + IEEE80211_ELEMID_COUNTRY = 7, + IEEE80211_ELEMID_HOPPING_PARMS = 8, + IEEE80211_ELEMID_HOPPING_PATTERN = 9, + IEEE80211_ELEMID_REQUEST = 10, + IEEE80211_ELEMID_QBSS_LOAD = 11, + IEEE80211_ELEMID_EDCAPARMS = 12, + IEEE80211_ELEMID_TSPEC = 13, + IEEE80211_ELEMID_TCLASS = 14, + IEEE80211_ELEMID_SCHEDULE = 15, + IEEE80211_ELEMID_CHALLENGE = 16, + /* 17-31 reserved for challenge text extension */ + IEEE80211_ELEMID_POWER_CONSTRAINT = 32, + IEEE80211_ELEMID_POWER_CAP = 33, + IEEE80211_ELEMID_TPC_REQUEST = 34, + IEEE80211_ELEMID_TPC_REPORT = 35, + IEEE80211_ELEMID_SUPP_CHNLS = 35, + IEEE80211_ELEMID_CSA = 37, /* 11h */ + IEEE80211_ELEMID_MEASUREMENT_REQUEST = 38, /* DFS */ + IEEE80211_ELEMID_MEASUREMENT_REPORT = 39, /* DFS */ + IEEE80211_ELEMID_QUIET = 40, + IEEE80211_ELEMID_IBSS_DFS = 41, + IEEE80211_ELEMID_ERP = 42, + IEEE80211_ELEMID_TS_DELAY = 43, + IEEE80211_ELEMID_TCLAS = 44, + IEEE80211_ELEMID_HTCAPS = 45, /* 11n */ + IEEE80211_ELEMID_QOS_CAP = 46, + /* 47 reserved */ + IEEE80211_ELEMID_RSN = 48, + /* 49 reserved */ + IEEE80211_ELEMID_XRATES = 50, + IEEE80211_ELEMID_AP_CHNL_REPORT = 51, + IEEE80211_ELEMID_NBR_REPORT = 52, + IEEE80211_ELEMID_RCPI = 53, + IEEE80211_ELEMID_MDE = 54, + IEEE80211_ELEMID_FTE = 55, + IEEE80211_ELEMID_TIE = 56, /* 11r */ + IEEE80211_ELEMID_RDE = 57, + IEEE80211_ELEMID_DSE = 58, + IEEE80211_ELEMID_SUPP_OPCLASS = 59, + IEEE80211_ELEMID_XCSA = 60, + IEEE80211_ELEMID_HTOP = 61, /* 11n */ + IEEE80211_ELEMID_SECONDARY_CHANL_OFFSET = 62, /* 11n */ + IEEE80211_ELEMID_AVG_ACCESS_DELAY = 63, + IEEE80211_ELEMID_ANTENNA = 64, + IEEE80211_ELEMID_RSNI = 65, + IEEE80211_ELEMID_MEASUREMENT_PILOT_TX = 66, + IEEE80211_ELEMID_AVAIL_CAPACITY = 67, + IEEE80211_ELEMID_AC_ACCESS_DELAY = 68, + IEEE80211_ELEMID_TIME_ADVERT = 69, + IEEE80211_ELEMID_RM = 70, + IEEE80211_ELEMID_MULTI_BSSID = 71, + IEEE80211_ELEMID_20_40_CBW_COEX = 72, /* 11n */ + IEEE80211_ELEMID_20_40_CBW_INTOLERANT = 73, /* 11n */ + IEEE80211_ELEMID_SCAN_PARAM_OVERLAP = 74, + IEEE80211_ELEMID_RIC = 75, + IEEE80211_ELEMID_MMIE = 76, /* 11w */ + IEEE80211_ELEMID_EVENT_REQUEST = 78, + IEEE80211_ELEMID_EVENT_REPORT = 79, + IEEE80211_ELEMID_DIAG_REQUEST = 80, + IEEE80211_ELEMID_DIAG_REPORT = 81, + IEEE80211_ELEMID_LOCATION_PARMS = 82, + IEEE80211_ELEMID_NONTX_BSSID = 83, + IEEE80211_ELEMID_SSID_LIST = 84, + IEEE80211_ELEMID_MULTI_BSSID_IDX = 85, + IEEE80211_ELEMID_FMS_DESC = 86, + IEEE80211_ELEMID_FMS_REQUEST = 87, + IEEE80211_ELEMID_FMS_RESPONSE = 88, + IEEE80211_ELEMID_QOS_TRAFFIC_CAP = 89, + IEEE80211_ELEMID_MAX_IDLE_PERIOD = 90, + IEEE80211_ELEMID_TFS_REQUEST = 91, + IEEE80211_ELEMID_TFS_RESPONSE = 92, + IEEE80211_ELEMID_WNM_SLEEP = 93, + IEEE80211_ELEMID_TIM_BCAST_REQUEST = 94, + IEEE80211_ELEMID_TIM_BCAST_RESPONSE = 95, + IEEE80211_ELEMID_INTERFERENCE_REPORT = 96, + IEEE80211_ELEMID_CHNL_USAGE = 97, + IEEE80211_ELEMID_TIME_ZONE = 98, + IEEE80211_ELEMID_DMS_REQUEST = 99, + IEEE80211_ELEMID_DMS_RESPONSE = 100, + IEEE80211_ELEMID_LINK_ID = 101, + IEEE80211_ELEMID_WAKE_SCHED = 102, + /* 103 undefined */ + IEEE80211_ELEMID_CHNL_SWITCH_TIMING = 104, + IEEE80211_ELEMID_PTI_CTRL = 105, + IEEE80211_ELEMID_TPU_BUF_STATUS = 106, + IEEE80211_ELEMID_INTERWORKING = 107, + IEEE80211_ELEMID_ADVERT_PROTOCOL = 108, + IEEE80211_ELEMID_EXPEDITED_BW_REQUEST = 109, + IEEE80211_ELEMID_QOS_MAP_SET = 110, + IEEE80211_ELEMID_ROAMING_CONSORTIUM = 111, + IEEE80211_ELEMID_EMERGENCY_ALERT_ID = 112, + IEEE80211_ELEMID_MESHCONF = 113, + IEEE80211_ELEMID_MESHID = 114, + IEEE80211_ELEMID_MESHLINK = 115, + IEEE80211_ELEMID_MESHCNGST = 116, + IEEE80211_ELEMID_MESHPEER = 117, + IEEE80211_ELEMID_MESHCSA = 118, + IEEE80211_ELEMID_MESHAWAKEW = 119, + IEEE80211_ELEMID_MESHBEACONT = 120, + IEEE80211_ELEMID_MCCAOP_SETUP_REQUEST = 121, + IEEE80211_ELEMID_MCCAOP_SETUP_REPLY = 122, + IEEE80211_ELEMID_MCCAOP_ADVERT = 123, + IEEE80211_ELEMID_MCCAOP_TEARDOWN = 124, + IEEE80211_ELEMID_MESHGANN = 125, + IEEE80211_ELEMID_MESHRANN = 126, + IEEE80211_ELEMID_XCAPS = 127, + /* 128-129 reserved */ + IEEE80211_ELEMID_MESHPREQ = 130, + IEEE80211_ELEMID_MESHPREP = 131, + IEEE80211_ELEMID_MESHPERR = 132, + /* 133-136 reserved */ + IEEE80211_ELEMID_MESHPXU = 137, + IEEE80211_ELEMID_MESHPXUC = 138, + IEEE80211_ELEMID_AUTH_MESH_PEERING_XCHG = 139, + IEEE80211_ELEMID_MIC = 140, + IEEE80211_ELEMID_DEST_URI = 141, + IEEE80211_ELEMID_U_APSD_COEX = 142, + /* 143-174 reserved */ + IEEE80211_ELEMID_MCCAOP_ADVERT_OVIEW = 174, + /* 175-190 reserved */ + IEEE80211_ELEMID_VHTCAPS = 191, /* 11ac */ + IEEE80211_ELEMID_VHTOP = 192, /* 11ac */ + IEEE80211_ELEMID_EXT_BSS_LOAD = 193, /* 11ac */ + IEEE80211_ELEMID_WIDEBAND_CHNL_SWITCH = 194, /* 11ac */ + IEEE80211_ELEMID_VHT_TXPOWER = 195, /* 11ac */ + IEEE80211_ELEMID_CHNL_SWITCH_WRAPPER = 196, /* 11ac */ + IEEE80211_ELEMID_AID = 197, /* 11ac */ + IEEE80211_ELEMID_QUIET_CHNL = 198, /* 11ac */ + IEEE80211_ELEMID_OPMODE_NOTIF = 199, /* 11ac */ + /* 200-220 reserved */ + IEEE80211_ELEMID_VENDOR = 221 /* vendor private */ + /* 222-255 reserved */ +}; + +/* + * Action field category values (see 802.11-2012 8.4.1.11 Table 8-38). + */ +enum { + IEEE80211_CATEG_SPECTRUM = 0, + IEEE80211_CATEG_QOS = 1, + IEEE80211_CATEG_DLS = 2, + IEEE80211_CATEG_BA = 3, + IEEE80211_CATEG_PUB = 4, + IEEE80211_CATEG_RADIO_MSRMNT = 5, + IEEE80211_CATEG_FAST_BSS_TRANS = 6, + IEEE80211_CATEG_HT = 7, /* 11n */ + IEEE80211_CATEG_SA_QUERY = 8, /* 11w */ + IEEE80211_CATEG_PROT_DUAL_PUBLIC_ACTION = 9, + IEEE80211_CATEG_WNM = 10, + IEEE80211_CATEG_UNPROT_WNM = 11, + IEEE80211_CATEG_TDLS = 12, + IEEE80211_CATEG_MESH = 13, + IEEE80211_CATEG_MULTIHOP = 14, + IEEE80211_CATEG_SELF_PROT = 15, + /* 16-125 reserved */ + IEEE80211_CATEG_PROT_VENDOR = 126, + IEEE80211_CATEG_VENDOR = 127 + /* 128-255 error */ +}; + +/* + * Block Ack Action field values (see 802.11-2012 8.5.5 Table 8-202). + */ +#define IEEE80211_ACTION_ADDBA_REQ 0 +#define IEEE80211_ACTION_ADDBA_RESP 1 +#define IEEE80211_ACTION_DELBA 2 +/* 3-255 reserved */ + +/* + * SA Query Action field values (see 802.11-2012 8.5.10 Table 8-227). + */ +#define IEEE80211_ACTION_SA_QUERY_REQ 0 +#define IEEE80211_ACTION_SA_QUERY_RESP 1 + +/* + * HT Action field values (see 802.11-2012 8.5.12 Table 8-229). + */ +#define IEEE80211_ACTION_NOTIFYCW 0 +#define IEEE80211_ACTION_SM_PWRSAVE 1 +#define IEEE80211_ACTION_PSMP 2 +#define IEEE80211_ACTION_SET_PCO_PHASE 3 +#define IEEE80211_ACTION_CSI 4 +#define IEEE80211_ACTION_NONCOMPRESSED_BF 5 +#define IEEE80211_ACTION_COMPRESSED_BF 6 +#define IEEE80211_ACTION_ASEL_IDX_FEEDBACK 7 +/* 8-255 reserved */ + +#define IEEE80211_RATE_BASIC 0x80 +#define IEEE80211_RATE_VAL 0x7f +#define IEEE80211_RATE_SIZE 8 /* 802.11 standard */ +#define IEEE80211_RATE_MAXSIZE 15 /* max rates we'll handle */ + +#define IEEE80211_HT_NUM_MCS 77 +#define IEEE80211_VHT_NUM_MCS 10 + +/* + * BlockAck/BlockAckReq Control field (see 802.11-2012 8.3.1.9 Figure 8-25). + */ +#define IEEE80211_BA_ACK_POLICY 0x0001 +#define IEEE80211_BA_MULTI_TID 0x0002 +#define IEEE80211_BA_COMPRESSED 0x0004 +#define IEEE80211_BA_TID_INFO_MASK 0xf000 +#define IEEE80211_BA_TID_INFO_SHIFT 12 + +/* + * ADDBA Parameter Set field (see 802.11-2012 8.4.1.14 Figure 8-48). + */ +#define IEEE80211_ADDBA_AMSDU 0x0001 /* A-MSDU in A-MPDU supported */ +#define IEEE80211_ADDBA_BA_POLICY 0x0002 /* 1=immediate BA 0=delayed BA */ +#define IEEE80211_ADDBA_TID_MASK 0x003c +#define IEEE80211_ADDBA_TID_SHIFT 2 +#define IEEE80211_ADDBA_BUFSZ_MASK 0xffc0 +#define IEEE80211_ADDBA_BUFSZ_SHIFT 6 + +/* + * DELBA Parameter Set field (see 802.11-2012 8.4.1.16 Figure 8-50). + */ +#define IEEE80211_DELBA_INITIATOR 0x0800 +#define IEEE80211_DELBA_TID_INFO_MASK 0xf000 +#define IEEE80211_DELBA_TID_INFO_SHIFT 12 + +/* + * ERP information element parameters (see 802.11-2012 8.4.2.14 Figure 8-95). + */ +#define IEEE80211_ERP_NON_ERP_PRESENT 0x01 +#define IEEE80211_ERP_USE_PROTECTION 0x02 +#define IEEE80211_ERP_BARKER_MODE 0x04 + +/* + * RSN capabilities (see 802.11-2012 8.4.2.27.4). + */ +#define IEEE80211_RSNCAP_PREAUTH 0x0001 +#define IEEE80211_RSNCAP_NOPAIRWISE 0x0002 +#define IEEE80211_RSNCAP_PTKSA_RCNT_MASK 0x000c +#define IEEE80211_RSNCAP_PTKSA_RCNT_SHIFT 2 +#define IEEE80211_RSNCAP_GTKSA_RCNT_MASK 0x0030 +#define IEEE80211_RSNCAP_GTKSA_RCNT_SHIFT 4 +#define IEEE80211_RSNCAP_RCNT1 0 +#define IEEE80211_RSNCAP_RCNT2 1 +#define IEEE80211_RSNCAP_RCNT4 2 +#define IEEE80211_RSNCAP_RCNT16 3 +#define IEEE80211_RSNCAP_MFPR 0x0040 /* 11w */ +#define IEEE80211_RSNCAP_MFPC 0x0080 /* 11w */ +#define IEEE80211_RSNCAP_PEERKEYENA 0x0200 +#define IEEE80211_RSNCAP_SPPAMSDUC 0x0400 /* 11n */ +#define IEEE80211_RSNCAP_SPPAMSDUR 0x0800 /* 11n */ +#define IEEE80211_RSNCAP_PBAC 0x1000 /* 11n */ +#define IEEE80211_RSNCAP_EXTENDED_KEYID 0x2000 + +/* + * HT Capabilities Info (see 802.11-2012 8.4.2.58.2). + */ +#define IEEE80211_HTCAP_LDPC 0x00000001 +#define IEEE80211_HTCAP_CBW20_40 0x00000002 +#define IEEE80211_HTCAP_SMPS_MASK 0x0000000c +#define IEEE80211_HTCAP_SMPS_SHIFT 2 +#define IEEE80211_HTCAP_SMPS_STA 0 +#define IEEE80211_HTCAP_SMPS_DYN 1 +#define IEEE80211_HTCAP_SMPS_DIS 3 +#define IEEE80211_HTCAP_GF 0x00000010 +#define IEEE80211_HTCAP_SGI20 0x00000020 +#define IEEE80211_HTCAP_SGI40 0x00000040 +#define IEEE80211_HTCAP_TXSTBC 0x00000080 +#define IEEE80211_HTCAP_RXSTBC_MASK 0x00000300 +#define IEEE80211_HTCAP_RXSTBC_SHIFT 8 +#define IEEE80211_HTCAP_DELAYEDBA 0x00000400 +#define IEEE80211_HTCAP_AMSDU7935 0x00000800 +#define IEEE80211_HTCAP_DSSSCCK40 0x00001000 +#define IEEE80211_HTCAP_PSMP 0x00002000 +#define IEEE80211_HTCAP_40INTOLERANT 0x00004000 +#define IEEE80211_HTCAP_LSIGTXOPPROT 0x00008000 + +/* + * HT A-MPDU parameters (see 802.11-2012 8.4.2.58.3). + */ +#define IEEE80211_AMPDU_PARAM_LE 0x03 +#define IEEE80211_AMPDU_PARAM_SS 0x1c +#define IEEE80211_AMPDU_PARAM_SS_NONE (0 << 2) +#define IEEE80211_AMPDU_PARAM_SS_0_25 (1 << 2) +#define IEEE80211_AMPDU_PARAM_SS_0_5 (2 << 2) +#define IEEE80211_AMPDU_PARAM_SS_1 (3 << 2) +#define IEEE80211_AMPDU_PARAM_SS_2 (4 << 2) +#define IEEE80211_AMPDU_PARAM_SS_4 (5 << 2) +#define IEEE80211_AMPDU_PARAM_SS_8 (6 << 2) +#define IEEE80211_AMPDU_PARAM_SS_16 (7 << 2) +/* bits 5-7 reserved */ + +/* + * HT Supported MCS Set (see 802.11-2012 8.4.2.58.4). + * This field is 16 bytes in size. Bitmasks given below + * operate on 8 or 16 bit integer subsets of this field + * for use with ieee80211com and ieee80211_node. + */ +/* Bits 0-76: Supported Rx MCS bitmask */ +/* Bits 77-79: Reserved */ +/* Bits 80-89: Highest Rx rate in units of 1MB/s */ +#define IEEE80211_MCS_RX_RATE_HIGH 0x03ff +/* Bits 90-95: Reserved */ +/* Bits 96-100: Tx MCS set */ +#define IEEE80211_TX_MCS_SET_DEFINED 0x01 +#define IEEE80211_TX_RX_MCS_NOT_EQUAL 0x02 +#define IEEE80211_TX_SPATIAL_STREAMS 0x0c +#define IEEE80211_TX_UNEQUAL_MODULATION 0x10 +/* Bits 101-127: Reserved */ + +/* + * HT Extended Capabilities (see 802.11-2012 8.4.2.58.5). + */ +#define IEEE80211_HTXCAP_PCO 0x0001 +#define IEEE80211_HTXCAP_PCOTT_MASK 0x0006 +#define IEEE80211_HTXCAP_PCOTT_SHIFT 1 +#define IEEE80211_HTXCAP_PCOTT_400 1 +#define IEEE80211_HTXCAP_PCOTT_1500 2 +#define IEEE80211_HTXCAP_PCOTT_5000 3 +/* Bits 3-7 are reserved. */ +#define IEEE80211_HTXCAP_MFB_MASK 0x0300 +#define IEEE80211_HTXCAP_MFB_SHIFT 8 +#define IEEE80211_HTXCAP_MFB_NONE 0 +#define IEEE80211_HTXCAP_MFB_UNSOL 2 +#define IEEE80211_HTXCAP_MFB_BOTH 3 +#define IEEE80211_HTXCAP_HTC 0x0400 +#define IEEE80211_HTXCAP_RDRESP 0x0800 +/* Bits 12-15 are reserved. */ + +/* + * Transmit Beamforming (TxBF) Capabilities (see 802.11-2012 8.4.2.58.6). + */ +#define IEEE80211_TXBFCAP_IMPLICIT_RX 0x00000001 +#define IEEE80211_TXBFCAP_RSSC 0x00000002 +#define IEEE80211_TXBFCAP_TSSC 0x00000004 +#define IEEE80211_TXBFCAP_RNDP 0x00000008 +#define IEEE80211_TXBFCAP_TNDP 0x00000010 +#define IEEE80211_TXBFCAP_IMPLICIT_TX 0x00000020 +#define IEEE80211_TXBFCAP_CALIB_MASK 0x000000c0 +#define IEEE80211_TXBFCAP_CALIB_SHIFT 6 +#define IEEE80211_TXBFCAP_TX_CSI 0x00000100 +#define IEEE80211_TXBFCAP_EXPLICIT_NSC 0x00000200 +#define IEEE80211_TXBFCAP_EXPLICIT_CSC 0x00000400 +#define IEEE80211_TXBFCAP_CSI_FB_DELAYED 0x00000800 +#define IEEE80211_TXBFCAP_CSI_FB_IMMEDIATE 0x00001000 +#define IEEE80211_TXBFCAP_EXPLICIT_NB_FB_DELAYED 0x00002000 +#define IEEE80211_TXBFCAP_EXPLICIT_NB_FB_IMMEDIATE 0x00004000 +#define IEEE80211_TXBFCAP_EXPLICIT_CB_FB_DELAYED 0x00008000 +#define IEEE80211_TXBFCAP_EXPLICIT_CB_FB_IMMEDIATE 0x00010000 +#define IEEE80211_TXBFCAP_MINIMAL_GROUPING_1_2 0x00020000 +#define IEEE80211_TXBFCAP_MINIMAL_GROUPING_1_4 0x00040000 +#define IEEE80211_TXBFCAP_CSI_NUM_ANT_MASK 0x00180000 +#define IEEE80211_TXBFCAP_CSI_NUM_ANT_SHIFT 19 +#define IEEE80211_TXBFCAP_NS_NUM_ANT_MASK 0x00600000 +#define IEEE80211_TXBFCAP_NS_NUM_ANT_SHIFT 21 +#define IEEE80211_TXBFCAP_CS_NUM_ANT_MASK 0x01800000 +#define IEEE80211_TXBFCAP_CS_NUM_ANT_SHIFT 23 +#define IEEE80211_TXBFCAP_CSI_NUM_ROWS_MASK 0x06000000 +#define IEEE80211_TXBFCAP_CSI_NUM_ROWS_SHIFT 25 +#define IEEE80211_TXBFCAP_CHANL_ESTIMATE_MASK 0x18000000 +#define IEEE80211_TXBFCAP_CHANL_ESTIMATE_SHIFT 27 + +/* + * Antenna Selection (ASEL) Capability (see 802.11-2012 8.4.2.58.7). + */ +#define IEEE80211_ASELCAP_ASEL 0x01 +#define IEEE80211_ASELCAP_CSIFB_TX 0x02 +#define IEEE80211_ASELCAP_ANT_IDX_FB_TX 0x04 +#define IEEE80211_ASELCAP_CSIFB 0x08 +#define IEEE80211_ASELCAP_ANT_IDX_FB 0x10 +#define IEEE80211_ASELCAP_ASEL_RX 0x20 +#define IEEE80211_ASELCAP_TX_SOUND_PPDU 0x20 +/* Bit 7 is reserved. */ + +/* + * HT Operation element (see 802.11-2012 8.4.2.59). + */ +/* Byte 0 contains primary channel number. */ +/* Byte 1. */ +#define IEEE80211_HTOP0_SCO_MASK 0x03 +#define IEEE80211_HTOP0_SCO_SHIFT 0 +#define IEEE80211_HTOP0_SCO_SCN 0 +#define IEEE80211_HTOP0_SCO_SCA 1 +#define IEEE80211_HTOP0_SCO_SCB 3 +#define IEEE80211_HTOP0_CHW 0x04 +#define IEEE80211_HTOP0_RIFS 0x08 +/* bits 4-7 reserved */ +/* Bytes 2-3. */ +#define IEEE80211_HTOP1_PROT_MASK 0x0003 +#define IEEE80211_HTOP1_PROT_SHIFT 0 +#define IEEE80211_HTOP1_NONGF_STA 0x0004 +/* Bit 3 is reserved. */ +#define IEEE80211_HTOP1_OBSS_NONHT_STA 0x0010 +/* Bits 5-15 are reserved. */ +/* Bytes 4-5. */ +/* Bits 0-5 are reserved. */ +#define IEEE80211_HTOP2_DUALBEACON 0x0040 +#define IEEE80211_HTOP2_DUALCTSPROT 0x0080 +#define IEEE80211_HTOP2_STBCBEACON 0x0100 +#define IEEE80211_HTOP2_LSIGTXOP 0x0200 +#define IEEE80211_HTOP2_PCOACTIVE 0x0400 +#define IEEE80211_HTOP2_PCOPHASE40 0x0800 +/* Bits 12-15 are reserved. */ + +/* + * VHT Capabilities Info (see 802.11ac-2013 8.4.2.160.2). + */ +#define IEEE80211_VHTCAP_MAX_MPDU_LENGTH_MASK 0x00000003 +#define IEEE80211_VHTCAP_MAX_MPDU_LENGTH_SHIFT 0 +#define IEEE80211_VHTCAP_MAX_MPDU_LENGTH_3895 0 +#define IEEE80211_VHTCAP_MAX_MPDU_LENGTH_7991 1 +#define IEEE80211_VHTCAP_MAX_MPDU_LENGTH_11454 2 +#define IEEE80211_VHTCAP_CHAN_WIDTH_MASK 0x0c +#define IEEE80211_VHTCAP_CHAN_WIDTH_SHIFT 2 +#define IEEE80211_VHTCAP_CHAN_WIDTH_80 0 +#define IEEE80211_VHTCAP_CHAN_WIDTH_160 1 +#define IEEE80211_VHTCAP_CHAN_WIDTH_160_8080 2 +#define IEEE80211_VHTCAP_RX_LDPC 0x00000010 +#define IEEE80211_VHTCAP_SGI80 0x00000020 +#define IEEE80211_VHTCAP_SGI160 0x00000040 +#define IEEE80211_VHTCAP_TX_STBC 0x00000080 +#define IEEE80211_VHTCAP_RX_STBC_SS_MASK 0x00000700 +#define IEEE80211_VHTCAP_RX_STBC_SS_SHIFT 8 +#define IEEE80211_VHTCAP_SU_BEAMFORMER 0x00000800 +#define IEEE80211_VHTCAP_SU_BEAMFORMEE 0x00001000 +#define IEEE80211_VHTCAP_BEAMFORMEE_STS_MASK 0x0000e000 +#define IEEE80211_VHTCAP_BEAMFORMEE_STS_SHIFT 13 +#define IEEE80211_VHTCAP_NUM_STS_MASK 0x00070000 +#define IEEE80211_VHTCAP_NUM_STS_SHIFT 16 +#define IEEE80211_VHTCAP_MU_BEAMFORMER 0x00080000 +#define IEEE80211_VHTCAP_MU_BEAMFORMEE 0x00100000 +#define IEEE80211_VHTCAP_TXOP_PS 0x00200000 +#define IEEE80211_VHTCAP_HTC_VHT 0x00400000 +#define IEEE80211_VHTCAP_MAX_AMPDU_LEN_MASK 0x03800000 +#define IEEE80211_VHTCAP_MAX_AMPDU_LEN_SHIFT 23 +#define IEEE80211_VHTCAP_MAX_AMPDU_LEN_8K 0 +#define IEEE80211_VHTCAP_MAX_AMPDU_LEN_16K 1 +#define IEEE80211_VHTCAP_MAX_AMPDU_LEN_32K 2 +#define IEEE80211_VHTCAP_MAX_AMPDU_LEN_64K 3 +#define IEEE80211_VHTCAP_MAX_AMPDU_LEN_128K 4 +#define IEEE80211_VHTCAP_MAX_AMPDU_LEN_256K 5 +#define IEEE80211_VHTCAP_MAX_AMPDU_LEN_512K 6 +#define IEEE80211_VHTCAP_MAX_AMPDU_LEN_1024K 7 +#define IEEE80211_VHTCAP_LINK_ADAPT_MASK 0x0c000000 +#define IEEE80211_VHTCAP_LINK_ADAPT_SHIFT 26 +#define IEEE80211_VHTCAP_LINK_ADAPT_UNSOL_MFB 2 +#define IEEE80211_VHTCAP_LINK_ADAPT_MRQ_MFB 3 +#define IEEE80211_VHTCAP_RX_ANT_PATTERN 0x10000000 +#define IEEE80211_VHTCAP_TX_ANT_PATTERN 0x20000000 + +/* + * VHT-MCS and NSS map (see 802.11ac-2013 8.4.2.160.3, Figure 8-401bs). + * Set of VHT MCS supported for a given number of spatial streams, `n'. + * Used by the VHT capabilities IE and by the basic VHT MSC set in + * the VHT operation IE. + */ +#define IEEE80211_VHT_MCS_FOR_SS_MASK(n) (0x3 << (2*((n)-1))) +#define IEEE80211_VHT_MCS_FOR_SS_SHIFT(n) (2*((n)-1)) +#define IEEE80211_VHT_MCS_0_7 0 +#define IEEE80211_VHT_MCS_0_8 1 +#define IEEE80211_VHT_MCS_0_9 2 +#define IEEE80211_VHT_MCS_SS_NOT_SUPP 3 + +#define IEEE80211_VHT_MAX_LGI_MBIT_S_MASK 0x1fff +#define IEEE80211_VHT_MAX_LGI_MBIT_S_SHIFT 0 + +/* The highest number of spatial streams supported by VHT. */ +#define IEEE80211_VHT_NUM_SS 8 + +/* + * VHT Operation element (see 802.11ac-2013 8.4.2.161). + */ +/* Byte 0. */ +#define IEEE80211_VHTOP0_CHAN_WIDTH_MASK 0x03 +#define IEEE80211_VHTOP0_CHAN_WIDTH_SHIFT 0 +#define IEEE80211_VHTOP0_CHAN_WIDTH_HT 0 +#define IEEE80211_VHTOP0_CHAN_WIDTH_80 1 +#define IEEE80211_VHTOP0_CHAN_WIDTH_160 2 +#define IEEE80211_VHTOP0_CHAN_WIDTH_8080 3 +/* Byte 1 contains channel center frequency index 0 for 80, 80+80, 160 MHz. */ +/* Byte 2 contains channel center frequency index 1 for 80+80 MHz only. */ + +/* + * EDCA Access Categories. + */ +enum ieee80211_edca_ac { + EDCA_AC_BK = 1, /* Background */ + EDCA_AC_BE = 0, /* Best Effort */ + EDCA_AC_VI = 2, /* Video */ + EDCA_AC_VO = 3 /* Voice */ +}; +#define EDCA_NUM_AC 4 + +/* number of TID values (traffic identifier) */ +#define IEEE80211_NUM_TID 16 + +/* Atheros private advanced capabilities info */ +#define ATHEROS_CAP_TURBO_PRIME 0x01 +#define ATHEROS_CAP_COMPRESSION 0x02 +#define ATHEROS_CAP_FAST_FRAME 0x04 +/* bits 3-6 reserved */ +#define ATHEROS_CAP_BOOST 0x80 + +/*- + * Organizationally Unique Identifiers. + * See http://standards.ieee.org/regauth/oui/oui.txt for a list. + */ +#define ATHEROS_OUI ((const u_int8_t[]){ 0x00, 0x03, 0x7f }) +#define BROADCOM_OUI ((const u_int8_t[]){ 0x00, 0x90, 0x4c }) +#define IEEE80211_OUI ((const u_int8_t[]){ 0x00, 0x0f, 0xac }) +#define MICROSOFT_OUI ((const u_int8_t[]){ 0x00, 0x50, 0xf2 }) + +#define IEEE80211_AUTH_ALGORITHM(auth) \ + ((auth)[0] | ((auth)[1] << 8)) +#define IEEE80211_AUTH_TRANSACTION(auth) \ + ((auth)[2] | ((auth)[3] << 8)) +#define IEEE80211_AUTH_STATUS(auth) \ + ((auth)[4] | ((auth)[5] << 8)) + +/* + * Authentication Algorithm Number field (see 7.3.1.1). + */ +#define IEEE80211_AUTH_ALG_OPEN 0x0000 +#define IEEE80211_AUTH_ALG_SHARED 0x0001 +#define IEEE80211_AUTH_ALG_LEAP 0x0080 + +/* + * Authentication Transaction Sequence Number field (see 7.3.1.2). + */ +enum { + IEEE80211_AUTH_OPEN_REQUEST = 1, + IEEE80211_AUTH_OPEN_RESPONSE = 2 +}; +enum { + IEEE80211_AUTH_SHARED_REQUEST = 1, + IEEE80211_AUTH_SHARED_CHALLENGE = 2, + IEEE80211_AUTH_SHARED_RESPONSE = 3, + IEEE80211_AUTH_SHARED_PASS = 4 +}; + +/* + * Reason codes (see Table 22). + */ +enum { + IEEE80211_REASON_UNSPECIFIED = 1, + IEEE80211_REASON_AUTH_EXPIRE = 2, + IEEE80211_REASON_AUTH_LEAVE = 3, + IEEE80211_REASON_ASSOC_EXPIRE = 4, + IEEE80211_REASON_ASSOC_TOOMANY = 5, + IEEE80211_REASON_NOT_AUTHED = 6, + IEEE80211_REASON_NOT_ASSOCED = 7, + IEEE80211_REASON_ASSOC_LEAVE = 8, + IEEE80211_REASON_ASSOC_NOT_AUTHED = 9, + + /* XXX the following two reason codes are not correct */ + IEEE80211_REASON_RSN_REQUIRED = 11, + IEEE80211_REASON_RSN_INCONSISTENT = 12, + + IEEE80211_REASON_IE_INVALID = 13, + IEEE80211_REASON_MIC_FAILURE = 14, + IEEE80211_REASON_4WAY_TIMEOUT = 15, + IEEE80211_REASON_GROUP_TIMEOUT = 16, + IEEE80211_REASON_RSN_DIFFERENT_IE = 17, + IEEE80211_REASON_BAD_GROUP_CIPHER = 18, + IEEE80211_REASON_BAD_PAIRWISE_CIPHER = 19, + IEEE80211_REASON_BAD_AKMP = 20, + IEEE80211_REASON_RSN_IE_VER_UNSUP = 21, + IEEE80211_REASON_RSN_IE_BAD_CAP = 22, + + IEEE80211_REASON_CIPHER_REJ_POLICY = 24, + + IEEE80211_REASON_SETUP_REQUIRED = 38, + IEEE80211_REASON_TIMEOUT = 39 +}; + +/* + * Status codes (see Table 23). + */ +enum { + IEEE80211_STATUS_SUCCESS = 0, + IEEE80211_STATUS_UNSPECIFIED = 1, + IEEE80211_STATUS_CAPINFO = 10, + IEEE80211_STATUS_NOT_ASSOCED = 11, + IEEE80211_STATUS_OTHER = 12, + IEEE80211_STATUS_ALG = 13, + IEEE80211_STATUS_SEQUENCE = 14, + IEEE80211_STATUS_CHALLENGE = 15, + IEEE80211_STATUS_TIMEOUT = 16, + IEEE80211_STATUS_TOOMANY = 17, + IEEE80211_STATUS_BASIC_RATE = 18, + IEEE80211_STATUS_SP_REQUIRED = 19, + IEEE80211_STATUS_PBCC_REQUIRED = 20, + IEEE80211_STATUS_CA_REQUIRED = 21, + IEEE80211_STATUS_TOO_MANY_STATIONS = 22, + IEEE80211_STATUS_RATES = 23, + IEEE80211_STATUS_SHORTSLOT_REQUIRED = 25, + IEEE80211_STATUS_DSSSOFDM_REQUIRED = 26, + + IEEE80211_STATUS_TRY_AGAIN_LATER = 30, + IEEE80211_STATUS_MFP_POLICY = 31, + + IEEE80211_STATUS_REFUSED = 37, + IEEE80211_STATUS_INVALID_PARAM = 38, + + IEEE80211_STATUS_IE_INVALID = 40, + IEEE80211_STATUS_BAD_GROUP_CIPHER = 41, + IEEE80211_STATUS_BAD_PAIRWISE_CIPHER = 42, + IEEE80211_STATUS_BAD_AKMP = 43, + IEEE80211_STATUS_RSN_IE_VER_UNSUP = 44, + + IEEE80211_STATUS_CIPHER_REJ_POLICY = 46 +}; + +#define IEEE80211_WEP_KEYLEN 5 /* 40bit */ +#define IEEE80211_WEP_NKID 4 /* number of key ids */ +#define IEEE80211_CHALLENGE_LEN 128 + +/* WEP header constants */ +#define IEEE80211_WEP_IVLEN 3 /* 24bit */ +#define IEEE80211_WEP_KIDLEN 1 /* 1 octet */ +#define IEEE80211_WEP_CRCLEN 4 /* CRC-32 */ +#define IEEE80211_CRC_LEN 4 +#define IEEE80211_WEP_TOTLEN (IEEE80211_WEP_IVLEN + \ + IEEE80211_WEP_KIDLEN + \ + IEEE80211_WEP_CRCLEN) + +/* + * 802.11i defines an extended IV for use with non-WEP ciphers. + * When the EXTIV bit is set in the key id byte an additional + * 4 bytes immediately follow the IV for TKIP. For CCMP the + * EXTIV bit is likewise set but the 8 bytes represent the + * CCMP header rather than IV+extended-IV. + */ +#define IEEE80211_WEP_EXTIV 0x20 +#define IEEE80211_WEP_EXTIVLEN 4 /* extended IV length */ +#define IEEE80211_WEP_MICLEN 8 /* trailing MIC */ + +/* + * Maximum acceptable MTU is: + * IEEE80211_MAX_LEN - WEP overhead - CRC - + * QoS overhead - RSN/WPA overhead + * Min is arbitrarily chosen > IEEE80211_MIN_LEN. The default + * mtu is Ethernet-compatible; it's set by ether_ifattach. + */ +#define IEEE80211_MTU_MAX 2290 +#define IEEE80211_MTU_MIN 32 + +#define IEEE80211_MAX_LEN (2300 + IEEE80211_CRC_LEN + \ + (IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN + IEEE80211_WEP_CRCLEN)) +#define IEEE80211_ACK_LEN \ + (sizeof(struct ieee80211_frame_ack) + IEEE80211_CRC_LEN) +#define IEEE80211_MIN_LEN \ + (sizeof(struct ieee80211_frame_min) + IEEE80211_CRC_LEN) + +/* + * The 802.11 spec says at most 2007 stations may be + * associated at once. For most AP's this is way more + * than is feasible so we use a default of 1800. This + * number may be overridden by the driver and/or by + * user configuration. + */ +#define IEEE80211_AID_MAX 2007 +#define IEEE80211_AID_DEF 1800 +#define IEEE80211_AID(b) ((b) &~ 0xc000) + +/* + * RTS frame length parameters. The default is specified in + * the 802.11 spec. The max may be wrong for jumbo frames. + */ +#define IEEE80211_RTS_DEFAULT 512 +#define IEEE80211_RTS_MIN 1 +#define IEEE80211_RTS_MAX IEEE80211_MAX_LEN + +#define IEEE80211_PLCP_SERVICE 0x00 +#define IEEE80211_PLCP_SERVICE_PBCC 0x08 /* PBCC encoded */ +#define IEEE80211_PLCP_SERVICE_LENEXT 0x80 /* length extension bit */ + +/* One Time Unit (TU) is 1Kus = 1024 microseconds. */ +#define IEEE80211_DUR_TU 1024 + +/* IEEE 802.11b durations for DSSS PHY in microseconds */ +#define IEEE80211_DUR_DS_LONG_PREAMBLE 144 +#define IEEE80211_DUR_DS_SHORT_PREAMBLE 72 +#define IEEE80211_DUR_DS_PREAMBLE_DIFFERENCE \ + (IEEE80211_DUR_DS_LONG_PREAMBLE - IEEE80211_DUR_DS_SHORT_PREAMBLE) +#define IEEE80211_DUR_DS_FAST_PLCPHDR 24 +#define IEEE80211_DUR_DS_SLOW_PLCPHDR 48 +#define IEEE80211_DUR_DS_PLCPHDR_DIFFERENCE \ + (IEEE80211_DUR_DS_SLOW_PLCPHDR - IEEE80211_DUR_DS_FAST_PLCPHDR) +#define IEEE80211_DUR_DS_SLOW_ACK 112 +#define IEEE80211_DUR_DS_FAST_ACK 56 +#define IEEE80211_DUR_DS_SLOW_CTS 112 +#define IEEE80211_DUR_DS_FAST_CTS 56 +#define IEEE80211_DUR_DS_SLOT 20 +#define IEEE80211_DUR_DS_SHSLOT 9 +#define IEEE80211_DUR_DS_SIFS 10 +#define IEEE80211_DUR_DS_PIFS (IEEE80211_DUR_DS_SIFS + IEEE80211_DUR_DS_SLOT) +#define IEEE80211_DUR_DS_DIFS (IEEE80211_DUR_DS_SIFS + \ + 2 * IEEE80211_DUR_DS_SLOT) +#define IEEE80211_DUR_DS_EIFS (IEEE80211_DUR_DS_SIFS + \ + IEEE80211_DUR_DS_SLOW_ACK + \ + IEEE80211_DUR_DS_LONG_PREAMBLE + \ + IEEE80211_DUR_DS_SLOW_PLCPHDR + \ + IEEE80211_DUR_DIFS) + +/* + * The RSNA key descriptor used by IEEE 802.11 does not use the IEEE 802.1X + * key descriptor. Instead, it uses the key descriptor described in 8.5.2. + */ +#define EAPOL_KEY_NONCE_LEN 32 +#define EAPOL_KEY_IV_LEN 16 +#define EAPOL_KEY_MIC_LEN 16 + +struct ieee80211_eapol_key { + u_int8_t version; +#define EAPOL_VERSION 1 + + u_int8_t type; +/* IEEE Std 802.1X-2004, 7.5.4 (only type EAPOL-Key is used here) */ +#define EAP_PACKET 0 +#define EAPOL_START 1 +#define EAPOL_LOGOFF 2 +#define EAPOL_KEY 3 +#define EAPOL_ASF_ALERT 4 + + u_int8_t len[2]; + u_int8_t desc; +/* IEEE Std 802.1X-2004, 7.6.1 */ +#define EAPOL_KEY_DESC_RC4 1 /* deprecated */ +#define EAPOL_KEY_DESC_IEEE80211 2 +#define EAPOL_KEY_DESC_WPA 254 /* non-standard WPA */ + + u_int8_t info[2]; +#define EAPOL_KEY_VERSION_MASK 0x7 +#define EAPOL_KEY_DESC_V1 1 +#define EAPOL_KEY_DESC_V2 2 +#define EAPOL_KEY_DESC_V3 3 /* 11r */ +#define EAPOL_KEY_PAIRWISE (1 << 3) +#define EAPOL_KEY_INSTALL (1 << 6) /* I */ +#define EAPOL_KEY_KEYACK (1 << 7) /* A */ +#define EAPOL_KEY_KEYMIC (1 << 8) /* M */ +#define EAPOL_KEY_SECURE (1 << 9) /* S */ +#define EAPOL_KEY_ERROR (1 << 10) +#define EAPOL_KEY_REQUEST (1 << 11) +#define EAPOL_KEY_ENCRYPTED (1 << 12) +#define EAPOL_KEY_SMK (1 << 13) +/* WPA compatibility */ +#define EAPOL_KEY_WPA_KID_MASK 0x3 +#define EAPOL_KEY_WPA_KID_SHIFT 4 +#define EAPOL_KEY_WPA_TX EAPOL_KEY_INSTALL + + u_int8_t keylen[2]; + u_int8_t replaycnt[8]; + u_int8_t nonce[EAPOL_KEY_NONCE_LEN]; + u_int8_t iv[EAPOL_KEY_IV_LEN]; + u_int8_t rsc[8]; + u_int8_t reserved[8]; + u_int8_t mic[EAPOL_KEY_MIC_LEN]; + u_int8_t paylen[2]; +} __packed; + +/* Pairwise Transient Key (see 8.5.1.2) */ +struct ieee80211_ptk { + u_int8_t kck[16]; /* Key Confirmation Key */ + u_int8_t kek[16]; /* Key Encryption Key */ + u_int8_t tk[32]; /* Temporal Key */ +} __packed; + +#define IEEE80211_PMKID_LEN 16 +#define IEEE80211_SMKID_LEN 16 + +/* + * Key Data Encapsulation (see Table 62). + */ +enum { + IEEE80211_KDE_GTK = 1, + IEEE80211_KDE_MACADDR = 3, + IEEE80211_KDE_PMKID = 4, + IEEE80211_KDE_SMK = 5, + IEEE80211_KDE_NONCE = 6, + IEEE80211_KDE_LIFETIME = 7, + IEEE80211_KDE_ERROR = 8, + IEEE80211_KDE_IGTK = 9 /* 11w */ +}; + +/* + * HT protection modes (see 802.11-2012 8.4.2.59) + */ +enum ieee80211_htprot { + IEEE80211_HTPROT_NONE = 0, /* only 20/40MHz HT STAs exist */ + IEEE80211_HTPROT_NONMEMBER, /* non-HT STA overlaps our channel */ + IEEE80211_HTPROT_20MHZ, /* 20MHz HT STA on a 40MHz channel */ + IEEE80211_HTPROT_NONHT_MIXED /* non-HT STA associated to our BSS */ +}; + +#endif /* _NET80211_IEEE80211_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net80211/ieee80211_amrr.h b/lib/libc/include/generic-openbsd/net80211/ieee80211_amrr.h new file mode 100644 index 0000000000..12d439bc16 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net80211/ieee80211_amrr.h @@ -0,0 +1,58 @@ +/* $OpenBSD: ieee80211_amrr.h,v 1.4 2007/06/16 13:17:05 damien Exp $ */ + +/*- + * Copyright (c) 2006 + * Damien Bergamini + * + * 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 _NET80211_IEEE80211_AMRR_H_ +#define _NET80211_IEEE80211_AMRR_H_ + +/*- + * Naive implementation of the Adaptive Multi Rate Retry algorithm: + * + * "IEEE 802.11 Rate Adaptation: A Practical Approach" + * Mathieu Lacage, Hossein Manshaei, Thierry Turletti + * INRIA Sophia - Projet Planete + * http://www-sop.inria.fr/rapports/sophia/RR-5208.html + */ + +/* + * Rate control settings. + */ +struct ieee80211_amrr { + u_int amrr_min_success_threshold; + u_int amrr_max_success_threshold; +}; + +#define IEEE80211_AMRR_MIN_SUCCESS_THRESHOLD 1 +#define IEEE80211_AMRR_MAX_SUCCESS_THRESHOLD 15 + +/* + * Rate control state for a given node. + */ +struct ieee80211_amrr_node { + u_int amn_success; + u_int amn_recovery; + u_int amn_success_threshold; + u_int amn_txcnt; + u_int amn_retrycnt; +}; + +void ieee80211_amrr_node_init(const struct ieee80211_amrr *, + struct ieee80211_amrr_node *); +void ieee80211_amrr_choose(struct ieee80211_amrr *, struct ieee80211_node *, + struct ieee80211_amrr_node *); + +#endif /* _NET80211_IEEE80211_AMRR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net80211/ieee80211_crypto.h b/lib/libc/include/generic-openbsd/net80211/ieee80211_crypto.h new file mode 100644 index 0000000000..5e32276229 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net80211/ieee80211_crypto.h @@ -0,0 +1,194 @@ +/* $OpenBSD: ieee80211_crypto.h,v 1.28 2025/03/22 07:24:08 kevlo Exp $ */ + +/*- + * Copyright (c) 2007,2008 Damien Bergamini + * + * 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 _NET80211_IEEE80211_CRYPTO_H_ +#define _NET80211_IEEE80211_CRYPTO_H_ + +/* + * 802.11 protocol crypto-related definitions. + */ + +/* + * 802.11 ciphers. + */ +enum ieee80211_cipher { + IEEE80211_CIPHER_NONE = 0x00000000, + IEEE80211_CIPHER_USEGROUP = 0x00000001, + IEEE80211_CIPHER_WEP40 = 0x00000002, + IEEE80211_CIPHER_TKIP = 0x00000004, + IEEE80211_CIPHER_CCMP = 0x00000008, + IEEE80211_CIPHER_WEP104 = 0x00000010, + IEEE80211_CIPHER_BIP = 0x00000020 /* 11w */ +}; + +/* + * 802.11 Authentication and Key Management Protocols. + */ +enum ieee80211_akm { + IEEE80211_AKM_NONE = 0x00000000, + IEEE80211_AKM_8021X = 0x00000001, + IEEE80211_AKM_PSK = 0x00000002, + IEEE80211_AKM_SHA256_8021X = 0x00000004, /* 11w */ + IEEE80211_AKM_SHA256_PSK = 0x00000008, /* 11w */ + IEEE80211_AKM_SAE = 0x00000010 +}; + +#define IEEE80211_TKIP_HDRLEN 8 +#define IEEE80211_TKIP_MICLEN 8 +#define IEEE80211_TKIP_ICVLEN 4 +#define IEEE80211_CCMP_HDRLEN 8 +#define IEEE80211_CCMP_MICLEN 8 + +#define IEEE80211_PMK_LEN 32 + +#ifdef _KERNEL + +static __inline int +ieee80211_is_8021x_akm(enum ieee80211_akm akm) +{ + return akm == IEEE80211_AKM_8021X || + akm == IEEE80211_AKM_SHA256_8021X; +} + +static __inline int +ieee80211_is_sha256_akm(enum ieee80211_akm akm) +{ + return akm == IEEE80211_AKM_SHA256_8021X || + akm == IEEE80211_AKM_SHA256_PSK; +} + +struct ieee80211_key { + u_int8_t k_id; /* identifier (0-5) */ + enum ieee80211_cipher k_cipher; + u_int k_flags; +#define IEEE80211_KEY_GROUP 0x00000001 /* group data key */ +#define IEEE80211_KEY_TX 0x00000002 /* Tx+Rx */ +#define IEEE80211_KEY_IGTK 0x00000004 /* integrity group key */ +#define IEEE80211_KEY_SWCRYPTO 0x00000080 /* loaded for software crypto */ + + u_int k_len; + u_int64_t k_rsc[IEEE80211_NUM_TID]; + u_int64_t k_mgmt_rsc; + u_int64_t k_tsc; + u_int8_t k_key[32]; + void *k_priv; +}; + +#define IEEE80211_KEYBUF_SIZE 16 + +/* + * Entry in the PMKSA cache. + */ +struct ieee80211_pmk { + enum ieee80211_akm pmk_akm; + u_int32_t pmk_lifetime; +#define IEEE80211_PMK_INFINITE 0 + + u_int8_t pmk_pmkid[IEEE80211_PMKID_LEN]; + u_int8_t pmk_macaddr[IEEE80211_ADDR_LEN]; + u_int8_t pmk_key[IEEE80211_PMK_LEN]; + + TAILQ_ENTRY(ieee80211_pmk) pmk_next; +}; + +/* forward references */ +struct ieee80211com; +struct ieee80211_node; + +void ieee80211_crypto_attach(struct ifnet *); +void ieee80211_crypto_detach(struct ifnet *); + +void ieee80211_crypto_clear_groupkeys(struct ieee80211com *); +struct ieee80211_key *ieee80211_get_txkey(struct ieee80211com *, + const struct ieee80211_frame *, struct ieee80211_node *); +struct ieee80211_key *ieee80211_get_rxkey(struct ieee80211com *, + struct mbuf *, struct ieee80211_node *); +struct mbuf *ieee80211_encrypt(struct ieee80211com *, struct mbuf *, + struct ieee80211_key *); +struct mbuf *ieee80211_decrypt(struct ieee80211com *, struct mbuf *, + struct ieee80211_node *); + +int ieee80211_set_key(struct ieee80211com *, struct ieee80211_node *, + struct ieee80211_key *); +void ieee80211_delete_key(struct ieee80211com *, struct ieee80211_node *, + struct ieee80211_key *); + +void ieee80211_eapol_key_mic(struct ieee80211_eapol_key *, + const u_int8_t *); +int ieee80211_eapol_key_check_mic(struct ieee80211_eapol_key *, + const u_int8_t *); +#ifndef IEEE80211_STA_ONLY +void ieee80211_eapol_key_encrypt(struct ieee80211com *, + struct ieee80211_eapol_key *, const u_int8_t *); +#endif +int ieee80211_eapol_key_decrypt(struct ieee80211_eapol_key *, + const u_int8_t *); + +struct ieee80211_pmk *ieee80211_pmksa_add(struct ieee80211com *, + enum ieee80211_akm, const u_int8_t *, const u_int8_t *, u_int32_t); +struct ieee80211_pmk *ieee80211_pmksa_find(struct ieee80211com *, + struct ieee80211_node *, const u_int8_t *); +void ieee80211_derive_ptk(enum ieee80211_akm, const u_int8_t *, + const u_int8_t *, const u_int8_t *, const u_int8_t *, + const u_int8_t *, struct ieee80211_ptk *); +int ieee80211_cipher_keylen(enum ieee80211_cipher); + +int ieee80211_wep_set_key(struct ieee80211com *, struct ieee80211_key *); +void ieee80211_wep_delete_key(struct ieee80211com *, + struct ieee80211_key *); +struct mbuf *ieee80211_wep_encrypt(struct ieee80211com *, struct mbuf *, + struct ieee80211_key *); +struct mbuf *ieee80211_wep_decrypt(struct ieee80211com *, struct mbuf *, + struct ieee80211_key *); + +int ieee80211_tkip_set_key(struct ieee80211com *, struct ieee80211_key *); +void ieee80211_tkip_delete_key(struct ieee80211com *, + struct ieee80211_key *); +struct mbuf *ieee80211_tkip_encrypt(struct ieee80211com *, + struct mbuf *, struct ieee80211_key *); +int ieee80211_tkip_get_tsc(uint64_t *, uint64_t **, struct mbuf *, + struct ieee80211_key *); +struct mbuf *ieee80211_tkip_decrypt(struct ieee80211com *, + struct mbuf *, struct ieee80211_key *); +void ieee80211_tkip_mic(struct mbuf *, int, const u_int8_t *, + u_int8_t[IEEE80211_TKIP_MICLEN]); +void ieee80211_michael_mic_failure(struct ieee80211com *, u_int64_t); +#ifndef IEEE80211_STA_ONLY +void ieee80211_michael_mic_failure_timeout(void *); +#endif + +int ieee80211_ccmp_set_key(struct ieee80211com *, struct ieee80211_key *); +void ieee80211_ccmp_delete_key(struct ieee80211com *, + struct ieee80211_key *); +struct mbuf *ieee80211_ccmp_encrypt(struct ieee80211com *, struct mbuf *, + struct ieee80211_key *); +int ieee80211_ccmp_get_pn(uint64_t *, uint64_t **, struct mbuf *, + struct ieee80211_key *); +struct mbuf *ieee80211_ccmp_decrypt(struct ieee80211com *, struct mbuf *, + struct ieee80211_key *); + +int ieee80211_bip_set_key(struct ieee80211com *, struct ieee80211_key *); +void ieee80211_bip_delete_key(struct ieee80211com *, + struct ieee80211_key *); +struct mbuf *ieee80211_bip_encap(struct ieee80211com *, struct mbuf *, + struct ieee80211_key *); +struct mbuf *ieee80211_bip_decap(struct ieee80211com *, struct mbuf *, + struct ieee80211_key *); + +#endif /* _KERNEL */ +#endif /* _NET80211_IEEE80211_CRYPTO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net80211/ieee80211_ioctl.h b/lib/libc/include/generic-openbsd/net80211/ieee80211_ioctl.h new file mode 100644 index 0000000000..f6a31ee3ff --- /dev/null +++ b/lib/libc/include/generic-openbsd/net80211/ieee80211_ioctl.h @@ -0,0 +1,429 @@ +/* $OpenBSD: ieee80211_ioctl.h,v 1.44 2025/03/22 07:24:08 kevlo Exp $ */ +/* $NetBSD: ieee80211_ioctl.h,v 1.7 2004/04/30 22:51:04 dyoung Exp $ */ + +/*- + * Copyright (c) 2001 Atsushi Onoe + * Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: src/sys/net80211/ieee80211_ioctl.h,v 1.5 2004/03/30 22:57:57 sam Exp $ + */ +#ifndef _NET80211_IEEE80211_IOCTL_H_ +#define _NET80211_IEEE80211_IOCTL_H_ + +/* + * IEEE 802.11 ioctls. + */ + +/* per-interface statistics */ +struct ieee80211_stats { + u_int32_t is_rx_badversion; /* rx frame with bad version */ + u_int32_t is_rx_tooshort; /* rx frame too short */ + u_int32_t is_rx_wrongbss; /* rx from wrong bssid */ + u_int32_t is_rx_dup; /* rx discard 'cuz dup */ + u_int32_t is_rx_wrongdir; /* rx w/ wrong direction */ + u_int32_t is_rx_mcastecho; /* rx discard 'cuz mcast echo */ + u_int32_t is_rx_notassoc; /* rx discard 'cuz sta !assoc */ + u_int32_t is_rx_nowep; /* rx w/ wep but wep !config */ + u_int32_t is_rx_unencrypted; /* rx w/o wep but wep config */ + u_int32_t is_rx_wepfail; /* rx wep processing failed */ + u_int32_t is_rx_decap; /* rx decapsulation failed */ + u_int32_t is_rx_mgtdiscard; /* rx discard mgt frames */ + u_int32_t is_rx_ctl; /* rx discard ctrl frames */ + u_int32_t is_rx_rstoobig; /* rx rate set truncated */ + u_int32_t is_rx_elem_missing; /* rx required element missing*/ + u_int32_t is_rx_elem_toobig; /* rx element too big */ + u_int32_t is_rx_elem_toosmall; /* rx element too small */ + u_int32_t is_rx_badchan; /* rx frame w/ invalid chan */ + u_int32_t is_rx_chanmismatch; /* rx frame chan mismatch */ + u_int32_t is_rx_nodealloc; /* rx frame dropped */ + u_int32_t is_rx_ssidmismatch; /* rx frame ssid mismatch */ + u_int32_t is_rx_auth_unsupported; /* rx w/ unsupported auth alg */ + u_int32_t is_rx_auth_fail; /* rx sta auth failure */ + u_int32_t is_rx_assoc_bss; /* rx assoc from wrong bssid */ + u_int32_t is_rx_assoc_notauth; /* rx assoc w/o auth */ + u_int32_t is_rx_assoc_capmismatch;/* rx assoc w/ cap mismatch */ + u_int32_t is_rx_assoc_norate; /* rx assoc w/ no rate match */ + u_int32_t is_rx_deauth; /* rx deauthentication */ + u_int32_t is_rx_disassoc; /* rx disassociation */ + u_int32_t is_rx_badsubtype; /* rx frame w/ unknown subtype*/ + u_int32_t is_rx_nombuf; /* rx failed for lack of mbuf */ + u_int32_t is_rx_decryptcrc; /* rx decrypt failed on crc */ + u_int32_t is_rx_ahdemo_mgt; /* rx discard ahdemo mgt frame*/ + u_int32_t is_rx_bad_auth; /* rx bad auth request */ + u_int32_t is_tx_nombuf; /* tx failed for lack of mbuf */ + u_int32_t is_tx_nonode; /* tx failed for no node */ + u_int32_t is_tx_unknownmgt; /* tx of unknown mgt frame */ + u_int32_t is_scan_active; /* active scans started */ + u_int32_t is_scan_passive; /* passive scans started */ + u_int32_t is_node_timeout; /* nodes timed out inactivity */ + u_int32_t is_crypto_nomem; /* no memory for crypto ctx */ + u_int32_t is_rx_assoc_badrsnie; /* rx assoc w/ bad RSN IE */ + u_int32_t is_rx_unauth; /* rx port not valid */ + u_int32_t is_tx_noauth; /* tx port not valid */ + u_int32_t is_rx_eapol_key; /* rx eapol-key frames */ + u_int32_t is_rx_eapol_replay; /* rx replayed eapol frames */ + u_int32_t is_rx_eapol_badmic; /* rx eapol frames w/ bad mic */ + u_int32_t is_rx_remmicfail; /* rx tkip remote mic fails */ + u_int32_t is_rx_locmicfail; /* rx tkip local mic fails */ + u_int32_t is_tkip_replays; + u_int32_t is_tkip_icv_errs; + u_int32_t is_ccmp_replays; + u_int32_t is_ccmp_dec_errs; + u_int32_t is_cmac_replays; + u_int32_t is_cmac_icv_errs; + u_int32_t is_pbac_errs; + u_int32_t is_ht_nego_no_mandatory_mcs; + u_int32_t is_ht_nego_no_basic_mcs; + u_int32_t is_ht_nego_bad_crypto; + u_int32_t is_ht_prot_change; + u_int32_t is_ht_rx_ba_agreements; + u_int32_t is_ht_tx_ba_agreements; + u_int32_t is_ht_rx_frame_below_ba_winstart; + u_int32_t is_ht_rx_frame_above_ba_winend; + u_int32_t is_ht_rx_ba_window_slide; + u_int32_t is_ht_rx_ba_window_jump; + u_int32_t is_ht_rx_ba_no_buf; + u_int32_t is_ht_rx_ba_frame_lost; + u_int32_t is_ht_rx_ba_window_gap_timeout; + u_int32_t is_ht_rx_ba_timeout; + u_int32_t is_ht_tx_ba_timeout; + u_int32_t is_vht_nego_no_mandatory_mcs; + u_int32_t is_vht_nego_no_basic_mcs; +}; + +#define SIOCG80211STATS _IOWR('i', 242, struct ifreq) + +/* network identifier (ESSID), nwid is pointed at by ifr.ifr_data */ +struct ieee80211_nwid { + u_int8_t i_len; + u_int8_t i_nwid[IEEE80211_NWID_LEN]; +}; + +#define SIOCS80211NWID _IOWR('i', 230, struct ifreq) +#define SIOCG80211NWID _IOWR('i', 231, struct ifreq) + +/* network key (WEP), the first member must be matched with struct ifreq */ +struct ieee80211_nwkey { + char i_name[IFNAMSIZ]; /* if_name, e.g. "wi0" */ + int i_wepon; /* wep enabled flag */ + int i_defkid; /* default encrypt key id */ + struct { + int i_keylen; + u_int8_t *i_keydat; + } i_key[IEEE80211_WEP_NKID]; +}; + +#define IEEE80211_NWKEY_OPEN 0 /* No privacy */ +#define IEEE80211_NWKEY_WEP 1 /* WEP enabled */ +#define IEEE80211_NWKEY_EAP 2 /* EAP enabled */ +#define IEEE80211_NWKEY_PERSIST 0x100 /* designate persist keyset */ + +#define SIOCS80211NWKEY _IOW('i', 232, struct ieee80211_nwkey) +#define SIOCG80211NWKEY _IOWR('i', 233, struct ieee80211_nwkey) + +/* power management parameters */ +struct ieee80211_power { + char i_name[IFNAMSIZ]; /* if_name, e.g. "wi0" */ + int i_enabled; /* 1 == on, 0 == off */ + int i_maxsleep; /* max sleep in ms */ +}; +#define SIOCS80211POWER _IOW('i', 234, struct ieee80211_power) +#define SIOCG80211POWER _IOWR('i', 235, struct ieee80211_power) + +#define IEEE80211_AUTH_NONE 0 +#define IEEE80211_AUTH_OPEN 1 +#define IEEE80211_AUTH_SHARED 2 + +/* channel request */ +struct ieee80211chanreq { + char i_name[IFNAMSIZ]; /* if_name, e.g. "wi0" */ + u_int16_t i_channel; +}; + +/* + * Channels are specified by frequency and attributes. + */ +struct ieee80211_chaninfo { + u_int16_t ic_freq; /* setting in MHz */ + u_int16_t ic_flags; /* see below */ +}; + +/* + * Channel attributes. + */ +#define IEEE80211_CHANINFO_2GHZ 0x0080 /* 2 GHz spectrum channel */ +#define IEEE80211_CHANINFO_5GHZ 0x0100 /* 5 GHz spectrum channel */ +#define IEEE80211_CHANINFO_PASSIVE 0x0200 /* Only passive scan allowed */ + +struct ieee80211_chanreq_all { + char i_name[IFNAMSIZ]; /* if_name, e.g. "wi0" */ + struct ieee80211_chaninfo *i_chans; /* array of 256 elements */ +}; + +#ifndef IEEE80211_CHAN_ANY +#define IEEE80211_CHAN_ANY 0xffff +#endif + +#define SIOCS80211CHANNEL _IOW('i', 238, struct ieee80211chanreq) +#define SIOCG80211CHANNEL _IOWR('i', 239, struct ieee80211chanreq) +#define SIOCG80211ALLCHANS _IOWR('i', 215, struct ieee80211_chanreq_all) + +/* BSS identifier */ +struct ieee80211_bssid { + char i_name[IFNAMSIZ]; /* if_name, e.g. "wi0" */ + u_int8_t i_bssid[IEEE80211_ADDR_LEN]; +}; + +#define SIOCS80211BSSID _IOW('i', 240, struct ieee80211_bssid) +#define SIOCG80211BSSID _IOWR('i', 241, struct ieee80211_bssid) + +/* transmit power */ +struct ieee80211_txpower { + char i_name[IFNAMSIZ]; /* if_name, e.g. "wi0" */ + int i_mode; /* auto, manual */ + int16_t i_val; /* dBm */ +}; + +#define SIOCS80211TXPOWER _IOW('i', 243, struct ieee80211_txpower) +#define SIOCG80211TXPOWER _IOWR('i', 244, struct ieee80211_txpower) + +#define IEEE80211_TXPOWER_MODE_FIXED 0 /* fixed tx power value */ +#define IEEE80211_TXPOWER_MODE_AUTO 1 /* auto level control */ + +struct ieee80211_wpapsk { + char i_name[IFNAMSIZ]; /* if_name, e.g. "wi0" */ + int i_enabled; + u_int8_t i_psk[32]; +}; + +#define SIOCS80211WPAPSK _IOW('i', 245, struct ieee80211_wpapsk) +#define SIOCG80211WPAPSK _IOWR('i', 246, struct ieee80211_wpapsk) + +#define IEEE80211_WPA_PROTO_WPA1 0x01 +#define IEEE80211_WPA_PROTO_WPA2 0x02 + +#define IEEE80211_WPA_CIPHER_NONE 0x00 +#define IEEE80211_WPA_CIPHER_USEGROUP 0x01 +#define IEEE80211_WPA_CIPHER_WEP40 0x02 +#define IEEE80211_WPA_CIPHER_TKIP 0x04 +#define IEEE80211_WPA_CIPHER_CCMP 0x08 +#define IEEE80211_WPA_CIPHER_WEP104 0x10 +#define IEEE80211_WPA_CIPHER_BIP 0x20 + +#define IEEE80211_WPA_AKM_PSK 0x01 +#define IEEE80211_WPA_AKM_8021X 0x02 +#define IEEE80211_WPA_AKM_SHA256_PSK 0x04 +#define IEEE80211_WPA_AKM_SHA256_8021X 0x08 +#define IEEE80211_WPA_AKM_SAE 0x10 + +struct ieee80211_wpaparams { + char i_name[IFNAMSIZ]; /* if_name, e.g. "wi0" */ + int i_enabled; + u_int i_protos; + u_int i_akms; + u_int i_ciphers; + u_int i_groupcipher; +}; + +#define SIOCS80211WPAPARMS _IOW('i', 247, struct ieee80211_wpaparams) +#define SIOCG80211WPAPARMS _IOWR('i', 248, struct ieee80211_wpaparams) + +struct ieee80211_keyavail { + char i_name[IFNAMSIZ]; /* if_name, e.g. "wi0" */ + u_int8_t i_macaddr[IEEE80211_ADDR_LEN]; + u_int8_t i_key[32]; + u_int32_t i_lifetime; +}; + +struct ieee80211_keyrun { + char i_name[IFNAMSIZ]; /* if_name, e.g. "wi0" */ + u_int8_t i_macaddr[IEEE80211_ADDR_LEN]; +}; + +#define SIOCS80211KEYAVAIL _IOW('i', 251, struct ieee80211_keyavail) +#define SIOCS80211KEYRUN _IOW('i', 252, struct ieee80211_keyrun) + +/* scan request (will block) */ +#define IEEE80211_SCAN_TIMEOUT 30 /* timeout in seconds */ + +#define SIOCS80211SCAN _IOW('i', 210, struct ifreq) + +#define SIOCG80211JOINALL _IOWR('i', 218, struct ieee80211_joinreq_all) +#define SIOCS80211JOIN _IOWR('i', 255, struct ifreq) +#define SIOCG80211JOIN _IOWR('i', 0, struct ifreq) + +/* join is pointed at by ifr.ifr_data */ +struct ieee80211_join { + u_int8_t i_len; /* length of i_nwid */ + u_int8_t i_nwid[IEEE80211_NWID_LEN]; + u_int32_t i_flags; + + struct ieee80211_wpaparams i_wpaparams; + struct ieee80211_wpapsk i_wpapsk; + struct ieee80211_nwkey i_nwkey; +}; + +struct ieee80211_joinreq_all { + char ja_ifname[IFNAMSIZ]; + int ja_nodes; /* returned count */ + size_t ja_size; /* size of node buffer */ + struct ieee80211_join *ja_node; /* allocated node buffer */ +}; + + +#define IEEE80211_JOIN_SHOW 0x01 +#define IEEE80211_JOIN_FOUND 0x02 +#define IEEE80211_JOIN_DEL 0x04 +#define IEEE80211_JOIN_NWKEY 0x08 +#define IEEE80211_JOIN_WPA 0x10 +#define IEEE80211_JOIN_WPAPSK 0x20 +#define IEEE80211_JOIN_8021X 0x40 +#define IEEE80211_JOIN_ANY 0x80 +#define IEEE80211_JOIN_DEL_ALL 0x100 + +/* node and requests */ +struct ieee80211_nodereq { + char nr_ifname[IFNAMSIZ]; /* e.g. "ath0" */ + + /* Node address and name information */ + u_int8_t nr_macaddr[IEEE80211_ADDR_LEN]; /* node lladdr */ + u_int8_t nr_bssid[IEEE80211_ADDR_LEN]; /* bssid */ + u_int8_t nr_nwid_len; /* ESSID length */ + u_int8_t nr_nwid[IEEE80211_NWID_LEN]; /* ESSID */ + + /* Channel and rates */ + u_int16_t nr_channel; /* last channel */ + u_int16_t nr_chan_flags; /* channel flags */ + u_int8_t nr_nrates; /* rate count */ + u_int8_t nr_rates[IEEE80211_RATE_MAXSIZE]; /* rate set */ + + /* Node status information */ + int8_t nr_rssi; /* received signal strength */ + int8_t nr_max_rssi; /* maximum rssi */ + u_int8_t nr_tstamp[8]; /* from last received beacon */ + u_int16_t nr_intval; /* beacon interval */ + u_int16_t nr_capinfo; /* capabilities */ + u_int8_t nr_erp; /* 11g only */ + u_int8_t nr_pwrsave; /* power saving mode */ + u_int16_t nr_associd; /* assoc response */ + u_int16_t nr_txseq; /* seq to be transmitted */ + u_int16_t nr_rxseq; /* seq previous received */ + u_int32_t nr_fails; /* failure count to associate */ + u_int32_t nr_inact; /* inactivity mark count */ + u_int8_t nr_txrate; /* index to nr_rates[] */ + u_int16_t nr_state; /* node state in the cache */ + + /* RSN */ + u_int nr_rsnprotos; + u_int nr_rsnciphers; + u_int nr_rsnakms; + + /* Node flags */ + u_int8_t nr_flags; + + /* HT */ + uint16_t nr_htcaps; + uint8_t nr_rxmcs[howmany(80,NBBY)]; + uint16_t nr_max_rxrate; /* in Mb/s, 0 <= rate <= 1023 */ + uint8_t nr_tx_mcs_set; + + /* HT / VHT */ + uint8_t nr_txmcs; + + /* VHT */ + uint8_t nr_vht_ss; + + u_int32_t nr_assoc_fail; /* association failure reasons */ +}; + +#define IEEE80211_NODEREQ_STATE(_s) (1 << _s) +#define IEEE80211_NODEREQ_STATE_BITS \ + "\20\01CACHE\02BSS\03AUTH\04ASSOC\05COLLECT" + +#define IEEE80211_NODEREQ_RSSI(_nr) \ + ((u_int)(((float)(_nr)->nr_rssi / (_nr)->nr_max_rssi) * 100)) + +#define IEEE80211_NODEREQ_STA 0x00 /* station */ +#define IEEE80211_NODEREQ_AP 0x01 /* access point */ +#define IEEE80211_NODEREQ_AP_BSS 0x02 /* current bss access point */ +#define IEEE80211_NODEREQ_COPY 0x04 /* add node with flags */ +#define IEEE80211_NODEREQ_HT 0x08 /* HT negotiated */ +#define IEEE80211_NODEREQ_VHT 0x10 /* VHT negotiated */ + +#define SIOCG80211NODE _IOWR('i', 211, struct ieee80211_nodereq) +#define SIOCS80211NODE _IOW('i', 212, struct ieee80211_nodereq) +#define SIOCS80211DELNODE _IOW('i', 213, struct ieee80211_nodereq) + +#define IEEE80211_NODEREQ_ASSOCFAIL_CHAN 0x01 +#define IEEE80211_NODEREQ_ASSOCFAIL_IBSS 0x02 +#define IEEE80211_NODEREQ_ASSOCFAIL_PRIVACY 0x04 +#define IEEE80211_NODEREQ_ASSOCFAIL_BASIC_RATE 0x08 +#define IEEE80211_NODEREQ_ASSOCFAIL_ESSID 0x10 +#define IEEE80211_NODEREQ_ASSOCFAIL_BSSID 0x20 +#define IEEE80211_NODEREQ_ASSOCFAIL_WPA_PROTO 0x40 +#define IEEE80211_NODEREQ_ASSOCFAIL_WPA_KEY 0x80 +#define IEEE80211_NODEREQ_ASSOCFAIL_BITS \ + "\20\1!CHAN\2!IBSS\3!PRIVACY\4!BASICRATE\5!ESSID\6!BSSID\7!WPAPROTO" \ + "\10!WPAKEY" + +/* get the entire node cache */ +struct ieee80211_nodereq_all { + char na_ifname[IFNAMSIZ]; /* e.g. "ath0" */ + + int na_nodes; /* returned count */ + size_t na_size; /* size of node buffer */ + struct ieee80211_nodereq *na_node; /* allocated node buffer */ + + /* Match nodes by flag */ + u_int8_t na_flags; /* IEEE80211_NODEREQ_* */ +}; + +#define SIOCG80211ALLNODES _IOWR('i', 214, struct ieee80211_nodereq_all) + +/* net80211 specific interface flags */ +#define IEEE80211_F_HIDENWID 0x00000001 /* CONF: hidden ssid mode */ +#define IEEE80211_F_NOBRIDGE 0x00000002 /* CONF: no internal bridging */ +#define IEEE80211_F_HOSTAPMASK 0x00000003 +#define IEEE80211_F_STAYAUTH 0x00000004 /* CONF: ignore deauth */ +#define IEEE80211_F_NOMIMO 0x00000008 /* CONF: disable MIMO */ +#define IEEE80211_F_USERBITS "\20\01HIDENWID\02NOBRIDGE\03STAYAUTH\04NOMIMO" + +struct ieee80211_flags { + const char *f_name; + u_int f_flag; +}; + +#define IEEE80211_FLAGS { \ + { "hidenwid", IEEE80211_F_HIDENWID }, \ + { "nobridge", IEEE80211_F_NOBRIDGE }, \ + { "stayauth", IEEE80211_F_STAYAUTH }, \ + { "nomimo", IEEE80211_F_NOMIMO } \ +} + +#define SIOCG80211FLAGS _IOWR('i', 216, struct ifreq) +#define SIOCS80211FLAGS _IOW('i', 217, struct ifreq) + +#endif /* _NET80211_IEEE80211_IOCTL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net80211/ieee80211_node.h b/lib/libc/include/generic-openbsd/net80211/ieee80211_node.h new file mode 100644 index 0000000000..bdf413bb2d --- /dev/null +++ b/lib/libc/include/generic-openbsd/net80211/ieee80211_node.h @@ -0,0 +1,676 @@ +/* $OpenBSD: ieee80211_node.h,v 1.97 2025/08/01 20:39:26 stsp Exp $ */ +/* $NetBSD: ieee80211_node.h,v 1.9 2004/04/30 22:57:32 dyoung Exp $ */ + +/*- + * Copyright (c) 2001 Atsushi Onoe + * Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: src/sys/net80211/ieee80211_node.h,v 1.10 2004/04/05 22:10:26 sam Exp $ + */ +#ifndef _NET80211_IEEE80211_NODE_H_ +#define _NET80211_IEEE80211_NODE_H_ + +#include + +#define IEEE80211_PSCAN_WAIT 5 /* passive scan wait */ +#define IEEE80211_TRANS_WAIT 5 /* transition wait */ +#define IEEE80211_INACT_WAIT 5 /* inactivity timer interval */ +#define IEEE80211_INACT_MAX (300/IEEE80211_INACT_WAIT) +#define IEEE80211_CACHE_SIZE 512 +#define IEEE80211_CACHE_WAIT 30 +#define IEEE80211_INACT_SCAN 10 /* for station mode */ + +struct ieee80211_rateset { + u_int8_t rs_nrates; + u_int8_t rs_rates[IEEE80211_RATE_MAXSIZE]; +}; + +extern const struct ieee80211_rateset ieee80211_std_rateset_11a; +extern const struct ieee80211_rateset ieee80211_std_rateset_11b; +extern const struct ieee80211_rateset ieee80211_std_rateset_11g; + +/* Index into ieee80211_std_ratesets_11n[] array. */ +#define IEEE80211_HT_RATESET_SISO 0 +#define IEEE80211_HT_RATESET_SISO_SGI 1 +#define IEEE80211_HT_RATESET_MIMO2 2 +#define IEEE80211_HT_RATESET_MIMO2_SGI 3 +#define IEEE80211_HT_RATESET_MIMO3 4 +#define IEEE80211_HT_RATESET_MIMO3_SGI 5 +#define IEEE80211_HT_RATESET_MIMO4 6 +#define IEEE80211_HT_RATESET_MIMO4_SGI 7 +#define IEEE80211_HT_RATESET_SISO_40 8 +#define IEEE80211_HT_RATESET_SISO_SGI40 9 +#define IEEE80211_HT_RATESET_MIMO2_40 10 +#define IEEE80211_HT_RATESET_MIMO2_SGI40 11 +#define IEEE80211_HT_RATESET_MIMO3_40 12 +#define IEEE80211_HT_RATESET_MIMO3_SGI40 13 +#define IEEE80211_HT_RATESET_MIMO4_40 14 +#define IEEE80211_HT_RATESET_MIMO4_SGI40 15 +#define IEEE80211_HT_NUM_RATESETS 16 + +/* Maximum number of rates in a HT rateset. */ +#define IEEE80211_HT_RATESET_MAX_NRATES 8 + +/* Number of MCS indices represented by struct ieee80211_ht_rateset. */ +#define IEEE80211_HT_RATESET_NUM_MCS 32 + +struct ieee80211_ht_rateset { + uint32_t nrates; + uint32_t rates[IEEE80211_HT_RATESET_MAX_NRATES]; /* 500 kbit/s units */ + + /* + * This bitmask can only express MCS 0 - MCS 31. + * IEEE 802.11 defined 77 HT MCS in total but common hardware + * implementations tend to support MCS index 0 through 31 only. + */ + uint32_t mcs_mask; + + /* Range of MCS indices represented in this rateset. */ + int min_mcs; + int max_mcs; + + int chan40; + int sgi; +}; + +extern const struct ieee80211_ht_rateset ieee80211_std_ratesets_11n[]; + +/* Index into ieee80211_std_ratesets_11ac[] array. */ +#define IEEE80211_VHT_RATESET_SISO 0 +#define IEEE80211_VHT_RATESET_SISO_SGI 1 +#define IEEE80211_VHT_RATESET_MIMO2 2 +#define IEEE80211_VHT_RATESET_MIMO2_SGI 3 +#define IEEE80211_VHT_RATESET_SISO_40 4 +#define IEEE80211_VHT_RATESET_SISO_40_SGI 5 +#define IEEE80211_VHT_RATESET_MIMO2_40 6 +#define IEEE80211_VHT_RATESET_MIMO2_40_SGI 7 +#define IEEE80211_VHT_RATESET_SISO_80 8 +#define IEEE80211_VHT_RATESET_SISO_80_SGI 9 +#define IEEE80211_VHT_RATESET_MIMO2_80 10 +#define IEEE80211_VHT_RATESET_MIMO2_80_SGI 11 +#define IEEE80211_VHT_NUM_RATESETS 12 + +/* Maximum number of rates in a VHT rateset. */ +#define IEEE80211_VHT_RATESET_MAX_NRATES 10 + +struct ieee80211_vht_rateset { + int idx; /* This rateset's index in ieee80211_std_ratesets_11ac[]. */ + + uint32_t nrates; + uint32_t rates[IEEE80211_VHT_RATESET_MAX_NRATES]; /* 500 kbit/s units */ + + /* Number of spatial streams used by rates in this rateset. */ + int num_ss; + + int chan40; + int chan80; + int sgi; +}; + +extern const struct ieee80211_vht_rateset ieee80211_std_ratesets_11ac[]; + +enum ieee80211_node_state { + IEEE80211_STA_CACHE, /* cached node */ + IEEE80211_STA_BSS, /* ic->ic_bss, the network we joined */ + IEEE80211_STA_AUTH, /* successfully authenticated */ + IEEE80211_STA_ASSOC, /* successfully associated */ + IEEE80211_STA_COLLECT /* This node remains in the cache while + * the driver sends a de-auth message; + * afterward it should be freed to make room + * for a new node. + */ +}; + +#define ieee80211_node_newstate(__ni, __state) \ + do { \ + (__ni)->ni_state = (__state); \ + } while (0) + +enum ieee80211_node_psstate { + IEEE80211_PS_AWAKE, + IEEE80211_PS_DOZE +}; + +#define IEEE80211_PS_MAX_QUEUE 50 /* maximum saved packets */ + +/* Authenticator state machine: 4-Way Handshake (see 8.5.6.1.1) */ +enum { + RSNA_INITIALIZE, + RSNA_AUTHENTICATION, + RSNA_AUTHENTICATION_2, + RSNA_INITPMK, + RSNA_INITPSK, + RSNA_PTKSTART, + RSNA_PTKCALCNEGOTIATING, + RSNA_PTKCALCNEGOTIATING_2, + RSNA_PTKINITNEGOTIATING, + RSNA_PTKINITDONE, + RSNA_DISCONNECT, + RSNA_DISCONNECTED +}; + +/* Authenticator state machine: Group Key Handshake (see 8.5.6.1.2) */ +enum { + RSNA_IDLE, + RSNA_REKEYNEGOTIATING, + RSNA_REKEYESTABLISHED, + RSNA_KEYERROR +}; + +/* Supplicant state machine: 4-Way Handshake (not documented in standard) */ +enum { + RSNA_SUPP_INITIALIZE, /* not expecting any messages */ + RSNA_SUPP_PTKSTART, /* awaiting handshake message 1 */ + RSNA_SUPP_PTKNEGOTIATING, /* got message 1 and derived PTK */ + RSNA_SUPP_PTKDONE /* got message 3 and authenticated AP */ +}; + +struct ieee80211_rxinfo { + u_int32_t rxi_flags; + u_int32_t rxi_tstamp; + int rxi_rssi; + uint8_t rxi_chan; +}; +#define IEEE80211_RXI_HWDEC 0x00000001 +#define IEEE80211_RXI_AMPDU_DONE 0x00000002 +#define IEEE80211_RXI_HWDEC_SAME_PN 0x00000004 +#define IEEE80211_RXI_SAME_SEQ 0x00000008 + +/* Block Acknowledgement Record */ +struct ieee80211_tx_ba { + struct ieee80211_node *ba_ni; /* backpointer for callbacks */ + struct timeout ba_to; + int ba_timeout_val; + int ba_state; +#define IEEE80211_BA_INIT 0 +#define IEEE80211_BA_REQUESTED 1 +#define IEEE80211_BA_AGREED 2 + + /* ADDBA parameter set field for this BA agreement. */ + u_int16_t ba_params; + + /* These values are IEEE802.11 frame sequence numbers (0x0-0xfff) */ + u_int16_t ba_winstart; + u_int16_t ba_winend; + + /* Number of A-MPDU subframes in reorder buffer. */ + u_int16_t ba_winsize; +#define IEEE80211_BA_MAX_WINSZ 64 /* corresponds to maximum ADDBA BUFSZ */ + + u_int8_t ba_token; + + /* Bitmap for ACK'd frames in the current BA window. */ + uint64_t ba_bitmap; +}; + +struct ieee80211_rx_ba { + struct ieee80211_node *ba_ni; /* backpointer for callbacks */ + struct { + struct mbuf *m; + struct ieee80211_rxinfo rxi; + } *ba_buf; + struct timeout ba_to; + int ba_timeout_val; + int ba_state; + u_int16_t ba_params; + u_int16_t ba_winstart; + u_int16_t ba_winend; + u_int16_t ba_winsize; + u_int16_t ba_head; + struct timeout ba_gap_to; +#define IEEE80211_BA_GAP_TIMEOUT 300 /* msec */ + + /* + * Counter for frames forced to wait in the reordering buffer + * due to a leading gap caused by one or more missing frames. + */ + int ba_gapwait; + + /* Counter for consecutive frames which missed the BA window. */ + int ba_winmiss; + /* Sequence number of previous frame which missed the BA window. */ + uint16_t ba_missedsn; + /* Window moves forward after this many frames have missed it. */ +#define IEEE80211_BA_MAX_WINMISS 8 + + uint8_t ba_token; +}; + +/* + * Node specific information. Note that drivers are expected + * to derive from this structure to add device-specific per-node + * state. This is done by overriding the ic_node_* methods in + * the ieee80211com structure. + */ +struct ieee80211_node { + RBT_ENTRY(ieee80211_node) ni_node; + + struct ieee80211com *ni_ic; /* back-pointer */ + + u_int ni_refcnt; + u_int ni_scangen; /* gen# for timeout scan */ + + /* hardware */ + u_int32_t ni_rstamp; /* recv timestamp */ + u_int8_t ni_rssi; /* recv ssi */ + + /* header */ + u_int8_t ni_macaddr[IEEE80211_ADDR_LEN]; + u_int8_t ni_bssid[IEEE80211_ADDR_LEN]; + + /* beacon, probe response */ + u_int8_t ni_tstamp[8]; /* from last rcv'd beacon */ + u_int16_t ni_intval; /* beacon interval */ + u_int16_t ni_capinfo; /* capabilities */ + u_int8_t ni_esslen; + u_int8_t ni_essid[IEEE80211_NWID_LEN]; + struct ieee80211_rateset ni_rates; /* negotiated rate set */ + u_int8_t *ni_country; /* country information XXX */ + struct ieee80211_channel *ni_chan; + u_int8_t ni_erp; /* 11g only */ + + /* DTIM and contention free period (CFP) */ + u_int8_t ni_dtimcount; + u_int8_t ni_dtimperiod; +#ifdef notyet + u_int8_t ni_cfpperiod; /* # of DTIMs between CFPs */ + u_int16_t ni_cfpduremain; /* remaining cfp duration */ + u_int16_t ni_cfpmaxduration;/* max CFP duration in TU */ + u_int16_t ni_nextdtim; /* time to next DTIM */ + u_int16_t ni_timoffset; +#endif + + /* power saving mode */ + u_int8_t ni_pwrsave; + struct mbuf_queue ni_savedq; /* packets queued for pspoll */ + + /* RSN */ + struct timeout ni_eapol_to; + u_int ni_rsn_state; + u_int ni_rsn_supp_state; + u_int ni_rsn_gstate; + u_int ni_rsn_retries; + u_int ni_supported_rsnprotos; + u_int ni_rsnprotos; + u_int ni_supported_rsnakms; + u_int ni_rsnakms; + u_int ni_rsnciphers; + enum ieee80211_cipher ni_rsngroupcipher; + enum ieee80211_cipher ni_rsngroupmgmtcipher; + u_int16_t ni_rsncaps; + enum ieee80211_cipher ni_rsncipher; + u_int8_t ni_nonce[EAPOL_KEY_NONCE_LEN]; + u_int8_t ni_pmk[IEEE80211_PMK_LEN]; + u_int8_t ni_pmkid[IEEE80211_PMKID_LEN]; + u_int64_t ni_replaycnt; + u_int8_t ni_replaycnt_ok; + u_int64_t ni_reqreplaycnt; + u_int8_t ni_reqreplaycnt_ok; + u_int8_t *ni_rsnie; + struct ieee80211_key ni_pairwise_key; + struct ieee80211_ptk ni_ptk; + u_int8_t ni_key_count; + int ni_port_valid; + + /* SA Query */ + u_int16_t ni_sa_query_trid; + struct timeout ni_sa_query_to; + int ni_sa_query_count; + + /* HT capabilities */ + uint16_t ni_htcaps; + uint8_t ni_ampdu_param; + uint8_t ni_rxmcs[howmany(80,NBBY)]; + uint16_t ni_max_rxrate; /* in Mb/s, 0 <= rate <= 1023 */ + uint8_t ni_tx_mcs_set; + uint16_t ni_htxcaps; + uint32_t ni_txbfcaps; + uint8_t ni_aselcaps; + + /* HT operation */ + uint8_t ni_primary_chan; /* XXX corresponds to ni_chan */ + uint8_t ni_htop0; + uint16_t ni_htop1; + uint16_t ni_htop2; + uint8_t ni_basic_mcs[howmany(128,NBBY)]; + + /* VHT capabilities */ + uint32_t ni_vhtcaps; + uint16_t ni_vht_rxmcs; + uint16_t ni_vht_rx_max_lgi_mbit_s; + uint16_t ni_vht_txmcs; + uint16_t ni_vht_tx_max_lgi_mbit_s; + + /* VHT operation */ + uint8_t ni_vht_chan_width; + uint8_t ni_vht_chan_center_freq_idx0; + uint8_t ni_vht_chan_center_freq_idx1; + uint16_t ni_vht_basic_mcs; + + /* Timeout handlers which trigger Tx Block Ack negotiation. */ + struct timeout ni_addba_req_to[IEEE80211_NUM_TID]; + int ni_addba_req_intval[IEEE80211_NUM_TID]; +#define IEEE80211_ADDBA_REQ_INTVAL_MAX 30 /* in seconds */ + + /* Block Ack records */ + struct ieee80211_tx_ba ni_tx_ba[IEEE80211_NUM_TID]; + struct ieee80211_rx_ba ni_rx_ba[IEEE80211_NUM_TID]; + + int ni_txmcs; /* current MCS used for TX */ + int ni_vht_ss; /* VHT # spatial streams */ + + /* others */ + u_int16_t ni_associd; /* assoc response */ + u_int16_t ni_txseq; /* seq to be transmitted */ + u_int16_t ni_rxseq; /* seq previous received */ + u_int16_t ni_qos_txseqs[IEEE80211_NUM_TID]; + u_int16_t ni_qos_rxseqs[IEEE80211_NUM_TID]; + int ni_fails; /* failure count to associate */ + uint32_t ni_assoc_fail; /* assoc failure reasons */ +#define IEEE80211_NODE_ASSOCFAIL_CHAN 0x01 +#define IEEE80211_NODE_ASSOCFAIL_IBSS 0x02 +#define IEEE80211_NODE_ASSOCFAIL_PRIVACY 0x04 +#define IEEE80211_NODE_ASSOCFAIL_BASIC_RATE 0x08 +#define IEEE80211_NODE_ASSOCFAIL_ESSID 0x10 +#define IEEE80211_NODE_ASSOCFAIL_BSSID 0x20 +#define IEEE80211_NODE_ASSOCFAIL_WPA_PROTO 0x40 +#define IEEE80211_NODE_ASSOCFAIL_WPA_KEY 0x80 + + int ni_inact; /* inactivity mark count */ + int ni_txrate; /* index to ni_rates[] */ + int ni_state; + + u_int32_t ni_flags; /* special-purpose state */ +#define IEEE80211_NODE_ERP 0x0001 +#define IEEE80211_NODE_QOS 0x0002 +#define IEEE80211_NODE_REKEY 0x0004 /* GTK rekeying in progress */ +#define IEEE80211_NODE_RXPROT 0x0008 /* RX protection ON */ +#define IEEE80211_NODE_TXPROT 0x0010 /* TX protection ON */ +#define IEEE80211_NODE_TXRXPROT \ + (IEEE80211_NODE_TXPROT | IEEE80211_NODE_RXPROT) +#define IEEE80211_NODE_RXMGMTPROT 0x0020 /* RX MMPDU protection ON */ +#define IEEE80211_NODE_TXMGMTPROT 0x0040 /* TX MMPDU protection ON */ +#define IEEE80211_NODE_MFP 0x0080 /* MFP negotiated */ +#define IEEE80211_NODE_PMK 0x0100 /* ni_pmk set */ +#define IEEE80211_NODE_PMKID 0x0200 /* ni_pmkid set */ +#define IEEE80211_NODE_HT 0x0400 /* HT negotiated */ +#define IEEE80211_NODE_SA_QUERY 0x0800 /* SA Query in progress */ +#define IEEE80211_NODE_SA_QUERY_FAILED 0x1000 /* last SA Query failed */ +#define IEEE80211_NODE_RSN_NEW_PTK 0x2000 /* expecting a new PTK */ +#define IEEE80211_NODE_HT_SGI20 0x4000 /* SGI on 20 MHz negotiated */ +#define IEEE80211_NODE_HT_SGI40 0x8000 /* SGI on 40 MHz negotiated */ +#define IEEE80211_NODE_VHT 0x10000 /* VHT negotiated */ +#define IEEE80211_NODE_HTCAP 0x20000 /* claims to support HT */ +#define IEEE80211_NODE_VHTCAP 0x40000 /* claims to support VHT */ +#define IEEE80211_NODE_VHT_SGI80 0x80000 /* SGI on 80 MHz negotiated */ +#define IEEE80211_NODE_VHT_SGI160 0x100000 /* SGI on 160 MHz negotiated */ + + /* If not NULL, this function gets called when ni_refcnt hits zero. */ + void (*ni_unref_cb)(struct ieee80211com *, + struct ieee80211_node *); + void * ni_unref_arg; + size_t ni_unref_arg_size; +}; + +RBT_HEAD(ieee80211_tree, ieee80211_node); + +struct ieee80211_ess_rbt { + RBT_ENTRY(ieee80211_ess_rbt) ess_rbt; + u_int8_t esslen; + u_int8_t essid[IEEE80211_NWID_LEN]; + struct ieee80211_node *ni2; + struct ieee80211_node *ni5; + struct ieee80211_node *ni; +}; + +RBT_HEAD(ieee80211_ess_tree, ieee80211_ess_rbt); + +static inline void +ieee80211_node_incref(struct ieee80211_node *ni) +{ + int s; + + s = splnet(); + ni->ni_refcnt++; + splx(s); +} + +static inline u_int +ieee80211_node_decref(struct ieee80211_node *ni) +{ + u_int refcnt; + int s; + + s = splnet(); + refcnt = --ni->ni_refcnt; + splx(s); + return refcnt; +} + +static inline struct ieee80211_node * +ieee80211_ref_node(struct ieee80211_node *ni) +{ + ieee80211_node_incref(ni); + return ni; +} + +static inline void +ieee80211_unref_node(struct ieee80211_node **ni) +{ + ieee80211_node_decref(*ni); + *ni = NULL; /* guard against use */ +} + +/* + * Check if the peer supports HT. + * Require a HT capabilities IE and at least one of the mandatory MCS. + * MCS 0-7 are mandatory but some APs have particular MCS disabled. + */ +static inline int +ieee80211_node_supports_ht(struct ieee80211_node *ni) +{ + return ((ni->ni_flags & IEEE80211_NODE_HTCAP) && + ni->ni_rxmcs[0] & 0xff); +} + +/* Check if the peer supports HT short guard interval (SGI) on 20 MHz. */ +static inline int +ieee80211_node_supports_ht_sgi20(struct ieee80211_node *ni) +{ + return ieee80211_node_supports_ht(ni) && + (ni->ni_htcaps & IEEE80211_HTCAP_SGI20); +} + +/* Check if the peer supports HT short guard interval (SGI) on 40 MHz. */ +static inline int +ieee80211_node_supports_ht_sgi40(struct ieee80211_node *ni) +{ + return ieee80211_node_supports_ht(ni) && + (ni->ni_htcaps & IEEE80211_HTCAP_SGI40); +} + +/* Check if the peer can receive frames sent on a 40 MHz channel. */ +static inline int +ieee80211_node_supports_ht_chan40(struct ieee80211_node *ni) +{ + return (ieee80211_node_supports_ht(ni) && + (ni->ni_htcaps & IEEE80211_HTCAP_CBW20_40) && + (ni->ni_htop0 & IEEE80211_HTOP0_CHW)); +} + +/* + * Check if the peer supports VHT. + * Require a VHT capabilities IE and support for VHT MCS with a single + * spatial stream. + */ +static inline int +ieee80211_node_supports_vht(struct ieee80211_node *ni) +{ + uint16_t rx_mcs; + + rx_mcs = (ni->ni_vht_rxmcs & IEEE80211_VHT_MCS_FOR_SS_MASK(1)) >> + IEEE80211_VHT_MCS_FOR_SS_SHIFT(1); + + return ((ni->ni_flags & IEEE80211_NODE_VHTCAP) && + rx_mcs != IEEE80211_VHT_MCS_SS_NOT_SUPP); +} + +/* Check if the peer supports VHT short guard interval (SGI) on 80 MHz. */ +static inline int +ieee80211_node_supports_vht_sgi80(struct ieee80211_node *ni) +{ + return ieee80211_node_supports_vht(ni) && + (ni->ni_vhtcaps & IEEE80211_VHTCAP_SGI80); +} + +/* Check if the peer supports VHT short guard interval (SGI) on 160 MHz. */ +static inline int +ieee80211_node_supports_vht_sgi160(struct ieee80211_node *ni) +{ + return ieee80211_node_supports_vht(ni) && + (ni->ni_vhtcaps & IEEE80211_VHTCAP_SGI160); +} + +/* Check if the peer can receive frames sent on an 80 MHz channel. */ +static inline int +ieee80211_node_supports_vht_chan80(struct ieee80211_node *ni) +{ + uint8_t cap_chan_width, op_chan_width; + + if (!ieee80211_node_supports_vht(ni)) + return 0; + + cap_chan_width = (ni->ni_vhtcaps & IEEE80211_VHTCAP_CHAN_WIDTH_MASK) >> + IEEE80211_VHTCAP_CHAN_WIDTH_SHIFT; + if (cap_chan_width != IEEE80211_VHTCAP_CHAN_WIDTH_80 && + cap_chan_width != IEEE80211_VHTCAP_CHAN_WIDTH_160 && + cap_chan_width != IEEE80211_VHTCAP_CHAN_WIDTH_160_8080) + return 0; + + op_chan_width = (ni->ni_vht_chan_width & + IEEE80211_VHTOP0_CHAN_WIDTH_MASK) >> + IEEE80211_VHTOP0_CHAN_WIDTH_SHIFT; + + return (op_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_80 || + op_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_160 || + op_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_8080); +} + +/* Check if the peer can receive frames sent on a 160 MHz channel. */ +static inline int +ieee80211_node_supports_vht_chan160(struct ieee80211_node *ni) +{ + uint8_t cap_chan_width, op_chan_width; + + if (!ieee80211_node_supports_vht(ni)) + return 0; + + cap_chan_width = (ni->ni_vhtcaps & IEEE80211_VHTCAP_CHAN_WIDTH_MASK) >> + IEEE80211_VHTCAP_CHAN_WIDTH_SHIFT; + if (cap_chan_width != IEEE80211_VHTCAP_CHAN_WIDTH_160) + return 0; + + op_chan_width = (ni->ni_vht_chan_width & + IEEE80211_VHTOP0_CHAN_WIDTH_MASK) >> + IEEE80211_VHTOP0_CHAN_WIDTH_SHIFT; + + return (op_chan_width == IEEE80211_VHTOP0_CHAN_WIDTH_160); +} + +struct ieee80211com; + +typedef void ieee80211_iter_func(void *, struct ieee80211_node *); + +void ieee80211_node_attach(struct ifnet *); +void ieee80211_node_lateattach(struct ifnet *); +void ieee80211_node_detach(struct ifnet *); + +void ieee80211_begin_scan(struct ifnet *); +void ieee80211_next_scan(struct ifnet *); +void ieee80211_end_scan(struct ifnet *); +void ieee80211_reset_scan(struct ifnet *); +struct ieee80211_node *ieee80211_alloc_node(struct ieee80211com *, + const u_int8_t *); +struct ieee80211_node *ieee80211_dup_bss(struct ieee80211com *, + const u_int8_t *); +struct ieee80211_node *ieee80211_find_node(struct ieee80211com *, + const u_int8_t *); +void ieee80211_node_tx_ba_clear(struct ieee80211_node *, int); +void ieee80211_ba_del(struct ieee80211_node *); +struct ieee80211_node *ieee80211_find_rxnode(struct ieee80211com *, + const struct ieee80211_frame *); +struct ieee80211_node *ieee80211_find_txnode(struct ieee80211com *, + const u_int8_t *); +void ieee80211_release_node(struct ieee80211com *, + struct ieee80211_node *); +void ieee80211_node_cleanup(struct ieee80211com *, struct ieee80211_node *); +void ieee80211_free_allnodes(struct ieee80211com *, int); +void ieee80211_iterate_nodes(struct ieee80211com *, + ieee80211_iter_func *, void *); +void ieee80211_clean_cached(struct ieee80211com *); +void ieee80211_clean_nodes(struct ieee80211com *, int); +void ieee80211_setup_htcaps(struct ieee80211_node *, const uint8_t *, + uint8_t); +void ieee80211_clear_htcaps(struct ieee80211_node *); +int ieee80211_setup_htop(struct ieee80211_node *, const uint8_t *, + uint8_t, int); +void ieee80211_setup_vhtcaps(struct ieee80211_node *, const uint8_t *, + uint8_t); +void ieee80211_clear_vhtcaps(struct ieee80211_node *); +int ieee80211_setup_vhtop(struct ieee80211_node *, const uint8_t *, + uint8_t, int); +int ieee80211_setup_rates(struct ieee80211com *, + struct ieee80211_node *, const u_int8_t *, const u_int8_t *, int); +enum ieee80211_phymode ieee80211_node_abg_mode(struct ieee80211com *, + struct ieee80211_node *); +void ieee80211_node_trigger_addba_req(struct ieee80211_node *, int); +void ieee80211_count_longslotsta(void *, struct ieee80211_node *); +void ieee80211_count_nonerpsta(void *, struct ieee80211_node *); +void ieee80211_count_pssta(void *, struct ieee80211_node *); +void ieee80211_count_rekeysta(void *, struct ieee80211_node *); +void ieee80211_node_join(struct ieee80211com *, + struct ieee80211_node *, int); +void ieee80211_node_leave(struct ieee80211com *, + struct ieee80211_node *); +int ieee80211_match_bss(struct ieee80211com *, struct ieee80211_node *, int); +void ieee80211_node_tx_stopped(struct ieee80211com *, struct ieee80211_node *); +struct ieee80211_node *ieee80211_node_choose_bss(struct ieee80211com *, int, + struct ieee80211_node **); +void ieee80211_node_join_bss(struct ieee80211com *, struct ieee80211_node *); +void ieee80211_create_ibss(struct ieee80211com* , + struct ieee80211_channel *); +void ieee80211_notify_dtim(struct ieee80211com *); +void ieee80211_set_tim(struct ieee80211com *, int, int); +void ieee80211_free_node(struct ieee80211com *, struct ieee80211_node *); + +int ieee80211_node_cmp(const struct ieee80211_node *, + const struct ieee80211_node *); +int ieee80211_ess_cmp(const struct ieee80211_ess_rbt *, + const struct ieee80211_ess_rbt *); +RBT_PROTOTYPE(ieee80211_tree, ieee80211_node, ni_node, ieee80211_node_cmp); +RBT_PROTOTYPE(ieee80211_ess_tree, ieee80211_ess_rbt, ess_rbt, ieee80211_ess_cmp); + +#endif /* _NET80211_IEEE80211_NODE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net80211/ieee80211_priv.h b/lib/libc/include/generic-openbsd/net80211/ieee80211_priv.h new file mode 100644 index 0000000000..a6178833b2 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net80211/ieee80211_priv.h @@ -0,0 +1,135 @@ +/* $OpenBSD: ieee80211_priv.h,v 1.5 2009/01/26 19:09:41 damien Exp $ */ + +/*- + * Copyright (c) 2008 Damien Bergamini + * + * 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 _NET80211_IEEE80211_PRIV_H_ +#define _NET80211_IEEE80211_PRIV_H_ + +#ifdef IEEE80211_DEBUG +extern int ieee80211_debug; +#define DPRINTF(X) do { \ + if (ieee80211_debug) { \ + printf("%s: ", __func__); \ + printf X; \ + } \ +} while(0) +#else +#define DPRINTF(X) +#endif + +#define SEQ_LT(a,b) \ + ((((u_int16_t)(a) - (u_int16_t)(b)) & 0xfff) > 2048) + +#define IEEE80211_AID_SET(b, w) \ + ((w)[IEEE80211_AID(b) / 32] |= (1 << (IEEE80211_AID(b) % 32))) +#define IEEE80211_AID_CLR(b, w) \ + ((w)[IEEE80211_AID(b) / 32] &= ~(1 << (IEEE80211_AID(b) % 32))) +#define IEEE80211_AID_ISSET(b, w) \ + ((w)[IEEE80211_AID(b) / 32] & (1 << (IEEE80211_AID(b) % 32))) + +#define IEEE80211_RSNIE_MAXLEN \ + (2 + /* Version */ \ + 4 + /* Group Data Cipher Suite */ \ + 2 + /* Pairwise Cipher Suite Count */ \ + 4 * 2 + /* Pairwise Cipher Suite List (max 2) */ \ + 2 + /* AKM Suite List Count */ \ + 4 * 4 + /* AKM Suite List (max 4) */ \ + 2 + /* RSN Capabilities */ \ + 2 + /* PMKID Count */ \ + 16 * 1 + /* PMKID List (max 1) */ \ + 4) /* 11w: Group Integrity Cipher Suite */ + +#define IEEE80211_WPAIE_MAXLEN \ + (4 + /* MICROSOFT_OUI */ \ + 2 + /* Version */ \ + 4 + /* Group Cipher Suite */ \ + 2 + /* Pairwise Cipher Suite Count */ \ + 4 * 2 + /* Pairwise Cipher Suite List (max 2) */ \ + 2 + /* AKM Suite List Count */ \ + 4 * 2) /* AKM Suite List (max 2) */ + +struct ieee80211_rsnparams { + u_int16_t rsn_nakms; + u_int32_t rsn_akms; + u_int16_t rsn_nciphers; + u_int32_t rsn_ciphers; + enum ieee80211_cipher rsn_groupcipher; + enum ieee80211_cipher rsn_groupmgmtcipher; + u_int16_t rsn_caps; + u_int8_t rsn_npmkids; + const u_int8_t *rsn_pmkids; +}; + +/* unaligned big endian access */ +#define BE_READ_2(p) \ + ((u_int16_t) \ + ((((const u_int8_t *)(p))[0] << 8) | \ + (((const u_int8_t *)(p))[1]))) + +#define BE_READ_8(p) \ + ((u_int64_t)(p)[0] << 56 | (u_int64_t)(p)[1] << 48 | \ + (u_int64_t)(p)[2] << 40 | (u_int64_t)(p)[3] << 32 | \ + (u_int64_t)(p)[4] << 24 | (u_int64_t)(p)[5] << 16 | \ + (u_int64_t)(p)[6] << 8 | (u_int64_t)(p)[7]) + +#define BE_WRITE_2(p, v) do { \ + ((u_int8_t *)(p))[0] = (v) >> 8; \ + ((u_int8_t *)(p))[1] = (v) & 0xff; \ +} while (0) + +#define BE_WRITE_8(p, v) do { \ + (p)[0] = (v) >> 56; (p)[1] = (v) >> 48; \ + (p)[2] = (v) >> 40; (p)[3] = (v) >> 32; \ + (p)[4] = (v) >> 24; (p)[5] = (v) >> 16; \ + (p)[6] = (v) >> 8; (p)[7] = (v); \ +} while (0) + +/* unaligned little endian access */ +#define LE_READ_2(p) \ + ((u_int16_t) \ + ((((const u_int8_t *)(p))[0]) | \ + (((const u_int8_t *)(p))[1] << 8))) + +#define LE_READ_4(p) \ + ((u_int32_t) \ + ((((const u_int8_t *)(p))[0]) | \ + (((const u_int8_t *)(p))[1] << 8) | \ + (((const u_int8_t *)(p))[2] << 16) | \ + (((const u_int8_t *)(p))[3] << 24))) + +#define LE_READ_6(p) \ + ((u_int64_t)(p)[5] << 40 | (u_int64_t)(p)[4] << 32 | \ + (u_int64_t)(p)[3] << 24 | (u_int64_t)(p)[2] << 16 | \ + (u_int64_t)(p)[1] << 8 | (u_int64_t)(p)[0]) + +#define LE_WRITE_2(p, v) do { \ + ((u_int8_t *)(p))[0] = (v) & 0xff; \ + ((u_int8_t *)(p))[1] = (v) >> 8; \ +} while (0) + +#define LE_WRITE_4(p, v) do { \ + (p)[3] = (v) >> 24; (p)[2] = (v) >> 16; \ + (p)[1] = (v) >> 8; (p)[0] = (v); \ +} while (0) + +#define LE_WRITE_6(p, v) do { \ + (p)[5] = (v) >> 40; (p)[4] = (v) >> 32; \ + (p)[3] = (v) >> 24; (p)[2] = (v) >> 16; \ + (p)[1] = (v) >> 8; (p)[0] = (v); \ +} while (0) + +#endif /* _NET80211_IEEE80211_PRIV_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net80211/ieee80211_proto.h b/lib/libc/include/generic-openbsd/net80211/ieee80211_proto.h new file mode 100644 index 0000000000..46443677ce --- /dev/null +++ b/lib/libc/include/generic-openbsd/net80211/ieee80211_proto.h @@ -0,0 +1,189 @@ +/* $OpenBSD: ieee80211_proto.h,v 1.50 2025/06/14 08:46:34 jsg Exp $ */ +/* $NetBSD: ieee80211_proto.h,v 1.3 2003/10/13 04:23:56 dyoung Exp $ */ + +/*- + * Copyright (c) 2001 Atsushi Onoe + * Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: src/sys/net80211/ieee80211_proto.h,v 1.4 2003/08/19 22:17:03 sam Exp $ + */ +#ifndef _NET80211_IEEE80211_PROTO_H_ +#define _NET80211_IEEE80211_PROTO_H_ + +/* + * 802.11 protocol implementation definitions. + */ + +enum ieee80211_state { + IEEE80211_S_INIT = 0, /* default state */ + IEEE80211_S_SCAN = 1, /* scanning */ + IEEE80211_S_AUTH = 2, /* try to authenticate */ + IEEE80211_S_ASSOC = 3, /* try to assoc */ + IEEE80211_S_RUN = 4 /* associated */ +}; +#define IEEE80211_S_MAX (IEEE80211_S_RUN+1) + +#define IEEE80211_SEND_MGMT(_ic,_ni,_type,_arg) \ + ((*(_ic)->ic_send_mgmt)(_ic, _ni, _type, _arg, 0)) +/* shortcut */ +#define IEEE80211_SEND_ACTION(_ic,_ni,_categ,_action,_arg) \ + ((*(_ic)->ic_send_mgmt)(_ic, _ni, IEEE80211_FC0_SUBTYPE_ACTION, \ + (_categ) << 16 | (_action), _arg)) + +extern const char * const ieee80211_mgt_subtype_name[]; +extern const char * const ieee80211_state_name[IEEE80211_S_MAX]; +extern const char * const ieee80211_phymode_name[]; + +extern void ieee80211_proto_attach(struct ifnet *); +extern void ieee80211_proto_detach(struct ifnet *); + +struct ieee80211_node; +struct ieee80211_rxinfo; +struct ieee80211_rsnparams; +extern void ieee80211_rtm_80211info_task(void *); +extern void ieee80211_set_link_state(struct ieee80211com *, int); +extern u_int ieee80211_get_hdrlen(const struct ieee80211_frame *); +extern int ieee80211_classify(struct ieee80211com *, struct mbuf *); +extern void ieee80211_inputm(struct ifnet *, struct mbuf *, + struct ieee80211_node *, struct ieee80211_rxinfo *, + struct mbuf_list *); +extern void ieee80211_input(struct ifnet *, struct mbuf *, + struct ieee80211_node *, struct ieee80211_rxinfo *); +extern int ieee80211_output(struct ifnet *, struct mbuf *, struct sockaddr *, + struct rtentry *); +extern void ieee80211_recv_mgmt(struct ieee80211com *, struct mbuf *, + struct ieee80211_node *, struct ieee80211_rxinfo *, int); +extern int ieee80211_send_mgmt(struct ieee80211com *, struct ieee80211_node *, + int, int, int); +extern void ieee80211_eapol_key_input(struct ieee80211com *, struct mbuf *, + struct ieee80211_node *); +extern void ieee80211_tx_compressed_bar(struct ieee80211com *, + struct ieee80211_node *, int, uint16_t); +extern struct mbuf *ieee80211_encap(struct ifnet *, struct mbuf *, + struct ieee80211_node **); +extern struct mbuf *ieee80211_get_rts(struct ieee80211com *, + const struct ieee80211_frame *, u_int16_t); +extern struct mbuf *ieee80211_get_cts_to_self(struct ieee80211com *, + u_int16_t); +extern struct mbuf *ieee80211_get_compressed_bar(struct ieee80211com *, + struct ieee80211_node *, int, uint16_t); +extern struct mbuf *ieee80211_beacon_alloc(struct ieee80211com *, + struct ieee80211_node *); +extern int ieee80211_save_ie(const u_int8_t *, u_int8_t **); +extern void ieee80211_eapol_timeout(void *); +extern int ieee80211_send_4way_msg1(struct ieee80211com *, + struct ieee80211_node *); +extern int ieee80211_send_4way_msg2(struct ieee80211com *, + struct ieee80211_node *, const u_int8_t *, + const struct ieee80211_ptk *); +extern int ieee80211_send_4way_msg3(struct ieee80211com *, + struct ieee80211_node *); +extern int ieee80211_send_4way_msg4(struct ieee80211com *, + struct ieee80211_node *); +extern int ieee80211_send_group_msg1(struct ieee80211com *, + struct ieee80211_node *); +extern int ieee80211_send_group_msg2(struct ieee80211com *, + struct ieee80211_node *, const struct ieee80211_key *); +extern int ieee80211_send_eapol_key_req(struct ieee80211com *, + struct ieee80211_node *, u_int16_t, u_int64_t); +extern int ieee80211_pwrsave(struct ieee80211com *, struct mbuf *, + struct ieee80211_node *); +#define ieee80211_new_state(_ic, _nstate, _arg) \ + (((_ic)->ic_newstate)((_ic), (_nstate), (_arg))) +extern enum ieee80211_edca_ac ieee80211_up_to_ac(struct ieee80211com *, int); +extern u_int8_t *ieee80211_add_capinfo(u_int8_t *, struct ieee80211com *, + const struct ieee80211_node *); +extern u_int8_t *ieee80211_add_ssid(u_int8_t *, const u_int8_t *, u_int); +extern u_int8_t *ieee80211_add_rates(u_int8_t *, + const struct ieee80211_rateset *); +extern u_int8_t *ieee80211_add_ds_params(u_int8_t *, struct ieee80211com *, + const struct ieee80211_node *); +extern u_int8_t *ieee80211_add_tim(u_int8_t *, struct ieee80211com *); +extern u_int8_t *ieee80211_add_ibss_params(u_int8_t *, + const struct ieee80211_node *); +extern u_int8_t *ieee80211_add_edca_params(u_int8_t *, struct ieee80211com *); +extern u_int8_t *ieee80211_add_erp(u_int8_t *, struct ieee80211com *); +extern u_int8_t *ieee80211_add_qos_capability(u_int8_t *, + struct ieee80211com *); +extern u_int8_t *ieee80211_add_rsn(u_int8_t *, struct ieee80211com *, + const struct ieee80211_node *); +extern u_int8_t *ieee80211_add_wpa(u_int8_t *, struct ieee80211com *, + const struct ieee80211_node *); +extern u_int8_t *ieee80211_add_xrates(u_int8_t *, + const struct ieee80211_rateset *); +extern u_int8_t *ieee80211_add_htcaps(u_int8_t *, struct ieee80211com *); +extern u_int8_t *ieee80211_add_htop(u_int8_t *, struct ieee80211com *); +extern u_int8_t *ieee80211_add_vhtcaps(u_int8_t *, struct ieee80211com *); +extern u_int8_t *ieee80211_add_tie(u_int8_t *, u_int8_t, u_int32_t); + +extern int ieee80211_parse_rsn(struct ieee80211com *, const u_int8_t *, + struct ieee80211_rsnparams *); +extern int ieee80211_parse_wpa(struct ieee80211com *, const u_int8_t *, + struct ieee80211_rsnparams *); +extern void ieee80211_print_essid(const u_int8_t *, int); +#ifdef IEEE80211_DEBUG +extern void ieee80211_dump_pkt(const u_int8_t *, int, int, int); +#endif +extern int ieee80211_ibss_merge(struct ieee80211com *, + struct ieee80211_node *, u_int64_t); +extern void ieee80211_reset_erp(struct ieee80211com *); +extern void ieee80211_set_shortslottime(struct ieee80211com *, int); +extern void ieee80211_auth_open_confirm(struct ieee80211com *, + struct ieee80211_node *, uint16_t); +extern void ieee80211_auth_open(struct ieee80211com *, + const struct ieee80211_frame *, struct ieee80211_node *, + struct ieee80211_rxinfo *rs, u_int16_t, u_int16_t); +extern void ieee80211_stop_ampdu_tx(struct ieee80211com *, + struct ieee80211_node *, int); +extern void ieee80211_gtk_rekey_timeout(void *); +extern int ieee80211_keyrun(struct ieee80211com *, u_int8_t *); +extern void ieee80211_setkeys(struct ieee80211com *); +extern void ieee80211_setkeysdone(struct ieee80211com *); +extern void ieee80211_sa_query_timeout(void *); +extern void ieee80211_sa_query_request(struct ieee80211com *, + struct ieee80211_node *); +extern void ieee80211_ht_negotiate(struct ieee80211com *, + struct ieee80211_node *); +extern void ieee80211_vht_negotiate(struct ieee80211com *, + struct ieee80211_node *); +extern void ieee80211_tx_ba_timeout(void *); +extern void ieee80211_rx_ba_timeout(void *); +extern int ieee80211_addba_request(struct ieee80211com *, + struct ieee80211_node *, u_int16_t, u_int8_t); +extern void ieee80211_delba_request(struct ieee80211com *, + struct ieee80211_node *, u_int16_t, u_int8_t, u_int8_t); +extern void ieee80211_addba_req_accept(struct ieee80211com *, + struct ieee80211_node *, uint8_t); +extern void ieee80211_addba_req_refuse(struct ieee80211com *, + struct ieee80211_node *, uint8_t); +extern void ieee80211_addba_resp_accept(struct ieee80211com *, + struct ieee80211_node *, uint8_t); +extern void ieee80211_addba_resp_refuse(struct ieee80211com *, + struct ieee80211_node *, uint8_t, uint16_t); +extern void ieee80211_output_ba_move_window(struct ieee80211com *, + struct ieee80211_node *, uint8_t, uint16_t); + +#endif /* _NET80211_IEEE80211_PROTO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net80211/ieee80211_ra.h b/lib/libc/include/generic-openbsd/net80211/ieee80211_ra.h new file mode 100644 index 0000000000..8ead145b84 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net80211/ieee80211_ra.h @@ -0,0 +1,82 @@ +/* $OpenBSD: ieee80211_ra.h,v 1.2 2021/10/11 09:01:06 stsp Exp $ */ + +/* + * Copyright (c) 2021 Christian Ehrhardt + * Copyright (c) 2021 Stefan Sperling + * + * 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. + */ + +/* + * Goodput statistics struct. Measures the effective data rate of an MCS. + * All uint64_t numbers in this struct use fixed-point arithmetic. + */ +struct ieee80211_ra_goodput_stats { + uint64_t measured; /* Most recently measured goodput. */ + uint64_t average; /* Average measured goodput. */ + uint64_t stddeviation; /* Goodput standard deviation. */ + uint64_t loss; /* This rate's loss percentage SFER. */ + uint32_t nprobe_pkts; /* Number of packets in current probe. */ + uint32_t nprobe_fail; /* Number of failed packets. */ +}; + +/* + * Rate adaptation state. + * + * Drivers should not modify any fields of this structure directly. + * Use ieee80211_ra_init() and ieee80211_ra_add_stats() only. + */ +struct ieee80211_ra_node { + /* Bitmaps MCS 0-31. */ + uint32_t valid_probes; + uint32_t valid_rates; + uint32_t candidate_rates; + uint32_t probed_rates; + + /* Probing state. */ + int probing; +#define IEEE80211_RA_NOT_PROBING 0x0 +#define IEEE80211_RA_PROBING_DOWN 0x1 +#define IEEE80211_RA_PROBING_UP 0x2 +#define IEEE80211_RA_PROBING_INTER 0x4 /* combined with UP or DOWN */ + + /* The current best MCS found by probing. */ + int best_mcs; + + /* Goodput statistics for each MCS. */ + struct ieee80211_ra_goodput_stats g[IEEE80211_HT_RATESET_NUM_MCS]; +}; + +/* Initialize rate adaptation state. */ +void ieee80211_ra_node_init(struct ieee80211_ra_node *); + +/* + * Drivers report information about 802.11n/HT Tx attempts here. + * mcs: The HT MCS used during this Tx attempt. + * total: How many Tx attempts (initial attempt + any retries) were made? + * fail: How many of these Tx attempts failed? + */ +void ieee80211_ra_add_stats_ht(struct ieee80211_ra_node *, + struct ieee80211com *, struct ieee80211_node *, + int mcs, unsigned int total, unsigned int fail); + +/* Drivers call this function to update ni->ni_txmcs. */ +void ieee80211_ra_choose(struct ieee80211_ra_node *, + struct ieee80211com *, struct ieee80211_node *); + +/* Get the HT rateset for a particular HT MCS with 40MHz and/or SGI on/off. */ +const struct ieee80211_ht_rateset * ieee80211_ra_get_ht_rateset(int mcs, + int chan40, int sgi); + +/* Check whether SGI should be used. */ +int ieee80211_ra_use_ht_sgi(struct ieee80211_node *); \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net80211/ieee80211_ra_vht.h b/lib/libc/include/generic-openbsd/net80211/ieee80211_ra_vht.h new file mode 100644 index 0000000000..bb49453b36 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net80211/ieee80211_ra_vht.h @@ -0,0 +1,91 @@ +/* $OpenBSD: ieee80211_ra_vht.h,v 1.1 2022/03/19 10:25:09 stsp Exp $ */ + +/* + * Copyright (c) 2021 Christian Ehrhardt + * Copyright (c) 2021, 2022 Stefan Sperling + * + * 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. + */ + +/* + * Goodput statistics struct. Measures the effective data rate of a rate. + * All uint64_t numbers in this struct use fixed-point arithmetic. + */ +struct ieee80211_ra_vht_goodput_stats { + uint64_t measured; /* Most recently measured goodput. */ + uint64_t average; /* Average measured goodput. */ + uint64_t stddeviation; /* Goodput standard deviation. */ + uint64_t loss; /* This rate's loss percentage SFER. */ + uint32_t nprobe_pkts; /* Number of packets in current probe. */ + uint32_t nprobe_fail; /* Number of failed packets. */ +}; + +/* + * Rate adaptation state. + * + * Drivers should not modify any fields of this structure directly. + * Use ieee80211_ra_vht_init() and ieee80211_ra_vht_add_stats() only. + */ +struct ieee80211_ra_vht_node { + /* Bitmaps for MCS 0-9 for a given number of spatial streams. */ + uint16_t valid_probes[IEEE80211_VHT_NUM_SS]; + uint16_t valid_rates[IEEE80211_VHT_NUM_SS]; + uint16_t candidate_rates[IEEE80211_VHT_NUM_SS]; + uint16_t probed_rates[IEEE80211_VHT_NUM_SS]; + + /* Maximum usable MCS per given number of spatial streams. */ + int max_mcs[IEEE80211_VHT_NUM_SS]; + + /* Probing state. */ + int probing; +#define IEEE80211_RA_NOT_PROBING 0x0 +#define IEEE80211_RA_PROBING_DOWN 0x1 +#define IEEE80211_RA_PROBING_UP 0x2 +#define IEEE80211_RA_PROBING_INTER 0x4 /* combined with UP or DOWN */ + + /* The current best MCS,NSS found by probing. */ + int best_mcs; + int best_nss; + + /* Goodput statistics for each rate. */ + struct ieee80211_ra_vht_goodput_stats + g[IEEE80211_VHT_NUM_RATESETS][IEEE80211_VHT_RATESET_MAX_NRATES]; +}; + +/* Initialize rate adaptation state. */ +void ieee80211_ra_vht_node_init(struct ieee80211_ra_vht_node *); + +/* + * Drivers report information about 802.11ac/VHT Tx attempts here. + * mcs: The VHT MCS used during this Tx attempt. + * nss: The number of spatial streams used during this Tx attempt. + * total: How many Tx attempts (initial attempt + any retries) were made? + * fail: How many of these Tx attempts failed? + */ +void ieee80211_ra_vht_add_stats(struct ieee80211_ra_vht_node *, + struct ieee80211com *, struct ieee80211_node *, + int mcs, int nss, unsigned int total, unsigned int fail); + +/* Drivers call this function to update ni->ni_txmcs and ni->ni_vht_ss. */ +void ieee80211_ra_vht_choose(struct ieee80211_ra_vht_node *, + struct ieee80211com *, struct ieee80211_node *); + +/* + * Get the VHT rateset for a particular VHT MCS, NSS, with 40MHz, 80MHz, + * and/or SGI on/off. + */ +const struct ieee80211_vht_rateset * ieee80211_ra_vht_get_rateset(int mcs, + int nss, int chan40, int chan80, int sgi); + +/* Check whether SGI should be used. */ +int ieee80211_ra_vht_use_sgi(struct ieee80211_node *); \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net80211/ieee80211_radiotap.h b/lib/libc/include/generic-openbsd/net80211/ieee80211_radiotap.h new file mode 100644 index 0000000000..302030262b --- /dev/null +++ b/lib/libc/include/generic-openbsd/net80211/ieee80211_radiotap.h @@ -0,0 +1,215 @@ +/* $OpenBSD: ieee80211_radiotap.h,v 1.17 2022/03/14 15:06:04 stsp Exp $ */ +/* $FreeBSD: src/sys/net80211/ieee80211_radiotap.h,v 1.3 2004/04/05 22:13:21 sam Exp $ */ +/* $NetBSD: ieee80211_radiotap.h,v 1.9 2004/06/06 04:13:28 dyoung Exp $ */ + +/*- + * Copyright (c) 2003, 2004 David Young. 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 DAVID YOUNG ``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 DAVID + * YOUNG 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 _NET_IF_IEEE80211RADIOTAP_H_ +#define _NET_IF_IEEE80211RADIOTAP_H_ + +/* A generic radio capture format is desirable. There is one for + * Linux, but it is neither rigidly defined (there were not even + * units given for some fields) nor easily extensible. + * + * I suggest the following extensible radio capture format. It is + * based on a bitmap indicating which fields are present. + * + * I am trying to describe precisely what the application programmer + * should expect in the following, and for that reason I tell the + * units and origin of each measurement (where it applies), or else I + * use sufficiently weaselly language ("is a monotonically nondecreasing + * function of...") that I cannot set false expectations for lawyerly + * readers. + */ + +/* XXX tcpdump/libpcap do not tolerate variable-length headers, + * yet, so we pad every radiotap header to 64 bytes. Ugh. + */ +#define IEEE80211_RADIOTAP_HDRLEN 64 + +/* The radio capture header precedes the 802.11 header. */ +struct ieee80211_radiotap_header { + u_int8_t it_version; /* Version 0. Only increases + * for drastic changes, + * introduction of compatible + * new fields does not count. + */ + u_int8_t it_pad; + u_int16_t it_len; /* length of the whole + * header in bytes, including + * it_version, it_pad, + * it_len, and data fields. + */ + u_int32_t it_present; /* A bitmap telling which + * fields are present. Set bit 31 + * (0x80000000) to extend the + * bitmap by another 32 bits. + * Additional extensions are made + * by setting bit 31. + */ +} __packed; + +/* Name Data type Units + * ---- --------- ----- + * + * IEEE80211_RADIOTAP_TSFT u_int64_t microseconds + * + * Value in microseconds of the MAC's 64-bit 802.11 Time + * Synchronization Function timer when the first bit of the + * MPDU arrived at the MAC. For received frames, only. + * + * IEEE80211_RADIOTAP_CHANNEL 2 x u_int16_t MHz, bitmap + * + * Tx/Rx frequency in MHz, followed by flags (see below). + * + * IEEE80211_RADIOTAP_FHSS u_int16_t see below + * + * For frequency-hopping radios, the hop set (first byte) + * and pattern (second byte). + * + * IEEE80211_RADIOTAP_RATE u_int8_t 500kb/s or MCS index + * + * Tx/Rx data rate in units of 500kb/s. If the high bit (0x80) is set + * the remaining bits contain an MCS index instead of a date rate. + * + * IEEE80211_RADIOTAP_DBM_ANTSIGNAL int8_t decibels from + * one milliwatt (dBm) + * + * RF signal power at the antenna, decibel difference from + * one milliwatt. + * + * IEEE80211_RADIOTAP_DBM_ANTNOISE int8_t decibels from + * one milliwatt (dBm) + * + * RF noise power at the antenna, decibel difference from one + * milliwatt. + * + * IEEE80211_RADIOTAP_DB_ANTSIGNAL u_int8_t decibel (dB) + * + * RF signal power at the antenna, decibel difference from an + * arbitrary, fixed reference. + * + * IEEE80211_RADIOTAP_DB_ANTNOISE u_int8_t decibel (dB) + * + * RF noise power at the antenna, decibel difference from an + * arbitrary, fixed reference point. + * + * IEEE80211_RADIOTAP_BARKER_CODE_LOCK u_int16_t unitless + * + * Quality of Barker code lock. Unitless. Monotonically + * nondecreasing with "better" lock strength. Called "Signal + * Quality" in datasheets. (Is there a standard way to measure + * this?) + * + * IEEE80211_RADIOTAP_TX_ATTENUATION u_int16_t unitless + * + * Transmit power expressed as unitless distance from max + * power set at factory calibration. 0 is max power. + * Monotonically nondecreasing with lower power levels. + * + * IEEE80211_RADIOTAP_DB_TX_ATTENUATION u_int16_t decibels (dB) + * + * Transmit power expressed as decibel distance from max power + * set at factory calibration. 0 is max power. Monotonically + * nondecreasing with lower power levels. + * + * IEEE80211_RADIOTAP_DBM_TX_POWER int8_t decibels from + * one milliwatt (dBm) + * + * Transmit power expressed as dBm (decibels from a 1 milliwatt + * reference). This is the absolute power level measured at + * the antenna port. + * + * IEEE80211_RADIOTAP_FLAGS u_int8_t bitmap + * + * Properties of transmitted and received frames. See flags + * defined below. + * + * IEEE80211_RADIOTAP_ANTENNA u_int8_t antenna index + * + * Unitless indication of the Rx/Tx antenna for this packet. + * The first antenna is antenna 0. + * + * IEEE80211_RADIOTAP_FCS u_int32_t data + * + * FCS from frame in network byte order. + * + * IEEE80211_RADIOTAP_RSSI 2x u_int8_t RSSI, max RSSI + * + * A relative Received Signal Strength Index + */ +enum ieee80211_radiotap_type { + IEEE80211_RADIOTAP_TSFT = 0, + IEEE80211_RADIOTAP_FLAGS = 1, + IEEE80211_RADIOTAP_RATE = 2, + IEEE80211_RADIOTAP_CHANNEL = 3, + IEEE80211_RADIOTAP_FHSS = 4, + IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5, + IEEE80211_RADIOTAP_DBM_ANTNOISE = 6, + IEEE80211_RADIOTAP_LOCK_QUALITY = 7, + IEEE80211_RADIOTAP_TX_ATTENUATION = 8, + IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9, + IEEE80211_RADIOTAP_DBM_TX_POWER = 10, + IEEE80211_RADIOTAP_ANTENNA = 11, + IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12, + IEEE80211_RADIOTAP_DB_ANTNOISE = 13, + IEEE80211_RADIOTAP_FCS = 14, + IEEE80211_RADIOTAP_RSSI = 16, + IEEE80211_RADIOTAP_EXT = 31 +}; + +#ifndef _KERNEL +/* For IEEE80211_RADIOTAP_CHANNEL */ +#define IEEE80211_CHAN_CCK 0x0020 /* CCK channel */ +#define IEEE80211_CHAN_OFDM 0x0040 /* OFDM channel */ +#define IEEE80211_CHAN_2GHZ 0x0080 /* 2 GHz spectrum channel */ +#define IEEE80211_CHAN_5GHZ 0x0100 /* 5 GHz spectrum channel */ +#define IEEE80211_CHAN_PASSIVE 0x0200 /* Only passive scan allowed */ +#define IEEE80211_CHAN_DYN 0x0400 /* Dynamic CCK-OFDM channel */ +#define IEEE80211_CHAN_GFSK 0x0800 /* GFSK channel (FHSS PHY) */ +#define IEEE80211_CHAN_XR 0x1000 /* Extended range OFDM channel */ +#define IEEE80211_CHAN_HT 0x2000 /* 11n/HT channel */ +#define IEEE80211_CHAN_VHT 0x4000 /* 11ac/VHT channel */ +#define IEEE80211_CHAN_40MHZ 0x8000 /* use of 40 MHz is allowed */ +#endif /* !_KERNEL */ + +/* For IEEE80211_RADIOTAP_FLAGS */ +#define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received + * during CFP + */ +#define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received + * with short + * preamble + */ +#define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received + * with WEP encryption + */ +#define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received + * with fragmentation + */ +#define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */ + +#endif /* _NET_IF_IEEE80211RADIOTAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net80211/ieee80211_regdomain.h b/lib/libc/include/generic-openbsd/net80211/ieee80211_regdomain.h new file mode 100644 index 0000000000..e4bfc67ef5 --- /dev/null +++ b/lib/libc/include/generic-openbsd/net80211/ieee80211_regdomain.h @@ -0,0 +1,768 @@ +/* $OpenBSD: ieee80211_regdomain.h,v 1.9 2016/01/12 09:28:09 stsp Exp $ */ + +/* + * Copyright (c) 2004, 2005 Reyk Floeter + * + * 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 _NET80211_IEEE80211_REGDOMAIN_H_ +#define _NET80211_IEEE80211_REGDOMAIN_H_ + +typedef u_int32_t ieee80211_regdomain_t; + +enum ieee80211_regdomain { + DMN_DEFAULT = 0x00, + DMN_NULL_WORLD = 0x03, + DMN_NULL_ETSIB = 0x07, + DMN_NULL_ETSIC = 0x08, + DMN_FCC1_FCCA = 0x10, + DMN_FCC1_WORLD = 0x11, + DMN_FCC2_FCCA = 0x20, + DMN_FCC2_WORLD = 0x21, + DMN_FCC2_ETSIC = 0x22, + DMN_FRANCE_NULL = 0x31, + DMN_FCC3_FCCA = 0x3A, + DMN_ETSI1_WORLD = 0x37, + DMN_ETSI3_ETSIA = 0x32, + DMN_ETSI2_WORLD = 0x35, + DMN_ETSI3_WORLD = 0x36, + DMN_ETSI4_WORLD = 0x30, + DMN_ETSI4_ETSIC = 0x38, + DMN_ETSI5_WORLD = 0x39, + DMN_ETSI6_WORLD = 0x34, + DMN_ETSI_NULL = 0x33, + DMN_MKK1_MKKA = 0x40, + DMN_MKK1_MKKB = 0x41, + DMN_APL4_WORLD = 0x42, + DMN_MKK2_MKKA = 0x43, + DMN_APL_NULL = 0x44, + DMN_APL2_WORLD = 0x45, + DMN_APL2_APLC = 0x46, + DMN_APL3_WORLD = 0x47, + DMN_MKK1_FCCA = 0x48, + DMN_APL2_APLD = 0x49, + DMN_MKK1_MKKA1 = 0x4A, + DMN_MKK1_MKKA2 = 0x4B, + DMN_APL1_WORLD = 0x52, + DMN_APL1_FCCA = 0x53, + DMN_APL1_APLA = 0x54, + DMN_APL1_ETSIC = 0x55, + DMN_APL2_ETSIC = 0x56, + DMN_APL5_WORLD = 0x58, + DMN_WOR0_WORLD = 0x60, + DMN_WOR1_WORLD = 0x61, + DMN_WOR2_WORLD = 0x62, + DMN_WOR3_WORLD = 0x63, + DMN_WOR4_WORLD = 0x64, + DMN_WOR5_ETSIC = 0x65, + DMN_WOR01_WORLD = 0x66, + DMN_WOR02_WORLD = 0x67, + DMN_EU1_WORLD = 0x68, + DMN_WOR9_WORLD = 0x69, + DMN_WORA_WORLD = 0x6A, + + DMN_APL1 = 0xf0000001, + DMN_APL2 = 0xf0000002, + DMN_APL3 = 0xf0000004, + DMN_APL4 = 0xf0000008, + DMN_APL5 = 0xf0000010, + DMN_ETSI1 = 0xf0000020, + DMN_ETSI2 = 0xf0000040, + DMN_ETSI3 = 0xf0000080, + DMN_ETSI4 = 0xf0000100, + DMN_ETSI5 = 0xf0000200, + DMN_ETSI6 = 0xf0000400, + DMN_ETSIA = 0xf0000800, + DMN_ETSIB = 0xf0001000, + DMN_ETSIC = 0xf0002000, + DMN_FCC1 = 0xf0004000, + DMN_FCC2 = 0xf0008000, + DMN_FCC3 = 0xf0010000, + DMN_FCCA = 0xf0020000, + DMN_APLD = 0xf0040000, + DMN_MKK1 = 0xf0080000, + DMN_MKK2 = 0xf0100000, + DMN_MKKA = 0xf0200000, + DMN_NULL = 0xf0400000, + DMN_WORLD = 0xf0800000, + DMN_DEBUG = 0xf1000000 /* used for debugging */ +}; + +#define IEEE80211_DMN(_d) ((_d) & ~0xf0000000) + +struct ieee80211_regdomainname { + u_int32_t rn_domain; + const char *rn_name; +}; + +#define IEEE80211_REGDOMAIN_NAMES { \ + { DMN_APL1, "APL1" }, \ + { DMN_APL1_APLA, "APL1A" }, \ + { DMN_APL1_ETSIC, "APL1_ETSIC" }, \ + { DMN_APL1_FCCA, "APL1_FCCA" }, \ + { DMN_APL1_WORLD, "APL1W" }, \ + { DMN_APL2, "APL2" }, \ + { DMN_APL2_APLC, "APL2C" }, \ + { DMN_APL2_APLD, "APL2D" }, \ + { DMN_APL2_ETSIC, "APL2_ETSIC" }, \ + { DMN_APL2_WORLD, "APL2W" }, \ + { DMN_APL3, "APL3" }, \ + { DMN_APL3_WORLD, "APL3W" }, \ + { DMN_APL4, "APL4" }, \ + { DMN_APL4_WORLD, "APL4W" }, \ + { DMN_APL5, "APL5" }, \ + { DMN_APL5_WORLD, "APL5W" }, \ + { DMN_APLD, "APLD" }, \ + { DMN_APL_NULL, "APL" }, \ + { DMN_DEBUG, "DEBUG" }, \ + { DMN_ETSI1, "ETSI1" }, \ + { DMN_ETSI1_WORLD, "ETSI1W" }, \ + { DMN_ETSI2, "ETSI2" }, \ + { DMN_ETSI2_WORLD, "ETSI2W" }, \ + { DMN_ETSI3, "ETSI3" }, \ + { DMN_ETSI3_ETSIA, "ETSI3A" }, \ + { DMN_ETSI3_WORLD, "ETSI3W," }, \ + { DMN_ETSI4, "ETSI4" }, \ + { DMN_ETSI4_ETSIC, "ETSI4C" }, \ + { DMN_ETSI4_WORLD, "ETSI4W" }, \ + { DMN_ETSI5, "ETSI5" }, \ + { DMN_ETSI5_WORLD, "ETSI5W" }, \ + { DMN_ETSI6, "ETSI6" }, \ + { DMN_ETSI6_WORLD, "ETSI6W" }, \ + { DMN_ETSIA, "ETSIA" }, \ + { DMN_ETSIB, "ETSIB" }, \ + { DMN_ETSIC, "ETSIC" }, \ + { DMN_ETSI_NULL, "ETSI" }, \ + { DMN_EU1_WORLD, "EU1W" }, \ + { DMN_FCC1, "FCC1" }, \ + { DMN_FCC1_FCCA, "FCC1A" }, \ + { DMN_FCC1_WORLD, "FCC1W" }, \ + { DMN_FCC2, "FCC2" }, \ + { DMN_FCC2_ETSIC, "FCC2C" }, \ + { DMN_FCC2_FCCA, "FCC2A" }, \ + { DMN_FCC2_WORLD, "FCC2W" }, \ + { DMN_FCC3, "FCC3" }, \ + { DMN_FCC3_FCCA, "FCC3A" }, \ + { DMN_FCCA, "FCCA" }, \ + { DMN_FRANCE_NULL, "FRANCE" }, \ + { DMN_MKK1, "MKK1" }, \ + { DMN_MKK1_FCCA, "MKK1_FCCA" }, \ + { DMN_MKK1_MKKA, "MKK1A" }, \ + { DMN_MKK1_MKKA1, "MKK1A1" }, \ + { DMN_MKK1_MKKA2, "MKK1A2" }, \ + { DMN_MKK1_MKKB, "MKK1B" }, \ + { DMN_MKK2, "MKK2" }, \ + { DMN_MKK2_MKKA, "MKK2A" }, \ + { DMN_MKKA, "MKKA" }, \ + { DMN_DEFAULT, "NONE" }, \ + { DMN_NULL, "NONE" }, \ + { DMN_NULL_ETSIB, "ETSIB" }, \ + { DMN_NULL_ETSIC, "ETSIC" }, \ + { DMN_WOR01_WORLD, "WOR01W" }, \ + { DMN_WOR02_WORLD, "WOR02W" }, \ + { DMN_WOR0_WORLD, "WOR0W" }, \ + { DMN_WOR1_WORLD, "WOR1W" }, \ + { DMN_WOR2_WORLD, "WOR2W" }, \ + { DMN_WOR3_WORLD, "WOR3W" }, \ + { DMN_WOR4_WORLD, "WOR4W" }, \ + { DMN_WOR5_ETSIC, "WOR5_ETSIC" }, \ + { DMN_WOR9_WORLD, "WOR9W" }, \ + { DMN_WORA_WORLD, "WORAW" }, \ + { DMN_NULL_WORLD, "WORLD" }, \ + { DMN_WORLD, "WORLD" } \ +} + +struct ieee80211_regdomainmap { + u_int16_t rm_domain; + u_int32_t rm_domain_5ghz; + u_int32_t rm_domain_2ghz; +}; + +#define IEEE80211_REGDOMAIN_MAP { \ + { DMN_DEFAULT, DMN_DEBUG, DMN_DEBUG }, \ + { DMN_NULL_WORLD, DMN_NULL, DMN_WORLD }, \ + { DMN_NULL_ETSIB, DMN_NULL, DMN_ETSIB }, \ + { DMN_NULL_ETSIC, DMN_NULL, DMN_ETSIC }, \ + { DMN_FCC1_FCCA, DMN_FCC1, DMN_FCCA }, \ + { DMN_FCC1_WORLD, DMN_FCC1, DMN_WORLD }, \ + { DMN_FCC2_FCCA, DMN_FCC2, DMN_FCCA }, \ + { DMN_FCC2_WORLD, DMN_FCC2, DMN_WORLD }, \ + { DMN_FCC2_ETSIC, DMN_FCC2, DMN_ETSIC }, \ + { DMN_FRANCE_NULL, DMN_ETSI3, DMN_ETSI3 }, \ + { DMN_FCC3_FCCA, DMN_FCC3, DMN_WORLD }, \ + { DMN_ETSI1_WORLD, DMN_ETSI1, DMN_WORLD }, \ + { DMN_ETSI3_ETSIA, DMN_ETSI3, DMN_WORLD }, \ + { DMN_ETSI2_WORLD, DMN_ETSI2, DMN_WORLD }, \ + { DMN_ETSI3_WORLD, DMN_ETSI3, DMN_WORLD }, \ + { DMN_ETSI4_WORLD, DMN_ETSI4, DMN_WORLD }, \ + { DMN_ETSI4_ETSIC, DMN_ETSI4, DMN_ETSIC }, \ + { DMN_ETSI5_WORLD, DMN_ETSI5, DMN_WORLD }, \ + { DMN_ETSI6_WORLD, DMN_ETSI6, DMN_WORLD }, \ + { DMN_ETSI_NULL, DMN_ETSI1, DMN_ETSI1 }, \ + { DMN_MKK1_MKKA, DMN_MKK1, DMN_MKKA }, \ + { DMN_MKK1_MKKB, DMN_MKK1, DMN_MKKA }, \ + { DMN_APL4_WORLD, DMN_APL4, DMN_WORLD }, \ + { DMN_MKK2_MKKA, DMN_MKK2, DMN_MKKA }, \ + { DMN_APL_NULL, DMN_APL1, DMN_NULL }, \ + { DMN_APL2_WORLD, DMN_APL2, DMN_WORLD }, \ + { DMN_APL2_APLC, DMN_APL2, DMN_WORLD }, \ + { DMN_APL3_WORLD, DMN_APL3, DMN_WORLD }, \ + { DMN_MKK1_FCCA, DMN_MKK1, DMN_FCCA }, \ + { DMN_APL2_APLD, DMN_APL2, DMN_APLD }, \ + { DMN_MKK1_MKKA1, DMN_MKK1, DMN_MKKA }, \ + { DMN_MKK1_MKKA2, DMN_MKK1, DMN_MKKA }, \ + { DMN_APL1_WORLD, DMN_APL1, DMN_WORLD }, \ + { DMN_APL1_FCCA, DMN_APL1, DMN_FCCA }, \ + { DMN_APL1_APLA, DMN_APL1, DMN_WORLD }, \ + { DMN_APL1_ETSIC, DMN_APL1, DMN_ETSIC }, \ + { DMN_APL2_ETSIC, DMN_APL2, DMN_ETSIC }, \ + { DMN_APL5_WORLD, DMN_APL5, DMN_WORLD }, \ + { DMN_WOR0_WORLD, DMN_WORLD, DMN_WORLD }, \ + { DMN_WOR1_WORLD, DMN_WORLD, DMN_WORLD }, \ + { DMN_WOR2_WORLD, DMN_WORLD, DMN_WORLD }, \ + { DMN_WOR3_WORLD, DMN_WORLD, DMN_WORLD }, \ + { DMN_WOR4_WORLD, DMN_WORLD, DMN_WORLD }, \ + { DMN_WOR5_ETSIC, DMN_WORLD, DMN_WORLD }, \ + { DMN_WOR01_WORLD, DMN_WORLD, DMN_WORLD }, \ + { DMN_WOR02_WORLD, DMN_WORLD, DMN_WORLD }, \ + { DMN_EU1_WORLD, DMN_ETSI1, DMN_WORLD }, \ + { DMN_WOR9_WORLD, DMN_WORLD, DMN_WORLD }, \ + { DMN_WORA_WORLD, DMN_WORLD, DMN_WORLD }, \ +} + +enum ieee80211_countrycode { + CTRY_DEFAULT = 0, /* Default domain (NA) */ + CTRY_ALBANIA = 8, /* Albania */ + CTRY_ALGERIA = 12, /* Algeria */ + CTRY_ARGENTINA = 32, /* Argentina */ + CTRY_ARMENIA = 51, /* Armenia */ + CTRY_AUSTRALIA = 36, /* Australia */ + CTRY_AUSTRIA = 40, /* Austria */ + CTRY_AZERBAIJAN = 31, /* Azerbaijan */ + CTRY_BAHRAIN = 48, /* Bahrain */ + CTRY_BELARUS = 112, /* Belarus */ + CTRY_BELGIUM = 56, /* Belgium */ + CTRY_BELIZE = 84, /* Belize */ + CTRY_BOLIVIA = 68, /* Bolivia */ + CTRY_BRAZIL = 76, /* Brazil */ + CTRY_BRUNEI_DARUSSALAM = 96, /* Brunei Darussalam */ + CTRY_BULGARIA = 100, /* Bulgaria */ + CTRY_CANADA = 124, /* Canada */ + CTRY_CHILE = 152, /* Chile */ + CTRY_CHINA = 156, /* People's Republic of China */ + CTRY_COLOMBIA = 170, /* Colombia */ + CTRY_COSTA_RICA = 188, /* Costa Rica */ + CTRY_CROATIA = 191, /* Croatia */ + CTRY_CYPRUS = 196, /* Cyprus */ + CTRY_CZECH = 203, /* Czech Republic */ + CTRY_DENMARK = 208, /* Denmark */ + CTRY_DOMINICAN_REPUBLIC = 214, /* Dominican Republic */ + CTRY_ECUADOR = 218, /* Ecuador */ + CTRY_EGYPT = 818, /* Egypt */ + CTRY_EL_SALVADOR = 222, /* El Salvador */ + CTRY_ESTONIA = 233, /* Estonia */ + CTRY_FAEROE_ISLANDS = 234, /* Faeroe Islands */ + CTRY_FINLAND = 246, /* Finland */ + CTRY_FRANCE = 250, /* France */ + CTRY_FRANCE2 = 255, /* France2 */ + CTRY_GEORGIA = 268, /* Georgia */ + CTRY_GERMANY = 276, /* Germany */ + CTRY_GREECE = 300, /* Greece */ + CTRY_GUATEMALA = 320, /* Guatemala */ + CTRY_HONDURAS = 340, /* Honduras */ + CTRY_HONG_KONG = 344, /* Hong Kong S.A.R., P.R.C. */ + CTRY_HUNGARY = 348, /* Hungary */ + CTRY_ICELAND = 352, /* Iceland */ + CTRY_INDIA = 356, /* India */ + CTRY_INDONESIA = 360, /* Indonesia */ + CTRY_IRAN = 364, /* Iran */ + CTRY_IRAQ = 368, /* Iraq */ + CTRY_IRELAND = 372, /* Ireland */ + CTRY_ISRAEL = 376, /* Israel */ + CTRY_ITALY = 380, /* Italy */ + CTRY_JAMAICA = 388, /* Jamaica */ + CTRY_JAPAN = 392, /* Japan */ + CTRY_JAPAN1 = 393, /* Japan (JP1) */ + CTRY_JAPAN2 = 394, /* Japan (JP0) */ + CTRY_JAPAN3 = 395, /* Japan (JP1-1) */ + CTRY_JAPAN4 = 396, /* Japan (JE1) */ + CTRY_JAPAN5 = 397, /* Japan (JE2) */ + CTRY_JORDAN = 400, /* Jordan */ + CTRY_KAZAKHSTAN = 398, /* Kazakhstan */ + CTRY_KENYA = 404, /* Kenya */ + CTRY_KOREA_NORTH = 408, /* North Korea */ + CTRY_KOREA_ROC = 410, /* South Korea */ + CTRY_KOREA_ROC2 = 411, /* South Korea */ + CTRY_KUWAIT = 414, /* Kuwait */ + CTRY_LATVIA = 428, /* Latvia */ + CTRY_LEBANON = 422, /* Lebanon */ + CTRY_LIBYA = 434, /* Libya */ + CTRY_LIECHTENSTEIN = 438, /* Liechtenstein */ + CTRY_LITHUANIA = 440, /* Lithuania */ + CTRY_LUXEMBOURG = 442, /* Luxembourg */ + CTRY_MACAU = 446, /* Macau */ + CTRY_MACEDONIA = 807, /* Republic of Macedonia */ + CTRY_MALAYSIA = 458, /* Malaysia */ + CTRY_MEXICO = 484, /* Mexico */ + CTRY_MONACO = 492, /* Principality of Monaco */ + CTRY_MOROCCO = 504, /* Morocco */ + CTRY_NETHERLANDS = 528, /* Netherlands */ + CTRY_NEW_ZEALAND = 554, /* New Zealand */ + CTRY_NICARAGUA = 558, /* Nicaragua */ + CTRY_NORWAY = 578, /* Norway */ + CTRY_OMAN = 512, /* Oman */ + CTRY_PAKISTAN = 586, /* Islamic Republic of Pakistan */ + CTRY_PANAMA = 591, /* Panama */ + CTRY_PARAGUAY = 600, /* Paraguay */ + CTRY_PERU = 604, /* Peru */ + CTRY_PHILIPPINES = 608, /* Republic of the Philippines */ + CTRY_POLAND = 616, /* Poland */ + CTRY_PORTUGAL = 620, /* Portugal */ + CTRY_PUERTO_RICO = 630, /* Puerto Rico */ + CTRY_QATAR = 634, /* Qatar */ + CTRY_ROMANIA = 642, /* Romania */ + CTRY_RUSSIA = 643, /* Russia */ + CTRY_SAUDI_ARABIA = 682, /* Saudi Arabia */ + CTRY_SINGAPORE = 702, /* Singapore */ + CTRY_SLOVAKIA = 703, /* Slovak Republic */ + CTRY_SLOVENIA = 705, /* Slovenia */ + CTRY_SOUTH_AFRICA = 710, /* South Africa */ + CTRY_SPAIN = 724, /* Spain */ + CTRY_SRI_LANKA = 728, /* Sri Lanka */ + CTRY_SWEDEN = 752, /* Sweden */ + CTRY_SWITZERLAND = 756, /* Switzerland */ + CTRY_SYRIA = 760, /* Syria */ + CTRY_TAIWAN = 158, /* Taiwan */ + CTRY_THAILAND = 764, /* Thailand */ + CTRY_TRINIDAD_Y_TOBAGO = 780, /* Trinidad y Tobago */ + CTRY_TUNISIA = 788, /* Tunisia */ + CTRY_TURKEY = 792, /* Turkey */ + CTRY_UAE = 784, /* U.A.E. */ + CTRY_UKRAINE = 804, /* Ukraine */ + CTRY_UNITED_KINGDOM = 826, /* United Kingdom */ + CTRY_UNITED_STATES = 840, /* United States */ + CTRY_URUGUAY = 858, /* Uruguay */ + CTRY_UZBEKISTAN = 860, /* Uzbekistan */ + CTRY_VENEZUELA = 862, /* Venezuela */ + CTRY_VIET_NAM = 704, /* Viet Nam */ + CTRY_YEMEN = 887, /* Yemen */ + CTRY_ZIMBABWE = 716, /* Zimbabwe */ +}; + +struct ieee80211_countryname { + u_int16_t cn_code; + const char *cn_name; + u_int32_t cn_domain; +}; + +#define IEEE80211_REGDOMAIN_COUNTRY_NAMES { \ + { CTRY_DEFAULT, "00", DMN_DEFAULT }, \ + { CTRY_UAE, "ae", DMN_NULL_WORLD }, \ + { CTRY_ALBANIA, "al", DMN_NULL_WORLD }, \ + { CTRY_ARMENIA, "am", DMN_ETSI4_WORLD }, \ + { CTRY_ARGENTINA, "ar", DMN_APL3_WORLD }, \ + { CTRY_AUSTRIA, "at", DMN_ETSI5_WORLD }, \ + { CTRY_AUSTRALIA, "au", DMN_FCC2_WORLD }, \ + { CTRY_AZERBAIJAN, "az", DMN_ETSI4_WORLD }, \ + { CTRY_BELGIUM, "be", DMN_ETSI4_WORLD }, \ + { CTRY_BULGARIA, "bg", DMN_ETSI6_WORLD }, \ + { CTRY_BAHRAIN, "bh", DMN_NULL_WORLD }, \ + { CTRY_BRUNEI_DARUSSALAM, "bn", DMN_APL1_WORLD }, \ + { CTRY_BOLIVIA, "bo", DMN_APL1_ETSIC }, \ + { CTRY_BRAZIL, "br", DMN_NULL_ETSIC }, \ + { CTRY_BELARUS, "by", DMN_NULL_WORLD }, \ + { CTRY_BELIZE, "bz", DMN_NULL_ETSIC }, \ + { CTRY_CANADA, "ca", DMN_FCC2_FCCA }, \ + { CTRY_SWITZERLAND, "ch", DMN_ETSI2_WORLD }, \ + { CTRY_CHILE, "cl", DMN_APL5_WORLD }, \ + { CTRY_CHINA, "cn", DMN_APL1_WORLD }, \ + { CTRY_COLOMBIA, "co", DMN_FCC1_FCCA }, \ + { CTRY_COSTA_RICA, "cr", DMN_NULL_WORLD }, \ + { CTRY_CYPRUS, "cy", DMN_ETSI1_WORLD }, \ + { CTRY_CZECH, "cz", DMN_ETSI3_WORLD }, \ + { CTRY_GERMANY, "de", DMN_ETSI1_WORLD }, \ + { CTRY_DENMARK, "dk", DMN_ETSI1_WORLD }, \ + { CTRY_DOMINICAN_REPUBLIC, "do", DMN_FCC1_FCCA }, \ + { CTRY_ALGERIA, "dz", DMN_NULL_WORLD }, \ + { CTRY_ECUADOR, "ec", DMN_NULL_WORLD }, \ + { CTRY_ESTONIA, "ee", DMN_ETSI1_WORLD }, \ + { CTRY_EGYPT, "eg", DMN_NULL_WORLD }, \ + { CTRY_SPAIN, "es", DMN_ETSI1_WORLD }, \ + { CTRY_FRANCE2, "f2", DMN_ETSI3_WORLD }, \ + { CTRY_FINLAND, "fi", DMN_ETSI1_WORLD }, \ + { CTRY_FAEROE_ISLANDS, "fo", DMN_NULL_WORLD }, \ + { CTRY_FRANCE, "fr", DMN_ETSI3_WORLD }, \ + { CTRY_GEORGIA, "ge", DMN_ETSI4_WORLD }, \ + { CTRY_GREECE, "gr", DMN_NULL_WORLD }, \ + { CTRY_GUATEMALA, "gt", DMN_FCC1_FCCA }, \ + { CTRY_HONG_KONG, "hk", DMN_FCC2_WORLD }, \ + { CTRY_HONDURAS, "hn", DMN_NULL_WORLD }, \ + { CTRY_CROATIA, "hr", DMN_ETSI3_WORLD }, \ + { CTRY_HUNGARY, "hu", DMN_ETSI2_WORLD }, \ + { CTRY_INDONESIA, "id", DMN_NULL_WORLD }, \ + { CTRY_IRELAND, "ie", DMN_ETSI1_WORLD }, \ + { CTRY_ISRAEL, "il", DMN_NULL_WORLD }, \ + { CTRY_INDIA, "in", DMN_NULL_WORLD }, \ + { CTRY_IRAQ, "iq", DMN_NULL_WORLD }, \ + { CTRY_IRAN, "ir", DMN_APL1_WORLD }, \ + { CTRY_ICELAND, "is", DMN_ETSI1_WORLD }, \ + { CTRY_ITALY, "it", DMN_ETSI1_WORLD }, \ + { CTRY_JAPAN1, "j1", DMN_MKK1_MKKB }, \ + { CTRY_JAPAN2, "j2", DMN_MKK1_FCCA }, \ + { CTRY_JAPAN3, "j3", DMN_MKK2_MKKA }, \ + { CTRY_JAPAN4, "j4", DMN_MKK1_MKKA1 }, \ + { CTRY_JAPAN5, "j5", DMN_MKK1_MKKA2 }, \ + { CTRY_JAMAICA, "jm", DMN_NULL_WORLD }, \ + { CTRY_JORDAN, "jo", DMN_NULL_WORLD }, \ + { CTRY_JAPAN, "jp", DMN_MKK1_MKKA }, \ + { CTRY_KOREA_ROC2, "k2", DMN_APL2_APLD }, \ + { CTRY_KENYA, "ke", DMN_NULL_WORLD }, \ + { CTRY_KOREA_NORTH, "kp", DMN_APL2_WORLD }, \ + { CTRY_KOREA_ROC, "kr", DMN_APL2_WORLD }, \ + { CTRY_KUWAIT, "kw", DMN_NULL_WORLD }, \ + { CTRY_KAZAKHSTAN, "kz", DMN_NULL_WORLD }, \ + { CTRY_LEBANON, "lb", DMN_NULL_WORLD }, \ + { CTRY_LIECHTENSTEIN, "li", DMN_ETSI2_WORLD }, \ + { CTRY_SRI_LANKA, "lk", DMN_NULL_WORLD }, \ + { CTRY_LITHUANIA, "lt", DMN_ETSI1_WORLD }, \ + { CTRY_LUXEMBOURG, "lu", DMN_ETSI1_WORLD }, \ + { CTRY_LATVIA, "lv", DMN_NULL_WORLD }, \ + { CTRY_LIBYA, "ly", DMN_NULL_WORLD }, \ + { CTRY_MOROCCO, "ma", DMN_NULL_WORLD }, \ + { CTRY_MONACO, "mc", DMN_ETSI4_WORLD }, \ + { CTRY_MACEDONIA, "mk", DMN_NULL_WORLD }, \ + { CTRY_MACAU, "mo", DMN_FCC2_WORLD }, \ + { CTRY_MEXICO, "mx", DMN_FCC1_FCCA }, \ + { CTRY_MALAYSIA, "my", DMN_NULL_WORLD }, \ + { CTRY_NICARAGUA, "ni", DMN_NULL_WORLD }, \ + { CTRY_NETHERLANDS, "nl", DMN_ETSI1_WORLD }, \ + { CTRY_NORWAY, "no", DMN_ETSI1_WORLD }, \ + { CTRY_NEW_ZEALAND, "nz", DMN_FCC2_ETSIC }, \ + { CTRY_OMAN, "om", DMN_NULL_WORLD }, \ + { CTRY_PANAMA, "pa", DMN_FCC1_FCCA }, \ + { CTRY_PERU, "pe", DMN_NULL_WORLD }, \ + { CTRY_PHILIPPINES, "ph", DMN_FCC1_WORLD }, \ + { CTRY_PAKISTAN, "pk", DMN_NULL_WORLD }, \ + { CTRY_POLAND, "pl", DMN_ETSI1_WORLD }, \ + { CTRY_PUERTO_RICO, "pr", DMN_FCC1_FCCA }, \ + { CTRY_PORTUGAL, "pt", DMN_ETSI1_WORLD }, \ + { CTRY_PARAGUAY, "py", DMN_NULL_WORLD }, \ + { CTRY_QATAR, "qa", DMN_NULL_WORLD }, \ + { CTRY_ROMANIA, "ro", DMN_NULL_WORLD }, \ + { CTRY_RUSSIA, "ru", DMN_NULL_WORLD }, \ + { CTRY_SAUDI_ARABIA, "sa", DMN_NULL_WORLD }, \ + { CTRY_SWEDEN, "se", DMN_ETSI1_WORLD }, \ + { CTRY_SINGAPORE, "sg", DMN_APL4_WORLD }, \ + { CTRY_SLOVENIA, "si", DMN_ETSI1_WORLD }, \ + { CTRY_SLOVAKIA, "sk", DMN_ETSI3_WORLD }, \ + { CTRY_EL_SALVADOR, "sv", DMN_NULL_WORLD }, \ + { CTRY_SYRIA, "sy", DMN_NULL_WORLD }, \ + { CTRY_THAILAND, "th", DMN_APL2_WORLD }, \ + { CTRY_TUNISIA, "tn", DMN_ETSI3_WORLD }, \ + { CTRY_TURKEY, "tr", DMN_ETSI3_WORLD }, \ + { CTRY_TRINIDAD_Y_TOBAGO, "tt", DMN_ETSI4_WORLD }, \ + { CTRY_TAIWAN, "tw", DMN_APL3_WORLD }, \ + { CTRY_UKRAINE, "ua", DMN_NULL_WORLD }, \ + { CTRY_UNITED_KINGDOM, "uk", DMN_ETSI1_WORLD }, \ + { CTRY_UNITED_STATES, "us", DMN_FCC1_FCCA }, \ + { CTRY_URUGUAY, "uy", DMN_APL2_WORLD }, \ + { CTRY_UZBEKISTAN, "uz", DMN_FCC3_FCCA }, \ + { CTRY_VENEZUELA, "ve", DMN_APL2_ETSIC }, \ + { CTRY_VIET_NAM, "vn", DMN_NULL_WORLD }, \ + { CTRY_YEMEN, "ye", DMN_NULL_WORLD }, \ + { CTRY_SOUTH_AFRICA, "za", DMN_ETSI1_WORLD }, \ + { CTRY_ZIMBABWE, "zw", DMN_NULL_WORLD }, \ +} + +enum ieee80211_ctl { + CTL_11A = 0x00, + CTL_11B = 0x01, + CTL_11G = 0x02, + CTL_TURBO = 0x03, + CTL_TURBO_G = 0x04, + CTL_FCC = 0x10, + CTL_ETSI = 0x30, + CTL_MKK = 0x40, + CTL_NONE = 0xff +}; + +#define IEEE80211_CHANNELS_2GHZ_MIN 2412 /* 2GHz channel 1 */ +#define IEEE80211_CHANNELS_2GHZ_MAX 2732 /* 2GHz channel 26 */ + +struct ieee80211_regchannel { + u_int16_t rc_channel; + u_int32_t rc_domain; + u_int32_t rc_mode; +}; + +#define IEEE80211_CHANNELS_2GHZ { \ + { 2412, DMN_APLD, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2417, DMN_APLD, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2422, DMN_APLD, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2427, DMN_APLD, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2432, DMN_APLD, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2437, DMN_APLD, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2442, DMN_APLD, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2447, DMN_APLD, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2452, DMN_APLD, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2457, DMN_APLD, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2462, DMN_APLD, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2467, DMN_APLD, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2472, DMN_APLD, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + \ + { 2432, DMN_ETSIB, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2442, DMN_ETSIB, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + \ + { 2412, DMN_ETSIC, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2417, DMN_ETSIC, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2422, DMN_ETSIC, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2427, DMN_ETSIC, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2432, DMN_ETSIC, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2442, DMN_ETSIC, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2447, DMN_ETSIC, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2452, DMN_ETSIC, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2457, DMN_ETSIC, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2462, DMN_ETSIC, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2467, DMN_ETSIC, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2472, DMN_ETSIC, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + \ + { 2412, DMN_FCCA, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2417, DMN_FCCA, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2422, DMN_FCCA, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2427, DMN_FCCA, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2432, DMN_FCCA, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2442, DMN_FCCA, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2447, DMN_FCCA, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2452, DMN_FCCA, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2457, DMN_FCCA, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2462, DMN_FCCA, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + \ + { 2412, DMN_MKKA, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2417, DMN_MKKA, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2422, DMN_MKKA, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2427, DMN_MKKA, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2432, DMN_MKKA, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2437, DMN_MKKA, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2442, DMN_MKKA, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2447, DMN_MKKA, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2452, DMN_MKKA, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2457, DMN_MKKA, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2462, DMN_MKKA, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2467, DMN_MKKA, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2472, DMN_MKKA, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2484, DMN_MKKA, IEEE80211_CHAN_CCK }, \ + \ + { 2412, DMN_WORLD, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2417, DMN_WORLD, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2422, DMN_WORLD, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2427, DMN_WORLD, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2432, DMN_WORLD, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2442, DMN_WORLD, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2447, DMN_WORLD, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2452, DMN_WORLD, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2457, DMN_WORLD, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2462, DMN_WORLD, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2467, DMN_WORLD, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ + { 2472, DMN_WORLD, IEEE80211_CHAN_CCK|IEEE80211_CHAN_OFDM }, \ +} + +#define IEEE80211_CHANNELS_5GHZ_MIN 5005 /* 5GHz channel 1 */ +#define IEEE80211_CHANNELS_5GHZ_MAX 6100 /* 5GHz channel 220 */ + +#define IEEE80211_CHANNELS_5GHZ { \ + { 5745, DMN_APL1, IEEE80211_CHAN_OFDM }, \ + { 5765, DMN_APL1, IEEE80211_CHAN_OFDM }, \ + { 5785, DMN_APL1, IEEE80211_CHAN_OFDM }, \ + { 5805, DMN_APL1, IEEE80211_CHAN_OFDM }, \ + { 5825, DMN_APL1, IEEE80211_CHAN_OFDM }, \ + \ + { 5745, DMN_APL2, IEEE80211_CHAN_OFDM }, \ + { 5765, DMN_APL2, IEEE80211_CHAN_OFDM }, \ + { 5785, DMN_APL2, IEEE80211_CHAN_OFDM }, \ + { 5805, DMN_APL2, IEEE80211_CHAN_OFDM }, \ + \ + { 5280, DMN_APL3, IEEE80211_CHAN_OFDM }, \ + { 5300, DMN_APL3, IEEE80211_CHAN_OFDM }, \ + { 5320, DMN_APL3, IEEE80211_CHAN_OFDM }, \ + { 5745, DMN_APL3, IEEE80211_CHAN_OFDM }, \ + { 5765, DMN_APL3, IEEE80211_CHAN_OFDM }, \ + { 5785, DMN_APL3, IEEE80211_CHAN_OFDM }, \ + { 5805, DMN_APL3, IEEE80211_CHAN_OFDM }, \ + \ + { 5180, DMN_APL4, IEEE80211_CHAN_OFDM }, \ + { 5200, DMN_APL4, IEEE80211_CHAN_OFDM }, \ + { 5220, DMN_APL4, IEEE80211_CHAN_OFDM }, \ + { 5240, DMN_APL4, IEEE80211_CHAN_OFDM }, \ + { 5745, DMN_APL4, IEEE80211_CHAN_OFDM }, \ + { 5765, DMN_APL4, IEEE80211_CHAN_OFDM }, \ + { 5785, DMN_APL4, IEEE80211_CHAN_OFDM }, \ + { 5805, DMN_APL4, IEEE80211_CHAN_OFDM }, \ + { 5825, DMN_APL4, IEEE80211_CHAN_OFDM }, \ + \ + { 5745, DMN_APL5, IEEE80211_CHAN_OFDM }, \ + { 5765, DMN_APL5, IEEE80211_CHAN_OFDM }, \ + { 5785, DMN_APL5, IEEE80211_CHAN_OFDM }, \ + { 5805, DMN_APL5, IEEE80211_CHAN_OFDM }, \ + { 5825, DMN_APL5, IEEE80211_CHAN_OFDM }, \ + \ + { 5180, DMN_ETSI1, IEEE80211_CHAN_OFDM }, \ + { 5200, DMN_ETSI1, IEEE80211_CHAN_OFDM }, \ + { 5220, DMN_ETSI1, IEEE80211_CHAN_OFDM }, \ + { 5240, DMN_ETSI1, IEEE80211_CHAN_OFDM }, \ + { 5260, DMN_ETSI1, IEEE80211_CHAN_OFDM }, \ + { 5280, DMN_ETSI1, IEEE80211_CHAN_OFDM }, \ + { 5300, DMN_ETSI1, IEEE80211_CHAN_OFDM }, \ + { 5320, DMN_ETSI1, IEEE80211_CHAN_OFDM }, \ + { 5500, DMN_ETSI1, IEEE80211_CHAN_OFDM }, \ + { 5520, DMN_ETSI1, IEEE80211_CHAN_OFDM }, \ + { 5540, DMN_ETSI1, IEEE80211_CHAN_OFDM }, \ + { 5560, DMN_ETSI1, IEEE80211_CHAN_OFDM }, \ + { 5580, DMN_ETSI1, IEEE80211_CHAN_OFDM }, \ + { 5600, DMN_ETSI1, IEEE80211_CHAN_OFDM }, \ + { 5620, DMN_ETSI1, IEEE80211_CHAN_OFDM }, \ + { 5640, DMN_ETSI1, IEEE80211_CHAN_OFDM }, \ + { 5660, DMN_ETSI1, IEEE80211_CHAN_OFDM }, \ + { 5680, DMN_ETSI1, IEEE80211_CHAN_OFDM }, \ + { 5700, DMN_ETSI1, IEEE80211_CHAN_OFDM }, \ + \ + { 5180, DMN_ETSI2, IEEE80211_CHAN_OFDM }, \ + { 5200, DMN_ETSI2, IEEE80211_CHAN_OFDM }, \ + { 5220, DMN_ETSI2, IEEE80211_CHAN_OFDM }, \ + { 5240, DMN_ETSI2, IEEE80211_CHAN_OFDM }, \ + \ + { 5180, DMN_ETSI3, IEEE80211_CHAN_OFDM }, \ + { 5200, DMN_ETSI3, IEEE80211_CHAN_OFDM }, \ + { 5220, DMN_ETSI3, IEEE80211_CHAN_OFDM }, \ + { 5240, DMN_ETSI3, IEEE80211_CHAN_OFDM }, \ + { 5260, DMN_ETSI3, IEEE80211_CHAN_OFDM }, \ + { 5280, DMN_ETSI3, IEEE80211_CHAN_OFDM }, \ + { 5300, DMN_ETSI3, IEEE80211_CHAN_OFDM }, \ + { 5320, DMN_ETSI3, IEEE80211_CHAN_OFDM }, \ + \ + { 5180, DMN_ETSI4, IEEE80211_CHAN_OFDM }, \ + { 5200, DMN_ETSI4, IEEE80211_CHAN_OFDM }, \ + { 5220, DMN_ETSI4, IEEE80211_CHAN_OFDM }, \ + { 5240, DMN_ETSI4, IEEE80211_CHAN_OFDM }, \ + { 5260, DMN_ETSI4, IEEE80211_CHAN_OFDM }, \ + { 5280, DMN_ETSI4, IEEE80211_CHAN_OFDM }, \ + { 5300, DMN_ETSI4, IEEE80211_CHAN_OFDM }, \ + { 5320, DMN_ETSI4, IEEE80211_CHAN_OFDM }, \ + \ + { 5180, DMN_ETSI5, IEEE80211_CHAN_OFDM }, \ + { 5200, DMN_ETSI5, IEEE80211_CHAN_OFDM }, \ + { 5220, DMN_ETSI5, IEEE80211_CHAN_OFDM }, \ + { 5240, DMN_ETSI5, IEEE80211_CHAN_OFDM }, \ + \ + { 5180, DMN_ETSI6, IEEE80211_CHAN_OFDM }, \ + { 5200, DMN_ETSI6, IEEE80211_CHAN_OFDM }, \ + { 5220, DMN_ETSI6, IEEE80211_CHAN_OFDM }, \ + { 5240, DMN_ETSI6, IEEE80211_CHAN_OFDM }, \ + { 5260, DMN_ETSI6, IEEE80211_CHAN_OFDM }, \ + { 5280, DMN_ETSI6, IEEE80211_CHAN_OFDM }, \ + { 5500, DMN_ETSI6, IEEE80211_CHAN_OFDM }, \ + { 5520, DMN_ETSI6, IEEE80211_CHAN_OFDM }, \ + { 5540, DMN_ETSI6, IEEE80211_CHAN_OFDM }, \ + { 5560, DMN_ETSI6, IEEE80211_CHAN_OFDM }, \ + { 5580, DMN_ETSI6, IEEE80211_CHAN_OFDM }, \ + { 5600, DMN_ETSI6, IEEE80211_CHAN_OFDM }, \ + { 5620, DMN_ETSI6, IEEE80211_CHAN_OFDM }, \ + { 5640, DMN_ETSI6, IEEE80211_CHAN_OFDM }, \ + { 5660, DMN_ETSI6, IEEE80211_CHAN_OFDM }, \ + { 5680, DMN_ETSI6, IEEE80211_CHAN_OFDM }, \ + { 5700, DMN_ETSI6, IEEE80211_CHAN_OFDM }, \ + \ + { 5180, DMN_FCC1, IEEE80211_CHAN_OFDM }, \ + { 5200, DMN_FCC1, IEEE80211_CHAN_OFDM }, \ + { 5220, DMN_FCC1, IEEE80211_CHAN_OFDM }, \ + { 5240, DMN_FCC1, IEEE80211_CHAN_OFDM }, \ + { 5260, DMN_FCC1, IEEE80211_CHAN_OFDM }, \ + { 5280, DMN_FCC1, IEEE80211_CHAN_OFDM }, \ + { 5300, DMN_FCC1, IEEE80211_CHAN_OFDM }, \ + { 5320, DMN_FCC1, IEEE80211_CHAN_OFDM }, \ + { 5745, DMN_FCC1, IEEE80211_CHAN_OFDM }, \ + { 5765, DMN_FCC1, IEEE80211_CHAN_OFDM }, \ + { 5785, DMN_FCC1, IEEE80211_CHAN_OFDM }, \ + { 5805, DMN_FCC1, IEEE80211_CHAN_OFDM }, \ + { 5825, DMN_FCC1, IEEE80211_CHAN_OFDM }, \ + \ + { 5180, DMN_FCC2, IEEE80211_CHAN_OFDM }, \ + { 5200, DMN_FCC2, IEEE80211_CHAN_OFDM }, \ + { 5220, DMN_FCC2, IEEE80211_CHAN_OFDM }, \ + { 5240, DMN_FCC2, IEEE80211_CHAN_OFDM }, \ + { 5260, DMN_FCC2, IEEE80211_CHAN_OFDM }, \ + { 5280, DMN_FCC2, IEEE80211_CHAN_OFDM }, \ + { 5300, DMN_FCC2, IEEE80211_CHAN_OFDM }, \ + { 5320, DMN_FCC2, IEEE80211_CHAN_OFDM }, \ + { 5745, DMN_FCC2, IEEE80211_CHAN_OFDM }, \ + { 5765, DMN_FCC2, IEEE80211_CHAN_OFDM }, \ + { 5785, DMN_FCC2, IEEE80211_CHAN_OFDM }, \ + { 5805, DMN_FCC2, IEEE80211_CHAN_OFDM }, \ + { 5825, DMN_FCC2, IEEE80211_CHAN_OFDM }, \ + \ + { 5180, DMN_FCC3, IEEE80211_CHAN_OFDM }, \ + { 5200, DMN_FCC3, IEEE80211_CHAN_OFDM }, \ + { 5220, DMN_FCC3, IEEE80211_CHAN_OFDM }, \ + { 5240, DMN_FCC3, IEEE80211_CHAN_OFDM }, \ + { 5260, DMN_FCC3, IEEE80211_CHAN_OFDM }, \ + { 5280, DMN_FCC3, IEEE80211_CHAN_OFDM }, \ + { 5300, DMN_FCC3, IEEE80211_CHAN_OFDM }, \ + { 5320, DMN_FCC3, IEEE80211_CHAN_OFDM }, \ + { 5500, DMN_FCC3, IEEE80211_CHAN_OFDM }, \ + { 5520, DMN_FCC3, IEEE80211_CHAN_OFDM }, \ + { 5540, DMN_FCC3, IEEE80211_CHAN_OFDM }, \ + { 5560, DMN_FCC3, IEEE80211_CHAN_OFDM }, \ + { 5580, DMN_FCC3, IEEE80211_CHAN_OFDM }, \ + { 5600, DMN_FCC3, IEEE80211_CHAN_OFDM }, \ + { 5620, DMN_FCC3, IEEE80211_CHAN_OFDM }, \ + { 5640, DMN_FCC3, IEEE80211_CHAN_OFDM }, \ + { 5660, DMN_FCC3, IEEE80211_CHAN_OFDM }, \ + { 5680, DMN_FCC3, IEEE80211_CHAN_OFDM }, \ + { 5700, DMN_FCC3, IEEE80211_CHAN_OFDM }, \ + { 5745, DMN_FCC3, IEEE80211_CHAN_OFDM }, \ + { 5765, DMN_FCC3, IEEE80211_CHAN_OFDM }, \ + { 5785, DMN_FCC3, IEEE80211_CHAN_OFDM }, \ + { 5805, DMN_FCC3, IEEE80211_CHAN_OFDM }, \ + { 5825, DMN_FCC3, IEEE80211_CHAN_OFDM }, \ + \ + { 5170, DMN_MKK1, IEEE80211_CHAN_OFDM }, \ + { 5190, DMN_MKK1, IEEE80211_CHAN_OFDM }, \ + { 5210, DMN_MKK1, IEEE80211_CHAN_OFDM }, \ + { 5230, DMN_MKK1, IEEE80211_CHAN_OFDM }, \ + \ + { 5040, DMN_MKK2, IEEE80211_CHAN_OFDM }, \ + { 5060, DMN_MKK2, IEEE80211_CHAN_OFDM }, \ + { 5080, DMN_MKK2, IEEE80211_CHAN_OFDM }, \ + { 5170, DMN_MKK2, IEEE80211_CHAN_OFDM }, \ + { 5190, DMN_MKK2, IEEE80211_CHAN_OFDM }, \ + { 5210, DMN_MKK2, IEEE80211_CHAN_OFDM }, \ + { 5230, DMN_MKK2, IEEE80211_CHAN_OFDM }, \ + \ + { 5180, DMN_WORLD, IEEE80211_CHAN_OFDM }, \ + { 5200, DMN_WORLD, IEEE80211_CHAN_OFDM }, \ + { 5220, DMN_WORLD, IEEE80211_CHAN_OFDM }, \ + { 5240, DMN_WORLD, IEEE80211_CHAN_OFDM }, \ +} + +__BEGIN_DECLS + +extern u_int16_t ieee80211_name2countrycode(const char *); +extern u_int32_t ieee80211_name2regdomain(const char *); +extern const char *ieee80211_countrycode2name(u_int16_t); +extern const char *ieee80211_regdomain2name(u_int32_t); +extern u_int32_t ieee80211_regdomain2flag(u_int16_t, u_int16_t); +extern u_int32_t ieee80211_countrycode2regdomain(u_int16_t); + +__END_DECLS + +#endif /* _NET80211_IEEE80211_REGDOMAIN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net80211/ieee80211_rssadapt.h b/lib/libc/include/generic-openbsd/net80211/ieee80211_rssadapt.h new file mode 100644 index 0000000000..41b8a3248d --- /dev/null +++ b/lib/libc/include/generic-openbsd/net80211/ieee80211_rssadapt.h @@ -0,0 +1,103 @@ +/* $OpenBSD: ieee80211_rssadapt.h,v 1.5 2010/07/17 16:25:09 damien Exp $ */ +/* $NetBSD: ieee80211_rssadapt.h,v 1.3 2004/05/06 03:03:20 dyoung Exp $ */ + +/*- + * Copyright (c) 2003, 2004 David Young. 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 David Young ``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 David + * Young 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 _NET80211_IEEE80211_RSSADAPT_H_ +#define _NET80211_IEEE80211_RSSADAPT_H_ + +/* Data-rate adaptation loosely based on "Link Adaptation Strategy + * for IEEE 802.11 WLAN via Received Signal Strength Measurement" + * by Javier del Prado Pavon and Sunghyun Choi. + */ + +/* Buckets for frames 0-128 bytes long, 129-1024, 1025-maximum. */ +#define IEEE80211_RSSADAPT_BKTS 3 +#define IEEE80211_RSSADAPT_BKT0 128 +#define IEEE80211_RSSADAPT_BKTPOWER 3 /* 2**_BKTPOWER */ + +#define ieee80211_rssadapt_thresh_new \ + (ieee80211_rssadapt_thresh_denom - ieee80211_rssadapt_thresh_old) +#define ieee80211_rssadapt_decay_new \ + (ieee80211_rssadapt_decay_denom - ieee80211_rssadapt_decay_old) +#define ieee80211_rssadapt_avgrssi_new \ + (ieee80211_rssadapt_avgrssi_denom - ieee80211_rssadapt_avgrssi_old) + +struct ieee80211_rssadapt_expavgctl { + /* RSS threshold decay. */ + u_int rc_decay_denom; + u_int rc_decay_old; + /* RSS threshold update. */ + u_int rc_thresh_denom; + u_int rc_thresh_old; + /* RSS average update. */ + u_int rc_avgrssi_denom; + u_int rc_avgrssi_old; +}; + +struct ieee80211_rssadapt { + /* exponential average RSSI << 8 */ + u_int16_t ra_avg_rssi; + /* Tx failures in this update interval */ + u_int32_t ra_nfail; + /* Tx successes in this update interval */ + u_int32_t ra_nok; + /* exponential average packets/second */ + u_int32_t ra_pktrate; + /* RSSI threshold for each Tx rate */ + u_int16_t ra_rate_thresh[IEEE80211_RSSADAPT_BKTS] + [IEEE80211_RATE_SIZE]; + struct timeval ra_last_raise; + struct timeval ra_raise_interval; +}; + +/* Properties of a Tx packet, for link adaptation. */ +struct ieee80211_rssdesc { + u_int id_len; /* Tx packet length */ + u_int id_rateidx; /* index into ni->ni_rates */ + struct ieee80211_node *id_node; /* destination STA MAC */ + u_int8_t id_rssi; /* destination STA avg RSS @ + * Tx time + */ +}; + +void ieee80211_rssadapt_updatestats(struct ieee80211_rssadapt *); +void ieee80211_rssadapt_input(struct ieee80211com *, + const struct ieee80211_node *, struct ieee80211_rssadapt *, int); +void ieee80211_rssadapt_lower_rate(struct ieee80211com *, + const struct ieee80211_node *, struct ieee80211_rssadapt *, + const struct ieee80211_rssdesc *); +void ieee80211_rssadapt_raise_rate(struct ieee80211com *, + struct ieee80211_rssadapt *, const struct ieee80211_rssdesc *); +int ieee80211_rssadapt_choose(struct ieee80211_rssadapt *, + const struct ieee80211_rateset *, const struct ieee80211_frame *, + u_int, int, const char *, int); +#ifdef IEEE80211_DEBUG +extern int ieee80211_rssadapt_debug; +#endif /* IEEE80211_DEBUG */ + +#endif /* _NET80211_IEEE80211_RSSADAPT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/net80211/ieee80211_var.h b/lib/libc/include/generic-openbsd/net80211/ieee80211_var.h new file mode 100644 index 0000000000..6b03767eae --- /dev/null +++ b/lib/libc/include/generic-openbsd/net80211/ieee80211_var.h @@ -0,0 +1,511 @@ +/* $OpenBSD: ieee80211_var.h,v 1.112 2025/08/01 20:39:26 stsp Exp $ */ +/* $NetBSD: ieee80211_var.h,v 1.7 2004/05/06 03:07:10 dyoung Exp $ */ + +/*- + * Copyright (c) 2001 Atsushi Onoe + * Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD: src/sys/net80211/ieee80211_var.h,v 1.15 2004/04/05 22:10:26 sam Exp $ + */ +#ifndef _NET80211_IEEE80211_VAR_H_ +#define _NET80211_IEEE80211_VAR_H_ + +/* + * Definitions for IEEE 802.11 drivers. + */ + +#ifdef SMALL_KERNEL +#define IEEE80211_STA_ONLY 1 +#endif + +#include + +#include +#include +#include /* for ieee80211_stats */ +#include +#include + +#define IEEE80211_CHAN_MAX 255 +#define IEEE80211_CHAN_ANY 0xffff /* token for ``any channel'' */ +#define IEEE80211_CHAN_ANYC \ + ((struct ieee80211_channel *) NULL) + +#define IEEE80211_TXPOWER_MAX 100 /* max power */ +#define IEEE80211_TXPOWER_MIN -50 /* kill radio (if possible) */ + +#define IEEE80211_RSSI_THRES_2GHZ (-60) /* in dBm */ +#define IEEE80211_RSSI_THRES_5GHZ (-70) /* in dBm */ +#define IEEE80211_RSSI_THRES_RATIO_2GHZ 60 /* in percent */ +#define IEEE80211_RSSI_THRES_RATIO_5GHZ 50 /* in percent */ + +#define IEEE80211_BGSCAN_FAIL_MAX 512 /* units of 500 msec */ + +/* + * Missed beacon threshold: An access point has disappeared if this amount + * of consecutive beacons have been missed. + * This value needs to be high enough to avoid frequent re-connects to APs + * which suffer from occasional packet loss, and low enough to avoid a long + * delay before we start scanning when an AP has actually disappeared. + * + * The beacon interval is variable, but generally in the order of 100ms. + * So 30 beacons implies a grace period of about 3 seconds before we start + * searching for a new AP. + */ +#define IEEE80211_BEACON_MISS_THRES 30 /* units of beacons */ + +enum ieee80211_phytype { + IEEE80211_T_DS, /* direct sequence spread spectrum */ + IEEE80211_T_OFDM, /* frequency division multiplexing */ + IEEE80211_T_XR /* extended range mode */ +}; +#define IEEE80211_T_CCK IEEE80211_T_DS /* more common nomenclature */ + +/* XXX not really a mode; there are really multiple PHY's */ +enum ieee80211_phymode { + IEEE80211_MODE_AUTO = 0, /* autoselect */ + IEEE80211_MODE_11A = 1, /* 5GHz, OFDM */ + IEEE80211_MODE_11B = 2, /* 2GHz, CCK */ + IEEE80211_MODE_11G = 3, /* 2GHz, OFDM */ + IEEE80211_MODE_11N = 4, /* 2GHz/5GHz, OFDM/HT */ + IEEE80211_MODE_11AC = 5, /* 5GHz, OFDM/VHT */ +}; +#define IEEE80211_MODE_MAX (IEEE80211_MODE_11AC+1) + +enum ieee80211_opmode { + IEEE80211_M_STA = 1, /* infrastructure station */ +#ifndef IEEE80211_STA_ONLY + IEEE80211_M_IBSS = 0, /* IBSS (adhoc) station */ + IEEE80211_M_AHDEMO = 3, /* Old lucent compatible adhoc demo */ + IEEE80211_M_HOSTAP = 6, /* Software Access Point */ +#endif + IEEE80211_M_MONITOR = 8 /* Monitor mode */ +}; + +/* + * 802.11g protection mode. + */ +enum ieee80211_protmode { + IEEE80211_PROT_NONE = 0, /* no protection */ + IEEE80211_PROT_CTSONLY = 1, /* CTS to self */ + IEEE80211_PROT_RTSCTS = 2 /* RTS-CTS */ +}; + +/* + * Channels are specified by frequency and attributes. + */ +struct ieee80211_channel { + u_int16_t ic_freq; /* setting in MHz */ + u_int16_t ic_flags; /* see below */ + u_int32_t ic_xflags; /* extra flags; see below */ +}; + +/* + * Channel attributes (XXX must keep in sync with radiotap flags). + */ +#define IEEE80211_CHAN_CCK 0x0020 /* CCK channel */ +#define IEEE80211_CHAN_OFDM 0x0040 /* OFDM channel */ +#define IEEE80211_CHAN_2GHZ 0x0080 /* 2 GHz spectrum channel */ +#define IEEE80211_CHAN_5GHZ 0x0100 /* 5 GHz spectrum channel */ +#define IEEE80211_CHAN_PASSIVE 0x0200 /* Only passive scan allowed */ +#define IEEE80211_CHAN_DYN 0x0400 /* Dynamic CCK-OFDM channel */ +#define IEEE80211_CHAN_XR 0x1000 /* Extended range OFDM channel */ +#define IEEE80211_CHAN_HT 0x2000 /* 11n/HT channel */ +#define IEEE80211_CHAN_VHT 0x4000 /* 11ac/VHT channel */ +#define IEEE80211_CHAN_40MHZ 0x8000 /* use of 40 MHz is allowed */ + +/* + * Extra channel flags. + */ +#define IEEE80211_CHANX_80MHZ 0x00000001 /* use of 80 MHz is allowed */ +#define IEEE80211_CHANX_160MHZ 0x00000002 /* use of 160 MHz is allowed */ + +/* + * Useful combinations of channel characteristics. + */ +#define IEEE80211_CHAN_A \ + (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM) +#define IEEE80211_CHAN_B \ + (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK) +#define IEEE80211_CHAN_PUREG \ + (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_OFDM) +#define IEEE80211_CHAN_G \ + (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN) + +#define IEEE80211_IS_CHAN_A(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A) +#define IEEE80211_IS_CHAN_B(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B) +#define IEEE80211_IS_CHAN_PUREG(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_PUREG) == IEEE80211_CHAN_PUREG) +#define IEEE80211_IS_CHAN_G(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G) +#define IEEE80211_IS_CHAN_N(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_HT) == IEEE80211_CHAN_HT) +#define IEEE80211_IS_CHAN_AC(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_VHT) == IEEE80211_CHAN_VHT) + +#define IEEE80211_IS_CHAN_2GHZ(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_2GHZ) != 0) +#define IEEE80211_IS_CHAN_5GHZ(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_5GHZ) != 0) +#define IEEE80211_IS_CHAN_OFDM(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_OFDM) != 0) +#define IEEE80211_IS_CHAN_CCK(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_CCK) != 0) +#define IEEE80211_IS_CHAN_XR(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_XR) != 0) + +#define IEEE80211_CHAN_40MHZ_ALLOWED(_c) \ + (((_c)->ic_flags & IEEE80211_CHAN_40MHZ) != 0) +#define IEEE80211_CHAN_80MHZ_ALLOWED(_c) \ + (((_c)->ic_xflags & IEEE80211_CHANX_80MHZ) != 0) +#define IEEE80211_CHAN_160MHZ_ALLOWED(_c) \ + (((_c)->ic_xflags & IEEE80211_CHANX_160MHZ) != 0) + +/* + * EDCA AC parameters. + */ +struct ieee80211_edca_ac_params { + u_int8_t ac_ecwmin; /* CWmin = 2^ECWmin - 1 */ + u_int8_t ac_ecwmax; /* CWmax = 2^ECWmax - 1 */ + u_int8_t ac_aifsn; + u_int16_t ac_txoplimit; /* 32TU */ +#define IEEE80211_TXOP_TO_US(txop) ((txop) * 32) + + u_int8_t ac_acm; +}; + +extern const struct ieee80211_edca_ac_params + ieee80211_edca_table[IEEE80211_MODE_MAX][EDCA_NUM_AC]; +extern const struct ieee80211_edca_ac_params + ieee80211_qap_edca_table[IEEE80211_MODE_MAX][EDCA_NUM_AC]; + +#define IEEE80211_DEFRAG_SIZE 3 /* must be >= 3 according to spec */ +/* + * Entry in the fragment cache. + */ +struct ieee80211_defrag { + struct timeout df_to; + struct mbuf *df_m; + u_int16_t df_seq; + u_int8_t df_frag; +}; + +#define IEEE80211_PROTO_NONE 0 +#define IEEE80211_PROTO_RSN (1 << 0) +#define IEEE80211_PROTO_WPA (1 << 1) + +#define IEEE80211_SCAN_UNLOCKED 0x0 +#define IEEE80211_SCAN_LOCKED 0x1 +#define IEEE80211_SCAN_REQUEST 0x2 +#define IEEE80211_SCAN_RESUME 0x4 + +#define IEEE80211_GROUP_NKID 6 + +struct ieee80211_node_switch_bss_arg; + +struct ieee80211com { + struct arpcom ic_ac; + LIST_ENTRY(ieee80211com) ic_list; /* chain of all ieee80211com */ + void (*ic_recv_mgmt)(struct ieee80211com *, + struct mbuf *, struct ieee80211_node *, + struct ieee80211_rxinfo *, int); + int (*ic_send_mgmt)(struct ieee80211com *, + struct ieee80211_node *, int, int, int); + int (*ic_newstate)(struct ieee80211com *, + enum ieee80211_state, int); + int (*ic_newauth)(struct ieee80211com *, + struct ieee80211_node *, int, uint16_t); + void (*ic_newassoc)(struct ieee80211com *, + struct ieee80211_node *, int); + void (*ic_node_leave)(struct ieee80211com *, + struct ieee80211_node *); + void (*ic_updateslot)(struct ieee80211com *); + void (*ic_updateedca)(struct ieee80211com *); + void (*ic_set_tim)(struct ieee80211com *, int, int); + int (*ic_set_key)(struct ieee80211com *, + struct ieee80211_node *, + struct ieee80211_key *); + void (*ic_delete_key)(struct ieee80211com *, + struct ieee80211_node *, + struct ieee80211_key *); + int (*ic_ampdu_tx_start)(struct ieee80211com *, + struct ieee80211_node *, u_int8_t); + void (*ic_ampdu_tx_stop)(struct ieee80211com *, + struct ieee80211_node *, u_int8_t); + int (*ic_ampdu_rx_start)(struct ieee80211com *, + struct ieee80211_node *, u_int8_t); + void (*ic_ampdu_rx_stop)(struct ieee80211com *, + struct ieee80211_node *, u_int8_t); + void (*ic_updateprot)(struct ieee80211com *); + void (*ic_updatechan)(struct ieee80211com *); + void (*ic_updatedtim)(struct ieee80211com *); + int (*ic_bgscan_start)(struct ieee80211com *); + void (*ic_bgscan_done)(struct ieee80211com *, + struct ieee80211_node_switch_bss_arg *, + size_t); + struct timeout ic_bgscan_timeout; + uint32_t ic_bgscan_fail; + u_int8_t ic_myaddr[IEEE80211_ADDR_LEN]; + struct ieee80211_rateset ic_sup_rates[IEEE80211_MODE_MAX]; + struct ieee80211_channel ic_channels[IEEE80211_CHAN_MAX+1]; + u_char ic_chan_avail[howmany(IEEE80211_CHAN_MAX,NBBY)]; + u_char ic_chan_active[howmany(IEEE80211_CHAN_MAX, NBBY)]; + u_char ic_chan_scan[howmany(IEEE80211_CHAN_MAX,NBBY)]; + struct mbuf_queue ic_mgtq; + struct mbuf_queue ic_pwrsaveq; + u_int8_t ic_scan_count; /* count scans */ + u_int32_t ic_flags; /* state flags */ + u_int32_t ic_xflags; /* more flags */ + u_int32_t ic_userflags; /* yet more flags */ + u_int32_t ic_caps; /* capabilities */ + u_int16_t ic_modecaps; /* set of mode capabilities */ + u_int16_t ic_curmode; /* current mode */ + enum ieee80211_phytype ic_phytype; /* XXX wrong for multi-mode */ + enum ieee80211_opmode ic_opmode; /* operation mode */ + enum ieee80211_state ic_state; /* 802.11 state */ + u_int32_t *ic_aid_bitmap; + u_int16_t ic_max_aid; + enum ieee80211_protmode ic_protmode; /* 802.11g/n protection mode */ + struct ifmedia ic_media; /* interface media config */ + caddr_t ic_rawbpf; /* packet filter structure */ + struct ieee80211_node *ic_bss; /* information for this node */ + struct ieee80211_channel *ic_ibss_chan; + int ic_fixed_rate; /* index to ic_sup_rates[] */ + u_int16_t ic_rtsthreshold; + u_int16_t ic_fragthreshold; + u_int ic_scangen; /* gen# for timeout scan */ + struct ieee80211_node *(*ic_node_alloc)(struct ieee80211com *); + void (*ic_node_free)(struct ieee80211com *, + struct ieee80211_node *); + void (*ic_node_copy)(struct ieee80211com *, + struct ieee80211_node *, + const struct ieee80211_node *); + u_int8_t (*ic_node_getrssi)(struct ieee80211com *, + const struct ieee80211_node *); + int (*ic_node_checkrssi)(struct ieee80211com *, + const struct ieee80211_node *); + u_int8_t ic_max_rssi; + struct ieee80211_tree ic_tree; + int ic_nnodes; /* length of ic_nnodes */ + int ic_max_nnodes; /* max length of ic_nnodes */ + u_int16_t ic_lintval; /* listen interval */ + int16_t ic_txpower; /* tx power setting (dBm) */ + int ic_bmissthres; /* beacon miss threshold */ + int ic_mgt_timer; /* mgmt timeout */ +#ifndef IEEE80211_STA_ONLY + struct timeout ic_inact_timeout; /* node inactivity timeout */ + struct timeout ic_node_cache_timeout; +#endif + struct task ic_rtm_80211info_task; + int ic_des_esslen; + u_int8_t ic_des_essid[IEEE80211_NWID_LEN]; + struct ieee80211_channel *ic_des_chan; /* desired channel */ + u_int8_t ic_des_bssid[IEEE80211_ADDR_LEN]; + struct ieee80211_key ic_nw_keys[IEEE80211_GROUP_NKID]; + int ic_def_txkey; /* group data key index */ +#define ic_wep_txkey ic_def_txkey + int ic_igtk_kid; /* IGTK key index */ + u_int32_t ic_iv; /* initial vector for wep */ + struct ieee80211_stats ic_stats; /* statistics */ + struct timeval ic_last_merge_print; /* for rate-limiting + * IBSS merge print-outs + */ + struct ieee80211_edca_ac_params ic_edca_ac[EDCA_NUM_AC]; + u_int ic_edca_updtcount; + u_int16_t ic_tid_noack; + u_int8_t ic_globalcnt[EAPOL_KEY_NONCE_LEN]; + u_int8_t ic_nonce[EAPOL_KEY_NONCE_LEN]; + u_int8_t ic_psk[IEEE80211_PMK_LEN]; + struct timeout ic_rsn_timeout; + time_t ic_tkip_micfail; + u_int64_t ic_tkip_micfail_last_tsc; +#ifndef IEEE80211_STA_ONLY + struct timeout ic_tkip_micfail_timeout; +#endif + + TAILQ_HEAD(, ieee80211_pmk) ic_pmksa; /* PMKSA cache */ + u_int ic_rsnprotos; + u_int ic_rsnakms; + u_int ic_rsnciphers; + enum ieee80211_cipher ic_rsngroupcipher; + enum ieee80211_cipher ic_rsngroupmgmtcipher; + +#ifdef notyet + struct ieee80211_defrag ic_defrag[IEEE80211_DEFRAG_SIZE]; + int ic_defrag_cur; +#endif + + u_int8_t *ic_tim_bitmap; + u_int ic_tim_len; + u_int ic_tim_mcast_pending; + u_int ic_dtim_period; + u_int ic_dtim_count; + + u_int32_t ic_txbfcaps; + u_int16_t ic_htcaps; + u_int8_t ic_ampdu_params; + u_int8_t ic_sup_mcs[howmany(80, NBBY)]; + u_int16_t ic_max_rxrate; /* in Mb/s, 0 <= rate <= 1023 */ + u_int8_t ic_tx_mcs_set; + u_int16_t ic_htxcaps; + u_int8_t ic_aselcaps; + u_int8_t ic_dialog_token; + int ic_fixed_mcs; + + uint32_t ic_vhtcaps; + uint16_t ic_vht_rxmcs; + uint16_t ic_vht_rx_max_lgi_mbit_s; + uint16_t ic_vht_txmcs; + uint16_t ic_vht_tx_max_lgi_mbit_s; + + TAILQ_HEAD(, ieee80211_ess) ic_ess; +}; +#define ic_if ic_ac.ac_if +#define ic_softc ic_if.if_softc + +/* list of APs we want to automatically use */ +/* all data is copied from struct ieee80211com */ +struct ieee80211_ess { + /* nwid */ + int esslen; + u_int8_t essid[IEEE80211_NWID_LEN]; + + /* clear/wep/wpa */ + u_int32_t flags; + + /* nwkey */ + struct ieee80211_key nw_keys[IEEE80211_GROUP_NKID]; + int def_txkey; + + /* wpakey */ + u_int8_t psk[IEEE80211_PMK_LEN]; + u_int rsnprotos; + u_int rsnakms; + u_int rsnciphers; + enum ieee80211_cipher rsngroupcipher; + + TAILQ_ENTRY(ieee80211_ess) ess_next; +}; + +#define IEEE80211_ADDR_EQ(a1,a2) (memcmp(a1,a2,IEEE80211_ADDR_LEN) == 0) +#define IEEE80211_ADDR_COPY(dst,src) memcpy(dst,src,IEEE80211_ADDR_LEN) + +/* ic_flags */ +#define IEEE80211_F_ASCAN 0x00000001 /* STATUS: active scan */ +#define IEEE80211_F_SIBSS 0x00000002 /* STATUS: start IBSS */ +#define IEEE80211_F_WEPON 0x00000100 /* CONF: WEP enabled */ +#define IEEE80211_F_IBSSON 0x00000200 /* CONF: IBSS creation enable */ +#define IEEE80211_F_PMGTON 0x00000400 /* CONF: Power mgmt enable */ +#define IEEE80211_F_DESBSSID 0x00000800 /* CONF: des_bssid is set */ +#define IEEE80211_F_ROAMING 0x00002000 /* CONF: roaming enabled */ +#define IEEE80211_F_TXPMGT 0x00018000 /* STATUS: tx power */ +#define IEEE80211_F_TXPOW_OFF 0x00000000 /* TX Power: radio disabled */ +#define IEEE80211_F_TXPOW_FIXED 0x00008000 /* TX Power: fixed rate */ +#define IEEE80211_F_TXPOW_AUTO 0x00010000 /* TX Power: undefined */ +#define IEEE80211_F_SHSLOT 0x00020000 /* STATUS: short slot time */ +#define IEEE80211_F_SHPREAMBLE 0x00040000 /* STATUS: short preamble */ +#define IEEE80211_F_QOS 0x00080000 /* CONF: QoS enabled */ +#define IEEE80211_F_USEPROT 0x00100000 /* STATUS: protection enabled */ +#define IEEE80211_F_RSNON 0x00200000 /* CONF: RSN enabled */ +#define IEEE80211_F_PSK 0x00400000 /* CONF: pre-shared key set */ +#define IEEE80211_F_COUNTERM 0x00800000 /* STATUS: countermeasures */ +#define IEEE80211_F_MFPR 0x01000000 /* CONF: MFP required */ +#define IEEE80211_F_HTON 0x02000000 /* CONF: HT enabled */ +#define IEEE80211_F_PBAR 0x04000000 /* CONF: PBAC required */ +#define IEEE80211_F_BGSCAN 0x08000000 /* STATUS: background scan */ +#define IEEE80211_F_AUTO_JOIN 0x10000000 /* CONF: auto-join active */ +#define IEEE80211_F_VHTON 0x20000000 /* CONF: VHT enabled */ + +/* ic_xflags */ +#define IEEE80211_F_TX_MGMT_ONLY 0x00000001 /* leave data frames on ifq */ + +/* ic_caps */ +#define IEEE80211_C_WEP 0x00000001 /* CAPABILITY: WEP available */ +#define IEEE80211_C_IBSS 0x00000002 /* CAPABILITY: IBSS available */ +#define IEEE80211_C_PMGT 0x00000004 /* CAPABILITY: Power mgmt */ +#define IEEE80211_C_HOSTAP 0x00000008 /* CAPABILITY: HOSTAP avail */ +#define IEEE80211_C_AHDEMO 0x00000010 /* CAPABILITY: Old Adhoc Demo */ +#define IEEE80211_C_APPMGT 0x00000020 /* CAPABILITY: AP power mgmt */ +#define IEEE80211_C_TXPMGT 0x00000040 /* CAPABILITY: tx power mgmt */ +#define IEEE80211_C_SHSLOT 0x00000080 /* CAPABILITY: short slottime */ +#define IEEE80211_C_SHPREAMBLE 0x00000100 /* CAPABILITY: short preamble */ +#define IEEE80211_C_MONITOR 0x00000200 /* CAPABILITY: monitor mode */ +#define IEEE80211_C_SCANALL 0x00000400 /* CAPABILITY: scan all chan */ +#define IEEE80211_C_QOS 0x00000800 /* CAPABILITY: QoS avail */ +#define IEEE80211_C_RSN 0x00001000 /* CAPABILITY: RSN avail */ +#define IEEE80211_C_MFP 0x00002000 /* CAPABILITY: MFP avail */ +#define IEEE80211_C_RAWCTL 0x00004000 /* CAPABILITY: raw ctl */ +#define IEEE80211_C_SCANALLBAND 0x00008000 /* CAPABILITY: scan all bands */ +#define IEEE80211_C_TX_AMPDU 0x00010000 /* CAPABILITY: send A-MPDU */ +#define IEEE80211_C_ADDBA_OFFLOAD 0x00020000 /* CAPABILITY: ADDBA offload */ + +/* flags for ieee80211_fix_rate() */ +#define IEEE80211_F_DOSORT 0x00000001 /* sort rate list */ +#define IEEE80211_F_DOFRATE 0x00000002 /* use fixed rate */ +#define IEEE80211_F_DONEGO 0x00000004 /* calc negotiated rate */ +#define IEEE80211_F_DODEL 0x00000008 /* delete ignore rate */ + +void ieee80211_ifattach(struct ifnet *); +void ieee80211_ifdetach(struct ifnet *); +void ieee80211_channel_init(struct ifnet *); +void ieee80211_media_init(struct ifnet *, ifm_change_cb_t, ifm_stat_cb_t); +int ieee80211_media_change(struct ifnet *); +void ieee80211_media_status(struct ifnet *, struct ifmediareq *); +int ieee80211_ioctl(struct ifnet *, u_long, caddr_t); +int ieee80211_get_rate(struct ieee80211com *); +void ieee80211_watchdog(struct ifnet *); +int ieee80211_fix_rate(struct ieee80211com *, struct ieee80211_node *, int); +uint64_t ieee80211_rate2media(struct ieee80211com *, int, + enum ieee80211_phymode); +int ieee80211_media2rate(uint64_t); +uint64_t ieee80211_mcs2media(struct ieee80211com *, int, + enum ieee80211_phymode); +int ieee80211_media2mcs(uint64_t); +u_int8_t ieee80211_rate2plcp(u_int8_t, enum ieee80211_phymode); +u_int8_t ieee80211_plcp2rate(u_int8_t, enum ieee80211_phymode); +u_int ieee80211_mhz2ieee(u_int, u_int); +u_int ieee80211_chan2ieee(struct ieee80211com *, + const struct ieee80211_channel *); +u_int ieee80211_ieee2mhz(u_int, u_int); +int ieee80211_min_basic_rate(struct ieee80211com *); +int ieee80211_max_basic_rate(struct ieee80211com *); +int ieee80211_setmode(struct ieee80211com *, enum ieee80211_phymode); +enum ieee80211_phymode ieee80211_next_mode(struct ifnet *); +void ieee80211_disable_wep(struct ieee80211com *); +void ieee80211_disable_rsn(struct ieee80211com *); +int ieee80211_add_ess(struct ieee80211com *, struct ieee80211_join *); +void ieee80211_del_ess(struct ieee80211com *, char *, int, int); +void ieee80211_set_ess(struct ieee80211com *, struct ieee80211_ess *, + struct ieee80211_node *); +void ieee80211_deselect_ess(struct ieee80211com *); +struct ieee80211_ess *ieee80211_get_ess(struct ieee80211com *, const char *, int); +void ieee80211_begin_bgscan(struct ifnet *); + +extern int ieee80211_cache_size; + +#endif /* _NET80211_IEEE80211_VAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netdb.h b/lib/libc/include/generic-openbsd/netdb.h new file mode 100644 index 0000000000..c2dd1b9aa0 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netdb.h @@ -0,0 +1,329 @@ +/* $OpenBSD: netdb.h,v 1.33 2015/01/18 20:29:31 deraadt Exp $ */ + +/* + * ++Copyright++ 1980, 1983, 1988, 1993 + * - + * Copyright (c) 1980, 1983, 1988, 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. + * - + * Portions Copyright (c) 1993 by Digital Equipment Corporation. + * + * 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, and that + * the name of Digital Equipment Corporation not be used in advertising or + * publicity pertaining to distribution of the document or software without + * specific, written prior permission. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT + * CORPORATION 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. + * - + * --Copyright-- + */ + +/* + * Copyright (c) 1995, 1996, 1997, 1998, 1999 Craig Metz. 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 author nor the names of any 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. + */ + +/* + * @(#)netdb.h 8.1 (Berkeley) 6/2/93 + * $From: netdb.h,v 8.7 1996/05/09 05:59:09 vixie Exp $ + */ + +#ifndef _NETDB_H_ +#define _NETDB_H_ + +#include + +#ifndef _SOCKLEN_T_DEFINED_ +#define _SOCKLEN_T_DEFINED_ +typedef __socklen_t socklen_t; /* length type for network syscalls */ +#endif + +#define _PATH_HEQUIV "/etc/hosts.equiv" +#define _PATH_HOSTS "/etc/hosts" +#define _PATH_NETWORKS "/etc/networks" +#define _PATH_PROTOCOLS "/etc/protocols" +#define _PATH_SERVICES "/etc/services" + +/* + * Structures returned by network data base library. All addresses are + * supplied in host order, and returned in network order (suitable for + * use in system calls). + */ +struct hostent { + char *h_name; /* official name of host */ + char **h_aliases; /* alias list */ + int h_addrtype; /* host address type */ + int h_length; /* length of address */ + char **h_addr_list; /* list of addresses from name server */ +#define h_addr h_addr_list[0] /* address, for backward compatibility */ +}; + +/* + * Assumption here is that a network number + * fits in an in_addr_t -- probably a poor one. + */ +struct netent { + char *n_name; /* official name of net */ + char **n_aliases; /* alias list */ + int n_addrtype; /* net address type */ + in_addr_t n_net; /* network # */ +}; + +struct servent { + char *s_name; /* official service name */ + char **s_aliases; /* alias list */ + int s_port; /* port # */ + char *s_proto; /* protocol to use */ +}; + +struct protoent { + char *p_name; /* official protocol name */ + char **p_aliases; /* alias list */ + int p_proto; /* protocol # */ +}; + +#if __BSD_VISIBLE || __POSIX_VISIBLE < 200809 +extern int h_errno; + +/* + * Error return codes from gethostbyname() and gethostbyaddr() + * (left in extern int h_errno). + */ + +#define NETDB_INTERNAL -1 /* see errno */ +#define NETDB_SUCCESS 0 /* no problem */ +#define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */ +#define TRY_AGAIN 2 /* Non-Authoritative Host not found, or SERVERFAIL */ +#define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ +#define NO_DATA 4 /* Valid name, no data record of requested type */ +#define NO_ADDRESS NO_DATA /* no address */ +#endif /* __BSD_VISIBLE || __POSIX_VISIBLE < 200809 */ + +/* Values for getaddrinfo() and getnameinfo() */ +#define AI_PASSIVE 1 /* socket address is intended for bind() */ +#define AI_CANONNAME 2 /* request for canonical name */ +#define AI_NUMERICHOST 4 /* don't ever try hostname lookup */ +#define AI_EXT 8 /* enable non-portable extensions */ +#define AI_NUMERICSERV 16 /* don't ever try servname lookup */ +#define AI_FQDN 32 /* return the FQDN that was resolved */ +#define AI_ADDRCONFIG 64 /* return configured address families only */ +/* valid flags for addrinfo */ +#define AI_MASK \ + (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | AI_FQDN | \ + AI_ADDRCONFIG) + +#define NI_NUMERICHOST 1 /* return the host address, not the name */ +#define NI_NUMERICSERV 2 /* return the service address, not the name */ +#define NI_NOFQDN 4 /* return a short name if in the local domain */ +#define NI_NAMEREQD 8 /* fail if either host or service name is unknown */ +#define NI_DGRAM 16 /* look up datagram service instead of stream */ +/* #define NI_NUMERICSCOPE 32 return the scope number, not the name */ + +#if __BSD_VISIBLE +#define NI_MAXHOST 256 /* max host name from getnameinfo (MAXHOSTNAMELEN) */ +#define NI_MAXSERV 32 /* max serv. name length returned by getnameinfo */ + +/* + * Scope delimit character (KAME hack) + */ +#define SCOPE_DELIMITER '%' +#endif + +#define EAI_BADFLAGS -1 /* invalid value for ai_flags */ +#define EAI_NONAME -2 /* name or service is not known */ +#define EAI_AGAIN -3 /* temporary failure in name resolution */ +#define EAI_FAIL -4 /* non-recoverable failure in name resolution */ +#define EAI_NODATA -5 /* no address associated with name */ +#define EAI_FAMILY -6 /* ai_family not supported */ +#define EAI_SOCKTYPE -7 /* ai_socktype not supported */ +#define EAI_SERVICE -8 /* service not supported for ai_socktype */ +#define EAI_ADDRFAMILY -9 /* address family for name not supported */ +#define EAI_MEMORY -10 /* memory allocation failure */ +#define EAI_SYSTEM -11 /* system error (code indicated in errno) */ +#define EAI_BADHINTS -12 /* invalid value for hints */ +#define EAI_PROTOCOL -13 /* resolved protocol is unknown */ +#define EAI_OVERFLOW -14 /* argument buffer overflow */ + +struct addrinfo { + int ai_flags; /* input flags */ + int ai_family; /* protocol family for socket */ + int ai_socktype; /* socket type */ + int ai_protocol; /* protocol for socket */ + socklen_t ai_addrlen; /* length of socket-address */ + struct sockaddr *ai_addr; /* socket-address for socket */ + char *ai_canonname; /* canonical name for service location (iff req) */ + struct addrinfo *ai_next; /* pointer to next in list */ +}; + +#if __BSD_VISIBLE +/* + * Flags for getrrsetbyname() + */ +#define RRSET_VALIDATED 1 + +/* + * Return codes for getrrsetbyname() + */ +#define ERRSET_SUCCESS 0 +#define ERRSET_NOMEMORY 1 +#define ERRSET_FAIL 2 +#define ERRSET_INVAL 3 +#define ERRSET_NONAME 4 +#define ERRSET_NODATA 5 + +/* + * Structures used by getrrsetbyname() and freerrset() + */ +struct rdatainfo { + unsigned int rdi_length; /* length of data */ + unsigned char *rdi_data; /* record data */ +}; + +struct rrsetinfo { + unsigned int rri_flags; /* RRSET_VALIDATED ... */ + unsigned int rri_rdclass; /* class number */ + unsigned int rri_rdtype; /* RR type number */ + unsigned int rri_ttl; /* time to live */ + unsigned int rri_nrdatas; /* size of rdatas array */ + unsigned int rri_nsigs; /* size of sigs array */ + char *rri_name; /* canonical name */ + struct rdatainfo *rri_rdatas; /* individual records */ + struct rdatainfo *rri_sigs; /* individual signatures */ +}; + +struct servent_data { + void *fp; + char **aliases; + int maxaliases; + int stayopen; + char *line; +}; + +struct protoent_data { + void *fp; + char **aliases; + int maxaliases; + int stayopen; + char *line; +}; +#endif + +__BEGIN_DECLS +void endhostent(void); +void endnetent(void); +void endprotoent(void); +void endservent(void); +#if __BSD_VISIBLE || __POSIX_VISIBLE < 200809 +struct hostent *gethostbyaddr(const void *, socklen_t, int); +struct hostent *gethostbyname(const char *); +#endif +#if __BSD_VISIBLE +struct hostent *gethostbyname2(const char *, int); +#endif +struct hostent *gethostent(void); +struct netent *getnetbyaddr(in_addr_t, int); +struct netent *getnetbyname(const char *); +struct netent *getnetent(void); +struct protoent *getprotobyname(const char *); +struct protoent *getprotobynumber(int); +struct protoent *getprotoent(void); +struct servent *getservbyname(const char *, const char *); +struct servent *getservbyport(int, const char *); +struct servent *getservent(void); +#if __BSD_VISIBLE +void herror(const char *); +const char *hstrerror(int); +#endif +void sethostent(int); +/* void sethostfile(const char *); */ +void setnetent(int); +void setprotoent(int); +void setservent(int); + +#if __BSD_VISIBLE +void endprotoent_r(struct protoent_data *); +void endservent_r(struct servent_data *); +int getprotobyname_r(const char *, struct protoent *, + struct protoent_data *); +int getprotobynumber_r(int, struct protoent *, + struct protoent_data *); +int getservbyname_r(const char *, const char *, struct servent *, + struct servent_data *); +int getservbyport_r(int, const char *, struct servent *, + struct servent_data *); +int getservent_r(struct servent *, struct servent_data *); +int getprotoent_r(struct protoent *, struct protoent_data *); +void setprotoent_r(int, struct protoent_data *); +void setservent_r(int, struct servent_data *); +#endif + +int getaddrinfo(const char *, const char *, + const struct addrinfo *, struct addrinfo **); +void freeaddrinfo(struct addrinfo *); +int getnameinfo(const struct sockaddr *, socklen_t, + char *, size_t, char *, size_t, int); +const char *gai_strerror(int); + +#if __BSD_VISIBLE +int getrrsetbyname(const char *, unsigned int, unsigned int, unsigned int, struct rrsetinfo **); +void freerrset(struct rrsetinfo *); +#endif +__END_DECLS + +#endif /* !_NETDB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netgroup.h b/lib/libc/include/generic-openbsd/netgroup.h new file mode 100644 index 0000000000..ec48b2d208 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netgroup.h @@ -0,0 +1,62 @@ +/* $OpenBSD: netgroup.h,v 1.9 2023/01/04 13:00:11 jsg Exp $ */ +/* + * Copyright (c) 1994 Christos Zoulas + * 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 _NETGROUP_H_ +#define _NETGROUP_H_ + +#define _PATH_NETGROUP "/etc/netgroup" + +#define _PATH_NETGROUP_DB "/etc/netgroup.db" + +#define _PATH_NETGROUP_MKDB "/usr/sbin/netgroup_mkdb" + +#define _NG_KEYBYNAME '1' /* stored by name */ +#define _NG_KEYBYUSER '2' /* stored by user */ +#define _NG_KEYBYHOST '3' /* stored by host */ + +#define _NG_ERROR -1 +#define _NG_NONE 0 +#define _NG_NAME 1 +#define _NG_GROUP 2 + +struct netgroup { + char *ng_host; /* host name */ + char *ng_user; /* user name */ + char *ng_domain; /* domain name */ + struct netgroup *ng_next; /* thread */ +}; + +#include + +__BEGIN_DECLS +void setnetgrent(const char *); +int getnetgrent(const char **, const char **, const char **); +void endnetgrent(void); +int innetgr(const char *, const char *, const char *, const char *); +__END_DECLS + +#endif /* !_NETGROUP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/icmp6.h b/lib/libc/include/generic-openbsd/netinet/icmp6.h new file mode 100644 index 0000000000..db378d8086 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/icmp6.h @@ -0,0 +1,608 @@ +/* $OpenBSD: icmp6.h,v 1.57 2025/09/16 09:19:43 florian Exp $ */ +/* $KAME: icmp6.h,v 1.84 2003/04/23 10:26:51 itojun Exp $ */ + +/* + * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. + * 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 project 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 PROJECT 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 PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Copyright (c) 1982, 1986, 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. + * + * @(#)ip_icmp.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NETINET_ICMP6_H_ +#define _NETINET_ICMP6_H_ + +#define ICMPV6_PLD_MAXLEN 1232 /* IPV6_MMTU - sizeof(struct ip6_hdr) + - sizeof(struct icmp6_hdr) */ + +struct icmp6_hdr { + u_int8_t icmp6_type; /* type field */ + u_int8_t icmp6_code; /* code field */ + u_int16_t icmp6_cksum; /* checksum field */ + union { + u_int32_t icmp6_un_data32[1]; /* type-specific field */ + u_int16_t icmp6_un_data16[2]; /* type-specific field */ + u_int8_t icmp6_un_data8[4]; /* type-specific field */ + } icmp6_dataun; +} __packed; + +#define icmp6_data32 icmp6_dataun.icmp6_un_data32 +#define icmp6_data16 icmp6_dataun.icmp6_un_data16 +#define icmp6_data8 icmp6_dataun.icmp6_un_data8 +#define icmp6_pptr icmp6_data32[0] /* parameter prob */ +#define icmp6_mtu icmp6_data32[0] /* packet too big */ +#define icmp6_id icmp6_data16[0] /* echo request/reply */ +#define icmp6_seq icmp6_data16[1] /* echo request/reply */ +#define icmp6_maxdelay icmp6_data16[0] /* mcast group membership */ + +#define ICMP6_DST_UNREACH 1 /* dest unreachable, codes: */ +#define ICMP6_PACKET_TOO_BIG 2 /* packet too big */ +#define ICMP6_TIME_EXCEEDED 3 /* time exceeded, code: */ +#define ICMP6_PARAM_PROB 4 /* ip6 header bad */ + +#define ICMP6_ECHO_REQUEST 128 /* echo service */ +#define ICMP6_ECHO_REPLY 129 /* echo reply */ +#define MLD_LISTENER_QUERY 130 /* multicast listener query */ +#define MLD_LISTENER_REPORT 131 /* multicast listener report */ +#define MLD_LISTENER_DONE 132 /* multicast listener done */ + +/* RFC2292 decls */ +#define ICMP6_MEMBERSHIP_QUERY 130 /* group membership query */ +#define ICMP6_MEMBERSHIP_REPORT 131 /* group membership report */ +#define ICMP6_MEMBERSHIP_REDUCTION 132 /* group membership termination */ + +#define ND_ROUTER_SOLICIT 133 /* router solicitation */ +#define ND_ROUTER_ADVERT 134 /* router advertisement */ +#define ND_NEIGHBOR_SOLICIT 135 /* neighbor solicitation */ +#define ND_NEIGHBOR_ADVERT 136 /* neighbor advertisement */ +#define ND_REDIRECT 137 /* redirect */ + +#define ICMP6_ROUTER_RENUMBERING 138 /* router renumbering */ + +#define ICMP6_WRUREQUEST 139 /* who are you request */ +#define ICMP6_WRUREPLY 140 /* who are you reply */ +#define ICMP6_FQDN_QUERY 139 /* FQDN query */ +#define ICMP6_FQDN_REPLY 140 /* FQDN reply */ +#define ICMP6_NI_QUERY 139 /* node information request */ +#define ICMP6_NI_REPLY 140 /* node information reply */ +#define MLDV2_LISTENER_REPORT 143 /* RFC3810 listener report */ + +/* The definitions below are experimental. TBA */ +#define MLD_MTRACE_RESP 200 /* mtrace response(to sender) */ +#define MLD_MTRACE 201 /* mtrace messages */ + +#define ICMP6_MAXTYPE 201 + +#define ICMP6_DST_UNREACH_NOROUTE 0 /* no route to destination */ +#define ICMP6_DST_UNREACH_ADMIN 1 /* administratively prohibited */ +#define ICMP6_DST_UNREACH_BEYONDSCOPE 2 /* beyond scope of source address */ +#define ICMP6_DST_UNREACH_ADDR 3 /* address unreachable */ +#define ICMP6_DST_UNREACH_NOPORT 4 /* port unreachable */ + +#define ICMP6_TIME_EXCEED_TRANSIT 0 /* ttl==0 in transit */ +#define ICMP6_TIME_EXCEED_REASSEMBLY 1 /* ttl==0 in reass */ + +#define ICMP6_PARAMPROB_HEADER 0 /* erroneous header field */ +#define ICMP6_PARAMPROB_NEXTHEADER 1 /* unrecognized next header */ +#define ICMP6_PARAMPROB_OPTION 2 /* unrecognized option */ + +#define ICMP6_INFOMSG_MASK 0x80 /* all informational messages */ + +#define ICMP6_NI_SUBJ_IPV6 0 /* Query Subject is an IPv6 address */ +#define ICMP6_NI_SUBJ_FQDN 1 /* Query Subject is a Domain name */ +#define ICMP6_NI_SUBJ_IPV4 2 /* Query Subject is an IPv4 address */ + +#define ICMP6_NI_SUCCESS 0 /* node information successful reply */ +#define ICMP6_NI_REFUSED 1 /* node information request is refused */ +#define ICMP6_NI_UNKNOWN 2 /* unknown Qtype */ + +#define ICMP6_ROUTER_RENUMBERING_COMMAND 0 /* rr command */ +#define ICMP6_ROUTER_RENUMBERING_RESULT 1 /* rr result */ +#define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET 255 /* rr seq num reset */ + +/* Used in kernel only */ +#define ND_REDIRECT_ONLINK 0 /* redirect to an on-link node */ +#define ND_REDIRECT_ROUTER 1 /* redirect to a better router */ + +/* + * Multicast Listener Discovery + */ +struct mld_hdr { + struct icmp6_hdr mld_icmp6_hdr; + struct in6_addr mld_addr; /* multicast address */ +} __packed; + +/* shortcut macro definitions */ +#define mld_type mld_icmp6_hdr.icmp6_type +#define mld_code mld_icmp6_hdr.icmp6_code +#define mld_cksum mld_icmp6_hdr.icmp6_cksum +#define mld_maxdelay mld_icmp6_hdr.icmp6_data16[0] +#define mld_reserved mld_icmp6_hdr.icmp6_data16[1] + +/* + * Neighbor Discovery + */ + +struct nd_router_solicit { /* router solicitation */ + struct icmp6_hdr nd_rs_hdr; + /* could be followed by options */ +} __packed; + +#define nd_rs_type nd_rs_hdr.icmp6_type +#define nd_rs_code nd_rs_hdr.icmp6_code +#define nd_rs_cksum nd_rs_hdr.icmp6_cksum +#define nd_rs_reserved nd_rs_hdr.icmp6_data32[0] + +struct nd_router_advert { /* router advertisement */ + struct icmp6_hdr nd_ra_hdr; + u_int32_t nd_ra_reachable; /* reachable time */ + u_int32_t nd_ra_retransmit; /* retransmit timer */ + /* could be followed by options */ +} __packed; + +#define nd_ra_type nd_ra_hdr.icmp6_type +#define nd_ra_code nd_ra_hdr.icmp6_code +#define nd_ra_cksum nd_ra_hdr.icmp6_cksum +#define nd_ra_curhoplimit nd_ra_hdr.icmp6_data8[0] +#define nd_ra_flags_reserved nd_ra_hdr.icmp6_data8[1] +#define ND_RA_FLAG_MANAGED 0x80 +#define ND_RA_FLAG_OTHER 0x40 + +#define ND_RA_FLAG_RTPREF_MASK 0x18 /* 00011000 */ + +#define ND_RA_FLAG_RTPREF_HIGH 0x08 /* 00001000 */ +#define ND_RA_FLAG_RTPREF_MEDIUM 0x00 /* 00000000 */ +#define ND_RA_FLAG_RTPREF_LOW 0x18 /* 00011000 */ +#define ND_RA_FLAG_RTPREF_RSV 0x10 /* 00010000 */ + +#define nd_ra_router_lifetime nd_ra_hdr.icmp6_data16[1] + +struct nd_neighbor_solicit { /* neighbor solicitation */ + struct icmp6_hdr nd_ns_hdr; + struct in6_addr nd_ns_target; /*target address */ + /* could be followed by options */ +} __packed; + +#define nd_ns_type nd_ns_hdr.icmp6_type +#define nd_ns_code nd_ns_hdr.icmp6_code +#define nd_ns_cksum nd_ns_hdr.icmp6_cksum +#define nd_ns_reserved nd_ns_hdr.icmp6_data32[0] + +struct nd_neighbor_advert { /* neighbor advertisement */ + struct icmp6_hdr nd_na_hdr; + struct in6_addr nd_na_target; /* target address */ + /* could be followed by options */ +} __packed; + +#define nd_na_type nd_na_hdr.icmp6_type +#define nd_na_code nd_na_hdr.icmp6_code +#define nd_na_cksum nd_na_hdr.icmp6_cksum +#define nd_na_flags_reserved nd_na_hdr.icmp6_data32[0] +#define ND_NA_FLAG_ROUTER htonl(0x80000000) +#define ND_NA_FLAG_SOLICITED htonl(0x40000000) +#define ND_NA_FLAG_OVERRIDE htonl(0x20000000) + +struct nd_redirect { /* redirect */ + struct icmp6_hdr nd_rd_hdr; + struct in6_addr nd_rd_target; /* target address */ + struct in6_addr nd_rd_dst; /* destination address */ + /* could be followed by options */ +} __packed; + +#define nd_rd_type nd_rd_hdr.icmp6_type +#define nd_rd_code nd_rd_hdr.icmp6_code +#define nd_rd_cksum nd_rd_hdr.icmp6_cksum +#define nd_rd_reserved nd_rd_hdr.icmp6_data32[0] + +struct nd_opt_hdr { /* Neighbor discovery option header */ + u_int8_t nd_opt_type; + u_int8_t nd_opt_len; + /* followed by option specific data*/ +} __packed; + +#define ND_OPT_SOURCE_LINKADDR 1 +#define ND_OPT_TARGET_LINKADDR 2 +#define ND_OPT_PREFIX_INFORMATION 3 +#define ND_OPT_REDIRECTED_HEADER 4 +#define ND_OPT_MTU 5 +#define ND_OPT_ROUTE_INFO 24 +#define ND_OPT_RDNSS 25 +#define ND_OPT_DNSSL 31 + +struct nd_opt_prefix_info { /* prefix information */ + u_int8_t nd_opt_pi_type; + u_int8_t nd_opt_pi_len; + u_int8_t nd_opt_pi_prefix_len; + u_int8_t nd_opt_pi_flags_reserved; + u_int32_t nd_opt_pi_valid_time; + u_int32_t nd_opt_pi_preferred_time; + u_int32_t nd_opt_pi_reserved2; + struct in6_addr nd_opt_pi_prefix; +} __packed; + +#define ND_OPT_PI_FLAG_ONLINK 0x80 +#define ND_OPT_PI_FLAG_AUTO 0x40 + +struct nd_opt_rd_hdr { /* redirected header */ + u_int8_t nd_opt_rh_type; + u_int8_t nd_opt_rh_len; + u_int16_t nd_opt_rh_reserved1; + u_int32_t nd_opt_rh_reserved2; + /* followed by IP header and data */ +} __packed; + +struct nd_opt_mtu { /* MTU option */ + u_int8_t nd_opt_mtu_type; + u_int8_t nd_opt_mtu_len; + u_int16_t nd_opt_mtu_reserved; + u_int32_t nd_opt_mtu_mtu; +} __packed; + +struct nd_opt_route_info { /* route info */ + u_int8_t nd_opt_rti_type; + u_int8_t nd_opt_rti_len; + u_int8_t nd_opt_rti_prefixlen; + u_int8_t nd_opt_rti_flags; + u_int32_t nd_opt_rti_lifetime; +} __packed; + +struct nd_opt_rdnss { /* RDNSS option */ + u_int8_t nd_opt_rdnss_type; + u_int8_t nd_opt_rdnss_len; + u_int16_t nd_opt_rdnss_reserved; + u_int32_t nd_opt_rdnss_lifetime; + /* followed by list of recursive DNS servers */ +} __packed; + +struct nd_opt_dnssl { /* DNSSL option */ + u_int8_t nd_opt_dnssl_type; + u_int8_t nd_opt_dnssl_len; + u_int16_t nd_opt_dnssl_reserved; + u_int32_t nd_opt_dnssl_lifetime; + /* followed by list of DNS search domains */ +} __packed; + +/* + * icmp6 namelookup + */ +struct icmp6_namelookup { + struct icmp6_hdr icmp6_nl_hdr; + u_int8_t icmp6_nl_nonce[8]; + int32_t icmp6_nl_ttl; +#if 0 + u_int8_t icmp6_nl_len; + u_int8_t icmp6_nl_name[3]; +#endif + /* could be followed by options */ +} __packed; + +/* + * icmp6 node information + */ +struct icmp6_nodeinfo { + struct icmp6_hdr icmp6_ni_hdr; + u_int8_t icmp6_ni_nonce[8]; + /* could be followed by reply data */ +} __packed; + +#define ni_type icmp6_ni_hdr.icmp6_type +#define ni_code icmp6_ni_hdr.icmp6_code +#define ni_cksum icmp6_ni_hdr.icmp6_cksum +#define ni_qtype icmp6_ni_hdr.icmp6_data16[0] +#define ni_flags icmp6_ni_hdr.icmp6_data16[1] + +#define NI_QTYPE_NOOP 0 /* NOOP */ +#define NI_QTYPE_SUPTYPES 1 /* Supported Qtypes */ +#define NI_QTYPE_FQDN 2 /* FQDN (draft 04) */ +#define NI_QTYPE_DNSNAME 2 /* DNS Name */ +#define NI_QTYPE_NODEADDR 3 /* Node Addresses */ +#define NI_QTYPE_IPV4ADDR 4 /* IPv4 Addresses */ + +#define NI_SUPTYPE_FLAG_COMPRESS htons(0x0001) +#define NI_FQDN_FLAG_VALIDTTL htons(0x0001) + +#define NI_NODEADDR_FLAG_TRUNCATE htons(0x0001) +#define NI_NODEADDR_FLAG_ALL htons(0x0002) +#define NI_NODEADDR_FLAG_COMPAT htons(0x0004) +#define NI_NODEADDR_FLAG_LINKLOCAL htons(0x0008) +#define NI_NODEADDR_FLAG_SITELOCAL htons(0x0010) +#define NI_NODEADDR_FLAG_GLOBAL htons(0x0020) +#define NI_NODEADDR_FLAG_ANYCAST htons(0x0040) /* not in spec */ + +struct ni_reply_fqdn { + u_int32_t ni_fqdn_ttl; /* TTL */ + u_int8_t ni_fqdn_namelen; /* length in octets of the FQDN */ + u_int8_t ni_fqdn_name[3]; /* XXX: alignment */ +} __packed; + +/* + * Router Renumbering. as router-renum-08.txt + */ +struct icmp6_router_renum { /* router renumbering header */ + struct icmp6_hdr rr_hdr; + u_int8_t rr_segnum; + u_int8_t rr_flags; + u_int16_t rr_maxdelay; + u_int32_t rr_reserved; +} __packed; + +#define ICMP6_RR_FLAGS_TEST 0x80 +#define ICMP6_RR_FLAGS_REQRESULT 0x40 +#define ICMP6_RR_FLAGS_FORCEAPPLY 0x20 +#define ICMP6_RR_FLAGS_SPECSITE 0x10 +#define ICMP6_RR_FLAGS_PREVDONE 0x08 + +#define rr_type rr_hdr.icmp6_type +#define rr_code rr_hdr.icmp6_code +#define rr_cksum rr_hdr.icmp6_cksum +#define rr_seqnum rr_hdr.icmp6_data32[0] + +struct rr_pco_match { /* match prefix part */ + u_int8_t rpm_code; + u_int8_t rpm_len; + u_int8_t rpm_ordinal; + u_int8_t rpm_matchlen; + u_int8_t rpm_minlen; + u_int8_t rpm_maxlen; + u_int16_t rpm_reserved; + struct in6_addr rpm_prefix; +} __packed; + +#define RPM_PCO_ADD 1 +#define RPM_PCO_CHANGE 2 +#define RPM_PCO_SETGLOBAL 3 +#define RPM_PCO_MAX 4 + +struct rr_pco_use { /* use prefix part */ + u_int8_t rpu_uselen; + u_int8_t rpu_keeplen; + u_int8_t rpu_ramask; + u_int8_t rpu_raflags; + u_int32_t rpu_vltime; + u_int32_t rpu_pltime; + u_int32_t rpu_flags; + struct in6_addr rpu_prefix; +} __packed; +#define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK 0x80 +#define ICMP6_RR_PCOUSE_RAFLAGS_AUTO 0x40 + +#define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME htonl(0x80000000) +#define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME htonl(0x40000000) + +struct rr_result { /* router renumbering result message */ + u_int16_t rrr_flags; + u_int8_t rrr_ordinal; + u_int8_t rrr_matchedlen; + u_int32_t rrr_ifid; + struct in6_addr rrr_prefix; +} __packed; +#define ICMP6_RR_RESULT_FLAGS_OOB htons(0x0002) +#define ICMP6_RR_RESULT_FLAGS_FORBIDDEN htons(0x0001) + +/* + * icmp6 filter structures. + */ + +struct icmp6_filter { + u_int32_t icmp6_filt[8]; +}; + +#define ICMP6_FILTER_SETPASSALL(filterp) \ + memset(filterp, 0xff, sizeof(struct icmp6_filter)) +#define ICMP6_FILTER_SETBLOCKALL(filterp) \ + memset(filterp, 0x00, sizeof(struct icmp6_filter)) +#define ICMP6_FILTER_SETPASS(type, filterp) \ + (((filterp)->icmp6_filt[(type) >> 5]) |= (1 << ((type) & 31))) +#define ICMP6_FILTER_SETBLOCK(type, filterp) \ + (((filterp)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31))) +#define ICMP6_FILTER_WILLPASS(type, filterp) \ + ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) != 0) +#define ICMP6_FILTER_WILLBLOCK(type, filterp) \ + ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) == 0) + +/* + * Variables related to this implementation + * of the internet control message protocol version 6. + */ +struct icmp6stat { +/* statistics related to icmp6 packets generated */ + u_int64_t icp6s_error; /* # of calls to icmp6_error */ + u_int64_t icp6s_canterror; /* no error because old was icmp */ + u_int64_t icp6s_toofreq; /* no error because rate limitation */ + u_int64_t icp6s_outhist[256]; +/* statistics related to input message processed */ + u_int64_t icp6s_badcode; /* icmp6_code out of range */ + u_int64_t icp6s_tooshort; /* packet < sizeof(struct icmp6_hdr) */ + u_int64_t icp6s_checksum; /* bad checksum */ + u_int64_t icp6s_badlen; /* calculated bound mismatch */ + /* + * number of responses: this member is inherited from netinet code, but + * for netinet6 code, it is already available in icp6s_outhist[]. + */ + u_int64_t icp6s_reflect; + u_int64_t icp6s_inhist[256]; + u_int64_t icp6s_nd_toomanyopt; /* too many ND options */ + u_int64_t icp6s_odst_unreach_noroute; + u_int64_t icp6s_odst_unreach_admin; + u_int64_t icp6s_odst_unreach_beyondscope; + u_int64_t icp6s_odst_unreach_addr; + u_int64_t icp6s_odst_unreach_noport; + u_int64_t icp6s_opacket_too_big; + u_int64_t icp6s_otime_exceed_transit; + u_int64_t icp6s_otime_exceed_reassembly; + u_int64_t icp6s_oparamprob_header; + u_int64_t icp6s_oparamprob_nextheader; + u_int64_t icp6s_oparamprob_option; + u_int64_t icp6s_oredirect; /* we regard redirect as an error here */ + u_int64_t icp6s_ounknown; + u_int64_t icp6s_pmtuchg; /* path MTU changes */ + u_int64_t icp6s_nd_badopt; /* bad ND options */ + u_int64_t icp6s_badns; /* bad neighbor solicitation */ + u_int64_t icp6s_badna; /* bad neighbor advertisement */ + u_int64_t icp6s_badrs; /* bad router advertisement */ + u_int64_t icp6s_badra; /* bad router advertisement */ + u_int64_t icp6s_badredirect; /* bad redirect message */ +}; + +/* + * Names for ICMP sysctl objects + */ +#define ICMPV6CTL_STATS 1 +#define ICMPV6CTL_REDIRACCEPT 2 /* accept/process redirects */ +#define ICMPV6CTL_REDIRTIMEOUT 3 /* redirect cache time */ +#define ICMPV6CTL_ND6_DELAY 8 +#define ICMPV6CTL_ND6_UMAXTRIES 9 +#define ICMPV6CTL_ND6_MMAXTRIES 10 +#define ICMPV6CTL_ND6_QUEUED 11 +#define ICMPV6CTL_NODEINFO 13 +#define ICMPV6CTL_ERRPPSLIMIT 14 /* ICMPv6 error pps limitation */ +#define ICMPV6CTL_MTUDISC_HIWAT 16 +#define ICMPV6CTL_MTUDISC_LOWAT 17 +#define ICMPV6CTL_MAXID 18 + +#define ICMPV6CTL_NAMES { \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "redirtimeout", CTLTYPE_INT }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "nd6_delay", CTLTYPE_INT }, \ + { "nd6_umaxtries", CTLTYPE_INT }, \ + { "nd6_mmaxtries", CTLTYPE_INT }, \ + { "nd6_queued", CTLTYPE_INT }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "errppslimit", CTLTYPE_INT }, \ + { 0, 0 }, \ + { "mtudisc_hiwat", CTLTYPE_INT }, \ + { "mtudisc_lowat", CTLTYPE_INT }, \ +} + +#define RTF_PROBEMTU RTF_PROTO1 + +#ifdef _KERNEL + +#include + +enum icmp6stat_counters { + icp6s_error, + icp6s_canterror, + icp6s_toofreq, + icp6s_outhist, + icp6s_badcode = icp6s_outhist + 256, + icp6s_tooshort, + icp6s_checksum, + icp6s_badlen, + icp6s_reflect, + icp6s_inhist, + icp6s_nd_toomanyopt = icp6s_inhist + 256, + icp6s_odst_unreach_noroute, + icp6s_odst_unreach_admin, + icp6s_odst_unreach_beyondscope, + icp6s_odst_unreach_addr, + icp6s_odst_unreach_noport, + icp6s_opacket_too_big, + icp6s_otime_exceed_transit, + icp6s_otime_exceed_reassembly, + icp6s_oparamprob_header, + icp6s_oparamprob_nextheader, + icp6s_oparamprob_option, + icp6s_oredirect, + icp6s_ounknown, + icp6s_pmtuchg, + icp6s_nd_badopt, + icp6s_badns, + icp6s_badna, + icp6s_badrs, + icp6s_badra, + icp6s_badredirect, + icp6s_ncounters, +}; + +extern struct cpumem *icmp6counters; + +static inline void +icmp6stat_inc(enum icmp6stat_counters c) +{ + counters_inc(icmp6counters, c); +} + +struct rtentry; +struct rttimer; +struct in6_multi; + +void icmp6_init(void); +struct mbuf *icmp6_do_error(struct mbuf *, int, int, int); +void icmp6_error(struct mbuf *, int, int, int); +int icmp6_input(struct mbuf **, int *, int, int, + struct netstack *); +void icmp6_fasttimo(void); +int icmp6_reflect(struct mbuf **, size_t, struct sockaddr *); +void icmp6_redirect_input(struct mbuf *, int); +void icmp6_redirect_output(struct mbuf *, struct rtentry *); +int icmp6_sysctl(int *, u_int, void *, size_t *, void *, size_t); +struct rtentry *icmp6_mtudisc_clone(struct sockaddr_in6 *, u_int, int); + +struct ip6ctlparam; +void icmp6_mtudisc_update(struct ip6ctlparam *, int); +void icmp6_mtudisc_callback_register(void (*)(struct sockaddr_in6 *, u_int)); + +extern int icmp6_redirtimeout; /* cache time for redirect routes */ + +#endif /* _KERNEL */ +#endif /* _NETINET_ICMP6_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/icmp_var.h b/lib/libc/include/generic-openbsd/netinet/icmp_var.h new file mode 100644 index 0000000000..7aa326ae5c --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/icmp_var.h @@ -0,0 +1,111 @@ +/* $OpenBSD: icmp_var.h,v 1.16 2020/08/22 17:55:54 gnezdo Exp $ */ +/* $NetBSD: icmp_var.h,v 1.8 1995/03/26 20:32:19 jtc Exp $ */ + +/* + * Copyright (c) 1982, 1986, 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. + * + * @(#)icmp_var.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NETINET_ICMP_VAR_H_ +#define _NETINET_ICMP_VAR_H_ + +/* + * Variables related to this implementation + * of the internet control message protocol. + */ +struct icmpstat { +/* statistics related to icmp packets generated */ + u_long icps_error; /* # of calls to icmp_error */ + u_long icps_toofreq; /* no error because rate limiter */ + u_long icps_oldshort; /* no error because old ip too short */ + u_long icps_oldicmp; /* no error because old was icmp */ + u_long icps_outhist[ICMP_MAXTYPE + 1]; +/* statistics related to input messages processed */ + u_long icps_badcode; /* icmp_code out of range */ + u_long icps_tooshort; /* packet < ICMP_MINLEN */ + u_long icps_checksum; /* bad checksum */ + u_long icps_badlen; /* calculated bound mismatch */ + u_long icps_reflect; /* number of responses */ + u_long icps_bmcastecho; /* rejected broadcast icmps */ + u_long icps_inhist[ICMP_MAXTYPE + 1]; +}; + +/* + * Names for ICMP sysctl objects + */ +#define ICMPCTL_MASKREPL 1 /* allow replies to netmask requests */ +#define ICMPCTL_BMCASTECHO 2 /* reply to icmps to broadcast/mcast */ +#define ICMPCTL_ERRPPSLIMIT 3 /* ICMP error pps limitation */ +#define ICMPCTL_REDIRACCEPT 4 /* Accept redirects from routers */ +#define ICMPCTL_REDIRTIMEOUT 5 /* Remove routes added via redirects */ +#define ICMPCTL_TSTAMPREPL 6 /* allow replies to timestamp requests */ +#define ICMPCTL_STATS 7 /* ICMP statistics */ +#define ICMPCTL_MAXID 8 + +#define ICMPCTL_NAMES { \ + { 0, 0 }, \ + { "maskrepl", CTLTYPE_INT }, \ + { "bmcastecho", CTLTYPE_INT }, \ + { "errppslimit", CTLTYPE_INT }, \ + { "rediraccept", CTLTYPE_INT }, \ + { "redirtimeout", CTLTYPE_INT }, \ + { "tstamprepl", CTLTYPE_INT }, \ + { "stats", CTLTYPE_STRUCT } \ +} + +#ifdef _KERNEL + +#include + +enum icmpstat_counters { + icps_error, + icps_toofreq, + icps_oldshort, + icps_oldicmp, + icps_outhist, + icps_badcode = icps_outhist + ICMP_MAXTYPE + 1, + icps_tooshort, + icps_checksum, + icps_badlen, + icps_reflect, + icps_bmcastecho, + icps_inhist, + icps_ncounters = icps_inhist + ICMP_MAXTYPE + 1 +}; + +extern struct cpumem *icmpcounters; + +static inline void +icmpstat_inc(enum icmpstat_counters c) +{ + counters_inc(icmpcounters, c); +} + +#endif /* _KERNEL */ +#endif /* _NETINET_ICMP_VAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/if_ether.h b/lib/libc/include/generic-openbsd/netinet/if_ether.h new file mode 100644 index 0000000000..35eab71804 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/if_ether.h @@ -0,0 +1,398 @@ +/* $OpenBSD: if_ether.h,v 1.96 2025/07/07 00:55:15 jsg Exp $ */ +/* $NetBSD: if_ether.h,v 1.22 1996/05/11 13:00:00 mycroft Exp $ */ + +/* + * Copyright (c) 1982, 1986, 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. + * + * @(#)if_ether.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NETINET_IF_ETHER_H_ +#define _NETINET_IF_ETHER_H_ + +/* + * Some basic Ethernet constants. + */ +#define ETHER_ADDR_LEN 6 /* Ethernet address length */ +#define ETHER_TYPE_LEN 2 /* Ethernet type field length */ +#define ETHER_CRC_LEN 4 /* Ethernet CRC length */ +#define ETHER_HDR_LEN ((ETHER_ADDR_LEN * 2) + ETHER_TYPE_LEN) +#define ETHER_MIN_LEN 64 /* Minimum frame length, CRC included */ +#define ETHER_MAX_LEN 1518 /* Maximum frame length, CRC included */ +#define ETHER_MAX_DIX_LEN 1536 /* Maximum DIX frame length */ + +/* + * Some Ethernet extensions. + */ +#define ETHER_VLAN_ENCAP_LEN 4 /* len of 802.1Q VLAN encapsulation */ + +/* + * Mbuf adjust factor to force 32-bit alignment of IP header. + * Drivers should do m_adj(m, ETHER_ALIGN) when setting up a + * receive so the upper layers get the IP header properly aligned + * past the 14-byte Ethernet header. + */ +#define ETHER_ALIGN 2 /* driver adjust for IP hdr alignment */ + +/* + * The maximum supported Ethernet length and some space for encapsulation. + */ +#define ETHER_MAX_HARDMTU_LEN 65435 + +/* + * Ethernet address - 6 octets + */ +struct ether_addr { + u_int8_t ether_addr_octet[ETHER_ADDR_LEN]; +}; + +/* + * The length of the combined header. + */ +struct ether_header { + u_int8_t ether_dhost[ETHER_ADDR_LEN]; + u_int8_t ether_shost[ETHER_ADDR_LEN]; + u_int16_t ether_type; +}; + +/* + * VLAN headers. + */ + +struct ether_vlan_header { + u_char evl_dhost[ETHER_ADDR_LEN]; + u_char evl_shost[ETHER_ADDR_LEN]; + u_int16_t evl_encap_proto; + u_int16_t evl_tag; + u_int16_t evl_proto; +}; + +#define EVL_VLID_MASK 0xFFF +#define EVL_VLID_NULL 0x000 +/* 0x000 and 0xfff are reserved */ +#define EVL_VLID_MIN 0x001 +#define EVL_VLID_MAX 0xFFE +#define EVL_VLANOFTAG(tag) ((tag) & EVL_VLID_MASK) + +#define EVL_PRIO_MAX 7 +#define EVL_PRIO_BITS 13 +#define EVL_PRIOFTAG(tag) (((tag) >> EVL_PRIO_BITS) & 7) + +#define EVL_ENCAPLEN 4 /* length in octets of encapsulation */ + +#include + +#define ETHER_IS_MULTICAST(addr) (*(addr) & 0x01) /* is address mcast/bcast? */ +#define ETHER_IS_BROADCAST(addr) \ + (((addr)[0] & (addr)[1] & (addr)[2] & \ + (addr)[3] & (addr)[4] & (addr)[5]) == 0xff) +#define ETHER_IS_ANYADDR(addr) \ + (((addr)[0] | (addr)[1] | (addr)[2] | \ + (addr)[3] | (addr)[4] | (addr)[5]) == 0x00) +#define ETHER_IS_EQ(a1, a2) (memcmp((a1), (a2), ETHER_ADDR_LEN) == 0) + +/* + * It can be faster to work with ethernet addresses as a uint64_t. + * Provide some constants and functionality centrally to better + * support this. + */ + +#define ETH64_IS_MULTICAST(_e64) ((_e64) & 0x010000000000ULL) +#define ETH64_IS_BROADCAST(_e64) ((_e64) == 0xffffffffffffULL) +#define ETH64_IS_ANYADDR(_e64) ((_e64) == 0x000000000000ULL) + +#define ETH64_8021_RSVD_PREFIX 0x0180c2000000ULL +#define ETH64_8021_RSVD_MASK 0xfffffffffff0ULL +#define ETH64_IS_8021_RSVD(_e64) \ + (((_e64) & ETH64_8021_RSVD_MASK) == ETH64_8021_RSVD_PREFIX) + +/* + * Ethernet MTU constants. + */ +#define ETHERMTU (ETHER_MAX_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN) +#define ETHERMIN (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN) + +/* + * Ethernet CRC32 polynomials (big- and little-endian versions). + */ +#define ETHER_CRC_POLY_LE 0xedb88320 +#define ETHER_CRC_POLY_BE 0x04c11db6 + +/* + * Ethernet Address Resolution Protocol. + * + * See RFC 826 for protocol description. Structure below is adapted + * to resolving internet addresses. Field names used correspond to + * RFC 826. + */ +struct ether_arp { + struct arphdr ea_hdr; /* fixed-size header */ + u_int8_t arp_sha[ETHER_ADDR_LEN]; /* sender hardware address */ + u_int8_t arp_spa[4]; /* sender protocol address */ + u_int8_t arp_tha[ETHER_ADDR_LEN]; /* target hardware address */ + u_int8_t arp_tpa[4]; /* target protocol address */ +}; +#define arp_hrd ea_hdr.ar_hrd +#define arp_pro ea_hdr.ar_pro +#define arp_hln ea_hdr.ar_hln +#define arp_pln ea_hdr.ar_pln +#define arp_op ea_hdr.ar_op + +struct sockaddr_inarp { + u_int8_t sin_len; + u_int8_t sin_family; + u_int16_t sin_port; + struct in_addr sin_addr; + struct in_addr sin_srcaddr; + u_int16_t sin_tos; + u_int16_t sin_other; +#define SIN_PROXY 1 +}; + +/* + * IP and ethernet specific routing flags + */ +#define RTF_USETRAILERS RTF_PROTO1 /* use trailers */ +#define RTF_PERMANENT_ARP RTF_PROTO3 /* only manual overwrite of entry */ + +#ifdef _KERNEL + +#include + +/* + * Macro to map an IP multicast address to an Ethernet multicast address. + * The high-order 25 bits of the Ethernet address are statically assigned, + * and the low-order 23 bits are taken from the low end of the IP address. + */ +#define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \ + /* struct in_addr *ipaddr; */ \ + /* u_int8_t enaddr[ETHER_ADDR_LEN]; */ \ +do { \ + (enaddr)[0] = 0x01; \ + (enaddr)[1] = 0x00; \ + (enaddr)[2] = 0x5e; \ + (enaddr)[3] = ((u_int8_t *)ipaddr)[1] & 0x7f; \ + (enaddr)[4] = ((u_int8_t *)ipaddr)[2]; \ + (enaddr)[5] = ((u_int8_t *)ipaddr)[3]; \ +} while (/* CONSTCOND */ 0) + +/* + * Macro to map an IPv6 multicast address to an Ethernet multicast address. + * The high-order 16 bits of the Ethernet address are statically assigned, + * and the low-order 32 bits are taken from the low end of the IPv6 address. + */ +#define ETHER_MAP_IPV6_MULTICAST(ip6addr, enaddr) \ + /* struct in6_addr *ip6addr; */ \ + /* u_int8_t enaddr[ETHER_ADDR_LEN]; */ \ +do { \ + (enaddr)[0] = 0x33; \ + (enaddr)[1] = 0x33; \ + (enaddr)[2] = ((u_int8_t *)ip6addr)[12]; \ + (enaddr)[3] = ((u_int8_t *)ip6addr)[13]; \ + (enaddr)[4] = ((u_int8_t *)ip6addr)[14]; \ + (enaddr)[5] = ((u_int8_t *)ip6addr)[15]; \ +} while (/* CONSTCOND */ 0) + +#include /* for "struct ifnet" */ + +struct ether_brport { + struct mbuf *(*eb_input)(struct ifnet *, struct mbuf *, + uint64_t, void *, struct netstack *); + void (*eb_port_take)(void *); + void (*eb_port_rele)(void *); + void *eb_port; +}; + +/* + * Structure shared between the ethernet driver modules and + * the address resolution code. For example, each ec_softc or il_softc + * begins with this structure. + */ +struct arpcom { + struct ifnet ac_if; /* network-visible interface */ + u_int8_t ac_enaddr[ETHER_ADDR_LEN]; /* ethernet hardware address */ + char ac__pad[2]; /* pad for some machines */ + LIST_HEAD(, ether_multi) ac_multiaddrs; /* list of multicast addrs */ + int ac_multicnt; /* length of ac_multiaddrs */ + int ac_multirangecnt; /* number of mcast ranges */ + + void *ac_trunkport; + const struct ether_brport *ac_brport; +}; + +extern int arpt_keep; /* arp resolved cache expire */ +extern int arpt_down; /* arp down cache expire */ + +extern u_int8_t etherbroadcastaddr[ETHER_ADDR_LEN]; +extern u_int8_t etheranyaddr[ETHER_ADDR_LEN]; +extern u_int8_t ether_ipmulticast_min[ETHER_ADDR_LEN]; +extern u_int8_t ether_ipmulticast_max[ETHER_ADDR_LEN]; + +#ifdef NFSCLIENT +extern unsigned int revarp_ifidx; +#endif /* NFSCLIENT */ + +void revarpinput(struct ifnet *, struct mbuf *, struct netstack *); +void revarprequest(struct ifnet *); +int revarpwhoarewe(struct ifnet *, struct in_addr *, struct in_addr *); +int revarpwhoami(struct in_addr *, struct ifnet *); + +void arpinit(void); +void arpinput(struct ifnet *, struct mbuf *, struct netstack *); +void arprequest(struct ifnet *, u_int32_t *, u_int32_t *, u_int8_t *); +int arpproxy(struct in_addr, unsigned int); +int arpresolve(struct ifnet *, struct rtentry *, struct mbuf *, + struct sockaddr *, u_char *); +void arp_rtrequest(struct ifnet *, int, struct rtentry *); + +void ether_fakeaddr(struct ifnet *); +int ether_addmulti(struct ifreq *, struct arpcom *); +int ether_delmulti(struct ifreq *, struct arpcom *); +int ether_multiaddr(struct sockaddr *, u_int8_t *, u_int8_t *); +void ether_ifattach(struct ifnet *); +void ether_ifdetach(struct ifnet *); +int ether_ioctl(struct ifnet *, struct arpcom *, u_long, caddr_t); +void ether_input(struct ifnet *, struct mbuf *, struct netstack *); +int ether_resolve(struct ifnet *, struct mbuf *, struct sockaddr *, + struct rtentry *, struct ether_header *); +struct mbuf * + ether_encap(struct ifnet *, struct mbuf *, struct sockaddr *, + struct rtentry *, int *); +int ether_output(struct ifnet *, struct mbuf *, struct sockaddr *, + struct rtentry *); +void ether_rtrequest(struct ifnet *, int, struct rtentry *); +char *ether_sprintf(u_char *); + +int ether_brport_isset(struct ifnet *); +void ether_brport_set(struct ifnet *, const struct ether_brport *); +void ether_brport_clr(struct ifnet *); +const struct ether_brport * + ether_brport_get(struct ifnet *); +const struct ether_brport * + ether_brport_get_locked(struct ifnet *); + +uint64_t ether_addr_to_e64(const struct ether_addr *); +void ether_e64_to_addr(struct ether_addr *, uint64_t); + +struct ether_extracted { + struct ether_header *eh; + struct ether_vlan_header *evh; + struct ip *ip4; + struct ip6_hdr *ip6; + struct tcphdr *tcp; + struct udphdr *udp; + u_int iplen; + u_int iphlen; + u_int tcphlen; + u_int paylen; +}; + +void ether_extract_headers(struct mbuf *, struct ether_extracted *); + +/* + * Ethernet multicast address structure. There is one of these for each + * multicast address or range of multicast addresses that we are supposed + * to listen to on a particular interface. They are kept in a linked list, + * rooted in the interface's arpcom structure. (This really has nothing to + * do with ARP, or with the Internet address family, but this appears to be + * the minimally-disrupting place to put it.) + */ +struct ether_multi { + u_int8_t enm_addrlo[ETHER_ADDR_LEN]; /* low or only address of range */ + u_int8_t enm_addrhi[ETHER_ADDR_LEN]; /* high or only address of range */ + struct refcnt enm_refcnt; /* no. claims to this addr/range */ + LIST_ENTRY(ether_multi) enm_list; +}; + +/* + * Structure used by macros below to remember position when stepping through + * all of the ether_multi records. + */ +struct ether_multistep { + struct ether_multi *e_enm; +}; + +/* + * Macro for looking up the ether_multi record for a given range of Ethernet + * multicast addresses connected to a given arpcom structure. If no matching + * record is found, "enm" returns NULL. + */ +#define ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm) \ + /* u_int8_t addrlo[ETHER_ADDR_LEN]; */ \ + /* u_int8_t addrhi[ETHER_ADDR_LEN]; */ \ + /* struct arpcom *ac; */ \ + /* struct ether_multi *enm; */ \ +do { \ + for ((enm) = LIST_FIRST(&(ac)->ac_multiaddrs); \ + (enm) != NULL && \ + (memcmp((enm)->enm_addrlo, (addrlo), ETHER_ADDR_LEN) != 0 ||\ + memcmp((enm)->enm_addrhi, (addrhi), ETHER_ADDR_LEN) != 0); \ + (enm) = LIST_NEXT((enm), enm_list)); \ +} while (/* CONSTCOND */ 0) + +/* + * Macro to step through all of the ether_multi records, one at a time. + * The current position is remembered in "step", which the caller must + * provide. ETHER_FIRST_MULTI(), below, must be called to initialize "step" + * and get the first record. Both macros return a NULL "enm" when there + * are no remaining records. + */ +#define ETHER_NEXT_MULTI(step, enm) \ + /* struct ether_multistep step; */ \ + /* struct ether_multi *enm; */ \ +do { \ + if (((enm) = (step).e_enm) != NULL) \ + (step).e_enm = LIST_NEXT((enm), enm_list); \ +} while (/* CONSTCOND */ 0) + +#define ETHER_FIRST_MULTI(step, ac, enm) \ + /* struct ether_multistep step; */ \ + /* struct arpcom *ac; */ \ + /* struct ether_multi *enm; */ \ +do { \ + (step).e_enm = LIST_FIRST(&(ac)->ac_multiaddrs); \ + ETHER_NEXT_MULTI((step), (enm)); \ +} while (/* CONSTCOND */ 0) + +u_int32_t ether_crc32_le_update(u_int32_t crc, const u_int8_t *, size_t); +u_int32_t ether_crc32_be_update(u_int32_t crc, const u_int8_t *, size_t); +u_int32_t ether_crc32_le(const u_int8_t *, size_t); +u_int32_t ether_crc32_be(const u_int8_t *, size_t); + +#else /* _KERNEL */ + +__BEGIN_DECLS +char *ether_ntoa(const struct ether_addr *); +struct ether_addr *ether_aton(const char *); +int ether_ntohost(char *, struct ether_addr *); +int ether_hostton(const char *, struct ether_addr *); +int ether_line(const char *, struct ether_addr *, char *); +__END_DECLS + +#endif /* _KERNEL */ +#endif /* _NETINET_IF_ETHER_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/igmp.h b/lib/libc/include/generic-openbsd/netinet/igmp.h new file mode 100644 index 0000000000..005f2602be --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/igmp.h @@ -0,0 +1,97 @@ +/* $OpenBSD: igmp.h,v 1.6 2003/06/02 23:28:13 millert Exp $ */ +/* $NetBSD: igmp.h,v 1.6 1995/05/31 06:08:21 mycroft Exp $ */ + +/* + * Copyright (c) 1988 Stephen Deering. + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Stephen Deering of Stanford University. + * + * 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. + * + * @(#)igmp.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NETINET_IGMP_H_ +#define _NETINET_IGMP_H_ + +/* + * Internet Group Management Protocol (IGMP) definitions. + * + * MULTICAST 1.3 + */ + +/* + * IGMP packet format. + */ +struct igmp { + u_int8_t igmp_type; /* version & type of IGMP message */ + u_int8_t igmp_code; /* code for routing sub-messages */ + u_int16_t igmp_cksum; /* IP-style checksum */ + struct in_addr igmp_group; /* group address being reported */ +}; /* (zero for queries) */ + +#define IGMP_MINLEN 8 + +#define IGMP_HOST_MEMBERSHIP_QUERY 0x11 /* membership query */ +#define IGMP_v1_HOST_MEMBERSHIP_REPORT 0x12 /* v1 membership report */ +#define IGMP_DVMRP 0x13 /* DVMRP routing message */ +#define IGMP_PIM 0x14 /* PIM routing message */ +#define IGMP_v2_HOST_MEMBERSHIP_REPORT 0x16 /* v2 membership report */ +#define IGMP_HOST_LEAVE_MESSAGE 0x17 /* leave-group message */ +#define IGMP_MTRACE_REPLY 0x1e /* traceroute reply */ +#define IGMP_MTRACE_QUERY 0x1f /* traceroute query */ + +#define IGMP_MAX_HOST_REPORT_DELAY 10 /* max delay for response to */ + /* query (in seconds) */ + +#define IGMP_TIMER_SCALE 10 /* denominator for igmp_timer */ + +/* + * States for the IGMP v2 state table. + */ +#define IGMP_DELAYING_MEMBER 1 +#define IGMP_IDLE_MEMBER 2 +#define IGMP_LAZY_MEMBER 3 +#define IGMP_SLEEPING_MEMBER 4 +#define IGMP_AWAKENING_MEMBER 5 + +/* + * States for IGMP router version cache. + */ +#define IGMP_v1_ROUTER 1 +#define IGMP_v2_ROUTER 2 + +/* + * Revert to v2 if we haven't heard from the router in this amount of time. + */ +#define IGMP_AGE_THRESHOLD 540 + +#ifdef _KERNEL +void rti_delete(struct ifnet *); +#endif /* _KERNEL */ +#endif /* _NETINET_IGMP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/igmp_var.h b/lib/libc/include/generic-openbsd/netinet/igmp_var.h new file mode 100644 index 0000000000..06624e9aa4 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/igmp_var.h @@ -0,0 +1,116 @@ +/* $OpenBSD: igmp_var.h,v 1.16 2025/03/02 21:28:32 bluhm Exp $ */ +/* $NetBSD: igmp_var.h,v 1.9 1996/02/13 23:41:31 christos Exp $ */ + +/* + * Copyright (c) 1988 Stephen Deering. + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Stephen Deering of Stanford University. + * + * 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. + * + * @(#)igmp_var.h 8.1 (Berkeley) 7/19/93 + */ + +#ifndef _NETINET_IGMP_VAR_H_ +#define _NETINET_IGMP_VAR_H_ + +/* + * Internet Group Management Protocol (IGMP), + * implementation-specific definitions. + * + * Written by Steve Deering, Stanford, May 1988. + * Modified by Rosen Sharma, Stanford, Aug 1994. + * Modified by Bill Fenner, Xerox PARC, Feb 1995. + * + * MULTICAST 1.3 + */ + +struct igmpstat { + u_long igps_rcv_total; /* total IGMP messages received */ + u_long igps_rcv_tooshort; /* received with too few bytes */ + u_long igps_rcv_badsum; /* received with bad checksum */ + u_long igps_rcv_queries; /* received membership queries */ + u_long igps_rcv_badqueries; /* received invalid queries */ + u_long igps_rcv_reports; /* received membership reports */ + u_long igps_rcv_badreports; /* received invalid reports */ + u_long igps_rcv_ourreports; /* received reports for our groups */ + u_long igps_snd_reports; /* sent membership reports */ +}; + +/* + * Names for IGMP sysctl objects + */ +#define IGMPCTL_STATS 1 /* IGMP statistics */ +#define IGMPCTL_MAXID 2 + +#define IGMPCTL_NAMES { \ + { 0, 0 }, \ + { "stats", CTLTYPE_STRUCT } \ +} + +#ifdef _KERNEL + +#include + +enum igmpstat_counters { + igps_rcv_total, /* total IGMP messages received */ + igps_rcv_tooshort, /* received with too few bytes */ + igps_rcv_badsum, /* received with bad checksum */ + igps_rcv_queries, /* received membership queries */ + igps_rcv_badqueries, /* received invalid queries */ + igps_rcv_reports, /* received membership reports */ + igps_rcv_badreports, /* received invalid reports */ + igps_rcv_ourreports, /* received reports for our groups */ + igps_snd_reports, /* sent membership reports */ + igps_ncounters +}; + +extern struct cpumem *igmpcounters; + +static inline void +igmpstat_inc(enum igmpstat_counters c) +{ + counters_inc(igmpcounters, c); +} + +/* + * Macro to compute a random timer value between 1 and (IGMP_MAX_REPORTING_ + * DELAY * countdown frequency). We assume that the routine random() + * is defined somewhere (and that it returns a positive number). + */ +#define IGMP_RANDOM_DELAY(X) (arc4random_uniform(X) + 1) + +void igmp_init(void); +int igmp_input(struct mbuf **, int *, int, int, struct netstack *); +void igmp_joingroup(struct in_multi *, struct ifnet *); +void igmp_leavegroup(struct in_multi *, struct ifnet *); +void igmp_fasttimo(void); +void igmp_slowtimo(void); +int igmp_sysctl(int *, u_int, void *, size_t *, void *, size_t); +#endif /* _KERNEL */ +#endif /* _NETINET_IGMP_VAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/in.h b/lib/libc/include/generic-openbsd/netinet/in.h new file mode 100644 index 0000000000..04da1df3c9 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/in.h @@ -0,0 +1,833 @@ +/* $OpenBSD: in.h,v 1.149 2025/03/02 21:28:32 bluhm Exp $ */ +/* $NetBSD: in.h,v 1.20 1996/02/13 23:41:47 christos Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Constants and structures defined by the internet system, + * Per RFC 790, September 1981, and numerous additions. + */ + +#ifndef _NETINET_IN_H_ +#define _NETINET_IN_H_ + +#include + +#ifndef _KERNEL +#include + +/* is pulled in by */ +#ifndef htons +#define htons(x) __htobe16(x) +#define htonl(x) __htobe32(x) +#define ntohs(x) __htobe16(x) +#define ntohl(x) __htobe32(x) +#endif + +#endif /* _KERNEL */ + +#ifndef _SA_FAMILY_T_DEFINED_ +#define _SA_FAMILY_T_DEFINED_ +typedef __sa_family_t sa_family_t; /* sockaddr address family type */ +#endif /* _SA_FAMILY_T_DEFINED_ */ + +#ifndef _IN_TYPES_DEFINED_ +#define _IN_TYPES_DEFINED_ +typedef __in_addr_t in_addr_t; /* base type for internet address */ +typedef __in_port_t in_port_t; /* IP port type */ +#endif + +/* + * Protocols + */ +#define IPPROTO_IP 0 /* dummy for IP */ +#define IPPROTO_HOPOPTS IPPROTO_IP /* Hop-by-hop option header */ +#define IPPROTO_ICMP 1 /* control message protocol */ +#define IPPROTO_IGMP 2 /* group mgmt protocol */ +#define IPPROTO_GGP 3 /* gateway^2 (deprecated) */ +#define IPPROTO_IPIP 4 /* IP inside IP */ +#define IPPROTO_IPV4 IPPROTO_IPIP /* IP inside IP */ +#define IPPROTO_TCP 6 /* tcp */ +#define IPPROTO_EGP 8 /* exterior gateway protocol */ +#define IPPROTO_PUP 12 /* pup */ +#define IPPROTO_UDP 17 /* user datagram protocol */ +#define IPPROTO_IDP 22 /* xns idp */ +#define IPPROTO_TP 29 /* tp-4 w/ class negotiation */ +#define IPPROTO_IPV6 41 /* IPv6 in IPv6 */ +#define IPPROTO_ROUTING 43 /* Routing header */ +#define IPPROTO_FRAGMENT 44 /* Fragmentation/reassembly header */ +#define IPPROTO_RSVP 46 /* resource reservation */ +#define IPPROTO_GRE 47 /* GRE encap, RFCs 1701/1702 */ +#define IPPROTO_ESP 50 /* Encap. Security Payload */ +#define IPPROTO_AH 51 /* Authentication header */ +#define IPPROTO_MOBILE 55 /* IP Mobility, RFC 2004 */ +#define IPPROTO_ICMPV6 58 /* ICMP for IPv6 */ +#define IPPROTO_NONE 59 /* No next header */ +#define IPPROTO_DSTOPTS 60 /* Destination options header */ +#define IPPROTO_EON 80 /* ISO cnlp */ +#define IPPROTO_ETHERIP 97 /* Ethernet in IPv4 */ +#define IPPROTO_ENCAP 98 /* encapsulation header */ +#define IPPROTO_PIM 103 /* Protocol indep. multicast */ +#define IPPROTO_IPCOMP 108 /* IP Payload Comp. Protocol */ +#define IPPROTO_CARP 112 /* CARP */ +#define IPPROTO_SCTP 132 /* SCTP, RFC 4960 */ +#define IPPROTO_UDPLITE 136 /* UDP-Lite, RFC 3828 */ +#define IPPROTO_MPLS 137 /* unicast MPLS packet */ +#define IPPROTO_PFSYNC 240 /* PFSYNC */ +#define IPPROTO_RAW 255 /* raw IP packet */ + +#define IPPROTO_MAX 256 + +/* Only used internally, so it can be outside the range of valid IP protocols */ +#define IPPROTO_DIVERT 258 /* Divert sockets */ + +/* + * From FreeBSD: + * + * Local port number conventions: + * + * When a user does a bind(2) or connect(2) with a port number of zero, + * a non-conflicting local port address is chosen. + * The default range is IPPORT_RESERVED through + * IPPORT_USERRESERVED, although that is settable by sysctl. + * + * A user may set the IPPROTO_IP option IP_PORTRANGE to change this + * default assignment range. + * + * The value IP_PORTRANGE_DEFAULT causes the default behavior. + * + * The value IP_PORTRANGE_HIGH changes the range of candidate port numbers + * into the "high" range. These are reserved for client outbound connections + * which do not want to be filtered by any firewalls. + * + * The value IP_PORTRANGE_LOW changes the range to the "low" are + * that is (by convention) restricted to privileged processes. This + * convention is based on "vouchsafe" principles only. It is only secure + * if you trust the remote host to restrict these ports. + * + * The default range of ports and the high range can be changed by + * sysctl(3). (net.inet.ip.port{hi}{first,last}) + * + * Changing those values has bad security implications if you are + * using a stateless firewall that is allowing packets outside of that + * range in order to allow transparent outgoing connections. + * + * Such a firewall configuration will generally depend on the use of these + * default values. If you change them, you may find your Security + * Administrator looking for you with a heavy object. + */ + +/* + * Ports < IPPORT_RESERVED are reserved for + * privileged processes (e.g. root). + * Ports > IPPORT_USERRESERVED are reserved + * for servers, not necessarily privileged. + */ +#define IPPORT_RESERVED 1024 +#define IPPORT_USERRESERVED 49151 + +/* + * Default local port range to use by setting IP_PORTRANGE_HIGH + */ +#define IPPORT_HIFIRSTAUTO 49152 +#define IPPORT_HILASTAUTO 65535 + +#ifndef _IN_ADDR_DECLARED +#define _IN_ADDR_DECLARED +/* + * IP Version 4 Internet address (a structure for historical reasons) + */ +struct in_addr { + in_addr_t s_addr; +}; +#endif /* _IN_ADDR_DECLARED */ + +/* last return value of *_input(), meaning "all job for this pkt is done". */ +#define IPPROTO_DONE 257 + +/* + * Definitions of bits in internet address integers. + * On subnets, the decomposition of addresses to host and net parts + * is done according to subnet mask, not the masks here. + * + * By byte-swapping the constants, we avoid ever having to byte-swap IP + * addresses inside the kernel. Unfortunately, user-level programs rely + * on these macros not doing byte-swapping. + */ +#ifdef _KERNEL +#define __IPADDR(x) ((u_int32_t) htonl((u_int32_t)(x))) +#else +#define __IPADDR(x) ((u_int32_t)(x)) +#endif /* _KERNEL */ + +#define IN_CLASSA(i) (((u_int32_t)(i) & __IPADDR(0x80000000)) == \ + __IPADDR(0x00000000)) +#define IN_CLASSA_NET __IPADDR(0xff000000) +#define IN_CLASSA_NSHIFT 24 +#define IN_CLASSA_HOST __IPADDR(0x00ffffff) +#define IN_CLASSA_MAX 128 + +#define IN_CLASSB(i) (((u_int32_t)(i) & __IPADDR(0xc0000000)) == \ + __IPADDR(0x80000000)) +#define IN_CLASSB_NET __IPADDR(0xffff0000) +#define IN_CLASSB_NSHIFT 16 +#define IN_CLASSB_HOST __IPADDR(0x0000ffff) +#define IN_CLASSB_MAX 65536 + +#define IN_CLASSC(i) (((u_int32_t)(i) & __IPADDR(0xe0000000)) == \ + __IPADDR(0xc0000000)) +#define IN_CLASSC_NET __IPADDR(0xffffff00) +#define IN_CLASSC_NSHIFT 8 +#define IN_CLASSC_HOST __IPADDR(0x000000ff) + +#define IN_CLASSD(i) (((u_int32_t)(i) & __IPADDR(0xf0000000)) == \ + __IPADDR(0xe0000000)) +/* These ones aren't really net and host fields, but routing needn't know. */ +#define IN_CLASSD_NET __IPADDR(0xf0000000) +#define IN_CLASSD_NSHIFT 28 +#define IN_CLASSD_HOST __IPADDR(0x0fffffff) +#define IN_MULTICAST(i) IN_CLASSD(i) + +#define IN_RFC3021_NET __IPADDR(0xfffffffe) +#define IN_RFC3021_NSHIFT 31 +#define IN_RFC3021_HOST __IPADDR(0x00000001) +#define IN_RFC3021_SUBNET(n) (((u_int32_t)(n) & IN_RFC3021_NET) == \ + IN_RFC3021_NET) + +#define IN_EXPERIMENTAL(i) (((u_int32_t)(i) & __IPADDR(0xf0000000)) == \ + __IPADDR(0xf0000000)) +#define IN_BADCLASS(i) (((u_int32_t)(i) & __IPADDR(0xf0000000)) == \ + __IPADDR(0xf0000000)) + +#define IN_LOCAL_GROUP(i) (((u_int32_t)(i) & __IPADDR(0xffffff00)) == \ + __IPADDR(0xe0000000)) + +#ifdef _KERNEL +#define IN_CLASSFULBROADCAST(i, b) \ + ((IN_CLASSC(b) && (b | IN_CLASSC_HOST) == i) || \ + (IN_CLASSB(b) && (b | IN_CLASSB_HOST) == i) || \ + (IN_CLASSA(b) && (b | IN_CLASSA_HOST) == i)) +#endif /* _KERNEL */ + +#define INADDR_ANY __IPADDR(0x00000000) +#define INADDR_LOOPBACK __IPADDR(0x7f000001) +#define INADDR_BROADCAST __IPADDR(0xffffffff) /* must be masked */ +#ifndef _KERNEL +#define INADDR_NONE __IPADDR(0xffffffff) /* -1 return */ +#endif /* _KERNEL */ + +#define INADDR_UNSPEC_GROUP __IPADDR(0xe0000000) /* 224.0.0.0 */ +#define INADDR_ALLHOSTS_GROUP __IPADDR(0xe0000001) /* 224.0.0.1 */ +#define INADDR_ALLROUTERS_GROUP __IPADDR(0xe0000002) /* 224.0.0.2 */ +#define INADDR_CARP_GROUP __IPADDR(0xe0000012) /* 224.0.0.18 */ +#define INADDR_PFSYNC_GROUP __IPADDR(0xe00000f0) /* 224.0.0.240 */ +#define INADDR_MAX_LOCAL_GROUP __IPADDR(0xe00000ff) /* 224.0.0.255 */ + +#define IN_LOOPBACKNET 127 /* official! */ + +/* + * IP Version 4 socket address. + */ +struct sockaddr_in { + u_int8_t sin_len; + sa_family_t sin_family; + in_port_t sin_port; + struct in_addr sin_addr; + int8_t sin_zero[8]; +}; + +/* + * Structure used to describe IP options. + * Used to store options internally, to pass them to a process, + * or to restore options retrieved earlier. + * The ip_dst is used for the first-hop gateway when using a source route + * (this gets put into the header proper). + */ +struct ip_opts { + struct in_addr ip_dst; /* first hop, 0 w/o src rt */ +#if defined(__cplusplus) + int8_t Ip_opts[40]; /* cannot have same name as class */ +#else + int8_t ip_opts[40]; /* actually variable in size */ +#endif /* defined(__cplusplus) */ +}; + +/* + * Options for use with [gs]etsockopt at the IP level. + * First word of comment is data type; bool is stored in int. + */ +#define IP_OPTIONS 1 /* buf/ip_opts; set/get IP options */ +#define IP_HDRINCL 2 /* int; header is included with data */ +#define IP_TOS 3 /* int; IP type of service and preced. */ +#define IP_TTL 4 /* int; IP time to live */ +#define IP_RECVOPTS 5 /* bool; receive all IP opts w/dgram */ +#define IP_RECVRETOPTS 6 /* bool; receive IP opts for response */ +#define IP_RECVDSTADDR 7 /* bool; receive IP dst addr w/dgram */ +#define IP_RETOPTS 8 /* ip_opts; set/get IP options */ +#define IP_MULTICAST_IF 9 /* in_addr; set/get IP multicast i/f */ +#define IP_MULTICAST_TTL 10 /* u_char; set/get IP multicast ttl */ +#define IP_MULTICAST_LOOP 11 /* u_char; set/get IP multicast loopback */ +#define IP_ADD_MEMBERSHIP 12 /* ip_mreq; add an IP group membership */ +#define IP_DROP_MEMBERSHIP 13 /* ip_mreq; drop an IP group membership */ +#define IP_PORTRANGE 19 /* int; range to choose for unspec port */ +#define IP_AUTH_LEVEL 20 /* int; authentication used */ +#define IP_ESP_TRANS_LEVEL 21 /* int; transport encryption */ +#define IP_ESP_NETWORK_LEVEL 22 /* int; full-packet encryption */ +#define IP_IPSEC_LOCAL_ID 23 /* buf; IPsec local ID */ +#define IP_IPSEC_REMOTE_ID 24 /* buf; IPsec remote ID */ +#define IP_IPSEC_LOCAL_CRED 25 /* buf; was: IPsec local credentials */ +#define IP_IPSEC_REMOTE_CRED 26 /* buf; was: IPsec remote credentials */ +#define IP_IPSEC_LOCAL_AUTH 27 /* buf; was: IPsec local auth material */ +#define IP_IPSEC_REMOTE_AUTH 28 /* buf; was: IPsec remote auth material */ +#define IP_IPCOMP_LEVEL 29 /* int; compression used */ +#define IP_RECVIF 30 /* bool; receive reception if w/dgram */ +#define IP_RECVTTL 31 /* bool; receive IP TTL w/dgram */ +#define IP_MINTTL 32 /* minimum TTL for packet or drop */ +#define IP_RECVDSTPORT 33 /* bool; receive IP dst port w/dgram */ +#define IP_PIPEX 34 /* bool; using PIPEX */ +#define IP_RECVRTABLE 35 /* bool; receive rdomain w/dgram */ +#define IP_IPSECFLOWINFO 36 /* bool; IPsec flow info for dgram */ +#define IP_IPDEFTTL 37 /* int; IP TTL system default */ +#define IP_SENDSRCADDR IP_RECVDSTADDR /* struct in_addr; */ + /* source address to use */ + +#define IP_RTABLE 0x1021 /* int; routing table, see SO_RTABLE */ + +#if __BSD_VISIBLE +/* + * Security levels - IPsec, not IPSO + */ + +#define IPSEC_LEVEL_BYPASS 0x00 /* Bypass policy altogether */ +#define IPSEC_LEVEL_NONE 0x00 /* Send clear, accept any */ +#define IPSEC_LEVEL_AVAIL 0x01 /* Send secure if SA available */ +#define IPSEC_LEVEL_USE 0x02 /* Send secure, accept any */ +#define IPSEC_LEVEL_REQUIRE 0x03 /* Require secure inbound, also use */ +#define IPSEC_LEVEL_UNIQUE 0x04 /* Use outbound SA that is unique */ +#define IPSEC_LEVEL_DEFAULT IPSEC_LEVEL_AVAIL + +#define IPSEC_AUTH_LEVEL_DEFAULT IPSEC_LEVEL_DEFAULT +#define IPSEC_ESP_TRANS_LEVEL_DEFAULT IPSEC_LEVEL_DEFAULT +#define IPSEC_ESP_NETWORK_LEVEL_DEFAULT IPSEC_LEVEL_DEFAULT +#define IPSEC_IPCOMP_LEVEL_DEFAULT IPSEC_LEVEL_DEFAULT + +#endif /* __BSD_VISIBLE */ + +/* + * Defaults and limits for options + */ +#define IP_DEFAULT_MULTICAST_TTL 1 /* normally limit m'casts to 1 hop */ +#define IP_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */ +/* + * The imo_membership vector for each socket starts at IP_MIN_MEMBERSHIPS + * and is dynamically allocated at run-time, bounded by IP_MAX_MEMBERSHIPS, + * and is reallocated when needed, sized according to a power-of-two increment. + */ +#define IP_MIN_MEMBERSHIPS 15 +#define IP_MAX_MEMBERSHIPS 4095 + +/* + * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP. + */ +struct ip_mreq { + struct in_addr imr_multiaddr; /* IP multicast address of group */ + struct in_addr imr_interface; /* local IP address of interface */ +}; + +struct ip_mreqn { + struct in_addr imr_multiaddr; /* IP multicast address of group */ + struct in_addr imr_address; /* local IP address of interface */ + int imr_ifindex; /* interface index */ +}; + +/* + * Argument for IP_PORTRANGE: + * - which range to search when port is unspecified at bind() or connect() + */ +#define IP_PORTRANGE_DEFAULT 0 /* default range */ +#define IP_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */ +#define IP_PORTRANGE_LOW 2 /* "low" - vouchsafe security */ + +/* + * Buffer lengths for strings containing printable IP addresses + */ +#ifndef INET_ADDRSTRLEN +#define INET_ADDRSTRLEN 16 +#endif /* INET_ADDRSTRLEN */ + + +#if __BSD_VISIBLE +/* + * Definitions for inet sysctl operations. + * + * Third level is protocol number. + * Fourth level is desired variable within that protocol. + */ +#define IPPROTO_MAXID (IPPROTO_DIVERT + 1) /* don't list to IPPROTO_MAX */ + +#define CTL_IPPROTO_NAMES { \ + { "ip", CTLTYPE_NODE }, \ + { "icmp", CTLTYPE_NODE }, \ + { "igmp", CTLTYPE_NODE }, \ + { "ggp", CTLTYPE_NODE }, \ + { "ipip", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { "tcp", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { "egp", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "pup", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "udp", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "gre", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "esp", CTLTYPE_NODE }, \ + { "ah", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "etherip", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "ipcomp", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "carp", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "pfsync", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "divert", CTLTYPE_NODE }, \ +} + +/* + * Names for IP sysctl objects + */ +#define IPCTL_FORWARDING 1 /* act as router */ +#define IPCTL_SENDREDIRECTS 2 /* may send redirects when forwarding */ +#define IPCTL_DEFTTL 3 /* default TTL */ +#define IPCTL_SOURCEROUTE 5 /* may perform source routes */ +#define IPCTL_DIRECTEDBCAST 6 /* default broadcast behavior */ +#define IPCTL_IPPORT_FIRSTAUTO 7 +#define IPCTL_IPPORT_LASTAUTO 8 +#define IPCTL_IPPORT_HIFIRSTAUTO 9 +#define IPCTL_IPPORT_HILASTAUTO 10 +#define IPCTL_IPPORT_MAXQUEUE 11 +#define IPCTL_ENCDEBUG 12 +#define IPCTL_IPSEC_STATS 13 +#define IPCTL_IPSEC_EXPIRE_ACQUIRE 14 /* How long to wait for key mgmt. */ +#define IPCTL_IPSEC_EMBRYONIC_SA_TIMEOUT 15 /* new SA lifetime */ +#define IPCTL_IPSEC_REQUIRE_PFS 16 +#define IPCTL_IPSEC_SOFT_ALLOCATIONS 17 +#define IPCTL_IPSEC_ALLOCATIONS 18 +#define IPCTL_IPSEC_SOFT_BYTES 19 +#define IPCTL_IPSEC_BYTES 20 +#define IPCTL_IPSEC_TIMEOUT 21 +#define IPCTL_IPSEC_SOFT_TIMEOUT 22 +#define IPCTL_IPSEC_SOFT_FIRSTUSE 23 +#define IPCTL_IPSEC_FIRSTUSE 24 +#define IPCTL_IPSEC_ENC_ALGORITHM 25 +#define IPCTL_IPSEC_AUTH_ALGORITHM 26 +#define IPCTL_MTUDISC 27 /* allow path MTU discovery */ +#define IPCTL_MTUDISCTIMEOUT 28 /* allow path MTU discovery */ +#define IPCTL_IPSEC_IPCOMP_ALGORITHM 29 +#define IPCTL_IFQUEUE 30 +#define IPCTL_MFORWARDING 31 +#define IPCTL_MULTIPATH 32 +#define IPCTL_STATS 33 /* IP statistics */ +#define IPCTL_MRTPROTO 34 /* type of multicast */ +#define IPCTL_MRTSTATS 35 +#define IPCTL_ARPQUEUED 36 +#define IPCTL_MRTMFC 37 +#define IPCTL_MRTVIF 38 +#define IPCTL_ARPTIMEOUT 39 +#define IPCTL_ARPDOWN 40 +#define IPCTL_ARPQUEUE 41 +#define IPCTL_MAXID 42 + +#define IPCTL_NAMES { \ + { 0, 0 }, \ + { "forwarding", CTLTYPE_INT }, \ + { "redirect", CTLTYPE_INT }, \ + { "ttl", CTLTYPE_INT }, \ + /* { "mtu", CTLTYPE_INT }, */ { 0, 0 }, \ + { "sourceroute", CTLTYPE_INT }, \ + { "directed-broadcast", CTLTYPE_INT }, \ + { "portfirst", CTLTYPE_INT }, \ + { "portlast", CTLTYPE_INT }, \ + { "porthifirst", CTLTYPE_INT }, \ + { "porthilast", CTLTYPE_INT }, \ + { "maxqueue", CTLTYPE_INT }, \ + { "encdebug", CTLTYPE_INT }, \ + { 0, 0 /* ipsecstat */ }, \ + { "ipsec-expire-acquire", CTLTYPE_INT }, \ + { "ipsec-invalid-life", CTLTYPE_INT }, \ + { "ipsec-pfs", CTLTYPE_INT }, \ + { "ipsec-soft-allocs", CTLTYPE_INT }, \ + { "ipsec-allocs", CTLTYPE_INT }, \ + { "ipsec-soft-bytes", CTLTYPE_INT }, \ + { "ipsec-bytes", CTLTYPE_INT }, \ + { "ipsec-timeout", CTLTYPE_INT }, \ + { "ipsec-soft-timeout", CTLTYPE_INT }, \ + { "ipsec-soft-firstuse", CTLTYPE_INT }, \ + { "ipsec-firstuse", CTLTYPE_INT }, \ + { "ipsec-enc-alg", CTLTYPE_STRING }, \ + { "ipsec-auth-alg", CTLTYPE_STRING }, \ + { "mtudisc", CTLTYPE_INT }, \ + { "mtudisctimeout", CTLTYPE_INT }, \ + { "ipsec-comp-alg", CTLTYPE_STRING }, \ + { "ifq", CTLTYPE_NODE }, \ + { "mforwarding", CTLTYPE_INT }, \ + { "multipath", CTLTYPE_INT }, \ + { "stats", CTLTYPE_STRUCT }, \ + { "mrtproto", CTLTYPE_INT }, \ + { "mrtstats", CTLTYPE_STRUCT }, \ + { "arpqueued", CTLTYPE_INT }, \ + { "mrtmfc", CTLTYPE_STRUCT }, \ + { "mrtvif", CTLTYPE_STRUCT }, \ + { "arptimeout", CTLTYPE_INT }, \ + { "arpdown", CTLTYPE_INT }, \ + { "arpq", CTLTYPE_NODE }, \ +} + +#endif /* __BSD_VISIBLE */ + +/* INET6 stuff */ +#define __KAME_NETINET_IN_H_INCLUDED_ +#include +#undef __KAME_NETINET_IN_H_INCLUDED_ + +#ifndef _KERNEL +#if __BSD_VISIBLE +__BEGIN_DECLS +int bindresvport(int, struct sockaddr_in *); +struct sockaddr; +int bindresvport_sa(int, struct sockaddr *); +__END_DECLS +#endif /* __BSD_VISIBLE */ +#endif /* !_KERNEL */ + +#ifdef _KERNEL +extern const u_char inetctlerrmap[]; +extern const struct in_addr zeroin_addr; + +struct mbuf; +struct sockaddr; +struct sockaddr_in; +struct ifaddr; +struct in_ifaddr; +struct route; +struct netstack; + +void ipv4_input(struct ifnet *, struct mbuf *, struct netstack *); +struct mbuf * + ipv4_check(struct ifnet *, struct mbuf *); + +int in_broadcast(struct in_addr, u_int); +int in_canforward(struct in_addr); +int in_cksum(struct mbuf *, int); +int in4_cksum(struct mbuf *, u_int8_t, int, int); +void in_hdr_cksum_out(struct mbuf *, struct ifnet *); +void in_proto_cksum_out(struct mbuf *, struct ifnet *); +int in_ifcap_cksum(struct mbuf *, struct ifnet *, int); +void in_ifdetach(struct ifnet *); +int in_mask2len(struct in_addr *); +void in_len2mask(struct in_addr *, int); +int in_nam2sin(const struct mbuf *, struct sockaddr_in **); +int in_sa2sin(struct sockaddr *, struct sockaddr_in **); + +char *inet_ntoa(struct in_addr); +int inet_nat64(int, const void *, void *, const void *, u_int8_t); +int inet_nat46(int, const void *, void *, const void *, u_int8_t); + +const char *inet_ntop(int, const void *, char *, socklen_t); +const char *sockaddr_ntop(struct sockaddr *, char *, size_t); + +#define in_hosteq(s,t) ((s).s_addr == (t).s_addr) +#define in_nullhost(x) ((x).s_addr == INADDR_ANY) + +/* + * Convert between address family specific and general structs. + * Inline functions check the source type and are stricter than + * casts or defines. + */ + +static inline struct sockaddr_in * +satosin(struct sockaddr *sa) +{ + return ((struct sockaddr_in *)(sa)); +} + +static inline const struct sockaddr_in * +satosin_const(const struct sockaddr *sa) +{ + return ((const struct sockaddr_in *)(sa)); +} + +static inline struct sockaddr * +sintosa(struct sockaddr_in *sin) +{ + return ((struct sockaddr *)(sin)); +} + +static inline struct in_ifaddr * +ifatoia(struct ifaddr *ifa) +{ + return ((struct in_ifaddr *)(ifa)); +} +#endif /* _KERNEL */ +#endif /* _NETINET_IN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/in_pcb.h b/lib/libc/include/generic-openbsd/netinet/in_pcb.h new file mode 100644 index 0000000000..8bf9271b74 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/in_pcb.h @@ -0,0 +1,383 @@ +/* $OpenBSD: in_pcb.h,v 1.171 2025/07/14 09:01:52 jsg Exp $ */ +/* $NetBSD: in_pcb.h,v 1.14 1996/02/13 23:42:00 christos Exp $ */ + +/* + * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. + * 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 project 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 PROJECT 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 PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Copyright (c) 1982, 1986, 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)in_pcb.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NETINET_IN_PCB_H_ +#define _NETINET_IN_PCB_H_ + +#include +#include +#include +#include +#include +#include +#include + +#include + +/* + * Locks used to protect struct members in this file: + * I immutable after creation + * N net lock + * t inpt_mtx pcb table mutex + * L pf_inp_mtx link pf to inp mutex + * s so_lock socket rwlock + */ + +/* + * The pcb table mutex guarantees that all inpcb are consistent and + * that bind(2) and connect(2) create unique combinations of + * laddr/faddr/lport/fport/rtableid. This mutex is used to protect + * both address consistency and inpcb lookup during protocol input. + * All writes to inp_[lf]addr take table mutex. A per socket lock is + * needed, so that socket layer input have a consistent view at these + * values. + * + * In soconnect() and sosend() a per pcb mutex cannot be used. They + * eventually call IP output which takes pf lock which is a sleeping lock. + * Also connect(2) does a route lookup for source selection. There + * route resolve happens, which creates a route, which sends a route + * message, which needs route lock, which is a rw-lock. + * + * On the other hand a mutex should be used in protocol input. It + * does not make sense to do a process switch per packet. Better spin + * until the packet can be processed. + * + * So there are three locks. Table mutex is for writing inp_[lf]addr/port + * and lookup, socket rw-lock to separate sockets in system calls, and + * socket buffer mutex to protect socket receive buffer. Changing + * inp_[lf]addr/port takes both per socket rw-lock and global table mutex. + * Protocol input only reads inp_[lf]addr/port during lookup and is safe. + */ + +struct pf_state_key; + +union inpaddru { + struct in_addr iau_addr; + struct in6_addr iau_addr6; +}; + +/* + * Common structure pcb for internet protocol implementation. + * Here are stored pointers to local and foreign host table + * entries, local and foreign socket numbers, and pointers + * up (to a socket structure) and down (to a protocol-specific) + * control block. + */ +struct inpcb { + struct inpcbtable *inp_table; /* [I] inet queue/hash table */ + TAILQ_ENTRY(inpcb) inp_queue; /* [t] inet PCB queue */ + /* keep fields above in sync with struct inpcb_iterator */ + LIST_ENTRY(inpcb) inp_hash; /* [t] local and foreign hash */ + LIST_ENTRY(inpcb) inp_lhash; /* [t] local port hash */ + union inpaddru inp_faddru; /* [t] Foreign address. */ + union inpaddru inp_laddru; /* [t] Local address. */ +#define inp_faddr inp_faddru.iau_addr +#define inp_faddr6 inp_faddru.iau_addr6 +#define inp_laddr inp_laddru.iau_addr +#define inp_laddr6 inp_laddru.iau_addr6 + u_int16_t inp_fport; /* [t] foreign port */ + u_int16_t inp_lport; /* [t] local port */ + struct socket *inp_socket; /* [I] back pointer to socket */ + caddr_t inp_ppcb; /* [s] pointer to per-protocol pcb */ + struct route inp_route; /* [s] cached route */ + struct refcnt inp_refcnt; /* refcount PCB, delay memory free */ + int inp_flags; /* generic IP/datagram flags */ + union { /* Header prototype. */ + struct ip hu_ip; + struct ip6_hdr hu_ipv6; + } inp_hu; +#define inp_ip inp_hu.hu_ip +#define inp_ipv6 inp_hu.hu_ipv6 + union { + struct mbuf *inp_options; /* IPv4 options */ + struct ip6_pktopts *inp_outputopts6; /* IPv6 options */ + }; + int inp_hops; + union { + struct ip_moptions *mou_mo; + struct ip6_moptions *mou_mo6; + } inp_mou; +#define inp_moptions inp_mou.mou_mo /* [N] IPv4 multicast options */ +#define inp_moptions6 inp_mou.mou_mo6 /* [N] IPv6 multicast options */ + struct ipsec_level inp_seclevel; /* [N] IPsec level of socket */ + u_char inp_ip_minttl; /* minimum TTL or drop */ +#define inp_ip6_minhlim inp_ip_minttl /* minimum Hop Limit or drop */ +#define inp_flowinfo inp_hu.hu_ipv6.ip6_flow + + int inp_cksum6; + struct icmp6_filter *inp_icmp6filt; + struct pf_state_key *inp_pf_sk; /* [L] */ + struct mbuf *(*inp_upcall)(void *, struct mbuf *, + struct ip *, struct ip6_hdr *, void *, int, struct netstack *); + void *inp_upcall_arg; + u_int inp_rtableid; /* [t] */ + int inp_pipex; /* pipex indication */ + uint16_t inp_flowid; /* [s] */ +}; + +LIST_HEAD(inpcbhead, inpcb); + +struct inpcb_iterator { + struct inpcbtable *inp_table; /* [I] always NULL */ + TAILQ_ENTRY(inpcb) inp_queue; /* [t] inet PCB queue */ + /* keep fields above in sync with struct inpcb */ +}; + +static inline int +in_pcb_is_iterator(struct inpcb *inp) +{ + return (inp->inp_table == NULL ? 1 : 0); +} + +struct inpcbtable { + struct mutex inpt_mtx; /* protect queue and hash */ + TAILQ_HEAD(inpthead, inpcb) inpt_queue; /* [t] inet PCB queue */ + struct inpcbhead *inpt_hashtbl; /* [t] local and foreign hash */ + struct inpcbhead *inpt_lhashtbl; /* [t] local port hash */ + SIPHASH_KEY inpt_key, inpt_lkey; /* [I] secrets for hashes */ + u_long inpt_mask, inpt_lmask; /* [t] hash masks */ + int inpt_count, inpt_size; /* [t] queue count, hash size */ +}; + +/* flags in inp_flags: */ +#define INP_RECVOPTS 0x001 /* receive incoming IP options */ +#define INP_RECVRETOPTS 0x002 /* receive IP options for reply */ +#define INP_RECVDSTADDR 0x004 /* receive IP dst address */ + +#define INP_RXDSTOPTS INP_RECVOPTS +#define INP_RXHOPOPTS INP_RECVRETOPTS +#define INP_RXINFO INP_RECVDSTADDR +#define INP_RXSRCRT 0x010 +#define INP_HOPLIMIT 0x020 + +#define INP_HDRINCL 0x008 /* user supplies entire IP header */ +#define INP_HIGHPORT 0x010 /* user wants "high" port binding */ +#define INP_LOWPORT 0x020 /* user wants "low" port binding */ +#define INP_RECVIF 0x080 /* receive incoming interface */ +#define INP_RECVTTL 0x040 /* receive incoming IP TTL */ +#define INP_RECVDSTPORT 0x200 /* receive IP dst addr before rdr */ +#define INP_RECVRTABLE 0x400 /* receive routing table */ +#define INP_IPSECFLOWINFO 0x800 /* receive IPsec flow info */ + +#define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR| \ + INP_RXSRCRT|INP_HOPLIMIT|INP_RECVIF|INP_RECVTTL|INP_RECVDSTPORT| \ + INP_RECVRTABLE) + +/* + * These flags' values should be determined by either the transport + * protocol at PRU_BIND, PRU_LISTEN, PRU_CONNECT, etc, or by in_pcb*(). + */ +#define INP_IPV6 0x100 /* socket, proto, domain, family is PF_INET6 */ + +/* + * Flags in inp_flags for IPV6 + */ +#define IN6P_HIGHPORT INP_HIGHPORT /* user wants "high" port */ +#define IN6P_LOWPORT INP_LOWPORT /* user wants "low" port */ +#define IN6P_RECVDSTPORT INP_RECVDSTPORT /* receive IP dst addr before rdr */ +#define IN6P_PKTINFO 0x010000 /* receive IP6 dst and I/F */ +#define IN6P_HOPLIMIT 0x020000 /* receive hoplimit */ +#define IN6P_HOPOPTS 0x040000 /* receive hop-by-hop options */ +#define IN6P_DSTOPTS 0x080000 /* receive dst options after rthdr */ +#define IN6P_RTHDR 0x100000 /* receive routing header */ +#define IN6P_TCLASS 0x400000 /* receive traffic class value */ +#define IN6P_AUTOFLOWLABEL 0x800000 /* attach flowlabel automatically */ + +#define IN6P_ANONPORT 0x4000000 /* port chosen for user */ +#define IN6P_RFC2292 0x40000000 /* used RFC2292 API on the socket */ +#define IN6P_MTU 0x80000000 /* receive path MTU */ + +#define IN6P_MINMTU 0x20000000 /* use minimum MTU */ + +#define IN6P_CONTROLOPTS (IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\ + IN6P_DSTOPTS|IN6P_RTHDR|\ + IN6P_TCLASS|IN6P_AUTOFLOWLABEL|IN6P_RFC2292|\ + IN6P_MTU|IN6P_RECVDSTPORT) + +#define INPLOOKUP_WILDCARD 1 +#define INPLOOKUP_SETLOCAL 2 +#define INPLOOKUP_IPV6 4 + +#define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb) + +/* macros for handling bitmap of ports not to allocate dynamically */ +#define DP_MAPBITS (sizeof(u_int32_t) * NBBY) +#define DP_MAPSIZE (howmany(65536, DP_MAPBITS)) +#define DP_SET(m, p) ((m)[(p) / DP_MAPBITS] |= (1U << ((p) % DP_MAPBITS))) +#define DP_CLR(m, p) ((m)[(p) / DP_MAPBITS] &= ~(1U << ((p) % DP_MAPBITS))) +#define DP_ISSET(m, p) ((m)[(p) / DP_MAPBITS] & (1U << ((p) % DP_MAPBITS))) + +/* default values for baddynamicports [see ip_init()] */ +#define DEFBADDYNAMICPORTS_TCP { \ + 587, 749, 750, 751, 853, 871, 2049, \ + 6000, 6001, 6002, 6003, 6004, 6005, 6006, 6007, 6008, 6009, 6010, \ + 0 } +#define DEFBADDYNAMICPORTS_UDP { 623, 664, 749, 750, 751, 2049, \ + 3784, 3785, 7784, /* BFD/S-BFD ports */ \ + 0 } + +#define DEFROOTONLYPORTS_TCP { \ + 2049, \ + 0 } +#define DEFROOTONLYPORTS_UDP { \ + 2049, \ + 0 } + +struct baddynamicports { + u_int32_t tcp[DP_MAPSIZE]; + u_int32_t udp[DP_MAPSIZE]; +}; + +#ifdef _KERNEL + +#define IN_PCBLOCK_HOLD 1 +#define IN_PCBLOCK_GRAB 2 + +extern struct inpcbtable rawcbtable, rawin6pcbtable; +extern struct baddynamicports baddynamicports; +extern struct baddynamicports rootonlyports; +extern int in_pcbnotifymiss; + +void in_init(void); +void in_losing(struct inpcb *); +int in_pcballoc(struct socket *, struct inpcbtable *, int); +int in_pcbbind_locked(struct inpcb *, struct mbuf *, const void *, + struct proc *); +int in_pcbbind(struct inpcb *, struct mbuf *, struct proc *); +int in_pcbaddrisavail(const struct inpcb *, struct sockaddr_in *, int, + struct proc *); +int in_pcbconnect(struct inpcb *, struct mbuf *); +void in_pcbdetach(struct inpcb *); +struct socket * + in_pcbsolock(struct inpcb *); +void in_pcbsounlock(struct inpcb *, struct socket *); +struct inpcb * + in_pcbref(struct inpcb *); +void in_pcbunref(struct inpcb *); +void in_pcbdisconnect(struct inpcb *); +struct inpcb * + in_pcb_iterator(struct inpcbtable *, struct inpcb *, + struct inpcb_iterator *); +void in_pcb_iterator_abort(struct inpcbtable *, struct inpcb *, + struct inpcb_iterator *); +struct inpcb * + in_pcblookup(struct inpcbtable *, struct in_addr, u_int, + struct in_addr, u_int, u_int); +struct inpcb * + in_pcblookup_listen(struct inpcbtable *, struct in_addr, u_int, + struct mbuf *, u_int); +#ifdef INET6 +uint64_t in6_pcbhash(struct inpcbtable *, u_int, const struct in6_addr *, + u_short, const struct in6_addr *, u_short); +struct inpcb * + in6_pcblookup(struct inpcbtable *, const struct in6_addr *, + u_int, const struct in6_addr *, u_int, u_int); +struct inpcb * + in6_pcblookup_listen(struct inpcbtable *, struct in6_addr *, u_int, + struct mbuf *, u_int); +int in6_pcbaddrisavail_lock(const struct inpcb *, struct sockaddr_in6 *, + int, struct proc *, int); +int in6_pcbaddrisavail(const struct inpcb *, struct sockaddr_in6 *, int, + struct proc *); +int in6_pcbconnect(struct inpcb *, struct mbuf *); +void in6_setsockaddr(struct inpcb *, struct mbuf *); +void in6_setpeeraddr(struct inpcb *, struct mbuf *); +int in6_sockaddr(struct socket *, struct mbuf *); +int in6_peeraddr(struct socket *, struct mbuf *); +#endif /* INET6 */ +void in_pcbinit(struct inpcbtable *, int); +struct inpcb * + in_pcblookup_local_lock(struct inpcbtable *, const void *, u_int, int, + u_int, int); +void in_pcbnotifyall(struct inpcbtable *, const struct sockaddr_in *, + u_int, int, void (*)(struct inpcb *, int)); +void in_pcbrehash(struct inpcb *); +void in_pcbrtchange(struct inpcb *, int); +void in_setpeeraddr(struct inpcb *, struct mbuf *); +void in_setsockaddr(struct inpcb *, struct mbuf *); +int in_sockaddr(struct socket *, struct mbuf *); +int in_peeraddr(struct socket *, struct mbuf *); +int in_baddynamic(u_int16_t, u_int16_t); +int in_rootonly(u_int16_t, u_int16_t); +int in_pcbselsrc(struct in_addr *, const struct sockaddr_in *, + struct inpcb *); +struct rtentry * + in_pcbrtentry(struct inpcb *); + +/* INET6 stuff */ +struct rtentry * + in6_pcbrtentry(struct inpcb *); +void in6_pcbnotify(struct inpcbtable *, const struct sockaddr_in6 *, + u_int, const struct sockaddr_in6 *, u_int, u_int, int, void *, + void (*)(struct inpcb *, int)); +int in6_selecthlim(const struct inpcb *); +int in_pcbset_rtableid(struct inpcb *, u_int); +int in_pcbset_addr(struct inpcb *, const struct sockaddr *, + const struct sockaddr *, u_int); +int in6_pcbset_addr(struct inpcb *, const struct sockaddr_in6 *, + const struct sockaddr_in6 *, u_int); +void in_pcbunset_faddr(struct inpcb *); +void in_pcbunset_laddr(struct inpcb *); + +#endif /* _KERNEL */ +#endif /* _NETINET_IN_PCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/in_systm.h b/lib/libc/include/generic-openbsd/netinet/in_systm.h new file mode 100644 index 0000000000..0cab0c1e90 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/in_systm.h @@ -0,0 +1,47 @@ +/* $OpenBSD: in_systm.h,v 1.7 2014/07/13 13:57:56 mpi Exp $ */ +/* $NetBSD: in_systm.h,v 1.8 1995/04/13 06:29:22 cgd Exp $ */ + +/* + * Copyright (c) 1982, 1986, 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. + * + * @(#)in_systm.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NETINET_IN_SYSTM_H_ +#define _NETINET_IN_SYSTM_H_ + +/* network byte order */ +typedef u_int16_t n_short; +typedef u_int32_t n_long; +typedef u_int32_t n_time; /* ms since 00:00 GMT */ + +#ifdef _KERNEL +u_int32_t iptime(void); +#endif /* _KERNEL */ + +#endif /* _NETINET_IN_SYSTM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/in_var.h b/lib/libc/include/generic-openbsd/netinet/in_var.h new file mode 100644 index 0000000000..9a419c296b --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/in_var.h @@ -0,0 +1,166 @@ +/* $OpenBSD: in_var.h,v 1.41 2018/10/18 15:23:04 cheloha Exp $ */ +/* $NetBSD: in_var.h,v 1.16 1996/02/13 23:42:15 christos Exp $ */ + +/* + * Copyright (c) 1985, 1986, 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. + * + * @(#)in_var.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NETINET_IN_VAR_H_ +#define _NETINET_IN_VAR_H_ + +#include + +#ifdef _KERNEL +/* + * Interface address, Internet version. One of these structures + * is allocated for each interface with an Internet address. + * The ifaddr structure contains the protocol-independent part + * of the structure and is assumed to be first. + */ +struct in_ifaddr { + struct ifaddr ia_ifa; /* protocol-independent info */ +#define ia_ifp ia_ifa.ifa_ifp +#define ia_flags ia_ifa.ifa_flags + /* ia_net{,mask} in host order */ + u_int32_t ia_net; /* network number of interface */ + u_int32_t ia_netmask; /* mask of net part */ + TAILQ_ENTRY(in_ifaddr) ia_list; /* list of internet addresses */ + struct sockaddr_in ia_addr; /* reserve space for interface name */ + struct sockaddr_in ia_dstaddr; /* reserve space for broadcast addr */ +#define ia_broadaddr ia_dstaddr + struct sockaddr_in ia_sockmask; /* reserve space for general netmask */ + struct in_multi *ia_allhosts; /* multicast address record for + the allhosts multicast group */ +}; +#endif + +struct in_aliasreq { + char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */ + union { + struct sockaddr_in ifrau_addr; + int ifrau_align; + } ifra_ifrau; +#ifndef ifra_addr +#define ifra_addr ifra_ifrau.ifrau_addr +#endif + struct sockaddr_in ifra_dstaddr; +#define ifra_broadaddr ifra_dstaddr + struct sockaddr_in ifra_mask; +}; + + +#ifdef _KERNEL +/* + * Macro for finding the internet address structure (in_ifaddr) corresponding + * to a given interface (ifnet structure). + */ +#define IFP_TO_IA(ifp, ia) \ + /* struct ifnet *ifp; */ \ + /* struct in_ifaddr *ia; */ \ +do { \ + struct ifaddr *ifa; \ + NET_ASSERT_LOCKED(); \ + TAILQ_FOREACH(ifa, &(ifp)->if_addrlist, ifa_list) { \ + if (ifa->ifa_addr->sa_family == AF_INET) \ + break; \ + } \ + (ia) = ifatoia(ifa); \ +} while (/* CONSTCOND */ 0) +#endif + +/* + * Per-interface router version information. + */ +struct router_info { + unsigned int rti_ifidx; + int rti_type; /* type of router on this interface */ + int rti_age; /* time since last v1 query */ + LIST_ENTRY(router_info) rti_list; +}; + +#ifdef _KERNEL +/* + * Internet multicast address structure. There is one of these for each IP + * multicast group to which this host belongs on a given network interface. + */ +struct in_multi { + struct ifmaddr inm_ifma; /* Protocol-independent info */ +#define inm_refcnt inm_ifma.ifma_refcnt +#define inm_ifidx inm_ifma.ifma_ifidx + + struct sockaddr_in inm_sin; /* IPv4 multicast address */ +#define inm_addr inm_sin.sin_addr + + u_int inm_state; /* state of membership */ + u_int inm_timer; /* IGMP membership report timer */ + + struct router_info *inm_rti; /* router version info */ +}; + +static __inline struct in_multi * +ifmatoinm(struct ifmaddr *ifma) +{ + return ((struct in_multi *)(ifma)); +} + +/* + * Macro for looking up the in_multi record for a given IP multicast + * address on a given interface. If no matching record is found, "inm" + * returns NULL. + */ +#define IN_LOOKUP_MULTI(addr, ifp, inm) \ + /* struct in_addr addr; */ \ + /* struct ifnet *ifp; */ \ + /* struct in_multi *inm; */ \ +do { \ + struct ifmaddr *ifma; \ + \ + (inm) = NULL; \ + NET_ASSERT_LOCKED(); \ + TAILQ_FOREACH(ifma, &(ifp)->if_maddrlist, ifma_list) \ + if (ifma->ifma_addr->sa_family == AF_INET && \ + ifmatoinm(ifma)->inm_addr.s_addr == (addr).s_addr) {\ + (inm) = ifmatoinm(ifma); \ + break; \ + } \ +} while (/* CONSTCOND */ 0) + +int in_ifinit(struct ifnet *, + struct in_ifaddr *, struct sockaddr_in *, int); +struct in_multi *in_addmulti(struct in_addr *, struct ifnet *); +void in_delmulti(struct in_multi *); +int in_hasmulti(struct in_addr *, struct ifnet *); +void in_ifscrub(struct ifnet *, struct in_ifaddr *); +int in_control(struct socket *, u_long, caddr_t, struct ifnet *); +int in_ioctl(u_long, caddr_t, struct ifnet *, int); +void in_prefixlen2mask(struct in_addr *, int); +#endif + +#endif /* _NETINET_IN_VAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/ip.h b/lib/libc/include/generic-openbsd/netinet/ip.h new file mode 100644 index 0000000000..d4668ac424 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/ip.h @@ -0,0 +1,233 @@ +/* $OpenBSD: ip.h,v 1.20 2021/12/14 23:47:36 dtucker Exp $ */ +/* $NetBSD: ip.h,v 1.9 1995/05/15 01:22:44 cgd Exp $ */ + +/* + * Copyright (c) 1982, 1986, 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. + * + * @(#)ip.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NETINET_IP_H_ +#define _NETINET_IP_H_ + +/* + * Definitions for internet protocol version 4. + * Per RFC 791, September 1981. + */ +#define IPVERSION 4 + +/* + * Structure of an internet header, naked of options. + */ +struct ip { +#if _BYTE_ORDER == _LITTLE_ENDIAN + u_int ip_hl:4, /* header length */ + ip_v:4; /* version */ +#endif +#if _BYTE_ORDER == _BIG_ENDIAN + u_int ip_v:4, /* version */ + ip_hl:4; /* header length */ +#endif + u_int8_t ip_tos; /* type of service */ + u_int16_t ip_len; /* total length */ + u_int16_t ip_id; /* identification */ + u_int16_t ip_off; /* fragment offset field */ +#define IP_RF 0x8000 /* reserved fragment flag */ +#define IP_DF 0x4000 /* dont fragment flag */ +#define IP_MF 0x2000 /* more fragments flag */ +#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ + u_int8_t ip_ttl; /* time to live */ + u_int8_t ip_p; /* protocol */ + u_int16_t ip_sum; /* checksum */ + struct in_addr ip_src, ip_dst; /* source and dest address */ +}; + +#define IP_MAXPACKET 65535 /* maximum packet size */ + +/* + * Definitions for IP type of service (ip_tos) + */ +#define IPTOS_LOWDELAY 0x10 +#define IPTOS_THROUGHPUT 0x08 +#define IPTOS_RELIABILITY 0x04 +/* IPTOS_LOWCOST 0x02 XXX */ +#if 1 +/* ECN RFC3168 obsoletes RFC2481, and these will be deprecated soon. */ +#define IPTOS_CE 0x01 /* congestion experienced */ +#define IPTOS_ECT 0x02 /* ECN-capable transport */ +#endif + +/* + * Definitions for IP precedence (also in ip_tos) (hopefully unused) + */ +#define IPTOS_PREC_NETCONTROL 0xe0 +#define IPTOS_PREC_INTERNETCONTROL 0xc0 +#define IPTOS_PREC_CRITIC_ECP 0xa0 +#define IPTOS_PREC_FLASHOVERRIDE 0x80 +#define IPTOS_PREC_FLASH 0x60 +#define IPTOS_PREC_IMMEDIATE 0x40 +#define IPTOS_PREC_PRIORITY 0x20 +#define IPTOS_PREC_ROUTINE 0x00 + +/* + * Definitions for DiffServ Codepoints as per RFCs 2474, 3246, 4594 & 8622. + * These are the 6 most significant bits as they appear on the wire, so the + * two least significant bits must be zero. + */ +#define IPTOS_DSCP_CS0 0x00 +#define IPTOS_DSCP_LE 0x04 +#define IPTOS_DSCP_CS1 0x20 +#define IPTOS_DSCP_AF11 0x28 +#define IPTOS_DSCP_AF12 0x30 +#define IPTOS_DSCP_AF13 0x38 +#define IPTOS_DSCP_CS2 0x40 +#define IPTOS_DSCP_AF21 0x48 +#define IPTOS_DSCP_AF22 0x50 +#define IPTOS_DSCP_AF23 0x58 +#define IPTOS_DSCP_CS3 0x60 +#define IPTOS_DSCP_AF31 0x68 +#define IPTOS_DSCP_AF32 0x70 +#define IPTOS_DSCP_AF33 0x78 +#define IPTOS_DSCP_CS4 0x80 +#define IPTOS_DSCP_AF41 0x88 +#define IPTOS_DSCP_AF42 0x90 +#define IPTOS_DSCP_AF43 0x98 +#define IPTOS_DSCP_CS5 0xa0 +#define IPTOS_DSCP_EF 0xb8 +#define IPTOS_DSCP_CS6 0xc0 +#define IPTOS_DSCP_CS7 0xe0 + +/* + * ECN (Explicit Congestion Notification) codepoints in RFC3168 + * mapped to the lower 2 bits of the TOS field. + */ +#define IPTOS_ECN_NOTECT 0x00 /* not-ECT */ +#define IPTOS_ECN_ECT1 0x01 /* ECN-capable transport (1) */ +#define IPTOS_ECN_ECT0 0x02 /* ECN-capable transport (0) */ +#define IPTOS_ECN_CE 0x03 /* congestion experienced */ +#define IPTOS_ECN_MASK 0x03 /* ECN field mask */ + +/* + * Definitions for options. + */ +#define IPOPT_COPIED(o) ((o)&0x80) +#define IPOPT_CLASS(o) ((o)&0x60) +#define IPOPT_NUMBER(o) ((o)&0x1f) + +#define IPOPT_CONTROL 0x00 +#define IPOPT_RESERVED1 0x20 +#define IPOPT_DEBMEAS 0x40 +#define IPOPT_RESERVED2 0x60 + +#define IPOPT_EOL 0 /* end of option list */ +#define IPOPT_NOP 1 /* no operation */ + +#define IPOPT_RR 7 /* record packet route */ +#define IPOPT_TS 68 /* timestamp */ +#define IPOPT_SECURITY 130 /* provide s,c,h,tcc */ +#define IPOPT_LSRR 131 /* loose source route */ +#define IPOPT_SATID 136 /* satnet id */ +#define IPOPT_SSRR 137 /* strict source route */ +#define IPOPT_RA 148 /* router alert */ + +/* + * Offsets to fields in options other than EOL and NOP. + */ +#define IPOPT_OPTVAL 0 /* option ID */ +#define IPOPT_OLEN 1 /* option length */ +#define IPOPT_OFFSET 2 /* offset within option */ +#define IPOPT_MINOFF 4 /* min value of above */ + +/* + * Time stamp option structure. + */ +struct ip_timestamp { + u_int8_t ipt_code; /* IPOPT_TS */ + u_int8_t ipt_len; /* size of structure (variable) */ + u_int8_t ipt_ptr; /* index of current entry */ +#if _BYTE_ORDER == _LITTLE_ENDIAN + u_int ipt_flg:4, /* flags, see below */ + ipt_oflw:4; /* overflow counter */ +#endif +#if _BYTE_ORDER == _BIG_ENDIAN + u_int ipt_oflw:4, /* overflow counter */ + ipt_flg:4; /* flags, see below */ +#endif + union ipt_timestamp { + u_int32_t ipt_time[1]; + struct ipt_ta { + struct in_addr ipt_addr; + u_int32_t ipt_time; + } ipt_ta[1]; + } ipt_timestamp; +}; + +/* flag bits for ipt_flg */ +#define IPOPT_TS_TSONLY 0 /* timestamps only */ +#define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */ +#define IPOPT_TS_PRESPEC 3 /* specified modules only */ + +/* bits for security (not byte swapped) */ +#define IPOPT_SECUR_UNCLASS 0x0000 +#define IPOPT_SECUR_CONFID 0xf135 +#define IPOPT_SECUR_EFTO 0x789a +#define IPOPT_SECUR_MMMM 0xbc4d +#define IPOPT_SECUR_RESTR 0xaf13 +#define IPOPT_SECUR_SECRET 0xd788 +#define IPOPT_SECUR_TOPSECRET 0x6bc5 + +/* + * Internet implementation parameters. + */ +#define MAXTTL 255 /* maximum time to live (seconds) */ +#define IPDEFTTL 64 /* default ttl, from RFC 1340 */ +#define IPFRAGTTL 60 /* time to live for frags, slowhz */ +#define IPTTLDEC 1 /* subtracted when forwarding */ + +#define IP_MSS 576 /* default maximum segment size */ + +#ifdef _KERNEL + +/* Maximum length for IP protocol queues */ +#define IPQ_MAXLEN 2048 + +/* + * This is the real IPv4 pseudo header, used for computing the TCP and UDP + * checksums. For the Internet checksum, struct ipovly can be used instead. + * For stronger checksums, the real thing must be used. + */ +struct ippseudo { + struct in_addr ippseudo_src; /* source internet address */ + struct in_addr ippseudo_dst; /* destination internet address */ + u_int8_t ippseudo_pad; /* pad, must be zero */ + u_int8_t ippseudo_p; /* protocol */ + u_int16_t ippseudo_len; /* protocol length */ +}; +#endif /* _KERNEL */ + +#endif /* _NETINET_IP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/ip6.h b/lib/libc/include/generic-openbsd/netinet/ip6.h new file mode 100644 index 0000000000..e80ec228cf --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/ip6.h @@ -0,0 +1,293 @@ +/* $OpenBSD: ip6.h,v 1.23 2025/05/27 07:52:49 bluhm Exp $ */ +/* $KAME: ip6.h,v 1.45 2003/06/05 04:46:38 keiichi Exp $ */ + +/* + * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. + * 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 project 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 PROJECT 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 PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Copyright (c) 1982, 1986, 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. + * + * @(#)ip.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NETINET_IP6_H_ +#define _NETINET_IP6_H_ + +/* + * Definition for internet protocol version 6. + * RFC 2460 + */ + +struct ip6_hdr { + union { + struct ip6_hdrctl { + u_int32_t ip6_un1_flow; /* 20 bits of flow-ID */ + u_int16_t ip6_un1_plen; /* payload length */ + u_int8_t ip6_un1_nxt; /* next header */ + u_int8_t ip6_un1_hlim; /* hop limit */ + } ip6_un1; + u_int8_t ip6_un2_vfc; /* 4 bits version, top 4 bits class */ + } ip6_ctlun; + struct in6_addr ip6_src; /* source address */ + struct in6_addr ip6_dst; /* destination address */ +} __packed; + +#define ip6_vfc ip6_ctlun.ip6_un2_vfc +#define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow +#define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen +#define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt +#define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim +#define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim + +#define IPV6_VERSION 0x60 +#define IPV6_VERSION_MASK 0xf0 + +#if _BYTE_ORDER == _BIG_ENDIAN +#define IPV6_FLOWINFO_MASK 0x0fffffff /* flow info (28 bits) */ +#define IPV6_FLOWLABEL_MASK 0x000fffff /* flow label (20 bits) */ +#else +#if _BYTE_ORDER == _LITTLE_ENDIAN +#define IPV6_FLOWINFO_MASK 0xffffff0f /* flow info (28 bits) */ +#define IPV6_FLOWLABEL_MASK 0xffff0f00 /* flow label (20 bits) */ +#endif /* _LITTLE_ENDIAN */ +#endif +#if 1 +/* ECN bits proposed by Sally Floyd */ +#define IP6TOS_CE 0x01 /* congestion experienced */ +#define IP6TOS_ECT 0x02 /* ECN-capable transport */ +#endif + +#ifdef _KERNEL +/* + * for IPv6 pseudo header checksum + * XXX nonstandard + */ +struct ip6_hdr_pseudo { + struct in6_addr ip6ph_src; + struct in6_addr ip6ph_dst; + u_int32_t ip6ph_len; + u_int8_t ip6ph_zero[3]; + u_int8_t ip6ph_nxt; +} __packed; +#endif + +/* + * Extension Headers + */ +struct ip6_ext { + u_int8_t ip6e_nxt; + u_int8_t ip6e_len; +} __packed; + +/* Hop-by-Hop options header */ +/* XXX should we pad it to force alignment on an 8-byte boundary? */ +struct ip6_hbh { + u_int8_t ip6h_nxt; /* next header */ + u_int8_t ip6h_len; /* length in units of 8 octets */ + /* followed by options */ +} __packed; + +/* Destination options header */ +/* XXX should we pad it to force alignment on an 8-byte boundary? */ +struct ip6_dest { + u_int8_t ip6d_nxt; /* next header */ + u_int8_t ip6d_len; /* length in units of 8 octets */ + /* followed by options */ +} __packed; + +/* Option types and related macros */ +#define IP6OPT_PAD1 0x00 /* 00 0 00000 */ +#define IP6OPT_PADN 0x01 /* 00 0 00001 */ +#define IP6OPT_JUMBO 0xC2 /* 11 0 00010 = 194 */ +#define IP6OPT_NSAP_ADDR 0xC3 /* 11 0 00011 */ +#define IP6OPT_TUNNEL_LIMIT 0x04 /* 00 0 00100 */ +#define IP6OPT_ROUTER_ALERT 0x05 /* 00 0 00101 (RFC3542, recommended) */ + +#define IP6OPT_RTALERT_LEN 4 +#define IP6OPT_RTALERT_MLD 0 /* Datagram contains an MLD message */ +#define IP6OPT_RTALERT_RSVP 1 /* Datagram contains an RSVP message */ +#define IP6OPT_RTALERT_ACTNET 2 /* contains an Active Networks msg */ +#define IP6OPT_MINLEN 2 + +#define IP6OPT_TYPE(o) ((o) & 0xC0) +#define IP6OPT_TYPE_SKIP 0x00 +#define IP6OPT_TYPE_DISCARD 0x40 +#define IP6OPT_TYPE_FORCEICMP 0x80 +#define IP6OPT_TYPE_ICMP 0xC0 + +#define IP6OPT_MUTABLE 0x20 + +/* IPv6 options: common part */ +struct ip6_opt { + u_int8_t ip6o_type; + u_int8_t ip6o_len; +} __packed; + +/* Jumbo Payload Option */ +struct ip6_opt_jumbo { + u_int8_t ip6oj_type; + u_int8_t ip6oj_len; + u_int8_t ip6oj_jumbo_len[4]; +} __packed; +#define IP6OPT_JUMBO_LEN 6 + +/* NSAP Address Option */ +struct ip6_opt_nsap { + u_int8_t ip6on_type; + u_int8_t ip6on_len; + u_int8_t ip6on_src_nsap_len; + u_int8_t ip6on_dst_nsap_len; + /* followed by source NSAP */ + /* followed by destination NSAP */ +} __packed; + +/* Tunnel Limit Option */ +struct ip6_opt_tunnel { + u_int8_t ip6ot_type; + u_int8_t ip6ot_len; + u_int8_t ip6ot_encap_limit; +} __packed; + +/* Router Alert Option */ +struct ip6_opt_router { + u_int8_t ip6or_type; + u_int8_t ip6or_len; + u_int8_t ip6or_value[2]; +} __packed; +/* Router alert values (in network byte order) */ +#if _BYTE_ORDER == _BIG_ENDIAN +#define IP6_ALERT_MLD 0x0000 +#define IP6_ALERT_RSVP 0x0001 +#define IP6_ALERT_AN 0x0002 +#else +#if _BYTE_ORDER == _LITTLE_ENDIAN +#define IP6_ALERT_MLD 0x0000 +#define IP6_ALERT_RSVP 0x0100 +#define IP6_ALERT_AN 0x0200 +#endif /* _LITTLE_ENDIAN */ +#endif + +/* Routing header */ +struct ip6_rthdr { + u_int8_t ip6r_nxt; /* next header */ + u_int8_t ip6r_len; /* length in units of 8 octets */ + u_int8_t ip6r_type; /* routing type */ + u_int8_t ip6r_segleft; /* segments left */ + /* followed by routing type specific data */ +} __packed; + +/* Type 0 Routing header */ +struct ip6_rthdr0 { + u_int8_t ip6r0_nxt; /* next header */ + u_int8_t ip6r0_len; /* length in units of 8 octets */ + u_int8_t ip6r0_type; /* always zero */ + u_int8_t ip6r0_segleft; /* segments left */ + u_int32_t ip6r0_reserved; /* reserved field */ +} __packed; + +/* Fragment header */ +struct ip6_frag { + u_int8_t ip6f_nxt; /* next header */ + u_int8_t ip6f_reserved; /* reserved field */ + u_int16_t ip6f_offlg; /* offset, reserved, and flag */ + u_int32_t ip6f_ident; /* identification */ +} __packed; + +#if _BYTE_ORDER == _BIG_ENDIAN +#define IP6F_OFF_MASK 0xfff8 /* mask out offset from _offlg */ +#define IP6F_RESERVED_MASK 0x0006 /* reserved bits in ip6f_offlg */ +#define IP6F_MORE_FRAG 0x0001 /* more-fragments flag */ +#else /* _BYTE_ORDER == _LITTLE_ENDIAN */ +#define IP6F_OFF_MASK 0xf8ff /* mask out offset from _offlg */ +#define IP6F_RESERVED_MASK 0x0600 /* reserved bits in ip6f_offlg */ +#define IP6F_MORE_FRAG 0x0100 /* more-fragments flag */ +#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */ + +/* + * Internet implementation parameters. + */ +#define IPV6_MAXHLIM 255 /* maximum hoplimit */ +#define IPV6_DEFHLIM 64 /* default hlim */ +#define IPV6_FRAGTTL 120 /* ttl for fragment packets, in slowtimo tick */ +#define IPV6_HLIMDEC 1 /* subtracted when forwarding */ + +#define IPV6_MMTU 1280 /* minimal MTU and reassembly. 1024 + 256 */ +#define IPV6_MAXPACKET 65535 /* ip6 max packet size without Jumbo payload*/ + +#ifdef _KERNEL +/* + * ip6_exthdr_get() ensures that intermediate protocol header (from "off" + * to "len") is located in single mbuf, on contiguous memory region. + * The pointer to the region will be returned to pointer variable "val", + * with type "typ". + */ + +static inline void * +ip6_exthdr_get(struct mbuf **mp, int off, int len) +{ + struct mbuf *t; + int toff; + + if ((*mp)->m_len >= off + len) + return (mtod(*mp, caddr_t) + off); + + t = m_pulldown(*mp, off, len, &toff); + if (t == NULL) { + *mp = NULL; + return (NULL); + } + return (mtod(t, caddr_t) + toff); +} +#endif /* _KERNEL */ +#endif /* _NETINET_IP6_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/ip_ah.h b/lib/libc/include/generic-openbsd/netinet/ip_ah.h new file mode 100644 index 0000000000..7252eb68d4 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/ip_ah.h @@ -0,0 +1,134 @@ +/* $OpenBSD: ip_ah.h,v 1.37 2020/09/01 01:53:34 gnezdo Exp $ */ +/* + * The authors of this code are John Ioannidis (ji@tla.org), + * Angelos D. Keromytis (kermit@csd.uch.gr) and + * Niels Provos (provos@physnet.uni-hamburg.de). + * + * The original version of this code was written by John Ioannidis + * for BSD/OS in Athens, Greece, in November 1995. + * + * Ported to OpenBSD and NetBSD, with additional transforms, in December 1996, + * by Angelos D. Keromytis. + * + * Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis + * and Niels Provos. + * + * Additional features in 1999 by Angelos D. Keromytis. + * + * Copyright (C) 1995, 1996, 1997, 1998, 1999 John Ioannidis, + * Angelos D. Keromytis and Niels Provos. + * Copyright (c) 2001 Angelos D. Keromytis. + * + * Permission to use, copy, and modify this software with or without fee + * is hereby granted, provided that this entire notice is included in + * all copies of any software which is or includes a copy or + * modification of this software. + * You may use this code under the GNU public license if you so wish. Please + * contribute changes back to the authors under this freer than GPL license + * so that we may further the use of strong encryption without limitations to + * all. + * + * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY + * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE + * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR + * PURPOSE. + */ + +#ifndef _NETINET_IP_AH_H_ +#define _NETINET_IP_AH_H_ + +struct ahstat { + uint64_t ahs_hdrops; /* Packet shorter than header shows */ + uint64_t ahs_nopf; /* Protocol family not supported */ + uint64_t ahs_notdb; + uint64_t ahs_badkcr; + uint64_t ahs_badauth; + uint64_t ahs_noxform; + uint64_t ahs_qfull; + uint64_t ahs_wrap; + uint64_t ahs_replay; + uint64_t ahs_badauthl; /* Bad authenticator length */ + uint64_t ahs_input; /* Input AH packets */ + uint64_t ahs_output; /* Output AH packets */ + uint64_t ahs_invalid; /* Trying to use an invalid TDB */ + uint64_t ahs_ibytes; /* Input bytes */ + uint64_t ahs_obytes; /* Output bytes */ + uint64_t ahs_toobig; /* Packet got larger than + * IP_MAXPACKET */ + uint64_t ahs_pdrops; /* Packet blocked due to policy */ + uint64_t ahs_crypto; /* Crypto processing failure */ + uint64_t ahs_outfail; /* Packet output failure */ +}; + +struct ah { + u_int8_t ah_nh; + u_int8_t ah_hl; + u_int16_t ah_rv; + u_int32_t ah_spi; + u_int32_t ah_rpl; /* We may not use this, if we're using old xforms */ +}; + +/* Length of base AH header */ +#define AH_FLENGTH 8 + +/* + * Names for AH sysctl objects + */ +#define AHCTL_ENABLE 1 /* Enable AH processing */ +#define AHCTL_STATS 2 /* AH stats */ +#define AHCTL_MAXID 3 + +#define AHCTL_NAMES { \ + { 0, 0 }, \ + { "enable", CTLTYPE_INT }, \ + { "stats", CTLTYPE_STRUCT } \ +} + +#ifdef _KERNEL + +#include + +enum ahstat_counters { + ahs_hdrops, /* Packet shorter than header shows */ + ahs_nopf, /* Protocol family not supported */ + ahs_notdb, + ahs_badkcr, + ahs_badauth, + ahs_noxform, + ahs_qfull, + ahs_wrap, + ahs_replay, + ahs_badauthl, /* Bad authenticator length */ + ahs_input, /* Input AH packets */ + ahs_output, /* Output AH packets */ + ahs_invalid, /* Trying to use an invalid TDB */ + ahs_ibytes, /* Input bytes */ + ahs_obytes, /* Output bytes */ + ahs_toobig, /* Packet got larger than + * IP_MAXPACKET */ + ahs_pdrops, /* Packet blocked due to policy */ + ahs_crypto, /* Crypto processing failure */ + ahs_outfail, /* Packet output failure */ + + ahs_ncounters +}; + +extern struct cpumem *ahcounters; + +static inline void +ahstat_inc(enum ahstat_counters c) +{ + counters_inc(ahcounters, c); +} + +static inline void +ahstat_add(enum ahstat_counters c, uint64_t v) +{ + counters_add(ahcounters, c, v); +} + +extern int ah_enable; + +#endif /* _KERNEL */ +#endif /* _NETINET_IP_AH_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/ip_carp.h b/lib/libc/include/generic-openbsd/netinet/ip_carp.h new file mode 100644 index 0000000000..67bf438c6b --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/ip_carp.h @@ -0,0 +1,228 @@ +/* $OpenBSD: ip_carp.h,v 1.52 2025/03/02 21:28:32 bluhm Exp $ */ + +/* + * Copyright (c) 2002 Michael Shalayeff. All rights reserved. + * Copyright (c) 2003 Ryan McBride. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _NETINET_IP_CARP_H_ +#define _NETINET_IP_CARP_H_ + +/* + * The CARP header layout is as follows: + * + * 0 1 2 3 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |Version| Type | VirtualHostID | AdvSkew | Auth Len | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Demotion | AdvBase | Checksum | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Counter (1) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Counter (2) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | SHA-1 HMAC (1) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | SHA-1 HMAC (2) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | SHA-1 HMAC (3) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | SHA-1 HMAC (4) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | SHA-1 HMAC (5) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * + */ + +struct carp_header { +#if _BYTE_ORDER == _LITTLE_ENDIAN + u_int carp_type:4, + carp_version:4; +#endif +#if _BYTE_ORDER == _BIG_ENDIAN + u_int carp_version:4, + carp_type:4; +#endif + u_int8_t carp_vhid; /* virtual host id */ + u_int8_t carp_advskew; /* advertisement skew */ + u_int8_t carp_authlen; /* size of counter+md, 32bit chunks */ + u_int8_t carp_demote; /* demotion indicator */ + u_int8_t carp_advbase; /* advertisement interval */ + u_int16_t carp_cksum; + u_int32_t carp_counter[2]; + unsigned char carp_md[20]; /* SHA1 HMAC */ +} __packed; + +#define CARP_DFLTTL 255 + +/* carp_version */ +#define CARP_VERSION 2 + +/* carp_type */ +#define CARP_ADVERTISEMENT 0x01 + +#define CARP_KEY_LEN 20 /* a sha1 hash of a passphrase */ + +/* carp_advbase */ +#define CARP_DFLTINTV 1 + +/* + * Statistics. + */ +struct carpstats { + u_int64_t carps_ipackets; /* total input packets, IPv4 */ + u_int64_t carps_ipackets6; /* total input packets, IPv6 */ + u_int64_t carps_badif; /* wrong interface */ + u_int64_t carps_badttl; /* TTL is not CARP_DFLTTL */ + u_int64_t carps_hdrops; /* packets shorter than hdr */ + u_int64_t carps_badsum; /* bad checksum */ + u_int64_t carps_badver; /* bad (incl unsupp) version */ + u_int64_t carps_badlen; /* data length does not match */ + u_int64_t carps_badauth; /* bad authentication */ + u_int64_t carps_badvhid; /* bad VHID */ + u_int64_t carps_badaddrs; /* bad address list */ + + u_int64_t carps_opackets; /* total output packets, IPv4 */ + u_int64_t carps_opackets6; /* total output packets, IPv6 */ + u_int64_t carps_onomem; /* no memory for an mbuf */ + u_int64_t carps_ostates; /* total state updates sent */ + + u_int64_t carps_preempt; /* transitions to master */ +}; + +#define CARPDEVNAMSIZ 16 +#ifdef IFNAMSIZ +#if CARPDEVNAMSIZ != IFNAMSIZ +#error namsiz mismatch +#endif +#endif + +/* + * Configuration structure for SIOCSVH SIOCGVH + */ +struct carpreq { + int carpr_state; +#define CARP_STATES "INIT", "BACKUP", "MASTER" +#define CARP_MAXSTATE 2 +#define CARP_MAXNODES 32 + + char carpr_carpdev[CARPDEVNAMSIZ]; + u_int8_t carpr_vhids[CARP_MAXNODES]; + u_int8_t carpr_advskews[CARP_MAXNODES]; + u_int8_t carpr_states[CARP_MAXNODES]; +#define CARP_BAL_MODES "none", "ip", "ip-stealth", "ip-unicast" +#define CARP_BAL_NONE 0 +#define CARP_BAL_IP 1 +#define CARP_BAL_IPSTEALTH 2 +#define CARP_BAL_IPUNICAST 3 +#define CARP_BAL_MAXID 3 + u_int8_t carpr_balancing; + int carpr_advbase; + unsigned char carpr_key[CARP_KEY_LEN]; + struct in_addr carpr_peer; +}; + +/* + * Names for CARP sysctl objects + */ +#define CARPCTL_ALLOW 1 /* accept incoming CARP packets */ +#define CARPCTL_PREEMPT 2 /* high-pri backup preemption mode */ +#define CARPCTL_LOG 3 /* log bad packets */ +#define CARPCTL_STATS 4 /* CARP stats */ +#define CARPCTL_MAXID 5 + +#define CARPCTL_NAMES { \ + { 0, 0 }, \ + { "allow", CTLTYPE_INT }, \ + { "preempt", CTLTYPE_INT }, \ + { "log", CTLTYPE_INT }, \ + { "stats", CTLTYPE_STRUCT }, \ +} + +#ifdef _KERNEL + +#include +#include + +enum carpstat_counters { + carps_ipackets, + carps_ipackets6, + carps_badif, + carps_badttl, + carps_hdrops, + carps_badsum, + carps_badver, + carps_badlen, + carps_badauth, + carps_badvhid, + carps_badaddrs, + carps_opackets, + carps_opackets6, + carps_onomem, + carps_ostates, + carps_preempt, + carps_ncounters, +}; + +extern struct cpumem *carpcounters; + +static inline void +carpstat_inc(enum carpstat_counters c) +{ + counters_inc(carpcounters, c); +} + +/* + * If two carp interfaces share same physical interface, then we pretend all IP + * addresses belong to single interface. + */ +static inline int +carp_strict_addr_chk(struct ifnet *ifp_a, struct ifnet *ifp_b) +{ + return ((ifp_a->if_type == IFT_CARP && + ifp_b->if_index == ifp_a->if_carpdevidx) || + (ifp_b->if_type == IFT_CARP && + ifp_a->if_index == ifp_b->if_carpdevidx) || + (ifp_a->if_type == IFT_CARP && ifp_b->if_type == IFT_CARP && + ifp_a->if_carpdevidx == ifp_b->if_carpdevidx)); +} + +struct mbuf *carp_input(struct ifnet *, struct mbuf *, uint64_t, + struct netstack *); +int carp_proto_input(struct mbuf **, int *, int, int, + struct netstack *); +void carp_carpdev_state(void *); +void carp_group_demote_adj(struct ifnet *, int, char *); +int carp6_proto_input(struct mbuf **, int *, int, int, + struct netstack *); +int carp_iamatch(struct ifnet *); +int carp_ourether(struct ifnet *, u_int8_t *); +int carp_output(struct ifnet *, struct mbuf *, struct sockaddr *, + struct rtentry *); +int carp_sysctl(int *, u_int, void *, size_t *, void *, size_t); +int carp_lsdrop(struct ifnet *, struct mbuf *, sa_family_t, + u_int32_t *, u_int32_t *, int); +#endif /* _KERNEL */ +#endif /* _NETINET_IP_CARP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/ip_divert.h b/lib/libc/include/generic-openbsd/netinet/ip_divert.h new file mode 100644 index 0000000000..a11dee17ce --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/ip_divert.h @@ -0,0 +1,93 @@ +/* $OpenBSD: ip_divert.h,v 1.30 2025/06/23 12:05:46 bluhm Exp $ */ + +/* + * Copyright (c) 2009 Michele Marchetto + * + * 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 _IP_DIVERT_H_ +#define _IP_DIVERT_H_ + +struct divstat { + u_long divs_ipackets; /* total input packets */ + u_long divs_noport; /* no socket on port */ + u_long divs_fullsock; /* not delivered, input socket full */ + u_long divs_opackets; /* total output packets */ + u_long divs_errors; /* generic errors */ +}; + +/* + * Names for divert sysctl objects + */ +#define DIVERTCTL_RECVSPACE 1 /* receive buffer space */ +#define DIVERTCTL_SENDSPACE 2 /* send buffer space */ +#define DIVERTCTL_STATS 3 /* divert statistics */ +#define DIVERTCTL_MAXID 4 + +#define DIVERTCTL_NAMES { \ + { 0, 0 }, \ + { "recvspace", CTLTYPE_INT }, \ + { "sendspace", CTLTYPE_INT }, \ + { "stats", CTLTYPE_STRUCT } \ +} + +#ifdef _KERNEL + +#include + +#define DIVERT_SENDSPACE (65536 + 100) +#define DIVERT_RECVSPACE (65536 + 100) +#define DIVERT_HASHSIZE 128 + +enum divstat_counters { + divs_ipackets, + divs_noport, + divs_fullsock, + divs_opackets, + divs_errors, + divs_ncounters, +}; + +extern struct cpumem *divcounters; + +static inline void +divstat_inc(enum divstat_counters c) +{ + counters_inc(divcounters, c); +} + +extern u_int divert_sendspace; +extern u_int divert_recvspace; +extern struct inpcbtable divbtable, divb6table; +extern const struct pr_usrreqs divert_usrreqs, divert6_usrreqs; + +void divert_init(void); +void divert_packet(struct mbuf *, int, u_int16_t); +int divert_sysctl(int *, u_int, void *, size_t *, void *, size_t); +int divert_sysctl_divstat(void *, size_t *, void *); +int divert_attach(struct socket *, int, int); +int divert_detach(struct socket *); +int divert_bind(struct socket *, struct mbuf *, struct proc *); +int divert_shutdown(struct socket *); +int divert_send(struct socket *, struct mbuf *, struct mbuf *, + struct mbuf *); + +void divert6_init(void); +void divert6_packet(struct mbuf *, int, u_int16_t); +int divert6_attach(struct socket *, int, int); +int divert6_send(struct socket *, struct mbuf *, struct mbuf *, + struct mbuf *); + +#endif /* _KERNEL */ +#endif /* _IP_DIVERT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/ip_ecn.h b/lib/libc/include/generic-openbsd/netinet/ip_ecn.h new file mode 100644 index 0000000000..3e900aa197 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/ip_ecn.h @@ -0,0 +1,52 @@ +/* $OpenBSD: ip_ecn.h,v 1.7 2018/11/14 23:55:04 dlg Exp $ */ +/* $KAME: ip_ecn.h,v 1.5 2000/03/27 04:58:38 sumikawa Exp $ */ + +/* + * Copyright (C) 1999 WIDE Project. + * 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 project 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 PROJECT 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 PROJECT 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 _NETINET_IP_ECN_H_ +#define _NETINET_IP_ECN_H_ + +/* + * ECN consideration on tunnel ingress/egress operation. + * http://www.aciri.org/floyd/papers/draft-ipsec-ecn-00.txt + */ + +#define ECN_ALLOWED_IPSEC 2 /* ECN allowed */ +#define ECN_ALLOWED 1 /* ECN allowed */ +#define ECN_FORBIDDEN 0 /* ECN forbidden */ +#define ECN_NOCARE (-1) /* no consideration to ECN */ + +#if defined(_KERNEL) +extern void ip_ecn_ingress(int, u_int8_t *, u_int8_t *); +extern int ip_ecn_egress(int, u_int8_t *, u_int8_t *); +void ip_tos_patch(struct ip *, uint8_t); +#endif /* _KERNEL */ +#endif /* _NETINET_IP_ECN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/ip_esp.h b/lib/libc/include/generic-openbsd/netinet/ip_esp.h new file mode 100644 index 0000000000..79e213447a --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/ip_esp.h @@ -0,0 +1,141 @@ +/* $OpenBSD: ip_esp.h,v 1.48 2025/01/01 13:44:22 bluhm Exp $ */ +/* + * The authors of this code are John Ioannidis (ji@tla.org), + * Angelos D. Keromytis (kermit@csd.uch.gr) and + * Niels Provos (provos@physnet.uni-hamburg.de). + * + * The original version of this code was written by John Ioannidis + * for BSD/OS in Athens, Greece, in November 1995. + * + * Ported to OpenBSD and NetBSD, with additional transforms, in December 1996, + * by Angelos D. Keromytis. + * + * Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis + * and Niels Provos. + * + * Additional features in 1999 by Angelos D. Keromytis. + * + * Copyright (C) 1995, 1996, 1997, 1998, 1999 by John Ioannidis, + * Angelos D. Keromytis and Niels Provos. + * Copyright (c) 2001 Angelos D. Keromytis. + * + * Permission to use, copy, and modify this software with or without fee + * is hereby granted, provided that this entire notice is included in + * all copies of any software which is or includes a copy or + * modification of this software. + * You may use this code under the GNU public license if you so wish. Please + * contribute changes back to the authors under this freer than GPL license + * so that we may further the use of strong encryption without limitations to + * all. + * + * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY + * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE + * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR + * PURPOSE. + */ + +#ifndef _NETINET_IP_ESP_H_ +#define _NETINET_IP_ESP_H_ + +struct espstat { + uint64_t esps_hdrops; /* Packet shorter than header shows */ + uint64_t esps_nopf; /* Protocol family not supported */ + uint64_t esps_notdb; + uint64_t esps_badkcr; + uint64_t esps_qfull; + uint64_t esps_noxform; + uint64_t esps_badilen; + uint64_t esps_wrap; /* Replay counter wrapped around */ + uint64_t esps_badenc; /* Bad encryption detected */ + uint64_t esps_badauth; /* Only valid for transforms + * with auth */ + uint64_t esps_replay; /* Possible packet replay detected */ + uint64_t esps_input; /* Input ESP packets */ + uint64_t esps_output; /* Output ESP packets */ + uint64_t esps_invalid; /* Trying to use an invalid TDB */ + uint64_t esps_ibytes; /* Input bytes */ + uint64_t esps_obytes; /* Output bytes */ + uint64_t esps_toobig; /* Packet got larger than + * IP_MAXPACKET */ + uint64_t esps_pdrops; /* Packet blocked due to policy */ + uint64_t esps_crypto; /* Crypto processing failure */ + uint64_t esps_udpencin; /* Input ESP-in-UDP packets */ + uint64_t esps_udpencout; /* Output ESP-in-UDP packets */ + uint64_t esps_udpinval; /* Invalid input ESP-in-UDP packets */ + uint64_t esps_udpneeded; /* Trying to use a ESP-in-UDP TDB */ + uint64_t esps_outfail; /* Packet output failure */ +}; + +/* + * Names for ESP sysctl objects + */ +#define ESPCTL_ENABLE 1 /* Enable ESP processing */ +#define ESPCTL_UDPENCAP_ENABLE 2 /* Enable ESP over UDP */ +#define ESPCTL_UDPENCAP_PORT 3 /* UDP port for encapsulation */ +#define ESPCTL_STATS 4 /* ESP Stats */ +#define ESPCTL_MAXID 5 + +#define ESPCTL_NAMES { \ + { 0, 0 }, \ + { "enable", CTLTYPE_INT }, \ + { "udpencap", CTLTYPE_INT }, \ + { "udpencap_port", CTLTYPE_INT }, \ + { "stats", CTLTYPE_STRUCT }, \ +} + +#ifdef _KERNEL + +#include + +enum espstat_counters { + esps_hdrops, /* Packet shorter than header shows */ + esps_nopf, /* Protocol family not supported */ + esps_notdb, + esps_badkcr, + esps_qfull, + esps_noxform, + esps_badilen, + esps_wrap, /* Replay counter wrapped around */ + esps_badenc, /* Bad encryption detected */ + esps_badauth, /* Only valid for transformsx + * with auth */ + esps_replay, /* Possible packet replay detected */ + esps_input, /* Input ESP packets */ + esps_output, /* Output ESP packets */ + esps_invalid, /* Trying to use an invalid TDB */ + esps_ibytes, /* Input bytes */ + esps_obytes, /* Output bytes */ + esps_toobig, /* Packet got larger than + * IP_MAXPACKET */ + esps_pdrops, /* Packet blocked due to policy */ + esps_crypto, /* Crypto processing failure */ + esps_udpencin, /* Input ESP-in-UDP packets */ + esps_udpencout, /* Output ESP-in-UDP packets */ + esps_udpinval, /* Invalid input ESP-in-UDP packets */ + esps_udpneeded, /* Trying to use a ESP-in-UDP TDB */ + esps_outfail, /* Packet output failure */ + + esps_ncounters +}; + +extern struct cpumem *espcounters; + +static inline void +espstat_inc(enum espstat_counters c) +{ + counters_inc(espcounters, c); +} + +static inline void +espstat_add(enum espstat_counters c, uint64_t v) +{ + counters_add(espcounters, c, v); +} + +extern int esp_enable; +extern int udpencap_enable; +extern int udpencap_port; + +#endif /* _KERNEL */ +#endif /* _NETINET_IP_ESP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/ip_ether.h b/lib/libc/include/generic-openbsd/netinet/ip_ether.h new file mode 100644 index 0000000000..d213683626 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/ip_ether.h @@ -0,0 +1,111 @@ +/* $OpenBSD: ip_ether.h,v 1.30 2019/10/04 05:00:49 dlg Exp $ */ +/* + * The author of this code is Angelos D. Keromytis (angelos@adk.gr) + * + * This code was written by Angelos D. Keromytis in October 1999. + * + * Copyright (C) 1999-2001 Angelos D. Keromytis. + * + * Permission to use, copy, and modify this software with or without fee + * is hereby granted, provided that this entire notice is included in + * all copies of any software which is or includes a copy or + * modification of this software. + * You may use this code under the GNU public license if you so wish. Please + * contribute changes back to the authors under this freer than GPL license + * so that we may further the use of strong encryption without limitations to + * all. + * + * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY + * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE + * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR + * PURPOSE. + */ + +#ifndef _NETINET_IP_ETHER_H_ +#define _NETINET_IP_ETHER_H_ + +/* + * Ethernet-inside-IP processing. + */ + +struct etheripstat { + u_int64_t etherips_hdrops; /* packet shorter than header shows */ + u_int64_t etherips_qfull; /* bridge queue full, packet dropped */ + u_int64_t etherips_noifdrops; /* no interface/bridge information */ + u_int64_t etherips_pdrops; /* packet dropped due to policy */ + u_int64_t etherips_adrops; /* all other drops */ + u_int64_t etherips_ipackets; /* total input packets */ + u_int64_t etherips_opackets; /* total output packets */ + u_int64_t etherips_ibytes; /* input bytes */ + u_int64_t etherips_obytes; /* output bytes */ +}; + +struct etherip_header { +#if BYTE_ORDER == LITTLE_ENDIAN + u_int eip_res:4; /* reserved */ + u_int eip_ver:4; /* version */ +#endif +#if BYTE_ORDER == BIG_ENDIAN + u_int eip_ver:4; /* version */ + u_int eip_res:4; /* reserved */ +#endif + u_int8_t eip_pad; /* required padding byte */ +} __packed; + +#define ETHERIP_VERSION 0x03 + +/* + * Names for Ether-IP sysctl objects + */ +#define ETHERIPCTL_ALLOW 1 /* accept incoming EtherIP packets */ +#define ETHERIPCTL_STATS 2 /* etherip stats */ +#define ETHERIPCTL_MAXID 3 + +#define ETHERIPCTL_NAMES { \ + { 0, 0 }, \ + { "allow", CTLTYPE_INT }, \ + { "stats", CTLTYPE_STRUCT }, \ +} + +#ifdef _KERNEL + +#include + +enum etheripstat_counters { + etherips_hdrops, /* packet shorter than header shows */ + etherips_qfull, /* bridge queue full, packet dropped */ + etherips_noifdrops, /* no interface/bridge information */ + etherips_pdrops, /* packet dropped due to policy */ + etherips_adrops, /* all other drops */ + etherips_ipackets, /* total input packets */ + etherips_opackets, /* total output packets */ + etherips_ibytes, /* input bytes */ + etherips_obytes, /* output bytes */ + + etherips_ncounters +}; + +extern struct cpumem *etheripcounters; + +static inline void +etheripstat_inc(enum etheripstat_counters c) +{ + counters_inc(etheripcounters, c); +} + +static inline void +etheripstat_add(enum etheripstat_counters c, uint64_t v) +{ + counters_add(etheripcounters, c, v); +} + +static inline void +etheripstat_pkt(enum etheripstat_counters pcounter, + enum etheripstat_counters bcounter, uint64_t v) +{ + counters_pkt(etheripcounters, pcounter, bcounter, v); +} + +#endif /* _KERNEL */ +#endif /* _NETINET_IP_ETHER_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/ip_gre.h b/lib/libc/include/generic-openbsd/netinet/ip_gre.h new file mode 100644 index 0000000000..ed30e3cc6b --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/ip_gre.h @@ -0,0 +1,62 @@ +/* $OpenBSD: ip_gre.h,v 1.20 2025/01/01 13:44:22 bluhm Exp $ */ +/* $NetBSD: ip_gre.h,v 1.3 1998/10/07 23:33:02 thorpej Exp $ */ + +/* + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Heiko W.Rupp + * + * 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 _NETINET_IP_GRE_H_ +#define _NETINET_IP_GRE_H_ + +/* Protocol number for Cisco's WCCP + * The Internet Draft is: + * draft-forster-wrec-wccp-v1-00.txt + */ +#define GREPROTO_WCCP 0x883e + +/* + * Names for GRE sysctl objects + */ +#define GRECTL_ALLOW 1 /* accept incoming GRE packets */ +#define GRECTL_WCCP 2 /* accept WCCPv1-style GRE packets */ +#define GRECTL_MAXID 3 + +#define GRECTL_NAMES { \ + { 0, 0 }, \ + { "allow", CTLTYPE_INT }, \ + { "wccp", CTLTYPE_INT }, \ +} + +#ifdef _KERNEL + +extern const struct pr_usrreqs gre_usrreqs; + +int gre_send(struct socket *, struct mbuf *, struct mbuf *, + struct mbuf *); +#endif /* _KERNEL */ +#endif /* _NETINET_IP_GRE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/ip_icmp.h b/lib/libc/include/generic-openbsd/netinet/ip_icmp.h new file mode 100644 index 0000000000..601bfa4419 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/ip_icmp.h @@ -0,0 +1,246 @@ +/* $OpenBSD: ip_icmp.h,v 1.33 2025/03/02 21:28:32 bluhm Exp $ */ +/* $NetBSD: ip_icmp.h,v 1.10 1996/02/13 23:42:28 christos Exp $ */ + +/* + * Copyright (c) 1982, 1986, 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. + * + * @(#)ip_icmp.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NETINET_IP_ICMP_H_ +#define _NETINET_IP_ICMP_H_ + +/* + * Interface Control Message Protocol Definitions. + * Per RFC 792, September 1981. + * RFC 950, August 1985. (Address Mask Request / Reply) + * RFC 1256, September 1991. (Router Advertisement and Solicitation) + * RFC 1108, November 1991. (Param Problem, Missing Req. Option) + * RFC 1393, January 1993. (Traceroute) + * RFC 1475, June 1993. (Datagram Conversion Error) + * RFC 1812, June 1995. (adm prohib, host precedence, precedence cutoff) + * RFC 2002, October 1996. (Mobility changes to Router Advertisement) + */ + +/* + * ICMP Router Advertisement data + */ +struct icmp_ra_addr { + u_int32_t ira_addr; + u_int32_t ira_preference; +}; + +/* + * Structure of an icmp header. + */ +struct icmp { + u_int8_t icmp_type; /* type of message, see below */ + u_int8_t icmp_code; /* type sub code */ + u_int16_t icmp_cksum; /* ones complement cksum of struct */ + union { + u_int8_t ih_pptr; /* ICMP_PARAMPROB */ + struct ih_exthdr { /* RFC4884 extended header */ + u_int8_t iex_pad; + u_int8_t iex_length; + } ih_exthdr; + struct in_addr ih_gwaddr; /* ICMP_REDIRECT */ + struct ih_idseq { + u_int16_t icd_id; + u_int16_t icd_seq; + } ih_idseq; + int32_t ih_void; + + /* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */ + struct ih_pmtu { + u_int16_t ipm_void; + u_int16_t ipm_nextmtu; + } ih_pmtu; + + struct ih_rtradv { + u_int8_t irt_num_addrs; + u_int8_t irt_wpa; + u_int16_t irt_lifetime; + } ih_rtradv; + } icmp_hun; +#define icmp_pptr icmp_hun.ih_pptr +#define icmp_length icmp_hun.ih_exthdr.iex_length +#define icmp_gwaddr icmp_hun.ih_gwaddr +#define icmp_id icmp_hun.ih_idseq.icd_id +#define icmp_seq icmp_hun.ih_idseq.icd_seq +#define icmp_void icmp_hun.ih_void +#define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void +#define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu +#define icmp_num_addrs icmp_hun.ih_rtradv.irt_num_addrs +#define icmp_wpa icmp_hun.ih_rtradv.irt_wpa +#define icmp_lifetime icmp_hun.ih_rtradv.irt_lifetime + union { + struct id_ts { + u_int32_t its_otime; + u_int32_t its_rtime; + u_int32_t its_ttime; + } id_ts; + struct id_ip { + struct ip idi_ip; + /* options and then 64 bits of data */ + } id_ip; + u_int32_t id_mask; + int8_t id_data[1]; + } icmp_dun; +#define icmp_otime icmp_dun.id_ts.its_otime +#define icmp_rtime icmp_dun.id_ts.its_rtime +#define icmp_ttime icmp_dun.id_ts.its_ttime +#define icmp_ip icmp_dun.id_ip.idi_ip +#define icmp_mask icmp_dun.id_mask +#define icmp_data icmp_dun.id_data +}; + +struct icmp_ext_hdr { + u_int8_t ieh_version; /* only high nibble used */ + u_int8_t ieh_res; /* reserved, must be zero */ + u_int16_t ieh_cksum; /* ones complement cksum of ext hdr */ +}; + +#define ICMP_EXT_HDR_VERSION 0x20 +#define ICMP_EXT_HDR_VMASK 0xf0 +#define ICMP_EXT_OFFSET 128 + +struct icmp_ext_obj_hdr { + u_int16_t ieo_length; /* length of obj incl this header */ + u_int8_t ieo_cnum; /* class number */ + u_int8_t ieo_ctype; /* sub class type */ +}; + +#define ICMP_EXT_MPLS 1 +#define ICMP_EXT_IFINFO 2 + +/* + * For IPv6 transition related ICMP errors. + */ +#define ICMP_V6ADVLENMIN (8 + sizeof(struct ip) + 40) +#define ICMP_V6ADVLEN(p) (8 + ((p)->icmp_ip.ip_hl << 2) + 40) + +/* + * Lower bounds on packet lengths for various types. + * For the error advice packets must first insure that the + * packet is large enough to contain the returned ip header. + * Only then can we do the check to see if 64 bits of packet + * data have been returned, since we need to check the returned + * ip header length. + */ +#define ICMP_MINLEN 8 /* abs minimum */ +#define ICMP_TSLEN (8 + 3 * sizeof (u_int32_t)) /* timestamp */ +#define ICMP_MASKLEN 12 /* address mask */ +#define ICMP_ADVLENMIN (8 + sizeof (struct ip) + 8) /* min */ +#define ICMP_ADVLENMAX (8 + 60 + 40) /* maximum */ +#define ICMP_ADVLEN(p) (8 + ((p)->icmp_ip.ip_hl << 2) + 8) + /* N.B.: must separately check that ip_hl >= 5 */ + +/* + * Definition of type and code field values. + * https://www.iana.org/assignments/icmp-parameters + */ +#define ICMP_ECHOREPLY 0 /* echo reply */ +#define ICMP_UNREACH 3 /* dest unreachable, codes: */ +#define ICMP_UNREACH_NET 0 /* bad net */ +#define ICMP_UNREACH_HOST 1 /* bad host */ +#define ICMP_UNREACH_PROTOCOL 2 /* bad protocol */ +#define ICMP_UNREACH_PORT 3 /* bad port */ +#define ICMP_UNREACH_NEEDFRAG 4 /* IP_DF caused drop */ +#define ICMP_UNREACH_SRCFAIL 5 /* src route failed */ +#define ICMP_UNREACH_NET_UNKNOWN 6 /* unknown net */ +#define ICMP_UNREACH_HOST_UNKNOWN 7 /* unknown host */ +#define ICMP_UNREACH_ISOLATED 8 /* src host isolated */ +#define ICMP_UNREACH_NET_PROHIB 9 /* for crypto devs */ +#define ICMP_UNREACH_HOST_PROHIB 10 /* ditto */ +#define ICMP_UNREACH_TOSNET 11 /* bad tos for net */ +#define ICMP_UNREACH_TOSHOST 12 /* bad tos for host */ +#define ICMP_UNREACH_FILTER_PROHIB 13 /* prohibited access */ +#define ICMP_UNREACH_HOST_PRECEDENCE 14 /* precedence violat'n*/ +#define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 /* precedence cutoff */ +#define ICMP_SOURCEQUENCH 4 /* packet lost, slow down */ +#define ICMP_REDIRECT 5 /* shorter route, codes: */ +#define ICMP_REDIRECT_NET 0 /* for network */ +#define ICMP_REDIRECT_HOST 1 /* for host */ +#define ICMP_REDIRECT_TOSNET 2 /* for tos and net */ +#define ICMP_REDIRECT_TOSHOST 3 /* for tos and host */ +#define ICMP_ALTHOSTADDR 6 /* alternate host address */ +#define ICMP_ECHO 8 /* echo service */ +#define ICMP_ROUTERADVERT 9 /* router advertisement */ +#define ICMP_ROUTERADVERT_NORMAL 0 /* normal advertisement */ +#define ICMP_ROUTERADVERT_NOROUTE_COMMON 16 /* selective routing */ +#define ICMP_ROUTERSOLICIT 10 /* router solicitation */ +#define ICMP_TIMXCEED 11 /* time exceeded, code: */ +#define ICMP_TIMXCEED_INTRANS 0 /* ttl==0 in transit */ +#define ICMP_TIMXCEED_REASS 1 /* ttl==0 in reass */ +#define ICMP_PARAMPROB 12 /* ip header bad */ +#define ICMP_PARAMPROB_ERRATPTR 0 /* req. opt. absent */ +#define ICMP_PARAMPROB_OPTABSENT 1 /* req. opt. absent */ +#define ICMP_PARAMPROB_LENGTH 2 /* bad length */ +#define ICMP_TSTAMP 13 /* timestamp request */ +#define ICMP_TSTAMPREPLY 14 /* timestamp reply */ +#define ICMP_IREQ 15 /* information request */ +#define ICMP_IREQREPLY 16 /* information reply */ +#define ICMP_MASKREQ 17 /* address mask request */ +#define ICMP_MASKREPLY 18 /* address mask reply */ +#define ICMP_TRACEROUTE 30 /* traceroute */ +#define ICMP_DATACONVERR 31 /* data conversion error */ +#define ICMP_MOBILE_REDIRECT 32 /* mobile host redirect */ +#define ICMP_IPV6_WHEREAREYOU 33 /* IPv6 where-are-you */ +#define ICMP_IPV6_IAMHERE 34 /* IPv6 i-am-here */ +#define ICMP_MOBILE_REGREQUEST 35 /* mobile registration req */ +#define ICMP_MOBILE_REGREPLY 36 /* mobile registration reply */ +#define ICMP_SKIP 39 /* SKIP */ +#define ICMP_PHOTURIS 40 /* Photuris */ +#define ICMP_PHOTURIS_UNKNOWN_INDEX 1 /* unknown sec index */ +#define ICMP_PHOTURIS_AUTH_FAILED 2 /* auth failed */ +#define ICMP_PHOTURIS_DECRYPT_FAILED 3 /* decrypt failed */ + +#define ICMP_MAXTYPE 40 + +#define ICMP_INFOTYPE(type) \ + ((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \ + (type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \ + (type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \ + (type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \ + (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY) + +#ifdef _KERNEL +struct mbuf * + icmp_do_error(struct mbuf *, int, int, u_int32_t, int); +void icmp_error(struct mbuf *, int, int, u_int32_t, int); +int icmp_input(struct mbuf **, int *, int, int, struct netstack *); +void icmp_init(void); +int icmp_reflect(struct mbuf *, struct mbuf **, struct in_ifaddr *); +void icmp_send(struct mbuf *, struct mbuf *); +int icmp_sysctl(int *, u_int, void *, size_t *, void *, size_t); +struct rtentry * + icmp_mtudisc_clone(struct in_addr, u_int, int); +void icmp_mtudisc(struct icmp *, u_int); +int icmp_do_exthdr(struct mbuf *, u_int16_t, u_int8_t, void *, size_t); +#endif /* _KERNEL */ +#endif /* _NETINET_IP_ICMP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/ip_ipcomp.h b/lib/libc/include/generic-openbsd/netinet/ip_ipcomp.h new file mode 100644 index 0000000000..c207c33853 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/ip_ipcomp.h @@ -0,0 +1,126 @@ +/* $OpenBSD: ip_ipcomp.h,v 1.11 2020/09/01 01:53:34 gnezdo Exp $ */ + +/* + * Copyright (c) 2001 Jean-Jacques Bernard-Gundol (jj@wabbitt.org) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* IP payload compression protocol (IPComp), see RFC 2393 */ + +#ifndef _NETINET_IP_IPCOMP_H_ +#define _NETINET_IP_IPCOMP_H_ + +struct ipcompstat { + uint64_t ipcomps_hdrops; /* Packet shorter than header shows */ + uint64_t ipcomps_nopf; /* Protocol family not supported */ + uint64_t ipcomps_notdb; + uint64_t ipcomps_badkcr; + uint64_t ipcomps_qfull; + uint64_t ipcomps_noxform; + uint64_t ipcomps_wrap; + uint64_t ipcomps_input; /* Input IPcomp packets */ + uint64_t ipcomps_output; /* Output IPcomp packets */ + uint64_t ipcomps_invalid; /* Trying to use an invalid + * TDB */ + uint64_t ipcomps_ibytes; /* Input bytes */ + uint64_t ipcomps_obytes; /* Output bytes */ + uint64_t ipcomps_toobig; /* Packet got larger than + * IP_MAXPACKET */ + uint64_t ipcomps_pdrops; /* Packet blocked due to policy */ + uint64_t ipcomps_crypto; /* "Crypto" processing failure */ + uint64_t ipcomps_minlen; /* packets too short for compress */ + uint64_t ipcomps_outfail; /* Packet output failure */ +}; + +/* IPCOMP header */ +struct ipcomp { + u_int8_t ipcomp_nh; /* Next header */ + u_int8_t ipcomp_flags; /* Flags: reserved field: 0 */ + u_int16_t ipcomp_cpi; /* Compression Parameter Index, + * Network order */ +}; + +/* Length of IPCOMP header */ +#define IPCOMP_HLENGTH 4 + +/* + * Names for IPCOMP sysctl objects + */ +#define IPCOMPCTL_ENABLE 1 /* Enable COMP processing */ +#define IPCOMPCTL_STATS 2 /* COMP stats */ +#define IPCOMPCTL_MAXID 3 + +#define IPCOMPCTL_NAMES { \ + { 0, 0 }, \ + { "enable", CTLTYPE_INT }, \ + { "stats", CTLTYPE_STRUCT }, \ +} + +#ifdef _KERNEL + +#include + +enum ipcomp_counters { + ipcomps_hdrops, /* Packet shorter than header shows */ + ipcomps_nopf, /* Protocol family not supported */ + ipcomps_notdb, + ipcomps_badkcr, + ipcomps_qfull, + ipcomps_noxform, + ipcomps_wrap, + ipcomps_input, /* Input IPcomp packets */ + ipcomps_output, /* Output IPcomp packets */ + ipcomps_invalid, /* Trying to use an invalid + * TDB */ + ipcomps_ibytes, /* Input bytes */ + ipcomps_obytes, /* Output bytes */ + ipcomps_toobig, /* Packet got larger than + * IP_MAXPACKET */ + ipcomps_pdrops, /* Packet blocked due to policy */ + ipcomps_crypto, /* "Crypto" processing failure */ + ipcomps_minlen, /* packets too short for compress */ + ipcomps_outfail, /* Packet output failure */ + + ipcomps_ncounters +}; + +extern struct cpumem *ipcompcounters; + +static inline void +ipcompstat_inc(enum ipcomp_counters c) +{ + counters_inc(ipcompcounters, c); +} + +static inline void +ipcompstat_add(enum ipcomp_counters c, uint64_t v) +{ + counters_add(ipcompcounters, c, v); +} + +extern int ipcomp_enable; + +#endif /* _KERNEL */ +#endif /* _NETINET_IP_IPCOMP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/ip_ipip.h b/lib/libc/include/generic-openbsd/netinet/ip_ipip.h new file mode 100644 index 0000000000..d903badc20 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/ip_ipip.h @@ -0,0 +1,124 @@ +/* $OpenBSD: ip_ipip.h,v 1.15 2025/03/02 21:28:32 bluhm Exp $ */ +/* + * The authors of this code are John Ioannidis (ji@tla.org), + * Angelos D. Keromytis (kermit@csd.uch.gr) and + * Niels Provos (provos@physnet.uni-hamburg.de). + * + * The original version of this code was written by John Ioannidis + * for BSD/OS in Athens, Greece, in November 1995. + * + * Ported to OpenBSD and NetBSD, with additional transforms, in December 1996, + * by Angelos D. Keromytis. + * + * Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis + * and Niels Provos. + * + * Additional features in 1999 by Angelos D. Keromytis. + * + * Copyright (C) 1995, 1996, 1997, 1998, 1999 by John Ioannidis, + * Angelos D. Keromytis and Niels Provos. + * Copyright (c) 2001, Angelos D. Keromytis. + * + * Permission to use, copy, and modify this software with or without fee + * is hereby granted, provided that this entire notice is included in + * all copies of any software which is or includes a copy or + * modification of this software. + * You may use this code under the GNU public license if you so wish. Please + * contribute changes back to the authors under this freer than GPL license + * so that we may further the use of strong encryption without limitations to + * all. + * + * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY + * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE + * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR + * PURPOSE. + */ + +#ifndef _NETINET_IPIP_H_ +#define _NETINET_IPIP_H_ + +/* + * IP-inside-IP processing. + * Not quite all the functionality of RFC-1853, but the main idea is there. + */ + +struct ipipstat { + u_int64_t ipips_ipackets; /* total input packets */ + u_int64_t ipips_opackets; /* total output packets */ + u_int64_t ipips_hdrops; /* packet shorter than header shows */ + u_int64_t ipips_qfull; + u_int64_t ipips_ibytes; + u_int64_t ipips_obytes; + u_int64_t ipips_pdrops; /* packet dropped due to policy */ + u_int64_t ipips_spoof; /* IP spoofing attempts */ + u_int64_t ipips_family; /* Protocol family mismatch */ + u_int64_t ipips_unspec; /* Missing tunnel endpoint address */ +}; + +#define IP4_DEFAULT_TTL 0 +#define IP4_SAME_TTL -1 + +/* + * Names for IPIP sysctl objects + */ +#define IPIPCTL_ALLOW 1 /* accept incoming IP4 packets */ +#define IPIPCTL_STATS 2 /* IPIP stats */ +#define IPIPCTL_MAXID 3 + +#define IPIPCTL_NAMES { \ + { 0, 0 }, \ + { "allow", CTLTYPE_INT }, \ + { "stats", CTLTYPE_STRUCT }, \ +} + +#ifdef _KERNEL + +#include + +enum ipipstat_counters { + ipips_ipackets, + ipips_opackets, + ipips_hdrops, + ipips_qfull, + ipips_ibytes, + ipips_obytes, + ipips_pdrops, + ipips_spoof, + ipips_family, + ipips_unspec, + ipips_ncounters +}; + +extern struct cpumem *ipipcounters; + +static inline void +ipipstat_inc(enum ipipstat_counters c) +{ + counters_inc(ipipcounters, c); +} + +static inline void +ipipstat_add(enum ipipstat_counters c, uint64_t v) +{ + counters_add(ipipcounters, c, v); +} + +static inline void +ipipstat_pkt(enum ipipstat_counters p, enum ipipstat_counters b, uint64_t v) +{ + counters_pkt(ipipcounters, p, b, v); +} + +struct tdb; + +void ipip_init(void); +int ipip_input(struct mbuf **, int *, int, int, struct netstack *); +int ipip_input_if(struct mbuf **, int *, int, int, int, struct ifnet *, + struct netstack *); +int ipip_output(struct mbuf **, struct tdb *); +int ipip_sysctl(int *, u_int, void *, size_t *, void *, size_t); + +extern int ipip_allow; +#endif /* _KERNEL */ +#endif /* _NETINET_IPIP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/ip_ipsp.h b/lib/libc/include/generic-openbsd/netinet/ip_ipsp.h new file mode 100644 index 0000000000..a77dc4b4ce --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/ip_ipsp.h @@ -0,0 +1,737 @@ +/* $OpenBSD: ip_ipsp.h,v 1.249 2025/05/09 19:53:41 mvs Exp $ */ +/* + * The authors of this code are John Ioannidis (ji@tla.org), + * Angelos D. Keromytis (kermit@csd.uch.gr), + * Niels Provos (provos@physnet.uni-hamburg.de) and + * Niklas Hallqvist (niklas@appli.se). + * + * The original version of this code was written by John Ioannidis + * for BSD/OS in Athens, Greece, in November 1995. + * + * Ported to OpenBSD and NetBSD, with additional transforms, in December 1996, + * by Angelos D. Keromytis. + * + * Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis + * and Niels Provos. + * + * Additional features in 1999 by Angelos D. Keromytis and Niklas Hallqvist. + * + * Copyright (c) 1995, 1996, 1997, 1998, 1999 by John Ioannidis, + * Angelos D. Keromytis and Niels Provos. + * Copyright (c) 1999 Niklas Hallqvist. + * Copyright (c) 2001, Angelos D. Keromytis. + * + * Permission to use, copy, and modify this software with or without fee + * is hereby granted, provided that this entire notice is included in + * all copies of any software which is or includes a copy or + * modification of this software. + * You may use this code under the GNU public license if you so wish. Please + * contribute changes back to the authors under this freer than GPL license + * so that we may further the use of strong encryption without limitations to + * all. + * + * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY + * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE + * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR + * PURPOSE. + */ + +#ifndef _NETINET_IPSP_H_ +#define _NETINET_IPSP_H_ + +/* + * Locks used to protect struct members in this file: + * I immutable after creation + * a atomic operations + * N net lock + * A ipsec_acquire_mtx + * F ipsec_flows_mtx + * P ipo_tdb_mtx link policy to TDB global mutex + * D tdb_sadb_mtx SA database global mutex + * m tdb_mtx fields of struct tdb + * S pfsync fields of struct tdb + */ + +/* IPSP global definitions. */ + +#include +#include + +union sockaddr_union { + struct sockaddr sa; + struct sockaddr_in sin; + struct sockaddr_in6 sin6; +}; + +#define AH_HMAC_MAX_HASHLEN 32 /* 256 bits of authenticator for SHA512 */ +#define AH_HMAC_RPLENGTH 4 /* 32 bits of replay counter */ +#define AH_HMAC_INITIAL_RPL 1 /* Replay counter initial value */ + +/* Authenticator lengths */ +#define AH_MD5_ALEN 16 +#define AH_SHA1_ALEN 20 +#define AH_RMD160_ALEN 20 +#define AH_SHA2_256_ALEN 32 +#define AH_SHA2_384_ALEN 48 +#define AH_SHA2_512_ALEN 64 +#define AH_ALEN_MAX 64 /* Keep updated */ + +/* Reserved SPI numbers */ +#define SPI_LOCAL_USE 0 +#define SPI_RESERVED_MIN 1 +#define SPI_RESERVED_MAX 255 + +/* Reserved CPI numbers */ +#define CPI_RESERVED_MIN 1 +#define CPI_RESERVED_MAX 255 +#define CPI_PRIVATE_MIN 61440 +#define CPI_PRIVATE_MAX 65535 + +/* sysctl default values */ +#define IPSEC_DEFAULT_EMBRYONIC_SA_TIMEOUT 60 /* 1 minute */ +#define IPSEC_DEFAULT_PFS 1 +#define IPSEC_DEFAULT_SOFT_ALLOCATIONS 0 +#define IPSEC_DEFAULT_EXP_ALLOCATIONS 0 +#define IPSEC_DEFAULT_SOFT_BYTES 0 +#define IPSEC_DEFAULT_EXP_BYTES 0 +#define IPSEC_DEFAULT_SOFT_TIMEOUT 80000 +#define IPSEC_DEFAULT_EXP_TIMEOUT 86400 +#define IPSEC_DEFAULT_SOFT_FIRST_USE 3600 +#define IPSEC_DEFAULT_EXP_FIRST_USE 7200 +#define IPSEC_DEFAULT_DEF_ENC "aes" +#define IPSEC_DEFAULT_DEF_AUTH "hmac-sha1" +#define IPSEC_DEFAULT_EXPIRE_ACQUIRE 30 +#define IPSEC_DEFAULT_DEF_COMP "deflate" + +struct sockaddr_encap { + u_int8_t sen_len; /* length */ + u_int8_t sen_family; /* PF_KEY */ + u_int16_t sen_type; /* see SENT_* */ + union { + struct { /* SENT_IP4 */ + u_int8_t Direction; + struct in_addr Src; + struct in_addr Dst; + u_int8_t Proto; + u_int16_t Sport; + u_int16_t Dport; + } Sip4; + + struct { /* SENT_IP6 */ + u_int8_t Direction; + struct in6_addr Src; + struct in6_addr Dst; + u_int8_t Proto; + u_int16_t Sport; + u_int16_t Dport; + } Sip6; + } Sen; +}; + +#define IPSP_DIRECTION_IN 0x1 +#define IPSP_DIRECTION_OUT 0x2 + +struct ipsecstat { + uint64_t ipsec_tunnels; /* Number of active tunnels */ + uint64_t ipsec_prevtunnels; /* Past number of tunnels */ + uint64_t ipsec_ipackets; /* Input IPsec packets */ + uint64_t ipsec_opackets; /* Output IPsec packets */ + uint64_t ipsec_ibytes; /* Input bytes */ + uint64_t ipsec_obytes; /* Output bytes */ + uint64_t ipsec_idecompbytes; /* Input bytes, decompressed */ + uint64_t ipsec_ouncompbytes; /* Output bytes, uncompressed */ + uint64_t ipsec_idrops; /* Dropped on input */ + uint64_t ipsec_odrops; /* Dropped on output */ + uint64_t ipsec_crypto; /* Crypto processing failure */ + uint64_t ipsec_notdb; /* No TDB was found */ + uint64_t ipsec_noxform; /* Crypto error */ + uint64_t ipsec_exctdb; /* TDBs with hardlimit excess */ +}; + +struct ipsec_level { + u_char sl_auth; /* Authentication level */ + u_char sl_esp_trans; /* ESP transport level */ + u_char sl_esp_network; /* ESP network (encapsulation) level */ + u_char sl_ipcomp; /* Compression level */ +}; + +#ifdef _KERNEL + +#include +#include +#include +#include +#include + +enum ipsec_counters { + ipsec_tunnels, + ipsec_prevtunnels, + ipsec_ipackets, + ipsec_opackets, + ipsec_ibytes, + ipsec_obytes, + ipsec_idecompbytes, + ipsec_ouncompbytes, + ipsec_idrops, + ipsec_odrops, + ipsec_crypto, + ipsec_notdb, + ipsec_noxform, + ipsec_exctdb, + ipsec_ncounters +}; + +extern struct cpumem *ipseccounters; + +static inline void +ipsecstat_inc(enum ipsec_counters c) +{ + counters_inc(ipseccounters, c); +} + +static inline void +ipsecstat_dec(enum ipsec_counters c) +{ + counters_dec(ipseccounters, c); +} + +static inline void +ipsecstat_add(enum ipsec_counters c, uint64_t v) +{ + counters_add(ipseccounters, c, v); +} + +static inline void +ipsecstat_pkt(enum ipsec_counters p, enum ipsec_counters b, uint64_t v) +{ + counters_pkt(ipseccounters, p, b, v); +} + +struct m_tag; + +#define sen_data Sen.Data +#define sen_ip_src Sen.Sip4.Src +#define sen_ip_dst Sen.Sip4.Dst +#define sen_proto Sen.Sip4.Proto +#define sen_sport Sen.Sip4.Sport +#define sen_dport Sen.Sip4.Dport +#define sen_direction Sen.Sip4.Direction +#define sen_ip6_src Sen.Sip6.Src +#define sen_ip6_dst Sen.Sip6.Dst +#define sen_ip6_proto Sen.Sip6.Proto +#define sen_ip6_sport Sen.Sip6.Sport +#define sen_ip6_dport Sen.Sip6.Dport +#define sen_ip6_direction Sen.Sip6.Direction + +/* + * The "type" is really part of the address as far as the routing + * system is concerned. By using only one bit in the type field + * for each type, we sort-of make sure that different types of + * encapsulation addresses won't be matched against the wrong type. + * + */ + +#define SENT_IP4 0x0001 /* data is two struct in_addr */ +#define SENT_IP6 0x0002 + +#define SENT_LEN sizeof(struct sockaddr_encap) + +struct ipsec_id { + u_int16_t type; /* Subtype of data */ + int16_t len; /* Length of data following */ +}; + +struct ipsec_ids { + LIST_ENTRY(ipsec_ids) id_gc_list; /* [F] */ + RBT_ENTRY(ipsec_ids) id_node_id; /* [F] */ + RBT_ENTRY(ipsec_ids) id_node_flow; /* [F] */ + struct ipsec_id *id_local; /* [I] */ + struct ipsec_id *id_remote; /* [I] */ + u_int32_t id_flow; /* [I] */ + u_int id_refcount; /* [F] */ + u_int id_gc_ttl; /* [F] */ +}; +RBT_HEAD(ipsec_ids_flows, ipsec_ids); +RBT_HEAD(ipsec_ids_tree, ipsec_ids); + +struct ipsec_acquire { + union sockaddr_union ipa_addr; + u_int32_t ipa_seq; + struct sockaddr_encap ipa_info; + struct sockaddr_encap ipa_mask; + struct refcnt ipa_refcnt; + struct timeout ipa_timeout; + struct ipsec_policy *ipa_policy; /* [A] back pointer */ + TAILQ_ENTRY(ipsec_acquire) ipa_ipo_next; /* [A] per policy */ + TAILQ_ENTRY(ipsec_acquire) ipa_next; /* [A] global list */ +}; + +TAILQ_HEAD(ipsec_acquire_head, ipsec_acquire); + +struct ipsec_policy { + struct radix_node ipo_nodes[2]; /* radix tree glue */ + struct sockaddr_encap ipo_addr; + struct sockaddr_encap ipo_mask; + + union sockaddr_union ipo_src; /* Local address to use */ + union sockaddr_union ipo_dst; /* Remote gateway -- if it's zeroed: + * - on output, we try to + * contact the remote host + * directly (if needed). + * - on input, we accept on if + * the inner source is the + * same as the outer source + * address, or if transport + * mode was used. + */ + + u_int64_t ipo_last_searched; /* [P] Timestamp of lookup */ + + u_int8_t ipo_flags; /* See IPSP_POLICY_* definitions */ + u_int8_t ipo_type; /* USE/ACQUIRE/... */ + u_int8_t ipo_sproto; /* ESP/AH; if zero, use system dflts */ + u_int ipo_rdomain; + + struct refcnt ipo_refcnt; + + struct tdb *ipo_tdb; /* [P] Cached TDB entry */ + + struct ipsec_ids *ipo_ids; + + struct ipsec_acquire_head ipo_acquires; /* [A] List of acquires */ + TAILQ_ENTRY(ipsec_policy) ipo_tdb_next; /* [P] List TDB policies */ + TAILQ_ENTRY(ipsec_policy) ipo_list; /* List of all policies */ +}; + +#define IPSP_POLICY_NONE 0x0000 /* No flags set */ +#define IPSP_POLICY_STATIC 0x0002 /* Static policy */ + +#define IPSP_IPSEC_USE 0 /* Use if existing, don't acquire */ +#define IPSP_IPSEC_ACQUIRE 1 /* Try acquire, let packet through */ +#define IPSP_IPSEC_REQUIRE 2 /* Require SA */ +#define IPSP_PERMIT 3 /* Permit traffic through */ +#define IPSP_DENY 4 /* Deny traffic */ +#define IPSP_IPSEC_DONTACQ 5 /* Require, but don't acquire */ + +/* Identity types */ +#define IPSP_IDENTITY_NONE 0 +#define IPSP_IDENTITY_PREFIX 1 +#define IPSP_IDENTITY_FQDN 2 +#define IPSP_IDENTITY_USERFQDN 3 +#define IPSP_IDENTITY_ASN1_DN 4 + +struct tdb { /* tunnel descriptor block */ + /* + * Each TDB is on three hash tables: one keyed on dst/spi/sproto, + * one keyed on dst/sproto, and one keyed on src/sproto. The first + * is used for finding a specific TDB, the second for finding TDBs + * for outgoing policy matching, and the third for incoming + * policy matching. The following three fields maintain the hash + * queues in those three tables. + */ + struct tdb *tdb_hnext; /* [D] dst/spi/sproto table */ + struct tdb *tdb_dnext; /* [D] dst/sproto table */ + struct tdb *tdb_snext; /* [D] src/sproto table */ + struct tdb *tdb_inext; + struct tdb *tdb_onext; + SIMPLEQ_ENTRY(tdb) tdb_walk; /* [N] temp list for tdb walker */ + + struct refcnt tdb_refcnt; + struct mutex tdb_mtx; + + const struct xformsw *tdb_xform; /* Transform to use */ + const struct enc_xform *tdb_encalgxform; /* Enc algorithm */ + const struct auth_hash *tdb_authalgxform; /* Auth algorithm */ + const struct comp_algo *tdb_compalgxform; /* Compression algo */ + +#define TDBF_UNIQUE 0x00001 /* This should not be used by others */ +#define TDBF_TIMER 0x00002 /* Absolute expiration timer in use */ +#define TDBF_BYTES 0x00004 /* Check the byte counters */ +#define TDBF_ALLOCATIONS 0x00008 /* Check the flows counters */ +#define TDBF_INVALID 0x00010 /* This SPI is not valid yet/anymore */ +#define TDBF_FIRSTUSE 0x00020 /* Expire after first use */ +#define TDBF_DELETED 0x00040 /* This TDB has already been deleted */ +#define TDBF_SOFT_TIMER 0x00080 /* Soft expiration */ +#define TDBF_SOFT_BYTES 0x00100 /* Soft expiration */ +#define TDBF_SOFT_ALLOCATIONS 0x00200 /* Soft expiration */ +#define TDBF_SOFT_FIRSTUSE 0x00400 /* Soft expiration */ +#define TDBF_PFS 0x00800 /* Ask for PFS from Key Mgmt. */ +#define TDBF_TUNNELING 0x01000 /* Force IP-IP encapsulation */ +#define TDBF_USEDTUNNEL 0x10000 /* Appended a tunnel header in past */ +#define TDBF_UDPENCAP 0x20000 /* UDP encapsulation */ +#define TDBF_PFSYNC 0x40000 /* TDB will be synced */ +#define TDBF_PFSYNC_RPL 0x80000 /* Replay counter should be bumped */ +#define TDBF_ESN 0x100000 /* 64-bit sequence numbers (ESN) */ +#define TDBF_PFSYNC_SNAPPED 0x200000 /* entry is being dispatched to peer */ +#define TDBF_IFACE 0x400000 /* entry policy is via sec(4) */ + +#define TDBF_BITS ("\20" \ + "\1UNIQUE\2TIMER\3BYTES\4ALLOCATIONS" \ + "\5INVALID\6FIRSTUSE\7DELETED\10SOFT_TIMER" \ + "\11SOFT_BYTES\12SOFT_ALLOCATIONS\13SOFT_FIRSTUSE\14PFS" \ + "\15TUNNELING" \ + "\21USEDTUNNEL\22UDPENCAP\23PFSYNC\24PFSYNC_RPL" \ + "\25ESN" "\26IFACE") + + u_int32_t tdb_flags; /* [m] Flags related to this TDB */ + + struct timeout tdb_timer_tmo; + struct timeout tdb_first_tmo; + struct timeout tdb_stimer_tmo; + struct timeout tdb_sfirst_tmo; + + u_int32_t tdb_seq; /* Tracking number for PFKEY */ + u_int32_t tdb_exp_allocations; /* Expire after so many flows */ + u_int32_t tdb_soft_allocations; /* Expiration warning */ + u_int32_t tdb_cur_allocations; /* Total number of allocs */ + + u_int64_t tdb_exp_bytes; /* Expire after so many bytes passed */ + u_int64_t tdb_soft_bytes; /* Expiration warning */ + u_int64_t tdb_cur_bytes; /* Current count of bytes */ + + u_int64_t tdb_exp_timeout; /* When does the SPI expire */ + u_int64_t tdb_soft_timeout; /* Send soft-expire warning */ + u_int64_t tdb_established; /* When was SPI established */ + + u_int64_t tdb_first_use; /* When was it first used */ + u_int64_t tdb_soft_first_use; /* Soft warning */ + u_int64_t tdb_exp_first_use; /* Expire if tdb_first_use + + * tdb_exp_first_use <= curtime + */ + + u_int64_t tdb_last_used; /* When was this SA last used */ + u_int64_t tdb_last_marked;/* Last SKIPCRYPTO status change */ + + struct cpumem *tdb_counters; /* stats about this TDB */ + + u_int64_t tdb_cryptoid; /* Crypto session ID */ + + u_int32_t tdb_spi; /* [I] SPI */ + u_int16_t tdb_amxkeylen; /* Raw authentication key length */ + u_int16_t tdb_emxkeylen; /* Raw encryption key length */ + u_int16_t tdb_ivlen; /* IV length */ + u_int8_t tdb_sproto; /* [I] IPsec protocol */ + u_int8_t tdb_wnd; /* Replay window */ + u_int8_t tdb_satype; /* SA type (RFC2367, PF_KEY) */ + u_int8_t tdb_iface_dir; /* [I] sec(4) iface direction */ + + union sockaddr_union tdb_dst; /* [N] Destination address */ + union sockaddr_union tdb_src; /* [N] Source address */ + + u_int8_t *tdb_amxkey; /* Raw authentication key */ + u_int8_t *tdb_emxkey; /* Raw encryption key */ + +#define TDB_REPLAYWASTE 32 +#define TDB_REPLAYMAX (2100+TDB_REPLAYWASTE) + + u_int64_t tdb_rpl; /* Replay counter */ + u_int32_t tdb_seen[howmany(TDB_REPLAYMAX, 32)]; /* Anti-replay window */ + + u_int8_t tdb_iv[4]; /* Used for HALF-IV ESP */ + + struct ipsec_ids *tdb_ids; /* Src/Dst ID for this SA */ + int tdb_ids_swapped; /* XXX */ + + u_int32_t tdb_mtu; /* MTU at this point in the chain */ + u_int64_t tdb_mtutimeout; /* When to ignore this entry */ + + u_int16_t tdb_udpencap_port; /* Peer UDP port */ + + u_int16_t tdb_tag; /* Packet filter tag */ + u_int32_t tdb_tap; /* Alternate enc(4) interface */ + unsigned int tdb_iface; /* [I] sec(4) iface */ + + u_int tdb_rdomain; /* [I] Routing domain */ + u_int tdb_rdomain_post; /* [I] Change domain */ + + struct sockaddr_encap tdb_filter; /* What traffic is acceptable */ + struct sockaddr_encap tdb_filtermask; /* And the mask */ + + TAILQ_HEAD(tdb_policy_head, ipsec_policy) tdb_policy_head; /* [P] */ + TAILQ_ENTRY(tdb) tdb_sync_entry; /* [S] pfsync tdb queue */ + u_int32_t tdb_updates; /* [S] pfsync update counter */ +}; + +enum tdb_counters { + tdb_ipackets, /* Input IPsec packets */ + tdb_opackets, /* Output IPsec packets */ + tdb_ibytes, /* Input bytes */ + tdb_obytes, /* Output bytes */ + tdb_idrops, /* Dropped on input */ + tdb_odrops, /* Dropped on output */ + tdb_idecompbytes, /* Input bytes, decompressed */ + tdb_ouncompbytes, /* Output bytes, uncompressed */ + tdb_ncounters +}; + +static inline void +tdbstat_inc(struct tdb *tdb, enum tdb_counters c) +{ + counters_inc(tdb->tdb_counters, c); +} + +static inline void +tdbstat_add(struct tdb *tdb, enum tdb_counters c, uint64_t v) +{ + counters_add(tdb->tdb_counters, c, v); +} + +static inline void +tdbstat_pkt(struct tdb *tdb, enum tdb_counters pc, enum tdb_counters bc, + uint64_t bytes) +{ + counters_pkt(tdb->tdb_counters, pc, bc, bytes); +} + +struct tdb_ident { + u_int32_t spi; + union sockaddr_union dst; + u_int8_t proto; + u_int rdomain; +}; + +struct tdb_crypto { + union sockaddr_union tc_dst; + u_int64_t tc_rpl; + u_int32_t tc_spi; + int tc_protoff; + int tc_skip; + u_int tc_rdomain; + u_int8_t tc_proto; +}; + +struct ipsecinit { + u_int8_t *ii_enckey; + u_int8_t *ii_authkey; + u_int16_t ii_enckeylen; + u_int16_t ii_authkeylen; + u_int8_t ii_encalg; + u_int8_t ii_authalg; + u_int8_t ii_compalg; +}; + +/* xform IDs */ +#define XF_IP4 1 /* IP inside IP */ +#define XF_AH 2 /* AH */ +#define XF_ESP 3 /* ESP */ +#define XF_TCPSIGNATURE 5 /* TCP MD5 Signature option, RFC 2358 */ +#define XF_IPCOMP 6 /* IPCOMP */ + +/* xform attributes */ +#define XFT_AUTH 0x0001 +#define XFT_CONF 0x0100 +#define XFT_COMP 0x1000 + +#define IPSEC_ZEROES_SIZE 256 /* Larger than an IP6 extension hdr. */ + +struct xformsw { + u_short xf_type; /* Unique ID of xform */ + u_short xf_flags; /* flags (see below) */ + char *xf_name; /* human-readable name */ + int (*xf_attach)(void); /* called at config time */ + int (*xf_init)(struct tdb *, const struct xformsw *, + struct ipsecinit *); + int (*xf_zeroize)(struct tdb *); /* termination */ + int (*xf_input)(struct mbuf **, struct tdb *, int, int, + struct netstack *); + int (*xf_output)(struct mbuf *, struct tdb *, int, int); +}; + +extern int ipsec_in_use; +extern u_int64_t ipsec_last_added; +extern int encdebug; /* enable message reporting */ +extern struct pool tdb_pool; + +extern int ipsec_keep_invalid; /* lifetime of embryonic SAs (in sec) */ +extern int ipsec_require_pfs; /* use Perfect Forward Secrecy */ +extern int ipsec_expire_acquire; /* wait for security assoc. (in sec) */ +extern int ipsec_soft_allocations; /* flows/SA before renegotiation */ +extern int ipsec_exp_allocations; /* num. of flows/SA before it expires */ +extern int ipsec_soft_bytes; /* bytes/SA before renegotiation */ +extern int ipsec_exp_bytes; /* num of bytes/SA before it expires */ +extern int ipsec_soft_timeout; /* seconds/SA before renegotiation */ +extern int ipsec_exp_timeout; /* seconds/SA before it expires */ +extern int ipsec_soft_first_use; /* seconds between 1st asso & renego */ +extern int ipsec_exp_first_use; /* seconds between 1st asso & expire */ + +/* + * Names for IPsec sysctl objects + */ +#define IPSEC_ENCDEBUG IPCTL_ENCDEBUG /* 12 */ +#define IPSEC_STATS IPCTL_IPSEC_STATS /* 13 */ +#define IPSEC_EXPIRE_ACQUIRE IPCTL_IPSEC_EXPIRE_ACQUIRE /* 14 */ +#define IPSEC_EMBRYONIC_SA_TIMEOUT IPCTL_IPSEC_EMBRYONIC_SA_TIMEOUT/* 15 */ +#define IPSEC_REQUIRE_PFS IPCTL_IPSEC_REQUIRE_PFS /* 16 */ +#define IPSEC_SOFT_ALLOCATIONS IPCTL_IPSEC_SOFT_ALLOCATIONS /* 17 */ +#define IPSEC_ALLOCATIONS IPCTL_IPSEC_ALLOCATIONS /* 18 */ +#define IPSEC_SOFT_BYTES IPCTL_IPSEC_SOFT_BYTES /* 19 */ +#define IPSEC_BYTES IPCTL_IPSEC_BYTES /* 20 */ +#define IPSEC_TIMEOUT IPCTL_IPSEC_TIMEOUT /* 21 */ +#define IPSEC_SOFT_TIMEOUT IPCTL_IPSEC_SOFT_TIMEOUT /* 22 */ +#define IPSEC_SOFT_FIRSTUSE IPCTL_IPSEC_SOFT_FIRSTUSE /* 23 */ +#define IPSEC_FIRSTUSE IPCTL_IPSEC_FIRSTUSE /* 24 */ +#define IPSEC_MAXID 25 + +enum { + IPSEC_ENC_AES, + IPSEC_ENC_AESCTR, + IPSEC_ENC_3DES, + IPSEC_ENC_BLOWFISH, + IPSEC_ENC_CAST128, +}; + +enum { + IPSEC_AUTH_HMAC_SHA1, + IPSEC_AUTH_HMAC_RIPEMD160, + IPSEC_AUTH_MD5, + IPSEC_AUTH_SHA2_256, + IPSEC_AUTH_SHA2_384, + IPSEC_AUTH_SHA2_512, +}; + +enum { + IPSEC_COMP_DEFLATE, +}; + +extern int ipsec_def_enc; +extern int ipsec_def_auth; +extern int ipsec_def_comp; + +extern TAILQ_HEAD(ipsec_policy_head, ipsec_policy) ipsec_policy_head; + +extern struct mutex tdb_sadb_mtx; +extern struct mutex ipo_tdb_mtx; + +struct cryptop; + +/* Misc. */ +const char *ipsp_address(union sockaddr_union *, char *, socklen_t); + +/* SPD tables */ +struct radix_node_head *spd_table_add(unsigned int); +struct radix_node_head *spd_table_get(unsigned int); +int spd_table_walk(unsigned int, + int (*walker)(struct ipsec_policy *, void *, unsigned int), void *); + +/* TDB management routines */ +uint32_t reserve_spi(u_int, u_int32_t, u_int32_t, union sockaddr_union *, + union sockaddr_union *, u_int8_t, int *); +struct tdb *gettdb_dir(u_int, u_int32_t, union sockaddr_union *, u_int8_t, int); +#define gettdb(a,b,c,d) gettdb_dir((a),(b),(c),(d),0) +#define gettdb_rev(a,b,c,d) gettdb_dir((a),(b),(c),(d),1) +struct tdb *gettdbbydst(u_int, union sockaddr_union *, u_int8_t, + struct ipsec_ids *, + struct sockaddr_encap *, struct sockaddr_encap *); +struct tdb *gettdbbysrc(u_int, union sockaddr_union *, u_int8_t, + struct ipsec_ids *, + struct sockaddr_encap *, struct sockaddr_encap *); +struct tdb *gettdbbysrcdst_dir(u_int, u_int32_t, union sockaddr_union *, + union sockaddr_union *, u_int8_t, int); +#define gettdbbysrcdst(a,b,c,d,e) gettdbbysrcdst_dir((a),(b),(c),(d),(e),0) +#define gettdbbysrcdst_rev(a,b,c,d,e) gettdbbysrcdst_dir((a),(b),(c),(d),(e),1) +void puttdb(struct tdb *); +void puttdb_locked(struct tdb *); +void tdb_delete(struct tdb *); +struct tdb *tdb_alloc(u_int); +struct tdb *tdb_ref(struct tdb *); +void tdb_unref(struct tdb *); +void tdb_free(struct tdb *); +int tdb_init(struct tdb *, u_int16_t, struct ipsecinit *); +void tdb_unlink(struct tdb *); +void tdb_unlink_locked(struct tdb *); +void tdb_cleanspd(struct tdb *); +void tdb_unbundle(struct tdb *); +void tdb_addtimeouts(struct tdb *); +void tdb_deltimeouts(struct tdb *); +int tdb_walk(u_int, int (*)(struct tdb *, void *, int), void *); +void tdb_printit(void *, int, int (*)(const char *, ...)); + +/* XF_IP4 */ +int ipe4_attach(void); +int ipe4_init(struct tdb *, const struct xformsw *, struct ipsecinit *); +int ipe4_zeroize(struct tdb *); +int ipe4_input(struct mbuf **, struct tdb *, int, int, struct netstack *); + +/* XF_AH */ +int ah_attach(void); +int ah_init(struct tdb *, const struct xformsw *, struct ipsecinit *); +int ah_zeroize(struct tdb *); +int ah_input(struct mbuf **, struct tdb *, int, int, struct netstack *); +int ah_output(struct mbuf *, struct tdb *, int, int); +int ah_sysctl(int *, u_int, void *, size_t *, void *, size_t); + +int ah46_input(struct mbuf **, int *, int, int, struct netstack *); +void ah4_ctlinput(int, struct sockaddr *, u_int, void *); +void udpencap_ctlinput(int, struct sockaddr *, u_int, void *); + +/* XF_ESP */ +int esp_attach(void); +int esp_init(struct tdb *, const struct xformsw *, struct ipsecinit *); +int esp_zeroize(struct tdb *); +int esp_input(struct mbuf **, struct tdb *, int, int, struct netstack *); +int esp_output(struct mbuf *, struct tdb *, int, int); +int esp_sysctl(int *, u_int, void *, size_t *, void *, size_t); + +int esp46_input(struct mbuf **, int *, int, int, struct netstack *); +void esp4_ctlinput(int, struct sockaddr *, u_int, void *); + +/* XF_IPCOMP */ +int ipcomp_attach(void); +int ipcomp_init(struct tdb *, const struct xformsw *, struct ipsecinit *); +int ipcomp_zeroize(struct tdb *); +int ipcomp_input(struct mbuf **, struct tdb *, int, int, struct netstack *); +int ipcomp_output(struct mbuf *, struct tdb *, int, int); +int ipcomp_sysctl(int *, u_int, void *, size_t *, void *, size_t); +int ipcomp46_input(struct mbuf **, int *, int, int, struct netstack *); + +/* XF_TCPSIGNATURE */ +int tcp_signature_tdb_attach(void); +int tcp_signature_tdb_init(struct tdb *, const struct xformsw *, + struct ipsecinit *); +int tcp_signature_tdb_zeroize(struct tdb *); +int tcp_signature_tdb_input(struct mbuf **, struct tdb *, int, int, + struct netstack *); +int tcp_signature_tdb_output(struct mbuf *, struct tdb *, int, int); + +/* Replay window */ +int checkreplaywindow(struct tdb *, u_int64_t, u_int32_t, u_int32_t *, int); + +/* Packet processing */ +#define IPSP_DF_INHERIT -1 +#define IPSP_DF_OFF 0 +#define IPSP_DF_ON 1 + +int ipsp_process_packet(struct mbuf *, struct tdb *, int, int, int); +int ipsp_process_done(struct mbuf *, struct tdb *); +int ipsp_spd_lookup(struct mbuf *, int, int, int, struct tdb *, + const struct ipsec_level *, struct tdb **, struct ipsec_ids *); +int ipsp_is_unspecified(union sockaddr_union); +int ipsp_aux_match(struct tdb *, struct ipsec_ids *, + struct sockaddr_encap *, struct sockaddr_encap *); +int ipsp_ids_match(struct ipsec_ids *, struct ipsec_ids *); +struct ipsec_ids *ipsp_ids_insert(struct ipsec_ids *); +struct ipsec_ids *ipsp_ids_lookup(u_int32_t); +void ipsp_ids_free(struct ipsec_ids *); + +void ipsp_init(void); +void ipsec_init(void); +int ipsec_sysctl(int *, u_int, void *, size_t *, void *, size_t); +int ipsec_common_input(struct mbuf **, int, int, int, int, int, + struct netstack *); +int ipsec_common_input_cb(struct mbuf **, struct tdb *, int, int, + struct netstack *); +int ipsec_input_disabled(struct mbuf **, int *, int, int, + struct netstack *); +int ipsec_protoff(struct mbuf *, int, int); +int ipsec_delete_policy(struct ipsec_policy *); +ssize_t ipsec_hdrsz(struct tdb *); +void ipsec_adjust_mtu(struct mbuf *, u_int32_t); +void ipsec_set_mtu(struct tdb *, u_int32_t); +struct ipsec_acquire *ipsec_get_acquire(u_int32_t); +void ipsec_unref_acquire(struct ipsec_acquire *); +int ipsec_forward_check(struct mbuf *, int, int); +int ipsec_local_check(struct mbuf *, int, int, int); + +#endif /* _KERNEL */ +#endif /* _NETINET_IPSP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/ip_mroute.h b/lib/libc/include/generic-openbsd/netinet/ip_mroute.h new file mode 100644 index 0000000000..d800b3c872 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/ip_mroute.h @@ -0,0 +1,261 @@ +/* $OpenBSD: ip_mroute.h,v 1.34 2025/05/09 14:43:47 jan Exp $ */ +/* $NetBSD: ip_mroute.h,v 1.23 2004/04/21 17:49:46 itojun Exp $ */ + +#ifndef _NETINET_IP_MROUTE_H_ +#define _NETINET_IP_MROUTE_H_ + +/* + * Definitions for IP multicast forwarding. + * + * Written by David Waitzman, BBN Labs, August 1988. + * Modified by Steve Deering, Stanford, February 1989. + * Modified by Ajit Thyagarajan, PARC, August 1993. + * Modified by Ajit Thyagarajan, PARC, August 1994. + * Modified by Ahmed Helmy, SGI, June 1996. + * Modified by Pavlin Radoslavov, ICSI, October 2002. + * + * MROUTING Revision: 1.2 + * advanced API support, bandwidth metering and signaling. + */ + +/* + * Multicast Routing set/getsockopt commands. + */ +#define MRT_INIT 100 /* initialize forwarder */ +#define MRT_DONE 101 /* shut down forwarder */ +#define MRT_ADD_VIF 102 /* create virtual interface */ +#define MRT_DEL_VIF 103 /* delete virtual interface */ +#define MRT_ADD_MFC 104 /* insert forwarding cache entry */ +#define MRT_DEL_MFC 105 /* delete forwarding cache entry */ +#define MRT_VERSION 106 /* get kernel version number */ +#define MRT_ASSERT 107 /* enable assert processing */ +#define MRT_API_SUPPORT 109 /* supported MRT API */ +#define MRT_API_CONFIG 110 /* config MRT API */ + +/* + * Types and macros for handling bitmaps with one bit per virtual interface. + */ +#define MAXVIFS 32 +typedef u_int32_t vifbitmap_t; +typedef u_int16_t vifi_t; /* type of a vif index */ + +#define VIFM_SET(n, m) ((m) |= (1 << (n))) +#define VIFM_CLR(n, m) ((m) &= ~(1 << (n))) +#define VIFM_ISSET(n, m) ((m) & (1 << (n))) +#define VIFM_CLRALL(m) ((m) = 0x00000000) +#define VIFM_COPY(mfrom, mto) ((mto) = (mfrom)) +#define VIFM_SAME(m1, m2) ((m1) == (m2)) + +#define VIFF_TUNNEL 0x1 /* vif represents a tunnel end-point */ +#define VIFF_SRCRT 0x2 /* tunnel uses IP src routing */ + +/* + * Argument structure for MRT_ADD_VIF. + * (MRT_DEL_VIF takes a single vifi_t argument.) + */ +struct vifctl { + vifi_t vifc_vifi; /* the index of the vif to be added */ + u_int8_t vifc_flags; /* VIFF_ flags defined above */ + u_int8_t vifc_threshold; /* min ttl required to forward on vif */ + u_int32_t vifc_rate_limit; /* ignored */ + struct in_addr vifc_lcl_addr;/* local interface address */ + struct in_addr vifc_rmt_addr;/* remote address (tunnels only) */ +}; + +/* + * Argument structure for MRT_ADD_MFC and MRT_DEL_MFC. + * XXX if you change this, make sure to change struct mfcctl2 as well. + */ +struct mfcctl { + struct in_addr mfcc_origin; /* ip origin of mcasts */ + struct in_addr mfcc_mcastgrp; /* multicast group associated */ + vifi_t mfcc_parent; /* incoming vif */ + u_int8_t mfcc_ttls[MAXVIFS]; /* forwarding ttls on vifs */ +}; + +/* + * The new argument structure for MRT_ADD_MFC and MRT_DEL_MFC overlays + * and extends the old struct mfcctl. + */ +struct mfcctl2 { + /* the mfcctl fields */ + struct in_addr mfcc_origin; /* ip origin of mcasts */ + struct in_addr mfcc_mcastgrp; /* multicast group associated*/ + vifi_t mfcc_parent; /* incoming vif */ + u_int8_t mfcc_ttls[MAXVIFS]; /* forwarding ttls on vifs */ + + /* extension fields */ + u_int8_t mfcc_flags[MAXVIFS]; /* the MRT_MFC_FLAGS_* flags */ + struct in_addr mfcc_rp; /* the RP address */ +}; +/* + * The advanced-API flags. + * + * The MRT_MFC_FLAGS_XXX API flags are also used as flags + * for the mfcc_flags field. + */ +#define MRT_MFC_FLAGS_DISABLE_WRONGVIF (1 << 0) /* disable WRONGVIF signals */ +#define MRT_MFC_RP (1 << 8) /* enable RP address */ +#define MRT_MFC_BW_UPCALL (1 << 9) /* enable bw upcalls */ +#define MRT_MFC_FLAGS_ALL (MRT_MFC_FLAGS_DISABLE_WRONGVIF) +#define MRT_API_FLAGS_ALL (MRT_MFC_FLAGS_ALL | \ + MRT_MFC_RP | \ + MRT_MFC_BW_UPCALL) + +/* structure used to get all the mfc entries */ +struct mfcinfo { + struct in_addr mfc_origin; /* ip origin of mcasts */ + struct in_addr mfc_mcastgrp; /* multicast group associated */ + vifi_t mfc_parent; /* incoming vif */ + u_long mfc_pkt_cnt; /* pkt count for src-grp */ + u_long mfc_byte_cnt; /* byte count for src-grp */ + u_int8_t mfc_ttls[MAXVIFS]; /* forwarding ttls on vifs */ +}; + +/* structure used to get all the vif entries */ +struct vifinfo { + vifi_t v_vifi; /* the index of the vif to be added */ + u_int8_t v_flags; /* VIFF_ flags defined above */ + u_int8_t v_threshold; /* min ttl required to forward on vif */ + struct in_addr v_lcl_addr; /* local interface address */ + struct in_addr v_rmt_addr; /* remote address (tunnels only) */ + u_long v_pkt_in; /* # pkts in on interface */ + u_long v_pkt_out; /* # pkts out on interface */ + u_long v_bytes_in; /* # bytes in on interface */ + u_long v_bytes_out; /* # bytes out on interface */ +}; + +/* + * Argument structure used by mrouted to get src-grp pkt counts. + */ +struct sioc_sg_req { + struct in_addr src; + struct in_addr grp; + u_long pktcnt; + u_long bytecnt; + u_long wrong_if; +}; + +/* + * Argument structure used by mrouted to get vif pkt counts. + */ +struct sioc_vif_req { + vifi_t vifi; /* vif number */ + u_long icount; /* input packet count on vif */ + u_long ocount; /* output packet count on vif */ + u_long ibytes; /* input byte count on vif */ + u_long obytes; /* output byte count on vif */ +}; + + +/* + * The kernel's multicast routing statistics. + */ +struct mrtstat { + u_long mrts_mfc_lookups; /* # forw. cache hash table hits */ + u_long mrts_mfc_misses; /* # forw. cache hash table misses */ + u_long mrts_upcalls; /* # calls to mrouted */ + u_long mrts_no_route; /* no route for packet's origin */ + u_long mrts_bad_tunnel; /* malformed tunnel options */ + u_long mrts_cant_tunnel; /* no room for tunnel options */ + u_long mrts_wrong_if; /* arrived on wrong interface */ + u_long mrts_upq_ovflw; /* upcall Q overflow */ + u_long mrts_cache_cleanups; /* # entries with no upcalls */ + u_long mrts_drop_sel; /* pkts dropped selectively */ + u_long mrts_q_overflow; /* pkts dropped - Q overflow */ + u_long mrts_pkt2large; /* pkts dropped - size > BKT SIZE */ + u_long mrts_upq_sockfull; /* upcalls dropped - socket full */ +}; + +#ifdef _KERNEL + +enum mrtstat_counters { + mrts_mfc_lookups, + mrts_mfc_misses, + mrts_upcalls, + mrts_no_route, + mrts_bad_tunnel, + mrts_cant_tunnel, + mrts_wrong_if, + mrts_upq_ovflw, + mrts_cache_cleanups, + mrts_drop_sel, + mrts_q_overflow, + mrts_pkt2large, + mrts_upq_sockfull, + mrts_ncounters +}; + +extern struct cpumem *mrtcounters; + +static inline void +mrtstat_inc(enum mrtstat_counters c) +{ + counters_inc(mrtcounters, c); +} + +/* How frequent should we look for expired entries (in seconds). */ +#define MCAST_EXPIRE_FREQUENCY 30 + +extern int ip_mrtproto; + +/* + * The kernel's virtual-interface structure. + */ +struct vif { + vifi_t v_id; /* Virtual interface index */ + u_int8_t v_flags; /* VIFF_ flags defined above */ + u_int8_t v_threshold; /* min ttl required to forward on vif */ + struct in_addr v_lcl_addr; /* local interface address */ + struct in_addr v_rmt_addr; /* remote address (tunnels only) */ + u_long v_pkt_in; /* # pkts in on interface */ + u_long v_pkt_out; /* # pkts out on interface */ + u_long v_bytes_in; /* # bytes in on interface */ + u_long v_bytes_out; /* # bytes out on interface */ +}; + +/* + * The kernel's multicast forwarding cache entry structure. + * (A field for the type of service (mfc_tos) is to be added + * at a future point.) + */ +struct mfc { + vifi_t mfc_parent; /* incoming vif */ + u_long mfc_pkt_cnt; /* pkt count for src-grp */ + u_long mfc_byte_cnt; /* byte count for src-grp */ + u_long mfc_wrong_if; /* wrong if for src-grp */ + uint8_t mfc_ttl; /* route interface ttl */ + uint8_t mfc_flags; /* MRT_MFC_FLAGS_* flags */ + struct in_addr mfc_rp; /* the RP address */ + u_long mfc_expire; /* expire timer */ +}; + +/* + * Structure used to communicate from kernel to multicast router. + * (Note the convenient similarity to an IP packet.) + */ +struct igmpmsg { + u_int32_t unused1; + u_int32_t unused2; + u_int8_t im_msgtype; /* what type of message */ +#define IGMPMSG_NOCACHE 1 /* no MFC in the kernel */ +#define IGMPMSG_WRONGVIF 2 /* packet came from wrong interface */ +#define IGMPMSG_BW_UPCALL 4 /* BW monitoring upcall */ + u_int8_t im_mbz; /* must be zero */ + u_int8_t im_vif; /* vif rec'd on */ + u_int8_t unused3; + struct in_addr im_src, im_dst; +}; + +int ip_mrouter_set(struct socket *, int, struct mbuf *); +int ip_mrouter_get(struct socket *, int, struct mbuf *); +void mrt_init(void); +int mrt_ioctl(struct socket *, u_long, caddr_t); +int mrt_sysctl_vif(void *, size_t *); +int mrt_sysctl_mrtstat(void *, size_t *, void *); +int mrt_sysctl_mfc(void *, size_t *); +int ip_mrouter_done(struct socket *); +void vif_delete(struct ifnet *); + +#endif /* _KERNEL */ +#endif /* _NETINET_IP_MROUTE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/ip_var.h b/lib/libc/include/generic-openbsd/netinet/ip_var.h new file mode 100644 index 0000000000..69ef765c4f --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/ip_var.h @@ -0,0 +1,289 @@ +/* $OpenBSD: ip_var.h,v 1.123 2025/07/31 09:05:11 mvs Exp $ */ +/* $NetBSD: ip_var.h,v 1.16 1996/02/13 23:43:20 christos Exp $ */ + +/* + * Copyright (c) 1982, 1986, 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. + * + * @(#)ip_var.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NETINET_IP_VAR_H_ +#define _NETINET_IP_VAR_H_ + +/* + * Structure stored in mbuf in inpcb.ip_options + * and passed to ip_output when ip options are in use. + * The actual length of the options (including ipopt_dst) + * is in m_len. + */ +#define MAX_IPOPTLEN 40 + +/* + * Overlay for ip header used by other protocols (tcp, udp). + */ +struct ipovly { + u_int8_t ih_x1[9]; /* (unused) */ + u_int8_t ih_pr; /* protocol */ + u_int16_t ih_len; /* protocol length */ + struct in_addr ih_src; /* source internet address */ + struct in_addr ih_dst; /* destination internet address */ +}; + +struct ipstat { + u_long ips_total; /* total packets received */ + u_long ips_badsum; /* checksum bad */ + u_long ips_tooshort; /* packet too short */ + u_long ips_toosmall; /* not enough data */ + u_long ips_badhlen; /* ip header length < data size */ + u_long ips_badlen; /* ip length < ip header length */ + u_long ips_fragments; /* fragments received */ + u_long ips_fragdropped; /* frags dropped (dups, out of space) */ + u_long ips_fragtimeout; /* fragments timed out */ + u_long ips_forward; /* packets forwarded */ + u_long ips_cantforward; /* packets rcvd for unreachable dest */ + u_long ips_redirectsent; /* packets forwarded on same net */ + u_long ips_noproto; /* unknown or unsupported protocol */ + u_long ips_delivered; /* datagrams delivered to upper level*/ + u_long ips_localout; /* total ip packets generated here */ + u_long ips_odropped; /* lost output due to nobufs, etc. */ + u_long ips_reassembled; /* total packets reassembled ok */ + u_long ips_fragmented; /* datagrams successfully fragmented */ + u_long ips_ofragments; /* output fragments created */ + u_long ips_cantfrag; /* don't fragment flag was set, etc. */ + u_long ips_badoptions; /* error in option processing */ + u_long ips_noroute; /* packets discarded due to no route */ + u_long ips_badvers; /* ip version != 4 */ + u_long ips_rawout; /* total raw ip packets generated */ + u_long ips_badfrags; /* malformed fragments (bad length) */ + u_long ips_rcvmemdrop; /* frags dropped for lack of memory */ + u_long ips_toolong; /* ip length > max ip packet size */ + u_long ips_nogif; /* no match gif found */ + u_long ips_badaddr; /* invalid address on header */ + u_long ips_inswcsum; /* software checksummed on input */ + u_long ips_outswcsum; /* software checksummed on output */ + u_long ips_notmember; /* multicasts for unregistered groups */ + u_long ips_rtcachehit; /* valid route found in cache */ + u_long ips_rtcachemiss; /* route cache with new destination */ + u_long ips_wrongif; /* packet received on wrong interface */ + u_long ips_idropped; /* lost input due to nobufs, etc. */ +}; + +struct ipoption { + struct in_addr ipopt_dst; /* first-hop dst if source routed */ + int8_t ipopt_list[MAX_IPOPTLEN]; /* options proper */ +}; + +#ifdef _KERNEL + +#include + +enum ipstat_counters { + ips_total, /* total packets received */ + ips_badsum, /* checksum bad */ + ips_tooshort, /* packet too short */ + ips_toosmall, /* not enough data */ + ips_badhlen, /* ip header length < data size */ + ips_badlen, /* ip length < ip header length */ + ips_fragments, /* fragments received */ + ips_fragdropped, /* frags dropped (dups, out of space) */ + ips_fragtimeout, /* fragments timed out */ + ips_forward, /* packets forwarded */ + ips_cantforward, /* packets rcvd for unreachable dest */ + ips_redirectsent, /* packets forwarded on same net */ + ips_noproto, /* unknown or unsupported protocol */ + ips_delivered, /* datagrams delivered to upper level*/ + ips_localout, /* total ip packets generated here */ + ips_odropped, /* lost output packets due to nobufs, etc. */ + ips_reassembled, /* total packets reassembled ok */ + ips_fragmented, /* datagrams successfully fragmented */ + ips_ofragments, /* output fragments created */ + ips_cantfrag, /* don't fragment flag was set, etc. */ + ips_badoptions, /* error in option processing */ + ips_noroute, /* packets discarded due to no route */ + ips_badvers, /* ip version != 4 */ + ips_rawout, /* total raw ip packets generated */ + ips_badfrags, /* malformed fragments (bad length) */ + ips_rcvmemdrop, /* frags dropped for lack of memory */ + ips_toolong, /* ip length > max ip packet size */ + ips_nogif, /* no match gif found */ + ips_badaddr, /* invalid address on header */ + ips_inswcsum, /* software checksummed on input */ + ips_outswcsum, /* software checksummed on output */ + ips_notmember, /* multicasts for unregistered groups */ + ips_rtcachehit, /* valid route to destination found in cache */ + ips_rtcachemiss, /* route cache filled with new destination */ + ips_wrongif, /* packet received on wrong interface */ + ips_idropped, /* lost input packets due to nobufs, etc. */ + + ips_ncounters +}; + +extern struct cpumem *ipcounters; + +static inline void +ipstat_inc(enum ipstat_counters c) +{ + counters_inc(ipcounters, c); +} + +static inline void +ipstat_add(enum ipstat_counters c, uint64_t v) +{ + counters_add(ipcounters, c, v); +} + +/* + * Structure attached to inpcb.ip_moptions and + * passed to ip_output when IP multicast options are in use. + */ +struct ip_moptions { + struct in_multi **imo_membership; /* group memberships */ + unsigned short imo_ifidx; /* ifp index for outgoing multicasts */ + u_int8_t imo_ttl; /* TTL for outgoing multicasts */ + u_int8_t imo_loop; /* 1 => hear sends if a member */ + u_int16_t imo_num_memberships; /* no. memberships this socket */ + u_int16_t imo_max_memberships; /* max memberships this socket */ +}; + +#include + +/* + * Ip reassembly queue structures. + */ +LIST_HEAD(ipqehead, ipqent); +struct ipqent { + LIST_ENTRY(ipqent) ipqe_q; + struct ip *ipqe_ip; + struct mbuf *ipqe_m; /* mbuf contains packet */ + uint16_t ipqe_mff; /* for IP fragmentation */ +}; + +/* + * Ip reassembly queue structure. Each fragment + * being reassembled is attached to one of these structures. + * They are timed out after ipq_ttl drops to 0, and may also + * be reclaimed if memory becomes tight. + */ +struct ipq { + LIST_ENTRY(ipq) ipq_q; /* to other reass headers */ + u_int8_t ipq_ttl; /* time for reass q to live */ + u_int8_t ipq_p; /* protocol of this fragment */ + u_int16_t ipq_id; /* sequence id for reassembly */ + struct ipqehead ipq_fragq; /* to ip fragment queue */ + struct in_addr ipq_src, ipq_dst; +}; + +struct ipoffnxt { + int ion_off; + int ion_nxt; +}; + +/* flags passed to ip_output */ +#define IP_FORWARDING 0x0001 /* most of ip header exists */ +#define IP_RAWOUTPUT 0x0002 /* raw ip header exists */ +#define IP_REDIRECT 0x0004 /* redirected by pf or source route */ +#define IP_FORWARDING_IPSEC 0x0008 /* only packets processed by IPsec */ +#define IP_ALLOWBROADCAST SO_BROADCAST /* can send broadcast packets */ +#define IP_MTUDISC 0x0800 /* pmtu discovery, set DF */ + +extern struct ipstat ipstat; +extern int ip_defttl; /* default IP ttl */ + +#define IPMTUDISCTIMEOUT (10 * 60) /* as per RFC 1191 */ + +extern int ip_mtudisc; /* mtu discovery */ +extern int ip_mtudisc_timeout; /* seconds to timeout mtu discovery */ + +extern int ipport_firstauto; /* min port for port allocation */ +extern int ipport_lastauto; /* max port for port allocation */ +extern int ipport_hifirstauto; /* min dynamic/private port number */ +extern int ipport_hilastauto; /* max dynamic/private port number */ +extern int ip_forwarding; /* enable IP forwarding */ +#ifdef MROUTING +extern int ipmforwarding; /* enable multicast forwarding */ +#endif +extern int ipmultipath; /* enable multipath routing */ +extern int ip_directedbcast; /* accept all broadcast packets */ +extern unsigned int la_hold_total; + +extern const struct pr_usrreqs rip_usrreqs; + +extern struct rttimer_queue ip_mtudisc_timeout_q; +extern struct pool ipqent_pool; +struct rtentry; +struct route; +struct inpcb; +struct ipsec_level; + +int ip_ctloutput(int, struct socket *, int, int, struct mbuf *); +int ip_fragment(struct mbuf *, struct mbuf_list *, struct ifnet *, u_long); +void ip_freemoptions(struct ip_moptions *); +int ip_getmoptions(int, struct ip_moptions *, struct mbuf *); +void ip_init(void); +struct mbuf* + ip_insertoptions(struct mbuf *, struct mbuf *, int *); +int ip_mforward(struct mbuf *, struct ifnet *, int); +int ip_optcopy(struct ip *, struct ip *); +int ip_output(struct mbuf *, struct mbuf *, struct route *, int, + struct ip_moptions *, const struct ipsec_level *, u_int32_t); +u_int16_t + ip_randomid(void); +void ip_send(struct mbuf *); +void ip_send_raw(struct mbuf *); +void ip_slowtimo(void); +struct mbuf * + ip_srcroute(struct mbuf *); +void ip_stripoptions(struct mbuf *); +int ip_sysctl(int *, u_int, void *, size_t *, void *, size_t); +void ip_savecontrol(struct inpcb *, struct mbuf **, struct ip *, + struct mbuf *); +int ip_input_if(struct mbuf **, int *, int, int, struct ifnet *, + struct netstack *); +int ip_deliver(struct mbuf **, int *, int, int, int, struct netstack *); +void ip_forward(struct mbuf *, struct ifnet *, struct route *, int); +int rip_ctloutput(int, struct socket *, int, int, struct mbuf *); +void rip_init(void); +int rip_input(struct mbuf **, int *, int, int, struct netstack *); +int rip_output(struct mbuf *, struct socket *, struct sockaddr *, + struct mbuf *); +struct mbuf * + rip_chkhdr(struct mbuf *, struct mbuf *); +int rip_attach(struct socket *, int, int); +int rip_detach(struct socket *); +int rip_bind(struct socket *, struct mbuf *, struct proc *); +int rip_connect(struct socket *, struct mbuf *); +int rip_disconnect(struct socket *); +int rip_shutdown(struct socket *); +int rip_send(struct socket *, struct mbuf *, struct mbuf *, + struct mbuf *); +#ifdef MROUTING +extern struct socket *ip_mrouter[]; /* multicast routing daemon */ +#endif + +#endif /* _KERNEL */ +#endif /* _NETINET_IP_VAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/tcp.h b/lib/libc/include/generic-openbsd/netinet/tcp.h new file mode 100644 index 0000000000..a1eae184a4 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/tcp.h @@ -0,0 +1,222 @@ +/* $OpenBSD: tcp.h,v 1.24 2023/05/19 01:04:39 guenther Exp $ */ +/* $NetBSD: tcp.h,v 1.8 1995/04/17 05:32:58 cgd Exp $ */ + +/* + * Copyright (c) 1982, 1986, 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. + * + * @(#)tcp.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NETINET_TCP_H_ +#define _NETINET_TCP_H_ + +#include + +#if __BSD_VISIBLE + +typedef u_int32_t tcp_seq; + +/* + * TCP header. + * Per RFC 793, September, 1981. + */ +struct tcphdr { + u_int16_t th_sport; /* source port */ + u_int16_t th_dport; /* destination port */ + tcp_seq th_seq; /* sequence number */ + tcp_seq th_ack; /* acknowledgement number */ +#if _BYTE_ORDER == _LITTLE_ENDIAN + u_int32_t th_x2:4, /* (unused) */ + th_off:4; /* data offset */ +#endif +#if _BYTE_ORDER == _BIG_ENDIAN + u_int32_t th_off:4, /* data offset */ + th_x2:4; /* (unused) */ +#endif + u_int8_t th_flags; +#define TH_FIN 0x01 +#define TH_SYN 0x02 +#define TH_RST 0x04 +#define TH_PUSH 0x08 +#define TH_ACK 0x10 +#define TH_URG 0x20 +#define TH_ECE 0x40 +#define TH_CWR 0x80 + u_int16_t th_win; /* window */ + u_int16_t th_sum; /* checksum */ + u_int16_t th_urp; /* urgent pointer */ +}; +#define th_reseqlen th_urp /* TCP data length for + resequencing/reassembly */ + +#define TCPOPT_EOL 0 +#define TCPOPT_NOP 1 +#define TCPOPT_MAXSEG 2 +#define TCPOLEN_MAXSEG 4 +#define TCPOPT_WINDOW 3 +#define TCPOLEN_WINDOW 3 +#define TCPOPT_SACK_PERMITTED 4 /* Experimental */ +#define TCPOLEN_SACK_PERMITTED 2 +#define TCPOPT_SACK 5 /* Experimental */ +#define TCPOLEN_SACK 8 /* 2*sizeof(tcp_seq) */ +#define TCPOPT_TIMESTAMP 8 +#define TCPOLEN_TIMESTAMP 10 +#define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2) /* appendix A */ +#define TCPOPT_SIGNATURE 19 +#define TCPOLEN_SIGNATURE 18 +#define TCPOLEN_SIGLEN (TCPOLEN_SIGNATURE+2) /* padding */ + +#define MAX_TCPOPTLEN 40 /* Absolute maximum TCP options len */ + +#define TCPOPT_TSTAMP_HDR \ + (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP) + +/* Option definitions */ +#define TCPOPT_SACK_PERMIT_HDR \ +(TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_SACK_PERMITTED<<8|TCPOLEN_SACK_PERMITTED) +#define TCPOPT_SACK_HDR (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_SACK<<8) +/* Miscellaneous constants */ +#define MAX_SACK_BLKS 6 /* Max # SACK blocks stored at sender side */ +#define TCP_MAX_SACK 3 /* Max # SACKs sent in any segment */ +#define TCP_SACKHOLE_LIMIT 128 /* Max # SACK holes per connection */ + +/* + * Default maximum segment size for TCP. + * With an IP MSS of 576, this is 536, + * but 512 is probably more convenient. + * This should be defined as min(512, IP_MSS - sizeof (struct tcpiphdr)). + */ +#define TCP_MSS 512 + +#define TCP_MAXWIN 65535 /* largest value for (unscaled) window */ + +#define TCP_MAX_WINSHIFT 14 /* maximum window shift */ + +/* + * The TCP_INFO socket option comes from the Linux 2.6 TCP API, and permits + * the caller to query certain information about the state of a TCP + * connection. Provide an overlapping set of fields with the Linux + * implementation, but at the same time add a lot of OpenBSD specific + * extra information. + */ +struct tcp_info { + uint8_t tcpi_state; /* TCP FSM state. */ + uint8_t __tcpi_ca_state; + uint8_t __tcpi_retransmits; + uint8_t __tcpi_probes; + uint8_t __tcpi_backoff; + uint8_t tcpi_options; /* Options enabled on conn. */ +#define TCPI_OPT_TIMESTAMPS 0x01 +#define TCPI_OPT_SACK 0x02 +#define TCPI_OPT_WSCALE 0x04 +#define TCPI_OPT_ECN 0x08 +#define TCPI_OPT_TOE 0x10 + uint8_t tcpi_snd_wscale; /* RFC1323 send shift value. */ + uint8_t tcpi_rcv_wscale; /* RFC1323 recv shift value. */ + + uint32_t tcpi_rto; /* Retransmission timeout (usec). */ + uint32_t __tcpi_ato; + uint32_t tcpi_snd_mss; /* Max segment size for send. */ + uint32_t tcpi_rcv_mss; /* Max segment size for recv. */ + + uint32_t __tcpi_unacked; + uint32_t __tcpi_sacked; + uint32_t __tcpi_lost; + uint32_t __tcpi_retrans; + uint32_t __tcpi_fackets; + + /* Times; measurements in usecs. */ + uint32_t tcpi_last_data_sent; /* since last sent data. */ + uint32_t tcpi_last_ack_sent; /* since last sent ack. */ + uint32_t tcpi_last_data_recv; /* since last recv data. */ + uint32_t tcpi_last_ack_recv; /* since last recv ack. */ + + /* Metrics; variable units. */ + uint32_t __tcpi_pmtu; + uint32_t __tcpi_rcv_ssthresh; + uint32_t tcpi_rtt; /* Smoothed RTT in usecs. */ + uint32_t tcpi_rttvar; /* RTT variance in usecs. */ + uint32_t tcpi_snd_ssthresh; /* Slow start threshold. */ + uint32_t tcpi_snd_cwnd; /* Send congestion window. */ + uint32_t __tcpi_advmss; + uint32_t __tcpi_reordering; + + uint32_t __tcpi_rcv_rtt; + uint32_t tcpi_rcv_space; /* Advertised recv window. */ + + /* + * Members below this point are only set if process is privileged, + * otherwise values will be 0. + */ + + /* FreeBSD/NetBSD extensions to tcp_info. */ + uint32_t tcpi_snd_wnd; /* Advertised send window. */ + uint32_t tcpi_snd_nxt; /* Next egress seqno */ + uint32_t tcpi_rcv_nxt; /* Next ingress seqno */ + uint32_t tcpi_toe_tid; /* HWTID for TOE endpoints */ + uint32_t tcpi_snd_rexmitpack; /* Retransmitted packets */ + uint32_t tcpi_rcv_ooopack; /* Out-of-order packets */ + uint32_t tcpi_snd_zerowin; /* Zero-sized windows sent */ + + /* OpenBSD extensions */ + uint32_t tcpi_rttmin; + uint32_t tcpi_max_sndwnd; + uint32_t tcpi_rcv_adv; + uint32_t tcpi_rcv_up; + uint32_t tcpi_snd_una; + uint32_t tcpi_snd_up; + uint32_t tcpi_snd_wl1; + uint32_t tcpi_snd_wl2; + uint32_t tcpi_snd_max; + uint32_t tcpi_ts_recent; + uint32_t tcpi_ts_recent_age; + uint32_t tcpi_rfbuf_cnt; + uint32_t tcpi_rfbuf_ts; + uint32_t tcpi_so_rcv_sb_cc; + uint32_t tcpi_so_rcv_sb_hiwat; + uint32_t tcpi_so_rcv_sb_lowat; + uint32_t tcpi_so_rcv_sb_wat; + uint32_t tcpi_so_snd_sb_cc; + uint32_t tcpi_so_snd_sb_hiwat; + uint32_t tcpi_so_snd_sb_lowat; + uint32_t tcpi_so_snd_sb_wat; +}; + +#endif /* __BSD_VISIBLE */ + +/* + * User-settable options (used with setsockopt). + */ +#define TCP_NODELAY 0x01 /* don't delay send to coalesce pkts */ +#define TCP_MAXSEG 0x02 /* set maximum segment size */ +#define TCP_MD5SIG 0x04 /* enable TCP MD5 signature option */ +#define TCP_SACK_ENABLE 0x08 /* enable SACKs (if disabled by def.) */ +#define TCP_INFO 0x09 /* retrieve tcp_info structure */ +#define TCP_NOPUSH 0x10 /* don't push last block of write */ + +#endif /* _NETINET_TCP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/tcp_debug.h b/lib/libc/include/generic-openbsd/netinet/tcp_debug.h new file mode 100644 index 0000000000..973b431bbb --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/tcp_debug.h @@ -0,0 +1,106 @@ +/* $OpenBSD: tcp_debug.h,v 1.11 2018/05/10 13:30:25 bluhm Exp $ */ +/* $NetBSD: tcp_debug.h,v 1.5 1994/06/29 06:38:38 cgd Exp $ */ + +/* + * Copyright (c) 1982, 1986, 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. + * + * @(#)tcp_debug.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NETINET_TCP_DEBUG_H_ +#define _NETINET_TCP_DEBUG_H_ + +/* + * Tcp+ip header, after ip options removed. + */ +struct tcpiphdr { + struct ipovly ti_i; /* overlaid ip structure */ + struct tcphdr ti_t; /* tcp header */ +}; +#define ti_x1 ti_i.ih_x1 +#define ti_pr ti_i.ih_pr +#define ti_len ti_i.ih_len +#define ti_src ti_i.ih_src +#define ti_dst ti_i.ih_dst +#define ti_sport ti_t.th_sport +#define ti_dport ti_t.th_dport +#define ti_seq ti_t.th_seq +#define ti_ack ti_t.th_ack +#define ti_x2 ti_t.th_x2 +#define ti_off ti_t.th_off +#define ti_flags ti_t.th_flags +#define ti_win ti_t.th_win +#define ti_sum ti_t.th_sum +#define ti_urp ti_t.th_urp + +struct tcpipv6hdr { + struct ip6_hdr ti6_i; + struct tcphdr ti6_t; +}; + +#define ti6_src ti6_i.ip6_src +#define ti6_dst ti6_i.ip6_dst +#define ti6_plen ti6_i.ip6_plen +#define ti6_sport ti6_t.th_sport +#define ti6_dport ti6_t.th_dport +#define ti6_seq ti6_t.th_seq +#define ti6_ack ti6_t.th_ack +#define ti6_x2 ti6_t.th_x2 +#define ti6_off ti6_t.th_off +#define ti6_flags ti6_t.th_flags +#define ti6_win ti6_t.th_win +#define ti6_sum ti6_t.th_sum +#define ti6_urp ti6_t.th_urp + +struct tcp_debug { + uint32_t td_time; + short td_act; + short td_ostate; + caddr_t td_tcb; + struct tcpiphdr td_ti; + struct tcpipv6hdr td_ti6; + short td_req; + struct tcpcb td_cb; +}; + +#define TA_INPUT 0 +#define TA_OUTPUT 1 +#define TA_USER 2 +#define TA_RESPOND 3 +#define TA_DROP 4 +#define TA_TIMER 5 + +#ifdef TANAMES +const char *tanames[] = + { "input", "output", "user", "respond", "drop", "timer" }; +#endif /* TANAMES */ + +#define TCP_NDEBUG 100 +extern struct tcp_debug tcp_debug[]; +extern int tcp_debx; +#endif /* _NETINET_TCP_DEBUG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/tcp_fsm.h b/lib/libc/include/generic-openbsd/netinet/tcp_fsm.h new file mode 100644 index 0000000000..a6a20c60a3 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/tcp_fsm.h @@ -0,0 +1,85 @@ +/* $OpenBSD: tcp_fsm.h,v 1.10 2024/12/20 21:30:17 bluhm Exp $ */ +/* $NetBSD: tcp_fsm.h,v 1.6 1994/10/14 16:01:48 mycroft Exp $ */ + +/* + * Copyright (c) 1982, 1986, 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. + * + * @(#)tcp_fsm.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NETINET_TCP_FSM_H_ +#define _NETINET_TCP_FSM_H_ + +/* + * TCP FSM state definitions. + * Per RFC793, September, 1981. + */ + +#define TCP_NSTATES 11 + +#define TCPS_CLOSED 0 /* closed */ +#define TCPS_LISTEN 1 /* listening for connection */ +#define TCPS_SYN_SENT 2 /* active, have sent syn */ +#define TCPS_SYN_RECEIVED 3 /* have sent and received syn */ +/* states < TCPS_ESTABLISHED are those where connections not established */ +#define TCPS_ESTABLISHED 4 /* established */ +#define TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */ +/* states > TCPS_CLOSE_WAIT are those where user has closed */ +#define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */ +#define TCPS_CLOSING 7 /* closed xchd FIN; await ACK */ +#define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */ +/* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */ +#define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */ +#define TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */ + +#define TCPS_HAVERCVDSYN(s) ((s) >= TCPS_SYN_RECEIVED) +#define TCPS_HAVEESTABLISHED(s) ((s) >= TCPS_ESTABLISHED) +#define TCPS_HAVERCVDFIN(s) ((s) >= TCPS_TIME_WAIT) + +#ifdef TCPOUTFLAGS +/* + * Flags used when sending segments in tcp_output. + * Basic flags (TH_RST,TH_ACK,TH_SYN,TH_FIN) are totally + * determined by state, with the proviso that TH_FIN is sent only + * if all data queued for output is included in the segment. + */ +const u_char tcp_outflags[TCP_NSTATES] = { + TH_RST|TH_ACK, 0, TH_SYN, TH_SYN|TH_ACK, + TH_ACK, TH_ACK, + TH_FIN|TH_ACK, TH_FIN|TH_ACK, TH_FIN|TH_ACK, TH_ACK, TH_ACK, +}; +#endif /* TCPOUTFLAGS */ + +#ifdef TCPSTATES +const char *const tcpstates[] = { + "CLOSED", "LISTEN", "SYN_SENT", "SYN_RCVD", + "ESTABLISHED", "CLOSE_WAIT", "FIN_WAIT_1", "CLOSING", + "LAST_ACK", "FIN_WAIT_2", "TIME_WAIT", +}; +#endif /* TCPSTATES */ +#endif /* _NETINET_TCP_FSM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/tcp_seq.h b/lib/libc/include/generic-openbsd/netinet/tcp_seq.h new file mode 100644 index 0000000000..b68e2db5b2 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/tcp_seq.h @@ -0,0 +1,66 @@ +/* $OpenBSD: tcp_seq.h,v 1.6 2007/06/15 18:23:06 markus Exp $ */ +/* $NetBSD: tcp_seq.h,v 1.6 1995/03/26 20:32:35 jtc Exp $ */ + +/* + * Copyright (c) 1982, 1986, 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. + * + * @(#)tcp_seq.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NETINET_TCP_SEQ_H_ +#define _NETINET_TCP_SEQ_H_ + +/* + * TCP sequence numbers are 32 bit integers operated + * on with modular arithmetic. These macros can be + * used to compare such integers. + */ +#define SEQ_LT(a,b) ((int)((a)-(b)) < 0) +#define SEQ_LEQ(a,b) ((int)((a)-(b)) <= 0) +#define SEQ_GT(a,b) ((int)((a)-(b)) > 0) +#define SEQ_GEQ(a,b) ((int)((a)-(b)) >= 0) + +/* + * Macros to initialize tcp sequence numbers for + * send and receive from initial send and receive + * sequence numbers. + */ +#define tcp_rcvseqinit(tp) \ + (tp)->rcv_adv = (tp)->rcv_nxt = (tp)->irs + 1 + +#define tcp_sendseqinit(tp) \ + (tp)->snd_una = (tp)->snd_nxt = (tp)->snd_max = (tp)->snd_up = \ + (tp)->iss + +#define TCP_ISSINCR (125*1024) /* increment for tcp_iss each second */ +#define TCP_ISSINCR2 (1*1024*1024) /* increment for tcp_iss each second */ + +#ifdef _KERNEL +extern tcp_seq tcp_iss; /* tcp initial send seq # */ +#endif /* _KERNEL */ +#endif /* _NETINET_TCP_SEQ_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/tcp_timer.h b/lib/libc/include/generic-openbsd/netinet/tcp_timer.h new file mode 100644 index 0000000000..d15427d2f9 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/tcp_timer.h @@ -0,0 +1,168 @@ +/* $OpenBSD: tcp_timer.h,v 1.27 2025/06/08 17:06:19 bluhm Exp $ */ +/* $NetBSD: tcp_timer.h,v 1.6 1995/03/26 20:32:37 jtc Exp $ */ + +/* + * Copyright (c) 1982, 1986, 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. + * + * @(#)tcp_timer.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NETINET_TCP_TIMER_H_ +#define _NETINET_TCP_TIMER_H_ + +/* + * Definitions of the TCP timers. + */ +#define TCPT_REXMT 0 /* retransmit */ +#define TCPT_PERSIST 1 /* retransmit persistence */ +#define TCPT_KEEP 2 /* keep alive */ +#define TCPT_2MSL 3 /* 2*msl quiet time timer */ +#define TCPT_DELACK 4 /* delayed ack timeout */ + +#define TCPT_NTIMERS 5 + +/* + * The TCPT_REXMT timer is used to force retransmissions. + * The TCP has the TCPT_REXMT timer set whenever segments + * have been sent for which ACKs are expected but not yet + * received. If an ACK is received which advances tp->snd_una, + * then the retransmit timer is cleared (if there are no more + * outstanding segments) or reset to the base value (if there + * are more ACKs expected). Whenever the retransmit timer goes off, + * we retransmit one unacknowledged segment, and do a backoff + * on the retransmit timer. + * + * The TCPT_PERSIST timer is used to keep window size information + * flowing even if the window goes shut. If all previous transmissions + * have been acknowledged (so that there are no retransmissions in progress), + * and the window is too small to bother sending anything, then we start + * the TCPT_PERSIST timer. When it expires, if the window is nonzero, + * we go to transmit state. Otherwise, at intervals send a single byte + * into the peer's window to force him to update our window information. + * We do this at most as often as TCPT_PERSMIN time intervals, + * but no more frequently than the current estimate of round-trip + * packet time. The TCPT_PERSIST timer is cleared whenever we receive + * a window update from the peer. + * + * The TCPT_KEEP timer is used to keep connections alive. If an + * connection is idle (no segments received) for TCPTV_KEEP_INIT amount of time, + * but not yet established, then we drop the connection. Once the connection + * is established, if the connection is idle for TCPTV_KEEP_IDLE time + * (and keepalives have been enabled on the socket), we begin to probe + * the connection. We force the peer to send us a segment by sending: + * + * This segment is (deliberately) outside the window, and should elicit + * an ack segment in response from the peer. If, despite the TCPT_KEEP + * initiated segments we cannot elicit a response from a peer in TCPT_MAXIDLE + * amount of time probing, then we drop the connection. + */ + +/* + * Time constants. + */ +#define TCPTV_MSL TCP_TIME(30) /* max seg lifetime (hah!) */ +#define TCPTV_SRTTBASE 0 /* base roundtrip time; + if 0, no idea yet */ +#define TCPTV_SRTTDFLT TCP_TIME(3) /* assumed RTT if no info */ + +#define TCPTV_PERSMIN TCP_TIME(5) /* retransmit persistence */ +#define TCPTV_PERSMAX TCP_TIME(60) /* maximum persist interval */ + +#define TCPTV_KEEPINIT TCP_TIME(75) /* initial connect keep alive */ +#define TCPTV_KEEPIDLE TCP_TIME(120*60) /* dflt time before probing */ +#define TCPTV_KEEPINTVL TCP_TIME(75) /* default probe interval */ +#define TCPTV_KEEPCNT 8 /* max probes before drop */ + +#define TCPTV_MIN TCP_TIME(1) /* minimum allowable value */ +#define TCPTV_REXMTMAX TCP_TIME(64) /* max allowable REXMT value */ + +#define TCP_LINGERTIME 120 /* linger at most 2 minutes */ + +#define TCP_MAXRXTSHIFT 12 /* maximum retransmits */ + +#define TCP_DELACK_MSECS 200 /* time to delay ACK */ + +#ifdef TCPTIMERS +const char *tcptimers[TCPT_NTIMERS] = + { "REXMT", "PERSIST", "KEEP", "2MSL", "DELACK" }; +#endif /* TCPTIMERS */ + +/* + * Init, arm, disarm, and test TCP timers. + */ +#define TCP_TIMER_INIT(tp, timer) \ + timeout_set_flags(&(tp)->t_timer[(timer)], \ + tcp_timer_funcs[(timer)], (tp)->t_inpcb, \ + KCLOCK_NONE, TIMEOUT_PROC | TIMEOUT_MPSAFE) + +#define TCP_TIMER_ARM(tp, timer, msecs) \ +do { \ + SET((tp)->t_flags, TF_TIMER << (timer)); \ + if (timeout_add_msec(&(tp)->t_timer[(timer)], (msecs))) \ + in_pcbref((tp)->t_inpcb); \ +} while (0) + +#define TCP_TIMER_DISARM(tp, timer) \ +do { \ + CLR((tp)->t_flags, TF_TIMER << (timer)); \ + if (timeout_del(&(tp)->t_timer[(timer)])) \ + in_pcbunref((tp)->t_inpcb); \ +} while (0) + +#define TCP_TIMER_ISARMED(tp, timer) \ + ISSET((tp)->t_flags, TF_TIMER << (timer)) + +/* + * Force a time value to be in a certain range. + */ +#define TCPT_RANGESET(tv, value, tvmin, tvmax) \ +do { \ + (tv) = (value); \ + if ((tv) < (tvmin)) \ + (tv) = (tvmin); \ + else if ((tv) > (tvmax)) \ + (tv) = (tvmax); \ +} while (/* CONSTCOND */ 0) + +#ifdef _KERNEL +typedef void (*tcp_timer_func_t)(void *); + +extern const tcp_timer_func_t tcp_timer_funcs[TCPT_NTIMERS]; + +extern int tcp_delack_msecs; /* [I] delayed ACK timeout in millisecs */ +extern int tcp_always_keepalive;/* [a] assume SO_KEEPALIVE always set */ +extern int tcp_keepinit; /* [a] time to keep alive initial SYN packet */ +extern int tcp_keepidle; /* [a] time before keepalive probes begin */ +extern int tcp_keepintvl; /* [a] time between keepalive probes */ +extern int tcp_keepinit_sec; /* [a] copy of above in seconds for sysctl */ +extern int tcp_keepidle_sec; /* [a] copy of above in seconds for sysctl */ +extern int tcp_keepintvl_sec; /* [a] copy of above in seconds for sysctl */ +extern int tcp_ttl; /* time to live for TCP segs */ +extern const int tcp_backoff[]; +#endif /* _KERNEL */ +#endif /* _NETINET_TCP_TIMER_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/tcp_var.h b/lib/libc/include/generic-openbsd/netinet/tcp_var.h new file mode 100644 index 0000000000..616a6ae833 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/tcp_var.h @@ -0,0 +1,814 @@ +/* $OpenBSD: tcp_var.h,v 1.196 2025/09/16 17:29:35 bluhm Exp $ */ +/* $NetBSD: tcp_var.h,v 1.17 1996/02/13 23:44:24 christos Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1993, 1994 + * 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. + * + * @(#)tcp_var.h 8.3 (Berkeley) 4/10/94 + */ + +#ifndef _NETINET_TCP_VAR_H_ +#define _NETINET_TCP_VAR_H_ + +#include + +/* + * Kernel variables for tcp. + */ + +struct sackblk { + tcp_seq start; /* start seq no. of sack block */ + tcp_seq end; /* end seq no. */ +}; + +struct sackhole { + tcp_seq start; /* start seq no. of hole */ + tcp_seq end; /* end seq no. */ + int dups; /* number of dup(s)acks for this hole */ + tcp_seq rxmit; /* next seq. no in hole to be retransmitted */ + struct sackhole *next; /* next in list */ +}; + +/* + * TCP sequence queue structures. + */ +TAILQ_HEAD(tcpqehead, tcpqent); +struct tcpqent { + TAILQ_ENTRY(tcpqent) tcpqe_q; + struct tcphdr *tcpqe_tcp; + struct mbuf *tcpqe_m; /* mbuf contains packet */ +}; + +/* + * Tcp control block, one per tcp; fields: + */ +struct tcpcb { + struct tcpqehead t_segq; /* sequencing queue */ + struct timeout t_timer[TCPT_NTIMERS]; /* tcp timers */ + short t_state; /* state of this connection */ + short t_rxtshift; /* log(2) of rexmt exp. backoff */ + int t_rxtcur; /* current retransmit value */ + short t_dupacks; /* consecutive dup acks recd */ + u_short t_maxseg; /* maximum segment size */ + char t_force; /* 1 if forcing out a byte */ + u_int t_flags; +#define TF_ACKNOW 0x0001U /* ack peer immediately */ +#define TF_NODELAY 0x0004U /* don't delay packets to coalesce */ +#define TF_NOOPT 0x0008U /* don't use tcp options */ +#define TF_SENTFIN 0x0010U /* have sent FIN */ +#define TF_REQ_SCALE 0x0020U /* have/will request window scaling */ +#define TF_RCVD_SCALE 0x0040U /* other side has requested scaling */ +#define TF_REQ_TSTMP 0x0080U /* have/will request timestamps */ +#define TF_RCVD_TSTMP 0x0100U /* a timestamp was received in SYN */ +#define TF_SACK_PERMIT 0x0200U /* other side said I could SACK */ +#define TF_SIGNATURE 0x0400U /* require TCP MD5 signature */ +#ifdef TCP_ECN +#define TF_ECN_PERMIT 0x00008000U /* other side said I could ECN */ +#define TF_RCVD_CE 0x00010000U /* send ECE in subsequent segs */ +#define TF_SEND_CWR 0x00020000U /* send CWR in next seg */ +#define TF_DISABLE_ECN 0x00040000U /* disable ECN for this connection */ +#endif +#define TF_LASTIDLE 0x00100000U /* no outstanding ACK on last send */ +#define TF_PMTUD_PEND 0x00400000U /* Path MTU Discovery pending */ +#define TF_NEEDOUTPUT 0x00800000U /* call tcp_output after tcp_input */ +#define TF_NOPUSH 0x02000000U /* don't push */ +#define TF_TMR_REXMT 0x04000000U /* retransmit timer armed */ +#define TF_TMR_PERSIST 0x08000000U /* retransmit persistence timer armed */ +#define TF_TMR_KEEP 0x10000000U /* keep alive timer armed */ +#define TF_TMR_2MSL 0x20000000U /* 2*msl quiet time timer armed */ +#define TF_TMR_DELACK 0x40000000U /* delayed ack timer armed */ +#define TF_TIMER TF_TMR_REXMT /* used to shift with TCPT values */ + + struct mbuf *t_template; /* skeletal packet for transmit */ + struct inpcb *t_inpcb; /* back pointer to internet pcb */ +/* + * The following fields are used as in the protocol specification. + * See RFC793, Dec. 1981, page 21. + */ +/* send sequence variables */ + tcp_seq snd_una; /* send unacknowledged */ + tcp_seq snd_nxt; /* send next */ + tcp_seq snd_up; /* send urgent pointer */ + tcp_seq snd_wl1; /* window update seg seq number */ + tcp_seq snd_wl2; /* window update seg ack number */ + tcp_seq iss; /* initial send sequence number */ + u_long snd_wnd; /* send window */ + int sack_enable; /* enable SACK for this connection */ + int snd_numholes; /* number of holes seen by sender */ + struct sackhole *snd_holes; /* linked list of holes (sorted) */ + tcp_seq snd_last; /* for use in fast recovery */ +/* receive sequence variables */ + u_long rcv_wnd; /* receive window */ + tcp_seq rcv_nxt; /* receive next */ + tcp_seq rcv_up; /* receive urgent pointer */ + tcp_seq irs; /* initial receive sequence number */ + tcp_seq rcv_lastsack; /* last seq number(+1) sack'd by rcv'r*/ + int rcv_numsacks; /* # distinct sack blks present */ + struct sackblk sackblks[MAX_SACK_BLKS]; /* seq nos. of sack blocks */ + +/* + * Additional variables for this implementation. + */ +/* receive variables */ + tcp_seq rcv_adv; /* advertised window */ +/* retransmit variables */ + tcp_seq snd_max; /* highest sequence number sent; + * used to recognize retransmits + */ +/* congestion control (for slow start, source quench, retransmit after loss) */ + u_long snd_cwnd; /* congestion-controlled window */ + u_long snd_ssthresh; /* snd_cwnd size threshold for + * for slow start exponential to + * linear switch + */ + +/* auto-sizing variables */ + uint64_t rfbuf_ts; /* recv buffer autoscaling time stamp */ + u_int rfbuf_cnt; /* recv buffer autoscaling byte count */ + + u_short t_maxopd; /* mss plus options */ + u_short t_peermss; /* peer's maximum segment size */ + +/* + * transmit timing stuff. See below for scale of srtt and rttvar. + * "Variance" is actually smoothed difference. + */ + uint64_t t_rcvtime; /* time last segment received */ + uint64_t t_rcvacktime; /* time last ack received */ + uint64_t t_sndtime; /* time last segment sent */ + uint64_t t_sndacktime; /* time last ack sent */ + uint64_t t_rtttime; /* time we started measuring rtt */ + tcp_seq t_rtseq; /* sequence number being timed */ + int t_srtt; /* smoothed round-trip time */ + int t_rttvar; /* variance in round-trip time */ + u_int t_rttmin; /* minimum rtt allowed */ + u_long max_sndwnd; /* largest window peer has offered */ + +/* out-of-band data */ + char t_oobflags; /* have some */ + char t_iobc; /* input character */ +#define TCPOOB_HAVEDATA 0x01 +#define TCPOOB_HADDATA 0x02 + short t_softerror; /* possible error not yet reported */ + +/* RFC 1323 variables */ + u_char snd_scale; /* window scaling for send window */ + u_char rcv_scale; /* window scaling for recv window */ + u_char request_r_scale; /* pending window scaling */ + u_char requested_s_scale; + uint32_t ts_recent; /* timestamp echo data */ + uint32_t ts_modulate; /* modulation on timestamp */ + uint64_t ts_recent_age; /* when last updated */ + tcp_seq last_ack_sent; + +/* pointer for syn cache entries*/ + LIST_HEAD(, syn_cache) t_sc; /* list of entries by this tcb */ + +/* Path-MTU Discovery Information */ + u_int t_pmtud_mss_acked; /* MSS acked, lower bound for MTU */ + u_int t_pmtud_mtu_sent; /* MTU used, upper bound for MTU */ + tcp_seq t_pmtud_th_seq; /* TCP SEQ from ICMP payload */ + u_int t_pmtud_nextmtu; /* Advertised Next-Hop MTU from ICMP */ + u_short t_pmtud_ip_len; /* IP length from ICMP payload */ + u_short t_pmtud_ip_hl; /* IP header length from ICMP payload */ + + int pf; + +/* maintain a few stats per connection: */ + u_int t_rcvoopack; /* out-of-order packets received */ + u_int t_sndrexmitpack; /* retransmit packets sent */ + u_int t_sndzerowin; /* zero-window updates sent */ +}; + +#define intotcpcb(ip) ((struct tcpcb *)(ip)->inp_ppcb) +#define sototcpcb(so) (intotcpcb(sotoinpcb(so))) + +#ifdef _KERNEL +/* + * Handy way of passing around TCP option info. + */ +struct tcp_opt_info { + int ts_present; + u_int32_t ts_val; + u_int32_t ts_ecr; + u_int16_t maxseg; +}; + +/* + * Data for the TCP compressed state engine. + */ + +/* + * Locks used to protect global data and struct members: + * I immutable after creation + * N net lock + * S syn_cache_mtx tcp syn cache global mutex + * s so_lock socket lock of listen socket + */ + +extern struct mutex syn_cache_mtx; + +#define TCP_SYN_HASH_SIZE 293 +#define TCP_SYN_BUCKET_SIZE 35 + +union syn_cache_sa { + struct sockaddr sa; + struct sockaddr_in sin; + struct sockaddr_in6 sin6; +}; + +struct syn_cache { + TAILQ_ENTRY(syn_cache) sc_bucketq; /* [S] link on bucket list */ + struct refcnt sc_refcnt; /* ref count list and timer */ + struct timeout sc_timer; /* rexmt timer */ + struct route sc_route; /* [s] cached route */ + long sc_win; /* [I] advertised window */ + struct syn_cache_head *sc_buckethead; /* [S] our bucket index */ + struct syn_cache_set *sc_set; /* [S] our syn cache set */ + u_int64_t sc_timestamp; /* [s] timestamp from SYN */ + u_int32_t sc_hash; /* [S] */ + u_int32_t sc_modulate; /* [I] our timestamp modulator */ + union syn_cache_sa sc_src; /* [I] */ + union syn_cache_sa sc_dst; /* [I] */ + tcp_seq sc_irs; /* [I] */ + tcp_seq sc_iss; /* [I] */ + u_int sc_rtableid; /* [I] */ + u_int sc_rxtcur; /* [S] current rxt timeout */ + u_int sc_rxttot; /* [S] total time spend on queues */ + u_int sc_rxtshift; /* [S] for computing backoff */ + u_int sc_dynflags; /* [S] flags accessed with mutex */ +#define SCF_UNREACH 0x0001U /* we've had an unreach error */ + + u_short sc_fixflags; /* [I] set during initialization */ +#define SCF_TIMESTAMP 0x0010U /* peer will do timestamps */ +#define SCF_SACK_PERMIT 0x0020U /* permit sack */ +#define SCF_ECN_PERMIT 0x0040U /* permit ecn */ +#define SCF_SIGNATURE 0x0080U /* enforce tcp signatures */ + + struct mbuf *sc_ipopts; /* [s] IP options */ + u_int16_t sc_peermaxseg; /* [I] */ + u_int16_t sc_ourmaxseg; /* [I] */ + u_int sc_request_r_scale : 4, /* [I] */ + sc_requested_s_scale : 4; /* [I] */ + + struct inpcb *sc_inplisten; /* [S] inpcb for listening socket */ + LIST_ENTRY(syn_cache) sc_tpq; /* [S] list of entries by same tp */ +}; + +struct syn_cache_head { + TAILQ_HEAD(, syn_cache) sch_bucket; /* [S] bucket entries */ + u_short sch_length; /* [S] # entries in bucket */ +}; + +struct syn_cache_set { + struct syn_cache_head *scs_buckethead; /* [S] */ + long scs_use; /* [S] */ + int scs_size; /* [S] current size of hash table */ + int scs_count; /* [S] */ + u_int32_t scs_random[5]; /* [S] */ +}; + +#endif /* _KERNEL */ + +/* + * The smoothed round-trip time and estimated variance + * are stored as fixed point numbers scaled by the values below. + * For convenience, these scales are also used in smoothing the average + * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed). + * With these scales, srtt has 5 bits to the right of the binary point, + * and thus an "ALPHA" of 0.875. rttvar has 4 bits to the right of the + * binary point, and is smoothed with an ALPHA of 0.75. + */ +#define TCP_RTT_SHIFT 3 /* shift for srtt; 5 bits frac. */ +#define TCP_RTTVAR_SHIFT 2 /* shift for rttvar; 4 bits */ +#define TCP_RTT_BASE_SHIFT 2 /* remaining 2 bit shift */ +#define TCP_RTT_MAX (1<<18) /* maximum rtt */ + +/* + * The initial retransmission should happen at rtt + 4 * rttvar. + * Because of the way we do the smoothing, srtt and rttvar + * will each average +1/2 tick of bias. When we compute + * the retransmit timer, we want 1/2 tick of rounding and + * 1 extra tick because of +-1/2 tick uncertainty in the + * firing of the timer. The bias will give us exactly the + * 1.5 tick we need. But, because the bias is + * statistical, we have to test that we don't drop below + * the minimum feasible timer (which is 2 ticks). + * This macro assumes that the value of (1 << TCP_RTTVAR_SHIFT) + * is the same as the multiplier for rttvar. + */ +#define TCP_REXMTVAL(tp) \ + ((((tp)->t_srtt >> TCP_RTT_SHIFT) + (tp)->t_rttvar) \ + >> TCP_RTT_BASE_SHIFT) + +/* + * TCP statistics. + * Many of these should be kept per connection, + * but that's inconvenient at the moment. + */ +struct tcpstat { + u_int32_t tcps_connattempt; /* connections initiated */ + u_int32_t tcps_accepts; /* connections accepted */ + u_int32_t tcps_connects; /* connections established */ + u_int32_t tcps_drops; /* connections dropped */ + u_int32_t tcps_conndrops; /* embryonic connections dropped */ + u_int32_t tcps_closed; /* conn. closed (includes drops) */ + u_int32_t tcps_segstimed; /* segs where we tried to get rtt */ + u_int32_t tcps_rttupdated; /* times we succeeded */ + u_int32_t tcps_delack; /* delayed acks sent */ + u_int32_t tcps_timeoutdrop; /* conn. dropped in rxmt timeout */ + u_int32_t tcps_rexmttimeo; /* retransmit timeouts */ + u_int32_t tcps_persisttimeo; /* persist timeouts */ + u_int32_t tcps_persistdrop; /* connections dropped in persist */ + u_int32_t tcps_keeptimeo; /* keepalive timeouts */ + u_int32_t tcps_keepprobe; /* keepalive probes sent */ + u_int32_t tcps_keepdrops; /* connections dropped in keepalive */ + + u_int32_t tcps_sndtotal; /* total packets sent */ + u_int32_t tcps_sndpack; /* data packets sent */ + u_int64_t tcps_sndbyte; /* data bytes sent */ + u_int32_t tcps_sndrexmitpack; /* data packets retransmitted */ + u_int64_t tcps_sndrexmitbyte; /* data bytes retransmitted */ + u_int64_t tcps_sndrexmitfast; /* Fast retransmits */ + u_int32_t tcps_sndacks; /* ack-only packets sent */ + u_int32_t tcps_sndprobe; /* window probes sent */ + u_int32_t tcps_sndurg; /* packets sent with URG only */ + u_int32_t tcps_sndwinup; /* window update-only packets sent */ + u_int32_t tcps_sndctrl; /* control (SYN|FIN|RST) packets sent */ + + u_int32_t tcps_rcvtotal; /* total packets received */ + u_int32_t tcps_rcvpack; /* packets received in sequence */ + u_int64_t tcps_rcvbyte; /* bytes received in sequence */ + u_int32_t tcps_rcvbadsum; /* packets received with ccksum errs */ + u_int32_t tcps_rcvbadoff; /* packets received with bad offset */ + u_int32_t tcps_rcvmemdrop; /* packets dropped for lack of memory */ + u_int32_t tcps_rcvnosec; /* packets dropped for lack of ipsec */ + u_int32_t tcps_rcvshort; /* packets received too short */ + u_int32_t tcps_rcvduppack; /* duplicate-only packets received */ + u_int64_t tcps_rcvdupbyte; /* duplicate-only bytes received */ + u_int32_t tcps_rcvpartduppack; /* packets with some duplicate data */ + u_int64_t tcps_rcvpartdupbyte; /* dup. bytes in part-dup. packets */ + u_int32_t tcps_rcvoopack; /* out-of-order packets received */ + u_int64_t tcps_rcvoobyte; /* out-of-order bytes received */ + u_int32_t tcps_rcvpackafterwin; /* packets with data after window */ + u_int64_t tcps_rcvbyteafterwin; /* bytes rcvd after window */ + u_int32_t tcps_rcvafterclose; /* packets rcvd after "close" */ + u_int32_t tcps_rcvwinprobe; /* rcvd window probe packets */ + u_int32_t tcps_rcvdupack; /* rcvd duplicate acks */ + u_int32_t tcps_rcvacktoomuch; /* rcvd acks for unsent data */ + u_int32_t tcps_rcvacktooold; /* rcvd acks for old data */ + u_int32_t tcps_rcvackpack; /* rcvd ack packets */ + u_int64_t tcps_rcvackbyte; /* bytes acked by rcvd acks */ + u_int32_t tcps_rcvwinupd; /* rcvd window update packets */ + u_int32_t tcps_pawsdrop; /* segments dropped due to PAWS */ + u_int32_t tcps_predack; /* times hdr predict ok for acks */ + u_int32_t tcps_preddat; /* times hdr predict ok for data pkts */ + + u_int32_t tcps_pcbhashmiss; /* input packets missing pcb hash */ + u_int32_t tcps_noport; /* no socket on port */ + u_int32_t tcps_closing; /* inpcb exists, socket is closing */ + u_int32_t tcps_badsyn; /* SYN packet with src==dst rcv'ed */ + u_int32_t tcps_dropsyn; /* SYN packet dropped */ + + u_int32_t tcps_rcvbadsig; /* rcvd bad/missing TCP signatures */ + u_int64_t tcps_rcvgoodsig; /* rcvd good TCP signatures */ + u_int32_t tcps_inswcsum; /* input software-checksummed pkts */ + u_int32_t tcps_outswcsum; /* output software-checksummed pkts */ + + /* ECN stats */ + u_int32_t tcps_ecn_accepts; /* ecn connections accepted */ + u_int32_t tcps_ecn_rcvece; /* # of rcvd ece */ + u_int32_t tcps_ecn_rcvcwr; /* # of rcvd cwr */ + u_int32_t tcps_ecn_rcvce; /* # of rcvd ce in ip header */ + u_int32_t tcps_ecn_sndect; /* # of cwr sent */ + u_int32_t tcps_ecn_sndece; /* # of ece sent */ + u_int32_t tcps_ecn_sndcwr; /* # of cwr sent */ + u_int32_t tcps_cwr_ecn; /* # of cwnd reduced by ecn */ + u_int32_t tcps_cwr_frecovery; /* # of cwnd reduced by fastrecovery */ + u_int32_t tcps_cwr_timeout; /* # of cwnd reduced by timeout */ + + /* These statistics deal with the SYN cache. */ + u_int64_t tcps_sc_added; /* # of entries added */ + u_int64_t tcps_sc_completed; /* # of connections completed */ + u_int64_t tcps_sc_timed_out; /* # of entries timed out */ + u_int64_t tcps_sc_overflowed; /* # dropped due to overflow */ + u_int64_t tcps_sc_reset; /* # dropped due to RST */ + u_int64_t tcps_sc_unreach; /* # dropped due to ICMP unreach */ + u_int64_t tcps_sc_bucketoverflow;/* # dropped due to bucket overflow */ + u_int64_t tcps_sc_aborted; /* # of entries aborted (no mem) */ + u_int64_t tcps_sc_dupesyn; /* # of duplicate SYNs received */ + u_int64_t tcps_sc_dropped; /* # of SYNs dropped (no route/mem) */ + u_int64_t tcps_sc_collisions; /* # of hash collisions */ + u_int64_t tcps_sc_retransmitted;/* # of retransmissions */ + u_int64_t tcps_sc_seedrandom; /* # of syn cache seeds with random */ + u_int64_t tcps_sc_hash_size; /* hash buckets in current syn cache */ + u_int64_t tcps_sc_entry_count; /* # of entries in current syn cache */ + u_int64_t tcps_sc_entry_limit; /* limit of syn cache entries */ + u_int64_t tcps_sc_bucket_maxlen;/* maximum # of entries in any bucket */ + u_int64_t tcps_sc_bucket_limit; /* limit of syn cache bucket list */ + int64_t tcps_sc_uses_left; /* use counter of current syn cache */ + + u_int64_t tcps_conndrained; /* # of connections drained */ + + u_int64_t tcps_sack_recovery_episode; /* SACK recovery episodes */ + u_int64_t tcps_sack_rexmits; /* SACK rexmit segments */ + u_int64_t tcps_sack_rexmit_bytes; /* SACK rexmit bytes */ + u_int64_t tcps_sack_rcv_opts; /* SACK options received */ + u_int64_t tcps_sack_snd_opts; /* SACK options sent */ + u_int64_t tcps_sack_drop_opts; /* SACK options dropped */ + + u_int32_t tcps_outswtso; /* output tso chopped in software */ + u_int32_t tcps_outhwtso; /* output tso processed by hardware */ + u_int32_t tcps_outpkttso; /* packets generated by tso */ + u_int32_t tcps_outbadtso; /* output tso failed, packet dropped */ + u_int32_t tcps_inswlro; /* input lro on pseudo device */ + u_int32_t tcps_inhwlro; /* input lro from hardware */ + u_int32_t tcps_inpktlro; /* packets coalesced by hardware lro */ + u_int32_t tcps_inbadlro; /* input bad lro packets */ +}; + +/* + * Names for TCP sysctl objects. + */ + +#define TCPCTL_RFC1323 1 /* enable RFC1323 timestamps/scaling */ +#define TCPCTL_KEEPINITTIME 2 /* TCPT_KEEP value */ +#define TCPCTL_KEEPIDLE 3 /* allow tcp_keepidle to be changed */ +#define TCPCTL_KEEPINTVL 4 /* allow tcp_keepintvl to be changed */ +#define TCPCTL_SLOWHZ 5 /* return kernel idea of PR_SLOWHZ */ +#define TCPCTL_BADDYNAMIC 6 /* return bad dynamic port bitmap */ +#define TCPCTL_RECVSPACE 7 /* receive buffer space */ +#define TCPCTL_SENDSPACE 8 /* send buffer space */ +#define TCPCTL_IDENT 9 /* get connection owner */ +#define TCPCTL_SACK 10 /* selective acknowledgement, rfc 2018 */ +#define TCPCTL_MSSDFLT 11 /* Default maximum segment size */ +#define TCPCTL_RSTPPSLIMIT 12 /* RST pps limit */ +#define TCPCTL_ACK_ON_PUSH 13 /* ACK immediately on PUSH */ +#define TCPCTL_ECN 14 /* RFC3168 ECN */ +#define TCPCTL_SYN_CACHE_LIMIT 15 /* max size of comp. state engine */ +#define TCPCTL_SYN_BUCKET_LIMIT 16 /* max size of hash bucket */ +#define TCPCTL_RFC3390 17 /* enable/disable RFC3390 increased cwnd */ +#define TCPCTL_REASS_LIMIT 18 /* max entries for tcp reass queues */ +#define TCPCTL_DROP 19 /* drop tcp connection */ +#define TCPCTL_SACKHOLE_LIMIT 20 /* max entries for tcp sack queues */ +#define TCPCTL_STATS 21 /* TCP statistics */ +#define TCPCTL_ALWAYS_KEEPALIVE 22 /* assume SO_KEEPALIVE is always set */ +#define TCPCTL_SYN_USE_LIMIT 23 /* number of uses before reseeding hash */ +#define TCPCTL_ROOTONLY 24 /* return root only port bitmap */ +#define TCPCTL_SYN_HASH_SIZE 25 /* number of buckets in the hash */ +#define TCPCTL_TSO 26 /* enable TCP segmentation offload */ +#define TCPCTL_MAXID 27 + +#define TCPCTL_NAMES { \ + { 0, 0 }, \ + { "rfc1323", CTLTYPE_INT }, \ + { "keepinittime", CTLTYPE_INT }, \ + { "keepidle", CTLTYPE_INT }, \ + { "keepintvl", CTLTYPE_INT }, \ + { NULL, 0 }, \ + { "baddynamic", CTLTYPE_STRUCT }, \ + { NULL, 0 }, \ + { NULL, 0 }, \ + { "ident", CTLTYPE_STRUCT }, \ + { "sack", CTLTYPE_INT }, \ + { "mssdflt", CTLTYPE_INT }, \ + { "rstppslimit", CTLTYPE_INT }, \ + { "ackonpush", CTLTYPE_INT }, \ + { "ecn", CTLTYPE_INT }, \ + { "syncachelimit", CTLTYPE_INT }, \ + { "synbucketlimit", CTLTYPE_INT }, \ + { "rfc3390", CTLTYPE_INT }, \ + { "reasslimit", CTLTYPE_INT }, \ + { "drop", CTLTYPE_STRUCT }, \ + { "sackholelimit", CTLTYPE_INT }, \ + { "stats", CTLTYPE_STRUCT }, \ + { "always_keepalive", CTLTYPE_INT }, \ + { "synuselimit", CTLTYPE_INT }, \ + { "rootonly", CTLTYPE_STRUCT }, \ + { "synhashsize", CTLTYPE_INT }, \ + { "tso", CTLTYPE_INT }, \ +} + +struct tcp_ident_mapping { + struct sockaddr_storage faddr, laddr; + int euid, ruid; + u_int rdomain; +}; + +#ifdef _KERNEL + +#include +#include + +enum tcpstat_counters { + tcps_connattempt, + tcps_accepts, + tcps_connects, + tcps_drops, + tcps_conndrops, + tcps_closed, + tcps_segstimed, + tcps_rttupdated, + tcps_delack, + tcps_timeoutdrop, + tcps_rexmttimeo, + tcps_persisttimeo, + tcps_persistdrop, + tcps_keeptimeo, + tcps_keepprobe, + tcps_keepdrops, + tcps_sndtotal, + tcps_sndpack, + tcps_sndbyte, + tcps_sndrexmitpack, + tcps_sndrexmitbyte, + tcps_sndrexmitfast, + tcps_sndacks, + tcps_sndprobe, + tcps_sndurg, + tcps_sndwinup, + tcps_sndctrl, + tcps_rcvtotal, + tcps_rcvpack, + tcps_rcvbyte, + tcps_rcvbadsum, + tcps_rcvbadoff, + tcps_rcvmemdrop, + tcps_rcvnosec, + tcps_rcvshort, + tcps_rcvduppack, + tcps_rcvdupbyte, + tcps_rcvpartduppack, + tcps_rcvpartdupbyte, + tcps_rcvoopack, + tcps_rcvoobyte, + tcps_rcvpackafterwin, + tcps_rcvbyteafterwin, + tcps_rcvafterclose, + tcps_rcvwinprobe, + tcps_rcvdupack, + tcps_rcvacktoomuch, + tcps_rcvacktooold, + tcps_rcvackpack, + tcps_rcvackbyte, + tcps_rcvwinupd, + tcps_pawsdrop, + tcps_predack, + tcps_preddat, + tcps_pcbhashmiss, + tcps_noport, + tcps_closing, + tcps_badsyn, + tcps_dropsyn, + tcps_rcvbadsig, + tcps_rcvgoodsig, + tcps_inswcsum, + tcps_outswcsum, + tcps_ecn_accepts, + tcps_ecn_rcvece, + tcps_ecn_rcvcwr, + tcps_ecn_rcvce, + tcps_ecn_sndect, + tcps_ecn_sndece, + tcps_ecn_sndcwr, + tcps_cwr_ecn, + tcps_cwr_frecovery, + tcps_cwr_timeout, + tcps_sc_added, + tcps_sc_completed, + tcps_sc_timed_out, + tcps_sc_overflowed, + tcps_sc_reset, + tcps_sc_unreach, + tcps_sc_bucketoverflow, + tcps_sc_aborted, + tcps_sc_dupesyn, + tcps_sc_dropped, + tcps_sc_collisions, + tcps_sc_retransmitted, + tcps_sc_seedrandom, + tcps_sc_hash_size, + tcps_sc_entry_count, + tcps_sc_entry_limit, + tcps_sc_bucket_maxlen, + tcps_sc_bucket_limit, + tcps_sc_uses_left, + tcps_conndrained, + tcps_sack_recovery_episode, + tcps_sack_rexmits, + tcps_sack_rexmit_bytes, + tcps_sack_rcv_opts, + tcps_sack_snd_opts, + tcps_sack_drop_opts, + tcps_outswtso, + tcps_outhwtso, + tcps_outpkttso, + tcps_outbadtso, + tcps_inswlro, + tcps_inhwlro, + tcps_inpktlro, + tcps_inbadlro, + tcps_ncounters, +}; + +extern struct cpumem *tcpcounters; + +static inline void +tcpstat_inc(enum tcpstat_counters c) +{ + int s = splnet(); + counters_inc(tcpcounters, c); + splx(s); +} + +static inline void +tcpstat_add(enum tcpstat_counters c, uint64_t v) +{ + int s = splnet(); + counters_add(tcpcounters, c, v); + splx(s); +} + +static inline void +tcpstat_pkt(enum tcpstat_counters pcounter, enum tcpstat_counters bcounter, + uint64_t v) +{ + int s = splnet(); + counters_pkt(tcpcounters, pcounter, bcounter, v); + splx(s); +} + +extern uint64_t tcp_starttime; + +static inline uint64_t +tcp_now(void) +{ + /* TCP time ticks in 63 bit milliseconds with 63 bit random offset. */ + return tcp_starttime + (getnsecruntime() / 1000000ULL); +} + +#define TCP_TIME(_sec) ((_sec) * 1000) /* tcp_now() is in milliseconds */ + +extern struct mutex tcp_timer_mtx; +extern const struct pr_usrreqs tcp_usrreqs; + +#ifdef INET6 +extern const struct pr_usrreqs tcp6_usrreqs; +#endif + +extern struct pool tcpcb_pool; +extern struct inpcbtable tcbtable, tcb6table; /* queue of active tcpcb's */ +extern int tcp_do_rfc1323; /* [a] enabled/disabled? */ +extern const int tcprexmtthresh; +extern int tcp_mssdflt; /* [a] default maximum segment size */ +extern int tcp_rst_ppslim; /* [a] maximum outgoing RST packet per second */ +extern int tcp_ack_on_push; /* [a] ACK immediately on PUSH */ +extern int tcp_do_sack; /* [a] SACK enabled/disabled */ +extern struct pool sackhl_pool; +extern int tcp_sackhole_limit; /* max entries for tcp sack queues */ +extern int tcp_do_ecn; /* [a] RFC3168 ECN enabled/disabled? */ +extern int tcp_do_rfc3390; /* [a] RFC3390 Increasing TCP Initial Window */ +extern int tcp_do_tso; /* [a] enable TSO for TCP output packets */ + +extern struct pool tcpqe_pool; +extern int tcp_reass_limit; /* max entries for tcp reass queues */ + +extern int tcp_syn_hash_size; /* adjustable size of the hash array */ +extern int tcp_syn_cache_limit; /* max entries for compressed state engine */ +extern int tcp_syn_bucket_limit;/* max entries per hash bucket */ +extern int tcp_syn_use_limit; /* number of uses before reseeding hash */ +extern struct syn_cache_set tcp_syn_cache[]; +extern int tcp_syn_cache_active; /* active syn cache, may be 0 or 1 */ + +struct tdb; + +void tcp_canceltimers(struct tcpcb *); +struct tcpcb * + tcp_close(struct tcpcb *); +int tcp_freeq(struct tcpcb *); +#ifdef INET6 +void tcp6_ctlinput(int, struct sockaddr *, u_int, void *); +#endif +void tcp_ctlinput(int, struct sockaddr *, u_int, void *); +int tcp_ctloutput(int, struct socket *, int, int, struct mbuf *); +struct tcpcb * + tcp_dodisconnect(struct tcpcb *); +struct tcpcb * + tcp_drop(struct tcpcb *, int); +int tcp_dooptions(struct tcpcb *, u_char *, int, struct tcphdr *, + struct mbuf *, int, struct tcp_opt_info *, u_int, uint64_t); +void tcp_init(void); +int tcp_input(struct mbuf **, int *, int, int, struct netstack *); +void tcp_input_mlist(struct mbuf_list *, int); +int tcp_mss(struct tcpcb *, int); +void tcp_mss_update(struct tcpcb *); +void tcp_softlro_glue(struct mbuf_list *, struct mbuf *, struct ifnet *); +u_int tcp_hdrsz(struct tcpcb *); +void tcp_mtudisc(struct inpcb *, int); +void tcp_mtudisc_increase(struct inpcb *, int); +#ifdef INET6 +void tcp6_mtudisc_callback(struct sockaddr_in6 *, u_int); +#endif +struct tcpcb * + tcp_newtcpcb(struct inpcb *, int); +void tcp_notify(struct inpcb *, int); +int tcp_output(struct tcpcb *); +int tcp_softtso_chop(struct mbuf_list *, struct mbuf *, struct ifnet *, + u_int); +int tcp_if_output_tso(struct ifnet *, struct mbuf **, struct sockaddr *, + struct rtentry *, uint32_t, u_int); +void tcp_pulloutofband(struct socket *, u_int, struct mbuf *, int); +int tcp_reass(struct tcpcb *, struct tcphdr *, struct mbuf *, int *); +void tcp_rscale(struct tcpcb *, u_long); +void tcp_respond(struct tcpcb *, caddr_t, struct tcphdr *, tcp_seq, + tcp_seq, int, u_int, uint64_t); +void tcp_setpersist(struct tcpcb *); +void tcp_update_sndspace(struct tcpcb *); +void tcp_update_rcvspace(struct tcpcb *); +void tcp_slowtimo(void); +struct mbuf * + tcp_template(struct tcpcb *); +#ifndef SMALL_KERNEL +void tcp_trace(short, short, struct tcpcb *, struct tcpcb *, caddr_t, + int, int); +#endif +struct tcpcb * + tcp_usrclosed(struct tcpcb *); +int tcp_sysctl(int *, u_int, void *, size_t *, void *, size_t); +int tcp_attach(struct socket *, int, int); +int tcp_detach(struct socket *); +int tcp_bind(struct socket *, struct mbuf *, struct proc *); +int tcp_listen(struct socket *); +int tcp_connect(struct socket *, struct mbuf *); +int tcp_accept(struct socket *, struct mbuf *); +int tcp_disconnect(struct socket *); +int tcp_shutdown(struct socket *); +void tcp_rcvd(struct socket *); +int tcp_send(struct socket *, struct mbuf *, struct mbuf *, + struct mbuf *); +void tcp_abort(struct socket *); +int tcp_sockaddr(struct socket *, struct mbuf *); +int tcp_peeraddr(struct socket *, struct mbuf *); +int tcp_sense(struct socket *, struct stat *); +int tcp_rcvoob(struct socket *, struct mbuf *, int); +int tcp_sendoob(struct socket *, struct mbuf *, struct mbuf *, + struct mbuf *); +void tcp_xmit_timer(struct tcpcb *, int32_t); +void tcp_sack_option(struct tcpcb *,struct tcphdr *,u_char *,int); +void tcp_update_sack_list(struct tcpcb *tp, tcp_seq, tcp_seq); +void tcp_del_sackholes(struct tcpcb *, struct tcphdr *); +void tcp_clean_sackreport(struct tcpcb *tp); +void tcp_sack_adjust(struct tcpcb *tp); +struct sackhole * + tcp_sack_output(struct tcpcb *tp); +#ifdef DEBUG +void tcp_print_holes(struct tcpcb *tp); +#endif +u_long tcp_seq_subtract(u_long, u_long ); +#ifdef TCP_SIGNATURE +int tcp_signature_apply(caddr_t, caddr_t, unsigned int); +int tcp_signature(struct tdb *, int, struct mbuf *, struct tcphdr *, + int, int, char *); +#endif /* TCP_SIGNATURE */ +void tcp_set_iss_tsm(struct tcpcb *); + +void syn_cache_unreach(const struct sockaddr *, const struct sockaddr *, + struct tcphdr *, u_int); +void syn_cache_init(void); +void syn_cache_cleanup(struct tcpcb *); + +#ifdef SMALL_KERNEL +static inline void +tcp_trace(short act, short ostate, struct tcpcb *tp, struct tcpcb *otp, + caddr_t headers, int req, int len) +{ +} +#endif + +#endif /* _KERNEL */ +#endif /* _NETINET_TCP_VAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/udp.h b/lib/libc/include/generic-openbsd/netinet/udp.h new file mode 100644 index 0000000000..2726aee8db --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/udp.h @@ -0,0 +1,49 @@ +/* $OpenBSD: udp.h,v 1.5 2003/06/02 23:28:15 millert Exp $ */ +/* $NetBSD: udp.h,v 1.6 1995/04/13 06:37:10 cgd Exp $ */ + +/* + * Copyright (c) 1982, 1986, 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. + * + * @(#)udp.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NETINET_UDP_H_ +#define _NETINET_UDP_H_ + +/* + * Udp protocol header. + * Per RFC 768, September, 1981. + */ +struct udphdr { + u_int16_t uh_sport; /* source port */ + u_int16_t uh_dport; /* destination port */ + u_int16_t uh_ulen; /* udp length */ + u_int16_t uh_sum; /* udp checksum */ +}; + +#endif /* _NETINET_UDP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet/udp_var.h b/lib/libc/include/generic-openbsd/netinet/udp_var.h new file mode 100644 index 0000000000..c7e3d70b2f --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet/udp_var.h @@ -0,0 +1,155 @@ +/* $OpenBSD: udp_var.h,v 1.53 2025/03/02 21:28:32 bluhm Exp $ */ +/* $NetBSD: udp_var.h,v 1.12 1996/02/13 23:44:41 christos Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)udp_var.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NETINET_UDP_VAR_H_ +#define _NETINET_UDP_VAR_H_ + +/* + * UDP kernel structures and variables. + */ +struct udpiphdr { + struct ipovly ui_i; /* overlaid ip structure */ + struct udphdr ui_u; /* udp header */ +}; +#define ui_x1 ui_i.ih_x1 +#define ui_pr ui_i.ih_pr +#define ui_len ui_i.ih_len +#define ui_src ui_i.ih_src +#define ui_dst ui_i.ih_dst +#define ui_sport ui_u.uh_sport +#define ui_dport ui_u.uh_dport +#define ui_ulen ui_u.uh_ulen +#define ui_sum ui_u.uh_sum + +struct udpstat { + /* input statistics: */ + u_long udps_ipackets; /* total input packets */ + u_long udps_hdrops; /* packet shorter than header */ + u_long udps_badsum; /* checksum error */ + u_long udps_nosum; /* no checksum */ + u_long udps_badlen; /* data length larger than packet */ + u_long udps_noport; /* no socket on port */ + u_long udps_noportbcast; /* of above, arrived as broadcast */ + u_long udps_nosec; /* dropped for lack of ipsec */ + u_long udps_fullsock; /* not delivered, input socket full */ + u_long udps_pcbhashmiss; /* input packets missing pcb hash */ + u_long udps_inswcsum; /* input software-csummed packets */ + /* output statistics: */ + u_long udps_opackets; /* total output packets */ + u_long udps_outswcsum; /* output software-csummed packets */ +}; + +/* + * Names for UDP sysctl objects + */ +#define UDPCTL_CHECKSUM 1 /* checksum UDP packets */ +#define UDPCTL_BADDYNAMIC 2 /* return bad dynamic port bitmap */ +#define UDPCTL_RECVSPACE 3 /* receive buffer space */ +#define UDPCTL_SENDSPACE 4 /* send buffer space */ +#define UDPCTL_STATS 5 /* UDP statistics */ +#define UDPCTL_ROOTONLY 6 /* root only port bitmap */ +#define UDPCTL_MAXID 7 + +#define UDPCTL_NAMES { \ + { 0, 0 }, \ + { "checksum", CTLTYPE_INT }, \ + { "baddynamic", CTLTYPE_STRUCT }, \ + { "recvspace", CTLTYPE_INT }, \ + { "sendspace", CTLTYPE_INT }, \ + { "stats", CTLTYPE_STRUCT }, \ + { "rootonly", CTLTYPE_STRUCT }, \ +} + +#ifdef _KERNEL + +#include + +enum udpstat_counters { + /* input statistics: */ + udps_ipackets, /* total input packets */ + udps_hdrops, /* packet shorter than header */ + udps_badsum, /* checksum error */ + udps_nosum, /* no checksum */ + udps_badlen, /* data length larger than packet */ + udps_noport, /* no socket on port */ + udps_noportbcast, /* of above, arrived as broadcast */ + udps_nosec, /* dropped for lack of ipsec */ + udps_fullsock, /* not delivered, input socket full */ + udps_pcbhashmiss, /* input packets missing pcb hash */ + udps_inswcsum, /* input software-csummed packets */ + /* output statistics: */ + udps_opackets, /* total output packets */ + udps_outswcsum, /* output software-csummed packets */ + + udps_ncounters +}; + +extern struct cpumem *udpcounters; + +static inline void +udpstat_inc(enum udpstat_counters c) +{ + counters_inc(udpcounters, c); +} + +extern struct inpcbtable udbtable, udb6table; +extern struct udpstat udpstat; + +extern const struct pr_usrreqs udp_usrreqs; + +#ifdef INET6 +extern const struct pr_usrreqs udp6_usrreqs; +#endif + +#ifdef INET6 +void udp6_ctlinput(int, struct sockaddr *, u_int, void *); +#endif /* INET6 */ +void udp_ctlinput(int, struct sockaddr *, u_int, void *); +void udp_init(void); +int udp_input(struct mbuf **, int *, int, int, struct netstack *); +#ifdef INET6 +int udp6_output(struct inpcb *, struct mbuf *, struct mbuf *, + struct mbuf *); +#endif /* INET6 */ +int udp_sysctl(int *, u_int, void *, size_t *, void *, size_t); +int udp_attach(struct socket *, int, int); +int udp_detach(struct socket *); +int udp_bind(struct socket *, struct mbuf *, struct proc *); +int udp_connect(struct socket *, struct mbuf *); +int udp_disconnect(struct socket *); +int udp_shutdown(struct socket *); +int udp_send(struct socket *, struct mbuf *, struct mbuf *, + struct mbuf *); +#endif /* _KERNEL */ +#endif /* _NETINET_UDP_VAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet6/in6.h b/lib/libc/include/generic-openbsd/netinet6/in6.h new file mode 100644 index 0000000000..f1130bdbae --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet6/in6.h @@ -0,0 +1,685 @@ +/* $OpenBSD: in6.h,v 1.125 2025/09/16 09:19:16 florian Exp $ */ +/* $KAME: in6.h,v 1.83 2001/03/29 02:55:07 jinmei Exp $ */ + +/* + * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. + * 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 project 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 PROJECT 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 PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Copyright (c) 1982, 1986, 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)in.h 8.3 (Berkeley) 1/3/94 + */ + +#ifndef __KAME_NETINET_IN_H_INCLUDED_ +#error "do not include netinet6/in6.h directly, include netinet/in.h. see RFC2553" +#endif + +#ifndef _NETINET6_IN6_H_ +#define _NETINET6_IN6_H_ + +/* + * Identification of the network protocol stack + * for *BSD-current/release: http://www.kame.net/dev/cvsweb2.cgi/kame/COVERAGE + * has the table of implementation/integration differences. + */ +#define __KAME__ + +/* + * IPv6 address + */ +struct in6_addr { + union { + u_int8_t __u6_addr8[16]; + u_int16_t __u6_addr16[8]; + u_int32_t __u6_addr32[4]; + } __u6_addr; /* 128-bit IP6 address */ +}; + +#define s6_addr __u6_addr.__u6_addr8 +#ifdef _KERNEL /* XXX nonstandard */ +#define s6_addr8 __u6_addr.__u6_addr8 +#define s6_addr16 __u6_addr.__u6_addr16 +#define s6_addr32 __u6_addr.__u6_addr32 +#endif + +#ifndef INET6_ADDRSTRLEN +#define INET6_ADDRSTRLEN 46 +#endif + +/* + * Socket address for IPv6 + */ +#if __BSD_VISIBLE +#define SIN6_LEN /* Indicates sockaddr_in6 has a sin6_len field */ +#endif /* __BSD_VISIBLE */ +struct sockaddr_in6 { + u_int8_t sin6_len; /* length of this struct(sa_family_t)*/ + sa_family_t sin6_family; /* AF_INET6 (sa_family_t) */ + in_port_t sin6_port; /* Transport layer port # (in_port_t)*/ + u_int32_t sin6_flowinfo; /* IP6 flow information */ + struct in6_addr sin6_addr; /* IP6 address */ + u_int32_t sin6_scope_id; /* intface scope id */ +}; + + +/* + * Local definition for masks + */ +#ifdef _KERNEL /* XXX nonstandard */ +#define IN6MASK0 {{{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}} +#define IN6MASK32 {{{ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} +#define IN6MASK64 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} +#define IN6MASK96 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ + 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }}} +#define IN6MASK128 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}} + +extern const struct sockaddr_in6 sa6_any; + +extern const struct in6_addr in6mask0; +extern const struct in6_addr in6mask32; +extern const struct in6_addr in6mask64; +extern const struct in6_addr in6mask96; +extern const struct in6_addr in6mask128; +#endif /* _KERNEL */ + +/* Both kernel and libc define these for use */ +extern const struct in6_addr in6addr_any; +extern const struct in6_addr in6addr_loopback; +extern const struct in6_addr in6addr_intfacelocal_allnodes; +extern const struct in6_addr in6addr_linklocal_allnodes; +extern const struct in6_addr in6addr_linklocal_allrouters; + +#if __BSD_VISIBLE +/* + * Definition of some useful macros to handle IP6 addresses + */ +#define IN6ADDR_ANY_INIT \ + {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}} +#define IN6ADDR_LOOPBACK_INIT \ + {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} +#define IN6ADDR_NODELOCAL_ALLNODES_INIT \ + {{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} +#define IN6ADDR_INTFACELOCAL_ALLNODES_INIT \ + {{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} +#define IN6ADDR_LINKLOCAL_ALLNODES_INIT \ + {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}} +#define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \ + {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}} + +#define IN6_ARE_ADDR_EQUAL(a, b) \ + (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0) + +#endif /* __BSD_VISIBLE */ + +/* + * Macros started with IPV6_ADDR is KAME local + */ +#define __IPV6_ADDR_INT32_ONE htonl(1) +#define __IPV6_ADDR_INT32_TWO htonl(2) +#define __IPV6_ADDR_INT32_MNL htonl(0xff010000) +#define __IPV6_ADDR_INT32_MLL htonl(0xff020000) +#define __IPV6_ADDR_INT32_SMP htonl(0x0000ffff) +#define __IPV6_ADDR_INT16_ULL htons(0xfe80) +#define __IPV6_ADDR_INT16_USL htons(0xfec0) +#define __IPV6_ADDR_INT16_MLL htons(0xff02) + +/* + * Unspecified + */ +#define IN6_IS_ADDR_UNSPECIFIED(a) \ + ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ + (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ + (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ + (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) == 0)) + +/* + * Loopback + */ +#define IN6_IS_ADDR_LOOPBACK(a) \ + ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ + (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ + (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ + (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) == __IPV6_ADDR_INT32_ONE)) + +/* + * IPv4 compatible + */ +#define IN6_IS_ADDR_V4COMPAT(a) \ + ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ + (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ + (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ + (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) != 0) && \ + (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) != __IPV6_ADDR_INT32_ONE)) + +/* + * Mapped + */ +#define IN6_IS_ADDR_V4MAPPED(a) \ + ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ + (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ + (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == __IPV6_ADDR_INT32_SMP)) + +/* + * Unicast Scope + * Note that we must check topmost 10 bits only, not 16 bits (see RFC2373). + */ +#define IN6_IS_ADDR_LINKLOCAL(a) \ + (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80)) +#define IN6_IS_ADDR_SITELOCAL(a) \ + (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0)) + +/* + * Multicast + */ +#define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f) +#define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff) + +#define __IPV6_ADDR_SCOPE_NODELOCAL 0x01 +#define __IPV6_ADDR_SCOPE_INTFACELOCAL 0x01 +#define __IPV6_ADDR_SCOPE_LINKLOCAL 0x02 +#define __IPV6_ADDR_SCOPE_SITELOCAL 0x05 +#define __IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */ +#define __IPV6_ADDR_SCOPE_GLOBAL 0x0e + +#define IN6_IS_ADDR_MC_NODELOCAL(a) \ + (IN6_IS_ADDR_MULTICAST(a) && \ + (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_NODELOCAL)) +#define IN6_IS_ADDR_MC_INTFACELOCAL(a) \ + (IN6_IS_ADDR_MULTICAST(a) && \ + (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_INTFACELOCAL)) +#define IN6_IS_ADDR_MC_LINKLOCAL(a) \ + (IN6_IS_ADDR_MULTICAST(a) && \ + (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_LINKLOCAL)) +#define IN6_IS_ADDR_MC_SITELOCAL(a) \ + (IN6_IS_ADDR_MULTICAST(a) && \ + (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL)) +#define IN6_IS_ADDR_MC_ORGLOCAL(a) \ + (IN6_IS_ADDR_MULTICAST(a) && \ + (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL)) +#define IN6_IS_ADDR_MC_GLOBAL(a) \ + (IN6_IS_ADDR_MULTICAST(a) && \ + (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_GLOBAL)) + +#ifdef _KERNEL +#define IN6_IS_SCOPE_LINKLOCAL(a) \ + ((IN6_IS_ADDR_LINKLOCAL(a)) || \ + (IN6_IS_ADDR_MC_LINKLOCAL(a))) +#define IN6_IS_SCOPE_EMBED(a) \ + ((IN6_IS_ADDR_LINKLOCAL(a)) || \ + (IN6_IS_ADDR_MC_LINKLOCAL(a)) || \ + (IN6_IS_ADDR_MC_INTFACELOCAL(a))) + +#define IFA6_IS_DEPRECATED(a) \ + ((a)->ia6_lifetime.ia6t_pltime != ND6_INFINITE_LIFETIME && \ + (u_int32_t)((getuptime() - (a)->ia6_updatetime)) > \ + (a)->ia6_lifetime.ia6t_pltime) +#define IFA6_IS_INVALID(a) \ + ((a)->ia6_lifetime.ia6t_vltime != ND6_INFINITE_LIFETIME && \ + (u_int32_t)((getuptime() - (a)->ia6_updatetime)) > \ + (a)->ia6_lifetime.ia6t_vltime) + +#endif /* _KERNEL */ + +/* + * Options for use with [gs]etsockopt at the IPV6 level. + * First word of comment is data type; bool is stored in int. + */ +#define IPV6_UNICAST_HOPS 4 /* int; IP6 hops */ +#define IPV6_MULTICAST_IF 9 /* u_int; set/get IP6 multicast i/f */ +#define IPV6_MULTICAST_HOPS 10 /* u_int; set/get IP6 multicast hops */ +#define IPV6_MULTICAST_LOOP 11 /* u_int; set/get IP6 multicast loopback */ +#define IPV6_JOIN_GROUP 12 /* ip6_mreq; join a group membership */ +#define IPV6_LEAVE_GROUP 13 /* ip6_mreq; leave a group membership */ +#define IPV6_PORTRANGE 14 /* int; range to choose for unspec port */ +#if __BSD_VISIBLE +#define ICMP6_FILTER 18 /* icmp6_filter; icmp6 filter */ +#endif + +#define IPV6_CHECKSUM 26 /* int; checksum offset for raw socket */ +#define IPV6_V6ONLY 27 /* bool; make AF_INET6 sockets v6 only */ + +/* new socket options introduced in RFC3542 */ +#define IPV6_RTHDRDSTOPTS 35 /* ip6_dest; send dst option before rthdr */ + +#define IPV6_RECVPKTINFO 36 /* bool; recv if, dst addr */ +#define IPV6_RECVHOPLIMIT 37 /* bool; recv hop limit */ +#define IPV6_RECVRTHDR 38 /* bool; recv routing header */ +#define IPV6_RECVHOPOPTS 39 /* bool; recv hop-by-hop option */ +#define IPV6_RECVDSTOPTS 40 /* bool; recv dst option after rthdr */ + +#define IPV6_USE_MIN_MTU 42 /* bool; send packets at the minimum MTU */ +#define IPV6_RECVPATHMTU 43 /* bool; notify an according MTU */ + +#define IPV6_PATHMTU 44 /* mtuinfo; get the current path MTU (sopt), + 4 bytes int; MTU notification (cmsg) */ + +/* More new socket options introduced in RFC3542 */ +#define IPV6_PKTINFO 46 /* in6_pktinfo; send if, src addr */ +#define IPV6_HOPLIMIT 47 /* int; send hop limit */ +#define IPV6_NEXTHOP 48 /* sockaddr; next hop addr */ +#define IPV6_HOPOPTS 49 /* ip6_hbh; send hop-by-hop option */ +#define IPV6_DSTOPTS 50 /* ip6_dest; send dst option before rthdr */ +#define IPV6_RTHDR 51 /* ip6_rthdr; send routing header */ + +#define IPV6_AUTH_LEVEL 53 /* int; authentication used */ +#define IPV6_ESP_TRANS_LEVEL 54 /* int; transport encryption */ +#define IPV6_ESP_NETWORK_LEVEL 55 /* int; full-packet encryption */ +#if __BSD_VISIBLE +#define IPSEC6_OUTSA 56 /* set the outbound SA for a socket */ +#endif +#define IPV6_RECVTCLASS 57 /* bool; recv traffic class values */ + +#define IPV6_AUTOFLOWLABEL 59 /* bool; attach flowlabel automagically */ +#define IPV6_IPCOMP_LEVEL 60 /* int; compression */ + +#define IPV6_TCLASS 61 /* int; send traffic class value */ +#define IPV6_DONTFRAG 62 /* bool; disable IPv6 fragmentation */ +#define IPV6_PIPEX 63 /* bool; using PIPEX */ + +#define IPV6_RECVDSTPORT 64 /* bool; receive IP dst port w/dgram */ +#define IPV6_MINHOPCOUNT 65 /* int; minimum recv hop limit */ + +#define IPV6_RTABLE 0x1021 /* int; routing table, see SO_RTABLE */ + +/* to define items, should talk with KAME guys first, for *BSD compatibility */ +#define IPV6_RTHDR_LOOSE 0 /* this hop need not be a neighbor */ +#define IPV6_RTHDR_TYPE_0 0 /* IPv6 routing header type 0 */ + +/* + * Defaults and limits for options + */ +#define IPV6_DEFAULT_MULTICAST_HOPS 1 /* normally limit m'casts to 1 hop */ +#define IPV6_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */ + +/* + * Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP. + */ +struct ipv6_mreq { + struct in6_addr ipv6mr_multiaddr; + unsigned int ipv6mr_interface; +}; + +/* + * IPV6_PKTINFO: Packet information(RFC3542 sec 6) + */ +struct in6_pktinfo { + struct in6_addr ipi6_addr; /* src/dst IPv6 address */ + unsigned int ipi6_ifindex; /* send/recv interface index */ +}; + +/* + * Control structure for IPV6_RECVPATHMTU socket option. + * XXX Not allowed here by POSIX, but required by RFC 3542, so go + * XXX with the code on the pavement. + */ +struct ip6_mtuinfo { + struct sockaddr_in6 ip6m_addr; /* or sockaddr_storage? */ + u_int32_t ip6m_mtu; +}; + +/* + * Argument for IPV6_PORTRANGE: + * - which range to search when port is unspecified at bind() or connect() + */ +#define IPV6_PORTRANGE_DEFAULT 0 /* default range */ +#define IPV6_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */ +#define IPV6_PORTRANGE_LOW 2 /* "low" - vouchsafe security */ + +#ifdef __BSD_VISIBLE + +#ifndef _SOCKLEN_T_DEFINED_ +#define _SOCKLEN_T_DEFINED_ +typedef __socklen_t socklen_t; /* length type for network syscalls */ +#endif + +#endif /* __BSD_VISIBLE */ + +#ifdef _KERNEL +extern const u_char inet6ctlerrmap[]; +extern const struct in6_addr zeroin6_addr; + +struct mbuf; +struct sockaddr; +struct sockaddr_in6; +struct ifaddr; +struct in6_ifaddr; +struct ifnet; +struct rtentry; +struct netstack; + +void ipv6_input(struct ifnet *, struct mbuf *, struct netstack *); +struct mbuf * + ipv6_check(struct ifnet *, struct mbuf *); + +int in6_cksum(struct mbuf *, uint8_t, uint32_t, uint32_t); +void in6_proto_cksum_out(struct mbuf *, struct ifnet *); +int in6_addrscope(const struct in6_addr *); +struct in6_ifaddr *in6_ifawithscope(struct ifnet *, const struct in6_addr *, + u_int, struct rtentry *); +int in6_mask2len(struct in6_addr *, u_char *); +int in6_nam2sin6(const struct mbuf *, struct sockaddr_in6 **); +int in6_sa2sin6(struct sockaddr *, struct sockaddr_in6 **); + +struct ip6_pktopts; +struct ip6_moptions; + +int in6_embedscope(struct in6_addr *, const struct sockaddr_in6 *, + const struct ip6_pktopts *, const struct ip6_moptions *); +void in6_recoverscope(struct sockaddr_in6 *, const struct in6_addr *); +void in6_clearscope(struct in6_addr *); + +/* + * Convert between address family specific and general structs. + * Inline functions check the source type and are stricter than + * casts or defines. + */ + +static inline struct sockaddr_in6 * +satosin6(struct sockaddr *sa) +{ + return ((struct sockaddr_in6 *)(sa)); +} + +static inline const struct sockaddr_in6 * +satosin6_const(const struct sockaddr *sa) +{ + return ((const struct sockaddr_in6 *)(sa)); +} + +static inline struct sockaddr * +sin6tosa(struct sockaddr_in6 *sin6) +{ + return ((struct sockaddr *)(sin6)); +} + +static inline const struct sockaddr * +sin6tosa_const(const struct sockaddr_in6 *sin6) +{ + return ((const struct sockaddr *)(sin6)); +} + +static inline struct in6_ifaddr * +ifatoia6(struct ifaddr *ifa) +{ + return ((struct in6_ifaddr *)(ifa)); +} + +#endif /* _KERNEL */ + +#if __BSD_VISIBLE +/* + * Definitions for inet6 sysctl operations. + * + * Third level is protocol number. + * Fourth level is desired variable within that protocol. + */ +#define IPV6PROTO_MAXID (IPPROTO_DIVERT + 1) /* don't list to IPV6PROTO_MAX */ + +#define CTL_IPV6PROTO_NAMES { \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, \ + { "tcp6", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "udp6", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, \ + { "ip6", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, \ + { "ipsec6", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "icmp6", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ +/*110*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ +/*120*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ +/*130*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ +/*140*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ +/*150*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ +/*160*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ +/*170*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ +/*180*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ +/*190*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ +/*200*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ +/*210*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ +/*220*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ +/*230*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ +/*240*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ +/*250*/ { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "divert", CTLTYPE_NODE }, \ +} + +/* + * Names for IP sysctl objects + */ +#define IPV6CTL_FORWARDING 1 /* act as router */ +#define IPV6CTL_SENDREDIRECTS 2 /* may send redirects when forwarding*/ +#define IPV6CTL_DEFHLIM 3 /* default Hop-Limit */ +#define IPV6CTL_FORWSRCRT 5 /* forward source-routed dgrams */ +#define IPV6CTL_STATS 6 /* stats */ +#define IPV6CTL_MRTSTATS 7 /* multicast forwarding stats */ +#define IPV6CTL_MRTPROTO 8 /* multicast routing protocol */ +#define IPV6CTL_MAXFRAGPACKETS 9 /* max packets reassembly queue */ +#define IPV6CTL_SOURCECHECK 10 /* verify source route and intf */ +#define IPV6CTL_SOURCECHECK_LOGINT 11 /* minimum logging interval */ +#define IPV6CTL_ACCEPT_RTADV 12 +#define IPV6CTL_LOG_INTERVAL 14 +#define IPV6CTL_HDRNESTLIMIT 15 +#define IPV6CTL_DAD_COUNT 16 +#define IPV6CTL_AUTO_FLOWLABEL 17 +#define IPV6CTL_DEFMCASTHLIM 18 +/* 24 to 40: reserved */ +#define IPV6CTL_MAXFRAGS 41 /* max fragments */ +#define IPV6CTL_MFORWARDING 42 +#define IPV6CTL_MULTIPATH 43 +#define IPV6CTL_MCAST_PMTU 44 /* path MTU discovery for multicast */ +#define IPV6CTL_NEIGHBORGCTHRESH 45 +#define IPV6CTL_MAXDYNROUTES 48 +#define IPV6CTL_DAD_PENDING 49 +#define IPV6CTL_MTUDISCTIMEOUT 50 +#define IPV6CTL_IFQUEUE 51 +#define IPV6CTL_MRTMIF 52 +#define IPV6CTL_MRTMFC 53 +#define IPV6CTL_MAXID 54 + +/* New entries should be added here from current IPV6CTL_MAXID value. */ +/* to define items, should talk with KAME guys first, for *BSD compatibility */ + +#define IPV6CTL_NAMES { \ + { 0, 0 }, \ + { "forwarding", CTLTYPE_INT }, \ + { "redirect", CTLTYPE_INT }, \ + { "hlim", CTLTYPE_INT }, \ + { 0, 0 }, \ + { "forwsrcrt", CTLTYPE_INT }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "mrtproto", CTLTYPE_INT }, \ + { "maxfragpackets", CTLTYPE_INT }, \ + { "sourcecheck", CTLTYPE_INT }, \ + { "sourcecheck_logint", CTLTYPE_INT }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "hdrnestlimit", CTLTYPE_INT }, \ + { "dad_count", CTLTYPE_INT }, \ + { 0, 0 }, \ + { "defmcasthlim", CTLTYPE_INT }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "maxfrags", CTLTYPE_INT }, \ + { "mforwarding", CTLTYPE_INT }, \ + { "multipath", CTLTYPE_INT }, \ + { "multicast_mtudisc", CTLTYPE_INT }, \ + { "neighborgcthresh", CTLTYPE_INT }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "maxdynroutes", CTLTYPE_INT }, \ + { "dad_pending", CTLTYPE_INT }, \ + { "mtudisctimeout", CTLTYPE_INT }, \ + { "ifq", CTLTYPE_NODE }, \ + { "mrtmif", CTLTYPE_STRUCT }, \ + { "mrtmfc", CTLTYPE_STRUCT }, \ +} + +__BEGIN_DECLS +struct cmsghdr; + +extern int inet6_opt_init(void *, socklen_t); +extern int inet6_opt_append(void *, socklen_t, int, u_int8_t, + socklen_t, u_int8_t, void **); +extern int inet6_opt_finish(void *, socklen_t, int); +extern int inet6_opt_set_val(void *, int, void *, socklen_t); + +extern int inet6_opt_next(void *, socklen_t, int, u_int8_t *, + socklen_t *, void **); +extern int inet6_opt_find(void *, socklen_t, int, u_int8_t, + socklen_t *, void **); +extern int inet6_opt_get_val(void *, int, void *, socklen_t); + +extern socklen_t inet6_rth_space(int, int); +extern void *inet6_rth_init(void *, socklen_t, int, int); +extern int inet6_rth_add(void *, const struct in6_addr *); +extern int inet6_rth_reverse(const void *, void *); +extern int inet6_rth_segments(const void *); +extern struct in6_addr *inet6_rth_getaddr(const void *, int); +__END_DECLS +#endif /* __BSD_VISIBLE */ + +#endif /* !_NETINET6_IN6_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet6/in6_ifattach.h b/lib/libc/include/generic-openbsd/netinet6/in6_ifattach.h new file mode 100644 index 0000000000..b299d23c96 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet6/in6_ifattach.h @@ -0,0 +1,42 @@ +/* $OpenBSD: in6_ifattach.h,v 1.10 2019/08/21 15:32:18 florian Exp $ */ +/* $KAME: in6_ifattach.h,v 1.9 2000/04/12 05:35:48 itojun Exp $ */ + +/* + * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. + * 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 project 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 PROJECT 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 PROJECT 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 _NETINET6_IN6_IFATTACH_H_ +#define _NETINET6_IN6_IFATTACH_H_ + +#ifdef _KERNEL +int in6_ifattach(struct ifnet *); +void in6_ifdetach(struct ifnet *); +int in6_ifattach_linklocal(struct ifnet *, struct in6_addr *); +#endif /* _KERNEL */ + +#endif /* _NETINET6_IN6_IFATTACH_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet6/in6_var.h b/lib/libc/include/generic-openbsd/netinet6/in6_var.h new file mode 100644 index 0000000000..c928f8f619 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet6/in6_var.h @@ -0,0 +1,372 @@ +/* $OpenBSD: in6_var.h,v 1.81 2025/05/20 05:51:43 bluhm Exp $ */ +/* $KAME: in6_var.h,v 1.55 2001/02/16 12:49:45 itojun Exp $ */ + +/* + * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. + * 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 project 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 PROJECT 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 PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Copyright (c) 1985, 1986, 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. + * + * @(#)in_var.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NETINET6_IN6_VAR_H_ +#define _NETINET6_IN6_VAR_H_ + +/* + * Interface address, Internet version. One of these structures + * is allocated for each interface with an Internet address. + * The ifaddr structure contains the protocol-independent part + * of the structure and is assumed to be first. + */ + +/* + * pltime/vltime are just for future reference (required to implements 2 + * hour rule for hosts). they should never be modified by nd6_timeout or + * anywhere else. + * userland -> kernel: accept pltime/vltime + * kernel -> userland: throw up everything + * in kernel: modify preferred/expire only + */ +struct in6_addrlifetime { + time_t ia6t_expire; /* valid lifetime expiration time */ + time_t ia6t_preferred; /* preferred lifetime expiration time */ + u_int32_t ia6t_vltime; /* valid lifetime */ + u_int32_t ia6t_pltime; /* prefix lifetime */ +}; + +#ifdef _KERNEL +struct in6_ifaddr { + struct ifaddr ia_ifa; /* protocol-independent info */ +#define ia_ifp ia_ifa.ifa_ifp +#define ia_flags ia_ifa.ifa_flags + + struct sockaddr_in6 ia_addr; /* interface address */ + struct sockaddr_in6 ia_gwaddr; /* router we learned address from */ + struct sockaddr_in6 ia_dstaddr; /* space for destination addr */ + struct sockaddr_in6 ia_prefixmask; /* prefix mask */ + TAILQ_ENTRY(in6_ifaddr) ia_list; /* list of IP6 addresses */ + int ia6_flags; + + struct in6_addrlifetime ia6_lifetime; + time_t ia6_updatetime; + + /* multicast addresses joined from the kernel */ + LIST_HEAD(, in6_multi_mship) ia6_memberships; +}; +#endif /* _KERNEL */ + +/* + * IPv6 interface statistics, as defined in RFC2465 Ipv6IfStatsEntry (p12). + */ +struct in6_ifstat { + u_int64_t ifs6_in_receive; /* # of total input datagram */ + u_int64_t ifs6_in_hdrerr; /* # of datagrams with invalid hdr */ + u_int64_t ifs6_in_toobig; /* # of datagrams exceeded MTU */ + u_int64_t ifs6_in_noroute; /* # of datagrams with no route */ + u_int64_t ifs6_in_addrerr; /* # of datagrams with invalid dst */ + u_int64_t ifs6_in_protounknown; /* # of datagrams with unknown proto */ + /* NOTE: increment on final dst if */ + u_int64_t ifs6_in_truncated; /* # of truncated datagrams */ + u_int64_t ifs6_in_discard; /* # of discarded datagrams */ + /* NOTE: fragment timeout is not here */ + u_int64_t ifs6_in_deliver; /* # of datagrams delivered to ULP */ + /* NOTE: increment on final dst if */ + u_int64_t ifs6_out_forward; /* # of datagrams forwarded */ + /* NOTE: increment on outgoing if */ + u_int64_t ifs6_out_request; /* # of outgoing datagrams from ULP */ + /* NOTE: does not include forwards */ + u_int64_t ifs6_out_discard; /* # of discarded datagrams */ + u_int64_t ifs6_out_fragok; /* # of datagrams fragmented */ + u_int64_t ifs6_out_fragfail; /* # of datagrams failed on fragment */ + u_int64_t ifs6_out_fragcreat; /* # of fragment datagrams */ + /* NOTE: this is # after fragment */ + u_int64_t ifs6_reass_reqd; /* # of incoming fragmented packets */ + /* NOTE: increment on final dst if */ + u_int64_t ifs6_reass_ok; /* # of reassembled packets */ + /* NOTE: this is # after reass */ + /* NOTE: increment on final dst if */ + u_int64_t ifs6_reass_fail; /* # of reass failures */ + /* NOTE: may not be packet count */ + /* NOTE: increment on final dst if */ + u_int64_t ifs6_in_mcast; /* # of inbound multicast datagrams */ + u_int64_t ifs6_out_mcast; /* # of outbound multicast datagrams */ +}; + +/* + * ICMPv6 interface statistics, as defined in RFC2466 Ipv6IfIcmpEntry. + * XXX: I'm not sure if this file is the right place for this structure... + */ +struct icmp6_ifstat { + /* + * Input statistics + */ + /* ipv6IfIcmpInMsgs, total # of input messages */ + u_int64_t ifs6_in_msg; + /* ipv6IfIcmpInErrors, # of input error messages */ + u_int64_t ifs6_in_error; + /* ipv6IfIcmpInDestUnreachs, # of input dest unreach errors */ + u_int64_t ifs6_in_dstunreach; + /* ipv6IfIcmpInAdminProhibs, # of input administratively prohibited errs */ + u_int64_t ifs6_in_adminprohib; + /* ipv6IfIcmpInTimeExcds, # of input time exceeded errors */ + u_int64_t ifs6_in_timeexceed; + /* ipv6IfIcmpInParmProblems, # of input parameter problem errors */ + u_int64_t ifs6_in_paramprob; + /* ipv6IfIcmpInPktTooBigs, # of input packet too big errors */ + u_int64_t ifs6_in_pkttoobig; + /* ipv6IfIcmpInEchos, # of input echo requests */ + u_int64_t ifs6_in_echo; + /* ipv6IfIcmpInEchoReplies, # of input echo replies */ + u_int64_t ifs6_in_echoreply; + /* ipv6IfIcmpInRouterSolicits, # of input router solicitations */ + u_int64_t ifs6_in_routersolicit; + /* ipv6IfIcmpInRouterAdvertisements, # of input router advertisements */ + u_int64_t ifs6_in_routeradvert; + /* ipv6IfIcmpInNeighborSolicits, # of input neighbor solicitations */ + u_int64_t ifs6_in_neighborsolicit; + /* ipv6IfIcmpInNeighborAdvertisements, # of input neighbor advertisements */ + u_int64_t ifs6_in_neighboradvert; + /* ipv6IfIcmpInRedirects, # of input redirects */ + u_int64_t ifs6_in_redirect; + /* ipv6IfIcmpInGroupMembQueries, # of input MLD queries */ + u_int64_t ifs6_in_mldquery; + /* ipv6IfIcmpInGroupMembResponses, # of input MLD reports */ + u_int64_t ifs6_in_mldreport; + /* ipv6IfIcmpInGroupMembReductions, # of input MLD done */ + u_int64_t ifs6_in_mlddone; + + /* + * Output statistics. We should solve unresolved routing problem... + */ + /* ipv6IfIcmpOutMsgs, total # of output messages */ + u_int64_t ifs6_out_msg; + /* ipv6IfIcmpOutErrors, # of output error messages */ + u_int64_t ifs6_out_error; + /* ipv6IfIcmpOutDestUnreachs, # of output dest unreach errors */ + u_int64_t ifs6_out_dstunreach; + /* ipv6IfIcmpOutAdminProhibs, # of output administratively prohibited errs */ + u_int64_t ifs6_out_adminprohib; + /* ipv6IfIcmpOutTimeExcds, # of output time exceeded errors */ + u_int64_t ifs6_out_timeexceed; + /* ipv6IfIcmpOutParmProblems, # of output parameter problem errors */ + u_int64_t ifs6_out_paramprob; + /* ipv6IfIcmpOutPktTooBigs, # of output packet too big errors */ + u_int64_t ifs6_out_pkttoobig; + /* ipv6IfIcmpOutEchos, # of output echo requests */ + u_int64_t ifs6_out_echo; + /* ipv6IfIcmpOutEchoReplies, # of output echo replies */ + u_int64_t ifs6_out_echoreply; + /* ipv6IfIcmpOutRouterSolicits, # of output router solicitations */ + u_int64_t ifs6_out_routersolicit; + /* ipv6IfIcmpOutRouterAdvertisements, # of output router advertisements */ + u_int64_t ifs6_out_routeradvert; + /* ipv6IfIcmpOutNeighborSolicits, # of output neighbor solicitations */ + u_int64_t ifs6_out_neighborsolicit; + /* ipv6IfIcmpOutNeighborAdvertisements, # of output neighbor advertisements */ + u_int64_t ifs6_out_neighboradvert; + /* ipv6IfIcmpOutRedirects, # of output redirects */ + u_int64_t ifs6_out_redirect; + /* ipv6IfIcmpOutGroupMembQueries, # of output MLD queries */ + u_int64_t ifs6_out_mldquery; + /* ipv6IfIcmpOutGroupMembResponses, # of output MLD reports */ + u_int64_t ifs6_out_mldreport; + /* ipv6IfIcmpOutGroupMembReductions, # of output MLD done */ + u_int64_t ifs6_out_mlddone; +}; + +struct in6_ifreq { + char ifr_name[IFNAMSIZ]; + union { + struct sockaddr_in6 ifru_addr; + struct sockaddr_in6 ifru_dstaddr; + short ifru_flags; + int ifru_flags6; + int ifru_metric; + caddr_t ifru_data; + struct in6_addrlifetime ifru_lifetime; + struct in6_ifstat ifru_stat; + struct icmp6_ifstat ifru_icmp6stat; + } ifr_ifru; +}; + +struct in6_aliasreq { + char ifra_name[IFNAMSIZ]; + union { + struct sockaddr_in6 ifrau_addr; + int ifrau_align; + } ifra_ifrau; +#ifndef ifra_addr +#define ifra_addr ifra_ifrau.ifrau_addr +#endif + struct sockaddr_in6 ifra_dstaddr; + struct sockaddr_in6 ifra_prefixmask; + int ifra_flags; + struct in6_addrlifetime ifra_lifetime; +}; + +/* + * Given a pointer to an in6_ifaddr (ifaddr), + * return a pointer to the addr as a sockaddr_in6 + */ +#define IA6_IN6(ia) (&((ia)->ia_addr.sin6_addr)) +#define IA6_DSTIN6(ia) (&((ia)->ia_dstaddr.sin6_addr)) +#define IA6_MASKIN6(ia) (&((ia)->ia_prefixmask.sin6_addr)) +#define IA6_SIN6(ia) (&((ia)->ia_addr)) +#define IA6_DSTSIN6(ia) (&((ia)->ia_dstaddr)) +#define IFA_IN6(x) (&((struct sockaddr_in6 *)((x)->ifa_addr))->sin6_addr) +#define IFA_DSTIN6(x) (&((struct sockaddr_in6 *)((x)->ifa_dstaddr))->sin6_addr) + +#define SIOCDIFADDR_IN6 _IOW('i', 25, struct in6_ifreq) +#define SIOCAIFADDR_IN6 _IOW('i', 26, struct in6_aliasreq) + +#define SIOCGIFDSTADDR_IN6 _IOWR('i', 34, struct in6_ifreq) +#define SIOCGIFNETMASK_IN6 _IOWR('i', 37, struct in6_ifreq) + +#define SIOCGIFAFLAG_IN6 _IOWR('i', 73, struct in6_ifreq) + +#define SIOCGIFINFO_IN6 _IOWR('i', 108, struct in6_ndireq) +#define SIOCGNBRINFO_IN6 _IOWR('i', 78, struct in6_nbrinfo) + +#define SIOCGIFALIFETIME_IN6 _IOWR('i', 81, struct in6_ifreq) + +#define SIOCGETSGCNT_IN6 _IOWR('u', 106, struct sioc_sg_req6) +#define SIOCGETMIFCNT_IN6 _IOWR('u', 107, struct sioc_mif_req6) + +#define IN6_IFF_ANYCAST 0x01 /* anycast address */ +#define IN6_IFF_TENTATIVE 0x02 /* tentative address */ +#define IN6_IFF_DUPLICATED 0x04 /* DAD detected duplicate */ +#define IN6_IFF_DETACHED 0x08 /* may be detached from the link */ +#define IN6_IFF_DEPRECATED 0x10 /* deprecated address */ +#define IN6_IFF_AUTOCONF 0x40 /* autoconfigurable address. */ +#define IN6_IFF_TEMPORARY 0x80 /* RFC 4941 temporary address */ + +#ifdef _KERNEL +#define IN6_ARE_MASKED_ADDR_EQUAL(d, a, m) ( \ + (((d)->s6_addr32[0] ^ (a)->s6_addr32[0]) & (m)->s6_addr32[0]) == 0 && \ + (((d)->s6_addr32[1] ^ (a)->s6_addr32[1]) & (m)->s6_addr32[1]) == 0 && \ + (((d)->s6_addr32[2] ^ (a)->s6_addr32[2]) & (m)->s6_addr32[2]) == 0 && \ + (((d)->s6_addr32[3] ^ (a)->s6_addr32[3]) & (m)->s6_addr32[3]) == 0 ) + +#define IN6_ARE_SCOPE_CMP(a,b) ((a)-(b)) +#define IN6_ARE_SCOPE_EQUAL(a,b) ((a)==(b)) + +/* + * Multi-cast membership entry. One for each group/ifp that a PCB + * belongs to. + */ +struct in6_multi_mship { + struct in6_multi *i6mm_maddr; /* Multicast address pointer */ + LIST_ENTRY(in6_multi_mship) i6mm_chain; /* multicast options chain */ +}; + +struct in6_multi { + struct ifmaddr in6m_ifma; /* Protocol-independent info */ +#define in6m_refcnt in6m_ifma.ifma_refcnt +#define in6m_ifidx in6m_ifma.ifma_ifidx + + struct sockaddr_in6 in6m_sin; /* IPv6 multicast address */ +#define in6m_addr in6m_sin.sin6_addr + + u_int in6m_state; /* state of membership */ + u_int in6m_timer; /* MLD6 membership report timer */ +}; + +static __inline struct in6_multi * +ifmatoin6m(struct ifmaddr *ifma) +{ + return ((struct in6_multi *)(ifma)); +} + +/* + * Macros for looking up the in6_multi record for a given IP6 multicast + * address on a given interface. If no matching record is found, "in6m" + * returns NULL. + */ +#define IN6_LOOKUP_MULTI(addr, ifp, in6m) \ + /* struct in6_addr addr; */ \ + /* struct ifnet *ifp; */ \ + /* struct in6_multi *in6m; */ \ +do { \ + struct ifmaddr *ifma; \ + \ + (in6m) = NULL; \ + TAILQ_FOREACH(ifma, &(ifp)->if_maddrlist, ifma_list) \ + if (ifma->ifma_addr->sa_family == AF_INET6 && \ + IN6_ARE_ADDR_EQUAL(&ifmatoin6m(ifma)->in6m_addr, \ + &(addr))) { \ + (in6m) = ifmatoin6m(ifma); \ + break; \ + } \ +} while (/* CONSTCOND */ 0) + +struct in6_multi *in6_addmulti(struct in6_addr *, struct ifnet *, int *); +void in6_delmulti(struct in6_multi *); +int in6_hasmulti(struct in6_addr *, struct ifnet *); +struct in6_multi_mship *in6_joingroup(struct ifnet *, struct in6_addr *, int *); +void in6_leavegroup(struct in6_multi_mship *); +int in6_control(struct socket *, u_long, caddr_t, struct ifnet *); +int in6_ioctl(u_long, caddr_t, struct ifnet *, int); +int in6_update_ifa(struct ifnet *, struct in6_aliasreq *, + struct in6_ifaddr *); +void in6_purgeaddr(struct ifaddr *); +int in6if_do_dad(struct ifnet *); +struct in6_ifaddr *in6ifa_ifpforlinklocal(struct ifnet *, int); +struct in6_ifaddr *in6ifa_ifpwithaddr(struct ifnet *, struct in6_addr *); +int in6_addr2scopeid(unsigned int, const struct in6_addr *); +int in6_matchlen(const struct in6_addr *, const struct in6_addr *); +void in6_prefixlen2mask(struct in6_addr *, int); +#endif /* _KERNEL */ + +#endif /* _NETINET6_IN6_VAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet6/ip6_mroute.h b/lib/libc/include/generic-openbsd/netinet6/ip6_mroute.h new file mode 100644 index 0000000000..d88ea2ab61 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet6/ip6_mroute.h @@ -0,0 +1,265 @@ +/* $OpenBSD: ip6_mroute.h,v 1.25 2025/05/19 04:54:04 jan Exp $ */ +/* $KAME: ip6_mroute.h,v 1.17 2001/02/10 02:05:52 itojun Exp $ */ + +/* + * Copyright (C) 1998 WIDE Project. + * 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 project 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 PROJECT 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 PROJECT 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. + */ + +/* + * Definitions for IP multicast forwarding. + * + * Written by David Waitzman, BBN Labs, August 1988. + * Modified by Steve Deering, Stanford, February 1989. + * Modified by Ajit Thyagarajan, PARC, August 1993. + * Modified by Ajit Thyagarajan, PARC, August 1994. + * Modified by Ahmed Helmy, USC, September 1996. + * + * MROUTING Revision: 1.2 + */ + +#ifndef _NETINET6_IP6_MROUTE_H_ +#define _NETINET6_IP6_MROUTE_H_ + +/* + * Multicast Routing set/getsockopt commands. + */ +#define MRT6_DONE 101 /* shut down forwarder */ +#define MRT6_ADD_MIF 102 /* add multicast interface */ +#define MRT6_DEL_MIF 103 /* delete multicast interface */ +#define MRT6_ADD_MFC 104 /* insert forwarding cache entry */ +#define MRT6_DEL_MFC 105 /* delete forwarding cache entry */ +#define MRT6_INIT 108 /* initialize forwarder (mrt6msg) */ + +/* + * Types and macros for handling bitmaps with one bit per multicast interface. + */ +typedef u_short mifi_t; /* type of a mif index */ +#define MAXMIFS 64 + +/* + * Assume inclusion of sys/param.h or sys/select.h for howmany() + */ +#define __NIFBITS (sizeof(uint32_t) * 8) /* bits per mask */ +typedef struct if_set { + uint32_t ifs_bits[howmany(256, __NIFBITS)]; +} if_set; + +#define IF_SET(n, p) \ + ((p)->ifs_bits[(n)/__NIFBITS] |= (1U << ((n) % __NIFBITS))) +#define IF_CLR(n, p) \ + ((p)->ifs_bits[(n)/__NIFBITS] &= ~(1U << ((n) % __NIFBITS))) +#define IF_ISSET(n, p) \ + ((p)->ifs_bits[(n)/__NIFBITS] & (1U << ((n) % __NIFBITS))) +#define IF_COPY(f, t) memcpy(t, f, sizeof(*(f))) +#define IF_ZERO(p) memset(p, 0, sizeof(*(p))) + +/* + * Argument structure for MRT6_ADD_IF. + */ +struct mif6ctl { + mifi_t mif6c_mifi; /* the index of the mif to be added */ + u_char mif6c_flags; /* MIFF_ flags defined below */ + u_short mif6c_pifi; /* the index of the physical IF */ +#ifdef notyet + u_int mif6c_rate_limit; /* max rate */ +#endif +}; + +#define MIFF_REGISTER 0x1 /* mif represents a register end-point */ + +#define MF6C_INCOMPLETE_PARENT ((mifi_t)-1) + +/* + * Argument structure for MRT6_ADD_MFC and MRT6_DEL_MFC + */ +struct mf6cctl { + struct sockaddr_in6 mf6cc_origin; /* IPv6 origin of mcasts */ + struct sockaddr_in6 mf6cc_mcastgrp; /* multicast group associated */ + mifi_t mf6cc_parent; /* incoming ifindex */ + struct if_set mf6cc_ifset; /* set of forwarding ifs */ +}; + +/* structure used to get all the mif entries via sysctl */ +struct mif6info { + struct in6_addr m6_lcl_addr; /* local interface address */ + u_int16_t m6_ifindex; /* interface index */ + u_int64_t m6_pkt_in; /* # pkts in on interface */ + u_int64_t m6_pkt_out; /* # pkts out on interface */ + u_int64_t m6_bytes_in; /* # bytes in on interface */ + u_int64_t m6_bytes_out; /* # bytes out on interface */ + u_int m6_rate_limit; /* max rate */ + mifi_t m6_mifi; + u_char m6_flags; /* MIFF_ flags defined above */ +}; + +/* structure used to get all the mf6c entries via sysctl */ +struct mf6cinfo { + struct sockaddr_in6 mf6c_origin; /* IPv6 origin of mcasts */ + struct sockaddr_in6 mf6c_mcastgrp; /* multicast group associated*/ + mifi_t mf6c_parent; /* incoming IF */ + struct if_set mf6c_ifset; /* set of outgoing IFs */ + + u_int64_t mf6c_pkt_cnt; /* pkt count for src-grp */ + u_int64_t mf6c_byte_cnt; /* byte count for src-grp */ + u_int64_t mf6c_stall_cnt; /* pkt-cnt waiting for route */ +}; + +/* + * The kernel's multicast routing statistics. + */ +struct mrt6stat { + u_int64_t mrt6s_mfc_lookups; /* # forw. cache hash table hits */ + u_int64_t mrt6s_mfc_misses; /* # forw. cache hash table misses */ + u_int64_t mrt6s_upcalls; /* # calls to mrouted */ + u_int64_t mrt6s_no_route; /* no route for packet's origin */ + u_int64_t mrt6s_bad_tunnel; /* malformed tunnel options */ + u_int64_t mrt6s_cant_tunnel; /* no room for tunnel options */ + u_int64_t mrt6s_wrong_if; /* arrived on wrong interface */ + u_int64_t mrt6s_upq_ovflw; /* upcall Q overflow */ + u_int64_t mrt6s_cache_cleanups; /* # entries with no upcalls */ + u_int64_t mrt6s_drop_sel; /* pkts dropped selectively */ + u_int64_t mrt6s_q_overflow; /* pkts dropped - Q overflow */ + u_int64_t mrt6s_pkt2large; /* pkts dropped - size > BKT SIZE */ + u_int64_t mrt6s_upq_sockfull; /* upcalls dropped - socket full */ +}; + +/* + * Structure used to communicate from kernel to multicast router. + * We'll overlay the structure onto an MLD header (not an IPv6 header + * like igmpmsg{} used for IPv4 implementation). This is because this + * structure will be passed via an IPv6 raw socket, on which an application + * will only receive the payload i.e. the data after the IPv6 header and all + * the extension headers. (see Section 3 of draft-ietf-ipngwg-2292bis-01) + */ +struct mrt6msg { +#define MRT6MSG_NOCACHE 1 +#define MRT6MSG_WRONGMIF 2 +#define MRT6MSG_WHOLEPKT 3 /* used for user level encap*/ + u_char im6_mbz; /* must be zero */ + u_char im6_msgtype; /* what type of message */ + u_int16_t im6_mif; /* mif rec'd on */ + u_int32_t im6_pad; /* padding for 64bit arch */ + struct in6_addr im6_src, im6_dst; +}; + +/* + * Argument structure used by multicast routing daemon to get src-grp + * packet counts + */ +struct sioc_sg_req6 { + struct sockaddr_in6 src; + struct sockaddr_in6 grp; + u_int64_t pktcnt; + u_int64_t bytecnt; + u_int64_t wrong_if; +}; + +/* + * Argument structure used by mrouted to get mif pkt counts + */ +struct sioc_mif_req6 { + mifi_t mifi; /* mif number */ + u_int64_t icount; /* Input packet count on mif */ + u_int64_t ocount; /* Output packet count on mif */ + u_int64_t ibytes; /* Input byte count on mif */ + u_int64_t obytes; /* Output byte count on mif */ +}; + +#if defined(_KERNEL) + +enum mrt6stat_counters { + mrt6s_mfc_lookups, + mrt6s_mfc_misses, + mrt6s_upcalls, + mrt6s_no_route, + mrt6s_bad_tunnel, + mrt6s_cant_tunnel, + mrt6s_wrong_if, + mrt6s_upq_ovflw, + mrt6s_cache_cleanups, + mrt6s_drop_sel, + mrt6s_q_overflow, + mrt6s_pkt2large, + mrt6s_upq_sockfull, + mrt6s_ncounters +}; + +extern struct cpumem *mrt6counters; + +static inline void +mrt6stat_inc(enum mrt6stat_counters c) +{ + counters_inc(mrt6counters, c); +} + +/* How frequent should we look for expired entries (in seconds). */ +#define MCAST_EXPIRE_TIMEOUT 30 + +/* + * The kernel's multicast-interface structure. + */ +struct mif6 { + mifi_t m6_mifi; /* mif index */ + u_char m6_flags; /* MIFF_ flags defined above */ + u_int m6_rate_limit; /* max rate */ +#ifdef notyet + struct tbf *m6_tbf; /* token bucket structure at intf. */ +#endif + struct in6_addr m6_lcl_addr; /* local interface address */ + u_int64_t m6_pkt_in; /* # pkts in on interface */ + u_int64_t m6_pkt_out; /* # pkts out on interface */ + u_int64_t m6_bytes_in; /* # bytes in on interface */ + u_int64_t m6_bytes_out; /* # bytes out on interface */ +}; + +/* + * The kernel's multicast forwarding cache entry structure + */ +struct mf6c { + struct sockaddr_in6 mf6c_origin; /* IPv6 origin of mcasts */ + struct sockaddr_in6 mf6c_mcastgrp; /* multicast group associated*/ + mifi_t mf6c_parent; /* incoming IF */ + + u_int64_t mf6c_pkt_cnt; /* pkt count for src-grp */ + u_int64_t mf6c_byte_cnt; /* byte count for src-grp */ + u_int64_t mf6c_wrong_if; /* wrong if for src-grp */ + int mf6c_expire; /* time to clean entry up */ +}; + +int ip6_mrouter_set(int, struct socket *, struct mbuf *); +int ip6_mrouter_get(int, struct socket *, struct mbuf *); +int ip6_mrouter_done(struct socket *); +void ip6_mrouter_detach(struct ifnet *); +void mrt6_init(void); +int mrt6_ioctl(struct socket *, u_long, caddr_t); +int mrt6_sysctl_mif(void *, size_t *); +int mrt6_sysctl_mrt6stat(void *, size_t *, void *); +int mrt6_sysctl_mfc(void *, size_t *); +#endif /* _KERNEL */ + +#endif /* !_NETINET6_IP6_MROUTE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet6/ip6_var.h b/lib/libc/include/generic-openbsd/netinet6/ip6_var.h new file mode 100644 index 0000000000..e35c2be697 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet6/ip6_var.h @@ -0,0 +1,380 @@ +/* $OpenBSD: ip6_var.h,v 1.128 2025/09/16 09:19:16 florian Exp $ */ +/* $KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $ */ + +/* + * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. + * 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 project 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 PROJECT 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 PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Copyright (c) 1982, 1986, 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. + * + * @(#)ip_var.h 8.1 (Berkeley) 6/10/93 + */ + +#ifndef _NETINET6_IP6_VAR_H_ +#define _NETINET6_IP6_VAR_H_ + +struct ip6stat { + u_int64_t ip6s_total; /* total packets received */ + u_int64_t ip6s_tooshort; /* packet too short */ + u_int64_t ip6s_toosmall; /* not enough data */ + u_int64_t ip6s_fragments; /* fragments received */ + u_int64_t ip6s_fragdropped; /* frags dropped(dups, out of space) */ + u_int64_t ip6s_fragtimeout; /* fragments timed out */ + u_int64_t ip6s_fragoverflow; /* fragments that exceeded limit */ + u_int64_t ip6s_forward; /* packets forwarded */ + u_int64_t ip6s_cantforward; /* packets rcvd for unreachable dest */ + u_int64_t ip6s_redirectsent; /* packets forwarded on same net */ + u_int64_t ip6s_delivered; /* datagrams delivered to upper level*/ + u_int64_t ip6s_localout; /* total ip packets generated here */ + u_int64_t ip6s_odropped; /* lost output due to nobufs, etc. */ + u_int64_t ip6s_reassembled; /* total packets reassembled ok */ + u_int64_t ip6s_fragmented; /* datagrams successfully fragmented */ + u_int64_t ip6s_ofragments; /* output fragments created */ + u_int64_t ip6s_cantfrag; /* don't fragment flag was set, etc. */ + u_int64_t ip6s_badoptions; /* error in option processing */ + u_int64_t ip6s_noroute; /* packets discarded due to no route */ + u_int64_t ip6s_badvers; /* ip6 version != 6 */ + u_int64_t ip6s_rawout; /* total raw ip packets generated */ + u_int64_t ip6s_badscope; /* scope error */ + u_int64_t ip6s_notmember; /* don't join this multicast group */ + u_int64_t ip6s_nxthist[256]; /* next header history */ + u_int64_t ip6s_m1; /* one mbuf */ + u_int64_t ip6s_m2m[32]; /* two or more mbuf */ + u_int64_t ip6s_mext1; /* one ext mbuf */ + u_int64_t ip6s_mext2m; /* two or more ext mbuf */ + u_int64_t ip6s_nogif; /* no match gif found */ + u_int64_t ip6s_toomanyhdr; /* discarded due to too many headers */ + + /* + * statistics for improvement of the source address selection + * algorithm: + * XXX: hardcoded 16 = # of ip6 multicast scope types + 1 + */ + /* number of times that address selection fails */ + u_int64_t ip6s_sources_none; + /* number of times that an address on the outgoing I/F is chosen */ + u_int64_t ip6s_sources_sameif[16]; + /* number of times that an address on a non-outgoing I/F is chosen */ + u_int64_t ip6s_sources_otherif[16]; + /* + * number of times that an address that has the same scope + * from the destination is chosen. + */ + u_int64_t ip6s_sources_samescope[16]; + /* + * number of times that an address that has a different scope + * from the destination is chosen. + */ + u_int64_t ip6s_sources_otherscope[16]; + /* number of times that an deprecated address is chosen */ + u_int64_t ip6s_sources_deprecated[16]; + + u_int64_t ip6s_rtcachehit; /* valid route found in cache */ + u_int64_t ip6s_rtcachemiss; /* route cache with new destination */ + u_int64_t ip6s_wrongif; /* packet received on wrong interface */ + u_int64_t ip6s_idropped; /* lost input due to nobufs, etc. */ +}; + +#ifdef _KERNEL + +/* + * IP6 reassembly queue structure. Each fragment + * being reassembled is attached to one of these structures. + */ +struct ip6q { + TAILQ_ENTRY(ip6q) ip6q_queue; + LIST_HEAD(ip6asfrag_list, ip6asfrag) ip6q_asfrag; + struct in6_addr ip6q_src, ip6q_dst; + int ip6q_unfrglen; /* len of unfragmentable part */ + int ip6q_nfrag; /* # of fragments */ + u_int32_t ip6q_ident; /* fragment identification */ + u_int8_t ip6q_nxt; /* ip6f_nxt in first fragment */ + u_int8_t ip6q_ecn; + u_int8_t ip6q_ttl; /* time to live in slowtimo units */ +}; + +struct ip6asfrag { + LIST_ENTRY(ip6asfrag) ip6af_list; + struct mbuf *ip6af_m; + int ip6af_offset; /* offset in ip6af_m to next header */ + int ip6af_frglen; /* fragmentable part length */ + int ip6af_off; /* fragment offset */ + u_int16_t ip6af_mff; /* more fragment bit in frag off */ +}; + +struct ip6_moptions { + LIST_HEAD(, in6_multi_mship) im6o_memberships; + unsigned short im6o_ifidx; /* ifp index for outgoing multicasts */ + u_char im6o_hlim; /* hoplimit for outgoing multicasts */ + u_char im6o_loop; /* 1 >= hear sends if a member */ +}; + +/* + * Control options for outgoing packets + */ + +/* Routing header related info */ +struct ip6po_rhinfo { + struct ip6_rthdr *ip6po_rhi_rthdr; /* Routing header */ + struct route ip6po_rhi_route; /* Route to the 1st hop */ +}; +#define ip6po_rthdr ip6po_rhinfo.ip6po_rhi_rthdr +#define ip6po_route ip6po_rhinfo.ip6po_rhi_route + +struct ip6_pktopts { + /* Hoplimit for outgoing packets */ + int ip6po_hlim; + + /* Outgoing IF/address information */ + struct in6_pktinfo *ip6po_pktinfo; + + /* Hop-by-Hop options header */ + struct ip6_hbh *ip6po_hbh; + + /* Destination options header (before a routing header) */ + struct ip6_dest *ip6po_dest1; + + /* Routing header related info. */ + struct ip6po_rhinfo ip6po_rhinfo; + + /* Destination options header (after a routing header) */ + struct ip6_dest *ip6po_dest2; + + /* traffic class */ + int ip6po_tclass; + + /* fragment vs PMTU discovery policy */ + int ip6po_minmtu; +#define IP6PO_MINMTU_MCASTONLY -1 /* default: send at min MTU for multicast */ +#define IP6PO_MINMTU_DISABLE 0 /* always perform pmtu disc */ +#define IP6PO_MINMTU_ALL 1 /* always send at min MTU */ + + int ip6po_flags; +#define IP6PO_DONTFRAG 0x04 /* disable fragmentation (IPV6_DONTFRAG) */ +}; + +#include + +enum ip6stat_counters { + ip6s_total, + ip6s_tooshort, + ip6s_toosmall, + ip6s_fragments, + ip6s_fragdropped, + ip6s_fragtimeout, + ip6s_fragoverflow, + ip6s_forward, + ip6s_cantforward, + ip6s_redirectsent, + ip6s_delivered, + ip6s_localout, + ip6s_odropped, + ip6s_reassembled, + ip6s_fragmented, + ip6s_ofragments, + ip6s_cantfrag, + ip6s_badoptions, + ip6s_noroute, + ip6s_badvers, + ip6s_rawout, + ip6s_badscope, + ip6s_notmember, + ip6s_nxthist, + ip6s_m1 = ip6s_nxthist + 256, + ip6s_m2m, + ip6s_mext1 = ip6s_m2m + 32, + ip6s_mext2m, + ip6s_nogif, + ip6s_toomanyhdr, + ip6s_sources_none, + ip6s_sources_sameif, + ip6s_sources_otherif = ip6s_sources_sameif + 16, + ip6s_sources_samescope = ip6s_sources_otherif + 16, + ip6s_sources_otherscope = ip6s_sources_samescope + 16, + ip6s_sources_deprecated = ip6s_sources_otherscope + 16, + ip6s_rtcachehit = ip6s_sources_deprecated + 16, + ip6s_rtcachemiss, + ip6s_wrongif, + ip6s_idropped, + + ip6s_ncounters, +}; + +extern struct cpumem *ip6counters; + +static inline void +ip6stat_inc(enum ip6stat_counters c) +{ + counters_inc(ip6counters, c); +} + +static inline void +ip6stat_add(enum ip6stat_counters c, uint64_t v) +{ + counters_add(ip6counters, c, v); +} + +/* flags passed to ip6_output or ip6_forward as last parameter */ +#define IPV6_UNSPECSRC 0x01 /* allow :: as the source address */ +#define IPV6_FORWARDING 0x02 /* most of IPv6 header exists */ +#define IPV6_MINMTU 0x04 /* use minimum MTU (IPV6_USE_MIN_MTU) */ +#define IPV6_REDIRECT 0x08 /* redirected by pf */ +#define IPV6_FORWARDING_IPSEC 0x10 /* only packets processed by IPsec */ + +extern int ip6_mtudisc_timeout; /* mtu discovery */ +extern struct rttimer_queue icmp6_mtudisc_timeout_q; + +extern int ip6_defhlim; /* default hop limit */ +extern int ip6_defmcasthlim; /* default multicast hop limit */ +extern int ip6_forwarding; /* act as router? */ +extern int ip6_mforwarding; /* act as multicast router? */ +extern int ip6_multipath; /* use multipath routes */ +extern int ip6_sendredirect; /* send ICMPv6 redirect? */ +extern int ip6_mcast_pmtu; /* path MTU discovery for multicast */ +extern int ip6_neighborgcthresh; /* Threshold # of NDP entries for GC */ +extern int ip6_maxdynroutes; /* Max # of routes created via redirect */ + +extern struct socket *ip6_mrouter[RT_TABLEID_MAX + 1]; /* multicast routing daemon */ +extern int ip6_sendredirects; /* send IP redirects when forwarding? */ +extern int ip6_maxfragpackets; /* Maximum packets in reassembly queue */ +extern int ip6_maxfrags; /* Maximum fragments in reassembly queue */ +extern int ip6_hdrnestlimit; /* upper limit of # of extension headers */ +extern int ip6_dad_count; /* DupAddrDetectionTransmits */ +extern int ip6_dad_pending; /* number of currently running DADs */ + +extern const struct pr_usrreqs rip6_usrreqs; + +struct inpcb; +struct ipsec_level; + +int icmp6_ctloutput(int, struct socket *, int, int, struct mbuf *); + +void ip6_init(void); +void ip6intr(void); +int ip6_input_if(struct mbuf **, int *, int, int, struct ifnet *, + struct netstack *); +int ip6_ours_enqueue(struct mbuf **, int *, int); +void ip6_freepcbopts(struct ip6_pktopts *); +void ip6_freemoptions(struct ip6_moptions *); +int ip6_unknown_opt(struct mbuf **, u_int8_t *, int); +int ip6_get_prevhdr(struct mbuf *, int); +int ip6_nexthdr(struct mbuf *, int, int, int *); +int ip6_lasthdr(struct mbuf *, int, int, int *); +int ip6_mforward(struct ip6_hdr *, struct ifnet *, struct mbuf *, int); +int ip6_process_hopopts(struct mbuf **, u_int8_t *, int, u_int32_t *, + u_int32_t *); +void ip6_savecontrol(struct inpcb *, struct mbuf *, struct mbuf **); +int ip6_sysctl(int *, u_int, void *, size_t *, void *, size_t); + +void ip6_forward(struct mbuf *, struct route *, int); + +void ip6_mloopback(struct ifnet *, struct mbuf *, struct sockaddr_in6 *); +int ip6_output(struct mbuf *, struct ip6_pktopts *, struct route *, int, + struct ip6_moptions *, const struct ipsec_level *); +int ip6_fragment(struct mbuf *, struct mbuf_list *, int, u_char, u_long); +int ip6_ctloutput(int, struct socket *, int, int, struct mbuf *); +int ip6_raw_ctloutput(int, struct socket *, int, int, struct mbuf *); +void ip6_initpktopts(struct ip6_pktopts *); +int ip6_setpktopts(struct mbuf *, struct ip6_pktopts *, + struct ip6_pktopts *, int, int); +void ip6_clearpktopts(struct ip6_pktopts *, int); +void ip6_randomid_init(void); +u_int32_t ip6_randomid(void); +void ip6_send(struct mbuf *); + +int route6_input(struct mbuf **, int *, int, int, struct netstack *); + +void frag6_init(void); +int frag6_input(struct mbuf **, int *, int, int, struct netstack *); +int frag6_deletefraghdr(struct mbuf *, int); +void frag6_slowtimo(void); + +void rip6_init(void); +int rip6_input(struct mbuf **, int *, int, int, struct netstack *); +void rip6_ctlinput(int, struct sockaddr *, u_int, void *); +int rip6_ctloutput(int, struct socket *, int, int, struct mbuf *); +int rip6_output(struct mbuf *, struct socket *, struct sockaddr *, + struct mbuf *); +int rip6_attach(struct socket *, int, int); +int rip6_detach(struct socket *); +int rip6_bind(struct socket *, struct mbuf *, struct proc *); +int rip6_connect(struct socket *, struct mbuf *); +int rip6_disconnect(struct socket *); +int rip6_shutdown(struct socket *); +int rip6_send(struct socket *, struct mbuf *, struct mbuf *, + struct mbuf *); +int rip6_sysctl(int *, u_int, void *, size_t *, void *, size_t); + +int dest6_input(struct mbuf **, int *, int, int, struct netstack *); + +int in6_pcbselsrc(const struct in6_addr **, const struct sockaddr_in6 *, + struct inpcb *, struct ip6_pktopts *); +int in6_selectsrc(const struct in6_addr **, const struct sockaddr_in6 *, + struct ip6_moptions *, unsigned int); +struct rtentry *in6_selectroute(const struct in6_addr *, struct ip6_pktopts *, + struct route *, unsigned int rtableid); + +u_int32_t ip6_randomflowlabel(void); + +#ifdef IPSEC +struct tdb; +int ip6_output_ipsec_lookup(struct mbuf *, const struct ipsec_level *, + struct tdb **); +int ip6_output_ipsec_send(struct tdb *, struct mbuf *, struct route *, + u_int, int, int); +#endif /* IPSEC */ + +#endif /* _KERNEL */ + +#endif /* !_NETINET6_IP6_VAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet6/ip6protosw.h b/lib/libc/include/generic-openbsd/netinet6/ip6protosw.h new file mode 100644 index 0000000000..1d1c3df72e --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet6/ip6protosw.h @@ -0,0 +1,112 @@ +/* $OpenBSD: ip6protosw.h,v 1.16 2022/02/22 01:02:57 guenther Exp $ */ +/* $KAME: ip6protosw.h,v 1.22 2001/02/08 18:02:08 itojun Exp $ */ + +/* + * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. + * 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 project 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 PROJECT 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 PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +/*- + * Copyright (c) 1982, 1986, 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. + * + * @(#)protosw.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _NETINET6_IP6PROTOSW_H_ +#define _NETINET6_IP6PROTOSW_H_ + +/* + * Protocol switch table for IPv6. + * All other definitions should refer to sys/protosw.h + */ + +struct mbuf; +struct sockaddr; +struct socket; +struct domain; +struct proc; +struct ip6_hdr; +struct icmp6_hdr; +struct in6_addr; + +/* + * argument type for the last arg of pr_ctlinput(). + * should be consulted only with AF_INET6 family. + * + * IPv6 ICMP IPv6 [exthdrs] finalhdr payload + * ^ ^ ^ ^ + * | | ip6c_ip6 ip6c_off + * | ip6c_icmp6 + * ip6c_m + * + * ip6c_finaldst usually points to ip6c_ip6->ip6_dst. if the original + * (internal) packet carries a routing header, it may point the final + * destination address in the routing header. + * + * ip6c_src: ip6c_ip6->ip6_src + scope info + flowlabel in ip6c_ip6 + * (beware of flowlabel, if you try to compare it against others) + * ip6c_dst: ip6c_finaldst + scope info + */ +struct ip6ctlparam { + struct mbuf *ip6c_m; /* start of mbuf chain */ + struct icmp6_hdr *ip6c_icmp6; /* icmp6 header of target packet */ + struct ip6_hdr *ip6c_ip6; /* ip6 header of target packet */ + int ip6c_off; /* offset of the target proto header */ + struct sockaddr_in6 *ip6c_src; /* srcaddr w/ additional info */ + struct sockaddr_in6 *ip6c_dst; /* (final) dstaddr w/ additional info */ + struct in6_addr *ip6c_finaldst; /* final destination address */ + void *ip6c_cmdarg; /* control command dependent data */ + u_int8_t ip6c_nxt; /* final next header field */ +}; + +#endif /* !_NETINET6_IP6PROTOSW_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet6/mld6.h b/lib/libc/include/generic-openbsd/netinet6/mld6.h new file mode 100644 index 0000000000..594ce8c4f8 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet6/mld6.h @@ -0,0 +1,113 @@ +/* $OpenBSD: mld6.h,v 1.2 2010/03/22 21:29:22 jsg Exp $ */ +/* $FreeBSD: mld6.h,v 1.1 2009/04/29 11:31:23 bms Exp $ */ +/*- + * Copyright (c) 2009 Bruce Simpson. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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 _NETINET6_MLD6_H_ +#define _NETINET6_MLD6_H_ + +/* + * Multicast Listener Discovery (MLD) definitions. + */ + +/* Minimum length of any MLD protocol message. */ +#define MLD_MINLEN sizeof(struct icmp6_hdr) + +/* + * MLD v2 query format. + * See for struct mld_hdr + * (MLDv1 query and host report format). + */ +struct mldv2_query { + struct icmp6_hdr mld_icmp6_hdr; /* ICMPv6 header */ + struct in6_addr mld_addr; /* address being queried */ + uint8_t mld_misc; /* reserved/suppress/robustness */ + uint8_t mld_qqi; /* querier's query interval */ + uint16_t mld_numsrc; /* number of sources */ + /* followed by 1..numsrc source addresses */ +} __packed; +#define MLD_V2_QUERY_MINLEN sizeof(struct mldv2_query) +#define MLD_MRC_EXP(x) ((ntohs((x)) >> 12) & 0x0007) +#define MLD_MRC_MANT(x) (ntohs((x)) & 0x0fff) +#define MLD_QQIC_EXP(x) (((x) >> 4) & 0x07) +#define MLD_QQIC_MANT(x) ((x) & 0x0f) +#define MLD_QRESV(x) (((x) >> 4) & 0x0f) +#define MLD_SFLAG(x) (((x) >> 3) & 0x01) +#define MLD_QRV(x) ((x) & 0x07) + +/* + * MLDv2 host membership report header. + * mld_type: MLDV2_LISTENER_REPORT + */ +struct mldv2_report { + struct icmp6_hdr mld_icmp6_hdr; + /* followed by 1..numgrps records */ +} __packed; +/* overlaid on struct icmp6_hdr. */ +#define mld_numrecs mld_icmp6_hdr.icmp6_data16[1] + +struct mldv2_record { + uint8_t mr_type; /* record type */ + uint8_t mr_datalen; /* length of auxiliary data */ + uint16_t mr_numsrc; /* number of sources */ + struct in6_addr mr_addr; /* address being reported */ + /* followed by 1..numsrc source addresses */ +} __packed; +#define MLD_V2_REPORT_MAXRECS 65535 + +/* + * MLDv2 report modes. + */ +#define MLD_DO_NOTHING 0 /* don't send a record */ +#define MLD_MODE_IS_INCLUDE 1 /* MODE_IN */ +#define MLD_MODE_IS_EXCLUDE 2 /* MODE_EX */ +#define MLD_CHANGE_TO_INCLUDE_MODE 3 /* TO_IN */ +#define MLD_CHANGE_TO_EXCLUDE_MODE 4 /* TO_EX */ +#define MLD_ALLOW_NEW_SOURCES 5 /* ALLOW_NEW */ +#define MLD_BLOCK_OLD_SOURCES 6 /* BLOCK_OLD */ + +/* + * MLDv2 query types. + */ +#define MLD_V2_GENERAL_QUERY 1 +#define MLD_V2_GROUP_QUERY 2 +#define MLD_V2_GROUP_SOURCE_QUERY 3 + +/* + * Maximum report interval for MLDv1 host membership reports (in seconds) + */ +#define MLD_V1_MAX_RI 10 + +/* + * MLD_TIMER_SCALE denotes that the MLD code field specifies + * time in milliseconds. + */ +#define MLD_TIMER_SCALE 1000 + +#endif /* _NETINET6_MLD6_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet6/mld6_var.h b/lib/libc/include/generic-openbsd/netinet6/mld6_var.h new file mode 100644 index 0000000000..cd4feef7b3 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet6/mld6_var.h @@ -0,0 +1,53 @@ +/* $OpenBSD: mld6_var.h,v 1.6 2008/04/18 06:42:20 djm Exp $ */ +/* $KAME: mld6_var.h,v 1.4 2000/03/25 07:23:54 sumikawa Exp $ */ + +/* + * Copyright (C) 1998 WIDE Project. + * 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 project 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 PROJECT 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 PROJECT 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 _NETINET6_MLD6_VAR_H_ +#define _NETINET6_MLD6_VAR_H_ + +#ifdef _KERNEL + +#define MLD_RANDOM_DELAY(X) (arc4random_uniform(X) + 1) + +/* + * States for MLD stop-listening processing + */ +#define MLD_OTHERLISTENER 0 +#define MLD_IREPORTEDLAST 1 + +void mld6_init(void); +void mld6_input(struct mbuf *, int); +void mld6_start_listening(struct in6_multi *); +void mld6_stop_listening(struct in6_multi *); +void mld6_fasttimeo(void); +#endif /* _KERNEL */ + +#endif /* _NETINET6_MLD6_VAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet6/nd6.h b/lib/libc/include/generic-openbsd/netinet6/nd6.h new file mode 100644 index 0000000000..9a490a9afb --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet6/nd6.h @@ -0,0 +1,159 @@ +/* $OpenBSD: nd6.h,v 1.105 2025/09/16 09:19:43 florian Exp $ */ +/* $KAME: nd6.h,v 1.95 2002/06/08 11:31:06 itojun Exp $ */ + +/* + * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. + * 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 project 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 PROJECT 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 PROJECT 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 _NETINET6_ND6_H_ +#define _NETINET6_ND6_H_ + +#define ND6_LLINFO_PURGE -3 +#define ND6_LLINFO_NOSTATE -2 +#define ND6_LLINFO_INCOMPLETE 0 +#define ND6_LLINFO_REACHABLE 1 +#define ND6_LLINFO_STALE 2 +#define ND6_LLINFO_DELAY 3 +#define ND6_LLINFO_PROBE 4 + +/* + * Locks used to protect struct members in this file: + * I immutable after creation + * K kernel lock + * m nd6 mutex, needed when net lock is shared + * N net lock + */ + +struct nd_ifinfo { + u_int32_t reachable; /* [N] Reachable Time */ + int recalctm; /* [N] BaseReachable recalc timer */ +}; + +struct in6_nbrinfo { + char ifname[IFNAMSIZ]; /* if name, e.g. "en0" */ + struct in6_addr addr; /* IPv6 address of the neighbor */ + time_t expire; /* lifetime for NDP state transition */ + long asked; /* number of queries already sent for addr */ + int isrouter; /* if it acts as a router */ + int state; /* reachability state */ +}; + +struct in6_ndireq { + char ifname[IFNAMSIZ]; + struct nd_ifinfo ndi; +}; + +/* protocol constants */ +#define MAX_RTR_SOLICITATION_DELAY 1 /*1sec*/ +#define RTR_SOLICITATION_INTERVAL 4 /*4sec*/ +#define MAX_RTR_SOLICITATIONS 3 + +#define ND6_INFINITE_LIFETIME 0xffffffff + +#ifdef _KERNEL + +#include + +struct llinfo_nd6 { + TAILQ_ENTRY(llinfo_nd6) ln_list; /* [m] global nd6_list */ + struct rtentry *ln_rt; /* [I] backpointer to rtentry */ + /* keep fields above in sync with struct llinfo_nd6_iterator */ + struct refcnt ln_refcnt; /* entry refereced by list */ + struct mbuf_queue ln_mq; /* hold packets until resolved */ + struct in6_addr ln_saddr6; /* source of prompting packet */ + long ln_asked; /* number of queries already sent for addr */ + short ln_state; /* reachability state */ + short ln_router; /* 2^0: ND6 router bit */ +}; +#define LN_HOLD_QUEUE 10 +#define LN_HOLD_TOTAL 100 + +struct llinfo_nd6_iterator { + TAILQ_ENTRY(llinfo_nd6) ln_list; /* [m] global nd6_list */ + struct rtentry *ln_rt; /* [I] always NULL */ + /* keep fields above in sync with struct llinfo_nd6 */ +}; + +extern unsigned int ln_hold_total; + +#define ND6_LLINFO_PERMANENT(n) ((n)->ln_rt->rt_expire == 0) + +/* node constants */ +#define REACHABLE_TIME 30000 /* msec */ +#define RETRANS_TIMER 1000 /* msec */ +#define MIN_RANDOM_FACTOR 512 /* 1024 * 0.5 */ +#define MAX_RANDOM_FACTOR 1536 /* 1024 * 1.5 */ +#define ND_COMPUTE_RTIME(x) \ + (((MIN_RANDOM_FACTOR * (x >> 10)) + (arc4random() & \ + ((MAX_RANDOM_FACTOR - MIN_RANDOM_FACTOR) * (x >> 10)))) /1000) + +extern int nd6_delay; +extern int nd6_umaxtries; +extern int nd6_mmaxtries; +extern const int nd6_gctimer; + +struct nd_opts { + struct nd_opt_hdr *nd_opts_src_lladdr; + struct nd_opt_hdr *nd_opts_tgt_lladdr; +}; + +void nd6_init(void); +void nd6_ifattach(struct ifnet *); +void nd6_ifdetach(struct ifnet *); +int nd6_is_addr_neighbor(const struct sockaddr_in6 *, struct ifnet *); +int nd6_options(void *, int, struct nd_opts *); +struct rtentry *nd6_lookup(const struct in6_addr *, int, struct ifnet *, + u_int); +void nd6_llinfo_settimer(const struct llinfo_nd6 *, unsigned int); +void nd6_purge(struct ifnet *); +void nd6_rtrequest(struct ifnet *, int, struct rtentry *); +int nd6_ioctl(u_long, caddr_t, struct ifnet *); +void nd6_cache_lladdr(struct ifnet *, const struct in6_addr *, char *, + int, int, int, int); +int nd6_resolve(struct ifnet *, struct rtentry *, struct mbuf *, + struct sockaddr *, u_char *); +int nd6_need_cache(struct ifnet *); + +void nd6_na_input(struct mbuf *, int, int); +void nd6_na_output(struct ifnet *, const struct in6_addr *, + const struct in6_addr *, u_long, int, struct sockaddr *); +void nd6_ns_input(struct mbuf *, int, int); +void nd6_ns_output(struct ifnet *, const struct in6_addr *, + const struct in6_addr *, const struct in6_addr *, int); +caddr_t nd6_ifptomac(struct ifnet *); +void nd6_dad_start(struct ifaddr *); +void nd6_dad_stop(struct ifaddr *); + +void nd6_rtr_cache(struct mbuf *, int, int, int); + +int rt6_flush(struct in6_addr *, struct ifnet *); + +void nd6_expire_timer_update(struct in6_ifaddr *); +#endif /* _KERNEL */ + +#endif /* _NETINET6_ND6_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netinet6/raw_ip6.h b/lib/libc/include/generic-openbsd/netinet6/raw_ip6.h new file mode 100644 index 0000000000..63b525afa2 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netinet6/raw_ip6.h @@ -0,0 +1,86 @@ +/* $OpenBSD: raw_ip6.h,v 1.4 2017/02/09 15:23:35 jca Exp $ */ +/* $KAME: raw_ip6.h,v 1.2 2001/05/27 13:28:35 itojun Exp $ */ + +/* + * Copyright (C) 2001 WIDE Project. + * 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 project 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 PROJECT 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 PROJECT 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 _NETINET6_RAW_IP6_H_ +#define _NETINET6_RAW_IP6_H_ + +/* + * ICMPv6 stat is counted separately. see netinet/icmp6.h + */ +struct rip6stat { + u_int64_t rip6s_ipackets; /* total input packets */ + u_int64_t rip6s_isum; /* input checksum computations */ + u_int64_t rip6s_badsum; /* of above, checksum error */ + u_int64_t rip6s_nosock; /* no matching socket */ + u_int64_t rip6s_nosockmcast; /* of above, arrived as multicast */ + u_int64_t rip6s_fullsock; /* not delivered, input socket full */ + + u_int64_t rip6s_opackets; /* total output packets */ +}; + +/* + * Names for RIP6 sysctl objects + */ +#define RIPV6CTL_STATS 1 /* RIP6 stats */ +#define RIPV6CTL_MAXID 2 + +#define RIPM6CTL_NAMES { \ + { 0, 0 }, \ + { "stats", CTLTYPE_NODE }, \ +} + +#ifdef _KERNEL + +#include + +enum rip6stat_counters { + rip6s_ipackets, + rip6s_isum, + rip6s_badsum, + rip6s_nosock, + rip6s_nosockmcast, + rip6s_fullsock, + rip6s_opackets, + rip6s_ncounters, +}; + +extern struct cpumem *rip6counters; + +static inline void +rip6stat_inc(enum rip6stat_counters c) +{ + counters_inc(rip6counters, c); +} + +#endif + +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/netmpls/mpls.h b/lib/libc/include/generic-openbsd/netmpls/mpls.h new file mode 100644 index 0000000000..cd8a128664 --- /dev/null +++ b/lib/libc/include/generic-openbsd/netmpls/mpls.h @@ -0,0 +1,166 @@ +/* $OpenBSD: mpls.h,v 1.47 2025/03/02 21:28:32 bluhm Exp $ */ + +/* + * Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project. + * 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 project 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 PROJECT AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULARPURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, ORCONSEQUENTIAL + * 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 _NETMPLS_MPLS_H_ +#define _NETMPLS_MPLS_H_ + +/* + * Structure of a SHIM header. + */ +#define MPLS_LABEL_MAX ((1 << 20) - 1) + +struct shim_hdr { + u_int32_t shim_label; /* 20 bit label, 4 bit exp & BoS, 8 bit TTL */ +}; + +#define MPLS_HDRLEN sizeof(struct shim_hdr) + +/* + * By byte-swapping the constants, we avoid ever having to byte-swap IP + * addresses inside the kernel. Unfortunately, user-level programs rely + * on these macros not doing byte-swapping. + */ + +#ifdef _KERNEL +#define __MADDR(x) ((u_int32_t)htonl((u_int32_t)(x))) +#else +#define __MADDR(x) ((u_int32_t)(x)) +#endif + +#define MPLS_LABEL_MASK __MADDR(0xfffff000U) +#define MPLS_LABEL_OFFSET 12 +#define MPLS_EXP_MASK __MADDR(0x00000e00U) +#define MPLS_EXP_OFFSET 9 +#define MPLS_BOS_MASK __MADDR(0x00000100U) +#define MPLS_BOS_OFFSET 8 +#define MPLS_TTL_MASK __MADDR(0x000000ffU) + +#define CW_ZERO_MASK __MADDR(0xf0000000U) +#define CW_FRAG_MASK __MADDR(0x00300000U) + +#define MPLS_BOS_ISSET(l) (((l) & MPLS_BOS_MASK) == MPLS_BOS_MASK) + +/* Reserved label values (RFC3032) */ +#define MPLS_LABEL_IPV4NULL 0 /* IPv4 Explicit NULL Label */ +#define MPLS_LABEL_RTALERT 1 /* Router Alert Label */ +#define MPLS_LABEL_IPV6NULL 2 /* IPv6 Explicit NULL Label */ +#define MPLS_LABEL_IMPLNULL 3 /* Implicit NULL Label */ +/* MPLS_LABEL_RESERVED 4-15 */ /* Values 4-15 are reserved */ +#define MPLS_LABEL_RESERVED_MAX 15 + +/* + * Socket address + */ + +struct sockaddr_mpls { + u_int8_t smpls_len; /* length */ + u_int8_t smpls_family; /* AF_MPLS */ + u_int16_t smpls_pad0; + u_int32_t smpls_label; /* MPLS label */ + u_int32_t smpls_pad1[2]; +}; + +struct rt_mpls { + u_int32_t mpls_label; + u_int8_t mpls_operation; + u_int8_t mpls_exp; +}; + +#define MPLS_OP_LOCAL 0x0 +#define MPLS_OP_POP 0x1 +#define MPLS_OP_PUSH 0x2 +#define MPLS_OP_SWAP 0x4 + +#define MPLS_INKERNEL_LOOP_MAX 16 + +#define satosmpls(sa) ((struct sockaddr_mpls *)(sa)) +#define smplstosa(smpls) ((struct sockaddr *)(smpls)) + +/* + * Names for MPLS sysctl objects + */ +#define MPLSCTL_ENABLE 1 +#define MPLSCTL_DEFTTL 2 +#define MPLSCTL_MAPTTL_IP 5 +#define MPLSCTL_MAPTTL_IP6 6 +#define MPLSCTL_MAXID 7 + +#define MPLSCTL_NAMES { \ + { NULL, 0 }, \ + { NULL, 0 }, \ + { "ttl", CTLTYPE_INT }, \ + { "ifq", CTLTYPE_NODE },\ + { NULL, 0 }, \ + { "mapttl_ip", CTLTYPE_INT }, \ + { "mapttl_ip6", CTLTYPE_INT } \ +} + +#define IMR_TYPE_NONE 0 +#define IMR_TYPE_ETHERNET 1 +#define IMR_TYPE_ETHERNET_TAGGED 2 + +#define IMR_FLAG_CONTROLWORD 0x1 + +struct ifmpwreq { + uint32_t imr_flags; + uint32_t imr_type; /* pseudowire type */ + struct shim_hdr imr_lshim; /* local label */ + struct shim_hdr imr_rshim; /* remote label */ + struct sockaddr_storage imr_nexthop; +}; + +#endif + +#ifdef _KERNEL + +#define MPLS_LABEL2SHIM(_l) (htonl((_l) << MPLS_LABEL_OFFSET)) +#define MPLS_SHIM2LABEL(_s) (ntohl((_s)) >> MPLS_LABEL_OFFSET) + +extern int mpls_defttl; +extern int mpls_mapttl_ip; +extern int mpls_mapttl_ip6; + + +struct mbuf *mpls_shim_pop(struct mbuf *); +struct mbuf *mpls_shim_swap(struct mbuf *, struct rt_mpls *); +struct mbuf *mpls_shim_push(struct mbuf *, struct rt_mpls *); + +struct mbuf *mpls_ip_adjttl(struct mbuf *, u_int8_t); +#ifdef INET6 +struct mbuf *mpls_ip6_adjttl(struct mbuf *, u_int8_t); +#endif + +int mpls_output(struct ifnet *, struct mbuf *, struct sockaddr *, + struct rtentry *); +void mpls_input(struct ifnet *, struct mbuf *, struct netstack *); + +#endif /* _KERNEL */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/nfs/krpc.h b/lib/libc/include/generic-openbsd/nfs/krpc.h new file mode 100644 index 0000000000..43f50ecf8c --- /dev/null +++ b/lib/libc/include/generic-openbsd/nfs/krpc.h @@ -0,0 +1,28 @@ +/* $OpenBSD: krpc.h,v 1.7 2012/12/05 23:20:23 deraadt Exp $ */ +/* $NetBSD: krpc.h,v 1.4 1995/12/19 23:07:11 cgd Exp $ */ + +int krpc_call(struct sockaddr_in *, u_int, u_int, u_int, struct mbuf **, + struct mbuf **, int); +int krpc_portmap(struct sockaddr_in *, u_int, u_int, u_int16_t *); + +struct mbuf *xdr_string_encode(char *, int); +struct mbuf *xdr_string_decode(struct mbuf *, char *, int *); +struct mbuf *xdr_inaddr_encode(struct in_addr *); +struct mbuf *xdr_inaddr_decode(struct mbuf *, struct in_addr *); + +/* RPC definitions for the portmapper. */ +#define PMAPPORT 111 +#define PMAPPROG 100000 +#define PMAPVERS 2 +#define PMAPPROC_NULL 0 +#define PMAPPROC_SET 1 +#define PMAPPROC_UNSET 2 +#define PMAPPROC_GETPORT 3 +#define PMAPPROC_DUMP 4 +#define PMAPPROC_CALLIT 5 + +/* RPC definitions for bootparamd. */ +#define BOOTPARAM_PROG 100026 +#define BOOTPARAM_VERS 1 +#define BOOTPARAM_WHOAMI 1 +#define BOOTPARAM_GETFILE 2 \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/nfs/nfs.h b/lib/libc/include/generic-openbsd/nfs/nfs.h new file mode 100644 index 0000000000..3d47b496ca --- /dev/null +++ b/lib/libc/include/generic-openbsd/nfs/nfs.h @@ -0,0 +1,317 @@ +/* $OpenBSD: nfs.h,v 1.54 2024/05/04 10:53:37 jsg Exp $ */ +/* $NetBSD: nfs.h,v 1.10.4.1 1996/05/27 11:23:56 fvdl Exp $ */ + +/* + * Copyright (c) 1989, 1993, 1995 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Rick Macklem at The University of Guelph. + * + * 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. + * + * @(#)nfs.h 8.4 (Berkeley) 5/1/95 + */ + +#ifndef _NFS_NFS_H_ +#define _NFS_NFS_H_ + +#define NFS_TICKINTVL 5 /* Desired time for a tick (msec) */ +#define NFS_HZ (hz / nfs_ticks) /* Ticks/sec */ +#define NFS_TIMEO (1 * NFS_HZ) /* Default timeout = 1 second */ +#define NFS_MINTIMEO (1 * NFS_HZ) /* Min timeout to use */ +#define NFS_MAXTIMEO (60 * NFS_HZ) /* Max timeout to backoff to */ +#define NFS_TIMEOUTMUL 2 /* Timeout/Delay multiplier */ +#define NFS_MAXREXMIT 100 /* Stop counting after this many */ +#define NFS_RETRANS 10 /* Num of retrans for soft mounts */ +#define NFS_MAXGRPS 16 /* Max. size of groups list */ +#define NFS_MINATTRTIMO 5 /* Attribute cache timeout in sec */ +#define NFS_MAXATTRTIMO 60 +#define NFS_WSIZE 8192 /* Def. write data size <= 8192 */ +#define NFS_RSIZE 8192 /* Def. read data size <= 8192 */ +#define NFS_READDIRSIZE 8192 /* Def. readdir size */ +#define NFS_DEFRAHEAD 1 /* Def. read ahead # blocks */ +#define NFS_MAXRAHEAD 4 /* Max. read ahead # blocks */ +#define NFS_MAXASYNCDAEMON 20 /* Max. number async_daemons runable */ + +/* + * Ideally, NFS_DIRBLKSIZ should be bigger, but I've seen servers with + * broken NFS/ethernet drivers that won't work with anything bigger (Linux..) + */ +#define NFS_DIRBLKSIZ 1024 /* Must be a multiple of DIRBLKSIZ */ +#define NFS_READDIRBLKSIZ 512 /* Size of read dir blocks. XXX */ + +/* + * Oddballs + */ +#define NFS_CMPFH(n, f, s) \ + ((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s))) +#define NFS_ISV3(v) (VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3) +#define NFS_SRVMAXDATA(n) \ + (((n)->nd_flag & ND_NFSV3) ? (((n)->nd_nam2) ? \ + NFS_MAXDGRAMDATA : NFS_MAXDATA) : NFS_V2MAXDATA) + +/* + * The B_INVAFTERWRITE flag should be set to whatever is required by the + * buffer cache code to say "Invalidate the block after it is written back". + */ +#define B_INVAFTERWRITE B_INVAL + +/* + * Structures for the nfssvc(2) syscall. + * Not that anyone besides nfsd(8) should ever use it. + */ +struct nfsd_args { + int sock; /* Socket to serve */ + caddr_t name; /* Client addr for connection based sockets */ + int namelen; /* Length of name */ +}; + +struct nfsd_srvargs { + struct nfsd *nsd_nfsd; /* Pointer to in kernel nfsd struct */ + uid_t nsd_uid; /* Effective uid mapped to cred */ + u_int32_t nsd_haddr; /* IP address of client */ + struct xucred nsd_cr; /* Cred. uid maps to */ + int nsd_authlen; /* Length of auth string (ret) */ + u_char *nsd_authstr; /* Auth string (ret) */ + int nsd_verflen; /* and the verifier */ + u_char *nsd_verfstr; + struct timeval nsd_timestamp; /* timestamp from verifier */ + u_int32_t nsd_ttl; /* credential ttl (sec) */ +}; + +/* + * Stats structure + */ +struct nfsstats { + uint64_t attrcache_hits; + uint64_t attrcache_misses; + uint64_t lookupcache_hits; + uint64_t lookupcache_misses; + uint64_t direofcache_hits; + uint64_t direofcache_misses; + uint64_t biocache_reads; + uint64_t read_bios; + uint64_t read_physios; + uint64_t biocache_writes; + uint64_t write_bios; + uint64_t write_physios; + uint64_t biocache_readlinks; + uint64_t readlink_bios; + uint64_t biocache_readdirs; + uint64_t readdir_bios; + uint64_t rpccnt[NFS_NPROCS]; + uint64_t rpcretries; + uint64_t srvrpccnt[NFS_NPROCS]; + uint64_t srvrpc_errs; + uint64_t srv_errs; + uint64_t rpcrequests; + uint64_t rpctimeouts; + uint64_t rpcunexpected; + uint64_t rpcinvalid; + uint64_t srvcache_inproghits; + uint64_t srvcache_idemdonehits; + uint64_t srvcache_nonidemdonehits; + uint64_t srvcache_misses; + uint64_t forcedsync; + uint64_t srvnqnfs_leases; + uint64_t srvnqnfs_maxleases; + uint64_t srvnqnfs_getleases; + uint64_t srvvop_writes; +}; + +/* + * Flags for nfssvc() system call. + */ +#define NFSSVC_NFSD 0x004 +#define NFSSVC_ADDSOCK 0x008 + +/* + * fs.nfs sysctl(3) identifiers + */ +#define NFS_NFSSTATS 1 /* struct: struct nfsstats */ +#define NFS_NIOTHREADS 2 /* number of i/o threads */ +#define NFS_MAXID 3 + +#define FS_NFS_NAMES { \ + { 0, 0 }, \ + { "nfsstats", CTLTYPE_STRUCT }, \ + { "iothreads", CTLTYPE_INT } \ +} + +/* + * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts. + * What should be in this set is open to debate, but I believe that since + * I/O system calls on ufs are never interrupted by signals the set should + * be minimal. My reasoning is that many current programs that use signals + * such as SIGALRM will not expect file I/O system calls to be interrupted + * by them and break. + */ +#ifdef _KERNEL +extern int nfs_niothreads; + +struct uio; struct buf; struct vattr; struct nameidata; /* XXX */ + +#define NFSINT_SIGMASK (sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \ + sigmask(SIGHUP)|sigmask(SIGQUIT)) + +/* + * Socket errors ignored for connectionless sockets?? + * For now, ignore them all + */ +#define NFSIGNORE_SOERROR(s, e) \ + ((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \ + ((s) & PR_CONNREQUIRED) == 0) + +/* + * Nfs outstanding request list element + */ +struct nfsreq { + TAILQ_ENTRY(nfsreq) r_chain; + struct mbuf *r_mreq; + struct mbuf *r_mrep; + struct mbuf *r_md; + caddr_t r_dpos; + struct nfsmount *r_nmp; + struct vnode *r_vp; + u_int32_t r_xid; + int r_flags; /* flags on request, see below */ + int r_rexmit; /* current retrans count */ + int r_timer; /* tick counter on reply */ + int r_procnum; /* NFS procedure number */ + int r_rtt; /* RTT for rpc */ + struct proc *r_procp; /* Proc that did I/O system call */ +}; + +/* Flag values for r_flags */ +#define R_TIMING 0x01 /* timing request (in mntp) */ +#define R_SENT 0x02 /* request has been sent */ +#define R_SOFTTERM 0x04 /* soft mnt, too many retries */ +#define R_INTR 0x08 /* intr mnt, signal pending */ +#define R_SOCKERR 0x10 /* Fatal error on socket */ +#define R_TPRINTFMSG 0x20 /* Did a tprintf msg. */ +#define R_MUSTRESEND 0x40 /* Must resend request */ + +/* + * On fast networks, the estimator will try to reduce the + * timeout lower than the latency of the server's disks, + * which results in too many timeouts, so cap the lower + * bound. + */ +#define NFS_MINRTO (NFS_HZ >> 2) + +/* + * Keep the RTO from increasing to unreasonably large values + * when a server is not responding. + */ +#define NFS_MAXRTO (20 * NFS_HZ) + +enum nfs_rto_timers { + NFS_DEFAULT_TIMER, + NFS_GETATTR_TIMER, + NFS_LOOKUP_TIMER, + NFS_READ_TIMER, + NFS_WRITE_TIMER, +}; +#define NFS_MAX_TIMER (NFS_WRITE_TIMER) + +#define NFS_INITRTT (NFS_HZ << 3) + +/* + * Network address hash list element + */ +union nethostaddr { + u_int32_t had_inetaddr; + struct mbuf *had_nam; +}; + +struct nfssvc_sock { + TAILQ_ENTRY(nfssvc_sock) ns_chain; /* List of all nfssvc_sock's */ + struct file *ns_fp; /* fp from the... */ + struct socket *ns_so; /* ...socket this struct wraps */ + struct mbuf *ns_nam; /* MT_SONAME of client */ + struct mbuf *ns_raw; /* head of unpeeked mbufs */ + struct mbuf *ns_rawend; /* tail of unpeeked mbufs */ + struct mbuf *ns_rec; /* queued RPC records */ + struct mbuf *ns_recend; /* last queued RPC record */ + struct mbuf *ns_frag; /* end of record fragment */ + int ns_flag; /* socket status flags */ + int ns_solock; /* lock for connected socket */ + int ns_cc; /* actual chars queued */ + int ns_reclen; /* length of first queued record */ + u_int32_t ns_sref; /* # of refs to this struct */ +}; + +/* Bits for "ns_flag" */ +#define SLP_VALID 0x01 /* connection is usable */ +#define SLP_DOREC 0x02 /* receive operation required */ +#define SLP_NEEDQ 0x04 /* connection has data to queue from socket */ +#define SLP_DISCONN 0x08 /* connection is closed */ +#define SLP_GETSTREAM 0x10 /* extracting RPC from TCP connection */ +#define SLP_LASTFRAG 0x20 /* last fragment received on TCP connection */ +#define SLP_ALLFLAGS 0xff /* convenience */ + +/* + * One of these structures is allocated for each nfsd. + */ +struct nfsd { + TAILQ_ENTRY(nfsd) nfsd_chain; /* List of all nfsd's */ + int nfsd_flag; /* NFSD_ flags */ + struct nfssvc_sock *nfsd_slp; /* Current socket */ + struct proc *nfsd_procp; /* Proc ptr */ + struct nfsrv_descript *nfsd_nd; /* Associated nfsrv_descript */ +}; + +/* Bits for "nfsd_flag" */ +#define NFSD_WAITING 0x01 +#define NFSD_REQINPROG 0x02 + +/* + * This structure is used by the server for describing each request. + */ +struct nfsrv_descript { + struct mbuf *nd_mrep; /* Request mbuf list */ + struct mbuf *nd_md; /* Current dissect mbuf */ + struct mbuf *nd_nam; /* and socket addr */ + struct mbuf *nd_nam2; /* return socket addr */ + caddr_t nd_dpos; /* Current dissect pos */ + unsigned int nd_procnum; /* RPC # */ + int nd_flag; /* nd_flag */ + int nd_repstat; /* Reply status */ + u_int32_t nd_retxid; /* Reply xid */ + struct ucred nd_cr; /* Credentials */ +}; + +/* Bits for "nd_flag" */ +#define ND_NFSV3 0x08 + +extern struct pool nfsreqpl; +extern struct pool nfs_node_pool; +extern TAILQ_HEAD(nfsdhead, nfsd) nfsd_head; +extern int nfsd_head_flag; +#define NFSD_CHECKSLP 0x01 + +#endif /* _KERNEL */ +#endif /* _NFS_NFS_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/nfs/nfs_var.h b/lib/libc/include/generic-openbsd/nfs/nfs_var.h new file mode 100644 index 0000000000..73c6f8e0cd --- /dev/null +++ b/lib/libc/include/generic-openbsd/nfs/nfs_var.h @@ -0,0 +1,202 @@ +/* $OpenBSD: nfs_var.h,v 1.66 2024/09/09 03:50:14 jsg Exp $ */ +/* $NetBSD: nfs_var.h,v 1.3 1996/02/18 11:53:54 fvdl Exp $ */ + +/* + * Copyright (c) 1996 Christos Zoulas. 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 Christos Zoulas. + * 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. + */ + +/* + * XXX needs and because of typedefs. + */ +#ifndef _NFS_NFS_VAR_H_ +#define _NFS_NFS_VAR_H_ + +#ifdef _KERNEL + +struct nfsnode; +struct sillyrename; +struct componentname; +struct nfs_diskless; +struct nfsm_info; + +/* nfs_bio.c */ +int nfs_bioread(struct vnode *, struct uio *, int, struct ucred *); +int nfs_write(void *); +int nfs_vinvalbuf(struct vnode *, int, struct ucred *, struct proc *); +int nfs_asyncio(struct buf *, int readahead); +int nfs_doio(struct buf *, struct proc *); + +/* nfs_boot.c */ +int nfs_boot_init(struct nfs_diskless *, struct proc *); + +/* nfs_node.c */ +void nfs_ninit(struct nfsmount *); +int nfs_nget(struct mount *, nfsfh_t *, int, struct nfsnode **); +int nfs_inactive(void *); +int nfs_reclaim(void *); + +/* nfs_vnops.c */ +int nfs_readlink(void *); +int nfs_readlinkrpc(struct vnode *, struct uio *, struct ucred *); +int nfs_readrpc(struct vnode *, struct uio *); +int nfs_writerpc(struct vnode *, struct uio *, int *, int *); +int nfs_removeit(struct sillyrename *); +int nfs_writebp(struct buf *, int); + +#define nfs_ioctl ((int (*)(void *))enoioctl) + +/* nfs_serv.c */ +int nfsrv3_access(struct nfsrv_descript *, struct nfssvc_sock *, + struct proc *, struct mbuf **); +int nfsrv_getattr(struct nfsrv_descript *, struct nfssvc_sock *, + struct proc *, struct mbuf **); +int nfsrv_setattr(struct nfsrv_descript *, struct nfssvc_sock *, + struct proc *, struct mbuf **); +int nfsrv_lookup(struct nfsrv_descript *, struct nfssvc_sock *, + struct proc *, struct mbuf **); +int nfsrv_readlink(struct nfsrv_descript *, struct nfssvc_sock *, + struct proc *, struct mbuf **); +int nfsrv_read(struct nfsrv_descript *, struct nfssvc_sock *, + struct proc *, struct mbuf **); +int nfsrv_write(struct nfsrv_descript *, struct nfssvc_sock *, + struct proc *, struct mbuf **); +int nfsrv_create(struct nfsrv_descript *, struct nfssvc_sock *, + struct proc *, struct mbuf **); +int nfsrv_mknod(struct nfsrv_descript *, struct nfssvc_sock *, + struct proc *, struct mbuf **); +int nfsrv_remove(struct nfsrv_descript *, struct nfssvc_sock *, + struct proc *, struct mbuf **); +int nfsrv_rename(struct nfsrv_descript *, struct nfssvc_sock *, + struct proc *, struct mbuf **); +int nfsrv_link(struct nfsrv_descript *, struct nfssvc_sock *, + struct proc *, struct mbuf **); +int nfsrv_symlink(struct nfsrv_descript *, struct nfssvc_sock *, + struct proc *, struct mbuf **); +int nfsrv_mkdir(struct nfsrv_descript *, struct nfssvc_sock *, + struct proc *, struct mbuf **); +int nfsrv_rmdir(struct nfsrv_descript *, struct nfssvc_sock *, + struct proc *, struct mbuf **); +int nfsrv_readdir(struct nfsrv_descript *, struct nfssvc_sock *, + struct proc *, struct mbuf **); +int nfsrv_readdirplus(struct nfsrv_descript *, struct nfssvc_sock *, + struct proc *, struct mbuf **); +int nfsrv_commit(struct nfsrv_descript *, struct nfssvc_sock *, + struct proc *, struct mbuf **); +int nfsrv_statfs(struct nfsrv_descript *, struct nfssvc_sock *, + struct proc *, struct mbuf **); +int nfsrv_fsinfo(struct nfsrv_descript *, struct nfssvc_sock *, + struct proc *, struct mbuf **); +int nfsrv_pathconf(struct nfsrv_descript *, struct nfssvc_sock *, + struct proc *, struct mbuf **); +int nfsrv_null(struct nfsrv_descript *, struct nfssvc_sock *, + struct proc *, struct mbuf **); +int nfsrv_noop(struct nfsrv_descript *, struct nfssvc_sock *, + struct proc *, struct mbuf **); + +/* nfs_socket.c */ +int nfs_connect(struct nfsmount *, struct nfsreq *); +void nfs_disconnect(struct nfsmount *); +int nfs_send(struct socket *, struct mbuf *, struct mbuf *, + struct nfsreq *); +int nfs_request(struct vnode *, int, struct nfsm_info *); +int nfs_rephead(int, struct nfsrv_descript *, struct nfssvc_sock *, int, + struct mbuf **, struct mbuf **); +void nfs_timer(void *); +int nfs_sigintr(struct nfsmount *, struct nfsreq *, struct proc *); +int nfs_sndlock(int *, struct nfsreq *); +void nfs_sndunlock(int *); +void nfsrv_rcv(struct socket *, caddr_t, int); +int nfsrv_dorec(struct nfssvc_sock *, struct nfsd *, + struct nfsrv_descript **); +void nfsrv_wakenfsd(struct nfssvc_sock *); + +/* nfs_srvcache.c */ +void nfsrv_initcache(void ); +int nfsrv_getcache(struct nfsrv_descript *, struct nfssvc_sock *, + struct mbuf **); +void nfsrv_updatecache(struct nfsrv_descript *, int, struct mbuf *); +void nfsrv_cleancache(void); + +/* nfs_srvsubs.c */ +int nfs_namei(struct nameidata *, fhandle_t *, int, struct nfssvc_sock *, + struct mbuf *, struct mbuf **, caddr_t *, struct vnode **, + struct proc *); +void nfsm_adj(struct mbuf *, int, int); +void nfsm_srvwcc(struct nfsrv_descript *, int, struct vattr *, int, + struct vattr *, struct nfsm_info *); +void nfsm_srvpostop_attr(struct nfsrv_descript *, int, struct vattr *, + struct nfsm_info *); +void nfsm_srvfattr(struct nfsrv_descript *, struct vattr *, + struct nfs_fattr *); +int nfsrv_fhtovp(fhandle_t *, int, struct vnode **, struct ucred *, + struct nfssvc_sock *, struct mbuf *, int *); +int netaddr_match(int, union nethostaddr *, struct mbuf *); +int nfsm_srvsattr(struct mbuf **, struct vattr *, struct mbuf *, caddr_t *); + +/* nfs_subs.c */ +struct mbuf *nfsm_reqhead(int); +void nfsm_rpchead(struct nfsreq *, struct ucred *, int); +void *nfsm_build(struct mbuf **, u_int); +int nfsm_mbuftouio(struct mbuf **, struct uio *, int, caddr_t *); +void nfsm_uiotombuf(struct mbuf **, struct uio *, size_t); +void nfsm_strtombuf(struct mbuf **, void *, size_t); +void nfsm_buftombuf(struct mbuf **, void *, size_t); +int nfs_adv(struct mbuf **, caddr_t *, int, int); +int nfs_vfs_init(struct vfsconf *); +int nfs_attrtimeo(struct nfsnode *); +int nfs_loadattrcache(struct vnode **, struct mbuf **, caddr_t *, + struct vattr *); +int nfs_getattrcache(struct vnode *, struct vattr *); +void nfsm_v3attrbuild(struct mbuf **, struct vattr *, int); +int nfsm_disct(struct mbuf **, caddr_t *, int, int, caddr_t *); +void nfs_clearcommit(struct mount *); +int nfs_in_committed_range(struct vnode *, struct buf *); +int nfs_in_tobecommitted_range(struct vnode *, struct buf *); +void nfs_add_committed_range(struct vnode *, struct buf *); +void nfs_del_committed_range(struct vnode *, struct buf *); +void nfs_add_tobecommitted_range(struct vnode *, struct buf *); +void nfs_del_tobecommitted_range(struct vnode *, struct buf *); +void nfs_merge_commit_ranges(struct vnode *); +int nfsrv_errmap(struct nfsrv_descript *, int); +void nfsm_fhtom(struct nfsm_info *, struct vnode *, int); +void nfsm_srvfhtom(struct mbuf **, fhandle_t *, int); + +/* nfs_syscalls.c */ +int sys_nfssvc(struct proc *, void *, register_t *); +void nfsrv_init(int); +void nfs_getset_niothreads(int); + +/* nfs_kq.c */ +int nfs_kqfilter(void *); + +/* Internal NFS utility macros */ +#define mb_offset(m) (mtod((m), caddr_t) + (m)->m_len) +#define nfsm_padlen(s) (nfsm_rndup(s) - (s)) + +#endif /* _KERNEL */ +#endif /* _NFS_NFS_VAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/nfs/nfsdiskless.h b/lib/libc/include/generic-openbsd/nfs/nfsdiskless.h new file mode 100644 index 0000000000..0b9fa1d2db --- /dev/null +++ b/lib/libc/include/generic-openbsd/nfs/nfsdiskless.h @@ -0,0 +1,68 @@ +/* $OpenBSD: nfsdiskless.h,v 1.10 2013/09/20 23:51:44 fgsch Exp $ */ +/* $NetBSD: nfsdiskless.h,v 1.9 1996/02/18 11:54:00 fvdl Exp $ */ + +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Rick Macklem at The University of Guelph. + * + * 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. + * + * @(#)nfsdiskless.h 8.2 (Berkeley) 3/30/95 + */ + +#ifndef _NFS_DISKLESS_H_ +#define _NFS_DISKLESS_H_ + +/* + * Structure that must be initialized for a diskless nfs client. + * This structure is used by nfs_mountroot() to set up the root and swap + * vnodes plus do a partial ifconfig(8) and route(8) so that the critical + * net interface can communicate with the server. + * Whether or not the swap area is nfs mounted is determined + * by the value in swdevt[0]. (equal to NODEV --> swap over nfs) + * Currently only works for AF_INET protocols. + * NB: All fields are stored in net byte order to avoid hassles with + * client/server byte ordering differences. + */ +struct nfs_dlmount { + struct nfs_args ndm_args; + struct sockaddr_in ndm_saddr; /* Address of file server */ + char ndm_host[MNAMELEN]; /* Host name for mount pt */ + u_char ndm_fh[NFSX_V3FHMAX]; /* The file's file handle */ +}; +struct nfs_diskless { + struct sockaddr_in nd_boot; /* Address of boot server */ + struct nfs_dlmount nd_root; /* Mount info for root */ + struct nfs_dlmount nd_swap; /* Mount info for swap */ + struct vnode *sw_vp; +}; + +int nfs_boot_init(struct nfs_diskless *nd, struct proc *procp); +int nfs_boot_getfh(struct sockaddr_in *bpsin, char *key, + struct nfs_dlmount *ndmntp, int retries); +#endif /* _NFS_DISKLESS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/nfs/nfsm_subs.h b/lib/libc/include/generic-openbsd/nfs/nfsm_subs.h new file mode 100644 index 0000000000..d6dcf14622 --- /dev/null +++ b/lib/libc/include/generic-openbsd/nfs/nfsm_subs.h @@ -0,0 +1,185 @@ +/* $OpenBSD: nfsm_subs.h,v 1.49 2024/09/11 12:22:34 claudio Exp $ */ +/* $NetBSD: nfsm_subs.h,v 1.10 1996/03/20 21:59:56 fvdl Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Rick Macklem at The University of Guelph. + * + * 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. + * + * @(#)nfsm_subs.h 8.2 (Berkeley) 3/30/95 + */ + + +#ifndef _NFS_NFSM_SUBS_H_ +#define _NFS_NFSM_SUBS_H_ + +struct nfsm_info { + struct mbuf *nmi_mreq; + struct mbuf *nmi_mrep; + + struct proc *nmi_procp; /* XXX XXX XXX */ + struct ucred *nmi_cred; /* XXX XXX XXX */ + + /* Setting up / Tearing down. */ + struct mbuf *nmi_md; + struct mbuf *nmi_mb; + caddr_t nmi_dpos; + + int nmi_v3; + + int *nmi_errorp; +}; + +static inline void * +nfsm_dissect(struct nfsm_info *infop, int s) +{ + caddr_t ret; + int avail, error; + + avail = mtod(infop->nmi_md, caddr_t) + infop->nmi_md->m_len - + infop->nmi_dpos; + if (avail >= s) { + ret = infop->nmi_dpos; + infop->nmi_dpos += s; + return ret; + } + error = nfsm_disct(&infop->nmi_md, &infop->nmi_dpos, s, avail, &ret); + if (error != 0) { + m_freem(infop->nmi_mrep); + infop->nmi_mrep = NULL; + *infop->nmi_errorp = error; + return NULL; + } else { + return ret; + } +} + +#define nfsm_rndup(a) (((a)+3)&(~0x3)) + +static inline int +nfsm_adv(struct nfsm_info *infop, int s) +{ + int avail, error; + + avail = mtod(infop->nmi_md, caddr_t) + infop->nmi_md->m_len - + infop->nmi_dpos; + if (avail >= s) { + infop->nmi_dpos += s; + return 0; + } + error = nfs_adv(&infop->nmi_md, &infop->nmi_dpos, s, avail); + if (error != 0) { + m_freem(infop->nmi_mrep); + infop->nmi_mrep = NULL; + *infop->nmi_errorp = error; + return error; + } + return 0; +} + +static inline int +nfsm_postop_attr(struct nfsm_info *infop, struct vnode **vpp, int *attrflagp) +{ + uint32_t *tl; + struct vnode *ttvp; + int attrflag, error; + + if (infop->nmi_mrep == NULL) + return 0; + + ttvp = *vpp; + tl = (uint32_t *)nfsm_dissect(infop, NFSX_UNSIGNED); + if (tl == NULL) + return 1; /* anything nonzero */ + attrflag = fxdr_unsigned(int, *tl); + if (attrflag != 0) { + error = nfs_loadattrcache(&ttvp, &infop->nmi_md, + &infop->nmi_dpos, NULL); + if (error != 0) { + m_freem(infop->nmi_mrep); + infop->nmi_mrep = NULL; + *infop->nmi_errorp = error; + return error; + } + *vpp = ttvp; + } + *attrflagp = attrflag; + return 0; +} + +static inline int +nfsm_strsiz(struct nfsm_info *infop, int *lenp, int maxlen) +{ + uint32_t *tl = (uint32_t *)nfsm_dissect(infop, NFSX_UNSIGNED); + int len; + if (tl == NULL) + return 1; + len = fxdr_unsigned(int32_t, *tl); + if (len < 0 || len > maxlen) { + m_freem(infop->nmi_mrep); + infop->nmi_mrep = NULL; + *infop->nmi_errorp = EBADRPC; + return 1; + } + *lenp = len; + return 0; +} + +static inline int +nfsm_mtouio(struct nfsm_info *infop, struct uio *uiop, int len) +{ + int error; + + if (len <= 0) + return 0; + + error = nfsm_mbuftouio(&infop->nmi_md, uiop, len, &infop->nmi_dpos); + if (error != 0) { + m_freem(infop->nmi_mrep); + infop->nmi_mrep = NULL; + *infop->nmi_errorp = error; + return error; + } + return 0; +} + +static inline int +nfsm_strtom(struct nfsm_info *infop, char *str, size_t len, size_t maxlen) +{ + if (len > maxlen) { + m_freem(infop->nmi_mreq); + infop->nmi_mreq = NULL; + *infop->nmi_errorp = ENAMETOOLONG; + return 1; + } + nfsm_strtombuf(&infop->nmi_mb, str, len); + return 0; +} + +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/nfs/nfsmount.h b/lib/libc/include/generic-openbsd/nfs/nfsmount.h new file mode 100644 index 0000000000..94d988971e --- /dev/null +++ b/lib/libc/include/generic-openbsd/nfs/nfsmount.h @@ -0,0 +1,94 @@ +/* $OpenBSD: nfsmount.h,v 1.28 2018/04/09 09:39:53 mpi Exp $ */ +/* $NetBSD: nfsmount.h,v 1.10 1996/02/18 11:54:03 fvdl Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Rick Macklem at The University of Guelph. + * + * 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. + * + * @(#)nfsmount.h 8.3 (Berkeley) 3/30/95 + */ + + +#ifndef _NFS_NFSMOUNT_H_ +#define _NFS_NFSMOUNT_H_ + +/* + * Mount structure. + * One allocated on every NFS mount. + * Holds NFS specific information for mount. + */ +struct nfsmount { + RBT_HEAD(nfs_nodetree, nfsnode) + nm_ntree; /* filehandle/node tree */ + TAILQ_HEAD(reqs, nfsreq) + nm_reqsq; /* request queue for this mount. */ + struct timeout nm_rtimeout; /* timeout (scans/resends nm_reqsq). */ + struct mount *nm_mountp; /* Vfs structure for this filesystem */ + struct vnode *nm_vnode; /* vnode of root dir */ + int nm_flag; /* Flags for soft/hard... */ + int nm_numgrps; /* Max. size of groupslist */ + struct socket *nm_so; /* Rpc socket */ + int nm_sotype; /* Type of socket */ + int nm_soproto; /* and protocol */ + int nm_soflags; /* pr_flags for socket protocol */ + struct mbuf *nm_nam; /* Addr of server */ + int nm_timeo; /* Init timer for NFSMNT_DUMBTIMR */ + int nm_retry; /* Max retries */ + int nm_srtt[NFS_MAX_TIMER]; /* RTT Timers for RPCs */ + int nm_sdrtt[NFS_MAX_TIMER]; + int nm_sent; /* Request send count */ + int nm_cwnd; /* Request send window */ + int nm_timeouts; /* Request timeouts */ + int nm_rsize; /* Max size of read rpc */ + int nm_wsize; /* Max size of write rpc */ + int nm_readdirsize; /* Size of a readdir rpc */ + int nm_readahead; /* Num. of blocks to readahead */ + u_char nm_verf[NFSX_V3WRITEVERF]; /* V3 write verifier */ + u_short nm_acregmin; /* Attr cache file recently modified */ + u_short nm_acregmax; /* ac file not recently modified */ + u_short nm_acdirmin; /* ac for dir recently modified */ + u_short nm_acdirmax; /* ac for dir not recently modified */ +}; + +#ifdef _KERNEL + +/* Convert mount ptr to nfsmount ptr: */ +#define VFSTONFS(mp) ((struct nfsmount *)((mp)->mnt_data)) + +/* Prototypes for NFS mount operations: */ +int nfs_mount(struct mount *, const char *, void *, struct nameidata *, + struct proc *); +int nfs_fsinfo(struct nfsmount *, struct vnode *, struct ucred *, + struct proc *); +void nfs_init(void); + +#endif /* _KERNEL */ + +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/nfs/nfsnode.h b/lib/libc/include/generic-openbsd/nfs/nfsnode.h new file mode 100644 index 0000000000..dbc4ccffb7 --- /dev/null +++ b/lib/libc/include/generic-openbsd/nfs/nfsnode.h @@ -0,0 +1,141 @@ +/* $OpenBSD: nfsnode.h,v 1.44 2025/08/28 18:30:08 claudio Exp $ */ +/* $NetBSD: nfsnode.h,v 1.16 1996/02/18 11:54:04 fvdl Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Rick Macklem at The University of Guelph. + * + * 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. + * + * @(#)nfsnode.h 8.9 (Berkeley) 5/14/95 + */ + + +#ifndef _NFS_NFSNODE_H_ +#define _NFS_NFSNODE_H_ + +#ifndef _NFS_NFS_H_ +#include +#endif + +#include + +/* + * Silly rename structure that hangs off the nfsnode until the name + * can be removed by nfs_inactive() + */ +struct sillyrename { + struct ucred *s_cred; + struct vnode *s_dvp; + long s_namlen; + char s_name[24]; +}; + +/* + * The nfsnode is the nfs equivalent to ufs's inode. Any similarity + * is purely coincidental. + * There is a unique nfsnode allocated for each active file, + * each current directory, each mounted-on file, text file, and the root. + * An nfsnode is 'named' by its file handle. (nget/nfs_node.c) + */ +struct nfsnode { + RBT_ENTRY(nfsnode) n_entry; /* filehandle/node tree. */ + u_quad_t n_size; /* Current size of file */ + struct vattr n_vattr; /* Vnode attribute cache */ + time_t n_attrstamp; /* Attr. cache timestamp */ + struct timespec n_mtime; /* Prev modify time. */ + time_t n_ctime; /* Prev create time. */ + nfsfh_t *n_fhp; /* NFS File Handle */ + struct vnode *n_vnode; /* associated vnode */ + struct lockf_state *n_lockf; /* Locking record of file */ + struct rrwlock n_lock; /* NFSnode lock */ + int n_error; /* Save write error value */ + union { + struct timespec nf_atim; /* Special file times */ + nfsuint64 nd_cookieverf; /* Cookie verifier (dir only) */ + } n_un1; + union { + struct timespec nf_mtim; + off_t nd_direof; /* Dir. EOF offset cache */ + } n_un2; + struct sillyrename *n_sillyrename; /* Ptr to silly rename struct */ + short n_fhsize; /* size in bytes, of fh */ + short n_flag; /* Flag for locking.. */ + nfsfh_t n_fh; /* Small File Handle */ + time_t n_accstamp; /* Access cache timestamp */ + uid_t n_accuid; /* Last access requester */ + int n_accmode; /* Last mode requested */ + int n_accerror; /* Last returned error */ + struct ucred *n_rcred; + struct ucred *n_wcred; + + off_t n_pushedlo; /* 1st blk in committed range */ + off_t n_pushedhi; /* Last block in range */ + off_t n_pushlo; /* 1st block in commit range */ + off_t n_pushhi; /* Last block in range */ + struct rwlock n_commitlock; /* Serialize commits */ + int n_commitflags; +}; + +/* + * Values for n_commitflags + */ +#define NFS_COMMIT_PUSH_VALID 0x0001 /* push range valid */ +#define NFS_COMMIT_PUSHED_VALID 0x0002 /* pushed range valid */ + +#define n_atim n_un1.nf_atim +#define n_mtim n_un2.nf_mtim +#define n_cookieverf n_un1.nd_cookieverf +#define n_direofoffset n_un2.nd_direof + +/* + * Flags for n_flag + */ +#define NFLUSHWANT 0x0001 /* Want wakeup from a flush in prog. */ +#define NFLUSHINPROG 0x0002 /* Avoid multiple calls to vinvalbuf() */ +#define NMODIFIED 0x0004 /* Might have a modified buffer in bio */ +#define NWRITEERR 0x0008 /* Flag write errors so close will know */ +#define NACC 0x0100 /* Special file accessed */ +#define NUPD 0x0200 /* Special file updated */ +#define NCHG 0x0400 /* Special file times changed */ + +#define NFS_INVALIDATE_ATTRCACHE(np) ((np)->n_attrstamp = 0) + +/* + * Convert between nfsnode pointers and vnode pointers + */ +#define VTONFS(vp) ((struct nfsnode *)(vp)->v_data) +#define NFSTOV(np) ((np)->n_vnode) + +/* + * Queue head for nfsiod's + */ +extern TAILQ_HEAD(nfs_bufqhead, buf) nfs_bufq; +extern uint32_t nfs_bufqlen, nfs_bufqmax; + +#endif /* _NFS_NFSNODE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/nfs/nfsproto.h b/lib/libc/include/generic-openbsd/nfs/nfsproto.h new file mode 100644 index 0000000000..04fe7be0f4 --- /dev/null +++ b/lib/libc/include/generic-openbsd/nfs/nfsproto.h @@ -0,0 +1,415 @@ +/* $OpenBSD: nfsproto.h,v 1.11 2024/04/30 17:06:00 miod Exp $ */ +/* $NetBSD: nfsproto.h,v 1.1 1996/02/18 11:54:06 fvdl Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Rick Macklem at The University of Guelph. + * + * 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. + * + * @(#)nfsproto.h 8.2 (Berkeley) 3/30/95 + */ + +#ifndef _NFS_NFSPROTO_H_ +#define _NFS_NFSPROTO_H_ + +/* + * Constants as defined in the Sun NFS Version 2 and 3 specs. + * "NFS: Network File System Protocol Specification" RFC1094 + * and in the "NFS: Network File System Version 3 Protocol + * Specification" + */ + +#define NFS_PORT 2049 +#define NFS_PROG 100003 +#define NFS_VER2 2 +#define NFS_VER3 3 +#define NFS_VER4 4 +#define NFS_V2MAXDATA 8192 +#define NFS_MAXDGRAMDATA 32768 +#define NFS_MAXDATA MAXBSIZE +#define NFS_MAXPATHLEN 1024 +#define NFS_MAXNAMLEN 255 +#define NFS_MAXPKTHDR 404 +#define NFS_MAXPACKET (NFS_MAXPKTHDR + NFS_MAXDATA) +#define NFS_MINPACKET 20 +#define NFS_FABLKSIZE 512 /* Size in bytes of a block wrt fa_blocks */ + +/* Stat numbers for rpc returns (version 2 and 3) */ +#define NFS_OK 0 +#define NFSERR_PERM 1 +#define NFSERR_NOENT 2 +#define NFSERR_IO 5 +#define NFSERR_NXIO 6 +#define NFSERR_ACCES 13 +#define NFSERR_EXIST 17 +#define NFSERR_XDEV 18 /* Version 3 only */ +#define NFSERR_NODEV 19 +#define NFSERR_NOTDIR 20 +#define NFSERR_ISDIR 21 +#define NFSERR_INVAL 22 /* Version 3 only */ +#define NFSERR_FBIG 27 +#define NFSERR_NOSPC 28 +#define NFSERR_ROFS 30 +#define NFSERR_MLINK 31 /* Version 3 only */ +#define NFSERR_NAMETOL 63 +#define NFSERR_NOTEMPTY 66 +#define NFSERR_DQUOT 69 +#define NFSERR_STALE 70 +#define NFSERR_REMOTE 71 /* Version 3 only */ +#define NFSERR_WFLUSH 99 /* Version 2 only */ +#define NFSERR_BADHANDLE 10001 /* The rest Version 3 only */ +#define NFSERR_NOT_SYNC 10002 +#define NFSERR_BAD_COOKIE 10003 +#define NFSERR_NOTSUPP 10004 +#define NFSERR_TOOSMALL 10005 +#define NFSERR_SERVERFAULT 10006 +#define NFSERR_BADTYPE 10007 +#define NFSERR_JUKEBOX 10008 +#define NFSERR_TRYLATER NFSERR_JUKEBOX +#define NFSERR_STALEWRITEVERF 30001 /* Fake return for nfs_commit() */ + +#define NFSERR_RETVOID 0x20000000 /* Return void, not error */ +#define NFSERR_AUTHERR 0x40000000 /* Mark an authentication error */ +#define NFSERR_RETERR 0x80000000 /* Mark an error return for V3 */ + +/* Sizes in bytes of various nfs rpc components */ +#define NFSX_UNSIGNED 4 + +/* specific to NFS Version 2 */ +#define NFSX_V2FH 32 +#define NFSX_V2FATTR 68 +#define NFSX_V2SATTR 32 +#define NFSX_V2COOKIE 4 +#define NFSX_V2STATFS 20 + +/* specific to NFS Version 3 */ +#define NFSX_V3FH (sizeof (fhandle_t)) /* size this server uses */ +#define NFSX_V3FHMAX 64 /* max. allowed by protocol */ +#define NFSX_V3FATTR 84 +#define NFSX_V3SATTR 60 /* max. all fields filled in */ +#define NFSX_V3SRVSATTR (sizeof (struct nfsv3_sattr)) +#define NFSX_V3POSTOPATTR (NFSX_V3FATTR + NFSX_UNSIGNED) +#define NFSX_V3WCCDATA (NFSX_V3POSTOPATTR + 8 * NFSX_UNSIGNED) +#define NFSX_V3COOKIEVERF 8 +#define NFSX_V3WRITEVERF 8 +#define NFSX_V3CREATEVERF 8 +#define NFSX_V3STATFS 52 +#define NFSX_V3FSINFO 48 +#define NFSX_V3PATHCONF 24 + +/* variants for both versions */ +#define NFSX_FH(v3) ((v3) ? (NFSX_V3FHMAX + NFSX_UNSIGNED) : \ + NFSX_V2FH) +#define NFSX_SRVFH(v3) ((v3) ? NFSX_V3FH : NFSX_V2FH) +#define NFSX_FATTR(v3) ((v3) ? NFSX_V3FATTR : NFSX_V2FATTR) +#define NFSX_PREOPATTR(v3) ((v3) ? (7 * NFSX_UNSIGNED) : 0) +#define NFSX_POSTOPATTR(v3) ((v3) ? (NFSX_V3FATTR + NFSX_UNSIGNED) : 0) +#define NFSX_POSTOPORFATTR(v3) ((v3) ? (NFSX_V3FATTR + NFSX_UNSIGNED) : \ + NFSX_V2FATTR) +#define NFSX_WCCDATA(v3) ((v3) ? NFSX_V3WCCDATA : 0) +#define NFSX_WCCORFATTR(v3) ((v3) ? NFSX_V3WCCDATA : NFSX_V2FATTR) +#define NFSX_SATTR(v3) ((v3) ? NFSX_V3SATTR : NFSX_V2SATTR) +#define NFSX_COOKIEVERF(v3) ((v3) ? NFSX_V3COOKIEVERF : 0) +#define NFSX_WRITEVERF(v3) ((v3) ? NFSX_V3WRITEVERF : 0) +#define NFSX_READDIR(v3) ((v3) ? (5 * NFSX_UNSIGNED) : \ + (2 * NFSX_UNSIGNED)) +#define NFSX_STATFS(v3) ((v3) ? NFSX_V3STATFS : NFSX_V2STATFS) + +/* nfs rpc procedure numbers (before version mapping) */ +#define NFSPROC_NULL 0 +#define NFSPROC_GETATTR 1 +#define NFSPROC_SETATTR 2 +#define NFSPROC_LOOKUP 3 +#define NFSPROC_ACCESS 4 +#define NFSPROC_READLINK 5 +#define NFSPROC_READ 6 +#define NFSPROC_WRITE 7 +#define NFSPROC_CREATE 8 +#define NFSPROC_MKDIR 9 +#define NFSPROC_SYMLINK 10 +#define NFSPROC_MKNOD 11 +#define NFSPROC_REMOVE 12 +#define NFSPROC_RMDIR 13 +#define NFSPROC_RENAME 14 +#define NFSPROC_LINK 15 +#define NFSPROC_READDIR 16 +#define NFSPROC_READDIRPLUS 17 +#define NFSPROC_FSSTAT 18 +#define NFSPROC_FSINFO 19 +#define NFSPROC_PATHCONF 20 +#define NFSPROC_COMMIT 21 +#define NFSPROC_NOOP 22 +#define NFS_NPROCS 23 + +/* Actual Version 2 procedure numbers */ +#define NFSV2PROC_NULL 0 +#define NFSV2PROC_GETATTR 1 +#define NFSV2PROC_SETATTR 2 +#define NFSV2PROC_NOOP 3 +#define NFSV2PROC_ROOT NFSV2PROC_NOOP /* Obsolete */ +#define NFSV2PROC_LOOKUP 4 +#define NFSV2PROC_READLINK 5 +#define NFSV2PROC_READ 6 +#define NFSV2PROC_WRITECACHE NFSV2PROC_NOOP /* Obsolete */ +#define NFSV2PROC_WRITE 8 +#define NFSV2PROC_CREATE 9 +#define NFSV2PROC_REMOVE 10 +#define NFSV2PROC_RENAME 11 +#define NFSV2PROC_LINK 12 +#define NFSV2PROC_SYMLINK 13 +#define NFSV2PROC_MKDIR 14 +#define NFSV2PROC_RMDIR 15 +#define NFSV2PROC_READDIR 16 +#define NFSV2PROC_STATFS 17 + +/* + * Constants used by the Version 3 protocol for various RPCs + */ +#define NFSV3SATTRTIME_DONTCHANGE 0 +#define NFSV3SATTRTIME_TOSERVER 1 +#define NFSV3SATTRTIME_TOCLIENT 2 + +#define NFSV3ACCESS_READ 0x01 +#define NFSV3ACCESS_LOOKUP 0x02 +#define NFSV3ACCESS_MODIFY 0x04 +#define NFSV3ACCESS_EXTEND 0x08 +#define NFSV3ACCESS_DELETE 0x10 +#define NFSV3ACCESS_EXECUTE 0x20 + +#define NFSV3WRITE_UNSTABLE 0 +#define NFSV3WRITE_DATASYNC 1 +#define NFSV3WRITE_FILESYNC 2 + +#define NFSV3CREATE_UNCHECKED 0 +#define NFSV3CREATE_GUARDED 1 +#define NFSV3CREATE_EXCLUSIVE 2 + +#define NFSV3FSINFO_LINK 0x01 +#define NFSV3FSINFO_SYMLINK 0x02 +#define NFSV3FSINFO_HOMOGENEOUS 0x08 +#define NFSV3FSINFO_CANSETTIME 0x10 + +/* Conversion macros */ +#define vtonfsv2_mode(t,m) \ + txdr_unsigned(((t) == VFIFO) ? MAKEIMODE(VCHR, (m)) : \ + MAKEIMODE((t), (m))) +#define vtonfsv3_mode(m) txdr_unsigned((m) & 07777) +#define nfstov_mode(a) (fxdr_unsigned(mode_t, (a))&07777) +#define vtonfsv2_type(a) txdr_unsigned(nfsv2_type[((int32_t)(a))]) +#define vtonfsv3_type(a) txdr_unsigned(nfsv3_type[((int32_t)(a))]) +#define nfsv2tov_type(a) nv2tov_type[fxdr_unsigned(u_int32_t,(a))&0x7] +#define nfsv3tov_type(a) nv3tov_type[fxdr_unsigned(u_int32_t,(a))&0x7] + +/* File types */ +typedef enum { NFNON=0, NFREG=1, NFDIR=2, NFBLK=3, NFCHR=4, NFLNK=5, + NFSOCK=6, NFFIFO=7 } nfstype; + +/* Structs for common parts of the rpc's */ +/* + * File Handle (32 bytes for version 2), variable up to 64 for version 3. + */ +#ifndef NFS_MAXFHSIZE +#define NFS_MAXFHSIZE 64 +#endif +union nfsfh { + fhandle_t fh_generic; + u_char fh_bytes[NFS_MAXFHSIZE]; +}; +typedef union nfsfh nfsfh_t; + +struct nfsv2_time { + u_int32_t nfsv2_sec; + u_int32_t nfsv2_usec; +}; +typedef struct nfsv2_time nfstime2; + +struct nfsv3_time { + u_int32_t nfsv3_sec; + u_int32_t nfsv3_nsec; +}; +typedef struct nfsv3_time nfstime3; + +/* + * Quads are defined as arrays of 2 longs to ensure dense packing for the + * protocol and to facilitate xdr conversion. + */ +struct nfs_uquad { + u_int32_t nfsuquad[2]; +}; +typedef struct nfs_uquad nfsuint64; + +/* + * NFS Version 3 special file number. + */ +struct nfsv3_spec { + u_int32_t specdata1; + u_int32_t specdata2; +}; +typedef struct nfsv3_spec nfsv3spec; + +/* + * File attributes and setable attributes. These structures cover both + * NFS version 2 and the version 3 protocol. Note that the union is only + * used so that one pointer can refer to both variants. These structures + * go out on the wire and must be densely packed, so no quad data types + * are used. (all fields are longs or u_longs or structures of same) + * NB: You can't do sizeof(struct nfs_fattr), you must use the + * NFSX_FATTR(v3) macro. + */ +struct nfs_fattr { + u_int32_t fa_type; + u_int32_t fa_mode; + u_int32_t fa_nlink; + u_int32_t fa_uid; + u_int32_t fa_gid; + union { + struct { + u_int32_t nfsv2fa_size; + u_int32_t nfsv2fa_blocksize; + u_int32_t nfsv2fa_rdev; + u_int32_t nfsv2fa_blocks; + u_int32_t nfsv2fa_fsid; + u_int32_t nfsv2fa_fileid; + nfstime2 nfsv2fa_atime; + nfstime2 nfsv2fa_mtime; + nfstime2 nfsv2fa_ctime; + } fa_nfsv2; + struct { + nfsuint64 nfsv3fa_size; + nfsuint64 nfsv3fa_used; + nfsv3spec nfsv3fa_rdev; + nfsuint64 nfsv3fa_fsid; + nfsuint64 nfsv3fa_fileid; + nfstime3 nfsv3fa_atime; + nfstime3 nfsv3fa_mtime; + nfstime3 nfsv3fa_ctime; + } fa_nfsv3; + } fa_un; +}; + +/* and some ugly defines for accessing union components */ +#define fa2_size fa_un.fa_nfsv2.nfsv2fa_size +#define fa2_blocksize fa_un.fa_nfsv2.nfsv2fa_blocksize +#define fa2_rdev fa_un.fa_nfsv2.nfsv2fa_rdev +#define fa2_blocks fa_un.fa_nfsv2.nfsv2fa_blocks +#define fa2_fsid fa_un.fa_nfsv2.nfsv2fa_fsid +#define fa2_fileid fa_un.fa_nfsv2.nfsv2fa_fileid +#define fa2_atime fa_un.fa_nfsv2.nfsv2fa_atime +#define fa2_mtime fa_un.fa_nfsv2.nfsv2fa_mtime +#define fa2_ctime fa_un.fa_nfsv2.nfsv2fa_ctime +#define fa3_size fa_un.fa_nfsv3.nfsv3fa_size +#define fa3_used fa_un.fa_nfsv3.nfsv3fa_used +#define fa3_rdev fa_un.fa_nfsv3.nfsv3fa_rdev +#define fa3_fsid fa_un.fa_nfsv3.nfsv3fa_fsid +#define fa3_fileid fa_un.fa_nfsv3.nfsv3fa_fileid +#define fa3_atime fa_un.fa_nfsv3.nfsv3fa_atime +#define fa3_mtime fa_un.fa_nfsv3.nfsv3fa_mtime +#define fa3_ctime fa_un.fa_nfsv3.nfsv3fa_ctime + +struct nfsv2_sattr { + u_int32_t sa_mode; + u_int32_t sa_uid; + u_int32_t sa_gid; + u_int32_t sa_size; + nfstime2 sa_atime; + nfstime2 sa_mtime; +}; + +/* + * NFS Version 3 sattr structure for the new node creation case. + */ +struct nfsv3_sattr { + u_int32_t sa_modetrue; + u_int32_t sa_mode; + u_int32_t sa_uidfalse; + u_int32_t sa_gidfalse; + u_int32_t sa_sizefalse; + u_int32_t sa_atimetype; + nfstime3 sa_atime; + u_int32_t sa_mtimetype; + nfstime3 sa_mtime; +}; + +struct nfs_statfs { + union { + struct { + u_int32_t nfsv2sf_tsize; + u_int32_t nfsv2sf_bsize; + u_int32_t nfsv2sf_blocks; + u_int32_t nfsv2sf_bfree; + u_int32_t nfsv2sf_bavail; + } sf_nfsv2; + struct { + nfsuint64 nfsv3sf_tbytes; + nfsuint64 nfsv3sf_fbytes; + nfsuint64 nfsv3sf_abytes; + nfsuint64 nfsv3sf_tfiles; + nfsuint64 nfsv3sf_ffiles; + nfsuint64 nfsv3sf_afiles; + u_int32_t nfsv3sf_invarsec; + } sf_nfsv3; + } sf_un; +}; + +#define sf_tsize sf_un.sf_nfsv2.nfsv2sf_tsize +#define sf_bsize sf_un.sf_nfsv2.nfsv2sf_bsize +#define sf_blocks sf_un.sf_nfsv2.nfsv2sf_blocks +#define sf_bfree sf_un.sf_nfsv2.nfsv2sf_bfree +#define sf_bavail sf_un.sf_nfsv2.nfsv2sf_bavail +#define sf_tbytes sf_un.sf_nfsv3.nfsv3sf_tbytes +#define sf_fbytes sf_un.sf_nfsv3.nfsv3sf_fbytes +#define sf_abytes sf_un.sf_nfsv3.nfsv3sf_abytes +#define sf_tfiles sf_un.sf_nfsv3.nfsv3sf_tfiles +#define sf_ffiles sf_un.sf_nfsv3.nfsv3sf_ffiles +#define sf_afiles sf_un.sf_nfsv3.nfsv3sf_afiles +#define sf_invarsec sf_un.sf_nfsv3.nfsv3sf_invarsec + +struct nfsv3_fsinfo { + u_int32_t fs_rtmax; + u_int32_t fs_rtpref; + u_int32_t fs_rtmult; + u_int32_t fs_wtmax; + u_int32_t fs_wtpref; + u_int32_t fs_wtmult; + u_int32_t fs_dtpref; + nfsuint64 fs_maxfilesize; + nfstime3 fs_timedelta; + u_int32_t fs_properties; +}; + +struct nfsv3_pathconf { + u_int32_t pc_linkmax; + u_int32_t pc_namemax; + u_int32_t pc_notrunc; + u_int32_t pc_chownrestricted; + u_int32_t pc_caseinsensitive; + u_int32_t pc_casepreserving; +}; + +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/nfs/nfsrvcache.h b/lib/libc/include/generic-openbsd/nfs/nfsrvcache.h new file mode 100644 index 0000000000..93ee164628 --- /dev/null +++ b/lib/libc/include/generic-openbsd/nfs/nfsrvcache.h @@ -0,0 +1,81 @@ +/* $OpenBSD: nfsrvcache.h,v 1.8 2013/11/26 20:41:27 beck Exp $ */ +/* $NetBSD: nfsrvcache.h,v 1.10 1996/02/18 11:54:08 fvdl Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Rick Macklem at The University of Guelph. + * + * 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. + * + * @(#)nfsrvcache.h 8.3 (Berkeley) 3/30/95 + */ + +#ifndef _NFS_NFSRVCACHE_H_ +#define _NFS_NFSRVCACHE_H_ + +#define NFSRVCACHESIZ 2048 + +struct nfsrvcache { + TAILQ_ENTRY(nfsrvcache) rc_lru; /* LRU chain */ + LIST_ENTRY(nfsrvcache) rc_hash; /* Hash chain */ + u_int32_t rc_xid; /* rpc id number */ + union { + struct mbuf *ru_repmb; /* Reply mbuf list OR */ + int ru_repstat; /* Reply status */ + } rc_un; + union nethostaddr rc_haddr; /* Host address */ + u_int16_t rc_proc; /* rpc proc number */ + u_char rc_state; /* Current state of request */ + u_char rc_flag; /* Flag bits */ +}; + +#define rc_reply rc_un.ru_repmb +#define rc_status rc_un.ru_repstat +#define rc_inetaddr rc_haddr.had_inetaddr +#define rc_nam rc_haddr.had_nam + +/* Cache entry states */ +#define RC_UNUSED 0 +#define RC_INPROG 1 +#define RC_DONE 2 + +/* Return values */ +#define RC_DROPIT 0 +#define RC_REPLY 1 +#define RC_DOIT 2 +#define RC_CHECKIT 3 + +/* Flag bits */ +#define RC_LOCKED 0x01 +#define RC_WANTED 0x02 +#define RC_REPSTATUS 0x04 +#define RC_REPMBUF 0x08 +#define RC_INETADDR 0x20 +#define RC_NAM 0x40 + +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/nfs/rpcv2.h b/lib/libc/include/generic-openbsd/nfs/rpcv2.h new file mode 100644 index 0000000000..a88819ee47 --- /dev/null +++ b/lib/libc/include/generic-openbsd/nfs/rpcv2.h @@ -0,0 +1,101 @@ +/* $OpenBSD: rpcv2.h,v 1.8 2008/07/04 16:49:28 blambert Exp $ */ +/* $NetBSD: rpcv2.h,v 1.8 1996/02/18 11:54:11 fvdl Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Rick Macklem at The University of Guelph. + * + * 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. + * + * @(#)rpcv2.h 8.2 (Berkeley) 3/30/95 + */ + + +#ifndef _NFS_RPCV2_H_ +#define _NFS_RPCV2_H_ + +/* + * Definitions for Sun RPC Version 2, from + * "RPC: Remote Procedure Call Protocol Specification" RFC1057 + */ + +/* Version # */ +#define RPC_VER2 2 + +/* Authentication */ +#define RPCAUTH_NULL 0 +#define RPCAUTH_UNIX 1 +#define RPCAUTH_SHORT 2 +#define RPCAUTH_KERB4 4 +#define RPCAUTH_MAXSIZ 400 +#define RPCVERF_MAXSIZ 12 /* For Kerb, can actually be 400 */ +#define RPCAUTH_UNIXGIDS 16 + +/* + * Constants associated with authentication flavours. + */ +#define RPCAKN_FULLNAME 0 +#define RPCAKN_NICKNAME 1 + +/* Rpc Constants */ +#define RPC_CALL 0 +#define RPC_REPLY 1 +#define RPC_MSGACCEPTED 0 +#define RPC_MSGDENIED 1 +#define RPC_PROGUNAVAIL 1 +#define RPC_PROGMISMATCH 2 +#define RPC_PROCUNAVAIL 3 +#define RPC_GARBAGE 4 /* I like this one */ +#define RPC_MISMATCH 0 +#define RPC_AUTHERR 1 + +/* Authentication failures */ +#define AUTH_BADCRED 1 +#define AUTH_REJECTCRED 2 +#define AUTH_BADVERF 3 +#define AUTH_REJECTVERF 4 +#define AUTH_TOOWEAK 5 /* Give em wheaties */ + +/* Sizes of rpc header parts */ +#define RPC_SIZ 24 +#define RPC_REPLYSIZ 28 + +/* RPC Prog definitions */ +#define RPCPROG_MNT 100005 +#define RPCMNT_VER1 1 +#define RPCMNT_VER3 3 +#define RPCMNT_MOUNT 1 +#define RPCMNT_DUMP 2 +#define RPCMNT_UMOUNT 3 +#define RPCMNT_UMNTALL 4 +#define RPCMNT_EXPORT 5 +#define RPCMNT_NAMELEN 255 +#define RPCMNT_PATHLEN 1024 +#define RPCPROG_NFS 100003 + +#endif /* _NFS_RPCV2_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/nfs/xdr_subs.h b/lib/libc/include/generic-openbsd/nfs/xdr_subs.h new file mode 100644 index 0000000000..4cafdafbac --- /dev/null +++ b/lib/libc/include/generic-openbsd/nfs/xdr_subs.h @@ -0,0 +1,86 @@ +/* $OpenBSD: xdr_subs.h,v 1.10 2015/04/17 04:43:21 guenther Exp $ */ +/* $NetBSD: xdr_subs.h,v 1.11 1996/02/18 11:54:12 fvdl Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Rick Macklem at The University of Guelph. + * + * 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. + * + * @(#)xdr_subs.h 8.3 (Berkeley) 3/30/95 + */ + + +#ifndef _NFS_XDR_SUBS_H_ +#define _NFS_XDR_SUBS_H_ + +/* + * Macros used for conversion to/from xdr representation by nfs... + * These use the MACHINE DEPENDENT routines ntohl, htonl + * As defined by "XDR: External Data Representation Standard" RFC1014 + * + * To simplify the implementation, we use ntohl/htonl even on big-endian + * machines, and count on them being `#define'd away. Some of these + * might be slightly more efficient as quad_t copies on a big-endian, + * but we cannot count on their alignment anyway. + */ + +#define fxdr_unsigned(t, v) ((t)ntohl((int32_t)(v))) +#define txdr_unsigned(v) (htonl((int32_t)(v))) + +#define fxdr_nfsv2time(f, t) do { \ + (t)->tv_sec = ntohl(((struct nfsv2_time *)(f))->nfsv2_sec); \ + if (((struct nfsv2_time *)(f))->nfsv2_usec != 0xffffffff) \ + (t)->tv_nsec = 1000 * ntohl(((struct nfsv2_time *)(f))->nfsv2_usec); \ + else \ + (t)->tv_nsec = 0; \ +} while (0) + +struct nfsv2_time; +void txdr_nfsv2time(const struct timespec *_from, struct nfsv2_time *_to); + +#define fxdr_nfsv3time(f, t) do { \ + (t)->tv_sec = ntohl(((struct nfsv3_time *)(f))->nfsv3_sec); \ + (t)->tv_nsec = ntohl(((struct nfsv3_time *)(f))->nfsv3_nsec); \ +} while (0) +#define txdr_nfsv3time(f, t) do { \ + ((struct nfsv3_time *)(t))->nfsv3_sec = htonl((f)->tv_sec); \ + ((struct nfsv3_time *)(t))->nfsv3_nsec = htonl((f)->tv_nsec); \ +} while (0) + +#define fxdr_hyper(f) \ + ((((u_quad_t)ntohl(((u_int32_t *)(f))[0])) << 32) | \ + (u_quad_t)(ntohl(((u_int32_t *)(f))[1]))) + + +#define txdr_hyper(f, t) do { \ + ((u_int32_t *)(t))[0] = htonl((u_int32_t)((f) >> 32)); \ + ((u_int32_t *)(t))[1] = htonl((u_int32_t)((f) & 0xffffffff)); \ +} while (0) + +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/nl_types.h b/lib/libc/include/generic-openbsd/nl_types.h new file mode 100644 index 0000000000..b27328eff4 --- /dev/null +++ b/lib/libc/include/generic-openbsd/nl_types.h @@ -0,0 +1,91 @@ +/* $OpenBSD: nl_types.h,v 1.8 2008/06/26 05:42:04 ray Exp $ */ +/* $NetBSD: nl_types.h,v 1.6 1996/05/13 23:11:15 jtc Exp $ */ + +/*- + * Copyright (c) 1996 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by J.T. Conklin. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _NL_TYPES_H_ +#define _NL_TYPES_H_ +#include + +#ifdef _NLS_PRIVATE +/* + * MESSAGE CATALOG FILE FORMAT. + * + * The NetBSD message catalog format is similar to the format used by + * Svr4 systems. The differences are: + * * fixed byte order (big endian) + * * fixed data field sizes + * + * A message catalog contains four data types: a catalog header, one + * or more set headers, one or more message headers, and one or more + * text strings. + */ + +#define _NLS_MAGIC 0xff88ff89 + +struct _nls_cat_hdr { + int32_t __magic; + int32_t __nsets; + int32_t __mem; + int32_t __msg_hdr_offset; + int32_t __msg_txt_offset; +} ; + +struct _nls_set_hdr { + int32_t __setno; /* set number: 0 < x <= NL_SETMAX */ + int32_t __nmsgs; /* number of messages in the set */ + int32_t __index; /* index of first msg_hdr in msg_hdr table */ +} ; + +struct _nls_msg_hdr { + int32_t __msgno; /* msg number: 0 < x <= NL_MSGMAX */ + int32_t __msglen; + int32_t __offset; +} ; + +#endif + +#define NL_SETD 1 +#define NL_CAT_LOCALE 1 + +typedef struct _nl_catd { + void *__data; + int __size; +} *nl_catd; + +typedef long nl_item; + +__BEGIN_DECLS +extern nl_catd catopen(const char *, int); +extern char *catgets(nl_catd, int, int, const char *); +extern int catclose(nl_catd); +__END_DECLS + +#endif /* _NL_TYPES_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/nlist.h b/lib/libc/include/generic-openbsd/nlist.h new file mode 100644 index 0000000000..ed43472169 --- /dev/null +++ b/lib/libc/include/generic-openbsd/nlist.h @@ -0,0 +1,87 @@ +/* $OpenBSD: nlist.h,v 1.4 2003/06/02 19:34:12 millert Exp $ */ +/* $NetBSD: nlist.h,v 1.5 1994/10/26 00:56:11 cgd Exp $ */ + +/*- + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)nlist.h 8.2 (Berkeley) 1/21/94 + */ + +#ifndef _NLIST_H_ +#define _NLIST_H_ + +/* + * Symbol table entry format. The #ifdef's are so that programs including + * nlist.h can initialize nlist structures statically. + */ +struct nlist { +#ifdef _AOUT_INCLUDE_ + union { + char *n_name; /* symbol name (in memory) */ + long n_strx; /* file string table offset (on disk) */ + } n_un; +#else + char *n_name; /* symbol name (in memory) */ +#endif + +#define N_UNDF 0x00 /* undefined */ +#define N_ABS 0x02 /* absolute address */ +#define N_TEXT 0x04 /* text segment */ +#define N_DATA 0x06 /* data segment */ +#define N_BSS 0x08 /* bss segment */ +#define N_INDR 0x0a /* alias definition */ +#define N_SIZE 0x0c /* pseudo type, defines a symbol's size */ +#define N_COMM 0x12 /* common reference */ +#define N_FN 0x1e /* file name (N_EXT on) */ +#define N_WARN 0x1e /* warning message (N_EXT off) */ + +#define N_EXT 0x01 /* external (global) bit, OR'ed in */ +#define N_TYPE 0x1e /* mask for all the type bits */ + unsigned char n_type; /* type defines */ + + char n_other; /* spare */ +#define n_hash n_desc /* used internally by ld(1); XXX */ + short n_desc; /* used by stab entries */ + unsigned long n_value; /* address/value of the symbol */ +}; + +#define N_FORMAT "%08x" /* namelist value format; XXX */ +#define N_STAB 0x0e0 /* mask for debugger symbols -- stab(5) */ + +#include + +__BEGIN_DECLS +int nlist(const char *, struct nlist *); +__END_DECLS + +#endif /* !_NLIST_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ntfs/ntfs.h b/lib/libc/include/generic-openbsd/ntfs/ntfs.h new file mode 100644 index 0000000000..142f0b2ac1 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ntfs/ntfs.h @@ -0,0 +1,315 @@ +/* $OpenBSD: ntfs.h,v 1.19 2022/01/11 03:13:59 jsg Exp $ */ +/* $NetBSD: ntfs.h,v 1.5 2003/04/24 07:50:19 christos Exp $ */ + +/*- + * Copyright (c) 1998, 1999 Semen Ustimenko + * 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 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 AUTHOR 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. + * + * Id: ntfs.h,v 1.5 1999/05/12 09:42:51 semenu Exp + */ + +/*#define NTFS_DEBUG 1*/ +typedef u_int64_t cn_t; +typedef u_int16_t wchar; + +#define BBSIZE 1024 +#define BBOFF ((off_t)(0)) +#define BBLOCK 0 +#define NTFS_MFTINO 0 +#define NTFS_VOLUMEINO 3 +#define NTFS_ATTRDEFINO 4 +#define NTFS_ROOTINO 5 +#define NTFS_BITMAPINO 6 +#define NTFS_BOOTINO 7 +#define NTFS_BADCLUSINO 8 +#define NTFS_UPCASEINO 10 +#define NTFS_MAXFILENAME 255 + +/* + * UFS directories use 32bit inode numbers internally, regardless + * of what the system on top of it uses. + */ +typedef u_int32_t ntfsino_t; + +struct fixuphdr { + u_int32_t fh_magic; + u_int16_t fh_foff; + u_int16_t fh_fnum; +} __packed; + +#define NTFS_AF_INRUN 0x00000001 +struct attrhdr { + u_int32_t a_type; + u_int32_t reclen; + u_int8_t a_flag; + u_int8_t a_namelen; + u_int8_t a_nameoff; + u_int8_t reserved1; + u_int8_t a_compression; + u_int8_t reserved2; + u_int16_t a_index; +} __packed; +#define NTFS_A_STD 0x10 +#define NTFS_A_ATTRLIST 0x20 +#define NTFS_A_NAME 0x30 +#define NTFS_A_VOLUMENAME 0x60 +#define NTFS_A_DATA 0x80 +#define NTFS_A_INDXROOT 0x90 +#define NTFS_A_INDX 0xA0 +#define NTFS_A_INDXBITMAP 0xB0 + +#define NTFS_MAXATTRNAME 255 +struct attr { + struct attrhdr a_hdr; + union { + struct { + u_int16_t a_datalen; + u_int16_t reserved1; + u_int16_t a_dataoff; + u_int16_t a_indexed; + } __packed a_S_r; + struct { + cn_t a_vcnstart; + cn_t a_vcnend; + u_int16_t a_dataoff; + u_int16_t a_compressalg; + u_int32_t reserved1; + u_int64_t a_allocated; + u_int64_t a_datalen; + u_int64_t a_initialized; + } __packed a_S_nr; + } a_S; +} __packed; +#define a_r a_S.a_S_r +#define a_nr a_S.a_S_nr + +typedef struct { + u_int64_t t_create; + u_int64_t t_write; + u_int64_t t_mftwrite; + u_int64_t t_access; +} __packed ntfs_times_t; + +#define NTFS_FFLAG_RDONLY 0x01LL +#define NTFS_FFLAG_HIDDEN 0x02LL +#define NTFS_FFLAG_SYSTEM 0x04LL +#define NTFS_FFLAG_ARCHIVE 0x20LL +#define NTFS_FFLAG_COMPRESSED 0x0800LL +#define NTFS_FFLAG_DIR 0x10000000LL + +struct attr_name { + u_int32_t n_pnumber; /* Parent ntnode */ + u_int32_t reserved; + ntfs_times_t n_times; + u_int64_t n_size; + u_int64_t n_attrsz; + u_int64_t n_flag; + u_int8_t n_namelen; + u_int8_t n_nametype; + u_int16_t n_name[1]; +} __packed; + +#define NTFS_IRFLAG_INDXALLOC 0x00000001 +struct attr_indexroot { + u_int32_t ir_unkn1; /* always 0x30 */ + u_int32_t ir_unkn2; /* always 0x1 */ + u_int32_t ir_size;/* ??? */ + u_int32_t ir_unkn3; /* number of cluster */ + u_int32_t ir_unkn4; /* always 0x10 */ + u_int32_t ir_datalen; /* sizeof something */ + u_int32_t ir_allocated; /* same as above */ + u_int16_t ir_flag;/* ?? always 1 */ + u_int16_t ir_unkn7; +} __packed; + +struct attr_attrlist { + u_int32_t al_type; /* Attribute type */ + u_int16_t reclen; /* length of this entry */ + u_int8_t al_namelen; /* Attribute name len */ + u_int8_t al_nameoff; /* Name offset from entry start */ + u_int64_t al_vcnstart; /* VCN number */ + u_int32_t al_inumber; /* Parent ntnode */ + u_int32_t reserved; + u_int16_t al_index; /* Attribute index in MFT record */ + u_int16_t al_name[1]; /* Name */ +} __packed; + +#define NTFS_INDXMAGIC (u_int32_t)(0x58444E49) +struct attr_indexalloc { + struct fixuphdr ia_fixup; + u_int64_t unknown1; + cn_t ia_bufcn; + u_int16_t ia_hdrsize; + u_int16_t unknown2; + u_int32_t ia_inuse; + u_int32_t ia_allocated; +} __packed; + +#define NTFS_IEFLAG_SUBNODE 0x00000001 +#define NTFS_IEFLAG_LAST 0x00000002 + +struct attr_indexentry { + u_int32_t ie_number; + u_int32_t unknown1; + u_int16_t reclen; + u_int16_t ie_size; + u_int32_t ie_flag;/* 1 - has subnodes, 2 - last */ + u_int32_t ie_fpnumber; + u_int32_t unknown2; + ntfs_times_t ie_ftimes; + u_int64_t ie_fallocated; + u_int64_t ie_fsize; + u_int64_t ie_fflag; + u_int8_t ie_fnamelen; + u_int8_t ie_fnametype; + wchar ie_fname[NTFS_MAXFILENAME]; + /* cn_t ie_bufcn; buffer with subnodes */ +} __packed; + +#define NTFS_FILEMAGIC (u_int32_t)(0x454C4946) +#define NTFS_FRFLAG_DIR 0x0002 +struct filerec { + struct fixuphdr fr_fixup; + u_int8_t reserved[8]; + u_int16_t fr_seqnum; /* Sequence number */ + u_int16_t fr_nlink; + u_int16_t fr_attroff; /* offset to attributes */ + u_int16_t fr_flags; /* 1-nonresident attr, 2-directory */ + u_int32_t fr_size;/* hdr + attributes */ + u_int32_t fr_allocated; /* allocated length of record */ + u_int64_t fr_mainrec; /* main record */ + u_int16_t fr_attrnum; /* maximum attr number + 1 ??? */ +} __packed; + +#define NTFS_ATTRNAME_MAXLEN 0x40 +#define NTFS_ADFLAG_NONRES 0x0080 /* Attrib can be non resident */ +#define NTFS_ADFLAG_INDEX 0x0002 /* Attrib can be indexed */ +struct attrdef { + wchar ad_name[NTFS_ATTRNAME_MAXLEN]; + u_int32_t ad_type; + u_int32_t reserved1[2]; + u_int32_t ad_flag; + u_int64_t ad_minlen; + u_int64_t ad_maxlen; /* -1 for nonlimited */ +} __packed; + +struct ntvattrdef { + char ad_name[0x40]; + int ad_namelen; + u_int32_t ad_type; +} __packed; + +#define NTFS_BBID "NTFS " +#define NTFS_BBIDLEN 8 +struct bootfile { + u_int8_t reserved1[3]; /* asm jmp near ... */ + u_int8_t bf_sysid[8]; /* 'NTFS ' */ + u_int16_t bf_bps; /* bytes per sector */ + u_int8_t bf_spc; /* sectors per cluster */ + u_int8_t reserved2[7]; /* unused (zeroed) */ + u_int8_t bf_media; /* media desc. (0xF8) */ + u_int8_t reserved3[2]; + u_int16_t bf_spt; /* sectors per track */ + u_int16_t bf_heads; /* number of heads */ + u_int8_t reserver4[12]; + u_int64_t bf_spv; /* sectors per volume */ + cn_t bf_mftcn; /* $MFT cluster number */ + cn_t bf_mftmirrcn; /* $MFTMirr cn */ + u_int8_t bf_mftrecsz; /* MFT record size (clust) */ + /* 0xF6 indicates 1/4 */ + u_int32_t bf_ibsz; /* index buffer size */ + u_int32_t bf_volsn; /* volume ser. num. */ +} __packed; + +typedef wchar (ntfs_wget_func_t)(const char **); +typedef int (ntfs_wput_func_t)(char *, size_t, wchar); +typedef int (ntfs_wcmp_func_t)(wchar, wchar); + +/* + * Maximum number of ntnodes to keep in memory. We do not want to leave + * large data structures hanging off vnodes indefinitely and the data + * needed to reload the ntnode should already be in the buffer cache. + */ +#define LOADED_NTNODE_HI 16 +struct ntnode; +TAILQ_HEAD(ntnodeq, ntnode); + +#define NTFS_SYSNODESNUM 0x0B +struct ntfsmount { + struct mount *ntm_mountp; /* filesystem vfs structure */ + struct bootfile ntm_bootfile; + dev_t ntm_dev; /* device mounted */ + struct vnode *ntm_devvp; /* block device mounted vnode */ + struct vnode *ntm_sysvn[NTFS_SYSNODESNUM]; + u_int32_t ntm_bpmftrec; + uid_t ntm_uid; + gid_t ntm_gid; + mode_t ntm_mode; + u_long ntm_flag; + cn_t ntm_cfree; + struct ntvattrdef *ntm_ad; + int ntm_adnum; + struct netexport ntm_export; /* export information */ + ntfs_wget_func_t *ntm_wget; /* decode string to Unicode string */ + ntfs_wput_func_t *ntm_wput; /* encode Unicode string to string */ + ntfs_wcmp_func_t *ntm_wcmp; /* compare to wide characters */ + int ntm_ntnodes; /* Number of loaded ntnodes. */ + struct ntnodeq ntm_ntnodeq; /* Queue of ntnodes (LRU). */ +}; + +#define ntm_mftcn ntm_bootfile.bf_mftcn +#define ntm_mftmirrcn ntm_bootfile.bf_mftmirrcn +#define ntm_mftrecsz ntm_bootfile.bf_mftrecsz +#define ntm_spc ntm_bootfile.bf_spc +#define ntm_bps ntm_bootfile.bf_bps + +#define NTFS_NEXTREC(s, type) ((type)(((caddr_t) s) + (s)->reclen)) + +/* Convert mount ptr to ntfsmount ptr. */ +#define VFSTONTFS(mp) ((struct ntfsmount *)((mp)->mnt_data)) +#define VTONT(v) FTONT(VTOF(v)) +#define VTOF(v) ((struct fnode *)((v)->v_data)) +#define FTOV(f) ((f)->f_vp) +#define FTONT(f) ((f)->f_ip) +#define ntfs_cntobn(cn) (daddr_t)((cn) * (ntmp->ntm_spc)) +#define ntfs_cntob(cn) (off_t)((cn) * (ntmp)->ntm_spc * (ntmp)->ntm_bps) +#define ntfs_btocn(off) (cn_t)((off) / ((ntmp)->ntm_spc * (ntmp)->ntm_bps)) +#define ntfs_btocl(off) (cn_t)((off + ntfs_cntob(1) - 1) / ((ntmp)->ntm_spc * (ntmp)->ntm_bps)) +#define ntfs_btocnoff(off) (off_t)((off) % ((ntmp)->ntm_spc * (ntmp)->ntm_bps)) +#define ntfs_bntob(bn) (int32_t)((bn) * (ntmp)->ntm_bps) + +#ifdef _KERNEL +#if defined(NTFS_DEBUG) +extern int ntfs_debug; +#define DNPRINTF(n, x...) do { if(ntfs_debug >= (n)) printf(x); } while(0) +#define DPRINTF(x...) DNPRINTF(1, x) +#define DDPRINTF(x...) DNPRINTF(2, x) +#else /* NTFS_DEBUG */ +#define DNPRINTF(n, x...) +#define DPRINTF(x...) +#define DDPRINTF(x...) +#endif + +extern const struct vops ntfs_vops; +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ntfs/ntfs_compr.h b/lib/libc/include/generic-openbsd/ntfs/ntfs_compr.h new file mode 100644 index 0000000000..fef525dc35 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ntfs/ntfs_compr.h @@ -0,0 +1,36 @@ +/* $OpenBSD: ntfs_compr.h,v 1.2 2003/05/20 03:23:11 mickey Exp $ */ +/* $NetBSD: ntfs_compr.h,v 1.1 2002/12/23 17:38:32 jdolecek Exp $ */ + +/*- + * Copyright (c) 1998, 1999 Semen Ustimenko + * 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 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 AUTHOR 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. + * + * Id: ntfs_compr.h,v 1.4 1999/05/12 09:42:55 semenu Exp + */ + +#define NTFS_COMPBLOCK_SIZE 0x1000 +#define NTFS_COMPUNIT_CL 16 + +int ntfs_uncompblock(u_int8_t *, u_int8_t *); +int ntfs_uncompunit(struct ntfsmount *, u_int8_t *, u_int8_t *); \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ntfs/ntfs_ihash.h b/lib/libc/include/generic-openbsd/ntfs/ntfs_ihash.h new file mode 100644 index 0000000000..680c97fbac --- /dev/null +++ b/lib/libc/include/generic-openbsd/ntfs/ntfs_ihash.h @@ -0,0 +1,35 @@ +/* $OpenBSD: ntfs_ihash.h,v 1.7 2025/01/13 13:58:41 claudio Exp $ */ +/* $NetBSD: ntfs_ihash.h,v 1.1 2002/12/23 17:38:32 jdolecek Exp $ */ + +/*- + * Copyright (c) 1998, 1999 Semen Ustimenko + * 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 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 AUTHOR 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. + * + * Id: ntfs_ihash.h,v 1.3 1999/05/12 09:42:59 semenu Exp + */ + +void ntfs_nthashinit(void); +struct ntnode *ntfs_nthashlookup(dev_t, ntfsino_t); +int ntfs_nthashins(struct ntnode *); +void ntfs_nthashrem(struct ntnode *); \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ntfs/ntfs_inode.h b/lib/libc/include/generic-openbsd/ntfs/ntfs_inode.h new file mode 100644 index 0000000000..14c7d45ef6 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ntfs/ntfs_inode.h @@ -0,0 +1,98 @@ +/* $OpenBSD: ntfs_inode.h,v 1.8 2021/03/11 13:31:35 jsg Exp $ */ +/* $NetBSD: ntfs_inode.h,v 1.1 2002/12/23 17:38:33 jdolecek Exp $ */ + +/*- + * Copyright (c) 1998, 1999 Semen Ustimenko + * 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 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 AUTHOR 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. + * + * Id: ntfs_inode.h,v 1.4 1999/05/12 09:43:00 semenu Exp + */ + +#define IN_HASHED 0x0800 /* Inode is on hash list */ +#define IN_LOADED 0x8000 /* ntvattrs loaded */ +#define IN_PRELOADED 0x4000 /* loaded from directory entry */ + +struct ntnode { + struct vnode *i_devvp; /* vnode of blk dev we live on */ + dev_t i_dev; /* Device associated with the inode. */ + + LIST_ENTRY(ntnode) i_hash; + TAILQ_ENTRY(ntnode) i_loaded; + + struct ntnode *i_next; + struct ntnode **i_prev; + + struct ntfsmount *i_mp; + ntfsino_t i_number; + u_int32_t i_flag; + + /* locking */ + struct rwlock i_lock; + int i_usecount; + + LIST_HEAD(,fnode) i_fnlist; + LIST_HEAD(,ntvattr) i_valist; + + long i_nlink; /* MFR */ + u_int64_t i_mainrec; /* MFR */ + u_int32_t i_frflag; /* MFR */ +}; + +#define FN_PRELOADED 0x0001 +#define FN_VALID 0x0002 +#define FN_AATTRNAME 0x0004 /* space allocated for f_attrname */ +struct fnode { + LIST_ENTRY(fnode) f_fnlist; + struct vnode *f_vp; /* Associated vnode */ + struct ntnode *f_ip; /* Associated ntnode */ + u_long f_flag; + + ntfs_times_t f_times; /* $NAME/dirinfo */ + u_int32_t f_pnumber; /* $NAME/dirinfo */ + u_int32_t f_fflag; /* $NAME/dirinfo */ + u_int64_t f_size; /* defattr/dirinfo: */ + u_int64_t f_allocated; /* defattr/dirinfo */ + + u_int32_t f_attrtype; + char *f_attrname; + + /* for ntreaddir */ + u_int32_t f_lastdattr; + u_int32_t f_lastdblnum; + u_int32_t f_lastdoff; + u_int32_t f_lastdnum; + caddr_t f_dirblbuf; + u_int32_t f_dirblsz; +}; + +/* This overlays the fid structure (see ) */ +struct ntfid { + u_int16_t ntfid_len; /* Length of structure. */ + u_int16_t ntfid_pad; /* Force 32-bit alignment. */ + ntfsino_t ntfid_ino; /* File number (ino). */ + u_int8_t ntfid_attr; /* Attribute identifier */ +#ifdef notyet + int32_t ntfid_gen; /* Generation number. */ +#endif +}; \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ntfs/ntfs_subr.h b/lib/libc/include/generic-openbsd/ntfs/ntfs_subr.h new file mode 100644 index 0000000000..40a713d8da --- /dev/null +++ b/lib/libc/include/generic-openbsd/ntfs/ntfs_subr.h @@ -0,0 +1,104 @@ +/* $OpenBSD: ntfs_subr.h,v 1.12 2024/05/13 01:15:53 jsg Exp $ */ +/* $NetBSD: ntfs_subr.h,v 1.1 2002/12/23 17:38:33 jdolecek Exp $ */ + +/*- + * Copyright (c) 1998, 1999 Semen Ustimenko + * 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 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 AUTHOR 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. + * + * Id: ntfs_subr.h,v 1.4 1999/05/12 09:43:02 semenu Exp + */ + +#define VA_LOADED 0x0001 +#define VA_PRELOADED 0x0002 + +struct ntvattr { + LIST_ENTRY(ntvattr) va_list; + + u_int32_t va_vflag; + struct vnode *va_vp; + struct ntnode *va_ip; + + u_int32_t va_flag; + u_int32_t va_type; + u_int8_t va_namelen; + char va_name[NTFS_MAXATTRNAME]; + + u_int32_t va_compression; + u_int32_t va_compressalg; + u_int64_t va_datalen; + u_int64_t va_allocated; + cn_t va_vcnstart; + cn_t va_vcnend; + u_int16_t va_index; + union { + struct { + cn_t * cn; + cn_t * cl; + u_long cnt; + } vrun; + caddr_t datap; + struct attr_name *name; + struct attr_indexroot *iroot; + struct attr_indexalloc *ialloc; + } va_d; +}; +#define va_vruncn va_d.vrun.cn +#define va_vruncl va_d.vrun.cl +#define va_vruncnt va_d.vrun.cnt +#define va_datap va_d.datap +#define va_a_name va_d.name +#define va_a_iroot va_d.iroot +#define va_a_ialloc va_d.ialloc + +int ntfs_procfixups( struct ntfsmount *, u_int32_t, caddr_t, size_t ); +int ntfs_parserun( cn_t *, cn_t *, u_int8_t *, u_long, u_long *); +int ntfs_runtocn( cn_t *, struct ntfsmount *, u_int8_t *, u_long, cn_t); +int ntfs_readntvattr_plain( struct ntfsmount *, struct ntnode *, struct ntvattr *, off_t, size_t, void *,size_t *, struct uio *); +int ntfs_readattr_plain( struct ntfsmount *, struct ntnode *, u_int32_t, char *, off_t, size_t, void *,size_t *, struct uio *); +int ntfs_readattr( struct ntfsmount *, struct ntnode *, u_int32_t, char *, off_t, size_t, void *, struct uio *); +int ntfs_filesize( struct ntfsmount *, struct fnode *, u_int64_t *, u_int64_t *); +struct timespec ntfs_nttimetounix( u_int64_t ); +int ntfs_runtovrun( cn_t **, cn_t **, u_long *, u_int8_t *); +int ntfs_attrtontvattr( struct ntfsmount *, struct ntvattr **, struct attr * ); +void ntfs_freentvattr( struct ntvattr * ); +int ntfs_isnamepermitted(struct ntfsmount *, struct attr_indexentry * ); +int ntfs_ntvattrrele(struct ntvattr * ); +int ntfs_ntvattrget(struct ntfsmount *, struct ntnode *, u_int32_t, const char *, cn_t , struct ntvattr **); +void ntfs_ntref(struct ntnode *); +void ntfs_ntrele(struct ntnode *); +int ntfs_loadntnode( struct ntfsmount *, struct ntnode * ); +int ntfs_fget(struct ntfsmount *, struct ntnode *, int, char *, struct fnode **); +void ntfs_frele(struct fnode *); +int ntfs_ntreaddir(struct ntfsmount *, struct fnode *, u_int32_t, struct attr_indexentry **, struct proc *); +int ntfs_ntlookupfile(struct ntfsmount *, struct vnode *, struct componentname *, struct vnode **); +int ntfs_ntlookup(struct ntfsmount *, ntfsino_t, struct ntnode **); +int ntfs_ntget(struct ntnode *); +void ntfs_ntput(struct ntnode *); +int ntfs_toupper_use(struct mount *, struct ntfsmount *, struct proc *); +void ntfs_toupper_unuse(struct proc *); + +/* ntfs_conv.c stuff */ +ntfs_wget_func_t ntfs_utf8_wget; +ntfs_wput_func_t ntfs_utf8_wput; +ntfs_wcmp_func_t ntfs_utf8_wcmp; \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ntfs/ntfs_vfsops.h b/lib/libc/include/generic-openbsd/ntfs/ntfs_vfsops.h new file mode 100644 index 0000000000..aa0fa15889 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ntfs/ntfs_vfsops.h @@ -0,0 +1,40 @@ +/* $OpenBSD: ntfs_vfsops.h,v 1.4 2020/02/27 09:10:31 mpi Exp $ */ +/* $NetBSD: ntfs_vfsops.h,v 1.1 2002/12/23 17:38:34 jdolecek Exp $ */ + +/*- + * Copyright (c) 1998, 1999 Semen Ustimenko (semenu@FreeBSD.org) + * 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 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 AUTHOR 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. + * + * Id: ntfs_vfsops.h,v 1.3 1999/05/12 09:43:06 semenu Exp + */ +#define VG_DONTLOADIN 0x0001 /* Tells ntfs_vgetex to do not call */ + /* ntfs_loadntnode() on ntnode, even if */ + /* ntnode not loaded */ +#define VG_DONTVALIDFN 0x0002 /* Tells ntfs_vgetex to do not validate */ + /* fnode */ +#define VG_EXT 0x0004 /* This is not main record */ + +int ntfs_vgetex(struct mount *, ntfsino_t, u_int32_t, char *, u_long, u_long, + struct vnode **); +int ntfs_calccfree(struct ntfsmount *, cn_t *); \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ntfs/ntfsmount.h b/lib/libc/include/generic-openbsd/ntfs/ntfsmount.h new file mode 100644 index 0000000000..1f70433411 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ntfs/ntfsmount.h @@ -0,0 +1,33 @@ +/* $OpenBSD: ntfsmount.h,v 1.3 2006/05/29 20:40:58 miod Exp $ */ +/* $NetBSD: ntfsmount.h,v 1.1 2002/12/23 17:38:34 jdolecek Exp $ */ + +/*- + * Copyright (c) 1998, 1999 Semen Ustimenko + * 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 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 AUTHOR 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. + * + * Id: ntfsmount.h,v 1.4 1999/05/12 09:43:09 semenu Exp + */ + +#define NTFS_MFLAG_CASEINS 0x00000001 +#define NTFS_MFLAG_ALLNAMES 0x00000002 \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ohash.h b/lib/libc/include/generic-openbsd/ohash.h new file mode 100644 index 0000000000..fdbe7a0787 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ohash.h @@ -0,0 +1,74 @@ +/* $OpenBSD: ohash.h,v 1.2 2014/06/02 18:52:03 deraadt Exp $ */ + +/* Copyright (c) 1999, 2004 Marc Espie + * + * 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 OHASH_H +#define OHASH_H + +/* Open hashing support. + * Open hashing was chosen because it is much lighter than other hash + * techniques, and more efficient in most cases. + */ + +/* user-visible data structure */ +struct ohash_info { + ptrdiff_t key_offset; + void *data; /* user data */ + void *(*calloc)(size_t, size_t, void *); + void (*free)(void *, void *); + void *(*alloc)(size_t, void *); +}; + +struct _ohash_record; + +/* private structure. It's there just so you can do a sizeof */ +struct ohash { + struct _ohash_record *t; + struct ohash_info info; + unsigned int size; + unsigned int total; + unsigned int deleted; +}; + +/* For this to be tweakable, we use small primitives, and leave part of the + * logic to the client application. e.g., hashing is left to the client + * application. We also provide a simple table entry lookup that yields + * a hashing table index (opaque) to be used in find/insert/remove. + * The keys are stored at a known position in the client data. + */ +__BEGIN_DECLS +void ohash_init(struct ohash *, unsigned, struct ohash_info *); +void ohash_delete(struct ohash *); + +unsigned int ohash_lookup_interval(struct ohash *, const char *, + const char *, uint32_t); +unsigned int ohash_lookup_memory(struct ohash *, const char *, + size_t, uint32_t) + __attribute__ ((__bounded__(__string__,2,3))); +void *ohash_find(struct ohash *, unsigned int); +void *ohash_remove(struct ohash *, unsigned int); +void *ohash_insert(struct ohash *, unsigned int, void *); +void *ohash_first(struct ohash *, unsigned int *); +void *ohash_next(struct ohash *, unsigned int *); +unsigned int ohash_entries(struct ohash *); + +void *ohash_create_entry(struct ohash_info *, const char *, const char **); +uint32_t ohash_interval(const char *, const char **); + +unsigned int ohash_qlookupi(struct ohash *, const char *, const char **); +unsigned int ohash_qlookup(struct ohash *, const char *); +__END_DECLS +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/paths.h b/lib/libc/include/generic-openbsd/paths.h new file mode 100644 index 0000000000..93e207d2a7 --- /dev/null +++ b/lib/libc/include/generic-openbsd/paths.h @@ -0,0 +1,81 @@ +/* $OpenBSD: paths.h,v 1.26 2019/07/11 03:54:17 tedu Exp $ */ +/* $NetBSD: paths.h,v 1.7 1994/10/26 00:56:12 cgd Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)paths.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _PATHS_H_ +#define _PATHS_H_ + +/* Default search path. */ +#define _PATH_DEFPATH "/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin" +/* All standard utilities path. */ +#define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin" + +#define _PATH_BSHELL "/bin/sh" +#define _PATH_CONSOLE "/dev/console" +#define _PATH_CSHELL "/bin/csh" +#define _PATH_DEFTAPE "/dev/rst0" +#define _PATH_DEVDB "/var/run/dev.db" +#define _PATH_DEVNULL "/dev/null" +#define _PATH_FSIRAND "/sbin/fsirand" +#define _PATH_KLOG "/dev/klog" +#define _PATH_KMEM "/dev/kmem" +#define _PATH_KSHELL "/bin/ksh" +#define _PATH_KSYMS "/dev/ksyms" +#define _PATH_KVMDB "/var/db/kvm_bsd.db" +#define _PATH_LOCALE "/usr/share/locale" +#define _PATH_LOGCONF "/etc/syslog.conf" +#define _PATH_LOGPID "/var/run/syslog.pid" +#define _PATH_MAILDIR "/var/mail" +#define _PATH_MAN "/usr/share/man" +#define _PATH_MEM "/dev/mem" +#define _PATH_NOLOGIN "/etc/nologin" +#define _PATH_RSH "/usr/bin/ssh" +#define _PATH_SENDMAIL "/usr/sbin/sendmail" +#define _PATH_SHELLS "/etc/shells" +#define _PATH_TTY "/dev/tty" +#define _PATH_UNIX "/bsd" +#define _PATH_VI "/usr/bin/vi" + + +/* Provide trailing slash, since mostly used for building pathnames. */ +#define _PATH_BOOTDIR "/usr/mdec/" +#define _PATH_DEV "/dev/" +#define _PATH_DEVFD "/dev/fd/" +#define _PATH_TMP "/tmp/" +#define _PATH_UUCPLOCK "/var/spool/lock/" +#define _PATH_VARDB "/var/db/" +#define _PATH_VAREMPTY "/var/empty/" +#define _PATH_VARRUN "/var/run/" +#define _PATH_VARTMP "/var/tmp/" + +#endif /* !_PATHS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/poll.h b/lib/libc/include/generic-openbsd/poll.h new file mode 100644 index 0000000000..06092f6c04 --- /dev/null +++ b/lib/libc/include/generic-openbsd/poll.h @@ -0,0 +1,9 @@ +/* $OpenBSD: poll.h,v 1.3 2003/10/29 16:41:13 deraadt Exp $ */ + +/* + * Written by Theo de Raadt, Public Domain + * + * Typical poll() implementations expect poll.h to be in /usr/include. + * However this is not a convenient place for the real definitions. + */ +#include \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/protocols/dumprestore.h b/lib/libc/include/generic-openbsd/protocols/dumprestore.h new file mode 100644 index 0000000000..bb85d08d6f --- /dev/null +++ b/lib/libc/include/generic-openbsd/protocols/dumprestore.h @@ -0,0 +1,159 @@ +/* $OpenBSD: dumprestore.h,v 1.11 2021/01/21 00:16:36 mortimer Exp $ */ +/* $NetBSD: dumprestore.h,v 1.14 2005/12/26 19:01:47 perry Exp $ */ + +/* + * Copyright (c) 1980, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)dumprestore.h 8.2 (Berkeley) 1/21/94 + */ + +#ifndef _PROTOCOLS_DUMPRESTORE_H_ +#define _PROTOCOLS_DUMPRESTORE_H_ + +/* + * TP_BSIZE is the size of file blocks on the dump tapes. + * Note that TP_BSIZE must be a multiple of DEV_BSIZE. + * + * NTREC is the number of TP_BSIZE blocks that are written + * in each tape record. HIGHDENSITYTREC is the number of + * TP_BSIZE blocks that are written in each tape record on + * 6250 BPI or higher density tapes. + * + * TP_NINDIR is the number of indirect pointers in a TS_INODE + * or TS_ADDR record. Note that it must be a power of two. + */ +#define TP_BSIZE 1024 +#define NTREC 10 +#define HIGHDENSITYTREC 32 +#define TP_NINDIR (TP_BSIZE/2) +#define LBLSIZE 16 +#define NAMELEN 64 + +#define OFS_MAGIC (int)60011 +#define NFS_MAGIC (int)60012 +#ifndef FS_UFS2_MAGIC +#define FS_UFS2_MAGIC (int)0x19540119 +#endif +#define CHECKSUM (int)84446 + +extern union u_spcl { + char dummy[TP_BSIZE]; + struct s_spcl { + int32_t c_type; /* record type (see below) */ + int32_t c_old_date; /* date of this dump */ + int32_t c_old_ddate; /* date of previous dump */ + int32_t c_volume; /* dump volume number */ + int32_t c_old_tapea; /* logical block of this record */ + uint32_t c_inumber; /* number of inode */ + int32_t c_magic; /* magic number (see above) */ + int32_t c_checksum; /* record checksum */ + union { + struct ufs1_dinode __uc_dinode; + struct { + uint16_t __uc_mode; + int16_t __uc_spare1[3]; + uint64_t __uc_size; + int32_t __uc_old_atime; + int32_t __uc_atimensec; + int32_t __uc_old_mtime; + int32_t __uc_mtimensec; + int32_t __uc_spare2[2]; + int32_t __uc_rdev; + int32_t __uc_birthtimensec; + int64_t __uc_birthtime; + int64_t __uc_atime; + int64_t __uc_mtime; + int32_t __uc_spare4[7]; + uint32_t __uc_file_flags; + int32_t __uc_spare5[2]; + uint32_t __uc_uid; + uint32_t __uc_gid; + int32_t __uc_spare6[2]; + } __uc_ino; + } __c_ino; + int32_t c_count; /* number of valid c_addr entries */ + char c_addr[TP_NINDIR]; /* 1 => data; 0 => hole in inode */ + char c_label[LBLSIZE]; /* dump label */ + int32_t c_level; /* level of this dump */ + char c_filesys[NAMELEN]; /* name of dumped file system */ + char c_dev[NAMELEN]; /* name of dumped device */ + char c_host[NAMELEN]; /* name of dumped host */ + int32_t c_flags; /* additional information */ + int32_t c_old_firstrec; /* first record on volume */ + int64_t c_date; /* date of this dump */ + int64_t c_ddate; /* date of previous dump */ + int64_t c_tapea; /* logical block of this record */ + int64_t c_firstrec; /* first record on volume */ + int32_t c_spare[24]; /* reserved for future uses */ + } s_spcl; +} u_spcl; +#define spcl u_spcl.s_spcl + +#define c_dinode __c_ino.__uc_dinode +#define c_mode __c_ino.__uc_ino.__uc_mode +#define c_spare1 __c_ino.__uc_ino.__uc_spare1 +#define c_size __c_ino.__uc_ino.__uc_size +#define c_old_atime __c_ino.__uc_ino.__uc_old_atime +#define c_atime __c_ino.__uc_ino.__uc_atime +#define c_atimensec __c_ino.__uc_ino.__uc_atimensec +#define c_mtime __c_ino.__uc_ino.__uc_mtime +#define c_mtimensec __c_ino.__uc_ino.__uc_mtimensec +#define c_birthtime __c_ino.__uc_ino.__uc_birthtime +#define c_birthtimensec __c_ino.__uc_ino.__uc_birthtimensec +#define c_old_mtime __c_ino.__uc_ino.__uc_old_mtime +#define c_rdev __c_ino.__uc_ino.__uc_rdev +#define c_file_flags __c_ino.__uc_ino.__uc_file_flags +#define c_uid __c_ino.__uc_ino.__uc_uid +#define c_gid __c_ino.__uc_ino.__uc_gid + +/* + * special record types + */ +#define TS_TAPE 1 /* dump tape header */ +#define TS_INODE 2 /* beginning of file record */ +#define TS_ADDR 4 /* continuation of file record */ +#define TS_BITS 3 /* map of inodes on tape */ +#define TS_CLRI 6 /* map of inodes deleted since last dump */ +#define TS_END 5 /* end of volume marker */ + +/* + * flag values + */ +#define DR_NEWHEADER 0x0001 /* new format tape header */ +#define DR_NEWINODEFMT 0x0002 /* new format inodes on tape */ + +#define DUMPOUTFMT "%-18s %c %s" /* for printf */ + /* name, level, ctime(date) */ +#define DUMPINFMT "%18s %c %[^\n]\n" /* inverse for scanf */ + +#endif /* !_PROTOCOLS_DUMPRESTORE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/protocols/routed.h b/lib/libc/include/generic-openbsd/protocols/routed.h new file mode 100644 index 0000000000..e73756df7c --- /dev/null +++ b/lib/libc/include/generic-openbsd/protocols/routed.h @@ -0,0 +1,152 @@ +/* $OpenBSD: routed.h,v 1.3 2003/06/02 19:34:12 millert Exp $ */ + +/*- + * Copyright (c) 1983, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)routed.h 8.1 (Berkeley) 6/2/93 + * + */ + +#ifndef _ROUTED_H_ +#define _ROUTED_H_ + +/* + * Routing Information Protocol + * + * Derived from Xerox NS Routing Information Protocol + * by changing 32-bit net numbers to sockaddr's and + * padding stuff to 32-bit boundaries. + */ + +#define RIPv1 1 +#define RIPv2 2 +#ifndef RIPVERSION +#define RIPVERSION RIPv1 +#endif + +#define RIP_PORT 520 + +#if RIPVERSION == 1 +/* Note that this so called sockaddr has a 2-byte sa_family and no sa_len. + * It is not a UNIX sockaddr, but the shape of an address as defined + * in RIPv1. It is still defined to allow old versions of programs + * such as `gated` to use this file to define RIPv1. + */ +struct netinfo { + struct sockaddr rip_dst; /* destination net/host */ + u_int32_t rip_metric; /* cost of route */ +}; +#else +struct netinfo { + u_int16_t n_family; +#define RIP_AF_INET htons(AF_INET) +#define RIP_AF_UNSPEC 0 +#define RIP_AF_AUTH 0xffff + u_int16_t n_tag; /* optional in RIPv2 */ + u_int32_t n_dst; /* destination net or host */ +#define RIP_DEFAULT 0 + u_int32_t n_mask; /* netmask in RIPv2 */ + u_int32_t n_nhop; /* optional next hop in RIPv2 */ + u_int32_t n_metric; /* cost of route */ +}; +#endif + +/* RIPv2 authentication */ +struct netauth { + u_int16_t a_type; +#define RIP_AUTH_PW htons(2) /* password type */ + union { +#define RIP_AUTH_PW_LEN 16 + int8_t au_pw[RIP_AUTH_PW_LEN]; + } au; +}; + +struct rip { + u_int8_t rip_cmd; /* request/response */ + u_int8_t rip_vers; /* protocol version # */ + u_int16_t rip_res1; /* pad to 32-bit boundary */ + union { /* variable length... */ + struct netinfo ru_nets[1]; + int8_t ru_tracefile[1]; + struct netauth ru_auth[1]; + } ripun; +#define rip_nets ripun.ru_nets +#define rip_tracefile ripun.ru_tracefile +}; + +/* Packet types. + */ +#define RIPCMD_REQUEST 1 /* want info */ +#define RIPCMD_RESPONSE 2 /* responding to request */ +#define RIPCMD_TRACEON 3 /* turn tracing on */ +#define RIPCMD_TRACEOFF 4 /* turn it off */ + +/* Gated extended RIP to include a "poll" command instead of using + * RIPCMD_REQUEST with (RIP_AF_UNSPEC, RIP_DEFAULT). RFC 1058 says + * command 5 is used by Sun Microsystems for its own purposes. + */ +#define RIPCMD_POLL 5 + +#define RIPCMD_MAX 6 + +#ifdef RIPCMDS +char *ripcmds[RIPCMD_MAX] = { + "#0", "REQUEST", "RESPONSE", "TRACEON", "TRACEOFF" +}; +#endif + +#define HOPCNT_INFINITY 16 +#define MAXPACKETSIZE 512 /* max broadcast size */ +#define NETS_LEN ((MAXPACKETSIZE-sizeof(struct rip)) \ + / sizeof(struct netinfo) +1) + +#define INADDR_RIP_GROUP __IPADDR(0xe0000009) /* 224.0.0.9 */ + + +/* Timer values used in managing the routing table. + * + * Complete tables are broadcast every SUPPLY_INTERVAL seconds. + * If changes occur between updates, dynamic updates containing only changes + * may be sent. When these are sent, a timer is set for a random value + * between MIN_WAITTIME and MAX_WAITTIME, and no additional dynamic updates + * are sent until the timer expires. + * + * Every update of a routing entry forces an entry's timer to be reset. + * After EXPIRE_TIME without updates, the entry is marked invalid, + * but held onto until GARBAGE_TIME so that others may see it, to + * "poison" the bad route. + */ +#define SUPPLY_INTERVAL 30 /* time to supply tables */ +#define MIN_WAITTIME 2 /* min sec until next flash updates */ +#define MAX_WAITTIME 5 /* max sec until flash update */ + +#define STALE_TIME 90 /* switch to a new gateway */ +#define EXPIRE_TIME 180 /* time to mark entry invalid */ +#define GARBAGE_TIME 240 /* time to garbage collect */ + +#endif /* !_ROUTED_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/protocols/rwhod.h b/lib/libc/include/generic-openbsd/protocols/rwhod.h new file mode 100644 index 0000000000..9757f71f03 --- /dev/null +++ b/lib/libc/include/generic-openbsd/protocols/rwhod.h @@ -0,0 +1,67 @@ +/* $OpenBSD: rwhod.h,v 1.4 2003/06/02 19:34:12 millert Exp $ */ +/* $NetBSD: rwhod.h,v 1.3 1994/10/26 00:56:51 cgd Exp $ */ + +/* + * Copyright (c) 1983 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. + * + * @(#)rwhod.h 5.6 (Berkeley) 4/3/91 + */ + +#ifndef _RWHOD_H_ +#define _RWHOD_H_ + +/* + * rwho protocol packet format. + */ +struct outmp { + char out_line[8]; /* tty name */ + char out_name[8]; /* user id */ + int32_t out_time; /* time on */ +}; + +struct whod { + char wd_vers; /* protocol version # */ + char wd_type; /* packet type, see below */ + char wd_pad[2]; + int32_t wd_sendtime; /* time stamp by sender */ + int32_t wd_recvtime; /* time stamp applied by receiver */ + char wd_hostname[32]; /* hosts's name */ + int32_t wd_loadav[3]; /* load average as in uptime */ + int32_t wd_boottime; /* time system booted */ + struct whoent { + struct outmp we_utmp; /* active tty info */ + int32_t we_idle; /* tty idle time */ + } wd_we[1024 / sizeof (struct whoent)]; +}; + +#define WHODVERSION 1 +#define WHODTYPE_STATUS 1 /* host status */ + +#define _PATH_RWHODIR "/var/rwho" + +#endif /* !_RWHOD_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/protocols/talkd.h b/lib/libc/include/generic-openbsd/protocols/talkd.h new file mode 100644 index 0000000000..09ba396b11 --- /dev/null +++ b/lib/libc/include/generic-openbsd/protocols/talkd.h @@ -0,0 +1,120 @@ +/* $OpenBSD: talkd.h,v 1.5 2015/01/21 02:23:14 guenther Exp $ */ +/* $NetBSD: talkd.h,v 1.5 1995/03/04 07:59:30 cgd Exp $ */ + +/* + * Copyright (c) 1983 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. + * + * @(#)talkd.h 5.7 (Berkeley) 4/3/91 + */ + +#ifndef _TALKD_H_ +#define _TALKD_H_ + +/* + * This describes the protocol used by the talk server and clients. + * + * The talk server acts a repository of invitations, responding to + * requests by clients wishing to rendezvous for the purpose of + * holding a conversation. In normal operation, a client, the caller, + * initiates a rendezvous by sending a CTL_MSG to the server of + * type LOOK_UP. This causes the server to search its invitation + * tables to check if an invitation currently exists for the caller + * (to speak to the callee specified in the message). If the lookup + * fails, the caller then sends an ANNOUNCE message causing the server + * to broadcast an announcement on the callee's login ports requesting + * contact. When the callee responds, the local server uses the + * recorded invitation to respond with the appropriate rendezvous + * address and the caller and callee client programs establish a + * stream connection through which the conversation takes place. + */ + +struct osockaddr { + unsigned short sa_family; /* address family */ + char sa_data[14]; /* up to 14 bytes of direct address */ +}; + +/* + * Client->server request message format. + */ +typedef struct { + unsigned char vers; /* protocol version */ + unsigned char type; /* request type, see below */ + unsigned char answer; /* not used */ + unsigned char pad; + u_int32_t id_num; /* message id */ + struct osockaddr addr; /* old (4.3) style */ + struct osockaddr ctl_addr; /* old (4.3) style */ + int32_t pid; /* caller's process id */ +#define NAME_SIZE 12 + char l_name[NAME_SIZE]; /* caller's name */ + char r_name[NAME_SIZE]; /* callee's name */ +#define TTY_SIZE 16 + char r_tty[TTY_SIZE]; /* callee's tty name */ +} CTL_MSG; + +/* + * Server->client response message format. + */ +typedef struct { + unsigned char vers; /* protocol version */ + unsigned char type; /* type of request message, see below */ + unsigned char answer; /* response to request message, + see below */ + unsigned char pad; + u_int32_t id_num; /* message id */ + struct osockaddr addr; /* address for establishing + conversation */ +} CTL_RESPONSE; + +#define TALK_VERSION 1 /* protocol version */ + +/* message type values */ +#define LEAVE_INVITE 0 /* leave invitation with server */ +#define LOOK_UP 1 /* check for invitation by callee */ +#define DELETE 2 /* delete invitation by caller */ +#define ANNOUNCE 3 /* announce invitation by caller */ + +/* answer values */ +#define SUCCESS 0 /* operation completed properly */ +#define NOT_HERE 1 /* callee not logged in */ +#define FAILED 2 /* operation failed for unexplained reason */ +#define MACHINE_UNKNOWN 3 /* caller's machine name unknown */ +#define PERMISSION_DENIED 4 /* callee's tty doesn't permit announce */ +#define UNKNOWN_REQUEST 5 /* request has invalid type value */ +#define BADVERSION 6 /* request has invalid protocol version */ +#define BADADDR 7 /* request has invalid addr value */ +#define BADCTLADDR 8 /* request has invalid ctl_addr value */ + +/* + * Operational parameters. + */ +#define MAX_LIFE 60 /* max time daemon saves invitations */ +/* RING_WAIT should be 10's of seconds less than MAX_LIFE */ +#define RING_WAIT 30 /* time to wait before resending invitation */ + +#endif /* !_TALKD_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/protocols/timed.h b/lib/libc/include/generic-openbsd/protocols/timed.h new file mode 100644 index 0000000000..43104a6baf --- /dev/null +++ b/lib/libc/include/generic-openbsd/protocols/timed.h @@ -0,0 +1,101 @@ +/* $OpenBSD: timed.h,v 1.4 2015/01/16 00:27:00 deraadt Exp $ */ +/* $NetBSD: timed.h,v 1.5 1996/04/09 20:40:32 cgd Exp $ */ + +/* + * Copyright (c) 1983 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. + * + * @(#)timed.h 1.10 (Berkeley) 4/3/91 + */ + +#ifndef _TIMED_H_ +#define _TIMED_H_ + +/* + * Time Synchronization Protocol + */ + +#define TSPVERSION 1 +#define ANYADDR NULL + +struct tsp { + u_int8_t tsp_type; + u_int8_t tsp_vers; + u_int16_t tsp_seq; + union { + struct { + int32_t tv_sec; + int32_t tv_usec; + } tspu_time; + char tspu_hopcnt; + } tsp_u; + char tsp_name[256]; +}; + +#define tsp_time tsp_u.tspu_time +#define tsp_hopcnt tsp_u.tspu_hopcnt + +/* + * Command types. + */ +#define TSP_ANY 0 /* match any types */ +#define TSP_ADJTIME 1 /* send adjtime */ +#define TSP_ACK 2 /* generic acknowledgement */ +#define TSP_MASTERREQ 3 /* ask for master's name */ +#define TSP_MASTERACK 4 /* acknowledge master request */ +#define TSP_SETTIME 5 /* send network time */ +#define TSP_MASTERUP 6 /* inform slaves that master is up */ +#define TSP_SLAVEUP 7 /* slave is up but not polled */ +#define TSP_ELECTION 8 /* advance candidature for master */ +#define TSP_ACCEPT 9 /* support candidature of master */ +#define TSP_REFUSE 10 /* reject candidature of master */ +#define TSP_CONFLICT 11 /* two or more masters present */ +#define TSP_RESOLVE 12 /* masters' conflict resolution */ +#define TSP_QUIT 13 /* reject candidature if master is up */ +#define TSP_DATE 14 /* reset the time (date command) */ +#define TSP_DATEREQ 15 /* remote request to reset the time */ +#define TSP_DATEACK 16 /* acknowledge time setting */ +#define TSP_TRACEON 17 /* turn tracing on */ +#define TSP_TRACEOFF 18 /* turn tracing off */ +#define TSP_MSITE 19 /* find out master's site */ +#define TSP_MSITEREQ 20 /* remote master's site request */ +#define TSP_TEST 21 /* for testing election algo */ +#define TSP_SETDATE 22 /* New from date command */ +#define TSP_SETDATEREQ 23 /* New remote for above */ +#define TSP_LOOP 24 /* loop detection packet */ + +#define TSPTYPENUMBER 25 + +#ifdef TSPTYPES +char *tsptype[TSPTYPENUMBER] = + { "ANY", "ADJTIME", "ACK", "MASTERREQ", "MASTERACK", "SETTIME", "MASTERUP", + "SLAVEUP", "ELECTION", "ACCEPT", "REFUSE", "CONFLICT", "RESOLVE", "QUIT", + "DATE", "DATEREQ", "DATEACK", "TRACEON", "TRACEOFF", "MSITE", "MSITEREQ", + "TEST", "SETDATE", "SETDATEREQ", "LOOP" }; +#endif + +#endif /* !_TIMED_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/pthread.h b/lib/libc/include/generic-openbsd/pthread.h new file mode 100644 index 0000000000..14141e3992 --- /dev/null +++ b/lib/libc/include/generic-openbsd/pthread.h @@ -0,0 +1,315 @@ +/* $OpenBSD: pthread.h,v 1.4 2018/03/05 01:15:26 deraadt Exp $ */ + +/* + * Copyright (c) 1993, 1994 by Chris Provenzano, proven@mit.edu + * Copyright (c) 1995-1998 by John Birrell + * 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 Chris Provenzano. + * 4. The name of Chris Provenzano may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO ``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 CHRIS PROVENZANO 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. + * + * $FreeBSD: pthread.h,v 1.13 1999/07/31 08:36:07 rse Exp $ + */ +#ifndef _PTHREAD_H_ +#define _PTHREAD_H_ + +/* + * Header files. + */ +#include +#include +#include +#include +#include + +/* + * Run-time invariant values: + */ +#define PTHREAD_DESTRUCTOR_ITERATIONS 4 +#define PTHREAD_KEYS_MAX 256 +#define PTHREAD_STACK_MIN (1U << _MAX_PAGE_SHIFT) +#define PTHREAD_THREADS_MAX ULONG_MAX + +/* + * Flags for threads and thread attributes. + */ +#define PTHREAD_DETACHED 0x1 +#define PTHREAD_SCOPE_SYSTEM 0x2 +#define PTHREAD_INHERIT_SCHED 0x4 +#define PTHREAD_NOFLOAT 0x8 + +#define PTHREAD_CREATE_DETACHED PTHREAD_DETACHED +#define PTHREAD_CREATE_JOINABLE 0 +#define PTHREAD_SCOPE_PROCESS 0 +#define PTHREAD_EXPLICIT_SCHED 0 + +/* + * Flags for read/write lock attributes + */ +#define PTHREAD_PROCESS_PRIVATE 0 +#define PTHREAD_PROCESS_SHARED 1 + +/* + * Flags for cancelling threads + */ +#define PTHREAD_CANCEL_ENABLE 0 +#define PTHREAD_CANCEL_DISABLE 1 +#define PTHREAD_CANCEL_DEFERRED 0 +#define PTHREAD_CANCEL_ASYNCHRONOUS 2 +#define PTHREAD_CANCELED ((void *) 1) + +/* + * Barrier flags + */ +#define PTHREAD_BARRIER_SERIAL_THREAD -1 + +/* + * Forward structure definitions. + * + * These are mostly opaque to the user. + */ +struct pthread; +struct pthread_attr; +struct pthread_cond; +struct pthread_cond_attr; +struct pthread_mutex; +struct pthread_mutex_attr; +struct pthread_once; +struct pthread_rwlock; +struct pthread_rwlockattr; + +/* + * Primitive system data type definitions required by P1003.1c. + * + * Note that P1003.1c specifies that there are no defined comparison + * or assignment operators for the types pthread_attr_t, pthread_cond_t, + * pthread_condattr_t, pthread_mutex_t, pthread_mutexattr_t. + */ +typedef struct pthread *pthread_t; +typedef struct pthread_attr *pthread_attr_t; +typedef volatile struct pthread_mutex *pthread_mutex_t; +typedef struct pthread_mutex_attr *pthread_mutexattr_t; +typedef struct pthread_cond *pthread_cond_t; +typedef struct pthread_cond_attr *pthread_condattr_t; +typedef int pthread_key_t; +typedef struct pthread_once pthread_once_t; +typedef struct pthread_rwlock *pthread_rwlock_t; +typedef struct pthread_rwlockattr *pthread_rwlockattr_t; +typedef struct pthread_barrier *pthread_barrier_t; +typedef struct pthread_barrierattr *pthread_barrierattr_t; +typedef struct pthread_spinlock *pthread_spinlock_t; + +/* + * Additional type definitions: + * + * Note that P1003.1c reserves the prefixes pthread_ and PTHREAD_ for + * use in header symbols. + */ +typedef void *pthread_addr_t; +typedef void *(*pthread_startroutine_t)(void *); + +/* + * Once definitions. + */ +struct pthread_once { + int state; + pthread_mutex_t mutex; +}; + +/* + * Flags for once initialization. + */ +#define PTHREAD_NEEDS_INIT 0 +#define PTHREAD_DONE_INIT 1 + +/* + * Static once initialization values. + */ +#define PTHREAD_ONCE_INIT { PTHREAD_NEEDS_INIT, PTHREAD_MUTEX_INITIALIZER } + +/* + * Static initialization values. + */ +#define PTHREAD_MUTEX_INITIALIZER NULL +#define PTHREAD_COND_INITIALIZER NULL +#define PTHREAD_RWLOCK_INITIALIZER NULL + +#define PTHREAD_PRIO_NONE 0 +#define PTHREAD_PRIO_INHERIT 1 +#define PTHREAD_PRIO_PROTECT 2 + +/* + * Mutex types. + */ +enum pthread_mutextype { + PTHREAD_MUTEX_ERRORCHECK = 1, /* Error checking mutex */ + PTHREAD_MUTEX_RECURSIVE = 2, /* Recursive mutex */ + PTHREAD_MUTEX_NORMAL = 3, /* No error checking */ + PTHREAD_MUTEX_STRICT_NP = 4, /* Strict error checking */ + PTHREAD_MUTEX_TYPE_MAX +}; + +#define PTHREAD_MUTEX_ERRORCHECK PTHREAD_MUTEX_ERRORCHECK +#define PTHREAD_MUTEX_RECURSIVE PTHREAD_MUTEX_RECURSIVE +#define PTHREAD_MUTEX_NORMAL PTHREAD_MUTEX_NORMAL +#define PTHREAD_MUTEX_STRICT_NP PTHREAD_MUTEX_STRICT_NP +#define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_STRICT_NP + +/* + * Thread function prototype definitions: + */ +__BEGIN_DECLS +int pthread_atfork(void (*)(void), void (*)(void), void (*)(void)); +int pthread_attr_destroy(pthread_attr_t *); +int pthread_attr_getstack(const pthread_attr_t *, + void **, size_t *); +int pthread_attr_getstacksize(const pthread_attr_t *, size_t *); +int pthread_attr_getstackaddr(const pthread_attr_t *, void **); +int pthread_attr_getguardsize(const pthread_attr_t *, size_t *); +int pthread_attr_getdetachstate(const pthread_attr_t *, int *); +int pthread_attr_init(pthread_attr_t *); +int pthread_attr_setstacksize(pthread_attr_t *, size_t); +int pthread_attr_setstack(pthread_attr_t *, void *, size_t); +int pthread_attr_setstackaddr(pthread_attr_t *, void *); +int pthread_attr_setguardsize(pthread_attr_t *, size_t); +int pthread_attr_setdetachstate(pthread_attr_t *, int); +void pthread_cleanup_pop(int); +void pthread_cleanup_push(void (*) (void *), void *routine_arg); +int pthread_condattr_destroy(pthread_condattr_t *); +int pthread_condattr_init(pthread_condattr_t *); + +int pthread_cond_broadcast(pthread_cond_t *); +int pthread_cond_destroy(pthread_cond_t *); +int pthread_cond_init(pthread_cond_t *, + const pthread_condattr_t *); +int pthread_cond_signal(pthread_cond_t *); +int pthread_cond_timedwait(pthread_cond_t *, + pthread_mutex_t *, const struct timespec *); +int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *); +int pthread_create(pthread_t *, const pthread_attr_t *, + void *(*) (void *), void *); +int pthread_detach(pthread_t); +int pthread_equal(pthread_t, pthread_t); +__dead void pthread_exit(void *); +void *pthread_getspecific(pthread_key_t); +int pthread_join(pthread_t, void **); +int pthread_key_create(pthread_key_t *, + void (*) (void *)); +int pthread_key_delete(pthread_key_t); +int pthread_kill(pthread_t, int); +int pthread_mutexattr_init(pthread_mutexattr_t *); +int pthread_mutexattr_destroy(pthread_mutexattr_t *); +int pthread_mutexattr_gettype(pthread_mutexattr_t *, int *); +int pthread_mutexattr_settype(pthread_mutexattr_t *, int); +int pthread_mutex_destroy(pthread_mutex_t *); +int pthread_mutex_init(pthread_mutex_t *, + const pthread_mutexattr_t *); +int pthread_mutex_lock(pthread_mutex_t *); +int pthread_mutex_timedlock(pthread_mutex_t *, + const struct timespec *); +int pthread_mutex_trylock(pthread_mutex_t *); +int pthread_mutex_unlock(pthread_mutex_t *); +int pthread_once(pthread_once_t *, void (*) (void)); +int pthread_rwlock_destroy(pthread_rwlock_t *); +int pthread_rwlock_init(pthread_rwlock_t *, + const pthread_rwlockattr_t *); +int pthread_rwlock_rdlock(pthread_rwlock_t *); +int pthread_rwlock_timedrdlock(pthread_rwlock_t *, + const struct timespec *); +int pthread_rwlock_timedwrlock(pthread_rwlock_t *, + const struct timespec *); +int pthread_rwlock_tryrdlock(pthread_rwlock_t *); +int pthread_rwlock_trywrlock(pthread_rwlock_t *); +int pthread_rwlock_unlock(pthread_rwlock_t *); +int pthread_rwlock_wrlock(pthread_rwlock_t *); +int pthread_rwlockattr_init(pthread_rwlockattr_t *); +int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *, + int *); +int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int); +int pthread_rwlockattr_destroy(pthread_rwlockattr_t *); +pthread_t pthread_self(void); +int pthread_setspecific(pthread_key_t, const void *); + +int pthread_cancel(pthread_t); +int pthread_setcancelstate(int, int *); +int pthread_setcanceltype(int, int *); +void pthread_testcancel(void); + +int pthread_getprio(pthread_t); +int pthread_setprio(pthread_t, int); +void pthread_yield(void); + +int pthread_mutexattr_getprioceiling(pthread_mutexattr_t *, + int *); +int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *, + int); +int pthread_mutex_getprioceiling(pthread_mutex_t *, int *); +int pthread_mutex_setprioceiling(pthread_mutex_t *, int, int *); + +int pthread_mutexattr_getprotocol(pthread_mutexattr_t *, int *); +int pthread_mutexattr_setprotocol(pthread_mutexattr_t *, int); + +int pthread_condattr_getclock(const pthread_condattr_t *, + clockid_t *); +int pthread_condattr_setclock(pthread_condattr_t *, clockid_t); + +int pthread_attr_getinheritsched(const pthread_attr_t *, int *); +int pthread_attr_getschedparam(const pthread_attr_t *, + struct sched_param *); +int pthread_attr_getschedpolicy(const pthread_attr_t *, int *); +int pthread_attr_getscope(const pthread_attr_t *, int *); +int pthread_attr_setinheritsched(pthread_attr_t *, int); +int pthread_attr_setschedparam(pthread_attr_t *, + const struct sched_param *); +int pthread_attr_setschedpolicy(pthread_attr_t *, int); +int pthread_attr_setscope(pthread_attr_t *, int); +int pthread_getschedparam(pthread_t pthread, int *, + struct sched_param *); +int pthread_setschedparam(pthread_t, int, + const struct sched_param *); +int pthread_getconcurrency(void); +int pthread_setconcurrency(int); +int pthread_barrier_init(pthread_barrier_t *, + pthread_barrierattr_t *, unsigned int); +int pthread_barrier_destroy(pthread_barrier_t *); +int pthread_barrier_wait(pthread_barrier_t *); +int pthread_barrierattr_init(pthread_barrierattr_t *); +int pthread_barrierattr_destroy(pthread_barrierattr_t *); +int pthread_barrierattr_getpshared(pthread_barrierattr_t *, int *); +int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int); +int pthread_spin_init(pthread_spinlock_t *, int); +int pthread_spin_destroy(pthread_spinlock_t *); +int pthread_spin_trylock(pthread_spinlock_t *); +int pthread_spin_lock(pthread_spinlock_t *); +int pthread_spin_unlock(pthread_spinlock_t *); + +#if __POSIX_VISIBLE >= 200112 +int pthread_getcpuclockid(pthread_t, clockid_t *); +#endif +__END_DECLS + +#endif /* _PTHREAD_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/pthread_np.h b/lib/libc/include/generic-openbsd/pthread_np.h new file mode 100644 index 0000000000..3e22985498 --- /dev/null +++ b/lib/libc/include/generic-openbsd/pthread_np.h @@ -0,0 +1,56 @@ +/* $OpenBSD: pthread_np.h,v 1.3 2019/05/28 10:33:03 jca Exp $ */ +/* + * Copyright (c) 1996-98 John Birrell . + * 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 John Birrell. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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 _PTHREAD_NP_H_ +#define _PTHREAD_NP_H_ + +#include + +/* + * Non-POSIX type definitions: + */ +typedef void (*pthread_switch_routine_t)(pthread_t, pthread_t); + +/* + * Non-POSIX thread function prototype definitions: + */ +__BEGIN_DECLS +int pthread_mutexattr_getkind_np(pthread_mutexattr_t); +int pthread_mutexattr_setkind_np(pthread_mutexattr_t *, int); +void pthread_get_name_np(pthread_t, char *, size_t); +void pthread_set_name_np(pthread_t, const char *); +int pthread_stackseg_np(pthread_t, stack_t *); +int pthread_main_np(void); +__END_DECLS + +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/pwd.h b/lib/libc/include/generic-openbsd/pwd.h new file mode 100644 index 0000000000..e94e06937c --- /dev/null +++ b/lib/libc/include/generic-openbsd/pwd.h @@ -0,0 +1,119 @@ +/* $OpenBSD: pwd.h,v 1.26 2018/09/13 12:31:15 millert Exp $ */ +/* $NetBSD: pwd.h,v 1.9 1996/05/15 21:36:45 jtc Exp $ */ + +/*- + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * Portions Copyright(C) 1995, 1996, Jason Downs. 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. + * + * @(#)pwd.h 8.2 (Berkeley) 1/21/94 + */ + +#ifndef _PWD_H_ +#define _PWD_H_ + +#include + +#if __BSD_VISIBLE +#define _PATH_PASSWD "/etc/passwd" +#define _PATH_MASTERPASSWD "/etc/master.passwd" +#define _PATH_MASTERPASSWD_LOCK "/etc/ptmp" + +#define _PATH_MP_DB "/etc/pwd.db" +#define _PATH_SMP_DB "/etc/spwd.db" + +#define _PATH_PWD_MKDB "/usr/sbin/pwd_mkdb" + +#define _PW_KEYBYNAME '1' /* stored by name */ +#define _PW_KEYBYNUM '2' /* stored by entry in the "file" */ +#define _PW_KEYBYUID '3' /* stored by uid */ + +#define _PW_YPTOKEN "__YP!" + +#define _PASSWORD_EFMT1 '_' /* extended encryption format */ + +#define _PASSWORD_LEN 128 /* max length, not counting NUL */ +#define _PW_NAME_LEN 31 /* max length, not counting NUL */ + /* Should be MAXLOGNAME - 1 */ +#define _PW_BUF_LEN 1024 /* length of getpw*_r buffer */ + +#define _PASSWORD_NOUID 0x01 /* flag for no specified uid. */ +#define _PASSWORD_NOGID 0x02 /* flag for no specified gid. */ +#define _PASSWORD_NOCHG 0x04 /* flag for no specified change. */ +#define _PASSWORD_NOEXP 0x08 /* flag for no specified expire. */ + +/* Flags for pw_mkdb(3) */ +#define _PASSWORD_SECUREONLY 0x01 /* only generate spwd.db file */ +#define _PASSWORD_OMITV7 0x02 /* don't generate v7 passwd file */ + +#endif + +struct passwd { + char *pw_name; /* user name */ + char *pw_passwd; /* encrypted password */ + uid_t pw_uid; /* user uid */ + gid_t pw_gid; /* user gid */ + time_t pw_change; /* password change time */ + char *pw_class; /* user access class */ + char *pw_gecos; /* Honeywell login info */ + char *pw_dir; /* home directory */ + char *pw_shell; /* default shell */ + time_t pw_expire; /* account expiration */ +}; + +__BEGIN_DECLS +struct passwd *getpwuid(uid_t); +struct passwd *getpwnam(const char *); +struct passwd *getpwuid_shadow(uid_t); +struct passwd *getpwnam_shadow(const char *); +int getpwnam_r(const char *, struct passwd *, char *, size_t, + struct passwd **); +int getpwuid_r(uid_t, struct passwd *, char *, size_t, + struct passwd **); +#if __BSD_VISIBLE || __XPG_VISIBLE +struct passwd *getpwent(void); +void setpwent(void); +void endpwent(void); +#endif +#if __BSD_VISIBLE +int setpassent(int); +int uid_from_user(const char *, uid_t *); +const char *user_from_uid(uid_t, int); +char *bcrypt_gensalt(u_int8_t); +char *bcrypt(const char *, const char *); +int bcrypt_newhash(const char *, int, char *, size_t); +int bcrypt_checkpass(const char *, const char *); +struct passwd *pw_dup(const struct passwd *); +#endif +__END_DECLS + +#endif /* !_PWD_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/radius.h b/lib/libc/include/generic-openbsd/radius.h new file mode 100644 index 0000000000..482f1cf07c --- /dev/null +++ b/lib/libc/include/generic-openbsd/radius.h @@ -0,0 +1,572 @@ +/* $OpenBSD: radius.h,v 1.7 2024/06/29 11:50:31 yasuoka Exp $ */ + +/*- + * Copyright (c) 2009 Internet Initiative Japan Inc. + * 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 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 AUTHOR 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 _RADIUS_H +#define _RADIUS_H + +#define RADIUS_DEFAULT_PORT 1812 +#define RADIUS_ACCT_DEFAULT_PORT 1813 +#define RADIUS_DAE_DEFAULT_PORT 3799 + +/* RADIUS codes */ +#define RADIUS_CODE_ACCESS_REQUEST 1 +#define RADIUS_CODE_ACCESS_ACCEPT 2 +#define RADIUS_CODE_ACCESS_REJECT 3 +#define RADIUS_CODE_ACCOUNTING_REQUEST 4 +#define RADIUS_CODE_ACCOUNTING_RESPONSE 5 +#define RADIUS_CODE_ACCESS_CHALLENGE 11 +#define RADIUS_CODE_STATUS_SERVER 12 +#define RADIUS_CODE_STATUS_CLIENT 13 + +#define RADIUS_CODE_DISCONNECT_REQUEST 40 +#define RADIUS_CODE_DISCONNECT_ACK 41 +#define RADIUS_CODE_DISCONNECT_NAK 42 +#define RADIUS_CODE_COA_REQUEST 43 +#define RADIUS_CODE_COA_ACK 44 +#define RADIUS_CODE_COA_NAK 45 + +/* RADIUS attributes */ +#define RADIUS_TYPE_USER_NAME 1 +#define RADIUS_TYPE_USER_PASSWORD 2 +#define RADIUS_TYPE_CHAP_PASSWORD 3 +#define RADIUS_TYPE_NAS_IP_ADDRESS 4 +#define RADIUS_TYPE_NAS_PORT 5 +#define RADIUS_TYPE_SERVICE_TYPE 6 +#define RADIUS_TYPE_FRAMED_PROTOCOL 7 +#define RADIUS_TYPE_FRAMED_IP_ADDRESS 8 +#define RADIUS_TYPE_FRAMED_IP_NETMASK 9 +#define RADIUS_TYPE_FRAMED_ROUTING 10 +#define RADIUS_TYPE_FILTER_ID 11 +#define RADIUS_TYPE_FRAMED_MTU 12 +#define RADIUS_TYPE_FRAMED_COMPRESSION 13 +#define RADIUS_TYPE_LOGIN_IP_HOST 14 +#define RADIUS_TYPE_LOGIN_SERVICE 15 +#define RADIUS_TYPE_LOGIN_TCP_PORT 16 +/* unassigned 17 */ +#define RADIUS_TYPE_REPLY_MESSAGE 18 +#define RADIUS_TYPE_CALLBACK_NUMBER 19 +#define RADIUS_TYPE_CALLBACK_ID 20 +/* unassigned 21 */ +#define RADIUS_TYPE_FRAMED_ROUTE 22 +#define RADIUS_TYPE_FRAMED_IPX_NETWORK 23 +#define RADIUS_TYPE_STATE 24 +#define RADIUS_TYPE_CLASS 25 +#define RADIUS_TYPE_VENDOR_SPECIFIC 26 +#define RADIUS_TYPE_SESSION_TIMEOUT 27 +#define RADIUS_TYPE_IDLE_TIMEOUT 28 +#define RADIUS_TYPE_TERMINATION_ACTION 29 +#define RADIUS_TYPE_CALLED_STATION_ID 30 +#define RADIUS_TYPE_CALLING_STATION_ID 31 +#define RADIUS_TYPE_NAS_IDENTIFIER 32 +#define RADIUS_TYPE_PROXY_STATE 33 +#define RADIUS_TYPE_LOGIN_LAT_SERVICE 34 +#define RADIUS_TYPE_LOGIN_LAT_NODE 35 +#define RADIUS_TYPE_LOGIN_LAT_GROUP 36 +#define RADIUS_TYPE_FRAMED_APPLETALK_LINK 37 +#define RADIUS_TYPE_FRAMED_APPLETALK_NETWORK 38 +#define RADIUS_TYPE_FRAMED_APPLETALK_ZONE 39 +#define RADIUS_TYPE_ACCT_STATUS_TYPE 40 +#define RADIUS_TYPE_ACCT_DELAY_TIME 41 +#define RADIUS_TYPE_ACCT_INPUT_OCTETS 42 +#define RADIUS_TYPE_ACCT_OUTPUT_OCTETS 43 +#define RADIUS_TYPE_ACCT_SESSION_ID 44 +#define RADIUS_TYPE_ACCT_AUTHENTIC 45 +#define RADIUS_TYPE_ACCT_SESSION_TIME 46 +#define RADIUS_TYPE_ACCT_INPUT_PACKETS 47 +#define RADIUS_TYPE_ACCT_OUTPUT_PACKETS 48 +#define RADIUS_TYPE_ACCT_TERMINATE_CAUSE 49 +#define RADIUS_TYPE_ACCT_MULTI_SESSION_ID 50 +#define RADIUS_TYPE_ACCT_LINK_COUNT 51 +#define RADIUS_TYPE_ACCT_INPUT_GIGAWORDS 52 +#define RADIUS_TYPE_ACCT_OUTPUT_GIGAWORDS 53 +/* unassigned (for accounting) 54 */ +#define RADIUS_TYPE_EVENT_TIMESTAMP 55 +/* unassigned (for accounting) 56 */ +/* unassigned (for accounting) 57 */ +/* unassigned (for accounting) 58 */ +/* unassigned (for accounting) 59 */ +#define RADIUS_TYPE_CHAP_CHALLENGE 60 +#define RADIUS_TYPE_NAS_PORT_TYPE 61 +#define RADIUS_TYPE_PORT_LIMIT 62 +#define RADIUS_TYPE_LOGIN_LAT_PORT 63 +#define RADIUS_TYPE_TUNNEL_TYPE 64 +#define RADIUS_TYPE_TUNNEL_MEDIUM_TYPE 65 +#define RADIUS_TYPE_TUNNEL_CLIENT_ENDPOINT 66 +#define RADIUS_TYPE_TUNNEL_SERVER_ENDPOINT 67 +#define RADIUS_TYPE_ACCT_TUNNEL_CONNECTION 68 +#define RADIUS_TYPE_TUNNEL_PASSWORD 69 +#define RADIUS_TYPE_ARAP_PASSWORD 70 +#define RADIUS_TYPE_ARAP_FEATURES 71 +#define RADIUS_TYPE_ARAP_ZONE_ACCESS 72 +#define RADIUS_TYPE_ARAP_SECURITY 73 +#define RADIUS_TYPE_ARAP_SECURITY_DATA 74 +#define RADIUS_TYPE_PASSWORD_RETRY 75 +#define RADIUS_TYPE_PROMPT 76 +#define RADIUS_TYPE_CONNECT_INFO 77 +#define RADIUS_TYPE_CONFIGURATION_TOKEN 78 +#define RADIUS_TYPE_EAP_MESSAGE 79 +#define RADIUS_TYPE_MESSAGE_AUTHENTICATOR 80 +#define RADIUS_TYPE_TUNNEL_PRIVATE_GROUP_ID 81 +#define RADIUS_TYPE_TUNNEL_ASSIGNMENT_ID 82 +#define RADIUS_TYPE_TUNNEL_PREFERENCE 83 +#define RADIUS_TYPE_ARAP_CHALLENGE_RESPONSE 84 +#define RADIUS_TYPE_ACCT_INTERIM_INTERVAL 85 +#define RADIUS_TYPE_ACCT_TUNNEL_PACKETS_LOST 86 +#define RADIUS_TYPE_NAS_PORT_ID 87 +#define RADIUS_TYPE_FRAMED_POOL 88 +/* unassigned 89 */ +#define RADIUS_TYPE_TUNNEL_CLIENT_AUTH_ID 90 +#define RADIUS_TYPE_TUNNEL_SERVER_AUTH_ID 91 +/* unassigned 92-94 */ +#define RADIUS_TYPE_NAS_IPV6_ADDRESS 95 +#define RADIUS_TYPE_FRAMED_INTERFACE_ID 96 +#define RADIUS_TYPE_FRAMED_IPV6_PREFIX 97 +#define RADIUS_TYPE_LOGIN_IPV6_HOST 98 +#define RADIUS_TYPE_FRAMED_IPV6_ROUTE 99 +#define RADIUS_TYPE_FRAMED_IPV6_POOL 100 + +/* RFC 5176 3.5. Error-Cause */ +#define RADIUS_TYPE_ERROR_CAUSE 101 + +/* RFC 6911 3. Attributes */ +#define RADIUS_TYPE_FRAMED_IPV6_ADDRESS 168 +#define RADIUS_TYPE_DNS_SERVER_IPV6_ADDRESS 169 +#define RADIUS_TYPE_ROUTE_IPV6_INFORMATION 170 +#define RADIUS_TYPE_DELEGATED_IPV6_PREFIX_POOL 171 +#define RADIUS_TYPE_STATEFUL_IPV6_ADDRESS_POOL 172 + + +/* RFC 2865 5.7. Framed-Protocol */ +#define RADIUS_FRAMED_PROTOCOL_PPP 1 /* PPP */ +#define RADIUS_FRAMED_PROTOCOL_SLIP 2 /* SLIP */ +#define RADIUS_FRAMED_PROTOCOL_ARAP 3 /* AppleTalk Remote Access + * Protocol (ARAP) */ +#define RADIUS_FRAMED_PROTOCOL_GANDALF 4 /* Gandalf proprietary + * SingleLink/MultiLink + * protocol */ +#define RADIUS_FRAMED_PROTOCOL_XYLOGICS 5 /* Xylogics proprietary + * IPX/SLIP */ +#define RADIUS_FRAMED_PROTOCOL_X75 6 /* X.75 Synchronous */ + + +/* RFC 2865 5.6. Service-Type */ +#define RADIUS_SERVICE_TYPE_LOGIN 1 +#define RADIUS_SERVICE_TYPE_FRAMED 2 +#define RADIUS_SERVICE_TYPE_CB_LOGIN 3 +#define RADIUS_SERVICE_TYPE_CB_FRAMED 4 +#define RADIUS_SERVICE_TYPE_OUTBOUND 5 +#define RADIUS_SERVICE_TYPE_ADMINISTRATIVE 6 +#define RADIUS_SERVICE_TYPE_NAS_PROMPT 7 +#define RADIUS_SERVICE_TYPE_AUTHENTICAT_ONLY 8 +#define RADIUS_SERVICE_TYPE_CB_NAS_PROMPT 9 +#define RADIUS_SERVICE_TYPE_CALL_CHECK 10 +#define RADIUS_SERVICE_TYPE_CB_ADMINISTRATIVE 11 + + +/* Microsoft vendor specific attributes: see RFC2548*/ +#define RADIUS_VENDOR_MICROSOFT 311 +#define RADIUS_VTYPE_MS_CHAP_RESPONSE 1 +#define RADIUS_VTYPE_MS_CHAP_ERROR 2 +#define RADIUS_VTYPE_MS_CHAP_PW_1 3 +#define RADIUS_VTYPE_MS_CHAP_PW_2 4 +#define RADIUS_VTYPE_MS_CHAP_LM_ENC_PW 5 +#define RADIUS_VTYPE_MS_CHAP_NT_ENC_PW 6 +#define RADIUS_VTYPE_MPPE_ENCRYPTION_POLICY 7 +#define RADIUS_VTYPE_MPPE_ENCRYPTION_TYPES 8 +#define RADIUS_VTYPE_MS_RAS_VENDOR 9 +#define RADIUS_VTYPE_MS_CHAP_CHALLENGE 11 +#define RADIUS_VTYPE_MS_CHAP_MPPE_KEYS 12 +#define RADIUS_VTYPE_MS_BAP_USAGE 13 +#define RADIUS_VTYPE_MS_LINK_UTILIZATION_THRESHOLD 14 +#define RADIUS_VTYPE_MS_LINK_DROP_TIME_LIMIT 15 +#define RADIUS_VTYPE_MPPE_SEND_KEY 16 +#define RADIUS_VTYPE_MPPE_RECV_KEY 17 +#define RADIUS_VTYPE_MS_RAS_VERSION 18 +#define RADIUS_VTYPE_MS_OLD_ARAP_PASSWORD 19 +#define RADIUS_VTYPE_MS_NEW_ARAP_PASSWORD 20 +#define RADIUS_VTYPE_MS_ARAP_PASSWORD_CHANGE_REASON 21 +#define RADIUS_VTYPE_MS_FILTER 22 +#define RADIUS_VTYPE_MS_ACCT_AUTH_TYPE 23 +#define RADIUS_VTYPE_MS_ACCT_EAP_TYPE 24 +#define RADIUS_VTYPE_MS_CHAP2_RESPONSE 25 +#define RADIUS_VTYPE_MS_CHAP2_SUCCESS 26 +#define RADIUS_VTYPE_MS_CHAP2_PW 27 +#define RADIUS_VTYPE_MS_PRIMARY_DNS_SERVER 28 +#define RADIUS_VTYPE_MS_SECONDARY_DNS_SERVER 29 +#define RADIUS_VTYPE_MS_PRIMARY_NBNS_SERVER 30 +#define RADIUS_VTYPE_MS_SECONDARY_NBNS_SERVER 31 +/* unassigned? 32 */ +#define RADIUS_VTYPE_MS_ARAP_CHALLENGE 33 + + +/* RFC 2865 5.41. NAS-Port-Type */ +#define RADIUS_NAS_PORT_TYPE_ASYNC 0 /* Async */ +#define RADIUS_NAS_PORT_TYPE_SYNC 1 /* Sync */ +#define RADIUS_NAS_PORT_TYPE_ISDN_SYNC 2 /* ISDN Sync */ +#define RADIUS_NAS_PORT_TYPE_ISDN_ASYNC_V120 3 /* ISDN Async V.120 */ +#define RADIUS_NAS_PORT_TYPE_ISDN_ASYNC_V110 4 /* ISDN Async V.110 */ +#define RADIUS_NAS_PORT_TYPE_VIRTUAL 5 /* Virtual */ +#define RADIUS_NAS_PORT_TYPE_PIAFS 6 /* PIAFS */ +#define RADIUS_NAS_PORT_TYPE_HDLC_CLEAR_CHANNEL 7 /* HDLC Clear Channel */ +#define RADIUS_NAS_PORT_TYPE_X_25 8 /* X.25 */ +#define RADIUS_NAS_PORT_TYPE_X_75 9 /* X.75 */ +#define RADIUS_NAS_PORT_TYPE_G3_FAX 10 /* G.3 Fax */ +#define RADIUS_NAS_PORT_TYPE_SDSL 11 /* SDSL - Symmetric DSL */ +#define RADIUS_NAS_PORT_TYPE_ADSL_CAP 12 /* ADSL-CAP - Asymmetric + * DSL, Carrierless + * Amplitude Phase + * Modulation */ +#define RADIUS_NAS_PORT_TYPE_ADSL_DMT 13 /* ADSL-DMT - Asymmetric + * DSL, Discrete + * Multi-Tone */ +#define RADIUS_NAS_PORT_TYPE_IDSL 14 /* IDSL - ISDN Digital + * Subscriber Line */ +#define RADIUS_NAS_PORT_TYPE_ETHERNET 15 /* Ethernet */ +#define RADIUS_NAS_PORT_TYPE_XDSL 16 /* xDSL - Digital + * Subscriber Line of + * unknown type */ +#define RADIUS_NAS_PORT_TYPE_CABLE 17 /* Cable */ +#define RADIUS_NAS_PORT_TYPE_WIRELESS 18 /* Wireless - Other */ +#define RADIUS_NAS_PORT_TYPE_WIRELESS_802_11 19 /* Wireless - IEEE + * 802.11 */ + + +/* RFC 2866 5.1. Acct-Status-Type */ +#define RADIUS_ACCT_STATUS_TYPE_START 1 /* Start */ +#define RADIUS_ACCT_STATUS_TYPE_STOP 2 /* Stop */ +#define RADIUS_ACCT_STATUS_TYPE_INTERIM_UPDATE 3 /* Interim-Update */ +#define RADIUS_ACCT_STATUS_TYPE_ACCT_ON 7 /* Accounting-On */ +#define RADIUS_ACCT_STATUS_TYPE_ACCT_OFF 8 /* Accounting-Off */ + + +/* RFC 2866 5.6. Acct-Authentic */ +#define RADIUS_ACCT_AUTHENTIC_RADIUS 1 /* RADIUS */ +#define RADIUS_ACCT_AUTHENTIC_LOCAL 2 /* Local */ +#define RADIUS_ACCT_AUTHENTIC_REMOTE 3 /* Remote */ + + +/* RFC 2866 5.10. Acct-Terminate-Cause */ +#define RADIUS_TERMNATE_CAUSE_USER_REQUEST 1 /* User Request */ +#define RADIUS_TERMNATE_CAUSE_LOST_CARRIER 2 /* Lost Carrier */ +#define RADIUS_TERMNATE_CAUSE_LOST_SERVICE 3 /* Lost Service */ +#define RADIUS_TERMNATE_CAUSE_IDLE_TIMEOUT 4 /* Idle Timeout */ +#define RADIUS_TERMNATE_CAUSE_SESSION_TIMEOUT 5 /* Session Timeout */ +#define RADIUS_TERMNATE_CAUSE_ADMIN_RESET 6 /* Admin Reset */ +#define RADIUS_TERMNATE_CAUSE_ADMIN_REBOOT 7 /* Admin Reboot */ +#define RADIUS_TERMNATE_CAUSE_PORT_ERROR 8 /* Port Error */ +#define RADIUS_TERMNATE_CAUSE_NAS_ERROR 9 /* NAS Error */ +#define RADIUS_TERMNATE_CAUSE_NAS_RESET 10 /* NAS Request */ +#define RADIUS_TERMNATE_CAUSE_NAS_REBOOT 11 /* NAS Reboot */ +#define RADIUS_TERMNATE_CAUSE_PORT_UNNEEDED 12 /* Port Unneeded */ +#define RADIUS_TERMNATE_CAUSE_PORT_PREEMPTED 13 /* Port Preempted */ +#define RADIUS_TERMNATE_CAUSE_PORT_SUSPENDED 14 /* Port Suspended */ +#define RADIUS_TERMNATE_CAUSE_SERVICE_UNAVAIL 15 /* Service Unavailable */ +#define RADIUS_TERMNATE_CAUSE_CALLBACK 16 /* Callback */ +#define RADIUS_TERMNATE_CAUSE_USER_ERROR 17 /* User Error */ +#define RADIUS_TERMNATE_CAUSE_HOST_REQUEST 18 /* Host Request */ + + +/* RFC 2868 3.1. Tunnel-Type */ +#define RADIUS_TUNNEL_TYPE_PPTP 1 /* Point-to-Point Tunneling + * Protocol (PPTP) */ +#define RADIUS_TUNNEL_TYPE_L2F 2 /* Layer Two Forwarding (L2F) */ +#define RADIUS_TUNNEL_TYPE_L2TP 3 /* Layer Two Tunneling + * Protocol (L2TP) */ +#define RADIUS_TUNNEL_TYPE_ATMP 4 /* Ascend Tunnel Management + * Protocol (ATMP) */ +#define RADIUS_TUNNEL_TYPE_VTP 5 /* Virtual Tunneling Protocol + * (VTP) */ +#define RADIUS_TUNNEL_TYPE_AH 6 /* IP Authentication Header in + * the Tunnel-mode (AH) */ +#define RADIUS_TUNNEL_TYPE_IP 7 /* IP-in-IP Encapsulation + * (IP-IP) */ +#define RADIUS_TUNNEL_TYPE_MOBILE 8 /* Minimal IP-in-IP + * Encapsulation (MIN-IP-IP) */ +#define RADIUS_TUNNEL_TYPE_ESP 9 /* IP Encapsulating Security + * Payload in the Tunnel-mode + * (ESP) */ +#define RADIUS_TUNNEL_TYPE_GRE 10 /* Generic Route Encapsulation + * (GRE) */ +#define RADIUS_TUNNEL_TYPE_VDS 11 /* Bay Dial Virtual Services + * (DVS) */ +#define RADIUS_TUNNEL_TYPE_IPIP 12 /* IP-in-IP Tunneling */ + + +/* RFC 2868 3.2. Tunnel-Medium-Type */ +#define RADIUS_TUNNEL_MEDIUM_TYPE_IPV4 1 /* IPv4 (IP version 4) */ +#define RADIUS_TUNNEL_MEDIUM_TYPE_IPV6 2 /* IPv6 (IP version 6) */ +#define RADIUS_TUNNEL_MEDIUM_TYPE_NSAP 3 /* NSAP */ +#define RADIUS_TUNNEL_MEDIUM_TYPE_HDLC 4 /* HDLC (8-bit + * multidrop) */ +#define RADIUS_TUNNEL_MEDIUM_TYPE_BBN1822 5 /* BBN 1822 */ +#define RADIUS_TUNNEL_MEDIUM_TYPE_802 6 /* 802 (includes all 802 + * media plus Ethernet + * "canonical format")*/ +#define RADIUS_TUNNEL_MEDIUM_TYPE_E163 7 /* E.163 (POTS) */ +#define RADIUS_TUNNEL_MEDIUM_TYPE_E164 8 /* E.164 (SMDS, Frame + * Relay, ATM) */ +/* RFC 5167 3.5. Error-Cause */ +/* Residual Session Context Removed */ +#define RADIUS_ERROR_CAUSE_RESIDUAL_SESSION_REMOVED 201 +/* Invalid EAP Packet (Ignored) */ +#define RADIUS_ERROR_CAUSE_INVALID_EAP_PACKET 202 +/* Unsupported Attribute */ +#define RADIUS_ERROR_CAUSE_UNSUPPORTED_ATTRIBUTE 401 +/* Missing Attribute */ +#define RADIUS_ERROR_CAUSE_MISSING_ATTRIBUTE 402 +/* NAS Identification Mismatch */ +#define RADIUS_ERROR_CAUSE_NAS_IDENTIFICATION_MISMATCH 403 +/* Invalid Request */ +#define RADIUS_ERROR_CAUSE_INVALID_REQUEST 404 +/* Unsupported Service */ +#define RADIUS_ERROR_CAUSE_UNSUPPORTED_SERVICE 405 +/* Unsupported Extension */ +#define RADIUS_ERROR_CAUSE_UNSUPPORTED_EXTENSION 406 +/* Invalid Attribute Valu */ +#define RADIUS_ERROR_CAUSE_INVALID_ATTRIBUTE_VALUE 407 +/* Administratively Prohibited */ +#define RADIUS_ERROR_CAUSE_ADMINISTRATIVELY_PROHIBITED 501 +/* Request Not Routable (Proxy) */ +#define RADIUS_ERROR_CAUSE_REQUEST_NOT_ROUTABLE 502 +/* Session Context Not Found */ +#define RADIUS_ERROR_CAUSE_SESSION_NOT_FOUND 503 +/* Session Context Not Removable */ +#define RADIUS_ERROR_CAUSE_SESSION_NOT_REMOVABLE 504 +/* Other Proxy Processing Error */ +#define RADIUS_ERROR_CAUSE_OTHER_PROXY_PROCESSING_ERROR 505 +/* Resources Unavailable */ +#define RADIUS_ERROR_CAUSE_RESOURCES_UNAVAILABLE 506 +/* Request Initiated */ +#define RADIUS_ERROR_CAUSE_REQUEST_INITIATED 507 +/* Multiple Session Selection Unsupported */ +#define RADIUS_ERROR_CAUSE_MULTI_SELECTION_UNSUPPORTED 508 + +#include +#include + +#include +#include + +struct in_addr; +struct in6_addr; + +__BEGIN_DECLS + +/******* packet manipulation support *******/ + +typedef struct _RADIUS_PACKET RADIUS_PACKET; + +/* constructors */ +RADIUS_PACKET *radius_new_request_packet(uint8_t); +RADIUS_PACKET *radius_new_response_packet(uint8_t, const RADIUS_PACKET *); +RADIUS_PACKET *radius_convert_packet(const void *, size_t); + +/* destructor */ +int radius_delete_packet(RADIUS_PACKET *); + +/* accessors - header values */ +uint8_t radius_get_id(const RADIUS_PACKET *); +void radius_update_id(RADIUS_PACKET * packet); +void radius_set_id(RADIUS_PACKET *, uint8_t); +uint8_t radius_get_code(const RADIUS_PACKET *); +void radius_get_authenticator(const RADIUS_PACKET *, void *); +void radius_set_request_packet(RADIUS_PACKET *, + const RADIUS_PACKET *); +const RADIUS_PACKET * + radius_get_request_packet(const RADIUS_PACKET *); +int radius_check_response_authenticator(const RADIUS_PACKET *, + const char *); +int radius_check_accounting_request_authenticator( + const RADIUS_PACKET *, const char *); +uint8_t *radius_get_authenticator_retval(const RADIUS_PACKET *); +uint8_t *radius_get_request_authenticator_retval(const RADIUS_PACKET *); +void radius_set_accounting_request_authenticator(RADIUS_PACKET *, + const char *); +void radius_set_response_authenticator(RADIUS_PACKET *, + const char *); +uint16_t radius_get_length(const RADIUS_PACKET *); +const void *radius_get_data(const RADIUS_PACKET *); + +int radius_get_raw_attr(const RADIUS_PACKET *, uint8_t, void *, + size_t *); +int radius_get_vs_raw_attr(const RADIUS_PACKET *, uint32_t, + uint8_t, void *, size_t *); +int radius_put_raw_attr(RADIUS_PACKET *, uint8_t, const void *, + size_t); +int radius_put_vs_raw_attr(RADIUS_PACKET *, uint32_t, uint8_t, + const void *, size_t); +int radius_get_raw_attr_ptr(const RADIUS_PACKET *, uint8_t, + const void **, size_t *); +int radius_get_vs_raw_attr_ptr(const RADIUS_PACKET *, uint32_t, + uint8_t, const void **, size_t *); +int radius_get_raw_attr_cat(const RADIUS_PACKET *, uint8_t, + void *, size_t *); +int radius_get_vs_raw_attr_cat(const RADIUS_PACKET *, uint32_t, + uint8_t, void *, size_t *); +int radius_put_raw_attr_cat(RADIUS_PACKET *, uint8_t, + const void *, size_t); +int radius_put_vs_raw_attr_cat(RADIUS_PACKET *, uint32_t, uint8_t, + const void *, size_t); +int radius_set_raw_attr(RADIUS_PACKET *, uint8_t, const void *, + size_t); +int radius_set_vs_raw_attr(RADIUS_PACKET *, uint32_t, uint8_t, + const void *, size_t); + +int radius_del_attr_all(RADIUS_PACKET *, uint8_t); +int radius_del_vs_attr_all(RADIUS_PACKET *, uint32_t, uint8_t); + +bool radius_has_attr(const RADIUS_PACKET *, uint8_t); +bool radius_has_vs_attr(const RADIUS_PACKET *, uint32_t, uint8_t); + +/* typed attribute accessor (string) */ +int radius_get_string_attr(const RADIUS_PACKET *, uint8_t, char *, + size_t); +int radius_get_vs_string_attr(const RADIUS_PACKET *, uint32_t, + uint8_t, char *, size_t); +int radius_put_string_attr(RADIUS_PACKET *, uint8_t, const char *); +int radius_put_vs_string_attr(RADIUS_PACKET *, uint32_t, uint8_t, + const char *); + +/* typed attribute accessor (uint16_t) */ +int radius_get_uint16_attr(const RADIUS_PACKET *, + uint8_t, uint16_t *); +int radius_get_vs_uint16_attr(const RADIUS_PACKET *, + uint32_t, uint8_t, uint16_t *); +int radius_put_uint16_attr(RADIUS_PACKET *, + uint8_t, const uint16_t); +int radius_put_vs_uint16_attr(RADIUS_PACKET *, + uint32_t, uint8_t, const uint16_t); +int radius_set_uint16_attr(RADIUS_PACKET *, + uint8_t, const uint16_t); +int radius_set_vs_uint16_attr(RADIUS_PACKET *, + uint32_t, uint8_t, const uint16_t); + +/* typed attribute accessor (uint32_t) */ +int radius_get_uint32_attr(const RADIUS_PACKET *, + uint8_t, uint32_t *); +int radius_get_vs_uint32_attr(const RADIUS_PACKET *, + uint32_t, uint8_t, uint32_t *); +int radius_put_uint32_attr(RADIUS_PACKET *, + uint8_t, const uint32_t); +int radius_put_vs_uint32_attr(RADIUS_PACKET *, + uint32_t, uint8_t, const uint32_t); +int radius_set_uint32_attr(RADIUS_PACKET *, + uint8_t, const uint32_t); +int radius_set_vs_uint32_attr(RADIUS_PACKET *, + uint32_t, uint8_t, const uint32_t); + +/* typed attribute accessor (uint64_t) */ +int radius_get_uint64_attr(const RADIUS_PACKET *, + uint8_t, uint64_t *); +int radius_get_vs_uint64_attr(const RADIUS_PACKET *, + uint32_t, uint8_t, uint64_t *); +int radius_put_uint64_attr(RADIUS_PACKET *, + uint8_t, const uint64_t); +int radius_put_vs_uint64_attr(RADIUS_PACKET *, + uint32_t, uint8_t, const uint64_t); +int radius_set_uint64_attr(RADIUS_PACKET *, + uint8_t, const uint64_t); +int radius_set_vs_uint64_attr(RADIUS_PACKET *, + uint32_t, uint8_t, const uint64_t); + +/* typed attribute accessor (ipv4) */ +int radius_get_ipv4_attr(const RADIUS_PACKET *, + uint8_t, struct in_addr *); +int radius_get_vs_ipv4_attr(const RADIUS_PACKET *, + uint32_t, uint8_t, struct in_addr *); +int radius_put_ipv4_attr(RADIUS_PACKET *, + uint8_t, const struct in_addr); +int radius_put_vs_ipv4_attr(RADIUS_PACKET *, + uint32_t, uint8_t, const struct in_addr); +int radius_set_ipv4_attr(RADIUS_PACKET *, + uint8_t, const struct in_addr); +int radius_set_vs_ipv4_attr(RADIUS_PACKET *, + uint32_t, uint8_t, const struct in_addr); + +/* typed attribute accessor (ipv6) */ +int radius_get_ipv6_attr(const RADIUS_PACKET *, + uint8_t, struct in6_addr *); +int radius_get_vs_ipv6_attr(const RADIUS_PACKET *, + uint32_t, uint8_t, struct in6_addr *); +int radius_put_ipv6_attr(RADIUS_PACKET *, + uint8_t, const struct in6_addr *); +int radius_put_vs_ipv6_attr(RADIUS_PACKET *, + uint32_t, uint8_t, const struct in6_addr *); +int radius_set_ipv6_attr(RADIUS_PACKET *, + uint8_t, const struct in6_addr *); +int radius_set_vs_ipv6_attr(RADIUS_PACKET *, + uint32_t, uint8_t, const struct in6_addr *); + +/* message authenticator */ +int radius_put_message_authenticator(RADIUS_PACKET *, + const char *); +int radius_set_message_authenticator(RADIUS_PACKET *, + const char *); +int radius_check_message_authenticator(RADIUS_PACKET *, + const char *); + +/* encryption */ +int radius_encrypt_user_password_attr(void *, size_t *, + const char *, const void *, const char *); +int radius_decrypt_user_password_attr(char *, size_t, + const void *, size_t, const void *, const char *); +int radius_encrypt_mppe_key_attr(void *, size_t *, + const void *, size_t, const void *, const char *); +int radius_decrypt_mppe_key_attr(void *, size_t *, const void *, + size_t, const void *, const char *); + +/* encrypted attribute */ +int radius_get_user_password_attr(const RADIUS_PACKET *, + char *, size_t, const char *); +int radius_put_user_password_attr(RADIUS_PACKET *, + const char *, const char *); +int radius_get_mppe_send_key_attr(const RADIUS_PACKET *, void *, + size_t *, const char *); +int radius_put_mppe_send_key_attr(RADIUS_PACKET *, + const void *, size_t, const char *); +int radius_get_mppe_recv_key_attr(const RADIUS_PACKET *, + void *, size_t *, const char *); +int radius_put_mppe_recv_key_attr(RADIUS_PACKET *, const void *, + size_t, const char *); + +int radius_get_eap_msk(const RADIUS_PACKET *, void *, size_t *, + const char *); + +/* helpers */ +RADIUS_PACKET *radius_recvfrom(int, int, struct sockaddr *, socklen_t *); +int radius_sendto(int, const RADIUS_PACKET *, int flags, + const struct sockaddr *, socklen_t); +RADIUS_PACKET *radius_recv(int, int); +int radius_send(int, const RADIUS_PACKET *, int); +RADIUS_PACKET *radius_recvmsg(int, struct msghdr *, int); +int radius_sendmsg(int, const RADIUS_PACKET *, + const struct msghdr *, int); + +__END_DECLS + +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ranlib.h b/lib/libc/include/generic-openbsd/ranlib.h new file mode 100644 index 0000000000..2e7d5dc8d6 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ranlib.h @@ -0,0 +1,49 @@ +/* $OpenBSD: ranlib.h,v 1.3 2003/06/02 19:34:12 millert Exp $ */ +/* $NetBSD: ranlib.h,v 1.4 1994/10/26 00:56:14 cgd Exp $ */ + +/*- + * Copyright (c) 1990 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. + * + * @(#)ranlib.h 5.2 (Berkeley) 4/3/91 + */ + +#ifndef _RANLIB_H_ +#define _RANLIB_H_ + +#define RANLIBMAG "__.SYMDEF" /* archive file name */ +#define RANLIBSKEW 3 /* creation time offset */ + +struct ranlib { + union { + long ran_strx; /* string table index */ + char *ran_name; /* in memory symbol name */ + } ran_un; + long ran_off; /* archive file offset */ +}; + +#endif /* !_RANLIB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/readpassphrase.h b/lib/libc/include/generic-openbsd/readpassphrase.h new file mode 100644 index 0000000000..34cdaa411e --- /dev/null +++ b/lib/libc/include/generic-openbsd/readpassphrase.h @@ -0,0 +1,40 @@ +/* $OpenBSD: readpassphrase.h,v 1.6 2019/01/25 00:19:25 millert Exp $ */ + +/* + * Copyright (c) 2000, 2002 Todd C. Miller + * + * 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. + * + * Sponsored in part by the Defense Advanced Research Projects + * Agency (DARPA) and Air Force Research Laboratory, Air Force + * Materiel Command, USAF, under agreement number F39502-99-1-0512. + */ + +#ifndef _READPASSPHRASE_H_ +#define _READPASSPHRASE_H_ + +#define RPP_ECHO_OFF 0x00 /* Turn off echo (default). */ +#define RPP_ECHO_ON 0x01 /* Leave echo on. */ +#define RPP_REQUIRE_TTY 0x02 /* Fail if there is no tty. */ +#define RPP_FORCELOWER 0x04 /* Force input to lower case. */ +#define RPP_FORCEUPPER 0x08 /* Force input to upper case. */ +#define RPP_SEVENBIT 0x10 /* Strip the high bit from input. */ +#define RPP_STDIN 0x20 /* Read from stdin, not /dev/tty */ + +#include + +__BEGIN_DECLS +char * readpassphrase(const char *, char *, size_t, int); +__END_DECLS + +#endif /* !_READPASSPHRASE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/regex.h b/lib/libc/include/generic-openbsd/regex.h new file mode 100644 index 0000000000..7c0763f818 --- /dev/null +++ b/lib/libc/include/generic-openbsd/regex.h @@ -0,0 +1,104 @@ +/* $OpenBSD: regex.h,v 1.7 2012/12/05 23:19:57 deraadt Exp $ */ +/* $NetBSD: regex.h,v 1.4.6.1 1996/06/10 18:57:07 explorer Exp $ */ + +/*- + * Copyright (c) 1992 Henry Spencer. + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Henry Spencer of the University of Toronto. + * + * 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. + * + * @(#)regex.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _REGEX_H_ +#define _REGEX_H_ + +#include + +/* types */ +typedef off_t regoff_t; + +typedef struct { + int re_magic; + size_t re_nsub; /* number of parenthesized subexpressions */ + const char *re_endp; /* end pointer for REG_PEND */ + struct re_guts *re_g; /* none of your business :-) */ +} regex_t; + +typedef struct { + regoff_t rm_so; /* start of match */ + regoff_t rm_eo; /* end of match */ +} regmatch_t; + +/* regcomp() flags */ +#define REG_BASIC 0000 +#define REG_EXTENDED 0001 +#define REG_ICASE 0002 +#define REG_NOSUB 0004 +#define REG_NEWLINE 0010 +#define REG_NOSPEC 0020 +#define REG_PEND 0040 +#define REG_DUMP 0200 + +/* regerror() flags */ +#define REG_NOMATCH 1 +#define REG_BADPAT 2 +#define REG_ECOLLATE 3 +#define REG_ECTYPE 4 +#define REG_EESCAPE 5 +#define REG_ESUBREG 6 +#define REG_EBRACK 7 +#define REG_EPAREN 8 +#define REG_EBRACE 9 +#define REG_BADBR 10 +#define REG_ERANGE 11 +#define REG_ESPACE 12 +#define REG_BADRPT 13 +#define REG_EMPTY 14 +#define REG_ASSERT 15 +#define REG_INVARG 16 +#define REG_ATOI 255 /* convert name to number (!) */ +#define REG_ITOA 0400 /* convert number to name (!) */ + +/* regexec() flags */ +#define REG_NOTBOL 00001 +#define REG_NOTEOL 00002 +#define REG_STARTEND 00004 +#define REG_TRACE 00400 /* tracing of execution */ +#define REG_LARGE 01000 /* force large representation */ +#define REG_BACKR 02000 /* force use of backref code */ + +__BEGIN_DECLS +int regcomp(regex_t *, const char *, int); +size_t regerror(int, const regex_t *, char *, size_t); +int regexec(const regex_t *, const char *, size_t, regmatch_t [], int); +void regfree(regex_t *); +__END_DECLS + +#endif /* !_REGEX_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/resolv.h b/lib/libc/include/generic-openbsd/resolv.h new file mode 100644 index 0000000000..87b870b028 --- /dev/null +++ b/lib/libc/include/generic-openbsd/resolv.h @@ -0,0 +1,314 @@ +/* $OpenBSD: resolv.h,v 1.23 2021/11/22 20:18:27 jca Exp $ */ + +/* + * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. + * 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 project 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 PROJECT 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 PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * ++Copyright++ 1983, 1987, 1989, 1993 + * - + * Copyright (c) 1983, 1987, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * - + * Portions Copyright (c) 1993 by Digital Equipment Corporation. + * + * 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, and that + * the name of Digital Equipment Corporation not be used in advertising or + * publicity pertaining to distribution of the document or software without + * specific, written prior permission. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT + * CORPORATION 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. + * - + * --Copyright-- + */ + +/* + * @(#)resolv.h 8.1 (Berkeley) 6/2/93 + * $From: resolv.h,v 8.17 1996/11/26 10:11:20 vixie Exp $ + */ + +#ifndef _RESOLV_H_ +#define _RESOLV_H_ + +#include +#include +#include + +/* + * Revision information. This is the release date in YYYYMMDD format. + * It can change every day so the right thing to do with it is use it + * in preprocessor commands such as "#if (__RES > 19931104)". Do not + * compare for equality; rather, use it to determine whether your resolver + * is new enough to contain a certain feature. + */ + +#define __RES 19960801 + +/* + * Resolver configuration file. + * Normally not present, but may contain the address of the + * initial name server(s) to query and the domain search list. + */ + +#ifndef _PATH_RESCONF +#define _PATH_RESCONF "/etc/resolv.conf" +#endif + +/* + * Global defines and variables for resolver stub. + */ +#define MAXNS 3 /* max # name servers we'll track */ +#define MAXDFLSRCH 3 /* # default domain levels to try */ +#define MAXDNSRCH 6 /* max # domains in search path */ +#define LOCALDOMAINPARTS 2 /* min levels in name that is "local" */ +#define MAXDNSLUS 4 /* max # of host lookup types */ + +#define RES_TIMEOUT 5 /* min. seconds between retries */ +#define MAXRESOLVSORT 10 /* number of net to sort on */ +#define RES_MAXNDOTS 15 /* should reflect bit field size */ + +struct __res_state { + int retrans; /* retransmission time interval */ + int retry; /* number of times to retransmit */ + unsigned int options; /* option flags - see below. */ + int nscount; /* number of name servers */ + int family[2]; /* specifies which address + * families will be queried and + * in which order */ + struct sockaddr_in + nsaddr_list[MAXNS]; /* address of name server */ +#define nsaddr nsaddr_list[0] /* for backward compatibility */ + unsigned short id; /* current message id */ + char *dnsrch[MAXDNSRCH+1]; /* components of domain to search */ + char defdname[256]; /* default domain (deprecated) */ + unsigned int pfcode; /* RES_PRF_ flags - see below. */ + unsigned ndots:4; /* threshold for initial abs. query */ + unsigned nsort:4; /* number of elements in sort_list[] */ + char unused[3]; + struct { + struct in_addr addr; + u_int32_t mask; + } sort_list[MAXRESOLVSORT]; + char lookups[MAXDNSLUS]; + struct { time_t __res_sec; long __res_nsec; } restimespec; + time_t reschktime; +}; + +#if 1 /* INET6 */ +/* + * replacement of __res_state, separated to keep binary compatibility. + */ +struct __res_state_ext { + struct sockaddr_storage nsaddr_list[MAXNS]; + struct { + int af; /* address family for addr, mask */ + union { + struct in_addr ina; + struct in6_addr in6a; + } addr, mask; + } sort_list[MAXRESOLVSORT]; +}; +#endif + + +/* + * Resolver options (keep these in synch with res_debug.c, please) + */ +#define RES_INIT 0x00000001 /* address initialized */ +#define RES_DEBUG 0x00000002 /* print debug messages */ +#define RES_AAONLY 0x00000004 /* authoritative answers only (!IMPL)*/ +#define RES_USEVC 0x00000008 /* use virtual circuit */ +#define RES_PRIMARY 0x00000010 /* query primary server only (!IMPL) */ +#define RES_IGNTC 0x00000020 /* ignore trucation errors */ +#define RES_RECURSE 0x00000040 /* recursion desired */ +#define RES_DEFNAMES 0x00000080 /* use default domain name */ +#define RES_STAYOPEN 0x00000100 /* Keep TCP socket open */ +#define RES_DNSRCH 0x00000200 /* search up local domain tree */ +#define RES_INSECURE1 0x00000400 /* type 1 security disabled */ +#define RES_INSECURE2 0x00000800 /* type 2 security disabled */ +#define RES_NOALIASES 0x00001000 /* shuts off HOSTALIASES feature */ +#define RES_USE_INET6 0x00002000 /* use/map IPv6 in gethostbyname() */ +/* KAME extensions: use higher bit to avoid conflict with ISC use */ +#define RES_USE_EDNS0 0x40000000 /* use EDNS0 */ +/* DNSSEC extensions: use higher bit to avoid conflict with ISC use */ +#define RES_USE_DNSSEC 0x20000000 /* use DNSSEC using OK bit in OPT */ +#define RES_USE_CD 0x10000000 /* set Checking Disabled flag */ +#define RES_TRUSTAD 0x80000000 /* Request AD, keep it in responses. */ + +#define RES_DEFAULT (RES_RECURSE | RES_DEFNAMES | RES_DNSRCH) + +/* + * Resolver "pfcode" values. Used by dig. + */ +#define RES_PRF_STATS 0x00000001 +/* 0x00000002 */ +#define RES_PRF_CLASS 0x00000004 +#define RES_PRF_CMD 0x00000008 +#define RES_PRF_QUES 0x00000010 +#define RES_PRF_ANS 0x00000020 +#define RES_PRF_AUTH 0x00000040 +#define RES_PRF_ADD 0x00000080 +#define RES_PRF_HEAD1 0x00000100 +#define RES_PRF_HEAD2 0x00000200 +#define RES_PRF_TTLID 0x00000400 +#define RES_PRF_HEADX 0x00000800 +#define RES_PRF_QUERY 0x00001000 +#define RES_PRF_REPLY 0x00002000 +#define RES_PRF_INIT 0x00004000 +/* 0x00008000 */ + +/* hooks are still experimental as of 4.9.2 */ +typedef enum { res_goahead, res_nextns, res_modified, res_done, res_error } + res_sendhookact; + +typedef res_sendhookact (*res_send_qhook)(struct sockaddr_in * const *ns, + const unsigned char **query, + int *querylen, + unsigned char *ans, + int anssiz, + int *resplen); + +typedef res_sendhookact (*res_send_rhook)(const struct sockaddr_in *ns, + const unsigned char *query, + int querylen, + unsigned char *ans, + int anssiz, + int *resplen); + +struct res_sym { + int number; /* Identifying number, like T_MX */ + char * name; /* Its symbolic name, like "MX" */ + char * humanname; /* Its fun name, like "mail exchanger" */ +}; + +extern struct __res_state _res; +#if 1 /* INET6 */ +extern struct __res_state_ext _res_ext; +#endif +extern const struct res_sym __p_class_syms[]; +extern const struct res_sym __p_type_syms[]; + +/* Private routines shared between libc/net, named, nslookup and others. */ +#define res_hnok __res_hnok +#define res_ownok __res_ownok +#define res_mailok __res_mailok +#define res_dnok __res_dnok +#define sym_ntos __sym_ntos +#define b64_ntop __b64_ntop +#define b64_pton __b64_pton +#define dn_skipname __dn_skipname +#define putlong __putlong +#define putshort __putshort +#define p_class __p_class +#define p_type __p_type +#define dn_count_labels __dn_count_labels +#define dn_comp __dn_comp +#define res_randomid __res_randomid +#define res_send __res_send +#define res_opt __res_opt + +#ifdef BIND_RES_POSIX3 +#define dn_expand __dn_expand +#define res_init __res_init +#define res_query __res_query +#define res_search __res_search +#define res_querydomain __res_querydomain +#define res_mkquery __res_mkquery +#endif + +__BEGIN_DECLS +int res_hnok(const char *); +int res_ownok(const char *); +int res_mailok(const char *); +int res_dnok(const char *); +const char * sym_ntos(const struct res_sym *, int, int *); +int b64_ntop(unsigned char const *, size_t, char *, size_t); +int b64_pton(char const *, unsigned char *, size_t); +int dn_skipname(const unsigned char *, + const unsigned char *); +void putlong(u_int32_t, unsigned char *); +void putshort(u_int16_t, unsigned char *); +const char * p_class(int); +const char * p_type(int); +int dn_comp(const char *, unsigned char *, int, + unsigned char **, unsigned char **); +int dn_expand(const unsigned char *, const unsigned char *, + const unsigned char *, char *, int); +int res_init(void); +unsigned int res_randomid(void); +int res_query(const char *, int, int, unsigned char *, int) + __attribute__((__bounded__(__string__,4,5))); +int res_search(const char *, int, int, unsigned char *, int) + __attribute__((__bounded__(__string__,4,5))); +int res_querydomain(const char *, const char *, int, int, + unsigned char *, int) + __attribute__((__bounded__(__string__,5,6))); +int res_mkquery(int, const char *, int, int, + const unsigned char *, int, const unsigned char *, + unsigned char *, int) + __attribute__((__bounded__(__string__,5,6))) + __attribute__((__bounded__(__string__,8,9))); +int res_send(const unsigned char *, int, unsigned char *, + int) + __attribute__((__bounded__(__string__,3,4))); +__END_DECLS + +#endif /* !_RESOLV_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/rmd160.h b/lib/libc/include/generic-openbsd/rmd160.h new file mode 100644 index 0000000000..b227c3fc78 --- /dev/null +++ b/lib/libc/include/generic-openbsd/rmd160.h @@ -0,0 +1,60 @@ +/* $OpenBSD: rmd160.h,v 1.17 2012/12/05 23:19:57 deraadt Exp $ */ +/* + * Copyright (c) 2001 Markus Friedl. 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 _RMD160_H +#define _RMD160_H + +#define RMD160_BLOCK_LENGTH 64 +#define RMD160_DIGEST_LENGTH 20 +#define RMD160_DIGEST_STRING_LENGTH (RMD160_DIGEST_LENGTH * 2 + 1) + +/* RMD160 context. */ +typedef struct RMD160Context { + u_int32_t state[5]; /* state */ + u_int64_t count; /* number of bits, mod 2^64 */ + u_int8_t buffer[RMD160_BLOCK_LENGTH]; /* input buffer */ +} RMD160_CTX; + +__BEGIN_DECLS +void RMD160Init(RMD160_CTX *); +void RMD160Transform(u_int32_t [5], const u_int8_t [RMD160_BLOCK_LENGTH]) + __attribute__((__bounded__(__minbytes__,1,5))) + __attribute__((__bounded__(__minbytes__,2,RMD160_BLOCK_LENGTH))); +void RMD160Update(RMD160_CTX *, const u_int8_t *, size_t) + __attribute__((__bounded__(__string__,2,3))); +void RMD160Pad(RMD160_CTX *); +void RMD160Final(u_int8_t [RMD160_DIGEST_LENGTH], RMD160_CTX *) + __attribute__((__bounded__(__minbytes__,1,RMD160_DIGEST_LENGTH))); +char *RMD160End(RMD160_CTX *, char *) + __attribute__((__bounded__(__minbytes__,2,RMD160_DIGEST_STRING_LENGTH))); +char *RMD160File(const char *, char *) + __attribute__((__bounded__(__minbytes__,2,RMD160_DIGEST_STRING_LENGTH))); +char *RMD160FileChunk(const char *, char *, off_t, off_t) + __attribute__((__bounded__(__minbytes__,2,RMD160_DIGEST_STRING_LENGTH))); +char *RMD160Data(const u_int8_t *, size_t, char *) + __attribute__((__bounded__(__string__,1,2))) + __attribute__((__bounded__(__minbytes__,3,RMD160_DIGEST_STRING_LENGTH))); +__END_DECLS + +#endif /* _RMD160_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/rpc/auth.h b/lib/libc/include/generic-openbsd/rpc/auth.h new file mode 100644 index 0000000000..60b558ed39 --- /dev/null +++ b/lib/libc/include/generic-openbsd/rpc/auth.h @@ -0,0 +1,184 @@ +/* $OpenBSD: auth.h,v 1.9 2022/02/14 03:38:59 guenther Exp $ */ +/* $NetBSD: auth.h,v 1.7 1995/04/29 05:27:55 cgd Exp $ */ + +/* + * Copyright (c) 2010, Oracle America, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the name of the "Oracle America, Inc." 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT HOLDER 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: @(#)auth.h 1.17 88/02/08 SMI + * @(#)auth.h 2.3 88/08/07 4.0 RPCSRC + */ + +/* + * auth.h, Authentication interface. + * + * The data structures are completely opaque to the client. The client + * is required to pass a AUTH * to routines that create rpc + * "sessions". + */ + +#ifndef _RPC_AUTH_H +#define _RPC_AUTH_H +#include + +#define MAX_AUTH_BYTES 400 +#define MAXNETNAMELEN 255 /* maximum length of network user's name */ + +/* + * Status returned from authentication check + */ +enum auth_stat { + AUTH_OK=0, + /* + * failed at remote end + */ + AUTH_BADCRED=1, /* bogus credentials (seal broken) */ + AUTH_REJECTEDCRED=2, /* client should begin new session */ + AUTH_BADVERF=3, /* bogus verifier (seal broken) */ + AUTH_REJECTEDVERF=4, /* verifier expired or was replayed */ + AUTH_TOOWEAK=5, /* rejected due to security reasons */ + /* + * failed locally + */ + AUTH_INVALIDRESP=6, /* bogus response verifier */ + AUTH_FAILED=7 /* some unknown reason */ +}; + +typedef u_int32_t u_int32; /* 32-bit unsigned integers */ + +union des_block { + struct { + u_int32 high; + u_int32 low; + } key; + char c[8]; +}; +typedef union des_block des_block; +__BEGIN_DECLS +extern bool_t xdr_des_block(XDR *, des_block *); +__END_DECLS + +/* + * Authentication info. Opaque to client. + */ +struct opaque_auth { + enum_t oa_flavor; /* flavor of auth */ + caddr_t oa_base; /* address of more auth stuff */ + unsigned int oa_length; /* not to exceed MAX_AUTH_BYTES */ +}; + + +/* + * Auth handle, interface to client side authenticators. + */ +typedef struct __rpc_auth { + struct opaque_auth ah_cred; + struct opaque_auth ah_verf; + union des_block ah_key; + const struct auth_ops { + void (*ah_nextverf)(struct __rpc_auth *); + /* nextverf & serialize */ + int (*ah_marshal)(struct __rpc_auth *, XDR *); + /* validate varifier */ + int (*ah_validate)(struct __rpc_auth *, + struct opaque_auth *); + /* refresh credentials */ + int (*ah_refresh)(struct __rpc_auth *); + /* destroy this structure */ + void (*ah_destroy)(struct __rpc_auth *); + } *ah_ops; + caddr_t ah_private; +} AUTH; + + +/* + * Authentication ops. + * The ops and the auth handle provide the interface to the authenticators. + * + * AUTH *auth; + * XDR *xdrs; + * struct opaque_auth verf; + */ +#define AUTH_NEXTVERF(auth) \ + ((*((auth)->ah_ops->ah_nextverf))(auth)) +#define auth_nextverf(auth) \ + ((*((auth)->ah_ops->ah_nextverf))(auth)) + +#define AUTH_MARSHALL(auth, xdrs) \ + ((*((auth)->ah_ops->ah_marshal))(auth, xdrs)) +#define auth_marshall(auth, xdrs) \ + ((*((auth)->ah_ops->ah_marshal))(auth, xdrs)) + +#define AUTH_VALIDATE(auth, verfp) \ + ((*((auth)->ah_ops->ah_validate))((auth), verfp)) +#define auth_validate(auth, verfp) \ + ((*((auth)->ah_ops->ah_validate))((auth), verfp)) + +#define AUTH_REFRESH(auth) \ + ((*((auth)->ah_ops->ah_refresh))(auth)) +#define auth_refresh(auth) \ + ((*((auth)->ah_ops->ah_refresh))(auth)) + +#define AUTH_DESTROY(auth) \ + ((*((auth)->ah_ops->ah_destroy))(auth)) +#define auth_destroy(auth) \ + ((*((auth)->ah_ops->ah_destroy))(auth)) + + +extern struct opaque_auth _null_auth; + + +/* + * These are the various implementations of client side authenticators. + */ + +/* + * Unix style authentication + * AUTH *authunix_create(machname, uid, gid, len, aup_gids) + * char *machname; + * int uid; + * int gid; + * int len; + * int *aup_gids; + */ +__BEGIN_DECLS +struct sockaddr_in; +extern AUTH *authunix_create(char *, int, int, int, int *); +extern AUTH *authunix_create_default(void); +extern AUTH *authnone_create(void); +extern void set_rpc_maxgrouplist(int); +__END_DECLS + +#define AUTH_NONE 0 /* no authentication */ +#define AUTH_NULL 0 /* backward compatibility */ +#define AUTH_UNIX 1 /* unix style (uid, gids) */ +#define AUTH_SHORT 2 /* short hand unix style */ +#define AUTH_DES 3 /* des style (encrypted timestamps) */ + +#endif /* !_RPC_AUTH_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/rpc/auth_unix.h b/lib/libc/include/generic-openbsd/rpc/auth_unix.h new file mode 100644 index 0000000000..29d79a4603 --- /dev/null +++ b/lib/libc/include/generic-openbsd/rpc/auth_unix.h @@ -0,0 +1,84 @@ +/* $OpenBSD: auth_unix.h,v 1.5 2010/09/01 14:43:34 millert Exp $ */ +/* $NetBSD: auth_unix.h,v 1.4 1994/10/26 00:56:56 cgd Exp $ */ + +/* + * Copyright (c) 2010, Oracle America, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the name of the "Oracle America, Inc." 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT HOLDER 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: @(#)auth_unix.h 1.8 88/02/08 SMI + * @(#)auth_unix.h 2.2 88/07/29 4.0 RPCSRC + */ + +/* + * auth_unix.h, Protocol for UNIX style authentication parameters for RPC + */ + +/* + * The system is very weak. The client uses no encryption for it + * credentials and only sends null verifiers. The server sends backs + * null verifiers or optionally a verifier that suggests a new short hand + * for the credentials. + */ + +#ifndef _RPC_AUTH_UNIX_H +#define _RPC_AUTH_UNIX_H +#include + +/* The machine name is part of a credential; it may not exceed 255 bytes */ +#define MAX_MACHINE_NAME 255 + +/* gids compose part of a credential; there may not be more than 16 of them */ +#define NGRPS 16 + +/* + * Unix style credentials. + */ +struct authunix_parms { + unsigned long aup_time; + char *aup_machname; + int aup_uid; + int aup_gid; + unsigned int aup_len; + int *aup_gids; +}; + +__BEGIN_DECLS +extern bool_t xdr_authunix_parms(XDR *, struct authunix_parms *); +__END_DECLS + +/* + * If a response verifier has flavor AUTH_SHORT, + * then the body of the response verifier encapsulates the following structure; + * again it is serialized in the obvious fashion. + */ +struct short_hand_verf { + struct opaque_auth new_cred; +}; + +#endif /* !_RPC_AUTH_UNIX_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/rpc/clnt.h b/lib/libc/include/generic-openbsd/rpc/clnt.h new file mode 100644 index 0000000000..2ce2198eba --- /dev/null +++ b/lib/libc/include/generic-openbsd/rpc/clnt.h @@ -0,0 +1,362 @@ +/* $OpenBSD: clnt.h,v 1.14 2022/12/27 07:44:56 jmc Exp $ */ +/* $NetBSD: clnt.h,v 1.6 1995/04/29 05:27:58 cgd Exp $ */ + +/* + * Copyright (c) 2010, Oracle America, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the name of the "Oracle America, Inc." 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT HOLDER 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: @(#)clnt.h 1.31 88/02/08 SMI + * @(#)clnt.h 2.1 88/07/29 4.0 RPCSRC + */ + +/* + * clnt.h - Client side remote procedure call interface. + */ + +#ifndef _RPC_CLNT_H_ +#define _RPC_CLNT_H_ +#include + +/* + * Rpc calls return an enum clnt_stat. This should be looked at more, + * since each implementation is required to live with this (implementation + * independent) list of errors. + */ +enum clnt_stat { + RPC_SUCCESS=0, /* call succeeded */ + /* + * local errors + */ + RPC_CANTENCODEARGS=1, /* can't encode arguments */ + RPC_CANTDECODERES=2, /* can't decode results */ + RPC_CANTSEND=3, /* failure in sending call */ + RPC_CANTRECV=4, /* failure in receiving result */ + RPC_TIMEDOUT=5, /* call timed out */ + /* + * remote errors + */ + RPC_VERSMISMATCH=6, /* rpc versions not compatible */ + RPC_AUTHERROR=7, /* authentication error */ + RPC_PROGUNAVAIL=8, /* program not available */ + RPC_PROGVERSMISMATCH=9, /* program version mismatched */ + RPC_PROCUNAVAIL=10, /* procedure unavailable */ + RPC_CANTDECODEARGS=11, /* decode arguments error */ + RPC_SYSTEMERROR=12, /* generic "other problem" */ + + /* + * callrpc & clnt_create errors + */ + RPC_UNKNOWNHOST=13, /* unknown host name */ + RPC_UNKNOWNPROTO=17, /* unknown protocol */ + + /* + * _ create errors + */ + RPC_PMAPFAILURE=14, /* the pmapper failed in its call */ + RPC_PROGNOTREGISTERED=15, /* remote program is not registered */ + /* + * unspecified error + */ + RPC_FAILED=16 +}; + + +/* + * Error info. + */ +struct rpc_err { + enum clnt_stat re_status; + union { + int RE_errno; /* related system error */ + enum auth_stat RE_why; /* why the auth error occurred */ + struct { + u_int32_t low; /* lowest version supported */ + u_int32_t high; /* highest version supported */ + } RE_vers; + struct { /* maybe meaningful if RPC_FAILED */ + int32_t s1; + int32_t s2; + } RE_lb; /* life boot & debugging only */ + } ru; +#define re_errno ru.RE_errno +#define re_why ru.RE_why +#define re_vers ru.RE_vers +#define re_lb ru.RE_lb +}; + + +/* + * Client rpc handle. + * Created by individual implementations, see e.g. rpc_udp.c. + * Client is responsible for initializing auth, see e.g. auth_none.c. + */ +typedef struct __rpc_client { + AUTH *cl_auth; /* authenticator */ + const struct clnt_ops { + /* call remote procedure */ + enum clnt_stat (*cl_call)(struct __rpc_client *, + unsigned long, xdrproc_t, caddr_t, + xdrproc_t, caddr_t, struct timeval); + /* abort a call */ + void (*cl_abort)(struct __rpc_client *); + /* get specific error code */ + void (*cl_geterr)(struct __rpc_client *, + struct rpc_err *); + /* frees results */ + bool_t (*cl_freeres)(struct __rpc_client *, + xdrproc_t, caddr_t); + /* destroy this structure */ + void (*cl_destroy)(struct __rpc_client *); + /* the ioctl() of rpc */ + bool_t (*cl_control)(struct __rpc_client *, + unsigned int, void *); + } *cl_ops; + caddr_t cl_private; /* private stuff */ +} CLIENT; + + +/* + * client side rpc interface ops + * + * Parameter types are: + * + */ + +/* + * enum clnt_stat + * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout) + * CLIENT *rh; + * unsigned long proc; + * xdrproc_t xargs; + * caddr_t argsp; + * xdrproc_t xres; + * caddr_t resp; + * struct timeval timeout; + */ +#define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \ + ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, (caddr_t)argsp, \ + xres, (caddr_t)resp, secs)) +#define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \ + ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, (caddr_t)argsp, \ + xres, (caddr_t)resp, secs)) + +/* + * void + * CLNT_ABORT(rh); + * CLIENT *rh; + */ +#define CLNT_ABORT(rh) ((*(rh)->cl_ops->cl_abort)(rh)) +#define clnt_abort(rh) ((*(rh)->cl_ops->cl_abort)(rh)) + +/* + * struct rpc_err + * CLNT_GETERR(rh); + * CLIENT *rh; + */ +#define CLNT_GETERR(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp)) +#define clnt_geterr(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp)) + + +/* + * bool_t + * CLNT_FREERES(rh, xres, resp); + * CLIENT *rh; + * xdrproc_t xres; + * caddr_t resp; + */ +#define CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp)) +#define clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp)) + +/* + * bool_t + * CLNT_CONTROL(cl, request, info) + * CLIENT *cl; + * unsigned int request; + * char *info; + */ +#define CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in)) +#define clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in)) + +/* + * control operations that apply to both udp and tcp transports + */ +#define CLSET_TIMEOUT 1 /* set timeout (timeval) */ +#define CLGET_TIMEOUT 2 /* get timeout (timeval) */ +#define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */ +/* + * udp only control operations + */ +#define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */ +#define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */ +#define CLSET_CONNECTED 6 /* socket is connected, so use send() */ + +/* + * void + * CLNT_DESTROY(rh); + * CLIENT *rh; + */ +#define CLNT_DESTROY(rh) ((*(rh)->cl_ops->cl_destroy)(rh)) +#define clnt_destroy(rh) ((*(rh)->cl_ops->cl_destroy)(rh)) + + +/* + * RPCTEST is a test program which is accessible on every rpc + * transport/port. It is used for testing, performance evaluation, + * and network administration. + */ + +#define RPCTEST_PROGRAM ((unsigned long)1) +#define RPCTEST_VERSION ((unsigned long)1) +#define RPCTEST_NULL_PROC ((unsigned long)2) +#define RPCTEST_NULL_BATCH_PROC ((unsigned long)3) + +/* + * By convention, procedure 0 takes null arguments and returns them + */ + +#define NULLPROC ((unsigned int)0) + +/* + * Below are the client handle creation routines for the various + * implementations of client side rpc. They can return NULL if a + * creation failure occurs. + */ + +/* + * Memory based rpc (for speed check and testing) + * CLIENT * + * clntraw_create(prog, vers) + * unsigned long prog; + * unsigned long vers; + */ +__BEGIN_DECLS +extern CLIENT *clntraw_create(unsigned long, unsigned long); +__END_DECLS + + +/* + * Generic client creation routine. Supported protocols are "udp" and "tcp" + * CLIENT * + * clnt_create(host, prog, vers, prot); + * char *host; -- hostname + * unsigned long prog; -- program number + * unsigned long vers; -- version number + * char *prot; -- protocol + */ +__BEGIN_DECLS +extern CLIENT *clnt_create(char *, unsigned long, unsigned long, char *); +__END_DECLS + + +/* + * TCP based rpc + * CLIENT * + * clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz) + * struct sockaddr_in *raddr; + * unsigned long prog; + * unsigned long version; + * int *sockp; + * unsigned int sendsz; + * unsigned int recvsz; + */ +__BEGIN_DECLS +extern CLIENT *clnttcp_create(struct sockaddr_in *, unsigned long, + unsigned long, int *, unsigned int, unsigned int); +__END_DECLS + + +/* + * UDP based rpc. + * CLIENT * + * clntudp_create(raddr, program, version, wait, sockp) + * struct sockaddr_in *raddr; + * unsigned long program; + * unsigned long version; + * struct timeval wait; + * int *sockp; + * + * Same as above, but you specify max packet sizes. + * CLIENT * + * clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz) + * struct sockaddr_in *raddr; + * unsigned long program; + * unsigned long version; + * struct timeval wait; + * int *sockp; + * unsigned int sendsz; + * unsigned int recvsz; + */ +__BEGIN_DECLS +extern CLIENT *clntudp_create(struct sockaddr_in *, unsigned long, + unsigned long, struct timeval, int *); +extern CLIENT *clntudp_bufcreate(struct sockaddr_in *, unsigned long, + unsigned long, struct timeval, int *, unsigned int, unsigned int); +__END_DECLS + + +/* + * Print why creation failed + */ +__BEGIN_DECLS +extern void clnt_pcreateerror(char *); /* stderr */ +extern char *clnt_spcreateerror(char *); /* string */ +__END_DECLS + +/* + * Like clnt_perror(), but is more verbose in its output + */ +__BEGIN_DECLS +extern void clnt_perrno(enum clnt_stat); /* stderr */ +extern char *clnt_sperrno(enum clnt_stat); /* string */ +__END_DECLS + +/* + * Print an English error message, given the client error code + */ +__BEGIN_DECLS +extern void clnt_perror(CLIENT *, char *); /* stderr */ +extern char *clnt_sperror(CLIENT *, char *); /* string */ +__END_DECLS + + +/* + * If a creation fails, the following allows the user to figure out why. + */ +struct rpc_createerr { + enum clnt_stat cf_stat; + struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */ +}; + +extern struct rpc_createerr rpc_createerr; + + +#define UDPMSGSIZE 8800 /* rpc imposed limit on udp msg size */ +#define RPCSMALLMSGSIZE 400 /* a more reasonable packet size */ + +#endif /* !_RPC_CLNT_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/rpc/pmap_clnt.h b/lib/libc/include/generic-openbsd/rpc/pmap_clnt.h new file mode 100644 index 0000000000..c9e7f04a91 --- /dev/null +++ b/lib/libc/include/generic-openbsd/rpc/pmap_clnt.h @@ -0,0 +1,85 @@ +/* $OpenBSD: pmap_clnt.h,v 1.7 2010/09/01 14:43:34 millert Exp $ */ +/* $NetBSD: pmap_clnt.h,v 1.5 1994/12/04 01:12:42 cgd Exp $ */ + +/* + * Copyright (c) 2010, Oracle America, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the name of the "Oracle America, Inc." 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT HOLDER 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: @(#)pmap_clnt.h 1.11 88/02/08 SMI + * @(#)pmap_clnt.h 2.1 88/07/29 4.0 RPCSRC + */ + +/* + * pmap_clnt.h + * Supplies C routines to get to portmap services. + */ + +/* + * Usage: + * success = pmap_set(program, version, protocol, port); + * success = pmap_unset(program, version); + * port = pmap_getport(address, program, version, protocol); + * head = pmap_getmaps(address); + * clnt_stat = pmap_rmtcall(address, program, version, procedure, + * xdrargs, argsp, xdrres, resp, tout, port_ptr) + * (works for udp only.) + * clnt_stat = clnt_broadcast(program, version, procedure, + * xdrargs, argsp, xdrres, resp, eachresult) + * (like pmap_rmtcall, except the call is broadcasted to all + * locally connected nets. For each valid response received, + * the procedure eachresult is called. Its form is: + * done = eachresult(resp, raddr) + * bool_t done; + * caddr_t resp; + * struct sockaddr_in raddr; + * where resp points to the results of the call and raddr is the + * address if the responder to the broadcast. + */ + +#ifndef _RPC_PMAPCLNT_H +#define _RPC_PMAPCLNT_H +#include + +__BEGIN_DECLS +extern bool_t pmap_set(unsigned long, unsigned long, unsigned int, + int); +extern bool_t pmap_unset(unsigned long, unsigned long); +extern struct pmaplist *pmap_getmaps(struct sockaddr_in *); +extern enum clnt_stat pmap_rmtcall(struct sockaddr_in *, unsigned long, + unsigned long, unsigned long, xdrproc_t, caddr_t, + xdrproc_t, caddr_t, struct timeval, + unsigned long *); +extern enum clnt_stat clnt_broadcast(unsigned long, unsigned long, + unsigned long, xdrproc_t, char *, xdrproc_t, char *, + bool_t (*)(caddr_t, struct sockaddr_in *)); +extern unsigned short pmap_getport(struct sockaddr_in *, unsigned long, + unsigned long, unsigned int); +__END_DECLS + +#endif /* !_RPC_PMAPCLNT_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/rpc/pmap_prot.h b/lib/libc/include/generic-openbsd/rpc/pmap_prot.h new file mode 100644 index 0000000000..4b13fc61e6 --- /dev/null +++ b/lib/libc/include/generic-openbsd/rpc/pmap_prot.h @@ -0,0 +1,106 @@ +/* $OpenBSD: pmap_prot.h,v 1.6 2010/09/01 14:43:34 millert Exp $ */ +/* $NetBSD: pmap_prot.h,v 1.4 1994/10/26 00:57:00 cgd Exp $ */ + +/* + * Copyright (c) 2010, Oracle America, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the name of the "Oracle America, Inc." 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT HOLDER 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: @(#)pmap_prot.h 1.14 88/02/08 SMI + * @(#)pmap_prot.h 2.1 88/07/29 4.0 RPCSRC + */ + +/* + * pmap_prot.h + * Protocol for the local binder service, or pmap. + * + * The following procedures are supported by the protocol: + * + * PMAPPROC_NULL() returns () + * takes nothing, returns nothing + * + * PMAPPROC_SET(struct pmap) returns (bool_t) + * TRUE is success, FALSE is failure. Registers the tuple + * [prog, vers, prot, port]. + * + * PMAPPROC_UNSET(struct pmap) returns (bool_t) + * TRUE is success, FALSE is failure. Un-registers pair + * [prog, vers]. prot and port are ignored. + * + * PMAPPROC_GETPORT(struct pmap) returns (unsigned long). + * 0 is failure. Otherwise returns the port number where the pair + * [prog, vers] is registered. It may lie! + * + * PMAPPROC_DUMP() RETURNS (struct pmaplist *) + * + * PMAPPROC_CALLIT(unsigned int, unsigned int, unsigned int, string<>) + * RETURNS (port, string<>); + * usage: encapsulatedresults = PMAPPROC_CALLIT(prog, vers, proc, encapsulatedargs); + * Calls the procedure on the local machine. If it is not registered, + * this procedure is quite; ie it does not return error information!!! + * This procedure only is supported on rpc/udp and calls via + * rpc/udp. This routine only passes null authentication parameters. + * This file has no interface to xdr routines for PMAPPROC_CALLIT. + * + * The service supports remote procedure calls on udp/ip or tcp/ip socket 111. + */ + +#ifndef _RPC_PMAPPROT_H +#define _RPC_PMAPPROT_H +#include + +#define PMAPPORT ((unsigned short)111) +#define PMAPPROG ((unsigned long)100000) +#define PMAPVERS ((unsigned long)2) +#define PMAPVERS_PROTO ((unsigned long)2) +#define PMAPVERS_ORIG ((unsigned long)1) +#define PMAPPROC_NULL ((unsigned long)0) +#define PMAPPROC_SET ((unsigned long)1) +#define PMAPPROC_UNSET ((unsigned long)2) +#define PMAPPROC_GETPORT ((unsigned long)3) +#define PMAPPROC_DUMP ((unsigned long)4) +#define PMAPPROC_CALLIT ((unsigned long)5) + +struct pmap { + unsigned long pm_prog; + unsigned long pm_vers; + unsigned long pm_prot; + unsigned long pm_port; +}; + +struct pmaplist { + struct pmap pml_map; + struct pmaplist *pml_next; +}; + +__BEGIN_DECLS +extern bool_t xdr_pmap(XDR *, struct pmap *); +extern bool_t xdr_pmaplist(XDR *, struct pmaplist **); +__END_DECLS + +#endif /* !_RPC_PMAPPROT_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/rpc/pmap_rmt.h b/lib/libc/include/generic-openbsd/rpc/pmap_rmt.h new file mode 100644 index 0000000000..9be70c44ce --- /dev/null +++ b/lib/libc/include/generic-openbsd/rpc/pmap_rmt.h @@ -0,0 +1,65 @@ +/* $OpenBSD: pmap_rmt.h,v 1.5 2010/09/01 14:43:34 millert Exp $ */ +/* $NetBSD: pmap_rmt.h,v 1.4 1994/10/26 00:57:01 cgd Exp $ */ + +/* + * Copyright (c) 2010, Oracle America, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the name of the "Oracle America, Inc." 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT HOLDER 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: @(#)pmap_rmt.h 1.2 88/02/08 SMI + * @(#)pmap_rmt.h 2.1 88/07/29 4.0 RPCSRC + */ + +/* + * Structures and XDR routines for parameters to and replies from + * the portmapper remote-call-service. + */ + +#ifndef _RPC_PMAPRMT_H +#define _RPC_PMAPRMT_H +#include + +struct rmtcallargs { + unsigned long prog, vers, proc, arglen; + caddr_t args_ptr; + xdrproc_t xdr_args; +}; + +struct rmtcallres { + unsigned long *port_ptr; + unsigned long resultslen; + caddr_t results_ptr; + xdrproc_t xdr_results; +}; + +__BEGIN_DECLS +extern bool_t xdr_rmtcall_args(XDR *, struct rmtcallargs *); +extern bool_t xdr_rmtcallres(XDR *, struct rmtcallres *); +__END_DECLS + +#endif /* !_RPC_PMAPRMT_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/rpc/rpc.h b/lib/libc/include/generic-openbsd/rpc/rpc.h new file mode 100644 index 0000000000..69d3191380 --- /dev/null +++ b/lib/libc/include/generic-openbsd/rpc/rpc.h @@ -0,0 +1,108 @@ +/* $OpenBSD: rpc.h,v 1.11 2010/09/01 14:43:34 millert Exp $ */ +/* $NetBSD: rpc.h,v 1.5 1994/12/04 01:15:30 cgd Exp $ */ + +/* + * Copyright (c) 2010, Oracle America, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the name of the "Oracle America, Inc." 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT HOLDER 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: @(#)rpc.h 1.9 88/02/08 SMI + * @(#)rpc.h 2.4 89/07/11 4.0 RPCSRC + */ + +/* + * rpc.h, Just includes the billions of rpc header files necessary to + * do remote procedure calling. + */ +#ifndef _RPC_RPC_H +#define _RPC_RPC_H + +#include /* some typedefs */ +#include + +/* external data representation interfaces */ +#include /* generic (de)serializer */ + +/* Client side only authentication */ +#include /* generic authenticator (client side) */ + +/* Client side (mostly) remote procedure call */ +#include /* generic rpc stuff */ + +/* Client side (mostly) pmap functions */ +#include /* generic pmap stuff */ + +/* semi-private protocol headers */ +#include /* protocol for rpc messages */ +#include /* protocol for unix style cred */ +/* + * Uncomment-out the next line if you are building the rpc library with + * DES Authentication (see the README file in the secure_rpc/ directory). + */ +#ifdef notdef +#include /* protocol for des style cred */ +#endif + +/* Server side only remote procedure callee */ +#include /* service manager and multiplexer */ +#include /* service side authenticator */ + +/* + * COMMENT OUT THE NEXT INCLUDE (or add to the #ifndef) IF RUNNING ON + * A VERSION OF UNIX THAT USES SUN'S NFS SOURCE. These systems will + * already have the structures defined by included in . + */ +/* routines for parsing /etc/rpc */ + +struct rpcent { + char *r_name; /* name of server for this rpc program */ + char **r_aliases; /* alias list */ + int r_number; /* rpc program number */ +}; + +__BEGIN_DECLS +extern struct rpcent *getrpcbyname(char *); +extern struct rpcent *getrpcbynumber(int); +extern struct rpcent *getrpcent(void); +extern void setrpcent(int); +extern void endrpcent(void); + +extern int get_myaddress(struct sockaddr_in *); +extern int registerrpc(int, int, int, char *(*)(char [UDPMSGSIZE]), + xdrproc_t, xdrproc_t); +extern int callrpc(char *, int, int, int, xdrproc_t, char *, + xdrproc_t , char *); +extern int getrpcport(char *, int, int, int); + +extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *); + +extern int _rpc_dtablesize(void); + +__END_DECLS + +#endif /* !_RPC_RPC_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/rpc/rpc_des.h b/lib/libc/include/generic-openbsd/rpc/rpc_des.h new file mode 100644 index 0000000000..272ff423ed --- /dev/null +++ b/lib/libc/include/generic-openbsd/rpc/rpc_des.h @@ -0,0 +1,134 @@ +/* $OpenBSD: rpc_des.h,v 1.4 2010/09/01 14:43:34 millert Exp $ */ + +/* crypto/des/rpc_des.h */ +/* Copyright (C) 1995-1997 Eric Young (eay@mincom.oz.au) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@mincom.oz.au). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@mincom.oz.au). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * 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 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 cryptographic software written by + * Eric Young (eay@mincom.oz.au)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@mincom.oz.au)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR 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. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +/* @(#)des.h 2.2 88/08/10 4.0 RPCSRC; from 2.7 88/02/08 SMI */ +/* + * Copyright (c) 2010, Oracle America, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the name of the "Oracle America, Inc." 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT HOLDER 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 DES driver interface + * Keep this file hardware independent! + */ + +#define DES_MAXLEN 65536 /* maximum # of bytes to encrypt */ +#define DES_QUICKLEN 16 /* maximum # of bytes to encrypt quickly */ + +#ifdef HEADER_DES_H +#undef ENCRYPT +#undef DECRYPT +#endif + +enum desdir { ENCRYPT, DECRYPT }; +enum desmode { CBC, ECB }; + +/* + * parameters to ioctl call + */ +struct desparams { + unsigned char des_key[8]; /* key (with low bit parity) */ + enum desdir des_dir; /* direction */ + enum desmode des_mode; /* mode */ + unsigned char des_ivec[8]; /* input vector */ + unsigned int des_len; /* number of bytes to crypt */ + union { + unsigned char UDES_data[DES_QUICKLEN]; + unsigned char *UDES_buf; + } UDES; +# define des_data UDES.UDES_data /* direct data here if quick */ +# define des_buf UDES.UDES_buf /* otherwise, pointer to data */ +}; + +/* + * Encrypt an arbitrary sized buffer + */ +#define DESIOCBLOCK _IOWR(d, 6, struct desparams) + +/* + * Encrypt of small amount of data, quickly + */ +#define DESIOCQUICK _IOWR(d, 7, struct desparams) \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/rpc/rpc_msg.h b/lib/libc/include/generic-openbsd/rpc/rpc_msg.h new file mode 100644 index 0000000000..cabe4c54f1 --- /dev/null +++ b/lib/libc/include/generic-openbsd/rpc/rpc_msg.h @@ -0,0 +1,200 @@ +/* $OpenBSD: rpc_msg.h,v 1.7 2014/10/29 04:34:21 guenther Exp $ */ +/* $NetBSD: rpc_msg.h,v 1.5 1995/04/29 05:28:00 cgd Exp $ */ + +/* + * Copyright (c) 2010, Oracle America, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the name of the "Oracle America, Inc." 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT HOLDER 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: @(#)rpc_msg.h 1.7 86/07/16 SMI + * @(#)rpc_msg.h 2.1 88/07/29 4.0 RPCSRC + */ + +/* + * rpc_msg.h + * rpc message definition + */ + +#ifndef _RPC_RPCMSG_H +#define _RPC_RPCMSG_H + +#define RPC_MSG_VERSION ((unsigned long) 2) +#define RPC_SERVICE_PORT ((unsigned short) 2048) + +/* + * Bottom up definition of an rpc message. + * NOTE: call and reply use the same overall struct but + * different parts of unions within it. + */ + +enum msg_type { + CALL=0, + REPLY=1 +}; + +enum reply_stat { + MSG_ACCEPTED=0, + MSG_DENIED=1 +}; + +enum accept_stat { + SUCCESS=0, + PROG_UNAVAIL=1, + PROG_MISMATCH=2, + PROC_UNAVAIL=3, + GARBAGE_ARGS=4, + SYSTEM_ERR=5 +}; + +enum reject_stat { + RPC_MISMATCH=0, + AUTH_ERROR=1 +}; + +/* + * Reply part of an rpc exchange + */ + +/* + * Reply to an rpc request that was accepted by the server. + * Note: there could be an error even though the request was + * accepted. + */ +struct accepted_reply { + struct opaque_auth ar_verf; + enum accept_stat ar_stat; + union { + struct { + u_int32_t low; + u_int32_t high; + } AR_versions; + struct { + caddr_t where; + xdrproc_t proc; + } AR_results; + /* and many other null cases */ + } ru; +#define ar_results ru.AR_results +#define ar_vers ru.AR_versions +}; + +/* + * Reply to an rpc request that was rejected by the server. + */ +struct rejected_reply { + enum reject_stat rj_stat; + union { + struct { + u_int32_t low; + u_int32_t high; + } RJ_versions; + enum auth_stat RJ_why; /* why authentication did not work */ + } ru; +#define rj_vers ru.RJ_versions +#define rj_why ru.RJ_why +}; + +/* + * Body of a reply to an rpc request. + */ +struct reply_body { + enum reply_stat rp_stat; + union { + struct accepted_reply RP_ar; + struct rejected_reply RP_dr; + } ru; +#define rp_acpt ru.RP_ar +#define rp_rjct ru.RP_dr +}; + +/* + * Body of an rpc request call. + */ +struct call_body { + u_int32_t cb_rpcvers; /* must be equal to two */ + u_int32_t cb_prog; + u_int32_t cb_vers; + u_int32_t cb_proc; + struct opaque_auth cb_cred; + struct opaque_auth cb_verf; /* protocol specific - provided by client */ +}; + +/* + * The rpc message + */ +struct rpc_msg { + u_int32_t rm_xid; + enum msg_type rm_direction; + union { + struct call_body RM_cmb; + struct reply_body RM_rmb; + } ru; +#define rm_call ru.RM_cmb +#define rm_reply ru.RM_rmb +}; +#define acpted_rply ru.RM_rmb.ru.RP_ar +#define rjcted_rply ru.RM_rmb.ru.RP_dr + +__BEGIN_DECLS +/* + * XDR routine to handle a rpc message. + * xdr_callmsg(xdrs, cmsg) + * XDR *xdrs; + * struct rpc_msg *cmsg; + */ +extern bool_t xdr_callmsg(XDR *, struct rpc_msg *); + +/* + * XDR routine to pre-serialize the static part of a rpc message. + * xdr_callhdr(xdrs, cmsg) + * XDR *xdrs; + * struct rpc_msg *cmsg; + */ +extern bool_t xdr_callhdr(XDR *, struct rpc_msg *); + +/* + * XDR routine to handle a rpc reply. + * xdr_replymsg(xdrs, rmsg) + * XDR *xdrs; + * struct rpc_msg *rmsg; + */ +extern bool_t xdr_replymsg(XDR *, struct rpc_msg *); + +extern bool_t xdr_accepted_reply(XDR *, struct accepted_reply *); +extern bool_t xdr_rejected_reply(XDR *, struct rejected_reply *); + +/* + * Fills in the error part of a reply message. + * _seterr_reply(msg, error) + * struct rpc_msg *msg; + * struct rpc_err *error; + */ +extern void _seterr_reply(struct rpc_msg *, struct rpc_err *); +__END_DECLS + +#endif /* !_RPC_RPCMSG_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/rpc/svc.h b/lib/libc/include/generic-openbsd/rpc/svc.h new file mode 100644 index 0000000000..f505af9fb1 --- /dev/null +++ b/lib/libc/include/generic-openbsd/rpc/svc.h @@ -0,0 +1,326 @@ +/* $OpenBSD: svc.h,v 1.17 2022/02/14 03:38:59 guenther Exp $ */ +/* $NetBSD: svc.h,v 1.9 1995/04/29 05:28:01 cgd Exp $ */ + +/* + * Copyright (c) 2010, Oracle America, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the name of the "Oracle America, Inc." 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT HOLDER 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: @(#)svc.h 1.20 88/02/08 SMI + * @(#)svc.h 2.2 88/07/29 4.0 RPCSRC + */ + +/* + * svc.h, Server-side remote procedure call interface. + */ + +#ifndef _RPC_SVC_H +#define _RPC_SVC_H +#include +#include + +/* + * This interface must manage two items concerning remote procedure calling: + * + * 1) An arbitrary number of transport connections upon which rpc requests + * are received. The two most notable transports are TCP and UDP; they are + * created and registered by routines in svc_tcp.c and svc_udp.c, respectively; + * they in turn call xprt_register and xprt_unregister. + * + * 2) An arbitrary number of locally registered services. Services are + * described by the following four data: program number, version number, + * "service dispatch" function, a transport handle, and a boolean that + * indicates whether or not the exported program should be registered with a + * local binder service; if true the program's number and version and the + * port number from the transport handle are registered with the binder. + * These data are registered with the rpc svc system via svc_register. + * + * A service's dispatch function is called whenever an rpc request comes in + * on a transport. The request's program and version numbers must match + * those of the registered service. The dispatch function is passed two + * parameters, struct svc_req * and SVCXPRT *, defined below. + */ + +enum xprt_stat { + XPRT_DIED, + XPRT_MOREREQS, + XPRT_IDLE +}; + +/* + * Server side transport handle + */ +typedef struct __rpc_svcxprt { + int xp_sock; + unsigned short xp_port; /* associated port number */ + const struct xp_ops { + /* receive incoming requests */ + bool_t (*xp_recv)(struct __rpc_svcxprt *, + struct rpc_msg *); + /* get transport status */ + enum xprt_stat (*xp_stat)(struct __rpc_svcxprt *); + /* get arguments */ + bool_t (*xp_getargs)(struct __rpc_svcxprt *, xdrproc_t, + caddr_t); + /* send reply */ + bool_t (*xp_reply)(struct __rpc_svcxprt *, struct rpc_msg *); + /* free mem allocated for args */ + bool_t (*xp_freeargs)(struct __rpc_svcxprt *, xdrproc_t, + caddr_t); + /* destroy this struct */ + void (*xp_destroy)(struct __rpc_svcxprt *); + } *xp_ops; + socklen_t xp_addrlen; /* length of remote address */ + struct sockaddr_in xp_raddr; /* remote address */ + struct opaque_auth xp_verf; /* raw response verifier */ + caddr_t xp_p1; /* private */ + caddr_t xp_p2; /* private */ +} SVCXPRT; + +/* + * Approved way of getting address of caller + */ +#define svc_getcaller(x) (&(x)->xp_raddr) + +/* + * Operations defined on an SVCXPRT handle + * + * SVCXPRT *xprt; + * struct rpc_msg *msg; + * xdrproc_t xargs; + * caddr_t argsp; + */ +#define SVC_RECV(xprt, msg) \ + (*(xprt)->xp_ops->xp_recv)((xprt), (msg)) +#define svc_recv(xprt, msg) \ + (*(xprt)->xp_ops->xp_recv)((xprt), (msg)) + +#define SVC_STAT(xprt) \ + (*(xprt)->xp_ops->xp_stat)(xprt) +#define svc_stat(xprt) \ + (*(xprt)->xp_ops->xp_stat)(xprt) + +#define SVC_GETARGS(xprt, xargs, argsp) \ + (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp)) +#define svc_getargs(xprt, xargs, argsp) \ + (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp)) + +#define SVC_REPLY(xprt, msg) \ + (*(xprt)->xp_ops->xp_reply) ((xprt), (msg)) +#define svc_reply(xprt, msg) \ + (*(xprt)->xp_ops->xp_reply) ((xprt), (msg)) + +#define SVC_FREEARGS(xprt, xargs, argsp) \ + (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp)) +#define svc_freeargs(xprt, xargs, argsp) \ + (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp)) + +#define SVC_DESTROY(xprt) \ + (*(xprt)->xp_ops->xp_destroy)(xprt) +#define svc_destroy(xprt) \ + (*(xprt)->xp_ops->xp_destroy)(xprt) + + +/* + * Service request + */ +struct svc_req { + u_int32_t rq_prog; /* service program number */ + u_int32_t rq_vers; /* service protocol version */ + u_int32_t rq_proc; /* the desired procedure */ + struct opaque_auth rq_cred; /* raw creds from the wire */ + caddr_t rq_clntcred; /* read only cooked cred */ + SVCXPRT *rq_xprt; /* associated transport */ +}; + + +/* + * Service registration + * + * svc_register(xprt, prog, vers, dispatch, protocol) + * SVCXPRT *xprt; + * unsigned long prog; + * unsigned long vers; + * void (*dispatch)(); + * int protocol; like TCP or UDP, zero means do not register + */ +__BEGIN_DECLS +extern bool_t svc_register(SVCXPRT *, unsigned long, unsigned long, + void (*)(struct svc_req *, SVCXPRT *), int); +__END_DECLS + +/* + * Service un-registration + * + * svc_unregister(prog, vers) + * unsigned long prog; + * unsigned long vers; + */ +__BEGIN_DECLS +extern void svc_unregister(unsigned long, unsigned long); +__END_DECLS + +/* + * Transport registration. + * + * xprt_register(xprt) + * SVCXPRT *xprt; + */ +__BEGIN_DECLS +extern void xprt_register(SVCXPRT *); +__END_DECLS + +/* + * Transport un-register + * + * xprt_unregister(xprt) + * SVCXPRT *xprt; + */ +__BEGIN_DECLS +extern void xprt_unregister(SVCXPRT *); +__END_DECLS + + + + +/* + * When the service routine is called, it must first check to see if it + * knows about the procedure; if not, it should call svcerr_noproc + * and return. If so, it should deserialize its arguments via + * SVC_GETARGS (defined above). If the deserialization does not work, + * svcerr_decode should be called followed by a return. Successful + * decoding of the arguments should be followed the execution of the + * procedure's code and a call to svc_sendreply. + * + * Also, if the service refuses to execute the procedure due to too- + * weak authentication parameters, svcerr_weakauth should be called. + * Note: do not confuse access-control failure with weak authentication! + * + * NB: In pure implementations of rpc, the caller always waits for a reply + * msg. This message is sent when svc_sendreply is called. + * Therefore pure service implementations should always call + * svc_sendreply even if the function logically returns void; use + * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows + * for the abuse of pure rpc via batched calling or pipelining. In the + * case of a batched call, svc_sendreply should NOT be called since + * this would send a return message, which is what batching tries to avoid. + * It is the service/protocol writer's responsibility to know which calls are + * batched and which are not. Warning: responding to batch calls may + * deadlock the caller and server processes! + */ + +__BEGIN_DECLS +extern bool_t svc_sendreply(SVCXPRT *, xdrproc_t, char *); +extern void svcerr_decode(SVCXPRT *); +extern void svcerr_weakauth(SVCXPRT *); +extern void svcerr_noproc(SVCXPRT *); +extern void svcerr_progvers(SVCXPRT *, unsigned long, unsigned long); +extern void svcerr_auth(SVCXPRT *, enum auth_stat); +extern void svcerr_noprog(SVCXPRT *); +extern void svcerr_systemerr(SVCXPRT *); +__END_DECLS + +/* + * Lowest level dispatching -OR- who owns this process anyway. + * Somebody has to wait for incoming requests and then call the correct + * service routine. The routine svc_run does infinite waiting; i.e., + * svc_run never returns. + * Since another (co-existent) package may wish to selectively wait for + * incoming calls or other events outside of the rpc architecture, the + * routine svc_getreq is provided. It must be passed readfds, the + * "in-place" results of a select system call (see select, section 2). + */ + +/* + * Global keeper of rpc service descriptors in use + * dynamic; must be inspected before each call to select + */ +#include /* for fd_set */ +extern fd_set svc_fdset; +#define svc_fds svc_fdset.fds_bits[0] /* compatibility */ +extern struct pollfd *svc_pollfd; +extern int svc_max_pollfd; +extern int svc_maxfd; /* non-standard */ + +/* + * a small program implemented by the svc_rpc implementation itself; + * also see clnt.h for protocol numbers. + */ +extern void rpctest_service(); /* XXX relic? */ + +__BEGIN_DECLS +extern void svc_getreq(int); +extern void svc_getreq_common(int); +extern void svc_getreq_poll(struct pollfd *, const int); +extern void svc_getreqset(fd_set *); +extern void svc_getreqset2(fd_set *, int); +extern void svc_run(void); +__END_DECLS + +/* + * Socket to use on svcxxx_create call to get default socket + */ +#define RPC_ANYSOCK -1 + +/* + * These are the existing service side transport implementations + */ + +/* + * Memory based rpc for testing and timing. + */ +__BEGIN_DECLS +extern SVCXPRT *svcraw_create(void); +__END_DECLS + + +/* + * Udp based rpc. + */ +__BEGIN_DECLS +extern SVCXPRT *svcudp_create(int); +extern SVCXPRT *svcudp_bufcreate(int, unsigned int, unsigned int); +extern int svcudp_enablecache(SVCXPRT *, u_long); +__END_DECLS + + +/* + * Tcp based rpc. + */ +__BEGIN_DECLS +extern SVCXPRT *svctcp_create(int, unsigned int, unsigned int); +__END_DECLS + +/* + * Fd based rpc. + */ +__BEGIN_DECLS +extern SVCXPRT *svcfd_create(int, unsigned int, unsigned int); +__END_DECLS + +#endif /* !_RPC_SVC_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/rpc/svc_auth.h b/lib/libc/include/generic-openbsd/rpc/svc_auth.h new file mode 100644 index 0000000000..5690dbee09 --- /dev/null +++ b/lib/libc/include/generic-openbsd/rpc/svc_auth.h @@ -0,0 +1 @@ +/* this file intentionally left blank */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/rpc/types.h b/lib/libc/include/generic-openbsd/rpc/types.h new file mode 100644 index 0000000000..50ef3c4dde --- /dev/null +++ b/lib/libc/include/generic-openbsd/rpc/types.h @@ -0,0 +1,66 @@ +/* $OpenBSD: types.h,v 1.3 2010/09/01 14:43:34 millert Exp $ */ +/* $NetBSD: types.h,v 1.8 1995/04/29 05:28:05 cgd Exp $ */ + +/* + * Copyright (c) 2010, Oracle America, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the name of the "Oracle America, Inc." 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT HOLDER 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: @(#)types.h 1.18 87/07/24 SMI + * @(#)types.h 2.3 88/08/15 4.0 RPCSRC + */ + +/* + * Rpc additions to + */ +#ifndef _RPC_TYPES_H +#define _RPC_TYPES_H + +#define bool_t int32_t +#define enum_t int32_t +#define __dontcare__ -1 + +#ifndef FALSE +# define FALSE (0) +#endif +#ifndef TRUE +# define TRUE (1) +#endif +#ifndef NULL +# define NULL 0 +#endif + +#define mem_alloc(bsize) malloc(bsize) +#define mem_free(ptr, bsize) free(ptr) + +#ifndef makedev /* ie, we haven't already included it */ +#include +#endif +#include + +#endif /* !_RPC_TYPES_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/rpc/xdr.h b/lib/libc/include/generic-openbsd/rpc/xdr.h new file mode 100644 index 0000000000..f323aa2721 --- /dev/null +++ b/lib/libc/include/generic-openbsd/rpc/xdr.h @@ -0,0 +1,316 @@ +/* $OpenBSD: xdr.h,v 1.14 2022/12/27 07:44:56 jmc Exp $ */ +/* $NetBSD: xdr.h,v 1.7 1995/04/29 05:28:06 cgd Exp $ */ + +/* + * Copyright (c) 2010, Oracle America, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 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. + * * Neither the name of the "Oracle America, Inc." 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT HOLDER 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: @(#)xdr.h 1.19 87/04/22 SMI + * @(#)xdr.h 2.2 88/07/29 4.0 RPCSRC + */ + +/* + * xdr.h, External Data Representation Serialization Routines. + */ + +#ifndef _RPC_XDR_H +#define _RPC_XDR_H +#include + +/* + * XDR provides a conventional way for converting between C data + * types and an external bit-string representation. Library supplied + * routines provide for the conversion on built-in C data types. These + * routines and utility routines defined here are used to help implement + * a type encode/decode routine for each user-defined type. + * + * Each data type provides a single procedure which takes two arguments: + * + * bool_t + * xdrproc(xdrs, argresp) + * XDR *xdrs; + * *argresp; + * + * xdrs is an instance of a XDR handle, to which or from which the data + * type is to be converted. argresp is a pointer to the structure to be + * converted. The XDR handle contains an operation field which indicates + * which of the operations (ENCODE, DECODE * or FREE) is to be performed. + * + * XDR_DECODE may allocate space if the pointer argresp is null. This + * data can be freed with the XDR_FREE operation. + * + * We write only one procedure per data type to make it easy + * to keep the encode and decode procedures for a data type consistent. + * In many cases the same code performs all operations on a user defined type, + * because all the hard work is done in the component type routines. + * decode as a series of calls on the nested data types. + */ + +/* + * Xdr operations. XDR_ENCODE causes the type to be encoded into the + * stream. XDR_DECODE causes the type to be extracted from the stream. + * XDR_FREE can be used to release the space allocated by an XDR_DECODE + * request. + */ +enum xdr_op { + XDR_ENCODE=0, + XDR_DECODE=1, + XDR_FREE=2 +}; + +/* + * This is the number of bytes per unit of external data. + */ +#define BYTES_PER_XDR_UNIT (4) +#define RNDUP(x) ((((x) + BYTES_PER_XDR_UNIT - 1) / BYTES_PER_XDR_UNIT) \ + * BYTES_PER_XDR_UNIT) + +/* + * The XDR handle. + * Contains operation which is being applied to the stream, + * an operations vector for the particular implementation (e.g. see xdr_mem.c), + * and two private fields for the use of the particular implementation. + */ +typedef struct __rpc_xdr { + enum xdr_op x_op; /* operation; fast additional param */ + const struct xdr_ops { + /* get a long from underlying stream */ + bool_t (*x_getlong)(struct __rpc_xdr *, long *); + /* put a long to " */ + bool_t (*x_putlong)(struct __rpc_xdr *, long *); + /* get some bytes from " */ + bool_t (*x_getbytes)(struct __rpc_xdr *, caddr_t, + unsigned int); + /* put some bytes to " */ + bool_t (*x_putbytes)(struct __rpc_xdr *, caddr_t, + unsigned int); + /* returns bytes off from beginning */ + unsigned int (*x_getpostn)(struct __rpc_xdr *); + /* lets you reposition the stream */ + bool_t (*x_setpostn)(struct __rpc_xdr *, unsigned int); + /* buf quick ptr to buffered data */ + int32_t *(*x_inline)(struct __rpc_xdr *, unsigned int); + /* free privates of this xdr_stream */ + void (*x_destroy)(struct __rpc_xdr *); + bool_t (*x_control)(struct __rpc_xdr *, int, void *); + } *x_ops; + caddr_t x_public; /* users' data */ + caddr_t x_private; /* pointer to private data */ + caddr_t x_base; /* private used for position info */ + unsigned int x_handy; /* extra private word */ +} XDR; + +/* + * A xdrproc_t exists for each data type which is to be encoded or decoded. + * + * The second argument to the xdrproc_t is a pointer to an opaque pointer. + * The opaque pointer generally points to a structure of the data type + * to be decoded. If this pointer is 0, then the type routines should + * allocate dynamic storage of the appropriate size and return it. + * + * XXX can't actually prototype it, because some take three args!!! + */ +typedef bool_t (*xdrproc_t)(/* XDR *, void *, unsigned int */); + +/* + * Operations defined on a XDR handle + * + * XDR *xdrs; + * long *longp; + * caddr_t addr; + * unsigned int len; + * unsigned int pos; + */ +#define XDR_GETLONG(xdrs, longp) \ + (*(xdrs)->x_ops->x_getlong)(xdrs, longp) +#define xdr_getlong(xdrs, longp) \ + (*(xdrs)->x_ops->x_getlong)(xdrs, longp) + +#define XDR_PUTLONG(xdrs, longp) \ + (*(xdrs)->x_ops->x_putlong)(xdrs, longp) +#define xdr_putlong(xdrs, longp) \ + (*(xdrs)->x_ops->x_putlong)(xdrs, longp) + +#define XDR_GETBYTES(xdrs, addr, len) \ + (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len) +#define xdr_getbytes(xdrs, addr, len) \ + (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len) + +#define XDR_PUTBYTES(xdrs, addr, len) \ + (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len) +#define xdr_putbytes(xdrs, addr, len) \ + (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len) + +#define XDR_GETPOS(xdrs) \ + (*(xdrs)->x_ops->x_getpostn)(xdrs) +#define xdr_getpos(xdrs) \ + (*(xdrs)->x_ops->x_getpostn)(xdrs) + +#define XDR_SETPOS(xdrs, pos) \ + (*(xdrs)->x_ops->x_setpostn)(xdrs, pos) +#define xdr_setpos(xdrs, pos) \ + (*(xdrs)->x_ops->x_setpostn)(xdrs, pos) + +#define XDR_INLINE(xdrs, len) \ + (*(xdrs)->x_ops->x_inline)(xdrs, len) +#define xdr_inline(xdrs, len) \ + (*(xdrs)->x_ops->x_inline)(xdrs, len) + +#define XDR_DESTROY(xdrs) \ + if ((xdrs)->x_ops->x_destroy) \ + (*(xdrs)->x_ops->x_destroy)(xdrs) +#define xdr_destroy(xdrs) \ + if ((xdrs)->x_ops->x_destroy) \ + (*(xdrs)->x_ops->x_destroy)(xdrs) + +/* + * Support struct for discriminated unions. + * You create an array of xdrdiscrim structures, terminated with + * a entry with a null procedure pointer. The xdr_union routine gets + * the discriminant value and then searches the array of structures + * for a matching value. If a match is found the associated xdr routine + * is called to handle that part of the union. If there is + * no match, then a default routine may be called. + * If there is no match and no default routine it is an error. + */ +#define NULL_xdrproc_t ((xdrproc_t)0) +struct xdr_discrim { + int value; + xdrproc_t proc; +}; + +/* + * In-line routines for fast encode/decode of primitive data types. + * Caveat emptor: these use single memory cycles to get the + * data from the underlying buffer, and will fail to operate + * properly if the data is not aligned. The standard way to use these + * is to say: + * if ((buf = XDR_INLINE(xdrs, count)) == NULL) + * return (FALSE); + * <<< macro calls >>> + * where ``count'' is the number of bytes of data occupied + * by the primitive data types. + * + * N.B. and frozen for all time: each data type here uses 4 bytes + * of external representation. + */ +#define IXDR_GET_LONG(buf) ((long)ntohl((unsigned long)*(buf)++)) +#define IXDR_PUT_LONG(buf, v) (*(buf)++ = (long)htonl((unsigned long)v)) + +#define IXDR_GET_BOOL(buf) ((bool_t)IXDR_GET_LONG(buf)) +#define IXDR_GET_ENUM(buf, t) ((t)IXDR_GET_LONG(buf)) +#define IXDR_GET_U_LONG(buf) ((unsigned long)IXDR_GET_LONG(buf)) +#define IXDR_GET_SHORT(buf) ((short)IXDR_GET_LONG(buf)) +#define IXDR_GET_U_SHORT(buf) ((unsigned short)IXDR_GET_LONG(buf)) + +#define IXDR_PUT_BOOL(buf, v) IXDR_PUT_LONG((buf), ((long)(v))) +#define IXDR_PUT_ENUM(buf, v) IXDR_PUT_LONG((buf), ((long)(v))) +#define IXDR_PUT_U_LONG(buf, v) IXDR_PUT_LONG((buf), ((long)(v))) +#define IXDR_PUT_SHORT(buf, v) IXDR_PUT_LONG((buf), ((long)(v))) +#define IXDR_PUT_U_SHORT(buf, v) IXDR_PUT_LONG((buf), ((long)(v))) + +/* + * These are the "generic" xdr routines. + */ +__BEGIN_DECLS +extern bool_t xdr_void(void); +extern bool_t xdr_int(XDR *, int *); +extern bool_t xdr_u_int(XDR *, unsigned int *); +extern bool_t xdr_long(XDR *, long *); +extern bool_t xdr_u_long(XDR *, unsigned long *); +extern bool_t xdr_short(XDR *, short *); +extern bool_t xdr_u_short(XDR *, unsigned short *); +extern bool_t xdr_int16_t(XDR *, int16_t *); +extern bool_t xdr_u_int16_t(XDR *, u_int16_t *); +extern bool_t xdr_int32_t(XDR *, int32_t *); +extern bool_t xdr_u_int32_t(XDR *, u_int32_t *); +extern bool_t xdr_int64_t(XDR *, int64_t *); +extern bool_t xdr_u_int64_t(XDR *, u_int64_t *); +extern bool_t xdr_bool(XDR *, bool_t *); +extern bool_t xdr_enum(XDR *, enum_t *); +extern bool_t xdr_array(XDR *, char **, unsigned int *, unsigned int, + unsigned int, xdrproc_t); +extern bool_t xdr_bytes(XDR *, char **, unsigned int *, unsigned int); +extern bool_t xdr_opaque(XDR *, caddr_t, unsigned int); +extern bool_t xdr_string(XDR *, char **, unsigned int); +extern bool_t xdr_union(XDR *, enum_t *, char *, struct xdr_discrim *, + xdrproc_t); +extern bool_t xdr_char(XDR *, char *); +extern bool_t xdr_u_char(XDR *, unsigned char *); +extern bool_t xdr_vector(XDR *, char *, unsigned int, unsigned int, + xdrproc_t); +extern bool_t xdr_float(XDR *, float *); +extern bool_t xdr_double(XDR *, double *); +extern bool_t xdr_reference(XDR *, caddr_t *, unsigned int, xdrproc_t); +extern bool_t xdr_pointer(XDR *, caddr_t *, unsigned int, xdrproc_t); +extern bool_t xdr_wrapstring(XDR *, char **); +extern void xdr_free(xdrproc_t, char *); +__END_DECLS + +/* + * Common opaque bytes objects used by many rpc protocols; + * declared here due to commonality. + */ +#define MAX_NETOBJ_SZ 1024 +struct netobj { + unsigned int n_len; + char *n_bytes; +}; +typedef struct netobj netobj; +extern bool_t xdr_netobj(XDR *, struct netobj *); + +/* + * These are the public routines for the various implementations of + * xdr streams. + */ +__BEGIN_DECLS +/* XDR using memory buffers */ +extern void xdrmem_create(XDR *, char *, unsigned int, enum xdr_op); + +#ifdef _STDIO_H_ +/* XDR using stdio library */ +extern void xdrstdio_create(XDR *, FILE *, enum xdr_op); +#endif + +/* XDR pseudo records for tcp */ +extern void xdrrec_create(XDR *, unsigned int, unsigned int, char *, + int (*)(caddr_t, caddr_t, int), + int (*)(caddr_t, caddr_t, int)); + +/* make end of xdr record */ +extern bool_t xdrrec_endofrecord(XDR *, int); + +/* move to beginning of next record */ +extern bool_t xdrrec_skiprecord(XDR *); + +/* true if no more input */ +extern bool_t xdrrec_eof(XDR *); +__END_DECLS + +#endif /* !_RPC_XDR_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sched.h b/lib/libc/include/generic-openbsd/sched.h new file mode 100644 index 0000000000..423754e631 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sched.h @@ -0,0 +1,75 @@ +/* $OpenBSD: sched.h,v 1.1 2017/10/15 23:40:33 guenther Exp $ */ + +/* sched.h: POSIX 1003.1b Process Scheduling header */ + +/*- + * Copyright (c) 1996, 1997 + * HD Associates, Inc. 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 HD Associates, Inc + * and Jukka Antero Ukkonen. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES 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 HD ASSOCIATES 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 _SCHED_H_ +#define _SCHED_H_ + +#include /* For pid_t */ +#include /* Per P1003.4 */ + +/* Scheduling policies + */ +#define SCHED_FIFO 1 +#define SCHED_OTHER 2 +#define SCHED_RR 3 + +struct sched_param +{ + int sched_priority; +}; + +__BEGIN_DECLS +#if 0 /* not yet */ +int sched_setparam(pid_t, const struct sched_param *); +int sched_getparam(pid_t, struct sched_param *); + +int sched_setscheduler(pid_t, int, const struct sched_param *); +int sched_getscheduler(pid_t); +#endif + +int sched_yield(void); +int sched_get_priority_max(int); +int sched_get_priority_min(int); + +#if 0 /* not yet */ +struct timespec; +int sched_rr_get_interval(pid_t, struct timespec *); +#endif +__END_DECLS + +#endif /* _SCHED_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/scsi/cd.h b/lib/libc/include/generic-openbsd/scsi/cd.h new file mode 100644 index 0000000000..55009f2d69 --- /dev/null +++ b/lib/libc/include/generic-openbsd/scsi/cd.h @@ -0,0 +1,273 @@ +/* $OpenBSD: cd.h,v 1.28 2019/11/29 14:06:21 krw Exp $ */ +/* $NetBSD: scsi_cd.h,v 1.6 1996/03/19 03:06:39 mycroft Exp $ */ + +/* + * Written by Julian Elischer (julian@tfs.com) + * for TRW Financial Systems. + * + * TRW Financial Systems, in accordance with their agreement with Carnegie + * Mellon University, makes this software available to CMU to distribute + * or use in any manner that they see fit as long as this message is kept with + * the software. For this reason TFS also grants any other persons or + * organisations permission to use or modify this software. + * + * TFS supplies this software to be publicly redistributed + * on the understanding that TFS is not responsible for the correct + * functioning of this software in any circumstances. + * + * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 + */ +#ifndef _SCSI_CD_H +#define _SCSI_CD_H + +/* + * Define two bits always in the same place in byte 2 (flag byte) + */ +#define CD_RELADDR 0x01 +#define CD_MSF 0x02 + +/* + * SCSI command format + */ + +struct scsi_blank { + u_int8_t opcode; + u_int8_t byte2; +#define BLANK_DISC 0 +#define BLANK_MINIMAL 1 + u_int8_t addr[4]; + u_int8_t unused[5]; + u_int8_t control; +}; + +struct scsi_close_track { + u_int8_t opcode; + u_int8_t flags; +#define CT_IMMED 1 + u_int8_t closefunc; +#define CT_CLOSE_TRACK 1 +#define CT_CLOSE_SESS 2 +#define CT_CLOSE_BORDER 3 + u_int8_t unused; + u_int8_t track[2]; + u_int8_t unused1[3]; + u_int8_t control; +}; + +struct scsi_pause { + u_int8_t opcode; + u_int8_t byte2; + u_int8_t unused[6]; + u_int8_t resume; + u_int8_t control; +}; +#define PA_PAUSE 1 +#define PA_RESUME 0 + +struct scsi_play_msf { + u_int8_t opcode; + u_int8_t byte2; + u_int8_t unused; + u_int8_t start_m; + u_int8_t start_s; + u_int8_t start_f; + u_int8_t end_m; + u_int8_t end_s; + u_int8_t end_f; + u_int8_t control; +}; + +struct scsi_play_track { + u_int8_t opcode; + u_int8_t byte2; + u_int8_t unused[2]; + u_int8_t start_track; + u_int8_t start_index; + u_int8_t unused1; + u_int8_t end_track; + u_int8_t end_index; + u_int8_t control; +}; + +struct scsi_play { + u_int8_t opcode; + u_int8_t byte2; + u_int8_t blk_addr[4]; + u_int8_t unused; + u_int8_t xfer_len[2]; + u_int8_t control; +}; + +struct scsi_play_big { + u_int8_t opcode; + u_int8_t byte2; /* same as above */ + u_int8_t blk_addr[4]; + u_int8_t xfer_len[4]; + u_int8_t unused; + u_int8_t control; +}; + +struct scsi_play_rel_big { + u_int8_t opcode; + u_int8_t byte2; /* same as above */ + u_int8_t blk_addr[4]; + u_int8_t xfer_len[4]; + u_int8_t track; + u_int8_t control; +}; + +struct scsi_read_header { + u_int8_t opcode; + u_int8_t byte2; + u_int8_t blk_addr[4]; + u_int8_t unused; + u_int8_t data_len[2]; + u_int8_t control; +}; + +struct scsi_read_subchannel { + u_int8_t opcode; + u_int8_t byte2; + u_int8_t byte3; +#define SRS_SUBQ 0x40 + u_int8_t subchan_format; + u_int8_t unused[2]; + u_int8_t track; + u_int8_t data_len[2]; + u_int8_t control; +}; + +struct scsi_read_toc { + u_int8_t opcode; + u_int8_t byte2; + u_int8_t unused[4]; + u_int8_t from_track; + u_int8_t data_len[2]; + u_int8_t control; +}; + +struct scsi_read_track_info { + u_int8_t opcode; + u_int8_t addrtype; +#define RTI_LBA 0 +#define RTI_TRACK 1 +#define RTI_BORDER 2 + u_int8_t addr[4]; + u_int8_t unused; + u_int8_t data_len[2]; + u_int8_t control; +}; + +struct scsi_load_unload { + u_int8_t opcode; + u_int8_t reserved; +#define IMMED 0x1 + u_int8_t reserved2[2]; + u_int8_t options; +#define START 0x1 +#define LOUNLO 0x2 + u_int8_t reserved4[3]; + u_int8_t slot; + u_int8_t reserved5[2]; + u_int8_t control; +}; + +struct scsi_set_cd_speed { + u_int8_t opcode; + u_int8_t rotation; +#define ROTATE_CLV 0 +#define ROTATE_CAV 1 + u_int8_t read[2]; + u_int8_t write[2]; + u_int8_t reserved[5]; + u_int8_t control; +}; + +/* + * Opcodes + */ + +#define READ_SUBCHANNEL 0x42 /* cdrom read Subchannel */ +#define READ_TOC 0x43 /* cdrom read TOC */ +#define READ_HEADER 0x44 /* cdrom read header */ +#define PLAY 0x45 /* cdrom play 'play audio' mode */ +#define PLAY_MSF 0x47 /* cdrom play Min,Sec,Frames mode */ +#define PLAY_TRACK 0x48 /* cdrom play track/index mode */ +#define PLAY_TRACK_REL 0x49 /* cdrom play track/index mode */ +#define PAUSE 0x4b /* cdrom pause in 'play audio' mode */ +#define READ_TRACK_INFO 0x52 /* read track/rzone info */ +#define CLOSE_TRACK 0x5b /* close track/rzone/session/border */ +#define BLANK 0xa1 /* cdrom blank */ +#define PLAY_BIG 0xa5 /* cdrom pause in 'play audio' mode */ +#define LOAD_UNLOAD 0xa6 /* cdrom load/unload media */ +#define PLAY_TRACK_REL_BIG 0xa9 /* cdrom play track/index mode */ +#define SET_CD_SPEED 0xbb /* set cdrom read/write speed */ + +/* + * Mode pages + */ + +#define ERR_RECOVERY_PAGE 0x01 +#define WRITE_PARAM_PAGE 0x05 +#define AUDIO_PAGE 0x0e +#define CDVD_CAPABILITIES_PAGE 0x2a + +struct cd_audio_page { + u_int8_t page_code; +#define CD_PAGE_CODE 0x3F +#define CD_PAGE_PS 0x80 + u_int8_t param_len; + u_int8_t flags; +#define CD_PA_SOTC 0x02 +#define CD_PA_IMMED 0x04 + u_int8_t unused[2]; + u_int8_t format_lba; +#define CD_PA_FORMAT_LBA 0x0F +#define CD_PA_APR_VALID 0x80 + u_int8_t lb_per_sec[2]; + struct port_control { + u_int8_t channels; +#define CHANNEL 0x0F +#define CHANNEL_0 1 +#define CHANNEL_1 2 +#define CHANNEL_2 4 +#define CHANNEL_3 8 +#define LEFT_CHANNEL CHANNEL_0 +#define RIGHT_CHANNEL CHANNEL_1 +#define MUTE_CHANNEL 0x0 +#define BOTH_CHANNEL LEFT_CHANNEL | RIGHT_CHANNEL + u_int8_t volume; + } port[4]; +#define LEFT_PORT 0 +#define RIGHT_PORT 1 +}; + +/* + * There are 2352 bytes in a CD digital audio frame. One frame is 1/75 of a + * second, at 44.1kHz sample rate, 16 bits/sample, 2 channels. + * + * The frame data have the two channels interleaved, with the left + * channel first. Samples are little endian 16-bit signed values. + */ +#define CD_DA_BLKSIZ 2352 /* # bytes in CD-DA frame */ +#define CD_NORMAL_DENSITY_CODE 0x00 /* from Toshiba CD-ROM specs */ +#define CD_DA_DENSITY_CODE 0x82 /* from Toshiba CD-ROM specs */ + +struct scsi_read_dvd_structure { + u_int8_t opcode; /* GPCMD_READ_DVD_STRUCTURE */ + u_int8_t reserved; + u_int8_t address[4]; + u_int8_t layer; + u_int8_t format; + u_int8_t length[2]; + u_int8_t agid; /* bottom 6 bits reserved */ + u_int8_t control; +}; + +struct scsi_read_dvd_structure_data { + u_int8_t len[2]; /* Big-endian length of valid data. */ + u_int8_t reserved[2]; + u_int8_t data[2048]; +}; + +#endif /* _SCSI_CD_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/scsi/iscsi.h b/lib/libc/include/generic-openbsd/scsi/iscsi.h new file mode 100644 index 0000000000..99a0c87a02 --- /dev/null +++ b/lib/libc/include/generic-openbsd/scsi/iscsi.h @@ -0,0 +1,570 @@ +/* $OpenBSD: iscsi.h,v 1.9 2019/09/27 23:07:42 krw Exp $ */ + +/* + * Copyright (c) 2008 David Gwynne + * + * 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 _SCSI_ISCSI_H +#define _SCSI_ISCSI_H + +struct iscsi_pdu { + u_int8_t opcode; + u_int8_t flags; + u_int8_t _reserved1[2]; + + u_int8_t ahslen; + u_int8_t datalen[3]; + + u_int8_t lun[8]; + + u_int32_t itt; + + u_int8_t _reserved2[4]; + + u_int32_t cmdsn; + + u_int32_t expstatsn; + + u_int8_t _reserved3[16]; +} __packed; + +/* + * Initiator opcodes + */ + +#define ISCSI_OP_I_NOP 0x00 +#define ISCSI_OP_SCSI_REQUEST 0x01 +#define ISCSI_OP_TASK_REQUEST 0x02 +#define ISCSI_OP_LOGIN_REQUEST 0x03 +#define ISCSI_OP_TEXT_REQUEST 0x04 +#define ISCSI_OP_DATA_OUT 0x05 +#define ISCSI_OP_LOGOUT_REQUEST 0x06 +#define ISCSI_OP_SNACK_REQUEST 0x10 + +/* + * Target opcodes + */ + +#define ISCSI_OP_T_NOP 0x20 +#define ISCSI_OP_SCSI_RESPONSE 0x21 +#define ISCSI_OP_TASK_RESPONSE 0x22 +#define ISCSI_OP_LOGIN_RESPONSE 0x23 +#define ISCSI_OP_TEXT_RESPONSE 0x24 +#define ISCSI_OP_DATA_IN 0x25 +#define ISCSI_OP_LOGOUT_RESPONSE 0x26 +#define ISCSI_OP_R2T 0x31 +#define ISCSI_OP_ASYNC 0x32 +#define ISCSI_OP_REJECT 0x3f + +#define ISCSI_PDU_OPCODE(_o) ((_o) & 0x3f) +#define ISCSI_PDU_I(_h) ((_h)->opcode & 0x40) +#define ISCSI_PDU_F(_h) ((_h)->flags & 0x80) + +#define ISCSI_OP_F_IMMEDIATE 0x40 + +/* + * various other flags and values + */ +#define ISCSI_ISID_OUI 0x00000000 +#define ISCSI_ISID_EN 0x40000000 +#define ISCSI_ISID_RAND 0x80000000 + +struct iscsi_pdu_scsi_request { + u_int8_t opcode; + u_int8_t flags; + u_int8_t _reserved[2]; + + u_int8_t ahslen; + u_int8_t datalen[3]; + + u_int8_t lun[8]; + + u_int32_t itt; + + u_int32_t bytes; + + u_int32_t cmdsn; + + u_int32_t expstatsn; + + u_int8_t cdb[16]; +} __packed; + +struct iscsi_pdu_scsi_response { + u_int8_t opcode; + u_int8_t flags; + u_int8_t response; + u_int8_t status; + + u_int8_t ahslen; + u_int8_t datalen[3]; + + u_int8_t _reserved[8]; + + u_int32_t itt; + + u_int32_t snack; + + u_int32_t statsn; + + u_int32_t expcmdsn; + + u_int32_t maxcmdsn; + + u_int32_t expdatasn; + + u_int32_t birescount; + + u_int32_t rescount; +} __packed; + +#define ISCSI_SCSI_F_F 0x80 +#define ISCSI_SCSI_F_R 0x40 +#define ISCSI_SCSI_F_W 0x20 + +#define ISCSI_SCSI_ATTR_UNTAGGED 0 +#define ISCSI_SCSI_ATTR_SIMPLE 1 +#define ISCSI_SCSI_ATTR_ORDERED 2 +#define ISCSI_SCSI_ATTR_HEAD_OF_Q 3 +#define ISCSI_SCSI_ATTR_ACA 4 + +#define ISCSI_SCSI_STAT_GOOD 0x00 +#define ISCSI_SCSI_STAT_CHCK_COND 0x02 +/* we don't care about the type of the other error conditions */ + +struct iscsi_pdu_task_request { + u_int8_t opcode; + u_int8_t flags; + u_int8_t reserved[2]; + + u_int8_t ahslen; + u_int8_t datalen[3]; + + u_int8_t lun[8]; + + u_int32_t itt; + + u_int32_t tag; + + u_int32_t cmdsn; + + u_int32_t expstatsn; + + u_int32_t refcmdsn; + + u_int32_t expdatasn; + + u_int8_t _reserved[8]; +} __packed; + +struct iscsi_pdu_task_response { + u_int8_t opcode; + u_int8_t flags; + u_int8_t response; + u_int8_t _reserved1; + + u_int8_t ahslen; + u_int8_t datalen[3]; + + u_int8_t _reserved[8]; + + u_int32_t itt; + + u_int8_t _reserved2[4]; + + u_int32_t statsn; + + u_int32_t expcmdsn; + + u_int32_t maxcmdsn; + + u_int8_t _reserved3[12]; +} __packed; + +struct iscsi_pdu_data_out { + u_int8_t opcode; + u_int8_t flags; + u_int8_t _reserved1[2]; + + u_int8_t ahslen; + u_int8_t datalen[3]; + + u_int8_t lun[8]; + + u_int32_t itt; + + u_int32_t ttt; + + u_int8_t _reserved2[4]; + + u_int32_t expstatsn; + + u_int8_t _reserved3[4]; + + u_int32_t datasn; + + u_int32_t buffer_offs; + + u_int8_t _reserved4[4]; +} __packed; + +struct iscsi_pdu_data_in { + u_int8_t opcode; + u_int8_t flags; + u_int8_t _reserved; + u_int8_t status; + + u_int8_t ahslen; + u_int8_t datalen[3]; + + u_int8_t lun[8]; + + u_int32_t itt; + + u_int32_t ttt; + + u_int32_t statsn; + + u_int32_t expcmdsn; + + u_int32_t maxcmdsn; + + u_int32_t datasn; + + u_int32_t buffer_offs; + + u_int32_t residual; +} __packed; + +struct iscsi_pdu_rt2 { + u_int8_t opcode; + u_int8_t flags; + u_int8_t _reserved1[2]; + + u_int8_t ahslen; + u_int8_t datalen[3]; + + u_int8_t lun[8]; + + u_int32_t itt; + + u_int32_t ttt; + + u_int32_t statsn; + + u_int32_t expcmdsn; + + u_int32_t maxcmdsn; + + u_int32_t r2tsn; + + u_int32_t buffer_offs; + + u_int32_t desired_datalen; +} __packed; + +struct iscsi_pdu_async { + u_int8_t opcode; + u_int8_t flags; + u_int8_t _reserved1[2]; + + u_int8_t ahslen; + u_int8_t datalen[3]; + + u_int8_t lun[8]; + + u_int32_t ffffffff; + + u_int8_t _reserved2[4]; + + u_int32_t statsn; + + u_int32_t expcmdsn; + + u_int32_t maxcmdsn; + + u_int8_t event; + u_int8_t vcode; + u_int16_t param[3]; + + u_int8_t _reserved3[4]; +} __packed; + +struct iscsi_pdu_text_request { + u_int8_t opcode; + u_int8_t flags; + u_int8_t _reserved1[2]; + + u_int8_t ahslen; + u_int8_t datalen[3]; + + u_int8_t lun[8]; + + u_int32_t itt; + + u_int32_t ttt; + + u_int32_t cmdsn; + + u_int32_t expstatsn; + + u_int8_t _reserved2[16]; +} __packed; + +struct iscsi_pdu_text_response { + u_int8_t opcode; + u_int8_t flags; + u_int8_t _reserved1[2]; + + u_int8_t ahslen; + u_int8_t datalen[3]; + + u_int8_t lun[8]; + + u_int32_t itt; + + u_int32_t ttt; + + u_int32_t cmdsn; + + u_int32_t expcmdsn; + + u_int32_t maxcmdsn; + + u_int8_t _reserved2[12]; +} __packed; + +#define ISCSI_TEXT_F_F 0x80 +#define ISCSI_TEXT_F_C 0x40 + +struct iscsi_pdu_login_request { + u_int8_t opcode; + u_int8_t flags; + u_int8_t version_max; + u_int8_t version_min; + + u_int8_t ahslen; + u_int8_t datalen[3]; + + u_int32_t isid_base; + u_int16_t isid_qual; + u_int16_t tsih; + + u_int32_t itt; + + u_int16_t cid; + u_int8_t _reserved1[2]; + + u_int32_t cmdsn; + + u_int32_t expstatsn; + + u_int8_t _reserved2[16]; +} __packed; + +#define ISCSI_LOGIN_F_T 0x80 +#define ISCSI_LOGIN_F_C 0x40 +#define ISCSI_LOGIN_F_CSG(x) (((x) & 0x3) << 2) +#define ISCSI_LOGIN_F_NSG(x) ((x) & 0x3) +#define ISCSI_LOGIN_STG_SECNEG 0 +#define ISCSI_LOGIN_STG_OPNEG 1 +#define ISCSI_LOGIN_STG_FULL 3 + +struct iscsi_pdu_login_response { + u_int8_t opcode; + u_int8_t flags; + u_int8_t version_max; + u_int8_t version_active; + + u_int8_t ahslen; + u_int8_t datalen[3]; + + u_int32_t isid_base; + u_int16_t isid_qual; + u_int16_t tsih; + + u_int32_t itt; + + u_int8_t _reserved1[4]; + + u_int32_t statsn; + + u_int32_t expcmdsn; + + u_int32_t maxcmdsn; + + u_int8_t status_class; + u_int8_t status_detail; + + u_int8_t _reserved2[10]; +} __packed; + +struct iscsi_pdu_logout_request { + u_int8_t opcode; + u_int8_t flags; + u_int8_t _reserved1[2]; + + u_int8_t ahslen; + u_int8_t datalen[3]; + + u_int8_t _reserved2[8]; + + u_int32_t itt; + + u_int16_t cid; + u_int8_t _reserved3[2]; + + u_int32_t cmdsn; + + u_int32_t expstatsn; + + u_int8_t _reserved4[16]; +} __packed; + +#define ISCSI_LOGOUT_F 0x80 +#define ISCSI_LOGOUT_CLOSE_SESS 0 +#define ISCSI_LOGOUT_CLOSE_CONN 1 +#define ISCSI_LOGOUT_RCVRY_CONN 2 + +#define ISCSI_LOGOUT_RESP_SUCCESS 0 +#define ISCSI_LOGOUT_RESP_UNKN_CID 1 +#define ISCSI_LOGOUT_RESP_NO_SUPPORT 2 +#define ISCSI_LOGOUT_RESP_ERROR 3 + +struct iscsi_pdu_logout_response { + u_int8_t opcode; + u_int8_t flags; + u_int8_t response; + u_int8_t _reserved1; + + u_int8_t ahslen; + u_int8_t datalen[3]; + + u_int8_t _reserved2[8]; + + u_int32_t itt; + + u_int8_t _reserved3[4]; + + u_int32_t statsn; + + u_int32_t expcmdsn; + + u_int32_t maxcmdsn; + + u_int8_t _reserved4[4]; + + u_int16_t time2wait; + u_int16_t time2retain; + + u_int8_t _reserved5[4]; +} __packed; + +struct iscsi_pdu_snack_request { + u_int8_t opcode; + u_int8_t flags; + u_int8_t _reserved1[2]; + + u_int8_t ahslen; + u_int8_t datalen[3]; + + u_int8_t lun[8]; + + u_int32_t itt; + + u_int32_t ttt; + + u_int8_t _reserved2[4]; + + u_int32_t expstatsn; + + u_int8_t _reserved3[8]; + + u_int32_t begrun; + + u_int32_t runlength; +} __packed; + +struct iscsi_pdu_reject { + u_int8_t opcode; + u_int8_t flags; + u_int8_t reason; + u_int8_t _reserved1; + + u_int8_t ahslen; + u_int8_t datalen[3]; + + u_int8_t _reserved2[8]; + + u_int32_t ffffffff; + + u_int8_t _reserved3[4]; + + u_int32_t statsn; + + u_int32_t expcmdsn; + + u_int32_t maxcmdsn; + + u_int32_t datasn_r2tsn; + + u_int8_t _reserved4[8]; +} __packed; + +struct iscsi_pdu_nop_out { + u_int8_t opcode; + u_int8_t flags; + u_int8_t _reserved1[2]; + + u_int8_t ahslen; + u_int8_t datalen[3]; + + u_int8_t lun[8]; + + u_int32_t itt; + + u_int32_t ttt; + + u_int32_t cmdsn; + + u_int32_t expstatsn; + + u_int8_t _reserved2[16]; +} __packed; + +struct iscsi_pdu_nop_in { + u_int8_t opcode; + u_int8_t flags; + u_int8_t _reserved1[2]; + + u_int8_t ahslen; + u_int8_t datalen[3]; + + u_int8_t lun[8]; + + u_int32_t itt; + + u_int32_t ttt; + + u_int32_t statsn; + + u_int32_t expcmdsn; + + u_int32_t maxcmdsn; + + u_int8_t _reserved2[12]; +} __packed; + +#endif /* _SCSI_ISCSI_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/scsi/mpathvar.h b/lib/libc/include/generic-openbsd/scsi/mpathvar.h new file mode 100644 index 0000000000..46ed0f70cd --- /dev/null +++ b/lib/libc/include/generic-openbsd/scsi/mpathvar.h @@ -0,0 +1,59 @@ +/* $OpenBSD: mpathvar.h,v 1.10 2019/09/27 23:07:42 krw Exp $ */ + +/* + * Copyright (c) 2010 David Gwynne + * + * 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 _SCSI_MPATHVAR_H +#define _SCSI_MPATHVAR_H + +struct mpath_group; + +struct mpath_ops { + char op_name[16]; + int (*op_checksense)(struct scsi_xfer *); + void (*op_status)(struct scsi_link *); +}; + +#define MPATH_SENSE_DECLINED 0 /* path driver declined to interpret sense */ +#define MPATH_SENSE_FAILOVER 1 /* sense says controllers have failed over */ + +#define MPATH_S_UNKNOWN -1 +#define MPATH_S_ACTIVE 0 +#define MPATH_S_PASSIVE 1 + +struct mpath_path { + /* the path driver must set these */ + struct scsi_xshandler p_xsh; + struct scsi_link *p_link; + int p_gid; + + /* the following are private to mpath.c */ + TAILQ_ENTRY(mpath_path) p_entry; + struct mpath_group *p_group; + int p_state; +}; + +int mpath_path_probe(struct scsi_link *); +int mpath_path_attach(struct mpath_path *, u_int, + const struct mpath_ops *); +void mpath_path_status(struct mpath_path *, int); +int mpath_path_detach(struct mpath_path *); + +void mpath_start(struct mpath_path *, struct scsi_xfer *); + +struct device *mpath_bootdv(struct device *); + +#endif /* _SCSI_MPATHVAR_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/scsi/safte.h b/lib/libc/include/generic-openbsd/scsi/safte.h new file mode 100644 index 0000000000..ea22b5f55d --- /dev/null +++ b/lib/libc/include/generic-openbsd/scsi/safte.h @@ -0,0 +1,171 @@ +/* $OpenBSD: safte.h,v 1.9 2020/09/12 15:54:51 krw Exp $ */ + +/* + * Copyright (c) 2005 David Gwynne + * + * 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 _SCSI_SAFTE_H +#define _SCSI_SAFTE_H + +/* scsi_inquiry_data.extra */ +struct safte_inq { + u_int8_t uniqueid[7]; + u_int8_t chanid; + u_int8_t ident[6]; +#define SAFTE_IDENT "SAF-TE" +}; + +struct safte_readbuf_cmd { + u_int8_t opcode; /* READ_BUFFER */ + u_int8_t flags; +#define SAFTE_RD_LUNMASK 0xe0 /* the lun should always be 0 */ +#define SAFTE_RD_MODEMASK 0x07 +#define SAFTE_RD_MODE 0x01 /* 0x01 is the SAF-TE command mode */ + u_int8_t bufferid; +#define SAFTE_RD_CONFIG 0x00 /* enclosure configuration */ +#define SAFTE_RD_ENCSTAT 0x01 /* enclosure status */ +#define SAFTE_RD_USAGE 0x02 /* usage statistics */ +#define SAFTE_RD_INSERTS 0x03 /* device insertions */ +#define SAFTE_RD_SLOTSTAT 0x04 /* slot status */ +#define SAFTE_RD_GLOBALS 0x05 /* global flags */ + u_int32_t reserved1; + u_int16_t length; /* transfer length (big endian) */ + u_int8_t reserved2; +} __packed; + +struct safte_writebuf_cmd { + u_int8_t opcode; /* WRITE_BUFFER */ + u_int8_t flags; +#define SAFTE_WR_LUNMASK 0xe0 /* the lun should always be 0 */ +#define SAFTE_WR_MODEMASK 0x07 +#define SAFTE_WR_MODE 0x01 /* 0x01 is the SAF-TE command mode */ + u_int8_t reserved1[5]; + u_int16_t length; /* transfer length (big endian) */ + u_int8_t reserved2; +} __packed; + +#define SAFTE_WRITE_SLOTSTAT 0x10 /* write device slot status */ +#define SAFTE_WRITE_SETID 0x11 /* set scsi id */ +#define SAFTE_WRITE_SLOTOP 0x12 /* perform slot operation */ +#define SAFTE_WRITE_FANSPEED 0x13 /* set fan speed */ +#define SAFTE_WRITE_PWRSUP 0x14 /* activate power supply */ +#define SAFTE_WRITE_GLOBALS 0x15 /* global flags */ + + +/* enclosure configuration */ +struct safte_config { + u_int8_t nfans; /* number of fans */ + u_int8_t npwrsup; /* number of power supplies */ + u_int8_t nslots; /* number of device slots */ + u_int8_t doorlock; /* door lock installed */ + u_int8_t ntemps; /* number of temp sensors */ + u_int8_t alarm; /* audible alarm installed */ + u_int8_t therm; /* temps in C and num of thermostats */ +#define SAFTE_CFG_CELSIUSMASK 0x80 +#define SAFTE_CFG_CELSIUS(a) ((a) & SAFTE_CFG_CELSIUSMASK ? 1 : 0) +#define SAFTE_CFG_NTHERMMASK 0x0f +#define SAFTE_CFG_NTHERM(a) ((a) & SAFTE_CFG_NTHERMMASK) + u_int8_t reserved[56]; /* 7 to 62 */ + u_int8_t vendor_bytes; /* number of vendor specific bytes */ +} __packed; +#define SAFTE_CONFIG_LEN sizeof(struct safte_config) + +/* enclosure status fields */ +/* fan status field */ +#define SAFTE_FAN_OP 0x00 /* operational */ +#define SAFTE_FAN_MF 0x01 /* malfunctioning */ +#define SAFTE_FAN_NOTINST 0x02 /* not installed */ +#define SAFTE_FAN_UNKNOWN 0x80 /* unknown status or unreportable */ + +/* power supply status field */ +#define SAFTE_PWR_OP_ON 0x00 /* operational and on */ +#define SAFTE_PWR_OP_OFF 0x01 /* operational and off */ +#define SAFTE_PWR_MF_ON 0x10 /* malfunctioning and on */ +#define SAFTE_PWR_MF_OFF 0x11 /* malfunctioning and off */ +#define SAFTE_PWR_NOTINST 0x20 /* not present */ +#define SAFTE_PWR_PRESENT 0x21 /* present */ +#define SAFTE_PWR_UNKNOWN 0x80 /* unknown status or unreportable */ + +/* scsi id fields */ +/* are integers, not bitfields */ + +/* door lock status */ +#define SAFTE_DOOR_LOCKED 0x00 /* locked */ +#define SAFTE_DOOR_UNLOCKED 0x01 /* unlocked or uncontrollable */ +#define SAFTE_DOOR_UNKNOWN 0x80 /* unknown status or unreportable */ + +/* speaker status */ +#define SAFTE_SPKR_OFF 0x00 /* off or not installed */ +#define SAFTE_SPKR_ON 0x01 /* speaker is currently on */ + +/* temperature */ +#define SAFTE_TEMP_OFFSET -10 /* -10 to 245 degrees */ + +/* temp out of range */ +#define SAFTE_TEMP_ETA 0x8000 /* any temp alert */ + + +/* usage statistics */ +struct safte_usage { + u_int32_t minutes; /* total number of minutes on */ + u_int32_t cycles; /* total number of power cycles */ + u_int8_t reserved[7]; + u_int8_t vendor_bytes; /* number of vendor specific bytes */ +}; + + +/* device insertions */ +/* u_int16_t * nslots */ + + +/* device slot status */ +#define SAFTE_SLOTSTAT_INSERT (1<<0) /* inserted */ +#define SAFTE_SLOTSTAT_SWAP (1<<1) /* ready to be inserted/removed */ +#define SAFTE_SLOTSTAT_OPER (1<<2) /* ready for operation */ + + +/* global flags */ +struct safte_globals { + u_int8_t flags1; +#define SAFTE_GLOBAL_ALARM (1<<0) /* audible alarm */ +#define SAFTE_GLOBAL_FAILURE (1<<1) /* global failure indication */ +#define SAFTE_GLOBAL_WARNING (1<<2) /* global warning indication */ +#define SAFTE_GLOBAL_POWER (1<<3) /* enclosure power */ +#define SAFTE_GLOBAL_COOLING (1<<4) /* cooling failure */ +#define SAFTE_GLOBAL_PWRFAIL (1<<5) /* power failure */ +#define SAFTE_GLOBAL_DRVFAIL (1<<6) /* drive failure */ +#define SAFTE_GLOBAL_DRVWARN (1<<6) /* drive warning */ + u_int8_t flags2; +#define SAFTE_GLOBAL_ARRAYFAIL (1<<0) /* array failure */ +#define SAFTE_GLOBAL_ARRAYWARN (1<<1) /* array warning */ +#define SAFTE_GLOBAL_LOCK (1<<2) /* enclosure lock */ +#define SAFTE_GLOBAL_IDENTIFY (1<<3) /* identify enclosure */ + u_int8_t flags3; + u_int8_t reserved[13]; +}; + + +/* perform slot operation */ +struct safte_slotop { + u_int8_t opcode; /* SAFTE_WRITE_SLOTOP */ + u_int8_t slot; + u_int8_t flags; +#define SAFTE_SLOTOP_OPERATE (1<<0) /* prepare for operation */ +#define SAFTE_SLOTOP_INSREM (1<<1) /* prepare for insert/removal */ +#define SAFTE_SLOTOP_IDENTIFY (1<<2) /* identify */ + u_int8_t reserved[61]; /* zero these */ +} __packed; + +#endif /* _SCSI_SAFTE_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/scsi/scsi_all.h b/lib/libc/include/generic-openbsd/scsi/scsi_all.h new file mode 100644 index 0000000000..80ac85b5ae --- /dev/null +++ b/lib/libc/include/generic-openbsd/scsi/scsi_all.h @@ -0,0 +1,663 @@ +/* $OpenBSD: scsi_all.h,v 1.65 2022/01/11 23:10:11 jsg Exp $ */ +/* $NetBSD: scsi_all.h,v 1.10 1996/09/12 01:57:17 thorpej Exp $ */ + +/* + * SCSI general interface description + */ + +/* + * Largely written by Julian Elischer (julian@tfs.com) + * for TRW Financial Systems. + * + * TRW Financial Systems, in accordance with their agreement with Carnegie + * Mellon University, makes this software available to CMU to distribute + * or use in any manner that they see fit as long as this message is kept with + * the software. For this reason TFS also grants any other persons or + * organisations permission to use or modify this software. + * + * TFS supplies this software to be publicly redistributed + * on the understanding that TFS is not responsible for the correct + * functioning of this software in any circumstances. + * + * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 + */ + +#ifndef _SCSI_SCSI_ALL_H +#define _SCSI_SCSI_ALL_H + +/* + * SCSI command format + */ + +/* + * Define some bits that are in ALL (or a lot of) scsi commands + */ +#define SCSI_CTL_LINK 0x01 +#define SCSI_CTL_FLAG 0x02 +#define SCSI_CTL_VENDOR 0xC0 + + +/* + * Some old SCSI devices need the LUN to be set in the top 3 bits of the + * second byte of the CDB. + */ +#define SCSI_CMD_LUN_MASK 0xe0 +#define SCSI_CMD_LUN_SHIFT 5 + + +struct scsi_generic { + u_int8_t opcode; + u_int8_t bytes[15]; +}; + +struct scsi_test_unit_ready { + u_int8_t opcode; + u_int8_t byte2; + u_int8_t unused[3]; + u_int8_t control; +}; + +struct scsi_send_diag { + u_int8_t opcode; + u_int8_t byte2; +#define SSD_UOL 0x01 +#define SSD_DOL 0x02 +#define SSD_SELFTEST 0x04 +#define SSD_PF 0x10 + u_int8_t unused[1]; + u_int8_t paramlen[2]; + u_int8_t control; +}; + +struct scsi_sense { + u_int8_t opcode; + u_int8_t byte2; + u_int8_t unused[2]; + u_int8_t length; + u_int8_t control; +}; + +struct scsi_inquiry { + u_int8_t opcode; + u_int8_t flags; +#define SI_EVPD 0x01 + u_int8_t pagecode; +#define SI_PG_SUPPORTED 0x00 +#define SI_PG_SERIAL 0x80 +#define SI_PG_DEVID 0x83 +#define SI_PG_ATA 0x89 + u_int8_t length[2]; + u_int8_t control; +}; + +struct scsi_mode_sense { + u_int8_t opcode; + u_int8_t byte2; +#define SMS_DBD 0x08 /* Disable Block Descriptors */ + u_int8_t page; +#define SMS_PAGE_CODE 0x3F +#define SMS_PAGE_CTRL 0xC0 +#define SMS_PAGE_CTRL_CURRENT 0x00 +#define SMS_PAGE_CTRL_CHANGEABLE 0x40 +#define SMS_PAGE_CTRL_DEFAULT 0x80 +#define SMS_PAGE_CTRL_SAVED 0xC0 + u_int8_t unused; + u_int8_t length; + u_int8_t control; +}; + +struct scsi_mode_sense_big { + u_int8_t opcode; + u_int8_t byte2; /* same bits as small version */ +#define SMS_LLBAA 0x10 /* plus: Long LBA Accepted */ + u_int8_t page; /* same bits as small version */ + u_int8_t unused[4]; + u_int8_t length[2]; + u_int8_t control; +}; + +struct scsi_mode_select { + u_int8_t opcode; + u_int8_t byte2; +#define SMS_SP 0x01 +#define SMS_PF 0x10 + u_int8_t unused[2]; + u_int8_t length; + u_int8_t control; +}; + +struct scsi_mode_select_big { + u_int8_t opcode; + u_int8_t byte2; /* same bits as small version */ + u_int8_t unused[5]; + u_int8_t length[2]; + u_int8_t control; +}; + +struct scsi_reserve { + u_int8_t opcode; + u_int8_t byte2; + u_int8_t unused[2]; + u_int8_t length; + u_int8_t control; +}; + +struct scsi_release { + u_int8_t opcode; + u_int8_t byte2; + u_int8_t unused[2]; + u_int8_t length; + u_int8_t control; +}; + +struct scsi_prevent { + u_int8_t opcode; + u_int8_t byte2; + u_int8_t unused[2]; + u_int8_t how; + u_int8_t control; +}; +#define PR_PREVENT 0x01 +#define PR_ALLOW 0x00 + +struct scsi_report_luns { + u_int8_t opcode; + u_int8_t unused; + u_int8_t selectreport; +#define REPORT_NORMAL 0x00 +#define REPORT_WELLKNOWN 0x01 +#define REPORT_ALL 0x02 + u_int8_t unused2[3]; + u_int8_t length[4]; + u_int8_t unused4; + u_int8_t control; +}; + +/* + * Opcodes + */ +#define TEST_UNIT_READY 0x00 +#define REQUEST_SENSE 0x03 +#define INQUIRY 0x12 +#define MODE_SELECT 0x15 +#define RESERVE 0x16 +#define RELEASE 0x17 +#define MODE_SENSE 0x1a +#define START_STOP 0x1b +#define RECEIVE_DIAGNOSTIC 0x1c +#define SEND_DIAGNOSTIC 0x1d +#define PREVENT_ALLOW 0x1e +#define POSITION_TO_ELEMENT 0x2b +#define WRITE_BUFFER 0x3b +#define READ_BUFFER 0x3c +#define CHANGE_DEFINITION 0x40 +#define MODE_SELECT_BIG 0x55 +#define MODE_SENSE_BIG 0x5a +#define REPORT_LUNS 0xa0 + +/* + * Sort of an extra one, for SCSI_RESET. + */ +#define GENRETRY 1 + +/* + * Device Types + */ +#define T_DIRECT 0x00 /* Direct access block device (SBC-4) */ +#define T_SEQUENTIAL 0x01 /* Sequential access device (SSC-3) */ +#define T_PRINTER 0x02 /* Printer device (SSC) */ +#define T_PROCESSOR 0x03 /* Processor device (SPC-2) */ +#define T_WORM 0x04 /* Write once device (SBC) */ +#define T_CDROM 0x05 /* CD/DVD device (MMC-5) */ +#define T_SCANNER 0x06 /* Scanner device (Obsolete) */ +#define T_OPTICAL 0x07 /* Optical memory device (SBC) */ +#define T_CHANGER 0x08 /* Media changer device (SMC-3) */ +#define T_COMM 0x09 /* Communications device (Obsolete) */ +#define T_ASC0 0x0a /* Obsolete */ +#define T_ASC1 0x0b /* Obsolete */ +#define T_STORARRAY 0x0c /* Storage Array controller device (RAID) */ +#define T_ENCLOSURE 0x0d /* Enclosure services device (SES) */ +#define T_RDIRECT 0x0e /* Simplified direct access device (RBC) */ +#define T_OCRW 0x0f /* Optical card reader/writer (OCRW) */ +#define T_BCC 0x10 /* Bridge Controller Commands (BCC) */ +#define T_OSD 0x11 /* Object-based Storage device (OSD) */ +#define T_ADC 0x12 /* Automation/Drive Interface (ADC-2) */ +/* 0x13 - 0x1d RESERVED */ +#define T_WELL_KNOWN_LU 0x1e /* Well known logical unit */ +#define T_NODEVICE 0x1F /* Unknown or no device type */ + +#define T_REMOV 1 +#define T_FIXED 0 + +struct scsi_inquiry_data { + u_int8_t device; +#define SID_TYPE 0x1f +#define SID_QUAL 0xe0 +#define SID_QUAL_LU_OK 0x00 +#define SID_QUAL_LU_OFFLINE 0x20 +#define SID_QUAL_RSVD 0x40 +#define SID_QUAL_BAD_LU 0x60 + u_int8_t dev_qual2; +#define SID_QUAL2 0x7f +#define SID_REMOVABLE 0x80 + u_int8_t version; +#define SID_ANSII 0x07 +#define SID_ECMA 0x38 +#define SID_ISO 0xc0 + u_int8_t response_format; +#define SID_RESPONSE_DATA_FMT 0x0f /* < 2 == obsolete, > 2 reserved! */ +#define SID_SCSI2_RESPONSE 0x02 +#define SID_HiSup 0x10 /* Hierarchical LUNs */ +#define SID_NormACA 0x20 /* Normal ACA bit in CCB supported */ +#define SID_TrmIOP 0x40 /* obsolete */ +#define SID_AENC 0x80 /* obsolete */ + u_int8_t additional_length; +#define SID_SCSI2_HDRLEN 5 /* Bytes up to & including additional_length */ +#define SID_SCSI2_ALEN 31 /* Additional bytes of basic SCSI2 info */ + u_int8_t spc3_flags; +#define SPC3_SID_PROTECT 0x01 /* 0 == Type 0, 1 == Type 1, 2 or 3 */ +#define SPC3_SID_RESERVED 0x06 +#define SPC3_SID_3PC 0x08 /* 3rd party copy */ +#define SPC3_SID_TPGS_IMPLICIT 0x10 /* Implicit asymmetric LU access */ +#define SPC3_SID_TPGS_EXPLICIT 0x20 /* Explicit asymmetric LU access */ +#define SPC3_SID_ACC 0x40 /* Access controls controller */ +#define SPC3_SID_SCCS 0x80 /* Embedded storage array controller */ + u_int8_t spc2_flags; +#define SPC2_SID_ADDR16 0x01 /* obsolete */ +#define SPC2_RESERVED 0x06 +#define SPC2_SID_NChngr 0x08 /* obsolete */ +#define SPC2_SID_MultiP 0x10 /* multi-port target */ +#define SPC2_VS 0x20 /* ??? */ +#define SPC2_SID_EncServ 0x40 /* Embedded enclosure services */ +#define SPC2_SID_BQueue 0x80 /* obsolete */ + u_int8_t flags; +#define SID_VS 0x01 /* ??? */ +#define SID_CmdQue 0x02 /* Task management mode supported */ +#define SID_Linked 0x08 /* obsolete */ +#define SID_Sync 0x10 /* obsolete */ +#define SID_WBus16 0x20 /* obsolete */ +#define SID_WBus32 0x40 /* obsolete */ +#define SID_RelAdr 0x80 /* obsolete */ + char vendor[8]; + char product[16]; + char revision[4]; + u_int8_t extra[20]; + u_int8_t reserved[2]; + u_int8_t version_descriptor0[2]; + u_int8_t version_descriptor1[2]; + u_int8_t version_descriptor2[2]; + u_int8_t version_descriptor3[2]; + u_int8_t version_descriptor4[2]; + u_int8_t version_descriptor5[2]; + u_int8_t version_descriptor6[2]; + u_int8_t version_descriptor7[2]; + u_int8_t reserved2[22]; +}; + +struct scsi_vpd_hdr { + u_int8_t device; + u_int8_t page_code; + u_int8_t page_length[2]; +}; + +struct scsi_vpd_serial { + struct scsi_vpd_hdr hdr; + char serial[32]; +}; + +#define VPD_PROTO_ID_FC 0x0 /* Fibre Channel */ +#define VPD_PROTO_ID_SPI 0x1 /* Parallel SCSI */ +#define VPD_PROTO_ID_SSA 0x2 +#define VPD_PROTO_ID_IEEE1394 0x3 +#define VPD_PROTO_ID_SRP 0x4 /* SCSI RDMA Protocol */ +#define VPD_PROTO_ID_ISCSI 0x5 /* Internet SCSI (iSCSI) */ +#define VPD_PROTO_ID_SAS 0x6 /* Serial Attached SCSI */ +#define VPD_PROTO_ID_ADT 0x7 /* Automation/Drive Interface Transport */ +#define VPD_PROTO_ID_ATA 0x7 /* ATA/ATAPI */ +#define VPD_PROTO_ID_NONE 0xf + +struct scsi_vpd_devid_hdr { + u_int8_t pi_code; +#define VPD_DEVID_PI(_f) (((_f) >> 4) & 0x0f) +#define VPD_DEVID_CODE(_f) (((_f) >> 0) & 0x0f) +#define VPD_DEVID_CODE_BINARY 0x1 +#define VPD_DEVID_CODE_ASCII 0x2 +#define VPD_DEVID_CODE_UTF8 0x3 + u_int8_t flags; +#define VPD_DEVID_PIV 0x80 +#define VPD_DEVID_ASSOC(_f) ((_f) & 0x30) +#define VPD_DEVID_ASSOC_LU 0x00 +#define VPD_DEVID_ASSOC_PORT 0x10 +#define VPD_DEVID_ASSOC_TARG 0x20 +#define VPD_DEVID_TYPE(_f) ((_f) & 0x0f) +#define VPD_DEVID_TYPE_VENDOR 0x0 +#define VPD_DEVID_TYPE_T10 0x1 +#define VPD_DEVID_TYPE_EUI64 0x2 +#define VPD_DEVID_TYPE_NAA 0x3 +#define VPD_DEVID_TYPE_RELATIVE 0x4 +#define VPD_DEVID_TYPE_PORT 0x5 +#define VPD_DEVID_TYPE_LU 0x6 +#define VPD_DEVID_TYPE_MD5 0x7 +#define VPD_DEVID_TYPE_NAME 0x8 + u_int8_t reserved; + u_int8_t len; +}; + +struct scsi_vpd_ata { + struct scsi_vpd_hdr hdr; + + u_int8_t _reserved1[4]; + u_int8_t sat_vendor[8]; + u_int8_t sat_product[16]; + u_int8_t sat_revision[4]; + u_int8_t device_signature[20]; + u_int8_t command_code; +#define VPD_ATA_COMMAND_CODE_ATA 0xec +#define VPD_ATA_COMMAND_CODE_ATAPI 0xa1 + u_int8_t _reserved2[3]; + u_int8_t identify[512]; +}; + +struct scsi_read_cap_data { + u_int8_t addr[4]; + u_int8_t length[4]; +}; + +struct scsi_read_cap_data_16 { + u_int8_t addr[8]; + u_int8_t length[4]; + u_int8_t p_type_prot; +#define RC16_PROT_EN 0x01 /* Protection type is 0 when 0 */ +#define RC16_PROT_P_TYPE 0x0e +#define RC16_P_TYPE_1 0x00 /* Protection type 1 */ +#define RC16_P_TYPE_2 0x02 /* Protection type 2 */ +#define RC16_P_TYPE_3 0x04 /* Protection type 3 */ +#define RC16_BASIS 0x30 /* Meaning of addr */ +#define RC16_BASIS_HIGH 0x00 /* highest LBA of zone */ +#define RC16_BASIS_LAST 0x10 /* last LBA on unit */ + u_int8_t logical_per_phys; /* Logical Blks Per Physical Blk Exp */ +#define RC16_LBPPB_EXPONENT 0x0f /* 2**N LB per PB, 0 means unknown */ +#define RC16_PIIPLB_EXPONENT 0xf0 /* 2**N Prot info intervals per LB */ + u_int8_t lowest_aligned[2]; +#define RC16_LALBA 0x3fff /* lowest aligned LBA */ +#define RC16_LBPRZ 0x4000 /* unmapped LBA returns all zeros */ +#define READ_CAP_16_TPRZ 0x4000 /* XXX old name used in driver(s) */ +#define RC16_LBPME 0x8000 /* LB provisioning management enabled */ +#define READ_CAP_16_TPE 0x8000 /* XXX old name used in driver(s) */ + u_int8_t reserved[16]; +}; + +struct scsi_sense_data_unextended { +/* 1*/ u_int8_t error_code; +/* 4*/ u_int8_t block[3]; +}; + +struct scsi_sense_data { +/* 1*/ u_int8_t error_code; +#define SSD_ERRCODE_CURRENT 0x70 +#define SSD_ERRCODE_DEFERRED 0x71 +#define SSD_ERRCODE 0x7F +#define SSD_ERRCODE_VALID 0x80 +/* 2*/ u_int8_t segment; +/* 3*/ u_int8_t flags; +#define SSD_KEY 0x0F +#define SSD_ILI 0x20 +#define SSD_EOM 0x40 +#define SSD_FILEMARK 0x80 +/* 7*/ u_int8_t info[4]; +/* 8*/ u_int8_t extra_len; +/*12*/ u_int8_t cmd_spec_info[4]; +/*13*/ u_int8_t add_sense_code; +/*14*/ u_int8_t add_sense_code_qual; +/*15*/ u_int8_t fru; +/*16*/ u_int8_t sense_key_spec_1; +#define SSD_SCS_VALID 0x80 +#define SSD_SCS_CDB_ERROR 0x40 +#define SSD_SCS_SEGMENT_DESC 0x20 +#define SSD_SCS_VALID_BIT_INDEX 0x08 +#define SSD_SCS_BIT_INDEX 0x07 +/*17*/ u_int8_t sense_key_spec_2; +/*18*/ u_int8_t sense_key_spec_3; +}; + +#define SKEY_NO_SENSE 0x00 +#define SKEY_RECOVERED_ERROR 0x01 +#define SKEY_NOT_READY 0x02 +#define SKEY_MEDIUM_ERROR 0x03 +#define SKEY_HARDWARE_ERROR 0x04 +#define SKEY_ILLEGAL_REQUEST 0x05 +#define SKEY_UNIT_ATTENTION 0x06 +#define SKEY_WRITE_PROTECT 0x07 +#define SKEY_BLANK_CHECK 0x08 +#define SKEY_VENDOR_UNIQUE 0x09 +#define SKEY_COPY_ABORTED 0x0A +#define SKEY_ABORTED_COMMAND 0x0B +#define SKEY_EQUAL 0x0C +#define SKEY_VOLUME_OVERFLOW 0x0D +#define SKEY_MISCOMPARE 0x0E +#define SKEY_RESERVED 0x0F + + +/* Additional sense code info */ +#define ASC_ASCQ(ssd) ((ssd->add_sense_code << 8) | ssd->add_sense_code_qual) + +#define SENSE_FILEMARK_DETECTED 0x0001 +#define SENSE_END_OF_MEDIUM_DETECTED 0x0002 +#define SENSE_SETMARK_DETECTED 0x0003 +#define SENSE_BEGINNING_OF_MEDIUM_DETECTED 0x0004 +#define SENSE_END_OF_DATA_DETECTED 0x0005 +#define SENSE_NOT_READY_BECOMING_READY 0x0401 +#define SENSE_NOT_READY_INIT_REQUIRED 0x0402 +#define SENSE_NOT_READY_FORMAT 0x0404 +#define SENSE_NOT_READY_REBUILD 0x0405 +#define SENSE_NOT_READY_RECALC 0x0406 +#define SENSE_NOT_READY_INPROGRESS 0x0407 +#define SENSE_NOT_READY_LONGWRITE 0x0408 +#define SENSE_NOT_READY_SELFTEST 0x0409 +#define SENSE_POWER_RESET_OR_BUS 0x2900 +#define SENSE_POWER_ON 0x2901 +#define SENSE_BUS_RESET 0x2902 +#define SENSE_BUS_DEVICE_RESET 0x2903 +#define SENSE_DEVICE_INTERNAL_RESET 0x2904 +#define SENSE_TSC_CHANGE_SE 0x2905 +#define SENSE_TSC_CHANGE_LVD 0x2906 +#define SENSE_IT_NEXUS_LOSS 0x2907 +#define SENSE_BAD_MEDIUM 0x3000 +#define SENSE_NR_MEDIUM_UNKNOWN_FORMAT 0x3001 +#define SENSE_NR_MEDIUM_INCOMPATIBLE_FORMAT 0x3002 +#define SENSE_NW_MEDIUM_UNKNOWN_FORMAT 0x3004 +#define SENSE_NW_MEDIUM_INCOMPATIBLE_FORMAT 0x3005 +#define SENSE_NF_MEDIUM_INCOMPATIBLE_FORMAT 0x3006 +#define SENSE_NW_MEDIUM_AC_MISMATCH 0x3008 +#define SENSE_NOMEDIUM 0x3A00 +#define SENSE_NOMEDIUM_TCLOSED 0x3A01 +#define SENSE_NOMEDIUM_TOPEN 0x3A02 +#define SENSE_NOMEDIUM_LOADABLE 0x3A03 +#define SENSE_NOMEDIUM_AUXMEM 0x3A04 +#define SENSE_CARTRIDGE_FAULT 0x5200 +#define SENSE_MEDIUM_REMOVAL_PREVENTED 0x5302 + +struct scsi_blk_desc { + u_int8_t density; + u_int8_t nblocks[3]; + u_int8_t reserved; + u_int8_t blklen[3]; +}; + +struct scsi_direct_blk_desc { + u_int8_t nblocks[4]; + u_int8_t density; + u_int8_t blklen[3]; +}; + +struct scsi_blk_desc_big { + u_int8_t nblocks[8]; + u_int8_t density; + u_int8_t reserved[3]; + u_int8_t blklen[4]; +}; + +struct scsi_mode_header { + u_int8_t data_length; /* Sense data length */ + u_int8_t medium_type; + u_int8_t dev_spec; + u_int8_t blk_desc_len; +}; +#define VALID_MODE_HDR(_x) ((_x)->data_length >= 3) + +struct scsi_mode_header_big { + u_int8_t data_length[2]; /* Sense data length */ + u_int8_t medium_type; + u_int8_t dev_spec; + u_int8_t reserved; +#define LONGLBA 0x01 + u_int8_t reserved2; + u_int8_t blk_desc_len[2]; +}; +#define VALID_MODE_HDR_BIG(_x) (_2btol((_x)->data_length) >= 6) + +/* Both disks and tapes use dev_spec to report READONLY status. */ +#define SMH_DSP_WRITE_PROT 0x80 + +union scsi_mode_sense_buf { + struct scsi_mode_header hdr; + struct scsi_mode_header_big hdr_big; + u_char buf[254]; /* 255 & 256 bytes breaks some devices. */ + /* ahci doesn't like 255, various don't like */ + /* 256 because length must fit in 8 bits. */ +} __packed; /* Ensure sizeof() is 254! */ + +struct scsi_report_luns_data { + u_int8_t length[4]; /* length of LUN inventory, in bytes */ + u_int8_t reserved[4]; /* unused */ + /* + * LUN inventory- we only support the type zero form for now. + */ +#define RPL_LUNDATA_SIZE 8 /* Bytes per lun */ + struct { + u_int8_t lundata[RPL_LUNDATA_SIZE]; + } luns[256]; /* scsi_link->luns is u_int8_t. */ +}; +#define RPL_LUNDATA_T0LUN 1 /* Type 0 LUN is in lundata[1] */ + +struct scsi_lun_array { + uint8_t luns[256]; + int count; + int dumbscan; +}; + +/* + * ATA PASS-THROUGH as per SAT2 + */ + +#define ATA_PASSTHRU_12 0xa1 +#define ATA_PASSTHRU_16 0x85 + +#define ATA_PASSTHRU_PROTO_MASK 0x1e +#define ATA_PASSTHRU_PROTO_HW_RESET 0x00 +#define ATA_PASSTHRU_PROTO_SW_RESET 0x02 +#define ATA_PASSTHRU_PROTO_NON_DATA 0x06 +#define ATA_PASSTHRU_PROTO_PIO_DATAIN 0x08 +#define ATA_PASSTHRU_PROTO_PIO_DATAOUT 0x0a +#define ATA_PASSTHRU_PROTO_DMA 0x0c +#define ATA_PASSTHRU_PROTO_DMA_QUEUED 0x0e +#define ATA_PASSTHRU_PROTO_EXEC_DIAG 0x10 +#define ATA_PASSTHRU_PROTO_NON_DATA_RST 0x12 +#define ATA_PASSTHRU_PROTO_UDMA_DATAIN 0x14 +#define ATA_PASSTHRU_PROTO_UDMA_DATAOUT 0x16 +#define ATA_PASSTHRU_PROTO_FPDMA 0x18 +#define ATA_PASSTHRU_PROTO_RESPONSE 0x1e + +#define ATA_PASSTHRU_T_DIR_MASK 0x08 +#define ATA_PASSTHRU_T_DIR_READ 0x08 +#define ATA_PASSTHRU_T_DIR_WRITE 0x00 + +#define ATA_PASSTHRU_T_LEN_MASK 0x03 +#define ATA_PASSTHRU_T_LEN_NONE 0x00 +#define ATA_PASSTHRU_T_LEN_FEATURES 0x01 +#define ATA_PASSTHRU_T_LEN_SECTOR_COUNT 0x02 +#define ATA_PASSTHRU_T_LEN_TPSIU 0x03 + +struct scsi_ata_passthru_12 { + u_int8_t opcode; + u_int8_t count_proto; + u_int8_t flags; + u_int8_t features; + u_int8_t sector_count; + u_int8_t lba_low; + u_int8_t lba_mid; + u_int8_t lba_high; + u_int8_t device; + u_int8_t command; + u_int8_t _reserved; + u_int8_t control; +}; + +struct scsi_ata_passthru_16 { + u_int8_t opcode; + u_int8_t count_proto; + u_int8_t flags; + u_int8_t features[2]; + u_int8_t sector_count[2]; + u_int8_t lba_low[2]; + u_int8_t lba_mid[2]; + u_int8_t lba_high[2]; + u_int8_t device; + u_int8_t command; + u_int8_t control; +}; + +/* + * SPI status information unit. See section 14.3.5 of SPI-3. + */ +struct scsi_status_iu_header { +/* 2*/ u_int8_t reserved[2]; +/* 3*/ u_int8_t flags; +#define SIU_SNSVALID 0x2 +#define SIU_RSPVALID 0x1 +/* 4*/ u_int8_t status; +/* 8*/ u_int8_t sense_length[4]; +/*12*/ u_int8_t pkt_failures_length[4]; + u_int8_t data[1]; /* OR */ +}; + +#define SIU_PKTFAIL_CODE(siu) ((siu)->data[3]) +#define SIU_PFC_NONE 0x00 +#define SIU_PFC_CIU_FIELDS_INVALID 0x02 +#define SIU_PFC_TMF_NOT_SUPPORTED 0x04 +#define SIU_PFC_TMF_FAILED 0x05 +#define SIU_PFC_INVALID_TYPE_CODE 0x06 +#define SIU_PFC_ILLEGAL_REQUEST 0x07 + +#define SIU_SENSE_LENGTH(siu) (_4btol((siu)->sense_length)) +#define SIU_SENSE_DATA(siu) (((siu)->flags & SIU_RSPVALID) ? \ + &(siu)->data[_4btol((siu)->pkt_failures_length)] : &(siu)->data[0]) + +/* + * Values for 'Task Management Flags' field of SPI command information unit. + * See section 14.3.1 of SPI-3. + */ +#define SIU_TASKMGMT_NONE 0x00 +#define SIU_TASKMGMT_ABORT_TASK 0x01 +#define SIU_TASKMGMT_ABORT_TASK_SET 0x02 +#define SIU_TASKMGMT_CLEAR_TASK_SET 0x04 +#define SIU_TASKMGMT_LUN_RESET 0x08 +#define SIU_TASKMGMT_TARGET_RESET 0x20 +#define SIU_TASKMGMT_CLEAR_ACA 0x40 + +/* + * Status Byte + */ +#define SCSI_OK 0x00 +#define SCSI_CHECK 0x02 +#define SCSI_COND_MET 0x04 +#define SCSI_BUSY 0x08 +#define SCSI_INTERM 0x10 +#define SCSI_INTERM_COND_MET 0x14 +#define SCSI_RESV_CONFLICT 0x18 +#define SCSI_TERMINATED 0x22 +#define SCSI_QUEUE_FULL 0x28 /* Old (Pre SCSI-3) name */ +#define SCSI_TASKSET_FULL 0x28 /* New (SCSI-3) name */ +#define SCSI_ACA_ACTIVE 0x30 + +#endif /* _SCSI_SCSI_ALL_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/scsi/scsi_changer.h b/lib/libc/include/generic-openbsd/scsi/scsi_changer.h new file mode 100644 index 0000000000..cc8f0466f3 --- /dev/null +++ b/lib/libc/include/generic-openbsd/scsi/scsi_changer.h @@ -0,0 +1,419 @@ +/* $OpenBSD: scsi_changer.h,v 1.11 2023/04/11 00:45:09 jsg Exp $ */ +/* $NetBSD: scsi_changer.h,v 1.7 1996/04/03 00:25:48 thorpej Exp $ */ + +/* + * Copyright (c) 1996 Jason R. Thorpe + * All rights reserved. + * + * Partially based on an autochanger driver written by Stefan Grefen + * and on an autochanger driver written by the Systems Programming Group + * at the University of Utah Computer Science Department. + * + * 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 acknowledgements: + * This product includes software developed by Jason R. Thorpe + * for And Communications, http://www.and.com/ + * 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. + */ + +/* + * SCSI changer interface description + */ + +/* + * Partially derived from software written by Stefan Grefen + * (grefen@goofy.zdv.uni-mainz.de soon grefen@convex.com) + * based on the SCSI System by written Julian Elischer (julian@tfs.com) + * for TRW Financial Systems. + * + * TRW Financial Systems, in accordance with their agreement with Carnegie + * Mellon University, makes this software available to CMU to distribute + * or use in any manner that they see fit as long as this message is kept with + * the software. For this reason TFS also grants any other persons or + * organisations permission to use or modify this software. + * + * TFS supplies this software to be publicly redistributed + * on the understanding that TFS is not responsible for the correct + * functioning of this software in any circumstances. + * + * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 + */ + +#ifndef _SCSI_SCSI_CHANGER_H +#define _SCSI_SCSI_CHANGER_H + +/* + * SCSI command format + */ + +/* + * Exchange the medium in the source element with the medium + * located at the destination element. + */ +struct scsi_exchange_medium { + u_int8_t opcode; +#define EXCHANGE_MEDIUM 0xa6 + u_int8_t byte2; + u_int8_t tea[2]; /* transport element address */ + u_int8_t src[2]; /* source address */ + u_int8_t fdst[2]; /* first destination address */ + u_int8_t sdst[2]; /* second destination address */ + u_int8_t flags; +#define EXCHANGE_MEDIUM_INV1 0x01 +#define EXCHANGE_MEDIUM_INV2 0x02 + u_int8_t control; +}; + +/* + * Cause the medium changer to check all elements for medium and any + * other status relevant to the element. + */ +struct scsi_initialize_elememt_status { + u_int8_t opcode; +#define INITIALIZE_ELEMENT_STATUS 0x07 + u_int8_t byte2; + u_int8_t reserved[3]; + u_int8_t control; +}; + +/* + * Request the changer to move a unit of media from the source element + * to the destination element. + */ +struct scsi_move_medium { + u_int8_t opcode; +#define MOVE_MEDIUM 0xa5 + u_int8_t byte2; + u_int8_t tea[2]; /* transport element address */ + u_int8_t src[2]; /* source element address */ + u_int8_t dst[2]; /* destination element address */ + u_int8_t reserved[2]; + u_int8_t flags; +#define MOVE_MEDIUM_INVERT 0x01 + u_int8_t control; +}; + +/* + * Position the specified transport element (picker) in front of + * the destination element specified. + */ +struct scsi_position_to_element { + u_int8_t opcode; +#define POSITION_TO_ELEMENT 0x2b + u_int8_t byte2; + u_int8_t tea[2]; /* transport element address */ + u_int8_t dst[2]; /* destination element address */ + u_int8_t reserved[2]; + u_int8_t flags; +#define POSITION_TO_ELEMENT_INVERT 0x01 + u_int8_t control; +}; + +/* + * Request that the changer report the status of its internal elements. + */ +struct scsi_read_element_status { + u_int8_t opcode; +#define READ_ELEMENT_STATUS 0xb8 + u_int8_t byte2; +#define READ_ELEMENT_STATUS_VOLTAG 0x10 /* report volume tag info */ + /* ...next 4 bits are an element type code... */ + u_int8_t sea[2]; /* starting element address */ + u_int8_t count[2]; /* number of elements */ + u_int8_t reserved0; + u_int8_t len[3]; /* length of data buffer */ + u_int8_t reserved1; + u_int8_t control; +}; + +struct scsi_request_volume_element_address { + u_int8_t opcode; +#define REQUEST_VOLUME_ELEMENT_ADDRESS 0xb5 + u_int8_t byte2; +#define REQUEST_VOLUME_ELEMENT_ADDRESS_VOLTAG 0x10 + /* ...next 4 bits are an element type code... */ + u_int8_t eaddr[2]; /* element address */ + u_int8_t count[2]; /* number of elements */ + u_int8_t reserved0; + u_int8_t len[3]; /* length of data buffer */ + u_int8_t reserved1; + u_int8_t control; +}; + +/* XXX scsi_release */ + +/* + * Data returned by READ ELEMENT STATUS consists of an 8-byte header + * followed by one or more read_element_status_pages. + */ +struct read_element_status_header { + u_int8_t fear[2]; /* first element address reported */ + u_int8_t count[2]; /* number of elements available */ + u_int8_t reserved; + u_int8_t nbytes[3]; /* byte count of all pages */ +}; + +struct read_element_status_page_header { + u_int8_t type; /* element type code; see type codes below */ + u_int8_t flags; +#define READ_ELEMENT_STATUS_AVOLTAG 0x40 +#define READ_ELEMENT_STATUS_PVOLTAG 0x80 + u_int8_t edl[2]; /* element descriptor length */ + u_int8_t reserved; + u_int8_t nbytes[3]; /* byte count of all descriptors */ +}; + +/* + * Format of a volume tag + */ + +struct volume_tag { + u_int8_t vif[32]; /* volume identification field */ + u_int8_t reserved[2]; + u_int8_t vsn[2]; /* volume sequence number */ +}; + +struct read_element_status_descriptor { + u_int8_t eaddr[2]; /* element address */ + u_int8_t flags1; + +#define READ_ELEMENT_STATUS_FULL 0x01 +#define READ_ELEMENT_STATUS_IMPEXP 0x02 +#define READ_ELEMENT_STATUS_EXCEPT 0x04 +#define READ_ELEMENT_STATUS_ACCESS 0x08 +#define READ_ELEMENT_STATUS_EXENAB 0x10 +#define READ_ELEMENT_STATUS_INENAB 0x20 + +#define READ_ELEMENT_STATUS_MT_MASK1 0x05 +#define READ_ELEMENT_STATUS_ST_MASK1 0x0c +#define READ_ELEMENT_STATUS_IE_MASK1 0x3f +#define READ_ELEMENT_STATUS_DT_MASK1 0x0c + + u_int8_t reserved0; + u_int8_t sense_code; + u_int8_t sense_qual; + + /* + * dt_scsi_flags and dt_scsi_addr are valid only on data transport + * elements. These bytes are undefined for all other element types. + */ + u_int8_t dt_scsi_flags; + +#define READ_ELEMENT_STATUS_DT_LUNMASK 0x07 +#define READ_ELEMENT_STATUS_DT_LUVALID 0x10 +#define READ_ELEMENT_STATUS_DT_IDVALID 0x20 +#define READ_ELEMENT_STATUS_DT_NOTBUS 0x80 + + u_int8_t dt_scsi_addr; + + u_int8_t reserved1; + + u_int8_t flags2; +#define READ_ELEMENT_STATUS_INVERT 0x40 +#define READ_ELEMENT_STATUS_SVALID 0x80 + u_int8_t ssea[2]; /* source storage element address */ + + /* + * bytes 12-47: Primary volume tag information. + * (field omitted if PVOLTAG = 0) + * + * bytes 48-83: Alternate volume tag information. + * (field omitted if AVOLTAG = 0) + */ + + struct volume_tag pvoltag; /* omitted if PVOLTAG == 0 */ + struct volume_tag avoltag; /* omitted if AVOLTAG == 0 */ + + /* + * bytes 84-87: Reserved (moved up if either of the above fields + * are omitted) + * + * bytes 88-end: Vendor-specific: (moved up if either of the + * above fields are missing) + */ +}; + +/* XXX add data returned by REQUEST VOLUME ELEMENT ADDRESS */ + +/* Element type codes */ +#define ELEMENT_TYPE_MASK 0x0f /* Note: these aren't bits */ +#define ELEMENT_TYPE_ALL 0x00 +#define ELEMENT_TYPE_MT 0x01 +#define ELEMENT_TYPE_ST 0x02 +#define ELEMENT_TYPE_IE 0x03 +#define ELEMENT_TYPE_DT 0x04 + +/* + * XXX The following definitions should be common to all SCSI device types. + */ +#define PGCODE_MASK 0x3f /* valid page number bits in pg_code */ +#define PGCODE_PS 0x80 /* indicates page is savable */ + +/* + * Device capabilities page. + * + * This page defines characteristics of the element types in the + * medium changer device. + * + * Note in the definitions below, the following abbreviations are + * used: + * MT Medium transport element (picker) + * ST Storage transport element (slot) + * IE Import/export element (portal) + * DT Data transfer element (tape/disk drive) + */ +#define CAP_PAGE 0x1f +struct page_device_capabilities { + u_int8_t pg_code; /* page code (0x1f) */ + u_int8_t pg_length; /* page length (0x12) */ + + /* + * The STOR_xx bits indicate that an element of a given + * type may provide independent storage for a unit of + * media. The top four bits of this value are reserved. + */ + u_int8_t stor; +#define STOR_MT 0x01 +#define STOR_ST 0x02 +#define STOR_IE 0x04 +#define STOR_DT 0x08 + + u_int8_t reserved0; + + /* + * The MOVE_TO_yy bits indicate the changer supports + * moving a unit of medium from an element of a given type to an + * element of type yy. This is used to determine if a given + * MOVE MEDIUM command is legal. The top four bits of each + * of these values are reserved. + */ + u_int8_t move_from_mt; + u_int8_t move_from_st; + u_int8_t move_from_ie; + u_int8_t move_from_dt; +#define MOVE_TO_MT 0x01 +#define MOVE_TO_ST 0x02 +#define MOVE_TO_IE 0x04 +#define MOVE_TO_DT 0x08 + + u_int8_t reserved1[2]; + + /* + * Similar to above, but for EXCHANGE MEDIUM. + */ + u_int8_t exchange_with_mt; + u_int8_t exchange_with_st; + u_int8_t exchange_with_ie; + u_int8_t exchange_with_dt; +#define EXCHANGE_WITH_MT 0x01 +#define EXCHANGE_WITH_ST 0x02 +#define EXCHANGE_WITH_IE 0x04 +#define EXCHANGE_WITH_DT 0x08 +}; + +/* + * Medium changer element address assignment page. + * + * Some of these fields can be a little confusing, so an explanation + * is in order. + * + * Each component within a medium changer apparatus is called an + * "element". + * + * The "medium transport element address" is the address of the first + * picker (robotic arm). "Number of medium transport elements" tells + * us how many pickers exist in the changer. + * + * The "first storage element address" is the address of the first + * slot in the tape or disk magazine. "Number of storage elements" tells + * us how many slots exist in the changer. + * + * The "first import/export element address" is the address of the first + * medium portal accessible both by the medium changer and an outside + * human operator. This is where the changer might deposit tapes destined + * for some vault. The "number of import/export elements" tells us + * not many of these portals exist in the changer. NOTE: this number may + * be 0. + * + * The "first data transfer element address" is the address of the first + * tape or disk drive in the changer. "Number of data transfer elements" + * tells us how many drives exist in the changer. + */ +#define EA_PAGE 0x1d +struct page_element_address_assignment { + u_int8_t pg_code; /* page code (0x1d) */ + u_int8_t pg_length; /* page length (0x12) */ + + /* Medium transport element address */ + u_int8_t mtea[2]; + + /* Number of medium transport elements */ + u_int8_t nmte[2]; + + /* First storage element address */ + u_int8_t fsea[2]; + + /* Number of storage elements */ + u_int8_t nse[2]; + + /* First import/export element address */ + u_int8_t fieea[2]; + + /* Number of import/export elements */ + u_int8_t niee[2]; + + /* First data transfer element address */ + u_int8_t fdtea[2]; + + /* Number of data transfer elements */ + u_int8_t ndte[2]; + + u_int8_t reserved[2]; +}; + +/* + * Transport geometry parameters page. + * + * Defines whether each medium transport element is a member of a set of + * elements that share a common robotics subsystem and whether the element + * is capable of media rotation. One transport geometry descriptor is + * transferred for each medium transport element, beginning with the first + * medium transport element (other than the default transport element address + * of 0). + */ +#define TGP_PAGE 0x1e +struct page_transport_geometry_parameters { + u_int8_t pg_code; /* page code (0x1e) */ + u_int8_t pg_length; /* page length; variable */ + + /* Transport geometry descriptor(s) are here. */ + + u_int8_t misc; +#define CAN_ROTATE 0x01 + + /* Member number in transport element set. */ + u_int8_t member; +}; + +#endif /* _SCSI_SCSI_CHANGER_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/scsi/scsi_debug.h b/lib/libc/include/generic-openbsd/scsi/scsi_debug.h new file mode 100644 index 0000000000..2798355ae6 --- /dev/null +++ b/lib/libc/include/generic-openbsd/scsi/scsi_debug.h @@ -0,0 +1,76 @@ +/* $OpenBSD: scsi_debug.h,v 1.23 2022/02/28 14:48:11 krw Exp $ */ +/* $NetBSD: scsi_debug.h,v 1.7 1996/10/12 23:23:16 christos Exp $ */ + +/* + * Written by Julian Elischer (julian@tfs.com) + */ +#ifndef _SCSI_SCSI_DEBUG_H +#define _SCSI_SCSI_DEBUG_H +#ifdef _KERNEL + +/* + * These are the new debug bits. (Sat Oct 2 12:46:46 WST 1993) + * the following DEBUG bits are defined to exist in the flags word of + * the scsi_link structure. + */ +#define SDEV_DB1 0x0010 /* scsi commands, errors, data */ +#define SDEV_DB2 0x0020 /* routine flow tracking */ +#define SDEV_DB3 0x0040 /* internal to routine flows */ +#define SDEV_DB4 0x0080 /* level 4 debugging for this dev */ + +#ifdef SCSIDEBUG +/* targets and LUNs we want to debug */ +#ifndef SCSIDEBUG_BUSES +#define SCSIDEBUG_BUSES 0 +#endif /* ~SCSIDBUG_BUSES */ +#ifndef SCSIDEBUG_TARGETS +#define SCSIDEBUG_TARGETS 0 +#endif /* ~SCSIDEBUG_TARGETS */ +#ifndef SCSIDEBUG_LUNS +#define SCSIDEBUG_LUNS 0 +#endif /* ~SCSIDEBUG_LUNS */ +#ifndef SCSIDEBUG_LEVEL +#define SCSIDEBUG_LEVEL (SDEV_DB1|SDEV_DB2) +#endif /* ~SCSIDEBUG_LEVEL */ + +extern u_int32_t scsidebug_buses, scsidebug_targets, scsidebug_luns; +extern int scsidebug_level; + +extern const char *flagnames[]; +extern const char *quirknames[]; +extern const char *devicetypenames[32]; + +struct scsi_xfer; + +void scsi_show_sense(struct scsi_xfer *); +void scsi_show_xs(struct scsi_xfer *); +void scsi_show_mem(u_char *, int); +void scsi_show_flags(u_int32_t, const char **); +void scsi_show_inquiry_header(struct scsi_inquiry_data *); +void scsi_show_inquiry_match(struct scsi_inquiry_data *); + +/* + * This is the usual debug macro for use with the above bits + */ +#define SC_DEBUG(link,Level,Printstuff) do { \ + if ((link)->flags & (Level)) { \ + sc_print_addr(link); \ + printf Printstuff; \ + } \ +} while (0) +#define SC_DEBUGN(link,Level,Printstuff) do { \ + if ((link)->flags & (Level)) { \ + printf Printstuff; \ + } \ +} while (0) +#define SC_DEBUG_SENSE(xs) do { \ + scsi_show_sense(xs); \ +} while (0) +#else +#define SC_DEBUG(link,level,Printstuff) +#define SC_DEBUGN(link,level,Printstuff) +#define SC_DEBUG_SENSE(xs) +#endif /* SCSIDEBUG */ + +#endif /* _KERNEL */ +#endif /* _SCSI_SCSI_DEBUG_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/scsi/scsi_disk.h b/lib/libc/include/generic-openbsd/scsi/scsi_disk.h new file mode 100644 index 0000000000..93f7b696fe --- /dev/null +++ b/lib/libc/include/generic-openbsd/scsi/scsi_disk.h @@ -0,0 +1,496 @@ +/* $OpenBSD: scsi_disk.h,v 1.43 2022/01/11 23:10:11 jsg Exp $ */ +/* $NetBSD: scsi_disk.h,v 1.10 1996/07/05 16:19:05 christos Exp $ */ + +/* + * SCSI interface description + */ + +/* + * Some lines of this file come from a file of the name "scsi.h" + * distributed by OSF as part of mach2.5, + * so the following disclaimer has been kept. + * + * Copyright 1990 by Open Software Foundation, + * Grenoble, FRANCE + * + * All Rights Reserved + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby granted, + * provided that the above copyright notice appears in all copies and + * that both the copyright notice and this permission notice appear in + * supporting documentation, and that the name of OSF or Open Software + * Foundation not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. + * + * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, + * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, + * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * Largely written by Julian Elischer (julian@tfs.com) + * for TRW Financial Systems. + * + * TRW Financial Systems, in accordance with their agreement with Carnegie + * Mellon University, makes this software available to CMU to distribute + * or use in any manner that they see fit as long as this message is kept with + * the software. For this reason TFS also grants any other persons or + * organisations permission to use or modify this software. + * + * TFS supplies this software to be publicly redistributed + * on the understanding that TFS is not responsible for the correct + * functioning of this software in any circumstances. + * + * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 + */ + +/* + * SCSI command format + */ + +#ifndef _SCSI_SCSI_DISK_H +#define _SCSI_SCSI_DISK_H + +/* + * XXX Is this also used by ATAPI? + */ +#define FORMAT_UNIT 0x04 +struct scsi_format_unit { + u_int8_t opcode; + u_int8_t flags; +#define SFU_DLF_MASK 0x07 +#define SFU_CMPLST 0x08 +#define SFU_FMTDATA 0x10 + u_int8_t vendor_specific; + u_int8_t interleave[2]; + u_int8_t control; +}; + +/* + * If the FmtData bit is set, a FORMAT UNIT parameter list is transferred + * to the target during the DATA OUT phase. The parameter list includes + * + * Defect list header + * Initialization pattern descriptor (if any) + * Defect descriptor(s) (if any) + */ + +struct scsi_format_unit_defect_list_header { + u_int8_t reserved; + u_int8_t flags; +#define DLH_VS 0x01 /* vendor specific */ +#define DLH_IMMED 0x02 /* immediate return */ +#define DLH_DSP 0x04 /* disable saving parameters */ +#define DLH_IP 0x08 /* initialization pattern */ +#define DLH_STPF 0x10 /* stop format */ +#define DLH_DCRT 0x20 /* disable certification */ +#define DLH_DPRY 0x40 /* disable primary */ +#define DLH_FOV 0x80 /* format options valid */ + u_int8_t defect_lst_len[2]; +}; + +/* + * See Table 117 of the SCSI-2 specification for a description of + * the IP modifier. + */ +struct scsi_initialization_pattern_descriptor { + u_int8_t ip_modifier; + u_int8_t pattern_type; +#define IP_TYPE_DEFAULT 0x01 +#define IP_TYPE_REPEAT 0x01 + /* 0x02 -> 0x7f: reserved */ + /* 0x80 -> 0xff: vendor-specific */ + u_int8_t pattern_length[2]; +#if 0 + u_int8_t pattern[...]; +#endif /* 0 */ +}; + +/* + * Defect descriptors. These are used as the defect lists in the FORMAT UNIT + * and READ DEFECT DATA commands, and as the translate page of the + * SEND DIAGNOSTIC and RECEIVE DIAGNOSTIC RESULTS commands. + */ + +/* Block format */ +struct scsi_defect_descriptor_bf { + u_int8_t block_address[4]; +}; + +/* Bytes from index format */ +struct scsi_defect_descriptor_bfif { + u_int8_t cylinder[2]; + u_int8_t head; + u_int8_t bytes_from_index[2]; +}; + +/* Physical sector format */ +struct scsi_defect_descriptor_psf { + u_int8_t cylinder[2]; + u_int8_t head; + u_int8_t sector[2]; +}; + + +struct scsi_reassign_blocks { + u_int8_t opcode; + u_int8_t byte2; + u_int8_t unused[3]; + u_int8_t control; +}; + +/* + * XXX Is this also used by ATAPI? + */ +#define REZERO_UNIT 0x01 +struct scsi_rezero_unit { + u_int8_t opcode; + u_int8_t byte2; + u_int8_t reserved[3]; + u_int8_t control; +}; + +struct scsi_rw { + u_int8_t opcode; + u_int8_t addr[3]; +#define SRW_TOPADDR 0x1F /* only 5 bits here */ + u_int8_t length; + u_int8_t control; +}; + +struct scsi_rw_10 { + u_int8_t opcode; + u_int8_t byte2; +#define SRWB_RELADDR 0x01 + u_int8_t addr[4]; + u_int8_t reserved; + u_int8_t length[2]; + u_int8_t control; +}; + +struct scsi_rw_12 { + u_int8_t opcode; + u_int8_t byte2; + u_int8_t addr[4]; + u_int8_t length[4]; + u_int8_t reserved; + u_int8_t control; +}; + +struct scsi_rw_16 { + u_int8_t opcode; + u_int8_t byte2; + u_int8_t addr[8]; + u_int8_t length[4]; + u_int8_t reserved; + u_int8_t control; +}; + +struct scsi_write_same_10 { + u_int8_t opcode; + u_int8_t flags; +#define WRITE_SAME_F_LBDATA (1 << 1) +#define WRITE_SAME_F_PBDATA (1 << 2) + u_int8_t lba[4]; + u_int8_t group_number; + u_int8_t length[2]; + u_int8_t control; +}; + +struct scsi_write_same_16 { + u_int8_t opcode; + u_int8_t flags; +/* includes WRITE SAME 10 flags */ +#define WRITE_SAME_F_UNMAP (1 << 3) +#define WRITE_SAME_F_ANCHOR (1 << 4) + u_int8_t lba[8]; + u_int8_t length[4]; + u_int8_t group_number; + u_int8_t control; +}; + +struct scsi_unmap { + u_int8_t opcode; + u_int8_t anchor; + u_int8_t _reserved[4]; + u_int8_t group_number; + u_int8_t list_len[2]; + u_int8_t control; +}; + +struct scsi_unmap_data { + u_int8_t data_length[2]; + u_int8_t desc_length[2]; + u_int8_t _reserved[4]; + + /* followed by struct scsi_unmap_desc */ +}; + +struct scsi_unmap_desc { + u_int8_t logical_addr[8]; + u_int8_t logical_blocks[4]; + u_int8_t _reserved[4]; +}; + +struct scsi_read_capacity { + u_int8_t opcode; + u_int8_t byte2; + u_int8_t addr[4]; + u_int8_t unused[3]; + u_int8_t control; +}; + +struct scsi_read_capacity_16 { + u_int8_t opcode; + u_int8_t byte2; +#define SRC16_SERVICE_ACTION 0x10 + u_int8_t addr[8]; + u_int8_t length[4]; + u_int8_t reserved; + u_int8_t control; +}; + +struct scsi_start_stop { + u_int8_t opcode; + u_int8_t byte2; + u_int8_t unused[2]; + u_int8_t how; +#define SSS_STOP 0x00 +#define SSS_START 0x01 +#define SSS_LOEJ 0x02 + u_int8_t control; +}; + + +/* + * XXX Does ATAPI have an equivalent? + */ +struct scsi_synchronize_cache { + u_int8_t opcode; + u_int8_t flags; +#define SSC_RELADR 0x01 +#define SSC_IMMED 0x02 + u_int8_t addr[4]; + u_int8_t reserved; + u_int8_t length[2]; + u_int8_t control; +}; + + + +/* + * Disk specific opcodes + */ +#define REASSIGN_BLOCKS 0x07 +#define READ_COMMAND 0x08 +#define WRITE_COMMAND 0x0a +#define READ_CAPACITY 0x25 +#define READ_CAPACITY_16 0x9e +#define READ_10 0x28 +#define WRITE_10 0x2a +#define READ_12 0xa8 +#define WRITE_12 0xaa +#define READ_16 0x88 +#define WRITE_16 0x8a +#define SYNCHRONIZE_CACHE 0x35 +#define WRITE_SAME_10 0x41 +#define WRITE_SAME_16 0x93 +#define UNMAP 0x42 + + +struct scsi_reassign_blocks_data { + u_int8_t reserved[2]; + u_int8_t length[2]; + struct { + u_int8_t dlbaddr[4]; + } defect_descriptor[1]; +}; + +/* Only the lower 6 bits of the pg_code field are used for page #. */ +#define PAGE_DISK_FORMAT 3 +#define PAGE_RIGID_GEOMETRY 4 +#define PAGE_FLEX_GEOMETRY 5 +#define PAGE_REDUCED_GEOMETRY 6 +#define PAGE_CACHING_MODE 8 + +struct page_disk_format { + u_int8_t pg_code; /* page code (should be 3) */ + u_int8_t pg_length; /* page length (should be 0x16) */ + u_int8_t trk_z[2]; /* tracks per zone */ + u_int8_t alt_sec[2]; /* alternate sectors per zone */ + u_int8_t alt_trk_z[2]; /* alternate tracks per zone */ + u_int8_t alt_trk_v[2]; /* alternate tracks per volume */ + u_int8_t ph_sec_t[2]; /* physical sectors per track */ + u_int8_t bytes_s[2]; /* bytes per sector */ + u_int8_t interleave[2]; /* interleave */ + u_int8_t trk_skew[2]; /* track skew factor */ + u_int8_t cyl_skew[2]; /* cylinder skew */ + u_int8_t flags; /* various */ +#define DISK_FMT_SURF 0x10 +#define DISK_FMT_RMB 0x20 +#define DISK_FMT_HSEC 0x40 +#define DISK_FMT_SSEC 0x80 + u_int8_t reserved1; + u_int8_t reserved2; + u_int8_t reserved3; +}; + +struct page_rigid_geometry { + u_int8_t pg_code; /* page code (should be 4) */ + u_int8_t pg_length; /* page length (should be 0x12 or 0x16) */ + u_int8_t ncyl[3]; /* number of cylinders */ + u_int8_t nheads; /* number of heads */ + u_int8_t st_cyl_wp[3]; /* starting cyl., write precomp */ + u_int8_t st_cyl_rwc[3]; /* starting cyl., red. write cur */ + u_int8_t driv_step[2]; /* drive step rate */ + u_int8_t land_zone[3]; /* landing zone cylinder */ + u_int8_t sp_sync_ctl; /* spindle synch control */ +#define SPINDLE_SYNCH_MASK 0x03 /* mask of valid bits */ +#define SPINDLE_SYNCH_NONE 0x00 /* synch disabled or not supported */ +#define SPINDLE_SYNCH_SLAVE 0x01 /* disk is a slave */ +#define SPINDLE_SYNCH_MASTER 0x02 /* disk is a master */ +#define SPINDLE_SYNCH_MCONTROL 0x03 /* disk is a master control */ + u_int8_t rot_offset; /* rotational offset (for spindle synch) */ + u_int8_t reserved1; + u_int8_t rpm[2]; /* media rotation speed */ + u_int8_t reserved2; + u_int8_t reserved3; +}; + +struct page_flex_geometry { + u_int8_t pg_code; /* page code (should be 5) */ + u_int8_t pg_length; /* page length (should be 0x1a or 0x1e) */ + u_int8_t xfr_rate[2]; + u_int8_t nheads; /* number of heads */ + u_int8_t ph_sec_tr; /* physical sectors per track */ + u_int8_t bytes_s[2]; /* bytes per sector */ + u_int8_t ncyl[2]; /* number of cylinders */ + u_int8_t st_cyl_wp[2]; /* start cyl., write precomp */ + u_int8_t st_cyl_rwc[2]; /* start cyl., red. write cur */ + u_int8_t driv_step[2]; /* drive step rate */ + u_int8_t driv_step_w; /* drive step pulse width */ + u_int8_t head_settle[2];/* head settle delay */ + u_int8_t motor_on; /* motor on delay */ + u_int8_t motor_off; /* motor off delay */ + u_int8_t flags; /* various flags */ +#define MOTOR_ON 0x20 /* motor on (pin 16)? */ +#define START_AT_SECTOR_1 0x40 /* start at sector 1 */ +#define READY_VALID 0x20 /* RDY (pin 34) valid */ + u_int8_t step_p_cyl; /* step pulses per cylinder */ + u_int8_t write_pre; /* write precompensation */ + u_int8_t head_load; /* head load delay */ + u_int8_t head_unload; /* head unload delay */ + u_int8_t pin_34_2; /* pin 34 (6) pin 2 (7/11) definition */ + u_int8_t pin_4_1; /* pin 4 (8/9) pin 1 (13) definition */ + u_int8_t rpm[2]; /* media rotation speed */ + u_int8_t reserved1; + u_int8_t reserved2; +}; + +struct page_reduced_geometry { + u_int8_t pg_code; /* page code (should be 6) */ + u_int8_t pg_length; /* page length (should be 0x0B) */ + u_int8_t wcd; /* bit 0 = write cache disable */ + u_int8_t bytes_s[2]; /* bytes per sector */ + u_int8_t sectors[5]; /* total number of sectors */ + u_int8_t pow_perf; /* power/performance level */ + u_int8_t flags; /* various */ +#define LOCK_DISABLED 0x1 +#define FORMAT_DISABLED 0x2 +#define WRITE_DISABLED 0x4 +#define READ_DISABLED 0x8 + u_int8_t reserved; +}; + +struct page_caching_mode { + u_int8_t pg_code; /* page code (should be 8) */ + u_int8_t pg_length; /* page length (should be 0x12) */ + u_int8_t flags; +#define PG_CACHE_FL_RCD (1<<0) +#define PG_CACHE_FL_MF (1<<1) +#define PG_CACHE_FL_WCE (1<<2) +#define PG_CACHE_FL_SIZE (1<<3) +#define PG_CACHE_FL_DISC (1<<4) +#define PG_CACHE_FL_CAP (1<<5) +#define PG_CACHE_FL_ABPF (1<<6) +#define PG_CACHE_FL_IC (1<<7) + u_int8_t priority; +#define PG_CACHE_PRI_DEMAND(_f) ((_f) & 0x0f) +#define PG_CACHE_PRI_WRITE(_f) (((_f) >> 4) & 0x0f) + u_int8_t dis_prefetch_tl[2]; + u_int8_t min_prefetch[2]; + u_int8_t max_prefetch[2]; + u_int8_t max_prefetch_ceil[2]; +}; + +#define SI_PG_DISK_LIMITS 0xb0 /* block limits */ +#define SI_PG_DISK_INFO 0xb1 /* device characteristics */ +#define SI_PG_DISK_THIN 0xb2 /* thin provisioning */ + +struct scsi_vpd_disk_limits { + struct scsi_vpd_hdr hdr; +#define SI_PG_DISK_LIMITS_LEN 0x10 +#define SI_PG_DISK_LIMITS_LEN_THIN 0x3c + + u_int8_t _reserved1[1]; + u_int8_t max_comp_wr_len; + u_int8_t optimal_xfer_granularity[2]; + + u_int8_t max_xfer_len[4]; + + u_int8_t optimal_xfer[4]; + + u_int8_t max_xd_prefetch_len[4]; + + u_int8_t max_unmap_lba_count[4]; + + u_int8_t max_unmap_desc_count[4]; + + u_int8_t optimal_unmap_granularity[4]; + + u_int8_t unmap_granularity_align[4]; +#define SI_PG_DISK_LIMITS_UGAVALID (1U << 31) + + u_int8_t _reserved2[28]; +}; + +struct scsi_vpd_disk_info { + struct scsi_vpd_hdr hdr; + u_int8_t rpm[2]; +#define VPD_DISK_INFO_RPM_UNDEF 0x0000 +#define VPD_DISK_INFO_RPM_NONE 0x0001 + u_int8_t _reserved1[1]; + u_int8_t form_factor; +#define VPD_DISK_INFO_FORM_MASK 0xf +#define VPD_DISK_INFO_FORM_UNDEF 0x0 +#define VPD_DISK_INFO_FORM_5_25 0x1 +#define VPD_DISK_INFO_FORM_3_5 0x2 +#define VPD_DISK_INFO_FORM_2_5 0x3 +#define VPD_DISK_INFO_FORM_1_8 0x4 +#define VPD_DISK_INFO_FORM_LT_1_8 0x5 + u_int8_t _reserved2[56]; +}; + +struct scsi_vpd_disk_thin { + struct scsi_vpd_hdr hdr; + + u_int8_t threshold_exponent; + u_int8_t flags; +#define VPD_DISK_THIN_DP (1 << 0) /* descriptor present */ +#define VPD_DISK_THIN_ANC_SUP (0x7 << 1) +#define VPD_DISK_THIN_ANC_SUP_NO (0x0 << 1) +#define VPD_DISK_THIN_ANC_SUP_YES (0x1 << 1) +#define VPD_DISK_THIN_TPWS (1 << 6) /* WRITE SAME 16 */ +#define VPD_DISK_THIN_TPU (1 << 7) /* UNMAP */ + u_int8_t _reserved1[2]; + + /* followed by a designation descriptor if DP is set */ +}; + +#endif /* _SCSI_SCSI_DISK_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/scsi/scsi_message.h b/lib/libc/include/generic-openbsd/scsi/scsi_message.h new file mode 100644 index 0000000000..132da61655 --- /dev/null +++ b/lib/libc/include/generic-openbsd/scsi/scsi_message.h @@ -0,0 +1,67 @@ +/* $OpenBSD: scsi_message.h,v 1.10 2019/09/27 23:07:42 krw Exp $ */ + +#ifndef _SCSI_SCSI_MESSAGE_H +#define _SCSI_SCSI_MESSAGE_H + +#define IS1BYTEMSG(m) (((m) != 0x01 && (m) < 0x20) || (m) >= 0x80) +#define IS2BYTEMSG(m) (((m) & 0xf0) == 0x20) +#define ISEXTMSG(m) ((m) == 0x01) + +/* Messages (1 byte) */ /* I/T (M)andatory or (O)ptional */ +#define MSG_CMDCOMPLETE 0x00 /* M/M */ +#define MSG_EXTENDED 0x01 /* O/O */ +#define MSG_SAVEDATAPOINTER 0x02 /* O/O */ +#define MSG_RESTOREPOINTERS 0x03 /* O/O */ +#define MSG_DISCONNECT 0x04 /* O/O */ +#define MSG_INITIATOR_DET_ERR 0x05 /* M/M */ +#define MSG_ABORT 0x06 /* O/M */ +#define MSG_MESSAGE_REJECT 0x07 /* M/M */ +#define MSG_NOOP 0x08 /* M/M */ +#define MSG_PARITY_ERROR 0x09 /* M/M */ +#define MSG_LINK_CMD_COMPLETE 0x0a /* O/O */ +#define MSG_LINK_CMD_COMPLETEF 0x0b /* O/O */ +#define MSG_BUS_DEV_RESET 0x0c /* O/M */ +#define MSG_ABORT_TAG 0x0d /* O/O */ +#define MSG_CLEAR_QUEUE 0x0e /* O/O */ +#define MSG_INIT_RECOVERY 0x0f /* O/O */ +#define MSG_REL_RECOVERY 0x10 /* O/O */ +#define MSG_TERM_IO_PROC 0x11 /* O/O */ +#define MSG_QAS_REQUEST 0x55 /* O/O */ /* SPI3 */ + +/* Messages (2 byte) */ +#define MSG_SIMPLE_Q_TAG 0x20 /* O/O */ +#define MSG_HEAD_OF_Q_TAG 0x21 /* O/O */ +#define MSG_ORDERED_Q_TAG 0x22 /* O/O */ +#define MSG_IGN_WIDE_RESIDUE 0x23 /* O/O */ + +/* Identify message */ /* M/M */ +#define MSG_IDENTIFYFLAG 0x80 +#define MSG_IDENTIFY_DISCFLAG 0x40 +#define MSG_IDENTIFY(lun, disc) (((disc) ? 0xc0 : MSG_IDENTIFYFLAG) | (lun)) +#define MSG_ISIDENTIFY(m) ((m) & MSG_IDENTIFYFLAG) +#define MSG_IDENTIFY_LUNMASK 0x01F + +/* Extended messages (opcode and length) */ +#define MSG_EXT_SDTR 0x01 +#define MSG_EXT_SDTR_LEN 0x03 + +#define MSG_EXT_WDTR 0x03 +#define MSG_EXT_WDTR_LEN 0x02 + +#define MSG_EXT_WDTR_BUS_8_BIT 0x00 +#define MSG_EXT_WDTR_BUS_16_BIT 0x01 +#define MSG_EXT_WDTR_BUS_32_BIT 0x02 + +#define MSG_EXT_PPR 0x04 +#define MSG_EXT_PPR_LEN 0x06 + +#define MSG_EXT_PPR_PCOMP_EN 0x80 +#define MSG_EXT_PPR_RTI 0x40 +#define MSG_EXT_PPR_RD_STRM 0x20 +#define MSG_EXT_PPR_WR_FLOW 0x10 +#define MSG_EXT_PPR_HOLD_MCS 0x08 +#define MSG_EXT_PPR_PROT_QAS 0x04 +#define MSG_EXT_PPR_PROT_DT 0x02 +#define MSG_EXT_PPR_PROT_IUS 0x01 + +#endif /* _SCSI_SCSI_MESSAGE_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/scsi/scsi_tape.h b/lib/libc/include/generic-openbsd/scsi/scsi_tape.h new file mode 100644 index 0000000000..014e28b16d --- /dev/null +++ b/lib/libc/include/generic-openbsd/scsi/scsi_tape.h @@ -0,0 +1,240 @@ +/* $OpenBSD: scsi_tape.h,v 1.11 2019/09/27 23:07:42 krw Exp $ */ +/* $NetBSD: scsi_tape.h,v 1.9 1996/05/24 02:04:47 thorpej Exp $ */ + +/* + * Copyright (c) 1994 Charles Hannum. 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 Charles Hannum. + * 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. + */ + +/* + * Originally written by Julian Elischer (julian@tfs.com) + * for TRW Financial Systems. + * + * TRW Financial Systems, in accordance with their agreement with Carnegie + * Mellon University, makes this software available to CMU to distribute + * or use in any manner that they see fit as long as this message is kept with + * the software. For this reason TFS also grants any other persons or + * organisations permission to use or modify this software. + * + * TFS supplies this software to be publicly redistributed + * on the understanding that TFS is not responsible for the correct + * functioning of this software in any circumstances. + * + * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 + */ + +/* + * SCSI tape interface description + */ + +#ifndef _SCSI_SCSI_TAPE_H +#define _SCSI_SCSI_TAPE_H + +/* + * SCSI command formats + */ + +#define READ 0x08 +#define WRITE 0x0a +struct scsi_rw_tape { + u_int8_t opcode; + u_int8_t byte2; +#define SRW_FIXED 0x01 + u_int8_t len[3]; + u_int8_t control; +}; + +#define SPACE 0x11 +struct scsi_space { + u_int8_t opcode; + u_int8_t byte2; +#define SS_CODE 0x03 +#define SP_BLKS 0x00 +#define SP_FILEMARKS 0x01 +#define SP_SEQ_FILEMARKS 0x02 +#define SP_EOM 0x03 + u_int8_t number[3]; + u_int8_t control; +}; + +#define WRITE_FILEMARKS 0x10 +struct scsi_write_filemarks { + u_int8_t opcode; + u_int8_t byte2; + u_int8_t number[3]; + u_int8_t control; +}; + +#define REWIND 0x01 +struct scsi_rewind { + u_int8_t opcode; + u_int8_t byte2; +#define SR_IMMED 0x01 + u_int8_t unused[3]; + u_int8_t control; +}; + +#define LOAD 0x1b +struct scsi_load { + u_int8_t opcode; + u_int8_t byte2; +#define SL_IMMED 0x01 + u_int8_t unused[2]; + u_int8_t how; +#define LD_UNLOAD 0x00 +#define LD_LOAD 0x01 +#define LD_RETENSION 0x02 + u_int8_t control; +}; + +#define ERASE 0x19 +struct scsi_erase { + u_int8_t opcode; + u_int8_t byte2; +#define SE_LONG 0x01 +#define SE_IMMED 0x02 + u_int8_t unused[3]; + u_int8_t control; +}; + +#define READ_BLOCK_LIMITS 0x05 +struct scsi_block_limits { + u_int8_t opcode; + u_int8_t byte2; + u_int8_t unused[3]; + u_int8_t control; +}; + +struct scsi_block_limits_data { + u_int8_t reserved; + u_int8_t max_length[3]; /* Most significant */ + u_int8_t min_length[2]; /* Most significant */ +}; + +/* See SCSI-II spec 9.3.3.1 */ +struct scsi_tape_dev_conf_page { + u_int8_t pagecode; /* 0x10 */ + u_int8_t pagelength; /* 0x0e */ + u_int8_t byte2; +#define SMT_CAP 0x40 /* change active partition */ +#define SMT_CAF 0x20 /* change active format */ +#define SMT_AFMASK 0x1f /* active format mask */ + u_int8_t active_partition; + u_int8_t wb_full_ratio; + u_int8_t rb_empty_ratio; + u_int8_t wrdelay_time[2]; + u_int8_t byte8; +#define SMT_DBR 0x80 /* data buffer recovery */ +#define SMT_BIS 0x40 /* block identifiers supported */ +#define SMT_RSMK 0x20 /* report setmarks */ +#define SMT_AVC 0x10 /* automatic velocity control */ +#define SMT_SOCF_MASK 0xc0 /* stop on consecutive formats */ +#define SMT_RBO 0x20 /* recover buffer order */ +#define SMT_REW 0x10 /* report early warning */ + u_int8_t gap_size; + u_int8_t byte10; +#define SMT_EODDEFINED 0xe0 /* EOD defined */ +#define SMT_EEG 0x10 /* enable EOD generation */ +#define SMT_SEW 0x80 /* synchronize at early warning */ + u_int8_t ew_bufsize[3]; + u_int8_t sel_comp_alg; +#define SMT_COMP_NONE 0x00 +#define SMT_COMP_DEFAULT 0x01 + u_int8_t reserved; +}; + +/* defines for the device specific byte in the mode select/sense header */ +#define SMH_DSP_SPEED 0x0F +#define SMH_DSP_BUFF_MODE 0x70 +#define SMH_DSP_BUFF_MODE_OFF 0x00 +#define SMH_DSP_BUFF_MODE_ON 0x10 +#define SMH_DSP_BUFF_MODE_MLTI 0x20 + +/********************************************************************** + from the scsi2 spec + Value Tracks Density(bpi) Code Type Reference Note + 0x1 9 800 NRZI R X3.22-1983 2 + 0x2 9 1600 PE R X3.39-1986 2 + 0x3 9 6250 GCR R X3.54-1986 2 + 0x5 4/9 8000 GCR C X3.136-1986 1 + 0x6 9 3200 PE R X3.157-1987 2 + 0x7 4 6400 IMFM C X3.116-1986 1 + 0x8 4 8000 GCR CS X3.158-1986 1 + 0x9 18 37871 GCR C X3B5/87-099 2 + 0xA 22 6667 MFM C X3B5/86-199 1 + 0xB 4 1600 PE C X3.56-1986 1 + 0xC 24 12690 GCR C HI-TC1 1,5 + 0xD 24 25380 GCR C HI-TC2 1,5 + 0xF 15 10000 GCR C QIC-120 1,5 + 0x10 18 10000 GCR C QIC-150 1,5 + 0x11 26 16000 GCR C QIC-320(525?) 1,5 + 0x12 30 51667 RLL C QIC-1350 1,5 + 0x13 1 61000 DDS CS X3B5/88-185A 4 + 0x14 1 43245 RLL CS X3.202-1991 4 + 0x15 1 45434 RLL CS ECMA TC17 4 + 0x16 48 10000 MFM C X3.193-1990 1 + 0x17 48 42500 MFM C X3B5/91-174 1 + 0x45 73 67733 RLL C QIC3095 + + where Code means: + NRZI Non Return to Zero, change on ones + GCR Group Code Recording + PE Phase Encoded + IMFM Inverted Modified Frequency Modulation + MFM Modified Frequency Modulation + DDS Dat Data Storage + RLL Run Length Encoding + + where Type means: + R Reel-to-Reel + C Cartridge + CS cassette + + where Notes means: + 1 Serial Recorded + 2 Parallel Recorded + 3 Old format know as QIC-11 + 4 Helical Scan + 5 Not ANSI standard, rather industry standard. +********************************************************************/ + +#define HALFINCH_800 0x01 +#define HALFINCH_1600 0x02 +#define HALFINCH_6250 0x03 +#define QIC_11 0x04 /* from Archive 150S Theory of Op. XXX */ +#define QIC_24 0x05 /* may be bad, works for CIPHER ST150S XXX */ +#define QIC_120 0x0f +#define QIC_150 0x10 +#define QIC_320 0x11 +#define QIC_525 0x11 +#define QIC_1320 0x12 +#define DDS 0x13 +#define DAT_1 0x13 +#define QIC_3080 0x29 +#define QIC_3095 0x45 + +#endif /* _SCSI_SCSI_TAPE_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/scsi/scsiconf.h b/lib/libc/include/generic-openbsd/scsi/scsiconf.h new file mode 100644 index 0000000000..d05d6e0c1b --- /dev/null +++ b/lib/libc/include/generic-openbsd/scsi/scsiconf.h @@ -0,0 +1,579 @@ +/* $OpenBSD: scsiconf.h,v 1.202 2023/05/10 15:28:26 krw Exp $ */ +/* $NetBSD: scsiconf.h,v 1.35 1997/04/02 02:29:38 mycroft Exp $ */ + +/* + * Copyright (c) 1993, 1994, 1995 Charles Hannum. 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 Charles Hannum. + * 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. + */ + +/* + * Originally written by Julian Elischer (julian@tfs.com) + * for TRW Financial Systems for use under the MACH(2.5) operating system. + * + * TRW Financial Systems, in accordance with their agreement with Carnegie + * Mellon University, makes this software available to CMU to distribute + * or use in any manner that they see fit as long as this message is kept with + * the software. For this reason TFS also grants any other persons or + * organisations permission to use or modify this software. + * + * TFS supplies this software to be publicly redistributed + * on the understanding that TFS is not responsible for the correct + * functioning of this software in any circumstances. + * + * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 + */ + +#ifndef _SCSI_SCSICONF_H +#define _SCSI_SCSICONF_H + +#include +#include +#include + +static __inline void _lto2b(u_int32_t val, u_int8_t *bytes); +static __inline void _lto3b(u_int32_t val, u_int8_t *bytes); +static __inline void _lto4b(u_int32_t val, u_int8_t *bytes); +static __inline void _lto8b(u_int64_t val, u_int8_t *bytes); +static __inline u_int32_t _2btol(u_int8_t *bytes); +static __inline u_int32_t _3btol(u_int8_t *bytes); +static __inline u_int32_t _4btol(u_int8_t *bytes); +static __inline u_int64_t _5btol(u_int8_t *bytes); +static __inline u_int64_t _8btol(u_int8_t *bytes); + +static __inline void +_lto2b(u_int32_t val, u_int8_t *bytes) +{ + + bytes[0] = (val >> 8) & 0xff; + bytes[1] = val & 0xff; +} + +static __inline void +_lto3b(u_int32_t val, u_int8_t *bytes) +{ + + bytes[0] = (val >> 16) & 0xff; + bytes[1] = (val >> 8) & 0xff; + bytes[2] = val & 0xff; +} + +static __inline void +_lto4b(u_int32_t val, u_int8_t *bytes) +{ + + bytes[0] = (val >> 24) & 0xff; + bytes[1] = (val >> 16) & 0xff; + bytes[2] = (val >> 8) & 0xff; + bytes[3] = val & 0xff; +} + +static __inline void +_lto8b(u_int64_t val, u_int8_t *bytes) +{ + + bytes[0] = (val >> 56) & 0xff; + bytes[1] = (val >> 48) & 0xff; + bytes[2] = (val >> 40) & 0xff; + bytes[3] = (val >> 32) & 0xff; + bytes[4] = (val >> 24) & 0xff; + bytes[5] = (val >> 16) & 0xff; + bytes[6] = (val >> 8) & 0xff; + bytes[7] = val & 0xff; +} + +static __inline u_int32_t +_2btol(u_int8_t *bytes) +{ + u_int32_t rv; + + rv = (bytes[0] << 8) | bytes[1]; + return rv; +} + +static __inline u_int32_t +_3btol(u_int8_t *bytes) +{ + u_int32_t rv; + + rv = (bytes[0] << 16) | (bytes[1] << 8) | bytes[2]; + return rv; +} + +static __inline u_int32_t +_4btol(u_int8_t *bytes) +{ + u_int32_t rv; + + rv = (bytes[0] << 24) | (bytes[1] << 16) | + (bytes[2] << 8) | bytes[3]; + return rv; +} + +static __inline u_int64_t +_5btol(u_int8_t *bytes) +{ + u_int64_t rv; + + rv = ((u_int64_t)bytes[0] << 32) | + ((u_int64_t)bytes[1] << 24) | + ((u_int64_t)bytes[2] << 16) | + ((u_int64_t)bytes[3] << 8) | + (u_int64_t)bytes[4]; + return rv; +} + +static __inline u_int64_t +_8btol(u_int8_t *bytes) +{ + u_int64_t rv; + + rv = (((u_int64_t)bytes[0]) << 56) | + (((u_int64_t)bytes[1]) << 48) | + (((u_int64_t)bytes[2]) << 40) | + (((u_int64_t)bytes[3]) << 32) | + (((u_int64_t)bytes[4]) << 24) | + (((u_int64_t)bytes[5]) << 16) | + (((u_int64_t)bytes[6]) << 8) | + ((u_int64_t)bytes[7]); + return rv; +} + +#ifdef _KERNEL + +#define DEVID_NONE 0 +#define DEVID_NAA 1 +#define DEVID_EUI 2 +#define DEVID_T10 3 +#define DEVID_SERIAL 4 +#define DEVID_WWN 5 + +struct devid { + u_int8_t d_type; + u_int8_t d_flags; +#define DEVID_F_PRINT (1<<0) + u_int8_t d_refcount; + u_int8_t d_len; + + /* + * the devid struct is basically a header, the actual id is allocated + * immediately after it. + */ +}; + +#define DEVID_CMP(_a, _b) ( \ + (_a) != NULL && (_b) != NULL && \ + ((_a) == (_b) || \ + ((_a)->d_type != DEVID_NONE && \ + (_a)->d_type == (_b)->d_type && \ + (_a)->d_len == (_b)->d_len && \ + bcmp((_a) + 1, (_b) + 1, (_a)->d_len) == 0)) \ +) + +struct devid * devid_alloc(u_int8_t, u_int8_t, u_int8_t, u_int8_t *); +struct devid * devid_copy(struct devid *); +void devid_free(struct devid *); + +/* + * Each existing device (scsibus + target + lun) + * - is described by a scsi_link struct. + * Each scsi_link struct + * - identifies the device's softc and scsi_adapter. + * Each scsi_adapter struct + * - contains pointers to the device's scsi functions. + * Each scsibus_softc has an SLIST + * - holding pointers to the scsi_link structs of devices on that scsi bus. + * Each individual device + * - knows the address of its scsi_link structure. + */ + +struct scsi_xfer; +struct scsi_link; +struct scsibus_softc; + +/* + * Temporary hack + */ +extern int scsi_autoconf; + +/* + * These entrypoints are called by the high-end drivers to get services from + * whatever low-end drivers they are attached to. Each adapter type has one + * of these statically allocated. + */ +struct scsi_adapter { + void (*scsi_cmd)(struct scsi_xfer *); + void (*dev_minphys)(struct buf *, struct scsi_link *); + int (*dev_probe)(struct scsi_link *); + void (*dev_free)(struct scsi_link *); + int (*ioctl)(struct scsi_link *, u_long, caddr_t, int); +}; + +struct scsi_iopool; + +struct scsi_iohandler { + TAILQ_ENTRY(scsi_iohandler) q_entry; + u_int q_state; + + struct scsi_iopool *pool; + void (*handler)(void *, void *); + void *cookie; +}; +TAILQ_HEAD(scsi_runq, scsi_iohandler); + +struct scsi_iopool { + /* access to the IOs */ + void *iocookie; + /* + * Get an IO. This must reserve all resources that are necessary + * to send the transfer to the device. The resources must stay + * reserved during the lifetime of the IO, as the IO may be re-used + * without being io_put(), first. + */ + void *(*io_get)(void *); + void (*io_put)(void *, void *); + + /* the runqueue */ + struct scsi_runq queue; + /* runqueue semaphore */ + u_int running; + /* protection for the runqueue and its semaphore */ + struct mutex mtx; +}; + +struct scsi_xshandler { + struct scsi_iohandler ioh; /* must be first */ + + struct scsi_link *link; + void (*handler)(struct scsi_xfer *); +}; + +/* + * This structure describes the connection between an adapter driver and + * a device driver, and is used by each to call services provided by + * the other, and to allow generic scsi glue code to call these services + * as well. + */ +struct scsi_link { + SLIST_ENTRY(scsi_link) bus_list; + + u_int state; +#define SDEV_S_DYING (1<<1) + + u_int16_t target; /* targ of this dev */ + u_int16_t lun; /* lun of this dev */ + u_int16_t openings; /* available operations per lun */ + u_int64_t port_wwn; /* world wide name of port */ + u_int64_t node_wwn; /* world wide name of node */ + u_int16_t flags; /* flags that all devices have */ +#define SDEV_REMOVABLE 0x0001 /* media is removable */ +#define SDEV_MEDIA_LOADED 0x0002 /* device figures are still valid */ +#define SDEV_READONLY 0x0004 /* device is read-only */ +#define SDEV_OPEN 0x0008 /* at least 1 open session */ +#define SDEV_DBX 0x00f0 /* debugging flags (scsi_debug.h) */ +#define SDEV_EJECTING 0x0100 /* eject on device close */ +#define SDEV_ATAPI 0x0200 /* device is ATAPI */ +#define SDEV_UMASS 0x0400 /* device is UMASS SCSI */ +#define SDEV_VIRTUAL 0x0800 /* device is virtualised on the hba */ +#define SDEV_OWN_IOPL 0x1000 /* scsibus */ +#define SDEV_UFI 0x2000 /* Universal Floppy Interface */ + u_int16_t quirks; /* per-device oddities */ +#define SDEV_AUTOSAVE 0x0001 /* do implicit SAVEDATAPOINTER on disconnect */ +#define SDEV_NOSYNC 0x0002 /* does not grok SDTR */ +#define SDEV_NOWIDE 0x0004 /* does not grok WDTR */ +#define SDEV_NOTAGS 0x0008 /* lies about having tagged queueing */ +#define SDEV_NOSYNCCACHE 0x0010 /* no SYNCHRONIZE_CACHE */ +#define ADEV_NOSENSE 0x0020 /* No request sense - ATAPI */ +#define ADEV_LITTLETOC 0x0040 /* little-endian TOC - ATAPI */ +#define ADEV_NOCAPACITY 0x0080 /* no READ CD CAPACITY */ +#define ADEV_NODOORLOCK 0x0100 /* can't lock door */ + int (*interpret_sense)(struct scsi_xfer *); + void *device_softc; /* needed for call to foo_start */ + struct scsibus_softc *bus; /* link to the scsibus we're on */ + struct scsi_inquiry_data inqdata; /* copy of INQUIRY data from probe */ + struct devid *id; + + struct scsi_runq queue; + u_int running; + u_short pending; + + struct scsi_iopool *pool; +}; + +int scsiprint(void *, const char *); + +/* + * This describes matching information for scsi_inqmatch(). The more things + * match, the higher the configuration priority. + */ +struct scsi_inquiry_pattern { + u_int8_t type; + int removable; + char *vendor; + char *product; + char *revision; +}; + +struct scsibus_attach_args { + const struct scsi_adapter *saa_adapter; + void *saa_adapter_softc; + struct scsi_iopool *saa_pool; + u_int64_t saa_wwpn; + u_int64_t saa_wwnn; + u_int16_t saa_quirks; + u_int16_t saa_flags; + u_int16_t saa_openings; + u_int16_t saa_adapter_target; +#define SDEV_NO_ADAPTER_TARGET 0xffff + u_int16_t saa_adapter_buswidth; + u_int8_t saa_luns; +}; + +/* + * One of these is allocated and filled in for each scsi bus. + * It holds pointers to allow the scsi bus to get to the driver + * that is running each LUN on the bus. + * It also has a template entry which is the prototype struct + * supplied by the adapter driver. This is used to initialise + * the others, before they have the rest of the fields filled in. + */ +struct scsibus_softc { + struct device sc_dev; + SLIST_HEAD(, scsi_link) sc_link_list; + void *sb_adapter_softc; + const struct scsi_adapter *sb_adapter; + struct scsi_iopool *sb_pool; + u_int16_t sb_quirks; + u_int16_t sb_flags; + u_int16_t sb_openings; + u_int16_t sb_adapter_buswidth; + u_int16_t sb_adapter_target; + u_int8_t sb_luns; +}; + +/* + * This is used to pass information from the high-level configuration code + * to the device-specific drivers. + */ +struct scsi_attach_args { + struct scsi_link *sa_sc_link; +}; + +/* + * Each scsi transaction is fully described by one of these structures. + * It includes information about the source of the command and also the + * device and adapter for which the command is destined. + * (via the scsi_link structure) + */ +struct scsi_xfer { + SIMPLEQ_ENTRY(scsi_xfer) xfer_list; + int flags; + struct scsi_link *sc_link; /* all about our device and adapter */ + int retries; /* the number of times to retry */ + int timeout; /* in milliseconds */ + struct scsi_generic cmd; /* The scsi command to execute */ + int cmdlen; /* how long it is */ + u_char *data; /* dma address OR a uio address */ + int datalen; /* data len (blank if uio) */ + size_t resid; /* how much buffer was not touched */ + int error; /* an error value */ + struct buf *bp; /* If we need to associate with a buf */ + struct scsi_sense_data sense; /* 18 bytes*/ + u_int8_t status; /* SCSI status */ + /* + * timeout structure for hba's to use for a command + */ + struct timeout stimeout; + void *cookie; + void (*done)(struct scsi_xfer *); + + void *io; /* adapter io resource */ +}; +SIMPLEQ_HEAD(scsi_xfer_list, scsi_xfer); + +/* + * Per-request Flag values + */ +#define SCSI_NOSLEEP 0x00001 /* don't sleep */ +#define SCSI_POLL 0x00002 /* poll for completion */ +#define SCSI_AUTOCONF 0x00003 /* shorthand for SCSI_POLL | SCSI_NOSLEEP */ +#define ITSDONE 0x00008 /* the transfer is as done as it gets */ +#define SCSI_SILENT 0x00020 /* don't announce NOT READY or MEDIA CHANGE */ +#define SCSI_IGNORE_NOT_READY 0x00040 /* ignore NOT READY */ +#define SCSI_IGNORE_MEDIA_CHANGE 0x00080 /* ignore MEDIA CHANGE */ +#define SCSI_IGNORE_ILLEGAL_REQUEST 0x00100 /* ignore ILLEGAL REQUEST */ +#define SCSI_RESET 0x00200 /* Reset the device in question */ +#define SCSI_DATA_IN 0x00800 /* expect data to come INTO memory */ +#define SCSI_DATA_OUT 0x01000 /* expect data to flow OUT of memory */ +#define SCSI_TARGET 0x02000 /* This defines a TARGET mode op. */ +#define SCSI_ESCAPE 0x04000 /* Escape operation */ +#define SCSI_PRIVATE 0xf0000 /* private to each HBA flags */ + +/* + * Escape op-codes. This provides an extensible setup for operations + * that are not scsi commands. They are intended for modal operations. + */ + +#define SCSI_OP_TARGET 0x0001 +#define SCSI_OP_RESET 0x0002 +#define SCSI_OP_BDINFO 0x0003 + +/* + * Error values an adapter driver may return + */ +#define XS_NOERROR 0 /* there is no error, (sense is invalid) */ +#define XS_SENSE 1 /* Check the returned sense for the error */ +#define XS_DRIVER_STUFFUP 2 /* Driver failed to perform operation */ +#define XS_SELTIMEOUT 3 /* The device timed out.. turned off? */ +#define XS_TIMEOUT 4 /* The Timeout reported was caught by SW */ +#define XS_BUSY 5 /* The device busy, try again later? */ +#define XS_SHORTSENSE 6 /* Check the ATAPI sense for the error */ +#define XS_RESET 8 /* bus was reset; possible retry command */ + +/* + * Possible retries for scsi_test_unit_ready() + */ +#define TEST_READY_RETRIES 5 + +/* + * Possible retries for most SCSI commands. + */ +#define SCSI_RETRIES 4 + +const void *scsi_inqmatch(struct scsi_inquiry_data *, const void *, int, + int, int *); + +void scsi_init(void); +int scsi_test_unit_ready(struct scsi_link *, int, int); +int scsi_inquire(struct scsi_link *, struct scsi_inquiry_data *, int); +int scsi_read_cap_10(struct scsi_link *, struct scsi_read_cap_data *, int); +int scsi_read_cap_16(struct scsi_link *, struct scsi_read_cap_data_16 *, + int); +int scsi_inquire_vpd(struct scsi_link *, void *, u_int, u_int8_t, int); +void scsi_init_inquiry(struct scsi_xfer *, u_int8_t, u_int8_t, + void *, size_t); +int scsi_prevent(struct scsi_link *, int, int); +int scsi_start(struct scsi_link *, int, int); +void scsi_parse_blkdesc(struct scsi_link *, union scsi_mode_sense_buf *, int, + u_int32_t *, u_int64_t *, u_int32_t *); +int scsi_do_mode_sense(struct scsi_link *, int, + union scsi_mode_sense_buf *, void **, int, int, int *); +void scsi_parse_blkdesc(struct scsi_link *, union scsi_mode_sense_buf *, int, + u_int32_t *, u_int64_t *, u_int32_t *); +int scsi_mode_select(struct scsi_link *, int, struct scsi_mode_header *, + int, int); +int scsi_mode_select_big(struct scsi_link *, int, + struct scsi_mode_header_big *, int, int); +void scsi_copy_internal_data(struct scsi_xfer *, void *, size_t); +void scsi_done(struct scsi_xfer *); +int scsi_do_ioctl(struct scsi_link *, u_long, caddr_t, int); +void sc_print_addr(struct scsi_link *); +int scsi_report_luns(struct scsi_link *, int, + struct scsi_report_luns_data *, u_int32_t, int, int); +int scsi_interpret_sense(struct scsi_xfer *); + +void scsi_print_sense(struct scsi_xfer *); +void scsi_strvis(u_char *, u_char *, int); +int scsi_delay(struct scsi_xfer *, int); + +int scsi_probe(struct scsibus_softc *, int, int); +int scsi_probe_bus(struct scsibus_softc *); +int scsi_probe_target(struct scsibus_softc *, int); +int scsi_probe_lun(struct scsibus_softc *, int, int); + +int scsi_detach(struct scsibus_softc *, int, int, int); +int scsi_detach_target(struct scsibus_softc *, int, int); +int scsi_detach_lun(struct scsibus_softc *, int, int, int); + +int scsi_req_probe(struct scsibus_softc *, int, int); +int scsi_req_detach(struct scsibus_softc *, int, int, int); + +int scsi_activate(struct scsibus_softc *, int, int, int); + +struct scsi_link * scsi_get_link(struct scsibus_softc *, int, int); + +#define SID_ANSII_REV(x) ((x)->version & SID_ANSII) +#define SID_RESPONSE_FORMAT(x) ((x)->response_format & SID_RESPONSE_DATA_FMT) + +#define SCSI_REV_0 0x00 /* No conformance to any standard. */ +#define SCSI_REV_1 0x01 /* (Obsolete) SCSI-1 in olden times. */ +#define SCSI_REV_2 0x02 /* (Obsolete) SCSI-2 in olden times. */ +#define SCSI_REV_SPC 0x03 /* ANSI INCITS 301-1997 (SPC). */ +#define SCSI_REV_SPC2 0x04 /* ANSI INCITS 351-2001 (SPC-2) */ +#define SCSI_REV_SPC3 0x05 /* ANSI INCITS 408-2005 (SPC-3) */ +#define SCSI_REV_SPC4 0x06 /* ANSI INCITS 513-2015 (SPC-4) */ +#define SCSI_REV_SPC5 0x07 /* T10/BSR INCITS 503 (SPC-5) */ + +struct scsi_xfer * scsi_xs_get(struct scsi_link *, int); +void scsi_xs_exec(struct scsi_xfer *); +int scsi_xs_sync(struct scsi_xfer *); +void scsi_xs_put(struct scsi_xfer *); + +/* + * iopool stuff + */ +void scsi_iopool_init(struct scsi_iopool *, void *, + void *(*)(void *), void (*)(void *, void *)); +void scsi_iopool_run(struct scsi_iopool *); +void scsi_iopool_destroy(struct scsi_iopool *); +void scsi_link_shutdown(struct scsi_link *); + +void * scsi_io_get(struct scsi_iopool *, int); +void scsi_io_put(struct scsi_iopool *, void *); + +/* + * default io allocator. + */ +#define SCSI_IOPOOL_POISON ((void *)0x5c5) +void * scsi_default_get(void *); +void scsi_default_put(void *, void *); + +/* + * io handler interface + */ +void scsi_ioh_set(struct scsi_iohandler *, struct scsi_iopool *, + void (*)(void *, void *), void *); +int scsi_ioh_add(struct scsi_iohandler *); +int scsi_ioh_del(struct scsi_iohandler *); + +void scsi_xsh_set(struct scsi_xshandler *, struct scsi_link *, + void (*)(struct scsi_xfer *)); +int scsi_xsh_add(struct scsi_xshandler *); +int scsi_xsh_del(struct scsi_xshandler *); + +/* + * utility functions + */ +int scsi_pending_start(struct mutex *, u_int *); +int scsi_pending_finish(struct mutex *, u_int *); + +/* + * Utility functions for SCSI HBA emulation. + */ +void scsi_cmd_rw_decode(struct scsi_generic *, u_int64_t *, u_int32_t *); + +#endif /* _KERNEL */ +#endif /* _SCSI_SCSICONF_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/scsi/sdvar.h b/lib/libc/include/generic-openbsd/scsi/sdvar.h new file mode 100644 index 0000000000..db5fa0a3a5 --- /dev/null +++ b/lib/libc/include/generic-openbsd/scsi/sdvar.h @@ -0,0 +1,77 @@ +/* $OpenBSD: sdvar.h,v 1.52 2020/09/23 15:24:16 krw Exp $ */ +/* $NetBSD: sdvar.h,v 1.7 1998/08/17 00:49:03 mycroft Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Charles M. Hannum. + * + * 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. + */ + +/* + * Originally written by Julian Elischer (julian@dialix.oz.au) + * for TRW Financial Systems for use under the MACH(2.5) operating system. + * + * TRW Financial Systems, in accordance with their agreement with Carnegie + * Mellon University, makes this software available to CMU to distribute + * or use in any manner that they see fit as long as this message is kept with + * the software. For this reason TFS also grants any other persons or + * organisations permission to use or modify this software. + * + * TFS supplies this software to be publicly redistributed + * on the understanding that TFS is not responsible for the correct + * functioning of this software in any circumstances. + * + * Ported to run under 386BSD by Julian Elischer (julian@dialix.oz.au) Sept 1992 + */ + +#ifndef _SCSI_SDVAR_H +#define _SCSI_SDVAR_H + +#ifdef _KERNEL +struct sd_softc { + struct device sc_dev; + struct disk sc_dk; + struct bufq sc_bufq; + + int flags; +#define SDF_DIRTY 0x20 /* disk is dirty; needs cache flush */ +#define SDF_DYING 0x40 /* dying, when deactivated */ +#define SDF_THIN 0x01 /* disk is thin provisioned */ + struct scsi_link *sc_link; /* contains our targ, lun, etc. */ + struct disk_parms { + u_int32_t heads; /* number of heads */ + u_int32_t cyls; /* number of cylinders */ + u_int32_t sectors; /* number of sectors/track */ + u_int32_t secsize; /* number of bytes/sector */ + u_int64_t disksize; /* total number sectors */ + u_int32_t unmap_sectors; /* maximum sectors/unmap */ + u_int32_t unmap_descs; /* maximum descriptors/unmap */ + } params; + + struct scsi_xshandler sc_xsh; +}; +#endif /* _KERNEL */ +#endif /* _SCSI_SDVAR_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/scsi/ses.h b/lib/libc/include/generic-openbsd/scsi/ses.h new file mode 100644 index 0000000000..9e0247222d --- /dev/null +++ b/lib/libc/include/generic-openbsd/scsi/ses.h @@ -0,0 +1,235 @@ +/* $OpenBSD: ses.h,v 1.11 2024/09/04 07:54:53 mglocker Exp $ */ +/* + * Copyright (c) 2005 Marco Peereboom + * 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 AUTHORS 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 AUTHORS 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 _SCSI_SES_H_ +#define _SCSI_SES_H_ + +/* the scsi command */ +struct ses_scsi_diag { + u_int8_t opcode; /* SEND_DIAGNOSTIC or RECEIVE_DIAGNOSTIC */ + u_int8_t flags; +#define SES_DIAG_PCV (1<<0) /* page code valid */ +#define SES_DIAG_PF (1<<4) /* set this bit if page code is valid */ + u_int8_t pgcode; +#define SES_PAGE_CONFIG 0x01 /* Configuration */ +#define SES_PAGE_STATUS 0x02 /* Enclosure Status */ +#define SES_PAGE_EDESC 0x07 /* Element Descriptor */ + u_int16_t length; + u_int8_t control; +} __packed; + + +/* all the different sensor types */ +#define SES_T_UNSPEC 0x00 +#define SES_T_DEVICE 0x01 +#define SES_T_POWERSUPPLY 0x02 +#define SES_T_COOLING 0x03 +#define SES_T_TEMP 0x04 +#define SES_T_DOORLOCK 0x05 +#define SES_T_ALARM 0x06 +#define SES_T_ENC_SRV_CTRL 0x07 +#define SES_T_SCC_CTRL 0x08 +#define SES_T_NONVOL_CACHE 0x09 +#define SES_T_INV_OP_REASON 0x0a +#define SES_T_UPS 0x0b +#define SES_T_DISPLAY 0x0c +#define SES_T_KEYPAD 0x0d +#define SES_T_ENCLOSURE 0x0e +#define SES_T_SCSI_PORT_TRANS 0x0f +#define SES_T_LANGUAGE 0x10 +#define SES_T_COMM_PORT 0x11 +#define SES_T_VOLTAGE 0x12 +#define SES_T_CURRENT 0x13 +#define SES_T_SCSI_TARGET_PORT 0x14 +#define SES_T_SCSI_INIT_PORT 0x15 +#define SES_T_SIMP_SUBENC 0x16 +#define SES_T_ARRAY_DEVICE 0x17 + +#define SES_NUM_TYPES 256 + +/* diagnostic page header */ +struct ses_config_hdr { + u_int8_t pgcode; /* SES_PAGE_CONFIG */ + u_int8_t n_subenc; + u_int16_t length; + u_int32_t gencode; +} __packed; +#define SES_CFG_HDRLEN sizeof(struct ses_config_hdr) + +/* enclosure descriptor header */ +struct ses_enc_hdr { + u_int8_t enc_id; + u_int8_t subenc_id; + u_int8_t n_types; + u_int8_t vendor_len; +} __packed; +#define SES_ENC_HDRLEN sizeof(struct ses_enc_hdr) + +/* enclosure descriptor strings */ +struct ses_enc_desc { + u_int8_t logical_id[8]; /* this isn't a string */ + u_int8_t vendor_id[8]; + u_int8_t prod_id[16]; + u_int8_t prod_rev[4]; + u_int8_t vendor[0]; +} __packed; + +/* type descriptor header */ +struct ses_type_desc { + u_int8_t type; + u_int8_t n_elem; + u_int8_t subenc_id; + u_int8_t desc_len; +} __packed; +#define SES_TYPE_DESCLEN sizeof(struct ses_type_desc) + +/* status page header */ +struct ses_status_hdr { + u_int8_t pgcode; /* SES_PAGE_STATUS */ + u_int8_t flags; +#define SES_STAT_UNRECOV (1<<0) /* unrecoverable error */ +#define SES_STAT_CRIT (1<<1) /* critical error */ +#define SES_STAT_NONCRIT (1<<2) /* noncritical error */ +#define SES_STAT_INFO (1<<3) /* info available */ +#define SES_STAT_INVOP (1<<4) /* invalid operation */ + u_int16_t length; + u_int32_t gencode; +} __packed; +#define SES_STAT_HDRLEN sizeof(struct ses_status_hdr) + +struct ses_status { + u_int8_t com; +#define SES_STAT_CODE_MASK 0x0f +#define SES_STAT_CODE(x) ((x) & SES_STAT_CODE_MASK) +#define SES_STAT_CODE_UNSUP 0x00 /* unsupported */ +#define SES_STAT_CODE_OK 0x01 /* installed and ok */ +#define SES_STAT_CODE_CRIT 0x02 /* critical */ +#define SES_STAT_CODE_NONCRIT 0x03 /* warning */ +#define SES_STAT_CODE_UNREC 0x04 /* unrecoverable */ +#define SES_STAT_CODE_NOTINST 0x05 /* not installed */ +#define SES_STAT_CODE_UNKNOWN 0x06 /* unknown */ +#define SES_STAT_CODE_NOTAVAIL 0x07 /* not available */ +#define SES_STAT_SWAP (1<<4) /* element has been swapped */ +#define SES_STAT_DISABLED (1<<5) /* disabled */ +#define SES_STAT_PRDFAIL (1<<6) /* predicted failure */ +#define SES_STAT_SELECT (1<<7) /* set to modify element */ + + u_int8_t f1; /* use of these flags depends on the SES_T */ + u_int8_t f2; + u_int8_t f3; +} __packed; +#define SES_STAT_ELEMLEN sizeof(struct ses_status) + +/* device status */ +/* f1 is the device address */ +/* f2 */ +#define SES_S_DEV_REPORT (1<<0) /* enc report in progress */ +#define SES_S_DEV_IDENT (1<<1) /* currently identifying */ +#define SES_S_DEV_REMOVE (1<<2) /* ready to remove */ +#define SES_S_DEV_INSERT (1<<3) /* ready to insert */ +#define SES_S_DEV_ENCBYPB (1<<4) /* port B bypassed by enc */ +#define SES_S_DEV_ENCBYPA (1<<5) /* port A bypassed by enc */ +#define SES_S_DEV_DONOTREM (1<<6) /* do not remove */ +#define SES_S_DEV_APPCLBYPA (1<<7) /* port A bypassed by app */ +/* f3 */ +#define SES_S_DEV_DEVBYPB (1<<0) /* port B bypassed by dev */ +#define SES_S_DEV_DEVBYPA (1<<1) /* port A bypassed by dev */ +#define SES_S_DEV_BYPB (1<<2) +#define SES_S_DEV_BYPA (1<<3) +#define SES_S_DEV_OFF (1<<4) /* device is off */ +#define SES_S_DEV_FAULTRQST (1<<5) /* fault indicator rqsted */ +#define SES_S_DEV_FAULTSENSE (1<<6) /* fault sensed */ +#define SES_S_DEV_APPCLBYPB (1<<7) /* port B bypassed by app */ + +/* device configuration */ +/* f1 is reserved */ +/* f2 */ +#define SES_C_DEV_IDENT (1<<1) /* ident */ +#define SES_C_DEV_REMOVE (1<<2) /* remove */ +#define SES_C_DEV_INSERT (1<<3) /* insert */ +#define SES_C_DEV_DONOTREM (1<<6) /* do not remove */ +#define SES_C_DEV_ACTIVE (1<<7) /* active indicator */ +#define SES_C_DEV_F2MASK (SES_C_DEV_IDENT | SES_C_DEV_REMOVE | \ + SES_C_DEV_INSERT | SES_C_DEV_DONOTREM | SES_C_DEV_ACTIVE ) +/* f3 */ +#define SES_C_DEV_BYPB (1<<2) /* port B bypass */ +#define SES_C_DEV_BYPA (1<<3) /* port A bypass */ +#define SES_C_DEV_OFF (1<<4) /* off */ +#define SES_C_DEV_FAULT (1<<5) /* fault indicator */ +#define SES_C_DEV_F3MASK (SES_C_DEV_BYPB | SES_C_DEV_BYPA | \ + SES_C_DEV_OFF | SES_C_DEV_FAULT) + +/* power supply element */ +#define SES_S_PSU_IDENT(d) ((d)->f1 & (1<<6)) /* identify */ +#define SES_S_PSU_DCOC(d) ((d)->f2 & (1<<1)) /* DC over current */ +#define SES_S_PSU_DCUV(d) ((d)->f2 & (1<<2)) /* DC under voltage */ +#define SES_S_PSU_DCOV(d) ((d)->f2 & (1<<3)) /* DC over voltage */ +#define SES_S_PSU_DCFAIL(d) ((d)->f3 & (1<<0)) /* DC fail */ +#define SES_S_PSU_ACFAIL(d) ((d)->f3 & (1<<1)) /* AC fail */ +#define SES_S_PSU_TEMPWARN(d) ((d)->f3 & (1<<2)) /* Temp warn */ +#define SES_S_PSU_OVERTEMP(d) ((d)->f3 & (1<<3)) /* over temp fail */ +#define SES_S_PSU_OFF(d) ((d)->f3 & (1<<4)) /* is the unit off */ +#define SES_S_PSU_RQSTON(d) ((d)->f3 & (1<<5)) /* manually on */ +#define SES_S_PSU_FAIL(d) ((d)->f3 & (1<<6)) /* fail is set on */ + +/* cooling element */ +#define SES_S_COOL_IDENT(d) ((d)->f1 & (1<<6)) /* identify */ +#define SES_S_COOL_SPEED_MASK 0x03 +#define SES_S_COOL_SPEED(d) ((d)->f2 + \ + ((u_int16_t)((d)->f2 & SES_S_COOL_SPEED_MASK) << 8)) +#define SES_S_COOL_FACTOR 10 +#define SES_S_COOL_CODE(d) ((d)->f3 & 0x7) /* actual speed code */ +#define SES_S_COOL_C_STOPPED 0x0 /* stopped */ +#define SES_S_COOL_C_LOW1 0x1 /* lowest speed */ +#define SES_S_COOL_C_LOW2 0x2 /* second lowest speed */ +#define SES_S_COOL_C_LOW3 0x3 /* third lowest speed */ +#define SES_S_COOL_C_INTER 0x4 /* intermediate speed */ +#define SES_S_COOL_C_HI3 0x5 /* third highest speed */ +#define SES_S_COOL_C_HI2 0x6 /* second highest speed */ +#define SES_S_COOL_C_HI1 0x7 /* highest speed */ +#define SES_S_COOL_OFF ((d)->f3 & (1<<4)) /* not cooling */ +#define SES_S_COOL_RQSTON ((d)->f3 & (1<<5)) /* manually on */ +#define SES_S_COOL_FAIL ((d)->f3 & (1<<6)) /* fail indic is on */ + +/* temperature sensor */ +#define SES_S_TEMP_IDENT(d) ((d)->f1 & (1<<7)) /* identify */ +#define SES_S_TEMP(d) ((d)->f2) +#define SES_S_TEMP_OFFSET (-20) +#define SES_S_TEMP_UTWARN ((d)->f3 & (1<<0)) /* under temp warning */ +#define SES_S_TEMP_UTFAIL ((d)->f3 & (1<<1)) /* under temp failure */ +#define SES_S_TEMP_OTWARN ((d)->f3 & (1<<2)) /* over temp warning */ +#define SES_S_TEMP_OTFAIL ((d)->f3 & (1<<3)) /* over temp failure */ + +/* + * the length of the status page is the header and a status element for + * each type plus the number of elements for each type + */ +#define SES_STAT_LEN(t, e) \ + (SES_STAT_HDRLEN + SES_STAT_ELEMLEN * ((t)+(e))) + +#endif /* _SCSI_SES_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/search.h b/lib/libc/include/generic-openbsd/search.h new file mode 100644 index 0000000000..b2210203ca --- /dev/null +++ b/lib/libc/include/generic-openbsd/search.h @@ -0,0 +1,57 @@ +/* $OpenBSD: search.h,v 1.10 2014/07/18 04:16:09 matthew Exp $ */ +/* $NetBSD: search.h,v 1.9 1995/08/08 21:14:45 jtc Exp $ */ + +/* + * Written by J.T. Conklin + * Public domain. + */ + +#ifndef _SEARCH_H_ +#define _SEARCH_H_ + +#include +#include + +#ifndef _SIZE_T_DEFINED_ +#define _SIZE_T_DEFINED_ +typedef __size_t size_t; +#endif + +typedef struct entry { + char *key; + void *data; +} ENTRY; + +typedef enum { + FIND, ENTER +} ACTION; + +typedef enum { + preorder, + postorder, + endorder, + leaf +} VISIT; + +__BEGIN_DECLS +int hcreate(size_t); +void hdestroy(void); +ENTRY *hsearch(ENTRY, ACTION); + +void *lfind(const void *, const void *, size_t *, size_t, + int (*)(const void *, const void *)); +void *lsearch(const void *, void *, size_t *, size_t, + int (*)(const void *, const void *)); +void insque(void *, void *); +void remque(void *); + +void *tdelete(const void * __restrict, void ** __restrict, + int (*)(const void *, const void *)); +void *tfind(const void *, void * const *, + int (*)(const void *, const void *)); +void *tsearch(const void *, void **, + int (*)(const void *, const void *)); +void twalk(const void *, void (*)(const void *, VISIT, int)); +__END_DECLS + +#endif /* !_SEARCH_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/semaphore.h b/lib/libc/include/generic-openbsd/semaphore.h new file mode 100644 index 0000000000..5cd9001c8d --- /dev/null +++ b/lib/libc/include/generic-openbsd/semaphore.h @@ -0,0 +1,62 @@ +/* $OpenBSD: semaphore.h,v 1.1 2017/10/15 23:40:33 guenther Exp $ */ + +/* semaphore.h: POSIX 1003.1b semaphores */ + +/*- + * Copyright (c) 1996, 1997 + * HD Associates, Inc. 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 HD Associates, Inc + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES 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 HD ASSOCIATES 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 _SEMAPHORE_H_ +#define _SEMAPHORE_H_ + +#include + +/* Opaque type definition. */ +struct __sem; +typedef struct __sem *sem_t; +struct timespec; + +#define SEM_FAILED ((sem_t *)0) + +__BEGIN_DECLS +int sem_init(sem_t *, int, unsigned int); +int sem_destroy(sem_t *); +sem_t *sem_open(const char *, int, ...); +int sem_close(sem_t *); +int sem_unlink(const char *); +int sem_wait(sem_t *); +int sem_timedwait(sem_t * __restrict, const struct timespec * __restrict); +int sem_trywait(sem_t *); +int sem_post(sem_t *); +int sem_getvalue(sem_t * __restrict, int * __restrict); +__END_DECLS + +#endif /* _SEMAPHORE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/setjmp.h b/lib/libc/include/generic-openbsd/setjmp.h new file mode 100644 index 0000000000..fd6544b8dc --- /dev/null +++ b/lib/libc/include/generic-openbsd/setjmp.h @@ -0,0 +1,67 @@ +/* $OpenBSD: setjmp.h,v 1.7 2016/05/23 00:18:56 guenther Exp $ */ +/* $NetBSD: setjmp.h,v 1.11 1994/12/20 10:35:44 cgd Exp $ */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)setjmp.h 8.2 (Berkeley) 1/21/94 + */ + +#ifndef _SETJMP_H_ +#define _SETJMP_H_ + +#include +#include + +#if __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE +typedef long sigjmp_buf[_JBLEN + 1]; +#endif /* __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE */ + +typedef long jmp_buf[_JBLEN]; + +__BEGIN_DECLS +__returns_twice int setjmp(jmp_buf); +__dead void longjmp(jmp_buf, int); + +#if __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE +__returns_twice int sigsetjmp(sigjmp_buf, int); +__dead void siglongjmp(sigjmp_buf, int); +#endif /* __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE */ + +#if __BSD_VISIBLE || __XPG_VISIBLE +__returns_twice int _setjmp(jmp_buf); +__dead void _longjmp(jmp_buf, int); +#endif /* __BSD_VISIBLE || __XPG_VISIBLE */ +__END_DECLS + +#endif /* !_SETJMP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sha1.h b/lib/libc/include/generic-openbsd/sha1.h new file mode 100644 index 0000000000..f98d41c8e5 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sha1.h @@ -0,0 +1,57 @@ +/* $OpenBSD: sha1.h,v 1.24 2012/12/05 23:19:57 deraadt Exp $ */ + +/* + * SHA-1 in C + * By Steve Reid + * 100% Public Domain + */ + +#ifndef _SHA1_H +#define _SHA1_H + +#define SHA1_BLOCK_LENGTH 64 +#define SHA1_DIGEST_LENGTH 20 +#define SHA1_DIGEST_STRING_LENGTH (SHA1_DIGEST_LENGTH * 2 + 1) + +typedef struct { + u_int32_t state[5]; + u_int64_t count; + u_int8_t buffer[SHA1_BLOCK_LENGTH]; +} SHA1_CTX; + +__BEGIN_DECLS +void SHA1Init(SHA1_CTX *); +void SHA1Pad(SHA1_CTX *); +void SHA1Transform(u_int32_t [5], const u_int8_t [SHA1_BLOCK_LENGTH]) + __attribute__((__bounded__(__minbytes__,1,5))) + __attribute__((__bounded__(__minbytes__,2,SHA1_BLOCK_LENGTH))); +void SHA1Update(SHA1_CTX *, const u_int8_t *, size_t) + __attribute__((__bounded__(__string__,2,3))); +void SHA1Final(u_int8_t [SHA1_DIGEST_LENGTH], SHA1_CTX *) + __attribute__((__bounded__(__minbytes__,1,SHA1_DIGEST_LENGTH))); +char *SHA1End(SHA1_CTX *, char *) + __attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH))); +char *SHA1File(const char *, char *) + __attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH))); +char *SHA1FileChunk(const char *, char *, off_t, off_t) + __attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH))); +char *SHA1Data(const u_int8_t *, size_t, char *) + __attribute__((__bounded__(__string__,1,2))) + __attribute__((__bounded__(__minbytes__,3,SHA1_DIGEST_STRING_LENGTH))); +__END_DECLS + +#define HTONDIGEST(x) do { \ + x[0] = htonl(x[0]); \ + x[1] = htonl(x[1]); \ + x[2] = htonl(x[2]); \ + x[3] = htonl(x[3]); \ + x[4] = htonl(x[4]); } while (0) + +#define NTOHDIGEST(x) do { \ + x[0] = ntohl(x[0]); \ + x[1] = ntohl(x[1]); \ + x[2] = ntohl(x[2]); \ + x[3] = ntohl(x[3]); \ + x[4] = ntohl(x[4]); } while (0) + +#endif /* _SHA1_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sha2.h b/lib/libc/include/generic-openbsd/sha2.h new file mode 100644 index 0000000000..79bc16e3fb --- /dev/null +++ b/lib/libc/include/generic-openbsd/sha2.h @@ -0,0 +1,156 @@ +/* $OpenBSD: sha2.h,v 1.10 2016/09/03 17:00:29 tedu Exp $ */ + +/* + * FILE: sha2.h + * AUTHOR: Aaron D. Gifford + * + * Copyright (c) 2000-2001, Aaron D. Gifford + * 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 copyright holder nor the names of contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) 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: sha2.h,v 1.1 2001/11/08 00:02:01 adg Exp adg $ + */ + +#ifndef _SHA2_H +#define _SHA2_H + + +/*** SHA-256/384/512 Various Length Definitions ***********************/ +#define SHA224_BLOCK_LENGTH 64 +#define SHA224_DIGEST_LENGTH 28 +#define SHA224_DIGEST_STRING_LENGTH (SHA224_DIGEST_LENGTH * 2 + 1) +#define SHA256_BLOCK_LENGTH 64 +#define SHA256_DIGEST_LENGTH 32 +#define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1) +#define SHA384_BLOCK_LENGTH 128 +#define SHA384_DIGEST_LENGTH 48 +#define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1) +#define SHA512_BLOCK_LENGTH 128 +#define SHA512_DIGEST_LENGTH 64 +#define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1) +#define SHA512_256_BLOCK_LENGTH 128 +#define SHA512_256_DIGEST_LENGTH 32 +#define SHA512_256_DIGEST_STRING_LENGTH (SHA512_256_DIGEST_LENGTH * 2 + 1) + + +/*** SHA-224/256/384/512 Context Structure *******************************/ +typedef struct _SHA2_CTX { + union { + u_int32_t st32[8]; + u_int64_t st64[8]; + } state; + u_int64_t bitcount[2]; + u_int8_t buffer[SHA512_BLOCK_LENGTH]; +} SHA2_CTX; + +__BEGIN_DECLS +void SHA224Init(SHA2_CTX *); +void SHA224Transform(u_int32_t state[8], const u_int8_t [SHA224_BLOCK_LENGTH]); +void SHA224Update(SHA2_CTX *, const u_int8_t *, size_t) + __attribute__((__bounded__(__string__,2,3))); +void SHA224Pad(SHA2_CTX *); +void SHA224Final(u_int8_t [SHA224_DIGEST_LENGTH], SHA2_CTX *) + __attribute__((__bounded__(__minbytes__,1,SHA224_DIGEST_LENGTH))); +char *SHA224End(SHA2_CTX *, char *) + __attribute__((__bounded__(__minbytes__,2,SHA224_DIGEST_STRING_LENGTH))); +char *SHA224File(const char *, char *) + __attribute__((__bounded__(__minbytes__,2,SHA224_DIGEST_STRING_LENGTH))); +char *SHA224FileChunk(const char *, char *, off_t, off_t) + __attribute__((__bounded__(__minbytes__,2,SHA224_DIGEST_STRING_LENGTH))); +char *SHA224Data(const u_int8_t *, size_t, char *) + __attribute__((__bounded__(__string__,1,2))) + __attribute__((__bounded__(__minbytes__,3,SHA224_DIGEST_STRING_LENGTH))); + +void SHA256Init(SHA2_CTX *); +void SHA256Transform(u_int32_t state[8], const u_int8_t [SHA256_BLOCK_LENGTH]); +void SHA256Update(SHA2_CTX *, const u_int8_t *, size_t) + __attribute__((__bounded__(__string__,2,3))); +void SHA256Pad(SHA2_CTX *); +void SHA256Final(u_int8_t [SHA256_DIGEST_LENGTH], SHA2_CTX *) + __attribute__((__bounded__(__minbytes__,1,SHA256_DIGEST_LENGTH))); +char *SHA256End(SHA2_CTX *, char *) + __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH))); +char *SHA256File(const char *, char *) + __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH))); +char *SHA256FileChunk(const char *, char *, off_t, off_t) + __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH))); +char *SHA256Data(const u_int8_t *, size_t, char *) + __attribute__((__bounded__(__string__,1,2))) + __attribute__((__bounded__(__minbytes__,3,SHA256_DIGEST_STRING_LENGTH))); + +void SHA384Init(SHA2_CTX *); +void SHA384Transform(u_int64_t state[8], const u_int8_t [SHA384_BLOCK_LENGTH]); +void SHA384Update(SHA2_CTX *, const u_int8_t *, size_t) + __attribute__((__bounded__(__string__,2,3))); +void SHA384Pad(SHA2_CTX *); +void SHA384Final(u_int8_t [SHA384_DIGEST_LENGTH], SHA2_CTX *) + __attribute__((__bounded__(__minbytes__,1,SHA384_DIGEST_LENGTH))); +char *SHA384End(SHA2_CTX *, char *) + __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH))); +char *SHA384File(const char *, char *) + __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH))); +char *SHA384FileChunk(const char *, char *, off_t, off_t) + __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH))); +char *SHA384Data(const u_int8_t *, size_t, char *) + __attribute__((__bounded__(__string__,1,2))) + __attribute__((__bounded__(__minbytes__,3,SHA384_DIGEST_STRING_LENGTH))); + +void SHA512Init(SHA2_CTX *); +void SHA512Transform(u_int64_t state[8], const u_int8_t [SHA512_BLOCK_LENGTH]); +void SHA512Update(SHA2_CTX *, const u_int8_t *, size_t) + __attribute__((__bounded__(__string__,2,3))); +void SHA512Pad(SHA2_CTX *); +void SHA512Final(u_int8_t [SHA512_DIGEST_LENGTH], SHA2_CTX *) + __attribute__((__bounded__(__minbytes__,1,SHA512_DIGEST_LENGTH))); +char *SHA512End(SHA2_CTX *, char *) + __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH))); +char *SHA512File(const char *, char *) + __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH))); +char *SHA512FileChunk(const char *, char *, off_t, off_t) + __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH))); +char *SHA512Data(const u_int8_t *, size_t, char *) + __attribute__((__bounded__(__string__,1,2))) + __attribute__((__bounded__(__minbytes__,3,SHA512_DIGEST_STRING_LENGTH))); + +void SHA512_256Init(SHA2_CTX *); +void SHA512_256Transform(u_int64_t state[8], const u_int8_t [SHA512_256_BLOCK_LENGTH]); +void SHA512_256Update(SHA2_CTX *, const u_int8_t *, size_t) + __attribute__((__bounded__(__string__,2,3))); +void SHA512_256Pad(SHA2_CTX *); +void SHA512_256Final(u_int8_t [SHA512_256_DIGEST_LENGTH], SHA2_CTX *) + __attribute__((__bounded__(__minbytes__,1,SHA512_256_DIGEST_LENGTH))); +char *SHA512_256End(SHA2_CTX *, char *) + __attribute__((__bounded__(__minbytes__,2,SHA512_256_DIGEST_STRING_LENGTH))); +char *SHA512_256File(const char *, char *) + __attribute__((__bounded__(__minbytes__,2,SHA512_256_DIGEST_STRING_LENGTH))); +char *SHA512_256FileChunk(const char *, char *, off_t, off_t) + __attribute__((__bounded__(__minbytes__,2,SHA512_256_DIGEST_STRING_LENGTH))); +char *SHA512_256Data(const u_int8_t *, size_t, char *) + __attribute__((__bounded__(__string__,1,2))) + __attribute__((__bounded__(__minbytes__,3,SHA512_256_DIGEST_STRING_LENGTH))); +__END_DECLS + +#endif /* _SHA2_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/signal.h b/lib/libc/include/generic-openbsd/signal.h new file mode 100644 index 0000000000..0ab0dbb2e9 --- /dev/null +++ b/lib/libc/include/generic-openbsd/signal.h @@ -0,0 +1,140 @@ +/* $OpenBSD: signal.h,v 1.26 2018/05/30 13:20:38 bluhm Exp $ */ +/* $NetBSD: signal.h,v 1.8 1996/02/29 00:04:57 jtc Exp $ */ + +/*- + * Copyright (c) 1991, 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. + * + * @(#)signal.h 8.3 (Berkeley) 3/30/94 + */ + +#ifndef _USER_SIGNAL_H +#define _USER_SIGNAL_H + +#include + +#if __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE +#include +#endif + +__BEGIN_DECLS +#if __BSD_VISIBLE +extern const char *const sys_signame[_NSIG]; +extern const char *const sys_siglist[_NSIG]; +#endif + +int raise(int); +#if __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE +#if __BSD_VISIBLE || (__XPG_VISIBLE >= 500 && __XPG_VISIBLE < 700) +void (*bsd_signal(int, void (*)(int)))(int); +#endif +int kill(pid_t, int); +int sigaction(int, const struct sigaction *__restrict, + struct sigaction *__restrict); +int sigaddset(sigset_t *, int); +int sigdelset(sigset_t *, int); +int sigemptyset(sigset_t *); +int sigfillset(sigset_t *); +int sigismember(const sigset_t *, int); +int sigpending(sigset_t *); +int sigprocmask(int, const sigset_t *__restrict, sigset_t *__restrict); +#if __POSIX_VISIBLE >= 199506 +int pthread_sigmask(int, const sigset_t *__restrict, sigset_t *__restrict); +#endif +int sigsuspend(const sigset_t *); + +#if !defined(_ANSI_LIBRARY) + +extern int *__errno(void); + +__only_inline int sigaddset(sigset_t *__set, int __signo) +{ + if (__signo <= 0 || __signo >= _NSIG) { + *__errno() = 22; /* EINVAL */ + return -1; + } + *__set |= (1U << ((__signo)-1)); /* sigmask(__signo) */ + return (0); +} + +__only_inline int sigdelset(sigset_t *__set, int __signo) +{ + if (__signo <= 0 || __signo >= _NSIG) { + *__errno() = 22; /* EINVAL */ + return -1; + } + *__set &= ~(1U << ((__signo)-1)); /* sigmask(__signo) */ + return (0); +} + +__only_inline int sigismember(const sigset_t *__set, int __signo) +{ + if (__signo <= 0 || __signo >= _NSIG) { + *__errno() = 22; /* EINVAL */ + return -1; + } + return ((*__set & (1U << ((__signo)-1))) != 0); +} + +__only_inline int sigemptyset(sigset_t *__set) +{ + *__set = 0; + return (0); +} + +__only_inline int sigfillset(sigset_t *__set) +{ + *__set = ~(sigset_t)0; + return (0); +} + +#endif /* !_ANSI_LIBRARY */ + +#if __BSD_VISIBLE || __XPG_VISIBLE >= 420 +int killpg(pid_t, int); +int siginterrupt(int, int); +int sigaltstack(const struct sigaltstack *__restrict, + struct sigaltstack *__restrict); +#if __BSD_VISIBLE +int sigblock(int); +/* This is the traditional BSD sigpause() and not the XPG/POSIX sigpause(). */ +int sigpause(int); +int sigsetmask(int); +int sigvec(int, struct sigvec *, struct sigvec *); +int thrkill(pid_t _tid, int _signum, void *_tcb); +#endif +#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */ +#if __BSD_VISIBLE || __POSIX_VISIBLE >= 199309 || __XPG_VISIBLE >= 500 +int sigwait(const sigset_t *__restrict, int *__restrict); +#endif +#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 +void psignal(unsigned int, const char *); +#endif +#endif /* __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE */ +__END_DECLS + +#endif /* !_USER_SIGNAL_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/siphash.h b/lib/libc/include/generic-openbsd/siphash.h new file mode 100644 index 0000000000..99102bd78a --- /dev/null +++ b/lib/libc/include/generic-openbsd/siphash.h @@ -0,0 +1,86 @@ +/*- + * Copyright (c) 2013 Andre Oppermann + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $OpenBSD: siphash.h,v 1.5 2025/04/14 08:28:24 claudio Exp $ + */ + +/* + * SipHash is a family of pseudorandom functions (a.k.a. keyed hash functions) + * optimized for speed on short messages returning a 64bit hash/digest value. + * + * The number of rounds is defined during the initialization: + * SipHash24_Init() for the fast and reasonable strong version + * SipHash48_Init() for the strong version (half as fast) + * + * struct SIPHASH_CTX ctx; + * SipHash24_Init(&ctx); + * SipHash_SetKey(&ctx, "16bytes long key"); + * SipHash_Update(&ctx, pointer_to_string, length_of_string); + * SipHash_Final(output, &ctx); + */ + +#ifndef _SIPHASH_H_ +#define _SIPHASH_H_ + +#include +#include + +#define SIPHASH_BLOCK_LENGTH 8 +#define SIPHASH_KEY_LENGTH 16 +#define SIPHASH_DIGEST_LENGTH 8 + +typedef struct _SIPHASH_CTX { + uint64_t v[4]; + uint8_t buf[SIPHASH_BLOCK_LENGTH]; + uint32_t bytes; +} SIPHASH_CTX; + +typedef struct { + uint64_t k0; + uint64_t k1; +} SIPHASH_KEY; + +void SipHash_Init(SIPHASH_CTX *, const SIPHASH_KEY *); +void SipHash_Update(SIPHASH_CTX *, int, int, const void *, size_t); +uint64_t SipHash_End(SIPHASH_CTX *, int, int); +void SipHash_Final(void *, SIPHASH_CTX *, int, int); +uint64_t SipHash(const SIPHASH_KEY *, int, int, const void *, size_t); + +#define SipHash24_Init(_c, _k) SipHash_Init((_c), (_k)) +#define SipHash24_Update(_c, _p, _l) SipHash_Update((_c), 2, 4, (_p), (_l)) +#define SipHash24_End(_d) SipHash_End((_d), 2, 4) +#define SipHash24_Final(_d, _c) SipHash_Final((_d), (_c), 2, 4) +#define SipHash24(_k, _p, _l) SipHash((_k), 2, 4, (_p), (_l)) + +#define SipHash48_Init(_c, _k) SipHash_Init((_c), (_k)) +#define SipHash48_Update(_c, _p, _l) SipHash_Update((_c), 4, 8, (_p), (_l)) +#define SipHash48_End(_d) SipHash_End((_d), 4, 8) +#define SipHash48_Final(_d, _c) SipHash_Final((_d), (_c), 4, 8) +#define SipHash48(_k, _p, _l) SipHash((_k), 4, 8, (_p), (_l)) + +#endif /* _SIPHASH_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sndio.h b/lib/libc/include/generic-openbsd/sndio.h new file mode 100644 index 0000000000..cb7576053b --- /dev/null +++ b/lib/libc/include/generic-openbsd/sndio.h @@ -0,0 +1,216 @@ +/* $OpenBSD: sndio.h,v 1.15 2024/05/24 15:10:26 ratchov Exp $ */ +/* + * Copyright (c) 2008 Alexandre Ratchov + * + * 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 SNDIO_H +#define SNDIO_H + +#include + +/* + * default audio device and MIDI port + */ +#define SIO_DEVANY "default" +#define MIO_PORTANY "default" + +/* + * limits + * + * For now SIOCTL_DISPLAYMAX is 12 byte only. It nicely fits in the + * padding of the sioctl_desc structure: this allows any binary linked + * to the library version with no sioctl_desc->display to work with + * this library version. Currently, any string reported by the lower + * layers fits in the 12-byte buffer. Once larger strings start + * being used (or the ABI changes for any other reason) increase + * SIOCTL_DISPLAYMAX and properly pad the sioctl_desc structure. + */ +#define SIOCTL_NAMEMAX 12 /* max name length */ +#define SIOCTL_DISPLAYMAX 12 /* max display string length */ + +/* + * private ``handle'' structure + */ +struct sio_hdl; +struct mio_hdl; +struct sioctl_hdl; + +/* + * parameters of a full-duplex stream + */ +struct sio_par { + unsigned int bits; /* bits per sample */ + unsigned int bps; /* bytes per sample */ + unsigned int sig; /* 1 = signed, 0 = unsigned */ + unsigned int le; /* 1 = LE, 0 = BE byte order */ + unsigned int msb; /* 1 = MSB, 0 = LSB aligned */ + unsigned int rchan; /* number channels for recording direction */ + unsigned int pchan; /* number channels for playback direction */ + unsigned int rate; /* frames per second */ + unsigned int bufsz; /* end-to-end buffer size */ +#define SIO_IGNORE 0 /* pause during xrun */ +#define SIO_SYNC 1 /* resync after xrun */ +#define SIO_ERROR 2 /* terminate on xrun */ + unsigned int xrun; /* what to do on overruns/underruns */ + unsigned int round; /* optimal bufsz divisor */ + unsigned int appbufsz; /* minimum buffer size */ + int __pad[3]; /* for future use */ + unsigned int __magic; /* for internal/debug purposes only */ +}; + +/* + * capabilities of a stream + */ +struct sio_cap { +#define SIO_NENC 8 +#define SIO_NCHAN 8 +#define SIO_NRATE 16 +#define SIO_NCONF 4 + struct sio_enc { /* allowed sample encodings */ + unsigned int bits; + unsigned int bps; + unsigned int sig; + unsigned int le; + unsigned int msb; + } enc[SIO_NENC]; + unsigned int rchan[SIO_NCHAN]; /* allowed values for rchan */ + unsigned int pchan[SIO_NCHAN]; /* allowed values for pchan */ + unsigned int rate[SIO_NRATE]; /* allowed rates */ + int __pad[7]; /* for future use */ + unsigned int nconf; /* number of elements in confs[] */ + struct sio_conf { + unsigned int enc; /* mask of enc[] indexes */ + unsigned int rchan; /* mask of chan[] indexes (rec) */ + unsigned int pchan; /* mask of chan[] indexes (play) */ + unsigned int rate; /* mask of rate[] indexes */ + } confs[SIO_NCONF]; +}; + +#define SIO_XSTRINGS { "ignore", "sync", "error" } + +/* + * controlled component of the device + */ +struct sioctl_node { + char name[SIOCTL_NAMEMAX]; /* ex. "spkr" */ + int unit; /* optional number or -1 */ +}; + +/* + * description of a control (index, value) pair + */ +struct sioctl_desc { + unsigned int addr; /* control address */ +#define SIOCTL_NONE 0 /* deleted */ +#define SIOCTL_NUM 2 /* integer in the 0..maxval range */ +#define SIOCTL_SW 3 /* on/off switch (0 or 1) */ +#define SIOCTL_VEC 4 /* number, element of vector */ +#define SIOCTL_LIST 5 /* switch, element of a list */ +#define SIOCTL_SEL 6 /* element of a selector */ + unsigned int type; /* one of above */ + char func[SIOCTL_NAMEMAX]; /* function name, ex. "level" */ + char group[SIOCTL_NAMEMAX]; /* group this control belongs to */ + struct sioctl_node node0; /* affected node */ + struct sioctl_node node1; /* dito for SIOCTL_{VEC,LIST,SEL} */ + unsigned int maxval; /* max value */ + char display[SIOCTL_DISPLAYMAX]; /* free-format hint */ +}; + +/* + * mode bitmap + */ +#define SIO_PLAY 1 +#define SIO_REC 2 +#define MIO_OUT 4 +#define MIO_IN 8 +#define SIOCTL_READ 0x100 +#define SIOCTL_WRITE 0x200 + +/* + * default bytes per sample for the given bits per sample + */ +#define SIO_BPS(bits) (((bits) <= 8) ? 1 : (((bits) <= 16) ? 2 : 4)) + +/* + * default value of "sio_par->le" flag + */ +#if BYTE_ORDER == LITTLE_ENDIAN +#define SIO_LE_NATIVE 1 +#else +#define SIO_LE_NATIVE 0 +#endif + +/* + * maximum value of volume, eg. for sio_setvol() + */ +#define SIO_MAXVOL 127 + +#ifdef __cplusplus +extern "C" { +#endif + +struct pollfd; + +void sio_initpar(struct sio_par *); +struct sio_hdl *sio_open(const char *, unsigned int, int); +void sio_close(struct sio_hdl *); +int sio_setpar(struct sio_hdl *, struct sio_par *); +int sio_getpar(struct sio_hdl *, struct sio_par *); +int sio_getcap(struct sio_hdl *, struct sio_cap *); +void sio_onmove(struct sio_hdl *, void (*)(void *, int), void *); +size_t sio_write(struct sio_hdl *, const void *, size_t); +size_t sio_read(struct sio_hdl *, void *, size_t); +int sio_start(struct sio_hdl *); +int sio_stop(struct sio_hdl *); +int sio_flush(struct sio_hdl *); +int sio_nfds(struct sio_hdl *); +int sio_pollfd(struct sio_hdl *, struct pollfd *, int); +int sio_revents(struct sio_hdl *, struct pollfd *); +int sio_eof(struct sio_hdl *); +int sio_setvol(struct sio_hdl *, unsigned int); +int sio_onvol(struct sio_hdl *, void (*)(void *, unsigned int), void *); + +struct mio_hdl *mio_open(const char *, unsigned int, int); +void mio_close(struct mio_hdl *); +size_t mio_write(struct mio_hdl *, const void *, size_t); +size_t mio_read(struct mio_hdl *, void *, size_t); +int mio_nfds(struct mio_hdl *); +int mio_pollfd(struct mio_hdl *, struct pollfd *, int); +int mio_revents(struct mio_hdl *, struct pollfd *); +int mio_eof(struct mio_hdl *); + +struct sioctl_hdl *sioctl_open(const char *, unsigned int, int); +void sioctl_close(struct sioctl_hdl *); +int sioctl_ondesc(struct sioctl_hdl *, + void (*)(void *, struct sioctl_desc *, int), void *); +int sioctl_onval(struct sioctl_hdl *, + void (*)(void *, unsigned int, unsigned int), void *); +int sioctl_setval(struct sioctl_hdl *, unsigned int, unsigned int); +int sioctl_nfds(struct sioctl_hdl *); +int sioctl_pollfd(struct sioctl_hdl *, struct pollfd *, int); +int sioctl_revents(struct sioctl_hdl *, struct pollfd *); +int sioctl_eof(struct sioctl_hdl *); + +int mio_rmidi_getfd(const char *, unsigned int, int); +struct mio_hdl *mio_rmidi_fdopen(int, unsigned int, int); +int sio_sun_getfd(const char *, unsigned int, int); +struct sio_hdl *sio_sun_fdopen(int, unsigned int, int); +int sioctl_sun_getfd(const char *, unsigned int, int); +struct sioctl_hdl *sioctl_sun_fdopen(int, unsigned int, int); + +#ifdef __cplusplus +} +#endif + +#endif /* !defined(SNDIO_H) */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/soundcard.h b/lib/libc/include/generic-openbsd/soundcard.h new file mode 100644 index 0000000000..265990c9ce --- /dev/null +++ b/lib/libc/include/generic-openbsd/soundcard.h @@ -0,0 +1,317 @@ +/* $OpenBSD: soundcard.h,v 1.15 2015/01/22 00:07:15 deraadt Exp $ */ +/* $NetBSD: soundcard.h,v 1.11 2001/05/09 21:49:58 augustss Exp $ */ + +/*- + * Copyright (c) 1997 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Lennart Augustsson. + * + * 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. + */ + +/* + * WARNING! WARNING! + * This is an OSS (Linux) audio emulator. + * Use the sndio(7) API for developing new code, and this + * only for compiling Linux programs. + */ + +#ifndef _SOUNDCARD_H_ +#define _SOUNDCARD_H_ + +#ifndef _SYS_IOCTL_H_ +#include +#endif /* !_SYS_IOCTL_H_ */ + +#define SOUND_VERSION 0x030001 + +#define SNDCTL_DSP_RESET _IO ('P', 0) +#define SNDCTL_DSP_SYNC _IO ('P', 1) +#define SNDCTL_DSP_SPEED _IOWR('P', 2, int) +#define SOUND_PCM_READ_RATE _IOR ('P', 2, int) +#define SNDCTL_DSP_STEREO _IOWR('P', 3, int) +#define SNDCTL_DSP_GETBLKSIZE _IOWR('P', 4, int) +#define SNDCTL_DSP_SETFMT _IOWR('P', 5, int) +#define AFMT_QUERY 0x00000000 +#define AFMT_MU_LAW 0x00000001 +#define AFMT_A_LAW 0x00000002 +#define AFMT_IMA_ADPCM 0x00000004 +#define AFMT_U8 0x00000008 +#define AFMT_S16_LE 0x00000010 +#define AFMT_S16_BE 0x00000020 +#define AFMT_S8 0x00000040 +#define AFMT_U16_LE 0x00000080 +#define AFMT_U16_BE 0x00000100 +#define AFMT_MPEG 0x00000200 +#define SNDCTL_DSP_SAMPLESIZE SNDCTL_DSP_SETFMT +#define SOUND_PCM_READ_BITS _IOR ('P', 5, int) +#define SNDCTL_DSP_CHANNELS _IOWR('P', 6, int) +#define SOUND_PCM_WRITE_CHANNELS SNDCTL_DSP_CHANNELS +#define SOUND_PCM_READ_CHANNELS _IOR ('P', 6, int) +#define SOUND_PCM_WRITE_FILTER _IOWR('P', 7, int) +#define SOUND_PCM_READ_FILTER _IOR ('P', 7, int) +#define SNDCTL_DSP_POST _IO ('P', 8) +#define SNDCTL_DSP_SUBDIVIDE _IOWR('P', 9, int) +#define SNDCTL_DSP_SETFRAGMENT _IOWR('P', 10, int) +#define SNDCTL_DSP_GETFMTS _IOR ('P', 11, int) +#define SNDCTL_DSP_GETOSPACE _IOR ('P',12, struct audio_buf_info) +#define SNDCTL_DSP_GETISPACE _IOR ('P',13, struct audio_buf_info) +#define SNDCTL_DSP_NONBLOCK _IO ('P',14) +#define SNDCTL_DSP_GETCAPS _IOR ('P',15, int) +# define DSP_CAP_REVISION 0x000000ff +# define DSP_CAP_DUPLEX 0x00000100 +# define DSP_CAP_REALTIME 0x00000200 +# define DSP_CAP_BATCH 0x00000400 +# define DSP_CAP_COPROC 0x00000800 +# define DSP_CAP_TRIGGER 0x00001000 +# define DSP_CAP_MMAP 0x00002000 +#define SNDCTL_DSP_GETTRIGGER _IOR ('P', 16, int) +#define SNDCTL_DSP_SETTRIGGER _IOW ('P', 16, int) +# define PCM_ENABLE_INPUT 0x00000001 +# define PCM_ENABLE_OUTPUT 0x00000002 +#define SNDCTL_DSP_GETIPTR _IOR ('P', 17, struct count_info) +#define SNDCTL_DSP_GETOPTR _IOR ('P', 18, struct count_info) +#define SNDCTL_DSP_MAPINBUF _IOR ('P', 19, struct buffmem_desc) +#define SNDCTL_DSP_MAPOUTBUF _IOR ('P', 20, struct buffmem_desc) +#define SNDCTL_DSP_SETSYNCRO _IO ('P', 21) +#define SNDCTL_DSP_SETDUPLEX _IO ('P', 22) +#define SNDCTL_DSP_PROFILE _IOW ('P', 23, int) +#define SNDCTL_DSP_GETODELAY _IOR ('P', 24, int) +#define APF_NORMAL 0 +#define APF_NETWORK 1 +#define APF_CPUINTENS 2 + +/* Need native 16 bit format which depends on byte order */ +/* XXX This isn't really a good way, but I don't want to + * include all of endian.h because it contains a lot + * junk symbols. [augustss] + */ +#if __BSD_VISIBLE +#undef __BSD_VISIBLE +#define __BSD_VISIBLE 0 /* avoid dragging in a lot of junk */ +#include +#undef __BSD_VISIBLE +#define __BSD_VISIBLE 1 +#else +#include +#endif +#if _QUAD_LOWWORD == 0 +#define AFMT_S16_NE AFMT_S16_LE +#else +#define AFMT_S16_NE AFMT_S16_BE +#endif + + +/* Aliases */ +#define SOUND_PCM_WRITE_BITS SNDCTL_DSP_SETFMT +#define SOUND_PCM_WRITE_RATE SNDCTL_DSP_SPEED +#define SOUND_PCM_POST SNDCTL_DSP_POST +#define SOUND_PCM_RESET SNDCTL_DSP_RESET +#define SOUND_PCM_SYNC SNDCTL_DSP_SYNC +#define SOUND_PCM_SUBDIVIDE SNDCTL_DSP_SUBDIVIDE +#define SOUND_PCM_SETFRAGMENT SNDCTL_DSP_SETFRAGMENT +#define SOUND_PCM_GETFMTS SNDCTL_DSP_GETFMTS +#define SOUND_PCM_SETFMT SNDCTL_DSP_SETFMT +#define SOUND_PCM_GETOSPACE SNDCTL_DSP_GETOSPACE +#define SOUND_PCM_GETISPACE SNDCTL_DSP_GETISPACE +#define SOUND_PCM_NONBLOCK SNDCTL_DSP_NONBLOCK +#define SOUND_PCM_GETCAPS SNDCTL_DSP_GETCAPS +#define SOUND_PCM_GETTRIGGER SNDCTL_DSP_GETTRIGGER +#define SOUND_PCM_SETTRIGGER SNDCTL_DSP_SETTRIGGER +#define SOUND_PCM_SETSYNCRO SNDCTL_DSP_SETSYNCRO +#define SOUND_PCM_GETIPTR SNDCTL_DSP_GETIPTR +#define SOUND_PCM_GETOPTR SNDCTL_DSP_GETOPTR +#define SOUND_PCM_MAPINBUF SNDCTL_DSP_MAPINBUF +#define SOUND_PCM_MAPOUTBUF SNDCTL_DSP_MAPOUTBUF + +/* Mixer defines */ +#define SOUND_MIXER_FIRST 0 +#define SOUND_MIXER_NRDEVICES 25 + +#define SOUND_MIXER_VOLUME 0 +#define SOUND_MIXER_BASS 1 +#define SOUND_MIXER_TREBLE 2 +#define SOUND_MIXER_SYNTH 3 +#define SOUND_MIXER_PCM 4 +#define SOUND_MIXER_SPEAKER 5 +#define SOUND_MIXER_LINE 6 +#define SOUND_MIXER_MIC 7 +#define SOUND_MIXER_CD 8 +#define SOUND_MIXER_IMIX 9 +#define SOUND_MIXER_ALTPCM 10 +#define SOUND_MIXER_RECLEV 11 +#define SOUND_MIXER_IGAIN 12 +#define SOUND_MIXER_OGAIN 13 +#define SOUND_MIXER_LINE1 14 +#define SOUND_MIXER_LINE2 15 +#define SOUND_MIXER_LINE3 16 +#define SOUND_MIXER_DIGITAL1 17 +#define SOUND_MIXER_DIGITAL2 18 +#define SOUND_MIXER_DIGITAL3 19 +#define SOUND_MIXER_PHONEIN 20 +#define SOUND_MIXER_PHONEOUT 21 +#define SOUND_MIXER_VIDEO 22 +#define SOUND_MIXER_RADIO 23 +#define SOUND_MIXER_MONITOR 24 + +#define SOUND_ONOFF_MIN 28 +#define SOUND_ONOFF_MAX 30 + +#define SOUND_MIXER_NONE 31 + +#define SOUND_DEVICE_LABELS {"Vol ", "Bass ", "Trebl", "Synth", "Pcm ", "Spkr ", "Line ", \ + "Mic ", "CD ", "Mix ", "Pcm2 ", "Rec ", "IGain", "OGain", \ + "Line1", "Line2", "Line3", "Digital1", "Digital2", "Digital3", \ + "PhoneIn", "PhoneOut", "Video", "Radio", "Monitor"} + +#define SOUND_DEVICE_NAMES {"vol", "bass", "treble", "synth", "pcm", "speaker", "line", \ + "mic", "cd", "mix", "pcm2", "rec", "igain", "ogain", \ + "line1", "line2", "line3", "dig1", "dig2", "dig3", \ + "phin", "phout", "video", "radio", "monitor"} + +#define SOUND_MIXER_RECSRC 0xff +#define SOUND_MIXER_DEVMASK 0xfe +#define SOUND_MIXER_RECMASK 0xfd +#define SOUND_MIXER_CAPS 0xfc +#define SOUND_CAP_EXCL_INPUT 1 +#define SOUND_MIXER_STEREODEVS 0xfb + +#define MIXER_READ(dev) _IOR('M', dev, int) + +#define SOUND_MIXER_READ_RECSRC MIXER_READ(SOUND_MIXER_RECSRC) +#define SOUND_MIXER_READ_DEVMASK MIXER_READ(SOUND_MIXER_DEVMASK) +#define SOUND_MIXER_READ_RECMASK MIXER_READ(SOUND_MIXER_RECMASK) +#define SOUND_MIXER_READ_STEREODEVS MIXER_READ(SOUND_MIXER_STEREODEVS) +#define SOUND_MIXER_READ_CAPS MIXER_READ(SOUND_MIXER_CAPS) + +#define SOUND_MIXER_READ_VOLUME MIXER_READ(SOUND_MIXER_VOLUME) +#define SOUND_MIXER_READ_BASS MIXER_READ(SOUND_MIXER_BASS) +#define SOUND_MIXER_READ_TREBLE MIXER_READ(SOUND_MIXER_TREBLE) +#define SOUND_MIXER_READ_SYNTH MIXER_READ(SOUND_MIXER_SYNTH) +#define SOUND_MIXER_READ_PCM MIXER_READ(SOUND_MIXER_PCM) +#define SOUND_MIXER_READ_SPEAKER MIXER_READ(SOUND_MIXER_SPEAKER) +#define SOUND_MIXER_READ_LINE MIXER_READ(SOUND_MIXER_LINE) +#define SOUND_MIXER_READ_MIC MIXER_READ(SOUND_MIXER_MIC) +#define SOUND_MIXER_READ_CD MIXER_READ(SOUND_MIXER_CD) +#define SOUND_MIXER_READ_IMIX MIXER_READ(SOUND_MIXER_IMIX) +#define SOUND_MIXER_READ_ALTPCM MIXER_READ(SOUND_MIXER_ALTPCM) +#define SOUND_MIXER_READ_RECLEV MIXER_READ(SOUND_MIXER_RECLEV) +#define SOUND_MIXER_READ_IGAIN MIXER_READ(SOUND_MIXER_IGAIN) +#define SOUND_MIXER_READ_OGAIN MIXER_READ(SOUND_MIXER_OGAIN) +#define SOUND_MIXER_READ_LINE1 MIXER_READ(SOUND_MIXER_LINE1) +#define SOUND_MIXER_READ_LINE2 MIXER_READ(SOUND_MIXER_LINE2) +#define SOUND_MIXER_READ_LINE3 MIXER_READ(SOUND_MIXER_LINE3) + +#define MIXER_WRITE(dev) _IOW ('M', dev, int) +#define MIXER_WRITE_R(dev) _IOWR('M', dev, int) + +#define SOUND_MIXER_WRITE_RECSRC MIXER_WRITE(SOUND_MIXER_RECSRC) +#define SOUND_MIXER_WRITE_R_RECSRC MIXER_WRITE_R(SOUND_MIXER_RECSRC) + +#define SOUND_MIXER_WRITE_VOLUME MIXER_WRITE(SOUND_MIXER_VOLUME) +#define SOUND_MIXER_WRITE_BASS MIXER_WRITE(SOUND_MIXER_BASS) +#define SOUND_MIXER_WRITE_TREBLE MIXER_WRITE(SOUND_MIXER_TREBLE) +#define SOUND_MIXER_WRITE_SYNTH MIXER_WRITE(SOUND_MIXER_SYNTH) +#define SOUND_MIXER_WRITE_PCM MIXER_WRITE(SOUND_MIXER_PCM) +#define SOUND_MIXER_WRITE_SPEAKER MIXER_WRITE(SOUND_MIXER_SPEAKER) +#define SOUND_MIXER_WRITE_LINE MIXER_WRITE(SOUND_MIXER_LINE) +#define SOUND_MIXER_WRITE_MIC MIXER_WRITE(SOUND_MIXER_MIC) +#define SOUND_MIXER_WRITE_CD MIXER_WRITE(SOUND_MIXER_CD) +#define SOUND_MIXER_WRITE_IMIX MIXER_WRITE(SOUND_MIXER_IMIX) +#define SOUND_MIXER_WRITE_ALTPCM MIXER_WRITE(SOUND_MIXER_ALTPCM) +#define SOUND_MIXER_WRITE_RECLEV MIXER_WRITE(SOUND_MIXER_RECLEV) +#define SOUND_MIXER_WRITE_IGAIN MIXER_WRITE(SOUND_MIXER_IGAIN) +#define SOUND_MIXER_WRITE_OGAIN MIXER_WRITE(SOUND_MIXER_OGAIN) +#define SOUND_MIXER_WRITE_LINE1 MIXER_WRITE(SOUND_MIXER_LINE1) +#define SOUND_MIXER_WRITE_LINE2 MIXER_WRITE(SOUND_MIXER_LINE2) +#define SOUND_MIXER_WRITE_LINE3 MIXER_WRITE(SOUND_MIXER_LINE3) + +#define SOUND_MASK_VOLUME (1 << SOUND_MIXER_VOLUME) +#define SOUND_MASK_BASS (1 << SOUND_MIXER_BASS) +#define SOUND_MASK_TREBLE (1 << SOUND_MIXER_TREBLE) +#define SOUND_MASK_SYNTH (1 << SOUND_MIXER_SYNTH) +#define SOUND_MASK_PCM (1 << SOUND_MIXER_PCM) +#define SOUND_MASK_SPEAKER (1 << SOUND_MIXER_SPEAKER) +#define SOUND_MASK_LINE (1 << SOUND_MIXER_LINE) +#define SOUND_MASK_MIC (1 << SOUND_MIXER_MIC) +#define SOUND_MASK_CD (1 << SOUND_MIXER_CD) +#define SOUND_MASK_IMIX (1 << SOUND_MIXER_IMIX) +#define SOUND_MASK_ALTPCM (1 << SOUND_MIXER_ALTPCM) +#define SOUND_MASK_RECLEV (1 << SOUND_MIXER_RECLEV) +#define SOUND_MASK_IGAIN (1 << SOUND_MIXER_IGAIN) +#define SOUND_MASK_OGAIN (1 << SOUND_MIXER_OGAIN) +#define SOUND_MASK_LINE1 (1 << SOUND_MIXER_LINE1) +#define SOUND_MASK_LINE2 (1 << SOUND_MIXER_LINE2) +#define SOUND_MASK_LINE3 (1 << SOUND_MIXER_LINE3) +#define SOUND_MASK_DIGITAL1 (1 << SOUND_MIXER_DIGITAL1) +#define SOUND_MASK_DIGITAL2 (1 << SOUND_MIXER_DIGITAL2) +#define SOUND_MASK_DIGITAL3 (1 << SOUND_MIXER_DIGITAL3) +#define SOUND_MASK_PHONEIN (1 << SOUND_MIXER_PHONEIN) +#define SOUND_MASK_PHONEOUT (1 << SOUND_MIXER_PHONEOUT) +#define SOUND_MASK_VIDEO (1 << SOUND_MIXER_VIDEO) +#define SOUND_MASK_RADIO (1 << SOUND_MIXER_RADIO) +#define SOUND_MASK_MONITOR (1 << SOUND_MIXER_MONITOR) + +typedef struct mixer_info { + char id[16]; + char name[32]; + int modify_counter; + int fillers[10]; +} mixer_info; + +typedef struct _old_mixer_info { + char id[16]; + char name[32]; +} _old_mixer_info; + +#define SOUND_MIXER_INFO _IOR ('M', 101, mixer_info) +#define SOUND_OLD_MIXER_INFO _IOR ('M', 101, _old_mixer_info) + +#define OSS_GETVERSION _IOR ('M', 118, int) + +typedef struct audio_buf_info { + int fragments; + int fragstotal; + int fragsize; + int bytes; +} audio_buf_info; + +typedef struct count_info { + int bytes; + int blocks; + int ptr; +} count_info; + +typedef struct buffmem_desc { + unsigned int *buffer; + int size; +} buffmem_desc; + +#define ioctl _oss_ioctl + +__BEGIN_DECLS +int _oss_ioctl(int, unsigned long com, ...); +__END_DECLS + +#endif /* !_SOUNDCARD_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/spawn.h b/lib/libc/include/generic-openbsd/spawn.h new file mode 100644 index 0000000000..79f2dd47b7 --- /dev/null +++ b/lib/libc/include/generic-openbsd/spawn.h @@ -0,0 +1,103 @@ +/* $OpenBSD: spawn.h,v 1.3 2015/05/20 22:50:07 millert Exp $ */ +/*- + * Copyright (c) 2008 Ed Schouten + * 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 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 AUTHOR 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. + * + * $FreeBSD: src/include/spawn.h,v 1.3.2.1.6.1 2010/12/21 17:09:25 kensmith Exp $ + */ + +#ifndef _SPAWN_H_ +#define _SPAWN_H_ + +#include +#include + +struct sched_param; + +typedef struct __posix_spawnattr *posix_spawnattr_t; +typedef struct __posix_spawn_file_actions *posix_spawn_file_actions_t; + +#define POSIX_SPAWN_RESETIDS 0x01 +#define POSIX_SPAWN_SETPGROUP 0x02 +#define POSIX_SPAWN_SETSCHEDPARAM 0x04 +#define POSIX_SPAWN_SETSCHEDULER 0x08 +#define POSIX_SPAWN_SETSIGDEF 0x10 +#define POSIX_SPAWN_SETSIGMASK 0x20 + +__BEGIN_DECLS +/* + * Spawn routines + * + * XXX both arrays should be __restrict, but this does not work when GCC + * is invoked with -std=c99. + */ +int posix_spawn(pid_t *__restrict, const char *__restrict, + const posix_spawn_file_actions_t *, const posix_spawnattr_t *__restrict, + char *const [], char *const []); +int posix_spawnp(pid_t *__restrict, const char *__restrict, + const posix_spawn_file_actions_t *, const posix_spawnattr_t *__restrict, + char *const [], char *const []); + +/* + * File descriptor actions + */ +int posix_spawn_file_actions_init(posix_spawn_file_actions_t *); +int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *); + +int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *__restrict, + int, const char *__restrict, int, mode_t); +int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *, int, int); +int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *, int); + +/* + * Spawn attributes + */ +int posix_spawnattr_init(posix_spawnattr_t *); +int posix_spawnattr_destroy(posix_spawnattr_t *); + +int posix_spawnattr_getflags(const posix_spawnattr_t *__restrict, + short *__restrict); +int posix_spawnattr_getpgroup(const posix_spawnattr_t *__restrict, + pid_t *__restrict); +int posix_spawnattr_getschedparam(const posix_spawnattr_t *__restrict, + struct sched_param *__restrict); +int posix_spawnattr_getschedpolicy(const posix_spawnattr_t *__restrict, + int *__restrict); +int posix_spawnattr_getsigdefault(const posix_spawnattr_t *__restrict, + sigset_t *__restrict); +int posix_spawnattr_getsigmask(const posix_spawnattr_t *__restrict, + sigset_t *__restrict); + +int posix_spawnattr_setflags(posix_spawnattr_t *, short); +int posix_spawnattr_setpgroup(posix_spawnattr_t *, pid_t); +int posix_spawnattr_setschedparam(posix_spawnattr_t *__restrict, + const struct sched_param *__restrict); +int posix_spawnattr_setschedpolicy(posix_spawnattr_t *, int); +int posix_spawnattr_setsigdefault(posix_spawnattr_t *__restrict, + const sigset_t *__restrict); +int posix_spawnattr_setsigmask(posix_spawnattr_t *__restrict, + const sigset_t *__restrict); +__END_DECLS + +#endif /* !_SPAWN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/stdarg.h b/lib/libc/include/generic-openbsd/stdarg.h new file mode 100644 index 0000000000..0fbd75bb6e --- /dev/null +++ b/lib/libc/include/generic-openbsd/stdarg.h @@ -0,0 +1,45 @@ +/* $OpenBSD: stdarg.h,v 1.10 2020/07/21 23:09:00 daniel Exp $ */ +/* + * Copyright (c) 2003, 2004 Marc espie + * + * 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 _STDARG_H_ +#define _STDARG_H_ + +#include + +/* Define __gnuc_va_list. */ + +#ifndef __GNUC_VA_LIST +#define __GNUC_VA_LIST +typedef __builtin_va_list __gnuc_va_list; +#endif + +/* Note that the type used in va_arg is supposed to match the + actual type **after default promotions**. + Thus, va_arg (..., short) is not valid. */ + +#define va_start(ap, last) __builtin_va_start((ap), last) +#define va_end(ap) __builtin_va_end((ap)) +#define va_arg(ap, type) __builtin_va_arg((ap), type) +#define __va_copy(dst, src) __builtin_va_copy((dst),(src)) + +typedef __gnuc_va_list va_list; + +#if __ISO_C_VISIBLE >= 1999 +#define va_copy(dst, src) __va_copy((dst), (src)) +#endif + +#endif /* not _STDARG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/stdbool.h b/lib/libc/include/generic-openbsd/stdbool.h new file mode 100644 index 0000000000..f59fd12425 --- /dev/null +++ b/lib/libc/include/generic-openbsd/stdbool.h @@ -0,0 +1,45 @@ +/* $OpenBSD: stdbool.h,v 1.7 2015/09/04 23:47:09 daniel Exp $ */ + +/* + * Written by Marc Espie, September 25, 1999 + * Public domain. + */ + +#ifndef _STDBOOL_H_ +#define _STDBOOL_H_ + +#ifndef __cplusplus + +#if defined(__GNUC__) || \ + (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901) +/* Support for C99: type _Bool is already built-in. */ +#define false 0 +#define true 1 + +#else +/* `_Bool' type must promote to `int' or `unsigned int'. */ +typedef enum { + false = 0, + true = 1 +} _Bool; + +/* And those constants must also be available as macros. */ +#define false false +#define true true + +#endif + +/* User visible type `bool' is provided as a macro which may be redefined */ +#define bool _Bool + +#else /* __cplusplus */ +#define _Bool bool +#define bool bool +#define false false +#define true true +#endif /* __cplusplus */ + +/* Inform that everything is fine */ +#define __bool_true_false_are_defined 1 + +#endif /* _STDBOOL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/stddef.h b/lib/libc/include/generic-openbsd/stddef.h new file mode 100644 index 0000000000..4d7038050d --- /dev/null +++ b/lib/libc/include/generic-openbsd/stddef.h @@ -0,0 +1,84 @@ +/* $OpenBSD: stddef.h,v 1.14 2017/01/06 14:36:50 kettenis Exp $ */ +/* $NetBSD: stddef.h,v 1.4 1994/10/26 00:56:26 cgd Exp $ */ + +/*- + * Copyright (c) 1990 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. + * + * @(#)stddef.h 5.5 (Berkeley) 4/3/91 + */ + +#ifndef _STDDEF_H_ +#define _STDDEF_H_ + +#include +#include +#include + +#ifndef _PTRDIFF_T_DEFINED_ +#define _PTRDIFF_T_DEFINED_ +typedef __ptrdiff_t ptrdiff_t; +#endif + +#ifndef _SIZE_T_DEFINED_ +#define _SIZE_T_DEFINED_ +typedef __size_t size_t; +#endif + +/* in C++, wchar_t is a built-in type */ +#if !defined(_WCHAR_T_DEFINED_) && !defined(__cplusplus) +#define _WCHAR_T_DEFINED_ +typedef __wchar_t wchar_t; +#endif + +#ifndef _WINT_T_DEFINED_ +#define _WINT_T_DEFINED_ +typedef __wint_t wint_t; +#endif + +#ifndef _MBSTATE_T_DEFINED_ +#define _MBSTATE_T_DEFINED_ +typedef __mbstate_t mbstate_t; +#endif + +#if __GNUC_PREREQ__(4, 0) +#define offsetof(type, member) __builtin_offsetof(type, member) +#else +#define offsetof(type, member) ((size_t)(&((type *)0)->member)) +#endif + +#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103 +#ifndef __CLANG_MAX_ALIGN_T_DEFINED +#define __CLANG_MAX_ALIGN_T_DEFINED +typedef struct { + long long __max_align_ll __aligned(__alignof__(long long)); + long double __max_align_ld __aligned(__alignof__(long double)); +} max_align_t; +#endif +#endif + +#endif /* _STDDEF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/stdint.h b/lib/libc/include/generic-openbsd/stdint.h new file mode 100644 index 0000000000..c0372ec51c --- /dev/null +++ b/lib/libc/include/generic-openbsd/stdint.h @@ -0,0 +1,231 @@ +/* $OpenBSD: stdint.h,v 1.11 2019/01/25 00:19:26 millert Exp $ */ + +/* + * Copyright (c) 1997, 2005 Todd C. Miller + * + * 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 _SYS_STDINT_H_ +#define _SYS_STDINT_H_ + +#include +#include + +#ifndef __BIT_TYPES_DEFINED__ +#define __BIT_TYPES_DEFINED__ +#endif + +/* 7.18.1.1 Exact-width integer types (also in sys/types.h) */ +#ifndef _INT8_T_DEFINED_ +#define _INT8_T_DEFINED_ +typedef __int8_t int8_t; +#endif + +#ifndef _UINT8_T_DEFINED_ +#define _UINT8_T_DEFINED_ +typedef __uint8_t uint8_t; +#endif + +#ifndef _INT16_T_DEFINED_ +#define _INT16_T_DEFINED_ +typedef __int16_t int16_t; +#endif + +#ifndef _UINT16_T_DEFINED_ +#define _UINT16_T_DEFINED_ +typedef __uint16_t uint16_t; +#endif + +#ifndef _INT32_T_DEFINED_ +#define _INT32_T_DEFINED_ +typedef __int32_t int32_t; +#endif + +#ifndef _UINT32_T_DEFINED_ +#define _UINT32_T_DEFINED_ +typedef __uint32_t uint32_t; +#endif + +#ifndef _INT64_T_DEFINED_ +#define _INT64_T_DEFINED_ +typedef __int64_t int64_t; +#endif + +#ifndef _UINT64_T_DEFINED_ +#define _UINT64_T_DEFINED_ +typedef __uint64_t uint64_t; +#endif + +/* 7.18.1.2 Minimum-width integer types */ +typedef __int_least8_t int_least8_t; +typedef __uint_least8_t uint_least8_t; +typedef __int_least16_t int_least16_t; +typedef __uint_least16_t uint_least16_t; +typedef __int_least32_t int_least32_t; +typedef __uint_least32_t uint_least32_t; +typedef __int_least64_t int_least64_t; +typedef __uint_least64_t uint_least64_t; + +/* 7.18.1.3 Fastest minimum-width integer types */ +typedef __int_fast8_t int_fast8_t; +typedef __uint_fast8_t uint_fast8_t; +typedef __int_fast16_t int_fast16_t; +typedef __uint_fast16_t uint_fast16_t; +typedef __int_fast32_t int_fast32_t; +typedef __uint_fast32_t uint_fast32_t; +typedef __int_fast64_t int_fast64_t; +typedef __uint_fast64_t uint_fast64_t; + +/* 7.18.1.4 Integer types capable of holding object pointers */ +#ifndef _INTPTR_T_DEFINED_ +#define _INTPTR_T_DEFINED_ +typedef __intptr_t intptr_t; +#endif + +typedef __uintptr_t uintptr_t; + +/* 7.18.1.5 Greatest-width integer types */ +typedef __intmax_t intmax_t; +typedef __uintmax_t uintmax_t; + +/* + * 7.18.2 Limits of specified-width integer types. + * + * The following object-like macros specify the minimum and maximum limits + * of integer types corresponding to the typedef names defined above. + */ + +/* 7.18.2.1 Limits of exact-width integer types */ +#define INT8_MIN (-0x7f - 1) +#define INT16_MIN (-0x7fff - 1) +#define INT32_MIN (-0x7fffffff - 1) +#define INT64_MIN (-0x7fffffffffffffffLL - 1) + +#define INT8_MAX 0x7f +#define INT16_MAX 0x7fff +#define INT32_MAX 0x7fffffff +#define INT64_MAX 0x7fffffffffffffffLL + +#define UINT8_MAX 0xff +#define UINT16_MAX 0xffff +#define UINT32_MAX 0xffffffffU +#define UINT64_MAX 0xffffffffffffffffULL + +/* 7.18.2.2 Limits of minimum-width integer types */ +#define INT_LEAST8_MIN INT8_MIN +#define INT_LEAST16_MIN INT16_MIN +#define INT_LEAST32_MIN INT32_MIN +#define INT_LEAST64_MIN INT64_MIN + +#define INT_LEAST8_MAX INT8_MAX +#define INT_LEAST16_MAX INT16_MAX +#define INT_LEAST32_MAX INT32_MAX +#define INT_LEAST64_MAX INT64_MAX + +#define UINT_LEAST8_MAX UINT8_MAX +#define UINT_LEAST16_MAX UINT16_MAX +#define UINT_LEAST32_MAX UINT32_MAX +#define UINT_LEAST64_MAX UINT64_MAX + +/* 7.18.2.3 Limits of fastest minimum-width integer types */ +#define INT_FAST8_MIN __INT_FAST8_MIN +#define INT_FAST16_MIN __INT_FAST16_MIN +#define INT_FAST32_MIN __INT_FAST32_MIN +#define INT_FAST64_MIN __INT_FAST64_MIN + +#define INT_FAST8_MAX __INT_FAST8_MAX +#define INT_FAST16_MAX __INT_FAST16_MAX +#define INT_FAST32_MAX __INT_FAST32_MAX +#define INT_FAST64_MAX __INT_FAST64_MAX + +#define UINT_FAST8_MAX __UINT_FAST8_MAX +#define UINT_FAST16_MAX __UINT_FAST16_MAX +#define UINT_FAST32_MAX __UINT_FAST32_MAX +#define UINT_FAST64_MAX __UINT_FAST64_MAX + +/* 7.18.2.4 Limits of integer types capable of holding object pointers */ +#ifdef __LP64__ +#define INTPTR_MIN (-0x7fffffffffffffffL - 1) +#define INTPTR_MAX 0x7fffffffffffffffL +#define UINTPTR_MAX 0xffffffffffffffffUL +#else +#define INTPTR_MIN (-0x7fffffffL - 1) +#define INTPTR_MAX 0x7fffffffL +#define UINTPTR_MAX 0xffffffffUL +#endif + +/* 7.18.2.5 Limits of greatest-width integer types */ +#define INTMAX_MIN INT64_MIN +#define INTMAX_MAX INT64_MAX +#define UINTMAX_MAX UINT64_MAX + +/* + * 7.18.3 Limits of other integer types. + * + * The following object-like macros specify the minimum and maximum limits + * of integer types corresponding to types specified in other standard + * header files. + */ + +/* Limits of ptrdiff_t */ +#define PTRDIFF_MIN INTPTR_MIN +#define PTRDIFF_MAX INTPTR_MAX + +/* Limits of sig_atomic_t */ +#define SIG_ATOMIC_MIN INT32_MIN +#define SIG_ATOMIC_MAX INT32_MAX + +/* Limit of size_t */ +#ifndef SIZE_MAX +#define SIZE_MAX UINTPTR_MAX +#endif + +/* Limits of wchar_t */ +#ifndef WCHAR_MIN +#define WCHAR_MIN INT32_MIN +#endif +#ifndef WCHAR_MAX +#define WCHAR_MAX INT32_MAX +#endif + +/* Limits of wint_t */ +#define WINT_MIN INT32_MIN +#define WINT_MAX INT32_MAX + +/* + * 7.18.4 Macros for integer constants. + * + * The following function-like macros expand to integer constants + * suitable for initializing objects that have integer types corresponding + * to types defined in . The argument in any instance of + * these macros shall be a decimal, octal, or hexadecimal constant with + * a value that does not exceed the limits for the corresponding type. + */ + +/* 7.18.4.1 Macros for minimum-width integer constants. */ +#define INT8_C(_c) (_c) +#define INT16_C(_c) (_c) +#define INT32_C(_c) (_c) +#define INT64_C(_c) __CONCAT(_c, LL) + +#define UINT8_C(_c) (_c) +#define UINT16_C(_c) (_c) +#define UINT32_C(_c) __CONCAT(_c, U) +#define UINT64_C(_c) __CONCAT(_c, ULL) + +/* 7.18.4.2 Macros for greatest-width integer constants. */ +#define INTMAX_C(_c) __CONCAT(_c, LL) +#define UINTMAX_C(_c) __CONCAT(_c, ULL) + +#endif /* _SYS_STDINT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/stdio.h b/lib/libc/include/generic-openbsd/stdio.h new file mode 100644 index 0000000000..d4840555b2 --- /dev/null +++ b/lib/libc/include/generic-openbsd/stdio.h @@ -0,0 +1,308 @@ +/* $OpenBSD: stdio.h,v 1.57 2025/07/16 15:33:05 yasuoka Exp $ */ +/* $NetBSD: stdio.h,v 1.18 1996/04/25 18:29:21 jtc Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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. + * + * @(#)stdio.h 5.17 (Berkeley) 6/3/91 + */ + +#ifndef _STDIO_H_ +#define _STDIO_H_ + +#include +#include +#include + +#if __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE +#include /* XXX should be removed */ +#endif + +#ifndef _SIZE_T_DEFINED_ +#define _SIZE_T_DEFINED_ +typedef __size_t size_t; +#endif + +#ifndef _OFF_T_DEFINED_ +#define _OFF_T_DEFINED_ +typedef __off_t off_t; +#endif + +#define _FSTDIO /* Define for new stdio with functions. */ + +typedef off_t fpos_t; /* stdio file position type */ + +#ifndef _STDFILES_DECLARED +#define _STDFILES_DECLARED +typedef struct __sFILE FILE; +struct __sFstub { long _stub; }; + +__BEGIN_DECLS +extern struct __sFstub __stdin[]; +extern struct __sFstub __stdout[]; +extern struct __sFstub __stderr[]; +__END_DECLS +#endif + +#define stdin ((struct __sFILE *)__stdin) +#define stdout ((struct __sFILE *)__stdout) +#define stderr ((struct __sFILE *)__stderr) + +/* + * The following three definitions are for ANSI C, which took them + * from System V, which brilliantly took internal interface macros and + * made them official arguments to setvbuf(), without renaming them. + * Hence, these ugly _IOxxx names are *supposed* to appear in user code. + * + * Although numbered as their counterparts above, the implementation + * does not rely on this. + */ +#define _IOFBF 0 /* setvbuf should set fully buffered */ +#define _IOLBF 1 /* setvbuf should set line buffered */ +#define _IONBF 2 /* setvbuf should set unbuffered */ + +#define BUFSIZ 1024 /* size of buffer used by setbuf */ + +#define EOF (-1) + +/* + * FOPEN_MAX is a minimum maximum, and should be the number of descriptors + * that the kernel can provide without allocation of a resource that can + * fail without the process sleeping. Do not use this for anything. + */ +#define FOPEN_MAX 20 /* must be <= OPEN_MAX */ +#define FILENAME_MAX 1024 /* must be <= PATH_MAX */ + +/* System V/ANSI C; this is the wrong way to do this, do *not* use these. */ +#if __BSD_VISIBLE || __XPG_VISIBLE +#define P_tmpdir "/tmp/" +#endif +#define L_tmpnam 1024 /* XXX must be == PATH_MAX */ +#define TMP_MAX 0x7fffffff /* more, but don't overflow int */ + +#ifndef SEEK_SET +#define SEEK_SET 0 /* set file offset to offset */ +#endif +#ifndef SEEK_CUR +#define SEEK_CUR 1 /* set file offset to current plus offset */ +#endif +#ifndef SEEK_END +#define SEEK_END 2 /* set file offset to EOF plus offset */ +#endif + +/* + * Functions defined in ANSI C standard. + */ +__BEGIN_DECLS +void clearerr(FILE *); +#if __POSIX_VISIBLE >= 200809 +int dprintf(int, const char * __restrict, ...) + __attribute__((__format__ (printf, 2, 3))) + __attribute__((__nonnull__ (2))); +#endif +int fclose(FILE *); +int feof(FILE *); +int ferror(FILE *); +int fflush(FILE *); +int fgetc(FILE *); +int fgetpos(FILE *, fpos_t *); +char *fgets(char *, int, FILE *) + __attribute__((__bounded__ (__string__,1,2))); +FILE *fopen(const char *, const char *); +int fprintf(FILE *, const char * __restrict, ...); +int fputc(int, FILE *); +int fputs(const char *, FILE *); +size_t fread(void *, size_t, size_t, FILE *) + __attribute__((__bounded__ (__size__,1,3,2))); +FILE *freopen(const char *, const char *, FILE *); +int fscanf(FILE *, const char *, ...); +int fseek(FILE *, long, int); +int fseeko(FILE *, off_t, int); +int fsetpos(FILE *, const fpos_t *); +long ftell(FILE *); +off_t ftello(FILE *); +size_t fwrite(const void *, size_t, size_t, FILE *) + __attribute__((__bounded__ (__size__,1,3,2))); +int getc(FILE *); +int getchar(void); +#if __POSIX_VISIBLE >= 200809 +ssize_t getdelim(char ** __restrict, size_t * __restrict, int, + FILE * __restrict); +ssize_t getline(char ** __restrict, size_t * __restrict, + FILE * __restrict); +#endif +#if __BSD_VISIBLE && !defined(__SYS_ERRLIST) +#define __SYS_ERRLIST + +extern int sys_nerr; /* perror(3) external variables */ +extern char *sys_errlist[]; +#endif +void perror(const char *); +int printf(const char * __restrict, ...); +int putc(int, FILE *); +int putchar(int); +int puts(const char *); +int remove(const char *); +int rename(const char *, const char *); +#if __POSIX_VISIBLE >= 200809 +int renameat(int, const char *, int, const char *); +#endif +void rewind(FILE *); +int scanf(const char *, ...); +void setbuf(FILE *, char *); +int setvbuf(FILE *, char *, int, size_t); +int sprintf(char * __restrict, const char * __restrict, ...); +int sscanf(const char *, const char *, ...); +FILE *tmpfile(void); +char *tmpnam(char *); +int ungetc(int, FILE *); +int vfprintf(FILE *, const char * __restrict, __va_list); +int vprintf(const char * __restrict, __va_list); +int vsprintf(char * __restrict, const char * __restrict, __va_list); +#if __POSIX_VISIBLE >= 200809 +int vdprintf(int, const char * __restrict, __va_list) + __attribute__((__format__ (printf, 2, 0))) + __attribute__((__nonnull__ (2))); +#endif + +#if __ISO_C_VISIBLE >= 1999 || __XPG_VISIBLE >= 500 || __BSD_VISIBLE +int snprintf(char * __restrict, size_t, const char * __restrict, ...) + __attribute__((__format__ (printf, 3, 4))) + __attribute__((__nonnull__ (3))) + __attribute__((__bounded__ (__string__,1,2))); +int vsnprintf(char * __restrict, size_t, const char * __restrict, + __va_list) + __attribute__((__format__ (printf, 3, 0))) + __attribute__((__nonnull__ (3))) + __attribute__((__bounded__(__string__,1,2))); +#endif /* __ISO_C_VISIBLE >= 1999 || __XPG_VISIBLE >= 500 || __BSD_VISIBLE */ + +#if __ISO_C_VISIBLE >= 1999 || __BSD_VISIBLE +int vfscanf(FILE *, const char *, __va_list) + __attribute__((__format__ (scanf, 2, 0))) + __attribute__((__nonnull__ (2))); +int vscanf(const char *, __va_list) + __attribute__((__format__ (scanf, 1, 0))) + __attribute__((__nonnull__ (1))); +int vsscanf(const char *, const char *, __va_list) + __attribute__((__format__ (scanf, 2, 0))) + __attribute__((__nonnull__ (2))); +#endif /* __ISO_C_VISIBLE >= 1999 || __BSD_VISIBLE */ + +__END_DECLS + + +/* + * Functions defined in POSIX 1003.1. + */ +#if __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE +#define L_ctermid 1024 /* size for ctermid(); PATH_MAX */ + +__BEGIN_DECLS +char *ctermid(char *); +FILE *fdopen(int, const char *); +int fileno(FILE *); + +#if __POSIX_VISIBLE >= 199209 +int pclose(FILE *); +FILE *popen(const char *, const char *); +#endif + +#if __POSIX_VISIBLE >= 199506 +void flockfile(FILE *); +int ftrylockfile(FILE *); +void funlockfile(FILE *); + +/* + * These are normally used through macros as defined below, but POSIX + * requires functions as well. + */ +int getc_unlocked(FILE *); +int getchar_unlocked(void); +int putc_unlocked(int, FILE *); +int putchar_unlocked(int); +#endif /* __POSIX_VISIBLE >= 199506 */ + +#if __POSIX_VISIBLE >= 200809 +FILE *fmemopen(void *, size_t, const char *); +FILE *open_memstream(char **, size_t *); +#endif /* __POSIX_VISIBLE >= 200809 */ + +#if __XPG_VISIBLE +char *tempnam(const char *, const char *); +#endif + +#if __POSIX_VISIBLE >= 202405 || __BSD_VISIBLE +int asprintf(char ** __restrict, const char * __restrict, ...) + __attribute__((__format__ (printf, 2, 3))) + __attribute__((__nonnull__ (2))); +int vasprintf(char ** __restrict, const char * __restrict, __va_list) + __attribute__((__format__ (printf, 2, 0))) + __attribute__((__nonnull__ (2))); +#endif /* __POSIX_VISIBLE >= 202405 || __BSD_VISIBLE */ +__END_DECLS + +#endif /* __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE */ + +/* + * Routines that are purely local. + */ +#if __BSD_VISIBLE +__BEGIN_DECLS +int fdclose(FILE *, int *_fdp); +char *fgetln(FILE *, size_t *); +int fpurge(FILE *); +int getw(FILE *); +int putw(int, FILE *); +void setbuffer(FILE *, char *, int); +int setlinebuf(FILE *); +__END_DECLS + +/* + * Stdio function-access interface. + */ +__BEGIN_DECLS +FILE *funopen(const void *, + int (*)(void *, char *, int), + int (*)(void *, const char *, int), + off_t (*)(void *, off_t, int), + int (*)(void *)); +__END_DECLS +#define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0) +#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0) +#endif /* __BSD_VISIBLE */ + +#define getchar() getc(stdin) +#define putchar(x) putc(x, stdout) +#define getchar_unlocked() getc_unlocked(stdin) +#define putchar_unlocked(c) putc_unlocked(c, stdout) + +#endif /* _STDIO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/stdio_ext.h b/lib/libc/include/generic-openbsd/stdio_ext.h new file mode 100644 index 0000000000..28c97f25eb --- /dev/null +++ b/lib/libc/include/generic-openbsd/stdio_ext.h @@ -0,0 +1,31 @@ +/* $OpenBSD: stdio_ext.h,v 1.1 2024/08/12 20:56:55 guenther Exp $ */ +/* + * Copyright (c) 2024 Philip Guenther + * + * 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 _STDIO_EXT_H_ +#define _STDIO_EXT_H_ + +#include + +size_t __fpending(FILE *); +size_t __freadahead(FILE *); +int __freading(FILE *); +const char *__freadptr(FILE *, size_t *_sizep); +void __freadptrinc(FILE *, size_t _inc); +void __fseterr(FILE *); +int __fwriting(FILE *); + +#endif /* _STDIO_EXT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/stdlib.h b/lib/libc/include/generic-openbsd/stdlib.h new file mode 100644 index 0000000000..a7ffcea8ea --- /dev/null +++ b/lib/libc/include/generic-openbsd/stdlib.h @@ -0,0 +1,324 @@ +/* $OpenBSD: stdlib.h,v 1.78 2024/08/03 20:09:24 guenther Exp $ */ +/* $NetBSD: stdlib.h,v 1.25 1995/12/27 21:19:08 jtc Exp $ */ + +/*- + * Copyright (c) 1990 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. + * + * @(#)stdlib.h 5.13 (Berkeley) 6/4/91 + */ + +#ifndef _STDLIB_H_ +#define _STDLIB_H_ + +#include +#include +#include +#if __BSD_VISIBLE /* for quad_t, etc. (XXX - use protected types) */ +#include +#endif + +#ifndef _SIZE_T_DEFINED_ +#define _SIZE_T_DEFINED_ +typedef __size_t size_t; +#endif + +/* in C++, wchar_t is a built-in type */ +#if !defined(_WCHAR_T_DEFINED_) && !defined(__cplusplus) +#define _WCHAR_T_DEFINED_ +typedef __wchar_t wchar_t; +#endif + +typedef struct { + int quot; /* quotient */ + int rem; /* remainder */ +} div_t; + +typedef struct { + long quot; /* quotient */ + long rem; /* remainder */ +} ldiv_t; + +#if __ISO_C_VISIBLE >= 1999 +typedef struct { + long long quot; /* quotient */ + long long rem; /* remainder */ +} lldiv_t; +#endif + +#if __BSD_VISIBLE +typedef struct { + quad_t quot; /* quotient */ + quad_t rem; /* remainder */ +} qdiv_t; +#endif + +#define EXIT_FAILURE 1 +#define EXIT_SUCCESS 0 + +#define RAND_MAX 0x7fffffff + +#define MB_CUR_MAX __mb_cur_max() + +/* + * Some header files may define an abs macro. + * If defined, undef it to prevent a syntax error and issue a warning. + */ +#ifdef abs +#undef abs +#warning abs macro collides with abs() prototype, undefining +#endif + +__BEGIN_DECLS +__dead void abort(void); +int abs(int); +int atexit(void (*)(void)); +double atof(const char *); +int atoi(const char *); +long atol(const char *); +void *bsearch(const void *, const void *, size_t, size_t, + int (*)(const void *, const void *)); +void *calloc(size_t, size_t); +div_t div(int, int); +__dead void exit(int); +__dead void _Exit(int); +void free(void *); +char *getenv(const char *); +long labs(long); +ldiv_t ldiv(long, long); +void *malloc(size_t); +#if __BSD_VISIBLE +void freezero(void *, size_t) + __attribute__ ((__bounded__(__buffer__,1,2))); +void *calloc_conceal(size_t, size_t); +void *malloc_conceal(size_t); +void *recallocarray(void *, size_t, size_t, size_t); +#endif /* __BSD_VISIBLE */ +void qsort(void *, size_t, size_t, int (*)(const void *, const void *)); +int rand(void); +void *realloc(void *, size_t); +void srand(unsigned); +void srand_deterministic(unsigned); +double strtod(const char *__restrict, char **__restrict); +float strtof(const char *__restrict, char **__restrict); +long strtol(const char *__restrict, char **__restrict, int); +long double + strtold(const char *__restrict, char **__restrict); +unsigned long + strtoul(const char *__restrict, char **__restrict, int); +int system(const char *); + +size_t __mb_cur_max(void); +int mblen(const char *, size_t); +size_t mbstowcs(wchar_t *, const char *, size_t); +int wctomb(char *, wchar_t); +int mbtowc(wchar_t *, const char *, size_t); +size_t wcstombs(char *, const wchar_t *, size_t); + +/* + * IEEE Std 1003.1c-95, also adopted by X/Open CAE Spec Issue 5 Version 2 + */ +#if __BSD_VISIBLE || __POSIX_VISIBLE >= 199506 || defined(_REENTRANT) +int rand_r(unsigned int *); +#endif + +#if __BSD_VISIBLE || __XPG_VISIBLE >= 400 +double drand48(void); +double erand48(unsigned short[3]); +long jrand48(unsigned short[3]); +void lcong48(unsigned short[7]); +void lcong48_deterministic(unsigned short[7]); +long lrand48(void); +long mrand48(void); +long nrand48(unsigned short[3]); +unsigned short *seed48(unsigned short[3]); +unsigned short *seed48_deterministic(unsigned short[3]); +void srand48(long); +void srand48_deterministic(long); + +int putenv(char *); +#endif + +/* + * XSI functions marked LEGACY in IEEE Std 1003.1-2001 (POSIX) and + * removed in IEEE Std 1003.1-2008 + */ +#if __BSD_VISIBLE || __XPG_VISIBLE < 700 +char *ecvt(double, int, int *, int *); +char *fcvt(double, int, int *, int *); +char *gcvt(double, int, char *); +#if __BSD_VISIBLE || __XPG_VISIBLE >= 420 +char *mktemp(char *); +#endif +#endif /* __BSD_VISIBLE || __XPG_VISIBLE < 700 */ + +#if __BSD_VISIBLE || __XPG_VISIBLE >= 420 +long a64l(const char *); +char *l64a(long); + +char *initstate(unsigned int, char *, size_t) + __attribute__((__bounded__ (__string__,2,3))); +long random(void); +char *setstate(char *); +void srandom(unsigned int); +void srandom_deterministic(unsigned int); + +char *realpath(const char *, char *) + __attribute__((__bounded__ (__minbytes__,2,1024))); + +/* + * XSI functions marked LEGACY in XPG5 and removed in IEEE Std 1003.1-2001 + */ +#if __BSD_VISIBLE || __XPG_VISIBLE < 600 +int ttyslot(void); +void *valloc(size_t); /* obsoleted by malloc() */ +#endif +#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */ + +/* + * 4.4BSD, then XSI in XPG4.2, then added to POSIX base in IEEE Std 1003.1-2008 + */ +#if __BSD_VISIBLE || __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200809 +int mkstemp(char *); +#endif + +/* + * ISO C99 + */ +#if __ISO_C_VISIBLE >= 1999 +long long + atoll(const char *); +long long + llabs(long long); +lldiv_t + lldiv(long long, long long); +long long + strtoll(const char *__restrict, char **__restrict, int); +unsigned long long + strtoull(const char *__restrict, char **__restrict, int); +#endif + +#if __ISO_C_VISIBLE >= 2011 +void * + aligned_alloc(size_t, size_t); +#endif + +/* + * The Open Group Base Specifications, Issue 6; IEEE Std 1003.1-2001 (POSIX) + */ +#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 +int posix_memalign(void **, size_t, size_t); +int setenv(const char *, const char *, int); +int unsetenv(const char *); +#endif +#if __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200112 +char *ptsname(int); +int grantpt(int); +int unlockpt(int); +#endif +#if __POSIX_VISIBLE >= 200112 +int posix_openpt(int); +#endif + +/* + * The Open Group Base Specifications, Issue 7; IEEE Std 1003.1-2008 (POSIX) + */ +#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 +char *mkdtemp(char *); +#endif + +#if __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200809 +int getsubopt(char **, char * const *, char **); +#endif + +/* + * The Open Group Base Specifications, Issue 8 + */ +#if __POSIX_VISIBLE >= 202405 || __BSD_VISIBLE +int mkostemp(char *, int); +void *reallocarray(void *, size_t, size_t); +#endif + +#if __BSD_VISIBLE +#define alloca(n) __builtin_alloca(n) + +char *getbsize(int *, long *); +char *cgetcap(char *, const char *, int); +int cgetclose(void); +int cgetent(char **, char **, const char *); +int cgetfirst(char **, char **); +int cgetmatch(char *, const char *); +int cgetnext(char **, char **); +int cgetnum(char *, const char *, long *); +int cgetset(const char *); +int cgetusedb(int); +int cgetstr(char *, const char *, char **); +int cgetustr(char *, const char *, char **); + +int daemon(int, int); +char *devname(dev_t, mode_t); +int getloadavg(double [], int); + +const char * + getprogname(void); +void setprogname(const char *); + +extern char *suboptarg; /* getsubopt(3) external variable */ + +char * mkdtemps(char *, int); +int mkstemps(char *, int); +int mkostemps(char *, int, int); + +int heapsort(void *, size_t, size_t, int (*)(const void *, const void *)); +int mergesort(void *, size_t, size_t, int (*)(const void *, const void *)); +int radixsort(const unsigned char **, int, const unsigned char *, + unsigned); +int sradixsort(const unsigned char **, int, const unsigned char *, + unsigned); + +void srandomdev(void); +long long + strtonum(const char *, long long, long long, const char **); + +void setproctitle(const char *, ...) + __attribute__((__format__ (__printf__, 1, 2))); + +quad_t qabs(quad_t); +qdiv_t qdiv(quad_t, quad_t); +quad_t strtoq(const char *__restrict, char **__restrict, int); +u_quad_t strtouq(const char *__restrict, char **__restrict, int); + +uint32_t arc4random(void); +uint32_t arc4random_uniform(uint32_t); +void arc4random_buf(void *, size_t) + __attribute__((__bounded__ (__buffer__,1,2))); + +#endif /* __BSD_VISIBLE */ + +__END_DECLS + +#endif /* _STDLIB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/string.h b/lib/libc/include/generic-openbsd/string.h new file mode 100644 index 0000000000..a7a01caac0 --- /dev/null +++ b/lib/libc/include/generic-openbsd/string.h @@ -0,0 +1,141 @@ +/* $OpenBSD: string.h,v 1.34 2024/08/03 20:13:23 guenther Exp $ */ +/* $NetBSD: string.h,v 1.6 1994/10/26 00:56:30 cgd Exp $ */ + +/*- + * Copyright (c) 1990 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. + * + * @(#)string.h 5.10 (Berkeley) 3/9/91 + */ + +#ifndef _STRING_H_ +#define _STRING_H_ + +#include +#include +#include + +/* + * POSIX mandates that certain string functions not present in ISO C + * be prototyped in strings.h. Historically, we've included them here. + */ +#if __BSD_VISIBLE +#include +#endif + +#ifndef _SIZE_T_DEFINED_ +#define _SIZE_T_DEFINED_ +typedef __size_t size_t; +#endif + +#if __POSIX_VISIBLE >= 200809 +#ifndef _LOCALE_T_DEFINED_ +#define _LOCALE_T_DEFINED_ +typedef void *locale_t; +#endif +#endif + +__BEGIN_DECLS +void *memchr(const void *, int, size_t); +int memcmp(const void *, const void *, size_t); +void *memcpy(void *__restrict, const void *__restrict, size_t) + __attribute__ ((__bounded__(__buffer__,1,3))) + __attribute__ ((__bounded__(__buffer__,2,3))); +void *memmove(void *, const void *, size_t) + __attribute__ ((__bounded__(__buffer__,1,3))) + __attribute__ ((__bounded__(__buffer__,2,3))); +void *memset(void *, int, size_t) + __attribute__ ((__bounded__(__buffer__,1,3))); +char *strcat(char *__restrict, const char *__restrict); +char *strchr(const char *, int); +int strcmp(const char *, const char *); +int strcoll(const char *, const char *); +char *strcpy(char *__restrict, const char *__restrict); +size_t strcspn(const char *, const char *); +char *strerror(int); +size_t strlen(const char *); +char *strncat(char *__restrict, const char *__restrict, size_t) + __attribute__ ((__bounded__(__string__,1,3))); +int strncmp(const char *, const char *, size_t); +char *strncpy(char *__restrict, const char *__restrict, size_t) + __attribute__ ((__bounded__(__string__,1,3))); +char *strpbrk(const char *, const char *); +char *strrchr(const char *, int); +size_t strspn(const char *, const char *); +char *strstr(const char *, const char *); +char *strtok(char *__restrict, const char *__restrict); +char *strtok_r(char *__restrict, const char *__restrict, char **__restrict); +size_t strxfrm(char *__restrict, const char *__restrict, size_t) + __attribute__ ((__bounded__(__string__,1,3))); + +#if __XPG_VISIBLE +void *memccpy(void *__restrict, const void *__restrict, int, size_t) + __attribute__ ((__bounded__(__buffer__,1,4))); +#endif + +#if __POSIX_VISIBLE >= 200112 +int strerror_r(int, char *, size_t) + __attribute__ ((__bounded__(__string__,2,3))); +#endif + +#if __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200809 +char *strdup(const char *); +#endif + +#if __POSIX_VISIBLE >= 200809 +char *stpcpy(char *__restrict, const char *__restrict); +char *stpncpy(char *__restrict, const char *__restrict, size_t); +int strcoll_l(const char *, const char *, locale_t); +char *strerror_l(int, locale_t); +char *strndup(const char *, size_t); +size_t strnlen(const char *, size_t); +char *strsignal(int); +size_t strxfrm_l(char *__restrict, const char *__restrict, size_t, locale_t) + __attribute__ ((__bounded__(__string__,1,3))); +#endif + +#if __POSIX_VISIBLE >= 202405 || __BSD_VISIBLE +void *memmem(const void *, size_t, const void *, size_t); +size_t strlcat(char *__restrict, const char *__restrict, size_t) + __attribute__ ((__bounded__(__string__,1,3))); +size_t strlcpy(char *__restrict, const char *__restrict, size_t) + __attribute__ ((__bounded__(__string__,1,3))); +#endif + +#if __BSD_VISIBLE +void explicit_bzero(void *, size_t) + __attribute__ ((__bounded__(__buffer__,1,2))); +void *memrchr(const void *, int, size_t); +char *strcasestr(const char *, const char *); +void strmode(__mode_t, char *); +char *strsep(char **, const char *); +int timingsafe_bcmp(const void *, const void *, size_t); +int timingsafe_memcmp(const void *, const void *, size_t); +#endif +__END_DECLS + +#endif /* _STRING_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/strings.h b/lib/libc/include/generic-openbsd/strings.h new file mode 100644 index 0000000000..5656d59383 --- /dev/null +++ b/lib/libc/include/generic-openbsd/strings.h @@ -0,0 +1,83 @@ +/* $OpenBSD: strings.h,v 1.6 2017/09/10 21:50:36 schwarze Exp $ */ + +/*- + * Copyright (c) 1990 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. + * + * @(#)strings.h 5.8 (Berkeley) 5/15/90 + */ + +#ifndef _STRINGS_H_ +#define _STRINGS_H_ + +#include +#include + +/* + * POSIX mandates that certain string functions not present in ISO C + * be prototyped in strings.h. + */ + +#ifndef _SIZE_T_DEFINED_ +#define _SIZE_T_DEFINED_ +typedef __size_t size_t; +#endif + +#if __POSIX_VISIBLE >= 200809 +#ifndef _LOCALE_T_DEFINED_ +#define _LOCALE_T_DEFINED_ +typedef void *locale_t; +#endif +#endif + +__BEGIN_DECLS +#if __BSD_VISIBLE || (__XPG_VISIBLE >= 420 && __POSIX_VISIBLE <= 200112) +/* + * The following functions were removed from IEEE Std 1003.1-2008 + */ +int bcmp(const void *, const void *, size_t); +void bcopy(const void *, void *, size_t) + __attribute__ ((__bounded__(__buffer__,1,3))) + __attribute__ ((__bounded__(__buffer__,2,3))); +void bzero(void *, size_t) + __attribute__ ((__bounded__(__buffer__,1,2))); +char *index(const char *, int); +char *rindex(const char *, int); +#endif + +#if __XPG_VISIBLE >= 420 +int ffs(int); +int strcasecmp(const char *, const char *); +int strncasecmp(const char *, const char *, size_t); +#endif +#if __POSIX_VISIBLE >= 200809 +int strcasecmp_l(const char *, const char *, locale_t); +int strncasecmp_l(const char *, const char *, size_t, locale_t); +#endif +__END_DECLS + +#endif /* _STRINGS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/_endian.h b/lib/libc/include/generic-openbsd/sys/_endian.h new file mode 100644 index 0000000000..570cc6f564 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/_endian.h @@ -0,0 +1,179 @@ +/* $OpenBSD: _endian.h,v 1.8 2018/01/11 23:13:37 dlg 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. + */ + +/* + * Internal endianness macros. This pulls in to + * get the correct setting direction for the platform and sets internal + * ('__' prefix) macros appropriately. + */ + +#ifndef _SYS__ENDIAN_H_ +#define _SYS__ENDIAN_H_ + +#include + +#define __FROM_SYS__ENDIAN +#include +#undef __FROM_SYS__ENDIAN + +#define _LITTLE_ENDIAN 1234 +#define _BIG_ENDIAN 4321 +#define _PDP_ENDIAN 3412 + +/* Note that these macros evaluate their arguments several times. */ + +#define __swap16gen(x) \ + (__uint16_t)(((__uint16_t)(x) & 0xffU) << 8 | ((__uint16_t)(x) & 0xff00U) >> 8) + +#define __swap32gen(x) \ + (__uint32_t)(((__uint32_t)(x) & 0xff) << 24 | \ + ((__uint32_t)(x) & 0xff00) << 8 | ((__uint32_t)(x) & 0xff0000) >> 8 |\ + ((__uint32_t)(x) & 0xff000000) >> 24) + +#define __swap64gen(x) \ + (__uint64_t)((((__uint64_t)(x) & 0xff) << 56) | \ + ((__uint64_t)(x) & 0xff00ULL) << 40 | \ + ((__uint64_t)(x) & 0xff0000ULL) << 24 | \ + ((__uint64_t)(x) & 0xff000000ULL) << 8 | \ + ((__uint64_t)(x) & 0xff00000000ULL) >> 8 | \ + ((__uint64_t)(x) & 0xff0000000000ULL) >> 24 | \ + ((__uint64_t)(x) & 0xff000000000000ULL) >> 40 | \ + ((__uint64_t)(x) & 0xff00000000000000ULL) >> 56) + +#ifndef __HAVE_MD_SWAP +static __inline __uint16_t +__swap16md(__uint16_t x) +{ + return (__swap16gen(x)); +} + +static __inline __uint32_t +__swap32md(__uint32_t x) +{ + return (__swap32gen(x)); +} + +static __inline __uint64_t +__swap64md(__uint64_t x) +{ + return (__swap64gen(x)); +} +#endif + +#define __swap16(x) \ + (__uint16_t)(__builtin_constant_p(x) ? __swap16gen(x) : __swap16md(x)) +#define __swap32(x) \ + (__uint32_t)(__builtin_constant_p(x) ? __swap32gen(x) : __swap32md(x)) +#define __swap64(x) \ + (__uint64_t)(__builtin_constant_p(x) ? __swap64gen(x) : __swap64md(x)) + +#if _BYTE_ORDER == _LITTLE_ENDIAN + +#define _QUAD_HIGHWORD 1 +#define _QUAD_LOWWORD 0 + +#define __htobe16 __swap16 +#define __htobe32 __swap32 +#define __htobe64 __swap64 +#define __htole16(x) ((__uint16_t)(x)) +#define __htole32(x) ((__uint32_t)(x)) +#define __htole64(x) ((__uint64_t)(x)) + +#ifdef _KERNEL +#ifdef __HAVE_MD_SWAPIO + +#define __bemtoh16(_x) __mswap16(_x) +#define __bemtoh32(_x) __mswap32(_x) +#define __bemtoh64(_x) __mswap64(_x) + +#define __htobem16(_x, _v) __swapm16((_x), (_v)) +#define __htobem32(_x, _v) __swapm32((_x), (_v)) +#define __htobem64(_x, _v) __swapm64((_x), (_v)) + +#endif /* __HAVE_MD_SWAPIO */ +#endif /* _KERNEL */ +#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */ + +#if _BYTE_ORDER == _BIG_ENDIAN + +#define _QUAD_HIGHWORD 0 +#define _QUAD_LOWWORD 1 + +#define __htobe16(x) ((__uint16_t)(x)) +#define __htobe32(x) ((__uint32_t)(x)) +#define __htobe64(x) ((__uint64_t)(x)) +#define __htole16 __swap16 +#define __htole32 __swap32 +#define __htole64 __swap64 + +#ifdef _KERNEL +#ifdef __HAVE_MD_SWAPIO + +#define __lemtoh16(_x) __mswap16(_x) +#define __lemtoh32(_x) __mswap32(_x) +#define __lemtoh64(_x) __mswap64(_x) + +#define __htolem16(_x, _v) __swapm16((_x), (_v)) +#define __htolem32(_x, _v) __swapm32((_x), (_v)) +#define __htolem64(_x, _v) __swapm64((_x), (_v)) + +#endif /* __HAVE_MD_SWAPIO */ +#endif /* _KERNEL */ +#endif /* _BYTE_ORDER == _BIG_ENDIAN */ + + +#ifdef _KERNEL +/* + * Fill in the __hto[bl]em{16,32,64} and __[bl]emtoh{16,32,64} macros + * that haven't been defined yet + */ + +#ifndef __bemtoh16 +#define __bemtoh16(_x) __htobe16(*(__uint16_t *)(_x)) +#define __bemtoh32(_x) __htobe32(*(__uint32_t *)(_x)) +#define __bemtoh64(_x) __htobe64(*(__uint64_t *)(_x)) +#endif + +#ifndef __htobem16 +#define __htobem16(_x, _v) (*(__uint16_t *)(_x) = __htobe16(_v)) +#define __htobem32(_x, _v) (*(__uint32_t *)(_x) = __htobe32(_v)) +#define __htobem64(_x, _v) (*(__uint64_t *)(_x) = __htobe64(_v)) +#endif + +#ifndef __lemtoh16 +#define __lemtoh16(_x) __htole16(*(__uint16_t *)(_x)) +#define __lemtoh32(_x) __htole32(*(__uint32_t *)(_x)) +#define __lemtoh64(_x) __htole64(*(__uint64_t *)(_x)) +#endif + +#ifndef __htolem16 +#define __htolem16(_x, _v) (*(__uint16_t *)(_x) = __htole16(_v)) +#define __htolem32(_x, _v) (*(__uint32_t *)(_x) = __htole32(_v)) +#define __htolem64(_x, _v) (*(__uint64_t *)(_x) = __htole64(_v)) +#endif +#endif /* _KERNEL */ + +#endif /* _SYS__ENDIAN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/_lock.h b/lib/libc/include/generic-openbsd/sys/_lock.h new file mode 100644 index 0000000000..97c140b272 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/_lock.h @@ -0,0 +1,71 @@ +/* $OpenBSD: _lock.h,v 1.7 2025/04/14 12:53:54 visa Exp $ */ + +/*- + * Copyright (c) 1997 Berkeley Software Design, Inc. 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. Berkeley Software Design Inc's name may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``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 BERKELEY SOFTWARE DESIGN INC 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. + * + * $FreeBSD: head/sys/sys/_lock.h 179025 2008-05-15 20:10:06Z attilio $ + */ + +#ifndef _SYS__LOCK_H_ +#define _SYS__LOCK_H_ + +#define LO_CLASSFLAGS 0x0000ffff /* Class specific flags. */ +#define LO_INITIALIZED 0x00010000 /* Lock has been initialized. */ +#define LO_WITNESS 0x00020000 /* Should witness monitor this lock. */ +#define LO_RECURSABLE 0x00080000 /* Lock may recurse. */ +#define LO_SLEEPABLE 0x00100000 /* Lock may be held while sleeping. */ +#define LO_UPGRADABLE 0x00200000 /* Lock may be upgraded/downgraded. */ +#define LO_DUPOK 0x00400000 /* Don't check for duplicate acquires */ +#define LO_IS_VNODE 0x00800000 /* Tell WITNESS about a VNODE lock */ +#define LO_CLASSMASK 0x0f000000 /* Class index bitmask. */ +#define LO_HASPARENT 0x40000000 /* If set, non-NULL lo_relative + * points to parent lock. + * If clear, non-NULL lo_relative + * points to child lock. */ + +#define LO_CLASSSHIFT 24 + +enum lock_class_index { + LO_CLASS_KERNEL_LOCK, + LO_CLASS_MUTEX, + LO_CLASS_RWLOCK, + LO_CLASS_RRWLOCK +}; + +struct lock_object { + const struct lock_type *lo_type; + const char *lo_name; /* Individual lock name. */ + struct witness *lo_witness; /* Data for witness. */ + struct lock_object *lo_relative; /* Parent or child lock. */ + unsigned int lo_flags; +}; + +struct lock_type { + const char *lt_name; +}; + +#endif /* !_SYS__LOCK_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/_null.h b/lib/libc/include/generic-openbsd/sys/_null.h new file mode 100644 index 0000000000..f25deb1ba4 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/_null.h @@ -0,0 +1,18 @@ +/* $OpenBSD: _null.h,v 1.2 2016/09/09 22:07:58 millert Exp $ */ + +/* + * Written by Todd C. Miller, September 9, 2016 + * Public domain. + */ + +#ifndef NULL +#if !defined(__cplusplus) +#define NULL ((void *)0) +#elif __cplusplus >= 201103L +#define NULL nullptr +#elif defined(__GNUG__) +#define NULL __null +#else +#define NULL 0L +#endif +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/_time.h b/lib/libc/include/generic-openbsd/sys/_time.h new file mode 100644 index 0000000000..ea9a3a8a75 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/_time.h @@ -0,0 +1,85 @@ +/* $OpenBSD: _time.h,v 1.10 2022/10/25 16:30:30 millert Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _SYS__TIME_H_ +#define _SYS__TIME_H_ + +/* Frequency of ticks reported by clock(). */ +#define CLOCKS_PER_SEC 100 + +#if __BSD_VISIBLE +/* + * Per-process and per-thread clocks encode the PID or TID into the + * high bits, with the type in the bottom bits + */ +#define __CLOCK_ENCODE(type,id) ((type) | ((id) << 12)) +#define __CLOCK_TYPE(c) ((c) & 0xfff) +#define __CLOCK_PTID(c) (((c) >> 12) & 0xfffff) +#endif + +#if __POSIX_VISIBLE >= 199309 || __ISO_C_VISIBLE >= 2011 +#ifndef _TIME_T_DEFINED_ +#define _TIME_T_DEFINED_ +typedef __time_t time_t; +#endif + +#ifndef _TIMESPEC_DECLARED +#define _TIMESPEC_DECLARED +struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +}; +#endif +#endif + +#if __POSIX_VISIBLE >= 199309 +#define CLOCK_REALTIME 0 +#define CLOCK_PROCESS_CPUTIME_ID 2 +#define CLOCK_MONOTONIC 3 +#define CLOCK_THREAD_CPUTIME_ID 4 +#define CLOCK_UPTIME 5 +#define CLOCK_BOOTTIME 6 + +/* + * Structure defined by POSIX 1003.1b to be like a itimerval, + * but with timespecs. Used in the timer_*() system calls. + */ +struct itimerspec { + struct timespec it_interval; /* timer interval */ + struct timespec it_value; /* timer expiration */ +}; + +#define TIMER_RELTIME 0x0 /* relative timer */ +#define TIMER_ABSTIME 0x1 /* absolute timer */ + +#endif + +#endif /* !_SYS__TIME_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/_types.h b/lib/libc/include/generic-openbsd/sys/_types.h new file mode 100644 index 0000000000..2bcce5a08e --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/_types.h @@ -0,0 +1,77 @@ +/* $OpenBSD: _types.h,v 1.10 2022/08/06 13:31:13 semarie 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 + */ + +#ifndef _SYS__TYPES_H_ +#define _SYS__TYPES_H_ + +#include + +typedef __int64_t __blkcnt_t; /* blocks allocated for file */ +typedef __int32_t __blksize_t; /* optimal blocksize for I/O */ +typedef __int64_t __clock_t; /* ticks in CLOCKS_PER_SEC */ +typedef __int32_t __clockid_t; /* CLOCK_* identifiers */ +typedef unsigned long __cpuid_t; /* CPU id */ +typedef __int32_t __dev_t; /* device number */ +typedef __uint32_t __fixpt_t; /* fixed point number */ +typedef __uint64_t __fsblkcnt_t; /* file system block count */ +typedef __uint64_t __fsfilcnt_t; /* file system file count */ +typedef __uint32_t __gid_t; /* group id */ +typedef __uint32_t __id_t; /* may contain pid, uid or gid */ +typedef __uint32_t __in_addr_t; /* base type for internet address */ +typedef __uint16_t __in_port_t; /* IP port type */ +typedef __uint64_t __ino_t; /* inode number */ +typedef long __key_t; /* IPC key (for Sys V IPC) */ +typedef __uint32_t __mode_t; /* permissions */ +typedef __uint32_t __nlink_t; /* link count */ +typedef __int64_t __off_t; /* file offset or size */ +typedef __int32_t __pid_t; /* process id */ +typedef __uint64_t __rlim_t; /* resource limit */ +typedef __uint8_t __sa_family_t; /* sockaddr address family type */ +typedef __int32_t __segsz_t; /* segment size */ +typedef __uint32_t __socklen_t; /* length type for network syscalls */ +typedef long __suseconds_t; /* microseconds (signed) */ +typedef __int64_t __time_t; /* epoch time */ +typedef __int32_t __timer_t; /* POSIX timer identifiers */ +typedef __uint32_t __uid_t; /* user id */ +typedef __uint32_t __useconds_t; /* microseconds */ + +/* + * mbstate_t is an opaque object to keep conversion state, during multibyte + * stream conversions. The content must not be referenced by user programs. + */ +typedef union { + char __mbstate8[128]; + __int64_t __mbstateL; /* for alignment */ +} __mbstate_t; + +#endif /* !_SYS__TYPES_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/acct.h b/lib/libc/include/generic-openbsd/sys/acct.h new file mode 100644 index 0000000000..c858ab8e5c --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/acct.h @@ -0,0 +1,83 @@ +/* $OpenBSD: acct.h,v 1.16 2024/02/25 00:07:13 deraadt Exp $ */ +/* $NetBSD: acct.h,v 1.16 1995/03/26 20:23:52 jtc Exp $ */ + +/*- + * Copyright (c) 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)acct.h 8.3 (Berkeley) 7/10/94 + */ + +#include + +/* + * Accounting structures; these use a comp_t type which is a 3 bits base 8 + * exponent, 13 bit fraction ``floating point'' number. Units are 1/AHZ + * seconds. + */ +typedef u_int16_t comp_t; + +struct acct { + char ac_comm[_MAXCOMLEN]; /* command name, incl NUL */ + comp_t ac_utime; /* user time */ + comp_t ac_stime; /* system time */ + comp_t ac_etime; /* elapsed time */ + comp_t ac_io; /* count of IO blocks */ + time_t ac_btime; /* starting time */ + uid_t ac_uid; /* user id */ + gid_t ac_gid; /* group id */ + u_int32_t ac_mem; /* average memory usage */ + dev_t ac_tty; /* controlling tty, or -1 */ + pid_t ac_pid; /* process id */ + + u_int32_t ac_flag; /* accounting flags */ +#define AFORK 0x00000001 /* fork'd but not exec'd */ +#define AMAP 0x00000004 /* killed by syscall or stack mapping violation */ +#define ACORE 0x00000008 /* dumped core */ +#define AXSIG 0x00000010 /* killed by a signal */ +#define APLEDGE 0x00000020 /* killed due to pledge violation */ +#define ATRAP 0x00000040 /* memory access violation */ +#define AUNVEIL 0x00000080 /* unveil access violation */ +#define APINSYS 0x00000200 /* killed by syscall pin violation */ +#define ABTCFI 0x00000400 /* BT CFI violation */ +}; + +/* + * 1/AHZ is the granularity of the data encoded in the comp_t fields. + * This is not necessarily equal to hz. + */ +#define AHZ 64 + +#ifdef _KERNEL +int acct_process(struct proc *p); +void acct_shutdown(void); +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/ataio.h b/lib/libc/include/generic-openbsd/sys/ataio.h new file mode 100644 index 0000000000..4dd1e389fb --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/ataio.h @@ -0,0 +1,48 @@ +/* $OpenBSD: ataio.h,v 1.5 2003/09/26 21:43:32 miod Exp $ */ +/* $NetBSD: ataio.h,v 1.2 1998/11/23 22:58:23 kenh Exp $ */ + +#ifndef _SYS_ATAIO_H_ +#define _SYS_ATAIO_H_ + +#include +#include + +typedef struct atareq { + u_long flags; /* info about the request status and type */ + u_char command; /* command code */ + u_char features; /* feature modifier bits for command */ + u_char sec_count; /* sector count */ + u_char sec_num; /* sector number */ + u_char head; /* head number */ + u_short cylinder; /* cylinder/lba address */ + + caddr_t databuf; /* pointer to I/O data buffer */ + u_long datalen; /* length of data buffer */ + int timeout; /* command timeout */ + u_char retsts; /* return status for the command */ + u_char error; /* error bits */ +} atareq_t; + +/* bit definitions for flags */ +#define ATACMD_READ 0x00000001 +#define ATACMD_WRITE 0x00000002 +#define ATACMD_READREG 0x00000004 + +/* definitions for the return status (retsts) */ +#define ATACMD_OK 0x00 +#define ATACMD_TIMEOUT 0x01 +#define ATACMD_ERROR 0x02 +#define ATACMD_DF 0x03 + +#define ATAIOCCOMMAND _IOWR('Q', 8, atareq_t) + +typedef struct atagettrace { + unsigned int buf_size; /* length of data buffer */ + void *buf; /* pointer to data buffer */ + unsigned int bytes_copied; /* number of bytes copied to buffer */ + unsigned int bytes_left; /* number of bytes left */ +} atagettrace_t; + +#define ATAIOGETTRACE _IOWR('Q', 27, struct atagettrace) + +#endif /* _SYS_ATAIO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/atomic.h b/lib/libc/include/generic-openbsd/sys/atomic.h new file mode 100644 index 0000000000..68baa4661f --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/atomic.h @@ -0,0 +1,293 @@ +/* $OpenBSD: atomic.h,v 1.10 2025/01/03 21:27:41 bluhm Exp $ */ +/* + * Copyright (c) 2014 David Gwynne + * Copyright (c) 2022 Alexander Bluhm + * + * 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 _SYS_ATOMIC_H_ +#define _SYS_ATOMIC_H_ + +#include + +/* + * an arch wanting to provide its own implementations does so by defining + * macros. + */ + +/* + * atomic_cas_* + */ + +#ifndef atomic_cas_uint +static inline unsigned int +atomic_cas_uint(volatile unsigned int *p, unsigned int o, unsigned int n) +{ + return __sync_val_compare_and_swap(p, o, n); +} +#endif + +#ifndef atomic_cas_ulong +static inline unsigned long +atomic_cas_ulong(volatile unsigned long *p, unsigned long o, unsigned long n) +{ + return __sync_val_compare_and_swap(p, o, n); +} +#endif + +#ifndef atomic_cas_ptr +static inline void * +atomic_cas_ptr(volatile void *pp, void *o, void *n) +{ + void * volatile *p = (void * volatile *)pp; + return __sync_val_compare_and_swap(p, o, n); +} +#endif + +/* + * atomic_swap_* + */ + +#ifndef atomic_swap_uint +static inline unsigned int +atomic_swap_uint(volatile unsigned int *p, unsigned int v) +{ + return __sync_lock_test_and_set(p, v); +} +#endif + +#ifndef atomic_swap_ulong +static inline unsigned long +atomic_swap_ulong(volatile unsigned long *p, unsigned long v) +{ + return __sync_lock_test_and_set(p, v); +} +#endif + +#ifndef atomic_swap_ptr +static inline void * +atomic_swap_ptr(volatile void *pp, void *v) +{ + void * volatile *p = (void * volatile *)pp; + return __sync_lock_test_and_set(p, v); +} +#endif + +/* + * atomic_add_*_nv - add and fetch + */ + +#ifndef atomic_add_int_nv +static inline unsigned int +atomic_add_int_nv(volatile unsigned int *p, unsigned int v) +{ + return __sync_add_and_fetch(p, v); +} +#endif + +#ifndef atomic_add_long_nv +static inline unsigned long +atomic_add_long_nv(volatile unsigned long *p, unsigned long v) +{ + return __sync_add_and_fetch(p, v); +} +#endif + +/* + * atomic_add - add + */ + +#ifndef atomic_add_int +#define atomic_add_int(_p, _v) ((void)atomic_add_int_nv((_p), (_v))) +#endif + +#ifndef atomic_add_long +#define atomic_add_long(_p, _v) ((void)atomic_add_long_nv((_p), (_v))) +#endif + +/* + * atomic_inc_*_nv - increment and fetch + */ + +#ifndef atomic_inc_int_nv +#define atomic_inc_int_nv(_p) atomic_add_int_nv((_p), 1) +#endif + +#ifndef atomic_inc_long_nv +#define atomic_inc_long_nv(_p) atomic_add_long_nv((_p), 1) +#endif + +/* + * atomic_inc_* - increment + */ + +#ifndef atomic_inc_int +#define atomic_inc_int(_p) ((void)atomic_inc_int_nv(_p)) +#endif + +#ifndef atomic_inc_long +#define atomic_inc_long(_p) ((void)atomic_inc_long_nv(_p)) +#endif + +/* + * atomic_sub_*_nv - sub and fetch + */ + +#ifndef atomic_sub_int_nv +static inline unsigned int +atomic_sub_int_nv(volatile unsigned int *p, unsigned int v) +{ + return __sync_sub_and_fetch(p, v); +} +#endif + +#ifndef atomic_sub_long_nv +static inline unsigned long +atomic_sub_long_nv(volatile unsigned long *p, unsigned long v) +{ + return __sync_sub_and_fetch(p, v); +} +#endif + +/* + * atomic_sub_* - sub + */ + +#ifndef atomic_sub_int +#define atomic_sub_int(_p, _v) ((void)atomic_sub_int_nv((_p), (_v))) +#endif + +#ifndef atomic_sub_long +#define atomic_sub_long(_p, _v) ((void)atomic_sub_long_nv((_p), (_v))) +#endif + +/* + * atomic_dec_*_nv - decrement and fetch + */ + +#ifndef atomic_dec_int_nv +#define atomic_dec_int_nv(_p) atomic_sub_int_nv((_p), 1) +#endif + +#ifndef atomic_dec_long_nv +#define atomic_dec_long_nv(_p) atomic_sub_long_nv((_p), 1) +#endif + +/* + * atomic_dec_* - decrement + */ + +#ifndef atomic_dec_int +#define atomic_dec_int(_p) ((void)atomic_dec_int_nv(_p)) +#endif + +#ifndef atomic_dec_long +#define atomic_dec_long(_p) ((void)atomic_dec_long_nv(_p)) +#endif + +#ifdef _KERNEL +/* + * atomic_load_* - read from memory + */ + +static inline unsigned int +atomic_load_int(volatile const unsigned int *p) +{ + return *p; +} + +static inline unsigned long +atomic_load_long(volatile const unsigned long *p) +{ + return *p; +} + +/* + * atomic_store_* - write to memory + */ + +static inline void +atomic_store_int(volatile unsigned int *p, unsigned int v) +{ + *p = v; +} + +static inline void +atomic_store_long(volatile unsigned long *p, unsigned long v) +{ + *p = v; +} +#endif /* _KERNEL */ + +/* + * memory barriers + */ + +#ifndef membar_enter +#define membar_enter() __sync_synchronize() +#endif + +#ifndef membar_exit +#define membar_exit() __sync_synchronize() +#endif + +#ifndef membar_producer +#define membar_producer() __sync_synchronize() +#endif + +#ifndef membar_consumer +#define membar_consumer() __sync_synchronize() +#endif + +#ifndef membar_sync +#define membar_sync() __sync_synchronize() +#endif + +#ifndef membar_enter_after_atomic +#define membar_enter_after_atomic() membar_enter() +#endif + +#ifndef membar_exit_before_atomic +#define membar_exit_before_atomic() membar_exit() +#endif + +#ifdef _KERNEL + +/* + * Force any preceding reads to happen before any subsequent reads that + * depend on the value returned by the preceding reads. + */ +static inline void +membar_datadep_consumer(void) +{ +#ifdef __alpha__ + membar_consumer(); +#endif +} + +#define READ_ONCE(x) ({ \ + typeof(x) __tmp = *(volatile typeof(x) *)&(x); \ + membar_datadep_consumer(); \ + __tmp; \ +}) + +#define WRITE_ONCE(x, val) ({ \ + typeof(x) __tmp = (val); \ + *(volatile typeof(x) *)&(x) = __tmp; \ + __tmp; \ +}) + +#endif /* _KERNEL */ + +#endif /* _SYS_ATOMIC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/audioio.h b/lib/libc/include/generic-openbsd/sys/audioio.h new file mode 100644 index 0000000000..b60da96834 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/audioio.h @@ -0,0 +1,231 @@ +/* $OpenBSD: audioio.h,v 1.27 2016/09/14 06:12:20 ratchov Exp $ */ +/* $NetBSD: audioio.h,v 1.24 1998/08/13 06:28:41 mrg Exp $ */ + +/* + * Copyright (c) 1991-1993 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Computer Systems + * Engineering Group at Lawrence Berkeley Laboratory. + * 4. Neither the name of the University nor of the Laboratory 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 _SYS_AUDIOIO_H_ +#define _SYS_AUDIOIO_H_ + +#define AUMODE_PLAY 0x01 +#define AUMODE_RECORD 0x02 + +#define AUDIO_INITPAR(p) \ + (void)memset((void *)(p), 0xff, sizeof(struct audio_swpar)) + +/* + * argument to AUDIO_SETPAR and AUDIO_GETPAR ioctls + */ +struct audio_swpar { + unsigned int sig; /* if 1, encoding is signed */ + unsigned int le; /* if 1, encoding is little-endian */ + unsigned int bits; /* bits per sample */ + unsigned int bps; /* bytes per sample */ + unsigned int msb; /* if 1, bits are msb-aligned */ + unsigned int rate; /* common play & rec sample rate */ + unsigned int pchan; /* play channels */ + unsigned int rchan; /* rec channels */ + unsigned int nblks; /* number of blocks in play buffer */ + unsigned int round; /* common frames per block */ + unsigned int _spare[6]; +}; + +/* + * argument to AUDIO_GETSTATUS + */ +struct audio_status { + int mode; + int pause; + int active; + int _spare[5]; +}; + +/* + * Parameter for the AUDIO_GETDEV ioctl to determine current + * audio devices. + */ +#define MAX_AUDIO_DEV_LEN 16 +typedef struct audio_device { + char name[MAX_AUDIO_DEV_LEN]; + char version[MAX_AUDIO_DEV_LEN]; + char config[MAX_AUDIO_DEV_LEN]; +} audio_device_t; + +struct audio_pos { + unsigned int play_pos; /* total bytes played */ + unsigned int play_xrun; /* bytes of silence inserted */ + unsigned int rec_pos; /* total bytes recorded */ + unsigned int rec_xrun; /* bytes dropped */ +}; + +/* + * Audio device operations + */ +#define AUDIO_GETDEV _IOR('A', 27, struct audio_device) +#define AUDIO_GETPOS _IOR('A', 35, struct audio_pos) +#define AUDIO_GETPAR _IOR('A', 36, struct audio_swpar) +#define AUDIO_SETPAR _IOWR('A', 37, struct audio_swpar) +#define AUDIO_START _IO('A', 38) +#define AUDIO_STOP _IO('A', 39) +#define AUDIO_GETSTATUS _IOR('A', 40, struct audio_status) + +/* + * Mixer device + */ +#define AUDIO_MIN_GAIN 0 +#define AUDIO_MAX_GAIN 255 + +typedef struct mixer_level { + int num_channels; + u_char level[8]; /* [num_channels] */ +} mixer_level_t; +#define AUDIO_MIXER_LEVEL_MONO 0 +#define AUDIO_MIXER_LEVEL_LEFT 0 +#define AUDIO_MIXER_LEVEL_RIGHT 1 + +/* + * Device operations + */ + +typedef struct audio_mixer_name { + char name[MAX_AUDIO_DEV_LEN]; + int msg_id; +} audio_mixer_name_t; + +typedef struct mixer_devinfo { + int index; + audio_mixer_name_t label; + int type; +#define AUDIO_MIXER_CLASS 0 +#define AUDIO_MIXER_ENUM 1 +#define AUDIO_MIXER_SET 2 +#define AUDIO_MIXER_VALUE 3 + int mixer_class; + int next, prev; +#define AUDIO_MIXER_LAST -1 + union { + struct audio_mixer_enum { + int num_mem; + struct { + audio_mixer_name_t label; + int ord; + } member[32]; + } e; + struct audio_mixer_set { + int num_mem; + struct { + audio_mixer_name_t label; + int mask; + } member[32]; + } s; + struct audio_mixer_value { + audio_mixer_name_t units; + int num_channels; + int delta; + } v; + } un; +} mixer_devinfo_t; + + +typedef struct mixer_ctrl { + int dev; + int type; + union { + int ord; /* enum */ + int mask; /* set */ + mixer_level_t value; /* value */ + } un; +} mixer_ctrl_t; + +/* + * Mixer operations + */ +#define AUDIO_MIXER_READ _IOWR('M', 0, mixer_ctrl_t) +#define AUDIO_MIXER_WRITE _IOWR('M', 1, mixer_ctrl_t) +#define AUDIO_MIXER_DEVINFO _IOWR('M', 2, mixer_devinfo_t) + +/* + * Well known device names + */ +#define AudioNmicrophone "mic" +#define AudioNline "line" +#define AudioNcd "cd" +#define AudioNdac "dac" +#define AudioNaux "aux" +#define AudioNrecord "record" +#define AudioNvolume "volume" +#define AudioNmonitor "monitor" +#define AudioNtreble "treble" +#define AudioNmid "mid" +#define AudioNbass "bass" +#define AudioNbassboost "bassboost" +#define AudioNspeaker "spkr" +#define AudioNheadphone "hp" +#define AudioNoutput "output" +#define AudioNinput "input" +#define AudioNmaster "master" +#define AudioNstereo "stereo" +#define AudioNmono "mono" +#define AudioNloudness "loudness" +#define AudioNspatial "spatial" +#define AudioNsurround "surround" +#define AudioNpseudo "pseudo" +#define AudioNmute "mute" +#define AudioNenhanced "enhanced" +#define AudioNpreamp "preamp" +#define AudioNon "on" +#define AudioNoff "off" +#define AudioNmode "mode" +#define AudioNsource "source" +#define AudioNfmsynth "fmsynth" +#define AudioNwave "wave" +#define AudioNmidi "midi" +#define AudioNmixerout "mixerout" +#define AudioNswap "swap" /* swap left and right channels */ +#define AudioNagc "agc" +#define AudioNdelay "delay" +#define AudioNselect "select" /* select destination */ +#define AudioNvideo "video" +#define AudioNcenter "center" +#define AudioNdepth "depth" +#define AudioNlfe "lfe" +#define AudioNextamp "extamp" + +#define AudioCinputs "inputs" +#define AudioCoutputs "outputs" +#define AudioCrecord "record" +#define AudioCmonitor "monitor" +#define AudioCequalization "equalization" + +#endif /* !_SYS_AUDIOIO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/auxv.h b/lib/libc/include/generic-openbsd/sys/auxv.h new file mode 100644 index 0000000000..0a822654e8 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/auxv.h @@ -0,0 +1,50 @@ +/* $OpenBSD: auxv.h,v 1.1 2024/07/14 09:48:49 jca Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2017 Michal Meloun + * 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 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 AUTHOR 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 _SYS_AUXV_H_ +#define _SYS_AUXV_H_ + +#include +#include + +/* Values for a_type. */ +#define AT_NULL 0 /* Terminates the vector. */ +#define AT_IGNORE 1 /* Ignored entry. */ +#define AT_PAGESZ 6 /* Page size in bytes. */ +#define AT_HWCAP 25 /* CPU feature flags. */ +#define AT_HWCAP2 26 /* CPU feature flags 2. */ + +#define AT_COUNT 27 /* Count of defined aux entry types. */ + +__BEGIN_DECLS +int elf_aux_info(int aux, void *buf, int buflen); +__END_DECLS + +#endif /* !_SYS_AUXV_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/blist.h b/lib/libc/include/generic-openbsd/sys/blist.h new file mode 100644 index 0000000000..2cb91dee5f --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/blist.h @@ -0,0 +1,137 @@ +/* $OpenBSD: blist.h,v 1.2 2022/08/06 13:44:04 semarie Exp $ */ +/* DragonFlyBSD:7b80531f545c7d3c51c1660130c71d01f6bccbe0:/sys/sys/blist.h */ +/* + * Copyright (c) 2003,2004 The DragonFly Project. All rights reserved. + * + * This code is derived from software contributed to The DragonFly Project + * by Matthew Dillon + * + * 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 DragonFly Project 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT HOLDERS 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. + * + * Implements bitmap resource lists. + * + * Usage: + * blist = blist_create(blocks) + * (void) blist_destroy(blist) + * blkno = blist_alloc(blist, count) + * (void) blist_free(blist, blkno, count) + * nblks = blist_fill(blist, blkno, count) + * (void) blist_resize(&blist, count, freeextra) + * + * + * Notes: + * on creation, the entire list is marked reserved. You should + * first blist_free() the sections you want to make available + * for allocation before doing general blist_alloc()/free() + * ops. + * + * SWAPBLK_NONE is returned on failure. This module is typically + * capable of managing up to (2^31) blocks per blist, though + * the memory utilization would be insane if you actually did + * that. Managing something like 512MB worth of 4K blocks + * eats around 32 KBytes of memory. + * + * $FreeBSD: src/sys/sys/blist.h,v 1.2.2.1 2003/01/12 09:23:12 dillon Exp $ + */ + +#ifndef _SYS_BLIST_H_ +#define _SYS_BLIST_H_ + +#ifndef _SYS_TYPES_H_ +#include +#endif + +typedef u_long swblk_t; +typedef u_int64_t u_swblk_t; + +/* + * note: currently use SWAPBLK_NONE as an absolute value rather then + * a flag bit. + */ +#define SWAPBLK_NONE ((swblk_t)-1) + +/* + * blmeta and bl_bitmap_t MUST be a power of 2 in size. + */ + +typedef struct blmeta { + union { + swblk_t bmu_avail; /* space available under us */ + u_swblk_t bmu_bitmap; /* bitmap if we are a leaf */ + } u; + swblk_t bm_bighint; /* biggest contiguous block hint*/ +} blmeta_t; + +typedef struct blist { + swblk_t bl_blocks; /* area of coverage */ + /* XXX int64_t bl_radix */ + swblk_t bl_radix; /* coverage radix */ + swblk_t bl_skip; /* starting skip */ + swblk_t bl_free; /* number of free blocks */ + blmeta_t *bl_root; /* root of radix tree */ + swblk_t bl_rootblks; /* swblk_t blks allocated for tree */ +} *blist_t; + +#define BLIST_META_RADIX (sizeof(u_swblk_t)*8/2) /* 2 bits per */ +#define BLIST_BMAP_RADIX (sizeof(u_swblk_t)*8) /* 1 bit per */ + +/* + * The radix may exceed the size of a 64 bit signed (or unsigned) int + * when the maximal number of blocks is allocated. With a 32-bit swblk_t + * this corresponds to ~1G x PAGE_SIZE = 4096GB. The swap code usually + * divides this by 4, leaving us with a capability of up to four 1TB swap + * devices. + * + * With a 64-bit swblk_t the limitation is some insane number. + * + * NOTE: For now I don't trust that we overflow-detect properly so we divide + * out to ensure that no overflow occurs. + */ + +#if defined(_LP64) +/* swblk_t 64bits */ +#define BLIST_MAXBLKS (0x4000000000000000LL / \ + (BLIST_BMAP_RADIX / BLIST_META_RADIX)) +#else +#define BLIST_MAXBLKS (0x40000000 / \ + (BLIST_BMAP_RADIX / BLIST_META_RADIX)) +#endif + +#define BLIST_MAX_ALLOC BLIST_BMAP_RADIX + +blist_t blist_create(swblk_t); +void blist_destroy(blist_t); +swblk_t blist_alloc(blist_t, swblk_t); +swblk_t blist_allocat(blist_t, swblk_t, swblk_t); +void blist_free(blist_t, swblk_t, swblk_t); +swblk_t blist_fill(blist_t, swblk_t, swblk_t); +void blist_print(blist_t); +void blist_resize(blist_t *, swblk_t, int); +void blist_gapfind(blist_t, swblk_t *, swblk_t *); + +#endif /* _SYS_BLIST_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/buf.h b/lib/libc/include/generic-openbsd/sys/buf.h new file mode 100644 index 0000000000..864be56101 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/buf.h @@ -0,0 +1,303 @@ +/* $OpenBSD: buf.h,v 1.120 2025/08/14 16:13:52 beck Exp $ */ +/* $NetBSD: buf.h,v 1.25 1997/04/09 21:12:17 mycroft Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)buf.h 8.7 (Berkeley) 1/21/94 + */ + +#ifndef _SYS_BUF_H_ +#define _SYS_BUF_H_ +#include +#include +#include +#include + +#define NOLIST ((struct buf *)0x87654321) + +struct buf; +struct vnode; + +LIST_HEAD(bufhead, buf); + +/* + * Buffer queues + */ +#define BUFQ_NSCAN_N 128 +#define BUFQ_FIFO 0 +#define BUFQ_NSCAN 1 +#define BUFQ_DEFAULT BUFQ_NSCAN +#define BUFQ_HOWMANY 2 + +/* + * Write limits for bufq - defines high and low water marks for how + * many kva slots are allowed to be consumed to parallelize writes from + * the buffer cache from any individual bufq. + */ +#define BUFQ_HI 128 +#define BUFQ_LOW 64 + +struct bufq_impl; + +struct bufq { + SLIST_ENTRY(bufq) bufq_entries; + struct mutex bufq_mtx; + void *bufq_data; + u_int bufq_outstanding; + u_int bufq_hi; + u_int bufq_low; + int bufq_waiting; + int bufq_stop; + int bufq_type; + const struct bufq_impl *bufq_impl; +}; + +int bufq_init(struct bufq *, int); +void bufq_destroy(struct bufq *); + +void bufq_queue(struct bufq *, struct buf *); +struct buf *bufq_dequeue(struct bufq *); +int bufq_peek(struct bufq *); +void bufq_drain(struct bufq *); + +void bufq_wait(struct bufq *); +void bufq_done(struct bufq *, struct buf *); +void bufq_quiesce(void); +void bufq_restart(void); + +/* fifo */ +SIMPLEQ_HEAD(bufq_fifo_head, buf); +struct bufq_fifo { + SIMPLEQ_ENTRY(buf) bqf_entries; +}; + +/* nscan */ +SIMPLEQ_HEAD(bufq_nscan_head, buf); +struct bufq_nscan { + SIMPLEQ_ENTRY(buf) bqf_entries; +}; + +/* bufq link in struct buf */ +union bufq_data { + struct bufq_fifo bufq_data_fifo; + struct bufq_nscan bufq_data_nscan; +}; + +/* The buffer header describes an I/O operation in the kernel. */ +struct buf { + RBT_ENTRY(buf) b_rbbufs; /* vnode "hash" tree */ + LIST_ENTRY(buf) b_list; /* All allocated buffers. */ + LIST_ENTRY(buf) b_vnbufs; /* Buffer's associated vnode. */ + TAILQ_ENTRY(buf) b_freelist; /* Free list position if not active. */ + int cache; /* which cache are we in */ + struct proc *b_proc; /* Associated proc; NULL if kernel. */ + volatile long b_flags; /* B_* flags. */ + long b_bufsize; /* Allocated buffer size. */ + long b_bcount; /* Valid bytes in buffer. */ + size_t b_resid; /* Remaining I/O. */ + int b_error; /* Errno value. */ + dev_t b_dev; /* Device associated with buffer. */ + caddr_t b_data; /* associated data */ + void *b_saveaddr; /* Original b_data for physio. */ + + TAILQ_ENTRY(buf) b_valist; /* LRU of va to reuse. */ + + union bufq_data b_bufq; + struct bufq *b_bq; /* What bufq this buf is on */ + + struct uvm_object *b_pobj; + struct uvm_object b_uobj; /* Object containing the pages */ + off_t b_poffs; /* Offset within object */ + + daddr_t b_lblkno; /* Logical block number. */ + daddr_t b_blkno; /* Underlying physical block number. */ + /* Function to call upon completion. + * Will be called at splbio(). */ + void (*b_iodone)(struct buf *); + struct vnode *b_vp; /* Device vnode. */ + int b_dirtyoff; /* Offset in buffer of dirty region. */ + int b_dirtyend; /* Offset of end of dirty region. */ + int b_validoff; /* Offset in buffer of valid region. */ + int b_validend; /* Offset of end of valid region. */ +}; + +TAILQ_HEAD(bufqueue, buf); + +struct bufcache { + int64_t hotbufpages; + int64_t warmbufpages; + int64_t cachepages; + struct bufqueue hotqueue; + struct bufqueue coldqueue; + struct bufqueue warmqueue; +}; + +/* + * These flags are kept in b_flags. + */ +#define B_WRITE 0x00000000 /* Write buffer (pseudo flag). */ +#define B_AGE 0x00000001 /* Move to age queue when I/O done. */ +#define B_NEEDCOMMIT 0x00000002 /* Needs committing to stable storage */ +#define B_ASYNC 0x00000004 /* Start I/O, do not wait. */ +#define B_BAD 0x00000008 /* Bad block revectoring in progress. */ +#define B_BUSY 0x00000010 /* I/O in progress. */ +#define B_CACHE 0x00000020 /* Bread found us in the cache. */ +#define B_CALL 0x00000040 /* Call b_iodone from biodone. */ +#define B_DELWRI 0x00000080 /* Delay I/O until buffer reused. */ +#define B_DONE 0x00000100 /* I/O completed. */ +#define B_EINTR 0x00000200 /* I/O was interrupted */ +#define B_ERROR 0x00000400 /* I/O error occurred. */ +#define B_INVAL 0x00000800 /* Does not contain valid info. */ +#define B_NOCACHE 0x00001000 /* Do not cache block after use. */ +#define B_PHYS 0x00002000 /* I/O to user memory. */ +#define B_RAW 0x00004000 /* Set by physio for raw transfers. */ +#define B_READ 0x00008000 /* Read buffer. */ +#define B_WANTED 0x00010000 /* Process wants this buffer. */ +#define B_WRITEINPROG 0x00020000 /* Write in progress. */ +#define B_XXX 0x00040000 /* Debugging flag. */ +#define B_DEFERRED 0x00080000 /* Skipped over for cleaning */ +#define B_SCANNED 0x00100000 /* Block already pushed during sync */ +#define B_PDAEMON 0x00200000 /* I/O started by pagedaemon */ +#define B_RELEASED 0x00400000 /* free this buffer after its kvm */ +#define B_WARM 0x00800000 /* buffer is or has been on the warm queue */ +#define B_COLD 0x01000000 /* buffer is on the cold queue */ +#define B_BC 0x02000000 /* buffer is managed by the cache */ +#define B_DMA 0x04000000 /* buffer is DMA reachable */ + +#define B_BITS "\20\001AGE\002NEEDCOMMIT\003ASYNC\004BAD\005BUSY" \ + "\006CACHE\007CALL\010DELWRI\011DONE\012EINTR\013ERROR" \ + "\014INVAL\015NOCACHE\016PHYS\017RAW\020READ" \ + "\021WANTED\022WRITEINPROG\023XXX(FORMAT)\024DEFERRED" \ + "\025SCANNED\026DAEMON\027RELEASED\030WARM\031COLD\032BC\033DMA" + +/* + * Zero out the buffer's data area. + */ +#define clrbuf(bp) { \ + bzero((bp)->b_data, (bp)->b_bcount); \ + (bp)->b_resid = 0; \ +} + + +/* Flags to low-level allocation routines. */ +#define B_CLRBUF 0x01 /* Request allocated buffer be cleared. */ +#define B_SYNC 0x02 /* Do all allocations synchronously. */ + +struct cluster_info { + daddr_t ci_lastr; /* last read (read-ahead) */ + daddr_t ci_lastw; /* last write (write cluster) */ + daddr_t ci_cstart; /* start block of cluster */ + daddr_t ci_lasta; /* last allocation */ + int ci_clen; /* length of current cluster */ + int ci_ralen; /* Read-ahead length */ + daddr_t ci_maxra; /* last readahead block */ +}; + +#ifdef _KERNEL +__BEGIN_DECLS +/* Kva slots (of size MAXPHYS) reserved for syncer and cleaner. */ +#define RESERVE_SLOTS 4 +/* Buffer cache pages reserved for syncer and cleaner. */ +#define RESERVE_PAGES (RESERVE_SLOTS * MAXPHYS / PAGE_SIZE) +/* Minimum size of the buffer cache, in pages. */ +#define BCACHE_MIN (RESERVE_PAGES * 2) +#define UNCLEAN_PAGES (bcstats.numbufpages - bcstats.numcleanpages) + +extern struct proc *cleanerproc; +extern long bufpages; /* Max number of pages for buffers' data */ +extern struct pool bufpool; +extern struct bufhead bufhead; + +void bawrite(struct buf *); +void bdwrite(struct buf *); +void biodone(struct buf *); +int biowait(struct buf *); +int bread(struct vnode *, daddr_t, int, struct buf **); +int breadn(struct vnode *, daddr_t, int, daddr_t *, int *, int, + struct buf **); +void brelse(struct buf *); +void bufinit(void); +void buf_dirty(struct buf *); +void buf_undirty(struct buf *); +void buf_adjcnt(struct buf *, long); +int bwrite(struct buf *); +struct buf *getblk(struct vnode *, daddr_t, int, int, uint64_t); +struct buf *geteblk(size_t); +struct buf *incore(struct vnode *, daddr_t); + +/* + * bufcache functions + */ +void bufcache_take(struct buf *); +void bufcache_release(struct buf *); + +int buf_flip_high(struct buf *); +void buf_flip_dma(struct buf *); +struct buf *bufcache_getcleanbuf(int, int); +struct buf *bufcache_getdirtybuf(void); + +/* + * buf_kvm_init initializes the kvm handling for buffers. + * buf_acquire sets the B_BUSY flag and ensures that the buffer is + * mapped in the kvm. + * buf_release clears the B_BUSY flag and allows the buffer to become + * unmapped. + * buf_unmap is for internal use only. Unmaps the buffer from kvm. + */ +void buf_mem_init(vsize_t); +void buf_acquire(struct buf *); +void buf_acquire_nomap(struct buf *); +void buf_map(struct buf *); +void buf_release(struct buf *); +int buf_dealloc_mem(struct buf *); +void buf_fix_mapping(struct buf *, vsize_t); +void buf_alloc_pages(struct buf *, vsize_t); +void buf_free_pages(struct buf *); +int buf_realloc_pages(struct buf *, struct uvm_constraint_range *, int); + +void minphys(struct buf *bp); +int physio(void (*strategy)(struct buf *), dev_t dev, int flags, + void (*minphys)(struct buf *), struct uio *uio); +void brelvp(struct buf *); +void reassignbuf(struct buf *); +void bgetvp(struct vnode *, struct buf *); + +void buf_replacevnode(struct buf *, struct vnode *); +void buf_daemon(void *); +void buf_replacevnode(struct buf *, struct vnode *); +int bread_cluster(struct vnode *, daddr_t, int, struct buf **); + +__END_DECLS +#endif /* _KERNEL */ +#endif /* !_SYS_BUF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/cdefs.h b/lib/libc/include/generic-openbsd/sys/cdefs.h new file mode 100644 index 0000000000..2273af8568 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/cdefs.h @@ -0,0 +1,434 @@ +/* $OpenBSD: cdefs.h,v 1.45 2025/05/13 15:16:43 millert Exp $ */ +/* $NetBSD: cdefs.h,v 1.16 1996/04/03 20:46:39 christos Exp $ */ + +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Berkeley Software Design, Inc. + * + * 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. + * + * @(#)cdefs.h 8.7 (Berkeley) 1/21/94 + */ + +#ifndef _SYS_CDEFS_H_ +#define _SYS_CDEFS_H_ + +#include + +/* + * Macro to test if we're using a specific version of gcc or later. + */ +#ifdef __GNUC__ +#define __GNUC_PREREQ__(ma, mi) \ + ((__GNUC__ > (ma)) || (__GNUC__ == (ma) && __GNUC_MINOR__ >= (mi))) +#else +#define __GNUC_PREREQ__(ma, mi) 0 +#endif + +/* + * The __CONCAT macro is used to concatenate parts of symbol names, e.g. + * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. + * The __CONCAT macro is a bit tricky -- make sure you don't put spaces + * in between its arguments. Do not use __CONCAT on double-quoted strings, + * such as those from the __STRING macro: to concatenate strings just put + * them next to each other. + */ +#if defined(__STDC__) || defined(__cplusplus) +#define __P(protos) protos /* full-blown ANSI C */ +#define __CONCAT(x,y) x ## y +#define __STRING(x) #x + +#define __const const /* define reserved names to standard */ +#define __signed signed +#define __volatile volatile +#if defined(__cplusplus) || defined(__PCC__) +#define __inline inline /* convert to C++ keyword */ +#else +#if !defined(__GNUC__) +#define __inline /* delete GCC keyword */ +#endif /* !__GNUC__ */ +#endif /* !__cplusplus */ + +#else /* !(__STDC__ || __cplusplus) */ +#define __P(protos) () /* traditional C preprocessor */ +#define __CONCAT(x,y) x/**/y +#define __STRING(x) "x" + +#if !defined(__GNUC__) +#define __const /* delete pseudo-ANSI C keywords */ +#define __inline +#define __signed +#define __volatile +#endif /* !__GNUC__ */ +#endif /* !(__STDC__ || __cplusplus) */ + +/* + * GCC1 and some versions of GCC2 declare dead (non-returning) and + * pure (no side effects) functions using "volatile" and "const"; + * unfortunately, these then cause warnings under "-ansi -pedantic". + * GCC >= 2.5 uses the __attribute__((attrs)) style. All of these + * work for GNU C++ (modulo a slight glitch in the C++ grammar in + * the distribution version of 2.5.5). + * + * GCC defines a pure function as depending only on its arguments and + * global variables. Typical examples are strlen and sqrt. + */ + +#if !__GNUC_PREREQ__(2, 5) && !defined(__PCC__) +#define __attribute__(x) /* delete __attribute__ if non-gcc or gcc1 */ +#endif + +#if __GNUC_PREREQ__(2, 5) +#define __dead __attribute__((__noreturn__)) +#elif defined(__GNUC__) +#define __dead __volatile +#else +#define __dead /* delete */ +#endif + +#if __GNUC_PREREQ__(2, 96) +#define __pure __attribute__((__pure__)) +#elif defined(__GNUC__) +#define __pure __const +#else +#define __pure /* delete */ +#endif + +#if __GNUC_PREREQ__(2, 7) +#define __unused __attribute__((__unused__)) +#else +#define __unused /* delete */ +#endif + +#if __GNUC_PREREQ__(3, 1) +#define __used __attribute__((__used__)) +#else +#define __used __unused /* suppress -Wunused warnings */ +#endif + +#if __GNUC_PREREQ__(3,4) +# define __warn_unused_result __attribute__((__warn_unused_result__)) +#else +# define __warn_unused_result /* delete */ +#endif + +#if __GNUC_PREREQ__(3,3) && !defined(__clang__) +# define __bounded(args) __attribute__ ((__bounded__ args )) +#else +# define __bounded(args) /* delete */ +#endif + +/* + * __returns_twice makes the compiler not assume the function + * only returns once. This affects registerisation of variables: + * even local variables need to be in memory across such a call. + * Example: setjmp() + */ +#if __GNUC_PREREQ__(4, 1) +#define __returns_twice __attribute__((returns_twice)) +#else +#define __returns_twice +#endif + +/* + * __only_inline makes the compiler only use this function definition + * for inlining; references that can't be inlined will be left as + * external references instead of generating a local copy. The + * matching library should include a simple extern definition for + * the function to handle those references. c.f. ctype.h + */ +#ifdef __GNUC__ +# if __GNUC_PREREQ__(4, 2) +#define __only_inline extern __inline __attribute__((__gnu_inline__)) +# else +#define __only_inline extern __inline +# endif +#else +#define __only_inline static __inline +#endif + +/* + * GNU C version 2.96 adds explicit branch prediction so that + * the CPU back-end can hint the processor and also so that + * code blocks can be reordered such that the predicted path + * sees a more linear flow, thus improving cache behavior, etc. + * + * The following two macros provide us with a way to utilize this + * compiler feature. Use __predict_true() if you expect the expression + * to evaluate to true, and __predict_false() if you expect the + * expression to evaluate to false. + * + * A few notes about usage: + * + * * Generally, __predict_false() error condition checks (unless + * you have some _strong_ reason to do otherwise, in which case + * document it), and/or __predict_true() `no-error' condition + * checks, assuming you want to optimize for the no-error case. + * + * * Other than that, if you don't know the likelihood of a test + * succeeding from empirical or other `hard' evidence, don't + * make predictions. + * + * * These are meant to be used in places that are run `a lot'. + * It is wasteful to make predictions in code that is run + * seldomly (e.g. at subsystem initialization time) as the + * basic block reordering that this affects can often generate + * larger code. + */ +#if __GNUC_PREREQ__(2, 96) +#define __predict_true(exp) __builtin_expect(((exp) != 0), 1) +#define __predict_false(exp) __builtin_expect(((exp) != 0), 0) +#else +#define __predict_true(exp) ((exp) != 0) +#define __predict_false(exp) ((exp) != 0) +#endif + +/* Delete pseudo-keywords wherever they are not available or needed. */ +#ifndef __dead +#define __dead +#define __pure +#endif + +/* + * The __packed macro indicates that a variable or structure members + * should have the smallest possible alignment, despite any host CPU + * alignment requirements. + * + * The __aligned(x) macro specifies the minimum alignment of a + * variable or structure. + * + * These macros together are useful for describing the layout and + * alignment of messages exchanged with hardware or other systems. + */ + +#if __GNUC_PREREQ__(2, 7) || defined(__PCC__) +#define __packed __attribute__((__packed__)) +#define __aligned(x) __attribute__((__aligned__(x))) +#endif + +#if !__GNUC_PREREQ__(2, 8) +#define __extension__ +#endif + +#if __GNUC_PREREQ__(3, 0) +#define __malloc __attribute__((__malloc__)) +#else +#define __malloc +#endif + +#if defined(__cplusplus) +#define __BEGIN_EXTERN_C extern "C" { +#define __END_EXTERN_C } +#else +#define __BEGIN_EXTERN_C +#define __END_EXTERN_C +#endif + +#if __GNUC_PREREQ__(4, 0) +#define __dso_public __attribute__((__visibility__("default"))) +#define __dso_hidden __attribute__((__visibility__("hidden"))) +#define __BEGIN_PUBLIC_DECLS \ + _Pragma("GCC visibility push(default)") __BEGIN_EXTERN_C +#define __END_PUBLIC_DECLS __END_EXTERN_C _Pragma("GCC visibility pop") +#define __BEGIN_HIDDEN_DECLS \ + _Pragma("GCC visibility push(hidden)") __BEGIN_EXTERN_C +#define __END_HIDDEN_DECLS __END_EXTERN_C _Pragma("GCC visibility pop") +#else +#define __dso_public +#define __dso_hidden +#define __BEGIN_PUBLIC_DECLS __BEGIN_EXTERN_C +#define __END_PUBLIC_DECLS __END_EXTERN_C +#define __BEGIN_HIDDEN_DECLS __BEGIN_EXTERN_C +#define __END_HIDDEN_DECLS __END_EXTERN_C +#endif + +#define __BEGIN_DECLS __BEGIN_EXTERN_C +#define __END_DECLS __END_EXTERN_C + +/* + * "The nice thing about standards is that there are so many to choose from." + * There are a number of "feature test macros" specified by (different) + * standards that determine which interfaces and types the header files + * should expose. + * + * Because of inconsistencies in these macros, we define our own + * set in the private name space that end in _VISIBLE. These are + * always defined and so headers can test their values easily. + * Things can get tricky when multiple feature macros are defined. + * We try to take the union of all the features requested. + * + * The following macros are guaranteed to have a value after cdefs.h + * has been included: + * __POSIX_VISIBLE + * __XPG_VISIBLE + * __ISO_C_VISIBLE + * __BSD_VISIBLE + */ + +/* + * X/Open Portability Guides and Single Unix Specifications. + * _XOPEN_SOURCE XPG3 + * _XOPEN_SOURCE && _XOPEN_VERSION = 4 XPG4 + * _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED = 1 XPG4v2 + * _XOPEN_SOURCE == 500 XPG5 + * _XOPEN_SOURCE == 520 XPG5v2 + * _XOPEN_SOURCE == 600 POSIX 1003.1-2001 with XSI + * _XOPEN_SOURCE == 700 POSIX 1003.1-2008 with XSI + * _XOPEN_SOURCE == 800 POSIX 1003.1-2024 with XSI + * + * The XPG spec implies a specific value for _POSIX_C_SOURCE. + */ +#ifdef _XOPEN_SOURCE +# if (_XOPEN_SOURCE - 0 >= 800) +# define __XPG_VISIBLE 800 +# undef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 202405L +# elif (_XOPEN_SOURCE - 0 >= 700) +# define __XPG_VISIBLE 700 +# undef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 200809L +# elif (_XOPEN_SOURCE - 0 >= 600) +# define __XPG_VISIBLE 600 +# undef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 200112L +# elif (_XOPEN_SOURCE - 0 >= 520) +# define __XPG_VISIBLE 520 +# undef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 199506L +# elif (_XOPEN_SOURCE - 0 >= 500) +# define __XPG_VISIBLE 500 +# undef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 199506L +# elif (_XOPEN_SOURCE_EXTENDED - 0 == 1) +# define __XPG_VISIBLE 420 +# elif (_XOPEN_VERSION - 0 >= 4) +# define __XPG_VISIBLE 400 +# else +# define __XPG_VISIBLE 300 +# endif +#endif + +/* + * POSIX macros, these checks must follow the XOPEN ones above. + * + * _POSIX_SOURCE == 1 1003.1-1988 (superseded by _POSIX_C_SOURCE) + * _POSIX_C_SOURCE == 1 1003.1-1990 + * _POSIX_C_SOURCE == 2 1003.2-1992 + * _POSIX_C_SOURCE == 199309L 1003.1b-1993 + * _POSIX_C_SOURCE == 199506L 1003.1c-1995, 1003.1i-1995, + * and the omnibus ISO/IEC 9945-1:1996 + * _POSIX_C_SOURCE == 200112L 1003.1-2001 + * _POSIX_C_SOURCE == 200809L 1003.1-2008 + * _POSIX_C_SOURCE == 202405L 1003.1-2024 + * + * The POSIX spec implies a specific value for __ISO_C_VISIBLE, though + * this may be overridden by the _ISOC99_SOURCE macro later. + */ +#ifdef _POSIX_C_SOURCE +# if (_POSIX_C_SOURCE - 0 >= 202405) +# define __POSIX_VISIBLE 202405 +# define __ISO_C_VISIBLE 2017 +# elif (_POSIX_C_SOURCE - 0 >= 200809) +# define __POSIX_VISIBLE 200809 +# define __ISO_C_VISIBLE 1999 +# elif (_POSIX_C_SOURCE - 0 >= 200112) +# define __POSIX_VISIBLE 200112 +# define __ISO_C_VISIBLE 1999 +# elif (_POSIX_C_SOURCE - 0 >= 199506) +# define __POSIX_VISIBLE 199506 +# define __ISO_C_VISIBLE 1990 +# elif (_POSIX_C_SOURCE - 0 >= 199309) +# define __POSIX_VISIBLE 199309 +# define __ISO_C_VISIBLE 1990 +# elif (_POSIX_C_SOURCE - 0 >= 2) +# define __POSIX_VISIBLE 199209 +# define __ISO_C_VISIBLE 1990 +# else +# define __POSIX_VISIBLE 199009 +# define __ISO_C_VISIBLE 1990 +# endif +#elif defined(_POSIX_SOURCE) +# define __POSIX_VISIBLE 198808 +# define __ISO_C_VISIBLE 0 +#endif + +/* + * _ANSI_SOURCE means to expose ANSI C89 interfaces only. + * If the user defines it in addition to one of the POSIX or XOPEN + * macros, assume the POSIX/XOPEN macro(s) should take precedence. + */ +#if defined(_ANSI_SOURCE) && !defined(__POSIX_VISIBLE) && \ + !defined(__XPG_VISIBLE) +# define __POSIX_VISIBLE 0 +# define __XPG_VISIBLE 0 +# define __ISO_C_VISIBLE 1990 +#endif + +/* + * _ISOC99_SOURCE, _ISOC11_SOURCE, __STDC_VERSION__, and __cplusplus + * override any of the other macros since they are non-exclusive. + */ +#if defined(_ISOC11_SOURCE) || \ + (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112) || \ + (defined(__cplusplus) && __cplusplus >= 201703) +# undef __ISO_C_VISIBLE +# define __ISO_C_VISIBLE 2011 +#elif defined(_ISOC99_SOURCE) || \ + (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901) || \ + (defined(__cplusplus) && __cplusplus >= 201103) +# undef __ISO_C_VISIBLE +# define __ISO_C_VISIBLE 1999 +#endif + +/* + * Finally deal with BSD-specific interfaces that are not covered + * by any standards. We expose these when none of the POSIX or XPG + * macros is defined or if the user explicitly asks for them. + */ +#if !defined(_BSD_SOURCE) && \ + (defined(_ANSI_SOURCE) || defined(__XPG_VISIBLE) || defined(__POSIX_VISIBLE)) +# define __BSD_VISIBLE 0 +#endif + +/* + * Default values. + */ +#ifndef __XPG_VISIBLE +# define __XPG_VISIBLE 800 +#endif +#ifndef __POSIX_VISIBLE +# define __POSIX_VISIBLE 202405 +#endif +#ifndef __ISO_C_VISIBLE +# define __ISO_C_VISIBLE 2017 +#endif +#ifndef __BSD_VISIBLE +# define __BSD_VISIBLE 1 +#endif + +#endif /* !_SYS_CDEFS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/cdio.h b/lib/libc/include/generic-openbsd/sys/cdio.h new file mode 100644 index 0000000000..ee88041d66 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/cdio.h @@ -0,0 +1,435 @@ +/* $OpenBSD: cdio.h,v 1.17 2017/10/24 09:36:13 jsg Exp $ */ +/* $NetBSD: cdio.h,v 1.11 1996/02/19 18:29:04 scottr Exp $ */ + +#ifndef _SYS_CDIO_H_ +#define _SYS_CDIO_H_ + +#include +#include + +/* Shared between kernel & process */ + +union msf_lba { + struct { + u_char unused; + u_char minute; + u_char second; + u_char frame; + } msf; + u_int32_t lba; + u_char addr[4]; +}; + +struct cd_toc_entry { + u_char nothing1; +#if _BYTE_ORDER == _LITTLE_ENDIAN + u_int control:4; + u_int addr_type:4; +#endif +#if _BYTE_ORDER == _BIG_ENDIAN + u_int addr_type:4; + u_int control:4; +#endif + u_char track; + u_char nothing2; + union msf_lba addr; +}; + +struct cd_sub_channel_header { + u_char nothing1; + u_char audio_status; +#define CD_AS_AUDIO_INVALID 0x00 +#define CD_AS_PLAY_IN_PROGRESS 0x11 +#define CD_AS_PLAY_PAUSED 0x12 +#define CD_AS_PLAY_COMPLETED 0x13 +#define CD_AS_PLAY_ERROR 0x14 +#define CD_AS_NO_STATUS 0x15 + u_char data_len[2]; +}; + +struct cd_sub_channel_q_data { + u_char data_format; +#if _BYTE_ORDER == _LITTLE_ENDIAN + u_int control:4; + u_int addr_type:4; +#endif +#if _BYTE_ORDER == _BIG_ENDIAN + u_int addr_type:4; + u_int control:4; +#endif + u_char track_number; + u_char index_number; + u_char absaddr[4]; + u_char reladdr[4]; +#if _BYTE_ORDER == _LITTLE_ENDIAN + u_int :7; + u_int mc_valid:1; +#endif +#if _BYTE_ORDER == _BIG_ENDIAN + u_int mc_valid:1; + u_int :7; +#endif + u_char mc_number[15]; +#if _BYTE_ORDER == _LITTLE_ENDIAN + u_int :7; + u_int ti_valid:1; +#endif +#if _BYTE_ORDER == _BIG_ENDIAN + u_int ti_valid:1; + u_int :7; +#endif + u_char ti_number[15]; +}; + +struct cd_sub_channel_position_data { + u_char data_format; +#if _BYTE_ORDER == _LITTLE_ENDIAN + u_int control:4; + u_int addr_type:4; +#endif +#if _BYTE_ORDER == _BIG_ENDIAN + u_int addr_type:4; + u_int control:4; +#endif + u_char track_number; + u_char index_number; + union msf_lba absaddr; + union msf_lba reladdr; +}; + +struct cd_sub_channel_media_catalog { + u_char data_format; + u_char nothing1; + u_char nothing2; + u_char nothing3; +#if _BYTE_ORDER == _LITTLE_ENDIAN + u_int :7; + u_int mc_valid:1; +#endif +#if _BYTE_ORDER == _BIG_ENDIAN + u_int mc_valid:1; + u_int :7; +#endif + u_char mc_number[15]; +}; + +struct cd_sub_channel_track_info { + u_char data_format; + u_char nothing1; + u_char track_number; + u_char nothing2; +#if _BYTE_ORDER == _LITTLE_ENDIAN + u_int :7; + u_int ti_valid:1; +#endif +#if _BYTE_ORDER == _BIG_ENDIAN + u_int ti_valid:1; + u_int :7; +#endif + u_char ti_number[15]; +}; + +struct cd_sub_channel_info { + struct cd_sub_channel_header header; + union { + struct cd_sub_channel_q_data q_data; + struct cd_sub_channel_position_data position; + struct cd_sub_channel_media_catalog media_catalog; + struct cd_sub_channel_track_info track_info; + } what; +}; + +/* + * Ioctls for the CD drive + */ +struct ioc_play_track { + u_char start_track; + u_char start_index; + u_char end_track; + u_char end_index; +}; + +#define CDIOCPLAYTRACKS _IOW('c', 1, struct ioc_play_track) +struct ioc_play_blocks { + int blk; + int len; +}; +#define CDIOCPLAYBLOCKS _IOW('c', 2, struct ioc_play_blocks) + +struct ioc_read_subchannel { + u_char address_format; +#define CD_LBA_FORMAT 1 +#define CD_MSF_FORMAT 2 + u_char data_format; +#define CD_SUBQ_DATA 0 +#define CD_CURRENT_POSITION 1 +#define CD_MEDIA_CATALOG 2 +#define CD_TRACK_INFO 3 + u_char track; + int data_len; + struct cd_sub_channel_info *data; +}; +#define CDIOCREADSUBCHANNEL _IOWR('c', 3, struct ioc_read_subchannel) + +struct ioc_toc_header { + u_short len; + u_char starting_track; + u_char ending_track; +}; + +#define CDIOREADTOCHEADER _IOR('c', 4, struct ioc_toc_header) + +struct ioc_read_toc_entry { + u_char address_format; + u_char starting_track; +#define CD_TRACK_LEADOUT 0xaa + u_short data_len; + struct cd_toc_entry *data; +}; +#define CDIOREADTOCENTRIES _IOWR('c', 5, struct ioc_read_toc_entry) +#define CDIOREADTOCENTRYS CDIOREADTOCENTRIES + +/* read LBA start of a given session; 0=last, others not yet supported */ +#define CDIOREADMSADDR _IOWR('c', 6, int) + +struct ioc_patch { + u_char patch[4]; /* one for each channel */ +}; +#define CDIOCSETPATCH _IOW('c', 9, struct ioc_patch) + +struct ioc_vol { + u_char vol[4]; /* one for each channel */ +}; +#define CDIOCGETVOL _IOR('c', 10, struct ioc_vol) +#define CDIOCSETVOL _IOW('c', 11, struct ioc_vol) +#define CDIOCSETMONO _IO('c', 12) +#define CDIOCSETSTEREO _IO('c', 13) +#define CDIOCSETMUTE _IO('c', 14) +#define CDIOCSETLEFT _IO('c', 15) +#define CDIOCSETRIGHT _IO('c', 16) +#define CDIOCSETDEBUG _IO('c', 17) +#define CDIOCCLRDEBUG _IO('c', 18) +#define CDIOCPAUSE _IO('c', 19) +#define CDIOCRESUME _IO('c', 20) +#define CDIOCRESET _IO('c', 21) +#define CDIOCSTART _IO('c', 22) +#define CDIOCSTOP _IO('c', 23) +#define CDIOCEJECT _IO('c', 24) +#define CDIOCALLOW _IO('c', 25) +#define CDIOCPREVENT _IO('c', 26) +#define CDIOCCLOSE _IO('c', 27) + +struct ioc_play_msf { + u_char start_m; + u_char start_s; + u_char start_f; + u_char end_m; + u_char end_s; + u_char end_f; +}; +#define CDIOCPLAYMSF _IOW('c', 25, struct ioc_play_msf) + +struct ioc_load_unload { + u_char options; +#define CD_LU_ABORT 0x1 /* NOTE: These are the same as the ATAPI */ +#define CD_LU_UNLOAD 0x2 /* op values for the LOAD_UNLOAD command */ +#define CD_LU_LOAD 0x3 + u_char slot; +}; +#define CDIOCLOADUNLOAD _IOW('c', 26, struct ioc_load_unload) + +/* DVD definitions */ + +/* DVD-ROM Specific ioctls */ +#define DVD_READ_STRUCT _IOWR('d', 0, union dvd_struct) +#define DVD_WRITE_STRUCT _IOWR('d', 1, union dvd_struct) +#define DVD_AUTH _IOWR('d', 2, union dvd_authinfo) + +#define GPCMD_READ_DVD_STRUCTURE 0xad +#define GPCMD_SEND_DVD_STRUCTURE 0xad +#define GPCMD_REPORT_KEY 0xa4 +#define GPCMD_SEND_KEY 0xa3 + +/* DVD struct types */ +#define DVD_STRUCT_PHYSICAL 0x00 +#define DVD_STRUCT_COPYRIGHT 0x01 +#define DVD_STRUCT_DISCKEY 0x02 +#define DVD_STRUCT_BCA 0x03 +#define DVD_STRUCT_MANUFACT 0x04 + +struct dvd_layer { + u_int8_t book_version; + u_int8_t book_type; + u_int8_t min_rate; + u_int8_t disc_size; + u_int8_t layer_type; + u_int8_t track_path; + u_int8_t nlayers; + u_int8_t track_density; + u_int8_t linear_density; + u_int8_t bca; + u_int32_t start_sector; + u_int32_t end_sector; + u_int32_t end_sector_l0; +}; + +struct dvd_physical { + u_int8_t type; + + u_int8_t layer_num; + struct dvd_layer layer[4]; +}; + +struct dvd_copyright { + u_int8_t type; + + u_int8_t layer_num; + u_int8_t cpst; + u_int8_t rmi; +}; + +struct dvd_disckey { + u_int8_t type; + + u_int8_t agid; + u_int8_t value[2048]; +}; + +struct dvd_bca { + u_int8_t type; + + int len; + u_int8_t value[188]; +}; + +struct dvd_manufact { + u_int8_t type; + + u_int8_t layer_num; + int len; + u_int8_t value[2048]; +}; + +union dvd_struct { + u_int8_t type; + + struct dvd_physical physical; + struct dvd_copyright copyright; + struct dvd_disckey disckey; + struct dvd_bca bca; + struct dvd_manufact manufact; +}; + +/* + * DVD authentication ioctl + */ + +/* Authentication states */ +#define DVD_LU_SEND_AGID 0 +#define DVD_HOST_SEND_CHALLENGE 1 +#define DVD_LU_SEND_KEY1 2 +#define DVD_LU_SEND_CHALLENGE 3 +#define DVD_HOST_SEND_KEY2 4 + +/* Termination states */ +#define DVD_AUTH_ESTABLISHED 5 +#define DVD_AUTH_FAILURE 6 + +/* Other functions */ +#define DVD_LU_SEND_TITLE_KEY 7 +#define DVD_LU_SEND_ASF 8 +#define DVD_INVALIDATE_AGID 9 +#define DVD_LU_SEND_RPC_STATE 10 +#define DVD_HOST_SEND_RPC_STATE 11 + +#if 0 +/* State data */ +typedef u_int8_t dvd_key[5]; /* 40-bit value, MSB is first elem. */ +typedef u_int8_t dvd_challenge[10]; /* 80-bit value, MSB is first elem. */ +#endif + +#define DVD_KEY_SIZE 5 +#define DVD_CHALLENGE_SIZE 10 + +struct dvd_lu_send_agid { + u_int8_t type; + + u_int8_t agid; +}; + +struct dvd_host_send_challenge { + u_int8_t type; + + u_int8_t agid; + u_int8_t chal[DVD_CHALLENGE_SIZE]; +}; + +struct dvd_send_key { + u_int8_t type; + + u_int8_t agid; + u_int8_t key[DVD_KEY_SIZE]; +}; + +struct dvd_lu_send_challenge { + u_int8_t type; + + u_int8_t agid; + u_int8_t chal[DVD_CHALLENGE_SIZE]; +}; + +#define DVD_CPM_NO_COPYRIGHT 0 +#define DVD_CPM_COPYRIGHTED 1 + +#define DVD_CP_SEC_NONE 0 +#define DVD_CP_SEC_EXIST 1 + +#define DVD_CGMS_UNRESTRICTED 0 +#define DVD_CGMS_SINGLE 2 +#define DVD_CGMS_RESTRICTED 3 + +struct dvd_lu_send_title_key { + u_int8_t type; + + u_int8_t agid; + u_int8_t title_key[DVD_KEY_SIZE]; + int lba; + u_int8_t cpm; + u_int8_t cp_sec; + u_int8_t cgms; +}; + +struct dvd_lu_send_asf { + u_int8_t type; + + u_int8_t agid; + u_int8_t asf; +}; + +struct dvd_host_send_rpcstate { + u_int8_t type; + u_int8_t pdrc; +}; + +struct dvd_lu_send_rpcstate { + u_int8_t type; + u_int8_t vra; + u_int8_t ucca; + u_int8_t region_mask; + u_int8_t rpc_scheme; + }; + +union dvd_authinfo { + u_int8_t type; + + struct dvd_lu_send_agid lsa; + struct dvd_host_send_challenge hsc; + struct dvd_send_key lsk; + struct dvd_lu_send_challenge lsc; + struct dvd_send_key hsk; + struct dvd_lu_send_title_key lstk; + struct dvd_lu_send_asf lsasf; + struct dvd_host_send_rpcstate hrpcs; + struct dvd_lu_send_rpcstate lrpcs; +}; +#endif /* !_SYS_CDIO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/chio.h b/lib/libc/include/generic-openbsd/sys/chio.h new file mode 100644 index 0000000000..cae798b3c4 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/chio.h @@ -0,0 +1,177 @@ +/* $OpenBSD: chio.h,v 1.9 2025/03/31 08:39:38 jsg Exp $ */ +/* $NetBSD: chio.h,v 1.8 1996/04/03 00:25:21 thorpej Exp $ */ + +/* + * Copyright (c) 1996 Jason R. Thorpe + * 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 acknowledgements: + * This product includes software developed by Jason R. Thorpe + * for And Communications, http://www.and.com/ + * 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 _SYS_CHIO_H_ +#define _SYS_CHIO_H_ + +/* + * Element types. Used as "to" and "from" type indicators in move + * and exchange operations. + * + * Note that code in sys/scsi/ch.c relies on these values (uses them + * as offsets in an array, and other evil), so don't muck with them + * unless you know what you're doing. + */ +#define CHET_MT 0 /* medium transport (picker) */ +#define CHET_ST 1 /* storage transport (slot) */ +#define CHET_IE 2 /* import/export (portal) */ +#define CHET_DT 3 /* data transfer (drive) */ + +/* + * Maximum length of a volume identification string + */ +#define CH_VOLTAG_MAXLEN 32 + +/* + * Structure used to execute a MOVE MEDIUM command. + */ +struct changer_move { + int cm_fromtype; /* element type to move from */ + int cm_fromunit; /* logical unit of from element */ + int cm_totype; /* element type to move to */ + int cm_tounit; /* logical unit of to element */ + int cm_flags; /* misc. flags */ +}; + +/* cm_flags */ +#define CM_INVERT 0x01 /* invert media */ + +/* + * Structure used to execute an EXCHANGE MEDIUM command. In an + * exchange operation, the following steps occur: + * + * - media from source is moved to first destination. + * + * - media previously occupying first destination is moved + * to the second destination. + * + * The second destination may or may not be the same as the source. + * In the case of a simple exchange, the source and second destination + * are the same. + */ +struct changer_exchange { + int ce_srctype; /* element type of source */ + int ce_srcunit; /* logical unit of source */ + int ce_fdsttype; /* element type of first destination */ + int ce_fdstunit; /* logical unit of first destination */ + int ce_sdsttype; /* element type of second destination */ + int ce_sdstunit; /* logical unit of second destination */ + int ce_flags; /* misc. flags */ +}; + +/* ce_flags */ +#define CE_INVERT1 0x01 /* invert media 1 */ +#define CE_INVERT2 0x02 /* invert media 2 */ + +/* + * Structure used to execute a POSITION TO ELEMENT command. This + * moves the current picker in front of the specified element. + */ +struct changer_position { + int cp_type; /* element type */ + int cp_unit; /* logical unit of element */ + int cp_flags; /* misc. flags */ +}; + +/* cp_flags */ +#define CP_INVERT 0x01 /* invert picker */ + +/* + * Data returned by CHIOGPARAMS. + */ +struct changer_params { + int cp_curpicker; /* current picker */ + int cp_npickers; /* number of pickers */ + int cp_nslots; /* number of slots */ + int cp_nportals; /* number of import/export portals */ + int cp_ndrives; /* number of drives */ +}; + +struct changer_voltag { + u_char cv_volid[CH_VOLTAG_MAXLEN + 1]; + u_int16_t cv_serial; +}; + +struct changer_element_status { + int ces_type; /* element type */ + u_int8_t ces_flags; /* flags */ + u_int16_t ces_addr; /* logical element address */ + u_int8_t ces_sensecode; /* additional sense code for element */ + u_int8_t ces_sensequal; /* additional sense code qualifier */ + u_int8_t ces_source_type; /* element type of source address */ + u_int16_t ces_source_addr; /* source address of medium */ + struct changer_voltag ces_pvoltag; /* primary voltag */ + struct changer_voltag ces_avoltag; /* alternate voltag */ +}; + +/* + * Command used to get element status. + */ +struct changer_element_status_request { + int cesr_type; /* element type */ + int cesr_flags; +#define CESR_VOLTAGS 0x01 + + struct changer_element_status *cesr_data; /* pre-allocated data storage */ +}; + +/* + * Data returned by CHIOGSTATUS is an array of flags bytes. + * Not all flags have meaning for all element types. + */ +#define CESTATUS_FULL 0x01 /* element is full */ +#define CESTATUS_IMPEXP 0x02 /* media deposited by operator */ +#define CESTATUS_EXCEPT 0x04 /* element in abnormal state */ +#define CESTATUS_ACCESS 0x08 /* media accessible by picker */ +#define CESTATUS_EXENAB 0x10 /* element supports exporting */ +#define CESTATUS_INENAB 0x20 /* element supports importing */ + +#define CESTATUS_PICKER_MASK 0x05 /* flags valid for pickers */ +#define CESTATUS_SLOT_MASK 0x0c /* flags valid for slots */ +#define CESTATUS_PORTAL_MASK 0x3f /* flags valid for portals */ +#define CESTATUS_DRIVE_MASK 0x0c /* flags valid for drives */ + +#define CESTATUS_BITS \ + "\20\6INEAB\5EXENAB\4ACCESS\3EXCEPT\2IMPEXP\1FULL" + +#define CHIOMOVE _IOW('c', 0x41, struct changer_move) +#define CHIOEXCHANGE _IOW('c', 0x42, struct changer_exchange) +#define CHIOPOSITION _IOW('c', 0x43, struct changer_position) +#define CHIOGPICKER _IOR('c', 0x44, int) +#define CHIOSPICKER _IOW('c', 0x45, int) +#define CHIOGPARAMS _IOR('c', 0x46, struct changer_params) +#define CHIOGSTATUS _IOW('c', 0x48, struct changer_element_status_request) + +#endif /* _SYS_CHIO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/clockintr.h b/lib/libc/include/generic-openbsd/sys/clockintr.h new file mode 100644 index 0000000000..7432f80dcc --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/clockintr.h @@ -0,0 +1,144 @@ +/* $OpenBSD: clockintr.h,v 1.29 2024/02/25 19:15:50 cheloha Exp $ */ +/* + * Copyright (c) 2020-2024 Scott Cheloha + * + * 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 _SYS_CLOCKINTR_H_ +#define _SYS_CLOCKINTR_H_ + +#include + +struct clockintr_stat { + uint64_t cs_dispatched; /* total time in dispatch (ns) */ + uint64_t cs_early; /* number of early dispatch calls */ + uint64_t cs_earliness; /* total earliness (ns) */ + uint64_t cs_lateness; /* total lateness (ns) */ + uint64_t cs_prompt; /* number of prompt dispatch calls */ + uint64_t cs_run; /* number of events dispatched */ + uint64_t cs_spurious; /* number of spurious dispatch calls */ +}; + +#ifdef _KERNEL + +#include +#include + +struct clockqueue; +struct clockrequest; +struct cpu_info; + +/* + * Platform API + */ + +struct intrclock { + void *ic_cookie; + void (*ic_rearm)(void *, uint64_t); + void (*ic_trigger)(void *); +}; + +/* + * Schedulable clock interrupt callback. + * + * Struct member protections: + * + * I Immutable after initialization. + * m Parent queue mutex (cl_queue->cq_mtx). + */ +struct clockintr { + uint64_t cl_expiration; /* [m] dispatch time */ + TAILQ_ENTRY(clockintr) cl_alink; /* [m] cq_all glue */ + TAILQ_ENTRY(clockintr) cl_plink; /* [m] cq_pend glue */ + void *cl_arg; /* [I] argument */ + void (*cl_func)(struct clockrequest *, void*, void*); /* [I] callback */ + struct clockqueue *cl_queue; /* [I] parent queue */ + uint32_t cl_flags; /* [m] CLST_* flags */ +}; + +#define CLST_PENDING 0x00000001 /* scheduled to run */ + +/* + * Interface for callback rescheduling requests. + * + * Struct member protections: + * + * I Immutable after initialization. + * o Owned by a single CPU. + */ +struct clockrequest { + uint64_t cr_expiration; /* [o] copy of dispatch time */ + struct clockqueue *cr_queue; /* [I] enclosing queue */ + uint32_t cr_flags; /* [o] CR_* flags */ +}; + +#define CR_RESCHEDULE 0x00000001 /* reschedule upon return */ + +/* + * Per-CPU clock interrupt state. + * + * Struct member protections: + * + * a Modified atomically. + * I Immutable after initialization. + * m Per-queue mutex (cq_mtx). + * o Owned by a single CPU. + */ +struct clockqueue { + struct clockrequest cq_request; /* [o] callback request object */ + struct mutex cq_mtx; /* [a] per-queue mutex */ + uint64_t cq_uptime; /* [o] cached uptime */ + TAILQ_HEAD(, clockintr) cq_all; /* [m] established clockintr list */ + TAILQ_HEAD(, clockintr) cq_pend;/* [m] pending clockintr list */ + struct clockintr *cq_running; /* [m] running clockintr */ + struct clockintr cq_hardclock; /* [o] hardclock handle */ + struct intrclock cq_intrclock; /* [I] local interrupt clock */ + struct clockintr_stat cq_stat; /* [o] dispatch statistics */ + volatile uint32_t cq_gen; /* [o] cq_stat update generation */ + volatile uint32_t cq_dispatch; /* [o] dispatch is running */ + uint32_t cq_flags; /* [m] CQ_* flags; see below */ +}; + +#define CQ_INIT 0x00000001 /* clockintr_cpu_init() done */ +#define CQ_INTRCLOCK 0x00000002 /* intrclock installed */ +#define CQ_IGNORE_REQUEST 0x00000004 /* ignore callback requests */ +#define CQ_NEED_WAKEUP 0x00000008 /* caller at barrier */ +#define CQ_STATE_MASK 0x0000000f + +void clockintr_cpu_init(const struct intrclock *); +int clockintr_dispatch(void *); +void clockintr_trigger(void); + +/* + * Kernel API + */ + +#define CL_BARRIER 0x00000001 /* block if callback is running */ +#define CL_FLAG_MASK 0x00000001 + +uint64_t clockintr_advance(struct clockintr *, uint64_t); +void clockintr_bind(struct clockintr *, struct cpu_info *, + void (*)(struct clockrequest *, void *, void *), void *); +void clockintr_cancel(struct clockintr *); +void clockintr_schedule(struct clockintr *, uint64_t); +void clockintr_stagger(struct clockintr *, uint64_t, uint32_t, uint32_t); +void clockintr_unbind(struct clockintr *, uint32_t); +uint64_t clockrequest_advance(struct clockrequest *, uint64_t); +uint64_t clockrequest_advance_random(struct clockrequest *, uint64_t, uint32_t); +void clockqueue_init(struct clockqueue *); +int sysctl_clockintr(int *, u_int, void *, size_t *, void *, size_t); + +#endif /* _KERNEL */ + +#endif /* !_SYS_CLOCKINTR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/conf.h b/lib/libc/include/generic-openbsd/sys/conf.h new file mode 100644 index 0000000000..23bb3e8ea4 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/conf.h @@ -0,0 +1,620 @@ +/* $OpenBSD: conf.h,v 1.168 2025/09/08 17:25:46 helg Exp $ */ +/* $NetBSD: conf.h,v 1.33 1996/05/03 20:03:32 christos Exp $ */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)conf.h 8.3 (Berkeley) 1/21/94 + */ + + +#ifndef _SYS_CONF_H_ +#define _SYS_CONF_H_ + +/* + * Definitions of device driver entry switches + */ + +struct buf; +struct proc; +struct tty; +struct uio; +struct knote; + +/* + * Types for d_type + */ +#define D_DISK 1 +#define D_TTY 2 + +/* + * Flags for d_flags + */ +#define D_CLONE 0x0001 /* clone upon open */ + +#ifdef _KERNEL + +#define dev_type_open(n) int n(dev_t, int, int, struct proc *) +#define dev_type_close(n) int n(dev_t, int, int, struct proc *) +#define dev_type_strategy(n) void n(struct buf *) +#define dev_type_ioctl(n) \ + int n(dev_t, u_long, caddr_t, int, struct proc *) + +#define dev_decl(n,t) __CONCAT(dev_type_,t)(__CONCAT(n,t)) +#define dev_init(c,n,t) \ + ((c) > 0 ? __CONCAT(n,t) : (__CONCAT(dev_type_,t)((*))) enxio) + +#endif /* _KERNEL */ + +/* + * Block device switch table + */ +struct bdevsw { + int (*d_open)(dev_t dev, int oflags, int devtype, + struct proc *p); + int (*d_close)(dev_t dev, int fflag, int devtype, + struct proc *p); + void (*d_strategy)(struct buf *bp); + int (*d_ioctl)(dev_t dev, u_long cmd, caddr_t data, + int fflag, struct proc *p); + int (*d_dump)(dev_t dev, daddr_t blkno, caddr_t va, + size_t size); + daddr_t (*d_psize)(dev_t dev); + u_int d_type; + /* u_int d_flags; */ +}; + +#ifdef _KERNEL + +extern struct bdevsw bdevsw[]; + +/* bdevsw-specific types */ +#define dev_type_dump(n) int n(dev_t, daddr_t, caddr_t, size_t) +#define dev_type_size(n) daddr_t n(dev_t) + +/* bdevsw-specific initializations */ +#define dev_size_init(c,n) (c > 0 ? __CONCAT(n,size) : 0) + +#define bdev_decl(n) \ + dev_decl(n,open); dev_decl(n,close); dev_decl(n,strategy); \ + dev_decl(n,ioctl); dev_decl(n,dump); dev_decl(n,size) + +#define bdev_disk_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), \ + dev_init(c,n,strategy), dev_init(c,n,ioctl), \ + dev_init(c,n,dump), dev_size_init(c,n), D_DISK } + +#define bdev_swap_init(c,n) { \ + (dev_type_open((*))) enodev, (dev_type_close((*))) enodev, \ + dev_init(c,n,strategy), (dev_type_ioctl((*))) enodev, \ + (dev_type_dump((*))) enodev, 0 } + +#define bdev_notdef() { \ + (dev_type_open((*))) enodev, (dev_type_close((*))) enodev, \ + (dev_type_strategy((*))) enodev, (dev_type_ioctl((*))) enodev, \ + (dev_type_dump((*))) enodev, 0 } + +#endif + +/* + * Character device switch table + */ +struct cdevsw { + int (*d_open)(dev_t dev, int oflags, int devtype, + struct proc *p); + int (*d_close)(dev_t dev, int fflag, int devtype, + struct proc *); + int (*d_read)(dev_t dev, struct uio *uio, int ioflag); + int (*d_write)(dev_t dev, struct uio *uio, int ioflag); + int (*d_ioctl)(dev_t dev, u_long cmd, caddr_t data, + int fflag, struct proc *p); + int (*d_stop)(struct tty *tp, int rw); + struct tty * + (*d_tty)(dev_t dev); + paddr_t (*d_mmap)(dev_t, off_t, int); + u_int d_type; + u_int d_flags; + int (*d_kqfilter)(dev_t dev, struct knote *kn); +}; + +#ifdef _KERNEL + +extern struct cdevsw cdevsw[]; + +/* cdevsw-specific types */ +#define dev_type_read(n) int n(dev_t, struct uio *, int) +#define dev_type_write(n) int n(dev_t, struct uio *, int) +#define dev_type_stop(n) int n(struct tty *, int) +#define dev_type_tty(n) struct tty *n(dev_t) +#define dev_type_mmap(n) paddr_t n(dev_t, off_t, int) +#define dev_type_kqfilter(n) int n(dev_t, struct knote *) + +#define cdev_decl(n) \ + dev_decl(n,open); dev_decl(n,close); dev_decl(n,read); \ + dev_decl(n,write); dev_decl(n,ioctl); dev_decl(n,stop); \ + dev_decl(n,tty); dev_decl(n,mmap); \ + dev_decl(n,kqfilter) + +/* open, close, read, write, ioctl */ +#define cdev_disk_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \ + 0, (dev_type_mmap((*))) enodev, \ + D_DISK, 0, seltrue_kqfilter } + +/* open, close, read, write, ioctl */ +#define cdev_tape_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \ + 0, (dev_type_mmap((*))) enodev, \ + 0, 0, seltrue_kqfilter } + +/* open, close, read, write, ioctl, stop, tty */ +#define cdev_tty_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + dev_init(c,n,write), dev_init(c,n,ioctl), dev_init(c,n,stop), \ + dev_init(c,n,tty), (dev_type_mmap((*))) enodev, \ + D_TTY, 0, ttkqfilter } + +/* open, close, read, ioctl, kqfilter */ +#define cdev_mouse_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev , 0, 0, dev_init(c,n,kqfilter) } + +#define cdev_notdef() { \ + (dev_type_open((*))) enodev, (dev_type_close((*))) enodev, \ + (dev_type_read((*))) enodev, (dev_type_write((*))) enodev, \ + (dev_type_ioctl((*))) enodev, (dev_type_stop((*))) enodev, \ + 0, (dev_type_mmap((*))) enodev, 0, 0, seltrue_kqfilter } + +/* open, close, read, write, ioctl, kqfilter -- XXX should be a tty */ +#define cdev_cn_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + dev_init(c,n,write), dev_init(c,n,ioctl), dev_init(c,n,stop), \ + 0, (dev_type_mmap((*))) enodev, \ + D_TTY, 0, dev_init(c,n,kqfilter) } + +/* open, read, write, ioctl, kqfilter -- XXX should be a tty */ +#define cdev_ctty_init(c,n) { \ + dev_init(c,n,open), (dev_type_close((*))) nullop, dev_init(c,n,read), \ + dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) nullop, \ + 0, (dev_type_mmap((*))) enodev, \ + D_TTY, 0, dev_init(c,n,kqfilter) } + +/* open, close, read, write, ioctl, mmap */ +#define cdev_mm_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + dev_init(c,n,write), dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, dev_init(c,n,mmap), \ + 0, 0, seltrue_kqfilter } + +/* open, close, read, write, ioctl, tty, kqfilter */ +#define cdev_ptc_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) nullop, \ + dev_init(c,n,tty), (dev_type_mmap((*))) enodev, \ + D_TTY, 0, dev_init(c,n,kqfilter) } + +/* open, close, read, write, ioctl, mmap */ +#define cdev_ptm_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, (dev_type_mmap((*))) enodev } + +/* open, close, read, ioctl, kqfilter XXX should be a generic device */ +#define cdev_log_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,n,kqfilter) } + +/* open */ +#define cdev_fd_init(c,n) { \ + dev_init(c,n,open), (dev_type_close((*))) enodev, \ + (dev_type_read((*))) enodev, (dev_type_write((*))) enodev, \ + (dev_type_ioctl((*))) enodev, (dev_type_stop((*))) enodev, \ + 0, (dev_type_mmap((*))) enodev } + +/* open, close, read, write, ioctl, kqfilter -- XXX should be generic device */ +#define cdev_tun_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \ + 0, (dev_type_mmap((*))) enodev, \ + 0, 0, dev_init(c,n,kqfilter) } + +/* open, close, ioctl, kqfilter -- XXX should be generic device */ +#define cdev_vscsi_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), \ + (dev_type_read((*))) enodev, (dev_type_write((*))) enodev, \ + dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \ + 0, (dev_type_mmap((*))) enodev, \ + 0, 0, dev_init(c,n,kqfilter) } + +/* open, close, read, write, ioctl, kqfilter -- XXX should be generic device */ +#define cdev_pppx_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \ + 0, (dev_type_mmap((*))) enodev, \ + 0, 0, dev_init(c,n,kqfilter) } + +/* open, close, read, write, ioctl, kqfilter, cloning -- XXX should be generic device */ +#define cdev_bpf_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \ + 0, (dev_type_mmap((*))) enodev, \ + 0, D_CLONE, dev_init(c,n,kqfilter) } + +/* open, close, ioctl */ +#define cdev_ch_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev } + +/* open, close, ioctl */ +#define cdev_uk_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev } + +/* open, close, read, write, ioctl, kqfilter */ +#define cdev_audio_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + dev_init(c,n,write), dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,n,kqfilter) } + +/* open, close, read, write, ioctl, kqfilter */ +#define cdev_midi_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + dev_init(c,n,write), dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,n,kqfilter) } + +/* open, close, read */ +#define cdev_ksyms_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + (dev_type_write((*))) enodev, (dev_type_ioctl((*))) enodev, \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev, 0, 0, seltrue_kqfilter } + +/* open, close, ioctl */ +#define cdev_kstat_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev } + +/* open, close, read, write, ioctl, stop, tty, mmap, kqfilter */ +#define cdev_wsdisplay_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + dev_init(c,n,write), dev_init(c,n,ioctl), dev_init(c,n,stop), \ + dev_init(c,n,tty), dev_init(c,n,mmap), \ + D_TTY, 0, dev_init(c,n,kqfilter) } + +/* open, close, read, write, ioctl, kqfilter */ +#define cdev_random_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \ + 0, (dev_type_mmap((*))) enodev, \ + 0, 0, dev_init(c,n,kqfilter) } + +/* open, close, ioctl, nokqfilter */ +#define cdev_usb_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev } + +/* open, close, write */ +#define cdev_ulpt_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + dev_init(c,n,write), (dev_type_ioctl((*))) enodev, \ + (dev_type_stop((*))) enodev, 0, (dev_type_mmap((*))) enodev } + +/* open, close, ioctl */ +#define cdev_pf_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev, 0, D_CLONE } + +/* open, close, read, write, ioctl, kqfilter */ +#define cdev_usbdev_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \ + 0, (dev_type_mmap((*))) enodev, 0, 0, \ + dev_init(c,n,kqfilter) } + +/* open, close, read, write, ioctl, kqfilter */ +#define cdev_fido_init(c,n) { \ + dev_init(c,n,open), dev_init(c,uhid,close), dev_init(c,uhid,read), \ + dev_init(c,uhid,write), dev_init(c,fido,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,uhid,kqfilter) } + +/* open, close, read, write, ioctl, kqfilter */ +#define cdev_ujoy_init(c,n) { \ + dev_init(c,n,open), dev_init(c,uhid,close), dev_init(c,uhid,read), \ + dev_init(c,uhid,write), dev_init(c,ujoy,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,uhid,kqfilter) } + +/* open, close, init */ +#define cdev_pci_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev } + +/* open, close, ioctl */ +#define cdev_radio_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev } + +/* open, close, ioctl, read, mmap, kqfilter */ +#define cdev_video_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + dev_init(c,n,mmap), 0, 0, dev_init(c,n,kqfilter) } + +/* open, close, write, ioctl */ +#define cdev_spkr_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \ + 0, (dev_type_mmap((*))) enodev, \ + 0, 0, seltrue_kqfilter } + +/* open, close, write */ +#define cdev_lpt_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + dev_init(c,n,write), (dev_type_ioctl((*))) enodev, \ + (dev_type_stop((*))) enodev, 0, (dev_type_mmap((*))) enodev, \ + 0, 0, seltrue_kqfilter } + +/* open, close, read, ioctl, mmap */ +#define cdev_bktr_init(c, n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, dev_init(c,n,mmap), \ + 0, 0, seltrue_kqfilter } + +/* open, close, read, ioctl, kqfilter */ +#define cdev_hotplug_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,n,kqfilter) } + +/* open, close, ioctl */ +#define cdev_gpio_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev } + +/* open, close, ioctl */ +#define cdev_bio_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev } + +/* open, close, read, ioctl, mmap, nokqfilter */ +#define cdev_drm_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c, n, read), \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + dev_init(c,n,mmap), 0, D_CLONE, dev_init(c,n,kqfilter) } + +/* open, close, ioctl */ +#define cdev_amdmsr_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev } + +/* open, close, read, write, ioctl */ +#define cdev_fuse_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + dev_init(c,n,write), (dev_type_ioctl((*))) enodev, \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev, 0, D_CLONE, dev_init(c,n,kqfilter) } + +/* open, close, ioctl */ +#define cdev_pvbus_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), \ + (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, \ + dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev } + +/* open, close, ioctl */ +#define cdev_ipmi_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, (dev_type_mmap((*))) enodev, \ + 0, 0, seltrue_kqfilter } + +/* open, close, ioctl */ +#define cdev_efi_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev } + +/* open, close, ioctl, mmap */ +#define cdev_kcov_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_init(c,n,mmap)), 0, D_CLONE } + +/* open, close, read, ioctl */ +#define cdev_dt_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev, 0, D_CLONE } + +#endif + +/* + * Line discipline switch table + */ +struct linesw { + int (*l_open)(dev_t dev, struct tty *tp, struct proc *p); + int (*l_close)(struct tty *tp, int flags, struct proc *p); + int (*l_read)(struct tty *tp, struct uio *uio, + int flag); + int (*l_write)(struct tty *tp, struct uio *uio, + int flag); + int (*l_ioctl)(struct tty *tp, u_long cmd, caddr_t data, + int flag, struct proc *p); + int (*l_rint)(int c, struct tty *tp); + int (*l_start)(struct tty *tp); + int (*l_modem)(struct tty *tp, int flag); +}; + +#ifdef _KERNEL +extern struct linesw linesw[]; +extern dev_t swdevt[]; /* Swap device table */ +extern const int chrtoblktbl[]; +extern const int nchrtoblktbl; + +struct bdevsw *bdevsw_lookup(dev_t); +dev_t chrtoblk(dev_t); +dev_t blktochr(dev_t); +int iskmemdev(dev_t); +int iszerodev(dev_t); +dev_t getnulldev(void); + +cdev_decl(filedesc); + +cdev_decl(log); + +#define ptstty ptytty +#define ptsioctl ptyioctl +cdev_decl(pts); + +#define ptctty ptytty +#define ptcioctl ptyioctl +cdev_decl(ptc); + +cdev_decl(ptm); + +cdev_decl(ctty); + +cdev_decl(audio); +cdev_decl(drm); +cdev_decl(midi); +cdev_decl(radio); +cdev_decl(video); +cdev_decl(cn); + +bdev_decl(sw); + +bdev_decl(vnd); +cdev_decl(vnd); + +cdev_decl(ch); + +bdev_decl(sd); +cdev_decl(sd); + +cdev_decl(st); + +bdev_decl(cd); +cdev_decl(cd); + +bdev_decl(rd); +cdev_decl(rd); + +bdev_decl(uk); +cdev_decl(uk); + +cdev_decl(dt); + +cdev_decl(diskmap); + +cdev_decl(bpf); + +cdev_decl(pf); + +cdev_decl(tun); +cdev_decl(tap); +cdev_decl(pppx); +cdev_decl(pppac); + +cdev_decl(random); + +cdev_decl(wsdisplay); +cdev_decl(wskbd); +cdev_decl(wsmouse); +cdev_decl(wsmux); + +cdev_decl(ksyms); +cdev_decl(kstat); + +cdev_decl(bio); +cdev_decl(vscsi); + +cdev_decl(bktr); + +cdev_decl(usb); +cdev_decl(ugen); +cdev_decl(uhid); +cdev_decl(fido); +cdev_decl(ujoy); +cdev_decl(ucom); +cdev_decl(ulpt); + +cdev_decl(hotplug); +cdev_decl(gpio); +cdev_decl(amdmsr); +cdev_decl(fuse); +cdev_decl(pvbus); +cdev_decl(ipmi); +cdev_decl(efi); +cdev_decl(kcov); + +#endif + +#endif /* _SYS_CONF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/core.h b/lib/libc/include/generic-openbsd/sys/core.h new file mode 100644 index 0000000000..5facce4343 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/core.h @@ -0,0 +1,99 @@ +/* $OpenBSD: core.h,v 1.9 2024/01/17 22:22:25 kurt Exp $ */ +/* $NetBSD: core.h,v 1.4 1994/10/29 08:20:14 cgd Exp $ */ + +/* + * Copyright (c) 1994 Paul Kranenburg + * 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 Paul Kranenburg. + * 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. + */ + +#define COREMAGIC 0507 +#define CORESEGMAGIC 0510 + +/* + * The core structure's c_midmag field (like exec's a_midmag) is a + * network-byteorder encoding of this int + * FFFFFFmmmmmmmmmmMMMMMMMMMMMMMMMM + * Where `F' is 6 bits of flag (currently unused), + * `m' is 10 bits of machine-id, and + * `M' is 16 bits worth of magic number, ie. COREMAGIC. + * The macros below will set/get the needed fields. + */ +#define CORE_GETMAGIC(c) ( ntohl(((c).c_midmag)) & 0xffff ) +#define CORE_GETMID(c) ( (ntohl(((c).c_midmag)) >> 16) & 0x03ff ) +#define CORE_GETFLAG(c) ( (ntohl(((c).c_midmag)) >> 26) & 0x03f ) +#define CORE_SETMAGIC(c,mag,mid,flag) ( (c).c_midmag = htonl ( \ + ( ((flag) & 0x3f) << 26) | \ + ( ((mid) & 0x03ff) << 16) | \ + ( ((mag) & 0xffff) ) ) ) + +/* Flag definitions */ +#define CORE_CPU 1 +#define CORE_DATA 2 +#define CORE_STACK 4 + +#ifndef _KERNEL +/* + * XXX OBSOLETE, NO LONGER USED + * XXX This header file exists to support binutils' netbsd-core format + * XXX which is still needed for the a.out-m88k-openbsd use in luna88k + * XXX boot block creation. + * + * A core file consists of a header followed by a number of segments. + * Each segment is preceded by a `coreseg' structure giving the + * segment's type, the virtual address where the bits resided in + * process address space and the size of the segment. + * + * The core header specifies the lengths of the core header itself and + * each of the following core segment headers to allow for any machine + * dependent alignment requirements. + */ + +struct core { + u_int32_t c_midmag; /* magic, id, flags */ + u_int16_t c_hdrsize; /* Size of this header (machdep algn) */ + u_int16_t c_seghdrsize; /* Size of a segment header */ + u_int32_t c_nseg; /* # of core segments */ + char c_name[_MAXCOMLEN]; /* Copy of p->p_comm, incl NUL */ + u_int32_t c_signo; /* Killing signal */ + u_long c_ucode; /* Hmm ? */ + u_long c_cpusize; /* Size of machine dependent segment */ + u_long c_tsize; /* Size of traditional text segment */ + u_long c_dsize; /* Size of traditional data segment */ + u_long c_ssize; /* Size of traditional stack segment */ +}; + +struct coreseg { + u_int32_t c_midmag; /* magic, id, flags */ + u_long c_addr; /* Virtual address of segment */ + u_long c_size; /* Size of this segment */ +}; + +#else +int coredump_write(void *, enum uio_seg, const void *, size_t, int); +void coredump_unmap(void *, vaddr_t, vaddr_t); +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/ctf.h b/lib/libc/include/generic-openbsd/sys/ctf.h new file mode 100644 index 0000000000..2ce31a7c5e --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/ctf.h @@ -0,0 +1,186 @@ +/* $OpenBSD: ctf.h,v 1.5 2017/08/13 14:56:05 nayden Exp $ */ + +/* + * Copyright (c) 2016 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 _SYS_CTF_H_ +#define _SYS_CTF_H_ + +/* + * CTF ``Compact ANSI-C Type Format'' ABI header file. + */ + +struct ctf_header { + uint16_t cth_magic; + uint8_t cth_version; + uint8_t cth_flags; + uint32_t cth_parlabel; + uint32_t cth_parname; + uint32_t cth_lbloff; + uint32_t cth_objtoff; + uint32_t cth_funcoff; + uint32_t cth_typeoff; + uint32_t cth_stroff; + uint32_t cth_strlen; +}; + +#define CTF_F_COMPRESS (1 << 0) /* zlib compression */ + +struct ctf_lblent { + uint32_t ctl_label; + uint32_t ctl_typeidx; +}; + +struct ctf_stype { + uint32_t cts_name; + uint16_t cts_info; + union { + uint16_t _size; + uint16_t _type; + } _ST; +#define cts_size _ST._size +#define cts_type _ST._type +}; + +struct ctf_type { + struct ctf_stype _ctt_stype; +#define ctt_name _ctt_stype.cts_name +#define ctt_info _ctt_stype.cts_info +#define ctt_size _ctt_stype.cts_size +#define ctt_type _ctt_stype.cts_type + uint32_t ctt_lsizehi; + uint32_t ctt_lsizelo; +}; + +struct ctf_array { + uint16_t cta_contents; + uint16_t cta_index; + uint32_t cta_nelems; +}; + +struct ctf_member { + uint32_t ctm_name; + uint16_t ctm_type; + uint16_t ctm_offset; +}; + +struct ctf_lmember { + struct ctf_member _ctlm_member; +#define ctlm_name _ctlm_member.ctm_name +#define ctlm_type _ctlm_member.ctm_type +#define ctlm_pad0 _ctlm_member.ctm_offset + uint32_t ctlm_offsethi; + uint32_t ctlm_offsetlo; +}; + +#define CTF_LSTRUCT_THRESH 8192 + +struct ctf_enum { + uint32_t cte_name; + int32_t cte_value; +}; + +#define CTF_MAGIC 0xcff1 +#define CTF_VERSION 2 + +#define CTF_MAX_NAME 0x7fffffff +#define CTF_MAX_VLEN 0x03ff +#define CTF_MAX_SIZE 0xfffe +#define CTF_LSIZE_SENT CTF_MAX_SIZE+1 /* sentinel for cts vs ctt */ + +#define CTF_STRTAB_0 0 +#define CTF_STRTAB_1 1 + +/* + * Info macro. + */ +#define CTF_INFO_VLEN(i) (((i) & CTF_MAX_VLEN)) +#define CTF_INFO_ISROOT(i) (((i) & 0x0400) >> 10) +#define CTF_INFO_KIND(i) (((i) & 0xf800) >> 11) +#define CTF_K_UNKNOWN 0 +#define CTF_K_INTEGER 1 +#define CTF_K_FLOAT 2 +#define CTF_K_POINTER 3 +#define CTF_K_ARRAY 4 +#define CTF_K_FUNCTION 5 +#define CTF_K_STRUCT 6 +#define CTF_K_UNION 7 +#define CTF_K_ENUM 8 +#define CTF_K_FORWARD 9 +#define CTF_K_TYPEDEF 10 +#define CTF_K_VOLATILE 11 +#define CTF_K_CONST 12 +#define CTF_K_RESTRICT 13 +#define CTF_K_MAX 31 + +/* + * Integer/Float Encoding macro. + */ +#define _CTF_ENCODING(e) (((e) & 0xff000000) >> 24) +#define _CTF_OFFSET(e) (((e) & 0x00ff0000) >> 16) +#define _CTF_BITS(e) (((e) & 0x0000ffff)) +#define _CTF_DATA(encoding, offset, bits) \ + (((encoding) << 24) | ((offset) << 16) | (bits)) + +#define CTF_INT_ENCODING(e) _CTF_ENCODING(e) +#define CTF_INT_SIGNED (1 << 0) +#define CTF_INT_CHAR (1 << 1) +#define CTF_INT_BOOL (1 << 2) +#define CTF_INT_VARARGS (1 << 3) +#define CTF_INT_OFFSET(e) _CTF_OFFSET(e) +#define CTF_INT_BITS(e) _CTF_BITS(e) +#define CTF_INT_DATA(e, o, b) _CTF_DATA(e, o, b) + +#define CTF_FP_ENCODING(e) _CTF_ENCODING(e) +#define CTF_FP_SINGLE 1 +#define CTF_FP_DOUBLE 2 +#define CTF_FP_CPLX 3 +#define CTF_FP_DCPLX 4 +#define CTF_FP_LDCPLX 5 +#define CTF_FP_LDOUBLE 6 +#define CTF_FP_INTRVL 7 +#define CTF_FP_DINTRVL 8 +#define CTF_FP_LDINTRVL 9 +#define CTF_FP_IMAGRY 10 +#define CTF_FP_DIMAGRY 11 +#define CTF_FP_LDIMAGRY 12 +#define CTF_FP_OFFSET(e) _CTF_OFFSET(e) +#define CTF_FP_BITS(e) _CTF_BITS(e) +#define CTF_FP_DATA(e, o, b) _CTF_DATA(e, o, b) + +/* + * Name reference macro. + */ +#define CTF_NAME_STID(n) ((n) >> 31) +#define CTF_NAME_OFFSET(n) ((n) & CTF_MAX_NAME) + +/* + * Type macro. + */ +#define CTF_SIZE_TO_LSIZE_HI(s) ((uint32_t)((uint64_t)(s) >> 32)) +#define CTF_SIZE_TO_LSIZE_LO(s) ((uint32_t)(s)) +#define CTF_TYPE_LSIZE(t) \ + (((uint64_t)(t)->ctt_lsizehi) << 32 | (t)->ctt_lsizelo) + +/* + * Member macro. + */ +#define CTF_LMEM_OFFSET(m) \ + (((uint64_t)(m)->ctlm_offsethi) << 32 | (m)->ctlm_offsetlo) +#define CTF_OFFSET_TO_LMEMHI(off) ((uint32_t)((uint64_t)(off) >> 32)) +#define CTF_OFFSET_TO_LMEMLO(off) ((uint32_t)(off)) + +#endif /* _SYS_CTF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/device.h b/lib/libc/include/generic-openbsd/sys/device.h new file mode 100644 index 0000000000..58468d7f22 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/device.h @@ -0,0 +1,245 @@ +/* $OpenBSD: device.h,v 1.70 2025/09/16 12:18:10 hshoexer Exp $ */ +/* $NetBSD: device.h,v 1.15 1996/04/09 20:55:24 cgd Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)device.h 8.2 (Berkeley) 2/17/94 + */ + +#ifndef _SYS_DEVICE_H_ +#define _SYS_DEVICE_H_ + +#include + +/* + * Minimal device structures. + * Note that all ``system'' device types are listed here. + */ +enum devclass { + DV_DULL, /* generic, no special info */ + DV_CPU, /* CPU (carries resource utilization) */ + DV_DISK, /* disk drive (label, etc) */ + DV_IFNET, /* network interface */ + DV_TAPE, /* tape device */ + DV_TTY /* serial line interface (???) */ +}; + +/* + * Actions for ca_activate. + */ +#define DVACT_DEACTIVATE 1 /* deactivate the device */ +#define DVACT_QUIESCE 2 /* warn the device about suspend */ +#define DVACT_SUSPEND 3 /* suspend the device */ +#define DVACT_RESUME 4 /* resume the device */ +#define DVACT_WAKEUP 5 /* tell device to recover after resume */ +#define DVACT_POWERDOWN 6 /* power device down */ + +struct device { + enum devclass dv_class; /* this device's classification */ + TAILQ_ENTRY(device) dv_list; /* entry on list of all devices */ + struct cfdata *dv_cfdata; /* config data that found us */ + int dv_unit; /* device unit number */ + char dv_xname[16]; /* external name (name + unit) */ + struct device *dv_parent; /* pointer to parent device */ + int dv_flags; /* misc. flags; see below */ + int dv_ref; /* ref count */ +}; + +/* dv_flags */ +#define DVF_ACTIVE 0x0001 /* device is activated */ + +TAILQ_HEAD(devicelist, device); + +/* + * Configuration data (i.e., data placed in ioconf.c). + */ +struct cfdata { + const struct cfattach *cf_attach; /* config attachment */ + struct cfdriver *cf_driver; /* config driver */ + short cf_unit; /* unit number */ + short cf_fstate; /* finding state (below) */ + long *cf_loc; /* locators (machine dependent) */ + int cf_flags; /* flags from config */ + short *cf_parents; /* potential parents */ + int cf_locnames; /* start of names */ + short cf_starunit1; /* 1st usable unit number by STAR */ +}; +extern struct cfdata cfdata[]; +#define FSTATE_NOTFOUND 0 /* has not been found */ +#define FSTATE_FOUND 1 /* has been found */ +#define FSTATE_STAR 2 /* duplicable */ +#define FSTATE_DNOTFOUND 3 /* has not been found, and is disabled */ +#define FSTATE_DSTAR 4 /* duplicable, and is disabled */ + +typedef int (*cfmatch_t)(struct device *, void *, void *); +typedef void (*cfscan_t)(struct device *, void *); + +/* + * `configuration' attachment and driver (what the machine-independent + * autoconf uses). As devices are found, they are applied against all + * the potential matches. The one with the best match is taken, and a + * device structure (plus any other data desired) is allocated. Pointers + * to these are placed into an array of pointers. The array itself must + * be dynamic since devices can be found long after the machine is up + * and running. + * + * Devices can have multiple configuration attachments if they attach + * to different attributes (busses, or whatever), to allow specification + * of multiple match and attach functions. There is only one configuration + * driver per driver, so that things like unit numbers and the device + * structure array will be shared. + */ +struct cfattach { + size_t ca_devsize; /* size of dev data (for malloc) */ + cfmatch_t ca_match; /* returns a match level */ + void (*ca_attach)(struct device *, struct device *, void *); + int (*ca_detach)(struct device *, int); + int (*ca_activate)(struct device *, int); +}; + +/* Flags given to config_detach(), and the ca_detach function. */ +#define DETACH_FORCE 0x01 /* force detachment; hardware gone */ +#define DETACH_QUIET 0x02 /* don't print a notice */ + +/* For cd_mode, below */ +#define CD_INDIRECT 1 +#define CD_SKIPHIBERNATE 2 +#define CD_COCOVM 4 /* Allow a device on a VM employing + * confidential computing methods, + * e.g. AMD SEV. */ + +struct cfdriver { + void **cd_devs; /* devices found */ + char *cd_name; /* device name */ + enum devclass cd_class; /* device classification */ + int cd_mode; /* device type subclassification */ + int cd_ndevs; /* size of cd_devs array */ +}; + +/* + * Configuration printing functions, and their return codes. The second + * argument is NULL if the device was configured; otherwise it is the name + * of the parent device. The return value is ignored if the device was + * configured, so most functions can return UNCONF unconditionally. + */ +typedef int (*cfprint_t)(void *, const char *); +#define QUIET 0 /* print nothing */ +#define UNCONF 1 /* print " not configured\n" */ +#define UNSUPP 2 /* print " not supported\n" */ + +/* + * Pseudo-device attach information (function + number of pseudo-devs). + */ +struct pdevinit { + void (*pdev_attach)(int); + int pdev_count; +}; + +#ifdef _KERNEL + +#ifdef DIAGNOSTIC +extern int pdevinit_done; +#endif + +extern struct devicelist alldevs; /* list of all devices */ + +extern int autoconf_verbose; +extern volatile int config_pending; /* semaphore for mountroot */ + +void config_init(void); +void *config_search(cfmatch_t, struct device *, void *); +struct device *config_found_sm(struct device *, void *, cfprint_t, + cfmatch_t); +struct device *config_rootfound(char *, void *); +void config_scan(cfscan_t, struct device *); +struct device *config_attach(struct device *, void *, void *, cfprint_t); +int config_detach(struct device *, int); +int config_detach_children(struct device *, int); +int config_deactivate(struct device *); +int config_suspend(struct device *, int); +int config_suspend_all(int); +int config_activate_children(struct device *, int); +struct device *config_make_softc(struct device *parent, + struct cfdata *cf); +void config_defer(struct device *, void (*)(struct device *)); +void config_pending_incr(void); +void config_pending_decr(void); +void config_mountroot(struct device *, void (*)(struct device *)); +void config_process_deferred_mountroot(void); + +int request_sleep(int); +int sleep_state(void *, int); +#define SLEEP_SUSPEND 0x01 +#define SLEEP_HIBERNATE 0x02 +void sleep_mp(void); +void resume_mp(void); +int sleep_showstate(void *v, int sleepmode); +int sleep_setstate(void *v); +int sleep_resume(void *v); +int gosleep(void *v); +int suspend_finish(void *v); +int resuming(void); + +struct device *device_mainbus(void); +struct device *device_mpath(void); +struct device *device_lookup(struct cfdriver *, int unit); +void device_ref(struct device *); +void device_unref(struct device *); + +struct nam2blk { + char *name; + int maj; +}; + +int findblkmajor(struct device *dv); +char *findblkname(int); +void setroot(struct device *, int, int); +struct device *getdisk(char *str, int len, int defpart, dev_t *devp); +struct device *parsedisk(char *str, int len, int defpart, dev_t *devp); +void device_register(struct device *, void *); +void device_register_wakeup(struct device *); + +int loadfirmware(const char *name, u_char **bufp, size_t *buflen); +#define FIRMWARE_MAX 24*1024*1024 + +/* compatibility definitions */ +#define config_found(d, a, p) config_found_sm((d), (a), (p), NULL) + +#endif /* _KERNEL */ + +#endif /* !_SYS_DEVICE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/dir.h b/lib/libc/include/generic-openbsd/sys/dir.h new file mode 100644 index 0000000000..ef8bb24002 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/dir.h @@ -0,0 +1,65 @@ +/* $OpenBSD: dir.h,v 1.5 2003/06/02 23:28:21 millert Exp $ */ +/* $NetBSD: dir.h,v 1.9 1996/10/27 19:27:54 gwr Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)dir.h 8.2 (Berkeley) 1/4/94 + */ + +/* + * The information in this file should be obtained from + * and is provided solely (and temporarily) for backward compatibility. + */ + +#ifndef _SYS_DIR_H_ +#define _SYS_DIR_H_ + +#ifdef _KERNEL +/* This file should only be used by old user-level code. */ +#error "Please use instead" +#endif + +#include + +/* + * Backwards compatibility. + */ +#define direct dirent + +/* + * The DIRSIZ macro gives the minimum record length which will hold + * the directory entry. This requires the amount of space in struct direct + * without the d_name field, plus enough space for the name with a terminating + * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary. + */ +#undef DIRSIZ +#define DIRSIZ(dp) \ + ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3)) + +#endif /* !_SYS_DIR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/dirent.h b/lib/libc/include/generic-openbsd/sys/dirent.h new file mode 100644 index 0000000000..da231d07bf --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/dirent.h @@ -0,0 +1,100 @@ +/* $OpenBSD: dirent.h,v 1.11 2013/12/13 18:09:27 zhuk Exp $ */ +/* $NetBSD: dirent.h,v 1.12 1996/04/09 20:55:25 cgd Exp $ */ + +/*- + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)dirent.h 8.3 (Berkeley) 8/10/94 + */ + +#ifndef _SYS_DIRENT_H_ +#define _SYS_DIRENT_H_ + +#include + +/* + * The dirent structure defines the format of directory entries returned by + * the getdents(2) system call. + * + * A directory entry has a struct dirent at the front of it, containing its + * inode number, the length of the entry, and the length of the name + * contained in the entry. These are followed by the name padded to a 4 + * byte boundary with null bytes. All names are guaranteed null terminated. + * The maximum length of a name in a directory is MAXNAMLEN. + */ + +struct dirent { + __ino_t d_fileno; /* file number of entry */ + __off_t d_off; /* offset after this entry */ + __uint16_t d_reclen; /* length of this record */ + __uint8_t d_type; /* file type, see below */ + __uint8_t d_namlen; /* length of string in d_name */ + __uint8_t __d_padding[4]; /* suppress padding after d_name */ +#if __BSD_VISIBLE +#define MAXNAMLEN 255 + char d_name[MAXNAMLEN + 1]; /* name must be no longer than this */ +#else + char d_name[255 + 1]; /* name must be no longer than this */ +#endif +}; + +#if __BSD_VISIBLE +/* + * File types + */ +#define DT_UNKNOWN 0 +#define DT_FIFO 1 +#define DT_CHR 2 +#define DT_DIR 4 +#define DT_BLK 6 +#define DT_REG 8 +#define DT_LNK 10 +#define DT_SOCK 12 + +/* + * Convert between stat structure types and directory types. + */ +#define IFTODT(mode) (((mode) & 0170000) >> 12) +#define DTTOIF(dirtype) ((dirtype) << 12) + +#ifdef _KERNEL +/* + * The DIRENT_RECSIZE macro gives the minimum record length which will hold + * a directory entry with a name of the given length, including the terminating + * nul byte, rounded up to proper alignment. + * The DIRENT_SIZE macro does the same when given a pointer to a struct dirent + */ +#define DIRENT_RECSIZE(namelen) \ + ((offsetof(struct dirent, d_name) + (namelen) + 1 + 7) &~ 7) +#define DIRENT_SIZE(dp) \ + DIRENT_RECSIZE((dp)->d_namlen) +#endif + +#endif /* __BSD_VISIBLE */ + +#endif /* _SYS_DIRENT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/disk.h b/lib/libc/include/generic-openbsd/sys/disk.h new file mode 100644 index 0000000000..08c93668d9 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/disk.h @@ -0,0 +1,158 @@ +/* $OpenBSD: disk.h,v 1.42 2025/09/15 10:33:03 krw Exp $ */ +/* $NetBSD: disk.h,v 1.11 1996/04/28 20:22:50 thorpej Exp $ */ + +/* + * Copyright (c) 1995 Jason R. Thorpe. All rights reserved. + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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: Header: disk.h,v 1.5 92/11/19 04:33:03 torek Exp (LBL) + * + * @(#)disk.h 8.1 (Berkeley) 6/2/93 + */ + +/* + * Disk device structures. + */ + +#include +#include +#include +#include +#include + +struct disklabel; + +#define DS_DISKNAMELEN 16 + +struct diskstats { + char ds_name[DS_DISKNAMELEN]; + int ds_busy; /* busy counter */ + u_int64_t ds_rxfer; /* total number of read transfers */ + u_int64_t ds_wxfer; /* total number of write transfers */ + u_int64_t ds_seek; /* total independent seek operations */ + u_int64_t ds_rbytes; /* total bytes read */ + u_int64_t ds_wbytes; /* total bytes written */ + struct timeval ds_attachtime; /* time disk was attached */ + struct timeval ds_timestamp; /* time of first busy or any unbusy */ + struct timeval ds_time; /* total time spent busy */ +}; + +struct disk { + TAILQ_ENTRY(disk) dk_link; /* link in global disklist */ + struct rwlock dk_lock; /* disk lock */ + struct mutex dk_mtx; /* busy/unbusy mtx */ + char *dk_name; /* disk name */ + struct device *dk_device; /* disk device structure. */ + dev_t dk_devno; /* disk device number. */ + int dk_flags; /* disk flags */ +#define DKF_CONSTRUCTED 0x0001 +#define DKF_OPENED 0x0002 +#define DKF_NOLABELREAD 0x0004 + + /* + * Metrics data; note that some metrics may have no meaning + * on certain types of disks. + */ + int dk_busy; /* busy counter */ + u_int64_t dk_rxfer; /* total number of read transfers */ + u_int64_t dk_wxfer; /* total number of write transfers */ + u_int64_t dk_seek; /* total independent seek operations */ + u_int64_t dk_rbytes; /* total bytes read */ + u_int64_t dk_wbytes; /* total bytes written */ + struct timeval dk_attachtime; /* time disk was attached */ + struct timeval dk_timestamp; /* time of first busy or any unbusy */ + struct timeval dk_time; /* total time spent busy */ + + uint64_t dk_bopenmask; /* block devices open */ + uint64_t dk_copenmask; /* character devices open */ + uint64_t dk_openmask; /* composite (bopen|copen) */ + int dk_state; /* label state ### */ + int dk_blkshift; /* shift to convert DEV_BSIZE to blks*/ + int dk_byteshift; /* shift to convert bytes to blks */ + + /* + * Disk label information. Storage for the in-core disk label + * must be dynamically allocated, otherwise the size of this + * structure becomes machine-dependent. + */ + struct disklabel *dk_label; +}; + +/* states */ +#define DK_CLOSED 0 /* drive is closed */ +#define DK_WANTOPEN 1 /* drive being opened */ +#define DK_WANTOPENRAW 2 /* drive being opened */ +#define DK_RDLABEL 3 /* label being read */ +#define DK_OPEN 4 /* label read, drive open */ +#define DK_OPENRAW 5 /* open without label */ + +/* Disk map flags. */ +#define DM_OPENPART 0x1 /* Open raw partition. */ +#define DM_OPENBLCK 0x2 /* Open block device. */ + +/* + * disklist_head is defined here so that user-land has access to it. + */ +TAILQ_HEAD(disklist_head, disk); /* the disklist is a TAILQ */ + +#ifdef _KERNEL +extern struct disklist_head disklist; /* list of disks attached to system */ +extern int disk_count; /* number of disks in global disklist */ +extern int disk_change; /* disk attached/detached */ + +void disk_init(void); +int disk_construct(struct disk *); +void disk_attach(struct device *, struct disk *); +void disk_detach(struct disk *); +int disk_openpart(struct disk *, int, int, int); +void disk_closepart(struct disk *, int, int); +void disk_gone(int (*)(dev_t, int, int, struct proc *), int); +void disk_busy(struct disk *); +void disk_unbusy(struct disk *, long, daddr_t, int); + +int disk_lock(struct disk *); +void disk_lock_nointr(struct disk *); +void disk_unlock(struct disk *); +struct device *disk_lookup(struct cfdriver *, int); + +char *disk_readlabel(struct disklabel *, dev_t, char *, size_t); + +int disk_map(const char *, char *, int, int); + +int duid_iszero(u_char *); +const char *duid_format(u_char *); +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/disklabel.h b/lib/libc/include/generic-openbsd/sys/disklabel.h new file mode 100644 index 0000000000..a289bc7479 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/disklabel.h @@ -0,0 +1,482 @@ +/* $OpenBSD: disklabel.h,v 1.93 2025/09/17 10:16:09 deraadt Exp $ */ +/* $NetBSD: disklabel.h,v 1.41 1996/05/10 23:07:37 mark Exp $ */ + +/* + * Copyright (c) 1987, 1988, 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. + * + * @(#)disklabel.h 8.2 (Berkeley) 7/10/94 + */ + +/* + * Disk description table, see disktab(5) + */ +#define _PATH_DISKTAB "/etc/disktab" +#define DISKTAB "/etc/disktab" /* deprecated */ + +/* + * Each disk has a label which includes information about the hardware + * disk geometry, filesystem partitions, and drive specific information. + * The location of the label, as well as the number of partitions the + * label can describe and the number of the "whole disk" (raw) + * partition are machine dependent. + */ +#include + +#include + +/* + * Translate between device numbers and major/disk unit/disk partition. + */ +#define DISKUNIT(dev) (minor(dev) / MAXPARTITIONS) +#define DISKPART(dev) (minor(dev) % MAXPARTITIONS) +#define RAW_PART 2 /* 'c' partition */ +#define DISKMINOR(unit, part) \ + (((unit) * MAXPARTITIONS) + (part)) +#define MAKEDISKDEV(maj, unit, part) \ + (makedev((maj), DISKMINOR((unit), (part)))) +#define DISKLABELDEV(dev) \ + (MAKEDISKDEV(major(dev), DISKUNIT(dev), RAW_PART)) + +#define DISKMAGIC 0x82564557U /* The disk magic number */ + +#define MAXDISKSIZE 0x7fffffffffffLL /* 47 bits of reach */ + +#ifndef _LOCORE +struct disklabel { + u_int32_t d_magic; /* the magic number */ + u_int16_t d_type; /* drive type */ + u_int16_t d_subtype; /* controller/d_type specific */ + char d_typename[16]; /* type name, e.g. "eagle" */ + char d_packname[16]; /* pack identifier */ + + /* disk geometry: */ + u_int32_t d_secsize; /* # of bytes per sector */ + u_int32_t d_nsectors; /* # of data sectors per track */ + u_int32_t d_ntracks; /* # of tracks per cylinder */ + u_int32_t d_ncylinders; /* # of data cylinders per unit */ + u_int32_t d_secpercyl; /* # of data sectors per cylinder */ + u_int32_t d_secperunit; /* # of data sectors (low part) */ + + u_char d_uid[8]; /* Unique label identifier. */ + + /* + * Alternate cylinders include maintenance, replacement, configuration + * description areas, etc. + */ + u_int32_t d_acylinders; /* # of alt. cylinders per unit */ + + /* hardware characteristics: */ + u_int16_t d_bstarth; /* start of useable region (high part) */ + u_int16_t d_bendh; /* size of useable region (high part) */ + u_int32_t d_bstart; /* start of useable region */ + u_int32_t d_bend; /* end of useable region */ + u_int32_t d_flags; /* generic flags */ +#define NDDATA 5 + u_int32_t d_spare4[NDDATA]; + u_int16_t d_secperunith; /* # of data sectors (high part) */ + u_int16_t d_version; /* version # (1=48 bit addressing) */ +#define NSPARE 4 + u_int32_t d_spare[NSPARE]; /* reserved for future use */ + u_int32_t d_magic2; /* the magic number (again) */ + u_int16_t d_checksum; /* xor of data incl. partitions */ + + /* filesystem and partition information: */ + u_int16_t d_npartitions; /* number of partitions in following */ + u_int32_t d_spare2; + u_int32_t d_spare3; + struct partition { /* the partition table */ + u_int32_t p_size; /* number of sectors (low part) */ + u_int32_t p_offset; /* starting sector (low part) */ + u_int16_t p_offseth; /* starting sector (high part) */ + u_int16_t p_sizeh; /* number of sectors (high part) */ + u_int8_t p_fstype; /* filesystem type, see below */ + u_int8_t p_fragblock; /* encoded filesystem frag/block */ + u_int16_t p_cpg; /* UFS: FS cylinders per group */ + } d_partitions[MAXPARTITIONS]; /* actually may be more */ +}; +#endif /* _LOCORE */ + + +#define DISKLABELV1_FFS_FRAGBLOCK(fsize, frag) \ + ((fsize) * (frag) == 0 ? 0 : \ + (((ffs((fsize) * (frag)) - 13) << 3) | (ffs(frag)))) + +#define DISKLABELV1_FFS_BSIZE(i) ((i) == 0 ? 0 : (1 << (((i) >> 3) + 12))) +#define DISKLABELV1_FFS_FRAG(i) ((i) == 0 ? 0 : (1 << (((i) & 0x07) - 1))) +#define DISKLABELV1_FFS_FSIZE(i) (DISKLABELV1_FFS_FRAG(i) == 0 ? 0 : \ + (DISKLABELV1_FFS_BSIZE(i) / DISKLABELV1_FFS_FRAG(i))) + +#define DL_GETPSIZE(p) (((u_int64_t)(p)->p_sizeh << 32) + (p)->p_size) +#define DL_SETPSIZE(p, n) do { \ + u_int64_t __x = (n); \ + (p)->p_sizeh = __x >> 32; \ + (p)->p_size = __x; \ + } while (0) +#define DL_GETPOFFSET(p) (((u_int64_t)(p)->p_offseth << 32) + (p)->p_offset) +#define DL_SETPOFFSET(p, n) do { \ + u_int64_t __x = (n); \ + (p)->p_offseth = __x >> 32; \ + (p)->p_offset = __x; \ + } while (0) + +#define DL_GETDSIZE(d) (((u_int64_t)(d)->d_secperunith << 32) + \ + (d)->d_secperunit) +#define DL_SETDSIZE(d, n) do { \ + u_int64_t __x = (n); \ + (d)->d_secperunith = __x >> 32; \ + (d)->d_secperunit = __x; \ + } while (0) +#define DL_GETBSTART(d) (((u_int64_t)(d)->d_bstarth << 32) + \ + (d)->d_bstart) +#define DL_SETBSTART(d, n) do { \ + u_int64_t __x = (n); \ + (d)->d_bstarth = __x >> 32; \ + (d)->d_bstart = __x; \ + } while (0) +#define DL_GETBEND(d) (((u_int64_t)(d)->d_bendh << 32) + \ + (d)->d_bend) +#define DL_SETBEND(d, n) do { \ + u_int64_t __x = (n); \ + (d)->d_bendh = __x >> 32; \ + (d)->d_bend = __x; \ + } while (0) + +#define DL_BLKSPERSEC(d) ((d)->d_secsize / DEV_BSIZE) +#define DL_SECTOBLK(d, n) ((n) * DL_BLKSPERSEC(d)) +#define DL_BLKTOSEC(d, n) ((n) / DL_BLKSPERSEC(d)) +#define DL_BLKOFFSET(d, n) (((n) % DL_BLKSPERSEC(d)) * DEV_BSIZE) + +static __inline char +DL_PARTNUM2NAME(int partnum) +{ + if (partnum >= MAXPARTITIONS) + return -1; + if (partnum <= 'z' - 'a') + return 'a' + partnum; + else if (partnum - 26 <= 'Z' - 'A') + return 'A' + partnum - 26; + return -1; +} + +static __inline int +DL_PARTNAME2NUM(char partname) +{ + int partnum = -1; + + if (partname >= 'a' && partname <= 'z') + partnum = partname - 'a'; + else if (partname >= 'A' && partname <= 'Z') + partnum = partname - 'A' + 26; + if (partnum >= MAXPARTITIONS) + partnum = -1; + return partnum; +} + +/* d_type values: */ +#define DTYPE_SMD 1 /* SMD, XSMD; VAX hp/up */ +#define DTYPE_MSCP 2 /* MSCP */ +#define DTYPE_DEC 3 /* other DEC (rk, rl) */ +#define DTYPE_SCSI 4 /* SCSI */ +#define DTYPE_ESDI 5 /* ESDI interface */ +#define DTYPE_ST506 6 /* ST506 etc. */ +#define DTYPE_HPIB 7 /* CS/80 on HP-IB */ +#define DTYPE_HPFL 8 /* HP Fiber-link */ +#define DTYPE_FLOPPY 10 /* floppy */ +#define DTYPE_CCD 11 /* was: concatenated disk device */ +#define DTYPE_VND 12 /* vnode pseudo-disk */ +#define DTYPE_ATAPI 13 /* ATAPI */ +#define DTYPE_RAID 14 /* was: RAIDframe */ +#define DTYPE_RDROOT 15 /* ram disk root */ + +#ifdef DKTYPENAMES +static const char * const dktypenames[] = { + "unknown", + "SMD", + "MSCP", + "old DEC", + "SCSI", + "ESDI", + "ST506", + "HP-IB", + "HP-FL", + "type 9", + "floppy", + "ccd", /* deprecated */ + "vnd", + "ATAPI", + "RAID", + "rdroot", + NULL +}; +#define DKMAXTYPES (sizeof(dktypenames) / sizeof(dktypenames[0]) - 1) +#endif + +/* + * Filesystem type and version. + * Used to interpret other filesystem-specific + * per-partition information. + */ +#define FS_UNUSED 0 /* unused */ +#define FS_SWAP 1 /* swap */ +#define FS_V6 2 /* Sixth Edition */ +#define FS_V7 3 /* Seventh Edition */ +#define FS_SYSV 4 /* System V */ +#define FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */ +#define FS_V8 6 /* Eighth Edition, 4K blocks */ +#define FS_BSDFFS 7 /* 4.2BSD fast file system */ +#define FS_MSDOS 8 /* MSDOS file system */ +#define FS_BSDLFS 9 /* 4.4BSD log-structured file system */ +#define FS_OTHER 10 /* in use, but unknown/unsupported */ +#define FS_HPFS 11 /* OS/2 high-performance file system */ +#define FS_ISO9660 12 /* ISO 9660, normally CD-ROM */ +#define FS_BOOT 13 /* partition contains bootstrap */ +#define FS_ADOS 14 /* AmigaDOS fast file system */ +#define FS_HFS 15 /* Macintosh HFS */ +#define FS_ADFS 16 /* Acorn Disk Filing System */ +#define FS_EXT2FS 17 /* ext2fs */ +#define FS_CCD 18 /* ccd component */ +#define FS_RAID 19 /* RAIDframe or softraid */ +#define FS_NTFS 20 /* Windows/NT file system */ +#define FS_UDF 21 /* UDF (DVD) filesystem */ + +#ifdef DKTYPENAMES +static const char * const fstypenames[] = { + "unused", + "swap", + "Version6", + "Version7", + "SystemV", + "4.1BSD", + "Eighth-Edition", + "4.2BSD", + "MSDOS", + "4.4LFS", + "unknown", + "HPFS", + "ISO9660", + "boot", + "ADOS", + "HFS", + "ADFS", + "ext2fs", + "ccd", + "RAID", + "NTFS", + "UDF", + NULL +}; + +/* Similar to the above, but used for things like the mount command. */ +static char *fstypesnames[] = { + "", /* 0 */ + "", /* 1 */ + "", /* 2 */ + "", /* 3 */ + "", /* 4 */ + "", /* 5 */ + "", /* 6 */ + "ffs", /* 7 */ + "msdos", /* 8 */ + "lfs", /* 9 */ + "", /* 10 */ + "", /* 11 */ + "cd9660", /* 12 */ + "", /* 13 */ + "ados", /* 14 */ + "", /* 15 */ + "", /* 16 */ + "ext2fs", /* 17 */ + "", /* 18 */ + "", /* 19 */ + "ntfs", /* 20 */ + "udf", /* 21 */ + NULL +}; + +#define FSMAXTYPES (sizeof(fstypenames) / sizeof(fstypenames[0]) - 1) +#endif + +/* + * flags shared by various drives: + */ +#define D_VENDOR 0x08 /* vendor disklabel */ + +#ifndef _LOCORE +/* + * Structure used internally to retrieve information about a partition + * on a disk. + */ +struct partinfo { + struct disklabel *disklab; + struct partition *part; +}; + +/* GUID partition table -- located at sector 1 of some disks. */ +#define GPTSECTOR 1 /* DOS boot block relative sector # */ +#define GPTSIGNATURE 0x5452415020494645LL + /* ASCII string "EFI PART" encoded as 64-bit */ +#define GPTREVISION 0x10000 /* GPT header version 1.0 */ +#define NGPTPARTITIONS 128 +#define GPTPARTATTR_REQUIRED (1ULL << 0) +#define GPTPARTATTR_IGNORE (1ULL << 1) +#define GPTPARTATTR_BOOTABLE (1ULL << 2) +#define GPTPARTATTR_MS_READONLY (1ULL << 60) +#define GPTPARTATTR_MS_SHADOW (1ULL << 61) +#define GPTPARTATTR_MS_HIDDEN (1ULL << 62) +#define GPTPARTATTR_MS_NOAUTOMOUNT (1ULL << 63) + +#define GPTMINHDRSIZE 92 +#define GPTMINPARTSIZE 128 +#define GPTPARTNAMESIZE 36 + +/* all values in the GPT need to be little endian as per UEFI specification */ +struct gpt_header { + u_int64_t gh_sig; /* "EFI PART" */ + u_int32_t gh_rev; /* GPT Version 1.0: 0x00000100 */ + u_int32_t gh_size; /* Little-Endian */ + u_int32_t gh_csum; /* CRC32: with this field as 0 */ + u_int32_t gh_rsvd; /* always zero */ + u_int64_t gh_lba_self; /* LBA of this header */ + u_int64_t gh_lba_alt; /* LBA of alternate header */ + u_int64_t gh_lba_start; /* first usable LBA */ + u_int64_t gh_lba_end; /* last usable LBA */ + struct uuid gh_guid; /* disk GUID used to identify the disk */ + u_int64_t gh_part_lba; /* starting LBA of GPT partition entries */ + u_int32_t gh_part_num; /* # of partition entries */ + u_int32_t gh_part_size; /* size per entry, shall be 128*(2**n) + with n >= 0 */ + u_int32_t gh_part_csum; /* CRC32 checksum of all partition entries: + * starts at gh_part_lba and is computed over + * a byte length of gh_part_num*gh_part_size */ + /* the rest of the block is reserved by UEFI and must be zero */ +}; + +struct gpt_partition { + struct uuid gp_type; /* partition type GUID */ + struct uuid gp_guid; /* unique partition GUID */ + u_int64_t gp_lba_start; /* starting LBA of this partition */ + u_int64_t gp_lba_end; /* ending LBA of this partition, inclusive, + usually odd */ + u_int64_t gp_attrs; /* attribute flags */ + u_int16_t gp_name[GPTPARTNAMESIZE]; /* partition name, utf-16le */ + /* the rest of the GPT partition entry, if any, is reserved by UEFI + and must be zero */ +}; + +#define GPT_UUID_EFI_SYSTEM \ + { 0xc1, 0x2a, 0x73, 0x28, 0xf8, 0x1f, 0x11, 0xd2, \ + 0xba, 0x4b, 0x00, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b } +#define GPT_UUID_OPENBSD \ + { 0x82, 0x4c, 0xc7, 0xa0, 0x36, 0xa8, 0x11, 0xe3, \ + 0x89, 0x0a, 0x95, 0x25, 0x19, 0xad, 0x3f, 0x61 } + +/* DOS partition table -- located at start of some disks. */ +#define DOS_LABELSECTOR 1 +#define DOSBBSECTOR 0 /* DOS boot block relative sector # */ +#define DOSPARTOFF 446 +#define DOSDISKOFF 444 +#define NDOSPART 4 +#define DOSACTIVE 0x80 /* active partition */ + +#define DOSMBR_SIGNATURE (0xaa55) +#define DOSMBR_SIGNATURE_OFF (0x1fe) + +/* Maximum number of Extended Boot Records (EBRs) to traverse. */ +#define DOS_MAXEBR 256 + +struct dos_partition { + u_int8_t dp_flag; /* bootstrap flags */ + u_int8_t dp_shd; /* starting head */ + u_int8_t dp_ssect; /* starting sector */ + u_int8_t dp_scyl; /* starting cylinder */ + u_int8_t dp_typ; /* partition type (see below) */ + u_int8_t dp_ehd; /* end head */ + u_int8_t dp_esect; /* end sector */ + u_int8_t dp_ecyl; /* end cylinder */ + u_int32_t dp_start; /* absolute starting sector number */ + u_int32_t dp_size; /* partition size in sectors */ +}; + +/* Known DOS partition types. */ +#define DOSPTYP_UNUSED 0x00 /* Unused partition */ +#define DOSPTYP_FAT12 0x01 /* 12-bit FAT */ +#define DOSPTYP_FAT16S 0x04 /* 16-bit FAT, less than 32M */ +#define DOSPTYP_EXTEND 0x05 /* Extended; contains sub-partitions */ +#define DOSPTYP_FAT16B 0x06 /* 16-bit FAT, more than 32M */ +#define DOSPTYP_NTFS 0x07 /* NTFS */ +#define DOSPTYP_FAT32 0x0b /* 32-bit FAT */ +#define DOSPTYP_FAT32L 0x0c /* 32-bit FAT, LBA-mapped */ +#define DOSPTYP_FAT16L 0x0e /* 16-bit FAT, LBA-mapped */ +#define DOSPTYP_EXTENDL 0x0f /* Extended, LBA-mapped; (sub-partitions) */ +#define DOSPTYP_ONTRACK 0x54 +#define DOSPTYP_LINUX 0x83 /* That other thing */ +#define DOSPTYP_FREEBSD 0xa5 /* FreeBSD partition type */ +#define DOSPTYP_OPENBSD 0xa6 /* OpenBSD partition type */ +#define DOSPTYP_NETBSD 0xa9 /* NetBSD partition type */ +#define DOSPTYP_EFI 0xee /* EFI Protective Partition */ +#define DOSPTYP_EFISYS 0xef /* EFI System Partition */ + +struct dos_mbr { + u_int8_t dmbr_boot[DOSPARTOFF]; + struct dos_partition dmbr_parts[NDOSPART]; + u_int16_t dmbr_sign; +} __packed; + +#ifdef _KERNEL +void diskerr(struct buf *, char *, char *, int, int, struct disklabel *); +u_int dkcksum(struct disklabel *); +int initdisklabel(struct disklabel *); +int checkdisklabel(dev_t, void *, struct disklabel *, u_int64_t, u_int64_t); +int setdisklabel(struct disklabel *, struct disklabel *, u_int64_t); +int readdisklabel(dev_t, void (*)(struct buf *), struct disklabel *, int); +int writedisklabel(dev_t, void (*)(struct buf *), struct disklabel *); +int bounds_check_with_label(struct buf *, struct disklabel *); +int readdisksector(struct buf *, void (*)(struct buf *), + struct disklabel *, u_int64_t); +int readdoslabel(struct buf *, void (*)(struct buf *), + struct disklabel *, daddr_t *, int); +#ifdef CD9660 +int iso_disklabelspoof(dev_t dev, void (*strat)(struct buf *), + struct disklabel *lp); +#endif +#ifdef UDF +int udf_disklabelspoof(dev_t dev, void (*strat)(struct buf *), + struct disklabel *lp); +#endif +#endif +#endif /* _LOCORE */ + +#if !defined(_KERNEL) && !defined(_LOCORE) + +#include + +__BEGIN_DECLS +struct disklabel *getdiskbyname(const char *); +__END_DECLS + +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/dkio.h b/lib/libc/include/generic-openbsd/sys/dkio.h new file mode 100644 index 0000000000..e283329b75 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/dkio.h @@ -0,0 +1,86 @@ +/* $OpenBSD: dkio.h,v 1.13 2025/09/17 10:24:25 deraadt Exp $ */ +/* $NetBSD: dkio.h,v 1.1 1996/01/30 18:21:48 thorpej Exp $ */ + +/* + * Copyright (c) 1987, 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _SYS_DKIO_H_ +#define _SYS_DKIO_H_ + +#include + +/* + * Disk-specific ioctls. + */ + /* get and set disklabel; DIOCGPART used internally */ +#define DIOCGDINFO _IOR('d', 101, struct disklabel)/* get */ +#define DIOCSDINFO _IOW('d', 102, struct disklabel)/* set */ +#define DIOCWDINFO _IOW('d', 103, struct disklabel)/* set, update disk */ +#define DIOCGPART _IOW('d', 104, struct partinfo) /* get partition */ + +#define DIOCEJECT _IO('d', 112) /* eject removable disk */ +#define DIOCLOCK _IOW('d', 113, int) /* lock/unlock pack */ + +#define DIOCGPDINFO _IOR('d', 114, struct disklabel)/* get physical */ +#define DIOCRLDINFO _IO('d', 115) /* reload disklabel */ + +#if MAXPARTITIONS != 16 +/* XXX temporary to support the transition to more partitions */ +#define O_sizeof_disklabel (offsetof(struct disklabel, d_partitions[16])) +#define O_DIOCGDINFO _IOC(IOC_OUT, 'd', 101, O_sizeof_disklabel) +#endif + +struct dk_inquiry { + char vendor[64]; + char product[128]; + char revision[64]; + char serial[64]; +}; + +#define DIOCINQ _IOR('d', 116, struct dk_inquiry) + +struct dk_cache { + unsigned int wrcache; + unsigned int rdcache; +}; + +#define DIOCGCACHE _IOR('d', 117, struct dk_cache) /* get cache enabled */ +#define DIOCSCACHE _IOW('d', 118, struct dk_cache) /* set cache enabled */ + +struct dk_diskmap { + char *device; + int fd; + int flags; +}; + +#define DIOCMAP _IOWR('d', 119, struct dk_diskmap) + +#define DIOCCACHESYNC _IOW('d', 120, int) /* sync cache (force?) */ + +#endif /* _SYS_DKIO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/domain.h b/lib/libc/include/generic-openbsd/sys/domain.h new file mode 100644 index 0000000000..e33db12f71 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/domain.h @@ -0,0 +1,74 @@ +/* $OpenBSD: domain.h,v 1.25 2024/10/26 05:39:03 jsg Exp $ */ +/* $NetBSD: domain.h,v 1.10 1996/02/09 18:25:07 christos Exp $ */ + +/* + * Copyright (c) 1982, 1986, 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. + * + * @(#)domain.h 8.1 (Berkeley) 6/2/93 + */ + +/* + * Structure per communications domain. + */ + +#ifndef _SOCKLEN_T_DEFINED_ +#define _SOCKLEN_T_DEFINED_ +typedef __socklen_t socklen_t; /* length type for network syscalls */ +#endif + +/* + * Forward structure declarations for function prototypes [sic]. + */ +struct mbuf; + +struct domain { + int dom_family; /* AF_xxx */ + const char *dom_name; + void (*dom_init)(void); /* initialize domain data structures */ + /* externalize access rights */ + int (*dom_externalize)(struct mbuf *, socklen_t, int); + /* dispose of internalized rights */ + void (*dom_dispose)(struct mbuf *); + const struct protosw *dom_protosw, *dom_protoswNPROTOSW; + /* initialize routing table */ + unsigned int dom_sasize; /* size of sockaddr structure */ + unsigned int dom_rtoffset; /* offset of the key, in bytes */ + unsigned int dom_maxplen; /* maximum prefix length, in bits */ +}; + +#ifdef _KERNEL +void domaininit(void); + +extern const struct domain *const domains[]; +extern const struct domain inet6domain; +extern const struct domain inetdomain; +extern const struct domain mplsdomain; +extern const struct domain pfkeydomain; +extern const struct domain routedomain; +extern const struct domain unixdomain; +#endif /* _KERNEL */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/endian.h b/lib/libc/include/generic-openbsd/sys/endian.h new file mode 100644 index 0000000000..f4328aa9de --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/endian.h @@ -0,0 +1,124 @@ +/* $OpenBSD: endian.h,v 1.25 2014/12/21 04:49:00 guenther 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. + */ + +/* + * Public definitions for little- and big-endian systems. + * This file should be included as in userspace and as + * in the kernel. + * + * System headers that need endian information but that can't or don't + * want to export the public names here should include + * and use the internal names: _BYTE_ORDER, _*_ENDIAN, etc. + */ + +#ifndef _SYS_ENDIAN_H_ +#define _SYS_ENDIAN_H_ + +#include +#include + +/* Public names */ +#define LITTLE_ENDIAN _LITTLE_ENDIAN +#define BIG_ENDIAN _BIG_ENDIAN +#define PDP_ENDIAN _PDP_ENDIAN +#define BYTE_ORDER _BYTE_ORDER + + +/* + * These are specified to be function-like macros to match the spec + */ +#define htobe16(x) __htobe16(x) +#define htobe32(x) __htobe32(x) +#define htobe64(x) __htobe64(x) +#define htole16(x) __htole16(x) +#define htole32(x) __htole32(x) +#define htole64(x) __htole64(x) + +/* POSIX names */ +#define be16toh(x) __htobe16(x) +#define be32toh(x) __htobe32(x) +#define be64toh(x) __htobe64(x) +#define le16toh(x) __htole16(x) +#define le32toh(x) __htole32(x) +#define le64toh(x) __htole64(x) + + +#if __BSD_VISIBLE +#define swap16(x) __swap16(x) +#define swap32(x) __swap32(x) +#define swap64(x) __swap64(x) + +#define swap16_multi(v, n) do { \ + __size_t __swap16_multi_n = (n); \ + __uint16_t *__swap16_multi_v = (v); \ + \ + while (__swap16_multi_n) { \ + *__swap16_multi_v = swap16(*__swap16_multi_v); \ + __swap16_multi_v++; \ + __swap16_multi_n--; \ + } \ +} while (0) + +/* original BSD names */ +#define betoh16(x) __htobe16(x) +#define betoh32(x) __htobe32(x) +#define betoh64(x) __htobe64(x) +#define letoh16(x) __htole16(x) +#define letoh32(x) __htole32(x) +#define letoh64(x) __htole64(x) + +#ifndef htons +/* these were exposed here before */ +#define htons(x) __htobe16(x) +#define htonl(x) __htobe32(x) +#define ntohs(x) __htobe16(x) +#define ntohl(x) __htobe32(x) +#endif + +/* ancient stuff */ +#define NTOHL(x) (x) = ntohl((u_int32_t)(x)) +#define NTOHS(x) (x) = ntohs((u_int16_t)(x)) +#define HTONL(x) (x) = htonl((u_int32_t)(x)) +#define HTONS(x) (x) = htons((u_int16_t)(x)) +#endif /* __BSD_VISIBLE */ + +#ifdef _KERNEL +/* to/from memory conversions */ +#define bemtoh16 __bemtoh16 +#define bemtoh32 __bemtoh32 +#define bemtoh64 __bemtoh64 +#define htobem16 __htobem16 +#define htobem32 __htobem32 +#define htobem64 __htobem64 +#define lemtoh16 __lemtoh16 +#define lemtoh32 __lemtoh32 +#define lemtoh64 __lemtoh64 +#define htolem16 __htolem16 +#define htolem32 __htolem32 +#define htolem64 __htolem64 +#endif /* _KERNEL */ + +#endif /* _SYS_ENDIAN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/errno.h b/lib/libc/include/generic-openbsd/sys/errno.h new file mode 100644 index 0000000000..220cdf23f6 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/errno.h @@ -0,0 +1,182 @@ +/* $OpenBSD: errno.h,v 1.25 2017/09/05 03:06:26 jsg Exp $ */ +/* $NetBSD: errno.h,v 1.10 1996/01/20 01:33:53 jtc Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)errno.h 8.5 (Berkeley) 1/21/94 + */ + +#include + +#define EPERM 1 /* Operation not permitted */ +#define ENOENT 2 /* No such file or directory */ +#define ESRCH 3 /* No such process */ +#define EINTR 4 /* Interrupted system call */ +#define EIO 5 /* Input/output error */ +#define ENXIO 6 /* Device not configured */ +#define E2BIG 7 /* Argument list too long */ +#define ENOEXEC 8 /* Exec format error */ +#define EBADF 9 /* Bad file descriptor */ +#define ECHILD 10 /* No child processes */ +#define EDEADLK 11 /* Resource deadlock avoided */ + /* 11 was EAGAIN */ +#define ENOMEM 12 /* Cannot allocate memory */ +#define EACCES 13 /* Permission denied */ +#define EFAULT 14 /* Bad address */ +#if __BSD_VISIBLE +#define ENOTBLK 15 /* Block device required */ +#endif +#define EBUSY 16 /* Device busy */ +#define EEXIST 17 /* File exists */ +#define EXDEV 18 /* Cross-device link */ +#define ENODEV 19 /* Operation not supported by device */ +#define ENOTDIR 20 /* Not a directory */ +#define EISDIR 21 /* Is a directory */ +#define EINVAL 22 /* Invalid argument */ +#define ENFILE 23 /* Too many open files in system */ +#define EMFILE 24 /* Too many open files */ +#define ENOTTY 25 /* Inappropriate ioctl for device */ +#define ETXTBSY 26 /* Text file busy */ +#define EFBIG 27 /* File too large */ +#define ENOSPC 28 /* No space left on device */ +#define ESPIPE 29 /* Illegal seek */ +#define EROFS 30 /* Read-only file system */ +#define EMLINK 31 /* Too many links */ +#define EPIPE 32 /* Broken pipe */ + +/* math software */ +#define EDOM 33 /* Numerical argument out of domain */ +#define ERANGE 34 /* Result too large */ + +/* non-blocking and interrupt i/o */ +#define EAGAIN 35 /* Resource temporarily unavailable */ +#define EWOULDBLOCK EAGAIN /* Operation would block */ +#define EINPROGRESS 36 /* Operation now in progress */ +#define EALREADY 37 /* Operation already in progress */ + +/* ipc/network software -- argument errors */ +#define ENOTSOCK 38 /* Socket operation on non-socket */ +#define EDESTADDRREQ 39 /* Destination address required */ +#define EMSGSIZE 40 /* Message too long */ +#define EPROTOTYPE 41 /* Protocol wrong type for socket */ +#define ENOPROTOOPT 42 /* Protocol not available */ +#define EPROTONOSUPPORT 43 /* Protocol not supported */ +#if __BSD_VISIBLE +#define ESOCKTNOSUPPORT 44 /* Socket type not supported */ +#endif +#define EOPNOTSUPP 45 /* Operation not supported */ +#if __BSD_VISIBLE +#define EPFNOSUPPORT 46 /* Protocol family not supported */ +#endif +#define EAFNOSUPPORT 47 /* Address family not supported by protocol family */ +#define EADDRINUSE 48 /* Address already in use */ +#define EADDRNOTAVAIL 49 /* Can't assign requested address */ + +/* ipc/network software -- operational errors */ +#define ENETDOWN 50 /* Network is down */ +#define ENETUNREACH 51 /* Network is unreachable */ +#define ENETRESET 52 /* Network dropped connection on reset */ +#define ECONNABORTED 53 /* Software caused connection abort */ +#define ECONNRESET 54 /* Connection reset by peer */ +#define ENOBUFS 55 /* No buffer space available */ +#define EISCONN 56 /* Socket is already connected */ +#define ENOTCONN 57 /* Socket is not connected */ +#if __BSD_VISIBLE +#define ESHUTDOWN 58 /* Can't send after socket shutdown */ +#define ETOOMANYREFS 59 /* Too many references: can't splice */ +#endif /* __BSD_VISIBLE */ +#define ETIMEDOUT 60 /* Operation timed out */ +#define ECONNREFUSED 61 /* Connection refused */ + +#define ELOOP 62 /* Too many levels of symbolic links */ +#define ENAMETOOLONG 63 /* File name too long */ + +/* should be rearranged */ +#if __BSD_VISIBLE +#define EHOSTDOWN 64 /* Host is down */ +#endif /* __BSD_VISIBLE */ +#define EHOSTUNREACH 65 /* No route to host */ +#define ENOTEMPTY 66 /* Directory not empty */ + +/* quotas & mush */ +#if __BSD_VISIBLE +#define EPROCLIM 67 /* Too many processes */ +#define EUSERS 68 /* Too many users */ +#endif /* __BSD_VISIBLE */ +#define EDQUOT 69 /* Disk quota exceeded */ + +/* Network File System */ +#define ESTALE 70 /* Stale NFS file handle */ +#if __BSD_VISIBLE +#define EREMOTE 71 /* Too many levels of remote in path */ +#define EBADRPC 72 /* RPC struct is bad */ +#define ERPCMISMATCH 73 /* RPC version wrong */ +#define EPROGUNAVAIL 74 /* RPC program not available */ +#define EPROGMISMATCH 75 /* Program version wrong */ +#define EPROCUNAVAIL 76 /* Bad procedure for program */ +#endif /* __BSD_VISIBLE */ + +#define ENOLCK 77 /* No locks available */ +#define ENOSYS 78 /* Function not implemented */ + +#if __BSD_VISIBLE +#define EFTYPE 79 /* Inappropriate file type or format */ +#define EAUTH 80 /* Authentication error */ +#define ENEEDAUTH 81 /* Need authenticator */ +#define EIPSEC 82 /* IPsec processing failure */ +#define ENOATTR 83 /* Attribute not found */ +#endif /* __BSD_VISIBLE */ +#define EILSEQ 84 /* Illegal byte sequence */ +#if __BSD_VISIBLE +#define ENOMEDIUM 85 /* No medium found */ +#define EMEDIUMTYPE 86 /* Wrong medium type */ +#endif /* __BSD_VISIBLE */ +#define EOVERFLOW 87 /* Value too large to be stored in data type */ +#define ECANCELED 88 /* Operation canceled */ +#define EIDRM 89 /* Identifier removed */ +#define ENOMSG 90 /* No message of desired type */ +#define ENOTSUP 91 /* Not supported */ +#define EBADMSG 92 /* Bad message */ +#define ENOTRECOVERABLE 93 /* State not recoverable */ +#define EOWNERDEAD 94 /* Previous owner died */ +#define EPROTO 95 /* Protocol error */ +#if __BSD_VISIBLE +#define ELAST 95 /* Must be equal largest errno */ +#endif /* __BSD_VISIBLE */ + +#ifdef _KERNEL +/* pseudo-errors returned inside kernel to modify return to process */ +#define ERESTART -1 /* restart syscall */ +#define EJUSTRETURN -2 /* don't modify regs, just return */ +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/evcount.h b/lib/libc/include/generic-openbsd/sys/evcount.h new file mode 100644 index 0000000000..fa3d1e40cd --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/evcount.h @@ -0,0 +1,56 @@ +/* $OpenBSD: evcount.h,v 1.4 2022/11/10 07:05:41 jmatthew Exp $ */ +/* + * Copyright (c) 2004 Artur Grabowski + * Copyright (c) 2004 Aaron Campbell + * 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. 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 ``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 __SYS_EVCOUNT_H__ +#define __SYS_EVCOUNT_H__ + +#ifdef _KERNEL + +#include + +struct cpumem; + +struct evcount { + u_int64_t ec_count; /* main counter */ + int ec_id; /* counter ID */ + const char *ec_name; /* counter name */ + void *ec_data; /* user data */ + struct cpumem *ec_percpu; /* per-cpu counter */ + + TAILQ_ENTRY(evcount) next; +}; + +void evcount_attach(struct evcount *, const char *, void *); +void evcount_detach(struct evcount *); +void evcount_inc(struct evcount *); +void evcount_init_percpu(void); +void evcount_percpu(struct evcount *); +int evcount_sysctl(int *, u_int, void *, size_t *, void *, size_t); + +#endif /* _KERNEL */ + +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/event.h b/lib/libc/include/generic-openbsd/sys/event.h new file mode 100644 index 0000000000..4235efa23b --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/event.h @@ -0,0 +1,395 @@ +/* $OpenBSD: event.h,v 1.74 2025/05/10 09:44:39 visa Exp $ */ + +/*- + * Copyright (c) 1999,2000,2001 Jonathan Lemon + * 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 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/event.h,v 1.11 2001/02/24 01:41:31 jlemon Exp $ + */ + +#ifndef _SYS_EVENT_H_ +#define _SYS_EVENT_H_ + +#define EVFILT_READ (-1) +#define EVFILT_WRITE (-2) +#define EVFILT_AIO (-3) /* attached to aio requests */ +#define EVFILT_VNODE (-4) /* attached to vnodes */ +#define EVFILT_PROC (-5) /* attached to struct process */ +#define EVFILT_SIGNAL (-6) /* attached to struct process */ +#define EVFILT_TIMER (-7) /* timers */ +#define EVFILT_DEVICE (-8) /* devices */ +#define EVFILT_EXCEPT (-9) /* exceptional conditions */ +#define EVFILT_USER (-10) /* user event */ + +#define EVFILT_SYSCOUNT 10 + +#define EV_SET(kevp, a, b, c, d, e, f) do { \ + struct kevent *__kevp = (kevp); \ + (__kevp)->ident = (a); \ + (__kevp)->filter = (b); \ + (__kevp)->flags = (c); \ + (__kevp)->fflags = (d); \ + (__kevp)->data = (e); \ + (__kevp)->udata = (f); \ +} while(0) + +struct kevent { + __uintptr_t ident; /* identifier for this event */ + short filter; /* filter for event */ + unsigned short flags; /* action flags for kqueue */ + unsigned int fflags; /* filter flag value */ + __int64_t data; /* filter data value */ + void *udata; /* opaque user data identifier */ +}; + +/* actions */ +#define EV_ADD 0x0001 /* add event to kq (implies enable) */ +#define EV_DELETE 0x0002 /* delete event from kq */ +#define EV_ENABLE 0x0004 /* enable event */ +#define EV_DISABLE 0x0008 /* disable event (not reported) */ + +/* flags */ +#define EV_ONESHOT 0x0010 /* only report one occurrence */ +#define EV_CLEAR 0x0020 /* clear event state after reporting */ +#define EV_RECEIPT 0x0040 /* force EV_ERROR on success, data=0 */ +#define EV_DISPATCH 0x0080 /* disable event after reporting */ + +#define EV_SYSFLAGS 0xf800 /* reserved by system */ +#define EV_FLAG1 0x2000 /* filter-specific flag */ + +/* returned values */ +#define EV_EOF 0x8000 /* EOF detected */ +#define EV_ERROR 0x4000 /* error, data contains errno */ + +/* + * data/hint flags for EVFILT_{READ|WRITE}, shared with userspace + */ +#define NOTE_LOWAT 0x0001 /* low water mark */ +#define NOTE_EOF 0x0002 /* return on EOF */ + +/* + * data/hint flags for EVFILT_EXCEPT, shared with userspace and with + * EVFILT_{READ|WRITE} + */ +#define NOTE_OOB 0x0004 /* OOB data on a socket */ + +/* + * data/hint flags for EVFILT_VNODE, shared with userspace + */ +#define NOTE_DELETE 0x0001 /* vnode was removed */ +#define NOTE_WRITE 0x0002 /* data contents changed */ +#define NOTE_EXTEND 0x0004 /* size increased */ +#define NOTE_ATTRIB 0x0008 /* attributes changed */ +#define NOTE_LINK 0x0010 /* link count changed */ +#define NOTE_RENAME 0x0020 /* vnode was renamed */ +#define NOTE_REVOKE 0x0040 /* vnode access was revoked */ +#define NOTE_TRUNCATE 0x0080 /* vnode was truncated */ + +/* + * data/hint flags for EVFILT_PROC, shared with userspace + */ +#define NOTE_EXIT 0x80000000 /* process exited */ +#define NOTE_FORK 0x40000000 /* process forked */ +#define NOTE_EXEC 0x20000000 /* process exec'd */ +#define NOTE_PCTRLMASK 0xf0000000 /* mask for hint bits */ +#define NOTE_PDATAMASK 0x000fffff /* mask for pid */ + +/* additional flags for EVFILT_PROC */ +#define NOTE_TRACK 0x00000001 /* follow across forks */ +#define NOTE_TRACKERR 0x00000002 /* could not track child */ +#define NOTE_CHILD 0x00000004 /* am a child process */ + +/* data/hint flags for EVFILT_DEVICE, shared with userspace */ +#define NOTE_CHANGE 0x00000001 /* device change event */ + +/* additional flags for EVFILT_TIMER */ +#define NOTE_MSECONDS 0x00000000 /* data is milliseconds */ +#define NOTE_SECONDS 0x00000001 /* data is seconds */ +#define NOTE_USECONDS 0x00000002 /* data is microseconds */ +#define NOTE_NSECONDS 0x00000003 /* data is nanoseconds */ +#define NOTE_ABSTIME 0x00000010 /* timeout is absolute */ + +/* + * data/hint flags for EVFILT_USER, shared with userspace + */ +#define NOTE_FFNOP 0x00000000 /* ignore input fflags */ +#define NOTE_FFAND 0x40000000 /* AND fflags */ +#define NOTE_FFOR 0x80000000 /* OR fflags */ +#define NOTE_FFCOPY 0xc0000000 /* copy fflags */ + +#define NOTE_FFCTRLMASK 0xc0000000 /* masks for operations */ +#define NOTE_FFLAGSMASK 0x00ffffff + +#define NOTE_TRIGGER 0x01000000 /* trigger the event */ + +/* + * This is currently visible to userland to work around broken + * programs which pull in or . + */ +#include + +struct klistops; +struct knote; +SLIST_HEAD(knlist, knote); + +struct klist { + struct knlist kl_list; + const struct klistops *kl_ops; + void *kl_arg; +}; + +#ifdef _KERNEL + +/* kernel-only flags */ +#define __EV_SELECT 0x0800 /* match behavior of select */ +#define __EV_POLL 0x1000 /* match behavior of poll */ +#define __EV_HUP EV_FLAG1 /* device or socket disconnected */ + +#define EVFILT_MARKER 0xf /* placemarker for tailq */ + +/* + * hint flag for in-kernel use - must not equal any existing note + */ +#define NOTE_SUBMIT 0x01000000 /* initial knote submission */ + +#define KN_HASHSIZE 64 /* XXX should be tunable */ + +/* + * Flag indicating hint is a signal. Used by EVFILT_SIGNAL, and also + * shared by EVFILT_PROC (all knotes attached to p->p_klist) + */ +#define NOTE_SIGNAL 0x08000000 + +/* + * = Event filter interface + * + * == .f_flags + * + * Defines properties of the event filter: + * + * - FILTEROP_ISFD Each knote of this filter is associated + * with a file descriptor. + * + * - FILTEROP_MPSAFE The kqueue subsystem can invoke .f_attach(), + * .f_detach(), .f_modify() and .f_process() without + * the kernel lock. + * + * == .f_attach() + * + * Attaches the knote to the object. + * + * == .f_detach() + * + * Detaches the knote from the object. The object must not use this knote + * for delivering events after this callback has returned. + * + * == .f_event() + * + * Notifies the filter about an event. Called through knote(). + * + * == .f_modify() + * + * Modifies the knote with new state from the user. + * + * Returns non-zero if the knote has become active. + * + * == .f_process() + * + * Checks if the event is active and returns non-zero if the event should be + * returned to the user. + * + * If kev is non-NULL and the event is active, the callback should store + * the event's state in kev for delivery to the user. + * + * == Concurrency control + * + * The kqueue subsystem serializes calls of .f_attach(), .f_detach(), + * .f_modify() and .f_process(). + */ + +#define FILTEROP_ISFD 0x00000001 /* ident == filedescriptor */ +#define FILTEROP_MPSAFE 0x00000002 /* safe without kernel lock */ + +struct filterops { + int f_flags; + int (*f_attach)(struct knote *kn); + void (*f_detach)(struct knote *kn); + int (*f_event)(struct knote *kn, long hint); + int (*f_modify)(struct kevent *kev, struct knote *kn); + int (*f_process)(struct knote *kn, struct kevent *kev); +}; + +/* + * Locking: + * I immutable after creation + * o object lock + * q kn_kq->kq_lock + */ +struct knote { + SLIST_ENTRY(knote) kn_link; /* for fd */ + SLIST_ENTRY(knote) kn_selnext; /* for struct selinfo */ + TAILQ_ENTRY(knote) kn_tqe; + struct kqueue *kn_kq; /* [I] which queue we are on */ + struct kevent kn_kevent; + int kn_status; /* [q] */ + int kn_sfflags; /* [o] saved filter flags */ + __int64_t kn_sdata; /* [o] saved data field */ + union { + struct file *p_fp; /* file data pointer */ + struct process *p_process; /* process pointer */ + int p_useract; /* user event active */ + } kn_ptr; + const struct filterops *kn_fop; + void *kn_hook; /* [o] */ + unsigned int kn_pollid; /* [I] */ + +#define KN_ACTIVE 0x0001 /* event has been triggered */ +#define KN_QUEUED 0x0002 /* event is on queue */ +#define KN_DISABLED 0x0004 /* event is disabled */ +#define KN_DETACHED 0x0008 /* knote is detached */ +#define KN_PROCESSING 0x0010 /* knote is being processed */ +#define KN_WAITING 0x0020 /* waiting on processing */ + +#define kn_id kn_kevent.ident /* [I] */ +#define kn_filter kn_kevent.filter /* [I] */ +#define kn_flags kn_kevent.flags /* [o] */ +#define kn_fflags kn_kevent.fflags /* [o] */ +#define kn_data kn_kevent.data /* [o] */ +#define kn_udata kn_kevent.udata /* [o] */ +#define kn_fp kn_ptr.p_fp /* [o] */ +}; + +struct klistops { + void (*klo_assertlk)(void *); + int (*klo_lock)(void *); + void (*klo_unlock)(void *, int); +}; + +struct kqueue_scan_state { + struct kqueue *kqs_kq; /* kqueue of this scan */ + struct knote kqs_start; /* start marker */ + struct knote kqs_end; /* end marker */ + int kqs_nevent; /* number of events collected */ + int kqs_queued; /* if set, end marker is + * in queue */ +}; + +struct mutex; +struct proc; +struct rwlock; +struct timespec; + +extern const struct filterops dead_filtops; + +extern void kqpoll_init(unsigned int); +extern void kqpoll_done(unsigned int); +extern void kqpoll_exit(void); +extern void knote(struct klist *list, long hint); +extern void knote_locked(struct klist *list, long hint); +extern void knote_fdclose(struct proc *p, int fd); +extern void knote_processexit(struct process *); +extern void knote_processfork(struct process *, pid_t); +extern void knote_assign(const struct kevent *, struct knote *); +extern void knote_submit(struct knote *, struct kevent *); +extern void kqueue_init(void); +extern void kqueue_init_percpu(void); +extern int kqueue_register(struct kqueue *kq, struct kevent *kev, + unsigned int pollid, struct proc *p); +extern int kqueue_scan(struct kqueue_scan_state *, int, struct kevent *, + struct timespec *, struct proc *, int *); +extern void kqueue_scan_setup(struct kqueue_scan_state *, struct kqueue *); +extern void kqueue_scan_finish(struct kqueue_scan_state *); +extern int filt_seltrue(struct knote *kn, long hint); +extern int seltrue_kqfilter(dev_t, struct knote *); +extern void klist_init(struct klist *, const struct klistops *, void *); +extern void klist_init_mutex(struct klist *, struct mutex *); +extern void klist_init_rwlock(struct klist *, struct rwlock *); +extern void klist_free(struct klist *); +extern void klist_insert(struct klist *, struct knote *); +extern void klist_insert_locked(struct klist *, struct knote *); +extern void klist_remove(struct klist *, struct knote *); +extern void klist_remove_locked(struct klist *, struct knote *); +extern void klist_invalidate(struct klist *); + +static inline int +knote_modify_fn(const struct kevent *kev, struct knote *kn, + int (*f_event)(struct knote *, long)) +{ + knote_assign(kev, kn); + return ((*f_event)(kn, 0)); +} + +static inline int +knote_modify(const struct kevent *kev, struct knote *kn) +{ + return (knote_modify_fn(kev, kn, kn->kn_fop->f_event)); +} + +static inline int +knote_process_fn(struct knote *kn, struct kevent *kev, + int (*f_event)(struct knote *, long)) +{ + int active; + + /* + * If called from kqueue_scan(), skip f_event + * when EV_ONESHOT is set, to preserve old behaviour. + */ + if (kev != NULL && (kn->kn_flags & EV_ONESHOT)) + active = 1; + else + active = (*f_event)(kn, 0); + if (active) + knote_submit(kn, kev); + return (active); +} + +static inline int +knote_process(struct knote *kn, struct kevent *kev) +{ + return (knote_process_fn(kn, kev, kn->kn_fop->f_event)); +} + +static inline int +klist_empty(struct klist *klist) +{ + return (SLIST_EMPTY(&klist->kl_list)); +} + +#else /* !_KERNEL */ + +#include +struct timespec; + +__BEGIN_DECLS +int kqueue(void); +int kqueue1(int flags); +int kevent(int kq, const struct kevent *changelist, int nchanges, + struct kevent *eventlist, int nevents, + const struct timespec *timeout); +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_SYS_EVENT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/eventvar.h b/lib/libc/include/generic-openbsd/sys/eventvar.h new file mode 100644 index 0000000000..4a6ad517fe --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/eventvar.h @@ -0,0 +1,74 @@ +/* $OpenBSD: eventvar.h,v 1.17 2022/07/09 12:48:21 visa Exp $ */ + +/*- + * Copyright (c) 1999,2000 Jonathan Lemon + * 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 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 AUTHOR 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. + * + * $FreeBSD: src/sys/sys/eventvar.h,v 1.3 2000/05/26 02:06:54 jake Exp $ + */ + +#ifndef _SYS_EVENTVAR_H_ +#define _SYS_EVENTVAR_H_ + +#include +#include +#include + +#define KQ_NEVENTS 8 /* minimize copy{in,out} calls */ +#define KQEXTENT 256 /* linear growth by this amount */ + +/* + * Locking: + * I immutable after creation + * L kqueue_klist_lock + * a atomic operations + * q kq_lock + */ +struct kqueue { + struct mutex kq_lock; /* lock for queue access */ + TAILQ_HEAD(, knote) kq_head; /* [q] list of pending event */ + int kq_count; /* [q] # of pending events */ + struct refcnt kq_refcnt; /* [a] # of references */ + struct klist kq_klist; /* [L] knotes of other kqs */ + struct filedesc *kq_fdp; /* [I] fd table of this kq */ + + LIST_ENTRY(kqueue) kq_next; + + u_int kq_nknotes; /* [q] # of registered knotes */ + + int kq_knlistsize; /* [q] size of kq_knlist */ + struct knlist *kq_knlist; /* [q] list of + * attached knotes */ + u_long kq_knhashmask; /* [q] size of kq_knhash */ + struct knlist *kq_knhash; /* [q] hash table for + * attached knotes */ + struct task kq_task; /* deferring of activation */ + + int kq_state; /* [q] */ +#define KQ_SLEEP 0x02 +#define KQ_DYING 0x04 +#define KQ_TASK 0x08 +}; + +#endif /* !_SYS_EVENTVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/exec.h b/lib/libc/include/generic-openbsd/sys/exec.h new file mode 100644 index 0000000000..368dde8a36 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/exec.h @@ -0,0 +1,246 @@ +/* $OpenBSD: exec.h,v 1.57 2025/05/24 06:49:16 deraadt Exp $ */ +/* $NetBSD: exec.h,v 1.59 1996/02/09 18:25:09 christos Exp $ */ + +/*- + * Copyright (c) 1994 Christopher G. Demetriou + * Copyright (c) 1993 Theo de Raadt + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)exec.h 8.3 (Berkeley) 1/21/94 + */ + +#ifndef _SYS_EXEC_H_ +#define _SYS_EXEC_H_ + +/* + * The following structure is found at the top of the user stack of each + * user process. The ps program uses it to locate argv and environment + * strings. Programs that wish ps to display other information may modify + * it; normally ps_argvstr points to argv[0], and ps_nargvstr is the same + * as the program's argc. The fields ps_envstr and ps_nenvstr are the + * equivalent for the environment. + */ +struct ps_strings { + char **ps_argvstr; /* first of 0 or more argument strings */ + int ps_nargvstr; /* the number of argument strings */ + char **ps_envstr; /* first of 0 or more environment strings */ + int ps_nenvstr; /* the number of environment strings */ +}; + +/* + * the following structures allow execve() to put together processes + * in a more extensible and cleaner way. + * + * the exec_package struct defines an executable being execve()'d. + * it contains the header, the vmspace-building commands, the vnode + * information, and the arguments associated with the newly-execve'd + * process. + * + * the exec_vmcmd struct defines a command description to be used + * in creating the new process's vmspace. + */ + +struct proc; +struct exec_package; + +typedef int (*exec_makecmds_fcn)(struct proc *, struct exec_package *); + +struct execsw { + u_int es_hdrsz; /* size of header for this format */ + exec_makecmds_fcn es_check; /* function to check exec format */ +}; + +struct exec_vmcmd { + int (*ev_proc)(struct proc *p, struct exec_vmcmd *cmd); + /* procedure to run for region of vmspace */ + u_long ev_len; /* length of the segment to map */ + u_long ev_addr; /* address in the vmspace to place it at */ + struct vnode *ev_vp; /* vnode pointer for the file w/the data */ + u_long ev_offset; /* offset in the file for the data */ + u_int ev_prot; /* protections for segment */ + int ev_flags; +#define VMCMD_RELATIVE 0x0001 /* ev_addr is relative to base entry */ +#define VMCMD_BASE 0x0002 /* marks a base entry */ +#define VMCMD_STACK 0x0004 /* create with UVM_FLAG_STACK */ +#define VMCMD_IMMUTABLE 0x0010 /* create with UVM_ET_IMMUTABLE */ +#define VMCMD_TEXTREL 0x0020 /* terrible binary contains terrible textrel */ +}; + +#define EXEC_DEFAULT_VMCMD_SETSIZE 12 /* # of cmds in set to start */ + +/* exec vmspace-creation command set; see below */ +struct exec_vmcmd_set { + u_int evs_cnt; + u_int evs_used; + struct exec_vmcmd *evs_cmds; + struct exec_vmcmd evs_start[EXEC_DEFAULT_VMCMD_SETSIZE]; +}; + +struct elf_args; +struct exec_package { + char *ep_name; /* file's name */ + void *ep_hdr; /* file's exec header */ + u_int ep_hdrlen; /* length of ep_hdr */ + u_int ep_hdrvalid; /* bytes of ep_hdr that are valid */ + struct nameidata *ep_ndp; /* namei data pointer for lookups */ + struct exec_vmcmd_set ep_vmcmds; /* vmcmds used to build vmspace */ + struct vnode *ep_vp; /* executable's vnode */ + struct vattr *ep_vap; /* executable's attributes */ + u_long ep_taddr; /* process's text address */ + u_long ep_tsize; /* size of process's text */ + u_long ep_daddr; /* process's data(+bss) address */ + u_long ep_dsize; /* size of process's data(+bss) */ + u_long ep_maxsaddr; /* proc's max stack addr ("top") */ + u_long ep_minsaddr; /* proc's min stack addr ("bottom") */ + u_long ep_ssize; /* size of process's stack */ + u_long ep_entry; /* process's entry point */ + u_int ep_flags; /* flags; see below. */ + char **ep_fa; /* a fake args vector for scripts */ + int ep_fd; /* a file descriptor we're holding */ + struct elf_args *ep_args; /* ELF info */ + void *ep_auxinfo; /* userspace auxinfo address */ + char *ep_interp; /* name of interpreter if any */ + vaddr_t ep_pinstart, ep_pinend; /* executable region */ + u_int *ep_pins; /* array of system call offsets */ + int ep_npins; /* entries in array */ +}; +#define EXEC_INDIR 0x0001 /* script handling already done */ +#define EXEC_HASFD 0x0002 /* holding a shell script */ +#define EXEC_HASARGL 0x0004 /* has fake args vector */ +#define EXEC_SKIPARG 0x0008 /* don't copy user-supplied argv[0] */ +#define EXEC_DESTR 0x0010 /* destructive ops performed */ +#define EXEC_WXNEEDED 0x0020 /* executable will violate W^X */ +#define EXEC_NOBTCFI 0x0040 /* no branch target CFI */ +#define EXEC_PROFILE 0x0080 /* profiled binary */ + +#ifdef _KERNEL +/* + * functions used either by execve() or the various cpu-dependent execve() + * hooks. + */ +void vmcmdset_extend(struct exec_vmcmd_set *); +void kill_vmcmds(struct exec_vmcmd_set *evsp); +int vmcmd_map_pagedvn(struct proc *, struct exec_vmcmd *); +int vmcmd_map_readvn(struct proc *, struct exec_vmcmd *); +int vmcmd_map_zero(struct proc *, struct exec_vmcmd *); +int vmcmd_mutable(struct proc *, struct exec_vmcmd *); +int vmcmd_randomize(struct proc *, struct exec_vmcmd *); +int copyargs(struct exec_package *, struct ps_strings *, void *, void *); +void setregs(struct proc *, struct exec_package *, u_long, + struct ps_strings *); +int check_exec(struct proc *, struct exec_package *); +int exec_setup_stack(struct proc *, struct exec_package *); +int exec_process_vmcmds(struct proc *, struct exec_package *); + +void new_vmcmd(struct exec_vmcmd_set *evsp, + int (*proc)(struct proc *p, struct exec_vmcmd *), + u_long len, u_long addr, struct vnode *vp, u_long offset, + u_int prot, int flags); +#define NEW_VMCMD(evsp,proc,len,addr,vp,offset,prot) \ + new_vmcmd(evsp,proc,len,addr,vp,offset,prot, 0); +#define NEW_VMCMD2(evsp,proc,len,addr,vp,offset,prot,flags) \ + new_vmcmd(evsp,proc,len,addr,vp,offset,prot,flags) + +/* Initialize an empty vmcmd set */ +#define VMCMDSET_INIT(vmc) do { \ + (vmc)->evs_cnt = EXEC_DEFAULT_VMCMD_SETSIZE; \ + (vmc)->evs_cmds = (vmc)->evs_start; \ + (vmc)->evs_used = 0; \ +} while (0) + +/* + * Exec function switch: + * + * Note that each makecmds function is responsible for loading the + * exec package with the necessary functions for any exec-type-specific + * handling. + * + * Functions for specific exec types should be defined in their own + * header file. + */ +extern const struct execsw execsw[]; +extern int nexecs; +extern int exec_maxhdrsz; + +/* + * If non-zero, stackgap_random specifies the upper limit of the random gap size + * added to the fixed stack position. Must be n^2. + */ +extern int stackgap_random; + +/* Limit on total PT_OPENBSD_RANDOMIZE bytes. */ +#define ELF_RANDOMIZE_LIMIT 1024*1024 + +#endif /* _KERNEL */ + +/* + * a_mid - keep sorted in numerical order for sanity's sake + * ensure that: 0 < mid < 0x3ff + */ +#define MID_ZERO 0 /* unknown - implementation dependent */ +#define MID_SUN010 1 /* sun 68010/68020 binary */ +#define MID_SUN020 2 /* sun 68020-only binary */ +#define MID_PC386 100 /* 386 PC binary. (so quoth BFD) */ +#define MID_ROMPAOS 104 /* old IBM RT */ +#define MID_I386 134 /* i386 BSD binary */ +#define MID_M68K 135 /* m68k BSD binary with 8K page sizes */ +#define MID_M68K4K 136 /* DO NOT USE: m68k BSD binary with 4K page sizes */ +#define MID_NS32532 137 /* ns32532 */ +#define MID_SPARC 138 /* sparc */ +#define MID_PMAX 139 /* pmax */ +#define MID_VAX1K 140 /* vax 1k page size */ +#define MID_ALPHA 141 /* Alpha BSD binary */ +#define MID_MIPS 142 /* big-endian MIPS */ +#define MID_ARM6 143 /* ARM6 */ +#define MID_SH3 145 /* SH3 */ +#define MID_POWERPC 149 /* big-endian PowerPC */ +#define MID_VAX 150 /* vax */ +#define MID_SPARC64 151 /* LP64 sparc */ +#define MID_MIPS2 152 /* MIPS2 */ +#define MID_M88K 153 /* m88k BSD binary */ +#define MID_HPPA 154 /* hppa */ +#define MID_AMD64 157 /* AMD64 */ +#define MID_MIPS64 158 /* big-endian MIPS64 */ +#define MID_ARM64 159 /* ARM64 */ +#define MID_POWERPC64 160 /* big-endian 64-bit PowerPC */ +#define MID_RISCV64 161 /* Little-endian 64-bit RISC-V */ +#define MID_HP200 200 /* hp200 (68010) BSD binary */ +#define MID_HP300 300 /* hp300 (68020+68881) BSD binary */ +#define MID_HPUX 0x20C /* hp200/300 HP-UX binary */ +#define MID_HPUX800 0x20B /* hp800 HP-UX binary pa1.0 */ +#define MID_HPPA11 0x210 /* hp700 HP-UX binary pa1.1 */ +#define MID_HPPA20 0x214 /* hp700 HP-UX binary pa2.0 */ + +#include + +#endif /* !_SYS_EXEC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/exec_elf.h b/lib/libc/include/generic-openbsd/sys/exec_elf.h new file mode 100644 index 0000000000..2d39ed037d --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/exec_elf.h @@ -0,0 +1,843 @@ +/* $OpenBSD: exec_elf.h,v 1.108 2025/07/31 16:09:59 kettenis Exp $ */ +/* + * Copyright (c) 1995, 1996 Erik Theisen. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * This is the ELF ABI header file + * formerly known as "elf_abi.h". + */ + +#ifndef _SYS_EXEC_ELF_H_ +#define _SYS_EXEC_ELF_H_ + +#include +#include + +typedef __uint32_t Elf32_Addr; /* Unsigned program address */ +typedef __uint32_t Elf32_Off; /* Unsigned file offset */ +typedef __int32_t Elf32_Sword; /* Signed large integer */ +typedef __uint32_t Elf32_Word; /* Unsigned large integer */ +typedef __uint16_t Elf32_Half; /* Unsigned medium integer */ +typedef __uint64_t Elf32_Lword; + +typedef __uint64_t Elf64_Addr; +typedef __uint64_t Elf64_Off; +typedef __int32_t Elf64_Shalf; + +typedef __int32_t Elf64_Sword; +typedef __uint32_t Elf64_Word; + +typedef __int64_t Elf64_Sxword; +typedef __uint64_t Elf64_Xword; +typedef __uint64_t Elf64_Lword; + +typedef __uint16_t Elf64_Half; + +/* + * e_ident[] identification indexes + * See http://www.sco.com/developers/gabi/latest/ch4.eheader.html + */ +#define EI_MAG0 0 /* file ID */ +#define EI_MAG1 1 /* file ID */ +#define EI_MAG2 2 /* file ID */ +#define EI_MAG3 3 /* file ID */ +#define EI_CLASS 4 /* file class */ +#define EI_DATA 5 /* data encoding */ +#define EI_VERSION 6 /* ELF header version */ +#define EI_OSABI 7 /* OS/ABI ID */ +#define EI_ABIVERSION 8 /* ABI version */ +#define EI_PAD 9 /* start of pad bytes */ +#define EI_NIDENT 16 /* Size of e_ident[] */ + +/* e_ident[] magic number */ +#define ELFMAG0 0x7f /* e_ident[EI_MAG0] */ +#define ELFMAG1 'E' /* e_ident[EI_MAG1] */ +#define ELFMAG2 'L' /* e_ident[EI_MAG2] */ +#define ELFMAG3 'F' /* e_ident[EI_MAG3] */ +#define ELFMAG "\177ELF" /* magic */ +#define SELFMAG 4 /* size of magic */ + +/* e_ident[] file class */ +#define ELFCLASSNONE 0 /* invalid */ +#define ELFCLASS32 1 /* 32-bit objs */ +#define ELFCLASS64 2 /* 64-bit objs */ +#define ELFCLASSNUM 3 /* number of classes */ + +/* e_ident[] data encoding */ +#define ELFDATANONE 0 /* invalid */ +#define ELFDATA2LSB 1 /* Little-Endian */ +#define ELFDATA2MSB 2 /* Big-Endian */ +#define ELFDATANUM 3 /* number of data encode defines */ + +/* e_ident[] Operating System/ABI */ +#define ELFOSABI_SYSV 0 /* UNIX System V ABI */ +#define ELFOSABI_HPUX 1 /* HP-UX operating system */ +#define ELFOSABI_NETBSD 2 /* NetBSD */ +#define ELFOSABI_LINUX 3 /* GNU/Linux */ +#define ELFOSABI_HURD 4 /* GNU/Hurd */ +#define ELFOSABI_86OPEN 5 /* 86Open common IA32 ABI */ +#define ELFOSABI_SOLARIS 6 /* Solaris */ +#define ELFOSABI_MONTEREY 7 /* Monterey */ +#define ELFOSABI_IRIX 8 /* IRIX */ +#define ELFOSABI_FREEBSD 9 /* FreeBSD */ +#define ELFOSABI_TRU64 10 /* TRU64 UNIX */ +#define ELFOSABI_MODESTO 11 /* Novell Modesto */ +#define ELFOSABI_OPENBSD 12 /* OpenBSD */ +#define ELFOSABI_ARM 97 /* ARM */ +#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */ + +/* e_ident */ +#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \ + (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \ + (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \ + (ehdr).e_ident[EI_MAG3] == ELFMAG3) + +/* ELF Header */ +typedef struct elfhdr { + unsigned char e_ident[EI_NIDENT]; /* ELF Identification */ + Elf32_Half e_type; /* object file type */ + Elf32_Half e_machine; /* machine */ + Elf32_Word e_version; /* object file version */ + Elf32_Addr e_entry; /* virtual entry point */ + Elf32_Off e_phoff; /* program header table offset */ + Elf32_Off e_shoff; /* section header table offset */ + Elf32_Word e_flags; /* processor-specific flags */ + Elf32_Half e_ehsize; /* ELF header size */ + Elf32_Half e_phentsize; /* program header entry size */ + Elf32_Half e_phnum; /* number of program header entries */ + Elf32_Half e_shentsize; /* section header entry size */ + Elf32_Half e_shnum; /* number of section header entries */ + Elf32_Half e_shstrndx; /* section header table's "section + header string table" entry offset */ +} Elf32_Ehdr; + +typedef struct { + unsigned char e_ident[EI_NIDENT]; /* Id bytes */ + Elf64_Half e_type; /* file type */ + Elf64_Half e_machine; /* machine type */ + Elf64_Word e_version; /* version number */ + Elf64_Addr e_entry; /* entry point */ + Elf64_Off e_phoff; /* Program hdr offset */ + Elf64_Off e_shoff; /* Section hdr offset */ + Elf64_Word e_flags; /* Processor flags */ + Elf64_Half e_ehsize; /* sizeof ehdr */ + Elf64_Half e_phentsize; /* Program header entry size */ + Elf64_Half e_phnum; /* Number of program headers */ + Elf64_Half e_shentsize; /* Section header entry size */ + Elf64_Half e_shnum; /* Number of section headers */ + Elf64_Half e_shstrndx; /* String table index */ +} Elf64_Ehdr; + +/* e_type */ +#define ET_NONE 0 /* No file type */ +#define ET_REL 1 /* relocatable file */ +#define ET_EXEC 2 /* executable file */ +#define ET_DYN 3 /* shared object file */ +#define ET_CORE 4 /* core file */ +#define ET_NUM 5 /* number of types */ +#define ET_LOPROC 0xff00 /* reserved range for processor */ +#define ET_HIPROC 0xffff /* specific e_type */ + +/* e_machine */ +#define EM_NONE 0 /* No Machine */ +#define EM_M32 1 /* AT&T WE 32100 */ +#define EM_SPARC 2 /* SPARC */ +#define EM_386 3 /* Intel 80386 */ +#define EM_68K 4 /* Motorola 68000 */ +#define EM_88K 5 /* Motorola 88000 */ +#define EM_486 6 /* Intel 80486 - unused? */ +#define EM_860 7 /* Intel 80860 */ +#define EM_MIPS 8 /* MIPS R3000 Big-Endian only */ +/* + * Don't know if EM_MIPS_RS4_BE, + * EM_SPARC64, EM_PARISC, + * or EM_PPC are ABI compliant + */ +#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */ +#define EM_SPARC64 11 /* SPARC v9 64-bit unofficial */ +#define EM_PARISC 15 /* HPPA */ +#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */ +#define EM_PPC 20 /* PowerPC */ +#define EM_PPC64 21 /* PowerPC 64 */ +#define EM_ARM 40 /* Advanced RISC Machines ARM */ +#define EM_ALPHA 41 /* DEC ALPHA */ +#define EM_SH 42 /* Hitachi/Renesas Super-H */ +#define EM_SPARCV9 43 /* SPARC version 9 */ +#define EM_IA_64 50 /* Intel IA-64 Processor */ +#define EM_AMD64 62 /* AMD64 architecture */ +#define EM_X86_64 EM_AMD64 +#define EM_VAX 75 /* DEC VAX */ +#define EM_AARCH64 183 /* ARM 64-bit architecture (AArch64) */ +#define EM_RISCV 243 /* RISC-V */ + +/* Non-standard */ +#define EM_ALPHA_EXP 0x9026 /* DEC ALPHA */ +#define EM__LAST__ (EM_ALPHA_EXP + 1) + +/* Version */ +#define EV_NONE 0 /* Invalid */ +#define EV_CURRENT 1 /* Current */ +#define EV_NUM 2 /* number of versions */ + +/* Magic for e_phnum: get real value from sh_info of first section header */ +#define PN_XNUM 0xffff + +/* Section Header */ +typedef struct { + Elf32_Word sh_name; /* name - index into section header + string table section */ + Elf32_Word sh_type; /* type */ + Elf32_Word sh_flags; /* flags */ + Elf32_Addr sh_addr; /* address */ + Elf32_Off sh_offset; /* file offset */ + Elf32_Word sh_size; /* section size */ + Elf32_Word sh_link; /* section header table index link */ + Elf32_Word sh_info; /* extra information */ + Elf32_Word sh_addralign; /* address alignment */ + Elf32_Word sh_entsize; /* section entry size */ +} Elf32_Shdr; + +typedef struct { + Elf64_Word sh_name; /* section name */ + Elf64_Word sh_type; /* section type */ + Elf64_Xword sh_flags; /* section flags */ + Elf64_Addr sh_addr; /* virtual address */ + Elf64_Off sh_offset; /* file offset */ + Elf64_Xword sh_size; /* section size */ + Elf64_Word sh_link; /* link to another */ + Elf64_Word sh_info; /* misc info */ + Elf64_Xword sh_addralign; /* memory alignment */ + Elf64_Xword sh_entsize; /* table entry size */ +} Elf64_Shdr; + +/* Special Section Indexes */ +#define SHN_UNDEF 0 /* undefined */ +#define SHN_LORESERVE 0xff00 /* lower bounds of reserved indexes */ +#define SHN_LOPROC 0xff00 /* reserved range for processor */ +#define SHN_HIPROC 0xff1f /* specific section indexes */ +#define SHN_ABS 0xfff1 /* absolute value */ +#define SHN_COMMON 0xfff2 /* common symbol */ +#define SHN_XINDEX 0xffff /* Escape -- index stored elsewhere. */ +#define SHN_HIRESERVE 0xffff /* upper bounds of reserved indexes */ + +/* sh_type */ +#define SHT_NULL 0 /* inactive */ +#define SHT_PROGBITS 1 /* program defined information */ +#define SHT_SYMTAB 2 /* symbol table section */ +#define SHT_STRTAB 3 /* string table section */ +#define SHT_RELA 4 /* relocation section with addends*/ +#define SHT_HASH 5 /* symbol hash table section */ +#define SHT_DYNAMIC 6 /* dynamic section */ +#define SHT_NOTE 7 /* note section */ +#define SHT_NOBITS 8 /* no space section */ +#define SHT_REL 9 /* relocation section without addends */ +#define SHT_SHLIB 10 /* reserved - purpose unknown */ +#define SHT_DYNSYM 11 /* dynamic symbol table section */ +#define SHT_NUM 12 /* number of section types */ +#define SHT_INIT_ARRAY 14 /* pointers to init functions */ +#define SHT_FINI_ARRAY 15 /* pointers to termination functions */ +#define SHT_PREINIT_ARRAY 16 /* ptrs to funcs called before init */ +#define SHT_GROUP 17 /* defines a section group */ +#define SHT_SYMTAB_SHNDX 18 /* Section indexes (see SHN_XINDEX). */ +#define SHT_RELR 19 /* relative-only relocation section */ +#define SHT_LOOS 0x60000000 /* reserved range for OS specific */ +#define SHT_SUNW_dof 0x6ffffff4 /* used by dtrace */ +#define SHT_GNU_LIBLIST 0x6ffffff7 /* libraries to be prelinked */ +#define SHT_SUNW_move 0x6ffffffa /* inf for partially init'ed symbols */ +#define SHT_SUNW_syminfo 0x6ffffffc /* ad symbol information */ +#define SHT_SUNW_verdef 0x6ffffffd /* symbol versioning inf */ +#define SHT_SUNW_verneed 0x6ffffffe /* symbol versioning req */ +#define SHT_SUNW_versym 0x6fffffff /* symbol versioning table */ +#define SHT_HIOS 0x6fffffff /* section header types */ +#define SHT_LOPROC 0x70000000 /* reserved range for processor */ +#define SHT_HIPROC 0x7fffffff /* specific section header types */ +#define SHT_LOUSER 0x80000000 /* reserved range for application */ +#define SHT_HIUSER 0xffffffff /* specific indexes */ + +#define SHT_GNU_HASH 0x6ffffff6 /* GNU-style hash table section */ + +/* Section names */ +#define ELF_BSS ".bss" /* uninitialized data */ +#define ELF_DATA ".data" /* initialized data */ +#define ELF_CTF ".SUNW_ctf" /* CTF data */ +#define ELF_DEBUG ".debug" /* debug */ +#define ELF_DYNAMIC ".dynamic" /* dynamic linking information */ +#define ELF_DYNSTR ".dynstr" /* dynamic string table */ +#define ELF_DYNSYM ".dynsym" /* dynamic symbol table */ +#define ELF_FINI ".fini" /* termination code */ +#define ELF_GOT ".got" /* global offset table */ +#define ELF_HASH ".hash" /* symbol hash table */ +#define ELF_INIT ".init" /* initialization code */ +#define ELF_REL_DATA ".rel.data" /* relocation data */ +#define ELF_REL_FINI ".rel.fini" /* relocation termination code */ +#define ELF_REL_INIT ".rel.init" /* relocation initialization code */ +#define ELF_REL_DYN ".rel.dyn" /* relocation dynamic link info */ +#define ELF_REL_RODATA ".rel.rodata" /* relocation read-only data */ +#define ELF_REL_TEXT ".rel.text" /* relocation code */ +#define ELF_RODATA ".rodata" /* read-only data */ +#define ELF_SHSTRTAB ".shstrtab" /* section header string table */ +#define ELF_STRTAB ".strtab" /* string table */ +#define ELF_SYMTAB ".symtab" /* symbol table */ +#define ELF_TEXT ".text" /* code */ +#define ELF_OPENBSDRANDOMDATA ".openbsd.randomdata" /* constant randomdata */ +#define ELF_OPENBSDMUTABLE ".openbsd.mutable" /* mutable bss */ + + +/* Section Attribute Flags - sh_flags */ +#define SHF_WRITE 0x1 /* Writable */ +#define SHF_ALLOC 0x2 /* occupies memory */ +#define SHF_EXECINSTR 0x4 /* executable */ +#define SHF_MERGE 0x10 /* may be merged */ +#define SHF_STRINGS 0x20 /* contains strings */ +#define SHF_INFO_LINK 0x40 /* sh_info holds section index */ +#define SHF_LINK_ORDER 0x80 /* ordering requirements */ +#define SHF_OS_NONCONFORMING 0x100 /* OS-specific processing required */ +#define SHF_GROUP 0x200 /* member of section group */ +#define SHF_TLS 0x400 /* thread local storage */ +#define SHF_COMPRESSED 0x800 /* contains compressed data */ +#define SHF_MASKOS 0x0ff00000 /* OS-specific semantics */ +#define SHF_MASKPROC 0xf0000000 /* reserved bits for processor */ + /* specific section attributes */ + +/* Symbol Table Entry */ +typedef struct elf32_sym { + Elf32_Word st_name; /* name - index into string table */ + Elf32_Addr st_value; /* symbol value */ + Elf32_Word st_size; /* symbol size */ + unsigned char st_info; /* type and binding */ + unsigned char st_other; /* 0 - no defined meaning */ + Elf32_Half st_shndx; /* section header index */ +} Elf32_Sym; + +typedef struct { + Elf64_Word st_name; /* Symbol name index in str table */ + unsigned char st_info; /* type / binding attrs */ + unsigned char st_other; /* unused */ + Elf64_Half st_shndx; /* section index of symbol */ + Elf64_Addr st_value; /* value of symbol */ + Elf64_Xword st_size; /* size of symbol */ +} Elf64_Sym; + +/* Symbol table index */ +#define STN_UNDEF 0 /* undefined */ + +/* Extract symbol info - st_info */ +#define ELF32_ST_BIND(x) ((x) >> 4) +#define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf) +#define ELF32_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf)) + +#define ELF64_ST_BIND(x) ((x) >> 4) +#define ELF64_ST_TYPE(x) (((unsigned int) x) & 0xf) +#define ELF64_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf)) + +/* Symbol Binding - ELF32_ST_BIND - st_info */ +#define STB_LOCAL 0 /* Local symbol */ +#define STB_GLOBAL 1 /* Global symbol */ +#define STB_WEAK 2 /* like global - lower precedence */ +#define STB_NUM 3 /* number of symbol bindings */ +#define STB_LOPROC 13 /* reserved range for processor */ +#define STB_HIPROC 15 /* specific symbol bindings */ + +/* Symbol type - ELF32_ST_TYPE - st_info */ +#define STT_NOTYPE 0 /* not specified */ +#define STT_OBJECT 1 /* data object */ +#define STT_FUNC 2 /* function */ +#define STT_SECTION 3 /* section */ +#define STT_FILE 4 /* file */ +#define STT_TLS 6 /* thread local storage */ +#define STT_LOPROC 13 /* reserved range for processor */ +#define STT_HIPROC 15 /* specific symbol types */ + +/* Extract symbol visibility - st_other */ +#define ELF_ST_VISIBILITY(v) ((v) & 0x3) +#define ELF32_ST_VISIBILITY ELF_ST_VISIBILITY +#define ELF64_ST_VISIBILITY ELF_ST_VISIBILITY + +#define STV_DEFAULT 0 /* Visibility set by binding type */ +#define STV_INTERNAL 1 /* OS specific version of STV_HIDDEN */ +#define STV_HIDDEN 2 /* can only be seen inside own .so */ +#define STV_PROTECTED 3 /* HIDDEN inside, DEFAULT outside */ + +/* Relocation entry with implicit addend */ +typedef struct { + Elf32_Addr r_offset; /* offset of relocation */ + Elf32_Word r_info; /* symbol table index and type */ +} Elf32_Rel; + +/* Relocation entry with explicit addend */ +typedef struct { + Elf32_Addr r_offset; /* offset of relocation */ + Elf32_Word r_info; /* symbol table index and type */ + Elf32_Sword r_addend; +} Elf32_Rela; + +/* Extract relocation info - r_info */ +#define ELF32_R_SYM(i) ((i) >> 8) +#define ELF32_R_TYPE(i) ((unsigned char) (i)) +#define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t)) + +typedef struct { + Elf64_Addr r_offset; /* where to do it */ + Elf64_Xword r_info; /* index & type of relocation */ +} Elf64_Rel; + +typedef struct { + Elf64_Addr r_offset; /* where to do it */ + Elf64_Xword r_info; /* index & type of relocation */ + Elf64_Sxword r_addend; /* adjustment value */ +} Elf64_Rela; + +#define ELF64_R_SYM(info) ((info) >> 32) +#define ELF64_R_TYPE(info) ((info) & 0xFFFFFFFF) +#define ELF64_R_INFO(s,t) (((s) << 32) + (__uint32_t)(t)) + +#if defined(__mips64__) && defined(__MIPSEL__) +/* + * The 64-bit MIPS ELF ABI uses a slightly different relocation format + * than the regular ELF ABI: the r_info field is split into several + * pieces (see gnu/usr.bin/binutils-2.17/include/elf/mips.h for details). + */ +#undef ELF64_R_SYM +#undef ELF64_R_TYPE +#undef ELF64_R_INFO +#define ELF64_R_TYPE(info) ((__uint64_t)swap32((info) >> 32)) +#define ELF64_R_SYM(info) ((info) & 0xFFFFFFFF) +#define ELF64_R_INFO(s,t) (((__uint64_t)swap32(t) << 32) + (__uint32_t)(s)) +#endif /* __mips64__ && __MIPSEL__ */ + +/* + * Relative Relocation info. + * c.f. decode_relrs() in gnu/llvm/llvm/lib/Object/ELF.cpp + */ +typedef Elf32_Word Elf32_Relr; +typedef Elf64_Xword Elf64_Relr; + +/* Program Header */ +typedef struct { + Elf32_Word p_type; /* segment type */ + Elf32_Off p_offset; /* segment offset */ + Elf32_Addr p_vaddr; /* virtual address of segment */ + Elf32_Addr p_paddr; /* physical address - ignored? */ + Elf32_Word p_filesz; /* number of bytes in file for seg. */ + Elf32_Word p_memsz; /* number of bytes in mem. for seg. */ + Elf32_Word p_flags; /* flags */ + Elf32_Word p_align; /* memory alignment */ +} Elf32_Phdr; + +typedef struct { + Elf64_Word p_type; /* entry type */ + Elf64_Word p_flags; /* flags */ + Elf64_Off p_offset; /* offset */ + Elf64_Addr p_vaddr; /* virtual address */ + Elf64_Addr p_paddr; /* physical address */ + Elf64_Xword p_filesz; /* file size */ + Elf64_Xword p_memsz; /* memory size */ + Elf64_Xword p_align; /* memory & file alignment */ +} Elf64_Phdr; + +/* Segment types - p_type */ +#define PT_NULL 0 /* unused */ +#define PT_LOAD 1 /* loadable segment */ +#define PT_DYNAMIC 2 /* dynamic linking section */ +#define PT_INTERP 3 /* the RTLD */ +#define PT_NOTE 4 /* auxiliary information */ +#define PT_SHLIB 5 /* reserved - purpose undefined */ +#define PT_PHDR 6 /* program header */ +#define PT_TLS 7 /* thread local storage */ +#define PT_LOOS 0x60000000 /* reserved range for OS */ +#define PT_HIOS 0x6fffffff /* specific segment types */ +#define PT_LOPROC 0x70000000 /* reserved range for processor */ +#define PT_HIPROC 0x7fffffff /* specific segment types */ + +#define PT_GNU_EH_FRAME 0x6474e550 /* Exception handling info */ +#define PT_GNU_RELRO 0x6474e552 /* Read-only after relocation */ +#define PT_GNU_PROPERTY 0x6474e553 /* Program property note */ + +#define PT_OPENBSD_MUTABLE 0x65a3dbe5 /* like bss, but not immutable */ +#define PT_OPENBSD_RANDOMIZE 0x65a3dbe6 /* fill with random data */ +#define PT_OPENBSD_WXNEEDED 0x65a3dbe7 /* program performs W^X violations */ +#define PT_OPENBSD_NOBTCFI 0x65a3dbe8 /* no branch target CFI */ +#define PT_OPENBSD_SYSCALLS 0x65a3dbe9 /* syscall locations */ +#define PT_OPENBSD_BOOTDATA 0x65a41be6 /* section for boot arguments */ + +/* Segment flags - p_flags */ +#define PF_X 0x1 /* Executable */ +#define PF_W 0x2 /* Writable */ +#define PF_R 0x4 /* Readable */ +#define PF_MASKOS 0x0ff00000 /* reserved bits for OS */ + /* specific segment flags */ +#define PF_MASKPROC 0xf0000000 /* reserved bits for processor */ + /* specific segment flags */ + +#define PF_OPENBSD_MUTABLE 0x08000000 /* Mutable */ + +#ifdef _KERNEL +#define PF_ISVNODE 0x00100000 /* For coredump segments */ +#endif + +/* Dynamic structure */ +typedef struct { + Elf32_Sword d_tag; /* controls meaning of d_val */ + union { + Elf32_Word d_val; /* Multiple meanings - see d_tag */ + Elf32_Addr d_ptr; /* program virtual address */ + } d_un; +} Elf32_Dyn; + +typedef struct { + Elf64_Xword d_tag; /* controls meaning of d_val */ + union { + Elf64_Addr d_ptr; + Elf64_Xword d_val; + } d_un; +} Elf64_Dyn; + +/* Dynamic Array Tags - d_tag */ +#define DT_NULL 0 /* marks end of _DYNAMIC array */ +#define DT_NEEDED 1 /* string table offset of needed lib */ +#define DT_PLTRELSZ 2 /* size of relocation entries in PLT */ +#define DT_PLTGOT 3 /* address PLT/GOT */ +#define DT_HASH 4 /* address of symbol hash table */ +#define DT_STRTAB 5 /* address of string table */ +#define DT_SYMTAB 6 /* address of symbol table */ +#define DT_RELA 7 /* address of relocation table */ +#define DT_RELASZ 8 /* size of relocation table */ +#define DT_RELAENT 9 /* size of relocation entry */ +#define DT_STRSZ 10 /* size of string table */ +#define DT_SYMENT 11 /* size of symbol table entry */ +#define DT_INIT 12 /* address of initialization func. */ +#define DT_FINI 13 /* address of termination function */ +#define DT_SONAME 14 /* string table offset of shared obj */ +#define DT_RPATH 15 /* string table offset of library + search path */ +#define DT_SYMBOLIC 16 /* start sym search in shared obj. */ +#define DT_REL 17 /* address of rel. tbl. w addends */ +#define DT_RELSZ 18 /* size of DT_REL relocation table */ +#define DT_RELENT 19 /* size of DT_REL relocation entry */ +#define DT_PLTREL 20 /* PLT referenced relocation entry */ +#define DT_DEBUG 21 /* bugger */ +#define DT_TEXTREL 22 /* Allow rel. mod. to unwritable seg */ +#define DT_JMPREL 23 /* add. of PLT's relocation entries */ +#define DT_BIND_NOW 24 /* Bind now regardless of env setting */ +#define DT_INIT_ARRAY 25 /* address of array of init func */ +#define DT_FINI_ARRAY 26 /* address of array of term func */ +#define DT_INIT_ARRAYSZ 27 /* size of array of init func */ +#define DT_FINI_ARRAYSZ 28 /* size of array of term func */ +#define DT_RUNPATH 29 /* strtab offset of lib search path */ +#define DT_FLAGS 30 /* Set of DF_* flags */ +#define DT_ENCODING 31 /* further DT_* follow encoding rules */ +#define DT_PREINIT_ARRAY 32 /* address of array of preinit func */ +#define DT_PREINIT_ARRAYSZ 33 /* size of array of preinit func */ +#define DT_RELRSZ 35 /* size of DT_RELR relocation table */ +#define DT_RELR 36 /* addr of DT_RELR relocation table */ +#define DT_RELRENT 37 /* size of DT_RELR relocation entry */ +#define DT_LOOS 0x6000000d /* reserved range for OS */ +#define DT_HIOS 0x6ffff000 /* specific dynamic array tags */ +#define DT_LOPROC 0x70000000 /* reserved range for processor */ +#define DT_HIPROC 0x7fffffff /* specific dynamic array tags */ + +/* some other useful tags */ +#define DT_GNU_HASH 0x6ffffef5 /* address of GNU hash table */ +#define DT_RELACOUNT 0x6ffffff9 /* if present, number of RELATIVE */ +#define DT_RELCOUNT 0x6ffffffa /* relocs, which must come first */ +#define DT_FLAGS_1 0x6ffffffb + +/* Dynamic Flags - DT_FLAGS .dynamic entry */ +#define DF_ORIGIN 0x00000001 +#define DF_SYMBOLIC 0x00000002 +#define DF_TEXTREL 0x00000004 +#define DF_BIND_NOW 0x00000008 +#define DF_STATIC_TLS 0x00000010 + +/* Dynamic Flags - DT_FLAGS_1 .dynamic entry */ +#define DF_1_NOW 0x00000001 +#define DF_1_GLOBAL 0x00000002 +#define DF_1_GROUP 0x00000004 +#define DF_1_NODELETE 0x00000008 +#define DF_1_LOADFLTR 0x00000010 +#define DF_1_INITFIRST 0x00000020 +#define DF_1_NOOPEN 0x00000040 +#define DF_1_ORIGIN 0x00000080 +#define DF_1_DIRECT 0x00000100 +#define DF_1_TRANS 0x00000200 +#define DF_1_INTERPOSE 0x00000400 +#define DF_1_NODEFLIB 0x00000800 +#define DF_1_NODUMP 0x00001000 +#define DF_1_CONLFAT 0x00002000 +#define DF_1_ENDFILTEE 0x00004000 +#define DF_1_DISPRELDNE 0x00008000 +#define DF_1_DISPRELPND 0x00010000 +#define DF_1_NODIRECT 0x00020000 +#define DF_1_IGNMULDEF 0x00040000 +#define DF_1_NOKSYMS 0x00080000 +#define DF_1_NOHDR 0x00100000 +#define DF_1_EDITED 0x00200000 +#define DF_1_NORELOC 0x00400000 +#define DF_1_SYMINTPOSE 0x00800000 +#define DF_1_GLOBAUDIT 0x01000000 +#define DF_1_SINGLETON 0x02000000 +#define DF_1_PIE 0x08000000 + +/* + * Note header + */ +typedef struct { + Elf32_Word n_namesz; + Elf32_Word n_descsz; + Elf32_Word n_type; +} Elf32_Nhdr; + +typedef struct { + Elf64_Word n_namesz; + Elf64_Word n_descsz; + Elf64_Word n_type; +} Elf64_Nhdr; + +/* + * Note Definitions + */ +typedef struct { + Elf32_Word namesz; + Elf32_Word descsz; + Elf32_Word type; +} Elf32_Note; + +typedef struct { + Elf64_Word namesz; + Elf64_Word descsz; + Elf64_Word type; +} Elf64_Note; + +/* Values for n_type. */ +#define NT_PRSTATUS 1 /* Process status. */ +#define NT_FPREGSET 2 /* Floating point registers. */ +#define NT_PRPSINFO 3 /* Process state info. */ + +/* + * OpenBSD-specific core file information. + * + * OpenBSD ELF core files use notes to provide information about + * the process's state. The note name is "OpenBSD" for information + * that is global to the process, and "OpenBSD@nn", where "nn" is the + * thread ID of the thread that the information belongs to (such as + * register state). + * + * We use the following note identifiers: + * + * NT_OPENBSD_PROCINFO + * Note is a "elfcore_procinfo" structure. + * NT_OPENBSD_AUXV + * Note is a bunch of Auxiliary Vectors, terminated by + * an AT_NULL entry. + * NT_OPENBSD_REGS + * Note is a "reg" structure. + * NT_OPENBSD_FPREGS + * Note is a "fpreg" structure. + * + * Please try to keep the members of the "elfcore_procinfo" structure + * nicely aligned, and if you add elements, add them to the end and + * bump the version. + */ + +#define NT_OPENBSD_PROF 2 + +#define NT_OPENBSD_PROCINFO 10 +#define NT_OPENBSD_AUXV 11 + +#define NT_OPENBSD_REGS 20 +#define NT_OPENBSD_FPREGS 21 +#define NT_OPENBSD_XFPREGS 22 +#define NT_OPENBSD_WCOOKIE 23 +#define NT_OPENBSD_PACMASK 24 + +struct elfcore_procinfo { + /* Version 1 fields start here. */ + uint32_t cpi_version; /* elfcore_procinfo version */ +#define ELFCORE_PROCINFO_VERSION 1 + uint32_t cpi_cpisize; /* sizeof(elfcore_procinfo) */ + uint32_t cpi_signo; /* killing signal */ + uint32_t cpi_sigcode; /* signal code */ + uint32_t cpi_sigpend; /* pending signals */ + uint32_t cpi_sigmask; /* blocked signals */ + uint32_t cpi_sigignore; /* ignored signals */ + uint32_t cpi_sigcatch; /* signals being caught by user */ + int32_t cpi_pid; /* process ID */ + int32_t cpi_ppid; /* parent process ID */ + int32_t cpi_pgrp; /* process group ID */ + int32_t cpi_sid; /* session ID */ + uint32_t cpi_ruid; /* real user ID */ + uint32_t cpi_euid; /* effective user ID */ + uint32_t cpi_svuid; /* saved user ID */ + uint32_t cpi_rgid; /* real group ID */ + uint32_t cpi_egid; /* effective group ID */ + uint32_t cpi_svgid; /* saved group ID */ + int8_t cpi_name[32]; /* copy of pr->ps_comm */ +}; + +/* + * XXX - these _KERNEL items aren't part of the ABI! + */ +#if defined(_KERNEL) || defined(_DYN_LOADER) + +#define ELF32_NO_ADDR ((uint32_t) ~0) /* Indicates addr. not yet filled in */ + +typedef struct { + Elf32_Sword au_id; /* 32-bit id */ + Elf32_Word au_v; /* 32-bit value */ +} Aux32Info; + +#define ELF64_NO_ADDR ((__uint64_t) ~0)/* Indicates addr. not yet filled in */ + +typedef struct { + Elf64_Shalf au_id; /* 32-bit id */ + Elf64_Xword au_v; /* 64-bit value */ +} Aux64Info; + +enum AuxID { + AUX_null = 0, + AUX_ignore = 1, + AUX_execfd = 2, + AUX_phdr = 3, /* &phdr[0] */ + AUX_phent = 4, /* sizeof(phdr[0]) */ + AUX_phnum = 5, /* # phdr entries */ + AUX_pagesz = 6, /* PAGESIZE */ + AUX_base = 7, /* base addr for ld.so or static PIE */ + AUX_flags = 8, /* processor flags */ + AUX_entry = 9, /* a.out entry */ + AUX_hwcap = 25, /* processor flags */ + AUX_hwcap2 = 26, /* processor flags (continued) */ + AUX_sun_uid = 2000, /* euid */ + AUX_sun_ruid = 2001, /* ruid */ + AUX_sun_gid = 2002, /* egid */ + AUX_sun_rgid = 2003, /* rgid */ + AUX_openbsd_timekeep = 4000, /* userland clock_gettime */ +}; + +struct elf_args { + u_long arg_entry; /* program entry point */ + u_long arg_interp; /* Interpreter load address */ + u_long arg_phaddr; /* program header address */ + u_long arg_phentsize; /* Size of program header */ + u_long arg_phnum; /* Number of program headers */ +}; + +#endif + +#if !defined(ELFSIZE) && defined(ARCH_ELFSIZE) +#define ELFSIZE ARCH_ELFSIZE +#endif + +#if defined(ELFSIZE) +#define CONCAT(x,y) __CONCAT(x,y) +#define ELFNAME(x) CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x))) +#define ELFDEFNNAME(x) CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x))) +#endif + +#if defined(ELFSIZE) && (ELFSIZE == 32) +#define Elf_Ehdr Elf32_Ehdr +#define Elf_Phdr Elf32_Phdr +#define Elf_Shdr Elf32_Shdr +#define Elf_Sym Elf32_Sym +#define Elf_Rel Elf32_Rel +#define Elf_RelA Elf32_Rela +#define Elf_Relr Elf32_Relr +#define Elf_Dyn Elf32_Dyn +#define Elf_Half Elf32_Half +#define Elf_Word Elf32_Word +#define Elf_Sword Elf32_Sword +#define Elf_Addr Elf32_Addr +#define Elf_Off Elf32_Off +#define Elf_Nhdr Elf32_Nhdr +#define Elf_Note Elf32_Note + +#define ELF_R_SYM ELF32_R_SYM +#define ELF_R_TYPE ELF32_R_TYPE +#define ELF_R_INFO ELF32_R_INFO +#define ELFCLASS ELFCLASS32 + +#define ELF_ST_BIND ELF32_ST_BIND +#define ELF_ST_TYPE ELF32_ST_TYPE +#define ELF_ST_INFO ELF32_ST_INFO + +#define ELF_NO_ADDR ELF32_NO_ADDR +#define AuxInfo Aux32Info +#elif defined(ELFSIZE) && (ELFSIZE == 64) +#define Elf_Ehdr Elf64_Ehdr +#define Elf_Phdr Elf64_Phdr +#define Elf_Shdr Elf64_Shdr +#define Elf_Sym Elf64_Sym +#define Elf_Rel Elf64_Rel +#define Elf_RelA Elf64_Rela +#define Elf_Relr Elf64_Relr +#define Elf_Dyn Elf64_Dyn +#define Elf_Half Elf64_Half +#define Elf_Word Elf64_Word +#define Elf_Sword Elf64_Sword +#define Elf_Addr Elf64_Addr +#define Elf_Off Elf64_Off +#define Elf_Nhdr Elf64_Nhdr +#define Elf_Note Elf64_Note + +#define ELF_R_SYM ELF64_R_SYM +#define ELF_R_TYPE ELF64_R_TYPE +#define ELF_R_INFO ELF64_R_INFO +#define ELFCLASS ELFCLASS64 + +#define ELF_ST_BIND ELF64_ST_BIND +#define ELF_ST_TYPE ELF64_ST_TYPE +#define ELF_ST_INFO ELF64_ST_INFO + +#define ELF_NO_ADDR ELF64_NO_ADDR +#define AuxInfo Aux64Info +#endif + +#ifndef _KERNEL +extern Elf_Dyn _DYNAMIC[]; +#endif + +#ifdef _KERNEL +/* + * How many entries are in the AuxInfo array we pass to the process? + */ +#define ELF_AUX_ENTRIES 11 +#define ELF_AUX_WORDS (sizeof(AuxInfo) * ELF_AUX_ENTRIES / sizeof(char *)) + +#define ELFROUNDSIZE sizeof(Elf_Word) +#define elfround(x) roundup((x), ELFROUNDSIZE) + +struct exec_package; + +int exec_elf_makecmds(struct proc *, struct exec_package *); +int exec_elf_fixup(struct proc *, struct exec_package *); +int coredump_elf(struct proc *, void *); +int coredump_note_elf_md(struct proc *, void *, const char *, size_t *); +int coredump_writenote_elf(struct proc *, void *, Elf_Note *, + const char *, void *); +#endif /* _KERNEL */ + +#define ELF_TARG_VER 1 /* The ver for which this code is intended */ + +#endif /* _SYS_EXEC_ELF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/exec_script.h b/lib/libc/include/generic-openbsd/sys/exec_script.h new file mode 100644 index 0000000000..2d99321a99 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/exec_script.h @@ -0,0 +1,43 @@ +/* $OpenBSD: exec_script.h,v 1.6 2018/02/07 20:31:57 tedu Exp $ */ +/* $NetBSD: exec_script.h,v 1.6 1995/03/26 20:24:11 jtc Exp $ */ + +/* + * Copyright (c) 1994 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. + */ + +#define EXEC_SCRIPT_MAGIC "#!" +#define EXEC_SCRIPT_MAGICLEN 2 +#define EXEC_SCRIPT_HDRSZ (EXEC_SCRIPT_MAGICLEN + 1 + MAXINTERP + 1) + +#ifdef _KERNEL + +/* the shell script handler's entry in the exec switch */ +int exec_script_makecmds(struct proc *, struct exec_package *); + +#endif /* _KERNEL */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/extent.h b/lib/libc/include/generic-openbsd/sys/extent.h new file mode 100644 index 0000000000..4fc4b1bdd8 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/extent.h @@ -0,0 +1,132 @@ +/* $OpenBSD: extent.h,v 1.15 2024/01/19 22:12:24 kettenis Exp $ */ +/* $NetBSD: extent.h,v 1.6 1997/10/09 07:43:05 jtc Exp $ */ + +/*- + * Copyright (c) 1996 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. + */ + +#ifndef _SYS_EXTENT_H_ +#define _SYS_EXTENT_H_ + +#include + +struct extent_region { + LIST_ENTRY(extent_region) er_link; /* link in region list */ + u_long er_start; /* start of region */ + u_long er_end; /* end of region */ + int er_flags; /* misc. flags */ +}; + +/* er_flags */ +#define ER_ALLOC 0x01 /* region descriptor dynamically allocated */ +#define ER_DISCARD 0x02 /* discard region descriptor after use */ + +struct extent { + char *ex_name; /* name of extent */ + /* allocated regions in extent */ + LIST_HEAD(, extent_region) ex_regions; + u_long ex_start; /* start of extent */ + u_long ex_end; /* end of extent */ + int ex_mtype; /* memory type */ + int ex_flags; /* misc. information */ + + LIST_ENTRY(extent) ex_link; +}; + +struct extent_fixed { + struct extent fex_extent; /* MUST BE FIRST */ + /* freelist of region descriptors */ + LIST_HEAD(, extent_region) fex_freelist; + caddr_t fex_storage; /* storage space for descriptors */ + size_t fex_storagesize; /* size of storage space */ +}; + +/* ex_flags; for internal use only */ +#define EXF_FIXED 0x01 /* extent uses fixed storage */ +#define EXF_NOCOALESCE 0x02 /* coalescing of regions not allowed */ +#define EXF_WANTED 0x04 /* someone asleep on extent */ +#define EXF_FLWANTED 0x08 /* someone asleep on freelist */ + +#define EXF_BITS "\20\4FLWANTED\3WANTED\2NOCOALESCE\1FIXED" + +/* misc. flags passed to extent functions */ +#define EX_NOWAIT 0x0000 /* not safe to sleep */ +#define EX_WAITOK 0x0001 /* safe to sleep */ +#define EX_FAST 0x0002 /* take first fit in extent_alloc() */ +#define EX_CATCH 0x0004 /* catch signals while sleeping */ +#define EX_NOCOALESCE 0x0008 /* create a non-coalescing extent */ +#define EX_MALLOCOK 0x0010 /* safe to call malloc() */ +#define EX_WAITSPACE 0x0020 /* wait for space to become free */ +#define EX_BOUNDZERO 0x0040 /* boundary lines start at 0 */ +#define EX_CONFLICTOK 0x0080 /* allow conflicts */ +#define EX_FILLED 0x0100 /* create a filled extent */ + +/* + * Special place holders for "alignment" and "boundary" arguments, + * in the event the caller doesn't wish to use those features. + */ +#define EX_NOALIGN 1 /* don't do alignment */ +#define EX_NOBOUNDARY 0 /* don't do boundary checking */ + +#if defined(_KERNEL) || defined(_EXTENT_TESTING) +#define EXTENT_FIXED_STORAGE_SIZE(_nregions) \ + (ALIGN(sizeof(struct extent_fixed)) + \ + ((ALIGN(sizeof(struct extent_region))) * \ + (_nregions))) + +void extent_print_all(void); + +struct extent *extent_create(char *, u_long, u_long, int, + caddr_t, size_t, int); +void extent_destroy(struct extent *); +int extent_alloc_subregion(struct extent *, u_long, u_long, + u_long, u_long, u_long, u_long, int, u_long *); +int extent_alloc_subregion_with_descr(struct extent *, u_long, u_long, + u_long, u_long, u_long, u_long, int, struct extent_region *, + u_long *); +int extent_alloc_region(struct extent *, u_long, u_long, int); +int extent_alloc_region_with_descr(struct extent *, u_long, u_long, + int, struct extent_region *); +int extent_free(struct extent *, u_long, u_long, int); +void extent_print(struct extent *); + +/* Simple case of extent_alloc_subregion() */ +#define extent_alloc(_ex, _size, _alignment, _skew, _boundary, \ + _flags, _result) \ + extent_alloc_subregion((_ex), (_ex)->ex_start, (_ex)->ex_end, \ + (_size), (_alignment), (_skew), (_boundary), (_flags), (_result)) + +/* Simple case of extent_alloc_subregion_with_descr() */ +#define extent_alloc_with_descr(_ex, _size, _alignment, _skew, _boundary, \ + _flags, _region, _result) \ + extent_alloc_subregion_with_descr((_ex), (_ex)->ex_start, \ + (_ex)->ex_end, (_size), (_alignment), (_skew), (_boundary), \ + (_flags), (_region), (_result)) +#endif /* _KERNEL || _EXTENT_TESTING */ + +#endif /* ! _SYS_EXTENT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/fcntl.h b/lib/libc/include/generic-openbsd/sys/fcntl.h new file mode 100644 index 0000000000..ddd098c940 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/fcntl.h @@ -0,0 +1,231 @@ +/* $OpenBSD: fcntl.h,v 1.23 2025/08/04 04:59:30 guenther Exp $ */ +/* $NetBSD: fcntl.h,v 1.8 1995/03/26 20:24:12 jtc Exp $ */ + +/*- + * Copyright (c) 1983, 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)fcntl.h 8.3 (Berkeley) 1/21/94 + */ + +#ifndef _SYS_FCNTL_H_ +#define _SYS_FCNTL_H_ + +/* + * This file includes the definitions for open and fcntl + * described by POSIX for ; it also includes + * related kernel definitions. + */ + +#include +#ifndef _KERNEL +#include +#endif + +/* + * File status flags: these are used by open(2), fcntl(2). + * They are also used (indirectly) in the kernel file structure f_flags, + * which is a superset of the open/fcntl flags. Open flags and f_flags + * are inter-convertible using OFLAGS(fflags) and FFLAGS(oflags). + * Open/fcntl flags begin with O_; kernel-internal flags begin with F. + */ +/* open-only flags */ +#define O_RDONLY 0x0000 /* open for reading only */ +#define O_WRONLY 0x0001 /* open for writing only */ +#define O_RDWR 0x0002 /* open for reading and writing */ +#define O_ACCMODE 0x0003 /* mask for above modes */ + +/* + * Kernel encoding of open mode; separate read and write bits that are + * independently testable: 1 greater than the above. + * + * XXX + * FREAD and FWRITE are excluded from the #ifdef _KERNEL so that TIOCFLUSH, + * which was documented to use FREAD/FWRITE, continues to work. + */ +#if __BSD_VISIBLE +#define FREAD 0x0001 +#define FWRITE 0x0002 +#endif +#define O_NONBLOCK 0x0004 /* no delay */ +#define O_APPEND 0x0008 /* set append mode */ +#if __BSD_VISIBLE +#define O_SHLOCK 0x0010 /* open with shared file lock */ +#define O_EXLOCK 0x0020 /* open with exclusive file lock */ +#define O_ASYNC 0x0040 /* signal pgrp when data ready */ +#define O_FSYNC 0x0080 /* backwards compatibility */ +#endif +#if __POSIX_VISIBLE >= 199309 || __XPG_VISIBLE >= 420 +#define O_SYNC 0x0080 /* synchronous writes */ +/* + * POSIX 1003.1 permits a higher granularity for synchronous operations + * than we support. Since synchronicity is all or nothing in OpenBSD + * we just define these to be the same as O_SYNC. + */ +#define O_DSYNC O_SYNC /* synchronous data writes */ +#define O_RSYNC O_SYNC /* synchronous reads */ +#endif + +/* defined by POSIX Issue 7 */ +#define O_NOFOLLOW 0x0100 /* if path is a symlink, don't follow */ + +#define O_CREAT 0x0200 /* create if nonexistent */ +#define O_TRUNC 0x0400 /* truncate to zero length */ +#define O_EXCL 0x0800 /* error if already exists */ + +/* defined by POSIX 1003.1; BSD default, this bit is not required */ +#define O_NOCTTY 0x8000 /* don't assign controlling terminal */ + +/* defined by POSIX Issue 7 */ +#define O_CLOEXEC 0x10000 /* atomically set FD_CLOEXEC */ +#define O_DIRECTORY 0x20000 /* fail if not a directory */ + +/* defined by POSIX Issue 8 */ +#define O_CLOFORK 0x40000 /* atomically set FD_CLOFORK */ + +#ifdef _KERNEL +/* + * convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE. + * For out-of-range values for the flags, be slightly careful (but lossy). + */ +#define FFLAGS(oflags) (((oflags) & ~O_ACCMODE) | (((oflags) + 1) & O_ACCMODE)) +#define OFLAGS(fflags) (((fflags) & ~O_ACCMODE) | (((fflags) - 1) & O_ACCMODE)) + +/* bits to save after open */ +#define FMASK (FREAD|FWRITE|FAPPEND|FASYNC|FFSYNC|FNONBLOCK) +/* bits settable by fcntl(F_SETFL, ...) */ +#define FCNTLFLAGS (FAPPEND|FASYNC|FFSYNC|FNONBLOCK) +#endif + +/* + * The O_* flags used to have only F* names, which were used in the kernel + * and by fcntl. We retain the F* names for the kernel f_flags field + * and for backward compatibility for fcntl. + */ +#if __BSD_VISIBLE +#define FAPPEND O_APPEND /* kernel/compat */ +#define FASYNC O_ASYNC /* kernel/compat */ +#define FFSYNC O_SYNC /* kernel */ +#define FNONBLOCK O_NONBLOCK /* kernel */ +#define FNDELAY O_NONBLOCK /* compat */ +#define O_NDELAY O_NONBLOCK /* compat */ +#endif + +/* + * Constants used for fcntl(2) + */ + +/* command values */ +#define F_DUPFD 0 /* duplicate file descriptor */ +#define F_GETFD 1 /* get file descriptor flags */ +#define F_SETFD 2 /* set file descriptor flags */ +#define F_GETFL 3 /* get file status flags */ +#define F_SETFL 4 /* set file status flags */ +#if __POSIX_VISIBLE >= 200112 || __XPG_VISIBLE >= 500 +#define F_GETOWN 5 /* get SIGIO/SIGURG proc/pgrp */ +#define F_SETOWN 6 /* set SIGIO/SIGURG proc/pgrp */ +#endif +#define F_GETLK 7 /* get record locking information */ +#define F_SETLK 8 /* set record locking information */ +#define F_SETLKW 9 /* F_SETLK; wait if blocked */ +#if __POSIX_VISIBLE >= 200809 +#define F_DUPFD_CLOEXEC 10 /* duplicate with FD_CLOEXEC set */ +#endif +#if __BSD_VISIBLE +#define F_ISATTY 11 /* used by isatty(3) */ +#endif +#if __POSIX_VISIBLE >= 202405 +#define F_DUPFD_CLOFORK 12 /* duplicate with FD_CLOFORK set */ +#endif + +/* file descriptor flags (F_GETFD, F_SETFD) */ +#define FD_CLOEXEC 1 /* close-on-exec flag */ +#if __POSIX_VISIBLE >= 202405 +#define FD_CLOFORK 4 /* close-on-fork flag */ +#endif + +/* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */ +#define F_RDLCK 1 /* shared or read lock */ +#define F_UNLCK 2 /* unlock */ +#define F_WRLCK 3 /* exclusive or write lock */ +#ifdef _KERNEL +#define F_WAIT 0x010 /* Wait until lock is granted */ +#define F_FLOCK 0x020 /* Use flock(2) semantics for lock */ +#define F_POSIX 0x040 /* Use POSIX semantics for lock */ +#define F_INTR 0x080 /* Lock operation interrupted */ +#endif + +/* + * Advisory file segment locking data type - + * information passed to system by user + */ +struct flock { + off_t l_start; /* starting offset */ + off_t l_len; /* len = 0 means until end of file */ + pid_t l_pid; /* lock owner */ + short l_type; /* lock type: read/write, etc. */ + short l_whence; /* type of l_start */ +}; + + +#if __BSD_VISIBLE +/* lock operations for flock(2) */ +#define LOCK_SH 0x01 /* shared file lock */ +#define LOCK_EX 0x02 /* exclusive file lock */ +#define LOCK_NB 0x04 /* don't block when locking */ +#define LOCK_UN 0x08 /* unlock file */ +#endif + +#if __POSIX_VISIBLE >= 200809 +#define AT_FDCWD -100 + +#define AT_EACCESS 0x01 +#define AT_SYMLINK_NOFOLLOW 0x02 +#define AT_SYMLINK_FOLLOW 0x04 +#define AT_REMOVEDIR 0x08 +#endif + +#ifndef _KERNEL +__BEGIN_DECLS +int open(const char *, int, ...); +int creat(const char *, mode_t); +int fcntl(int, int, ...); +#if __BSD_VISIBLE +int flock(int, int); +#endif +#if __POSIX_VISIBLE >= 200809 +int openat(int, const char *, int, ...); +#endif +__END_DECLS +#endif + +#endif /* !_SYS_FCNTL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/file.h b/lib/libc/include/generic-openbsd/sys/file.h new file mode 100644 index 0000000000..047f0514c3 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/file.h @@ -0,0 +1,139 @@ +/* $OpenBSD: file.h,v 1.66 2022/06/20 01:39:44 visa Exp $ */ +/* $NetBSD: file.h,v 1.11 1995/03/26 20:24:13 jtc Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)file.h 8.2 (Berkeley) 8/20/94 + */ + +#ifndef _KERNEL +#include + +#else /* _KERNEL */ +#include +#include +#endif /* _KERNEL */ + +#define DTYPE_VNODE 1 /* file */ +#define DTYPE_SOCKET 2 /* communications endpoint */ +#define DTYPE_PIPE 3 /* pipe */ +#define DTYPE_KQUEUE 4 /* event queue */ +#define DTYPE_DMABUF 5 /* DMA buffer (for DRM) */ +#define DTYPE_SYNC 6 /* sync file (for DRM) */ + +#ifdef _KERNEL +struct proc; +struct uio; +struct knote; +struct stat; +struct file; +struct ucred; + +/** + * File operations. + * The following entries could be called without KERNEL_LOCK hold: + * - fo_read + * - fo_write + * - fo_close + */ +struct fileops { + int (*fo_read)(struct file *, struct uio *, int); + int (*fo_write)(struct file *, struct uio *, int); + int (*fo_ioctl)(struct file *, u_long, caddr_t, struct proc *); + int (*fo_kqfilter)(struct file *, struct knote *); + int (*fo_stat)(struct file *, struct stat *, struct proc *); + int (*fo_close)(struct file *, struct proc *); + int (*fo_seek)(struct file *, off_t *, int, struct proc *); +}; +#define FO_POSITION 0x00000001 /* positioned read/write */ + +/* + * Kernel descriptor table. + * One entry for each open kernel vnode and socket. + * + * Locks used to protect struct members in this file: + * I immutable after creation + * F global `fhdlk' mutex + * a atomic operations + * f per file `f_mtx' + * v vnode lock + */ +struct file { + LIST_ENTRY(file) f_list;/* [F] list of active files */ + struct mutex f_mtx; + u_int f_flag; /* [a] see fcntl.h */ + u_int f_iflags; /* [a] internal flags */ + int f_type; /* [I] descriptor type */ + u_int f_count; /* [a] reference count */ + struct ucred *f_cred; /* [I] credentials associated with descriptor */ + const struct fileops *f_ops; /* [I] file operation pointers */ + off_t f_offset; /* [f,v] offset */ + void *f_data; /* [I] private data */ + uint64_t f_rxfer; /* [f] total number of read transfers */ + uint64_t f_wxfer; /* [f] total number of write transfers */ + uint64_t f_seek; /* [f] total independent seek operations */ + uint64_t f_rbytes; /* [f] total bytes read */ + uint64_t f_wbytes; /* [f] total bytes written */ +}; + +#define FIF_HASLOCK 0x01 /* descriptor holds advisory lock */ +#define FIF_INSERTED 0x80 /* present in `filehead' */ + +#define FREF(fp) \ + do { \ + extern void vfs_stall_barrier(void); \ + vfs_stall_barrier(); \ + atomic_inc_int(&(fp)->f_count); \ + } while (0) + +#define FRELE(fp,p) \ + (atomic_dec_int_nv(&fp->f_count) == 0 ? fdrop(fp, p) : 0) + +#define FDUP_MAX_COUNT (UINT_MAX - 2 * MAXCPUS) + +int fdrop(struct file *, struct proc *); + +static inline off_t +foffset(struct file *fp) +{ + off_t offset; + + mtx_enter(&fp->f_mtx); + offset = fp->f_offset; + mtx_leave(&fp->f_mtx); + return (offset); +} + +LIST_HEAD(filelist, file); +extern int maxfiles; /* kernel limit on number of open files */ +extern int numfiles; /* actual number of open files */ +extern const struct fileops socketops; /* socket operations for files */ +extern const struct fileops vnops; /* vnode operations for files */ + +#endif /* _KERNEL */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/filedesc.h b/lib/libc/include/generic-openbsd/sys/filedesc.h new file mode 100644 index 0000000000..77a2106961 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/filedesc.h @@ -0,0 +1,159 @@ +/* $OpenBSD: filedesc.h,v 1.48 2025/08/04 04:59:30 guenther Exp $ */ +/* $NetBSD: filedesc.h,v 1.14 1996/04/09 20:55:28 cgd 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. + * + * @(#)filedesc.h 8.1 (Berkeley) 6/2/93 + */ + +#include +#include +/* + * This structure is used for the management of descriptors. It may be + * shared by multiple processes. + * + * A process is initially started out with NDFILE descriptors stored within + * this structure, selected to be enough for typical applications based on + * the historical limit of 20 open files (and the usage of descriptors by + * shells). If these descriptors are exhausted, a larger descriptor table + * may be allocated, up to a process' resource limit; the internal arrays + * are then unused. The initial expansion is set to NDEXTENT; each time + * it runs out, it is doubled until the resource limit is reached. NDEXTENT + * should be selected to be the biggest multiple of OFILESIZE (see below) + * that will fit in a power-of-two sized piece of memory. + */ +#define NDFILE 20 +#define NDEXTENT 50 /* 250 bytes in 256-byte alloc. */ +#define NDENTRIES 32 /* 32 fds per entry */ +#define NDENTRYMASK (NDENTRIES - 1) +#define NDENTRYSHIFT 5 /* bits per entry */ +#define NDREDUCE(x) (((x) + NDENTRIES - 1) >> NDENTRYSHIFT) +#define NDHISLOTS(x) (NDREDUCE(NDREDUCE(x))) +#define NDLOSLOTS(x) (NDHISLOTS(x) << NDENTRYSHIFT) + +struct kqueue; + +/* + * Locking: + * a atomic operations + * f fd_lock + * f/w fd_lock when writing + * K kernel lock + * m fd_fplock + */ +struct filedesc { + struct file **fd_ofiles; /* [f/w,m] file structures for + * open files */ + char *fd_ofileflags; /* [f] per-process open file flags */ + struct vnode *fd_cdir; /* [K] current directory */ + struct vnode *fd_rdir; /* [K] root directory */ + int fd_nfiles; /* [f] number of open files allocated */ + int fd_openfd; /* [f] number of files currently open */ + u_int *fd_himap; /* [f] each bit points to 32 fds */ + u_int *fd_lomap; /* [f] bitmap of free fds */ + int fd_lastfile; /* [f] high-water mark of fd_ofiles */ + int fd_freefile; /* [f] approx. next free file */ + mode_t fd_cmask; /* [f/w] mask for file creation */ + u_int fd_refcnt; /* [K] reference count */ + struct rwlock fd_lock; /* lock for the file descs */ + struct mutex fd_fplock; /* lock for reading fd_ofiles without + * fd_lock */ + LIST_HEAD(, kqueue) fd_kqlist; /* [f] kqueues attached to this + * filedesc */ + int fd_flags; /* [a] flags on this filedesc */ + u_int fd_nuserevents; /* [a] number of kqueue user events */ +}; + +/* + * Basic allocation of descriptors: + * one of the above, plus arrays for NDFILE descriptors. + */ +struct filedesc0 { + struct filedesc fd_fd; + /* + * These arrays are used when the number of open files is + * <= NDFILE, and are then pointed to by the pointers above. + */ + struct file *fd_dfiles[NDFILE]; + char fd_dfileflags[NDFILE]; + /* + * There arrays are used when the number of open files is + * <= 1024, and are then pointed to by the pointers above. + */ + u_int fd_dhimap[NDENTRIES >> NDENTRYSHIFT]; + u_int fd_dlomap[NDENTRIES]; +}; + +/* + * Per-process open flags. + */ +#define UF_EXCLOSE 0x01 /* auto-close on exec */ +#define UF_PLEDGED 0x02 /* open after pledge(2) */ +#define UF_FORKCLOSE 0x04 /* auto-close on fork */ + +/* + * Flags on the file descriptor table. + */ +#define FD_ADVLOCK 0x01 /* May hold a POSIX adv. lock. */ + +/* + * Storage required per open file descriptor. + */ +#define OFILESIZE (sizeof(struct file *) + sizeof(char)) + +#ifdef _KERNEL +/* + * Kernel global variables and routines. + */ +void filedesc_init(void); +int dupfdopen(struct proc *, int, int); +int fdalloc(struct proc *p, int want, int *result); +void fdexpand(struct proc *); +struct file *fnew(struct proc *_p); +int falloc(struct proc *_p, struct file **_rfp, int *_rfd); +struct filedesc *fdinit(void); +struct filedesc *fdshare(struct process *); +struct filedesc *fdcopy(struct process *); +void fdfree(struct proc *p); +int fdrelease(struct proc *p, int); +void fdinsert(struct filedesc *, int, int, struct file *); +void fdremove(struct filedesc *, int); +void fdprepforexec(struct proc *); +struct file *fd_iterfile(struct file *, struct proc *); +struct file *fd_getfile(struct filedesc *, int); +struct file *fd_getfile_mode(struct filedesc *, int, int); +int fd_checkclosed(struct filedesc *, int, struct file *); + +int closef(struct file *, struct proc *); +int getsock(struct proc *, int, struct file **); + +#define fdplock(fdp) do { NET_ASSERT_UNLOCKED(); rw_enter_write(&(fdp)->fd_lock); } while (0) +#define fdpunlock(fdp) rw_exit_write(&(fdp)->fd_lock) +#define fdpassertlocked(fdp) rw_assert_wrlock(&(fdp)->fd_lock) +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/filio.h b/lib/libc/include/generic-openbsd/sys/filio.h new file mode 100644 index 0000000000..de381f3c69 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/filio.h @@ -0,0 +1,54 @@ +/* $OpenBSD: filio.h,v 1.5 2007/06/01 22:30:48 deraadt Exp $ */ +/* $NetBSD: filio.h,v 1.5 1994/06/29 06:44:14 cgd Exp $ */ + +/*- + * Copyright (c) 1982, 1986, 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)filio.h 8.1 (Berkeley) 3/28/94 + */ + +#ifndef _SYS_FILIO_H_ +#define _SYS_FILIO_H_ + +#include + +/* Generic file-descriptor ioctl's. */ +#define FIOCLEX _IO('f', 1) /* set close on exec on fd */ +#define FIONCLEX _IO('f', 2) /* remove close on exec */ +#define FIONREAD _IOR('f', 127, int) /* get # bytes to read */ +#define FIONBIO _IOW('f', 126, int) /* set/clear non-blocking i/o */ +#define FIOASYNC _IOW('f', 125, int) /* set/clear async i/o */ +#define FIOSETOWN _IOW('f', 124, int) /* set owner */ +#define FIOGETOWN _IOR('f', 123, int) /* get owner */ + +#endif /* !_SYS_FILIO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/fusebuf.h b/lib/libc/include/generic-openbsd/sys/fusebuf.h new file mode 100644 index 0000000000..80e4e3d942 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/fusebuf.h @@ -0,0 +1,148 @@ +/* $OpenBSD: fusebuf.h,v 1.16 2025/09/06 06:15:52 helg Exp $ */ +/* + * Copyright (c) 2013 Sylvestre Gallon + * Copyright (c) 2013 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 _SYS_FUSEBUF_H_ +#define _SYS_FUSEBUF_H_ + +/* + * Maximum size of the read or write buffer sent from the kernel for VFS + * syscalls: read, readdir, readlink, write. + */ +#define FUSEBUFMAXSIZE (4096*1024) + +/* header at beginning of each fusebuf: */ +struct fb_hdr { + SIMPLEQ_ENTRY(fusebuf) fh_next; /* next buffer in chain */ + size_t fh_len; /* Amount of data */ + int fh_err; /* errno to pass back */ + int fh_type; /* type of data */ + ino_t fh_ino; /* Inode of this fusebuf */ + uint64_t fh_uuid; /* Uuid to track the answer */ + pid_t fh_tid; /* calling proc thread id */ + uid_t fh_uid; /* calling proc uid */ + gid_t fh_gid; /* calling proc gid */ + mode_t fh_umask; /* calling proc umask */ +}; + +/* header for fuse file operations (like read/write/mkdir): */ +struct fb_io { + uint64_t fi_fd; /* fd where the io is performed */ + ino_t fi_ino; /* ino for the io */ + off_t fi_off; /* offset for the io */ + size_t fi_len; /* Length of data */ + mode_t fi_mode; /* mode for fd */ + uint32_t fi_flags; /* flags on transfer */ + dev_t fi_rdev; /* dev for mknod */ +}; + +/* + * An operation is issued by the kernel through fuse(4) when the + * userland file system needs to execute an action (mkdir(2), + * link(2), etc). + * + * F_databuf can be superior to FUSELEN for fusefs_read, fusefs_writes and + * fusefs_readdir. If it is the case the transfer will be split in N + * fusebuf with a changing offset in FD_io. + * + * When the userland file system answers to this operation it uses + * the same ID (fh_uuid). + */ +struct fusebuf { + struct fb_hdr fb_hdr; + union { + struct statvfs FD_stat; /* vfs statfs */ + struct stat FD_attr; /* for attr vnops */ + struct fb_io FD_io; /* for file io vnops */ + } FD; + uint8_t *fb_dat; /* data's */ +}; + +#define fb_next fb_hdr.fh_next +#define fb_len fb_hdr.fh_len +#define fb_err fb_hdr.fh_err +#define fb_type fb_hdr.fh_type +#define fb_ino fb_hdr.fh_ino +#define fb_uuid fb_hdr.fh_uuid +#define fb_tid fb_hdr.fh_tid +#define fb_uid fb_hdr.fh_uid +#define fb_gid fb_hdr.fh_gid +#define fb_umask fb_hdr.fh_umask + +#define fb_stat FD.FD_stat +#define fb_attr FD.FD_attr +#define fb_io_fd FD.FD_io.fi_fd +#define fb_io_ino FD.FD_io.fi_ino +#define fb_io_off FD.FD_io.fi_off +#define fb_io_len FD.FD_io.fi_len +#define fb_io_mode FD.FD_io.fi_mode +#define fb_io_flags FD.FD_io.fi_flags +#define fb_io_rdev FD.FD_io.fi_rdev + +/* + * Macros for type conversion + * fbtod(fb,t) - convert fusebuf pointer to data pointer of correct + * type + */ +#define fbtod(fb,t) ((t)((fb)->fb_dat)) + +/* flags needed by setattr */ +#define FUSE_FATTR_MODE (1 << 0) +#define FUSE_FATTR_UID (1 << 1) +#define FUSE_FATTR_GID (1 << 2) +#define FUSE_FATTR_SIZE (1 << 3) +#define FUSE_FATTR_ATIME (1 << 4) +#define FUSE_FATTR_MTIME (1 << 5) +#define FUSE_FATTR_FH (1 << 6) + +/* fusebuf types */ +#define FBT_LOOKUP 0 +#define FBT_GETATTR 1 +#define FBT_SETATTR 2 +#define FBT_READLINK 3 +#define FBT_SYMLINK 4 +#define FBT_MKNOD 5 +#define FBT_MKDIR 6 +#define FBT_UNLINK 7 +#define FBT_RMDIR 8 +#define FBT_RENAME 9 +#define FBT_LINK 10 +#define FBT_OPEN 11 +#define FBT_READ 12 +#define FBT_WRITE 13 +#define FBT_STATFS 14 +#define FBT_RELEASE 16 +#define FBT_FSYNC 17 +#define FBT_FLUSH 18 +#define FBT_INIT 19 +#define FBT_OPENDIR 20 +#define FBT_READDIR 21 +#define FBT_RELEASEDIR 22 +#define FBT_FSYNCDIR 23 +#define FBT_ACCESS 24 +#define FBT_DESTROY 26 +#define FBT_RECLAIM 27 + +#ifdef _KERNEL + +/* fusebuf prototypes */ +struct fusebuf *fb_setup(size_t, ino_t, int, struct proc *); +int fb_queue(dev_t, struct fusebuf *); +void fb_delete(struct fusebuf *); + +#endif /* _KERNEL */ +#endif /* _SYS_FUSEBUF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/futex.h b/lib/libc/include/generic-openbsd/sys/futex.h new file mode 100644 index 0000000000..660d553464 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/futex.h @@ -0,0 +1,45 @@ +/* $OpenBSD: futex.h,v 1.3 2025/05/07 00:39:09 dlg Exp $ */ + +/* + * Copyright (c) 2016 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 _SYS_FUTEX_H_ +#define _SYS_FUTEX_H_ + +#ifndef _KERNEL +#include + +__BEGIN_DECLS +int futex(volatile uint32_t *, int, int, const struct timespec *, + volatile uint32_t *); +__END_DECLS +#endif /* ! _KERNEL */ + +#define FUTEX_OP_MASK 0x007f + +#define FUTEX_WAIT 1 +#define FUTEX_WAKE 2 +#define FUTEX_REQUEUE 3 + +#define FUTEX_FLAG_MASK 0xff80 + +#define FUTEX_PRIVATE_FLAG 0x0080 + +#define FUTEX_WAIT_PRIVATE (FUTEX_WAIT | FUTEX_PRIVATE_FLAG) +#define FUTEX_WAKE_PRIVATE (FUTEX_WAKE | FUTEX_PRIVATE_FLAG) +#define FUTEX_REQUEUE_PRIVATE (FUTEX_REQUEUE | FUTEX_PRIVATE_FLAG) + +#endif /* _SYS_FUTEX_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/gmon.h b/lib/libc/include/generic-openbsd/sys/gmon.h new file mode 100644 index 0000000000..2f1194c025 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/gmon.h @@ -0,0 +1,182 @@ +/* $OpenBSD: gmon.h,v 1.12 2025/07/16 16:22:58 deraadt Exp $ */ +/* $NetBSD: gmon.h,v 1.5 1996/04/09 20:55:30 cgd Exp $ */ + +/*- + * Copyright (c) 1982, 1986, 1992, 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. + * + * @(#)gmon.h 8.2 (Berkeley) 1/4/94 + */ + +#ifndef _SYS_GMON_H_ +#define _SYS_GMON_H_ + +#include +#include + +/* + * Structure prepended to gmon.out profiling data file. + */ +struct gmonhdr { + u_long lpc; /* base pc address of sample buffer */ + u_long hpc; /* max pc address of sampled buffer */ + int ncnt; /* size of sample buffer (plus this header) */ + int version; /* version number */ + int profrate; /* profiling clock rate */ + int totarc; /* space used by arcs */ + int spare[2]; /* reserved */ +}; +#define GMONVERSION 0x00051879 + +/* + * histogram counters are unsigned shorts (according to the kernel). + */ +#define HISTCOUNTER unsigned short + +/* + * fraction of text space to allocate for histogram counters here, 1/2 + */ +#define HISTFRACTION 2 + +/* + * Fraction of text space to allocate for from hash buckets. + * The value of HASHFRACTION is based on the minimum number of bytes + * of separation between two subroutine call points in the object code. + * Given MIN_SUBR_SEPARATION bytes of separation the value of + * HASHFRACTION is calculated as: + * + * HASHFRACTION = MIN_SUBR_SEPARATION / (2 * sizeof(short) - 1); + * + * For example, on the VAX, the shortest two call sequence is: + * + * calls $0,(r0) + * calls $0,(r0) + * + * which is separated by only three bytes, thus HASHFRACTION is + * calculated as: + * + * HASHFRACTION = 3 / (2 * 2 - 1) = 1 + * + * Note that the division above rounds down, thus if MIN_SUBR_FRACTION + * is less than three, this algorithm will not work! + * + * In practice, however, call instructions are rarely at a minimal + * distance. Hence, we will define HASHFRACTION to be 2 across all + * architectures. This saves a reasonable amount of space for + * profiling data structures without (in practice) sacrificing + * any granularity. + */ +#define HASHFRACTION 2 + +/* + * percent of text space to allocate for tostructs with a minimum. + */ +#define ARCDENSITY 2 +#define MINARCS 50 +#define MAXARCS ((1 << (8 * sizeof(HISTCOUNTER))) - 2) + +struct tostruct { + u_long selfpc; + long count; + u_short link; + u_short pad; +}; + +/* + * a raw arc, with pointers to the calling site and + * the called site and a count. + */ +struct rawarc { + u_long raw_frompc; + u_long raw_selfpc; + long raw_count; +}; + +/* + * general rounding functions. + */ +#define ROUNDDOWN(x,y) (((x)/(y))*(y)) +#define ROUNDUP(x,y) ((((x)+(y)-1)/(y))*(y)) + +/* + * The profiling data structures are housed in this structure. + */ +struct gmonparam { + int state; + u_short *kcount; + u_long kcountsize; + u_short *froms; + u_long fromssize; + struct tostruct *tos; + u_long tossize; + long tolimit; + u_long lowpc; + u_long highpc; + u_long textsize; + u_long hashfraction; + void *outbuf; + size_t outbuflen; + void *rawarcs; + int dirfd; + SLIST_ENTRY(gmonparam) list; +}; + +/* + * Possible states of profiling. + */ +#define GMON_PROF_ON 0 +#define GMON_PROF_BUSY 1 +#define GMON_PROF_ERROR 2 +#define GMON_PROF_OFF 3 + +/* + * Sysctl definitions for extracting profiling information from the kernel. + */ +#define GPROF_STATE 0 /* int: profiling enabling variable */ +#define GPROF_COUNT 1 /* struct: profile tick count buffer */ +#define GPROF_FROMS 2 /* struct: from location hash bucket */ +#define GPROF_TOS 3 /* struct: destination/count structure */ +#define GPROF_GMONPARAM 4 /* struct: profiling parameters (see above) */ + +#ifdef _KERNEL +extern int gmoninit; /* Is the kernel ready for being profiled? */ + +#else /* !_KERNEL */ + +#include + +__BEGIN_DECLS +extern struct gmonparam _gmonparam; +void _mcleanup(void); +void _monstartup(u_long, u_long); +void moncontrol(int); +struct gmonparam *_gmon_alloc(void); +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_SYS_GMON_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/gpio.h b/lib/libc/include/generic-openbsd/sys/gpio.h new file mode 100644 index 0000000000..95cbc9c82e --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/gpio.h @@ -0,0 +1,80 @@ +/* $OpenBSD: gpio.h,v 1.8 2011/10/03 20:24:51 matthieu Exp $ */ +/* + * Copyright (c) 2004 Alexander Yurchenko + * + * 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 _SYS_GPIO_H_ +#define _SYS_GPIO_H_ + +/* GPIO pin states */ +#define GPIO_PIN_LOW 0x00 /* low level (logical 0) */ +#define GPIO_PIN_HIGH 0x01 /* high level (logical 1) */ + +/* Max name length of a pin */ +#define GPIOPINMAXNAME 64 + +/* GPIO pin configuration flags */ +#define GPIO_PIN_INPUT 0x0001 /* input direction */ +#define GPIO_PIN_OUTPUT 0x0002 /* output direction */ +#define GPIO_PIN_INOUT 0x0004 /* bi-directional */ +#define GPIO_PIN_OPENDRAIN 0x0008 /* open-drain output */ +#define GPIO_PIN_PUSHPULL 0x0010 /* push-pull output */ +#define GPIO_PIN_TRISTATE 0x0020 /* output disabled */ +#define GPIO_PIN_PULLUP 0x0040 /* internal pull-up enabled */ +#define GPIO_PIN_PULLDOWN 0x0080 /* internal pull-down enabled */ +#define GPIO_PIN_INVIN 0x0100 /* invert input */ +#define GPIO_PIN_INVOUT 0x0200 /* invert output */ +#define GPIO_PIN_USER 0x0400 /* user != 0 can access */ +#define GPIO_PIN_SET 0x8000 /* set for securelevel access */ + +/* GPIO controller description */ +struct gpio_info { + int gpio_npins; /* total number of pins available */ +}; + +/* GPIO pin operation (read/write/toggle) */ +struct gpio_pin_op { + char gp_name[GPIOPINMAXNAME]; /* pin name */ + int gp_pin; /* pin number */ + int gp_value; /* value */ +}; + +/* GPIO pin configuration */ +struct gpio_pin_set { + char gp_name[GPIOPINMAXNAME]; + int gp_pin; + int gp_caps; + int gp_flags; + char gp_name2[GPIOPINMAXNAME]; /* new name */ +}; + +/* Attach/detach device drivers that use GPIO pins */ +struct gpio_attach { + char ga_dvname[16]; /* device name */ + int ga_offset; /* pin number */ + u_int32_t ga_mask; /* binary mask */ + u_int32_t ga_flags; /* flags */ +}; + +#define GPIOINFO _IOR('G', 0, struct gpio_info) +#define GPIOPINREAD _IOWR('G', 1, struct gpio_pin_op) +#define GPIOPINWRITE _IOWR('G', 2, struct gpio_pin_op) +#define GPIOPINTOGGLE _IOWR('G', 3, struct gpio_pin_op) +#define GPIOPINSET _IOWR('G', 4, struct gpio_pin_set) +#define GPIOPINUNSET _IOWR('G', 5, struct gpio_pin_set) +#define GPIOATTACH _IOWR('G', 6, struct gpio_attach) +#define GPIODETACH _IOWR('G', 7, struct gpio_attach) + +#endif /* !_SYS_GPIO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/hibernate.h b/lib/libc/include/generic-openbsd/sys/hibernate.h new file mode 100644 index 0000000000..d7e3176f19 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/hibernate.h @@ -0,0 +1,162 @@ +/* $OpenBSD: hibernate.h,v 1.51 2025/07/05 09:24:37 jsg Exp $ */ + +/* + * Copyright (c) 2011 Ariane van der Steldt + * + * 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 _SYS_HIBERNATE_H_ +#define _SYS_HIBERNATE_H_ + +#include +#include +#include +#include + +#define HIB_PHYSSEG_MAX 22 + +#define HIBERNATE_CHUNK_USED 1 +#define HIBERNATE_CHUNK_CONFLICT 2 +#define HIBERNATE_CHUNK_PLACED 4 + +/* Magic number used to indicate hibernate signature block */ +#define HIBERNATE_MAGIC 0x0B5D0B5D + +/* Page skip operations used during unpack */ +#define HIB_MOVE 2 +#define HIB_SKIP 1 + +struct hiballoc_entry; + +/* + * Allocator operates from an arena, that is pre-allocated by the caller. + */ +struct hiballoc_arena { + RBT_HEAD(hiballoc_addr, hiballoc_entry) hib_addrs; +}; + +/* + * Describes a zlib compression stream and its associated hiballoc area + */ +struct hibernate_zlib_state { + z_stream hib_stream; + struct hiballoc_arena hiballoc_arena; +}; + +/* + * Describes a range of physical memory on the machine + */ +struct hibernate_memory_range { + paddr_t base; + paddr_t end; +}; + +/* + * Describes a hibernate chunk structure, used when splitting the memory + * image of the machine into easy-to-manage pieces. + */ +struct hibernate_disk_chunk { + paddr_t base; /* Base of chunk */ + paddr_t end; /* End of chunk */ + daddr_t offset; /* Abs. disk block locating chunk */ + size_t compressed_size; /* Compressed size on disk */ + short flags; /* Flags */ +}; + +#define HIB_INIT -1 +#define HIB_DONE -2 +#define HIB_R 0 +#define HIB_W 1 +typedef int (*hibio_fn)(dev_t, daddr_t, vaddr_t, size_t, int, void *); + +/* + * Used to store information about the hibernation state of the machine, + * such as memory range count and extents, disk sector size, and various + * offsets where things are located on disk. + */ +union hibernate_info { + struct { + u_int32_t magic; + dev_t dev; + size_t nranges; + struct hibernate_memory_range ranges[HIB_PHYSSEG_MAX]; + size_t image_size; + size_t chunk_ctr; + daddr_t sig_offset; + daddr_t chunktable_offset; + daddr_t image_offset; + paddr_t piglet_pa; + vaddr_t piglet_va; + hibio_fn io_func; + void *io_page; + u_int8_t kern_hash[SHA256_DIGEST_LENGTH]; +#ifndef NO_PROPOLICE + long guard; +#endif /* ! NO_PROPOLICE */ + u_int32_t retguard_ofs; + u_int32_t sec_size; + }; + + /* XXX - remove restriction to have the struct fit in a single block */ + char pad[4096]; /* Pad to largest allowable disk sector size in bytes */ +}; + +void *hib_alloc(struct hiballoc_arena*, size_t); +void hib_free(struct hiballoc_arena*, void*); +int hiballoc_init(struct hiballoc_arena*, void*, size_t len); +void uvm_pmr_dirty_everything(void); +int uvm_pmr_alloc_pig(paddr_t*, psize_t, paddr_t); +int uvm_pmr_alloc_piglet(vaddr_t*, paddr_t*, vsize_t, paddr_t); +int uvm_page_rle(paddr_t); +void uvmpd_hibernate(void); + +hibio_fn get_hibernate_io_function(dev_t); +int get_hibernate_info(union hibernate_info *, int); + +int hibernate_zlib_reset(union hibernate_info *, int); +void *hibernate_zlib_alloc(void *, int, int); +void hibernate_zlib_free(void *, void *); +void hibernate_inflate_region(union hibernate_info *, paddr_t, paddr_t, + size_t); +size_t hibernate_deflate(union hibernate_info *, paddr_t, size_t *); +void hibernate_process_chunk(union hibernate_info *, + struct hibernate_disk_chunk *, paddr_t); +int hibernate_inflate_page(int *); + +int hibernate_block_io(union hibernate_info *, daddr_t, size_t, vaddr_t, int); +int hibernate_write_signature(union hibernate_info *); +int hibernate_write_chunktable(union hibernate_info *); +int hibernate_write_chunks(union hibernate_info *); +int hibernate_clear_signature(union hibernate_info *); +int hibernate_compare_signature(union hibernate_info *, + union hibernate_info *); +void hibernate_resume(void); +int hibernate_suspend(void); +int hibernate_read_image(union hibernate_info *); +int hibernate_read_chunks(union hibernate_info *, paddr_t, paddr_t, size_t, + struct hibernate_disk_chunk *); +void hibernate_unpack_image(union hibernate_info *); +void hibernate_populate_resume_pt(union hibernate_info *, paddr_t, paddr_t); +int hibernate_alloc(void); +void hibernate_free(void); +void hib_getentropy(char **, size_t *); + +int hibernate_write(union hibernate_info *, daddr_t, vaddr_t, size_t, int); +void hibernate_sort_ranges(union hibernate_info *); +void hibernate_suspend_bufcache(void); +void hibernate_resume_bufcache(void); + +void preallocate_hibernate_memory(void); + +#endif /* _SYS_HIBERNATE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/hotplug.h b/lib/libc/include/generic-openbsd/sys/hotplug.h new file mode 100644 index 0000000000..29529e1278 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/hotplug.h @@ -0,0 +1,40 @@ +/* $OpenBSD: hotplug.h,v 1.5 2006/05/28 16:52:34 mk Exp $ */ +/* + * Copyright (c) 2004 Alexander Yurchenko + * + * 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 _SYS_HOTPLUG_H_ +#define _SYS_HOTPLUG_H_ + +/* + * Public interface for enqueuing and dequeueing device + * attachment and detachment notifications. + */ + +#define HOTPLUG_DEVAT 0x01 /* device attached */ +#define HOTPLUG_DEVDT 0x02 /* device detached */ + +struct hotplug_event { + int he_type; /* event type */ + enum devclass he_devclass; /* device class */ + char he_devname[16]; /* device name */ +}; + +#ifdef _KERNEL +void hotplug_device_attach(enum devclass, char *); +void hotplug_device_detach(enum devclass, char *); +#endif + +#endif /* _SYS_HOTPLUG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/intrmap.h b/lib/libc/include/generic-openbsd/sys/intrmap.h new file mode 100644 index 0000000000..de64e1cdd1 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/intrmap.h @@ -0,0 +1,33 @@ +/* $OpenBSD: intrmap.h,v 1.4 2025/06/13 09:48:45 jsg Exp $ */ + +/* + * Copyright (c) 2020 David Gwynne + * + * 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 _SYS_INTRMAP_H_ +#define _SYS_INTRMAP_H_ + +struct intrmap; + +#define INTRMAP_POWEROF2 (1 << 0) + +struct intrmap *intrmap_create(const struct device *, + unsigned int, unsigned int, unsigned int); +void intrmap_destroy(struct intrmap *); + +unsigned int intrmap_count(const struct intrmap *); +struct cpu_info *intrmap_cpu(const struct intrmap *, unsigned int); + +#endif /* _SYS_INTRMAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/ioccom.h b/lib/libc/include/generic-openbsd/sys/ioccom.h new file mode 100644 index 0000000000..36d9d1da94 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/ioccom.h @@ -0,0 +1,68 @@ +/* $OpenBSD: ioccom.h,v 1.6 2025/05/02 10:14:46 jsg Exp $ */ +/* $NetBSD: ioccom.h,v 1.4 1994/10/30 21:49:56 cgd Exp $ */ + +/*- + * Copyright (c) 1982, 1986, 1990, 1993, 1994 + * 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. + * + * @(#)ioccom.h 8.2 (Berkeley) 3/28/94 + */ + +#ifndef _SYS_IOCCOM_H_ +#define _SYS_IOCCOM_H_ + +/* + * Ioctl's have the command encoded in the lower word, and the size of + * any in or out parameters in the upper word. The high 3 bits of the + * upper word are used to encode the in/out status of the parameter. + */ +#define IOCPARM_MASK 0x1fff /* parameter length, at most 13 bits */ +#define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK) +#define IOCBASECMD(x) ((x) & ~(IOCPARM_MASK << 16)) +#define IOCGROUP(x) (((x) >> 8) & 0xff) + +#define IOCPARM_MAX PAGE_SIZE /* max size of ioctl args */ + /* no parameters */ +#define IOC_VOID 0x20000000UL + /* copy parameters out */ +#define IOC_OUT 0x40000000UL + /* copy parameters in */ +#define IOC_IN 0x80000000UL + /* copy parameters in and out */ +#define IOC_INOUT (IOC_IN|IOC_OUT) + /* mask for IN/OUT/VOID */ +#define IOC_DIRMASK 0xe0000000UL + +#define _IOC(inout,group,num,len) \ + (inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num)) +#define _IO(g,n) _IOC(IOC_VOID, (g), (n), 0) +#define _IOR(g,n,t) _IOC(IOC_OUT, (g), (n), sizeof(t)) +#define _IOW(g,n,t) _IOC(IOC_IN, (g), (n), sizeof(t)) +/* this should be _IORW, but stdio got there first */ +#define _IOWR(g,n,t) _IOC(IOC_INOUT, (g), (n), sizeof(t)) + +#endif /* !_SYS_IOCCOM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/ioctl.h b/lib/libc/include/generic-openbsd/sys/ioctl.h new file mode 100644 index 0000000000..0f862b6e8f --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/ioctl.h @@ -0,0 +1,55 @@ +/* $OpenBSD: ioctl.h,v 1.17 2016/02/28 15:46:19 naddy Exp $ */ +/* $NetBSD: ioctl.h,v 1.20 1996/01/30 18:21:47 thorpej Exp $ */ + +/*- + * Copyright (c) 1982, 1986, 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)ioctl.h 8.6 (Berkeley) 3/28/94 + */ + +#ifndef _SYS_IOCTL_H_ +#define _SYS_IOCTL_H_ + +#include +#include +#include + +#ifndef _KERNEL + +#include + +__BEGIN_DECLS +int ioctl(int, unsigned long, ...); +__END_DECLS +#endif /* !_KERNEL */ +#endif /* !_SYS_IOCTL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/ipc.h b/lib/libc/include/generic-openbsd/sys/ipc.h new file mode 100644 index 0000000000..7f45b5a779 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/ipc.h @@ -0,0 +1,95 @@ +/* $OpenBSD: ipc.h,v 1.13 2014/11/15 21:42:50 guenther Exp $ */ +/* $NetBSD: ipc.h,v 1.15 1996/02/09 18:25:12 christos Exp $ */ + +/* + * Copyright (c) 1988 University of Utah. + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department. + * + * 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. + * + * @(#)ipc.h 8.3 (Berkeley) 1/21/94 + */ + +/* + * SVID compatible ipc.h file + */ +#ifndef _SYS_IPC_H_ +#define _SYS_IPC_H_ + +#include + +struct ipc_perm { + uid_t cuid; /* creator user id */ + gid_t cgid; /* creator group id */ + uid_t uid; /* user id */ + gid_t gid; /* group id */ + mode_t mode; /* r/w permission */ + unsigned short seq; /* sequence # (to generate unique msg/sem/shm id) */ + key_t key; /* user specified msg/sem/shm key */ +}; + +/* common mode bits */ +#define IPC_R 000400 /* read permission */ +#define IPC_W 000200 /* write/alter permission */ +#define IPC_M 010000 /* permission to change control info */ + +/* SVID required constants (same values as system 5) */ +#define IPC_CREAT 001000 /* create entry if key does not exist */ +#define IPC_EXCL 002000 /* fail if key exists */ +#define IPC_NOWAIT 004000 /* error if request must wait */ + +#define IPC_PRIVATE (key_t)0 /* private key */ + +#define IPC_RMID 0 /* remove identifier */ +#define IPC_SET 1 /* set options */ +#define IPC_STAT 2 /* get options */ + +#ifdef _KERNEL +/* Macros to convert between ipc ids and array indices or sequence ids */ +#define IPCID_TO_IX(id) ((id) & 0xffff) +#define IPCID_TO_SEQ(id) (((id) >> 16) & 0xffff) +#define IXSEQ_TO_IPCID(ix,perm) (((perm.seq) << 16) | (ix & 0xffff)) + +struct ucred; + +int ipcperm(struct ucred *, struct ipc_perm *, int); + +#else /* !_KERNEL */ + +__BEGIN_DECLS +key_t ftok(const char *, int); +__END_DECLS +#endif +#endif /* !_SYS_IPC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/kcore.h b/lib/libc/include/generic-openbsd/sys/kcore.h new file mode 100644 index 0000000000..571c9d4ad2 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/kcore.h @@ -0,0 +1,60 @@ +/* $OpenBSD: kcore.h,v 1.2 2023/01/04 10:59:34 jsg Exp $ */ +/* $NetBSD: kcore.h,v 1.1 1996/03/10 21:56:00 leo Exp $ */ + +/* + * Copyright (c) 1996 Leo Weppelman. + * 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 _SYS_KCORE_H_ +#define _SYS_KCORE_H_ + +/* + * Definitions for the kernel crash-dump format. The structure of + * the files and headers is borrowed from the 'regular' core files + * as described in . + */ +#define KCORE_MAGIC 0x8fca +#define KCORESEG_MAGIC 0x8fac + +/* + * Description of a memory segment. To make this suitable for sharing + * between all architectures, u_quad_t seems to be the necessary type... + */ +typedef struct { + u_quad_t start; /* Physical start address */ + u_quad_t size; /* Size in bytes */ +} phys_ram_seg_t; + +typedef struct kcore_hdr { + u_int32_t c_midmag; /* Magic, id, flags */ + u_int16_t c_hdrsize; /* Aligned header size */ + u_int16_t c_seghdrsize; /* Aligned seg-header size */ + u_int32_t c_nseg; /* Number of segments */ +} kcore_hdr_t; + +typedef struct kcore_seg { + u_int32_t c_midmag; /* Magic, id, flags */ + u_int32_t c_size; /* Sizeof this segment */ +} kcore_seg_t; + +#endif /* _SYS_KCORE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/kcov.h b/lib/libc/include/generic-openbsd/sys/kcov.h new file mode 100644 index 0000000000..eb3e237f69 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/kcov.h @@ -0,0 +1,55 @@ +/* $OpenBSD: kcov.h,v 1.9 2023/07/29 06:52:08 anton Exp $ */ + +/* + * Copyright (c) 2018 Anton Lindqvist + * + * 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 _SYS_KCOV_H_ +#define _SYS_KCOV_H_ + +#include + +#define KIOSETBUFSIZE _IOW('K', 1, unsigned long) +#define KIOENABLE _IOW('K', 2, int) +#define KIODISABLE _IO('K', 3) +#define KIOREMOTEATTACH _IOW('K', 4, struct kio_remote_attach *) + +#define KCOV_MODE_NONE 0 +#define KCOV_MODE_TRACE_PC 1 +#define KCOV_MODE_TRACE_CMP 2 + +#define KCOV_REMOTE_COMMON 0 + +struct kio_remote_attach { + int subsystem; + int id; +}; + +#ifdef _KERNEL + +struct proc; + +extern int kcov_cold; + +void kcov_exit(struct proc *); +int kcov_vnode(struct vnode *); +void kcov_remote_register(int, void *); +void kcov_remote_unregister(int, void *); +void kcov_remote_enter(int, void *); +void kcov_remote_leave(int, void *); + +#endif /* _KERNEL */ + +#endif /* !_SYS_KCOV_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/kernel.h b/lib/libc/include/generic-openbsd/sys/kernel.h new file mode 100644 index 0000000000..54966635ee --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/kernel.h @@ -0,0 +1,61 @@ +/* $OpenBSD: kernel.h,v 1.28 2025/09/25 08:46:50 mvs Exp $ */ +/* $NetBSD: kernel.h,v 1.11 1995/03/03 01:24:16 cgd Exp $ */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)kernel.h 8.3 (Berkeley) 1/21/94 + */ + +/* Global variables for the kernel. */ + +/* 1.1 */ +extern int hostid; +extern char hostname[MAXHOSTNAMELEN]; +extern int hostnamelen; +extern char domainname[MAXHOSTNAMELEN]; +extern int domainnamelen; + +/* 1.2 */ +extern int utc_offset; /* seconds east of UTC */ + +extern int tick; /* usec per tick (1000000 / hz) */ +extern int tick_nsec; /* nsec per tick */ +extern int ticks; /* # of hardclock ticks */ +extern int hz; /* system clock's frequency */ +extern int stathz; /* statistics clock's frequency */ +extern int profhz; /* profiling clock's frequency */ + +#ifndef HZ +#define HZ 100 +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/kstat.h b/lib/libc/include/generic-openbsd/sys/kstat.h new file mode 100644 index 0000000000..97afc625d9 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/kstat.h @@ -0,0 +1,211 @@ +/* $OpenBSD: kstat.h,v 1.6 2025/05/13 21:20:10 kettenis Exp $ */ + +/* + * Copyright (c) 2020 David Gwynne + * + * 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 _SYS_KSTAT_H_ +#define _SYS_KSTAT_H_ + +#include + +#define KSTAT_STRLEN 32 + +#define KSTAT_T_RAW 0 +#define KSTAT_T_KV 1 +#define KSTAT_T_COUNTERS 2 + +struct kstat_req { + unsigned int ks_rflags; +#define KSTATIOC_F_IGNVER (1 << 0) + /* the current version of the kstat subsystem */ + unsigned int ks_version; + + uint64_t ks_id; + + char ks_provider[KSTAT_STRLEN]; + unsigned int ks_instance; + char ks_name[KSTAT_STRLEN]; + unsigned int ks_unit; + + struct timespec ks_created; + struct timespec ks_updated; + struct timespec ks_interval; + unsigned int ks_type; + unsigned int ks_state; + + void *ks_data; + size_t ks_datalen; + unsigned int ks_dataver; +}; + +/* ioctls */ + +#define KSTATIOC_VERSION _IOR('k', 1, unsigned int) +#define KSTATIOC_FIND_ID _IOWR('k', 2, struct kstat_req) +#define KSTATIOC_NFIND_ID _IOWR('k', 3, struct kstat_req) +#define KSTATIOC_FIND_PROVIDER _IOWR('k', 4, struct kstat_req) +#define KSTATIOC_NFIND_PROVIDER _IOWR('k', 5, struct kstat_req) +#define KSTATIOC_FIND_NAME _IOWR('k', 6, struct kstat_req) +#define KSTATIOC_NFIND_NAME _IOWR('k', 7, struct kstat_req) + +/* named data */ + +#define KSTAT_KV_NAMELEN 16 +#define KSTAT_KV_ALIGN sizeof(uint64_t) + +enum kstat_kv_type { + KSTAT_KV_T_NULL, + KSTAT_KV_T_BOOL, + KSTAT_KV_T_COUNTER64, + KSTAT_KV_T_COUNTER32, + KSTAT_KV_T_UINT64, + KSTAT_KV_T_INT64, + KSTAT_KV_T_UINT32, + KSTAT_KV_T_INT32, + KSTAT_KV_T_ISTR, /* inline string */ + KSTAT_KV_T_STR, /* trailing string */ + KSTAT_KV_T_BYTES, /* trailing bytes */ + KSTAT_KV_T_TEMP, /* temperature (uK) */ + KSTAT_KV_T_COUNTER16, + KSTAT_KV_T_UINT16, + KSTAT_KV_T_INT16, + KSTAT_KV_T_FREQ, /* frequency (Hz) */ + KSTAT_KV_T_VOLTS_DC, /* voltage (uV DC) */ + KSTAT_KV_T_VOLTS_AC, /* voltage (uV AC) */ + KSTAT_KV_T_AMPS, /* current (uA) */ + KSTAT_KV_T_WATTS, /* power (uW) */ +}; + +/* units only apply to integer types */ +enum kstat_kv_unit { + KSTAT_KV_U_NONE = 0, + KSTAT_KV_U_PACKETS, /* packets */ + KSTAT_KV_U_BYTES, /* bytes */ + KSTAT_KV_U_CYCLES, /* cycles */ +}; + +struct kstat_kv { + char kv_key[KSTAT_KV_NAMELEN]; + union { + char v_istr[16]; + unsigned int v_bool; + uint64_t v_u64; + int64_t v_s64; + uint32_t v_u32; + int32_t v_s32; + uint16_t v_u16; + int16_t v_s16; + size_t v_len; + } kv_v; + enum kstat_kv_type kv_type; + enum kstat_kv_unit kv_unit; +} __aligned(KSTAT_KV_ALIGN); + +#define kstat_kv_istr(_kv) (_kv)->kv_v.v_istr +#define kstat_kv_bool(_kv) (_kv)->kv_v.v_bool +#define kstat_kv_u64(_kv) (_kv)->kv_v.v_u64 +#define kstat_kv_s64(_kv) (_kv)->kv_v.v_s64 +#define kstat_kv_u32(_kv) (_kv)->kv_v.v_u32 +#define kstat_kv_s32(_kv) (_kv)->kv_v.v_s32 +#define kstat_kv_u16(_kv) (_kv)->kv_v.v_u16 +#define kstat_kv_s16(_kv) (_kv)->kv_v.v_s16 +#define kstat_kv_len(_kv) (_kv)->kv_v.v_len +#define kstat_kv_temp(_kv) (_kv)->kv_v.v_u64 +#define kstat_kv_freq(_kv) (_kv)->kv_v.v_u64 +#define kstat_kv_volts(_kv) (_kv)->kv_v.v_u64 +#define kstat_kv_amps(_kv) (_kv)->kv_v.v_u64 +#define kstat_kv_watts(_kv) (_kv)->kv_v.v_u64 + +#ifdef _KERNEL + +#include + +struct kstat_lock_ops; +struct rwlock; + +struct kstat { + uint64_t ks_id; + + const char *ks_provider; + unsigned int ks_instance; + const char *ks_name; + unsigned int ks_unit; + + unsigned int ks_type; + unsigned int ks_flags; +#define KSTAT_F_REALLOC (1 << 0) + unsigned int ks_state; +#define KSTAT_S_CREATED 0 +#define KSTAT_S_INSTALLED 1 + + struct timespec ks_created; + RBT_ENTRY(kstat) ks_id_entry; + RBT_ENTRY(kstat) ks_pv_entry; + RBT_ENTRY(kstat) ks_nm_entry; + + /* the driver can update these between kstat creation and install */ + unsigned int ks_dataver; + void *ks_softc; + void *ks_ptr; + int (*ks_read)(struct kstat *); + int (*ks_copy)(struct kstat *, void *); + + const struct kstat_lock_ops * + ks_lock_ops; + void *ks_lock; + + /* the data that is updated by ks_read */ + void *ks_data; + size_t ks_datalen; + struct timespec ks_updated; + struct timespec ks_interval; +}; + +struct kstat *kstat_create(const char *, unsigned int, + const char *, unsigned int, + unsigned int, unsigned int); + +void kstat_set_rlock(struct kstat *, struct rwlock *); +void kstat_set_wlock(struct kstat *, struct rwlock *); +void kstat_set_mutex(struct kstat *, struct mutex *); +void kstat_set_cpu(struct kstat *, struct cpu_info *); + +int kstat_read_nop(struct kstat *); + +void kstat_install(struct kstat *); +void kstat_remove(struct kstat *); +void kstat_destroy(struct kstat *); + +/* + * kstat_kv api + */ + +#define KSTAT_KV_UNIT_INITIALIZER(_key, _type, _unit) { \ + .kv_key = (_key), \ + .kv_type = (_type), \ + .kv_unit = (_unit), \ +} + +#define KSTAT_KV_INITIALIZER(_key, _type) \ + KSTAT_KV_UNIT_INITIALIZER((_key), (_type), KSTAT_KV_U_NONE) + +void kstat_kv_init(struct kstat_kv *, const char *, enum kstat_kv_type); +void kstat_kv_unit_init(struct kstat_kv *, const char *, + enum kstat_kv_type, enum kstat_kv_unit); + +#endif /* _KERNEL */ + +#endif /* _SYS_KSTAT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/kthread.h b/lib/libc/include/generic-openbsd/sys/kthread.h new file mode 100644 index 0000000000..b6acac804a --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/kthread.h @@ -0,0 +1,50 @@ +/* $OpenBSD: kthread.h,v 1.7 2020/02/18 12:13:40 mpi Exp $ */ +/* $NetBSD: kthread.h,v 1.2 1998/11/14 00:08:49 thorpej Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_KTHREAD_H_ +#define _SYS_KTHREAD_H_ + +/* + * Kernel thread handling. + */ + +#ifdef _KERNEL +struct proc; +int kthread_create(void (*)(void *), void *, struct proc **, + const char *); +void kthread_create_deferred(void (*)(void *), void *); +void kthread_run_deferred_queue(void); +void kthread_exit(int) __attribute__((__noreturn__)); +#endif /* _KERNEL */ + +#endif /* _SYS_KTHREAD_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/ktrace.h b/lib/libc/include/generic-openbsd/sys/ktrace.h new file mode 100644 index 0000000000..7a2af2b159 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/ktrace.h @@ -0,0 +1,277 @@ +/* $OpenBSD: ktrace.h,v 1.50 2024/07/27 02:10:26 guenther Exp $ */ +/* $NetBSD: ktrace.h,v 1.12 1996/02/04 02:12:29 christos Exp $ */ + +/* + * Copyright (c) 1988, 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. + * + * @(#)ktrace.h 8.1 (Berkeley) 6/2/93 + */ + +#include +#include +#include +#include + +/* + * operations to ktrace system call (KTROP(op)) + */ +#define KTROP_SET 0 /* set trace points */ +#define KTROP_CLEAR 1 /* clear trace points */ +#define KTROP_CLEARFILE 2 /* stop all tracing to file */ +#define KTROP(o) ((o)&3) /* macro to extract operation */ +/* + * flags (ORed in with operation) + */ +#define KTRFLAG_DESCEND 4 /* perform op on all children too */ + +/* + * ktrace record header + */ +struct ktr_header { + uint ktr_type; /* trace record type */ + pid_t ktr_pid; /* process id */ + pid_t ktr_tid; /* thread id */ + struct timespec ktr_time; /* timestamp */ + char ktr_comm[_MAXCOMLEN]; /* command name, incl NUL */ + size_t ktr_len; /* length of buf */ +}; + +/* + * ktrace record types + */ + + /* + * KTR_START - start of trace record, one per ktrace(KTROP_SET) syscall + */ +#define KTR_START 0x4b545200 /* "KTR" */ + +/* + * KTR_SYSCALL - system call record + */ +#define KTR_SYSCALL 1 +struct ktr_syscall { + int ktr_code; /* syscall number */ + int ktr_argsize; /* size of arguments */ + /* + * followed by ktr_argsize/sizeof(register_t) "register_t"s + */ +}; + +/* + * KTR_SYSRET - return from system call record + */ +#define KTR_SYSRET 2 +struct ktr_sysret { + int ktr_code; + int ktr_error; + /* + * If ktr_error is zero, then followed by retval: register_t for + * all syscalls except lseek(), which uses long long + */ +}; + +/* + * KTR_NAMEI - namei record + */ +#define KTR_NAMEI 3 + /* record contains pathname */ + +/* + * KTR_GENIO - trace generic process i/o + */ +#define KTR_GENIO 4 +struct ktr_genio { + int ktr_fd; + enum uio_rw ktr_rw; + /* + * followed by data successfully read/written + */ +}; + +/* + * KTR_PSIG - trace processed signal + */ +#define KTR_PSIG 5 +struct ktr_psig { + int signo; + sig_t action; + int mask; + int code; + siginfo_t si; +}; + +/* + * KTR_STRUCT - misc. structs + */ +#define KTR_STRUCT 8 + /* + * record contains null-terminated struct name followed by + * struct contents + */ +struct sockaddr; +struct stat; + +/* + * KTR_USER - user record + */ +#define KTR_USER 9 +#define KTR_USER_MAXIDLEN 20 +#define KTR_USER_MAXLEN 2048 /* maximum length of passed data */ +struct ktr_user { + char ktr_id[KTR_USER_MAXIDLEN]; /* string id of caller */ + /* + * Followed by ktr_len - sizeof(struct ktr_user) of user data. + */ +}; + +/* + * KTR_EXECARGS and KTR_EXECENV - args and environment records + */ +#define KTR_EXECARGS 10 +#define KTR_EXECENV 11 + + +/* + * KTR_PLEDGE - details of pledge violation + */ +#define KTR_PLEDGE 12 +struct ktr_pledge { + int error; + int syscall; + uint64_t code; +}; + +/* + * KTR_PINSYSCALL - details of pinsyscall violation + */ +#define KTR_PINSYSCALL 13 +struct ktr_pinsyscall { + int error; + int syscall; + vaddr_t addr; +}; + +/* + * kernel trace points (in ps_traceflag) + */ +#define KTRFAC_MASK 0x00ffffff +#define KTRFAC_SYSCALL (1< + +__BEGIN_DECLS +int ktrace(const char *, int, int, pid_t); +int utrace(const char *, const void *, size_t); +__END_DECLS + +#else + +/* + * Test for kernel trace point + */ +#define KTRPOINT(p, type) \ + ((p)->p_p->ps_traceflag & (1<<(type)) && ((p)->p_flag & P_INKTR) == 0) + +void ktrgenio(struct proc *, int, enum uio_rw, struct iovec *, ssize_t); +void ktrnamei(struct proc *, char *); +void ktrpsig(struct proc *, int, sig_t, int, int, siginfo_t *); +void ktrsyscall(struct proc *, register_t, size_t, register_t []); +void ktrsysret(struct proc *, register_t, int, const register_t [2]); +int ktruser(struct proc *, const char *, const void *, size_t); +void ktrexec(struct proc *, int, const char *, ssize_t); +void ktrpledge(struct proc *, int, uint64_t, int); +void ktrpinsyscall(struct proc *, int, int, vaddr_t); + +void ktrcleartrace(struct process *); +void ktrsettrace(struct process *, int, struct vnode *, struct ucred *); + +void ktrstruct(struct proc *, const char *, const void *, size_t); + +/* please keep these sorted by second argument to ktrstruct() */ +#define ktrabstimespec(p, s) \ + ktrstruct(p, "abstimespec", s, sizeof(struct timespec)) +#define ktrabstimeval(p, s) \ + ktrstruct(p, "abstimeval", s, sizeof(struct timeval)) +#define ktrcmsghdr(p, s, l) \ + ktrstruct(p, "cmsghdr", s, l) +#define ktrfds(p, s, c) \ + ktrstruct(p, "fds", s, (c) * sizeof(int)) +#define ktrfdset(p, s, l) \ + ktrstruct(p, "fdset", s, l) +#define ktrflock(p, s) \ + ktrstruct(p, "flock", s, sizeof(struct flock)) +#define ktriovec(p, s, c) \ + ktrstruct(p, "iovec", s, (c) * sizeof(struct iovec)) +#define ktritimerval(p, s) \ + ktrstruct(p, "itimerval", s, sizeof(struct itimerval)) +#define ktrevent(p, s, c) \ + ktrstruct(p, "kevent", s, (c) * sizeof(struct kevent)) +#define ktrmmsghdr(p, s) \ + ktrstruct(p, "mmsghdr", s, sizeof(struct mmsghdr)) +#define ktrmsghdr(p, s) \ + ktrstruct(p, "msghdr", s, sizeof(struct msghdr)) +#define ktrpollfd(p, s, c) \ + ktrstruct(p, "pollfd", s, (c) * sizeof(struct pollfd)) +#define ktrquota(p, s) \ + ktrstruct(p, "quota", s, sizeof(struct dqblk)) +#define ktrreltimespec(p, s) \ + ktrstruct(p, "reltimespec", s, sizeof(struct timespec)) +#define ktrreltimeval(p, s) \ + ktrstruct(p, "reltimeval", s, sizeof(struct timeval)) +#define ktrrlimit(p, s) \ + ktrstruct(p, "rlimit", s, sizeof(struct rlimit)) +#define ktrrusage(p, s) \ + ktrstruct(p, "rusage", s, sizeof(struct rusage)) +#define ktrsigaction(p, s) \ + ktrstruct(p, "sigaction", s, sizeof(struct sigaction)) +#define ktrsiginfo(p, s) \ + ktrstruct(p, "siginfo", s, sizeof(siginfo_t)) +#define ktrsockaddr(p, s, l) \ + ktrstruct(p, "sockaddr", s, l) +#define ktrstat(p, s) \ + ktrstruct(p, "stat", s, sizeof(struct stat)) + +#endif /* !_KERNEL */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/limits.h b/lib/libc/include/generic-openbsd/sys/limits.h new file mode 100644 index 0000000000..fc119cae35 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/limits.h @@ -0,0 +1,125 @@ +/* $OpenBSD: limits.h,v 1.10 2012/06/30 20:21:10 guenther Exp $ */ +/* + * Copyright (c) 2002 Marc Espie. + * + * 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 OPENBSD PROJECT 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 OPENBSD + * PROJECT 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 _SYS_LIMITS_H_ +#define _SYS_LIMITS_H_ + +#include + +/* Common definitions for limits.h. */ + +/* Legacy */ +#include + +#define CHAR_BIT 8 /* number of bits in a char */ + +#define SCHAR_MAX 0x7f /* max value for a signed char */ +#define SCHAR_MIN (-0x7f-1) /* min value for a signed char */ + +#define UCHAR_MAX 0xff /* max value for an unsigned char */ +#ifdef __CHAR_UNSIGNED__ +# define CHAR_MIN 0 /* min value for a char */ +# define CHAR_MAX 0xff /* max value for a char */ +#else +# define CHAR_MAX 0x7f +# define CHAR_MIN (-0x7f-1) +#endif + +#define MB_LEN_MAX 4 /* Allow UTF-8 (RFC 3629) */ + +#define USHRT_MAX 0xffff /* max value for an unsigned short */ +#define SHRT_MAX 0x7fff /* max value for a short */ +#define SHRT_MIN (-0x7fff-1) /* min value for a short */ + +#define UINT_MAX 0xffffffffU /* max value for an unsigned int */ +#define INT_MAX 0x7fffffff /* max value for an int */ +#define INT_MIN (-0x7fffffff-1) /* min value for an int */ + +#ifdef __LP64__ +# define ULONG_MAX 0xffffffffffffffffUL + /* max value for unsigned long */ +# define LONG_MAX 0x7fffffffffffffffL + /* max value for a signed long */ +# define LONG_MIN (-0x7fffffffffffffffL-1) + /* min value for a signed long */ +#else +# define ULONG_MAX 0xffffffffUL /* max value for an unsigned long */ +# define LONG_MAX 0x7fffffffL /* max value for a long */ +# define LONG_MIN (-0x7fffffffL-1)/* min value for a long */ +#endif + +#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 +# define ULLONG_MAX 0xffffffffffffffffULL + /* max value for unsigned long long */ +# define LLONG_MAX 0x7fffffffffffffffLL + /* max value for a signed long long */ +# define LLONG_MIN (-0x7fffffffffffffffLL-1) + /* min value for a signed long long */ +#endif + +#if __BSD_VISIBLE +# define UID_MAX UINT_MAX /* max value for a uid_t */ +# define GID_MAX UINT_MAX /* max value for a gid_t */ +#endif + +#if __XPG_VISIBLE || __POSIX_VISIBLE >= 200809 +# ifdef __LP64__ +# define LONG_BIT 64 +# else +# define LONG_BIT 32 +# endif +# define WORD_BIT 32 +#endif + +#if __XPG_VISIBLE < 600 +# include + +/* XSI defines marked LEGACY in XPG5 and removed in IEEE Std 1003.1-2001 */ +# ifndef FLT_DIG +# define FLT_DIG __FLT_DIG +# endif +# ifndef FLT_MAX +# define FLT_MAX __FLT_MAX +# endif +# ifndef DBL_DIG +# define DBL_DIG __DBL_DIG +# endif +# ifndef DBL_MAX +# define DBL_MAX __DBL_MAX +# endif + +/* XSI defines marked LEGACY in XPG4v2 and removed in XPG5 */ +# if __XPG_VISIBLE < 500 +# ifndef FLT_MIN +# define FLT_MIN __FLT_MIN +# endif +# ifndef DBL_MIN +# define DBL_MIN __DBL_MIN +# endif +# endif + +#endif /* __XPG_VISIBLE < 600 */ + +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/lock.h b/lib/libc/include/generic-openbsd/sys/lock.h new file mode 100644 index 0000000000..868be1f65c --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/lock.h @@ -0,0 +1,55 @@ +/* $OpenBSD: lock.h,v 1.27 2016/06/19 11:54:33 natano Exp $ */ + +/* + * Copyright (c) 1995 + * The Regents of the University of California. All rights reserved. + * + * This code contains ideas from software contributed to Berkeley by + * Avadis Tevanian, Jr., Michael Wayne Young, and the Mach Operating + * System project at Carnegie-Mellon University. + * + * 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. + * + * @(#)lock.h 8.12 (Berkeley) 5/19/95 + */ + +#ifndef _LOCK_H_ +#define _LOCK_H_ + +#include + +#define LK_EXCLUSIVE RW_WRITE /* exclusive lock */ +#define LK_SHARED RW_READ /* shared lock */ +#define LK_TYPE_MASK (RW_WRITE|RW_READ) /* type of lock sought */ +#define LK_NOWAIT RW_NOSLEEP /* do not sleep to await lock */ +#define LK_RECURSEFAIL RW_RECURSEFAIL /* fail if recursive exclusive lock */ +#define LK_EXCLOTHER RW_WRITE_OTHER /* exclusive lock held by some other thread */ +#define LK_RWFLAGS (RW_WRITE|RW_READ|RW_NOSLEEP|RW_RECURSEFAIL|RW_WRITE_OTHER) + +/* LK_ specific */ +#define LK_DRAIN 0x1000UL /* wait for all lock activity to end */ +#define LK_RETRY 0x2000UL /* vn_lock: retry until locked */ + +#endif /* !_LOCK_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/lockf.h b/lib/libc/include/generic-openbsd/sys/lockf.h new file mode 100644 index 0000000000..61d21d4f21 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/lockf.h @@ -0,0 +1,45 @@ +/* $OpenBSD: lockf.h,v 1.17 2019/04/20 08:28:59 anton Exp $ */ +/* $NetBSD: lockf.h,v 1.5 1994/06/29 06:44:33 cgd Exp $ */ + +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Scooter Morris at Genentech Inc. + * + * 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. + * + * @(#)lockf.h 8.1 (Berkeley) 6/11/93 + */ + +#ifdef _KERNEL +struct lockf_state; + +void lf_init(void); +int lf_advlock(struct lockf_state **, + off_t, caddr_t, int, struct flock *, int); +void lf_purgelocks(struct lockf_state **); +#endif /* _KERNEL */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/malloc.h b/lib/libc/include/generic-openbsd/sys/malloc.h new file mode 100644 index 0000000000..dd519d4bbb --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/malloc.h @@ -0,0 +1,399 @@ +/* $OpenBSD: malloc.h,v 1.127 2025/02/05 18:29:17 mvs Exp $ */ +/* $NetBSD: malloc.h,v 1.39 1998/07/12 19:52:01 augustss Exp $ */ + +/* + * Copyright (c) 1987, 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. + * + * @(#)malloc.h 8.5 (Berkeley) 5/3/95 + */ + +#ifndef _SYS_MALLOC_H_ +#define _SYS_MALLOC_H_ + +#include + +#define KERN_MALLOC_BUCKETS 1 +#define KERN_MALLOC_BUCKET 2 +#define KERN_MALLOC_KMEMNAMES 3 +#define KERN_MALLOC_KMEMSTATS 4 +#define KERN_MALLOC_MAXID 5 + +#define CTL_KERN_MALLOC_NAMES { \ + { 0, 0 }, \ + { "buckets", CTLTYPE_STRING }, \ + { "bucket", CTLTYPE_NODE }, \ + { "kmemnames", CTLTYPE_STRING }, \ + { "kmemstat", CTLTYPE_NODE }, \ +} + +/* + * flags to malloc + */ +#define M_WAITOK 0x0001 +#define M_NOWAIT 0x0002 +#define M_CANFAIL 0x0004 +#define M_ZERO 0x0008 + +/* + * Types of memory to be allocated + */ +#define M_FREE 0 /* should be on free list */ +/* 1 - free */ +#define M_DEVBUF 2 /* device driver memory */ +/* 3 - free */ +#define M_PCB 4 /* protocol control blocks */ +#define M_RTABLE 5 /* routing tables */ +#define M_PF 6 /* packet filter structures */ +/* 7 - free */ +/* 8 - free */ +#define M_IFADDR 9 /* interface addresses */ +#define M_IFGROUP 10 /* interface groups */ +#define M_SYSCTL 11 /* sysctl persistent buffers */ +#define M_COUNTERS 12 /* per-CPU counters via counters_alloc(9) */ +/* 13 - free */ +#define M_IOCTLOPS 14 /* ioctl data buffers */ +/* 15-18 - free */ +#define M_IOV 19 /* large IOVs */ +#define M_MOUNT 20 /* VFS mount structs */ +/* 21 - free */ +#define M_NFSREQ 22 /* NFS request headers */ +#define M_NFSMNT 23 /* NFS mount structures */ +#define M_LOG 24 /* messages in kernel log stash */ +#define M_VNODE 25 /* Dynamically allocated vnodes */ +/* 26 - free */ +#define M_DQUOT 27 /* UFS quota entries */ +#define M_UFSMNT 28 /* UFS mount structures */ +#define M_SHM 29 /* SVID compatible shared memory segments */ +#define M_VMMAP 30 /* VM map structures */ +#define M_SEM 31 /* SVID compatible semaphores */ +#define M_DIRHASH 32 /* UFS directory hash structures */ +#define M_ACPI 33 /* ACPI structures */ +#define M_VMPMAP 34 /* VM pmap data */ +/* 35-38 - free */ +#define M_FILEDESC 39 /* open file descriptor tables */ +#define M_SIGIO 40 /* sigio structures */ +#define M_PROC 41 /* proc structures */ +#define M_SUBPROC 42 /* proc sub-structures */ +/* 43-45 - free */ +#define M_MFSNODE 46 /* MFS vnode private part */ +/* 47-48 - free */ +#define M_NETADDR 49 /* export host address structures */ +#define M_NFSSVC 50 /* NFS server structures */ +/* 51 - free */ +#define M_NFSD 52 /* NFS server daemon structures */ +#define M_IPMOPTS 53 /* internet multicast options */ +#define M_IPMADDR 54 /* internet multicast addresses */ +#define M_IFMADDR 55 /* link-level multicast addresses */ +#define M_MRTABLE 56 /* multicast routing tables */ +#define M_ISOFSMNT 57 /* ISOFS mount structures */ +#define M_ISOFSNODE 58 /* ISOFS vnode private part */ +#define M_MSDOSFSMNT 59 /* MSDOS FS mount structures */ +#define M_MSDOSFSFAT 60 /* MSDOS FS FAT tables */ +#define M_MSDOSFSNODE 61 /* MSDOS FS vnode private part */ +#define M_TTYS 62 /* allocated tty structures */ +#define M_EXEC 63 /* argument lists & other mem used by exec */ +#define M_MISCFSMNT 64 /* miscellaneous FS mount structures */ +#define M_FUSEFS 65 /* FUSE FS mount structures */ +/* 66-73 - free */ +#define M_PFKEY 74 /* pfkey data */ +#define M_TDB 75 /* transforms database */ +#define M_XDATA 76 /* IPsec data */ +/* 77 - free */ +#define M_PAGEDEP 78 /* file page dependencies */ +#define M_INODEDEP 79 /* inode dependencies */ +#define M_NEWBLK 80 /* new block allocation */ +/* 81-82 - free */ +#define M_INDIRDEP 83 /* indirect block dependencies */ +/* 84-91 - free */ +#define M_VMSWAP 92 /* VM swap structures */ +/* 93-97 - free */ +#define M_UVMAMAP 98 /* UVM amap and related */ +#define M_UVMAOBJ 99 /* UVM aobj and related */ +#define M_PINSYSCALL 100 /* pinsyscall */ +#define M_USB 101 /* USB general */ +#define M_USBDEV 102 /* USB device driver */ +#define M_USBHC 103 /* USB host controller */ +#define M_WITNESS 104 /* witness(4) memory */ +#define M_MEMDESC 105 /* memory range */ +/* 106-107 - free */ +#define M_CRYPTO_DATA 108 /* crypto(9) data buffers */ +/* 109 - free */ +#define M_CREDENTIALS 110 /* ipsec(4) related credentials */ +/* 111-122 - free */ + +/* KAME IPv6 */ +#define M_IP6OPT 123 /* IPv6 options */ +#define M_IP6NDP 124 /* IPv6 Neighbor Discovery structures */ +/* 125-126 - free */ +#define M_TEMP 127 /* miscellaneous temporary data buffers */ + +#define M_NTFSMNT 128 /* NTFS mount structures */ +#define M_NTFSNTNODE 129 /* NTFS ntnode information */ +#define M_NTFSFNODE 130 /* NTFS fnode information */ +#define M_NTFSDIR 131 /* NTFS directory buffers */ +#define M_NTFSNTHASH 132 /* NTFS ntnode hash tables */ +#define M_NTFSNTVATTR 133 /* NTFS file attribute information */ +#define M_NTFSRDATA 134 /* NTFS resident data */ +#define M_NTFSDECOMP 135 /* NTFS decompression temporary storage */ +#define M_NTFSRUN 136 /* NTFS vrun storage */ + +#define M_KEVENT 137 /* kqueue(2) data structures */ + + /* 138 free */ +#define M_SYNCACHE 139 /* SYN cache hash array */ + +#define M_UDFMOUNT 140 /* UDF mount structures */ +#define M_UDFFENTRY 141 /* UDF file entries */ +#define M_UDFFID 142 /* UDF file IDs */ + + /* 143 free */ + +#define M_AGP 144 /* AGP memory */ + +#define M_DRM 145 /* Direct Rendering Manager */ + +#define M_LAST 146 /* Must be last type + 1 */ + +#define INITKMEMNAMES { \ + "free", /* 0 M_FREE */ \ + NULL, \ + "devbuf", /* 2 M_DEVBUF */ \ + NULL, \ + "pcb", /* 4 M_PCB */ \ + "rtable", /* 5 M_RTABLE */ \ + "pf", /* 6 M_PF */ \ + NULL, \ + NULL, \ + "ifaddr", /* 9 M_IFADDR */ \ + "ifgroup", /* 10 M_IFGROUP */ \ + "sysctl", /* 11 M_SYSCTL */ \ + "counters", /* 12 M_COUNTERS */ \ + NULL, \ + "ioctlops", /* 14 M_IOCTLOPS */ \ + NULL, \ + NULL, \ + NULL, \ + NULL, \ + "iov", /* 19 M_IOV */ \ + "mount", /* 20 M_MOUNT */ \ + NULL, \ + "NFS req", /* 22 M_NFSREQ */ \ + "NFS mount", /* 23 M_NFSMNT */ \ + "log", /* 24 M_LOG */ \ + "vnodes", /* 25 M_VNODE */ \ + NULL, \ + "UFS quota", /* 27 M_DQUOT */ \ + "UFS mount", /* 28 M_UFSMNT */ \ + "shm", /* 29 M_SHM */ \ + "VM map", /* 30 M_VMMAP */ \ + "sem", /* 31 M_SEM */ \ + "dirhash", /* 32 M_DIRHASH */ \ + "ACPI", /* 33 M_ACPI */ \ + "VM pmap", /* 34 M_VMPMAP */ \ + NULL, /* 35 */ \ + NULL, /* 36 */ \ + NULL, /* 37 */ \ + NULL, \ + "file desc", /* 39 M_FILEDESC */ \ + "sigio", /* 40 M_SIGIO */ \ + "proc", /* 41 M_PROC */ \ + "subproc", /* 42 M_SUBPROC */ \ + NULL, \ + NULL, \ + NULL, \ + "MFS node", /* 46 M_MFSNODE */ \ + NULL, \ + NULL, \ + "Export Host", /* 49 M_NETADDR */ \ + "NFS srvsock", /* 50 M_NFSSVC */ \ + NULL, \ + "NFS daemon", /* 52 M_NFSD */ \ + "ip_moptions", /* 53 M_IPMOPTS */ \ + "in_multi", /* 54 M_IPMADDR */ \ + "ether_multi", /* 55 M_IFMADDR */ \ + "mrt", /* 56 M_MRTABLE */ \ + "ISOFS mount", /* 57 M_ISOFSMNT */ \ + "ISOFS node", /* 58 M_ISOFSNODE */ \ + "MSDOSFS mount", /* 59 M_MSDOSFSMNT */ \ + "MSDOSFS fat", /* 60 M_MSDOSFSFAT */ \ + "MSDOSFS node", /* 61 M_MSDOSFSNODE */ \ + "ttys", /* 62 M_TTYS */ \ + "exec", /* 63 M_EXEC */ \ + "miscfs mount", /* 64 M_MISCFSMNT */ \ + "fusefs mount", /* 65 M_FUSEFS */ \ + NULL, \ + NULL, \ + NULL, \ + NULL, \ + NULL, \ + NULL, \ + NULL, \ + NULL, \ + "pfkey data", /* 74 M_PFKEY */ \ + "tdb", /* 75 M_TDB */ \ + "xform_data", /* 76 M_XDATA */ \ + NULL, \ + "pagedep", /* 78 M_PAGEDEP */ \ + "inodedep", /* 79 M_INODEDEP */ \ + "newblk", /* 80 M_NEWBLK */ \ + NULL, \ + NULL, \ + "indirdep", /* 83 M_INDIRDEP */ \ + NULL, NULL, NULL, NULL, \ + NULL, NULL, NULL, NULL, \ + "VM swap", /* 92 M_VMSWAP */ \ + NULL, NULL, NULL, NULL, NULL, \ + "UVM amap", /* 98 M_UVMAMAP */ \ + "UVM aobj", /* 99 M_UVMAOBJ */ \ + "pinsyscall", /* 100 M_PINSYSCALL */ \ + "USB", /* 101 M_USB */ \ + "USB device", /* 102 M_USBDEV */ \ + "USB HC", /* 103 M_USBHC */ \ + "witness", /* 104 M_WITNESS */ \ + "memdesc", /* 105 M_MEMDESC */ \ + NULL, /* 106 */ \ + NULL, \ + "crypto data", /* 108 M_CRYPTO_DATA */ \ + NULL, \ + "IPsec creds", /* 110 M_CREDENTIALS */ \ + NULL, NULL, NULL, NULL, \ + NULL, NULL, NULL, NULL, \ + NULL, NULL, NULL, NULL, \ + "ip6_options", /* 123 M_IP6OPT */ \ + "NDP", /* 124 M_IP6NDP */ \ + NULL, \ + NULL, \ + "temp", /* 127 M_TEMP */ \ + "NTFS mount", /* 128 M_NTFSMNT */ \ + "NTFS node", /* 129 M_NTFSNTNODE */ \ + "NTFS fnode", /* 130 M_NTFSFNODE */ \ + "NTFS dir", /* 131 M_NTFSDIR */ \ + "NTFS hash", /* 132 M_NTFSNTHASH */ \ + "NTFS attr", /* 133 M_NTFSNTVATTR */ \ + "NTFS data", /* 134 M_NTFSRDATA */ \ + "NTFS decomp", /* 135 M_NTFSDECOMP */ \ + "NTFS vrun", /* 136 M_NTFSRUN */ \ + "kqueue", /* 137 M_KEVENT */ \ + NULL, /* 138 free */ \ + "SYN cache", /* 139 M_SYNCACHE */ \ + "UDF mount", /* 140 M_UDFMOUNT */ \ + "UDF file entry", /* 141 M_UDFFENTRY */ \ + "UDF file id", /* 142 M_UDFFID */ \ + NULL, /* 143 free */ \ + "AGP Memory", /* 144 M_AGP */ \ + "DRM", /* 145 M_DRM */ \ +} + +struct kmemstats { + long ks_inuse; /* # of packets of this type currently in use */ + long ks_calls; /* total packets of this type ever allocated */ + long ks_memuse; /* total memory held in bytes */ + u_short ks_limblocks; /* number of times blocked for hitting limit */ + long ks_maxused; /* maximum number ever used */ + long ks_limit; /* most that are allowed to exist */ + long ks_size; /* sizes of this thing that are allocated */ + long ks_spare; +}; + +/* + * Array of descriptors that describe the contents of each page + */ +struct kmemusage { + short ku_indx; /* bucket index */ + union { + u_short freecnt;/* for small allocations, free pieces in page */ + u_short pagecnt;/* for large allocations, pages alloced */ + } ku_un; +}; +#define ku_freecnt ku_un.freecnt +#define ku_pagecnt ku_un.pagecnt + +struct kmem_freelist; + +/* + * Set of buckets for each size of memory block that is retained + */ +struct kmembuckets { + XSIMPLEQ_HEAD(, kmem_freelist) kb_freelist; /* list of free blocks */ + u_int64_t kb_calls; /* total calls to allocate this size */ + u_int64_t kb_total; /* total number of blocks allocated */ + u_int64_t kb_totalfree; /* # of free elements in this bucket */ + u_int64_t kb_elmpercl; /* # of elements in this sized allocation */ + u_int64_t kb_highwat; /* high water mark */ + u_int64_t kb_couldfree; /* over high water mark and could free */ +}; + +/* + * Constants for setting the parameters of the kernel memory allocator. + * + * 2 ** MINBUCKET is the smallest unit of memory that will be + * allocated. It must be at least large enough to hold a pointer. + * + * Units of memory less or equal to MAXALLOCSAVE will permanently + * allocate physical memory; requests for these size pieces of + * memory are quite fast. Allocations greater than MAXALLOCSAVE must + * always allocate and free physical memory; requests for these + * size allocations should be done infrequently as they will be slow. + * + * Constraints: PAGE_SIZE <= MAXALLOCSAVE <= 2 ** (MINBUCKET + 14), and + * MAXALLOCSIZE must be a power of two. + */ +#define MINBUCKET 4 /* 4 => min allocation of 16 bytes */ + +#ifdef _KERNEL + +#define MINALLOCSIZE (1 << MINBUCKET) +#define MAXALLOCSAVE (2 * PAGE_SIZE) +#define MALLOC_MAX (65535 * PAGE_SIZE) + +/* + * Turn virtual addresses into kmem map indices + */ +#define kmemxtob(alloc) (kmembase + (alloc) * PAGE_SIZE) +#define btokmemx(addr) (((caddr_t)(addr) - kmembase) / PAGE_SIZE) +#define btokup(addr) (&kmemusage[((caddr_t)(addr) - kmembase) >> PAGE_SHIFT]) + +extern struct kmemstats kmemstats[]; +extern struct kmemusage *kmemusage; +extern char *kmembase; +extern struct kmembuckets bucket[]; + +void *malloc(size_t, int, int); +void *mallocarray(size_t, size_t, int, int); +void free(void *, int, size_t); +int sysctl_malloc(int *, u_int, void *, size_t *, void *, size_t, + struct proc *); + +void malloc_printit(int (*)(const char *, ...)); + +void poison_mem(void *, size_t); +int poison_check(void *, size_t, size_t *, uint32_t *); +uint32_t poison_value(void *); + +#endif /* _KERNEL */ +#endif /* !_SYS_MALLOC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/mbuf.h b/lib/libc/include/generic-openbsd/sys/mbuf.h new file mode 100644 index 0000000000..5774ff06bb --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/mbuf.h @@ -0,0 +1,571 @@ +/* $OpenBSD: mbuf.h,v 1.267 2025/06/25 20:26:32 miod Exp $ */ +/* $NetBSD: mbuf.h,v 1.19 1996/02/09 18:25:14 christos Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1988, 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. + * + * @(#)mbuf.h 8.5 (Berkeley) 2/19/95 + */ + +#ifndef _SYS_MBUF_H_ +#define _SYS_MBUF_H_ + +#include + +/* + * Constants related to network buffer management. + * MCLBYTES must be no larger than PAGE_SIZE (the software page size) and, + * on machines that exchange pages of input or output buffers with mbuf + * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple + * of the hardware page size. + */ +#define MSIZE 256 /* size of an mbuf */ + +/* + * Mbufs are of a single size, MSIZE, which includes overhead. An mbuf may + * add a single "mbuf cluster" of size MCLBYTES, which has no additional + * overhead and is used instead of the internal data area; this is done when + * at least MINCLSIZE of data must be stored. + */ + +#define MLEN (MSIZE - sizeof(struct m_hdr)) /* normal data len */ +#define MHLEN (MLEN - sizeof(struct pkthdr)) /* data len w/pkthdr */ + +#define MAXMCLBYTES (64 * 1024) /* largest cluster from the stack */ +#define MINCLSIZE (MHLEN + MLEN + 1) /* smallest amount to put in cluster */ + +#define MCLSHIFT 11 /* convert bytes to m_buf clusters */ + /* 2K cluster can hold Ether frame */ +#define MCLBYTES (1 << MCLSHIFT) /* size of a m_buf cluster */ + +/* Packet tags structure */ +struct m_tag { + SLIST_ENTRY(m_tag) m_tag_link; /* List of packet tags */ + u_int16_t m_tag_id; /* Tag ID */ + u_int16_t m_tag_len; /* Length of data */ +}; + +/* + * Macros for type conversion + * mtod(m,t) - convert mbuf pointer to data pointer of correct type + */ +#define mtod(m,t) ((t)((m)->m_data)) + +/* header at beginning of each mbuf: */ +struct m_hdr { + struct mbuf *mh_next; /* next buffer in chain */ + struct mbuf *mh_nextpkt; /* next chain in queue/record */ + caddr_t mh_data; /* location of data */ + u_int mh_len; /* amount of data in this mbuf */ + short mh_type; /* type of data in this mbuf */ + u_short mh_flags; /* flags; see below */ +#ifndef __LP64__ + u_int mh_pad; /* pad to 8-byte boundary */ +#endif +}; + +/* pf stuff */ +struct pf_state_key; +struct inpcb; + +struct pkthdr_pf { + struct pf_state_key *statekey; /* pf stackside statekey */ + struct inpcb *inp; /* connected pcb for outgoing packet */ + u_int32_t qid; /* queue id */ + u_int16_t tag; /* tag id */ + u_int16_t delay; /* delay packet by X ms */ + u_int8_t flags; + u_int8_t routed; + u_int8_t prio; + u_int8_t pad[1]; +}; + +/* pkthdr_pf.flags */ +#define PF_TAG_GENERATED 0x01 +#define PF_TAG_SYNCOOKIE_RECREATED 0x02 +#define PF_TAG_TRANSLATE_LOCALHOST 0x04 +#define PF_TAG_DIVERTED 0x08 +#define PF_TAG_DIVERTED_PACKET 0x10 +#define PF_TAG_REROUTE 0x20 +#define PF_TAG_REFRAGMENTED 0x40 /* refragmented ipv6 packet */ +#define PF_TAG_PROCESSED 0x80 /* packet was checked by pf */ + +#ifdef _KERNEL +#define MPF_BITS \ + ("\20\1GENERATED\2SYNCOOKIE_RECREATED\3TRANSLATE_LOCALHOST\4DIVERTED" \ + "\5DIVERTED_PACKET\6REROUTE\7REFRAGMENTED\10PROCESSED") +#endif + +/* record/packet header in first mbuf of chain; valid if M_PKTHDR set */ +struct pkthdr { + void *ph_cookie; /* additional data */ + SLIST_HEAD(, m_tag) ph_tags; /* list of packet tags */ + int64_t ph_timestamp; /* packet timestamp */ + int len; /* total packet length */ + u_int ph_rtableid; /* routing table id */ + u_int ph_ifidx; /* rcv interface index */ + u_int16_t ph_tagsset; /* mtags attached */ + u_int16_t ph_flowid; /* pseudo unique flow id */ + u_int16_t csum_flags; /* checksum flags */ + u_int16_t ether_vtag; /* Ethernet 802.1p+Q vlan tag */ + u_int16_t ph_mss; /* TCP max segment size */ + u_int8_t ph_loopcnt; /* mbuf is looping in kernel */ + u_int8_t ph_family; /* af, used when queueing */ + struct pkthdr_pf pf; +}; + +/* description of external storage mapped into mbuf, valid if M_EXT set */ +struct mbuf_ext { + caddr_t ext_buf; /* start of buffer */ + void *ext_arg; + u_int ext_free_fn; /* index of free function */ + u_int ext_size; /* size of buffer, for ext_free_fn */ + struct mbuf *ext_nextref; + struct mbuf *ext_prevref; +#ifdef DEBUG + const char *ext_ofile; + const char *ext_nfile; + int ext_oline; + int ext_nline; +#endif +}; + +struct mbuf { + struct m_hdr m_hdr; + union { + struct { + struct pkthdr MH_pkthdr; /* M_PKTHDR set */ + union { + struct mbuf_ext MH_ext; /* M_EXT set */ + char MH_databuf[MHLEN]; + } MH_dat; + } MH; + char M_databuf[MLEN]; /* !M_PKTHDR, !M_EXT */ + } M_dat; +}; +#define m_next m_hdr.mh_next +#define m_len m_hdr.mh_len +#define m_data m_hdr.mh_data +#define m_type m_hdr.mh_type +#define m_flags m_hdr.mh_flags +#define m_nextpkt m_hdr.mh_nextpkt +#define m_pkthdr M_dat.MH.MH_pkthdr +#define m_ext M_dat.MH.MH_dat.MH_ext +#define m_pktdat M_dat.MH.MH_dat.MH_databuf +#define m_dat M_dat.M_databuf + +/* mbuf flags */ +#define M_EXT 0x0001 /* has associated external storage */ +#define M_PKTHDR 0x0002 /* start of record */ +#define M_EOR 0x0004 /* end of record */ +#define M_EXTWR 0x0008 /* external storage is writable */ +#define M_PROTO1 0x0010 /* protocol-specific */ + +/* mbuf pkthdr flags, also in m_flags */ +#define M_VLANTAG 0x0020 /* ether_vtag is valid */ +#define M_LOOP 0x0040 /* packet has been sent from local machine */ +#define M_BCAST 0x0100 /* sent/received as link-level broadcast */ +#define M_MCAST 0x0200 /* sent/received as link-level multicast */ +#define M_CONF 0x0400 /* payload was encrypted (ESP-transport) */ +#define M_AUTH 0x0800 /* payload was authenticated (AH or ESP auth) */ +#define M_TUNNEL 0x1000 /* IP-in-IP added by tunnel mode IPsec */ +#define M_ZEROIZE 0x2000 /* Zeroize data part on free */ +#define M_COMP 0x4000 /* header was decompressed */ +#define M_LINK0 0x8000 /* link layer specific flag */ + +#ifdef _KERNEL +#define M_BITS \ + ("\20\1M_EXT\2M_PKTHDR\3M_EOR\4M_EXTWR\5M_PROTO1\6M_VLANTAG\7M_LOOP" \ + "\11M_BCAST\12M_MCAST\13M_CONF\14M_AUTH\15M_TUNNEL" \ + "\16M_ZEROIZE\17M_COMP\20M_LINK0") +#endif + +/* flags copied when copying m_pkthdr */ +#define M_COPYFLAGS (M_PKTHDR|M_EOR|M_PROTO1|M_BCAST|M_MCAST|M_CONF|M_COMP|\ + M_AUTH|M_LOOP|M_TUNNEL|M_LINK0|M_VLANTAG|M_ZEROIZE) + +/* Checksumming flags */ +#define M_IPV4_CSUM_OUT 0x0001 /* IPv4 checksum needed */ +#define M_TCP_CSUM_OUT 0x0002 /* TCP checksum needed */ +#define M_UDP_CSUM_OUT 0x0004 /* UDP checksum needed */ +#define M_IPV4_CSUM_IN_OK 0x0008 /* IPv4 checksum verified */ +#define M_IPV4_CSUM_IN_BAD 0x0010 /* IPv4 checksum bad */ +#define M_TCP_CSUM_IN_OK 0x0020 /* TCP checksum verified */ +#define M_TCP_CSUM_IN_BAD 0x0040 /* TCP checksum bad */ +#define M_UDP_CSUM_IN_OK 0x0080 /* UDP checksum verified */ +#define M_UDP_CSUM_IN_BAD 0x0100 /* UDP checksum bad */ +#define M_ICMP_CSUM_OUT 0x0200 /* ICMP/ICMPv6 checksum needed */ +#define M_ICMP_CSUM_IN_OK 0x0400 /* ICMP/ICMPv6 checksum verified */ +#define M_ICMP_CSUM_IN_BAD 0x0800 /* ICMP/ICMPv6 checksum bad */ +#define M_IPV6_DF_OUT 0x1000 /* don't fragment outgoing IPv6 */ +#define M_TIMESTAMP 0x2000 /* ph_timestamp is set */ +#define M_FLOWID 0x4000 /* ph_flowid is set */ +#define M_TCP_TSO 0x8000 /* TCP Segmentation Offload needed */ + +#ifdef _KERNEL +#define MCS_BITS \ + ("\20\1IPV4_CSUM_OUT\2TCP_CSUM_OUT\3UDP_CSUM_OUT\4IPV4_CSUM_IN_OK" \ + "\5IPV4_CSUM_IN_BAD\6TCP_CSUM_IN_OK\7TCP_CSUM_IN_BAD\10UDP_CSUM_IN_OK" \ + "\11UDP_CSUM_IN_BAD\12ICMP_CSUM_OUT\13ICMP_CSUM_IN_OK\14ICMP_CSUM_IN_BAD" \ + "\15IPV6_NODF_OUT" "\16TIMESTAMP" "\17FLOWID" "\20TCP_TSO") +#endif + +/* mbuf types */ +#define MT_FREE 0 /* should be on free list */ +#define MT_DATA 1 /* dynamic (data) allocation */ +#define MT_HEADER 2 /* packet header */ +#define MT_SONAME 3 /* socket name */ +#define MT_SOOPTS 4 /* socket options */ +#define MT_FTABLE 5 /* fragment reassembly header */ +#define MT_CONTROL 6 /* extra-data protocol message */ +#define MT_OOBDATA 7 /* expedited data */ +#define MT_NTYPES 8 + +/* flags to m_get/MGET */ +#include +#define M_DONTWAIT M_NOWAIT +#define M_WAIT M_WAITOK + +/* + * mbuf allocation/deallocation macros: + * + * MGET(struct mbuf *m, int how, int type) + * allocates an mbuf and initializes it to contain internal data. + * + * MGETHDR(struct mbuf *m, int how, int type) + * allocates an mbuf and initializes it to contain a packet header + * and internal data. + */ +#define MGET(m, how, type) m = m_get((how), (type)) + +#define MGETHDR(m, how, type) m = m_gethdr((how), (type)) + +/* + * Macros for tracking external storage associated with an mbuf. + */ +#ifdef DEBUG +#define MCLREFDEBUGN(m, file, line) do { \ + (m)->m_ext.ext_nfile = (file); \ + (m)->m_ext.ext_nline = (line); \ + } while (/* CONSTCOND */ 0) +#define MCLREFDEBUGO(m, file, line) do { \ + (m)->m_ext.ext_ofile = (file); \ + (m)->m_ext.ext_oline = (line); \ + } while (/* CONSTCOND */ 0) +#else +#define MCLREFDEBUGN(m, file, line) +#define MCLREFDEBUGO(m, file, line) +#endif + +#define MCLISREFERENCED(m) ((m)->m_ext.ext_nextref != (m)) + +#define MCLADDREFERENCE(o, n) m_extref((o), (n)) + +#define MCLINITREFERENCE(m) do { \ + (m)->m_ext.ext_prevref = (m); \ + (m)->m_ext.ext_nextref = (m); \ + MCLREFDEBUGO((m), __FILE__, __LINE__); \ + MCLREFDEBUGN((m), NULL, 0); \ + } while (/* CONSTCOND */ 0) + +/* + * Macros for mbuf external storage. + * + * MEXTADD adds pre-allocated external storage to + * a normal mbuf; the flag M_EXT is set. + * + * MCLGET allocates and adds an mbuf cluster to a normal mbuf; + * the flag M_EXT is set upon success. + */ +#define MEXTADD(m, buf, size, mflags, freefn, arg) do { \ + (m)->m_data = (m)->m_ext.ext_buf = (caddr_t)(buf); \ + (m)->m_flags |= M_EXT | (mflags & M_EXTWR); \ + (m)->m_ext.ext_size = (size); \ + (m)->m_ext.ext_free_fn = (freefn); \ + (m)->m_ext.ext_arg = (arg); \ + MCLINITREFERENCE(m); \ +} while (/* CONSTCOND */ 0) + +#define MCLGET(m, how) (void) m_clget((m), (how), MCLBYTES) +#define MCLGETL(m, how, l) m_clget((m), (how), (l)) + +u_int mextfree_register(void (*)(caddr_t, u_int, void *)); +#define MEXTFREE_POOL 0 + +/* + * Move just m_pkthdr from from to to, + * remove M_PKTHDR and clean flags/tags for from. + */ +#define M_MOVE_HDR(to, from) do { \ + (to)->m_pkthdr = (from)->m_pkthdr; \ + (from)->m_flags &= ~M_PKTHDR; \ + SLIST_INIT(&(from)->m_pkthdr.ph_tags); \ + (from)->m_pkthdr.pf.statekey = NULL; \ +} while (/* CONSTCOND */ 0) + +/* + * MOVE mbuf pkthdr from from to to. + * from must have M_PKTHDR set, and to must be empty. + */ +#define M_MOVE_PKTHDR(to, from) do { \ + (to)->m_flags = ((to)->m_flags & (M_EXT | M_EXTWR)); \ + (to)->m_flags |= (from)->m_flags & M_COPYFLAGS; \ + M_MOVE_HDR((to), (from)); \ + if (((to)->m_flags & M_EXT) == 0) \ + (to)->m_data = (to)->m_pktdat; \ +} while (/* CONSTCOND */ 0) + +/* + * Determine if an mbuf's data area is read-only. This is true for + * non-cluster external storage and for clusters that are being + * referenced by more than one mbuf. + */ +#define M_READONLY(m) \ + (((m)->m_flags & M_EXT) != 0 && \ + (((m)->m_flags & M_EXTWR) == 0 || MCLISREFERENCED(m))) + +/* + * Arrange to prepend space of size plen to mbuf m. + * If a new mbuf must be allocated, how specifies whether to wait. + * If how is M_DONTWAIT and allocation fails, the original mbuf chain + * is freed and m is set to NULL. + */ +#define M_PREPEND(m, plen, how) \ + (m) = m_prepend((m), (plen), (how)) + +/* length to m_copy to copy all */ +#define M_COPYALL 1000000000 + +enum mbstat_counters { + mbs_drops = MT_NTYPES, + mbs_wait, + mbs_drain, + mbs_defrag_alloc, + mbs_prepend_alloc, + mbs_pullup_alloc, + mbs_pullup_copy, + mbs_pulldown_alloc, + mbs_pulldown_copy, + mbs_ncounters +}; + +/* + * Mbuf statistics. + * For statistics related to mbuf and cluster allocations, see also the + * pool headers (mbpool and mclpool). + */ +struct mbstat { + u_long m_drops; /* times failed to find space */ + u_long m_wait; /* times waited for space */ + u_long m_drain; /* times drained protocols for space */ + u_long m_mtypes[MT_NTYPES]; /* type specific mbuf allocations */ + u_long m_defrag_alloc; + u_long m_prepend_alloc; + u_long m_pullup_alloc; + u_long m_pullup_copy; + u_long m_pulldown_alloc; + u_long m_pulldown_copy; +}; + +#include + +struct mbuf_list { + struct mbuf *ml_head; + struct mbuf *ml_tail; + u_int ml_len; +}; + +struct mbuf_queue { + struct mutex mq_mtx; + struct mbuf_list mq_list; + u_int mq_maxlen; + u_int mq_drops; +}; + +#ifdef _KERNEL +struct pool; + +extern long nmbclust; /* limit on the # of clusters */ +extern int max_linkhdr; /* largest link-level header */ +extern int max_protohdr; /* largest protocol header */ +extern int max_hdr; /* largest link+protocol header */ +extern struct cpumem *mbstat; /* mbuf statistics counter */ + +void mbinit(void); +void mbcpuinit(void); +int nmbclust_update(long); +struct mbuf *m_copym(struct mbuf *, int, int, int); +struct mbuf *m_free(struct mbuf *); +struct mbuf *m_get(int, int); +struct mbuf *m_getclr(int, int); +struct mbuf *m_gethdr(int, int); +struct mbuf *m_inithdr(struct mbuf *); +void m_removehdr(struct mbuf *); +void m_resethdr(struct mbuf *); +void m_calchdrlen(struct mbuf *); +int m_defrag(struct mbuf *, int); +struct mbuf *m_prepend(struct mbuf *, int, int); +struct mbuf *m_pulldown(struct mbuf *, int, int, int *); +struct mbuf *m_pullup(struct mbuf *, int); +struct mbuf *m_split(struct mbuf *, int, int); +struct mbuf *m_makespace(struct mbuf *, int, int, int *); +struct mbuf *m_getptr(struct mbuf *, int, int *); +int m_leadingspace(struct mbuf *); +int m_trailingspace(struct mbuf *); +void m_align(struct mbuf *, int); +struct mbuf *m_clget(struct mbuf *, int, u_int); +void m_extref(struct mbuf *, struct mbuf *); +void m_pool_init(struct pool *, u_int, u_int, const char *); +u_int m_pool_used(void); +void m_extfree_pool(caddr_t, u_int, void *); +void m_adj(struct mbuf *, int); +int m_copyback(struct mbuf *, int, int, const void *, int); +struct mbuf *m_freem(struct mbuf *); +void m_purge(struct mbuf *); +void m_copydata(struct mbuf *, int, int, void *); +void m_cat(struct mbuf *, struct mbuf *); +struct mbuf *m_devget(char *, int, int); +int m_apply(struct mbuf *, int, int, + int (*)(caddr_t, caddr_t, unsigned int), caddr_t); +struct mbuf *m_dup_pkt(struct mbuf *, unsigned int, int); +int m_dup_pkthdr(struct mbuf *, struct mbuf *, int); + +void m_microtime(const struct mbuf *, struct timeval *); + +static inline struct mbuf * +m_freemp(struct mbuf **mp) +{ + struct mbuf *m = *mp; + + *mp = NULL; + return m_freem(m); +} + +#include + +static inline void +mbstat_inc(enum mbstat_counters c) +{ + int s = splnet(); + counters_inc(mbstat, c); + splx(s); +} + +/* Packet tag routines */ +struct m_tag *m_tag_get(int, int, int); +void m_tag_prepend(struct mbuf *, struct m_tag *); +void m_tag_delete(struct mbuf *, struct m_tag *); +void m_tag_delete_chain(struct mbuf *); +struct m_tag *m_tag_find(struct mbuf *, int, struct m_tag *); +struct m_tag *m_tag_copy(struct m_tag *, int); +int m_tag_copy_chain(struct mbuf *, struct mbuf *, int); +struct m_tag *m_tag_first(struct mbuf *); +struct m_tag *m_tag_next(struct mbuf *, struct m_tag *); + +/* Packet tag types */ +#define PACKET_TAG_IPSEC_IN_DONE 0x0001 /* IPsec applied, in */ +#define PACKET_TAG_IPSEC_OUT_DONE 0x0002 /* IPsec applied, out */ +#define PACKET_TAG_IPSEC_FLOWINFO 0x0004 /* IPsec flowinfo */ +#define PACKET_TAG_IP_OFFNXT 0x0010 /* IPv4 offset and next proto */ +#define PACKET_TAG_IP6_OFFNXT 0x0020 /* IPv6 offset and next proto */ +#define PACKET_TAG_WIREGUARD 0x0040 /* WireGuard data */ +#define PACKET_TAG_GRE 0x0080 /* GRE processing done */ +#define PACKET_TAG_DLT 0x0100 /* data link layer type */ +#define PACKET_TAG_PF_DIVERT 0x0200 /* pf(4) diverted packet */ +#define PACKET_TAG_PF_REASSEMBLED 0x0800 /* pf reassembled ipv6 packet */ +#define PACKET_TAG_SRCROUTE 0x1000 /* IPv4 source routing options */ +#define PACKET_TAG_TUNNEL 0x2000 /* Tunnel endpoint address */ +#define PACKET_TAG_CARP_BAL_IP 0x4000 /* carp(4) ip balanced marker */ + +#define MTAG_BITS \ + ("\20\1IPSEC_IN_DONE\2IPSEC_OUT_DONE\3IPSEC_FLOWINFO" \ + "\4IPSEC_OUT_CRYPTO_NEEDED\5IPSEC_PENDING_TDB\6BRIDGE\7WG\10GRE\11DLT" \ + "\12PF_DIVERT\14PF_REASSEMBLED\15SRCROUTE\16TUNNEL\17CARP_BAL_IP") + +/* + * Maximum tag payload length (that is excluding the m_tag structure). + * Please make sure to update this value when increasing the payload + * length for an existing packet tag type or when adding a new one that + * has payload larger than the value below. + */ +#define PACKET_TAG_MAXSIZE 80 + +/* Detect mbufs looping in the kernel when spliced too often. */ +#define M_MAXLOOP 128 + +/* + * mbuf lists + */ + +#define MBUF_LIST_INITIALIZER() { NULL, NULL, 0 } + +void ml_init(struct mbuf_list *); +void ml_enqueue(struct mbuf_list *, struct mbuf *); +struct mbuf * ml_dequeue(struct mbuf_list *); +void ml_enlist(struct mbuf_list *, struct mbuf_list *); +struct mbuf * ml_dechain(struct mbuf_list *); +unsigned int ml_purge(struct mbuf_list *); +unsigned int ml_hdatalen(struct mbuf_list *); + +#define ml_len(_ml) ((_ml)->ml_len) +#define ml_empty(_ml) ((_ml)->ml_len == 0) + +#define MBUF_LIST_FIRST(_ml) ((_ml)->ml_head) +#define MBUF_LIST_NEXT(_m) ((_m)->m_nextpkt) + +#define MBUF_LIST_FOREACH(_ml, _m) \ + for ((_m) = MBUF_LIST_FIRST(_ml); \ + (_m) != NULL; \ + (_m) = MBUF_LIST_NEXT(_m)) + +/* + * mbuf queues + */ + +#include + +#define MBUF_QUEUE_INITIALIZER(_maxlen, _ipl) \ + { MUTEX_INITIALIZER(_ipl), MBUF_LIST_INITIALIZER(), (_maxlen), 0 } + +void mq_init(struct mbuf_queue *, u_int, int); +int mq_push(struct mbuf_queue *, struct mbuf *); +int mq_enqueue(struct mbuf_queue *, struct mbuf *); +struct mbuf * mq_dequeue(struct mbuf_queue *); +int mq_enlist(struct mbuf_queue *, struct mbuf_list *); +void mq_delist(struct mbuf_queue *, struct mbuf_list *); +unsigned int mq_purge(struct mbuf_queue *); +unsigned int mq_hdatalen(struct mbuf_queue *); +void mq_set_maxlen(struct mbuf_queue *, u_int); + +#define mq_len(_mq) READ_ONCE((_mq)->mq_list.ml_len) +#define mq_empty(_mq) (mq_len(_mq) == 0) +#define mq_full(_mq) (mq_len((_mq)) >= READ_ONCE((_mq)->mq_maxlen)) +#define mq_drops(_mq) READ_ONCE((_mq)->mq_drops) + +#endif /* _KERNEL */ +#endif /* _SYS_MBUF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/memrange.h b/lib/libc/include/generic-openbsd/sys/memrange.h new file mode 100644 index 0000000000..da26d09018 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/memrange.h @@ -0,0 +1,96 @@ +/* $OpenBSD: memrange.h,v 1.10 2015/08/18 20:19:32 miod Exp $ */ +/*- + * Copyright (c) 1999 Michael Smith + * 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 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 AUTHOR 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. + */ +/* + * Memory range attribute operations, performed on /dev/mem + */ + +/* Memory range attributes */ +#define MDF_UNCACHEABLE (1<<0) /* region not cached */ +#define MDF_WRITECOMBINE (1<<1) /* region supports "write combine" action */ +#define MDF_WRITETHROUGH (1<<2) /* write-through cached */ +#define MDF_WRITEBACK (1<<3) /* write-back cached */ +#define MDF_WRITEPROTECT (1<<4) /* read-only region */ +#define MDF_UNKNOWN (1<<5) /* any state we don't understand */ +#define MDF_ATTRMASK (0x00ffffff) + +#define MDF_FIXBASE (1<<24) /* fixed base */ +#define MDF_FIXLEN (1<<25) /* fixed length */ +#define MDF_FIRMWARE (1<<26) /* set by firmware (XXX not useful?) */ +#define MDF_ACTIVE (1<<27) /* currently active */ +#define MDF_BOGUS (1<<28) /* we don't like it */ +#define MDF_FIXACTIVE (1<<29) /* can't be turned off */ +#define MDF_FORCE (1<<31) /* force risky changes */ + +struct mem_range_desc { + u_int64_t mr_base; + u_int64_t mr_len; + int mr_flags; + char mr_owner[8]; +}; + +struct mem_range_op { + struct mem_range_desc *mo_desc; + int mo_arg[2]; +#define MEMRANGE_SET_UPDATE 0 +#define MEMRANGE_SET_REMOVE 1 + /* XXX want a flag that says "set and undo when I exit" */ +}; + +#define MEMRANGE_GET _IOWR('m', 50, struct mem_range_op) +#define MEMRANGE_SET _IOW('m', 51, struct mem_range_op) + +/* Offset indicating a write combining mapping is requested. */ +#define MEMRANGE_WC_RANGE 0x4000000000000000ULL + +#ifdef _KERNEL + +struct mem_range_softc; +struct mem_range_ops { + void (*init)(struct mem_range_softc *sc); + int (*set)(struct mem_range_softc *sc, + struct mem_range_desc *mrd, int *arg); + void (*initAP)(struct mem_range_softc *sc); + void (*reload)(struct mem_range_softc *sc); +}; + +struct mem_range_softc { + struct mem_range_ops *mr_op; + int mr_cap; + int mr_ndesc; + struct mem_range_desc *mr_desc; +}; + +extern struct mem_range_softc mem_range_softc; + +__BEGIN_DECLS +extern void mem_range_attach(void); +extern int mem_range_attr_get(struct mem_range_desc *mrd, int *arg); +extern int mem_range_attr_set(struct mem_range_desc *mrd, int *arg); +extern void mem_range_AP_init(void); +extern void mem_range_reload(void); +__END_DECLS +#endif /* _KERNEL */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/mman.h b/lib/libc/include/generic-openbsd/sys/mman.h new file mode 100644 index 0000000000..e6a2f2b3b6 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/mman.h @@ -0,0 +1,166 @@ +/* $OpenBSD: mman.h,v 1.35 2022/10/07 14:59:39 deraadt Exp $ */ +/* $NetBSD: mman.h,v 1.11 1995/03/26 20:24:23 jtc Exp $ */ + +/*- + * Copyright (c) 1982, 1986, 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. + * + * @(#)mman.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _KERNEL +#include +#endif + +/* + * Protections are chosen from these bits, or-ed together + */ +#define PROT_NONE 0x00 /* no permissions */ +#define PROT_READ 0x01 /* pages can be read */ +#define PROT_WRITE 0x02 /* pages can be written */ +#define PROT_EXEC 0x04 /* pages can be executed */ + +/* + * Flags contain sharing type and options. + * Sharing types; choose one. + */ +#define MAP_SHARED 0x0001 /* share changes */ +#define MAP_PRIVATE 0x0002 /* changes are private */ + +/* + * Other flags + */ +#define MAP_FIXED 0x0010 /* map addr must be exactly as requested */ +#define __MAP_NOREPLACE 0x0800 /* fail if address not available */ +#define MAP_ANON 0x1000 /* allocated from memory, swap space */ +#define MAP_ANONYMOUS MAP_ANON /* alternate POSIX spelling */ +#define __MAP_NOFAULT 0x2000 +#define MAP_STACK 0x4000 /* mapping is used for a stack */ +#define MAP_CONCEAL 0x8000 /* omit from dumps */ + +#define MAP_FLAGMASK 0xfff7 + +#ifndef _KERNEL +/* + * Legacy defines for userland source compatibility. + * Can be removed once no longer needed in base and ports. + */ +#define MAP_COPY MAP_PRIVATE /* "copy" region at mmap time */ +#define MAP_FILE 0 /* map from file (default) */ +#define MAP_HASSEMAPHORE 0 /* region may contain semaphores */ +#define MAP_INHERIT 0 /* region is retained after exec */ +#define MAP_NOEXTEND 0 /* for MAP_FILE, don't change file size */ +#define MAP_NORESERVE 0 /* Sun: don't reserve needed swap area */ +#define MAP_RENAME 0 /* Sun: rename private pages to file */ +#define MAP_TRYFIXED 0 /* attempt hint address, even within heap */ +#endif + +/* + * Error return from mmap() + */ +#define MAP_FAILED ((void *)-1) + +/* + * POSIX memory advisory values. + * Note: keep consistent with the original definitions below. + */ +#define POSIX_MADV_NORMAL 0 /* no further special treatment */ +#define POSIX_MADV_RANDOM 1 /* expect random page references */ +#define POSIX_MADV_SEQUENTIAL 2 /* expect sequential page references */ +#define POSIX_MADV_WILLNEED 3 /* will need these pages */ +#define POSIX_MADV_DONTNEED 4 /* don't need these pages */ + +#if __BSD_VISIBLE +/* + * Original advice values, equivalent to POSIX definitions, + * and few implementation-specific ones. For in-kernel and historic use. + */ +#define MADV_NORMAL POSIX_MADV_NORMAL +#define MADV_RANDOM POSIX_MADV_RANDOM +#define MADV_SEQUENTIAL POSIX_MADV_SEQUENTIAL +#define MADV_WILLNEED POSIX_MADV_WILLNEED +#define MADV_DONTNEED POSIX_MADV_DONTNEED +#define MADV_SPACEAVAIL 5 /* insure that resources are reserved */ +#define MADV_FREE 6 /* pages are empty, free them */ +#endif + +/* + * Flags to minherit + */ +#define MAP_INHERIT_SHARE 0 /* share with child */ +#define MAP_INHERIT_COPY 1 /* copy into child */ +#define MAP_INHERIT_NONE 2 /* absent from child */ +#define MAP_INHERIT_ZERO 3 /* zero in child */ + +/* + * Flags to msync + */ +#define MS_ASYNC 0x01 /* perform asynchronous writes */ +#define MS_SYNC 0x02 /* perform synchronous writes */ +#define MS_INVALIDATE 0x04 /* invalidate cached data */ + +/* + * Flags to mlockall + */ +#define MCL_CURRENT 0x01 /* lock all pages currently mapped */ +#define MCL_FUTURE 0x02 /* lock all pages mapped in the future */ + +#ifndef _KERNEL +#include + +#ifndef _SIZE_T_DEFINED_ +#define _SIZE_T_DEFINED_ +typedef __size_t size_t; +#endif + +#ifndef _OFF_T_DEFINED_ +#define _OFF_T_DEFINED_ +typedef __off_t off_t; +#endif + +__BEGIN_DECLS +void * mmap(void *, size_t, int, int, int, off_t); +int mprotect(void *, size_t, int); +int munmap(void *, size_t); +int msync(void *, size_t, int); +int mlock(const void *, size_t); +int munlock(const void *, size_t); +int mlockall(int); +int munlockall(void); +#if __BSD_VISIBLE +int madvise(void *, size_t, int); +int minherit(void *, size_t, int); +int mimmutable(void *, size_t); +void * mquery(void *, size_t, int, int, int, off_t); +#endif +int posix_madvise(void *, size_t, int); +int shm_open(const char *, int, __mode_t); +int shm_unlink(const char *); +int shm_mkstemp(char *); +__END_DECLS + +#endif /* !_KERNEL */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/mount.h b/lib/libc/include/generic-openbsd/sys/mount.h new file mode 100644 index 0000000000..f863cb68ff --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/mount.h @@ -0,0 +1,639 @@ +/* $OpenBSD: mount.h,v 1.153 2025/01/02 01:19:22 dlg Exp $ */ +/* $NetBSD: mount.h,v 1.48 1996/02/18 11:55:47 fvdl Exp $ */ + +/* + * Copyright (c) 1989, 1991, 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. + * + * @(#)mount.h 8.15 (Berkeley) 7/14/94 + */ + +#ifndef _SYS_MOUNT_H_ +#define _SYS_MOUNT_H_ + +#include +#ifndef _KERNEL +#include +#endif +#include +#include + +typedef struct { int32_t val[2]; } fsid_t; /* file system id type */ + +/* + * File identifier. + * These are unique per filesystem on a single machine. + */ +#define MAXFIDSZ 16 + +struct fid { + u_short fid_len; /* length of data in bytes */ + u_short fid_reserved; /* force longword alignment */ + char fid_data[MAXFIDSZ]; /* data (variable length) */ +}; + +/* + * Export arguments for local filesystem mount calls. + */ +struct export_args { + int ex_flags; /* export related flags */ + uid_t ex_root; /* mapping for root uid */ + struct xucred ex_anon; /* mapping for anonymous user */ + struct sockaddr *ex_addr; /* net address to which exported */ + int ex_addrlen; /* and the net address length */ + struct sockaddr *ex_mask; /* mask of valid bits in saddr */ + int ex_masklen; /* and the smask length */ +}; + +/* + * Arguments to mount UFS-based filesystems + */ +struct ufs_args { + char *fspec; /* block special device to mount */ + struct export_args export_info;/* network export information */ +}; + +/* + * Arguments to mount MFS + */ +struct mfs_args { + char *fspec; /* name to export for statfs */ + struct export_args export_info;/* if exported MFSes are supported */ + caddr_t base; /* base of file system in memory */ + u_long size; /* size of file system */ +}; + +/* + * Arguments to mount ISO 9660 filesystems. + */ +struct iso_args { + char *fspec; /* block special device to mount */ + struct export_args export_info;/* network export info */ + int flags; /* mounting flags, see below */ + int sess; /* start sector of session */ +}; + +#define ISOFSMNT_NORRIP 0x00000001 /* disable Rock Ridge Ext.*/ +#define ISOFSMNT_GENS 0x00000002 /* enable generation numbers */ +#define ISOFSMNT_EXTATT 0x00000004 /* enable extended attr. */ +#define ISOFSMNT_NOJOLIET 0x00000008 /* disable Joliet Ext.*/ +#define ISOFSMNT_SESS 0x00000010 /* use iso_args.sess */ + +/* + * Arguments to mount NFS + */ +#define NFS_ARGSVERSION 4 /* change when nfs_args changes */ +struct nfs_args { + int version; /* args structure version number */ + struct sockaddr *addr; /* file server address */ + int addrlen; /* length of address */ + int sotype; /* Socket type */ + int proto; /* and Protocol */ + u_char *fh; /* File handle to be mounted */ + int fhsize; /* Size, in bytes, of fh */ + int flags; /* flags */ + int wsize; /* write size in bytes */ + int rsize; /* read size in bytes */ + int readdirsize; /* readdir size in bytes */ + int timeo; /* initial timeout in .1 secs */ + int retrans; /* times to retry send */ + int maxgrouplist; /* Max. size of group list */ + int readahead; /* # of blocks to readahead */ + int leaseterm; /* Term (sec) of lease */ + int deadthresh; /* Retrans threshold */ + char *hostname; /* server's name */ + int acregmin; /* Attr cache file recently modified */ + int acregmax; /* ac file not recently modified */ + int acdirmin; /* ac for dir recently modified */ + int acdirmax; /* ac for dir not recently modified */ +}; + +/* + * NFS mount option flags + */ +#define NFSMNT_RESVPORT 0x00000000 /* always use reserved ports */ +#define NFSMNT_SOFT 0x00000001 /* soft mount (hard is default) */ +#define NFSMNT_WSIZE 0x00000002 /* set write size */ +#define NFSMNT_RSIZE 0x00000004 /* set read size */ +#define NFSMNT_TIMEO 0x00000008 /* set initial timeout */ +#define NFSMNT_RETRANS 0x00000010 /* set number of request retries */ +#define NFSMNT_MAXGRPS 0x00000020 /* set maximum grouplist size */ +#define NFSMNT_INT 0x00000040 /* allow interrupts on hard mount */ +#define NFSMNT_NOCONN 0x00000080 /* Don't Connect the socket */ +#define NFSMNT_NQNFS 0x00000100 /* Use Nqnfs protocol */ +#define NFSMNT_NFSV3 0x00000200 /* Use NFS Version 3 protocol */ +#define NFSMNT_KERB 0x00000400 /* Use Kerberos authentication */ +#define NFSMNT_DUMBTIMR 0x00000800 /* Don't estimate rtt dynamically */ +#define NFSMNT_LEASETERM 0x00001000 /* set lease term (nqnfs) */ +#define NFSMNT_READAHEAD 0x00002000 /* set read ahead */ +#define NFSMNT_DEADTHRESH 0x00004000 /* set dead server retry thresh */ +#define NFSMNT_NOAC 0x00008000 /* disable attribute cache */ +#define NFSMNT_RDIRPLUS 0x00010000 /* Use Readdirplus for V3 */ +#define NFSMNT_READDIRSIZE 0x00020000 /* Set readdir size */ + +/* Flags valid only in mount syscall arguments */ +#define NFSMNT_ACREGMIN 0x00040000 /* acregmin field valid */ +#define NFSMNT_ACREGMAX 0x00080000 /* acregmax field valid */ +#define NFSMNT_ACDIRMIN 0x00100000 /* acdirmin field valid */ +#define NFSMNT_ACDIRMAX 0x00200000 /* acdirmax field valid */ + +/* Flags valid only in kernel */ +#define NFSMNT_INTERNAL 0xfffc0000 /* Bits set internally */ +#define NFSMNT_HASWRITEVERF 0x00040000 /* Has write verifier for V3 */ +#define NFSMNT_GOTPATHCONF 0x00080000 /* Got the V3 pathconf info */ +#define NFSMNT_GOTFSINFO 0x00100000 /* Got the V3 fsinfo */ +#define NFSMNT_MNTD 0x00200000 /* Mnt server for mnt point */ +#define NFSMNT_DISMINPROG 0x00400000 /* Dismount in progress */ +#define NFSMNT_DISMNT 0x00800000 /* Dismounted */ +#define NFSMNT_SNDLOCK 0x01000000 /* Send socket lock */ +#define NFSMNT_WANTSND 0x02000000 /* Want above */ +#define NFSMNT_RCVLOCK 0x04000000 /* Rcv socket lock */ +#define NFSMNT_WANTRCV 0x08000000 /* Want above */ +#define NFSMNT_WAITAUTH 0x10000000 /* Wait for authentication */ +#define NFSMNT_HASAUTH 0x20000000 /* Has authenticator */ +#define NFSMNT_WANTAUTH 0x40000000 /* Wants an authenticator */ +#define NFSMNT_AUTHERR 0x80000000 /* Authentication error */ + +/* + * Arguments to mount MSDOS filesystems. + */ +struct msdosfs_args { + char *fspec; /* blocks special holding the fs to mount */ + struct export_args export_info; + /* network export information */ + uid_t uid; /* uid that owns msdosfs files */ + gid_t gid; /* gid that owns msdosfs files */ + mode_t mask; /* mask to be applied for msdosfs perms */ + int flags; /* see below */ +}; + +/* + * Msdosfs mount options: + */ +#define MSDOSFSMNT_SHORTNAME 0x01 /* Force old DOS short names only */ +#define MSDOSFSMNT_LONGNAME 0x02 /* Force Win'95 long names */ +#define MSDOSFSMNT_NOWIN95 0x04 /* Completely ignore Win95 entries */ + +/* + * Arguments to mount ntfs filesystems + */ +struct ntfs_args { + char *fspec; /* block special device to mount */ + struct export_args export_info;/* network export information */ + uid_t uid; /* uid that owns ntfs files */ + gid_t gid; /* gid that owns ntfs files */ + mode_t mode; /* mask to be applied for ntfs perms */ + u_long flag; /* additional flags */ +}; + +/* + * ntfs mount options: + */ +#define NTFS_MFLAG_CASEINS 0x00000001 +#define NTFS_MFLAG_ALLNAMES 0x00000002 + +/* Arguments to mount UDF file systems */ +struct udf_args { + char *fspec; /* Block special device to mount */ + u_int32_t lastblock; /* Special device last block */ +}; + +/* + * Arguments to mount tmpfs file systems + */ +#define TMPFS_ARGS_VERSION 1 +struct tmpfs_args { + int ta_version; + + /* Size counters. */ + ino_t ta_nodes_max; + off_t ta_size_max; + + /* Root node attributes. */ + uid_t ta_root_uid; + gid_t ta_root_gid; + mode_t ta_root_mode; +}; + +/* + * Arguments to mount fusefs filesystems + */ +struct fusefs_args { + char *name; + int fd; + int max_read; + + /* + * FUSE does not allow the file system to be accessed by other users + * unless this option is specified. This is to prevent unintentional + * denial of service to other users if the file system is not + * responding. e.g. user executes df(1) or cron job that scans mounted + * file systems. + */ + int allow_other; +}; + +/* + * file system statistics + */ + +#define MFSNAMELEN 16 /* length of fs type name, including nul */ +#define MNAMELEN 90 /* length of buffer for returned name */ + +/* per-filesystem mount options */ +union mount_info { + struct ufs_args ufs_args; + struct mfs_args mfs_args; + struct nfs_args nfs_args; + struct iso_args iso_args; + struct msdosfs_args msdosfs_args; + struct ntfs_args ntfs_args; + struct tmpfs_args tmpfs_args; + char __align[160]; /* 64-bit alignment and room to grow */ +}; + +/* new statfs structure with mount options and statvfs fields */ +struct statfs { + u_int32_t f_flags; /* copy of mount flags */ + u_int32_t f_bsize; /* file system block size */ + u_int32_t f_iosize; /* optimal transfer block size */ + + /* unit is f_bsize */ + u_int64_t f_blocks; /* total data blocks in file system */ + u_int64_t f_bfree; /* free blocks in fs */ + int64_t f_bavail; /* free blocks avail to non-superuser */ + + u_int64_t f_files; /* total file nodes in file system */ + u_int64_t f_ffree; /* free file nodes in fs */ + int64_t f_favail; /* free file nodes avail to non-root */ + + u_int64_t f_syncwrites; /* count of sync writes since mount */ + u_int64_t f_syncreads; /* count of sync reads since mount */ + u_int64_t f_asyncwrites; /* count of async writes since mount */ + u_int64_t f_asyncreads; /* count of async reads since mount */ + + fsid_t f_fsid; /* file system id */ + u_int32_t f_namemax; /* maximum filename length */ + uid_t f_owner; /* user that mounted the file system */ + u_int64_t f_ctime; /* last mount [-u] time */ + + char f_fstypename[MFSNAMELEN]; /* fs type name */ + char f_mntonname[MNAMELEN]; /* directory on which mounted */ + char f_mntfromname[MNAMELEN]; /* mounted file system */ + char f_mntfromspec[MNAMELEN]; /* special for mount request */ + union mount_info mount_info; /* per-filesystem mount options */ +}; + + +/* + * File system types. + */ +#define MOUNT_FFS "ffs" /* UNIX "Fast" Filesystem */ +#define MOUNT_UFS MOUNT_FFS /* for compatibility */ +#define MOUNT_NFS "nfs" /* Network Filesystem */ +#define MOUNT_MFS "mfs" /* Memory Filesystem */ +#define MOUNT_MSDOS "msdos" /* MSDOS Filesystem */ +#define MOUNT_AFS "afs" /* Andrew Filesystem */ +#define MOUNT_CD9660 "cd9660" /* ISO9660 (aka CDROM) Filesystem */ +#define MOUNT_EXT2FS "ext2fs" /* Second Extended Filesystem */ +#define MOUNT_NCPFS "ncpfs" /* NetWare Network File System */ +#define MOUNT_NTFS "ntfs" /* NTFS */ +#define MOUNT_UDF "udf" /* UDF */ +#define MOUNT_TMPFS "tmpfs" /* tmpfs */ +#define MOUNT_FUSEFS "fuse" /* FUSE */ + +/* + * Structure per mounted file system. Each mounted file system has an + * array of operations and an instance record. The file systems are + * put on a doubly linked list. + */ +struct mount { + TAILQ_ENTRY(mount) mnt_list; /* mount list */ + SLIST_ENTRY(mount) mnt_dounmount; /* unmount work queue */ + const struct vfsops *mnt_op; /* operations on fs */ + struct vfsconf *mnt_vfc; /* configuration info */ + struct vnode *mnt_vnodecovered; /* vnode we mounted on */ + struct vnode *mnt_syncer; /* syncer vnode */ + TAILQ_HEAD(, vnode) mnt_vnodelist; /* list of vnodes this mount */ + struct rwlock mnt_lock; /* mount structure lock */ + struct refcnt mnt_refs; + int mnt_flag; /* flags */ + struct statfs mnt_stat; /* cache of filesystem stats */ + void *mnt_data; /* private data */ +}; + +/* + * Mount flags. + * + * Unmount uses MNT_FORCE flag. + */ +#define MNT_RDONLY 0x00000001 /* read only filesystem */ +#define MNT_SYNCHRONOUS 0x00000002 /* file system written synchronously */ +#define MNT_NOEXEC 0x00000004 /* can't exec from filesystem */ +#define MNT_NOSUID 0x00000008 /* don't honor setuid bits on fs */ +#define MNT_NODEV 0x00000010 /* don't interpret special files */ +#define MNT_NOPERM 0x00000020 /* don't enforce permission checks */ +#define MNT_ASYNC 0x00000040 /* file system written asynchronously */ +#define MNT_WXALLOWED 0x00000800 /* filesystem allows W|X mappings */ + +/* + * exported mount flags. + */ +#define MNT_EXRDONLY 0x00000080 /* exported read only */ +#define MNT_EXPORTED 0x00000100 /* file system is exported */ +#define MNT_DEFEXPORTED 0x00000200 /* exported to the world */ +#define MNT_EXPORTANON 0x00000400 /* use anon uid mapping for everyone */ + +/* + * Flags set by internal operations. + */ +#define MNT_LOCAL 0x00001000 /* filesystem is stored locally */ +#define MNT_QUOTA 0x00002000 /* quotas are enabled on filesystem */ +#define MNT_ROOTFS 0x00004000 /* identifies the root filesystem */ + +/* + * Extra post 4.4BSD-lite2 mount flags. + */ +#define MNT_NOATIME 0x00008000 /* don't update access times on fs */ + +/* + * Mask of flags that are visible to statfs() + */ +#define MNT_VISFLAGMASK 0x0400ffff + +#define MNT_BITS \ + "\20\001RDONLY\002SYNCHRONOUS\003NOEXEC\004NOSUID\005NODEV\006NOPERM" \ + "\007ASYNC\010EXRDONLY\011EXPORTED\012DEFEXPORTED\013EXPORTANON" \ + "\014WXALLOWED\015LOCAL\016QUOTA\017ROOTFS\020NOATIME\021UPDATE" \ + "\022DELEXPORT\023RELOAD\024FORCE\025STALLED\026SWAPPABLE\031UNMOUNT" \ + "\032WANTRDWR\033SOFTDEP\034DOOMED" + +/* + * filesystem control flags. + */ +#define MNT_UPDATE 0x00010000 /* not a real mount, just an update */ +#define MNT_DELEXPORT 0x00020000 /* delete export host lists */ +#define MNT_RELOAD 0x00040000 /* reload filesystem data */ +#define MNT_FORCE 0x00080000 /* force unmount or readonly change */ +#define MNT_STALLED 0x00100000 /* filesystem stalled */ +#define MNT_SWAPPABLE 0x00200000 /* filesystem can be used for swap */ +#define MNT_UNMOUNT 0x01000000 /* unmount in progress */ +#define MNT_WANTRDWR 0x02000000 /* want upgrade to read/write */ +#define MNT_SOFTDEP 0x04000000 /* soft dependencies being done - now ignored */ +#define MNT_DOOMED 0x08000000 /* device behind filesystem is gone */ + +#ifdef _KERNEL +#define MNT_OP_FLAGS (MNT_UPDATE | MNT_RELOAD | MNT_FORCE | MNT_WANTRDWR) +#endif + +/* + * Flags for various system call interfaces. + * + * waitfor flags to vfs_sync() and getfsstat() + */ +#define MNT_WAIT 1 /* synchronously wait for I/O to complete */ +#define MNT_NOWAIT 2 /* start all I/O, but do not wait for it */ +#define MNT_LAZY 3 /* push data not written by filesystem syncer */ + +/* + * Generic file handle + */ +struct fhandle { + fsid_t fh_fsid; /* File system id of mount point */ + struct fid fh_fid; /* File sys specific id */ +}; +typedef struct fhandle fhandle_t; + +/* + * Sysctl CTL_VFS definitions. + * + * Second level identifier specifies which filesystem. Second level + * identifier VFS_GENERIC returns information about all filesystems. + */ +#define VFS_GENERIC 0 /* generic filesystem information */ +/* + * Third level identifiers for VFS_GENERIC are given below; third + * level identifiers for specific filesystems are given in their + * mount specific header files. + */ +#define VFS_MAXTYPENUM 1 /* int: highest defined filesystem type */ +#define VFS_CONF 2 /* struct: vfsconf for filesystem given + as next argument */ +#define VFS_BCACHESTAT 3 /* struct: buffer cache statistics given + as next argument */ +#define CTL_VFSGENCTL_NAMES { \ + { 0, 0 }, \ + { "maxtypenum", CTLTYPE_INT }, \ + { "conf", CTLTYPE_NODE }, \ + { "bcachestat", CTLTYPE_STRUCT } \ +} + +/* + * Filesystem configuration information. One of these exists for each + * type of filesystem supported by the kernel. These are searched at + * mount time to identify the requested filesystem. + */ +struct vfsconf { + const struct vfsops *vfc_vfsops; /* filesystem operations vector */ + char vfc_name[MFSNAMELEN]; /* filesystem type name */ + int vfc_typenum; /* historic filesystem type number */ + u_int vfc_refcount; /* number mounted of this type */ + int vfc_flags; /* permanent flags */ + size_t vfc_datasize; /* size of data args */ +}; + +/* buffer cache statistics */ +struct bcachestats { + int64_t numbufs; /* number of buffers allocated */ + int64_t numbufpages; /* number of pages in buffer cache */ + int64_t numdirtypages; /* number of dirty free pages */ + int64_t numcleanpages; /* number of clean free pages */ + int64_t pendingwrites; /* number of pending writes */ + int64_t pendingreads; /* number of pending reads */ + int64_t numwrites; /* total writes started */ + int64_t numreads; /* total reads started */ + int64_t cachehits; /* total reads found in cache */ + int64_t busymapped; /* number of busy and mapped buffers */ + int64_t dmapages; /* dma reachable pages in buffer cache */ + int64_t highpages; /* pages above dma region */ + int64_t delwribufs; /* delayed write buffers */ + int64_t kvaslots; /* kva slots total */ + int64_t kvaslots_avail; /* available kva slots */ + int64_t highflips; /* total flips to above DMA */ + int64_t highflops; /* total failed flips to above DMA */ + int64_t dmaflips; /* total flips from high to DMA */ +}; +#ifdef _KERNEL +extern struct bcachestats bcstats; +extern long buflowpages, bufhighpages, bufbackpages; +#define BUFPAGES_DEFICIT (((buflowpages - bcstats.numbufpages) < 0) ? 0 \ + : buflowpages - bcstats.numbufpages) +#define BUFPAGES_INACT (((bcstats.numcleanpages - buflowpages) < 0) ? 0 \ + : bcstats.numcleanpages - buflowpages) +extern int bufcachepercent; +extern void bufadjust(int); +struct uvm_constraint_range; +extern unsigned long bufbackoff(struct uvm_constraint_range*, long); + +/* + * Operations supported on mounted file system. + */ +struct nameidata; +struct mbuf; + +extern int maxvfsconf; /* highest defined filesystem type */ + +struct vfsops { + int (*vfs_mount)(struct mount *mp, const char *path, + void *data, + struct nameidata *ndp, struct proc *p); + int (*vfs_start)(struct mount *mp, int flags, + struct proc *p); + int (*vfs_unmount)(struct mount *mp, int mntflags, + struct proc *p); + int (*vfs_root)(struct mount *mp, struct vnode **vpp); + int (*vfs_quotactl)(struct mount *mp, int cmds, uid_t uid, + caddr_t arg, struct proc *p); + int (*vfs_statfs)(struct mount *mp, struct statfs *sbp, + struct proc *p); + int (*vfs_sync)(struct mount *mp, int waitfor, int stall, + struct ucred *cred, struct proc *p); + int (*vfs_vget)(struct mount *mp, ino_t ino, + struct vnode **vpp); + int (*vfs_fhtovp)(struct mount *mp, struct fid *fhp, + struct vnode **vpp); + int (*vfs_vptofh)(struct vnode *vp, struct fid *fhp); + int (*vfs_init)(struct vfsconf *); + int (*vfs_sysctl)(int *, u_int, void *, size_t *, void *, + size_t, struct proc *); + int (*vfs_checkexp)(struct mount *mp, struct mbuf *nam, + int *extflagsp, struct ucred **credanonp); +}; + +#define VFS_MOUNT(MP, PATH, DATA, NDP, P) \ + (*(MP)->mnt_op->vfs_mount)(MP, PATH, DATA, NDP, P) +#define VFS_START(MP, FLAGS, P) (*(MP)->mnt_op->vfs_start)(MP, FLAGS, P) +#define VFS_UNMOUNT(MP, FORCE, P) (*(MP)->mnt_op->vfs_unmount)(MP, FORCE, P) +#define VFS_ROOT(MP, VPP) (*(MP)->mnt_op->vfs_root)(MP, VPP) +#define VFS_QUOTACTL(MP,C,U,A,P) (*(MP)->mnt_op->vfs_quotactl)(MP, C, U, A, P) +#define VFS_STATFS(MP, SBP, P) (*(MP)->mnt_op->vfs_statfs)(MP, SBP, P) +#define VFS_SYNC(MP, W, S, C, P) (*(MP)->mnt_op->vfs_sync)(MP, W, S, C, P) +#define VFS_VGET(MP, INO, VPP) (*(MP)->mnt_op->vfs_vget)(MP, INO, VPP) +#define VFS_FHTOVP(MP, FIDP, VPP) \ + (*(MP)->mnt_op->vfs_fhtovp)(MP, FIDP, VPP) +#define VFS_VPTOFH(VP, FIDP) (*(VP)->v_mount->mnt_op->vfs_vptofh)(VP, FIDP) +#define VFS_CHECKEXP(MP, NAM, EXFLG, CRED) \ + (*(MP)->mnt_op->vfs_checkexp)(MP, NAM, EXFLG, CRED) + +/* Set up the filesystem operations for vnodes. */ +extern const struct vfsops ffs_vfsops; +extern const struct vfsops mfs_vfsops; +extern const struct vfsops msdosfs_vfsops; +extern const struct vfsops nfs_vfsops; +extern const struct vfsops cd9660_vfsops; +extern const struct vfsops ext2fs_vfsops; +extern const struct vfsops ntfs_vfsops; +extern const struct vfsops udf_vfsops; +extern const struct vfsops fusefs_vfsops; +extern const struct vfsops tmpfs_vfsops; + +#include +#include /* XXX for AF_MAX */ + +/* + * Network address lookup element + */ +struct netcred { + struct radix_node netc_rnodes[2]; + int netc_exflags; + int netc_len; /* size of the allocation */ + struct ucred netc_anon; +}; + +/* + * Network export information + */ +struct netexport { + struct netcred ne_defexported; /* Default export */ + struct radix_node_head *ne_rtable_inet;/* Individual exports */ +}; + +/* + * exported vnode operations + */ +int vfs_busy(struct mount *, int); +#define VB_READ 0x01 +#define VB_WRITE 0x02 +#define VB_NOWAIT 0x04 /* immediately fail on busy lock */ +#define VB_WAIT 0x08 /* sleep fail on busy lock */ +#define VB_DUPOK 0x10 /* permit duplicate mount busying */ + +int vfs_isbusy(struct mount *); +struct mount *vfs_mount_alloc(struct vnode *, struct vfsconf *); +void vfs_mount_free(struct mount *); +int vfs_mount_foreach_vnode(struct mount *, int (*func)(struct vnode *, + void *), void *); +void vfs_getnewfsid(struct mount *); +struct mount *vfs_getvfs(fsid_t *); +int vfs_mountedon(struct vnode *); +int vfs_rootmountalloc(char *, char *, struct mount **); +void vfs_unbusy(struct mount *); +extern TAILQ_HEAD(mntlist, mount) mountlist; +int vfs_stall(struct proc *, int); +void vfs_stall_barrier(void); + + /* process mount export info */ +int vfs_export(struct mount *, struct netexport *, struct export_args *); + /* lookup host in fs export list */ +struct netcred *vfs_export_lookup(struct mount *, struct netexport *, + struct mbuf *); +int vfs_allocate_syncvnode(struct mount *); + +int vfs_syncwait(struct proc *, int); /* sync and wait for complete */ +void vfs_shutdown(struct proc *); /* unmount and sync file systems */ +int dounmount(struct mount *, int, struct proc *); +void vfsinit(void); +struct vfsconf *vfs_byname(const char *); +struct vfsconf *vfs_bytypenum(int); +#else /* _KERNEL */ +__BEGIN_DECLS +int fstatfs(int, struct statfs *); +int getfh(const char *, fhandle_t *); +int getfsstat(struct statfs *, size_t, int); +int getmntinfo(struct statfs **, int); +int mount(const char *, const char *, int, void *); +int statfs(const char *, struct statfs *); +int unmount(const char *, int); +#if __BSD_VISIBLE +struct stat; +int fhopen(const fhandle_t *, int); +int fhstat(const fhandle_t *, struct stat *); +int fhstatfs(const fhandle_t *, struct statfs *); +#endif /* __BSD_VISIBLE */ +__END_DECLS +#endif /* _KERNEL */ +#endif /* !_SYS_MOUNT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/mplock.h b/lib/libc/include/generic-openbsd/sys/mplock.h new file mode 100644 index 0000000000..2a7afbd6e7 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/mplock.h @@ -0,0 +1,74 @@ +/* $OpenBSD: mplock.h,v 1.14 2024/07/03 01:36:50 jsg Exp $ */ + +/* + * Copyright (c) 2004 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 _MPLOCK_H_ +#define _MPLOCK_H_ + +#include + +#ifdef __USE_MI_MPLOCK + +#include + +struct __mp_lock_cpu { + u_int mplc_ticket; + u_int mplc_depth; +}; + +struct __mp_lock { + struct __mp_lock_cpu mpl_cpus[MAXCPUS]; + volatile u_int mpl_ticket; + u_int mpl_users; +#ifdef WITNESS + struct lock_object mpl_lock_obj; +#endif +}; + +void ___mp_lock_init(struct __mp_lock *, const struct lock_type *); +void __mp_lock(struct __mp_lock *); +void __mp_unlock(struct __mp_lock *); +int __mp_release_all(struct __mp_lock *); +void __mp_acquire_count(struct __mp_lock *, int); +int __mp_lock_held(struct __mp_lock *, struct cpu_info *); + +#ifdef WITNESS + +#define __mp_lock_init(mpl) do { \ + static const struct lock_type __lock_type = { .lt_name = #mpl };\ + ___mp_lock_init((mpl), &__lock_type); \ +} while (0) + +#else /* WITNESS */ + +#define __mp_lock_init(mpl) ___mp_lock_init((mpl), NULL) + +#endif /* WITNESS */ + +#endif /* __USE_MI_MPLOCK */ + +extern struct __mp_lock kernel_lock; + +#endif /* !_MPLOCK_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/msg.h b/lib/libc/include/generic-openbsd/sys/msg.h new file mode 100644 index 0000000000..a7a4f3a5ba --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/msg.h @@ -0,0 +1,146 @@ +/* $OpenBSD: msg.h,v 1.24 2024/10/27 22:08:25 jsg Exp $ */ +/* $NetBSD: msg.h,v 1.9 1996/02/09 18:25:18 christos Exp $ */ + +/* + * SVID compatible msg.h file + * + * Author: Daniel Boulet + * + * Copyright 1993 Daniel Boulet and RTMX Inc. + * + * This system call was implemented by Daniel Boulet under contract from RTMX. + * + * Redistribution and use in source forms, with and without modification, + * are permitted provided that this entire comment appears intact. + * + * Redistribution in binary form may occur without any restrictions. + * Obviously, it would be nice if you gave credit where credit is due + * but requiring it would be too onerous. + * + * This software is provided ``AS IS'' without any warranties of any kind. + */ + +#ifndef _SYS_MSG_H_ +#define _SYS_MSG_H_ + +#include + +/* + * The MSG_NOERROR identifier value, the msqid_ds struct and the msg struct + * are as defined by the SV API Intel 386 Processor Supplement. + */ + +#define MSG_NOERROR 010000 /* don't complain about too long msgs */ + +typedef unsigned long msgqnum_t; +typedef unsigned long msglen_t; + +struct msqid_ds { + struct ipc_perm msg_perm; /* msg queue permission bits */ + struct msg *msg_first; /* first message in the queue */ + struct msg *msg_last; /* last message in the queue */ + msglen_t msg_cbytes; /* number of bytes in use on the queue */ + msgqnum_t msg_qnum; /* number of msgs in the queue */ + msglen_t msg_qbytes; /* max # of bytes on the queue */ + pid_t msg_lspid; /* pid of last msgsnd() */ + pid_t msg_lrpid; /* pid of last msgrcv() */ + time_t msg_stime; /* time of last msgsnd() */ + long msg_pad1; + time_t msg_rtime; /* time of last msgrcv() */ + long msg_pad2; + time_t msg_ctime; /* time of last msgctl() */ + long msg_pad3; + long msg_pad4[4]; +}; + +#ifdef _KERNEL +#include + +struct msg { + long msg_type; + size_t msg_len; + struct mbuf *msg_data; + + TAILQ_ENTRY(msg) msg_next; +}; + +struct que { + struct msqid_ds msqid_ds; + int que_ix; /* pseudo-index */ + int que_flags; + int que_references; + + TAILQ_ENTRY(que) que_next; + TAILQ_HEAD(, msg) que_msgs; +}; + +/* for que_flags */ +#define MSGQ_READERS 0x01 +#define MSGQ_WRITERS 0x02 +#define MSGQ_DYING 0x04 + +#define QREF(q) (q)->que_references++ + +#define QRELE(q) do { \ + if (--(q)->que_references == 0 && (q)->que_flags & MSGQ_DYING) \ + wakeup_one(&(q)->que_references); \ +} while (0) + +/* + * Based on the configuration parameters described in an SVR2 (yes, two) + * config(1m) man page. + * + * Each message is broken up and stored in segments that are msgssz bytes + * long. For efficiency reasons, this should be a power of two. Also, + * it doesn't make sense if it is less than 8 or greater than about 256. + * Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of + * two between 8 and 1024 inclusive (and panic's if it isn't). + */ +struct msginfo { + int msgmax, /* max chars in a message */ + msgmni, /* max message queue identifiers */ + msgmnb, /* max chars in a queue */ + msgtql, /* max messages in system */ + msgssz, /* size of a message segment (see notes above) */ + msgseg; /* number of message segments */ +}; +#ifdef SYSVMSG +extern struct msginfo msginfo; +#endif + +int sysctl_sysvmsg(int *, u_int, void *, size_t *); + +struct msg_sysctl_info { + struct msginfo msginfo; + struct msqid_ds msgids[1]; +}; + +#ifndef MSGSSZ +#define MSGSSZ 8 /* Each segment must be 2^N long */ +#endif +#ifndef MSGSEG +#define MSGSEG 2048 /* must be less than 32767 */ +#endif +#undef MSGMAX /* ALWAYS compute MSGMAX! */ +#define MSGMAX (MSGSSZ*MSGSEG) +#ifndef MSGMNB +#define MSGMNB 2048 /* max # of bytes in a queue */ +#endif +#ifndef MSGMNI +#define MSGMNI 40 +#endif +#ifndef MSGTQL +#define MSGTQL 40 +#endif + +void msginit(void); +#else /* !_KERNEL */ +__BEGIN_DECLS +int msgctl(int, int, struct msqid_ds *); +int msgget(key_t, int); +int msgsnd(int, const void *, size_t, int); +int msgrcv(int, void *, size_t, long, int); +__END_DECLS +#endif + +#endif /* !_SYS_MSG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/msgbuf.h b/lib/libc/include/generic-openbsd/sys/msgbuf.h new file mode 100644 index 0000000000..11395ce60b --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/msgbuf.h @@ -0,0 +1,58 @@ +/* $OpenBSD: msgbuf.h,v 1.13 2020/10/25 10:55:42 visa Exp $ */ +/* $NetBSD: msgbuf.h,v 1.8 1995/03/26 20:24:27 jtc Exp $ */ + +/* + * Copyright (c) 1981, 1984, 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. + * + * @(#)msgbuf.h 8.1 (Berkeley) 6/2/93 + */ + +/* + * Locking: + * I immutable after creation + * L log_mtx + * Lw log_mtx for writing + */ +struct msgbuf { +#define MSG_MAGIC 0x063061 + long msg_magic; /* [I] buffer magic value */ + long msg_bufx; /* [L] write pointer */ + long msg_bufr; /* [L] read pointer */ + long msg_bufs; /* [I] real msg_bufc size (bytes) */ + long msg_bufd; /* [L] number of dropped bytes */ + char msg_bufc[1]; /* [Lw] buffer */ +}; +#ifdef _KERNEL +#define CONSBUFSIZE (16 * 1024) /* console message buffer size */ +extern struct msgbuf *msgbufp; +extern struct msgbuf *consbufp; + +void initmsgbuf(caddr_t buf, size_t bufsize); +void initconsbuf(void); +void msgbuf_putchar(struct msgbuf *, const char c); +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/mtio.h b/lib/libc/include/generic-openbsd/sys/mtio.h new file mode 100644 index 0000000000..c8bfe4c6c3 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/mtio.h @@ -0,0 +1,147 @@ +/* $OpenBSD: mtio.h,v 1.9 2007/06/01 18:44:48 krw Exp $ */ +/* $NetBSD: mtio.h,v 1.14 1997/04/15 06:50:19 lukem Exp $ */ + +/* + * Copyright (c) 1982, 1986, 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. + * + * @(#)mtio.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _SYS_MTIO_H_ +#define _SYS_MTIO_H_ + +/* + * Structures and definitions for mag tape io control commands + */ + +/* structure for MTIOCTOP - mag tape op command */ +struct mtop { + short mt_op; /* operations defined below */ + int mt_count; /* how many of them */ +}; + +/* operations */ +#define MTWEOF 0 /* write an end-of-file record */ +#define MTFSF 1 /* forward space file */ +#define MTBSF 2 /* backward space file */ +#define MTFSR 3 /* forward space record */ +#define MTBSR 4 /* backward space record */ +#define MTREW 5 /* rewind */ +#define MTOFFL 6 /* rewind and put the drive offline */ +#define MTNOP 7 /* no operation, sets status only */ +#define MTRETEN 8 /* retension */ +#define MTERASE 9 /* erase entire tape */ +#define MTEOM 10 /* forward to end of media */ +#define MTNBSF 11 /* backward space to beginning of file */ +#define MTCACHE 12 /* enable controller cache */ +#define MTNOCACHE 13 /* disable controller cache */ +#define MTSETBSIZ 14 /* set block size; 0 for variable */ +#define MTSETDNSTY 15 /* set density code for current mode */ + +/* structure for MTIOCGET - mag tape get status command */ + +struct mtget { + short mt_type; /* type of magtape device */ +/* the following two registers are grossly device dependent */ + short mt_dsreg; /* ``drive status'' register */ + short mt_erreg; /* ``error'' register */ +/* end device-dependent registers */ + short mt_resid; /* residual count */ + int mt_fileno; /* current file number relative to BOT. */ + int mt_blkno; /* current block number relative to BOF. */ + int mt_blksiz; /* current block size */ + int mt_density; /* current density code */ + int mt_mblksiz; /* default block size */ + int mt_mdensity; /* default density code */ +}; + +/* + * Constants for mt_type byte. These are the same + * for controllers compatible with the types listed. + */ +#define MT_ISTS 0x01 /* TS-11 */ +#define MT_ISHT 0x02 /* TM03 Massbus: TE16, TU45, TU77 */ +#define MT_ISTM 0x03 /* TM11/TE10 Unibus */ +#define MT_ISMT 0x04 /* TM78/TU78 Massbus */ +#define MT_ISUT 0x05 /* SI TU-45 emulation on Unibus */ +#define MT_ISCPC 0x06 /* SUN */ +#define MT_ISAR 0x07 /* SUN */ +#define MT_ISTMSCP 0x08 /* DEC TMSCP protocol (TU81, TK50) */ +#define MT_ISCY 0x09 /* CCI Cipher */ +#define MT_ISCT 0x0a /* HP 1/4 tape */ +#define MT_ISFHP 0x0b /* HP 7980 1/2 tape */ +#define MT_ISEXABYTE 0x0c /* Exabyte */ +#define MT_ISEXA8200 0x0c /* Exabyte EXB-8200 */ +#define MT_ISEXA8500 0x0d /* Exabyte EXB-8500 */ +#define MT_ISVIPER1 0x0e /* Archive Viper-150 */ +#define MT_ISPYTHON 0x0f /* Archive Python (DAT) */ +#define MT_ISHPDAT 0x10 /* HP 35450A DAT drive */ +#define MT_ISWANGTEK 0x11 /* WANGTEK 5150ES */ +#define MT_ISCALIPER 0x12 /* Caliper CP150 */ +#define MT_ISWTEK5099 0x13 /* WANGTEK 5099ES */ +#define MT_ISVIPER2525 0x14 /* Archive Viper 2525 */ +#define MT_ISMFOUR 0x11 /* M4 Data 1/2 9track drive */ +#define MT_ISTK50 0x12 /* DEC SCSI TK50 */ +#define MT_ISMT02 0x13 /* Emulex MT02 SCSI tape controller */ + +/* bits defined for the mt_dsreg field */ +#define MT_DS_RDONLY 0x10 /* tape mounted readonly */ +#define MT_DS_MOUNTED 0x03 /* tape mounted (for control opens) */ + +/* mag tape io control commands */ +#define MTIOCTOP _IOW('m', 1, struct mtop) /* do a mag tape op */ +#define MTIOCGET _IOR('m', 2, struct mtget) /* get tape status */ +#define MTIOCIEOT _IO('m', 3) /* ignore EOT error */ +#define MTIOCEEOT _IO('m', 4) /* enable EOT error */ + +/* + * When more SCSI-3 SSC (streaming device) devices are out there + * that support the full 32 byte type 2 structure, we'll have to + * rethink these ioctls to support all the entities they haul into + * the picture (64 bit blocks, logical file record numbers, etc..). + */ +#define MTIOCRDSPOS _IOR('m', 5, u_int32_t) /* get logical blk addr */ +#define MTIOCRDHPOS _IOR('m', 6, u_int32_t) /* get hardware blk addr */ +#define MTIOCSLOCATE _IOW('m', 5, u_int32_t) /* seek to logical blk addr */ +#define MTIOCHLOCATE _IOW('m', 6, u_int32_t) /* seek to hardware blk addr */ + +#ifdef _KERNEL +/* + * minor device number + */ + +#define T_UNIT 003 /* unit selection */ +#define T_NOREWIND 004 /* no rewind on close */ +#define T_DENSEL 030 /* density select */ +#define T_800BPI 000 /* select 800 bpi */ +#define T_1600BPI 010 /* select 1600 bpi */ +#define T_6250BPI 020 /* select 6250 bpi */ +#define T_BADBPI 030 /* undefined selection */ +#endif /* _KERNEL */ + +#endif /* !_SYS_MTIO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/mutex.h b/lib/libc/include/generic-openbsd/sys/mutex.h new file mode 100644 index 0000000000..2e66c66ada --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/mutex.h @@ -0,0 +1,168 @@ +/* $OpenBSD: mutex.h,v 1.23 2025/07/02 14:36:56 claudio Exp $ */ + +/* + * Copyright (c) 2004 Artur Grabowski + * + * 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 _SYS_MUTEX_H_ +#define _SYS_MUTEX_H_ + +/* + * A mutex is: + * - owned by a cpu. + * - non-recursive. + * - spinning. + * - not providing mutual exclusion between processes, only cpus. + * - providing interrupt blocking when necessary. + * + * Different mutexes can be nested, but not interleaved. This is ok: + * "mtx_enter(foo); mtx_enter(bar); mtx_leave(bar); mtx_leave(foo);" + * This is _not_ ok: + * "mtx_enter(foo); mtx_enter(bar); mtx_leave(foo); mtx_leave(bar);" + */ + +/* + * To prevent lock ordering problems with the kernel lock, we need to + * make sure we block all interrupts that can grab the kernel lock. + * The simplest way to achieve this is to make sure mutexes always + * raise the interrupt priority level to the highest level that has + * interrupts that grab the kernel lock. + */ +#ifdef MULTIPROCESSOR +#define __MUTEX_IPL(ipl) \ + (((ipl) < IPL_MPFLOOR) ? IPL_MPFLOOR : (ipl)) +#else +#define __MUTEX_IPL(ipl) (ipl) +#endif + +#include + +#ifdef __USE_MI_MUTEX + +#include + +struct mutex { + void *volatile mtx_owner; + int mtx_wantipl; + int mtx_oldipl; +#ifdef WITNESS + struct lock_object mtx_lock_obj; +#endif +}; + +#ifdef WITNESS +#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \ + { NULL, __MUTEX_IPL((ipl)), IPL_NONE, MTX_LO_INITIALIZER(name, flags) } +#else +#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \ + { NULL, __MUTEX_IPL((ipl)), IPL_NONE } +#endif + +void __mtx_init(struct mutex *, int); +#define _mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl))) + +#ifdef DIAGNOSTIC +#define MUTEX_ASSERT_LOCKED(mtx) do { \ + if (((mtx)->mtx_owner != curcpu()) && !(panicstr || db_active)) \ + panic("mutex %p not held in %s", (mtx), __func__); \ +} while (0) + +#define MUTEX_ASSERT_UNLOCKED(mtx) do { \ + if (((mtx)->mtx_owner == curcpu()) && !(panicstr || db_active)) \ + panic("mutex %p held in %s", (mtx), __func__); \ +} while (0) +#else +#define MUTEX_ASSERT_LOCKED(mtx) do { (void)(mtx); } while (0) +#define MUTEX_ASSERT_UNLOCKED(mtx) do { (void)(mtx); } while (0) +#endif + +#define MUTEX_LOCK_OBJECT(mtx) (&(mtx)->mtx_lock_obj) +#define MUTEX_OLDIPL(mtx) (mtx)->mtx_oldipl + +#endif /* __USE_MI_MUTEX */ + + +#define MTX_LO_FLAGS(flags) \ + ((!((flags) & MTX_NOWITNESS) ? LO_WITNESS : 0) | \ + ((flags) & MTX_DUPOK ? LO_DUPOK : 0) | \ + LO_INITIALIZED | (LO_CLASS_MUTEX << LO_CLASSSHIFT)) + +#define __MTX_STRING(x) #x +#define __MTX_S(x) __MTX_STRING(x) +#define __MTX_NAME __FILE__ ":" __MTX_S(__LINE__) + +#define MTX_LO_INITIALIZER(name, flags) \ + { .lo_type = &(const struct lock_type){ .lt_name = __MTX_NAME }, \ + .lo_name = (name), \ + .lo_flags = MTX_LO_FLAGS(flags) } + +#define MTX_NOWITNESS 0x01 +#define MTX_DUPOK 0x02 + +#define MUTEX_INITIALIZER(ipl) \ + MUTEX_INITIALIZER_FLAGS(ipl, __MTX_NAME, 0) + +/* + * Some architectures need to do magic for the ipl, so they need a macro. + */ +#ifndef _mtx_init +void _mtx_init(struct mutex *, int); +#endif + +void mtx_enter(struct mutex *); +int mtx_enter_try(struct mutex *); +void mtx_leave(struct mutex *); + +#define mtx_init(m, ipl) mtx_init_flags(m, ipl, NULL, 0) + +#define mtx_owned(mtx) \ + (((mtx)->mtx_owner == curcpu()) || panicstr || db_active) + +#ifdef WITNESS + +void _mtx_init_flags(struct mutex *, int, const char *, int, + const struct lock_type *); + +#define mtx_init_flags(m, ipl, name, flags) do { \ + static const struct lock_type __lock_type = { .lt_name = #m }; \ + _mtx_init_flags(m, ipl, name, flags, &__lock_type); \ +} while (0) + +#else /* WITNESS */ + +#define mtx_init_flags(m, ipl, name, flags) do { \ + (void)(name); (void)(flags); \ + _mtx_init(m, ipl); \ +} while (0) + +#define _mtx_init_flags(m,i,n,f,t) _mtx_init(m,i) + +#endif /* WITNESS */ + +#if defined(_KERNEL) && defined(DDB) + +struct db_mutex { + struct cpu_info *volatile mtx_owner; + unsigned long mtx_intr_state; +}; + +#define DB_MUTEX_INITIALIZER { NULL, 0 } + +void db_mtx_enter(struct db_mutex *); +void db_mtx_leave(struct db_mutex *); + +#endif /* _KERNEL && DDB */ + +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/namei.h b/lib/libc/include/generic-openbsd/sys/namei.h new file mode 100644 index 0000000000..02339cab41 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/namei.h @@ -0,0 +1,274 @@ +/* $OpenBSD: namei.h,v 1.50 2022/01/11 23:59:55 jsg Exp $ */ +/* $NetBSD: namei.h,v 1.11 1996/02/09 18:25:20 christos Exp $ */ + +/* + * Copyright (c) 1985, 1989, 1991, 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. + * + * @(#)namei.h 8.4 (Berkeley) 8/20/94 + */ + +#ifndef _SYS_NAMEI_H_ +#define _SYS_NAMEI_H_ + +#include +#include +#include + +struct unveil; + +/* + * Encapsulation of namei parameters. + */ +struct nameidata { + /* + * Arguments to namei/lookup. + */ + const char *ni_dirp; /* pathname pointer */ + int ni_dirfd; /* dirfd from *at() functions */ + enum uio_seg ni_segflg; /* location of pathname */ + /* u_long ni_nameiop; namei operation */ + /* u_long ni_flags; flags to namei */ + /* struct proc *ni_proc; process requesting lookup */ + /* + * Arguments to lookup. + */ + /* struct ucred *ni_cred; credentials */ + struct vnode *ni_startdir; /* starting directory */ + struct vnode *ni_rootdir; /* logical root directory */ + uint64_t ni_pledge; /* expected pledge for namei */ + u_char ni_unveil; /* required unveil flags for namei */ + /* + * Results: returned from/manipulated by lookup + */ + struct vnode *ni_vp; /* vnode of result */ + struct vnode *ni_dvp; /* vnode of intermediate directory */ + + /* + * Shared between namei and lookup/commit routines. + */ + size_t ni_pathlen; /* remaining chars in path */ + char *ni_next; /* next location in pathname */ + u_long ni_loopcnt; /* count of symlinks encountered */ + struct unveil *ni_unveil_match; /* last matching unveil component */ + + /* + * Lookup parameters: this structure describes the subset of + * information from the nameidata structure that is passed + * through the VOP interface. + */ + struct componentname { + /* + * Arguments to lookup. + */ + u_long cn_nameiop; /* namei operation */ + u_long cn_flags; /* flags to namei */ + struct proc *cn_proc; /* process requesting lookup */ + struct ucred *cn_cred; /* credentials */ + /* + * Shared between lookup and commit routines. + */ + char *cn_pnbuf; /* pathname buffer */ + char *cn_rpbuf; /* realpath buffer */ + size_t cn_rpi; /* realpath index */ + char *cn_nameptr; /* pointer to looked up name */ + long cn_namelen; /* length of looked up component */ + long cn_consume; /* chars to consume in lookup() */ + } ni_cnd; +}; + +#ifdef _KERNEL +/* + * namei operations + */ +#define LOOKUP 0 /* perform name lookup only */ +#define CREATE 1 /* setup for file creation */ +#define DELETE 2 /* setup for file deletion */ +#define RENAME 3 /* setup for file renaming */ +#define OPMASK 3 /* mask for operation */ +/* + * namei operational modifier flags, stored in ni_cnd.flags + */ +#define LOCKLEAF 0x0004 /* lock inode on return */ +#define LOCKPARENT 0x0008 /* want parent vnode returned locked */ +#define WANTPARENT 0x0010 /* want parent vnode returned unlocked */ +#define NOCACHE 0x0020 /* name must not be left in cache */ +#define FOLLOW 0x0040 /* follow symbolic links */ +#define NOFOLLOW 0x0000 /* do not follow symbolic links (pseudo) */ +#define MODMASK 0x00fc /* mask of operational modifiers */ +/* + * Namei parameter descriptors. + * + * SAVENAME may be set by either the callers of namei or by VOP_LOOKUP. + * If the caller of namei sets the flag (for example execve wants to + * know the name of the program that is being executed), then it must + * free the buffer. If VOP_LOOKUP sets the flag, then the buffer must + * be freed by either the commit routine or the VOP_ABORT routine. + * SAVESTART is set only by the callers of namei. It implies SAVENAME + * plus the addition of saving the parent directory that contains the + * name in ni_startdir. It allows repeated calls to lookup for the + * name being sought. The caller is responsible for releasing the + * buffer and for vrele'ing ni_startdir. + */ +#define NOCROSSMOUNT 0x000100 /* do not cross mount points */ +#define RDONLY 0x000200 /* lookup with read-only semantics */ +#define HASBUF 0x000400 /* has allocated pathname buffer */ +#define SAVENAME 0x000800 /* save pathname buffer */ +#define SAVESTART 0x001000 /* save starting directory */ +#define ISDOTDOT 0x002000 /* current component name is .. */ +#define MAKEENTRY 0x004000 /* entry is to be added to name cache */ +#define ISLASTCN 0x008000 /* this is last component of pathname */ +#define ISSYMLINK 0x010000 /* symlink needs interpretation */ +#define REALPATH 0x020000 /* save pathname buffer for realpath */ +#define REQUIREDIR 0x080000 /* must be a directory */ +#define STRIPSLASHES 0x100000 /* strip trailing slashes */ +#define PDIRUNLOCK 0x200000 /* vfs_lookup() unlocked parent dir */ +#define BYPASSUNVEIL 0x400000 /* bypass pledgepath check */ +#define KERNELPATH 0x800000 /* access file as kernel, not process */ + +/* + * Initialization of an nameidata structure. + */ +void ndinitat(struct nameidata *ndp, u_long op, u_long flags, + enum uio_seg segflg, int dirfd, const char *namep, struct proc *p); + +#define NDINITAT(ndp, op, flags, segflg, dirfd, namep, p) \ + ndinitat(ndp, op, flags, segflg, dirfd, namep, p) + +#define NDINIT(ndp, op, flags, segflp, namep, p) \ + ndinitat(ndp, op, flags, segflp, AT_FDCWD, namep, p) + +/* Defined for users of NDINIT(). */ +#define AT_FDCWD -100 +#endif + +/* + * This structure describes the elements in the cache of recent + * names looked up by namei. + */ + +#define NAMECACHE_MAXLEN 31 /* maximum name segment length we bother with */ + +struct namecache { + TAILQ_ENTRY(namecache) nc_lru; /* Regular Entry LRU chain */ + TAILQ_ENTRY(namecache) nc_neg; /* Negative Entry LRU chain */ + RBT_ENTRY(namecache) n_rbcache; /* Namecache rb tree from vnode */ + TAILQ_ENTRY(namecache) nc_me; /* ncp's referring to me */ + struct vnode *nc_dvp; /* vnode of parent of name */ + u_long nc_dvpid; /* capability number of nc_dvp */ + struct vnode *nc_vp; /* vnode the name refers to */ + u_long nc_vpid; /* capability number of nc_vp */ + char nc_nlen; /* length of name */ + char nc_name[NAMECACHE_MAXLEN]; /* segment name */ +}; + +#ifdef _KERNEL +struct namecache_rb_cache; + +int namei(struct nameidata *ndp); +int vfs_lookup(struct nameidata *ndp); +int vfs_relookup(struct vnode *dvp, struct vnode **vpp, + struct componentname *cnp); +void cache_tree_init(struct namecache_rb_cache *); +void cache_purge(struct vnode *); +int cache_lookup(struct vnode *, struct vnode **, struct componentname *); +void cache_enter(struct vnode *, struct vnode *, struct componentname *); +int cache_revlookup(struct vnode *, struct vnode **, char **, char *); +void nchinit(void); +struct mount; +void cache_purgevfs(struct mount *); + +int unveil_add(struct proc *, struct nameidata *, const char *); +void unveil_removevnode(struct vnode *); +ssize_t unveil_find_cover(struct vnode *, struct proc *); +struct unveil *unveil_lookup(struct vnode *, struct process *, ssize_t *); +void unveil_start_relative(struct proc *, struct nameidata *, struct vnode *); +void unveil_check_component(struct proc *, struct nameidata *, struct vnode *); +int unveil_check_final(struct proc *, struct nameidata *); + +extern struct pool namei_pool; + +#endif + +/* + * Stats on usefulness of namei caches. + */ +struct nchstats { + u_int64_t ncs_goodhits; /* hits that we can really use */ + u_int64_t ncs_neghits; /* negative hits that we can use */ + u_int64_t ncs_badhits; /* hits we must drop */ + u_int64_t ncs_falsehits; /* hits with id mismatch */ + u_int64_t ncs_miss; /* misses */ + u_int64_t ncs_long; /* long names that ignore cache */ + u_int64_t ncs_pass2; /* names found with passes == 2 */ + u_int64_t ncs_2passes; /* number of times we attempt it */ + u_int64_t ncs_revhits; /* reverse-cache hits */ + u_int64_t ncs_revmiss; /* reverse-cache misses */ + u_int64_t ncs_dothits; /* hits on '.' lookups */ + u_int64_t ncs_dotdothits; /* hits on '..' lookups */ +}; + +/* These sysctl names are only really used by sysctl(8) */ +#define KERN_NCHSTATS_GOODHITS 1 +#define KERN_NCHSTATS_NEGHITS 2 +#define KERN_NCHSTATS_BADHITS 3 +#define KERN_NCHSTATS_FALSEHITS 4 +#define KERN_NCHSTATS_MISS 5 +#define KERN_NCHSTATS_LONG 6 +#define KERN_NCHSTATS_PASS2 7 +#define KERN_NCHSTATS_2PASSES 8 +#define KERN_NCHSTATS_REVHITS 9 +#define KERN_NCHSTATS_REVMISS 10 +#define KERN_NCHSTATS_DOTHITS 11 +#define KERN_NCHSTATS_DOTDOTHITS 12 +#define KERN_NCHSTATS_MAXID 13 + +#define CTL_KERN_NCHSTATS_NAMES { \ + { 0, 0 }, \ + { "good_hits", CTLTYPE_QUAD }, \ + { "negative_hits", CTLTYPE_QUAD }, \ + { "bad_hits", CTLTYPE_QUAD }, \ + { "false_hits", CTLTYPE_QUAD }, \ + { "misses", CTLTYPE_QUAD }, \ + { "long_names", CTLTYPE_QUAD }, \ + { "pass2", CTLTYPE_QUAD }, \ + { "2passes", CTLTYPE_QUAD }, \ + { "ncs_revhits", CTLTYPE_QUAD }, \ + { "ncs_revmiss", CTLTYPE_QUAD }, \ + { "ncs_dothits", CTLTYPE_QUAD }, \ + { "nch_dotdothits", CTLTYPE_QUAD }, \ +} + +/* Unveil flags for namei */ +#define UNVEIL_READ 0x01 +#define UNVEIL_WRITE 0x02 +#define UNVEIL_CREATE 0x04 +#define UNVEIL_EXEC 0x08 +#define UNVEIL_USERSET 0x10 +#define UNVEIL_MASK 0x0F + +#endif /* !_SYS_NAMEI_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/param.h b/lib/libc/include/generic-openbsd/sys/param.h new file mode 100644 index 0000000000..e86909313f --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/param.h @@ -0,0 +1,223 @@ +/* $OpenBSD: param.h,v 1.145 2025/09/10 16:00:04 deraadt Exp $ */ + +/*- + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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 _SYS_PARAM_H_ +#define _SYS_PARAM_H_ + +#define BSD 199306 /* System version (year & month). */ +#define BSD4_3 1 +#define BSD4_4 1 + +/* zig patch: ___OpenBSD and OpenBSDX_Y are defined by the compiler */ +#define OpenBSD ___OpenBSD + +#include + +#ifndef _LOCORE +#include +#endif + +/* + * Machine-independent constants (some used in following include files). + * Redefined constants are from POSIX 1003.1 limits file. + * + * MAXCOMLEN should be >= sizeof(ac_comm) (see ) + * MAXLOGNAME should be >= UT_NAMESIZE (see ) + */ +#include + +#define MAXCOMLEN _MAXCOMLEN-1 /* max command name remembered, without NUL */ +#define MAXINTERP 128 /* max interpreter file name length */ +#define MAXLOGNAME LOGIN_NAME_MAX /* max login name length w/ NUL */ +#define MAXUPRC CHILD_MAX /* max simultaneous processes */ +#define NCARGS ARG_MAX /* max bytes for an exec function */ +#define NGROUPS NGROUPS_MAX /* max number groups */ +#define NOFILE OPEN_MAX /* max open files per process (soft) */ +#define NOFILE_MAX 1024 /* max open files per process (hard) */ +#define NOGROUP 65535 /* marker for empty group set member */ +#define MAXHOSTNAMELEN 256 /* max hostname length w/ NUL */ + +/* More types and definitions used throughout the kernel. */ +#ifdef _KERNEL +#include +#include +#include +#include +#include +#include +#endif + +/* Signals. */ +#include + +/* Machine type dependent parameters. */ +#include +#include + +#ifdef _KERNEL +/* + * Priorities. Note that with 32 run queues, differences less than 4 are + * insignificant. + */ +#define PSWP 0 +#define PVM 4 +#define PINOD 8 +#define PRIBIO 16 +#define PVFS 20 +#endif /* _KERNEL */ +#define PZERO 22 /* No longer magic, shouldn't be here. XXX */ +#ifdef _KERNEL +#define PSOCK 24 +#define PWAIT 32 +#define PLOCK 36 +#define PPAUSE 40 +#define PUSER 50 +#define MAXPRI 127 /* Priorities range from 0 through MAXPRI. */ + +#define PRIMASK 0x0ff +#define PCATCH 0x100 /* OR'd with pri for tsleep to check signals */ +#define PNORELOCK 0x200 /* OR'd with pri for msleep to not reacquire + the mutex */ +#endif /* _KERNEL */ + +#define NODEV (dev_t)(-1) /* non-existent device */ + +#define ALIGNBYTES _ALIGNBYTES +#define ALIGN(p) _ALIGN(p) +#define ALIGNED_POINTER(p,t) _ALIGNED_POINTER(p,t) + +/* + * File system parameters and macros. + * + * The file system is made out of blocks of at most MAXBSIZE units, with + * smaller units (fragments) only in the last direct block. MAXBSIZE + * primarily determines the size of buffers in the buffer pool. It may be + * made larger without any effect on existing file systems; however making + * it smaller makes some file systems unmountable. + */ +#ifdef _KERNEL +#define MAXPHYS (64 * 1024) /* max raw I/O transfer size */ +#endif /* _KERNEL */ +#define MAXBSIZE (64 * 1024) + +#define _DEV_BSHIFT 9 /* log2(DEV_BSIZE) */ +#define DEV_BSIZE (1 << _DEV_BSHIFT) +#ifdef _KERNEL +#define DEV_BSHIFT _DEV_BSHIFT +#define BLKDEV_IOSIZE PAGE_SIZE +#endif /* _KERNEL */ + +/* pages to disk blocks */ +#ifndef ctod +#define ctod(x) ((x) << (PAGE_SHIFT - _DEV_BSHIFT)) +#endif +#ifndef dtoc +#define dtoc(x) ((x) >> (PAGE_SHIFT - _DEV_BSHIFT)) +#endif + +/* bytes to disk blocks */ +#ifndef btodb +#define btodb(x) ((x) >> _DEV_BSHIFT) +#endif +#ifndef dbtob +#define dbtob(x) ((x) << _DEV_BSHIFT) +#endif + +/* + * MAXPATHLEN defines the longest permissible path length after expanding + * symbolic links. It is used to allocate a temporary buffer from the buffer + * pool in which to do the name expansion, hence should be a power of two, + * and must be less than or equal to MAXBSIZE. MAXSYMLINKS defines the + * maximum number of symbolic links that may be expanded in a path name. + * It should be set high enough to allow all legitimate uses, but halt + * infinite loops reasonably quickly. + */ +#define MAXPATHLEN PATH_MAX +#define MAXSYMLINKS SYMLOOP_MAX + +/* Macros to set/clear/test flags. */ +#ifdef _KERNEL +#define SET(t, f) ((t) |= (f)) +#define CLR(t, f) ((t) &= ~(f)) +#define ISSET(t, f) ((t) & (f)) +#endif /* _KERNEL */ + +/* Bit map related macros. */ +#define setbit(a,i) ((a)[(i)>>3] |= 1<<((i)&(NBBY-1))) +#define clrbit(a,i) ((a)[(i)>>3] &= ~(1<<((i)&(NBBY-1)))) +#define isset(a,i) ((a)[(i)>>3] & (1<<((i)&(NBBY-1)))) +#define isclr(a,i) (((a)[(i)>>3] & (1<<((i)&(NBBY-1)))) == 0) + +/* Macros for counting and rounding. */ +#ifndef howmany +#define howmany(x, y) (((x)+((y)-1))/(y)) +#endif +#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) +#define powerof2(x) ((((x)-1)&(x))==0) + +/* Macros for min/max. */ +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define MAX(a,b) (((a)>(b))?(a):(b)) + +/* Macros for calculating the offset of a field */ +#if !defined(offsetof) && defined(_KERNEL) +#if __GNUC_PREREQ__(4, 0) +#define offsetof(s, e) __builtin_offsetof(s, e) +#else +#define offsetof(s, e) ((size_t)&((s *)0)->e) +#endif +#endif /* !defined(offsetof) && defined(_KERNEL) */ + +#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) + +/* + * Scale factor for scaled integers used to count %cpu time and load avgs. + * + * The number of CPU `tick's that map to a unique `%age' can be expressed + * by the formula (1 / (2 ^ (FSHIFT - 11))). The maximum load average that + * can be calculated (assuming 32 bits) can be closely approximated using + * the formula (2 ^ (2 * (16 - FSHIFT))) for (FSHIFT < 15). + * + * For the scheduler to maintain a 1:1 mapping of CPU `tick' to `%age', + * FSHIFT must be at least 11; this gives us a maximum load avg of ~1024. + */ +#define _FSHIFT 11 /* bits to right of fixed binary point */ +#ifdef _KERNEL +#define FSHIFT _FSHIFT +#endif +#define FSCALE (1<<_FSHIFT) + +#endif /* !_SYS_PARAM_H_ */ diff --git a/lib/libc/include/generic-openbsd/sys/pciio.h b/lib/libc/include/generic-openbsd/sys/pciio.h new file mode 100644 index 0000000000..1e3b6fcaf2 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/pciio.h @@ -0,0 +1,86 @@ +/* $OpenBSD: pciio.h,v 1.8 2020/06/22 04:11:37 dlg Exp $ */ + +/*- + * Copyright (c) 1997, Stefan Esser + * Copyright (c) 1997, 1998, 1999, Kenneth D. Merry + * 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 unmodified, 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. + * + * $FreeBSD: src/sys/sys/pciio.h,v 1.5 1999/12/08 17:44:04 ken Exp $ + * + */ + +#ifndef _SYS_PCIIO_H_ +#define _SYS_PCIIO_H_ + +#include + +struct pcisel { + u_int8_t pc_bus; /* bus number */ + u_int8_t pc_dev; /* device on this bus */ + u_int8_t pc_func; /* function on this device */ +}; + +struct pci_io { + struct pcisel pi_sel; /* device to operate on */ + int pi_reg; /* configuration register to examine */ + int pi_width; /* width (in bytes) of read or write */ + u_int32_t pi_data; /* data to write or result of read */ +}; + +struct pci_rom { + struct pcisel pr_sel; + int pr_romlen; + char *pr_rom; +}; + +struct pci_vpd_req { + struct pcisel pv_sel; + int pv_offset; + int pv_count; + uint32_t *pv_data; +}; + +struct pci_vga { + struct pcisel pv_sel; + int pv_lock; + int pv_decode; +}; + +#define PCI_VGA_UNLOCK 0x00 +#define PCI_VGA_LOCK 0x01 +#define PCI_VGA_TRYLOCK 0x02 + +#define PCI_VGA_IO_ENABLE 0x01 +#define PCI_VGA_MEM_ENABLE 0x02 + +#define PCIOCREAD _IOWR('p', 2, struct pci_io) +#define PCIOCWRITE _IOWR('p', 3, struct pci_io) +#define PCIOCGETROMLEN _IOWR('p', 4, struct pci_rom) +#define PCIOCGETROM _IOWR('p', 5, struct pci_rom) +#define PCIOCGETVGA _IOWR('p', 6, struct pci_vga) +#define PCIOCSETVGA _IOWR('p', 7, struct pci_vga) +#define PCIOCREADMASK _IOWR('p', 8, struct pci_io) +#define PCIOCGETVPD _IOWR('p', 9, struct pci_vpd_req) + +#endif /* !_SYS_PCIIO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/pclock.h b/lib/libc/include/generic-openbsd/sys/pclock.h new file mode 100644 index 0000000000..594102eb16 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/pclock.h @@ -0,0 +1,49 @@ +/* $OpenBSD: pclock.h,v 1.1 2025/05/31 10:24:50 dlg Exp $ */ + +/* + * Copyright (c) 2023 David Gwynne + * + * 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 _SYS_PCLOCK_H +#define _SYS_PCLOCK_H + +#include + +struct pc_lock { + volatile unsigned int pcl_gen; +}; + +#ifdef _KERNEL + +#define PC_LOCK_INITIALIZER() { .pcl_gen = 0 } + +void pc_lock_init(struct pc_lock *); + +/* single (non-interlocking) producer */ +unsigned int pc_sprod_enter(struct pc_lock *); +void pc_sprod_leave(struct pc_lock *, unsigned int); + +/* multiple (interlocking) producers */ +unsigned int pc_mprod_enter(struct pc_lock *); +void pc_mprod_leave(struct pc_lock *, unsigned int); + +/* consumer */ +void pc_cons_enter(struct pc_lock *, unsigned int *); +__warn_unused_result int + pc_cons_leave(struct pc_lock *, unsigned int *); + +#endif /* _KERNEL */ + +#endif /* _SYS_PCLOCK_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/percpu.h b/lib/libc/include/generic-openbsd/sys/percpu.h new file mode 100644 index 0000000000..3457bdb0f2 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/percpu.h @@ -0,0 +1,199 @@ +/* $OpenBSD: percpu.h,v 1.9 2023/09/16 09:33:27 mpi Exp $ */ + +/* + * Copyright (c) 2016 David Gwynne + * + * 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 _SYS_PERCPU_H_ +#define _SYS_PERCPU_H_ + +#ifndef CACHELINESIZE +#define CACHELINESIZE 64 +#endif + +#ifndef __upunused /* this should go in param.h */ +#ifdef MULTIPROCESSOR +#define __upunused +#else +#define __upunused __attribute__((__unused__)) +#endif +#endif + +struct cpumem { + void *mem; +}; + +struct cpumem_iter { + unsigned int cpu; +} __upunused; + +struct counters_ref { + uint64_t g; + uint64_t *c; +}; + +#ifdef _KERNEL + +#include + +struct pool; + +struct cpumem *cpumem_get(struct pool *); +void cpumem_put(struct pool *, struct cpumem *); + +struct cpumem *cpumem_malloc(size_t, int); +struct cpumem *cpumem_malloc_ncpus(struct cpumem *, size_t, int); +void cpumem_free(struct cpumem *, int, size_t); + +void *cpumem_first(struct cpumem_iter *, struct cpumem *); +void *cpumem_next(struct cpumem_iter *, struct cpumem *); + +static inline void * +cpumem_enter(struct cpumem *cm) +{ +#ifdef MULTIPROCESSOR + return (cm[cpu_number()].mem); +#else + return (cm); +#endif +} + +static inline void +cpumem_leave(struct cpumem *cm, void *mem) +{ + /* KDASSERT? */ +} + +#ifdef MULTIPROCESSOR + +#define CPUMEM_BOOT_MEMORY(_name, _sz) \ +static struct { \ + unsigned char mem[_sz]; \ + struct cpumem cpumem; \ +} __aligned(CACHELINESIZE) _name##_boot_cpumem = { \ + .cpumem = { _name##_boot_cpumem.mem } \ +} + +#define CPUMEM_BOOT_INITIALIZER(_name) \ + { &_name##_boot_cpumem.cpumem } + +#else /* MULTIPROCESSOR */ + +#define CPUMEM_BOOT_MEMORY(_name, _sz) \ +static struct { \ + unsigned char mem[_sz]; \ +} __aligned(sizeof(uint64_t)) _name##_boot_cpumem + +#define CPUMEM_BOOT_INITIALIZER(_name) \ + { (struct cpumem *)&_name##_boot_cpumem.mem } + +#endif /* MULTIPROCESSOR */ + +#define CPUMEM_FOREACH(_var, _iter, _cpumem) \ + for ((_var) = cpumem_first((_iter), (_cpumem)); \ + (_var) != NULL; \ + (_var) = cpumem_next((_iter), (_cpumem))) + +/* + * per cpu counters + */ + +struct cpumem *counters_alloc(unsigned int); +struct cpumem *counters_alloc_ncpus(struct cpumem *, unsigned int); +void counters_free(struct cpumem *, unsigned int); +void counters_read(struct cpumem *, uint64_t *, unsigned int, + uint64_t *); +void counters_zero(struct cpumem *, unsigned int); + +static inline uint64_t * +counters_enter(struct counters_ref *ref, struct cpumem *cm) +{ + ref->c = cpumem_enter(cm); +#ifdef MULTIPROCESSOR + ref->g = ++(*ref->c); /* make the generation number odd */ + membar_producer(); + return (ref->c + 1); +#else + return (ref->c); +#endif +} + +static inline void +counters_leave(struct counters_ref *ref, struct cpumem *cm) +{ +#ifdef MULTIPROCESSOR + membar_producer(); + (*ref->c) = ++ref->g; /* make the generation number even again */ +#endif + cpumem_leave(cm, ref->c); +} + +static inline void +counters_inc(struct cpumem *cm, unsigned int c) +{ + struct counters_ref ref; + uint64_t *counters; + + counters = counters_enter(&ref, cm); + counters[c]++; + counters_leave(&ref, cm); +} + +static inline void +counters_dec(struct cpumem *cm, unsigned int c) +{ + struct counters_ref ref; + uint64_t *counters; + + counters = counters_enter(&ref, cm); + counters[c]--; + counters_leave(&ref, cm); +} + +static inline void +counters_add(struct cpumem *cm, unsigned int c, uint64_t v) +{ + struct counters_ref ref; + uint64_t *counters; + + counters = counters_enter(&ref, cm); + counters[c] += v; + counters_leave(&ref, cm); +} + +static inline void +counters_pkt(struct cpumem *cm, unsigned int c, unsigned int b, uint64_t v) +{ + struct counters_ref ref; + uint64_t *counters; + + counters = counters_enter(&ref, cm); + counters[c]++; + counters[b] += v; + counters_leave(&ref, cm); +} + +#ifdef MULTIPROCESSOR +#define COUNTERS_BOOT_MEMORY(_name, _n) \ + CPUMEM_BOOT_MEMORY(_name, ((_n) + 1) * sizeof(uint64_t)) +#else +#define COUNTERS_BOOT_MEMORY(_name, _n) \ + CPUMEM_BOOT_MEMORY(_name, (_n) * sizeof(uint64_t)) +#endif + +#define COUNTERS_BOOT_INITIALIZER(_name) CPUMEM_BOOT_INITIALIZER(_name) + +#endif /* _KERNEL */ +#endif /* _SYS_PERCPU_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/pipe.h b/lib/libc/include/generic-openbsd/sys/pipe.h new file mode 100644 index 0000000000..38b442b13b --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/pipe.h @@ -0,0 +1,98 @@ +/* $OpenBSD: pipe.h,v 1.29 2022/07/09 12:48:21 visa Exp $ */ + +/* + * Copyright (c) 1996 John S. Dyson + * 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 immediately at the beginning of the file, without modification, + * 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. Absolutely no warranty of function or purpose is made by the author + * John S. Dyson. + * 4. This work was done expressly for inclusion into FreeBSD. Other use + * is allowed if this notation is included. + * 5. Modifications may be freely made to this file if the above conditions + * are met. + */ + +#ifndef _SYS_PIPE_H_ +#define _SYS_PIPE_H_ + +#ifndef _KERNEL +#include /* for struct timespec */ +#endif /* _KERNEL */ + +#include /* for struct klist */ +#include /* for struct sigio_ref */ + +/* + * Pipe buffer size, keep moderate in value, pipes take kva space. + */ +#ifndef PIPE_SIZE +#define PIPE_SIZE 16384 +#endif + +#ifndef BIG_PIPE_SIZE +#define BIG_PIPE_SIZE (64*1024) +#endif + +/* + * Pipe buffer information. + * Separate in, out, cnt are used to simplify calculations. + * Buffered write is active when the buffer.cnt field is set. + */ +struct pipebuf { + u_int cnt; /* number of chars currently in buffer */ + u_int in; /* in pointer */ + u_int out; /* out pointer */ + u_int size; /* size of buffer */ + caddr_t buffer; /* kva of buffer */ +}; + +/* + * Bits in pipe_state. + */ +#define PIPE_ASYNC 0x004 /* Async? I/O. */ +#define PIPE_WANTR 0x008 /* Reader wants some characters. */ +#define PIPE_WANTW 0x010 /* Writer wants space to put characters. */ +#define PIPE_WANTD 0x020 /* Pipe is wanted to be run-down. */ +#define PIPE_EOF 0x080 /* Pipe is in EOF condition. */ +#define PIPE_LOCK 0x100 /* Thread has exclusive I/O access. */ +#define PIPE_LWANT 0x200 /* Thread wants exclusive I/O access. */ + +struct pipe_pair; + +/* + * Per-pipe data structure. + * Two of these are linked together to produce bi-directional pipes. + * + * Locking: + * I immutable after creation + * S sigio_lock + * p pipe_lock + */ +struct pipe { + struct rwlock *pipe_lock; + struct pipebuf pipe_buffer; /* [p] data storage */ + struct klist pipe_klist; /* [p] list of knotes */ + struct timespec pipe_atime; /* [p] time of last access */ + struct timespec pipe_mtime; /* [p] time of last modify */ + struct timespec pipe_ctime; /* [I] time of status change */ + struct sigio_ref pipe_sigio; /* [S] async I/O registration */ + struct pipe *pipe_peer; /* [p] link with other direction */ + struct pipe_pair *pipe_pair; /* [I] pipe storage */ + u_int pipe_state; /* [p] pipe status info */ + int pipe_busy; /* [p] # readers/writers */ +}; + +#ifdef _KERNEL +void pipe_init(void); +#endif /* _KERNEL */ + +#endif /* !_SYS_PIPE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/pledge.h b/lib/libc/include/generic-openbsd/sys/pledge.h new file mode 100644 index 0000000000..85a1fdc64c --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/pledge.h @@ -0,0 +1,143 @@ +/* $OpenBSD: pledge.h,v 1.52 2025/07/05 09:24:37 jsg Exp $ */ + +/* + * Copyright (c) 2015 Nicholas Marriott + * Copyright (c) 2015 Theo de Raadt + * + * 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 _SYS_PLEDGE_H_ +#define _SYS_PLEDGE_H_ + +/* + * pledge(2) requests + */ +#define PLEDGE_ALWAYS 0xffffffffffffffffULL +#define PLEDGE_RPATH 0x0000000000000001ULL /* allow open for read */ +#define PLEDGE_WPATH 0x0000000000000002ULL /* allow open for write */ +#define PLEDGE_CPATH 0x0000000000000004ULL /* allow creat, mkdir, unlink etc */ +#define PLEDGE_STDIO 0x0000000000000008ULL /* operate on own pid */ +#define PLEDGE_TMPPATH 0x0000000000000010ULL /* for mk*temp() */ +#define PLEDGE_DNS 0x0000000000000020ULL /* DNS services */ +#define PLEDGE_INET 0x0000000000000040ULL /* AF_INET/AF_INET6 sockets */ +#define PLEDGE_FLOCK 0x0000000000000080ULL /* file locking */ +#define PLEDGE_UNIX 0x0000000000000100ULL /* AF_UNIX sockets */ +#define PLEDGE_ID 0x0000000000000200ULL /* allow setuid, setgid, etc */ +#define PLEDGE_TAPE 0x0000000000000400ULL /* Tape ioctl */ +#define PLEDGE_GETPW 0x0000000000000800ULL /* YP enables if ypbind.lock */ +#define PLEDGE_PROC 0x0000000000001000ULL /* fork, waitpid, etc */ +#define PLEDGE_SETTIME 0x0000000000002000ULL /* able to set/adj time/freq */ +#define PLEDGE_FATTR 0x0000000000004000ULL /* allow explicit file st_* mods */ +#define PLEDGE_PROTEXEC 0x0000000000008000ULL /* allow use of PROT_EXEC */ +#define PLEDGE_TTY 0x0000000000010000ULL /* tty setting */ +#define PLEDGE_SENDFD 0x0000000000020000ULL /* AF_UNIX CMSG fd sending */ +#define PLEDGE_RECVFD 0x0000000000040000ULL /* AF_UNIX CMSG fd receiving */ +#define PLEDGE_EXEC 0x0000000000080000ULL /* execve, child is free of pledge */ +#define PLEDGE_ROUTE 0x0000000000100000ULL /* routing lookups */ +#define PLEDGE_MCAST 0x0000000000200000ULL /* multicast joins */ +#define PLEDGE_VMINFO 0x0000000000400000ULL /* vminfo listings */ +#define PLEDGE_PS 0x0000000000800000ULL /* ps listings */ +#define PLEDGE_DISKLABEL 0x0000000002000000ULL /* disklabels */ +#define PLEDGE_PF 0x0000000004000000ULL /* pf ioctls */ +#define PLEDGE_AUDIO 0x0000000008000000ULL /* audio ioctls */ +#define PLEDGE_DPATH 0x0000000010000000ULL /* mknod & mkfifo */ +#define PLEDGE_DRM 0x0000000020000000ULL /* drm ioctls */ +#define PLEDGE_VMM 0x0000000040000000ULL /* vmm ioctls */ +#define PLEDGE_CHOWN 0x0000000080000000ULL /* chown(2) family */ +#define PLEDGE_CHOWNUID 0x0000000100000000ULL /* allow owner/group changes */ +#define PLEDGE_BPF 0x0000000200000000ULL /* bpf ioctl */ +#define PLEDGE_ERROR 0x0000000400000000ULL /* ENOSYS instead of kill */ +#define PLEDGE_WROUTE 0x0000000800000000ULL /* interface address ioctls */ +#define PLEDGE_UNVEIL 0x0000001000000000ULL /* allow unveil() */ +#define PLEDGE_VIDEO 0x0000002000000000ULL /* video ioctls */ + +/* + * Bits outside PLEDGE_USERSET are used by the kernel itself + * to track program behaviours which have been observed. + */ +#define PLEDGE_USERSET 0x0fffffffffffffffULL + +#ifdef PLEDGENAMES +static const struct { + uint64_t bits; + const char *name; +} pledgenames[] = { + { PLEDGE_STDIO, "stdio" }, + { PLEDGE_RPATH, "rpath" }, + { PLEDGE_WPATH, "wpath" }, + { PLEDGE_CPATH, "cpath" }, + { PLEDGE_DPATH, "dpath" }, + { PLEDGE_TMPPATH, "tmppath" }, + { PLEDGE_INET, "inet" }, + { PLEDGE_MCAST, "mcast" }, + { PLEDGE_FATTR, "fattr" }, + { PLEDGE_CHOWNUID, "chown" }, + { PLEDGE_FLOCK, "flock" }, + { PLEDGE_UNIX, "unix" }, + { PLEDGE_DNS, "dns" }, + { PLEDGE_GETPW, "getpw" }, + { PLEDGE_SENDFD, "sendfd" }, + { PLEDGE_RECVFD, "recvfd" }, + { PLEDGE_TAPE, "tape" }, + { PLEDGE_TTY, "tty" }, + { PLEDGE_PROC, "proc" }, + { PLEDGE_EXEC, "exec" }, + { PLEDGE_PROTEXEC, "prot_exec" }, + { PLEDGE_SETTIME, "settime" }, + { PLEDGE_PS, "ps" }, + { PLEDGE_VMINFO, "vminfo" }, + { PLEDGE_ID, "id" }, + { PLEDGE_PF, "pf" }, + { PLEDGE_ROUTE, "route" }, + { PLEDGE_WROUTE, "wroute" }, + { PLEDGE_AUDIO, "audio" }, + { PLEDGE_VIDEO, "video" }, + { PLEDGE_BPF, "bpf" }, + { PLEDGE_UNVEIL, "unveil" }, + { PLEDGE_ERROR, "error" }, + { PLEDGE_DISKLABEL, "disklabel" }, + { PLEDGE_DRM, "drm" }, + { PLEDGE_VMM, "vmm" }, + { 0, NULL }, +}; +#endif + +#ifdef _KERNEL + +int pledge_syscall(struct proc *, int, uint64_t *); +int pledge_fail(struct proc *, int, uint64_t); + +struct nameidata; +int pledge_namei(struct proc *, struct nameidata *, char *); +int pledge_sendfd(struct proc *p, struct file *); +int pledge_recvfd(struct proc *p, struct file *); +int pledge_sysctl(struct proc *p, int namelen, int *name, void *new); +int pledge_chown(struct proc *p, uid_t, gid_t); +int pledge_adjtime(struct proc *p, const void *v); +int pledge_sendit(struct proc *p, const void *to); +int pledge_sockopt(struct proc *p, int set, int level, int optname); +int pledge_socket(struct proc *p, int domain, unsigned int state); +int pledge_ioctl(struct proc *p, long com, struct file *); +int pledge_ioctl_drm(struct proc *p, long com, dev_t device); +int pledge_ioctl_vmm(struct proc *p, long com); +int pledge_ioctl_psp(struct proc *p, long com); +int pledge_flock(struct proc *p); +int pledge_fcntl(struct proc *p, int cmd); +int pledge_swapctl(struct proc *p, int cmd); +int pledge_kill(struct proc *p, pid_t pid); +int pledge_protexec(struct proc *p, int prot); + +#endif /* _KERNEL */ + +#endif /* _SYS_PLEDGE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/poll.h b/lib/libc/include/generic-openbsd/sys/poll.h new file mode 100644 index 0000000000..3536a1e546 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/poll.h @@ -0,0 +1,89 @@ +/* $OpenBSD: poll.h,v 1.16 2024/08/04 22:28:08 guenther Exp $ */ + +/* + * Copyright (c) 1996 Theo de Raadt + * 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 _SYS_POLL_H_ +#define _SYS_POLL_H_ + +typedef struct pollfd { + int fd; + short events; + short revents; +} pollfd_t; + +typedef unsigned int nfds_t; + +#define POLLIN 0x0001 +#define POLLPRI 0x0002 +#define POLLOUT 0x0004 +#define POLLERR 0x0008 +#define POLLHUP 0x0010 +#define POLLNVAL 0x0020 +#define POLLRDNORM 0x0040 +#define POLLNORM POLLRDNORM +#define POLLWRNORM POLLOUT +#define POLLRDBAND 0x0080 +#define POLLWRBAND 0x0100 +#ifdef _KERNEL +#define POLL_NOHUP 0x1000 /* internal use only */ +#endif + +#define INFTIM (-1) + +#ifndef _KERNEL +#include + +#if __POSIX_VISIBLE >= 202405 || __BSD_VISIBLE +#include + +#ifndef _SIGSET_T_DEFINED_ +#define _SIGSET_T_DEFINED_ +typedef unsigned int sigset_t; +#endif + +#ifndef _TIME_T_DEFINED_ +#define _TIME_T_DEFINED_ +typedef __time_t time_t; +#endif + +#ifndef _TIMESPEC_DECLARED +#define _TIMESPEC_DECLARED +struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +}; +#endif +#endif /* __BSD_VISIBLE */ + +__BEGIN_DECLS +int poll(struct pollfd[], nfds_t, int); +#if __POSIX_VISIBLE >= 202405 || __BSD_VISIBLE +int ppoll(struct pollfd[], nfds_t, const struct timespec * __restrict, const sigset_t * __restrict); +#endif /* __BSD_VISIBLE */ +__END_DECLS +#endif /* _KERNEL */ + +#endif /* !_SYS_POLL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/pool.h b/lib/libc/include/generic-openbsd/sys/pool.h new file mode 100644 index 0000000000..2a5ad6354d --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/pool.h @@ -0,0 +1,287 @@ +/* $OpenBSD: pool.h,v 1.81 2025/05/21 09:33:49 mvs Exp $ */ +/* $NetBSD: pool.h,v 1.27 2001/06/06 22:00:17 rafal Exp $ */ + +/*- + * Copyright (c) 1997, 1998, 1999, 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Paul Kranenburg; by Jason R. Thorpe of the Numerical Aerospace + * Simulation Facility, NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_POOL_H_ +#define _SYS_POOL_H_ + +/* + * sysctls. + * kern.pool.npools + * kern.pool.name. + * kern.pool.pool. + */ +#define KERN_POOL_NPOOLS 1 +#define KERN_POOL_NAME 2 +#define KERN_POOL_POOL 3 +#define KERN_POOL_CACHE 4 /* global pool cache info */ +#define KERN_POOL_CACHE_CPUS 5 /* all cpus cache info */ + +struct kinfo_pool { + unsigned int pr_size; /* size of a pool item */ + unsigned int pr_pgsize; /* size of a "page" */ + unsigned int pr_itemsperpage; /* number of items per "page" */ + unsigned int pr_minpages; /* same in page units */ + unsigned int pr_maxpages; /* maximum # of idle pages to keep */ + unsigned int pr_hardlimit; /* hard limit to number of allocated + items */ + + unsigned int pr_npages; /* # of pages allocated */ + unsigned int pr_nout; /* # items currently allocated */ + unsigned int pr_nitems; /* # items in the pool */ + + unsigned long pr_nget; /* # of successful requests */ + unsigned long pr_nput; /* # of releases */ + unsigned long pr_nfail; /* # of unsuccessful requests */ + unsigned long pr_npagealloc; /* # of pages allocated */ + unsigned long pr_npagefree; /* # of pages released */ + unsigned int pr_hiwat; /* max # of pages in pool */ + unsigned long pr_nidle; /* # of idle pages */ +}; + +struct kinfo_pool_cache { + uint64_t pr_ngc; /* # of times a list has been gc'ed */ + unsigned int pr_len; /* current target for list len */ + unsigned int pr_nitems; /* # of idle items in the depot */ + unsigned int pr_contention; /* # of times mtx was busy */ +}; + +/* + * KERN_POOL_CACHE_CPUS provides an array, not a single struct. ie, it + * provides struct kinfo_pool_cache_cpu kppc[ncpusfound]. + */ +struct kinfo_pool_cache_cpu { + unsigned int pr_cpu; /* which cpu this cache is on */ + + /* counters for times items were handled by the cache */ + uint64_t pr_nget; /* # of requests */ + uint64_t pr_nfail; /* # of unsuccessful requests */ + uint64_t pr_nput; /* # of releases */ + + /* counters for times the cache interacted with the pool */ + uint64_t pr_nlget; /* # of list requests */ + uint64_t pr_nlfail; /* # of unsuccessful list requests */ + uint64_t pr_nlput; /* # of list releases */ +}; + +#if defined(_KERNEL) || defined(_LIBKVM) + +#include +#include +#include +#include + +struct pool; +struct pool_request; +struct pool_lock_ops; +TAILQ_HEAD(pool_requests, pool_request); + +struct pool_allocator { + void *(*pa_alloc)(struct pool *, int, int *); + void (*pa_free)(struct pool *, void *); + size_t pa_pagesz; +}; + +/* + * The pa_pagesz member encodes the sizes of pages that can be + * provided by the allocator, and whether the allocations can be + * aligned to their size. + * + * Page sizes can only be powers of two. Each available page size is + * represented by its value set as a bit. e.g., to indicate that an + * allocator can provide 16k and 32k pages you initialise pa_pagesz + * to (32768 | 16384). + * + * If the allocator can provide aligned pages the low bit in pa_pagesz + * is set. The POOL_ALLOC_ALIGNED macro is provided as a convenience. + * + * If pa_pagesz is unset (i.e. 0), POOL_ALLOC_DEFAULT will be used + * instead. + */ + +#define POOL_ALLOC_ALIGNED 1UL +#define POOL_ALLOC_SIZE(_sz, _a) ((_sz) | (_a)) +#define POOL_ALLOC_SIZES(_min, _max, _a) \ + ((_max) | \ + (((_max) - 1) & ~((_min) - 1)) | (_a)) + +#define POOL_ALLOC_DEFAULT \ + POOL_ALLOC_SIZE(PAGE_SIZE, POOL_ALLOC_ALIGNED) + +TAILQ_HEAD(pool_pagelist, pool_page_header); + +struct pool_cache_item; +TAILQ_HEAD(pool_cache_lists, pool_cache_item); +struct cpumem; + +union pool_lock { + struct mutex prl_mtx; + struct rwlock prl_rwlock; +}; + +struct pool { + struct refcnt pr_refcnt; + union pool_lock pr_lock; + const struct pool_lock_ops * + pr_lock_ops; + SIMPLEQ_ENTRY(pool) + pr_poollist; + struct pool_pagelist + pr_emptypages; /* Empty pages */ + struct pool_pagelist + pr_fullpages; /* Full pages */ + struct pool_pagelist + pr_partpages; /* Partially-allocated pages */ + struct pool_page_header * + pr_curpage; + unsigned int pr_size; /* Size of item */ + unsigned int pr_minitems; /* minimum # of items to keep */ + unsigned int pr_minpages; /* same in page units */ + unsigned int pr_maxpages; /* maximum # of idle pages to keep */ + unsigned int pr_npages; /* # of pages allocated */ + unsigned int pr_itemsperpage;/* # items that fit in a page */ + unsigned int pr_slack; /* unused space in a page */ + unsigned int pr_nitems; /* number of available items in pool */ + unsigned int pr_nout; /* # items currently allocated */ + unsigned int pr_hardlimit; /* hard limit to number of allocated + items */ + unsigned int pr_serial; /* unique serial number of the pool */ + unsigned int pr_pgsize; /* Size of a "page" */ + vaddr_t pr_pgmask; /* Mask with an item to get a page */ + struct pool_allocator * + pr_alloc; /* backend allocator */ + const char * pr_wchan; /* tsleep(9) identifier */ +#define PR_WAITOK 0x0001 /* M_WAITOK */ +#define PR_NOWAIT 0x0002 /* M_NOWAIT */ +#define PR_LIMITFAIL 0x0004 /* M_CANFAIL */ +#define PR_ZERO 0x0008 /* M_ZERO */ +#define PR_RWLOCK 0x0010 +#define PR_WANTED 0x0100 + + int pr_flags; + int pr_ipl; + + RBT_HEAD(phtree, pool_page_header) + pr_phtree; + + struct cpumem * pr_cache; + unsigned long pr_cache_magic[2]; + union pool_lock pr_cache_lock; + struct pool_cache_lists + pr_cache_lists; /* list of idle item lists */ + u_int pr_cache_nitems; /* # of idle items */ + u_int pr_cache_items; /* target list length */ + u_int pr_cache_contention; + u_int pr_cache_contention_prev; + uint64_t pr_cache_timestamp; /* time idle list was empty */ + uint64_t pr_cache_ngc; /* # of times the gc released a list */ + int pr_cache_nout; + + u_int pr_align; + u_int pr_maxcolors; /* Cache coloring */ + int pr_phoffset; /* Offset in page of page header */ + + /* + * pool item requests queue + */ + union pool_lock pr_requests_lock; + struct pool_requests + pr_requests; + unsigned int pr_requesting; + + /* + * Instrumentation + */ + unsigned long pr_nget; /* # of successful requests */ + unsigned long pr_nfail; /* # of unsuccessful requests */ + unsigned long pr_nput; /* # of releases */ + unsigned long pr_npagealloc; /* # of pages allocated */ + unsigned long pr_npagefree; /* # of pages released */ + unsigned int pr_hiwat; /* max # of pages in pool */ + unsigned long pr_nidle; /* # of idle pages */ + + /* Physical memory configuration. */ + const struct kmem_pa_mode * + pr_crange; +}; + +#endif /* _KERNEL || _LIBKVM */ + +#ifdef _KERNEL + +extern struct pool_allocator pool_allocator_single; +extern struct pool_allocator pool_allocator_multi; + +struct pool_request { + TAILQ_ENTRY(pool_request) pr_entry; + void (*pr_handler)(struct pool *, void *, void *); + void *pr_cookie; + void *pr_item; +}; + +void pool_init(struct pool *, size_t, u_int, int, int, + const char *, struct pool_allocator *); +void pool_cache_init(struct pool *); +void pool_destroy(struct pool *); +void pool_setlowat(struct pool *, int); +void pool_sethiwat(struct pool *, int); +int pool_sethardlimit(struct pool *, u_int); +void pool_set_constraints(struct pool *, + const struct kmem_pa_mode *mode); + +void *pool_get(struct pool *, int) __malloc; +void pool_request_init(struct pool_request *, + void (*)(struct pool *, void *, void *), void *); +void pool_request(struct pool *, struct pool_request *); +void pool_put(struct pool *, void *); +void pool_wakeup(struct pool *); +int pool_reclaim(struct pool *); +void pool_reclaim_all(void); +int pool_prime(struct pool *, int); + +#ifdef DDB +/* + * Debugging and diagnostic aides. + */ +void pool_printit(struct pool *, const char *, + int (*)(const char *, ...)); +void pool_walk(struct pool *, int, int (*)(const char *, ...), + void (*)(void *, int, int (*)(const char *, ...))); +#endif + +/* the allocator for dma-able memory is a thin layer on top of pool */ +void dma_alloc_init(void); +void *dma_alloc(size_t size, int flags); +void dma_free(void *m, size_t size); +#endif /* _KERNEL */ + +#endif /* _SYS_POOL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/proc.h b/lib/libc/include/generic-openbsd/sys/proc.h new file mode 100644 index 0000000000..e1d6e62bbc --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/proc.h @@ -0,0 +1,678 @@ +/* $OpenBSD: proc.h,v 1.397 2025/08/18 04:15:35 dlg Exp $ */ +/* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */ + +/*- + * Copyright (c) 1986, 1989, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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 8.8 (Berkeley) 1/21/94 + */ + +#ifndef _SYS_PROC_H_ +#define _SYS_PROC_H_ + +#include /* Machine-dependent proc substruct. */ +#include /* For struct selinfo */ +#include /* For LOGIN_NAME_MAX */ +#include +#include /* For struct timeout */ +#include /* For struct klist */ +#include /* For struct mutex */ +#include /* For struct rusage */ +#include /* For struct rwlock */ +#include /* For struct sigio */ +#include /* For struct refcnt */ +#include + +#ifdef _KERNEL +#include +#define __need_process +#endif + +/* + * One structure allocated per session. + */ +struct process; +struct session { + int s_count; /* Ref cnt; pgrps in session. */ + struct process *s_leader; /* Session leader. */ + struct vnode *s_ttyvp; /* Vnode of controlling terminal. */ + struct tty *s_ttyp; /* Controlling terminal. */ + char s_login[LOGIN_NAME_MAX]; /* Setlogin() name. */ + pid_t s_verauthppid; + uid_t s_verauthuid; + struct timeout s_verauthto; +}; + +void zapverauth(/* struct session */ void *); + +/* + * One structure allocated per process group. + */ +struct pgrp { + LIST_ENTRY(pgrp) pg_hash; /* Hash chain. */ + LIST_HEAD(, process) pg_members;/* Pointer to pgrp members. */ + struct session *pg_session; /* Pointer to session. */ + struct sigiolst pg_sigiolst; /* List of sigio structures. */ + pid_t pg_id; /* Pgrp id. */ + int pg_jobc; /* # procs qualifying pgrp for job control */ +}; + +/* + * time usage: accumulated times in ticks + * Each thread is immediately accumulated here. For processes only the + * time of exited threads is accumulated and to get the proper process + * time usage tuagg_get_process() needs to be called. + * Accounting of threads is done lockless by curproc using the tu_pcl + * pc_lock. Code should use tu_enter() and tu_leave() for this. + * The process ps_tu structure is locked by the ps_mtx. + */ +#define TU_UTICKS 0 /* Statclock hits in user mode. */ +#define TU_STICKS 1 /* Statclock hits in system mode. */ +#define TU_ITICKS 2 /* Statclock hits processing intr. */ +#define TU_TICKS_COUNT 3 + +struct tusage { + struct pc_lock tu_pcl; + uint64_t tu_ticks[TU_TICKS_COUNT]; +#define tu_uticks tu_ticks[TU_UTICKS] +#define tu_sticks tu_ticks[TU_STICKS] +#define tu_iticks tu_ticks[TU_ITICKS] + uint64_t tu_ixrss; + uint64_t tu_idrss; + uint64_t tu_isrss; + struct timespec tu_runtime; /* Realtime. */ +}; + +/* + * Description of a process. + * + * These structures contain the information needed to manage a thread of + * control, known in UN*X as a process; it has references to substructures + * containing descriptions of things that the process uses, but may share + * with related processes. + * + * struct process is the higher level process containing information + * shared by all threads in a process, while struct proc contains the + * run-time information needed by threads. + */ +#ifdef __need_process +struct proc; +struct unveil; + +struct pinsyscall { + vaddr_t pn_start; + vaddr_t pn_end; + u_int *pn_pins; /* array of offsets indexed by syscall# */ + int pn_npins; /* number of entries in table */ +}; + +/* + * Locks used to protect struct members in this file: + * I immutable after creation + * a atomic operations + * K kernel lock + * m this process' `ps_mtx' + * p this process' `ps_lock' + * Q kqueue_ps_list_lock + * R rlimit_lock + * S scheduler lock + * T itimer_mtx + */ +struct process { + struct refcnt ps_refcnt; + + /* + * ps_mainproc is the original thread in the process. + * It's only still special for the handling of + * some signal and ptrace behaviors that need to be fixed. + */ + struct proc *ps_mainproc; + struct ucred *ps_ucred; /* Process owner's identity. */ + + LIST_ENTRY(process) ps_list; /* List of all processes. */ + TAILQ_HEAD(,proc) ps_threads; /* [K|m] Threads in this process. */ + + LIST_ENTRY(process) ps_pglist; /* List of processes in pgrp. */ + struct process *ps_pptr; /* [K|m] Pointer to parent process. */ + LIST_ENTRY(process) ps_sibling; /* List of sibling processes. */ + LIST_HEAD(, process) ps_children;/* Pointer to list of children. */ + LIST_ENTRY(process) ps_hash; /* Hash chain. */ + + /* + * An orphan is the child that has been re-parented to the + * debugger as a result of attaching to it. Need to keep + * track of them for parent to be able to collect the exit + * status of what used to be children. + */ + LIST_ENTRY(process) ps_orphan; /* List of orphan processes. */ + LIST_HEAD(, process) ps_orphans;/* Pointer to list of orphans. */ + + struct sigiolst ps_sigiolst; /* List of sigio structures. */ + struct sigacts *ps_sigacts; /* [I] Signal actions, state */ + struct vnode *ps_textvp; /* Vnode of executable. */ + struct filedesc *ps_fd; /* Ptr to open files structure */ + struct vmspace *ps_vmspace; /* Address space */ + pid_t ps_pid; /* [I] Process identifier. */ + + struct rwlock ps_lock; /* per-process rwlock */ + struct mutex ps_mtx; /* per-process mutex */ + +/* The following fields are all zeroed upon creation in process_new. */ +#define ps_startzero ps_klist + struct klist ps_klist; /* [Q,m] knotes attached to process */ + u_int ps_flags; /* [a] PS_* flags. */ + int ps_siglist; /* Signals pending for the process. */ + + struct proc *ps_single; /* [m] Thread for single-threading. */ + struct proc *ps_trapped; /* [m] Thread trapped for ptrace. */ + u_int ps_suspendcnt; /* [m] Number of threads to suspend. */ + u_int ps_exitcnt; /* [m] Number of threads in exit1. */ + + int ps_traceflag; /* Kernel trace points. */ + struct vnode *ps_tracevp; /* Trace to vnode. */ + struct ucred *ps_tracecred; /* Creds for writing trace */ + + u_int ps_xexit; /* Exit status for wait */ + int ps_xsig; /* Stopping or killing signal */ + + pid_t ps_ppid; /* [K|m] Cached parent pid */ + int ps_ptmask; /* Ptrace event mask */ + struct ptrace_state *ps_ptstat;/* Ptrace state */ + struct process *ps_opptr; /* [K|m] Old parent during ptrace. */ + + struct rusage *ps_ru; /* sum of stats for dead threads. */ + struct tusage ps_tu; /* [m] accumul times of dead threads. */ + struct rusage ps_cru; /* sum of stats for reaped children */ + struct itimerspec ps_timer[3]; /* [m] ITIMER_REAL timer */ + /* [T] ITIMER_{VIRTUAL,PROF} timers */ + struct timeout ps_rucheck_to; /* [] resource limit check timer */ + time_t ps_nextxcpu; /* when to send next SIGXCPU, */ + /* in seconds of process runtime */ + + u_int64_t ps_wxcounter; + + struct unveil *ps_uvpaths; /* unveil vnodes and names */ + ssize_t ps_uvvcount; /* count of unveil vnodes held */ + size_t ps_uvncount; /* count of unveil names allocated */ + int ps_uvdone; /* no more unveil is permitted */ + +/* End area that is zeroed on creation. */ +#define ps_endzero ps_startcopy + +/* The following fields are all copied upon creation in process_new. */ +#define ps_startcopy ps_limit + struct plimit *ps_limit; /* [m,R] Process limits. */ + struct pgrp *ps_pgrp; /* [K|m] Pointer to process group. */ + + char ps_comm[_MAXCOMLEN]; /* command name, incl NUL */ + + vaddr_t ps_strings; /* User pointers to argv/env */ + vaddr_t ps_auxinfo; /* User pointer to auxinfo */ + vaddr_t ps_timekeep; /* User pointer to timekeep */ + vaddr_t ps_sigcode; /* [I] User pointer to signal code */ + vaddr_t ps_sigcoderet; /* [I] User ptr to sigreturn retPC */ + u_long ps_sigcookie; /* [I] */ + u_int ps_rtableid; /* [a] Process routing table/domain. */ + u_short ps_iflags; /* [I] flags set at exec time */ +# define PSI_WXNEEDED 0x0001 /* Process allowed to violate W^X */ +# define PSI_NOBTCFI 0x0002 /* No Branch Target CFI */ +# define PSI_PROFILE 0x0004 /* linked with -pg: allow profile(2) */ +# define PSI_BITS \ + ("\20" "\001WXNEEDED" "\002NOBTCFI" "\003PROFILE" ) + char ps_nice; /* Process "nice" value. */ + + struct uprof { /* profile arguments */ + caddr_t pr_base; /* sample buffer base */ + size_t pr_size; /* sample buffer size */ + u_long pr_off; /* pc offset */ + u_int pr_scale; /* pc scaling */ + char *pr_buf; /* total memory buffer */ + size_t pr_buflen; /* ... length */ + struct ucred *pr_ucred; /* cred at first profil(2) call */ + struct vnode *pr_cdir; /* cwd at first profil(2) call */ + } ps_prof; + + u_int32_t ps_acflag; /* Accounting flags. */ + + uint64_t ps_pledge; /* [m] pledge promises */ + uint64_t ps_execpledge; /* [m] execpledge promises */ + + int64_t ps_kbind_cookie; /* [m] */ + u_long ps_kbind_addr; /* [m] */ +/* an address that can't be in userspace or kernelspace */ +#define BOGO_PC (u_long)-1 + + struct pinsyscall ps_pin; /* static or ld.so */ + struct pinsyscall ps_libcpin; /* libc.so, from pinsyscalls(2) */ + +/* End area that is copied on creation. */ +#define ps_endcopy ps_threadcnt + u_int ps_threadcnt; /* [m] Number of threads. */ + + struct timespec ps_start; /* starting uptime. */ + struct timeout ps_realit_to; /* [m] ITIMER_REAL timeout */ +}; + +#define ps_session ps_pgrp->pg_session +#define ps_pgid ps_pgrp->pg_id + +#endif /* __need_process */ + +/* + * These flags are kept in ps_flags. + * + * When adding a new flag, carefully consider whether it should be + * added to PS_FLAGS_INHERITED_ON_FORK. + */ +#define PS_CONTROLT 0x00000001 /* Has a controlling terminal. */ +#define PS_EXEC 0x00000002 /* Process called exec. */ +#define PS_INEXEC 0x00000004 /* Process is doing an exec right now */ +#define PS_EXITING 0x00000008 /* Process is exiting. */ +#define PS_SUGID 0x00000010 /* Had set id privs since last exec. */ +#define PS_SUGIDEXEC 0x00000020 /* last execve() was set[ug]id */ +#define PS_PPWAIT 0x00000040 /* Parent waits for exec/exit. */ +#define PS_ISPWAIT 0x00000080 /* Is parent of PPWAIT child. */ +#define PS_PROFIL 0x00000100 /* Has started profiling. */ +#define PS_TRACED 0x00000200 /* Being ptraced. */ +#define PS_WAITED 0x00000400 /* Stopped proc was waited for. */ +#define PS_COREDUMP 0x00000800 /* Busy coredumping */ +#define PS_SINGLEEXIT 0x00001000 /* Other threads must die. */ +#define PS_SINGLEUNWIND 0x00002000 /* Other threads must unwind. */ +#define PS_NOZOMBIE 0x00004000 /* No signal or zombie at exit. */ +#define PS_STOPPING 0x00008000 /* Just stopped, need sig to parent. */ +#define PS_SYSTEM 0x00010000 /* No sigs, stats or swapping. */ +#define PS_EMBRYO 0x00020000 /* New process, not yet fledged */ +#define PS_ZOMBIE 0x00040000 /* Dead and ready to be waited for */ +#define PS_NOBROADCASTKILL 0x00080000 /* Process excluded from kill -1. */ +#define PS_PLEDGE 0x00100000 /* Has called pledge(2) */ +#define PS_avail2 0x00200000 +#define PS_EXECPLEDGE 0x00400000 /* Has exec pledges */ +#define PS_ORPHAN 0x00800000 /* Process is on an orphan list */ +#define PS_CHROOT 0x01000000 /* Process is chrooted */ +#define PS_avail1 0x02000000 +#define PS_ITIMER 0x04000000 /* Virtual interval timers running */ +#define PS_avail0 0x08000000 +#define PS_WAITEVENT 0x10000000 /* wait(2) event pending */ +#define PS_CONTINUED 0x20000000 /* Continued proc not yet waited for */ +#define PS_STOPPED 0x40000000 /* Stopped process */ +#define PS_TRAPPED 0x80000000 /* Stopped due to tracing event */ + +#define PS_BITS \ + ("\20" "\01CONTROLT" "\02EXEC" "\03INEXEC" "\04EXITING" "\05SUGID" \ + "\06SUGIDEXEC" "\07PPWAIT" "\010ISPWAIT" "\011PROFIL" "\012TRACED" \ + "\013WAITED" "\014COREDUMP" "\015SINGLEEXIT" "\016SINGLEUNWIND" \ + "\017NOZOMBIE" "\020STOPPING" "\021SYSTEM" "\022EMBRYO" "\023ZOMBIE" \ + "\024NOBROADCASTKILL" "\025PLEDGE" "\027EXECPLEDGE" \ + "\030ORPHAN" "\031CHROOT" "\033ITIMER" \ + "\035WAITEVENT" "\036CONTINUED" "\037STOPPED" "\040TRAPPED") + +#define PS_FLAGS_INHERITED_ON_FORK \ + (PS_SUGID | PS_SUGIDEXEC | PS_PLEDGE | PS_EXECPLEDGE | PS_CHROOT) + +struct kcov_dev; +struct lock_list_entry; +struct kqueue; + +struct p_inentry { + u_long ie_serial; + vaddr_t ie_start; + vaddr_t ie_end; +}; + +/* + * Locks used to protect struct members in this file: + * I immutable after creation + * S scheduler lock + * U uidinfolk + * l read only reference, see lim_read_enter() + * o owned (modified only) by this thread + * m this proc's' `p->p_p->ps_mtx' + */ +struct proc { + TAILQ_ENTRY(proc) p_runq; /* [S] current run/sleep queue */ + LIST_ENTRY(proc) p_list; /* List of all threads. */ + + struct process *p_p; /* [I] The process of this thread. */ + TAILQ_ENTRY(proc) p_thr_link; /* [K|m] Threads in a process linkage. */ + + /* substructures: */ + struct filedesc *p_fd; /* copy of p_p->ps_fd */ + struct vmspace *p_vmspace; /* [I] copy of p_p->ps_vmspace */ + struct p_inentry p_spinentry; /* [o] cache for SP check */ + + int p_flag; /* P_* flags. */ + u_char p_spare; /* unused */ + char p_stat; /* [S] S* process status. */ + u_char p_runpri; /* [S] Runqueue priority */ + u_char p_descfd; /* if not 255, fdesc permits this fd */ + + pid_t p_tid; /* Thread identifier. */ + LIST_ENTRY(proc) p_hash; /* Hash chain. */ + +/* The following fields are all zeroed upon creation in fork. */ +#define p_startzero p_dupfd + int p_dupfd; /* Sideways return value from filedescopen. XXX */ + + /* scheduling */ + unsigned int p_cpticks; /* [o] Ticks of cpu time. */ + unsigned int p_cpticks2; /* [K] last times ticks */ + const volatile void *p_wchan; /* [S] Sleep address. */ + struct timeout p_sleep_to;/* timeout for tsleep() */ + const char *p_wmesg; /* [S] Reason for sleep. */ + volatile fixpt_t p_pctcpu; /* [a] %cpu for this thread */ + u_int p_slptime; /* [S] Time since last blocked. */ + struct cpu_info * volatile p_cpu; /* [S] CPU we're running on. */ + + struct rusage p_ru; /* Statistics */ + struct tusage p_tu; /* [o] accumulated times. */ + + struct plimit *p_limit; /* [l] read ref. of p_p->ps_limit */ + struct kcov_dev *p_kd; /* kcov device handle */ + struct lock_list_entry *p_sleeplocks; /* WITNESS lock tracking */ + struct kqueue *p_kq; /* [o] select/poll queue of evts */ + unsigned long p_kq_serial; /* [o] to check against enqueued evts */ + + int p_siglist; /* [a] Signals arrived & not delivered*/ + +/* End area that is zeroed on creation. */ +#define p_endzero p_startcopy + +/* The following fields are all copied upon creation in fork. */ +#define p_startcopy p_sigmask + sigset_t p_sigmask; /* [o] Current signal mask */ + + char p_name[_MAXCOMLEN]; /* thread name, incl NUL */ + u_char p_slppri; /* [S] Sleeping priority */ + u_char p_usrpri; /* [S] Priority based on p_estcpu & ps_nice */ + u_int p_estcpu; /* [S] Time averaged val of p_cpticks */ + int p_pledge_syscall; /* Cache of current syscall */ + uint64_t p_pledge; /* [o] copy of p_p->ps_pledge */ + + struct ucred *p_ucred; /* [o] cached credentials */ + struct sigaltstack p_sigstk; /* sp & on stack state variable */ + + u_long p_prof_addr; /* tmp storage for profiling addr until AST */ + u_long p_prof_ticks; /* tmp storage for profiling ticks until AST */ + +/* End area that is copied on creation. */ +#define p_endcopy p_addr + struct user *p_addr; /* Kernel virtual addr of u-area */ + struct mdproc p_md; /* Any machine-dependent fields. */ + + sigset_t p_oldmask; /* [o] Saved mask from before sigpause */ + int p_sisig; /* For core dump/debugger XXX */ + union sigval p_sigval; /* For core dump/debugger XXX */ + long p_sitrapno; /* For core dump/debugger XXX */ + int p_sicode; /* For core dump/debugger XXX */ +}; + +/* Status values. */ +#define SIDL 1 /* Thread being created by fork. */ +#define SRUN 2 /* Currently runnable. */ +#define SSLEEP 3 /* Sleeping on an address. */ +#define SSTOP 4 /* Debugging or suspension. */ +#define SZOMB 5 /* unused */ +#define SDEAD 6 /* Thread is almost gone */ +#define SONPROC 7 /* Thread is currently on a CPU. */ + +#define P_HASSIBLING(p) ((p)->p_p->ps_threadcnt > 1) + +/* + * These flags are per-thread and kept in p_flag + */ +#define P_INKTR 0x00000001 /* In a ktrace op, don't recurse */ +#define P_PROFPEND 0x00000002 /* SIGPROF needs to be posted */ +#define P_ALRMPEND 0x00000004 /* SIGVTALRM needs to be posted */ +#define P_SIGSUSPEND 0x00000008 /* Need to restore before-suspend mask*/ +#define P_CANTSLEEP 0x00000010 /* insomniac thread */ +#define P_INSCHED 0x00000020 /* Switching scheduler state. */ +#define P_SINTR 0x00000080 /* Sleep is interruptible. */ +#define P_SYSTEM 0x00000200 /* No sigs, stats or swapping. */ +#define P_TIMEOUT 0x00000400 /* Timing out during sleep. */ +#define P_TIMEOUTRAN 0x00000800 /* Timeout handler has finished. */ +#define P_TRACESINGLE 0x00001000 /* Ptrace: keep single threaded. */ +#define P_WEXIT 0x00002000 /* Working on exiting. */ +#define P_OWEUPC 0x00008000 /* Owe proc an addupc() at next ast. */ +#define P_SUSPSINGLE 0x00080000 /* Need to stop for single threading. */ +#define P_THREAD 0x04000000 /* Only a thread, not a real process */ +#define P_SUSPSIG 0x08000000 /* Stopped from signal. */ +#define P_CPUPEG 0x40000000 /* Do not move to another cpu. */ + +#define P_BITS \ + ("\20" "\01INKTR" "\02PROFPEND" "\03ALRMPEND" "\04SIGSUSPEND" \ + "\05CANTSLEEP" "\06INSCHED" "\010SINTR" "\012SYSTEM" "\013TIMEOUT" \ + "\014TIMEOUTRAN" \ + "\015TRACESINGLE" "\016WEXIT" "\020OWEUPC" "\024SUSPSINGLE" \ + "\033THREAD" "\034SUSPSIG" "\037CPUPEG") + +#define THREAD_PID_OFFSET 100000 + +#ifdef _KERNEL + +struct uidinfo { + LIST_ENTRY(uidinfo) ui_hash; /* [U] */ + uid_t ui_uid; /* [I] */ + long ui_proccnt; /* [U] proc structs */ + long ui_lockcnt; /* [U] lockf structs */ +}; + +struct uidinfo *uid_find(uid_t); +void uid_release(struct uidinfo *); + +/* + * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t, + * as it is used to represent "no process group". + * We set PID_MAX to 99999 to keep it in 5 columns in ps + * When exposed to userspace, thread IDs have THREAD_PID_OFFSET + * added to keep them from overlapping the PID range. For them, + * we use a * a (0 .. 2^n] range for cheapness, picking 'n' such + * that 2^n + THREAD_PID_OFFSET and THREAD_PID_OFFSET have + * the same number of columns when printed. + */ +#define PID_MAX 99999 +#define TID_MASK 0x7ffff + +#define NO_PID (PID_MAX+1) + +#define SESS_LEADER(pr) ((pr)->ps_session->s_leader == (pr)) +#define SESSHOLD(s) ((s)->s_count++) +#define SESSRELE(s) do { \ + if (--(s)->s_count == 0) { \ + timeout_del(&(s)->s_verauthto); \ + pool_put(&session_pool, (s)); \ + } \ +} while (/* CONSTCOND */ 0) + +/* + * Flags to fork1(). + */ +#define FORK_FORK 0x00000001 +#define FORK_VFORK 0x00000002 +#define FORK_IDLE 0x00000004 +#define FORK_PPWAIT 0x00000008 +#define FORK_SHAREFILES 0x00000010 +#define FORK_SYSTEM 0x00000020 +#define FORK_NOZOMBIE 0x00000040 +#define FORK_SHAREVM 0x00000080 +#define FORK_PTRACE 0x00000400 + +#define EXIT_NORMAL 0x00000001 +#define EXIT_THREAD 0x00000002 +#define EXIT_THREAD_NOCHECK 0x00000003 + +#define TIDHASH(tid) (&tidhashtbl[(tid) & tidhash]) +extern LIST_HEAD(tidhashhead, proc) *tidhashtbl; +extern u_long tidhash; + +#define PIDHASH(pid) (&pidhashtbl[(pid) & pidhash]) +extern LIST_HEAD(pidhashhead, process) *pidhashtbl; +extern u_long pidhash; + +#define PGRPHASH(pgid) (&pgrphashtbl[(pgid) & pgrphash]) +extern LIST_HEAD(pgrphashhead, pgrp) *pgrphashtbl; +extern u_long pgrphash; + +extern struct proc proc0; /* Process slot for swapper. */ +extern struct process process0; /* Process slot for kernel threads. */ +extern int nprocesses, maxprocess; /* Cur and max number of processes. */ +extern int nthreads, maxthread; /* Cur and max number of threads. */ + +LIST_HEAD(proclist, proc); +LIST_HEAD(processlist, process); +extern struct processlist allprocess; /* List of all processes. */ +extern struct processlist zombprocess; /* List of zombie processes. */ +extern struct proclist allproc; /* List of all threads. */ + +extern struct process *initprocess; /* Process slot for init. */ +extern struct proc *reaperproc; /* Thread slot for reaper. */ +extern struct proc *syncerproc; /* filesystem syncer daemon */ + +extern struct pool process_pool; /* memory pool for processes */ +extern struct pool proc_pool; /* memory pool for procs */ +extern struct pool rusage_pool; /* memory pool for zombies */ +extern struct pool ucred_pool; /* memory pool for ucreds */ +extern struct pool session_pool; /* memory pool for sessions */ +extern struct pool pgrp_pool; /* memory pool for pgrps */ + +void freepid(pid_t); + +struct process *prfind(pid_t); /* Find process by id. */ +struct process *zombiefind(pid_t); /* Find zombie process by id. */ +struct proc *tfind(pid_t); /* Find thread by id. */ +struct pgrp *pgfind(pid_t); /* Find process group by id. */ +struct proc *tfind_user(pid_t, struct process *); + /* Find thread by userspace id. */ +void proc_printit(struct proc *p, const char *modif, + int (*pr)(const char *, ...)); + +int chgproccnt(uid_t uid, int diff); +void enternewpgrp(struct process *, struct pgrp *, struct session *); +void enterthispgrp(struct process *, struct pgrp *); +int inferior(struct process *, struct process *); +void leavepgrp(struct process *); +void killjobc(struct process *); +void preempt(void); +void procinit(void); +void setpriority(struct proc *, uint32_t, uint8_t); +void setrunnable(struct proc *); +void endtsleep(void *); +int wakeup_proc(struct proc *); +void unsleep(struct proc *); +void reaper(void *); +__dead void exit1(struct proc *, int, int, int); +void exit2(struct proc *); +void cpu_fork(struct proc *_curp, struct proc *_child, void *_stack, + void *_tcb, void (*_func)(void *), void *_arg); +void cpu_exit(struct proc *); +void process_initialize(struct process *, struct proc *); +int fork1(struct proc *_curp, int _flags, void (*_func)(void *), + void *_arg, register_t *_retval, struct proc **_newprocp); +int thread_fork(struct proc *_curp, void *_stack, void *_tcb, + pid_t *_tidptr, register_t *_retval); +int groupmember(gid_t, struct ucred *); +void dorefreshcreds(struct process *, struct proc *); +void dosigsuspend(struct proc *, sigset_t); + +static inline void +refreshcreds(struct proc *p) +{ + struct process *pr = p->p_p; + + /* this is an unlocked access to ps_ucred, but the result is benign */ + if (pr->ps_ucred != p->p_ucred) + dorefreshcreds(pr, p); +} + +#define SINGLE_SUSPEND 0x01 /* other threads to stop wherever they are */ +#define SINGLE_UNWIND 0x02 /* other threads to unwind and stop */ +#define SINGLE_EXIT 0x03 /* other threads to unwind and then exit */ +#define SINGLE_MASK 0x0f +/* extra flags for single_thread_set */ +#define SINGLE_DEEP 0x10 /* call is in deep */ + +int single_thread_set(struct proc *, int); +void single_thread_clear(struct proc *); + +int proc_suspend_check(struct proc *, int); +void process_suspend_signal(struct process *); +void process_stop(struct process *, int, int); + +void child_return(void *); + +int proc_cansugid(struct proc *); + +struct cond { + unsigned int c_wait; /* [a] initialized and waiting */ +}; + +#define COND_INITIALIZER() { .c_wait = 1 } + +void proc_trampoline_mi(void); + +/* + * functions to handle sets of cpus. + * + * For now we keep the cpus in ints so that we can use the generic + * atomic ops. + */ +#define CPUSET_ASIZE(x) (((x) - 1)/32 + 1) +#define CPUSET_SSIZE CPUSET_ASIZE(MAXCPUS) +struct cpuset { + int cs_set[CPUSET_SSIZE]; +}; + +void cpuset_init_cpu(struct cpu_info *); + +void cpuset_add(struct cpuset *, struct cpu_info *); +void cpuset_del(struct cpuset *, struct cpu_info *); +int cpuset_isset(struct cpuset *, struct cpu_info *); +void cpuset_copy(struct cpuset *, struct cpuset *); +void cpuset_intersection(struct cpuset *t, struct cpuset *, struct cpuset *); +void cpuset_complement(struct cpuset *, struct cpuset *, struct cpuset *); +int cpuset_cardinality(struct cpuset *); +struct cpu_info *cpuset_first(struct cpuset *); + +static inline unsigned int +tu_enter(struct tusage *tu) +{ + return pc_sprod_enter(&tu->tu_pcl); +} + +static inline void +tu_leave(struct tusage *tu, unsigned int gen) +{ + pc_sprod_leave(&tu->tu_pcl, gen); +} + +#endif /* _KERNEL */ +#endif /* !_SYS_PROC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/protosw.h b/lib/libc/include/generic-openbsd/sys/protosw.h new file mode 100644 index 0000000000..db18f5f66e --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/protosw.h @@ -0,0 +1,407 @@ +/* $OpenBSD: protosw.h,v 1.72 2025/03/02 21:28:32 bluhm Exp $ */ +/* $NetBSD: protosw.h,v 1.10 1996/04/09 20:55:32 cgd Exp $ */ + +/*- + * Copyright (c) 1982, 1986, 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. + * + * @(#)protosw.h 8.1 (Berkeley) 6/2/93 + */ + +/* + * Protocol switch table. + * + * Each protocol has a handle initializing one of these structures, + * which is used for protocol-protocol and system-protocol communication. + * + * A protocol is called through the pr_init entry before any other. + * Thereafter it is called every 200ms through the pr_fasttimo entry and + * every 500ms through the pr_slowtimo for timer based actions. + * + * Protocols pass data between themselves as chains of mbufs using + * the pr_input and pr_send hooks. Pr_input passes data up (towards + * UNIX) and pr_send passes it down (towards the imps); control + * information passes up and down on pr_ctlinput and pr_ctloutput. + * The protocol is responsible for the space occupied by any the + * arguments to these entries and must dispose it. + * + * The userreq routine interfaces protocols to the system and is + * described below. + */ + +#ifndef _SYS_PROTOSW_H_ +#define _SYS_PROTOSW_H_ + +struct mbuf; +struct sockaddr; +struct socket; +struct domain; +struct proc; +struct stat; +struct ifnet; +struct netstack; + +struct pr_usrreqs { + int (*pru_attach)(struct socket *, int, int); + int (*pru_detach)(struct socket *); + int (*pru_bind)(struct socket *, struct mbuf *, struct proc *); + int (*pru_listen)(struct socket *); + int (*pru_connect)(struct socket *, struct mbuf *); + int (*pru_accept)(struct socket *, struct mbuf *); + int (*pru_disconnect)(struct socket *); + int (*pru_shutdown)(struct socket *); + void (*pru_rcvd)(struct socket *); + int (*pru_send)(struct socket *, struct mbuf *, struct mbuf *, + struct mbuf *); + void (*pru_abort)(struct socket *); + int (*pru_control)(struct socket *, u_long, caddr_t, + struct ifnet *); + int (*pru_sense)(struct socket *, struct stat *); + int (*pru_rcvoob)(struct socket *, struct mbuf *, int); + int (*pru_sendoob)(struct socket *, struct mbuf *, struct mbuf *, + struct mbuf *); + int (*pru_sockaddr)(struct socket *, struct mbuf *); + int (*pru_peeraddr)(struct socket *, struct mbuf *); + int (*pru_connect2)(struct socket *, struct socket *); +}; + +struct protosw { + short pr_type; /* socket type used for */ + const struct domain *pr_domain; /* domain protocol a member of */ + short pr_protocol; /* protocol number */ + short pr_flags; /* see below */ + +/* protocol-protocol hooks */ + /* input to protocol (from below) */ + int (*pr_input)(struct mbuf **, int *, int, int, struct netstack *); + /* control input (from below) */ + void (*pr_ctlinput)(int, struct sockaddr *, u_int, void *); + /* control output (from above) */ + int (*pr_ctloutput)(int, struct socket *, int, int, struct mbuf *); + +/* user-protocol hooks */ + const struct pr_usrreqs *pr_usrreqs; + +/* utility hooks */ + void (*pr_init)(void); /* initialization hook */ + void (*pr_fasttimo)(void); /* fast timeout (200ms) */ + void (*pr_slowtimo)(void); /* slow timeout (500ms) */ + /* sysctl for protocol */ + int (*pr_sysctl)(int *, u_int, void *, size_t *, void *, size_t); +}; + +#define PR_SLOWHZ 2 /* 2 slow timeouts per second */ +#define PR_FASTHZ 5 /* 5 fast timeouts per second */ + +/* + * Values for pr_flags. + * PR_ADDR requires PR_ATOMIC; + * PR_ADDR and PR_CONNREQUIRED are mutually exclusive. + */ +#define PR_ATOMIC 0x0001 /* exchange atomic messages only */ +#define PR_ADDR 0x0002 /* addresses given with messages */ +#define PR_CONNREQUIRED 0x0004 /* connection required by protocol */ +#define PR_WANTRCVD 0x0008 /* want PRU_RCVD calls */ +#define PR_RIGHTS 0x0010 /* passes capabilities */ +#define PR_ABRTACPTDIS 0x0020 /* abort on accept(2) to disconnected + socket */ +#define PR_SPLICE 0x0040 /* socket splicing is possible */ +#define PR_MPINPUT 0x0080 /* input runs with shared netlock */ +#define PR_MPSYSCTL 0x0200 /* mp-safe sysctl(2) handler */ + +/* + * The arguments to usrreq are: + * (*protosw[].pr_usrreq)(up, req, m, nam, opt); + * where up is a (struct socket *), req is one of these requests, + * m is a optional mbuf chain containing a message, + * nam is an optional mbuf chain containing an address, + * and opt is a pointer to a socketopt structure or nil. + * The protocol is responsible for disposal of the mbuf chain m, + * the caller is responsible for any space held by nam and opt. + * A non-zero return from usrreq gives an + * UNIX error number which should be passed to higher level software. + */ +#define PRU_ATTACH 0 /* attach protocol to up */ +#define PRU_DETACH 1 /* detach protocol from up */ +#define PRU_BIND 2 /* bind socket to address */ +#define PRU_LISTEN 3 /* listen for connection */ +#define PRU_CONNECT 4 /* establish connection to peer */ +#define PRU_ACCEPT 5 /* accept connection from peer */ +#define PRU_DISCONNECT 6 /* disconnect from peer */ +#define PRU_SHUTDOWN 7 /* won't send any more data */ +#define PRU_RCVD 8 /* have taken data; more room now */ +#define PRU_SEND 9 /* send this data */ +#define PRU_ABORT 10 /* abort (fast DISCONNECT, DETACH) */ +#define PRU_CONTROL 11 /* control operations on protocol */ +#define PRU_SENSE 12 /* return status into m */ +#define PRU_RCVOOB 13 /* retrieve out of band data */ +#define PRU_SENDOOB 14 /* send out of band data */ +#define PRU_SOCKADDR 15 /* fetch socket's address */ +#define PRU_PEERADDR 16 /* fetch peer's address */ +#define PRU_CONNECT2 17 /* connect two sockets */ +/* begin for protocols internal use */ +#define PRU_FASTTIMO 18 /* 200ms timeout */ +#define PRU_SLOWTIMO 19 /* 500ms timeout */ +#define PRU_PROTORCV 20 /* receive from below */ +#define PRU_PROTOSEND 21 /* send to below */ + +#define PRU_NREQ 22 + +#ifdef PRUREQUESTS +const char *prurequests[] = { + "ATTACH", "DETACH", "BIND", "LISTEN", + "CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN", + "RCVD", "SEND", "ABORT", "CONTROL", + "SENSE", "RCVOOB", "SENDOOB", "SOCKADDR", + "PEERADDR", "CONNECT2", "FASTTIMO", "SLOWTIMO", + "PROTORCV", "PROTOSEND", +}; +#endif + +/* + * The arguments to the ctlinput routine are + * (*protosw[].pr_ctlinput)(cmd, sa, arg); + * where cmd is one of the commands below, sa is a pointer to a sockaddr, + * and arg is an optional caddr_t argument used within a protocol family. + */ +#define PRC_IFDOWN 0 /* interface transition */ +#define PRC_ROUTEDEAD 1 /* select new route if possible ??? */ +#define PRC_MTUINC 2 /* increase in mtu to host */ +#define PRC_QUENCH2 3 /* DEC congestion bit says slow down */ +#define PRC_QUENCH 4 /* some one said to slow down */ +#define PRC_MSGSIZE 5 /* message size forced drop */ +#define PRC_HOSTDEAD 6 /* host appears to be down */ +#define PRC_HOSTUNREACH 7 /* deprecated (use PRC_UNREACH_HOST) */ +#define PRC_UNREACH_NET 8 /* no route to network */ +#define PRC_UNREACH_HOST 9 /* no route to host */ +#define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */ +#define PRC_UNREACH_PORT 11 /* bad port # */ +/* was PRC_UNREACH_NEEDFRAG 12 (use PRC_MSGSIZE) */ +#define PRC_UNREACH_SRCFAIL 13 /* source route failed */ +#define PRC_REDIRECT_NET 14 /* net routing redirect */ +#define PRC_REDIRECT_HOST 15 /* host routing redirect */ +#define PRC_REDIRECT_TOSNET 16 /* redirect for type of service & net */ +#define PRC_REDIRECT_TOSHOST 17 /* redirect for tos & host */ +#define PRC_TIMXCEED_INTRANS 18 /* packet lifetime expired in transit */ +#define PRC_TIMXCEED_REASS 19 /* lifetime expired on reass q */ +#define PRC_PARAMPROB 20 /* header incorrect */ + +#define PRC_NCMDS 21 + +#define PRC_IS_REDIRECT(cmd) \ + ((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST) + +#ifdef PRCREQUESTS +char *prcrequests[] = { + "IFDOWN", "ROUTEDEAD", "MTUINC", "DEC-BIT-QUENCH2", + "QUENCH", "MSGSIZE", "HOSTDEAD", "#7", + "NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH", + "#12", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT", + "TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS", + "PARAMPROB" +}; +#endif + +/* + * The arguments to ctloutput are: + * (*protosw[].pr_ctloutput)(req, so, level, optname, optval); + * req is one of the actions listed below, so is a (struct socket *), + * level is an indication of which protocol layer the option is intended. + * optname is a protocol dependent socket option request, + * optval is a pointer to a mbuf-chain pointer, for value-return results. + * The protocol is responsible for disposal of the mbuf chain *optval + * if supplied, + * the caller is responsible for any space held by *optval, when returned. + * A non-zero return from usrreq gives an + * UNIX error number which should be passed to higher level software. + */ +#define PRCO_GETOPT 0 +#define PRCO_SETOPT 1 + +#define PRCO_NCMDS 2 + +#ifdef PRCOREQUESTS +char *prcorequests[] = { + "GETOPT", "SETOPT", +}; +#endif + +#ifdef _KERNEL + +#include +#include + +const struct protosw *pffindproto(int, int, int); +const struct protosw *pffindtype(int, int); +const struct domain *pffinddomain(int); +void pfctlinput(int, struct sockaddr *); + +extern u_char ip_protox[]; +extern const struct protosw inetsw[]; + +#ifdef INET6 +extern u_char ip6_protox[]; +extern const struct protosw inet6sw[]; +#endif /* INET6 */ + +static inline int +pru_attach(struct socket *so, int proto, int wait) +{ + return (*so->so_proto->pr_usrreqs->pru_attach)(so, proto, wait); +} + +static inline int +pru_detach(struct socket *so) +{ + return (*so->so_proto->pr_usrreqs->pru_detach)(so); +} + +static inline int +pru_bind(struct socket *so, struct mbuf *nam, struct proc *p) +{ + if (so->so_proto->pr_usrreqs->pru_bind) + return (*so->so_proto->pr_usrreqs->pru_bind)(so, nam, p); + return (EOPNOTSUPP); +} + +static inline int +pru_listen(struct socket *so) +{ + if (so->so_proto->pr_usrreqs->pru_listen) + return (*so->so_proto->pr_usrreqs->pru_listen)(so); + return (EOPNOTSUPP); +} + +static inline int +pru_connect(struct socket *so, struct mbuf *nam) +{ + if (so->so_proto->pr_usrreqs->pru_connect) + return (*so->so_proto->pr_usrreqs->pru_connect)(so, nam); + return (EOPNOTSUPP); +} + +static inline int +pru_accept(struct socket *so, struct mbuf *nam) +{ + if (so->so_proto->pr_usrreqs->pru_accept) + return (*so->so_proto->pr_usrreqs->pru_accept)(so, nam); + return (EOPNOTSUPP); +} + +static inline int +pru_disconnect(struct socket *so) +{ + if (so->so_proto->pr_usrreqs->pru_disconnect) + return (*so->so_proto->pr_usrreqs->pru_disconnect)(so); + return (EOPNOTSUPP); +} + +static inline int +pru_shutdown(struct socket *so) +{ + return (*so->so_proto->pr_usrreqs->pru_shutdown)(so); +} + +static inline void +pru_rcvd(struct socket *so) +{ + (*so->so_proto->pr_usrreqs->pru_rcvd)(so); +} + +static inline int +pru_send(struct socket *so, struct mbuf *top, struct mbuf *addr, + struct mbuf *control) +{ + return (*so->so_proto->pr_usrreqs->pru_send)(so, top, addr, control); +} + +static inline void +pru_abort(struct socket *so) +{ + (*so->so_proto->pr_usrreqs->pru_abort)(so); +} + +static inline int +pru_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp) +{ + if (so->so_proto->pr_usrreqs->pru_control) + return (*so->so_proto->pr_usrreqs->pru_control)(so, + cmd, data, ifp); + return (EOPNOTSUPP); +} + +static inline int +pru_sense(struct socket *so, struct stat *ub) +{ + if (so->so_proto->pr_usrreqs->pru_sense) + return (*so->so_proto->pr_usrreqs->pru_sense)(so, ub); + return (0); +} + +static inline int +pru_rcvoob(struct socket *so, struct mbuf *m, int flags) +{ + if (so->so_proto->pr_usrreqs->pru_rcvoob) + return (*so->so_proto->pr_usrreqs->pru_rcvoob)(so, m, flags); + return (EOPNOTSUPP); +} + +static inline int +pru_sendoob(struct socket *so, struct mbuf *top, struct mbuf *addr, + struct mbuf *control) +{ + if (so->so_proto->pr_usrreqs->pru_sendoob) + return (*so->so_proto->pr_usrreqs->pru_sendoob)(so, + top, addr, control); + m_freem(top); + m_freem(control); + return (EOPNOTSUPP); +} + +static inline int +pru_sockaddr(struct socket *so, struct mbuf *addr) +{ + return (*so->so_proto->pr_usrreqs->pru_sockaddr)(so, addr); +} + +static inline int +pru_peeraddr(struct socket *so, struct mbuf *addr) +{ + return (*so->so_proto->pr_usrreqs->pru_peeraddr)(so, addr); +} + +static inline int +pru_connect2(struct socket *so1, struct socket *so2) +{ + if (so1->so_proto->pr_usrreqs->pru_connect2) + return (*so1->so_proto->pr_usrreqs->pru_connect2)(so1, so2); + return (EOPNOTSUPP); +} + +#endif + +#endif /* _SYS_PROTOSW_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/ptrace.h b/lib/libc/include/generic-openbsd/sys/ptrace.h new file mode 100644 index 0000000000..54ee9d75d2 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/ptrace.h @@ -0,0 +1,137 @@ +/* $OpenBSD: ptrace.h,v 1.16 2020/03/16 11:58:46 mpi Exp $ */ +/* $NetBSD: ptrace.h,v 1.21 1996/02/09 18:25:26 christos Exp $ */ + +/*- + * Copyright (c) 1984, 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. + * + * @(#)ptrace.h 8.2 (Berkeley) 1/4/94 + */ + +#ifndef _SYS_PTRACE_H_ +#define _SYS_PTRACE_H_ + +#define PT_TRACE_ME 0 /* child declares it's being traced */ +#define PT_READ_I 1 /* read word in child's I space */ +#define PT_READ_D 2 /* read word in child's D space */ +#define PT_WRITE_I 4 /* write word in child's I space */ +#define PT_WRITE_D 5 /* write word in child's D space */ +#define PT_CONTINUE 7 /* continue the child */ +#define PT_KILL 8 /* kill the child process */ +#define PT_ATTACH 9 /* attach to running process */ +#define PT_DETACH 10 /* detach from running process */ +#define PT_IO 11 /* do I/O to/from the stopped process. */ + +struct ptrace_io_desc { + int piod_op; /* I/O operation */ + void *piod_offs; /* child offset */ + void *piod_addr; /* parent offset */ + size_t piod_len; /* request length */ +}; + +/* + * Operations in piod_op. + */ +#define PIOD_READ_D 1 /* Read from D space */ +#define PIOD_WRITE_D 2 /* Write to D space */ +#define PIOD_READ_I 3 /* Read from I space */ +#define PIOD_WRITE_I 4 /* Write to I space */ +#define PIOD_READ_AUXV 5 /* Read from aux array */ + +#define PT_SET_EVENT_MASK 12 +#define PT_GET_EVENT_MASK 13 + +typedef struct ptrace_event { + int pe_set_event; +} ptrace_event_t; + +#define PTRACE_FORK 0x0002 /* Report forks */ + +#define PT_GET_PROCESS_STATE 14 + +typedef struct ptrace_state { + int pe_report_event; + pid_t pe_other_pid; + pid_t pe_tid; +} ptrace_state_t; + +#define PT_GET_THREAD_FIRST 15 +#define PT_GET_THREAD_NEXT 16 + +struct ptrace_thread_state { + pid_t pts_tid; +}; + +#define PT_FIRSTMACH 32 /* for machine-specific requests */ +#include /* machine-specific requests, if any */ + +#ifdef _KERNEL + +/* + * There is a bunch of PT_ requests that are machine dependent, but not + * optional. Check if they were defined by MD code here. + */ +#if !defined(PT_GETREGS) || !defined(PT_SETREGS) +#error Machine dependent ptrace not complete. +#endif + +struct reg; +#if defined(PT_GETFPREGS) || defined(PT_SETFPREGS) +struct fpreg; +#endif + +void process_reparent(struct process *_child, struct process *_newparent); +void process_untrace(struct process *_tr); +#ifdef PT_GETFPREGS +int process_read_fpregs(struct proc *_t, struct fpreg *); +#endif +int process_read_regs(struct proc *_t, struct reg *); +int process_set_pc(struct proc *_t, caddr_t _addr); +int process_sstep(struct proc *_t, int _sstep); +#ifdef PT_SETFPREGS +int process_write_fpregs(struct proc *_t, struct fpreg *); +#endif +int process_write_regs(struct proc *_t, struct reg *); +int process_checkioperm(struct proc *_curp, struct process *_tr); +int process_domem(struct proc *_curp, struct process *_tr, struct uio *, + int _req); + +#ifndef FIX_SSTEP +#define FIX_SSTEP(p) +#endif + +#else /* !_KERNEL */ + +#include + +__BEGIN_DECLS +int ptrace(int _request, pid_t _pid, caddr_t _addr, int _data); +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_SYS_PTRACE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/queue.h b/lib/libc/include/generic-openbsd/sys/queue.h new file mode 100644 index 0000000000..db4f22bee5 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/queue.h @@ -0,0 +1,633 @@ +/* $OpenBSD: queue.h,v 1.46 2020/12/30 13:33:12 millert Exp $ */ +/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */ + +/* + * Copyright (c) 1991, 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. + * + * @(#)queue.h 8.5 (Berkeley) 8/20/94 + */ + +#ifndef _SYS_QUEUE_H_ +#define _SYS_QUEUE_H_ + +#include + +/* + * This file defines five types of data structures: singly-linked lists, + * lists, simple queues, tail queues and XOR simple queues. + * + * + * A singly-linked list is headed by a single forward pointer. The elements + * are singly linked for minimum space and pointer manipulation overhead at + * the expense of O(n) removal for arbitrary elements. New elements can be + * added to the list after an existing element or at the head of the list. + * Elements being removed from the head of the list should use the explicit + * macro for this purpose for optimum efficiency. A singly-linked list may + * only be traversed in the forward direction. Singly-linked lists are ideal + * for applications with large datasets and few or no removals or for + * implementing a LIFO queue. + * + * A list is headed by a single forward pointer (or an array of forward + * pointers for a hash table header). The elements are doubly linked + * so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before + * or after an existing element or at the head of the list. A list + * may only be traversed in the forward direction. + * + * A simple queue is headed by a pair of pointers, one to the head of the + * list and the other to the tail of the list. The elements are singly + * linked to save space, so elements can only be removed from the + * head of the list. New elements can be added to the list before or after + * an existing element, at the head of the list, or at the end of the + * list. A simple queue may only be traversed in the forward direction. + * + * A tail queue is headed by a pair of pointers, one to the head of the + * list and the other to the tail of the list. The elements are doubly + * linked so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before or + * after an existing element, at the head of the list, or at the end of + * the list. A tail queue may be traversed in either direction. + * + * An XOR simple queue is used in the same way as a regular simple queue. + * The difference is that the head structure also includes a "cookie" that + * is XOR'd with the queue pointer (first, last or next) to generate the + * real pointer value. + * + * For details on the use of these macros, see the queue(3) manual page. + */ + +#if defined(QUEUE_MACRO_DEBUG) || (defined(_KERNEL) && defined(DIAGNOSTIC)) +#define _Q_INVALID ((void *)-1) +#define _Q_INVALIDATE(a) (a) = _Q_INVALID +#else +#define _Q_INVALIDATE(a) +#endif + +/* + * Singly-linked List definitions. + */ +#define SLIST_HEAD(name, type) \ +struct name { \ + struct type *slh_first; /* first element */ \ +} + +#define SLIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define SLIST_ENTRY(type) \ +struct { \ + struct type *sle_next; /* next element */ \ +} + +/* + * Singly-linked List access methods. + */ +#define SLIST_FIRST(head) ((head)->slh_first) +#define SLIST_END(head) NULL +#define SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head)) +#define SLIST_NEXT(elm, field) ((elm)->field.sle_next) + +#define SLIST_FOREACH(var, head, field) \ + for((var) = SLIST_FIRST(head); \ + (var) != SLIST_END(head); \ + (var) = SLIST_NEXT(var, field)) + +#define SLIST_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = SLIST_FIRST(head); \ + (var) && ((tvar) = SLIST_NEXT(var, field), 1); \ + (var) = (tvar)) + +/* + * Singly-linked List functions. + */ +#define SLIST_INIT(head) { \ + SLIST_FIRST(head) = SLIST_END(head); \ +} + +#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \ + (elm)->field.sle_next = (slistelm)->field.sle_next; \ + (slistelm)->field.sle_next = (elm); \ +} while (0) + +#define SLIST_INSERT_HEAD(head, elm, field) do { \ + (elm)->field.sle_next = (head)->slh_first; \ + (head)->slh_first = (elm); \ +} while (0) + +#define SLIST_REMOVE_AFTER(elm, field) do { \ + (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \ +} while (0) + +#define SLIST_REMOVE_HEAD(head, field) do { \ + (head)->slh_first = (head)->slh_first->field.sle_next; \ +} while (0) + +#define SLIST_REMOVE(head, elm, type, field) do { \ + if ((head)->slh_first == (elm)) { \ + SLIST_REMOVE_HEAD((head), field); \ + } else { \ + struct type *curelm = (head)->slh_first; \ + \ + while (curelm->field.sle_next != (elm)) \ + curelm = curelm->field.sle_next; \ + curelm->field.sle_next = \ + curelm->field.sle_next->field.sle_next; \ + } \ + _Q_INVALIDATE((elm)->field.sle_next); \ +} while (0) + +/* + * List definitions. + */ +#define LIST_HEAD(name, type) \ +struct name { \ + struct type *lh_first; /* first element */ \ +} + +#define LIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define LIST_ENTRY(type) \ +struct { \ + struct type *le_next; /* next element */ \ + struct type **le_prev; /* address of previous next element */ \ +} + +/* + * List access methods. + */ +#define LIST_FIRST(head) ((head)->lh_first) +#define LIST_END(head) NULL +#define LIST_EMPTY(head) (LIST_FIRST(head) == LIST_END(head)) +#define LIST_NEXT(elm, field) ((elm)->field.le_next) + +#define LIST_FOREACH(var, head, field) \ + for((var) = LIST_FIRST(head); \ + (var)!= LIST_END(head); \ + (var) = LIST_NEXT(var, field)) + +#define LIST_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = LIST_FIRST(head); \ + (var) && ((tvar) = LIST_NEXT(var, field), 1); \ + (var) = (tvar)) + +/* + * List functions. + */ +#define LIST_INIT(head) do { \ + LIST_FIRST(head) = LIST_END(head); \ +} while (0) + +#define LIST_INSERT_AFTER(listelm, elm, field) do { \ + if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \ + (listelm)->field.le_next->field.le_prev = \ + &(elm)->field.le_next; \ + (listelm)->field.le_next = (elm); \ + (elm)->field.le_prev = &(listelm)->field.le_next; \ +} while (0) + +#define LIST_INSERT_BEFORE(listelm, elm, field) do { \ + (elm)->field.le_prev = (listelm)->field.le_prev; \ + (elm)->field.le_next = (listelm); \ + *(listelm)->field.le_prev = (elm); \ + (listelm)->field.le_prev = &(elm)->field.le_next; \ +} while (0) + +#define LIST_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.le_next = (head)->lh_first) != NULL) \ + (head)->lh_first->field.le_prev = &(elm)->field.le_next;\ + (head)->lh_first = (elm); \ + (elm)->field.le_prev = &(head)->lh_first; \ +} while (0) + +#define LIST_REMOVE(elm, field) do { \ + if ((elm)->field.le_next != NULL) \ + (elm)->field.le_next->field.le_prev = \ + (elm)->field.le_prev; \ + *(elm)->field.le_prev = (elm)->field.le_next; \ + _Q_INVALIDATE((elm)->field.le_prev); \ + _Q_INVALIDATE((elm)->field.le_next); \ +} while (0) + +#define LIST_REPLACE(elm, elm2, field) do { \ + if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \ + (elm2)->field.le_next->field.le_prev = \ + &(elm2)->field.le_next; \ + (elm2)->field.le_prev = (elm)->field.le_prev; \ + *(elm2)->field.le_prev = (elm2); \ + _Q_INVALIDATE((elm)->field.le_prev); \ + _Q_INVALIDATE((elm)->field.le_next); \ +} while (0) + +/* + * Simple queue definitions. + */ +#define SIMPLEQ_HEAD(name, type) \ +struct name { \ + struct type *sqh_first; /* first element */ \ + struct type **sqh_last; /* addr of last next element */ \ +} + +#define SIMPLEQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).sqh_first } + +#define SIMPLEQ_ENTRY(type) \ +struct { \ + struct type *sqe_next; /* next element */ \ +} + +/* + * Simple queue access methods. + */ +#define SIMPLEQ_FIRST(head) ((head)->sqh_first) +#define SIMPLEQ_END(head) NULL +#define SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head)) +#define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next) + +#define SIMPLEQ_FOREACH(var, head, field) \ + for((var) = SIMPLEQ_FIRST(head); \ + (var) != SIMPLEQ_END(head); \ + (var) = SIMPLEQ_NEXT(var, field)) + +#define SIMPLEQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = SIMPLEQ_FIRST(head); \ + (var) && ((tvar) = SIMPLEQ_NEXT(var, field), 1); \ + (var) = (tvar)) + +/* + * Simple queue functions. + */ +#define SIMPLEQ_INIT(head) do { \ + (head)->sqh_first = NULL; \ + (head)->sqh_last = &(head)->sqh_first; \ +} while (0) + +#define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \ + (head)->sqh_last = &(elm)->field.sqe_next; \ + (head)->sqh_first = (elm); \ +} while (0) + +#define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.sqe_next = NULL; \ + *(head)->sqh_last = (elm); \ + (head)->sqh_last = &(elm)->field.sqe_next; \ +} while (0) + +#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \ + if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\ + (head)->sqh_last = &(elm)->field.sqe_next; \ + (listelm)->field.sqe_next = (elm); \ +} while (0) + +#define SIMPLEQ_REMOVE_HEAD(head, field) do { \ + if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \ + (head)->sqh_last = &(head)->sqh_first; \ +} while (0) + +#define SIMPLEQ_REMOVE_AFTER(head, elm, field) do { \ + if (((elm)->field.sqe_next = (elm)->field.sqe_next->field.sqe_next) \ + == NULL) \ + (head)->sqh_last = &(elm)->field.sqe_next; \ +} while (0) + +#define SIMPLEQ_CONCAT(head1, head2) do { \ + if (!SIMPLEQ_EMPTY((head2))) { \ + *(head1)->sqh_last = (head2)->sqh_first; \ + (head1)->sqh_last = (head2)->sqh_last; \ + SIMPLEQ_INIT((head2)); \ + } \ +} while (0) + +/* + * XOR Simple queue definitions. + */ +#define XSIMPLEQ_HEAD(name, type) \ +struct name { \ + struct type *sqx_first; /* first element */ \ + struct type **sqx_last; /* addr of last next element */ \ + unsigned long sqx_cookie; \ +} + +#define XSIMPLEQ_ENTRY(type) \ +struct { \ + struct type *sqx_next; /* next element */ \ +} + +/* + * XOR Simple queue access methods. + */ +#define XSIMPLEQ_XOR(head, ptr) ((__typeof(ptr))((head)->sqx_cookie ^ \ + (unsigned long)(ptr))) +#define XSIMPLEQ_FIRST(head) XSIMPLEQ_XOR(head, ((head)->sqx_first)) +#define XSIMPLEQ_END(head) NULL +#define XSIMPLEQ_EMPTY(head) (XSIMPLEQ_FIRST(head) == XSIMPLEQ_END(head)) +#define XSIMPLEQ_NEXT(head, elm, field) XSIMPLEQ_XOR(head, ((elm)->field.sqx_next)) + + +#define XSIMPLEQ_FOREACH(var, head, field) \ + for ((var) = XSIMPLEQ_FIRST(head); \ + (var) != XSIMPLEQ_END(head); \ + (var) = XSIMPLEQ_NEXT(head, var, field)) + +#define XSIMPLEQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = XSIMPLEQ_FIRST(head); \ + (var) && ((tvar) = XSIMPLEQ_NEXT(head, var, field), 1); \ + (var) = (tvar)) + +/* + * XOR Simple queue functions. + */ +#define XSIMPLEQ_INIT(head) do { \ + arc4random_buf(&(head)->sqx_cookie, sizeof((head)->sqx_cookie)); \ + (head)->sqx_first = XSIMPLEQ_XOR(head, NULL); \ + (head)->sqx_last = XSIMPLEQ_XOR(head, &(head)->sqx_first); \ +} while (0) + +#define XSIMPLEQ_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.sqx_next = (head)->sqx_first) == \ + XSIMPLEQ_XOR(head, NULL)) \ + (head)->sqx_last = XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \ + (head)->sqx_first = XSIMPLEQ_XOR(head, (elm)); \ +} while (0) + +#define XSIMPLEQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.sqx_next = XSIMPLEQ_XOR(head, NULL); \ + *(XSIMPLEQ_XOR(head, (head)->sqx_last)) = XSIMPLEQ_XOR(head, (elm)); \ + (head)->sqx_last = XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \ +} while (0) + +#define XSIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \ + if (((elm)->field.sqx_next = (listelm)->field.sqx_next) == \ + XSIMPLEQ_XOR(head, NULL)) \ + (head)->sqx_last = XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \ + (listelm)->field.sqx_next = XSIMPLEQ_XOR(head, (elm)); \ +} while (0) + +#define XSIMPLEQ_REMOVE_HEAD(head, field) do { \ + if (((head)->sqx_first = XSIMPLEQ_XOR(head, \ + (head)->sqx_first)->field.sqx_next) == XSIMPLEQ_XOR(head, NULL)) \ + (head)->sqx_last = XSIMPLEQ_XOR(head, &(head)->sqx_first); \ +} while (0) + +#define XSIMPLEQ_REMOVE_AFTER(head, elm, field) do { \ + if (((elm)->field.sqx_next = XSIMPLEQ_XOR(head, \ + (elm)->field.sqx_next)->field.sqx_next) \ + == XSIMPLEQ_XOR(head, NULL)) \ + (head)->sqx_last = \ + XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \ +} while (0) + + +/* + * Tail queue definitions. + */ +#define TAILQ_HEAD(name, type) \ +struct name { \ + struct type *tqh_first; /* first element */ \ + struct type **tqh_last; /* addr of last next element */ \ +} + +#define TAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).tqh_first } + +#define TAILQ_ENTRY(type) \ +struct { \ + struct type *tqe_next; /* next element */ \ + struct type **tqe_prev; /* address of previous next element */ \ +} + +/* + * Tail queue access methods. + */ +#define TAILQ_FIRST(head) ((head)->tqh_first) +#define TAILQ_END(head) NULL +#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) +#define TAILQ_LAST(head, headname) \ + (*(((struct headname *)((head)->tqh_last))->tqh_last)) +/* XXX */ +#define TAILQ_PREV(elm, headname, field) \ + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) +#define TAILQ_EMPTY(head) \ + (TAILQ_FIRST(head) == TAILQ_END(head)) + +#define TAILQ_FOREACH(var, head, field) \ + for((var) = TAILQ_FIRST(head); \ + (var) != TAILQ_END(head); \ + (var) = TAILQ_NEXT(var, field)) + +#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = TAILQ_FIRST(head); \ + (var) != TAILQ_END(head) && \ + ((tvar) = TAILQ_NEXT(var, field), 1); \ + (var) = (tvar)) + + +#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ + for((var) = TAILQ_LAST(head, headname); \ + (var) != TAILQ_END(head); \ + (var) = TAILQ_PREV(var, headname, field)) + +#define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \ + for ((var) = TAILQ_LAST(head, headname); \ + (var) != TAILQ_END(head) && \ + ((tvar) = TAILQ_PREV(var, headname, field), 1); \ + (var) = (tvar)) + +/* + * Tail queue functions. + */ +#define TAILQ_INIT(head) do { \ + (head)->tqh_first = NULL; \ + (head)->tqh_last = &(head)->tqh_first; \ +} while (0) + +#define TAILQ_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \ + (head)->tqh_first->field.tqe_prev = \ + &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (head)->tqh_first = (elm); \ + (elm)->field.tqe_prev = &(head)->tqh_first; \ +} while (0) + +#define TAILQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.tqe_next = NULL; \ + (elm)->field.tqe_prev = (head)->tqh_last; \ + *(head)->tqh_last = (elm); \ + (head)->tqh_last = &(elm)->field.tqe_next; \ +} while (0) + +#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\ + (elm)->field.tqe_next->field.tqe_prev = \ + &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (listelm)->field.tqe_next = (elm); \ + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \ +} while (0) + +#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ + (elm)->field.tqe_next = (listelm); \ + *(listelm)->field.tqe_prev = (elm); \ + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \ +} while (0) + +#define TAILQ_REMOVE(head, elm, field) do { \ + if (((elm)->field.tqe_next) != NULL) \ + (elm)->field.tqe_next->field.tqe_prev = \ + (elm)->field.tqe_prev; \ + else \ + (head)->tqh_last = (elm)->field.tqe_prev; \ + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ + _Q_INVALIDATE((elm)->field.tqe_prev); \ + _Q_INVALIDATE((elm)->field.tqe_next); \ +} while (0) + +#define TAILQ_REPLACE(head, elm, elm2, field) do { \ + if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \ + (elm2)->field.tqe_next->field.tqe_prev = \ + &(elm2)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm2)->field.tqe_next; \ + (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \ + *(elm2)->field.tqe_prev = (elm2); \ + _Q_INVALIDATE((elm)->field.tqe_prev); \ + _Q_INVALIDATE((elm)->field.tqe_next); \ +} while (0) + +#define TAILQ_CONCAT(head1, head2, field) do { \ + if (!TAILQ_EMPTY(head2)) { \ + *(head1)->tqh_last = (head2)->tqh_first; \ + (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \ + (head1)->tqh_last = (head2)->tqh_last; \ + TAILQ_INIT((head2)); \ + } \ +} while (0) + +/* + * Singly-linked Tail queue declarations. + */ +#define STAILQ_HEAD(name, type) \ +struct name { \ + struct type *stqh_first; /* first element */ \ + struct type **stqh_last; /* addr of last next element */ \ +} + +#define STAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).stqh_first } + +#define STAILQ_ENTRY(type) \ +struct { \ + struct type *stqe_next; /* next element */ \ +} + +/* + * Singly-linked Tail queue access methods. + */ +#define STAILQ_FIRST(head) ((head)->stqh_first) +#define STAILQ_END(head) NULL +#define STAILQ_EMPTY(head) (STAILQ_FIRST(head) == STAILQ_END(head)) +#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next) + +#define STAILQ_FOREACH(var, head, field) \ + for ((var) = STAILQ_FIRST(head); \ + (var) != STAILQ_END(head); \ + (var) = STAILQ_NEXT(var, field)) + +#define STAILQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = STAILQ_FIRST(head); \ + (var) && ((tvar) = STAILQ_NEXT(var, field), 1); \ + (var) = (tvar)) + +/* + * Singly-linked Tail queue functions. + */ +#define STAILQ_INIT(head) do { \ + STAILQ_FIRST((head)) = NULL; \ + (head)->stqh_last = &STAILQ_FIRST((head)); \ +} while (0) + +#define STAILQ_INSERT_HEAD(head, elm, field) do { \ + if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ + STAILQ_FIRST((head)) = (elm); \ +} while (0) + +#define STAILQ_INSERT_TAIL(head, elm, field) do { \ + STAILQ_NEXT((elm), field) = NULL; \ + *(head)->stqh_last = (elm); \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ +} while (0) + +#define STAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ + if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((elm), field)) == NULL)\ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ + STAILQ_NEXT((elm), field) = (elm); \ +} while (0) + +#define STAILQ_REMOVE_HEAD(head, field) do { \ + if ((STAILQ_FIRST((head)) = \ + STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \ + (head)->stqh_last = &STAILQ_FIRST((head)); \ +} while (0) + +#define STAILQ_REMOVE_AFTER(head, elm, field) do { \ + if ((STAILQ_NEXT(elm, field) = \ + STAILQ_NEXT(STAILQ_NEXT(elm, field), field)) == NULL) \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ +} while (0) + +#define STAILQ_REMOVE(head, elm, type, field) do { \ + if (STAILQ_FIRST((head)) == (elm)) { \ + STAILQ_REMOVE_HEAD((head), field); \ + } else { \ + struct type *curelm = (head)->stqh_first; \ + while (STAILQ_NEXT(curelm, field) != (elm)) \ + curelm = STAILQ_NEXT(curelm, field); \ + STAILQ_REMOVE_AFTER(head, curelm, field); \ + } \ +} while (0) + +#define STAILQ_CONCAT(head1, head2) do { \ + if (!STAILQ_EMPTY((head2))) { \ + *(head1)->stqh_last = (head2)->stqh_first; \ + (head1)->stqh_last = (head2)->stqh_last; \ + STAILQ_INIT((head2)); \ + } \ +} while (0) + +#define STAILQ_LAST(head, type, field) \ + (STAILQ_EMPTY((head)) ? NULL : \ + ((struct type *)(void *) \ + ((char *)((head)->stqh_last) - offsetof(struct type, field)))) + +#endif /* !_SYS_QUEUE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/radioio.h b/lib/libc/include/generic-openbsd/sys/radioio.h new file mode 100644 index 0000000000..de1737d445 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/radioio.h @@ -0,0 +1,76 @@ +/* $OpenBSD: radioio.h,v 1.5 2015/01/14 21:15:36 deraadt Exp $ */ +/* $RuOBSD: radioio.h,v 1.4 2001/10/18 16:51:36 pva Exp $ */ + +/* + * Copyright (c) 2001 Maxim Tsyplakov , + * Vladimir Popov + * 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 AUTHORS ``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 AUTHORS 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 _SYS_RADIOIO_H_ +#define _SYS_RADIOIO_H_ + +#include + +#define MIN_FM_FREQ 87500 +#define MAX_FM_FREQ 108000 + +#define MIN_TV_CHAN 0 +#define MAX_TV_CHAN 150 + +#define IF_FREQ 10700 + +struct radio_info { + int mute; + int volume; + int stereo; + int rfreq; /* reference frequency */ + int lock; /* locking field strength during an automatic search */ + u_int32_t freq; /* in kHz */ + u_int32_t caps; /* card capabilities */ +#define RADIO_CAPS_DETECT_STEREO (1<<0) +#define RADIO_CAPS_DETECT_SIGNAL (1<<1) +#define RADIO_CAPS_SET_MONO (1<<2) +#define RADIO_CAPS_HW_SEARCH (1<<3) +#define RADIO_CAPS_HW_AFC (1<<4) +#define RADIO_CAPS_REFERENCE_FREQ (1<<5) +#define RADIO_CAPS_LOCK_SENSITIVITY (1<<6) +#define RADIO_CAPS_RESERVED1 (1<<7) +#define RADIO_CAPS_RESERVED2 (0xFF<<8) +#define RADIO_CARD_TYPE (0xFF<<16) + u_int32_t info; +#define RADIO_INFO_STEREO (1<<0) +#define RADIO_INFO_SIGNAL (1<<1) + u_int32_t tuner_mode; +#define RADIO_TUNER_MODE_RADIO (1<<0) +#define RADIO_TUNER_MODE_TV (1<<1) + u_int32_t chan; + u_int32_t chnlset; +}; + +/* Radio device operations */ +#define RIOCGINFO _IOR('R', 21, struct radio_info) /* get info */ +#define RIOCSINFO _IOWR('R', 22, struct radio_info) /* set info */ +#define RIOCSSRCH _IOW('R', 23, int) /* search up/down */ + +#endif /* _SYS_RADIOIO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/reboot.h b/lib/libc/include/generic-openbsd/sys/reboot.h new file mode 100644 index 0000000000..e2a7e0f3a0 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/reboot.h @@ -0,0 +1,109 @@ +/* $OpenBSD: reboot.h,v 1.21 2025/09/16 12:18:10 hshoexer Exp $ */ +/* $NetBSD: reboot.h,v 1.9 1996/04/22 01:23:25 christos Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1988, 1993, 1994 + * 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. + * + * @(#)reboot.h 8.2 (Berkeley) 7/10/94 + */ + +#ifndef _SYS_REBOOT_H_ +#define _SYS_REBOOT_H_ + +/* + * Arguments to reboot system call. These are passed to the boot program, + * and then on to init. + */ +#define RB_AUTOBOOT 0 /* flags for system auto-booting itself */ + +#define RB_ASKNAME 0x00001 /* ask for file name to reboot from */ +#define RB_SINGLE 0x00002 /* reboot to single user only */ +#define RB_NOSYNC 0x00004 /* dont sync before reboot */ +#define RB_HALT 0x00008 /* don't reboot, just halt */ +#define RB_INITNAME 0x00010 /* name given for /etc/init (unused) */ +#define RB_DFLTROOT 0x00020 /* use compiled-in rootdev */ +#define RB_KDB 0x00040 /* give control to kernel debugger */ +#define RB_RDONLY 0x00080 /* mount root fs read-only */ +#define RB_DUMP 0x00100 /* dump kernel memory before reboot */ +#define RB_MINIROOT 0x00200 /* mini-root present in memory at boot time */ +#define RB_CONFIG 0x00400 /* change configured devices */ +#define RB_TIMEBAD 0x00800 /* don't call resettodr() in boot() */ +#define RB_POWERDOWN 0x01000 /* attempt to power down machine */ +#define RB_SERCONS 0x02000 /* use serial console if available */ +#define RB_USERREQ 0x04000 /* boot() called at user request (e.g. ddb) */ +#define RB_RESET 0x08000 /* just reset, no cleanup */ +#define RB_GOODRANDOM 0x10000 /* excellent random seed loaded */ +#define RB_UNHIBERNATE 0x20000 /* unhibernate */ +#define RB_COCOVM 0x40000 /* booting confidential VM (e.g. SEV enabled) */ + +/* + * Constants for converting boot-style device number to type, + * adaptor (uba, mba, etc), unit number and partition number. + * Type (== major device number) is in the low byte + * for backward compatibility. Except for that of the "magic + * number", each mask applies to the shifted value. + * Format: + * (4) (4) (4) (4) (8) (8) + * -------------------------------- + * |MA | AD| CT| UN| PART | TYPE | + * -------------------------------- + */ +#define B_ADAPTORSHIFT 24 +#define B_ADAPTORMASK 0x0f +#define B_ADAPTOR(val) (((val) >> B_ADAPTORSHIFT) & B_ADAPTORMASK) +#define B_CONTROLLERSHIFT 20 +#define B_CONTROLLERMASK 0xf +#define B_CONTROLLER(val) (((val)>>B_CONTROLLERSHIFT) & B_CONTROLLERMASK) +#define B_UNITSHIFT 16 +#define B_UNITMASK 0xf +#define B_UNIT(val) (((val) >> B_UNITSHIFT) & B_UNITMASK) +#define B_PARTITIONSHIFT 8 +#define B_PARTITIONMASK 0xff +#define B_PARTITION(val) (((val) >> B_PARTITIONSHIFT) & B_PARTITIONMASK) +#define B_TYPESHIFT 0 +#define B_TYPEMASK 0xff +#define B_TYPE(val) (((val) >> B_TYPESHIFT) & B_TYPEMASK) + +#define B_MAGICMASK 0xf0000000 +#define B_DEVMAGIC 0xa0000000 + +#define MAKEBOOTDEV(type, adaptor, controller, unit, partition) \ + (((type) << B_TYPESHIFT) | ((adaptor) << B_ADAPTORSHIFT) | \ + ((controller) << B_CONTROLLERSHIFT) | ((unit) << B_UNITSHIFT) | \ + ((partition) << B_PARTITIONSHIFT) | B_DEVMAGIC) + +#if defined(_KERNEL) && !defined(_STANDALONE) && !defined(_LOCORE) + +__BEGIN_DECLS +__dead void reboot(int); +__dead void boot(int); +__END_DECLS + +#endif /* _KERNEL */ + +#endif /* !_SYS_REBOOT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/refcnt.h b/lib/libc/include/generic-openbsd/sys/refcnt.h new file mode 100644 index 0000000000..150735d27d --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/refcnt.h @@ -0,0 +1,59 @@ +/* $OpenBSD: refcnt.h,v 1.16 2025/08/05 12:52:20 bluhm Exp $ */ + +/* + * Copyright (c) 2015 David Gwynne + * + * 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 _SYS_REFCNT_H_ +#define _SYS_REFCNT_H_ + +/* + * Locks used to protect struct members in this file: + * I immutable after creation + * a atomic operations + */ + +struct refcnt { + unsigned int r_refs; /* [a] reference counter */ + int r_traceidx; /* [I] index for dt(4) tracing */ +}; + +#define REFCNT_INITIALIZER() { .r_refs = 1, .r_traceidx = 0 } + +#ifdef _KERNEL + +void refcnt_init(struct refcnt *); +void refcnt_init_trace(struct refcnt *, int); +void refcnt_take(struct refcnt *); +int refcnt_rele(struct refcnt *); +void refcnt_rele_wake(struct refcnt *); +void refcnt_finalize(struct refcnt *, const char *); +unsigned int refcnt_read(const struct refcnt *); + +#define refcnt_shared(_r) (refcnt_read((_r)) > 1) + +/* sorted alphabetically, keep in sync with dev/dt/dt_prov_static.c */ +#define DT_REFCNT_IDX_ETHMULTI 1 +#define DT_REFCNT_IDX_IFADDR 2 +#define DT_REFCNT_IDX_IFMADDR 3 +#define DT_REFCNT_IDX_INPCB 4 +#define DT_REFCNT_IDX_RTENTRY 5 +#define DT_REFCNT_IDX_SOCKET 6 +#define DT_REFCNT_IDX_SYNCACHE 7 +#define DT_REFCNT_IDX_TDB 8 + +#endif /* _KERNEL */ + +#endif /* _SYS_REFCNT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/resource.h b/lib/libc/include/generic-openbsd/sys/resource.h new file mode 100644 index 0000000000..fcef9802bd --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/resource.h @@ -0,0 +1,128 @@ +/* $OpenBSD: resource.h,v 1.14 2013/10/25 04:42:48 guenther Exp $ */ +/* $NetBSD: resource.h,v 1.14 1996/02/09 18:25:27 christos Exp $ */ + +/* + * Copyright (c) 1982, 1986, 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. + * + * @(#)resource.h 8.2 (Berkeley) 1/4/94 + */ + +#ifndef _SYS_RESOURCE_H_ +#define _SYS_RESOURCE_H_ + +#include + +/* + * Process priority specifications to get/setpriority. + */ +#define PRIO_MIN (-20) +#define PRIO_MAX 20 + +#define PRIO_PROCESS 0 +#define PRIO_PGRP 1 +#define PRIO_USER 2 + +/* + * Resource utilization information. + */ + +#define RUSAGE_SELF 0 +#define RUSAGE_CHILDREN (-1) +#define RUSAGE_THREAD 1 + +struct rusage { + struct timeval ru_utime; /* user time used */ + struct timeval ru_stime; /* system time used */ + long ru_maxrss; /* max resident set size */ +#define ru_first ru_ixrss + long ru_ixrss; /* integral shared text memory size */ + long ru_idrss; /* integral unshared data " */ + long ru_isrss; /* integral unshared stack " */ + long ru_minflt; /* page reclaims */ + long ru_majflt; /* page faults */ + long ru_nswap; /* swaps */ + long ru_inblock; /* block input operations */ + long ru_oublock; /* block output operations */ + long ru_msgsnd; /* messages sent */ + long ru_msgrcv; /* messages received */ + long ru_nsignals; /* signals received */ + long ru_nvcsw; /* voluntary context switches */ + long ru_nivcsw; /* involuntary " */ +#define ru_last ru_nivcsw +}; + +/* + * Resource limits + */ +#define RLIMIT_CPU 0 /* cpu time in milliseconds */ +#define RLIMIT_FSIZE 1 /* maximum file size */ +#define RLIMIT_DATA 2 /* data size */ +#define RLIMIT_STACK 3 /* stack size */ +#define RLIMIT_CORE 4 /* core file size */ +#define RLIMIT_RSS 5 /* resident set size */ +#define RLIMIT_MEMLOCK 6 /* locked-in-memory address space */ +#define RLIMIT_NPROC 7 /* number of processes */ +#define RLIMIT_NOFILE 8 /* number of open files */ + +#define RLIM_NLIMITS 9 /* number of resource limits */ + +#define RLIM_INFINITY (((rlim_t)1 << 63) - 1) +#define RLIM_SAVED_MAX RLIM_INFINITY +#define RLIM_SAVED_CUR RLIM_INFINITY + +struct rlimit { + rlim_t rlim_cur; /* current (soft) limit */ + rlim_t rlim_max; /* maximum value for rlim_cur */ +}; + +#if __BSD_VISIBLE +/* Load average structure. */ +struct loadavg { + fixpt_t ldavg[3]; + long fscale; +}; +#endif /* __BSD_VISIBLE */ + +#ifdef _KERNEL +extern struct loadavg averunnable; +struct process; +int dosetrlimit(struct proc *, u_int, struct rlimit *); +int donice(struct proc *, struct process *, int); +int dogetrusage(struct proc *, int, struct rusage *); + +#else +__BEGIN_DECLS +int getpriority(int, id_t); +int getrlimit(int, struct rlimit *); +int getrusage(int, struct rusage *); +int setpriority(int, id_t, int); +int setrlimit(int, const struct rlimit *); +__END_DECLS + +#endif /* _KERNEL */ +#endif /* !_SYS_RESOURCE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/resourcevar.h b/lib/libc/include/generic-openbsd/sys/resourcevar.h new file mode 100644 index 0000000000..de6db8037a --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/resourcevar.h @@ -0,0 +1,114 @@ +/* $OpenBSD: resourcevar.h,v 1.35 2024/10/24 23:24:58 jsg Exp $ */ +/* $NetBSD: resourcevar.h,v 1.12 1995/11/22 23:01:53 cgd Exp $ */ + +/* + * Copyright (c) 1991, 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. + * + * @(#)resourcevar.h 8.3 (Berkeley) 2/22/94 + */ + +#ifndef _SYS_RESOURCEVAR_H_ +#define _SYS_RESOURCEVAR_H_ + +#include + +/* + * Kernel shareable process resource limits. Because this structure + * is moderately large but changes infrequently, it is shared + * copy-on-write after forks. + */ +struct plimit { + struct rlimit pl_rlimit[RLIM_NLIMITS]; + struct refcnt pl_refcnt; +}; + +/* add user profiling from AST */ +#define ADDUPROF(p) \ +do { \ + atomic_clearbits_int(&(p)->p_flag, P_OWEUPC); \ + addupc_task((p), (p)->p_prof_addr, (p)->p_prof_ticks); \ + (p)->p_prof_ticks = 0; \ +} while (0) + +#ifdef _KERNEL + +#include /* for KASSERT() */ + +extern uint64_t profclock_period; + +void addupc_intr(struct proc *, u_long, u_long); +void addupc_task(struct proc *, u_long, u_int); +struct clockrequest; +void profclock(struct clockrequest *, void *, void *); +void tuagg_add_process(struct process *, struct proc *); +void tuagg_add_runtime(void); +struct tusage; +void tuagg_get_proc(struct tusage *, struct proc *); +void tuagg_get_process(struct tusage *, struct process *); +void calctsru(struct tusage *, struct timespec *, struct timespec *, + struct timespec *); +void calcru(struct tusage *, struct timeval *, struct timeval *, + struct timeval *); +void lim_startup(struct plimit *); +void lim_free(struct plimit *); +void lim_fork(struct process *, struct process *); +struct plimit *lim_read_enter(void); + +/* + * Finish read access to resource limits. + */ +static inline void +lim_read_leave(struct plimit *limit) +{ + /* nothing */ +} + +/* + * Get the value of the resource limit in current process. + */ +static inline rlim_t +lim_cur(int which) +{ + struct plimit *limit; + rlim_t val; + + KASSERT(which >= 0 && which < RLIM_NLIMITS); + + limit = lim_read_enter(); + val = limit->pl_rlimit[which].rlim_cur; + lim_read_leave(limit); + return (val); +} + +rlim_t lim_cur_proc(struct proc *, int); + +void ruadd(struct rusage *, const struct rusage *); +void rucheck(void *); + +#endif +#endif /* !_SYS_RESOURCEVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/rwlock.h b/lib/libc/include/generic-openbsd/sys/rwlock.h new file mode 100644 index 0000000000..fa5a61a152 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/rwlock.h @@ -0,0 +1,251 @@ +/* $OpenBSD: rwlock.h,v 1.34 2025/07/21 20:36:41 bluhm Exp $ */ +/* + * Copyright (c) 2002 Artur Grabowski + * + * 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. + */ + +/* + * Multiple readers, single writer lock. + * + * Simplistic implementation modelled after rw locks in Solaris. + * + * The rwl_owner has the following layout: + * [ owner or count of readers | wrlock | wrwant | wait ] + * + * When the WAIT bit is set (bit 0), the lock has waiters sleeping on it. + * When the WRWANT bit is set (bit 1), at least one waiter wants a write lock. + * When the WRLOCK bit is set (bit 2) the lock is currently write-locked. + * + * When write locked, the upper bits contain the struct proc * pointer to + * the writer, otherwise they count the number of readers. + * + * We provide a simple machine independent implementation: + * + * void rw_enter_read(struct rwlock *) + * atomically test for RWLOCK_WRLOCK and if not set, increment the lock + * by RWLOCK_READ_INCR. While RWLOCK_WRLOCK is set, loop into rw_enter_wait. + * + * void rw_enter_write(struct rwlock *); + * atomically test for the lock being 0 (it's not possible to have + * owner/read count unset and waiter bits set) and if 0 set the owner to + * the proc and RWLOCK_WRLOCK. While not zero, loop into rw_enter_wait. + * + * void rw_exit_read(struct rwlock *); + * atomically decrement lock by RWLOCK_READ_INCR and unset RWLOCK_WAIT and + * RWLOCK_WRWANT remembering the old value of lock and if RWLOCK_WAIT was set, + * call rw_exit_waiters with the old contents of the lock. + * + * void rw_exit_write(struct rwlock *); + * atomically swap the contents of the lock with 0 and if RWLOCK_WAIT was + * set, call rw_exit_waiters with the old contents of the lock. + */ + +#ifndef _SYS_RWLOCK_H +#define _SYS_RWLOCK_H + +#include + +struct proc; + +struct rwlock { + volatile unsigned long rwl_owner; + volatile unsigned int rwl_waiters; + volatile unsigned int rwl_readers; + const char *rwl_name; +#ifdef WITNESS + struct lock_object rwl_lock_obj; +#endif + int rwl_traceidx; +}; + +#define RWLOCK_LO_FLAGS(flags) \ + ((ISSET(flags, RWL_DUPOK) ? LO_DUPOK : 0) | \ + (ISSET(flags, RWL_NOWITNESS) ? 0 : LO_WITNESS) | \ + (ISSET(flags, RWL_IS_VNODE) ? LO_IS_VNODE : 0) | \ + LO_INITIALIZED | LO_SLEEPABLE | LO_UPGRADABLE | \ + (LO_CLASS_RWLOCK << LO_CLASSSHIFT)) + +#define RRWLOCK_LO_FLAGS(flags) \ + ((ISSET(flags, RWL_DUPOK) ? LO_DUPOK : 0) | \ + (ISSET(flags, RWL_NOWITNESS) ? 0 : LO_WITNESS) | \ + (ISSET(flags, RWL_IS_VNODE) ? LO_IS_VNODE : 0) | \ + LO_INITIALIZED | LO_RECURSABLE | LO_SLEEPABLE | LO_UPGRADABLE | \ + (LO_CLASS_RRWLOCK << LO_CLASSSHIFT)) + +#define RWLOCK_LO_INITIALIZER(name, flags) \ + { .lo_type = &(const struct lock_type){ .lt_name = name }, \ + .lo_name = (name), \ + .lo_flags = RWLOCK_LO_FLAGS(flags) } + +#define RWL_DUPOK 0x01 +#define RWL_NOWITNESS 0x02 +#define RWL_IS_VNODE 0x04 + +#ifdef WITNESS +#define RWLOCK_INITIALIZER(name) \ + { 0, 0, 0, name, .rwl_lock_obj = RWLOCK_LO_INITIALIZER(name, 0), 0 } +#define RWLOCK_INITIALIZER_TRACE(name, trace) \ + { 0, 0, 0, name, .rwl_lock_obj = RWLOCK_LO_INITIALIZER(name, 0), trace } +#else +#define RWLOCK_INITIALIZER(name) \ + { 0, 0, 0, name, 0 } +#define RWLOCK_INITIALIZER_TRACE(name, trace) \ + { 0, 0, 0, name, trace } +#endif + +#define RWLOCK_WRLOCK 0x04UL +#define RWLOCK_MASK 0x07UL + +#define RWLOCK_OWNER(rwl) ((struct proc *)((rwl)->rwl_owner & ~RWLOCK_MASK)) + +#define RWLOCK_READER_SHIFT 3UL +#define RWLOCK_READ_INCR (1UL << RWLOCK_READER_SHIFT) + +#define RW_WRITE 0x0001UL /* exclusive lock */ +#define RW_READ 0x0002UL /* shared lock */ +#define RW_DOWNGRADE 0x0004UL /* downgrade exclusive to shared */ +#define RW_UPGRADE 0x0005UL +#define RW_OPMASK 0x0007UL + +#define RW_INTR 0x0010UL /* interruptible sleep */ +#define RW_NOSLEEP 0x0040UL /* don't wait for the lock */ +#define RW_RECURSEFAIL 0x0080UL /* Fail on recursion for RRW locks. */ +#define RW_DUPOK 0x0100UL /* Permit duplicate lock */ + +/* + * for rw_status() and rrw_status() only: exclusive lock held by + * some other thread + */ +#define RW_WRITE_OTHER 0x0100UL + +/* recursive rwlocks; */ +struct rrwlock { + struct rwlock rrwl_lock; + uint32_t rrwl_wcnt; /* # writers. */ +}; + +#ifdef _KERNEL + +void _rw_init_flags(struct rwlock *, const char *, int, + const struct lock_type *, int); + +#ifdef WITNESS +#define rw_init_flags_trace(rwl, name, flags, trace) do { \ + static const struct lock_type __lock_type = { .lt_name = #rwl };\ + _rw_init_flags(rwl, name, flags, &__lock_type, trace); \ +} while (0) +#define rw_init_flags(rwl, name, flags) do { \ + static const struct lock_type __lock_type = { .lt_name = #rwl };\ + _rw_init_flags(rwl, name, flags, &__lock_type, 0); \ +} while (0) +#define rw_init(rwl, name) rw_init_flags(rwl, name, 0) +#else /* WITNESS */ +#define rw_init_flags_trace(rwl, name, flags, trace) \ + _rw_init_flags(rwl, name, flags, NULL, trace) +#define rw_init_flags(rwl, name, flags) \ + _rw_init_flags(rwl, name, flags, NULL, 0) +#define rw_init(rwl, name) _rw_init_flags(rwl, name, 0, NULL, 0) +#endif /* WITNESS */ + +void rw_enter_read(struct rwlock *); +void rw_enter_write(struct rwlock *); +void rw_exit_read(struct rwlock *); +void rw_exit_write(struct rwlock *); + +#ifdef DIAGNOSTIC +void rw_assert_wrlock(struct rwlock *); +void rw_assert_rdlock(struct rwlock *); +void rw_assert_anylock(struct rwlock *); +void rw_assert_unlocked(struct rwlock *); +#else +#define rw_assert_wrlock(rwl) ((void)0) +#define rw_assert_rdlock(rwl) ((void)0) +#define rw_assert_anylock(rwl) ((void)0) +#define rw_assert_unlocked(rwl) ((void)0) +#endif + +int rw_enter(struct rwlock *, int); +void rw_exit(struct rwlock *); +int rw_status(struct rwlock *); + +static inline int +rw_read_held(struct rwlock *rwl) +{ + return (rw_status(rwl) == RW_READ); +} + +static inline int +rw_write_held(struct rwlock *rwl) +{ + return (rw_status(rwl) == RW_WRITE); +} + +static inline int +rw_lock_held(struct rwlock *rwl) +{ + int status; + + status = rw_status(rwl); + + return (status == RW_READ || status == RW_WRITE); +} + + +void _rrw_init_flags(struct rrwlock *, const char *, int, + const struct lock_type *); +int rrw_enter(struct rrwlock *, int); +void rrw_exit(struct rrwlock *); +int rrw_status(struct rrwlock *); + +#ifdef WITNESS +#define rrw_init_flags(rrwl, name, flags) do { \ + static const struct lock_type __lock_type = { .lt_name = #rrwl };\ + _rrw_init_flags(rrwl, name, flags, &__lock_type); \ +} while (0) +#define rrw_init(rrwl, name) rrw_init_flags(rrwl, name, 0) +#else /* WITNESS */ +#define rrw_init_flags(rrwl, name, flags) \ + _rrw_init_flags(rrwl, name, 0, NULL) +#define rrw_init(rrwl, name) _rrw_init_flags(rrwl, name, 0, NULL) +#endif /* WITNESS */ + + +/* + * Allocated, reference-counted rwlocks + */ + +#ifdef WITNESS +#define rw_obj_alloc_flags(rwl, name, flags) do { \ + static struct lock_type __lock_type = { .lt_name = #rwl }; \ + _rw_obj_alloc_flags(rwl, name, flags, &__lock_type); \ +} while (0) +#else +#define rw_obj_alloc_flags(rwl, name, flags) \ + _rw_obj_alloc_flags(rwl, name, flags, NULL) +#endif +#define rw_obj_alloc(rwl, name) rw_obj_alloc_flags(rwl, name, 0) + +void rw_obj_init(void); +void _rw_obj_alloc_flags(struct rwlock **, const char *, int, + struct lock_type *); +void rw_obj_hold(struct rwlock *); +int rw_obj_free(struct rwlock *); + +/* sorted alphabetically, keep in sync with dev/dt/dt_prov_static.c */ +#define DT_RWLOCK_IDX_NETLOCK 1 +#define DT_RWLOCK_IDX_SOLOCK 2 + +#endif /* _KERNEL */ + +#endif /* _SYS_RWLOCK_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/sched.h b/lib/libc/include/generic-openbsd/sys/sched.h new file mode 100644 index 0000000000..d60605e710 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/sched.h @@ -0,0 +1,216 @@ +/* $OpenBSD: sched.h,v 1.77 2025/06/09 10:57:46 claudio Exp $ */ +/* $NetBSD: sched.h,v 1.2 1999/02/28 18:14:58 ross Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Ross Harvey. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*- + * Copyright (c) 1982, 1986, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)kern_clock.c 8.5 (Berkeley) 1/21/94 + */ + +#ifndef _SYS_SCHED_H_ +#define _SYS_SCHED_H_ + +/* + * Posix defines a which may want to include + */ + +/* + * CPU states. + * XXX Not really scheduler state, but no other good place to put + * it right now, and it really is per-CPU. + */ +#define CP_USER 0 +#define CP_NICE 1 +#define CP_SYS 2 +#define CP_SPIN 3 +#define CP_INTR 4 +#define CP_IDLE 5 +#define CPUSTATES 6 + +struct cpustats { + uint64_t cs_time[CPUSTATES]; /* CPU state statistics */ + uint64_t cs_flags; /* see below */ +}; + +#define CPUSTATS_ONLINE 0x0001 /* CPU is schedulable */ + +#ifdef _KERNEL + +#include +#include +#include + +#define SCHED_NQS 32 /* 32 run queues. */ + +struct smr_entry; + +/* + * Per-CPU scheduler state. + * o owned (modified only) by this CPU + */ +struct schedstate_percpu { + struct proc *spc_idleproc; /* idle proc for this cpu */ + TAILQ_HEAD(prochead, proc) spc_qs[SCHED_NQS]; + TAILQ_HEAD(,proc) spc_deadproc; + struct timespec spc_runtime; /* time curproc started running */ + volatile int spc_schedflags; /* flags; see below */ + u_int spc_schedticks; /* ticks for schedclock() */ + struct pc_lock spc_cp_time_lock; + u_int64_t spc_cp_time[CPUSTATES]; /* CPU state statistics */ + + struct clockintr spc_itimer; /* [o] itimer_update handle */ + struct clockintr spc_profclock; /* [o] profclock handle */ + struct clockintr spc_roundrobin;/* [o] roundrobin handle */ + struct clockintr spc_statclock; /* [o] statclock handle */ + + u_int spc_nrun; /* procs on the run queues */ + + volatile uint32_t spc_whichqs; + volatile u_int spc_spinning; /* this cpu is currently spinning */ + + SIMPLEQ_HEAD(, smr_entry) spc_deferred; /* deferred smr calls */ + u_int spc_ndeferred; /* number of deferred smr calls */ + u_int spc_smrdepth; /* level of smr nesting */ + u_char spc_smrexpedite; /* if set, dispatch smr entries + * without delay */ + u_char spc_smrgp; /* this CPU's view of grace period */ + volatile u_char spc_curpriority; /* [o] usrpri of curproc */ +}; + +/* spc_flags */ +#define SPCF_SEENRR 0x0001 /* process has seen roundrobin() */ +#define SPCF_SHOULDYIELD 0x0002 /* process should yield the CPU */ +#define SPCF_SWITCHCLEAR (SPCF_SEENRR|SPCF_SHOULDYIELD) +#define SPCF_SHOULDHALT 0x0004 /* CPU should be vacated */ +#define SPCF_HALTED 0x0008 /* CPU has been halted */ +#define SPCF_PROFCLOCK 0x0010 /* profclock() was started */ +#define SPCF_ITIMER 0x0020 /* itimer_update() was started */ + +#define SCHED_PPQ (128 / SCHED_NQS) /* priorities per queue */ +#define NICE_WEIGHT 2 /* priorities per nice level */ +#define ESTCPULIM(e) min((e), NICE_WEIGHT * PRIO_MAX - SCHED_PPQ) + +extern uint64_t roundrobin_period; + +struct proc; +void schedclock(struct proc *); +struct clockrequest; +void roundrobin(struct clockrequest *, void *, void *); +void scheduler_start(void); +void userret(struct proc *p); + +struct cpu_info; +void sched_init(void); +void sched_init_cpu(struct cpu_info *); +void sched_idle(void *); +void sched_exit(struct proc *); +void sched_toidle(void); +void mi_switch(void); +void cpu_switchto(struct proc *, struct proc *); +struct proc *sched_chooseproc(void); +struct cpu_info *sched_choosecpu(struct proc *); +struct cpu_info *sched_choosecpu_fork(struct proc *parent, int); +void cpu_idle_enter(void); +void cpu_idle_cycle(void); +void cpu_idle_leave(void); +void sched_peg_curproc(struct cpu_info *ci); +void sched_unpeg_curproc(void); +void sched_barrier(struct cpu_info *ci); + +int sysctl_hwsetperf(void *, size_t *, void *, size_t); +int sysctl_hwperfpolicy(void *, size_t *, void *, size_t); +int sysctl_hwsmt(void *, size_t *, void *, size_t); +int sysctl_hwncpuonline(void); + +#ifdef MULTIPROCESSOR +void sched_start_secondary_cpus(void); +void sched_stop_secondary_cpus(void); +#endif + +#define cpu_is_idle(ci) ((ci)->ci_schedstate.spc_whichqs == 0) +int cpu_is_online(struct cpu_info *); + +void setrunqueue(struct cpu_info *, struct proc *, uint8_t); +void remrunqueue(struct proc *); + +/* Chargeback parents for the sins of their children. */ +#define scheduler_wait_hook(parent, child) do { \ + (parent)->p_estcpu = ESTCPULIM((parent)->p_estcpu + (child)->p_estcpu);\ +} while (0) + +/* Allow other processes to progress */ +#define sched_pause(func) do { \ + if (curcpu()->ci_schedstate.spc_schedflags & SPCF_SHOULDYIELD) \ + func(); \ +} while (0) + +extern struct mutex sched_lock; + +#define SCHED_ASSERT_LOCKED() MUTEX_ASSERT_LOCKED(&sched_lock) +#define SCHED_ASSERT_UNLOCKED() MUTEX_ASSERT_UNLOCKED(&sched_lock) + +#define SCHED_LOCK_INIT() mtx_init(&sched_lock, IPL_SCHED) +#define SCHED_LOCK() mtx_enter(&sched_lock) +#define SCHED_UNLOCK() mtx_leave(&sched_lock) + +#endif /* _KERNEL */ +#endif /* _SYS_SCHED_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/scsiio.h b/lib/libc/include/generic-openbsd/sys/scsiio.h new file mode 100644 index 0000000000..90ae749bf4 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/scsiio.h @@ -0,0 +1,74 @@ +/* $OpenBSD: scsiio.h,v 1.10 2012/09/05 17:17:47 deraadt Exp $ */ +/* $NetBSD: scsiio.h,v 1.3 1994/06/29 06:45:09 cgd Exp $ */ + +#ifndef _SYS_SCSIIO_H_ +#define _SYS_SCSIIO_H_ + + +#include +#include + +#define SENSEBUFLEN 48 +#define CMDBUFLEN 16 + +typedef struct scsireq { + u_long flags; /* info about the request status and type */ + u_long timeout; + u_char cmd[CMDBUFLEN]; + u_char cmdlen; + caddr_t databuf; /* address in user space of buffer */ + u_long datalen; /* size of user buffer (request) */ + u_long datalen_used; /* size of user buffer (used)*/ + u_char sense[SENSEBUFLEN]; /* returned sense will be in here */ + u_char senselen; /* sensedata request size (MAX of SENSEBUFLEN)*/ + u_char senselen_used; /* return value only */ + u_char status; /* what the scsi status was from the adapter */ + u_char retsts; /* the return status for the command */ + int error; /* error bits */ +} scsireq_t; + +/* bit definitions for flags */ +#define SCCMD_READ 0x00000001 +#define SCCMD_WRITE 0x00000002 +#define SCCMD_IOV 0x00000004 +#define SCCMD_ESCAPE 0x00000010 +#define SCCMD_TARGET 0x00000020 + + +/* definitions for the return status (retsts) */ +#define SCCMD_OK 0x00 +#define SCCMD_TIMEOUT 0x01 +#define SCCMD_BUSY 0x02 +#define SCCMD_SENSE 0x03 +#define SCCMD_UNKNOWN 0x04 + +#define SCIOCCOMMAND _IOWR('Q', 1, scsireq_t) + +#define SC_DB_CMDS 0x00000001 /* show all scsi cmds and errors */ +#define SC_DB_FLOW 0x00000002 /* show routines entered */ +#define SC_DB_FLOW2 0x00000004 /* show path INSIDE routines */ +#define SC_DB_DMA 0x00000008 /* show DMA segments etc */ +#define SCIOCDEBUG _IOW('Q', 2, int) /* from 0 to 15 */ + +struct scsi_addr { + int type; +#define TYPE_SCSI 0 +#define TYPE_ATAPI 1 + int scbus; /* -1 if wildcard */ + int target; /* -1 if wildcard */ + int lun; /* -1 if wildcard */ +}; + +#define SCIOCRESET _IO('Q', 7) /* reset the device */ +#define SCIOCIDENTIFY _IOR('Q', 9, struct scsi_addr) + +struct sbioc_device { + void *sd_cookie; + int sd_target; + int sd_lun; +}; + +#define SBIOCPROBE _IOWR('Q', 127, struct sbioc_device) +#define SBIOCDETACH _IOWR('Q', 128, struct sbioc_device) + +#endif /* _SYS_SCSIIO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/select.h b/lib/libc/include/generic-openbsd/sys/select.h new file mode 100644 index 0000000000..7d9a52fc17 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/select.h @@ -0,0 +1,137 @@ +/* $OpenBSD: select.h,v 1.17 2016/09/12 19:41:20 guenther Exp $ */ + +/*- + * Copyright (c) 1992, 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. + * + * @(#)select.h 8.2 (Berkeley) 1/4/94 + */ + +#ifndef _SYS_SELECT_H_ +#define _SYS_SELECT_H_ + +#include + +#ifndef _TIMEVAL_DECLARED +#define _TIMEVAL_DECLARED +struct timeval { + time_t tv_sec; /* seconds */ + suseconds_t tv_usec; /* and microseconds */ +}; +#endif + +#ifndef _TIMESPEC_DECLARED +#define _TIMESPEC_DECLARED +struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +}; +#endif + +/* + * Select uses bit masks of file descriptors in longs. These macros + * manipulate such bit fields (the filesystem macros use chars). + * FD_SETSIZE may be defined by the user, but the default here should + * be enough for most uses. + */ +#ifndef FD_SETSIZE +#define FD_SETSIZE 1024 +#endif + +/* + * We don't want to pollute the namespace with select(2) internals. + * Non-underscore versions are exposed later #if __BSD_VISIBLE + */ +#define __NBBY 8 /* number of bits in a byte */ +typedef uint32_t __fd_mask; +#define __NFDBITS ((unsigned)(sizeof(__fd_mask) * __NBBY)) /* bits per mask */ +#define __howmany(x, y) (((x) + ((y) - 1)) / (y)) + +typedef struct fd_set { + __fd_mask fds_bits[__howmany(FD_SETSIZE, __NFDBITS)]; +} fd_set; + +static __inline void +__fd_set(int fd, fd_set *p) +{ + p->fds_bits[fd / __NFDBITS] |= (1U << (fd % __NFDBITS)); +} +#define FD_SET(n, p) __fd_set((n), (p)) + +static __inline void +__fd_clr(int fd, fd_set *p) +{ + p->fds_bits[fd / __NFDBITS] &= ~(1U << (fd % __NFDBITS)); +} +#define FD_CLR(n, p) __fd_clr((n), (p)) + +static __inline int +__fd_isset(int fd, const fd_set *p) +{ + return (p->fds_bits[fd / __NFDBITS] & (1U << (fd % __NFDBITS))); +} +#define FD_ISSET(n, p) __fd_isset((n), (p)) + +#if __BSD_VISIBLE +#define FD_COPY(f, t) (void)(*(t) = *(f)) +#endif +#define FD_ZERO(p) do { \ + fd_set *_p = (p); \ + __size_t _n = __howmany(FD_SETSIZE, __NFDBITS); \ + \ + while (_n > 0) \ + _p->fds_bits[--_n] = 0; \ +} while (0) + +#if __BSD_VISIBLE +#define NBBY __NBBY +#define fd_mask __fd_mask +#define NFDBITS __NFDBITS +#ifndef howmany +#define howmany(x, y) __howmany(x, y) +#endif +#endif /* __BSD_VISIBLE */ + +#ifndef _KERNEL +#ifndef _SIGSET_T_DEFINED_ +#define _SIGSET_T_DEFINED_ +typedef unsigned int sigset_t; +#endif + +#ifndef _SELECT_DEFINED_ +#define _SELECT_DEFINED_ +__BEGIN_DECLS +int select(int, fd_set * __restrict, fd_set * __restrict, + fd_set * __restrict, struct timeval * __restrict); +int pselect(int, fd_set * __restrict, fd_set * __restrict, + fd_set * __restrict, const struct timespec * __restrict, + const sigset_t * __restrict); +__END_DECLS +#endif +#endif /* !_KERNEL */ + +#endif /* !_SYS_SELECT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/selinfo.h b/lib/libc/include/generic-openbsd/sys/selinfo.h new file mode 100644 index 0000000000..15b07f3744 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/selinfo.h @@ -0,0 +1,51 @@ +/* $OpenBSD: selinfo.h,v 1.6 2022/07/05 15:06:16 visa Exp $ */ + +/*- + * Copyright (c) 1992, 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. + * + * @(#)select.h 8.2 (Berkeley) 1/4/94 + */ + +#ifndef _SYS_SELINFO_H_ +#define _SYS_SELINFO_H_ + +#include /* for struct klist */ + +/* + * Used to maintain information about processes that wish to be + * notified when I/O becomes possible. + */ +struct selinfo { + struct klist si_note; /* kernel note list */ +}; + +#ifdef _KERNEL +void selwakeup(struct selinfo *); +#endif + +#endif /* !_SYS_SELINFO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/sem.h b/lib/libc/include/generic-openbsd/sys/sem.h new file mode 100644 index 0000000000..621ec97144 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/sem.h @@ -0,0 +1,192 @@ +/* $OpenBSD: sem.h,v 1.26 2024/10/26 05:39:03 jsg Exp $ */ +/* $NetBSD: sem.h,v 1.8 1996/02/09 18:25:29 christos Exp $ */ + +/* + * SVID compatible sem.h file + * + * Author: Daniel Boulet + */ + +#ifndef _SYS_SEM_H_ +#define _SYS_SEM_H_ + +#ifndef _SYS_IPC_H_ +#include +#endif + +#if __BSD_VISIBLE + +/* sem-specific sysctl variables corresponding to members of struct seminfo */ +#define KERN_SEMINFO_SEMMNI 1 /* int: # of semaphore identifiers */ +#define KERN_SEMINFO_SEMMNS 2 /* int: # of semaphores in system */ +#define KERN_SEMINFO_SEMMNU 3 /* int: # of undo structures in system */ +#define KERN_SEMINFO_SEMMSL 4 /* int: max semaphores per id */ +#define KERN_SEMINFO_SEMOPM 5 /* int: max operations per semop call */ +#define KERN_SEMINFO_SEMUME 6 /* int: max undo entries per process */ +#define KERN_SEMINFO_SEMUSZ 7 /* int: size in bytes of struct undo */ +#define KERN_SEMINFO_SEMVMX 8 /* int: semaphore maximum value */ +#define KERN_SEMINFO_SEMAEM 9 /* int: adjust on exit max value */ +#define KERN_SEMINFO_MAXID 10 /* number of valid semaphore sysctls */ + +#define CTL_KERN_SEMINFO_NAMES { \ + { 0, 0 }, \ + { "semmni", CTLTYPE_INT }, \ + { "semmns", CTLTYPE_INT }, \ + { "semmnu", CTLTYPE_INT }, \ + { "semmsl", CTLTYPE_INT }, \ + { "semopm", CTLTYPE_INT }, \ + { "semume", CTLTYPE_INT }, \ + { "semusz", CTLTYPE_INT }, \ + { "semvmx", CTLTYPE_INT }, \ + { "semaem", CTLTYPE_INT }, \ +} + +#endif /* __BSD_VISIBLE */ + +struct sem { + unsigned short semval; /* semaphore value */ + pid_t sempid; /* pid of last operation */ + unsigned short semncnt; /* # awaiting semval > cval */ + unsigned short semzcnt; /* # awaiting semval = 0 */ +}; + +struct semid_ds { + struct ipc_perm sem_perm; /* operation permission struct */ + struct sem *sem_base; /* pointer to first semaphore in set */ + unsigned short sem_nsems; /* number of sems in set */ + time_t sem_otime; /* last operation time */ + long sem_pad1; /* SVABI/386 says I need this here */ + time_t sem_ctime; /* last change time */ + /* Times measured in secs since */ + /* 00:00:00 GMT, Jan. 1, 1970 */ + long sem_pad2; /* SVABI/386 says I need this here */ + long sem_pad3[4]; /* SVABI/386 says I need this here */ +}; + +/* + * semop's sops parameter structure + */ +struct sembuf { + unsigned short sem_num; /* semaphore # */ + short sem_op; /* semaphore operation */ + short sem_flg; /* operation flags */ +}; +#define SEM_UNDO 010000 + +/* + * semctl's arg parameter structure + */ +union semun { + int val; /* value for SETVAL */ + struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ + unsigned short *array; /* array for GETALL & SETALL */ +}; + +/* + * commands for semctl + */ +#define GETNCNT 3 /* Return the value of semncnt {READ} */ +#define GETPID 4 /* Return the value of sempid {READ} */ +#define GETVAL 5 /* Return the value of semval {READ} */ +#define GETALL 6 /* Return semvals into arg.array {READ} */ +#define GETZCNT 7 /* Return the value of semzcnt {READ} */ +#define SETVAL 8 /* Set the value of semval to arg.val {ALTER} */ +#define SETALL 9 /* Set semvals from arg.array {ALTER} */ + + +/* + * Permissions + */ +#define SEM_A 0200 /* alter permission */ +#define SEM_R 0400 /* read permission */ + + +#ifdef _KERNEL +#include + +/* + * Kernel implementation stuff + */ +#define SEMVMX 32767 /* semaphore maximum value */ +#define SEMAEM 16384 /* adjust on exit max value */ + +/* + * Undo structure (one per process) + */ +struct sem_undo { + SLIST_ENTRY(sem_undo) un_next; /* ptr to next active undo structure */ + struct process *un_proc; /* owner of this structure */ + short un_cnt; /* # of active entries */ + struct undo { + short un_adjval; /* adjust on exit values */ + short un_num; /* semaphore # */ + int un_id; /* semid */ + } un_ent[1]; /* undo entries */ +}; + +/* + * semaphore info struct + */ +struct seminfo { + int semmni, /* # of semaphore identifiers */ + semmns, /* # of semaphores in system */ + semmnu, /* # of undo structures in system */ + semmsl, /* max # of semaphores per id */ + semopm, /* max # of operations per semop call */ + semume, /* max # of undo entries per process */ + semusz, /* size in bytes of undo structure */ + semvmx, /* semaphore maximum value */ + semaem; /* adjust on exit max value */ +}; + +struct sem_sysctl_info { + struct seminfo seminfo; + struct semid_ds semids[1]; +}; + +extern struct seminfo seminfo; + +/* + * Configuration parameters + */ +#ifndef SEMMNI +#define SEMMNI 10 /* # of semaphore identifiers */ +#endif +#ifndef SEMMNS +#define SEMMNS 60 /* # of semaphores in system */ +#endif +#ifndef SEMUME +#define SEMUME 10 /* max # of undo entries per process */ +#endif +#ifndef SEMMNU +#define SEMMNU 30 /* # of undo structures in system */ +#endif + +/* shouldn't need tuning */ +#ifndef SEMMSL +#define SEMMSL SEMMNS /* max # of semaphores per id */ +#endif +#ifndef SEMOPM +#define SEMOPM 100 /* max # of operations per semop call */ +#endif + +/* actual size of an undo structure */ +#define SEMUSZ (sizeof(struct sem_undo)+sizeof(struct undo)*SEMUME) + +extern struct semid_ds **sema; /* semaphore id list */ + +void seminit(void); +void semexit(struct process *); +int sysctl_sysvsem(int *, u_int, void *, size_t *, void *, size_t); +#endif /* _KERNEL */ + +#ifndef _KERNEL +__BEGIN_DECLS +int semctl(int, int, int, ...); +int __semctl(int, int, int, union semun *); +int semget(key_t, int, int); +int semop(int, struct sembuf *, size_t); +__END_DECLS +#endif /* !_KERNEL */ + +#endif /* !_SYS_SEM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/sensors.h b/lib/libc/include/generic-openbsd/sys/sensors.h new file mode 100644 index 0000000000..86cd6a10ec --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/sensors.h @@ -0,0 +1,179 @@ +/* $OpenBSD: sensors.h,v 1.37 2020/07/15 07:13:57 kettenis Exp $ */ + +/* + * Copyright (c) 2003, 2004 Alexander Yurchenko + * Copyright (c) 2006 Constantine A. Murenin + * 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 _SYS_SENSORS_H_ +#define _SYS_SENSORS_H_ + +/* Sensor types */ +enum sensor_type { + SENSOR_TEMP, /* temperature (uK) */ + SENSOR_FANRPM, /* fan revolution speed */ + SENSOR_VOLTS_DC, /* voltage (uV DC) */ + SENSOR_VOLTS_AC, /* voltage (uV AC) */ + SENSOR_OHMS, /* resistance */ + SENSOR_WATTS, /* power (uW) */ + SENSOR_AMPS, /* current (uA) */ + SENSOR_WATTHOUR, /* power capacity (uWh) */ + SENSOR_AMPHOUR, /* power capacity (uAh) */ + SENSOR_INDICATOR, /* boolean indicator */ + SENSOR_INTEGER, /* generic integer value */ + SENSOR_PERCENT, /* percent (m%) */ + SENSOR_LUX, /* illuminance (ulx) */ + SENSOR_DRIVE, /* disk */ + SENSOR_TIMEDELTA, /* system time error (nSec) */ + SENSOR_HUMIDITY, /* humidity (m%RH) */ + SENSOR_FREQ, /* frequency (uHz) */ + SENSOR_ANGLE, /* angle (uDegrees) */ + SENSOR_DISTANCE, /* distance (uMeter) */ + SENSOR_PRESSURE, /* pressure (mPa) */ + SENSOR_ACCEL, /* acceleration (u m/s^2) */ + SENSOR_VELOCITY, /* velocity (u m/s) */ + SENSOR_ENERGY, /* energy (uJ) */ + SENSOR_MAX_TYPES +}; + +#ifndef _KERNEL +static const char * const sensor_type_s[SENSOR_MAX_TYPES + 1] = { + "temp", + "fan", + "volt", + "acvolt", + "resistance", + "power", + "current", + "watthour", + "amphour", + "indicator", + "raw", + "percent", + "illuminance", + "drive", + "timedelta", + "humidity", + "frequency", + "angle", + "distance", + "pressure", + "acceleration", + "velocity", + "energy", + "undefined" +}; +#endif /* !_KERNEL */ + +#define SENSOR_DRIVE_EMPTY 1 +#define SENSOR_DRIVE_READY 2 +#define SENSOR_DRIVE_POWERUP 3 +#define SENSOR_DRIVE_ONLINE 4 +#define SENSOR_DRIVE_IDLE 5 +#define SENSOR_DRIVE_ACTIVE 6 +#define SENSOR_DRIVE_REBUILD 7 +#define SENSOR_DRIVE_POWERDOWN 8 +#define SENSOR_DRIVE_FAIL 9 +#define SENSOR_DRIVE_PFAIL 10 + +/* Sensor states */ +enum sensor_status { + SENSOR_S_UNSPEC, /* status is unspecified */ + SENSOR_S_OK, /* status is ok */ + SENSOR_S_WARN, /* status is warning */ + SENSOR_S_CRIT, /* status is critical */ + SENSOR_S_UNKNOWN /* status is unknown */ +}; + +/* Sensor data: + * New fields should be added at the end to encourage backwards compat + */ +struct sensor { + char desc[32]; /* sensor description, may be empty */ + struct timeval tv; /* sensor value last change time */ + int64_t value; /* current value */ + enum sensor_type type; /* sensor type */ + enum sensor_status status; /* sensor status */ + int numt; /* sensor number of .type type */ + int flags; /* sensor flags */ +#define SENSOR_FINVALID 0x0001 /* sensor is invalid */ +#define SENSOR_FUNKNOWN 0x0002 /* sensor value is unknown */ +}; + +/* Sensor device data: + * New fields should be added at the end to encourage backwards compat + */ +struct sensordev { + int num; /* sensordev number */ + char xname[16]; /* unix device name */ + int maxnumt[SENSOR_MAX_TYPES]; + int sensors_count; +}; + +#ifdef _KERNEL + +/* Sensor data */ +struct ksensor { + SLIST_ENTRY(ksensor) list; /* device-scope list */ + char desc[32]; /* sensor description, may be empty */ + struct timeval tv; /* sensor value last change time */ + int64_t value; /* current value */ + enum sensor_type type; /* sensor type */ + enum sensor_status status; /* sensor status */ + int numt; /* sensor number of .type type */ + int flags; /* sensor flags, ie. SENSOR_FINVALID */ +}; +SLIST_HEAD(ksensors_head, ksensor); + +/* Sensor device data */ +struct ksensordev { + SLIST_ENTRY(ksensordev) list; + int num; /* sensordev number */ + char xname[16]; /* unix device name */ + int maxnumt[SENSOR_MAX_TYPES]; + int sensors_count; + struct ksensors_head sensors_list; +}; + +/* struct ksensordev */ +void sensordev_install(struct ksensordev *); +void sensordev_deinstall(struct ksensordev *); +int sensordev_get(int, struct ksensordev **); + +/* struct ksensor */ +void sensor_attach(struct ksensordev *, struct ksensor *); +void sensor_detach(struct ksensordev *, struct ksensor *); +int sensor_find(int, enum sensor_type, int, struct ksensor **); + +/* task scheduling */ +struct sensor_task; +struct sensor_task *sensor_task_register(void *, void (*)(void *), + unsigned int); +void sensor_task_unregister(struct sensor_task *); +void sensor_quiesce(void); +void sensor_restart(void); + +#endif /* _KERNEL */ + +#endif /* !_SYS_SENSORS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/shm.h b/lib/libc/include/generic-openbsd/sys/shm.h new file mode 100644 index 0000000000..b3e2acabda --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/shm.h @@ -0,0 +1,150 @@ +/* $OpenBSD: shm.h,v 1.31 2024/10/26 05:39:03 jsg Exp $ */ +/* $NetBSD: shm.h,v 1.20 1996/04/09 20:55:35 cgd Exp $ */ + +/* + * Copyright (c) 1994 Adam Glass + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Adam Glass. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY 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. + */ + +/* + * As defined+described in "X/Open System Interfaces and Headers" + * Issue 4, p. XXX + */ + +#ifndef _SYS_SHM_H_ +#define _SYS_SHM_H_ + +#ifndef _SYS_IPC_H_ +#include +#endif + +#if __BSD_VISIBLE + +/* shm-specific sysctl variables corresponding to members of struct shminfo */ +#define KERN_SHMINFO_SHMMAX 1 /* int: max shm segment size (bytes) */ +#define KERN_SHMINFO_SHMMIN 2 /* int: min shm segment size (bytes) */ +#define KERN_SHMINFO_SHMMNI 3 /* int: max number of shm identifiers */ +#define KERN_SHMINFO_SHMSEG 4 /* int: max shm segments per process */ +#define KERN_SHMINFO_SHMALL 5 /* int: max amount of shm (pages) */ +#define KERN_SHMINFO_MAXID 6 /* number of valid shared memory ids */ + +#define CTL_KERN_SHMINFO_NAMES { \ + { 0, 0 }, \ + { "shmmax", CTLTYPE_INT }, \ + { "shmmin", CTLTYPE_INT }, \ + { "shmmni", CTLTYPE_INT }, \ + { "shmseg", CTLTYPE_INT }, \ + { "shmall", CTLTYPE_INT }, \ +} + +/* + * Old (deprecated) access mode definitions--do not use. + * Provided for compatibility with old code only. + */ +#define SHM_R IPC_R +#define SHM_W IPC_W + +#endif /* __BSD_VISIBLE */ + +/* + * Shared memory operation flags for shmat(2). + */ +#define SHM_RDONLY 010000 /* Attach read-only (else read-write) */ +#define SHM_RND 020000 /* Round attach address to SHMLBA */ + +/* + * Shared memory specific control commands for shmctl(). + * We accept but ignore these (XXX). + */ +#define SHM_LOCK 3 /* Lock segment in memory. */ +#define SHM_UNLOCK 4 /* Unlock a segment locked by SHM_LOCK. */ + +/* + * Segment low boundary address multiple + */ +#define SHMLBA (1U << _MAX_PAGE_SHIFT) + +typedef short shmatt_t; + +struct shmid_ds { + struct ipc_perm shm_perm; /* operation permission structure */ + int shm_segsz; /* size of segment in bytes */ + pid_t shm_lpid; /* process ID of last shm op */ + pid_t shm_cpid; /* process ID of creator */ + shmatt_t shm_nattch; /* number of current attaches */ + time_t shm_atime; /* time of last shmat() */ + long __shm_atimensec; + time_t shm_dtime; /* time of last shmdt() */ + long __shm_dtimensec; + time_t shm_ctime; /* time of last change by shmctl() */ + long __shm_ctimensec; + void *shm_internal; /* implementation specific data */ +}; + +#if __BSD_VISIBLE +/* + * System V style catch-all structure for shared memory constants that + * might be of interest to user programs. Do we really want/need this? + */ +struct shminfo { + int shmmax; /* max shared memory segment size (bytes) */ + int shmmin; /* min shared memory segment size (bytes) */ + int shmmni; /* max number of shared memory identifiers */ + int shmseg; /* max shared memory segments per process */ + int shmall; /* max amount of shared memory (pages) */ +}; + +struct shm_sysctl_info { + struct shminfo shminfo; + struct shmid_ds shmids[1]; +}; +#endif /* __BSD_VISIBLE */ + +#ifdef _KERNEL +extern struct shminfo shminfo; +extern struct shmid_ds **shmsegs; + +struct vmspace; + +void shminit(void); +void shmfork(struct vmspace *, struct vmspace *); +void shmexit(struct vmspace *); +int sysctl_sysvshm(int *, u_int, void *, size_t *, void *, size_t); + +#else /* !_KERNEL */ + +__BEGIN_DECLS +void *shmat(int, const void *, int); +int shmctl(int, int, struct shmid_ds *); +int shmdt(const void *); +int shmget(key_t, size_t, int); +__END_DECLS + +#endif /* !_KERNEL */ + +#endif /* !_SYS_SHM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/siginfo.h b/lib/libc/include/generic-openbsd/sys/siginfo.h new file mode 100644 index 0000000000..45f151144f --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/siginfo.h @@ -0,0 +1,200 @@ +/* $OpenBSD: siginfo.h,v 1.14 2024/02/21 15:53:07 deraadt Exp $ */ + +/* + * Copyright (c) 1997 Theo de Raadt + * 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 _SYS_SIGINFO_H +#define _SYS_SIGINFO_H + +#include + +union sigval { + int sival_int; /* integer value */ + void *sival_ptr; /* pointer value */ +}; + +/* + * Negative signal codes are reserved for future use for + * user generated signals. + */ +#define SI_FROMUSER(sip) ((sip)->si_code <= 0) +#define SI_FROMKERNEL(sip) ((sip)->si_code > 0) + +#define SI_NOINFO 32767 /* no signal information */ +#define SI_USER 0 /* user generated signal via kill() */ +#define SI_LWP (-1) /* user generated signal via lwp_kill()*/ +#define SI_QUEUE (-2) /* user generated signal via sigqueue()*/ +#define SI_TIMER (-3) /* from timer expiration */ + +#if __POSIX_VISIBLE >= 199309 || __XPG_VISIBLE +/* + * The machine dependent signal codes (SIGILL, SIGFPE, + * SIGSEGV, and SIGBUS) + */ +#define ILL_ILLOPC 1 /* illegal opcode */ +#define ILL_ILLOPN 2 /* illegal operand */ +#define ILL_ILLADR 3 /* illegal addressing mode */ +#define ILL_ILLTRP 4 /* illegal trap */ +#define ILL_PRVOPC 5 /* privileged opcode */ +#define ILL_PRVREG 6 /* privileged register */ +#define ILL_COPROC 7 /* co-processor */ +#define ILL_BADSTK 8 /* bad stack */ +#define ILL_BTCFI 9 /* IBT missing on indirect call */ +#define NSIGILL 9 + +#define EMT_TAGOVF 1 /* tag overflow */ +#define NSIGEMT 1 + +#define FPE_INTDIV 1 /* integer divide by zero */ +#define FPE_INTOVF 2 /* integer overflow */ +#define FPE_FLTDIV 3 /* floating point divide by zero */ +#define FPE_FLTOVF 4 /* floating point overflow */ +#define FPE_FLTUND 5 /* floating point underflow */ +#define FPE_FLTRES 6 /* floating point inexact result */ +#define FPE_FLTINV 7 /* invalid floating point operation */ +#define FPE_FLTSUB 8 /* subscript out of range */ +#define NSIGFPE 8 + +#define SEGV_MAPERR 1 /* address not mapped to object */ +#define SEGV_ACCERR 2 /* invalid permissions */ +#define NSIGSEGV 2 + +#define BUS_ADRALN 1 /* invalid address alignment */ +#define BUS_ADRERR 2 /* non-existent physical address */ +#define BUS_OBJERR 3 /* object specific hardware error */ +#define NSIGBUS 3 + +#endif /* __POSIX_VISIBLE >= 199309 || __XPG_VISIBLE */ + +/* + * SIGTRAP signal codes + */ +#define TRAP_BRKPT 1 /* breakpoint trap */ +#define TRAP_TRACE 2 /* trace trap */ +#define NSIGTRAP 2 + +/* + * SIGCHLD signal codes + */ +#define CLD_EXITED 1 /* child has exited */ +#define CLD_KILLED 2 /* child was killed */ +#define CLD_DUMPED 3 /* child has coredumped */ +#define CLD_TRAPPED 4 /* traced child has stopped */ +#define CLD_STOPPED 5 /* child has stopped on signal */ +#define CLD_CONTINUED 6 /* stopped child has continued */ +#define NSIGCLD 6 + +#if 0 +/* + * SIGPOLL signal codes - not supported + */ +#define POLL_IN 1 /* input available */ +#define POLL_OUT 2 /* output possible */ +#define POLL_MSG 3 /* message available */ +#define POLL_ERR 4 /* I/O error */ +#define POLL_PRI 5 /* high priority input available */ +#define POLL_HUP 6 /* device disconnected */ +#define NSIGPOLL 6 + +/* + * SIGPROF signal codes - not supported + */ +#define PROF_SIG 1 /* have to set code non-zero */ +#define NSIGPROF 1 +#endif + +#define SI_MAXSZ 128 +#define SI_PAD ((SI_MAXSZ / sizeof (int)) - 3) + +#include + +typedef struct { + int si_signo; /* signal from signal.h */ + int si_code; /* code from above */ + int si_errno; /* error from errno.h */ + union { + int _pad[SI_PAD]; /* for future growth */ + struct { /* kill(), SIGCHLD */ + pid_t _pid; /* process ID */ + uid_t _uid; + union { + struct { + union sigval _value; + } _kill; + struct { + clock_t _utime; + clock_t _stime; + int _status; + } _cld; + } _pdata; + } _proc; + struct { /* SIGSEGV, SIGBUS, SIGILL and SIGFPE */ + void *_addr; /* faulting address */ + int _trapno; /* illegal trap number */ + } _fault; +#if 0 + struct { /* SIGPOLL, SIGXFSZ */ + /* fd not currently available for SIGPOLL */ + int _fd; /* file descriptor */ + long _band; + } _file; + struct { /* SIGPROF */ + caddr_t _faddr; /* last fault address */ + timespec _tstamp; /* real time stamp */ + short _syscall; /* current syscall */ + char _nsysarg; /* number of arguments */ + char _fault; /* last fault type */ + long _sysarg[8]; /* syscall arguments */ + long _mstate[17]; /* exactly fills struct*/ + } _prof; +#endif + } _data; +} siginfo_t; + +#define si_pid _data._proc._pid +#define si_uid _data._proc._uid + +#define si_status _data._proc._pdata._cld._status +#define si_stime _data._proc._pdata._cld._stime +#define si_utime _data._proc._pdata._cld._utime +#define si_value _data._proc._pdata._kill._value +#define si_addr _data._fault._addr +#define si_trapno _data._fault._trapno +#define si_fd _data._file._fd +#define si_band _data._file._band + +#define si_tstamp _data._prof._tstamp +#define si_syscall _data._prof._syscall +#define si_nsysarg _data._prof._nsysarg +#define si_sysarg _data._prof._sysarg +#define si_fault _data._prof._fault +#define si_faddr _data._prof._faddr +#define si_mstate _data._prof._mstate + +#if defined(_KERNEL) +void initsiginfo(siginfo_t *, int, u_long, int, union sigval); +#endif + +#endif /* _SYS_SIGINFO_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/sigio.h b/lib/libc/include/generic-openbsd/sys/sigio.h new file mode 100644 index 0000000000..7119f971bf --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/sigio.h @@ -0,0 +1,95 @@ +/* $OpenBSD: sigio.h,v 1.4 2020/01/08 16:27:42 visa 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. + * + * @(#)filedesc.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: head/sys/sys/sigio.h 326023 2017-11-20 19:43:44Z pfg $ + */ + +#ifndef _SYS_SIGIO_H_ +#define _SYS_SIGIO_H_ + +struct sigio; +LIST_HEAD(sigiolst, sigio); + +/* + * sigio registration + * + * Locking: + * S sigio_lock + */ +struct sigio_ref { + struct sigio *sir_sigio; /* [S] associated sigio struct */ +}; + +#ifdef _KERNEL + +/* + * This structure holds the information needed to send a SIGIO or + * a SIGURG signal to a process or process group when new data arrives + * on a device or socket. The structure is placed on an LIST belonging + * to the proc or pgrp so that the entire list may be revoked when the + * process exits or the process group disappears. + * + * Locking: + * I immutable after creation + * S sigio_lock + */ +struct sigio { + union { + struct process *siu_proc; + /* [I] process to receive + * SIGIO/SIGURG */ + struct pgrp *siu_pgrp; /* [I] process group to receive ... */ + } sio_u; + LIST_ENTRY(sigio) sio_pgsigio; /* [S] sigio's for process or group */ + struct sigio_ref *sio_myref; /* [I] location of the pointer that + * holds the reference to + * this structure */ + struct ucred *sio_ucred; /* [I] current credentials */ + pid_t sio_pgid; /* [I] pgid for signals */ +}; +#define sio_proc sio_u.siu_proc +#define sio_pgrp sio_u.siu_pgrp + +static inline void +sigio_init(struct sigio_ref *sir) +{ + sir->sir_sigio = NULL; +} + +void sigio_copy(struct sigio_ref *, struct sigio_ref *); +void sigio_free(struct sigio_ref *); +void sigio_freelist(struct sigiolst *); +void sigio_getown(struct sigio_ref *, u_long, caddr_t); +int sigio_setown(struct sigio_ref *, u_long, caddr_t); + +#endif /* _KERNEL */ + +#endif /* _SYS_SIGIO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/signal.h b/lib/libc/include/generic-openbsd/sys/signal.h new file mode 100644 index 0000000000..9303ad8ac2 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/signal.h @@ -0,0 +1,202 @@ +/* $OpenBSD: signal.h,v 1.29 2018/04/18 16:05:20 deraadt Exp $ */ +/* $NetBSD: signal.h,v 1.21 1996/02/09 18:25:32 christos Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1989, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)signal.h 8.2 (Berkeley) 1/21/94 + */ + +#ifndef _SYS_SIGNAL_H_ +#define _SYS_SIGNAL_H_ + +#include /* sigcontext; codes for SIGILL, SIGFPE */ + +#define _NSIG 33 /* counting 0 (mask is 1-32) */ + +#if __BSD_VISIBLE +#define NSIG _NSIG +#endif + +#define SIGHUP 1 /* hangup */ +#define SIGINT 2 /* interrupt */ +#define SIGQUIT 3 /* quit */ +#define SIGILL 4 /* illegal instruction (not reset when caught) */ +#define SIGTRAP 5 /* trace trap (not reset when caught) */ +#define SIGABRT 6 /* abort() */ +#if __BSD_VISIBLE +#define SIGIOT SIGABRT /* compatibility */ +#define SIGEMT 7 /* EMT instruction */ +#endif +#define SIGFPE 8 /* floating point exception */ +#define SIGKILL 9 /* kill (cannot be caught or ignored) */ +#define SIGBUS 10 /* bus error */ +#define SIGSEGV 11 /* segmentation violation */ +#define SIGSYS 12 /* bad argument to system call */ +#define SIGPIPE 13 /* write on a pipe with no one to read it */ +#define SIGALRM 14 /* alarm clock */ +#define SIGTERM 15 /* software termination signal from kill */ +#define SIGURG 16 /* urgent condition on IO channel */ +#define SIGSTOP 17 /* sendable stop signal not from tty */ +#define SIGTSTP 18 /* stop signal from tty */ +#define SIGCONT 19 /* continue a stopped process */ +#define SIGCHLD 20 /* to parent on child stop or exit */ +#define SIGTTIN 21 /* to readers pgrp upon background tty read */ +#define SIGTTOU 22 /* like TTIN for output if (tp->t_local<OSTOP) */ +#if __BSD_VISIBLE +#define SIGIO 23 /* input/output possible signal */ +#endif +#define SIGXCPU 24 /* exceeded CPU time limit */ +#define SIGXFSZ 25 /* exceeded file size limit */ +#define SIGVTALRM 26 /* virtual time alarm */ +#define SIGPROF 27 /* profiling time alarm */ +#if __BSD_VISIBLE +#define SIGWINCH 28 /* window size changes */ +#define SIGINFO 29 /* information request */ +#endif +#define SIGUSR1 30 /* user defined signal 1 */ +#define SIGUSR2 31 /* user defined signal 2 */ +#if __BSD_VISIBLE +#define SIGTHR 32 /* thread library AST */ +#endif + +/* + * Language spec says we must list exactly one parameter, even though we + * actually supply three. Ugh! + */ +#define SIG_DFL (void (*)(int))0 +#define SIG_IGN (void (*)(int))1 +#define SIG_ERR (void (*)(int))-1 + +#if __POSIX_VISIBLE || __XPG_VISIBLE +#ifndef _SIGSET_T_DEFINED_ +#define _SIGSET_T_DEFINED_ +typedef unsigned int sigset_t; +#endif + +#include + +/* + * Signal vector "template" used in sigaction call. + */ +struct sigaction { + union { /* signal handler */ + void (*__sa_handler)(int); + void (*__sa_sigaction)(int, siginfo_t *, void *); + } __sigaction_u; + sigset_t sa_mask; /* signal mask to apply */ + int sa_flags; /* see signal options below */ +}; + +/* if SA_SIGINFO is set, sa_sigaction is to be used instead of sa_handler. */ +#define sa_handler __sigaction_u.__sa_handler +#define sa_sigaction __sigaction_u.__sa_sigaction + +#if __XPG_VISIBLE >= 500 +#define SA_ONSTACK 0x0001 /* take signal on signal stack */ +#define SA_RESTART 0x0002 /* restart system on signal return */ +#define SA_RESETHAND 0x0004 /* reset to SIG_DFL when taking signal */ +#define SA_NODEFER 0x0010 /* don't mask the signal we're delivering */ +#define SA_NOCLDWAIT 0x0020 /* don't create zombies (assign to pid 1) */ +#endif /* __XPG_VISIBLE >= 500 */ +#define SA_NOCLDSTOP 0x0008 /* do not generate SIGCHLD on child stop */ +#if __POSIX_VISIBLE >= 199309 || __XPG_VISIBLE >= 500 +#define SA_SIGINFO 0x0040 /* generate siginfo_t */ +#endif + +/* + * Flags for sigprocmask: + */ +#define SIG_BLOCK 1 /* block specified signal set */ +#define SIG_UNBLOCK 2 /* unblock specified signal set */ +#define SIG_SETMASK 3 /* set specified signal set */ +#endif /* __POSIX_VISIBLE || __XPG_VISIBLE */ + +#if __BSD_VISIBLE +typedef void (*sig_t)(int); /* type of signal function */ + +/* + * 4.3 compatibility: + * Signal vector "template" used in sigvec call. + */ +struct sigvec { + void (*sv_handler)(int); /* signal handler */ + int sv_mask; /* signal mask to apply */ + int sv_flags; /* see signal options below */ +}; +#define SV_ONSTACK SA_ONSTACK +#define SV_INTERRUPT SA_RESTART /* same bit, opposite sense */ +#define SV_RESETHAND SA_RESETHAND +#define sv_onstack sv_flags /* isn't compatibility wonderful! */ + +/* + * Macro for converting signal number to a mask suitable for + * sigblock(). + */ +#define sigmask(m) (1U << ((m)-1)) + +#define BADSIG SIG_ERR + +#endif /* __BSD_VISIBLE */ + +#if __BSD_VISIBLE || __XPG_VISIBLE >= 420 +/* + * Structure used in sigaltstack call. + */ +typedef struct sigaltstack { + void *ss_sp; /* signal stack base */ + size_t ss_size; /* signal stack length */ + int ss_flags; /* SS_DISABLE and/or SS_ONSTACK */ +} stack_t; +#define SS_ONSTACK 0x0001 /* take signals on alternate stack */ +#define SS_DISABLE 0x0004 /* disable taking signals on alternate stack */ +#define MINSIGSTKSZ (3U << _MAX_PAGE_SHIFT) /* minimum allowable stack */ +#if _MAX_PAGE_SHIFT < 14 /* recommended stack size */ +#define SIGSTKSZ (MINSIGSTKSZ + (1U << _MAX_PAGE_SHIFT) * 4) +#else +#define SIGSTKSZ (MINSIGSTKSZ + (1U << _MAX_PAGE_SHIFT) * 2) +#endif + +typedef struct sigcontext ucontext_t; +#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */ + +#ifndef _KERNEL +/* + * For historical reasons; programs expect signal's return value to be + * defined by . + */ +__BEGIN_DECLS +void (*signal(int, void (*)(int)))(int); +__END_DECLS +#endif /* !_KERNEL */ +#endif /* !_SYS_SIGNAL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/signalvar.h b/lib/libc/include/generic-openbsd/sys/signalvar.h new file mode 100644 index 0000000000..defb09c77a --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/signalvar.h @@ -0,0 +1,140 @@ +/* $OpenBSD: signalvar.h,v 1.58 2025/03/10 09:28:57 claudio Exp $ */ +/* $NetBSD: signalvar.h,v 1.17 1996/04/22 01:23:31 christos Exp $ */ + +/* + * Copyright (c) 1991, 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. + * + * @(#)signalvar.h 8.3 (Berkeley) 1/4/94 + */ + +#ifndef _SYS_SIGNALVAR_H_ /* tmp for user.h */ +#define _SYS_SIGNALVAR_H_ + +/* + * Kernel signal definitions and data structures, + * not exported to user programs. + */ + +/* + * Process signal actions and state, needed only within the process + * (not necessarily resident). + * + * Locks used to protect struct members in struct sigacts: + * a atomic operations + * m this process' `ps_mtx' + */ +struct sigacts { + sig_t ps_sigact[NSIG]; /* [m] disposition of signals */ + sigset_t ps_catchmask[NSIG]; /* [m] signals to be blocked */ + sigset_t ps_sigonstack; /* [m] signals to take on sigstack */ + sigset_t ps_sigintr; /* [m] signals interrupt syscalls */ + sigset_t ps_sigreset; /* [m] signals that reset when caught */ + sigset_t ps_siginfo; /* [m] signals that provide siginfo */ + sigset_t ps_sigignore; /* [m] signals being ignored */ + sigset_t ps_sigcatch; /* [m] signals being caught by user */ + int ps_sigflags; /* [a] signal flags, below */ +}; + +/* signal flags */ +#define SAS_NOCLDSTOP 0x01 /* No SIGCHLD when children stop. */ +#define SAS_NOCLDWAIT 0x02 /* No zombies if child dies */ + +/* additional signal action values, used only temporarily/internally */ +#define SIG_CATCH (void (*)(int))2 +#define SIG_HOLD (void (*)(int))3 + +/* + * Check if process p has an unmasked signal pending. + * Return mask of pending signals. + */ +#define SIGPENDING(p) \ + (((p)->p_siglist | (p)->p_p->ps_siglist) & ~(p)->p_sigmask) + +/* + * Signal properties and actions. + */ +#define SA_KILL 0x01 /* terminates process by default */ +#define SA_CORE 0x02 /* ditto and coredumps */ +#define SA_STOP 0x04 /* suspend process */ +#define SA_TTYSTOP 0x08 /* ditto, from tty */ +#define SA_IGNORE 0x10 /* ignore by default */ +#define SA_CONT 0x20 /* continue if suspended */ +#define SA_CANTMASK 0x40 /* non-maskable, catchable */ + +#define sigcantmask (sigmask(SIGKILL) | sigmask(SIGSTOP)) + +#ifdef _KERNEL +enum signal_type { SPROCESS, STHREAD }; + +struct sigio_ref; + +struct sigctx { + sig_t sig_action; + sigset_t sig_catchmask; + int sig_onstack; + int sig_intr; + int sig_reset; + int sig_info; + int sig_ignore; + int sig_catch; + int sig_stop; +}; + +/* + * Machine-independent functions: + */ +int coredump(struct proc *p); +void execsigs(struct proc *p); +int cursig(struct proc *p, struct sigctx *, int); +void pgsigio(struct sigio_ref *sir, int sig, int checkctty); +void pgsignal(struct pgrp *pgrp, int sig, int checkctty); +void psignal(struct proc *p, int sig); +void ptsignal(struct proc *p, int sig, enum signal_type type); +void prsignal(struct process *pr, int sig); +void trapsignal(struct proc *p, int sig, u_long code, int type, + union sigval val); +__dead void sigexit(struct proc *, int); +void sigabort(struct proc *); +int sigismasked(struct proc *, int); +int sigonstack(size_t); +int killpg1(struct proc *, int, int, int); + +void signal_init(void); + +void sigstkinit(struct sigaltstack *); +struct sigacts *sigactsinit(struct process *); +void sigactsfree(struct sigacts *); +void siginit(struct sigacts *); + +/* + * Machine-dependent functions: + */ +int sendsig(sig_t _catcher, int _sig, sigset_t _mask, const siginfo_t *_si, + int _info, int _onstack); +#endif /* _KERNEL */ +#endif /* !_SYS_SIGNALVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/smr.h b/lib/libc/include/generic-openbsd/sys/smr.h new file mode 100644 index 0000000000..30ac0d9f53 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/smr.h @@ -0,0 +1,440 @@ +/* $OpenBSD: smr.h,v 1.9 2022/07/25 08:06:44 visa Exp $ */ + +/* + * Copyright (c) 2019 Visa Hankala + * + * 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 _SYS_SMR_H_ +#define _SYS_SMR_H_ + +#include + +struct smr_entry { + SIMPLEQ_ENTRY(smr_entry) smr_list; + void (*smr_func)(void *); + void *smr_arg; +}; + +SIMPLEQ_HEAD(smr_entry_list, smr_entry); + +#ifdef _KERNEL + +#include + +void smr_startup(void); +void smr_startup_thread(void); +void smr_idle(void); +void smr_read_enter(void); +void smr_read_leave(void); + +void smr_call_impl(struct smr_entry *, void (*)(void *), void *, int); +void smr_barrier_impl(int); + +#define smr_call(entry, func, arg) smr_call_impl(entry, func, arg, 0) +#define smr_barrier() smr_barrier_impl(0) +#define smr_flush() smr_barrier_impl(1) + +static inline void +smr_init(struct smr_entry *smr) +{ + smr->smr_func = NULL; + smr->smr_arg = NULL; +} + +#ifdef DIAGNOSTIC +#define SMR_ASSERT_CRITICAL() do { \ + if (panicstr == NULL && !db_active) \ + KASSERT(curcpu()->ci_schedstate.spc_smrdepth > 0); \ +} while (0) +#define SMR_ASSERT_NONCRITICAL() do { \ + if (panicstr == NULL && !db_active) \ + KASSERT(curcpu()->ci_schedstate.spc_smrdepth == 0); \ +} while (0) +#else +#define SMR_ASSERT_CRITICAL() do {} while (0) +#define SMR_ASSERT_NONCRITICAL() do {} while (0) +#endif + +#endif /* _KERNEL */ + +#define SMR_PTR_GET(pptr) READ_ONCE(*pptr) + +#define SMR_PTR_GET_LOCKED(pptr) (*(pptr)) + +#define SMR_PTR_SET_LOCKED(pptr, val) do { \ + membar_producer(); \ + WRITE_ONCE(*pptr, val); \ +} while (0) + +/* + * List implementations for use with safe memory reclamation. + */ + +/* + * Copyright (c) 1991, 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. + * + * @(#)queue.h 8.5 (Berkeley) 8/20/94 + */ + +#include + +/* + * This file defines three types of data structures: singly-linked lists, + * lists, and tail queues. + * + * + * A singly-linked list is headed by a single forward pointer. The elements + * are singly linked for minimum space and pointer manipulation overhead at + * the expense of O(n) removal for arbitrary elements. New elements can be + * added to the list after an existing element or at the head of the list. + * Elements being removed from the head of the list should use the explicit + * macro for this purpose for optimum efficiency. A singly-linked list may + * only be traversed in the forward direction. Singly-linked lists are ideal + * for applications with large datasets and few or no removals or for + * implementing a LIFO queue. + * + * A list is headed by a single forward pointer (or an array of forward + * pointers for a hash table header). The elements are doubly linked + * so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before + * or after an existing element or at the head of the list. A list + * may only be traversed in the forward direction. + * + * A tail queue is headed by a pair of pointers, one to the head of the + * list and the other to the tail of the list. The elements are doubly + * linked so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before or + * after an existing element, at the head of the list, or at the end of + * the list. A tail queue may only be traversed in the forward direction + * by lock-free readers. + */ + +/* + * Singly-linked List definitions. + */ +#define SMR_SLIST_HEAD(name, type) \ +struct name { \ + struct type *smr_slh_first; /* first element, SMR-protected */\ +} + +#define SMR_SLIST_HEAD_INITIALIZER(head) \ + { .smr_slh_first = NULL } + +#define SMR_SLIST_ENTRY(type) \ +struct { \ + struct type *smr_sle_next; /* next element, SMR-protected */\ +} + +/* + * Singly-linked List access methods. + */ +#define SMR_SLIST_END(head) NULL + +#define SMR_SLIST_FIRST(head) \ + SMR_PTR_GET(&(head)->smr_slh_first) +#define SMR_SLIST_NEXT(elm, field) \ + SMR_PTR_GET(&(elm)->field.smr_sle_next) + +#define SMR_SLIST_FIRST_LOCKED(head) \ + SMR_PTR_GET_LOCKED(&(head)->smr_slh_first) +#define SMR_SLIST_EMPTY_LOCKED(head) \ + (SMR_SLIST_FIRST_LOCKED(head) == SMR_SLIST_END(head)) +#define SMR_SLIST_NEXT_LOCKED(elm, field) \ + SMR_PTR_GET_LOCKED(&(elm)->field.smr_sle_next) + +#define SMR_SLIST_FOREACH(var, head, field) \ + for ((var) = SMR_SLIST_FIRST(head); \ + (var) != SMR_SLIST_END(head); \ + (var) = SMR_SLIST_NEXT(var, field)) + +#define SMR_SLIST_FOREACH_LOCKED(var, head, field) \ + for ((var) = SMR_SLIST_FIRST_LOCKED(head); \ + (var) != SMR_SLIST_END(head); \ + (var) = SMR_SLIST_NEXT_LOCKED(var, field)) + +#define SMR_SLIST_FOREACH_SAFE_LOCKED(var, head, field, tvar) \ + for ((var) = SMR_SLIST_FIRST_LOCKED(head); \ + (var) && ((tvar) = SMR_SLIST_NEXT_LOCKED(var, field), 1); \ + (var) = (tvar)) + +/* + * Singly-linked List functions. + */ +#define SMR_SLIST_INIT(head) do { \ + (head)->smr_slh_first = SMR_SLIST_END(head); \ +} while (0) + +#define SMR_SLIST_INSERT_AFTER_LOCKED(slistelm, elm, field) do { \ + (elm)->field.smr_sle_next = (slistelm)->field.smr_sle_next; \ + membar_producer(); \ + (slistelm)->field.smr_sle_next = (elm); \ +} while (0) + +#define SMR_SLIST_INSERT_HEAD_LOCKED(head, elm, field) do { \ + (elm)->field.smr_sle_next = (head)->smr_slh_first; \ + membar_producer(); \ + (head)->smr_slh_first = (elm); \ +} while (0) + +#define SMR_SLIST_REMOVE_AFTER_LOCKED(elm, field) do { \ + (elm)->field.smr_sle_next = \ + (elm)->field.smr_sle_next->field.smr_sle_next; \ +} while (0) + +#define SMR_SLIST_REMOVE_HEAD_LOCKED(head, field) do { \ + (head)->smr_slh_first = (head)->smr_slh_first->field.smr_sle_next;\ +} while (0) + +#define SMR_SLIST_REMOVE_LOCKED(head, elm, type, field) do { \ + if ((head)->smr_slh_first == (elm)) { \ + SMR_SLIST_REMOVE_HEAD_LOCKED((head), field); \ + } else { \ + struct type *curelm = (head)->smr_slh_first; \ + \ + while (curelm->field.smr_sle_next != (elm)) \ + curelm = curelm->field.smr_sle_next; \ + curelm->field.smr_sle_next = \ + curelm->field.smr_sle_next->field.smr_sle_next; \ + } \ + /* (elm)->field.smr_sle_next must be left intact to allow \ + * any concurrent readers to proceed iteration. */ \ +} while (0) + +/* + * List definitions. + */ +#define SMR_LIST_HEAD(name, type) \ +struct name { \ + struct type *smr_lh_first; /* first element, SMR-protected */\ +} + +#define SMR_LIST_HEAD_INITIALIZER(head) \ + { .smr_lh_first = NULL } + +#define SMR_LIST_ENTRY(type) \ +struct { \ + struct type *smr_le_next; /* next element, SMR-protected */\ + struct type **smr_le_prev; /* address of previous next element */\ +} + +/* + * List access methods. + */ +#define SMR_LIST_END(head) NULL + +#define SMR_LIST_FIRST(head) \ + SMR_PTR_GET(&(head)->smr_lh_first) +#define SMR_LIST_NEXT(elm, field) \ + SMR_PTR_GET(&(elm)->field.smr_le_next) + +#define SMR_LIST_FIRST_LOCKED(head) ((head)->smr_lh_first) +#define SMR_LIST_NEXT_LOCKED(elm, field) ((elm)->field.smr_le_next) +#define SMR_LIST_EMPTY_LOCKED(head) \ + (SMR_LIST_FIRST_LOCKED(head) == SMR_LIST_END(head)) + +#define SMR_LIST_FOREACH(var, head, field) \ + for((var) = SMR_LIST_FIRST(head); \ + (var)!= SMR_LIST_END(head); \ + (var) = SMR_LIST_NEXT(var, field)) + +#define SMR_LIST_FOREACH_LOCKED(var, head, field) \ + for((var) = SMR_LIST_FIRST_LOCKED(head); \ + (var)!= SMR_LIST_END(head); \ + (var) = SMR_LIST_NEXT_LOCKED(var, field)) + +#define SMR_LIST_FOREACH_SAFE_LOCKED(var, head, field, tvar) \ + for ((var) = SMR_LIST_FIRST_LOCKED(head); \ + (var) && ((tvar) = SMR_LIST_NEXT_LOCKED(var, field), 1); \ + (var) = (tvar)) + +/* + * List functions. + */ +#define SMR_LIST_INIT(head) do { \ + (head)->smr_lh_first = SMR_LIST_END(head); \ +} while (0) + +#define SMR_LIST_INSERT_AFTER_LOCKED(listelm, elm, field) do { \ + (elm)->field.smr_le_next = (listelm)->field.smr_le_next; \ + if ((listelm)->field.smr_le_next != NULL) \ + (listelm)->field.smr_le_next->field.smr_le_prev = \ + &(elm)->field.smr_le_next; \ + (elm)->field.smr_le_prev = &(listelm)->field.smr_le_next; \ + membar_producer(); \ + (listelm)->field.smr_le_next = (elm); \ +} while (0) + +#define SMR_LIST_INSERT_BEFORE_LOCKED(listelm, elm, field) do { \ + (elm)->field.smr_le_prev = (listelm)->field.smr_le_prev; \ + (elm)->field.smr_le_next = (listelm); \ + membar_producer(); \ + *(listelm)->field.smr_le_prev = (elm); \ + (listelm)->field.smr_le_prev = &(elm)->field.smr_le_next; \ +} while (0) + +#define SMR_LIST_INSERT_HEAD_LOCKED(head, elm, field) do { \ + (elm)->field.smr_le_next = (head)->smr_lh_first; \ + (elm)->field.smr_le_prev = &(head)->smr_lh_first; \ + if ((head)->smr_lh_first != NULL) \ + (head)->smr_lh_first->field.smr_le_prev = \ + &(elm)->field.smr_le_next; \ + membar_producer(); \ + (head)->smr_lh_first = (elm); \ +} while (0) + +#define SMR_LIST_REMOVE_LOCKED(elm, field) do { \ + if ((elm)->field.smr_le_next != NULL) \ + (elm)->field.smr_le_next->field.smr_le_prev = \ + (elm)->field.smr_le_prev; \ + *(elm)->field.smr_le_prev = (elm)->field.smr_le_next; \ + /* (elm)->field.smr_le_next must be left intact to allow \ + * any concurrent readers to proceed iteration. */ \ +} while (0) + +/* + * Tail queue definitions. + */ +#define SMR_TAILQ_HEAD(name, type) \ +struct name { \ + struct type *smr_tqh_first; /* first element, SMR-protected */\ + struct type **smr_tqh_last; /* last element */ \ +} + +#define SMR_TAILQ_HEAD_INITIALIZER(head) \ + { .smr_tqh_first = NULL, .smr_tqh_last = &(head).smr_tqh_first } + +#define SMR_TAILQ_ENTRY(type) \ +struct { \ + struct type *smr_tqe_next; /* next element, SMR-protected */\ + struct type **smr_tqe_prev; /* address of previous next element */\ +} + +/* + * Tail queue access methods. + */ +#define SMR_TAILQ_END(head) NULL + +#define SMR_TAILQ_FIRST(head) \ + SMR_PTR_GET(&(head)->smr_tqh_first) +#define SMR_TAILQ_NEXT(elm, field) \ + SMR_PTR_GET(&(elm)->field.smr_tqe_next) + +#define SMR_TAILQ_FIRST_LOCKED(head) ((head)->smr_tqh_first) +#define SMR_TAILQ_NEXT_LOCKED(elm, field) ((elm)->field.smr_tqe_next) +#define SMR_TAILQ_LAST_LOCKED(head, headname) \ + (*(((struct headname *)((head)->smr_tqh_last))->smr_tqh_last)) +#define SMR_TAILQ_EMPTY_LOCKED(head) \ + (SMR_TAILQ_FIRST_LOCKED(head) == SMR_TAILQ_END(head)) + +#define SMR_TAILQ_FOREACH(var, head, field) \ + for((var) = SMR_TAILQ_FIRST(head); \ + (var)!= SMR_TAILQ_END(head); \ + (var) = SMR_TAILQ_NEXT(var, field)) + +#define SMR_TAILQ_FOREACH_LOCKED(var, head, field) \ + for((var) = SMR_TAILQ_FIRST_LOCKED(head); \ + (var)!= SMR_TAILQ_END(head); \ + (var) = SMR_TAILQ_NEXT_LOCKED(var, field)) + +#define SMR_TAILQ_FOREACH_SAFE_LOCKED(var, head, field, tvar) \ + for ((var) = SMR_TAILQ_FIRST_LOCKED(head); \ + (var) && ((tvar) = SMR_TAILQ_NEXT_LOCKED(var, field), 1); \ + (var) = (tvar)) + +/* + * Tail queue functions. + */ +#define SMR_TAILQ_INIT(head) do { \ + (head)->smr_tqh_first = SMR_TAILQ_END(head); \ + (head)->smr_tqh_last = &(head)->smr_tqh_first; \ +} while (0) + +#define SMR_TAILQ_INSERT_AFTER_LOCKED(head, listelm, elm, field) do { \ + (elm)->field.smr_tqe_next = (listelm)->field.smr_tqe_next; \ + if ((listelm)->field.smr_tqe_next != NULL) \ + (listelm)->field.smr_tqe_next->field.smr_tqe_prev = \ + &(elm)->field.smr_tqe_next; \ + else \ + (head)->smr_tqh_last = &(elm)->field.smr_tqe_next; \ + (elm)->field.smr_tqe_prev = &(listelm)->field.smr_tqe_next; \ + membar_producer(); \ + (listelm)->field.smr_tqe_next = (elm); \ +} while (0) + +#define SMR_TAILQ_INSERT_BEFORE_LOCKED(listelm, elm, field) do { \ + (elm)->field.smr_tqe_prev = (listelm)->field.smr_tqe_prev; \ + (elm)->field.smr_tqe_next = (listelm); \ + membar_producer(); \ + *(listelm)->field.smr_tqe_prev = (elm); \ + (listelm)->field.smr_tqe_prev = &(elm)->field.smr_tqe_next; \ +} while (0) + +#define SMR_TAILQ_INSERT_HEAD_LOCKED(head, elm, field) do { \ + (elm)->field.smr_tqe_next = (head)->smr_tqh_first; \ + (elm)->field.smr_tqe_prev = &(head)->smr_tqh_first; \ + if ((head)->smr_tqh_first != NULL) \ + (head)->smr_tqh_first->field.smr_tqe_prev = \ + &(elm)->field.smr_tqe_next; \ + else \ + (head)->smr_tqh_last = &(elm)->field.smr_tqe_next; \ + membar_producer(); \ + (head)->smr_tqh_first = (elm); \ +} while (0) + +#define SMR_TAILQ_INSERT_TAIL_LOCKED(head, elm, field) do { \ + (elm)->field.smr_tqe_next = NULL; \ + (elm)->field.smr_tqe_prev = (head)->smr_tqh_last; \ + membar_producer(); \ + *(head)->smr_tqh_last = (elm); \ + (head)->smr_tqh_last = &(elm)->field.smr_tqe_next; \ +} while (0) + +#define SMR_TAILQ_REMOVE_LOCKED(head, elm, field) do { \ + if ((elm)->field.smr_tqe_next != NULL) \ + (elm)->field.smr_tqe_next->field.smr_tqe_prev = \ + (elm)->field.smr_tqe_prev; \ + else \ + (head)->smr_tqh_last = (elm)->field.smr_tqe_prev; \ + *(elm)->field.smr_tqe_prev = (elm)->field.smr_tqe_next; \ + /* (elm)->field.smr_tqe_next must be left intact to allow \ + * any concurrent readers to proceed iteration. */ \ +} while (0) + +#endif /* !_SYS_SMR_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/socket.h b/lib/libc/include/generic-openbsd/sys/socket.h new file mode 100644 index 0000000000..537c0d9286 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/socket.h @@ -0,0 +1,617 @@ +/* $OpenBSD: socket.h,v 1.108 2025/08/04 04:59:30 guenther Exp $ */ +/* $NetBSD: socket.h,v 1.14 1996/02/09 18:25:36 christos Exp $ */ + +/* + * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994 + * 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. + * + * @(#)socket.h 8.4 (Berkeley) 2/21/94 + */ + +#ifndef _SYS_SOCKET_H_ +#define _SYS_SOCKET_H_ + +/* get the definitions for struct iovec, size_t, ssize_t, and */ +#include + +#if __BSD_VISIBLE +#include /* for off_t, uid_t, and gid_t */ +#endif + +#ifndef _SOCKLEN_T_DEFINED_ +#define _SOCKLEN_T_DEFINED_ +typedef __socklen_t socklen_t; /* length type for network syscalls */ +#endif + +#ifndef _SA_FAMILY_T_DEFINED_ +#define _SA_FAMILY_T_DEFINED_ +typedef __sa_family_t sa_family_t; /* sockaddr address family type */ +#endif + + +/* + * Definitions related to sockets: types, address families, options. + */ + +/* + * Types + */ +#define SOCK_STREAM 1 /* stream socket */ +#define SOCK_DGRAM 2 /* datagram socket */ +#define SOCK_RAW 3 /* raw-protocol interface */ +#define SOCK_RDM 4 /* reliably-delivered message */ +#define SOCK_SEQPACKET 5 /* sequenced packet stream */ +#ifdef _KERNEL +#define SOCK_TYPE_MASK 0x000F /* mask that covers the above */ +#endif + +/* + * Socket creation flags + */ +#if __POSIX_VISIBLE >= 202405 || __BSD_VISIBLE +#define SOCK_CLOEXEC 0x8000 /* set FD_CLOEXEC */ +#define SOCK_NONBLOCK 0x4000 /* set O_NONBLOCK */ +#endif +#if __BSD_VISIBLE +#ifdef _KERNEL +#define SOCK_NONBLOCK_INHERIT 0x2000 /* inherit O_NONBLOCK from listener */ +#endif +#define SOCK_DNS 0x1000 /* set SS_DNS */ +#endif /* __BSD_VISIBLE */ +#if __POSIX_VISIBLE >= 202405 +#define SOCK_CLOFORK 0x0800 /* set FD_CLOFORK */ +#endif + +/* + * Option flags per-socket. + */ +#define SO_DEBUG 0x0001 /* turn on debugging info recording */ +#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */ +#define SO_REUSEADDR 0x0004 /* allow local address reuse */ +#define SO_KEEPALIVE 0x0008 /* keep connections alive */ +#define SO_DONTROUTE 0x0010 /* just use interface addresses */ +#define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */ +#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */ +#define SO_LINGER 0x0080 /* linger on close if data present */ +#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */ +#define SO_REUSEPORT 0x0200 /* allow local address & port reuse */ +#define SO_TIMESTAMP 0x0800 /* timestamp received dgram traffic */ +#define SO_BINDANY 0x1000 /* allow bind to any address */ +#define SO_ZEROIZE 0x2000 /* zero out all mbufs sent over socket */ + +/* + * Additional options, not kept in so_options. + */ +#define SO_SNDBUF 0x1001 /* send buffer size */ +#define SO_RCVBUF 0x1002 /* receive buffer size */ +#define SO_SNDLOWAT 0x1003 /* send low-water mark */ +#define SO_RCVLOWAT 0x1004 /* receive low-water mark */ +#define SO_SNDTIMEO 0x1005 /* send timeout */ +#define SO_RCVTIMEO 0x1006 /* receive timeout */ +#define SO_ERROR 0x1007 /* get error status and clear */ +#define SO_TYPE 0x1008 /* get socket type */ +#define SO_RTABLE 0x1021 /* routing table to be used */ +#define SO_PEERCRED 0x1022 /* get connect-time credentials */ +#define SO_SPLICE 0x1023 /* splice data to other socket */ +#define SO_DOMAIN 0x1024 /* get socket domain */ +#define SO_PROTOCOL 0x1025 /* get socket protocol */ + +/* + * Structure used for manipulating linger option. + */ +struct linger { + int l_onoff; /* option on/off */ + int l_linger; /* linger time */ +}; + +#if __BSD_VISIBLE + +#ifndef _TIMEVAL_DECLARED +#define _TIMEVAL_DECLARED +struct timeval { + time_t tv_sec; /* seconds */ + suseconds_t tv_usec; /* and microseconds */ +}; +#endif + +/* + * Structure used for manipulating splice option. + */ +struct splice { + int sp_fd; /* drain socket file descriptor */ + off_t sp_max; /* if set, maximum bytes to splice */ + struct timeval sp_idle; /* idle timeout */ +}; + +/* + * Maximum number of alternate routing tables + */ +#define RT_TABLEID_MAX 255 +#define RT_TABLEID_BITS 8 +#define RT_TABLEID_MASK 0xff + +#endif /* __BSD_VISIBLE */ + +/* + * Level number for (get/set)sockopt() to apply to socket itself. + */ +#define SOL_SOCKET 0xffff /* options for socket level */ + +/* + * Address families. + */ +#define AF_UNSPEC 0 /* unspecified */ +#define AF_UNIX 1 /* local to host */ +#define AF_LOCAL AF_UNIX /* draft POSIX compatibility */ +#define AF_INET 2 /* internetwork: UDP, TCP, etc. */ +#define AF_IMPLINK 3 /* arpanet imp addresses */ +#define AF_PUP 4 /* pup protocols: e.g. BSP */ +#define AF_CHAOS 5 /* mit CHAOS protocols */ +#define AF_NS 6 /* XEROX NS protocols */ +#define AF_ISO 7 /* ISO protocols */ +#define AF_OSI AF_ISO +#define AF_ECMA 8 /* european computer manufacturers */ +#define AF_DATAKIT 9 /* datakit protocols */ +#define AF_CCITT 10 /* CCITT protocols, X.25 etc */ +#define AF_SNA 11 /* IBM SNA */ +#define AF_DECnet 12 /* DECnet */ +#define AF_DLI 13 /* DEC Direct data link interface */ +#define AF_LAT 14 /* LAT */ +#define AF_HYLINK 15 /* NSC Hyperchannel */ +#define AF_APPLETALK 16 /* Apple Talk */ +#define AF_ROUTE 17 /* Internal Routing Protocol */ +#define AF_LINK 18 /* Link layer interface */ +#define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */ +#define AF_COIP 20 /* connection-oriented IP, aka ST II */ +#define AF_CNT 21 /* Computer Network Technology */ +#define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */ +#define AF_IPX 23 /* Novell Internet Protocol */ +#define AF_INET6 24 /* IPv6 */ +#define pseudo_AF_PIP 25 /* Help Identify PIP packets */ +#define AF_ISDN 26 /* Integrated Services Digital Network*/ +#define AF_E164 AF_ISDN /* CCITT E.164 recommendation */ +#define AF_NATM 27 /* native ATM access */ +#define AF_ENCAP 28 +#define AF_SIP 29 /* Simple Internet Protocol */ +#define AF_KEY 30 +#define pseudo_AF_HDRCMPLT 31 /* Used by BPF to not rewrite headers + in interface output routine */ +#define AF_BLUETOOTH 32 /* Bluetooth */ +#define AF_MPLS 33 /* MPLS */ +#define pseudo_AF_PFLOW 34 /* pflow */ +#define pseudo_AF_PIPEX 35 /* PIPEX */ +#define AF_FRAME 36 /* frame (Ethernet) sockets */ +#define AF_MAX 37 + +/* + * Structure used by kernel to store most + * addresses. + */ +struct sockaddr { + __uint8_t sa_len; /* total length */ + sa_family_t sa_family; /* address family */ + char sa_data[14]; /* actually longer; address value */ +}; + +/* + * Sockaddr type which can hold any sockaddr type available + * in the system. + * + * Note: __ss_{len,family} is defined in RFC2553. During RFC2553 discussion + * the field name went back and forth between ss_len and __ss_len, + * and RFC2553 specifies it to be __ss_len. openbsd picked ss_len. + * For maximum portability, userland programmer would need to + * (1) make the code never touch ss_len portion (cast it into sockaddr and + * touch sa_len), or (2) add "-Dss_len=__ss_len" into CFLAGS to unify all + * occurrences (including header file) to __ss_len. + */ +struct sockaddr_storage { + __uint8_t ss_len; /* total length */ + sa_family_t ss_family; /* address family */ + unsigned char __ss_pad1[6]; /* align to quad */ + __uint64_t __ss_pad2; /* force alignment for stupid compilers */ + unsigned char __ss_pad3[240]; /* pad to a total of 256 bytes */ +}; + +#ifdef _KERNEL +/* + * Structure used by kernel to pass protocol + * information in raw sockets. + */ +struct sockproto { + unsigned short sp_family; /* address family */ + unsigned short sp_protocol; /* protocol */ +}; +#endif /* _KERNEL */ + +/* + * Protocol families, same as address families for now. + */ +#define PF_UNSPEC AF_UNSPEC +#define PF_LOCAL AF_LOCAL +#define PF_UNIX AF_UNIX +#define PF_INET AF_INET +#define PF_IMPLINK AF_IMPLINK +#define PF_PUP AF_PUP +#define PF_CHAOS AF_CHAOS +#define PF_NS AF_NS +#define PF_ISO AF_ISO +#define PF_OSI AF_ISO +#define PF_ECMA AF_ECMA +#define PF_DATAKIT AF_DATAKIT +#define PF_CCITT AF_CCITT +#define PF_SNA AF_SNA +#define PF_DECnet AF_DECnet +#define PF_DLI AF_DLI +#define PF_LAT AF_LAT +#define PF_HYLINK AF_HYLINK +#define PF_APPLETALK AF_APPLETALK +#define PF_ROUTE AF_ROUTE +#define PF_LINK AF_LINK +#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */ +#define PF_COIP AF_COIP +#define PF_CNT AF_CNT +#define PF_IPX AF_IPX /* same format as AF_NS */ +#define PF_INET6 AF_INET6 +#define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */ +#define PF_PIP pseudo_AF_PIP +#define PF_ISDN AF_ISDN +#define PF_NATM AF_NATM +#define PF_ENCAP AF_ENCAP +#define PF_SIP AF_SIP +#define PF_KEY AF_KEY +#define PF_BPF pseudo_AF_HDRCMPLT +#define PF_BLUETOOTH AF_BLUETOOTH +#define PF_MPLS AF_MPLS +#define PF_PFLOW pseudo_AF_PFLOW +#define PF_PIPEX pseudo_AF_PIPEX +#define PF_FRAME AF_FRAME +#define PF_MAX AF_MAX + +/* + * These are the valid values for the "how" field used by shutdown(2). + */ +#define SHUT_RD 0 +#define SHUT_WR 1 +#define SHUT_RDWR 2 + +#if __BSD_VISIBLE +#define SA_LEN(x) ((x)->sa_len) + +/* Read using getsockopt() with SOL_SOCKET, SO_PEERCRED */ +struct sockpeercred { + uid_t uid; /* effective user id */ + gid_t gid; /* effective group id */ + pid_t pid; +}; + +/* + * Definitions for network related sysctl, CTL_NET. + * + * Second level is protocol family. + * Third level is protocol number. + * + * Further levels are defined by the individual families below. + */ +#define NET_MAXID AF_MAX + +#define CTL_NET_NAMES { \ + { 0, 0 }, \ + { "unix", CTLTYPE_NODE }, \ + { "inet", CTLTYPE_NODE }, \ + { "implink", CTLTYPE_NODE }, \ + { "pup", CTLTYPE_NODE }, \ + { "chaos", CTLTYPE_NODE }, \ + { "xerox_ns", CTLTYPE_NODE }, \ + { "iso", CTLTYPE_NODE }, \ + { "ecma", CTLTYPE_NODE }, \ + { "datakit", CTLTYPE_NODE }, \ + { "ccitt", CTLTYPE_NODE }, \ + { "ibm_sna", CTLTYPE_NODE }, \ + { "decnet", CTLTYPE_NODE }, \ + { "dec_dli", CTLTYPE_NODE }, \ + { "lat", CTLTYPE_NODE }, \ + { "hylink", CTLTYPE_NODE }, \ + { "appletalk", CTLTYPE_NODE }, \ + { "route", CTLTYPE_NODE }, \ + { "link", CTLTYPE_NODE }, \ + { "xtp", CTLTYPE_NODE }, \ + { "coip", CTLTYPE_NODE }, \ + { "cnt", CTLTYPE_NODE }, \ + { "rtip", CTLTYPE_NODE }, \ + { "ipx", CTLTYPE_NODE }, \ + { "inet6", CTLTYPE_NODE }, \ + { "pip", CTLTYPE_NODE }, \ + { "isdn", CTLTYPE_NODE }, \ + { "natm", CTLTYPE_NODE }, \ + { "encap", CTLTYPE_NODE }, \ + { "sip", CTLTYPE_NODE }, \ + { "key", CTLTYPE_NODE }, \ + { "bpf", CTLTYPE_NODE }, \ + { "bluetooth", CTLTYPE_NODE }, \ + { "mpls", CTLTYPE_NODE }, \ + { "pflow", CTLTYPE_NODE }, \ + { "pipex", CTLTYPE_NODE }, \ +} + +/* + * PF_ROUTE - Routing table + * + * Four additional levels are defined: + * Fourth: address family, 0 is wildcard + * Fifth: type of info, defined below + * Sixth: flag(s) to mask with for NET_RT_FLAGS + * Seventh: routing table to use (facultative, defaults to 0) + * NET_RT_TABLE has the table id as sixth element. + */ +#define NET_RT_DUMP 1 /* dump; may limit to a.f. */ +#define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */ +#define NET_RT_IFLIST 3 /* survey interface list */ +#define NET_RT_STATS 4 /* routing table statistics */ +#define NET_RT_TABLE 5 +#define NET_RT_IFNAMES 6 +#define NET_RT_SOURCE 7 +#define NET_RT_MAXID 8 + +#define CTL_NET_RT_NAMES { \ + { 0, 0 }, \ + { "dump", CTLTYPE_STRUCT }, \ + { "flags", CTLTYPE_STRUCT }, \ + { "iflist", CTLTYPE_STRUCT }, \ + { "stats", CTLTYPE_STRUCT }, \ + { "table", CTLTYPE_STRUCT }, \ + { "ifnames", CTLTYPE_STRUCT }, \ + { "source", CTLTYPE_STRUCT }, \ +} + +/* + * PF_UNIX - unix socket tunables + */ +#define NET_UNIX_INFLIGHT 6 +#define NET_UNIX_DEFERRED 7 +#define NET_UNIX_MAXID 8 + +#define CTL_NET_UNIX_NAMES { \ + { 0, 0 }, \ + { "stream", CTLTYPE_NODE }, \ + { "dgram", CTLTYPE_NODE }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "seqpacket", CTLTYPE_NODE }, \ + { "inflight", CTLTYPE_INT }, \ + { "deferred", CTLTYPE_INT }, \ +} + +#define UNPCTL_RECVSPACE 1 +#define UNPCTL_SENDSPACE 2 +#define NET_UNIX_PROTO_MAXID 3 + +#define CTL_NET_UNIX_PROTO_NAMES { \ + { 0, 0 }, \ + { "recvspace", CTLTYPE_INT }, \ + { "sendspace", CTLTYPE_INT }, \ +} + +/* + * PF_LINK - link layer or device tunables + */ +#define NET_LINK_IFRXQ 1 /* net.link.ifrxq */ +#define NET_LINK_MAXID 2 + +#define CTL_NET_LINK_NAMES { \ + { 0, 0 }, \ + { "ifrxq", CTLTYPE_NODE }, \ +} + +#define NET_LINK_IFRXQ_PRESSURE_RETURN \ + 1 /* net.link.ifrxq.pressure_return */ +#define NET_LINK_IFRXQ_PRESSURE_DROP \ + 2 /* net.link.ifrxq.pressure_drop */ +#define NET_LINK_IFRXQ_MAXID 3 + +#define CTL_NET_LINK_IFRXQ_NAMES { \ + { 0, 0 }, \ + { "pressure_return", CTLTYPE_INT }, \ + { "pressure_drop", CTLTYPE_INT }, \ +} + +/* + * PF_KEY - Key Management + */ +#define NET_KEY_SADB_DUMP 1 /* return SADB */ +#define NET_KEY_SPD_DUMP 2 /* return SPD */ +#define NET_KEY_MAXID 3 + +#define CTL_NET_KEY_NAMES { \ + { 0, 0 }, \ + { "sadb_dump", CTLTYPE_STRUCT }, \ + { "spd_dump", CTLTYPE_STRUCT }, \ +} + +/* + * PF_BPF not really a family, but connected under CTL_NET + */ +#define NET_BPF_BUFSIZE 1 /* default buffer size */ +#define NET_BPF_MAXBUFSIZE 2 /* maximum buffer size */ +#define NET_BPF_MAXID 3 + +#define CTL_NET_BPF_NAMES { \ + { 0, 0 }, \ + { "bufsize", CTLTYPE_INT }, \ + { "maxbufsize", CTLTYPE_INT }, \ +} + +/* + * PF_PFLOW not really a family, but connected under CTL_NET + */ +#define NET_PFLOW_STATS 1 /* statistics */ +#define NET_PFLOW_MAXID 2 + +#define CTL_NET_PFLOW_NAMES { \ + { 0, 0 }, \ + { "stats", CTLTYPE_STRUCT }, \ +} +#endif /* __BSD_VISIBLE */ + +/* + * Maximum queue length specifiable by listen(2). + */ +#define SOMAXCONN 128 + +/* + * Message header for recvmsg and sendmsg calls. + * Used value-result for recvmsg, value only for sendmsg. + */ +struct msghdr { + void *msg_name; /* optional address */ + socklen_t msg_namelen; /* size of address */ + struct iovec *msg_iov; /* scatter/gather array */ + unsigned int msg_iovlen; /* # elements in msg_iov */ + void *msg_control; /* ancillary data, see below */ + socklen_t msg_controllen; /* ancillary data buffer len */ + int msg_flags; /* flags on received message */ +}; + +struct mmsghdr { + struct msghdr msg_hdr; + unsigned int msg_len; +}; + +struct timespec; + +#define MSG_OOB 0x1 /* process out-of-band data */ +#define MSG_PEEK 0x2 /* peek at incoming message */ +#define MSG_DONTROUTE 0x4 /* send without using routing tables */ +#define MSG_EOR 0x8 /* data completes record */ +#define MSG_TRUNC 0x10 /* data discarded before delivery */ +#define MSG_CTRUNC 0x20 /* control data lost before delivery */ +#define MSG_WAITALL 0x40 /* wait for full request or error */ +#define MSG_DONTWAIT 0x80 /* this message should be nonblocking */ +#define MSG_BCAST 0x100 /* this message rec'd as broadcast */ +#define MSG_MCAST 0x200 /* this message rec'd as multicast */ +#define MSG_NOSIGNAL 0x400 /* do not send SIGPIPE */ +#define MSG_CMSG_CLOEXEC 0x800 /* set FD_CLOEXEC on received fds */ +#define MSG_WAITFORONE 0x1000 /* nonblocking but wait for one msg */ +#define MSG_CMSG_CLOFORK 0x2000 /* set FD_CLOFORK on received fds */ + +/* + * Header for ancillary data objects in msg_control buffer. + * Used for additional information with/about a datagram + * not expressible by flags. The format is a sequence + * of message elements headed by cmsghdr structures. + */ +struct cmsghdr { + socklen_t cmsg_len; /* data byte count, including hdr */ + int cmsg_level; /* originating protocol */ + int cmsg_type; /* protocol-specific type */ +/* followed by u_char cmsg_data[]; */ +}; + +/* given pointer to struct cmsghdr, return pointer to data */ +#define CMSG_DATA(cmsg) \ + ((unsigned char *)(cmsg) + _ALIGN(sizeof(struct cmsghdr))) + +/* given pointer to struct cmsghdr, return pointer to next cmsghdr */ +#define CMSG_NXTHDR(mhdr, cmsg) \ + (((char *)(cmsg) + _ALIGN((cmsg)->cmsg_len) + \ + _ALIGN(sizeof(struct cmsghdr)) > \ + ((char *)(mhdr)->msg_control) + (mhdr)->msg_controllen) ? \ + (struct cmsghdr *)NULL : \ + (struct cmsghdr *)((char *)(cmsg) + _ALIGN((cmsg)->cmsg_len))) + +/* + * RFC 2292 requires to check msg_controllen, in case that the kernel returns + * an empty list for some reasons. + */ +#define CMSG_FIRSTHDR(mhdr) \ + ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \ + (struct cmsghdr *)(mhdr)->msg_control : \ + (struct cmsghdr *)NULL) + +/* Round len up to next alignment boundary */ +#ifdef _KERNEL +#define CMSG_ALIGN(n) _ALIGN(n) +#endif + +/* Length of the contents of a control message of length len */ +#define CMSG_LEN(len) (_ALIGN(sizeof(struct cmsghdr)) + (len)) + +/* Length of the space taken up by a padded control message of length len */ +#define CMSG_SPACE(len) (_ALIGN(sizeof(struct cmsghdr)) + _ALIGN(len)) + +/* "Socket"-level control message types: */ +#define SCM_RIGHTS 0x01 /* access rights (array of int) */ +#define SCM_TIMESTAMP 0x04 /* timestamp (struct timeval) */ + +#ifndef _KERNEL + +__BEGIN_DECLS +int accept(int, struct sockaddr *, socklen_t *); +int bind(int, const struct sockaddr *, socklen_t); +int connect(int, const struct sockaddr *, socklen_t); +int getpeername(int, struct sockaddr *, socklen_t *); +int getsockname(int, struct sockaddr *, socklen_t *); +int getsockopt(int, int, int, void *, socklen_t *); +int listen(int, int); +ssize_t recv(int, void *, size_t, int); +ssize_t recvfrom(int, void *, size_t, int, struct sockaddr *, socklen_t *); +ssize_t recvmsg(int, struct msghdr *, int); +int recvmmsg(int, struct mmsghdr *, unsigned int, int, struct timespec *); +ssize_t send(int, const void *, size_t, int); +ssize_t sendto(int, const void *, + size_t, int, const struct sockaddr *, socklen_t); +ssize_t sendmsg(int, const struct msghdr *, int); +int sendmmsg(int, struct mmsghdr *, unsigned int, int); +int setsockopt(int, int, int, const void *, socklen_t); +int shutdown(int, int); +int sockatmark(int); +int socket(int, int, int); +int socketpair(int, int, int, int *); + +#if __POSIX_VISIBLE >= 202405 || __BSD_VISIBLE +int accept4(int, struct sockaddr *__restrict, socklen_t *__restrict, int); +#endif + +#if __BSD_VISIBLE +int getpeereid(int, uid_t *, gid_t *); +int getrtable(void); +int setrtable(int); +#endif /* __BSD_VISIBLE */ + +__END_DECLS + +#else + +static inline struct sockaddr * +sstosa(struct sockaddr_storage *ss) +{ + return ((struct sockaddr *)(ss)); +} + +#endif /* !_KERNEL */ + +#endif /* !_SYS_SOCKET_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/socketvar.h b/lib/libc/include/generic-openbsd/sys/socketvar.h new file mode 100644 index 0000000000..e64f148b18 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/socketvar.h @@ -0,0 +1,443 @@ +/* $OpenBSD: socketvar.h,v 1.159 2025/07/25 08:58:44 mvs Exp $ */ +/* $NetBSD: socketvar.h,v 1.18 1996/02/09 18:25:38 christos Exp $ */ + +/*- + * Copyright (c) 1982, 1986, 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)socketvar.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _SYS_SOCKETVAR_H_ +#define _SYS_SOCKETVAR_H_ + +#include +#include +#include /* for struct sigio_ref */ +#include +#include +#include +#include +#include + +#ifndef _SOCKLEN_T_DEFINED_ +#define _SOCKLEN_T_DEFINED_ +typedef __socklen_t socklen_t; /* length type for network syscalls */ +#endif + +TAILQ_HEAD(soqhead, socket); + +/* + * Locks used to protect global data and struct members: + * I immutable after creation + * a atomic + * mr sb_mxt of so_rcv buffer + * ms sb_mtx of so_snd buffer + * m sb_mtx + * br sblock() of so_rcv buffer + * bs sblock() od so_snd buffer + * s solock() + */ + +/* + * Variables for socket splicing, allocated only when needed. + */ +struct sosplice { + struct socket *ssp_socket; /* [mr ms] send data to drain socket */ + struct socket *ssp_soback; /* [ms ms] back ref to source socket */ + off_t ssp_len; /* [mr] number of bytes spliced */ + off_t ssp_max; /* [I] maximum number of bytes */ + struct timeval ssp_idletv; /* [I] idle timeout */ + struct timeout ssp_idleto; + struct task ssp_task; /* task for somove */ +}; + +/* + * Variables for socket buffering. + */ +struct sockbuf { + struct rwlock sb_lock; + struct mutex sb_mtx; +/* The following fields are all zeroed on flush. */ +#define sb_startzero sb_cc + u_long sb_cc; /* [m] actual chars in buffer */ + u_long sb_datacc; /* [m] data only chars in buffer */ + u_long sb_hiwat; /* [m] max actual char count */ + u_long sb_wat; /* [m] default watermark */ + u_long sb_mbcnt; /* [m] chars of mbufs used */ + u_long sb_mbmax; /* [m] max chars of mbufs to use */ + long sb_lowat; /* [m] low water mark */ + struct mbuf *sb_mb; /* [m] the mbuf chain */ + struct mbuf *sb_mbtail; /* [m] the last mbuf in the chain */ + struct mbuf *sb_lastrecord; /* [m] first mbuf of last record in + socket buffer */ + short sb_flags; /* [m] flags, see below */ +/* End area that is zeroed on flush. */ +#define sb_endzero sb_flags + short sb_state; /* [m] socket state on sockbuf */ + uint64_t sb_timeo_nsecs; /* [m] timeout for read/write */ + struct klist sb_klist; /* [m] list of knotes */ +}; + +#define SB_MAX (2*1024*1024) /* default for max chars in sockbuf */ +#define SB_WAIT 0x0001 /* someone is waiting for data/space */ +#define SB_ASYNC 0x0002 /* ASYNC I/O, need signals */ +#define SB_SPLICE 0x0004 /* buffer is splice source or drain */ +#define SB_NOINTR 0x0008 /* operations not interruptible */ + +/* + * Kernel structure per socket. + * Contains send and receive buffer queues, + * handle on protocol and pointer to protocol + * private data and error information. + */ +struct socket { + const struct protosw *so_proto; /* [I] protocol handle */ + struct rwlock so_lock; /* this socket lock */ + struct refcnt so_refcnt; /* references to this socket */ + void *so_pcb; /* [s] protocol control block */ + u_int so_state; /* [s] internal state flags SS_*, + see below */ + short so_type; /* [I] generic type, see socket.h */ + short so_options; /* [s] from socket call, see + socket.h */ + short so_linger; /* [s] time to linger while closing */ +/* + * Variables for connection queueing. + * Socket where accepts occur is so_head in all subsidiary sockets. + * If so_head is 0, socket is not related to an accept. + * For head socket so_q0 queues partially completed connections, + * while so_q is a queue of connections ready to be accepted. + * If a connection is aborted and it has so_head set, then + * it has to be pulled out of either so_q0 or so_q. + * We allow connections to queue up based on current queue lengths + * and limit on number of queued connections for this socket. + * + * Connections queue relies on both socket locks of listening and + * unaccepted sockets. Socket lock of listening socket should be + * always taken first. + */ + struct socket *so_head; /* [s] back pointer to accept socket */ + struct soqhead *so_onq; /* [s] queue (q or q0) that we're on */ + struct soqhead so_q0; /* [s] queue of partial connections */ + struct soqhead so_q; /* [s] queue of incoming connections */ + struct sigio_ref so_sigio; /* async I/O registration */ + TAILQ_ENTRY(socket) so_qe; /* [s] our queue entry (q or q0) */ + short so_q0len; /* [s] partials on so_q0 */ + short so_qlen; /* [s] number of connections on so_q */ + short so_qlimit; /* [s] max number queued connections */ + short so_timeo; /* [s] connection timeout */ + u_long so_oobmark; /* [mr] chars to oob mark */ + u_int so_error; /* [a] error affecting connection */ + + struct sosplice *so_sp; /* [s br] */ + + struct sockbuf so_rcv; + struct sockbuf so_snd; + + void (*so_upcall)(struct socket *, caddr_t, int); /* [s] */ + caddr_t so_upcallarg; /* [s] Arg for above */ + uid_t so_euid; /* [I] who opened the socket */ + uid_t so_ruid; /* [I] */ + gid_t so_egid; /* [I] */ + gid_t so_rgid; /* [I] */ + pid_t so_cpid; /* [I] pid of process that opened + socket */ +}; + +/* + * Socket state bits. + * + * NOTE: The following states should be used with corresponding socket's + * buffer `sb_state' only: + * + * SS_CANTSENDMORE with `so_snd' + * SS_ISSENDING with `so_snd' + * SS_CANTRCVMORE with `so_rcv' + * SS_RCVATMARK with `so_rcv' + */ + +#define SS_NOFDREF 0x001 /* no file table ref any more */ +#define SS_ISCONNECTED 0x002 /* socket connected to a peer */ +#define SS_ISCONNECTING 0x004 /* in process of connecting to peer */ +#define SS_ISDISCONNECTING 0x008 /* in process of disconnecting */ +#define SS_CANTSENDMORE 0x010 /* can't send more data to peer */ +#define SS_CANTRCVMORE 0x020 /* can't receive more data from peer */ +#define SS_RCVATMARK 0x040 /* at mark on input */ +#define SS_ISDISCONNECTED 0x800 /* socket disconnected from peer */ + +#define SS_PRIV 0x080 /* privileged for broadcast, raw... */ +#define SS_CONNECTOUT 0x1000 /* connect, not accept, at this end */ +#define SS_ISSENDING 0x2000 /* hint for lower layer */ +#define SS_DNS 0x4000 /* created using SOCK_DNS socket(2) */ +#define SS_YP 0x8000 /* created using ypconnect(2) */ + +#ifdef _KERNEL + +#include +#include + +struct mbuf; +struct sockaddr; +struct proc; +struct msghdr; +struct stat; +struct knote; + +void soassertlocked(struct socket *); +void soassertlocked_readonly(struct socket *); +void sbmtxassertlocked(struct sockbuf *); + +int soo_read(struct file *, struct uio *, int); +int soo_write(struct file *, struct uio *, int); +int soo_ioctl(struct file *, u_long, caddr_t, struct proc *); +int soo_kqfilter(struct file *, struct knote *); +int soo_close(struct file *, struct proc *); +int soo_stat(struct file *, struct stat *, struct proc *); +void sbappend(struct sockbuf *, struct mbuf *); +void sbappendstream(struct sockbuf *, struct mbuf *); +int sbappendaddr(struct sockbuf *, const struct sockaddr *, struct mbuf *, + struct mbuf *); +int sbappendcontrol(struct sockbuf *, struct mbuf *, struct mbuf *); +void sbappendrecord(struct sockbuf *, struct mbuf *); +void sbcompress(struct sockbuf *, struct mbuf *, struct mbuf *); +struct mbuf * + sbcreatecontrol(const void *, size_t, int, int); +void sbdrop(struct sockbuf *, int); +void sbdroprecord(struct sockbuf *); +void sbflush(struct sockbuf *); +void sbrelease(struct sockbuf *); +int sbcheckreserve(u_long, u_long); +int sbchecklowmem(void); +int sbreserve(struct sockbuf *, u_long); +int sbwait(struct sockbuf *); +void soinit(void); +void soabort(struct socket *); +int soaccept(struct socket *, struct mbuf *); +int sobind(struct socket *, struct mbuf *, struct proc *); +void socantrcvmore(struct socket *); +void socantsendmore(struct socket *); +int soclose(struct socket *, int); +int soconnect(struct socket *, struct mbuf *); +int soconnect2(struct socket *, struct socket *); +int socreate(int, struct socket **, int, int); +int sodisconnect(struct socket *); +struct socket *soalloc(const struct protosw *, int); +void sofree(struct socket *, int); +void sorele(struct socket *); +int sogetopt(struct socket *, int, int, struct mbuf *); +void sohasoutofband(struct socket *); +void soisconnected(struct socket *); +void soisconnecting(struct socket *); +void soisdisconnected(struct socket *); +void soisdisconnecting(struct socket *); +int solisten(struct socket *, int); +struct socket *sonewconn(struct socket *, int, int); +void soqinsque(struct socket *, struct socket *, int); +int soqremque(struct socket *, int); +int soreceive(struct socket *, struct mbuf **, struct uio *, + struct mbuf **, struct mbuf **, int *, socklen_t); +int soreserve(struct socket *, u_long, u_long); +int sosend(struct socket *, struct mbuf *, struct uio *, + struct mbuf *, struct mbuf *, int); +int sosetopt(struct socket *, int, int, struct mbuf *); +int soshutdown(struct socket *, int); +void sowakeup(struct socket *, struct sockbuf *); +void sorwakeup(struct socket *); +void sowwakeup(struct socket *); +int sockargs(struct mbuf **, const void *, size_t, int); + +int sosleep_nsec(struct socket *, void *, int, const char *, uint64_t); +void solock(struct socket *); +void solock_shared(struct socket *); +void solock_nonet(struct socket *); +int solock_persocket(struct socket *); +void solock_pair(struct socket *, struct socket *); +void sounlock(struct socket *); +void sounlock_shared(struct socket *); +void sounlock_nonet(struct socket *); +void sounlock_pair(struct socket *, struct socket *); + +int sendit(struct proc *, int, struct msghdr *, int, register_t *); +int recvit(struct proc *, int, struct msghdr *, caddr_t, register_t *); +int doaccept(struct proc *, int, struct sockaddr *, socklen_t *, int, + register_t *); + +#ifdef SOCKBUF_DEBUG +void sblastrecordchk(struct sockbuf *, const char *); +#define SBLASTRECORDCHK(sb, where) sblastrecordchk((sb), (where)) + +void sblastmbufchk(struct sockbuf *, const char *); +#define SBLASTMBUFCHK(sb, where) sblastmbufchk((sb), (where)) +void sbcheck(struct socket *, struct sockbuf *); +#define SBCHECK(so, sb) sbcheck((so), (sb)) +#else +#define SBLASTRECORDCHK(sb, where) /* nothing */ +#define SBLASTMBUFCHK(sb, where) /* nothing */ +#define SBCHECK(so, sb) /* nothing */ +#endif /* SOCKBUF_DEBUG */ + +/* + * Flags to sblock() + */ +#define SBL_WAIT 0x01 /* Wait if lock not immediately available. */ +#define SBL_NOINTR 0x02 /* Enforce non-interruptible sleep. */ + +int sblock(struct sockbuf *, int); +void sbunlock(struct sockbuf *); + +extern u_long sb_max; +extern struct pool socket_pool; + +static inline struct socket * +soref(struct socket *so) +{ + if (so == NULL) + return NULL; + refcnt_take(&so->so_refcnt); + return so; +} + +/* + * Macros for sockets and socket buffering. + */ + +#define isspliced(so) ((so)->so_sp && (so)->so_sp->ssp_socket) +#define issplicedback(so) ((so)->so_sp && (so)->so_sp->ssp_soback) + +/* + * Do we need to notify the other side when I/O is possible? + */ +static inline int +sb_notify(struct sockbuf *sb) +{ + int rv; + + mtx_enter(&sb->sb_mtx); + rv = ((sb->sb_flags & (SB_WAIT|SB_ASYNC|SB_SPLICE)) != 0 || + !klist_empty(&sb->sb_klist)); + mtx_leave(&sb->sb_mtx); + + return rv; +} + +/* + * How much space is there in a socket buffer (so->so_snd or so->so_rcv)? + * This is problematical if the fields are unsigned, as the space might + * still be negative (cc > hiwat or mbcnt > mbmax). Should detect + * overflow and return 0. + */ + +static inline long +sbspace_locked(struct sockbuf *sb) +{ + sbmtxassertlocked(sb); + + return lmin(sb->sb_hiwat - sb->sb_cc, sb->sb_mbmax - sb->sb_mbcnt); +} + +static inline long +sbspace(struct sockbuf *sb) +{ + long ret; + + mtx_enter(&sb->sb_mtx); + ret = sbspace_locked(sb); + mtx_leave(&sb->sb_mtx); + + return ret; +} + +/* do we have to send all at once on a socket? */ +#define sosendallatonce(so) \ + ((so)->so_proto->pr_flags & PR_ATOMIC) + +/* are we sending on this socket? */ +#define soissending(so) \ + ((so)->so_snd.sb_state & SS_ISSENDING) + +/* can we read something from so? */ +static inline int +soreadable(struct socket *so) +{ + soassertlocked_readonly(so); + if (isspliced(so)) + return 0; + return (so->so_rcv.sb_state & SS_CANTRCVMORE) || + so->so_error || so->so_rcv.sb_cc >= so->so_rcv.sb_lowat; +} + +/* can we write something to so? */ +static inline int +sowriteable(struct socket *so) +{ + soassertlocked_readonly(so); + return ((sbspace(&so->so_snd) >= so->so_snd.sb_lowat && + ((so->so_state & SS_ISCONNECTED) || + (so->so_proto->pr_flags & PR_CONNREQUIRED)==0)) || + (so->so_snd.sb_state & SS_CANTSENDMORE) || so->so_error); +} + +/* adjust counters in sb reflecting allocation of m */ +static inline void +sballoc(struct sockbuf *sb, struct mbuf *m) +{ + sb->sb_cc += m->m_len; + if (m->m_type != MT_CONTROL && m->m_type != MT_SONAME) + sb->sb_datacc += m->m_len; + sb->sb_mbcnt += MSIZE; + if (m->m_flags & M_EXT) + sb->sb_mbcnt += m->m_ext.ext_size; +} + +/* adjust counters in sb reflecting freeing of m */ +static inline void +sbfree(struct sockbuf *sb, struct mbuf *m) +{ + sb->sb_cc -= m->m_len; + if (m->m_type != MT_CONTROL && m->m_type != MT_SONAME) + sb->sb_datacc -= m->m_len; + sb->sb_mbcnt -= MSIZE; + if (m->m_flags & M_EXT) + sb->sb_mbcnt -= m->m_ext.ext_size; +} + +static inline void +sbassertlocked(struct sockbuf *sb) +{ + rw_assert_wrlock(&sb->sb_lock); +} + +#define SB_EMPTY_FIXUP(sb) do { \ + if ((sb)->sb_mb == NULL) { \ + (sb)->sb_mbtail = NULL; \ + (sb)->sb_lastrecord = NULL; \ + } \ +} while (/*CONSTCOND*/0) + +#endif /* _KERNEL */ +#endif /* _SYS_SOCKETVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/sockio.h b/lib/libc/include/generic-openbsd/sys/sockio.h new file mode 100644 index 0000000000..10d85c7923 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/sockio.h @@ -0,0 +1,223 @@ +/* $OpenBSD: sockio.h,v 1.84 2021/11/11 10:03:10 claudio Exp $ */ +/* $NetBSD: sockio.h,v 1.5 1995/08/23 00:40:47 thorpej Exp $ */ + +/*- + * Copyright (c) 1982, 1986, 1990, 1993, 1994 + * 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. + * + * @(#)sockio.h 8.1 (Berkeley) 3/28/94 + */ + +#ifndef _SYS_SOCKIO_H_ +#define _SYS_SOCKIO_H_ + +#include + +/* Socket ioctl's. */ +#define SIOCATMARK _IOR('s', 7, int) /* at oob mark? */ +#define SIOCSPGRP _IOW('s', 8, int) /* set process group */ +#define SIOCGPGRP _IOR('s', 9, int) /* get process group */ + +#define SIOCSIFADDR _IOW('i', 12, struct ifreq) /* set ifnet address */ +#define SIOCGIFADDR _IOWR('i', 33, struct ifreq) /* get ifnet address */ +#define SIOCSIFDSTADDR _IOW('i', 14, struct ifreq) /* set p-p address */ +#define SIOCGIFDSTADDR _IOWR('i', 34, struct ifreq) /* get p-p address */ +#define SIOCSIFFLAGS _IOW('i', 16, struct ifreq) /* set ifnet flags */ +#define SIOCGIFFLAGS _IOWR('i', 17, struct ifreq) /* get ifnet flags */ +#define SIOCGIFBRDADDR _IOWR('i', 35, struct ifreq) /* get broadcast addr */ +#define SIOCSIFBRDADDR _IOW('i', 19, struct ifreq) /* set broadcast addr */ +#define SIOCGIFCONF _IOWR('i', 36, struct ifconf) /* get ifnet list */ +#define SIOCGIFNETMASK _IOWR('i', 37, struct ifreq) /* get net addr mask */ +#define SIOCSIFNETMASK _IOW('i', 22, struct ifreq) /* set net addr mask */ +#define SIOCGIFMETRIC _IOWR('i', 23, struct ifreq) /* get IF metric */ +#define SIOCSIFMETRIC _IOW('i', 24, struct ifreq) /* set IF metric */ +#define SIOCDIFADDR _IOW('i', 25, struct ifreq) /* delete IF addr */ +#define SIOCAIFADDR _IOW('i', 26, struct ifaliasreq)/* add/chg IF alias */ +#define SIOCGIFDATA _IOWR('i', 27, struct ifreq) /* get if_data */ +#define SIOCSIFLLADDR _IOW('i', 31, struct ifreq) /* set link level addr */ + +#define SIOCADDMULTI _IOW('i', 49, struct ifreq) /* add m'cast addr */ +#define SIOCDELMULTI _IOW('i', 50, struct ifreq) /* del m'cast addr */ +#define SIOCGETVIFCNT _IOWR('u', 51, struct sioc_vif_req)/* vif pkt cnt */ +#define SIOCGETSGCNT _IOWR('u', 52, struct sioc_sg_req) /* sg pkt cnt */ + +/* 53 and 54 used to be SIOC[SG]IFMEDIA with a 32 bit media word */ +#define SIOCSIFMEDIA _IOWR('i', 55, struct ifreq) /* set net media */ +#define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */ +#define SIOCGIFSFFPAGE _IOWR('i', 57, struct if_sffpage) /* get SFF page */ + +#define SIOCDIFPHYADDR _IOW('i', 73, struct ifreq) /* delete gif addrs */ +#define SIOCSLIFPHYADDR _IOW('i', 74, struct if_laddrreq) /* set gif addrs */ +#define SIOCGLIFPHYADDR _IOWR('i', 75, struct if_laddrreq) /* get gif addrs */ + +#define SIOCBRDGADD _IOW('i', 60, struct ifbreq) /* add bridge ifs */ +#define SIOCBRDGDEL _IOW('i', 61, struct ifbreq) /* del bridge ifs */ +#define SIOCBRDGGIFFLGS _IOWR('i', 62, struct ifbreq) /* get brdg if flags */ +#define SIOCBRDGSIFFLGS _IOW('i', 63, struct ifbreq) /* set brdg if flags */ +#define SIOCBRDGSCACHE _IOW('i', 64, struct ifbrparam)/* set cache size */ +#define SIOCBRDGGCACHE _IOWR('i', 65, struct ifbrparam)/* get cache size */ +#define SIOCBRDGADDS _IOW('i', 65, struct ifbreq) /* add span port */ +#define SIOCBRDGIFS _IOWR('i', 66, struct ifbreq) /* get member ifs */ +#define SIOCBRDGDELS _IOW('i', 66, struct ifbreq) /* del span port */ +#define SIOCBRDGRTS _IOWR('i', 67, struct ifbaconf) /* get addresses */ +#define SIOCBRDGSADDR _IOWR('i', 68, struct ifbareq) /* set addr flags */ +#define SIOCBRDGSTO _IOW('i', 69, struct ifbrparam)/* cache timeout */ +#define SIOCBRDGGTO _IOWR('i', 70, struct ifbrparam)/* cache timeout */ +#define SIOCBRDGDADDR _IOW('i', 71, struct ifbareq) /* delete addr */ +#define SIOCBRDGFLUSH _IOW('i', 72, struct ifbreq) /* flush addr cache */ +#define SIOCBRDGADDL _IOW('i', 73, struct ifbreq) /* add local port */ +#define SIOCBRDGSIFPROT _IOW('i', 74, struct ifbreq) /* set protected grp */ + +#define SIOCBRDGARL _IOW('i', 77, struct ifbrlreq) /* add bridge rule */ +#define SIOCBRDGFRL _IOW('i', 78, struct ifbrlreq) /* flush brdg rules */ +#define SIOCBRDGGRL _IOWR('i', 79, struct ifbrlconf)/* get bridge rules */ +#define SIOCBRDGGPRI _IOWR('i', 80, struct ifbrparam)/* get priority */ +#define SIOCBRDGSPRI _IOW('i', 80, struct ifbrparam)/* set priority */ +#define SIOCBRDGGHT _IOWR('i', 81, struct ifbrparam)/* get hello time */ +#define SIOCBRDGSHT _IOW('i', 81, struct ifbrparam)/* set hello time */ +#define SIOCBRDGGFD _IOWR('i', 82, struct ifbrparam)/* get forward delay */ +#define SIOCBRDGSFD _IOW('i', 82, struct ifbrparam)/* set forward delay */ +#define SIOCBRDGGMA _IOWR('i', 83, struct ifbrparam)/* get max age */ +#define SIOCBRDGSMA _IOW('i', 83, struct ifbrparam)/* set max age */ +#define SIOCBRDGSIFPRIO _IOW('i', 84, struct ifbreq) /* set if priority */ +#define SIOCBRDGSIFCOST _IOW('i', 85, struct ifbreq) /* set if cost */ + +#define SIOCBRDGGPARAM _IOWR('i', 88, struct ifbropreq)/* get brdg STP parms */ +#define SIOCBRDGSTXHC _IOW('i', 89, struct ifbrparam)/* set tx hold count */ +#define SIOCBRDGSPROTO _IOW('i', 90, struct ifbrparam)/* set protocol */ + +#define SIOCSIFMTU _IOW('i', 127, struct ifreq) /* set ifnet mtu */ +#define SIOCGIFMTU _IOWR('i', 126, struct ifreq) /* get ifnet mtu */ + +#define SIOCIFCREATE _IOW('i', 122, struct ifreq) /* create clone if */ +#define SIOCIFDESTROY _IOW('i', 121, struct ifreq) /* destroy clone if */ +#define SIOCIFGCLONERS _IOWR('i', 120, struct if_clonereq) /* get cloners */ + +#define SIOCAIFGROUP _IOW('i', 135, struct ifgroupreq) /* add an ifgroup */ +#define SIOCGIFGROUP _IOWR('i', 136, struct ifgroupreq) /* get ifgroups */ +#define SIOCDIFGROUP _IOW('i', 137, struct ifgroupreq) /* delete ifgroup */ +#define SIOCGIFGMEMB _IOWR('i', 138, struct ifgroupreq) /* get members */ +#define SIOCGIFGATTR _IOWR('i', 139, struct ifgroupreq) /* get ifgroup attribs */ +#define SIOCSIFGATTR _IOW('i', 140, struct ifgroupreq) /* set ifgroup attribs */ +#define SIOCGIFGLIST _IOWR('i', 141, struct ifgroupreq) /* get ifgroup list */ + +#define SIOCSIFDESCR _IOW('i', 128, struct ifreq) /* set ifnet descr */ +#define SIOCGIFDESCR _IOWR('i', 129, struct ifreq) /* get ifnet descr */ + +#define SIOCSIFRTLABEL _IOW('i', 130, struct ifreq) /* set ifnet rtlabel */ +#define SIOCGIFRTLABEL _IOWR('i', 131, struct ifreq) /* set ifnet rtlabel */ + +#define SIOCSETVLAN _IOW('i', 143, struct ifreq) /* set vlan parent if */ +#define SIOCGETVLAN _IOWR('i', 144, struct ifreq) /* get vlan parent if */ + +#define SIOCSSPPPPARAMS _IOW('i', 147, struct ifreq) /* set pppoe params */ +#define SIOCGSPPPPARAMS _IOWR('i', 148, struct ifreq) /* get pppoe params */ + +#define SIOCDELLABEL _IOW('i', 151, struct ifreq) /* del MPLS label */ +#define SIOCGPWE3 _IOWR('i', 152, struct ifreq) /* get MPLS PWE3 cap */ +#define SIOCSETLABEL _IOW('i', 153, struct ifreq) /* set MPLS label */ +#define SIOCGETLABEL _IOW('i', 154, struct ifreq) /* get MPLS label */ + +#define SIOCSIFPRIORITY _IOW('i', 155, struct ifreq) /* set if priority */ +#define SIOCGIFPRIORITY _IOWR('i', 156, struct ifreq) /* get if priority */ + +#define SIOCSIFXFLAGS _IOW('i', 157, struct ifreq) /* set ifnet xflags */ +#define SIOCGIFXFLAGS _IOWR('i', 158, struct ifreq) /* get ifnet xflags */ + +#define SIOCSIFRDOMAIN _IOW('i', 159, struct ifreq) /* set ifnet VRF id */ +#define SIOCGIFRDOMAIN _IOWR('i', 160, struct ifreq) /* get ifnet VRF id */ + +#define SIOCSLIFPHYRTABLE _IOW('i', 161, struct ifreq) /* set tunnel VRF id */ +#define SIOCGLIFPHYRTABLE _IOWR('i', 162, struct ifreq) /* get tunnel VRF id */ + +#define SIOCSETKALIVE _IOW('i', 163, struct ifkalivereq) +#define SIOCGETKALIVE _IOWR('i', 164, struct ifkalivereq) + +#define SIOCGIFHARDMTU _IOWR('i', 165, struct ifreq) /* get ifnet hardmtu */ + +#define SIOCSVNETID _IOW('i', 166, struct ifreq) /* set virt net id */ +#define SIOCGVNETID _IOWR('i', 167, struct ifreq) /* get virt net id */ + +#define SIOCSLIFPHYTTL _IOW('i', 168, struct ifreq) /* set tunnel ttl */ +#define SIOCGLIFPHYTTL _IOWR('i', 169, struct ifreq) /* get tunnel ttl */ + +#define SIOCGIFRXR _IOW('i', 170, struct ifreq) +#define SIOCIFAFATTACH _IOW('i', 171, struct if_afreq) /* attach given af */ +#define SIOCIFAFDETACH _IOW('i', 172, struct if_afreq) /* detach given af */ + +#define SIOCSETMPWCFG _IOW('i', 173, struct ifreq) /* set mpw config */ +#define SIOCGETMPWCFG _IOWR('i', 174, struct ifreq) /* get mpw config */ + +#define SIOCDVNETID _IOW('i', 175, struct ifreq) /* del virt net id */ + +#define SIOCSIFPAIR _IOW('i', 176, struct ifreq) /* set paired if */ +#define SIOCGIFPAIR _IOWR('i', 177, struct ifreq) /* get paired if */ + +#define SIOCSIFPARENT _IOW('i', 178, struct if_parent) /* set parent if */ +#define SIOCGIFPARENT _IOWR('i', 179, struct if_parent) /* get parent if */ +#define SIOCDIFPARENT _IOW('i', 180, struct ifreq) /* del parent if */ + +#define SIOCSIFLLPRIO _IOW('i', 181, struct ifreq) /* set ifnet llprio */ +#define SIOCGIFLLPRIO _IOWR('i', 182, struct ifreq) /* get ifnet llprio */ + +#define SIOCGUMBINFO _IOWR('i', 190, struct ifreq) /* get MBIM info */ +#define SIOCSUMBPARAM _IOW('i', 191, struct ifreq) /* set MBIM param */ +#define SIOCGUMBPARAM _IOWR('i', 192, struct ifreq) /* get MBIM param */ + +#define SIOCSLIFPHYDF _IOW('i', 193, struct ifreq) /* set tunnel df/nodf */ +#define SIOCGLIFPHYDF _IOWR('i', 194, struct ifreq) /* set tunnel df/nodf */ + +#define SIOCSVNETFLOWID _IOW('i', 195, struct ifreq) /* set vnet flowid */ +#define SIOCGVNETFLOWID _IOWR('i', 196, struct ifreq) /* get vnet flowid */ + +#define SIOCSTXHPRIO _IOW('i', 197, struct ifreq) /* set tx hdr prio */ +#define SIOCGTXHPRIO _IOWR('i', 198, struct ifreq) /* get tx hdr prio */ + +#define SIOCSLIFPHYECN _IOW('i', 199, struct ifreq) /* set ecn copying */ +#define SIOCGLIFPHYECN _IOWR('i', 200, struct ifreq) /* get ecn copying */ + +#define SIOCSRXHPRIO _IOW('i', 219, struct ifreq) /* set rx hdr prio */ +#define SIOCGRXHPRIO _IOWR('i', 219, struct ifreq) /* get rx hdr prio */ + +#define SIOCSPWE3CTRLWORD _IOW('i', 220, struct ifreq) +#define SIOCGPWE3CTRLWORD _IOWR('i', 220, struct ifreq) +#define SIOCSPWE3FAT _IOW('i', 221, struct ifreq) +#define SIOCGPWE3FAT _IOWR('i', 221, struct ifreq) +#define SIOCSPWE3NEIGHBOR _IOW('i', 222, struct if_laddrreq) +#define SIOCGPWE3NEIGHBOR _IOWR('i', 222, struct if_laddrreq) +#define SIOCDPWE3NEIGHBOR _IOW('i', 222, struct ifreq) + +#define SIOCSVH _IOWR('i', 245, struct ifreq) /* set carp param */ +#define SIOCGVH _IOWR('i', 246, struct ifreq) /* get carp param */ + +#define SIOCSETPFSYNC _IOW('i', 247, struct ifreq) +#define SIOCGETPFSYNC _IOWR('i', 248, struct ifreq) + +#define SIOCSETPFLOW _IOW('i', 253, struct ifreq) +#define SIOCGETPFLOW _IOWR('i', 254, struct ifreq) + +#endif /* !_SYS_SOCKIO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/softintr.h b/lib/libc/include/generic-openbsd/sys/softintr.h new file mode 100644 index 0000000000..b30da0abab --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/softintr.h @@ -0,0 +1,41 @@ +/* $OpenBSD: softintr.h,v 1.1 2025/04/23 15:07:00 visa Exp $ */ + +/* + * Copyright (c) 2025 Visa Hankala + * + * 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 _SYS_SOFTINTR_H_ +#define _SYS_SOFTINTR_H_ + +#ifdef _KERNEL +#ifdef __USE_MI_SOFTINTR + +#define SOFTINTR_CLOCK 0 +#define SOFTINTR_NET 1 +#define SOFTINTR_TTY 2 +#define NSOFTINTR 3 + +#ifndef _LOCORE +void softintr_init(void); +void *softintr_establish(int, void (*)(void *), void *); +void softintr_disestablish(void *); +void softintr_dispatch(int); +void softintr_schedule(void *); +#endif /* !_LOCORE */ + +#endif /* __USE_MI_SOFTINTR */ +#endif /* _KERNEL */ + +#endif /* !_SYS_SOFTINTR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/specdev.h b/lib/libc/include/generic-openbsd/sys/specdev.h new file mode 100644 index 0000000000..b769f5881d --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/specdev.h @@ -0,0 +1,111 @@ +/* $OpenBSD: specdev.h,v 1.41 2022/06/26 05:20:42 visa Exp $ */ +/* $NetBSD: specdev.h,v 1.12 1996/02/13 13:13:01 mycroft 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. + * + * @(#)specdev.h 8.3 (Berkeley) 8/10/94 + */ + +SLIST_HEAD(vnodechain, vnode); + +/* + * This structure defines the information maintained about + * special devices. It is allocated in checkalias and freed + * in vgone. + */ +struct specinfo { + struct vnodechain *si_hashchain; + SLIST_ENTRY(vnode) si_specnext; + struct mount *si_mountpoint; + dev_t si_rdev; + struct lockf_state *si_lockf; + daddr_t si_lastr; + union { + struct vnode *ci_parent; /* pointer back to parent device */ + u_int8_t *ci_bitmap; /* bitmap of devices cloned off us */ + } si_ci; +}; + +struct cloneinfo { + struct vnode *ci_vp; /* cloned vnode */ + void *ci_data; /* original vnode's v_data */ +}; + +/* + * Exported shorthand + */ +#define v_rdev v_specinfo->si_rdev +#define v_hashchain v_specinfo->si_hashchain +#define v_specnext v_specinfo->si_specnext +#define v_specmountpoint v_specinfo->si_mountpoint +#define v_speclockf v_specinfo->si_lockf +#define v_specparent v_specinfo->si_ci.ci_parent +#define v_specbitmap v_specinfo->si_ci.ci_bitmap + +/* + * We use the upper 16 bits of the minor to record the clone instance. + * This gives us 8 bits for encoding the real minor number. + */ +#define CLONE_SHIFT 8 +#define CLONE_MAPSZ 128 + +/* + * Special device management + */ +#define SPECHSZ 64 +#if ((SPECHSZ&(SPECHSZ-1)) == 0) +#define SPECHASH(rdev) (((rdev>>5)+(rdev))&(SPECHSZ-1)) +#else +#define SPECHASH(rdev) (((unsigned)((rdev>>5)+(rdev)))%SPECHSZ) +#endif + +#ifdef _KERNEL + +extern struct vnodechain speclisth[SPECHSZ]; + +/* + * Prototypes for special file operations on vnodes. + */ +int spec_getattr(void *); +int spec_setattr(void *); +int spec_access(void *); +int spec_open(void *); +int spec_close(void *); +int spec_read(void *); +int spec_write(void *); +int spec_ioctl(void *); +int spec_kqfilter(void *); +int spec_fsync(void *); +int spec_inactive(void *); +int spec_strategy(void *); +int spec_print(void *); +int spec_pathconf(void *); +int spec_advlock(void *); + +#endif /* _KERNEL */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/srp.h b/lib/libc/include/generic-openbsd/sys/srp.h new file mode 100644 index 0000000000..11d846ae79 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/srp.h @@ -0,0 +1,196 @@ +/* $OpenBSD: srp.h,v 1.16 2025/06/25 20:26:32 miod Exp $ */ + +/* + * Copyright (c) 2014 Jonathan Matthew + * + * 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 _SYS_SRP_H_ +#define _SYS_SRP_H_ + +#include + +#ifndef __upunused +#ifdef MULTIPROCESSOR +#define __upunused +#else +#define __upunused __attribute__((__unused__)) +#endif +#endif /* __upunused */ + +struct srp { + void *ref; +}; + +#define SRP_INITIALIZER() { NULL } + +struct srp_hazard { + struct srp *sh_p; + void *sh_v; +}; + +struct srp_ref { + struct srp_hazard *hz; +} __upunused; + +#define SRP_HAZARD_NUM 16 + +struct srp_gc { + void (*srp_gc_dtor)(void *, void *); + void *srp_gc_cookie; + struct refcnt srp_gc_refcnt; +}; + +#define SRP_GC_INITIALIZER(_d, _c) { (_d), (_c), REFCNT_INITIALIZER() } + +/* + * singly linked list built by following srps + */ + +struct srpl_rc { + void (*srpl_ref)(void *, void *); + struct srp_gc srpl_gc; +}; +#define srpl_cookie srpl_gc.srp_gc_cookie + +#define SRPL_RC_INITIALIZER(_r, _u, _c) { _r, SRP_GC_INITIALIZER(_u, _c) } + +struct srpl { + struct srp sl_head; +}; + +#define SRPL_HEAD(name, type) struct srpl + +#define SRPL_ENTRY(type) \ +struct { \ + struct srp se_next; \ +} + +#ifdef _KERNEL + +void srp_startup(void); +void srp_gc_init(struct srp_gc *, void (*)(void *, void *), void *); +void *srp_swap_locked(struct srp *, void *); +void srp_update_locked(struct srp_gc *, struct srp *, void *); +void *srp_get_locked(struct srp *); + +void srp_init(struct srp *); + +#ifdef MULTIPROCESSOR +void *srp_swap(struct srp *, void *); +void srp_update(struct srp_gc *, struct srp *, void *); +void srp_finalize(void *, const char *); +void *srp_enter(struct srp_ref *, struct srp *); +void *srp_follow(struct srp_ref *, struct srp *); +void srp_leave(struct srp_ref *); +#else /* MULTIPROCESSOR */ + +static inline void * +srp_enter(struct srp_ref *sr, struct srp *srp) +{ + sr->hz = NULL; + return srp->ref; +} + +#define srp_swap(_srp, _v) srp_swap_locked((_srp), (_v)) +#define srp_update(_gc, _srp, _v) srp_update_locked((_gc), (_srp), (_v)) +#define srp_finalize(_v, _wchan) ((void)0) +#define srp_follow(_sr, _srp) srp_enter(_sr, _srp) +#define srp_leave(_sr) do { } while (0) +#endif /* MULTIPROCESSOR */ + + +void srpl_rc_init(struct srpl_rc *, void (*)(void *, void *), + void (*)(void *, void *), void *); + +#define SRPL_INIT(_sl) srp_init(&(_sl)->sl_head) + +#define SRPL_FIRST(_sr, _sl) srp_enter((_sr), &(_sl)->sl_head) +#define SRPL_NEXT(_sr, _e, _ENTRY) srp_enter((_sr), &(_e)->_ENTRY.se_next) +#define SRPL_FOLLOW(_sr, _e, _ENTRY) srp_follow((_sr), &(_e)->_ENTRY.se_next) + +#define SRPL_FOREACH(_c, _sr, _sl, _ENTRY) \ + for ((_c) = SRPL_FIRST(_sr, _sl); \ + (_c) != NULL; \ + (_c) = SRPL_FOLLOW(_sr, _c, _ENTRY)) + +#define SRPL_LEAVE(_sr) srp_leave((_sr)) + +#define SRPL_FIRST_LOCKED(_sl) srp_get_locked(&(_sl)->sl_head) +#define SRPL_EMPTY_LOCKED(_sl) (SRPL_FIRST_LOCKED(_sl) == NULL) + +#define SRPL_NEXT_LOCKED(_e, _ENTRY) \ + srp_get_locked(&(_e)->_ENTRY.se_next) + +#define SRPL_FOREACH_LOCKED(_c, _sl, _ENTRY) \ + for ((_c) = SRPL_FIRST_LOCKED(_sl); \ + (_c) != NULL; \ + (_c) = SRPL_NEXT_LOCKED((_c), _ENTRY)) + +#define SRPL_FOREACH_SAFE_LOCKED(_c, _sl, _ENTRY, _tc) \ + for ((_c) = SRPL_FIRST_LOCKED(_sl); \ + (_c) && ((_tc) = SRPL_NEXT_LOCKED(_c, _ENTRY), 1); \ + (_c) = (_tc)) + +#define SRPL_INSERT_HEAD_LOCKED(_rc, _sl, _e, _ENTRY) do { \ + void *head; \ + \ + srp_init(&(_e)->_ENTRY.se_next); \ + \ + head = SRPL_FIRST_LOCKED(_sl); \ + if (head != NULL) { \ + (_rc)->srpl_ref(&(_rc)->srpl_cookie, head); \ + srp_update_locked(&(_rc)->srpl_gc, \ + &(_e)->_ENTRY.se_next, head); \ + } \ + \ + (_rc)->srpl_ref(&(_rc)->srpl_cookie, _e); \ + srp_update_locked(&(_rc)->srpl_gc, &(_sl)->sl_head, (_e)); \ +} while (0) + +#define SRPL_INSERT_AFTER_LOCKED(_rc, _se, _e, _ENTRY) do { \ + void *next; \ + \ + srp_init(&(_e)->_ENTRY.se_next); \ + \ + next = SRPL_NEXT_LOCKED(_se, _ENTRY); \ + if (next != NULL) { \ + (_rc)->srpl_ref(&(_rc)->srpl_cookie, next); \ + srp_update_locked(&(_rc)->srpl_gc, \ + &(_e)->_ENTRY.se_next, next); \ + } \ + \ + (_rc)->srpl_ref(&(_rc)->srpl_cookie, _e); \ + srp_update_locked(&(_rc)->srpl_gc, \ + &(_se)->_ENTRY.se_next, (_e)); \ +} while (0) + +#define SRPL_REMOVE_LOCKED(_rc, _sl, _e, _type, _ENTRY) do { \ + struct srp *ref; \ + struct _type *c, *n; \ + \ + ref = &(_sl)->sl_head; \ + while ((c = srp_get_locked(ref)) != (_e)) \ + ref = &c->_ENTRY.se_next; \ + \ + n = SRPL_NEXT_LOCKED(c, _ENTRY); \ + if (n != NULL) \ + (_rc)->srpl_ref(&(_rc)->srpl_cookie, n); \ + srp_update_locked(&(_rc)->srpl_gc, ref, n); \ + srp_update_locked(&(_rc)->srpl_gc, &c->_ENTRY.se_next, NULL); \ +} while (0) + +#endif /* _KERNEL */ + +#endif /* _SYS_SRP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/stacktrace.h b/lib/libc/include/generic-openbsd/sys/stacktrace.h new file mode 100644 index 0000000000..aec5d32feb --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/stacktrace.h @@ -0,0 +1,41 @@ +/* $OpenBSD: stacktrace.h,v 1.4 2023/04/26 16:53:59 claudio Exp $ */ + +/* + * Copyright (c) 2017 Visa Hankala + * + * Permission to use, copy, modify, and/or 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 _SYS_STACKTRACE_H_ +#define _SYS_STACKTRACE_H_ + +#define STACKTRACE_MAX 19 + +struct stacktrace { + unsigned int st_count; + unsigned long st_pc[STACKTRACE_MAX]; +}; + +#ifdef _KERNEL +void stacktrace_print(struct stacktrace *, int (*)(const char *, ...)); +void stacktrace_save_at(struct stacktrace *, unsigned int); +void stacktrace_save_utrace(struct stacktrace *); + +static inline void +stacktrace_save(struct stacktrace *st) +{ + stacktrace_save_at(st, 0); +} +#endif + +#endif /* _SYS_STACKTRACE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/stat.h b/lib/libc/include/generic-openbsd/sys/stat.h new file mode 100644 index 0000000000..578c27ebed --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/stat.h @@ -0,0 +1,222 @@ +/* $OpenBSD: stat.h,v 1.29 2022/01/11 23:59:55 jsg Exp $ */ +/* $NetBSD: stat.h,v 1.20 1996/05/16 22:17:49 cgd Exp $ */ + +/*- + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)stat.h 8.9 (Berkeley) 8/17/94 + */ + +#ifndef _SYS_STAT_H_ +#define _SYS_STAT_H_ + +#include + +struct stat { + mode_t st_mode; /* inode protection mode */ + dev_t st_dev; /* inode's device */ + ino_t st_ino; /* inode's number */ + nlink_t st_nlink; /* number of hard links */ + uid_t st_uid; /* user ID of the file's owner */ + gid_t st_gid; /* group ID of the file's group */ + dev_t st_rdev; /* device type */ +#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE + struct timespec st_atim; /* time of last access */ + struct timespec st_mtim; /* time of last data modification */ + struct timespec st_ctim; /* time of last file status change */ +#else + time_t st_atime; /* time of last access */ + long st_atimensec; /* nsec of last access */ + time_t st_mtime; /* time of last data modification */ + long st_mtimensec; /* nsec of last data modification */ + time_t st_ctime; /* time of last file status change */ + long st_ctimensec; /* nsec of last file status change */ +#endif /* __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE */ + off_t st_size; /* file size, in bytes */ + blkcnt_t st_blocks; /* blocks allocated for file */ + blksize_t st_blksize; /* optimal blocksize for I/O */ + u_int32_t st_flags; /* user defined flags for file */ + u_int32_t st_gen; /* file generation number */ +#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE + struct timespec __st_birthtim; /* time of file creation */ +#else + time_t __st_birthtime; /* time of file creation */ + long __st_birthtimensec; /* nsec of file creation */ +#endif /* __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE */ +}; +#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE +#define st_atime st_atim.tv_sec +#define st_mtime st_mtim.tv_sec +#define st_ctime st_ctim.tv_sec +#define __st_birthtime __st_birthtim.tv_sec +#endif +#if __BSD_VISIBLE +#define st_atimespec st_atim +#define st_atimensec st_atim.tv_nsec +#define st_mtimespec st_mtim +#define st_mtimensec st_mtim.tv_nsec +#define st_ctimespec st_ctim +#define st_ctimensec st_ctim.tv_nsec +#define __st_birthtimespec __st_birthtim +#define __st_birthtimensec __st_birthtim.tv_nsec +#endif + +#define S_ISUID 0004000 /* set user id on execution */ +#define S_ISGID 0002000 /* set group id on execution */ +#if __BSD_VISIBLE +#define S_ISTXT 0001000 /* sticky bit */ +#endif + +#define S_IRWXU 0000700 /* RWX mask for owner */ +#define S_IRUSR 0000400 /* R for owner */ +#define S_IWUSR 0000200 /* W for owner */ +#define S_IXUSR 0000100 /* X for owner */ + +#if __BSD_VISIBLE +#define S_IREAD S_IRUSR +#define S_IWRITE S_IWUSR +#define S_IEXEC S_IXUSR +#endif + +#define S_IRWXG 0000070 /* RWX mask for group */ +#define S_IRGRP 0000040 /* R for group */ +#define S_IWGRP 0000020 /* W for group */ +#define S_IXGRP 0000010 /* X for group */ + +#define S_IRWXO 0000007 /* RWX mask for other */ +#define S_IROTH 0000004 /* R for other */ +#define S_IWOTH 0000002 /* W for other */ +#define S_IXOTH 0000001 /* X for other */ + +#if __XPG_VISIBLE || __BSD_VISIBLE +#define S_IFMT 0170000 /* type of file mask */ +#define S_IFIFO 0010000 /* named pipe (fifo) */ +#define S_IFCHR 0020000 /* character special */ +#define S_IFDIR 0040000 /* directory */ +#define S_IFBLK 0060000 /* block special */ +#define S_IFREG 0100000 /* regular */ +#define S_IFLNK 0120000 /* symbolic link */ +#define S_IFSOCK 0140000 /* socket */ +#define S_ISVTX 0001000 /* save swapped text even after use */ +#endif + +#define S_ISDIR(m) ((m & 0170000) == 0040000) /* directory */ +#define S_ISCHR(m) ((m & 0170000) == 0020000) /* char special */ +#define S_ISBLK(m) ((m & 0170000) == 0060000) /* block special */ +#define S_ISREG(m) ((m & 0170000) == 0100000) /* regular file */ +#define S_ISFIFO(m) ((m & 0170000) == 0010000) /* fifo */ +#if __POSIX_VISIBLE >= 200112 || __BSD_VISIBLE +#define S_ISLNK(m) ((m & 0170000) == 0120000) /* symbolic link */ +#define S_ISSOCK(m) ((m & 0170000) == 0140000) /* socket */ +#endif + +#if __POSIX_VISIBLE >= 200809 +/* mandated to be present, but permitted to always return zero */ +#define S_TYPEISMQ(m) 0 +#define S_TYPEISSEM(m) 0 +#define S_TYPEISSHM(m) 0 +#endif + +#if __BSD_VISIBLE +#define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 00777 */ + /* 07777 */ +#define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO) + /* 00666 */ +#define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) + +#define S_BLKSIZE 512 /* block size used in the stat struct */ + +/* + * Definitions of flags stored in file flags word. + * + * Super-user and owner changeable flags. + */ +#define UF_SETTABLE 0x0000ffff /* mask of owner changeable flags */ +#define UF_NODUMP 0x00000001 /* do not dump file */ +#define UF_IMMUTABLE 0x00000002 /* file may not be changed */ +#define UF_APPEND 0x00000004 /* writes to file may only append */ +#define UF_OPAQUE 0x00000008 /* directory is opaque wrt. union */ +/* + * Super-user changeable flags. + */ +#define SF_SETTABLE 0xffff0000 /* mask of superuser changeable flags */ +#define SF_ARCHIVED 0x00010000 /* file is archived */ +#define SF_IMMUTABLE 0x00020000 /* file may not be changed */ +#define SF_APPEND 0x00040000 /* writes to file may only append */ + +#ifdef _KERNEL +/* + * Shorthand abbreviations of above. + */ +#define OPAQUE (UF_OPAQUE) +#define APPEND (UF_APPEND | SF_APPEND) +#define IMMUTABLE (UF_IMMUTABLE | SF_IMMUTABLE) +#endif /* _KERNEL */ +#endif /* __BSD_VISIBLE */ + +#if __POSIX_VISIBLE >= 200809 +#define UTIME_NOW -2L +#define UTIME_OMIT -1L +#endif /* __POSIX_VISIBLE */ + +#ifndef _KERNEL +__BEGIN_DECLS +int chmod(const char *, mode_t); +int fstat(int, struct stat *); +int mknod(const char *, mode_t, dev_t); +int mkdir(const char *, mode_t); +int mkfifo(const char *, mode_t); +int stat(const char *, struct stat *); +mode_t umask(mode_t); +#if __POSIX_VISIBLE >= 200112L || __XPG_VISIBLE >= 420 || __BSD_VISIBLE +int fchmod(int, mode_t); +int lstat(const char *, struct stat *); +#endif +#if __POSIX_VISIBLE >= 200809 +int fchmodat(int, const char *, mode_t, int); +int fstatat(int, const char *, struct stat *, int); +int mkdirat(int, const char *, mode_t); +int mkfifoat(int, const char *, mode_t); +int mknodat(int, const char *, mode_t, dev_t); +int utimensat(int, const char *, const struct timespec [2], int); +int futimens(int, const struct timespec [2]); +#endif +#if __BSD_VISIBLE +int chflags(const char *, unsigned int); +int chflagsat(int, const char *, unsigned int, int); +int fchflags(int, unsigned int); +int isfdtype(int, int); +#endif +__END_DECLS +#endif +#endif /* !_SYS_STAT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/statvfs.h b/lib/libc/include/generic-openbsd/sys/statvfs.h new file mode 100644 index 0000000000..d5c873bde2 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/statvfs.h @@ -0,0 +1,48 @@ +/* $OpenBSD: statvfs.h,v 1.4 2022/02/11 15:11:35 millert Exp $ */ + +/* + * Copyright (c) 2008 Otto Moerbeek + * + * 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 _SYS_STATVFS_H_ +#define _SYS_STATVFS_H_ + +#include + +struct statvfs { + unsigned long f_bsize; /* file system block size */ + unsigned long f_frsize; /* fundamental file system block size */ + fsblkcnt_t f_blocks; /* number of blocks (unit f_frsize) */ + fsblkcnt_t f_bfree; /* free blocks in file system */ + fsblkcnt_t f_bavail; /* free blocks for non-root */ + fsfilcnt_t f_files; /* total file inodes */ + fsfilcnt_t f_ffree; /* free file inodes */ + fsfilcnt_t f_favail; /* free file inodes for non-root */ + unsigned long f_fsid; /* file system id */ + unsigned long f_flag; /* bit mask of f_flag values */ + unsigned long f_namemax; /* maximum filename length */ +}; + +#define ST_RDONLY 0x0001UL /* read-only filesystem */ +#define ST_NOSUID 0x0002UL /* nosuid flag set */ + +#ifndef _KERNEL +__BEGIN_DECLS +int fstatvfs(int, struct statvfs *); +int statvfs(const char *, struct statvfs *); +__END_DECLS +#endif /* !_KERNEL */ + +#endif /* !_SYS_STATVFS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/stdarg.h b/lib/libc/include/generic-openbsd/sys/stdarg.h new file mode 100644 index 0000000000..0fbd75bb6e --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/stdarg.h @@ -0,0 +1,45 @@ +/* $OpenBSD: stdarg.h,v 1.10 2020/07/21 23:09:00 daniel Exp $ */ +/* + * Copyright (c) 2003, 2004 Marc espie + * + * 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 _STDARG_H_ +#define _STDARG_H_ + +#include + +/* Define __gnuc_va_list. */ + +#ifndef __GNUC_VA_LIST +#define __GNUC_VA_LIST +typedef __builtin_va_list __gnuc_va_list; +#endif + +/* Note that the type used in va_arg is supposed to match the + actual type **after default promotions**. + Thus, va_arg (..., short) is not valid. */ + +#define va_start(ap, last) __builtin_va_start((ap), last) +#define va_end(ap) __builtin_va_end((ap)) +#define va_arg(ap, type) __builtin_va_arg((ap), type) +#define __va_copy(dst, src) __builtin_va_copy((dst),(src)) + +typedef __gnuc_va_list va_list; + +#if __ISO_C_VISIBLE >= 1999 +#define va_copy(dst, src) __va_copy((dst), (src)) +#endif + +#endif /* not _STDARG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/stdint.h b/lib/libc/include/generic-openbsd/sys/stdint.h new file mode 100644 index 0000000000..c0372ec51c --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/stdint.h @@ -0,0 +1,231 @@ +/* $OpenBSD: stdint.h,v 1.11 2019/01/25 00:19:26 millert Exp $ */ + +/* + * Copyright (c) 1997, 2005 Todd C. Miller + * + * 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 _SYS_STDINT_H_ +#define _SYS_STDINT_H_ + +#include +#include + +#ifndef __BIT_TYPES_DEFINED__ +#define __BIT_TYPES_DEFINED__ +#endif + +/* 7.18.1.1 Exact-width integer types (also in sys/types.h) */ +#ifndef _INT8_T_DEFINED_ +#define _INT8_T_DEFINED_ +typedef __int8_t int8_t; +#endif + +#ifndef _UINT8_T_DEFINED_ +#define _UINT8_T_DEFINED_ +typedef __uint8_t uint8_t; +#endif + +#ifndef _INT16_T_DEFINED_ +#define _INT16_T_DEFINED_ +typedef __int16_t int16_t; +#endif + +#ifndef _UINT16_T_DEFINED_ +#define _UINT16_T_DEFINED_ +typedef __uint16_t uint16_t; +#endif + +#ifndef _INT32_T_DEFINED_ +#define _INT32_T_DEFINED_ +typedef __int32_t int32_t; +#endif + +#ifndef _UINT32_T_DEFINED_ +#define _UINT32_T_DEFINED_ +typedef __uint32_t uint32_t; +#endif + +#ifndef _INT64_T_DEFINED_ +#define _INT64_T_DEFINED_ +typedef __int64_t int64_t; +#endif + +#ifndef _UINT64_T_DEFINED_ +#define _UINT64_T_DEFINED_ +typedef __uint64_t uint64_t; +#endif + +/* 7.18.1.2 Minimum-width integer types */ +typedef __int_least8_t int_least8_t; +typedef __uint_least8_t uint_least8_t; +typedef __int_least16_t int_least16_t; +typedef __uint_least16_t uint_least16_t; +typedef __int_least32_t int_least32_t; +typedef __uint_least32_t uint_least32_t; +typedef __int_least64_t int_least64_t; +typedef __uint_least64_t uint_least64_t; + +/* 7.18.1.3 Fastest minimum-width integer types */ +typedef __int_fast8_t int_fast8_t; +typedef __uint_fast8_t uint_fast8_t; +typedef __int_fast16_t int_fast16_t; +typedef __uint_fast16_t uint_fast16_t; +typedef __int_fast32_t int_fast32_t; +typedef __uint_fast32_t uint_fast32_t; +typedef __int_fast64_t int_fast64_t; +typedef __uint_fast64_t uint_fast64_t; + +/* 7.18.1.4 Integer types capable of holding object pointers */ +#ifndef _INTPTR_T_DEFINED_ +#define _INTPTR_T_DEFINED_ +typedef __intptr_t intptr_t; +#endif + +typedef __uintptr_t uintptr_t; + +/* 7.18.1.5 Greatest-width integer types */ +typedef __intmax_t intmax_t; +typedef __uintmax_t uintmax_t; + +/* + * 7.18.2 Limits of specified-width integer types. + * + * The following object-like macros specify the minimum and maximum limits + * of integer types corresponding to the typedef names defined above. + */ + +/* 7.18.2.1 Limits of exact-width integer types */ +#define INT8_MIN (-0x7f - 1) +#define INT16_MIN (-0x7fff - 1) +#define INT32_MIN (-0x7fffffff - 1) +#define INT64_MIN (-0x7fffffffffffffffLL - 1) + +#define INT8_MAX 0x7f +#define INT16_MAX 0x7fff +#define INT32_MAX 0x7fffffff +#define INT64_MAX 0x7fffffffffffffffLL + +#define UINT8_MAX 0xff +#define UINT16_MAX 0xffff +#define UINT32_MAX 0xffffffffU +#define UINT64_MAX 0xffffffffffffffffULL + +/* 7.18.2.2 Limits of minimum-width integer types */ +#define INT_LEAST8_MIN INT8_MIN +#define INT_LEAST16_MIN INT16_MIN +#define INT_LEAST32_MIN INT32_MIN +#define INT_LEAST64_MIN INT64_MIN + +#define INT_LEAST8_MAX INT8_MAX +#define INT_LEAST16_MAX INT16_MAX +#define INT_LEAST32_MAX INT32_MAX +#define INT_LEAST64_MAX INT64_MAX + +#define UINT_LEAST8_MAX UINT8_MAX +#define UINT_LEAST16_MAX UINT16_MAX +#define UINT_LEAST32_MAX UINT32_MAX +#define UINT_LEAST64_MAX UINT64_MAX + +/* 7.18.2.3 Limits of fastest minimum-width integer types */ +#define INT_FAST8_MIN __INT_FAST8_MIN +#define INT_FAST16_MIN __INT_FAST16_MIN +#define INT_FAST32_MIN __INT_FAST32_MIN +#define INT_FAST64_MIN __INT_FAST64_MIN + +#define INT_FAST8_MAX __INT_FAST8_MAX +#define INT_FAST16_MAX __INT_FAST16_MAX +#define INT_FAST32_MAX __INT_FAST32_MAX +#define INT_FAST64_MAX __INT_FAST64_MAX + +#define UINT_FAST8_MAX __UINT_FAST8_MAX +#define UINT_FAST16_MAX __UINT_FAST16_MAX +#define UINT_FAST32_MAX __UINT_FAST32_MAX +#define UINT_FAST64_MAX __UINT_FAST64_MAX + +/* 7.18.2.4 Limits of integer types capable of holding object pointers */ +#ifdef __LP64__ +#define INTPTR_MIN (-0x7fffffffffffffffL - 1) +#define INTPTR_MAX 0x7fffffffffffffffL +#define UINTPTR_MAX 0xffffffffffffffffUL +#else +#define INTPTR_MIN (-0x7fffffffL - 1) +#define INTPTR_MAX 0x7fffffffL +#define UINTPTR_MAX 0xffffffffUL +#endif + +/* 7.18.2.5 Limits of greatest-width integer types */ +#define INTMAX_MIN INT64_MIN +#define INTMAX_MAX INT64_MAX +#define UINTMAX_MAX UINT64_MAX + +/* + * 7.18.3 Limits of other integer types. + * + * The following object-like macros specify the minimum and maximum limits + * of integer types corresponding to types specified in other standard + * header files. + */ + +/* Limits of ptrdiff_t */ +#define PTRDIFF_MIN INTPTR_MIN +#define PTRDIFF_MAX INTPTR_MAX + +/* Limits of sig_atomic_t */ +#define SIG_ATOMIC_MIN INT32_MIN +#define SIG_ATOMIC_MAX INT32_MAX + +/* Limit of size_t */ +#ifndef SIZE_MAX +#define SIZE_MAX UINTPTR_MAX +#endif + +/* Limits of wchar_t */ +#ifndef WCHAR_MIN +#define WCHAR_MIN INT32_MIN +#endif +#ifndef WCHAR_MAX +#define WCHAR_MAX INT32_MAX +#endif + +/* Limits of wint_t */ +#define WINT_MIN INT32_MIN +#define WINT_MAX INT32_MAX + +/* + * 7.18.4 Macros for integer constants. + * + * The following function-like macros expand to integer constants + * suitable for initializing objects that have integer types corresponding + * to types defined in . The argument in any instance of + * these macros shall be a decimal, octal, or hexadecimal constant with + * a value that does not exceed the limits for the corresponding type. + */ + +/* 7.18.4.1 Macros for minimum-width integer constants. */ +#define INT8_C(_c) (_c) +#define INT16_C(_c) (_c) +#define INT32_C(_c) (_c) +#define INT64_C(_c) __CONCAT(_c, LL) + +#define UINT8_C(_c) (_c) +#define UINT16_C(_c) (_c) +#define UINT32_C(_c) __CONCAT(_c, U) +#define UINT64_C(_c) __CONCAT(_c, ULL) + +/* 7.18.4.2 Macros for greatest-width integer constants. */ +#define INTMAX_C(_c) __CONCAT(_c, LL) +#define UINTMAX_C(_c) __CONCAT(_c, ULL) + +#endif /* _SYS_STDINT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/swap.h b/lib/libc/include/generic-openbsd/sys/swap.h new file mode 100644 index 0000000000..4018a7813a --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/swap.h @@ -0,0 +1,62 @@ +/* $OpenBSD: swap.h,v 1.7 2013/09/30 12:02:30 millert Exp $ */ +/* $NetBSD: swap.h,v 1.2 1998/09/13 14:46:24 christos Exp $ */ + +/* + * Copyright (c) 1995, 1996, 1998 Matthew R. Green, Tobias Weingartner + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_SWAP_H_ +#define _SYS_SWAP_H_ + +#include + +/* These structures are used to return swap information for userland */ +struct swapent { + dev_t se_dev; /* device id */ + int se_flags; /* flags */ + int se_nblks; /* total blocks */ + int se_inuse; /* blocks in use */ + int se_priority; /* priority of this device */ + char se_path[PATH_MAX]; /* path name */ +}; + +#ifdef _KERNEL +#define NETDEV (dev_t)(-2) /* network device (for nfs swap) */ +#endif /* _KERNEL */ + +#define SWAP_ON 1 /* begin swapping on device */ +#define SWAP_OFF 2 /* (stop swapping on device) */ +#define SWAP_NSWAP 3 /* how many swap devices ? */ +#define SWAP_STATS 4 /* get device info */ +#define SWAP_CTL 5 /* change priority on device */ +#define SWAP_DUMPDEV 7 /* use this device as dump device */ + +#define SWF_INUSE 0x00000001 /* in use: we have swapped here */ +#define SWF_ENABLE 0x00000002 /* enabled: we can swap here */ +#define SWF_BUSY 0x00000004 /* busy: I/O happening here */ +#define SWF_FAKE 0x00000008 /* fake: still being built */ + +#endif /* _SYS_SWAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/syscall.h b/lib/libc/include/generic-openbsd/sys/syscall.h new file mode 100644 index 0000000000..6aa7b3f897 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/syscall.h @@ -0,0 +1,728 @@ +/* $OpenBSD: syscall.h,v 1.283 2025/05/24 06:50:02 deraadt Exp $ */ + +/* + * System call numbers. + * + * DO NOT EDIT-- this file is automatically generated. + * created from; OpenBSD: syscalls.master,v 1.270 2025/05/24 06:49:16 deraadt Exp + */ + +/* syscall: "exit" ret: "void" args: "int" */ +#define SYS_exit 1 + +/* syscall: "fork" ret: "int" args: */ +#define SYS_fork 2 + +/* syscall: "read" ret: "ssize_t" args: "int" "void *" "size_t" */ +#define SYS_read 3 + +/* syscall: "write" ret: "ssize_t" args: "int" "const void *" "size_t" */ +#define SYS_write 4 + +/* syscall: "open" ret: "int" args: "const char *" "int" "..." "mode_t" */ +#define SYS_open 5 + +/* syscall: "close" ret: "int" args: "int" */ +#define SYS_close 6 + +/* syscall: "getentropy" ret: "int" args: "void *" "size_t" */ +#define SYS_getentropy 7 + +/* syscall: "__tfork" ret: "int" args: "const struct __tfork *" "size_t" */ +#define SYS___tfork 8 + +/* syscall: "link" ret: "int" args: "const char *" "const char *" */ +#define SYS_link 9 + +/* syscall: "unlink" ret: "int" args: "const char *" */ +#define SYS_unlink 10 + +/* syscall: "wait4" ret: "pid_t" args: "pid_t" "int *" "int" "struct rusage *" */ +#define SYS_wait4 11 + +/* syscall: "chdir" ret: "int" args: "const char *" */ +#define SYS_chdir 12 + +/* syscall: "fchdir" ret: "int" args: "int" */ +#define SYS_fchdir 13 + +/* syscall: "mknod" ret: "int" args: "const char *" "mode_t" "dev_t" */ +#define SYS_mknod 14 + +/* syscall: "chmod" ret: "int" args: "const char *" "mode_t" */ +#define SYS_chmod 15 + +/* syscall: "chown" ret: "int" args: "const char *" "uid_t" "gid_t" */ +#define SYS_chown 16 + +/* syscall: "break" ret: "int" args: "char *" */ +#define SYS_break 17 + +/* syscall: "getdtablecount" ret: "int" args: */ +#define SYS_getdtablecount 18 + +/* syscall: "getrusage" ret: "int" args: "int" "struct rusage *" */ +#define SYS_getrusage 19 + +/* syscall: "getpid" ret: "pid_t" args: */ +#define SYS_getpid 20 + +/* syscall: "mount" ret: "int" args: "const char *" "const char *" "int" "void *" */ +#define SYS_mount 21 + +/* syscall: "unmount" ret: "int" args: "const char *" "int" */ +#define SYS_unmount 22 + +/* syscall: "setuid" ret: "int" args: "uid_t" */ +#define SYS_setuid 23 + +/* syscall: "getuid" ret: "uid_t" args: */ +#define SYS_getuid 24 + +/* syscall: "geteuid" ret: "uid_t" args: */ +#define SYS_geteuid 25 + +/* syscall: "ptrace" ret: "int" args: "int" "pid_t" "caddr_t" "int" */ +#define SYS_ptrace 26 + +/* syscall: "recvmsg" ret: "ssize_t" args: "int" "struct msghdr *" "int" */ +#define SYS_recvmsg 27 + +/* syscall: "sendmsg" ret: "ssize_t" args: "int" "const struct msghdr *" "int" */ +#define SYS_sendmsg 28 + +/* syscall: "recvfrom" ret: "ssize_t" args: "int" "void *" "size_t" "int" "struct sockaddr *" "socklen_t *" */ +#define SYS_recvfrom 29 + +/* syscall: "accept" ret: "int" args: "int" "struct sockaddr *" "socklen_t *" */ +#define SYS_accept 30 + +/* syscall: "getpeername" ret: "int" args: "int" "struct sockaddr *" "socklen_t *" */ +#define SYS_getpeername 31 + +/* syscall: "getsockname" ret: "int" args: "int" "struct sockaddr *" "socklen_t *" */ +#define SYS_getsockname 32 + +/* syscall: "access" ret: "int" args: "const char *" "int" */ +#define SYS_access 33 + +/* syscall: "chflags" ret: "int" args: "const char *" "u_int" */ +#define SYS_chflags 34 + +/* syscall: "fchflags" ret: "int" args: "int" "u_int" */ +#define SYS_fchflags 35 + +/* syscall: "sync" ret: "void" args: */ +#define SYS_sync 36 + + /* 37 is obsolete msyscall */ +/* syscall: "stat" ret: "int" args: "const char *" "struct stat *" */ +#define SYS_stat 38 + +/* syscall: "getppid" ret: "pid_t" args: */ +#define SYS_getppid 39 + +/* syscall: "lstat" ret: "int" args: "const char *" "struct stat *" */ +#define SYS_lstat 40 + +/* syscall: "dup" ret: "int" args: "int" */ +#define SYS_dup 41 + +/* syscall: "fstatat" ret: "int" args: "int" "const char *" "struct stat *" "int" */ +#define SYS_fstatat 42 + +/* syscall: "getegid" ret: "gid_t" args: */ +#define SYS_getegid 43 + +/* syscall: "ktrace" ret: "int" args: "const char *" "int" "int" "pid_t" */ +#define SYS_ktrace 45 + +/* syscall: "sigaction" ret: "int" args: "int" "const struct sigaction *" "struct sigaction *" */ +#define SYS_sigaction 46 + +/* syscall: "getgid" ret: "gid_t" args: */ +#define SYS_getgid 47 + +/* syscall: "sigprocmask" ret: "int" args: "int" "sigset_t" */ +#define SYS_sigprocmask 48 + +/* syscall: "mmap" ret: "void *" args: "void *" "size_t" "int" "int" "int" "off_t" */ +#define SYS_mmap 49 + +/* syscall: "setlogin" ret: "int" args: "const char *" */ +#define SYS_setlogin 50 + +/* syscall: "acct" ret: "int" args: "const char *" */ +#define SYS_acct 51 + +/* syscall: "sigpending" ret: "int" args: */ +#define SYS_sigpending 52 + +/* syscall: "fstat" ret: "int" args: "int" "struct stat *" */ +#define SYS_fstat 53 + +/* syscall: "ioctl" ret: "int" args: "int" "u_long" "..." "void *" */ +#define SYS_ioctl 54 + +/* syscall: "reboot" ret: "int" args: "int" */ +#define SYS_reboot 55 + +/* syscall: "revoke" ret: "int" args: "const char *" */ +#define SYS_revoke 56 + +/* syscall: "symlink" ret: "int" args: "const char *" "const char *" */ +#define SYS_symlink 57 + +/* syscall: "readlink" ret: "ssize_t" args: "const char *" "char *" "size_t" */ +#define SYS_readlink 58 + +/* syscall: "execve" ret: "int" args: "const char *" "char *const *" "char *const *" */ +#define SYS_execve 59 + +/* syscall: "umask" ret: "mode_t" args: "mode_t" */ +#define SYS_umask 60 + +/* syscall: "chroot" ret: "int" args: "const char *" */ +#define SYS_chroot 61 + +/* syscall: "getfsstat" ret: "int" args: "struct statfs *" "size_t" "int" */ +#define SYS_getfsstat 62 + +/* syscall: "statfs" ret: "int" args: "const char *" "struct statfs *" */ +#define SYS_statfs 63 + +/* syscall: "fstatfs" ret: "int" args: "int" "struct statfs *" */ +#define SYS_fstatfs 64 + +/* syscall: "fhstatfs" ret: "int" args: "const fhandle_t *" "struct statfs *" */ +#define SYS_fhstatfs 65 + +/* syscall: "vfork" ret: "int" args: */ +#define SYS_vfork 66 + +/* syscall: "gettimeofday" ret: "int" args: "struct timeval *" "struct timezone *" */ +#define SYS_gettimeofday 67 + +/* syscall: "settimeofday" ret: "int" args: "const struct timeval *" "const struct timezone *" */ +#define SYS_settimeofday 68 + +/* syscall: "setitimer" ret: "int" args: "int" "const struct itimerval *" "struct itimerval *" */ +#define SYS_setitimer 69 + +/* syscall: "getitimer" ret: "int" args: "int" "struct itimerval *" */ +#define SYS_getitimer 70 + +/* syscall: "select" ret: "int" args: "int" "fd_set *" "fd_set *" "fd_set *" "struct timeval *" */ +#define SYS_select 71 + +/* syscall: "kevent" ret: "int" args: "int" "const struct kevent *" "int" "struct kevent *" "int" "const struct timespec *" */ +#define SYS_kevent 72 + +/* syscall: "munmap" ret: "int" args: "void *" "size_t" */ +#define SYS_munmap 73 + +/* syscall: "mprotect" ret: "int" args: "void *" "size_t" "int" */ +#define SYS_mprotect 74 + +/* syscall: "madvise" ret: "int" args: "void *" "size_t" "int" */ +#define SYS_madvise 75 + +/* syscall: "utimes" ret: "int" args: "const char *" "const struct timeval *" */ +#define SYS_utimes 76 + +/* syscall: "futimes" ret: "int" args: "int" "const struct timeval *" */ +#define SYS_futimes 77 + +/* syscall: "mquery" ret: "void *" args: "void *" "size_t" "int" "int" "int" "off_t" */ +#define SYS_mquery 78 + +/* syscall: "getgroups" ret: "int" args: "int" "gid_t *" */ +#define SYS_getgroups 79 + +/* syscall: "setgroups" ret: "int" args: "int" "const gid_t *" */ +#define SYS_setgroups 80 + +/* syscall: "getpgrp" ret: "int" args: */ +#define SYS_getpgrp 81 + +/* syscall: "setpgid" ret: "int" args: "pid_t" "pid_t" */ +#define SYS_setpgid 82 + +/* syscall: "futex" ret: "int" args: "uint32_t *" "int" "int" "const struct timespec *" "uint32_t *" */ +#define SYS_futex 83 + +/* syscall: "utimensat" ret: "int" args: "int" "const char *" "const struct timespec *" "int" */ +#define SYS_utimensat 84 + +/* syscall: "futimens" ret: "int" args: "int" "const struct timespec *" */ +#define SYS_futimens 85 + +/* syscall: "kbind" ret: "int" args: "const struct __kbind *" "size_t" "int64_t" */ +#define SYS_kbind 86 + +/* syscall: "clock_gettime" ret: "int" args: "clockid_t" "struct timespec *" */ +#define SYS_clock_gettime 87 + +/* syscall: "clock_settime" ret: "int" args: "clockid_t" "const struct timespec *" */ +#define SYS_clock_settime 88 + +/* syscall: "clock_getres" ret: "int" args: "clockid_t" "struct timespec *" */ +#define SYS_clock_getres 89 + +/* syscall: "dup2" ret: "int" args: "int" "int" */ +#define SYS_dup2 90 + +/* syscall: "nanosleep" ret: "int" args: "const struct timespec *" "struct timespec *" */ +#define SYS_nanosleep 91 + +/* syscall: "fcntl" ret: "int" args: "int" "int" "..." "void *" */ +#define SYS_fcntl 92 + +/* syscall: "accept4" ret: "int" args: "int" "struct sockaddr *" "socklen_t *" "int" */ +#define SYS_accept4 93 + +/* syscall: "__thrsleep" ret: "int" args: "const volatile void *" "clockid_t" "const struct timespec *" "void *" "const int *" */ +#define SYS___thrsleep 94 + +/* syscall: "fsync" ret: "int" args: "int" */ +#define SYS_fsync 95 + +/* syscall: "setpriority" ret: "int" args: "int" "id_t" "int" */ +#define SYS_setpriority 96 + +/* syscall: "socket" ret: "int" args: "int" "int" "int" */ +#define SYS_socket 97 + +/* syscall: "connect" ret: "int" args: "int" "const struct sockaddr *" "socklen_t" */ +#define SYS_connect 98 + +/* syscall: "getdents" ret: "int" args: "int" "void *" "size_t" */ +#define SYS_getdents 99 + +/* syscall: "getpriority" ret: "int" args: "int" "id_t" */ +#define SYS_getpriority 100 + +/* syscall: "pipe2" ret: "int" args: "int *" "int" */ +#define SYS_pipe2 101 + +/* syscall: "dup3" ret: "int" args: "int" "int" "int" */ +#define SYS_dup3 102 + +/* syscall: "sigreturn" ret: "int" args: "struct sigcontext *" */ +#define SYS_sigreturn 103 + +/* syscall: "bind" ret: "int" args: "int" "const struct sockaddr *" "socklen_t" */ +#define SYS_bind 104 + +/* syscall: "setsockopt" ret: "int" args: "int" "int" "int" "const void *" "socklen_t" */ +#define SYS_setsockopt 105 + +/* syscall: "listen" ret: "int" args: "int" "int" */ +#define SYS_listen 106 + +/* syscall: "chflagsat" ret: "int" args: "int" "const char *" "u_int" "int" */ +#define SYS_chflagsat 107 + +/* syscall: "pledge" ret: "int" args: "const char *" "const char *" */ +#define SYS_pledge 108 + +/* syscall: "ppoll" ret: "int" args: "struct pollfd *" "u_int" "const struct timespec *" "const sigset_t *" */ +#define SYS_ppoll 109 + +/* syscall: "pselect" ret: "int" args: "int" "fd_set *" "fd_set *" "fd_set *" "const struct timespec *" "const sigset_t *" */ +#define SYS_pselect 110 + +/* syscall: "sigsuspend" ret: "int" args: "int" */ +#define SYS_sigsuspend 111 + +/* syscall: "sendsyslog" ret: "int" args: "const char *" "size_t" "int" */ +#define SYS_sendsyslog 112 + +/* syscall: "unveil" ret: "int" args: "const char *" "const char *" */ +#define SYS_unveil 114 + +/* syscall: "__realpath" ret: "int" args: "const char *" "char *" */ +#define SYS___realpath 115 + +/* syscall: "recvmmsg" ret: "int" args: "int" "struct mmsghdr *" "unsigned int" "int" "struct timespec *" */ +#define SYS_recvmmsg 116 + +/* syscall: "sendmmsg" ret: "int" args: "int" "struct mmsghdr *" "unsigned int" "int" */ +#define SYS_sendmmsg 117 + +/* syscall: "getsockopt" ret: "int" args: "int" "int" "int" "void *" "socklen_t *" */ +#define SYS_getsockopt 118 + +/* syscall: "thrkill" ret: "int" args: "pid_t" "int" "void *" */ +#define SYS_thrkill 119 + +/* syscall: "readv" ret: "ssize_t" args: "int" "const struct iovec *" "int" */ +#define SYS_readv 120 + +/* syscall: "writev" ret: "ssize_t" args: "int" "const struct iovec *" "int" */ +#define SYS_writev 121 + +/* syscall: "kill" ret: "int" args: "int" "int" */ +#define SYS_kill 122 + +/* syscall: "fchown" ret: "int" args: "int" "uid_t" "gid_t" */ +#define SYS_fchown 123 + +/* syscall: "fchmod" ret: "int" args: "int" "mode_t" */ +#define SYS_fchmod 124 + + /* 125 is obsolete orecvfrom */ +/* syscall: "setreuid" ret: "int" args: "uid_t" "uid_t" */ +#define SYS_setreuid 126 + +/* syscall: "setregid" ret: "int" args: "gid_t" "gid_t" */ +#define SYS_setregid 127 + +/* syscall: "rename" ret: "int" args: "const char *" "const char *" */ +#define SYS_rename 128 + + /* 129 is obsolete otruncate */ + /* 130 is obsolete oftruncate */ +/* syscall: "flock" ret: "int" args: "int" "int" */ +#define SYS_flock 131 + +/* syscall: "mkfifo" ret: "int" args: "const char *" "mode_t" */ +#define SYS_mkfifo 132 + +/* syscall: "sendto" ret: "ssize_t" args: "int" "const void *" "size_t" "int" "const struct sockaddr *" "socklen_t" */ +#define SYS_sendto 133 + +/* syscall: "shutdown" ret: "int" args: "int" "int" */ +#define SYS_shutdown 134 + +/* syscall: "socketpair" ret: "int" args: "int" "int" "int" "int *" */ +#define SYS_socketpair 135 + +/* syscall: "mkdir" ret: "int" args: "const char *" "mode_t" */ +#define SYS_mkdir 136 + +/* syscall: "rmdir" ret: "int" args: "const char *" */ +#define SYS_rmdir 137 + + /* 138 is obsolete t32_utimes */ + /* 139 is obsolete 4.2 sigreturn */ +/* syscall: "adjtime" ret: "int" args: "const struct timeval *" "struct timeval *" */ +#define SYS_adjtime 140 + +/* syscall: "getlogin_r" ret: "int" args: "char *" "size_t" */ +#define SYS_getlogin_r 141 + +/* syscall: "getthrname" ret: "int" args: "pid_t" "char *" "size_t" */ +#define SYS_getthrname 142 + +/* syscall: "setthrname" ret: "int" args: "pid_t" "const char *" */ +#define SYS_setthrname 143 + + /* 144 is obsolete ogetrlimit */ + /* 145 is obsolete osetrlimit */ + /* 146 is obsolete pinsyscall */ +/* syscall: "setsid" ret: "int" args: */ +#define SYS_setsid 147 + +/* syscall: "quotactl" ret: "int" args: "const char *" "int" "int" "char *" */ +#define SYS_quotactl 148 + + /* 149 is obsolete oquota */ +/* syscall: "ypconnect" ret: "int" args: "int" */ +#define SYS_ypconnect 150 + +/* syscall: "nfssvc" ret: "int" args: "int" "void *" */ +#define SYS_nfssvc 155 + + /* 156 is obsolete ogetdirentries */ + /* 157 is obsolete statfs25 */ +/* syscall: "pinsyscalls" ret: "int" args: "void *" "size_t" "u_int *" "int" */ +#define SYS_pinsyscalls 158 + +/* syscall: "mimmutable" ret: "int" args: "void *" "size_t" */ +#define SYS_mimmutable 159 + +/* syscall: "waitid" ret: "int" args: "int" "id_t" "siginfo_t *" "int" */ +#define SYS_waitid 160 + +/* syscall: "getfh" ret: "int" args: "const char *" "fhandle_t *" */ +#define SYS_getfh 161 + + /* 162 is obsolete ogetdomainname */ + /* 163 is obsolete osetdomainname */ +/* syscall: "__tmpfd" ret: "int" args: "int" */ +#define SYS___tmpfd 164 + +/* syscall: "sysarch" ret: "int" args: "int" "void *" */ +#define SYS_sysarch 165 + +/* syscall: "lseek" ret: "off_t" args: "int" "off_t" "int" */ +#define SYS_lseek 166 + +/* syscall: "truncate" ret: "int" args: "const char *" "off_t" */ +#define SYS_truncate 167 + +/* syscall: "ftruncate" ret: "int" args: "int" "off_t" */ +#define SYS_ftruncate 168 + +/* syscall: "pread" ret: "ssize_t" args: "int" "void *" "size_t" "off_t" */ +#define SYS_pread 169 + +/* syscall: "pwrite" ret: "ssize_t" args: "int" "const void *" "size_t" "off_t" */ +#define SYS_pwrite 170 + +/* syscall: "preadv" ret: "ssize_t" args: "int" "const struct iovec *" "int" "off_t" */ +#define SYS_preadv 171 + +/* syscall: "pwritev" ret: "ssize_t" args: "int" "const struct iovec *" "int" "off_t" */ +#define SYS_pwritev 172 + + /* 173 is obsolete pad_pread */ + /* 174 is obsolete pad_pwrite */ +/* syscall: "profil" ret: "int" args: "void *" "size_t" "size_t" "u_long" "u_int" "int" */ +#define SYS_profil 175 + +/* syscall: "setgid" ret: "int" args: "gid_t" */ +#define SYS_setgid 181 + +/* syscall: "setegid" ret: "int" args: "gid_t" */ +#define SYS_setegid 182 + +/* syscall: "seteuid" ret: "int" args: "uid_t" */ +#define SYS_seteuid 183 + + /* 184 is obsolete lfs_bmapv */ + /* 185 is obsolete lfs_markv */ + /* 186 is obsolete lfs_segclean */ + /* 187 is obsolete lfs_segwait */ + /* 188 is obsolete stat35 */ + /* 189 is obsolete fstat35 */ +/* syscall: "pathconfat" ret: "long" args: "int" "const char *" "int" "int" */ +#define SYS_pathconfat 190 + +/* syscall: "pathconf" ret: "long" args: "const char *" "int" */ +#define SYS_pathconf 191 + +/* syscall: "fpathconf" ret: "long" args: "int" "int" */ +#define SYS_fpathconf 192 + +/* syscall: "swapctl" ret: "int" args: "int" "const void *" "int" */ +#define SYS_swapctl 193 + +/* syscall: "getrlimit" ret: "int" args: "int" "struct rlimit *" */ +#define SYS_getrlimit 194 + +/* syscall: "setrlimit" ret: "int" args: "int" "const struct rlimit *" */ +#define SYS_setrlimit 195 + + /* 196 is obsolete ogetdirentries48 */ + /* 197 is obsolete pad_mmap */ + /* 198 is obsolete __syscall */ + /* 199 is obsolete pad_lseek */ + /* 200 is obsolete pad_truncate */ + /* 201 is obsolete pad_ftruncate */ +/* syscall: "sysctl" ret: "int" args: "const int *" "u_int" "void *" "size_t *" "void *" "size_t" */ +#define SYS_sysctl 202 + +/* syscall: "mlock" ret: "int" args: "const void *" "size_t" */ +#define SYS_mlock 203 + +/* syscall: "munlock" ret: "int" args: "const void *" "size_t" */ +#define SYS_munlock 204 + + /* 206 is obsolete t32_futimes */ +/* syscall: "getpgid" ret: "pid_t" args: "pid_t" */ +#define SYS_getpgid 207 + + /* 208 is obsolete nnpfspioctl */ +/* syscall: "utrace" ret: "int" args: "const char *" "const void *" "size_t" */ +#define SYS_utrace 209 + +/* syscall: "semget" ret: "int" args: "key_t" "int" "int" */ +#define SYS_semget 221 + + /* 222 is obsolete semop35 */ + /* 223 is obsolete semconfig35 */ +/* syscall: "msgget" ret: "int" args: "key_t" "int" */ +#define SYS_msgget 225 + +/* syscall: "msgsnd" ret: "int" args: "int" "const void *" "size_t" "int" */ +#define SYS_msgsnd 226 + +/* syscall: "msgrcv" ret: "int" args: "int" "void *" "size_t" "long" "int" */ +#define SYS_msgrcv 227 + +/* syscall: "shmat" ret: "void *" args: "int" "const void *" "int" */ +#define SYS_shmat 228 + +/* syscall: "shmdt" ret: "int" args: "const void *" */ +#define SYS_shmdt 230 + + /* 231 is obsolete shmget35 */ + /* 232 is obsolete t32_clock_gettime */ + /* 233 is obsolete t32_clock_settime */ + /* 234 is obsolete t32_clock_getres */ + /* 240 is obsolete t32_nanosleep */ +/* syscall: "minherit" ret: "int" args: "void *" "size_t" "int" */ +#define SYS_minherit 250 + + /* 251 is obsolete rfork */ +/* syscall: "poll" ret: "int" args: "struct pollfd *" "u_int" "int" */ +#define SYS_poll 252 + +/* syscall: "issetugid" ret: "int" args: */ +#define SYS_issetugid 253 + +/* syscall: "lchown" ret: "int" args: "const char *" "uid_t" "gid_t" */ +#define SYS_lchown 254 + +/* syscall: "getsid" ret: "pid_t" args: "pid_t" */ +#define SYS_getsid 255 + +/* syscall: "msync" ret: "int" args: "void *" "size_t" "int" */ +#define SYS_msync 256 + + /* 257 is obsolete semctl35 */ + /* 258 is obsolete shmctl35 */ + /* 259 is obsolete msgctl35 */ +/* syscall: "pipe" ret: "int" args: "int *" */ +#define SYS_pipe 263 + +/* syscall: "fhopen" ret: "int" args: "const fhandle_t *" "int" */ +#define SYS_fhopen 264 + + /* 267 is obsolete pad_preadv */ + /* 268 is obsolete pad_pwritev */ +/* syscall: "kqueue" ret: "int" args: */ +#define SYS_kqueue 269 + +/* syscall: "kqueue1" ret: "int" args: "int" */ +#define SYS_kqueue1 270 + +/* syscall: "mlockall" ret: "int" args: "int" */ +#define SYS_mlockall 271 + +/* syscall: "munlockall" ret: "int" args: */ +#define SYS_munlockall 272 + +/* syscall: "getresuid" ret: "int" args: "uid_t *" "uid_t *" "uid_t *" */ +#define SYS_getresuid 281 + +/* syscall: "setresuid" ret: "int" args: "uid_t" "uid_t" "uid_t" */ +#define SYS_setresuid 282 + +/* syscall: "getresgid" ret: "int" args: "gid_t *" "gid_t *" "gid_t *" */ +#define SYS_getresgid 283 + +/* syscall: "setresgid" ret: "int" args: "gid_t" "gid_t" "gid_t" */ +#define SYS_setresgid 284 + + /* 285 is obsolete sys_omquery */ + /* 286 is obsolete pad_mquery */ +/* syscall: "closefrom" ret: "int" args: "int" */ +#define SYS_closefrom 287 + +/* syscall: "sigaltstack" ret: "int" args: "const struct sigaltstack *" "struct sigaltstack *" */ +#define SYS_sigaltstack 288 + +/* syscall: "shmget" ret: "int" args: "key_t" "size_t" "int" */ +#define SYS_shmget 289 + +/* syscall: "semop" ret: "int" args: "int" "struct sembuf *" "size_t" */ +#define SYS_semop 290 + + /* 291 is obsolete t32_stat */ + /* 292 is obsolete t32_fstat */ + /* 293 is obsolete t32_lstat */ +/* syscall: "fhstat" ret: "int" args: "const fhandle_t *" "struct stat *" */ +#define SYS_fhstat 294 + +/* syscall: "__semctl" ret: "int" args: "int" "int" "int" "union semun *" */ +#define SYS___semctl 295 + +/* syscall: "shmctl" ret: "int" args: "int" "int" "struct shmid_ds *" */ +#define SYS_shmctl 296 + +/* syscall: "msgctl" ret: "int" args: "int" "int" "struct msqid_ds *" */ +#define SYS_msgctl 297 + +/* syscall: "sched_yield" ret: "int" args: */ +#define SYS_sched_yield 298 + +/* syscall: "getthrid" ret: "pid_t" args: */ +#define SYS_getthrid 299 + + /* 300 is obsolete t32___thrsleep */ +/* syscall: "__thrwakeup" ret: "int" args: "const volatile void *" "int" */ +#define SYS___thrwakeup 301 + +/* syscall: "__threxit" ret: "void" args: "pid_t *" */ +#define SYS___threxit 302 + +/* syscall: "__thrsigdivert" ret: "int" args: "sigset_t" "siginfo_t *" "const struct timespec *" */ +#define SYS___thrsigdivert 303 + +/* syscall: "__getcwd" ret: "int" args: "char *" "size_t" */ +#define SYS___getcwd 304 + +/* syscall: "adjfreq" ret: "int" args: "const int64_t *" "int64_t *" */ +#define SYS_adjfreq 305 + + /* 306 is obsolete getfsstat53 */ + /* 307 is obsolete statfs53 */ + /* 308 is obsolete fstatfs53 */ + /* 309 is obsolete fhstatfs53 */ +/* syscall: "setrtable" ret: "int" args: "int" */ +#define SYS_setrtable 310 + +/* syscall: "getrtable" ret: "int" args: */ +#define SYS_getrtable 311 + + /* 312 is obsolete t32_getdirentries */ +/* syscall: "faccessat" ret: "int" args: "int" "const char *" "int" "int" */ +#define SYS_faccessat 313 + +/* syscall: "fchmodat" ret: "int" args: "int" "const char *" "mode_t" "int" */ +#define SYS_fchmodat 314 + +/* syscall: "fchownat" ret: "int" args: "int" "const char *" "uid_t" "gid_t" "int" */ +#define SYS_fchownat 315 + + /* 316 is obsolete t32_fstatat */ +/* syscall: "linkat" ret: "int" args: "int" "const char *" "int" "const char *" "int" */ +#define SYS_linkat 317 + +/* syscall: "mkdirat" ret: "int" args: "int" "const char *" "mode_t" */ +#define SYS_mkdirat 318 + +/* syscall: "mkfifoat" ret: "int" args: "int" "const char *" "mode_t" */ +#define SYS_mkfifoat 319 + +/* syscall: "mknodat" ret: "int" args: "int" "const char *" "mode_t" "dev_t" */ +#define SYS_mknodat 320 + +/* syscall: "openat" ret: "int" args: "int" "const char *" "int" "..." "mode_t" */ +#define SYS_openat 321 + +/* syscall: "readlinkat" ret: "ssize_t" args: "int" "const char *" "char *" "size_t" */ +#define SYS_readlinkat 322 + +/* syscall: "renameat" ret: "int" args: "int" "const char *" "int" "const char *" */ +#define SYS_renameat 323 + +/* syscall: "symlinkat" ret: "int" args: "const char *" "int" "const char *" */ +#define SYS_symlinkat 324 + +/* syscall: "unlinkat" ret: "int" args: "int" "const char *" "int" */ +#define SYS_unlinkat 325 + + /* 326 is obsolete t32_utimensat */ + /* 327 is obsolete t32_futimens */ + /* 328 is obsolete __tfork51 */ +/* syscall: "__set_tcb" ret: "void" args: "void *" */ +#define SYS___set_tcb 329 + +/* syscall: "__get_tcb" ret: "void *" args: */ +#define SYS___get_tcb 330 + +#define SYS_MAXSYSCALL 331 \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/syscall_mi.h b/lib/libc/include/generic-openbsd/sys/syscall_mi.h new file mode 100644 index 0000000000..f633a55fe6 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/syscall_mi.h @@ -0,0 +1,259 @@ +/* $OpenBSD: syscall_mi.h,v 1.37 2024/12/27 11:57:16 mpi Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)kern_xxx.c 8.2 (Berkeley) 11/14/93 + */ + +#include +#include +#include +#include +#include +#include +#include + +#ifdef KTRACE +#include +#endif + +#include "dt.h" +#if NDT > 0 +#include +#endif + +/* + * Check if a system call is entered from precisely correct location + */ +static inline int +pin_check(struct proc *p, register_t code) +{ + extern char sigcodecall[], sigcoderet[], sigcodecall[]; + struct pinsyscall *pin = NULL, *ppin, *plibcpin; + struct process *pr = p->p_p; + vaddr_t addr; + int error = 0; + + /* point at start of syscall instruction */ + addr = (vaddr_t)PROC_PC(p) - (vaddr_t)(sigcoderet - sigcodecall); + ppin = &pr->ps_pin; + plibcpin = &pr->ps_libcpin; + + /* + * System calls come from the following places, checks are ordered + * by most common case: + * 1) dynamic binary: syscalls in libc.so (in the ps_libcpin region) + * 2a) static binary: syscalls in main program (in the ps_pin region) + * 2b) dynamic binary: syscalls in ld.so (in the ps_pin region) + * 3) sigtramp, containing only sigreturn(2) + */ + if (plibcpin->pn_pins && + addr >= plibcpin->pn_start && addr < plibcpin->pn_end) + pin = plibcpin; + else if (ppin->pn_pins && + addr >= ppin->pn_start && addr < ppin->pn_end) + pin = ppin; + else if (PROC_PC(p) == pr->ps_sigcoderet) { + if (code == SYS_sigreturn) + return (0); + error = EPERM; + goto die; + } + if (pin) { + if (code >= pin->pn_npins || pin->pn_pins[code] == 0) + error = ENOSYS; + else if (pin->pn_pins[code] + pin->pn_start == addr) + ; /* correct location */ + else if (pin->pn_pins[code] == (u_int)-1) + ; /* multiple locations, hopefully a boring operation */ + else + error = ENOSYS; + } else + error = ENOSYS; + if (error == 0) + return (0); +die: +#ifdef KTRACE + if (KTRPOINT(p, KTR_PINSYSCALL)) + ktrpinsyscall(p, error, code, addr); +#endif + KERNEL_LOCK(); + /* XXX remove or simplify this uprintf() call after OpenBSD 7.5 release */ + uprintf("%s[%d]: pinsyscalls addr %lx code %ld, pinoff 0x%x " + "(pin%s %d %lx-%lx %lx) (libcpin%s %d %lx-%lx %lx) error %d\n", + p->p_p->ps_comm, p->p_p->ps_pid, addr, code, + (pin && code < pin->pn_npins) ? pin->pn_pins[code] : -1, + pin == ppin ? "(Y)" : "", ppin->pn_npins, + ppin->pn_start, ppin->pn_end, ppin->pn_end - ppin->pn_start, + pin == plibcpin ? "(Y)" : "", plibcpin->pn_npins, + plibcpin->pn_start, plibcpin->pn_end, plibcpin->pn_end - plibcpin->pn_start, + error); + p->p_p->ps_acflag |= APINSYS; + + /* Try to stop threads immediately, because this process is suspect */ + if (P_HASSIBLING(p)) + single_thread_set(p, SINGLE_UNWIND | SINGLE_DEEP); + /* Send uncatchable SIGABRT for coredump */ + sigabort(p); + KERNEL_UNLOCK(); + return (error); +} + +/* + * The MD setup for a system call has been done; here's the MI part. + */ +static inline int +mi_syscall(struct proc *p, register_t code, const struct sysent *callp, + register_t *argp, register_t retval[2]) +{ + uint64_t tval; + int lock = !(callp->sy_flags & SY_NOLOCK); + int error, pledged; + + /* refresh the thread's cache of the process's creds */ + refreshcreds(p); + +#ifdef SYSCALL_DEBUG + KERNEL_LOCK(); + scdebug_call(p, code, argp); + KERNEL_UNLOCK(); +#endif + TRACEPOINT(raw_syscalls, sys_enter, code, NULL); +#if NDT > 0 + DT_ENTER(syscall, code, callp->sy_argsize, argp); +#endif +#ifdef KTRACE + if (KTRPOINT(p, KTR_SYSCALL)) { + /* convert to mask, then include with code */ + ktrsyscall(p, code, callp->sy_argsize, argp); + } +#endif + + /* SP must be within MAP_STACK space */ + if (!uvm_map_inentry(p, &p->p_spinentry, PROC_STACK(p), + "[%s]%d/%d sp=%lx inside %lx-%lx: not MAP_STACK\n", + uvm_map_inentry_sp, p->p_vmspace->vm_map.sserial)) + return (EPERM); + + if ((error = pin_check(p, code))) + return (error); + + pledged = (p->p_p->ps_flags & PS_PLEDGE); + if (pledged && (error = pledge_syscall(p, code, &tval))) { + KERNEL_LOCK(); + error = pledge_fail(p, error, tval); + KERNEL_UNLOCK(); + return (error); + } + if (lock) + KERNEL_LOCK(); + error = (*callp->sy_call)(p, argp, retval); + if (lock) + KERNEL_UNLOCK(); + + return (error); +} + +/* + * Finish MI stuff on return, after the registers have been set + */ +static inline void +mi_syscall_return(struct proc *p, register_t code, int error, + const register_t retval[2]) +{ +#ifdef SYSCALL_DEBUG + KERNEL_LOCK(); + scdebug_ret(p, code, error, retval); + KERNEL_UNLOCK(); +#endif +#if NDT > 0 + DT_LEAVE(syscall, code, error, retval[0], retval[1]); +#endif + TRACEPOINT(raw_syscalls, sys_exit, code, NULL); + + userret(p); + +#ifdef KTRACE + if (KTRPOINT(p, KTR_SYSRET)) + ktrsysret(p, code, error, retval); +#endif +} + +/* + * Finish MI stuff for a new process/thread to return + */ +static inline void +mi_child_return(struct proc *p) +{ +#if defined(SYSCALL_DEBUG) || defined(KTRACE) || NDT > 0 + int code = (p->p_flag & P_THREAD) ? SYS___tfork : + (p->p_p->ps_flags & PS_PPWAIT) ? SYS_vfork : SYS_fork; + const register_t child_retval[2] = { 0, 1 }; +#endif + + TRACEPOINT(sched, on__cpu, NULL); + +#ifdef SYSCALL_DEBUG + KERNEL_LOCK(); + scdebug_ret(p, code, 0, child_retval); + KERNEL_UNLOCK(); +#endif +#if NDT > 0 + DT_LEAVE(syscall, code, 0, child_retval[0], child_retval[1]); +#endif + TRACEPOINT(raw_syscalls, sys_exit, code, NULL); + + userret(p); + +#ifdef KTRACE + if (KTRPOINT(p, KTR_SYSRET)) + ktrsysret(p, code, 0, child_retval); +#endif +} + +/* + * Do the specific processing necessary for an AST + */ +static inline void +mi_ast(struct proc *p, int resched) +{ + if (p->p_flag & P_OWEUPC) { + KERNEL_LOCK(); + ADDUPROF(p); + KERNEL_UNLOCK(); + } + if (resched) + preempt(); + + /* + * XXX could move call to userret() here, but + * hppa calls ast() in syscall return and sh calls + * it after userret() + */ +} \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/syscallargs.h b/lib/libc/include/generic-openbsd/sys/syscallargs.h new file mode 100644 index 0000000000..62f9a6d1e3 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/syscallargs.h @@ -0,0 +1,1419 @@ +/* $OpenBSD: syscallargs.h,v 1.286 2025/05/24 06:50:02 deraadt Exp $ */ + +/* + * System call argument lists. + * + * DO NOT EDIT-- this file is automatically generated. + * created from; OpenBSD: syscalls.master,v 1.270 2025/05/24 06:49:16 deraadt Exp + */ + +#ifdef syscallarg +#undef syscallarg +#endif + +#define syscallarg(x) \ + union { \ + register_t pad; \ + struct { x datum; } le; \ + struct { \ + int8_t pad[ (sizeof (register_t) < sizeof (x)) \ + ? 0 \ + : sizeof (register_t) - sizeof (x)]; \ + x datum; \ + } be; \ + } + +struct sys_exit_args { + syscallarg(int) rval; +}; + +struct sys_read_args { + syscallarg(int) fd; + syscallarg(void *) buf; + syscallarg(size_t) nbyte; +}; + +struct sys_write_args { + syscallarg(int) fd; + syscallarg(const void *) buf; + syscallarg(size_t) nbyte; +}; + +struct sys_open_args { + syscallarg(const char *) path; + syscallarg(int) flags; + syscallarg(mode_t) mode; +}; + +struct sys_close_args { + syscallarg(int) fd; +}; + +struct sys_getentropy_args { + syscallarg(void *) buf; + syscallarg(size_t) nbyte; +}; + +struct sys___tfork_args { + syscallarg(const struct __tfork *) param; + syscallarg(size_t) psize; +}; + +struct sys_link_args { + syscallarg(const char *) path; + syscallarg(const char *) link; +}; + +struct sys_unlink_args { + syscallarg(const char *) path; +}; + +struct sys_wait4_args { + syscallarg(pid_t) pid; + syscallarg(int *) status; + syscallarg(int) options; + syscallarg(struct rusage *) rusage; +}; + +struct sys_chdir_args { + syscallarg(const char *) path; +}; + +struct sys_fchdir_args { + syscallarg(int) fd; +}; + +struct sys_mknod_args { + syscallarg(const char *) path; + syscallarg(mode_t) mode; + syscallarg(dev_t) dev; +}; + +struct sys_chmod_args { + syscallarg(const char *) path; + syscallarg(mode_t) mode; +}; + +struct sys_chown_args { + syscallarg(const char *) path; + syscallarg(uid_t) uid; + syscallarg(gid_t) gid; +}; + +struct sys_obreak_args { + syscallarg(char *) nsize; +}; + +struct sys_getrusage_args { + syscallarg(int) who; + syscallarg(struct rusage *) rusage; +}; + +struct sys_mount_args { + syscallarg(const char *) type; + syscallarg(const char *) path; + syscallarg(int) flags; + syscallarg(void *) data; +}; + +struct sys_unmount_args { + syscallarg(const char *) path; + syscallarg(int) flags; +}; + +struct sys_setuid_args { + syscallarg(uid_t) uid; +}; + +struct sys_ptrace_args { + syscallarg(int) req; + syscallarg(pid_t) pid; + syscallarg(caddr_t) addr; + syscallarg(int) data; +}; + +struct sys_recvmsg_args { + syscallarg(int) s; + syscallarg(struct msghdr *) msg; + syscallarg(int) flags; +}; + +struct sys_sendmsg_args { + syscallarg(int) s; + syscallarg(const struct msghdr *) msg; + syscallarg(int) flags; +}; + +struct sys_recvfrom_args { + syscallarg(int) s; + syscallarg(void *) buf; + syscallarg(size_t) len; + syscallarg(int) flags; + syscallarg(struct sockaddr *) from; + syscallarg(socklen_t *) fromlenaddr; +}; + +struct sys_accept_args { + syscallarg(int) s; + syscallarg(struct sockaddr *) name; + syscallarg(socklen_t *) anamelen; +}; + +struct sys_getpeername_args { + syscallarg(int) fdes; + syscallarg(struct sockaddr *) asa; + syscallarg(socklen_t *) alen; +}; + +struct sys_getsockname_args { + syscallarg(int) fdes; + syscallarg(struct sockaddr *) asa; + syscallarg(socklen_t *) alen; +}; + +struct sys_access_args { + syscallarg(const char *) path; + syscallarg(int) amode; +}; + +struct sys_chflags_args { + syscallarg(const char *) path; + syscallarg(u_int) flags; +}; + +struct sys_fchflags_args { + syscallarg(int) fd; + syscallarg(u_int) flags; +}; + +struct sys_stat_args { + syscallarg(const char *) path; + syscallarg(struct stat *) ub; +}; + +struct sys_lstat_args { + syscallarg(const char *) path; + syscallarg(struct stat *) ub; +}; + +struct sys_dup_args { + syscallarg(int) fd; +}; + +struct sys_fstatat_args { + syscallarg(int) fd; + syscallarg(const char *) path; + syscallarg(struct stat *) buf; + syscallarg(int) flag; +}; + +struct sys_ktrace_args { + syscallarg(const char *) fname; + syscallarg(int) ops; + syscallarg(int) facs; + syscallarg(pid_t) pid; +}; + +struct sys_sigaction_args { + syscallarg(int) signum; + syscallarg(const struct sigaction *) nsa; + syscallarg(struct sigaction *) osa; +}; + +struct sys_sigprocmask_args { + syscallarg(int) how; + syscallarg(sigset_t) mask; +}; + +struct sys_mmap_args { + syscallarg(void *) addr; + syscallarg(size_t) len; + syscallarg(int) prot; + syscallarg(int) flags; + syscallarg(int) fd; + syscallarg(off_t) pos; +}; + +struct sys_setlogin_args { + syscallarg(const char *) namebuf; +}; + +struct sys_acct_args { + syscallarg(const char *) path; +}; + +struct sys_fstat_args { + syscallarg(int) fd; + syscallarg(struct stat *) sb; +}; + +struct sys_ioctl_args { + syscallarg(int) fd; + syscallarg(u_long) com; + syscallarg(void *) data; +}; + +struct sys_reboot_args { + syscallarg(int) opt; +}; + +struct sys_revoke_args { + syscallarg(const char *) path; +}; + +struct sys_symlink_args { + syscallarg(const char *) path; + syscallarg(const char *) link; +}; + +struct sys_readlink_args { + syscallarg(const char *) path; + syscallarg(char *) buf; + syscallarg(size_t) count; +}; + +struct sys_execve_args { + syscallarg(const char *) path; + syscallarg(char *const *) argp; + syscallarg(char *const *) envp; +}; + +struct sys_umask_args { + syscallarg(mode_t) newmask; +}; + +struct sys_chroot_args { + syscallarg(const char *) path; +}; + +struct sys_getfsstat_args { + syscallarg(struct statfs *) buf; + syscallarg(size_t) bufsize; + syscallarg(int) flags; +}; + +struct sys_statfs_args { + syscallarg(const char *) path; + syscallarg(struct statfs *) buf; +}; + +struct sys_fstatfs_args { + syscallarg(int) fd; + syscallarg(struct statfs *) buf; +}; + +struct sys_fhstatfs_args { + syscallarg(const fhandle_t *) fhp; + syscallarg(struct statfs *) buf; +}; + +struct sys_gettimeofday_args { + syscallarg(struct timeval *) tp; + syscallarg(struct timezone *) tzp; +}; + +struct sys_settimeofday_args { + syscallarg(const struct timeval *) tv; + syscallarg(const struct timezone *) tzp; +}; + +struct sys_setitimer_args { + syscallarg(int) which; + syscallarg(const struct itimerval *) itv; + syscallarg(struct itimerval *) oitv; +}; + +struct sys_getitimer_args { + syscallarg(int) which; + syscallarg(struct itimerval *) itv; +}; + +struct sys_select_args { + syscallarg(int) nd; + syscallarg(fd_set *) in; + syscallarg(fd_set *) ou; + syscallarg(fd_set *) ex; + syscallarg(struct timeval *) tv; +}; + +struct sys_kevent_args { + syscallarg(int) fd; + syscallarg(const struct kevent *) changelist; + syscallarg(int) nchanges; + syscallarg(struct kevent *) eventlist; + syscallarg(int) nevents; + syscallarg(const struct timespec *) timeout; +}; + +struct sys_munmap_args { + syscallarg(void *) addr; + syscallarg(size_t) len; +}; + +struct sys_mprotect_args { + syscallarg(void *) addr; + syscallarg(size_t) len; + syscallarg(int) prot; +}; + +struct sys_madvise_args { + syscallarg(void *) addr; + syscallarg(size_t) len; + syscallarg(int) behav; +}; + +struct sys_utimes_args { + syscallarg(const char *) path; + syscallarg(const struct timeval *) tptr; +}; + +struct sys_futimes_args { + syscallarg(int) fd; + syscallarg(const struct timeval *) tptr; +}; + +struct sys_mquery_args { + syscallarg(void *) addr; + syscallarg(size_t) len; + syscallarg(int) prot; + syscallarg(int) flags; + syscallarg(int) fd; + syscallarg(off_t) pos; +}; + +struct sys_getgroups_args { + syscallarg(int) gidsetsize; + syscallarg(gid_t *) gidset; +}; + +struct sys_setgroups_args { + syscallarg(int) gidsetsize; + syscallarg(const gid_t *) gidset; +}; + +struct sys_setpgid_args { + syscallarg(pid_t) pid; + syscallarg(pid_t) pgid; +}; + +struct sys_futex_args { + syscallarg(uint32_t *) f; + syscallarg(int) op; + syscallarg(int) val; + syscallarg(const struct timespec *) timeout; + syscallarg(uint32_t *) g; +}; + +struct sys_utimensat_args { + syscallarg(int) fd; + syscallarg(const char *) path; + syscallarg(const struct timespec *) times; + syscallarg(int) flag; +}; + +struct sys_futimens_args { + syscallarg(int) fd; + syscallarg(const struct timespec *) times; +}; + +struct sys_kbind_args { + syscallarg(const struct __kbind *) param; + syscallarg(size_t) psize; + syscallarg(int64_t) proc_cookie; +}; + +struct sys_clock_gettime_args { + syscallarg(clockid_t) clock_id; + syscallarg(struct timespec *) tp; +}; + +struct sys_clock_settime_args { + syscallarg(clockid_t) clock_id; + syscallarg(const struct timespec *) tp; +}; + +struct sys_clock_getres_args { + syscallarg(clockid_t) clock_id; + syscallarg(struct timespec *) tp; +}; + +struct sys_dup2_args { + syscallarg(int) from; + syscallarg(int) to; +}; + +struct sys_nanosleep_args { + syscallarg(const struct timespec *) rqtp; + syscallarg(struct timespec *) rmtp; +}; + +struct sys_fcntl_args { + syscallarg(int) fd; + syscallarg(int) cmd; + syscallarg(void *) arg; +}; + +struct sys_accept4_args { + syscallarg(int) s; + syscallarg(struct sockaddr *) name; + syscallarg(socklen_t *) anamelen; + syscallarg(int) flags; +}; + +struct sys___thrsleep_args { + syscallarg(const volatile void *) ident; + syscallarg(clockid_t) clock_id; + syscallarg(const struct timespec *) tp; + syscallarg(void *) lock; + syscallarg(const int *) abort; +}; + +struct sys_fsync_args { + syscallarg(int) fd; +}; + +struct sys_setpriority_args { + syscallarg(int) which; + syscallarg(id_t) who; + syscallarg(int) prio; +}; + +struct sys_socket_args { + syscallarg(int) domain; + syscallarg(int) type; + syscallarg(int) protocol; +}; + +struct sys_connect_args { + syscallarg(int) s; + syscallarg(const struct sockaddr *) name; + syscallarg(socklen_t) namelen; +}; + +struct sys_getdents_args { + syscallarg(int) fd; + syscallarg(void *) buf; + syscallarg(size_t) buflen; +}; + +struct sys_getpriority_args { + syscallarg(int) which; + syscallarg(id_t) who; +}; + +struct sys_pipe2_args { + syscallarg(int *) fdp; + syscallarg(int) flags; +}; + +struct sys_dup3_args { + syscallarg(int) from; + syscallarg(int) to; + syscallarg(int) flags; +}; + +struct sys_sigreturn_args { + syscallarg(struct sigcontext *) sigcntxp; +}; + +struct sys_bind_args { + syscallarg(int) s; + syscallarg(const struct sockaddr *) name; + syscallarg(socklen_t) namelen; +}; + +struct sys_setsockopt_args { + syscallarg(int) s; + syscallarg(int) level; + syscallarg(int) name; + syscallarg(const void *) val; + syscallarg(socklen_t) valsize; +}; + +struct sys_listen_args { + syscallarg(int) s; + syscallarg(int) backlog; +}; + +struct sys_chflagsat_args { + syscallarg(int) fd; + syscallarg(const char *) path; + syscallarg(u_int) flags; + syscallarg(int) atflags; +}; + +struct sys_pledge_args { + syscallarg(const char *) promises; + syscallarg(const char *) execpromises; +}; + +struct sys_ppoll_args { + syscallarg(struct pollfd *) fds; + syscallarg(u_int) nfds; + syscallarg(const struct timespec *) ts; + syscallarg(const sigset_t *) mask; +}; + +struct sys_pselect_args { + syscallarg(int) nd; + syscallarg(fd_set *) in; + syscallarg(fd_set *) ou; + syscallarg(fd_set *) ex; + syscallarg(const struct timespec *) ts; + syscallarg(const sigset_t *) mask; +}; + +struct sys_sigsuspend_args { + syscallarg(int) mask; +}; + +struct sys_sendsyslog_args { + syscallarg(const char *) buf; + syscallarg(size_t) nbyte; + syscallarg(int) flags; +}; + +struct sys_unveil_args { + syscallarg(const char *) path; + syscallarg(const char *) permissions; +}; + +struct sys___realpath_args { + syscallarg(const char *) pathname; + syscallarg(char *) resolved; +}; + +struct sys_recvmmsg_args { + syscallarg(int) s; + syscallarg(struct mmsghdr *) mmsg; + syscallarg(unsigned int) vlen; + syscallarg(int) flags; + syscallarg(struct timespec *) timeout; +}; + +struct sys_sendmmsg_args { + syscallarg(int) s; + syscallarg(struct mmsghdr *) mmsg; + syscallarg(unsigned int) vlen; + syscallarg(int) flags; +}; + +struct sys_getsockopt_args { + syscallarg(int) s; + syscallarg(int) level; + syscallarg(int) name; + syscallarg(void *) val; + syscallarg(socklen_t *) avalsize; +}; + +struct sys_thrkill_args { + syscallarg(pid_t) tid; + syscallarg(int) signum; + syscallarg(void *) tcb; +}; + +struct sys_readv_args { + syscallarg(int) fd; + syscallarg(const struct iovec *) iovp; + syscallarg(int) iovcnt; +}; + +struct sys_writev_args { + syscallarg(int) fd; + syscallarg(const struct iovec *) iovp; + syscallarg(int) iovcnt; +}; + +struct sys_kill_args { + syscallarg(int) pid; + syscallarg(int) signum; +}; + +struct sys_fchown_args { + syscallarg(int) fd; + syscallarg(uid_t) uid; + syscallarg(gid_t) gid; +}; + +struct sys_fchmod_args { + syscallarg(int) fd; + syscallarg(mode_t) mode; +}; + +struct sys_setreuid_args { + syscallarg(uid_t) ruid; + syscallarg(uid_t) euid; +}; + +struct sys_setregid_args { + syscallarg(gid_t) rgid; + syscallarg(gid_t) egid; +}; + +struct sys_rename_args { + syscallarg(const char *) from; + syscallarg(const char *) to; +}; + +struct sys_flock_args { + syscallarg(int) fd; + syscallarg(int) how; +}; + +struct sys_mkfifo_args { + syscallarg(const char *) path; + syscallarg(mode_t) mode; +}; + +struct sys_sendto_args { + syscallarg(int) s; + syscallarg(const void *) buf; + syscallarg(size_t) len; + syscallarg(int) flags; + syscallarg(const struct sockaddr *) to; + syscallarg(socklen_t) tolen; +}; + +struct sys_shutdown_args { + syscallarg(int) s; + syscallarg(int) how; +}; + +struct sys_socketpair_args { + syscallarg(int) domain; + syscallarg(int) type; + syscallarg(int) protocol; + syscallarg(int *) rsv; +}; + +struct sys_mkdir_args { + syscallarg(const char *) path; + syscallarg(mode_t) mode; +}; + +struct sys_rmdir_args { + syscallarg(const char *) path; +}; + +struct sys_adjtime_args { + syscallarg(const struct timeval *) delta; + syscallarg(struct timeval *) olddelta; +}; + +struct sys_getlogin_r_args { + syscallarg(char *) namebuf; + syscallarg(size_t) namelen; +}; + +struct sys_getthrname_args { + syscallarg(pid_t) tid; + syscallarg(char *) name; + syscallarg(size_t) len; +}; + +struct sys_setthrname_args { + syscallarg(pid_t) tid; + syscallarg(const char *) name; +}; + +struct sys_quotactl_args { + syscallarg(const char *) path; + syscallarg(int) cmd; + syscallarg(int) uid; + syscallarg(char *) arg; +}; + +struct sys_ypconnect_args { + syscallarg(int) type; +}; + +struct sys_nfssvc_args { + syscallarg(int) flag; + syscallarg(void *) argp; +}; + +struct sys_pinsyscalls_args { + syscallarg(void *) base; + syscallarg(size_t) len; + syscallarg(u_int *) pins; + syscallarg(int) npins; +}; + +struct sys_mimmutable_args { + syscallarg(void *) addr; + syscallarg(size_t) len; +}; + +struct sys_waitid_args { + syscallarg(int) idtype; + syscallarg(id_t) id; + syscallarg(siginfo_t *) info; + syscallarg(int) options; +}; + +struct sys_getfh_args { + syscallarg(const char *) fname; + syscallarg(fhandle_t *) fhp; +}; + +struct sys___tmpfd_args { + syscallarg(int) flags; +}; + +struct sys_sysarch_args { + syscallarg(int) op; + syscallarg(void *) parms; +}; + +struct sys_lseek_args { + syscallarg(int) fd; + syscallarg(off_t) offset; + syscallarg(int) whence; +}; + +struct sys_truncate_args { + syscallarg(const char *) path; + syscallarg(off_t) length; +}; + +struct sys_ftruncate_args { + syscallarg(int) fd; + syscallarg(off_t) length; +}; + +struct sys_pread_args { + syscallarg(int) fd; + syscallarg(void *) buf; + syscallarg(size_t) nbyte; + syscallarg(off_t) offset; +}; + +struct sys_pwrite_args { + syscallarg(int) fd; + syscallarg(const void *) buf; + syscallarg(size_t) nbyte; + syscallarg(off_t) offset; +}; + +struct sys_preadv_args { + syscallarg(int) fd; + syscallarg(const struct iovec *) iovp; + syscallarg(int) iovcnt; + syscallarg(off_t) offset; +}; + +struct sys_pwritev_args { + syscallarg(int) fd; + syscallarg(const struct iovec *) iovp; + syscallarg(int) iovcnt; + syscallarg(off_t) offset; +}; + +struct sys_profil_args { + syscallarg(void *) buf; + syscallarg(size_t) buflen; + syscallarg(size_t) samplesize; + syscallarg(u_long) offset; + syscallarg(u_int) scale; + syscallarg(int) dirfd; +}; + +struct sys_setgid_args { + syscallarg(gid_t) gid; +}; + +struct sys_setegid_args { + syscallarg(gid_t) egid; +}; + +struct sys_seteuid_args { + syscallarg(uid_t) euid; +}; + +struct sys_pathconfat_args { + syscallarg(int) fd; + syscallarg(const char *) path; + syscallarg(int) name; + syscallarg(int) flag; +}; + +struct sys_pathconf_args { + syscallarg(const char *) path; + syscallarg(int) name; +}; + +struct sys_fpathconf_args { + syscallarg(int) fd; + syscallarg(int) name; +}; + +struct sys_swapctl_args { + syscallarg(int) cmd; + syscallarg(const void *) arg; + syscallarg(int) misc; +}; + +struct sys_getrlimit_args { + syscallarg(int) which; + syscallarg(struct rlimit *) rlp; +}; + +struct sys_setrlimit_args { + syscallarg(int) which; + syscallarg(const struct rlimit *) rlp; +}; + +struct sys_sysctl_args { + syscallarg(const int *) name; + syscallarg(u_int) namelen; + syscallarg(void *) old; + syscallarg(size_t *) oldlenp; + syscallarg(void *) new; + syscallarg(size_t) newlen; +}; + +struct sys_mlock_args { + syscallarg(const void *) addr; + syscallarg(size_t) len; +}; + +struct sys_munlock_args { + syscallarg(const void *) addr; + syscallarg(size_t) len; +}; + +struct sys_getpgid_args { + syscallarg(pid_t) pid; +}; + +struct sys_utrace_args { + syscallarg(const char *) label; + syscallarg(const void *) addr; + syscallarg(size_t) len; +}; + +struct sys_semget_args { + syscallarg(key_t) key; + syscallarg(int) nsems; + syscallarg(int) semflg; +}; + +struct sys_msgget_args { + syscallarg(key_t) key; + syscallarg(int) msgflg; +}; + +struct sys_msgsnd_args { + syscallarg(int) msqid; + syscallarg(const void *) msgp; + syscallarg(size_t) msgsz; + syscallarg(int) msgflg; +}; + +struct sys_msgrcv_args { + syscallarg(int) msqid; + syscallarg(void *) msgp; + syscallarg(size_t) msgsz; + syscallarg(long) msgtyp; + syscallarg(int) msgflg; +}; + +struct sys_shmat_args { + syscallarg(int) shmid; + syscallarg(const void *) shmaddr; + syscallarg(int) shmflg; +}; + +struct sys_shmdt_args { + syscallarg(const void *) shmaddr; +}; + +struct sys_minherit_args { + syscallarg(void *) addr; + syscallarg(size_t) len; + syscallarg(int) inherit; +}; + +struct sys_poll_args { + syscallarg(struct pollfd *) fds; + syscallarg(u_int) nfds; + syscallarg(int) timeout; +}; + +struct sys_lchown_args { + syscallarg(const char *) path; + syscallarg(uid_t) uid; + syscallarg(gid_t) gid; +}; + +struct sys_getsid_args { + syscallarg(pid_t) pid; +}; + +struct sys_msync_args { + syscallarg(void *) addr; + syscallarg(size_t) len; + syscallarg(int) flags; +}; + +struct sys_pipe_args { + syscallarg(int *) fdp; +}; + +struct sys_fhopen_args { + syscallarg(const fhandle_t *) fhp; + syscallarg(int) flags; +}; + +struct sys_kqueue1_args { + syscallarg(int) flags; +}; + +struct sys_mlockall_args { + syscallarg(int) flags; +}; + +struct sys_getresuid_args { + syscallarg(uid_t *) ruid; + syscallarg(uid_t *) euid; + syscallarg(uid_t *) suid; +}; + +struct sys_setresuid_args { + syscallarg(uid_t) ruid; + syscallarg(uid_t) euid; + syscallarg(uid_t) suid; +}; + +struct sys_getresgid_args { + syscallarg(gid_t *) rgid; + syscallarg(gid_t *) egid; + syscallarg(gid_t *) sgid; +}; + +struct sys_setresgid_args { + syscallarg(gid_t) rgid; + syscallarg(gid_t) egid; + syscallarg(gid_t) sgid; +}; + +struct sys_closefrom_args { + syscallarg(int) fd; +}; + +struct sys_sigaltstack_args { + syscallarg(const struct sigaltstack *) nss; + syscallarg(struct sigaltstack *) oss; +}; + +struct sys_shmget_args { + syscallarg(key_t) key; + syscallarg(size_t) size; + syscallarg(int) shmflg; +}; + +struct sys_semop_args { + syscallarg(int) semid; + syscallarg(struct sembuf *) sops; + syscallarg(size_t) nsops; +}; + +struct sys_fhstat_args { + syscallarg(const fhandle_t *) fhp; + syscallarg(struct stat *) sb; +}; + +struct sys___semctl_args { + syscallarg(int) semid; + syscallarg(int) semnum; + syscallarg(int) cmd; + syscallarg(union semun *) arg; +}; + +struct sys_shmctl_args { + syscallarg(int) shmid; + syscallarg(int) cmd; + syscallarg(struct shmid_ds *) buf; +}; + +struct sys_msgctl_args { + syscallarg(int) msqid; + syscallarg(int) cmd; + syscallarg(struct msqid_ds *) buf; +}; + +struct sys___thrwakeup_args { + syscallarg(const volatile void *) ident; + syscallarg(int) n; +}; + +struct sys___threxit_args { + syscallarg(pid_t *) notdead; +}; + +struct sys___thrsigdivert_args { + syscallarg(sigset_t) sigmask; + syscallarg(siginfo_t *) info; + syscallarg(const struct timespec *) timeout; +}; + +struct sys___getcwd_args { + syscallarg(char *) buf; + syscallarg(size_t) len; +}; + +struct sys_adjfreq_args { + syscallarg(const int64_t *) freq; + syscallarg(int64_t *) oldfreq; +}; + +struct sys_setrtable_args { + syscallarg(int) rtableid; +}; + +struct sys_faccessat_args { + syscallarg(int) fd; + syscallarg(const char *) path; + syscallarg(int) amode; + syscallarg(int) flag; +}; + +struct sys_fchmodat_args { + syscallarg(int) fd; + syscallarg(const char *) path; + syscallarg(mode_t) mode; + syscallarg(int) flag; +}; + +struct sys_fchownat_args { + syscallarg(int) fd; + syscallarg(const char *) path; + syscallarg(uid_t) uid; + syscallarg(gid_t) gid; + syscallarg(int) flag; +}; + +struct sys_linkat_args { + syscallarg(int) fd1; + syscallarg(const char *) path1; + syscallarg(int) fd2; + syscallarg(const char *) path2; + syscallarg(int) flag; +}; + +struct sys_mkdirat_args { + syscallarg(int) fd; + syscallarg(const char *) path; + syscallarg(mode_t) mode; +}; + +struct sys_mkfifoat_args { + syscallarg(int) fd; + syscallarg(const char *) path; + syscallarg(mode_t) mode; +}; + +struct sys_mknodat_args { + syscallarg(int) fd; + syscallarg(const char *) path; + syscallarg(mode_t) mode; + syscallarg(dev_t) dev; +}; + +struct sys_openat_args { + syscallarg(int) fd; + syscallarg(const char *) path; + syscallarg(int) flags; + syscallarg(mode_t) mode; +}; + +struct sys_readlinkat_args { + syscallarg(int) fd; + syscallarg(const char *) path; + syscallarg(char *) buf; + syscallarg(size_t) count; +}; + +struct sys_renameat_args { + syscallarg(int) fromfd; + syscallarg(const char *) from; + syscallarg(int) tofd; + syscallarg(const char *) to; +}; + +struct sys_symlinkat_args { + syscallarg(const char *) path; + syscallarg(int) fd; + syscallarg(const char *) link; +}; + +struct sys_unlinkat_args { + syscallarg(int) fd; + syscallarg(const char *) path; + syscallarg(int) flag; +}; + +struct sys___set_tcb_args { + syscallarg(void *) tcb; +}; + +/* + * System call prototypes. + */ + +int sys_exit(struct proc *, void *, register_t *); +int sys_fork(struct proc *, void *, register_t *); +int sys_read(struct proc *, void *, register_t *); +int sys_write(struct proc *, void *, register_t *); +int sys_open(struct proc *, void *, register_t *); +int sys_close(struct proc *, void *, register_t *); +int sys_getentropy(struct proc *, void *, register_t *); +int sys___tfork(struct proc *, void *, register_t *); +int sys_link(struct proc *, void *, register_t *); +int sys_unlink(struct proc *, void *, register_t *); +int sys_wait4(struct proc *, void *, register_t *); +int sys_chdir(struct proc *, void *, register_t *); +int sys_fchdir(struct proc *, void *, register_t *); +int sys_mknod(struct proc *, void *, register_t *); +int sys_chmod(struct proc *, void *, register_t *); +int sys_chown(struct proc *, void *, register_t *); +int sys_obreak(struct proc *, void *, register_t *); +int sys_getdtablecount(struct proc *, void *, register_t *); +int sys_getrusage(struct proc *, void *, register_t *); +int sys_getpid(struct proc *, void *, register_t *); +int sys_mount(struct proc *, void *, register_t *); +int sys_unmount(struct proc *, void *, register_t *); +int sys_setuid(struct proc *, void *, register_t *); +int sys_getuid(struct proc *, void *, register_t *); +int sys_geteuid(struct proc *, void *, register_t *); +#ifdef PTRACE +int sys_ptrace(struct proc *, void *, register_t *); +#else +#endif +int sys_recvmsg(struct proc *, void *, register_t *); +int sys_sendmsg(struct proc *, void *, register_t *); +int sys_recvfrom(struct proc *, void *, register_t *); +int sys_accept(struct proc *, void *, register_t *); +int sys_getpeername(struct proc *, void *, register_t *); +int sys_getsockname(struct proc *, void *, register_t *); +int sys_access(struct proc *, void *, register_t *); +int sys_chflags(struct proc *, void *, register_t *); +int sys_fchflags(struct proc *, void *, register_t *); +int sys_sync(struct proc *, void *, register_t *); +int sys_stat(struct proc *, void *, register_t *); +int sys_getppid(struct proc *, void *, register_t *); +int sys_lstat(struct proc *, void *, register_t *); +int sys_dup(struct proc *, void *, register_t *); +int sys_fstatat(struct proc *, void *, register_t *); +int sys_getegid(struct proc *, void *, register_t *); +#ifdef KTRACE +int sys_ktrace(struct proc *, void *, register_t *); +#else +#endif +int sys_sigaction(struct proc *, void *, register_t *); +int sys_getgid(struct proc *, void *, register_t *); +int sys_sigprocmask(struct proc *, void *, register_t *); +int sys_mmap(struct proc *, void *, register_t *); +int sys_setlogin(struct proc *, void *, register_t *); +#ifdef ACCOUNTING +int sys_acct(struct proc *, void *, register_t *); +#else +#endif +int sys_sigpending(struct proc *, void *, register_t *); +int sys_fstat(struct proc *, void *, register_t *); +int sys_ioctl(struct proc *, void *, register_t *); +int sys_reboot(struct proc *, void *, register_t *); +int sys_revoke(struct proc *, void *, register_t *); +int sys_symlink(struct proc *, void *, register_t *); +int sys_readlink(struct proc *, void *, register_t *); +int sys_execve(struct proc *, void *, register_t *); +int sys_umask(struct proc *, void *, register_t *); +int sys_chroot(struct proc *, void *, register_t *); +int sys_getfsstat(struct proc *, void *, register_t *); +int sys_statfs(struct proc *, void *, register_t *); +int sys_fstatfs(struct proc *, void *, register_t *); +int sys_fhstatfs(struct proc *, void *, register_t *); +int sys_vfork(struct proc *, void *, register_t *); +int sys_gettimeofday(struct proc *, void *, register_t *); +int sys_settimeofday(struct proc *, void *, register_t *); +int sys_setitimer(struct proc *, void *, register_t *); +int sys_getitimer(struct proc *, void *, register_t *); +int sys_select(struct proc *, void *, register_t *); +int sys_kevent(struct proc *, void *, register_t *); +int sys_munmap(struct proc *, void *, register_t *); +int sys_mprotect(struct proc *, void *, register_t *); +int sys_madvise(struct proc *, void *, register_t *); +int sys_utimes(struct proc *, void *, register_t *); +int sys_futimes(struct proc *, void *, register_t *); +int sys_mquery(struct proc *, void *, register_t *); +int sys_getgroups(struct proc *, void *, register_t *); +int sys_setgroups(struct proc *, void *, register_t *); +int sys_getpgrp(struct proc *, void *, register_t *); +int sys_setpgid(struct proc *, void *, register_t *); +int sys_futex(struct proc *, void *, register_t *); +int sys_utimensat(struct proc *, void *, register_t *); +int sys_futimens(struct proc *, void *, register_t *); +int sys_kbind(struct proc *, void *, register_t *); +int sys_clock_gettime(struct proc *, void *, register_t *); +int sys_clock_settime(struct proc *, void *, register_t *); +int sys_clock_getres(struct proc *, void *, register_t *); +int sys_dup2(struct proc *, void *, register_t *); +int sys_nanosleep(struct proc *, void *, register_t *); +int sys_fcntl(struct proc *, void *, register_t *); +int sys_accept4(struct proc *, void *, register_t *); +int sys___thrsleep(struct proc *, void *, register_t *); +int sys_fsync(struct proc *, void *, register_t *); +int sys_setpriority(struct proc *, void *, register_t *); +int sys_socket(struct proc *, void *, register_t *); +int sys_connect(struct proc *, void *, register_t *); +int sys_getdents(struct proc *, void *, register_t *); +int sys_getpriority(struct proc *, void *, register_t *); +int sys_pipe2(struct proc *, void *, register_t *); +int sys_dup3(struct proc *, void *, register_t *); +int sys_sigreturn(struct proc *, void *, register_t *); +int sys_bind(struct proc *, void *, register_t *); +int sys_setsockopt(struct proc *, void *, register_t *); +int sys_listen(struct proc *, void *, register_t *); +int sys_chflagsat(struct proc *, void *, register_t *); +int sys_pledge(struct proc *, void *, register_t *); +int sys_ppoll(struct proc *, void *, register_t *); +int sys_pselect(struct proc *, void *, register_t *); +int sys_sigsuspend(struct proc *, void *, register_t *); +int sys_sendsyslog(struct proc *, void *, register_t *); +int sys_unveil(struct proc *, void *, register_t *); +int sys___realpath(struct proc *, void *, register_t *); +int sys_recvmmsg(struct proc *, void *, register_t *); +int sys_sendmmsg(struct proc *, void *, register_t *); +int sys_getsockopt(struct proc *, void *, register_t *); +int sys_thrkill(struct proc *, void *, register_t *); +int sys_readv(struct proc *, void *, register_t *); +int sys_writev(struct proc *, void *, register_t *); +int sys_kill(struct proc *, void *, register_t *); +int sys_fchown(struct proc *, void *, register_t *); +int sys_fchmod(struct proc *, void *, register_t *); +int sys_setreuid(struct proc *, void *, register_t *); +int sys_setregid(struct proc *, void *, register_t *); +int sys_rename(struct proc *, void *, register_t *); +int sys_flock(struct proc *, void *, register_t *); +int sys_mkfifo(struct proc *, void *, register_t *); +int sys_sendto(struct proc *, void *, register_t *); +int sys_shutdown(struct proc *, void *, register_t *); +int sys_socketpair(struct proc *, void *, register_t *); +int sys_mkdir(struct proc *, void *, register_t *); +int sys_rmdir(struct proc *, void *, register_t *); +int sys_adjtime(struct proc *, void *, register_t *); +int sys_getlogin_r(struct proc *, void *, register_t *); +int sys_getthrname(struct proc *, void *, register_t *); +int sys_setthrname(struct proc *, void *, register_t *); +int sys_setsid(struct proc *, void *, register_t *); +int sys_quotactl(struct proc *, void *, register_t *); +int sys_ypconnect(struct proc *, void *, register_t *); +#if defined(NFSCLIENT) || defined(NFSSERVER) +int sys_nfssvc(struct proc *, void *, register_t *); +#else +#endif +int sys_pinsyscalls(struct proc *, void *, register_t *); +int sys_mimmutable(struct proc *, void *, register_t *); +int sys_waitid(struct proc *, void *, register_t *); +int sys_getfh(struct proc *, void *, register_t *); +int sys___tmpfd(struct proc *, void *, register_t *); +int sys_sysarch(struct proc *, void *, register_t *); +int sys_lseek(struct proc *, void *, register_t *); +int sys_truncate(struct proc *, void *, register_t *); +int sys_ftruncate(struct proc *, void *, register_t *); +int sys_pread(struct proc *, void *, register_t *); +int sys_pwrite(struct proc *, void *, register_t *); +int sys_preadv(struct proc *, void *, register_t *); +int sys_pwritev(struct proc *, void *, register_t *); +int sys_profil(struct proc *, void *, register_t *); +int sys_setgid(struct proc *, void *, register_t *); +int sys_setegid(struct proc *, void *, register_t *); +int sys_seteuid(struct proc *, void *, register_t *); +int sys_pathconfat(struct proc *, void *, register_t *); +int sys_pathconf(struct proc *, void *, register_t *); +int sys_fpathconf(struct proc *, void *, register_t *); +int sys_swapctl(struct proc *, void *, register_t *); +int sys_getrlimit(struct proc *, void *, register_t *); +int sys_setrlimit(struct proc *, void *, register_t *); +int sys_sysctl(struct proc *, void *, register_t *); +int sys_mlock(struct proc *, void *, register_t *); +int sys_munlock(struct proc *, void *, register_t *); +int sys_getpgid(struct proc *, void *, register_t *); +int sys_utrace(struct proc *, void *, register_t *); +#ifdef SYSVSEM +int sys_semget(struct proc *, void *, register_t *); +#else +#endif +#ifdef SYSVMSG +int sys_msgget(struct proc *, void *, register_t *); +int sys_msgsnd(struct proc *, void *, register_t *); +int sys_msgrcv(struct proc *, void *, register_t *); +#else +#endif +#ifdef SYSVSHM +int sys_shmat(struct proc *, void *, register_t *); +int sys_shmdt(struct proc *, void *, register_t *); +#else +#endif +int sys_minherit(struct proc *, void *, register_t *); +int sys_poll(struct proc *, void *, register_t *); +int sys_issetugid(struct proc *, void *, register_t *); +int sys_lchown(struct proc *, void *, register_t *); +int sys_getsid(struct proc *, void *, register_t *); +int sys_msync(struct proc *, void *, register_t *); +int sys_pipe(struct proc *, void *, register_t *); +int sys_fhopen(struct proc *, void *, register_t *); +int sys_kqueue(struct proc *, void *, register_t *); +int sys_kqueue1(struct proc *, void *, register_t *); +int sys_mlockall(struct proc *, void *, register_t *); +int sys_munlockall(struct proc *, void *, register_t *); +int sys_getresuid(struct proc *, void *, register_t *); +int sys_setresuid(struct proc *, void *, register_t *); +int sys_getresgid(struct proc *, void *, register_t *); +int sys_setresgid(struct proc *, void *, register_t *); +int sys_closefrom(struct proc *, void *, register_t *); +int sys_sigaltstack(struct proc *, void *, register_t *); +#ifdef SYSVSHM +int sys_shmget(struct proc *, void *, register_t *); +#else +#endif +#ifdef SYSVSEM +int sys_semop(struct proc *, void *, register_t *); +#else +#endif +int sys_fhstat(struct proc *, void *, register_t *); +#ifdef SYSVSEM +int sys___semctl(struct proc *, void *, register_t *); +#else +#endif +#ifdef SYSVSHM +int sys_shmctl(struct proc *, void *, register_t *); +#else +#endif +#ifdef SYSVMSG +int sys_msgctl(struct proc *, void *, register_t *); +#else +#endif +int sys_sched_yield(struct proc *, void *, register_t *); +int sys_getthrid(struct proc *, void *, register_t *); +int sys___thrwakeup(struct proc *, void *, register_t *); +int sys___threxit(struct proc *, void *, register_t *); +int sys___thrsigdivert(struct proc *, void *, register_t *); +int sys___getcwd(struct proc *, void *, register_t *); +int sys_adjfreq(struct proc *, void *, register_t *); +int sys_setrtable(struct proc *, void *, register_t *); +int sys_getrtable(struct proc *, void *, register_t *); +int sys_faccessat(struct proc *, void *, register_t *); +int sys_fchmodat(struct proc *, void *, register_t *); +int sys_fchownat(struct proc *, void *, register_t *); +int sys_linkat(struct proc *, void *, register_t *); +int sys_mkdirat(struct proc *, void *, register_t *); +int sys_mkfifoat(struct proc *, void *, register_t *); +int sys_mknodat(struct proc *, void *, register_t *); +int sys_openat(struct proc *, void *, register_t *); +int sys_readlinkat(struct proc *, void *, register_t *); +int sys_renameat(struct proc *, void *, register_t *); +int sys_symlinkat(struct proc *, void *, register_t *); +int sys_unlinkat(struct proc *, void *, register_t *); +int sys___set_tcb(struct proc *, void *, register_t *); +int sys___get_tcb(struct proc *, void *, register_t *); \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/sysctl.h b/lib/libc/include/generic-openbsd/sys/sysctl.h new file mode 100644 index 0000000000..39620208b0 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/sysctl.h @@ -0,0 +1,1100 @@ +/* $OpenBSD: sysctl.h,v 1.246 2025/07/31 09:05:11 mvs Exp $ */ +/* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Mike Karels at Berkeley Software Design, Inc. + * + * 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. + * + * @(#)sysctl.h 8.2 (Berkeley) 3/30/95 + */ + +#ifndef _SYS_SYSCTL_H_ +#define _SYS_SYSCTL_H_ + +#include +#include + +/* + * Definitions for sysctl call. The sysctl call uses a hierarchical name + * for objects that can be examined or modified. The name is expressed as + * a sequence of integers. Like a file path name, the meaning of each + * component depends on its place in the hierarchy. The top-level and kern + * identifiers are defined here, and other identifiers are defined in the + * respective subsystem header files. + */ + +#define CTL_MAXNAME 12 /* largest number of components supported */ + +/* + * Each subsystem defined by sysctl defines a list of variables + * for that subsystem. Each name is either a node with further + * levels defined below it, or it is a leaf of some particular + * type given below. Each sysctl level defines a set of name/type + * pairs to be used by sysctl(1) in manipulating the subsystem. + */ +struct ctlname { + char *ctl_name; /* subsystem name */ + int ctl_type; /* type of name */ +}; +#define CTLTYPE_NODE 1 /* name is a node */ +#define CTLTYPE_INT 2 /* name describes an integer */ +#define CTLTYPE_STRING 3 /* name describes a string */ +#define CTLTYPE_QUAD 4 /* name describes a 64-bit number */ +#define CTLTYPE_STRUCT 5 /* name describes a structure */ + +/* + * Top-level identifiers + */ +#define CTL_UNSPEC 0 /* unused */ +#define CTL_KERN 1 /* "high kernel": proc, limits */ +#define CTL_VM 2 /* virtual memory */ +/* gap for CTL_FS 3 */ +#define CTL_NET 4 /* network, see socket.h */ +#define CTL_DEBUG 5 /* debugging parameters */ +#define CTL_HW 6 /* generic cpu/io */ +#define CTL_MACHDEP 7 /* machine dependent */ +/*define gap 8 was CTL_USER: removed 2013-04 */ +#define CTL_DDB 9 /* DDB user interface, see db_var.h */ +#define CTL_VFS 10 /* VFS sysctl's */ +#define CTL_MAXID 11 /* number of valid top-level ids */ + +#define CTL_NAMES { \ + { 0, 0 }, \ + { "kern", CTLTYPE_NODE }, \ + { "vm", CTLTYPE_NODE }, \ + { "gap", 0 }, \ + { "net", CTLTYPE_NODE }, \ + { "debug", CTLTYPE_NODE }, \ + { "hw", CTLTYPE_NODE }, \ + { "machdep", CTLTYPE_NODE }, \ + { "gap", 0 }, \ + { "ddb", CTLTYPE_NODE }, \ + { "vfs", CTLTYPE_NODE }, \ +} + +/* + * CTL_KERN identifiers + */ +#define KERN_OSTYPE 1 /* string: system version */ +#define KERN_OSRELEASE 2 /* string: system release */ +#define KERN_OSREV 3 /* int: system revision */ +#define KERN_VERSION 4 /* string: compile time info */ +#define KERN_MAXVNODES 5 /* int: max vnodes */ +#define KERN_MAXPROC 6 /* int: max processes */ +#define KERN_MAXFILES 7 /* int: max open files */ +#define KERN_ARGMAX 8 /* int: max arguments to exec */ +#define KERN_SECURELVL 9 /* int: system security level */ +#define KERN_HOSTNAME 10 /* string: hostname */ +#define KERN_HOSTID 11 /* int: host identifier */ +#define KERN_CLOCKRATE 12 /* struct: struct clockinfo */ +/* was KERN_DNSJACKPORT 13 */ +/* was KERN_PROC 14 */ +/* was KERN_FILE 15 */ +#define KERN_PROF 16 /* node: kernel profiling info */ +#define KERN_POSIX1 17 /* int: POSIX.1 version */ +#define KERN_NGROUPS 18 /* int: # of supplemental group ids */ +#define KERN_JOB_CONTROL 19 /* int: is job control available */ +#define KERN_SAVED_IDS 20 /* int: saved set-user/group-ID */ +#define KERN_BOOTTIME 21 /* struct: time kernel was booted */ +#define KERN_DOMAINNAME 22 /* string: (YP) domainname */ +#define KERN_MAXPARTITIONS 23 /* int: number of partitions/disk */ +#define KERN_RAWPARTITION 24 /* int: raw partition number */ +#define KERN_MAXTHREAD 25 /* int: max threads */ +#define KERN_NTHREADS 26 /* int: number of threads */ +#define KERN_OSVERSION 27 /* string: kernel build version */ +#define KERN_SOMAXCONN 28 /* int: listen queue maximum */ +#define KERN_SOMINCONN 29 /* int: half-open controllable param */ +/* was KERN_USERMOUNT 30 */ +/* was KERN_RND 31 */ +#define KERN_NOSUIDCOREDUMP 32 /* int: no setuid coredumps ever */ +#define KERN_FSYNC 33 /* int: file synchronization support */ +#define KERN_SYSVMSG 34 /* int: SysV message queue support */ +#define KERN_SYSVSEM 35 /* int: SysV semaphore support */ +#define KERN_SYSVSHM 36 /* int: SysV shared memory support */ +/* was KERN_ARND 37 */ +#define KERN_MSGBUFSIZE 38 /* int: size of message buffer */ +#define KERN_MALLOCSTATS 39 /* node: malloc statistics */ +#define KERN_CPTIME 40 /* array: cp_time */ +#define KERN_NCHSTATS 41 /* struct: vfs cache statistics */ +#define KERN_FORKSTAT 42 /* struct: fork statistics */ +/* was KERN_NSELCOLL 43 */ +#define KERN_TTY 44 /* node: tty information */ +#define KERN_CCPU 45 /* int: ccpu */ +#define KERN_FSCALE 46 /* int: fscale */ +#define KERN_NPROCS 47 /* int: number of processes */ +#define KERN_MSGBUF 48 /* message buffer, KERN_MSGBUFSIZE */ +#define KERN_POOL 49 /* struct: pool information */ +#define KERN_STACKGAPRANDOM 50 /* int: stackgap_random */ +#define KERN_SYSVIPC_INFO 51 /* struct: SysV sem/shm/msg info */ +#define KERN_ALLOWKMEM 52 /* int: allowkmem */ +#define KERN_WITNESSWATCH 53 /* int: witnesswatch */ +#define KERN_SPLASSERT 54 /* int: splassert */ +#define KERN_PROC_ARGS 55 /* node: proc args and env */ +#define KERN_NFILES 56 /* int: number of open files */ +#define KERN_TTYCOUNT 57 /* int: number of tty devices */ +#define KERN_NUMVNODES 58 /* int: number of vnodes in use */ +#define KERN_MBSTAT 59 /* struct: mbuf statistics */ +#define KERN_WITNESS 60 /* node: witness */ +#define KERN_SEMINFO 61 /* struct: SysV struct seminfo */ +#define KERN_SHMINFO 62 /* struct: SysV struct shminfo */ +#define KERN_INTRCNT 63 /* node: interrupt counters */ +#define KERN_WATCHDOG 64 /* node: watchdog */ +#define KERN_ALLOWDT 65 /* int: allowdt */ +#define KERN_PROC 66 /* struct: process entries */ +#define KERN_MAXCLUSTERS 67 /* number of mclusters */ +#define KERN_EVCOUNT 68 /* node: event counters */ +#define KERN_TIMECOUNTER 69 /* node: timecounter */ +#define KERN_MAXLOCKSPERUID 70 /* int: locks per uid */ +#define KERN_CPTIME2 71 /* array: cp_time2 */ +#define KERN_CACHEPCT 72 /* buffer cache % of physmem */ +#define KERN_FILE 73 /* struct: file entries */ +#define KERN_WXABORT 74 /* int: w^x sigabrt & core */ +#define KERN_CONSDEV 75 /* dev_t: console terminal device */ +#define KERN_NETLIVELOCKS 76 /* int: number of network livelocks */ +#define KERN_POOL_DEBUG 77 /* int: enable pool_debug */ +#define KERN_PROC_CWD 78 /* node: proc cwd */ +#define KERN_PROC_NOBROADCASTKILL 79 /* node: proc no broadcast kill */ +#define KERN_PROC_VMMAP 80 /* node: proc vmmap */ +#define KERN_GLOBAL_PTRACE 81 /* allow ptrace globally */ +#define KERN_CONSBUFSIZE 82 /* int: console message buffer size */ +#define KERN_CONSBUF 83 /* console message buffer */ +#define KERN_AUDIO 84 /* struct: audio properties */ +#define KERN_CPUSTATS 85 /* struct: cpu statistics */ +#define KERN_PFSTATUS 86 /* struct: pf status and stats */ +#define KERN_TIMEOUT_STATS 87 /* struct: timeout status and stats */ +#define KERN_UTC_OFFSET 88 /* int: adjust RTC time to UTC */ +#define KERN_VIDEO 89 /* struct: video properties */ +#define KERN_CLOCKINTR 90 /* node: clockintr */ +#define KERN_AUTOCONF_SERIAL 91 /* int: kernel device tree state serial */ +#define KERN_MAXID 92 /* number of valid kern ids */ + +#define CTL_KERN_NAMES { \ + { 0, 0 }, \ + { "ostype", CTLTYPE_STRING }, \ + { "osrelease", CTLTYPE_STRING }, \ + { "osrevision", CTLTYPE_INT }, \ + { "version", CTLTYPE_STRING }, \ + { "maxvnodes", CTLTYPE_INT }, \ + { "maxproc", CTLTYPE_INT }, \ + { "maxfiles", CTLTYPE_INT }, \ + { "argmax", CTLTYPE_INT }, \ + { "securelevel", CTLTYPE_INT }, \ + { "hostname", CTLTYPE_STRING }, \ + { "hostid", CTLTYPE_INT }, \ + { "clockrate", CTLTYPE_STRUCT }, \ + { "gap", 0 }, \ + { "gap", 0 }, \ + { "gap", 0 }, \ + { "profiling", CTLTYPE_NODE }, \ + { "posix1version", CTLTYPE_INT }, \ + { "ngroups", CTLTYPE_INT }, \ + { "job_control", CTLTYPE_INT }, \ + { "saved_ids", CTLTYPE_INT }, \ + { "boottime", CTLTYPE_STRUCT }, \ + { "domainname", CTLTYPE_STRING }, \ + { "maxpartitions", CTLTYPE_INT }, \ + { "rawpartition", CTLTYPE_INT }, \ + { "maxthread", CTLTYPE_INT }, \ + { "nthreads", CTLTYPE_INT }, \ + { "osversion", CTLTYPE_STRING }, \ + { "somaxconn", CTLTYPE_INT }, \ + { "sominconn", CTLTYPE_INT }, \ + { "gap", 0 }, \ + { "gap", 0 }, \ + { "nosuidcoredump", CTLTYPE_INT }, \ + { "fsync", CTLTYPE_INT }, \ + { "sysvmsg", CTLTYPE_INT }, \ + { "sysvsem", CTLTYPE_INT }, \ + { "sysvshm", CTLTYPE_INT }, \ + { "gap", 0 }, \ + { "msgbufsize", CTLTYPE_INT }, \ + { "malloc", CTLTYPE_NODE }, \ + { "cp_time", CTLTYPE_STRUCT }, \ + { "nchstats", CTLTYPE_STRUCT }, \ + { "forkstat", CTLTYPE_STRUCT }, \ + { "gap", 0 }, \ + { "tty", CTLTYPE_NODE }, \ + { "ccpu", CTLTYPE_INT }, \ + { "fscale", CTLTYPE_INT }, \ + { "nprocs", CTLTYPE_INT }, \ + { "msgbuf", CTLTYPE_STRUCT }, \ + { "pool", CTLTYPE_NODE }, \ + { "stackgap_random", CTLTYPE_INT }, \ + { "sysvipc_info", CTLTYPE_INT }, \ + { "allowkmem", CTLTYPE_INT }, \ + { "witnesswatch", CTLTYPE_INT }, \ + { "splassert", CTLTYPE_INT }, \ + { "procargs", CTLTYPE_NODE }, \ + { "nfiles", CTLTYPE_INT }, \ + { "ttycount", CTLTYPE_INT }, \ + { "numvnodes", CTLTYPE_INT }, \ + { "mbstat", CTLTYPE_STRUCT }, \ + { "witness", CTLTYPE_NODE }, \ + { "seminfo", CTLTYPE_STRUCT }, \ + { "shminfo", CTLTYPE_STRUCT }, \ + { "intrcnt", CTLTYPE_NODE }, \ + { "watchdog", CTLTYPE_NODE }, \ + { "allowdt", CTLTYPE_INT }, \ + { "proc", CTLTYPE_STRUCT }, \ + { "maxclusters", CTLTYPE_INT }, \ + { "evcount", CTLTYPE_NODE }, \ + { "timecounter", CTLTYPE_NODE }, \ + { "maxlocksperuid", CTLTYPE_INT }, \ + { "cp_time2", CTLTYPE_STRUCT }, \ + { "bufcachepercent", CTLTYPE_INT }, \ + { "file", CTLTYPE_STRUCT }, \ + { "wxabort", CTLTYPE_INT }, \ + { "consdev", CTLTYPE_STRUCT }, \ + { "netlivelocks", CTLTYPE_INT }, \ + { "pool_debug", CTLTYPE_INT }, \ + { "proc_cwd", CTLTYPE_NODE }, \ + { "proc_nobroadcastkill", CTLTYPE_NODE }, \ + { "proc_vmmap", CTLTYPE_NODE }, \ + { "global_ptrace", CTLTYPE_INT }, \ + { "consbufsize", CTLTYPE_INT }, \ + { "consbuf", CTLTYPE_STRUCT }, \ + { "audio", CTLTYPE_STRUCT }, \ + { "cpustats", CTLTYPE_STRUCT }, \ + { "pfstatus", CTLTYPE_STRUCT }, \ + { "timeout_stats", CTLTYPE_STRUCT }, \ + { "utc_offset", CTLTYPE_INT }, \ + { "video", CTLTYPE_STRUCT }, \ + { "clockintr", CTLTYPE_NODE }, \ + { "autoconf_serial", CTLTYPE_INT }, \ +} + +/* + * KERN_PROC subtypes + */ +#define KERN_PROC_ALL 0 /* everything but kernel threads */ +#define KERN_PROC_PID 1 /* by process id */ +#define KERN_PROC_PGRP 2 /* by process group id */ +#define KERN_PROC_SESSION 3 /* by session of pid */ +#define KERN_PROC_TTY 4 /* by controlling tty */ +#define KERN_PROC_UID 5 /* by effective uid */ +#define KERN_PROC_RUID 6 /* by real uid */ +#define KERN_PROC_KTHREAD 7 /* also return kernel threads */ +#define KERN_PROC_SHOW_THREADS 0x40000000/* also return normal threads */ + +/* + * KERN_SYSVIPC_INFO subtypes + */ +#define KERN_SYSVIPC_MSG_INFO 1 /* msginfo and msqid_ds */ +#define KERN_SYSVIPC_SEM_INFO 2 /* seminfo and semid_ds */ +#define KERN_SYSVIPC_SHM_INFO 3 /* shminfo and shmid_ds */ + +/* + * KERN_PROC_ARGS subtypes + */ +#define KERN_PROC_ARGV 1 +#define KERN_PROC_NARGV 2 +#define KERN_PROC_ENV 3 +#define KERN_PROC_NENV 4 + +/* + * KERN_AUDIO + */ +#define KERN_AUDIO_RECORD 1 +#define KERN_AUDIO_KBDCONTROL 2 +#define KERN_AUDIO_MAXID 3 + +#define CTL_KERN_AUDIO_NAMES { \ + { 0, 0 }, \ + { "record", CTLTYPE_INT }, \ + { "kbdcontrol", CTLTYPE_INT }, \ +} + +/* + * KERN_VIDEO + */ +#define KERN_VIDEO_RECORD 1 +#define KERN_VIDEO_MAXID 2 + +#define CTL_KERN_VIDEO_NAMES { \ + { 0, 0 }, \ + { "record", CTLTYPE_INT }, \ +} + +/* + * KERN_WITNESS + */ +#define KERN_WITNESS_WATCH 1 /* int: operating mode */ +#define KERN_WITNESS_LOCKTRACE 2 /* int: stack trace saving mode */ +#define KERN_WITNESS_MAXID 3 + +#define CTL_KERN_WITNESS_NAMES { \ + { 0, 0 }, \ + { "watch", CTLTYPE_INT }, \ + { "locktrace", CTLTYPE_INT }, \ +} + +/* + * KERN_PROC subtype ops return arrays of relatively fixed size + * structures of process info. Use 8 byte alignment, and new + * elements should only be added to the end of this structure so + * binary compatibility can be preserved. + */ +#define KI_NGROUPS 16 +#define KI_MAXCOMLEN _MAXCOMLEN /* includes NUL */ +#define KI_WMESGLEN 8 +#define KI_MAXLOGNAME 32 +#define KI_EMULNAMELEN 8 + +#define KI_NOCPU (~(u_int64_t)0) + +struct kinfo_proc { + u_int64_t p_forw; /* PTR: linked run/sleep queue. */ + u_int64_t p_back; + u_int64_t p_paddr; /* PTR: address of proc */ + + u_int64_t p_addr; /* PTR: Kernel virtual addr of u-area */ + u_int64_t p_fd; /* PTR: Ptr to open files structure. */ + u_int64_t p_stats; /* unused, always zero. */ + u_int64_t p_limit; /* PTR: Process limits. */ + u_int64_t p_vmspace; /* PTR: Address space. */ + u_int64_t p_sigacts; /* PTR: Signal actions, state */ + u_int64_t p_sess; /* PTR: session pointer */ + u_int64_t p_tsess; /* PTR: tty session pointer */ + u_int64_t p_ru; /* PTR: Exit information. XXX */ + + int32_t p_eflag; /* LONG: extra kinfo_proc flags */ +#define EPROC_CTTY 0x01 /* controlling tty vnode active */ +#define EPROC_SLEADER 0x02 /* session leader */ +#define EPROC_UNVEIL 0x04 /* has unveil settings */ +#define EPROC_LKUNVEIL 0x08 /* unveil is locked */ + int32_t p_exitsig; /* unused, always zero. */ + int32_t p_flag; /* INT: P_* flags. */ + + int32_t p_pid; /* PID_T: Process identifier. */ + int32_t p_ppid; /* PID_T: Parent process id */ + int32_t p_sid; /* PID_T: session id */ + int32_t p__pgid; /* PID_T: process group id */ + /* XXX: hijacks p_pgid */ + int32_t p_tpgid; /* PID_T: tty process group id */ + + u_int32_t p_uid; /* UID_T: effective user id */ + u_int32_t p_ruid; /* UID_T: real user id */ + u_int32_t p_gid; /* GID_T: effective group id */ + u_int32_t p_rgid; /* GID_T: real group id */ + + u_int32_t p_groups[KI_NGROUPS]; /* GID_T: groups */ + int16_t p_ngroups; /* SHORT: number of groups */ + + int16_t p_jobc; /* SHORT: job control counter */ + u_int32_t p_tdev; /* DEV_T: controlling tty dev */ + + u_int32_t p_estcpu; /* U_INT: Time averaged value of p_cpticks. */ + u_int32_t p_rtime_sec; /* STRUCT TIMEVAL: Real time. */ + u_int32_t p_rtime_usec; /* STRUCT TIMEVAL: Real time. */ + int32_t p_cpticks; /* INT: Ticks of cpu time. */ + u_int32_t p_pctcpu; /* FIXPT_T: %cpu for this process */ + u_int32_t p_swtime; /* unused, always zero */ + u_int32_t p_slptime; /* U_INT: Time since last blocked. */ + int32_t p_schedflags; /* INT: PSCHED_* flags */ + + u_int64_t p_uticks; /* U_QUAD_T: Statclock hits in user mode. */ + u_int64_t p_sticks; /* U_QUAD_T: Statclock hits in system mode. */ + u_int64_t p_iticks; /* U_QUAD_T: Statclock hits processing intr. */ + + u_int64_t p_tracep; /* PTR: Trace to vnode or file */ + int32_t p_traceflag; /* INT: Kernel trace points. */ + + int32_t p_holdcnt; /* INT: If non-zero, don't swap. */ + + int32_t p_siglist; /* INT: Signals arrived but not delivered. */ + u_int32_t p_sigmask; /* SIGSET_T: Current signal mask. */ + u_int32_t p_sigignore; /* SIGSET_T: Signals being ignored. */ + u_int32_t p_sigcatch; /* SIGSET_T: Signals being caught by user. */ + + int8_t p_stat; /* CHAR: S* process status (from LWP). */ + u_int8_t p_priority; /* U_CHAR: Process priority. */ + u_int8_t p_usrpri; /* U_CHAR: User-priority based on p_estcpu and ps_nice. */ + u_int8_t p_nice; /* U_CHAR: Process "nice" value. */ + + u_int16_t p_xstat; /* U_SHORT: Exit status for wait; also stop signal. */ + u_int16_t p_spare; /* U_SHORT: unused */ + + char p_comm[KI_MAXCOMLEN]; + + char p_wmesg[KI_WMESGLEN]; /* wchan message */ + u_int64_t p_wchan; /* PTR: sleep address. */ + + char p_login[KI_MAXLOGNAME]; /* setlogin() name */ + + int32_t p_vm_rssize; /* SEGSZ_T: current resident set size in pages */ + int32_t p_vm_tsize; /* SEGSZ_T: text size (pages) */ + int32_t p_vm_dsize; /* SEGSZ_T: data size (pages) */ + int32_t p_vm_ssize; /* SEGSZ_T: stack size (pages) */ + + int64_t p_uvalid; /* CHAR: following p_u* members from struct user are valid */ + /* XXX 64 bits for alignment */ + u_int64_t p_ustart_sec; /* STRUCT TIMEVAL: starting time. */ + u_int32_t p_ustart_usec; /* STRUCT TIMEVAL: starting time. */ + + u_int32_t p_uutime_sec; /* STRUCT TIMEVAL: user time. */ + u_int32_t p_uutime_usec; /* STRUCT TIMEVAL: user time. */ + u_int32_t p_ustime_sec; /* STRUCT TIMEVAL: system time. */ + u_int32_t p_ustime_usec; /* STRUCT TIMEVAL: system time. */ + + u_int64_t p_uru_maxrss; /* LONG: max resident set size. */ + u_int64_t p_uru_ixrss; /* LONG: integral shared memory size. */ + u_int64_t p_uru_idrss; /* LONG: integral unshared data ". */ + u_int64_t p_uru_isrss; /* LONG: integral unshared stack ". */ + u_int64_t p_uru_minflt; /* LONG: page reclaims. */ + u_int64_t p_uru_majflt; /* LONG: page faults. */ + u_int64_t p_uru_nswap; /* LONG: swaps. */ + u_int64_t p_uru_inblock; /* LONG: block input operations. */ + u_int64_t p_uru_oublock; /* LONG: block output operations. */ + u_int64_t p_uru_msgsnd; /* LONG: messages sent. */ + u_int64_t p_uru_msgrcv; /* LONG: messages received. */ + u_int64_t p_uru_nsignals; /* LONG: signals received. */ + u_int64_t p_uru_nvcsw; /* LONG: voluntary context switches. */ + u_int64_t p_uru_nivcsw; /* LONG: involuntary ". */ + + u_int32_t p_uctime_sec; /* STRUCT TIMEVAL: child u+s time. */ + u_int32_t p_uctime_usec; /* STRUCT TIMEVAL: child u+s time. */ + u_int32_t p_psflags; /* UINT: PS_* flags on the process. */ + u_int32_t p_acflag; /* UINT: Accounting flags. */ + u_int32_t p_svuid; /* UID_T: saved user id */ + u_int32_t p_svgid; /* GID_T: saved group id */ + char p_emul[KI_EMULNAMELEN]; /* syscall emulation name */ + u_int64_t p_rlim_rss_cur; /* RLIM_T: soft limit for rss */ + u_int64_t p_cpuid; /* LONG: CPU id */ + u_int64_t p_vm_map_size; /* VSIZE_T: virtual size */ + int32_t p_tid; /* PID_T: Thread identifier. */ + u_int32_t p_rtableid; /* U_INT: Routing table identifier. */ + + u_int64_t p_pledge; /* U_INT64_T: Pledge flags. */ + char p_name[KI_MAXCOMLEN]; /* thread name */ +}; + +/* + * VM address range entry, matching struct vm_map_entry. Useful for + * debuggers to know process's addresses. + * + * To iterate entries, set the last kve_end as the base address into + * kve_start. + */ +struct kinfo_vmentry { + u_long kve_start; /* vaddr_t */ + u_long kve_end; /* vaddr_t */ + u_long kve_guard; /* vsize_t */ + u_long kve_fspace; /* vsize_t */ + u_long kve_fspace_augment; /* vsize_t */ + u_int64_t kve_offset; /* voff_t */ + int kve_wired_count; + int kve_etype; + int kve_protection; + int kve_max_protection; + int kve_advice; + int kve_inheritance; + u_int8_t kve_flags; /* u_int8_t */ +}; + +/* keep in sync with UVM_ET_* */ +#define KVE_ET_OBJ 0x00000001 +#define KVE_ET_SUBMAP 0x00000002 +#define KVE_ET_COPYONWRITE 0x00000004 +#define KVE_ET_NEEDSCOPY 0x00000008 +#define KVE_ET_HOLE 0x00000010 +#define KVE_ET_NOFAULT 0x00000020 +#define KVE_ET_STACK 0x00000040 +#define KVE_ET_WC 0x00000080 +#define KVE_ET_CONCEAL 0x00000100 +#define KVE_ET_SYSCALL 0x00000200 +#define KVE_ET_FREEMAPPED 0x00000800 + +#define KVE_PROT_NONE 0x00000000 +#define KVE_PROT_READ 0x00000001 +#define KVE_PROT_WRITE 0x00000002 +#define KVE_PROT_EXEC 0x00000004 + +#define KVE_ADV_NORMAL 0x00000000 +#define KVE_ADV_RANDOM 0x00000001 +#define KVE_ADV_SEQUENTIAL 0x00000002 + +#define KVE_INH_SHARE 0x00000000 +#define KVE_INH_COPY 0x00000010 +#define KVE_INH_NONE 0x00000020 +#define KVE_INH_ZERO 0x00000030 + +#define KVE_F_STATIC 0x01 +#define KVE_F_KMEM 0x02 + +#if defined(_KERNEL) || defined(_LIBKVM) + +/* + * Macros for filling in the bulk of a kinfo_proc structure, used + * in the kernel to implement the KERN_PROC sysctl and in userland + * in libkvm to implement reading from kernel crashes. The macro + * arguments are all pointers; by name they are: + * kp - target kinfo_proc structure + * copy_str - a function or macro invoked as copy_str(dst,src,maxlen) + * that has strlcpy or memcpy semantics; the destination is + * pre-filled with zeros; for libkvm, src is a kvm address + * p - source struct proc + * pr - source struct process + * uc - source struct ucreds + * pg - source struct pgrp + * paddr - kernel address of the source struct proc + * praddr - kernel address of the source struct process + * sess - source struct session + * vm - source struct vmspace + * lim - source struct plimits + * sa - source struct sigacts + * There are some members that are not handled by these macros + * because they're too painful to generalize: p_sid, p_tdev, + * p_tpgid, p_tsess, p_vm_rssize, p_u[us]time_{sec,usec}, p_cpuid + */ + +#if defined(_KERNEL) +#define PR_LOCK(pr) mtx_enter(&(pr)->ps_mtx) +#define PR_UNLOCK(pr) mtx_leave(&(pr)->ps_mtx) +#else +#define PR_LOCK(pr) /* nothing */ +#define PR_UNLOCK(pr) /* nothing */ +#endif + +#define _getcompatprio(_p) \ + ((_p)->p_stat == SRUN ? (_p)->p_runpri : \ + ((_p)->p_stat == SSLEEP) ? (_p)->p_slppri : (_p)->p_usrpri) + +#define PTRTOINT64(_x) ((u_int64_t)(u_long)(_x)) + +#define _FILL_KPROC_MIN(a,b) (((a)<(b))?(a):(b)) + +#define FILL_KPROC(kp, copy_str, p, pr, uc, pg, paddr, \ + praddr, sess, vm, lim, sa, tu, isthread, show_addresses) \ +do { \ + memset((kp), 0, sizeof(*(kp))); \ + \ + if (show_addresses) { \ + (kp)->p_paddr = PTRTOINT64(paddr); \ + (kp)->p_fd = PTRTOINT64((pr)->ps_fd); \ + (kp)->p_limit = PTRTOINT64((pr)->ps_limit); \ + (kp)->p_vmspace = PTRTOINT64((pr)->ps_vmspace); \ + (kp)->p_sigacts = PTRTOINT64((pr)->ps_sigacts); \ + (kp)->p_sess = PTRTOINT64((pg)->pg_session); \ + (kp)->p_ru = PTRTOINT64((pr)->ps_ru); \ + } \ + (kp)->p_stats = 0; \ + (kp)->p_exitsig = 0; \ + (kp)->p_flag = (p)->p_flag; \ + (kp)->p_pid = (pr)->ps_pid; \ + (kp)->p_psflags = (pr)->ps_flags; \ + \ + (kp)->p__pgid = (pg)->pg_id; \ + \ + (kp)->p_uid = (uc)->cr_uid; \ + (kp)->p_ruid = (uc)->cr_ruid; \ + (kp)->p_gid = (uc)->cr_gid; \ + (kp)->p_rgid = (uc)->cr_rgid; \ + (kp)->p_svuid = (uc)->cr_svuid; \ + (kp)->p_svgid = (uc)->cr_svgid; \ + \ + memcpy((kp)->p_groups, (uc)->cr_groups, \ + _FILL_KPROC_MIN(sizeof((kp)->p_groups), sizeof((uc)->cr_groups))); \ + (kp)->p_ngroups = (uc)->cr_ngroups; \ + \ + (kp)->p_jobc = (pg)->pg_jobc; \ + \ + (kp)->p_estcpu = (p)->p_estcpu; \ + if (isthread) { \ + (kp)->p_tid = (p)->p_tid + THREAD_PID_OFFSET; \ + strlcpy((kp)->p_name, (p)->p_name, sizeof((kp)->p_name)); \ + } else { \ + (kp)->p_tid = -1; \ + } \ + (kp)->p_rtime_sec = (tu)->tu_runtime.tv_sec; \ + (kp)->p_rtime_usec = (tu)->tu_runtime.tv_nsec/1000; \ + (kp)->p_uticks = (tu)->tu_uticks; \ + (kp)->p_sticks = (tu)->tu_sticks; \ + (kp)->p_iticks = (tu)->tu_iticks; \ + (kp)->p_cpticks = (p)->p_cpticks; \ + \ + if (show_addresses) \ + (kp)->p_tracep = PTRTOINT64((pr)->ps_tracevp); \ + (kp)->p_traceflag = (pr)->ps_traceflag; \ + \ + (kp)->p_siglist = (p)->p_siglist | (pr)->ps_siglist; \ + (kp)->p_sigmask = (p)->p_sigmask; \ + \ + PR_LOCK(pr); \ + (kp)->p_ppid = (pr)->ps_ppid; \ + (kp)->p_sigignore = (sa) ? (sa)->ps_sigignore : 0; \ + (kp)->p_sigcatch = (sa) ? (sa)->ps_sigcatch : 0; \ + \ + if (lim) \ + (kp)->p_rlim_rss_cur = \ + (lim)->pl_rlimit[RLIMIT_RSS].rlim_cur; \ + PR_UNLOCK(pr); \ + \ + (kp)->p_stat = (p)->p_stat; \ + (kp)->p_nice = (pr)->ps_nice; \ + \ + (kp)->p_xstat = W_EXITCODE((pr)->ps_xexit, (pr)->ps_xsig); \ + (kp)->p_acflag = (pr)->ps_acflag; \ + (kp)->p_pledge = (pr)->ps_pledge; \ + \ + strlcpy((kp)->p_emul, "native", sizeof((kp)->p_emul)); \ + strlcpy((kp)->p_comm, (pr)->ps_comm, sizeof((kp)->p_comm)); \ + strlcpy((kp)->p_login, (sess)->s_login, \ + _FILL_KPROC_MIN(sizeof((kp)->p_login), sizeof((sess)->s_login))); \ + \ + if ((sess)->s_ttyvp) \ + (kp)->p_eflag |= EPROC_CTTY; \ + if ((pr)->ps_uvpaths) \ + (kp)->p_eflag |= EPROC_UNVEIL; \ + if ((pr)->ps_uvdone || \ + (((pr)->ps_flags & PS_PLEDGE) && \ + ((pr)->ps_pledge & PLEDGE_UNVEIL) == 0)) \ + (kp)->p_eflag |= EPROC_LKUNVEIL; \ + \ + if (((pr)->ps_flags & (PS_EMBRYO | PS_ZOMBIE)) == 0) { \ + if ((vm) != NULL) { \ + (kp)->p_vm_rssize = (vm)->vm_rssize; \ + (kp)->p_vm_tsize = (vm)->vm_tsize; \ + (kp)->p_vm_dsize = (vm)->vm_dused; \ + (kp)->p_vm_ssize = (vm)->vm_ssize; \ + } \ + (kp)->p_addr = PTRTOINT64((p)->p_addr); \ + (kp)->p_stat = (p)->p_stat; \ + (kp)->p_slptime = (p)->p_slptime; \ + (kp)->p_holdcnt = 1; \ + (kp)->p_priority = _getcompatprio(p); \ + (kp)->p_usrpri = (p)->p_usrpri; \ + if ((p)->p_wchan && (p)->p_wmesg) \ + copy_str((kp)->p_wmesg, (p)->p_wmesg, \ + sizeof((kp)->p_wmesg)); \ + if (show_addresses) \ + (kp)->p_wchan = PTRTOINT64((p)->p_wchan); \ + } \ + \ + if (((pr)->ps_flags & PS_ZOMBIE) == 0) { \ + struct timeval __tv; \ + \ + (kp)->p_uvalid = 1; \ + \ + (kp)->p_uru_maxrss = (p)->p_ru.ru_maxrss; \ + (kp)->p_uru_ixrss = (p)->p_ru.ru_ixrss; \ + (kp)->p_uru_idrss = (p)->p_ru.ru_idrss; \ + (kp)->p_uru_isrss = (p)->p_ru.ru_isrss; \ + (kp)->p_uru_minflt = (p)->p_ru.ru_minflt; \ + (kp)->p_uru_majflt = (p)->p_ru.ru_majflt; \ + (kp)->p_uru_nswap = (p)->p_ru.ru_nswap; \ + (kp)->p_uru_inblock = (p)->p_ru.ru_inblock; \ + (kp)->p_uru_oublock = (p)->p_ru.ru_oublock; \ + (kp)->p_uru_msgsnd = (p)->p_ru.ru_msgsnd; \ + (kp)->p_uru_msgrcv = (p)->p_ru.ru_msgrcv; \ + (kp)->p_uru_nsignals = (p)->p_ru.ru_nsignals; \ + (kp)->p_uru_nvcsw = (p)->p_ru.ru_nvcsw; \ + (kp)->p_uru_nivcsw = (p)->p_ru.ru_nivcsw; \ + \ + timeradd(&(pr)->ps_cru.ru_utime, \ + &(pr)->ps_cru.ru_stime, &__tv); \ + (kp)->p_uctime_sec = __tv.tv_sec; \ + (kp)->p_uctime_usec = __tv.tv_usec; \ + } \ + \ + (kp)->p_cpuid = KI_NOCPU; \ + (kp)->p_rtableid = (pr)->ps_rtableid; \ +} while (0) + +#endif /* defined(_KERNEL) || defined(_LIBKVM) */ + + +/* + * kern.file returns an array of these structures, which are designed + * both to be immune to 32/64 bit emulation issues and to + * provide backwards compatibility. The order differs slightly from + * that of the real struct file, and some fields are taken from other + * structures (struct vnode, struct proc) in order to make the file + * information more useful. + */ +#define KERN_FILE_BYFILE 1 +#define KERN_FILE_BYPID 2 +#define KERN_FILE_BYUID 3 +#define KERN_FILESLOP 10 + +#define KERN_FILE_TEXT -1 +#define KERN_FILE_CDIR -2 +#define KERN_FILE_RDIR -3 +#define KERN_FILE_TRACE -4 + +#define KI_MNAMELEN 96 /* rounded up from 90 */ +#define KI_UNPPATHLEN 104 + +struct kinfo_file { + uint64_t f_fileaddr; /* PTR: address of struct file */ + uint32_t f_flag; /* UINT: flags (see fcntl.h) */ + uint32_t f_iflags; /* UINT: internal flags */ + uint32_t f_type; /* INT: descriptor type */ + uint32_t f_count; /* UINT: reference count */ + uint32_t f_msgcount; /* UINT: references from msg queue */ + uint32_t f_usecount; /* INT: number active users */ + uint64_t f_ucred; /* PTR: creds for descriptor */ + uint32_t f_uid; /* UID_T: descriptor credentials */ + uint32_t f_gid; /* GID_T: descriptor credentials */ + uint64_t f_ops; /* PTR: address of fileops */ + uint64_t f_offset; /* OFF_T: offset */ + uint64_t f_data; /* PTR: descriptor data */ + uint64_t f_rxfer; /* UINT64: number of read xfers */ + uint64_t f_rwfer; /* UINT64: number of write xfers */ + uint64_t f_seek; /* UINT64: number of seek operations */ + uint64_t f_rbytes; /* UINT64: total bytes read */ + uint64_t f_wbytes; /* UINT64: total bytes written */ + + /* information about the vnode associated with this file */ + uint64_t v_un; /* PTR: socket, specinfo, etc */ + uint32_t v_type; /* ENUM: vnode type */ + uint32_t v_tag; /* ENUM: type of underlying data */ + uint32_t v_flag; /* UINT: vnode flags */ + uint32_t va_rdev; /* DEV_T: raw device */ + uint64_t v_data; /* PTR: private data for fs */ + uint64_t v_mount; /* PTR: mount info for fs */ + uint64_t va_fileid; /* LONG: file id */ + uint64_t va_size; /* UINT64_T: file size in bytes */ + uint32_t va_mode; /* MODE_T: file access mode and type */ + uint32_t va_fsid; /* DEV_T: filesystem device */ + char f_mntonname[KI_MNAMELEN]; + + /* socket information */ + uint32_t so_type; /* SHORT: socket type */ + uint32_t so_state; /* SHORT: socket state */ + uint64_t so_pcb; /* PTR: socket pcb */ + /* for non-root: -1 if not NULL */ + uint32_t so_protocol; /* SHORT: socket protocol type */ + uint32_t so_family; /* INT: socket domain family */ + uint64_t inp_ppcb; /* PTR: pointer to per-protocol pcb */ + uint32_t inp_lport; /* SHORT: local inet port */ + uint32_t inp_laddru[4]; /* STRUCT: local inet addr */ + uint32_t inp_fport; /* SHORT: foreign inet port */ + uint32_t inp_faddru[4]; /* STRUCT: foreign inet addr */ + uint64_t unp_conn; /* PTR: connected socket cntrl block */ + + /* pipe information */ + uint64_t pipe_peer; /* PTR: link with other direction */ + uint32_t pipe_state; /* UINT: pipe status info */ + + /* kqueue information */ + uint32_t kq_count; /* INT: number of pending events */ + uint32_t kq_state; /* INT: kqueue status information */ + + uint32_t __unused1; /* INT: unused */ + + /* process information when retrieved via KERN_FILE_BY[PU]ID */ + uint32_t p_pid; /* PID_T: process id */ + int32_t fd_fd; /* INT: descriptor number */ + uint32_t fd_ofileflags; /* CHAR: open file flags */ + uint32_t p_uid; /* UID_T: process credentials */ + uint32_t p_gid; /* GID_T: process credentials */ + uint32_t p_tid; /* PID_T: thread id */ + char p_comm[KI_MAXCOMLEN]; + + /* more socket information */ + uint32_t inp_rtableid; /* UINT: Routing table identifier. */ + uint64_t so_splice; /* PTR: f_data of spliced socket */ + int64_t so_splicelen; /* OFF_T: already spliced count or */ + /* -1 if this is target of splice */ + uint64_t so_rcv_cc; /* LONG: chars in receive buf */ + uint64_t so_snd_cc; /* LONG: chars in send buf */ + uint64_t unp_refs; /* PTR: connected sockets */ + uint64_t unp_nextref; /* PTR: link to next connected socket */ + uint64_t unp_addr; /* PTR: address of the socket address */ + char unp_path[KI_UNPPATHLEN]; + uint32_t inp_proto; /* CHAR: raw protocol id */ + uint32_t t_state; /* SHORT: tcp state */ + uint64_t t_rcv_wnd; /* ULONG: tcp receive window */ + uint64_t t_snd_wnd; /* ULONG: tcp send window */ + uint64_t t_snd_cwnd; /* ULONG: congestion-controlled win */ + + uint32_t va_nlink; /* NLINK_T: number of references to file */ +}; + +/* + * KERN_INTRCNT + */ +#define KERN_INTRCNT_NUM 1 /* int: # intrcnt */ +#define KERN_INTRCNT_CNT 2 /* node: intrcnt */ +#define KERN_INTRCNT_NAME 3 /* node: names */ +#define KERN_INTRCNT_VECTOR 4 /* node: interrupt vector # */ +#define KERN_INTRCNT_MAXID 5 + +#define CTL_KERN_INTRCNT_NAMES { \ + { 0, 0 }, \ + { "nintrcnt", CTLTYPE_INT }, \ + { "intrcnt", CTLTYPE_NODE }, \ + { "intrname", CTLTYPE_NODE }, \ +} + +/* + * KERN_WATCHDOG + */ +#define KERN_WATCHDOG_PERIOD 1 /* int: watchdog period */ +#define KERN_WATCHDOG_AUTO 2 /* int: automatic tickle */ +#define KERN_WATCHDOG_MAXID 3 + +#define CTL_KERN_WATCHDOG_NAMES { \ + { 0, 0 }, \ + { "period", CTLTYPE_INT }, \ + { "auto", CTLTYPE_INT }, \ +} + +/* + * KERN_TIMECOUNTER + */ +#define KERN_TIMECOUNTER_TICK 1 /* int: number of revolutions */ +#define KERN_TIMECOUNTER_TIMESTEPWARNINGS 2 /* int: log a warning when time changes */ +#define KERN_TIMECOUNTER_HARDWARE 3 /* string: tick hardware used */ +#define KERN_TIMECOUNTER_CHOICE 4 /* string: tick hardware used */ +#define KERN_TIMECOUNTER_MAXID 5 + +#define CTL_KERN_TIMECOUNTER_NAMES { \ + { 0, 0 }, \ + { "tick", CTLTYPE_INT }, \ + { "timestepwarnings", CTLTYPE_INT }, \ + { "hardware", CTLTYPE_STRING }, \ + { "choice", CTLTYPE_STRING }, \ +} + +/* + * KERN_CLOCKINTR + */ +#define KERN_CLOCKINTR_STATS 1 /* struct: stats */ +#define KERN_CLOCKINTR_MAXID 2 + +#define CTL_KERN_CLOCKINTR_NAMES { \ + { 0, 0 }, \ + { "stats", CTLTYPE_STRUCT }, \ +} + +/* + * CTL_HW identifiers + */ +#define HW_MACHINE 1 /* string: machine class */ +#define HW_MODEL 2 /* string: specific machine model */ +#define HW_NCPU 3 /* int: number of configured cpus */ +#define HW_BYTEORDER 4 /* int: machine byte order */ +#define HW_PHYSMEM 5 /* int: total memory */ +#define HW_USERMEM 6 /* int: non-kernel memory */ +#define HW_PAGESIZE 7 /* int: software page size */ +#define HW_DISKNAMES 8 /* strings: disk drive names */ +#define HW_DISKSTATS 9 /* struct: diskstats[] */ +#define HW_DISKCOUNT 10 /* int: number of disks */ +#define HW_SENSORS 11 /* node: hardware monitors */ +#define HW_CPUSPEED 12 /* get CPU frequency */ +#define HW_SETPERF 13 /* set CPU performance % */ +#define HW_VENDOR 14 /* string: vendor name */ +#define HW_PRODUCT 15 /* string: product name */ +#define HW_VERSION 16 /* string: hardware version */ +#define HW_SERIALNO 17 /* string: hardware serial number */ +#define HW_UUID 18 /* string: universal unique id */ +#define HW_PHYSMEM64 19 /* quad: total memory */ +#define HW_USERMEM64 20 /* quad: non-kernel memory */ +#define HW_NCPUFOUND 21 /* int: number of cpus found */ +#define HW_ALLOWPOWERDOWN 22 /* allow power button shutdown */ +#define HW_PERFPOLICY 23 /* set performance policy */ +#define HW_SMT 24 /* int: enable SMT/HT/CMT */ +#define HW_NCPUONLINE 25 /* int: number of cpus being used */ +#define HW_POWER 26 /* int: machine has wall-power */ +#define HW_BATTERY 27 /* node: battery */ +#define HW_UCOMNAMES 28 /* strings: ucom names */ +#define HW_MAXID 29 /* number of valid hw ids */ + +#define CTL_HW_NAMES { \ + { 0, 0 }, \ + { "machine", CTLTYPE_STRING }, \ + { "model", CTLTYPE_STRING }, \ + { "ncpu", CTLTYPE_INT }, \ + { "byteorder", CTLTYPE_INT }, \ + { "gap", 0 }, \ + { "gap", 0 }, \ + { "pagesize", CTLTYPE_INT }, \ + { "disknames", CTLTYPE_STRING }, \ + { "diskstats", CTLTYPE_STRUCT }, \ + { "diskcount", CTLTYPE_INT }, \ + { "sensors", CTLTYPE_NODE}, \ + { "cpuspeed", CTLTYPE_INT }, \ + { "setperf", CTLTYPE_INT }, \ + { "vendor", CTLTYPE_STRING }, \ + { "product", CTLTYPE_STRING }, \ + { "version", CTLTYPE_STRING }, \ + { "serialno", CTLTYPE_STRING }, \ + { "uuid", CTLTYPE_STRING }, \ + { "physmem", CTLTYPE_QUAD }, \ + { "usermem", CTLTYPE_QUAD }, \ + { "ncpufound", CTLTYPE_INT }, \ + { "allowpowerdown", CTLTYPE_INT }, \ + { "perfpolicy", CTLTYPE_STRING }, \ + { "smt", CTLTYPE_INT }, \ + { "ncpuonline", CTLTYPE_INT }, \ + { "power", CTLTYPE_INT }, \ + { "battery", CTLTYPE_NODE }, \ + { "ucomnames", CTLTYPE_STRING }, \ +} + +/* + * HW_BATTERY + */ +#define HW_BATTERY_CHARGEMODE 1 /* int: battery charging mode */ +#define HW_BATTERY_CHARGESTART 2 /* int: battery start charge percent */ +#define HW_BATTERY_CHARGESTOP 3 /* int: battery stop charge percent */ +#define HW_BATTERY_MAXID 4 + +#define CTL_HW_BATTERY_NAMES { \ + { 0, 0 }, \ + { "chargemode", CTLTYPE_INT }, \ + { "chargestart", CTLTYPE_INT }, \ + { "chargestop", CTLTYPE_INT }, \ +} + +/* + * CTL_DEBUG definitions + * + * Second level identifier specifies which debug variable. + * Third level identifier specifies which structure component. + */ +#define CTL_DEBUG_NAME 0 /* string: variable name */ +#define CTL_DEBUG_VALUE 1 /* int: variable value */ +#define CTL_DEBUG_MAXID 20 + +#ifdef _KERNEL +#ifdef DEBUG_SYSCTL +/* + * CTL_DEBUG variables. + * + * These are declared as separate variables so that they can be + * individually initialized at the location of their associated + * variable. The loader prevents multiple use by issuing errors + * if a variable is initialized in more than one place. They are + * aggregated into an array in debug_sysctl(), so that it can + * conveniently locate them when queried. If more debugging + * variables are added, they must also be declared here and also + * entered into the array. + */ +struct ctldebug { + char *debugname; /* name of debugging variable */ + int *debugvar; /* pointer to debugging variable */ +}; +#endif /* DEBUG_SYSCTL */ + +/* + * Exported sysctl variable with valid bounds. Both bounds are inclusive to + * allow full range of values. + */ +struct sysctl_bounded_args { + int mib; /* identifier shared with userspace as a CTL_ #define */ + int *var; /* never NULL */ + int minimum; /* checking is disabled if minimum == maximum */ + int maximum; /* read-only variable if minimum > maximum */ +}; + +/* Special case minimum,maximum marker for sysctl_bounded_args. */ +#define SYSCTL_INT_READONLY 1,0 + +/* + * Internal sysctl function calling convention: + * + * (*sysctlfn)(name, namelen, oldval, oldlenp, newval, newlen); + * + * The name parameter points at the next component of the name to be + * interpreted. The namelen parameter is the number of integers in + * the name. + */ +typedef int (sysctlfn)(int *, u_int, void *, size_t *, void *, size_t, struct proc *); + +extern struct rwlock sysctl_lock; + +int sysctl_vslock(void *, size_t); +void sysctl_vsunlock(void *, size_t); + +int sysctl_int_lower(void *, size_t *, void *, size_t, int *); +int sysctl_int(void *, size_t *, void *, size_t, int *); +int sysctl_rdint(void *, size_t *, void *, int); +int sysctl_securelevel_int(void *, size_t *, void *, size_t, int *); +int sysctl_int_bounded(void *, size_t *, void *, size_t, int *, int, int); +int sysctl_bounded_arr(const struct sysctl_bounded_args *, u_int, + int *, u_int, void *, size_t *, void *, size_t); +int sysctl_rdquad(void *, size_t *, void *, int64_t); +int sysctl_string(void *, size_t *, void *, size_t, char *, size_t); +int sysctl_tstring(void *, size_t *, void *, size_t, char *, size_t); +int sysctl__string(void *, size_t *, void *, size_t, char *, size_t, int); +int sysctl_rdstring(void *, size_t *, void *, const char *); +int sysctl_rdstruct(void *, size_t *, void *, const void *, size_t); +int sysctl_struct(void *, size_t *, void *, size_t, void *, size_t); +int sysctl_file(int *, u_int, char *, size_t *, struct proc *); +int sysctl_doproc(int *, u_int, char *, size_t *); +struct mbuf_queue; +int sysctl_mq(int *, u_int, void *, size_t *, void *, size_t, + struct mbuf_queue *); +struct rtentry; +int sysctl_dumpentry(const struct rtentry *, void *, unsigned int); +int sysctl_rtable(int *, u_int, void *, size_t *, void *, size_t); +int sysctl_clockrate(char *, size_t *, void *); +#if defined(GPROF) || defined(DDBPROF) +int sysctl_doprof(int *, u_int, void *, size_t *, void *, size_t); +#endif +int sysctl_dopool(int *, u_int, char *, size_t *); + +int kern_sysctl(int *, u_int, void *, size_t *, void *, size_t, + struct proc *); +int hw_sysctl(int *, u_int, void *, size_t *, void *, size_t, + struct proc *); +#ifdef DEBUG_SYSCTL +int debug_sysctl(int *, u_int, void *, size_t *, void *, size_t, + struct proc *); +#endif +int net_sysctl(int *, u_int, void *, size_t *, void *, size_t, + struct proc *); +int cpu_sysctl(int *, u_int, void *, size_t *, void *, size_t, + struct proc *); +int vfs_sysctl(int *, u_int, void *, size_t *, void *, size_t, + struct proc *); +int sysctl_sysvipc(int *, u_int, void *, size_t *); +int sysctl_wdog(int *, u_int, void *, size_t *, void *, size_t); + +extern int (*cpu_cpuspeed)(int *); +extern void (*cpu_setperf)(int); + +int net_ifiq_sysctl(int *, u_int, void *, size_t *, void *, size_t); +int bpf_sysctl(int *, u_int, void *, size_t *, void *, size_t); +int pflow_sysctl(int *, u_int, void *, size_t *, void *, size_t); +int pipex_sysctl(int *, u_int, void *, size_t *, void *, size_t); +int mpls_sysctl(int *, u_int, void *, size_t *, void *, size_t); +int pf_sysctl(void *, size_t *, void *, size_t); +int uipc_sysctl(int *, u_int, void *, size_t *, void *, size_t); + +#else /* !_KERNEL */ + +__BEGIN_DECLS +int sysctl(const int *, u_int, void *, size_t *, void *, size_t); +__END_DECLS +#endif /* _KERNEL */ +#endif /* !_SYS_SYSCTL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/syslimits.h b/lib/libc/include/generic-openbsd/sys/syslimits.h new file mode 100644 index 0000000000..976941871c --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/syslimits.h @@ -0,0 +1,83 @@ +/* $OpenBSD: syslimits.h,v 1.16 2024/08/02 01:53:21 guenther Exp $ */ +/* $NetBSD: syslimits.h,v 1.12 1995/10/05 05:26:19 thorpej Exp $ */ + +/* + * Copyright (c) 1988, 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. + * + * @(#)syslimits.h 8.1 (Berkeley) 6/2/93 + */ + +#include + +#if __POSIX_VISIBLE || __XPG_VISIBLE || __BSD_VISIBLE +#define ARG_MAX (512 * 1024) /* max bytes for an exec function */ +#define CHILD_MAX 80 /* max simultaneous processes */ +#define LINK_MAX 32767 /* max file link count */ +#define MAX_CANON 255 /* max bytes in term canon input line */ +#define MAX_INPUT 255 /* max bytes in terminal input */ +#define NAME_MAX 255 /* max bytes in a file name */ +#define NGROUPS_MAX 16 /* max supplemental group id's */ +#define OPEN_MAX 64 /* max open files per process */ +#define PATH_MAX 1024 /* max bytes in pathname */ +#define PIPE_BUF 512 /* max bytes for atomic pipe writes */ +#define SYMLINK_MAX PATH_MAX /* max bytes in a symbolic link */ +#define SYMLOOP_MAX 32 /* max symlinks per path (for loops) */ + +#define BC_BASE_MAX INT_MAX /* max ibase/obase values in bc(1) */ +#define BC_DIM_MAX 65535 /* max array elements in bc(1) */ +#define BC_SCALE_MAX INT_MAX /* max scale value in bc(1) */ +#define BC_STRING_MAX INT_MAX /* max const string length in bc(1) */ +#define COLL_WEIGHTS_MAX 2 /* max weights for order keyword */ +#define EXPR_NEST_MAX 32 /* max expressions nested in expr(1) */ +#define LINE_MAX 2048 /* max bytes in an input line */ +#ifndef RE_DUP_MAX +#define RE_DUP_MAX 255 /* max RE's in interval notation */ +#define SEM_VALUE_MAX UINT_MAX /* max value of a sem_* semaphore */ +#endif + +#if __XPG_VISIBLE +#define IOV_MAX 1024 /* max # of iov's (readv,sendmsg,etc) */ +#define NZERO 20 /* default "nice" */ +#endif /* __XPG_VISIBLE */ + +#endif /* __POSIX_VISIBLE || __XPG_VISIBLE || __BSD_VISIBLE */ + +#if __XPG_VISIBLE >= 500 || __POSIX_VISIBLE >= 199506 || __BSD_VISIBLE +#define TTY_NAME_MAX 260 /* max tty device name length w/ NUL */ +#define LOGIN_NAME_MAX 32 /* max login name length w/ NUL */ +#endif /* __XPG_VISIBLE >= 500 || __POSIX_VISIBLE >= 199506 || __BSD_VISIBLE */ + +#if __POSIX_VISIBLE >= 200112 +#define HOST_NAME_MAX 255 /* max hostname length w/o NUL */ +#endif + +#if __POSIX_VISIBLE >= 202405 +#define GETENTROPY_MAX 256 /* max bytes from getentropy(2) */ +#endif + +#define _MAXCOMLEN 24 /* includes NUL */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/syslog.h b/lib/libc/include/generic-openbsd/sys/syslog.h new file mode 100644 index 0000000000..b4af686209 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/syslog.h @@ -0,0 +1,220 @@ +/* $OpenBSD: syslog.h,v 1.19 2023/04/27 23:16:18 gnezdo Exp $ */ +/* $NetBSD: syslog.h,v 1.14 1996/04/03 20:46:44 christos Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1988, 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. + * + * @(#)syslog.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _SYS_SYSLOG_H_ +#define _SYS_SYSLOG_H_ + +#define _PATH_LOG "/dev/log" + +#define LIOCSFD _IOW('l', 127, int) /* set sendsyslog() fd */ + +#define LOG_MAXLINE 8192 /* maximum line length */ + +/* + * priorities/facilities are encoded into a single 32-bit quantity, where the + * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility + * (0-big number). Both the priorities and the facilities map roughly + * one-to-one to strings in the syslogd(8) source code. This mapping is + * included in this file. + * + * priorities (these are ordered) + */ +#define LOG_EMERG 0 /* system is unusable */ +#define LOG_ALERT 1 /* action must be taken immediately */ +#define LOG_CRIT 2 /* critical conditions */ +#define LOG_ERR 3 /* error conditions */ +#define LOG_WARNING 4 /* warning conditions */ +#define LOG_NOTICE 5 /* normal but significant condition */ +#define LOG_INFO 6 /* informational */ +#define LOG_DEBUG 7 /* debug-level messages */ + +#define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */ + /* extract priority */ +#define LOG_PRI(p) ((p) & LOG_PRIMASK) + +#ifdef SYSLOG_NAMES +#define INTERNAL_NOPRI 0x10 /* the "no priority" priority */ + /* mark "facility" */ +#define INTERNAL_MARK (LOG_NFACILITIES<<3) +typedef struct _code { + char *c_name; + int c_val; +} CODE; + +CODE prioritynames[] = { + { "alert", LOG_ALERT }, + { "crit", LOG_CRIT }, + { "debug", LOG_DEBUG }, + { "emerg", LOG_EMERG }, + { "err", LOG_ERR }, + { "error", LOG_ERR }, /* DEPRECATED */ + { "info", LOG_INFO }, + { "none", INTERNAL_NOPRI }, /* INTERNAL */ + { "notice", LOG_NOTICE }, + { "panic", LOG_EMERG }, /* DEPRECATED */ + { "warn", LOG_WARNING }, /* DEPRECATED */ + { "warning", LOG_WARNING }, + { NULL, -1 }, +}; +#endif + +/* facility codes */ +#define LOG_KERN (0<<3) /* kernel messages */ +#define LOG_USER (1<<3) /* random user-level messages */ +#define LOG_MAIL (2<<3) /* mail system */ +#define LOG_DAEMON (3<<3) /* system daemons */ +#define LOG_AUTH (4<<3) /* security/authorization messages */ +#define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */ +#define LOG_LPR (6<<3) /* line printer subsystem */ +#define LOG_NEWS (7<<3) /* network news subsystem */ +#define LOG_UUCP (8<<3) /* UUCP subsystem */ +#define LOG_CRON (9<<3) /* clock daemon */ +#define LOG_AUTHPRIV (10<<3) /* security/authorization messages (private) */ +#define LOG_FTP (11<<3) /* ftp daemon */ + + /* other codes through 15 reserved for system use */ +#define LOG_LOCAL0 (16<<3) /* reserved for local use */ +#define LOG_LOCAL1 (17<<3) /* reserved for local use */ +#define LOG_LOCAL2 (18<<3) /* reserved for local use */ +#define LOG_LOCAL3 (19<<3) /* reserved for local use */ +#define LOG_LOCAL4 (20<<3) /* reserved for local use */ +#define LOG_LOCAL5 (21<<3) /* reserved for local use */ +#define LOG_LOCAL6 (22<<3) /* reserved for local use */ +#define LOG_LOCAL7 (23<<3) /* reserved for local use */ + +#define LOG_NFACILITIES 24 /* current number of facilities */ +#define LOG_FACMASK 0x03f8 /* mask to extract facility part */ + /* facility of pri */ +#define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3) + +#ifdef SYSLOG_NAMES +CODE facilitynames[] = { + { "auth", LOG_AUTH }, + { "authpriv", LOG_AUTHPRIV }, + { "cron", LOG_CRON }, + { "daemon", LOG_DAEMON }, + { "ftp", LOG_FTP }, + { "kern", LOG_KERN }, + { "lpr", LOG_LPR }, + { "mail", LOG_MAIL }, + { "mark", INTERNAL_MARK }, /* INTERNAL */ + { "news", LOG_NEWS }, + { "security", LOG_AUTH }, /* DEPRECATED */ + { "syslog", LOG_SYSLOG }, + { "user", LOG_USER }, + { "uucp", LOG_UUCP }, + { "local0", LOG_LOCAL0 }, + { "local1", LOG_LOCAL1 }, + { "local2", LOG_LOCAL2 }, + { "local3", LOG_LOCAL3 }, + { "local4", LOG_LOCAL4 }, + { "local5", LOG_LOCAL5 }, + { "local6", LOG_LOCAL6 }, + { "local7", LOG_LOCAL7 }, + { NULL, -1 }, +}; +#endif + +/* Used by reentrant functions */ + +struct syslog_data { + int log_stat; + const char *log_tag; + int log_fac; + int log_mask; +}; + +#define SYSLOG_DATA_INIT {0, (const char *)0, LOG_USER, 0xff} + +#ifdef _KERNEL +#define LOG_PRINTF -1 /* pseudo-priority to indicate use of printf */ +#endif + +/* + * arguments to setlogmask. + */ +#define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */ +#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */ + +/* + * Option flags for openlog. + * + * LOG_ODELAY no longer does anything. + * LOG_NDELAY is the inverse of what it used to be. + */ +#define LOG_PID 0x01 /* log the pid with each message */ +#define LOG_CONS 0x02 /* log on the console if errors in sending */ +#define LOG_ODELAY 0x04 /* delay open until first syslog() (default) */ +#define LOG_NDELAY 0x08 /* don't delay open */ +#define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */ +#define LOG_PERROR 0x20 /* log to stderr as well */ + +#ifndef _KERNEL + +/* + * Don't use va_list in the vsyslog() prototype. Va_list is typedef'd + * in . Including it here may collide with the utility's includes. + * It's unreasonable for utilities to have to include it to include , + * so we get __va_list from and use it. + */ +#include +#include + +__BEGIN_DECLS +void closelog(void); +void openlog(const char *, int, int); +int setlogmask(int); +void syslog(int, const char *, ...) + __attribute__((__format__(__syslog__,2,3))); +void vsyslog(int, const char *, __va_list); +void closelog_r(struct syslog_data *); +void openlog_r(const char *, int, int, struct syslog_data *); +int setlogmask_r(int, struct syslog_data *); +void syslog_r(int, struct syslog_data *, const char *, ...) + __attribute__((__format__(__syslog__,3,4))); +void vsyslog_r(int, struct syslog_data *, const char *, __va_list); +int sendsyslog(const char *, __size_t, int); +__END_DECLS + +#else /* !_KERNEL */ + +void logpri(int); +void log(int, const char *, ...) + __attribute__((__format__(__kprintf__,2,3))); +int addlog(const char *, ...) + __attribute__((__format__(__kprintf__,1,2))); +void logwakeup(void); + +#endif /* !_KERNEL */ +#endif /* !_SYS_SYSLOG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/systm.h b/lib/libc/include/generic-openbsd/sys/systm.h new file mode 100644 index 0000000000..1a1aad8230 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/systm.h @@ -0,0 +1,449 @@ +/* $OpenBSD: systm.h,v 1.177 2025/07/28 05:08:35 dlg Exp $ */ +/* $NetBSD: systm.h,v 1.50 1996/06/09 04:55:09 briggs Exp $ */ + +/*- + * Copyright (c) 1982, 1988, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)systm.h 8.4 (Berkeley) 2/23/94 + */ + +#ifndef __SYSTM_H__ +#define __SYSTM_H__ + +#include +#include + +/* + * The `securelevel' variable controls the security level of the system. + * It can only be decreased by process 1 (/sbin/init). + * + * Security levels are as follows: + * -1 permanently insecure mode - always run system in level 0 mode. + * 0 insecure mode - immutable and append-only flags may be turned off. + * All devices may be read or written subject to permission modes. + * 1 secure mode - immutable and append-only flags may not be changed; + * raw disks of mounted filesystems, /dev/mem, and /dev/kmem are + * read-only. + * 2 highly secure mode - same as (1) plus raw disks are always + * read-only whether mounted or not. This level precludes tampering + * with filesystems by unmounting them, but also inhibits running + * newfs while the system is secured. + * + * In normal operation, the system runs in level 0 mode while single user + * and in level 1 mode while multiuser. If level 2 mode is desired while + * running multiuser, it can be set in the multiuser startup script + * (/etc/rc.local) using sysctl(1). If it is desired to run the system + * in level 0 mode while multiuser, initialize the variable securelevel + * in /sys/kern/kern_sysctl.c to -1. Note that it is NOT initialized to + * zero as that would allow the vmunix binary to be patched to -1. + * Without initialization, securelevel loads in the BSS area which only + * comes into existence when the kernel is loaded and hence cannot be + * patched by a stalking hacker. + */ +extern int securelevel; /* system security level */ +extern const char *panicstr; /* panic message */ +extern const char version[]; /* system version */ +extern const char copyright[]; /* system copyright */ +extern const char ostype[]; +extern const char osversion[]; +extern const char osrelease[]; +extern int cold; /* cold start flag initialized in locore */ +extern int db_active; /* running currently inside ddb(4) */ + +extern char *hw_vendor; /* sysctl hw.vendor */ +extern char *hw_prod; /* sysctl hw.product */ +extern char *hw_uuid; /* sysctl hw.uuid */ +extern char *hw_serial; /* sysctl hw.serialno */ +extern char *hw_ver; /* sysctl hw.version */ + +extern int ncpus; /* number of CPUs used */ +extern int ncpusfound; /* number of CPUs found */ +extern int nblkdev; /* number of entries in bdevsw */ +extern int nchrdev; /* number of entries in cdevsw */ + +extern int physmem; /* physical memory */ + +extern dev_t dumpdev; /* dump device */ +extern long dumplo; /* offset into dumpdev */ + +extern dev_t rootdev; /* root device */ +extern u_char bootduid[8]; /* boot device disklabel uid */ +extern u_char rootduid[8]; /* root device disklabel uid */ +extern struct vnode *rootvp; /* vnode equivalent to above */ +extern struct device *rootdv; /* device equivalent to above */ + +extern dev_t swapdev; /* swapping device */ +extern struct vnode *swapdev_vp;/* vnode equivalent to above */ + +extern int nowake; /* dead wakeup(9) channel */ + +#ifdef MP_LOCKDEBUG +extern long __mp_lock_spinout; +#endif + +struct proc; +struct process; +#define curproc curcpu()->ci_curproc + +typedef int sy_call_t(struct proc *, void *, register_t *); + +extern const struct sysent { /* system call table */ + short sy_narg; /* number of args */ + short sy_argsize; /* total size of arguments */ + int sy_flags; + sy_call_t *sy_call; /* implementing function */ +} sysent[]; + +#define SY_NOLOCK 0x01 + +#if _BYTE_ORDER == _BIG_ENDIAN +#define SCARG(p, k) ((p)->k.be.datum) /* get arg from args pointer */ +#elif _BYTE_ORDER == _LITTLE_ENDIAN +#define SCARG(p, k) ((p)->k.le.datum) /* get arg from args pointer */ +#else +#error "what byte order is this machine?" +#endif + +#if defined(_KERNEL) && defined(SYSCALL_DEBUG) +void scdebug_call(struct proc *p, register_t code, const register_t retval[]); +void scdebug_ret(struct proc *p, register_t code, int error, + const register_t retval[]); +#endif /* _KERNEL && SYSCALL_DEBUG */ + +extern int boothowto; /* reboot flags, from console subsystem */ + +extern void (*v_putc)(int); /* Virtual console putc routine */ + +/* + * General function declarations. + */ +int nullop(void *); +int enodev(void); +int enosys(void); +int enoioctl(void); +int enxio(void); +int eopnotsupp(void *); + +void *hashinit(int, int, int, u_long *); +void hashfree(void *, int, int); +int sys_nosys(struct proc *, void *, register_t *); + +void panic(const char *, ...) + __attribute__((__noreturn__,__format__(__kprintf__,1,2))); +void __assert(const char *, const char *, int, const char *) + __attribute__((__noreturn__)); +int printf(const char *, ...) + __attribute__((__format__(__kprintf__,1,2))); +void uprintf(const char *, ...) + __attribute__((__format__(__kprintf__,1,2))); +int vprintf(const char *, va_list) + __attribute__((__format__(__kprintf__,1,0))); +int vsnprintf(char *, size_t, const char *, va_list) + __attribute__((__format__(__kprintf__,3,0))); +int snprintf(char *buf, size_t, const char *, ...) + __attribute__((__format__(__kprintf__,3,4))); +struct tty; +void ttyprintf(struct tty *, const char *, ...) + __attribute__((__format__(__kprintf__,2,3))); + +void splassert_fail(int, int, const char *); +extern int splassert_ctl; + +void assertwaitok(void); + +void tablefull(const char *); + +int kcopy(const void *, void *, size_t) + __attribute__ ((__bounded__(__buffer__,1,3))) + __attribute__ ((__bounded__(__buffer__,2,3))); + +void bcopy(const void *, void *, size_t) + __attribute__ ((__bounded__(__buffer__,1,3))) + __attribute__ ((__bounded__(__buffer__,2,3))); +void bzero(void *, size_t) + __attribute__ ((__bounded__(__buffer__,1,2))); +void explicit_bzero(void *, size_t) + __attribute__ ((__bounded__(__buffer__,1,2))); +int bcmp(const void *, const void *, size_t); +void *memcpy(void *, const void *, size_t) + __attribute__ ((__bounded__(__buffer__,1,3))) + __attribute__ ((__bounded__(__buffer__,2,3))); +void *memmove(void *, const void *, size_t) + __attribute__ ((__bounded__(__buffer__,1,3))) + __attribute__ ((__bounded__(__buffer__,2,3))); +void *memset(void *, int, size_t) + __attribute__ ((__bounded__(__buffer__,1,3))); + +int copyinstr(const void *, void *, size_t, size_t *) + __attribute__ ((__bounded__(__string__,2,3))); +int _copyinstr(const void *, void *, size_t, size_t *) + __attribute__ ((__bounded__(__string__,2,3))); +int copyoutstr(const void *, void *, size_t, size_t *); +int copyin(const void *, void *, size_t) + __attribute__ ((__bounded__(__buffer__,2,3))); +int _copyin(const void *, void *, size_t) + __attribute__ ((__bounded__(__buffer__,2,3))); +int copyout(const void *, void *, size_t); +int copyin32(const uint32_t *, uint32_t *); + +void random_start(int); +void enqueue_randomness(unsigned int); +void suspend_randomness(void); +void resume_randomness(char *, size_t); + +struct arc4random_ctx; +void arc4random_buf(void *, size_t) + __attribute__ ((__bounded__(__buffer__,1,2))); +struct arc4random_ctx *arc4random_ctx_new(void); +void arc4random_ctx_free(struct arc4random_ctx *); +void arc4random_ctx_buf(struct arc4random_ctx *, void *, size_t); +u_int32_t arc4random(void); +u_int32_t arc4random_uniform(u_int32_t); + +struct timeval; +struct timespec; +int tvtohz(const struct timeval *); +int tstohz(const struct timespec *); +void realitexpire(void *); + +extern uint64_t hardclock_period; +extern uint64_t statclock_avg; +extern int statclock_is_randomized; + +struct clockframe; +void hardclock(struct clockframe *); + +struct clockrequest; +void statclock(struct clockrequest *, void *, void *); + +void initclocks(void); +void inittodr(time_t); +void resettodr(void); +void cpu_initclocks(void); +void cpu_startclock(void); + +void startprofclock(struct process *); +void stopprofclock(struct process *); +void setstatclockrate(int); +void prof_fork(struct process *); +void prof_exec(struct process *); +void prof_write(struct proc *); + +void start_periodic_resettodr(void); +void stop_periodic_resettodr(void); + +void sleep_setup(const volatile void *, int, const char *); +int sleep_finish(uint64_t, int); +void sleep_queue_init(void); + +struct cond; +void cond_init(struct cond *); +void cond_wait(struct cond *, const char *); +void cond_signal_handler(void *); + +static inline void +cond_signal(struct cond *c) +{ + cond_signal_handler(c); +} + +#define INFSLP UINT64_MAX +#define MAXTSLP (UINT64_MAX - 1) + +struct mutex; +struct rwlock; +void wakeup_n(const volatile void *, int); +void wakeup(const volatile void *); +#define wakeup_one(c) wakeup_n((c), 1) +int tsleep(const volatile void *, int, const char *, int); +int tsleep_nsec(const volatile void *, int, const char *, uint64_t); +int msleep(const volatile void *, struct mutex *, int, const char*, int); +int msleep_nsec(const volatile void *, struct mutex *, int, const char*, + uint64_t); +int rwsleep(const volatile void *, struct rwlock *, int, const char *, int); +int rwsleep_nsec(const volatile void *, struct rwlock *, int, const char *, + uint64_t); +void yield(void); + +void wdog_register(int (*)(void *, int), void *); +void wdog_shutdown(void *); + +/* + * Startup hooks are functions running after the scheduler has started + * but before any threads have been created or root has been mounted. + */ + +struct hook_desc { + TAILQ_ENTRY(hook_desc) hd_list; + void (*hd_fn)(void *); + void *hd_arg; +}; +TAILQ_HEAD(hook_desc_head, hook_desc); + +extern struct hook_desc_head startuphook_list; + +void *hook_establish(struct hook_desc_head *, int, void (*)(void *), void *); +void hook_disestablish(struct hook_desc_head *, void *); +void dohooks(struct hook_desc_head *, int); + +#define HOOK_REMOVE 0x01 +#define HOOK_FREE 0x02 + +#define startuphook_establish(fn, arg) \ + hook_establish(&startuphook_list, 1, (fn), (arg)) +#define startuphook_disestablish(vhook) \ + hook_disestablish(&startuphook_list, (vhook)) +#define dostartuphooks() dohooks(&startuphook_list, HOOK_REMOVE|HOOK_FREE) + +struct uio; +int uiomove(void *, size_t, struct uio *); + +#if defined(_KERNEL) + +#include + +extern struct rwlock netlock; + +/* + * Network stack data structures are, unless stated otherwise, protected + * by the NET_LOCK(). It's a single non-recursive lock for the whole + * subsystem. + */ +#define NET_LOCK() do { rw_enter_write(&netlock); } while (0) +#define NET_UNLOCK() do { rw_exit_write(&netlock); } while (0) + +/* + * Reader version of NET_LOCK(). + * The "softnet" thread should be the only thread processing packets + * without holding an exclusive lock. This is done to allow read-only + * ioctl(2) to not block. + * Shared lock can be grabbed instead of the exclusive version if no field + * protected by the NET_LOCK() is modified by the ioctl/sysctl. + * Socket system call can use shared netlock if it has additional locks + * to protect socket and pcb data structures. + */ +#define NET_LOCK_SHARED() do { rw_enter_read(&netlock); } while (0) +#define NET_UNLOCK_SHARED() do { rw_exit_read(&netlock); } while (0) + +#ifdef DIAGNOSTIC + +#define NET_ASSERT_UNLOCKED() \ +do { \ + int _s = rw_status(&netlock); \ + if ((splassert_ctl > 0) && (_s == RW_WRITE)) \ + splassert_fail(0, RW_WRITE, __func__); \ +} while (0) + +#define NET_ASSERT_LOCKED() \ +do { \ + int _s = rw_status(&netlock); \ + if ((splassert_ctl > 0) && (_s != RW_WRITE && _s != RW_READ)) \ + splassert_fail(RW_READ, _s, __func__); \ +} while (0) + +#define NET_ASSERT_LOCKED_EXCLUSIVE() \ +do { \ + int _s = rw_status(&netlock); \ + if ((splassert_ctl > 0) && (_s != RW_WRITE)) \ + splassert_fail(RW_WRITE, _s, __func__); \ +} while (0) + +#else /* DIAGNOSTIC */ +#define NET_ASSERT_UNLOCKED() do {} while (0) +#define NET_ASSERT_LOCKED() do {} while (0) +#define NET_ASSERT_LOCKED_EXCLUSIVE() do {} while (0) +#endif /* !DIAGNOSTIC */ + +__returns_twice int setjmp(label_t *); +__dead void longjmp(label_t *); +#endif + +void consinit(void); + +void cpu_startup(void); +void cpu_configure(void); +void diskconf(void); + +void powerbutton_event(void); + +int nfs_mountroot(void); +int dk_mountroot(void); +extern int (*mountroot)(void); + +#include + +#define bzero(b, n) __builtin_bzero((b), (n)) +#define memcmp(b1, b2, n) __builtin_memcmp((b1), (b2), (n)) +#define memcpy(d, s, n) __builtin_memcpy((d), (s), (n)) +#define memset(b, c, n) __builtin_memset((b), (c), (n)) +#if (defined(__GNUC__) && __GNUC__ >= 4) +#define memmove(d, s, n) __builtin_memmove((d), (s), (n)) +#endif +#if !defined(__clang__) && (defined(__GNUC__) && __GNUC__ >= 4) +#define bcmp(b1, b2, n) __builtin_bcmp((b1), (b2), (n)) +#define bcopy(s, d, n) __builtin_bcopy((s), (d), (n)) +#endif + +#if defined(DDB) +/* debugger entry points */ +void db_enter(void); /* in DDB only */ +int db_rint(int); +#endif + +#ifdef BOOT_CONFIG +void user_config(void); +#endif + +#if defined(MULTIPROCESSOR) +void _kernel_lock_init(void); +void _kernel_lock(void); +void _kernel_unlock(void); +int _kernel_lock_held(void); + +#define KERNEL_LOCK_INIT() _kernel_lock_init() +#define KERNEL_LOCK() _kernel_lock() +#define KERNEL_UNLOCK() _kernel_unlock() +#define KERNEL_ASSERT_LOCKED() KASSERT(_kernel_lock_held()) +#define KERNEL_ASSERT_UNLOCKED() KASSERT(panicstr || db_active || !_kernel_lock_held()) + +#else /* ! MULTIPROCESSOR */ + +#define KERNEL_LOCK_INIT() /* nothing */ +#define KERNEL_LOCK() /* nothing */ +#define KERNEL_UNLOCK() /* nothing */ +#define KERNEL_ASSERT_LOCKED() /* nothing */ +#define KERNEL_ASSERT_UNLOCKED() /* nothing */ + +#endif /* MULTIPROCESSOR */ + +#endif /* __SYSTM_H__ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/task.h b/lib/libc/include/generic-openbsd/sys/task.h new file mode 100644 index 0000000000..98706b00f3 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/task.h @@ -0,0 +1,62 @@ +/* $OpenBSD: task.h,v 1.18 2020/08/01 08:40:20 anton Exp $ */ + +/* + * Copyright (c) 2013 David Gwynne + * + * 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 _SYS_TASK_H_ +#define _SYS_TASK_H_ + +#include + +struct taskq; + +struct task { + TAILQ_ENTRY(task) t_entry; + void (*t_func)(void *); + void *t_arg; + unsigned int t_flags; +#if 1 /* NKCOV > 0 */ + struct process *t_process; +#endif +}; + +#define TASK_ONQUEUE 1 + +TAILQ_HEAD(task_list, task); + +#define TASKQ_MPSAFE (1 << 0) + +#define TASK_INITIALIZER(_f, _a) {{ NULL, NULL }, (_f), (_a), 0 } + +#ifdef _KERNEL +extern struct taskq *const systq; +extern struct taskq *const systqmp; + +struct taskq *taskq_create(const char *, unsigned int, int, unsigned int); +void taskq_destroy(struct taskq *); +void taskq_barrier(struct taskq *); + +void taskq_del_barrier(struct taskq *, struct task *); + +void task_set(struct task *, void (*)(void *), void *); +int task_add(struct taskq *, struct task *); +int task_del(struct taskq *, struct task *); + +#define task_pending(_t) ((_t)->t_flags & TASK_ONQUEUE) + +#endif /* _KERNEL */ + +#endif /* _SYS_TASK_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/termios.h b/lib/libc/include/generic-openbsd/sys/termios.h new file mode 100644 index 0000000000..3845c34501 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/termios.h @@ -0,0 +1,304 @@ +/* $OpenBSD: termios.h,v 1.14 2022/12/30 23:41:45 millert Exp $ */ +/* $NetBSD: termios.h,v 1.14 1996/04/09 20:55:41 cgd Exp $ */ + +/* + * Copyright (c) 1988, 1989, 1993, 1994 + * 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. + * + * @(#)termios.h 8.3 (Berkeley) 3/28/94 + */ + +#ifndef _SYS_TERMIOS_H_ +#define _SYS_TERMIOS_H_ + +#include + +/* + * Special Control Characters + * + * Index into c_cc[] character array. + * + * Name Subscript Enabled by + */ +#define VEOF 0 /* ICANON */ +#define VEOL 1 /* ICANON */ +#if __BSD_VISIBLE +#define VEOL2 2 /* ICANON */ +#endif +#define VERASE 3 /* ICANON */ +#if __BSD_VISIBLE +#define VWERASE 4 /* ICANON */ +#endif +#define VKILL 5 /* ICANON */ +#if __BSD_VISIBLE +#define VREPRINT 6 /* ICANON */ +#endif +/* 7 spare 1 */ +#define VINTR 8 /* ISIG */ +#define VQUIT 9 /* ISIG */ +#define VSUSP 10 /* ISIG */ +#if __BSD_VISIBLE +#define VDSUSP 11 /* ISIG */ +#endif +#define VSTART 12 /* IXON, IXOFF */ +#define VSTOP 13 /* IXON, IXOFF */ +#if __BSD_VISIBLE +#define VLNEXT 14 /* IEXTEN */ +#define VDISCARD 15 /* IEXTEN */ +#endif +#define VMIN 16 /* !ICANON */ +#define VTIME 17 /* !ICANON */ +#if __BSD_VISIBLE +#define VSTATUS 18 /* ICANON */ +/* 19 spare 2 */ +#endif +#define NCCS 20 + +#define _POSIX_VDISABLE (0377) + +#if __BSD_VISIBLE +#define CCEQ(val, c) (c == val ? val != _POSIX_VDISABLE : 0) +#endif + +/* + * Input flags - software input processing + */ +#define IGNBRK 0x00000001 /* ignore BREAK condition */ +#define BRKINT 0x00000002 /* map BREAK to SIGINT */ +#define IGNPAR 0x00000004 /* ignore (discard) parity errors */ +#define PARMRK 0x00000008 /* mark parity and framing errors */ +#define INPCK 0x00000010 /* enable checking of parity errors */ +#define ISTRIP 0x00000020 /* strip 8th bit off chars */ +#define INLCR 0x00000040 /* map NL into CR */ +#define IGNCR 0x00000080 /* ignore CR */ +#define ICRNL 0x00000100 /* map CR to NL (ala CRMOD) */ +#define IXON 0x00000200 /* enable output flow control */ +#define IXOFF 0x00000400 /* enable input flow control */ +#if __BSD_VISIBLE +#define IXANY 0x00000800 /* any char will restart after stop */ +#define IUCLC 0x00001000 /* translate upper to lower case */ +#define IMAXBEL 0x00002000 /* ring bell on input queue full */ +#endif /* __BSD_VISIBLE */ + +/* + * Output flags - software output processing + */ +#define OPOST 0x00000001 /* enable following output processing */ +#if __XPG_VISIBLE +#define ONLCR 0x00000002 /* map NL to CR-NL (ala CRMOD) */ +#endif +#if __BSD_VISIBLE || __XPG_VISIBLE +#define TABDLY 0x00000004 /* horizontal tab delay mask */ +#define TAB0 0x00000000 /* no tab delay or expansion */ +#define TAB3 0x00000004 /* expand tabs to spaces */ +#if __BSD_VISIBLE +#define OXTABS TAB3 /* BSD name for TAB3 */ +#define ONOEOT 0x00000008 /* discard EOT's (^D) on output */ +#endif +#endif +#if __XPG_VISIBLE +#define OCRNL 0x00000010 /* map CR to NL */ +#define OLCUC 0x00000020 /* translate lower case to upper case */ +#define ONOCR 0x00000040 /* No CR output at column 0 */ +#define ONLRET 0x00000080 /* NL performs the CR function */ +#endif /* __XPG_VISIBLE */ + +/* + * Control flags - hardware control of terminal + */ +#if __BSD_VISIBLE +#define CIGNORE 0x00000001 /* ignore control flags */ +#endif +#define CSIZE 0x00000300 /* character size mask */ +#define CS5 0x00000000 /* 5 bits (pseudo) */ +#define CS6 0x00000100 /* 6 bits */ +#define CS7 0x00000200 /* 7 bits */ +#define CS8 0x00000300 /* 8 bits */ +#define CSTOPB 0x00000400 /* send 2 stop bits */ +#define CREAD 0x00000800 /* enable receiver */ +#define PARENB 0x00001000 /* parity enable */ +#define PARODD 0x00002000 /* odd parity, else even */ +#define HUPCL 0x00004000 /* hang up on last close */ +#define CLOCAL 0x00008000 /* ignore modem status lines */ +#if __BSD_VISIBLE +#define CRTSCTS 0x00010000 /* RTS/CTS full-duplex flow control */ +#define CRTS_IFLOW CRTSCTS /* XXX compat */ +#define CCTS_OFLOW CRTSCTS /* XXX compat */ +#define MDMBUF 0x00100000 /* DTR/DCD hardware flow control */ +#define CHWFLOW (MDMBUF|CRTSCTS) /* all types of hw flow control */ +#endif /* __BSD_VISIBLE */ + +/* + * "Local" flags - dumping ground for other state + * + * Warning: some flags in this structure begin with + * the letter "I" and look like they belong in the + * input flag. + */ + +#if __BSD_VISIBLE +#define ECHOKE 0x00000001 /* visual erase for line kill */ +#endif +#define ECHOE 0x00000002 /* visually erase chars */ +#define ECHOK 0x00000004 /* echo NL after line kill */ +#define ECHO 0x00000008 /* enable echoing */ +#define ECHONL 0x00000010 /* echo NL even if ECHO is off */ +#if __BSD_VISIBLE +#define ECHOPRT 0x00000020 /* visual erase mode for hardcopy */ +#define ECHOCTL 0x00000040 /* echo control chars as ^(Char) */ +#endif +#define ISIG 0x00000080 /* enable signals INTR, QUIT, [D]SUSP */ +#define ICANON 0x00000100 /* canonicalize input lines */ +#if __BSD_VISIBLE +#define ALTWERASE 0x00000200 /* use alternate WERASE algorithm */ +#endif +#define IEXTEN 0x00000400 /* enable DISCARD and LNEXT */ +#define EXTPROC 0x00000800 /* external processing */ +#define TOSTOP 0x00400000 /* stop background jobs from output */ +#if __BSD_VISIBLE +#define FLUSHO 0x00800000 /* output being flushed (state) */ +#define XCASE 0x01000000 /* canonical upper/lower case */ +#define NOKERNINFO 0x02000000 /* no kernel output from VSTATUS */ +#define PENDIN 0x20000000 /* XXX retype pending input (state) */ +#endif +#define NOFLSH 0x80000000 /* don't flush after interrupt */ + +typedef unsigned int tcflag_t; +typedef unsigned char cc_t; +typedef unsigned int speed_t; + +struct termios { + tcflag_t c_iflag; /* input flags */ + tcflag_t c_oflag; /* output flags */ + tcflag_t c_cflag; /* control flags */ + tcflag_t c_lflag; /* local flags */ + cc_t c_cc[NCCS]; /* control chars */ + int c_ispeed; /* input speed */ + int c_ospeed; /* output speed */ +}; + +/* + * Commands passed to tcsetattr() for setting the termios structure. + */ +#define TCSANOW 0 /* make change immediate */ +#define TCSADRAIN 1 /* drain output, then change */ +#define TCSAFLUSH 2 /* drain output, flush input */ +#if __BSD_VISIBLE +#define TCSASOFT 0x10 /* flag - don't alter h.w. state */ +#endif + +/* + * Standard speeds + */ +#define B0 0 +#define B50 50 +#define B75 75 +#define B110 110 +#define B134 134 +#define B150 150 +#define B200 200 +#define B300 300 +#define B600 600 +#define B1200 1200 +#define B1800 1800 +#define B2400 2400 +#define B4800 4800 +#define B9600 9600 +#define B19200 19200 +#define B38400 38400 +#if __BSD_VISIBLE +#define B7200 7200 +#define B14400 14400 +#define B28800 28800 +#define B57600 57600 +#define B76800 76800 +#define B115200 115200 +#define B230400 230400 +#define EXTA 19200 +#define EXTB 38400 +#endif /* __BSD_VISIBLE */ + +#ifndef _KERNEL + +#define TCIFLUSH 1 +#define TCOFLUSH 2 +#define TCIOFLUSH 3 +#define TCOOFF 1 +#define TCOON 2 +#define TCIOFF 3 +#define TCION 4 + +#include + +#if __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200809 +#ifndef _PID_T_DEFINED_ +#define _PID_T_DEFINED_ +typedef __pid_t pid_t; +#endif +#endif + +__BEGIN_DECLS +speed_t cfgetispeed(const struct termios *); +speed_t cfgetospeed(const struct termios *); +int cfsetispeed(struct termios *, speed_t); +int cfsetospeed(struct termios *, speed_t); +int tcgetattr(int, struct termios *); +int tcsetattr(int, int, const struct termios *); +int tcdrain(int); +int tcflow(int, int); +int tcflush(int, int); +int tcsendbreak(int, int); + +#if __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200809 +pid_t tcgetsid(int); +#endif + +#if __BSD_VISIBLE +void cfmakeraw(struct termios *); +int cfsetspeed(struct termios *, speed_t); +#endif /* __BSD_VISIBLE */ +__END_DECLS + +#endif /* !_KERNEL */ + +#if __BSD_VISIBLE +/* + * Include tty ioctl's that aren't just for backwards compatibility + * with the old tty driver. These ioctl definitions were previously + * in . + */ +#include +#endif + +/* + * END OF PROTECTED INCLUDE. + */ +#endif /* !_SYS_TERMIOS_H_ */ + +#if __BSD_VISIBLE +#include +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/time.h b/lib/libc/include/generic-openbsd/sys/time.h new file mode 100644 index 0000000000..7c4a69a854 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/time.h @@ -0,0 +1,473 @@ +/* $OpenBSD: time.h,v 1.67 2025/06/05 08:49:09 claudio Exp $ */ +/* $NetBSD: time.h,v 1.18 1996/04/23 10:29:33 mycroft Exp $ */ + +/* + * Copyright (c) 1982, 1986, 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. + * + * @(#)time.h 8.2 (Berkeley) 7/10/94 + */ + +#ifndef _SYS_TIME_H_ +#define _SYS_TIME_H_ + +#include + +#ifndef _TIMEVAL_DECLARED +#define _TIMEVAL_DECLARED +/* + * Structure returned by gettimeofday(2) system call, + * and used in other calls. + */ +struct timeval { + time_t tv_sec; /* seconds */ + suseconds_t tv_usec; /* and microseconds */ +}; +#endif + +#ifndef _TIMESPEC_DECLARED +#define _TIMESPEC_DECLARED +/* + * Structure defined by POSIX.1b to be like a timeval. + */ +struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +}; +#endif + +#define TIMEVAL_TO_TIMESPEC(tv, ts) do { \ + (ts)->tv_sec = (tv)->tv_sec; \ + (ts)->tv_nsec = (tv)->tv_usec * 1000; \ +} while (0) +#define TIMESPEC_TO_TIMEVAL(tv, ts) do { \ + (tv)->tv_sec = (ts)->tv_sec; \ + (tv)->tv_usec = (ts)->tv_nsec / 1000; \ +} while (0) + +struct timezone { + int tz_minuteswest; /* minutes west of Greenwich */ + int tz_dsttime; /* type of dst correction */ +}; +#define DST_NONE 0 /* not on dst */ +#define DST_USA 1 /* USA style dst */ +#define DST_AUST 2 /* Australian style dst */ +#define DST_WET 3 /* Western European dst */ +#define DST_MET 4 /* Middle European dst */ +#define DST_EET 5 /* Eastern European dst */ +#define DST_CAN 6 /* Canada */ + +/* Operations on timevals. */ +#define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 +#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) +#define timerisvalid(tvp) \ + ((tvp)->tv_usec >= 0 && (tvp)->tv_usec < 1000000) +#define timercmp(tvp, uvp, cmp) \ + (((tvp)->tv_sec == (uvp)->tv_sec) ? \ + ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ + ((tvp)->tv_sec cmp (uvp)->tv_sec)) +#define timeradd(tvp, uvp, vvp) \ + do { \ + (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ + if ((vvp)->tv_usec >= 1000000) { \ + (vvp)->tv_sec++; \ + (vvp)->tv_usec -= 1000000; \ + } \ + } while (0) +#define timersub(tvp, uvp, vvp) \ + do { \ + (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ + (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ + if ((vvp)->tv_usec < 0) { \ + (vvp)->tv_sec--; \ + (vvp)->tv_usec += 1000000; \ + } \ + } while (0) + +/* Operations on timespecs. */ +#define timespecclear(tsp) (tsp)->tv_sec = (tsp)->tv_nsec = 0 +#define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec) +#define timespecisvalid(tsp) \ + ((tsp)->tv_nsec >= 0 && (tsp)->tv_nsec < 1000000000L) +#define timespeccmp(tsp, usp, cmp) \ + (((tsp)->tv_sec == (usp)->tv_sec) ? \ + ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \ + ((tsp)->tv_sec cmp (usp)->tv_sec)) +#define timespecadd(tsp, usp, vsp) \ + do { \ + (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \ + (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \ + if ((vsp)->tv_nsec >= 1000000000L) { \ + (vsp)->tv_sec++; \ + (vsp)->tv_nsec -= 1000000000L; \ + } \ + } while (0) +#define timespecsub(tsp, usp, vsp) \ + do { \ + (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \ + (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \ + if ((vsp)->tv_nsec < 0) { \ + (vsp)->tv_sec--; \ + (vsp)->tv_nsec += 1000000000L; \ + } \ + } while (0) + +/* + * Names of the interval timers, and structure + * defining a timer setting. + */ +#define ITIMER_REAL 0 +#define ITIMER_VIRTUAL 1 +#define ITIMER_PROF 2 + +struct itimerval { + struct timeval it_interval; /* timer interval */ + struct timeval it_value; /* current value */ +}; + +#if __BSD_VISIBLE +/* + * clock information structure for sysctl({CTL_KERN, KERN_CLOCKRATE}) + */ +struct clockinfo { + int hz; /* clock frequency */ + int tick; /* micro-seconds per hz tick */ + int stathz; /* statistics clock frequency */ + int profhz; /* profiling clock frequency */ +}; +#endif /* __BSD_VISIBLE */ + +#if defined(_KERNEL) || defined(_STANDALONE) || defined (_LIBC) +#include + +/* Time expressed as seconds and fractions of a second + operations on it. */ +struct bintime { + time_t sec; + uint64_t frac; +}; +#endif + +#if defined(_KERNEL) || defined(_STANDALONE) || defined (_LIBC) + +#define bintimecmp(btp, ctp, cmp) \ + ((btp)->sec == (ctp)->sec ? \ + (btp)->frac cmp (ctp)->frac : \ + (btp)->sec cmp (ctp)->sec) + +static inline void +bintimeaddfrac(const struct bintime *bt, uint64_t x, struct bintime *ct) +{ + ct->sec = bt->sec; + if (bt->frac > bt->frac + x) + ct->sec++; + ct->frac = bt->frac + x; +} + +static inline void +bintimeadd(const struct bintime *bt, const struct bintime *ct, + struct bintime *dt) +{ + dt->sec = bt->sec + ct->sec; + if (bt->frac > bt->frac + ct->frac) + dt->sec++; + dt->frac = bt->frac + ct->frac; +} + +static inline void +bintimesub(const struct bintime *bt, const struct bintime *ct, + struct bintime *dt) +{ + dt->sec = bt->sec - ct->sec; + if (bt->frac < bt->frac - ct->frac) + dt->sec--; + dt->frac = bt->frac - ct->frac; +} + +static inline void +TIMECOUNT_TO_BINTIME(u_int count, uint64_t scale, struct bintime *bt) +{ + uint64_t hi64; + + hi64 = count * (scale >> 32); + bt->sec = hi64 >> 32; + bt->frac = hi64 << 32; + bintimeaddfrac(bt, count * (scale & 0xffffffff), bt); +} + +/*- + * Background information: + * + * When converting between timestamps on parallel timescales of differing + * resolutions it is historical and scientific practice to round down rather + * than doing 4/5 rounding. + * + * The date changes at midnight, not at noon. + * + * Even at 15:59:59.999999999 it's not four'o'clock. + * + * time_second ticks after N.999999999 not after N.4999999999 + */ + +static inline uint32_t +FRAC_TO_NSEC(uint64_t frac) +{ + return ((frac >> 32) * 1000000000ULL) >> 32; +} + +static inline void +BINTIME_TO_TIMESPEC(const struct bintime *bt, struct timespec *ts) +{ + ts->tv_sec = bt->sec; + ts->tv_nsec = FRAC_TO_NSEC(bt->frac); +} + +static inline void +TIMESPEC_TO_BINTIME(const struct timespec *ts, struct bintime *bt) +{ + bt->sec = ts->tv_sec; + /* 18446744073 = int(2^64 / 1000000000) */ + bt->frac = (uint64_t)ts->tv_nsec * (uint64_t)18446744073ULL; +} + +static inline void +BINTIME_TO_TIMEVAL(const struct bintime *bt, struct timeval *tv) +{ + tv->tv_sec = bt->sec; + tv->tv_usec = (long)(((uint64_t)1000000 * (uint32_t)(bt->frac >> 32)) >> 32); +} + +static inline void +TIMEVAL_TO_BINTIME(const struct timeval *tv, struct bintime *bt) +{ + bt->sec = (time_t)tv->tv_sec; + /* 18446744073709 = int(2^64 / 1000000) */ + bt->frac = (uint64_t)tv->tv_usec * (uint64_t)18446744073709ULL; +} +#endif + +#if defined(_KERNEL) || defined(_STANDALONE) + +/* + * Functions for looking at our clocks: [get]{bin,nano,micro}[boot|up]time() + * + * Functions without the "get" prefix returns the best timestamp + * we can produce in the given format. + * + * "bin" == struct bintime == seconds + 64 bit fraction of seconds. + * "nano" == struct timespec == seconds + nanoseconds. + * "micro" == struct timeval == seconds + microseconds. + * + * Functions containing "up" returns time relative to boot and + * should be used for calculating time intervals. + * + * Functions containing "boot" return the GMT time at which the + * system booted. + * + * Functions with just "time" return the current GMT time. + * + * Functions with the "get" prefix returns a less precise result + * much faster than the functions without "get" prefix and should + * be used where a precision of 10 msec is acceptable or where + * performance is priority. (NB: "precision", _not_ "resolution" !) + */ + +void bintime(struct bintime *); +void nanotime(struct timespec *); +void microtime(struct timeval *); + +void getnanotime(struct timespec *); +void getmicrotime(struct timeval *); + +void binuptime(struct bintime *); +void nanouptime(struct timespec *); +void microuptime(struct timeval *); + +void getbinuptime(struct bintime *); +void getnanouptime(struct timespec *); +void getmicrouptime(struct timeval *); + +void binboottime(struct bintime *); +void microboottime(struct timeval *); +void nanoboottime(struct timespec *); + +void binruntime(struct bintime *); +void nanoruntime(struct timespec *); + +void getbinruntime(struct bintime *); +uint64_t getnsecruntime(void); + +time_t gettime(void); +time_t getuptime(void); + +uint64_t nsecuptime(void); +uint64_t getnsecuptime(void); + +struct proc; +int clock_gettime(struct proc *, clockid_t, struct timespec *); + +struct clockrequest; +void itimer_update(struct clockrequest *, void *, void *); + +void cancel_all_itimers(void); +int settime(const struct timespec *); +int ratecheck(struct timeval *, const struct timeval *); +int ppsratecheck(struct timeval *, int *, int); + +/* + * "POSIX time" to/from "YY/MM/DD/hh/mm/ss" + */ +struct clock_ymdhms { + u_short dt_year; + u_char dt_mon; + u_char dt_day; + u_char dt_wday; /* Day of week */ + u_char dt_hour; + u_char dt_min; + u_char dt_sec; +}; + +time_t clock_ymdhms_to_secs(struct clock_ymdhms *); +void clock_secs_to_ymdhms(time_t, struct clock_ymdhms *); +/* + * BCD to decimal and decimal to BCD. + */ +#define FROMBCD(x) (((x) >> 4) * 10 + ((x) & 0xf)) +#define TOBCD(x) (((x) / 10 * 16) + ((x) % 10)) + +/* Some handy constants. */ +#define SECDAY 86400L +#define SECYR (SECDAY * 365) + +/* Traditional POSIX base year */ +#define POSIX_BASE_YEAR 1970 + +#include + +static inline void +USEC_TO_TIMEVAL(uint64_t us, struct timeval *tv) +{ + tv->tv_sec = us / 1000000; + tv->tv_usec = us % 1000000; +} + +static inline void +NSEC_TO_TIMEVAL(uint64_t ns, struct timeval *tv) +{ + tv->tv_sec = ns / 1000000000L; + tv->tv_usec = (ns % 1000000000L) / 1000; +} + +static inline uint64_t +TIMEVAL_TO_NSEC(const struct timeval *tv) +{ + uint64_t nsecs; + + if (tv->tv_sec > UINT64_MAX / 1000000000ULL) + return UINT64_MAX; + nsecs = tv->tv_sec * 1000000000ULL; + if (tv->tv_usec * 1000ULL > UINT64_MAX - nsecs) + return UINT64_MAX; + return nsecs + tv->tv_usec * 1000ULL; +} + +static inline void +NSEC_TO_TIMESPEC(uint64_t ns, struct timespec *ts) +{ + ts->tv_sec = ns / 1000000000L; + ts->tv_nsec = ns % 1000000000L; +} + +static inline uint64_t +SEC_TO_NSEC(uint64_t seconds) +{ + if (seconds > UINT64_MAX / 1000000000ULL) + return UINT64_MAX; + return seconds * 1000000000ULL; +} + +static inline uint64_t +MSEC_TO_NSEC(uint64_t milliseconds) +{ + if (milliseconds > UINT64_MAX / 1000000ULL) + return UINT64_MAX; + return milliseconds * 1000000ULL; +} + +static inline uint64_t +USEC_TO_NSEC(uint64_t microseconds) +{ + if (microseconds > UINT64_MAX / 1000ULL) + return UINT64_MAX; + return microseconds * 1000ULL; +} + +static inline uint64_t +TIMESPEC_TO_NSEC(const struct timespec *ts) +{ + if (ts->tv_sec > (UINT64_MAX - ts->tv_nsec) / 1000000000ULL) + return UINT64_MAX; + return ts->tv_sec * 1000000000ULL + ts->tv_nsec; +} + +static inline uint64_t +BINTIME_TO_NSEC(const struct bintime *bt) +{ + return bt->sec * 1000000000ULL + FRAC_TO_NSEC(bt->frac); +} + +extern int tick_nsec; + +static inline uint64_t +TICKS_TO_NSEC(uint64_t ticks) +{ + return ticks * tick_nsec; +} + +#else /* !_KERNEL */ +#include + +#if __BSD_VISIBLE || __XPG_VISIBLE +__BEGIN_DECLS +#if __BSD_VISIBLE +int adjtime(const struct timeval *, struct timeval *); +int adjfreq(const int64_t *, int64_t *); +#endif +#if __XPG_VISIBLE +int futimes(int, const struct timeval *); +int getitimer(int, struct itimerval *); +int gettimeofday(struct timeval *, struct timezone *); +int setitimer(int, const struct itimerval *, struct itimerval *); +int settimeofday(const struct timeval *, const struct timezone *); +int utimes(const char *, const struct timeval *); +#endif /* __XPG_VISIBLE */ +__END_DECLS +#endif /* __BSD_VISIBLE || __XPG_VISIBLE */ + +#endif /* !_KERNEL */ + +#endif /* !_SYS_TIME_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/timeout.h b/lib/libc/include/generic-openbsd/sys/timeout.h new file mode 100644 index 0000000000..4bb7ef1555 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/timeout.h @@ -0,0 +1,126 @@ +/* $OpenBSD: timeout.h,v 1.51 2025/05/23 23:56:14 dlg Exp $ */ +/* + * Copyright (c) 2000-2001 Artur Grabowski + * 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. 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 ``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 _SYS_TIMEOUT_H_ +#define _SYS_TIMEOUT_H_ + +#include + +struct circq { + struct circq *next; /* next element */ + struct circq *prev; /* previous element */ +}; + +struct timeout { + struct circq to_list; /* timeout queue, don't move */ + struct timespec to_abstime; /* absolute time to run at */ + void (*to_func)(void *); /* function to call */ + void *to_arg; /* function argument */ +#if 1 /* NKCOV > 0 */ + struct process *to_process; /* kcov identifier */ +#endif + int to_time; /* ticks on event */ + int to_flags; /* misc flags */ + int to_kclock; /* abstime's kernel clock */ +}; + +/* + * flags in the to_flags field. + */ +#define TIMEOUT_PROC 0x01 /* needs a process context */ +#define TIMEOUT_ONQUEUE 0x02 /* on any timeout queue */ +#define TIMEOUT_INITIALIZED 0x04 /* initialized */ +#define TIMEOUT_TRIGGERED 0x08 /* running or ran */ +#define TIMEOUT_MPSAFE 0x10 /* run without kernel lock */ + +struct timeoutstat { + uint64_t tos_added; /* timeout_add*(9) calls */ + uint64_t tos_cancelled; /* dequeued during timeout_del*(9) */ + uint64_t tos_deleted; /* timeout_del*(9) calls */ + uint64_t tos_late; /* run after deadline */ + uint64_t tos_pending; /* number currently ONQUEUE */ + uint64_t tos_readded; /* timeout_add*(9) + already ONQUEUE */ + uint64_t tos_rescheduled; /* bucketed + already SCHEDULED */ + uint64_t tos_run_softclock; /* run from softclock() */ + uint64_t tos_run_thread; /* run from softclock_thread() */ + uint64_t tos_scheduled; /* bucketed during softclock() */ + uint64_t tos_softclocks; /* softclock() calls */ + uint64_t tos_thread_wakeups; /* wakeups in softclock_thread() */ +}; + +#ifdef _KERNEL +int timeout_sysctl(void *, size_t *, void *, size_t); + +/* + * special macros + * + * timeout_pending(to) - is this timeout already scheduled to run? + * timeout_initialized(to) - is this timeout initialized? + */ +#define timeout_pending(to) ((to)->to_flags & TIMEOUT_ONQUEUE) +#define timeout_initialized(to) ((to)->to_flags & TIMEOUT_INITIALIZED) +#define timeout_triggered(to) ((to)->to_flags & TIMEOUT_TRIGGERED) + +#define KCLOCK_NONE (-1) /* dummy clock for sanity checks */ +#define KCLOCK_UPTIME 0 /* uptime clock; time since boot */ +#define KCLOCK_MAX 1 + +#define TIMEOUT_INITIALIZER_FLAGS(_fn, _arg, _kclock, _flags) { \ + .to_list = { NULL, NULL }, \ + .to_abstime = { .tv_sec = 0, .tv_nsec = 0 }, \ + .to_func = (_fn), \ + .to_arg = (_arg), \ + .to_time = 0, \ + .to_flags = (_flags) | TIMEOUT_INITIALIZED, \ + .to_kclock = (_kclock) \ +} + +#define TIMEOUT_INITIALIZER(_f, _a) \ + TIMEOUT_INITIALIZER_FLAGS((_f), (_a), KCLOCK_NONE, 0) + +void timeout_set(struct timeout *, void (*)(void *), void *); +void timeout_set_flags(struct timeout *, void (*)(void *), void *, int, int); +void timeout_set_proc(struct timeout *, void (*)(void *), void *); + +int timeout_add(struct timeout *, int); +int timeout_add_sec(struct timeout *, int); +int timeout_add_msec(struct timeout *, uint64_t); +int timeout_add_usec(struct timeout *, uint64_t); +int timeout_add_nsec(struct timeout *, uint64_t); + +int timeout_abs_ts(struct timeout *, const struct timespec *); + +int timeout_del(struct timeout *); +int timeout_del_barrier(struct timeout *); +void timeout_barrier(struct timeout *); + +void timeout_adjust_ticks(int); +void timeout_hardclock_update(void); +void timeout_startup(void); + +#endif /* _KERNEL */ + +#endif /* _SYS_TIMEOUT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/times.h b/lib/libc/include/generic-openbsd/sys/times.h new file mode 100644 index 0000000000..dec9d90687 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/times.h @@ -0,0 +1,63 @@ +/* $OpenBSD: times.h,v 1.6 2013/07/06 18:44:21 naddy Exp $ */ +/* $NetBSD: times.h,v 1.8 1995/03/26 20:24:54 jtc Exp $ */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)times.h 8.4 (Berkeley) 1/21/94 + */ + +#ifndef _SYS_TIMES_H_ +#define _SYS_TIMES_H_ + +#include +#include + +#ifndef _CLOCK_T_DEFINED_ +#define _CLOCK_T_DEFINED_ +typedef __clock_t clock_t; +#endif + +struct tms { + clock_t tms_utime; /* User CPU time */ + clock_t tms_stime; /* System CPU time */ + clock_t tms_cutime; /* User CPU time of terminated child procs */ + clock_t tms_cstime; /* System CPU time of terminated child procs */ +}; + +#ifndef _KERNEL +__BEGIN_DECLS +clock_t times(struct tms *); +__END_DECLS +#endif +#endif /* !_SYS_TIMES_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/timetc.h b/lib/libc/include/generic-openbsd/sys/timetc.h new file mode 100644 index 0000000000..9dcb1cf390 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/timetc.h @@ -0,0 +1,124 @@ +/* $OpenBSD: timetc.h,v 1.14 2023/02/04 19:19:35 cheloha Exp $ */ + +/* + * Copyright (c) 2000 Poul-Henning Kamp + * + * 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. + */ + +/* + * If we meet some day, and you think this stuff is worth it, you + * can buy me a beer in return. Poul-Henning Kamp + */ + +#ifndef _SYS_TIMETC_H_ +#define _SYS_TIMETC_H_ + +#if !defined(_KERNEL) && !defined(_LIBC) +#error "no user-serviceable parts inside" +#endif + +#include +#include + +/*- + * `struct timecounter' is the interface between the hardware which implements + * a timecounter and the MI code which uses this to keep track of time. + * + * A timecounter is a binary counter which has two properties: + * * it runs at a fixed, known frequency. + * * it has sufficient bits to not roll over in less than approximately + * max(2 msec, 2/HZ seconds). (The value 2 here is really 1 + delta, + * for some indeterminate value of delta.) + */ + +struct timecounter; +typedef u_int timecounter_get_t(struct timecounter *); + +/* + * Locks used to protect struct members in this file: + * I immutable after initialization + * T tc_lock + * W windup_mtx + */ + +struct timecounter { + timecounter_get_t *tc_get_timecount; /* [I] */ + /* + * This function reads the counter. It is not required to + * mask any unimplemented bits out, as long as they are + * constant. + */ + u_int tc_counter_mask; /* [I] */ + /* This mask should mask off any unimplemented bits. */ + u_int64_t tc_frequency; /* [I] */ + /* Frequency of the counter in Hz. */ + char *tc_name; /* [I] */ + /* Name of the timecounter. */ + int tc_quality; /* [I] */ + /* + * Used to determine if this timecounter is better than + * another timecounter higher means better. Negative + * means "only use at explicit request". + */ + void *tc_priv; /* [I] */ + /* Pointer to the timecounter's private parts. */ + int tc_user; /* [I] */ + /* Expose this timecounter to userland. */ + SLIST_ENTRY(timecounter) tc_next; /* [I] */ + /* Pointer to the next timecounter. */ + int64_t tc_freq_adj; /* [T,W] */ + /* Current frequency adjustment. */ + u_int64_t tc_precision; /* [I] */ + /* Precision of the counter. Computed in tc_init(). */ +}; + +struct timekeep { + /* set at initialization */ + uint32_t tk_version; /* version number */ + + /* timehands members */ + uint64_t tk_scale; + u_int tk_offset_count; + struct bintime tk_offset; + struct bintime tk_naptime; + struct bintime tk_boottime; + volatile u_int tk_generation; + + /* timecounter members */ + int tk_user; + u_int tk_counter_mask; +}; +#define TK_VERSION 0 + +struct rwlock; +extern struct rwlock tc_lock; + +extern struct timecounter *timecounter; + +extern struct uvm_object *timekeep_object; +extern struct timekeep *timekeep; + +u_int64_t tc_getfrequency(void); +u_int64_t tc_getprecision(void); +void tc_init(struct timecounter *tc); +void tc_reset_quality(struct timecounter *, int); +void tc_setclock(const struct timespec *ts); +void tc_setrealtimeclock(const struct timespec *ts); +void tc_ticktock(void); +void inittimecounter(void); +int sysctl_tc(int *, u_int, void *, size_t *, void *, size_t); +void tc_adjfreq(int64_t *, int64_t *); +void tc_adjtime(int64_t *, int64_t *); + +#endif /* !_SYS_TIMETC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/tprintf.h b/lib/libc/include/generic-openbsd/sys/tprintf.h new file mode 100644 index 0000000000..af0d8812fc --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/tprintf.h @@ -0,0 +1,41 @@ +/* $OpenBSD: tprintf.h,v 1.6 2003/08/24 01:27:07 avsm Exp $ */ +/* $NetBSD: tprintf.h,v 1.10 1996/04/09 20:55:43 cgd 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. + * + * @(#)tprintf.h 8.1 (Berkeley) 6/2/93 + */ + +typedef struct session *tpr_t; + +tpr_t tprintf_open(struct proc *); +void tprintf_close(tpr_t); + +void tprintf(tpr_t, const char *fmt, ...) + __attribute__((__format__(__kprintf__,2,3))); \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/tracepoint.h b/lib/libc/include/generic-openbsd/sys/tracepoint.h new file mode 100644 index 0000000000..a50023a13f --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/tracepoint.h @@ -0,0 +1,38 @@ +/* $OpenBSD: tracepoint.h,v 1.2 2022/06/28 09:32:28 bluhm Exp $ */ + +/* + * Copyright (c) 2019 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 _SYS_TRACEPOINT_H_ +#define _SYS_TRACEPOINT_H_ + +#ifdef _KERNEL + +#include "dt.h" +#if NDT > 0 +#include + +#define TRACEPOINT(func, name, args...) DT_STATIC_ENTER(func, name, args) +#define TRACEINDEX(func, index, args...) DT_INDEX_ENTER(func, index, args) + +#else /* NDT > 0 */ + +#define TRACEPOINT(func, name, args...) +#define TRACEINDEX(func, index, args...) + +#endif /* NDT > 0 */ +#endif /* _KERNEL */ +#endif /* _SYS_TRACEPOINT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/tree.h b/lib/libc/include/generic-openbsd/sys/tree.h new file mode 100644 index 0000000000..c8e30cf896 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/tree.h @@ -0,0 +1,1004 @@ +/* $OpenBSD: tree.h,v 1.31 2023/03/08 04:43:09 guenther Exp $ */ +/* + * Copyright 2002 Niels Provos + * 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 _SYS_TREE_H_ +#define _SYS_TREE_H_ + +#include + +/* + * This file defines data structures for different types of trees: + * splay trees and red-black trees. + * + * A splay tree is a self-organizing data structure. Every operation + * on the tree causes a splay to happen. The splay moves the requested + * node to the root of the tree and partly rebalances it. + * + * This has the benefit that request locality causes faster lookups as + * the requested nodes move to the top of the tree. On the other hand, + * every lookup causes memory writes. + * + * The Balance Theorem bounds the total access time for m operations + * and n inserts on an initially empty tree as O((m + n)lg n). The + * amortized cost for a sequence of m accesses to a splay tree is O(lg n); + * + * A red-black tree is a binary search tree with the node color as an + * extra attribute. It fulfills a set of conditions: + * - every search path from the root to a leaf consists of the + * same number of black nodes, + * - each red node (except for the root) has a black parent, + * - each leaf node is black. + * + * Every operation on a red-black tree is bounded as O(lg n). + * The maximum height of a red-black tree is 2lg (n+1). + */ + +#define SPLAY_HEAD(name, type) \ +struct name { \ + struct type *sph_root; /* root of the tree */ \ +} + +#define SPLAY_INITIALIZER(root) \ + { NULL } + +#define SPLAY_INIT(root) do { \ + (root)->sph_root = NULL; \ +} while (0) + +#define SPLAY_ENTRY(type) \ +struct { \ + struct type *spe_left; /* left element */ \ + struct type *spe_right; /* right element */ \ +} + +#define SPLAY_LEFT(elm, field) (elm)->field.spe_left +#define SPLAY_RIGHT(elm, field) (elm)->field.spe_right +#define SPLAY_ROOT(head) (head)->sph_root +#define SPLAY_EMPTY(head) (SPLAY_ROOT(head) == NULL) + +/* SPLAY_ROTATE_{LEFT,RIGHT} expect that tmp hold SPLAY_{RIGHT,LEFT} */ +#define SPLAY_ROTATE_RIGHT(head, tmp, field) do { \ + SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(tmp, field); \ + SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ + (head)->sph_root = tmp; \ +} while (0) + +#define SPLAY_ROTATE_LEFT(head, tmp, field) do { \ + SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(tmp, field); \ + SPLAY_LEFT(tmp, field) = (head)->sph_root; \ + (head)->sph_root = tmp; \ +} while (0) + +#define SPLAY_LINKLEFT(head, tmp, field) do { \ + SPLAY_LEFT(tmp, field) = (head)->sph_root; \ + tmp = (head)->sph_root; \ + (head)->sph_root = SPLAY_LEFT((head)->sph_root, field); \ +} while (0) + +#define SPLAY_LINKRIGHT(head, tmp, field) do { \ + SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ + tmp = (head)->sph_root; \ + (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field); \ +} while (0) + +#define SPLAY_ASSEMBLE(head, node, left, right, field) do { \ + SPLAY_RIGHT(left, field) = SPLAY_LEFT((head)->sph_root, field); \ + SPLAY_LEFT(right, field) = SPLAY_RIGHT((head)->sph_root, field);\ + SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(node, field); \ + SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(node, field); \ +} while (0) + +/* Generates prototypes and inline functions */ + +#define SPLAY_PROTOTYPE(name, type, field, cmp) \ +void name##_SPLAY(struct name *, struct type *); \ +void name##_SPLAY_MINMAX(struct name *, int); \ +struct type *name##_SPLAY_INSERT(struct name *, struct type *); \ +struct type *name##_SPLAY_REMOVE(struct name *, struct type *); \ + \ +/* Finds the node with the same key as elm */ \ +static __unused __inline struct type * \ +name##_SPLAY_FIND(struct name *head, struct type *elm) \ +{ \ + if (SPLAY_EMPTY(head)) \ + return(NULL); \ + name##_SPLAY(head, elm); \ + if ((cmp)(elm, (head)->sph_root) == 0) \ + return (head->sph_root); \ + return (NULL); \ +} \ + \ +static __unused __inline struct type * \ +name##_SPLAY_NEXT(struct name *head, struct type *elm) \ +{ \ + name##_SPLAY(head, elm); \ + if (SPLAY_RIGHT(elm, field) != NULL) { \ + elm = SPLAY_RIGHT(elm, field); \ + while (SPLAY_LEFT(elm, field) != NULL) { \ + elm = SPLAY_LEFT(elm, field); \ + } \ + } else \ + elm = NULL; \ + return (elm); \ +} \ + \ +static __unused __inline struct type * \ +name##_SPLAY_MIN_MAX(struct name *head, int val) \ +{ \ + name##_SPLAY_MINMAX(head, val); \ + return (SPLAY_ROOT(head)); \ +} + +/* Main splay operation. + * Moves node close to the key of elm to top + */ +#define SPLAY_GENERATE(name, type, field, cmp) \ +struct type * \ +name##_SPLAY_INSERT(struct name *head, struct type *elm) \ +{ \ + if (SPLAY_EMPTY(head)) { \ + SPLAY_LEFT(elm, field) = SPLAY_RIGHT(elm, field) = NULL; \ + } else { \ + int __comp; \ + name##_SPLAY(head, elm); \ + __comp = (cmp)(elm, (head)->sph_root); \ + if(__comp < 0) { \ + SPLAY_LEFT(elm, field) = SPLAY_LEFT((head)->sph_root, field);\ + SPLAY_RIGHT(elm, field) = (head)->sph_root; \ + SPLAY_LEFT((head)->sph_root, field) = NULL; \ + } else if (__comp > 0) { \ + SPLAY_RIGHT(elm, field) = SPLAY_RIGHT((head)->sph_root, field);\ + SPLAY_LEFT(elm, field) = (head)->sph_root; \ + SPLAY_RIGHT((head)->sph_root, field) = NULL; \ + } else \ + return ((head)->sph_root); \ + } \ + (head)->sph_root = (elm); \ + return (NULL); \ +} \ + \ +struct type * \ +name##_SPLAY_REMOVE(struct name *head, struct type *elm) \ +{ \ + struct type *__tmp; \ + if (SPLAY_EMPTY(head)) \ + return (NULL); \ + name##_SPLAY(head, elm); \ + if ((cmp)(elm, (head)->sph_root) == 0) { \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL) { \ + (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field);\ + } else { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + (head)->sph_root = SPLAY_LEFT((head)->sph_root, field);\ + name##_SPLAY(head, elm); \ + SPLAY_RIGHT((head)->sph_root, field) = __tmp; \ + } \ + return (elm); \ + } \ + return (NULL); \ +} \ + \ +void \ +name##_SPLAY(struct name *head, struct type *elm) \ +{ \ + struct type __node, *__left, *__right, *__tmp; \ + int __comp; \ +\ + SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\ + __left = __right = &__node; \ +\ + while ((__comp = (cmp)(elm, (head)->sph_root))) { \ + if (__comp < 0) { \ + __tmp = SPLAY_LEFT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if ((cmp)(elm, __tmp) < 0){ \ + SPLAY_ROTATE_RIGHT(head, __tmp, field); \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKLEFT(head, __right, field); \ + } else if (__comp > 0) { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if ((cmp)(elm, __tmp) > 0){ \ + SPLAY_ROTATE_LEFT(head, __tmp, field); \ + if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKRIGHT(head, __left, field); \ + } \ + } \ + SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ +} \ + \ +/* Splay with either the minimum or the maximum element \ + * Used to find minimum or maximum element in tree. \ + */ \ +void name##_SPLAY_MINMAX(struct name *head, int __comp) \ +{ \ + struct type __node, *__left, *__right, *__tmp; \ +\ + SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\ + __left = __right = &__node; \ +\ + while (1) { \ + if (__comp < 0) { \ + __tmp = SPLAY_LEFT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if (__comp < 0){ \ + SPLAY_ROTATE_RIGHT(head, __tmp, field); \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKLEFT(head, __right, field); \ + } else if (__comp > 0) { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if (__comp > 0) { \ + SPLAY_ROTATE_LEFT(head, __tmp, field); \ + if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKRIGHT(head, __left, field); \ + } \ + } \ + SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ +} + +#define SPLAY_NEGINF -1 +#define SPLAY_INF 1 + +#define SPLAY_INSERT(name, x, y) name##_SPLAY_INSERT(x, y) +#define SPLAY_REMOVE(name, x, y) name##_SPLAY_REMOVE(x, y) +#define SPLAY_FIND(name, x, y) name##_SPLAY_FIND(x, y) +#define SPLAY_NEXT(name, x, y) name##_SPLAY_NEXT(x, y) +#define SPLAY_MIN(name, x) (SPLAY_EMPTY(x) ? NULL \ + : name##_SPLAY_MIN_MAX(x, SPLAY_NEGINF)) +#define SPLAY_MAX(name, x) (SPLAY_EMPTY(x) ? NULL \ + : name##_SPLAY_MIN_MAX(x, SPLAY_INF)) + +#define SPLAY_FOREACH(x, name, head) \ + for ((x) = SPLAY_MIN(name, head); \ + (x) != NULL; \ + (x) = SPLAY_NEXT(name, head, x)) + +/* Macros that define a red-black tree */ +#define RB_HEAD(name, type) \ +struct name { \ + struct type *rbh_root; /* root of the tree */ \ +} + +#define RB_INITIALIZER(root) \ + { NULL } + +#define RB_INIT(root) do { \ + (root)->rbh_root = NULL; \ +} while (0) + +#define RB_BLACK 0 +#define RB_RED 1 +#define RB_ENTRY(type) \ +struct { \ + struct type *rbe_left; /* left element */ \ + struct type *rbe_right; /* right element */ \ + struct type *rbe_parent; /* parent element */ \ + int rbe_color; /* node color */ \ +} + +#define RB_LEFT(elm, field) (elm)->field.rbe_left +#define RB_RIGHT(elm, field) (elm)->field.rbe_right +#define RB_PARENT(elm, field) (elm)->field.rbe_parent +#define RB_COLOR(elm, field) (elm)->field.rbe_color +#define RB_ROOT(head) (head)->rbh_root +#define RB_EMPTY(head) (RB_ROOT(head) == NULL) + +#define RB_SET(elm, parent, field) do { \ + RB_PARENT(elm, field) = parent; \ + RB_LEFT(elm, field) = RB_RIGHT(elm, field) = NULL; \ + RB_COLOR(elm, field) = RB_RED; \ +} while (0) + +#define RB_SET_BLACKRED(black, red, field) do { \ + RB_COLOR(black, field) = RB_BLACK; \ + RB_COLOR(red, field) = RB_RED; \ +} while (0) + +#ifndef RB_AUGMENT +#define RB_AUGMENT(x) do {} while (0) +#endif + +#define RB_ROTATE_LEFT(head, elm, tmp, field) do { \ + (tmp) = RB_RIGHT(elm, field); \ + if ((RB_RIGHT(elm, field) = RB_LEFT(tmp, field))) { \ + RB_PARENT(RB_LEFT(tmp, field), field) = (elm); \ + } \ + RB_AUGMENT(elm); \ + if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field))) { \ + if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \ + RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \ + else \ + RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \ + } else \ + (head)->rbh_root = (tmp); \ + RB_LEFT(tmp, field) = (elm); \ + RB_PARENT(elm, field) = (tmp); \ + RB_AUGMENT(tmp); \ + if ((RB_PARENT(tmp, field))) \ + RB_AUGMENT(RB_PARENT(tmp, field)); \ +} while (0) + +#define RB_ROTATE_RIGHT(head, elm, tmp, field) do { \ + (tmp) = RB_LEFT(elm, field); \ + if ((RB_LEFT(elm, field) = RB_RIGHT(tmp, field))) { \ + RB_PARENT(RB_RIGHT(tmp, field), field) = (elm); \ + } \ + RB_AUGMENT(elm); \ + if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field))) { \ + if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \ + RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \ + else \ + RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \ + } else \ + (head)->rbh_root = (tmp); \ + RB_RIGHT(tmp, field) = (elm); \ + RB_PARENT(elm, field) = (tmp); \ + RB_AUGMENT(tmp); \ + if ((RB_PARENT(tmp, field))) \ + RB_AUGMENT(RB_PARENT(tmp, field)); \ +} while (0) + +/* Generates prototypes and inline functions */ +#define RB_PROTOTYPE(name, type, field, cmp) \ + RB_PROTOTYPE_INTERNAL(name, type, field, cmp,) +#define RB_PROTOTYPE_STATIC(name, type, field, cmp) \ + RB_PROTOTYPE_INTERNAL(name, type, field, cmp, __attribute__((__unused__)) static) +#define RB_PROTOTYPE_INTERNAL(name, type, field, cmp, attr) \ +attr void name##_RB_INSERT_COLOR(struct name *, struct type *); \ +attr void name##_RB_REMOVE_COLOR(struct name *, struct type *, struct type *);\ +attr struct type *name##_RB_REMOVE(struct name *, struct type *); \ +attr struct type *name##_RB_INSERT(struct name *, struct type *); \ +attr struct type *name##_RB_FIND(struct name *, struct type *); \ +attr struct type *name##_RB_NFIND(struct name *, struct type *); \ +attr struct type *name##_RB_NEXT(struct type *); \ +attr struct type *name##_RB_PREV(struct type *); \ +attr struct type *name##_RB_MINMAX(struct name *, int); \ + \ + +/* Main rb operation. + * Moves node close to the key of elm to top + */ +#define RB_GENERATE(name, type, field, cmp) \ + RB_GENERATE_INTERNAL(name, type, field, cmp,) +#define RB_GENERATE_STATIC(name, type, field, cmp) \ + RB_GENERATE_INTERNAL(name, type, field, cmp, __attribute__((__unused__)) static) +#define RB_GENERATE_INTERNAL(name, type, field, cmp, attr) \ +attr void \ +name##_RB_INSERT_COLOR(struct name *head, struct type *elm) \ +{ \ + struct type *parent, *gparent, *tmp; \ + while ((parent = RB_PARENT(elm, field)) && \ + RB_COLOR(parent, field) == RB_RED) { \ + gparent = RB_PARENT(parent, field); \ + if (parent == RB_LEFT(gparent, field)) { \ + tmp = RB_RIGHT(gparent, field); \ + if (tmp && RB_COLOR(tmp, field) == RB_RED) { \ + RB_COLOR(tmp, field) = RB_BLACK; \ + RB_SET_BLACKRED(parent, gparent, field);\ + elm = gparent; \ + continue; \ + } \ + if (RB_RIGHT(parent, field) == elm) { \ + RB_ROTATE_LEFT(head, parent, tmp, field);\ + tmp = parent; \ + parent = elm; \ + elm = tmp; \ + } \ + RB_SET_BLACKRED(parent, gparent, field); \ + RB_ROTATE_RIGHT(head, gparent, tmp, field); \ + } else { \ + tmp = RB_LEFT(gparent, field); \ + if (tmp && RB_COLOR(tmp, field) == RB_RED) { \ + RB_COLOR(tmp, field) = RB_BLACK; \ + RB_SET_BLACKRED(parent, gparent, field);\ + elm = gparent; \ + continue; \ + } \ + if (RB_LEFT(parent, field) == elm) { \ + RB_ROTATE_RIGHT(head, parent, tmp, field);\ + tmp = parent; \ + parent = elm; \ + elm = tmp; \ + } \ + RB_SET_BLACKRED(parent, gparent, field); \ + RB_ROTATE_LEFT(head, gparent, tmp, field); \ + } \ + } \ + RB_COLOR(head->rbh_root, field) = RB_BLACK; \ +} \ + \ +attr void \ +name##_RB_REMOVE_COLOR(struct name *head, struct type *parent, struct type *elm) \ +{ \ + struct type *tmp; \ + while ((elm == NULL || RB_COLOR(elm, field) == RB_BLACK) && \ + elm != RB_ROOT(head)) { \ + if (RB_LEFT(parent, field) == elm) { \ + tmp = RB_RIGHT(parent, field); \ + if (RB_COLOR(tmp, field) == RB_RED) { \ + RB_SET_BLACKRED(tmp, parent, field); \ + RB_ROTATE_LEFT(head, parent, tmp, field);\ + tmp = RB_RIGHT(parent, field); \ + } \ + if ((RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\ + (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\ + RB_COLOR(tmp, field) = RB_RED; \ + elm = parent; \ + parent = RB_PARENT(elm, field); \ + } else { \ + if (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK) {\ + struct type *oleft; \ + if ((oleft = RB_LEFT(tmp, field)))\ + RB_COLOR(oleft, field) = RB_BLACK;\ + RB_COLOR(tmp, field) = RB_RED; \ + RB_ROTATE_RIGHT(head, tmp, oleft, field);\ + tmp = RB_RIGHT(parent, field); \ + } \ + RB_COLOR(tmp, field) = RB_COLOR(parent, field);\ + RB_COLOR(parent, field) = RB_BLACK; \ + if (RB_RIGHT(tmp, field)) \ + RB_COLOR(RB_RIGHT(tmp, field), field) = RB_BLACK;\ + RB_ROTATE_LEFT(head, parent, tmp, field);\ + elm = RB_ROOT(head); \ + break; \ + } \ + } else { \ + tmp = RB_LEFT(parent, field); \ + if (RB_COLOR(tmp, field) == RB_RED) { \ + RB_SET_BLACKRED(tmp, parent, field); \ + RB_ROTATE_RIGHT(head, parent, tmp, field);\ + tmp = RB_LEFT(parent, field); \ + } \ + if ((RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\ + (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\ + RB_COLOR(tmp, field) = RB_RED; \ + elm = parent; \ + parent = RB_PARENT(elm, field); \ + } else { \ + if (RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) {\ + struct type *oright; \ + if ((oright = RB_RIGHT(tmp, field)))\ + RB_COLOR(oright, field) = RB_BLACK;\ + RB_COLOR(tmp, field) = RB_RED; \ + RB_ROTATE_LEFT(head, tmp, oright, field);\ + tmp = RB_LEFT(parent, field); \ + } \ + RB_COLOR(tmp, field) = RB_COLOR(parent, field);\ + RB_COLOR(parent, field) = RB_BLACK; \ + if (RB_LEFT(tmp, field)) \ + RB_COLOR(RB_LEFT(tmp, field), field) = RB_BLACK;\ + RB_ROTATE_RIGHT(head, parent, tmp, field);\ + elm = RB_ROOT(head); \ + break; \ + } \ + } \ + } \ + if (elm) \ + RB_COLOR(elm, field) = RB_BLACK; \ +} \ + \ +attr struct type * \ +name##_RB_REMOVE(struct name *head, struct type *elm) \ +{ \ + struct type *child, *parent, *old = elm; \ + int color; \ + if (RB_LEFT(elm, field) == NULL) \ + child = RB_RIGHT(elm, field); \ + else if (RB_RIGHT(elm, field) == NULL) \ + child = RB_LEFT(elm, field); \ + else { \ + struct type *left; \ + elm = RB_RIGHT(elm, field); \ + while ((left = RB_LEFT(elm, field))) \ + elm = left; \ + child = RB_RIGHT(elm, field); \ + parent = RB_PARENT(elm, field); \ + color = RB_COLOR(elm, field); \ + if (child) \ + RB_PARENT(child, field) = parent; \ + if (parent) { \ + if (RB_LEFT(parent, field) == elm) \ + RB_LEFT(parent, field) = child; \ + else \ + RB_RIGHT(parent, field) = child; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = child; \ + if (RB_PARENT(elm, field) == old) \ + parent = elm; \ + (elm)->field = (old)->field; \ + if (RB_PARENT(old, field)) { \ + if (RB_LEFT(RB_PARENT(old, field), field) == old)\ + RB_LEFT(RB_PARENT(old, field), field) = elm;\ + else \ + RB_RIGHT(RB_PARENT(old, field), field) = elm;\ + RB_AUGMENT(RB_PARENT(old, field)); \ + } else \ + RB_ROOT(head) = elm; \ + RB_PARENT(RB_LEFT(old, field), field) = elm; \ + if (RB_RIGHT(old, field)) \ + RB_PARENT(RB_RIGHT(old, field), field) = elm; \ + if (parent) { \ + left = parent; \ + do { \ + RB_AUGMENT(left); \ + } while ((left = RB_PARENT(left, field))); \ + } \ + goto color; \ + } \ + parent = RB_PARENT(elm, field); \ + color = RB_COLOR(elm, field); \ + if (child) \ + RB_PARENT(child, field) = parent; \ + if (parent) { \ + if (RB_LEFT(parent, field) == elm) \ + RB_LEFT(parent, field) = child; \ + else \ + RB_RIGHT(parent, field) = child; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = child; \ +color: \ + if (color == RB_BLACK) \ + name##_RB_REMOVE_COLOR(head, parent, child); \ + return (old); \ +} \ + \ +/* Inserts a node into the RB tree */ \ +attr struct type * \ +name##_RB_INSERT(struct name *head, struct type *elm) \ +{ \ + struct type *tmp; \ + struct type *parent = NULL; \ + int comp = 0; \ + tmp = RB_ROOT(head); \ + while (tmp) { \ + parent = tmp; \ + comp = (cmp)(elm, parent); \ + if (comp < 0) \ + tmp = RB_LEFT(tmp, field); \ + else if (comp > 0) \ + tmp = RB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + RB_SET(elm, parent, field); \ + if (parent != NULL) { \ + if (comp < 0) \ + RB_LEFT(parent, field) = elm; \ + else \ + RB_RIGHT(parent, field) = elm; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = elm; \ + name##_RB_INSERT_COLOR(head, elm); \ + return (NULL); \ +} \ + \ +/* Finds the node with the same key as elm */ \ +attr struct type * \ +name##_RB_FIND(struct name *head, struct type *elm) \ +{ \ + struct type *tmp = RB_ROOT(head); \ + int comp; \ + while (tmp) { \ + comp = cmp(elm, tmp); \ + if (comp < 0) \ + tmp = RB_LEFT(tmp, field); \ + else if (comp > 0) \ + tmp = RB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + return (NULL); \ +} \ + \ +/* Finds the first node greater than or equal to the search key */ \ +attr struct type * \ +name##_RB_NFIND(struct name *head, struct type *elm) \ +{ \ + struct type *tmp = RB_ROOT(head); \ + struct type *res = NULL; \ + int comp; \ + while (tmp) { \ + comp = cmp(elm, tmp); \ + if (comp < 0) { \ + res = tmp; \ + tmp = RB_LEFT(tmp, field); \ + } \ + else if (comp > 0) \ + tmp = RB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + return (res); \ +} \ + \ +attr struct type * \ +name##_RB_NEXT(struct type *elm) \ +{ \ + if (RB_RIGHT(elm, field)) { \ + elm = RB_RIGHT(elm, field); \ + while (RB_LEFT(elm, field)) \ + elm = RB_LEFT(elm, field); \ + } else { \ + if (RB_PARENT(elm, field) && \ + (elm == RB_LEFT(RB_PARENT(elm, field), field))) \ + elm = RB_PARENT(elm, field); \ + else { \ + while (RB_PARENT(elm, field) && \ + (elm == RB_RIGHT(RB_PARENT(elm, field), field)))\ + elm = RB_PARENT(elm, field); \ + elm = RB_PARENT(elm, field); \ + } \ + } \ + return (elm); \ +} \ + \ +attr struct type * \ +name##_RB_PREV(struct type *elm) \ +{ \ + if (RB_LEFT(elm, field)) { \ + elm = RB_LEFT(elm, field); \ + while (RB_RIGHT(elm, field)) \ + elm = RB_RIGHT(elm, field); \ + } else { \ + if (RB_PARENT(elm, field) && \ + (elm == RB_RIGHT(RB_PARENT(elm, field), field))) \ + elm = RB_PARENT(elm, field); \ + else { \ + while (RB_PARENT(elm, field) && \ + (elm == RB_LEFT(RB_PARENT(elm, field), field)))\ + elm = RB_PARENT(elm, field); \ + elm = RB_PARENT(elm, field); \ + } \ + } \ + return (elm); \ +} \ + \ +attr struct type * \ +name##_RB_MINMAX(struct name *head, int val) \ +{ \ + struct type *tmp = RB_ROOT(head); \ + struct type *parent = NULL; \ + while (tmp) { \ + parent = tmp; \ + if (val < 0) \ + tmp = RB_LEFT(tmp, field); \ + else \ + tmp = RB_RIGHT(tmp, field); \ + } \ + return (parent); \ +} + +#define RB_NEGINF -1 +#define RB_INF 1 + +#define RB_INSERT(name, x, y) name##_RB_INSERT(x, y) +#define RB_REMOVE(name, x, y) name##_RB_REMOVE(x, y) +#define RB_FIND(name, x, y) name##_RB_FIND(x, y) +#define RB_NFIND(name, x, y) name##_RB_NFIND(x, y) +#define RB_NEXT(name, x, y) name##_RB_NEXT(y) +#define RB_PREV(name, x, y) name##_RB_PREV(y) +#define RB_MIN(name, x) name##_RB_MINMAX(x, RB_NEGINF) +#define RB_MAX(name, x) name##_RB_MINMAX(x, RB_INF) + +#define RB_FOREACH(x, name, head) \ + for ((x) = RB_MIN(name, head); \ + (x) != NULL; \ + (x) = name##_RB_NEXT(x)) + +#define RB_FOREACH_SAFE(x, name, head, y) \ + for ((x) = RB_MIN(name, head); \ + ((x) != NULL) && ((y) = name##_RB_NEXT(x), 1); \ + (x) = (y)) + +#define RB_FOREACH_REVERSE(x, name, head) \ + for ((x) = RB_MAX(name, head); \ + (x) != NULL; \ + (x) = name##_RB_PREV(x)) + +#define RB_FOREACH_REVERSE_SAFE(x, name, head, y) \ + for ((x) = RB_MAX(name, head); \ + ((x) != NULL) && ((y) = name##_RB_PREV(x), 1); \ + (x) = (y)) + + +/* + * Copyright (c) 2016 David Gwynne + * + * 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. + */ + +struct rb_type { + int (*t_compare)(const void *, const void *); + void (*t_augment)(void *); + unsigned int t_offset; /* offset of rb_entry in type */ +}; + +struct rb_tree { + struct rb_entry *rbt_root; +}; + +struct rb_entry { + struct rb_entry *rbt_parent; + struct rb_entry *rbt_left; + struct rb_entry *rbt_right; + unsigned int rbt_color; +}; + +#define RBT_HEAD(_name, _type) \ +struct _name { \ + struct rb_tree rbh_root; \ +} + +#define RBT_ENTRY(_type) struct rb_entry + +static inline void +_rb_init(struct rb_tree *rbt) +{ + rbt->rbt_root = NULL; +} + +static inline int +_rb_empty(struct rb_tree *rbt) +{ + return (rbt->rbt_root == NULL); +} + +void *_rb_insert(const struct rb_type *, struct rb_tree *, void *); +void *_rb_remove(const struct rb_type *, struct rb_tree *, void *); +void *_rb_find(const struct rb_type *, struct rb_tree *, const void *); +void *_rb_nfind(const struct rb_type *, struct rb_tree *, const void *); +void *_rb_root(const struct rb_type *, struct rb_tree *); +void *_rb_min(const struct rb_type *, struct rb_tree *); +void *_rb_max(const struct rb_type *, struct rb_tree *); +void *_rb_next(const struct rb_type *, void *); +void *_rb_prev(const struct rb_type *, void *); +void *_rb_left(const struct rb_type *, void *); +void *_rb_right(const struct rb_type *, void *); +void *_rb_parent(const struct rb_type *, void *); +void _rb_set_left(const struct rb_type *, void *, void *); +void _rb_set_right(const struct rb_type *, void *, void *); +void _rb_set_parent(const struct rb_type *, void *, void *); +void _rb_poison(const struct rb_type *, void *, unsigned long); +int _rb_check(const struct rb_type *, void *, unsigned long); + +#define RBT_INITIALIZER(_head) { { NULL } } + +#define RBT_PROTOTYPE(_name, _type, _field, _cmp) \ +extern const struct rb_type *const _name##_RBT_TYPE; \ + \ +__unused static inline void \ +_name##_RBT_INIT(struct _name *head) \ +{ \ + _rb_init(&head->rbh_root); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_INSERT(struct _name *head, struct _type *elm) \ +{ \ + return _rb_insert(_name##_RBT_TYPE, &head->rbh_root, elm); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_REMOVE(struct _name *head, struct _type *elm) \ +{ \ + return _rb_remove(_name##_RBT_TYPE, &head->rbh_root, elm); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_FIND(struct _name *head, const struct _type *key) \ +{ \ + return _rb_find(_name##_RBT_TYPE, &head->rbh_root, key); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_NFIND(struct _name *head, const struct _type *key) \ +{ \ + return _rb_nfind(_name##_RBT_TYPE, &head->rbh_root, key); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_ROOT(struct _name *head) \ +{ \ + return _rb_root(_name##_RBT_TYPE, &head->rbh_root); \ +} \ + \ +__unused static inline int \ +_name##_RBT_EMPTY(struct _name *head) \ +{ \ + return _rb_empty(&head->rbh_root); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_MIN(struct _name *head) \ +{ \ + return _rb_min(_name##_RBT_TYPE, &head->rbh_root); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_MAX(struct _name *head) \ +{ \ + return _rb_max(_name##_RBT_TYPE, &head->rbh_root); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_NEXT(struct _type *elm) \ +{ \ + return _rb_next(_name##_RBT_TYPE, elm); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_PREV(struct _type *elm) \ +{ \ + return _rb_prev(_name##_RBT_TYPE, elm); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_LEFT(struct _type *elm) \ +{ \ + return _rb_left(_name##_RBT_TYPE, elm); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_RIGHT(struct _type *elm) \ +{ \ + return _rb_right(_name##_RBT_TYPE, elm); \ +} \ + \ +__unused static inline struct _type * \ +_name##_RBT_PARENT(struct _type *elm) \ +{ \ + return _rb_parent(_name##_RBT_TYPE, elm); \ +} \ + \ +__unused static inline void \ +_name##_RBT_SET_LEFT(struct _type *elm, struct _type *left) \ +{ \ + _rb_set_left(_name##_RBT_TYPE, elm, left); \ +} \ + \ +__unused static inline void \ +_name##_RBT_SET_RIGHT(struct _type *elm, struct _type *right) \ +{ \ + _rb_set_right(_name##_RBT_TYPE, elm, right); \ +} \ + \ +__unused static inline void \ +_name##_RBT_SET_PARENT(struct _type *elm, struct _type *parent) \ +{ \ + _rb_set_parent(_name##_RBT_TYPE, elm, parent); \ +} \ + \ +__unused static inline void \ +_name##_RBT_POISON(struct _type *elm, unsigned long poison) \ +{ \ + _rb_poison(_name##_RBT_TYPE, elm, poison); \ +} \ + \ +__unused static inline int \ +_name##_RBT_CHECK(struct _type *elm, unsigned long poison) \ +{ \ + return _rb_check(_name##_RBT_TYPE, elm, poison); \ +} + +#define RBT_GENERATE_INTERNAL(_name, _type, _field, _cmp, _aug) \ +static int \ +_name##_RBT_COMPARE(const void *lptr, const void *rptr) \ +{ \ + const struct _type *l = lptr, *r = rptr; \ + return _cmp(l, r); \ +} \ +static const struct rb_type _name##_RBT_INFO = { \ + _name##_RBT_COMPARE, \ + _aug, \ + offsetof(struct _type, _field), \ +}; \ +const struct rb_type *const _name##_RBT_TYPE = &_name##_RBT_INFO + +#define RBT_GENERATE_AUGMENT(_name, _type, _field, _cmp, _aug) \ +static void \ +_name##_RBT_AUGMENT(void *ptr) \ +{ \ + struct _type *p = ptr; \ + return _aug(p); \ +} \ +RBT_GENERATE_INTERNAL(_name, _type, _field, _cmp, _name##_RBT_AUGMENT) + +#define RBT_GENERATE(_name, _type, _field, _cmp) \ + RBT_GENERATE_INTERNAL(_name, _type, _field, _cmp, NULL) + +#define RBT_INIT(_name, _head) _name##_RBT_INIT(_head) +#define RBT_INSERT(_name, _head, _elm) _name##_RBT_INSERT(_head, _elm) +#define RBT_REMOVE(_name, _head, _elm) _name##_RBT_REMOVE(_head, _elm) +#define RBT_FIND(_name, _head, _key) _name##_RBT_FIND(_head, _key) +#define RBT_NFIND(_name, _head, _key) _name##_RBT_NFIND(_head, _key) +#define RBT_ROOT(_name, _head) _name##_RBT_ROOT(_head) +#define RBT_EMPTY(_name, _head) _name##_RBT_EMPTY(_head) +#define RBT_MIN(_name, _head) _name##_RBT_MIN(_head) +#define RBT_MAX(_name, _head) _name##_RBT_MAX(_head) +#define RBT_NEXT(_name, _elm) _name##_RBT_NEXT(_elm) +#define RBT_PREV(_name, _elm) _name##_RBT_PREV(_elm) +#define RBT_LEFT(_name, _elm) _name##_RBT_LEFT(_elm) +#define RBT_RIGHT(_name, _elm) _name##_RBT_RIGHT(_elm) +#define RBT_PARENT(_name, _elm) _name##_RBT_PARENT(_elm) +#define RBT_SET_LEFT(_name, _elm, _l) _name##_RBT_SET_LEFT(_elm, _l) +#define RBT_SET_RIGHT(_name, _elm, _r) _name##_RBT_SET_RIGHT(_elm, _r) +#define RBT_SET_PARENT(_name, _elm, _p) _name##_RBT_SET_PARENT(_elm, _p) +#define RBT_POISON(_name, _elm, _p) _name##_RBT_POISON(_elm, _p) +#define RBT_CHECK(_name, _elm, _p) _name##_RBT_CHECK(_elm, _p) + +#define RBT_FOREACH(_e, _name, _head) \ + for ((_e) = RBT_MIN(_name, (_head)); \ + (_e) != NULL; \ + (_e) = RBT_NEXT(_name, (_e))) + +#define RBT_FOREACH_SAFE(_e, _name, _head, _n) \ + for ((_e) = RBT_MIN(_name, (_head)); \ + (_e) != NULL && ((_n) = RBT_NEXT(_name, (_e)), 1); \ + (_e) = (_n)) + +#define RBT_FOREACH_REVERSE(_e, _name, _head) \ + for ((_e) = RBT_MAX(_name, (_head)); \ + (_e) != NULL; \ + (_e) = RBT_PREV(_name, (_e))) + +#define RBT_FOREACH_REVERSE_SAFE(_e, _name, _head, _n) \ + for ((_e) = RBT_MAX(_name, (_head)); \ + (_e) != NULL && ((_n) = RBT_PREV(_name, (_e)), 1); \ + (_e) = (_n)) + +#endif /* _SYS_TREE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/tty.h b/lib/libc/include/generic-openbsd/sys/tty.h new file mode 100644 index 0000000000..cb60f93476 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/tty.h @@ -0,0 +1,332 @@ +/* $OpenBSD: tty.h,v 1.45 2025/09/25 08:46:50 mvs Exp $ */ +/* $NetBSD: tty.h,v 1.30.4.1 1996/06/02 09:08:13 mrg Exp $ */ + +/*- + * Copyright (c) 1982, 1986, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)tty.h 8.6 (Berkeley) 1/21/94 + */ + +#include +#include +#include /* For struct selinfo. */ +#include + +#define KERN_TTY_TKNIN 1 /* quad: input chars */ +#define KERN_TTY_TKNOUT 2 /* quad: output chars */ +#define KERN_TTY_TKRAWCC 3 /* quad: input chars, raw mode */ +#define KERN_TTY_TKCANCC 4 /* quad: input char, cooked mode */ +#define KERN_TTY_INFO 5 /* struct: tty stats */ +/* was KERN_TTY_MAXPTYS 6 */ +/* was KERN_TTY_NPTYS 7 */ +#define KERN_TTY_MAXID 8 + +#define CTL_KERN_TTY_NAMES { \ + { 0, 0 }, \ + { "tk_nin", CTLTYPE_QUAD }, \ + { "tk_nout", CTLTYPE_QUAD }, \ + { "tk_rawcc", CTLTYPE_QUAD }, \ + { "tk_cancc", CTLTYPE_QUAD }, \ + { "ttyinfo", CTLTYPE_STRUCT }, \ + { "gap", 0 }, \ + { "gap", 0 }, \ +} + +/* ptmget, for /dev/ptm pty getting ioctl PTMGET */ + +struct ptmget { + int cfd; + int sfd; + char cn[16]; + char sn[16]; +}; +#define PTMGET _IOR('t', 1, struct ptmget) /* get ptys */ +#define PATH_PTMDEV "/dev/ptm" +#define TTY_GID 4 /* XXX evil hardcoding of tty gid */ + +/* + * Clists are actually ring buffers. The c_cc, c_cf, c_cl fields have + * exactly the same behaviour as in true clists. + * if c_cq is NULL, the ring buffer has no TTY_QUOTE functionality + * (but, saves memory and cpu time) + * + * *DON'T* play with c_cs, c_ce, c_cq, or c_cl outside tty_subr.c!!! + */ +struct clist { + int c_cc; /* count of characters in queue */ + int c_cn; /* total ring buffer length */ + u_char *c_cf; /* points to first character */ + u_char *c_cl; /* points to next open character */ + u_char *c_cs; /* start of ring buffer */ + u_char *c_ce; /* c_ce + c_len */ + u_char *c_cq; /* N bits/bytes long, see tty_subr.c */ +}; + +/* + * Per-tty structure. + * + * Should be split in two, into device and tty drivers. + * Glue could be masks of what to echo and circular buffer + * (low, high, timeout). + */ +struct tty { + TAILQ_ENTRY(tty) tty_link; /* Link in global tty list. */ + struct clist t_rawq; /* Device raw input queue. */ + long t_rawcc; /* Raw input queue statistics. */ + struct clist t_canq; /* Device canonical queue. */ + long t_cancc; /* Canonical queue statistics. */ + struct clist t_outq; /* Device output queue. */ + long t_outcc; /* Output queue statistics. */ + int t_qlen; /* Length of above queues */ + u_char t_line; /* Interface to device drivers. */ + dev_t t_dev; /* Device. */ + int t_state; /* Device and driver (TS*) state. */ + int t_flags; /* Tty flags. */ + struct pgrp *t_pgrp; /* Foreground process group. */ + struct session *t_session; /* Enclosing session. */ + struct selinfo t_rsel; /* Tty read/oob select. */ + struct selinfo t_wsel; /* Tty write select. */ + struct termios t_termios; /* Termios state. */ + struct winsize t_winsize; /* Window size. */ + /* Start output. */ + void (*t_oproc)(struct tty *); + /* Set hardware state. */ + int (*t_param)(struct tty *, struct termios *); + /* Set hardware flow control. */ + int (*t_hwiflow)(struct tty *tp, int flag); + void *t_sc; /* XXX: net/if_sl.c:sl_softc. */ + short t_column; /* Tty output column. */ + short t_rocount, t_rocol; /* Tty. */ + short t_hiwat; /* High water mark. */ + short t_lowat; /* Low water mark. */ + short t_gen; /* Generation number. */ + struct timeout t_rstrt_to; /* restart timeout */ + struct timeval t_tv; /* timestamp */ +}; + +/* + * Small version of struct tty exported via sysctl KERN_TTY_INFO + */ +struct itty { + dev_t t_dev; + int t_rawq_c_cc; + int t_canq_c_cc; + int t_outq_c_cc; + short t_hiwat; + short t_lowat; + short t_column; + int t_state; + struct session *t_session; + pid_t t_pgrp_pg_id; + u_char t_line; +}; + +#define t_cc t_termios.c_cc +#define t_cflag t_termios.c_cflag +#define t_iflag t_termios.c_iflag +#define t_ispeed t_termios.c_ispeed +#define t_lflag t_termios.c_lflag +#define t_min t_termios.c_min +#define t_oflag t_termios.c_oflag +#define t_ospeed t_termios.c_ospeed +#define t_time t_termios.c_time + +#define TTIPRI 25 /* Sleep priority for tty reads. */ +#define TTOPRI 26 /* Sleep priority for tty writes. */ + +#define OBUFSIZ 512 +#define TTYHOG(tp) (tp)->t_qlen + +#ifdef _KERNEL +#define TTMAXLOWAT 256 +#define TTMINLOWAT 32 +#define TTMINHIWAT 100 +#define TTHIWATMINSPACE 200 /* Min space above hiwat */ +#endif + +/* These flags are kept in t_state. */ +#define TS_ASLEEP 0x00001 /* Process waiting for tty. */ +#define TS_ASYNC 0x00002 /* Tty in async I/O mode. */ +#define TS_BUSY 0x00004 /* Draining output. */ +#define TS_CARR_ON 0x00008 /* Carrier is present. */ +#define TS_FLUSH 0x00010 /* Outq has been flushed during DMA. */ +#define TS_ISOPEN 0x00020 /* Open has completed. */ +#define TS_TBLOCK 0x00040 /* Further input blocked. */ +#define TS_TIMEOUT 0x00080 /* Wait for output char processing. */ +#define TS_TTSTOP 0x00100 /* Output paused. */ +#define TS_WOPEN 0x00200 /* Open in progress. */ +#define TS_XCLUDE 0x00400 /* Tty requires exclusivity. */ + +/* State for intra-line fancy editing work. */ +#define TS_BKSL 0x00800 /* State for lowercase \ work. */ +#define TS_CNTTB 0x01000 /* Counting tab width, ignore FLUSHO. */ +#define TS_ERASE 0x02000 /* Within a \.../ for PRTRUB. */ +#define TS_LNCH 0x04000 /* Next character is literal. */ +#define TS_TYPEN 0x08000 /* Retyping suspended input (PENDIN). */ +#define TS_LOCAL (TS_BKSL | TS_CNTTB | TS_ERASE | TS_LNCH | TS_TYPEN) + +#define TS_TSTAMPDCDSET 0x10000 /* update timestamp on DCD set */ +#define TS_TSTAMPDCDCLR 0x20000 /* update timestamp on DCD clr */ +#define TS_TSTAMPCTSSET 0x40000 /* update timestamp on CTS set */ +#define TS_TSTAMPCTSCLR 0x80000 /* update timestamp on CTS clr */ + +/* Character type information. */ +#define ORDINARY 0 +#define CONTROL 1 +#define BACKSPACE 2 +#define NEWLINE 3 +#define TAB 4 +#define VTAB 5 +#define RETURN 6 + +struct speedtab { + int sp_speed; /* Speed. */ + int sp_code; /* Code. */ +}; + +/* Modem control commands (driver). */ +#define DMSET 0 +#define DMBIS 1 +#define DMBIC 2 +#define DMGET 3 + +/* Flags on a character passed to ttyinput. */ +#define TTY_CHARMASK 0x000000ff /* Character mask */ +#define TTY_QUOTE 0x00000100 /* Character quoted */ +#define TTY_ERRORMASK 0xff000000 /* Error mask */ +#define TTY_FE 0x01000000 /* Framing error or BREAK condition */ +#define TTY_PE 0x02000000 /* Parity error */ + +/* Is tp controlling terminal for pr? */ +#define isctty(pr, tp) \ + ((pr)->ps_session == (tp)->t_session && (pr)->ps_flags & PS_CONTROLT) + +/* Is pr in background of tp? */ +#define isbackground(pr, tp) \ + (isctty((pr), (tp)) && (pr)->ps_pgrp != (tp)->t_pgrp) + +/* + * ttylist_head is defined here so that user-land has access to it. + */ +TAILQ_HEAD(ttylist_head, tty); /* the ttylist is a TAILQ */ + +#ifdef _KERNEL + +extern int tty_count; /* number of ttys in global ttylist */ + +/* Symbolic sleep message strings. */ +extern char ttyin[], ttyout[], ttopen[], ttclos[], ttybg[]; + +extern int64_t tk_cancc, tk_nin, tk_nout, tk_rawcc; + +int sysctl_tty(int *, u_int, void *, size_t *, void *, size_t); +int sysctl_pty(int *, u_int, void *, size_t *, void *, size_t); + +int b_to_q(u_char *cp, int cc, struct clist *q); +void catq(struct clist *from, struct clist *to); +int getc(struct clist *q); +void ndflush(struct clist *q, int cc); +int ndqb(struct clist *q, int flag); +u_char *firstc(struct clist *clp, int *c, int *cc); +u_char *nextc(struct clist *q, u_char *cp, int *c, int *cc); +int putc(int c, struct clist *q); +int q_to_b(struct clist *q, u_char *cp, int cc); +int unputc(struct clist *q); + +int nullmodem(struct tty *tp, int flag); +int tputchar(int c, struct tty *tp); +int ttioctl(struct tty *tp, u_long com, caddr_t data, int flag, + struct proc *p); +int ttread(struct tty *tp, struct uio *uio, int flag); +void ttrstrt(void *tp); +int ttkqfilter(dev_t dev, struct knote *kn); +void ttsetwater(struct tty *tp); +int ttspeedtab(int speed, const struct speedtab *table); +int ttstart(struct tty *tp); +void ttwakeupwr(struct tty *tp); +void ttwakeup(struct tty *tp); +int ttwrite(struct tty *tp, struct uio *uio, int flag); +void ttychars(struct tty *tp); +int ttycheckoutq(struct tty *tp, int wait); +int ttyclose(struct tty *tp); +void ttyflush(struct tty *tp, int rw); +void ttyinfo(struct tty *tp); +int ttyinput(int c, struct tty *tp); +int ttylclose(struct tty *tp, int flag, struct proc *p); +int ttymodem(struct tty *tp, int flag); +int ttyopen(dev_t device, struct tty *tp, struct proc *p); +int ttyoutput(int c, struct tty *tp); +void ttypend(struct tty *tp); +int ttyretype(struct tty *tp); +int ttyrub(int c, struct tty *tp); +int ttysleep(struct tty *tp, void *chan, int pri, char *wmesg); +int ttysleep_nsec(struct tty *, void *, int, char *, uint64_t); +int ttywait(struct tty *tp); +int ttywflush(struct tty *tp); +void ttytstamp(struct tty *tp, int octs, int ncts, int odcd, int ndcd); + +void tty_init(void); +struct tty *ttymalloc(int); +void ttyfree(struct tty *); + +int cttyopen(dev_t, int, int, struct proc *); +int cttyread(dev_t, struct uio *, int); +int cttywrite(dev_t, struct uio *, int); +int cttyioctl(dev_t, u_long, caddr_t, int, struct proc *); + +void clalloc(struct clist *, int, int); +void clfree(struct clist *); + +int nullioctl(struct tty *, u_long, caddr_t, int, struct proc *); + +int pppopen(dev_t dev, struct tty *, struct proc *); +int pppclose(struct tty *, int, struct proc *); +int ppptioctl(struct tty *, u_long, caddr_t, int, struct proc *); +int pppinput(int c, struct tty *); +int pppstart(struct tty *); +int pppread(struct tty *, struct uio *, int); +int pppwrite(struct tty *, struct uio *, int); + +int nmeaopen(dev_t, struct tty *, struct proc *); +int nmeaclose(struct tty *, int, struct proc *); +int nmeainput(int, struct tty *); + +int mstsopen(dev_t, struct tty *, struct proc *); +int mstsclose(struct tty *, int, struct proc *); +int mstsinput(int, struct tty *); + +int endrunopen(dev_t, struct tty *, struct proc *); +int endrunclose(struct tty *, int, struct proc *); +int endruninput(int, struct tty *); + +#endif /* _KERNEL */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/ttycom.h b/lib/libc/include/generic-openbsd/sys/ttycom.h new file mode 100644 index 0000000000..757d49a85b --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/ttycom.h @@ -0,0 +1,151 @@ +/* $OpenBSD: ttycom.h,v 1.17 2018/06/16 13:55:03 deraadt Exp $ */ +/* $NetBSD: ttycom.h,v 1.4 1996/05/19 17:17:53 jonathan Exp $ */ + +/*- + * Copyright (c) 1982, 1986, 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)ttycom.h 8.1 (Berkeley) 3/28/94 + */ + +#ifndef _SYS_TTYCOM_H_ +#define _SYS_TTYCOM_H_ + +#include + +/* Tty ioctl's. */ + +/* + * Window/terminal size structure. This information is stored by the kernel + * in order to provide a consistent interface, but is not used by the kernel. + */ +struct winsize { + unsigned short ws_row; /* rows, in characters */ + unsigned short ws_col; /* columns, in characters */ + unsigned short ws_xpixel; /* horizontal size, pixels */ + unsigned short ws_ypixel; /* vertical size, pixels */ +}; + +struct tstamps { + int ts_set; /* TIOCM_CAR and/or TIOCM_CTS */ + int ts_clr; +}; + +#define TIOCM_LE 0001 /* line enable */ +#define TIOCM_DTR 0002 /* data terminal ready */ +#define TIOCM_RTS 0004 /* request to send */ +#define TIOCM_ST 0010 /* secondary transmit */ +#define TIOCM_SR 0020 /* secondary receive */ +#define TIOCM_CTS 0040 /* clear to send */ +#define TIOCM_CAR 0100 /* carrier detect */ +#define TIOCM_CD TIOCM_CAR +#define TIOCM_RNG 0200 /* ring */ +#define TIOCM_RI TIOCM_RNG +#define TIOCM_DSR 0400 /* data set ready */ + /* 8-10 compat */ +#define TIOCEXCL _IO('t', 13) /* set exclusive use of tty */ +#define TIOCNXCL _IO('t', 14) /* reset exclusive use of tty */ + /* 15 unused */ +#define TIOCFLUSH _IOW('t', 16, int) /* flush buffers */ + /* 17-18 compat */ +#define TIOCGETA _IOR('t', 19, struct termios) /* get termios struct */ +#define TIOCSETA _IOW('t', 20, struct termios) /* set termios struct */ +#define TIOCSETAW _IOW('t', 21, struct termios) /* drain output, set */ +#define TIOCSETAF _IOW('t', 22, struct termios) /* drn out, fls in, set */ +#define TIOCGETD _IOR('t', 26, int) /* get line discipline */ +#define TIOCSETD _IOW('t', 27, int) /* set line discipline */ +#define TIOCSETVERAUTH _IOW('t', 28, int) /* set verified auth */ +#define TIOCCLRVERAUTH _IO('t', 29) /* clear verified auth */ +#define TIOCCHKVERAUTH _IO('t', 30) /* check verified auth */ + /* 127-124 compat */ +#define TIOCSBRK _IO('t', 123) /* set break bit */ +#define TIOCCBRK _IO('t', 122) /* clear break bit */ +#define TIOCSDTR _IO('t', 121) /* set data terminal ready */ +#define TIOCCDTR _IO('t', 120) /* clear data terminal ready */ +#define TIOCGPGRP _IOR('t', 119, int) /* get pgrp of tty */ +#define TIOCSPGRP _IOW('t', 118, int) /* set pgrp of tty */ + /* 117-116 compat */ +#define TIOCOUTQ _IOR('t', 115, int) /* output queue size */ +#define TIOCNOTTY _IO('t', 113) /* void tty association */ +#define TIOCPKT _IOW('t', 112, int) /* pty: set/clear packet mode */ +#define TIOCPKT_DATA 0x00 /* data packet */ +#define TIOCPKT_FLUSHREAD 0x01 /* flush packet */ +#define TIOCPKT_FLUSHWRITE 0x02 /* flush packet */ +#define TIOCPKT_STOP 0x04 /* stop output */ +#define TIOCPKT_START 0x08 /* start output */ +#define TIOCPKT_NOSTOP 0x10 /* no more ^S, ^Q */ +#define TIOCPKT_DOSTOP 0x20 /* now do ^S ^Q */ +#define TIOCPKT_IOCTL 0x40 /* state change of pty driver */ +#define TIOCSTOP _IO('t', 111) /* stop output, like ^S */ +#define TIOCSTART _IO('t', 110) /* start output, like ^Q */ +#define TIOCMSET _IOW('t', 109, int) /* set all modem bits */ +#define TIOCMBIS _IOW('t', 108, int) /* bis modem bits */ +#define TIOCMBIC _IOW('t', 107, int) /* bic modem bits */ +#define TIOCMGET _IOR('t', 106, int) /* get all modem bits */ +#define TIOCREMOTE _IOW('t', 105, int) /* remote input editing */ +#define TIOCGWINSZ _IOR('t', 104, struct winsize) /* get window size */ +#define TIOCSWINSZ _IOW('t', 103, struct winsize) /* set window size */ +#define TIOCUCNTL _IOW('t', 102, int) /* pty: set/clr usr cntl mode */ +#define UIOCCMD(n) _IO('u', n) /* usr cntl op "n" */ +#define TIOCUCNTL_SBRK (TIOCSBRK & 0xff)/* set break bit, usr ctnl */ +#define TIOCUCNTL_CBRK (TIOCCBRK & 0xff)/* clear break bit, usr ctnl */ +#define TIOCSTAT _IO('t', 101) /* generate status message */ +#define TIOCGSID _IOR('t', 99, int) /* get sid of tty */ +#define TIOCCONS _IOW('t', 98, int) /* become virtual console */ +#define TIOCSCTTY _IO('t', 97) /* become controlling tty */ +#define TIOCEXT _IOW('t', 96, int) /* pty: external processing */ +#define TIOCSIG _IOW('t', 95, int) /* pty: generate signal */ +#define TIOCDRAIN _IO('t', 94) /* wait till output drained */ +#define TIOCGFLAGS _IOR('t', 93, int) /* get device flags */ +#define TIOCSFLAGS _IOW('t', 92, int) /* set device flags */ +#define TIOCFLAG_SOFTCAR 0x01 /* ignore hardware carrier */ +#define TIOCFLAG_CLOCAL 0x02 /* set clocal on open */ +#define TIOCFLAG_CRTSCTS 0x04 /* set crtscts on open */ +#define TIOCFLAG_MDMBUF 0x08 /* set mdmbuf on open */ +#define TIOCFLAG_PPS 0x10 /* call hardpps on carrier up */ +#define TIOCGTSTAMP _IOR('t', 91, struct timeval) /* get timestamp */ +#define TIOCSTSTAMP _IOW('t', 90, struct tstamps) /* timestamp reasons */ + +/* Backwards compatibility */ +#define TIOCMODG TIOCMGET +#define TIOCMODS TIOCMSET + +#define TTYDISC 0 /* termios tty line discipline */ +#define TABLDISC 3 /* tablet discipline */ +#define SLIPDISC 4 /* serial IP discipline */ +#define PPPDISC 5 /* ppp discipline */ +#define STRIPDISC 6 /* metricom wireless IP discipline */ +#define NMEADISC 7 /* NMEA0183 discipline */ +#define MSTSDISC 8 /* Meinberg time string discipline */ +#define ENDRUNDISC 9 /* EndRun time format discipline */ + +#endif /* !_SYS_TTYCOM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/ttydefaults.h b/lib/libc/include/generic-openbsd/sys/ttydefaults.h new file mode 100644 index 0000000000..87886c5859 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/ttydefaults.h @@ -0,0 +1,95 @@ +/* $OpenBSD: ttydefaults.h,v 1.7 2019/03/12 11:01:25 nicm Exp $ */ +/* $NetBSD: ttydefaults.h,v 1.8 1996/04/09 20:55:45 cgd Exp $ */ + +/*- + * Copyright (c) 1982, 1986, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)ttydefaults.h 8.4 (Berkeley) 1/21/94 + */ + +/* + * System wide defaults for terminal state. + */ +#ifndef _SYS_TTYDEFAULTS_H_ +#define _SYS_TTYDEFAULTS_H_ + +/* + * Defaults on "first" open. + */ +#define TTYDEF_IFLAG (BRKINT | ICRNL | IMAXBEL | IXON | IXANY) +#define TTYDEF_OFLAG (OPOST | ONLCR) +#define TTYDEF_LFLAG (ECHO | ICANON | ISIG | IEXTEN | ECHOE|ECHOKE|ECHOCTL) +#define TTYDEF_CFLAG (CREAD | CS8 | HUPCL) +#define TTYDEF_SPEED (B9600) + +/* + * Control Character Defaults + */ +#define CTRL(x) (x&037) +#define CEOF CTRL('d') +#define CEOL ((unsigned char)'\377') /* XXX avoid _POSIX_VDISABLE */ +#define CERASE 0177 +#define CINTR CTRL('c') +#define CSTATUS ((unsigned char)'\377') /* XXX avoid _POSIX_VDISABLE */ +#define CKILL CTRL('u') +#define CMIN 1 +#define CQUIT 034 /* FS, ^\ */ +#define CSUSP CTRL('z') +#define CTIME 0 +#define CDSUSP CTRL('y') +#define CSTART CTRL('q') +#define CSTOP CTRL('s') +#define CLNEXT CTRL('v') +#define CDISCARD CTRL('o') +#define CWERASE CTRL('w') +#define CREPRINT CTRL('r') +#define CEOT CEOF +/* compat */ +#define CBRK CEOL +#define CRPRNT CREPRINT +#define CFLUSH CDISCARD + +/* PROTECTED INCLUSION ENDS HERE */ +#endif /* !_SYS_TTYDEFAULTS_H_ */ + +/* + * #define TTYDEFCHARS to include an array of default control characters. + */ +#ifdef TTYDEFCHARS +cc_t ttydefchars[NCCS] = { + CEOF, CEOL, CEOL, CERASE, CWERASE, CKILL, CREPRINT, + _POSIX_VDISABLE, CINTR, CQUIT, CSUSP, CDSUSP, CSTART, CSTOP, CLNEXT, + CDISCARD, CMIN, CTIME, CSTATUS, _POSIX_VDISABLE +}; +#undef TTYDEFCHARS +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/types.h b/lib/libc/include/generic-openbsd/sys/types.h new file mode 100644 index 0000000000..9ea9bab090 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/types.h @@ -0,0 +1,260 @@ +/* $OpenBSD: types.h,v 1.49 2022/08/06 13:31:13 semarie Exp $ */ +/* $NetBSD: types.h,v 1.29 1996/11/15 22:48:25 jtc Exp $ */ + +/*- + * Copyright (c) 1982, 1986, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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.4 (Berkeley) 1/21/94 + */ + +#ifndef _SYS_TYPES_H_ +#define _SYS_TYPES_H_ + +#include +#if __BSD_VISIBLE +#include +#else +#include +#endif + +#if __BSD_VISIBLE +typedef unsigned char u_char; +typedef unsigned short u_short; +typedef unsigned int u_int; +typedef unsigned long u_long; + +typedef unsigned char unchar; /* Sys V compatibility */ +typedef unsigned short ushort; /* Sys V compatibility */ +typedef unsigned int uint; /* Sys V compatibility */ +typedef unsigned long ulong; /* Sys V compatibility */ + +typedef __cpuid_t cpuid_t; /* CPU id */ +typedef __register_t register_t; /* register-sized type */ +#endif /* __BSD_VISIBLE */ + +/* + * XXX The exact-width bit types should only be exposed if __BSD_VISIBLE + * but the rest of the includes are not ready for that yet. + */ +#ifndef __BIT_TYPES_DEFINED__ +#define __BIT_TYPES_DEFINED__ +#endif + +#ifndef _INT8_T_DEFINED_ +#define _INT8_T_DEFINED_ +typedef __int8_t int8_t; +#endif + +#ifndef _UINT8_T_DEFINED_ +#define _UINT8_T_DEFINED_ +typedef __uint8_t uint8_t; +#endif + +#ifndef _INT16_T_DEFINED_ +#define _INT16_T_DEFINED_ +typedef __int16_t int16_t; +#endif + +#ifndef _UINT16_T_DEFINED_ +#define _UINT16_T_DEFINED_ +typedef __uint16_t uint16_t; +#endif + +#ifndef _INT32_T_DEFINED_ +#define _INT32_T_DEFINED_ +typedef __int32_t int32_t; +#endif + +#ifndef _UINT32_T_DEFINED_ +#define _UINT32_T_DEFINED_ +typedef __uint32_t uint32_t; +#endif + +#ifndef _INT64_T_DEFINED_ +#define _INT64_T_DEFINED_ +typedef __int64_t int64_t; +#endif + +#ifndef _UINT64_T_DEFINED_ +#define _UINT64_T_DEFINED_ +typedef __uint64_t uint64_t; +#endif + +/* BSD-style unsigned bits types */ +typedef __uint8_t u_int8_t; +typedef __uint16_t u_int16_t; +typedef __uint32_t u_int32_t; +typedef __uint64_t u_int64_t; + +/* quads, deprecated in favor of 64 bit int types */ +typedef __int64_t quad_t; +typedef __uint64_t u_quad_t; + +#if __BSD_VISIBLE +/* VM system types */ +typedef __vaddr_t vaddr_t; +typedef __paddr_t paddr_t; +typedef __vsize_t vsize_t; +typedef __psize_t psize_t; +#endif /* __BSD_VISIBLE */ + +/* Standard system types */ +typedef __blkcnt_t blkcnt_t; /* blocks allocated for file */ +typedef __blksize_t blksize_t; /* optimal blocksize for I/O */ +typedef char * caddr_t; /* core address */ +typedef __int32_t daddr32_t; /* 32-bit disk address */ +typedef __int64_t daddr_t; /* 64-bit disk address */ +typedef __dev_t dev_t; /* device number */ +typedef __fixpt_t fixpt_t; /* fixed point number */ +typedef __gid_t gid_t; /* group id */ +typedef __id_t id_t; /* may contain pid, uid or gid */ +typedef __ino_t ino_t; /* inode number */ +typedef __key_t key_t; /* IPC key (for Sys V IPC) */ +typedef __mode_t mode_t; /* permissions */ +typedef __nlink_t nlink_t; /* link count */ +typedef __rlim_t rlim_t; /* resource limit */ +typedef __segsz_t segsz_t; /* segment size */ +typedef __uid_t uid_t; /* user id */ +typedef __useconds_t useconds_t; /* microseconds */ +typedef __suseconds_t suseconds_t; /* microseconds (signed) */ +typedef __fsblkcnt_t fsblkcnt_t; /* file system block count */ +typedef __fsfilcnt_t fsfilcnt_t; /* file system file count */ + +/* + * The following types may be defined in multiple header files. + */ +#ifndef _CLOCK_T_DEFINED_ +#define _CLOCK_T_DEFINED_ +typedef __clock_t clock_t; +#endif + +#ifndef _CLOCKID_T_DEFINED_ +#define _CLOCKID_T_DEFINED_ +typedef __clockid_t clockid_t; +#endif + +#ifndef _PID_T_DEFINED_ +#define _PID_T_DEFINED_ +typedef __pid_t pid_t; +#endif + +#ifndef _SIZE_T_DEFINED_ +#define _SIZE_T_DEFINED_ +typedef __size_t size_t; +#endif + +#ifndef _SSIZE_T_DEFINED_ +#define _SSIZE_T_DEFINED_ +typedef __ssize_t ssize_t; +#endif + +#ifndef _TIME_T_DEFINED_ +#define _TIME_T_DEFINED_ +typedef __time_t time_t; +#endif + +#ifndef _TIMER_T_DEFINED_ +#define _TIMER_T_DEFINED_ +typedef __timer_t timer_t; +#endif + +#ifndef _OFF_T_DEFINED_ +#define _OFF_T_DEFINED_ +typedef __off_t off_t; +#endif + +/* + * These belong in unistd.h, but are placed here too to ensure that + * long arguments will be promoted to off_t if the program fails to + * include that header or explicitly cast them to off_t. + */ +#if __BSD_VISIBLE && !defined(_KERNEL) +__BEGIN_DECLS +off_t lseek(int, off_t, int); +int ftruncate(int, off_t); +int truncate(const char *, off_t); +__END_DECLS +#endif /* __BSD_VISIBLE && !_KERNEL */ + +#if __BSD_VISIBLE +/* Major, minor numbers, dev_t's. */ +#define major(x) (((unsigned)(x) >> 8) & 0xff) +#define minor(x) ((unsigned)((x) & 0xff) | (((x) & 0xffff0000) >> 8)) +#define makedev(x,y) ((dev_t)((((x) & 0xff) << 8) | ((y) & 0xff) | (((y) & 0xffff00) << 8))) +#endif + +#if defined(__STDC__) && defined(_KERNEL) +/* + * Forward structure declarations for function prototypes. We include the + * common structures that cross subsystem boundaries here; others are mostly + * used in the same place that the structure is defined. + */ +struct proc; +struct pgrp; +struct ucred; +struct rusage; +struct file; +struct buf; +struct tty; +struct uio; +#endif + +#ifdef _KERNEL +#if defined(__GNUC__) || \ + (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901) +/* Support for C99: type _Bool is already built-in. */ +#define false 0 +#define true 1 + +#else +/* `_Bool' type must promote to `int' or `unsigned int'. */ +typedef enum { + false = 0, + true = 1 +} _Bool; + +/* And those constants must also be available as macros. */ +#define false false +#define true true + +#endif + +/* User visible type `bool' is provided as a macro which may be redefined */ +#define bool _Bool + +/* Inform that everything is fine */ +#define __bool_true_false_are_defined 1 + +#endif /* _KERNEL */ + +#endif /* !_SYS_TYPES_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/ucred.h b/lib/libc/include/generic-openbsd/sys/ucred.h new file mode 100644 index 0000000000..6f3bdda198 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/ucred.h @@ -0,0 +1,85 @@ +/* $OpenBSD: ucred.h,v 1.14 2022/03/17 14:23:34 visa Exp $ */ +/* $NetBSD: ucred.h,v 1.12 1995/06/01 22:44:50 jtc Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ucred.h 8.2 (Berkeley) 1/4/94 + */ + +#ifndef _SYS_UCRED_H_ +#define _SYS_UCRED_H_ + +#include +#include + +/* + * Credentials. + */ +struct ucred { + struct refcnt cr_refcnt; /* reference count */ + +/* The following fields are all copied by crset() */ +#define cr_startcopy cr_uid + uid_t cr_uid; /* effective user id */ + uid_t cr_ruid; /* Real user id. */ + uid_t cr_svuid; /* Saved effective user id. */ + gid_t cr_gid; /* effective group id */ + gid_t cr_rgid; /* Real group id. */ + gid_t cr_svgid; /* Saved effective group id. */ + short cr_ngroups; /* number of groups */ + gid_t cr_groups[NGROUPS_MAX]; /* groups */ +}; +#define NOCRED ((struct ucred *)-1) /* no credential available */ +#define FSCRED ((struct ucred *)-2) /* filesystem credential */ + +/* + * Userspace version, for use in syscalls arguments + */ +struct xucred { + uid_t cr_uid; /* user id */ + gid_t cr_gid; /* group id */ + short cr_ngroups; /* number of groups */ + gid_t cr_groups[NGROUPS_MAX]; /* groups */ +}; + +#ifdef _KERNEL + +int crfromxucred(struct ucred *, const struct xucred *); +void crset(struct ucred *, const struct ucred *); +struct ucred *crcopy(struct ucred *cr); +struct ucred *crdup(struct ucred *cr); +void crfree(struct ucred *cr); +struct ucred *crget(void); +struct ucred *crhold(struct ucred *); +int suser(struct proc *p); +int suser_ucred(struct ucred *cred); + +#endif /* _KERNEL */ + +#endif /* !_SYS_UCRED_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/uio.h b/lib/libc/include/generic-openbsd/sys/uio.h new file mode 100644 index 0000000000..5e499be184 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/uio.h @@ -0,0 +1,107 @@ +/* $OpenBSD: uio.h,v 1.20 2024/10/26 05:39:03 jsg Exp $ */ +/* $NetBSD: uio.h,v 1.12 1996/02/09 18:25:45 christos Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1993, 1994 + * 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. + * + * @(#)uio.h 8.5 (Berkeley) 2/22/94 + */ + +#ifndef _SYS_UIO_H_ +#define _SYS_UIO_H_ + +#include +#include + +#ifndef _SIZE_T_DEFINED_ +#define _SIZE_T_DEFINED_ +typedef __size_t size_t; +#endif + +#ifndef _SSIZE_T_DEFINED_ +#define _SSIZE_T_DEFINED_ +typedef __ssize_t ssize_t; +#endif + +struct iovec { + void *iov_base; /* Base address. */ + size_t iov_len; /* Length. */ +}; + +#if __BSD_VISIBLE /* needed by kdump */ +enum uio_rw { UIO_READ, UIO_WRITE }; + +/* Segment flag values. */ +enum uio_seg { + UIO_USERSPACE, /* from user data space */ + UIO_SYSSPACE /* from system space */ +}; +#endif /* __BSD_VISIBLE */ + +#ifdef _KERNEL +struct uio { + struct iovec *uio_iov; /* pointer to array of iovecs */ + int uio_iovcnt; /* number of iovecs in array */ + off_t uio_offset; /* offset into file this uio corresponds to */ + size_t uio_resid; /* residual i/o count */ + enum uio_seg uio_segflg; /* see above */ + enum uio_rw uio_rw; /* see above */ + struct proc *uio_procp;/* associated thread or NULL */ +}; + +/* + * Limits + */ +#define UIO_SMALLIOV 8 /* 8 on stack, else malloc */ +#endif /* _KERNEL */ + +#if __BSD_VISIBLE +#define UIO_MAXIOV 1024 /* Deprecated, use IOV_MAX instead */ +#endif + +#ifndef _KERNEL +__BEGIN_DECLS +#if __BSD_VISIBLE +ssize_t preadv(int, const struct iovec *, int, __off_t); +ssize_t pwritev(int, const struct iovec *, int, __off_t); +#endif /* __BSD_VISIBLE */ +ssize_t readv(int, const struct iovec *, int); +ssize_t writev(int, const struct iovec *, int); +__END_DECLS +#else +int ureadc(int c, struct uio *); + +int iovec_copyin(const struct iovec *, struct iovec **, struct iovec *, + unsigned int, size_t *); +void iovec_free(struct iovec *, unsigned int ); +int dofilereadv(struct proc *, int, struct uio *, int, register_t *); +int dofilewritev(struct proc *, int, struct uio *, int, register_t *); + +#endif /* !_KERNEL */ + +#endif /* !_SYS_UIO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/un.h b/lib/libc/include/generic-openbsd/sys/un.h new file mode 100644 index 0000000000..07430f116d --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/un.h @@ -0,0 +1,65 @@ +/* $OpenBSD: un.h,v 1.14 2015/07/18 15:00:01 guenther Exp $ */ +/* $NetBSD: un.h,v 1.11 1996/02/04 02:12:47 christos Exp $ */ + +/* + * Copyright (c) 1982, 1986, 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. + * + * @(#)un.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _SYS_UN_H_ +#define _SYS_UN_H_ + +#include +#include + +#ifndef _SA_FAMILY_T_DEFINED_ +#define _SA_FAMILY_T_DEFINED_ +typedef __sa_family_t sa_family_t; /* sockaddr address family type */ +#endif + +/* + * Definitions for UNIX IPC domain. + */ +struct sockaddr_un { + unsigned char sun_len; /* sockaddr len excluding NUL */ + sa_family_t sun_family; /* AF_UNIX */ + char sun_path[104]; /* path name (gag) */ +}; + +#ifndef _KERNEL +#if __BSD_VISIBLE + +/* actual length of an initialized sockaddr_un */ +#define SUN_LEN(su) \ + (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path)) + +#endif /* __BSD_VISIBLE */ + +#endif /* _KERNEL */ +#endif /* !_SYS_UN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/unistd.h b/lib/libc/include/generic-openbsd/sys/unistd.h new file mode 100644 index 0000000000..7a911b4562 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/unistd.h @@ -0,0 +1,106 @@ +/* $OpenBSD: unistd.h,v 1.31 2015/07/20 00:56:10 guenther Exp $ */ +/* $NetBSD: unistd.h,v 1.10 1994/06/29 06:46:06 cgd Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)unistd.h 8.2 (Berkeley) 1/7/94 + */ + +#ifndef _SYS_UNISTD_H_ +#define _SYS_UNISTD_H_ + +#include + +#define _POSIX_VDISABLE (0377) +#define _POSIX_ASYNC_IO (-1) +#define _POSIX_PRIO_IO (-1) +#define _POSIX_SYNC_IO (-1) + +/* Define the POSIX.1 version we target for compliance. */ +#define _POSIX_VERSION 200809L + +/* access function */ +#define F_OK 0 /* test for existence of file */ +#define X_OK 0x01 /* test for execute or search permission */ +#define W_OK 0x02 /* test for write permission */ +#define R_OK 0x04 /* test for read permission */ + +/* whence values for lseek(2) */ +#define SEEK_SET 0 /* set file offset to offset */ +#define SEEK_CUR 1 /* set file offset to current plus offset */ +#define SEEK_END 2 /* set file offset to EOF plus offset */ + +#if __BSD_VISIBLE +/* old BSD whence values for lseek(2); renamed by POSIX 1003.1 */ +#define L_SET SEEK_SET +#define L_INCR SEEK_CUR +#define L_XTND SEEK_END + +/* the parameters argument passed to the __tfork() syscall */ +struct __tfork { + void *tf_tcb; + pid_t *tf_tid; + void *tf_stack; +}; + +/* the parameters argument for the kbind() syscall */ +struct __kbind { + void *kb_addr; + size_t kb_size; +}; +#define KBIND_BLOCK_MAX 2 /* powerpc, sparc, and sparc64 need 2 blocks */ +#define KBIND_DATA_MAX 24 /* sparc64 needs 6, four-byte words */ +#endif + +/* the pathconf(2) variable values are part of the ABI */ + +/* configurable pathname variables */ +#define _PC_LINK_MAX 1 +#define _PC_MAX_CANON 2 +#define _PC_MAX_INPUT 3 +#define _PC_NAME_MAX 4 +#define _PC_PATH_MAX 5 +#define _PC_PIPE_BUF 6 +#define _PC_CHOWN_RESTRICTED 7 +#define _PC_NO_TRUNC 8 +#define _PC_VDISABLE 9 +#define _PC_2_SYMLINKS 10 +#define _PC_ALLOC_SIZE_MIN 11 +#define _PC_ASYNC_IO 12 +#define _PC_FILESIZEBITS 13 +#define _PC_PRIO_IO 14 +#define _PC_REC_INCR_XFER_SIZE 15 +#define _PC_REC_MAX_XFER_SIZE 16 +#define _PC_REC_MIN_XFER_SIZE 17 +#define _PC_REC_XFER_ALIGN 18 +#define _PC_SYMLINK_MAX 19 +#define _PC_SYNC_IO 20 +#define _PC_TIMESTAMP_RESOLUTION 21 + +#endif /* !_SYS_UNISTD_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/unpcb.h b/lib/libc/include/generic-openbsd/sys/unpcb.h new file mode 100644 index 0000000000..cae6ebd9b4 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/unpcb.h @@ -0,0 +1,145 @@ +/* $OpenBSD: unpcb.h,v 1.45 2022/11/26 17:51:18 mvs Exp $ */ +/* $NetBSD: unpcb.h,v 1.6 1994/06/29 06:46:08 cgd Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)unpcb.h 8.1 (Berkeley) 6/2/93 + */ + +#include + +/* + * Protocol control block for an active + * instance of a UNIX internal protocol. + * + * A socket may be associated with an vnode in the + * file system. If so, the unp_vnode pointer holds + * a reference count to this vnode, which should be vrele'd + * when the socket goes away. + * + * A socket may be connected to another socket, in which + * case the control block of the socket to which it is connected + * is given by unp_conn. + * + * A socket may be referenced by a number of sockets (e.g. several + * sockets may be connected to a datagram socket.) These sockets + * are in a linked list starting with unp_refs, linked through + * unp_nextref and null-terminated. Note that a socket may be referenced + * by a number of other sockets and may also reference a socket (not + * necessarily one which is referencing it). This generates + * the need for unp_refs and unp_nextref to be separate fields. + * + * Stream sockets keep copies of receive sockbuf sb_cc and sb_mbcnt + * so that changes in the sockbuf may be computed to modify + * back pressure on the sender accordingly. + * + * Locks used to protect struct members: + * I immutable after creation + * G unp_gc_lock + * s socket lock + */ + + +struct unpcb { + struct refcnt unp_refcnt; /* references to this pcb */ + struct socket *unp_socket; /* [I] pointer back to socket */ + struct vnode *unp_vnode; /* [s] if associated with file */ + struct file *unp_file; /* [G] backpointer for unp_gc() */ + struct unpcb *unp_conn; /* [s] control block of connected + socket */ + ino_t unp_ino; /* [s] fake inode number */ + SLIST_HEAD(,unpcb) unp_refs; /* [s] referencing socket linked list */ + SLIST_ENTRY(unpcb) unp_nextref; /* [s] link in unp_refs list */ + struct mbuf *unp_addr; /* [s] bound address of socket */ + long unp_msgcount; /* [G] references from socket rcv buf */ + long unp_gcrefs; /* [G] references from gc */ + int unp_flags; /* [s] this unpcb contains peer eids */ + int unp_gcflags; /* [G] garbage collector flags */ + struct sockpeercred unp_connid;/* [s] id of peer process */ + struct timespec unp_ctime; /* [I] holds creation time */ + LIST_ENTRY(unpcb) unp_link; /* [G] link in per-AF list of sockets */ +}; + +/* + * flag bits in unp_flags + */ +#define UNP_FEIDS 0x01 /* unp_connid contains information */ +#define UNP_FEIDSBIND 0x02 /* unp_connid was set by a bind */ +#define UNP_BINDING 0x04 /* unp is binding now */ +#define UNP_CONNECTING 0x08 /* unp is connecting now */ + +/* + * flag bits in unp_gcflags + */ +#define UNP_GCDEAD 0x01 /* unp could be dead */ + +#define sotounpcb(so) ((struct unpcb *)((so)->so_pcb)) + +#ifdef _KERNEL + +struct stat; + +struct fdpass { + struct file *fp; + int flags; +}; + +extern const struct pr_usrreqs uipc_usrreqs; +extern const struct pr_usrreqs uipc_dgram_usrreqs; + +int uipc_attach(struct socket *, int, int); +int uipc_detach(struct socket *); +int uipc_bind(struct socket *, struct mbuf *, struct proc *); +int uipc_listen(struct socket *); +int uipc_connect(struct socket *, struct mbuf *); +int uipc_accept(struct socket *, struct mbuf *); +int uipc_disconnect(struct socket *); +int uipc_shutdown(struct socket *); +int uipc_dgram_shutdown(struct socket *); +void uipc_rcvd(struct socket *); +int uipc_send(struct socket *, struct mbuf *, struct mbuf *, + struct mbuf *); +int uipc_dgram_send(struct socket *, struct mbuf *, struct mbuf *, + struct mbuf *); +void uipc_abort(struct socket *); +int uipc_sense(struct socket *, struct stat *); +int uipc_sockaddr(struct socket *, struct mbuf *); +int uipc_peeraddr(struct socket *, struct mbuf *); +int uipc_connect2(struct socket *, struct socket *); + +void unp_init(void); +int unp_connect(struct socket *, struct mbuf *, struct proc *); +int unp_connect2(struct socket *, struct socket *); +void unp_detach(struct unpcb *); +void unp_disconnect(struct unpcb *); +void unp_gc(void *); +int unp_externalize(struct mbuf *, socklen_t, int); +int unp_internalize(struct mbuf *, struct proc *); +void unp_dispose(struct mbuf *); +#endif /* _KERNEL */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/user.h b/lib/libc/include/generic-openbsd/sys/user.h new file mode 100644 index 0000000000..1d80462bd9 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/user.h @@ -0,0 +1,48 @@ +/* $OpenBSD: user.h,v 1.9 2014/07/08 23:31:22 deraadt Exp $ */ +/* $NetBSD: user.h,v 1.10 1996/04/09 20:55:49 cgd Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1989, 1991, 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. + * + * @(#)user.h 8.2 (Berkeley) 9/23/93 + */ + +#include +#include +#include + +/* + * Per process structure containing data that isn't needed in core + * when the process isn't running (esp. when swapped out). + * This structure may or may not be at the same kernel address + * in all processes. + */ + +struct user { + struct pcb u_pcb; +}; \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/utsname.h b/lib/libc/include/generic-openbsd/sys/utsname.h new file mode 100644 index 0000000000..8f1378962a --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/utsname.h @@ -0,0 +1,59 @@ +/* $OpenBSD: utsname.h,v 1.6 2013/03/24 17:45:50 deraadt Exp $ */ +/* $NetBSD: utsname.h,v 1.6 1994/06/29 06:46:11 cgd Exp $ */ + +/*- + * Copyright (c) 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chuck Karish of Mindcraft, Inc. + * + * 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. + * + * @(#)utsname.h 8.1 (Berkeley) 1/4/94 + */ + +#ifndef _SYS_UTSNAME_H +#define _SYS_UTSNAME_H + +#define SYS_NMLN 256 + +struct utsname { + char sysname[SYS_NMLN]; /* Name of this OS. */ + char nodename[SYS_NMLN]; /* Name of this network node. */ + char release[SYS_NMLN]; /* Release level. */ + char version[SYS_NMLN]; /* Version level. */ + char machine[SYS_NMLN]; /* Hardware type. */ +}; + +#include + +#ifndef _KERNEL +__BEGIN_DECLS +int uname(struct utsname *); +__END_DECLS +#endif /* !_KERNEL */ + +#endif /* !_SYS_UTSNAME_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/uuid.h b/lib/libc/include/generic-openbsd/sys/uuid.h new file mode 100644 index 0000000000..c834c09802 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/uuid.h @@ -0,0 +1,71 @@ +/* $OpenBSD: uuid.h,v 1.5 2025/07/11 19:12:49 krw Exp $ */ +/* $NetBSD: uuid.h,v 1.5 2008/11/18 14:01:03 joerg Exp $ */ + +/* + * Copyright (c) 2002 Marcel Moolenaar + * 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. + * + * $FreeBSD: /repoman/r/ncvs/src/sys/sys/uuid.h,v 1.3 2003/05/31 16:47:07 phk Exp $ + */ + +#ifndef _SYS_UUID_H_ +#define _SYS_UUID_H_ + +/* Length of a node address (an IEEE 802 address). */ +#define _UUID_NODE_LEN 6 + +/* Length of a printed UUID. */ +#define _UUID_BUF_LEN 38 + +/* + * See also: + * http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt + * http://www.opengroup.org/onlinepubs/009629399/apdxa.htm + * + * A DCE 1.1 compatible source representation of UUIDs. + */ +struct uuid { + uint32_t time_low; + uint16_t time_mid; + uint16_t time_hi_and_version; + uint8_t clock_seq_hi_and_reserved; + uint8_t clock_seq_low; + uint8_t node[_UUID_NODE_LEN]; +}; + +#ifdef _KERNEL + +#define UUID_NODE_LEN _UUID_NODE_LEN +#define UUID_BUF_LEN _UUID_BUF_LEN + +int uuid_snprintf(char *, size_t, const struct uuid *); +int uuid_printf(const struct uuid *); + +#else /* _KERNEL */ + +typedef struct uuid uuid_t; + +#endif /* _KERNEL */ + +#endif /* _SYS_UUID_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/varargs.h b/lib/libc/include/generic-openbsd/sys/varargs.h new file mode 100644 index 0000000000..0f3d2c690a --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/varargs.h @@ -0,0 +1,51 @@ +/* $OpenBSD: varargs.h,v 1.4 2020/07/21 23:09:00 daniel Exp $ */ +/* + * Copyright (c) 2003, 2004 Marc espie + * + * 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 _VARARGS_H_ +#define _VARARGS_H_ + +/* These macros implement traditional (non-ANSI) varargs + for GNU C. */ + +#define va_alist __builtin_va_alist + +#define __va_ellipsis ... + +/* ??? We don't process attributes correctly in K&R argument context. */ +typedef int __builtin_va_alist_t __attribute__((__mode__(__word__))); + +/* ??? It would be nice to get rid of the ellipsis here. It causes + current_function_varargs to be set in cc1. */ +#define va_dcl __builtin_va_alist_t __builtin_va_alist; ... + +/* Define __gnuc_va_list, just as in stdarg.h. */ + +#ifndef __GNUC_VA_LIST +#define __GNUC_VA_LIST +typedef __builtin_va_list __gnuc_va_list; +#endif + +#define va_start(v) __builtin_varargs_start((v)) +#define va_end __builtin_va_end +#define va_arg __builtin_va_arg +#define __va_copy(d,s) __builtin_va_copy((d),(s)) + +/* Define va_list from __gnuc_va_list. */ + +typedef __gnuc_va_list va_list; + +#endif /* _VARARGS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/videoio.h b/lib/libc/include/generic-openbsd/sys/videoio.h new file mode 100644 index 0000000000..361f46c7ae --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/videoio.h @@ -0,0 +1,6328 @@ +/* $OpenBSD: videoio.h,v 1.26 2025/08/02 09:27:59 kirill Exp $ */ + +/* + * Video for Linux Two header file + * + * Copyright (C) 1999-2012 the contributors + * Copyright (C) 2012 Nokia Corporation + * Contact: Sakari Ailus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Alternatively you can redistribute this file under the terms of the + * BSD license as stated below: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. The names of its contributors may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT + * OWNER 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. + * + * Header file for v4l or V4L2 drivers and applications + * with public API. + * All kernel-specific stuff were moved to media/v4l2-dev.h, so + * no #if __KERNEL tests are allowed here + * + * See https://linuxtv.org for more info + * + * Author: Bill Dirks + * Justin Schoeman + * Hans Verkuil + * et al. + */ + +#ifndef _SYS_VIDEOIO_H_ +#define _SYS_VIDEOIO_H_ +#include +#include +#include +/* Inline #include + * (v4l2-common.h was split off from videodev2.h and has the same BSD license.) + * + * Begin of v4l2-common.h + */ +/* + * + * Selection interface definitions + * + */ + +/* Current cropping area */ +#define V4L2_SEL_TGT_CROP 0x0000 +/* Default cropping area */ +#define V4L2_SEL_TGT_CROP_DEFAULT 0x0001 +/* Cropping bounds */ +#define V4L2_SEL_TGT_CROP_BOUNDS 0x0002 +/* Native frame size */ +#define V4L2_SEL_TGT_NATIVE_SIZE 0x0003 +/* Current composing area */ +#define V4L2_SEL_TGT_COMPOSE 0x0100 +/* Default composing area */ +#define V4L2_SEL_TGT_COMPOSE_DEFAULT 0x0101 +/* Composing bounds */ +#define V4L2_SEL_TGT_COMPOSE_BOUNDS 0x0102 +/* Current composing area plus all padding pixels */ +#define V4L2_SEL_TGT_COMPOSE_PADDED 0x0103 + +/* Backward compatibility target definitions --- to be removed. */ +#define V4L2_SEL_TGT_CROP_ACTIVE V4L2_SEL_TGT_CROP +#define V4L2_SEL_TGT_COMPOSE_ACTIVE V4L2_SEL_TGT_COMPOSE +#define V4L2_SUBDEV_SEL_TGT_CROP_ACTUAL V4L2_SEL_TGT_CROP +#define V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTUAL V4L2_SEL_TGT_COMPOSE +#define V4L2_SUBDEV_SEL_TGT_CROP_BOUNDS V4L2_SEL_TGT_CROP_BOUNDS +#define V4L2_SUBDEV_SEL_TGT_COMPOSE_BOUNDS V4L2_SEL_TGT_COMPOSE_BOUNDS + +/* Selection flags */ +#define V4L2_SEL_FLAG_GE (1 << 0) +#define V4L2_SEL_FLAG_LE (1 << 1) +#define V4L2_SEL_FLAG_KEEP_CONFIG (1 << 2) + +struct v4l2_edid { + u_int32_t pad; + u_int32_t start_block; + u_int32_t blocks; + u_int32_t reserved[5]; + u_int8_t *edid; +}; + +/* Backward compatibility target definitions --- to be removed. */ +#define V4L2_SEL_TGT_CROP_ACTIVE V4L2_SEL_TGT_CROP +#define V4L2_SEL_TGT_COMPOSE_ACTIVE V4L2_SEL_TGT_COMPOSE +#define V4L2_SUBDEV_SEL_TGT_CROP_ACTUAL V4L2_SEL_TGT_CROP +#define V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTUAL V4L2_SEL_TGT_COMPOSE +#define V4L2_SUBDEV_SEL_TGT_CROP_BOUNDS V4L2_SEL_TGT_CROP_BOUNDS +#define V4L2_SUBDEV_SEL_TGT_COMPOSE_BOUNDS V4L2_SEL_TGT_COMPOSE_BOUNDS + +/* Backward compatibility flag definitions --- to be removed. */ +#define V4L2_SUBDEV_SEL_FLAG_SIZE_GE V4L2_SEL_FLAG_GE +#define V4L2_SUBDEV_SEL_FLAG_SIZE_LE V4L2_SEL_FLAG_LE +#define V4L2_SUBDEV_SEL_FLAG_KEEP_CONFIG V4L2_SEL_FLAG_KEEP_CONFIG +/* + * End of v4l2-common.h + */ +/* Inline #include + * (v4l2-controls.h was split off from videodev2.h and has the same BSD license.) + * + * Begin of v4l2-controls.h + */ +/* Control classes */ +#define V4L2_CTRL_CLASS_USER 0x00980000 /* Old-style 'user' controls */ +#define V4L2_CTRL_CLASS_CODEC 0x00990000 /* Stateful codec controls */ +#define V4L2_CTRL_CLASS_CAMERA 0x009a0000 /* Camera class controls */ +#define V4L2_CTRL_CLASS_FM_TX 0x009b0000 /* FM Modulator controls */ +#define V4L2_CTRL_CLASS_FLASH 0x009c0000 /* Camera flash controls */ +#define V4L2_CTRL_CLASS_JPEG 0x009d0000 /* JPEG-compression controls */ +#define V4L2_CTRL_CLASS_IMAGE_SOURCE 0x009e0000 /* Image source controls */ +#define V4L2_CTRL_CLASS_IMAGE_PROC 0x009f0000 /* Image processing controls */ +#define V4L2_CTRL_CLASS_DV 0x00a00000 /* Digital Video controls */ +#define V4L2_CTRL_CLASS_FM_RX 0x00a10000 /* FM Receiver controls */ +#define V4L2_CTRL_CLASS_RF_TUNER 0x00a20000 /* RF tuner controls */ +#define V4L2_CTRL_CLASS_DETECT 0x00a30000 /* Detection controls */ +#define V4L2_CTRL_CLASS_CODEC_STATELESS 0x00a40000 /* Stateless codecs controls */ +#define V4L2_CTRL_CLASS_COLORIMETRY 0x00a50000 /* Colorimetry controls */ + +/* User-class control IDs */ + +#define V4L2_CID_BASE (V4L2_CTRL_CLASS_USER | 0x900) +#define V4L2_CID_USER_BASE V4L2_CID_BASE +#define V4L2_CID_USER_CLASS (V4L2_CTRL_CLASS_USER | 1) +#define V4L2_CID_BRIGHTNESS (V4L2_CID_BASE+0) +#define V4L2_CID_CONTRAST (V4L2_CID_BASE+1) +#define V4L2_CID_SATURATION (V4L2_CID_BASE+2) +#define V4L2_CID_HUE (V4L2_CID_BASE+3) +#define V4L2_CID_AUDIO_VOLUME (V4L2_CID_BASE+5) +#define V4L2_CID_AUDIO_BALANCE (V4L2_CID_BASE+6) +#define V4L2_CID_AUDIO_BASS (V4L2_CID_BASE+7) +#define V4L2_CID_AUDIO_TREBLE (V4L2_CID_BASE+8) +#define V4L2_CID_AUDIO_MUTE (V4L2_CID_BASE+9) +#define V4L2_CID_AUDIO_LOUDNESS (V4L2_CID_BASE+10) +#define V4L2_CID_BLACK_LEVEL (V4L2_CID_BASE+11) /* Deprecated */ +#define V4L2_CID_AUTO_WHITE_BALANCE (V4L2_CID_BASE+12) +#define V4L2_CID_DO_WHITE_BALANCE (V4L2_CID_BASE+13) +#define V4L2_CID_RED_BALANCE (V4L2_CID_BASE+14) +#define V4L2_CID_BLUE_BALANCE (V4L2_CID_BASE+15) +#define V4L2_CID_GAMMA (V4L2_CID_BASE+16) +#define V4L2_CID_WHITENESS (V4L2_CID_GAMMA) /* Deprecated */ +#define V4L2_CID_EXPOSURE (V4L2_CID_BASE+17) +#define V4L2_CID_AUTOGAIN (V4L2_CID_BASE+18) +#define V4L2_CID_GAIN (V4L2_CID_BASE+19) +#define V4L2_CID_HFLIP (V4L2_CID_BASE+20) +#define V4L2_CID_VFLIP (V4L2_CID_BASE+21) + +#define V4L2_CID_POWER_LINE_FREQUENCY (V4L2_CID_BASE+24) +enum v4l2_power_line_frequency { + V4L2_CID_POWER_LINE_FREQUENCY_DISABLED = 0, + V4L2_CID_POWER_LINE_FREQUENCY_50HZ = 1, + V4L2_CID_POWER_LINE_FREQUENCY_60HZ = 2, + V4L2_CID_POWER_LINE_FREQUENCY_AUTO = 3, +}; +#define V4L2_CID_HUE_AUTO (V4L2_CID_BASE+25) +#define V4L2_CID_WHITE_BALANCE_TEMPERATURE (V4L2_CID_BASE+26) +#define V4L2_CID_SHARPNESS (V4L2_CID_BASE+27) +#define V4L2_CID_BACKLIGHT_COMPENSATION (V4L2_CID_BASE+28) +#define V4L2_CID_CHROMA_AGC (V4L2_CID_BASE+29) +#define V4L2_CID_COLOR_KILLER (V4L2_CID_BASE+30) +#define V4L2_CID_COLORFX (V4L2_CID_BASE+31) +enum v4l2_colorfx { + V4L2_COLORFX_NONE = 0, + V4L2_COLORFX_BW = 1, + V4L2_COLORFX_SEPIA = 2, + V4L2_COLORFX_NEGATIVE = 3, + V4L2_COLORFX_EMBOSS = 4, + V4L2_COLORFX_SKETCH = 5, + V4L2_COLORFX_SKY_BLUE = 6, + V4L2_COLORFX_GRASS_GREEN = 7, + V4L2_COLORFX_SKIN_WHITEN = 8, + V4L2_COLORFX_VIVID = 9, + V4L2_COLORFX_AQUA = 10, + V4L2_COLORFX_ART_FREEZE = 11, + V4L2_COLORFX_SILHOUETTE = 12, + V4L2_COLORFX_SOLARIZATION = 13, + V4L2_COLORFX_ANTIQUE = 14, + V4L2_COLORFX_SET_CBCR = 15, + V4L2_COLORFX_SET_RGB = 16, +}; +#define V4L2_CID_AUTOBRIGHTNESS (V4L2_CID_BASE+32) +#define V4L2_CID_BAND_STOP_FILTER (V4L2_CID_BASE+33) + +#define V4L2_CID_ROTATE (V4L2_CID_BASE+34) +#define V4L2_CID_BG_COLOR (V4L2_CID_BASE+35) + +#define V4L2_CID_CHROMA_GAIN (V4L2_CID_BASE+36) + +#define V4L2_CID_ILLUMINATORS_1 (V4L2_CID_BASE+37) +#define V4L2_CID_ILLUMINATORS_2 (V4L2_CID_BASE+38) + +#define V4L2_CID_MIN_BUFFERS_FOR_CAPTURE (V4L2_CID_BASE+39) +#define V4L2_CID_MIN_BUFFERS_FOR_OUTPUT (V4L2_CID_BASE+40) + +#define V4L2_CID_ALPHA_COMPONENT (V4L2_CID_BASE+41) +#define V4L2_CID_COLORFX_CBCR (V4L2_CID_BASE+42) +#define V4L2_CID_COLORFX_RGB (V4L2_CID_BASE+43) + +/* last CID + 1 */ +#define V4L2_CID_LASTP1 (V4L2_CID_BASE+44) + +/* USER-class private control IDs */ + +/* + * The base for the meye driver controls. This driver was removed, but + * we keep this define in case any software still uses it. + */ +#define V4L2_CID_USER_MEYE_BASE (V4L2_CID_USER_BASE + 0x1000) + +/* The base for the bttv driver controls. + * We reserve 32 controls for this driver. */ +#define V4L2_CID_USER_BTTV_BASE (V4L2_CID_USER_BASE + 0x1010) + + +/* The base for the s2255 driver controls. + * We reserve 16 controls for this driver. */ +#define V4L2_CID_USER_S2255_BASE (V4L2_CID_USER_BASE + 0x1030) + +/* + * The base for the si476x driver controls. See include/media/drv-intf/si476x.h + * for the list of controls. Total of 16 controls is reserved for this driver + */ +#define V4L2_CID_USER_SI476X_BASE (V4L2_CID_USER_BASE + 0x1040) + +/* The base for the TI VPE driver controls. Total of 16 controls is reserved for + * this driver */ +#define V4L2_CID_USER_TI_VPE_BASE (V4L2_CID_USER_BASE + 0x1050) + +/* The base for the saa7134 driver controls. + * We reserve 16 controls for this driver. */ +#define V4L2_CID_USER_SAA7134_BASE (V4L2_CID_USER_BASE + 0x1060) + +/* The base for the adv7180 driver controls. + * We reserve 16 controls for this driver. */ +#define V4L2_CID_USER_ADV7180_BASE (V4L2_CID_USER_BASE + 0x1070) + +/* The base for the tc358743 driver controls. + * We reserve 16 controls for this driver. */ +#define V4L2_CID_USER_TC358743_BASE (V4L2_CID_USER_BASE + 0x1080) + +/* The base for the max217x driver controls. + * We reserve 32 controls for this driver + */ +#define V4L2_CID_USER_MAX217X_BASE (V4L2_CID_USER_BASE + 0x1090) + +/* The base for the imx driver controls. + * We reserve 16 controls for this driver. */ +#define V4L2_CID_USER_IMX_BASE (V4L2_CID_USER_BASE + 0x10b0) + +/* + * The base for the atmel isc driver controls. + * We reserve 32 controls for this driver. + */ +#define V4L2_CID_USER_ATMEL_ISC_BASE (V4L2_CID_USER_BASE + 0x10c0) + +/* + * The base for the CODA driver controls. + * We reserve 16 controls for this driver. + */ +#define V4L2_CID_USER_CODA_BASE (V4L2_CID_USER_BASE + 0x10e0) +/* + * The base for MIPI CCS driver controls. + * We reserve 128 controls for this driver. + */ +#define V4L2_CID_USER_CCS_BASE (V4L2_CID_USER_BASE + 0x10f0) +/* + * The base for Allegro driver controls. + * We reserve 16 controls for this driver. + */ +#define V4L2_CID_USER_ALLEGRO_BASE (V4L2_CID_USER_BASE + 0x1170) + +/* + * The base for the isl7998x driver controls. + * We reserve 16 controls for this driver. + */ +#define V4L2_CID_USER_ISL7998X_BASE (V4L2_CID_USER_BASE + 0x1180) + +/* + * The base for DW100 driver controls. + * We reserve 16 controls for this driver. + */ +#define V4L2_CID_USER_DW100_BASE (V4L2_CID_USER_BASE + 0x1190) + +/* + * The base for Aspeed driver controls. + * We reserve 16 controls for this driver. + */ +#define V4L2_CID_USER_ASPEED_BASE (V4L2_CID_USER_BASE + 0x11a0) + +/* + * The base for Nuvoton NPCM driver controls. + * We reserve 16 controls for this driver. + */ +#define V4L2_CID_USER_NPCM_BASE (V4L2_CID_USER_BASE + 0x11b0) + +/* + * The base for THine THP7312 driver controls. + * We reserve 32 controls for this driver. + */ +#define V4L2_CID_USER_THP7312_BASE (V4L2_CID_USER_BASE + 0x11c0) + +/* + * The base for the uvc driver controls. + * See linux/uvcvideo.h for the list of controls. + * We reserve 64 controls for this driver. + */ +#define V4L2_CID_USER_UVC_BASE (V4L2_CID_USER_BASE + 0x11e0) + +/* + * The base for Rockchip ISP1 driver controls. + * We reserve 16 controls for this driver. + */ +#define V4L2_CID_USER_RKISP1_BASE (V4L2_CID_USER_BASE + 0x1220) + +/* MPEG-class control IDs */ +/* The MPEG controls are applicable to all codec controls + * and the 'MPEG' part of the define is historical */ + +#define V4L2_CID_CODEC_BASE (V4L2_CTRL_CLASS_CODEC | 0x900) +#define V4L2_CID_CODEC_CLASS (V4L2_CTRL_CLASS_CODEC | 1) + +/* MPEG streams, specific to multiplexed streams */ +#define V4L2_CID_MPEG_STREAM_TYPE (V4L2_CID_CODEC_BASE+0) +enum v4l2_mpeg_stream_type { + V4L2_MPEG_STREAM_TYPE_MPEG2_PS = 0, /* MPEG-2 program stream */ + V4L2_MPEG_STREAM_TYPE_MPEG2_TS = 1, /* MPEG-2 transport stream */ + V4L2_MPEG_STREAM_TYPE_MPEG1_SS = 2, /* MPEG-1 system stream */ + V4L2_MPEG_STREAM_TYPE_MPEG2_DVD = 3, /* MPEG-2 DVD-compatible stream */ + V4L2_MPEG_STREAM_TYPE_MPEG1_VCD = 4, /* MPEG-1 VCD-compatible stream */ + V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD = 5, /* MPEG-2 SVCD-compatible stream */ +}; +#define V4L2_CID_MPEG_STREAM_PID_PMT (V4L2_CID_CODEC_BASE+1) +#define V4L2_CID_MPEG_STREAM_PID_AUDIO (V4L2_CID_CODEC_BASE+2) +#define V4L2_CID_MPEG_STREAM_PID_VIDEO (V4L2_CID_CODEC_BASE+3) +#define V4L2_CID_MPEG_STREAM_PID_PCR (V4L2_CID_CODEC_BASE+4) +#define V4L2_CID_MPEG_STREAM_PES_ID_AUDIO (V4L2_CID_CODEC_BASE+5) +#define V4L2_CID_MPEG_STREAM_PES_ID_VIDEO (V4L2_CID_CODEC_BASE+6) +#define V4L2_CID_MPEG_STREAM_VBI_FMT (V4L2_CID_CODEC_BASE+7) +enum v4l2_mpeg_stream_vbi_fmt { + V4L2_MPEG_STREAM_VBI_FMT_NONE = 0, /* No VBI in the MPEG stream */ + V4L2_MPEG_STREAM_VBI_FMT_IVTV = 1, /* VBI in private packets, IVTV format */ +}; + +/* MPEG audio controls specific to multiplexed streams */ +#define V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ (V4L2_CID_CODEC_BASE+100) +enum v4l2_mpeg_audio_sampling_freq { + V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100 = 0, + V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000 = 1, + V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000 = 2, +}; +#define V4L2_CID_MPEG_AUDIO_ENCODING (V4L2_CID_CODEC_BASE+101) +enum v4l2_mpeg_audio_encoding { + V4L2_MPEG_AUDIO_ENCODING_LAYER_1 = 0, + V4L2_MPEG_AUDIO_ENCODING_LAYER_2 = 1, + V4L2_MPEG_AUDIO_ENCODING_LAYER_3 = 2, + V4L2_MPEG_AUDIO_ENCODING_AAC = 3, + V4L2_MPEG_AUDIO_ENCODING_AC3 = 4, +}; +#define V4L2_CID_MPEG_AUDIO_L1_BITRATE (V4L2_CID_CODEC_BASE+102) +enum v4l2_mpeg_audio_l1_bitrate { + V4L2_MPEG_AUDIO_L1_BITRATE_32K = 0, + V4L2_MPEG_AUDIO_L1_BITRATE_64K = 1, + V4L2_MPEG_AUDIO_L1_BITRATE_96K = 2, + V4L2_MPEG_AUDIO_L1_BITRATE_128K = 3, + V4L2_MPEG_AUDIO_L1_BITRATE_160K = 4, + V4L2_MPEG_AUDIO_L1_BITRATE_192K = 5, + V4L2_MPEG_AUDIO_L1_BITRATE_224K = 6, + V4L2_MPEG_AUDIO_L1_BITRATE_256K = 7, + V4L2_MPEG_AUDIO_L1_BITRATE_288K = 8, + V4L2_MPEG_AUDIO_L1_BITRATE_320K = 9, + V4L2_MPEG_AUDIO_L1_BITRATE_352K = 10, + V4L2_MPEG_AUDIO_L1_BITRATE_384K = 11, + V4L2_MPEG_AUDIO_L1_BITRATE_416K = 12, + V4L2_MPEG_AUDIO_L1_BITRATE_448K = 13, +}; +#define V4L2_CID_MPEG_AUDIO_L2_BITRATE (V4L2_CID_CODEC_BASE+103) +enum v4l2_mpeg_audio_l2_bitrate { + V4L2_MPEG_AUDIO_L2_BITRATE_32K = 0, + V4L2_MPEG_AUDIO_L2_BITRATE_48K = 1, + V4L2_MPEG_AUDIO_L2_BITRATE_56K = 2, + V4L2_MPEG_AUDIO_L2_BITRATE_64K = 3, + V4L2_MPEG_AUDIO_L2_BITRATE_80K = 4, + V4L2_MPEG_AUDIO_L2_BITRATE_96K = 5, + V4L2_MPEG_AUDIO_L2_BITRATE_112K = 6, + V4L2_MPEG_AUDIO_L2_BITRATE_128K = 7, + V4L2_MPEG_AUDIO_L2_BITRATE_160K = 8, + V4L2_MPEG_AUDIO_L2_BITRATE_192K = 9, + V4L2_MPEG_AUDIO_L2_BITRATE_224K = 10, + V4L2_MPEG_AUDIO_L2_BITRATE_256K = 11, + V4L2_MPEG_AUDIO_L2_BITRATE_320K = 12, + V4L2_MPEG_AUDIO_L2_BITRATE_384K = 13, +}; +#define V4L2_CID_MPEG_AUDIO_L3_BITRATE (V4L2_CID_CODEC_BASE+104) +enum v4l2_mpeg_audio_l3_bitrate { + V4L2_MPEG_AUDIO_L3_BITRATE_32K = 0, + V4L2_MPEG_AUDIO_L3_BITRATE_40K = 1, + V4L2_MPEG_AUDIO_L3_BITRATE_48K = 2, + V4L2_MPEG_AUDIO_L3_BITRATE_56K = 3, + V4L2_MPEG_AUDIO_L3_BITRATE_64K = 4, + V4L2_MPEG_AUDIO_L3_BITRATE_80K = 5, + V4L2_MPEG_AUDIO_L3_BITRATE_96K = 6, + V4L2_MPEG_AUDIO_L3_BITRATE_112K = 7, + V4L2_MPEG_AUDIO_L3_BITRATE_128K = 8, + V4L2_MPEG_AUDIO_L3_BITRATE_160K = 9, + V4L2_MPEG_AUDIO_L3_BITRATE_192K = 10, + V4L2_MPEG_AUDIO_L3_BITRATE_224K = 11, + V4L2_MPEG_AUDIO_L3_BITRATE_256K = 12, + V4L2_MPEG_AUDIO_L3_BITRATE_320K = 13, +}; +#define V4L2_CID_MPEG_AUDIO_MODE (V4L2_CID_CODEC_BASE+105) +enum v4l2_mpeg_audio_mode { + V4L2_MPEG_AUDIO_MODE_STEREO = 0, + V4L2_MPEG_AUDIO_MODE_JOINT_STEREO = 1, + V4L2_MPEG_AUDIO_MODE_DUAL = 2, + V4L2_MPEG_AUDIO_MODE_MONO = 3, +}; +#define V4L2_CID_MPEG_AUDIO_MODE_EXTENSION (V4L2_CID_CODEC_BASE+106) +enum v4l2_mpeg_audio_mode_extension { + V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4 = 0, + V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_8 = 1, + V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_12 = 2, + V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_16 = 3, +}; +#define V4L2_CID_MPEG_AUDIO_EMPHASIS (V4L2_CID_CODEC_BASE+107) +enum v4l2_mpeg_audio_emphasis { + V4L2_MPEG_AUDIO_EMPHASIS_NONE = 0, + V4L2_MPEG_AUDIO_EMPHASIS_50_DIV_15_uS = 1, + V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17 = 2, +}; +#define V4L2_CID_MPEG_AUDIO_CRC (V4L2_CID_CODEC_BASE+108) +enum v4l2_mpeg_audio_crc { + V4L2_MPEG_AUDIO_CRC_NONE = 0, + V4L2_MPEG_AUDIO_CRC_CRC16 = 1, +}; +#define V4L2_CID_MPEG_AUDIO_MUTE (V4L2_CID_CODEC_BASE+109) +#define V4L2_CID_MPEG_AUDIO_AAC_BITRATE (V4L2_CID_CODEC_BASE+110) +#define V4L2_CID_MPEG_AUDIO_AC3_BITRATE (V4L2_CID_CODEC_BASE+111) +enum v4l2_mpeg_audio_ac3_bitrate { + V4L2_MPEG_AUDIO_AC3_BITRATE_32K = 0, + V4L2_MPEG_AUDIO_AC3_BITRATE_40K = 1, + V4L2_MPEG_AUDIO_AC3_BITRATE_48K = 2, + V4L2_MPEG_AUDIO_AC3_BITRATE_56K = 3, + V4L2_MPEG_AUDIO_AC3_BITRATE_64K = 4, + V4L2_MPEG_AUDIO_AC3_BITRATE_80K = 5, + V4L2_MPEG_AUDIO_AC3_BITRATE_96K = 6, + V4L2_MPEG_AUDIO_AC3_BITRATE_112K = 7, + V4L2_MPEG_AUDIO_AC3_BITRATE_128K = 8, + V4L2_MPEG_AUDIO_AC3_BITRATE_160K = 9, + V4L2_MPEG_AUDIO_AC3_BITRATE_192K = 10, + V4L2_MPEG_AUDIO_AC3_BITRATE_224K = 11, + V4L2_MPEG_AUDIO_AC3_BITRATE_256K = 12, + V4L2_MPEG_AUDIO_AC3_BITRATE_320K = 13, + V4L2_MPEG_AUDIO_AC3_BITRATE_384K = 14, + V4L2_MPEG_AUDIO_AC3_BITRATE_448K = 15, + V4L2_MPEG_AUDIO_AC3_BITRATE_512K = 16, + V4L2_MPEG_AUDIO_AC3_BITRATE_576K = 17, + V4L2_MPEG_AUDIO_AC3_BITRATE_640K = 18, +}; +#define V4L2_CID_MPEG_AUDIO_DEC_PLAYBACK (V4L2_CID_CODEC_BASE+112) +enum v4l2_mpeg_audio_dec_playback { + V4L2_MPEG_AUDIO_DEC_PLAYBACK_AUTO = 0, + V4L2_MPEG_AUDIO_DEC_PLAYBACK_STEREO = 1, + V4L2_MPEG_AUDIO_DEC_PLAYBACK_LEFT = 2, + V4L2_MPEG_AUDIO_DEC_PLAYBACK_RIGHT = 3, + V4L2_MPEG_AUDIO_DEC_PLAYBACK_MONO = 4, + V4L2_MPEG_AUDIO_DEC_PLAYBACK_SWAPPED_STEREO = 5, +}; +#define V4L2_CID_MPEG_AUDIO_DEC_MULTILINGUAL_PLAYBACK (V4L2_CID_CODEC_BASE+113) + +/* MPEG video controls specific to multiplexed streams */ +#define V4L2_CID_MPEG_VIDEO_ENCODING (V4L2_CID_CODEC_BASE+200) +enum v4l2_mpeg_video_encoding { + V4L2_MPEG_VIDEO_ENCODING_MPEG_1 = 0, + V4L2_MPEG_VIDEO_ENCODING_MPEG_2 = 1, + V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC = 2, +}; +#define V4L2_CID_MPEG_VIDEO_ASPECT (V4L2_CID_CODEC_BASE+201) +enum v4l2_mpeg_video_aspect { + V4L2_MPEG_VIDEO_ASPECT_1x1 = 0, + V4L2_MPEG_VIDEO_ASPECT_4x3 = 1, + V4L2_MPEG_VIDEO_ASPECT_16x9 = 2, + V4L2_MPEG_VIDEO_ASPECT_221x100 = 3, +}; +#define V4L2_CID_MPEG_VIDEO_B_FRAMES (V4L2_CID_CODEC_BASE+202) +#define V4L2_CID_MPEG_VIDEO_GOP_SIZE (V4L2_CID_CODEC_BASE+203) +#define V4L2_CID_MPEG_VIDEO_GOP_CLOSURE (V4L2_CID_CODEC_BASE+204) +#define V4L2_CID_MPEG_VIDEO_PULLDOWN (V4L2_CID_CODEC_BASE+205) +#define V4L2_CID_MPEG_VIDEO_BITRATE_MODE (V4L2_CID_CODEC_BASE+206) +enum v4l2_mpeg_video_bitrate_mode { + V4L2_MPEG_VIDEO_BITRATE_MODE_VBR = 0, + V4L2_MPEG_VIDEO_BITRATE_MODE_CBR = 1, + V4L2_MPEG_VIDEO_BITRATE_MODE_CQ = 2, +}; +#define V4L2_CID_MPEG_VIDEO_BITRATE (V4L2_CID_CODEC_BASE+207) +#define V4L2_CID_MPEG_VIDEO_BITRATE_PEAK (V4L2_CID_CODEC_BASE+208) +#define V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION (V4L2_CID_CODEC_BASE+209) +#define V4L2_CID_MPEG_VIDEO_MUTE (V4L2_CID_CODEC_BASE+210) +#define V4L2_CID_MPEG_VIDEO_MUTE_YUV (V4L2_CID_CODEC_BASE+211) +#define V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE (V4L2_CID_CODEC_BASE+212) +#define V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER (V4L2_CID_CODEC_BASE+213) +#define V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB (V4L2_CID_CODEC_BASE+214) +#define V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE (V4L2_CID_CODEC_BASE+215) +#define V4L2_CID_MPEG_VIDEO_HEADER_MODE (V4L2_CID_CODEC_BASE+216) +enum v4l2_mpeg_video_header_mode { + V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE = 0, + V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME = 1, + +}; +#define V4L2_CID_MPEG_VIDEO_MAX_REF_PIC (V4L2_CID_CODEC_BASE+217) +#define V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE (V4L2_CID_CODEC_BASE+218) +#define V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES (V4L2_CID_CODEC_BASE+219) +#define V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB (V4L2_CID_CODEC_BASE+220) +#define V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE (V4L2_CID_CODEC_BASE+221) +enum v4l2_mpeg_video_multi_slice_mode { + V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE = 0, + V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_MAX_MB = 1, + V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_MAX_BYTES = 2, + /* Kept for backwards compatibility reasons. Stupid typo... */ + V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB = 1, + V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES = 2, +}; +#define V4L2_CID_MPEG_VIDEO_VBV_SIZE (V4L2_CID_CODEC_BASE+222) +#define V4L2_CID_MPEG_VIDEO_DEC_PTS (V4L2_CID_CODEC_BASE+223) +#define V4L2_CID_MPEG_VIDEO_DEC_FRAME (V4L2_CID_CODEC_BASE+224) +#define V4L2_CID_MPEG_VIDEO_VBV_DELAY (V4L2_CID_CODEC_BASE+225) +#define V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER (V4L2_CID_CODEC_BASE+226) +#define V4L2_CID_MPEG_VIDEO_MV_H_SEARCH_RANGE (V4L2_CID_CODEC_BASE+227) +#define V4L2_CID_MPEG_VIDEO_MV_V_SEARCH_RANGE (V4L2_CID_CODEC_BASE+228) +#define V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME (V4L2_CID_CODEC_BASE+229) +#define V4L2_CID_MPEG_VIDEO_BASELAYER_PRIORITY_ID (V4L2_CID_CODEC_BASE+230) +#define V4L2_CID_MPEG_VIDEO_AU_DELIMITER (V4L2_CID_CODEC_BASE+231) +#define V4L2_CID_MPEG_VIDEO_LTR_COUNT (V4L2_CID_CODEC_BASE+232) +#define V4L2_CID_MPEG_VIDEO_FRAME_LTR_INDEX (V4L2_CID_CODEC_BASE+233) +#define V4L2_CID_MPEG_VIDEO_USE_LTR_FRAMES (V4L2_CID_CODEC_BASE+234) +#define V4L2_CID_MPEG_VIDEO_DEC_CONCEAL_COLOR (V4L2_CID_CODEC_BASE+235) +#define V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD (V4L2_CID_CODEC_BASE+236) +#define V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD_TYPE (V4L2_CID_CODEC_BASE+237) +enum v4l2_mpeg_video_intra_refresh_period_type { + V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD_TYPE_RANDOM = 0, + V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD_TYPE_CYCLIC = 1, +}; + +/* CIDs for the MPEG-2 Part 2 (H.262) codec */ +#define V4L2_CID_MPEG_VIDEO_MPEG2_LEVEL (V4L2_CID_CODEC_BASE+270) +enum v4l2_mpeg_video_mpeg2_level { + V4L2_MPEG_VIDEO_MPEG2_LEVEL_LOW = 0, + V4L2_MPEG_VIDEO_MPEG2_LEVEL_MAIN = 1, + V4L2_MPEG_VIDEO_MPEG2_LEVEL_HIGH_1440 = 2, + V4L2_MPEG_VIDEO_MPEG2_LEVEL_HIGH = 3, +}; +#define V4L2_CID_MPEG_VIDEO_MPEG2_PROFILE (V4L2_CID_CODEC_BASE+271) +enum v4l2_mpeg_video_mpeg2_profile { + V4L2_MPEG_VIDEO_MPEG2_PROFILE_SIMPLE = 0, + V4L2_MPEG_VIDEO_MPEG2_PROFILE_MAIN = 1, + V4L2_MPEG_VIDEO_MPEG2_PROFILE_SNR_SCALABLE = 2, + V4L2_MPEG_VIDEO_MPEG2_PROFILE_SPATIALLY_SCALABLE = 3, + V4L2_MPEG_VIDEO_MPEG2_PROFILE_HIGH = 4, + V4L2_MPEG_VIDEO_MPEG2_PROFILE_MULTIVIEW = 5, +}; + +/* CIDs for the FWHT codec as used by the vicodec driver. */ +#define V4L2_CID_FWHT_I_FRAME_QP (V4L2_CID_CODEC_BASE + 290) +#define V4L2_CID_FWHT_P_FRAME_QP (V4L2_CID_CODEC_BASE + 291) + +#define V4L2_CID_MPEG_VIDEO_H263_I_FRAME_QP (V4L2_CID_CODEC_BASE+300) +#define V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP (V4L2_CID_CODEC_BASE+301) +#define V4L2_CID_MPEG_VIDEO_H263_B_FRAME_QP (V4L2_CID_CODEC_BASE+302) +#define V4L2_CID_MPEG_VIDEO_H263_MIN_QP (V4L2_CID_CODEC_BASE+303) +#define V4L2_CID_MPEG_VIDEO_H263_MAX_QP (V4L2_CID_CODEC_BASE+304) +#define V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP (V4L2_CID_CODEC_BASE+350) +#define V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP (V4L2_CID_CODEC_BASE+351) +#define V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP (V4L2_CID_CODEC_BASE+352) +#define V4L2_CID_MPEG_VIDEO_H264_MIN_QP (V4L2_CID_CODEC_BASE+353) +#define V4L2_CID_MPEG_VIDEO_H264_MAX_QP (V4L2_CID_CODEC_BASE+354) +#define V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM (V4L2_CID_CODEC_BASE+355) +#define V4L2_CID_MPEG_VIDEO_H264_CPB_SIZE (V4L2_CID_CODEC_BASE+356) +#define V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE (V4L2_CID_CODEC_BASE+357) +enum v4l2_mpeg_video_h264_entropy_mode { + V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CAVLC = 0, + V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CABAC = 1, +}; +#define V4L2_CID_MPEG_VIDEO_H264_I_PERIOD (V4L2_CID_CODEC_BASE+358) +#define V4L2_CID_MPEG_VIDEO_H264_LEVEL (V4L2_CID_CODEC_BASE+359) +enum v4l2_mpeg_video_h264_level { + V4L2_MPEG_VIDEO_H264_LEVEL_1_0 = 0, + V4L2_MPEG_VIDEO_H264_LEVEL_1B = 1, + V4L2_MPEG_VIDEO_H264_LEVEL_1_1 = 2, + V4L2_MPEG_VIDEO_H264_LEVEL_1_2 = 3, + V4L2_MPEG_VIDEO_H264_LEVEL_1_3 = 4, + V4L2_MPEG_VIDEO_H264_LEVEL_2_0 = 5, + V4L2_MPEG_VIDEO_H264_LEVEL_2_1 = 6, + V4L2_MPEG_VIDEO_H264_LEVEL_2_2 = 7, + V4L2_MPEG_VIDEO_H264_LEVEL_3_0 = 8, + V4L2_MPEG_VIDEO_H264_LEVEL_3_1 = 9, + V4L2_MPEG_VIDEO_H264_LEVEL_3_2 = 10, + V4L2_MPEG_VIDEO_H264_LEVEL_4_0 = 11, + V4L2_MPEG_VIDEO_H264_LEVEL_4_1 = 12, + V4L2_MPEG_VIDEO_H264_LEVEL_4_2 = 13, + V4L2_MPEG_VIDEO_H264_LEVEL_5_0 = 14, + V4L2_MPEG_VIDEO_H264_LEVEL_5_1 = 15, + V4L2_MPEG_VIDEO_H264_LEVEL_5_2 = 16, + V4L2_MPEG_VIDEO_H264_LEVEL_6_0 = 17, + V4L2_MPEG_VIDEO_H264_LEVEL_6_1 = 18, + V4L2_MPEG_VIDEO_H264_LEVEL_6_2 = 19, +}; +#define V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA (V4L2_CID_CODEC_BASE+360) +#define V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA (V4L2_CID_CODEC_BASE+361) +#define V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE (V4L2_CID_CODEC_BASE+362) +enum v4l2_mpeg_video_h264_loop_filter_mode { + V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_ENABLED = 0, + V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED = 1, + V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED_AT_SLICE_BOUNDARY = 2, +}; +#define V4L2_CID_MPEG_VIDEO_H264_PROFILE (V4L2_CID_CODEC_BASE+363) +enum v4l2_mpeg_video_h264_profile { + V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE = 0, + V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE = 1, + V4L2_MPEG_VIDEO_H264_PROFILE_MAIN = 2, + V4L2_MPEG_VIDEO_H264_PROFILE_EXTENDED = 3, + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH = 4, + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_10 = 5, + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_422 = 6, + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_444_PREDICTIVE = 7, + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_10_INTRA = 8, + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_422_INTRA = 9, + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_444_INTRA = 10, + V4L2_MPEG_VIDEO_H264_PROFILE_CAVLC_444_INTRA = 11, + V4L2_MPEG_VIDEO_H264_PROFILE_SCALABLE_BASELINE = 12, + V4L2_MPEG_VIDEO_H264_PROFILE_SCALABLE_HIGH = 13, + V4L2_MPEG_VIDEO_H264_PROFILE_SCALABLE_HIGH_INTRA = 14, + V4L2_MPEG_VIDEO_H264_PROFILE_STEREO_HIGH = 15, + V4L2_MPEG_VIDEO_H264_PROFILE_MULTIVIEW_HIGH = 16, + V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_HIGH = 17, +}; +#define V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_HEIGHT (V4L2_CID_CODEC_BASE+364) +#define V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_WIDTH (V4L2_CID_CODEC_BASE+365) +#define V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_ENABLE (V4L2_CID_CODEC_BASE+366) +#define V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC (V4L2_CID_CODEC_BASE+367) +enum v4l2_mpeg_video_h264_vui_sar_idc { + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_UNSPECIFIED = 0, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_1x1 = 1, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_12x11 = 2, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_10x11 = 3, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_16x11 = 4, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_40x33 = 5, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_24x11 = 6, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_20x11 = 7, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_32x11 = 8, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_80x33 = 9, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_18x11 = 10, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_15x11 = 11, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_64x33 = 12, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_160x99 = 13, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_4x3 = 14, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_3x2 = 15, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_2x1 = 16, + V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_EXTENDED = 17, +}; +#define V4L2_CID_MPEG_VIDEO_H264_SEI_FRAME_PACKING (V4L2_CID_CODEC_BASE+368) +#define V4L2_CID_MPEG_VIDEO_H264_SEI_FP_CURRENT_FRAME_0 (V4L2_CID_CODEC_BASE+369) +#define V4L2_CID_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE (V4L2_CID_CODEC_BASE+370) +enum v4l2_mpeg_video_h264_sei_fp_arrangement_type { + V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_CHECKERBOARD = 0, + V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_COLUMN = 1, + V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_ROW = 2, + V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_SIDE_BY_SIDE = 3, + V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_TOP_BOTTOM = 4, + V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_TEMPORAL = 5, +}; +#define V4L2_CID_MPEG_VIDEO_H264_FMO (V4L2_CID_CODEC_BASE+371) +#define V4L2_CID_MPEG_VIDEO_H264_FMO_MAP_TYPE (V4L2_CID_CODEC_BASE+372) +enum v4l2_mpeg_video_h264_fmo_map_type { + V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_INTERLEAVED_SLICES = 0, + V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_SCATTERED_SLICES = 1, + V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_FOREGROUND_WITH_LEFT_OVER = 2, + V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_BOX_OUT = 3, + V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_RASTER_SCAN = 4, + V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_WIPE_SCAN = 5, + V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_EXPLICIT = 6, +}; +#define V4L2_CID_MPEG_VIDEO_H264_FMO_SLICE_GROUP (V4L2_CID_CODEC_BASE+373) +#define V4L2_CID_MPEG_VIDEO_H264_FMO_CHANGE_DIRECTION (V4L2_CID_CODEC_BASE+374) +enum v4l2_mpeg_video_h264_fmo_change_dir { + V4L2_MPEG_VIDEO_H264_FMO_CHANGE_DIR_RIGHT = 0, + V4L2_MPEG_VIDEO_H264_FMO_CHANGE_DIR_LEFT = 1, +}; +#define V4L2_CID_MPEG_VIDEO_H264_FMO_CHANGE_RATE (V4L2_CID_CODEC_BASE+375) +#define V4L2_CID_MPEG_VIDEO_H264_FMO_RUN_LENGTH (V4L2_CID_CODEC_BASE+376) +#define V4L2_CID_MPEG_VIDEO_H264_ASO (V4L2_CID_CODEC_BASE+377) +#define V4L2_CID_MPEG_VIDEO_H264_ASO_SLICE_ORDER (V4L2_CID_CODEC_BASE+378) +#define V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING (V4L2_CID_CODEC_BASE+379) +#define V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_TYPE (V4L2_CID_CODEC_BASE+380) +enum v4l2_mpeg_video_h264_hierarchical_coding_type { + V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_B = 0, + V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_P = 1, +}; +#define V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER (V4L2_CID_CODEC_BASE+381) +#define V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER_QP (V4L2_CID_CODEC_BASE+382) +#define V4L2_CID_MPEG_VIDEO_H264_CONSTRAINED_INTRA_PREDICTION (V4L2_CID_CODEC_BASE+383) +#define V4L2_CID_MPEG_VIDEO_H264_CHROMA_QP_INDEX_OFFSET (V4L2_CID_CODEC_BASE+384) +#define V4L2_CID_MPEG_VIDEO_H264_I_FRAME_MIN_QP (V4L2_CID_CODEC_BASE+385) +#define V4L2_CID_MPEG_VIDEO_H264_I_FRAME_MAX_QP (V4L2_CID_CODEC_BASE+386) +#define V4L2_CID_MPEG_VIDEO_H264_P_FRAME_MIN_QP (V4L2_CID_CODEC_BASE+387) +#define V4L2_CID_MPEG_VIDEO_H264_P_FRAME_MAX_QP (V4L2_CID_CODEC_BASE+388) +#define V4L2_CID_MPEG_VIDEO_H264_B_FRAME_MIN_QP (V4L2_CID_CODEC_BASE+389) +#define V4L2_CID_MPEG_VIDEO_H264_B_FRAME_MAX_QP (V4L2_CID_CODEC_BASE+390) +#define V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L0_BR (V4L2_CID_CODEC_BASE+391) +#define V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L1_BR (V4L2_CID_CODEC_BASE+392) +#define V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L2_BR (V4L2_CID_CODEC_BASE+393) +#define V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L3_BR (V4L2_CID_CODEC_BASE+394) +#define V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L4_BR (V4L2_CID_CODEC_BASE+395) +#define V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L5_BR (V4L2_CID_CODEC_BASE+396) +#define V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L6_BR (V4L2_CID_CODEC_BASE+397) +#define V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP (V4L2_CID_CODEC_BASE+400) +#define V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP (V4L2_CID_CODEC_BASE+401) +#define V4L2_CID_MPEG_VIDEO_MPEG4_B_FRAME_QP (V4L2_CID_CODEC_BASE+402) +#define V4L2_CID_MPEG_VIDEO_MPEG4_MIN_QP (V4L2_CID_CODEC_BASE+403) +#define V4L2_CID_MPEG_VIDEO_MPEG4_MAX_QP (V4L2_CID_CODEC_BASE+404) +#define V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL (V4L2_CID_CODEC_BASE+405) +enum v4l2_mpeg_video_mpeg4_level { + V4L2_MPEG_VIDEO_MPEG4_LEVEL_0 = 0, + V4L2_MPEG_VIDEO_MPEG4_LEVEL_0B = 1, + V4L2_MPEG_VIDEO_MPEG4_LEVEL_1 = 2, + V4L2_MPEG_VIDEO_MPEG4_LEVEL_2 = 3, + V4L2_MPEG_VIDEO_MPEG4_LEVEL_3 = 4, + V4L2_MPEG_VIDEO_MPEG4_LEVEL_3B = 5, + V4L2_MPEG_VIDEO_MPEG4_LEVEL_4 = 6, + V4L2_MPEG_VIDEO_MPEG4_LEVEL_5 = 7, +}; +#define V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE (V4L2_CID_CODEC_BASE+406) +enum v4l2_mpeg_video_mpeg4_profile { + V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE = 0, + V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_SIMPLE = 1, + V4L2_MPEG_VIDEO_MPEG4_PROFILE_CORE = 2, + V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE_SCALABLE = 3, + V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_CODING_EFFICIENCY = 4, +}; +#define V4L2_CID_MPEG_VIDEO_MPEG4_QPEL (V4L2_CID_CODEC_BASE+407) + +/* Control IDs for VP8 streams + * Although VP8 is not part of MPEG we add these controls to the MPEG class + * as that class is already handling other video compression standards + */ +#define V4L2_CID_MPEG_VIDEO_VPX_NUM_PARTITIONS (V4L2_CID_CODEC_BASE+500) +enum v4l2_vp8_num_partitions { + V4L2_CID_MPEG_VIDEO_VPX_1_PARTITION = 0, + V4L2_CID_MPEG_VIDEO_VPX_2_PARTITIONS = 1, + V4L2_CID_MPEG_VIDEO_VPX_4_PARTITIONS = 2, + V4L2_CID_MPEG_VIDEO_VPX_8_PARTITIONS = 3, +}; +#define V4L2_CID_MPEG_VIDEO_VPX_IMD_DISABLE_4X4 (V4L2_CID_CODEC_BASE+501) +#define V4L2_CID_MPEG_VIDEO_VPX_NUM_REF_FRAMES (V4L2_CID_CODEC_BASE+502) +enum v4l2_vp8_num_ref_frames { + V4L2_CID_MPEG_VIDEO_VPX_1_REF_FRAME = 0, + V4L2_CID_MPEG_VIDEO_VPX_2_REF_FRAME = 1, + V4L2_CID_MPEG_VIDEO_VPX_3_REF_FRAME = 2, +}; +#define V4L2_CID_MPEG_VIDEO_VPX_FILTER_LEVEL (V4L2_CID_CODEC_BASE+503) +#define V4L2_CID_MPEG_VIDEO_VPX_FILTER_SHARPNESS (V4L2_CID_CODEC_BASE+504) +#define V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_REF_PERIOD (V4L2_CID_CODEC_BASE+505) +#define V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_SEL (V4L2_CID_CODEC_BASE+506) +enum v4l2_vp8_golden_frame_sel { + V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_USE_PREV = 0, + V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_USE_REF_PERIOD = 1, +}; +#define V4L2_CID_MPEG_VIDEO_VPX_MIN_QP (V4L2_CID_CODEC_BASE+507) +#define V4L2_CID_MPEG_VIDEO_VPX_MAX_QP (V4L2_CID_CODEC_BASE+508) +#define V4L2_CID_MPEG_VIDEO_VPX_I_FRAME_QP (V4L2_CID_CODEC_BASE+509) +#define V4L2_CID_MPEG_VIDEO_VPX_P_FRAME_QP (V4L2_CID_CODEC_BASE+510) + +#define V4L2_CID_MPEG_VIDEO_VP8_PROFILE (V4L2_CID_CODEC_BASE+511) +enum v4l2_mpeg_video_vp8_profile { + V4L2_MPEG_VIDEO_VP8_PROFILE_0 = 0, + V4L2_MPEG_VIDEO_VP8_PROFILE_1 = 1, + V4L2_MPEG_VIDEO_VP8_PROFILE_2 = 2, + V4L2_MPEG_VIDEO_VP8_PROFILE_3 = 3, +}; +/* Deprecated alias for compatibility reasons. */ +#define V4L2_CID_MPEG_VIDEO_VPX_PROFILE V4L2_CID_MPEG_VIDEO_VP8_PROFILE +#define V4L2_CID_MPEG_VIDEO_VP9_PROFILE (V4L2_CID_CODEC_BASE+512) +enum v4l2_mpeg_video_vp9_profile { + V4L2_MPEG_VIDEO_VP9_PROFILE_0 = 0, + V4L2_MPEG_VIDEO_VP9_PROFILE_1 = 1, + V4L2_MPEG_VIDEO_VP9_PROFILE_2 = 2, + V4L2_MPEG_VIDEO_VP9_PROFILE_3 = 3, +}; +#define V4L2_CID_MPEG_VIDEO_VP9_LEVEL (V4L2_CID_CODEC_BASE+513) +enum v4l2_mpeg_video_vp9_level { + V4L2_MPEG_VIDEO_VP9_LEVEL_1_0 = 0, + V4L2_MPEG_VIDEO_VP9_LEVEL_1_1 = 1, + V4L2_MPEG_VIDEO_VP9_LEVEL_2_0 = 2, + V4L2_MPEG_VIDEO_VP9_LEVEL_2_1 = 3, + V4L2_MPEG_VIDEO_VP9_LEVEL_3_0 = 4, + V4L2_MPEG_VIDEO_VP9_LEVEL_3_1 = 5, + V4L2_MPEG_VIDEO_VP9_LEVEL_4_0 = 6, + V4L2_MPEG_VIDEO_VP9_LEVEL_4_1 = 7, + V4L2_MPEG_VIDEO_VP9_LEVEL_5_0 = 8, + V4L2_MPEG_VIDEO_VP9_LEVEL_5_1 = 9, + V4L2_MPEG_VIDEO_VP9_LEVEL_5_2 = 10, + V4L2_MPEG_VIDEO_VP9_LEVEL_6_0 = 11, + V4L2_MPEG_VIDEO_VP9_LEVEL_6_1 = 12, + V4L2_MPEG_VIDEO_VP9_LEVEL_6_2 = 13, +}; + +/* CIDs for HEVC encoding. */ + +#define V4L2_CID_MPEG_VIDEO_HEVC_MIN_QP (V4L2_CID_CODEC_BASE + 600) +#define V4L2_CID_MPEG_VIDEO_HEVC_MAX_QP (V4L2_CID_CODEC_BASE + 601) +#define V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_QP (V4L2_CID_CODEC_BASE + 602) +#define V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_QP (V4L2_CID_CODEC_BASE + 603) +#define V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_QP (V4L2_CID_CODEC_BASE + 604) +#define V4L2_CID_MPEG_VIDEO_HEVC_HIER_QP (V4L2_CID_CODEC_BASE + 605) +#define V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_TYPE (V4L2_CID_CODEC_BASE + 606) +enum v4l2_mpeg_video_hevc_hier_coding_type { + V4L2_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_B = 0, + V4L2_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_P = 1, +}; +#define V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_LAYER (V4L2_CID_CODEC_BASE + 607) +#define V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L0_QP (V4L2_CID_CODEC_BASE + 608) +#define V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L1_QP (V4L2_CID_CODEC_BASE + 609) +#define V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L2_QP (V4L2_CID_CODEC_BASE + 610) +#define V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L3_QP (V4L2_CID_CODEC_BASE + 611) +#define V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L4_QP (V4L2_CID_CODEC_BASE + 612) +#define V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L5_QP (V4L2_CID_CODEC_BASE + 613) +#define V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L6_QP (V4L2_CID_CODEC_BASE + 614) +#define V4L2_CID_MPEG_VIDEO_HEVC_PROFILE (V4L2_CID_CODEC_BASE + 615) +enum v4l2_mpeg_video_hevc_profile { + V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN = 0, + V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_STILL_PICTURE = 1, + V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10 = 2, +}; +#define V4L2_CID_MPEG_VIDEO_HEVC_LEVEL (V4L2_CID_CODEC_BASE + 616) +enum v4l2_mpeg_video_hevc_level { + V4L2_MPEG_VIDEO_HEVC_LEVEL_1 = 0, + V4L2_MPEG_VIDEO_HEVC_LEVEL_2 = 1, + V4L2_MPEG_VIDEO_HEVC_LEVEL_2_1 = 2, + V4L2_MPEG_VIDEO_HEVC_LEVEL_3 = 3, + V4L2_MPEG_VIDEO_HEVC_LEVEL_3_1 = 4, + V4L2_MPEG_VIDEO_HEVC_LEVEL_4 = 5, + V4L2_MPEG_VIDEO_HEVC_LEVEL_4_1 = 6, + V4L2_MPEG_VIDEO_HEVC_LEVEL_5 = 7, + V4L2_MPEG_VIDEO_HEVC_LEVEL_5_1 = 8, + V4L2_MPEG_VIDEO_HEVC_LEVEL_5_2 = 9, + V4L2_MPEG_VIDEO_HEVC_LEVEL_6 = 10, + V4L2_MPEG_VIDEO_HEVC_LEVEL_6_1 = 11, + V4L2_MPEG_VIDEO_HEVC_LEVEL_6_2 = 12, +}; +#define V4L2_CID_MPEG_VIDEO_HEVC_FRAME_RATE_RESOLUTION (V4L2_CID_CODEC_BASE + 617) +#define V4L2_CID_MPEG_VIDEO_HEVC_TIER (V4L2_CID_CODEC_BASE + 618) +enum v4l2_mpeg_video_hevc_tier { + V4L2_MPEG_VIDEO_HEVC_TIER_MAIN = 0, + V4L2_MPEG_VIDEO_HEVC_TIER_HIGH = 1, +}; +#define V4L2_CID_MPEG_VIDEO_HEVC_MAX_PARTITION_DEPTH (V4L2_CID_CODEC_BASE + 619) +#define V4L2_CID_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE (V4L2_CID_CODEC_BASE + 620) +enum v4l2_cid_mpeg_video_hevc_loop_filter_mode { + V4L2_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE_DISABLED = 0, + V4L2_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE_ENABLED = 1, + V4L2_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE_DISABLED_AT_SLICE_BOUNDARY = 2, +}; +#define V4L2_CID_MPEG_VIDEO_HEVC_LF_BETA_OFFSET_DIV2 (V4L2_CID_CODEC_BASE + 621) +#define V4L2_CID_MPEG_VIDEO_HEVC_LF_TC_OFFSET_DIV2 (V4L2_CID_CODEC_BASE + 622) +#define V4L2_CID_MPEG_VIDEO_HEVC_REFRESH_TYPE (V4L2_CID_CODEC_BASE + 623) +enum v4l2_cid_mpeg_video_hevc_refresh_type { + V4L2_MPEG_VIDEO_HEVC_REFRESH_NONE = 0, + V4L2_MPEG_VIDEO_HEVC_REFRESH_CRA = 1, + V4L2_MPEG_VIDEO_HEVC_REFRESH_IDR = 2, +}; +#define V4L2_CID_MPEG_VIDEO_HEVC_REFRESH_PERIOD (V4L2_CID_CODEC_BASE + 624) +#define V4L2_CID_MPEG_VIDEO_HEVC_LOSSLESS_CU (V4L2_CID_CODEC_BASE + 625) +#define V4L2_CID_MPEG_VIDEO_HEVC_CONST_INTRA_PRED (V4L2_CID_CODEC_BASE + 626) +#define V4L2_CID_MPEG_VIDEO_HEVC_WAVEFRONT (V4L2_CID_CODEC_BASE + 627) +#define V4L2_CID_MPEG_VIDEO_HEVC_GENERAL_PB (V4L2_CID_CODEC_BASE + 628) +#define V4L2_CID_MPEG_VIDEO_HEVC_TEMPORAL_ID (V4L2_CID_CODEC_BASE + 629) +#define V4L2_CID_MPEG_VIDEO_HEVC_STRONG_SMOOTHING (V4L2_CID_CODEC_BASE + 630) +#define V4L2_CID_MPEG_VIDEO_HEVC_MAX_NUM_MERGE_MV_MINUS1 (V4L2_CID_CODEC_BASE + 631) +#define V4L2_CID_MPEG_VIDEO_HEVC_INTRA_PU_SPLIT (V4L2_CID_CODEC_BASE + 632) +#define V4L2_CID_MPEG_VIDEO_HEVC_TMV_PREDICTION (V4L2_CID_CODEC_BASE + 633) +#define V4L2_CID_MPEG_VIDEO_HEVC_WITHOUT_STARTCODE (V4L2_CID_CODEC_BASE + 634) +#define V4L2_CID_MPEG_VIDEO_HEVC_SIZE_OF_LENGTH_FIELD (V4L2_CID_CODEC_BASE + 635) +enum v4l2_cid_mpeg_video_hevc_size_of_length_field { + V4L2_MPEG_VIDEO_HEVC_SIZE_0 = 0, + V4L2_MPEG_VIDEO_HEVC_SIZE_1 = 1, + V4L2_MPEG_VIDEO_HEVC_SIZE_2 = 2, + V4L2_MPEG_VIDEO_HEVC_SIZE_4 = 3, +}; +#define V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L0_BR (V4L2_CID_CODEC_BASE + 636) +#define V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L1_BR (V4L2_CID_CODEC_BASE + 637) +#define V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L2_BR (V4L2_CID_CODEC_BASE + 638) +#define V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L3_BR (V4L2_CID_CODEC_BASE + 639) +#define V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L4_BR (V4L2_CID_CODEC_BASE + 640) +#define V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L5_BR (V4L2_CID_CODEC_BASE + 641) +#define V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L6_BR (V4L2_CID_CODEC_BASE + 642) +#define V4L2_CID_MPEG_VIDEO_REF_NUMBER_FOR_PFRAMES (V4L2_CID_CODEC_BASE + 643) +#define V4L2_CID_MPEG_VIDEO_PREPEND_SPSPPS_TO_IDR (V4L2_CID_CODEC_BASE + 644) +#define V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITY (V4L2_CID_CODEC_BASE + 645) +#define V4L2_CID_MPEG_VIDEO_FRAME_SKIP_MODE (V4L2_CID_CODEC_BASE + 646) +enum v4l2_mpeg_video_frame_skip_mode { + V4L2_MPEG_VIDEO_FRAME_SKIP_MODE_DISABLED = 0, + V4L2_MPEG_VIDEO_FRAME_SKIP_MODE_LEVEL_LIMIT = 1, + V4L2_MPEG_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT = 2, +}; + +#define V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_MIN_QP (V4L2_CID_CODEC_BASE + 647) +#define V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_MAX_QP (V4L2_CID_CODEC_BASE + 648) +#define V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_MIN_QP (V4L2_CID_CODEC_BASE + 649) +#define V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_MAX_QP (V4L2_CID_CODEC_BASE + 650) +#define V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_MIN_QP (V4L2_CID_CODEC_BASE + 651) +#define V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_MAX_QP (V4L2_CID_CODEC_BASE + 652) + +#define V4L2_CID_MPEG_VIDEO_DEC_DISPLAY_DELAY (V4L2_CID_CODEC_BASE + 653) +#define V4L2_CID_MPEG_VIDEO_DEC_DISPLAY_DELAY_ENABLE (V4L2_CID_CODEC_BASE + 654) + +#define V4L2_CID_MPEG_VIDEO_AV1_PROFILE (V4L2_CID_CODEC_BASE + 655) +/** + * enum v4l2_mpeg_video_av1_profile - AV1 profiles + * + * @V4L2_MPEG_VIDEO_AV1_PROFILE_MAIN: compliant decoders must be able to decode + * streams with seq_profile equal to 0. + * @V4L2_MPEG_VIDEO_AV1_PROFILE_HIGH: compliant decoders must be able to decode + * streams with seq_profile equal less than or equal to 1. + * @V4L2_MPEG_VIDEO_AV1_PROFILE_PROFESSIONAL: compliant decoders must be able to + * decode streams with seq_profile less than or equal to 2. + * + * Conveys the highest profile a decoder can work with. + */ +enum v4l2_mpeg_video_av1_profile { + V4L2_MPEG_VIDEO_AV1_PROFILE_MAIN = 0, + V4L2_MPEG_VIDEO_AV1_PROFILE_HIGH = 1, + V4L2_MPEG_VIDEO_AV1_PROFILE_PROFESSIONAL = 2, +}; + +#define V4L2_CID_MPEG_VIDEO_AV1_LEVEL (V4L2_CID_CODEC_BASE + 656) +/** + * enum v4l2_mpeg_video_av1_level - AV1 levels + * + * @V4L2_MPEG_VIDEO_AV1_LEVEL_2_0: Level 2.0. + * @V4L2_MPEG_VIDEO_AV1_LEVEL_2_1: Level 2.1. + * @V4L2_MPEG_VIDEO_AV1_LEVEL_2_2: Level 2.2. + * @V4L2_MPEG_VIDEO_AV1_LEVEL_2_3: Level 2.3. + * @V4L2_MPEG_VIDEO_AV1_LEVEL_3_0: Level 3.0. + * @V4L2_MPEG_VIDEO_AV1_LEVEL_3_1: Level 3.1. + * @V4L2_MPEG_VIDEO_AV1_LEVEL_3_2: Level 3.2. + * @V4L2_MPEG_VIDEO_AV1_LEVEL_3_3: Level 3.3. + * @V4L2_MPEG_VIDEO_AV1_LEVEL_4_0: Level 4.0. + * @V4L2_MPEG_VIDEO_AV1_LEVEL_4_1: Level 4.1. + * @V4L2_MPEG_VIDEO_AV1_LEVEL_4_2: Level 4.2. + * @V4L2_MPEG_VIDEO_AV1_LEVEL_4_3: Level 4.3. + * @V4L2_MPEG_VIDEO_AV1_LEVEL_5_0: Level 5.0. + * @V4L2_MPEG_VIDEO_AV1_LEVEL_5_1: Level 5.1. + * @V4L2_MPEG_VIDEO_AV1_LEVEL_5_2: Level 5.2. + * @V4L2_MPEG_VIDEO_AV1_LEVEL_5_3: Level 5.3. + * @V4L2_MPEG_VIDEO_AV1_LEVEL_6_0: Level 6.0. + * @V4L2_MPEG_VIDEO_AV1_LEVEL_6_1: Level 6.1. + * @V4L2_MPEG_VIDEO_AV1_LEVEL_6_2: Level 6.2. + * @V4L2_MPEG_VIDEO_AV1_LEVEL_6_3: Level 6.3. + * @V4L2_MPEG_VIDEO_AV1_LEVEL_7_0: Level 7.0. + * @V4L2_MPEG_VIDEO_AV1_LEVEL_7_1: Level 7.1. + * @V4L2_MPEG_VIDEO_AV1_LEVEL_7_2: Level 7.2. + * @V4L2_MPEG_VIDEO_AV1_LEVEL_7_3: Level 7.3. + * + * Conveys the highest level a decoder can work with. + */ +enum v4l2_mpeg_video_av1_level { + V4L2_MPEG_VIDEO_AV1_LEVEL_2_0 = 0, + V4L2_MPEG_VIDEO_AV1_LEVEL_2_1 = 1, + V4L2_MPEG_VIDEO_AV1_LEVEL_2_2 = 2, + V4L2_MPEG_VIDEO_AV1_LEVEL_2_3 = 3, + + V4L2_MPEG_VIDEO_AV1_LEVEL_3_0 = 4, + V4L2_MPEG_VIDEO_AV1_LEVEL_3_1 = 5, + V4L2_MPEG_VIDEO_AV1_LEVEL_3_2 = 6, + V4L2_MPEG_VIDEO_AV1_LEVEL_3_3 = 7, + + V4L2_MPEG_VIDEO_AV1_LEVEL_4_0 = 8, + V4L2_MPEG_VIDEO_AV1_LEVEL_4_1 = 9, + V4L2_MPEG_VIDEO_AV1_LEVEL_4_2 = 10, + V4L2_MPEG_VIDEO_AV1_LEVEL_4_3 = 11, + + V4L2_MPEG_VIDEO_AV1_LEVEL_5_0 = 12, + V4L2_MPEG_VIDEO_AV1_LEVEL_5_1 = 13, + V4L2_MPEG_VIDEO_AV1_LEVEL_5_2 = 14, + V4L2_MPEG_VIDEO_AV1_LEVEL_5_3 = 15, + + V4L2_MPEG_VIDEO_AV1_LEVEL_6_0 = 16, + V4L2_MPEG_VIDEO_AV1_LEVEL_6_1 = 17, + V4L2_MPEG_VIDEO_AV1_LEVEL_6_2 = 18, + V4L2_MPEG_VIDEO_AV1_LEVEL_6_3 = 19, + + V4L2_MPEG_VIDEO_AV1_LEVEL_7_0 = 20, + V4L2_MPEG_VIDEO_AV1_LEVEL_7_1 = 21, + V4L2_MPEG_VIDEO_AV1_LEVEL_7_2 = 22, + V4L2_MPEG_VIDEO_AV1_LEVEL_7_3 = 23 +}; + +#define V4L2_CID_MPEG_VIDEO_AVERAGE_QP (V4L2_CID_CODEC_BASE + 657) + +/* MPEG-class control IDs specific to the CX2341x driver as defined by V4L2 */ +#define V4L2_CID_CODEC_CX2341X_BASE (V4L2_CTRL_CLASS_CODEC | 0x1000) +#define V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE (V4L2_CID_CODEC_CX2341X_BASE+0) +enum v4l2_mpeg_cx2341x_video_spatial_filter_mode { + V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_MANUAL = 0, + V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO = 1, +}; +#define V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER (V4L2_CID_CODEC_CX2341X_BASE+1) +#define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE (V4L2_CID_CODEC_CX2341X_BASE+2) +enum v4l2_mpeg_cx2341x_video_luma_spatial_filter_type { + V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_OFF = 0, + V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_HOR = 1, + V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_VERT = 2, + V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_HV_SEPARABLE = 3, + V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_SYM_NON_SEPARABLE = 4, +}; +#define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE (V4L2_CID_CODEC_CX2341X_BASE+3) +enum v4l2_mpeg_cx2341x_video_chroma_spatial_filter_type { + V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_OFF = 0, + V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_1D_HOR = 1, +}; +#define V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE (V4L2_CID_CODEC_CX2341X_BASE+4) +enum v4l2_mpeg_cx2341x_video_temporal_filter_mode { + V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL = 0, + V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_AUTO = 1, +}; +#define V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER (V4L2_CID_CODEC_CX2341X_BASE+5) +#define V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE (V4L2_CID_CODEC_CX2341X_BASE+6) +enum v4l2_mpeg_cx2341x_video_median_filter_type { + V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF = 0, + V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_HOR = 1, + V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_VERT = 2, + V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_HOR_VERT = 3, + V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_DIAG = 4, +}; +#define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM (V4L2_CID_CODEC_CX2341X_BASE+7) +#define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP (V4L2_CID_CODEC_CX2341X_BASE+8) +#define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM (V4L2_CID_CODEC_CX2341X_BASE+9) +#define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP (V4L2_CID_CODEC_CX2341X_BASE+10) +#define V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS (V4L2_CID_CODEC_CX2341X_BASE+11) + +/* MPEG-class control IDs specific to the Samsung MFC 5.1 driver as defined by V4L2 */ +#define V4L2_CID_CODEC_MFC51_BASE (V4L2_CTRL_CLASS_CODEC | 0x1100) + +#define V4L2_CID_MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY (V4L2_CID_CODEC_MFC51_BASE+0) +#define V4L2_CID_MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY_ENABLE (V4L2_CID_CODEC_MFC51_BASE+1) +#define V4L2_CID_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE (V4L2_CID_CODEC_MFC51_BASE+2) +enum v4l2_mpeg_mfc51_video_frame_skip_mode { + V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_DISABLED = 0, + V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_LEVEL_LIMIT = 1, + V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT = 2, +}; +#define V4L2_CID_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE (V4L2_CID_CODEC_MFC51_BASE+3) +enum v4l2_mpeg_mfc51_video_force_frame_type { + V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_DISABLED = 0, + V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_I_FRAME = 1, + V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_NOT_CODED = 2, +}; +#define V4L2_CID_MPEG_MFC51_VIDEO_PADDING (V4L2_CID_CODEC_MFC51_BASE+4) +#define V4L2_CID_MPEG_MFC51_VIDEO_PADDING_YUV (V4L2_CID_CODEC_MFC51_BASE+5) +#define V4L2_CID_MPEG_MFC51_VIDEO_RC_FIXED_TARGET_BIT (V4L2_CID_CODEC_MFC51_BASE+6) +#define V4L2_CID_MPEG_MFC51_VIDEO_RC_REACTION_COEFF (V4L2_CID_CODEC_MFC51_BASE+7) +#define V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_ACTIVITY (V4L2_CID_CODEC_MFC51_BASE+50) +#define V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_DARK (V4L2_CID_CODEC_MFC51_BASE+51) +#define V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_SMOOTH (V4L2_CID_CODEC_MFC51_BASE+52) +#define V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_STATIC (V4L2_CID_CODEC_MFC51_BASE+53) +#define V4L2_CID_MPEG_MFC51_VIDEO_H264_NUM_REF_PIC_FOR_P (V4L2_CID_CODEC_MFC51_BASE+54) + +/* Camera class control IDs */ + +#define V4L2_CID_CAMERA_CLASS_BASE (V4L2_CTRL_CLASS_CAMERA | 0x900) +#define V4L2_CID_CAMERA_CLASS (V4L2_CTRL_CLASS_CAMERA | 1) + +#define V4L2_CID_EXPOSURE_AUTO (V4L2_CID_CAMERA_CLASS_BASE+1) +enum v4l2_exposure_auto_type { + V4L2_EXPOSURE_AUTO = 0, + V4L2_EXPOSURE_MANUAL = 1, + V4L2_EXPOSURE_SHUTTER_PRIORITY = 2, + V4L2_EXPOSURE_APERTURE_PRIORITY = 3 +}; +#define V4L2_CID_EXPOSURE_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+2) +#define V4L2_CID_EXPOSURE_AUTO_PRIORITY (V4L2_CID_CAMERA_CLASS_BASE+3) + +#define V4L2_CID_PAN_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+4) +#define V4L2_CID_TILT_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+5) +#define V4L2_CID_PAN_RESET (V4L2_CID_CAMERA_CLASS_BASE+6) +#define V4L2_CID_TILT_RESET (V4L2_CID_CAMERA_CLASS_BASE+7) + +#define V4L2_CID_PAN_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+8) +#define V4L2_CID_TILT_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+9) + +#define V4L2_CID_FOCUS_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+10) +#define V4L2_CID_FOCUS_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+11) +#define V4L2_CID_FOCUS_AUTO (V4L2_CID_CAMERA_CLASS_BASE+12) + +#define V4L2_CID_ZOOM_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+13) +#define V4L2_CID_ZOOM_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+14) +#define V4L2_CID_ZOOM_CONTINUOUS (V4L2_CID_CAMERA_CLASS_BASE+15) + +#define V4L2_CID_PRIVACY (V4L2_CID_CAMERA_CLASS_BASE+16) + +#define V4L2_CID_IRIS_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+17) +#define V4L2_CID_IRIS_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+18) + +#define V4L2_CID_AUTO_EXPOSURE_BIAS (V4L2_CID_CAMERA_CLASS_BASE+19) + +#define V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE (V4L2_CID_CAMERA_CLASS_BASE+20) +enum v4l2_auto_n_preset_white_balance { + V4L2_WHITE_BALANCE_MANUAL = 0, + V4L2_WHITE_BALANCE_AUTO = 1, + V4L2_WHITE_BALANCE_INCANDESCENT = 2, + V4L2_WHITE_BALANCE_FLUORESCENT = 3, + V4L2_WHITE_BALANCE_FLUORESCENT_H = 4, + V4L2_WHITE_BALANCE_HORIZON = 5, + V4L2_WHITE_BALANCE_DAYLIGHT = 6, + V4L2_WHITE_BALANCE_FLASH = 7, + V4L2_WHITE_BALANCE_CLOUDY = 8, + V4L2_WHITE_BALANCE_SHADE = 9, +}; + +#define V4L2_CID_WIDE_DYNAMIC_RANGE (V4L2_CID_CAMERA_CLASS_BASE+21) +#define V4L2_CID_IMAGE_STABILIZATION (V4L2_CID_CAMERA_CLASS_BASE+22) + +#define V4L2_CID_ISO_SENSITIVITY (V4L2_CID_CAMERA_CLASS_BASE+23) +#define V4L2_CID_ISO_SENSITIVITY_AUTO (V4L2_CID_CAMERA_CLASS_BASE+24) +enum v4l2_iso_sensitivity_auto_type { + V4L2_ISO_SENSITIVITY_MANUAL = 0, + V4L2_ISO_SENSITIVITY_AUTO = 1, +}; + +#define V4L2_CID_EXPOSURE_METERING (V4L2_CID_CAMERA_CLASS_BASE+25) +enum v4l2_exposure_metering { + V4L2_EXPOSURE_METERING_AVERAGE = 0, + V4L2_EXPOSURE_METERING_CENTER_WEIGHTED = 1, + V4L2_EXPOSURE_METERING_SPOT = 2, + V4L2_EXPOSURE_METERING_MATRIX = 3, +}; + +#define V4L2_CID_SCENE_MODE (V4L2_CID_CAMERA_CLASS_BASE+26) +enum v4l2_scene_mode { + V4L2_SCENE_MODE_NONE = 0, + V4L2_SCENE_MODE_BACKLIGHT = 1, + V4L2_SCENE_MODE_BEACH_SNOW = 2, + V4L2_SCENE_MODE_CANDLE_LIGHT = 3, + V4L2_SCENE_MODE_DAWN_DUSK = 4, + V4L2_SCENE_MODE_FALL_COLORS = 5, + V4L2_SCENE_MODE_FIREWORKS = 6, + V4L2_SCENE_MODE_LANDSCAPE = 7, + V4L2_SCENE_MODE_NIGHT = 8, + V4L2_SCENE_MODE_PARTY_INDOOR = 9, + V4L2_SCENE_MODE_PORTRAIT = 10, + V4L2_SCENE_MODE_SPORTS = 11, + V4L2_SCENE_MODE_SUNSET = 12, + V4L2_SCENE_MODE_TEXT = 13, +}; + +#define V4L2_CID_3A_LOCK (V4L2_CID_CAMERA_CLASS_BASE+27) +#define V4L2_LOCK_EXPOSURE (1 << 0) +#define V4L2_LOCK_WHITE_BALANCE (1 << 1) +#define V4L2_LOCK_FOCUS (1 << 2) + +#define V4L2_CID_AUTO_FOCUS_START (V4L2_CID_CAMERA_CLASS_BASE+28) +#define V4L2_CID_AUTO_FOCUS_STOP (V4L2_CID_CAMERA_CLASS_BASE+29) +#define V4L2_CID_AUTO_FOCUS_STATUS (V4L2_CID_CAMERA_CLASS_BASE+30) +#define V4L2_AUTO_FOCUS_STATUS_IDLE (0 << 0) +#define V4L2_AUTO_FOCUS_STATUS_BUSY (1 << 0) +#define V4L2_AUTO_FOCUS_STATUS_REACHED (1 << 1) +#define V4L2_AUTO_FOCUS_STATUS_FAILED (1 << 2) + +#define V4L2_CID_AUTO_FOCUS_RANGE (V4L2_CID_CAMERA_CLASS_BASE+31) +enum v4l2_auto_focus_range { + V4L2_AUTO_FOCUS_RANGE_AUTO = 0, + V4L2_AUTO_FOCUS_RANGE_NORMAL = 1, + V4L2_AUTO_FOCUS_RANGE_MACRO = 2, + V4L2_AUTO_FOCUS_RANGE_INFINITY = 3, +}; + +#define V4L2_CID_PAN_SPEED (V4L2_CID_CAMERA_CLASS_BASE+32) +#define V4L2_CID_TILT_SPEED (V4L2_CID_CAMERA_CLASS_BASE+33) + +#define V4L2_CID_CAMERA_ORIENTATION (V4L2_CID_CAMERA_CLASS_BASE+34) +#define V4L2_CAMERA_ORIENTATION_FRONT 0 +#define V4L2_CAMERA_ORIENTATION_BACK 1 +#define V4L2_CAMERA_ORIENTATION_EXTERNAL 2 + +#define V4L2_CID_CAMERA_SENSOR_ROTATION (V4L2_CID_CAMERA_CLASS_BASE+35) + +#define V4L2_CID_HDR_SENSOR_MODE (V4L2_CID_CAMERA_CLASS_BASE+36) + +/* FM Modulator class control IDs */ + +#define V4L2_CID_FM_TX_CLASS_BASE (V4L2_CTRL_CLASS_FM_TX | 0x900) +#define V4L2_CID_FM_TX_CLASS (V4L2_CTRL_CLASS_FM_TX | 1) + +#define V4L2_CID_RDS_TX_DEVIATION (V4L2_CID_FM_TX_CLASS_BASE + 1) +#define V4L2_CID_RDS_TX_PI (V4L2_CID_FM_TX_CLASS_BASE + 2) +#define V4L2_CID_RDS_TX_PTY (V4L2_CID_FM_TX_CLASS_BASE + 3) +#define V4L2_CID_RDS_TX_PS_NAME (V4L2_CID_FM_TX_CLASS_BASE + 5) +#define V4L2_CID_RDS_TX_RADIO_TEXT (V4L2_CID_FM_TX_CLASS_BASE + 6) +#define V4L2_CID_RDS_TX_MONO_STEREO (V4L2_CID_FM_TX_CLASS_BASE + 7) +#define V4L2_CID_RDS_TX_ARTIFICIAL_HEAD (V4L2_CID_FM_TX_CLASS_BASE + 8) +#define V4L2_CID_RDS_TX_COMPRESSED (V4L2_CID_FM_TX_CLASS_BASE + 9) +#define V4L2_CID_RDS_TX_DYNAMIC_PTY (V4L2_CID_FM_TX_CLASS_BASE + 10) +#define V4L2_CID_RDS_TX_TRAFFIC_ANNOUNCEMENT (V4L2_CID_FM_TX_CLASS_BASE + 11) +#define V4L2_CID_RDS_TX_TRAFFIC_PROGRAM (V4L2_CID_FM_TX_CLASS_BASE + 12) +#define V4L2_CID_RDS_TX_MUSIC_SPEECH (V4L2_CID_FM_TX_CLASS_BASE + 13) +#define V4L2_CID_RDS_TX_ALT_FREQS_ENABLE (V4L2_CID_FM_TX_CLASS_BASE + 14) +#define V4L2_CID_RDS_TX_ALT_FREQS (V4L2_CID_FM_TX_CLASS_BASE + 15) + +#define V4L2_CID_AUDIO_LIMITER_ENABLED (V4L2_CID_FM_TX_CLASS_BASE + 64) +#define V4L2_CID_AUDIO_LIMITER_RELEASE_TIME (V4L2_CID_FM_TX_CLASS_BASE + 65) +#define V4L2_CID_AUDIO_LIMITER_DEVIATION (V4L2_CID_FM_TX_CLASS_BASE + 66) + +#define V4L2_CID_AUDIO_COMPRESSION_ENABLED (V4L2_CID_FM_TX_CLASS_BASE + 80) +#define V4L2_CID_AUDIO_COMPRESSION_GAIN (V4L2_CID_FM_TX_CLASS_BASE + 81) +#define V4L2_CID_AUDIO_COMPRESSION_THRESHOLD (V4L2_CID_FM_TX_CLASS_BASE + 82) +#define V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME (V4L2_CID_FM_TX_CLASS_BASE + 83) +#define V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME (V4L2_CID_FM_TX_CLASS_BASE + 84) + +#define V4L2_CID_PILOT_TONE_ENABLED (V4L2_CID_FM_TX_CLASS_BASE + 96) +#define V4L2_CID_PILOT_TONE_DEVIATION (V4L2_CID_FM_TX_CLASS_BASE + 97) +#define V4L2_CID_PILOT_TONE_FREQUENCY (V4L2_CID_FM_TX_CLASS_BASE + 98) + +#define V4L2_CID_TUNE_PREEMPHASIS (V4L2_CID_FM_TX_CLASS_BASE + 112) +enum v4l2_preemphasis { + V4L2_PREEMPHASIS_DISABLED = 0, + V4L2_PREEMPHASIS_50_uS = 1, + V4L2_PREEMPHASIS_75_uS = 2, +}; +#define V4L2_CID_TUNE_POWER_LEVEL (V4L2_CID_FM_TX_CLASS_BASE + 113) +#define V4L2_CID_TUNE_ANTENNA_CAPACITOR (V4L2_CID_FM_TX_CLASS_BASE + 114) + + +/* Flash and privacy (indicator) light controls */ + +#define V4L2_CID_FLASH_CLASS_BASE (V4L2_CTRL_CLASS_FLASH | 0x900) +#define V4L2_CID_FLASH_CLASS (V4L2_CTRL_CLASS_FLASH | 1) + +#define V4L2_CID_FLASH_LED_MODE (V4L2_CID_FLASH_CLASS_BASE + 1) +enum v4l2_flash_led_mode { + V4L2_FLASH_LED_MODE_NONE, + V4L2_FLASH_LED_MODE_FLASH, + V4L2_FLASH_LED_MODE_TORCH, +}; + +#define V4L2_CID_FLASH_STROBE_SOURCE (V4L2_CID_FLASH_CLASS_BASE + 2) +enum v4l2_flash_strobe_source { + V4L2_FLASH_STROBE_SOURCE_SOFTWARE, + V4L2_FLASH_STROBE_SOURCE_EXTERNAL, +}; + +#define V4L2_CID_FLASH_STROBE (V4L2_CID_FLASH_CLASS_BASE + 3) +#define V4L2_CID_FLASH_STROBE_STOP (V4L2_CID_FLASH_CLASS_BASE + 4) +#define V4L2_CID_FLASH_STROBE_STATUS (V4L2_CID_FLASH_CLASS_BASE + 5) + +#define V4L2_CID_FLASH_TIMEOUT (V4L2_CID_FLASH_CLASS_BASE + 6) +#define V4L2_CID_FLASH_INTENSITY (V4L2_CID_FLASH_CLASS_BASE + 7) +#define V4L2_CID_FLASH_TORCH_INTENSITY (V4L2_CID_FLASH_CLASS_BASE + 8) +#define V4L2_CID_FLASH_INDICATOR_INTENSITY (V4L2_CID_FLASH_CLASS_BASE + 9) + +#define V4L2_CID_FLASH_FAULT (V4L2_CID_FLASH_CLASS_BASE + 10) +#define V4L2_FLASH_FAULT_OVER_VOLTAGE (1 << 0) +#define V4L2_FLASH_FAULT_TIMEOUT (1 << 1) +#define V4L2_FLASH_FAULT_OVER_TEMPERATURE (1 << 2) +#define V4L2_FLASH_FAULT_SHORT_CIRCUIT (1 << 3) +#define V4L2_FLASH_FAULT_OVER_CURRENT (1 << 4) +#define V4L2_FLASH_FAULT_INDICATOR (1 << 5) +#define V4L2_FLASH_FAULT_UNDER_VOLTAGE (1 << 6) +#define V4L2_FLASH_FAULT_INPUT_VOLTAGE (1 << 7) +#define V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE (1 << 8) + +#define V4L2_CID_FLASH_CHARGE (V4L2_CID_FLASH_CLASS_BASE + 11) +#define V4L2_CID_FLASH_READY (V4L2_CID_FLASH_CLASS_BASE + 12) + + +/* JPEG-class control IDs */ + +#define V4L2_CID_JPEG_CLASS_BASE (V4L2_CTRL_CLASS_JPEG | 0x900) +#define V4L2_CID_JPEG_CLASS (V4L2_CTRL_CLASS_JPEG | 1) + +#define V4L2_CID_JPEG_CHROMA_SUBSAMPLING (V4L2_CID_JPEG_CLASS_BASE + 1) +enum v4l2_jpeg_chroma_subsampling { + V4L2_JPEG_CHROMA_SUBSAMPLING_444 = 0, + V4L2_JPEG_CHROMA_SUBSAMPLING_422 = 1, + V4L2_JPEG_CHROMA_SUBSAMPLING_420 = 2, + V4L2_JPEG_CHROMA_SUBSAMPLING_411 = 3, + V4L2_JPEG_CHROMA_SUBSAMPLING_410 = 4, + V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY = 5, +}; +#define V4L2_CID_JPEG_RESTART_INTERVAL (V4L2_CID_JPEG_CLASS_BASE + 2) +#define V4L2_CID_JPEG_COMPRESSION_QUALITY (V4L2_CID_JPEG_CLASS_BASE + 3) + +#define V4L2_CID_JPEG_ACTIVE_MARKER (V4L2_CID_JPEG_CLASS_BASE + 4) +#define V4L2_JPEG_ACTIVE_MARKER_APP0 (1 << 0) +#define V4L2_JPEG_ACTIVE_MARKER_APP1 (1 << 1) +#define V4L2_JPEG_ACTIVE_MARKER_COM (1 << 16) +#define V4L2_JPEG_ACTIVE_MARKER_DQT (1 << 17) +#define V4L2_JPEG_ACTIVE_MARKER_DHT (1 << 18) + + +/* Image source controls */ +#define V4L2_CID_IMAGE_SOURCE_CLASS_BASE (V4L2_CTRL_CLASS_IMAGE_SOURCE | 0x900) +#define V4L2_CID_IMAGE_SOURCE_CLASS (V4L2_CTRL_CLASS_IMAGE_SOURCE | 1) + +#define V4L2_CID_VBLANK (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 1) +#define V4L2_CID_HBLANK (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 2) +#define V4L2_CID_ANALOGUE_GAIN (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 3) +#define V4L2_CID_TEST_PATTERN_RED (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 4) +#define V4L2_CID_TEST_PATTERN_GREENR (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 5) +#define V4L2_CID_TEST_PATTERN_BLUE (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 6) +#define V4L2_CID_TEST_PATTERN_GREENB (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 7) +#define V4L2_CID_UNIT_CELL_SIZE (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 8) +#define V4L2_CID_NOTIFY_GAINS (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 9) + + +/* Image processing controls */ + +#define V4L2_CID_IMAGE_PROC_CLASS_BASE (V4L2_CTRL_CLASS_IMAGE_PROC | 0x900) +#define V4L2_CID_IMAGE_PROC_CLASS (V4L2_CTRL_CLASS_IMAGE_PROC | 1) + +#define V4L2_CID_LINK_FREQ (V4L2_CID_IMAGE_PROC_CLASS_BASE + 1) +#define V4L2_CID_PIXEL_RATE (V4L2_CID_IMAGE_PROC_CLASS_BASE + 2) +#define V4L2_CID_TEST_PATTERN (V4L2_CID_IMAGE_PROC_CLASS_BASE + 3) +#define V4L2_CID_DEINTERLACING_MODE (V4L2_CID_IMAGE_PROC_CLASS_BASE + 4) +#define V4L2_CID_DIGITAL_GAIN (V4L2_CID_IMAGE_PROC_CLASS_BASE + 5) + +/* DV-class control IDs defined by V4L2 */ +#define V4L2_CID_DV_CLASS_BASE (V4L2_CTRL_CLASS_DV | 0x900) +#define V4L2_CID_DV_CLASS (V4L2_CTRL_CLASS_DV | 1) + +#define V4L2_CID_DV_TX_HOTPLUG (V4L2_CID_DV_CLASS_BASE + 1) +#define V4L2_CID_DV_TX_RXSENSE (V4L2_CID_DV_CLASS_BASE + 2) +#define V4L2_CID_DV_TX_EDID_PRESENT (V4L2_CID_DV_CLASS_BASE + 3) +#define V4L2_CID_DV_TX_MODE (V4L2_CID_DV_CLASS_BASE + 4) +enum v4l2_dv_tx_mode { + V4L2_DV_TX_MODE_DVI_D = 0, + V4L2_DV_TX_MODE_HDMI = 1, +}; +#define V4L2_CID_DV_TX_RGB_RANGE (V4L2_CID_DV_CLASS_BASE + 5) +enum v4l2_dv_rgb_range { + V4L2_DV_RGB_RANGE_AUTO = 0, + V4L2_DV_RGB_RANGE_LIMITED = 1, + V4L2_DV_RGB_RANGE_FULL = 2, +}; + +#define V4L2_CID_DV_TX_IT_CONTENT_TYPE (V4L2_CID_DV_CLASS_BASE + 6) +enum v4l2_dv_it_content_type { + V4L2_DV_IT_CONTENT_TYPE_GRAPHICS = 0, + V4L2_DV_IT_CONTENT_TYPE_PHOTO = 1, + V4L2_DV_IT_CONTENT_TYPE_CINEMA = 2, + V4L2_DV_IT_CONTENT_TYPE_GAME = 3, + V4L2_DV_IT_CONTENT_TYPE_NO_ITC = 4, +}; + +#define V4L2_CID_DV_RX_POWER_PRESENT (V4L2_CID_DV_CLASS_BASE + 100) +#define V4L2_CID_DV_RX_RGB_RANGE (V4L2_CID_DV_CLASS_BASE + 101) +#define V4L2_CID_DV_RX_IT_CONTENT_TYPE (V4L2_CID_DV_CLASS_BASE + 102) + +#define V4L2_CID_FM_RX_CLASS_BASE (V4L2_CTRL_CLASS_FM_RX | 0x900) +#define V4L2_CID_FM_RX_CLASS (V4L2_CTRL_CLASS_FM_RX | 1) + +#define V4L2_CID_TUNE_DEEMPHASIS (V4L2_CID_FM_RX_CLASS_BASE + 1) +enum v4l2_deemphasis { + V4L2_DEEMPHASIS_DISABLED = V4L2_PREEMPHASIS_DISABLED, + V4L2_DEEMPHASIS_50_uS = V4L2_PREEMPHASIS_50_uS, + V4L2_DEEMPHASIS_75_uS = V4L2_PREEMPHASIS_75_uS, +}; + +#define V4L2_CID_RDS_RECEPTION (V4L2_CID_FM_RX_CLASS_BASE + 2) +#define V4L2_CID_RDS_RX_PTY (V4L2_CID_FM_RX_CLASS_BASE + 3) +#define V4L2_CID_RDS_RX_PS_NAME (V4L2_CID_FM_RX_CLASS_BASE + 4) +#define V4L2_CID_RDS_RX_RADIO_TEXT (V4L2_CID_FM_RX_CLASS_BASE + 5) +#define V4L2_CID_RDS_RX_TRAFFIC_ANNOUNCEMENT (V4L2_CID_FM_RX_CLASS_BASE + 6) +#define V4L2_CID_RDS_RX_TRAFFIC_PROGRAM (V4L2_CID_FM_RX_CLASS_BASE + 7) +#define V4L2_CID_RDS_RX_MUSIC_SPEECH (V4L2_CID_FM_RX_CLASS_BASE + 8) + +#define V4L2_CID_RF_TUNER_CLASS_BASE (V4L2_CTRL_CLASS_RF_TUNER | 0x900) +#define V4L2_CID_RF_TUNER_CLASS (V4L2_CTRL_CLASS_RF_TUNER | 1) + +#define V4L2_CID_RF_TUNER_BANDWIDTH_AUTO (V4L2_CID_RF_TUNER_CLASS_BASE + 11) +#define V4L2_CID_RF_TUNER_BANDWIDTH (V4L2_CID_RF_TUNER_CLASS_BASE + 12) +#define V4L2_CID_RF_TUNER_RF_GAIN (V4L2_CID_RF_TUNER_CLASS_BASE + 32) +#define V4L2_CID_RF_TUNER_LNA_GAIN_AUTO (V4L2_CID_RF_TUNER_CLASS_BASE + 41) +#define V4L2_CID_RF_TUNER_LNA_GAIN (V4L2_CID_RF_TUNER_CLASS_BASE + 42) +#define V4L2_CID_RF_TUNER_MIXER_GAIN_AUTO (V4L2_CID_RF_TUNER_CLASS_BASE + 51) +#define V4L2_CID_RF_TUNER_MIXER_GAIN (V4L2_CID_RF_TUNER_CLASS_BASE + 52) +#define V4L2_CID_RF_TUNER_IF_GAIN_AUTO (V4L2_CID_RF_TUNER_CLASS_BASE + 61) +#define V4L2_CID_RF_TUNER_IF_GAIN (V4L2_CID_RF_TUNER_CLASS_BASE + 62) +#define V4L2_CID_RF_TUNER_PLL_LOCK (V4L2_CID_RF_TUNER_CLASS_BASE + 91) + + +/* Detection-class control IDs defined by V4L2 */ +#define V4L2_CID_DETECT_CLASS_BASE (V4L2_CTRL_CLASS_DETECT | 0x900) +#define V4L2_CID_DETECT_CLASS (V4L2_CTRL_CLASS_DETECT | 1) + +#define V4L2_CID_DETECT_MD_MODE (V4L2_CID_DETECT_CLASS_BASE + 1) +enum v4l2_detect_md_mode { + V4L2_DETECT_MD_MODE_DISABLED = 0, + V4L2_DETECT_MD_MODE_GLOBAL = 1, + V4L2_DETECT_MD_MODE_THRESHOLD_GRID = 2, + V4L2_DETECT_MD_MODE_REGION_GRID = 3, +}; +#define V4L2_CID_DETECT_MD_GLOBAL_THRESHOLD (V4L2_CID_DETECT_CLASS_BASE + 2) +#define V4L2_CID_DETECT_MD_THRESHOLD_GRID (V4L2_CID_DETECT_CLASS_BASE + 3) +#define V4L2_CID_DETECT_MD_REGION_GRID (V4L2_CID_DETECT_CLASS_BASE + 4) + + +/* Stateless CODECs controls */ +#define V4L2_CID_CODEC_STATELESS_BASE (V4L2_CTRL_CLASS_CODEC_STATELESS | 0x900) +#define V4L2_CID_CODEC_STATELESS_CLASS (V4L2_CTRL_CLASS_CODEC_STATELESS | 1) + +#define V4L2_CID_STATELESS_H264_DECODE_MODE (V4L2_CID_CODEC_STATELESS_BASE + 0) +/** + * enum v4l2_stateless_h264_decode_mode - Decoding mode + * + * @V4L2_STATELESS_H264_DECODE_MODE_SLICE_BASED: indicates that decoding + * is performed one slice at a time. In this mode, + * V4L2_CID_STATELESS_H264_SLICE_PARAMS must contain the parsed slice + * parameters and the OUTPUT buffer must contain a single slice. + * V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF feature is used + * in order to support multislice frames. + * @V4L2_STATELESS_H264_DECODE_MODE_FRAME_BASED: indicates that + * decoding is performed per frame. The OUTPUT buffer must contain + * all slices and also both fields. This mode is typically supported + * by device drivers that are able to parse the slice(s) header(s) + * in hardware. When this mode is selected, + * V4L2_CID_STATELESS_H264_SLICE_PARAMS is not used. + */ +enum v4l2_stateless_h264_decode_mode { + V4L2_STATELESS_H264_DECODE_MODE_SLICE_BASED, + V4L2_STATELESS_H264_DECODE_MODE_FRAME_BASED, +}; + +#define V4L2_CID_STATELESS_H264_START_CODE (V4L2_CID_CODEC_STATELESS_BASE + 1) +/** + * enum v4l2_stateless_h264_start_code - Start code + * + * @V4L2_STATELESS_H264_START_CODE_NONE: slices are passed + * to the driver without any start code. + * @V4L2_STATELESS_H264_START_CODE_ANNEX_B: slices are passed + * to the driver with an Annex B start code prefix + * (legal start codes can be 3-bytes 0x000001 or 4-bytes 0x00000001). + * This mode is typically supported by device drivers that parse + * the start code in hardware. + */ +enum v4l2_stateless_h264_start_code { + V4L2_STATELESS_H264_START_CODE_NONE, + V4L2_STATELESS_H264_START_CODE_ANNEX_B, +}; + +#define V4L2_H264_SPS_CONSTRAINT_SET0_FLAG 0x01 +#define V4L2_H264_SPS_CONSTRAINT_SET1_FLAG 0x02 +#define V4L2_H264_SPS_CONSTRAINT_SET2_FLAG 0x04 +#define V4L2_H264_SPS_CONSTRAINT_SET3_FLAG 0x08 +#define V4L2_H264_SPS_CONSTRAINT_SET4_FLAG 0x10 +#define V4L2_H264_SPS_CONSTRAINT_SET5_FLAG 0x20 + +#define V4L2_H264_SPS_FLAG_SEPARATE_COLOUR_PLANE 0x01 +#define V4L2_H264_SPS_FLAG_QPPRIME_Y_ZERO_TRANSFORM_BYPASS 0x02 +#define V4L2_H264_SPS_FLAG_DELTA_PIC_ORDER_ALWAYS_ZERO 0x04 +#define V4L2_H264_SPS_FLAG_GAPS_IN_FRAME_NUM_VALUE_ALLOWED 0x08 +#define V4L2_H264_SPS_FLAG_FRAME_MBS_ONLY 0x10 +#define V4L2_H264_SPS_FLAG_MB_ADAPTIVE_FRAME_FIELD 0x20 +#define V4L2_H264_SPS_FLAG_DIRECT_8X8_INFERENCE 0x40 + +#define V4L2_H264_SPS_HAS_CHROMA_FORMAT(sps) \ + ((sps)->profile_idc == 100 || (sps)->profile_idc == 110 || \ + (sps)->profile_idc == 122 || (sps)->profile_idc == 244 || \ + (sps)->profile_idc == 44 || (sps)->profile_idc == 83 || \ + (sps)->profile_idc == 86 || (sps)->profile_idc == 118 || \ + (sps)->profile_idc == 128 || (sps)->profile_idc == 138 || \ + (sps)->profile_idc == 139 || (sps)->profile_idc == 134 || \ + (sps)->profile_idc == 135) + +#define V4L2_CID_STATELESS_H264_SPS (V4L2_CID_CODEC_STATELESS_BASE + 2) +/** + * struct v4l2_ctrl_h264_sps - H264 sequence parameter set + * + * All the members on this sequence parameter set structure match the + * sequence parameter set syntax as specified by the H264 specification. + * + * @profile_idc: see H264 specification. + * @constraint_set_flags: see H264 specification. + * @level_idc: see H264 specification. + * @seq_parameter_set_id: see H264 specification. + * @chroma_format_idc: see H264 specification. + * @bit_depth_luma_minus8: see H264 specification. + * @bit_depth_chroma_minus8: see H264 specification. + * @log2_max_frame_num_minus4: see H264 specification. + * @pic_order_cnt_type: see H264 specification. + * @log2_max_pic_order_cnt_lsb_minus4: see H264 specification. + * @max_num_ref_frames: see H264 specification. + * @num_ref_frames_in_pic_order_cnt_cycle: see H264 specification. + * @offset_for_ref_frame: see H264 specification. + * @offset_for_non_ref_pic: see H264 specification. + * @offset_for_top_to_bottom_field: see H264 specification. + * @pic_width_in_mbs_minus1: see H264 specification. + * @pic_height_in_map_units_minus1: see H264 specification. + * @flags: see V4L2_H264_SPS_FLAG_{}. + */ +struct v4l2_ctrl_h264_sps { + u_int8_t profile_idc; + u_int8_t constraint_set_flags; + u_int8_t level_idc; + u_int8_t seq_parameter_set_id; + u_int8_t chroma_format_idc; + u_int8_t bit_depth_luma_minus8; + u_int8_t bit_depth_chroma_minus8; + u_int8_t log2_max_frame_num_minus4; + u_int8_t pic_order_cnt_type; + u_int8_t log2_max_pic_order_cnt_lsb_minus4; + u_int8_t max_num_ref_frames; + u_int8_t num_ref_frames_in_pic_order_cnt_cycle; + int32_t offset_for_ref_frame[255]; + int32_t offset_for_non_ref_pic; + int32_t offset_for_top_to_bottom_field; + u_int16_t pic_width_in_mbs_minus1; + u_int16_t pic_height_in_map_units_minus1; + u_int32_t flags; +}; + +#define V4L2_H264_PPS_FLAG_ENTROPY_CODING_MODE 0x0001 +#define V4L2_H264_PPS_FLAG_BOTTOM_FIELD_PIC_ORDER_IN_FRAME_PRESENT 0x0002 +#define V4L2_H264_PPS_FLAG_WEIGHTED_PRED 0x0004 +#define V4L2_H264_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT 0x0008 +#define V4L2_H264_PPS_FLAG_CONSTRAINED_INTRA_PRED 0x0010 +#define V4L2_H264_PPS_FLAG_REDUNDANT_PIC_CNT_PRESENT 0x0020 +#define V4L2_H264_PPS_FLAG_TRANSFORM_8X8_MODE 0x0040 +#define V4L2_H264_PPS_FLAG_SCALING_MATRIX_PRESENT 0x0080 + +#define V4L2_CID_STATELESS_H264_PPS (V4L2_CID_CODEC_STATELESS_BASE + 3) +/** + * struct v4l2_ctrl_h264_pps - H264 picture parameter set + * + * Except where noted, all the members on this picture parameter set + * structure match the picture parameter set syntax as specified + * by the H264 specification. + * + * In particular, V4L2_H264_PPS_FLAG_SCALING_MATRIX_PRESENT flag + * has a specific meaning. This flag should be set if a non-flat + * scaling matrix applies to the picture. In this case, applications + * are expected to use V4L2_CID_STATELESS_H264_SCALING_MATRIX, + * to pass the values of the non-flat matrices. + * + * @pic_parameter_set_id: see H264 specification. + * @seq_parameter_set_id: see H264 specification. + * @num_slice_groups_minus1: see H264 specification. + * @num_ref_idx_l0_default_active_minus1: see H264 specification. + * @num_ref_idx_l1_default_active_minus1: see H264 specification. + * @weighted_bipred_idc: see H264 specification. + * @pic_init_qp_minus26: see H264 specification. + * @pic_init_qs_minus26: see H264 specification. + * @chroma_qp_index_offset: see H264 specification. + * @second_chroma_qp_index_offset: see H264 specification. + * @flags: see V4L2_H264_PPS_FLAG_{}. + */ +struct v4l2_ctrl_h264_pps { + u_int8_t pic_parameter_set_id; + u_int8_t seq_parameter_set_id; + u_int8_t num_slice_groups_minus1; + u_int8_t num_ref_idx_l0_default_active_minus1; + u_int8_t num_ref_idx_l1_default_active_minus1; + u_int8_t weighted_bipred_idc; + int8_t pic_init_qp_minus26; + int8_t pic_init_qs_minus26; + int8_t chroma_qp_index_offset; + int8_t second_chroma_qp_index_offset; + u_int16_t flags; +}; + +#define V4L2_CID_STATELESS_H264_SCALING_MATRIX (V4L2_CID_CODEC_STATELESS_BASE + 4) +/** + * struct v4l2_ctrl_h264_scaling_matrix - H264 scaling matrices + * + * @scaling_list_4x4: scaling matrix after applying the inverse + * scanning process. Expected list order is Intra Y, Intra Cb, + * Intra Cr, Inter Y, Inter Cb, Inter Cr. The values on each + * scaling list are expected in raster scan order. + * @scaling_list_8x8: scaling matrix after applying the inverse + * scanning process. Expected list order is Intra Y, Inter Y, + * Intra Cb, Inter Cb, Intra Cr, Inter Cr. The values on each + * scaling list are expected in raster scan order. + * + * Note that the list order is different for the 4x4 and 8x8 + * matrices as per the H264 specification, see table 7-2 "Assignment + * of mnemonic names to scaling list indices and specification of + * fall-back rule". + */ +struct v4l2_ctrl_h264_scaling_matrix { + u_int8_t scaling_list_4x4[6][16]; + u_int8_t scaling_list_8x8[6][64]; +}; + +struct v4l2_h264_weight_factors { + int16_t luma_weight[32]; + int16_t luma_offset[32]; + int16_t chroma_weight[32][2]; + int16_t chroma_offset[32][2]; +}; + +#define V4L2_H264_CTRL_PRED_WEIGHTS_REQUIRED(pps, slice) \ + ((((pps)->flags & V4L2_H264_PPS_FLAG_WEIGHTED_PRED) && \ + ((slice)->slice_type == V4L2_H264_SLICE_TYPE_P || \ + (slice)->slice_type == V4L2_H264_SLICE_TYPE_SP)) || \ + ((pps)->weighted_bipred_idc == 1 && \ + (slice)->slice_type == V4L2_H264_SLICE_TYPE_B)) + +#define V4L2_CID_STATELESS_H264_PRED_WEIGHTS (V4L2_CID_CODEC_STATELESS_BASE + 5) +/** + * struct v4l2_ctrl_h264_pred_weights - Prediction weight table + * + * Prediction weight table, which matches the syntax specified + * by the H264 specification. + * + * @luma_log2_weight_denom: see H264 specification. + * @chroma_log2_weight_denom: see H264 specification. + * @weight_factors: luma and chroma weight factors. + */ +struct v4l2_ctrl_h264_pred_weights { + u_int16_t luma_log2_weight_denom; + u_int16_t chroma_log2_weight_denom; + struct v4l2_h264_weight_factors weight_factors[2]; +}; + +#define V4L2_H264_SLICE_TYPE_P 0 +#define V4L2_H264_SLICE_TYPE_B 1 +#define V4L2_H264_SLICE_TYPE_I 2 +#define V4L2_H264_SLICE_TYPE_SP 3 +#define V4L2_H264_SLICE_TYPE_SI 4 + +#define V4L2_H264_SLICE_FLAG_DIRECT_SPATIAL_MV_PRED 0x01 +#define V4L2_H264_SLICE_FLAG_SP_FOR_SWITCH 0x02 + +#define V4L2_H264_TOP_FIELD_REF 0x1 +#define V4L2_H264_BOTTOM_FIELD_REF 0x2 +#define V4L2_H264_FRAME_REF 0x3 + +/** + * struct v4l2_h264_reference - H264 picture reference + * + * @fields: indicates how the picture is referenced. + * Valid values are V4L2_H264_{}_REF. + * @index: index into v4l2_ctrl_h264_decode_params.dpb[]. + */ +struct v4l2_h264_reference { + u_int8_t fields; + u_int8_t index; +}; + +/* + * Maximum DPB size, as specified by section 'A.3.1 Level limits + * common to the Baseline, Main, and Extended profiles'. + */ +#define V4L2_H264_NUM_DPB_ENTRIES 16 +#define V4L2_H264_REF_LIST_LEN (2 * V4L2_H264_NUM_DPB_ENTRIES) + +#define V4L2_CID_STATELESS_H264_SLICE_PARAMS (V4L2_CID_CODEC_STATELESS_BASE + 6) +/** + * struct v4l2_ctrl_h264_slice_params - H264 slice parameters + * + * This structure holds the H264 syntax elements that are specified + * as non-invariant for the slices in a given frame. + * + * Slice invariant syntax elements are contained in struct + * v4l2_ctrl_h264_decode_params. This is done to reduce the API surface + * on frame-based decoders, where slice header parsing is done by the + * hardware. + * + * Slice invariant syntax elements are specified in specification section + * "7.4.3 Slice header semantics". + * + * Except where noted, the members on this struct match the slice header syntax. + * + * @header_bit_size: offset in bits to slice_data() from the beginning of this slice. + * @first_mb_in_slice: see H264 specification. + * @slice_type: see H264 specification. + * @colour_plane_id: see H264 specification. + * @redundant_pic_cnt: see H264 specification. + * @cabac_init_idc: see H264 specification. + * @slice_qp_delta: see H264 specification. + * @slice_qs_delta: see H264 specification. + * @disable_deblocking_filter_idc: see H264 specification. + * @slice_alpha_c0_offset_div2: see H264 specification. + * @slice_beta_offset_div2: see H264 specification. + * @num_ref_idx_l0_active_minus1: see H264 specification. + * @num_ref_idx_l1_active_minus1: see H264 specification. + * @reserved: padding field. Should be zeroed by applications. + * @ref_pic_list0: reference picture list 0 after applying the per-slice modifications. + * @ref_pic_list1: reference picture list 1 after applying the per-slice modifications. + * @flags: see V4L2_H264_SLICE_FLAG_{}. + */ +struct v4l2_ctrl_h264_slice_params { + u_int32_t header_bit_size; + u_int32_t first_mb_in_slice; + u_int8_t slice_type; + u_int8_t colour_plane_id; + u_int8_t redundant_pic_cnt; + u_int8_t cabac_init_idc; + int8_t slice_qp_delta; + int8_t slice_qs_delta; + u_int8_t disable_deblocking_filter_idc; + int8_t slice_alpha_c0_offset_div2; + int8_t slice_beta_offset_div2; + u_int8_t num_ref_idx_l0_active_minus1; + u_int8_t num_ref_idx_l1_active_minus1; + + u_int8_t reserved; + + struct v4l2_h264_reference ref_pic_list0[V4L2_H264_REF_LIST_LEN]; + struct v4l2_h264_reference ref_pic_list1[V4L2_H264_REF_LIST_LEN]; + + u_int32_t flags; +}; + +#define V4L2_H264_DPB_ENTRY_FLAG_VALID 0x01 +#define V4L2_H264_DPB_ENTRY_FLAG_ACTIVE 0x02 +#define V4L2_H264_DPB_ENTRY_FLAG_LONG_TERM 0x04 +#define V4L2_H264_DPB_ENTRY_FLAG_FIELD 0x08 + +/** + * struct v4l2_h264_dpb_entry - H264 decoded picture buffer entry + * + * @reference_ts: timestamp of the V4L2 capture buffer to use as reference. + * The timestamp refers to the timestamp field in struct v4l2_buffer. + * Use v4l2_timeval_to_ns() to convert the struct timeval to a u_int64_t. + * @pic_num: matches PicNum variable assigned during the reference + * picture lists construction process. + * @frame_num: frame identifier which matches frame_num syntax element. + * @fields: indicates how the DPB entry is referenced. Valid values are + * V4L2_H264_{}_REF. + * @reserved: padding field. Should be zeroed by applications. + * @top_field_order_cnt: matches TopFieldOrderCnt picture value. + * @bottom_field_order_cnt: matches BottomFieldOrderCnt picture value. + * Note that picture field is indicated by v4l2_buffer.field. + * @flags: see V4L2_H264_DPB_ENTRY_FLAG_{}. + */ +struct v4l2_h264_dpb_entry { + u_int64_t reference_ts; + u_int32_t pic_num; + u_int16_t frame_num; + u_int8_t fields; + u_int8_t reserved[5]; + int32_t top_field_order_cnt; + int32_t bottom_field_order_cnt; + u_int32_t flags; +}; + +#define V4L2_H264_DECODE_PARAM_FLAG_IDR_PIC 0x01 +#define V4L2_H264_DECODE_PARAM_FLAG_FIELD_PIC 0x02 +#define V4L2_H264_DECODE_PARAM_FLAG_BOTTOM_FIELD 0x04 +#define V4L2_H264_DECODE_PARAM_FLAG_PFRAME 0x08 +#define V4L2_H264_DECODE_PARAM_FLAG_BFRAME 0x10 + +#define V4L2_CID_STATELESS_H264_DECODE_PARAMS (V4L2_CID_CODEC_STATELESS_BASE + 7) +/** + * struct v4l2_ctrl_h264_decode_params - H264 decoding parameters + * + * @dpb: decoded picture buffer. + * @nal_ref_idc: slice header syntax element. + * @frame_num: slice header syntax element. + * @top_field_order_cnt: matches TopFieldOrderCnt picture value. + * @bottom_field_order_cnt: matches BottomFieldOrderCnt picture value. + * Note that picture field is indicated by v4l2_buffer.field. + * @idr_pic_id: slice header syntax element. + * @pic_order_cnt_lsb: slice header syntax element. + * @delta_pic_order_cnt_bottom: slice header syntax element. + * @delta_pic_order_cnt0: slice header syntax element. + * @delta_pic_order_cnt1: slice header syntax element. + * @dec_ref_pic_marking_bit_size: size in bits of dec_ref_pic_marking() + * syntax element. + * @pic_order_cnt_bit_size: size in bits of pic order count syntax. + * @slice_group_change_cycle: slice header syntax element. + * @reserved: padding field. Should be zeroed by applications. + * @flags: see V4L2_H264_DECODE_PARAM_FLAG_{}. + */ +struct v4l2_ctrl_h264_decode_params { + struct v4l2_h264_dpb_entry dpb[V4L2_H264_NUM_DPB_ENTRIES]; + u_int16_t nal_ref_idc; + u_int16_t frame_num; + int32_t top_field_order_cnt; + int32_t bottom_field_order_cnt; + u_int16_t idr_pic_id; + u_int16_t pic_order_cnt_lsb; + int32_t delta_pic_order_cnt_bottom; + int32_t delta_pic_order_cnt0; + int32_t delta_pic_order_cnt1; + u_int32_t dec_ref_pic_marking_bit_size; + u_int32_t pic_order_cnt_bit_size; + u_int32_t slice_group_change_cycle; + + u_int32_t reserved; + u_int32_t flags; +}; + + +/* Stateless FWHT control, used by the vicodec driver */ + +/* Current FWHT version */ +#define V4L2_FWHT_VERSION 3 + +/* Set if this is an interlaced format */ +#define V4L2_FWHT_FL_IS_INTERLACED _BITUL(0) +/* Set if this is a bottom-first (NTSC) interlaced format */ +#define V4L2_FWHT_FL_IS_BOTTOM_FIRST _BITUL(1) +/* Set if each 'frame' contains just one field */ +#define V4L2_FWHT_FL_IS_ALTERNATE _BITUL(2) +/* + * If V4L2_FWHT_FL_IS_ALTERNATE was set, then this is set if this + * 'frame' is the bottom field, else it is the top field. + */ +#define V4L2_FWHT_FL_IS_BOTTOM_FIELD _BITUL(3) +/* Set if the Y' plane is uncompressed */ +#define V4L2_FWHT_FL_LUMA_IS_UNCOMPRESSED _BITUL(4) +/* Set if the Cb plane is uncompressed */ +#define V4L2_FWHT_FL_CB_IS_UNCOMPRESSED _BITUL(5) +/* Set if the Cr plane is uncompressed */ +#define V4L2_FWHT_FL_CR_IS_UNCOMPRESSED _BITUL(6) +/* Set if the chroma plane is full height, if cleared it is half height */ +#define V4L2_FWHT_FL_CHROMA_FULL_HEIGHT _BITUL(7) +/* Set if the chroma plane is full width, if cleared it is half width */ +#define V4L2_FWHT_FL_CHROMA_FULL_WIDTH _BITUL(8) +/* Set if the alpha plane is uncompressed */ +#define V4L2_FWHT_FL_ALPHA_IS_UNCOMPRESSED _BITUL(9) +/* Set if this is an I Frame */ +#define V4L2_FWHT_FL_I_FRAME _BITUL(10) + +/* A 4-values flag - the number of components - 1 */ +#define V4L2_FWHT_FL_COMPONENTS_NUM_MSK GENMASK(18, 16) +#define V4L2_FWHT_FL_COMPONENTS_NUM_OFFSET 16 + +/* A 4-values flag - the pixel encoding type */ +#define V4L2_FWHT_FL_PIXENC_MSK GENMASK(20, 19) +#define V4L2_FWHT_FL_PIXENC_OFFSET 19 +#define V4L2_FWHT_FL_PIXENC_YUV (1 << V4L2_FWHT_FL_PIXENC_OFFSET) +#define V4L2_FWHT_FL_PIXENC_RGB (2 << V4L2_FWHT_FL_PIXENC_OFFSET) +#define V4L2_FWHT_FL_PIXENC_HSV (3 << V4L2_FWHT_FL_PIXENC_OFFSET) + +#define V4L2_CID_STATELESS_FWHT_PARAMS (V4L2_CID_CODEC_STATELESS_BASE + 100) +/** + * struct v4l2_ctrl_fwht_params - FWHT parameters + * + * @backward_ref_ts: timestamp of the V4L2 capture buffer to use as reference. + * The timestamp refers to the timestamp field in struct v4l2_buffer. + * Use v4l2_timeval_to_ns() to convert the struct timeval to a u_int64_t. + * @version: must be V4L2_FWHT_VERSION. + * @width: width of frame. + * @height: height of frame. + * @flags: FWHT flags (see V4L2_FWHT_FL_*). + * @colorspace: the colorspace (enum v4l2_colorspace). + * @xfer_func: the transfer function (enum v4l2_xfer_func). + * @ycbcr_enc: the Y'CbCr encoding (enum v4l2_ycbcr_encoding). + * @quantization: the quantization (enum v4l2_quantization). + */ +struct v4l2_ctrl_fwht_params { + u_int64_t backward_ref_ts; + u_int32_t version; + u_int32_t width; + u_int32_t height; + u_int32_t flags; + u_int32_t colorspace; + u_int32_t xfer_func; + u_int32_t ycbcr_enc; + u_int32_t quantization; +}; + +/* Stateless VP8 control */ + +#define V4L2_VP8_SEGMENT_FLAG_ENABLED 0x01 +#define V4L2_VP8_SEGMENT_FLAG_UPDATE_MAP 0x02 +#define V4L2_VP8_SEGMENT_FLAG_UPDATE_FEATURE_DATA 0x04 +#define V4L2_VP8_SEGMENT_FLAG_DELTA_VALUE_MODE 0x08 + +/** + * struct v4l2_vp8_segment - VP8 segment-based adjustments parameters + * + * @quant_update: update values for the segment quantizer. + * @lf_update: update values for the loop filter level. + * @segment_probs: branch probabilities of the segment_id decoding tree. + * @padding: padding field. Should be zeroed by applications. + * @flags: see V4L2_VP8_SEGMENT_FLAG_{}. + * + * This structure contains segment-based adjustments related parameters. + * See the 'update_segmentation()' part of the frame header syntax, + * and section '9.3. Segment-Based Adjustments' of the VP8 specification + * for more details. + */ +struct v4l2_vp8_segment { + int8_t quant_update[4]; + int8_t lf_update[4]; + u_int8_t segment_probs[3]; + u_int8_t padding; + u_int32_t flags; +}; + +#define V4L2_VP8_LF_ADJ_ENABLE 0x01 +#define V4L2_VP8_LF_DELTA_UPDATE 0x02 +#define V4L2_VP8_LF_FILTER_TYPE_SIMPLE 0x04 + +/** + * struct v4l2_vp8_loop_filter - VP8 loop filter parameters + * + * @ref_frm_delta: Reference frame signed delta values. + * @mb_mode_delta: MB prediction mode signed delta values. + * @sharpness_level: matches sharpness_level syntax element. + * @level: matches loop_filter_level syntax element. + * @padding: padding field. Should be zeroed by applications. + * @flags: see V4L2_VP8_LF_{}. + * + * This structure contains loop filter related parameters. + * See the 'mb_lf_adjustments()' part of the frame header syntax, + * and section '9.4. Loop Filter Type and Levels' of the VP8 specification + * for more details. + */ +struct v4l2_vp8_loop_filter { + int8_t ref_frm_delta[4]; + int8_t mb_mode_delta[4]; + u_int8_t sharpness_level; + u_int8_t level; + u_int16_t padding; + u_int32_t flags; +}; + +/** + * struct v4l2_vp8_quantization - VP8 quantizattion indices + * + * @y_ac_qi: luma AC coefficient table index. + * @y_dc_delta: luma DC delta vaue. + * @y2_dc_delta: y2 block DC delta value. + * @y2_ac_delta: y2 block AC delta value. + * @uv_dc_delta: chroma DC delta value. + * @uv_ac_delta: chroma AC delta value. + * @padding: padding field. Should be zeroed by applications. + * + * This structure contains the quantization indices present + * in 'quant_indices()' part of the frame header syntax. + * See section '9.6. Dequantization Indices' of the VP8 specification + * for more details. + */ +struct v4l2_vp8_quantization { + u_int8_t y_ac_qi; + int8_t y_dc_delta; + int8_t y2_dc_delta; + int8_t y2_ac_delta; + int8_t uv_dc_delta; + int8_t uv_ac_delta; + u_int16_t padding; +}; + +#define V4L2_VP8_COEFF_PROB_CNT 11 +#define V4L2_VP8_MV_PROB_CNT 19 + +/** + * struct v4l2_vp8_entropy - VP8 update probabilities + * + * @coeff_probs: coefficient probability update values. + * @y_mode_probs: luma intra-prediction probabilities. + * @uv_mode_probs: chroma intra-prediction probabilities. + * @mv_probs: mv decoding probability. + * @padding: padding field. Should be zeroed by applications. + * + * This structure contains the update probabilities present in + * 'token_prob_update()' and 'mv_prob_update()' part of the frame header. + * See section '17.2. Probability Updates' of the VP8 specification + * for more details. + */ +struct v4l2_vp8_entropy { + u_int8_t coeff_probs[4][8][3][V4L2_VP8_COEFF_PROB_CNT]; + u_int8_t y_mode_probs[4]; + u_int8_t uv_mode_probs[3]; + u_int8_t mv_probs[2][V4L2_VP8_MV_PROB_CNT]; + u_int8_t padding[3]; +}; + +/** + * struct v4l2_vp8_entropy_coder_state - VP8 boolean coder state + * + * @range: coder state value for "Range" + * @value: coder state value for "Value" + * @bit_count: number of bits left in range "Value". + * @padding: padding field. Should be zeroed by applications. + * + * This structure contains the state for the boolean coder, as + * explained in section '7. Boolean Entropy Decoder' of the VP8 specification. + */ +struct v4l2_vp8_entropy_coder_state { + u_int8_t range; + u_int8_t value; + u_int8_t bit_count; + u_int8_t padding; +}; + +#define V4L2_VP8_FRAME_FLAG_KEY_FRAME 0x01 +#define V4L2_VP8_FRAME_FLAG_EXPERIMENTAL 0x02 +#define V4L2_VP8_FRAME_FLAG_SHOW_FRAME 0x04 +#define V4L2_VP8_FRAME_FLAG_MB_NO_SKIP_COEFF 0x08 +#define V4L2_VP8_FRAME_FLAG_SIGN_BIAS_GOLDEN 0x10 +#define V4L2_VP8_FRAME_FLAG_SIGN_BIAS_ALT 0x20 + +#define V4L2_VP8_FRAME_IS_KEY_FRAME(hdr) \ + (!!((hdr)->flags & V4L2_VP8_FRAME_FLAG_KEY_FRAME)) + +#define V4L2_CID_STATELESS_VP8_FRAME (V4L2_CID_CODEC_STATELESS_BASE + 200) +/** + * struct v4l2_ctrl_vp8_frame - VP8 frame parameters + * + * @segment: segmentation parameters. See &v4l2_vp8_segment for more details + * @lf: loop filter parameters. See &v4l2_vp8_loop_filter for more details + * @quant: quantization parameters. See &v4l2_vp8_quantization for more details + * @entropy: update probabilities. See &v4l2_vp8_entropy for more details + * @coder_state: boolean coder state. See &v4l2_vp8_entropy_coder_state for more details + * @width: frame width. + * @height: frame height. + * @horizontal_scale: horizontal scaling factor. + * @vertical_scale: vertical scaling factor. + * @version: bitstream version. + * @prob_skip_false: frame header syntax element. + * @prob_intra: frame header syntax element. + * @prob_last: frame header syntax element. + * @prob_gf: frame header syntax element. + * @num_dct_parts: number of DCT coefficients partitions. + * @first_part_size: size of the first partition, i.e. the control partition. + * @first_part_header_bits: size in bits of the first partition header portion. + * @dct_part_sizes: DCT coefficients sizes. + * @last_frame_ts: "last" reference buffer timestamp. + * The timestamp refers to the timestamp field in struct v4l2_buffer. + * Use v4l2_timeval_to_ns() to convert the struct timeval to a u_int64_t. + * @golden_frame_ts: "golden" reference buffer timestamp. + * @alt_frame_ts: "alt" reference buffer timestamp. + * @flags: see V4L2_VP8_FRAME_FLAG_{}. + */ +struct v4l2_ctrl_vp8_frame { + struct v4l2_vp8_segment segment; + struct v4l2_vp8_loop_filter lf; + struct v4l2_vp8_quantization quant; + struct v4l2_vp8_entropy entropy; + struct v4l2_vp8_entropy_coder_state coder_state; + + u_int16_t width; + u_int16_t height; + + u_int8_t horizontal_scale; + u_int8_t vertical_scale; + + u_int8_t version; + u_int8_t prob_skip_false; + u_int8_t prob_intra; + u_int8_t prob_last; + u_int8_t prob_gf; + u_int8_t num_dct_parts; + + u_int32_t first_part_size; + u_int32_t first_part_header_bits; + u_int32_t dct_part_sizes[8]; + + u_int64_t last_frame_ts; + u_int64_t golden_frame_ts; + u_int64_t alt_frame_ts; + + u_int64_t flags; +}; + +/* Stateless MPEG-2 controls */ + +#define V4L2_MPEG2_SEQ_FLAG_PROGRESSIVE 0x01 + +#define V4L2_CID_STATELESS_MPEG2_SEQUENCE (V4L2_CID_CODEC_STATELESS_BASE+220) +/** + * struct v4l2_ctrl_mpeg2_sequence - MPEG-2 sequence header + * + * All the members on this structure match the sequence header and sequence + * extension syntaxes as specified by the MPEG-2 specification. + * + * Fields horizontal_size, vertical_size and vbv_buffer_size are a + * combination of respective _value and extension syntax elements, + * as described in section 6.3.3 "Sequence header". + * + * @horizontal_size: combination of elements horizontal_size_value and + * horizontal_size_extension. + * @vertical_size: combination of elements vertical_size_value and + * vertical_size_extension. + * @vbv_buffer_size: combination of elements vbv_buffer_size_value and + * vbv_buffer_size_extension. + * @profile_and_level_indication: see MPEG-2 specification. + * @chroma_format: see MPEG-2 specification. + * @flags: see V4L2_MPEG2_SEQ_FLAG_{}. + */ +struct v4l2_ctrl_mpeg2_sequence { + u_int16_t horizontal_size; + u_int16_t vertical_size; + u_int32_t vbv_buffer_size; + u_int16_t profile_and_level_indication; + u_int8_t chroma_format; + u_int8_t flags; +}; + +#define V4L2_MPEG2_PIC_CODING_TYPE_I 1 +#define V4L2_MPEG2_PIC_CODING_TYPE_P 2 +#define V4L2_MPEG2_PIC_CODING_TYPE_B 3 +#define V4L2_MPEG2_PIC_CODING_TYPE_D 4 + +#define V4L2_MPEG2_PIC_TOP_FIELD 0x1 +#define V4L2_MPEG2_PIC_BOTTOM_FIELD 0x2 +#define V4L2_MPEG2_PIC_FRAME 0x3 + +#define V4L2_MPEG2_PIC_FLAG_TOP_FIELD_FIRST 0x0001 +#define V4L2_MPEG2_PIC_FLAG_FRAME_PRED_DCT 0x0002 +#define V4L2_MPEG2_PIC_FLAG_CONCEALMENT_MV 0x0004 +#define V4L2_MPEG2_PIC_FLAG_Q_SCALE_TYPE 0x0008 +#define V4L2_MPEG2_PIC_FLAG_INTRA_VLC 0x0010 +#define V4L2_MPEG2_PIC_FLAG_ALT_SCAN 0x0020 +#define V4L2_MPEG2_PIC_FLAG_REPEAT_FIRST 0x0040 +#define V4L2_MPEG2_PIC_FLAG_PROGRESSIVE 0x0080 + +#define V4L2_CID_STATELESS_MPEG2_PICTURE (V4L2_CID_CODEC_STATELESS_BASE+221) +/** + * struct v4l2_ctrl_mpeg2_picture - MPEG-2 picture header + * + * All the members on this structure match the picture header and picture + * coding extension syntaxes as specified by the MPEG-2 specification. + * + * @backward_ref_ts: timestamp of the V4L2 capture buffer to use as + * reference for backward prediction. + * @forward_ref_ts: timestamp of the V4L2 capture buffer to use as + * reference for forward prediction. These timestamp refers to the + * timestamp field in struct v4l2_buffer. Use v4l2_timeval_to_ns() + * to convert the struct timeval to a u_int64_t. + * @flags: see V4L2_MPEG2_PIC_FLAG_{}. + * @f_code: see MPEG-2 specification. + * @picture_coding_type: see MPEG-2 specification. + * @picture_structure: see V4L2_MPEG2_PIC_{}_FIELD. + * @intra_dc_precision: see MPEG-2 specification. + * @reserved: padding field. Should be zeroed by applications. + */ +struct v4l2_ctrl_mpeg2_picture { + u_int64_t backward_ref_ts; + u_int64_t forward_ref_ts; + u_int32_t flags; + u_int8_t f_code[2][2]; + u_int8_t picture_coding_type; + u_int8_t picture_structure; + u_int8_t intra_dc_precision; + u_int8_t reserved[5]; +}; + +#define V4L2_CID_STATELESS_MPEG2_QUANTISATION (V4L2_CID_CODEC_STATELESS_BASE+222) +/** + * struct v4l2_ctrl_mpeg2_quantisation - MPEG-2 quantisation + * + * Quantisation matrices as specified by section 6.3.7 + * "Quant matrix extension". + * + * @intra_quantiser_matrix: The quantisation matrix coefficients + * for intra-coded frames, in zigzag scanning order. It is relevant + * for both luma and chroma components, although it can be superseded + * by the chroma-specific matrix for non-4:2:0 YUV formats. + * @non_intra_quantiser_matrix: The quantisation matrix coefficients + * for non-intra-coded frames, in zigzag scanning order. It is relevant + * for both luma and chroma components, although it can be superseded + * by the chroma-specific matrix for non-4:2:0 YUV formats. + * @chroma_intra_quantiser_matrix: The quantisation matrix coefficients + * for the chominance component of intra-coded frames, in zigzag scanning + * order. Only relevant for 4:2:2 and 4:4:4 YUV formats. + * @chroma_non_intra_quantiser_matrix: The quantisation matrix coefficients + * for the chrominance component of non-intra-coded frames, in zigzag scanning + * order. Only relevant for 4:2:2 and 4:4:4 YUV formats. + */ +struct v4l2_ctrl_mpeg2_quantisation { + u_int8_t intra_quantiser_matrix[64]; + u_int8_t non_intra_quantiser_matrix[64]; + u_int8_t chroma_intra_quantiser_matrix[64]; + u_int8_t chroma_non_intra_quantiser_matrix[64]; +}; + +#define V4L2_CID_STATELESS_HEVC_SPS (V4L2_CID_CODEC_STATELESS_BASE + 400) +#define V4L2_CID_STATELESS_HEVC_PPS (V4L2_CID_CODEC_STATELESS_BASE + 401) +#define V4L2_CID_STATELESS_HEVC_SLICE_PARAMS (V4L2_CID_CODEC_STATELESS_BASE + 402) +#define V4L2_CID_STATELESS_HEVC_SCALING_MATRIX (V4L2_CID_CODEC_STATELESS_BASE + 403) +#define V4L2_CID_STATELESS_HEVC_DECODE_PARAMS (V4L2_CID_CODEC_STATELESS_BASE + 404) +#define V4L2_CID_STATELESS_HEVC_DECODE_MODE (V4L2_CID_CODEC_STATELESS_BASE + 405) +#define V4L2_CID_STATELESS_HEVC_START_CODE (V4L2_CID_CODEC_STATELESS_BASE + 406) +#define V4L2_CID_STATELESS_HEVC_ENTRY_POINT_OFFSETS (V4L2_CID_CODEC_STATELESS_BASE + 407) + +enum v4l2_stateless_hevc_decode_mode { + V4L2_STATELESS_HEVC_DECODE_MODE_SLICE_BASED, + V4L2_STATELESS_HEVC_DECODE_MODE_FRAME_BASED, +}; + +enum v4l2_stateless_hevc_start_code { + V4L2_STATELESS_HEVC_START_CODE_NONE, + V4L2_STATELESS_HEVC_START_CODE_ANNEX_B, +}; + +#define V4L2_HEVC_SLICE_TYPE_B 0 +#define V4L2_HEVC_SLICE_TYPE_P 1 +#define V4L2_HEVC_SLICE_TYPE_I 2 + +#define V4L2_HEVC_SPS_FLAG_SEPARATE_COLOUR_PLANE (1ULL << 0) +#define V4L2_HEVC_SPS_FLAG_SCALING_LIST_ENABLED (1ULL << 1) +#define V4L2_HEVC_SPS_FLAG_AMP_ENABLED (1ULL << 2) +#define V4L2_HEVC_SPS_FLAG_SAMPLE_ADAPTIVE_OFFSET (1ULL << 3) +#define V4L2_HEVC_SPS_FLAG_PCM_ENABLED (1ULL << 4) +#define V4L2_HEVC_SPS_FLAG_PCM_LOOP_FILTER_DISABLED (1ULL << 5) +#define V4L2_HEVC_SPS_FLAG_LONG_TERM_REF_PICS_PRESENT (1ULL << 6) +#define V4L2_HEVC_SPS_FLAG_SPS_TEMPORAL_MVP_ENABLED (1ULL << 7) +#define V4L2_HEVC_SPS_FLAG_STRONG_INTRA_SMOOTHING_ENABLED (1ULL << 8) + +/** + * struct v4l2_ctrl_hevc_sps - ITU-T Rec. H.265: Sequence parameter set + * + * @video_parameter_set_id: specifies the value of the + * vps_video_parameter_set_id of the active VPS + * @seq_parameter_set_id: provides an identifier for the SPS for + * reference by other syntax elements + * @pic_width_in_luma_samples: specifies the width of each decoded picture + * in units of luma samples + * @pic_height_in_luma_samples: specifies the height of each decoded picture + * in units of luma samples + * @bit_depth_luma_minus8: this value plus 8specifies the bit depth of the + * samples of the luma array + * @bit_depth_chroma_minus8: this value plus 8 specifies the bit depth of the + * samples of the chroma arrays + * @log2_max_pic_order_cnt_lsb_minus4: this value plus 4 specifies the value of + * the variable MaxPicOrderCntLsb + * @sps_max_dec_pic_buffering_minus1: this value plus 1 specifies the maximum + * required size of the decoded picture + * buffer for the codec video sequence + * @sps_max_num_reorder_pics: indicates the maximum allowed number of pictures + * @sps_max_latency_increase_plus1: not equal to 0 is used to compute the + * value of SpsMaxLatencyPictures array + * @log2_min_luma_coding_block_size_minus3: plus 3 specifies the minimum + * luma coding block size + * @log2_diff_max_min_luma_coding_block_size: specifies the difference between + * the maximum and minimum luma + * coding block size + * @log2_min_luma_transform_block_size_minus2: plus 2 specifies the minimum luma + * transform block size + * @log2_diff_max_min_luma_transform_block_size: specifies the difference between + * the maximum and minimum luma + * transform block size + * @max_transform_hierarchy_depth_inter: specifies the maximum hierarchy + * depth for transform units of + * coding units coded in inter + * prediction mode + * @max_transform_hierarchy_depth_intra: specifies the maximum hierarchy + * depth for transform units of + * coding units coded in intra + * prediction mode + * @pcm_sample_bit_depth_luma_minus1: this value plus 1 specifies the number of + * bits used to represent each of PCM sample + * values of the luma component + * @pcm_sample_bit_depth_chroma_minus1: this value plus 1 specifies the number + * of bits used to represent each of PCM + * sample values of the chroma components + * @log2_min_pcm_luma_coding_block_size_minus3: this value plus 3 specifies the + * minimum size of coding blocks + * @log2_diff_max_min_pcm_luma_coding_block_size: specifies the difference between + * the maximum and minimum size of + * coding blocks + * @num_short_term_ref_pic_sets: specifies the number of st_ref_pic_set() + * syntax structures included in the SPS + * @num_long_term_ref_pics_sps: specifies the number of candidate long-term + * reference pictures that are specified in the SPS + * @chroma_format_idc: specifies the chroma sampling + * @sps_max_sub_layers_minus1: this value plus 1 specifies the maximum number + * of temporal sub-layers + * @reserved: padding field. Should be zeroed by applications. + * @flags: see V4L2_HEVC_SPS_FLAG_{} + */ +struct v4l2_ctrl_hevc_sps { + u_int8_t video_parameter_set_id; + u_int8_t seq_parameter_set_id; + u_int16_t pic_width_in_luma_samples; + u_int16_t pic_height_in_luma_samples; + u_int8_t bit_depth_luma_minus8; + u_int8_t bit_depth_chroma_minus8; + u_int8_t log2_max_pic_order_cnt_lsb_minus4; + u_int8_t sps_max_dec_pic_buffering_minus1; + u_int8_t sps_max_num_reorder_pics; + u_int8_t sps_max_latency_increase_plus1; + u_int8_t log2_min_luma_coding_block_size_minus3; + u_int8_t log2_diff_max_min_luma_coding_block_size; + u_int8_t log2_min_luma_transform_block_size_minus2; + u_int8_t log2_diff_max_min_luma_transform_block_size; + u_int8_t max_transform_hierarchy_depth_inter; + u_int8_t max_transform_hierarchy_depth_intra; + u_int8_t pcm_sample_bit_depth_luma_minus1; + u_int8_t pcm_sample_bit_depth_chroma_minus1; + u_int8_t log2_min_pcm_luma_coding_block_size_minus3; + u_int8_t log2_diff_max_min_pcm_luma_coding_block_size; + u_int8_t num_short_term_ref_pic_sets; + u_int8_t num_long_term_ref_pics_sps; + u_int8_t chroma_format_idc; + u_int8_t sps_max_sub_layers_minus1; + + u_int8_t reserved[6]; + u_int64_t flags; +}; + +#define V4L2_HEVC_PPS_FLAG_DEPENDENT_SLICE_SEGMENT_ENABLED (1ULL << 0) +#define V4L2_HEVC_PPS_FLAG_OUTPUT_FLAG_PRESENT (1ULL << 1) +#define V4L2_HEVC_PPS_FLAG_SIGN_DATA_HIDING_ENABLED (1ULL << 2) +#define V4L2_HEVC_PPS_FLAG_CABAC_INIT_PRESENT (1ULL << 3) +#define V4L2_HEVC_PPS_FLAG_CONSTRAINED_INTRA_PRED (1ULL << 4) +#define V4L2_HEVC_PPS_FLAG_TRANSFORM_SKIP_ENABLED (1ULL << 5) +#define V4L2_HEVC_PPS_FLAG_CU_QP_DELTA_ENABLED (1ULL << 6) +#define V4L2_HEVC_PPS_FLAG_PPS_SLICE_CHROMA_QP_OFFSETS_PRESENT (1ULL << 7) +#define V4L2_HEVC_PPS_FLAG_WEIGHTED_PRED (1ULL << 8) +#define V4L2_HEVC_PPS_FLAG_WEIGHTED_BIPRED (1ULL << 9) +#define V4L2_HEVC_PPS_FLAG_TRANSQUANT_BYPASS_ENABLED (1ULL << 10) +#define V4L2_HEVC_PPS_FLAG_TILES_ENABLED (1ULL << 11) +#define V4L2_HEVC_PPS_FLAG_ENTROPY_CODING_SYNC_ENABLED (1ULL << 12) +#define V4L2_HEVC_PPS_FLAG_LOOP_FILTER_ACROSS_TILES_ENABLED (1ULL << 13) +#define V4L2_HEVC_PPS_FLAG_PPS_LOOP_FILTER_ACROSS_SLICES_ENABLED (1ULL << 14) +#define V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_OVERRIDE_ENABLED (1ULL << 15) +#define V4L2_HEVC_PPS_FLAG_PPS_DISABLE_DEBLOCKING_FILTER (1ULL << 16) +#define V4L2_HEVC_PPS_FLAG_LISTS_MODIFICATION_PRESENT (1ULL << 17) +#define V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT (1ULL << 18) +#define V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT (1ULL << 19) +#define V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING (1ULL << 20) + +/** + * struct v4l2_ctrl_hevc_pps - ITU-T Rec. H.265: Picture parameter set + * + * @pic_parameter_set_id: identifies the PPS for reference by other + * syntax elements + * @num_extra_slice_header_bits: specifies the number of extra slice header + * bits that are present in the slice header RBSP + * for coded pictures referring to the PPS. + * @num_ref_idx_l0_default_active_minus1: this value plus 1 specifies the + * inferred value of num_ref_idx_l0_active_minus1 + * @num_ref_idx_l1_default_active_minus1: this value plus 1 specifies the + * inferred value of num_ref_idx_l1_active_minus1 + * @init_qp_minus26: this value plus 26 specifies the initial value of SliceQp Y for + * each slice referring to the PPS + * @diff_cu_qp_delta_depth: specifies the difference between the luma coding + * tree block size and the minimum luma coding block + * size of coding units that convey cu_qp_delta_abs + * and cu_qp_delta_sign_flag + * @pps_cb_qp_offset: specify the offsets to the luma quantization parameter Cb + * @pps_cr_qp_offset: specify the offsets to the luma quantization parameter Cr + * @num_tile_columns_minus1: this value plus 1 specifies the number of tile columns + * partitioning the picture + * @num_tile_rows_minus1: this value plus 1 specifies the number of tile rows partitioning + * the picture + * @column_width_minus1: this value plus 1 specifies the width of the each tile column in + * units of coding tree blocks + * @row_height_minus1: this value plus 1 specifies the height of the each tile row in + * units of coding tree blocks + * @pps_beta_offset_div2: specify the default deblocking parameter offsets for + * beta divided by 2 + * @pps_tc_offset_div2: specify the default deblocking parameter offsets for tC + * divided by 2 + * @log2_parallel_merge_level_minus2: this value plus 2 specifies the value of + * the variable Log2ParMrgLevel + * @reserved: padding field. Should be zeroed by applications. + * @flags: see V4L2_HEVC_PPS_FLAG_{} + */ +struct v4l2_ctrl_hevc_pps { + u_int8_t pic_parameter_set_id; + u_int8_t num_extra_slice_header_bits; + u_int8_t num_ref_idx_l0_default_active_minus1; + u_int8_t num_ref_idx_l1_default_active_minus1; + int8_t init_qp_minus26; + u_int8_t diff_cu_qp_delta_depth; + int8_t pps_cb_qp_offset; + int8_t pps_cr_qp_offset; + u_int8_t num_tile_columns_minus1; + u_int8_t num_tile_rows_minus1; + u_int8_t column_width_minus1[20]; + u_int8_t row_height_minus1[22]; + int8_t pps_beta_offset_div2; + int8_t pps_tc_offset_div2; + u_int8_t log2_parallel_merge_level_minus2; + u_int8_t reserved; + u_int64_t flags; +}; + +#define V4L2_HEVC_DPB_ENTRY_LONG_TERM_REFERENCE 0x01 + +#define V4L2_HEVC_SEI_PIC_STRUCT_FRAME 0 +#define V4L2_HEVC_SEI_PIC_STRUCT_TOP_FIELD 1 +#define V4L2_HEVC_SEI_PIC_STRUCT_BOTTOM_FIELD 2 +#define V4L2_HEVC_SEI_PIC_STRUCT_TOP_BOTTOM 3 +#define V4L2_HEVC_SEI_PIC_STRUCT_BOTTOM_TOP 4 +#define V4L2_HEVC_SEI_PIC_STRUCT_TOP_BOTTOM_TOP 5 +#define V4L2_HEVC_SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM 6 +#define V4L2_HEVC_SEI_PIC_STRUCT_FRAME_DOUBLING 7 +#define V4L2_HEVC_SEI_PIC_STRUCT_FRAME_TRIPLING 8 +#define V4L2_HEVC_SEI_PIC_STRUCT_TOP_PAIRED_PREVIOUS_BOTTOM 9 +#define V4L2_HEVC_SEI_PIC_STRUCT_BOTTOM_PAIRED_PREVIOUS_TOP 10 +#define V4L2_HEVC_SEI_PIC_STRUCT_TOP_PAIRED_NEXT_BOTTOM 11 +#define V4L2_HEVC_SEI_PIC_STRUCT_BOTTOM_PAIRED_NEXT_TOP 12 + +#define V4L2_HEVC_DPB_ENTRIES_NUM_MAX 16 + +/** + * struct v4l2_hevc_dpb_entry - HEVC decoded picture buffer entry + * + * @timestamp: timestamp of the V4L2 capture buffer to use as reference. + * @flags: long term flag for the reference frame + * @field_pic: whether the reference is a field picture or a frame. + * @reserved: padding field. Should be zeroed by applications. + * @pic_order_cnt_val: the picture order count of the current picture. + */ +struct v4l2_hevc_dpb_entry { + u_int64_t timestamp; + u_int8_t flags; + u_int8_t field_pic; + u_int16_t reserved; + int32_t pic_order_cnt_val; +}; + +/** + * struct v4l2_hevc_pred_weight_table - HEVC weighted prediction parameters + * + * @delta_luma_weight_l0: the difference of the weighting factor applied + * to the luma prediction value for list 0 + * @luma_offset_l0: the additive offset applied to the luma prediction value + * for list 0 + * @delta_chroma_weight_l0: the difference of the weighting factor applied + * to the chroma prediction values for list 0 + * @chroma_offset_l0: the difference of the additive offset applied to + * the chroma prediction values for list 0 + * @delta_luma_weight_l1: the difference of the weighting factor applied + * to the luma prediction value for list 1 + * @luma_offset_l1: the additive offset applied to the luma prediction value + * for list 1 + * @delta_chroma_weight_l1: the difference of the weighting factor applied + * to the chroma prediction values for list 1 + * @chroma_offset_l1: the difference of the additive offset applied to + * the chroma prediction values for list 1 + * @luma_log2_weight_denom: the base 2 logarithm of the denominator for + * all luma weighting factors + * @delta_chroma_log2_weight_denom: the difference of the base 2 logarithm + * of the denominator for all chroma + * weighting factors + */ +struct v4l2_hevc_pred_weight_table { + int8_t delta_luma_weight_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; + int8_t luma_offset_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; + int8_t delta_chroma_weight_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX][2]; + int8_t chroma_offset_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX][2]; + + int8_t delta_luma_weight_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; + int8_t luma_offset_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; + int8_t delta_chroma_weight_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX][2]; + int8_t chroma_offset_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX][2]; + + u_int8_t luma_log2_weight_denom; + int8_t delta_chroma_log2_weight_denom; +}; + +#define V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_SAO_LUMA (1ULL << 0) +#define V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_SAO_CHROMA (1ULL << 1) +#define V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_TEMPORAL_MVP_ENABLED (1ULL << 2) +#define V4L2_HEVC_SLICE_PARAMS_FLAG_MVD_L1_ZERO (1ULL << 3) +#define V4L2_HEVC_SLICE_PARAMS_FLAG_CABAC_INIT (1ULL << 4) +#define V4L2_HEVC_SLICE_PARAMS_FLAG_COLLOCATED_FROM_L0 (1ULL << 5) +#define V4L2_HEVC_SLICE_PARAMS_FLAG_USE_INTEGER_MV (1ULL << 6) +#define V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_DEBLOCKING_FILTER_DISABLED (1ULL << 7) +#define V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_LOOP_FILTER_ACROSS_SLICES_ENABLED (1ULL << 8) +#define V4L2_HEVC_SLICE_PARAMS_FLAG_DEPENDENT_SLICE_SEGMENT (1ULL << 9) + +/** + * struct v4l2_ctrl_hevc_slice_params - HEVC slice parameters + * + * This control is a dynamically sized 1-dimensional array, + * V4L2_CTRL_FLAG_DYNAMIC_ARRAY flag must be set when using it. + * + * @bit_size: size (in bits) of the current slice data + * @data_byte_offset: offset (in bytes) to the video data in the current slice data + * @num_entry_point_offsets: specifies the number of entry point offset syntax + * elements in the slice header. + * @nal_unit_type: specifies the coding type of the slice (B, P or I) + * @nuh_temporal_id_plus1: minus 1 specifies a temporal identifier for the NAL unit + * @slice_type: see V4L2_HEVC_SLICE_TYPE_{} + * @colour_plane_id: specifies the colour plane associated with the current slice + * @slice_pic_order_cnt: specifies the picture order count + * @num_ref_idx_l0_active_minus1: this value plus 1 specifies the maximum + * reference index for reference picture list 0 + * that may be used to decode the slice + * @num_ref_idx_l1_active_minus1: this value plus 1 specifies the maximum + * reference index for reference picture list 1 + * that may be used to decode the slice + * @collocated_ref_idx: specifies the reference index of the collocated picture used + * for temporal motion vector prediction + * @five_minus_max_num_merge_cand: specifies the maximum number of merging + * motion vector prediction candidates supported in + * the slice subtracted from 5 + * @slice_qp_delta: specifies the initial value of QpY to be used for the coding + * blocks in the slice + * @slice_cb_qp_offset: specifies a difference to be added to the value of pps_cb_qp_offset + * @slice_cr_qp_offset: specifies a difference to be added to the value of pps_cr_qp_offset + * @slice_act_y_qp_offset: screen content extension parameters + * @slice_act_cb_qp_offset: screen content extension parameters + * @slice_act_cr_qp_offset: screen content extension parameters + * @slice_beta_offset_div2: specify the deblocking parameter offsets for beta divided by 2 + * @slice_tc_offset_div2: specify the deblocking parameter offsets for tC divided by 2 + * @pic_struct: indicates whether a picture should be displayed as a frame or as one or + * more fields + * @reserved0: padding field. Should be zeroed by applications. + * @slice_segment_addr: specifies the address of the first coding tree block in + * the slice segment + * @ref_idx_l0: the list of L0 reference elements as indices in the DPB + * @ref_idx_l1: the list of L1 reference elements as indices in the DPB + * @short_term_ref_pic_set_size: specifies the size of short-term reference + * pictures set included in the SPS + * @long_term_ref_pic_set_size: specifies the size of long-term reference + * pictures set include in the SPS + * @pred_weight_table: the prediction weight coefficients for inter-picture + * prediction + * @reserved1: padding field. Should be zeroed by applications. + * @flags: see V4L2_HEVC_SLICE_PARAMS_FLAG_{} + */ +struct v4l2_ctrl_hevc_slice_params { + u_int32_t bit_size; + u_int32_t data_byte_offset; + u_int32_t num_entry_point_offsets; + + /* ISO/IEC 23008-2, ITU-T Rec. H.265: NAL unit header */ + u_int8_t nal_unit_type; + u_int8_t nuh_temporal_id_plus1; + + /* ISO/IEC 23008-2, ITU-T Rec. H.265: General slice segment header */ + u_int8_t slice_type; + u_int8_t colour_plane_id; + int32_t slice_pic_order_cnt; + u_int8_t num_ref_idx_l0_active_minus1; + u_int8_t num_ref_idx_l1_active_minus1; + u_int8_t collocated_ref_idx; + u_int8_t five_minus_max_num_merge_cand; + int8_t slice_qp_delta; + int8_t slice_cb_qp_offset; + int8_t slice_cr_qp_offset; + int8_t slice_act_y_qp_offset; + int8_t slice_act_cb_qp_offset; + int8_t slice_act_cr_qp_offset; + int8_t slice_beta_offset_div2; + int8_t slice_tc_offset_div2; + + /* ISO/IEC 23008-2, ITU-T Rec. H.265: Picture timing SEI message */ + u_int8_t pic_struct; + + u_int8_t reserved0[3]; + /* ISO/IEC 23008-2, ITU-T Rec. H.265: General slice segment header */ + u_int32_t slice_segment_addr; + u_int8_t ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; + u_int8_t ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; + u_int16_t short_term_ref_pic_set_size; + u_int16_t long_term_ref_pic_set_size; + + /* ISO/IEC 23008-2, ITU-T Rec. H.265: Weighted prediction parameter */ + struct v4l2_hevc_pred_weight_table pred_weight_table; + + u_int8_t reserved1[2]; + u_int64_t flags; +}; + +#define V4L2_HEVC_DECODE_PARAM_FLAG_IRAP_PIC 0x1 +#define V4L2_HEVC_DECODE_PARAM_FLAG_IDR_PIC 0x2 +#define V4L2_HEVC_DECODE_PARAM_FLAG_NO_OUTPUT_OF_PRIOR 0x4 + +/** + * struct v4l2_ctrl_hevc_decode_params - HEVC decode parameters + * + * @pic_order_cnt_val: picture order count + * @short_term_ref_pic_set_size: specifies the size of short-term reference + * pictures set included in the SPS of the first slice + * @long_term_ref_pic_set_size: specifies the size of long-term reference + * pictures set include in the SPS of the first slice + * @num_active_dpb_entries: the number of entries in dpb + * @num_poc_st_curr_before: the number of reference pictures in the short-term + * set that come before the current frame + * @num_poc_st_curr_after: the number of reference pictures in the short-term + * set that come after the current frame + * @num_poc_lt_curr: the number of reference pictures in the long-term set + * @poc_st_curr_before: provides the index of the short term before references + * in DPB array + * @poc_st_curr_after: provides the index of the short term after references + * in DPB array + * @poc_lt_curr: provides the index of the long term references in DPB array + * @num_delta_pocs_of_ref_rps_idx: same as the derived value NumDeltaPocs[RefRpsIdx], + * can be used to parse the RPS data in slice headers + * instead of skipping it with @short_term_ref_pic_set_size. + * @reserved: padding field. Should be zeroed by applications. + * @dpb: the decoded picture buffer, for meta-data about reference frames + * @flags: see V4L2_HEVC_DECODE_PARAM_FLAG_{} + */ +struct v4l2_ctrl_hevc_decode_params { + int32_t pic_order_cnt_val; + u_int16_t short_term_ref_pic_set_size; + u_int16_t long_term_ref_pic_set_size; + u_int8_t num_active_dpb_entries; + u_int8_t num_poc_st_curr_before; + u_int8_t num_poc_st_curr_after; + u_int8_t num_poc_lt_curr; + u_int8_t poc_st_curr_before[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; + u_int8_t poc_st_curr_after[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; + u_int8_t poc_lt_curr[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; + u_int8_t num_delta_pocs_of_ref_rps_idx; + u_int8_t reserved[3]; + struct v4l2_hevc_dpb_entry dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]; + u_int64_t flags; +}; + +/** + * struct v4l2_ctrl_hevc_scaling_matrix - HEVC scaling lists parameters + * + * @scaling_list_4x4: scaling list is used for the scaling process for + * transform coefficients. The values on each scaling + * list are expected in raster scan order + * @scaling_list_8x8: scaling list is used for the scaling process for + * transform coefficients. The values on each scaling + * list are expected in raster scan order + * @scaling_list_16x16: scaling list is used for the scaling process for + * transform coefficients. The values on each scaling + * list are expected in raster scan order + * @scaling_list_32x32: scaling list is used for the scaling process for + * transform coefficients. The values on each scaling + * list are expected in raster scan order + * @scaling_list_dc_coef_16x16: scaling list is used for the scaling process + * for transform coefficients. The values on each + * scaling list are expected in raster scan order. + * @scaling_list_dc_coef_32x32: scaling list is used for the scaling process + * for transform coefficients. The values on each + * scaling list are expected in raster scan order. + */ +struct v4l2_ctrl_hevc_scaling_matrix { + u_int8_t scaling_list_4x4[6][16]; + u_int8_t scaling_list_8x8[6][64]; + u_int8_t scaling_list_16x16[6][64]; + u_int8_t scaling_list_32x32[2][64]; + u_int8_t scaling_list_dc_coef_16x16[6]; + u_int8_t scaling_list_dc_coef_32x32[2]; +}; + +#define V4L2_CID_COLORIMETRY_CLASS_BASE (V4L2_CTRL_CLASS_COLORIMETRY | 0x900) +#define V4L2_CID_COLORIMETRY_CLASS (V4L2_CTRL_CLASS_COLORIMETRY | 1) + +#define V4L2_CID_COLORIMETRY_HDR10_CLL_INFO (V4L2_CID_COLORIMETRY_CLASS_BASE + 0) + +struct v4l2_ctrl_hdr10_cll_info { + u_int16_t max_content_light_level; + u_int16_t max_pic_average_light_level; +}; + +#define V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY (V4L2_CID_COLORIMETRY_CLASS_BASE + 1) + +#define V4L2_HDR10_MASTERING_PRIMARIES_X_LOW 5 +#define V4L2_HDR10_MASTERING_PRIMARIES_X_HIGH 37000 +#define V4L2_HDR10_MASTERING_PRIMARIES_Y_LOW 5 +#define V4L2_HDR10_MASTERING_PRIMARIES_Y_HIGH 42000 +#define V4L2_HDR10_MASTERING_WHITE_POINT_X_LOW 5 +#define V4L2_HDR10_MASTERING_WHITE_POINT_X_HIGH 37000 +#define V4L2_HDR10_MASTERING_WHITE_POINT_Y_LOW 5 +#define V4L2_HDR10_MASTERING_WHITE_POINT_Y_HIGH 42000 +#define V4L2_HDR10_MASTERING_MAX_LUMA_LOW 50000 +#define V4L2_HDR10_MASTERING_MAX_LUMA_HIGH 100000000 +#define V4L2_HDR10_MASTERING_MIN_LUMA_LOW 1 +#define V4L2_HDR10_MASTERING_MIN_LUMA_HIGH 50000 + +struct v4l2_ctrl_hdr10_mastering_display { + u_int16_t display_primaries_x[3]; + u_int16_t display_primaries_y[3]; + u_int16_t white_point_x; + u_int16_t white_point_y; + u_int32_t max_display_mastering_luminance; + u_int32_t min_display_mastering_luminance; +}; + +/* Stateless VP9 controls */ + +#define V4L2_VP9_LOOP_FILTER_FLAG_DELTA_ENABLED 0x1 +#define V4L2_VP9_LOOP_FILTER_FLAG_DELTA_UPDATE 0x2 + +/** + * struct v4l2_vp9_loop_filter - VP9 loop filter parameters + * + * @ref_deltas: contains the adjustment needed for the filter level based on the + * chosen reference frame. If this syntax element is not present in the bitstream, + * users should pass its last value. + * @mode_deltas: contains the adjustment needed for the filter level based on the + * chosen mode. If this syntax element is not present in the bitstream, users should + * pass its last value. + * @level: indicates the loop filter strength. + * @sharpness: indicates the sharpness level. + * @flags: combination of V4L2_VP9_LOOP_FILTER_FLAG_{} flags. + * @reserved: padding field. Should be zeroed by applications. + * + * This structure contains all loop filter related parameters. See sections + * '7.2.8 Loop filter semantics' of the VP9 specification for more details. + */ +struct v4l2_vp9_loop_filter { + int8_t ref_deltas[4]; + int8_t mode_deltas[2]; + u_int8_t level; + u_int8_t sharpness; + u_int8_t flags; + u_int8_t reserved[7]; +}; + +/** + * struct v4l2_vp9_quantization - VP9 quantization parameters + * + * @base_q_idx: indicates the base frame qindex. + * @delta_q_y_dc: indicates the Y DC quantizer relative to base_q_idx. + * @delta_q_uv_dc: indicates the UV DC quantizer relative to base_q_idx. + * @delta_q_uv_ac: indicates the UV AC quantizer relative to base_q_idx. + * @reserved: padding field. Should be zeroed by applications. + * + * Encodes the quantization parameters. See section '7.2.9 Quantization params + * syntax' of the VP9 specification for more details. + */ +struct v4l2_vp9_quantization { + u_int8_t base_q_idx; + int8_t delta_q_y_dc; + int8_t delta_q_uv_dc; + int8_t delta_q_uv_ac; + u_int8_t reserved[4]; +}; + +#define V4L2_VP9_SEGMENTATION_FLAG_ENABLED 0x01 +#define V4L2_VP9_SEGMENTATION_FLAG_UPDATE_MAP 0x02 +#define V4L2_VP9_SEGMENTATION_FLAG_TEMPORAL_UPDATE 0x04 +#define V4L2_VP9_SEGMENTATION_FLAG_UPDATE_DATA 0x08 +#define V4L2_VP9_SEGMENTATION_FLAG_ABS_OR_DELTA_UPDATE 0x10 + +#define V4L2_VP9_SEG_LVL_ALT_Q 0 +#define V4L2_VP9_SEG_LVL_ALT_L 1 +#define V4L2_VP9_SEG_LVL_REF_FRAME 2 +#define V4L2_VP9_SEG_LVL_SKIP 3 +#define V4L2_VP9_SEG_LVL_MAX 4 + +#define V4L2_VP9_SEGMENT_FEATURE_ENABLED(id) (1 << (id)) +#define V4L2_VP9_SEGMENT_FEATURE_ENABLED_MASK 0xf + +/** + * struct v4l2_vp9_segmentation - VP9 segmentation parameters + * + * @feature_data: data attached to each feature. Data entry is only valid if + * the feature is enabled. The array shall be indexed with segment number as + * the first dimension (0..7) and one of V4L2_VP9_SEG_{} as the second dimension. + * @feature_enabled: bitmask defining which features are enabled in each segment. + * The value for each segment is a combination of V4L2_VP9_SEGMENT_FEATURE_ENABLED(id) + * values where id is one of V4L2_VP9_SEG_LVL_{}. + * @tree_probs: specifies the probability values to be used when decoding a + * Segment-ID. See '5.15. Segmentation map' section of the VP9 specification + * for more details. + * @pred_probs: specifies the probability values to be used when decoding a + * Predicted-Segment-ID. See '6.4.14. Get segment id syntax' section of :ref:`vp9` + * for more details. + * @flags: combination of V4L2_VP9_SEGMENTATION_FLAG_{} flags. + * @reserved: padding field. Should be zeroed by applications. + * + * Encodes the quantization parameters. See section '7.2.10 Segmentation params syntax' of + * the VP9 specification for more details. + */ +struct v4l2_vp9_segmentation { + int16_t feature_data[8][4]; + u_int8_t feature_enabled[8]; + u_int8_t tree_probs[7]; + u_int8_t pred_probs[3]; + u_int8_t flags; + u_int8_t reserved[5]; +}; + +#define V4L2_VP9_FRAME_FLAG_KEY_FRAME 0x001 +#define V4L2_VP9_FRAME_FLAG_SHOW_FRAME 0x002 +#define V4L2_VP9_FRAME_FLAG_ERROR_RESILIENT 0x004 +#define V4L2_VP9_FRAME_FLAG_INTRA_ONLY 0x008 +#define V4L2_VP9_FRAME_FLAG_ALLOW_HIGH_PREC_MV 0x010 +#define V4L2_VP9_FRAME_FLAG_REFRESH_FRAME_CTX 0x020 +#define V4L2_VP9_FRAME_FLAG_PARALLEL_DEC_MODE 0x040 +#define V4L2_VP9_FRAME_FLAG_X_SUBSAMPLING 0x080 +#define V4L2_VP9_FRAME_FLAG_Y_SUBSAMPLING 0x100 +#define V4L2_VP9_FRAME_FLAG_COLOR_RANGE_FULL_SWING 0x200 + +#define V4L2_VP9_SIGN_BIAS_LAST 0x1 +#define V4L2_VP9_SIGN_BIAS_GOLDEN 0x2 +#define V4L2_VP9_SIGN_BIAS_ALT 0x4 + +#define V4L2_VP9_RESET_FRAME_CTX_NONE 0 +#define V4L2_VP9_RESET_FRAME_CTX_SPEC 1 +#define V4L2_VP9_RESET_FRAME_CTX_ALL 2 + +#define V4L2_VP9_INTERP_FILTER_EIGHTTAP 0 +#define V4L2_VP9_INTERP_FILTER_EIGHTTAP_SMOOTH 1 +#define V4L2_VP9_INTERP_FILTER_EIGHTTAP_SHARP 2 +#define V4L2_VP9_INTERP_FILTER_BILINEAR 3 +#define V4L2_VP9_INTERP_FILTER_SWITCHABLE 4 + +#define V4L2_VP9_REFERENCE_MODE_SINGLE_REFERENCE 0 +#define V4L2_VP9_REFERENCE_MODE_COMPOUND_REFERENCE 1 +#define V4L2_VP9_REFERENCE_MODE_SELECT 2 + +#define V4L2_VP9_PROFILE_MAX 3 + +#define V4L2_CID_STATELESS_VP9_FRAME (V4L2_CID_CODEC_STATELESS_BASE + 300) +/** + * struct v4l2_ctrl_vp9_frame - VP9 frame decoding control + * + * @lf: loop filter parameters. See &v4l2_vp9_loop_filter for more details. + * @quant: quantization parameters. See &v4l2_vp9_quantization for more details. + * @seg: segmentation parameters. See &v4l2_vp9_segmentation for more details. + * @flags: combination of V4L2_VP9_FRAME_FLAG_{} flags. + * @compressed_header_size: compressed header size in bytes. + * @uncompressed_header_size: uncompressed header size in bytes. + * @frame_width_minus_1: add 1 to it and you'll get the frame width expressed in pixels. + * @frame_height_minus_1: add 1 to it and you'll get the frame height expressed in pixels. + * @render_width_minus_1: add 1 to it and you'll get the expected render width expressed in + * pixels. This is not used during the decoding process but might be used by HW scalers + * to prepare a frame that's ready for scanout. + * @render_height_minus_1: add 1 to it and you'll get the expected render height expressed in + * pixels. This is not used during the decoding process but might be used by HW scalers + * to prepare a frame that's ready for scanout. + * @last_frame_ts: "last" reference buffer timestamp. + * The timestamp refers to the timestamp field in struct v4l2_buffer. + * Use v4l2_timeval_to_ns() to convert the struct timeval to a u_int64_t. + * @golden_frame_ts: "golden" reference buffer timestamp. + * The timestamp refers to the timestamp field in struct v4l2_buffer. + * Use v4l2_timeval_to_ns() to convert the struct timeval to a u_int64_t. + * @alt_frame_ts: "alt" reference buffer timestamp. + * The timestamp refers to the timestamp field in struct v4l2_buffer. + * Use v4l2_timeval_to_ns() to convert the struct timeval to a u_int64_t. + * @ref_frame_sign_bias: a bitfield specifying whether the sign bias is set for a given + * reference frame. Either of V4L2_VP9_SIGN_BIAS_{}. + * @reset_frame_context: specifies whether the frame context should be reset to default values. + * Either of V4L2_VP9_RESET_FRAME_CTX_{}. + * @frame_context_idx: frame context that should be used/updated. + * @profile: VP9 profile. Can be 0, 1, 2 or 3. + * @bit_depth: bits per components. Can be 8, 10 or 12. Note that not all profiles support + * 10 and/or 12 bits depths. + * @interpolation_filter: specifies the filter selection used for performing inter prediction. + * Set to one of V4L2_VP9_INTERP_FILTER_{}. + * @tile_cols_log2: specifies the base 2 logarithm of the width of each tile (where the width + * is measured in units of 8x8 blocks). Shall be less than or equal to 6. + * @tile_rows_log2: specifies the base 2 logarithm of the height of each tile (where the height + * is measured in units of 8x8 blocks). + * @reference_mode: specifies the type of inter prediction to be used. + * Set to one of V4L2_VP9_REFERENCE_MODE_{}. + * @reserved: padding field. Should be zeroed by applications. + */ +struct v4l2_ctrl_vp9_frame { + struct v4l2_vp9_loop_filter lf; + struct v4l2_vp9_quantization quant; + struct v4l2_vp9_segmentation seg; + u_int32_t flags; + u_int16_t compressed_header_size; + u_int16_t uncompressed_header_size; + u_int16_t frame_width_minus_1; + u_int16_t frame_height_minus_1; + u_int16_t render_width_minus_1; + u_int16_t render_height_minus_1; + u_int64_t last_frame_ts; + u_int64_t golden_frame_ts; + u_int64_t alt_frame_ts; + u_int8_t ref_frame_sign_bias; + u_int8_t reset_frame_context; + u_int8_t frame_context_idx; + u_int8_t profile; + u_int8_t bit_depth; + u_int8_t interpolation_filter; + u_int8_t tile_cols_log2; + u_int8_t tile_rows_log2; + u_int8_t reference_mode; + u_int8_t reserved[7]; +}; + +#define V4L2_VP9_NUM_FRAME_CTX 4 + +/** + * struct v4l2_vp9_mv_probs - VP9 Motion vector probability updates + * @joint: motion vector joint probability updates. + * @sign: motion vector sign probability updates. + * @classes: motion vector class probability updates. + * @class0_bit: motion vector class0 bit probability updates. + * @bits: motion vector bits probability updates. + * @class0_fr: motion vector class0 fractional bit probability updates. + * @fr: motion vector fractional bit probability updates. + * @class0_hp: motion vector class0 high precision fractional bit probability updates. + * @hp: motion vector high precision fractional bit probability updates. + * + * This structure contains new values of motion vector probabilities. + * A value of zero in an array element means there is no update of the relevant probability. + * See `struct v4l2_vp9_prob_updates` for details. + */ +struct v4l2_vp9_mv_probs { + u_int8_t joint[3]; + u_int8_t sign[2]; + u_int8_t classes[2][10]; + u_int8_t class0_bit[2]; + u_int8_t bits[2][10]; + u_int8_t class0_fr[2][2][3]; + u_int8_t fr[2][3]; + u_int8_t class0_hp[2]; + u_int8_t hp[2]; +}; + +#define V4L2_CID_STATELESS_VP9_COMPRESSED_HDR (V4L2_CID_CODEC_STATELESS_BASE + 301) + +#define V4L2_VP9_TX_MODE_ONLY_4X4 0 +#define V4L2_VP9_TX_MODE_ALLOW_8X8 1 +#define V4L2_VP9_TX_MODE_ALLOW_16X16 2 +#define V4L2_VP9_TX_MODE_ALLOW_32X32 3 +#define V4L2_VP9_TX_MODE_SELECT 4 + +/** + * struct v4l2_ctrl_vp9_compressed_hdr - VP9 probability updates control + * @tx_mode: specifies the TX mode. Set to one of V4L2_VP9_TX_MODE_{}. + * @tx8: TX 8x8 probability updates. + * @tx16: TX 16x16 probability updates. + * @tx32: TX 32x32 probability updates. + * @coef: coefficient probability updates. + * @skip: skip probability updates. + * @inter_mode: inter mode probability updates. + * @interp_filter: interpolation filter probability updates. + * @is_inter: is inter-block probability updates. + * @comp_mode: compound prediction mode probability updates. + * @single_ref: single ref probability updates. + * @comp_ref: compound ref probability updates. + * @y_mode: Y prediction mode probability updates. + * @uv_mode: UV prediction mode probability updates. + * @partition: partition probability updates. + * @mv: motion vector probability updates. + * + * This structure holds the probabilities update as parsed in the compressed + * header (Spec 6.3). These values represent the value of probability update after + * being translated with inv_map_table[] (see 6.3.5). A value of zero in an array element + * means that there is no update of the relevant probability. + * + * This control is optional and needs to be used when dealing with the hardware which is + * not capable of parsing the compressed header itself. Only drivers which need it will + * implement it. + */ +struct v4l2_ctrl_vp9_compressed_hdr { + u_int8_t tx_mode; + u_int8_t tx8[2][1]; + u_int8_t tx16[2][2]; + u_int8_t tx32[2][3]; + u_int8_t coef[4][2][2][6][6][3]; + u_int8_t skip[3]; + u_int8_t inter_mode[7][3]; + u_int8_t interp_filter[4][2]; + u_int8_t is_inter[4]; + u_int8_t comp_mode[5]; + u_int8_t single_ref[5][2]; + u_int8_t comp_ref[5]; + u_int8_t y_mode[4][9]; + u_int8_t uv_mode[10][9]; + u_int8_t partition[16][3]; + + struct v4l2_vp9_mv_probs mv; +}; + +/* Stateless AV1 controls */ + +#define V4L2_AV1_TOTAL_REFS_PER_FRAME 8 +#define V4L2_AV1_CDEF_MAX 8 +#define V4L2_AV1_NUM_PLANES_MAX 3 /* 1 if monochrome, 3 otherwise */ +#define V4L2_AV1_MAX_SEGMENTS 8 +#define V4L2_AV1_MAX_OPERATING_POINTS (1 << 5) /* 5 bits to encode */ +#define V4L2_AV1_REFS_PER_FRAME 7 +#define V4L2_AV1_MAX_NUM_Y_POINTS (1 << 4) /* 4 bits to encode */ +#define V4L2_AV1_MAX_NUM_CB_POINTS (1 << 4) /* 4 bits to encode */ +#define V4L2_AV1_MAX_NUM_CR_POINTS (1 << 4) /* 4 bits to encode */ +#define V4L2_AV1_AR_COEFFS_SIZE 25 /* (2 * 3 * (3 + 1)) + 1 */ +#define V4L2_AV1_MAX_NUM_PLANES 3 +#define V4L2_AV1_MAX_TILE_COLS 64 +#define V4L2_AV1_MAX_TILE_ROWS 64 +#define V4L2_AV1_MAX_TILE_COUNT 512 + +#define V4L2_AV1_SEQUENCE_FLAG_STILL_PICTURE 0x00000001 +#define V4L2_AV1_SEQUENCE_FLAG_USE_128X128_SUPERBLOCK 0x00000002 +#define V4L2_AV1_SEQUENCE_FLAG_ENABLE_FILTER_INTRA 0x00000004 +#define V4L2_AV1_SEQUENCE_FLAG_ENABLE_INTRA_EDGE_FILTER 0x00000008 +#define V4L2_AV1_SEQUENCE_FLAG_ENABLE_INTERINTRA_COMPOUND 0x00000010 +#define V4L2_AV1_SEQUENCE_FLAG_ENABLE_MASKED_COMPOUND 0x00000020 +#define V4L2_AV1_SEQUENCE_FLAG_ENABLE_WARPED_MOTION 0x00000040 +#define V4L2_AV1_SEQUENCE_FLAG_ENABLE_DUAL_FILTER 0x00000080 +#define V4L2_AV1_SEQUENCE_FLAG_ENABLE_ORDER_HINT 0x00000100 +#define V4L2_AV1_SEQUENCE_FLAG_ENABLE_JNT_COMP 0x00000200 +#define V4L2_AV1_SEQUENCE_FLAG_ENABLE_REF_FRAME_MVS 0x00000400 +#define V4L2_AV1_SEQUENCE_FLAG_ENABLE_SUPERRES 0x00000800 +#define V4L2_AV1_SEQUENCE_FLAG_ENABLE_CDEF 0x00001000 +#define V4L2_AV1_SEQUENCE_FLAG_ENABLE_RESTORATION 0x00002000 +#define V4L2_AV1_SEQUENCE_FLAG_MONO_CHROME 0x00004000 +#define V4L2_AV1_SEQUENCE_FLAG_COLOR_RANGE 0x00008000 +#define V4L2_AV1_SEQUENCE_FLAG_SUBSAMPLING_X 0x00010000 +#define V4L2_AV1_SEQUENCE_FLAG_SUBSAMPLING_Y 0x00020000 +#define V4L2_AV1_SEQUENCE_FLAG_FILM_GRAIN_PARAMS_PRESENT 0x00040000 +#define V4L2_AV1_SEQUENCE_FLAG_SEPARATE_UV_DELTA_Q 0x00080000 + +#define V4L2_CID_STATELESS_AV1_SEQUENCE (V4L2_CID_CODEC_STATELESS_BASE + 500) +/** + * struct v4l2_ctrl_av1_sequence - AV1 Sequence + * + * Represents an AV1 Sequence OBU. See section 5.5 "Sequence header OBU syntax" + * for more details. + * + * @flags: See V4L2_AV1_SEQUENCE_FLAG_{}. + * @seq_profile: specifies the features that can be used in the coded video + * sequence. + * @order_hint_bits: specifies the number of bits used for the order_hint field + * at each frame. + * @bit_depth: the bitdepth to use for the sequence as described in section + * 5.5.2 "Color config syntax". + * @reserved: padding field. Should be zeroed by applications. + * @max_frame_width_minus_1: specifies the maximum frame width minus 1 for the + * frames represented by this sequence header. + * @max_frame_height_minus_1: specifies the maximum frame height minus 1 for the + * frames represented by this sequence header. + */ +struct v4l2_ctrl_av1_sequence { + u_int32_t flags; + u_int8_t seq_profile; + u_int8_t order_hint_bits; + u_int8_t bit_depth; + u_int8_t reserved; + u_int16_t max_frame_width_minus_1; + u_int16_t max_frame_height_minus_1; +}; + +#define V4L2_CID_STATELESS_AV1_TILE_GROUP_ENTRY (V4L2_CID_CODEC_STATELESS_BASE + 501) +/** + * struct v4l2_ctrl_av1_tile_group_entry - AV1 Tile Group entry + * + * Represents a single AV1 tile inside an AV1 Tile Group. Note that MiRowStart, + * MiRowEnd, MiColStart and MiColEnd can be retrieved from struct + * v4l2_av1_tile_info in struct v4l2_ctrl_av1_frame using tile_row and + * tile_col. See section 6.10.1 "General tile group OBU semantics" for more + * details. + * + * @tile_offset: offset from the OBU data, i.e. where the coded tile data + * actually starts. + * @tile_size: specifies the size in bytes of the coded tile. Equivalent to + * "TileSize" in the AV1 Specification. + * @tile_row: specifies the row of the current tile. Equivalent to "TileRow" in + * the AV1 Specification. + * @tile_col: specifies the col of the current tile. Equivalent to "TileCol" in + * the AV1 Specification. + */ +struct v4l2_ctrl_av1_tile_group_entry { + u_int32_t tile_offset; + u_int32_t tile_size; + u_int32_t tile_row; + u_int32_t tile_col; +}; + +/** + * enum v4l2_av1_warp_model - AV1 Warp Model as described in section 3 + * "Symbols and abbreviated terms" of the AV1 Specification. + * + * @V4L2_AV1_WARP_MODEL_IDENTITY: Warp model is just an identity transform. + * @V4L2_AV1_WARP_MODEL_TRANSLATION: Warp model is a pure translation. + * @V4L2_AV1_WARP_MODEL_ROTZOOM: Warp model is a rotation + symmetric zoom + + * translation. + * @V4L2_AV1_WARP_MODEL_AFFINE: Warp model is a general affine transform. + */ +enum v4l2_av1_warp_model { + V4L2_AV1_WARP_MODEL_IDENTITY = 0, + V4L2_AV1_WARP_MODEL_TRANSLATION = 1, + V4L2_AV1_WARP_MODEL_ROTZOOM = 2, + V4L2_AV1_WARP_MODEL_AFFINE = 3, +}; + +/** + * enum v4l2_av1_reference_frame - AV1 reference frames + * + * @V4L2_AV1_REF_INTRA_FRAME: Intra Frame Reference + * @V4L2_AV1_REF_LAST_FRAME: Last Reference Frame + * @V4L2_AV1_REF_LAST2_FRAME: Last2 Reference Frame + * @V4L2_AV1_REF_LAST3_FRAME: Last3 Reference Frame + * @V4L2_AV1_REF_GOLDEN_FRAME: Golden Reference Frame + * @V4L2_AV1_REF_BWDREF_FRAME: BWD Reference Frame + * @V4L2_AV1_REF_ALTREF2_FRAME: Alternative2 Reference Frame + * @V4L2_AV1_REF_ALTREF_FRAME: Alternative Reference Frame + */ +enum v4l2_av1_reference_frame { + V4L2_AV1_REF_INTRA_FRAME = 0, + V4L2_AV1_REF_LAST_FRAME = 1, + V4L2_AV1_REF_LAST2_FRAME = 2, + V4L2_AV1_REF_LAST3_FRAME = 3, + V4L2_AV1_REF_GOLDEN_FRAME = 4, + V4L2_AV1_REF_BWDREF_FRAME = 5, + V4L2_AV1_REF_ALTREF2_FRAME = 6, + V4L2_AV1_REF_ALTREF_FRAME = 7, +}; + +#define V4L2_AV1_GLOBAL_MOTION_IS_INVALID(ref) (1 << (ref)) + +#define V4L2_AV1_GLOBAL_MOTION_FLAG_IS_GLOBAL 0x1 +#define V4L2_AV1_GLOBAL_MOTION_FLAG_IS_ROT_ZOOM 0x2 +#define V4L2_AV1_GLOBAL_MOTION_FLAG_IS_TRANSLATION 0x4 +/** + * struct v4l2_av1_global_motion - AV1 Global Motion parameters as described in + * section 6.8.17 "Global motion params semantics" of the AV1 specification. + * + * @flags: A bitfield containing the flags per reference frame. See + * V4L2_AV1_GLOBAL_MOTION_FLAG_{} + * @type: The type of global motion transform used. + * @params: this field has the same meaning as "gm_params" in the AV1 + * specification. + * @invalid: bitfield indicating whether the global motion params are invalid + * for a given reference frame. See section 7.11.3.6 Setup shear process and + * the variable "warpValid". Use V4L2_AV1_GLOBAL_MOTION_IS_INVALID(ref) to + * create a suitable mask. + * @reserved: padding field. Should be zeroed by applications. + */ + +struct v4l2_av1_global_motion { + u_int8_t flags[V4L2_AV1_TOTAL_REFS_PER_FRAME]; + enum v4l2_av1_warp_model type[V4L2_AV1_TOTAL_REFS_PER_FRAME]; + int32_t params[V4L2_AV1_TOTAL_REFS_PER_FRAME][6]; + u_int8_t invalid; + u_int8_t reserved[3]; +}; + +/** + * enum v4l2_av1_frame_restoration_type - AV1 Frame Restoration Type + * @V4L2_AV1_FRAME_RESTORE_NONE: no filtering is applied. + * @V4L2_AV1_FRAME_RESTORE_WIENER: Wiener filter process is invoked. + * @V4L2_AV1_FRAME_RESTORE_SGRPROJ: self guided filter process is invoked. + * @V4L2_AV1_FRAME_RESTORE_SWITCHABLE: restoration filter is swichtable. + */ +enum v4l2_av1_frame_restoration_type { + V4L2_AV1_FRAME_RESTORE_NONE = 0, + V4L2_AV1_FRAME_RESTORE_WIENER = 1, + V4L2_AV1_FRAME_RESTORE_SGRPROJ = 2, + V4L2_AV1_FRAME_RESTORE_SWITCHABLE = 3, +}; + +#define V4L2_AV1_LOOP_RESTORATION_FLAG_USES_LR 0x1 +#define V4L2_AV1_LOOP_RESTORATION_FLAG_USES_CHROMA_LR 0x2 + +/** + * struct v4l2_av1_loop_restoration - AV1 Loop Restauration as described in + * section 6.10.15 "Loop restoration params semantics" of the AV1 specification. + * + * @flags: See V4L2_AV1_LOOP_RESTORATION_FLAG_{}. + * @lr_unit_shift: specifies if the luma restoration size should be halved. + * @lr_uv_shift: specifies if the chroma size should be half the luma size. + * @reserved: padding field. Should be zeroed by applications. + * @frame_restoration_type: specifies the type of restoration used for each + * plane. See enum v4l2_av1_frame_restoration_type. + * @loop_restoration_size: specifies the size of loop restoration units in units + * of samples in the current plane. + */ +struct v4l2_av1_loop_restoration { + u_int8_t flags; + u_int8_t lr_unit_shift; + u_int8_t lr_uv_shift; + u_int8_t reserved; + enum v4l2_av1_frame_restoration_type frame_restoration_type[V4L2_AV1_NUM_PLANES_MAX]; + u_int32_t loop_restoration_size[V4L2_AV1_MAX_NUM_PLANES]; +}; + +/** + * struct v4l2_av1_cdef - AV1 CDEF params semantics as described in section + * 6.10.14 "CDEF params semantics" of the AV1 specification + * + * @damping_minus_3: controls the amount of damping in the deringing filter. + * @bits: specifies the number of bits needed to specify which CDEF filter to + * apply. + * @y_pri_strength: specifies the strength of the primary filter. + * @y_sec_strength: specifies the strength of the secondary filter. + * @uv_pri_strength: specifies the strength of the primary filter. + * @uv_sec_strength: specifies the strength of the secondary filter. + */ +struct v4l2_av1_cdef { + u_int8_t damping_minus_3; + u_int8_t bits; + u_int8_t y_pri_strength[V4L2_AV1_CDEF_MAX]; + u_int8_t y_sec_strength[V4L2_AV1_CDEF_MAX]; + u_int8_t uv_pri_strength[V4L2_AV1_CDEF_MAX]; + u_int8_t uv_sec_strength[V4L2_AV1_CDEF_MAX]; +}; + +#define V4L2_AV1_SEGMENTATION_FLAG_ENABLED 0x1 +#define V4L2_AV1_SEGMENTATION_FLAG_UPDATE_MAP 0x2 +#define V4L2_AV1_SEGMENTATION_FLAG_TEMPORAL_UPDATE 0x4 +#define V4L2_AV1_SEGMENTATION_FLAG_UPDATE_DATA 0x8 +#define V4L2_AV1_SEGMENTATION_FLAG_SEG_ID_PRE_SKIP 0x10 + +/** + * enum v4l2_av1_segment_feature - AV1 segment features as described in section + * 3 "Symbols and abbreviated terms" of the AV1 specification. + * + * @V4L2_AV1_SEG_LVL_ALT_Q: Index for quantizer segment feature. + * @V4L2_AV1_SEG_LVL_ALT_LF_Y_V: Index for vertical luma loop filter segment + * feature. + * @V4L2_AV1_SEG_LVL_REF_FRAME: Index for reference frame segment feature. + * @V4L2_AV1_SEG_LVL_REF_SKIP: Index for skip segment feature. + * @V4L2_AV1_SEG_LVL_REF_GLOBALMV: Index for global mv feature. + * @V4L2_AV1_SEG_LVL_MAX: Number of segment features. + */ +enum v4l2_av1_segment_feature { + V4L2_AV1_SEG_LVL_ALT_Q = 0, + V4L2_AV1_SEG_LVL_ALT_LF_Y_V = 1, + V4L2_AV1_SEG_LVL_REF_FRAME = 5, + V4L2_AV1_SEG_LVL_REF_SKIP = 6, + V4L2_AV1_SEG_LVL_REF_GLOBALMV = 7, + V4L2_AV1_SEG_LVL_MAX = 8 +}; + +#define V4L2_AV1_SEGMENT_FEATURE_ENABLED(id) (1 << (id)) + +/** + * struct v4l2_av1_segmentation - AV1 Segmentation params as defined in section + * 6.8.13 "Segmentation params semantics" of the AV1 specification. + * + * @flags: see V4L2_AV1_SEGMENTATION_FLAG_{}. + * @last_active_seg_id: indicates the highest numbered segment id that has some + * enabled feature. This is used when decoding the segment id to only decode + * choices corresponding to used segments. + * @feature_enabled: bitmask defining which features are enabled in each + * segment. Use V4L2_AV1_SEGMENT_FEATURE_ENABLED to build a suitable mask. + * @feature_data: data attached to each feature. Data entry is only valid if the + * feature is enabled + */ +struct v4l2_av1_segmentation { + u_int8_t flags; + u_int8_t last_active_seg_id; + u_int8_t feature_enabled[V4L2_AV1_MAX_SEGMENTS]; + int16_t feature_data[V4L2_AV1_MAX_SEGMENTS][V4L2_AV1_SEG_LVL_MAX]; +}; + +#define V4L2_AV1_LOOP_FILTER_FLAG_DELTA_ENABLED 0x1 +#define V4L2_AV1_LOOP_FILTER_FLAG_DELTA_UPDATE 0x2 +#define V4L2_AV1_LOOP_FILTER_FLAG_DELTA_LF_PRESENT 0x4 +#define V4L2_AV1_LOOP_FILTER_FLAG_DELTA_LF_MULTI 0x8 + +/** + * struct v4l2_av1_loop_filter - AV1 Loop filter params as defined in section + * 6.8.10 "Loop filter semantics" and 6.8.16 "Loop filter delta parameters + * semantics" of the AV1 specification. + * + * @flags: see V4L2_AV1_LOOP_FILTER_FLAG_{} + * @level: an array containing loop filter strength values. Different loop + * filter strength values from the array are used depending on the image plane + * being filtered, and the edge direction (vertical or horizontal) being + * filtered. + * @sharpness: indicates the sharpness level. The loop_filter_level and + * loop_filter_sharpness together determine when a block edge is filtered, and + * by how much the filtering can change the sample values. The loop filter + * process is described in section 7.14 of the AV1 specification. + * @ref_deltas: contains the adjustment needed for the filter level based on the + * chosen reference frame. If this syntax element is not present, it maintains + * its previous value. + * @mode_deltas: contains the adjustment needed for the filter level based on + * the chosen mode. If this syntax element is not present, it maintains its + * previous value. + * @delta_lf_res: specifies the left shift which should be applied to decoded + * loop filter delta values. + */ +struct v4l2_av1_loop_filter { + u_int8_t flags; + u_int8_t level[4]; + u_int8_t sharpness; + int8_t ref_deltas[V4L2_AV1_TOTAL_REFS_PER_FRAME]; + int8_t mode_deltas[2]; + u_int8_t delta_lf_res; +}; + +#define V4L2_AV1_QUANTIZATION_FLAG_DIFF_UV_DELTA 0x1 +#define V4L2_AV1_QUANTIZATION_FLAG_USING_QMATRIX 0x2 +#define V4L2_AV1_QUANTIZATION_FLAG_DELTA_Q_PRESENT 0x4 + +/** + * struct v4l2_av1_quantization - AV1 Quantization params as defined in section + * 6.8.11 "Quantization params semantics" of the AV1 specification. + * + * @flags: see V4L2_AV1_QUANTIZATION_FLAG_{} + * @base_q_idx: indicates the base frame qindex. This is used for Y AC + * coefficients and as the base value for the other quantizers. + * @delta_q_y_dc: indicates the Y DC quantizer relative to base_q_idx. + * @delta_q_u_dc: indicates the U DC quantizer relative to base_q_idx. + * @delta_q_u_ac: indicates the U AC quantizer relative to base_q_idx. + * @delta_q_v_dc: indicates the V DC quantizer relative to base_q_idx. + * @delta_q_v_ac: indicates the V AC quantizer relative to base_q_idx. + * @qm_y: specifies the level in the quantizer matrix that should be used for + * luma plane decoding. + * @qm_u: specifies the level in the quantizer matrix that should be used for + * chroma U plane decoding. + * @qm_v: specifies the level in the quantizer matrix that should be used for + * chroma V plane decoding. + * @delta_q_res: specifies the left shift which should be applied to decoded + * quantizer index delta values. + */ +struct v4l2_av1_quantization { + u_int8_t flags; + u_int8_t base_q_idx; + int8_t delta_q_y_dc; + int8_t delta_q_u_dc; + int8_t delta_q_u_ac; + int8_t delta_q_v_dc; + int8_t delta_q_v_ac; + u_int8_t qm_y; + u_int8_t qm_u; + u_int8_t qm_v; + u_int8_t delta_q_res; +}; + +#define V4L2_AV1_TILE_INFO_FLAG_UNIFORM_TILE_SPACING 0x1 + +/** + * struct v4l2_av1_tile_info - AV1 Tile info as defined in section 6.8.14 "Tile + * info semantics" of the AV1 specification. + * + * @flags: see V4L2_AV1_TILE_INFO_FLAG_{} + * @context_update_tile_id: specifies which tile to use for the CDF update. + * @tile_rows: specifies the number of tiles down the frame. + * @tile_cols: specifies the number of tiles across the frame. + * @mi_col_starts: an array specifying the start column (in units of 4x4 luma + * samples) for each tile across the image. + * @mi_row_starts: an array specifying the start row (in units of 4x4 luma + * samples) for each tile down the image. + * @width_in_sbs_minus_1: specifies the width of a tile minus 1 in units of + * superblocks. + * @height_in_sbs_minus_1: specifies the height of a tile minus 1 in units of + * superblocks. + * @tile_size_bytes: specifies the number of bytes needed to code each tile + * size. + * @reserved: padding field. Should be zeroed by applications. + */ +struct v4l2_av1_tile_info { + u_int8_t flags; + u_int8_t context_update_tile_id; + u_int8_t tile_cols; + u_int8_t tile_rows; + u_int32_t mi_col_starts[V4L2_AV1_MAX_TILE_COLS + 1]; + u_int32_t mi_row_starts[V4L2_AV1_MAX_TILE_ROWS + 1]; + u_int32_t width_in_sbs_minus_1[V4L2_AV1_MAX_TILE_COLS]; + u_int32_t height_in_sbs_minus_1[V4L2_AV1_MAX_TILE_ROWS]; + u_int8_t tile_size_bytes; + u_int8_t reserved[3]; +}; + +/** + * enum v4l2_av1_frame_type - AV1 Frame Type + * + * @V4L2_AV1_KEY_FRAME: Key frame + * @V4L2_AV1_INTER_FRAME: Inter frame + * @V4L2_AV1_INTRA_ONLY_FRAME: Intra-only frame + * @V4L2_AV1_SWITCH_FRAME: Switch frame + */ +enum v4l2_av1_frame_type { + V4L2_AV1_KEY_FRAME = 0, + V4L2_AV1_INTER_FRAME = 1, + V4L2_AV1_INTRA_ONLY_FRAME = 2, + V4L2_AV1_SWITCH_FRAME = 3 +}; + +/** + * enum v4l2_av1_interpolation_filter - AV1 interpolation filter types + * + * @V4L2_AV1_INTERPOLATION_FILTER_EIGHTTAP: eight tap filter + * @V4L2_AV1_INTERPOLATION_FILTER_EIGHTTAP_SMOOTH: eight tap smooth filter + * @V4L2_AV1_INTERPOLATION_FILTER_EIGHTTAP_SHARP: eight tap sharp filter + * @V4L2_AV1_INTERPOLATION_FILTER_BILINEAR: bilinear filter + * @V4L2_AV1_INTERPOLATION_FILTER_SWITCHABLE: filter selection is signaled at + * the block level + * + * See section 6.8.9 "Interpolation filter semantics" of the AV1 specification + * for more details. + */ +enum v4l2_av1_interpolation_filter { + V4L2_AV1_INTERPOLATION_FILTER_EIGHTTAP = 0, + V4L2_AV1_INTERPOLATION_FILTER_EIGHTTAP_SMOOTH = 1, + V4L2_AV1_INTERPOLATION_FILTER_EIGHTTAP_SHARP = 2, + V4L2_AV1_INTERPOLATION_FILTER_BILINEAR = 3, + V4L2_AV1_INTERPOLATION_FILTER_SWITCHABLE = 4, +}; + +/** + * enum v4l2_av1_tx_mode - AV1 Tx mode as described in section 6.8.21 "TX mode + * semantics" of the AV1 specification. + * @V4L2_AV1_TX_MODE_ONLY_4X4: the inverse transform will use only 4x4 + * transforms + * @V4L2_AV1_TX_MODE_LARGEST: the inverse transform will use the largest + * transform size that fits inside the block + * @V4L2_AV1_TX_MODE_SELECT: the choice of transform size is specified + * explicitly for each block. + */ +enum v4l2_av1_tx_mode { + V4L2_AV1_TX_MODE_ONLY_4X4 = 0, + V4L2_AV1_TX_MODE_LARGEST = 1, + V4L2_AV1_TX_MODE_SELECT = 2 +}; + +#define V4L2_AV1_FRAME_FLAG_SHOW_FRAME 0x00000001 +#define V4L2_AV1_FRAME_FLAG_SHOWABLE_FRAME 0x00000002 +#define V4L2_AV1_FRAME_FLAG_ERROR_RESILIENT_MODE 0x00000004 +#define V4L2_AV1_FRAME_FLAG_DISABLE_CDF_UPDATE 0x00000008 +#define V4L2_AV1_FRAME_FLAG_ALLOW_SCREEN_CONTENT_TOOLS 0x00000010 +#define V4L2_AV1_FRAME_FLAG_FORCE_INTEGER_MV 0x00000020 +#define V4L2_AV1_FRAME_FLAG_ALLOW_INTRABC 0x00000040 +#define V4L2_AV1_FRAME_FLAG_USE_SUPERRES 0x00000080 +#define V4L2_AV1_FRAME_FLAG_ALLOW_HIGH_PRECISION_MV 0x00000100 +#define V4L2_AV1_FRAME_FLAG_IS_MOTION_MODE_SWITCHABLE 0x00000200 +#define V4L2_AV1_FRAME_FLAG_USE_REF_FRAME_MVS 0x00000400 +#define V4L2_AV1_FRAME_FLAG_DISABLE_FRAME_END_UPDATE_CDF 0x00000800 +#define V4L2_AV1_FRAME_FLAG_ALLOW_WARPED_MOTION 0x00001000 +#define V4L2_AV1_FRAME_FLAG_REFERENCE_SELECT 0x00002000 +#define V4L2_AV1_FRAME_FLAG_REDUCED_TX_SET 0x00004000 +#define V4L2_AV1_FRAME_FLAG_SKIP_MODE_ALLOWED 0x00008000 +#define V4L2_AV1_FRAME_FLAG_SKIP_MODE_PRESENT 0x00010000 +#define V4L2_AV1_FRAME_FLAG_FRAME_SIZE_OVERRIDE 0x00020000 +#define V4L2_AV1_FRAME_FLAG_BUFFER_REMOVAL_TIME_PRESENT 0x00040000 +#define V4L2_AV1_FRAME_FLAG_FRAME_REFS_SHORT_SIGNALING 0x00080000 + +#define V4L2_CID_STATELESS_AV1_FRAME (V4L2_CID_CODEC_STATELESS_BASE + 502) +/** + * struct v4l2_ctrl_av1_frame - Represents an AV1 Frame Header OBU. + * + * @tile_info: tile info + * @quantization: quantization params + * @segmentation: segmentation params + * @superres_denom: the denominator for the upscaling ratio. + * @loop_filter: loop filter params + * @cdef: cdef params + * @skip_mode_frame: specifies the frames to use for compound prediction when + * skip_mode is equal to 1. + * @primary_ref_frame: specifies which reference frame contains the CDF values + * and other state that should be loaded at the start of the frame. + * @loop_restoration: loop restoration params + * @global_motion: global motion params + * @flags: see V4L2_AV1_FRAME_FLAG_{} + * @frame_type: specifies the AV1 frame type + * @order_hint: specifies OrderHintBits least significant bits of the expected + * output order for this frame. + * @upscaled_width: the upscaled width. + * @interpolation_filter: specifies the filter selection used for performing + * inter prediction. + * @tx_mode: specifies how the transform size is determined. + * @frame_width_minus_1: add 1 to get the frame's width. + * @frame_height_minus_1: add 1 to get the frame's height + * @render_width_minus_1: add 1 to get the render width of the frame in luma + * samples. + * @render_height_minus_1: add 1 to get the render height of the frame in luma + * samples. + * @current_frame_id: specifies the frame id number for the current frame. Frame + * id numbers are additional information that do not affect the decoding + * process, but provide decoders with a way of detecting missing reference + * frames so that appropriate action can be taken. + * @buffer_removal_time: specifies the frame removal time in units of DecCT clock + * ticks counted from the removal time of the last random access point for + * operating point opNum. + * @reserved: padding field. Should be zeroed by applications. + * @order_hints: specifies the expected output order hint for each reference + * frame. This field corresponds to the OrderHints variable from the + * specification (section 5.9.2 "Uncompressed header syntax"). As such, this is + * only used for non-intra frames and ignored otherwise. order_hints[0] is + * always ignored. + * @reference_frame_ts: the V4L2 timestamp of the reference frame slots. + * @ref_frame_idx: used to index into @reference_frame_ts when decoding + * inter-frames. The meaning of this array is the same as in the specification. + * The timestamp refers to the timestamp field in struct v4l2_buffer. Use + * v4l2_timeval_to_ns() to convert the struct timeval to a u_int64_t. + * @refresh_frame_flags: contains a bitmask that specifies which reference frame + * slots will be updated with the current frame after it is decoded. + */ +struct v4l2_ctrl_av1_frame { + struct v4l2_av1_tile_info tile_info; + struct v4l2_av1_quantization quantization; + u_int8_t superres_denom; + struct v4l2_av1_segmentation segmentation; + struct v4l2_av1_loop_filter loop_filter; + struct v4l2_av1_cdef cdef; + u_int8_t skip_mode_frame[2]; + u_int8_t primary_ref_frame; + struct v4l2_av1_loop_restoration loop_restoration; + struct v4l2_av1_global_motion global_motion; + u_int32_t flags; + enum v4l2_av1_frame_type frame_type; + u_int32_t order_hint; + u_int32_t upscaled_width; + enum v4l2_av1_interpolation_filter interpolation_filter; + enum v4l2_av1_tx_mode tx_mode; + u_int32_t frame_width_minus_1; + u_int32_t frame_height_minus_1; + u_int16_t render_width_minus_1; + u_int16_t render_height_minus_1; + + u_int32_t current_frame_id; + u_int32_t buffer_removal_time[V4L2_AV1_MAX_OPERATING_POINTS]; + u_int8_t reserved[4]; + u_int32_t order_hints[V4L2_AV1_TOTAL_REFS_PER_FRAME]; + u_int64_t reference_frame_ts[V4L2_AV1_TOTAL_REFS_PER_FRAME]; + int8_t ref_frame_idx[V4L2_AV1_REFS_PER_FRAME]; + u_int8_t refresh_frame_flags; +}; + +#define V4L2_AV1_FILM_GRAIN_FLAG_APPLY_GRAIN 0x1 +#define V4L2_AV1_FILM_GRAIN_FLAG_UPDATE_GRAIN 0x2 +#define V4L2_AV1_FILM_GRAIN_FLAG_CHROMA_SCALING_FROM_LUMA 0x4 +#define V4L2_AV1_FILM_GRAIN_FLAG_OVERLAP 0x8 +#define V4L2_AV1_FILM_GRAIN_FLAG_CLIP_TO_RESTRICTED_RANGE 0x10 + +#define V4L2_CID_STATELESS_AV1_FILM_GRAIN (V4L2_CID_CODEC_STATELESS_BASE + 505) +/** + * struct v4l2_ctrl_av1_film_grain - AV1 Film Grain parameters. + * + * Film grain parameters as specified by section 6.8.20 of the AV1 Specification. + * + * @flags: see V4L2_AV1_FILM_GRAIN_{}. + * @cr_mult: represents a multiplier for the cr component used in derivation of + * the input index to the cr component scaling function. + * @grain_seed: specifies the starting value for the pseudo-random numbers used + * during film grain synthesis. + * @film_grain_params_ref_idx: indicates which reference frame contains the + * film grain parameters to be used for this frame. + * @num_y_points: specifies the number of points for the piece-wise linear + * scaling function of the luma component. + * @point_y_value: represents the x (luma value) coordinate for the i-th point + * of the piecewise linear scaling function for luma component. The values are + * signaled on the scale of 0..255. In case of 10 bit video, these values + * correspond to luma values divided by 4. In case of 12 bit video, these values + * correspond to luma values divided by 16. + * @point_y_scaling: represents the scaling (output) value for the i-th point + * of the piecewise linear scaling function for luma component. + * @num_cb_points: specifies the number of points for the piece-wise linear + * scaling function of the cb component. + * @point_cb_value: represents the x coordinate for the i-th point of the + * piece-wise linear scaling function for cb component. The values are signaled + * on the scale of 0..255. + * @point_cb_scaling: represents the scaling (output) value for the i-th point + * of the piecewise linear scaling function for cb component. + * @num_cr_points: specifies represents the number of points for the piece-wise + * linear scaling function of the cr component. + * @point_cr_value: represents the x coordinate for the i-th point of the + * piece-wise linear scaling function for cr component. The values are signaled + * on the scale of 0..255. + * @point_cr_scaling: represents the scaling (output) value for the i-th point + * of the piecewise linear scaling function for cr component. + * @grain_scaling_minus_8: represents the shift – 8 applied to the values of the + * chroma component. The grain_scaling_minus_8 can take values of 0..3 and + * determines the range and quantization step of the standard deviation of film + * grain. + * @ar_coeff_lag: specifies the number of auto-regressive coefficients for luma + * and chroma. + * @ar_coeffs_y_plus_128: specifies auto-regressive coefficients used for the Y + * plane. + * @ar_coeffs_cb_plus_128: specifies auto-regressive coefficients used for the U + * plane. + * @ar_coeffs_cr_plus_128: specifies auto-regressive coefficients used for the V + * plane. + * @ar_coeff_shift_minus_6: specifies the range of the auto-regressive + * coefficients. Values of 0, 1, 2, and 3 correspond to the ranges for + * auto-regressive coefficients of [-2, 2), [-1, 1), [-0.5, 0.5) and [-0.25, + * 0.25) respectively. + * @grain_scale_shift: specifies how much the Gaussian random numbers should be + * scaled down during the grain synthesis process. + * @cb_mult: represents a multiplier for the cb component used in derivation of + * the input index to the cb component scaling function. + * @cb_luma_mult: represents a multiplier for the average luma component used in + * derivation of the input index to the cb component scaling function. + * @cr_luma_mult: represents a multiplier for the average luma component used in + * derivation of the input index to the cr component scaling function. + * @cb_offset: represents an offset used in derivation of the input index to the + * cb component scaling function. + * @cr_offset: represents an offset used in derivation of the input index to the + * cr component scaling function. + * @reserved: padding field. Should be zeroed by applications. + */ +struct v4l2_ctrl_av1_film_grain { + u_int8_t flags; + u_int8_t cr_mult; + u_int16_t grain_seed; + u_int8_t film_grain_params_ref_idx; + u_int8_t num_y_points; + u_int8_t point_y_value[V4L2_AV1_MAX_NUM_Y_POINTS]; + u_int8_t point_y_scaling[V4L2_AV1_MAX_NUM_Y_POINTS]; + u_int8_t num_cb_points; + u_int8_t point_cb_value[V4L2_AV1_MAX_NUM_CB_POINTS]; + u_int8_t point_cb_scaling[V4L2_AV1_MAX_NUM_CB_POINTS]; + u_int8_t num_cr_points; + u_int8_t point_cr_value[V4L2_AV1_MAX_NUM_CR_POINTS]; + u_int8_t point_cr_scaling[V4L2_AV1_MAX_NUM_CR_POINTS]; + u_int8_t grain_scaling_minus_8; + u_int8_t ar_coeff_lag; + u_int8_t ar_coeffs_y_plus_128[V4L2_AV1_AR_COEFFS_SIZE]; + u_int8_t ar_coeffs_cb_plus_128[V4L2_AV1_AR_COEFFS_SIZE]; + u_int8_t ar_coeffs_cr_plus_128[V4L2_AV1_AR_COEFFS_SIZE]; + u_int8_t ar_coeff_shift_minus_6; + u_int8_t grain_scale_shift; + u_int8_t cb_mult; + u_int8_t cb_luma_mult; + u_int8_t cr_luma_mult; + u_int16_t cb_offset; + u_int16_t cr_offset; + u_int8_t reserved[4]; +}; + +/* MPEG-compression definitions kept for backwards compatibility */ +#define V4L2_CTRL_CLASS_MPEG V4L2_CTRL_CLASS_CODEC +#define V4L2_CID_MPEG_CLASS V4L2_CID_CODEC_CLASS +#define V4L2_CID_MPEG_BASE V4L2_CID_CODEC_BASE +#define V4L2_CID_MPEG_CX2341X_BASE V4L2_CID_CODEC_CX2341X_BASE +#define V4L2_CID_MPEG_MFC51_BASE V4L2_CID_CODEC_MFC51_BASE +/* + * End of v4l2-controls.h + */ + +#ifndef __user +#define __user +#endif + +/* + * Common stuff for both V4L1 and V4L2 + * Moved from videodev.h + */ +#define VIDEO_MAX_FRAME 32 +#define VIDEO_MAX_PLANES 8 + +/* + * M I S C E L L A N E O U S + */ + +/* Four-character-code (FOURCC) */ +#define v4l2_fourcc(a, b, c, d)\ + ((u_int32_t)(a) | ((u_int32_t)(b) << 8) | ((u_int32_t)(c) << 16) | ((u_int32_t)(d) << 24)) +#define v4l2_fourcc_be(a, b, c, d) (v4l2_fourcc(a, b, c, d) | (1U << 31)) + +/* + * E N U M S + */ +enum v4l2_field { + V4L2_FIELD_ANY = 0, /* driver can choose from none, + top, bottom, interlaced + depending on whatever it thinks + is approximate ... */ + V4L2_FIELD_NONE = 1, /* this device has no fields ... */ + V4L2_FIELD_TOP = 2, /* top field only */ + V4L2_FIELD_BOTTOM = 3, /* bottom field only */ + V4L2_FIELD_INTERLACED = 4, /* both fields interlaced */ + V4L2_FIELD_SEQ_TB = 5, /* both fields sequential into one + buffer, top-bottom order */ + V4L2_FIELD_SEQ_BT = 6, /* same as above + bottom-top order */ + V4L2_FIELD_ALTERNATE = 7, /* both fields alternating into + separate buffers */ + V4L2_FIELD_INTERLACED_TB = 8, /* both fields interlaced, top field + first and the top field is + transmitted first */ + V4L2_FIELD_INTERLACED_BT = 9, /* both fields interlaced, top field + first and the bottom field is + transmitted first */ +}; +#define V4L2_FIELD_HAS_TOP(field) \ + ((field) == V4L2_FIELD_TOP ||\ + (field) == V4L2_FIELD_INTERLACED ||\ + (field) == V4L2_FIELD_INTERLACED_TB ||\ + (field) == V4L2_FIELD_INTERLACED_BT ||\ + (field) == V4L2_FIELD_SEQ_TB ||\ + (field) == V4L2_FIELD_SEQ_BT) +#define V4L2_FIELD_HAS_BOTTOM(field) \ + ((field) == V4L2_FIELD_BOTTOM ||\ + (field) == V4L2_FIELD_INTERLACED ||\ + (field) == V4L2_FIELD_INTERLACED_TB ||\ + (field) == V4L2_FIELD_INTERLACED_BT ||\ + (field) == V4L2_FIELD_SEQ_TB ||\ + (field) == V4L2_FIELD_SEQ_BT) +#define V4L2_FIELD_HAS_BOTH(field) \ + ((field) == V4L2_FIELD_INTERLACED ||\ + (field) == V4L2_FIELD_INTERLACED_TB ||\ + (field) == V4L2_FIELD_INTERLACED_BT ||\ + (field) == V4L2_FIELD_SEQ_TB ||\ + (field) == V4L2_FIELD_SEQ_BT) +#define V4L2_FIELD_HAS_T_OR_B(field) \ + ((field) == V4L2_FIELD_BOTTOM ||\ + (field) == V4L2_FIELD_TOP ||\ + (field) == V4L2_FIELD_ALTERNATE) +#define V4L2_FIELD_IS_INTERLACED(field) \ + ((field) == V4L2_FIELD_INTERLACED ||\ + (field) == V4L2_FIELD_INTERLACED_TB ||\ + (field) == V4L2_FIELD_INTERLACED_BT) +#define V4L2_FIELD_IS_SEQUENTIAL(field) \ + ((field) == V4L2_FIELD_SEQ_TB ||\ + (field) == V4L2_FIELD_SEQ_BT) + +enum v4l2_buf_type { + V4L2_BUF_TYPE_VIDEO_CAPTURE = 1, + V4L2_BUF_TYPE_VIDEO_OUTPUT = 2, + V4L2_BUF_TYPE_VIDEO_OVERLAY = 3, + V4L2_BUF_TYPE_VBI_CAPTURE = 4, + V4L2_BUF_TYPE_VBI_OUTPUT = 5, + V4L2_BUF_TYPE_SLICED_VBI_CAPTURE = 6, + V4L2_BUF_TYPE_SLICED_VBI_OUTPUT = 7, + V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY = 8, + V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE = 9, + V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE = 10, + V4L2_BUF_TYPE_SDR_CAPTURE = 11, + V4L2_BUF_TYPE_SDR_OUTPUT = 12, + V4L2_BUF_TYPE_META_CAPTURE = 13, + V4L2_BUF_TYPE_META_OUTPUT = 14, + /* + * Note: V4L2_TYPE_IS_VALID and V4L2_TYPE_IS_OUTPUT must + * be updated if a new type is added. + */ + /* Deprecated, do not use */ + V4L2_BUF_TYPE_PRIVATE = 0x80, +}; + +#define V4L2_TYPE_IS_VALID(type) \ + ((type) >= V4L2_BUF_TYPE_VIDEO_CAPTURE &&\ + (type) <= V4L2_BUF_TYPE_META_OUTPUT) + +#define V4L2_TYPE_IS_MULTIPLANAR(type) \ + ((type) == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE \ + || (type) == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) + +#define V4L2_TYPE_IS_OUTPUT(type) \ + ((type) == V4L2_BUF_TYPE_VIDEO_OUTPUT \ + || (type) == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE \ + || (type) == V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY \ + || (type) == V4L2_BUF_TYPE_VBI_OUTPUT \ + || (type) == V4L2_BUF_TYPE_SLICED_VBI_OUTPUT \ + || (type) == V4L2_BUF_TYPE_SDR_OUTPUT \ + || (type) == V4L2_BUF_TYPE_META_OUTPUT) + +#define V4L2_TYPE_IS_CAPTURE(type) \ + (V4L2_TYPE_IS_VALID(type) && !V4L2_TYPE_IS_OUTPUT(type)) + +enum v4l2_tuner_type { + V4L2_TUNER_RADIO = 1, + V4L2_TUNER_ANALOG_TV = 2, + V4L2_TUNER_DIGITAL_TV = 3, + V4L2_TUNER_SDR = 4, + V4L2_TUNER_RF = 5, +}; + +/* Deprecated, do not use */ +#define V4L2_TUNER_ADC V4L2_TUNER_SDR + +enum v4l2_memory { + V4L2_MEMORY_MMAP = 1, + V4L2_MEMORY_USERPTR = 2, + V4L2_MEMORY_OVERLAY = 3, + V4L2_MEMORY_DMABUF = 4, +}; + +/* see also http://vektor.theorem.ca/graphics/ycbcr/ */ +enum v4l2_colorspace { + /* + * Default colorspace, i.e. let the driver figure it out. + * Can only be used with video capture. + */ + V4L2_COLORSPACE_DEFAULT = 0, + + /* SMPTE 170M: used for broadcast NTSC/PAL SDTV */ + V4L2_COLORSPACE_SMPTE170M = 1, + + /* Obsolete pre-1998 SMPTE 240M HDTV standard, superseded by Rec 709 */ + V4L2_COLORSPACE_SMPTE240M = 2, + + /* Rec.709: used for HDTV */ + V4L2_COLORSPACE_REC709 = 3, + + /* + * Deprecated, do not use. No driver will ever return this. This was + * based on a misunderstanding of the bt878 datasheet. + */ + V4L2_COLORSPACE_BT878 = 4, + + /* + * NTSC 1953 colorspace. This only makes sense when dealing with + * really, really old NTSC recordings. Superseded by SMPTE 170M. + */ + V4L2_COLORSPACE_470_SYSTEM_M = 5, + + /* + * EBU Tech 3213 PAL/SECAM colorspace. + */ + V4L2_COLORSPACE_470_SYSTEM_BG = 6, + + /* + * Effectively shorthand for V4L2_COLORSPACE_SRGB, V4L2_YCBCR_ENC_601 + * and V4L2_QUANTIZATION_FULL_RANGE. To be used for (Motion-)JPEG. + */ + V4L2_COLORSPACE_JPEG = 7, + + /* For RGB colorspaces such as produces by most webcams. */ + V4L2_COLORSPACE_SRGB = 8, + + /* opRGB colorspace */ + V4L2_COLORSPACE_OPRGB = 9, + + /* BT.2020 colorspace, used for UHDTV. */ + V4L2_COLORSPACE_BT2020 = 10, + + /* Raw colorspace: for RAW unprocessed images */ + V4L2_COLORSPACE_RAW = 11, + + /* DCI-P3 colorspace, used by cinema projectors */ + V4L2_COLORSPACE_DCI_P3 = 12, +}; + +/* + * Determine how COLORSPACE_DEFAULT should map to a proper colorspace. + * This depends on whether this is a SDTV image (use SMPTE 170M), an + * HDTV image (use Rec. 709), or something else (use sRGB). + */ +#define V4L2_MAP_COLORSPACE_DEFAULT(is_sdtv, is_hdtv) \ + ((is_sdtv) ? V4L2_COLORSPACE_SMPTE170M : \ + ((is_hdtv) ? V4L2_COLORSPACE_REC709 : V4L2_COLORSPACE_SRGB)) + +enum v4l2_xfer_func { + /* + * Mapping of V4L2_XFER_FUNC_DEFAULT to actual transfer functions + * for the various colorspaces: + * + * V4L2_COLORSPACE_SMPTE170M, V4L2_COLORSPACE_470_SYSTEM_M, + * V4L2_COLORSPACE_470_SYSTEM_BG, V4L2_COLORSPACE_REC709 and + * V4L2_COLORSPACE_BT2020: V4L2_XFER_FUNC_709 + * + * V4L2_COLORSPACE_SRGB, V4L2_COLORSPACE_JPEG: V4L2_XFER_FUNC_SRGB + * + * V4L2_COLORSPACE_OPRGB: V4L2_XFER_FUNC_OPRGB + * + * V4L2_COLORSPACE_SMPTE240M: V4L2_XFER_FUNC_SMPTE240M + * + * V4L2_COLORSPACE_RAW: V4L2_XFER_FUNC_NONE + * + * V4L2_COLORSPACE_DCI_P3: V4L2_XFER_FUNC_DCI_P3 + */ + V4L2_XFER_FUNC_DEFAULT = 0, + V4L2_XFER_FUNC_709 = 1, + V4L2_XFER_FUNC_SRGB = 2, + V4L2_XFER_FUNC_OPRGB = 3, + V4L2_XFER_FUNC_SMPTE240M = 4, + V4L2_XFER_FUNC_NONE = 5, + V4L2_XFER_FUNC_DCI_P3 = 6, + V4L2_XFER_FUNC_SMPTE2084 = 7, +}; + +/* + * Determine how XFER_FUNC_DEFAULT should map to a proper transfer function. + * This depends on the colorspace. + */ +#define V4L2_MAP_XFER_FUNC_DEFAULT(colsp) \ + ((colsp) == V4L2_COLORSPACE_OPRGB ? V4L2_XFER_FUNC_OPRGB : \ + ((colsp) == V4L2_COLORSPACE_SMPTE240M ? V4L2_XFER_FUNC_SMPTE240M : \ + ((colsp) == V4L2_COLORSPACE_DCI_P3 ? V4L2_XFER_FUNC_DCI_P3 : \ + ((colsp) == V4L2_COLORSPACE_RAW ? V4L2_XFER_FUNC_NONE : \ + ((colsp) == V4L2_COLORSPACE_SRGB || (colsp) == V4L2_COLORSPACE_JPEG ? \ + V4L2_XFER_FUNC_SRGB : V4L2_XFER_FUNC_709))))) + +enum v4l2_ycbcr_encoding { + /* + * Mapping of V4L2_YCBCR_ENC_DEFAULT to actual encodings for the + * various colorspaces: + * + * V4L2_COLORSPACE_SMPTE170M, V4L2_COLORSPACE_470_SYSTEM_M, + * V4L2_COLORSPACE_470_SYSTEM_BG, V4L2_COLORSPACE_SRGB, + * V4L2_COLORSPACE_OPRGB and V4L2_COLORSPACE_JPEG: V4L2_YCBCR_ENC_601 + * + * V4L2_COLORSPACE_REC709 and V4L2_COLORSPACE_DCI_P3: V4L2_YCBCR_ENC_709 + * + * V4L2_COLORSPACE_BT2020: V4L2_YCBCR_ENC_BT2020 + * + * V4L2_COLORSPACE_SMPTE240M: V4L2_YCBCR_ENC_SMPTE240M + */ + V4L2_YCBCR_ENC_DEFAULT = 0, + + /* ITU-R 601 -- SDTV */ + V4L2_YCBCR_ENC_601 = 1, + + /* Rec. 709 -- HDTV */ + V4L2_YCBCR_ENC_709 = 2, + + /* ITU-R 601/EN 61966-2-4 Extended Gamut -- SDTV */ + V4L2_YCBCR_ENC_XV601 = 3, + + /* Rec. 709/EN 61966-2-4 Extended Gamut -- HDTV */ + V4L2_YCBCR_ENC_XV709 = 4, + + /* + * sYCC (Y'CbCr encoding of sRGB), identical to ENC_601. It was added + * originally due to a misunderstanding of the sYCC standard. It should + * not be used, instead use V4L2_YCBCR_ENC_601. + */ + V4L2_YCBCR_ENC_SYCC = 5, + + /* BT.2020 Non-constant Luminance Y'CbCr */ + V4L2_YCBCR_ENC_BT2020 = 6, + + /* BT.2020 Constant Luminance Y'CbcCrc */ + V4L2_YCBCR_ENC_BT2020_CONST_LUM = 7, + + /* SMPTE 240M -- Obsolete HDTV */ + V4L2_YCBCR_ENC_SMPTE240M = 8, +}; + +/* + * enum v4l2_hsv_encoding values should not collide with the ones from + * enum v4l2_ycbcr_encoding. + */ +enum v4l2_hsv_encoding { + + /* Hue mapped to 0 - 179 */ + V4L2_HSV_ENC_180 = 128, + + /* Hue mapped to 0-255 */ + V4L2_HSV_ENC_256 = 129, +}; + +/* + * Determine how YCBCR_ENC_DEFAULT should map to a proper Y'CbCr encoding. + * This depends on the colorspace. + */ +#define V4L2_MAP_YCBCR_ENC_DEFAULT(colsp) \ + (((colsp) == V4L2_COLORSPACE_REC709 || \ + (colsp) == V4L2_COLORSPACE_DCI_P3) ? V4L2_YCBCR_ENC_709 : \ + ((colsp) == V4L2_COLORSPACE_BT2020 ? V4L2_YCBCR_ENC_BT2020 : \ + ((colsp) == V4L2_COLORSPACE_SMPTE240M ? V4L2_YCBCR_ENC_SMPTE240M : \ + V4L2_YCBCR_ENC_601))) + +enum v4l2_quantization { + /* + * The default for R'G'B' quantization is always full range. + * For Y'CbCr the quantization is always limited range, except + * for COLORSPACE_JPEG: this is full range. + */ + V4L2_QUANTIZATION_DEFAULT = 0, + V4L2_QUANTIZATION_FULL_RANGE = 1, + V4L2_QUANTIZATION_LIM_RANGE = 2, +}; + +/* + * Determine how QUANTIZATION_DEFAULT should map to a proper quantization. + * This depends on whether the image is RGB or not, the colorspace. + * The Y'CbCr encoding is not used anymore, but is still there for backwards + * compatibility. + */ +#define V4L2_MAP_QUANTIZATION_DEFAULT(is_rgb_or_hsv, colsp, ycbcr_enc) \ + (((is_rgb_or_hsv) || (colsp) == V4L2_COLORSPACE_JPEG) ? \ + V4L2_QUANTIZATION_FULL_RANGE : V4L2_QUANTIZATION_LIM_RANGE) + +/* + * Deprecated names for opRGB colorspace (IEC 61966-2-5) + * + * WARNING: Please don't use these deprecated defines in your code, as + * there is a chance we have to remove them in the future. + */ +#define V4L2_COLORSPACE_ADOBERGB V4L2_COLORSPACE_OPRGB +#define V4L2_XFER_FUNC_ADOBERGB V4L2_XFER_FUNC_OPRGB + +enum v4l2_priority { + V4L2_PRIORITY_UNSET = 0, /* not initialized */ + V4L2_PRIORITY_BACKGROUND = 1, + V4L2_PRIORITY_INTERACTIVE = 2, + V4L2_PRIORITY_RECORD = 3, + V4L2_PRIORITY_DEFAULT = V4L2_PRIORITY_INTERACTIVE, +}; + +struct v4l2_rect { + int32_t left; + int32_t top; + u_int32_t width; + u_int32_t height; +}; + +struct v4l2_fract { + u_int32_t numerator; + u_int32_t denominator; +}; + +struct v4l2_area { + u_int32_t width; + u_int32_t height; +}; + +/** + * struct v4l2_capability - Describes V4L2 device caps returned by VIDIOC_QUERYCAP + * + * @driver: name of the driver module (e.g. "bttv") + * @card: name of the card (e.g. "Hauppauge WinTV") + * @bus_info: name of the bus (e.g. "PCI:" + pci_name(pci_dev) ) + * @version: KERNEL_VERSION + * @capabilities: capabilities of the physical device as a whole + * @device_caps: capabilities accessed via this particular device (node) + * @reserved: reserved fields for future extensions + */ +struct v4l2_capability { + u_int8_t driver[16]; + u_int8_t card[32]; + u_int8_t bus_info[32]; + u_int32_t version; + u_int32_t capabilities; + u_int32_t device_caps; + u_int32_t reserved[3]; +}; + +/* Values for 'capabilities' field */ +#define V4L2_CAP_VIDEO_CAPTURE 0x00000001 /* Is a video capture device */ +#define V4L2_CAP_VIDEO_OUTPUT 0x00000002 /* Is a video output device */ +#define V4L2_CAP_VIDEO_OVERLAY 0x00000004 /* Can do video overlay */ +#define V4L2_CAP_VBI_CAPTURE 0x00000010 /* Is a raw VBI capture device */ +#define V4L2_CAP_VBI_OUTPUT 0x00000020 /* Is a raw VBI output device */ +#define V4L2_CAP_SLICED_VBI_CAPTURE 0x00000040 /* Is a sliced VBI capture device */ +#define V4L2_CAP_SLICED_VBI_OUTPUT 0x00000080 /* Is a sliced VBI output device */ +#define V4L2_CAP_RDS_CAPTURE 0x00000100 /* RDS data capture */ +#define V4L2_CAP_VIDEO_OUTPUT_OVERLAY 0x00000200 /* Can do video output overlay */ +#define V4L2_CAP_HW_FREQ_SEEK 0x00000400 /* Can do hardware frequency seek */ +#define V4L2_CAP_RDS_OUTPUT 0x00000800 /* Is an RDS encoder */ + +/* Is a video capture device that supports multiplanar formats */ +#define V4L2_CAP_VIDEO_CAPTURE_MPLANE 0x00001000 +/* Is a video output device that supports multiplanar formats */ +#define V4L2_CAP_VIDEO_OUTPUT_MPLANE 0x00002000 +/* Is a video mem-to-mem device that supports multiplanar formats */ +#define V4L2_CAP_VIDEO_M2M_MPLANE 0x00004000 +/* Is a video mem-to-mem device */ +#define V4L2_CAP_VIDEO_M2M 0x00008000 + +#define V4L2_CAP_TUNER 0x00010000 /* has a tuner */ +#define V4L2_CAP_AUDIO 0x00020000 /* has audio support */ +#define V4L2_CAP_RADIO 0x00040000 /* is a radio device */ +#define V4L2_CAP_MODULATOR 0x00080000 /* has a modulator */ + +#define V4L2_CAP_SDR_CAPTURE 0x00100000 /* Is a SDR capture device */ +#define V4L2_CAP_EXT_PIX_FORMAT 0x00200000 /* Supports the extended pixel format */ +#define V4L2_CAP_SDR_OUTPUT 0x00400000 /* Is a SDR output device */ +#define V4L2_CAP_META_CAPTURE 0x00800000 /* Is a metadata capture device */ + +#define V4L2_CAP_READWRITE 0x01000000 /* read/write systemcalls */ +#define V4L2_CAP_EDID 0x02000000 /* Is an EDID-only device */ +#define V4L2_CAP_STREAMING 0x04000000 /* streaming I/O ioctls */ +#define V4L2_CAP_META_OUTPUT 0x08000000 /* Is a metadata output device */ + +#define V4L2_CAP_TOUCH 0x10000000 /* Is a touch device */ + +#define V4L2_CAP_IO_MC 0x20000000 /* Is input/output controlled by the media controller */ + +#define V4L2_CAP_DEVICE_CAPS 0x80000000 /* sets device capabilities field */ + +/* + * V I D E O I M A G E F O R M A T + */ +struct v4l2_pix_format { + u_int32_t width; + u_int32_t height; + u_int32_t pixelformat; + u_int32_t field; /* enum v4l2_field */ + u_int32_t bytesperline; /* for padding, zero if unused */ + u_int32_t sizeimage; + u_int32_t colorspace; /* enum v4l2_colorspace */ + u_int32_t priv; /* private data, depends on pixelformat */ + u_int32_t flags; /* format flags (V4L2_PIX_FMT_FLAG_*) */ + union { + /* enum v4l2_ycbcr_encoding */ + u_int32_t ycbcr_enc; + /* enum v4l2_hsv_encoding */ + u_int32_t hsv_enc; + }; + u_int32_t quantization; /* enum v4l2_quantization */ + u_int32_t xfer_func; /* enum v4l2_xfer_func */ +}; + +/* Pixel format FOURCC depth Description */ + +/* RGB formats (1 or 2 bytes per pixel) */ +#define V4L2_PIX_FMT_RGB332 v4l2_fourcc('R', 'G', 'B', '1') /* 8 RGB-3-3-2 */ +#define V4L2_PIX_FMT_RGB444 v4l2_fourcc('R', '4', '4', '4') /* 16 xxxxrrrr ggggbbbb */ +#define V4L2_PIX_FMT_ARGB444 v4l2_fourcc('A', 'R', '1', '2') /* 16 aaaarrrr ggggbbbb */ +#define V4L2_PIX_FMT_XRGB444 v4l2_fourcc('X', 'R', '1', '2') /* 16 xxxxrrrr ggggbbbb */ +#define V4L2_PIX_FMT_RGBA444 v4l2_fourcc('R', 'A', '1', '2') /* 16 rrrrgggg bbbbaaaa */ +#define V4L2_PIX_FMT_RGBX444 v4l2_fourcc('R', 'X', '1', '2') /* 16 rrrrgggg bbbbxxxx */ +#define V4L2_PIX_FMT_ABGR444 v4l2_fourcc('A', 'B', '1', '2') /* 16 aaaabbbb ggggrrrr */ +#define V4L2_PIX_FMT_XBGR444 v4l2_fourcc('X', 'B', '1', '2') /* 16 xxxxbbbb ggggrrrr */ +#define V4L2_PIX_FMT_BGRA444 v4l2_fourcc('G', 'A', '1', '2') /* 16 bbbbgggg rrrraaaa */ +#define V4L2_PIX_FMT_BGRX444 v4l2_fourcc('B', 'X', '1', '2') /* 16 bbbbgggg rrrrxxxx */ +#define V4L2_PIX_FMT_RGB555 v4l2_fourcc('R', 'G', 'B', 'O') /* 16 RGB-5-5-5 */ +#define V4L2_PIX_FMT_ARGB555 v4l2_fourcc('A', 'R', '1', '5') /* 16 ARGB-1-5-5-5 */ +#define V4L2_PIX_FMT_XRGB555 v4l2_fourcc('X', 'R', '1', '5') /* 16 XRGB-1-5-5-5 */ +#define V4L2_PIX_FMT_RGBA555 v4l2_fourcc('R', 'A', '1', '5') /* 16 RGBA-5-5-5-1 */ +#define V4L2_PIX_FMT_RGBX555 v4l2_fourcc('R', 'X', '1', '5') /* 16 RGBX-5-5-5-1 */ +#define V4L2_PIX_FMT_ABGR555 v4l2_fourcc('A', 'B', '1', '5') /* 16 ABGR-1-5-5-5 */ +#define V4L2_PIX_FMT_XBGR555 v4l2_fourcc('X', 'B', '1', '5') /* 16 XBGR-1-5-5-5 */ +#define V4L2_PIX_FMT_BGRA555 v4l2_fourcc('B', 'A', '1', '5') /* 16 BGRA-5-5-5-1 */ +#define V4L2_PIX_FMT_BGRX555 v4l2_fourcc('B', 'X', '1', '5') /* 16 BGRX-5-5-5-1 */ +#define V4L2_PIX_FMT_RGB565 v4l2_fourcc('R', 'G', 'B', 'P') /* 16 RGB-5-6-5 */ +#define V4L2_PIX_FMT_RGB555X v4l2_fourcc('R', 'G', 'B', 'Q') /* 16 RGB-5-5-5 BE */ +#define V4L2_PIX_FMT_ARGB555X v4l2_fourcc_be('A', 'R', '1', '5') /* 16 ARGB-5-5-5 BE */ +#define V4L2_PIX_FMT_XRGB555X v4l2_fourcc_be('X', 'R', '1', '5') /* 16 XRGB-5-5-5 BE */ +#define V4L2_PIX_FMT_RGB565X v4l2_fourcc('R', 'G', 'B', 'R') /* 16 RGB-5-6-5 BE */ + +/* RGB formats (3 or 4 bytes per pixel) */ +#define V4L2_PIX_FMT_BGR666 v4l2_fourcc('B', 'G', 'R', 'H') /* 18 BGR-6-6-6 */ +#define V4L2_PIX_FMT_BGR24 v4l2_fourcc('B', 'G', 'R', '3') /* 24 BGR-8-8-8 */ +#define V4L2_PIX_FMT_RGB24 v4l2_fourcc('R', 'G', 'B', '3') /* 24 RGB-8-8-8 */ +#define V4L2_PIX_FMT_BGR32 v4l2_fourcc('B', 'G', 'R', '4') /* 32 BGR-8-8-8-8 */ +#define V4L2_PIX_FMT_ABGR32 v4l2_fourcc('A', 'R', '2', '4') /* 32 BGRA-8-8-8-8 */ +#define V4L2_PIX_FMT_XBGR32 v4l2_fourcc('X', 'R', '2', '4') /* 32 BGRX-8-8-8-8 */ +#define V4L2_PIX_FMT_BGRA32 v4l2_fourcc('R', 'A', '2', '4') /* 32 ABGR-8-8-8-8 */ +#define V4L2_PIX_FMT_BGRX32 v4l2_fourcc('R', 'X', '2', '4') /* 32 XBGR-8-8-8-8 */ +#define V4L2_PIX_FMT_RGB32 v4l2_fourcc('R', 'G', 'B', '4') /* 32 RGB-8-8-8-8 */ +#define V4L2_PIX_FMT_RGBA32 v4l2_fourcc('A', 'B', '2', '4') /* 32 RGBA-8-8-8-8 */ +#define V4L2_PIX_FMT_RGBX32 v4l2_fourcc('X', 'B', '2', '4') /* 32 RGBX-8-8-8-8 */ +#define V4L2_PIX_FMT_ARGB32 v4l2_fourcc('B', 'A', '2', '4') /* 32 ARGB-8-8-8-8 */ +#define V4L2_PIX_FMT_XRGB32 v4l2_fourcc('B', 'X', '2', '4') /* 32 XRGB-8-8-8-8 */ +#define V4L2_PIX_FMT_RGBX1010102 v4l2_fourcc('R', 'X', '3', '0') /* 32 RGBX-10-10-10-2 */ +#define V4L2_PIX_FMT_RGBA1010102 v4l2_fourcc('R', 'A', '3', '0') /* 32 RGBA-10-10-10-2 */ +#define V4L2_PIX_FMT_ARGB2101010 v4l2_fourcc('A', 'R', '3', '0') /* 32 ARGB-2-10-10-10 */ + +/* RGB formats (6 or 8 bytes per pixel) */ +#define V4L2_PIX_FMT_BGR48_12 v4l2_fourcc('B', '3', '1', '2') /* 48 BGR 12-bit per component */ +#define V4L2_PIX_FMT_BGR48 v4l2_fourcc('B', 'G', 'R', '6') /* 48 BGR 16-bit per component */ +#define V4L2_PIX_FMT_RGB48 v4l2_fourcc('R', 'G', 'B', '6') /* 48 RGB 16-bit per component */ +#define V4L2_PIX_FMT_ABGR64_12 v4l2_fourcc('B', '4', '1', '2') /* 64 BGRA 12-bit per component */ + +/* Grey formats */ +#define V4L2_PIX_FMT_GREY v4l2_fourcc('G', 'R', 'E', 'Y') /* 8 Greyscale */ +#define V4L2_PIX_FMT_Y4 v4l2_fourcc('Y', '0', '4', ' ') /* 4 Greyscale */ +#define V4L2_PIX_FMT_Y6 v4l2_fourcc('Y', '0', '6', ' ') /* 6 Greyscale */ +#define V4L2_PIX_FMT_Y10 v4l2_fourcc('Y', '1', '0', ' ') /* 10 Greyscale */ +#define V4L2_PIX_FMT_Y12 v4l2_fourcc('Y', '1', '2', ' ') /* 12 Greyscale */ +#define V4L2_PIX_FMT_Y012 v4l2_fourcc('Y', '0', '1', '2') /* 12 Greyscale */ +#define V4L2_PIX_FMT_Y14 v4l2_fourcc('Y', '1', '4', ' ') /* 14 Greyscale */ +#define V4L2_PIX_FMT_Y16 v4l2_fourcc('Y', '1', '6', ' ') /* 16 Greyscale */ +#define V4L2_PIX_FMT_Y16_BE v4l2_fourcc_be('Y', '1', '6', ' ') /* 16 Greyscale BE */ + +/* Grey bit-packed formats */ +#define V4L2_PIX_FMT_Y10BPACK v4l2_fourcc('Y', '1', '0', 'B') /* 10 Greyscale bit-packed */ +#define V4L2_PIX_FMT_Y10P v4l2_fourcc('Y', '1', '0', 'P') /* 10 Greyscale, MIPI RAW10 packed */ +#define V4L2_PIX_FMT_IPU3_Y10 v4l2_fourcc('i', 'p', '3', 'y') /* IPU3 packed 10-bit greyscale */ +#define V4L2_PIX_FMT_Y12P v4l2_fourcc('Y', '1', '2', 'P') /* 12 Greyscale, MIPI RAW12 packed */ +#define V4L2_PIX_FMT_Y14P v4l2_fourcc('Y', '1', '4', 'P') /* 14 Greyscale, MIPI RAW14 packed */ + +/* Palette formats */ +#define V4L2_PIX_FMT_PAL8 v4l2_fourcc('P', 'A', 'L', '8') /* 8 8-bit palette */ + +/* Chrominance formats */ +#define V4L2_PIX_FMT_UV8 v4l2_fourcc('U', 'V', '8', ' ') /* 8 UV 4:4 */ + +/* Luminance+Chrominance formats */ +#define V4L2_PIX_FMT_YUYV v4l2_fourcc('Y', 'U', 'Y', 'V') /* 16 YUV 4:2:2 */ +#define V4L2_PIX_FMT_YYUV v4l2_fourcc('Y', 'Y', 'U', 'V') /* 16 YUV 4:2:2 */ +#define V4L2_PIX_FMT_YVYU v4l2_fourcc('Y', 'V', 'Y', 'U') /* 16 YVU 4:2:2 */ +#define V4L2_PIX_FMT_UYVY v4l2_fourcc('U', 'Y', 'V', 'Y') /* 16 YUV 4:2:2 */ +#define V4L2_PIX_FMT_VYUY v4l2_fourcc('V', 'Y', 'U', 'Y') /* 16 YUV 4:2:2 */ +#define V4L2_PIX_FMT_Y41P v4l2_fourcc('Y', '4', '1', 'P') /* 12 YUV 4:1:1 */ +#define V4L2_PIX_FMT_YUV444 v4l2_fourcc('Y', '4', '4', '4') /* 16 xxxxyyyy uuuuvvvv */ +#define V4L2_PIX_FMT_YUV555 v4l2_fourcc('Y', 'U', 'V', 'O') /* 16 YUV-5-5-5 */ +#define V4L2_PIX_FMT_YUV565 v4l2_fourcc('Y', 'U', 'V', 'P') /* 16 YUV-5-6-5 */ +#define V4L2_PIX_FMT_YUV24 v4l2_fourcc('Y', 'U', 'V', '3') /* 24 YUV-8-8-8 */ +#define V4L2_PIX_FMT_YUV32 v4l2_fourcc('Y', 'U', 'V', '4') /* 32 YUV-8-8-8-8 */ +#define V4L2_PIX_FMT_AYUV32 v4l2_fourcc('A', 'Y', 'U', 'V') /* 32 AYUV-8-8-8-8 */ +#define V4L2_PIX_FMT_XYUV32 v4l2_fourcc('X', 'Y', 'U', 'V') /* 32 XYUV-8-8-8-8 */ +#define V4L2_PIX_FMT_VUYA32 v4l2_fourcc('V', 'U', 'Y', 'A') /* 32 VUYA-8-8-8-8 */ +#define V4L2_PIX_FMT_VUYX32 v4l2_fourcc('V', 'U', 'Y', 'X') /* 32 VUYX-8-8-8-8 */ +#define V4L2_PIX_FMT_YUVA32 v4l2_fourcc('Y', 'U', 'V', 'A') /* 32 YUVA-8-8-8-8 */ +#define V4L2_PIX_FMT_YUVX32 v4l2_fourcc('Y', 'U', 'V', 'X') /* 32 YUVX-8-8-8-8 */ +#define V4L2_PIX_FMT_M420 v4l2_fourcc('M', '4', '2', '0') /* 12 YUV 4:2:0 2 lines y, 1 line uv interleaved */ +#define V4L2_PIX_FMT_YUV48_12 v4l2_fourcc('Y', '3', '1', '2') /* 48 YUV 4:4:4 12-bit per component */ + +/* + * YCbCr packed format. For each Y2xx format, xx bits of valid data occupy the MSBs + * of the 16 bit components, and 16-xx bits of zero padding occupy the LSBs. + */ +#define V4L2_PIX_FMT_Y210 v4l2_fourcc('Y', '2', '1', '0') /* 32 YUYV 4:2:2 */ +#define V4L2_PIX_FMT_Y212 v4l2_fourcc('Y', '2', '1', '2') /* 32 YUYV 4:2:2 */ +#define V4L2_PIX_FMT_Y216 v4l2_fourcc('Y', '2', '1', '6') /* 32 YUYV 4:2:2 */ + +/* two planes -- one Y, one Cr + Cb interleaved */ +#define V4L2_PIX_FMT_NV12 v4l2_fourcc('N', 'V', '1', '2') /* 12 Y/CbCr 4:2:0 */ +#define V4L2_PIX_FMT_NV21 v4l2_fourcc('N', 'V', '2', '1') /* 12 Y/CrCb 4:2:0 */ +#define V4L2_PIX_FMT_NV15 v4l2_fourcc('N', 'V', '1', '5') /* 15 Y/CbCr 4:2:0 10-bit packed */ +#define V4L2_PIX_FMT_NV16 v4l2_fourcc('N', 'V', '1', '6') /* 16 Y/CbCr 4:2:2 */ +#define V4L2_PIX_FMT_NV61 v4l2_fourcc('N', 'V', '6', '1') /* 16 Y/CrCb 4:2:2 */ +#define V4L2_PIX_FMT_NV20 v4l2_fourcc('N', 'V', '2', '0') /* 20 Y/CbCr 4:2:2 10-bit packed */ +#define V4L2_PIX_FMT_NV24 v4l2_fourcc('N', 'V', '2', '4') /* 24 Y/CbCr 4:4:4 */ +#define V4L2_PIX_FMT_NV42 v4l2_fourcc('N', 'V', '4', '2') /* 24 Y/CrCb 4:4:4 */ +#define V4L2_PIX_FMT_P010 v4l2_fourcc('P', '0', '1', '0') /* 24 Y/CbCr 4:2:0 10-bit per component */ +#define V4L2_PIX_FMT_P012 v4l2_fourcc('P', '0', '1', '2') /* 24 Y/CbCr 4:2:0 12-bit per component */ + +/* two non contiguous planes - one Y, one Cr + Cb interleaved */ +#define V4L2_PIX_FMT_NV12M v4l2_fourcc('N', 'M', '1', '2') /* 12 Y/CbCr 4:2:0 */ +#define V4L2_PIX_FMT_NV21M v4l2_fourcc('N', 'M', '2', '1') /* 21 Y/CrCb 4:2:0 */ +#define V4L2_PIX_FMT_NV16M v4l2_fourcc('N', 'M', '1', '6') /* 16 Y/CbCr 4:2:2 */ +#define V4L2_PIX_FMT_NV61M v4l2_fourcc('N', 'M', '6', '1') /* 16 Y/CrCb 4:2:2 */ +#define V4L2_PIX_FMT_P012M v4l2_fourcc('P', 'M', '1', '2') /* 24 Y/CbCr 4:2:0 12-bit per component */ + +/* three planes - Y Cb, Cr */ +#define V4L2_PIX_FMT_YUV410 v4l2_fourcc('Y', 'U', 'V', '9') /* 9 YUV 4:1:0 */ +#define V4L2_PIX_FMT_YVU410 v4l2_fourcc('Y', 'V', 'U', '9') /* 9 YVU 4:1:0 */ +#define V4L2_PIX_FMT_YUV411P v4l2_fourcc('4', '1', '1', 'P') /* 12 YVU411 planar */ +#define V4L2_PIX_FMT_YUV420 v4l2_fourcc('Y', 'U', '1', '2') /* 12 YUV 4:2:0 */ +#define V4L2_PIX_FMT_YVU420 v4l2_fourcc('Y', 'V', '1', '2') /* 12 YVU 4:2:0 */ +#define V4L2_PIX_FMT_YUV422P v4l2_fourcc('4', '2', '2', 'P') /* 16 YVU422 planar */ + +/* three non contiguous planes - Y, Cb, Cr */ +#define V4L2_PIX_FMT_YUV420M v4l2_fourcc('Y', 'M', '1', '2') /* 12 YUV420 planar */ +#define V4L2_PIX_FMT_YVU420M v4l2_fourcc('Y', 'M', '2', '1') /* 12 YVU420 planar */ +#define V4L2_PIX_FMT_YUV422M v4l2_fourcc('Y', 'M', '1', '6') /* 16 YUV422 planar */ +#define V4L2_PIX_FMT_YVU422M v4l2_fourcc('Y', 'M', '6', '1') /* 16 YVU422 planar */ +#define V4L2_PIX_FMT_YUV444M v4l2_fourcc('Y', 'M', '2', '4') /* 24 YUV444 planar */ +#define V4L2_PIX_FMT_YVU444M v4l2_fourcc('Y', 'M', '4', '2') /* 24 YVU444 planar */ + +/* Tiled YUV formats */ +#define V4L2_PIX_FMT_NV12_4L4 v4l2_fourcc('V', 'T', '1', '2') /* 12 Y/CbCr 4:2:0 4x4 tiles */ +#define V4L2_PIX_FMT_NV12_16L16 v4l2_fourcc('H', 'M', '1', '2') /* 12 Y/CbCr 4:2:0 16x16 tiles */ +#define V4L2_PIX_FMT_NV12_32L32 v4l2_fourcc('S', 'T', '1', '2') /* 12 Y/CbCr 4:2:0 32x32 tiles */ +#define V4L2_PIX_FMT_NV15_4L4 v4l2_fourcc('V', 'T', '1', '5') /* 15 Y/CbCr 4:2:0 10-bit 4x4 tiles */ +#define V4L2_PIX_FMT_P010_4L4 v4l2_fourcc('T', '0', '1', '0') /* 12 Y/CbCr 4:2:0 10-bit 4x4 macroblocks */ +#define V4L2_PIX_FMT_NV12_8L128 v4l2_fourcc('A', 'T', '1', '2') /* Y/CbCr 4:2:0 8x128 tiles */ +#define V4L2_PIX_FMT_NV12_10BE_8L128 v4l2_fourcc_be('A', 'X', '1', '2') /* Y/CbCr 4:2:0 10-bit 8x128 tiles */ + +/* Tiled YUV formats, non contiguous planes */ +#define V4L2_PIX_FMT_NV12MT v4l2_fourcc('T', 'M', '1', '2') /* 12 Y/CbCr 4:2:0 64x32 tiles */ +#define V4L2_PIX_FMT_NV12MT_16X16 v4l2_fourcc('V', 'M', '1', '2') /* 12 Y/CbCr 4:2:0 16x16 tiles */ +#define V4L2_PIX_FMT_NV12M_8L128 v4l2_fourcc('N', 'A', '1', '2') /* Y/CbCr 4:2:0 8x128 tiles */ +#define V4L2_PIX_FMT_NV12M_10BE_8L128 v4l2_fourcc_be('N', 'T', '1', '2') /* Y/CbCr 4:2:0 10-bit 8x128 tiles */ + +/* Bayer formats - see http://www.siliconimaging.com/RGB%20Bayer.htm */ +#define V4L2_PIX_FMT_SBGGR8 v4l2_fourcc('B', 'A', '8', '1') /* 8 BGBG.. GRGR.. */ +#define V4L2_PIX_FMT_SGBRG8 v4l2_fourcc('G', 'B', 'R', 'G') /* 8 GBGB.. RGRG.. */ +#define V4L2_PIX_FMT_SGRBG8 v4l2_fourcc('G', 'R', 'B', 'G') /* 8 GRGR.. BGBG.. */ +#define V4L2_PIX_FMT_SRGGB8 v4l2_fourcc('R', 'G', 'G', 'B') /* 8 RGRG.. GBGB.. */ +#define V4L2_PIX_FMT_SBGGR10 v4l2_fourcc('B', 'G', '1', '0') /* 10 BGBG.. GRGR.. */ +#define V4L2_PIX_FMT_SGBRG10 v4l2_fourcc('G', 'B', '1', '0') /* 10 GBGB.. RGRG.. */ +#define V4L2_PIX_FMT_SGRBG10 v4l2_fourcc('B', 'A', '1', '0') /* 10 GRGR.. BGBG.. */ +#define V4L2_PIX_FMT_SRGGB10 v4l2_fourcc('R', 'G', '1', '0') /* 10 RGRG.. GBGB.. */ + /* 10bit raw bayer packed, 5 bytes for every 4 pixels */ +#define V4L2_PIX_FMT_SBGGR10P v4l2_fourcc('p', 'B', 'A', 'A') +#define V4L2_PIX_FMT_SGBRG10P v4l2_fourcc('p', 'G', 'A', 'A') +#define V4L2_PIX_FMT_SGRBG10P v4l2_fourcc('p', 'g', 'A', 'A') +#define V4L2_PIX_FMT_SRGGB10P v4l2_fourcc('p', 'R', 'A', 'A') + /* 10bit raw bayer a-law compressed to 8 bits */ +#define V4L2_PIX_FMT_SBGGR10ALAW8 v4l2_fourcc('a', 'B', 'A', '8') +#define V4L2_PIX_FMT_SGBRG10ALAW8 v4l2_fourcc('a', 'G', 'A', '8') +#define V4L2_PIX_FMT_SGRBG10ALAW8 v4l2_fourcc('a', 'g', 'A', '8') +#define V4L2_PIX_FMT_SRGGB10ALAW8 v4l2_fourcc('a', 'R', 'A', '8') + /* 10bit raw bayer DPCM compressed to 8 bits */ +#define V4L2_PIX_FMT_SBGGR10DPCM8 v4l2_fourcc('b', 'B', 'A', '8') +#define V4L2_PIX_FMT_SGBRG10DPCM8 v4l2_fourcc('b', 'G', 'A', '8') +#define V4L2_PIX_FMT_SGRBG10DPCM8 v4l2_fourcc('B', 'D', '1', '0') +#define V4L2_PIX_FMT_SRGGB10DPCM8 v4l2_fourcc('b', 'R', 'A', '8') +#define V4L2_PIX_FMT_SBGGR12 v4l2_fourcc('B', 'G', '1', '2') /* 12 BGBG.. GRGR.. */ +#define V4L2_PIX_FMT_SGBRG12 v4l2_fourcc('G', 'B', '1', '2') /* 12 GBGB.. RGRG.. */ +#define V4L2_PIX_FMT_SGRBG12 v4l2_fourcc('B', 'A', '1', '2') /* 12 GRGR.. BGBG.. */ +#define V4L2_PIX_FMT_SRGGB12 v4l2_fourcc('R', 'G', '1', '2') /* 12 RGRG.. GBGB.. */ + /* 12bit raw bayer packed, 3 bytes for every 2 pixels */ +#define V4L2_PIX_FMT_SBGGR12P v4l2_fourcc('p', 'B', 'C', 'C') +#define V4L2_PIX_FMT_SGBRG12P v4l2_fourcc('p', 'G', 'C', 'C') +#define V4L2_PIX_FMT_SGRBG12P v4l2_fourcc('p', 'g', 'C', 'C') +#define V4L2_PIX_FMT_SRGGB12P v4l2_fourcc('p', 'R', 'C', 'C') +#define V4L2_PIX_FMT_SBGGR14 v4l2_fourcc('B', 'G', '1', '4') /* 14 BGBG.. GRGR.. */ +#define V4L2_PIX_FMT_SGBRG14 v4l2_fourcc('G', 'B', '1', '4') /* 14 GBGB.. RGRG.. */ +#define V4L2_PIX_FMT_SGRBG14 v4l2_fourcc('G', 'R', '1', '4') /* 14 GRGR.. BGBG.. */ +#define V4L2_PIX_FMT_SRGGB14 v4l2_fourcc('R', 'G', '1', '4') /* 14 RGRG.. GBGB.. */ + /* 14bit raw bayer packed, 7 bytes for every 4 pixels */ +#define V4L2_PIX_FMT_SBGGR14P v4l2_fourcc('p', 'B', 'E', 'E') +#define V4L2_PIX_FMT_SGBRG14P v4l2_fourcc('p', 'G', 'E', 'E') +#define V4L2_PIX_FMT_SGRBG14P v4l2_fourcc('p', 'g', 'E', 'E') +#define V4L2_PIX_FMT_SRGGB14P v4l2_fourcc('p', 'R', 'E', 'E') +#define V4L2_PIX_FMT_SBGGR16 v4l2_fourcc('B', 'Y', 'R', '2') /* 16 BGBG.. GRGR.. */ +#define V4L2_PIX_FMT_SGBRG16 v4l2_fourcc('G', 'B', '1', '6') /* 16 GBGB.. RGRG.. */ +#define V4L2_PIX_FMT_SGRBG16 v4l2_fourcc('G', 'R', '1', '6') /* 16 GRGR.. BGBG.. */ +#define V4L2_PIX_FMT_SRGGB16 v4l2_fourcc('R', 'G', '1', '6') /* 16 RGRG.. GBGB.. */ + +/* HSV formats */ +#define V4L2_PIX_FMT_HSV24 v4l2_fourcc('H', 'S', 'V', '3') +#define V4L2_PIX_FMT_HSV32 v4l2_fourcc('H', 'S', 'V', '4') + +/* compressed formats */ +#define V4L2_PIX_FMT_MJPEG v4l2_fourcc('M', 'J', 'P', 'G') /* Motion-JPEG */ +#define V4L2_PIX_FMT_JPEG v4l2_fourcc('J', 'P', 'E', 'G') /* JFIF JPEG */ +#define V4L2_PIX_FMT_DV v4l2_fourcc('d', 'v', 's', 'd') /* 1394 */ +#define V4L2_PIX_FMT_MPEG v4l2_fourcc('M', 'P', 'E', 'G') /* MPEG-1/2/4 Multiplexed */ +#define V4L2_PIX_FMT_H264 v4l2_fourcc('H', '2', '6', '4') /* H264 with start codes */ +#define V4L2_PIX_FMT_H264_NO_SC v4l2_fourcc('A', 'V', 'C', '1') /* H264 without start codes */ +#define V4L2_PIX_FMT_H264_MVC v4l2_fourcc('M', '2', '6', '4') /* H264 MVC */ +#define V4L2_PIX_FMT_H263 v4l2_fourcc('H', '2', '6', '3') /* H263 */ +#define V4L2_PIX_FMT_MPEG1 v4l2_fourcc('M', 'P', 'G', '1') /* MPEG-1 ES */ +#define V4L2_PIX_FMT_MPEG2 v4l2_fourcc('M', 'P', 'G', '2') /* MPEG-2 ES */ +#define V4L2_PIX_FMT_MPEG2_SLICE v4l2_fourcc('M', 'G', '2', 'S') /* MPEG-2 parsed slice data */ +#define V4L2_PIX_FMT_MPEG4 v4l2_fourcc('M', 'P', 'G', '4') /* MPEG-4 part 2 ES */ +#define V4L2_PIX_FMT_XVID v4l2_fourcc('X', 'V', 'I', 'D') /* Xvid */ +#define V4L2_PIX_FMT_VC1_ANNEX_G v4l2_fourcc('V', 'C', '1', 'G') /* SMPTE 421M Annex G compliant stream */ +#define V4L2_PIX_FMT_VC1_ANNEX_L v4l2_fourcc('V', 'C', '1', 'L') /* SMPTE 421M Annex L compliant stream */ +#define V4L2_PIX_FMT_VP8 v4l2_fourcc('V', 'P', '8', '0') /* VP8 */ +#define V4L2_PIX_FMT_VP8_FRAME v4l2_fourcc('V', 'P', '8', 'F') /* VP8 parsed frame */ +#define V4L2_PIX_FMT_VP9 v4l2_fourcc('V', 'P', '9', '0') /* VP9 */ +#define V4L2_PIX_FMT_VP9_FRAME v4l2_fourcc('V', 'P', '9', 'F') /* VP9 parsed frame */ +#define V4L2_PIX_FMT_HEVC v4l2_fourcc('H', 'E', 'V', 'C') /* HEVC aka H.265 */ +#define V4L2_PIX_FMT_FWHT v4l2_fourcc('F', 'W', 'H', 'T') /* Fast Walsh Hadamard Transform (vicodec) */ +#define V4L2_PIX_FMT_FWHT_STATELESS v4l2_fourcc('S', 'F', 'W', 'H') /* Stateless FWHT (vicodec) */ +#define V4L2_PIX_FMT_H264_SLICE v4l2_fourcc('S', '2', '6', '4') /* H264 parsed slices */ +#define V4L2_PIX_FMT_HEVC_SLICE v4l2_fourcc('S', '2', '6', '5') /* HEVC parsed slices */ +#define V4L2_PIX_FMT_AV1_FRAME v4l2_fourcc('A', 'V', '1', 'F') /* AV1 parsed frame */ +#define V4L2_PIX_FMT_SPK v4l2_fourcc('S', 'P', 'K', '0') /* Sorenson Spark */ +#define V4L2_PIX_FMT_RV30 v4l2_fourcc('R', 'V', '3', '0') /* RealVideo 8 */ +#define V4L2_PIX_FMT_RV40 v4l2_fourcc('R', 'V', '4', '0') /* RealVideo 9 & 10 */ + +/* Vendor-specific formats */ +#define V4L2_PIX_FMT_CPIA1 v4l2_fourcc('C', 'P', 'I', 'A') /* cpia1 YUV */ +#define V4L2_PIX_FMT_WNVA v4l2_fourcc('W', 'N', 'V', 'A') /* Winnov hw compress */ +#define V4L2_PIX_FMT_SN9C10X v4l2_fourcc('S', '9', '1', '0') /* SN9C10x compression */ +#define V4L2_PIX_FMT_SN9C20X_I420 v4l2_fourcc('S', '9', '2', '0') /* SN9C20x YUV 4:2:0 */ +#define V4L2_PIX_FMT_PWC1 v4l2_fourcc('P', 'W', 'C', '1') /* pwc older webcam */ +#define V4L2_PIX_FMT_PWC2 v4l2_fourcc('P', 'W', 'C', '2') /* pwc newer webcam */ +#define V4L2_PIX_FMT_ET61X251 v4l2_fourcc('E', '6', '2', '5') /* ET61X251 compression */ +#define V4L2_PIX_FMT_SPCA501 v4l2_fourcc('S', '5', '0', '1') /* YUYV per line */ +#define V4L2_PIX_FMT_SPCA505 v4l2_fourcc('S', '5', '0', '5') /* YYUV per line */ +#define V4L2_PIX_FMT_SPCA508 v4l2_fourcc('S', '5', '0', '8') /* YUVY per line */ +#define V4L2_PIX_FMT_SPCA561 v4l2_fourcc('S', '5', '6', '1') /* compressed GBRG bayer */ +#define V4L2_PIX_FMT_PAC207 v4l2_fourcc('P', '2', '0', '7') /* compressed BGGR bayer */ +#define V4L2_PIX_FMT_MR97310A v4l2_fourcc('M', '3', '1', '0') /* compressed BGGR bayer */ +#define V4L2_PIX_FMT_JL2005BCD v4l2_fourcc('J', 'L', '2', '0') /* compressed RGGB bayer */ +#define V4L2_PIX_FMT_SN9C2028 v4l2_fourcc('S', 'O', 'N', 'X') /* compressed GBRG bayer */ +#define V4L2_PIX_FMT_SQ905C v4l2_fourcc('9', '0', '5', 'C') /* compressed RGGB bayer */ +#define V4L2_PIX_FMT_PJPG v4l2_fourcc('P', 'J', 'P', 'G') /* Pixart 73xx JPEG */ +#define V4L2_PIX_FMT_OV511 v4l2_fourcc('O', '5', '1', '1') /* ov511 JPEG */ +#define V4L2_PIX_FMT_OV518 v4l2_fourcc('O', '5', '1', '8') /* ov518 JPEG */ +#define V4L2_PIX_FMT_STV0680 v4l2_fourcc('S', '6', '8', '0') /* stv0680 bayer */ +#define V4L2_PIX_FMT_TM6000 v4l2_fourcc('T', 'M', '6', '0') /* tm5600/tm60x0 */ +#define V4L2_PIX_FMT_CIT_YYVYUY v4l2_fourcc('C', 'I', 'T', 'V') /* one line of Y then 1 line of VYUY */ +#define V4L2_PIX_FMT_KONICA420 v4l2_fourcc('K', 'O', 'N', 'I') /* YUV420 planar in blocks of 256 pixels */ +#define V4L2_PIX_FMT_JPGL v4l2_fourcc('J', 'P', 'G', 'L') /* JPEG-Lite */ +#define V4L2_PIX_FMT_SE401 v4l2_fourcc('S', '4', '0', '1') /* se401 janggu compressed rgb */ +#define V4L2_PIX_FMT_S5C_UYVY_JPG v4l2_fourcc('S', '5', 'C', 'I') /* S5C73M3 interleaved UYVY/JPEG */ +#define V4L2_PIX_FMT_Y8I v4l2_fourcc('Y', '8', 'I', ' ') /* Greyscale 8-bit L/R interleaved */ +#define V4L2_PIX_FMT_Y12I v4l2_fourcc('Y', '1', '2', 'I') /* Greyscale 12-bit L/R interleaved */ +#define V4L2_PIX_FMT_Y16I v4l2_fourcc('Y', '1', '6', 'I') /* Greyscale 16-bit L/R interleaved */ +#define V4L2_PIX_FMT_Z16 v4l2_fourcc('Z', '1', '6', ' ') /* Depth data 16-bit */ +#define V4L2_PIX_FMT_MT21C v4l2_fourcc('M', 'T', '2', '1') /* Mediatek compressed block mode */ +#define V4L2_PIX_FMT_MM21 v4l2_fourcc('M', 'M', '2', '1') /* Mediatek 8-bit block mode, two non-contiguous planes */ +#define V4L2_PIX_FMT_MT2110T v4l2_fourcc('M', 'T', '2', 'T') /* Mediatek 10-bit block tile mode */ +#define V4L2_PIX_FMT_MT2110R v4l2_fourcc('M', 'T', '2', 'R') /* Mediatek 10-bit block raster mode */ +#define V4L2_PIX_FMT_INZI v4l2_fourcc('I', 'N', 'Z', 'I') /* Intel Planar Greyscale 10-bit and Depth 16-bit */ +#define V4L2_PIX_FMT_CNF4 v4l2_fourcc('C', 'N', 'F', '4') /* Intel 4-bit packed depth confidence information */ +#define V4L2_PIX_FMT_HI240 v4l2_fourcc('H', 'I', '2', '4') /* BTTV 8-bit dithered RGB */ +#define V4L2_PIX_FMT_QC08C v4l2_fourcc('Q', '0', '8', 'C') /* Qualcomm 8-bit compressed */ +#define V4L2_PIX_FMT_QC10C v4l2_fourcc('Q', '1', '0', 'C') /* Qualcomm 10-bit compressed */ +#define V4L2_PIX_FMT_AJPG v4l2_fourcc('A', 'J', 'P', 'G') /* Aspeed JPEG */ +#define V4L2_PIX_FMT_HEXTILE v4l2_fourcc('H', 'X', 'T', 'L') /* Hextile compressed */ + +/* 10bit raw packed, 32 bytes for every 25 pixels, last LSB 6 bits unused */ +#define V4L2_PIX_FMT_IPU3_SBGGR10 v4l2_fourcc('i', 'p', '3', 'b') /* IPU3 packed 10-bit BGGR bayer */ +#define V4L2_PIX_FMT_IPU3_SGBRG10 v4l2_fourcc('i', 'p', '3', 'g') /* IPU3 packed 10-bit GBRG bayer */ +#define V4L2_PIX_FMT_IPU3_SGRBG10 v4l2_fourcc('i', 'p', '3', 'G') /* IPU3 packed 10-bit GRBG bayer */ +#define V4L2_PIX_FMT_IPU3_SRGGB10 v4l2_fourcc('i', 'p', '3', 'r') /* IPU3 packed 10-bit RGGB bayer */ + +/* Raspberry Pi PiSP compressed formats. */ +#define V4L2_PIX_FMT_PISP_COMP1_RGGB v4l2_fourcc('P', 'C', '1', 'R') /* PiSP 8-bit mode 1 compressed RGGB bayer */ +#define V4L2_PIX_FMT_PISP_COMP1_GRBG v4l2_fourcc('P', 'C', '1', 'G') /* PiSP 8-bit mode 1 compressed GRBG bayer */ +#define V4L2_PIX_FMT_PISP_COMP1_GBRG v4l2_fourcc('P', 'C', '1', 'g') /* PiSP 8-bit mode 1 compressed GBRG bayer */ +#define V4L2_PIX_FMT_PISP_COMP1_BGGR v4l2_fourcc('P', 'C', '1', 'B') /* PiSP 8-bit mode 1 compressed BGGR bayer */ +#define V4L2_PIX_FMT_PISP_COMP1_MONO v4l2_fourcc('P', 'C', '1', 'M') /* PiSP 8-bit mode 1 compressed monochrome */ +#define V4L2_PIX_FMT_PISP_COMP2_RGGB v4l2_fourcc('P', 'C', '2', 'R') /* PiSP 8-bit mode 2 compressed RGGB bayer */ +#define V4L2_PIX_FMT_PISP_COMP2_GRBG v4l2_fourcc('P', 'C', '2', 'G') /* PiSP 8-bit mode 2 compressed GRBG bayer */ +#define V4L2_PIX_FMT_PISP_COMP2_GBRG v4l2_fourcc('P', 'C', '2', 'g') /* PiSP 8-bit mode 2 compressed GBRG bayer */ +#define V4L2_PIX_FMT_PISP_COMP2_BGGR v4l2_fourcc('P', 'C', '2', 'B') /* PiSP 8-bit mode 2 compressed BGGR bayer */ +#define V4L2_PIX_FMT_PISP_COMP2_MONO v4l2_fourcc('P', 'C', '2', 'M') /* PiSP 8-bit mode 2 compressed monochrome */ + +/* Renesas RZ/V2H CRU packed formats. 64-bit units with contiguous pixels */ +#define V4L2_PIX_FMT_RAW_CRU10 v4l2_fourcc('C', 'R', '1', '0') +#define V4L2_PIX_FMT_RAW_CRU12 v4l2_fourcc('C', 'R', '1', '2') +#define V4L2_PIX_FMT_RAW_CRU14 v4l2_fourcc('C', 'R', '1', '4') +#define V4L2_PIX_FMT_RAW_CRU20 v4l2_fourcc('C', 'R', '2', '0') + +/* SDR formats - used only for Software Defined Radio devices */ +#define V4L2_SDR_FMT_CU8 v4l2_fourcc('C', 'U', '0', '8') /* IQ u8 */ +#define V4L2_SDR_FMT_CU16LE v4l2_fourcc('C', 'U', '1', '6') /* IQ u16le */ +#define V4L2_SDR_FMT_CS8 v4l2_fourcc('C', 'S', '0', '8') /* complex s8 */ +#define V4L2_SDR_FMT_CS14LE v4l2_fourcc('C', 'S', '1', '4') /* complex s14le */ +#define V4L2_SDR_FMT_RU12LE v4l2_fourcc('R', 'U', '1', '2') /* real u12le */ +#define V4L2_SDR_FMT_PCU16BE v4l2_fourcc('P', 'C', '1', '6') /* planar complex u16be */ +#define V4L2_SDR_FMT_PCU18BE v4l2_fourcc('P', 'C', '1', '8') /* planar complex u18be */ +#define V4L2_SDR_FMT_PCU20BE v4l2_fourcc('P', 'C', '2', '0') /* planar complex u20be */ + +/* Touch formats - used for Touch devices */ +#define V4L2_TCH_FMT_DELTA_TD16 v4l2_fourcc('T', 'D', '1', '6') /* 16-bit signed deltas */ +#define V4L2_TCH_FMT_DELTA_TD08 v4l2_fourcc('T', 'D', '0', '8') /* 8-bit signed deltas */ +#define V4L2_TCH_FMT_TU16 v4l2_fourcc('T', 'U', '1', '6') /* 16-bit unsigned touch data */ +#define V4L2_TCH_FMT_TU08 v4l2_fourcc('T', 'U', '0', '8') /* 8-bit unsigned touch data */ + +/* Meta-data formats */ +#define V4L2_META_FMT_VSP1_HGO v4l2_fourcc('V', 'S', 'P', 'H') /* R-Car VSP1 1-D Histogram */ +#define V4L2_META_FMT_VSP1_HGT v4l2_fourcc('V', 'S', 'P', 'T') /* R-Car VSP1 2-D Histogram */ +#define V4L2_META_FMT_UVC v4l2_fourcc('U', 'V', 'C', 'H') /* UVC Payload Header metadata */ +#define V4L2_META_FMT_D4XX v4l2_fourcc('D', '4', 'X', 'X') /* D4XX Payload Header metadata */ +#define V4L2_META_FMT_UVC_MSXU_1_5 v4l2_fourcc('U', 'V', 'C', 'M') /* UVC MSXU metadata */ +#define V4L2_META_FMT_VIVID v4l2_fourcc('V', 'I', 'V', 'D') /* Vivid Metadata */ + +/* Vendor specific - used for RK_ISP1 camera sub-system */ +#define V4L2_META_FMT_RK_ISP1_PARAMS v4l2_fourcc('R', 'K', '1', 'P') /* Rockchip ISP1 3A Parameters */ +#define V4L2_META_FMT_RK_ISP1_STAT_3A v4l2_fourcc('R', 'K', '1', 'S') /* Rockchip ISP1 3A Statistics */ +#define V4L2_META_FMT_RK_ISP1_EXT_PARAMS v4l2_fourcc('R', 'K', '1', 'E') /* Rockchip ISP1 3a Extensible Parameters */ + +/* Vendor specific - used for C3_ISP */ +#define V4L2_META_FMT_C3ISP_PARAMS v4l2_fourcc('C', '3', 'P', 'M') /* Amlogic C3 ISP Parameters */ +#define V4L2_META_FMT_C3ISP_STATS v4l2_fourcc('C', '3', 'S', 'T') /* Amlogic C3 ISP Statistics */ + +/* Vendor specific - used for RaspberryPi PiSP */ +#define V4L2_META_FMT_RPI_BE_CFG v4l2_fourcc('R', 'P', 'B', 'C') /* PiSP BE configuration */ +#define V4L2_META_FMT_RPI_FE_CFG v4l2_fourcc('R', 'P', 'F', 'C') /* PiSP FE configuration */ +#define V4L2_META_FMT_RPI_FE_STATS v4l2_fourcc('R', 'P', 'F', 'S') /* PiSP FE stats */ + +/* priv field value to indicates that subsequent fields are valid. */ +#define V4L2_PIX_FMT_PRIV_MAGIC 0xfeedcafe + +/* Flags */ +#define V4L2_PIX_FMT_FLAG_PREMUL_ALPHA 0x00000001 +#define V4L2_PIX_FMT_FLAG_SET_CSC 0x00000002 + +/* + * F O R M A T E N U M E R A T I O N + */ +struct v4l2_fmtdesc { + u_int32_t index; /* Format number */ + u_int32_t type; /* enum v4l2_buf_type */ + u_int32_t flags; + u_int8_t description[32]; /* Description string */ + u_int32_t pixelformat; /* Format fourcc */ + u_int32_t mbus_code; /* Media bus code */ + u_int32_t reserved[3]; +}; + +#define V4L2_FMT_FLAG_COMPRESSED 0x0001 +#define V4L2_FMT_FLAG_EMULATED 0x0002 +#define V4L2_FMT_FLAG_CONTINUOUS_BYTESTREAM 0x0004 +#define V4L2_FMT_FLAG_DYN_RESOLUTION 0x0008 +#define V4L2_FMT_FLAG_ENC_CAP_FRAME_INTERVAL 0x0010 +#define V4L2_FMT_FLAG_CSC_COLORSPACE 0x0020 +#define V4L2_FMT_FLAG_CSC_XFER_FUNC 0x0040 +#define V4L2_FMT_FLAG_CSC_YCBCR_ENC 0x0080 +#define V4L2_FMT_FLAG_CSC_HSV_ENC V4L2_FMT_FLAG_CSC_YCBCR_ENC +#define V4L2_FMT_FLAG_CSC_QUANTIZATION 0x0100 +#define V4L2_FMT_FLAG_META_LINE_BASED 0x0200 + +/* Format description flag, to be ORed with the index */ +#define V4L2_FMTDESC_FLAG_ENUM_ALL 0x80000000 + + /* Frame Size and frame rate enumeration */ +/* + * F R A M E S I Z E E N U M E R A T I O N + */ +enum v4l2_frmsizetypes { + V4L2_FRMSIZE_TYPE_DISCRETE = 1, + V4L2_FRMSIZE_TYPE_CONTINUOUS = 2, + V4L2_FRMSIZE_TYPE_STEPWISE = 3, +}; + +struct v4l2_frmsize_discrete { + u_int32_t width; /* Frame width [pixel] */ + u_int32_t height; /* Frame height [pixel] */ +}; + +struct v4l2_frmsize_stepwise { + u_int32_t min_width; /* Minimum frame width [pixel] */ + u_int32_t max_width; /* Maximum frame width [pixel] */ + u_int32_t step_width; /* Frame width step size [pixel] */ + u_int32_t min_height; /* Minimum frame height [pixel] */ + u_int32_t max_height; /* Maximum frame height [pixel] */ + u_int32_t step_height; /* Frame height step size [pixel] */ +}; + +struct v4l2_frmsizeenum { + u_int32_t index; /* Frame size number */ + u_int32_t pixel_format; /* Pixel format */ + u_int32_t type; /* Frame size type the device supports. */ + + union { /* Frame size */ + struct v4l2_frmsize_discrete discrete; + struct v4l2_frmsize_stepwise stepwise; + }; + + u_int32_t reserved[2]; /* Reserved space for future use */ +}; + +/* + * F R A M E R A T E E N U M E R A T I O N + */ +enum v4l2_frmivaltypes { + V4L2_FRMIVAL_TYPE_DISCRETE = 1, + V4L2_FRMIVAL_TYPE_CONTINUOUS = 2, + V4L2_FRMIVAL_TYPE_STEPWISE = 3, +}; + +struct v4l2_frmival_stepwise { + struct v4l2_fract min; /* Minimum frame interval [s] */ + struct v4l2_fract max; /* Maximum frame interval [s] */ + struct v4l2_fract step; /* Frame interval step size [s] */ +}; + +struct v4l2_frmivalenum { + u_int32_t index; /* Frame format index */ + u_int32_t pixel_format; /* Pixel format */ + u_int32_t width; /* Frame width */ + u_int32_t height; /* Frame height */ + u_int32_t type; /* Frame interval type the device supports. */ + + union { /* Frame interval */ + struct v4l2_fract discrete; + struct v4l2_frmival_stepwise stepwise; + }; + + u_int32_t reserved[2]; /* Reserved space for future use */ +}; + +/* + * T I M E C O D E + */ +struct v4l2_timecode { + u_int32_t type; + u_int32_t flags; + u_int8_t frames; + u_int8_t seconds; + u_int8_t minutes; + u_int8_t hours; + u_int8_t userbits[4]; +}; + +/* Type */ +#define V4L2_TC_TYPE_24FPS 1 +#define V4L2_TC_TYPE_25FPS 2 +#define V4L2_TC_TYPE_30FPS 3 +#define V4L2_TC_TYPE_50FPS 4 +#define V4L2_TC_TYPE_60FPS 5 + +/* Flags */ +#define V4L2_TC_FLAG_DROPFRAME 0x0001 /* "drop-frame" mode */ +#define V4L2_TC_FLAG_COLORFRAME 0x0002 +#define V4L2_TC_USERBITS_field 0x000C +#define V4L2_TC_USERBITS_USERDEFINED 0x0000 +#define V4L2_TC_USERBITS_8BITCHARS 0x0008 +/* The above is based on SMPTE timecodes */ + +struct v4l2_jpegcompression { + int quality; + + int APPn; /* Number of APP segment to be written, + * must be 0..15 */ + int APP_len; /* Length of data in JPEG APPn segment */ + char APP_data[60]; /* Data in the JPEG APPn segment. */ + + int COM_len; /* Length of data in JPEG COM segment */ + char COM_data[60]; /* Data in JPEG COM segment */ + + u_int32_t jpeg_markers; /* Which markers should go into the JPEG + * output. Unless you exactly know what + * you do, leave them untouched. + * Including less markers will make the + * resulting code smaller, but there will + * be fewer applications which can read it. + * The presence of the APP and COM marker + * is influenced by APP_len and COM_len + * ONLY, not by this property! */ + +#define V4L2_JPEG_MARKER_DHT (1<<3) /* Define Huffman Tables */ +#define V4L2_JPEG_MARKER_DQT (1<<4) /* Define Quantization Tables */ +#define V4L2_JPEG_MARKER_DRI (1<<5) /* Define Restart Interval */ +#define V4L2_JPEG_MARKER_COM (1<<6) /* Comment segment */ +#define V4L2_JPEG_MARKER_APP (1<<7) /* App segment, driver will + * always use APP0 */ +}; + +/* + * M E M O R Y - M A P P I N G B U F F E R S + */ + +struct v4l2_requestbuffers { + u_int32_t count; + u_int32_t type; /* enum v4l2_buf_type */ + u_int32_t memory; /* enum v4l2_memory */ + u_int32_t capabilities; + u_int8_t flags; + u_int8_t reserved[3]; +}; + +#define V4L2_MEMORY_FLAG_NON_COHERENT (1 << 0) + +/* capabilities for struct v4l2_requestbuffers and v4l2_create_buffers */ +#define V4L2_BUF_CAP_SUPPORTS_MMAP (1 << 0) +#define V4L2_BUF_CAP_SUPPORTS_USERPTR (1 << 1) +#define V4L2_BUF_CAP_SUPPORTS_DMABUF (1 << 2) +#define V4L2_BUF_CAP_SUPPORTS_REQUESTS (1 << 3) +#define V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS (1 << 4) +#define V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF (1 << 5) +#define V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS (1 << 6) +#define V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS (1 << 7) +#define V4L2_BUF_CAP_SUPPORTS_REMOVE_BUFS (1 << 8) + +/** + * struct v4l2_plane - plane info for multi-planar buffers + * @bytesused: number of bytes occupied by data in the plane (payload) + * @length: size of this plane (NOT the payload) in bytes + * @m.mem_offset: when memory in the associated struct v4l2_buffer is + * V4L2_MEMORY_MMAP, equals the offset from the start of + * the device memory for this plane (or is a "cookie" that + * should be passed to mmap() called on the video node) + * @m.userptr: when memory is V4L2_MEMORY_USERPTR, a userspace pointer + * pointing to this plane + * @m.fd: when memory is V4L2_MEMORY_DMABUF, a userspace file + * descriptor associated with this plane + * @m: union of @mem_offset, @userptr and @fd + * @data_offset: offset in the plane to the start of data; usually 0, + * unless there is a header in front of the data + * @reserved: drivers and applications must zero this array + * + * Multi-planar buffers consist of one or more planes, e.g. an YCbCr buffer + * with two planes can have one plane for Y, and another for interleaved CbCr + * components. Each plane can reside in a separate memory buffer, or even in + * a completely separate memory node (e.g. in embedded devices). + */ +struct v4l2_plane { + u_int32_t bytesused; + u_int32_t length; + union { + u_int32_t mem_offset; + unsigned long userptr; + int32_t fd; + } m; + u_int32_t data_offset; + u_int32_t reserved[11]; +}; + +/** + * struct v4l2_buffer - video buffer info + * @index: id number of the buffer + * @type: enum v4l2_buf_type; buffer type (type == *_MPLANE for + * multiplanar buffers); + * @bytesused: number of bytes occupied by data in the buffer (payload); + * unused (set to 0) for multiplanar buffers + * @flags: buffer informational flags + * @field: enum v4l2_field; field order of the image in the buffer + * @timestamp: frame timestamp + * @timecode: frame timecode + * @sequence: sequence count of this frame + * @memory: enum v4l2_memory; the method, in which the actual video data is + * passed + * @m.offset: for non-multiplanar buffers with memory == V4L2_MEMORY_MMAP; + * offset from the start of the device memory for this plane, + * (or a "cookie" that should be passed to mmap() as offset) + * @m.userptr: for non-multiplanar buffers with memory == V4L2_MEMORY_USERPTR; + * a userspace pointer pointing to this buffer + * @m.fd: for non-multiplanar buffers with memory == V4L2_MEMORY_DMABUF; + * a userspace file descriptor associated with this buffer + * @m.planes: for multiplanar buffers; userspace pointer to the array of plane + * info structs for this buffer + * @m: union of @offset, @userptr, @planes and @fd + * @length: size in bytes of the buffer (NOT its payload) for single-plane + * buffers (when type != *_MPLANE); number of elements in the + * planes array for multi-plane buffers + * @reserved2: drivers and applications must zero this field + * @request_fd: fd of the request that this buffer should use + * @reserved: for backwards compatibility with applications that do not know + * about @request_fd + * + * Contains data exchanged by application and driver using one of the Streaming + * I/O methods. + */ +struct v4l2_buffer { + u_int32_t index; + u_int32_t type; + u_int32_t bytesused; + u_int32_t flags; + u_int32_t field; + struct timeval timestamp; + struct v4l2_timecode timecode; + u_int32_t sequence; + + /* memory location */ + u_int32_t memory; + union { + u_int32_t offset; + unsigned long userptr; + struct v4l2_plane *planes; + int32_t fd; + } m; + u_int32_t length; + u_int32_t reserved2; + union { + int32_t request_fd; + u_int32_t reserved; + }; +}; + +/** + * v4l2_timeval_to_ns - Convert timeval to nanoseconds + * @tv: pointer to the timeval variable to be converted + * + * Returns the scalar nanosecond representation of the timeval + * parameter. + */ +static inline u_int64_t v4l2_timeval_to_ns(const struct timeval *tv) +{ + return (u_int64_t)tv->tv_sec * 1000000000ULL + tv->tv_usec * 1000; +} + +/* Flags for 'flags' field */ +/* Buffer is mapped (flag) */ +#define V4L2_BUF_FLAG_MAPPED 0x00000001 +/* Buffer is queued for processing */ +#define V4L2_BUF_FLAG_QUEUED 0x00000002 +/* Buffer is ready */ +#define V4L2_BUF_FLAG_DONE 0x00000004 +/* Image is a keyframe (I-frame) */ +#define V4L2_BUF_FLAG_KEYFRAME 0x00000008 +/* Image is a P-frame */ +#define V4L2_BUF_FLAG_PFRAME 0x00000010 +/* Image is a B-frame */ +#define V4L2_BUF_FLAG_BFRAME 0x00000020 +/* Buffer is ready, but the data contained within is corrupted. */ +#define V4L2_BUF_FLAG_ERROR 0x00000040 +/* Buffer is added to an unqueued request */ +#define V4L2_BUF_FLAG_IN_REQUEST 0x00000080 +/* timecode field is valid */ +#define V4L2_BUF_FLAG_TIMECODE 0x00000100 +/* Don't return the capture buffer until OUTPUT timestamp changes */ +#define V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF 0x00000200 +/* Buffer is prepared for queuing */ +#define V4L2_BUF_FLAG_PREPARED 0x00000400 +/* Cache handling flags */ +#define V4L2_BUF_FLAG_NO_CACHE_INVALIDATE 0x00000800 +#define V4L2_BUF_FLAG_NO_CACHE_CLEAN 0x00001000 +/* Timestamp type */ +#define V4L2_BUF_FLAG_TIMESTAMP_MASK 0x0000e000 +#define V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN 0x00000000 +#define V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC 0x00002000 +#define V4L2_BUF_FLAG_TIMESTAMP_COPY 0x00004000 +/* Timestamp sources. */ +#define V4L2_BUF_FLAG_TSTAMP_SRC_MASK 0x00070000 +#define V4L2_BUF_FLAG_TSTAMP_SRC_EOF 0x00000000 +#define V4L2_BUF_FLAG_TSTAMP_SRC_SOE 0x00010000 +/* mem2mem encoder/decoder */ +#define V4L2_BUF_FLAG_LAST 0x00100000 +/* request_fd is valid */ +#define V4L2_BUF_FLAG_REQUEST_FD 0x00800000 + +/** + * struct v4l2_exportbuffer - export of video buffer as DMABUF file descriptor + * + * @index: id number of the buffer + * @type: enum v4l2_buf_type; buffer type (type == *_MPLANE for + * multiplanar buffers); + * @plane: index of the plane to be exported, 0 for single plane queues + * @flags: flags for newly created file, currently only O_CLOEXEC is + * supported, refer to manual of open syscall for more details + * @fd: file descriptor associated with DMABUF (set by driver) + * @reserved: drivers and applications must zero this array + * + * Contains data used for exporting a video buffer as DMABUF file descriptor. + * The buffer is identified by a 'cookie' returned by VIDIOC_QUERYBUF + * (identical to the cookie used to mmap() the buffer to userspace). All + * reserved fields must be set to zero. The field reserved0 is expected to + * become a structure 'type' allowing an alternative layout of the structure + * content. Therefore this field should not be used for any other extensions. + */ +struct v4l2_exportbuffer { + u_int32_t type; /* enum v4l2_buf_type */ + u_int32_t index; + u_int32_t plane; + u_int32_t flags; + int32_t fd; + u_int32_t reserved[11]; +}; + +/* + * O V E R L A Y P R E V I E W + */ +struct v4l2_framebuffer { + u_int32_t capability; + u_int32_t flags; +/* FIXME: in theory we should pass something like PCI device + memory + * region + offset instead of some physical address */ + void *base; + struct { + u_int32_t width; + u_int32_t height; + u_int32_t pixelformat; + u_int32_t field; /* enum v4l2_field */ + u_int32_t bytesperline; /* for padding, zero if unused */ + u_int32_t sizeimage; + u_int32_t colorspace; /* enum v4l2_colorspace */ + u_int32_t priv; /* reserved field, set to 0 */ + } fmt; +}; +/* Flags for the 'capability' field. Read only */ +#define V4L2_FBUF_CAP_EXTERNOVERLAY 0x0001 +#define V4L2_FBUF_CAP_CHROMAKEY 0x0002 +#define V4L2_FBUF_CAP_LIST_CLIPPING 0x0004 +#define V4L2_FBUF_CAP_BITMAP_CLIPPING 0x0008 +#define V4L2_FBUF_CAP_LOCAL_ALPHA 0x0010 +#define V4L2_FBUF_CAP_GLOBAL_ALPHA 0x0020 +#define V4L2_FBUF_CAP_LOCAL_INV_ALPHA 0x0040 +#define V4L2_FBUF_CAP_SRC_CHROMAKEY 0x0080 +/* Flags for the 'flags' field. */ +#define V4L2_FBUF_FLAG_PRIMARY 0x0001 +#define V4L2_FBUF_FLAG_OVERLAY 0x0002 +#define V4L2_FBUF_FLAG_CHROMAKEY 0x0004 +#define V4L2_FBUF_FLAG_LOCAL_ALPHA 0x0008 +#define V4L2_FBUF_FLAG_GLOBAL_ALPHA 0x0010 +#define V4L2_FBUF_FLAG_LOCAL_INV_ALPHA 0x0020 +#define V4L2_FBUF_FLAG_SRC_CHROMAKEY 0x0040 + +struct v4l2_clip { + struct v4l2_rect c; + struct v4l2_clip __user *next; +}; + +struct v4l2_window { + struct v4l2_rect w; + u_int32_t field; /* enum v4l2_field */ + u_int32_t chromakey; + struct v4l2_clip *clips; + u_int32_t clipcount; + void __user *bitmap; + u_int8_t global_alpha; +}; + +/* + * C A P T U R E P A R A M E T E R S + */ +struct v4l2_captureparm { + u_int32_t capability; /* Supported modes */ + u_int32_t capturemode; /* Current mode */ + struct v4l2_fract timeperframe; /* Time per frame in seconds */ + u_int32_t extendedmode; /* Driver-specific extensions */ + u_int32_t readbuffers; /* # of buffers for read */ + u_int32_t reserved[4]; +}; + +/* Flags for 'capability' and 'capturemode' fields */ +#define V4L2_MODE_HIGHQUALITY 0x0001 /* High quality imaging mode */ +#define V4L2_CAP_TIMEPERFRAME 0x1000 /* timeperframe field is supported */ + +struct v4l2_outputparm { + u_int32_t capability; /* Supported modes */ + u_int32_t outputmode; /* Current mode */ + struct v4l2_fract timeperframe; /* Time per frame in seconds */ + u_int32_t extendedmode; /* Driver-specific extensions */ + u_int32_t writebuffers; /* # of buffers for write */ + u_int32_t reserved[4]; +}; + +/* + * I N P U T I M A G E C R O P P I N G + */ +struct v4l2_cropcap { + u_int32_t type; /* enum v4l2_buf_type */ + struct v4l2_rect bounds; + struct v4l2_rect defrect; + struct v4l2_fract pixelaspect; +}; + +struct v4l2_crop { + u_int32_t type; /* enum v4l2_buf_type */ + struct v4l2_rect c; +}; + +/** + * struct v4l2_selection - selection info + * @type: buffer type (do not use *_MPLANE types) + * @target: Selection target, used to choose one of possible rectangles; + * defined in v4l2-common.h; V4L2_SEL_TGT_* . + * @flags: constraints flags, defined in v4l2-common.h; V4L2_SEL_FLAG_*. + * @r: coordinates of selection window + * @reserved: for future use, rounds structure size to 64 bytes, set to zero + * + * Hardware may use multiple helper windows to process a video stream. + * The structure is used to exchange this selection areas between + * an application and a driver. + */ +struct v4l2_selection { + u_int32_t type; + u_int32_t target; + u_int32_t flags; + struct v4l2_rect r; + u_int32_t reserved[9]; +}; + + +/* + * A N A L O G V I D E O S T A N D A R D + */ + +typedef u_int64_t v4l2_std_id; + +/* + * Attention: Keep the V4L2_STD_* bit definitions in sync with + * include/dt-bindings/display/sdtv-standards.h SDTV_STD_* bit definitions. + */ +/* one bit for each */ +#define V4L2_STD_PAL_B ((v4l2_std_id)0x00000001) +#define V4L2_STD_PAL_B1 ((v4l2_std_id)0x00000002) +#define V4L2_STD_PAL_G ((v4l2_std_id)0x00000004) +#define V4L2_STD_PAL_H ((v4l2_std_id)0x00000008) +#define V4L2_STD_PAL_I ((v4l2_std_id)0x00000010) +#define V4L2_STD_PAL_D ((v4l2_std_id)0x00000020) +#define V4L2_STD_PAL_D1 ((v4l2_std_id)0x00000040) +#define V4L2_STD_PAL_K ((v4l2_std_id)0x00000080) + +#define V4L2_STD_PAL_M ((v4l2_std_id)0x00000100) +#define V4L2_STD_PAL_N ((v4l2_std_id)0x00000200) +#define V4L2_STD_PAL_Nc ((v4l2_std_id)0x00000400) +#define V4L2_STD_PAL_60 ((v4l2_std_id)0x00000800) + +#define V4L2_STD_NTSC_M ((v4l2_std_id)0x00001000) /* BTSC */ +#define V4L2_STD_NTSC_M_JP ((v4l2_std_id)0x00002000) /* EIA-J */ +#define V4L2_STD_NTSC_443 ((v4l2_std_id)0x00004000) +#define V4L2_STD_NTSC_M_KR ((v4l2_std_id)0x00008000) /* FM A2 */ + +#define V4L2_STD_SECAM_B ((v4l2_std_id)0x00010000) +#define V4L2_STD_SECAM_D ((v4l2_std_id)0x00020000) +#define V4L2_STD_SECAM_G ((v4l2_std_id)0x00040000) +#define V4L2_STD_SECAM_H ((v4l2_std_id)0x00080000) +#define V4L2_STD_SECAM_K ((v4l2_std_id)0x00100000) +#define V4L2_STD_SECAM_K1 ((v4l2_std_id)0x00200000) +#define V4L2_STD_SECAM_L ((v4l2_std_id)0x00400000) +#define V4L2_STD_SECAM_LC ((v4l2_std_id)0x00800000) + +/* ATSC/HDTV */ +#define V4L2_STD_ATSC_8_VSB ((v4l2_std_id)0x01000000) +#define V4L2_STD_ATSC_16_VSB ((v4l2_std_id)0x02000000) + +/* FIXME: + Although std_id is 64 bits, there is an issue on PPC32 architecture that + makes switch(u_int64_t) to break. So, there's a hack on v4l2-common.c rounding + this value to 32 bits. + As, currently, the max value is for V4L2_STD_ATSC_16_VSB (30 bits wide), + it should work fine. However, if needed to add more than two standards, + v4l2-common.c should be fixed. + */ + +/* + * Some macros to merge video standards in order to make live easier for the + * drivers and V4L2 applications + */ + +/* + * "Common" NTSC/M - It should be noticed that V4L2_STD_NTSC_443 is + * Missing here. + */ +#define V4L2_STD_NTSC (V4L2_STD_NTSC_M |\ + V4L2_STD_NTSC_M_JP |\ + V4L2_STD_NTSC_M_KR) +/* Secam macros */ +#define V4L2_STD_SECAM_DK (V4L2_STD_SECAM_D |\ + V4L2_STD_SECAM_K |\ + V4L2_STD_SECAM_K1) +/* All Secam Standards */ +#define V4L2_STD_SECAM (V4L2_STD_SECAM_B |\ + V4L2_STD_SECAM_G |\ + V4L2_STD_SECAM_H |\ + V4L2_STD_SECAM_DK |\ + V4L2_STD_SECAM_L |\ + V4L2_STD_SECAM_LC) +/* PAL macros */ +#define V4L2_STD_PAL_BG (V4L2_STD_PAL_B |\ + V4L2_STD_PAL_B1 |\ + V4L2_STD_PAL_G) +#define V4L2_STD_PAL_DK (V4L2_STD_PAL_D |\ + V4L2_STD_PAL_D1 |\ + V4L2_STD_PAL_K) +/* + * "Common" PAL - This macro is there to be compatible with the old + * V4L1 concept of "PAL": /BGDKHI. + * Several PAL standards are missing here: /M, /N and /Nc + */ +#define V4L2_STD_PAL (V4L2_STD_PAL_BG |\ + V4L2_STD_PAL_DK |\ + V4L2_STD_PAL_H |\ + V4L2_STD_PAL_I) +/* Chroma "agnostic" standards */ +#define V4L2_STD_B (V4L2_STD_PAL_B |\ + V4L2_STD_PAL_B1 |\ + V4L2_STD_SECAM_B) +#define V4L2_STD_G (V4L2_STD_PAL_G |\ + V4L2_STD_SECAM_G) +#define V4L2_STD_H (V4L2_STD_PAL_H |\ + V4L2_STD_SECAM_H) +#define V4L2_STD_L (V4L2_STD_SECAM_L |\ + V4L2_STD_SECAM_LC) +#define V4L2_STD_GH (V4L2_STD_G |\ + V4L2_STD_H) +#define V4L2_STD_DK (V4L2_STD_PAL_DK |\ + V4L2_STD_SECAM_DK) +#define V4L2_STD_BG (V4L2_STD_B |\ + V4L2_STD_G) +#define V4L2_STD_MN (V4L2_STD_PAL_M |\ + V4L2_STD_PAL_N |\ + V4L2_STD_PAL_Nc |\ + V4L2_STD_NTSC) + +/* Standards where MTS/BTSC stereo could be found */ +#define V4L2_STD_MTS (V4L2_STD_NTSC_M |\ + V4L2_STD_PAL_M |\ + V4L2_STD_PAL_N |\ + V4L2_STD_PAL_Nc) + +/* Standards for Countries with 60Hz Line frequency */ +#define V4L2_STD_525_60 (V4L2_STD_PAL_M |\ + V4L2_STD_PAL_60 |\ + V4L2_STD_NTSC |\ + V4L2_STD_NTSC_443) +/* Standards for Countries with 50Hz Line frequency */ +#define V4L2_STD_625_50 (V4L2_STD_PAL |\ + V4L2_STD_PAL_N |\ + V4L2_STD_PAL_Nc |\ + V4L2_STD_SECAM) + +#define V4L2_STD_ATSC (V4L2_STD_ATSC_8_VSB |\ + V4L2_STD_ATSC_16_VSB) +/* Macros with none and all analog standards */ +#define V4L2_STD_UNKNOWN 0 +#define V4L2_STD_ALL (V4L2_STD_525_60 |\ + V4L2_STD_625_50) + +struct v4l2_standard { + u_int32_t index; + v4l2_std_id id; + u_int8_t name[24]; + struct v4l2_fract frameperiod; /* Frames, not fields */ + u_int32_t framelines; + u_int32_t reserved[4]; +}; + +/* + * D V B T T I M I N G S + */ + +/** struct v4l2_bt_timings - BT.656/BT.1120 timing data + * @width: total width of the active video in pixels + * @height: total height of the active video in lines + * @interlaced: Interlaced or progressive + * @polarities: Positive or negative polarities + * @pixelclock: Pixel clock in HZ. Ex. 74.25MHz->74250000 + * @hfrontporch:Horizontal front porch in pixels + * @hsync: Horizontal Sync length in pixels + * @hbackporch: Horizontal back porch in pixels + * @vfrontporch:Vertical front porch in lines + * @vsync: Vertical Sync length in lines + * @vbackporch: Vertical back porch in lines + * @il_vfrontporch:Vertical front porch for the even field + * (aka field 2) of interlaced field formats + * @il_vsync: Vertical Sync length for the even field + * (aka field 2) of interlaced field formats + * @il_vbackporch:Vertical back porch for the even field + * (aka field 2) of interlaced field formats + * @standards: Standards the timing belongs to + * @flags: Flags + * @picture_aspect: The picture aspect ratio (hor/vert). + * @cea861_vic: VIC code as per the CEA-861 standard. + * @hdmi_vic: VIC code as per the HDMI standard. + * @reserved: Reserved fields, must be zeroed. + * + * A note regarding vertical interlaced timings: height refers to the total + * height of the active video frame (= two fields). The blanking timings refer + * to the blanking of each field. So the height of the total frame is + * calculated as follows: + * + * tot_height = height + vfrontporch + vsync + vbackporch + + * il_vfrontporch + il_vsync + il_vbackporch + * + * The active height of each field is height / 2. + */ +struct v4l2_bt_timings { + u_int32_t width; + u_int32_t height; + u_int32_t interlaced; + u_int32_t polarities; + u_int64_t pixelclock; + u_int32_t hfrontporch; + u_int32_t hsync; + u_int32_t hbackporch; + u_int32_t vfrontporch; + u_int32_t vsync; + u_int32_t vbackporch; + u_int32_t il_vfrontporch; + u_int32_t il_vsync; + u_int32_t il_vbackporch; + u_int32_t standards; + u_int32_t flags; + struct v4l2_fract picture_aspect; + u_int8_t cea861_vic; + u_int8_t hdmi_vic; + u_int8_t reserved[46]; +} __attribute__ ((packed)); + +/* Interlaced or progressive format */ +#define V4L2_DV_PROGRESSIVE 0 +#define V4L2_DV_INTERLACED 1 + +/* Polarities. If bit is not set, it is assumed to be negative polarity */ +#define V4L2_DV_VSYNC_POS_POL 0x00000001 +#define V4L2_DV_HSYNC_POS_POL 0x00000002 + +/* Timings standards */ +#define V4L2_DV_BT_STD_CEA861 (1 << 0) /* CEA-861 Digital TV Profile */ +#define V4L2_DV_BT_STD_DMT (1 << 1) /* VESA Discrete Monitor Timings */ +#define V4L2_DV_BT_STD_CVT (1 << 2) /* VESA Coordinated Video Timings */ +#define V4L2_DV_BT_STD_GTF (1 << 3) /* VESA Generalized Timings Formula */ +#define V4L2_DV_BT_STD_SDI (1 << 4) /* SDI Timings */ + +/* Flags */ + +/* + * CVT/GTF specific: timing uses reduced blanking (CVT) or the 'Secondary + * GTF' curve (GTF). In both cases the horizontal and/or vertical blanking + * intervals are reduced, allowing a higher resolution over the same + * bandwidth. This is a read-only flag. + */ +#define V4L2_DV_FL_REDUCED_BLANKING (1 << 0) +/* + * CEA-861 specific: set for CEA-861 formats with a framerate of a multiple + * of six. These formats can be optionally played at 1 / 1.001 speed. + * This is a read-only flag. + */ +#define V4L2_DV_FL_CAN_REDUCE_FPS (1 << 1) +/* + * CEA-861 specific: only valid for video transmitters, the flag is cleared + * by receivers. + * If the framerate of the format is a multiple of six, then the pixelclock + * used to set up the transmitter is divided by 1.001 to make it compatible + * with 60 Hz based standards such as NTSC and PAL-M that use a framerate of + * 29.97 Hz. Otherwise this flag is cleared. If the transmitter can't generate + * such frequencies, then the flag will also be cleared. + */ +#define V4L2_DV_FL_REDUCED_FPS (1 << 2) +/* + * Specific to interlaced formats: if set, then field 1 is really one half-line + * longer and field 2 is really one half-line shorter, so each field has + * exactly the same number of half-lines. Whether half-lines can be detected + * or used depends on the hardware. + */ +#define V4L2_DV_FL_HALF_LINE (1 << 3) +/* + * If set, then this is a Consumer Electronics (CE) video format. Such formats + * differ from other formats (commonly called IT formats) in that if RGB + * encoding is used then by default the RGB values use limited range (i.e. + * use the range 16-235) as opposed to 0-255. All formats defined in CEA-861 + * except for the 640x480 format are CE formats. + */ +#define V4L2_DV_FL_IS_CE_VIDEO (1 << 4) +/* Some formats like SMPTE-125M have an interlaced signal with a odd + * total height. For these formats, if this flag is set, the first + * field has the extra line. If not, it is the second field. + */ +#define V4L2_DV_FL_FIRST_FIELD_EXTRA_LINE (1 << 5) +/* + * If set, then the picture_aspect field is valid. Otherwise assume that the + * pixels are square, so the picture aspect ratio is the same as the width to + * height ratio. + */ +#define V4L2_DV_FL_HAS_PICTURE_ASPECT (1 << 6) +/* + * If set, then the cea861_vic field is valid and contains the Video + * Identification Code as per the CEA-861 standard. + */ +#define V4L2_DV_FL_HAS_CEA861_VIC (1 << 7) +/* + * If set, then the hdmi_vic field is valid and contains the Video + * Identification Code as per the HDMI standard (HDMI Vendor Specific + * InfoFrame). + */ +#define V4L2_DV_FL_HAS_HDMI_VIC (1 << 8) +/* + * CEA-861 specific: only valid for video receivers. + * If set, then HW can detect the difference between regular FPS and + * 1000/1001 FPS. Note: This flag is only valid for HDMI VIC codes with + * the V4L2_DV_FL_CAN_REDUCE_FPS flag set. + */ +#define V4L2_DV_FL_CAN_DETECT_REDUCED_FPS (1 << 9) + +/* A few useful defines to calculate the total blanking and frame sizes */ +#define V4L2_DV_BT_BLANKING_WIDTH(bt) \ + ((bt)->hfrontporch + (bt)->hsync + (bt)->hbackporch) +#define V4L2_DV_BT_FRAME_WIDTH(bt) \ + ((bt)->width + V4L2_DV_BT_BLANKING_WIDTH(bt)) +#define V4L2_DV_BT_BLANKING_HEIGHT(bt) \ + ((bt)->vfrontporch + (bt)->vsync + (bt)->vbackporch + \ + ((bt)->interlaced ? \ + ((bt)->il_vfrontporch + (bt)->il_vsync + (bt)->il_vbackporch) : 0)) +#define V4L2_DV_BT_FRAME_HEIGHT(bt) \ + ((bt)->height + V4L2_DV_BT_BLANKING_HEIGHT(bt)) + +/** struct v4l2_dv_timings - DV timings + * @type: the type of the timings + * @bt: BT656/1120 timings + */ +struct v4l2_dv_timings { + u_int32_t type; + union { + struct v4l2_bt_timings bt; + u_int32_t reserved[32]; + }; +} __attribute__ ((packed)); + +/* Values for the type field */ +#define V4L2_DV_BT_656_1120 0 /* BT.656/1120 timing type */ + + +/** struct v4l2_enum_dv_timings - DV timings enumeration + * @index: enumeration index + * @pad: the pad number for which to enumerate timings (used with + * v4l-subdev nodes only) + * @reserved: must be zeroed + * @timings: the timings for the given index + */ +struct v4l2_enum_dv_timings { + u_int32_t index; + u_int32_t pad; + u_int32_t reserved[2]; + struct v4l2_dv_timings timings; +}; + +/** struct v4l2_bt_timings_cap - BT.656/BT.1120 timing capabilities + * @min_width: width in pixels + * @max_width: width in pixels + * @min_height: height in lines + * @max_height: height in lines + * @min_pixelclock: Pixel clock in HZ. Ex. 74.25MHz->74250000 + * @max_pixelclock: Pixel clock in HZ. Ex. 74.25MHz->74250000 + * @standards: Supported standards + * @capabilities: Supported capabilities + * @reserved: Must be zeroed + */ +struct v4l2_bt_timings_cap { + u_int32_t min_width; + u_int32_t max_width; + u_int32_t min_height; + u_int32_t max_height; + u_int64_t min_pixelclock; + u_int64_t max_pixelclock; + u_int32_t standards; + u_int32_t capabilities; + u_int32_t reserved[16]; +} __attribute__ ((packed)); + +/* Supports interlaced formats */ +#define V4L2_DV_BT_CAP_INTERLACED (1 << 0) +/* Supports progressive formats */ +#define V4L2_DV_BT_CAP_PROGRESSIVE (1 << 1) +/* Supports CVT/GTF reduced blanking */ +#define V4L2_DV_BT_CAP_REDUCED_BLANKING (1 << 2) +/* Supports custom formats */ +#define V4L2_DV_BT_CAP_CUSTOM (1 << 3) + +/** struct v4l2_dv_timings_cap - DV timings capabilities + * @type: the type of the timings (same as in struct v4l2_dv_timings) + * @pad: the pad number for which to query capabilities (used with + * v4l-subdev nodes only) + * @bt: the BT656/1120 timings capabilities + */ +struct v4l2_dv_timings_cap { + u_int32_t type; + u_int32_t pad; + u_int32_t reserved[2]; + union { + struct v4l2_bt_timings_cap bt; + u_int32_t raw_data[32]; + }; +}; + + +/* + * V I D E O I N P U T S + */ +struct v4l2_input { + u_int32_t index; /* Which input */ + u_int8_t name[32]; /* Label */ + u_int32_t type; /* Type of input */ + u_int32_t audioset; /* Associated audios (bitfield) */ + u_int32_t tuner; /* Tuner index */ + v4l2_std_id std; + u_int32_t status; + u_int32_t capabilities; + u_int32_t reserved[3]; +}; + +/* Values for the 'type' field */ +#define V4L2_INPUT_TYPE_TUNER 1 +#define V4L2_INPUT_TYPE_CAMERA 2 +#define V4L2_INPUT_TYPE_TOUCH 3 + +/* field 'status' - general */ +#define V4L2_IN_ST_NO_POWER 0x00000001 /* Attached device is off */ +#define V4L2_IN_ST_NO_SIGNAL 0x00000002 +#define V4L2_IN_ST_NO_COLOR 0x00000004 + +/* field 'status' - sensor orientation */ +/* If sensor is mounted upside down set both bits */ +#define V4L2_IN_ST_HFLIP 0x00000010 /* Frames are flipped horizontally */ +#define V4L2_IN_ST_VFLIP 0x00000020 /* Frames are flipped vertically */ + +/* field 'status' - analog */ +#define V4L2_IN_ST_NO_H_LOCK 0x00000100 /* No horizontal sync lock */ +#define V4L2_IN_ST_COLOR_KILL 0x00000200 /* Color killer is active */ +#define V4L2_IN_ST_NO_V_LOCK 0x00000400 /* No vertical sync lock */ +#define V4L2_IN_ST_NO_STD_LOCK 0x00000800 /* No standard format lock */ + +/* field 'status' - digital */ +#define V4L2_IN_ST_NO_SYNC 0x00010000 /* No synchronization lock */ +#define V4L2_IN_ST_NO_EQU 0x00020000 /* No equalizer lock */ +#define V4L2_IN_ST_NO_CARRIER 0x00040000 /* Carrier recovery failed */ + +/* field 'status' - VCR and set-top box */ +#define V4L2_IN_ST_MACROVISION 0x01000000 /* Macrovision detected */ +#define V4L2_IN_ST_NO_ACCESS 0x02000000 /* Conditional access denied */ +#define V4L2_IN_ST_VTR 0x04000000 /* VTR time constant */ + +/* capabilities flags */ +#define V4L2_IN_CAP_DV_TIMINGS 0x00000002 /* Supports S_DV_TIMINGS */ +#define V4L2_IN_CAP_CUSTOM_TIMINGS V4L2_IN_CAP_DV_TIMINGS /* For compatibility */ +#define V4L2_IN_CAP_STD 0x00000004 /* Supports S_STD */ +#define V4L2_IN_CAP_NATIVE_SIZE 0x00000008 /* Supports setting native size */ + +/* + * V I D E O O U T P U T S + */ +struct v4l2_output { + u_int32_t index; /* Which output */ + u_int8_t name[32]; /* Label */ + u_int32_t type; /* Type of output */ + u_int32_t audioset; /* Associated audios (bitfield) */ + u_int32_t modulator; /* Associated modulator */ + v4l2_std_id std; + u_int32_t capabilities; + u_int32_t reserved[3]; +}; +/* Values for the 'type' field */ +#define V4L2_OUTPUT_TYPE_MODULATOR 1 +#define V4L2_OUTPUT_TYPE_ANALOG 2 +#define V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY 3 + +/* capabilities flags */ +#define V4L2_OUT_CAP_DV_TIMINGS 0x00000002 /* Supports S_DV_TIMINGS */ +#define V4L2_OUT_CAP_CUSTOM_TIMINGS V4L2_OUT_CAP_DV_TIMINGS /* For compatibility */ +#define V4L2_OUT_CAP_STD 0x00000004 /* Supports S_STD */ +#define V4L2_OUT_CAP_NATIVE_SIZE 0x00000008 /* Supports setting native size */ + +/* + * C O N T R O L S + */ +struct v4l2_control { + u_int32_t id; + int32_t value; +}; + +struct v4l2_ext_control { + u_int32_t id; + u_int32_t size; + u_int32_t reserved2[1]; + union { + int32_t value; + int64_t value64; + char __user *string; + u_int8_t __user *p_u8; + u_int16_t __user *p_u16; + u_int32_t __user *p_u32; + int32_t __user *p_s32; + int64_t __user *p_s64; + struct v4l2_area __user *p_area; + struct v4l2_rect __user *p_rect; + struct v4l2_ctrl_h264_sps __user *p_h264_sps; + struct v4l2_ctrl_h264_pps __user *p_h264_pps; + struct v4l2_ctrl_h264_scaling_matrix __user *p_h264_scaling_matrix; + struct v4l2_ctrl_h264_pred_weights __user *p_h264_pred_weights; + struct v4l2_ctrl_h264_slice_params __user *p_h264_slice_params; + struct v4l2_ctrl_h264_decode_params __user *p_h264_decode_params; + struct v4l2_ctrl_fwht_params __user *p_fwht_params; + struct v4l2_ctrl_vp8_frame __user *p_vp8_frame; + struct v4l2_ctrl_mpeg2_sequence __user *p_mpeg2_sequence; + struct v4l2_ctrl_mpeg2_picture __user *p_mpeg2_picture; + struct v4l2_ctrl_mpeg2_quantisation __user *p_mpeg2_quantisation; + struct v4l2_ctrl_vp9_compressed_hdr __user *p_vp9_compressed_hdr_probs; + struct v4l2_ctrl_vp9_frame __user *p_vp9_frame; + struct v4l2_ctrl_hevc_sps __user *p_hevc_sps; + struct v4l2_ctrl_hevc_pps __user *p_hevc_pps; + struct v4l2_ctrl_hevc_slice_params __user *p_hevc_slice_params; + struct v4l2_ctrl_hevc_scaling_matrix __user *p_hevc_scaling_matrix; + struct v4l2_ctrl_hevc_decode_params __user *p_hevc_decode_params; + struct v4l2_ctrl_av1_sequence __user *p_av1_sequence; + struct v4l2_ctrl_av1_tile_group_entry __user *p_av1_tile_group_entry; + struct v4l2_ctrl_av1_frame __user *p_av1_frame; + struct v4l2_ctrl_av1_film_grain __user *p_av1_film_grain; + struct v4l2_ctrl_hdr10_cll_info __user *p_hdr10_cll_info; + struct v4l2_ctrl_hdr10_mastering_display __user *p_hdr10_mastering_display; + void __user *ptr; + } __attribute__ ((packed)); +} __attribute__ ((packed)); + +struct v4l2_ext_controls { + union { + u_int32_t ctrl_class; + u_int32_t which; + }; + u_int32_t count; + u_int32_t error_idx; + int32_t request_fd; + u_int32_t reserved[1]; + struct v4l2_ext_control *controls; +}; + +#define V4L2_CTRL_ID_MASK (0x0fffffff) +#define V4L2_CTRL_ID2CLASS(id) ((id) & 0x0fff0000UL) +#define V4L2_CTRL_ID2WHICH(id) ((id) & 0x0fff0000UL) +#define V4L2_CTRL_DRIVER_PRIV(id) (((id) & 0xffff) >= 0x1000) +#define V4L2_CTRL_MAX_DIMS (4) +#define V4L2_CTRL_WHICH_CUR_VAL 0 +#define V4L2_CTRL_WHICH_DEF_VAL 0x0f000000 +#define V4L2_CTRL_WHICH_REQUEST_VAL 0x0f010000 +#define V4L2_CTRL_WHICH_MIN_VAL 0x0f020000 +#define V4L2_CTRL_WHICH_MAX_VAL 0x0f030000 + +enum v4l2_ctrl_type { + V4L2_CTRL_TYPE_INTEGER = 1, + V4L2_CTRL_TYPE_BOOLEAN = 2, + V4L2_CTRL_TYPE_MENU = 3, + V4L2_CTRL_TYPE_BUTTON = 4, + V4L2_CTRL_TYPE_INTEGER64 = 5, + V4L2_CTRL_TYPE_CTRL_CLASS = 6, + V4L2_CTRL_TYPE_STRING = 7, + V4L2_CTRL_TYPE_BITMASK = 8, + V4L2_CTRL_TYPE_INTEGER_MENU = 9, + + /* Compound types are >= 0x0100 */ + V4L2_CTRL_COMPOUND_TYPES = 0x0100, + V4L2_CTRL_TYPE_U8 = 0x0100, + V4L2_CTRL_TYPE_U16 = 0x0101, + V4L2_CTRL_TYPE_U32 = 0x0102, + V4L2_CTRL_TYPE_AREA = 0x0106, + V4L2_CTRL_TYPE_RECT = 0x0107, + + V4L2_CTRL_TYPE_HDR10_CLL_INFO = 0x0110, + V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY = 0x0111, + + V4L2_CTRL_TYPE_H264_SPS = 0x0200, + V4L2_CTRL_TYPE_H264_PPS = 0x0201, + V4L2_CTRL_TYPE_H264_SCALING_MATRIX = 0x0202, + V4L2_CTRL_TYPE_H264_SLICE_PARAMS = 0x0203, + V4L2_CTRL_TYPE_H264_DECODE_PARAMS = 0x0204, + V4L2_CTRL_TYPE_H264_PRED_WEIGHTS = 0x0205, + + V4L2_CTRL_TYPE_FWHT_PARAMS = 0x0220, + + V4L2_CTRL_TYPE_VP8_FRAME = 0x0240, + + V4L2_CTRL_TYPE_MPEG2_QUANTISATION = 0x0250, + V4L2_CTRL_TYPE_MPEG2_SEQUENCE = 0x0251, + V4L2_CTRL_TYPE_MPEG2_PICTURE = 0x0252, + + V4L2_CTRL_TYPE_VP9_COMPRESSED_HDR = 0x0260, + V4L2_CTRL_TYPE_VP9_FRAME = 0x0261, + + V4L2_CTRL_TYPE_HEVC_SPS = 0x0270, + V4L2_CTRL_TYPE_HEVC_PPS = 0x0271, + V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS = 0x0272, + V4L2_CTRL_TYPE_HEVC_SCALING_MATRIX = 0x0273, + V4L2_CTRL_TYPE_HEVC_DECODE_PARAMS = 0x0274, + + V4L2_CTRL_TYPE_AV1_SEQUENCE = 0x280, + V4L2_CTRL_TYPE_AV1_TILE_GROUP_ENTRY = 0x281, + V4L2_CTRL_TYPE_AV1_FRAME = 0x282, + V4L2_CTRL_TYPE_AV1_FILM_GRAIN = 0x283, +}; + +/* Used in the VIDIOC_QUERYCTRL ioctl for querying controls */ +struct v4l2_queryctrl { + u_int32_t id; + u_int32_t type; /* enum v4l2_ctrl_type */ + u_int8_t name[32]; /* Whatever */ + int32_t minimum; /* Note signedness */ + int32_t maximum; + int32_t step; + int32_t default_value; + u_int32_t flags; + u_int32_t reserved[2]; +}; + +/* Used in the VIDIOC_QUERY_EXT_CTRL ioctl for querying extended controls */ +struct v4l2_query_ext_ctrl { + u_int32_t id; + u_int32_t type; + char name[32]; + int64_t minimum; + int64_t maximum; + u_int64_t step; + int64_t default_value; + u_int32_t flags; + u_int32_t elem_size; + u_int32_t elems; + u_int32_t nr_of_dims; + u_int32_t dims[V4L2_CTRL_MAX_DIMS]; + u_int32_t reserved[32]; +}; + +/* Used in the VIDIOC_QUERYMENU ioctl for querying menu items */ +struct v4l2_querymenu { + u_int32_t id; + u_int32_t index; + union { + u_int8_t name[32]; /* Whatever */ + int64_t value; + }; + u_int32_t reserved; +} __attribute__ ((packed)); + +/* Control flags */ +#define V4L2_CTRL_FLAG_DISABLED 0x0001 +#define V4L2_CTRL_FLAG_GRABBED 0x0002 +#define V4L2_CTRL_FLAG_READ_ONLY 0x0004 +#define V4L2_CTRL_FLAG_UPDATE 0x0008 +#define V4L2_CTRL_FLAG_INACTIVE 0x0010 +#define V4L2_CTRL_FLAG_SLIDER 0x0020 +#define V4L2_CTRL_FLAG_WRITE_ONLY 0x0040 +#define V4L2_CTRL_FLAG_VOLATILE 0x0080 +#define V4L2_CTRL_FLAG_HAS_PAYLOAD 0x0100 +#define V4L2_CTRL_FLAG_EXECUTE_ON_WRITE 0x0200 +#define V4L2_CTRL_FLAG_MODIFY_LAYOUT 0x0400 +#define V4L2_CTRL_FLAG_DYNAMIC_ARRAY 0x0800 +#define V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX 0x1000 + +/* Query flags, to be ORed with the control ID */ +#define V4L2_CTRL_FLAG_NEXT_CTRL 0x80000000 +#define V4L2_CTRL_FLAG_NEXT_COMPOUND 0x40000000 + +/* User-class control IDs defined by V4L2 */ +#define V4L2_CID_MAX_CTRLS 1024 +/* IDs reserved for driver specific controls */ +#define V4L2_CID_PRIVATE_BASE 0x08000000 + + +/* + * T U N I N G + */ +struct v4l2_tuner { + u_int32_t index; + u_int8_t name[32]; + u_int32_t type; /* enum v4l2_tuner_type */ + u_int32_t capability; + u_int32_t rangelow; + u_int32_t rangehigh; + u_int32_t rxsubchans; + u_int32_t audmode; + int32_t signal; + int32_t afc; + u_int32_t reserved[4]; +}; + +struct v4l2_modulator { + u_int32_t index; + u_int8_t name[32]; + u_int32_t capability; + u_int32_t rangelow; + u_int32_t rangehigh; + u_int32_t txsubchans; + u_int32_t type; /* enum v4l2_tuner_type */ + u_int32_t reserved[3]; +}; + +/* Flags for the 'capability' field */ +#define V4L2_TUNER_CAP_LOW 0x0001 +#define V4L2_TUNER_CAP_NORM 0x0002 +#define V4L2_TUNER_CAP_HWSEEK_BOUNDED 0x0004 +#define V4L2_TUNER_CAP_HWSEEK_WRAP 0x0008 +#define V4L2_TUNER_CAP_STEREO 0x0010 +#define V4L2_TUNER_CAP_LANG2 0x0020 +#define V4L2_TUNER_CAP_SAP 0x0020 +#define V4L2_TUNER_CAP_LANG1 0x0040 +#define V4L2_TUNER_CAP_RDS 0x0080 +#define V4L2_TUNER_CAP_RDS_BLOCK_IO 0x0100 +#define V4L2_TUNER_CAP_RDS_CONTROLS 0x0200 +#define V4L2_TUNER_CAP_FREQ_BANDS 0x0400 +#define V4L2_TUNER_CAP_HWSEEK_PROG_LIM 0x0800 +#define V4L2_TUNER_CAP_1HZ 0x1000 + +/* Flags for the 'rxsubchans' field */ +#define V4L2_TUNER_SUB_MONO 0x0001 +#define V4L2_TUNER_SUB_STEREO 0x0002 +#define V4L2_TUNER_SUB_LANG2 0x0004 +#define V4L2_TUNER_SUB_SAP 0x0004 +#define V4L2_TUNER_SUB_LANG1 0x0008 +#define V4L2_TUNER_SUB_RDS 0x0010 + +/* Values for the 'audmode' field */ +#define V4L2_TUNER_MODE_MONO 0x0000 +#define V4L2_TUNER_MODE_STEREO 0x0001 +#define V4L2_TUNER_MODE_LANG2 0x0002 +#define V4L2_TUNER_MODE_SAP 0x0002 +#define V4L2_TUNER_MODE_LANG1 0x0003 +#define V4L2_TUNER_MODE_LANG1_LANG2 0x0004 + +struct v4l2_frequency { + u_int32_t tuner; + u_int32_t type; /* enum v4l2_tuner_type */ + u_int32_t frequency; + u_int32_t reserved[8]; +}; + +#define V4L2_BAND_MODULATION_VSB (1 << 1) +#define V4L2_BAND_MODULATION_FM (1 << 2) +#define V4L2_BAND_MODULATION_AM (1 << 3) + +struct v4l2_frequency_band { + u_int32_t tuner; + u_int32_t type; /* enum v4l2_tuner_type */ + u_int32_t index; + u_int32_t capability; + u_int32_t rangelow; + u_int32_t rangehigh; + u_int32_t modulation; + u_int32_t reserved[9]; +}; + +struct v4l2_hw_freq_seek { + u_int32_t tuner; + u_int32_t type; /* enum v4l2_tuner_type */ + u_int32_t seek_upward; + u_int32_t wrap_around; + u_int32_t spacing; + u_int32_t rangelow; + u_int32_t rangehigh; + u_int32_t reserved[5]; +}; + +/* + * R D S + */ + +struct v4l2_rds_data { + u_int8_t lsb; + u_int8_t msb; + u_int8_t block; +} __attribute__ ((packed)); + +#define V4L2_RDS_BLOCK_MSK 0x7 +#define V4L2_RDS_BLOCK_A 0 +#define V4L2_RDS_BLOCK_B 1 +#define V4L2_RDS_BLOCK_C 2 +#define V4L2_RDS_BLOCK_D 3 +#define V4L2_RDS_BLOCK_C_ALT 4 +#define V4L2_RDS_BLOCK_INVALID 7 + +#define V4L2_RDS_BLOCK_CORRECTED 0x40 +#define V4L2_RDS_BLOCK_ERROR 0x80 + +/* + * A U D I O + */ +struct v4l2_audio { + u_int32_t index; + u_int8_t name[32]; + u_int32_t capability; + u_int32_t mode; + u_int32_t reserved[2]; +}; + +/* Flags for the 'capability' field */ +#define V4L2_AUDCAP_STEREO 0x00001 +#define V4L2_AUDCAP_AVL 0x00002 + +/* Flags for the 'mode' field */ +#define V4L2_AUDMODE_AVL 0x00001 + +struct v4l2_audioout { + u_int32_t index; + u_int8_t name[32]; + u_int32_t capability; + u_int32_t mode; + u_int32_t reserved[2]; +}; + +/* + * M P E G S E R V I C E S + */ +#if 1 +#define V4L2_ENC_IDX_FRAME_I (0) +#define V4L2_ENC_IDX_FRAME_P (1) +#define V4L2_ENC_IDX_FRAME_B (2) +#define V4L2_ENC_IDX_FRAME_MASK (0xf) + +struct v4l2_enc_idx_entry { + u_int64_t offset; + u_int64_t pts; + u_int32_t length; + u_int32_t flags; + u_int32_t reserved[2]; +}; + +#define V4L2_ENC_IDX_ENTRIES (64) +struct v4l2_enc_idx { + u_int32_t entries; + u_int32_t entries_cap; + u_int32_t reserved[4]; + struct v4l2_enc_idx_entry entry[V4L2_ENC_IDX_ENTRIES]; +}; + + +#define V4L2_ENC_CMD_START (0) +#define V4L2_ENC_CMD_STOP (1) +#define V4L2_ENC_CMD_PAUSE (2) +#define V4L2_ENC_CMD_RESUME (3) + +/* Flags for V4L2_ENC_CMD_STOP */ +#define V4L2_ENC_CMD_STOP_AT_GOP_END (1 << 0) + +struct v4l2_encoder_cmd { + u_int32_t cmd; + u_int32_t flags; + union { + struct { + u_int32_t data[8]; + } raw; + }; +}; + +/* Decoder commands */ +#define V4L2_DEC_CMD_START (0) +#define V4L2_DEC_CMD_STOP (1) +#define V4L2_DEC_CMD_PAUSE (2) +#define V4L2_DEC_CMD_RESUME (3) +#define V4L2_DEC_CMD_FLUSH (4) + +/* Flags for V4L2_DEC_CMD_START */ +#define V4L2_DEC_CMD_START_MUTE_AUDIO (1 << 0) + +/* Flags for V4L2_DEC_CMD_PAUSE */ +#define V4L2_DEC_CMD_PAUSE_TO_BLACK (1 << 0) + +/* Flags for V4L2_DEC_CMD_STOP */ +#define V4L2_DEC_CMD_STOP_TO_BLACK (1 << 0) +#define V4L2_DEC_CMD_STOP_IMMEDIATELY (1 << 1) + +/* Play format requirements (returned by the driver): */ + +/* The decoder has no special format requirements */ +#define V4L2_DEC_START_FMT_NONE (0) +/* The decoder requires full GOPs */ +#define V4L2_DEC_START_FMT_GOP (1) + +/* The structure must be zeroed before use by the application + This ensures it can be extended safely in the future. */ +struct v4l2_decoder_cmd { + u_int32_t cmd; + u_int32_t flags; + union { + struct { + u_int64_t pts; + } stop; + + struct { + /* 0 or 1000 specifies normal speed, + 1 specifies forward single stepping, + -1 specifies backward single stepping, + >1: playback at speed/1000 of the normal speed, + <-1: reverse playback at (-speed/1000) of the normal speed. */ + int32_t speed; + u_int32_t format; + } start; + + struct { + u_int32_t data[16]; + } raw; + }; +}; +#endif + + +/* + * D A T A S E R V I C E S ( V B I ) + * + * Data services API by Michael Schimek + */ + +/* Raw VBI */ +struct v4l2_vbi_format { + u_int32_t sampling_rate; /* in 1 Hz */ + u_int32_t offset; + u_int32_t samples_per_line; + u_int32_t sample_format; /* V4L2_PIX_FMT_* */ + int32_t start[2]; + u_int32_t count[2]; + u_int32_t flags; /* V4L2_VBI_* */ + u_int32_t reserved[2]; /* must be zero */ +}; + +/* VBI flags */ +#define V4L2_VBI_UNSYNC (1 << 0) +#define V4L2_VBI_INTERLACED (1 << 1) + +/* ITU-R start lines for each field */ +#define V4L2_VBI_ITU_525_F1_START (1) +#define V4L2_VBI_ITU_525_F2_START (264) +#define V4L2_VBI_ITU_625_F1_START (1) +#define V4L2_VBI_ITU_625_F2_START (314) + +/* Sliced VBI + * + * This implements is a proposal V4L2 API to allow SLICED VBI + * required for some hardware encoders. It should change without + * notice in the definitive implementation. + */ + +struct v4l2_sliced_vbi_format { + u_int16_t service_set; + /* service_lines[0][...] specifies lines 0-23 (1-23 used) of the first field + service_lines[1][...] specifies lines 0-23 (1-23 used) of the second field + (equals frame lines 313-336 for 625 line video + standards, 263-286 for 525 line standards) */ + u_int16_t service_lines[2][24]; + u_int32_t io_size; + u_int32_t reserved[2]; /* must be zero */ +}; + +/* Teletext World System Teletext + (WST), defined on ITU-R BT.653-2 */ +#define V4L2_SLICED_TELETEXT_B (0x0001) +/* Video Program System, defined on ETS 300 231*/ +#define V4L2_SLICED_VPS (0x0400) +/* Closed Caption, defined on EIA-608 */ +#define V4L2_SLICED_CAPTION_525 (0x1000) +/* Wide Screen System, defined on ITU-R BT1119.1 */ +#define V4L2_SLICED_WSS_625 (0x4000) + +#define V4L2_SLICED_VBI_525 (V4L2_SLICED_CAPTION_525) +#define V4L2_SLICED_VBI_625 (V4L2_SLICED_TELETEXT_B | V4L2_SLICED_VPS | V4L2_SLICED_WSS_625) + +struct v4l2_sliced_vbi_cap { + u_int16_t service_set; + /* service_lines[0][...] specifies lines 0-23 (1-23 used) of the first field + service_lines[1][...] specifies lines 0-23 (1-23 used) of the second field + (equals frame lines 313-336 for 625 line video + standards, 263-286 for 525 line standards) */ + u_int16_t service_lines[2][24]; + u_int32_t type; /* enum v4l2_buf_type */ + u_int32_t reserved[3]; /* must be 0 */ +}; + +struct v4l2_sliced_vbi_data { + u_int32_t id; + u_int32_t field; /* 0: first field, 1: second field */ + u_int32_t line; /* 1-23 */ + u_int32_t reserved; /* must be 0 */ + u_int8_t data[48]; +}; + +/* + * Sliced VBI data inserted into MPEG Streams + */ + +/* + * V4L2_MPEG_STREAM_VBI_FMT_IVTV: + * + * Structure of payload contained in an MPEG 2 Private Stream 1 PES Packet in an + * MPEG-2 Program Pack that contains V4L2_MPEG_STREAM_VBI_FMT_IVTV Sliced VBI + * data + * + * Note, the MPEG-2 Program Pack and Private Stream 1 PES packet header + * definitions are not included here. See the MPEG-2 specifications for details + * on these headers. + */ + +/* Line type IDs */ +#define V4L2_MPEG_VBI_IVTV_TELETEXT_B (1) +#define V4L2_MPEG_VBI_IVTV_CAPTION_525 (4) +#define V4L2_MPEG_VBI_IVTV_WSS_625 (5) +#define V4L2_MPEG_VBI_IVTV_VPS (7) + +struct v4l2_mpeg_vbi_itv0_line { + u_int8_t id; /* One of V4L2_MPEG_VBI_IVTV_* above */ + u_int8_t data[42]; /* Sliced VBI data for the line */ +} __attribute__ ((packed)); + +struct v4l2_mpeg_vbi_itv0 { + u_int32_t linemask[2]; /* Bitmasks of VBI service lines present */ + struct v4l2_mpeg_vbi_itv0_line line[35]; +} __attribute__ ((packed)); + +struct v4l2_mpeg_vbi_ITV0 { + struct v4l2_mpeg_vbi_itv0_line line[36]; +} __attribute__ ((packed)); + +#define V4L2_MPEG_VBI_IVTV_MAGIC0 "itv0" +#define V4L2_MPEG_VBI_IVTV_MAGIC1 "ITV0" + +struct v4l2_mpeg_vbi_fmt_ivtv { + u_int8_t magic[4]; + union { + struct v4l2_mpeg_vbi_itv0 itv0; + struct v4l2_mpeg_vbi_ITV0 ITV0; + }; +} __attribute__ ((packed)); + +/* + * A G G R E G A T E S T R U C T U R E S + */ + +/** + * struct v4l2_plane_pix_format - additional, per-plane format definition + * @sizeimage: maximum size in bytes required for data, for which + * this plane will be used + * @bytesperline: distance in bytes between the leftmost pixels in two + * adjacent lines + * @reserved: drivers and applications must zero this array + */ +struct v4l2_plane_pix_format { + u_int32_t sizeimage; + u_int32_t bytesperline; + u_int16_t reserved[6]; +} __attribute__ ((packed)); + +/** + * struct v4l2_pix_format_mplane - multiplanar format definition + * @width: image width in pixels + * @height: image height in pixels + * @pixelformat: little endian four character code (fourcc) + * @field: enum v4l2_field; field order (for interlaced video) + * @colorspace: enum v4l2_colorspace; supplemental to pixelformat + * @plane_fmt: per-plane information + * @num_planes: number of planes for this format + * @flags: format flags (V4L2_PIX_FMT_FLAG_*) + * @ycbcr_enc: enum v4l2_ycbcr_encoding, Y'CbCr encoding + * @hsv_enc: enum v4l2_hsv_encoding, HSV encoding + * @quantization: enum v4l2_quantization, colorspace quantization + * @xfer_func: enum v4l2_xfer_func, colorspace transfer function + * @reserved: drivers and applications must zero this array + */ +struct v4l2_pix_format_mplane { + u_int32_t width; + u_int32_t height; + u_int32_t pixelformat; + u_int32_t field; + u_int32_t colorspace; + + struct v4l2_plane_pix_format plane_fmt[VIDEO_MAX_PLANES]; + u_int8_t num_planes; + u_int8_t flags; + union { + u_int8_t ycbcr_enc; + u_int8_t hsv_enc; + }; + u_int8_t quantization; + u_int8_t xfer_func; + u_int8_t reserved[7]; +} __attribute__ ((packed)); + +/** + * struct v4l2_sdr_format - SDR format definition + * @pixelformat: little endian four character code (fourcc) + * @buffersize: maximum size in bytes required for data + * @reserved: drivers and applications must zero this array + */ +struct v4l2_sdr_format { + u_int32_t pixelformat; + u_int32_t buffersize; + u_int8_t reserved[24]; +} __attribute__ ((packed)); + +/** + * struct v4l2_meta_format - metadata format definition + * @dataformat: little endian four character code (fourcc) + * @buffersize: maximum size in bytes required for data + * @width: number of data units of data per line (valid for line + * based formats only, see format documentation) + * @height: number of lines of data per buffer (valid for line based + * formats only) + * @bytesperline: offset between the beginnings of two adjacent lines in + * bytes (valid for line based formats only) + */ +struct v4l2_meta_format { + u_int32_t dataformat; + u_int32_t buffersize; + u_int32_t width; + u_int32_t height; + u_int32_t bytesperline; +} __attribute__ ((packed)); + +/** + * struct v4l2_format - stream data format + * @type: enum v4l2_buf_type; type of the data stream + * @fmt.pix: definition of an image format + * @fmt.pix_mp: definition of a multiplanar image format + * @fmt.win: definition of an overlaid image + * @fmt.vbi: raw VBI capture or output parameters + * @fmt.sliced: sliced VBI capture or output parameters + * @fmt.raw_data: placeholder for future extensions and custom formats + * @fmt: union of @pix, @pix_mp, @win, @vbi, @sliced, @sdr, + * @meta and @raw_data + */ +struct v4l2_format { + u_int32_t type; + union { + struct v4l2_pix_format pix; /* V4L2_BUF_TYPE_VIDEO_CAPTURE */ + struct v4l2_pix_format_mplane pix_mp; /* V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE */ + struct v4l2_window win; /* V4L2_BUF_TYPE_VIDEO_OVERLAY */ + struct v4l2_vbi_format vbi; /* V4L2_BUF_TYPE_VBI_CAPTURE */ + struct v4l2_sliced_vbi_format sliced; /* V4L2_BUF_TYPE_SLICED_VBI_CAPTURE */ + struct v4l2_sdr_format sdr; /* V4L2_BUF_TYPE_SDR_CAPTURE */ + struct v4l2_meta_format meta; /* V4L2_BUF_TYPE_META_CAPTURE */ + u_int8_t raw_data[200]; /* user-defined */ + } fmt; +}; + +/* Stream type-dependent parameters + */ +struct v4l2_streamparm { + u_int32_t type; /* enum v4l2_buf_type */ + union { + struct v4l2_captureparm capture; + struct v4l2_outputparm output; + u_int8_t raw_data[200]; /* user-defined */ + } parm; +}; + +/* + * E V E N T S + */ + +#define V4L2_EVENT_ALL 0 +#define V4L2_EVENT_VSYNC 1 +#define V4L2_EVENT_EOS 2 +#define V4L2_EVENT_CTRL 3 +#define V4L2_EVENT_FRAME_SYNC 4 +#define V4L2_EVENT_SOURCE_CHANGE 5 +#define V4L2_EVENT_MOTION_DET 6 +#define V4L2_EVENT_PRIVATE_START 0x08000000 + +/* Payload for V4L2_EVENT_VSYNC */ +struct v4l2_event_vsync { + /* Can be V4L2_FIELD_ANY, _NONE, _TOP or _BOTTOM */ + u_int8_t field; +} __attribute__ ((packed)); + +/* Payload for V4L2_EVENT_CTRL */ +#define V4L2_EVENT_CTRL_CH_VALUE (1 << 0) +#define V4L2_EVENT_CTRL_CH_FLAGS (1 << 1) +#define V4L2_EVENT_CTRL_CH_RANGE (1 << 2) +#define V4L2_EVENT_CTRL_CH_DIMENSIONS (1 << 3) + +struct v4l2_event_ctrl { + u_int32_t changes; + u_int32_t type; + union { + int32_t value; + int64_t value64; + }; + u_int32_t flags; + int32_t minimum; + int32_t maximum; + int32_t step; + int32_t default_value; +}; + +struct v4l2_event_frame_sync { + u_int32_t frame_sequence; +}; + +#define V4L2_EVENT_SRC_CH_RESOLUTION (1 << 0) + +struct v4l2_event_src_change { + u_int32_t changes; +}; + +#define V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ (1 << 0) + +/** + * struct v4l2_event_motion_det - motion detection event + * @flags: if V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ is set, then the + * frame_sequence field is valid. + * @frame_sequence: the frame sequence number associated with this event. + * @region_mask: which regions detected motion. + */ +struct v4l2_event_motion_det { + u_int32_t flags; + u_int32_t frame_sequence; + u_int32_t region_mask; +}; + +struct v4l2_event { + u_int32_t type; + union { + struct v4l2_event_vsync vsync; + struct v4l2_event_ctrl ctrl; + struct v4l2_event_frame_sync frame_sync; + struct v4l2_event_src_change src_change; + struct v4l2_event_motion_det motion_det; + u_int8_t data[64]; + } u; + u_int32_t pending; + u_int32_t sequence; + struct timespec timestamp; + u_int32_t id; + u_int32_t reserved[8]; +}; + +#define V4L2_EVENT_SUB_FL_SEND_INITIAL (1 << 0) +#define V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK (1 << 1) + +struct v4l2_event_subscription { + u_int32_t type; + u_int32_t id; + u_int32_t flags; + u_int32_t reserved[5]; +}; + +/* + * A D V A N C E D D E B U G G I N G + * + * NOTE: EXPERIMENTAL API, NEVER RELY ON THIS IN APPLICATIONS! + * FOR DEBUGGING, TESTING AND INTERNAL USE ONLY! + */ + +/* VIDIOC_DBG_G_REGISTER and VIDIOC_DBG_S_REGISTER */ + +#define V4L2_CHIP_MATCH_BRIDGE 0 /* Match against chip ID on the bridge (0 for the bridge) */ +#define V4L2_CHIP_MATCH_SUBDEV 4 /* Match against subdev index */ + +/* The following four defines are no longer in use */ +#define V4L2_CHIP_MATCH_HOST V4L2_CHIP_MATCH_BRIDGE +#define V4L2_CHIP_MATCH_I2C_DRIVER 1 /* Match against I2C driver name */ +#define V4L2_CHIP_MATCH_I2C_ADDR 2 /* Match against I2C 7-bit address */ +#define V4L2_CHIP_MATCH_AC97 3 /* Match against ancillary AC97 chip */ + +struct v4l2_dbg_match { + u_int32_t type; /* Match type */ + union { /* Match this chip, meaning determined by type */ + u_int32_t addr; + char name[32]; + }; +} __attribute__ ((packed)); + +struct v4l2_dbg_register { + struct v4l2_dbg_match match; + u_int32_t size; /* register size in bytes */ + u_int64_t reg; + u_int64_t val; +} __attribute__ ((packed)); + +#define V4L2_CHIP_FL_READABLE (1 << 0) +#define V4L2_CHIP_FL_WRITABLE (1 << 1) + +/* VIDIOC_DBG_G_CHIP_INFO */ +struct v4l2_dbg_chip_info { + struct v4l2_dbg_match match; + char name[32]; + u_int32_t flags; + u_int32_t reserved[32]; +} __attribute__ ((packed)); + +/** + * struct v4l2_create_buffers - VIDIOC_CREATE_BUFS argument + * @index: on return, index of the first created buffer + * @count: entry: number of requested buffers, + * return: number of created buffers + * @memory: enum v4l2_memory; buffer memory type + * @format: frame format, for which buffers are requested + * @capabilities: capabilities of this buffer type. + * @flags: additional buffer management attributes (ignored unless the + * queue has V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS capability + * and configured for MMAP streaming I/O). + * @max_num_buffers: if V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS capability flag is set + * this field indicate the maximum possible number of buffers + * for this queue. + * @reserved: future extensions + */ +struct v4l2_create_buffers { + u_int32_t index; + u_int32_t count; + u_int32_t memory; + struct v4l2_format format; + u_int32_t capabilities; + u_int32_t flags; + u_int32_t max_num_buffers; + u_int32_t reserved[5]; +}; + +/** + * struct v4l2_remove_buffers - VIDIOC_REMOVE_BUFS argument + * @index: the first buffer to be removed + * @count: number of buffers to removed + * @type: enum v4l2_buf_type + * @reserved: future extensions + */ +struct v4l2_remove_buffers { + u_int32_t index; + u_int32_t count; + u_int32_t type; + u_int32_t reserved[13]; +}; + +/* + * I O C T L C O D E S F O R V I D E O D E V I C E S + * + */ +#define VIDIOC_QUERYCAP _IOR('V', 0, struct v4l2_capability) +#define VIDIOC_ENUM_FMT _IOWR('V', 2, struct v4l2_fmtdesc) +#define VIDIOC_G_FMT _IOWR('V', 4, struct v4l2_format) +#define VIDIOC_S_FMT _IOWR('V', 5, struct v4l2_format) +#define VIDIOC_REQBUFS _IOWR('V', 8, struct v4l2_requestbuffers) +#define VIDIOC_QUERYBUF _IOWR('V', 9, struct v4l2_buffer) +#define VIDIOC_G_FBUF _IOR('V', 10, struct v4l2_framebuffer) +#define VIDIOC_S_FBUF _IOW('V', 11, struct v4l2_framebuffer) +#define VIDIOC_OVERLAY _IOW('V', 14, int) +#define VIDIOC_QBUF _IOWR('V', 15, struct v4l2_buffer) +#define VIDIOC_EXPBUF _IOWR('V', 16, struct v4l2_exportbuffer) +#define VIDIOC_DQBUF _IOWR('V', 17, struct v4l2_buffer) +#define VIDIOC_STREAMON _IOW('V', 18, int) +#define VIDIOC_STREAMOFF _IOW('V', 19, int) +#define VIDIOC_G_PARM _IOWR('V', 21, struct v4l2_streamparm) +#define VIDIOC_S_PARM _IOWR('V', 22, struct v4l2_streamparm) +#define VIDIOC_G_STD _IOR('V', 23, v4l2_std_id) +#define VIDIOC_S_STD _IOW('V', 24, v4l2_std_id) +#define VIDIOC_ENUMSTD _IOWR('V', 25, struct v4l2_standard) +#define VIDIOC_ENUMINPUT _IOWR('V', 26, struct v4l2_input) +#define VIDIOC_G_CTRL _IOWR('V', 27, struct v4l2_control) +#define VIDIOC_S_CTRL _IOWR('V', 28, struct v4l2_control) +#define VIDIOC_G_TUNER _IOWR('V', 29, struct v4l2_tuner) +#define VIDIOC_S_TUNER _IOW('V', 30, struct v4l2_tuner) +#define VIDIOC_G_AUDIO _IOR('V', 33, struct v4l2_audio) +#define VIDIOC_S_AUDIO _IOW('V', 34, struct v4l2_audio) +#define VIDIOC_QUERYCTRL _IOWR('V', 36, struct v4l2_queryctrl) +#define VIDIOC_QUERYMENU _IOWR('V', 37, struct v4l2_querymenu) +#define VIDIOC_G_INPUT _IOR('V', 38, int) +#define VIDIOC_S_INPUT _IOWR('V', 39, int) +#define VIDIOC_G_EDID _IOWR('V', 40, struct v4l2_edid) +#define VIDIOC_S_EDID _IOWR('V', 41, struct v4l2_edid) +#define VIDIOC_G_OUTPUT _IOR('V', 46, int) +#define VIDIOC_S_OUTPUT _IOWR('V', 47, int) +#define VIDIOC_ENUMOUTPUT _IOWR('V', 48, struct v4l2_output) +#define VIDIOC_G_AUDOUT _IOR('V', 49, struct v4l2_audioout) +#define VIDIOC_S_AUDOUT _IOW('V', 50, struct v4l2_audioout) +#define VIDIOC_G_MODULATOR _IOWR('V', 54, struct v4l2_modulator) +#define VIDIOC_S_MODULATOR _IOW('V', 55, struct v4l2_modulator) +#define VIDIOC_G_FREQUENCY _IOWR('V', 56, struct v4l2_frequency) +#define VIDIOC_S_FREQUENCY _IOW('V', 57, struct v4l2_frequency) +#define VIDIOC_CROPCAP _IOWR('V', 58, struct v4l2_cropcap) +#define VIDIOC_G_CROP _IOWR('V', 59, struct v4l2_crop) +#define VIDIOC_S_CROP _IOW('V', 60, struct v4l2_crop) +#define VIDIOC_G_JPEGCOMP _IOR('V', 61, struct v4l2_jpegcompression) +#define VIDIOC_S_JPEGCOMP _IOW('V', 62, struct v4l2_jpegcompression) +#define VIDIOC_QUERYSTD _IOR('V', 63, v4l2_std_id) +#define VIDIOC_TRY_FMT _IOWR('V', 64, struct v4l2_format) +#define VIDIOC_ENUMAUDIO _IOWR('V', 65, struct v4l2_audio) +#define VIDIOC_ENUMAUDOUT _IOWR('V', 66, struct v4l2_audioout) +#define VIDIOC_G_PRIORITY _IOR('V', 67, u_int32_t) /* enum v4l2_priority */ +#define VIDIOC_S_PRIORITY _IOW('V', 68, u_int32_t) /* enum v4l2_priority */ +#define VIDIOC_G_SLICED_VBI_CAP _IOWR('V', 69, struct v4l2_sliced_vbi_cap) +#define VIDIOC_LOG_STATUS _IO('V', 70) +#define VIDIOC_G_EXT_CTRLS _IOWR('V', 71, struct v4l2_ext_controls) +#define VIDIOC_S_EXT_CTRLS _IOWR('V', 72, struct v4l2_ext_controls) +#define VIDIOC_TRY_EXT_CTRLS _IOWR('V', 73, struct v4l2_ext_controls) +#define VIDIOC_ENUM_FRAMESIZES _IOWR('V', 74, struct v4l2_frmsizeenum) +#define VIDIOC_ENUM_FRAMEINTERVALS _IOWR('V', 75, struct v4l2_frmivalenum) +#define VIDIOC_G_ENC_INDEX _IOR('V', 76, struct v4l2_enc_idx) +#define VIDIOC_ENCODER_CMD _IOWR('V', 77, struct v4l2_encoder_cmd) +#define VIDIOC_TRY_ENCODER_CMD _IOWR('V', 78, struct v4l2_encoder_cmd) + +/* + * Experimental, meant for debugging, testing and internal use. + * Only implemented if CONFIG_VIDEO_ADV_DEBUG is defined. + * You must be root to use these ioctls. Never use these in applications! + */ +#define VIDIOC_DBG_S_REGISTER _IOW('V', 79, struct v4l2_dbg_register) +#define VIDIOC_DBG_G_REGISTER _IOWR('V', 80, struct v4l2_dbg_register) + +#define VIDIOC_S_HW_FREQ_SEEK _IOW('V', 82, struct v4l2_hw_freq_seek) +#define VIDIOC_S_DV_TIMINGS _IOWR('V', 87, struct v4l2_dv_timings) +#define VIDIOC_G_DV_TIMINGS _IOWR('V', 88, struct v4l2_dv_timings) +#define VIDIOC_DQEVENT _IOR('V', 89, struct v4l2_event) +#define VIDIOC_SUBSCRIBE_EVENT _IOW('V', 90, struct v4l2_event_subscription) +#define VIDIOC_UNSUBSCRIBE_EVENT _IOW('V', 91, struct v4l2_event_subscription) +#define VIDIOC_CREATE_BUFS _IOWR('V', 92, struct v4l2_create_buffers) +#define VIDIOC_PREPARE_BUF _IOWR('V', 93, struct v4l2_buffer) +#define VIDIOC_G_SELECTION _IOWR('V', 94, struct v4l2_selection) +#define VIDIOC_S_SELECTION _IOWR('V', 95, struct v4l2_selection) +#define VIDIOC_DECODER_CMD _IOWR('V', 96, struct v4l2_decoder_cmd) +#define VIDIOC_TRY_DECODER_CMD _IOWR('V', 97, struct v4l2_decoder_cmd) +#define VIDIOC_ENUM_DV_TIMINGS _IOWR('V', 98, struct v4l2_enum_dv_timings) +#define VIDIOC_QUERY_DV_TIMINGS _IOR('V', 99, struct v4l2_dv_timings) +#define VIDIOC_DV_TIMINGS_CAP _IOWR('V', 100, struct v4l2_dv_timings_cap) +#define VIDIOC_ENUM_FREQ_BANDS _IOWR('V', 101, struct v4l2_frequency_band) + +/* + * Experimental, meant for debugging, testing and internal use. + * Never use this in applications! + */ +#define VIDIOC_DBG_G_CHIP_INFO _IOWR('V', 102, struct v4l2_dbg_chip_info) + +#define VIDIOC_QUERY_EXT_CTRL _IOWR('V', 103, struct v4l2_query_ext_ctrl) +#define VIDIOC_REMOVE_BUFS _IOWR('V', 104, struct v4l2_remove_buffers) + + +/* Reminder: when adding new ioctls please add support for them to + drivers/media/v4l2-core/v4l2-compat-ioctl32.c as well! */ + +#define BASE_VIDIOC_PRIVATE 192 /* 192-255 are private */ + +/* Deprecated definitions kept for backwards compatibility */ +#define V4L2_PIX_FMT_HM12 V4L2_PIX_FMT_NV12_16L16 +#define V4L2_PIX_FMT_SUNXI_TILED_NV12 V4L2_PIX_FMT_NV12_32L32 +/* + * This capability was never implemented, anyone using this cap should drop it + * from their code. + */ +#define V4L2_CAP_ASYNCIO 0x02000000 + +#endif /* _SYS_VIDEOIO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/vmmeter.h b/lib/libc/include/generic-openbsd/sys/vmmeter.h new file mode 100644 index 0000000000..547065fe13 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/vmmeter.h @@ -0,0 +1,97 @@ +/* $OpenBSD: vmmeter.h,v 1.15 2016/07/27 14:44:59 tedu Exp $ */ +/* $NetBSD: vmmeter.h,v 1.9 1995/03/26 20:25:04 jtc Exp $ */ + +/*- + * Copyright (c) 1982, 1986, 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. + * + * @(#)vmmeter.h 8.2 (Berkeley) 7/10/94 + */ + +#ifndef __VMMETER_H__ +#define __VMMETER_H__ + +/* + * System wide statistics counters. Look in for the + * UVM equivalent. + */ + +/* systemwide totals computed every five seconds */ +struct vmtotal { + u_int16_t t_rq; /* length of the run queue */ + u_int16_t t_dw; /* jobs in ``disk wait'' (neg priority) */ + u_int16_t t_pw; /* jobs in page wait */ + u_int16_t t_sl; /* jobs sleeping in core */ + u_int16_t t_sw; /* swapped out runnable/short block jobs */ + u_int32_t t_vm; /* total virtual memory */ + u_int32_t t_avm; /* active virtual memory */ + u_int32_t t_rm; /* total real memory in use */ + u_int32_t t_arm; /* active real memory */ + u_int32_t t_vmshr; /* shared virtual memory */ + u_int32_t t_avmshr; /* active shared virtual memory */ + u_int32_t t_rmshr; /* shared real memory */ + u_int32_t t_armshr; /* active shared real memory */ + u_int32_t t_free; /* free memory pages */ +}; + +/* + * Fork/vfork/__tfork accounting. + */ +struct forkstat { + uint32_t cntfork; /* number of fork() calls */ + uint32_t cntvfork; /* number of vfork() calls */ + uint32_t cnttfork; /* number of __tfork() calls */ + uint32_t cntkthread; /* number of kernel threads created */ + uint64_t sizfork; /* VM pages affected by fork() */ + uint64_t sizvfork; /* VM pages affected by vfork() */ + uint64_t siztfork; /* VM pages affected by __tfork() */ + uint64_t sizkthread; /* VM pages affected by kernel threads */ +}; + +/* These sysctl names are only really used by sysctl(8) */ +#define KERN_FORKSTAT_FORK 1 +#define KERN_FORKSTAT_VFORK 2 +#define KERN_FORKSTAT_TFORK 3 +#define KERN_FORKSTAT_KTHREAD 4 +#define KERN_FORKSTAT_SIZFORK 5 +#define KERN_FORKSTAT_SIZVFORK 6 +#define KERN_FORKSTAT_SIZTFORK 7 +#define KERN_FORKSTAT_SIZKTHREAD 8 +#define KERN_FORKSTAT_MAXID 9 + +#define CTL_KERN_FORKSTAT_NAMES { \ + { 0, 0 }, \ + { "forks", CTLTYPE_INT }, \ + { "vforks", CTLTYPE_INT }, \ + { "tforks", CTLTYPE_INT }, \ + { "kthreads", CTLTYPE_INT }, \ + { "fork_pages", CTLTYPE_INT }, \ + { "vfork_pages", CTLTYPE_INT }, \ + { "tfork_pages", CTLTYPE_INT }, \ + { "kthread_pages", CTLTYPE_INT }, \ +} +#endif /* __VMMETER_H__ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/vnode.h b/lib/libc/include/generic-openbsd/sys/vnode.h new file mode 100644 index 0000000000..656c10118b --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/vnode.h @@ -0,0 +1,650 @@ +/* $OpenBSD: vnode.h,v 1.179 2025/09/25 09:05:47 mpi Exp $ */ +/* $NetBSD: vnode.h,v 1.38 1996/02/29 20:59:05 cgd Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)vnode.h 8.11 (Berkeley) 11/21/94 + */ + +#ifndef _SYS_VNODE_H_ +#define _SYS_VNODE_H_ + +#include +#include +#include +#include +#include + +/* + * The vnode is the focus of all file activity in UNIX. There is a + * unique vnode allocated for each active file, each current directory, + * each mounted-on file, text file, and the root. + */ + +/* + * Vnode types. VNON means no type. + */ +enum vtype { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD }; + +#define VTYPE_NAMES \ + "VNON", "VREG", "VDIR", "VBLK", "VCHR", "VLNK", "VSOCK", "VFIFO", "VBAD" + +/* + * Vnode tag types. + * These are for the benefit of external programs only (e.g., pstat) + * and should NEVER be inspected by the kernel. + * + * Note that v_tag is actually used to tell MFS from FFS, and EXT2FS from + * the rest, so don't believe the above comment! + */ +enum vtagtype { + VT_NON, VT_UFS, VT_NFS, VT_MFS, VT_MSDOSFS, + VT_PORTAL, VT_PROCFS, VT_AFS, VT_ISOFS, VT_ADOSFS, + VT_EXT2FS, VT_VFS, VT_NTFS, VT_UDF, VT_FUSEFS, VT_TMPFS, +}; + +#define VTAG_NAMES \ + "NON", "UFS", "NFS", "MFS", "MSDOSFS", \ + "unused", "unused", "unused", "ISOFS", "unused", \ + "EXT2FS", "VFS", "NTFS", "UDF", "FUSEFS", "TMPFS" + +/* + * Each underlying filesystem allocates its own private area and hangs + * it from v_data. If non-null, this area is freed in getnewvnode(). + */ +LIST_HEAD(buflists, buf); + +RBT_HEAD(buf_rb_bufs, buf); + +struct namecache; +RBT_HEAD(namecache_rb_cache, namecache); + +/* + * Locks used to protect struct members in struct vnode: + * a atomic + * V vnode_mtx + * B IPL_BIO + */ +struct uvm_vnode; +struct vnode { + struct uvm_vnode *v_uvm; /* uvm data */ + const struct vops *v_op; /* vnode operations vector */ + enum vtype v_type; /* vnode type */ + enum vtagtype v_tag; /* type of underlying data */ + u_int v_flag; /* vnode flags (see below) */ + u_int v_lflag; /* [V] lock vnode flags */ + u_int v_usecount; /* reference count of users */ + u_int v_uvcount; /* unveil references */ + u_int v_writecount; /* reference count of writers */ + u_int v_lockcount; /* [V] # threads waiting on lock */ + + u_int v_bioflag; /* [B] flags accessed in interrupts */ + u_int v_holdcnt; /* [B] buffer references */ + u_int v_id; /* capability identifier */ + struct mount *v_mount; /* ptr to vfs we are in */ + TAILQ_ENTRY(vnode) v_freelist; /* [B] vnode freelist */ + TAILQ_ENTRY(vnode) v_mntvnodes; /* vnodes for mount point */ + struct buf_rb_bufs v_bufs_tree;/* [B] lookup of all bufs */ + struct buflists v_cleanblkhd; /* [B] clean blocklist head */ + struct buflists v_dirtyblkhd; /* [B] dirty blocklist head */ + u_int v_numoutput; /* [B] num of writes in progress */ + LIST_ENTRY(vnode) v_synclist; /* [B] vnode with dirty buffers */ + union { + struct mount *vu_mountedhere;/* ptr to mounted vfs (VDIR) */ + struct socket *vu_socket; /* unix ipc (VSOCK) */ + struct specinfo *vu_specinfo; /* device (VCHR, VBLK) */ + struct fifoinfo *vu_fifoinfo; /* fifo (VFIFO) */ + } v_un; + + /* VFS namecache */ + struct namecache_rb_cache v_nc_tree; + TAILQ_HEAD(, namecache) v_cache_dst; /* cache entries to us */ + + void *v_data; /* private data for fs */ + struct klist v_klist; /* identity of poller(s) */ +}; +#define v_mountedhere v_un.vu_mountedhere +#define v_socket v_un.vu_socket +#define v_specinfo v_un.vu_specinfo +#define v_fifoinfo v_un.vu_fifoinfo + +/* + * Vnode flags. + */ +#define VROOT 0x0001 /* root of its file system */ +#define VTEXT 0x0002 /* vnode is a pure text prototype */ +#define VSYSTEM 0x0004 /* vnode being used by kernel */ +#define VISTTY 0x0008 /* vnode represents a tty */ +#define VXLOCK 0x0100 /* vnode is locked to change underlying type */ +#define VXWANT 0x0200 /* process is waiting for vnode */ +#define VCLONED 0x0400 /* vnode was cloned */ +#define VALIASED 0x0800 /* vnode has an alias */ +#define VLARVAL 0x1000 /* vnode data not yet set up by higher level */ +#define VLOCKSWORK 0x4000 /* FS supports locking discipline */ +#define VCLONE 0x8000 /* vnode is a clone */ + +/* + * (v_bioflag) Flags that may be manipulated by interrupt handlers + */ +#define VBIOWAIT 0x0001 /* waiting for output to complete */ +#define VBIOONSYNCLIST 0x0002 /* Vnode is on syncer worklist */ +#define VBIOONFREELIST 0x0004 /* Vnode is on a free list */ +#define VBIOERROR 0x0008 /* A write failed */ + +/* + * Vnode attributes. A field value of VNOVAL represents a field whose value + * is unavailable (getattr) or which is not to be changed (setattr). For + * the timespec fields, only the tv_nsec member needs to be set to VNOVAL: + * if tv_nsec != VNOVAL then both tv_sec and tv_nsec are valid. + */ +struct vattr { + enum vtype va_type; /* vnode type (for create) */ + mode_t va_mode; /* files access mode and type */ + nlink_t va_nlink; /* number of references to file */ + uid_t va_uid; /* owner user id */ + gid_t va_gid; /* owner group id */ + long va_fsid; /* file system id (dev for now) */ + u_quad_t va_fileid; /* file id */ + u_quad_t va_size; /* file size in bytes */ + long va_blocksize; /* blocksize preferred for i/o */ + struct timespec va_atime; /* time of last access */ + struct timespec va_mtime; /* time of last modification */ + struct timespec va_ctime; /* time file changed */ + u_long va_gen; /* generation number of file */ + u_long va_flags; /* flags defined for file */ + dev_t va_rdev; /* device the special file represents */ + u_quad_t va_bytes; /* bytes of disk space held by file */ + u_quad_t va_filerev; /* file modification number */ + u_int va_vaflags; /* operations flags, see below */ + long va_spare; /* remain quad aligned */ +}; + +/* + * Flags for va_vaflags. + */ +#define VA_UTIMES_NULL 0x01 /* utimes argument was NULL */ +#define VA_EXCLUSIVE 0x02 /* exclusive create request */ +#define VA_UTIMES_CHANGE 0x04 /* ctime should be updated */ +/* + * Flags for ioflag. + */ +#define IO_UNIT 0x01 /* do I/O as atomic unit */ +#define IO_APPEND 0x02 /* append write to end */ +#define IO_SYNC 0x04 /* do I/O synchronously */ +#define IO_NODELOCKED 0x08 /* underlying node already locked */ +#define IO_NDELAY 0x10 /* FNDELAY flag set in file table */ +#define IO_NOLIMIT 0x20 /* don't enforce limits on i/o */ +#define IO_NOCACHE 0x40 /* don't cache result of this i/o */ + +/* + * Modes. Some values same as Ixxx entries from inode.h for now. + */ +#define VSUID 04000 /* set user id on execution */ +#define VSGID 02000 /* set group id on execution */ +#define VSVTX 01000 /* save swapped text even after use */ +#define VREAD 00400 /* read, write, execute permissions */ +#define VWRITE 00200 +#define VEXEC 00100 + +/* + * Token indicating no attribute value yet assigned. + */ +#define VNOVAL (-1) + +#ifdef _KERNEL +RBT_PROTOTYPE(buf_rb_bufs, buf, b_rbbufs, rb_buf_compare); +/* + * Convert between vnode types and inode formats (since POSIX.1 + * defines mode word of stat structure in terms of inode formats). + */ +extern enum vtype iftovt_tab[]; +extern int vttoif_tab[]; +#define IFTOVT(mode) (iftovt_tab[((mode) & S_IFMT) >> 12]) +#define VTTOIF(indx) (vttoif_tab[(int)(indx)]) +#define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode)) + +/* + * Flags to various vnode functions. + */ +#define SKIPSYSTEM 0x0001 /* vflush: skip vnodes marked VSYSTEM */ +#define FORCECLOSE 0x0002 /* vflush: force file closure */ +#define WRITECLOSE 0x0004 /* vflush: only close writeable files */ +#define DOCLOSE 0x0008 /* vclean: close active files */ +#define IGNORECLEAN 0x0010 /* vflush: ignore clean vnodes */ +#define V_SAVE 0x0001 /* vinvalbuf: sync file first */ +#define V_SAVEMETA 0x0002 /* vinvalbuf: leave indirect blocks */ + +#define REVOKEALL 0x0001 /* vop_revoke: revoke all aliases */ + + +#define VN_KNOTE(vp, b) \ + knote_locked(&vp->v_klist, (b)) + +/* + * Global vnode data. + */ +extern struct vnode *rootvnode; /* root (i.e. "/") vnode */ +extern int initialvnodes; /* XXX number of vnodes to start */ +extern int maxvnodes; /* XXX number of vnodes to allocate */ +extern int syncdelay; /* seconds to delay syncing vnodes */ +extern int rushjob; /* # of slots syncer should run ASAP */ +extern struct mutex vnode_mtx; +extern void vhold(struct vnode *); +extern void vdrop(struct vnode *); + +/* vnode operations */ +struct vops { + int (*vop_lock)(void *); + int (*vop_unlock)(void *); + int (*vop_islocked)(void *); + int (*vop_abortop)(void *); + int (*vop_access)(void *); + int (*vop_advlock)(void *); + int (*vop_bmap)(void *); + int (*vop_bwrite)(void *); + int (*vop_close)(void *); + int (*vop_create)(void *); + int (*vop_fsync)(void *); + int (*vop_getattr)(void *); + int (*vop_inactive)(void *); + int (*vop_ioctl)(void *); + int (*vop_link)(void *); + int (*vop_lookup)(void *); + int (*vop_mknod)(void *); + int (*vop_open)(void *); + int (*vop_pathconf)(void *); + int (*vop_print)(void *); + int (*vop_read)(void *); + int (*vop_readdir)(void *); + int (*vop_readlink)(void *); + int (*vop_reclaim)(void *); + int (*vop_remove)(void *); + int (*vop_rename)(void *); + int (*vop_revoke)(void *); + int (*vop_mkdir)(void *); + int (*vop_rmdir)(void *); + int (*vop_setattr)(void *); + int (*vop_strategy)(void *); + int (*vop_symlink)(void *); + int (*vop_write)(void *); + int (*vop_kqfilter)(void *); +}; + +extern const struct vops dead_vops; +extern const struct vops spec_vops; + +struct vop_generic_args { + void *a_garbage; + /* Other data probably follows; */ +}; + +struct vop_islocked_args { + struct vnode *a_vp; +}; +int VOP_ISLOCKED(struct vnode *); + +struct vop_lookup_args { + struct vnode *a_dvp; + struct vnode **a_vpp; + struct componentname *a_cnp; +}; +int VOP_LOOKUP(struct vnode *, struct vnode **, struct componentname *); + +struct vop_create_args { + struct vnode *a_dvp; + struct vnode **a_vpp; + struct componentname *a_cnp; + struct vattr *a_vap; +}; +int VOP_CREATE(struct vnode *, struct vnode **, struct componentname *, + struct vattr *); + +struct vop_mknod_args { + struct vnode *a_dvp; + struct vnode **a_vpp; + struct componentname *a_cnp; + struct vattr *a_vap; +}; +int VOP_MKNOD(struct vnode *, struct vnode **, struct componentname *, + struct vattr *); + +struct vop_open_args { + struct vnode *a_vp; + int a_mode; + struct ucred *a_cred; + struct proc *a_p; +}; +int VOP_OPEN(struct vnode *, int, struct ucred *, struct proc *); + +struct vop_close_args { + struct vnode *a_vp; + int a_fflag; + struct ucred *a_cred; + struct proc *a_p; +}; +int VOP_CLOSE(struct vnode *, int, struct ucred *, struct proc *); + +struct vop_access_args { + struct vnode *a_vp; + int a_mode; + struct ucred *a_cred; + struct proc *a_p; +}; +int VOP_ACCESS(struct vnode *, int, struct ucred *, struct proc *); + +struct vop_getattr_args { + struct vnode *a_vp; + struct vattr *a_vap; + struct ucred *a_cred; + struct proc *a_p; +}; +int VOP_GETATTR(struct vnode *, struct vattr *, struct ucred *, struct proc *); + +struct vop_setattr_args { + struct vnode *a_vp; + struct vattr *a_vap; + struct ucred *a_cred; + struct proc *a_p; +}; +int VOP_SETATTR(struct vnode *, struct vattr *, struct ucred *, struct proc *); + +struct vop_read_args { + struct vnode *a_vp; + struct uio *a_uio; + int a_ioflag; + struct ucred *a_cred; +}; +int VOP_READ(struct vnode *, struct uio *, int, struct ucred *); + +struct vop_write_args { + struct vnode *a_vp; + struct uio *a_uio; + int a_ioflag; + struct ucred *a_cred; +}; +int VOP_WRITE(struct vnode *, struct uio *, int, struct ucred *); + +struct vop_ioctl_args { + struct vnode *a_vp; + u_long a_command; + void *a_data; + int a_fflag; + struct ucred *a_cred; + struct proc *a_p; +}; +int VOP_IOCTL(struct vnode *, u_long, void *, int, struct ucred *, + struct proc *); + +struct vop_kqfilter_args { + struct vnode *a_vp; + int a_fflag; + struct knote *a_kn; +}; +int VOP_KQFILTER(struct vnode *, int, struct knote *); + +struct vop_revoke_args { + struct vnode *a_vp; + int a_flags; +}; +int VOP_REVOKE(struct vnode *, int); + +struct vop_fsync_args { + struct vnode *a_vp; + struct ucred *a_cred; + int a_waitfor; + struct proc *a_p; +}; +int VOP_FSYNC(struct vnode *, struct ucred *, int, struct proc *); + +struct vop_remove_args { + struct vnode *a_dvp; + struct vnode *a_vp; + struct componentname *a_cnp; +}; +int VOP_REMOVE(struct vnode *, struct vnode *, struct componentname *); + +struct vop_link_args { + struct vnode *a_dvp; + struct vnode *a_vp; + struct componentname *a_cnp; +}; +int VOP_LINK(struct vnode *, struct vnode *, struct componentname *); + +struct vop_rename_args { + struct vnode *a_fdvp; + struct vnode *a_fvp; + struct componentname *a_fcnp; + struct vnode *a_tdvp; + struct vnode *a_tvp; + struct componentname *a_tcnp; +}; +int VOP_RENAME(struct vnode *, struct vnode *, struct componentname *, + struct vnode *, struct vnode *, struct componentname *); + +struct vop_mkdir_args { + struct vnode *a_dvp; + struct vnode **a_vpp; + struct componentname *a_cnp; + struct vattr *a_vap; +}; +int VOP_MKDIR(struct vnode *, struct vnode **, struct componentname *, + struct vattr *); + +struct vop_rmdir_args { + struct vnode *a_dvp; + struct vnode *a_vp; + struct componentname *a_cnp; +}; +int VOP_RMDIR(struct vnode *, struct vnode *, struct componentname *); + +struct vop_symlink_args { + struct vnode *a_dvp; + struct vnode **a_vpp; + struct componentname *a_cnp; + struct vattr *a_vap; + char *a_target; +}; +int VOP_SYMLINK(struct vnode *, struct vnode **, struct componentname *, + struct vattr *, char *); + +struct vop_readdir_args { + struct vnode *a_vp; + struct uio *a_uio; + struct ucred *a_cred; + int *a_eofflag; +}; +int VOP_READDIR(struct vnode *, struct uio *, struct ucred *, int *); + +struct vop_readlink_args { + struct vnode *a_vp; + struct uio *a_uio; + struct ucred *a_cred; +}; +int VOP_READLINK(struct vnode *, struct uio *, struct ucred *); + +struct vop_abortop_args { + struct vnode *a_dvp; + struct componentname *a_cnp; +}; +int VOP_ABORTOP(struct vnode *, struct componentname *); + +struct vop_inactive_args { + struct vnode *a_vp; + struct proc *a_p; +}; +int VOP_INACTIVE(struct vnode *, struct proc *); + +struct vop_reclaim_args { + struct vnode *a_vp; + struct proc *a_p; +}; +int VOP_RECLAIM(struct vnode *, struct proc *); + +struct vop_lock_args { + struct vnode *a_vp; + int a_flags; +}; +int VOP_LOCK(struct vnode *, int); + +struct vop_unlock_args { + struct vnode *a_vp; +}; +int VOP_UNLOCK(struct vnode *); + +struct vop_bmap_args { + struct vnode *a_vp; + daddr_t a_bn; + struct vnode **a_vpp; + daddr_t *a_bnp; + int *a_runp; +}; +int VOP_BMAP(struct vnode *, daddr_t, struct vnode **, daddr_t *, int *); + +struct vop_print_args { + struct vnode *a_vp; +}; +int VOP_PRINT(struct vnode *); + +struct vop_pathconf_args { + struct vnode *a_vp; + int a_name; + register_t *a_retval; +}; +int VOP_PATHCONF(struct vnode *, int, register_t *); + +struct vop_advlock_args { + struct vnode *a_vp; + void *a_id; + int a_op; + struct flock *a_fl; + int a_flags; +}; +int VOP_ADVLOCK(struct vnode *, void *, int, struct flock *, int); + +struct vop_strategy_args { + struct vnode *a_vp; + struct buf *a_bp; +}; +int VOP_STRATEGY(struct vnode *, struct buf *); + +/* Special cases: */ +struct vop_bwrite_args { + struct buf *a_bp; +}; +int VOP_BWRITE(struct buf *); +/* End of special cases. */ + + +/* Public vnode manipulation functions. */ +struct file; +struct mount; +struct nameidata; +struct proc; +struct stat; +struct statfs; +struct ucred; +struct uio; +struct vattr; +struct vnode; + +/* vfs_subr */ +int bdevvp(dev_t, struct vnode **); +int cdevvp(dev_t, struct vnode **); +struct vnode *checkalias(struct vnode *, dev_t, struct mount *); +int getnewvnode(enum vtagtype, struct mount *, const struct vops *, + struct vnode **); +int vaccess(enum vtype, mode_t, uid_t, gid_t, mode_t, struct ucred *); +int vnoperm(struct vnode *); +void vattr_null(struct vattr *); +void vdevgone(int, int, int, enum vtype); +int vcount(struct vnode *); +int vfinddev(dev_t, enum vtype, struct vnode **); +void vflushbuf(struct vnode *, int); +int vflush(struct mount *, struct vnode *, int); +int vget(struct vnode *, int); +void vgone(struct vnode *); +void vgonel(struct vnode *, struct proc *); +int vinvalbuf(struct vnode *, int, struct ucred *, struct proc *, + int, uint64_t); +void vntblinit(void); +int vwaitforio(struct vnode *, int, char *, uint64_t); +void vwakeup(struct vnode *); +void vput(struct vnode *); +int vrecycle(struct vnode *, struct proc *); +int vrele(struct vnode *); +void vref(struct vnode *); +void vprint(char *, struct vnode *); +void copy_statfs_info(struct statfs *, const struct mount *); + +/* vfs_getcwd.c */ +#define GETCWD_CHECK_ACCESS 0x0001 +int vfs_getcwd_scandir(struct vnode **, struct vnode **, char **, char *, + struct proc *); +int vfs_getcwd_common(struct vnode *, struct vnode *, char **, char *, int, + int, struct proc *); +int vfs_getcwd_getcache(struct vnode **, struct vnode **, char **, char *); + +/* vfs_default.c */ +int vop_generic_abortop(void *); +int vop_generic_badop(void *); +int vop_generic_bmap(void *); +int vop_generic_bwrite(void *); +int vop_generic_revoke(void *); +int vop_generic_lookup(void *); + +/* vfs_vnops.c */ +int vn_isunder(struct vnode *, struct vnode *, struct proc *); +int vn_close(struct vnode *, int, struct ucred *, struct proc *); +int vn_open(struct nameidata *, int, int); +int vn_rdwr(enum uio_rw, struct vnode *, caddr_t, int, off_t, + enum uio_seg, int, struct ucred *, size_t *, struct proc *); +int vn_stat(struct vnode *, struct stat *, struct proc *); +int vn_statfile(struct file *, struct stat *, struct proc *); +int vn_lock(struct vnode *, int); +int vn_writechk(struct vnode *); +int vn_fsizechk(struct vnode *, struct uio *, int, ssize_t *); +int vn_ioctl(struct file *, u_long, caddr_t, struct proc *); +void vn_marktext(struct vnode *); + +/* vfs_sync.c */ +void syncer_thread(void *); +void vn_initialize_syncerd(void); +void vn_syncer_add_to_worklist(struct vnode *, int); + +/* misc */ +int getvnode(struct proc *, int, struct file **); + +/* uvm */ +void uvm_vnp_setsize(struct vnode *, off_t); +void uvm_vnp_sync(struct mount *); +int uvm_vnp_uncache(struct vnode *); + + +#endif /* _KERNEL */ +#endif /* _SYS_VNODE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/wait.h b/lib/libc/include/generic-openbsd/sys/wait.h new file mode 100644 index 0000000000..f4dd7d83d1 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/wait.h @@ -0,0 +1,120 @@ +/* $OpenBSD: wait.h,v 1.20 2022/12/19 00:22:11 guenther Exp $ */ +/* $NetBSD: wait.h,v 1.11 1996/04/09 20:55:51 cgd Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1989, 1993, 1994 + * 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. + * + * @(#)wait.h 8.2 (Berkeley) 7/10/94 + */ + +#ifndef _SYS_WAIT_H_ +#define _SYS_WAIT_H_ + +#include +#include + +/* + * This file holds definitions relevant to the wait4 system call + * and the alternate interfaces that use it (wait, wait3, waitpid). + */ + +/* + * Macros to test the exit status returned by wait + * and extract the relevant values. + */ +#define _WSTATUS(x) ((x) & 0177) +#define _WSTOPPED 0177 /* _WSTATUS if process is stopped */ +#define _WCONTINUED 0177777 /* process has continued */ +#define WIFSTOPPED(x) (((x) & 0xff) == _WSTOPPED) +#define WSTOPSIG(x) (int)(((unsigned)(x) >> 8) & 0xff) +#define WIFSIGNALED(x) (_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0) +#define WTERMSIG(x) (_WSTATUS(x)) +#define WIFEXITED(x) (_WSTATUS(x) == 0) +#define WEXITSTATUS(x) (int)(((unsigned)(x) >> 8) & 0xff) +#define WIFCONTINUED(x) (((x) & _WCONTINUED) == _WCONTINUED) +#if __XPG_VISIBLE +#define WCOREFLAG 0200 +#define WCOREDUMP(x) ((x) & WCOREFLAG) + +#define W_EXITCODE(ret, sig) ((ret) << 8 | (sig)) +#define W_STOPCODE(sig) ((sig) << 8 | _WSTOPPED) +#endif + +/* + * Option bits for the third argument of wait4. WNOHANG causes the + * wait to not hang if there are no stopped or terminated processes, rather + * returning an error indication in this case (pid==0). WUNTRACED + * indicates that the caller should receive status about untraced children + * which stop due to signals. If children are stopped and a wait without + * this option is done, it is as though they were still running... nothing + * about them is returned. WNOWAIT only requests information about zombie, + * leaving the proc around, available for later waits. + */ +#define WNOHANG 0x01 /* don't hang in wait */ +#define WUNTRACED 0x02 /* report stopped-by-signal processes */ +#define WCONTINUED 0x08 /* report job control continued processes */ +#if __POSIX_VISIBLE >= 200809 || __XPG_VISIBLE >= 420 +#define WEXITED 0x04 /* report exited processes */ +#define WSTOPPED WUNTRACED +#define WNOWAIT 0x10 /* poll only */ +#define WTRAPPED 0x20 /* report stopped-by-tracing processes */ + +typedef enum { + P_ALL, + P_PGID, + P_PID +} idtype_t; +#endif + +#if __BSD_VISIBLE +/* + * Tokens for special values of the "pid" parameter to wait4. + */ +#define WAIT_ANY (-1) /* any process */ +#define WAIT_MYPGRP 0 /* any process in my process group */ +#endif /* __BSD_VISIBLE */ + +#ifndef _KERNEL +#include + +__BEGIN_DECLS +struct rusage; /* forward declaration */ + +pid_t wait(int *); +pid_t waitpid(pid_t, int *, int); +#if __POSIX_VISIBLE >= 200809 || __XPG_VISIBLE >= 420 +int waitid(idtype_t, id_t, siginfo_t *, int); +#endif +#if __BSD_VISIBLE +pid_t wait3(int *, int, struct rusage *); +pid_t wait4(pid_t, int *, int, struct rusage *); +#endif /* __BSD_VISIBLE */ +__END_DECLS +#endif /* !_KERNEL */ + +#endif /* !_SYS_WAIT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/witness.h b/lib/libc/include/generic-openbsd/sys/witness.h new file mode 100644 index 0000000000..231ed70b5e --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/witness.h @@ -0,0 +1,165 @@ +/* $OpenBSD: witness.h,v 1.7 2025/07/05 09:24:37 jsg Exp $ */ + +/*- + * Copyright (c) 1997 Berkeley Software Design, Inc. 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. Berkeley Software Design Inc's name may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``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 BERKELEY SOFTWARE DESIGN INC 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 BSDI Id: mutex.h,v 2.7.2.35 2000/04/27 03:10:26 cp + * $FreeBSD: head/sys/sys/lock.h 313908 2017-02-18 01:52:10Z mjg $ + */ + +#ifndef _SYS_WITNESS_H_ +#define _SYS_WITNESS_H_ + +#include + +/* + * Lock classes are statically assigned an index into the global lock_classes + * array. Debugging code looks up the lock class for a given lock object + * by indexing the array. + */ +#define LO_CLASSINDEX(lock) \ + ((((lock)->lo_flags) & LO_CLASSMASK) >> LO_CLASSSHIFT) +#define LOCK_CLASS(lock) \ + (lock_classes[LO_CLASSINDEX((lock))]) +#define LOCK_CLASS_MAX \ + (LO_CLASSMASK >> LO_CLASSSHIFT) + +/* + * Option flags passed to lock operations that witness also needs to know + * about or that are generic across all locks. + */ +#define LOP_NEWORDER 0x00000001 /* Define a new lock order. */ +#define LOP_QUIET 0x00000002 /* Don't log locking operations. */ +#define LOP_TRYLOCK 0x00000004 /* Don't check lock order. */ +#define LOP_EXCLUSIVE 0x00000008 /* Exclusive lock. */ +#define LOP_DUPOK 0x00000010 /* Don't check for duplicate acquires */ + +/* Flags passed to witness_assert. */ +#define LA_MASKASSERT 0x000000ff /* Mask for witness defined asserts. */ +#define LA_UNLOCKED 0x00000000 /* Lock is unlocked. */ +#define LA_LOCKED 0x00000001 /* Lock is at least share locked. */ +#define LA_SLOCKED 0x00000002 /* Lock is exactly share locked. */ +#define LA_XLOCKED 0x00000004 /* Lock is exclusively locked. */ +#define LA_RECURSED 0x00000008 /* Lock is recursed. */ +#define LA_NOTRECURSED 0x00000010 /* Lock is not recursed. */ + +#ifdef _KERNEL + +void witness_initialize(void); +void witness_init(struct lock_object *, const struct lock_type *); +int witness_defineorder(struct lock_object *, struct lock_object *); +void witness_checkorder(struct lock_object *, int, struct lock_object *); +void witness_lock(struct lock_object *, int); +void witness_upgrade(struct lock_object *, int); +void witness_downgrade(struct lock_object *, int); +void witness_unlock(struct lock_object *, int); +void witness_setrelative(struct lock_object *, struct lock_object *, int); +int witness_warn(int, struct lock_object *, const char *, ...); +void witness_assert(const struct lock_object *, int); +void witness_display_spinlock(struct lock_object *, struct proc *, + int (*)(const char *, ...)); +void witness_norelease(struct lock_object *); +void witness_releaseok(struct lock_object *); +void witness_thread_exit(struct proc *); +int witness_sysctl(int *, u_int, void *, size_t *, void *, size_t); +int witness_sysctl_watch(void *, size_t *, void *, size_t); + +#ifdef WITNESS + +/* Flags for witness_warn(). */ +#define WARN_KERNELOK 0x01 /* Kernel lock is exempt from this check. */ +#define WARN_PANIC 0x02 /* Panic if check fails. */ +#define WARN_SLEEPOK 0x04 /* Sleepable locks are exempt from check. */ + +#define WITNESS_INITIALIZE() \ + witness_initialize() + +#define WITNESS_INIT(lock, type) \ + witness_init((lock), (type)) + +#define WITNESS_CHECKORDER(lock, flags, interlock) \ + witness_checkorder((lock), (flags), (interlock)) + +#define WITNESS_DEFINEORDER(lock1, lock2) \ + witness_defineorder((struct lock_object *)(lock1), \ + (struct lock_object *)(lock2)) + +#define WITNESS_LOCK(lock, flags) \ + witness_lock((lock), (flags)) + +#define WITNESS_UPGRADE(lock, flags) \ + witness_upgrade((lock), (flags)) + +#define WITNESS_DOWNGRADE(lock, flags) \ + witness_downgrade((lock), (flags)) + +#define WITNESS_UNLOCK(lock, flags) \ + witness_unlock((lock), (flags)) + +/* Set permitted child lock for lock. */ +#define WITNESS_SETCHILD(lock, child) \ + witness_setrelative((lock), (child), 0) + +/* Set permitted parent lock for lock. */ +#define WITNESS_SETPARENT(lock, parent) \ + witness_setrelative((lock), (parent), 1) + +#define WITNESS_CHECK(flags, lock, fmt, ...) \ + witness_warn((flags), (lock), (fmt), ## __VA_ARGS__) + +#define WITNESS_WARN(flags, lock, fmt, ...) \ + witness_warn((flags), (lock), (fmt), ## __VA_ARGS__) + +#define WITNESS_NORELEASE(lock) \ + witness_norelease(&(lock)->lock_object) + +#define WITNESS_RELEASEOK(lock) \ + witness_releaseok(&(lock)->lock_object) + +#define WITNESS_THREAD_EXIT(p) \ + witness_thread_exit((p)) + +#else /* WITNESS */ +#define WITNESS_INITIALIZE() (void)0 +#define WITNESS_INIT(lock, type) (void)0 +#define WITNESS_DEFINEORDER(lock1, lock2) 0 +#define WITNESS_CHECKORDER(lock, flagsi, interlock) (void)0 +#define WITNESS_LOCK(lock, flags) (void)0 +#define WITNESS_UPGRADE(lock, flags) (void)0 +#define WITNESS_DOWNGRADE(lock, flags) (void)0 +#define WITNESS_UNLOCK(lock, flags) (void)0 +#define WITNESS_SETCHILD(lock, child) (void)0 +#define WITNESS_SETPARENT(lock, parent) (void)0 +#define WITNESS_CHECK(flags, lock, fmt, ...) 0 +#define WITNESS_WARN(flags, lock, fmt, ...) (void)0 +#define WITNESS_NORELEASE(lock) (void)0 +#define WITNESS_RELEASEOK(lock) (void)0 +#define WITNESS_THREAD_EXIT(p) (void)0 +#endif /* WITNESS */ + +#endif /* _KERNEL */ +#endif /* _SYS_WITNESS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sys/xcall.h b/lib/libc/include/generic-openbsd/sys/xcall.h new file mode 100644 index 0000000000..b4ec9d497a --- /dev/null +++ b/lib/libc/include/generic-openbsd/sys/xcall.h @@ -0,0 +1,84 @@ +/* $OpenBSD: xcall.h,v 1.1 2025/07/13 05:45:21 dlg Exp $ */ + +/* + * Copyright (c) 2025 David Gwynne + * + * 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. + */ + +/* + * CPU crosscall API + * + * Work to execute on a CPU is wrapped in a struct xcall, which is + * like a task or timeout. Each CPU (in an MP kernel) has an array + * of pointers to xcall structs. The local CPU uses CAS ops to try + * and swap their xcall onto one of the slots on the remote CPU, + * and will spin until space becomes available. Once the xcall has + * been added, an IPI is sent to the remote CPU to kick of processing + * of the array. The xcall IPI handler defers processing of the + * xcall array to a low IPL level using a softintr handler. + * + * To implement this API on an architecture requires the following: + * + * 1. A device has to depend on the xcall attribute to have the + * xcall code included in the kernel build. e.g., on amd64 the cpu + * device depends on the xcall attribute, as defined in + * src/sys/arch/amd64/conf/files.amd64: + * + * device cpu: xcall + * + * The rest of the changes are only necessary for MULTIPROCESSOR builds: + * + * 2. struct cpu_info has to have a `struct xcall_cpu ci_xcall` member. + * + * 3. cpu_xcall_establish has to be called against each cpu_info struct. + * + * 4. cpu_xcall_ipi has to be provided by machine/intr.h. + * + * 5. The MD xcall IPI handler has to call cpu_xcall_dispatch. + */ + +#ifndef _SYS_XCALL_H +#define _SYS_XCALL_H + +struct xcall { + void (*xc_func)(void *); + void *xc_arg; +}; + +/* MD code adds this to struct cpu_info as ci_xcall */ +struct xcall_cpu { + struct xcall *xci_xcalls[4]; + void *xci_softintr; +}; + +#ifdef _KERNEL +#define XCALL_INITIALIZER(_f, _a) { \ + .xc_func = _f, \ + .xc_arg = _a, \ +} + +void cpu_xcall_set(struct xcall *, void (*)(void *), void *); +void cpu_xcall(struct cpu_info *, struct xcall *); + +void cpu_xcall_sync(struct cpu_info *, void (*)(void *), void *, + const char *); + +/* MD cpu setup calls this */ +void cpu_xcall_establish(struct cpu_info *); +/* MD ipi handler calls this */ +void cpu_xcall_dispatch(struct cpu_info *); + +#endif /* _KERNEL */ + +#endif /* _SYS_XCALL_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/sysexits.h b/lib/libc/include/generic-openbsd/sysexits.h new file mode 100644 index 0000000000..c78c27e7e1 --- /dev/null +++ b/lib/libc/include/generic-openbsd/sysexits.h @@ -0,0 +1,119 @@ +/* $OpenBSD: sysexits.h,v 1.5 2003/06/02 19:34:12 millert Exp $ */ +/* $NetBSD: sysexits.h,v 1.4 1994/10/26 00:56:33 cgd Exp $ */ + +/* + * Copyright (c) 1987 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. + * + * @(#)sysexits.h 4.8 (Berkeley) 4/3/91 + */ + +#ifndef _SYSEXITS_H_ +#define _SYSEXITS_H_ + +/* + * SYSEXITS.H -- Exit status codes for system programs. + * + * This include file attempts to categorize possible error + * exit statuses for system programs, notably delivermail + * and the Berkeley network. + * + * Error numbers begin at EX__BASE to reduce the possibility of + * clashing with other exit statuses that random programs may + * already return. The meaning of the codes is approximately + * as follows: + * + * EX_USAGE -- The command was used incorrectly, e.g., with + * the wrong number of arguments, a bad flag, a bad + * syntax in a parameter, or whatever. + * EX_DATAERR -- The input data was incorrect in some way. + * This should only be used for user's data & not + * system files. + * EX_NOINPUT -- An input file (not a system file) did not + * exist or was not readable. This could also include + * errors like "No message" to a mailer (if it cared + * to catch it). + * EX_NOUSER -- The user specified did not exist. This might + * be used for mail addresses or remote logins. + * EX_NOHOST -- The host specified did not exist. This is used + * in mail addresses or network requests. + * EX_UNAVAILABLE -- A service is unavailable. This can occur + * if a support program or file does not exist. This + * can also be used as a catchall message when something + * you wanted to do doesn't work, but you don't know + * why. + * EX_SOFTWARE -- An internal software error has been detected. + * This should be limited to non-operating system related + * errors as possible. + * EX_OSERR -- An operating system error has been detected. + * This is intended to be used for such things as "cannot + * fork", "cannot create pipe", or the like. It includes + * things like getuid returning a user that does not + * exist in the passwd file. + * EX_OSFILE -- Some system file (e.g., /etc/passwd, /var/run/utmp, + * etc.) does not exist, cannot be opened, or has some + * sort of error (e.g., syntax error). + * EX_CANTCREAT -- A (user specified) output file cannot be + * created. + * EX_IOERR -- An error occurred while doing I/O on some file. + * EX_TEMPFAIL -- temporary failure, indicating something that + * is not really an error. In sendmail, this means + * that a mailer (e.g.) could not create a connection, + * and the request should be reattempted later. + * EX_PROTOCOL -- the remote system returned something that + * was "not possible" during a protocol exchange. + * EX_NOPERM -- You did not have sufficient permission to + * perform the operation. This is not intended for + * file system problems, which should use EX_NOINPUT or + * EX_CANTCREAT, but rather for higher level permissions. + * EX_CONFIG -- Something was found in an unconfigured or + * misconfigured state. + */ + +#define EX_OK 0 /* successful termination */ + +#define EX__BASE 64 /* base value for error messages */ + +#define EX_USAGE 64 /* command line usage error */ +#define EX_DATAERR 65 /* data format error */ +#define EX_NOINPUT 66 /* cannot open input */ +#define EX_NOUSER 67 /* addressee unknown */ +#define EX_NOHOST 68 /* host name unknown */ +#define EX_UNAVAILABLE 69 /* service unavailable */ +#define EX_SOFTWARE 70 /* internal software error */ +#define EX_OSERR 71 /* system error (e.g., can't fork) */ +#define EX_OSFILE 72 /* critical OS file missing */ +#define EX_CANTCREAT 73 /* can't create (user) output file */ +#define EX_IOERR 74 /* input/output error */ +#define EX_TEMPFAIL 75 /* temp failure; user is invited to retry */ +#define EX_PROTOCOL 76 /* remote error in protocol */ +#define EX_NOPERM 77 /* permission denied */ +#define EX_CONFIG 78 /* configuration error */ + +#define EX__MAX 78 /* maximum listed value */ + +#endif /* !_SYSEXITS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/syslog.h b/lib/libc/include/generic-openbsd/syslog.h new file mode 100644 index 0000000000..b4af686209 --- /dev/null +++ b/lib/libc/include/generic-openbsd/syslog.h @@ -0,0 +1,220 @@ +/* $OpenBSD: syslog.h,v 1.19 2023/04/27 23:16:18 gnezdo Exp $ */ +/* $NetBSD: syslog.h,v 1.14 1996/04/03 20:46:44 christos Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1988, 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. + * + * @(#)syslog.h 8.1 (Berkeley) 6/2/93 + */ + +#ifndef _SYS_SYSLOG_H_ +#define _SYS_SYSLOG_H_ + +#define _PATH_LOG "/dev/log" + +#define LIOCSFD _IOW('l', 127, int) /* set sendsyslog() fd */ + +#define LOG_MAXLINE 8192 /* maximum line length */ + +/* + * priorities/facilities are encoded into a single 32-bit quantity, where the + * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility + * (0-big number). Both the priorities and the facilities map roughly + * one-to-one to strings in the syslogd(8) source code. This mapping is + * included in this file. + * + * priorities (these are ordered) + */ +#define LOG_EMERG 0 /* system is unusable */ +#define LOG_ALERT 1 /* action must be taken immediately */ +#define LOG_CRIT 2 /* critical conditions */ +#define LOG_ERR 3 /* error conditions */ +#define LOG_WARNING 4 /* warning conditions */ +#define LOG_NOTICE 5 /* normal but significant condition */ +#define LOG_INFO 6 /* informational */ +#define LOG_DEBUG 7 /* debug-level messages */ + +#define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */ + /* extract priority */ +#define LOG_PRI(p) ((p) & LOG_PRIMASK) + +#ifdef SYSLOG_NAMES +#define INTERNAL_NOPRI 0x10 /* the "no priority" priority */ + /* mark "facility" */ +#define INTERNAL_MARK (LOG_NFACILITIES<<3) +typedef struct _code { + char *c_name; + int c_val; +} CODE; + +CODE prioritynames[] = { + { "alert", LOG_ALERT }, + { "crit", LOG_CRIT }, + { "debug", LOG_DEBUG }, + { "emerg", LOG_EMERG }, + { "err", LOG_ERR }, + { "error", LOG_ERR }, /* DEPRECATED */ + { "info", LOG_INFO }, + { "none", INTERNAL_NOPRI }, /* INTERNAL */ + { "notice", LOG_NOTICE }, + { "panic", LOG_EMERG }, /* DEPRECATED */ + { "warn", LOG_WARNING }, /* DEPRECATED */ + { "warning", LOG_WARNING }, + { NULL, -1 }, +}; +#endif + +/* facility codes */ +#define LOG_KERN (0<<3) /* kernel messages */ +#define LOG_USER (1<<3) /* random user-level messages */ +#define LOG_MAIL (2<<3) /* mail system */ +#define LOG_DAEMON (3<<3) /* system daemons */ +#define LOG_AUTH (4<<3) /* security/authorization messages */ +#define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */ +#define LOG_LPR (6<<3) /* line printer subsystem */ +#define LOG_NEWS (7<<3) /* network news subsystem */ +#define LOG_UUCP (8<<3) /* UUCP subsystem */ +#define LOG_CRON (9<<3) /* clock daemon */ +#define LOG_AUTHPRIV (10<<3) /* security/authorization messages (private) */ +#define LOG_FTP (11<<3) /* ftp daemon */ + + /* other codes through 15 reserved for system use */ +#define LOG_LOCAL0 (16<<3) /* reserved for local use */ +#define LOG_LOCAL1 (17<<3) /* reserved for local use */ +#define LOG_LOCAL2 (18<<3) /* reserved for local use */ +#define LOG_LOCAL3 (19<<3) /* reserved for local use */ +#define LOG_LOCAL4 (20<<3) /* reserved for local use */ +#define LOG_LOCAL5 (21<<3) /* reserved for local use */ +#define LOG_LOCAL6 (22<<3) /* reserved for local use */ +#define LOG_LOCAL7 (23<<3) /* reserved for local use */ + +#define LOG_NFACILITIES 24 /* current number of facilities */ +#define LOG_FACMASK 0x03f8 /* mask to extract facility part */ + /* facility of pri */ +#define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3) + +#ifdef SYSLOG_NAMES +CODE facilitynames[] = { + { "auth", LOG_AUTH }, + { "authpriv", LOG_AUTHPRIV }, + { "cron", LOG_CRON }, + { "daemon", LOG_DAEMON }, + { "ftp", LOG_FTP }, + { "kern", LOG_KERN }, + { "lpr", LOG_LPR }, + { "mail", LOG_MAIL }, + { "mark", INTERNAL_MARK }, /* INTERNAL */ + { "news", LOG_NEWS }, + { "security", LOG_AUTH }, /* DEPRECATED */ + { "syslog", LOG_SYSLOG }, + { "user", LOG_USER }, + { "uucp", LOG_UUCP }, + { "local0", LOG_LOCAL0 }, + { "local1", LOG_LOCAL1 }, + { "local2", LOG_LOCAL2 }, + { "local3", LOG_LOCAL3 }, + { "local4", LOG_LOCAL4 }, + { "local5", LOG_LOCAL5 }, + { "local6", LOG_LOCAL6 }, + { "local7", LOG_LOCAL7 }, + { NULL, -1 }, +}; +#endif + +/* Used by reentrant functions */ + +struct syslog_data { + int log_stat; + const char *log_tag; + int log_fac; + int log_mask; +}; + +#define SYSLOG_DATA_INIT {0, (const char *)0, LOG_USER, 0xff} + +#ifdef _KERNEL +#define LOG_PRINTF -1 /* pseudo-priority to indicate use of printf */ +#endif + +/* + * arguments to setlogmask. + */ +#define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */ +#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */ + +/* + * Option flags for openlog. + * + * LOG_ODELAY no longer does anything. + * LOG_NDELAY is the inverse of what it used to be. + */ +#define LOG_PID 0x01 /* log the pid with each message */ +#define LOG_CONS 0x02 /* log on the console if errors in sending */ +#define LOG_ODELAY 0x04 /* delay open until first syslog() (default) */ +#define LOG_NDELAY 0x08 /* don't delay open */ +#define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */ +#define LOG_PERROR 0x20 /* log to stderr as well */ + +#ifndef _KERNEL + +/* + * Don't use va_list in the vsyslog() prototype. Va_list is typedef'd + * in . Including it here may collide with the utility's includes. + * It's unreasonable for utilities to have to include it to include , + * so we get __va_list from and use it. + */ +#include +#include + +__BEGIN_DECLS +void closelog(void); +void openlog(const char *, int, int); +int setlogmask(int); +void syslog(int, const char *, ...) + __attribute__((__format__(__syslog__,2,3))); +void vsyslog(int, const char *, __va_list); +void closelog_r(struct syslog_data *); +void openlog_r(const char *, int, int, struct syslog_data *); +int setlogmask_r(int, struct syslog_data *); +void syslog_r(int, struct syslog_data *, const char *, ...) + __attribute__((__format__(__syslog__,3,4))); +void vsyslog_r(int, struct syslog_data *, const char *, __va_list); +int sendsyslog(const char *, __size_t, int); +__END_DECLS + +#else /* !_KERNEL */ + +void logpri(int); +void log(int, const char *, ...) + __attribute__((__format__(__kprintf__,2,3))); +int addlog(const char *, ...) + __attribute__((__format__(__kprintf__,1,2))); +void logwakeup(void); + +#endif /* !_KERNEL */ +#endif /* !_SYS_SYSLOG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/tar.h b/lib/libc/include/generic-openbsd/tar.h new file mode 100644 index 0000000000..ec0a54b2f3 --- /dev/null +++ b/lib/libc/include/generic-openbsd/tar.h @@ -0,0 +1,66 @@ +/* $OpenBSD: tar.h,v 1.3 2008/06/26 05:42:04 ray Exp $ */ +/* $NetBSD: tar.h,v 1.1 1996/02/05 22:34:13 jtc Exp $ */ + +/*- + * Copyright (c) 1996 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by J.T. Conklin. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _TAR_H_ +#define _TAR_H_ + +#define TMAGIC "ustar" +#define TMAGLEN 6 +#define TVERSION "00" +#define TVERSLEN 2 + +/* Typeflag field definitions */ +#define REGTYPE '0' +#define AREGTYPE '\0' +#define LNKTYPE '1' +#define SYMTYPE '2' +#define CHRTYPE '3' +#define BLKTYPE '4' +#define DIRTYPE '5' +#define FIFOTYPE '6' +#define CONTTYPE '7' + +/* Mode field bit definitions */ +#define TSUID 04000 +#define TSGID 02000 +#define TSVTX 01000 +#define TUREAD 00400 +#define TUWRITE 00200 +#define TUEXEC 00100 +#define TGREAD 00040 +#define TGWRITE 00020 +#define TGEXEC 00010 +#define TOREAD 00004 +#define TOWRITE 00002 +#define TOEXEC 00001 + +#endif /* _TAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/termios.h b/lib/libc/include/generic-openbsd/termios.h new file mode 100644 index 0000000000..3845c34501 --- /dev/null +++ b/lib/libc/include/generic-openbsd/termios.h @@ -0,0 +1,304 @@ +/* $OpenBSD: termios.h,v 1.14 2022/12/30 23:41:45 millert Exp $ */ +/* $NetBSD: termios.h,v 1.14 1996/04/09 20:55:41 cgd Exp $ */ + +/* + * Copyright (c) 1988, 1989, 1993, 1994 + * 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. + * + * @(#)termios.h 8.3 (Berkeley) 3/28/94 + */ + +#ifndef _SYS_TERMIOS_H_ +#define _SYS_TERMIOS_H_ + +#include + +/* + * Special Control Characters + * + * Index into c_cc[] character array. + * + * Name Subscript Enabled by + */ +#define VEOF 0 /* ICANON */ +#define VEOL 1 /* ICANON */ +#if __BSD_VISIBLE +#define VEOL2 2 /* ICANON */ +#endif +#define VERASE 3 /* ICANON */ +#if __BSD_VISIBLE +#define VWERASE 4 /* ICANON */ +#endif +#define VKILL 5 /* ICANON */ +#if __BSD_VISIBLE +#define VREPRINT 6 /* ICANON */ +#endif +/* 7 spare 1 */ +#define VINTR 8 /* ISIG */ +#define VQUIT 9 /* ISIG */ +#define VSUSP 10 /* ISIG */ +#if __BSD_VISIBLE +#define VDSUSP 11 /* ISIG */ +#endif +#define VSTART 12 /* IXON, IXOFF */ +#define VSTOP 13 /* IXON, IXOFF */ +#if __BSD_VISIBLE +#define VLNEXT 14 /* IEXTEN */ +#define VDISCARD 15 /* IEXTEN */ +#endif +#define VMIN 16 /* !ICANON */ +#define VTIME 17 /* !ICANON */ +#if __BSD_VISIBLE +#define VSTATUS 18 /* ICANON */ +/* 19 spare 2 */ +#endif +#define NCCS 20 + +#define _POSIX_VDISABLE (0377) + +#if __BSD_VISIBLE +#define CCEQ(val, c) (c == val ? val != _POSIX_VDISABLE : 0) +#endif + +/* + * Input flags - software input processing + */ +#define IGNBRK 0x00000001 /* ignore BREAK condition */ +#define BRKINT 0x00000002 /* map BREAK to SIGINT */ +#define IGNPAR 0x00000004 /* ignore (discard) parity errors */ +#define PARMRK 0x00000008 /* mark parity and framing errors */ +#define INPCK 0x00000010 /* enable checking of parity errors */ +#define ISTRIP 0x00000020 /* strip 8th bit off chars */ +#define INLCR 0x00000040 /* map NL into CR */ +#define IGNCR 0x00000080 /* ignore CR */ +#define ICRNL 0x00000100 /* map CR to NL (ala CRMOD) */ +#define IXON 0x00000200 /* enable output flow control */ +#define IXOFF 0x00000400 /* enable input flow control */ +#if __BSD_VISIBLE +#define IXANY 0x00000800 /* any char will restart after stop */ +#define IUCLC 0x00001000 /* translate upper to lower case */ +#define IMAXBEL 0x00002000 /* ring bell on input queue full */ +#endif /* __BSD_VISIBLE */ + +/* + * Output flags - software output processing + */ +#define OPOST 0x00000001 /* enable following output processing */ +#if __XPG_VISIBLE +#define ONLCR 0x00000002 /* map NL to CR-NL (ala CRMOD) */ +#endif +#if __BSD_VISIBLE || __XPG_VISIBLE +#define TABDLY 0x00000004 /* horizontal tab delay mask */ +#define TAB0 0x00000000 /* no tab delay or expansion */ +#define TAB3 0x00000004 /* expand tabs to spaces */ +#if __BSD_VISIBLE +#define OXTABS TAB3 /* BSD name for TAB3 */ +#define ONOEOT 0x00000008 /* discard EOT's (^D) on output */ +#endif +#endif +#if __XPG_VISIBLE +#define OCRNL 0x00000010 /* map CR to NL */ +#define OLCUC 0x00000020 /* translate lower case to upper case */ +#define ONOCR 0x00000040 /* No CR output at column 0 */ +#define ONLRET 0x00000080 /* NL performs the CR function */ +#endif /* __XPG_VISIBLE */ + +/* + * Control flags - hardware control of terminal + */ +#if __BSD_VISIBLE +#define CIGNORE 0x00000001 /* ignore control flags */ +#endif +#define CSIZE 0x00000300 /* character size mask */ +#define CS5 0x00000000 /* 5 bits (pseudo) */ +#define CS6 0x00000100 /* 6 bits */ +#define CS7 0x00000200 /* 7 bits */ +#define CS8 0x00000300 /* 8 bits */ +#define CSTOPB 0x00000400 /* send 2 stop bits */ +#define CREAD 0x00000800 /* enable receiver */ +#define PARENB 0x00001000 /* parity enable */ +#define PARODD 0x00002000 /* odd parity, else even */ +#define HUPCL 0x00004000 /* hang up on last close */ +#define CLOCAL 0x00008000 /* ignore modem status lines */ +#if __BSD_VISIBLE +#define CRTSCTS 0x00010000 /* RTS/CTS full-duplex flow control */ +#define CRTS_IFLOW CRTSCTS /* XXX compat */ +#define CCTS_OFLOW CRTSCTS /* XXX compat */ +#define MDMBUF 0x00100000 /* DTR/DCD hardware flow control */ +#define CHWFLOW (MDMBUF|CRTSCTS) /* all types of hw flow control */ +#endif /* __BSD_VISIBLE */ + +/* + * "Local" flags - dumping ground for other state + * + * Warning: some flags in this structure begin with + * the letter "I" and look like they belong in the + * input flag. + */ + +#if __BSD_VISIBLE +#define ECHOKE 0x00000001 /* visual erase for line kill */ +#endif +#define ECHOE 0x00000002 /* visually erase chars */ +#define ECHOK 0x00000004 /* echo NL after line kill */ +#define ECHO 0x00000008 /* enable echoing */ +#define ECHONL 0x00000010 /* echo NL even if ECHO is off */ +#if __BSD_VISIBLE +#define ECHOPRT 0x00000020 /* visual erase mode for hardcopy */ +#define ECHOCTL 0x00000040 /* echo control chars as ^(Char) */ +#endif +#define ISIG 0x00000080 /* enable signals INTR, QUIT, [D]SUSP */ +#define ICANON 0x00000100 /* canonicalize input lines */ +#if __BSD_VISIBLE +#define ALTWERASE 0x00000200 /* use alternate WERASE algorithm */ +#endif +#define IEXTEN 0x00000400 /* enable DISCARD and LNEXT */ +#define EXTPROC 0x00000800 /* external processing */ +#define TOSTOP 0x00400000 /* stop background jobs from output */ +#if __BSD_VISIBLE +#define FLUSHO 0x00800000 /* output being flushed (state) */ +#define XCASE 0x01000000 /* canonical upper/lower case */ +#define NOKERNINFO 0x02000000 /* no kernel output from VSTATUS */ +#define PENDIN 0x20000000 /* XXX retype pending input (state) */ +#endif +#define NOFLSH 0x80000000 /* don't flush after interrupt */ + +typedef unsigned int tcflag_t; +typedef unsigned char cc_t; +typedef unsigned int speed_t; + +struct termios { + tcflag_t c_iflag; /* input flags */ + tcflag_t c_oflag; /* output flags */ + tcflag_t c_cflag; /* control flags */ + tcflag_t c_lflag; /* local flags */ + cc_t c_cc[NCCS]; /* control chars */ + int c_ispeed; /* input speed */ + int c_ospeed; /* output speed */ +}; + +/* + * Commands passed to tcsetattr() for setting the termios structure. + */ +#define TCSANOW 0 /* make change immediate */ +#define TCSADRAIN 1 /* drain output, then change */ +#define TCSAFLUSH 2 /* drain output, flush input */ +#if __BSD_VISIBLE +#define TCSASOFT 0x10 /* flag - don't alter h.w. state */ +#endif + +/* + * Standard speeds + */ +#define B0 0 +#define B50 50 +#define B75 75 +#define B110 110 +#define B134 134 +#define B150 150 +#define B200 200 +#define B300 300 +#define B600 600 +#define B1200 1200 +#define B1800 1800 +#define B2400 2400 +#define B4800 4800 +#define B9600 9600 +#define B19200 19200 +#define B38400 38400 +#if __BSD_VISIBLE +#define B7200 7200 +#define B14400 14400 +#define B28800 28800 +#define B57600 57600 +#define B76800 76800 +#define B115200 115200 +#define B230400 230400 +#define EXTA 19200 +#define EXTB 38400 +#endif /* __BSD_VISIBLE */ + +#ifndef _KERNEL + +#define TCIFLUSH 1 +#define TCOFLUSH 2 +#define TCIOFLUSH 3 +#define TCOOFF 1 +#define TCOON 2 +#define TCIOFF 3 +#define TCION 4 + +#include + +#if __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200809 +#ifndef _PID_T_DEFINED_ +#define _PID_T_DEFINED_ +typedef __pid_t pid_t; +#endif +#endif + +__BEGIN_DECLS +speed_t cfgetispeed(const struct termios *); +speed_t cfgetospeed(const struct termios *); +int cfsetispeed(struct termios *, speed_t); +int cfsetospeed(struct termios *, speed_t); +int tcgetattr(int, struct termios *); +int tcsetattr(int, int, const struct termios *); +int tcdrain(int); +int tcflow(int, int); +int tcflush(int, int); +int tcsendbreak(int, int); + +#if __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200809 +pid_t tcgetsid(int); +#endif + +#if __BSD_VISIBLE +void cfmakeraw(struct termios *); +int cfsetspeed(struct termios *, speed_t); +#endif /* __BSD_VISIBLE */ +__END_DECLS + +#endif /* !_KERNEL */ + +#if __BSD_VISIBLE +/* + * Include tty ioctl's that aren't just for backwards compatibility + * with the old tty driver. These ioctl definitions were previously + * in . + */ +#include +#endif + +/* + * END OF PROTECTED INCLUDE. + */ +#endif /* !_SYS_TERMIOS_H_ */ + +#if __BSD_VISIBLE +#include +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/tgmath.h b/lib/libc/include/generic-openbsd/tgmath.h new file mode 100644 index 0000000000..70460a8ebc --- /dev/null +++ b/lib/libc/include/generic-openbsd/tgmath.h @@ -0,0 +1,169 @@ +/* $OpenBSD: tgmath.h,v 1.1 2011/07/08 19:28:06 martynas Exp $ */ + +/*- + * Copyright (c) 2004 Stefan Farfeleder. + * 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 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 AUTHOR 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. + * + * $FreeBSD: src/include/tgmath.h,v 1.5 2007/02/02 18:30:23 schweikh Exp $ + */ + +#ifndef _TGMATH_H_ +#define _TGMATH_H_ + +#include +#include + +/* + * This implementation of requires two implementation-dependent + * macros to be defined: + * __tg_impl_simple(x, y, z, fn, fnf, fnl, ...) + * Invokes fnl() if the corresponding real type of x, y or z is long + * double, fn() if it is double or any has an integer type, and fnf() + * otherwise. + * __tg_impl_full(x, y, z, fn, fnf, fnl, cfn, cfnf, cfnl, ...) + * Invokes [c]fnl() if the corresponding real type of x, y or z is long + * double, [c]fn() if it is double or any has an integer type, and + * [c]fnf() otherwise. The function with the 'c' prefix is called if + * any of x, y or z is a complex number. + * Both macros call the chosen function with all additional arguments passed + * to them, as given by __VA_ARGS__. + * + * Note that these macros cannot be implemented with C's ?: operator, + * because the return type of the whole expression would incorrectly be long + * double complex regardless of the argument types. + */ + +#if __GNUC_PREREQ__(3, 1) +#define __tg_type(e, t) __builtin_types_compatible_p(__typeof__(e), t) +#define __tg_type3(e1, e2, e3, t) \ + (__tg_type(e1, t) || __tg_type(e2, t) || __tg_type(e3, t)) +#define __tg_type_corr(e1, e2, e3, t) \ + (__tg_type3(e1, e2, e3, t) || __tg_type3(e1, e2, e3, t _Complex)) +#define __tg_integer(e1, e2, e3) \ + (((__typeof__(e1))1.5 == 1) || ((__typeof__(e2))1.5 == 1) || \ + ((__typeof__(e3))1.5 == 1)) +#define __tg_is_complex(e1, e2, e3) \ + (__tg_type3(e1, e2, e3, float _Complex) || \ + __tg_type3(e1, e2, e3, double _Complex) || \ + __tg_type3(e1, e2, e3, long double _Complex) || \ + __tg_type3(e1, e2, e3, __typeof__(_Complex_I))) + +#define __tg_impl_simple(x, y, z, fn, fnf, fnl, ...) \ + __builtin_choose_expr(__tg_type_corr(x, y, z, long double), \ + fnl(__VA_ARGS__), __builtin_choose_expr( \ + __tg_type_corr(x, y, z, double) || __tg_integer(x, y, z),\ + fn(__VA_ARGS__), fnf(__VA_ARGS__))) + +#define __tg_impl_full(x, y, z, fn, fnf, fnl, cfn, cfnf, cfnl, ...) \ + __builtin_choose_expr(__tg_is_complex(x, y, z), \ + __tg_impl_simple(x, y, z, cfn, cfnf, cfnl, __VA_ARGS__), \ + __tg_impl_simple(x, y, z, fn, fnf, fnl, __VA_ARGS__)) + +#else /* __GNUC__ */ +#error " not implemented for this compiler" +#endif /* !__GNUC__ */ + +/* Macros to save lots of repetition below */ +#define __tg_simple(x, fn) \ + __tg_impl_simple(x, x, x, fn, fn##f, fn##l, x) +#define __tg_simple2(x, y, fn) \ + __tg_impl_simple(x, x, y, fn, fn##f, fn##l, x, y) +#define __tg_simplev(x, fn, ...) \ + __tg_impl_simple(x, x, x, fn, fn##f, fn##l, __VA_ARGS__) +#define __tg_full(x, fn) \ + __tg_impl_full(x, x, x, fn, fn##f, fn##l, c##fn, c##fn##f, c##fn##l, x) + +/* 7.22#4 -- These macros expand to real or complex functions, depending on + * the type of their arguments. */ +#define acos(x) __tg_full(x, acos) +#define asin(x) __tg_full(x, asin) +#define atan(x) __tg_full(x, atan) +#define acosh(x) __tg_full(x, acosh) +#define asinh(x) __tg_full(x, asinh) +#define atanh(x) __tg_full(x, atanh) +#define cos(x) __tg_full(x, cos) +#define sin(x) __tg_full(x, sin) +#define tan(x) __tg_full(x, tan) +#define cosh(x) __tg_full(x, cosh) +#define sinh(x) __tg_full(x, sinh) +#define tanh(x) __tg_full(x, tanh) +#define exp(x) __tg_full(x, exp) +#define log(x) __tg_full(x, log) +#define pow(x, y) __tg_impl_full(x, x, y, pow, powf, powl, \ + cpow, cpowf, cpowl, x, y) +#define sqrt(x) __tg_full(x, sqrt) + +/* "The corresponding type-generic macro for fabs and cabs is fabs." */ +#define fabs(x) __tg_impl_full(x, x, x, fabs, fabsf, fabsl, \ + cabs, cabsf, cabsl, x) + +/* 7.22#5 -- These macros are only defined for arguments with real type. */ +#define atan2(x, y) __tg_simple2(x, y, atan2) +#define cbrt(x) __tg_simple(x, cbrt) +#define ceil(x) __tg_simple(x, ceil) +#define copysign(x, y) __tg_simple2(x, y, copysign) +#define erf(x) __tg_simple(x, erf) +#define erfc(x) __tg_simple(x, erfc) +#define exp2(x) __tg_simple(x, exp2) +#define expm1(x) __tg_simple(x, expm1) +#define fdim(x, y) __tg_simple2(x, y, fdim) +#define floor(x) __tg_simple(x, floor) +#define fma(x, y, z) __tg_impl_simple(x, y, z, fma, fmaf, fmal, x, y, z) +#define fmax(x, y) __tg_simple2(x, y, fmax) +#define fmin(x, y) __tg_simple2(x, y, fmin) +#define fmod(x, y) __tg_simple2(x, y, fmod) +#define frexp(x, y) __tg_simplev(x, frexp, x, y) +#define hypot(x, y) __tg_simple2(x, y, hypot) +#define ilogb(x) __tg_simple(x, ilogb) +#define ldexp(x, y) __tg_simplev(x, ldexp, x, y) +#define lgamma(x) __tg_simple(x, lgamma) +#define llrint(x) __tg_simple(x, llrint) +#define llround(x) __tg_simple(x, llround) +#define log10(x) __tg_simple(x, log10) +#define log1p(x) __tg_simple(x, log1p) +#define log2(x) __tg_simple(x, log2) +#define logb(x) __tg_simple(x, logb) +#define lrint(x) __tg_simple(x, lrint) +#define lround(x) __tg_simple(x, lround) +#define nearbyint(x) __tg_simple(x, nearbyint) +#define nextafter(x, y) __tg_simple2(x, y, nextafter) +#define nexttoward(x, y) __tg_simplev(x, nexttoward, x, y) +#define remainder(x, y) __tg_simple2(x, y, remainder) +#define remquo(x, y, z) __tg_impl_simple(x, x, y, remquo, remquof, \ + remquol, x, y, z) +#define rint(x) __tg_simple(x, rint) +#define round(x) __tg_simple(x, round) +#define scalbn(x, y) __tg_simplev(x, scalbn, x, y) +#define scalbln(x, y) __tg_simplev(x, scalbln, x, y) +#define tgamma(x) __tg_simple(x, tgamma) +#define trunc(x) __tg_simple(x, trunc) + +/* 7.22#6 -- These macros always expand to complex functions. */ +#define carg(x) __tg_simple(x, carg) +#define cimag(x) __tg_simple(x, cimag) +#define conj(x) __tg_simple(x, conj) +#define cproj(x) __tg_simple(x, cproj) +#define creal(x) __tg_simple(x, creal) + +#endif /* !_TGMATH_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/tib.h b/lib/libc/include/generic-openbsd/tib.h new file mode 100644 index 0000000000..063c9a94a6 --- /dev/null +++ b/lib/libc/include/generic-openbsd/tib.h @@ -0,0 +1,264 @@ +/* $OpenBSD: tib.h,v 1.10 2023/12/08 19:14:36 miod Exp $ */ +/* + * Copyright (c) 2011,2014 Philip Guenther + * + * 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. + */ + +/* + * Thread Information Block (TIB) and Thread Local Storage (TLS) handling + * (the TCB, Thread Control Block, is part of the TIB) + */ + +#ifndef _TIB_H_ +#define _TIB_H_ + +#include +#include + +#include + + +/* + * This header defines struct tib and at least eight macros: + * TLS_VARIANT + * Either 1 or 2 (Actually defined by ) + * + * TCB_SET(tcb) + * Set the TCB pointer for this thread to 'tcb' + * + * TCB_GET() + * Return the TCB pointer for this thread + * + * TCB_TO_TIB(tcb) + * Given a TCB pointer, return the matching TIB pointer + * + * TIB_TO_TCB(tib) + * Given a TIB pointer, return the matching TCB pointer + * + * TIB_INIT(tib, dtv, thread) + * Initializes a TIB for a new thread, using the supplied + * values for its dtv and thread pointers + * + * TIB_GET() + * Short-hand for TCB_TO_TIB(TCB_GET()) + * + * TIB_EXTRA_ALIGN + * On TLS variant 2 archs, what alignment is sufficient + * for the extra space that will be used for struct pthread? + * + * The following functions are provided by either ld.so (dynamic) or + * libc (static) for allocating and freeing a common memory block that + * will hold both the TIB and the pthread structure: + * _dl_allocate_tib(sizeof(struct pthread)) + * Allocates a combined TIB and pthread memory region. + * The argument is the amount of space to reserve + * for the pthread structure. Returns a pointer to + * the TIB inside the allocated block. + * + * _dl_free_tib(tib, sizeof(struct pthread)) + * Frees a TIB and pthread block previously allocated + * with _dl_allocate_tib(). Must be passed the return + * value of that previous call. + */ + +/* + * Regarding : + * - it must define the TLS_VARIANT macro + * - it may define TCB_OFFSET if the TCB address in the kernel and/or + * register is offset from the actual TCB address. TCB_OFFSET > 0 + * means the kernel/register points to *after* the real data. + * - if there's a faster way to get or set the TCB pointer for the thread + * than the __{get,set}_tcb() syscalls, it should define either or both + * the TCB_{GET,SET} macros to do so. + */ + + +/* All archs but mips64 have fast TCB_GET() and don't need caching */ +#ifndef __mips64__ +# define TCB_HAVE_MD_GET 1 +#endif +#ifdef TCB_SET +# define TCB_HAVE_MD_SET 1 +#else +# define TCB_SET(tcb) __set_tcb(tcb) +#endif +#ifndef TCB_OFFSET +# define TCB_OFFSET 0 +#endif + +/* + * tib_cantcancel values is non-zero if the thread should skip all + * cancellation processing + */ +#define CANCEL_DISABLED 1 +#define CANCEL_DYING 2 + +/* + * tib_cancel_point is non-zero if we're in a cancel point; its modified + * by the cancel point code and read by the cancellation signal handler + */ +#define CANCEL_POINT 1 +#define CANCEL_POINT_DELAYED 2 + + +#if TLS_VARIANT == 1 +/* + * ABI specifies that the static TLS data starts two words after the + * (notional) thread pointer, with the first of those two words being + * the TLS dtv pointer. The other (second) word is reserved for the + * implementation, so we place the pointer to the thread structure there, + * but we place our actual thread bits before the TCB, at negative offsets + * from the TCB pointer. Ergo, memory is laid out, low to high, as: + * + * [pthread structure] + * TIB { + * ...cancelation and other int-sized info... + * int errno + * void *locale + * TCB (- TCB_OFFSET) { + * void *dtv + * struct pthread *thread + * } + * } + * static TLS data + */ + +struct tib { + void *tib_atexit; + int tib_thread_flags; /* internal to libpthread */ + pid_t tib_tid; + int tib_cantcancel; + int tib_cancel_point; + int tib_canceled; + int tib_errno; + void *tib_locale; +#ifdef __powerpc64__ + void *tib_thread; + void *tib_dtv; /* internal to the runtime linker */ +#else + void *tib_dtv; /* internal to the runtime linker */ + void *tib_thread; +#endif +}; + + +#elif TLS_VARIANT == 2 +/* + * ABI specifies that the static TLS data occupies the memory before + * the TCB pointer, at negative offsets, and that on i386 and amd64 + * the word the TCB points to contains a pointer to itself. So, + * we place errno and our thread bits after that. Memory is laid + * out, low to high, as: + * static TLS data + * TIB { + * TCB (- TCB_OFFSET) { + * self pointer [i386/amd64 only] + * void *dtv + * } + * struct pthread *thread + * void *locale + * int errno + * ...cancelation and other int-sized info... + * } + * [pthread structure] + */ + +struct tib { +#if defined(__i386) || defined(__amd64) + struct tib *__tib_self; +# define __tib_tcb __tib_self +#endif + void *tib_dtv; /* internal to the runtime linker */ + void *tib_thread; + void *tib_locale; + int tib_errno; + int tib_canceled; + int tib_cancel_point; + int tib_cantcancel; + pid_t tib_tid; + int tib_thread_flags; /* internal to libpthread */ + void *tib_atexit; +}; + +#if defined(__i386) || defined(__amd64) +# define _TIB_PREP(tib) \ + ((void)((tib)->__tib_self = (tib))) +#endif + +#define TIB_EXTRA_ALIGN sizeof(void *) + +#else +# error "unknown TLS variant" +#endif + +/* nothing to do by default */ +#ifndef _TIB_PREP +# define _TIB_PREP(tib) ((void)0) +#endif + +#define TIB_INIT(tib, dtv, thread) do { \ + (tib)->tib_thread = (thread); \ + (tib)->tib_atexit = NULL; \ + (tib)->tib_locale = NULL; \ + (tib)->tib_cantcancel = 0; \ + (tib)->tib_cancel_point = 0; \ + (tib)->tib_canceled = 0; \ + (tib)->tib_dtv = (dtv); \ + (tib)->tib_errno = 0; \ + (tib)->tib_thread_flags = 0; \ + _TIB_PREP(tib); \ + } while (0) + +#ifndef __tib_tcb +# define __tib_tcb tib_dtv +#endif +#define _TIBO_TCB (offsetof(struct tib, __tib_tcb) + TCB_OFFSET) + +#define TCB_TO_TIB(tcb) ((struct tib *)((char *)(tcb) - _TIBO_TCB)) +#define TIB_TO_TCB(tib) ((char *)(tib) + _TIBO_TCB) +#define TIB_GET() TCB_TO_TIB(TCB_GET()) + + +__BEGIN_DECLS +struct dl_info; +struct dl_phdr_info; +struct dl_cb_0 { + void *(*dl_allocate_tib)(size_t); + void (*dl_free_tib)(void *, size_t); + void (*dl_clean_boot)(void); + void *(*dlopen)(const char *, int); + int (*dlclose)(void *); + void *(*dlsym)(void *, const char *); + int (*dladdr)(const void *, struct dl_info *); + int (*dlctl)(void *, int, void *); + char *(*dlerror)(void); + int (*dl_iterate_phdr)(int (*)(struct dl_phdr_info *, + size_t, void *), void *); +}; + +#define DL_CB_CUR 0 +typedef struct dl_cb_0 dl_cb; + +/* type of function passed to init functions that returns a dl_cb */ +typedef const void *dl_cb_cb(int _version); + +void *_dl_allocate_tib(size_t _extra) __dso_public; +void _dl_free_tib(void *_tib, size_t _extra) __dso_public; + +/* The actual syscalls */ +void *__get_tcb(void); +void __set_tcb(void *_tcb); +__END_DECLS + +#endif /* _TIB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/time.h b/lib/libc/include/generic-openbsd/time.h new file mode 100644 index 0000000000..2762f0f1dc --- /dev/null +++ b/lib/libc/include/generic-openbsd/time.h @@ -0,0 +1,178 @@ +/* $OpenBSD: time.h,v 1.32 2022/10/25 16:30:30 millert Exp $ */ +/* $NetBSD: time.h,v 1.9 1994/10/26 00:56:35 cgd Exp $ */ + +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)time.h 5.12 (Berkeley) 3/9/91 + */ + +#ifndef _TIME_H_ +#define _TIME_H_ + +#include +#include +#include +#include + +#ifndef _CLOCK_T_DEFINED_ +#define _CLOCK_T_DEFINED_ +typedef __clock_t clock_t; +#endif + +#ifndef _TIME_T_DEFINED_ +#define _TIME_T_DEFINED_ +typedef __time_t time_t; +#endif + +#ifndef _SIZE_T_DEFINED_ +#define _SIZE_T_DEFINED_ +typedef __size_t size_t; +#endif + +#if __POSIX_VISIBLE > 0 && __POSIX_VISIBLE < 200112 || __BSD_VISIBLE +/* + * Frequency of the clock ticks reported by times(). Deprecated - use + * sysconf(_SC_CLK_TCK) instead. (Removed in 1003.1-2001.) + */ +#define CLK_TCK 100 +#endif + +#if __POSIX_VISIBLE >= 199309 +#ifndef _CLOCKID_T_DEFINED_ +#define _CLOCKID_T_DEFINED_ +typedef __clockid_t clockid_t; +#endif + +#ifndef _TIMER_T_DEFINED_ +#define _TIMER_T_DEFINED_ +typedef __timer_t timer_t; +#endif +#endif + +#if __POSIX_VISIBLE >= 200112 +#ifndef _PID_T_DEFINED_ +#define _PID_T_DEFINED_ +typedef __pid_t pid_t; +#endif +#endif + +#if __POSIX_VISIBLE >= 200809 +#ifndef _LOCALE_T_DEFINED_ +#define _LOCALE_T_DEFINED_ +typedef void *locale_t; +#endif +#endif + +struct tm { + int tm_sec; /* seconds after the minute [0-60] */ + int tm_min; /* minutes after the hour [0-59] */ + int tm_hour; /* hours since midnight [0-23] */ + int tm_mday; /* day of the month [1-31] */ + int tm_mon; /* months since January [0-11] */ + int tm_year; /* years since 1900 */ + int tm_wday; /* days since Sunday [0-6] */ + int tm_yday; /* days since January 1 [0-365] */ + int tm_isdst; /* Daylight Saving Time flag */ + long tm_gmtoff; /* offset from UTC in seconds */ + char *tm_zone; /* timezone abbreviation */ +}; + +__BEGIN_DECLS +char *asctime(const struct tm *); +clock_t clock(void); +char *ctime(const time_t *); +double difftime(time_t, time_t); +struct tm *gmtime(const time_t *); +struct tm *localtime(const time_t *); +time_t mktime(struct tm *); +size_t strftime(char *__restrict, size_t, const char *__restrict, + const struct tm *__restrict) + __attribute__ ((__bounded__(__string__,1,2))); +time_t time(time_t *); + +#if __XPG_VISIBLE >= 300 +extern int daylight; +extern long timezone; +#endif +#if __XPG_VISIBLE >= 400 +char *strptime(const char *__restrict, const char *__restrict, + struct tm *__restrict); +#endif + +#if __POSIX_VISIBLE >= 199506 +char *asctime_r(const struct tm *__restrict, char *__restrict) + __attribute__ ((__bounded__(__minbytes__,2,26))); +char *ctime_r(const time_t *, char *) + __attribute__ ((__bounded__(__minbytes__,2,26))); +struct tm *gmtime_r(const time_t *__restrict, struct tm *__restrict); +struct tm *localtime_r(const time_t *__restrict, struct tm *__restrict); +#endif + +#if __POSIX_VISIBLE +extern char *tzname[2]; +void tzset(void); +#endif + +#if __POSIX_VISIBLE >= 199309 +int clock_getres(clockid_t, struct timespec *); +int clock_gettime(clockid_t, struct timespec *); +int clock_settime(clockid_t, const struct timespec *); +int nanosleep(const struct timespec *, struct timespec *); +#endif + +#if __POSIX_VISIBLE >= 200112 +int clock_getcpuclockid(pid_t, clockid_t *); +#endif + +#if __POSIX_VISIBLE >= 200809 +size_t strftime_l(char *__restrict, size_t, const char *__restrict, + const struct tm *__restrict, locale_t) + __attribute__ ((__bounded__(__string__,1,2))); +#endif + +#if __ISO_C_VISIBLE >= 2011 +#define TIME_UTC 1 /* time elapsed since epoch */ +int timespec_get(struct timespec *_ts, int _base); +#endif + +#if __BSD_VISIBLE +void tzsetwall(void); +time_t timelocal(struct tm *); +time_t timegm(struct tm *); +time_t timeoff(struct tm *, const long); +#endif +__END_DECLS + +#endif /* !_TIME_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ttyent.h b/lib/libc/include/generic-openbsd/ttyent.h new file mode 100644 index 0000000000..39c97dd775 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ttyent.h @@ -0,0 +1,73 @@ +/* $OpenBSD: ttyent.h,v 1.4 2003/06/02 19:34:12 millert Exp $ */ +/* $NetBSD: ttyent.h,v 1.5 1994/10/26 00:56:36 cgd Exp $ */ + +/* + * Copyright (c) 1989 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. + * + * @(#)ttyent.h 5.7 (Berkeley) 4/3/91 + */ + +#ifndef _TTYENT_H_ +#define _TTYENT_H_ + +#define _PATH_TTYS "/etc/ttys" + +#define _TTYS_OFF "off" +#define _TTYS_ON "on" +#define _TTYS_SECURE "secure" +#define _TTYS_WINDOW "window" +#define _TTYS_LOCAL "local" +#define _TTYS_RTSCTS "rtscts" +#define _TTYS_SOFTCAR "softcar" +#define _TTYS_MDMBUF "mdmbuf" + +struct ttyent { + char *ty_name; /* terminal device name */ + char *ty_getty; /* command to execute, usually getty */ + char *ty_type; /* terminal type for termcap */ +#define TTY_ON 0x01 /* enable logins (start ty_getty program) */ +#define TTY_SECURE 0x02 /* allow uid of 0 to login */ +#define TTY_LOCAL 0x04 /* set 'CLOCAL' on open (dev. specific) */ +#define TTY_RTSCTS 0x08 /* set 'CRTSCTS' on open (dev. specific) */ +#define TTY_SOFTCAR 0x10 /* ignore hardware carrier (dev. spec.) */ +#define TTY_MDMBUF 0x20 /* set 'MDMBUF' on open (dev. specific) */ + int ty_status; /* status flags */ + char *ty_window; /* command to start up window manager */ + char *ty_comment; /* comment field */ +}; + +#include + +__BEGIN_DECLS +struct ttyent *getttyent(void); +struct ttyent *getttynam(const char *); +int setttyent(void); +int endttyent(void); +__END_DECLS + +#endif /* !_TTYENT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/uchar.h b/lib/libc/include/generic-openbsd/uchar.h new file mode 100644 index 0000000000..543a4251fd --- /dev/null +++ b/lib/libc/include/generic-openbsd/uchar.h @@ -0,0 +1,40 @@ +/* $OpenBSD: uchar.h,v 1.2 2023/09/05 23:16:01 schwarze Exp $ */ +/* + * Written by Ingo Schwarze + * and placed in the public domain on March 19, 2022. + */ + +#ifndef _UCHAR_H_ +#define _UCHAR_H_ + +#include +#include + +#ifndef _MBSTATE_T_DEFINED_ +#define _MBSTATE_T_DEFINED_ +typedef __mbstate_t mbstate_t; +#endif + +#ifndef _SIZE_T_DEFINED_ +#define _SIZE_T_DEFINED_ +typedef __size_t size_t; +#endif + +#define __STDC_UTF_16__ 1 +#define __STDC_UTF_32__ 1 + +#if !defined(__cplusplus) || __cplusplus < 201103L +typedef __uint16_t char16_t; +typedef __uint32_t char32_t; +#endif + +__BEGIN_DECLS +size_t mbrtoc16(char16_t * __restrict, const char * __restrict, size_t, + mbstate_t * __restrict); +size_t c16rtomb(char * __restrict, char16_t, mbstate_t * __restrict); +size_t mbrtoc32(char32_t * __restrict, const char * __restrict, size_t, + mbstate_t * __restrict); +size_t c32rtomb(char * __restrict, char32_t, mbstate_t * __restrict); +__END_DECLS + +#endif /* !_UCHAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ufs/ext2fs/ext2fs.h b/lib/libc/include/generic-openbsd/ufs/ext2fs/ext2fs.h new file mode 100644 index 0000000000..2290e2e310 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ufs/ext2fs/ext2fs.h @@ -0,0 +1,449 @@ +/* $OpenBSD: ext2fs.h,v 1.27 2024/07/15 13:27:36 martijn Exp $ */ +/* $NetBSD: ext2fs.h,v 1.10 2000/01/28 16:00:23 bouyer Exp $ */ + +/* + * Copyright (c) 1997 Manuel Bouyer. + * Copyright (c) 1982, 1986, 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. + * + * @(#)fs.h 8.10 (Berkeley) 10/27/94 + * Modified for ext2fs by Manuel Bouyer. + */ + +#include + +/* + * Each disk drive contains some number of file systems. + * A file system consists of a number of cylinder groups. + * Each cylinder group has inodes and data. + * + * A file system is described by its super-block, which in turn + * describes the cylinder groups. The super-block is critical + * data and is replicated in each cylinder group to protect against + * catastrophic loss. This is done at `newfs' time and the critical + * super-block data does not change, so the copies need not be + * referenced further unless disaster strikes. + * + * The first boot and super blocks are given in absolute disk addresses. + * The byte-offset forms are preferred, as they don't imply a sector size. + */ +#define BBSIZE 1024 +#define SBSIZE 1024 +#define BBOFF ((off_t)(0)) +#define SBOFF ((off_t)(BBOFF + BBSIZE)) +#define BBLOCK ((daddr_t)(0)) +#define SBLOCK ((daddr_t)(BBLOCK + BBSIZE / DEV_BSIZE)) + +/* + * Inodes are, like in UFS, 32-bit unsigned integers and therefore ufsino_t. + * Disk blocks are 32-bit, if the filesystem isn't operating in 64-bit mode + * (the incompatible ext4 64BIT flag). More work is needed to properly use + * daddr_t as the disk block data type on both BE and LE architectures. + * XXX disk blocks are simply u_int32_t for now. + */ + +/* + * MINBSIZE is the smallest allowable block size. + * MINBSIZE must be big enough to hold a cylinder group block, + * thus changes to (struct cg) must keep its size within MINBSIZE. + * Note that super blocks are always of size SBSIZE, + * and that both SBSIZE and MAXBSIZE must be >= MINBSIZE. + * FSIZE means fragment size. + */ +#define LOG_MINBSIZE 10 +#define MINBSIZE (1 << LOG_MINBSIZE) +#define LOG_MINFSIZE 10 +#define MINFSIZE (1 << LOG_MINFSIZE) + +/* + * The path name on which the file system is mounted is maintained + * in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in + * the super block for this name. + */ +#define MAXMNTLEN 512 + +/* + * MINFREE gives the minimum acceptable percentage of file system + * blocks which may be free. If the freelist drops below this level + * only the superuser may continue to allocate blocks. This may + * be set to 0 if no reserve of free blocks is deemed necessary, + * however throughput drops by fifty percent if the file system + * is run at between 95% and 100% full; thus the minimum default + * value of fs_minfree is 5%. However, to get good clustering + * performance, 10% is a better choice. hence we use 10% as our + * default value. With 10% free space, fragmentation is not a + * problem, so we choose to optimize for time. + */ +#define MINFREE 5 + +/* + * Super block for an ext2fs file system. + */ +struct ext2fs { + u_int32_t e2fs_icount; /* Inode count */ + u_int32_t e2fs_bcount; /* blocks count */ + u_int32_t e2fs_rbcount; /* reserved blocks count */ + u_int32_t e2fs_fbcount; /* free blocks count */ + u_int32_t e2fs_ficount; /* free inodes count */ + u_int32_t e2fs_first_dblock; /* first data block */ + u_int32_t e2fs_log_bsize; /* block size = 1024*(2^e2fs_log_bsize) */ + u_int32_t e2fs_log_fsize; /* fragment size log2 */ + u_int32_t e2fs_bpg; /* blocks per group */ + u_int32_t e2fs_fpg; /* frags per group */ + u_int32_t e2fs_ipg; /* inodes per group */ + u_int32_t e2fs_mtime; /* mount time */ + u_int32_t e2fs_wtime; /* write time */ + u_int16_t e2fs_mnt_count; /* mount count */ + u_int16_t e2fs_max_mnt_count; /* max mount count */ + u_int16_t e2fs_magic; /* magic number */ + u_int16_t e2fs_state; /* file system state */ + u_int16_t e2fs_beh; /* behavior on errors */ + u_int16_t e2fs_minrev; /* minor revision level */ + u_int32_t e2fs_lastfsck; /* time of last fsck */ + u_int32_t e2fs_fsckintv; /* max time between fscks */ + u_int32_t e2fs_creator; /* creator OS */ + u_int32_t e2fs_rev; /* revision level */ + u_int16_t e2fs_ruid; /* default uid for reserved blocks */ + u_int16_t e2fs_rgid; /* default gid for reserved blocks */ + /* EXT2_DYNAMIC_REV superblocks */ + u_int32_t e2fs_first_ino; /* first non-reserved inode */ + u_int16_t e2fs_inode_size; /* size of inode structure */ + u_int16_t e2fs_block_group_nr; /* block grp number of this sblk*/ + u_int32_t e2fs_features_compat; /* compatible feature set */ + u_int32_t e2fs_features_incompat; /* incompatible feature set */ + u_int32_t e2fs_features_rocompat; /* RO-compatible feature set */ + u_int8_t e2fs_uuid[16]; /* 128-bit uuid for volume */ + char e2fs_vname[16]; /* volume name */ + char e2fs_fsmnt[64]; /* name mounted on */ + u_int32_t e2fs_algo; /* For compression */ + u_int8_t e2fs_prealloc; /* # of blocks to preallocate */ + u_int8_t e2fs_dir_prealloc; /* # of blocks to preallocate for dir */ + u_int16_t e2fs_reserved_ngdb; /* # of reserved gd blocks for resize */ + /* Ext3 JBD2 journaling. */ + u_int8_t e2fs_journal_uuid[16]; + u_int32_t e2fs_journal_ino; + u_int32_t e2fs_journal_dev; + u_int32_t e2fs_last_orphan; /* start of list of inodes to delete */ + u_int32_t e2fs_hash_seed[4]; /* htree hash seed */ + u_int8_t e2fs_def_hash_version; + u_int8_t e2fs_journal_backup_type; + u_int16_t e2fs_gdesc_size; + u_int32_t e2fs_default_mount_opts; + u_int32_t e2fs_first_meta_bg; + u_int32_t e2fs_mkfs_time; + u_int32_t e2fs_journal_backup[17]; + u_int32_t e2fs_bcount_hi; /* high bits of blocks count */ + u_int32_t e2fs_rbcount_hi; /* high bits of reserved blocks count */ + u_int32_t e2fs_fbcount_hi; /* high bits of free blocks count */ + u_int16_t e2fs_min_extra_isize; /* all inodes have some bytes */ + u_int16_t e2fs_want_extra_isize;/* inodes must reserve some bytes */ + u_int32_t e2fs_flags; /* miscellaneous flags */ + u_int16_t e2fs_raid_stride; /* RAID stride */ + u_int16_t e2fs_mmpintv; /* seconds to wait in MMP checking */ + u_int64_t e2fs_mmpblk; /* block for multi-mount protection */ + u_int32_t e2fs_raid_stripe_wid; /* blocks on data disks (N * stride) */ + u_int8_t e2fs_log_gpf; /* FLEX_BG group size */ + u_int8_t e2fs_chksum_type; /* metadata checksum algorithm used */ + u_int8_t e2fs_encrypt; /* versioning level for encryption */ + u_int8_t e2fs_reserved_pad; + u_int64_t e2fs_kbytes_written; /* number of lifetime kilobytes */ + u_int32_t e2fs_snapinum; /* inode number of active snapshot */ + u_int32_t e2fs_snapid; /* sequential ID of active snapshot */ + u_int64_t e2fs_snaprbcount; /* rsvd blocks for active snapshot */ + u_int32_t e2fs_snaplist; /* inode number for on-disk snapshot */ + u_int32_t e2fs_errcount; /* number of file system errors */ + u_int32_t e2fs_first_errtime; /* first time an error happened */ + u_int32_t e2fs_first_errino; /* inode involved in first error */ + u_int64_t e2fs_first_errblk; /* block involved of first error */ + u_int8_t e2fs_first_errfunc[32];/* function where error happened */ + u_int32_t e2fs_first_errline; /* line number where error happened */ + u_int32_t e2fs_last_errtime; /* most recent time of an error */ + u_int32_t e2fs_last_errino; /* inode involved in last error */ + u_int32_t e2fs_last_errline; /* line number where error happened */ + u_int64_t e2fs_last_errblk; /* block involved of last error */ + u_int8_t e2fs_last_errfunc[32];/* function where error happened */ + u_int8_t e2fs_mount_opts[64]; + u_int32_t e2fs_usrquota_inum; /* inode for tracking user quota */ + u_int32_t e2fs_grpquota_inum; /* inode for tracking group quota */ + u_int32_t e2fs_overhead_clusters;/* overhead blocks/clusters */ + u_int32_t e2fs_backup_bgs[2]; /* groups with sparse_super2 SBs */ + u_int8_t e2fs_encrypt_algos[4];/* encryption algorithms in use */ + u_int8_t e2fs_encrypt_pw_salt[16];/* salt used for string2key */ + u_int32_t e2fs_lpf_ino; /* location of the lost+found inode */ + u_int32_t e2fs_proj_quota_inum; /* inode for tracking project quota */ + u_int32_t e2fs_chksum_seed; /* checksum seed */ + u_int32_t e2fs_reserved[98]; /* padding to the end of the block */ + u_int32_t e2fs_sbchksum; /* superblock checksum */ +}; + + +/* in-memory data for ext2fs */ +struct m_ext2fs { + struct ext2fs e2fs; + u_char e2fs_fsmnt[MAXMNTLEN]; /* name mounted on */ + int8_t e2fs_ronly; /* mounted read-only flag */ + int8_t e2fs_fmod; /* super block modified flag */ + int32_t e2fs_fsize; /* fragment size */ + int32_t e2fs_bsize; /* block size */ + int32_t e2fs_bshift; /* ``lblkno'' calc of logical blkno */ + int32_t e2fs_bmask; /* ``blkoff'' calc of blk offsets */ + int64_t e2fs_qbmask; /* ~fs_bmask - for use with quad size */ + int32_t e2fs_fsbtodb; /* fsbtodb and dbtofsb shift constant */ + int32_t e2fs_ncg; /* number of cylinder groups */ + int32_t e2fs_ngdb; /* number of group descriptor block */ + int32_t e2fs_ipb; /* number of inodes per block */ + int32_t e2fs_itpg; /* number of inode table per group */ + off_t e2fs_maxfilesize; /* depends on LARGE/HUGE flags */ + struct ext2_gd *e2fs_gd; /* group descriptors */ +}; + +static inline int +e2fs_overflow(struct m_ext2fs *fs, off_t lower, off_t value) +{ + return (value < lower || value > fs->e2fs_maxfilesize); +} + +/* + * Filesystem identification + */ +#define E2FS_MAGIC 0xef53 /* the ext2fs magic number */ +#define E2FS_REV0 0 /* revision levels */ +#define E2FS_REV1 1 /* revision levels */ + +/* compatible/incompatible features */ +#define EXT2F_COMPAT_PREALLOC 0x0001 +#define EXT2F_COMPAT_IMAGIC_INODES 0x0002 +#define EXT2F_COMPAT_HAS_JOURNAL 0x0004 +#define EXT2F_COMPAT_EXT_ATTR 0x0008 +#define EXT2F_COMPAT_RESIZE 0x0010 +#define EXT2F_COMPAT_DIR_INDEX 0x0020 +#define EXT2F_COMPAT_SPARSE_SUPER2 0x0200 + +#define EXT2F_ROCOMPAT_SPARSE_SUPER 0x0001 +#define EXT2F_ROCOMPAT_LARGE_FILE 0x0002 +#define EXT2F_ROCOMPAT_BTREE_DIR 0x0004 +#define EXT2F_ROCOMPAT_HUGE_FILE 0x0008 +#define EXT2F_ROCOMPAT_GDT_CSUM 0x0010 +#define EXT2F_ROCOMPAT_DIR_NLINK 0x0020 +#define EXT2F_ROCOMPAT_EXTRA_ISIZE 0x0040 +#define EXT2F_ROCOMPAT_QUOTA 0x0100 +#define EXT2F_ROCOMPAT_BIGALLOC 0x0200 +#define EXT2F_ROCOMPAT_METADATA_CKSUM 0x0400 +#define EXT2F_ROCOMPAT_READONLY 0x1000 +#define EXT2F_ROCOMPAT_PROJECT 0x2000 + +#define EXT2F_INCOMPAT_COMP 0x0001 +#define EXT2F_INCOMPAT_FTYPE 0x0002 +#define EXT2F_INCOMPAT_RECOVER 0x0004 +#define EXT2F_INCOMPAT_JOURNAL_DEV 0x0008 +#define EXT2F_INCOMPAT_META_BG 0x0010 +#define EXT2F_INCOMPAT_EXTENTS 0x0040 +#define EXT2F_INCOMPAT_64BIT 0x0080 +#define EXT2F_INCOMPAT_MMP 0x0100 +#define EXT2F_INCOMPAT_FLEX_BG 0x0200 +#define EXT2F_INCOMPAT_EA_INODE 0x0400 +#define EXT2F_INCOMPAT_DIRDATA 0x1000 +#define EXT2F_INCOMPAT_CSUM_SEED 0x2000 +#define EXT2F_INCOMPAT_LARGEDIR 0x4000 +#define EXT2F_INCOMPAT_INLINE_DATA 0x8000 +#define EXT2F_INCOMPAT_ENCRYPT 0x10000 + +struct ext2_feature { + uint32_t mask; + const char *name; +}; + +static const struct ext2_feature ro_compat[] = { + { EXT2F_ROCOMPAT_SPARSE_SUPER, "sparse_super" }, + { EXT2F_ROCOMPAT_LARGE_FILE, "large_file" }, + { EXT2F_ROCOMPAT_BTREE_DIR, "btree_dir" }, + { EXT2F_ROCOMPAT_HUGE_FILE, "huge_file" }, + { EXT2F_ROCOMPAT_GDT_CSUM, "uninit_bg" }, + { EXT2F_ROCOMPAT_DIR_NLINK, "dir_nlink" }, + { EXT2F_ROCOMPAT_EXTRA_ISIZE, "extra_isize" }, + { EXT2F_ROCOMPAT_QUOTA, "quota" }, + { EXT2F_ROCOMPAT_BIGALLOC, "bigalloc" }, + { EXT2F_ROCOMPAT_METADATA_CKSUM, "metadata_csum" }, + { EXT2F_ROCOMPAT_READONLY, "read-only" }, + { EXT2F_ROCOMPAT_PROJECT, "project" } +}; + +static const struct ext2_feature incompat[] = { + { EXT2F_INCOMPAT_COMP, "compression" }, + { EXT2F_INCOMPAT_FTYPE, "filetype" }, + { EXT2F_INCOMPAT_RECOVER, "needs_recovery" }, + { EXT2F_INCOMPAT_JOURNAL_DEV, "journal_dev" }, + { EXT2F_INCOMPAT_META_BG, "meta_bg" }, + { EXT2F_INCOMPAT_EXTENTS, "extents" }, + { EXT2F_INCOMPAT_64BIT, "64bit" }, + { EXT2F_INCOMPAT_MMP, "mmp" }, + { EXT2F_INCOMPAT_FLEX_BG, "flex_bg" }, + { EXT2F_INCOMPAT_EA_INODE, "ea_inode" }, + { EXT2F_INCOMPAT_DIRDATA, "dirdata" }, + { EXT2F_INCOMPAT_CSUM_SEED, "metadata_csum_seed" }, + { EXT2F_INCOMPAT_LARGEDIR, "large_dir" }, + { EXT2F_INCOMPAT_INLINE_DATA, "inline_data" }, + { EXT2F_INCOMPAT_ENCRYPT, "encrypt" } +}; + +/* features supported in this implementation */ +#define EXT2F_COMPAT_SUPP 0x0000 +#define EXT2F_ROCOMPAT_SUPP (EXT2F_ROCOMPAT_SPARSE_SUPER | \ + EXT2F_ROCOMPAT_LARGE_FILE) +#define EXT2F_INCOMPAT_SUPP (EXT2F_INCOMPAT_FTYPE) +#define EXT4F_RO_INCOMPAT_SUPP (EXT2F_INCOMPAT_EXTENTS | \ + EXT2F_INCOMPAT_FLEX_BG | \ + EXT2F_INCOMPAT_META_BG | \ + EXT2F_INCOMPAT_RECOVER) + +/* + * Definitions of behavior on errors + */ +#define E2FS_BEH_CONTINUE 1 /* continue operation */ +#define E2FS_BEH_READONLY 2 /* remount fs read only */ +#define E2FS_BEH_PANIC 3 /* cause panic */ +#define E2FS_BEH_DEFAULT E2FS_BEH_CONTINUE + +/* + * OS identification + */ +#define E2FS_OS_LINUX 0 +#define E2FS_OS_HURD 1 +#define E2FS_OS_MASIX 2 + +/* + * Filesystem clean flags + */ +#define E2FS_ISCLEAN 0x01 +#define E2FS_ERRORS 0x02 + +/* ext2 file system block group descriptor */ + +struct ext2_gd { + u_int32_t ext2bgd_b_bitmap; /* blocks bitmap block */ + u_int32_t ext2bgd_i_bitmap; /* inodes bitmap block */ + u_int32_t ext2bgd_i_tables; /* inodes table block */ + u_int16_t ext2bgd_nbfree; /* number of free blocks */ + u_int16_t ext2bgd_nifree; /* number of free inodes */ + u_int16_t ext2bgd_ndirs; /* number of directories */ + u_int16_t reserved; + u_int32_t reserved2[3]; +}; + +/* + * If the EXT2F_ROCOMPAT_SPARSE_SUPER flag is set, the cylinder group has a + * copy of the super and cylinder group descriptors blocks only if it's + * a power of 3, 5 or 7 + */ + +static __inline__ int cg_has_sb(int) __attribute__((__unused__)); +static __inline int +cg_has_sb(int i) +{ + int a3 ,a5 , a7; + + if (i == 0 || i == 1) + return 1; + for (a3 = 3, a5 = 5, a7 = 7; + a3 <= i || a5 <= i || a7 <= i; + a3 *= 3, a5 *= 5, a7 *= 7) + if (i == a3 || i == a5 || i == a7) + return 1; + return 0; +} + +/* + * Ext2 metadata is stored in little-endian byte order. + * JBD2 journal used in ext3 and ext4 is big-endian! + */ +#if BYTE_ORDER == LITTLE_ENDIAN +#define e2fs_sbload(old, new) memcpy((new), (old), SBSIZE); +#define e2fs_cgload(old, new, size) memcpy((new), (old), (size)); +#define e2fs_sbsave(old, new) memcpy((new), (old), SBSIZE); +#define e2fs_cgsave(old, new, size) memcpy((new), (old), (size)); +#else +void e2fs_sb_bswap(struct ext2fs *, struct ext2fs *); +void e2fs_cg_bswap(struct ext2_gd *, struct ext2_gd *, int); +#define e2fs_sbload(old, new) e2fs_sb_bswap((old), (new)) +#define e2fs_cgload(old, new, size) e2fs_cg_bswap((old), (new), (size)); +#define e2fs_sbsave(old, new) e2fs_sb_bswap((old), (new)) +#define e2fs_cgsave(old, new, size) e2fs_cg_bswap((old), (new), (size)); +#endif + +/* + * Turn file system block numbers into disk block addresses. + * This maps file system blocks to device size blocks. + */ +#define fsbtodb(fs, b) ((b) << (fs)->e2fs_fsbtodb) +#define dbtofsb(fs, b) ((b) >> (fs)->e2fs_fsbtodb) + +/* + * Macros for handling inode numbers: + * inode number to file system block offset. + * inode number to cylinder group number. + * inode number to file system block address. + */ +#define ino_to_cg(fs, x) (((x) - 1) / (fs)->e2fs.e2fs_ipg) +#define ino_to_fsba(fs, x) \ + ((fs)->e2fs_gd[ino_to_cg(fs, x)].ext2bgd_i_tables + \ + (((x)-1) % (fs)->e2fs.e2fs_ipg)/(fs)->e2fs_ipb) +#define ino_to_fsbo(fs, x) (((x)-1) % (fs)->e2fs_ipb) + +/* + * Give cylinder group number for a file system block. + * Give cylinder group block number for a file system block. + */ +#define dtog(fs, d) (((d) - (fs)->e2fs.e2fs_first_dblock) / (fs)->e2fs.e2fs_fpg) +#define dtogd(fs, d) \ + (((d) - (fs)->e2fs.e2fs_first_dblock) % (fs)->e2fs.e2fs_fpg) + +/* + * The following macros optimize certain frequently calculated + * quantities by using shifts and masks in place of divisions + * modulos and multiplications. + */ +#define blkoff(fs, loc) /* calculates (loc % fs->e2fs_bsize) */ \ + ((loc) & (fs)->e2fs_qbmask) +#define lblktosize(fs, blk) /* calculates (blk * fs->e2fs_bsize) */ \ + ((blk) << (fs)->e2fs_bshift) +#define lblkno(fs, loc) /* calculates (loc / fs->e2fs_bsize) */ \ + ((loc) >> (fs)->e2fs_bshift) +#define blkroundup(fs, size) /* calculates roundup(size, fs->e2fs_bsize) */ \ + (((size) + (fs)->e2fs_qbmask) & (fs)->e2fs_bmask) +#define fragroundup(fs, size) /* calculates roundup(size, fs->e2fs_bsize) */ \ + (((size) + (fs)->e2fs_qbmask) & (fs)->e2fs_bmask) +/* + * Determine the number of available frags given a + * percentage to hold in reserve. + */ +#define freespace(fs) \ + ((fs)->e2fs.e2fs_fbcount - (fs)->e2fs.e2fs_rbcount) + +/* + * Number of indirects in a file system block. + */ +#define NINDIR(fs) ((fs)->e2fs_bsize / sizeof(u_int32_t)) \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ufs/ext2fs/ext2fs_dinode.h b/lib/libc/include/generic-openbsd/ufs/ext2fs/ext2fs_dinode.h new file mode 100644 index 0000000000..0b5972ecd2 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ufs/ext2fs/ext2fs_dinode.h @@ -0,0 +1,166 @@ +/* $OpenBSD: ext2fs_dinode.h,v 1.17 2014/07/31 17:37:52 pelikan Exp $ */ +/* $NetBSD: ext2fs_dinode.h,v 1.6 2000/01/26 16:21:33 bouyer Exp $ */ + +/* + * Copyright (c) 1997 Manuel Bouyer. + * Copyright (c) 1982, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)dinode.h 8.6 (Berkeley) 9/13/94 + * Modified for ext2fs by Manuel Bouyer. + */ + +#include +#include /* for ufsino_t */ + +/* + * The root inode is the root of the file system. Inode 0 can't be used for + * normal purposes and bad blocks are normally linked to inode 1, thus + * the root inode is 2. + * Inode 3 to 10 are reserved in ext2fs. + */ +#define EXT2_ROOTINO ((ufsino_t)2) +#define EXT2_RESIZEINO ((ufsino_t)7) +#define EXT2_FIRSTINO ((ufsino_t)11) + +/* + * A dinode contains all the meta-data associated with a UFS file. + * This structure defines the on-disk format of a dinode. Since + * this structure describes an on-disk structure, all its fields + * are defined by types with precise widths. + */ + +#define NDADDR 12 /* Direct addresses in inode. */ +#define NIADDR 3 /* Indirect addresses in inode. */ + +#define EXT2_MAXSYMLINKLEN ((NDADDR+NIADDR) * sizeof (u_int32_t)) + +struct ext2fs_dinode { + u_int16_t e2di_mode; /* 0: IFMT, permissions; see below. */ + u_int16_t e2di_uid_low; /* 2: owner UID, bits 15:0 */ + u_int32_t e2di_size; /* 4: file size (bytes) bits 31:0 */ + u_int32_t e2di_atime; /* 8: Access time */ + u_int32_t e2di_ctime; /* 12: Change time */ + u_int32_t e2di_mtime; /* 16: Modification time */ + u_int32_t e2di_dtime; /* 20: Deletion time */ + u_int16_t e2di_gid_low; /* 24: Owner GID, lowest bits */ + u_int16_t e2di_nlink; /* 26: File link count */ + u_int32_t e2di_nblock; /* 28: blocks count */ + u_int32_t e2di_flags; /* 32: status flags (chflags) */ + u_int32_t e2di_version_lo; /* 36: inode version, bits 31:0 */ + u_int32_t e2di_blocks[NDADDR+NIADDR]; /* 40: disk blocks */ + u_int32_t e2di_gen; /* 100: generation number */ + u_int32_t e2di_facl; /* 104: file ACL, bits 31:0 */ + u_int32_t e2di_size_hi; /* 108: file size (bytes), bits 63:32 */ + u_int32_t e2di_faddr; /* 112: fragment address (obsolete) */ + u_int16_t e2di_nblock_hi; /* 116: blocks count, bits 47:32 */ + u_int16_t e2di_facl_hi; /* 118: file ACL, bits 47:32 */ + u_int16_t e2di_uid_high; /* 120: owner UID, bits 31:16 */ + u_int16_t e2di_gid_high; /* 122: owner GID, bits 31:16 */ + u_int16_t e2di_chksum_lo; /* 124: inode checksum, bits 15:0 */ + u_int16_t e2di__reserved; /* 126: unused */ + u_int16_t e2di_isize; /* 128: size of this inode */ + u_int16_t e2di_chksum_hi; /* 130: inode checksum, bits 31:16 */ + u_int32_t e2di_x_ctime; /* 132: extra Change time */ + u_int32_t e2di_x_mtime; /* 136: extra Modification time */ + u_int32_t e2di_x_atime; /* 140: extra Access time */ + u_int32_t e2di_crtime; /* 144: Creation (birth) time */ + u_int32_t e2di_x_crtime; /* 148: extra Creation (birth) time */ + u_int32_t e2di_version_hi; /* 152: inode version, bits 63:31 */ +}; + +#define E2MAXSYMLINKLEN ((NDADDR + NIADDR) * sizeof(u_int32_t)) + +/* File permissions. */ +#define EXT2_IEXEC 0000100 /* Executable. */ +#define EXT2_IWRITE 0000200 /* Writeable. */ +#define EXT2_IREAD 0000400 /* Readable. */ +#define EXT2_ISVTX 0001000 /* Sticky bit. */ +#define EXT2_ISGID 0002000 /* Set-gid. */ +#define EXT2_ISUID 0004000 /* Set-uid. */ + +/* File types. */ +#define EXT2_IFMT 0170000 /* Mask of file type. */ +#define EXT2_IFIFO 0010000 /* Named pipe (fifo). */ +#define EXT2_IFCHR 0020000 /* Character device. */ +#define EXT2_IFDIR 0040000 /* Directory file. */ +#define EXT2_IFBLK 0060000 /* Block device. */ +#define EXT2_IFREG 0100000 /* Regular file. */ +#define EXT2_IFLNK 0120000 /* Symbolic link. */ +#define EXT2_IFSOCK 0140000 /* UNIX domain socket. */ + +/* file flags */ +#define EXT2_SECRM 0x00000001 /* Secure deletion */ +#define EXT2_UNRM 0x00000002 /* Undelete */ +#define EXT2_COMPR 0x00000004 /* Compress file */ +#define EXT2_SYNC 0x00000008 /* Synchronous updates */ +#define EXT2_IMMUTABLE 0x00000010 /* Immutable file */ +#define EXT2_APPEND 0x00000020 /* writes to file may only append */ +#define EXT2_NODUMP 0x00000040 /* do not dump file */ +#define EXT2_NOATIME 0x00000080 /* do not update access time */ +#define EXT4_INDEX 0x00001000 /* hash-indexed directory */ +#define EXT4_JOURNAL_DATA 0x00004000 /* file data should be journaled */ +#define EXT4_DIRSYNC 0x00010000 /* all dirent updates done synchronously */ +#define EXT4_TOPDIR 0x00020000 /* top of directory hierarchies */ +#define EXT4_HUGE_FILE 0x00040000 /* nblocks unit is fsb, not db */ +#define EXT4_EXTENTS 0x00080000 /* inode uses extents */ +#define EXT4_EOFBLOCKS 0x00400000 /* blocks allocated beyond EOF */ + +/* Size of on-disk inode. */ +#define EXT2_REV0_DINODE_SIZE 128 +#define EXT2_DINODE_SIZE(fs) ((fs)->e2fs.e2fs_rev > E2FS_REV0 ? \ + (fs)->e2fs.e2fs_inode_size : \ + EXT2_REV0_DINODE_SIZE) + +/* + * The e2di_blocks fields may be overlaid with other information for + * file types that do not have associated disk storage. Block + * and character devices overlay the first data block with their + * dev_t value. Short symbolic links place their path in the + * di_db area. + */ + +#define e2di_rdev e2di_blocks[0] +#define e2di_shortlink e2di_blocks + +/* e2fs needs byte swapping on big-endian systems */ +#if BYTE_ORDER == LITTLE_ENDIAN +# define e2fs_iload(fs, old, new) \ + memcpy((new),(old), MIN(EXT2_DINODE_SIZE(fs), sizeof(*new))) +# define e2fs_isave(fs, old, new) \ + memcpy((new),(old), MIN(EXT2_DINODE_SIZE(fs), sizeof(*new))) +#else +struct m_ext2fs; +void e2fs_i_bswap(struct m_ext2fs *, struct ext2fs_dinode *, struct ext2fs_dinode *); +# define e2fs_iload(fs, old, new) e2fs_i_bswap((fs), (old), (new)) +# define e2fs_isave(fs, old, new) e2fs_i_bswap((fs), (old), (new)) +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ufs/ext2fs/ext2fs_dir.h b/lib/libc/include/generic-openbsd/ufs/ext2fs/ext2fs_dir.h new file mode 100644 index 0000000000..b47408f6b0 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ufs/ext2fs/ext2fs_dir.h @@ -0,0 +1,170 @@ +/* $OpenBSD: ext2fs_dir.h,v 1.12 2024/01/09 03:16:00 guenther Exp $ */ +/* $NetBSD: ext2fs_dir.h,v 1.4 2000/01/28 16:00:23 bouyer Exp $ */ + +/* + * Copyright (c) 1997 Manuel Bouyer. + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)dir.h 8.4 (Berkeley) 8/10/94 + * Modified for ext2fs by Manuel Bouyer. + */ + +#ifndef _EXT2FS_DIR_H_ +#define _EXT2FS_DIR_H_ + +/* + * Theoretically, directories can be more than 2Gb in length, however, in + * practice this seems unlikely. So, we define the type doff_t as a 32-bit + * quantity to keep down the cost of doing lookup on a 32-bit machine. + */ +#define doff_t int32_t +#define EXT2FS_MAXDIRSIZE (0x7fffffff) + +/* + * A directory consists of some number of blocks of e2fs_bsize bytes. + * + * Each block contains some number of directory entry + * structures, which are of variable length. Each directory entry has + * a struct direct at the front of it, containing its inode number, + * the length of the entry, and the length of the name contained in + * the entry. These are followed by the name padded to a 4 byte boundary + * with null bytes. All names are guaranteed null terminated. + * The maximum length of a name in a directory is EXT2FS_MAXNAMLEN. + * + * The macro EXT2FS_DIRSIZ(dp) gives the amount of space required to + * represent a directory entry. Free space in a directory is represented by + * entries which have dp->e2d_reclen > DIRSIZ(dp). All d2fs_bsize bytes + * in a directory block are claimed by the directory entries. This + * usually results in the last entry in a directory having a large + * dp->e2d_reclen. When entries are deleted from a directory, the + * space is returned to the previous entry in the same directory + * block by increasing its dp->e2d_reclen. If the first entry of + * a directory block is free, then its dp->e2d_ino is set to 0. + * Entries other than the first in a directory do not normally have + * dp->e2d_ino set to 0. + * Ext2 rev 0 has a 16 bits e2d_namlen. For Ext2 rev 1 this has been split + * into a 8 bits e2d_namlen and 8 bits e2d_type (looks like ffs, isnt't it ? :) + * It's safe to use this for rev 0 as well because all ext2 are little-endian. + */ + +#define EXT2FS_MAXNAMLEN 255 + +struct ext2fs_direct { + u_int32_t e2d_ino; /* inode number of entry */ + u_int16_t e2d_reclen; /* length of this record */ + u_int8_t e2d_namlen; /* length of string in d_name */ + u_int8_t e2d_type; /* file type */ + char e2d_name[EXT2FS_MAXNAMLEN];/* name with length <= EXT2FS_MAXNAMLEN */ +}; + +enum slotstatus { + NONE, + COMPACT, + FOUND +}; + +struct ext2fs_searchslot { + enum slotstatus slotstatus; + doff_t slotoffset; /* offset of area with free space */ + int slotsize; /* size of area at slotoffset */ + int slotfreespace; /* amount of space free in slot */ + int slotneeded; /* sizeof the entry we are seeking */ +}; + +/* Ext2 directory file types (not the same as FFS. Sigh. */ +#define EXT2_FT_UNKNOWN 0 +#define EXT2_FT_REG_FILE 1 +#define EXT2_FT_DIR 2 +#define EXT2_FT_CHRDEV 3 +#define EXT2_FT_BLKDEV 4 +#define EXT2_FT_FIFO 5 +#define EXT2_FT_SOCK 6 +#define EXT2_FT_SYMLINK 7 + +#define EXT2_FT_MAX 8 + +#define E2IFTODT(mode) (((mode) & 0170000) >> 12) + +static __inline__ u_int8_t inot2ext2dt(u_int16_t) + __attribute__((__unused__)); +static __inline__ u_int8_t +inot2ext2dt(u_int16_t type) +{ + switch(type) { + case E2IFTODT(EXT2_IFIFO): + return EXT2_FT_FIFO; + case E2IFTODT(EXT2_IFCHR): + return EXT2_FT_CHRDEV; + case E2IFTODT(EXT2_IFDIR): + return EXT2_FT_DIR; + case E2IFTODT(EXT2_IFBLK): + return EXT2_FT_BLKDEV; + case E2IFTODT(EXT2_IFREG): + return EXT2_FT_REG_FILE; + case E2IFTODT(EXT2_IFLNK): + return EXT2_FT_SYMLINK; + case E2IFTODT(EXT2_IFSOCK): + return EXT2_FT_SOCK; + default: + return 0; + } +} + +/* + * The EXT2FS_DIRSIZ macro gives the minimum record length which will hold + * the directory entryfor a name len "len" (without the terminating null byte). + * This requires the amount of space in struct direct + * without the d_name field, plus enough space for the name without a + * terminating null byte, rounded up to a 4 byte boundary. + */ +#define EXT2FS_DIRSIZ(len) \ + (( 8 + len + 3) &~ 3) + +/* + * Template for manipulating directories. Should use struct direct's, + * but the name field is EXT2FS_MAXNAMLEN - 1, and this just won't do. + */ +struct ext2fs_dirtemplate { + u_int32_t dot_ino; + int16_t dot_reclen; + u_int8_t dot_namlen; + u_int8_t dot_type; + char dot_name[4]; /* must be multiple of 4 */ + u_int32_t dotdot_ino; + int16_t dotdot_reclen; + u_int8_t dotdot_namlen; + u_int8_t dotdot_type; + char dotdot_name[4]; /* ditto */ +}; + +#endif /* !_EXT2FS_DIR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ufs/ext2fs/ext2fs_extents.h b/lib/libc/include/generic-openbsd/ufs/ext2fs/ext2fs_extents.h new file mode 100644 index 0000000000..a682d681b1 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ufs/ext2fs/ext2fs_extents.h @@ -0,0 +1,99 @@ +/*- + * Copyright (c) 2012, 2010 Zheng Liu + * 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 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 AUTHOR 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. + * + * $FreeBSD: head/sys/fs/ext2fs/ext2_extents.h 262623 2014-02-28 21:25:32Z pfg $ + */ +#ifndef _FS_EXT2FS_EXT2_EXTENTS_H_ +#define _FS_EXT2FS_EXT2_EXTENTS_H_ + +#include + +#define EXT4_EXT_MAGIC 0xf30a + +#define EXT4_EXT_CACHE_NO 0 +#define EXT4_EXT_CACHE_GAP 1 +#define EXT4_EXT_CACHE_IN 2 + +/* + * Ext4 file system extent on disk. + */ +struct ext4_extent { + uint32_t e_blk; /* first logical block */ + uint16_t e_len; /* number of blocks */ + uint16_t e_start_hi; /* high 16 bits of physical block */ + uint32_t e_start_lo; /* low 32 bits of physical block */ +}; + +/* + * Extent index on disk. + */ +struct ext4_extent_index { + uint32_t ei_blk; /* indexes logical blocks */ + uint32_t ei_leaf_lo; /* points to physical block of the + * next level */ + uint16_t ei_leaf_hi; /* high 16 bits of physical block */ + uint16_t ei_unused; +}; + +/* + * Extent tree header. + */ +struct ext4_extent_header { + uint16_t eh_magic; /* magic number: 0xf30a */ + uint16_t eh_ecount; /* number of valid entries */ + uint16_t eh_max; /* capacity of store in entries */ + uint16_t eh_depth; /* the depth of extent tree */ + uint32_t eh_gen; /* generation of extent tree */ +}; + +/* + * Save cached extent. + */ +struct ext4_extent_cache { + daddr_t ec_start; /* extent start */ + uint32_t ec_blk; /* logical block */ + uint32_t ec_len; + uint32_t ec_type; +}; + +/* + * Save path to some extent. + */ +struct ext4_extent_path { + uint16_t ep_depth; + struct buf *ep_bp; + struct ext4_extent *ep_ext; + struct ext4_extent_index *ep_index; + struct ext4_extent_header *ep_header; +}; + +struct inode; +struct m_ext2fs; +int ext4_ext_in_cache(struct inode *, daddr_t, struct ext4_extent *); +void ext4_ext_put_cache(struct inode *, struct ext4_extent *, int); +struct ext4_extent_path *ext4_ext_find_extent(struct m_ext2fs *fs, + struct inode *, daddr_t, struct ext4_extent_path *); + +#endif /* !_FS_EXT2FS_EXT2_EXTENTS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ufs/ext2fs/ext2fs_extern.h b/lib/libc/include/generic-openbsd/ufs/ext2fs/ext2fs_extern.h new file mode 100644 index 0000000000..c581077cf4 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ufs/ext2fs/ext2fs_extern.h @@ -0,0 +1,146 @@ +/* $OpenBSD: ext2fs_extern.h,v 1.40 2025/07/07 00:55:15 jsg Exp $ */ +/* $NetBSD: ext2fs_extern.h,v 1.1 1997/06/11 09:33:55 bouyer Exp $ */ + +/*- + * Copyright (c) 1997 Manuel Bouyer. + * Copyright (c) 1991, 1993, 1994 + * 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. + * + * @(#)ffs_extern.h 8.3 (Berkeley) 4/16/94 + * Modified for ext2fs by Manuel Bouyer. + */ + +struct buf; +struct fid; +struct m_ext2fs; +struct inode; +struct mount; +struct nameidata; +struct proc; +struct statfs; +struct timeval; +struct ucred; +struct ufsmount; +struct uio; +struct vnode; +struct vfsconf; +struct mbuf; +struct componentname; + +extern struct pool ext2fs_inode_pool; /* memory pool for inodes */ +extern struct pool ext2fs_dinode_pool; /* memory pool for dinodes */ + +__BEGIN_DECLS + +/* ext2fs_alloc.c */ +int ext2fs_alloc(struct inode *, u_int32_t, u_int32_t , struct ucred *, + u_int32_t *); +int ext2fs_inode_alloc(struct inode *, mode_t mode, struct ucred *, + struct vnode **); +daddr_t ext2fs_blkpref(struct inode *, u_int32_t, int, u_int32_t *); +void ext2fs_blkfree(struct inode *, u_int32_t); +void ext2fs_inode_free(struct inode *, ufsino_t, mode_t); + +/* ext2fs_balloc.c */ +int ext2fs_buf_alloc(struct inode *, u_int32_t, int, struct ucred *, + struct buf **, int); + +/* ext2fs_bmap.c */ +int ext2fs_bmap(void *); + +/* ext2fs_inode.c */ +u_int64_t ext2fs_size(struct inode *); +int ext2fs_init(struct vfsconf *); +int ext2fs_setsize(struct inode *, u_int64_t); +int ext2fs_update(struct inode *ip, int waitfor); +int ext2fs_truncate(struct inode *, off_t, int, struct ucred *); +int ext2fs_inactive(void *); + +/* ext2fs_lookup.c */ +int ext2fs_readdir(void *); +int ext2fs_lookup(void *); +int ext2fs_direnter(struct inode *, struct vnode *, struct componentname *); +int ext2fs_dirremove(struct vnode *, struct componentname *); +int ext2fs_dirrewrite(struct inode *, struct inode *, struct componentname *); +int ext2fs_dirempty(struct inode *, ufsino_t, struct ucred *); +int ext2fs_checkpath(struct inode *, struct inode *, struct ucred *); + +/* ext2fs_subr.c */ +int ext2fs_bufatoff(struct inode *, off_t, char **, struct buf **); +int ext2fs_vinit(struct mount *, struct vnode **); + +/* ext2fs_vfsops.c */ +int ext2fs_mountroot(void); +int ext2fs_mount(struct mount *, const char *, void *, struct nameidata *, + struct proc *); +int ext2fs_reload(struct mount *, struct ucred *, struct proc *); +int ext2fs_mountfs(struct vnode *, struct mount *, struct proc *); +int ext2fs_unmount(struct mount *, int, struct proc *); +int ext2fs_flushfiles(struct mount *, int, struct proc *); +int ext2fs_statfs(struct mount *, struct statfs *, struct proc *); +int ext2fs_sync(struct mount *, int, int, struct ucred *, struct proc *); +int ext2fs_vget(struct mount *, ino_t, struct vnode **); +int ext2fs_fhtovp(struct mount *, struct fid *, struct vnode **); +int ext2fs_vptofh(struct vnode *, struct fid *); +int ext2fs_sbupdate(struct ufsmount *, int); +int ext2fs_cgupdate(struct ufsmount *, int); + +/* ext2fs_readwrite.c */ +int ext2fs_read(void *); +int ext2fs_write(void *); + +/* ext2fs_vnops.c */ +int ext2fs_create(void *); +int ext2fs_mknod(void *); +int ext2fs_open(void *); +int ext2fs_access(void *); +int ext2fs_getattr(void *); +int ext2fs_setattr(void *); +int ext2fs_remove(void *); +int ext2fs_link(void *); +int ext2fs_rename(void *); +int ext2fs_mkdir(void *); +int ext2fs_rmdir(void *); +int ext2fs_symlink(void *); +int ext2fs_readlink(void *); +int ext2fs_pathconf(void *); +int ext2fs_advlock(void *); +int ext2fs_makeinode(int, struct vnode *, struct vnode **, + struct componentname *cnp); +int ext2fs_fsync(void *); +int ext2fs_reclaim(void *); +int ext2fsfifo_reclaim(void *); + +__END_DECLS + +#define IS_EXT2_VNODE(vp) (vp->v_tag == VT_EXT2FS) + +extern const struct vops ext2fs_vops; +extern const struct vops ext2fs_specvops; +#ifdef FIFO +extern const struct vops ext2fs_fifovops; +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ufs/ffs/ffs_extern.h b/lib/libc/include/generic-openbsd/ufs/ffs/ffs_extern.h new file mode 100644 index 0000000000..99a45c6fe4 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ufs/ffs/ffs_extern.h @@ -0,0 +1,170 @@ +/* $OpenBSD: ffs_extern.h,v 1.51 2024/10/08 02:58:26 jsg Exp $ */ +/* $NetBSD: ffs_extern.h,v 1.4 1996/02/09 22:22:22 christos Exp $ */ + +/* + * Copyright (c) 1991, 1993, 1994 + * 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. + * + * @(#)ffs_extern.h 8.3 (Berkeley) 4/16/94 + */ + +#define FFS_CLUSTERREAD 1 /* cluster reading enabled */ +#define FFS_CLUSTERWRITE 2 /* cluster writing enabled */ +#define FFS_REALLOCBLKS 3 /* block reallocation enabled */ +#define FFS_ASYNCFREE 4 /* asynchronous block freeing enabled */ +#define FFS_MAX_SOFTDEPS 5 /* maximum structs before slowdown */ +#define FFS_SD_TICKDELAY 6 /* ticks to pause during slowdown */ +#define FFS_SD_WORKLIST_PUSH 7 /* # of worklist cleanups */ +#define FFS_SD_BLK_LIMIT_PUSH 8 /* # of times block limit neared */ +#define FFS_SD_INO_LIMIT_PUSH 9 /* # of times inode limit neared */ +#define FFS_SD_BLK_LIMIT_HIT 10 /* # of times block slowdown imposed */ +#define FFS_SD_INO_LIMIT_HIT 11 /* # of times inode slowdown imposed */ +#define FFS_SD_SYNC_LIMIT_HIT 12 /* # of synchronous slowdowns imposed */ +#define FFS_SD_INDIR_BLK_PTRS 13 /* bufs redirtied as indir ptrs not written */ +#define FFS_SD_INODE_BITMAP 14 /* bufs redirtied as inode bitmap not written */ +#define FFS_SD_DIRECT_BLK_PTRS 15 /* bufs redirtied as direct ptrs not written */ +#define FFS_SD_DIR_ENTRY 16 /* bufs redirtied as dir entry cannot write */ +#define FFS_DIRHASH_DIRSIZE 17 /* min directory size, in bytes */ +#define FFS_DIRHASH_MAXMEM 18 /* max kvm to use, in bytes */ +#define FFS_DIRHASH_MEM 19 /* current mem usage, in bytes */ +#define FFS_MAXID 20 /* number of valid ffs ids */ + +#define FFS_NAMES { \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "dirhash_dirsize", CTLTYPE_INT }, \ + { "dirhash_maxmem", CTLTYPE_INT }, \ + { "dirhash_mem", CTLTYPE_INT }, \ +} + +struct buf; +struct fid; +struct fs; +struct inode; +struct mount; +struct nameidata; +struct proc; +struct statfs; +struct timeval; +struct ucred; +struct ufsmount; +struct vfsconf; +struct uio; +struct vnode; +struct mbuf; +struct cg; +struct vop_vfree_args; + +extern const struct vops ffs_vops; +extern const struct vops ffs_specvops; +extern const struct vops ffs_fifovops; + +/* ffs_alloc.c */ +int ffs_alloc(struct inode *, daddr_t, daddr_t , int, struct ucred *, + daddr_t *); +int ffs_realloccg(struct inode *, daddr_t, daddr_t, int, int , + struct ucred *, struct buf **, daddr_t *); +int ffs_inode_alloc(struct inode *, mode_t, struct ucred *, struct vnode **); +int ffs_inode_free(struct inode *, ufsino_t, mode_t); +int ffs_freefile(struct inode *, ufsino_t, mode_t); + +int32_t ffs1_blkpref(struct inode *, daddr_t, int, int32_t *); +#ifdef FFS2 +int64_t ffs2_blkpref(struct inode *, daddr_t, int, int64_t *); +#endif +void ffs_blkfree(struct inode *, daddr_t, long); +void ffs_clusteracct(struct fs *, struct cg *, daddr_t, int); + +/* ffs_balloc.c */ +int ffs_balloc(struct inode *, off_t, int, struct ucred *, int, struct buf **); + +/* ffs_inode.c */ +int ffs_init(struct vfsconf *); +int ffs_update(struct inode *, int); +int ffs_truncate(struct inode *, off_t, int, struct ucred *); + +/* ffs_subr.c */ +int ffs_bufatoff(struct inode *, off_t, char **, struct buf **); +void ffs_fragacct(struct fs *, int, int32_t[], int); +int ffs_isfreeblock(struct fs *, u_char *, daddr_t); +int ffs_isblock(struct fs *, u_char *, daddr_t); +void ffs_clrblock(struct fs *, u_char *, daddr_t); +void ffs_setblock(struct fs *, u_char *, daddr_t); +int ffs_vinit(struct mount *, struct vnode **); + +/* ffs_vfsops.c */ +int ffs_mountroot(void); +int ffs_mount(struct mount *, const char *, void *, struct nameidata *, + struct proc *); +int ffs_reload(struct mount *, struct ucred *, struct proc *); +int ffs_mountfs(struct vnode *, struct mount *, struct proc *); +int ffs_oldfscompat(struct fs *); +int ffs_unmount(struct mount *, int, struct proc *); +int ffs_flushfiles(struct mount *, int, struct proc *); +int ffs_statfs(struct mount *, struct statfs *, struct proc *); +int ffs_sync(struct mount *, int, int, struct ucred *, struct proc *); +int ffs_vget(struct mount *, ino_t, struct vnode **); +int ffs_fhtovp(struct mount *, struct fid *, struct vnode **); +int ffs_vptofh(struct vnode *, struct fid *); +int ffs_sysctl(int *, u_int, void *, size_t *, void *, size_t, + struct proc *); +int ffs_sbupdate(struct ufsmount *, int); + +/* ffs_vnops.c */ +int ffs_read(void *); +int ffs_write(void *); +int ffs_fsync(void *); +int ffs_reclaim(void *); +int ffsfifo_reclaim(void *); + +/* + * Soft dependency function prototypes. + */ + +struct vop_vfree_args; +struct vop_fsync_args; + +extern struct pool ffs_ino_pool; /* memory pool for inodes */ +extern struct pool ffs_dinode1_pool; /* memory pool for UFS1 dinodes */ +#ifdef FFS2 +extern struct pool ffs_dinode2_pool; /* memory pool for UFS2 dinodes */ +#endif \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ufs/ffs/fs.h b/lib/libc/include/generic-openbsd/ufs/ffs/fs.h new file mode 100644 index 0000000000..688b167ef2 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ufs/ffs/fs.h @@ -0,0 +1,591 @@ +/* $OpenBSD: fs.h,v 1.45 2024/02/03 18:51:58 beck Exp $ */ +/* $NetBSD: fs.h,v 1.6 1995/04/12 21:21:02 mycroft Exp $ */ + +/* + * Copyright (c) 1982, 1986, 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. + * + * @(#)fs.h 8.10 (Berkeley) 10/27/94 + */ + +/* + * Each disk drive contains some number of file systems. + * A file system consists of a number of cylinder groups. + * Each cylinder group has inodes and data. + * + * A file system is described by its super-block, which in turn + * describes the cylinder groups. The super-block is critical + * data and is replicated in each cylinder group to protect against + * catastrophic loss. This is done at `newfs' time and the critical + * super-block data does not change, so the copies need not be + * referenced further unless disaster strikes. + * + * For file system fs, the offsets of the various blocks of interest + * are given in the super block as: + * [fs->fs_sblkno] Super-block + * [fs->fs_cblkno] Cylinder group block + * [fs->fs_iblkno] Inode blocks + * [fs->fs_dblkno] Data blocks + * The beginning of cylinder group cg in fs, is given by + * the ``cgbase(fs, cg)'' macro. + * + * The first boot and super blocks are given in absolute disk addresses. + * The byte-offset forms are preferred, as they don't imply a sector size. + */ +#define BBSIZE 8192 +#define SBSIZE 8192 +#define BBOFF ((off_t)(0)) +#define SBOFF ((off_t)(BBOFF + BBSIZE)) +#define BBLOCK ((daddr_t)(0)) +#define SBLOCK ((daddr_t)(BBLOCK + BBSIZE / DEV_BSIZE)) +#define SBLOCK_UFS1 8192 +#define SBLOCK_UFS2 65536 +#define SBLOCK_PIGGY 262144 +#define SBLOCKSIZE 8192 +#define SBLOCKSEARCH \ + { SBLOCK_UFS2, SBLOCK_UFS1, SBLOCK_PIGGY, -1 } + +/* + * Addresses stored in inodes are capable of addressing fragments + * of `blocks'. File system blocks of at most size MAXBSIZE can + * be optionally broken into 2, 4, or 8 pieces, each of which is + * addressable; these pieces may be DEV_BSIZE, or some multiple of + * a DEV_BSIZE unit. + * + * Large files consist of exclusively large data blocks. To avoid + * undue wasted disk space, the last data block of a small file may be + * allocated as only as many fragments of a large block as are + * necessary. The file system format retains only a single pointer + * to such a fragment, which is a piece of a single large block that + * has been divided. The size of such a fragment is determinable from + * information in the inode, using the ``blksize(fs, ip, lbn)'' macro. + * + * The file system records space availability at the fragment level; + * to determine block availability, aligned fragments are examined. + */ + +#define MAXFRAG 8 + +/* + * MINBSIZE is the smallest allowable block size. + * In order to insure that it is possible to create files of size + * 2^32 with only two levels of indirection, MINBSIZE is set to 4096. + * MINBSIZE must be big enough to hold a cylinder group block, + * thus changes to (struct cg) must keep its size within MINBSIZE. + * Note that super blocks are always of size SBSIZE, + * and that both SBSIZE and MAXBSIZE must be >= MINBSIZE. + */ +#define MINBSIZE 4096 + +/* + * The path name on which the file system is mounted is maintained + * in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in + * the super block for this name. + */ +#define MAXMNTLEN 468 + +/* + * The volume name for this file system is kept in fs_volname. + * MAXVOLLEN defines the length of the buffer allocated. + */ +#define MAXVOLLEN 32 + +/* + * There is a 128-byte region in the superblock reserved for in-core + * pointers to summary information. Originally this included an array + * of pointers to blocks of struct csum; now there are just three + * pointers and the remaining space is padded with fs_ocsp[]. + * + * NOCSPTRS determines the size of this padding. One pointer (fs_csp) + * is taken away to point to a contiguous array of struct csum for + * all cylinder groups; a second (fs_maxcluster) points to an array + * of cluster sizes that is computed as cylinder groups are inspected, + * and the third points to an array that tracks the creation of new + * directories. + */ +#define NOCSPTRS ((128 / sizeof(void *)) - 4) + +/* + * A summary of contiguous blocks of various sizes is maintained + * in each cylinder group. Normally this is set by the initial + * value of fs_maxcontig. To conserve space, a maximum summary size + * is set by FS_MAXCONTIG. + */ +#define FS_MAXCONTIG 16 + +/* + * MINFREE gives the minimum acceptable percentage of file system + * blocks which may be free. If the freelist drops below this level + * only the superuser may continue to allocate blocks. This may + * be set to 0 if no reserve of free blocks is deemed necessary, + * however throughput drops by fifty percent if the file system + * is run at between 95% and 100% full; thus the minimum default + * value of fs_minfree is 5%. However, to get good clustering + * performance, 10% is a better choice. With 5% free space, + * fragmentation is not a problem, so we choose to optimize for time. + */ +#define MINFREE 5 +#define DEFAULTOPT FS_OPTTIME + +/* + * The directory preference algorithm(dirpref) can be tuned by adjusting + * the following parameters which tell the system the average file size + * and the average number of files per directory. These defaults are well + * selected for typical filesystems, but may need to be tuned for odd + * cases like filesystems being used for squid caches or news spools. + */ +#define AVFILESIZ 16384 /* expected average file size */ +#define AFPDIR 64 /* expected number of files per directory */ + +/* + * Size of superblock space reserved for snapshots. + */ +#define FSMAXSNAP 20 + +/* + * Per cylinder group information; summarized in blocks allocated + * from first cylinder group data blocks. These blocks have to be + * read in from fs_csaddr (size fs_cssize) in addition to the + * super block. + */ +struct csum { + int32_t cs_ndir; /* number of directories */ + int32_t cs_nbfree; /* number of free blocks */ + int32_t cs_nifree; /* number of free inodes */ + int32_t cs_nffree; /* number of free frags */ +}; + +struct csum_total { + int64_t cs_ndir; /* number of directories */ + int64_t cs_nbfree; /* number of free blocks */ + int64_t cs_nifree; /* number of free inodes */ + int64_t cs_nffree; /* number of free frags */ + int64_t cs_spare[4]; /* future expansion */ +}; + +/* + * Super block for an FFS file system. + */ +struct fs { + int32_t fs_firstfield; /* historic file system linked list, */ + int32_t fs_unused_1; /* used for incore super blocks */ + int32_t fs_sblkno; /* addr of super-block / frags */ + int32_t fs_cblkno; /* offset of cyl-block / frags */ + int32_t fs_iblkno; /* offset of inode-blocks / frags */ + int32_t fs_dblkno; /* offset of first data / frags */ + int32_t fs_cgoffset; /* cylinder group offset in cylinder */ + int32_t fs_cgmask; /* used to calc mod fs_ntrak */ + int32_t fs_ffs1_time; /* last time written */ + int32_t fs_ffs1_size; /* # of blocks in fs / frags */ + int32_t fs_ffs1_dsize; /* # of data blocks in fs */ + u_int32_t fs_ncg; /* # of cylinder groups */ + int32_t fs_bsize; /* size of basic blocks / bytes */ + int32_t fs_fsize; /* size of frag blocks / bytes */ + int32_t fs_frag; /* # of frags in a block in fs */ +/* these are configuration parameters */ + int32_t fs_minfree; /* minimum percentage of free blocks */ + int32_t fs_rotdelay; /* # of ms for optimal next block */ + int32_t fs_rps; /* disk revolutions per second */ +/* these fields can be computed from the others */ + int32_t fs_bmask; /* ``blkoff'' calc of blk offsets */ + int32_t fs_fmask; /* ``fragoff'' calc of frag offsets */ + int32_t fs_bshift; /* ``lblkno'' calc of logical blkno */ + int32_t fs_fshift; /* ``numfrags'' calc # of frags */ +/* these are configuration parameters */ + int32_t fs_maxcontig; /* max # of contiguous blks */ + int32_t fs_maxbpg; /* max # of blks per cyl group */ +/* these fields can be computed from the others */ + int32_t fs_fragshift; /* block to frag shift */ + int32_t fs_fsbtodb; /* fsbtodb and dbtofsb shift constant */ + int32_t fs_sbsize; /* actual size of super block */ + int32_t fs_csmask; /* csum block offset (now unused) */ + int32_t fs_csshift; /* csum block number (now unused) */ + int32_t fs_nindir; /* value of NINDIR */ + u_int32_t fs_inopb; /* inodes per file system block */ + int32_t fs_nspf; /* DEV_BSIZE sectors per frag */ +/* yet another configuration parameter */ + int32_t fs_optim; /* optimization preference, see below */ +/* these fields are derived from the hardware */ + int32_t fs_npsect; /* DEV_BSIZE sectors/track + spares */ + int32_t fs_interleave; /* DEV_BSIZE sector interleave */ + int32_t fs_trackskew; /* sector 0 skew, per track */ +/* fs_id takes the space of the unused fs_headswitch and fs_trkseek fields */ + int32_t fs_id[2]; /* unique filesystem id */ +/* sizes determined by number of cylinder groups and their sizes */ + int32_t fs_ffs1_csaddr; /* blk addr of cyl grp summary area */ + int32_t fs_cssize; /* cyl grp summary area size / bytes */ + int32_t fs_cgsize; /* cyl grp block size / bytes */ +/* these fields are derived from the hardware */ + int32_t fs_ntrak; /* tracks per cylinder */ + int32_t fs_nsect; /* DEV_BSIZE sectors per track */ + int32_t fs_spc; /* DEV_BSIZE sectors per cylinder */ +/* this comes from the disk driver partitioning */ + int32_t fs_ncyl; /* cylinders in file system */ +/* these fields can be computed from the others */ + int32_t fs_cpg; /* cylinders per group */ + u_int32_t fs_ipg; /* inodes per group */ + int32_t fs_fpg; /* blocks per group * fs_frag */ +/* this data must be re-computed after crashes */ + struct csum fs_ffs1_cstotal; /* cylinder summary information */ +/* these fields are cleared at mount time */ + int8_t fs_fmod; /* super block modified flag */ + int8_t fs_clean; /* file system is clean flag */ + int8_t fs_ronly; /* mounted read-only flag */ + int8_t fs_ffs1_flags; /* see FS_ below */ + u_char fs_fsmnt[MAXMNTLEN]; /* name mounted on */ + u_char fs_volname[MAXVOLLEN]; /* volume name */ + u_int64_t fs_swuid; /* system-wide uid */ + int32_t fs_pad; /* due to alignment of fs_swuid */ +/* these fields retain the current block allocation info */ + int32_t fs_cgrotor; /* last cg searched */ + void *fs_ocsp[NOCSPTRS]; /* padding; was list of fs_cs buffers */ + u_int8_t *fs_contigdirs; /* # of contiguously allocated dirs */ + struct csum *fs_csp; /* cg summary info buffer for fs_cs */ + int32_t *fs_maxcluster; /* max cluster in each cyl group */ + u_char *fs_active; /* reserved for snapshots */ + int32_t fs_cpc; /* cyl per cycle in postbl */ +/* this area is only allocated if fs_ffs1_flags & FS_FLAGS_UPDATED */ + int32_t fs_maxbsize; /* maximum blocking factor permitted */ + int64_t fs_spareconf64[17]; /* old rotation block list head */ + int64_t fs_sblockloc; /* offset of standard super block */ + struct csum_total fs_cstotal; /* cylinder summary information */ + int64_t fs_time; /* time last written */ + int64_t fs_size; /* number of blocks in fs */ + int64_t fs_dsize; /* number of data blocks in fs */ + int64_t fs_csaddr; /* blk addr of cyl grp summary area */ + int64_t fs_pendingblocks; /* blocks in process of being freed */ + u_int32_t fs_pendinginodes; /* inodes in process of being freed */ + u_int32_t fs_snapinum[FSMAXSNAP];/* space reserved for snapshots */ +/* back to stuff that has been around a while */ + u_int32_t fs_avgfilesize; /* expected average file size */ + u_int32_t fs_avgfpdir; /* expected # of files per directory */ + int32_t fs_sparecon[26]; /* reserved for future constants */ + u_int32_t fs_flags; /* see FS_ flags below */ + int32_t fs_fscktime; /* last time fsck(8)ed */ + int32_t fs_contigsumsize; /* size of cluster summary array */ + int32_t fs_maxsymlinklen; /* max length of an internal symlink */ + int32_t fs_inodefmt; /* format of on-disk inodes */ + u_int64_t fs_maxfilesize; /* maximum representable file size */ + int64_t fs_qbmask; /* ~fs_bmask - for use with quad size */ + int64_t fs_qfmask; /* ~fs_fmask - for use with quad size */ + int32_t fs_state; /* validate fs_clean field */ + int32_t fs_postblformat; /* format of positional layout tables */ + int32_t fs_nrpos; /* number of rotational positions */ + int32_t fs_postbloff; /* (u_int16) rotation block list head */ + int32_t fs_rotbloff; /* (u_int8) blocks for each rotation */ + int32_t fs_magic; /* magic number */ + u_int8_t fs_space[1]; /* list of blocks for each rotation */ +/* actually longer */ +}; + +/* + * Filesystem identification + */ +#define FS_MAGIC 0x011954 /* the fast filesystem magic number */ +#define FS_UFS1_MAGIC 0x011954 /* the fast filesystem magic number */ +#define FS_UFS2_MAGIC 0x19540119 /* UFS fast filesystem magic number */ +#define FS_OKAY 0x7c269d38 /* superblock checksum */ +#define FS_42INODEFMT -1 /* 4.2BSD inode format */ +#define FS_44INODEFMT 2 /* 4.4BSD inode format */ + +/* + * Filesystem clean flags + */ +#define FS_ISCLEAN 0x01 +#define FS_WASCLEAN 0x02 + +/* + * Preference for optimization. + */ +#define FS_OPTTIME 0 /* minimize allocation time */ +#define FS_OPTSPACE 1 /* minimize disk fragmentation */ + +/* + * Filesystem flags. + */ +#define FS_UNCLEAN 0x01 /* filesystem not clean at mount */ +/* + * The following flag is used to detect a FFS1 file system that had its flags + * moved to the new (FFS2) location for compatibility. + */ +#define FS_FLAGS_UPDATED 0x80 /* file system has FFS2-like flags */ + +/* + * Rotational layout table format types + */ +#define FS_42POSTBLFMT -1 /* 4.2BSD rotational table format */ +#define FS_DYNAMICPOSTBLFMT 1 /* dynamic rotational table format */ +/* + * Macros for access to superblock array structures + */ +#define fs_rotbl(fs) \ + (((fs)->fs_postblformat == FS_42POSTBLFMT) \ + ? ((fs)->fs_space) \ + : ((u_int8_t *)((u_int8_t *)(fs) + (fs)->fs_rotbloff))) + +/* + * The size of a cylinder group is calculated by CGSIZE. The maximum size + * is limited by the fact that cylinder groups are at most one block. + * Its size is derived from the size of the maps maintained in the + * cylinder group and the (struct cg) size. + */ +#define CGSIZE(fs) \ + /* base cg */ (sizeof(struct cg) + sizeof(int32_t) + \ + /* blktot size */ (fs)->fs_cpg * sizeof(int32_t) + \ + /* blks size */ (fs)->fs_cpg * (fs)->fs_nrpos * sizeof(int16_t) + \ + /* inode map */ howmany((fs)->fs_ipg, NBBY) + \ + /* block map */ howmany((fs)->fs_fpg, NBBY) + \ + /* if present */ ((fs)->fs_contigsumsize <= 0 ? 0 : \ + /* cluster sum */ (fs)->fs_contigsumsize * sizeof(int32_t) + \ + /* cluster map */ howmany(fragstoblks(fs, (fs)->fs_fpg), NBBY))) + +/* + * Convert cylinder group to base address of its global summary info. + */ +#define fs_cs(fs, indx) fs_csp[indx] + +/* + * Cylinder group block for a file system. + */ +#define CG_MAGIC 0x090255 +struct cg { + int32_t cg_firstfield; /* historic cyl groups linked list */ + int32_t cg_magic; /* magic number */ + int32_t cg_time; /* time last written */ + u_int32_t cg_cgx; /* we are the cgx'th cylinder group */ + int16_t cg_ncyl; /* number of cyl's this cg */ + int16_t cg_niblk; /* number of inode blocks this cg */ + u_int32_t cg_ndblk; /* number of data blocks this cg */ + struct csum cg_cs; /* cylinder summary information */ + u_int32_t cg_rotor; /* position of last used block */ + u_int32_t cg_frotor; /* position of last used frag */ + u_int32_t cg_irotor; /* position of last used inode */ + u_int32_t cg_frsum[MAXFRAG]; /* counts of available frags */ + int32_t cg_btotoff; /* (int32) block totals per cylinder */ + int32_t cg_boff; /* (u_int16) free block positions */ + u_int32_t cg_iusedoff; /* (u_int8) used inode map */ + u_int32_t cg_freeoff; /* (u_int8) free block map */ + u_int32_t cg_nextfreeoff; /* (u_int8) next available space */ + u_int32_t cg_clustersumoff; /* (u_int32) counts of avail clusters */ + u_int32_t cg_clusteroff; /* (u_int8) free cluster map */ + u_int32_t cg_nclusterblks; /* number of clusters this cg */ + u_int32_t cg_ffs2_niblk; /* number of inode blocks this cg */ + u_int32_t cg_initediblk; /* last initialized inode */ + int32_t cg_sparecon32[3]; /* reserved for future use */ + int64_t cg_ffs2_time; /* time last written */ + int64_t cg_sparecon64[3]; /* reserved for future use */ +/* actually longer */ +}; + +/* + * Macros for access to cylinder group array structures + */ +#define cg_blktot(cgp) \ + (((cgp)->cg_magic != CG_MAGIC) \ + ? (((struct ocg *)(cgp))->cg_btot) \ + : ((int32_t *)((u_int8_t *)(cgp) + (cgp)->cg_btotoff))) +#define cg_blks(fs, cgp, cylno) \ + (((cgp)->cg_magic != CG_MAGIC) \ + ? (((struct ocg *)(cgp))->cg_b[cylno]) \ + : ((int16_t *)((u_int8_t *)(cgp) + \ + (cgp)->cg_boff) + (cylno) * (fs)->fs_nrpos)) +#define cg_inosused(cgp) \ + (((cgp)->cg_magic != CG_MAGIC) \ + ? (((struct ocg *)(cgp))->cg_iused) \ + : ((u_int8_t *)((u_int8_t *)(cgp) + (cgp)->cg_iusedoff))) +#define cg_blksfree(cgp) \ + (((cgp)->cg_magic != CG_MAGIC) \ + ? (((struct ocg *)(cgp))->cg_free) \ + : ((u_int8_t *)((u_int8_t *)(cgp) + (cgp)->cg_freeoff))) +#define cg_chkmagic(cgp) \ + ((cgp)->cg_magic == CG_MAGIC || ((struct ocg *)(cgp))->cg_magic == CG_MAGIC) +#define cg_clustersfree(cgp) \ + ((u_int8_t *)((u_int8_t *)(cgp) + (cgp)->cg_clusteroff)) +#define cg_clustersum(cgp) \ + ((int32_t *)((u_int8_t *)(cgp) + (cgp)->cg_clustersumoff)) + +/* + * The following structure is defined + * for compatibility with old file systems. + */ +struct ocg { + int32_t cg_firstfield; /* historic linked list of cyl groups */ + int32_t cg_unused_1; /* used for incore cyl groups */ + int32_t cg_time; /* time last written */ + int32_t cg_cgx; /* we are the cgx'th cylinder group */ + int16_t cg_ncyl; /* number of cyl's this cg */ + int16_t cg_niblk; /* number of inode blocks this cg */ + int32_t cg_ndblk; /* number of data blocks this cg */ + struct csum cg_cs; /* cylinder summary information */ + int32_t cg_rotor; /* position of last used block */ + int32_t cg_frotor; /* position of last used frag */ + int32_t cg_irotor; /* position of last used inode */ + int32_t cg_frsum[8]; /* counts of available frags */ + int32_t cg_btot[32]; /* block totals per cylinder */ + int16_t cg_b[32][8]; /* positions of free blocks */ + u_int8_t cg_iused[256]; /* used inode map */ + int32_t cg_magic; /* magic number */ + u_int8_t cg_free[1]; /* free block map */ +/* actually longer */ +}; + +/* + * Turn file system block numbers into disk block addresses. + * This maps file system blocks to DEV_BSIZE (a.k.a. 512-byte) size disk + * blocks. + */ +#define fsbtodb(fs, b) ((b) << (fs)->fs_fsbtodb) +#define dbtofsb(fs, b) ((b) >> (fs)->fs_fsbtodb) + +/* + * Cylinder group macros to locate things in cylinder groups. + * They calc file system addresses of cylinder group data structures. + */ +#define cgbase(fs, c) ((daddr_t)(fs)->fs_fpg * (c)) +#define cgdata(fs, c) (cgdmin(fs, c) + (fs)->fs_minfree) /* data zone */ +#define cgmeta(fs, c) (cgdmin(fs, c)) /* meta data */ +#define cgdmin(fs, c) (cgstart(fs, c) + (fs)->fs_dblkno) /* 1st data */ +#define cgimin(fs, c) (cgstart(fs, c) + (fs)->fs_iblkno) /* inode blk */ +#define cgsblock(fs, c) (cgstart(fs, c) + (fs)->fs_sblkno) /* super blk */ +#define cgtod(fs, c) (cgstart(fs, c) + (fs)->fs_cblkno) /* cg block */ +#define cgstart(fs, c) \ + (cgbase(fs, c) + (fs)->fs_cgoffset * ((c) & ~((fs)->fs_cgmask))) + +/* + * Macros for handling inode numbers: + * inode number to file system block offset. + * inode number to cylinder group number. + * inode number to file system block address. + */ +#define ino_to_cg(fs, x) ((x) / (fs)->fs_ipg) +#define ino_to_fsba(fs, x) \ + ((daddr_t)(cgimin(fs, ino_to_cg(fs, x)) + \ + (blkstofrags((fs), (((x) % (fs)->fs_ipg) / INOPB(fs)))))) +#define ino_to_fsbo(fs, x) ((x) % INOPB(fs)) + +/* + * Give cylinder group number for a file system block. + * Give frag block number in cylinder group for a file system block. + */ +#define dtog(fs, d) ((d) / (fs)->fs_fpg) +#define dtogd(fs, d) ((d) % (fs)->fs_fpg) + +/* + * Extract the bits for a block from a map. + * Compute the cylinder and rotational position of a cyl block addr. + */ +#define blkmap(fs, map, loc) \ + (((map)[(loc) / NBBY] >> ((loc) % NBBY)) & (0xff >> (NBBY - (fs)->fs_frag))) +#define cbtocylno(fs, bno) \ + (fsbtodb(fs, bno) / (fs)->fs_spc) +#define cbtorpos(fs, bno) \ + ((fs)->fs_nrpos <= 1 ? 0 : \ + (fsbtodb(fs, bno) % (fs)->fs_spc / (fs)->fs_nsect * (fs)->fs_trackskew + \ + fsbtodb(fs, bno) % (fs)->fs_spc % (fs)->fs_nsect * (fs)->fs_interleave) % \ + (fs)->fs_nsect * (fs)->fs_nrpos / (fs)->fs_npsect) + +/* + * The following macros optimize certain frequently calculated + * quantities by using shifts and masks in place of divisions + * modulos and multiplications. + */ +#define blkoff(fs, loc) /* calculates (loc % fs->fs_bsize) */ \ + ((loc) & (fs)->fs_qbmask) +#define fragoff(fs, loc) /* calculates (loc % fs->fs_fsize) */ \ + ((loc) & (fs)->fs_qfmask) +#define lblktosize(fs, blk) /* calculates ((off_t)blk * fs->fs_bsize) */ \ + ((off_t)(blk) << (fs)->fs_bshift) +#define lblkno(fs, loc) /* calculates (loc / fs->fs_bsize) */ \ + ((loc) >> (fs)->fs_bshift) +#define numfrags(fs, loc) /* calculates (loc / fs->fs_fsize) */ \ + ((loc) >> (fs)->fs_fshift) +#define blkroundup(fs, size) /* calculates roundup(size, fs->fs_bsize) */ \ + (((size) + (fs)->fs_qbmask) & (fs)->fs_bmask) +#define fragroundup(fs, size) /* calculates roundup(size, fs->fs_fsize) */ \ + (((size) + (fs)->fs_qfmask) & (fs)->fs_fmask) +#define fragstoblks(fs, frags) /* calculates (frags / fs->fs_frag) */ \ + ((frags) >> (fs)->fs_fragshift) +#define blkstofrags(fs, blks) /* calculates (blks * fs->fs_frag) */ \ + ((blks) << (fs)->fs_fragshift) +#define fragnum(fs, fsb) /* calculates (fsb % fs->fs_frag) */ \ + ((fsb) & ((fs)->fs_frag - 1)) +#define blknum(fs, fsb) /* calculates rounddown(fsb, fs->fs_frag) */ \ + ((fsb) &~ ((fs)->fs_frag - 1)) + +/* + * Determine the number of available frags given a + * percentage to hold in reserve. + */ +#define freespace(fs, percentreserved) \ + (blkstofrags((fs), (fs)->fs_cstotal.cs_nbfree) + \ + (fs)->fs_cstotal.cs_nffree - ((fs)->fs_dsize * (percentreserved) / 100)) + +/* + * Determining the size of a file block in the file system. + */ +#define blksize(fs, ip, lbn) \ + (((lbn) >= NDADDR || DIP((ip), size) >= ((lbn) + 1) << (fs)->fs_bshift) \ + ? (u_int64_t)(fs)->fs_bsize \ + : (fragroundup(fs, blkoff(fs, DIP((ip), size))))) +#define dblksize(fs, dip, lbn) \ + (((lbn) >= NDADDR || (dip)->di_size >= ((lbn) + 1) << (fs)->fs_bshift) \ + ? (u_int64_t)(fs)->fs_bsize \ + : (fragroundup(fs, blkoff(fs, (dip)->di_size)))) + +#define sblksize(fs, size, lbn) \ + (((lbn) >= NDADDR || (size) >= ((lbn) + 1) << (fs)->fs_bshift) \ + ? (u_int64_t)(fs)->fs_bsize \ + : (fragroundup(fs, blkoff(fs, (size))))) + + +/* + * Number of disk sectors per block/fragment; assumes DEV_BSIZE byte + * sector size. + */ +#define NSPB(fs) ((fs)->fs_nspf << (fs)->fs_fragshift) +#define NSPF(fs) ((fs)->fs_nspf) + +/* Number of inodes per file system block (fs->fs_bsize) */ +#define INOPB(fs) ((fs)->fs_inopb) +/* Number of inodes per file system fragment (fs->fs_fsize) */ +#define INOPF(fs) ((fs)->fs_inopb >> (fs)->fs_fragshift) + +/* + * Number of indirects in a file system block. + */ +#define NINDIR(fs) ((fs)->fs_nindir) + +/* Maximum file size the kernel allows. + * Even though ffs can handle files up to 16TB, we do limit the max file + * to 2^31 pages to prevent overflow of a 32-bit unsigned int. The buffer + * cache has its own checks but a little added paranoia never hurts. + */ +#define FS_KERNMAXFILESIZE(pgsiz, fs) ((u_int64_t)0x80000000 * \ + MIN((pgsiz), (fs)->fs_bsize) - 1) + +extern const int inside[], around[]; +extern const u_char *fragtbl[]; \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ufs/mfs/mfs_extern.h b/lib/libc/include/generic-openbsd/ufs/mfs/mfs_extern.h new file mode 100644 index 0000000000..6ae7703437 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ufs/mfs/mfs_extern.h @@ -0,0 +1,63 @@ +/* $OpenBSD: mfs_extern.h,v 1.22 2021/10/02 08:51:41 semarie Exp $ */ +/* $NetBSD: mfs_extern.h,v 1.4 1996/02/09 22:31:27 christos Exp $ */ + +/*- + * Copyright (c) 1991, 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. + * + * @(#)mfs_extern.h 8.2 (Berkeley) 6/16/94 + */ + +struct buf; +struct mount; +struct nameidata; +struct proc; +struct statfs; +struct ucred; +struct vnode; +struct vfsconf; +struct mbuf; +struct mfsnode; + +extern const struct vops mfs_vops; + +/* mfs_vfsops.c */ +int mfs_mount(struct mount *, const char *, void *, struct nameidata *, + struct proc *); +int mfs_start(struct mount *, int, struct proc *); +int mfs_init(struct vfsconf *); +int mfs_checkexp(struct mount *, struct mbuf *, int *, struct ucred **); + +/* mfs_vnops.c */ +int mfs_open(void *); +int mfs_ioctl(void *); +int mfs_strategy(void *); +void mfs_doio(struct mfsnode *, struct buf *); +int mfs_close(void *); +int mfs_inactive(void *); +int mfs_reclaim(void *); +int mfs_print(void *); \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ufs/mfs/mfsnode.h b/lib/libc/include/generic-openbsd/ufs/mfs/mfsnode.h new file mode 100644 index 0000000000..cf33fad913 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ufs/mfs/mfsnode.h @@ -0,0 +1,53 @@ +/* $OpenBSD: mfsnode.h,v 1.15 2016/11/07 00:26:33 guenther Exp $ */ +/* $NetBSD: mfsnode.h,v 1.3 1996/02/09 22:31:31 christos Exp $ */ + +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)mfsnode.h 8.2 (Berkeley) 8/11/93 + */ + +/* + * This structure defines the control data for the memory based file system. + */ + +struct mfsnode { + struct vnode *mfs_vnode; /* vnode associated with this mfsnode */ + struct bufq mfs_bufq; /* bufq for MFS I/O */ + caddr_t mfs_baseoff; /* base of file system in memory */ + long mfs_size; /* size of memory file system */ + pid_t mfs_tid; /* supporting thread's tid */ + struct buf *mfs_buflist; /* list of I/O requests */ + int mfs_shutdown; /* shutdown request */ +}; + +/* + * Convert between mfsnode pointers and vnode pointers + */ +#define VTOMFS(vp) ((struct mfsnode *)(vp)->v_data) +#define MFSTOV(mfsp) ((mfsp)->mfs_vnode) \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ufs/ufs/dinode.h b/lib/libc/include/generic-openbsd/ufs/ufs/dinode.h new file mode 100644 index 0000000000..bfb626a301 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ufs/ufs/dinode.h @@ -0,0 +1,156 @@ +/* $OpenBSD: dinode.h,v 1.19 2020/05/28 15:48:29 otto Exp $ */ +/* $NetBSD: dinode.h,v 1.7 1995/06/15 23:22:48 cgd Exp $ */ + +/* + * Copyright (c) 1982, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)dinode.h 8.9 (Berkeley) 3/29/95 + */ + +#ifndef _UFS_DINODE_H_ +#define _UFS_DINODE_H_ + +/* + * UFS directories use 32bit inode numbers internally, regardless + * of what the system on top of it uses. + */ +typedef u_int32_t ufsino_t; + +/* + * The root inode is the root of the file system. Inode 0 can't be used for + * normal purposes and historically bad blocks were linked to inode 1, thus + * the root inode is 2. (Inode 1 is no longer used for this purpose, however + * numerous dump tapes make this assumption, so we are stuck with it). + */ +#define ROOTINO ((ufsino_t)2) + +/* + * A dinode contains all the meta-data associated with a UFS file. + * This structure defines the on-disk format of a dinode. Since + * this structure describes an on-disk structure, all its fields + * are defined by types with precise widths. + */ +#define NXADDR 2 /* External addresses in inode */ +#define NDADDR 12 /* Direct addresses in inode. */ +#define NIADDR 3 /* Indirect addresses in inode. */ + +struct ufs1_dinode { + u_int16_t di_mode; /* 0: IFMT, permissions; see below. */ + int16_t di_nlink; /* 2: File link count. */ + union { + u_int16_t oldids[2]; /* 4: Ffs: old user and group ids. */ + u_int32_t inumber; /* 4: Lfs: inode number. */ + } di_u; + u_int64_t di_size; /* 8: File byte count. */ + int32_t di_atime; /* 16: Last access time. */ + int32_t di_atimensec; /* 20: Last access time. */ + int32_t di_mtime; /* 24: Last modified time. */ + int32_t di_mtimensec; /* 28: Last modified time. */ + int32_t di_ctime; /* 32: Last inode change time. */ + int32_t di_ctimensec; /* 36: Last inode change time. */ + int32_t di_db[NDADDR]; /* 40: Direct disk blocks. */ + int32_t di_ib[NIADDR]; /* 88: Indirect disk blocks. */ + u_int32_t di_flags; /* 100: Status flags (chflags). */ + int32_t di_blocks; /* 104: Blocks actually held. */ + u_int32_t di_gen; /* 108: Generation number. */ + u_int32_t di_uid; /* 112: File owner. */ + u_int32_t di_gid; /* 116: File group. */ + int32_t di_spare[2]; /* 120: Reserved; currently unused */ +}; + +struct ufs2_dinode { + u_int16_t di_mode; /* 0: IFMT, permissions; see below. */ + int16_t di_nlink; /* 2: File link count. */ + u_int32_t di_uid; /* 4: File owner. */ + u_int32_t di_gid; /* 8: File group. */ + u_int32_t di_blksize; /* 12: Inode blocksize. */ + u_int64_t di_size; /* 16: File byte count. */ + u_int64_t di_blocks; /* 24: Bytes actually held. */ + int64_t di_atime; /* 32: Last access time. */ + int64_t di_mtime; /* 40: Last modified time. */ + int64_t di_ctime; /* 48: Last inode change time. */ + int64_t di_birthtime; /* 56: Inode creation time. */ + int32_t di_mtimensec; /* 64: Last modified time. */ + int32_t di_atimensec; /* 68: Last access time. */ + int32_t di_ctimensec; /* 72: Last inode change time. */ + int32_t di_birthnsec; /* 76: Inode creation time. */ + int32_t di_gen; /* 80: Generation number. */ + u_int32_t di_kernflags; /* 84: Kernel flags. */ + u_int32_t di_flags; /* 88: Status flags (chflags). */ + int32_t di_extsize; /* 92: External attributes block. */ + int64_t di_extb[NXADDR];/* 96: External attributes block. */ + int64_t di_db[NDADDR]; /* 112: Direct disk blocks. */ + int64_t di_ib[NIADDR]; /* 208: Indirect disk blocks. */ + int64_t di_spare[3]; /* 232: Reserved; currently unused */ +}; + +/* + * The di_db fields may be overlaid with other information for + * file types that do not have associated disk storage. Block + * and character devices overlay the first data block with their + * dev_t value. Short symbolic links place their path in the + * di_db area. + */ +#define di_inumber di_u.inumber +#define di_ogid di_u.oldids[1] +#define di_ouid di_u.oldids[0] +#define di_rdev di_db[0] +#define di_shortlink di_db + +#define MAXSYMLINKLEN_UFS1 ((NDADDR + NIADDR) * sizeof(int32_t)) +#define MAXSYMLINKLEN_UFS2 ((NDADDR + NIADDR) * sizeof(int64_t)) + +#define MAXSYMLINKLEN(ip) \ + ((ip)->i_ump->um_fstype == UM_UFS1) ? \ + MAXSYMLINKLEN_UFS1 : MAXSYMLINKLEN_UFS2 + +/* File permissions. */ +#define IEXEC 0000100 /* Executable. */ +#define IWRITE 0000200 /* Writeable. */ +#define IREAD 0000400 /* Readable. */ +#define ISVTX 0001000 /* Sticky bit. */ +#define ISGID 0002000 /* Set-gid. */ +#define ISUID 0004000 /* Set-uid. */ + +/* File types. */ +#define IFMT 0170000 /* Mask of file type. */ +#define IFIFO 0010000 /* Named pipe (fifo). */ +#define IFCHR 0020000 /* Character device. */ +#define IFDIR 0040000 /* Directory file. */ +#define IFBLK 0060000 /* Block device. */ +#define IFREG 0100000 /* Regular file. */ +#define IFLNK 0120000 /* Symbolic link. */ +#define IFSOCK 0140000 /* UNIX domain socket. */ +#define IFWHT 0160000 /* Whiteout. */ + +#endif /* _UFS_DINODE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ufs/ufs/dir.h b/lib/libc/include/generic-openbsd/ufs/ufs/dir.h new file mode 100644 index 0000000000..8ce82cc088 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ufs/ufs/dir.h @@ -0,0 +1,134 @@ +/* $OpenBSD: dir.h,v 1.13 2024/01/09 03:15:59 guenther Exp $ */ +/* $NetBSD: dir.h,v 1.8 1996/03/09 19:42:41 scottr Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)dir.h 8.4 (Berkeley) 8/10/94 + */ + +#ifndef _DIR_H_ +#define _DIR_H_ + +/* + * Theoretically, directories can be more than 2Gb in length, however, in + * practice this seems unlikely. So, we define the type doff_t as a 32-bit + * quantity to keep down the cost of doing lookup on a 32-bit machine. + */ +#define doff_t int32_t +#define MAXDIRSIZE (0x7fffffff) + +/* + * A directory consists of some number of blocks of DIRBLKSIZ + * bytes, where DIRBLKSIZ is chosen such that it can be transferred + * to disk in a single atomic operation (e.g. 512 bytes on most machines). + * + * Each DIRBLKSIZ byte block contains some number of directory entry + * structures, which are of variable length. Each directory entry has + * a struct direct at the front of it, containing its inode number, + * the length of the entry, and the length of the name contained in + * the entry. These are followed by the name padded to a 4 byte boundary + * with null bytes. All names are guaranteed null terminated. + * The maximum length of a name in a directory is MAXNAMLEN. + * + * The macro DIRSIZ(dp) gives the amount of space required to represent + * a directory entry. Free space in a directory is represented by + * entries which have dp->d_reclen > DIRSIZ(dp). All DIRBLKSIZ bytes + * in a directory block are claimed by the directory entries. This + * usually results in the last entry in a directory having a large + * dp->d_reclen. When entries are deleted from a directory, the + * space is returned to the previous entry in the same directory + * block by increasing its dp->d_reclen. If the first entry of + * a directory block is free, then its dp->d_ino is set to 0. + * Entries other than the first in a directory do not normally have + * dp->d_ino set to 0. + */ +#define DIRBLKSIZ DEV_BSIZE +#define MAXNAMLEN 255 + +struct direct { + u_int32_t d_ino; /* inode number of entry */ + u_int16_t d_reclen; /* length of this record */ + u_int8_t d_type; /* file type, see below */ + u_int8_t d_namlen; /* length of string in d_name */ + char d_name[MAXNAMLEN + 1];/* name with length <= MAXNAMLEN */ +}; + +/* + * File types + */ +#define DT_UNKNOWN 0 +#define DT_FIFO 1 +#define DT_CHR 2 +#define DT_DIR 4 +#define DT_BLK 6 +#define DT_REG 8 +#define DT_LNK 10 +#define DT_SOCK 12 + +/* + * Convert between stat structure types and directory types. + */ +#define IFTODT(mode) (((mode) & 0170000) >> 12) +#define DTTOIF(dirtype) ((dirtype) << 12) + +/* + * The DIRSIZ macro gives the minimum record length which will hold + * the directory entry. This requires the amount of space in struct direct + * without the d_name field, plus enough space for the name with a terminating + * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary. + */ +#define DIR_ROUNDUP 4 /* Directory name roundup size */ +#define DIRECTSIZ(namlen) \ + ((offsetof(struct direct, d_name) + \ + ((namlen)+1)*sizeof(((struct direct *)0)->d_name[0]) + 3) & ~3) +#define DIRSIZ(dp) \ + ((sizeof(struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3)) + +/* + * Template for manipulating directories. Should use struct direct's, + * but the name field is MAXNAMLEN - 1, and this just won't do. + */ +struct dirtemplate { + u_int32_t dot_ino; + int16_t dot_reclen; + u_int8_t dot_type; + u_int8_t dot_namlen; + char dot_name[4]; /* must be multiple of 4 */ + u_int32_t dotdot_ino; + int16_t dotdot_reclen; + u_int8_t dotdot_type; + u_int8_t dotdot_namlen; + char dotdot_name[4]; /* ditto */ +}; +#endif /* !_DIR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ufs/ufs/dirhash.h b/lib/libc/include/generic-openbsd/ufs/ufs/dirhash.h new file mode 100644 index 0000000000..6424604803 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ufs/ufs/dirhash.h @@ -0,0 +1,132 @@ +/* $OpenBSD: dirhash.h,v 1.9 2024/10/14 02:20:01 jsg Exp $ */ +/* + * Copyright (c) 2001 Ian Dowse. 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 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 AUTHOR 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. + * + * $FreeBSD: src/sys/ufs/ufs/dirhash.h,v 1.4 2003/01/01 18:48:59 schweikh Exp $ + */ + +#ifndef _UFS_UFS_DIRHASH_H_ +#define _UFS_UFS_DIRHASH_H_ + +#include + +/* + * For fast operations on large directories, we maintain a hash + * that maps the file name to the offset of the directory entry within + * the directory file. + * + * The hashing uses a dumb spillover to the next free slot on + * collisions, so we must keep the utilisation low to avoid + * long linear searches. Deleted entries that are not the last + * in a chain must be marked DIRHASH_DEL. + * + * We also maintain information about free space in each block + * to speed up creations. + */ +#define DIRHASH_EMPTY (-1) /* entry unused */ +#define DIRHASH_DEL (-2) /* deleted entry; may be part of chain */ + +#define DIRALIGN 4 +#define DH_NFSTATS (DIRECTSIZ(MAXNAMLEN + 1) / DIRALIGN) + /* max DIRALIGN words in a directory entry */ + +/* + * Dirhash uses a score mechanism to achieve a hybrid between a + * least-recently-used and a least-often-used algorithm for entry + * recycling. The score is incremented when a directory is used, and + * decremented when the directory is a candidate for recycling. When + * the score reaches zero, the hash is recycled. Hashes are linked + * together on a TAILQ list, and hashes with higher scores filter + * towards the tail (most recently used) end of the list. + * + * New hash entries are given an initial score of DH_SCOREINIT and are + * placed at the most-recently-used end of the list. This helps a lot + * in the worst-case case scenario where every directory access is + * to a directory that is not hashed (i.e. the working set of hash + * candidates is much larger than the configured memory limit). In this + * case it limits the number of hash builds to 1/DH_SCOREINIT of the + * number of accesses. + */ +#define DH_SCOREINIT 8 /* initial dh_score when dirhash built */ +#define DH_SCOREMAX 64 /* max dh_score value */ + +/* + * The main hash table has 2 levels. It is an array of pointers to + * blocks of DH_NBLKOFF offsets. + */ +#define DH_BLKOFFSHIFT 8 +#define DH_NBLKOFF (1 << DH_BLKOFFSHIFT) +#define DH_BLKOFFMASK (DH_NBLKOFF - 1) + +#define DH_ENTRY(dh, slot) \ + ((dh)->dh_hash[(slot) >> DH_BLKOFFSHIFT][(slot) & DH_BLKOFFMASK]) + +struct dirhash { + struct rwlock dh_mtx; /* protects all fields except dh_list */ + doff_t **dh_hash; /* the hash array (2-level) */ + int dh_narrays; /* number of entries in dh_hash */ + int dh_hlen; /* total slots in the 2-level hash array */ + int dh_hused; /* entries in use */ + + /* Free space statistics. XXX assumes DIRBLKSIZ is 512. */ + u_int8_t *dh_blkfree; /* free DIRALIGN words in each dir block */ + int dh_nblk; /* size of dh_blkfree array */ + int dh_dirblks; /* number of DIRBLKSIZ blocks in dir */ + int dh_firstfree[DH_NFSTATS + 1]; /* first blk with N words free */ + + int dh_seqopt; /* sequential access optimisation enabled */ + doff_t dh_seqoff; /* sequential access optimisation offset */ + + int dh_score; /* access count for this dirhash */ + + int dh_onlist; /* true if on the ufsdirhash_list chain */ + + /* Protected by ufsdirhash_mtx. */ + TAILQ_ENTRY(dirhash) dh_list; /* chain of all dirhashes */ +}; + +extern int ufs_mindirhashsize; +extern int ufs_dirhashmaxmem; +extern int ufs_dirhashmem; + +/* + * Dirhash functions. + */ +void ufsdirhash_init(void); +void ufsdirhash_uninit(void); +int ufsdirhash_build(struct inode *); +doff_t ufsdirhash_findfree(struct inode *, int, int *); +doff_t ufsdirhash_enduseful(struct inode *); +int ufsdirhash_lookup(struct inode *, char *, int, doff_t *, struct buf **, + doff_t *); +void ufsdirhash_newblk(struct inode *, doff_t); +void ufsdirhash_add(struct inode *, struct direct *, doff_t); +void ufsdirhash_remove(struct inode *, struct direct *, doff_t); +void ufsdirhash_move(struct inode *, struct direct *, doff_t, doff_t); +void ufsdirhash_dirtrunc(struct inode *, doff_t); +void ufsdirhash_free(struct inode *); + +void ufsdirhash_checkblock(struct inode *, char *, doff_t); + +#endif /* !_UFS_UFS_DIRHASH_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ufs/ufs/inode.h b/lib/libc/include/generic-openbsd/ufs/ufs/inode.h new file mode 100644 index 0000000000..7d253d1b24 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ufs/ufs/inode.h @@ -0,0 +1,344 @@ +/* $OpenBSD: inode.h,v 1.54 2024/02/03 18:51:58 beck Exp $ */ +/* $NetBSD: inode.h,v 1.8 1995/06/15 23:22:50 cgd Exp $ */ + +/* + * Copyright (c) 1982, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)inode.h 8.5 (Berkeley) 7/8/94 + */ + +#include +#include +#include +#include +#include +#include + + +/* + * Per-filesystem inode extensions. + */ +struct ext2fs_inode_ext { + u_int32_t ext2fs_last_lblk; /* last logical blk allocated */ + u_int32_t ext2fs_last_blk; /* last blk allocated on disk */ + u_int32_t ext2fs_effective_uid; /* effective inode uid */ + u_int32_t ext2fs_effective_gid; /* effective inode gid */ + struct ext4_extent_cache ext2fs_extent_cache; +}; + +/* + * The inode is used to describe each active (or recently active) file in the + * UFS filesystem. It is composed of two types of information. The first part + * is the information that is needed only while the file is active (such as + * the identity of the file and linkage to speed its lookup). The second part + * is * the permanent meta-data associated with the file which is read in + * from the permanent dinode from long term storage when the file becomes + * active, and is put back when the file is no longer being used. + */ +struct inode { + LIST_ENTRY(inode) i_hash; /* Hash chain */ + struct vnode *i_vnode;/* Vnode associated with this inode. */ + struct ufsmount *i_ump; + u_int32_t i_flag; /* flags, see below */ + dev_t i_dev; /* Device associated with the inode. */ + ufsino_t i_number; /* The identity of the inode. */ + int i_effnlink; /* i_nlink when I/O completes */ + + union { /* Associated filesystem. */ + struct fs *fs; /* FFS */ + struct m_ext2fs *e2fs; /* EXT2FS */ + } inode_u; + +#define i_fs inode_u.fs +#define i_e2fs inode_u.e2fs + + struct cluster_info i_ci; + struct dquot *i_dquot[MAXQUOTAS]; /* Dquot structures. */ + u_quad_t i_modrev; /* Revision level for NFS lease. */ + struct lockf_state *i_lockf; /* Byte-level lock state. */ + struct rrwlock i_lock;/* Inode lock */ + + /* + * Side effects; used during directory lookup. + */ + int32_t i_count; /* Size of free slot in directory. */ + doff_t i_endoff; /* End of useful stuff in directory. */ + doff_t i_diroff; /* Offset in dir, where we found last entry. */ + doff_t i_offset; /* Offset of free space in directory. */ + ufsino_t i_ino; /* Inode number of found directory. */ + u_int32_t i_reclen; /* Size of found directory entry. */ + /* + * Inode extensions + */ + union { + /* Other extensions could go here... */ + struct ext2fs_inode_ext e2fs; + struct dirhash *dirhash; + } inode_ext; + +#define i_e2fs_last_lblk inode_ext.e2fs.ext2fs_last_lblk +#define i_e2fs_last_blk inode_ext.e2fs.ext2fs_last_blk +#define i_e2fs_uid inode_ext.e2fs.ext2fs_effective_uid +#define i_e2fs_gid inode_ext.e2fs.ext2fs_effective_gid +#define i_e2fs_ext_cache inode_ext.e2fs.ext2fs_extent_cache +#define i_dirhash inode_ext.dirhash + + /* + * The on-disk dinode itself. + */ + union { + struct ufs1_dinode *ffs1_din; + struct ufs2_dinode *ffs2_din; + struct ext2fs_dinode *e2fs_din; + } dinode_u; + +#define i_din1 dinode_u.ffs1_din +#define i_din2 dinode_u.ffs2_din +#define i_e2din dinode_u.e2fs_din + + struct inode_vtbl *i_vtbl; +}; + +struct inode_vtbl { + int (* iv_truncate)(struct inode *, off_t, int, + struct ucred *); + int (* iv_update)(struct inode *, int waitfor); + int (* iv_inode_alloc)(struct inode *, mode_t mode, + struct ucred *, struct vnode **); + int (* iv_inode_free)(struct inode *, ufsino_t ino, mode_t mode); + int (* iv_buf_alloc)(struct inode *, off_t, int, struct ucred *, + int, struct buf **); + int (* iv_bufatoff)(struct inode *, off_t offset, char **res, + struct buf **bpp); +}; + +#define UFS_TRUNCATE(ip, off, flags, cred) \ + ((ip)->i_vtbl->iv_truncate)((ip), (off), (flags), (cred)) + +#define UFS_UPDATE(ip, sync) \ + ((ip)->i_vtbl->iv_update)((ip), (sync)) + +#define UFS_INODE_ALLOC(pip, mode, cred, vpp) \ + ((pip)->i_vtbl->iv_inode_alloc)((pip), (mode), (cred), (vpp)) + +#define UFS_INODE_FREE(pip, ino, mode) \ + ((pip)->i_vtbl->iv_inode_free)((pip), (ino), (mode)) + +#define UFS_BUF_ALLOC(ip, startoffset, size, cred, flags, bpp) \ + ((ip)->i_vtbl->iv_buf_alloc)((ip), (startoffset), (size), (cred), \ + (flags), (bpp)) + +#define UFS_BUFATOFF(ip, offset, res, bpp) \ + ((ip)->i_vtbl->iv_bufatoff)((ip), (offset), (res), (bpp)) + +#define i_ffs1_atime i_din1->di_atime +#define i_ffs1_atimensec i_din1->di_atimensec +#define i_ffs1_blocks i_din1->di_blocks +#define i_ffs1_ctime i_din1->di_ctime +#define i_ffs1_ctimensec i_din1->di_ctimensec +#define i_ffs1_db i_din1->di_db +#define i_ffs1_flags i_din1->di_flags +#define i_ffs1_gen i_din1->di_gen +#define i_ffs1_gid i_din1->di_gid +#define i_ffs1_ib i_din1->di_ib +#define i_ffs1_mode i_din1->di_mode +#define i_ffs1_mtime i_din1->di_mtime +#define i_ffs1_mtimensec i_din1->di_mtimensec +#define i_ffs1_nlink i_din1->di_nlink +#define i_ffs1_rdev i_din1->di_rdev +#define i_ffs1_shortlink i_din1->di_shortlink +#define i_ffs1_size i_din1->di_size +#define i_ffs1_uid i_din1->di_uid + +#define i_ffs2_atime i_din2->di_atime +#define i_ffs2_atimensec i_din2->di_atimensec +#define i_ffs2_blocks i_din2->di_blocks +#define i_ffs2_blksize i_din2->di_blksize +#define i_ffs2_ctime i_din2->di_ctime +#define i_ffs2_ctimensec i_din2->di_ctimensec +#define i_ffs2_db i_din2->di_db +#define i_ffs2_flags i_din2->di_flags +#define i_ffs2_gen i_din2->di_gen +#define i_ffs2_gid i_din2->di_gid +#define i_ffs2_ib i_din2->di_ib +#define i_ffs2_mode i_din2->di_mode +#define i_ffs2_mtime i_din2->di_mtime +#define i_ffs2_mtimensec i_din2->di_mtimensec +#define i_ffs2_nlink i_din2->di_nlink +#define i_ffs2_rdev i_din2->di_rdev +#define i_ffs2_size i_din2->di_size +#define i_ffs2_uid i_din2->di_uid + +#ifndef _KERNEL +/* + * These are here purely for backwards compatibility for userland. + * They allow direct references to FFS structures using the old names. + */ +#define i_atime i_din1->di_atime +#define i_atimensec i_din1->di_atimensec +#define i_blocks i_din1->di_blocks +#define i_ctime i_din1->di_ctime +#define i_ctimensec i_din1->di_ctimensec +#define i_db i_din1->di_db +#define i_flags i_din1->di_flags +#define i_gen i_din1->di_gen +#define i_gid i_din1->di_gid +#define i_ib i_din1->di_ib +#define i_mode i_din1->di_mode +#define i_mtime i_din1->di_mtime +#define i_mtimensec i_din1->di_mtimensec +#define i_nlink i_din1->di_nlink +#define i_rdev i_din1->di_rdev +#define i_shortlink i_din1->di_shortlink +#define i_size i_din1->di_size +#define i_uid i_din1->di_uid +#endif /* _KERNEL */ + +#define i_e2fs_mode i_e2din->e2di_mode +#define i_e2fs_size i_e2din->e2di_size +#define i_e2fs_atime i_e2din->e2di_atime +#define i_e2fs_ctime i_e2din->e2di_ctime +#define i_e2fs_mtime i_e2din->e2di_mtime +#define i_e2fs_dtime i_e2din->e2di_dtime +#define i_e2fs_nlink i_e2din->e2di_nlink +#define i_e2fs_nblock i_e2din->e2di_nblock +#define i_e2fs_flags i_e2din->e2di_flags +#define i_e2fs_blocks i_e2din->e2di_blocks +#define i_e2fs_gen i_e2din->e2di_gen +#define i_e2fs_facl i_e2din->e2di_facl +#define i_e2fs_size_hi i_e2din->e2di_size_hi +#define i_e2fs_faddr i_e2din->e2di_faddr +#define i_e2fs_nblock_hi i_e2din->e2di_nblock_hi +#define i_e2fs_faddr_hi i_e2din->e2di_faddr_hi +#define i_e2fs_uid_low i_e2din->e2di_uid_low +#define i_e2fs_gid_low i_e2din->e2di_gid_low +#define i_e2fs_uid_high i_e2din->e2di_uid_high +#define i_e2fs_gid_high i_e2din->e2di_gid_high + +/* These flags are kept in i_flag. */ +#define IN_ACCESS 0x0001 /* Access time update request. */ +#define IN_CHANGE 0x0002 /* Inode change time update request. */ +#define IN_UPDATE 0x0004 /* Modification time update request */ +#define IN_MODIFIED 0x0008 /* Inode has been modified. */ +#define IN_RENAME 0x0010 /* Inode is being renamed. */ +#define IN_SHLOCK 0x0020 /* File has shared lock. */ +#define IN_EXLOCK 0x0040 /* File has exclusive lock. */ +#define IN_LAZYMOD 0x0080 /* Modified, but don't write yet. */ +#define IN_HASHED 0x0100 /* Inode is on the hash chain */ + +#define i_devvp i_ump->um_devvp + +#ifdef _KERNEL + +/* + * The DIP macros are used to access fields in the dinode. + */ + +#ifdef FFS2 +#define DIP(ip, field) \ + (((ip)->i_ump->um_fstype == UM_UFS1) ? \ + (ip)->i_ffs1_##field : (ip)->i_ffs2_##field) +#else +#define DIP(ip, field) \ + ((ip)->i_ffs1_##field) +#endif + +#ifdef FFS2 +#define DIP_OP(ip, field, op, value) \ + do { \ + if ((ip)->i_ump->um_fstype == UM_UFS1) \ + (ip)->i_ffs1_##field op (value); \ + else \ + (ip)->i_ffs2_##field op (value); \ + } while (0) +#else +#define DIP_OP(ip, field, op, value) \ + do { \ + (ip)->i_ffs1_##field op (value); \ + } while (0) +#endif + +#define DIP_ASSIGN(ip, field, value) DIP_OP(ip, field, =, value) +#define DIP_ADD(ip, field, value) DIP_OP(ip, field, +=, value) +#define DIP_AND(ip, field, value) DIP_OP(ip, field, &=, value) +#define DIP_OR(ip, field, value) DIP_OP(ip, field, |=, value) + +#ifdef FFS2 +#define SHORTLINK(ip) \ + (((ip)->i_ump->um_fstype == UM_UFS1) ? \ + (caddr_t)(ip)->i_ffs1_db : (caddr_t)(ip)->i_ffs2_db) +#else +#define SHORTLINK(ip) \ + ((caddr_t)(ip)->i_ffs1_db) +#endif + +/* + * Structure used to pass around logical block paths generated by + * ufs_getlbns and used by truncate and bmap code. + */ +struct indir { + daddr_t in_lbn; /* Logical block number. */ + int in_off; /* Offset in buffer. */ + int in_exists; /* Flag if the block exists. */ +}; + +/* Convert between inode pointers and vnode pointers. */ +#define VTOI(vp) ((struct inode *)(vp)->v_data) +#define ITOV(ip) ((ip)->i_vnode) + +#define EXT2FS_ITIMES(ip) do { \ + if ((ip)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE)) { \ + (ip)->i_flag |= IN_MODIFIED; \ + if ((ip)->i_flag & IN_ACCESS) \ + (ip)->i_e2fs_atime = gettime(); \ + if ((ip)->i_flag & IN_UPDATE) \ + (ip)->i_e2fs_mtime = gettime(); \ + if ((ip)->i_flag & IN_CHANGE) { \ + (ip)->i_e2fs_ctime = gettime(); \ + (ip)->i_modrev++; \ + } \ + (ip)->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE); \ + } \ +} while (0) + +/* Determine if soft dependencies are being done */ +#define DOINGASYNC(vp) ((vp)->v_mount->mnt_flag & MNT_ASYNC) + +/* This overlays the fid structure (see mount.h). */ +struct ufid { + u_int16_t ufid_len; /* Length of structure. */ + u_int16_t ufid_pad; /* Force 32-bit alignment. */ + ufsino_t ufid_ino; /* File number (ino). */ + u_int32_t ufid_gen; /* Generation number. */ +}; +#endif /* _KERNEL */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ufs/ufs/quota.h b/lib/libc/include/generic-openbsd/ufs/ufs/quota.h new file mode 100644 index 0000000000..c00330a773 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ufs/ufs/quota.h @@ -0,0 +1,149 @@ +/* $OpenBSD: quota.h,v 1.12 2013/07/03 04:58:40 guenther Exp $ */ +/* $NetBSD: quota.h,v 1.6 1995/03/26 20:38:17 jtc Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Robert Elz at The University of Melbourne. + * + * 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. + * + * @(#)quota.h 8.3 (Berkeley) 8/19/94 + */ + +#ifndef _QUOTA_ +#define _QUOTA_ + +/* + * Definitions for disk quotas imposed on the average user + * (big brother finally hits UNIX). + * + * The following constants define the amount of time given a user before the + * soft limits are treated as hard limits (usually resulting in an allocation + * failure). The timer is started when the user crosses their soft limit, it + * is reset when they go below their soft limit. + */ +#define MAX_IQ_TIME (7*24*60*60) /* seconds in 1 week */ +#define MAX_DQ_TIME (7*24*60*60) /* seconds in 1 week */ + +/* + * The following constants define the usage of the quota file array in the + * ufsmount structure and dquot array in the inode structure. The semantics + * of the elements of these arrays are defined in the routine getinoquota; + * the remainder of the quota code treats them generically and need not be + * inspected when changing the size of the array. + */ +#define MAXQUOTAS 2 +#define USRQUOTA 0 /* element used for user quotas */ +#define GRPQUOTA 1 /* element used for group quotas */ + +/* + * Definitions for the default names of the quotas files. + */ +#define INITQFNAMES { \ + "user", /* USRQUOTA */ \ + "group", /* GRPQUOTA */ \ + "undefined", \ +} +#define QUOTAFILENAME "quota" +#define QUOTAGROUP "operator" + +/* + * Command definitions for the 'quotactl' system call. The commands are + * broken into a main command defined below and a subcommand that is used + * to convey the type of quota that is being manipulated (see above). + */ +#define SUBCMDMASK 0x00ff +#define SUBCMDSHIFT 8 +#define QCMD(cmd, type) (((cmd) << SUBCMDSHIFT) | ((type) & SUBCMDMASK)) + +#define Q_QUOTAON 0x0100 /* enable quotas */ +#define Q_QUOTAOFF 0x0200 /* disable quotas */ +#define Q_GETQUOTA 0x0300 /* get limits and usage */ +#define Q_SETQUOTA 0x0400 /* set limits and usage */ +#define Q_SETUSE 0x0500 /* set usage */ +#define Q_SYNC 0x0600 /* sync disk copy of a filesystems quotas */ + +/* + * The following structure defines the format of the disk quota file + * (as it appears on disk) - the file is an array of these structures + * indexed by user or group number. The setquota system call establishes + * the vnode for each quota file (a pointer is retained in the ufsmount + * structure). + */ +struct dqblk { + u_int32_t dqb_bhardlimit; /* absolute limit on disk blks alloc */ + u_int32_t dqb_bsoftlimit; /* preferred limit on disk blks */ + u_int32_t dqb_curblocks; /* current block count */ + u_int32_t dqb_ihardlimit; /* maximum # allocated inodes + 1 */ + u_int32_t dqb_isoftlimit; /* preferred inode limit */ + u_int32_t dqb_curinodes; /* current # allocated inodes */ + /* XXX 2038 */ + u_int32_t dqb_btime; /* time limit for excessive disk use */ + u_int32_t dqb_itime; /* time limit for excessive files */ +}; + +#ifdef _KERNEL +/* + * Flags to ufs_quota_{alloc,free}_{blocks,inode}2 + */ +enum ufs_quota_flags { + UFS_QUOTA_NOUID = 0x1, /* Don't change UID quota */ + UFS_QUOTA_NOGID = 0x2, /* Don't change GID quota */ + UFS_QUOTA_FORCE = 0x1000 /* don't check limits - just change it */ +}; /* Change GID */ + +struct dquot; +struct inode; +struct mount; +struct proc; +struct ucred; +struct ufsmount; +struct vnode; +__BEGIN_DECLS +#define ufs_quota_alloc_blocks(i, c, cr) ufs_quota_alloc_blocks2(i, c, cr, 0) +#define ufs_quota_free_blocks(i, c, cr) ufs_quota_free_blocks2(i, c, cr, 0) +#define ufs_quota_alloc_inode(i, cr) ufs_quota_alloc_inode2(i, cr, 0) +#define ufs_quota_free_inode(i, cr) ufs_quota_free_inode2(i, cr, 0) +int ufs_quota_alloc_blocks2(struct inode *, daddr_t, struct ucred *, enum ufs_quota_flags); +int ufs_quota_free_blocks2(struct inode *, daddr_t, struct ucred *, enum ufs_quota_flags); +int ufs_quota_alloc_inode2(struct inode *, struct ucred *, enum ufs_quota_flags); +int ufs_quota_free_inode2(struct inode *, struct ucred *, enum ufs_quota_flags); + +int ufs_quota_delete(struct inode *); + +int getinoquota(struct inode *); +int quotaoff(struct proc *, struct mount *, int); +int qsync(struct mount *mp); +int ufs_quotactl(struct mount *, int, uid_t, caddr_t, struct proc *); + +void ufs_quota_init(void); + +__END_DECLS +#endif /* _KERNEL */ + +#endif /* _QUOTA_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ufs/ufs/ufs_extern.h b/lib/libc/include/generic-openbsd/ufs/ufs/ufs_extern.h new file mode 100644 index 0000000000..aba1b88467 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ufs/ufs/ufs_extern.h @@ -0,0 +1,132 @@ +/* $OpenBSD: ufs_extern.h,v 1.41 2024/07/07 01:39:06 jsg Exp $ */ +/* $NetBSD: ufs_extern.h,v 1.5 1996/02/09 22:36:03 christos Exp $ */ + +/*- + * Copyright (c) 1991, 1993, 1994 + * 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. + * + * @(#)ufs_extern.h 8.6 (Berkeley) 8/10/94 + */ + +struct buf; +struct componentname; +struct direct; +struct disklabel; +struct dquot; +struct fid; +struct flock; +struct indir; +struct inode; +struct mbuf; +struct mount; +struct nameidata; +struct proc; +struct ucred; +struct ufs_args; +struct ufsmount; +struct uio; +struct vattr; +struct vfsconf; +struct vnode; + +int ufs_access(void *); +int ufs_advlock(void *); +int ufs_bmap(void *); +int ufs_close(void *); +int ufs_create(void *); +int ufs_getattr(void *); +int ufs_inactive(void *); +int ufs_ioctl(void *); +int ufs_islocked(void *); +int ufs_link(void *); +int ufs_lock(void *); +int ufs_lookup(void *); +int ufs_mkdir(void *); +int ufs_mknod(void *); +int ufs_open(void *); +int ufs_pathconf(void *); +int ufs_print(void *); +int ufs_readdir(void *); +int ufs_readlink(void *); +int ufs_remove(void *); +int ufs_rename(void *); +int ufs_rmdir(void *); +int ufs_kqfilter(void *); +int ufs_setattr(void *); +int ufs_strategy(void *); +int ufs_symlink(void *); +int ufs_unlock(void *); +int ufsspec_close(void *); +int ufsspec_read(void *); +int ufsspec_write(void *); + +#ifdef FIFO +int ufsfifo_read(void *); +int ufsfifo_write(void *); +int ufsfifo_close(void *); +#endif + +/* ufs_bmap.c */ +int ufs_bmaparray(struct vnode *, daddr_t, daddr_t *, struct indir *, + int *, int *); +int ufs_getlbns(struct vnode *, daddr_t, struct indir *, int *); + +/* ufs_ihash.c */ +void ufs_ihashinit(void); +struct vnode *ufs_ihashget(dev_t, ufsino_t); +int ufs_ihashins(struct inode *); +void ufs_ihashrem(struct inode *); + +/* ufs_inode.c */ +int ufs_init(struct vfsconf *); +int ufs_reclaim(struct vnode *); + +/* ufs_lookup.c */ +void ufs_dirbad(struct inode *, doff_t, char *); +int ufs_dirbadentry(struct vnode *, struct direct *, int); +void ufs_makedirentry(struct inode *, struct componentname *, + struct direct *); +int ufs_direnter(struct vnode *, struct vnode *, struct direct *, + struct componentname *, struct buf *); +int ufs_dirremove(struct vnode *, struct inode *, int, int); +int ufs_dirrewrite(struct inode *, struct inode *, + ufsino_t, int, int); +int ufs_dirempty(struct inode *, ufsino_t, struct ucred *); +int ufs_checkpath(struct inode *, struct inode *, struct ucred *); + +/* ufs_vfsops.c */ +int ufs_start(struct mount *, int, struct proc *); +int ufs_root(struct mount *, struct vnode **); +int ufs_quotactl(struct mount *, int, uid_t, caddr_t, struct proc *); +int ufs_fhtovp(struct mount *, struct ufid *, struct vnode **); +int ufs_check_export(struct mount *, struct mbuf *, int *, + struct ucred **); + +/* ufs_vnops.c */ +void ufs_itimes(struct vnode *); +int ufs_makeinode(int, struct vnode *, struct vnode **, + struct componentname *); \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/ufs/ufs/ufsmount.h b/lib/libc/include/generic-openbsd/ufs/ufs/ufsmount.h new file mode 100644 index 0000000000..47d82b8559 --- /dev/null +++ b/lib/libc/include/generic-openbsd/ufs/ufs/ufsmount.h @@ -0,0 +1,94 @@ +/* $OpenBSD: ufsmount.h,v 1.13 2016/02/27 18:50:38 natano Exp $ */ +/* $NetBSD: ufsmount.h,v 1.4 1994/12/21 20:00:23 mycroft Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1989, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ufsmount.h 8.4 (Berkeley) 10/27/94 + */ + +struct buf; +struct inode; +struct nameidata; +struct timeval; +struct ucred; +struct uio; +struct vnode; +struct netexport; + +/* This structure describes the UFS specific mount structure data. */ +struct ufsmount { + struct mount *um_mountp; /* filesystem vfs structure */ + dev_t um_dev; /* device mounted */ + struct vnode *um_devvp; /* block device mounted vnode */ + u_long um_fstype; /* type of file system */ + + union { /* pointer to superblock */ + struct fs *fs; /* FFS */ + struct m_ext2fs *e2fs; /* EXT2FS */ + } ufsmount_u; +#define um_fs ufsmount_u.fs +#define um_e2fs ufsmount_u.e2fs +#define um_e2fsb ufsmount_u.e2fs->s_es + + struct vnode *um_quotas[MAXQUOTAS]; /* pointer to quota files */ + struct ucred *um_cred[MAXQUOTAS]; /* quota file access cred */ + u_long um_nindir; /* indirect ptrs per block */ + u_long um_bptrtodb; /* indir ptr to disk block */ + u_long um_seqinc; /* inc between seq blocks */ + time_t um_btime[MAXQUOTAS]; /* block quota time limit */ + time_t um_itime[MAXQUOTAS]; /* inode quota time limit */ + char um_qflags[MAXQUOTAS]; /* quota specific flags */ + struct netexport um_export; /* export information */ + u_int64_t um_savedmaxfilesize; /* XXX - limit maxfilesize */ + u_int um_maxsymlinklen; /* max size of short symlink */ +}; + +/* + * Filesystem types + */ +#define UM_UFS1 1 +#define UM_UFS2 2 +#define UM_EXT2FS 3 + +/* + * Flags describing the state of quotas. + */ +#define QTF_OPENING 0x01 /* Q_QUOTAON in progress */ +#define QTF_CLOSING 0x02 /* Q_QUOTAOFF in progress */ + +/* Convert mount ptr to ufsmount ptr. */ +#define VFSTOUFS(mp) ((struct ufsmount *)((mp)->mnt_data)) + +/* + * Macros to access file system parameters in the ufsmount structure. + * Used by ufs_bmap. + */ +#define MNINDIR(ump) ((ump)->um_nindir) +#define blkptrtodb(ump, b) ((b) << (ump)->um_bptrtodb) +#define is_sequential(ump, a, b) ((b) == (a) + ump->um_seqinc) \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/unistd.h b/lib/libc/include/generic-openbsd/unistd.h new file mode 100644 index 0000000000..115e53fda2 --- /dev/null +++ b/lib/libc/include/generic-openbsd/unistd.h @@ -0,0 +1,541 @@ +/* $OpenBSD: unistd.h,v 1.112 2025/05/24 06:49:16 deraadt Exp $ */ +/* $NetBSD: unistd.h,v 1.26.4.1 1996/05/28 02:31:51 mrg Exp $ */ + +/*- + * Copyright (c) 1991 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. + * + * @(#)unistd.h 5.13 (Berkeley) 6/17/91 + */ + +#ifndef _UNISTD_H_ +#define _UNISTD_H_ + +#include +#include +#include + +#define STDIN_FILENO 0 /* standard input file descriptor */ +#define STDOUT_FILENO 1 /* standard output file descriptor */ +#define STDERR_FILENO 2 /* standard error file descriptor */ + +#if __XPG_VISIBLE || __POSIX_VISIBLE >= 200112 +#define F_ULOCK 0 /* unlock locked section */ +#define F_LOCK 1 /* lock a section for exclusive use */ +#define F_TLOCK 2 /* test and lock a section for exclusive use */ +#define F_TEST 3 /* test a section for locks by other procs */ +#endif + +/* + * POSIX options and option groups we unconditionally do or don't + * implement. Please keep this list in alphabetical order. + * + * Anything which is defined as zero below **must** have an + * implementation for the corresponding sysconf() which is able to + * determine conclusively whether or not the feature is supported. + * Anything which is defined as other than -1 below **must** have + * complete headers, types, and function declarations as specified by + * the POSIX standard; however, if the relevant sysconf() function + * returns -1, the functions may be stubbed out. + */ +#define _POSIX_ADVISORY_INFO (-1) +#define _POSIX_ASYNCHRONOUS_IO (-1) +#define _POSIX_BARRIERS 200112L +#define _POSIX_CHOWN_RESTRICTED 1 +#define _POSIX_CLOCK_SELECTION (-1) +#define _POSIX_CPUTIME 200809L +#define _POSIX_FSYNC 200112L +#define _POSIX_IPV6 0 +#define _POSIX_JOB_CONTROL 1 +#define _POSIX_MAPPED_FILES 200112L +#define _POSIX_MEMLOCK 200112L +#define _POSIX_MEMLOCK_RANGE 200112L +#define _POSIX_MEMORY_PROTECTION 200112L +#define _POSIX_MESSAGE_PASSING (-1) +#define _POSIX_MONOTONIC_CLOCK 200112L +#define _POSIX_NO_TRUNC 1 +#define _POSIX_PRIORITIZED_IO (-1) +#define _POSIX_PRIORITY_SCHEDULING (-1) +#define _POSIX_RAW_SOCKETS 200112L +#define _POSIX_READER_WRITER_LOCKS 200112L +#define _POSIX_REALTIME_SIGNALS (-1) +#define _POSIX_REGEXP 1 +#define _POSIX_SAVED_IDS 1 +#define _POSIX_SEMAPHORES 200112L +#define _POSIX_SHARED_MEMORY_OBJECTS 200809L +#define _POSIX_SHELL 1 +#define _POSIX_SPAWN 200112L +#define _POSIX_SPIN_LOCKS 200112L +#define _POSIX_SPORADIC_SERVER (-1) +#define _POSIX_SYNCHRONIZED_IO (-1) +#define _POSIX_THREAD_ATTR_STACKADDR 200112L +#define _POSIX_THREAD_ATTR_STACKSIZE 200112L +#define _POSIX_THREAD_CPUTIME 200809L +#define _POSIX_THREAD_PRIO_INHERIT (-1) +#define _POSIX_THREAD_PRIO_PROTECT (-1) +#define _POSIX_THREAD_PRIORITY_SCHEDULING (-1) +#define _POSIX_THREAD_PROCESS_SHARED (-1) +#define _POSIX_THREAD_ROBUST_PRIO_INHERIT (-1) +#define _POSIX_THREAD_ROBUST_PRIO_PROTECT (-1) +#define _POSIX_THREAD_SAFE_FUNCTIONS 200112L +#define _POSIX_THREAD_SPORADIC_SERVER (-1) +#define _POSIX_THREADS 200112L +#define _POSIX_TIMEOUTS 200112L +#define _POSIX_TIMERS (-1) +#define _POSIX_TRACE (-1) +#define _POSIX_TRACE_EVENT_FILTER (-1) +#define _POSIX_TRACE_INHERIT (-1) +#define _POSIX_TRACE_LOG (-1) +#define _POSIX_TYPED_MEMORY_OBJECTS (-1) +#define _POSIX2_C_BIND 200112L +#define _POSIX2_C_DEV (-1) /* need C99 utility */ +#define _POSIX2_CHAR_TERM 1 +#define _POSIX2_FORT_DEV (-1) /* need fort77 utility */ +#define _POSIX2_FORT_RUN (-1) /* need asa utility */ +#define _POSIX2_LOCALEDEF (-1) +#define _POSIX2_PBS (-1) +#define _POSIX2_PBS_ACCOUNTING (-1) +#define _POSIX2_PBS_CHECKPOINT (-1) +#define _POSIX2_PBS_LOCATE (-1) +#define _POSIX2_PBS_MESSAGE (-1) +#define _POSIX2_PBS_TRACK (-1) +#define _POSIX2_SW_DEV 200112L +#define _POSIX2_UPE 200112L +#define _POSIX_V6_ILP32_OFF32 (-1) +#define _POSIX_V6_ILP32_OFFBIG 0 +#define _POSIX_V6_LP64_OFF64 0 +#define _POSIX_V6_LPBIG_OFFBIG 0 +#define _POSIX_V7_ILP32_OFF32 (-1) +#define _POSIX_V7_ILP32_OFFBIG 0 +#define _POSIX_V7_LP64_OFF64 0 +#define _POSIX_V7_LPBIG_OFFBIG 0 + +#define _XOPEN_CRYPT 1 +#define _XOPEN_ENH_I18N (-1) /* mandatory in XSI */ +#define _XOPEN_LEGACY (-1) +#define _XOPEN_REALTIME (-1) +#define _XOPEN_REALTIME_THREADS (-1) +#define _XOPEN_SHM 1 +#define _XOPEN_STREAMS (-1) +#define _XOPEN_UUCP (-1) +#define _XOPEN_UNIX (-1) + +/* Define the POSIX.2 version we target for compliance. */ +#define _POSIX2_VERSION 200809L + +/* the sysconf(3) variable values are part of the ABI */ + +/* configurable system variables */ +#define _SC_ARG_MAX 1 +#define _SC_CHILD_MAX 2 +#define _SC_CLK_TCK 3 +#define _SC_NGROUPS_MAX 4 +#define _SC_OPEN_MAX 5 +#define _SC_JOB_CONTROL 6 +#define _SC_SAVED_IDS 7 +#define _SC_VERSION 8 +#define _SC_BC_BASE_MAX 9 +#define _SC_BC_DIM_MAX 10 +#define _SC_BC_SCALE_MAX 11 +#define _SC_BC_STRING_MAX 12 +#define _SC_COLL_WEIGHTS_MAX 13 +#define _SC_EXPR_NEST_MAX 14 +#define _SC_LINE_MAX 15 +#define _SC_RE_DUP_MAX 16 +#define _SC_2_VERSION 17 +#define _SC_2_C_BIND 18 +#define _SC_2_C_DEV 19 +#define _SC_2_CHAR_TERM 20 +#define _SC_2_FORT_DEV 21 +#define _SC_2_FORT_RUN 22 +#define _SC_2_LOCALEDEF 23 +#define _SC_2_SW_DEV 24 +#define _SC_2_UPE 25 +#define _SC_STREAM_MAX 26 +#define _SC_TZNAME_MAX 27 +#define _SC_PAGESIZE 28 +#define _SC_PAGE_SIZE _SC_PAGESIZE /* 1170 compatibility */ +#define _SC_FSYNC 29 +#define _SC_XOPEN_SHM 30 +#define _SC_SEM_NSEMS_MAX 31 +#define _SC_SEM_VALUE_MAX 32 +#define _SC_HOST_NAME_MAX 33 +#define _SC_MONOTONIC_CLOCK 34 +#define _SC_2_PBS 35 +#define _SC_2_PBS_ACCOUNTING 36 +#define _SC_2_PBS_CHECKPOINT 37 +#define _SC_2_PBS_LOCATE 38 +#define _SC_2_PBS_MESSAGE 39 +#define _SC_2_PBS_TRACK 40 +#define _SC_ADVISORY_INFO 41 +#define _SC_AIO_LISTIO_MAX 42 +#define _SC_AIO_MAX 43 +#define _SC_AIO_PRIO_DELTA_MAX 44 +#define _SC_ASYNCHRONOUS_IO 45 +#define _SC_ATEXIT_MAX 46 +#define _SC_BARRIERS 47 +#define _SC_CLOCK_SELECTION 48 +#define _SC_CPUTIME 49 +#define _SC_DELAYTIMER_MAX 50 +#define _SC_IOV_MAX 51 +#define _SC_IPV6 52 +#define _SC_MAPPED_FILES 53 +#define _SC_MEMLOCK 54 +#define _SC_MEMLOCK_RANGE 55 +#define _SC_MEMORY_PROTECTION 56 +#define _SC_MESSAGE_PASSING 57 +#define _SC_MQ_OPEN_MAX 58 +#define _SC_MQ_PRIO_MAX 59 +#define _SC_PRIORITIZED_IO 60 +#define _SC_PRIORITY_SCHEDULING 61 +#define _SC_RAW_SOCKETS 62 +#define _SC_READER_WRITER_LOCKS 63 +#define _SC_REALTIME_SIGNALS 64 +#define _SC_REGEXP 65 +#define _SC_RTSIG_MAX 66 +#define _SC_SEMAPHORES 67 +#define _SC_SHARED_MEMORY_OBJECTS 68 +#define _SC_SHELL 69 +#define _SC_SIGQUEUE_MAX 70 +#define _SC_SPAWN 71 +#define _SC_SPIN_LOCKS 72 +#define _SC_SPORADIC_SERVER 73 +#define _SC_SS_REPL_MAX 74 +#define _SC_SYNCHRONIZED_IO 75 +#define _SC_SYMLOOP_MAX 76 +#define _SC_THREAD_ATTR_STACKADDR 77 +#define _SC_THREAD_ATTR_STACKSIZE 78 +#define _SC_THREAD_CPUTIME 79 +#define _SC_THREAD_DESTRUCTOR_ITERATIONS 80 +#define _SC_THREAD_KEYS_MAX 81 +#define _SC_THREAD_PRIO_INHERIT 82 +#define _SC_THREAD_PRIO_PROTECT 83 +#define _SC_THREAD_PRIORITY_SCHEDULING 84 +#define _SC_THREAD_PROCESS_SHARED 85 +#define _SC_THREAD_ROBUST_PRIO_INHERIT 86 +#define _SC_THREAD_ROBUST_PRIO_PROTECT 87 +#define _SC_THREAD_SPORADIC_SERVER 88 +#define _SC_THREAD_STACK_MIN 89 +#define _SC_THREAD_THREADS_MAX 90 +#define _SC_THREADS 91 +#define _SC_TIMEOUTS 92 +#define _SC_TIMER_MAX 93 +#define _SC_TIMERS 94 +#define _SC_TRACE 95 +#define _SC_TRACE_EVENT_FILTER 96 +#define _SC_TRACE_EVENT_NAME_MAX 97 +#define _SC_TRACE_INHERIT 98 +#define _SC_TRACE_LOG 99 +#define _SC_GETGR_R_SIZE_MAX 100 +#define _SC_GETPW_R_SIZE_MAX 101 +#define _SC_LOGIN_NAME_MAX 102 +#define _SC_THREAD_SAFE_FUNCTIONS 103 +#define _SC_TRACE_NAME_MAX 104 +#define _SC_TRACE_SYS_MAX 105 +#define _SC_TRACE_USER_EVENT_MAX 106 +#define _SC_TTY_NAME_MAX 107 +#define _SC_TYPED_MEMORY_OBJECTS 108 +#define _SC_V6_ILP32_OFF32 109 +#define _SC_V6_ILP32_OFFBIG 110 +#define _SC_V6_LP64_OFF64 111 +#define _SC_V6_LPBIG_OFFBIG 112 +#define _SC_V7_ILP32_OFF32 113 +#define _SC_V7_ILP32_OFFBIG 114 +#define _SC_V7_LP64_OFF64 115 +#define _SC_V7_LPBIG_OFFBIG 116 +#define _SC_XOPEN_CRYPT 117 +#define _SC_XOPEN_ENH_I18N 118 +#define _SC_XOPEN_LEGACY 119 +#define _SC_XOPEN_REALTIME 120 +#define _SC_XOPEN_REALTIME_THREADS 121 +#define _SC_XOPEN_STREAMS 122 +#define _SC_XOPEN_UNIX 123 +#define _SC_XOPEN_UUCP 124 +#define _SC_XOPEN_VERSION 125 + +#define _SC_PHYS_PAGES 500 +#define _SC_AVPHYS_PAGES 501 +#define _SC_NPROCESSORS_CONF 502 +#define _SC_NPROCESSORS_ONLN 503 + +/* configurable system strings */ +#define _CS_PATH 1 +#define _CS_POSIX_V6_ILP32_OFF32_CFLAGS 2 +#define _CS_POSIX_V6_ILP32_OFF32_LDFLAGS 3 +#define _CS_POSIX_V6_ILP32_OFF32_LIBS 4 +#define _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS 5 +#define _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS 6 +#define _CS_POSIX_V6_ILP32_OFFBIG_LIBS 7 +#define _CS_POSIX_V6_LP64_OFF64_CFLAGS 8 +#define _CS_POSIX_V6_LP64_OFF64_LDFLAGS 9 +#define _CS_POSIX_V6_LP64_OFF64_LIBS 10 +#define _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS 11 +#define _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS 12 +#define _CS_POSIX_V6_LPBIG_OFFBIG_LIBS 13 +#define _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS 14 +#define _CS_V6_ENV 15 +#define _CS_POSIX_V7_ILP32_OFF32_CFLAGS 16 +#define _CS_POSIX_V7_ILP32_OFF32_LDFLAGS 17 +#define _CS_POSIX_V7_ILP32_OFF32_LIBS 18 +#define _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS 19 +#define _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS 20 +#define _CS_POSIX_V7_ILP32_OFFBIG_LIBS 21 +#define _CS_POSIX_V7_LP64_OFF64_CFLAGS 22 +#define _CS_POSIX_V7_LP64_OFF64_LDFLAGS 23 +#define _CS_POSIX_V7_LP64_OFF64_LIBS 24 +#define _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS 25 +#define _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS 26 +#define _CS_POSIX_V7_LPBIG_OFFBIG_LIBS 27 +#define _CS_POSIX_V7_THREADS_CFLAGS 28 +#define _CS_POSIX_V7_THREADS_LDFLAGS 29 +#define _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS 30 +#define _CS_V7_ENV 31 + +#ifndef _INTPTR_T_DEFINED_ +#define _INTPTR_T_DEFINED_ +typedef __intptr_t intptr_t; +#endif + +__BEGIN_DECLS +__dead void _exit(int); +int access(const char *, int); +unsigned int alarm(unsigned int); +int chdir(const char *); +int chown(const char *, uid_t, gid_t); +int close(int); +int dup(int); +int dup2(int, int); +int execl(const char *, const char *, ...) + __attribute__((__sentinel__)); +int execle(const char *, const char *, ...); +int execlp(const char *, const char *, ...) + __attribute__((__sentinel__)); +int execv(const char *, char *const *); +int execve(const char *, char *const *, char *const *); +int execvp(const char *, char *const *); +#if __BSD_VISIBLE +int execvpe(const char *, char *const *, char *const *); +#endif +pid_t fork(void); +long fpathconf(int, int); +char *getcwd(char *, size_t) + __attribute__((__bounded__(__string__,1,2))); +gid_t getegid(void); +uid_t geteuid(void); +gid_t getgid(void); +int getgroups(int, gid_t *); +char *getlogin(void); +pid_t getpgrp(void); +pid_t getpid(void); +pid_t getppid(void); +uid_t getuid(void); +int isatty(int); +int link(const char *, const char *); +off_t lseek(int, off_t, int); +long pathconf(const char *, int); +#if __BSD_VISIBLE +long pathconfat(int, const char *, int, int); +#endif +int pause(void); +int pipe(int *); +ssize_t read(int, void *, size_t) + __attribute__((__bounded__(__buffer__,2,3))); +int rmdir(const char *); +int setgid(gid_t); +int setuid(uid_t); +unsigned int sleep(unsigned int); +long sysconf(int); +pid_t tcgetpgrp(int); +int tcsetpgrp(int, pid_t); +char *ttyname(int); +int unlink(const char *); +ssize_t write(int, const void *, size_t) + __attribute__((__bounded__(__buffer__,2,3))); + +#if __POSIX_VISIBLE || __XPG_VISIBLE >= 300 +pid_t setsid(void); +int setpgid(pid_t, pid_t); +#endif + +#if __POSIX_VISIBLE >= 199209 || __XPG_VISIBLE +size_t confstr(int, char *, size_t) + __attribute__((__bounded__(__string__,2,3))); +#ifndef _GETOPT_DEFINED_ +#define _GETOPT_DEFINED_ +int getopt(int, char * const *, const char *); +extern char *optarg; /* getopt(3) external variables */ +extern int opterr, optind, optopt, optreset; +#endif /* _GETOPT_DEFINED_ */ +#endif + +#if __POSIX_VISIBLE >= 199506 || __XPG_VISIBLE +int fsync(int); +int ftruncate(int, off_t); +int getlogin_r(char *, size_t) + __attribute__((__bounded__(__string__,1,2))); +ssize_t readlink(const char * __restrict, char * __restrict, size_t) + __attribute__ ((__bounded__(__string__,2,3))); +#endif +#if __POSIX_VISIBLE >= 199506 +int fdatasync(int); +#endif + +#if __XPG_VISIBLE || __BSD_VISIBLE +char *crypt(const char *, const char *); +int fchdir(int); +int fchown(int, uid_t, gid_t); +long gethostid(void); +char *getwd(char *) + __attribute__ ((__bounded__(__minbytes__,1,1024))); +int lchown(const char *, uid_t, gid_t); +int mkstemp(char *); +char *mktemp(char *); +int nice(int); +int setregid(gid_t, gid_t); +int setreuid(uid_t, uid_t); +void swab(const void *__restrict, void *__restrict, ssize_t); +void sync(void); +int truncate(const char *, off_t); +useconds_t ualarm(useconds_t, useconds_t); +int usleep(useconds_t); +pid_t vfork(void); +#endif + +#if __POSIX_VISIBLE >= 200809 || __XPG_VISIBLE >= 420 +pid_t getpgid(pid_t); +pid_t getsid(pid_t); +#endif + +#if __XPG_VISIBLE >= 500 +ssize_t pread(int, void *, size_t, off_t) + __attribute__((__bounded__(__buffer__,2,3))); +ssize_t pwrite(int, const void *, size_t, off_t) + __attribute__((__bounded__(__buffer__,2,3))); +int ttyname_r(int, char *, size_t) + __attribute__((__bounded__(__string__,2,3))); +#endif + +#if __BSD_VISIBLE || __XPG_VISIBLE <= 500 +/* Interfaces withdrawn by X/Open Issue 5 Version 0 */ +int brk(void *); +int chroot(const char *); +int getdtablesize(void); +int getpagesize(void); +char *getpass(const char *); +void *sbrk(int); +#endif + +#if __POSIX_VISIBLE >= 200112 || __XPG_VISIBLE >= 420 +int lockf(int, int, off_t); +#endif + +#if __POSIX_VISIBLE >= 200112 || __XPG_VISIBLE >= 420 || __BSD_VISIBLE +int symlink(const char *, const char *); +int gethostname(char *, size_t) + __attribute__ ((__bounded__(__string__,1,2))); +int setegid(gid_t); +int seteuid(uid_t); +#endif + +#if __POSIX_VISIBLE >= 200809 +int faccessat(int, const char *, int, int); +int fchownat(int, const char *, uid_t, gid_t, int); +int linkat(int, const char *, int, const char *, int); +ssize_t readlinkat(int, const char *, char *, size_t) + __attribute__ ((__bounded__(__string__,3,4))); +int symlinkat(const char *, int, const char *); +int unlinkat(int, const char *, int); +#endif + +#if __POSIX_VISIBLE >= 202405 || __BSD_VISIBLE +int getentropy(void *, size_t); +#endif +#if __XPG_VISIBLE >= 800 || __BSD_VISIBLE +int getresgid(gid_t *, gid_t *, gid_t *); +int getresuid(uid_t *, uid_t *, uid_t *); +int setresgid(gid_t, gid_t, gid_t); +int setresuid(uid_t, uid_t, uid_t); +#endif + +#if __BSD_VISIBLE +int dup3(int, int, int); +int pipe2(int [2], int); +#endif + +#if __BSD_VISIBLE +int acct(const char *); +int closefrom(int); +int crypt_checkpass(const char *, const char *); +int crypt_newhash(const char *, const char *, char *, size_t); +void endusershell(void); +char *fflagstostr(u_int32_t); +int getdomainname(char *, size_t) + __attribute__ ((__bounded__(__string__,1,2))); +int getdtablecount(void); +int getgrouplist(const char *, gid_t, gid_t *, int *); +mode_t getmode(const void *, mode_t); +pid_t getthrid(void); +int getthrname(pid_t, char *, size_t); +char *getusershell(void); +int initgroups(const char *, gid_t); +int issetugid(void); +char *mkdtemp(char *); +int mkstemps(char *, int); +int nfssvc(int, void *); +int profil(void *, size_t, size_t, unsigned long, unsigned int, int) + __attribute__ ((__bounded__(__string__,1,2))); +int quotactl(const char *, int, int, char *); +int rcmd(char **, int, const char *, + const char *, const char *, int *); +int rcmd_af(char **, int, const char *, + const char *, const char *, int *, int); +int rcmdsh(char **, int, const char *, + const char *, const char *, char *); +int reboot(int); +int revoke(const char *); +int rresvport(int *); +int rresvport_af(int *, int); +int ruserok(const char *, int, const char *, const char *); +int setdomainname(const char *, size_t); +int setgroups(int, const gid_t *); +int sethostid(long); +int sethostname(const char *, size_t); +int setlogin(const char *); +void *setmode(const char *); +int setpgrp(pid_t _pid, pid_t _pgrp); /* BSD compat version */ +int setthrname(pid_t, const char *); +void setusershell(void); +int strtofflags(char **, u_int32_t *, u_int32_t *); +int swapctl(int cmd, const void *arg, int misc); +int pledge(const char *, const char *); +int unveil(const char *, const char *); +pid_t __tfork_thread(const struct __tfork *, size_t, void (*)(void *), + void *); +#endif /* __BSD_VISIBLE */ +__END_DECLS + +#endif /* !_UNISTD_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/usbhid.h b/lib/libc/include/generic-openbsd/usbhid.h new file mode 100644 index 0000000000..3fa9afccf0 --- /dev/null +++ b/lib/libc/include/generic-openbsd/usbhid.h @@ -0,0 +1,100 @@ +/* $OpenBSD: usbhid.h,v 1.9 2021/05/30 19:54:52 jcs Exp $ */ +/* $NetBSD: usbhid.h,v 1.1 2001/12/28 17:45:27 augustss Exp $ */ + +/* + * Copyright (c) 1999 Lennart Augustsson + * 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 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 AUTHOR 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. + */ + +typedef struct report_desc *report_desc_t; + +typedef struct hid_data *hid_data_t; + +typedef enum hid_kind { + hid_input, hid_output, hid_feature, hid_collection, hid_endcollection +} hid_kind_t; + +typedef struct hid_item { + /* Global */ + uint32_t _usage_page; + int32_t logical_minimum; + int32_t logical_maximum; + int32_t physical_minimum; + int32_t physical_maximum; + int32_t unit_exponent; + int32_t unit; + int32_t report_size; + int32_t report_ID; +#define NO_REPORT_ID 0 + int32_t report_count; + /* Local */ + uint32_t usage; + int32_t usage_minimum; + int32_t usage_maximum; + int32_t designator_index; + int32_t designator_minimum; + int32_t designator_maximum; + int32_t string_index; + int32_t string_minimum; + int32_t string_maximum; + int32_t set_delimiter; + /* Misc */ + int32_t collection; + int collevel; + enum hid_kind kind; + uint32_t flags; + /* Location */ + uint32_t pos; + /* unused */ + struct hid_item *next; +} hid_item_t; + +#define HID_PAGE(u) (((u) >> 16) & 0xffff) +#define HID_USAGE(u) ((u) & 0xffff) + +/* Obtaining a report descriptor, descr.c: */ +report_desc_t hid_get_report_desc(int file); +report_desc_t hid_use_report_desc(unsigned char *data, unsigned int size); +void hid_dispose_report_desc(report_desc_t); +void hid_get_report_desc_data(report_desc_t, uint8_t **, uint32_t *); + +/* Parsing of a HID report descriptor, parse.c: */ +hid_data_t hid_start_parse(report_desc_t d, int kindset, int id); +void hid_end_parse(hid_data_t s); +int hid_get_item(hid_data_t s, hid_item_t *h); +int hid_report_size(report_desc_t d, enum hid_kind k, int id); +int hid_locate(report_desc_t d, unsigned int usage, enum hid_kind k, + hid_item_t *h, int id); + +/* Conversion to/from usage names, usage.c: */ +const char *hid_usage_page(int i); +const char *hid_usage_in_page(unsigned int u); +void hid_init(const char *file); +int hid_start(const char *file); +int hid_parse_usage_in_page(const char *name); +int hid_parse_usage_page(const char *name); + +/* Extracting/insertion of data, data.c: */ +int32_t hid_get_data(const void *p, const hid_item_t *h); +void hid_set_data(void *p, const hid_item_t *h, int32_t data); \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/util.h b/lib/libc/include/generic-openbsd/util.h new file mode 100644 index 0000000000..dc9305f58b --- /dev/null +++ b/lib/libc/include/generic-openbsd/util.h @@ -0,0 +1,129 @@ +/* $OpenBSD: util.h,v 1.38 2022/05/11 17:23:56 millert Exp $ */ +/* $NetBSD: util.h,v 1.2 1996/05/16 07:00:22 thorpej Exp $ */ + +/*- + * Copyright (c) 1995 + * The Regents of the University of California. All rights reserved. + * Portions Copyright (c) 1996, Jason Downs. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _UTIL_H_ +#define _UTIL_H_ + +#include + +/* + * fparseln() specific operation flags. + */ +#define FPARSELN_UNESCESC 0x01 +#define FPARSELN_UNESCCONT 0x02 +#define FPARSELN_UNESCCOMM 0x04 +#define FPARSELN_UNESCREST 0x08 +#define FPARSELN_UNESCALL 0x0f + +/* + * opendev() specific operation flags. + */ +#define OPENDEV_PART 0x01 /* Try to open the raw partition. */ +#define OPENDEV_BLCK 0x04 /* Open block, not character device. */ + +/* + * uu_lock(3) specific flags. + */ +#define UU_LOCK_INUSE (1) +#define UU_LOCK_OK (0) +#define UU_LOCK_OPEN_ERR (-1) +#define UU_LOCK_READ_ERR (-2) +#define UU_LOCK_CREAT_ERR (-3) +#define UU_LOCK_WRITE_ERR (-4) +#define UU_LOCK_LINK_ERR (-5) +#define UU_LOCK_TRY_ERR (-6) +#define UU_LOCK_OWNER_ERR (-7) + +/* + * fmt_scaled(3) specific flags. + */ +#define FMT_SCALED_STRSIZE 7 /* minus sign, 4 digits, suffix, null byte */ + +/* + * stub struct definitions. + */ +struct __sFILE; +struct login_cap; +struct passwd; +struct termios; +struct utmp; +struct winsize; + +__BEGIN_DECLS +char *fparseln(struct __sFILE *, size_t *, size_t *, const char[3], int); +void login(struct utmp *); +int login_tty(int); +int logout(const char *); +void logwtmp(const char *, const char *, const char *); +int opendev(const char *, int, int, char **); +int pidfile(const char *); +void pw_setdir(const char *); +char *pw_file(const char *); +int pw_lock(int); +int pw_mkdb(char *, int); +int pw_abort(void); +void pw_init(void); +void pw_edit(int, const char *); +void pw_prompt(void); +void pw_copy(int, int, const struct passwd *, const struct passwd *); +int pw_scan(char *, struct passwd *, int *); +__dead void pw_error(const char *, int, int); +int getptmfd(void); +int openpty(int *, int *, char *, const struct termios *, + const struct winsize *); +int fdopenpty(int, int *, int *, char *, const struct termios *, + const struct winsize *); +int opendisk(const char *, int, char *, size_t, int); +pid_t forkpty(int *, char *, const struct termios *, const struct winsize *); +pid_t fdforkpty(int, int *, char *, const struct termios *, + const struct winsize *); +int getmaxpartitions(void); +int getrawpartition(void); +void login_fbtab(const char *, uid_t, gid_t); +int login_check_expire(struct __sFILE *, struct passwd *, char *, int); +char *readlabelfs(char *, int); +const char *uu_lockerr(int); +int uu_lock(const char *); +int uu_lock_txfr(const char *, pid_t); +int uu_unlock(const char *); +int fmt_scaled(long long, char *); +int scan_scaled(char *, long long *); +int isduid(const char *, int); +int pkcs5_pbkdf2(const char *, size_t, const uint8_t *, size_t, + uint8_t *, size_t, unsigned int); +int bcrypt_pbkdf(const char *, size_t, const uint8_t *, size_t, + uint8_t *, size_t, unsigned int); + +__END_DECLS + +#endif /* !_UTIL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/utime.h b/lib/libc/include/generic-openbsd/utime.h new file mode 100644 index 0000000000..3132ff9bc1 --- /dev/null +++ b/lib/libc/include/generic-openbsd/utime.h @@ -0,0 +1,55 @@ +/* $OpenBSD: utime.h,v 1.7 2013/04/02 05:16:14 guenther Exp $ */ +/* $NetBSD: utime.h,v 1.3 1994/10/26 00:56:39 cgd Exp $ */ + +/*- + * Copyright (c) 1990 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. + * + * @(#)utime.h 5.4 (Berkeley) 4/3/91 + */ + +#ifndef _UTIME_H_ +#define _UTIME_H_ + +#include +#include + +#ifndef _TIME_T_DEFINED_ +#define _TIME_T_DEFINED_ +typedef __time_t time_t; +#endif + +struct utimbuf { + time_t actime; /* Access time */ + time_t modtime; /* Modification time */ +}; + +__BEGIN_DECLS +int utime(const char *, const struct utimbuf *); +__END_DECLS + +#endif /* !_UTIME_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/utmp.h b/lib/libc/include/generic-openbsd/utmp.h new file mode 100644 index 0000000000..f4f6a761be --- /dev/null +++ b/lib/libc/include/generic-openbsd/utmp.h @@ -0,0 +1,69 @@ +/* $OpenBSD: utmp.h,v 1.6 2014/01/08 06:50:57 guenther Exp $ */ +/* $NetBSD: utmp.h,v 1.6 1994/10/26 00:56:40 cgd Exp $ */ + +/* + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * 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. + * + * @(#)utmp.h 8.2 (Berkeley) 1/21/94 + */ + +#ifndef _UTMP_H_ +#define _UTMP_H_ + +#define _PATH_UTMP "/var/run/utmp" +#define _PATH_WTMP "/var/log/wtmp" +#define _PATH_LASTLOG "/var/log/lastlog" + +#define UT_NAMESIZE 32 +#define UT_LINESIZE 8 +#define UT_HOSTSIZE 256 + +/* + * Note that these are *not* C strings and thus are not + * guaranteed to be NUL-terminated. + */ + +struct lastlog { + time_t ll_time; + char ll_line[UT_LINESIZE]; + char ll_host[UT_HOSTSIZE]; +}; + +struct utmp { + char ut_line[UT_LINESIZE]; + char ut_name[UT_NAMESIZE]; + char ut_host[UT_HOSTSIZE]; + time_t ut_time; +}; + +#endif /* !_UTMP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/uuid.h b/lib/libc/include/generic-openbsd/uuid.h new file mode 100644 index 0000000000..e0e0152d05 --- /dev/null +++ b/lib/libc/include/generic-openbsd/uuid.h @@ -0,0 +1,69 @@ +/* $OpenBSD: uuid.h,v 1.1 2014/08/31 09:36:36 miod Exp $ */ +/* $NetBSD: uuid.h,v 1.2 2008/04/23 07:52:32 plunky Exp $ */ + +/* + * Copyright (c) 2002 Marcel Moolenaar + * Copyright (c) 2002 Hiten Mahesh Pandya + * 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 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 AUTHOR 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. + * + * $FreeBSD: src/include/uuid.h,v 1.2 2002/11/05 10:55:16 jmallett Exp $ + */ + +#ifndef _UUID_H_ +#define _UUID_H_ + +#include +#include + +/* Status codes returned by the functions. */ +#define uuid_s_ok 0 +#define uuid_s_bad_version 1 +#define uuid_s_invalid_string_uuid 2 +#define uuid_s_no_memory 3 + +/* Length of a printed UUID. */ +#define UUID_BUF_LEN _UUID_BUF_LEN + +/* Length of a UUID. */ +#define UUID_STR_LEN 36 + +#include + +__BEGIN_DECLS +int32_t uuid_compare(const uuid_t *, const uuid_t *, uint32_t *); +void uuid_create(uuid_t *, uint32_t *); +void uuid_create_nil(uuid_t *, uint32_t *); +int32_t uuid_equal(const uuid_t *, const uuid_t *, uint32_t *); +void uuid_from_string(const char *, uuid_t *, uint32_t *); +uint16_t uuid_hash(const uuid_t *, uint32_t *); +int32_t uuid_is_nil(const uuid_t *, uint32_t *); +void uuid_to_string(const uuid_t *, char **, uint32_t *); + +void uuid_enc_le(void *, const uuid_t *); +void uuid_dec_le(const void *, uuid_t *); +void uuid_enc_be(void *, const uuid_t *); +void uuid_dec_be(const void *, uuid_t *); +__END_DECLS + +#endif /* _UUID_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/uvm/uvm.h b/lib/libc/include/generic-openbsd/uvm/uvm.h new file mode 100644 index 0000000000..e66f26f12b --- /dev/null +++ b/lib/libc/include/generic-openbsd/uvm/uvm.h @@ -0,0 +1,143 @@ +/* $OpenBSD: uvm.h,v 1.73 2024/04/02 08:39:17 deraadt Exp $ */ +/* $NetBSD: uvm.h,v 1.24 2000/11/27 08:40:02 chs Exp $ */ + +/* + * Copyright (c) 1997 Charles D. Cranor and Washington University. + * 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. + * + * from: Id: uvm.h,v 1.1.2.14 1998/02/02 20:07:19 chuck Exp + */ + +#ifndef _UVM_UVM_H_ +#define _UVM_UVM_H_ + +#include +#include +#include +#include +#include +#include +#include + +#include + +/* + * uvm structure (vm global state: collected in one structure for ease + * of reference...) + * + * Locks used to protect struct members in this file: + * Q uvm.pageqlock + * F uvm.fpageqlock + */ +struct uvm { + /* vm_page related parameters */ + + /* vm_page queues */ + struct pglist page_active; /* [Q] allocated pages, in use */ + struct pglist page_inactive; /* [Q] pages inactive (reclaim/free) */ + /* Lock order: pageqlock, then fpageqlock. */ + struct mutex pageqlock; /* [] lock for active/inactive page q */ + struct mutex fpageqlock; /* [] lock for free page q + pdaemon */ + boolean_t page_init_done; /* TRUE if uvm_page_init() finished */ + struct uvm_pmr_control pmr_control; /* [F] pmemrange data */ + + /* page daemon trigger */ + int pagedaemon; /* daemon sleeps on this */ + struct proc *pagedaemon_proc; /* daemon's pid */ + + /* aiodone daemon trigger */ + int aiodoned; /* daemon sleeps on this */ + struct proc *aiodoned_proc; /* daemon's pid */ + struct mutex aiodoned_lock; + + /* static kernel map entry pool */ + SLIST_HEAD(, vm_map_entry) kentry_free; /* free page pool */ + + /* aio_done is locked by uvm.aiodoned_lock. */ + TAILQ_HEAD(, buf) aio_done; /* done async i/o reqs */ + + /* kernel object: to support anonymous pageable kernel memory */ + struct uvm_object *kernel_object; +}; + +/* + * vm_map_entry etype bits: + */ +#define UVM_ET_OBJ 0x0001 /* it is a uvm_object */ +#define UVM_ET_SUBMAP 0x0002 /* it is a vm_map submap */ +#define UVM_ET_COPYONWRITE 0x0004 /* copy_on_write */ +#define UVM_ET_NEEDSCOPY 0x0008 /* needs_copy */ +#define UVM_ET_HOLE 0x0010 /* no backend */ +#define UVM_ET_NOFAULT 0x0020 /* don't fault */ +#define UVM_ET_STACK 0x0040 /* this is a stack */ +#define UVM_ET_WC 0x0080 /* write combining */ +#define UVM_ET_CONCEAL 0x0100 /* omit from dumps */ +#define UVM_ET_IMMUTABLE 0x0400 /* entry may not be changed */ +#define UVM_ET_FREEMAPPED 0x8000 /* map entry is on free list (DEBUG) */ + +#define UVM_ET_ISOBJ(E) (((E)->etype & UVM_ET_OBJ) != 0) +#define UVM_ET_ISSUBMAP(E) (((E)->etype & UVM_ET_SUBMAP) != 0) +#define UVM_ET_ISCOPYONWRITE(E) (((E)->etype & UVM_ET_COPYONWRITE) != 0) +#define UVM_ET_ISNEEDSCOPY(E) (((E)->etype & UVM_ET_NEEDSCOPY) != 0) +#define UVM_ET_ISHOLE(E) (((E)->etype & UVM_ET_HOLE) != 0) +#define UVM_ET_ISNOFAULT(E) (((E)->etype & UVM_ET_NOFAULT) != 0) +#define UVM_ET_ISSTACK(E) (((E)->etype & UVM_ET_STACK) != 0) +#define UVM_ET_ISWC(E) (((E)->etype & UVM_ET_WC) != 0) +#define UVM_ET_ISCONCEAL(E) (((E)->etype & UVM_ET_CONCEAL) != 0) + +#ifdef _KERNEL + +/* + * holds all the internal UVM data + */ +extern struct uvm uvm; + +/* + * UVM_PAGE_OWN: track page ownership (only if UVM_PAGE_TRKOWN) + */ + +#if defined(UVM_PAGE_TRKOWN) +#define UVM_PAGE_OWN(PG, TAG) uvm_page_own(PG, TAG) +#else +#define UVM_PAGE_OWN(PG, TAG) /* nothing */ +#endif /* UVM_PAGE_TRKOWN */ + +/* + * uvm_map internal functions. + * Used by uvm_map address selectors. + */ +struct vm_map_entry *uvm_map_entrybyaddr(struct uvm_map_addr *, vaddr_t); +int uvm_map_isavail(struct vm_map *, + struct uvm_addr_state *, + struct vm_map_entry **, struct vm_map_entry**, + vaddr_t, vsize_t); +struct uvm_addr_state *uvm_map_uaddr(struct vm_map *, vaddr_t); +struct uvm_addr_state *uvm_map_uaddr_e(struct vm_map *, struct vm_map_entry *); + +#define VMMAP_FREE_START(_entry) ((_entry)->end + (_entry)->guard) +#define VMMAP_FREE_END(_entry) ((_entry)->end + (_entry)->guard + \ + (_entry)->fspace) + +#endif /* _KERNEL */ + +#endif /* _UVM_UVM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/uvm/uvm_addr.h b/lib/libc/include/generic-openbsd/uvm/uvm_addr.h new file mode 100644 index 0000000000..c4191bed51 --- /dev/null +++ b/lib/libc/include/generic-openbsd/uvm/uvm_addr.h @@ -0,0 +1,115 @@ +/* $OpenBSD: uvm_addr.h,v 1.8 2024/07/04 04:52:10 jsg Exp $ */ + +/* + * Copyright (c) 2011 Ariane van der Steldt + * + * 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 _UVM_UVM_ADDR_H_ +#define _UVM_UVM_ADDR_H_ + +/* + * Address selection logic. + * + * Address selection is just that: selection. These functions may make no + * changes to the map, except for their own state (which is passed as a + * uaddr_state pointer). + */ + + +/* + * UVM address selection base state. + * + * Each uvm address algorithm requires these parameters: + * - lower bound address (page aligned) + * - upper bound address (page aligned) + * - function address pointers + */ +struct uvm_addr_state { + vaddr_t uaddr_minaddr; + vaddr_t uaddr_maxaddr; + const struct uvm_addr_functions *uaddr_functions; +}; + +/* + * This structure describes one algorithm implementation. + * + * Each algorithm is described in terms of: + * - uaddr_select: an address selection algorithm + * - uaddr_free_insert: a freelist insertion function (optional) + * - uaddr_free_remove: a freelist deletion function (optional) + * - uaddr_destroy: a destructor for the algorithm state + */ +struct uvm_addr_functions { + int (*uaddr_select)(struct vm_map *map, + struct uvm_addr_state *uaddr, + struct vm_map_entry **entry_out, vaddr_t *addr_out, + vsize_t sz, vaddr_t align, vaddr_t offset, + vm_prot_t prot, vaddr_t hint); + void (*uaddr_free_insert)(struct vm_map *map, + struct uvm_addr_state *uaddr_state, + struct vm_map_entry *entry); + void (*uaddr_free_remove)(struct vm_map *map, + struct uvm_addr_state *uaddr_state, + struct vm_map_entry *entry); + void (*uaddr_destroy)(struct uvm_addr_state *uaddr_state); + void (*uaddr_print)(struct uvm_addr_state *uaddr_state, boolean_t full, + int (*pr)(const char *, ...)); + + const char* uaddr_name; /* Name of the allocator. */ +}; + + +#ifdef _KERNEL + +void uvm_addr_init(void); +void uvm_addr_destroy(struct uvm_addr_state *); +int uvm_addr_linsearch(struct vm_map *, + struct uvm_addr_state *, struct vm_map_entry **, + vaddr_t *addr_out, vaddr_t, vsize_t, + vaddr_t, vaddr_t, int, vaddr_t, vaddr_t, + vsize_t, vsize_t); +int uvm_addr_invoke(struct vm_map *, + struct uvm_addr_state *, struct vm_map_entry **, + struct vm_map_entry **, vaddr_t*, + vsize_t, vaddr_t, vaddr_t, vm_prot_t, vaddr_t); +#if 0 +struct uvm_addr_state *uaddr_lin_create(vaddr_t, vaddr_t); +#endif +struct uvm_addr_state *uaddr_rnd_create(vaddr_t, vaddr_t); +#ifndef SMALL_KERNEL +struct uvm_addr_state *uaddr_bestfit_create(vaddr_t, vaddr_t); +struct uvm_addr_state *uaddr_pivot_create(vaddr_t, vaddr_t); +struct uvm_addr_state *uaddr_stack_brk_create(vaddr_t, vaddr_t); +#endif /* SMALL_KERNEL */ +int uvm_addr_fitspace(vaddr_t *, vaddr_t *, + vaddr_t, vaddr_t, vsize_t, vaddr_t, vaddr_t, + vsize_t, vsize_t); + +#if defined(DEBUG) || defined(DDB) +void uvm_addr_print(struct uvm_addr_state *, const char *, + boolean_t, int (*pr)(const char *, ...)); +#endif /* DEBUG || DDB */ + +/* + * Kernel bootstrap allocator. + */ +RBT_HEAD(uaddr_free_rbtree, vm_map_entry); +RBT_PROTOTYPE(uaddr_free_rbtree, vm_map_entry, dfree.rbtree, + uvm_mapent_fspace_cmp); + +extern struct uvm_addr_state uaddr_kbootstrap; + +#endif /* _KERNEL */ +#endif /* _UVM_UVM_ADDR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/uvm/uvm_amap.h b/lib/libc/include/generic-openbsd/uvm/uvm_amap.h new file mode 100644 index 0000000000..bf8cb644f5 --- /dev/null +++ b/lib/libc/include/generic-openbsd/uvm/uvm_amap.h @@ -0,0 +1,265 @@ +/* $OpenBSD: uvm_amap.h,v 1.36 2025/05/25 01:52:00 gnezdo Exp $ */ +/* $NetBSD: uvm_amap.h,v 1.14 2001/02/18 21:19:08 chs Exp $ */ + +/* + * Copyright (c) 1997 Charles D. Cranor and Washington University. + * 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 _UVM_UVM_AMAP_H_ +#define _UVM_UVM_AMAP_H_ + +/* + * uvm_amap.h: general amap interface and amap implementation-specific info + */ + +/* + * an amap structure contains pointers to a set of anons that are + * mapped together in virtual memory (an anon is a single page of + * anonymous virtual memory -- see uvm_anon.h). in uvm we hide the + * details of the implementation of amaps behind a general amap + * interface. this allows us to change the amap implementation + * without having to touch the rest of the code. this file is divided + * into two parts: the definition of the uvm amap interface and the + * amap implementation-specific definitions. + */ + +#ifdef _KERNEL + +/* + * part 1: amap interface + */ + +/* + * forward definition of vm_amap structure. only amap + * implementation-specific code should directly access the fields of + * this structure. + */ + +struct vm_amap; + +/* + * prototypes for the amap interface + */ + + /* ensure amap can store anon */ +void amap_populate(struct vm_aref *, vaddr_t); + /* add an anon to an amap */ +int amap_add(struct vm_aref *, vaddr_t, struct vm_anon *, + boolean_t); + /* allocate a new amap */ +struct vm_amap *amap_alloc(vaddr_t, int, int); + /* clear amap needs-copy flag */ +void amap_copy(vm_map_t, vm_map_entry_t, int, boolean_t, vaddr_t, + vaddr_t); + /* resolve all COW faults now */ +void amap_cow_now(vm_map_t, vm_map_entry_t); + /* free amap */ +void amap_free(struct vm_amap *); + /* init amap module (at boot time) */ +void amap_init(void); + /* lookup an anon @ offset in amap */ +struct vm_anon *amap_lookup(struct vm_aref *, vaddr_t); + /* lookup multiple anons */ +void amap_lookups(struct vm_aref *, vaddr_t, struct vm_anon **, int); + /* add a reference to an amap */ +void amap_ref(struct vm_amap *, vaddr_t, vsize_t, int); + /* split reference to amap into two */ +void amap_splitref(struct vm_aref *, struct vm_aref *, vaddr_t); + /* remove an anon from an amap */ +void amap_unadd(struct vm_aref *, vaddr_t); + /* drop reference to an amap */ +void amap_unref(struct vm_amap *, vaddr_t, vsize_t, int); + /* remove all anons from amap */ +void amap_wipeout(struct vm_amap *); +boolean_t amap_swap_off(int, int); + +/* + * amap flag values + */ + +#define AMAP_SHARED 0x1 /* amap is shared */ +#define AMAP_REFALL 0x2 /* amap_ref: reference entire amap */ +#define AMAP_SWAPOFF 0x4 /* amap_swap_off() is in progress */ + +#endif /* _KERNEL */ + +/**********************************************************************/ + +/* + * part 2: amap implementation-specific info + */ + +/* + * we currently provide an array-based amap implementation. in this + * implementation we track split references so that we don't lose track of + * references during partial unmaps. + */ + +/* + * here is the definition of the vm_amap structure and helper structures for + * this implementation. + */ + +struct vm_amap_chunk { + TAILQ_ENTRY(vm_amap_chunk) ac_list; + int ac_baseslot; + uint16_t ac_usedmap; + uint16_t ac_nslot; + struct vm_anon *ac_anon[]; +}; + +struct vm_amap { + struct rwlock *am_lock; /* lock for all vm_amap flags */ + int am_ref; /* reference count */ + int am_flags; /* flags */ + int am_nslot; /* # of slots currently in map */ + int am_nused; /* # of slots currently in use */ + int *am_ppref; /* per page reference count (if !NULL) */ + LIST_ENTRY(vm_amap) am_list; + + union { + struct { + struct vm_amap_chunk **amn_buckets; + TAILQ_HEAD(, vm_amap_chunk) amn_chunks; + int amn_nbuckets; /* # of buckets */ + int amn_ncused; /* # of chunkers currently in use */ + int amn_hashshift; /* shift count to hash slot to bucket */ + } ami_normal; + + /* + * MUST be last element in vm_amap because it contains a + * variably sized array element. + */ + struct vm_amap_chunk ami_small; + } am_impl; + +#define am_buckets am_impl.ami_normal.amn_buckets +#define am_chunks am_impl.ami_normal.amn_chunks +#define am_nbuckets am_impl.ami_normal.amn_nbuckets +#define am_ncused am_impl.ami_normal.amn_ncused +#define am_hashshift am_impl.ami_normal.amn_hashshift + +#define am_small am_impl.ami_small +}; + +/* + * The entries in an amap are called slots. For example an amap that + * covers four pages is said to have four slots. + * + * The slots of an amap are clustered into chunks of UVM_AMAP_CHUNK + * slots each. The data structure of a chunk is vm_amap_chunk. + * Every chunk contains an array of pointers to vm_anon, and a bitmap + * is used to represent which of the slots are in use. + * + * Small amaps of up to UVM_AMAP_CHUNK slots have the chunk directly + * embedded in the amap structure. + * + * amaps with more slots are normal amaps and organize chunks in a hash + * table. The hash table is organized as an array of buckets. + * All chunks of the amap are additionally stored in a linked list. + * Chunks that belong to the same hash bucket are stored in the list + * consecutively. When all slots in a chunk are unused, the chunk is freed. + * + * For large amaps, the bucket array can grow large. See the description + * below how large bucket arrays are avoided. + */ + +/* + * defines for handling of large sparse amaps: + * + * one of the problems of array-based amaps is that if you allocate a + * large sparsely-used area of virtual memory you end up allocating + * large arrays that, for the most part, don't get used. this is a + * problem for BSD in that the kernel likes to make these types of + * allocations to "reserve" memory for possible future use. + * + * for example, the kernel allocates (reserves) a large chunk of user + * VM for possible stack growth. most of the time only a page or two + * of this VM is actually used. since the stack is anonymous memory + * it makes sense for it to live in an amap, but if we allocated an + * amap for the entire stack range we could end up wasting a large + * amount of malloc'd KVM. + * + * for example, on the i386 at boot time we allocate two amaps for the stack + * of /sbin/init: + * 1. a 7680 slot amap at protection PROT_NONE (reserve space for stack) + * 2. a 512 slot amap at protection PROT_READ|PROT_WRITE (top of stack) + * + * most of the array allocated for the amaps for this is never used. + * the amap interface provides a way for us to avoid this problem by + * allowing amap_copy() to break larger amaps up into smaller sized + * chunks (controlled by the "canchunk" option). we use this feature + * to reduce our memory usage with the BSD stack management. if we + * are asked to create an amap with more than UVM_AMAP_LARGE slots in it, + * we attempt to break it up into a UVM_AMAP_CHUNK sized amap if the + * "canchunk" flag is set. + * + * so, in the i386 example, the 7680 slot area is never referenced so + * nothing gets allocated (amap_copy is never called because the protection + * is zero). the 512 slot area for the top of the stack is referenced. + * the chunking code breaks it up into 16 slot chunks (hopefully a single + * 16 slot chunk is enough to handle the whole stack). + */ + +#define UVM_AMAP_LARGE 256 /* # of slots in "large" amap */ +#define UVM_AMAP_CHUNK 16 /* # of slots to chunk large amaps in */ + +#define UVM_AMAP_SMALL(amap) ((amap)->am_nslot <= UVM_AMAP_CHUNK) +#define UVM_AMAP_SLOTIDX(slot) ((slot) % UVM_AMAP_CHUNK) +#define UVM_AMAP_BUCKET(amap, slot) \ + (((slot) / UVM_AMAP_CHUNK) >> (amap)->am_hashshift) + +#ifdef _KERNEL + +/* + * macros + */ + +/* AMAP_B2SLOT: convert byte offset to slot */ +#define AMAP_B2SLOT(S,B) { \ + KASSERT(((B) & (PAGE_SIZE - 1)) == 0); \ + (S) = (B) >> PAGE_SHIFT; \ +} + +#define AMAP_CHUNK_FOREACH(chunk, amap) \ + for (chunk = (UVM_AMAP_SMALL(amap) ? \ + &(amap)->am_small : TAILQ_FIRST(&(amap)->am_chunks)); \ + (chunk) != NULL; (chunk) = TAILQ_NEXT(chunk, ac_list)) + +#define AMAP_BASE_SLOT(slot) \ + (((slot) / UVM_AMAP_CHUNK) * UVM_AMAP_CHUNK) + +/* + * flags macros + */ + +#define amap_flags(AMAP) ((AMAP)->am_flags) +#define amap_refs(AMAP) ((AMAP)->am_ref) + +#define amap_lock(AMAP, RWLT) rw_enter((AMAP)->am_lock, (RWLT)) +#define amap_unlock(AMAP) rw_exit((AMAP)->am_lock) + +#endif /* _KERNEL */ + +#endif /* _UVM_UVM_AMAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/uvm/uvm_anon.h b/lib/libc/include/generic-openbsd/uvm/uvm_anon.h new file mode 100644 index 0000000000..a852f72d72 --- /dev/null +++ b/lib/libc/include/generic-openbsd/uvm/uvm_anon.h @@ -0,0 +1,103 @@ +/* $OpenBSD: uvm_anon.h,v 1.23 2025/04/16 09:16:48 mpi Exp $ */ +/* $NetBSD: uvm_anon.h,v 1.13 2000/12/27 09:17:04 chs Exp $ */ + +/* + * Copyright (c) 1997 Charles D. Cranor and Washington University. + * 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 _UVM_UVM_ANON_H_ +#define _UVM_UVM_ANON_H_ + +/* + * anonymous memory management + * + * anonymous virtual memory is short term virtual memory that goes away + * when the processes referencing it go away. an anonymous page of + * virtual memory is described by the following data structure: + */ + +struct vm_anon { + struct rwlock *an_lock; + + struct vm_page *an_page; /* if in RAM */ + int an_ref; /* reference count */ + + /* + * Drum swap slot # (if != 0) [if we hold an_page, PG_BUSY] + */ + int an_swslot; + +#if defined(MULTIPROCESSOR) && defined(__LP64__) + /* + * The per-CPU pool caching code requires pool item to be + * at least the size of struct pool_cache_item. + */ + long unused; +#endif +}; + +/* + * for active vm_anon's the data can be in one of the following state: + * [1] in a vm_page with no backing store allocated yet, [2] in a vm_page + * with backing store allocated, or [3] paged out to backing store + * (no vm_page). + * + * for pageout in case [2]: if the page has been modified then we must + * flush it out to backing store, otherwise we can just dump the + * vm_page. + */ + +/* + * anons are grouped together in anonymous memory maps, or amaps. + * amaps are defined in uvm_amap.h. + */ + +/* + * processes reference anonymous virtual memory maps with an anonymous + * reference structure: + * Note that the offset field indicates which part of the amap we are + * referencing. + * Locked by vm_map lock. + */ + +struct vm_aref { + int ar_pageoff; /* page offset into amap we start */ + struct vm_amap *ar_amap; /* pointer to amap */ +}; + +#ifdef _KERNEL +struct vm_anon *uvm_analloc(void); +void uvm_anfree_list(struct vm_anon *, struct pglist *); +void uvm_anon_release(struct vm_anon *); +void uvm_anwait(void); +void uvm_anon_init(void); +void uvm_anon_init_percpu(void); +void uvm_anon_dropswap(struct vm_anon *); +boolean_t uvm_anon_pagein(struct vm_amap *, struct vm_anon *); + +#define uvm_anfree(an) uvm_anfree_list((an), NULL) + +#endif /* _KERNEL */ + +#endif /* _UVM_UVM_ANON_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/uvm/uvm_aobj.h b/lib/libc/include/generic-openbsd/uvm/uvm_aobj.h new file mode 100644 index 0000000000..1fc48ca548 --- /dev/null +++ b/lib/libc/include/generic-openbsd/uvm/uvm_aobj.h @@ -0,0 +1,77 @@ +/* $OpenBSD: uvm_aobj.h,v 1.20 2023/05/13 09:24:59 mpi Exp $ */ +/* $NetBSD: uvm_aobj.h,v 1.10 2000/01/11 06:57:49 chs Exp $ */ + +/* + * Copyright (c) 1998 Chuck Silvers, Charles D. Cranor and + * Washington University. + * 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. + * + * from: Id: uvm_aobj.h,v 1.1.2.4 1998/02/06 05:19:28 chs Exp + */ +/* + * uvm_aobj.h: anonymous memory uvm_object pager + * + * author: Chuck Silvers + * started: Jan-1998 + * + * - design mostly from Chuck Cranor + */ + +#ifndef _UVM_UVM_AOBJ_H_ +#define _UVM_UVM_AOBJ_H_ + +/* + * flags + */ + +/* flags for uao_create: can only be used one time (at bootup) */ +#define UAO_FLAG_KERNOBJ 0x1 /* create kernel object */ +#define UAO_FLAG_KERNSWAP 0x2 /* enable kernel swap */ +#define UAO_FLAG_CANFAIL 0x4 /* creation can fail */ + +/* internal flags */ +#define UAO_FLAG_NOSWAP 0x8 /* aobj can't swap (kernel obj only!) */ + +#ifdef _KERNEL + +/* + * prototypes + */ + +void uao_init(void); +int uao_set_swslot(struct uvm_object *, int, int); +int uao_find_swslot(struct uvm_object *, int); +int uao_dropswap(struct uvm_object *, int); +int uao_swap_off(int, int); +int uao_shrink(struct uvm_object *, int); +int uao_grow(struct uvm_object *, int); + +/* + * globals + */ + +extern const struct uvm_pagerops aobj_pager; + +#endif /* _KERNEL */ + +#endif /* _UVM_UVM_AOBJ_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/uvm/uvm_ddb.h b/lib/libc/include/generic-openbsd/uvm/uvm_ddb.h new file mode 100644 index 0000000000..e8b85f4ed8 --- /dev/null +++ b/lib/libc/include/generic-openbsd/uvm/uvm_ddb.h @@ -0,0 +1,46 @@ +/* $OpenBSD: uvm_ddb.h,v 1.14 2015/02/05 23:51:06 mpi Exp $ */ +/* $NetBSD: uvm_ddb.h,v 1.5 2000/11/25 06:27:59 chs Exp $ */ + +/* + * Copyright (c) 1997 Charles D. Cranor and Washington University. + * 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 _UVM_UVM_DDB_H_ +#define _UVM_UVM_DDB_H_ + +#ifdef _KERNEL + +#ifdef DDB +void uvm_map_printit(vm_map_t, boolean_t, + int (*)(const char *, ...)); +void uvm_object_printit(struct uvm_object *, boolean_t, + int (*)(const char *, ...)); +void uvm_page_printit(struct vm_page *, boolean_t, + int (*)(const char *, ...)); +void uvmexp_print(int (*)(const char *, ...)); +#endif /* DDB */ + +#endif /* _KERNEL */ + +#endif /* _UVM_UVM_DDB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/uvm/uvm_device.h b/lib/libc/include/generic-openbsd/uvm/uvm_device.h new file mode 100644 index 0000000000..677d411eed --- /dev/null +++ b/lib/libc/include/generic-openbsd/uvm/uvm_device.h @@ -0,0 +1,71 @@ +/* $OpenBSD: uvm_device.h,v 1.11 2014/07/11 16:35:40 jsg Exp $ */ +/* $NetBSD: uvm_device.h,v 1.9 2000/05/28 10:21:55 drochner Exp $ */ + +/* + * Copyright (c) 1997 Charles D. Cranor and Washington University. + * 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. + * + * from: Id: uvm_device.h,v 1.1.2.2 1997/10/03 17:39:44 chuck Exp + */ + +#ifndef _UVM_UVM_DEVICE_H_ +#define _UVM_UVM_DEVICE_H_ + +/* + * uvm_device.h + * + * device handle into the VM system. + */ + +/* + * the uvm_device structure. object is put at the top of the data structure. + * this allows: + * (struct uvm_device *) == (struct uvm_object *) + */ + +struct uvm_device { + struct uvm_object u_obj; /* the actual VM object */ + int u_flags; /* flags [LOCKED BY UDV_LOCK!] */ + dev_t u_device; /* our device */ + LIST_ENTRY(uvm_device) u_list; /* list of device objects */ +}; + +/* + * u_flags values + */ + +#define UVM_DEVICE_HOLD 0x1 /* someone has a "hold" on it */ +#define UVM_DEVICE_WANTED 0x2 /* someone wants to put a "hold" on */ + +#ifdef _KERNEL + +/* + * prototypes + */ + +struct uvm_object *udv_attach(dev_t, vm_prot_t, voff_t, vsize_t); +struct uvm_object *udv_attach_drm(dev_t, vm_prot_t, voff_t, vsize_t); + +#endif /* _KERNEL */ + +#endif /* _UVM_UVM_DEVICE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/uvm/uvm_extern.h b/lib/libc/include/generic-openbsd/uvm/uvm_extern.h new file mode 100644 index 0000000000..f3575f0bfc --- /dev/null +++ b/lib/libc/include/generic-openbsd/uvm/uvm_extern.h @@ -0,0 +1,456 @@ +/* $OpenBSD: uvm_extern.h,v 1.184 2025/06/03 08:38:17 mpi Exp $ */ +/* $NetBSD: uvm_extern.h,v 1.57 2001/03/09 01:02:12 chs Exp $ */ + +/* + * Copyright (c) 1997 Charles D. Cranor and Washington University. + * 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. + */ + +/*- + * Copyright (c) 1991, 1992, 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. + * + * @(#)vm_extern.h 8.5 (Berkeley) 5/3/95 + */ + +#ifndef _UVM_UVM_EXTERN_H_ +#define _UVM_UVM_EXTERN_H_ + +typedef int vm_fault_t; + +typedef int vm_inherit_t; /* XXX: inheritance codes */ +typedef off_t voff_t; /* XXX: offset within a uvm_object */ + +struct vm_map_entry; +typedef struct vm_map_entry *vm_map_entry_t; + +struct vm_map; +typedef struct vm_map *vm_map_t; + +struct vm_page; +typedef struct vm_page *vm_page_t; + +/* + * Bit assignments assigned by UVM_MAPFLAG() and extracted by + * UVM_{PROTECTION,INHERIT,MAXPROTECTION,ADVICE}(): + * bits 0-2 protection + * bit 3 unused + * bits 4-5 inheritance + * bits 6-7 unused + * bits 8-10 max protection + * bit 11 unused + * bits 12-14 advice + * bit 15 unused + * bits 16-N flags + */ + +/* protections bits */ +#define PROT_MASK (PROT_READ | PROT_WRITE | PROT_EXEC) + +/* inherit codes */ +#define MAP_INHERIT_MASK 0x3 /* inherit mask */ + +typedef int vm_prot_t; + +#define MADV_MASK 0x7 /* mask */ + +/* mapping flags */ +#define UVM_FLAG_FIXED 0x0010000 /* find space */ +#define UVM_FLAG_OVERLAY 0x0020000 /* establish overlay */ +#define UVM_FLAG_NOMERGE 0x0040000 /* don't merge map entries */ +#define UVM_FLAG_COPYONW 0x0080000 /* set copy_on_write flag */ +#define UVM_FLAG_TRYLOCK 0x0100000 /* fail if we can not lock map */ +#define UVM_FLAG_HOLE 0x0200000 /* no backend */ +#define UVM_FLAG_QUERY 0x0400000 /* do everything, except actual execution */ +#define UVM_FLAG_NOFAULT 0x0800000 /* don't fault */ +#define UVM_FLAG_UNMAP 0x1000000 /* unmap to make space */ +#define UVM_FLAG_STACK 0x2000000 /* page may contain a stack */ +#define UVM_FLAG_WC 0x4000000 /* write combining */ +#define UVM_FLAG_CONCEAL 0x8000000 /* omit from dumps */ +#define UVM_FLAG_SIGALTSTACK 0x20000000 /* sigaltstack validation required */ + +/* macros to extract info */ +#define UVM_PROTECTION(X) ((X) & PROT_MASK) +#define UVM_INHERIT(X) (((X) >> 4) & MAP_INHERIT_MASK) +#define UVM_MAXPROTECTION(X) (((X) >> 8) & PROT_MASK) +#define UVM_ADVICE(X) (((X) >> 12) & MADV_MASK) + +#define UVM_MAPFLAG(prot, maxprot, inh, advice, flags) \ + ((prot) | ((maxprot) << 8) | ((inh) << 4) | ((advice) << 12) | (flags)) + +/* magic offset value */ +#define UVM_UNKNOWN_OFFSET ((voff_t) -1) + /* offset not known(obj) or don't care(!obj) */ + +/* + * the following defines are for uvm_km_kmemalloc's flags + */ +#define UVM_KMF_NOWAIT 0x1 /* matches M_NOWAIT */ +#define UVM_KMF_VALLOC 0x2 /* allocate VA only */ +#define UVM_KMF_CANFAIL 0x4 /* caller handles failure */ +#define UVM_KMF_ZERO 0x08 /* zero pages */ +#define UVM_KMF_TRYLOCK UVM_FLAG_TRYLOCK /* try locking only */ + +/* + * flags for uvm_pagealloc() + */ +#define UVM_PGA_USERESERVE 0x0001 /* ok to use reserve pages */ +#define UVM_PGA_ZERO 0x0002 /* returned page must be zeroed */ + +/* + * flags for uvm_pglistalloc() also used by uvm_pmr_getpages() + */ +#define UVM_PLA_WAITOK 0x0001 /* may sleep */ +#define UVM_PLA_NOWAIT 0x0002 /* can't sleep (need one of the two) */ +#define UVM_PLA_ZERO 0x0004 /* zero all pages before returning */ +#define UVM_PLA_TRYCONTIG 0x0008 /* try to allocate contig physmem */ +#define UVM_PLA_FAILOK 0x0010 /* caller can handle failure */ +#define UVM_PLA_NOWAKE 0x0020 /* don't wake page daemon on failure */ +#define UVM_PLA_USERESERVE 0x0040 /* can allocate from kernel reserve */ + +/* + * lockflags that control the locking behavior of various functions. + */ +#define UVM_LK_ENTER 0x00000001 /* map locked on entry */ +#define UVM_LK_EXIT 0x00000002 /* leave map locked on exit */ + +/* + * flags to uvm_page_physload. + */ +#define PHYSLOAD_DEVICE 0x01 /* don't add to the page queue */ + +#include +#include +#include + +#ifdef _KERNEL +struct buf; +struct pglist; +struct vmspace; +struct pmap; +#endif + +#include + +#include +#include +#include +#include + +#ifdef _KERNEL +#include +#include +#endif + +/* + * Shareable process virtual address space. + * May eventually be merged with vm_map. + * Several fields are temporary (text, data stuff). + * + * Locks used to protect struct members in this file: + * K kernel lock + * I immutable after creation + * a atomic operations + * v vm_map's lock + */ +struct vmspace { + struct vm_map vm_map; /* VM address map */ + int vm_refcnt; /* [a] number of references */ + caddr_t vm_shm; /* SYS5 shared memory private data XXX */ +/* we copy from vm_startcopy to the end of the structure on fork */ +#define vm_startcopy vm_rssize + segsz_t vm_rssize; /* current resident set size in pages */ + segsz_t vm_swrss; /* resident set size before last swap */ + segsz_t vm_tsize; /* text size (pages) XXX */ + segsz_t vm_dsize; /* data size (pages) XXX */ + segsz_t vm_dused; /* data segment length (pages) XXX */ + segsz_t vm_ssize; /* [v] stack size (pages) */ + caddr_t vm_taddr; /* [I] user virtual address of text */ + caddr_t vm_daddr; /* [I] user virtual address of data */ + caddr_t vm_maxsaddr; /* [I] user VA at max stack growth */ + caddr_t vm_minsaddr; /* [I] user VA at top of stack */ +}; + +/* + * uvm_constraint_range's: + * MD code is allowed to setup constraint ranges for memory allocators, the + * primary use for this is to keep allocation for certain memory consumers + * such as mbuf pools within address ranges that are reachable by devices + * that perform DMA. + * + * It is also to discourage memory allocations from being satisfied from ranges + * such as the ISA memory range, if they can be satisfied with allocation + * from other ranges. + * + * the MD ranges are defined in arch/ARCH/ARCH/machdep.c + */ +struct uvm_constraint_range { + paddr_t ucr_low; + paddr_t ucr_high; +}; + +#ifdef _KERNEL + +#include +extern struct uvmexp uvmexp; + +/* Constraint ranges, set by MD code. */ +extern struct uvm_constraint_range isa_constraint; +extern struct uvm_constraint_range dma_constraint; +extern struct uvm_constraint_range no_constraint; +extern struct uvm_constraint_range *uvm_md_constraints[]; + +/* + * the various kernel maps, owned by MD code + */ +extern struct vm_map *exec_map; +extern struct vm_map *kernel_map; +extern struct vm_map *kmem_map; +extern struct vm_map *phys_map; + +/* base of kernel virtual memory */ +extern vaddr_t vm_min_kernel_address; + +#define vm_resident_count(vm) (pmap_resident_count((vm)->vm_map.pmap)) + +struct plimit; + +void vmapbuf(struct buf *, vsize_t); +void vunmapbuf(struct buf *, vsize_t); +struct uvm_object *uao_create(vsize_t, int); +void uao_detach(struct uvm_object *); +void uao_reference(struct uvm_object *); +int uvm_fault(vm_map_t, vaddr_t, vm_fault_t, vm_prot_t); + +vaddr_t uvm_uarea_alloc(void); +void uvm_uarea_free(struct proc *); +void uvm_purge(void); +void uvm_exit(struct process *); +void uvm_init_limits(struct plimit *); +boolean_t uvm_kernacc(caddr_t, size_t, int); + +int uvm_vslock(struct proc *, caddr_t, size_t, + vm_prot_t); +void uvm_vsunlock(struct proc *, caddr_t, size_t); +int uvm_vslock_device(struct proc *, void *, size_t, + vm_prot_t, void **); +void uvm_vsunlock_device(struct proc *, void *, size_t, + void *); +void uvm_init(void); +void uvm_init_percpu(void); +int uvm_io(vm_map_t, struct uio *, int); + +#define UVM_IO_FIXPROT 0x01 + +void uvm_km_free(vm_map_t, vaddr_t, vsize_t); +vaddr_t uvm_km_kmemalloc_pla(struct vm_map *, + struct uvm_object *, vsize_t, vsize_t, int, + paddr_t, paddr_t, paddr_t, paddr_t, int); +#define uvm_km_kmemalloc(map, obj, sz, flags) \ + uvm_km_kmemalloc_pla(map, obj, sz, 0, flags, 0, (paddr_t)-1, 0, 0, 0) +struct vm_map *uvm_km_suballoc(vm_map_t, vaddr_t *, vaddr_t *, + vsize_t, int, boolean_t, vm_map_t); +/* + * Allocation mode for virtual space. + * + * kv_map - pointer to the pointer to the map we're allocating from. + * kv_align - alignment. + * kv_wait - wait for free space in the map if it's full. The default + * allocators don't wait since running out of space in kernel_map and + * kmem_map is usually fatal. Special maps like exec_map are specifically + * limited, so waiting for space in them is necessary. + * kv_singlepage - use the single page allocator. + * kv_executable - map the physical pages with PROT_EXEC. + */ +struct kmem_va_mode { + struct vm_map **kv_map; + vsize_t kv_align; + char kv_wait; + char kv_singlepage; +}; + +/* + * Allocation mode for physical pages. + * + * kp_constraint - allocation constraint for physical pages. + * kp_object - if the pages should be allocated from an object. + * kp_align - physical alignment of the first page in the allocation. + * kp_boundary - boundary that the physical addresses can't cross if + * the allocation is contiguous. + * kp_nomem - don't allocate any backing pages. + * kp_maxseg - maximal amount of contiguous segments. + * kp_zero - zero the returned memory. + * kp_pageable - allocate pageable memory. + */ +struct kmem_pa_mode { + struct uvm_constraint_range *kp_constraint; + struct uvm_object **kp_object; + paddr_t kp_align; + paddr_t kp_boundary; + int kp_maxseg; + char kp_nomem; + char kp_zero; + char kp_pageable; +}; + +/* + * Dynamic allocation parameters. Stuff that changes too often or too much + * to create separate va and pa modes for. + * + * kd_waitok - is it ok to sleep? + * kd_trylock - don't sleep on map locks. + * kd_prefer - offset to feed to PMAP_PREFER + * kd_slowdown - special parameter for the singlepage va allocator + * that tells the caller to sleep if possible to let the singlepage + * allocator catch up. + */ +struct kmem_dyn_mode { + voff_t kd_prefer; + int *kd_slowdown; + char kd_waitok; + char kd_trylock; +}; + +#define KMEM_DYN_INITIALIZER { UVM_UNKNOWN_OFFSET, NULL, 0, 0 } + +/* + * Notice that for kv_ waiting has a different meaning. It's only supposed + * to be used for very space constrained maps where waiting is a way + * to throttle some other operation. + * The exception is kv_page which needs to wait relatively often. + * All kv_ except kv_intrsafe will potentially sleep. + */ +extern const struct kmem_va_mode kv_any; +extern const struct kmem_va_mode kv_intrsafe; +extern const struct kmem_va_mode kv_page; + +extern const struct kmem_pa_mode kp_dirty; +extern const struct kmem_pa_mode kp_zero; +extern const struct kmem_pa_mode kp_dma; +extern const struct kmem_pa_mode kp_dma_contig; +extern const struct kmem_pa_mode kp_dma_zero; +extern const struct kmem_pa_mode kp_pageable; +extern const struct kmem_pa_mode kp_none; + +extern const struct kmem_dyn_mode kd_waitok; +extern const struct kmem_dyn_mode kd_nowait; +extern const struct kmem_dyn_mode kd_trylock; + +void *km_alloc(size_t, const struct kmem_va_mode *, + const struct kmem_pa_mode *, + const struct kmem_dyn_mode *); +void km_free(void *, size_t, const struct kmem_va_mode *, + const struct kmem_pa_mode *); +int uvm_map(vm_map_t, vaddr_t *, vsize_t, + struct uvm_object *, voff_t, vsize_t, unsigned int); +int uvm_mapanon(vm_map_t, vaddr_t *, vsize_t, vsize_t, unsigned int); +int uvm_map_pageable(vm_map_t, vaddr_t, + vaddr_t, boolean_t, int); +int uvm_map_pageable_all(vm_map_t, int, vsize_t); +boolean_t uvm_map_checkprot(vm_map_t, vaddr_t, + vaddr_t, vm_prot_t); +int uvm_map_protect(vm_map_t, vaddr_t, + vaddr_t, vm_prot_t, int etype, boolean_t, boolean_t); +struct vmspace *uvmspace_alloc(vaddr_t, vaddr_t, + boolean_t, boolean_t); +void uvmspace_init(struct vmspace *, struct pmap *, + vaddr_t, vaddr_t, boolean_t, boolean_t); +void uvmspace_exec(struct proc *, vaddr_t, vaddr_t); +struct vmspace *uvmspace_fork(struct process *); +void uvmspace_addref(struct vmspace *); +void uvmspace_purge(struct vmspace *); +void uvmspace_free(struct vmspace *); +struct vmspace *uvmspace_share(struct process *); +int uvm_sysctl(int *, u_int, void *, size_t *, + void *, size_t, struct proc *); +struct vm_page *uvm_pagealloc(struct uvm_object *, + voff_t, struct vm_anon *, int); +int uvm_pagealloc_multi(struct uvm_object *, voff_t, + vsize_t, int); +void uvm_pagerealloc(struct vm_page *, + struct uvm_object *, voff_t); +int uvm_pagerealloc_multi(struct uvm_object *, voff_t, + vsize_t, int, struct uvm_constraint_range *); +/* Actually, uvm_page_physload takes PF#s which need their own type */ +void uvm_page_physload(paddr_t, paddr_t, paddr_t, + paddr_t, int); +void uvm_setpagesize(void); +void uvm_shutdown(void); +void uvm_aio_biodone(struct buf *); +void uvm_aio_aiodone(struct buf *); +void uvm_pageout(void *); +void uvm_aiodone_daemon(void *); +void uvm_wait(const char *); +int uvm_pglistalloc(psize_t, paddr_t, paddr_t, + paddr_t, paddr_t, struct pglist *, int, int); +void uvm_pglistfree(struct pglist *); +void uvm_pmr_use_inc(paddr_t, paddr_t); +void uvm_swap_init(void); +typedef int uvm_coredump_setup_cb(int _nsegment, void *_cookie); +typedef int uvm_coredump_walk_cb(vaddr_t _start, vaddr_t _realend, + vaddr_t _end, vm_prot_t _prot, int _isvnode, + int _nsegment, void *_cookie); +int uvm_coredump_walkmap(struct proc *_p, + uvm_coredump_setup_cb *_setup, + uvm_coredump_walk_cb *_walk, void *_cookie); +void uvm_grow(struct proc *, vaddr_t); +void uvm_pagezero_thread(void *); +void kmeminit_nkmempages(void); +void kmeminit(void); +extern u_int nkmempages; + +struct vnode; +struct uvm_object *uvn_attach(struct vnode *, vm_prot_t); + +struct process; +struct kinfo_vmentry; +int fill_vmmap(struct process *, struct kinfo_vmentry *, + size_t *); + +#endif /* _KERNEL */ + +#endif /* _UVM_UVM_EXTERN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/uvm/uvm_fault.h b/lib/libc/include/generic-openbsd/uvm/uvm_fault.h new file mode 100644 index 0000000000..c8fa50c668 --- /dev/null +++ b/lib/libc/include/generic-openbsd/uvm/uvm_fault.h @@ -0,0 +1,83 @@ +/* $OpenBSD: uvm_fault.h,v 1.16 2020/11/06 11:52:39 mpi Exp $ */ +/* $NetBSD: uvm_fault.h,v 1.14 2000/06/26 14:21:17 mrg Exp $ */ + +/* + * Copyright (c) 1997 Charles D. Cranor and Washington University. + * 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. + * + * from: Id: uvm_fault.h,v 1.1.2.2 1997/12/08 16:07:12 chuck Exp + */ + +#ifndef _UVM_UVM_FAULT_H_ +#define _UVM_UVM_FAULT_H_ + +/* + * fault types + */ + +#define VM_FAULT_INVALID ((vm_fault_t) 0x0) /* invalid mapping */ +#define VM_FAULT_PROTECT ((vm_fault_t) 0x1) /* protection */ +#define VM_FAULT_WIRE ((vm_fault_t) 0x2) /* wire mapping */ + +/* + * fault data structures + */ + +/* + * uvm_faultinfo: to load one of these fill in all orig_* fields and + * then call uvmfault_lookup on it. + */ + + +struct uvm_faultinfo { + vm_map_t orig_map; /* IN: original map */ + vaddr_t orig_rvaddr; /* IN: original rounded VA */ + vsize_t orig_size; /* IN: original size of interest */ + vm_map_t map; /* map (could be a submap) */ + unsigned int mapv; /* map's version number */ + vm_map_entry_t entry; /* map entry (from 'map') */ + vsize_t size; /* size of interest */ +}; + +#ifdef _KERNEL + +/* + * fault prototypes + */ + +void uvmfault_init(void); + +boolean_t uvmfault_lookup(struct uvm_faultinfo *, boolean_t); +boolean_t uvmfault_relock(struct uvm_faultinfo *); +void uvmfault_unlockall(struct uvm_faultinfo *, struct vm_amap *, + struct uvm_object *); +int uvmfault_anonget(struct uvm_faultinfo *, struct vm_amap *, + struct vm_anon *); + +int uvm_fault_wire(vm_map_t, vaddr_t, vaddr_t, vm_prot_t); +void uvm_fault_unwire(vm_map_t, vaddr_t, vaddr_t); +void uvm_fault_unwire_locked(vm_map_t, vaddr_t, vaddr_t); + +#endif /* _KERNEL */ + +#endif /* _UVM_UVM_FAULT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/uvm/uvm_glue.h b/lib/libc/include/generic-openbsd/uvm/uvm_glue.h new file mode 100644 index 0000000000..e59e2b0112 --- /dev/null +++ b/lib/libc/include/generic-openbsd/uvm/uvm_glue.h @@ -0,0 +1,44 @@ +/* $OpenBSD: uvm_glue.h,v 1.11 2025/06/02 18:49:04 claudio Exp $ */ +/* $NetBSD: uvm_glue.h,v 1.6 1999/06/21 17:25:11 thorpej Exp $ */ + +/* + * Copyright (c) 1997 Charles D. Cranor and Washington University. + * 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. + * + * from: Id: uvm_glue.h,v 1.1.2.1 1997/08/14 19:10:48 chuck Exp + */ + +#ifndef _UVM_UVM_GLUE_H_ +#define _UVM_UVM_GLUE_H_ + +#ifdef _KERNEL + +/* + * uvm_glue.h + */ + +struct vm_page *uvm_atopg(vaddr_t); + +#endif /* _KERNEL */ + +#endif /* _UVM_UVM_GLUE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/uvm/uvm_km.h b/lib/libc/include/generic-openbsd/uvm/uvm_km.h new file mode 100644 index 0000000000..6b3cf3b41a --- /dev/null +++ b/lib/libc/include/generic-openbsd/uvm/uvm_km.h @@ -0,0 +1,82 @@ +/* $OpenBSD: uvm_km.h,v 1.15 2017/05/11 00:42:05 dlg Exp $ */ +/* $NetBSD: uvm_km.h,v 1.9 1999/06/21 17:25:11 thorpej Exp $ */ + +/* + * Copyright (c) 1997 Charles D. Cranor and Washington University. + * 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. + * + * from: Id: uvm_km.h,v 1.1.2.2 1997/12/30 12:03:15 mrg Exp + */ + +#ifndef _UVM_UVM_KM_H_ +#define _UVM_UVM_KM_H_ + +/* + * uvm_km.h + */ + +#ifdef _KERNEL + +#include + +/* + * prototypes + */ + +void uvm_km_init(vaddr_t, vaddr_t, vaddr_t); +void uvm_km_page_init(void); +void uvm_km_page_lateinit(void); +void uvm_km_pgremove(struct uvm_object *, vaddr_t, vaddr_t); +void uvm_km_pgremove_intrsafe(vaddr_t, vaddr_t); + +#if !defined(__HAVE_PMAP_DIRECT) + +#define UVM_KM_PAGES_LOWAT_MAX (2048) +#define UVM_KM_PAGES_HIWAT_MAX (4 * UVM_KM_PAGES_LOWAT_MAX) + +struct uvm_km_free_page { + struct uvm_km_free_page *next; +}; +struct uvm_km_pages { + struct mutex mtx; + + /* Low and high water mark for addresses. */ + int lowat; + int hiwat; + + /* Kernel address pool. */ + int free; + vaddr_t page[UVM_KM_PAGES_HIWAT_MAX]; + + struct uvm_km_free_page *freelist; + int freelistlen; + + struct proc *km_proc; +}; + +extern struct uvm_km_pages uvm_km_pages; +#endif /* _HAVE_PMAP_DIRECT */ + +#endif /* _KERNEL */ + +#endif /* _UVM_UVM_KM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/uvm/uvm_map.h b/lib/libc/include/generic-openbsd/uvm/uvm_map.h new file mode 100644 index 0000000000..3b32a318db --- /dev/null +++ b/lib/libc/include/generic-openbsd/uvm/uvm_map.h @@ -0,0 +1,434 @@ +/* $OpenBSD: uvm_map.h,v 1.96 2025/09/14 13:06:02 mpi Exp $ */ +/* $NetBSD: uvm_map.h,v 1.24 2001/02/18 21:19:08 chs Exp $ */ + +/* + * Copyright (c) 2011 Ariane van der Steldt + * + * 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. + * + * + * Copyright (c) 1997 Charles D. Cranor and Washington University. + * Copyright (c) 1991, 1993, The Regents of the University of California. + * + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * The Mach Operating System project at Carnegie-Mellon University. + * + * 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_map.h 8.3 (Berkeley) 3/15/94 + * from: Id: uvm_map.h,v 1.1.2.3 1998/02/07 01:16:55 chs Exp + * + * + * Copyright (c) 1987, 1990 Carnegie-Mellon University. + * All rights reserved. + * + * Permission to use, copy, modify and distribute this software and + * its documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND + * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + */ + +#ifndef _UVM_UVM_MAP_H_ +#define _UVM_UVM_MAP_H_ + +#include +#include + +#ifdef _KERNEL + +/* + * UVM_MAP_CLIP_START: ensure that the entry begins at or after + * the starting address, if it doesn't we split the entry. + * + * => map must be locked by caller + */ + +#define UVM_MAP_CLIP_START(_map, _entry, _addr) \ + do { \ + KASSERT((_entry)->end + (_entry)->fspace > (_addr)); \ + if ((_entry)->start < (_addr)) \ + uvm_map_clip_start((_map), (_entry), (_addr)); \ + } while (0) + +/* + * UVM_MAP_CLIP_END: ensure that the entry ends at or before + * the ending address, if it doesn't we split the entry. + * + * => map must be locked by caller + */ + +#define UVM_MAP_CLIP_END(_map, _entry, _addr) \ + do { \ + KASSERT((_entry)->start < (_addr)); \ + if ((_entry)->end > (_addr)) \ + uvm_map_clip_end((_map), (_entry), (_addr)); \ + } while (0) + +/* + * extract flags + */ +#define UVM_EXTRACT_FIXPROT 0x8 /* set prot to maxprot as we go */ + +#endif /* _KERNEL */ + +#include + +/* + * Address map entries consist of start and end addresses, + * a VM object (or sharing map) and offset into that object, + * and user-exported inheritance and protection information. + * Also included is control information for virtual copy operations. + */ +struct vm_map_entry { + union { + RBT_ENTRY(vm_map_entry) addr_entry; /* address tree */ + SLIST_ENTRY(vm_map_entry) addr_kentry; + } daddrs; + + union { + RBT_ENTRY(vm_map_entry) rbtree; /* Link freespace tree. */ + TAILQ_ENTRY(vm_map_entry) tailq;/* Link freespace queue. */ + TAILQ_ENTRY(vm_map_entry) deadq;/* dead entry queue */ + } dfree; + +#define uvm_map_entry_start_copy start + vaddr_t start; /* start address */ + vaddr_t end; /* end address */ + + vsize_t guard; /* bytes in guard */ + vsize_t fspace; /* free space */ + + union { + struct uvm_object *uvm_obj; /* uvm object */ + struct vm_map *sub_map; /* belongs to another map */ + } object; /* object I point to */ + voff_t offset; /* offset into object */ + struct vm_aref aref; /* anonymous overlay */ + int etype; /* entry type */ + vm_prot_t protection; /* protection code */ + vm_prot_t max_protection; /* maximum protection */ + vm_inherit_t inheritance; /* inheritance */ + int wired_count; /* can be paged if == 0 */ + int advice; /* madvise advice */ +#define uvm_map_entry_stop_copy flags + u_int8_t flags; /* flags */ + +#define UVM_MAP_STATIC 0x01 /* static map entry */ +#define UVM_MAP_KMEM 0x02 /* from kmem entry pool */ + + vsize_t fspace_augment; /* max(fspace) in subtree */ +}; + +#define VM_MAPENT_ISWIRED(entry) ((entry)->wired_count != 0) + +TAILQ_HEAD(uvm_map_deadq, vm_map_entry); /* dead entry queue */ +RBT_HEAD(uvm_map_addr, vm_map_entry); +#ifdef _KERNEL +RBT_PROTOTYPE(uvm_map_addr, vm_map_entry, daddrs.addr_entry, + uvm_mapentry_addrcmp); +#endif + +/* + * A Map is a rbtree of map entries, kept sorted by address. + * In addition, free space entries are also kept in a rbtree, + * indexed by free size. + * + * + * + * LOCKING PROTOCOL NOTES: + * ----------------------- + * + * VM map locking is a little complicated. There are both shared + * and exclusive locks on maps. However, it is sometimes required + * to unlock a VM map (to prevent lock ordering issues) without + * allowing any other thread to modify it. + * + * In order to prevent this scenario, we introduce the notion of + * a `busy' map. A `busy' map is unlocked, but other threads + * attempting to write-lock wait for this flag to clear before + * entering the lock manager. A map may only be marked busy + * when the map is write-locked and may only be marked unbusy by + * the thread which marked it busy. + * + * Access to the map `flags' member is controlled by the `flags_lock' + * simple lock. Note that some flags are static (set once at map + * creation time, and never changed), and thus require no locking + * to check those flags. All flags which are r/w must be set or + * cleared while the `flags_lock' is asserted. Additional locking + * requirements are: + * + * VM_MAP_PAGEABLE r/o static flag; no locking required + * + * VM_MAP_INTRSAFE r/o static flag; no locking required + * + * VM_MAP_WIREFUTURE r/w; may only be set or cleared when + * map is write-locked. may be tested + * without asserting `flags_lock'. + * + * VM_MAP_GUARDPAGES r/o; must be specified at map + * initialization time. + * If set, guards will appear between + * automatic allocations. + * No locking required. + * + * VM_MAP_ISVMSPACE r/o; set by uvmspace_alloc. + * Signifies that this map is a vmspace. + * (The implementation treats all maps + * without this bit as kernel maps.) + * No locking required. + * + * + * All automatic allocations (uvm_map without MAP_FIXED) will allocate + * from vm_map.free. + * If that allocation fails: + * - vmspace maps will spill over into vm_map.bfree, + * - all other maps will call uvm_map_kmem_grow() to increase the arena. + * + * vmspace maps have their data, brk() and stack arenas automatically + * updated when uvm_map() is invoked without MAP_FIXED. + * The spill over arena (vm_map.bfree) will contain the space in the brk() + * and stack ranges. + * Kernel maps never have a bfree arena and this tree will always be empty. + * + * + * read_locks and write_locks are used in lock debugging code. + * + * Locks used to protect struct members in this file: + * a atomic operations + * I immutable after creation or exec(2) + * v `vm_map_lock' (this map `lock' or `mtx') + * f flags_lock + */ +struct vm_map { + struct pmap *pmap; /* [I] Physical map */ + u_long sserial; /* [v] # stack changes */ + + struct uvm_map_addr addr; /* [v] Entry tree, by addr */ + + vsize_t size; /* virtual size */ + int ref_count; /* [a] Reference count */ + int flags; /* [f] flags */ + unsigned int timestamp; /* Version number */ + struct proc *busy; /* [f] thread holding map busy*/ + unsigned int nbusy; /* [f] waiters for busy */ + + vaddr_t min_offset; /* [I] First address in map. */ + vaddr_t max_offset; /* [I] Last address in map. */ + + /* + * Allocation overflow regions. + */ + vaddr_t b_start; /* [v] Start for brk() alloc. */ + vaddr_t b_end; /* [v] End for brk() alloc. */ + vaddr_t s_start; /* [v] Start for stack alloc. */ + vaddr_t s_end; /* [v] End for stack alloc. */ + + /* + * Special address selectors. + * + * The uaddr_exe mapping is used if: + * - protX is selected + * - the pointer is not NULL + * + * If uaddr_exe is not used, the other mappings are checked in + * order of appearance. + * If a hint is given, the selection will only be used if the hint + * falls in the range described by the mapping. + * + * The states are pointers because: + * - they may not all be in use + * - the struct size for different schemes is variable + * + * The uaddr_brk_stack selector will select addresses that are in + * the brk/stack area of the map. + */ + struct uvm_addr_state *uaddr_exe; /* Executable selector. */ + struct uvm_addr_state *uaddr_any[4]; /* More selectors. */ + struct uvm_addr_state *uaddr_brk_stack; /* Brk/stack selector. */ + +#define UVM_MAP_CHECK_COPYIN_MAX 4 /* main, sigtramp, ld.so, libc.so */ + struct uvm_check_copyin { + vaddr_t start, end; + } check_copyin[UVM_MAP_CHECK_COPYIN_MAX]; + int check_copyin_count; + + /* + * XXX struct mutex changes size because of compile options, so + * place after fields which are inspected by libkvm / procmap(1) + */ + struct rwlock lock; /* Non-intrsafe lock */ + struct mutex mtx; /* Intrsafe lock */ + struct mutex flags_lock; /* flags lock */ +}; + +/* vm_map flags */ +#define VM_MAP_PAGEABLE 0x01 /* ro: entries are pageable */ +#define VM_MAP_INTRSAFE 0x02 /* ro: interrupt safe map */ +#define VM_MAP_WIREFUTURE 0x04 /* rw: wire future mappings */ +#define VM_MAP_GUARDPAGES 0x20 /* rw: add guard pgs to map */ +#define VM_MAP_ISVMSPACE 0x40 /* ro: map is a vmspace */ +#define VM_MAP_PINSYSCALL_ONCE 0x100 /* rw: pinsyscall done */ + +/* Number of kernel maps and entries to statically allocate */ +#define MAX_KMAPENT 1024 /* Sufficient to make it to the scheduler. */ + +#ifdef _KERNEL +/* + * globals: + */ + +extern vaddr_t uvm_maxkaddr; + +/* + * protos: the following prototypes define the interface to vm_map + */ + +void uvm_map_deallocate(struct vm_map *); + +int uvm_map_clean(struct vm_map *, vaddr_t, vaddr_t, int); +void uvm_map_clip_start(struct vm_map *, struct vm_map_entry *, + vaddr_t); +void uvm_map_clip_end(struct vm_map *, struct vm_map_entry *, + vaddr_t); +int uvm_map_extract(struct vm_map *, vaddr_t, vsize_t, + vaddr_t *, int); +struct vm_map * uvm_map_create(pmap_t, vaddr_t, vaddr_t, int); +vaddr_t uvm_map_pie(vaddr_t); +vaddr_t uvm_map_hint(struct vmspace *, vm_prot_t, vaddr_t, vaddr_t); +int uvm_map_check_copyin_add(struct vm_map *, vaddr_t, vaddr_t); +int uvm_map_immutable(struct vm_map *, vaddr_t, vaddr_t, int); +int uvm_map_inherit(struct vm_map *, vaddr_t, vaddr_t, vm_inherit_t); +int uvm_map_advice(struct vm_map *, vaddr_t, vaddr_t, int); +void uvm_map_init(void); +boolean_t uvm_map_lookup_entry(struct vm_map *, vaddr_t, vm_map_entry_t *); +boolean_t uvm_map_is_stack_remappable(struct vm_map *, vaddr_t, vsize_t, int); +int uvm_map_remap_as_stack(struct proc *, vaddr_t, vsize_t); +void uvm_map_setup(struct vm_map *, pmap_t, vaddr_t, vaddr_t, int); +int uvm_map_submap(struct vm_map *, vaddr_t, vaddr_t, + struct vm_map *); +void uvm_unmap(struct vm_map *, vaddr_t, vaddr_t); +void uvm_unmap_detach(struct uvm_map_deadq *, int); +int uvm_unmap_remove(struct vm_map*, vaddr_t, vaddr_t, + struct uvm_map_deadq *, boolean_t, boolean_t, boolean_t); +void uvm_map_set_uaddr(struct vm_map*, struct uvm_addr_state**, + struct uvm_addr_state*); +int uvm_map_mquery(struct vm_map*, vaddr_t*, vsize_t, voff_t, int); + + +struct p_inentry; + +int uvm_map_inentry_sp(vm_map_entry_t); +boolean_t uvm_map_inentry(struct proc *, struct p_inentry *, vaddr_t addr, + const char *fmt, int (*fn)(vm_map_entry_t), u_long serial); + +struct kinfo_vmentry; + +int uvm_map_fill_vmmap(struct vm_map *, struct kinfo_vmentry *, + size_t *); + +/* + * VM map locking operations. + */ + +boolean_t vm_map_lock_try_ln(struct vm_map*, char*, int); +void vm_map_lock_ln(struct vm_map*, char*, int); +void vm_map_lock_read_ln(struct vm_map*, char*, int); +void vm_map_unlock_ln(struct vm_map*, char*, int); +void vm_map_unlock_read_ln(struct vm_map*, char*, int); +boolean_t vm_map_upgrade_ln(struct vm_map*, char*, int); +void vm_map_downgrade_ln(struct vm_map*, char*, int); +void vm_map_busy_ln(struct vm_map*, char*, int); +void vm_map_unbusy_ln(struct vm_map*, char*, int); +void vm_map_assert_anylock_ln(struct vm_map*, char*, int); +void vm_map_assert_wrlock_ln(struct vm_map*, char*, int); + +#ifdef DIAGNOSTIC +#define vm_map_lock_try(map) vm_map_lock_try_ln(map, __FILE__, __LINE__) +#define vm_map_lock(map) vm_map_lock_ln(map, __FILE__, __LINE__) +#define vm_map_lock_read(map) vm_map_lock_read_ln(map, __FILE__, __LINE__) +#define vm_map_unlock(map) vm_map_unlock_ln(map, __FILE__, __LINE__) +#define vm_map_unlock_read(map) vm_map_unlock_read_ln(map, __FILE__, __LINE__) +#define vm_map_upgrade(map) vm_map_upgrade_ln(map, __FILE__, __LINE__) +#define vm_map_downgrade(map) vm_map_downgrade_ln(map, __FILE__, __LINE__) +#define vm_map_busy(map) vm_map_busy_ln(map, __FILE__, __LINE__) +#define vm_map_unbusy(map) vm_map_unbusy_ln(map, __FILE__, __LINE__) +#define vm_map_assert_anylock(map) \ + vm_map_assert_anylock_ln(map, __FILE__, __LINE__) +#define vm_map_assert_wrlock(map) \ + vm_map_assert_wrlock_ln(map, __FILE__, __LINE__) +#else +#define vm_map_lock_try(map) vm_map_lock_try_ln(map, NULL, 0) +#define vm_map_lock(map) vm_map_lock_ln(map, NULL, 0) +#define vm_map_lock_read(map) vm_map_lock_read_ln(map, NULL, 0) +#define vm_map_unlock(map) vm_map_unlock_ln(map, NULL, 0) +#define vm_map_unlock_read(map) vm_map_unlock_read_ln(map, NULL, 0) +#define vm_map_upgrade(map) vm_map_upgrade_ln(map, NULL, 0) +#define vm_map_downgrade(map) vm_map_downgrade_ln(map, NULL, 0) +#define vm_map_busy(map) vm_map_busy_ln(map, NULL, 0) +#define vm_map_unbusy(map) vm_map_unbusy_ln(map, NULL, 0) +#define vm_map_assert_anylock(map) vm_map_assert_anylock_ln(map, NULL, 0) +#define vm_map_assert_wrlock(map) vm_map_assert_wrlock_ln(map, NULL, 0) +#endif + +void uvm_map_lock_entry(struct vm_map_entry *); +void uvm_map_unlock_entry(struct vm_map_entry *); + +#endif /* _KERNEL */ + +/* + * Functions implemented as macros + */ +#define vm_map_min(map) ((map)->min_offset) +#define vm_map_max(map) ((map)->max_offset) +#define vm_map_pmap(map) ((map)->pmap) + +#endif /* _UVM_UVM_MAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/uvm/uvm_object.h b/lib/libc/include/generic-openbsd/uvm/uvm_object.h new file mode 100644 index 0000000000..af9e887576 --- /dev/null +++ b/lib/libc/include/generic-openbsd/uvm/uvm_object.h @@ -0,0 +1,126 @@ +/* $OpenBSD: uvm_object.h,v 1.30 2022/09/04 06:49:11 jsg Exp $ */ +/* $NetBSD: uvm_object.h,v 1.11 2001/03/09 01:02:12 chs Exp $ */ + +/* + * Copyright (c) 1997 Charles D. Cranor and Washington University. + * 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. + * + * from: Id: uvm_object.h,v 1.1.2.2 1998/01/04 22:44:51 chuck Exp + */ + +#ifndef _UVM_UVM_OBJECT_H_ +#define _UVM_UVM_OBJECT_H_ + +/* + * The UVM memory object interface. Notes: + * + * A UVM memory object represents a list of pages, which are managed by + * the object's pager operations (uvm_object::pgops). All pages belonging + * to an object are owned by it and thus protected by the object lock. + * + * The lock (uvm_object::vmobjlock) may be shared amongst the UVM objects. + * By default, the lock is allocated dynamically using rw_obj_init() cache. + * Lock sharing is normally used when there is an underlying object. For + * example, vnode representing a file may have an underlying node, which + * is the case for tmpfs and layered file systems. In such case, vnode's + * UVM object and the underlying UVM object shares the lock. + * + * The reference count is managed atomically for the anonymous UVM objects. + * For other objects, it is arbitrary (may use the lock or atomics). + */ + +struct uvm_object { + struct rwlock *vmobjlock; /* lock on object */ + const struct uvm_pagerops *pgops; /* pager ops */ + RBT_HEAD(uvm_objtree, vm_page) memt; /* pages in object */ + int uo_npages; /* # of pages in memt */ + int uo_refs; /* reference count */ +}; + +/* + * UVM_OBJ_KERN is a 'special' uo_refs value which indicates that the + * object is a kernel memory object rather than a normal one (kernel + * memory objects don't have reference counts -- they never die). + * + * this value is used to detected kernel object mappings at uvm_unmap() + * time. normally when an object is unmapped its pages eventually become + * deactivated and then paged out and/or freed. this is not useful + * for kernel objects... when a kernel object is unmapped we always want + * to free the resources associated with the mapping. UVM_OBJ_KERN + * allows us to decide which type of unmapping we want to do. + * + * in addition, we have kernel objects which may be used in an + * interrupt context. these objects get their mappings entered + * with pmap_kenter*() and removed with pmap_kremove(), which + * are safe to call in interrupt context, and must be used ONLY + * for wired kernel mappings in these objects and their associated + * maps. + */ +#define UVM_OBJ_KERN (-2) + +#define UVM_OBJ_IS_KERN_OBJECT(uobj) \ + ((uobj)->uo_refs == UVM_OBJ_KERN) + +#ifdef _KERNEL + +extern const struct uvm_pagerops uvm_vnodeops; +extern const struct uvm_pagerops uvm_deviceops; +extern const struct uvm_pagerops pmap_pager; +extern const struct uvm_pagerops bufcache_pager; + +/* For object trees */ +int uvm_pagecmp(const struct vm_page *, const struct vm_page *); +RBT_PROTOTYPE(uvm_objtree, vm_page, objt, uvm_pagecmp) + +#define UVM_OBJ_IS_VNODE(uobj) \ + ((uobj)->pgops == &uvm_vnodeops) + +#define UVM_OBJ_IS_DEVICE(uobj) \ + ((uobj)->pgops == &uvm_deviceops) + +#define UVM_OBJ_IS_VTEXT(uobj) \ + ((uobj)->pgops == &uvm_vnodeops && \ + ((struct vnode *)uobj)->v_flag & VTEXT) + +#define UVM_OBJ_IS_AOBJ(uobj) \ + ((uobj)->pgops == &aobj_pager) + +#define UVM_OBJ_IS_PMAP(uobj) \ + ((uobj)->pgops == &pmap_pager) + +#define UVM_OBJ_IS_BUFCACHE(uobj) \ + ((uobj)->pgops == &bufcache_pager) + +#define UVM_OBJ_IS_DUMMY(uobj) \ + (UVM_OBJ_IS_PMAP(uobj) || UVM_OBJ_IS_BUFCACHE(uobj)) + +void uvm_obj_init(struct uvm_object *, const struct uvm_pagerops *, int); +void uvm_obj_destroy(struct uvm_object *); +void uvm_obj_setlock(struct uvm_object *, struct rwlock *); +int uvm_obj_wire(struct uvm_object *, voff_t, voff_t, struct pglist *); +void uvm_obj_unwire(struct uvm_object *, voff_t, voff_t); +void uvm_obj_free(struct uvm_object *); + +#endif /* _KERNEL */ + +#endif /* _UVM_UVM_OBJECT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/uvm/uvm_page.h b/lib/libc/include/generic-openbsd/uvm/uvm_page.h new file mode 100644 index 0000000000..1462923101 --- /dev/null +++ b/lib/libc/include/generic-openbsd/uvm/uvm_page.h @@ -0,0 +1,301 @@ +/* $OpenBSD: uvm_page.h,v 1.73 2025/03/10 18:54:38 mpi Exp $ */ +/* $NetBSD: uvm_page.h,v 1.19 2000/12/28 08:24:55 chs Exp $ */ + +/* + * Copyright (c) 1997 Charles D. Cranor and Washington University. + * Copyright (c) 1991, 1993, The Regents of the University of California. + * + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * The Mach Operating System project at Carnegie-Mellon University. + * + * 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_page.h 7.3 (Berkeley) 4/21/91 + * from: Id: uvm_page.h,v 1.1.2.6 1998/02/04 02:31:42 chuck Exp + * + * + * Copyright (c) 1987, 1990 Carnegie-Mellon University. + * All rights reserved. + * + * Permission to use, copy, modify and distribute this software and + * its documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND + * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + */ + +#ifndef _UVM_UVM_PAGE_H_ +#define _UVM_UVM_PAGE_H_ + +/* + * uvm_page.h + */ + +/* + * Resident memory system definitions. + */ + +/* + * Management of resident (logical) pages. + * + * A small structure is kept for each resident + * page, indexed by page number. Each structure + * contains a list used for manipulating pages, and + * a tree structure for in object/offset lookups + * + * In addition, the structure contains the object + * and offset to which this page belongs (for pageout), + * and sundry status bits. + * + * Locks used to protect struct members in this file: + * I immutable after creation + * a atomic operations + * Q uvm.pageqlock + * F uvm.fpageqlock + * o owner lock (uobject->vmobjlock or uanon->an_lock) + */ + +TAILQ_HEAD(pglist, vm_page); + +struct vm_page { + TAILQ_ENTRY(vm_page) pageq; /* [Q] LRU or free page queue */ + RBT_ENTRY(vm_page) objt; /* [o] object tree */ + + struct vm_anon *uanon; /* [o] anon */ + struct uvm_object *uobject; /* [o] object */ + voff_t offset; /* [o] offset into object */ + + uint32_t pg_flags; /* [a] object flags */ + + uint32_t pg_version; /* version count */ + uint32_t wire_count; /* [o] wired down map refs */ + + paddr_t phys_addr; /* [I] physical address */ + psize_t fpgsz; /* [F] free page range size */ + + struct vm_page_md mdpage; /* pmap-specific data */ + +#if defined(UVM_PAGE_TRKOWN) + /* debugging fields to track page ownership */ + pid_t owner; /* thread that set PG_BUSY */ + char *owner_tag; /* why it was set busy */ +#endif +}; + +/* + * These are the flags defined for vm_page. + * + * Note: PG_FILLED and PG_DIRTY are added for the filesystems. + */ + +/* + * locking rules: + * PQ_ ==> lock by page queue lock + * PQ_FREE is locked by free queue lock and is mutex with all other PQs + * pg_flags may only be changed using the atomic operations. + * + * PG_ZERO is used to indicate that a page has been pre-zero'd. This flag + * is only set when the page is on no queues, and is cleared when the page + * is placed on the free list. + */ + +#define PG_BUSY 0x00000001 /* page is locked */ +#define PG_WANTED 0x00000002 /* someone is waiting for page */ +#define PG_TABLED 0x00000004 /* page is in VP table */ +#define PG_CLEAN 0x00000008 /* page has not been modified */ +#define PG_CLEANCHK 0x00000010 /* clean bit has been checked */ +#define PG_RELEASED 0x00000020 /* page released while paging */ +#define PG_FAKE 0x00000040 /* page is not yet initialized */ +#define PG_RDONLY 0x00000080 /* page must be mapped read-only */ +#define PG_ZERO 0x00000100 /* page is pre-zero'd */ +#define PG_DEV 0x00000200 /* page is in device space, lay off */ +#define PG_MASK 0x0000ffff + +#define PQ_FREE 0x00010000 /* page is on free list */ +#define PQ_INACTIVE 0x00020000 /* page is in inactive list */ +#define PQ_ACTIVE 0x00040000 /* page is in active list */ +#define PQ_ITER 0x00080000 /* page is an iterator marker */ +#define PQ_ANON 0x00100000 /* page is part of an anon, rather + than an uvm_object */ +#define PQ_AOBJ 0x00200000 /* page is part of an anonymous + uvm_object */ +#define PQ_SWAPBACKED (PQ_ANON|PQ_AOBJ) +#define PQ_ENCRYPT 0x00400000 /* page needs {en,de}cryption */ +#define PQ_MASK 0x00ff0000 + +#define PG_PMAP0 0x01000000 /* Used by some pmaps. */ +#define PG_PMAP1 0x02000000 /* Used by some pmaps. */ +#define PG_PMAP2 0x04000000 /* Used by some pmaps. */ +#define PG_PMAP3 0x08000000 /* Used by some pmaps. */ +#define PG_PMAP4 0x10000000 /* Used by some pmaps. */ +#define PG_PMAP5 0x20000000 /* Used by some pmaps. */ +#define PG_PMAPMASK 0x3f000000 + +/* + * physical memory layout structure + * + * MD vmparam.h must #define: + * VM_PHYSSEG_MAX = max number of physical memory segments we support + * (if this is "1" then we revert to a "contig" case) + * VM_PHYSSEG_STRAT: memory sort/search options (for VM_PHYSSEG_MAX > 1) + * - VM_PSTRAT_RANDOM: linear search (random order) + * - VM_PSTRAT_BSEARCH: binary search (sorted by address) + * - VM_PSTRAT_BIGFIRST: linear search (sorted by largest segment first) + * - others? + * XXXCDC: eventually we should purge all left-over global variables... + */ +#define VM_PSTRAT_RANDOM 1 +#define VM_PSTRAT_BSEARCH 2 +#define VM_PSTRAT_BIGFIRST 3 + +/* + * vm_physmemseg: describes one segment of physical memory + */ +struct vm_physseg { + paddr_t start; /* PF# of first page in segment */ + paddr_t end; /* (PF# of last page in segment) + 1 */ + paddr_t avail_start; /* PF# of first free page in segment */ + paddr_t avail_end; /* (PF# of last free page in segment) +1 */ + struct vm_page *pgs; /* vm_page structures (from start) */ + struct vm_page *lastpg; /* vm_page structure for end */ +}; + +#ifdef _KERNEL + +/* + * physical memory config is stored in vm_physmem. + */ + +extern struct vm_physseg vm_physmem[VM_PHYSSEG_MAX]; +extern int vm_nphysseg; + +/* + * prototypes: the following prototypes define the interface to pages + */ + +void uvm_page_init(vaddr_t *, vaddr_t *); +#if defined(UVM_PAGE_TRKOWN) +void uvm_page_own(struct vm_page *, char *); +#endif +#if !defined(PMAP_STEAL_MEMORY) +boolean_t uvm_page_physget(paddr_t *); +#endif + +void uvm_pageactivate(struct vm_page *); +void uvm_pagedequeue(struct vm_page *); +vaddr_t uvm_pageboot_alloc(vsize_t); +void uvm_pagecopy(struct vm_page *, struct vm_page *); +void uvm_pagedeactivate(struct vm_page *); +void uvm_pageclean(struct vm_page *); +void uvm_pagefree(struct vm_page *); +void uvm_page_unbusy(struct vm_page **, int); +struct vm_page *uvm_pagelookup(struct uvm_object *, voff_t); +void uvm_pageunwire(struct vm_page *); +void uvm_pagewait(struct vm_page *, struct rwlock *, const char *); +void uvm_pagewire(struct vm_page *); +void uvm_pagezero(struct vm_page *); +void uvm_pagealloc_pg(struct vm_page *, struct uvm_object *, + voff_t, struct vm_anon *); + +struct uvm_constraint_range; /* XXX move to uvm_extern.h? */ +psize_t uvm_pagecount(struct uvm_constraint_range*); + +#if VM_PHYSSEG_MAX == 1 +/* + * Inline functions for archs where function calls are expensive. + */ +/* + * vm_physseg_find: find vm_physseg structure that belongs to a PA + */ +static inline int +vm_physseg_find(paddr_t pframe, int *offp) +{ + /* 'contig' case */ + if (pframe >= vm_physmem[0].start && pframe < vm_physmem[0].end) { + if (offp) + *offp = pframe - vm_physmem[0].start; + return 0; + } + return -1; +} + +/* + * PHYS_TO_VM_PAGE: find vm_page for a PA. used by MI code to get vm_pages + * back from an I/O mapping (ugh!). used in some MD code as well. + */ +static inline struct vm_page * +PHYS_TO_VM_PAGE(paddr_t pa) +{ + paddr_t pf = atop(pa); + int off; + int psi; + + psi = vm_physseg_find(pf, &off); + + return ((psi == -1) ? NULL : &vm_physmem[psi].pgs[off]); +} +#else +/* if VM_PHYSSEG_MAX > 1 they're not inline, they're in uvm_page.c. */ +struct vm_page *PHYS_TO_VM_PAGE(paddr_t); +int vm_physseg_find(paddr_t, int *); +#endif + +/* + * macros + */ + +#define uvm_lock_pageq() mtx_enter(&uvm.pageqlock) +#define uvm_unlock_pageq() mtx_leave(&uvm.pageqlock) +#define uvm_lock_fpageq() mtx_enter(&uvm.fpageqlock) +#define uvm_unlock_fpageq() mtx_leave(&uvm.fpageqlock) + +#define UVM_PAGEZERO_TARGET (uvmexp.free / 8) + +#define VM_PAGE_TO_PHYS(pg) ((pg)->phys_addr) + +#define VM_PAGE_IS_FREE(pg) ((pg)->pg_flags & PQ_FREE) + +#define PADDR_IS_DMA_REACHABLE(paddr) \ + (dma_constraint.ucr_low <= paddr && dma_constraint.ucr_high > paddr) + +#endif /* _KERNEL */ + +#endif /* _UVM_UVM_PAGE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/uvm/uvm_pager.h b/lib/libc/include/generic-openbsd/uvm/uvm_pager.h new file mode 100644 index 0000000000..f9449680c1 --- /dev/null +++ b/lib/libc/include/generic-openbsd/uvm/uvm_pager.h @@ -0,0 +1,173 @@ +/* $OpenBSD: uvm_pager.h,v 1.33 2021/10/12 07:38:22 mpi Exp $ */ +/* $NetBSD: uvm_pager.h,v 1.20 2000/11/27 08:40:05 chs Exp $ */ + +/* + * Copyright (c) 1997 Charles D. Cranor and Washington University. + * 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. + * + * from: Id: uvm_pager.h,v 1.1.2.14 1998/01/13 19:00:50 chuck Exp + */ + +/* + * Copyright (c) 1990 University of Utah. + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * the Systems Programming Group of the University of Utah Computer + * Science Department. + * + * 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_pager.h 8.5 (Berkeley) 7/7/94 + */ + +#ifndef _UVM_UVM_PAGER_H_ +#define _UVM_UVM_PAGER_H_ + +#ifdef _KERNEL + +struct uvm_pagerops { + /* init pager */ + void (*pgo_init)(void); + /* add reference to obj */ + void (*pgo_reference)(struct uvm_object *); + /* drop reference to obj */ + void (*pgo_detach)(struct uvm_object *); + /* special nonstd fault fn */ + int (*pgo_fault)(struct uvm_faultinfo *, vaddr_t, + vm_page_t *, int, int, vm_fault_t, + vm_prot_t, int); + /* flush pages out of obj */ + boolean_t (*pgo_flush)(struct uvm_object *, voff_t, + voff_t, int); + /* get/read page */ + int (*pgo_get)(struct uvm_object *, voff_t, + vm_page_t *, int *, int, vm_prot_t, int, int); + /* put/write page */ + int (*pgo_put)(struct uvm_object *, vm_page_t *, + int, boolean_t); + /* return range of cluster */ + void (*pgo_cluster)(struct uvm_object *, voff_t, + voff_t *, voff_t *); + /* make "put" cluster */ + struct vm_page ** (*pgo_mk_pcluster)(struct uvm_object *, + struct vm_page **, int *, struct vm_page *, + int, voff_t, voff_t); +}; + +/* pager flags [mostly for flush] */ + +#define PGO_CLEANIT 0x001 /* write dirty pages to backing store */ +#define PGO_SYNCIO 0x002 /* if PGO_CLEANIT: use sync I/O? */ +#define PGO_DEACTIVATE 0x004 /* deactivate flushed pages */ +#define PGO_FREE 0x008 /* free flushed pages */ +/* if PGO_FREE is not set then the pages stay where they are. */ + +#define PGO_ALLPAGES 0x010 /* flush whole object/get all pages */ +#define PGO_DOACTCLUST 0x020 /* flag to mk_pcluster to include active */ +#define PGO_LOCKED 0x040 /* fault data structures are locked [get] */ +#define PGO_PDFREECLUST 0x080 /* daemon's free cluster flag [uvm_pager_put] */ +#define PGO_REALLOCSWAP 0x100 /* reallocate swap area [pager_dropcluster] */ +#define PGO_NOWAIT 0x200 /* do not wait for inode lock */ + +/* page we are not interested in getting */ +#define PGO_DONTCARE ((struct vm_page *) -1L) /* [get only] */ + +/* + * prototypes + */ + +void uvm_pager_dropcluster(struct uvm_object *, struct vm_page *, + struct vm_page **, int *, int); +void uvm_pager_init(void); +int uvm_pager_put(struct uvm_object *, struct vm_page *, + struct vm_page ***, int *, int, voff_t, voff_t); + + +vaddr_t uvm_pagermapin(struct vm_page **, int, int); +void uvm_pagermapout(vaddr_t, int); +struct vm_page **uvm_mk_pcluster(struct uvm_object *, struct vm_page **, + int *, struct vm_page *, int, voff_t, voff_t); + +/* Flags to uvm_pagermapin() */ +#define UVMPAGER_MAPIN_WAITOK 0x01 /* it's okay to wait */ +#define UVMPAGER_MAPIN_READ 0x02 /* host <- device */ +#define UVMPAGER_MAPIN_WRITE 0x00 /* device -> host (pseudo flag) */ + +/* + * get/put return values + * OK operation was successful + * BAD specified data was out of the accepted range + * FAIL specified data was in range, but doesn't exist + * PEND operations was initiated but not completed + * ERROR error while accessing data that is in range and exists + * AGAIN temporary resource shortage prevented operation from happening + * UNLOCK unlock the map and try again + * REFAULT [uvm_fault internal use only!] unable to relock data structures, + * thus the mapping needs to be reverified before we can proceed + */ +#define VM_PAGER_OK 0 +#define VM_PAGER_BAD 1 +#define VM_PAGER_FAIL 2 +#define VM_PAGER_PEND 3 +#define VM_PAGER_ERROR 4 +#define VM_PAGER_AGAIN 5 +#define VM_PAGER_UNLOCK 6 +#define VM_PAGER_REFAULT 7 + +/* + * XXX + * this is needed until the device strategy interface + * is changed to do physically-addressed i/o. + */ + +#ifndef PAGER_MAP_SIZE +#define PAGER_MAP_SIZE (16 * 1024 * 1024) +#endif + +#endif /* _KERNEL */ + +#endif /* _UVM_UVM_PAGER_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/uvm/uvm_param.h b/lib/libc/include/generic-openbsd/uvm/uvm_param.h new file mode 100644 index 0000000000..f21919792e --- /dev/null +++ b/lib/libc/include/generic-openbsd/uvm/uvm_param.h @@ -0,0 +1,91 @@ +/* $OpenBSD: uvm_param.h,v 1.18 2015/02/07 08:21:24 miod Exp $ */ +/* $NetBSD: uvm_param.h,v 1.5 2001/03/09 01:02:12 chs Exp $ */ + +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * The Mach Operating System project at Carnegie-Mellon University. + * + * 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_param.h 8.2 (Berkeley) 1/9/95 + * + * + * Copyright (c) 1987, 1990 Carnegie-Mellon University. + * All rights reserved. + * + * Authors: Avadis Tevanian, Jr., Michael Wayne Young + * + * Permission to use, copy, modify and distribute this software and + * its documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND + * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + */ + +/* + * Machine independent virtual memory parameters. + */ + +#ifndef _VM_PARAM_ +#define _VM_PARAM_ + +#ifdef _KERNEL + +#include + +typedef int boolean_t; +#define TRUE 1 +#define FALSE 0 + +#define DEFAULT_PAGE_SIZE 4096 + +#define atop(x) ((x) >> PAGE_SHIFT) +#define ptoa(x) ((paddr_t)(x) << PAGE_SHIFT) +#define round_page(x) (((x) + PAGE_MASK) & ~PAGE_MASK) +#define trunc_page(x) ((x) & ~PAGE_MASK) + +#if !defined(VM_KERNEL_SPACE_SIZE) +#define VM_KERNEL_SPACE_SIZE (VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS) +#endif + +#endif /* _KERNEL */ +#endif /* _VM_PARAM_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/uvm/uvm_percpu.h b/lib/libc/include/generic-openbsd/uvm/uvm_percpu.h new file mode 100644 index 0000000000..78a9548e56 --- /dev/null +++ b/lib/libc/include/generic-openbsd/uvm/uvm_percpu.h @@ -0,0 +1,48 @@ +/* $OpenBSD: uvm_percpu.h,v 1.3 2024/05/01 12:54:27 mpi Exp $ */ + +/* + * Copyright (c) 2024 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 _UVM_UVM_PCPU_H_ +#define _UVM_UVM_PCPU_H_ + +struct vm_page; + +/* + * The number of pages per magazine should be large enough to get rid of the + * contention in the pmemrange allocator during concurrent page faults and + * small enough to limit fragmentation. + */ +#define UVM_PMR_CACHEMAGSZ 8 + +/* + * Magazine + */ +struct uvm_pmr_cache_item { + struct vm_page *upci_pages[UVM_PMR_CACHEMAGSZ]; + int upci_npages; /* # of pages in magazine */ +}; + +/* + * Per-CPU cache of physical pages. + */ +struct uvm_pmr_cache { + struct uvm_pmr_cache_item upc_magz[2]; /* magazines */ + int upc_actv; /* index of active magazine */ + +}; + +#endif /* _UVM_UVM_PCPU_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/uvm/uvm_pmap.h b/lib/libc/include/generic-openbsd/uvm/uvm_pmap.h new file mode 100644 index 0000000000..b653fbb19d --- /dev/null +++ b/lib/libc/include/generic-openbsd/uvm/uvm_pmap.h @@ -0,0 +1,195 @@ +/* $OpenBSD: uvm_pmap.h,v 1.37 2025/06/02 18:49:04 claudio Exp $ */ +/* $NetBSD: uvm_pmap.h,v 1.1 2000/06/27 09:00:14 mrg Exp $ */ + +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * The Mach Operating System project at Carnegie-Mellon University. + * + * 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. + * + * @(#)pmap.h 8.1 (Berkeley) 6/11/93 + * + * + * Copyright (c) 1987, 1990 Carnegie-Mellon University. + * All rights reserved. + * + * Author: Avadis Tevanian, Jr. + * + * Permission to use, copy, modify and distribute this software and + * its documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND + * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + */ + +/* + * Machine address mapping definitions -- machine-independent + * section. [For machine-dependent section, see "machine/pmap.h".] + */ + +#ifndef _PMAP_VM_ +#define _PMAP_VM_ + +struct proc; /* for pmap_activate()/pmap_deactivate() proto */ + +/* + * Each machine dependent implementation is expected to + * keep certain statistics. They may do this anyway they + * so choose, but are expected to return the statistics + * in the following structure. + */ +struct pmap_statistics { + long resident_count; /* # of pages mapped (total)*/ + long wired_count; /* # of pages wired */ +}; +typedef struct pmap_statistics *pmap_statistics_t; + +#include + +/* + * Flags passed to pmap_enter(). Note the bottom 3 bits are PROT_* + * bits, used to indicate the access type that was made (to seed modified + * and referenced information). + */ +#define PMAP_WIRED 0x00000010 /* wired mapping */ +#define PMAP_CANFAIL 0x00000020 /* can fail if resource shortage */ +#define PMAP_MD0 0x00000040 /* Machine dependant */ +#define PMAP_MD1 0x00000080 /* Machine dependant */ +#define PMAP_MD2 0x00000100 /* Machine dependant */ +#define PMAP_MD3 0x00000200 /* Machine dependant */ + +#ifndef PMAP_WC +#define PMAP_WC 0 +#endif + +#ifndef PMAP_PREFER +#define PMAP_PREFER_ALIGN() 0 +#define PMAP_PREFER_OFFSET(off) 0 +#endif + +#ifdef _KERNEL +__BEGIN_DECLS +#ifndef pmap_activate +void pmap_activate(struct proc *); +#endif +#ifndef pmap_deactivate +void pmap_deactivate(struct proc *); +#endif +#ifndef pmap_unwire +void pmap_unwire(pmap_t, vaddr_t); +#endif + +#if !defined(pmap_clear_modify) +boolean_t pmap_clear_modify(struct vm_page *); +#endif +#if !defined(pmap_clear_reference) +boolean_t pmap_clear_reference(struct vm_page *); +#endif + +#if !defined(pmap_copy_page) +void pmap_copy_page(struct vm_page *, struct vm_page *); +#endif +struct pmap *pmap_create(void); +void pmap_destroy(pmap_t); +int pmap_enter(pmap_t, + vaddr_t, paddr_t, vm_prot_t, int); +boolean_t pmap_extract(pmap_t, vaddr_t, paddr_t *); +#if defined(PMAP_GROWKERNEL) +vaddr_t pmap_growkernel(vaddr_t); +#endif + +void pmap_init(void); + +void pmap_kenter_pa(vaddr_t, paddr_t, vm_prot_t); +void pmap_kremove(vaddr_t, vsize_t); +#if !defined(pmap_is_modified) +boolean_t pmap_is_modified(struct vm_page *); +#endif +#if !defined(pmap_is_referenced) +boolean_t pmap_is_referenced(struct vm_page *); +#endif + +void pmap_page_protect(struct vm_page *, vm_prot_t); + +#if !defined(pmap_proc_iflush) +void pmap_proc_iflush(struct process *, vaddr_t, vsize_t); +#endif +void pmap_protect(pmap_t, vaddr_t, vaddr_t, vm_prot_t); +#if !defined(pmap_reference) +void pmap_reference(pmap_t); +#endif +#if !defined(pmap_remove) +void pmap_remove(pmap_t, vaddr_t, vaddr_t); +#endif +#if !defined(pmap_remove_holes) +void pmap_remove_holes(struct vmspace *); +#endif +#if !defined(pmap_update) +void pmap_update(pmap_t); +#endif +#if !defined(pmap_zero_page) +void pmap_zero_page(struct vm_page *); +#endif + +#if defined(PMAP_STEAL_MEMORY) +vaddr_t pmap_steal_memory(vsize_t, vaddr_t *, vaddr_t *); +#else +void pmap_virtual_space(vaddr_t *, vaddr_t *); +#endif + +#if defined(__HAVE_PMAP_POPULATE) +void pmap_populate(pmap_t, vaddr_t); +#endif + +#if defined(__HAVE_PMAP_PURGE) +void pmap_purge(struct proc *); +#endif + +/* nested pmaps are used in i386/amd64 vmm */ +#ifndef pmap_nested +#define pmap_nested(pm) 0 +#endif + +__END_DECLS +#endif /* kernel*/ + +#endif /* _PMAP_VM_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/uvm/uvm_pmemrange.h b/lib/libc/include/generic-openbsd/uvm/uvm_pmemrange.h new file mode 100644 index 0000000000..49af017d96 --- /dev/null +++ b/lib/libc/include/generic-openbsd/uvm/uvm_pmemrange.h @@ -0,0 +1,165 @@ +/* $OpenBSD: uvm_pmemrange.h,v 1.19 2024/11/07 11:12:46 mpi Exp $ */ + +/* + * Copyright (c) 2009 Ariane van der Steldt + * + * 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. + */ + +/* + * uvm_pmemrange.h: describe and manage free physical memory. + */ + +#ifndef _UVM_UVM_PMEMRANGE_H_ +#define _UVM_UVM_PMEMRANGE_H_ + +RBT_HEAD(uvm_pmr_addr, vm_page); +RBT_HEAD(uvm_pmr_size, vm_page); + +/* + * Page types available: + * - DIRTY: this page may contain random data. + * - ZERO: this page has been zeroed. + */ +#define UVM_PMR_MEMTYPE_DIRTY 0 +#define UVM_PMR_MEMTYPE_ZERO 1 +#define UVM_PMR_MEMTYPE_MAX 2 + +/* + * An address range of memory. + */ +struct uvm_pmemrange { + struct uvm_pmr_addr addr; /* Free page chunks, sorted by addr. */ + struct uvm_pmr_size size[UVM_PMR_MEMTYPE_MAX]; + /* Free page chunks, sorted by size. */ + TAILQ_HEAD(, vm_page) single[UVM_PMR_MEMTYPE_MAX]; + /* single page regions (uses pageq) */ + + paddr_t low; /* Start of address range (pgno). */ + paddr_t high; /* End +1 (pgno). */ + int use; /* Use counter. */ + psize_t nsegs; /* Current range count. */ + + TAILQ_ENTRY(uvm_pmemrange) pmr_use; + /* pmr, sorted by use */ + RBT_ENTRY(uvm_pmemrange) pmr_addr; + /* pmr, sorted by address */ +}; + +/* + * Description of failing memory allocation. + * + * Every descriptor corresponds to a request for the page daemon to release + * pages in a given memory range. There is one global descriptor for nowait + * allocations, all others are sitting on the stack of processes waiting for + * physical pages. + * + * There are multiple ways physical pages can become available: + * [1] unmanaged pages are released by shrinkers (bufbackoff(), drmbackoff()...) + * [2] page daemon drops them (we notice because they are freed) + * [3] a process calls free or exit + * + * The buffer cache and page daemon can decide that they don't have the + * ability to make pages available in the requested range. In that case, + * the FAIL bit will be set. + * XXX There's a possibility that a page is no longer on the queues but + * XXX has not yet been freed, or that a page was busy. + * XXX Also, wired pages are not considered for paging, so they could + * XXX cause a failure that may be recoverable. + * + * Locks used to protect struct members in this file: + * F uvm_lock_fpageq + * I immutable after creation + */ +struct uvm_pmalloc { + TAILQ_ENTRY(uvm_pmalloc) pmq; /* [F] next request */ + struct uvm_constraint_range pm_constraint; /* [I] memory range */ + psize_t pm_size; /* [I] # pages */ + int pm_flags; /* [F] states flags */ +}; + +/* + * Indicate to the page daemon that a nowait call failed and it should + * recover at least some memory in the most restricted region (assumed + * to be dma_constraint). + */ +extern struct uvm_pmalloc nowait_pma; /* [F] */ + + +/* + * uvm_pmalloc flags. + */ +#define UVM_PMA_LINKED 0x01 /* uvm_pmalloc is on list */ +#define UVM_PMA_BUSY 0x02 /* entry is busy with fpageq unlocked */ +#define UVM_PMA_FAIL 0x10 /* page daemon cannot free pages */ +#define UVM_PMA_FREED 0x20 /* at least one page in the range was freed */ + +RBT_HEAD(uvm_pmemrange_addr, uvm_pmemrange); +TAILQ_HEAD(uvm_pmemrange_use, uvm_pmemrange); + +/* + * pmr control structure. Contained in uvm.pmr_control. + */ +struct uvm_pmr_control { + struct uvm_pmemrange_addr addr; + struct uvm_pmemrange_use use; + + /* Only changed while fpageq is locked. */ + TAILQ_HEAD(, uvm_pmalloc) allocs; +}; + +void uvm_pmr_freepages(struct vm_page *, psize_t); +void uvm_pmr_freepageq(struct pglist *); +int uvm_pmr_getpages(psize_t, paddr_t, paddr_t, paddr_t, paddr_t, + int, int, struct pglist *); +void uvm_pmr_init(void); +int uvm_wait_pla(paddr_t, paddr_t, paddr_t, int); +void uvm_wakeup_pla(paddr_t, psize_t); + +#if defined(DDB) || defined(DEBUG) +int uvm_pmr_isfree(struct vm_page *pg); +#endif + +/* + * Internal tree logic. + */ + +int uvm_pmr_addr_cmp(const struct vm_page *, const struct vm_page *); +int uvm_pmr_size_cmp(const struct vm_page *, const struct vm_page *); + +RBT_PROTOTYPE(uvm_pmr_addr, vm_page, objt, uvm_pmr_addr_cmp); +RBT_PROTOTYPE(uvm_pmr_size, vm_page, objt, uvm_pmr_size_cmp); +RBT_PROTOTYPE(uvm_pmemrange_addr, uvm_pmemrange, pmr_addr, + uvm_pmemrange_addr_cmp); + +struct vm_page *uvm_pmr_insert_addr(struct uvm_pmemrange *, + struct vm_page *, int); +void uvm_pmr_insert_size(struct uvm_pmemrange *, + struct vm_page *); +struct vm_page *uvm_pmr_insert(struct uvm_pmemrange *, + struct vm_page *, int); +void uvm_pmr_remove_addr(struct uvm_pmemrange *, + struct vm_page *); +void uvm_pmr_remove_size(struct uvm_pmemrange *, + struct vm_page *); +void uvm_pmr_remove(struct uvm_pmemrange *, + struct vm_page *); +struct vm_page *uvm_pmr_extract_range(struct uvm_pmemrange *, + struct vm_page *, paddr_t, paddr_t, + struct pglist *); +struct vm_page *uvm_pmr_cache_get(int); +void uvm_pmr_cache_put(struct vm_page *); +unsigned int uvm_pmr_cache_drain(void); + + +#endif /* _UVM_UVM_PMEMRANGE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/uvm/uvm_swap.h b/lib/libc/include/generic-openbsd/uvm/uvm_swap.h new file mode 100644 index 0000000000..d3eb55d061 --- /dev/null +++ b/lib/libc/include/generic-openbsd/uvm/uvm_swap.h @@ -0,0 +1,58 @@ +/* $OpenBSD: uvm_swap.h,v 1.20 2023/10/27 19:18:53 mpi Exp $ */ +/* $NetBSD: uvm_swap.h,v 1.5 2000/01/11 06:57:51 chs Exp $ */ + +/* + * Copyright (c) 1997 Matthew R. Green + * 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. + * + * from: Id: uvm_swap.h,v 1.1.2.6 1997/12/15 05:39:31 mrg Exp + */ + +#ifndef _UVM_UVM_SWAP_H_ +#define _UVM_UVM_SWAP_H_ + +#define SWCLUSTPAGES (MAXBSIZE >> PAGE_SHIFT) +#define SWSLOT_BAD (-1) + +#ifdef _KERNEL + +int uvm_swap_get(struct vm_page *, int, int); +int uvm_swap_put(int, struct vm_page **, int, int); +int uvm_swap_alloc(int *, boolean_t); +void uvm_swap_free(int, int); +void uvm_swap_markbad(int, int); +int uvm_swapisfilled(void); +int uvm_swapisfull(void); +void uvm_swap_freepages(struct vm_page **, int); +#ifdef HIBERNATE +int uvm_hibswap(dev_t, u_long *, u_long *); +#endif /* HIBERNATE */ +#ifdef UVM_SWAP_ENCRYPT +void uvm_swap_initcrypt_all(void); +void uvm_swap_finicrypt_all(void); +#endif + +#endif /* _KERNEL */ + +#endif /* _UVM_UVM_SWAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/uvm/uvm_swap_encrypt.h b/lib/libc/include/generic-openbsd/uvm/uvm_swap_encrypt.h new file mode 100644 index 0000000000..3b46dfa05b --- /dev/null +++ b/lib/libc/include/generic-openbsd/uvm/uvm_swap_encrypt.h @@ -0,0 +1,85 @@ +/* $OpenBSD: uvm_swap_encrypt.h,v 1.14 2024/11/07 09:04:55 jsg Exp $ */ + +/* + * Copyright 1999 Niels Provos + * 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 Niels Provos. + * 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 _UVM_SWAP_ENCRYPT_H +#define _UVM_SWAP_ENCRYPT_H + +#define SWPENC_ENABLE 0 +#define SWPENC_CREATED 1 +#define SWPENC_DELETED 2 +#define SWPENC_MAXID 3 + +#define CTL_SWPENC_NAMES { \ + { "enable", CTLTYPE_INT }, \ + { "keyscreated", CTLTYPE_INT }, \ + { "keysdeleted", CTLTYPE_INT }, \ +} + +#define SWAP_KEY_SIZE 4 /* 128-bit keys */ + +struct swap_key { + u_int32_t key[SWAP_KEY_SIZE]; /* secret key for swap range */ + u_int16_t refcount; /* pages that still need it */ +}; + +int swap_encrypt_ctl(int *, u_int, void *, size_t *, void *, size_t, + struct proc *); + +void swap_encrypt(struct swap_key *,caddr_t, caddr_t, u_int64_t, size_t); +void swap_decrypt(struct swap_key *,caddr_t, caddr_t, u_int64_t, size_t); + +void swap_key_cleanup(struct swap_key *); +void swap_key_prepare(struct swap_key *, int); + +void swap_key_create(struct swap_key *); +void swap_key_delete(struct swap_key *); + +static inline void +swap_key_get(struct swap_key *key) +{ + if (key->refcount == 0) + swap_key_create(key); + key->refcount++; +} + +static inline void +swap_key_put(struct swap_key *key) +{ + key->refcount--; + if (key->refcount == 0) + swap_key_delete(key); +} + +extern int uvm_doswapencrypt; /* swapencrypt enabled/disabled */ +extern int swap_encrypt_initialized; + +#endif /* _UVM_SWAP_ENCRYPT_H */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/uvm/uvm_vnode.h b/lib/libc/include/generic-openbsd/uvm/uvm_vnode.h new file mode 100644 index 0000000000..37db256a05 --- /dev/null +++ b/lib/libc/include/generic-openbsd/uvm/uvm_vnode.h @@ -0,0 +1,100 @@ +/* $OpenBSD: uvm_vnode.h,v 1.22 2025/09/25 09:05:47 mpi Exp $ */ +/* $NetBSD: uvm_vnode.h,v 1.9 2000/03/26 20:54:48 kleink Exp $ */ + +/* + * + * Copyright (c) 1997 Charles D. Cranor and Washington University. + * 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 Charles D. Cranor and + * Washington University. + * 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. + * + * from: Id: uvm_vnode.h,v 1.1.2.4 1997/10/03 21:18:24 chuck Exp + */ + +#ifndef _UVM_UVM_VNODE_H_ +#define _UVM_UVM_VNODE_H_ + +/* + * uvm_vnode.h + * + * vnode handle into the VM system. + */ + +struct vnode; + +/* + * the uvm_vnode structure. + * + * Locks used to protect struct members in this file: + * I immutable after creation + * K kernel lock + * S uvn_sync_lock + * v u_obj's vmobjlock + */ +struct uvm_vnode { + struct uvm_object u_obj; /* the actual VM object */ + struct vnode *u_vnode; /* [I] pointer back to vnode */ + int u_flags; /* [v] flags */ + int u_nio; /* [v] number of running I/O requests */ + voff_t u_size; /* [v] size of object */ + + LIST_ENTRY(uvm_vnode) u_wlist; /* [K] list of writeable vnode objs */ + + SIMPLEQ_ENTRY(uvm_vnode) u_syncq; /* [S] vnode objs due for a "sync" */ +}; + +/* + * u_flags values + */ +#define UVM_VNODE_VALID 0x001 /* we are attached to the vnode */ +#define UVM_VNODE_CANPERSIST 0x002 /* we can persist after ref == 0 */ +#define UVM_VNODE_ALOCK 0x004 /* uvn_attach is locked out */ +#define UVM_VNODE_DYING 0x008 /* final detach/terminate in + progress */ +#define UVM_VNODE_RELKILL 0x010 /* uvn should be killed by releasepg + when final i/o is done */ +#define UVM_VNODE_WANTED 0x020 /* someone is waiting for alock, + dying, or relkill to clear */ +#define UVM_VNODE_VNISLOCKED 0x040 /* underlying vnode struct is locked + (valid when DYING is true) */ +#define UVM_VNODE_IOSYNC 0x080 /* I/O sync in progress ... setter + sleeps on &uvn->u_nio */ +#define UVM_VNODE_IOSYNCWANTED 0x100 /* a process is waiting for the + i/o sync to clear so it can do + i/o */ +#define UVM_VNODE_WRITEABLE 0x200 /* uvn has pages that are writeable */ + +/* + * UVM_VNODE_BLOCKED: any condition that should new processes from + * touching the vnode [set WANTED and sleep to wait for it to clear] + */ +#define UVM_VNODE_BLOCKED (UVM_VNODE_ALOCK|UVM_VNODE_DYING|UVM_VNODE_RELKILL) + +void uvm_vnp_obj_alloc(struct vnode *); +void uvm_vnp_terminate(struct vnode *); + +#endif /* _UVM_UVM_VNODE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/uvm/uvmexp.h b/lib/libc/include/generic-openbsd/uvm/uvmexp.h new file mode 100644 index 0000000000..54fcb47a9d --- /dev/null +++ b/lib/libc/include/generic-openbsd/uvm/uvmexp.h @@ -0,0 +1,203 @@ +/* $OpenBSD: uvmexp.h,v 1.19 2025/03/10 19:52:57 miod Exp $ */ + +#ifndef _UVM_UVMEXP_ +#define _UVM_UVMEXP_ + +/* + * CTL_VM identifiers + */ +#define VM_METER 1 /* struct vmmeter */ +#define VM_LOADAVG 2 /* struct loadavg */ +#define VM_PSSTRINGS 3 /* PSSTRINGS */ +#define VM_UVMEXP 4 /* struct uvmexp */ +#define VM_SWAPENCRYPT 5 /* int */ +#define VM_NKMEMPAGES 6 /* int - # kmem_map pages */ +#define VM_ANONMIN 7 +#define VM_VTEXTMIN 8 +#define VM_VNODEMIN 9 +#define VM_MAXSLP 10 +#define VM_USPACE 11 +#define VM_MALLOC_CONF 12 /* config for userland malloc */ +#define VM_MAXID 13 /* number of valid vm ids */ + +#define CTL_VM_NAMES { \ + { 0, 0 }, \ + { "vmmeter", CTLTYPE_STRUCT }, \ + { "loadavg", CTLTYPE_STRUCT }, \ + { "psstrings", CTLTYPE_STRUCT }, \ + { "uvmexp", CTLTYPE_STRUCT }, \ + { "swapencrypt", CTLTYPE_NODE }, \ + { "nkmempages", CTLTYPE_INT }, \ + { "anonmin", CTLTYPE_INT }, \ + { "vtextmin", CTLTYPE_INT }, \ + { "vnodemin", CTLTYPE_INT }, \ + { "maxslp", CTLTYPE_INT }, \ + { "uspace", CTLTYPE_INT }, \ + { "malloc_conf", CTLTYPE_STRING }, \ +} + +/* + * uvmexp: global data structures that are exported to parts of the kernel + * other than the vm system. + * + * Locks used to protect struct members in this file: + * a atomic operations + * I immutable after creation + * K kernel lock + * F uvm_lock_fpageq + * L uvm_lock_pageq + * S uvm_swap_data_lock + * p copy of per-CPU counters, used only by userland. + */ +struct uvmexp { + /* vm_page constants */ + int pagesize; /* size of a page (PAGE_SIZE): must be power of 2 */ + int pagemask; /* page mask */ + int pageshift; /* page shift */ + + /* vm_page counters */ + int npages; /* [I] number of pages we manage */ + int free; /* [F] number of free pages */ + int active; /* [L] # of active pages */ + int inactive; /* [L] # of pages that we free'd but may want back */ + int paging; /* [a] # of pages in the process of being paged out */ + int wired; /* [a] number of wired pages */ + + int zeropages; /* [F] number of zero'd pages */ + int reserve_pagedaemon; /* [I] # of pages reserved for pagedaemon */ + int reserve_kernel; /* [I] # of pages reserved for kernel */ + int percpucaches; /* [a] # of pages in per-CPU caches */ + int vnodepages; /* XXX # of pages used by vnode page cache */ + int vtextpages; /* XXX # of pages used by vtext vnodes */ + + /* pageout params */ + int freemin; /* [I] min number of free pages */ + int freetarg; /* [I] target number of free pages */ + int inactarg; /* target number of inactive pages */ + int wiredmax; /* [I] max number of wired pages */ + int anonmin; /* min threshold for anon pages */ + int vtextmin; /* min threshold for vtext pages */ + int vnodemin; /* min threshold for vnode pages */ + int anonminpct; /* min percent anon pages */ + int vtextminpct;/* min percent vtext pages */ + int vnodeminpct;/* min percent vnode pages */ + + /* swap */ + int nswapdev; /* [S] number of configured swap devices in system */ + int swpages; /* [S] number of PAGE_SIZE'ed swap pages */ + int swpginuse; /* [S] number of swap pages in use */ + int swpgonly; /* [a] number of swap pages in use, not also in RAM */ + int nswget; /* [a] number of swap pages moved from disk to RAM */ + int nanon; /* XXX number total of anon's in system */ + int unused05; /* formerly nanonneeded */ + int unused06; /* formerly nfreeanon */ + + /* stat counters */ + int faults; /* [p] page fault count */ + int traps; /* trap count */ + int intrs; /* interrupt count */ + int swtch; /* context switch count */ + int softs; /* software interrupt count */ + int syscalls; /* system calls */ + int pageins; /* [p] pagein operation count */ + /* pageouts are in pdpageouts below */ + int pcphit; /* [a] # of pagealloc from per-CPU cache */ + int pcpmiss; /* [a] # of times a per-CPU cache was empty */ + int pgswapin; /* pages swapped in */ + int pgswapout; /* pages swapped out */ + int forks; /* forks */ + int forks_ppwait; /* forks where parent waits */ + int forks_sharevm; /* forks where vmspace is shared */ + int pga_zerohit; /* pagealloc where zero wanted and zero + was available */ + int pga_zeromiss; /* pagealloc where zero wanted and zero + not available */ + int unused09; /* formerly zeroaborts */ + + /* fault subcounters */ + int fltnoram; /* [p] # of times fault was out of ram */ + int fltnoanon; /* [p] # of times fault was out of anons */ + int fltnoamap; /* [p] # of times fault was out of amap chunks */ + int fltpgwait; /* [p] # of times fault had to wait on a page */ + int fltpgrele; /* [p] # of times fault found a released page */ + int fltrelck; /* [p] # of times fault relock is a success */ + int fltnorelck; /* [p] # of times fault relock failed */ + int fltanget; /* [p] # of times fault gets anon page */ + int fltanretry; /* [p] # of times fault retrys an anon get */ + int fltamcopy; /* [p] # of times fault clears "needs copy" */ + int fltnamap; /* [p] # of times fault maps a neighbor anon page */ + int fltnomap; /* [p] # of times fault maps a neighbor obj page */ + int fltlget; /* [p] # of times fault does a locked pgo_get */ + int fltget; /* [p] # of times fault does an unlocked get */ + int flt_anon; /* [p] # of times fault anon (case 1a) */ + int flt_acow; /* [p] # of times fault anon cow (case 1b) */ + int flt_obj; /* [p] # of times fault is on object page (2a) */ + int flt_prcopy; /* [p] # of times fault promotes with copy (2b) */ + int flt_przero; /* [p] # of times fault promotes with zerofill (2b) */ + int fltup; /* [p] # of times fault upgrade is a success */ + int fltnoup; /* [p] # of times fault upgrade failed */ + + /* daemon counters */ + int pdwoke; /* [F] # of times daemon woke up */ + int pdrevs; /* number of times daemon scanned for free pages */ + int pdswout; /* number of times daemon called for swapout */ + int pdfreed; /* number of pages daemon freed since boot */ + int pdscans; /* number of pages daemon scanned since boot */ + int pdanscan; /* number of anonymous pages scanned by daemon */ + int pdobscan; /* number of object pages scanned by daemon */ + int pdreact; /* number of pages daemon reactivated since boot */ + int pdbusy; /* number of times daemon found a busy page */ + int pdpageouts; /* number of times daemon started a pageout */ + int pdpending; /* number of times daemon got a pending pagout */ + int pddeact; /* number of pages daemon deactivates */ + + int unused13; /* formerly pdrevtext */ + + int fpswtch; /* FPU context switches */ + int kmapent; /* number of kernel map entries */ +}; + +struct _ps_strings { + void *val; +}; + +#ifdef _KERNEL + +/* + * Per-cpu UVM counters. + */ +extern struct cpumem *uvmexp_counters; + +enum uvm_exp_counters { + /* stat counters */ + faults, /* page fault count */ + pageins, /* pagein operation count */ + + /* fault subcounters */ + flt_noram, /* number of times fault was out of ram */ + flt_noanon, /* number of times fault was out of anons */ + flt_noamap, /* number of times fault was out of amap chunks */ + flt_pgwait, /* number of times fault had to wait on a page */ + flt_pgrele, /* number of times fault found a released page */ + flt_relck, /* number of times fault relock is a success */ + flt_norelck, /* number of times fault relock failed */ + flt_anget, /* number of times fault gets anon page */ + flt_anretry, /* number of times fault retrys an anon get */ + flt_amcopy, /* number of times fault clears "needs copy" */ + flt_namap, /* number of times fault maps a neighbor anon page */ + flt_nomap, /* number of times fault maps a neighbor obj page */ + flt_lget, /* number of times fault does a locked pgo_get */ + flt_get, /* number of times fault does an unlocked get */ + flt_anon, /* number of times fault anon (case 1a) */ + flt_acow, /* number of times fault anon cow (case 1b) */ + flt_obj, /* number of times fault is on object page (2a) */ + flt_prcopy, /* number of times fault promotes with copy (2b) */ + flt_przero, /* number of times fault promotes with zerofill (2b) */ + flt_up, /* number of times fault upgrade is a success */ + flt_noup, /* number of times fault upgrade failed */ + + exp_ncounters +}; + +#endif /* _KERNEL */ +#endif /*_UVM_UVMEXP_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/varargs.h b/lib/libc/include/generic-openbsd/varargs.h new file mode 100644 index 0000000000..0f3d2c690a --- /dev/null +++ b/lib/libc/include/generic-openbsd/varargs.h @@ -0,0 +1,51 @@ +/* $OpenBSD: varargs.h,v 1.4 2020/07/21 23:09:00 daniel Exp $ */ +/* + * Copyright (c) 2003, 2004 Marc espie + * + * 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 _VARARGS_H_ +#define _VARARGS_H_ + +/* These macros implement traditional (non-ANSI) varargs + for GNU C. */ + +#define va_alist __builtin_va_alist + +#define __va_ellipsis ... + +/* ??? We don't process attributes correctly in K&R argument context. */ +typedef int __builtin_va_alist_t __attribute__((__mode__(__word__))); + +/* ??? It would be nice to get rid of the ellipsis here. It causes + current_function_varargs to be set in cc1. */ +#define va_dcl __builtin_va_alist_t __builtin_va_alist; ... + +/* Define __gnuc_va_list, just as in stdarg.h. */ + +#ifndef __GNUC_VA_LIST +#define __GNUC_VA_LIST +typedef __builtin_va_list __gnuc_va_list; +#endif + +#define va_start(v) __builtin_varargs_start((v)) +#define va_end __builtin_va_end +#define va_arg __builtin_va_arg +#define __va_copy(d,s) __builtin_va_copy((d),(s)) + +/* Define va_list from __gnuc_va_list. */ + +typedef __gnuc_va_list va_list; + +#endif /* _VARARGS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/vis.h b/lib/libc/include/generic-openbsd/vis.h new file mode 100644 index 0000000000..132089a724 --- /dev/null +++ b/lib/libc/include/generic-openbsd/vis.h @@ -0,0 +1,93 @@ +/* $OpenBSD: vis.h,v 1.15 2015/07/20 01:52:27 millert Exp $ */ +/* $NetBSD: vis.h,v 1.4 1994/10/26 00:56:41 cgd Exp $ */ + +/*- + * Copyright (c) 1990 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. + * + * @(#)vis.h 5.9 (Berkeley) 4/3/91 + */ + +#ifndef _VIS_H_ +#define _VIS_H_ + +/* + * to select alternate encoding format + */ +#define VIS_OCTAL 0x01 /* use octal \ddd format */ +#define VIS_CSTYLE 0x02 /* use \[nrft0..] where appropriate */ + +/* + * to alter set of characters encoded (default is to encode all + * non-graphic except space, tab, and newline). + */ +#define VIS_SP 0x04 /* also encode space */ +#define VIS_TAB 0x08 /* also encode tab */ +#define VIS_NL 0x10 /* also encode newline */ +#define VIS_WHITE (VIS_SP | VIS_TAB | VIS_NL) +#define VIS_SAFE 0x20 /* only encode "unsafe" characters */ +#define VIS_DQ 0x200 /* backslash-escape double quotes */ +#define VIS_ALL 0x400 /* encode all characters */ + +/* + * other + */ +#define VIS_NOSLASH 0x40 /* inhibit printing '\' */ +#define VIS_GLOB 0x100 /* encode glob(3) magics and '#' */ + +/* + * unvis return codes + */ +#define UNVIS_VALID 1 /* character valid */ +#define UNVIS_VALIDPUSH 2 /* character valid, push back passed char */ +#define UNVIS_NOCHAR 3 /* valid sequence, no character produced */ +#define UNVIS_SYNBAD -1 /* unrecognized escape sequence */ +#define UNVIS_ERROR -2 /* decoder in unknown state (unrecoverable) */ + +/* + * unvis flags + */ +#define UNVIS_END 1 /* no more characters */ + +#include + +__BEGIN_DECLS +char *vis(char *, int, int, int); +int strvis(char *, const char *, int); +int stravis(char **, const char *, int); +int strnvis(char *, const char *, size_t, int) + __attribute__ ((__bounded__(__string__,1,3))); +int strvisx(char *, const char *, size_t, int) + __attribute__ ((__bounded__(__string__,1,3))); +int strunvis(char *, const char *); +int unvis(char *, char, int *, int); +ssize_t strnunvis(char *, const char *, size_t) + __attribute__ ((__bounded__(__string__,1,3))); + +__END_DECLS + +#endif /* !_VIS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/wchar.h b/lib/libc/include/generic-openbsd/wchar.h new file mode 100644 index 0000000000..bfcefc4340 --- /dev/null +++ b/lib/libc/include/generic-openbsd/wchar.h @@ -0,0 +1,253 @@ +/* $OpenBSD: wchar.h,v 1.34 2025/07/16 15:33:05 yasuoka Exp $ */ +/* $NetBSD: wchar.h,v 1.16 2003/03/07 07:11:35 tshiozak Exp $ */ + +/*- + * Copyright (c)1999 Citrus Project, + * 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 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 AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/*- + * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Julian Coleman. + * + * 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 _WCHAR_H_ +#define _WCHAR_H_ + +#include +#include +#include + +#ifndef _STDFILES_DECLARED +#define _STDFILES_DECLARED +typedef struct __sFILE FILE; +struct __sFstub { long _stub; }; + +__BEGIN_DECLS +extern struct __sFstub __stdin[]; +extern struct __sFstub __stdout[]; +extern struct __sFstub __stderr[]; +__END_DECLS +#endif + +#if !defined(_WCHAR_T_DEFINED_) && !defined(__cplusplus) +#define _WCHAR_T_DEFINED_ +typedef __wchar_t wchar_t; +#endif + +#ifndef _MBSTATE_T_DEFINED_ +#define _MBSTATE_T_DEFINED_ +typedef __mbstate_t mbstate_t; +#endif + +#ifndef _WINT_T_DEFINED_ +#define _WINT_T_DEFINED_ +typedef __wint_t wint_t; +#endif + +#ifndef _SIZE_T_DEFINED_ +#define _SIZE_T_DEFINED_ +typedef __size_t size_t; +#endif + +#ifndef WEOF +#define WEOF ((wint_t)-1) +#endif + +#ifndef WCHAR_MIN +#define WCHAR_MIN (-0x7fffffff - 1) +#endif +#ifndef WCHAR_MAX +#define WCHAR_MAX 0x7fffffff +#endif + +#if __POSIX_VISIBLE >= 200809 +#ifndef _LOCALE_T_DEFINED_ +#define _LOCALE_T_DEFINED_ +typedef void *locale_t; +#endif +#endif + +__BEGIN_DECLS +wint_t btowc(int); +size_t mbrlen(const char * __restrict, size_t, mbstate_t * __restrict); +size_t mbrtowc(wchar_t * __restrict, const char * __restrict, size_t, + mbstate_t * __restrict); +int mbsinit(const mbstate_t *); +size_t mbsrtowcs(wchar_t * __restrict, const char ** __restrict, size_t, + mbstate_t * __restrict) + __attribute__ ((__bounded__(__wcstring__,1,3))); +size_t wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict); +wchar_t *wcscat(wchar_t * __restrict, const wchar_t * __restrict); +wchar_t *wcschr(const wchar_t *, wchar_t); +int wcscmp(const wchar_t *, const wchar_t *); +int wcscoll(const wchar_t *, const wchar_t *); +wchar_t *wcscpy(wchar_t * __restrict, const wchar_t * __restrict); +size_t wcscspn(const wchar_t *, const wchar_t *); +size_t wcslen(const wchar_t *); +wchar_t *wcsncat(wchar_t * __restrict, const wchar_t * __restrict, + size_t) + __attribute__ ((__bounded__(__wcstring__,1,3))); +int wcsncmp(const wchar_t *, const wchar_t *, size_t); +wchar_t *wcsncpy(wchar_t * __restrict , const wchar_t * __restrict, + size_t) + __attribute__ ((__bounded__(__wcstring__,1,3))); +wchar_t *wcspbrk(const wchar_t *, const wchar_t *); +wchar_t *wcsrchr(const wchar_t *, wchar_t); +size_t wcsrtombs(char * __restrict, const wchar_t ** __restrict, size_t, + mbstate_t * __restrict) + __attribute__ ((__bounded__(__wcstring__,1,3))); +size_t wcsspn(const wchar_t *, const wchar_t *); +wchar_t *wcsstr(const wchar_t *, const wchar_t *); +wchar_t *wcstok(wchar_t * __restrict, const wchar_t * __restrict, + wchar_t ** __restrict); +size_t wcsxfrm(wchar_t *, const wchar_t *, size_t); +wchar_t *wcswcs(const wchar_t *, const wchar_t *); +wchar_t *wmemchr(const wchar_t *, wchar_t, size_t); +int wmemcmp(const wchar_t *, const wchar_t *, size_t); +wchar_t *wmemcpy(wchar_t * __restrict, const wchar_t * __restrict, + size_t) + __attribute__ ((__bounded__(__wcstring__,1,3))) + __attribute__ ((__bounded__(__wcstring__,2,3))); +wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t) + __attribute__ ((__bounded__(__wcstring__,1,3))) + __attribute__ ((__bounded__(__wcstring__,2,3))); +wchar_t *wmemset(wchar_t *, wchar_t, size_t) + __attribute__ ((__bounded__(__wcstring__,1,3))); + +int wcswidth(const wchar_t *, size_t); +int wctob(wint_t); +int wcwidth(wchar_t); + +double wcstod(const wchar_t * __restrict, wchar_t ** __restrict); +long int wcstol(const wchar_t * __restrict, wchar_t ** __restrict, int base); +unsigned long int wcstoul(const wchar_t * __restrict, wchar_t ** __restrict, + int base); + +#if __POSIX_VISIBLE >= 200809 +FILE *open_wmemstream(wchar_t **, size_t *); + +int wcscoll_l(const wchar_t *, const wchar_t *, locale_t); +wchar_t *wcsdup(const wchar_t *); +int wcscasecmp(const wchar_t *, const wchar_t *); +int wcscasecmp_l(const wchar_t *, const wchar_t *, locale_t); +size_t wcsnlen(const wchar_t *, size_t); +int wcsncasecmp(const wchar_t *, const wchar_t *, size_t); +int wcsncasecmp_l(const wchar_t *, const wchar_t *, size_t, locale_t); +size_t wcsxfrm_l(wchar_t *, const wchar_t *, size_t, locale_t); + +size_t mbsnrtowcs(wchar_t * __restrict, const char ** __restrict, size_t, + size_t, mbstate_t * __restrict) + __attribute__ ((__bounded__(__wcstring__,1,4))); +size_t wcsnrtombs(char * __restrict, const wchar_t ** __restrict, size_t, + size_t, mbstate_t * __restrict) + __attribute__ ((__bounded__(__wcstring__,1,4))); +#endif + +#if __ISO_C_VISIBLE >= 1999 +float wcstof(const wchar_t * __restrict, wchar_t ** __restrict); +long double wcstold(const wchar_t * __restrict, wchar_t ** __restrict); + +struct tm; +size_t wcsftime(wchar_t * __restrict, size_t, const wchar_t *__restrict, + const struct tm *__restrict); +#endif + +#if !defined(__STRICT_ANSI__) || __ISO_C_VISIBLE >= 1999 +long long int wcstoll(const wchar_t * __restrict, + wchar_t ** __restrict, int base); +unsigned long long int wcstoull(const wchar_t * __restrict, + wchar_t ** __restrict, int base); +#endif + +wint_t ungetwc(wint_t, FILE *); +wint_t fgetwc(FILE *); +wchar_t *fgetws(wchar_t * __restrict, int, FILE * __restrict) + __attribute__ ((__bounded__(__wcstring__,1,2))); +wint_t getwc(FILE *); +wint_t getwchar(void); +wint_t fputwc(wchar_t, FILE *); +int fputws(const wchar_t * __restrict, FILE * __restrict); +wint_t putwc(wchar_t, FILE *); +wint_t putwchar(wchar_t); + +int fwide(FILE *, int); + +int fwprintf(FILE * __restrict, const wchar_t * __restrict, ...); +int swprintf(wchar_t * __restrict, size_t, const wchar_t * __restrict, ...); +int vfwprintf(FILE * __restrict, const wchar_t * __restrict, __va_list); +int vswprintf(wchar_t * __restrict, size_t, const wchar_t * __restrict, + __va_list); +int vwprintf(const wchar_t * __restrict, __va_list); +int wprintf(const wchar_t * __restrict, ...); + +int fwscanf(FILE * __restrict, const wchar_t * __restrict, ...); +int swscanf(const wchar_t * __restrict, const wchar_t * __restrict, ...); +int vfwscanf(FILE * __restrict, const wchar_t * __restrict, __va_list); +int vswscanf(const wchar_t * __restrict, const wchar_t * __restrict, __va_list); +int vwscanf(const wchar_t * __restrict, __va_list); +int wscanf(const wchar_t * __restrict, ...); + +#if __POSIX_VISIBLE >= 202405 || __BSD_VISIBLE +size_t wcslcat(wchar_t * __restrict, const wchar_t * __restrict, size_t) + __attribute__ ((__bounded__(__wcstring__,1,3))); +size_t wcslcpy(wchar_t * __restrict, const wchar_t * __restrict, size_t) + __attribute__ ((__bounded__(__wcstring__,1,3))); +#endif + +#if __BSD_VISIBLE +wchar_t *fgetwln(FILE * __restrict, size_t * __restrict); +#endif + +#define getwc(f) fgetwc(f) +#define getwchar() getwc((FILE *)__stdin) +#define putwc(wc, f) fputwc((wc), (f)) +#define putwchar(wc) putwc((wc), (FILE *)__stdout) +__END_DECLS + +#endif /* !_WCHAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/generic-openbsd/wctype.h b/lib/libc/include/generic-openbsd/wctype.h new file mode 100644 index 0000000000..0d95b5fb2c --- /dev/null +++ b/lib/libc/include/generic-openbsd/wctype.h @@ -0,0 +1,107 @@ +/* $OpenBSD: wctype.h,v 1.6 2017/09/05 03:16:13 schwarze Exp $ */ +/* $NetBSD: wctype.h,v 1.5 2003/03/02 22:18:11 tshiozak Exp $ */ + +/*- + * Copyright (c)1999 Citrus Project, + * 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 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 AUTHOR 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. + * + * citrus Id: wctype.h,v 1.4 2000/12/21 01:50:21 itojun Exp + */ + +#ifndef _WCTYPE_H_ +#define _WCTYPE_H_ + +#include +#include + +#ifndef _WINT_T_DEFINED_ +#define _WINT_T_DEFINED_ +typedef __wint_t wint_t; +#endif + +#ifndef _WCTRANS_T_DEFINED_ +#define _WCTRANS_T_DEFINED_ +typedef __wctrans_t wctrans_t; +#endif + +#ifndef _WCTYPE_T_DEFINED_ +#define _WCTYPE_T_DEFINED_ +typedef __wctype_t wctype_t; +#endif + +#ifndef WEOF +#define WEOF ((wint_t)-1) +#endif + +#if __POSIX_VISIBLE >= 200809 +#ifndef _LOCALE_T_DEFINED_ +#define _LOCALE_T_DEFINED_ +typedef void *locale_t; +#endif +#endif + +__BEGIN_DECLS +int iswalnum(wint_t); +int iswalpha(wint_t); +int iswblank(wint_t); +int iswcntrl(wint_t); +int iswdigit(wint_t); +int iswgraph(wint_t); +int iswlower(wint_t); +int iswprint(wint_t); +int iswpunct(wint_t); +int iswspace(wint_t); +int iswupper(wint_t); +int iswxdigit(wint_t); +int iswctype(wint_t, wctype_t); +wint_t towctrans(wint_t, wctrans_t); +wint_t towlower(wint_t); +wint_t towupper(wint_t); +wctrans_t wctrans(const char *); +wctype_t wctype(const char *); + +#if __POSIX_VISIBLE >= 200809 +int iswalnum_l(wint_t, locale_t); +int iswalpha_l(wint_t, locale_t); +int iswblank_l(wint_t, locale_t); +int iswcntrl_l(wint_t, locale_t); +int iswdigit_l(wint_t, locale_t); +int iswgraph_l(wint_t, locale_t); +int iswlower_l(wint_t, locale_t); +int iswprint_l(wint_t, locale_t); +int iswpunct_l(wint_t, locale_t); +int iswspace_l(wint_t, locale_t); +int iswupper_l(wint_t, locale_t); +int iswxdigit_l(wint_t, locale_t); +int iswctype_l(wint_t, wctype_t, locale_t); +wint_t towctrans_l(wint_t, wctrans_t, locale_t); +wint_t towlower_l(wint_t, locale_t); +wint_t towupper_l(wint_t, locale_t); +wctrans_t wctrans_l(const char *, locale_t); +wctype_t wctype_l(const char *, locale_t); +#endif + +__END_DECLS + +#endif /* _WCTYPE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/frame.h b/lib/libc/include/mips64-openbsd-none/frame.h new file mode 100644 index 0000000000..f8295979a3 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/frame.h @@ -0,0 +1,3 @@ +/* $OpenBSD: frame.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/_types.h b/lib/libc/include/mips64-openbsd-none/machine/_types.h new file mode 100644 index 0000000000..12dbcd35ee --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/_types.h @@ -0,0 +1,3 @@ +/* $OpenBSD: _types.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/asm.h b/lib/libc/include/mips64-openbsd-none/machine/asm.h new file mode 100644 index 0000000000..a7660ee641 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/asm.h @@ -0,0 +1,9 @@ +/* $OpenBSD: asm.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ + +#ifdef MULTIPROCESSOR +#define HW_GET_CPU_INFO(ci, tmp) \ + dmfc0 ci, COP_0_ERROR_PC +#endif + +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/atomic.h b/lib/libc/include/mips64-openbsd-none/machine/atomic.h new file mode 100644 index 0000000000..1d56c3a000 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/atomic.h @@ -0,0 +1,45 @@ +/* $OpenBSD: atomic.h,v 1.3 2020/07/08 15:53:59 visa Exp $ */ + +/* + * Copyright (c) 2017 Visa Hankala + * + * Permission to use, copy, modify, and/or 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 _OCTEON_ATOMIC_H_ +#define _OCTEON_ATOMIC_H_ + +#ifdef _KERNEL + +static inline void +octeon_syncw(void) +{ + __asm__ volatile ( + " .set push\n" + " .set arch=octeon\n" + /* Issue the barrier twice to work around CN3xxx erratum Core-401. + * A single syncw might not enforce write ordering properly. */ + " syncw\n" + " syncw\n" + " .set pop\n" + : : : "memory"); +} + +#define membar_consumer() __asm__ volatile ("" : : : "memory") +#define membar_producer() octeon_syncw() + +#endif /* _KERNEL */ + +#include + +#endif /* !_OCTEON_ATOMIC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/autoconf.h b/lib/libc/include/mips64-openbsd-none/machine/autoconf.h new file mode 100644 index 0000000000..0b9aa66be9 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/autoconf.h @@ -0,0 +1,58 @@ +/* $OpenBSD: autoconf.h,v 1.4 2019/07/12 03:03:48 visa Exp $ */ + +/* + * Copyright (c) 2001-2003 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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. + * + */ + +/* + * Definitions used by autoconfiguration. + */ + +#ifndef _MACHINE_AUTOCONF_H_ +#define _MACHINE_AUTOCONF_H_ + +#include + +struct mainbus_attach_args { + const char *maa_name; +}; + +extern struct device *bootdv; +extern char bootdev[]; +extern char uboot_rootdev[]; +extern enum devclass bootdev_class; + +#include + +void com_fdt_init_cons(void); +void parse_uboot_root(const char *); + +extern unsigned int octeon_ver; +#define OCTEON_1 0 +#define OCTEON_PLUS 1 +#define OCTEON_2 2 +#define OCTEON_3 3 + +#endif /* _MACHINE_AUTOCONF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/bus.h b/lib/libc/include/mips64-openbsd-none/machine/bus.h new file mode 100644 index 0000000000..257157af06 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/bus.h @@ -0,0 +1,510 @@ +/* $OpenBSD: bus.h,v 1.8 2020/04/14 17:35:28 kettenis Exp $ */ + +/* + * Copyright (c) 2003-2004 Opsycon AB Sweden. 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_BUS_H_ +#define _MACHINE_BUS_H_ + +#ifdef __STDC__ +#define CAT(a,b) a##b +#define CAT3(a,b,c) a##b##c +#else +#define CAT(a,b) a/**/b +#define CAT3(a,b,c) a/**/b/**/c +#endif + +/* + * Bus access types. + */ +struct mips_bus_space; +typedef u_long bus_addr_t; +typedef u_long bus_size_t; +typedef u_long bus_space_handle_t; +typedef struct mips_bus_space *bus_space_tag_t; +typedef struct mips_bus_space bus_space_t; + +struct mips_bus_space { + bus_addr_t bus_base; + void *bus_private; + u_int8_t (*_space_read_1)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_1)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int8_t); + u_int16_t (*_space_read_2)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_2)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int16_t); + u_int32_t (*_space_read_4)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_4)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int32_t); + u_int64_t (*_space_read_8)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_8)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int64_t); + void (*_space_read_raw_2)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, u_int8_t *, bus_size_t); + void (*_space_write_raw_2)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const u_int8_t *, bus_size_t); + void (*_space_read_raw_4)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, u_int8_t *, bus_size_t); + void (*_space_write_raw_4)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const u_int8_t *, bus_size_t); + void (*_space_read_raw_8)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, u_int8_t *, bus_size_t); + void (*_space_write_raw_8)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const u_int8_t *, bus_size_t); + int (*_space_map)(bus_space_tag_t , bus_addr_t, + bus_size_t, int, bus_space_handle_t *); + void (*_space_unmap)(bus_space_tag_t, bus_space_handle_t, + bus_size_t); + int (*_space_subregion)(bus_space_tag_t, bus_space_handle_t, + bus_size_t, bus_size_t, bus_space_handle_t *); + void * (*_space_vaddr)(bus_space_tag_t, bus_space_handle_t); +}; + +#define bus_space_read_1(t, h, o) (*(t)->_space_read_1)((t), (h), (o)) +#define bus_space_read_2(t, h, o) (*(t)->_space_read_2)((t), (h), (o)) +#define bus_space_read_4(t, h, o) (*(t)->_space_read_4)((t), (h), (o)) +#define bus_space_read_8(t, h, o) (*(t)->_space_read_8)((t), (h), (o)) + +#define bus_space_write_1(t, h, o, v) (*(t)->_space_write_1)((t), (h), (o), (v)) +#define bus_space_write_2(t, h, o, v) (*(t)->_space_write_2)((t), (h), (o), (v)) +#define bus_space_write_4(t, h, o, v) (*(t)->_space_write_4)((t), (h), (o), (v)) +#define bus_space_write_8(t, h, o, v) (*(t)->_space_write_8)((t), (h), (o), (v)) + +#define bus_space_read_raw_multi_2(t, h, a, b, l) \ + (*(t)->_space_read_raw_2)((t), (h), (a), (b), (l)) +#define bus_space_read_raw_multi_4(t, h, a, b, l) \ + (*(t)->_space_read_raw_4)((t), (h), (a), (b), (l)) +#define bus_space_read_raw_multi_8(t, h, a, b, l) \ + (*(t)->_space_read_raw_8)((t), (h), (a), (b), (l)) + +#define bus_space_write_raw_multi_2(t, h, a, b, l) \ + (*(t)->_space_write_raw_2)((t), (h), (a), (b), (l)) +#define bus_space_write_raw_multi_4(t, h, a, b, l) \ + (*(t)->_space_write_raw_4)((t), (h), (a), (b), (l)) +#define bus_space_write_raw_multi_8(t, h, a, b, l) \ + (*(t)->_space_write_raw_8)((t), (h), (a), (b), (l)) + +#define bus_space_map(t, o, s, c, p) (*(t)->_space_map)((t), (o), (s), (c), (p)) +#define bus_space_unmap(t, h, s) (*(t)->_space_unmap)((t), (h), (s)) +#define bus_space_subregion(t, h, o, s, p) \ + (*(t)->_space_subregion)((t), (h), (o), (s), (p)) + +#define BUS_SPACE_MAP_CACHEABLE 0x01 +#define BUS_SPACE_MAP_KSEG0 0x02 +#define BUS_SPACE_MAP_LINEAR 0x04 +#define BUS_SPACE_MAP_PREFETCHABLE 0x08 + +#define bus_space_vaddr(t, h) (*(t)->_space_vaddr)((t), (h)) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_multi(n,m) \ +static __inline void \ +CAT(bus_space_read_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_size_t o, CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) \ + *x++ = CAT(bus_space_read_,n)(bst, bsh, o); \ +} + +bus_space_read_multi(1,8) +bus_space_read_multi(2,16) +bus_space_read_multi(4,32) +bus_space_read_multi(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_region(n,m) \ +static __inline void \ +CAT(bus_space_read_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) { \ + *x++ = CAT(bus_space_read_,n)(bst, bsh, ba); \ + ba += (n); \ + } \ +} + +bus_space_read_region(1,8) +bus_space_read_region(2,16) +bus_space_read_region(4,32) +bus_space_read_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_raw_region(n,m) \ +static __inline void \ +CAT(bus_space_read_raw_region_,n)(bus_space_tag_t bst, \ + bus_space_handle_t bsh, \ + bus_addr_t ba, u_int8_t *x, size_t cnt) \ +{ \ + cnt >>= ((n) >> 1); \ + while (cnt--) { \ + CAT(bus_space_read_raw_multi_,n)(bst, bsh, ba, x, (n)); \ + ba += (n); \ + x += (n); \ + } \ +} + +bus_space_read_raw_region(2,16) +bus_space_read_raw_region(4,32) +bus_space_read_raw_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_multi(n,m) \ +static __inline void \ +CAT(bus_space_write_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_size_t o, const CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) \ + CAT(bus_space_write_,n)(bst, bsh, o, *x++); \ +} + +bus_space_write_multi(1,8) +bus_space_write_multi(2,16) +bus_space_write_multi(4,32) +bus_space_write_multi(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_region(n,m) \ +static __inline void \ +CAT(bus_space_write_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, const CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) { \ + CAT(bus_space_write_,n)(bst, bsh, ba, *x++); \ + ba += (n); \ + } \ +} + +bus_space_write_region(1,8) +bus_space_write_region(2,16) +bus_space_write_region(4,32) +bus_space_write_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_raw_region(n,m) \ +static __inline void \ +CAT(bus_space_write_raw_region_,n)(bus_space_tag_t bst, \ + bus_space_handle_t bsh, \ + bus_addr_t ba, const u_int8_t *x, size_t cnt) \ +{ \ + cnt >>= ((n) >> 1); \ + while (cnt--) { \ + CAT(bus_space_write_raw_multi_,n)(bst, bsh, ba, x, (n)); \ + ba += (n); \ + x += (n); \ + } \ +} + +bus_space_write_raw_region(2,16) +bus_space_write_raw_region(4,32) +bus_space_write_raw_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_set_region(n,m) \ +static __inline void \ +CAT(bus_space_set_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, CAT3(u_int,m,_t) x, size_t cnt) \ +{ \ + while (cnt--) { \ + CAT(bus_space_write_,n)(bst, bsh, ba, x); \ + ba += (n); \ + } \ +} + +bus_space_set_region(1,8) +bus_space_set_region(2,16) +bus_space_set_region(4,32) +bus_space_set_region(8,64) + +/*----------------------------------------------------------------------------*/ +static __inline void +bus_space_copy_1(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + char *s = (char *)(h1 + o1); + char *d = (char *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + + +static __inline void +bus_space_copy_2(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + short *s = (short *)(h1 + o1); + short *d = (short *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + +static __inline void +bus_space_copy_4(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + int *s = (int *)(h1 + o1); + int *d = (int *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + +static __inline void +bus_space_copy_8(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + int64_t *s = (int64_t *)(h1 + o1); + int64_t *d = (int64_t *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + +/*----------------------------------------------------------------------------*/ +/* + * Bus read/write barrier methods. + * + * void bus_space_barrier(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * bus_size_t len, int flags); + * + */ +static inline void +bus_space_barrier(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, + bus_size_t length, int flags) +{ + __asm__ volatile ("sync" ::: "memory"); +} +#define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */ +#define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */ + +#define BUS_DMA_WAITOK 0x0000 +#define BUS_DMA_NOWAIT 0x0001 +#define BUS_DMA_ALLOCNOW 0x0002 +#define BUS_DMA_COHERENT 0x0008 +#define BUS_DMA_BUS1 0x0010 /* placeholders for bus functions... */ +#define BUS_DMA_BUS2 0x0020 +#define BUS_DMA_BUS3 0x0040 +#define BUS_DMA_BUS4 0x0080 +#define BUS_DMA_READ 0x0100 /* mapping is device -> memory only */ +#define BUS_DMA_WRITE 0x0200 /* mapping is memory -> device only */ +#define BUS_DMA_STREAMING 0x0400 /* hint: sequential, unidirectional */ +#define BUS_DMA_ZERO 0x0800 /* zero memory in dmamem_alloc */ +#define BUS_DMA_NOCACHE 0x1000 +#define BUS_DMA_64BIT 0x2000 /* device handles 64bit dva */ + +/* Forwards needed by prototypes below. */ +struct mbuf; +struct proc; +struct uio; + +#define BUS_DMASYNC_POSTREAD 0x0001 +#define BUS_DMASYNC_POSTWRITE 0x0002 +#define BUS_DMASYNC_PREREAD 0x0004 +#define BUS_DMASYNC_PREWRITE 0x0008 + +typedef struct machine_bus_dma_tag *bus_dma_tag_t; +typedef struct machine_bus_dmamap *bus_dmamap_t; + +/* + * bus_dma_segment_t + * + * Describes a single contiguous DMA transaction. Values + * are suitable for programming into DMA registers. + */ +struct machine_bus_dma_segment { + bus_addr_t ds_addr; /* DMA address */ + bus_size_t ds_len; /* length of transfer */ + + paddr_t _ds_paddr; /* CPU address */ + vaddr_t _ds_vaddr; /* CPU address */ +}; +typedef struct machine_bus_dma_segment bus_dma_segment_t; + +/* + * bus_dma_tag_t + * + * A machine-dependent opaque type describing the implementation of + * DMA for a given bus. + */ + +struct machine_bus_dma_tag { + void *_cookie; /* cookie used in the guts */ + + /* + * DMA mapping methods. + */ + int (*_dmamap_create)(bus_dma_tag_t , bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); + void (*_dmamap_destroy)(bus_dma_tag_t , bus_dmamap_t); + int (*_dmamap_load)(bus_dma_tag_t , bus_dmamap_t, void *, + bus_size_t, struct proc *, int); + int (*_dmamap_load_mbuf)(bus_dma_tag_t , bus_dmamap_t, + struct mbuf *, int); + int (*_dmamap_load_uio)(bus_dma_tag_t , bus_dmamap_t, + struct uio *, int); + int (*_dmamap_load_raw)(bus_dma_tag_t , bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); + int (*_dmamap_load_buffer)(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int, paddr_t *, int *, int); + void (*_dmamap_unload)(bus_dma_tag_t , bus_dmamap_t); + void (*_dmamap_sync)(bus_dma_tag_t , bus_dmamap_t, + bus_addr_t, bus_size_t, int); + + /* + * DMA memory utility functions. + */ + int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); + void (*_dmamem_free)(bus_dma_tag_t, bus_dma_segment_t *, int); + int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); + void (*_dmamem_unmap)(bus_dma_tag_t, caddr_t, size_t); + paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *, + int, off_t, int, int); + + /* + * internal memory address translation information. + */ + bus_addr_t (*_pa_to_device)(paddr_t); + paddr_t (*_device_to_pa)(bus_addr_t); + bus_addr_t _dma_mask; +}; + +#define bus_dmamap_create(t, s, n, m, b, f, p) \ + (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p)) +#define bus_dmamap_destroy(t, p) \ + (*(t)->_dmamap_destroy)((t), (p)) +#define bus_dmamap_load(t, m, b, s, p, f) \ + (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f)) +#define bus_dmamap_load_mbuf(t, m, b, f) \ + (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f)) +#define bus_dmamap_load_uio(t, m, u, f) \ + (*(t)->_dmamap_load_uio)((t), (m), (u), (f)) +#define bus_dmamap_load_raw(t, m, sg, n, s, f) \ + (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f)) +#define bus_dmamap_unload(t, p) \ + (*(t)->_dmamap_unload)((t), (p)) +#define bus_dmamap_sync(t, p, a, l, o) \ + (void)((t)->_dmamap_sync ? \ + (*(t)->_dmamap_sync)((t), (p), (a), (l), (o)) : (void)0) + +#define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \ + (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f)) +#define bus_dmamem_free(t, sg, n) \ + (*(t)->_dmamem_free)((t), (sg), (n)) +#define bus_dmamem_map(t, sg, n, s, k, f) \ + (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f)) +#define bus_dmamem_unmap(t, k, s) \ + (*(t)->_dmamem_unmap)((t), (k), (s)) +#define bus_dmamem_mmap(t, sg, n, o, p, f) \ + (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f)) + +int _dmamap_create(bus_dma_tag_t, bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); +void _dmamap_destroy(bus_dma_tag_t, bus_dmamap_t); +int _dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int); +int _dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, struct mbuf *, int); +int _dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, struct uio *, int); +int _dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); +int _dmamap_load_buffer(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int, paddr_t *, int *, int); +void _dmamap_unload(bus_dma_tag_t, bus_dmamap_t); +void _dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, + bus_size_t, int); + +int _dmamem_alloc(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); +void _dmamem_free(bus_dma_tag_t, bus_dma_segment_t *, int); +int _dmamem_map(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); +void _dmamem_unmap(bus_dma_tag_t, caddr_t, size_t); +paddr_t _dmamem_mmap(bus_dma_tag_t, bus_dma_segment_t *, int, off_t, int, int); +int _dmamem_alloc_range(bus_dma_tag_t, bus_size_t, bus_size_t, bus_size_t, + bus_dma_segment_t *, int, int *, int, paddr_t, paddr_t); + +/* + * bus_dmamap_t + * + * Describes a DMA mapping. + */ +struct machine_bus_dmamap { + /* + * PRIVATE MEMBERS: not for use by machine-independent code. + */ + bus_size_t _dm_size; /* largest DMA transfer mappable */ + int _dm_segcnt; /* number of segs this map can map */ + bus_size_t _dm_maxsegsz; /* largest possible segment */ + bus_size_t _dm_boundary; /* don't cross this */ + int _dm_flags; /* misc. flags */ + + void *_dm_cookie; /* cookie for bus-specific functions */ + + /* + * PUBLIC MEMBERS: these are used by machine-independent code. + */ + bus_size_t dm_mapsize; /* size of the mapping */ + int dm_nsegs; /* # valid segments in mapping */ + bus_dma_segment_t dm_segs[1]; /* segments; variable length */ +}; + +int generic_space_map(bus_space_tag_t, bus_addr_t, bus_size_t, int, + bus_space_handle_t *); +void generic_space_unmap(bus_space_tag_t, bus_space_handle_t, bus_size_t); +int generic_space_region(bus_space_tag_t, bus_space_handle_t, bus_size_t, + bus_size_t, bus_space_handle_t *); +void *generic_space_vaddr(bus_space_tag_t, bus_space_handle_t); +uint8_t generic_space_read_1(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint16_t generic_space_read_2(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint32_t generic_space_read_4(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint64_t generic_space_read_8(bus_space_tag_t, bus_space_handle_t, bus_size_t); +void generic_space_read_raw_2(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_1(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint8_t); +void generic_space_write_2(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint16_t); +void generic_space_write_4(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint32_t); +void generic_space_write_8(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint64_t); +void generic_space_write_raw_2(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); +void generic_space_read_raw_4(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_raw_4(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); +void generic_space_read_raw_8(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_raw_8(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); + +#endif /* _MACHINE_BUS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/conf.h b/lib/libc/include/mips64-openbsd-none/machine/conf.h new file mode 100644 index 0000000000..df1ce719b2 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/conf.h @@ -0,0 +1,55 @@ +/* $OpenBSD: conf.h,v 1.4 2022/06/28 14:43:50 visa Exp $ */ +/* $NetBSD: conf.h,v 1.2 1996/05/05 19:28:34 christos Exp $ */ + +/* + * Copyright (c) 1996 Christos Zoulas. 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 Christos Zoulas. + * 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 _OCTEON_CONF_H_ +#define _OCTEON_CONF_H_ + +#include + +/* open, close, ioctl */ +#define cdev_octboot_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) nullop, 0, \ + (dev_type_mmap((*))) enodev } + +/* open, close, ioctl */ +#define cdev_openprom_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) nullop, 0, \ + (dev_type_mmap((*))) enodev } + +cdev_decl(octboot); +cdev_decl(openprom); + +#endif /* _OCTEON_CONF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/cpu.h b/lib/libc/include/mips64-openbsd-none/machine/cpu.h new file mode 100644 index 0000000000..e5e26d7837 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/cpu.h @@ -0,0 +1,106 @@ +/* $OpenBSD: cpu.h,v 1.12 2018/02/18 14:50:08 visa 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 and Rick Macklem. + * + * 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. + * + * Copyright (C) 1989 Digital Equipment Corporation. + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby granted, + * provided that the above copyright notice appears in all copies. + * Digital Equipment Corporation makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * from: @(#)cpu.h 8.4 (Berkeley) 1/4/94 + */ + +#ifndef _MACHINE_CPU_H_ +#define _MACHINE_CPU_H_ + +#ifdef _KERNEL + +#define OCTEON_MAXCPUS 16 + +#if defined(MULTIPROCESSOR) && !defined(_LOCORE) +#define MAXCPUS OCTEON_MAXCPUS +struct cpu_info; +void hw_cpu_boot_secondary(struct cpu_info *); +void hw_cpu_hatch(struct cpu_info *); +void hw_cpu_spinup_trampoline(struct cpu_info *); +int hw_ipi_intr_establish(int (*)(void *), u_long); +void hw_ipi_intr_set(u_long); +void hw_ipi_intr_clear(u_long); + +/* Keep in sync with HW_GET_CPU_INFO(). */ +static inline struct cpu_info * +hw_getcurcpu(void) +{ + struct cpu_info *ci; + __asm__ volatile ("dmfc0 %0, $30" /* ErrorEPC */ : "=r" (ci)); + return ci; +} + +static inline void +hw_setcurcpu(struct cpu_info *ci) +{ + __asm__ volatile ("dmtc0 %0, $30" /* ErrorEPC */ : : "r" (ci)); +} +#endif /* MULTIPROCESSOR && !_LOCORE */ + +#define CACHELINESIZE 128 + +/* + * No need to use the per-cpu_info function pointers, as we only support + * one processor type. + */ +#define Mips_SyncCache(ci) \ + Octeon_SyncCache((ci)) +#define Mips_InvalidateICache(ci, va, l) \ + Octeon_InvalidateICache((ci), (va), (l)) +#define Mips_InvalidateICachePage(ci, va) \ + Octeon_InvalidateICachePage((ci), (va)) +#define Mips_SyncICache(ci) \ + Octeon_SyncICache((ci)) +#define Mips_SyncDCachePage(ci, va, pa) \ + Octeon_SyncDCachePage((ci), (va), (pa)) +#define Mips_HitSyncDCachePage(ci, va, pa) \ + Octeon_SyncDCachePage((ci), (va), (pa)) +#define Mips_HitSyncDCache(ci, va, l) \ + Octeon_HitSyncDCache((ci), (va), (l)) +#define Mips_IOSyncDCache(ci, va, l, h) \ + Octeon_IOSyncDCache((ci), (va), (l), (h)) +#define Mips_HitInvalidateDCache(ci, va, l) \ + Octeon_HitInvalidateDCache((ci), (va), (l)) + +#endif/* _KERNEL */ + +#include + +#endif /* !_MACHINE_CPU_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/cpustate.h b/lib/libc/include/mips64-openbsd-none/machine/cpustate.h new file mode 100644 index 0000000000..d0dcf0e7c0 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/cpustate.h @@ -0,0 +1,3 @@ +/* $OpenBSD: cpustate.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/db_machdep.h b/lib/libc/include/mips64-openbsd-none/machine/db_machdep.h new file mode 100644 index 0000000000..3a3271b423 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/db_machdep.h @@ -0,0 +1,3 @@ +/* $OpenBSD: db_machdep.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/elf.h b/lib/libc/include/mips64-openbsd-none/machine/elf.h new file mode 100644 index 0000000000..5918df727b --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/elf.h @@ -0,0 +1,3 @@ +/* $OpenBSD: elf.h,v 1.1 2024/07/14 19:33:59 miod Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/endian.h b/lib/libc/include/mips64-openbsd-none/machine/endian.h new file mode 100644 index 0000000000..2bfd2b1abd --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/endian.h @@ -0,0 +1,3 @@ +/* $OpenBSD: endian.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/exec.h b/lib/libc/include/mips64-openbsd-none/machine/exec.h new file mode 100644 index 0000000000..498f7f2eca --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/exec.h @@ -0,0 +1,3 @@ +/* $OpenBSD: exec.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/fdt.h b/lib/libc/include/mips64-openbsd-none/machine/fdt.h new file mode 100644 index 0000000000..4033bc9a0c --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/fdt.h @@ -0,0 +1,40 @@ +/* $OpenBSD: fdt.h,v 1.2 2018/08/06 10:52:30 patrick Exp $ */ + +/* + * Copyright (c) 2016 Patrick Wildt + * + * 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 __OCTEON_FDT_H__ +#define __OCTEON_FDT_H__ + +#include + +struct fdt_attach_args { + const char *fa_name; + int fa_node; + bus_space_tag_t fa_iot; + bus_dma_tag_t fa_dmat; + struct fdt_reg *fa_reg; + int fa_nreg; + uint32_t *fa_intr; + int fa_nintr; + int fa_acells; + int fa_scells; +}; + +#define fdt_intr_establish octeon_intr_establish_fdt +#define fdt_intr_disestablish octeon_intr_disestablish_fdt + +#endif /* __OCTEON_FDT_H__ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/fpu.h b/lib/libc/include/mips64-openbsd-none/machine/fpu.h new file mode 100644 index 0000000000..3d415d39b4 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/fpu.h @@ -0,0 +1,3 @@ +/* $OpenBSD: fpu.h,v 1.1 2010/10/03 06:03:57 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/frame.h b/lib/libc/include/mips64-openbsd-none/machine/frame.h new file mode 100644 index 0000000000..f8295979a3 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/frame.h @@ -0,0 +1,3 @@ +/* $OpenBSD: frame.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/ieee.h b/lib/libc/include/mips64-openbsd-none/machine/ieee.h new file mode 100644 index 0000000000..8a538bc8eb --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/ieee.h @@ -0,0 +1,3 @@ +/* $OpenBSD: ieee.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/ieeefp.h b/lib/libc/include/mips64-openbsd-none/machine/ieeefp.h new file mode 100644 index 0000000000..2060e7a21f --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/ieeefp.h @@ -0,0 +1,3 @@ +/* $OpenBSD: ieeefp.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/intr.h b/lib/libc/include/mips64-openbsd-none/machine/intr.h new file mode 100644 index 0000000000..eef4afc728 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/intr.h @@ -0,0 +1,186 @@ +/* $OpenBSD: intr.h,v 1.23 2025/05/10 10:01:03 visa Exp $ */ + +/* + * Copyright (c) 2001-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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_INTR_H_ +#define _MACHINE_INTR_H_ + +#define __USE_MI_SOFTINTR + +#include + +/* + * The interrupt level ipl is a logical level; per-platform interrupt + * code will turn it into the appropriate hardware interrupt masks + * values. + * + * Interrupt sources on the CPU are kept enabled regardless of the + * current ipl value; individual hardware sources interrupting while + * logically masked are masked on the fly, remembered as pending, and + * unmasked at the first splx() opportunity. + * + * An exception to this rule is the clock interrupt. Clock interrupts + * are always allowed to happen, but will (of course!) not be serviced + * if logically masked. The reason for this is that clocks usually sit on + * INT5 and cannot be easily masked if external hardware masking is used. + */ + +/* Interrupt priority `levels'; not mutually exclusive. */ +#define IPL_NONE 0 /* nothing */ +#define IPL_SOFTINT 1 /* soft interrupts */ +#define IPL_SOFTCLOCK 1 /* soft clock interrupts */ +#define IPL_SOFTNET 2 /* soft network interrupts */ +#define IPL_SOFTTTY 3 /* soft terminal interrupts */ +#define IPL_SOFTHIGH IPL_SOFTTTY /* highest level of soft interrupts */ +#define IPL_BIO 4 /* block I/O */ +#define IPL_AUDIO IPL_BIO +#define IPL_NET 5 /* network */ +#define IPL_TTY 6 /* terminal */ +#define IPL_VM 7 /* memory allocation */ +#define IPL_CLOCK 8 /* clock */ +#define IPL_SCHED IPL_CLOCK +#define IPL_HIGH 9 /* everything */ +#define IPL_IPI 10 /* interprocessor interrupt */ +#define NIPLS 11 /* number of levels */ + +#define IPL_MPFLOOR IPL_TTY + +/* Interrupt priority 'flags'. */ +#define IPL_MPSAFE 0x100 + +/* Interrupt sharing types. */ +#define IST_NONE 0 /* none */ +#define IST_PULSE 1 /* pulsed */ +#define IST_EDGE 2 /* edge-triggered */ +#define IST_LEVEL 3 /* level-triggered */ + +#ifndef _LOCORE + +void softintr(int); + +#define splbio() splraise(IPL_BIO) +#define splnet() splraise(IPL_NET) +#define spltty() splraise(IPL_TTY) +#define splaudio() splraise(IPL_AUDIO) +#define splvm() splraise(IPL_VM) +#define splclock() splraise(IPL_CLOCK) +#define splsched() splraise(IPL_SCHED) +#define splhigh() splraise(IPL_HIGH) + +#define splsoftclock() splraise(IPL_SOFTCLOCK) +#define splsoftnet() splraise(IPL_SOFTNET) +#define splstatclock() splhigh() + +#define spl0() spllower(0) + +void splinit(void); + +#ifdef DIAGNOSTIC +/* + * Although this function is implemented in MI code, it must be in this MD + * header because we don't want this header to include MI includes. + */ +void splassert_fail(int, int, const char *); +extern int splassert_ctl; +void splassert_check(int, const char *); +#define splassert(__wantipl) do { \ + if (splassert_ctl > 0) { \ + splassert_check(__wantipl, __func__); \ + } \ +} while (0) +#define splsoftassert(wantipl) splassert(wantipl) +#else +#define splassert(X) +#define splsoftassert(X) +#endif + +void register_splx_handler(void (*)(int)); +int splraise(int); +void splx(int); +int spllower(int); + +void intr_barrier(void *); + +/* + * Low level interrupt dispatcher registration data. + */ + +/* Schedule priorities for base interrupts (CPU) */ +#define INTPRI_IPI 0 +#define INTPRI_CLOCK 1 +/* other values are system-specific */ + +#define NLOWINT 16 /* Number of low level registrations possible */ + +extern uint32_t idle_mask; + +struct trapframe; +void set_intr(int, uint32_t, uint32_t(*)(uint32_t, struct trapframe *)); + +uint32_t updateimask(uint32_t); +void dosoftint(void); + +struct intr_controller { + void *ic_cookie; + void (*ic_init)(void); + void *(*ic_establish)(int, int, int (*)(void *), void *, + const char *); + void *(*ic_establish_fdt_idx)(void *, int, int, int, + int (*)(void *), void *, const char *); + void (*ic_disestablish)(void *); + void (*ic_intr_barrier)(void *); + +#ifdef MULTIPROCESSOR + int (*ic_ipi_establish)(int (*)(void *), cpuid_t); + void (*ic_ipi_set)(cpuid_t); + void (*ic_ipi_clear)(cpuid_t); +#endif /* MULTIPROCESSOR */ + + int ic_node; + int ic_phandle; + LIST_ENTRY(intr_controller) ic_list; +}; + +#ifdef MULTIPROCESSOR +#define ENABLEIPI() updateimask(~CR_INT_1) /* enable IPI interrupt level */ +#endif + +void *octeon_intr_establish(int, int, int (*)(void *), + void *, const char *); +void octeon_intr_disestablish(void *); +void octeon_intr_init(void); +void octeon_intr_register(struct intr_controller *); + +void *octeon_intr_establish_fdt(int, int, int (*)(void *), + void *, const char *); +void *octeon_intr_establish_fdt_idx(int, int, int, int (*)(void *), + void *, const char *); +void octeon_intr_disestablish_fdt(void *); + +#endif /* _LOCORE */ + +#endif /* _MACHINE_INTR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/kcore.h b/lib/libc/include/mips64-openbsd-none/machine/kcore.h new file mode 100644 index 0000000000..b221eb2048 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/kcore.h @@ -0,0 +1,3 @@ +/* $OpenBSD: kcore.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/limits.h b/lib/libc/include/mips64-openbsd-none/machine/limits.h new file mode 100644 index 0000000000..06574d0acb --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/limits.h @@ -0,0 +1,3 @@ +/* $OpenBSD: limits.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/memconf.h b/lib/libc/include/mips64-openbsd-none/machine/memconf.h new file mode 100644 index 0000000000..ec2791c749 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/memconf.h @@ -0,0 +1,3 @@ +/* $OpenBSD: memconf.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/mips_opcode.h b/lib/libc/include/mips64-openbsd-none/machine/mips_opcode.h new file mode 100644 index 0000000000..865ce02ebe --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/mips_opcode.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mips_opcode.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/mplock.h b/lib/libc/include/mips64-openbsd-none/machine/mplock.h new file mode 100644 index 0000000000..f15d109545 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/mplock.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mplock.h,v 1.2 2015/09/09 15:48:52 visa Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/mutex.h b/lib/libc/include/mips64-openbsd-none/machine/mutex.h new file mode 100644 index 0000000000..9a15499276 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/mutex.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mutex.h,v 1.3 2015/07/08 13:37:31 dlg Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/octboot.h b/lib/libc/include/mips64-openbsd-none/machine/octboot.h new file mode 100644 index 0000000000..1a889f7b6a --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/octboot.h @@ -0,0 +1,36 @@ +/* $OpenBSD: octboot.h,v 1.2 2020/05/26 13:21:58 visa Exp $ */ + +/* + * Copyright (c) 2019-2020 Visa Hankala + * + * Permission to use, copy, modify, and/or 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 _OCTEON_OCTBOOT_H_ +#define _OCTEON_OCTBOOT_H_ + +#include + +#define OCTBOOT_MAX_ARGS 8 /* maximum number of boot arguments */ + +struct octboot_kexec_args { + char *kimg; /* kernel image buffer */ + size_t klen; /* size of kernel image */ + char *argv[OCTBOOT_MAX_ARGS]; + /* kernel boot arguments */ +}; + +#define OBIOC_KEXEC _IOW('O', 1, struct octboot_kexec_args) +#define OBIOC_GETROOTDEV _IOR('O', 2, char[PATH_MAX]) + +#endif /* !_OCTEON_OCTBOOT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/octeon_model.h b/lib/libc/include/mips64-openbsd-none/machine/octeon_model.h new file mode 100644 index 0000000000..cac7c19ef9 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/octeon_model.h @@ -0,0 +1,87 @@ +/* $OpenBSD: octeon_model.h,v 1.9 2024/06/26 01:40:49 jsg Exp $ */ + +/* + * Copyright (c) 2007 + * Internet Initiative Japan, Inc. 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 AUTHORS 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 AUTHORS 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 _MIPS_OCTEON_MODEL_H_ +#define _MIPS_OCTEON_MODEL_H_ + +#define OCTEON_MODEL_CN38XX_REV1 0x000d0000 +#define OCTEON_MODEL_CN38XX_REV2 0x000d0001 +#define OCTEON_MODEL_CN38XX_REV3 0x000d0003 +#define OCTEON_MODEL_CN3100 0x000d0100 +#define OCTEON_MODEL_CN3020 0x000d0110 +#define OCTEON_MODEL_CN3010 0x000d0200 +#define OCTEON_MODEL_CN3005 0x000d0210 +#define OCTEON_MODEL_CN5010 0x000d0600 +#define OCTEON_MODEL_CN5010_PASS1_1 0x000d0601 +#define OCTEON_MODEL_CN61XX_PASS1_0 0x000d9300 +#define OCTEON_MODEL_CN61XX_PASS1_1 0x000d9301 + +#define OCTEON_MODEL_MASK 0x00ffff10 +#define OCTEON_MODEL_REV_MASK 0x00ffff1f +#define OCTEON_MODEL_FAMILY_MASK 0x00ffff00 +#define OCTEON_MODEL_FAMILY_REV_MASK 0x00ffff0f + +#define OCTEON_MODEL_FAMILY_CN58XX 0x000d0300 +#define OCTEON_MODEL_FAMILY_CN56XX 0x000d0400 +#define OCTEON_MODEL_FAMILY_CN38XX 0x000d0000 +#define OCTEON_MODEL_FAMILY_CN31XX 0x000d0100 +#define OCTEON_MODEL_FAMILY_CN30XX 0x000d0200 +#define OCTEON_MODEL_FAMILY_CN50XX 0x000d0600 +#define OCTEON_MODEL_FAMILY_CN63XX 0x000d9000 +#define OCTEON_MODEL_FAMILY_CN68XX 0x000d9100 +#define OCTEON_MODEL_FAMILY_CN66XX 0x000d9200 +#define OCTEON_MODEL_FAMILY_CN61XX 0x000d9300 +#define OCTEON_MODEL_FAMILY_CN78XX 0x000d9500 +#define OCTEON_MODEL_FAMILY_CN71XX 0x000d9600 +#define OCTEON_MODEL_FAMILY_CN73XX 0x000d9700 + +/* + * get chip id + */ +static inline uint32_t +octeon_get_chipid(void) +{ + uint32_t tmp; + + asm volatile ( + " .set push \n" + " .set mips64 \n" + " .set noreorder \n" + " mfc0 %0, $15, 0 \n" + " .set pop \n" + : "=&r"(tmp) : ); + + return(tmp); +} + +#define octeon_model(id) ((id) & OCTEON_MODEL_MASK) +#define octeon_model_revision(id) ((id) & OCTEON_MODEL_REV_MASK) +#define octeon_model_family(id) ((id) & OCTEON_MODEL_FAMILY_MASK) +#define octeon_model_family_revision(id) ((id) & OCTEON_MODEL_FAMILY_REV_MASK) + +#endif \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/octeonreg.h b/lib/libc/include/mips64-openbsd-none/machine/octeonreg.h new file mode 100644 index 0000000000..af75e6d7fb --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/octeonreg.h @@ -0,0 +1,198 @@ +/* $OpenBSD: octeonreg.h,v 1.11 2020/07/11 15:18:08 visa Exp $ */ + +/* + * Copyright (c) 2003-2004 Opsycon AB (www.opsycon.com). + * + * 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_OCTEONREG_H_ +#define _MACHINE_OCTEONREG_H_ + +#define OCTEON_CF_BASE 0x1D000800ULL +#define OCTEON_CIU3_BASE 0x1010000000000ULL +#define OCTEON_CIU_BASE 0x1070000000000ULL +#define OCTEON_CIU_SIZE 0x7000 +#define OCTEON_MIO_BOOT_BASE 0x1180000000000ULL +#define OCTEON_UART0_BASE 0x1180000000800ULL +#define OCTEON_UART1_BASE 0x1180000000C00ULL +#define OCTEON_RNG_BASE 0x1400000000000ULL +#define OCTEON_AMDCF_BASE 0x1dc00000ULL + +#define MIO_BOOT_REG_CFG0 0x0 +#define MIO_BOOT_REG_CFG(x) (MIO_BOOT_REG_CFG0+((x)*8)) +#define BOOT_CFG_BASE_MASK 0xFFFF +#define BOOT_CFG_BASE_SHIFT 16 +#define BOOT_CFG_WIDTH_MASK 0x10000000 +#define BOOT_CFG_WIDTH_SHIFT 28 + +#define CIU_INT_WORKQ0 0 +#define CIU_INT_WORKQ1 1 +#define CIU_INT_WORKQ2 2 +#define CIU_INT_WORKQ3 3 +#define CIU_INT_WORKQ4 4 +#define CIU_INT_WORKQ5 5 +#define CIU_INT_WORKQ6 6 +#define CIU_INT_WORKQ7 7 +#define CIU_INT_WORKQ8 8 +#define CIU_INT_WORKQ9 9 +#define CIU_INT_WORKQ10 10 +#define CIU_INT_WORKQ11 11 +#define CIU_INT_WORKQ12 12 +#define CIU_INT_WORKQ13 13 +#define CIU_INT_WORKQ14 14 +#define CIU_INT_WORKQ15 15 +#define CIU_INT_GPIO0 16 +#define CIU_INT_GPIO1 17 +#define CIU_INT_GPIO2 18 +#define CIU_INT_GPIO3 19 +#define CIU_INT_GPIO4 20 +#define CIU_INT_GPIO5 21 +#define CIU_INT_GPIO6 22 +#define CIU_INT_GPIO7 23 +#define CIU_INT_GPIO8 24 +#define CIU_INT_GPIO9 25 +#define CIU_INT_GPIO10 26 +#define CIU_INT_GPIO11 27 +#define CIU_INT_GPIO12 28 +#define CIU_INT_GPIO13 29 +#define CIU_INT_GPIO14 30 +#define CIU_INT_GPIO15 31 +#define CIU_INT_MBOX0 32 +#define CIU_INT_MBOX1 33 +#define CIU_INT_MBOX(x) (CIU_INT_MBOX0+(x)) +#define CIU_INT_UART0 34 +#define CIU_INT_UART1 35 +#define CIU_INT_PCI_INTA 36 +#define CIU_INT_PCI_INTB 37 +#define CIU_INT_PCI_INTC 38 +#define CIU_INT_PCI_INTD 39 +#define CIU_INT_PCI_MSIA 40 +#define CIU_INT_PCI_MSIB 41 +#define CIU_INT_PCI_MSIC 42 +#define CIU_INT_PCI_MSID 43 +#define CIU_INT_44 44 +#define CIU_INT_TWSI 45 +#define CIU_INT_RML 46 +#define CIU_INT_TRACE 47 +#define CIU_INT_GMX_DRP0 48 +#define CIU_INT_GMX_DRP1 49 +#define CIU_INT_IPD_DRP 50 +#define CIU_INT_KEY_ZERO 51 +#define CIU_INT_TIMER0 52 +#define CIU_INT_TIMER1 53 +#define CIU_INT_TIMER2 54 +#define CIU_INT_TIMER3 55 +#define CIU_INT_USB 56 +#define CIU_INT_PCM 57 +#define CIU_INT_MPI 58 +#define CIU_INT_TWSI2 59 +#define CIU_INT_POWIQ 60 +#define CIU_INT_IPDPPTHR 61 +#define CIU_INT_MII0 62 +#define CIU_INT_BOOTDMA 63 + +#define CIU_INT0_SUM0 0x00000000 +#define CIU_INT1_SUM0 0x00000008 +#define CIU_INT2_SUM0 0x00000010 +#define CIU_INT3_SUM0 0x00000018 +#define CIU_IP2_SUM0(x) (CIU_INT0_SUM0+(0x10 * (x))) +#define CIU_IP3_SUM0(x) (CIU_INT1_SUM0+(0x10 * (x))) +#define CIU_INT32_SUM0 0x00000100 +#define CIU_INT32_SUM1 0x00000108 +#define CIU_INT0_EN0 0x00000200 +#define CIU_INT1_EN0 0x00000210 +#define CIU_INT2_EN0 0x00000220 +#define CIU_INT3_EN0 0x00000230 +#define CIU_IP2_EN0(x) (CIU_INT0_EN0+(0x20 * (x))) +#define CIU_IP3_EN0(x) (CIU_INT1_EN0+(0x20 * (x))) +#define CIU_INT32_EN0 0x00000400 +#define CIU_INT0_EN1 0x00000208 +#define CIU_INT1_EN1 0x00000218 +#define CIU_INT2_EN1 0x00000228 +#define CIU_INT3_EN1 0x00000238 +#define CIU_INT32_EN1 0x00000408 +#define CIU_IP2_EN1(x) (CIU_INT0_EN1+(0x20 * (x))) +#define CIU_IP3_EN1(x) (CIU_INT1_EN1+(0x20 * (x))) +#define CIU_TIM0 0x00000480 +#define CIU_TIM1 0x00000488 +#define CIU_TIM2 0x00000490 +#define CIU_TIM3 0x00000498 +#define CIU_WDOG0 0x00000500 +#define CIU_WDOG1 0x00000508 +#define CIU_PP_POKE0 0x00000580 +#define CIU_PP_POKE1 0x00000588 +#define CIU_MBOX_SET0 0x00000600 +#define CIU_MBOX_SET1 0x00000608 +#define CIU_MBOX_SET(x) (CIU_MBOX_SET0+(0x08 * (x))) +#define CIU_MBOX_CLR0 0x00000680 +#define CIU_MBOX_CLR1 0x00000688 +#define CIU_MBOX_CLR(x) (CIU_MBOX_CLR0+(0x08 * (x))) +#define CIU_PP_RST 0x00000700 +#define CIU_PP_DBG 0x00000708 +#define CIU_GSTOP 0x00000710 +#define CIU_NMI 0x00000718 +#define CIU_DINT 0x00000720 +#define CIU_FUSE 0x00000728 +#define CIU_BIST 0x00000730 +#define CIU_SOFT_BIST 0x00000738 +#define CIU_SOFT_RST 0x00000740 +#define CIU_SOFT_PRST 0x00000748 +#define CIU_PCI_INTA 0x00000750 +#define CIU_INT0_SUM4 0x00000C00 +#define CIU_INT1_SUM4 0x00000C08 +#define CIU_INT0_EN4_0 0x00000C80 +#define CIU_INT1_EN4_0 0x00000C90 +#define CIU_INT0_EN4_1 0x00000C88 +#define CIU_INT1_EN4_1 0x00000C98 +#define CIU_IP4_SUM2(x) (0x00008c00 + 8 * (x)) +#define CIU_IP4_EN2(x) (0x0000a400 + 8 * (x)) + +#define CIU3_FUSE 0x000001a0 + +#define FPA3_CLK_COUNT 0x12800000000f0ULL + +/* OCTEON II */ +#define MIO_RST_BOOT 0x1180000001600ULL +#define MIO_RST_BOOT_C_MUL_SHIFT 30 +#define MIO_RST_BOOT_C_MUL_MASK 0x7f +#define MIO_RST_BOOT_PNR_MUL_SHIFT 24 +#define MIO_RST_BOOT_PNR_MUL_MASK 0x3f + +#define MIO_RST_CTL(x) (0x1180000001618ULL + 8 * (x)) +#define MIO_RST_CTL_PRTMODE 0x0000000000000030ULL + +/* OCTEON III */ +#define RST_BOOT 0x1180006001600ULL +#define RST_BOOT_C_MUL_SHIFT 30 +#define RST_BOOT_C_MUL_MASK 0x7f +#define RST_BOOT_PNR_MUL_SHIFT 24 +#define RST_BOOT_PNR_MUL_MASK 0x3f +#define RST_CTL(x) (0x1180006001640ULL + 8 * (x)) +#define RST_CTL_RST_DONE 0x0000000000000100ULL +#define RST_CTL_HOST_MODE 0x0000000000000040ULL +#define RST_SOFT_RST 0x1180006001680ULL + +#define OCTEON_IO_REF_CLOCK 50000000 /* 50MHz */ + +#endif /* !_MACHINE_OCTEONREG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/octeonvar.h b/lib/libc/include/mips64-openbsd-none/machine/octeonvar.h new file mode 100644 index 0000000000..cc0f782bf3 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/octeonvar.h @@ -0,0 +1,498 @@ +/* $OpenBSD: octeonvar.h,v 1.54 2022/08/29 02:01:18 jsg Exp $ */ +/* $NetBSD: maltavar.h,v 1.3 2002/03/18 10:10:16 simonb Exp $ */ + +/*- + * Copyright (c) 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. + */ + +#ifndef _MIPS_OCTEON_OCTEONVAR_H_ +#define _MIPS_OCTEON_OCTEONVAR_H_ + +#include + +/* XXX elsewhere */ +#define _ASM_PROLOGUE \ + " .set push \n" \ + " .set noreorder \n" +#define _ASM_PROLOGUE_MIPS64 \ + _ASM_PROLOGUE \ + " .set mips64 \n" +#define _ASM_PROLOGUE_OCTEON \ + _ASM_PROLOGUE \ + " .set arch=octeon \n" +#define _ASM_EPILOGUE \ + " .set pop \n" +/* + * subbits = __BITS64_GET(XXX, bits); + * bits = __BITS64_SET(XXX, subbits); + */ +#ifndef __BITS64_GET +#define __BITS64_GET(name, bits) \ + (((uint64_t)(bits) & name) >> name##_SHIFT) +#endif +#ifndef __BITS64_SET +#define __BITS64_SET(name, subbits) \ + (((uint64_t)(subbits) << name##_SHIFT) & name) +#endif + +struct octeon_config { + bus_space_tag_t mc_iobus_bust; + bus_space_tag_t mc_bootbus_bust; + + bus_dma_tag_t mc_iobus_dmat; + bus_dma_tag_t mc_bootbus_dmat; +}; + +#define GPIO_CONFIG_MD_OUTPUT_SEL_MASK (GPIO_CONFIG_MD0 | GPIO_CONFIG_MD1) +#define GPIO_CONFIG_MD_USB0_VBUS_CTRL GPIO_CONFIG_MD0 +#define GPIO_CONFIG_MD_USB1_VBUS_CTRL GPIO_CONFIG_MD1 + +/* + * FPA map + */ + +#define OCTEON_POOL_NO_PKT 0 +#define OCTEON_POOL_NO_WQE 1 +#define OCTEON_POOL_NO_CMD 2 +#define OCTEON_POOL_NO_SG 3 +#define OCTEON_POOL_NO_XXX_4 4 +#define OCTEON_POOL_NO_XXX_5 5 +#define OCTEON_POOL_NO_XXX_6 6 +#define OCTEON_POOL_NO_DUMP 7 /* FPA debug dump */ + +#define OCTEON_POOL_SIZE_PKT 1920 /* 128 x 15 */ +#define OCTEON_POOL_SIZE_WQE 128 /* 128 x 1 */ +#define OCTEON_POOL_SIZE_CMD 1024 /* 128 x 8 */ +#define OCTEON_POOL_SIZE_SG 128 /* 128 x 1 */ +#define OCTEON_POOL_SIZE_XXX_4 0 +#define OCTEON_POOL_SIZE_XXX_5 0 +#define OCTEON_POOL_SIZE_XXX_6 0 +#define OCTEON_POOL_SIZE_XXX_7 0 + +#define OCTEON_POOL_NELEMS_PKT 4096 +#define OCTEON_POOL_NELEMS_WQE 4096 +#define OCTEON_POOL_NELEMS_CMD 32 +#define OCTEON_POOL_NELEMS_SG 4096 +#define OCTEON_POOL_NELEMS_XXX_4 0 +#define OCTEON_POOL_NELEMS_XXX_5 0 +#define OCTEON_POOL_NELEMS_XXX_6 0 +#define OCTEON_POOL_NELEMS_XXX_7 0 + +/* + * CVMSEG (``scratch'') memory map + */ +struct octeon_cvmseg_map { + uint64_t csm_pow_intr; + + struct octeon_cvmseg_ether_map { + uint64_t csm_ether_fau_done; + } csm_ether[12/* XXX */]; +} __packed; +#define OCTEON_CVMSEG_OFFSET(entry) \ + offsetof(struct octeon_cvmseg_map, entry) +#define OCTEON_CVMSEG_ETHER_OFFSET(n, entry) \ + (offsetof(struct octeon_cvmseg_map, csm_ether) + \ + sizeof(struct octeon_cvmseg_ether_map) * (n) + \ + offsetof(struct octeon_cvmseg_ether_map, entry)) + +/* + * FAU register map + * + * => FAU registers exist in FAU unit + * => devices (PKO) can access these registers + * => CPU can read those values after loading them into CVMSEG + */ +struct octeon_fau_map { + struct { + /* PKO command index */ + uint64_t _fau_map_port_pkocmdidx; + /* send requested */ + uint64_t _fau_map_port_txreq; + /* send completed */ + uint64_t _fau_map_port_txdone; + /* XXX */ + uint64_t _fau_map_port_pad; + } __packed _fau_map_port[3]; +}; + +/* + * POW qos/group map + */ + +#define OCTEON_POW_QOS_PIP 0 +#define OCTEON_POW_QOS_CORE1 1 +#define OCTEON_POW_QOS_XXX_2 2 +#define OCTEON_POW_QOS_XXX_3 3 +#define OCTEON_POW_QOS_XXX_4 4 +#define OCTEON_POW_QOS_XXX_5 5 +#define OCTEON_POW_QOS_XXX_6 6 +#define OCTEON_POW_QOS_XXX_7 7 + +#define OCTEON_POW_GROUP_MAX 16 + +enum cnmac_stat { + cnmac_stat_rx_toto_gmx, + cnmac_stat_rx_totp_gmx, + cnmac_stat_rx_toto_pip, + cnmac_stat_rx_totp_pip, + cnmac_stat_rx_h64, + cnmac_stat_rx_h127, + cnmac_stat_rx_h255, + cnmac_stat_rx_h511, + cnmac_stat_rx_h1023, + cnmac_stat_rx_h1518, + cnmac_stat_rx_hmax, + cnmac_stat_rx_bcast, + cnmac_stat_rx_mcast, + cnmac_stat_rx_qdpo, + cnmac_stat_rx_qdpp, + cnmac_stat_rx_fcs, + cnmac_stat_rx_frag, + cnmac_stat_rx_undersz, + cnmac_stat_rx_jabber, + cnmac_stat_rx_oversz, + cnmac_stat_rx_raw, + cnmac_stat_rx_bad, + cnmac_stat_rx_drop, + cnmac_stat_rx_ctl, + cnmac_stat_rx_dmac, + cnmac_stat_tx_toto, + cnmac_stat_tx_totp, + cnmac_stat_tx_hmin, + cnmac_stat_tx_h64, + cnmac_stat_tx_h127, + cnmac_stat_tx_h255, + cnmac_stat_tx_h511, + cnmac_stat_tx_h1023, + cnmac_stat_tx_h1518, + cnmac_stat_tx_hmax, + cnmac_stat_tx_bcast, + cnmac_stat_tx_mcast, + cnmac_stat_tx_coll, + cnmac_stat_tx_defer, + cnmac_stat_tx_scol, + cnmac_stat_tx_mcol, + cnmac_stat_tx_ctl, + cnmac_stat_tx_uflow, + cnmac_stat_count +}; + +#if defined(_KERNEL) || defined(_STANDALONE) +#define OCTEON_ARGV_MAX 64 + +/* + * OCTEON board types recognized by OpenBSD/octeon. + * + * It is fine to use BOARD_UNKNOWN when the board does not need + * special treatment. + */ +enum octeon_board { + BOARD_UNKNOWN, + BOARD_CHECKPOINT_N100, + BOARD_CN3010_EVB_HS5, + BOARD_DLINK_DSR_500, + BOARD_NETGEAR_UTM25, + BOARD_RHINOLABS_UTM8, + BOARD_UBIQUITI_E100, + BOARD_UBIQUITI_E120, + BOARD_UBIQUITI_E200, + BOARD_UBIQUITI_E220, + BOARD_UBIQUITI_E300, + BOARD_UBIQUITI_E1000, +}; + +struct boot_desc { + uint32_t desc_ver; + uint32_t desc_size; + uint64_t stack_top; + uint64_t heap_start; + uint64_t heap_end; + uint64_t __unused17; + uint64_t __unused16; + uint32_t __unused18; + uint32_t __unused15; + uint32_t __unused14; + uint32_t argc; + uint32_t argv[OCTEON_ARGV_MAX]; + uint32_t flags; + uint32_t core_mask; + uint32_t dram_size; + uint32_t phy_mem_desc_addr; + uint32_t debugger_flag_addr; + uint32_t eclock; + uint32_t __unused10; + uint32_t __unused9; + uint16_t __unused8; + uint8_t __unused7; + uint8_t __unused6; + uint16_t __unused5; + uint8_t __unused4; + uint8_t __unused3; + uint8_t __unused2[20]; + uint8_t __unused1[6]; + uint8_t __unused0; + uint64_t boot_info_addr; +}; + +struct boot_info { + uint32_t ver_major; + uint32_t ver_minor; + uint64_t stack_top; + uint64_t heap_start; + uint64_t heap_end; + uint64_t boot_desc_addr; + uint32_t exception_base_addr; + uint32_t stack_size; + uint32_t flags; + uint32_t core_mask; + uint32_t dram_size; + uint32_t phys_mem_desc_addr; + uint32_t debugger_flags_addr; + uint32_t eclock; + uint32_t dclock; + uint32_t __unused0; + uint16_t board_type; + uint8_t board_rev_major; + uint8_t board_rev_minor; + uint16_t __unused1; + uint8_t __unused2; + uint8_t __unused3; + char board_serial[20]; + uint8_t mac_addr_base[6]; + uint8_t mac_addr_count; + uint64_t cf_common_addr; + uint64_t cf_attr_addr; + uint64_t led_display_addr; + uint32_t dfaclock; + uint32_t config_flags; + /* The fields below are available when ver_minor >= 3. */ + uint64_t fdt_addr; +}; + +struct octeon_bootmem_desc { + uint32_t lock; + uint32_t flags; + uint64_t head_addr; + uint32_t major_version; + uint32_t minor_version; + uint64_t app_data_addr; + uint64_t app_data_size; + uint32_t named_block_num_blocks; + uint32_t named_block_name_len; + uint64_t named_block_array_addr; +}; + +struct octeon_bootmem_block { + uint64_t next; + uint64_t size; +}; + +extern enum octeon_board octeon_board; +extern struct boot_desc *octeon_boot_desc; +extern struct boot_info *octeon_boot_info; + +#ifdef _KERNEL +/* Device capabilities advertised in boot_info->config_flags */ +#define BOOTINFO_CFG_FLAG_PCI_HOST (1ull << 0) +#define BOOTINFO_CFG_FLAG_PCI_TARGET (1ull << 1) +#define BOOTINFO_CFG_FLAG_DEBUG (1ull << 2) +#define BOOTINFO_CFG_FLAG_NO_MAGIC (1ull << 3) + +#define BOOTMEM_BLOCK_ALIGN 16 +#define BOOTMEM_BLOCK_MASK (BOOTMEM_BLOCK_ALIGN - 1) +#define BOOTMEM_BLOCK_MIN_SIZE 16 + +int bootmem_alloc_region(paddr_t, size_t); +void bootmem_free(paddr_t, size_t); + +int octeon_ioclock_speed(void); + +#endif /* _KERNEL */ +#endif /* _KERNEL || _STANDALONE */ + +static inline int +ffs64(uint64_t val) +{ + int ret; + + __asm volatile ( \ + _ASM_PROLOGUE_MIPS64 + " dclz %0, %1 \n" + _ASM_EPILOGUE + : "=r"(ret) : "r"(val)); + return 64 - ret; +} + +static inline int +ffs32(uint32_t val) +{ + int ret; + + __asm volatile ( \ + _ASM_PROLOGUE_MIPS64 + " clz %0, %1 \n" + _ASM_EPILOGUE + : "=r"(ret) : "r"(val)); + return 32 - ret; +} + +static inline uint64_t +octeon_xkphys_read_8(paddr_t address) +{ + volatile uint64_t *p = + (volatile uint64_t *)(PHYS_TO_XKPHYS(address, CCA_NC)); + return (*p); +} + +#define MIO_BOOT_BIST_STAT 0x00011800000000f8ULL +static inline void +octeon_xkphys_write_8(paddr_t address, uint64_t value) +{ + *(volatile uint64_t *)(PHYS_TO_XKPHYS(address, CCA_NC)) = value; + + /* + * It seems an immediate read is necessary when doing a write to an RSL + * register in order to complete the write. + * We use MIO_BOOT_BIST_STAT because it's apparently the fastest + * write. + */ + + /* + * XXX + * This if would be better written as: + * if ((address & 0xffffff0000000000ULL) == OCTEON_MIO_BOOT_BASE) { + * but octeonreg.h can't be included here and we want this inlined + * + * Note that the SDK masks with 0x7ffff but that doesn't make sense. + * This is a physical address. + */ + if (((address >> 40) & 0xfffff) == (0x118)) { + value = *(volatile uint64_t *) + (PHYS_TO_XKPHYS(MIO_BOOT_BIST_STAT, CCA_NC)); + } +} + +static inline void +octeon_iobdma_write_8(uint64_t value) +{ + uint64_t addr = 0xffffffffffffa200ULL; + + *(volatile uint64_t *)addr = value; +} + +static inline void +octeon_lmtdma_write_8(off_t offset, uint64_t value) +{ + *(volatile uint64_t *)(0xffffffffffffa400ULL + offset) = value; +} + +static inline uint64_t +octeon_cvmseg_read_8(size_t offset) +{ + return *(volatile uint64_t *)(0xffffffffffff8000ULL + offset); +} + +static inline void +octeon_cvmseg_write_8(size_t offset, uint64_t value) +{ + *(volatile uint64_t *)(0xffffffffffff8000ULL + offset) = value; +} + +static inline uint32_t +octeon_get_coreid(void) +{ + uint32_t coreid; + + __asm volatile ( + _ASM_PROLOGUE_OCTEON + " rdhwr %0, $0\n" + _ASM_EPILOGUE + : "=r" (coreid)); + return coreid; +} + +static inline uint64_t +octeon_get_cycles(void) +{ + uint64_t tmp; + + __asm volatile ( + _ASM_PROLOGUE_MIPS64 + " dmfc0 %[tmp], $9, 6 \n" + _ASM_EPILOGUE + : [tmp]"=&r"(tmp)); + return tmp; +} + +static inline uint64_t +octeon_get_cvmctl(void) +{ + uint64_t tmp; + + __asm volatile ( + _ASM_PROLOGUE_OCTEON + " dmfc0 %[tmp], $9, 7 \n" + _ASM_EPILOGUE + : [tmp]"=r"(tmp)); + return tmp; +} + +static inline uint64_t +octeon_get_cvmmemctl(void) +{ + uint64_t tmp; + + __asm volatile ( + _ASM_PROLOGUE_OCTEON + " dmfc0 %[tmp], $11, 7 \n" + _ASM_EPILOGUE + : [tmp]"=r"(tmp)); + return tmp; +} + +static inline void +octeon_set_cvmmemctl(uint64_t val) +{ + __asm volatile ( + _ASM_PROLOGUE_OCTEON + " dmtc0 %[tmp], $11, 7 \n" + _ASM_EPILOGUE + : : [tmp]"r"(val) : "memory"); +} + +static inline void +octeon_synciobdma(void) +{ + __asm volatile ( + _ASM_PROLOGUE_OCTEON + " synciobdma\n" + _ASM_EPILOGUE + : : : "memory"); +} + +#endif /* _MIPS_OCTEON_OCTEONVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/openpromio.h b/lib/libc/include/mips64-openbsd-none/machine/openpromio.h new file mode 100644 index 0000000000..c33fb937a0 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/openpromio.h @@ -0,0 +1,57 @@ +/* $OpenBSD: openpromio.h,v 1.1 2016/07/05 12:53:40 visa Exp $ */ +/* $NetBSD: openpromio.h,v 1.1.1.1 1998/06/20 04:58:52 eeh Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)openpromio.h 8.1 (Berkeley) 6/11/93 + */ + +struct opiocdesc { + int op_nodeid; /* passed or returned node id */ + int op_namelen; /* length of op_name */ + char *op_name; /* pointer to field name */ + int op_buflen; /* length of op_buf (value-result) */ + char *op_buf; /* pointer to field value */ +}; + +#define OPIOCGET _IOWR('O', 1, struct opiocdesc) /* get openprom field */ +#define OPIOCSET _IOW('O', 2, struct opiocdesc) /* set openprom field */ +#define OPIOCNEXTPROP _IOWR('O', 3, struct opiocdesc) /* get next property */ +#define OPIOCGETOPTNODE _IOR('O', 4, int) /* get openprom field */ +#define OPIOCGETNEXT _IOWR('O', 5, int) /* get next node of node */ +#define OPIOCGETCHILD _IOWR('O', 6, int) /* get first child of node */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/param.h b/lib/libc/include/mips64-openbsd-none/machine/param.h new file mode 100644 index 0000000000..336a652308 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/param.h @@ -0,0 +1,22 @@ +/* $OpenBSD: param.h,v 1.5 2018/08/09 12:19:32 patrick Exp $ */ + +/* Public Domain */ + +#ifndef _MACHINE_PARAM_H_ +#define _MACHINE_PARAM_H_ + +#define MACHINE "octeon" +#define _MACHINE octeon +#define MACHINE_ARCH "mips64" +#define _MACHINE_ARCH mips64 +#define MID_MACHINE MID_MIPS64 + +#define PAGE_SHIFT 14 + +#include + +#ifdef _KERNEL +#define __HAVE_FDT +#endif + +#endif /* _MACHINE_PARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/pcb.h b/lib/libc/include/mips64-openbsd-none/machine/pcb.h new file mode 100644 index 0000000000..d48bd47247 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/pcb.h @@ -0,0 +1,3 @@ +/* $OpenBSD: pcb.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/pci_machdep.h b/lib/libc/include/mips64-openbsd-none/machine/pci_machdep.h new file mode 100644 index 0000000000..b3aa0341f1 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/pci_machdep.h @@ -0,0 +1,133 @@ +/* $OpenBSD: pci_machdep.h,v 1.13 2024/05/20 23:13:33 jsg Exp $ */ + +/* + * Copyright (c) 2003-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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. + * + */ +#include + +typedef struct mips_pci_chipset *pci_chipset_tag_t; + +typedef u_int64_t pcitag_t; +#define PCITAG_NODE(x) ((x) >> 32) +#define PCITAG_OFFSET(x) ((x) & 0xffffffff) + +typedef u_long pci_intr_handle_t; + +struct pci_attach_args; + +/* + * mips-specific PCI structure and type definitions. + * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE. + */ +struct mips_pci_chipset { + void *pc_conf_v; + void (*pc_attach_hook)(struct device *, + struct device *, struct pcibus_attach_args *); + int (*pc_bus_maxdevs)(void *, int); + pcitag_t (*pc_make_tag)(void *, int, int, int); + void (*pc_decompose_tag)(void *, pcitag_t, int *, + int *, int *); + int (*pc_conf_size)(void *, pcitag_t); + pcireg_t (*pc_conf_read)(void *, pcitag_t, int); + void (*pc_conf_write)(void *, pcitag_t, int, pcireg_t); + + void *pc_intr_v; + int (*pc_intr_map)(struct pci_attach_args *, + pci_intr_handle_t *); + const char *(*pc_intr_string)(void *, pci_intr_handle_t); + void *(*pc_intr_establish)(void *, pci_intr_handle_t, + int, int (*)(void *), void *, char *); + void (*pc_intr_disestablish)(void *, void *); +}; + +/* + * Functions provided to machine-independent PCI code. + */ +//#define DEBUG_PCI_CONF + +#define pci_attach_hook(p, s, pba) \ + (*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba)) +#define pci_bus_maxdevs(c, b) \ + (*(c)->pc_bus_maxdevs)((c)->pc_conf_v, (b)) +#define pci_make_tag(c, b, d, f) \ + (*(c)->pc_make_tag)((c)->pc_conf_v, (b), (d), (f)) +#define pci_decompose_tag(c, t, bp, dp, fp) \ + (*(c)->pc_decompose_tag)((c)->pc_conf_v, (t), (bp), (dp), (fp)) + +#define pci_conf_size(c, t) \ + (*(c)->pc_conf_size)((c)->pc_conf_v, (t)) + +#ifdef DEBUG_PCI_CONF +static inline pcireg_t +pci_conf_read_db(void *cookie, pcitag_t tag, int reg, + const char *file, const char *func, int line) +{ + struct mips_pci_chipset *pc = cookie; + pcireg_t val; + + val = (*(pc)->pc_conf_read)(pc->pc_conf_v, tag, reg); + printf("%s:%s:%d:pci_conf_read(%llx,%x) = %x\n", file, func, line, + tag, reg, val); + return val; +} + +static inline void +pci_conf_write_db(void *cookie, pcitag_t tag, int reg, pcireg_t val, + const char *file, const char *func, int line) +{ + struct mips_pci_chipset *pc = cookie; + + printf("%s:%s:%d:pci_conf_write(%llx,%x,%x)\n", file, func, line, + tag, reg, val); + (*(pc)->pc_conf_write)(pc->pc_conf_v, tag, reg, val); +} + + +#define pci_conf_read(c, t, r) \ + pci_conf_read_db(c, t, r, __FILE__, __FUNCTION__, __LINE__) +#define pci_conf_write(c, t, r, v) \ + pci_conf_write_db(c, t, r, v, __FILE__, __FUNCTION__, __LINE__) +#else +#define pci_conf_read(c, t, r) \ + (*(c)->pc_conf_read)((c)->pc_conf_v, (t), (r)) +#define pci_conf_write(c, t, r, v) \ + (*(c)->pc_conf_write)((c)->pc_conf_v, (t), (r), (v)) +#endif +#define pci_intr_map(c, ihp) \ + (*(c)->pa_pc->pc_intr_map)((c), (ihp)) +#define pci_intr_map_msi(c, ihp) (-1) +#define pci_intr_map_msix(c, vec, ihp) (-1) +#define pci_intr_string(c, ih) \ + (*(c)->pc_intr_string)((c)->pc_intr_v, (ih)) +#define pci_intr_establish(c, ih, l, h, a, nm) \ + (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), (h), (a), (nm)) +#define pci_intr_disestablish(c, iv) \ + (*(c)->pc_intr_disestablish)((c)->pc_intr_v, (iv)) +#define pci_probe_device_hook(c, a) (0) + +#define pci_min_powerstate(c, t) (PCI_PMCSR_STATE_D3) +#define pci_set_powerstate_md(c, t, s, p) + +#define pci_dev_postattach(a, b) \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/pmap.h b/lib/libc/include/mips64-openbsd-none/machine/pmap.h new file mode 100644 index 0000000000..93a59c2555 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/pmap.h @@ -0,0 +1,3 @@ +/* $OpenBSD: pmap.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/proc.h b/lib/libc/include/mips64-openbsd-none/machine/proc.h new file mode 100644 index 0000000000..feb4d625ea --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/proc.h @@ -0,0 +1,3 @@ +/* $OpenBSD: proc.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/profile.h b/lib/libc/include/mips64-openbsd-none/machine/profile.h new file mode 100644 index 0000000000..f6b93ca73c --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/profile.h @@ -0,0 +1,3 @@ +/* $OpenBSD: profile.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/pte.h b/lib/libc/include/mips64-openbsd-none/machine/pte.h new file mode 100644 index 0000000000..a1543ff6ce --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/pte.h @@ -0,0 +1,3 @@ +/* $OpenBSD: pte.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/ptrace.h b/lib/libc/include/mips64-openbsd-none/machine/ptrace.h new file mode 100644 index 0000000000..be18759bda --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/ptrace.h @@ -0,0 +1,3 @@ +/* $OpenBSD: ptrace.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/reg.h b/lib/libc/include/mips64-openbsd-none/machine/reg.h new file mode 100644 index 0000000000..b21b51b978 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/reg.h @@ -0,0 +1,3 @@ +/* $OpenBSD: reg.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/regdef.h b/lib/libc/include/mips64-openbsd-none/machine/regdef.h new file mode 100644 index 0000000000..dc004a4ce8 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/regdef.h @@ -0,0 +1,3 @@ +/* $OpenBSD: regdef.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/regnum.h b/lib/libc/include/mips64-openbsd-none/machine/regnum.h new file mode 100644 index 0000000000..b20d7d3c3f --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/regnum.h @@ -0,0 +1,3 @@ +/* $OpenBSD: regnum.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/setjmp.h b/lib/libc/include/mips64-openbsd-none/machine/setjmp.h new file mode 100644 index 0000000000..bdd733d22d --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/setjmp.h @@ -0,0 +1,3 @@ +/* $OpenBSD: setjmp.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/signal.h b/lib/libc/include/mips64-openbsd-none/machine/signal.h new file mode 100644 index 0000000000..2a21ca6358 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/signal.h @@ -0,0 +1,3 @@ +/* $OpenBSD: signal.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/simplebusvar.h b/lib/libc/include/mips64-openbsd-none/machine/simplebusvar.h new file mode 100644 index 0000000000..32763ebfc8 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/simplebusvar.h @@ -0,0 +1,34 @@ +/* $OpenBSD: simplebusvar.h,v 1.1 2023/09/22 01:10:43 jsg Exp $ */ + +/* + * Copyright (c) 2016 Patrick Wildt + * + * 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. + */ + +struct simplebus_softc { + struct device sc_dev; + int sc_node; + bus_space_tag_t sc_iot; + bus_dma_tag_t sc_dmat; + int sc_acells; + int sc_scells; + int sc_pacells; + int sc_pscells; + bus_space_t sc_bus; + int *sc_ranges; + int sc_rangeslen; + int sc_early; +}; + +extern void simplebus_attach(struct device *, struct device *, void *); \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/spinlock.h b/lib/libc/include/mips64-openbsd-none/machine/spinlock.h new file mode 100644 index 0000000000..800fc6eeb1 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/spinlock.h @@ -0,0 +1,3 @@ +/* $OpenBSD: spinlock.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/sysarch.h b/lib/libc/include/mips64-openbsd-none/machine/sysarch.h new file mode 100644 index 0000000000..05bc151676 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/sysarch.h @@ -0,0 +1,3 @@ +/* $OpenBSD: sysarch.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/timetc.h b/lib/libc/include/mips64-openbsd-none/machine/timetc.h new file mode 100644 index 0000000000..d3d291c815 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/timetc.h @@ -0,0 +1,23 @@ +/* $OpenBSD: timetc.h,v 1.2 2020/07/18 08:37:43 visa Exp $ */ +/* + * Copyright (c) 2020 Paul Irofti + * + * 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_TIMETC_H_ +#define _MACHINE_TIMETC_H_ + +#include + +#endif /* _MACHINE_TIMETC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/trap.h b/lib/libc/include/mips64-openbsd-none/machine/trap.h new file mode 100644 index 0000000000..7ed252bd11 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/trap.h @@ -0,0 +1,3 @@ +/* $OpenBSD: trap.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/machine/vmparam.h b/lib/libc/include/mips64-openbsd-none/machine/vmparam.h new file mode 100644 index 0000000000..336c1cf70f --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/machine/vmparam.h @@ -0,0 +1,11 @@ +/* $OpenBSD: vmparam.h,v 1.3 2017/07/30 16:09:53 visa Exp $ */ +/* public domain */ +#ifndef _MACHINE_VMPARAM_H_ +#define _MACHINE_VMPARAM_H_ + +#define VM_PHYSSEG_MAX 8 /* Max number of physical memory segments */ +#define VM_PHYSSEG_STRAT VM_PSTRAT_BIGFIRST + +#include + +#endif /* _MACHINE_VMPARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/_float.h b/lib/libc/include/mips64-openbsd-none/octeon/_float.h new file mode 100644 index 0000000000..6c9717939f --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/_float.h @@ -0,0 +1,3 @@ +/* $OpenBSD: _float.h,v 1.1 2012/06/26 16:12:44 deraadt Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/_types.h b/lib/libc/include/mips64-openbsd-none/octeon/_types.h new file mode 100644 index 0000000000..12dbcd35ee --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/_types.h @@ -0,0 +1,3 @@ +/* $OpenBSD: _types.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/asm.h b/lib/libc/include/mips64-openbsd-none/octeon/asm.h new file mode 100644 index 0000000000..a7660ee641 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/asm.h @@ -0,0 +1,9 @@ +/* $OpenBSD: asm.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ + +#ifdef MULTIPROCESSOR +#define HW_GET_CPU_INFO(ci, tmp) \ + dmfc0 ci, COP_0_ERROR_PC +#endif + +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/atomic.h b/lib/libc/include/mips64-openbsd-none/octeon/atomic.h new file mode 100644 index 0000000000..1d56c3a000 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/atomic.h @@ -0,0 +1,45 @@ +/* $OpenBSD: atomic.h,v 1.3 2020/07/08 15:53:59 visa Exp $ */ + +/* + * Copyright (c) 2017 Visa Hankala + * + * Permission to use, copy, modify, and/or 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 _OCTEON_ATOMIC_H_ +#define _OCTEON_ATOMIC_H_ + +#ifdef _KERNEL + +static inline void +octeon_syncw(void) +{ + __asm__ volatile ( + " .set push\n" + " .set arch=octeon\n" + /* Issue the barrier twice to work around CN3xxx erratum Core-401. + * A single syncw might not enforce write ordering properly. */ + " syncw\n" + " syncw\n" + " .set pop\n" + : : : "memory"); +} + +#define membar_consumer() __asm__ volatile ("" : : : "memory") +#define membar_producer() octeon_syncw() + +#endif /* _KERNEL */ + +#include + +#endif /* !_OCTEON_ATOMIC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/autoconf.h b/lib/libc/include/mips64-openbsd-none/octeon/autoconf.h new file mode 100644 index 0000000000..0b9aa66be9 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/autoconf.h @@ -0,0 +1,58 @@ +/* $OpenBSD: autoconf.h,v 1.4 2019/07/12 03:03:48 visa Exp $ */ + +/* + * Copyright (c) 2001-2003 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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. + * + */ + +/* + * Definitions used by autoconfiguration. + */ + +#ifndef _MACHINE_AUTOCONF_H_ +#define _MACHINE_AUTOCONF_H_ + +#include + +struct mainbus_attach_args { + const char *maa_name; +}; + +extern struct device *bootdv; +extern char bootdev[]; +extern char uboot_rootdev[]; +extern enum devclass bootdev_class; + +#include + +void com_fdt_init_cons(void); +void parse_uboot_root(const char *); + +extern unsigned int octeon_ver; +#define OCTEON_1 0 +#define OCTEON_PLUS 1 +#define OCTEON_2 2 +#define OCTEON_3 3 + +#endif /* _MACHINE_AUTOCONF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/bus.h b/lib/libc/include/mips64-openbsd-none/octeon/bus.h new file mode 100644 index 0000000000..257157af06 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/bus.h @@ -0,0 +1,510 @@ +/* $OpenBSD: bus.h,v 1.8 2020/04/14 17:35:28 kettenis Exp $ */ + +/* + * Copyright (c) 2003-2004 Opsycon AB Sweden. 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_BUS_H_ +#define _MACHINE_BUS_H_ + +#ifdef __STDC__ +#define CAT(a,b) a##b +#define CAT3(a,b,c) a##b##c +#else +#define CAT(a,b) a/**/b +#define CAT3(a,b,c) a/**/b/**/c +#endif + +/* + * Bus access types. + */ +struct mips_bus_space; +typedef u_long bus_addr_t; +typedef u_long bus_size_t; +typedef u_long bus_space_handle_t; +typedef struct mips_bus_space *bus_space_tag_t; +typedef struct mips_bus_space bus_space_t; + +struct mips_bus_space { + bus_addr_t bus_base; + void *bus_private; + u_int8_t (*_space_read_1)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_1)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int8_t); + u_int16_t (*_space_read_2)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_2)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int16_t); + u_int32_t (*_space_read_4)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_4)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int32_t); + u_int64_t (*_space_read_8)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_8)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int64_t); + void (*_space_read_raw_2)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, u_int8_t *, bus_size_t); + void (*_space_write_raw_2)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const u_int8_t *, bus_size_t); + void (*_space_read_raw_4)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, u_int8_t *, bus_size_t); + void (*_space_write_raw_4)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const u_int8_t *, bus_size_t); + void (*_space_read_raw_8)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, u_int8_t *, bus_size_t); + void (*_space_write_raw_8)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const u_int8_t *, bus_size_t); + int (*_space_map)(bus_space_tag_t , bus_addr_t, + bus_size_t, int, bus_space_handle_t *); + void (*_space_unmap)(bus_space_tag_t, bus_space_handle_t, + bus_size_t); + int (*_space_subregion)(bus_space_tag_t, bus_space_handle_t, + bus_size_t, bus_size_t, bus_space_handle_t *); + void * (*_space_vaddr)(bus_space_tag_t, bus_space_handle_t); +}; + +#define bus_space_read_1(t, h, o) (*(t)->_space_read_1)((t), (h), (o)) +#define bus_space_read_2(t, h, o) (*(t)->_space_read_2)((t), (h), (o)) +#define bus_space_read_4(t, h, o) (*(t)->_space_read_4)((t), (h), (o)) +#define bus_space_read_8(t, h, o) (*(t)->_space_read_8)((t), (h), (o)) + +#define bus_space_write_1(t, h, o, v) (*(t)->_space_write_1)((t), (h), (o), (v)) +#define bus_space_write_2(t, h, o, v) (*(t)->_space_write_2)((t), (h), (o), (v)) +#define bus_space_write_4(t, h, o, v) (*(t)->_space_write_4)((t), (h), (o), (v)) +#define bus_space_write_8(t, h, o, v) (*(t)->_space_write_8)((t), (h), (o), (v)) + +#define bus_space_read_raw_multi_2(t, h, a, b, l) \ + (*(t)->_space_read_raw_2)((t), (h), (a), (b), (l)) +#define bus_space_read_raw_multi_4(t, h, a, b, l) \ + (*(t)->_space_read_raw_4)((t), (h), (a), (b), (l)) +#define bus_space_read_raw_multi_8(t, h, a, b, l) \ + (*(t)->_space_read_raw_8)((t), (h), (a), (b), (l)) + +#define bus_space_write_raw_multi_2(t, h, a, b, l) \ + (*(t)->_space_write_raw_2)((t), (h), (a), (b), (l)) +#define bus_space_write_raw_multi_4(t, h, a, b, l) \ + (*(t)->_space_write_raw_4)((t), (h), (a), (b), (l)) +#define bus_space_write_raw_multi_8(t, h, a, b, l) \ + (*(t)->_space_write_raw_8)((t), (h), (a), (b), (l)) + +#define bus_space_map(t, o, s, c, p) (*(t)->_space_map)((t), (o), (s), (c), (p)) +#define bus_space_unmap(t, h, s) (*(t)->_space_unmap)((t), (h), (s)) +#define bus_space_subregion(t, h, o, s, p) \ + (*(t)->_space_subregion)((t), (h), (o), (s), (p)) + +#define BUS_SPACE_MAP_CACHEABLE 0x01 +#define BUS_SPACE_MAP_KSEG0 0x02 +#define BUS_SPACE_MAP_LINEAR 0x04 +#define BUS_SPACE_MAP_PREFETCHABLE 0x08 + +#define bus_space_vaddr(t, h) (*(t)->_space_vaddr)((t), (h)) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_multi(n,m) \ +static __inline void \ +CAT(bus_space_read_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_size_t o, CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) \ + *x++ = CAT(bus_space_read_,n)(bst, bsh, o); \ +} + +bus_space_read_multi(1,8) +bus_space_read_multi(2,16) +bus_space_read_multi(4,32) +bus_space_read_multi(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_region(n,m) \ +static __inline void \ +CAT(bus_space_read_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) { \ + *x++ = CAT(bus_space_read_,n)(bst, bsh, ba); \ + ba += (n); \ + } \ +} + +bus_space_read_region(1,8) +bus_space_read_region(2,16) +bus_space_read_region(4,32) +bus_space_read_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_raw_region(n,m) \ +static __inline void \ +CAT(bus_space_read_raw_region_,n)(bus_space_tag_t bst, \ + bus_space_handle_t bsh, \ + bus_addr_t ba, u_int8_t *x, size_t cnt) \ +{ \ + cnt >>= ((n) >> 1); \ + while (cnt--) { \ + CAT(bus_space_read_raw_multi_,n)(bst, bsh, ba, x, (n)); \ + ba += (n); \ + x += (n); \ + } \ +} + +bus_space_read_raw_region(2,16) +bus_space_read_raw_region(4,32) +bus_space_read_raw_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_multi(n,m) \ +static __inline void \ +CAT(bus_space_write_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_size_t o, const CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) \ + CAT(bus_space_write_,n)(bst, bsh, o, *x++); \ +} + +bus_space_write_multi(1,8) +bus_space_write_multi(2,16) +bus_space_write_multi(4,32) +bus_space_write_multi(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_region(n,m) \ +static __inline void \ +CAT(bus_space_write_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, const CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) { \ + CAT(bus_space_write_,n)(bst, bsh, ba, *x++); \ + ba += (n); \ + } \ +} + +bus_space_write_region(1,8) +bus_space_write_region(2,16) +bus_space_write_region(4,32) +bus_space_write_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_raw_region(n,m) \ +static __inline void \ +CAT(bus_space_write_raw_region_,n)(bus_space_tag_t bst, \ + bus_space_handle_t bsh, \ + bus_addr_t ba, const u_int8_t *x, size_t cnt) \ +{ \ + cnt >>= ((n) >> 1); \ + while (cnt--) { \ + CAT(bus_space_write_raw_multi_,n)(bst, bsh, ba, x, (n)); \ + ba += (n); \ + x += (n); \ + } \ +} + +bus_space_write_raw_region(2,16) +bus_space_write_raw_region(4,32) +bus_space_write_raw_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_set_region(n,m) \ +static __inline void \ +CAT(bus_space_set_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, CAT3(u_int,m,_t) x, size_t cnt) \ +{ \ + while (cnt--) { \ + CAT(bus_space_write_,n)(bst, bsh, ba, x); \ + ba += (n); \ + } \ +} + +bus_space_set_region(1,8) +bus_space_set_region(2,16) +bus_space_set_region(4,32) +bus_space_set_region(8,64) + +/*----------------------------------------------------------------------------*/ +static __inline void +bus_space_copy_1(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + char *s = (char *)(h1 + o1); + char *d = (char *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + + +static __inline void +bus_space_copy_2(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + short *s = (short *)(h1 + o1); + short *d = (short *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + +static __inline void +bus_space_copy_4(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + int *s = (int *)(h1 + o1); + int *d = (int *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + +static __inline void +bus_space_copy_8(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + int64_t *s = (int64_t *)(h1 + o1); + int64_t *d = (int64_t *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + +/*----------------------------------------------------------------------------*/ +/* + * Bus read/write barrier methods. + * + * void bus_space_barrier(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * bus_size_t len, int flags); + * + */ +static inline void +bus_space_barrier(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, + bus_size_t length, int flags) +{ + __asm__ volatile ("sync" ::: "memory"); +} +#define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */ +#define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */ + +#define BUS_DMA_WAITOK 0x0000 +#define BUS_DMA_NOWAIT 0x0001 +#define BUS_DMA_ALLOCNOW 0x0002 +#define BUS_DMA_COHERENT 0x0008 +#define BUS_DMA_BUS1 0x0010 /* placeholders for bus functions... */ +#define BUS_DMA_BUS2 0x0020 +#define BUS_DMA_BUS3 0x0040 +#define BUS_DMA_BUS4 0x0080 +#define BUS_DMA_READ 0x0100 /* mapping is device -> memory only */ +#define BUS_DMA_WRITE 0x0200 /* mapping is memory -> device only */ +#define BUS_DMA_STREAMING 0x0400 /* hint: sequential, unidirectional */ +#define BUS_DMA_ZERO 0x0800 /* zero memory in dmamem_alloc */ +#define BUS_DMA_NOCACHE 0x1000 +#define BUS_DMA_64BIT 0x2000 /* device handles 64bit dva */ + +/* Forwards needed by prototypes below. */ +struct mbuf; +struct proc; +struct uio; + +#define BUS_DMASYNC_POSTREAD 0x0001 +#define BUS_DMASYNC_POSTWRITE 0x0002 +#define BUS_DMASYNC_PREREAD 0x0004 +#define BUS_DMASYNC_PREWRITE 0x0008 + +typedef struct machine_bus_dma_tag *bus_dma_tag_t; +typedef struct machine_bus_dmamap *bus_dmamap_t; + +/* + * bus_dma_segment_t + * + * Describes a single contiguous DMA transaction. Values + * are suitable for programming into DMA registers. + */ +struct machine_bus_dma_segment { + bus_addr_t ds_addr; /* DMA address */ + bus_size_t ds_len; /* length of transfer */ + + paddr_t _ds_paddr; /* CPU address */ + vaddr_t _ds_vaddr; /* CPU address */ +}; +typedef struct machine_bus_dma_segment bus_dma_segment_t; + +/* + * bus_dma_tag_t + * + * A machine-dependent opaque type describing the implementation of + * DMA for a given bus. + */ + +struct machine_bus_dma_tag { + void *_cookie; /* cookie used in the guts */ + + /* + * DMA mapping methods. + */ + int (*_dmamap_create)(bus_dma_tag_t , bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); + void (*_dmamap_destroy)(bus_dma_tag_t , bus_dmamap_t); + int (*_dmamap_load)(bus_dma_tag_t , bus_dmamap_t, void *, + bus_size_t, struct proc *, int); + int (*_dmamap_load_mbuf)(bus_dma_tag_t , bus_dmamap_t, + struct mbuf *, int); + int (*_dmamap_load_uio)(bus_dma_tag_t , bus_dmamap_t, + struct uio *, int); + int (*_dmamap_load_raw)(bus_dma_tag_t , bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); + int (*_dmamap_load_buffer)(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int, paddr_t *, int *, int); + void (*_dmamap_unload)(bus_dma_tag_t , bus_dmamap_t); + void (*_dmamap_sync)(bus_dma_tag_t , bus_dmamap_t, + bus_addr_t, bus_size_t, int); + + /* + * DMA memory utility functions. + */ + int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); + void (*_dmamem_free)(bus_dma_tag_t, bus_dma_segment_t *, int); + int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); + void (*_dmamem_unmap)(bus_dma_tag_t, caddr_t, size_t); + paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *, + int, off_t, int, int); + + /* + * internal memory address translation information. + */ + bus_addr_t (*_pa_to_device)(paddr_t); + paddr_t (*_device_to_pa)(bus_addr_t); + bus_addr_t _dma_mask; +}; + +#define bus_dmamap_create(t, s, n, m, b, f, p) \ + (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p)) +#define bus_dmamap_destroy(t, p) \ + (*(t)->_dmamap_destroy)((t), (p)) +#define bus_dmamap_load(t, m, b, s, p, f) \ + (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f)) +#define bus_dmamap_load_mbuf(t, m, b, f) \ + (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f)) +#define bus_dmamap_load_uio(t, m, u, f) \ + (*(t)->_dmamap_load_uio)((t), (m), (u), (f)) +#define bus_dmamap_load_raw(t, m, sg, n, s, f) \ + (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f)) +#define bus_dmamap_unload(t, p) \ + (*(t)->_dmamap_unload)((t), (p)) +#define bus_dmamap_sync(t, p, a, l, o) \ + (void)((t)->_dmamap_sync ? \ + (*(t)->_dmamap_sync)((t), (p), (a), (l), (o)) : (void)0) + +#define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \ + (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f)) +#define bus_dmamem_free(t, sg, n) \ + (*(t)->_dmamem_free)((t), (sg), (n)) +#define bus_dmamem_map(t, sg, n, s, k, f) \ + (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f)) +#define bus_dmamem_unmap(t, k, s) \ + (*(t)->_dmamem_unmap)((t), (k), (s)) +#define bus_dmamem_mmap(t, sg, n, o, p, f) \ + (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f)) + +int _dmamap_create(bus_dma_tag_t, bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); +void _dmamap_destroy(bus_dma_tag_t, bus_dmamap_t); +int _dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int); +int _dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, struct mbuf *, int); +int _dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, struct uio *, int); +int _dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); +int _dmamap_load_buffer(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int, paddr_t *, int *, int); +void _dmamap_unload(bus_dma_tag_t, bus_dmamap_t); +void _dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, + bus_size_t, int); + +int _dmamem_alloc(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); +void _dmamem_free(bus_dma_tag_t, bus_dma_segment_t *, int); +int _dmamem_map(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); +void _dmamem_unmap(bus_dma_tag_t, caddr_t, size_t); +paddr_t _dmamem_mmap(bus_dma_tag_t, bus_dma_segment_t *, int, off_t, int, int); +int _dmamem_alloc_range(bus_dma_tag_t, bus_size_t, bus_size_t, bus_size_t, + bus_dma_segment_t *, int, int *, int, paddr_t, paddr_t); + +/* + * bus_dmamap_t + * + * Describes a DMA mapping. + */ +struct machine_bus_dmamap { + /* + * PRIVATE MEMBERS: not for use by machine-independent code. + */ + bus_size_t _dm_size; /* largest DMA transfer mappable */ + int _dm_segcnt; /* number of segs this map can map */ + bus_size_t _dm_maxsegsz; /* largest possible segment */ + bus_size_t _dm_boundary; /* don't cross this */ + int _dm_flags; /* misc. flags */ + + void *_dm_cookie; /* cookie for bus-specific functions */ + + /* + * PUBLIC MEMBERS: these are used by machine-independent code. + */ + bus_size_t dm_mapsize; /* size of the mapping */ + int dm_nsegs; /* # valid segments in mapping */ + bus_dma_segment_t dm_segs[1]; /* segments; variable length */ +}; + +int generic_space_map(bus_space_tag_t, bus_addr_t, bus_size_t, int, + bus_space_handle_t *); +void generic_space_unmap(bus_space_tag_t, bus_space_handle_t, bus_size_t); +int generic_space_region(bus_space_tag_t, bus_space_handle_t, bus_size_t, + bus_size_t, bus_space_handle_t *); +void *generic_space_vaddr(bus_space_tag_t, bus_space_handle_t); +uint8_t generic_space_read_1(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint16_t generic_space_read_2(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint32_t generic_space_read_4(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint64_t generic_space_read_8(bus_space_tag_t, bus_space_handle_t, bus_size_t); +void generic_space_read_raw_2(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_1(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint8_t); +void generic_space_write_2(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint16_t); +void generic_space_write_4(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint32_t); +void generic_space_write_8(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint64_t); +void generic_space_write_raw_2(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); +void generic_space_read_raw_4(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_raw_4(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); +void generic_space_read_raw_8(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_raw_8(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); + +#endif /* _MACHINE_BUS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/cdefs.h b/lib/libc/include/mips64-openbsd-none/octeon/cdefs.h new file mode 100644 index 0000000000..e44353fedf --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/cdefs.h @@ -0,0 +1,3 @@ +/* $OpenBSD: cdefs.h,v 1.2 2013/03/28 17:30:45 martynas Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/conf.h b/lib/libc/include/mips64-openbsd-none/octeon/conf.h new file mode 100644 index 0000000000..df1ce719b2 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/conf.h @@ -0,0 +1,55 @@ +/* $OpenBSD: conf.h,v 1.4 2022/06/28 14:43:50 visa Exp $ */ +/* $NetBSD: conf.h,v 1.2 1996/05/05 19:28:34 christos Exp $ */ + +/* + * Copyright (c) 1996 Christos Zoulas. 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 Christos Zoulas. + * 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 _OCTEON_CONF_H_ +#define _OCTEON_CONF_H_ + +#include + +/* open, close, ioctl */ +#define cdev_octboot_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) nullop, 0, \ + (dev_type_mmap((*))) enodev } + +/* open, close, ioctl */ +#define cdev_openprom_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) nullop, 0, \ + (dev_type_mmap((*))) enodev } + +cdev_decl(octboot); +cdev_decl(openprom); + +#endif /* _OCTEON_CONF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/cpu.h b/lib/libc/include/mips64-openbsd-none/octeon/cpu.h new file mode 100644 index 0000000000..e5e26d7837 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/cpu.h @@ -0,0 +1,106 @@ +/* $OpenBSD: cpu.h,v 1.12 2018/02/18 14:50:08 visa 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 and Rick Macklem. + * + * 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. + * + * Copyright (C) 1989 Digital Equipment Corporation. + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby granted, + * provided that the above copyright notice appears in all copies. + * Digital Equipment Corporation makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * from: @(#)cpu.h 8.4 (Berkeley) 1/4/94 + */ + +#ifndef _MACHINE_CPU_H_ +#define _MACHINE_CPU_H_ + +#ifdef _KERNEL + +#define OCTEON_MAXCPUS 16 + +#if defined(MULTIPROCESSOR) && !defined(_LOCORE) +#define MAXCPUS OCTEON_MAXCPUS +struct cpu_info; +void hw_cpu_boot_secondary(struct cpu_info *); +void hw_cpu_hatch(struct cpu_info *); +void hw_cpu_spinup_trampoline(struct cpu_info *); +int hw_ipi_intr_establish(int (*)(void *), u_long); +void hw_ipi_intr_set(u_long); +void hw_ipi_intr_clear(u_long); + +/* Keep in sync with HW_GET_CPU_INFO(). */ +static inline struct cpu_info * +hw_getcurcpu(void) +{ + struct cpu_info *ci; + __asm__ volatile ("dmfc0 %0, $30" /* ErrorEPC */ : "=r" (ci)); + return ci; +} + +static inline void +hw_setcurcpu(struct cpu_info *ci) +{ + __asm__ volatile ("dmtc0 %0, $30" /* ErrorEPC */ : : "r" (ci)); +} +#endif /* MULTIPROCESSOR && !_LOCORE */ + +#define CACHELINESIZE 128 + +/* + * No need to use the per-cpu_info function pointers, as we only support + * one processor type. + */ +#define Mips_SyncCache(ci) \ + Octeon_SyncCache((ci)) +#define Mips_InvalidateICache(ci, va, l) \ + Octeon_InvalidateICache((ci), (va), (l)) +#define Mips_InvalidateICachePage(ci, va) \ + Octeon_InvalidateICachePage((ci), (va)) +#define Mips_SyncICache(ci) \ + Octeon_SyncICache((ci)) +#define Mips_SyncDCachePage(ci, va, pa) \ + Octeon_SyncDCachePage((ci), (va), (pa)) +#define Mips_HitSyncDCachePage(ci, va, pa) \ + Octeon_SyncDCachePage((ci), (va), (pa)) +#define Mips_HitSyncDCache(ci, va, l) \ + Octeon_HitSyncDCache((ci), (va), (l)) +#define Mips_IOSyncDCache(ci, va, l, h) \ + Octeon_IOSyncDCache((ci), (va), (l), (h)) +#define Mips_HitInvalidateDCache(ci, va, l) \ + Octeon_HitInvalidateDCache((ci), (va), (l)) + +#endif/* _KERNEL */ + +#include + +#endif /* !_MACHINE_CPU_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/cpustate.h b/lib/libc/include/mips64-openbsd-none/octeon/cpustate.h new file mode 100644 index 0000000000..d0dcf0e7c0 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/cpustate.h @@ -0,0 +1,3 @@ +/* $OpenBSD: cpustate.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/db_machdep.h b/lib/libc/include/mips64-openbsd-none/octeon/db_machdep.h new file mode 100644 index 0000000000..3a3271b423 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/db_machdep.h @@ -0,0 +1,3 @@ +/* $OpenBSD: db_machdep.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/disklabel.h b/lib/libc/include/mips64-openbsd-none/octeon/disklabel.h new file mode 100644 index 0000000000..e7758205f6 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/disklabel.h @@ -0,0 +1,16 @@ +/* $OpenBSD: disklabel.h,v 1.3 2015/09/30 15:35:30 krw Exp $ */ +/* public domain */ + +/* + * Standard MBR partition scheme, with the label in the second sector + * of the OpenBSD partition. + */ + +#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_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/elf.h b/lib/libc/include/mips64-openbsd-none/octeon/elf.h new file mode 100644 index 0000000000..5918df727b --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/elf.h @@ -0,0 +1,3 @@ +/* $OpenBSD: elf.h,v 1.1 2024/07/14 19:33:59 miod Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/endian.h b/lib/libc/include/mips64-openbsd-none/octeon/endian.h new file mode 100644 index 0000000000..2bfd2b1abd --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/endian.h @@ -0,0 +1,3 @@ +/* $OpenBSD: endian.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/exec.h b/lib/libc/include/mips64-openbsd-none/octeon/exec.h new file mode 100644 index 0000000000..498f7f2eca --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/exec.h @@ -0,0 +1,3 @@ +/* $OpenBSD: exec.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/fdt.h b/lib/libc/include/mips64-openbsd-none/octeon/fdt.h new file mode 100644 index 0000000000..4033bc9a0c --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/fdt.h @@ -0,0 +1,40 @@ +/* $OpenBSD: fdt.h,v 1.2 2018/08/06 10:52:30 patrick Exp $ */ + +/* + * Copyright (c) 2016 Patrick Wildt + * + * 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 __OCTEON_FDT_H__ +#define __OCTEON_FDT_H__ + +#include + +struct fdt_attach_args { + const char *fa_name; + int fa_node; + bus_space_tag_t fa_iot; + bus_dma_tag_t fa_dmat; + struct fdt_reg *fa_reg; + int fa_nreg; + uint32_t *fa_intr; + int fa_nintr; + int fa_acells; + int fa_scells; +}; + +#define fdt_intr_establish octeon_intr_establish_fdt +#define fdt_intr_disestablish octeon_intr_disestablish_fdt + +#endif /* __OCTEON_FDT_H__ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/fenv.h b/lib/libc/include/mips64-openbsd-none/octeon/fenv.h new file mode 100644 index 0000000000..08e89fbf32 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/fenv.h @@ -0,0 +1,3 @@ +/* $OpenBSD: fenv.h,v 1.2 2013/06/01 21:20:54 jasper Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/fpu.h b/lib/libc/include/mips64-openbsd-none/octeon/fpu.h new file mode 100644 index 0000000000..3d415d39b4 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/fpu.h @@ -0,0 +1,3 @@ +/* $OpenBSD: fpu.h,v 1.1 2010/10/03 06:03:57 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/frame.h b/lib/libc/include/mips64-openbsd-none/octeon/frame.h new file mode 100644 index 0000000000..f8295979a3 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/frame.h @@ -0,0 +1,3 @@ +/* $OpenBSD: frame.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/ieee.h b/lib/libc/include/mips64-openbsd-none/octeon/ieee.h new file mode 100644 index 0000000000..8a538bc8eb --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/ieee.h @@ -0,0 +1,3 @@ +/* $OpenBSD: ieee.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/ieeefp.h b/lib/libc/include/mips64-openbsd-none/octeon/ieeefp.h new file mode 100644 index 0000000000..2060e7a21f --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/ieeefp.h @@ -0,0 +1,3 @@ +/* $OpenBSD: ieeefp.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/intr.h b/lib/libc/include/mips64-openbsd-none/octeon/intr.h new file mode 100644 index 0000000000..eef4afc728 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/intr.h @@ -0,0 +1,186 @@ +/* $OpenBSD: intr.h,v 1.23 2025/05/10 10:01:03 visa Exp $ */ + +/* + * Copyright (c) 2001-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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_INTR_H_ +#define _MACHINE_INTR_H_ + +#define __USE_MI_SOFTINTR + +#include + +/* + * The interrupt level ipl is a logical level; per-platform interrupt + * code will turn it into the appropriate hardware interrupt masks + * values. + * + * Interrupt sources on the CPU are kept enabled regardless of the + * current ipl value; individual hardware sources interrupting while + * logically masked are masked on the fly, remembered as pending, and + * unmasked at the first splx() opportunity. + * + * An exception to this rule is the clock interrupt. Clock interrupts + * are always allowed to happen, but will (of course!) not be serviced + * if logically masked. The reason for this is that clocks usually sit on + * INT5 and cannot be easily masked if external hardware masking is used. + */ + +/* Interrupt priority `levels'; not mutually exclusive. */ +#define IPL_NONE 0 /* nothing */ +#define IPL_SOFTINT 1 /* soft interrupts */ +#define IPL_SOFTCLOCK 1 /* soft clock interrupts */ +#define IPL_SOFTNET 2 /* soft network interrupts */ +#define IPL_SOFTTTY 3 /* soft terminal interrupts */ +#define IPL_SOFTHIGH IPL_SOFTTTY /* highest level of soft interrupts */ +#define IPL_BIO 4 /* block I/O */ +#define IPL_AUDIO IPL_BIO +#define IPL_NET 5 /* network */ +#define IPL_TTY 6 /* terminal */ +#define IPL_VM 7 /* memory allocation */ +#define IPL_CLOCK 8 /* clock */ +#define IPL_SCHED IPL_CLOCK +#define IPL_HIGH 9 /* everything */ +#define IPL_IPI 10 /* interprocessor interrupt */ +#define NIPLS 11 /* number of levels */ + +#define IPL_MPFLOOR IPL_TTY + +/* Interrupt priority 'flags'. */ +#define IPL_MPSAFE 0x100 + +/* Interrupt sharing types. */ +#define IST_NONE 0 /* none */ +#define IST_PULSE 1 /* pulsed */ +#define IST_EDGE 2 /* edge-triggered */ +#define IST_LEVEL 3 /* level-triggered */ + +#ifndef _LOCORE + +void softintr(int); + +#define splbio() splraise(IPL_BIO) +#define splnet() splraise(IPL_NET) +#define spltty() splraise(IPL_TTY) +#define splaudio() splraise(IPL_AUDIO) +#define splvm() splraise(IPL_VM) +#define splclock() splraise(IPL_CLOCK) +#define splsched() splraise(IPL_SCHED) +#define splhigh() splraise(IPL_HIGH) + +#define splsoftclock() splraise(IPL_SOFTCLOCK) +#define splsoftnet() splraise(IPL_SOFTNET) +#define splstatclock() splhigh() + +#define spl0() spllower(0) + +void splinit(void); + +#ifdef DIAGNOSTIC +/* + * Although this function is implemented in MI code, it must be in this MD + * header because we don't want this header to include MI includes. + */ +void splassert_fail(int, int, const char *); +extern int splassert_ctl; +void splassert_check(int, const char *); +#define splassert(__wantipl) do { \ + if (splassert_ctl > 0) { \ + splassert_check(__wantipl, __func__); \ + } \ +} while (0) +#define splsoftassert(wantipl) splassert(wantipl) +#else +#define splassert(X) +#define splsoftassert(X) +#endif + +void register_splx_handler(void (*)(int)); +int splraise(int); +void splx(int); +int spllower(int); + +void intr_barrier(void *); + +/* + * Low level interrupt dispatcher registration data. + */ + +/* Schedule priorities for base interrupts (CPU) */ +#define INTPRI_IPI 0 +#define INTPRI_CLOCK 1 +/* other values are system-specific */ + +#define NLOWINT 16 /* Number of low level registrations possible */ + +extern uint32_t idle_mask; + +struct trapframe; +void set_intr(int, uint32_t, uint32_t(*)(uint32_t, struct trapframe *)); + +uint32_t updateimask(uint32_t); +void dosoftint(void); + +struct intr_controller { + void *ic_cookie; + void (*ic_init)(void); + void *(*ic_establish)(int, int, int (*)(void *), void *, + const char *); + void *(*ic_establish_fdt_idx)(void *, int, int, int, + int (*)(void *), void *, const char *); + void (*ic_disestablish)(void *); + void (*ic_intr_barrier)(void *); + +#ifdef MULTIPROCESSOR + int (*ic_ipi_establish)(int (*)(void *), cpuid_t); + void (*ic_ipi_set)(cpuid_t); + void (*ic_ipi_clear)(cpuid_t); +#endif /* MULTIPROCESSOR */ + + int ic_node; + int ic_phandle; + LIST_ENTRY(intr_controller) ic_list; +}; + +#ifdef MULTIPROCESSOR +#define ENABLEIPI() updateimask(~CR_INT_1) /* enable IPI interrupt level */ +#endif + +void *octeon_intr_establish(int, int, int (*)(void *), + void *, const char *); +void octeon_intr_disestablish(void *); +void octeon_intr_init(void); +void octeon_intr_register(struct intr_controller *); + +void *octeon_intr_establish_fdt(int, int, int (*)(void *), + void *, const char *); +void *octeon_intr_establish_fdt_idx(int, int, int, int (*)(void *), + void *, const char *); +void octeon_intr_disestablish_fdt(void *); + +#endif /* _LOCORE */ + +#endif /* _MACHINE_INTR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/kcore.h b/lib/libc/include/mips64-openbsd-none/octeon/kcore.h new file mode 100644 index 0000000000..b221eb2048 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/kcore.h @@ -0,0 +1,3 @@ +/* $OpenBSD: kcore.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/limits.h b/lib/libc/include/mips64-openbsd-none/octeon/limits.h new file mode 100644 index 0000000000..06574d0acb --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/limits.h @@ -0,0 +1,3 @@ +/* $OpenBSD: limits.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/loadfile_machdep.h b/lib/libc/include/mips64-openbsd-none/octeon/loadfile_machdep.h new file mode 100644 index 0000000000..1486f8ce5c --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/loadfile_machdep.h @@ -0,0 +1,49 @@ +/* $OpenBSD: loadfile_machdep.h,v 1.2 2015/07/17 20:44:39 miod Exp $ */ +/* $NetBSD: loadfile_machdep.h,v 1.2 2001/10/31 17:20:49 thorpej Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * 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. + */ + +#define BOOT_ELF +#define ELFSIZE 64 + +#define LOAD_KERNEL LOAD_ALL +#define COUNT_KERNEL COUNT_ALL + +#define LOADADDR(a) (((u_long)(a)) + offset) +#define ALIGNENTRY(a) ((u_long)(a)) +#define READ(f, b, c) read((f), (void *)LOADADDR(b), (c)) +#define BCOPY(s, d, c) memcpy((void *)LOADADDR(d), (void *)(s), (c)) +#define BZERO(d, c) memset((void *)LOADADDR(d), 0, (c)) +#define WARN(a) (void)(printf a, \ + printf((errno ? ": %s\n" : "\n"), \ + strerror(errno))) +#define PROGRESS(a) (void) printf a +#define ALLOC(a) alloc(a) +#define FREE(a, b) free(a, b) \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/memconf.h b/lib/libc/include/mips64-openbsd-none/octeon/memconf.h new file mode 100644 index 0000000000..ec2791c749 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/memconf.h @@ -0,0 +1,3 @@ +/* $OpenBSD: memconf.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/mips_opcode.h b/lib/libc/include/mips64-openbsd-none/octeon/mips_opcode.h new file mode 100644 index 0000000000..865ce02ebe --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/mips_opcode.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mips_opcode.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/mplock.h b/lib/libc/include/mips64-openbsd-none/octeon/mplock.h new file mode 100644 index 0000000000..f15d109545 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/mplock.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mplock.h,v 1.2 2015/09/09 15:48:52 visa Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/mutex.h b/lib/libc/include/mips64-openbsd-none/octeon/mutex.h new file mode 100644 index 0000000000..9a15499276 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/mutex.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mutex.h,v 1.3 2015/07/08 13:37:31 dlg Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/octboot.h b/lib/libc/include/mips64-openbsd-none/octeon/octboot.h new file mode 100644 index 0000000000..1a889f7b6a --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/octboot.h @@ -0,0 +1,36 @@ +/* $OpenBSD: octboot.h,v 1.2 2020/05/26 13:21:58 visa Exp $ */ + +/* + * Copyright (c) 2019-2020 Visa Hankala + * + * Permission to use, copy, modify, and/or 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 _OCTEON_OCTBOOT_H_ +#define _OCTEON_OCTBOOT_H_ + +#include + +#define OCTBOOT_MAX_ARGS 8 /* maximum number of boot arguments */ + +struct octboot_kexec_args { + char *kimg; /* kernel image buffer */ + size_t klen; /* size of kernel image */ + char *argv[OCTBOOT_MAX_ARGS]; + /* kernel boot arguments */ +}; + +#define OBIOC_KEXEC _IOW('O', 1, struct octboot_kexec_args) +#define OBIOC_GETROOTDEV _IOR('O', 2, char[PATH_MAX]) + +#endif /* !_OCTEON_OCTBOOT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/octeon_model.h b/lib/libc/include/mips64-openbsd-none/octeon/octeon_model.h new file mode 100644 index 0000000000..cac7c19ef9 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/octeon_model.h @@ -0,0 +1,87 @@ +/* $OpenBSD: octeon_model.h,v 1.9 2024/06/26 01:40:49 jsg Exp $ */ + +/* + * Copyright (c) 2007 + * Internet Initiative Japan, Inc. 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 AUTHORS 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 AUTHORS 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 _MIPS_OCTEON_MODEL_H_ +#define _MIPS_OCTEON_MODEL_H_ + +#define OCTEON_MODEL_CN38XX_REV1 0x000d0000 +#define OCTEON_MODEL_CN38XX_REV2 0x000d0001 +#define OCTEON_MODEL_CN38XX_REV3 0x000d0003 +#define OCTEON_MODEL_CN3100 0x000d0100 +#define OCTEON_MODEL_CN3020 0x000d0110 +#define OCTEON_MODEL_CN3010 0x000d0200 +#define OCTEON_MODEL_CN3005 0x000d0210 +#define OCTEON_MODEL_CN5010 0x000d0600 +#define OCTEON_MODEL_CN5010_PASS1_1 0x000d0601 +#define OCTEON_MODEL_CN61XX_PASS1_0 0x000d9300 +#define OCTEON_MODEL_CN61XX_PASS1_1 0x000d9301 + +#define OCTEON_MODEL_MASK 0x00ffff10 +#define OCTEON_MODEL_REV_MASK 0x00ffff1f +#define OCTEON_MODEL_FAMILY_MASK 0x00ffff00 +#define OCTEON_MODEL_FAMILY_REV_MASK 0x00ffff0f + +#define OCTEON_MODEL_FAMILY_CN58XX 0x000d0300 +#define OCTEON_MODEL_FAMILY_CN56XX 0x000d0400 +#define OCTEON_MODEL_FAMILY_CN38XX 0x000d0000 +#define OCTEON_MODEL_FAMILY_CN31XX 0x000d0100 +#define OCTEON_MODEL_FAMILY_CN30XX 0x000d0200 +#define OCTEON_MODEL_FAMILY_CN50XX 0x000d0600 +#define OCTEON_MODEL_FAMILY_CN63XX 0x000d9000 +#define OCTEON_MODEL_FAMILY_CN68XX 0x000d9100 +#define OCTEON_MODEL_FAMILY_CN66XX 0x000d9200 +#define OCTEON_MODEL_FAMILY_CN61XX 0x000d9300 +#define OCTEON_MODEL_FAMILY_CN78XX 0x000d9500 +#define OCTEON_MODEL_FAMILY_CN71XX 0x000d9600 +#define OCTEON_MODEL_FAMILY_CN73XX 0x000d9700 + +/* + * get chip id + */ +static inline uint32_t +octeon_get_chipid(void) +{ + uint32_t tmp; + + asm volatile ( + " .set push \n" + " .set mips64 \n" + " .set noreorder \n" + " mfc0 %0, $15, 0 \n" + " .set pop \n" + : "=&r"(tmp) : ); + + return(tmp); +} + +#define octeon_model(id) ((id) & OCTEON_MODEL_MASK) +#define octeon_model_revision(id) ((id) & OCTEON_MODEL_REV_MASK) +#define octeon_model_family(id) ((id) & OCTEON_MODEL_FAMILY_MASK) +#define octeon_model_family_revision(id) ((id) & OCTEON_MODEL_FAMILY_REV_MASK) + +#endif \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/octeonreg.h b/lib/libc/include/mips64-openbsd-none/octeon/octeonreg.h new file mode 100644 index 0000000000..af75e6d7fb --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/octeonreg.h @@ -0,0 +1,198 @@ +/* $OpenBSD: octeonreg.h,v 1.11 2020/07/11 15:18:08 visa Exp $ */ + +/* + * Copyright (c) 2003-2004 Opsycon AB (www.opsycon.com). + * + * 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_OCTEONREG_H_ +#define _MACHINE_OCTEONREG_H_ + +#define OCTEON_CF_BASE 0x1D000800ULL +#define OCTEON_CIU3_BASE 0x1010000000000ULL +#define OCTEON_CIU_BASE 0x1070000000000ULL +#define OCTEON_CIU_SIZE 0x7000 +#define OCTEON_MIO_BOOT_BASE 0x1180000000000ULL +#define OCTEON_UART0_BASE 0x1180000000800ULL +#define OCTEON_UART1_BASE 0x1180000000C00ULL +#define OCTEON_RNG_BASE 0x1400000000000ULL +#define OCTEON_AMDCF_BASE 0x1dc00000ULL + +#define MIO_BOOT_REG_CFG0 0x0 +#define MIO_BOOT_REG_CFG(x) (MIO_BOOT_REG_CFG0+((x)*8)) +#define BOOT_CFG_BASE_MASK 0xFFFF +#define BOOT_CFG_BASE_SHIFT 16 +#define BOOT_CFG_WIDTH_MASK 0x10000000 +#define BOOT_CFG_WIDTH_SHIFT 28 + +#define CIU_INT_WORKQ0 0 +#define CIU_INT_WORKQ1 1 +#define CIU_INT_WORKQ2 2 +#define CIU_INT_WORKQ3 3 +#define CIU_INT_WORKQ4 4 +#define CIU_INT_WORKQ5 5 +#define CIU_INT_WORKQ6 6 +#define CIU_INT_WORKQ7 7 +#define CIU_INT_WORKQ8 8 +#define CIU_INT_WORKQ9 9 +#define CIU_INT_WORKQ10 10 +#define CIU_INT_WORKQ11 11 +#define CIU_INT_WORKQ12 12 +#define CIU_INT_WORKQ13 13 +#define CIU_INT_WORKQ14 14 +#define CIU_INT_WORKQ15 15 +#define CIU_INT_GPIO0 16 +#define CIU_INT_GPIO1 17 +#define CIU_INT_GPIO2 18 +#define CIU_INT_GPIO3 19 +#define CIU_INT_GPIO4 20 +#define CIU_INT_GPIO5 21 +#define CIU_INT_GPIO6 22 +#define CIU_INT_GPIO7 23 +#define CIU_INT_GPIO8 24 +#define CIU_INT_GPIO9 25 +#define CIU_INT_GPIO10 26 +#define CIU_INT_GPIO11 27 +#define CIU_INT_GPIO12 28 +#define CIU_INT_GPIO13 29 +#define CIU_INT_GPIO14 30 +#define CIU_INT_GPIO15 31 +#define CIU_INT_MBOX0 32 +#define CIU_INT_MBOX1 33 +#define CIU_INT_MBOX(x) (CIU_INT_MBOX0+(x)) +#define CIU_INT_UART0 34 +#define CIU_INT_UART1 35 +#define CIU_INT_PCI_INTA 36 +#define CIU_INT_PCI_INTB 37 +#define CIU_INT_PCI_INTC 38 +#define CIU_INT_PCI_INTD 39 +#define CIU_INT_PCI_MSIA 40 +#define CIU_INT_PCI_MSIB 41 +#define CIU_INT_PCI_MSIC 42 +#define CIU_INT_PCI_MSID 43 +#define CIU_INT_44 44 +#define CIU_INT_TWSI 45 +#define CIU_INT_RML 46 +#define CIU_INT_TRACE 47 +#define CIU_INT_GMX_DRP0 48 +#define CIU_INT_GMX_DRP1 49 +#define CIU_INT_IPD_DRP 50 +#define CIU_INT_KEY_ZERO 51 +#define CIU_INT_TIMER0 52 +#define CIU_INT_TIMER1 53 +#define CIU_INT_TIMER2 54 +#define CIU_INT_TIMER3 55 +#define CIU_INT_USB 56 +#define CIU_INT_PCM 57 +#define CIU_INT_MPI 58 +#define CIU_INT_TWSI2 59 +#define CIU_INT_POWIQ 60 +#define CIU_INT_IPDPPTHR 61 +#define CIU_INT_MII0 62 +#define CIU_INT_BOOTDMA 63 + +#define CIU_INT0_SUM0 0x00000000 +#define CIU_INT1_SUM0 0x00000008 +#define CIU_INT2_SUM0 0x00000010 +#define CIU_INT3_SUM0 0x00000018 +#define CIU_IP2_SUM0(x) (CIU_INT0_SUM0+(0x10 * (x))) +#define CIU_IP3_SUM0(x) (CIU_INT1_SUM0+(0x10 * (x))) +#define CIU_INT32_SUM0 0x00000100 +#define CIU_INT32_SUM1 0x00000108 +#define CIU_INT0_EN0 0x00000200 +#define CIU_INT1_EN0 0x00000210 +#define CIU_INT2_EN0 0x00000220 +#define CIU_INT3_EN0 0x00000230 +#define CIU_IP2_EN0(x) (CIU_INT0_EN0+(0x20 * (x))) +#define CIU_IP3_EN0(x) (CIU_INT1_EN0+(0x20 * (x))) +#define CIU_INT32_EN0 0x00000400 +#define CIU_INT0_EN1 0x00000208 +#define CIU_INT1_EN1 0x00000218 +#define CIU_INT2_EN1 0x00000228 +#define CIU_INT3_EN1 0x00000238 +#define CIU_INT32_EN1 0x00000408 +#define CIU_IP2_EN1(x) (CIU_INT0_EN1+(0x20 * (x))) +#define CIU_IP3_EN1(x) (CIU_INT1_EN1+(0x20 * (x))) +#define CIU_TIM0 0x00000480 +#define CIU_TIM1 0x00000488 +#define CIU_TIM2 0x00000490 +#define CIU_TIM3 0x00000498 +#define CIU_WDOG0 0x00000500 +#define CIU_WDOG1 0x00000508 +#define CIU_PP_POKE0 0x00000580 +#define CIU_PP_POKE1 0x00000588 +#define CIU_MBOX_SET0 0x00000600 +#define CIU_MBOX_SET1 0x00000608 +#define CIU_MBOX_SET(x) (CIU_MBOX_SET0+(0x08 * (x))) +#define CIU_MBOX_CLR0 0x00000680 +#define CIU_MBOX_CLR1 0x00000688 +#define CIU_MBOX_CLR(x) (CIU_MBOX_CLR0+(0x08 * (x))) +#define CIU_PP_RST 0x00000700 +#define CIU_PP_DBG 0x00000708 +#define CIU_GSTOP 0x00000710 +#define CIU_NMI 0x00000718 +#define CIU_DINT 0x00000720 +#define CIU_FUSE 0x00000728 +#define CIU_BIST 0x00000730 +#define CIU_SOFT_BIST 0x00000738 +#define CIU_SOFT_RST 0x00000740 +#define CIU_SOFT_PRST 0x00000748 +#define CIU_PCI_INTA 0x00000750 +#define CIU_INT0_SUM4 0x00000C00 +#define CIU_INT1_SUM4 0x00000C08 +#define CIU_INT0_EN4_0 0x00000C80 +#define CIU_INT1_EN4_0 0x00000C90 +#define CIU_INT0_EN4_1 0x00000C88 +#define CIU_INT1_EN4_1 0x00000C98 +#define CIU_IP4_SUM2(x) (0x00008c00 + 8 * (x)) +#define CIU_IP4_EN2(x) (0x0000a400 + 8 * (x)) + +#define CIU3_FUSE 0x000001a0 + +#define FPA3_CLK_COUNT 0x12800000000f0ULL + +/* OCTEON II */ +#define MIO_RST_BOOT 0x1180000001600ULL +#define MIO_RST_BOOT_C_MUL_SHIFT 30 +#define MIO_RST_BOOT_C_MUL_MASK 0x7f +#define MIO_RST_BOOT_PNR_MUL_SHIFT 24 +#define MIO_RST_BOOT_PNR_MUL_MASK 0x3f + +#define MIO_RST_CTL(x) (0x1180000001618ULL + 8 * (x)) +#define MIO_RST_CTL_PRTMODE 0x0000000000000030ULL + +/* OCTEON III */ +#define RST_BOOT 0x1180006001600ULL +#define RST_BOOT_C_MUL_SHIFT 30 +#define RST_BOOT_C_MUL_MASK 0x7f +#define RST_BOOT_PNR_MUL_SHIFT 24 +#define RST_BOOT_PNR_MUL_MASK 0x3f +#define RST_CTL(x) (0x1180006001640ULL + 8 * (x)) +#define RST_CTL_RST_DONE 0x0000000000000100ULL +#define RST_CTL_HOST_MODE 0x0000000000000040ULL +#define RST_SOFT_RST 0x1180006001680ULL + +#define OCTEON_IO_REF_CLOCK 50000000 /* 50MHz */ + +#endif /* !_MACHINE_OCTEONREG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/octeonvar.h b/lib/libc/include/mips64-openbsd-none/octeon/octeonvar.h new file mode 100644 index 0000000000..cc0f782bf3 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/octeonvar.h @@ -0,0 +1,498 @@ +/* $OpenBSD: octeonvar.h,v 1.54 2022/08/29 02:01:18 jsg Exp $ */ +/* $NetBSD: maltavar.h,v 1.3 2002/03/18 10:10:16 simonb Exp $ */ + +/*- + * Copyright (c) 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. + */ + +#ifndef _MIPS_OCTEON_OCTEONVAR_H_ +#define _MIPS_OCTEON_OCTEONVAR_H_ + +#include + +/* XXX elsewhere */ +#define _ASM_PROLOGUE \ + " .set push \n" \ + " .set noreorder \n" +#define _ASM_PROLOGUE_MIPS64 \ + _ASM_PROLOGUE \ + " .set mips64 \n" +#define _ASM_PROLOGUE_OCTEON \ + _ASM_PROLOGUE \ + " .set arch=octeon \n" +#define _ASM_EPILOGUE \ + " .set pop \n" +/* + * subbits = __BITS64_GET(XXX, bits); + * bits = __BITS64_SET(XXX, subbits); + */ +#ifndef __BITS64_GET +#define __BITS64_GET(name, bits) \ + (((uint64_t)(bits) & name) >> name##_SHIFT) +#endif +#ifndef __BITS64_SET +#define __BITS64_SET(name, subbits) \ + (((uint64_t)(subbits) << name##_SHIFT) & name) +#endif + +struct octeon_config { + bus_space_tag_t mc_iobus_bust; + bus_space_tag_t mc_bootbus_bust; + + bus_dma_tag_t mc_iobus_dmat; + bus_dma_tag_t mc_bootbus_dmat; +}; + +#define GPIO_CONFIG_MD_OUTPUT_SEL_MASK (GPIO_CONFIG_MD0 | GPIO_CONFIG_MD1) +#define GPIO_CONFIG_MD_USB0_VBUS_CTRL GPIO_CONFIG_MD0 +#define GPIO_CONFIG_MD_USB1_VBUS_CTRL GPIO_CONFIG_MD1 + +/* + * FPA map + */ + +#define OCTEON_POOL_NO_PKT 0 +#define OCTEON_POOL_NO_WQE 1 +#define OCTEON_POOL_NO_CMD 2 +#define OCTEON_POOL_NO_SG 3 +#define OCTEON_POOL_NO_XXX_4 4 +#define OCTEON_POOL_NO_XXX_5 5 +#define OCTEON_POOL_NO_XXX_6 6 +#define OCTEON_POOL_NO_DUMP 7 /* FPA debug dump */ + +#define OCTEON_POOL_SIZE_PKT 1920 /* 128 x 15 */ +#define OCTEON_POOL_SIZE_WQE 128 /* 128 x 1 */ +#define OCTEON_POOL_SIZE_CMD 1024 /* 128 x 8 */ +#define OCTEON_POOL_SIZE_SG 128 /* 128 x 1 */ +#define OCTEON_POOL_SIZE_XXX_4 0 +#define OCTEON_POOL_SIZE_XXX_5 0 +#define OCTEON_POOL_SIZE_XXX_6 0 +#define OCTEON_POOL_SIZE_XXX_7 0 + +#define OCTEON_POOL_NELEMS_PKT 4096 +#define OCTEON_POOL_NELEMS_WQE 4096 +#define OCTEON_POOL_NELEMS_CMD 32 +#define OCTEON_POOL_NELEMS_SG 4096 +#define OCTEON_POOL_NELEMS_XXX_4 0 +#define OCTEON_POOL_NELEMS_XXX_5 0 +#define OCTEON_POOL_NELEMS_XXX_6 0 +#define OCTEON_POOL_NELEMS_XXX_7 0 + +/* + * CVMSEG (``scratch'') memory map + */ +struct octeon_cvmseg_map { + uint64_t csm_pow_intr; + + struct octeon_cvmseg_ether_map { + uint64_t csm_ether_fau_done; + } csm_ether[12/* XXX */]; +} __packed; +#define OCTEON_CVMSEG_OFFSET(entry) \ + offsetof(struct octeon_cvmseg_map, entry) +#define OCTEON_CVMSEG_ETHER_OFFSET(n, entry) \ + (offsetof(struct octeon_cvmseg_map, csm_ether) + \ + sizeof(struct octeon_cvmseg_ether_map) * (n) + \ + offsetof(struct octeon_cvmseg_ether_map, entry)) + +/* + * FAU register map + * + * => FAU registers exist in FAU unit + * => devices (PKO) can access these registers + * => CPU can read those values after loading them into CVMSEG + */ +struct octeon_fau_map { + struct { + /* PKO command index */ + uint64_t _fau_map_port_pkocmdidx; + /* send requested */ + uint64_t _fau_map_port_txreq; + /* send completed */ + uint64_t _fau_map_port_txdone; + /* XXX */ + uint64_t _fau_map_port_pad; + } __packed _fau_map_port[3]; +}; + +/* + * POW qos/group map + */ + +#define OCTEON_POW_QOS_PIP 0 +#define OCTEON_POW_QOS_CORE1 1 +#define OCTEON_POW_QOS_XXX_2 2 +#define OCTEON_POW_QOS_XXX_3 3 +#define OCTEON_POW_QOS_XXX_4 4 +#define OCTEON_POW_QOS_XXX_5 5 +#define OCTEON_POW_QOS_XXX_6 6 +#define OCTEON_POW_QOS_XXX_7 7 + +#define OCTEON_POW_GROUP_MAX 16 + +enum cnmac_stat { + cnmac_stat_rx_toto_gmx, + cnmac_stat_rx_totp_gmx, + cnmac_stat_rx_toto_pip, + cnmac_stat_rx_totp_pip, + cnmac_stat_rx_h64, + cnmac_stat_rx_h127, + cnmac_stat_rx_h255, + cnmac_stat_rx_h511, + cnmac_stat_rx_h1023, + cnmac_stat_rx_h1518, + cnmac_stat_rx_hmax, + cnmac_stat_rx_bcast, + cnmac_stat_rx_mcast, + cnmac_stat_rx_qdpo, + cnmac_stat_rx_qdpp, + cnmac_stat_rx_fcs, + cnmac_stat_rx_frag, + cnmac_stat_rx_undersz, + cnmac_stat_rx_jabber, + cnmac_stat_rx_oversz, + cnmac_stat_rx_raw, + cnmac_stat_rx_bad, + cnmac_stat_rx_drop, + cnmac_stat_rx_ctl, + cnmac_stat_rx_dmac, + cnmac_stat_tx_toto, + cnmac_stat_tx_totp, + cnmac_stat_tx_hmin, + cnmac_stat_tx_h64, + cnmac_stat_tx_h127, + cnmac_stat_tx_h255, + cnmac_stat_tx_h511, + cnmac_stat_tx_h1023, + cnmac_stat_tx_h1518, + cnmac_stat_tx_hmax, + cnmac_stat_tx_bcast, + cnmac_stat_tx_mcast, + cnmac_stat_tx_coll, + cnmac_stat_tx_defer, + cnmac_stat_tx_scol, + cnmac_stat_tx_mcol, + cnmac_stat_tx_ctl, + cnmac_stat_tx_uflow, + cnmac_stat_count +}; + +#if defined(_KERNEL) || defined(_STANDALONE) +#define OCTEON_ARGV_MAX 64 + +/* + * OCTEON board types recognized by OpenBSD/octeon. + * + * It is fine to use BOARD_UNKNOWN when the board does not need + * special treatment. + */ +enum octeon_board { + BOARD_UNKNOWN, + BOARD_CHECKPOINT_N100, + BOARD_CN3010_EVB_HS5, + BOARD_DLINK_DSR_500, + BOARD_NETGEAR_UTM25, + BOARD_RHINOLABS_UTM8, + BOARD_UBIQUITI_E100, + BOARD_UBIQUITI_E120, + BOARD_UBIQUITI_E200, + BOARD_UBIQUITI_E220, + BOARD_UBIQUITI_E300, + BOARD_UBIQUITI_E1000, +}; + +struct boot_desc { + uint32_t desc_ver; + uint32_t desc_size; + uint64_t stack_top; + uint64_t heap_start; + uint64_t heap_end; + uint64_t __unused17; + uint64_t __unused16; + uint32_t __unused18; + uint32_t __unused15; + uint32_t __unused14; + uint32_t argc; + uint32_t argv[OCTEON_ARGV_MAX]; + uint32_t flags; + uint32_t core_mask; + uint32_t dram_size; + uint32_t phy_mem_desc_addr; + uint32_t debugger_flag_addr; + uint32_t eclock; + uint32_t __unused10; + uint32_t __unused9; + uint16_t __unused8; + uint8_t __unused7; + uint8_t __unused6; + uint16_t __unused5; + uint8_t __unused4; + uint8_t __unused3; + uint8_t __unused2[20]; + uint8_t __unused1[6]; + uint8_t __unused0; + uint64_t boot_info_addr; +}; + +struct boot_info { + uint32_t ver_major; + uint32_t ver_minor; + uint64_t stack_top; + uint64_t heap_start; + uint64_t heap_end; + uint64_t boot_desc_addr; + uint32_t exception_base_addr; + uint32_t stack_size; + uint32_t flags; + uint32_t core_mask; + uint32_t dram_size; + uint32_t phys_mem_desc_addr; + uint32_t debugger_flags_addr; + uint32_t eclock; + uint32_t dclock; + uint32_t __unused0; + uint16_t board_type; + uint8_t board_rev_major; + uint8_t board_rev_minor; + uint16_t __unused1; + uint8_t __unused2; + uint8_t __unused3; + char board_serial[20]; + uint8_t mac_addr_base[6]; + uint8_t mac_addr_count; + uint64_t cf_common_addr; + uint64_t cf_attr_addr; + uint64_t led_display_addr; + uint32_t dfaclock; + uint32_t config_flags; + /* The fields below are available when ver_minor >= 3. */ + uint64_t fdt_addr; +}; + +struct octeon_bootmem_desc { + uint32_t lock; + uint32_t flags; + uint64_t head_addr; + uint32_t major_version; + uint32_t minor_version; + uint64_t app_data_addr; + uint64_t app_data_size; + uint32_t named_block_num_blocks; + uint32_t named_block_name_len; + uint64_t named_block_array_addr; +}; + +struct octeon_bootmem_block { + uint64_t next; + uint64_t size; +}; + +extern enum octeon_board octeon_board; +extern struct boot_desc *octeon_boot_desc; +extern struct boot_info *octeon_boot_info; + +#ifdef _KERNEL +/* Device capabilities advertised in boot_info->config_flags */ +#define BOOTINFO_CFG_FLAG_PCI_HOST (1ull << 0) +#define BOOTINFO_CFG_FLAG_PCI_TARGET (1ull << 1) +#define BOOTINFO_CFG_FLAG_DEBUG (1ull << 2) +#define BOOTINFO_CFG_FLAG_NO_MAGIC (1ull << 3) + +#define BOOTMEM_BLOCK_ALIGN 16 +#define BOOTMEM_BLOCK_MASK (BOOTMEM_BLOCK_ALIGN - 1) +#define BOOTMEM_BLOCK_MIN_SIZE 16 + +int bootmem_alloc_region(paddr_t, size_t); +void bootmem_free(paddr_t, size_t); + +int octeon_ioclock_speed(void); + +#endif /* _KERNEL */ +#endif /* _KERNEL || _STANDALONE */ + +static inline int +ffs64(uint64_t val) +{ + int ret; + + __asm volatile ( \ + _ASM_PROLOGUE_MIPS64 + " dclz %0, %1 \n" + _ASM_EPILOGUE + : "=r"(ret) : "r"(val)); + return 64 - ret; +} + +static inline int +ffs32(uint32_t val) +{ + int ret; + + __asm volatile ( \ + _ASM_PROLOGUE_MIPS64 + " clz %0, %1 \n" + _ASM_EPILOGUE + : "=r"(ret) : "r"(val)); + return 32 - ret; +} + +static inline uint64_t +octeon_xkphys_read_8(paddr_t address) +{ + volatile uint64_t *p = + (volatile uint64_t *)(PHYS_TO_XKPHYS(address, CCA_NC)); + return (*p); +} + +#define MIO_BOOT_BIST_STAT 0x00011800000000f8ULL +static inline void +octeon_xkphys_write_8(paddr_t address, uint64_t value) +{ + *(volatile uint64_t *)(PHYS_TO_XKPHYS(address, CCA_NC)) = value; + + /* + * It seems an immediate read is necessary when doing a write to an RSL + * register in order to complete the write. + * We use MIO_BOOT_BIST_STAT because it's apparently the fastest + * write. + */ + + /* + * XXX + * This if would be better written as: + * if ((address & 0xffffff0000000000ULL) == OCTEON_MIO_BOOT_BASE) { + * but octeonreg.h can't be included here and we want this inlined + * + * Note that the SDK masks with 0x7ffff but that doesn't make sense. + * This is a physical address. + */ + if (((address >> 40) & 0xfffff) == (0x118)) { + value = *(volatile uint64_t *) + (PHYS_TO_XKPHYS(MIO_BOOT_BIST_STAT, CCA_NC)); + } +} + +static inline void +octeon_iobdma_write_8(uint64_t value) +{ + uint64_t addr = 0xffffffffffffa200ULL; + + *(volatile uint64_t *)addr = value; +} + +static inline void +octeon_lmtdma_write_8(off_t offset, uint64_t value) +{ + *(volatile uint64_t *)(0xffffffffffffa400ULL + offset) = value; +} + +static inline uint64_t +octeon_cvmseg_read_8(size_t offset) +{ + return *(volatile uint64_t *)(0xffffffffffff8000ULL + offset); +} + +static inline void +octeon_cvmseg_write_8(size_t offset, uint64_t value) +{ + *(volatile uint64_t *)(0xffffffffffff8000ULL + offset) = value; +} + +static inline uint32_t +octeon_get_coreid(void) +{ + uint32_t coreid; + + __asm volatile ( + _ASM_PROLOGUE_OCTEON + " rdhwr %0, $0\n" + _ASM_EPILOGUE + : "=r" (coreid)); + return coreid; +} + +static inline uint64_t +octeon_get_cycles(void) +{ + uint64_t tmp; + + __asm volatile ( + _ASM_PROLOGUE_MIPS64 + " dmfc0 %[tmp], $9, 6 \n" + _ASM_EPILOGUE + : [tmp]"=&r"(tmp)); + return tmp; +} + +static inline uint64_t +octeon_get_cvmctl(void) +{ + uint64_t tmp; + + __asm volatile ( + _ASM_PROLOGUE_OCTEON + " dmfc0 %[tmp], $9, 7 \n" + _ASM_EPILOGUE + : [tmp]"=r"(tmp)); + return tmp; +} + +static inline uint64_t +octeon_get_cvmmemctl(void) +{ + uint64_t tmp; + + __asm volatile ( + _ASM_PROLOGUE_OCTEON + " dmfc0 %[tmp], $11, 7 \n" + _ASM_EPILOGUE + : [tmp]"=r"(tmp)); + return tmp; +} + +static inline void +octeon_set_cvmmemctl(uint64_t val) +{ + __asm volatile ( + _ASM_PROLOGUE_OCTEON + " dmtc0 %[tmp], $11, 7 \n" + _ASM_EPILOGUE + : : [tmp]"r"(val) : "memory"); +} + +static inline void +octeon_synciobdma(void) +{ + __asm volatile ( + _ASM_PROLOGUE_OCTEON + " synciobdma\n" + _ASM_EPILOGUE + : : : "memory"); +} + +#endif /* _MIPS_OCTEON_OCTEONVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/openpromio.h b/lib/libc/include/mips64-openbsd-none/octeon/openpromio.h new file mode 100644 index 0000000000..c33fb937a0 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/openpromio.h @@ -0,0 +1,57 @@ +/* $OpenBSD: openpromio.h,v 1.1 2016/07/05 12:53:40 visa Exp $ */ +/* $NetBSD: openpromio.h,v 1.1.1.1 1998/06/20 04:58:52 eeh Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)openpromio.h 8.1 (Berkeley) 6/11/93 + */ + +struct opiocdesc { + int op_nodeid; /* passed or returned node id */ + int op_namelen; /* length of op_name */ + char *op_name; /* pointer to field name */ + int op_buflen; /* length of op_buf (value-result) */ + char *op_buf; /* pointer to field value */ +}; + +#define OPIOCGET _IOWR('O', 1, struct opiocdesc) /* get openprom field */ +#define OPIOCSET _IOW('O', 2, struct opiocdesc) /* set openprom field */ +#define OPIOCNEXTPROP _IOWR('O', 3, struct opiocdesc) /* get next property */ +#define OPIOCGETOPTNODE _IOR('O', 4, int) /* get openprom field */ +#define OPIOCGETNEXT _IOWR('O', 5, int) /* get next node of node */ +#define OPIOCGETCHILD _IOWR('O', 6, int) /* get first child of node */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/param.h b/lib/libc/include/mips64-openbsd-none/octeon/param.h new file mode 100644 index 0000000000..336a652308 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/param.h @@ -0,0 +1,22 @@ +/* $OpenBSD: param.h,v 1.5 2018/08/09 12:19:32 patrick Exp $ */ + +/* Public Domain */ + +#ifndef _MACHINE_PARAM_H_ +#define _MACHINE_PARAM_H_ + +#define MACHINE "octeon" +#define _MACHINE octeon +#define MACHINE_ARCH "mips64" +#define _MACHINE_ARCH mips64 +#define MID_MACHINE MID_MIPS64 + +#define PAGE_SHIFT 14 + +#include + +#ifdef _KERNEL +#define __HAVE_FDT +#endif + +#endif /* _MACHINE_PARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/pcb.h b/lib/libc/include/mips64-openbsd-none/octeon/pcb.h new file mode 100644 index 0000000000..d48bd47247 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/pcb.h @@ -0,0 +1,3 @@ +/* $OpenBSD: pcb.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/pci_machdep.h b/lib/libc/include/mips64-openbsd-none/octeon/pci_machdep.h new file mode 100644 index 0000000000..b3aa0341f1 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/pci_machdep.h @@ -0,0 +1,133 @@ +/* $OpenBSD: pci_machdep.h,v 1.13 2024/05/20 23:13:33 jsg Exp $ */ + +/* + * Copyright (c) 2003-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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. + * + */ +#include + +typedef struct mips_pci_chipset *pci_chipset_tag_t; + +typedef u_int64_t pcitag_t; +#define PCITAG_NODE(x) ((x) >> 32) +#define PCITAG_OFFSET(x) ((x) & 0xffffffff) + +typedef u_long pci_intr_handle_t; + +struct pci_attach_args; + +/* + * mips-specific PCI structure and type definitions. + * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE. + */ +struct mips_pci_chipset { + void *pc_conf_v; + void (*pc_attach_hook)(struct device *, + struct device *, struct pcibus_attach_args *); + int (*pc_bus_maxdevs)(void *, int); + pcitag_t (*pc_make_tag)(void *, int, int, int); + void (*pc_decompose_tag)(void *, pcitag_t, int *, + int *, int *); + int (*pc_conf_size)(void *, pcitag_t); + pcireg_t (*pc_conf_read)(void *, pcitag_t, int); + void (*pc_conf_write)(void *, pcitag_t, int, pcireg_t); + + void *pc_intr_v; + int (*pc_intr_map)(struct pci_attach_args *, + pci_intr_handle_t *); + const char *(*pc_intr_string)(void *, pci_intr_handle_t); + void *(*pc_intr_establish)(void *, pci_intr_handle_t, + int, int (*)(void *), void *, char *); + void (*pc_intr_disestablish)(void *, void *); +}; + +/* + * Functions provided to machine-independent PCI code. + */ +//#define DEBUG_PCI_CONF + +#define pci_attach_hook(p, s, pba) \ + (*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba)) +#define pci_bus_maxdevs(c, b) \ + (*(c)->pc_bus_maxdevs)((c)->pc_conf_v, (b)) +#define pci_make_tag(c, b, d, f) \ + (*(c)->pc_make_tag)((c)->pc_conf_v, (b), (d), (f)) +#define pci_decompose_tag(c, t, bp, dp, fp) \ + (*(c)->pc_decompose_tag)((c)->pc_conf_v, (t), (bp), (dp), (fp)) + +#define pci_conf_size(c, t) \ + (*(c)->pc_conf_size)((c)->pc_conf_v, (t)) + +#ifdef DEBUG_PCI_CONF +static inline pcireg_t +pci_conf_read_db(void *cookie, pcitag_t tag, int reg, + const char *file, const char *func, int line) +{ + struct mips_pci_chipset *pc = cookie; + pcireg_t val; + + val = (*(pc)->pc_conf_read)(pc->pc_conf_v, tag, reg); + printf("%s:%s:%d:pci_conf_read(%llx,%x) = %x\n", file, func, line, + tag, reg, val); + return val; +} + +static inline void +pci_conf_write_db(void *cookie, pcitag_t tag, int reg, pcireg_t val, + const char *file, const char *func, int line) +{ + struct mips_pci_chipset *pc = cookie; + + printf("%s:%s:%d:pci_conf_write(%llx,%x,%x)\n", file, func, line, + tag, reg, val); + (*(pc)->pc_conf_write)(pc->pc_conf_v, tag, reg, val); +} + + +#define pci_conf_read(c, t, r) \ + pci_conf_read_db(c, t, r, __FILE__, __FUNCTION__, __LINE__) +#define pci_conf_write(c, t, r, v) \ + pci_conf_write_db(c, t, r, v, __FILE__, __FUNCTION__, __LINE__) +#else +#define pci_conf_read(c, t, r) \ + (*(c)->pc_conf_read)((c)->pc_conf_v, (t), (r)) +#define pci_conf_write(c, t, r, v) \ + (*(c)->pc_conf_write)((c)->pc_conf_v, (t), (r), (v)) +#endif +#define pci_intr_map(c, ihp) \ + (*(c)->pa_pc->pc_intr_map)((c), (ihp)) +#define pci_intr_map_msi(c, ihp) (-1) +#define pci_intr_map_msix(c, vec, ihp) (-1) +#define pci_intr_string(c, ih) \ + (*(c)->pc_intr_string)((c)->pc_intr_v, (ih)) +#define pci_intr_establish(c, ih, l, h, a, nm) \ + (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), (h), (a), (nm)) +#define pci_intr_disestablish(c, iv) \ + (*(c)->pc_intr_disestablish)((c)->pc_intr_v, (iv)) +#define pci_probe_device_hook(c, a) (0) + +#define pci_min_powerstate(c, t) (PCI_PMCSR_STATE_D3) +#define pci_set_powerstate_md(c, t, s, p) + +#define pci_dev_postattach(a, b) \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/pmap.h b/lib/libc/include/mips64-openbsd-none/octeon/pmap.h new file mode 100644 index 0000000000..93a59c2555 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/pmap.h @@ -0,0 +1,3 @@ +/* $OpenBSD: pmap.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/proc.h b/lib/libc/include/mips64-openbsd-none/octeon/proc.h new file mode 100644 index 0000000000..feb4d625ea --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/proc.h @@ -0,0 +1,3 @@ +/* $OpenBSD: proc.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/profile.h b/lib/libc/include/mips64-openbsd-none/octeon/profile.h new file mode 100644 index 0000000000..f6b93ca73c --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/profile.h @@ -0,0 +1,3 @@ +/* $OpenBSD: profile.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/pte.h b/lib/libc/include/mips64-openbsd-none/octeon/pte.h new file mode 100644 index 0000000000..a1543ff6ce --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/pte.h @@ -0,0 +1,3 @@ +/* $OpenBSD: pte.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/ptrace.h b/lib/libc/include/mips64-openbsd-none/octeon/ptrace.h new file mode 100644 index 0000000000..be18759bda --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/ptrace.h @@ -0,0 +1,3 @@ +/* $OpenBSD: ptrace.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/reg.h b/lib/libc/include/mips64-openbsd-none/octeon/reg.h new file mode 100644 index 0000000000..b21b51b978 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/reg.h @@ -0,0 +1,3 @@ +/* $OpenBSD: reg.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/regdef.h b/lib/libc/include/mips64-openbsd-none/octeon/regdef.h new file mode 100644 index 0000000000..dc004a4ce8 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/regdef.h @@ -0,0 +1,3 @@ +/* $OpenBSD: regdef.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/regnum.h b/lib/libc/include/mips64-openbsd-none/octeon/regnum.h new file mode 100644 index 0000000000..b20d7d3c3f --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/regnum.h @@ -0,0 +1,3 @@ +/* $OpenBSD: regnum.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/reloc.h b/lib/libc/include/mips64-openbsd-none/octeon/reloc.h new file mode 100644 index 0000000000..4eb8c01cf1 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/reloc.h @@ -0,0 +1,5 @@ +/* $OpenBSD: reloc.h,v 1.1 2017/08/12 15:33:41 visa Exp $ */ + +/* public domain */ + +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/setjmp.h b/lib/libc/include/mips64-openbsd-none/octeon/setjmp.h new file mode 100644 index 0000000000..bdd733d22d --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/setjmp.h @@ -0,0 +1,3 @@ +/* $OpenBSD: setjmp.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/signal.h b/lib/libc/include/mips64-openbsd-none/octeon/signal.h new file mode 100644 index 0000000000..2a21ca6358 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/signal.h @@ -0,0 +1,3 @@ +/* $OpenBSD: signal.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/simplebusvar.h b/lib/libc/include/mips64-openbsd-none/octeon/simplebusvar.h new file mode 100644 index 0000000000..32763ebfc8 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/simplebusvar.h @@ -0,0 +1,34 @@ +/* $OpenBSD: simplebusvar.h,v 1.1 2023/09/22 01:10:43 jsg Exp $ */ + +/* + * Copyright (c) 2016 Patrick Wildt + * + * 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. + */ + +struct simplebus_softc { + struct device sc_dev; + int sc_node; + bus_space_tag_t sc_iot; + bus_dma_tag_t sc_dmat; + int sc_acells; + int sc_scells; + int sc_pacells; + int sc_pscells; + bus_space_t sc_bus; + int *sc_ranges; + int sc_rangeslen; + int sc_early; +}; + +extern void simplebus_attach(struct device *, struct device *, void *); \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/spinlock.h b/lib/libc/include/mips64-openbsd-none/octeon/spinlock.h new file mode 100644 index 0000000000..800fc6eeb1 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/spinlock.h @@ -0,0 +1,3 @@ +/* $OpenBSD: spinlock.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/sysarch.h b/lib/libc/include/mips64-openbsd-none/octeon/sysarch.h new file mode 100644 index 0000000000..05bc151676 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/sysarch.h @@ -0,0 +1,3 @@ +/* $OpenBSD: sysarch.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/tcb.h b/lib/libc/include/mips64-openbsd-none/octeon/tcb.h new file mode 100644 index 0000000000..427e19101a --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/tcb.h @@ -0,0 +1,3 @@ +/* $OpenBSD: tcb.h,v 1.2 2013/06/01 21:20:54 jasper Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/timetc.h b/lib/libc/include/mips64-openbsd-none/octeon/timetc.h new file mode 100644 index 0000000000..d3d291c815 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/timetc.h @@ -0,0 +1,23 @@ +/* $OpenBSD: timetc.h,v 1.2 2020/07/18 08:37:43 visa Exp $ */ +/* + * Copyright (c) 2020 Paul Irofti + * + * 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_TIMETC_H_ +#define _MACHINE_TIMETC_H_ + +#include + +#endif /* _MACHINE_TIMETC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/trap.h b/lib/libc/include/mips64-openbsd-none/octeon/trap.h new file mode 100644 index 0000000000..7ed252bd11 --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/trap.h @@ -0,0 +1,3 @@ +/* $OpenBSD: trap.h,v 1.1 2010/09/20 06:32:30 syuu Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64-openbsd-none/octeon/vmparam.h b/lib/libc/include/mips64-openbsd-none/octeon/vmparam.h new file mode 100644 index 0000000000..336c1cf70f --- /dev/null +++ b/lib/libc/include/mips64-openbsd-none/octeon/vmparam.h @@ -0,0 +1,11 @@ +/* $OpenBSD: vmparam.h,v 1.3 2017/07/30 16:09:53 visa Exp $ */ +/* public domain */ +#ifndef _MACHINE_VMPARAM_H_ +#define _MACHINE_VMPARAM_H_ + +#define VM_PHYSSEG_MAX 8 /* Max number of physical memory segments */ +#define VM_PHYSSEG_STRAT VM_PSTRAT_BIGFIRST + +#include + +#endif /* _MACHINE_VMPARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/frame.h b/lib/libc/include/mips64el-openbsd-none/frame.h new file mode 100644 index 0000000000..d14827e33c --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/frame.h @@ -0,0 +1,3 @@ +/* $OpenBSD: frame.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/_float.h b/lib/libc/include/mips64el-openbsd-none/loongson/_float.h new file mode 100644 index 0000000000..6c9717939f --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/_float.h @@ -0,0 +1,3 @@ +/* $OpenBSD: _float.h,v 1.1 2012/06/26 16:12:44 deraadt Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/_types.h b/lib/libc/include/mips64el-openbsd-none/loongson/_types.h new file mode 100644 index 0000000000..327e3d3e38 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/_types.h @@ -0,0 +1,3 @@ +/* $OpenBSD: _types.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/apmvar.h b/lib/libc/include/mips64el-openbsd-none/loongson/apmvar.h new file mode 100644 index 0000000000..99c4026f96 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/apmvar.h @@ -0,0 +1,127 @@ +/* $OpenBSD: apmvar.h,v 1.6 2019/01/22 02:36:30 phessler Exp $ */ + +/* + * Copyright (c) 2001 Alexander Guy + * Copyright (c) 1995 John T. Kohl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef _MACHINE_APMVAR_H_ +#define _MACHINE_APMVAR_H_ + +#include + +/* Advanced Power Management (v1.0 and v1.1 specification) + * functions/defines/etc. + */ + +/* These definitions make up the heart of the user-land interface + * to the APM devices. + */ + +#define APM_AC_OFF 0x00 +#define APM_AC_ON 0x01 +#define APM_AC_BACKUP 0x02 +#define APM_AC_UNKNOWN 0xff +#define APM_BATT_HIGH 0x00 +#define APM_BATT_LOW 0x01 +#define APM_BATT_CRITICAL 0x02 +#define APM_BATT_CHARGING 0x03 +#define APM_BATT_UNKNOWN 0xff +#define APM_BATT_LIFE_UNKNOWN 0xff + +#define APM_NOEVENT 0x0000 +#define APM_STANDBY_REQ 0x0001 +#define APM_SUSPEND_REQ 0x0002 +#define APM_NORMAL_RESUME 0x0003 +#define APM_CRIT_RESUME 0x0004 /* suspend/resume happened + without us */ +#define APM_BATTERY_LOW 0x0005 +#define APM_POWER_CHANGE 0x0006 +#define APM_UPDATE_TIME 0x0007 +#define APM_CRIT_SUSPEND_REQ 0x0008 +#define APM_USER_STANDBY_REQ 0x0009 +#define APM_USER_SUSPEND_REQ 0x000A +#define APM_SYS_STANDBY_RESUME 0x000B +#define APM_CAPABILITY_CHANGE 0x000C /* apm v1.2 */ +#define APM_USER_HIBERNATE_REQ 0x000D +#define APM_EVENT_MASK 0xffff + +#define APM_EVENT_COMPOSE(t,i) ((((i) & 0x7fff) << 16)|((t) & APM_EVENT_MASK)) +#define APM_EVENT_TYPE(e) ((e) & APM_EVENT_MASK) +#define APM_EVENT_INDEX(e) ((e) >> 16) + +/* + * LP (Laptop Package) + * + * Copyright (C) 1994 by HOSOKAWA Tatsumi + * + * This software may be used, modified, copied, and distributed, in + * both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + */ + +#define APM_BATTERY_ABSENT 4 + +struct apm_power_info { + u_char battery_state; + u_char ac_state; + u_char battery_life; + u_char spare1; + u_int minutes_left; /* estimate */ + u_int spare2[6]; +}; + +struct apm_ctl { + u_int dev; + u_int mode; +}; + +#define APM_IOC_REJECT _IOW('A', 0, struct apm_event_info) /* reject request # */ +#define APM_IOC_STANDBY _IO('A', 1) /* put system into standby */ +#define APM_IOC_SUSPEND _IO('A', 2) /* put system into suspend */ +#define APM_IOC_GETPOWER _IOR('A', 3, struct apm_power_info) /* fetch battery state */ +#define APM_IOC_DEV_CTL _IOW('A', 5, struct apm_ctl) /* put device into mode */ +#define APM_IOC_PRN_CTL _IOW('A', 6, int ) /* driver power status msg */ +#define APM_PRINT_ON 0 /* driver power status displayed */ +#define APM_PRINT_OFF 1 /* driver power status not displayed */ +#define APM_PRINT_PCT 2 /* driver power status only displayed + if the percentage changes */ +#define APM_IOC_STANDBY_REQ _IO('A', 7) /* request standby */ +#define APM_IOC_SUSPEND_REQ _IO('A', 8) /* request suspend */ +#define APM_IOC_HIBERNATE _IO('A', 9) /* put system into hibernate */ + +#ifdef _KERNEL +void apm_setinfohook(int (*)(struct apm_power_info *)); +int apm_record_event(u_int, const char *, const char *); +#endif + +#endif /* _MACHINE_APMVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/asm.h b/lib/libc/include/mips64el-openbsd-none/loongson/asm.h new file mode 100644 index 0000000000..63eab17513 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/asm.h @@ -0,0 +1,9 @@ +/* $OpenBSD: asm.h,v 1.2 2016/11/18 15:38:14 visa Exp $ */ +/* public domain */ + +#ifdef MULTIPROCESSOR +#define HW_GET_CPU_INFO(ci, tmp) \ + dmfc0 ci, COP_0_ERROR_PC +#endif + +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/atomic.h b/lib/libc/include/mips64el-openbsd-none/loongson/atomic.h new file mode 100644 index 0000000000..19aa2fd4f6 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/atomic.h @@ -0,0 +1,3 @@ +/* $OpenBSD: atomic.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/autoconf.h b/lib/libc/include/mips64el-openbsd-none/loongson/autoconf.h new file mode 100644 index 0000000000..7292105a5b --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/autoconf.h @@ -0,0 +1,124 @@ +/* $OpenBSD: autoconf.h,v 1.17 2017/05/21 13:00:53 visa Exp $ */ + +/* + * Copyright (c) 2001-2003 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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. + * + */ + +/* + * Definitions used by autoconfiguration. + */ + +#ifndef _MACHINE_AUTOCONF_H_ +#define _MACHINE_AUTOCONF_H_ + +#include + +struct bonito_config; +struct htb_config; +struct mips_isa_chipset; + +/* + * List of legacy I/O ranges. + */ +struct legacy_io_range { + bus_addr_t start; + bus_size_t end; /* inclusive */ +}; + +/* + * Per platform information. + */ +struct platform { + int system_type; +#define LOONGSON_2E 0x0000 /* Generic Loongson 2E system */ +#define LOONGSON_YEELOONG 0x0001 /* Lemote Yeeloong */ +#define LOONGSON_GDIUM 0x0002 /* EMTEC Gdium Liberty */ +#define LOONGSON_FULOONG 0x0003 /* Lemote Fuloong */ +#define LOONGSON_LYNLOONG 0x0004 /* Lemote Lynloong */ +#define LOONGSON_EBT700 0x0005 /* eBenton EBT700 */ +#define LOONGSON_3A 0x0066 /* Loongson 2Gq or 3A based system */ + + char *vendor; + char *product; + + const struct bonito_config *bonito_config; + const struct htb_config *htb_config; + struct mips_isa_chipset *isa_chipset; + const struct legacy_io_range *legacy_io_ranges; + + void (*setup)(void); + void (*device_register)(struct device *, + void *); + + void (*powerdown)(void); + void (*reset)(void); + int (*suspend)(void); + int (*resume)(void); + +#ifdef MULTIPROCESSOR + void (*config_secondary_cpus)( + struct device *, cfprint_t); + void (*boot_secondary_cpu)( + struct cpu_info *); + int (*ipi_establish)(int (*)(void *), + cpuid_t); + void (*ipi_set)(cpuid_t); + void (*ipi_clear)(cpuid_t); +#endif /* MULTIPROCESSOR */ +}; + +#define LOONGSON_MAXCPUS 16 + +extern const struct platform *sys_platform; +extern void *loongson_videobios; +extern uint loongson_cpumask; +extern uint loongson_ver; +extern int nnodes; + +#ifdef MULTIPROCESSOR +extern uint64_t cpu_spinup_a0; +extern uint64_t cpu_spinup_sp; +#endif + +struct mainbus_attach_args { + const char *maa_name; +}; + +extern struct device *bootdv; +extern char bootdev[]; +extern enum devclass bootdev_class; + +extern bus_space_tag_t early_mem_t; +extern bus_space_tag_t early_io_t; + +#define REGVAL8(x) *((volatile uint8_t *)PHYS_TO_XKPHYS((x), CCA_NC)) +#define REGVAL32(x) *((volatile uint32_t *)PHYS_TO_XKPHYS((x), CCA_NC)) +#define REGVAL64(x) *((volatile uint64_t *)PHYS_TO_XKPHYS((x), CCA_NC)) + +#define REGVAL(x) REGVAL32(x) + +#include + +#endif /* _MACHINE_AUTOCONF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/bus.h b/lib/libc/include/mips64el-openbsd-none/loongson/bus.h new file mode 100644 index 0000000000..24430920dd --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/bus.h @@ -0,0 +1,513 @@ +/* $OpenBSD: bus.h,v 1.8 2020/04/14 17:35:28 kettenis Exp $ */ + +/* + * Copyright (c) 2003-2004 Opsycon AB Sweden. 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_BUS_H_ +#define _MACHINE_BUS_H_ + +#ifdef __STDC__ +#define CAT(a,b) a##b +#define CAT3(a,b,c) a##b##c +#else +#define CAT(a,b) a/**/b +#define CAT3(a,b,c) a/**/b/**/c +#endif + +/* + * Bus access types. + */ +struct mips_bus_space; +typedef u_long bus_addr_t; +typedef u_long bus_size_t; +typedef u_long bus_space_handle_t; +typedef struct mips_bus_space *bus_space_tag_t; + +struct mips_bus_space { + bus_addr_t bus_base; + void *bus_private; + u_int8_t (*_space_read_1)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_1)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int8_t); + u_int16_t (*_space_read_2)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_2)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int16_t); + u_int32_t (*_space_read_4)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_4)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int32_t); + u_int64_t (*_space_read_8)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_8)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int64_t); + void (*_space_read_raw_2)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, u_int8_t *, bus_size_t); + void (*_space_write_raw_2)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const u_int8_t *, bus_size_t); + void (*_space_read_raw_4)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, u_int8_t *, bus_size_t); + void (*_space_write_raw_4)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const u_int8_t *, bus_size_t); + void (*_space_read_raw_8)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, u_int8_t *, bus_size_t); + void (*_space_write_raw_8)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const u_int8_t *, bus_size_t); + int (*_space_map)(bus_space_tag_t , bus_addr_t, + bus_size_t, int, bus_space_handle_t *); + void (*_space_unmap)(bus_space_tag_t, bus_space_handle_t, + bus_size_t); + int (*_space_subregion)(bus_space_tag_t, bus_space_handle_t, + bus_size_t, bus_size_t, bus_space_handle_t *); + void * (*_space_vaddr)(bus_space_tag_t, bus_space_handle_t); + paddr_t (*_space_mmap)(bus_space_tag_t, bus_addr_t, off_t, + int, int); +}; + +#define bus_space_read_1(t, h, o) (*(t)->_space_read_1)((t), (h), (o)) +#define bus_space_read_2(t, h, o) (*(t)->_space_read_2)((t), (h), (o)) +#define bus_space_read_4(t, h, o) (*(t)->_space_read_4)((t), (h), (o)) +#define bus_space_read_8(t, h, o) (*(t)->_space_read_8)((t), (h), (o)) + +#define bus_space_write_1(t, h, o, v) (*(t)->_space_write_1)((t), (h), (o), (v)) +#define bus_space_write_2(t, h, o, v) (*(t)->_space_write_2)((t), (h), (o), (v)) +#define bus_space_write_4(t, h, o, v) (*(t)->_space_write_4)((t), (h), (o), (v)) +#define bus_space_write_8(t, h, o, v) (*(t)->_space_write_8)((t), (h), (o), (v)) + +#define bus_space_read_raw_multi_2(t, h, a, b, l) \ + (*(t)->_space_read_raw_2)((t), (h), (a), (b), (l)) +#define bus_space_read_raw_multi_4(t, h, a, b, l) \ + (*(t)->_space_read_raw_4)((t), (h), (a), (b), (l)) +#define bus_space_read_raw_multi_8(t, h, a, b, l) \ + (*(t)->_space_read_raw_8)((t), (h), (a), (b), (l)) + +#define bus_space_write_raw_multi_2(t, h, a, b, l) \ + (*(t)->_space_write_raw_2)((t), (h), (a), (b), (l)) +#define bus_space_write_raw_multi_4(t, h, a, b, l) \ + (*(t)->_space_write_raw_4)((t), (h), (a), (b), (l)) +#define bus_space_write_raw_multi_8(t, h, a, b, l) \ + (*(t)->_space_write_raw_8)((t), (h), (a), (b), (l)) + +#define bus_space_map(t, o, s, c, p) (*(t)->_space_map)((t), (o), (s), (c), (p)) +#define bus_space_unmap(t, h, s) (*(t)->_space_unmap)((t), (h), (s)) +#define bus_space_subregion(t, h, o, s, p) \ + (*(t)->_space_subregion)((t), (h), (o), (s), (p)) + +#define BUS_SPACE_MAP_CACHEABLE 0x01 +#define BUS_SPACE_MAP_LINEAR 0x02 +#define BUS_SPACE_MAP_PREFETCHABLE 0x04 + +#define bus_space_vaddr(t, h) (*(t)->_space_vaddr)((t), (h)) +#define bus_space_mmap(t, a, o, p, f) \ + (*(t)->_space_mmap)((t), (a), (o), (p), (f)) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_multi(n,m) \ +static __inline void \ +CAT(bus_space_read_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_size_t o, CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) \ + *x++ = CAT(bus_space_read_,n)(bst, bsh, o); \ +} + +bus_space_read_multi(1,8) +bus_space_read_multi(2,16) +bus_space_read_multi(4,32) +bus_space_read_multi(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_region(n,m) \ +static __inline void \ +CAT(bus_space_read_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) { \ + *x++ = CAT(bus_space_read_,n)(bst, bsh, ba); \ + ba += (n); \ + } \ +} + +bus_space_read_region(1,8) +bus_space_read_region(2,16) +bus_space_read_region(4,32) +bus_space_read_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_raw_region(n,m) \ +static __inline void \ +CAT(bus_space_read_raw_region_,n)(bus_space_tag_t bst, \ + bus_space_handle_t bsh, \ + bus_addr_t ba, u_int8_t *x, size_t cnt) \ +{ \ + cnt >>= ((n) >> 1); \ + while (cnt--) { \ + CAT(bus_space_read_raw_multi_,n)(bst, bsh, ba, x, (n)); \ + ba += (n); \ + x += (n); \ + } \ +} + +bus_space_read_raw_region(2,16) +bus_space_read_raw_region(4,32) +bus_space_read_raw_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_multi(n,m) \ +static __inline void \ +CAT(bus_space_write_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_size_t o, const CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) \ + CAT(bus_space_write_,n)(bst, bsh, o, *x++); \ +} + +bus_space_write_multi(1,8) +bus_space_write_multi(2,16) +bus_space_write_multi(4,32) +bus_space_write_multi(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_region(n,m) \ +static __inline void \ +CAT(bus_space_write_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, const CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) { \ + CAT(bus_space_write_,n)(bst, bsh, ba, *x++); \ + ba += (n); \ + } \ +} + +bus_space_write_region(1,8) +bus_space_write_region(2,16) +bus_space_write_region(4,32) +bus_space_write_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_raw_region(n,m) \ +static __inline void \ +CAT(bus_space_write_raw_region_,n)(bus_space_tag_t bst, \ + bus_space_handle_t bsh, \ + bus_addr_t ba, const u_int8_t *x, size_t cnt) \ +{ \ + cnt >>= ((n) >> 1); \ + while (cnt--) { \ + CAT(bus_space_write_raw_multi_,n)(bst, bsh, ba, x, (n)); \ + ba += (n); \ + x += (n); \ + } \ +} + +bus_space_write_raw_region(2,16) +bus_space_write_raw_region(4,32) +bus_space_write_raw_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_set_region(n,m) \ +static __inline void \ +CAT(bus_space_set_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, CAT3(u_int,m,_t) x, size_t cnt) \ +{ \ + while (cnt--) { \ + CAT(bus_space_write_,n)(bst, bsh, ba, x); \ + ba += (n); \ + } \ +} + +bus_space_set_region(1,8) +bus_space_set_region(2,16) +bus_space_set_region(4,32) +bus_space_set_region(8,64) + +/*----------------------------------------------------------------------------*/ +static __inline void +bus_space_copy_1(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + char *s = (char *)(h1 + o1); + char *d = (char *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + + +static __inline void +bus_space_copy_2(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + short *s = (short *)(h1 + o1); + short *d = (short *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + +static __inline void +bus_space_copy_4(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + int *s = (int *)(h1 + o1); + int *d = (int *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + +static __inline void +bus_space_copy_8(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + int64_t *s = (int64_t *)(h1 + o1); + int64_t *d = (int64_t *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + +int generic_space_map(bus_space_tag_t, bus_addr_t, bus_size_t, int, + bus_space_handle_t *); +void generic_space_unmap(bus_space_tag_t, bus_space_handle_t, bus_size_t); +int generic_space_region(bus_space_tag_t, bus_space_handle_t, bus_size_t, + bus_size_t, bus_space_handle_t *); +void *generic_space_vaddr(bus_space_tag_t, bus_space_handle_t); +uint8_t generic_space_read_1(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint16_t generic_space_read_2(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint32_t generic_space_read_4(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint64_t generic_space_read_8(bus_space_tag_t, bus_space_handle_t, bus_size_t); +void generic_space_read_raw_2(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_1(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint8_t); +void generic_space_write_2(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint16_t); +void generic_space_write_4(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint32_t); +void generic_space_write_8(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint64_t); +void generic_space_write_raw_2(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); +void generic_space_read_raw_4(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_raw_4(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); +void generic_space_read_raw_8(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_raw_8(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); +paddr_t generic_space_mmap(bus_space_tag_t, bus_addr_t, off_t, int, int); + +/*----------------------------------------------------------------------------*/ +/* + * Bus read/write barrier methods. + * + * void bus_space_barrier(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * bus_size_t len, int flags); + * + */ +static inline void +bus_space_barrier(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, + bus_size_t length, int flags) +{ + __asm__ volatile ("sync" ::: "memory"); +} +#define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */ +#define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */ + +#define BUS_DMA_WAITOK 0x0000 +#define BUS_DMA_NOWAIT 0x0001 +#define BUS_DMA_ALLOCNOW 0x0002 +#define BUS_DMA_COHERENT 0x0008 +#define BUS_DMA_BUS1 0x0010 /* placeholders for bus functions... */ +#define BUS_DMA_BUS2 0x0020 +#define BUS_DMA_BUS3 0x0040 +#define BUS_DMA_BUS4 0x0080 +#define BUS_DMA_READ 0x0100 /* mapping is device -> memory only */ +#define BUS_DMA_WRITE 0x0200 /* mapping is memory -> device only */ +#define BUS_DMA_STREAMING 0x0400 /* hint: sequential, unidirectional */ +#define BUS_DMA_ZERO 0x0800 /* zero memory in dmamem_alloc */ +#define BUS_DMA_NOCACHE 0x1000 +#define BUS_DMA_64BIT 0x2000 /* device handles 64bit dva */ + +/* Forwards needed by prototypes below. */ +struct mbuf; +struct proc; +struct uio; + +#define BUS_DMASYNC_POSTREAD 0x0001 +#define BUS_DMASYNC_POSTWRITE 0x0002 +#define BUS_DMASYNC_PREREAD 0x0004 +#define BUS_DMASYNC_PREWRITE 0x0008 + +typedef struct machine_bus_dma_tag *bus_dma_tag_t; +typedef struct machine_bus_dmamap *bus_dmamap_t; + +/* + * bus_dma_segment_t + * + * Describes a single contiguous DMA transaction. Values + * are suitable for programming into DMA registers. + */ +struct machine_bus_dma_segment { + bus_addr_t ds_addr; /* DMA address */ + bus_size_t ds_len; /* length of transfer */ + + paddr_t _ds_paddr; /* CPU address */ + vaddr_t _ds_vaddr; /* CPU address */ +}; +typedef struct machine_bus_dma_segment bus_dma_segment_t; + +/* + * bus_dma_tag_t + * + * A machine-dependent opaque type describing the implementation of + * DMA for a given bus. + */ + +struct machine_bus_dma_tag { + void *_cookie; /* cookie used in the guts */ + + /* + * DMA mapping methods. + */ + int (*_dmamap_create)(bus_dma_tag_t , bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); + void (*_dmamap_destroy)(bus_dma_tag_t , bus_dmamap_t); + int (*_dmamap_load)(bus_dma_tag_t , bus_dmamap_t, void *, + bus_size_t, struct proc *, int); + int (*_dmamap_load_mbuf)(bus_dma_tag_t , bus_dmamap_t, + struct mbuf *, int); + int (*_dmamap_load_uio)(bus_dma_tag_t , bus_dmamap_t, + struct uio *, int); + int (*_dmamap_load_raw)(bus_dma_tag_t , bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); + int (*_dmamap_load_buffer)(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int, paddr_t *, int *, int); + void (*_dmamap_unload)(bus_dma_tag_t , bus_dmamap_t); + void (*_dmamap_sync)(bus_dma_tag_t , bus_dmamap_t, + bus_addr_t, bus_size_t, int); + + /* + * DMA memory utility functions. + */ + int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); + void (*_dmamem_free)(bus_dma_tag_t, bus_dma_segment_t *, int); + int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); + void (*_dmamem_unmap)(bus_dma_tag_t, caddr_t, size_t); + paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *, + int, off_t, int, int); + + /* + * internal memory address translation information. + */ + bus_addr_t (*_pa_to_device)(paddr_t); + paddr_t (*_device_to_pa)(bus_addr_t); + bus_addr_t _dma_mask; +}; + +#define bus_dmamap_create(t, s, n, m, b, f, p) \ + (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p)) +#define bus_dmamap_destroy(t, p) \ + (*(t)->_dmamap_destroy)((t), (p)) +#define bus_dmamap_load(t, m, b, s, p, f) \ + (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f)) +#define bus_dmamap_load_mbuf(t, m, b, f) \ + (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f)) +#define bus_dmamap_load_uio(t, m, u, f) \ + (*(t)->_dmamap_load_uio)((t), (m), (u), (f)) +#define bus_dmamap_load_raw(t, m, sg, n, s, f) \ + (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f)) +#define bus_dmamap_unload(t, p) \ + (*(t)->_dmamap_unload)((t), (p)) +#define bus_dmamap_sync(t, p, a, l, o) \ + (void)((t)->_dmamap_sync ? \ + (*(t)->_dmamap_sync)((t), (p), (a), (l), (o)) : (void)0) + +#define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \ + (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f)) +#define bus_dmamem_free(t, sg, n) \ + (*(t)->_dmamem_free)((t), (sg), (n)) +#define bus_dmamem_map(t, sg, n, s, k, f) \ + (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f)) +#define bus_dmamem_unmap(t, k, s) \ + (*(t)->_dmamem_unmap)((t), (k), (s)) +#define bus_dmamem_mmap(t, sg, n, o, p, f) \ + (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f)) + +int _dmamap_create(bus_dma_tag_t, bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); +void _dmamap_destroy(bus_dma_tag_t, bus_dmamap_t); +int _dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int); +int _dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, struct mbuf *, int); +int _dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, struct uio *, int); +int _dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); +int _dmamap_load_buffer(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int, paddr_t *, int *, int); +void _dmamap_unload(bus_dma_tag_t, bus_dmamap_t); +void _dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, + bus_size_t, int); + +int _dmamem_alloc(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); +void _dmamem_free(bus_dma_tag_t, bus_dma_segment_t *, int); +int _dmamem_map(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); +void _dmamem_unmap(bus_dma_tag_t, caddr_t, size_t); +paddr_t _dmamem_mmap(bus_dma_tag_t, bus_dma_segment_t *, int, off_t, int, int); +int _dmamem_alloc_range(bus_dma_tag_t, bus_size_t, bus_size_t, bus_size_t, + bus_dma_segment_t *, int, int *, int, paddr_t, paddr_t); + +/* + * bus_dmamap_t + * + * Describes a DMA mapping. + */ +struct machine_bus_dmamap { + /* + * PRIVATE MEMBERS: not for use by machine-independent code. + */ + bus_size_t _dm_size; /* largest DMA transfer mappable */ + int _dm_segcnt; /* number of segs this map can map */ + bus_size_t _dm_maxsegsz; /* largest possible segment */ + bus_size_t _dm_boundary; /* don't cross this */ + int _dm_flags; /* misc. flags */ + + void *_dm_cookie; /* cookie for bus-specific functions */ + + /* + * PUBLIC MEMBERS: these are used by machine-independent code. + */ + bus_size_t dm_mapsize; /* size of the mapping */ + int dm_nsegs; /* # valid segments in mapping */ + bus_dma_segment_t dm_segs[1]; /* segments; variable length */ +}; + +#endif /* _MACHINE_BUS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/cdefs.h b/lib/libc/include/mips64el-openbsd-none/loongson/cdefs.h new file mode 100644 index 0000000000..e44353fedf --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/cdefs.h @@ -0,0 +1,3 @@ +/* $OpenBSD: cdefs.h,v 1.2 2013/03/28 17:30:45 martynas Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/conf.h b/lib/libc/include/mips64el-openbsd-none/loongson/conf.h new file mode 100644 index 0000000000..8eafed12d4 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/conf.h @@ -0,0 +1,42 @@ +/* $OpenBSD: conf.h,v 1.4 2022/06/28 14:43:50 visa Exp $ */ +/* $NetBSD: conf.h,v 1.2 1996/05/05 19:28:34 christos Exp $ */ + +/* + * Copyright (c) 1996 Christos Zoulas. 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 Christos Zoulas. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +/* open, close, write, ioctl, kqueue */ +#define cdev_apm_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,n,kqfilter) } + +cdev_decl(apm); \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/cpu.h b/lib/libc/include/mips64el-openbsd-none/loongson/cpu.h new file mode 100644 index 0000000000..d3d84bf3db --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/cpu.h @@ -0,0 +1,103 @@ +/* $OpenBSD: cpu.h,v 1.8 2017/07/30 16:05:24 visa 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 and Rick Macklem. + * + * 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. + * + * Copyright (C) 1989 Digital Equipment Corporation. + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby granted, + * provided that the above copyright notice appears in all copies. + * Digital Equipment Corporation makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * from: @(#)cpu.h 8.4 (Berkeley) 1/4/94 + */ + +#ifdef _KERNEL + +#if defined(MULTIPROCESSOR) && !defined(_LOCORE) +#define MAXCPUS 4 +struct cpu_info; +struct cpu_info *hw_getcurcpu(void); +void hw_setcurcpu(struct cpu_info *); +void hw_cpu_boot_secondary(struct cpu_info *); +void hw_cpu_hatch(struct cpu_info *); +void hw_cpu_spinup_trampoline(struct cpu_info *); +int hw_ipi_intr_establish(int (*)(void *), u_long); +void hw_ipi_intr_set(u_long); +void hw_ipi_intr_clear(u_long); +#endif /* MULTIPROCESSOR && !_LOCORE */ + +#if defined(CPU_LOONGSON2) && !defined(CPU_LOONGSON3) +#define Mips_SyncCache(ci) \ + Loongson2_SyncCache((ci)) +#define Mips_InvalidateICache(ci, va, l) \ + Loongson2_InvalidateICache((ci), (va), (l)) +#define Mips_InvalidateICachePage(ci, va) \ + Loongson2_InvalidateICachePage((ci), (va)) +#define Mips_SyncICache(ci) \ + Loongson2_SyncICache((ci)) +#define Mips_SyncDCachePage(ci, va, pa) \ + Loongson2_SyncDCachePage((ci), (va), (pa)) +#define Mips_HitSyncDCachePage(ci, va, pa) \ + Loongson2_SyncDCachePage((ci), (va), (pa)) +#define Mips_HitSyncDCache(ci, va, l) \ + Loongson2_HitSyncDCache((ci), (va), (l)) +#define Mips_IOSyncDCache(ci, va, l, h) \ + Loongson2_IOSyncDCache((ci), (va), (l), (h)) +#define Mips_HitInvalidateDCache(ci, va, l) \ + Loongson2_HitInvalidateDCache((ci), (va), (l)) +#endif + +#if defined(CPU_LOONGSON3) && !defined(CPU_LOONGSON2) +#define Mips_SyncCache(ci) \ + Loongson3_SyncCache((ci)) +#define Mips_InvalidateICache(ci, va, l) \ + Loongson3_InvalidateICache((ci), (va), (l)) +#define Mips_InvalidateICachePage(ci, va) \ + Loongson3_InvalidateICachePage((ci), (va)) +#define Mips_SyncICache(ci) \ + Loongson3_SyncICache((ci)) +#define Mips_SyncDCachePage(ci, va, pa) \ + Loongson3_SyncDCachePage((ci), (va), (pa)) +#define Mips_HitSyncDCachePage(ci, va, pa) \ + Loongson3_SyncDCachePage((ci), (va), (pa)) +#define Mips_HitSyncDCache(ci, va, l) \ + Loongson3_HitSyncDCache((ci), (va), (l)) +#define Mips_IOSyncDCache(ci, va, l, h) \ + Loongson3_IOSyncDCache((ci), (va), (l), (h)) +#define Mips_HitInvalidateDCache(ci, va, l) \ + Loongson3_HitInvalidateDCache((ci), (va), (l)) +#endif + +#endif /* _KERNEL */ + +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/cpustate.h b/lib/libc/include/mips64el-openbsd-none/loongson/cpustate.h new file mode 100644 index 0000000000..f5aff1a41b --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/cpustate.h @@ -0,0 +1,3 @@ +/* $OpenBSD: cpustate.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/db_machdep.h b/lib/libc/include/mips64el-openbsd-none/loongson/db_machdep.h new file mode 100644 index 0000000000..3759d83371 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/db_machdep.h @@ -0,0 +1,3 @@ +/* $OpenBSD: db_machdep.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/disklabel.h b/lib/libc/include/mips64el-openbsd-none/loongson/disklabel.h new file mode 100644 index 0000000000..e7758205f6 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/disklabel.h @@ -0,0 +1,16 @@ +/* $OpenBSD: disklabel.h,v 1.3 2015/09/30 15:35:30 krw Exp $ */ +/* public domain */ + +/* + * Standard MBR partition scheme, with the label in the second sector + * of the OpenBSD partition. + */ + +#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_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/elf.h b/lib/libc/include/mips64el-openbsd-none/loongson/elf.h new file mode 100644 index 0000000000..5918df727b --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/elf.h @@ -0,0 +1,3 @@ +/* $OpenBSD: elf.h,v 1.1 2024/07/14 19:33:59 miod Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/endian.h b/lib/libc/include/mips64el-openbsd-none/loongson/endian.h new file mode 100644 index 0000000000..2e7392a082 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/endian.h @@ -0,0 +1,3 @@ +/* $OpenBSD: endian.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/exec.h b/lib/libc/include/mips64el-openbsd-none/loongson/exec.h new file mode 100644 index 0000000000..53433783f0 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/exec.h @@ -0,0 +1,3 @@ +/* $OpenBSD: exec.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/fenv.h b/lib/libc/include/mips64el-openbsd-none/loongson/fenv.h new file mode 100644 index 0000000000..08e89fbf32 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/fenv.h @@ -0,0 +1,3 @@ +/* $OpenBSD: fenv.h,v 1.2 2013/06/01 21:20:54 jasper Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/fpu.h b/lib/libc/include/mips64el-openbsd-none/loongson/fpu.h new file mode 100644 index 0000000000..19ee8af414 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/fpu.h @@ -0,0 +1,3 @@ +/* $OpenBSD: fpu.h,v 1.1 2010/09/17 00:34:04 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/frame.h b/lib/libc/include/mips64el-openbsd-none/loongson/frame.h new file mode 100644 index 0000000000..d14827e33c --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/frame.h @@ -0,0 +1,3 @@ +/* $OpenBSD: frame.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/hibernate.h b/lib/libc/include/mips64el-openbsd-none/loongson/hibernate.h new file mode 100644 index 0000000000..f0a99c6df6 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/hibernate.h @@ -0,0 +1,33 @@ +/* $OpenBSD: hibernate.h,v 1.3 2018/06/21 07:33:30 mlarkin Exp $ */ + +/* + * Copyright (c) 2013 Paul Irofti. + * + * 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 + +/* Loongson hibernate support structures and functions */ + +int get_hibernate_info_md(union hibernate_info *); +void hibernate_flush(void); +void hibernate_enter_resume_mapping(vaddr_t, paddr_t, int); +int hibernate_inflate_skip(union hibernate_info *, paddr_t); +int hibernate_suspend(void); +void hibernate_switch_stack_machdep(void); +void hibernate_resume_machdep(vaddr_t); +void hibernate_activate_resume_pt_machdep(void); +void hibernate_enable_intr_machdep(void); +void hibernate_disable_intr_machdep(void); \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/hibernate_var.h b/lib/libc/include/mips64el-openbsd-none/loongson/hibernate_var.h new file mode 100644 index 0000000000..de84657a4b --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/hibernate_var.h @@ -0,0 +1,39 @@ +/* $OpenBSD: hibernate_var.h,v 1.1 2013/06/02 21:46:04 pirofti Exp $ */ + +/* + * Copyright (c) 2013 Paul Irofti. + * + * 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. + */ + +/* Loongson hibernate support definitions */ + +#define PAGE_MASK_4M ((256 * PAGE_SIZE) - 1) + +#define PIGLET_PAGE_MASK ~((paddr_t)PAGE_MASK_4M) + +/* + * Steal hibernate pages right after the first page which is reserved + * for the exception area. + * */ +#define HIBERNATE_STACK_PAGE (PAGE_SIZE * 1) +#define HIBERNATE_INFLATE_PAGE (PAGE_SIZE * 2) +#define HIBERNATE_COPY_PAGE (PAGE_SIZE * 3) +#define HIBERNATE_HIBALLOC_PAGE (PAGE_SIZE * 4) + +#define HIBERNATE_RESERVED_PAGES 4 + +/* Use 4MB hibernation chunks */ +#define HIBERNATE_CHUNK_SIZE 0x400000 + +#define HIBERNATE_CHUNK_TABLE_SIZE 0x100000 \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/ieee.h b/lib/libc/include/mips64el-openbsd-none/loongson/ieee.h new file mode 100644 index 0000000000..d390acb3c5 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/ieee.h @@ -0,0 +1,3 @@ +/* $OpenBSD: ieee.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/ieeefp.h b/lib/libc/include/mips64el-openbsd-none/loongson/ieeefp.h new file mode 100644 index 0000000000..17e880358e --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/ieeefp.h @@ -0,0 +1,3 @@ +/* $OpenBSD: ieeefp.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/intr.h b/lib/libc/include/mips64el-openbsd-none/loongson/intr.h new file mode 100644 index 0000000000..64d103bc39 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/intr.h @@ -0,0 +1,193 @@ +/* $OpenBSD: intr.h,v 1.19 2025/05/10 10:01:03 visa Exp $ */ + +/* + * Copyright (c) 2001-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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_INTR_H_ +#define _MACHINE_INTR_H_ + +#define __USE_MI_SOFTINTR + +#include + +/* + * The interrupt level ipl is a logical level; per-platform interrupt + * code will turn it into the appropriate hardware interrupt masks + * values. + * + * Interrupt sources on the CPU are kept enabled regardless of the + * current ipl value; individual hardware sources interrupting while + * logically masked are masked on the fly, remembered as pending, and + * unmasked at the first splx() opportunity. + * + * An exception to this rule is the clock interrupt. Clock interrupts + * are always allowed to happen, but will (of course!) not be serviced + * if logically masked. The reason for this is that clocks usually sit on + * INT5 and cannot be easily masked if external hardware masking is used. + */ + +/* Interrupt priority `levels'; not mutually exclusive. */ +#define IPL_NONE 0 /* nothing */ +#define IPL_SOFTINT 1 /* soft interrupts */ +#define IPL_SOFTCLOCK 1 /* soft clock interrupts */ +#define IPL_SOFTNET 2 /* soft network interrupts */ +#define IPL_SOFTTTY 3 /* soft terminal interrupts */ +#define IPL_SOFTHIGH IPL_SOFTTTY /* highest level of soft interrupts */ +#define IPL_BIO 4 /* block I/O */ +#define IPL_AUDIO IPL_BIO +#define IPL_NET 5 /* network */ +#define IPL_TTY 6 /* terminal */ +#define IPL_VM 7 /* memory allocation */ +#define IPL_CLOCK 8 /* clock */ +#define IPL_STATCLOCK IPL_CLOCK +#define IPL_SCHED 9 /* everything */ +#define IPL_HIGH 9 /* everything */ +#define IPL_IPI 10 /* interprocessor interrupt */ +#define NIPLS 11 /* number of levels */ + +#define IPL_MPFLOOR IPL_TTY + +/* Interrupt priority 'flags'. */ +#define IPL_MPSAFE 0x100 + +/* Interrupt sharing types. */ +#define IST_NONE 0 /* none */ +#define IST_PULSE 1 /* pulsed */ +#define IST_EDGE 2 /* edge-triggered */ +#define IST_LEVEL 3 /* level-triggered */ + +#ifndef _LOCORE + +void softintr(int); + +#define splbio() splraise(IPL_BIO) +#define splnet() splraise(IPL_NET) +#define spltty() splraise(IPL_TTY) +#define splaudio() splraise(IPL_AUDIO) +#define splclock() splraise(IPL_CLOCK) +#define splvm() splraise(IPL_VM) +#define splhigh() splraise(IPL_HIGH) + +#define splsoftclock() splraise(IPL_SOFTCLOCK) +#define splsoftnet() splraise(IPL_SOFTNET) +#define splstatclock() splhigh() + +#define splsched() splhigh() +#define spl0() spllower(0) + +void splinit(void); + +#ifdef DIAGNOSTIC +/* + * Although this function is implemented in MI code, it must be in this MD + * header because we don't want this header to include MI includes. + */ +void splassert_fail(int, int, const char *); +extern int splassert_ctl; +void splassert_check(int, const char *); +#define splassert(__wantipl) do { \ + if (splassert_ctl > 0) { \ + splassert_check(__wantipl, __func__); \ + } \ +} while (0) +#define splsoftassert(wantipl) splassert(wantipl) +#else +#define splassert(X) +#define splsoftassert(X) +#endif + +void register_splx_handler(void (*)(int)); +int splraise(int); +void splx(int); +int spllower(int); + +/* + * Interrupt control struct used by interrupt dispatchers + * to hold interrupt handler info. + */ + +#include + +struct intrhand { + struct intrhand *ih_next; + int (*ih_fun)(void *); + void *ih_arg; + int ih_level; + int ih_irq; + int ih_flags; +#define IH_MPSAFE 0x01 + struct evcount ih_count; +}; + +void intr_barrier(void *); + +/* + * Low level interrupt dispatcher registration data. + */ + +/* Schedule priorities for base interrupts (CPU) */ +#define INTPRI_IPI 0 +#define INTPRI_CLOCK 1 +/* other values are system-specific */ + +#define NLOWINT 4 /* Number of low level registrations possible */ + +extern uint32_t idle_mask; + +struct trapframe; +void set_intr(int, uint32_t, uint32_t(*)(uint32_t, struct trapframe *)); + +uint32_t updateimask(uint32_t); +void dosoftint(void); + +#ifdef MULTIPROCESSOR +extern uint32_t ipi_mask; +#define ENABLEIPI() updateimask(~ipi_mask) +#endif + +struct pic { + void (*pic_eoi)(int); + void (*pic_mask)(int); + void (*pic_unmask)(int); +}; + +#ifdef CPU_LOONGSON3 + +void loongson3_intr_init(void); +void *loongson3_intr_establish(int, int, int (*)(void *), void*, + const char *); +void loongson3_intr_disestablish(void *); +void *loongson3_ht_intr_establish(int, int, int (*)(void *), void*, + const char *); +void loongson3_ht_intr_disestablish(void *); + +void loongson3_register_ht_pic(const struct pic *); + +#endif /* CPU_LOONGSON3 */ + +#endif /* _LOCORE */ + +#endif /* _MACHINE_INTR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/isa_machdep.h b/lib/libc/include/mips64el-openbsd-none/loongson/isa_machdep.h new file mode 100644 index 0000000000..201c218bd3 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/isa_machdep.h @@ -0,0 +1,51 @@ +/* $OpenBSD: isa_machdep.h,v 1.2 2010/05/08 21:59:56 miod Exp $ */ + +/* + * Copyright (c) 2007 Miodrag Vallat. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice, this permission notice, and the disclaimer below + * 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_ISA_MACHDEP_H_ +#define _MACHINE_ISA_MACHDEP_H_ + +#include + +#define __NO_ISA_INTR_CHECK + +typedef struct mips_isa_chipset *isa_chipset_tag_t; + +struct mips_isa_chipset { + void *ic_v; + + void (*ic_attach_hook)(struct device *, struct device *, + struct isabus_attach_args *); + void *(*ic_intr_establish)(void *, int, int, int, int (*)(void *), + void *, char *); + void (*ic_intr_disestablish)(void *, void *); +}; + +#define isa_attach_hook(p, s, iba) \ + (*(iba)->iba_ic->ic_attach_hook)((p), (s), (iba)) +#define isa_intr_establish(c, i, t, l, f, a, n) \ + (*(c)->ic_intr_establish)((c)->ic_v, (i), (t), (l), (f), (a), (n)) +#define isa_intr_disestablish(c, h) \ + (*(c)->ic_intr_disestablish)((c)->ic_v, (h)) + +void loongson_generic_isa_attach_hook(struct device *, struct device *, + struct isabus_attach_args *); +void loongson_isa_specific_eoi(int); +void loongson_set_isa_imr(uint); + +#endif \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/kcore.h b/lib/libc/include/mips64el-openbsd-none/loongson/kcore.h new file mode 100644 index 0000000000..c38fa9f7f6 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/kcore.h @@ -0,0 +1,3 @@ +/* $OpenBSD: kcore.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/limits.h b/lib/libc/include/mips64el-openbsd-none/loongson/limits.h new file mode 100644 index 0000000000..12007d997a --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/limits.h @@ -0,0 +1,3 @@ +/* $OpenBSD: limits.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/loadfile_machdep.h b/lib/libc/include/mips64el-openbsd-none/loongson/loadfile_machdep.h new file mode 100644 index 0000000000..1486f8ce5c --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/loadfile_machdep.h @@ -0,0 +1,49 @@ +/* $OpenBSD: loadfile_machdep.h,v 1.2 2015/07/17 20:44:39 miod Exp $ */ +/* $NetBSD: loadfile_machdep.h,v 1.2 2001/10/31 17:20:49 thorpej Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * 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. + */ + +#define BOOT_ELF +#define ELFSIZE 64 + +#define LOAD_KERNEL LOAD_ALL +#define COUNT_KERNEL COUNT_ALL + +#define LOADADDR(a) (((u_long)(a)) + offset) +#define ALIGNENTRY(a) ((u_long)(a)) +#define READ(f, b, c) read((f), (void *)LOADADDR(b), (c)) +#define BCOPY(s, d, c) memcpy((void *)LOADADDR(d), (void *)(s), (c)) +#define BZERO(d, c) memset((void *)LOADADDR(d), 0, (c)) +#define WARN(a) (void)(printf a, \ + printf((errno ? ": %s\n" : "\n"), \ + strerror(errno))) +#define PROGRESS(a) (void) printf a +#define ALLOC(a) alloc(a) +#define FREE(a, b) free(a, b) \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/loongson2.h b/lib/libc/include/mips64el-openbsd-none/loongson/loongson2.h new file mode 100644 index 0000000000..05688a8e0f --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/loongson2.h @@ -0,0 +1,3 @@ +/* $OpenBSD: loongson2.h,v 1.1.1.1 2009/08/06 20:51:44 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/loongson3.h b/lib/libc/include/mips64el-openbsd-none/loongson/loongson3.h new file mode 100644 index 0000000000..bcbe6ca701 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/loongson3.h @@ -0,0 +1,3 @@ +/* $OpenBSD: loongson3.h,v 1.1 2016/11/06 10:20:33 visa Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/memconf.h b/lib/libc/include/mips64el-openbsd-none/loongson/memconf.h new file mode 100644 index 0000000000..c7782048ac --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/memconf.h @@ -0,0 +1,3 @@ +/* $OpenBSD: memconf.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/mips_opcode.h b/lib/libc/include/mips64el-openbsd-none/loongson/mips_opcode.h new file mode 100644 index 0000000000..5b5cbc3494 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/mips_opcode.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mips_opcode.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/mplock.h b/lib/libc/include/mips64el-openbsd-none/loongson/mplock.h new file mode 100644 index 0000000000..dc963887f8 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/mplock.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mplock.h,v 1.1 2017/01/19 14:51:02 visa Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/mutex.h b/lib/libc/include/mips64el-openbsd-none/loongson/mutex.h new file mode 100644 index 0000000000..8003e465f6 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/mutex.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mutex.h,v 1.2 2015/07/08 13:37:31 dlg Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/param.h b/lib/libc/include/mips64el-openbsd-none/loongson/param.h new file mode 100644 index 0000000000..cd410bd602 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/param.h @@ -0,0 +1,31 @@ +/* $OpenBSD: param.h,v 1.3 2013/03/23 16:12:23 deraadt Exp $ */ + +/* Public Domain */ + +#ifndef _MACHINE_PARAM_H_ +#define _MACHINE_PARAM_H_ + +#define MACHINE "loongson" +#define _MACHINE loongson +#define MACHINE_ARCH "mips64el" /* not the canonical endianness */ +#define _MACHINE_ARCH mips64el +#define MACHINE_CPU "mips64" +#define _MACHINE_CPU mips64 +#define MID_MACHINE MID_MIPS64 + +#ifdef _KERNEL + +/* + * The Loongson level 1 cache expects software to prevent virtual + * aliases. Unfortunately, since this cache is physically tagged, + * this would require all virtual address to have the same bits 14 + * and 13 as their physical addresses, which is not something the + * kernel can guarantee unless the page size is at least 16KB. + */ +#define PAGE_SHIFT 14 + +#endif /* _KERNEL */ + +#include + +#endif /* _MACHINE_PARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/pcb.h b/lib/libc/include/mips64el-openbsd-none/loongson/pcb.h new file mode 100644 index 0000000000..e48bfc2f31 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/pcb.h @@ -0,0 +1,3 @@ +/* $OpenBSD: pcb.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/pci_machdep.h b/lib/libc/include/mips64el-openbsd-none/loongson/pci_machdep.h new file mode 100644 index 0000000000..ade283806c --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/pci_machdep.h @@ -0,0 +1,101 @@ +/* $OpenBSD: pci_machdep.h,v 1.10 2016/05/04 14:30:01 kettenis Exp $ */ + +/* + * Copyright (c) 2003-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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. + * + */ + +typedef struct mips_pci_chipset *pci_chipset_tag_t; +typedef u_long pcitag_t; +typedef u_long pci_intr_handle_t; + +struct pci_attach_args; + +/* + * mips-specific PCI structure and type definitions. + * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE. + */ +struct mips_pci_chipset { + void *pc_conf_v; + void (*pc_attach_hook)(struct device *, + struct device *, struct pcibus_attach_args *); + int (*pc_bus_maxdevs)(void *, int); + pcitag_t (*pc_make_tag)(void *, int, int, int); + void (*pc_decompose_tag)(void *, pcitag_t, int *, + int *, int *); + int (*pc_conf_size)(void *, pcitag_t); + pcireg_t (*pc_conf_read)(void *, pcitag_t, int); + void (*pc_conf_write)(void *, pcitag_t, int, pcireg_t); + + void *pc_intr_v; + int (*pc_intr_map)(struct pci_attach_args *, pci_intr_handle_t *); + const char *(*pc_intr_string)(void *, pci_intr_handle_t); + void *(*pc_intr_establish)(void *, pci_intr_handle_t, + int, int (*)(void *), void *, char *); + void (*pc_intr_disestablish)(void *, void *); +}; + +/* + * Functions provided to machine-independent PCI code. + */ +#define pci_attach_hook(p, s, pba) \ + (*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba)) +#define pci_bus_maxdevs(c, b) \ + (*(c)->pc_bus_maxdevs)((c)->pc_conf_v, (b)) +#define pci_make_tag(c, b, d, f) \ + (*(c)->pc_make_tag)((c)->pc_conf_v, (b), (d), (f)) +#define pci_decompose_tag(c, t, bp, dp, fp) \ + (*(c)->pc_decompose_tag)((c)->pc_conf_v, (t), (bp), (dp), (fp)) +#define pci_conf_size(c, t) \ + (*(c)->pc_conf_size)((c)->pc_conf_v, (t)) +#define pci_conf_read(c, t, r) \ + (*(c)->pc_conf_read)((c)->pc_conf_v, (t), (r)) +#define pci_conf_write(c, t, r, v) \ + (*(c)->pc_conf_write)((c)->pc_conf_v, (t), (r), (v)) +#define pci_intr_map(c, ihp) \ + (*(c)->pa_pc->pc_intr_map)((c), (ihp)) +#define pci_intr_map_msi(c, ihp) (-1) +#define pci_intr_map_msix(c, vec, ihp) (-1) +#define pci_intr_string(c, ih) \ + (*(c)->pc_intr_string)((c)->pc_intr_v, (ih)) +#define pci_intr_establish(c, ih, l, h, a, nm) \ + (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), (h), (a), (nm)) +#define pci_intr_disestablish(c, iv) \ + (*(c)->pc_intr_disestablish)((c)->pc_intr_v, (iv)) +#define pci_probe_device_hook(c, a) (0) + +#define pci_min_powerstate(c, t) (PCI_PMCSR_STATE_D3) +#define pci_set_powerstate_md(c, t, s, p) + +/* PCI view of CPU memory */ +extern paddr_t loongson_dma_base; + +/* + * Functions used during early system configuration. + */ + +extern pcitag_t (*pci_make_tag_early)(int, int, int); +extern pcireg_t (*pci_conf_read_early)(pcitag_t, int); + +#define pci_dev_postattach(a, b) \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/pmap.h b/lib/libc/include/mips64el-openbsd-none/loongson/pmap.h new file mode 100644 index 0000000000..eda0b11a3c --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/pmap.h @@ -0,0 +1,3 @@ +/* $OpenBSD: pmap.h,v 1.1.1.1 2009/07/31 09:26:26 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/pmon.h b/lib/libc/include/mips64el-openbsd-none/loongson/pmon.h new file mode 100644 index 0000000000..7729adb468 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/pmon.h @@ -0,0 +1,209 @@ +/* $OpenBSD: pmon.h,v 1.5 2017/05/21 13:00:53 visa Exp $ */ + +/* + * Copyright (c) 2009, 2012 Miodrag Vallat. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_PMON_H_ +#define _MACHINE_PMON_H_ + +#if defined(_KERNEL) || defined(_STANDALONE) + +/* + * PMON2000 callvec definitions + */ + +/* 32-bit compatible types */ +typedef uint32_t pmon_size_t; +typedef int32_t pmon_ssize_t; +typedef int64_t pmon_off_t; + +int pmon_open(const char *, int, ...); +int pmon_close(int); +int pmon_read(int, void *, pmon_size_t); +pmon_ssize_t pmon_write(int, const void *, pmon_size_t); +pmon_off_t pmon_lseek(int, pmon_off_t, int); +int pmon_printf(const char *, ...); +void pmon_cacheflush(void); +char * pmon_gets(char *); + +#define PMON_MAXLN 256 /* internal gets() size limit */ + +extern int32_t pmon_callvec; + +const char *pmon_getarg(const int); +void pmon_init(int32_t, int32_t, int32_t, int32_t, uint32_t); + +#define PMON_ENVTYPE_ENVP 0 +#define PMON_ENVTYPE_EFI 1 +int pmon_getenvtype(void); + +/* + * The new environment interface is a /salmigondis/ of badly thought-out + * structs put together, pretending to be inspired by EFI but conveniently + * omitting key EFI structs because they are deemed non-applicable to + * MIPS systems. + * Of course, some fields are absolute addresses, while others are relative + * pointers, to add to the confusion. + */ + +struct pmon_env_reset { + void (*cold_boot)(void); /* not filled */ + void (*warm_boot)(void); + void (*boot)(unsigned int); /* not filled */ + void (*poweroff)(void); +}; + +/* all values are offsets relative to the beginning of the struct */ +struct pmon_env_ptr { + uint64_t offs_mem; + uint64_t offs_cpu; + uint64_t offs_sys; + uint64_t offs_irq; + uint64_t offs_iface; + uint64_t offs_special; + uint64_t offs_device; +}; + +struct pmon_env_smbios { + uint16_t version; + uint64_t vga_bios; + struct pmon_env_ptr ptrs; +}; + +struct pmon_env_efi { + uint64_t mps; /* not filled */ + uint64_t acpi; /* not filled */ + uint64_t acpi20; /* not filled */ + struct pmon_env_smbios bios; + uint64_t sal_systab; /* not filled */ + uint64_t bootinfo; /* not filled */ +}; + +struct pmon_env { + struct pmon_env_efi efi; + struct pmon_env_reset reset; +}; + +#define PMON_MEM_MAX 128 +struct pmon_env_mem_entry { + uint32_t node; + uint32_t type; +#define PMON_MEM_SYSTEM_LOW 1 /* physical memory <= 256 MB */ +#define PMON_MEM_SYSTEM_HIGH 2 /* physical memory > 256 MB */ +#define PMON_MEM_RESERVED 3 +#define PMON_MEM_PCI_IO 4 +#define PMON_MEM_PCI_MEM 5 +#define PMON_MEM_CPU_REGISTERS 6 +#define PMON_MEM_VIDEO_ROM 7 +#define PMON_MEM_OTHER_ROM 8 +#define PMON_MEM_ACPI_TABLE 9 + uint64_t address; + uint32_t size; +}; +struct pmon_env_mem { + uint16_t version; /* not filled */ + uint32_t nentries; + uint32_t mem_freq; + struct pmon_env_mem_entry mem_map[PMON_MEM_MAX]; +} __packed; + +struct pmon_env_cpu { + uint16_t version; /* not filled */ + uint32_t prid; /* cop0 PrID */ + uint32_t cputype; +/* 0 and 1 are supposedly intended for 2E and 2F, which do NOT provide this + interface; moreover Linux and PMON disagree on the values and have 2E and + 2F swapped. */ +#define PMON_CPUTYPE_LS3A 2 +#define PMON_CPUTYPE_LS3B 3 +#define PMON_CPUTYPE_LS1A 4 +#define PMON_CPUTYPE_LS1B 5 + uint32_t node; /* total number of NUMA nodes */ + uint16_t coreid; /* boot CPU core id */ + uint16_t reserved_cores; /* mask of reserved cores */ + uint32_t speed; + uint32_t ncpus; +} __packed; + +struct pmon_env_sys { + uint16_t version; /* not filled */ + uint32_t ccnuma_smp; + uint32_t double_channel; +} __packed; + +struct pmon_env_irq { + uint16_t version; /* not filled */ + uint16_t size; /* not filled */ + uint16_t rtr_bus; /* not filled */ + uint16_t rtr_devfn; /* not filled */ + uint32_t vendor; /* not filled */ + uint32_t device; /* not filled */ + uint32_t pic_type; +#define PMON_IRQ_PIC_HT 0 +#define PMON_IRQ_PIC_I8259 1 + uint64_t ht_interrupt_bit; + uint64_t ht_enable; + uint32_t node; + uint64_t pci_memory_space_start; + uint64_t pci_memory_space_end; + uint64_t pci_io_space_start; /* not filled */ + uint64_t pci_io_space_end; /* not filled */ + uint64_t pci_cfg_space; /* not filled */ +} __packed; + +struct pmon_env_iface { + uint16_t version; +#define PMON_IFACE_VERSION 0x0001 + uint16_t size; + uint8_t flag; + char description[64]; /* firmware version */ +} __packed; + +#define PMON_RESOURCE_MAX 128 +struct pmon_env_resource { + uint64_t start; + uint64_t end; + char name[64]; + uint32_t flags; +}; +struct pmon_env_special { + uint16_t version; + char name[64]; + uint32_t type; + struct pmon_env_resource resource[PMON_RESOURCE_MAX]; +}; + +struct pmon_env_device { + char name[64]; /* system description */ + uint32_t nentries; + struct pmon_env_resource resource[PMON_RESOURCE_MAX]; +}; + +const char *pmon_getenv(const char *); + +const struct pmon_env_reset *pmon_get_env_reset(void); +const struct pmon_env_smbios *pmon_get_env_smbios(void); +const struct pmon_env_mem *pmon_get_env_mem(void); +const struct pmon_env_cpu *pmon_get_env_cpu(void); +const struct pmon_env_sys *pmon_get_env_sys(void); +const struct pmon_env_irq *pmon_get_env_irq(void); +const struct pmon_env_iface *pmon_get_env_iface(void); +const struct pmon_env_special *pmon_get_env_special(void); +const struct pmon_env_device *pmon_get_env_device(void); + +#endif /* _KERNEL || _STANDALONE */ + +#endif /* _MACHINE_PMON_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/proc.h b/lib/libc/include/mips64el-openbsd-none/loongson/proc.h new file mode 100644 index 0000000000..27b68200cf --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/proc.h @@ -0,0 +1,3 @@ +/* $OpenBSD: proc.h,v 1.1.1.1 2009/07/31 09:26:26 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/profile.h b/lib/libc/include/mips64el-openbsd-none/loongson/profile.h new file mode 100644 index 0000000000..d258d1147b --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/profile.h @@ -0,0 +1,3 @@ +/* $OpenBSD: profile.h,v 1.1.1.1 2009/07/31 09:26:26 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/pte.h b/lib/libc/include/mips64el-openbsd-none/loongson/pte.h new file mode 100644 index 0000000000..24c761d664 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/pte.h @@ -0,0 +1,3 @@ +/* $OpenBSD: pte.h,v 1.1.1.1 2009/07/31 09:26:26 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/ptrace.h b/lib/libc/include/mips64el-openbsd-none/loongson/ptrace.h new file mode 100644 index 0000000000..bd8e886725 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/ptrace.h @@ -0,0 +1,3 @@ +/* $OpenBSD: ptrace.h,v 1.1.1.1 2009/07/31 09:26:26 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/reg.h b/lib/libc/include/mips64el-openbsd-none/loongson/reg.h new file mode 100644 index 0000000000..aeecc496fe --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/reg.h @@ -0,0 +1,3 @@ +/* $OpenBSD: reg.h,v 1.1.1.1 2009/07/31 09:26:26 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/regdef.h b/lib/libc/include/mips64el-openbsd-none/loongson/regdef.h new file mode 100644 index 0000000000..03ae54124e --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/regdef.h @@ -0,0 +1,3 @@ +/* $OpenBSD: regdef.h,v 1.1.1.1 2009/07/31 09:26:26 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/regnum.h b/lib/libc/include/mips64el-openbsd-none/loongson/regnum.h new file mode 100644 index 0000000000..e371c1ed20 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/regnum.h @@ -0,0 +1,3 @@ +/* $OpenBSD: regnum.h,v 1.1.1.1 2009/07/31 09:26:26 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/reloc.h b/lib/libc/include/mips64el-openbsd-none/loongson/reloc.h new file mode 100644 index 0000000000..4eb8c01cf1 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/reloc.h @@ -0,0 +1,5 @@ +/* $OpenBSD: reloc.h,v 1.1 2017/08/12 15:33:41 visa Exp $ */ + +/* public domain */ + +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/setjmp.h b/lib/libc/include/mips64el-openbsd-none/loongson/setjmp.h new file mode 100644 index 0000000000..c834f0409a --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/setjmp.h @@ -0,0 +1,3 @@ +/* $OpenBSD: setjmp.h,v 1.1.1.1 2009/07/31 09:26:26 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/signal.h b/lib/libc/include/mips64el-openbsd-none/loongson/signal.h new file mode 100644 index 0000000000..7f4d38dee7 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/signal.h @@ -0,0 +1,3 @@ +/* $OpenBSD: signal.h,v 1.1.1.1 2009/07/31 09:26:26 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/spinlock.h b/lib/libc/include/mips64el-openbsd-none/loongson/spinlock.h new file mode 100644 index 0000000000..63f58612b8 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/spinlock.h @@ -0,0 +1,3 @@ +/* $OpenBSD: spinlock.h,v 1.1.1.1 2009/07/31 09:26:26 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/sysarch.h b/lib/libc/include/mips64el-openbsd-none/loongson/sysarch.h new file mode 100644 index 0000000000..6dac08a77b --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/sysarch.h @@ -0,0 +1,3 @@ +/* $OpenBSD: sysarch.h,v 1.1.1.1 2009/11/22 18:12:44 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/tcb.h b/lib/libc/include/mips64el-openbsd-none/loongson/tcb.h new file mode 100644 index 0000000000..427e19101a --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/tcb.h @@ -0,0 +1,3 @@ +/* $OpenBSD: tcb.h,v 1.2 2013/06/01 21:20:54 jasper Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/timetc.h b/lib/libc/include/mips64el-openbsd-none/loongson/timetc.h new file mode 100644 index 0000000000..d3d291c815 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/timetc.h @@ -0,0 +1,23 @@ +/* $OpenBSD: timetc.h,v 1.2 2020/07/18 08:37:43 visa Exp $ */ +/* + * Copyright (c) 2020 Paul Irofti + * + * 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_TIMETC_H_ +#define _MACHINE_TIMETC_H_ + +#include + +#endif /* _MACHINE_TIMETC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/trap.h b/lib/libc/include/mips64el-openbsd-none/loongson/trap.h new file mode 100644 index 0000000000..c700eedba1 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/trap.h @@ -0,0 +1,3 @@ +/* $OpenBSD: trap.h,v 1.1.1.1 2009/07/31 09:26:26 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/loongson/vmparam.h b/lib/libc/include/mips64el-openbsd-none/loongson/vmparam.h new file mode 100644 index 0000000000..c6c4b75cfe --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/loongson/vmparam.h @@ -0,0 +1,11 @@ +/* $OpenBSD: vmparam.h,v 1.5 2017/05/21 13:00:53 visa Exp $ */ +/* public domain */ +#ifndef _MACHINE_VMPARAM_H_ +#define _MACHINE_VMPARAM_H_ + +#define VM_PHYSSEG_MAX 8 /* Max number of physical memory segments */ +#define VM_PHYSSEG_STRAT VM_PSTRAT_BIGFIRST + +#include + +#endif /* _MACHINE_VMPARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/_types.h b/lib/libc/include/mips64el-openbsd-none/machine/_types.h new file mode 100644 index 0000000000..327e3d3e38 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/_types.h @@ -0,0 +1,3 @@ +/* $OpenBSD: _types.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/apmvar.h b/lib/libc/include/mips64el-openbsd-none/machine/apmvar.h new file mode 100644 index 0000000000..99c4026f96 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/apmvar.h @@ -0,0 +1,127 @@ +/* $OpenBSD: apmvar.h,v 1.6 2019/01/22 02:36:30 phessler Exp $ */ + +/* + * Copyright (c) 2001 Alexander Guy + * Copyright (c) 1995 John T. Kohl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef _MACHINE_APMVAR_H_ +#define _MACHINE_APMVAR_H_ + +#include + +/* Advanced Power Management (v1.0 and v1.1 specification) + * functions/defines/etc. + */ + +/* These definitions make up the heart of the user-land interface + * to the APM devices. + */ + +#define APM_AC_OFF 0x00 +#define APM_AC_ON 0x01 +#define APM_AC_BACKUP 0x02 +#define APM_AC_UNKNOWN 0xff +#define APM_BATT_HIGH 0x00 +#define APM_BATT_LOW 0x01 +#define APM_BATT_CRITICAL 0x02 +#define APM_BATT_CHARGING 0x03 +#define APM_BATT_UNKNOWN 0xff +#define APM_BATT_LIFE_UNKNOWN 0xff + +#define APM_NOEVENT 0x0000 +#define APM_STANDBY_REQ 0x0001 +#define APM_SUSPEND_REQ 0x0002 +#define APM_NORMAL_RESUME 0x0003 +#define APM_CRIT_RESUME 0x0004 /* suspend/resume happened + without us */ +#define APM_BATTERY_LOW 0x0005 +#define APM_POWER_CHANGE 0x0006 +#define APM_UPDATE_TIME 0x0007 +#define APM_CRIT_SUSPEND_REQ 0x0008 +#define APM_USER_STANDBY_REQ 0x0009 +#define APM_USER_SUSPEND_REQ 0x000A +#define APM_SYS_STANDBY_RESUME 0x000B +#define APM_CAPABILITY_CHANGE 0x000C /* apm v1.2 */ +#define APM_USER_HIBERNATE_REQ 0x000D +#define APM_EVENT_MASK 0xffff + +#define APM_EVENT_COMPOSE(t,i) ((((i) & 0x7fff) << 16)|((t) & APM_EVENT_MASK)) +#define APM_EVENT_TYPE(e) ((e) & APM_EVENT_MASK) +#define APM_EVENT_INDEX(e) ((e) >> 16) + +/* + * LP (Laptop Package) + * + * Copyright (C) 1994 by HOSOKAWA Tatsumi + * + * This software may be used, modified, copied, and distributed, in + * both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + */ + +#define APM_BATTERY_ABSENT 4 + +struct apm_power_info { + u_char battery_state; + u_char ac_state; + u_char battery_life; + u_char spare1; + u_int minutes_left; /* estimate */ + u_int spare2[6]; +}; + +struct apm_ctl { + u_int dev; + u_int mode; +}; + +#define APM_IOC_REJECT _IOW('A', 0, struct apm_event_info) /* reject request # */ +#define APM_IOC_STANDBY _IO('A', 1) /* put system into standby */ +#define APM_IOC_SUSPEND _IO('A', 2) /* put system into suspend */ +#define APM_IOC_GETPOWER _IOR('A', 3, struct apm_power_info) /* fetch battery state */ +#define APM_IOC_DEV_CTL _IOW('A', 5, struct apm_ctl) /* put device into mode */ +#define APM_IOC_PRN_CTL _IOW('A', 6, int ) /* driver power status msg */ +#define APM_PRINT_ON 0 /* driver power status displayed */ +#define APM_PRINT_OFF 1 /* driver power status not displayed */ +#define APM_PRINT_PCT 2 /* driver power status only displayed + if the percentage changes */ +#define APM_IOC_STANDBY_REQ _IO('A', 7) /* request standby */ +#define APM_IOC_SUSPEND_REQ _IO('A', 8) /* request suspend */ +#define APM_IOC_HIBERNATE _IO('A', 9) /* put system into hibernate */ + +#ifdef _KERNEL +void apm_setinfohook(int (*)(struct apm_power_info *)); +int apm_record_event(u_int, const char *, const char *); +#endif + +#endif /* _MACHINE_APMVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/asm.h b/lib/libc/include/mips64el-openbsd-none/machine/asm.h new file mode 100644 index 0000000000..63eab17513 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/asm.h @@ -0,0 +1,9 @@ +/* $OpenBSD: asm.h,v 1.2 2016/11/18 15:38:14 visa Exp $ */ +/* public domain */ + +#ifdef MULTIPROCESSOR +#define HW_GET_CPU_INFO(ci, tmp) \ + dmfc0 ci, COP_0_ERROR_PC +#endif + +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/atomic.h b/lib/libc/include/mips64el-openbsd-none/machine/atomic.h new file mode 100644 index 0000000000..19aa2fd4f6 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/atomic.h @@ -0,0 +1,3 @@ +/* $OpenBSD: atomic.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/autoconf.h b/lib/libc/include/mips64el-openbsd-none/machine/autoconf.h new file mode 100644 index 0000000000..7292105a5b --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/autoconf.h @@ -0,0 +1,124 @@ +/* $OpenBSD: autoconf.h,v 1.17 2017/05/21 13:00:53 visa Exp $ */ + +/* + * Copyright (c) 2001-2003 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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. + * + */ + +/* + * Definitions used by autoconfiguration. + */ + +#ifndef _MACHINE_AUTOCONF_H_ +#define _MACHINE_AUTOCONF_H_ + +#include + +struct bonito_config; +struct htb_config; +struct mips_isa_chipset; + +/* + * List of legacy I/O ranges. + */ +struct legacy_io_range { + bus_addr_t start; + bus_size_t end; /* inclusive */ +}; + +/* + * Per platform information. + */ +struct platform { + int system_type; +#define LOONGSON_2E 0x0000 /* Generic Loongson 2E system */ +#define LOONGSON_YEELOONG 0x0001 /* Lemote Yeeloong */ +#define LOONGSON_GDIUM 0x0002 /* EMTEC Gdium Liberty */ +#define LOONGSON_FULOONG 0x0003 /* Lemote Fuloong */ +#define LOONGSON_LYNLOONG 0x0004 /* Lemote Lynloong */ +#define LOONGSON_EBT700 0x0005 /* eBenton EBT700 */ +#define LOONGSON_3A 0x0066 /* Loongson 2Gq or 3A based system */ + + char *vendor; + char *product; + + const struct bonito_config *bonito_config; + const struct htb_config *htb_config; + struct mips_isa_chipset *isa_chipset; + const struct legacy_io_range *legacy_io_ranges; + + void (*setup)(void); + void (*device_register)(struct device *, + void *); + + void (*powerdown)(void); + void (*reset)(void); + int (*suspend)(void); + int (*resume)(void); + +#ifdef MULTIPROCESSOR + void (*config_secondary_cpus)( + struct device *, cfprint_t); + void (*boot_secondary_cpu)( + struct cpu_info *); + int (*ipi_establish)(int (*)(void *), + cpuid_t); + void (*ipi_set)(cpuid_t); + void (*ipi_clear)(cpuid_t); +#endif /* MULTIPROCESSOR */ +}; + +#define LOONGSON_MAXCPUS 16 + +extern const struct platform *sys_platform; +extern void *loongson_videobios; +extern uint loongson_cpumask; +extern uint loongson_ver; +extern int nnodes; + +#ifdef MULTIPROCESSOR +extern uint64_t cpu_spinup_a0; +extern uint64_t cpu_spinup_sp; +#endif + +struct mainbus_attach_args { + const char *maa_name; +}; + +extern struct device *bootdv; +extern char bootdev[]; +extern enum devclass bootdev_class; + +extern bus_space_tag_t early_mem_t; +extern bus_space_tag_t early_io_t; + +#define REGVAL8(x) *((volatile uint8_t *)PHYS_TO_XKPHYS((x), CCA_NC)) +#define REGVAL32(x) *((volatile uint32_t *)PHYS_TO_XKPHYS((x), CCA_NC)) +#define REGVAL64(x) *((volatile uint64_t *)PHYS_TO_XKPHYS((x), CCA_NC)) + +#define REGVAL(x) REGVAL32(x) + +#include + +#endif /* _MACHINE_AUTOCONF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/bus.h b/lib/libc/include/mips64el-openbsd-none/machine/bus.h new file mode 100644 index 0000000000..24430920dd --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/bus.h @@ -0,0 +1,513 @@ +/* $OpenBSD: bus.h,v 1.8 2020/04/14 17:35:28 kettenis Exp $ */ + +/* + * Copyright (c) 2003-2004 Opsycon AB Sweden. 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_BUS_H_ +#define _MACHINE_BUS_H_ + +#ifdef __STDC__ +#define CAT(a,b) a##b +#define CAT3(a,b,c) a##b##c +#else +#define CAT(a,b) a/**/b +#define CAT3(a,b,c) a/**/b/**/c +#endif + +/* + * Bus access types. + */ +struct mips_bus_space; +typedef u_long bus_addr_t; +typedef u_long bus_size_t; +typedef u_long bus_space_handle_t; +typedef struct mips_bus_space *bus_space_tag_t; + +struct mips_bus_space { + bus_addr_t bus_base; + void *bus_private; + u_int8_t (*_space_read_1)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_1)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int8_t); + u_int16_t (*_space_read_2)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_2)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int16_t); + u_int32_t (*_space_read_4)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_4)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int32_t); + u_int64_t (*_space_read_8)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_8)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int64_t); + void (*_space_read_raw_2)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, u_int8_t *, bus_size_t); + void (*_space_write_raw_2)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const u_int8_t *, bus_size_t); + void (*_space_read_raw_4)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, u_int8_t *, bus_size_t); + void (*_space_write_raw_4)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const u_int8_t *, bus_size_t); + void (*_space_read_raw_8)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, u_int8_t *, bus_size_t); + void (*_space_write_raw_8)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const u_int8_t *, bus_size_t); + int (*_space_map)(bus_space_tag_t , bus_addr_t, + bus_size_t, int, bus_space_handle_t *); + void (*_space_unmap)(bus_space_tag_t, bus_space_handle_t, + bus_size_t); + int (*_space_subregion)(bus_space_tag_t, bus_space_handle_t, + bus_size_t, bus_size_t, bus_space_handle_t *); + void * (*_space_vaddr)(bus_space_tag_t, bus_space_handle_t); + paddr_t (*_space_mmap)(bus_space_tag_t, bus_addr_t, off_t, + int, int); +}; + +#define bus_space_read_1(t, h, o) (*(t)->_space_read_1)((t), (h), (o)) +#define bus_space_read_2(t, h, o) (*(t)->_space_read_2)((t), (h), (o)) +#define bus_space_read_4(t, h, o) (*(t)->_space_read_4)((t), (h), (o)) +#define bus_space_read_8(t, h, o) (*(t)->_space_read_8)((t), (h), (o)) + +#define bus_space_write_1(t, h, o, v) (*(t)->_space_write_1)((t), (h), (o), (v)) +#define bus_space_write_2(t, h, o, v) (*(t)->_space_write_2)((t), (h), (o), (v)) +#define bus_space_write_4(t, h, o, v) (*(t)->_space_write_4)((t), (h), (o), (v)) +#define bus_space_write_8(t, h, o, v) (*(t)->_space_write_8)((t), (h), (o), (v)) + +#define bus_space_read_raw_multi_2(t, h, a, b, l) \ + (*(t)->_space_read_raw_2)((t), (h), (a), (b), (l)) +#define bus_space_read_raw_multi_4(t, h, a, b, l) \ + (*(t)->_space_read_raw_4)((t), (h), (a), (b), (l)) +#define bus_space_read_raw_multi_8(t, h, a, b, l) \ + (*(t)->_space_read_raw_8)((t), (h), (a), (b), (l)) + +#define bus_space_write_raw_multi_2(t, h, a, b, l) \ + (*(t)->_space_write_raw_2)((t), (h), (a), (b), (l)) +#define bus_space_write_raw_multi_4(t, h, a, b, l) \ + (*(t)->_space_write_raw_4)((t), (h), (a), (b), (l)) +#define bus_space_write_raw_multi_8(t, h, a, b, l) \ + (*(t)->_space_write_raw_8)((t), (h), (a), (b), (l)) + +#define bus_space_map(t, o, s, c, p) (*(t)->_space_map)((t), (o), (s), (c), (p)) +#define bus_space_unmap(t, h, s) (*(t)->_space_unmap)((t), (h), (s)) +#define bus_space_subregion(t, h, o, s, p) \ + (*(t)->_space_subregion)((t), (h), (o), (s), (p)) + +#define BUS_SPACE_MAP_CACHEABLE 0x01 +#define BUS_SPACE_MAP_LINEAR 0x02 +#define BUS_SPACE_MAP_PREFETCHABLE 0x04 + +#define bus_space_vaddr(t, h) (*(t)->_space_vaddr)((t), (h)) +#define bus_space_mmap(t, a, o, p, f) \ + (*(t)->_space_mmap)((t), (a), (o), (p), (f)) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_multi(n,m) \ +static __inline void \ +CAT(bus_space_read_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_size_t o, CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) \ + *x++ = CAT(bus_space_read_,n)(bst, bsh, o); \ +} + +bus_space_read_multi(1,8) +bus_space_read_multi(2,16) +bus_space_read_multi(4,32) +bus_space_read_multi(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_region(n,m) \ +static __inline void \ +CAT(bus_space_read_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) { \ + *x++ = CAT(bus_space_read_,n)(bst, bsh, ba); \ + ba += (n); \ + } \ +} + +bus_space_read_region(1,8) +bus_space_read_region(2,16) +bus_space_read_region(4,32) +bus_space_read_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_raw_region(n,m) \ +static __inline void \ +CAT(bus_space_read_raw_region_,n)(bus_space_tag_t bst, \ + bus_space_handle_t bsh, \ + bus_addr_t ba, u_int8_t *x, size_t cnt) \ +{ \ + cnt >>= ((n) >> 1); \ + while (cnt--) { \ + CAT(bus_space_read_raw_multi_,n)(bst, bsh, ba, x, (n)); \ + ba += (n); \ + x += (n); \ + } \ +} + +bus_space_read_raw_region(2,16) +bus_space_read_raw_region(4,32) +bus_space_read_raw_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_multi(n,m) \ +static __inline void \ +CAT(bus_space_write_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_size_t o, const CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) \ + CAT(bus_space_write_,n)(bst, bsh, o, *x++); \ +} + +bus_space_write_multi(1,8) +bus_space_write_multi(2,16) +bus_space_write_multi(4,32) +bus_space_write_multi(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_region(n,m) \ +static __inline void \ +CAT(bus_space_write_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, const CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) { \ + CAT(bus_space_write_,n)(bst, bsh, ba, *x++); \ + ba += (n); \ + } \ +} + +bus_space_write_region(1,8) +bus_space_write_region(2,16) +bus_space_write_region(4,32) +bus_space_write_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_raw_region(n,m) \ +static __inline void \ +CAT(bus_space_write_raw_region_,n)(bus_space_tag_t bst, \ + bus_space_handle_t bsh, \ + bus_addr_t ba, const u_int8_t *x, size_t cnt) \ +{ \ + cnt >>= ((n) >> 1); \ + while (cnt--) { \ + CAT(bus_space_write_raw_multi_,n)(bst, bsh, ba, x, (n)); \ + ba += (n); \ + x += (n); \ + } \ +} + +bus_space_write_raw_region(2,16) +bus_space_write_raw_region(4,32) +bus_space_write_raw_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_set_region(n,m) \ +static __inline void \ +CAT(bus_space_set_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, CAT3(u_int,m,_t) x, size_t cnt) \ +{ \ + while (cnt--) { \ + CAT(bus_space_write_,n)(bst, bsh, ba, x); \ + ba += (n); \ + } \ +} + +bus_space_set_region(1,8) +bus_space_set_region(2,16) +bus_space_set_region(4,32) +bus_space_set_region(8,64) + +/*----------------------------------------------------------------------------*/ +static __inline void +bus_space_copy_1(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + char *s = (char *)(h1 + o1); + char *d = (char *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + + +static __inline void +bus_space_copy_2(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + short *s = (short *)(h1 + o1); + short *d = (short *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + +static __inline void +bus_space_copy_4(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + int *s = (int *)(h1 + o1); + int *d = (int *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + +static __inline void +bus_space_copy_8(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + int64_t *s = (int64_t *)(h1 + o1); + int64_t *d = (int64_t *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + +int generic_space_map(bus_space_tag_t, bus_addr_t, bus_size_t, int, + bus_space_handle_t *); +void generic_space_unmap(bus_space_tag_t, bus_space_handle_t, bus_size_t); +int generic_space_region(bus_space_tag_t, bus_space_handle_t, bus_size_t, + bus_size_t, bus_space_handle_t *); +void *generic_space_vaddr(bus_space_tag_t, bus_space_handle_t); +uint8_t generic_space_read_1(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint16_t generic_space_read_2(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint32_t generic_space_read_4(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint64_t generic_space_read_8(bus_space_tag_t, bus_space_handle_t, bus_size_t); +void generic_space_read_raw_2(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_1(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint8_t); +void generic_space_write_2(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint16_t); +void generic_space_write_4(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint32_t); +void generic_space_write_8(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint64_t); +void generic_space_write_raw_2(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); +void generic_space_read_raw_4(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_raw_4(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); +void generic_space_read_raw_8(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_raw_8(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); +paddr_t generic_space_mmap(bus_space_tag_t, bus_addr_t, off_t, int, int); + +/*----------------------------------------------------------------------------*/ +/* + * Bus read/write barrier methods. + * + * void bus_space_barrier(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * bus_size_t len, int flags); + * + */ +static inline void +bus_space_barrier(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, + bus_size_t length, int flags) +{ + __asm__ volatile ("sync" ::: "memory"); +} +#define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */ +#define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */ + +#define BUS_DMA_WAITOK 0x0000 +#define BUS_DMA_NOWAIT 0x0001 +#define BUS_DMA_ALLOCNOW 0x0002 +#define BUS_DMA_COHERENT 0x0008 +#define BUS_DMA_BUS1 0x0010 /* placeholders for bus functions... */ +#define BUS_DMA_BUS2 0x0020 +#define BUS_DMA_BUS3 0x0040 +#define BUS_DMA_BUS4 0x0080 +#define BUS_DMA_READ 0x0100 /* mapping is device -> memory only */ +#define BUS_DMA_WRITE 0x0200 /* mapping is memory -> device only */ +#define BUS_DMA_STREAMING 0x0400 /* hint: sequential, unidirectional */ +#define BUS_DMA_ZERO 0x0800 /* zero memory in dmamem_alloc */ +#define BUS_DMA_NOCACHE 0x1000 +#define BUS_DMA_64BIT 0x2000 /* device handles 64bit dva */ + +/* Forwards needed by prototypes below. */ +struct mbuf; +struct proc; +struct uio; + +#define BUS_DMASYNC_POSTREAD 0x0001 +#define BUS_DMASYNC_POSTWRITE 0x0002 +#define BUS_DMASYNC_PREREAD 0x0004 +#define BUS_DMASYNC_PREWRITE 0x0008 + +typedef struct machine_bus_dma_tag *bus_dma_tag_t; +typedef struct machine_bus_dmamap *bus_dmamap_t; + +/* + * bus_dma_segment_t + * + * Describes a single contiguous DMA transaction. Values + * are suitable for programming into DMA registers. + */ +struct machine_bus_dma_segment { + bus_addr_t ds_addr; /* DMA address */ + bus_size_t ds_len; /* length of transfer */ + + paddr_t _ds_paddr; /* CPU address */ + vaddr_t _ds_vaddr; /* CPU address */ +}; +typedef struct machine_bus_dma_segment bus_dma_segment_t; + +/* + * bus_dma_tag_t + * + * A machine-dependent opaque type describing the implementation of + * DMA for a given bus. + */ + +struct machine_bus_dma_tag { + void *_cookie; /* cookie used in the guts */ + + /* + * DMA mapping methods. + */ + int (*_dmamap_create)(bus_dma_tag_t , bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); + void (*_dmamap_destroy)(bus_dma_tag_t , bus_dmamap_t); + int (*_dmamap_load)(bus_dma_tag_t , bus_dmamap_t, void *, + bus_size_t, struct proc *, int); + int (*_dmamap_load_mbuf)(bus_dma_tag_t , bus_dmamap_t, + struct mbuf *, int); + int (*_dmamap_load_uio)(bus_dma_tag_t , bus_dmamap_t, + struct uio *, int); + int (*_dmamap_load_raw)(bus_dma_tag_t , bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); + int (*_dmamap_load_buffer)(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int, paddr_t *, int *, int); + void (*_dmamap_unload)(bus_dma_tag_t , bus_dmamap_t); + void (*_dmamap_sync)(bus_dma_tag_t , bus_dmamap_t, + bus_addr_t, bus_size_t, int); + + /* + * DMA memory utility functions. + */ + int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); + void (*_dmamem_free)(bus_dma_tag_t, bus_dma_segment_t *, int); + int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); + void (*_dmamem_unmap)(bus_dma_tag_t, caddr_t, size_t); + paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *, + int, off_t, int, int); + + /* + * internal memory address translation information. + */ + bus_addr_t (*_pa_to_device)(paddr_t); + paddr_t (*_device_to_pa)(bus_addr_t); + bus_addr_t _dma_mask; +}; + +#define bus_dmamap_create(t, s, n, m, b, f, p) \ + (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p)) +#define bus_dmamap_destroy(t, p) \ + (*(t)->_dmamap_destroy)((t), (p)) +#define bus_dmamap_load(t, m, b, s, p, f) \ + (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f)) +#define bus_dmamap_load_mbuf(t, m, b, f) \ + (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f)) +#define bus_dmamap_load_uio(t, m, u, f) \ + (*(t)->_dmamap_load_uio)((t), (m), (u), (f)) +#define bus_dmamap_load_raw(t, m, sg, n, s, f) \ + (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f)) +#define bus_dmamap_unload(t, p) \ + (*(t)->_dmamap_unload)((t), (p)) +#define bus_dmamap_sync(t, p, a, l, o) \ + (void)((t)->_dmamap_sync ? \ + (*(t)->_dmamap_sync)((t), (p), (a), (l), (o)) : (void)0) + +#define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \ + (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f)) +#define bus_dmamem_free(t, sg, n) \ + (*(t)->_dmamem_free)((t), (sg), (n)) +#define bus_dmamem_map(t, sg, n, s, k, f) \ + (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f)) +#define bus_dmamem_unmap(t, k, s) \ + (*(t)->_dmamem_unmap)((t), (k), (s)) +#define bus_dmamem_mmap(t, sg, n, o, p, f) \ + (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f)) + +int _dmamap_create(bus_dma_tag_t, bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); +void _dmamap_destroy(bus_dma_tag_t, bus_dmamap_t); +int _dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int); +int _dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, struct mbuf *, int); +int _dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, struct uio *, int); +int _dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); +int _dmamap_load_buffer(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int, paddr_t *, int *, int); +void _dmamap_unload(bus_dma_tag_t, bus_dmamap_t); +void _dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, + bus_size_t, int); + +int _dmamem_alloc(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); +void _dmamem_free(bus_dma_tag_t, bus_dma_segment_t *, int); +int _dmamem_map(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); +void _dmamem_unmap(bus_dma_tag_t, caddr_t, size_t); +paddr_t _dmamem_mmap(bus_dma_tag_t, bus_dma_segment_t *, int, off_t, int, int); +int _dmamem_alloc_range(bus_dma_tag_t, bus_size_t, bus_size_t, bus_size_t, + bus_dma_segment_t *, int, int *, int, paddr_t, paddr_t); + +/* + * bus_dmamap_t + * + * Describes a DMA mapping. + */ +struct machine_bus_dmamap { + /* + * PRIVATE MEMBERS: not for use by machine-independent code. + */ + bus_size_t _dm_size; /* largest DMA transfer mappable */ + int _dm_segcnt; /* number of segs this map can map */ + bus_size_t _dm_maxsegsz; /* largest possible segment */ + bus_size_t _dm_boundary; /* don't cross this */ + int _dm_flags; /* misc. flags */ + + void *_dm_cookie; /* cookie for bus-specific functions */ + + /* + * PUBLIC MEMBERS: these are used by machine-independent code. + */ + bus_size_t dm_mapsize; /* size of the mapping */ + int dm_nsegs; /* # valid segments in mapping */ + bus_dma_segment_t dm_segs[1]; /* segments; variable length */ +}; + +#endif /* _MACHINE_BUS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/conf.h b/lib/libc/include/mips64el-openbsd-none/machine/conf.h new file mode 100644 index 0000000000..8eafed12d4 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/conf.h @@ -0,0 +1,42 @@ +/* $OpenBSD: conf.h,v 1.4 2022/06/28 14:43:50 visa Exp $ */ +/* $NetBSD: conf.h,v 1.2 1996/05/05 19:28:34 christos Exp $ */ + +/* + * Copyright (c) 1996 Christos Zoulas. 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 Christos Zoulas. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +/* open, close, write, ioctl, kqueue */ +#define cdev_apm_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,n,kqfilter) } + +cdev_decl(apm); \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/cpu.h b/lib/libc/include/mips64el-openbsd-none/machine/cpu.h new file mode 100644 index 0000000000..d3d84bf3db --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/cpu.h @@ -0,0 +1,103 @@ +/* $OpenBSD: cpu.h,v 1.8 2017/07/30 16:05:24 visa 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 and Rick Macklem. + * + * 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. + * + * Copyright (C) 1989 Digital Equipment Corporation. + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby granted, + * provided that the above copyright notice appears in all copies. + * Digital Equipment Corporation makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * from: @(#)cpu.h 8.4 (Berkeley) 1/4/94 + */ + +#ifdef _KERNEL + +#if defined(MULTIPROCESSOR) && !defined(_LOCORE) +#define MAXCPUS 4 +struct cpu_info; +struct cpu_info *hw_getcurcpu(void); +void hw_setcurcpu(struct cpu_info *); +void hw_cpu_boot_secondary(struct cpu_info *); +void hw_cpu_hatch(struct cpu_info *); +void hw_cpu_spinup_trampoline(struct cpu_info *); +int hw_ipi_intr_establish(int (*)(void *), u_long); +void hw_ipi_intr_set(u_long); +void hw_ipi_intr_clear(u_long); +#endif /* MULTIPROCESSOR && !_LOCORE */ + +#if defined(CPU_LOONGSON2) && !defined(CPU_LOONGSON3) +#define Mips_SyncCache(ci) \ + Loongson2_SyncCache((ci)) +#define Mips_InvalidateICache(ci, va, l) \ + Loongson2_InvalidateICache((ci), (va), (l)) +#define Mips_InvalidateICachePage(ci, va) \ + Loongson2_InvalidateICachePage((ci), (va)) +#define Mips_SyncICache(ci) \ + Loongson2_SyncICache((ci)) +#define Mips_SyncDCachePage(ci, va, pa) \ + Loongson2_SyncDCachePage((ci), (va), (pa)) +#define Mips_HitSyncDCachePage(ci, va, pa) \ + Loongson2_SyncDCachePage((ci), (va), (pa)) +#define Mips_HitSyncDCache(ci, va, l) \ + Loongson2_HitSyncDCache((ci), (va), (l)) +#define Mips_IOSyncDCache(ci, va, l, h) \ + Loongson2_IOSyncDCache((ci), (va), (l), (h)) +#define Mips_HitInvalidateDCache(ci, va, l) \ + Loongson2_HitInvalidateDCache((ci), (va), (l)) +#endif + +#if defined(CPU_LOONGSON3) && !defined(CPU_LOONGSON2) +#define Mips_SyncCache(ci) \ + Loongson3_SyncCache((ci)) +#define Mips_InvalidateICache(ci, va, l) \ + Loongson3_InvalidateICache((ci), (va), (l)) +#define Mips_InvalidateICachePage(ci, va) \ + Loongson3_InvalidateICachePage((ci), (va)) +#define Mips_SyncICache(ci) \ + Loongson3_SyncICache((ci)) +#define Mips_SyncDCachePage(ci, va, pa) \ + Loongson3_SyncDCachePage((ci), (va), (pa)) +#define Mips_HitSyncDCachePage(ci, va, pa) \ + Loongson3_SyncDCachePage((ci), (va), (pa)) +#define Mips_HitSyncDCache(ci, va, l) \ + Loongson3_HitSyncDCache((ci), (va), (l)) +#define Mips_IOSyncDCache(ci, va, l, h) \ + Loongson3_IOSyncDCache((ci), (va), (l), (h)) +#define Mips_HitInvalidateDCache(ci, va, l) \ + Loongson3_HitInvalidateDCache((ci), (va), (l)) +#endif + +#endif /* _KERNEL */ + +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/cpustate.h b/lib/libc/include/mips64el-openbsd-none/machine/cpustate.h new file mode 100644 index 0000000000..f5aff1a41b --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/cpustate.h @@ -0,0 +1,3 @@ +/* $OpenBSD: cpustate.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/db_machdep.h b/lib/libc/include/mips64el-openbsd-none/machine/db_machdep.h new file mode 100644 index 0000000000..3759d83371 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/db_machdep.h @@ -0,0 +1,3 @@ +/* $OpenBSD: db_machdep.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/elf.h b/lib/libc/include/mips64el-openbsd-none/machine/elf.h new file mode 100644 index 0000000000..5918df727b --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/elf.h @@ -0,0 +1,3 @@ +/* $OpenBSD: elf.h,v 1.1 2024/07/14 19:33:59 miod Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/endian.h b/lib/libc/include/mips64el-openbsd-none/machine/endian.h new file mode 100644 index 0000000000..2e7392a082 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/endian.h @@ -0,0 +1,3 @@ +/* $OpenBSD: endian.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/exec.h b/lib/libc/include/mips64el-openbsd-none/machine/exec.h new file mode 100644 index 0000000000..53433783f0 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/exec.h @@ -0,0 +1,3 @@ +/* $OpenBSD: exec.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/fpu.h b/lib/libc/include/mips64el-openbsd-none/machine/fpu.h new file mode 100644 index 0000000000..19ee8af414 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/fpu.h @@ -0,0 +1,3 @@ +/* $OpenBSD: fpu.h,v 1.1 2010/09/17 00:34:04 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/frame.h b/lib/libc/include/mips64el-openbsd-none/machine/frame.h new file mode 100644 index 0000000000..d14827e33c --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/frame.h @@ -0,0 +1,3 @@ +/* $OpenBSD: frame.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/hibernate.h b/lib/libc/include/mips64el-openbsd-none/machine/hibernate.h new file mode 100644 index 0000000000..f0a99c6df6 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/hibernate.h @@ -0,0 +1,33 @@ +/* $OpenBSD: hibernate.h,v 1.3 2018/06/21 07:33:30 mlarkin Exp $ */ + +/* + * Copyright (c) 2013 Paul Irofti. + * + * 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 + +/* Loongson hibernate support structures and functions */ + +int get_hibernate_info_md(union hibernate_info *); +void hibernate_flush(void); +void hibernate_enter_resume_mapping(vaddr_t, paddr_t, int); +int hibernate_inflate_skip(union hibernate_info *, paddr_t); +int hibernate_suspend(void); +void hibernate_switch_stack_machdep(void); +void hibernate_resume_machdep(vaddr_t); +void hibernate_activate_resume_pt_machdep(void); +void hibernate_enable_intr_machdep(void); +void hibernate_disable_intr_machdep(void); \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/hibernate_var.h b/lib/libc/include/mips64el-openbsd-none/machine/hibernate_var.h new file mode 100644 index 0000000000..de84657a4b --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/hibernate_var.h @@ -0,0 +1,39 @@ +/* $OpenBSD: hibernate_var.h,v 1.1 2013/06/02 21:46:04 pirofti Exp $ */ + +/* + * Copyright (c) 2013 Paul Irofti. + * + * 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. + */ + +/* Loongson hibernate support definitions */ + +#define PAGE_MASK_4M ((256 * PAGE_SIZE) - 1) + +#define PIGLET_PAGE_MASK ~((paddr_t)PAGE_MASK_4M) + +/* + * Steal hibernate pages right after the first page which is reserved + * for the exception area. + * */ +#define HIBERNATE_STACK_PAGE (PAGE_SIZE * 1) +#define HIBERNATE_INFLATE_PAGE (PAGE_SIZE * 2) +#define HIBERNATE_COPY_PAGE (PAGE_SIZE * 3) +#define HIBERNATE_HIBALLOC_PAGE (PAGE_SIZE * 4) + +#define HIBERNATE_RESERVED_PAGES 4 + +/* Use 4MB hibernation chunks */ +#define HIBERNATE_CHUNK_SIZE 0x400000 + +#define HIBERNATE_CHUNK_TABLE_SIZE 0x100000 \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/ieee.h b/lib/libc/include/mips64el-openbsd-none/machine/ieee.h new file mode 100644 index 0000000000..d390acb3c5 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/ieee.h @@ -0,0 +1,3 @@ +/* $OpenBSD: ieee.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/ieeefp.h b/lib/libc/include/mips64el-openbsd-none/machine/ieeefp.h new file mode 100644 index 0000000000..17e880358e --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/ieeefp.h @@ -0,0 +1,3 @@ +/* $OpenBSD: ieeefp.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/intr.h b/lib/libc/include/mips64el-openbsd-none/machine/intr.h new file mode 100644 index 0000000000..64d103bc39 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/intr.h @@ -0,0 +1,193 @@ +/* $OpenBSD: intr.h,v 1.19 2025/05/10 10:01:03 visa Exp $ */ + +/* + * Copyright (c) 2001-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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_INTR_H_ +#define _MACHINE_INTR_H_ + +#define __USE_MI_SOFTINTR + +#include + +/* + * The interrupt level ipl is a logical level; per-platform interrupt + * code will turn it into the appropriate hardware interrupt masks + * values. + * + * Interrupt sources on the CPU are kept enabled regardless of the + * current ipl value; individual hardware sources interrupting while + * logically masked are masked on the fly, remembered as pending, and + * unmasked at the first splx() opportunity. + * + * An exception to this rule is the clock interrupt. Clock interrupts + * are always allowed to happen, but will (of course!) not be serviced + * if logically masked. The reason for this is that clocks usually sit on + * INT5 and cannot be easily masked if external hardware masking is used. + */ + +/* Interrupt priority `levels'; not mutually exclusive. */ +#define IPL_NONE 0 /* nothing */ +#define IPL_SOFTINT 1 /* soft interrupts */ +#define IPL_SOFTCLOCK 1 /* soft clock interrupts */ +#define IPL_SOFTNET 2 /* soft network interrupts */ +#define IPL_SOFTTTY 3 /* soft terminal interrupts */ +#define IPL_SOFTHIGH IPL_SOFTTTY /* highest level of soft interrupts */ +#define IPL_BIO 4 /* block I/O */ +#define IPL_AUDIO IPL_BIO +#define IPL_NET 5 /* network */ +#define IPL_TTY 6 /* terminal */ +#define IPL_VM 7 /* memory allocation */ +#define IPL_CLOCK 8 /* clock */ +#define IPL_STATCLOCK IPL_CLOCK +#define IPL_SCHED 9 /* everything */ +#define IPL_HIGH 9 /* everything */ +#define IPL_IPI 10 /* interprocessor interrupt */ +#define NIPLS 11 /* number of levels */ + +#define IPL_MPFLOOR IPL_TTY + +/* Interrupt priority 'flags'. */ +#define IPL_MPSAFE 0x100 + +/* Interrupt sharing types. */ +#define IST_NONE 0 /* none */ +#define IST_PULSE 1 /* pulsed */ +#define IST_EDGE 2 /* edge-triggered */ +#define IST_LEVEL 3 /* level-triggered */ + +#ifndef _LOCORE + +void softintr(int); + +#define splbio() splraise(IPL_BIO) +#define splnet() splraise(IPL_NET) +#define spltty() splraise(IPL_TTY) +#define splaudio() splraise(IPL_AUDIO) +#define splclock() splraise(IPL_CLOCK) +#define splvm() splraise(IPL_VM) +#define splhigh() splraise(IPL_HIGH) + +#define splsoftclock() splraise(IPL_SOFTCLOCK) +#define splsoftnet() splraise(IPL_SOFTNET) +#define splstatclock() splhigh() + +#define splsched() splhigh() +#define spl0() spllower(0) + +void splinit(void); + +#ifdef DIAGNOSTIC +/* + * Although this function is implemented in MI code, it must be in this MD + * header because we don't want this header to include MI includes. + */ +void splassert_fail(int, int, const char *); +extern int splassert_ctl; +void splassert_check(int, const char *); +#define splassert(__wantipl) do { \ + if (splassert_ctl > 0) { \ + splassert_check(__wantipl, __func__); \ + } \ +} while (0) +#define splsoftassert(wantipl) splassert(wantipl) +#else +#define splassert(X) +#define splsoftassert(X) +#endif + +void register_splx_handler(void (*)(int)); +int splraise(int); +void splx(int); +int spllower(int); + +/* + * Interrupt control struct used by interrupt dispatchers + * to hold interrupt handler info. + */ + +#include + +struct intrhand { + struct intrhand *ih_next; + int (*ih_fun)(void *); + void *ih_arg; + int ih_level; + int ih_irq; + int ih_flags; +#define IH_MPSAFE 0x01 + struct evcount ih_count; +}; + +void intr_barrier(void *); + +/* + * Low level interrupt dispatcher registration data. + */ + +/* Schedule priorities for base interrupts (CPU) */ +#define INTPRI_IPI 0 +#define INTPRI_CLOCK 1 +/* other values are system-specific */ + +#define NLOWINT 4 /* Number of low level registrations possible */ + +extern uint32_t idle_mask; + +struct trapframe; +void set_intr(int, uint32_t, uint32_t(*)(uint32_t, struct trapframe *)); + +uint32_t updateimask(uint32_t); +void dosoftint(void); + +#ifdef MULTIPROCESSOR +extern uint32_t ipi_mask; +#define ENABLEIPI() updateimask(~ipi_mask) +#endif + +struct pic { + void (*pic_eoi)(int); + void (*pic_mask)(int); + void (*pic_unmask)(int); +}; + +#ifdef CPU_LOONGSON3 + +void loongson3_intr_init(void); +void *loongson3_intr_establish(int, int, int (*)(void *), void*, + const char *); +void loongson3_intr_disestablish(void *); +void *loongson3_ht_intr_establish(int, int, int (*)(void *), void*, + const char *); +void loongson3_ht_intr_disestablish(void *); + +void loongson3_register_ht_pic(const struct pic *); + +#endif /* CPU_LOONGSON3 */ + +#endif /* _LOCORE */ + +#endif /* _MACHINE_INTR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/isa_machdep.h b/lib/libc/include/mips64el-openbsd-none/machine/isa_machdep.h new file mode 100644 index 0000000000..201c218bd3 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/isa_machdep.h @@ -0,0 +1,51 @@ +/* $OpenBSD: isa_machdep.h,v 1.2 2010/05/08 21:59:56 miod Exp $ */ + +/* + * Copyright (c) 2007 Miodrag Vallat. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice, this permission notice, and the disclaimer below + * 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_ISA_MACHDEP_H_ +#define _MACHINE_ISA_MACHDEP_H_ + +#include + +#define __NO_ISA_INTR_CHECK + +typedef struct mips_isa_chipset *isa_chipset_tag_t; + +struct mips_isa_chipset { + void *ic_v; + + void (*ic_attach_hook)(struct device *, struct device *, + struct isabus_attach_args *); + void *(*ic_intr_establish)(void *, int, int, int, int (*)(void *), + void *, char *); + void (*ic_intr_disestablish)(void *, void *); +}; + +#define isa_attach_hook(p, s, iba) \ + (*(iba)->iba_ic->ic_attach_hook)((p), (s), (iba)) +#define isa_intr_establish(c, i, t, l, f, a, n) \ + (*(c)->ic_intr_establish)((c)->ic_v, (i), (t), (l), (f), (a), (n)) +#define isa_intr_disestablish(c, h) \ + (*(c)->ic_intr_disestablish)((c)->ic_v, (h)) + +void loongson_generic_isa_attach_hook(struct device *, struct device *, + struct isabus_attach_args *); +void loongson_isa_specific_eoi(int); +void loongson_set_isa_imr(uint); + +#endif \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/kcore.h b/lib/libc/include/mips64el-openbsd-none/machine/kcore.h new file mode 100644 index 0000000000..c38fa9f7f6 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/kcore.h @@ -0,0 +1,3 @@ +/* $OpenBSD: kcore.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/limits.h b/lib/libc/include/mips64el-openbsd-none/machine/limits.h new file mode 100644 index 0000000000..12007d997a --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/limits.h @@ -0,0 +1,3 @@ +/* $OpenBSD: limits.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/loongson2.h b/lib/libc/include/mips64el-openbsd-none/machine/loongson2.h new file mode 100644 index 0000000000..05688a8e0f --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/loongson2.h @@ -0,0 +1,3 @@ +/* $OpenBSD: loongson2.h,v 1.1.1.1 2009/08/06 20:51:44 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/loongson3.h b/lib/libc/include/mips64el-openbsd-none/machine/loongson3.h new file mode 100644 index 0000000000..bcbe6ca701 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/loongson3.h @@ -0,0 +1,3 @@ +/* $OpenBSD: loongson3.h,v 1.1 2016/11/06 10:20:33 visa Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/memconf.h b/lib/libc/include/mips64el-openbsd-none/machine/memconf.h new file mode 100644 index 0000000000..c7782048ac --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/memconf.h @@ -0,0 +1,3 @@ +/* $OpenBSD: memconf.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/mips_opcode.h b/lib/libc/include/mips64el-openbsd-none/machine/mips_opcode.h new file mode 100644 index 0000000000..5b5cbc3494 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/mips_opcode.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mips_opcode.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/mplock.h b/lib/libc/include/mips64el-openbsd-none/machine/mplock.h new file mode 100644 index 0000000000..dc963887f8 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/mplock.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mplock.h,v 1.1 2017/01/19 14:51:02 visa Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/mutex.h b/lib/libc/include/mips64el-openbsd-none/machine/mutex.h new file mode 100644 index 0000000000..8003e465f6 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/mutex.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mutex.h,v 1.2 2015/07/08 13:37:31 dlg Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/param.h b/lib/libc/include/mips64el-openbsd-none/machine/param.h new file mode 100644 index 0000000000..cd410bd602 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/param.h @@ -0,0 +1,31 @@ +/* $OpenBSD: param.h,v 1.3 2013/03/23 16:12:23 deraadt Exp $ */ + +/* Public Domain */ + +#ifndef _MACHINE_PARAM_H_ +#define _MACHINE_PARAM_H_ + +#define MACHINE "loongson" +#define _MACHINE loongson +#define MACHINE_ARCH "mips64el" /* not the canonical endianness */ +#define _MACHINE_ARCH mips64el +#define MACHINE_CPU "mips64" +#define _MACHINE_CPU mips64 +#define MID_MACHINE MID_MIPS64 + +#ifdef _KERNEL + +/* + * The Loongson level 1 cache expects software to prevent virtual + * aliases. Unfortunately, since this cache is physically tagged, + * this would require all virtual address to have the same bits 14 + * and 13 as their physical addresses, which is not something the + * kernel can guarantee unless the page size is at least 16KB. + */ +#define PAGE_SHIFT 14 + +#endif /* _KERNEL */ + +#include + +#endif /* _MACHINE_PARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/pcb.h b/lib/libc/include/mips64el-openbsd-none/machine/pcb.h new file mode 100644 index 0000000000..e48bfc2f31 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/pcb.h @@ -0,0 +1,3 @@ +/* $OpenBSD: pcb.h,v 1.1.1.1 2009/07/31 09:26:25 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/pci_machdep.h b/lib/libc/include/mips64el-openbsd-none/machine/pci_machdep.h new file mode 100644 index 0000000000..ade283806c --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/pci_machdep.h @@ -0,0 +1,101 @@ +/* $OpenBSD: pci_machdep.h,v 1.10 2016/05/04 14:30:01 kettenis Exp $ */ + +/* + * Copyright (c) 2003-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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. + * + */ + +typedef struct mips_pci_chipset *pci_chipset_tag_t; +typedef u_long pcitag_t; +typedef u_long pci_intr_handle_t; + +struct pci_attach_args; + +/* + * mips-specific PCI structure and type definitions. + * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE. + */ +struct mips_pci_chipset { + void *pc_conf_v; + void (*pc_attach_hook)(struct device *, + struct device *, struct pcibus_attach_args *); + int (*pc_bus_maxdevs)(void *, int); + pcitag_t (*pc_make_tag)(void *, int, int, int); + void (*pc_decompose_tag)(void *, pcitag_t, int *, + int *, int *); + int (*pc_conf_size)(void *, pcitag_t); + pcireg_t (*pc_conf_read)(void *, pcitag_t, int); + void (*pc_conf_write)(void *, pcitag_t, int, pcireg_t); + + void *pc_intr_v; + int (*pc_intr_map)(struct pci_attach_args *, pci_intr_handle_t *); + const char *(*pc_intr_string)(void *, pci_intr_handle_t); + void *(*pc_intr_establish)(void *, pci_intr_handle_t, + int, int (*)(void *), void *, char *); + void (*pc_intr_disestablish)(void *, void *); +}; + +/* + * Functions provided to machine-independent PCI code. + */ +#define pci_attach_hook(p, s, pba) \ + (*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba)) +#define pci_bus_maxdevs(c, b) \ + (*(c)->pc_bus_maxdevs)((c)->pc_conf_v, (b)) +#define pci_make_tag(c, b, d, f) \ + (*(c)->pc_make_tag)((c)->pc_conf_v, (b), (d), (f)) +#define pci_decompose_tag(c, t, bp, dp, fp) \ + (*(c)->pc_decompose_tag)((c)->pc_conf_v, (t), (bp), (dp), (fp)) +#define pci_conf_size(c, t) \ + (*(c)->pc_conf_size)((c)->pc_conf_v, (t)) +#define pci_conf_read(c, t, r) \ + (*(c)->pc_conf_read)((c)->pc_conf_v, (t), (r)) +#define pci_conf_write(c, t, r, v) \ + (*(c)->pc_conf_write)((c)->pc_conf_v, (t), (r), (v)) +#define pci_intr_map(c, ihp) \ + (*(c)->pa_pc->pc_intr_map)((c), (ihp)) +#define pci_intr_map_msi(c, ihp) (-1) +#define pci_intr_map_msix(c, vec, ihp) (-1) +#define pci_intr_string(c, ih) \ + (*(c)->pc_intr_string)((c)->pc_intr_v, (ih)) +#define pci_intr_establish(c, ih, l, h, a, nm) \ + (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), (h), (a), (nm)) +#define pci_intr_disestablish(c, iv) \ + (*(c)->pc_intr_disestablish)((c)->pc_intr_v, (iv)) +#define pci_probe_device_hook(c, a) (0) + +#define pci_min_powerstate(c, t) (PCI_PMCSR_STATE_D3) +#define pci_set_powerstate_md(c, t, s, p) + +/* PCI view of CPU memory */ +extern paddr_t loongson_dma_base; + +/* + * Functions used during early system configuration. + */ + +extern pcitag_t (*pci_make_tag_early)(int, int, int); +extern pcireg_t (*pci_conf_read_early)(pcitag_t, int); + +#define pci_dev_postattach(a, b) \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/pmap.h b/lib/libc/include/mips64el-openbsd-none/machine/pmap.h new file mode 100644 index 0000000000..eda0b11a3c --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/pmap.h @@ -0,0 +1,3 @@ +/* $OpenBSD: pmap.h,v 1.1.1.1 2009/07/31 09:26:26 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/pmon.h b/lib/libc/include/mips64el-openbsd-none/machine/pmon.h new file mode 100644 index 0000000000..7729adb468 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/pmon.h @@ -0,0 +1,209 @@ +/* $OpenBSD: pmon.h,v 1.5 2017/05/21 13:00:53 visa Exp $ */ + +/* + * Copyright (c) 2009, 2012 Miodrag Vallat. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_PMON_H_ +#define _MACHINE_PMON_H_ + +#if defined(_KERNEL) || defined(_STANDALONE) + +/* + * PMON2000 callvec definitions + */ + +/* 32-bit compatible types */ +typedef uint32_t pmon_size_t; +typedef int32_t pmon_ssize_t; +typedef int64_t pmon_off_t; + +int pmon_open(const char *, int, ...); +int pmon_close(int); +int pmon_read(int, void *, pmon_size_t); +pmon_ssize_t pmon_write(int, const void *, pmon_size_t); +pmon_off_t pmon_lseek(int, pmon_off_t, int); +int pmon_printf(const char *, ...); +void pmon_cacheflush(void); +char * pmon_gets(char *); + +#define PMON_MAXLN 256 /* internal gets() size limit */ + +extern int32_t pmon_callvec; + +const char *pmon_getarg(const int); +void pmon_init(int32_t, int32_t, int32_t, int32_t, uint32_t); + +#define PMON_ENVTYPE_ENVP 0 +#define PMON_ENVTYPE_EFI 1 +int pmon_getenvtype(void); + +/* + * The new environment interface is a /salmigondis/ of badly thought-out + * structs put together, pretending to be inspired by EFI but conveniently + * omitting key EFI structs because they are deemed non-applicable to + * MIPS systems. + * Of course, some fields are absolute addresses, while others are relative + * pointers, to add to the confusion. + */ + +struct pmon_env_reset { + void (*cold_boot)(void); /* not filled */ + void (*warm_boot)(void); + void (*boot)(unsigned int); /* not filled */ + void (*poweroff)(void); +}; + +/* all values are offsets relative to the beginning of the struct */ +struct pmon_env_ptr { + uint64_t offs_mem; + uint64_t offs_cpu; + uint64_t offs_sys; + uint64_t offs_irq; + uint64_t offs_iface; + uint64_t offs_special; + uint64_t offs_device; +}; + +struct pmon_env_smbios { + uint16_t version; + uint64_t vga_bios; + struct pmon_env_ptr ptrs; +}; + +struct pmon_env_efi { + uint64_t mps; /* not filled */ + uint64_t acpi; /* not filled */ + uint64_t acpi20; /* not filled */ + struct pmon_env_smbios bios; + uint64_t sal_systab; /* not filled */ + uint64_t bootinfo; /* not filled */ +}; + +struct pmon_env { + struct pmon_env_efi efi; + struct pmon_env_reset reset; +}; + +#define PMON_MEM_MAX 128 +struct pmon_env_mem_entry { + uint32_t node; + uint32_t type; +#define PMON_MEM_SYSTEM_LOW 1 /* physical memory <= 256 MB */ +#define PMON_MEM_SYSTEM_HIGH 2 /* physical memory > 256 MB */ +#define PMON_MEM_RESERVED 3 +#define PMON_MEM_PCI_IO 4 +#define PMON_MEM_PCI_MEM 5 +#define PMON_MEM_CPU_REGISTERS 6 +#define PMON_MEM_VIDEO_ROM 7 +#define PMON_MEM_OTHER_ROM 8 +#define PMON_MEM_ACPI_TABLE 9 + uint64_t address; + uint32_t size; +}; +struct pmon_env_mem { + uint16_t version; /* not filled */ + uint32_t nentries; + uint32_t mem_freq; + struct pmon_env_mem_entry mem_map[PMON_MEM_MAX]; +} __packed; + +struct pmon_env_cpu { + uint16_t version; /* not filled */ + uint32_t prid; /* cop0 PrID */ + uint32_t cputype; +/* 0 and 1 are supposedly intended for 2E and 2F, which do NOT provide this + interface; moreover Linux and PMON disagree on the values and have 2E and + 2F swapped. */ +#define PMON_CPUTYPE_LS3A 2 +#define PMON_CPUTYPE_LS3B 3 +#define PMON_CPUTYPE_LS1A 4 +#define PMON_CPUTYPE_LS1B 5 + uint32_t node; /* total number of NUMA nodes */ + uint16_t coreid; /* boot CPU core id */ + uint16_t reserved_cores; /* mask of reserved cores */ + uint32_t speed; + uint32_t ncpus; +} __packed; + +struct pmon_env_sys { + uint16_t version; /* not filled */ + uint32_t ccnuma_smp; + uint32_t double_channel; +} __packed; + +struct pmon_env_irq { + uint16_t version; /* not filled */ + uint16_t size; /* not filled */ + uint16_t rtr_bus; /* not filled */ + uint16_t rtr_devfn; /* not filled */ + uint32_t vendor; /* not filled */ + uint32_t device; /* not filled */ + uint32_t pic_type; +#define PMON_IRQ_PIC_HT 0 +#define PMON_IRQ_PIC_I8259 1 + uint64_t ht_interrupt_bit; + uint64_t ht_enable; + uint32_t node; + uint64_t pci_memory_space_start; + uint64_t pci_memory_space_end; + uint64_t pci_io_space_start; /* not filled */ + uint64_t pci_io_space_end; /* not filled */ + uint64_t pci_cfg_space; /* not filled */ +} __packed; + +struct pmon_env_iface { + uint16_t version; +#define PMON_IFACE_VERSION 0x0001 + uint16_t size; + uint8_t flag; + char description[64]; /* firmware version */ +} __packed; + +#define PMON_RESOURCE_MAX 128 +struct pmon_env_resource { + uint64_t start; + uint64_t end; + char name[64]; + uint32_t flags; +}; +struct pmon_env_special { + uint16_t version; + char name[64]; + uint32_t type; + struct pmon_env_resource resource[PMON_RESOURCE_MAX]; +}; + +struct pmon_env_device { + char name[64]; /* system description */ + uint32_t nentries; + struct pmon_env_resource resource[PMON_RESOURCE_MAX]; +}; + +const char *pmon_getenv(const char *); + +const struct pmon_env_reset *pmon_get_env_reset(void); +const struct pmon_env_smbios *pmon_get_env_smbios(void); +const struct pmon_env_mem *pmon_get_env_mem(void); +const struct pmon_env_cpu *pmon_get_env_cpu(void); +const struct pmon_env_sys *pmon_get_env_sys(void); +const struct pmon_env_irq *pmon_get_env_irq(void); +const struct pmon_env_iface *pmon_get_env_iface(void); +const struct pmon_env_special *pmon_get_env_special(void); +const struct pmon_env_device *pmon_get_env_device(void); + +#endif /* _KERNEL || _STANDALONE */ + +#endif /* _MACHINE_PMON_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/proc.h b/lib/libc/include/mips64el-openbsd-none/machine/proc.h new file mode 100644 index 0000000000..27b68200cf --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/proc.h @@ -0,0 +1,3 @@ +/* $OpenBSD: proc.h,v 1.1.1.1 2009/07/31 09:26:26 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/profile.h b/lib/libc/include/mips64el-openbsd-none/machine/profile.h new file mode 100644 index 0000000000..d258d1147b --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/profile.h @@ -0,0 +1,3 @@ +/* $OpenBSD: profile.h,v 1.1.1.1 2009/07/31 09:26:26 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/pte.h b/lib/libc/include/mips64el-openbsd-none/machine/pte.h new file mode 100644 index 0000000000..24c761d664 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/pte.h @@ -0,0 +1,3 @@ +/* $OpenBSD: pte.h,v 1.1.1.1 2009/07/31 09:26:26 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/ptrace.h b/lib/libc/include/mips64el-openbsd-none/machine/ptrace.h new file mode 100644 index 0000000000..bd8e886725 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/ptrace.h @@ -0,0 +1,3 @@ +/* $OpenBSD: ptrace.h,v 1.1.1.1 2009/07/31 09:26:26 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/reg.h b/lib/libc/include/mips64el-openbsd-none/machine/reg.h new file mode 100644 index 0000000000..aeecc496fe --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/reg.h @@ -0,0 +1,3 @@ +/* $OpenBSD: reg.h,v 1.1.1.1 2009/07/31 09:26:26 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/regdef.h b/lib/libc/include/mips64el-openbsd-none/machine/regdef.h new file mode 100644 index 0000000000..03ae54124e --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/regdef.h @@ -0,0 +1,3 @@ +/* $OpenBSD: regdef.h,v 1.1.1.1 2009/07/31 09:26:26 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/regnum.h b/lib/libc/include/mips64el-openbsd-none/machine/regnum.h new file mode 100644 index 0000000000..e371c1ed20 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/regnum.h @@ -0,0 +1,3 @@ +/* $OpenBSD: regnum.h,v 1.1.1.1 2009/07/31 09:26:26 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/setjmp.h b/lib/libc/include/mips64el-openbsd-none/machine/setjmp.h new file mode 100644 index 0000000000..c834f0409a --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/setjmp.h @@ -0,0 +1,3 @@ +/* $OpenBSD: setjmp.h,v 1.1.1.1 2009/07/31 09:26:26 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/signal.h b/lib/libc/include/mips64el-openbsd-none/machine/signal.h new file mode 100644 index 0000000000..7f4d38dee7 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/signal.h @@ -0,0 +1,3 @@ +/* $OpenBSD: signal.h,v 1.1.1.1 2009/07/31 09:26:26 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/spinlock.h b/lib/libc/include/mips64el-openbsd-none/machine/spinlock.h new file mode 100644 index 0000000000..63f58612b8 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/spinlock.h @@ -0,0 +1,3 @@ +/* $OpenBSD: spinlock.h,v 1.1.1.1 2009/07/31 09:26:26 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/sysarch.h b/lib/libc/include/mips64el-openbsd-none/machine/sysarch.h new file mode 100644 index 0000000000..6dac08a77b --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/sysarch.h @@ -0,0 +1,3 @@ +/* $OpenBSD: sysarch.h,v 1.1.1.1 2009/11/22 18:12:44 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/timetc.h b/lib/libc/include/mips64el-openbsd-none/machine/timetc.h new file mode 100644 index 0000000000..d3d291c815 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/timetc.h @@ -0,0 +1,23 @@ +/* $OpenBSD: timetc.h,v 1.2 2020/07/18 08:37:43 visa Exp $ */ +/* + * Copyright (c) 2020 Paul Irofti + * + * 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_TIMETC_H_ +#define _MACHINE_TIMETC_H_ + +#include + +#endif /* _MACHINE_TIMETC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/trap.h b/lib/libc/include/mips64el-openbsd-none/machine/trap.h new file mode 100644 index 0000000000..c700eedba1 --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/trap.h @@ -0,0 +1,3 @@ +/* $OpenBSD: trap.h,v 1.1.1.1 2009/07/31 09:26:26 miod Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/mips64el-openbsd-none/machine/vmparam.h b/lib/libc/include/mips64el-openbsd-none/machine/vmparam.h new file mode 100644 index 0000000000..c6c4b75cfe --- /dev/null +++ b/lib/libc/include/mips64el-openbsd-none/machine/vmparam.h @@ -0,0 +1,11 @@ +/* $OpenBSD: vmparam.h,v 1.5 2017/05/21 13:00:53 visa Exp $ */ +/* public domain */ +#ifndef _MACHINE_VMPARAM_H_ +#define _MACHINE_VMPARAM_H_ + +#define VM_PHYSSEG_MAX 8 /* Max number of physical memory segments */ +#define VM_PHYSSEG_STRAT VM_PSTRAT_BIGFIRST + +#include + +#endif /* _MACHINE_VMPARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/frame.h b/lib/libc/include/powerpc-openbsd-eabihf/frame.h new file mode 100644 index 0000000000..9edae57f95 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/frame.h @@ -0,0 +1,3 @@ +/* $OpenBSD: frame.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/_float.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/_float.h new file mode 100644 index 0000000000..1bf34fd14e --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/_float.h @@ -0,0 +1,3 @@ +/* $OpenBSD: _float.h,v 1.1 2012/06/26 16:12:44 deraadt Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/_types.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/_types.h new file mode 100644 index 0000000000..e896392602 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/_types.h @@ -0,0 +1,4 @@ +/* $OpenBSD: _types.h,v 1.1 2006/01/06 18:50:09 millert Exp $ */ + +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/apmvar.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/apmvar.h new file mode 100644 index 0000000000..4aa7952d46 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/apmvar.h @@ -0,0 +1,122 @@ +/* $OpenBSD: apmvar.h,v 1.10 2019/01/22 02:36:30 phessler Exp $ */ + +/* + * Copyright (c) 2001 Alexander Guy + * Copyright (c) 1995 John T. Kohl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef _MACHINE_APMVAR_H_ +#define _MACHINE_APMVAR_H_ + +#include + +/* Advanced Power Management (v1.0 and v1.1 specification) + * functions/defines/etc. + */ + +/* These definitions make up the heart of the user-land interface + * to the APM devices. + */ + +#define APM_AC_OFF 0x00 +#define APM_AC_ON 0x01 +#define APM_AC_BACKUP 0x02 +#define APM_AC_UNKNOWN 0xff +#define APM_BATT_HIGH 0x00 +#define APM_BATT_LOW 0x01 +#define APM_BATT_CRITICAL 0x02 +#define APM_BATT_CHARGING 0x03 +#define APM_BATT_UNKNOWN 0xff +#define APM_BATT_LIFE_UNKNOWN 0xff + +#define APM_NOEVENT 0x0000 +#define APM_STANDBY_REQ 0x0001 +#define APM_SUSPEND_REQ 0x0002 +#define APM_NORMAL_RESUME 0x0003 +#define APM_CRIT_RESUME 0x0004 /* suspend/resume happened + without us */ +#define APM_BATTERY_LOW 0x0005 +#define APM_POWER_CHANGE 0x0006 +#define APM_UPDATE_TIME 0x0007 +#define APM_CRIT_SUSPEND_REQ 0x0008 +#define APM_USER_STANDBY_REQ 0x0009 +#define APM_USER_SUSPEND_REQ 0x000A +#define APM_SYS_STANDBY_RESUME 0x000B +#define APM_CAPABILITY_CHANGE 0x000C /* apm v1.2 */ +#define APM_USER_HIBERNATE_REQ 0x000D +#define APM_EVENT_MASK 0xffff + +#define APM_EVENT_COMPOSE(t,i) ((((i) & 0x7fff) << 16)|((t) & APM_EVENT_MASK)) +#define APM_EVENT_TYPE(e) ((e) & APM_EVENT_MASK) +#define APM_EVENT_INDEX(e) ((e) >> 16) + +/* + * LP (Laptop Package) + * + * Copyright (C) 1994 by HOSOKAWA Tatsumi + * + * This software may be used, modified, copied, and distributed, in + * both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + */ + +#define APM_BATTERY_ABSENT 4 + +struct apm_power_info { + u_char battery_state; + u_char ac_state; + u_char battery_life; + u_char spare1; + u_int minutes_left; /* estimate */ + u_int spare2[6]; +}; + +struct apm_ctl { + u_int dev; + u_int mode; +}; + +#define APM_IOC_REJECT _IOW('A', 0, struct apm_event_info) /* reject request # */ +#define APM_IOC_STANDBY _IO('A', 1) /* put system into standby */ +#define APM_IOC_SUSPEND _IO('A', 2) /* put system into suspend */ +#define APM_IOC_GETPOWER _IOR('A', 3, struct apm_power_info) /* fetch battery state */ +#define APM_IOC_DEV_CTL _IOW('A', 5, struct apm_ctl) /* put device into mode */ +#define APM_IOC_PRN_CTL _IOW('A', 6, int ) /* driver power status msg */ +#define APM_PRINT_ON 0 /* driver power status displayed */ +#define APM_PRINT_OFF 1 /* driver power status not displayed */ +#define APM_PRINT_PCT 2 /* driver power status only displayed + if the percentage changes */ +#define APM_IOC_STANDBY_REQ _IO('A', 7) /* request standby */ +#define APM_IOC_SUSPEND_REQ _IO('A', 8) /* request suspend */ +#define APM_IOC_HIBERNATE _IO('A', 9) /* put system into hibernate */ + +#endif /* _MACHINE_APMVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/asm.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/asm.h new file mode 100644 index 0000000000..ea7bd91fc3 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/asm.h @@ -0,0 +1,3 @@ +/* $OpenBSD: asm.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/atomic.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/atomic.h new file mode 100644 index 0000000000..bd432ef8ec --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/atomic.h @@ -0,0 +1,10 @@ +/* $OpenBSD: atomic.h,v 1.3 2011/03/23 16:54:36 pirofti Exp $ */ + +/* Public Domain */ + +#ifndef _MACHINE_ATOMIC_H_ +#define _MACHINE_ATOMIC_H_ + +#include + +#endif /* _MACHINE_ATOMIC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/autoconf.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/autoconf.h new file mode 100644 index 0000000000..3ec5c80d9e --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/autoconf.h @@ -0,0 +1,72 @@ +/* $OpenBSD: autoconf.h,v 1.13 2024/05/22 05:51:49 jsg Exp $ */ + +/* + * Copyright (c) 1997 Per Fogelstrom + * + * 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. + * + */ +/* + * Machine-dependent structures of autoconfiguration + */ + +#ifndef _MACHINE_AUTOCONF_H_ +#define _MACHINE_AUTOCONF_H_ + +#include + +struct confargs { + char *ca_name; + bus_space_tag_t ca_iot; + bus_dma_tag_t ca_dmat; + u_int32_t ca_node; + int ca_nreg; + u_int32_t *ca_reg; + int ca_nintr; + int32_t *ca_intr; + u_int ca_baseaddr; + +}; + +int badaddr(void *, u_int32_t); + +typedef int (time_read_t)(time_t *sec); +typedef int (time_write_t)(time_t sec); + +extern time_read_t *time_read; +extern time_write_t *time_write; + +typedef int mac_intr_handle_t; +typedef void *(intr_establish_t)(void *, mac_intr_handle_t, + int, int, int (*func)(void *), void *, const char *); +typedef void (intr_disestablish_t)(void *, void *); +struct cpu_info; +typedef void (intr_send_ipi_t)(struct cpu_info *, int); + +intr_establish_t mac_intr_establish; +intr_disestablish_t mac_intr_disestablish; +extern intr_establish_t *intr_establish_func; +extern intr_disestablish_t *intr_disestablish_func; +extern intr_send_ipi_t *intr_send_ipi_func; + + +#endif /* _MACHINE_AUTOCONF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/bus.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/bus.h new file mode 100644 index 0000000000..0787b68183 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/bus.h @@ -0,0 +1,643 @@ +/* $OpenBSD: bus.h,v 1.27 2024/05/22 05:51:49 jsg Exp $ */ + +/* + * Copyright (c) 1997 Per Fogelstrom. All rights reserved. + * Copyright (c) 1996 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christopher G. Demetriou + * for the NetBSD Project. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MACHINE_BUS_H_ +#define _MACHINE_BUS_H_ + +#include + +#ifdef __STDC__ +#define CAT(a,b) a##b +#define CAT3(a,b,c) a##b##c +#else +#define CAT(a,b) a/**/b +#define CAT3(a,b,c) a/**/b/**/c +#endif + +/* + * Bus access types. + */ +typedef u_long bus_addr_t; +typedef u_long bus_size_t; +typedef u_long bus_space_handle_t; +typedef struct ppc_bus_space *bus_space_tag_t; + +struct ppc_bus_space { + u_int32_t bus_base; + u_int32_t bus_size; + u_int8_t bus_io; /* IO or memory */ +}; +#define POWERPC_BUS_TAG_BASE(x) ((x)->bus_base) + +/* + * Access methods for bus resources + */ +int bus_space_map(bus_space_tag_t t, bus_addr_t addr, + bus_size_t size, int flags, bus_space_handle_t *bshp); +void bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh, + bus_size_t size); +int bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh, + bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp); +int bus_space_alloc(bus_space_tag_t tag, bus_addr_t rstart, + bus_addr_t rend, bus_size_t size, bus_size_t alignment, + bus_size_t boundary, int flags, bus_addr_t *addrp, + bus_space_handle_t *handlep); +void bus_space_free(bus_space_tag_t tag, bus_space_handle_t handle, + bus_size_t size); +paddr_t bus_space_mmap(bus_space_tag_t, bus_addr_t, off_t, int, int); + +#define BUS_SPACE_MAP_CACHEABLE 0x01 +#define BUS_SPACE_MAP_LINEAR 0x02 +#define BUS_SPACE_MAP_PREFETCHABLE 0x04 + +/* + * void *bus_space_vaddr(bus_space_tag_t, bus_space_handle_t); + * + * Get the kernel virtual address for the mapped bus space. + * Only allowed for regions mapped with BUS_SPACE_MAP_LINEAR. + */ +#define bus_space_vaddr(t, h) ((void *)(h)) + +#define bus_space_read(n,m) \ +static __inline CAT3(u_int,m,_t) \ +CAT(bus_space_read_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba) \ +{ \ + return CAT3(in,m,rb)((volatile CAT3(u_int,m,_t) *)(bsh + (ba))); \ +} + +bus_space_read(1,8) +bus_space_read(2,16) +bus_space_read(4,32) + +#define bus_space_read_8 !!! bus_space_read_8 unimplemented !!! + +#define bus_space_write(n,m) \ +static __inline void \ +CAT(bus_space_write_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, CAT3(u_int,m,_t) x) \ +{ \ + CAT3(out,m,rb)((volatile CAT3(u_int,m,_t) *)(bsh + (ba)), x); \ +} + +bus_space_write(1,8) +bus_space_write(2,16) +bus_space_write(4,32) + +#define bus_space_write_8 !!! bus_space_write_8 unimplemented !!! + +#define bus_space_read_raw(n,m) \ +static __inline CAT3(u_int,m,_t) \ +CAT(bus_space_read_raw_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba) \ +{ \ + return CAT(in,m)((volatile CAT3(u_int,m,_t) *)(bsh + (ba))); \ +} + +bus_space_read_raw(1,8) +bus_space_read_raw(2,16) +bus_space_read_raw(4,32) + +#define bus_space_read_raw_8 !!! bus_space_read_raw_8 unimplemented !!! + +#define bus_space_write_raw(n,m) \ +static __inline void \ +CAT(bus_space_write_raw_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, CAT3(u_int,m,_t) x) \ +{ \ + CAT(out,m)((volatile CAT3(u_int,m,_t) *)(bsh + (ba)), x); \ +} + +bus_space_write_raw(1,8) +bus_space_write_raw(2,16) +bus_space_write_raw(4,32) + +#define bus_space_write_raw_8 !!! bus_space_write_raw_8 unimplemented !!! + +#define bus_space_read_multi(n, m) \ +static __inline void \ +CAT(bus_space_read_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_size_t ba, CAT3(u_int,m,_t) *buf, bus_size_t cnt) \ +{ \ + while (cnt--) \ + *buf++ = CAT(bus_space_read_,n)(bst, bsh, ba); \ +} + +bus_space_read_multi(1,8) +bus_space_read_multi(2,16) +bus_space_read_multi(4,32) + +#define bus_space_read_multi_8 !!! bus_space_read_multi_8 not implemented !!! + + +#define bus_space_write_multi_8 !!! bus_space_write_multi_8 not implemented !!! + +#define bus_space_write_multi(n, m) \ +static __inline void \ +CAT(bus_space_write_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_size_t ba, const CAT3(u_int,m,_t) *buf, bus_size_t cnt) \ +{ \ + while (cnt--) \ + CAT(bus_space_write_,n)(bst, bsh, ba, *buf++); \ +} + +bus_space_write_multi(1,8) +bus_space_write_multi(2,16) +bus_space_write_multi(4,32) + +#define bus_space_write_multi_8 !!! bus_space_write_multi_8 not implemented !!! + +/* + * void bus_space_read_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_intN_t *addr, size_t count); + * + * Read `count' 1, 2, 4, or 8 byte quantities from bus space + * described by tag/handle and starting at `offset' and copy into + * buffer provided. + */ +#define __BA(t, h, o) ((void *)((h) + (o))) + +static __inline void +bus_space_read_region_1(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int8_t *addr, size_t count) +{ + volatile u_int8_t *s = __BA(tag, bsh, offset); + + while (count--) + *addr++ = *s++; + __asm volatile("eieio; sync"); +} + +static __inline void +bus_space_read_region_2(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int16_t *addr, size_t count) +{ + volatile u_int16_t *s = __BA(tag, bsh, offset); + + while (count--) + __asm volatile("lhbrx %0, 0, %1" : + "=r"(*addr++) : "r"(s++)); + __asm volatile("eieio; sync"); +} + +static __inline void +bus_space_read_region_4(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int32_t *addr, size_t count) +{ + volatile u_int32_t *s = __BA(tag, bsh, offset); + + while (count--) + __asm volatile("lwbrx %0, 0, %1" : + "=r"(*addr++) : "r"(s++)); + __asm volatile("eieio; sync"); +} + +#if 0 /* Cause a link error for bus_space_read_region_8 */ +#define bus_space_read_region_8 !!! unimplemented !!! +#endif + + +/* + * void bus_space_write_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * const u_intN_t *addr, size_t count); + * + * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided + * to bus space described by tag/handle starting at `offset'. + */ + +static __inline void +bus_space_write_region_1(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, const u_int8_t *addr, size_t count) +{ + volatile u_int8_t *d = __BA(tag, bsh, offset); + + while (count--) + *d++ = *addr++; + __asm volatile("eieio; sync"); +} + +static __inline void +bus_space_write_region_2(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, const u_int16_t *addr, size_t count) +{ + volatile u_int16_t *d = __BA(tag, bsh, offset); + + while (count--) + __asm volatile("sthbrx %0, 0, %1" :: + "r"(*addr++), "r"(d++)); + __asm volatile("eieio; sync"); +} + +static __inline void +bus_space_write_region_4(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, const u_int32_t *addr, size_t count) +{ + volatile u_int32_t *d = __BA(tag, bsh, offset); + + while (count--) + __asm volatile("stwbrx %0, 0, %1" :: + "r"(*addr++), "r"(d++)); + __asm volatile("eieio; sync"); +} + +#if 0 +#define bus_space_write_region_8 !!! bus_space_write_region_8 unimplemented !!! +#endif + +/* + * void bus_space_read_raw_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_intN_t *addr, size_t count); + * + * Read `count' bytes from bus space described by tag/handle and starting + * at `offset' and copy into buffer provided w/o bus-host byte swapping. + */ + +static __inline void +bus_space_read_raw_region_2(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int8_t *addr, size_t count) +{ + volatile u_int16_t *s = __BA(tag, bsh, offset); + u_int16_t *laddr = (void *)addr; + + count = count >> 1; + + while (count--) + *laddr++ = *s++; + __asm volatile("eieio; sync"); +} + +static __inline void +bus_space_read_raw_region_4(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int8_t *addr, size_t count) +{ + volatile u_int32_t *s = __BA(tag, bsh, offset); + u_int32_t *laddr = (void *)addr; + + count = count >> 2; + + while (count--) + *laddr++ = *s++; + __asm volatile("eieio; sync"); +} + +#if 0 /* Cause a link error for bus_space_read_raw_region_8 */ +#define bus_space_read_raw_region_8 \ + !!! bus_space_read_raw_region_8 unimplemented !!! +#endif + + +/* + * void bus_space_write_raw_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * const u_intN_t *addr, size_t count); + * + * Write `count' bytes from the buffer provided to bus space described + * by tag/handle starting at `offset' w/o host-bus byte swapping. + */ + +static __inline void +bus_space_write_raw_region_2(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, const u_int8_t *addr, size_t count) +{ + volatile u_int16_t *d = __BA(tag, bsh, offset); + const u_int16_t *laddr = (void *)addr; + + count = count >> 1; + + while (count--) + *d++ = *laddr++; + __asm volatile("eieio; sync"); +} + +static __inline void +bus_space_write_raw_region_4(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, const u_int8_t *addr, size_t count) +{ + volatile u_int32_t *d = __BA(tag, bsh, offset); + const u_int32_t *laddr = (void *)addr; + + count = count >> 2; + + while (count--) + *d++ = *laddr++; + __asm volatile("eieio; sync"); +} + +#if 0 +#define bus_space_write_raw_region_8 \ + !!! bus_space_write_raw_region_8 unimplemented !!! +#endif + +/* + * void bus_space_set_multi_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, u_intN_t val, + * size_t count); + * + * Write the 1, 2, 4, or 8 byte value `val' to bus space described + * by tag/handle/offset `count' times. + */ +static __inline void bus_space_set_multi_1(bus_space_tag_t, + bus_space_handle_t, bus_size_t, u_int8_t, size_t); +static __inline void bus_space_set_multi_2(bus_space_tag_t, + bus_space_handle_t, bus_size_t, u_int16_t, size_t); +static __inline void bus_space_set_multi_4(bus_space_tag_t, + bus_space_handle_t, bus_size_t, u_int32_t, size_t); + +static __inline void +bus_space_set_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int8_t val, size_t count) +{ + volatile u_int8_t *d = __BA(tag, bsh, offset); + + while (count--) + *d = val; + __asm__ volatile("eieio; sync"); +} + +static __inline void +bus_space_set_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int16_t val, size_t count) +{ + volatile u_int16_t *d = __BA(tag, bsh, offset); + + while (count--) + __asm__ volatile("sthbrx %0, 0, %1" :: + "r"(val), "r"(d)); + __asm__ volatile("eieio; sync"); +} + +static __inline void +bus_space_set_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int32_t val, size_t count) +{ + volatile u_int32_t *d = __BA(tag, bsh, offset); + + while (count--) + __asm__ volatile("stwbrx %0, 0, %1" :: + "r"(val), "r"(d)); + __asm__ volatile("eieio; sync"); +} + +#define bus_space_set_multi_8 !!! bus_space_set_multi_8 unimplemented !!! + +/* These are OpenBSD extensions to the general NetBSD bus interface. */ +void +bus_space_read_raw_multi_2(bus_space_tag_t bst, bus_space_handle_t bsh, + bus_addr_t ba, u_int8_t *dst, bus_size_t size); +void +bus_space_read_raw_multi_4(bus_space_tag_t bst, bus_space_handle_t bsh, + bus_addr_t ba, u_int8_t *dst, bus_size_t size); +#define bus_space_read_raw_multi_8 \ + !!! bus_space_read_raw_multi_8 not implemented !!! + +void +bus_space_write_raw_multi_2(bus_space_tag_t bst, bus_space_handle_t bsh, + bus_addr_t ba, const u_int8_t *src, bus_size_t size); +void +bus_space_write_raw_multi_4(bus_space_tag_t bst, bus_space_handle_t bsh, + bus_addr_t ba, const u_int8_t *src, bus_size_t size); +#define bus_space_write_raw_multi_8 \ + !!! bus_space_write_raw_multi_8 not implemented !!! + +void +bus_space_set_region_1(bus_space_tag_t bst, bus_space_handle_t h, bus_size_t o, + u_int8_t val, bus_size_t c); +void +bus_space_set_region_2(bus_space_tag_t bst, bus_space_handle_t h, bus_size_t o, + u_int16_t val, bus_size_t c); +void +bus_space_set_region_4(bus_space_tag_t bst, bus_space_handle_t h, bus_size_t o, + u_int32_t val, bus_size_t c); +#define bus_space_set_region_8 \ + !!! bus_space_set_region_8 not implemented !!! + +void +bus_space_copy_1(void *v, bus_space_handle_t h1, bus_space_handle_t h2, + bus_size_t o1, bus_size_t o2, bus_size_t c); +void +bus_space_copy_2(void *v, bus_space_handle_t h1, bus_space_handle_t h2, + bus_size_t o1, bus_size_t o2, bus_size_t c); +void +bus_space_copy_4(void *v, bus_space_handle_t h1, bus_space_handle_t h2, + bus_size_t o1, bus_size_t o2, bus_size_t c); +#define bus_space_copy_8 \ + !!! bus_space_copy_8 not implemented !!! + +/* + * Bus read/write barrier methods. + * + * void bus_space_barrier(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * bus_size_t len, int flags); + * + * Note: powerpc does not currently implement barriers, but we must + * provide the flags to MI code. + * the processor does have eieio which is effectively the barrier + * operator, however due to how memory is mapped this should? not + * be required. + */ +#define bus_space_barrier(t, h, o, l, f) \ + ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f))) +#define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */ +#define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */ + +#define BUS_DMA_WAITOK 0x0000 /* safe to sleep (pseudo-flag) */ +#define BUS_DMA_NOWAIT 0x0001 /* not safe to sleep */ +#define BUS_DMA_ALLOCNOW 0x0002 /* perform resource allocation now */ +#define BUS_DMA_COHERENT 0x0008 /* hint: map memory DMA coherent */ +#define BUS_DMA_BUS1 0x0010 /* placeholders for bus functions... */ +#define BUS_DMA_BUS2 0x0020 +#define BUS_DMA_BUS3 0x0040 +#define BUS_DMA_BUS4 0x0080 +#define BUS_DMA_READ 0x0100 /* mapping is device -> memory only */ +#define BUS_DMA_WRITE 0x0200 /* mapping is memory -> device only */ +#define BUS_DMA_STREAMING 0x0400 /* hint: sequential, unidirectional */ +#define BUS_DMA_ZERO 0x0800 /* zero memory in dmamem_alloc */ +#define BUS_DMA_NOCACHE 0x1000 /* map memory uncached */ +#define BUS_DMA_64BIT 0x2000 /* device handles 64bit dva */ + + +/* Forwards needed by prototypes below. */ +struct mbuf; +struct proc; +struct uio; + +#define BUS_DMASYNC_POSTREAD 0x01 +#define BUS_DMASYNC_POSTWRITE 0x02 +#define BUS_DMASYNC_PREREAD 0x04 +#define BUS_DMASYNC_PREWRITE 0x08 + +typedef struct powerpc_bus_dma_tag *bus_dma_tag_t; +typedef struct powerpc_bus_dmamap *bus_dmamap_t; + +/* + * bus_dma_segment_t + * + * Describes a single contiguous DMA transaction. Values + * are suitable for programming into DMA registers. + */ +struct powerpc_bus_dma_segment { + bus_addr_t ds_addr; /* DMA address */ + bus_size_t ds_len; /* length of transfer */ +}; +typedef struct powerpc_bus_dma_segment bus_dma_segment_t; + +/* + * bus_dma_tag_t + * + * A machine-dependent opaque type describing the implementation of + * DMA for a given bus. + */ + +struct powerpc_bus_dma_tag { + void *_cookie; /* cookie used in the guts */ + + /* + * DMA mapping methods. + */ + int (*_dmamap_create)(bus_dma_tag_t , bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); + void (*_dmamap_destroy)(bus_dma_tag_t , bus_dmamap_t); + int (*_dmamap_load)(bus_dma_tag_t , bus_dmamap_t, void *, + bus_size_t, struct proc *, int); + int (*_dmamap_load_mbuf)(bus_dma_tag_t , bus_dmamap_t, + struct mbuf *, int); + int (*_dmamap_load_uio)(bus_dma_tag_t , bus_dmamap_t, + struct uio *, int); + int (*_dmamap_load_raw)(bus_dma_tag_t , bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); + void (*_dmamap_unload)(bus_dma_tag_t , bus_dmamap_t); + void (*_dmamap_sync)(bus_dma_tag_t , bus_dmamap_t, + bus_addr_t, bus_size_t, int); + + /* + * DMA memory utility functions. + */ + int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); + int (*_dmamem_alloc_range)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int, + bus_addr_t, bus_addr_t); + void (*_dmamem_free)(bus_dma_tag_t, bus_dma_segment_t *, int); + int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); + void (*_dmamem_unmap)(bus_dma_tag_t, caddr_t, size_t); + paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *, + int, off_t, int, int); +}; + +#define bus_dmamap_create(t, s, n, m, b, f, p) \ + (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p)) +#define bus_dmamap_destroy(t, p) \ + (*(t)->_dmamap_destroy)((t), (p)) +#define bus_dmamap_load(t, m, b, s, p, f) \ + (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f)) +#define bus_dmamap_load_mbuf(t, m, b, f) \ + (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f)) +#define bus_dmamap_load_uio(t, m, u, f) \ + (*(t)->_dmamap_load_uio)((t), (m), (u), (f)) +#define bus_dmamap_load_raw(t, m, sg, n, s, f) \ + (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f)) +#define bus_dmamap_unload(t, p) \ + (*(t)->_dmamap_unload)((t), (p)) +#define bus_dmamap_sync(t, p, a, l, o) \ + (void)((t)->_dmamap_sync ? \ + (*(t)->_dmamap_sync)((t), (p), (a), (l), (o)) : (void)0) + +#define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \ + (*(t)->_dmamem_alloc)((t)->_cookie, (s), (a), (b), (sg), (n), (r), (f)) +#define bus_dmamem_alloc_range(t, s, a, b, sg, n, r, f, l, h) \ + (*(t)->_dmamem_alloc_range)((t), (s), (a), (b), (sg), \ + (n), (r), (f), (l), (h)) +#define bus_dmamem_free(t, sg, n) \ + (*(t)->_dmamem_free)((t)->_cookie, (sg), (n)) +#define bus_dmamem_map(t, sg, n, s, k, f) \ + (*(t)->_dmamem_map)((t)->_cookie, (sg), (n), (s), (k), (f)) +#define bus_dmamem_unmap(t, k, s) \ + (*(t)->_dmamem_unmap)((t)->_cookie, (k), (s)) +#define bus_dmamem_mmap(t, sg, n, o, p, f) \ + (*(t)->_dmamem_mmap)((t)->_cookie, (sg), (n), (o), (p), (f)) + +int _dmamap_create(bus_dma_tag_t, bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); +void _dmamap_destroy(bus_dma_tag_t, bus_dmamap_t); +int _dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int); +int _dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, struct mbuf *, int); +int _dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, struct uio *, int); +int _dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); +void _dmamap_unload(bus_dma_tag_t, bus_dmamap_t); +void _dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, bus_size_t, + int); + +int _dmamem_alloc(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); +int _dmamem_alloc_range( bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int, + bus_addr_t, bus_addr_t); +void _dmamem_free(bus_dma_tag_t, bus_dma_segment_t *, int); +int _dmamem_map(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); +void _dmamem_unmap(bus_dma_tag_t, caddr_t, size_t); +paddr_t _dmamem_mmap(bus_dma_tag_t, bus_dma_segment_t *, int, off_t, int, int); + +/* + * bus_dmamap_t + * + * Describes a DMA mapping. + */ +struct powerpc_bus_dmamap { + /* + * PRIVATE MEMBERS: not for use by machine-independent code. + */ + bus_size_t _dm_size; /* largest DMA transfer mappable */ + int _dm_segcnt; /* number of segs this map can map */ + bus_size_t _dm_maxsegsz; /* largest possible segment */ + bus_size_t _dm_boundary; /* don't cross this */ + int _dm_flags; /* misc. flags */ + + void *_dm_cookie; /* cookie for bus-specific functions */ + + /* + * PUBLIC MEMBERS: these are used by machine-independent code. + */ + bus_size_t dm_mapsize; /* size of the mapping */ + int dm_nsegs; /* # valid segments in mapping */ + bus_dma_segment_t dm_segs[1]; /* segments; variable length */ +}; + +#endif /* _MACHINE_BUS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/cdefs.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/cdefs.h new file mode 100644 index 0000000000..4e15edb0a4 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/cdefs.h @@ -0,0 +1,3 @@ +/* $OpenBSD: cdefs.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/conf.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/conf.h new file mode 100644 index 0000000000..370b2c67c5 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/conf.h @@ -0,0 +1,56 @@ +/* $OpenBSD: conf.h,v 1.15 2022/06/28 14:43:50 visa Exp $ */ +/* $NetBSD: conf.h,v 1.2 1996/05/05 19:28:34 christos Exp $ */ + +/* + * Copyright (c) 1996 Christos Zoulas. 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 Christos Zoulas. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#define mmread mmrw +#define mmwrite mmrw +cdev_decl(mm); + +/* open, close, write, ioctl, kqueue */ +#define cdev_apm_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,n,kqfilter) } + +cdev_decl(apm); +cdev_decl(zs); + +/* open, close, ioctl */ +#define cdev_openprom_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) nullop, 0, \ + (dev_type_mmap((*))) enodev } + +cdev_decl(openprom); \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/cpu.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/cpu.h new file mode 100644 index 0000000000..9b938b2a8d --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/cpu.h @@ -0,0 +1,76 @@ +/* $OpenBSD: cpu.h,v 1.15 2022/10/21 22:42:36 gkoehler Exp $ */ +/* $NetBSD: cpu.h,v 1.1 1996/09/30 16:34:21 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. + */ +#ifndef _MACHINE_CPU_H_ +#define _MACHINE_CPU_H_ + +/* + * CTL_MACHDEP definitions. + */ +#define CPU_ALLOWAPERTURE 1 /* allow mmap of /dev/xf86 */ +#define CPU_ALTIVEC 2 /* altivec is present */ +#define CPU_LIDACTION 3 /* action caused by lid close */ +#define CPU_PWRACTION 4 /* action caused by power button */ +#define CPU_MAXID 5 /* number of valid machdep ids */ + +#define CTL_MACHDEP_NAMES { \ + { 0, 0 }, \ + { "allowaperture", CTLTYPE_INT }, \ + { "altivec", CTLTYPE_INT }, \ + { "lidaction", CTLTYPE_INT }, \ + { "pwraction", CTLTYPE_INT }, \ +} + +#ifdef _KERNEL + +#include + +/* Frequency scaling */ +#define FREQ_FULL 0 +#define FREQ_HALF 1 +#define FREQ_QUARTER 2 /* Supported only on IBM 970MP */ + +extern u_int32_t ppc_curfreq; +extern u_int32_t ppc_maxfreq; +extern int ppc_altivec; + +extern void (*ppc64_slew_voltage)(u_int); + +extern u_int32_t ticks_per_sec; +extern u_int32_t ns_per_tick; + +extern int lid_action; +extern int pwr_action; + +#endif /* _KERNEL */ +#endif /* _MACHINE_CPU_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/db_machdep.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/db_machdep.h new file mode 100644 index 0000000000..525dade241 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/db_machdep.h @@ -0,0 +1,3 @@ +/* $OpenBSD: db_machdep.h,v 1.7 2016/03/05 17:41:55 mpi Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/disklabel.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/disklabel.h new file mode 100644 index 0000000000..aca83dc5eb --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/disklabel.h @@ -0,0 +1,90 @@ +/* $OpenBSD: disklabel.h,v 1.16 2015/09/30 15:13:54 krw Exp $ */ + +/* + * Copyright (c) 1994 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 _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 */ + +/* HFS/DPME */ + +/* partition map structure from Inside Macintosh: Devices, SCSI Manager + * pp. 13-14. The partition map always begins on physical block 1. + * + * With the exception of block 0, all blocks on the disk must belong to + * exactly one partition. The partition map itself belongs to a partition + * of type `APPLE_PARTITION_MAP', and is not limited in size by anything + * other than available disk space. The partition map is not necessarily + * the first partition listed. + */ +struct part_map_entry { +#define PART_ENTRY_MAGIC 0x504d + u_int16_t pmSig; /* partition signature */ + u_int16_t pmSigPad; /* (reserved) */ + u_int32_t pmMapBlkCnt; /* number of blocks in partition map */ + u_int32_t pmPyPartStart; /* first physical block of partition */ + u_int32_t pmPartBlkCnt; /* number of blocks in partition */ + char pmPartName[32]; /* partition name */ + char pmPartType[32]; /* partition type */ + u_int32_t pmLgDataStart; /* first logical block of data area */ + u_int32_t pmDataCnt; /* number of blocks in data area */ + u_int32_t pmPartStatus; /* partition status information */ + u_int32_t pmLgBootStart; /* first logical block of boot code */ + u_int32_t pmBootSize; /* size of boot code, in bytes */ + u_int32_t pmBootLoad; /* boot code load address */ + u_int32_t pmBootLoad2; /* (reserved) */ + u_int32_t pmBootEntry; /* boot code entry point */ + u_int32_t pmBootEntry2; /* (reserved) */ + u_int32_t pmBootCksum; /* boot code checksum */ + char pmProcessor[16]; /* processor type (e.g. "68020") */ + u_int8_t pmBootArgs[128]; /* A/UX boot arguments */ + /* we do not index the disk image as an array, + * leave out the on disk padding + */ +#if 0 + u_int8_t pad[248]; /* pad to end of block */ +#endif +}; + +#define PART_TYPE_DRIVER "APPLE_DRIVER" +#define PART_TYPE_DRIVER43 "APPLE_DRIVER43" +#define PART_TYPE_DRIVERATA "APPLE_DRIVER_ATA" +#define PART_TYPE_DRIVERIOKIT "APPLE_DRIVER_IOKIT" +#define PART_TYPE_FWDRIVER "APPLE_FWDRIVER" +#define PART_TYPE_FWB_COMPONENT "FWB DRIVER COMPONENTS" +#define PART_TYPE_FREE "APPLE_FREE" +#define PART_TYPE_MAC "APPLE_HFS" +#define PART_TYPE_OPENBSD "OPENBSD" + +#endif /* _MACHINE_DISKLABEL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/elf.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/elf.h new file mode 100644 index 0000000000..ed920f5d1e --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/elf.h @@ -0,0 +1,3 @@ +/* $OpenBSD: elf.h,v 1.1 2024/07/14 19:33:59 miod Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/endian.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/endian.h new file mode 100644 index 0000000000..4bc2fa0df5 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/endian.h @@ -0,0 +1,3 @@ +/* $OpenBSD: endian.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/exec.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/exec.h new file mode 100644 index 0000000000..b283c6dd5f --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/exec.h @@ -0,0 +1,3 @@ +/* $OpenBSD: exec.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/fenv.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/fenv.h new file mode 100644 index 0000000000..63244974f9 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/fenv.h @@ -0,0 +1,3 @@ +/* $OpenBSD: fenv.h,v 1.2 2013/06/01 21:20:54 jasper Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/fpu.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/fpu.h new file mode 100644 index 0000000000..b3c92c2976 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/fpu.h @@ -0,0 +1,3 @@ +/* $OpenBSD: fpu.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/frame.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/frame.h new file mode 100644 index 0000000000..9edae57f95 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/frame.h @@ -0,0 +1,3 @@ +/* $OpenBSD: frame.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/ieee.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/ieee.h new file mode 100644 index 0000000000..46e05aeea4 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/ieee.h @@ -0,0 +1,3 @@ +/* $OpenBSD: ieee.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/ieeefp.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/ieeefp.h new file mode 100644 index 0000000000..d42b97756f --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/ieeefp.h @@ -0,0 +1,3 @@ +/* $OpenBSD: ieeefp.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/intr.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/intr.h new file mode 100644 index 0000000000..e1a6b65ddc --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/intr.h @@ -0,0 +1,10 @@ +/* $OpenBSD: intr.h,v 1.9 2014/04/01 20:27:14 mpi Exp $ */ + +#include + +#ifndef _LOCORE +extern int intr_shared_edge; + +void install_extint(void (*handler)(void)); +void openpic_set_priority(int, int); +#endif \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/kcore.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/kcore.h new file mode 100644 index 0000000000..0f3da93e38 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/kcore.h @@ -0,0 +1,3 @@ +/* $OpenBSD: kcore.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/limits.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/limits.h new file mode 100644 index 0000000000..3b2a85e186 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/limits.h @@ -0,0 +1,3 @@ +/* $OpenBSD: limits.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/loadfile_machdep.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/loadfile_machdep.h new file mode 100644 index 0000000000..5ec3bc68fa --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/loadfile_machdep.h @@ -0,0 +1,49 @@ +/* $OpenBSD: loadfile_machdep.h,v 1.4 2015/07/17 20:44:39 miod Exp $ */ +/* $NetBSD: loadfile_machdep.h,v 1.1 1999/04/29 03:17:12 tsubai Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * 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. + */ + +#define BOOT_ELF +#define ELFSIZE 32 + +#define LOAD_KERNEL LOAD_ALL +#define COUNT_KERNEL COUNT_ALL + +#define LOADADDR(a) (((u_long)(a)) + offset) +#define ALIGNENTRY(a) ((u_long)(a)) +#define READ(f, b, c) read((f), (void *)LOADADDR(b), (c)) +#define BCOPY(s, d, c) memcpy((void *)LOADADDR(d), (void *)(s), (c)) +#define BZERO(d, c) memset((void *)LOADADDR(d), 0, (c)) +#define WARN(a) (void)(printf a, \ + printf((errno ? ": %s\n" : "\n"), \ + strerror(errno))) +#define PROGRESS(a) (void) printf a +#define ALLOC(a) alloc(a) +#define FREE(a, b) free(a, b) \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/mplock.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/mplock.h new file mode 100644 index 0000000000..7e82ab4902 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/mplock.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mplock.h,v 1.3 2015/06/26 11:15:32 dlg Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/mutex.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/mutex.h new file mode 100644 index 0000000000..06bd20011d --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/mutex.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mutex.h,v 1.1 2007/03/22 19:26:28 kettenis Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/openpromio.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/openpromio.h new file mode 100644 index 0000000000..1b69c531fe --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/openpromio.h @@ -0,0 +1,57 @@ +/* $OpenBSD: openpromio.h,v 1.1 2007/11/12 19:23:26 kettenis Exp $ */ +/* $NetBSD: openpromio.h,v 1.1.1.1 1998/06/20 04:58:52 eeh Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)openpromio.h 8.1 (Berkeley) 6/11/93 + */ + +struct opiocdesc { + int op_nodeid; /* passed or returned node id */ + int op_namelen; /* length of op_name */ + char *op_name; /* pointer to field name */ + int op_buflen; /* length of op_buf (value-result) */ + char *op_buf; /* pointer to field value */ +}; + +#define OPIOCGET _IOWR('O', 1, struct opiocdesc) /* get openprom field */ +#define OPIOCSET _IOW('O', 2, struct opiocdesc) /* set openprom field */ +#define OPIOCNEXTPROP _IOWR('O', 3, struct opiocdesc) /* get next property */ +#define OPIOCGETOPTNODE _IOR('O', 4, int) /* get openprom field */ +#define OPIOCGETNEXT _IOWR('O', 5, int) /* get next node of node */ +#define OPIOCGETCHILD _IOWR('O', 6, int) /* get first child of node */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/param.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/param.h new file mode 100644 index 0000000000..1aeadbe686 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/param.h @@ -0,0 +1,52 @@ +/* $OpenBSD: param.h,v 1.6 2014/04/07 16:29:06 deraadt 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 _MACHINE_PARAM_H_ +#define _MACHINE_PARAM_H_ + +#ifdef _KERNEL +#ifndef _LOCORE +#include +#endif /* _LOCORE */ +#endif + +#include + +#define MACHINE "macppc" +#define _MACHINE macppc + +#define KERNBASE 0x100000 + +#define MSGBUFSIZE (4 * PAGE_SIZE) + +#endif /* _MACHINE_PARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/pcb.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/pcb.h new file mode 100644 index 0000000000..ae453583b2 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/pcb.h @@ -0,0 +1,3 @@ +/* $OpenBSD: pcb.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/pci_machdep.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/pci_machdep.h new file mode 100644 index 0000000000..443fe240af --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/pci_machdep.h @@ -0,0 +1,108 @@ +/* $OpenBSD: pci_machdep.h,v 1.4 2019/12/05 12:46:54 mpi Exp $ */ +/* $NetBSD: pci_machdep.h,v 1.7 2001/07/20 00:07:14 eeh Exp $ */ + +/* + * Copyright (c) 1999 Matthew R. Green + * 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_PCI_MACHDEP_H_ +#define _MACHINE_PCI_MACHDEP_H_ + +extern struct powerpc_bus_dma_tag pci_bus_dma_tag; + +/* + * Forward declarations. + */ +struct pci_attach_args; + +/* + * define some bits used to glue into the common PCI code. + */ + +typedef struct ppc_pci_chipset *pci_chipset_tag_t; + +typedef unsigned long pci_intr_handle_t; + +/* + * The stuuuuuuupid allegedly MI PCI code expects pcitag_t to be a + * scalar type. But we really need to store both the OFW node and + * the bus/device/function info in it. (We'd like to store more, + * like all the ofw properties, but we don't need to.) Luckily, + * both are 32-bit values, so we can squeeze them into a u_int64_t + * with a little help from some macros. + */ + +#define PCITAG_NODE(x) (int)(((x)>>32)&0xffffffff) +#define PCITAG_OFFSET(x) ((x)&0xffffffff) +#define PCITAG_BUS(t) ((PCITAG_OFFSET(t)>>16)&0xff) +#define PCITAG_DEV(t) ((PCITAG_OFFSET(t)>>11)&0x1f) +#define PCITAG_FUN(t) ((PCITAG_OFFSET(t)>>8)&0x7) +#define PCITAG_CREATE(n,b,d,f) (((uint64_t)(n)<<32)|((b)<<16)|((d)<<11)|((f)<<8)) +typedef uint64_t pcitag_t; + +struct ppc_pci_chipset { + void *pc_conf_v; + int pc_node; + int busnode[256]; + + pcireg_t (*pc_conf_read)(void *, pcitag_t, int); + void (*pc_conf_write)(void *, pcitag_t, int, pcireg_t); +}; + + +void pci_attach_hook(struct device *, struct device *, + struct pcibus_attach_args *); +int pci_bus_maxdevs(pci_chipset_tag_t, int); +pcitag_t pci_make_tag(pci_chipset_tag_t, int, int, int); +void pci_decompose_tag(pci_chipset_tag_t, pcitag_t, int *, int *, + int *); +int pci_conf_size(pci_chipset_tag_t, pcitag_t); +pcireg_t pci_conf_read(pci_chipset_tag_t, pcitag_t, int); +void pci_conf_write(pci_chipset_tag_t, pcitag_t, int, pcireg_t); +int pci_intr_map(struct pci_attach_args *, pci_intr_handle_t *); +int pci_intr_map_msi(struct pci_attach_args *, pci_intr_handle_t *); +#define pci_intr_map_msix(p, vec, ihp) (-1) +int pci_intr_line(pci_chipset_tag_t, pci_intr_handle_t); +const char *pci_intr_string(pci_chipset_tag_t, pci_intr_handle_t); +void *pci_intr_establish(pci_chipset_tag_t, pci_intr_handle_t, + int, int (*)(void *), void *, const char *); +void pci_intr_disestablish(pci_chipset_tag_t, void *); +int pci_ether_hw_addr(pci_chipset_tag_t, uint8_t *); + +#define pci_probe_device_hook(c, a) (0) + +#define pci_min_powerstate(c, t) (PCI_PMCSR_STATE_D3) +#define pci_set_powerstate_md(c, t, s, p) + +#define pci_dev_postattach(a, b) + +int ofw_intr_map(int, uint32_t *, uint32_t *); +int ofw_enumerate_pcibus(struct pci_softc *, + int (*match)(struct pci_attach_args *), + struct pci_attach_args *); + +#define PCI_MACHDEP_ENUMERATE_BUS ofw_enumerate_pcibus + +#endif /* _MACHINE_PCI_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/pio.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/pio.h new file mode 100644 index 0000000000..551a29a603 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/pio.h @@ -0,0 +1,3 @@ +/* $OpenBSD: pio.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/pmap.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/pmap.h new file mode 100644 index 0000000000..3bff9d0214 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/pmap.h @@ -0,0 +1,3 @@ +/* $OpenBSD: pmap.h,v 1.5 2005/11/07 02:19:46 brad Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/proc.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/proc.h new file mode 100644 index 0000000000..9fb584cd31 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/proc.h @@ -0,0 +1,3 @@ +/* $OpenBSD: proc.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/profile.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/profile.h new file mode 100644 index 0000000000..6ef4ef31dd --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/profile.h @@ -0,0 +1,3 @@ +/* $OpenBSD: profile.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/psl.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/psl.h new file mode 100644 index 0000000000..75712e28fa --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/psl.h @@ -0,0 +1,3 @@ +/* $OpenBSD: psl.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/pte.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/pte.h new file mode 100644 index 0000000000..effc458c15 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/pte.h @@ -0,0 +1,3 @@ +/* $OpenBSD: pte.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/ptrace.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/ptrace.h new file mode 100644 index 0000000000..8853814e4c --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/ptrace.h @@ -0,0 +1,3 @@ +/* $OpenBSD: ptrace.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/rbus_machdep.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/rbus_machdep.h new file mode 100644 index 0000000000..1c0cb27000 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/rbus_machdep.h @@ -0,0 +1,62 @@ +/* $OpenBSD: rbus_machdep.h,v 1.6 2011/03/23 16:54:36 pirofti Exp $ */ +/* $NetBSD: rbus_machdep.h,v 1.2 1999/10/15 06:43:05 haya Exp $ */ + +/* + * Copyright (c) 1999 + * HAYAKAWA Koichi. 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. + */ + + +#if !defined _MACHINE_RBUS_MACHDEP_H_ +#define _MACHINE_RBUS_MACHDEP_H_ + +struct pci_attach_args; /* XXX */ + +void _bus_space_unmap(bus_space_tag_t, bus_space_handle_t, + bus_size_t, bus_addr_t *); + +#define md_space_map(rbt, physaddr, size, flags, bshp) \ + bus_space_map((rbt)->rb_bt, (physaddr), (size), (flags), (bshp)) + +/* XXX */ +bus_addr_t bus_space_unmap_p(bus_space_tag_t t, bus_space_handle_t bsh, + bus_size_t size); + + +#define md_space_unmap(rbt, bsh, size, adrp) \ + do { \ + *adrp = bus_space_unmap_p((rbt)->rb_bt, (bsh), (size)); \ + if ((rbt)->rb_bt->bus_io) { \ + *adrp = *adrp & 0xffff; \ + } \ + } while (0) + +rbus_tag_t rbus_pccbb_parent_io(struct device *self, + struct pci_attach_args *pa); +rbus_tag_t rbus_pccbb_parent_mem(struct device *self, + struct pci_attach_args *pa); + +void pccbb_attach_hook(struct device *, struct device *, + struct pci_attach_args *); + +#endif /* _MACHINE_RBUS_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/reg.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/reg.h new file mode 100644 index 0000000000..8162e439ce --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/reg.h @@ -0,0 +1,3 @@ +/* $OpenBSD: reg.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/reloc.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/reloc.h new file mode 100644 index 0000000000..faca641c79 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/reloc.h @@ -0,0 +1,3 @@ +/* $OpenBSD: reloc.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/setjmp.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/setjmp.h new file mode 100644 index 0000000000..da9cc287b3 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/setjmp.h @@ -0,0 +1,3 @@ +/* $OpenBSD: setjmp.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/signal.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/signal.h new file mode 100644 index 0000000000..fc14275006 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/signal.h @@ -0,0 +1,3 @@ +/* $OpenBSD: signal.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/spinlock.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/spinlock.h new file mode 100644 index 0000000000..37b5429335 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/spinlock.h @@ -0,0 +1,3 @@ +/* $OpenBSD: spinlock.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/tcb.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/tcb.h new file mode 100644 index 0000000000..406394c940 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/tcb.h @@ -0,0 +1,3 @@ +/* $OpenBSD: tcb.h,v 1.2 2013/06/01 21:20:54 jasper Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/timetc.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/timetc.h new file mode 100644 index 0000000000..20d9dfb763 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/timetc.h @@ -0,0 +1,23 @@ +/* $OpenBSD: timetc.h,v 1.2 2020/07/17 20:15:43 gkoehler Exp $ */ +/* + * Copyright (c) 2020 Paul Irofti + * + * 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_TIMETC_H_ +#define _MACHINE_TIMETC_H_ + +#define TC_TB 1 + +#endif /* _MACHINE_TIMETC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/trap.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/trap.h new file mode 100644 index 0000000000..4ceaa94f2b --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/trap.h @@ -0,0 +1,3 @@ +/* $OpenBSD: trap.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/vmparam.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/vmparam.h new file mode 100644 index 0000000000..a8578e2734 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/vmparam.h @@ -0,0 +1,99 @@ +/* $OpenBSD: vmparam.h,v 1.33 2024/01/30 16:43:22 deraadt Exp $ */ +/* $NetBSD: vmparam.h,v 1.1 1996/09/30 16:34:38 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. + */ + +#ifndef MACHINE_VMPARAM_H +#define MACHINE_VMPARAM_H + +#define USRSTACK VM_MAXUSER_ADDRESS + +#ifndef MAXTSIZ +#define MAXTSIZ (128*1024*1024) /* max text size */ +#endif + +#ifndef DFLDSIZ +#define DFLDSIZ (64*1024*1024) /* default data size */ +#endif + +#ifndef MAXDSIZ +#define MAXDSIZ (2UL*1024*1024*1024) /* max data size */ +#endif + +#ifndef BRKSIZ +#define BRKSIZ MAXDSIZ /* heap gap size */ +#endif + +#ifndef DFLSSIZ +#define DFLSSIZ (2*1024*1024) /* default stack size */ +#endif + +#ifndef MAXSSIZ +#define MAXSSIZ (32*1024*1024) /* max stack size */ +#endif + +#define STACKGAP_RANDOM 256*1024 + +/* + * Size of shared memory map + */ +#ifndef SHMMAXPGS +#define SHMMAXPGS 8192 /* 32mb */ +#endif + +/* + * Size of User Raw I/O map + */ +#define USRIOSIZE 1024 + +/* + * Would like to have MAX addresses = 0, but this doesn't (currently) work + */ +#define VM_MIN_ADDRESS ((vaddr_t)PAGE_SIZE) +#define VM_MAXUSER_ADDRESS ((vaddr_t)0xfffff000) +#define VM_MAX_ADDRESS VM_MAXUSER_ADDRESS +#define VM_MIN_KERNEL_ADDRESS ((vaddr_t)(PPC_KERNEL_SR << ADDR_SR_SHIFT)) + +/* map PIE into approximately the first quarter of user va space */ +#define VM_PIE_MIN_ADDR PAGE_SIZE +#define VM_PIE_MAX_ADDR 0x40000000 + +#define VM_KERN_ADDRESS_SIZE (PPC_SEGMENT_LENGTH - (32 * 1024 * 1024)) +#define VM_MAX_KERNEL_ADDRESS (VM_MIN_KERNEL_ADDRESS + VM_KERN_ADDRESS_SIZE) + +#define VM_PHYS_SIZE (USRIOSIZE * PAGE_SIZE) + +#define VM_PHYSSEG_MAX 32 /* actually we could have this many segments */ +#define VM_PHYSSEG_STRAT VM_PSTRAT_BSEARCH +#define VM_PHYSSEG_NOADD /* can't add RAM after vm_mem_init */ + +#endif \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/machine/z8530var.h b/lib/libc/include/powerpc-openbsd-eabihf/machine/z8530var.h new file mode 100644 index 0000000000..275214fc2d --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/machine/z8530var.h @@ -0,0 +1,152 @@ +/* $OpenBSD: z8530var.h,v 1.11 2024/05/22 05:51:49 jsg Exp $ */ +/* $NetBSD: z8530var.h,v 1.5 2002/03/17 19:40:45 atatat Exp $ */ + +/* + * Copyright (c) 1994 Gordon W. Ross + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)zsvar.h 8.1 (Berkeley) 6/11/93 + */ + +#include +#include + +/* + * Clock source info structure, added here so xzs_chanstate works + */ +struct zsclksrc { + long clk; /* clock rate, in MHz, present on signal line */ + int flags; /* Specifies how this source can be used + (RTxC divided, RTxC BRG, PCLK BRG, TRxC divided) + and also if the source is "external" and if it + is changeable (by an ioctl ex.). The + source usage flags are used by the tty + child. The other bits tell zsloadchannelregs + if it should call an md signal source + changing routine. ZSC_VARIABLE says if + an ioctl should be able to change the + clock rate.*/ +}; +#define ZSC_PCLK 0x01 +#define ZSC_RTXBRG 0x02 +#define ZSC_RTXDIV 0x04 +#define ZSC_TRXDIV 0x08 +#define ZSC_VARIABLE 0x40 +#define ZSC_EXTERN 0x80 + +#define ZSC_BRG 0x03 +#define ZSC_DIV 0x0c + + +/* + * These are the machine-dependent (extended) variants of + * struct zs_chanstate and struct zsc_softc + */ +struct xzs_chanstate { + /* machine-independent part (First!)*/ + struct zs_chanstate xzs_cs; + /* machine-dependent extensions */ + int cs_hwflags; + int cs_chip; /* type of chip */ + /* Clock source info... */ + int cs_clock_count; /* how many signal sources available */ + struct zsclksrc cs_clocks[4]; /* info on available signal sources */ + long cs_cclk_flag; /* flag for current clock source */ + long cs_pclk_flag; /* flag for pending clock source */ + int cs_csource; /* current source # */ + int cs_psource; /* pending source # */ +}; + +struct zsc_softc { + struct device zsc_dev; /* base device */ + struct zs_chanstate *zsc_cs[2]; /* channel A and B soft state */ + /* Machine-dependent part follows... */ + void *zsc_softintr; + struct xzs_chanstate xzsc_xcs_store[2]; + dbdma_regmap_t *zsc_txdmareg[2]; + dbdma_command_t *zsc_txdmacmd[2]; + /* XXX tx only, for now */ +}; + +/* + * Functions to read and write individual registers in a channel. + * The ZS chip requires a 1.6 uSec. recovery time between accesses, + * and the Sun3 hardware does NOT take care of this for you. + * MacII hardware DOES take care of the delay for us. :-) + * XXX - Then these should be inline functions! -gwr + * Some clock-chirped macs lose serial ports. It could be that the + * hardware delay is tied to the CPU speed, and that the minimum delay + * no longer's respected. For them, ZS_DELAY might help. + * XXX - no one seems to want to try and check this -wrs + */ + +u_char zs_read_reg(struct zs_chanstate *cs, u_char reg); +u_char zs_read_csr(struct zs_chanstate *cs); +u_char zs_read_data(struct zs_chanstate *cs); + +void zs_write_reg(struct zs_chanstate *cs, u_char reg, u_char val); +void zs_write_csr(struct zs_chanstate *cs, u_char val); +void zs_write_data(struct zs_chanstate *cs, u_char val); + +/* XXX - Could define splzs() here instead of in psl.h */ +#define splzs spltty + +/* Hook for MD ioctl support */ +int zsmdioctl(struct zs_chanstate *cs, u_long cmd, caddr_t data); +/* XXX - This is a bit gross... */ +/* +#define ZS_MD_IOCTL(cs, cmd, data) zsmdioctl(cs, cmd, data) +*/ + +/* Callback for "external" clock sources */ +void zsmd_setclock(struct zs_chanstate *cs); +#define ZS_MD_SETCLK(cs) zsmd_setclock(cs) + +#define PCLK (9600 * 384) /* PCLK pin input clock rate */ + +/* The layout of this is hardware-dependent (padding, order). */ +struct zschan { + volatile u_char zc_csr; /* ctrl,status, and indirect access */ + u_char zc_xxx0[15]; + volatile u_char zc_data; /* data */ + u_char zc_xxx1[15]; +}; + +#ifndef ZSCCF_CHANNEL +#define ZSCCF_CHANNEL 0 +#define ZSCCF_CHANNEL_DEFAULT -1 +#endif \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/_float.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/_float.h new file mode 100644 index 0000000000..1bf34fd14e --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/_float.h @@ -0,0 +1,3 @@ +/* $OpenBSD: _float.h,v 1.1 2012/06/26 16:12:44 deraadt Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/_types.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/_types.h new file mode 100644 index 0000000000..e896392602 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/_types.h @@ -0,0 +1,4 @@ +/* $OpenBSD: _types.h,v 1.1 2006/01/06 18:50:09 millert Exp $ */ + +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/apmvar.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/apmvar.h new file mode 100644 index 0000000000..4aa7952d46 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/apmvar.h @@ -0,0 +1,122 @@ +/* $OpenBSD: apmvar.h,v 1.10 2019/01/22 02:36:30 phessler Exp $ */ + +/* + * Copyright (c) 2001 Alexander Guy + * Copyright (c) 1995 John T. Kohl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef _MACHINE_APMVAR_H_ +#define _MACHINE_APMVAR_H_ + +#include + +/* Advanced Power Management (v1.0 and v1.1 specification) + * functions/defines/etc. + */ + +/* These definitions make up the heart of the user-land interface + * to the APM devices. + */ + +#define APM_AC_OFF 0x00 +#define APM_AC_ON 0x01 +#define APM_AC_BACKUP 0x02 +#define APM_AC_UNKNOWN 0xff +#define APM_BATT_HIGH 0x00 +#define APM_BATT_LOW 0x01 +#define APM_BATT_CRITICAL 0x02 +#define APM_BATT_CHARGING 0x03 +#define APM_BATT_UNKNOWN 0xff +#define APM_BATT_LIFE_UNKNOWN 0xff + +#define APM_NOEVENT 0x0000 +#define APM_STANDBY_REQ 0x0001 +#define APM_SUSPEND_REQ 0x0002 +#define APM_NORMAL_RESUME 0x0003 +#define APM_CRIT_RESUME 0x0004 /* suspend/resume happened + without us */ +#define APM_BATTERY_LOW 0x0005 +#define APM_POWER_CHANGE 0x0006 +#define APM_UPDATE_TIME 0x0007 +#define APM_CRIT_SUSPEND_REQ 0x0008 +#define APM_USER_STANDBY_REQ 0x0009 +#define APM_USER_SUSPEND_REQ 0x000A +#define APM_SYS_STANDBY_RESUME 0x000B +#define APM_CAPABILITY_CHANGE 0x000C /* apm v1.2 */ +#define APM_USER_HIBERNATE_REQ 0x000D +#define APM_EVENT_MASK 0xffff + +#define APM_EVENT_COMPOSE(t,i) ((((i) & 0x7fff) << 16)|((t) & APM_EVENT_MASK)) +#define APM_EVENT_TYPE(e) ((e) & APM_EVENT_MASK) +#define APM_EVENT_INDEX(e) ((e) >> 16) + +/* + * LP (Laptop Package) + * + * Copyright (C) 1994 by HOSOKAWA Tatsumi + * + * This software may be used, modified, copied, and distributed, in + * both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + */ + +#define APM_BATTERY_ABSENT 4 + +struct apm_power_info { + u_char battery_state; + u_char ac_state; + u_char battery_life; + u_char spare1; + u_int minutes_left; /* estimate */ + u_int spare2[6]; +}; + +struct apm_ctl { + u_int dev; + u_int mode; +}; + +#define APM_IOC_REJECT _IOW('A', 0, struct apm_event_info) /* reject request # */ +#define APM_IOC_STANDBY _IO('A', 1) /* put system into standby */ +#define APM_IOC_SUSPEND _IO('A', 2) /* put system into suspend */ +#define APM_IOC_GETPOWER _IOR('A', 3, struct apm_power_info) /* fetch battery state */ +#define APM_IOC_DEV_CTL _IOW('A', 5, struct apm_ctl) /* put device into mode */ +#define APM_IOC_PRN_CTL _IOW('A', 6, int ) /* driver power status msg */ +#define APM_PRINT_ON 0 /* driver power status displayed */ +#define APM_PRINT_OFF 1 /* driver power status not displayed */ +#define APM_PRINT_PCT 2 /* driver power status only displayed + if the percentage changes */ +#define APM_IOC_STANDBY_REQ _IO('A', 7) /* request standby */ +#define APM_IOC_SUSPEND_REQ _IO('A', 8) /* request suspend */ +#define APM_IOC_HIBERNATE _IO('A', 9) /* put system into hibernate */ + +#endif /* _MACHINE_APMVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/asm.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/asm.h new file mode 100644 index 0000000000..ea7bd91fc3 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/asm.h @@ -0,0 +1,3 @@ +/* $OpenBSD: asm.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/atomic.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/atomic.h new file mode 100644 index 0000000000..bd432ef8ec --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/atomic.h @@ -0,0 +1,10 @@ +/* $OpenBSD: atomic.h,v 1.3 2011/03/23 16:54:36 pirofti Exp $ */ + +/* Public Domain */ + +#ifndef _MACHINE_ATOMIC_H_ +#define _MACHINE_ATOMIC_H_ + +#include + +#endif /* _MACHINE_ATOMIC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/autoconf.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/autoconf.h new file mode 100644 index 0000000000..3ec5c80d9e --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/autoconf.h @@ -0,0 +1,72 @@ +/* $OpenBSD: autoconf.h,v 1.13 2024/05/22 05:51:49 jsg Exp $ */ + +/* + * Copyright (c) 1997 Per Fogelstrom + * + * 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. + * + */ +/* + * Machine-dependent structures of autoconfiguration + */ + +#ifndef _MACHINE_AUTOCONF_H_ +#define _MACHINE_AUTOCONF_H_ + +#include + +struct confargs { + char *ca_name; + bus_space_tag_t ca_iot; + bus_dma_tag_t ca_dmat; + u_int32_t ca_node; + int ca_nreg; + u_int32_t *ca_reg; + int ca_nintr; + int32_t *ca_intr; + u_int ca_baseaddr; + +}; + +int badaddr(void *, u_int32_t); + +typedef int (time_read_t)(time_t *sec); +typedef int (time_write_t)(time_t sec); + +extern time_read_t *time_read; +extern time_write_t *time_write; + +typedef int mac_intr_handle_t; +typedef void *(intr_establish_t)(void *, mac_intr_handle_t, + int, int, int (*func)(void *), void *, const char *); +typedef void (intr_disestablish_t)(void *, void *); +struct cpu_info; +typedef void (intr_send_ipi_t)(struct cpu_info *, int); + +intr_establish_t mac_intr_establish; +intr_disestablish_t mac_intr_disestablish; +extern intr_establish_t *intr_establish_func; +extern intr_disestablish_t *intr_disestablish_func; +extern intr_send_ipi_t *intr_send_ipi_func; + + +#endif /* _MACHINE_AUTOCONF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/bus.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/bus.h new file mode 100644 index 0000000000..0787b68183 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/bus.h @@ -0,0 +1,643 @@ +/* $OpenBSD: bus.h,v 1.27 2024/05/22 05:51:49 jsg Exp $ */ + +/* + * Copyright (c) 1997 Per Fogelstrom. All rights reserved. + * Copyright (c) 1996 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christopher G. Demetriou + * for the NetBSD Project. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MACHINE_BUS_H_ +#define _MACHINE_BUS_H_ + +#include + +#ifdef __STDC__ +#define CAT(a,b) a##b +#define CAT3(a,b,c) a##b##c +#else +#define CAT(a,b) a/**/b +#define CAT3(a,b,c) a/**/b/**/c +#endif + +/* + * Bus access types. + */ +typedef u_long bus_addr_t; +typedef u_long bus_size_t; +typedef u_long bus_space_handle_t; +typedef struct ppc_bus_space *bus_space_tag_t; + +struct ppc_bus_space { + u_int32_t bus_base; + u_int32_t bus_size; + u_int8_t bus_io; /* IO or memory */ +}; +#define POWERPC_BUS_TAG_BASE(x) ((x)->bus_base) + +/* + * Access methods for bus resources + */ +int bus_space_map(bus_space_tag_t t, bus_addr_t addr, + bus_size_t size, int flags, bus_space_handle_t *bshp); +void bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh, + bus_size_t size); +int bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh, + bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp); +int bus_space_alloc(bus_space_tag_t tag, bus_addr_t rstart, + bus_addr_t rend, bus_size_t size, bus_size_t alignment, + bus_size_t boundary, int flags, bus_addr_t *addrp, + bus_space_handle_t *handlep); +void bus_space_free(bus_space_tag_t tag, bus_space_handle_t handle, + bus_size_t size); +paddr_t bus_space_mmap(bus_space_tag_t, bus_addr_t, off_t, int, int); + +#define BUS_SPACE_MAP_CACHEABLE 0x01 +#define BUS_SPACE_MAP_LINEAR 0x02 +#define BUS_SPACE_MAP_PREFETCHABLE 0x04 + +/* + * void *bus_space_vaddr(bus_space_tag_t, bus_space_handle_t); + * + * Get the kernel virtual address for the mapped bus space. + * Only allowed for regions mapped with BUS_SPACE_MAP_LINEAR. + */ +#define bus_space_vaddr(t, h) ((void *)(h)) + +#define bus_space_read(n,m) \ +static __inline CAT3(u_int,m,_t) \ +CAT(bus_space_read_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba) \ +{ \ + return CAT3(in,m,rb)((volatile CAT3(u_int,m,_t) *)(bsh + (ba))); \ +} + +bus_space_read(1,8) +bus_space_read(2,16) +bus_space_read(4,32) + +#define bus_space_read_8 !!! bus_space_read_8 unimplemented !!! + +#define bus_space_write(n,m) \ +static __inline void \ +CAT(bus_space_write_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, CAT3(u_int,m,_t) x) \ +{ \ + CAT3(out,m,rb)((volatile CAT3(u_int,m,_t) *)(bsh + (ba)), x); \ +} + +bus_space_write(1,8) +bus_space_write(2,16) +bus_space_write(4,32) + +#define bus_space_write_8 !!! bus_space_write_8 unimplemented !!! + +#define bus_space_read_raw(n,m) \ +static __inline CAT3(u_int,m,_t) \ +CAT(bus_space_read_raw_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba) \ +{ \ + return CAT(in,m)((volatile CAT3(u_int,m,_t) *)(bsh + (ba))); \ +} + +bus_space_read_raw(1,8) +bus_space_read_raw(2,16) +bus_space_read_raw(4,32) + +#define bus_space_read_raw_8 !!! bus_space_read_raw_8 unimplemented !!! + +#define bus_space_write_raw(n,m) \ +static __inline void \ +CAT(bus_space_write_raw_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, CAT3(u_int,m,_t) x) \ +{ \ + CAT(out,m)((volatile CAT3(u_int,m,_t) *)(bsh + (ba)), x); \ +} + +bus_space_write_raw(1,8) +bus_space_write_raw(2,16) +bus_space_write_raw(4,32) + +#define bus_space_write_raw_8 !!! bus_space_write_raw_8 unimplemented !!! + +#define bus_space_read_multi(n, m) \ +static __inline void \ +CAT(bus_space_read_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_size_t ba, CAT3(u_int,m,_t) *buf, bus_size_t cnt) \ +{ \ + while (cnt--) \ + *buf++ = CAT(bus_space_read_,n)(bst, bsh, ba); \ +} + +bus_space_read_multi(1,8) +bus_space_read_multi(2,16) +bus_space_read_multi(4,32) + +#define bus_space_read_multi_8 !!! bus_space_read_multi_8 not implemented !!! + + +#define bus_space_write_multi_8 !!! bus_space_write_multi_8 not implemented !!! + +#define bus_space_write_multi(n, m) \ +static __inline void \ +CAT(bus_space_write_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_size_t ba, const CAT3(u_int,m,_t) *buf, bus_size_t cnt) \ +{ \ + while (cnt--) \ + CAT(bus_space_write_,n)(bst, bsh, ba, *buf++); \ +} + +bus_space_write_multi(1,8) +bus_space_write_multi(2,16) +bus_space_write_multi(4,32) + +#define bus_space_write_multi_8 !!! bus_space_write_multi_8 not implemented !!! + +/* + * void bus_space_read_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_intN_t *addr, size_t count); + * + * Read `count' 1, 2, 4, or 8 byte quantities from bus space + * described by tag/handle and starting at `offset' and copy into + * buffer provided. + */ +#define __BA(t, h, o) ((void *)((h) + (o))) + +static __inline void +bus_space_read_region_1(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int8_t *addr, size_t count) +{ + volatile u_int8_t *s = __BA(tag, bsh, offset); + + while (count--) + *addr++ = *s++; + __asm volatile("eieio; sync"); +} + +static __inline void +bus_space_read_region_2(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int16_t *addr, size_t count) +{ + volatile u_int16_t *s = __BA(tag, bsh, offset); + + while (count--) + __asm volatile("lhbrx %0, 0, %1" : + "=r"(*addr++) : "r"(s++)); + __asm volatile("eieio; sync"); +} + +static __inline void +bus_space_read_region_4(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int32_t *addr, size_t count) +{ + volatile u_int32_t *s = __BA(tag, bsh, offset); + + while (count--) + __asm volatile("lwbrx %0, 0, %1" : + "=r"(*addr++) : "r"(s++)); + __asm volatile("eieio; sync"); +} + +#if 0 /* Cause a link error for bus_space_read_region_8 */ +#define bus_space_read_region_8 !!! unimplemented !!! +#endif + + +/* + * void bus_space_write_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * const u_intN_t *addr, size_t count); + * + * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided + * to bus space described by tag/handle starting at `offset'. + */ + +static __inline void +bus_space_write_region_1(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, const u_int8_t *addr, size_t count) +{ + volatile u_int8_t *d = __BA(tag, bsh, offset); + + while (count--) + *d++ = *addr++; + __asm volatile("eieio; sync"); +} + +static __inline void +bus_space_write_region_2(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, const u_int16_t *addr, size_t count) +{ + volatile u_int16_t *d = __BA(tag, bsh, offset); + + while (count--) + __asm volatile("sthbrx %0, 0, %1" :: + "r"(*addr++), "r"(d++)); + __asm volatile("eieio; sync"); +} + +static __inline void +bus_space_write_region_4(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, const u_int32_t *addr, size_t count) +{ + volatile u_int32_t *d = __BA(tag, bsh, offset); + + while (count--) + __asm volatile("stwbrx %0, 0, %1" :: + "r"(*addr++), "r"(d++)); + __asm volatile("eieio; sync"); +} + +#if 0 +#define bus_space_write_region_8 !!! bus_space_write_region_8 unimplemented !!! +#endif + +/* + * void bus_space_read_raw_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_intN_t *addr, size_t count); + * + * Read `count' bytes from bus space described by tag/handle and starting + * at `offset' and copy into buffer provided w/o bus-host byte swapping. + */ + +static __inline void +bus_space_read_raw_region_2(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int8_t *addr, size_t count) +{ + volatile u_int16_t *s = __BA(tag, bsh, offset); + u_int16_t *laddr = (void *)addr; + + count = count >> 1; + + while (count--) + *laddr++ = *s++; + __asm volatile("eieio; sync"); +} + +static __inline void +bus_space_read_raw_region_4(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int8_t *addr, size_t count) +{ + volatile u_int32_t *s = __BA(tag, bsh, offset); + u_int32_t *laddr = (void *)addr; + + count = count >> 2; + + while (count--) + *laddr++ = *s++; + __asm volatile("eieio; sync"); +} + +#if 0 /* Cause a link error for bus_space_read_raw_region_8 */ +#define bus_space_read_raw_region_8 \ + !!! bus_space_read_raw_region_8 unimplemented !!! +#endif + + +/* + * void bus_space_write_raw_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * const u_intN_t *addr, size_t count); + * + * Write `count' bytes from the buffer provided to bus space described + * by tag/handle starting at `offset' w/o host-bus byte swapping. + */ + +static __inline void +bus_space_write_raw_region_2(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, const u_int8_t *addr, size_t count) +{ + volatile u_int16_t *d = __BA(tag, bsh, offset); + const u_int16_t *laddr = (void *)addr; + + count = count >> 1; + + while (count--) + *d++ = *laddr++; + __asm volatile("eieio; sync"); +} + +static __inline void +bus_space_write_raw_region_4(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, const u_int8_t *addr, size_t count) +{ + volatile u_int32_t *d = __BA(tag, bsh, offset); + const u_int32_t *laddr = (void *)addr; + + count = count >> 2; + + while (count--) + *d++ = *laddr++; + __asm volatile("eieio; sync"); +} + +#if 0 +#define bus_space_write_raw_region_8 \ + !!! bus_space_write_raw_region_8 unimplemented !!! +#endif + +/* + * void bus_space_set_multi_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, u_intN_t val, + * size_t count); + * + * Write the 1, 2, 4, or 8 byte value `val' to bus space described + * by tag/handle/offset `count' times. + */ +static __inline void bus_space_set_multi_1(bus_space_tag_t, + bus_space_handle_t, bus_size_t, u_int8_t, size_t); +static __inline void bus_space_set_multi_2(bus_space_tag_t, + bus_space_handle_t, bus_size_t, u_int16_t, size_t); +static __inline void bus_space_set_multi_4(bus_space_tag_t, + bus_space_handle_t, bus_size_t, u_int32_t, size_t); + +static __inline void +bus_space_set_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int8_t val, size_t count) +{ + volatile u_int8_t *d = __BA(tag, bsh, offset); + + while (count--) + *d = val; + __asm__ volatile("eieio; sync"); +} + +static __inline void +bus_space_set_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int16_t val, size_t count) +{ + volatile u_int16_t *d = __BA(tag, bsh, offset); + + while (count--) + __asm__ volatile("sthbrx %0, 0, %1" :: + "r"(val), "r"(d)); + __asm__ volatile("eieio; sync"); +} + +static __inline void +bus_space_set_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh, + bus_size_t offset, u_int32_t val, size_t count) +{ + volatile u_int32_t *d = __BA(tag, bsh, offset); + + while (count--) + __asm__ volatile("stwbrx %0, 0, %1" :: + "r"(val), "r"(d)); + __asm__ volatile("eieio; sync"); +} + +#define bus_space_set_multi_8 !!! bus_space_set_multi_8 unimplemented !!! + +/* These are OpenBSD extensions to the general NetBSD bus interface. */ +void +bus_space_read_raw_multi_2(bus_space_tag_t bst, bus_space_handle_t bsh, + bus_addr_t ba, u_int8_t *dst, bus_size_t size); +void +bus_space_read_raw_multi_4(bus_space_tag_t bst, bus_space_handle_t bsh, + bus_addr_t ba, u_int8_t *dst, bus_size_t size); +#define bus_space_read_raw_multi_8 \ + !!! bus_space_read_raw_multi_8 not implemented !!! + +void +bus_space_write_raw_multi_2(bus_space_tag_t bst, bus_space_handle_t bsh, + bus_addr_t ba, const u_int8_t *src, bus_size_t size); +void +bus_space_write_raw_multi_4(bus_space_tag_t bst, bus_space_handle_t bsh, + bus_addr_t ba, const u_int8_t *src, bus_size_t size); +#define bus_space_write_raw_multi_8 \ + !!! bus_space_write_raw_multi_8 not implemented !!! + +void +bus_space_set_region_1(bus_space_tag_t bst, bus_space_handle_t h, bus_size_t o, + u_int8_t val, bus_size_t c); +void +bus_space_set_region_2(bus_space_tag_t bst, bus_space_handle_t h, bus_size_t o, + u_int16_t val, bus_size_t c); +void +bus_space_set_region_4(bus_space_tag_t bst, bus_space_handle_t h, bus_size_t o, + u_int32_t val, bus_size_t c); +#define bus_space_set_region_8 \ + !!! bus_space_set_region_8 not implemented !!! + +void +bus_space_copy_1(void *v, bus_space_handle_t h1, bus_space_handle_t h2, + bus_size_t o1, bus_size_t o2, bus_size_t c); +void +bus_space_copy_2(void *v, bus_space_handle_t h1, bus_space_handle_t h2, + bus_size_t o1, bus_size_t o2, bus_size_t c); +void +bus_space_copy_4(void *v, bus_space_handle_t h1, bus_space_handle_t h2, + bus_size_t o1, bus_size_t o2, bus_size_t c); +#define bus_space_copy_8 \ + !!! bus_space_copy_8 not implemented !!! + +/* + * Bus read/write barrier methods. + * + * void bus_space_barrier(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * bus_size_t len, int flags); + * + * Note: powerpc does not currently implement barriers, but we must + * provide the flags to MI code. + * the processor does have eieio which is effectively the barrier + * operator, however due to how memory is mapped this should? not + * be required. + */ +#define bus_space_barrier(t, h, o, l, f) \ + ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f))) +#define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */ +#define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */ + +#define BUS_DMA_WAITOK 0x0000 /* safe to sleep (pseudo-flag) */ +#define BUS_DMA_NOWAIT 0x0001 /* not safe to sleep */ +#define BUS_DMA_ALLOCNOW 0x0002 /* perform resource allocation now */ +#define BUS_DMA_COHERENT 0x0008 /* hint: map memory DMA coherent */ +#define BUS_DMA_BUS1 0x0010 /* placeholders for bus functions... */ +#define BUS_DMA_BUS2 0x0020 +#define BUS_DMA_BUS3 0x0040 +#define BUS_DMA_BUS4 0x0080 +#define BUS_DMA_READ 0x0100 /* mapping is device -> memory only */ +#define BUS_DMA_WRITE 0x0200 /* mapping is memory -> device only */ +#define BUS_DMA_STREAMING 0x0400 /* hint: sequential, unidirectional */ +#define BUS_DMA_ZERO 0x0800 /* zero memory in dmamem_alloc */ +#define BUS_DMA_NOCACHE 0x1000 /* map memory uncached */ +#define BUS_DMA_64BIT 0x2000 /* device handles 64bit dva */ + + +/* Forwards needed by prototypes below. */ +struct mbuf; +struct proc; +struct uio; + +#define BUS_DMASYNC_POSTREAD 0x01 +#define BUS_DMASYNC_POSTWRITE 0x02 +#define BUS_DMASYNC_PREREAD 0x04 +#define BUS_DMASYNC_PREWRITE 0x08 + +typedef struct powerpc_bus_dma_tag *bus_dma_tag_t; +typedef struct powerpc_bus_dmamap *bus_dmamap_t; + +/* + * bus_dma_segment_t + * + * Describes a single contiguous DMA transaction. Values + * are suitable for programming into DMA registers. + */ +struct powerpc_bus_dma_segment { + bus_addr_t ds_addr; /* DMA address */ + bus_size_t ds_len; /* length of transfer */ +}; +typedef struct powerpc_bus_dma_segment bus_dma_segment_t; + +/* + * bus_dma_tag_t + * + * A machine-dependent opaque type describing the implementation of + * DMA for a given bus. + */ + +struct powerpc_bus_dma_tag { + void *_cookie; /* cookie used in the guts */ + + /* + * DMA mapping methods. + */ + int (*_dmamap_create)(bus_dma_tag_t , bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); + void (*_dmamap_destroy)(bus_dma_tag_t , bus_dmamap_t); + int (*_dmamap_load)(bus_dma_tag_t , bus_dmamap_t, void *, + bus_size_t, struct proc *, int); + int (*_dmamap_load_mbuf)(bus_dma_tag_t , bus_dmamap_t, + struct mbuf *, int); + int (*_dmamap_load_uio)(bus_dma_tag_t , bus_dmamap_t, + struct uio *, int); + int (*_dmamap_load_raw)(bus_dma_tag_t , bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); + void (*_dmamap_unload)(bus_dma_tag_t , bus_dmamap_t); + void (*_dmamap_sync)(bus_dma_tag_t , bus_dmamap_t, + bus_addr_t, bus_size_t, int); + + /* + * DMA memory utility functions. + */ + int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); + int (*_dmamem_alloc_range)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int, + bus_addr_t, bus_addr_t); + void (*_dmamem_free)(bus_dma_tag_t, bus_dma_segment_t *, int); + int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); + void (*_dmamem_unmap)(bus_dma_tag_t, caddr_t, size_t); + paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *, + int, off_t, int, int); +}; + +#define bus_dmamap_create(t, s, n, m, b, f, p) \ + (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p)) +#define bus_dmamap_destroy(t, p) \ + (*(t)->_dmamap_destroy)((t), (p)) +#define bus_dmamap_load(t, m, b, s, p, f) \ + (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f)) +#define bus_dmamap_load_mbuf(t, m, b, f) \ + (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f)) +#define bus_dmamap_load_uio(t, m, u, f) \ + (*(t)->_dmamap_load_uio)((t), (m), (u), (f)) +#define bus_dmamap_load_raw(t, m, sg, n, s, f) \ + (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f)) +#define bus_dmamap_unload(t, p) \ + (*(t)->_dmamap_unload)((t), (p)) +#define bus_dmamap_sync(t, p, a, l, o) \ + (void)((t)->_dmamap_sync ? \ + (*(t)->_dmamap_sync)((t), (p), (a), (l), (o)) : (void)0) + +#define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \ + (*(t)->_dmamem_alloc)((t)->_cookie, (s), (a), (b), (sg), (n), (r), (f)) +#define bus_dmamem_alloc_range(t, s, a, b, sg, n, r, f, l, h) \ + (*(t)->_dmamem_alloc_range)((t), (s), (a), (b), (sg), \ + (n), (r), (f), (l), (h)) +#define bus_dmamem_free(t, sg, n) \ + (*(t)->_dmamem_free)((t)->_cookie, (sg), (n)) +#define bus_dmamem_map(t, sg, n, s, k, f) \ + (*(t)->_dmamem_map)((t)->_cookie, (sg), (n), (s), (k), (f)) +#define bus_dmamem_unmap(t, k, s) \ + (*(t)->_dmamem_unmap)((t)->_cookie, (k), (s)) +#define bus_dmamem_mmap(t, sg, n, o, p, f) \ + (*(t)->_dmamem_mmap)((t)->_cookie, (sg), (n), (o), (p), (f)) + +int _dmamap_create(bus_dma_tag_t, bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); +void _dmamap_destroy(bus_dma_tag_t, bus_dmamap_t); +int _dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int); +int _dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, struct mbuf *, int); +int _dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, struct uio *, int); +int _dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); +void _dmamap_unload(bus_dma_tag_t, bus_dmamap_t); +void _dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, bus_size_t, + int); + +int _dmamem_alloc(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); +int _dmamem_alloc_range( bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int, + bus_addr_t, bus_addr_t); +void _dmamem_free(bus_dma_tag_t, bus_dma_segment_t *, int); +int _dmamem_map(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); +void _dmamem_unmap(bus_dma_tag_t, caddr_t, size_t); +paddr_t _dmamem_mmap(bus_dma_tag_t, bus_dma_segment_t *, int, off_t, int, int); + +/* + * bus_dmamap_t + * + * Describes a DMA mapping. + */ +struct powerpc_bus_dmamap { + /* + * PRIVATE MEMBERS: not for use by machine-independent code. + */ + bus_size_t _dm_size; /* largest DMA transfer mappable */ + int _dm_segcnt; /* number of segs this map can map */ + bus_size_t _dm_maxsegsz; /* largest possible segment */ + bus_size_t _dm_boundary; /* don't cross this */ + int _dm_flags; /* misc. flags */ + + void *_dm_cookie; /* cookie for bus-specific functions */ + + /* + * PUBLIC MEMBERS: these are used by machine-independent code. + */ + bus_size_t dm_mapsize; /* size of the mapping */ + int dm_nsegs; /* # valid segments in mapping */ + bus_dma_segment_t dm_segs[1]; /* segments; variable length */ +}; + +#endif /* _MACHINE_BUS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/cdefs.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/cdefs.h new file mode 100644 index 0000000000..4e15edb0a4 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/cdefs.h @@ -0,0 +1,3 @@ +/* $OpenBSD: cdefs.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/conf.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/conf.h new file mode 100644 index 0000000000..370b2c67c5 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/conf.h @@ -0,0 +1,56 @@ +/* $OpenBSD: conf.h,v 1.15 2022/06/28 14:43:50 visa Exp $ */ +/* $NetBSD: conf.h,v 1.2 1996/05/05 19:28:34 christos Exp $ */ + +/* + * Copyright (c) 1996 Christos Zoulas. 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 Christos Zoulas. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#define mmread mmrw +#define mmwrite mmrw +cdev_decl(mm); + +/* open, close, write, ioctl, kqueue */ +#define cdev_apm_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,n,kqfilter) } + +cdev_decl(apm); +cdev_decl(zs); + +/* open, close, ioctl */ +#define cdev_openprom_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) nullop, 0, \ + (dev_type_mmap((*))) enodev } + +cdev_decl(openprom); \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/cpu.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/cpu.h new file mode 100644 index 0000000000..9b938b2a8d --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/cpu.h @@ -0,0 +1,76 @@ +/* $OpenBSD: cpu.h,v 1.15 2022/10/21 22:42:36 gkoehler Exp $ */ +/* $NetBSD: cpu.h,v 1.1 1996/09/30 16:34:21 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. + */ +#ifndef _MACHINE_CPU_H_ +#define _MACHINE_CPU_H_ + +/* + * CTL_MACHDEP definitions. + */ +#define CPU_ALLOWAPERTURE 1 /* allow mmap of /dev/xf86 */ +#define CPU_ALTIVEC 2 /* altivec is present */ +#define CPU_LIDACTION 3 /* action caused by lid close */ +#define CPU_PWRACTION 4 /* action caused by power button */ +#define CPU_MAXID 5 /* number of valid machdep ids */ + +#define CTL_MACHDEP_NAMES { \ + { 0, 0 }, \ + { "allowaperture", CTLTYPE_INT }, \ + { "altivec", CTLTYPE_INT }, \ + { "lidaction", CTLTYPE_INT }, \ + { "pwraction", CTLTYPE_INT }, \ +} + +#ifdef _KERNEL + +#include + +/* Frequency scaling */ +#define FREQ_FULL 0 +#define FREQ_HALF 1 +#define FREQ_QUARTER 2 /* Supported only on IBM 970MP */ + +extern u_int32_t ppc_curfreq; +extern u_int32_t ppc_maxfreq; +extern int ppc_altivec; + +extern void (*ppc64_slew_voltage)(u_int); + +extern u_int32_t ticks_per_sec; +extern u_int32_t ns_per_tick; + +extern int lid_action; +extern int pwr_action; + +#endif /* _KERNEL */ +#endif /* _MACHINE_CPU_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/db_machdep.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/db_machdep.h new file mode 100644 index 0000000000..525dade241 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/db_machdep.h @@ -0,0 +1,3 @@ +/* $OpenBSD: db_machdep.h,v 1.7 2016/03/05 17:41:55 mpi Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/disklabel.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/disklabel.h new file mode 100644 index 0000000000..aca83dc5eb --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/disklabel.h @@ -0,0 +1,90 @@ +/* $OpenBSD: disklabel.h,v 1.16 2015/09/30 15:13:54 krw Exp $ */ + +/* + * Copyright (c) 1994 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 _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 */ + +/* HFS/DPME */ + +/* partition map structure from Inside Macintosh: Devices, SCSI Manager + * pp. 13-14. The partition map always begins on physical block 1. + * + * With the exception of block 0, all blocks on the disk must belong to + * exactly one partition. The partition map itself belongs to a partition + * of type `APPLE_PARTITION_MAP', and is not limited in size by anything + * other than available disk space. The partition map is not necessarily + * the first partition listed. + */ +struct part_map_entry { +#define PART_ENTRY_MAGIC 0x504d + u_int16_t pmSig; /* partition signature */ + u_int16_t pmSigPad; /* (reserved) */ + u_int32_t pmMapBlkCnt; /* number of blocks in partition map */ + u_int32_t pmPyPartStart; /* first physical block of partition */ + u_int32_t pmPartBlkCnt; /* number of blocks in partition */ + char pmPartName[32]; /* partition name */ + char pmPartType[32]; /* partition type */ + u_int32_t pmLgDataStart; /* first logical block of data area */ + u_int32_t pmDataCnt; /* number of blocks in data area */ + u_int32_t pmPartStatus; /* partition status information */ + u_int32_t pmLgBootStart; /* first logical block of boot code */ + u_int32_t pmBootSize; /* size of boot code, in bytes */ + u_int32_t pmBootLoad; /* boot code load address */ + u_int32_t pmBootLoad2; /* (reserved) */ + u_int32_t pmBootEntry; /* boot code entry point */ + u_int32_t pmBootEntry2; /* (reserved) */ + u_int32_t pmBootCksum; /* boot code checksum */ + char pmProcessor[16]; /* processor type (e.g. "68020") */ + u_int8_t pmBootArgs[128]; /* A/UX boot arguments */ + /* we do not index the disk image as an array, + * leave out the on disk padding + */ +#if 0 + u_int8_t pad[248]; /* pad to end of block */ +#endif +}; + +#define PART_TYPE_DRIVER "APPLE_DRIVER" +#define PART_TYPE_DRIVER43 "APPLE_DRIVER43" +#define PART_TYPE_DRIVERATA "APPLE_DRIVER_ATA" +#define PART_TYPE_DRIVERIOKIT "APPLE_DRIVER_IOKIT" +#define PART_TYPE_FWDRIVER "APPLE_FWDRIVER" +#define PART_TYPE_FWB_COMPONENT "FWB DRIVER COMPONENTS" +#define PART_TYPE_FREE "APPLE_FREE" +#define PART_TYPE_MAC "APPLE_HFS" +#define PART_TYPE_OPENBSD "OPENBSD" + +#endif /* _MACHINE_DISKLABEL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/elf.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/elf.h new file mode 100644 index 0000000000..ed920f5d1e --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/elf.h @@ -0,0 +1,3 @@ +/* $OpenBSD: elf.h,v 1.1 2024/07/14 19:33:59 miod Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/endian.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/endian.h new file mode 100644 index 0000000000..4bc2fa0df5 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/endian.h @@ -0,0 +1,3 @@ +/* $OpenBSD: endian.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/exec.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/exec.h new file mode 100644 index 0000000000..b283c6dd5f --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/exec.h @@ -0,0 +1,3 @@ +/* $OpenBSD: exec.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/fenv.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/fenv.h new file mode 100644 index 0000000000..63244974f9 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/fenv.h @@ -0,0 +1,3 @@ +/* $OpenBSD: fenv.h,v 1.2 2013/06/01 21:20:54 jasper Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/fpu.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/fpu.h new file mode 100644 index 0000000000..b3c92c2976 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/fpu.h @@ -0,0 +1,3 @@ +/* $OpenBSD: fpu.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/frame.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/frame.h new file mode 100644 index 0000000000..9edae57f95 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/frame.h @@ -0,0 +1,3 @@ +/* $OpenBSD: frame.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/ieee.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/ieee.h new file mode 100644 index 0000000000..46e05aeea4 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/ieee.h @@ -0,0 +1,3 @@ +/* $OpenBSD: ieee.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/ieeefp.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/ieeefp.h new file mode 100644 index 0000000000..d42b97756f --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/ieeefp.h @@ -0,0 +1,3 @@ +/* $OpenBSD: ieeefp.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/intr.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/intr.h new file mode 100644 index 0000000000..e1a6b65ddc --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/intr.h @@ -0,0 +1,10 @@ +/* $OpenBSD: intr.h,v 1.9 2014/04/01 20:27:14 mpi Exp $ */ + +#include + +#ifndef _LOCORE +extern int intr_shared_edge; + +void install_extint(void (*handler)(void)); +void openpic_set_priority(int, int); +#endif \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/kcore.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/kcore.h new file mode 100644 index 0000000000..0f3da93e38 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/kcore.h @@ -0,0 +1,3 @@ +/* $OpenBSD: kcore.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/limits.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/limits.h new file mode 100644 index 0000000000..3b2a85e186 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/limits.h @@ -0,0 +1,3 @@ +/* $OpenBSD: limits.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/loadfile_machdep.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/loadfile_machdep.h new file mode 100644 index 0000000000..5ec3bc68fa --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/loadfile_machdep.h @@ -0,0 +1,49 @@ +/* $OpenBSD: loadfile_machdep.h,v 1.4 2015/07/17 20:44:39 miod Exp $ */ +/* $NetBSD: loadfile_machdep.h,v 1.1 1999/04/29 03:17:12 tsubai Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * 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. + */ + +#define BOOT_ELF +#define ELFSIZE 32 + +#define LOAD_KERNEL LOAD_ALL +#define COUNT_KERNEL COUNT_ALL + +#define LOADADDR(a) (((u_long)(a)) + offset) +#define ALIGNENTRY(a) ((u_long)(a)) +#define READ(f, b, c) read((f), (void *)LOADADDR(b), (c)) +#define BCOPY(s, d, c) memcpy((void *)LOADADDR(d), (void *)(s), (c)) +#define BZERO(d, c) memset((void *)LOADADDR(d), 0, (c)) +#define WARN(a) (void)(printf a, \ + printf((errno ? ": %s\n" : "\n"), \ + strerror(errno))) +#define PROGRESS(a) (void) printf a +#define ALLOC(a) alloc(a) +#define FREE(a, b) free(a, b) \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/mplock.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/mplock.h new file mode 100644 index 0000000000..7e82ab4902 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/mplock.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mplock.h,v 1.3 2015/06/26 11:15:32 dlg Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/mutex.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/mutex.h new file mode 100644 index 0000000000..06bd20011d --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/mutex.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mutex.h,v 1.1 2007/03/22 19:26:28 kettenis Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/openpromio.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/openpromio.h new file mode 100644 index 0000000000..1b69c531fe --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/openpromio.h @@ -0,0 +1,57 @@ +/* $OpenBSD: openpromio.h,v 1.1 2007/11/12 19:23:26 kettenis Exp $ */ +/* $NetBSD: openpromio.h,v 1.1.1.1 1998/06/20 04:58:52 eeh Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)openpromio.h 8.1 (Berkeley) 6/11/93 + */ + +struct opiocdesc { + int op_nodeid; /* passed or returned node id */ + int op_namelen; /* length of op_name */ + char *op_name; /* pointer to field name */ + int op_buflen; /* length of op_buf (value-result) */ + char *op_buf; /* pointer to field value */ +}; + +#define OPIOCGET _IOWR('O', 1, struct opiocdesc) /* get openprom field */ +#define OPIOCSET _IOW('O', 2, struct opiocdesc) /* set openprom field */ +#define OPIOCNEXTPROP _IOWR('O', 3, struct opiocdesc) /* get next property */ +#define OPIOCGETOPTNODE _IOR('O', 4, int) /* get openprom field */ +#define OPIOCGETNEXT _IOWR('O', 5, int) /* get next node of node */ +#define OPIOCGETCHILD _IOWR('O', 6, int) /* get first child of node */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/param.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/param.h new file mode 100644 index 0000000000..1aeadbe686 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/param.h @@ -0,0 +1,52 @@ +/* $OpenBSD: param.h,v 1.6 2014/04/07 16:29:06 deraadt 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 _MACHINE_PARAM_H_ +#define _MACHINE_PARAM_H_ + +#ifdef _KERNEL +#ifndef _LOCORE +#include +#endif /* _LOCORE */ +#endif + +#include + +#define MACHINE "macppc" +#define _MACHINE macppc + +#define KERNBASE 0x100000 + +#define MSGBUFSIZE (4 * PAGE_SIZE) + +#endif /* _MACHINE_PARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/pcb.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/pcb.h new file mode 100644 index 0000000000..ae453583b2 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/pcb.h @@ -0,0 +1,3 @@ +/* $OpenBSD: pcb.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/pci_machdep.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/pci_machdep.h new file mode 100644 index 0000000000..443fe240af --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/pci_machdep.h @@ -0,0 +1,108 @@ +/* $OpenBSD: pci_machdep.h,v 1.4 2019/12/05 12:46:54 mpi Exp $ */ +/* $NetBSD: pci_machdep.h,v 1.7 2001/07/20 00:07:14 eeh Exp $ */ + +/* + * Copyright (c) 1999 Matthew R. Green + * 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_PCI_MACHDEP_H_ +#define _MACHINE_PCI_MACHDEP_H_ + +extern struct powerpc_bus_dma_tag pci_bus_dma_tag; + +/* + * Forward declarations. + */ +struct pci_attach_args; + +/* + * define some bits used to glue into the common PCI code. + */ + +typedef struct ppc_pci_chipset *pci_chipset_tag_t; + +typedef unsigned long pci_intr_handle_t; + +/* + * The stuuuuuuupid allegedly MI PCI code expects pcitag_t to be a + * scalar type. But we really need to store both the OFW node and + * the bus/device/function info in it. (We'd like to store more, + * like all the ofw properties, but we don't need to.) Luckily, + * both are 32-bit values, so we can squeeze them into a u_int64_t + * with a little help from some macros. + */ + +#define PCITAG_NODE(x) (int)(((x)>>32)&0xffffffff) +#define PCITAG_OFFSET(x) ((x)&0xffffffff) +#define PCITAG_BUS(t) ((PCITAG_OFFSET(t)>>16)&0xff) +#define PCITAG_DEV(t) ((PCITAG_OFFSET(t)>>11)&0x1f) +#define PCITAG_FUN(t) ((PCITAG_OFFSET(t)>>8)&0x7) +#define PCITAG_CREATE(n,b,d,f) (((uint64_t)(n)<<32)|((b)<<16)|((d)<<11)|((f)<<8)) +typedef uint64_t pcitag_t; + +struct ppc_pci_chipset { + void *pc_conf_v; + int pc_node; + int busnode[256]; + + pcireg_t (*pc_conf_read)(void *, pcitag_t, int); + void (*pc_conf_write)(void *, pcitag_t, int, pcireg_t); +}; + + +void pci_attach_hook(struct device *, struct device *, + struct pcibus_attach_args *); +int pci_bus_maxdevs(pci_chipset_tag_t, int); +pcitag_t pci_make_tag(pci_chipset_tag_t, int, int, int); +void pci_decompose_tag(pci_chipset_tag_t, pcitag_t, int *, int *, + int *); +int pci_conf_size(pci_chipset_tag_t, pcitag_t); +pcireg_t pci_conf_read(pci_chipset_tag_t, pcitag_t, int); +void pci_conf_write(pci_chipset_tag_t, pcitag_t, int, pcireg_t); +int pci_intr_map(struct pci_attach_args *, pci_intr_handle_t *); +int pci_intr_map_msi(struct pci_attach_args *, pci_intr_handle_t *); +#define pci_intr_map_msix(p, vec, ihp) (-1) +int pci_intr_line(pci_chipset_tag_t, pci_intr_handle_t); +const char *pci_intr_string(pci_chipset_tag_t, pci_intr_handle_t); +void *pci_intr_establish(pci_chipset_tag_t, pci_intr_handle_t, + int, int (*)(void *), void *, const char *); +void pci_intr_disestablish(pci_chipset_tag_t, void *); +int pci_ether_hw_addr(pci_chipset_tag_t, uint8_t *); + +#define pci_probe_device_hook(c, a) (0) + +#define pci_min_powerstate(c, t) (PCI_PMCSR_STATE_D3) +#define pci_set_powerstate_md(c, t, s, p) + +#define pci_dev_postattach(a, b) + +int ofw_intr_map(int, uint32_t *, uint32_t *); +int ofw_enumerate_pcibus(struct pci_softc *, + int (*match)(struct pci_attach_args *), + struct pci_attach_args *); + +#define PCI_MACHDEP_ENUMERATE_BUS ofw_enumerate_pcibus + +#endif /* _MACHINE_PCI_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/pio.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/pio.h new file mode 100644 index 0000000000..551a29a603 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/pio.h @@ -0,0 +1,3 @@ +/* $OpenBSD: pio.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/pmap.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/pmap.h new file mode 100644 index 0000000000..3bff9d0214 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/pmap.h @@ -0,0 +1,3 @@ +/* $OpenBSD: pmap.h,v 1.5 2005/11/07 02:19:46 brad Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/proc.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/proc.h new file mode 100644 index 0000000000..9fb584cd31 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/proc.h @@ -0,0 +1,3 @@ +/* $OpenBSD: proc.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/profile.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/profile.h new file mode 100644 index 0000000000..6ef4ef31dd --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/profile.h @@ -0,0 +1,3 @@ +/* $OpenBSD: profile.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/psl.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/psl.h new file mode 100644 index 0000000000..75712e28fa --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/psl.h @@ -0,0 +1,3 @@ +/* $OpenBSD: psl.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/pte.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/pte.h new file mode 100644 index 0000000000..effc458c15 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/pte.h @@ -0,0 +1,3 @@ +/* $OpenBSD: pte.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/ptrace.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/ptrace.h new file mode 100644 index 0000000000..8853814e4c --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/ptrace.h @@ -0,0 +1,3 @@ +/* $OpenBSD: ptrace.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/rbus_machdep.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/rbus_machdep.h new file mode 100644 index 0000000000..1c0cb27000 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/rbus_machdep.h @@ -0,0 +1,62 @@ +/* $OpenBSD: rbus_machdep.h,v 1.6 2011/03/23 16:54:36 pirofti Exp $ */ +/* $NetBSD: rbus_machdep.h,v 1.2 1999/10/15 06:43:05 haya Exp $ */ + +/* + * Copyright (c) 1999 + * HAYAKAWA Koichi. 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. + */ + + +#if !defined _MACHINE_RBUS_MACHDEP_H_ +#define _MACHINE_RBUS_MACHDEP_H_ + +struct pci_attach_args; /* XXX */ + +void _bus_space_unmap(bus_space_tag_t, bus_space_handle_t, + bus_size_t, bus_addr_t *); + +#define md_space_map(rbt, physaddr, size, flags, bshp) \ + bus_space_map((rbt)->rb_bt, (physaddr), (size), (flags), (bshp)) + +/* XXX */ +bus_addr_t bus_space_unmap_p(bus_space_tag_t t, bus_space_handle_t bsh, + bus_size_t size); + + +#define md_space_unmap(rbt, bsh, size, adrp) \ + do { \ + *adrp = bus_space_unmap_p((rbt)->rb_bt, (bsh), (size)); \ + if ((rbt)->rb_bt->bus_io) { \ + *adrp = *adrp & 0xffff; \ + } \ + } while (0) + +rbus_tag_t rbus_pccbb_parent_io(struct device *self, + struct pci_attach_args *pa); +rbus_tag_t rbus_pccbb_parent_mem(struct device *self, + struct pci_attach_args *pa); + +void pccbb_attach_hook(struct device *, struct device *, + struct pci_attach_args *); + +#endif /* _MACHINE_RBUS_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/reg.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/reg.h new file mode 100644 index 0000000000..8162e439ce --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/reg.h @@ -0,0 +1,3 @@ +/* $OpenBSD: reg.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/reloc.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/reloc.h new file mode 100644 index 0000000000..faca641c79 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/reloc.h @@ -0,0 +1,3 @@ +/* $OpenBSD: reloc.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/setjmp.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/setjmp.h new file mode 100644 index 0000000000..da9cc287b3 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/setjmp.h @@ -0,0 +1,3 @@ +/* $OpenBSD: setjmp.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/signal.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/signal.h new file mode 100644 index 0000000000..fc14275006 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/signal.h @@ -0,0 +1,3 @@ +/* $OpenBSD: signal.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/spinlock.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/spinlock.h new file mode 100644 index 0000000000..37b5429335 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/spinlock.h @@ -0,0 +1,3 @@ +/* $OpenBSD: spinlock.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/tcb.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/tcb.h new file mode 100644 index 0000000000..406394c940 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/tcb.h @@ -0,0 +1,3 @@ +/* $OpenBSD: tcb.h,v 1.2 2013/06/01 21:20:54 jasper Exp $ */ +/* public domain */ +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/timetc.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/timetc.h new file mode 100644 index 0000000000..20d9dfb763 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/timetc.h @@ -0,0 +1,23 @@ +/* $OpenBSD: timetc.h,v 1.2 2020/07/17 20:15:43 gkoehler Exp $ */ +/* + * Copyright (c) 2020 Paul Irofti + * + * 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_TIMETC_H_ +#define _MACHINE_TIMETC_H_ + +#define TC_TB 1 + +#endif /* _MACHINE_TIMETC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/trap.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/trap.h new file mode 100644 index 0000000000..4ceaa94f2b --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/trap.h @@ -0,0 +1,3 @@ +/* $OpenBSD: trap.h,v 1.1 2001/09/01 15:49:06 drahn Exp $ */ + +#include \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/vmparam.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/vmparam.h new file mode 100644 index 0000000000..a8578e2734 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/vmparam.h @@ -0,0 +1,99 @@ +/* $OpenBSD: vmparam.h,v 1.33 2024/01/30 16:43:22 deraadt Exp $ */ +/* $NetBSD: vmparam.h,v 1.1 1996/09/30 16:34:38 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. + */ + +#ifndef MACHINE_VMPARAM_H +#define MACHINE_VMPARAM_H + +#define USRSTACK VM_MAXUSER_ADDRESS + +#ifndef MAXTSIZ +#define MAXTSIZ (128*1024*1024) /* max text size */ +#endif + +#ifndef DFLDSIZ +#define DFLDSIZ (64*1024*1024) /* default data size */ +#endif + +#ifndef MAXDSIZ +#define MAXDSIZ (2UL*1024*1024*1024) /* max data size */ +#endif + +#ifndef BRKSIZ +#define BRKSIZ MAXDSIZ /* heap gap size */ +#endif + +#ifndef DFLSSIZ +#define DFLSSIZ (2*1024*1024) /* default stack size */ +#endif + +#ifndef MAXSSIZ +#define MAXSSIZ (32*1024*1024) /* max stack size */ +#endif + +#define STACKGAP_RANDOM 256*1024 + +/* + * Size of shared memory map + */ +#ifndef SHMMAXPGS +#define SHMMAXPGS 8192 /* 32mb */ +#endif + +/* + * Size of User Raw I/O map + */ +#define USRIOSIZE 1024 + +/* + * Would like to have MAX addresses = 0, but this doesn't (currently) work + */ +#define VM_MIN_ADDRESS ((vaddr_t)PAGE_SIZE) +#define VM_MAXUSER_ADDRESS ((vaddr_t)0xfffff000) +#define VM_MAX_ADDRESS VM_MAXUSER_ADDRESS +#define VM_MIN_KERNEL_ADDRESS ((vaddr_t)(PPC_KERNEL_SR << ADDR_SR_SHIFT)) + +/* map PIE into approximately the first quarter of user va space */ +#define VM_PIE_MIN_ADDR PAGE_SIZE +#define VM_PIE_MAX_ADDR 0x40000000 + +#define VM_KERN_ADDRESS_SIZE (PPC_SEGMENT_LENGTH - (32 * 1024 * 1024)) +#define VM_MAX_KERNEL_ADDRESS (VM_MIN_KERNEL_ADDRESS + VM_KERN_ADDRESS_SIZE) + +#define VM_PHYS_SIZE (USRIOSIZE * PAGE_SIZE) + +#define VM_PHYSSEG_MAX 32 /* actually we could have this many segments */ +#define VM_PHYSSEG_STRAT VM_PSTRAT_BSEARCH +#define VM_PHYSSEG_NOADD /* can't add RAM after vm_mem_init */ + +#endif \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/macppc/z8530var.h b/lib/libc/include/powerpc-openbsd-eabihf/macppc/z8530var.h new file mode 100644 index 0000000000..275214fc2d --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/macppc/z8530var.h @@ -0,0 +1,152 @@ +/* $OpenBSD: z8530var.h,v 1.11 2024/05/22 05:51:49 jsg Exp $ */ +/* $NetBSD: z8530var.h,v 1.5 2002/03/17 19:40:45 atatat Exp $ */ + +/* + * Copyright (c) 1994 Gordon W. Ross + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)zsvar.h 8.1 (Berkeley) 6/11/93 + */ + +#include +#include + +/* + * Clock source info structure, added here so xzs_chanstate works + */ +struct zsclksrc { + long clk; /* clock rate, in MHz, present on signal line */ + int flags; /* Specifies how this source can be used + (RTxC divided, RTxC BRG, PCLK BRG, TRxC divided) + and also if the source is "external" and if it + is changeable (by an ioctl ex.). The + source usage flags are used by the tty + child. The other bits tell zsloadchannelregs + if it should call an md signal source + changing routine. ZSC_VARIABLE says if + an ioctl should be able to change the + clock rate.*/ +}; +#define ZSC_PCLK 0x01 +#define ZSC_RTXBRG 0x02 +#define ZSC_RTXDIV 0x04 +#define ZSC_TRXDIV 0x08 +#define ZSC_VARIABLE 0x40 +#define ZSC_EXTERN 0x80 + +#define ZSC_BRG 0x03 +#define ZSC_DIV 0x0c + + +/* + * These are the machine-dependent (extended) variants of + * struct zs_chanstate and struct zsc_softc + */ +struct xzs_chanstate { + /* machine-independent part (First!)*/ + struct zs_chanstate xzs_cs; + /* machine-dependent extensions */ + int cs_hwflags; + int cs_chip; /* type of chip */ + /* Clock source info... */ + int cs_clock_count; /* how many signal sources available */ + struct zsclksrc cs_clocks[4]; /* info on available signal sources */ + long cs_cclk_flag; /* flag for current clock source */ + long cs_pclk_flag; /* flag for pending clock source */ + int cs_csource; /* current source # */ + int cs_psource; /* pending source # */ +}; + +struct zsc_softc { + struct device zsc_dev; /* base device */ + struct zs_chanstate *zsc_cs[2]; /* channel A and B soft state */ + /* Machine-dependent part follows... */ + void *zsc_softintr; + struct xzs_chanstate xzsc_xcs_store[2]; + dbdma_regmap_t *zsc_txdmareg[2]; + dbdma_command_t *zsc_txdmacmd[2]; + /* XXX tx only, for now */ +}; + +/* + * Functions to read and write individual registers in a channel. + * The ZS chip requires a 1.6 uSec. recovery time between accesses, + * and the Sun3 hardware does NOT take care of this for you. + * MacII hardware DOES take care of the delay for us. :-) + * XXX - Then these should be inline functions! -gwr + * Some clock-chirped macs lose serial ports. It could be that the + * hardware delay is tied to the CPU speed, and that the minimum delay + * no longer's respected. For them, ZS_DELAY might help. + * XXX - no one seems to want to try and check this -wrs + */ + +u_char zs_read_reg(struct zs_chanstate *cs, u_char reg); +u_char zs_read_csr(struct zs_chanstate *cs); +u_char zs_read_data(struct zs_chanstate *cs); + +void zs_write_reg(struct zs_chanstate *cs, u_char reg, u_char val); +void zs_write_csr(struct zs_chanstate *cs, u_char val); +void zs_write_data(struct zs_chanstate *cs, u_char val); + +/* XXX - Could define splzs() here instead of in psl.h */ +#define splzs spltty + +/* Hook for MD ioctl support */ +int zsmdioctl(struct zs_chanstate *cs, u_long cmd, caddr_t data); +/* XXX - This is a bit gross... */ +/* +#define ZS_MD_IOCTL(cs, cmd, data) zsmdioctl(cs, cmd, data) +*/ + +/* Callback for "external" clock sources */ +void zsmd_setclock(struct zs_chanstate *cs); +#define ZS_MD_SETCLK(cs) zsmd_setclock(cs) + +#define PCLK (9600 * 384) /* PCLK pin input clock rate */ + +/* The layout of this is hardware-dependent (padding, order). */ +struct zschan { + volatile u_char zc_csr; /* ctrl,status, and indirect access */ + u_char zc_xxx0[15]; + volatile u_char zc_data; /* data */ + u_char zc_xxx1[15]; +}; + +#ifndef ZSCCF_CHANNEL +#define ZSCCF_CHANNEL 0 +#define ZSCCF_CHANNEL_DEFAULT -1 +#endif \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/_float.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/_float.h new file mode 100644 index 0000000000..31988cbf86 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/_float.h @@ -0,0 +1,71 @@ +/* $OpenBSD: _float.h,v 1.1 2012/06/26 16:12:44 deraadt Exp $ */ + +/* + * Copyright (c) 1989 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _MACHINE__FLOAT_H_ +#define _MACHINE__FLOAT_H_ + +#define __FLT_RADIX 2 /* b */ +#define __FLT_ROUNDS __flt_rounds() +#define __FLT_EVAL_METHOD 0 /* no promotions */ + +#define __FLT_MANT_DIG 24 /* p */ +#define __FLT_EPSILON 1.19209290E-07F /* b**(1-p) */ +#define __FLT_DIG 6 /* floor((p-1)*log10(b))+(b == 10) */ +#define __FLT_MIN_EXP (-125) /* emin */ +#define __FLT_MIN 1.17549435E-38F /* b**(emin-1) */ +#define __FLT_MIN_10_EXP (-37) /* ceil(log10(b**(emin-1))) */ +#define __FLT_MAX_EXP 128 /* emax */ +#define __FLT_MAX 3.40282347E+38F /* (1-b**(-p))*b**emax */ +#define __FLT_MAX_10_EXP 38 /* floor(log10((1-b**(-p))*b**emax)) */ + +#define __DBL_MANT_DIG 53 +#define __DBL_EPSILON 2.2204460492503131E-16 +#define __DBL_DIG 15 +#define __DBL_MIN_EXP (-1021) +#define __DBL_MIN 2.2250738585072014E-308 +#define __DBL_MIN_10_EXP (-307) +#define __DBL_MAX_EXP 1024 +#define __DBL_MAX 1.7976931348623157E+308 +#define __DBL_MAX_10_EXP 308 + +#define __LDBL_MANT_DIG DBL_MANT_DIG +#define __LDBL_EPSILON DBL_EPSILON +#define __LDBL_DIG DBL_DIG +#define __LDBL_MIN_EXP DBL_MIN_EXP +#define __LDBL_MIN DBL_MIN +#define __LDBL_MIN_10_EXP DBL_MIN_10_EXP +#define __LDBL_MAX_EXP DBL_MAX_EXP +#define __LDBL_MAX DBL_MAX +#define __LDBL_MAX_10_EXP DBL_MAX_10_EXP + +#define __DECIMAL_DIG 17 + +#endif /* _MACHINE__FLOAT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/_types.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/_types.h new file mode 100644 index 0000000000..e3d855f9a0 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/_types.h @@ -0,0 +1,141 @@ +/* $OpenBSD: _types.h,v 1.25 2023/07/02 19:02:28 cheloha 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 _POWERPC__TYPES_H_ +#define _POWERPC__TYPES_H_ + +#if defined(_KERNEL) +typedef struct label_t { + long val[25]; +} 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(double) - 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; +typedef long long __int64_t; +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 +struct __va_list_tag; +typedef struct __va_list_tag * __va_list; +#endif + +/* Wide character support types */ +#ifndef __cplusplus +typedef int __wchar_t; +#endif +typedef int __wint_t; +typedef int __rune_t; +typedef void * __wctrans_t; +typedef void * __wctype_t; + +#endif /* _POWERPC__TYPES_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/asm.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/asm.h new file mode 100644 index 0000000000..87f1863b3c --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/asm.h @@ -0,0 +1,127 @@ +/* $OpenBSD: asm.h,v 1.19 2023/02/03 06:13:08 miod Exp $ */ +/* $NetBSD: asm.h,v 1.1 1996/09/30 16:34:20 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. + */ + +#ifndef _POWERPC_ASM_H_ +#define _POWERPC_ASM_H_ + +#define _C_LABEL(x) x +#define _ASM_LABEL(x) x + +#ifdef __STDC__ +# define _TMP_LABEL(x) .L_ ## x +#else +# define _TMP_LABEL(x) .L_/**/x +#endif + +#define _ENTRY_NB(x) \ + .text; .align 2; .type x,@function; x: +#define _ENTRY(x) .globl x; _ENTRY_NB(x) + +#if defined(PROF) || defined(GPROF) +# define _PROF_PROLOGUE(y) \ + .section ".data"; \ + .align 2; \ +_TMP_LABEL(y):; \ + .long 0; \ + .section ".text"; \ + mflr 0; \ + addis 11, 11, _TMP_LABEL(y)@ha; \ + stw 0, 4(1); \ + addi 0, 11,_TMP_LABEL(y)@l; \ + bl _mcount; +#else +# define _PROF_PROLOGUE(y) +#endif + +#define ENTRY(y) _ENTRY(y); _PROF_PROLOGUE(y) +#define ENTRY_NB(y) _ENTRY_NB(y); _PROF_PROLOGUE(y) +#define ASENTRY(y) _ENTRY(y); _PROF_PROLOGUE(y) +#define END(y) .size y, . - y + +#define STRONG_ALIAS(alias,sym) \ + .global alias; .set alias,sym +#define WEAK_ALIAS(alias,sym) \ + .weak alias; .set alias,sym + +#if defined(_RET_PROTECTOR) +# if defined(__PIC__) +# define RETGUARD_LOAD_RANDOM(x, reg) \ + bcl 20, 31, 66f; \ +66: mflr reg; \ + addis reg, reg, (__retguard_ ## x - 66b)@ha; \ + lwz reg, ((__retguard_ ## x - 66b)@l)(reg) +# else +# define RETGUARD_LOAD_RANDOM(x, reg) \ + lis reg, (__retguard_ ## x)@ha; \ + lwz reg, ((__retguard_ ## x)@l)(reg) +# endif +# define RETGUARD_SETUP(x, reg, retreg) \ + mflr retreg; \ + RETGUARD_SETUP_LATE(x, reg, retreg) +# define RETGUARD_SETUP_LATE(x, reg, retreg) \ + RETGUARD_SYMBOL(x); \ + RETGUARD_LOAD_RANDOM(x, reg); \ + xor reg, reg, retreg +# define RETGUARD_CHECK(x, reg, retreg) \ + xor reg, reg, retreg; \ + RETGUARD_LOAD_RANDOM(x, %r10); \ + mtlr retreg; \ + twne reg, %r10 +# define RETGUARD_SAVE(reg, loc) \ + stw reg, loc +# define RETGUARD_LOAD(reg, loc) \ + lwz reg, loc +# define RETGUARD_SYMBOL(x) \ + .ifndef __retguard_ ## x; \ + .hidden __retguard_ ## x; \ + .type __retguard_ ## x,@object; \ + .pushsection .openbsd.randomdata.retguard,"aw",@progbits; \ + .weak __retguard_ ## x; \ + .p2align 2; \ + __retguard_ ## x: ; \ + .long 0; \ + .size __retguard_ ## x, 4; \ + .popsection; \ + .endif +#else +# define RETGUARD_LOAD_RANDOM(x, reg) +# define RETGUARD_SETUP(x, reg, retreg) +# define RETGUARD_SETUP_LATE(x, reg, retreg) +# define RETGUARD_CHECK(x, reg, retreg) +# define RETGUARD_SAVE(reg, loc) +# define RETGUARD_LOAD(reg, loc) +# define RETGUARD_SYMBOL(x) +#endif + +#endif /* !_POWERPC_ASM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/atomic.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/atomic.h new file mode 100644 index 0000000000..0453051551 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/atomic.h @@ -0,0 +1,292 @@ +/* $OpenBSD: atomic.h,v 1.13 2022/08/29 02:01:18 jsg 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 _POWERPC_ATOMIC_H_ +#define _POWERPC_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: 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_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: 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_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: lwarx %0, 0, %2 \n" + " stwcx. %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: lwarx %0, 0, %2 \n" + " stwcx. %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: lwarx %0, 0, %2 \n" + " stwcx. %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: 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_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: 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_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: 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_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 /* _POWERPC_ATOMIC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/bat.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/bat.h new file mode 100644 index 0000000000..dbd2225101 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/bat.h @@ -0,0 +1,72 @@ +/* $OpenBSD: bat.h,v 1.6 2015/03/31 16:00:38 mpi 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_BAT_H_ +#define _POWERPC_BAT_H_ + +struct bat { + u_int32_t batu; + u_int32_t batl; +}; + +#define BATU(vaddr,len) (((vaddr)&0xf0000000)|(len)|0x2) +#define BATL(raddr,wimg) (((raddr)&0xf0000000)|(wimg)|0x2) + +#define BAT_W 0x40 +#define BAT_I 0x20 +#define BAT_M 0x10 +#define BAT_G 0x08 + +#define BAT_BL_128K 0x00000000 +#define BAT_BL_256K 0x00000004 +#define BAT_BL_512K 0x0000000c +#define BAT_BL_1M 0x0000001c +#define BAT_BL_2M 0x0000003c +#define BAT_BL_4M 0x0000007c +#define BAT_BL_8M 0x000000fc +#define BAT_BL_16M 0x000001fc +#define BAT_BL_32M 0x000003fc +#define BAT_BL_64M 0x000007fc +#define BAT_BL_128M 0x00000ffc +#define BAT_BL_256M 0x00001ffc +/* Extended Block Lengths (7455+) */ +#define BAT_BL_512M 0x00003ffc +#define BAT_BL_1G 0x00007ffc +#define BAT_BL_2G 0x0000fffc +#define BAT_BL_4G 0x0001fffc + +#ifdef _KERNEL +extern struct bat battable[16]; +#endif + +#endif /* _POWERPC_BAT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/cdefs.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/cdefs.h new file mode 100644 index 0000000000..f84970e7aa --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/cdefs.h @@ -0,0 +1,21 @@ +/* $OpenBSD: cdefs.h,v 1.7 2013/03/28 17:30:45 martynas Exp $ */ + +/* + * Written by J.T. Conklin 01/17/95. + * Public domain. + */ + +#ifndef _POWERPC_CDEFS_H_ +#define _POWERPC_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 /* !_POWERPC_CDEFS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/cpu.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/cpu.h new file mode 100644 index 0000000000..4ce4264905 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/cpu.h @@ -0,0 +1,473 @@ +/* $OpenBSD: cpu.h,v 1.80 2025/04/07 15:43:00 gkoehler Exp $ */ +/* $NetBSD: cpu.h,v 1.1 1996/09/30 16:34:21 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. + */ +#ifndef _POWERPC_CPU_H_ +#define _POWERPC_CPU_H_ + +#include + +#include +#include +#include +#include + +struct cpu_info { + struct device *ci_dev; /* our device */ + struct schedstate_percpu ci_schedstate; /* scheduler state */ + + struct proc *ci_curproc; + + struct pcb *ci_curpcb; + struct pmap *ci_curpm; + struct proc *ci_fpuproc; + struct proc *ci_vecproc; + int ci_cpuid; + + volatile int ci_want_resched; + volatile int ci_cpl; + volatile int ci_ipending; + volatile int ci_dec_deferred; + + volatile int ci_flags; +#define CI_FLAGS_SLEEPING 2 + +#if defined(MULTIPROCESSOR) + struct srp_hazard ci_srp_hazards[SRP_HAZARD_NUM]; +#endif + + int ci_idepth; + char *ci_intstk; +#define CPUSAVE_LEN 8 + register_t ci_tempsave[CPUSAVE_LEN]; + register_t ci_ddbsave[CPUSAVE_LEN]; +#define DISISAVE_LEN 4 + register_t ci_disisave[DISISAVE_LEN]; + + struct clockqueue ci_queue; + + volatile int ci_ddb_paused; +#define CI_DDB_RUNNING 0 +#define CI_DDB_SHOULDSTOP 1 +#define CI_DDB_STOPPED 2 +#define CI_DDB_ENTERDDB 3 +#define CI_DDB_INDDB 4 + + u_int32_t ci_randseed; + +#ifdef DIAGNOSTIC + int ci_mutex_level; +#endif +#ifdef GPROF + struct gmonparam *ci_gmon; + struct clockintr ci_gmonclock; +#endif + char ci_panicbuf[512]; +}; + +static __inline struct cpu_info * +curcpu(void) +{ + struct cpu_info *ci; + + __asm volatile ("mfsprg %0,0" : "=r"(ci)); + return ci; +} + +#define curpcb (curcpu()->ci_curpcb) +#define curpm (curcpu()->ci_curpm) + +#define CPU_INFO_UNIT(ci) ((ci)->ci_dev ? (ci)->ci_dev->dv_unit : 0) + +#ifdef MULTIPROCESSOR + +#define PPC_MAXPROCS 4 + +static __inline int +cpu_number(void) +{ + int pir; + + pir = curcpu()->ci_cpuid; + return pir; +} + +void cpu_boot_secondary_processors(void); + +#define CPU_IS_PRIMARY(ci) ((ci)->ci_cpuid == 0) +#define CPU_IS_RUNNING(ci) 1 +#define CPU_INFO_ITERATOR int +#define CPU_INFO_FOREACH(cii, ci) \ + for (cii = 0, ci = &cpu_info[0]; cii < ncpusfound; cii++, ci++) + +void cpu_unidle(struct cpu_info *); + +#else + +#define PPC_MAXPROCS 1 + +#define cpu_number() 0 + +#define CPU_IS_PRIMARY(ci) 1 +#define CPU_IS_RUNNING(ci) 1 +#define CPU_INFO_ITERATOR int +#define CPU_INFO_FOREACH(cii, ci) \ + for (cii = 0, ci = curcpu(); ci != NULL; ci = NULL) + +#define cpu_unidle(ci) + +#endif + +#define CPU_BUSY_CYCLE() do {} while (0) + +#define MAXCPUS PPC_MAXPROCS + +extern struct cpu_info cpu_info[PPC_MAXPROCS]; + +#define CLKF_USERMODE(frame) (((frame)->srr1 & PSL_PR) != 0) +#define CLKF_PC(frame) ((frame)->srr0) +#define CLKF_INTR(frame) ((frame)->depth > 1) + +extern int ppc_cpuidle; +extern int ppc_proc_is_64b; +extern int ppc_nobat; + +void cpu_bootstrap(void); + +static inline unsigned int +cpu_rnd_messybits(void) +{ + unsigned int hi, lo; + + __asm volatile("mftbu %0; mftb %1" : "=r" (hi), "=r" (lo)); + + return (hi ^ lo); +} + +/* + * This is used during profiling to integrate system time. + */ +#define PROC_PC(p) (trapframe(p)->srr0) +#define PROC_STACK(p) (trapframe(p)->fixreg[1]) + +void delay(unsigned); +#define DELAY(n) delay(n) + +#define aston(p) ((p)->p_md.md_astpending = 1) + +/* + * Preempt the current process if in interrupt from user mode, + * or after the current trap/syscall if in system mode. + */ +#define need_resched(ci) \ +do { \ + ci->ci_want_resched = 1; \ + if (ci->ci_curproc != NULL) \ + aston(ci->ci_curproc); \ +} while (0) +#define clear_resched(ci) (ci)->ci_want_resched = 0 + +#define need_proftick(p) aston(p) + +void signotify(struct proc *); + +extern char *bootpath; + +#ifndef CACHELINESIZE +#define CACHELINESIZE 32 /* For now XXX */ +#endif + +static __inline void +syncicache(void *from, size_t len) +{ + size_t by, i; + + by = CACHELINESIZE; + i = 0; + do { + __asm volatile ("dcbst %0,%1" :: "r"(from), "r"(i)); + i += by; + } while (i < len); + __asm volatile ("sync"); + i = 0; + do { + __asm volatile ("icbi %0,%1" :: "r"(from), "r"(i)); + i += by; + } while (i < len); + __asm volatile ("sync; isync"); +} + +static __inline void +invdcache(void *from, int len) +{ + int l; + char *p = from; + + len = len + (((u_int32_t) from) & (CACHELINESIZE - 1)); + l = len; + + do { + __asm volatile ("dcbi 0,%0" :: "r"(p)); + p += CACHELINESIZE; + } while ((l -= CACHELINESIZE) > 0); + __asm volatile ("sync"); +} + +static __inline void +flushdcache(void *from, int len) +{ + int l; + char *p = from; + + len = len + (((u_int32_t) from) & (CACHELINESIZE - 1)); + l = len; + + do { + __asm volatile ("dcbf 0,%0" :: "r"(p)); + p += CACHELINESIZE; + } while ((l -= CACHELINESIZE) > 0); + __asm volatile ("sync"); +} + +#define FUNC_SPR(n, name) \ +static __inline u_int32_t ppc_mf ## name(void) \ +{ \ + u_int32_t ret; \ + __asm volatile ("mfspr %0," # n : "=r" (ret)); \ + return ret; \ +} \ +static __inline void ppc_mt ## name(u_int32_t val) \ +{ \ + __asm volatile ("mtspr "# n ",%0" :: "r" (val)); \ +} \ + +FUNC_SPR(0, mq) +FUNC_SPR(1, xer) +FUNC_SPR(4, rtcu) +FUNC_SPR(5, rtcl) +FUNC_SPR(8, lr) +FUNC_SPR(9, ctr) +FUNC_SPR(18, dsisr) +FUNC_SPR(19, dar) +FUNC_SPR(22, dec) +FUNC_SPR(25, sdr1) +FUNC_SPR(26, srr0) +FUNC_SPR(27, srr1) +FUNC_SPR(256, vrsave) +FUNC_SPR(272, sprg0) +FUNC_SPR(273, sprg1) +FUNC_SPR(274, sprg2) +FUNC_SPR(275, sprg3) +FUNC_SPR(280, asr) +FUNC_SPR(282, ear) +FUNC_SPR(287, pvr) +FUNC_SPR(311, hior) +FUNC_SPR(528, ibat0u) +FUNC_SPR(529, ibat0l) +FUNC_SPR(530, ibat1u) +FUNC_SPR(531, ibat1l) +FUNC_SPR(532, ibat2u) +FUNC_SPR(533, ibat2l) +FUNC_SPR(534, ibat3u) +FUNC_SPR(535, ibat3l) +FUNC_SPR(560, ibat4u) +FUNC_SPR(561, ibat4l) +FUNC_SPR(562, ibat5u) +FUNC_SPR(563, ibat5l) +FUNC_SPR(564, ibat6u) +FUNC_SPR(565, ibat6l) +FUNC_SPR(566, ibat7u) +FUNC_SPR(567, ibat7l) +FUNC_SPR(536, dbat0u) +FUNC_SPR(537, dbat0l) +FUNC_SPR(538, dbat1u) +FUNC_SPR(539, dbat1l) +FUNC_SPR(540, dbat2u) +FUNC_SPR(541, dbat2l) +FUNC_SPR(542, dbat3u) +FUNC_SPR(543, dbat3l) +FUNC_SPR(568, dbat4u) +FUNC_SPR(569, dbat4l) +FUNC_SPR(570, dbat5u) +FUNC_SPR(571, dbat5l) +FUNC_SPR(572, dbat6u) +FUNC_SPR(573, dbat6l) +FUNC_SPR(574, dbat7u) +FUNC_SPR(575, dbat7l) +FUNC_SPR(1009, hid1) +FUNC_SPR(1010, iabr) +FUNC_SPR(1017, l2cr) +FUNC_SPR(1018, l3cr) +FUNC_SPR(1013, dabr) +FUNC_SPR(1023, pir) + +static __inline u_int32_t +ppc_mftbl(void) +{ + int ret; + __asm volatile ("mftb %0" : "=r" (ret)); + return ret; +} + + +static __inline u_int64_t +ppc_mftb(void) +{ + u_long scratch; + u_int64_t tb; + + __asm volatile ("1: mftbu %0; mftb %L0; mftbu %1;" + " cmpw 0,%0,%1; bne 1b" : "=r"(tb), "=r"(scratch)); + return tb; +} + +static __inline void +ppc_mttb(u_int64_t tb) +{ + __asm volatile ("mttbl %0" :: "r"(0)); + __asm volatile ("mttbu %0" :: "r"((u_int32_t)(tb >> 32))); + __asm volatile ("mttbl %0" :: "r"((u_int32_t)(tb & 0xffffffff))); +} + +static __inline u_int32_t +ppc_mfmsr(void) +{ + int ret; + __asm volatile ("mfmsr %0" : "=r" (ret)); + return ret; +} + +static __inline void +ppc_mtmsr(u_int32_t val) +{ + __asm volatile ("mtmsr %0" :: "r" (val)); +} + +static __inline void +ppc_mtsrin(u_int32_t val, u_int32_t sn_shifted) +{ + __asm volatile ("mtsrin %0,%1" :: "r"(val), "r"(sn_shifted)); +} + +u_int64_t ppc64_mfscomc(void); +void ppc_mtscomc(u_int32_t); +void ppc64_mtscomc(u_int64_t); +u_int64_t ppc64_mfscomd(void); +void ppc_mtscomd(u_int32_t); +u_int32_t ppc_mfhid0(void); +void ppc_mthid0(u_int32_t); +u_int64_t ppc64_mfhid1(void); +void ppc64_mthid1(u_int64_t); +u_int64_t ppc64_mfhid4(void); +void ppc64_mthid4(u_int64_t); +u_int64_t ppc64_mfhid5(void); +void ppc64_mthid5(u_int64_t); + +#include + +/* + * General functions to enable and disable interrupts + * without having inlined assembly code in many functions. + */ +static __inline void +ppc_intr_enable(int enable) +{ + u_int32_t msr; + if (enable != 0) { + msr = ppc_mfmsr(); + msr |= PSL_EE; + ppc_mtmsr(msr); + } +} + +static __inline int +ppc_intr_disable(void) +{ + u_int32_t emsr, dmsr; + emsr = ppc_mfmsr(); + dmsr = emsr & ~PSL_EE; + ppc_mtmsr(dmsr); + return (emsr & PSL_EE); +} + +static inline void +intr_enable(void) +{ + ppc_mtmsr(ppc_mfmsr() | PSL_EE); +} + +static __inline u_long +intr_disable(void) +{ + return ppc_intr_disable(); +} + +static __inline void +intr_restore(u_long s) +{ + ppc_intr_enable(s); +} + +int ppc_cpuspeed(int *); + +/* + * PowerPC CPU types + */ +#define PPC_CPU_MPC601 1 +#define PPC_CPU_MPC603 3 +#define PPC_CPU_MPC604 4 +#define PPC_CPU_MPC603e 6 +#define PPC_CPU_MPC603ev 7 +#define PPC_CPU_MPC750 8 +#define PPC_CPU_MPC604ev 9 +#define PPC_CPU_MPC7400 12 +#define PPC_CPU_IBM970 0x0039 +#define PPC_CPU_IBM970FX 0x003c +#define PPC_CPU_IBM970MP 0x0044 +#define PPC_CPU_IBM750FX 0x7000 +#define PPC_CPU_MPC7410 0x800c +#define PPC_CPU_MPC7447A 0x8003 +#define PPC_CPU_MPC7448 0x8004 +#define PPC_CPU_MPC7450 0x8000 +#define PPC_CPU_MPC7455 0x8001 +#define PPC_CPU_MPC7457 0x8002 +#define PPC_CPU_MPC83xx 0x8083 + +/* + * This needs to be included late since it relies on definitions higher + * up in this file. + */ +#if defined(MULTIPROCESSOR) && defined(_KERNEL) +#include +#endif + +#endif /* _POWERPC_CPU_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/db_machdep.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/db_machdep.h new file mode 100644 index 0000000000..2f853f7487 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/db_machdep.h @@ -0,0 +1,102 @@ +/* $OpenBSD: db_machdep.h,v 1.32 2022/01/28 18:37:40 gkoehler Exp $*/ +/* $NetBSD: db_machdep.h,v 1.13 1996/04/29 20:50:08 leo Exp $ */ + +/* + * Mach Operating System + * Copyright (c) 1992 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +/* + * Machine-dependent defines for new kernel debugger. + */ +#ifndef _POWERPC_DB_MACHDEP_H_ +#define _POWERPC_DB_MACHDEP_H_ + +#include +#include +#include +#include + +typedef long db_expr_t; /* expression - signed */ +typedef struct trapframe db_regs_t; +extern db_regs_t ddb_regs; /* register state */ + +#define PC_REGS(regs) ((regs)->srr0) +#define SET_PC_REGS(regs, value) PC_REGS(regs) = (value) + +#define BKPT_INST 0x7C810808 /* breakpoint instruction */ + +#define BKPT_SIZE (4) /* size of breakpoint inst */ +#define BKPT_SET(inst) (BKPT_INST) + +#define db_clear_single_step(regs) ((regs)->srr1 &= ~PSL_SE) +#define db_set_single_step(regs) ((regs)->srr1 |= PSL_SE) + +#define T_BREAKPOINT 0xffff +#define IS_BREAKPOINT_TRAP(type, code) ((type) == T_BREAKPOINT) + +#ifdef T_WATCHPOINT +#define IS_WATCHPOINT_TRAP(type, code) ((type) == T_WATCHPOINT) +#else +#define IS_WATCHPOINT_TRAP(type, code) 0 +#endif + +#define M_RTS 0xfc0007fe +#define I_RTS 0x4c000020 +#define M_BC 0xfc000000 +#define I_BC 0x40000000 +#define M_B 0xfc000000 +#define I_B 0x50000000 +#define M_RFI 0xfc0007fe +#define I_RFI 0x4c000064 + +#define inst_trap_return(ins) (((ins)&M_RFI) == I_RFI) +#define inst_return(ins) (((ins)&M_RTS) == I_RTS) +#define inst_call(ins) (((ins)&M_BC ) == I_BC || \ + ((ins)&M_B ) == I_B ) + +#ifdef _KERNEL + +int db_enter_ddb(void); +void db_startcpu(int); +void db_stopcpu(int); +void ppc_ipi_db(struct cpu_info *); + +void kdb_kintr(void *); +void db_save_regs(struct trapframe *frame); +void ddb_trap(void); +db_expr_t db_dumpframe(u_int32_t pframe, int (*pr)(const char *, ...)); + +#define DDB_STATE_NOT_RUNNING 0 +#define DDB_STATE_RUNNING 1 +#define DDB_STATE_EXITING 2 + +/* + * We define some of our own commands + */ +#define DB_MACHINE_COMMANDS + +#endif /* _KERNEL */ + +#endif /* _POWERPC_DB_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/elf.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/elf.h new file mode 100644 index 0000000000..d1a121fff9 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/elf.h @@ -0,0 +1,66 @@ +/* $OpenBSD: elf.h,v 1.3 2025/02/19 18:25:03 jca Exp $ */ + +/* + * This file is in the public domain. + */ + +#ifndef _MACHINE_ELF_H_ +#define _MACHINE_ELF_H_ + +/* + * CPU Feature Attributes + * + * These are defined in the PowerPC ELF ABI for the AT_HWCAP vector, + * and are exported to userland via the elf_aux_info(3) function. + */ + +#ifdef _KERNEL +# define __HAVE_CPU_HWCAP +# define __HAVE_CPU_HWCAP2 +extern unsigned long hwcap; +extern unsigned long hwcap2; +#endif /* _KERNEL */ + +#define PPC_FEATURE_32 0x80000000 /* Always true */ +#define PPC_FEATURE_64 0x40000000 /* Defined on a 64-bit CPU */ +#define PPC_FEATURE_601_INSTR 0x20000000 +#define PPC_FEATURE_HAS_ALTIVEC 0x10000000 +#define PPC_FEATURE_HAS_FPU 0x08000000 +#define PPC_FEATURE_HAS_MMU 0x04000000 +#define PPC_FEATURE_UNIFIED_CACHE 0x01000000 +#define PPC_FEATURE_HAS_SPE 0x00800000 +#define PPC_FEATURE_HAS_EFP_SINGLE 0x00400000 +#define PPC_FEATURE_HAS_EFP_DOUBLE 0x00200000 +#define PPC_FEATURE_NO_TB 0x00100000 +#define PPC_FEATURE_POWER4 0x00080000 +#define PPC_FEATURE_POWER5 0x00040000 +#define PPC_FEATURE_POWER5_PLUS 0x00020000 +#define PPC_FEATURE_CELL 0x00010000 +#define PPC_FEATURE_BOOKE 0x00008000 +#define PPC_FEATURE_SMT 0x00004000 +#define PPC_FEATURE_ICACHE_SNOOP 0x00002000 +#define PPC_FEATURE_ARCH_2_05 0x00001000 +#define PPC_FEATURE_HAS_DFP 0x00000400 +#define PPC_FEATURE_POWER6_EXT 0x00000200 +#define PPC_FEATURE_ARCH_2_06 0x00000100 +#define PPC_FEATURE_HAS_VSX 0x00000080 +#define PPC_FEATURE_TRUE_LE 0x00000002 +#define PPC_FEATURE_PPC_LE 0x00000001 + +#define PPC_FEATURE2_ARCH_2_07 0x80000000 +#define PPC_FEATURE2_HTM 0x40000000 +#define PPC_FEATURE2_DSCR 0x20000000 +#define PPC_FEATURE2_EBB 0x10000000 +#define PPC_FEATURE2_ISEL 0x08000000 +#define PPC_FEATURE2_TAR 0x04000000 +#define PPC_FEATURE2_HAS_VEC_CRYPTO 0x02000000 +#define PPC_FEATURE2_HTM_NOSC 0x01000000 +#define PPC_FEATURE2_ARCH_3_00 0x00800000 +#define PPC_FEATURE2_HAS_IEEE128 0x00400000 +#define PPC_FEATURE2_DARN 0x00200000 +#define PPC_FEATURE2_SCV 0x00100000 +#define PPC_FEATURE2_HTM_NOSUSPEND 0x00080000 +#define PPC_FEATURE2_ARCH_3_1 0x00040000 +#define PPC_FEATURE2_MMA 0x00020000 + +#endif /* !_MACHINE_ELF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/endian.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/endian.h new file mode 100644 index 0000000000..6e97b5fbdc --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/endian.h @@ -0,0 +1,37 @@ +/* $OpenBSD: endian.h,v 1.22 2024/05/07 14:26:48 naddy 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 _POWERPC_ENDIAN_H_ +#define _POWERPC_ENDIAN_H_ + +#undef _BIG_ENDIAN /* XXX - gcc may define _BIG_ENDIAN too */ +#define _BYTE_ORDER _BIG_ENDIAN + +#ifndef __FROM_SYS__ENDIAN +#include +#endif + +#endif /* _POWERPC_ENDIAN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/exec.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/exec.h new file mode 100644 index 0000000000..7ecfa3a6de --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/exec.h @@ -0,0 +1,46 @@ +/* $OpenBSD: exec.h,v 1.16 2021/03/11 11:16:59 jsg Exp $ */ + +/* + * Copyright (c) 1997 Per Fogelstrom, Opsycon AB. + * + * 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. + * + * $Id: exec.h,v 1.16 2021/03/11 11:16:59 jsg Exp $ + */ + +#ifndef _POWERPC_EXEC_H_ +#define _POWERPC_EXEC_H_ + +#define __LDPGSZ 4096 /* linker page size */ + +#define ARCH_ELFSIZE 32 + +#define ELF_TARG_CLASS ELFCLASS32 +#define ELF_TARG_DATA ELFDATA2MSB +#define ELF_TARG_MACH EM_PPC + +/* Processor specific dynamic tag values. */ +#define DT_PPC_GOT 0x70000000 + +#define DT_PROCNUM (DT_PPC_GOT - DT_LOPROC + 1) + +#endif /* _POWERPC_EXEC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/fenv.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/fenv.h new file mode 100644 index 0000000000..dd0f8d80c9 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/fenv.h @@ -0,0 +1,96 @@ +/* $OpenBSD: fenv.h,v 1.3 2011/05/25 21:46:49 martynas Exp $ */ + +/* + * Copyright (c) 2011 Martynas Venckus + * + * 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 _POWERPC_FENV_H_ +#define _POWERPC_FENV_H_ + +/* + * Each symbol representing a floating point exception expands to an integer + * constant expression with values, such that bitwise-inclusive ORs of _all + * combinations_ of the constants result in distinct values. + * + * We use such values that allow direct bitwise operations on FPU registers. + */ +#define FE_INEXACT 0x02000000 +#define FE_DIVBYZERO 0x04000000 +#define FE_UNDERFLOW 0x08000000 +#define FE_OVERFLOW 0x10000000 +#define FE_INVALID 0x20000000 +#define _FE_INVALID_SOFT 0x00000400 +#define _FE_INVALID_ALL 0x01f80700 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * exception constants defined above. + */ +#define FE_ALL_EXCEPT (FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | \ + FE_OVERFLOW | FE_INVALID) +#define _MASK_SHIFT 22 + +/* + * Each symbol representing the rounding direction, expands to an integer + * constant expression whose value is distinct non-negative value. + * + * We use such values that allow direct bitwise operations on FPU registers. + */ +#define FE_TONEAREST 0x0 +#define FE_TOWARDZERO 0x1 +#define FE_UPWARD 0x2 +#define FE_DOWNWARD 0x3 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * rounding direction constants defined above. + */ +#define _ROUND_MASK (FE_TONEAREST | FE_TOWARDZERO | FE_UPWARD | \ + FE_DOWNWARD) + +/* + * fenv_t represents the entire floating-point environment. + */ +typedef unsigned int fenv_t; + +/* + * The following constant represents the default floating-point environment + * (that is, the one installed at program startup) and has type pointer to + * const-qualified fenv_t. + * + * It can be used as an argument to the functions within the header + * that manage the floating-point environment, namely fesetenv() and + * feupdateenv(). + */ +__BEGIN_DECLS +extern fenv_t __fe_dfl_env; +__END_DECLS +#define FE_DFL_ENV ((const fenv_t *)&__fe_dfl_env) + +/* + * fexcept_t represents the floating-point status flags collectively, including + * any status the implementation associates with the flags. + * + * A floating-point status flag is a system variable whose value is set (but + * never cleared) when a floating-point exception is raised, which occurs as a + * side effect of exceptional floating-point arithmetic to provide auxiliary + * information. + * + * A floating-point control mode is a system variable whose value may be set by + * the user to affect the subsequent behavior of floating-point arithmetic. + */ +typedef unsigned int fexcept_t; + +#endif /* !_POWERPC_FENV_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/fpu.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/fpu.h new file mode 100644 index 0000000000..5018d672d8 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/fpu.h @@ -0,0 +1,71 @@ +/* $OpenBSD: fpu.h,v 1.6 2005/10/09 14:52:12 drahn Exp $ */ + +/*- + * Copyright (C) 1996 Wolfgang Solfrank. + * Copyright (C) 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_FPU_H_ +#define _POWERPC_FPU_H_ + +#define FPCSR_FX 0x80000000 +#define FPCSR_FEX 0x40000000 +#define FPCSR_VX 0x20000000 +#define FPCSR_OX 0x10000000 +#define FPCSR_UX 0x08000000 +#define FPCSR_ZX 0x04000000 +#define FPCSR_XX 0x02000000 +#define FPCSR_VXSNAN 0x01000000 +#define FPCSR_VXISI 0x00800000 +#define FPCSR_VXIDI 0x00400000 +#define FPCSR_VXZDZ 0x00200000 +#define FPCSR_VXIMZ 0x00100000 +#define FPCSR_VXVC 0x00080000 +#define FPCSR_FR 0x00040000 +#define FPCSR_FI 0x00020000 +#define FPCSR_FPRF 0x0001f000 +#define FPCSR_C 0x00010000 +#define FPCSR_FPCC 0x0000f000 +#define FPCSR_FL 0x00008000 +#define FPCSR_FG 0x00004000 +#define FPCSR_FE 0x00002000 +#define FPCSR_FU 0x00001000 +#define FPCSR_VXSOFT 0x00000400 +#define FPCSR_VXSQRT 0x00000200 +#define FPCSR_VXCVI 0x00000100 +#define FPCSR_VE 0x00000080 +#define FPCSR_OE 0x00000040 +#define FPCSR_UE 0x00000020 +#define FPCSR_ZE 0x00000010 +#define FPCSR_XE 0x00000008 +#define FPCSR_NI 0x00000004 +#define FPCSR_RN 0x00000003 + +void enable_fpu(struct proc *p); +void save_fpu(void); +#endif /* _POWERPC_FPU_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/frame.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/frame.h new file mode 100644 index 0000000000..90edbe7a18 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/frame.h @@ -0,0 +1,79 @@ +/* $OpenBSD: frame.h,v 1.8 2024/11/05 21:47:00 miod 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_FRAME_H_ +#define _POWERPC_FRAME_H_ + +/* + * This is to ensure alignment of the stackpointer + */ +#define FRAMELEN roundup(sizeof(struct trapframe) + 8, 16) +#define trapframe(p) ((struct trapframe *)((void *)(p)->p_addr + USPACE - FRAMELEN + 8)) + +struct switchframe { + register_t sp; + int fill; + int user_sr; + int cr; + register_t fixreg2; + register_t fixreg[19]; /* R13-R31 */ +}; + +struct clockframe { + register_t srr1; + register_t srr0; + int unused; + int depth; +}; + +/* + * Call frame for PowerPC used during fork. + */ +struct callframe { + register_t sp; + register_t lr; + register_t r30; + register_t r31; +}; + +struct sigframe { + int sf_signum; + siginfo_t *sf_sip; + struct sigcontext sf_sc; + siginfo_t sf_si; +}; + +struct fpsig { + double f[14]; /* f0 - f13 are volatile */ + double fpscr; +}; +#endif /* _POWERPC_FRAME_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/hid.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/hid.h new file mode 100644 index 0000000000..9700125005 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/hid.h @@ -0,0 +1,158 @@ +/* $OpenBSD: hid.h,v 1.1 2013/10/31 08:26:12 mpi Exp $ */ + +/*- + * Copyright (c) 2000 Tsubai Masanari. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: hid.h,v 1.2 2001/08/22 21:05:25 matt Exp $ + */ + +#ifndef _POWERPC_HID_H_ +#define _POWERPC_HID_H_ + +/* Hardware Implementation Dependent registers for the PowerPC */ + +#define HID0_EMCP 0x80000000 /* Enable machine check pin */ +#define HID0_DBP 0x40000000 /* Disable 60x bus parity generation */ +#define HID0_EBA 0x20000000 /* Enable 60x bus address parity checking */ +#define HID0_EBD 0x10000000 /* Enable 60x bus data parity checking */ +#define HID0_BCLK 0x08000000 /* CLK_OUT clock type selection */ +#define HID0_EICE 0x04000000 /* Enable ICE output */ +#define HID0_TBEN 0x04000000 /* Time base enable (7450) */ +#define HID0_ECLK 0x02000000 /* CLK_OUT clock type selection */ +#define HID0_PAR 0x01000000 /* Disable precharge of ARTRY */ +#define HID0_STEN 0x01000000 /* Software table search enable (7450) */ +#define HID0_DEEPNAP 0x01000000 /* Enable deep nap mode (970) */ +#define HID0_HBATEN 0x00800000 /* High BAT enable (74[45][578]) */ +#define HID0_DOZE 0x00800000 /* Enable doze mode */ +#define HID0_NAP 0x00400000 /* Enable nap mode */ +#define HID0_SLEEP 0x00200000 /* Enable sleep mode */ +#define HID0_DPM 0x00100000 /* Enable Dynamic power management */ +#define HID0_RISEG 0x00080000 /* Read I-SEG */ +#define HID0_TG 0x00040000 /* Timebase Granularity (OEA64) */ +#define HID0_BHTCLR 0x00040000 /* Clear branch history table (7450) */ +#define HID0_EIEC 0x00040000 /* Enable internal error checking */ +#define HID0_XAEN 0x00020000 /* Enable eXtended Addressing (7450) */ +#define HID0_NHR 0x00010000 /* Not hard reset */ +#define HID0_ICE 0x00008000 /* Enable i-cache */ +#define HID0_DCE 0x00004000 /* Enable d-cache */ +#define HID0_ILOCK 0x00002000 /* i-cache lock */ +#define HID0_DLOCK 0x00001000 /* d-cache lock */ +#define HID0_ICFI 0x00000800 /* i-cache flush invalidate */ +#define HID0_DCFI 0x00000400 /* d-cache flush invalidate */ +#define HID0_SPD 0x00000200 /* Disable speculative cache access */ +#define HID0_XBSEN 0x00000100 /* Extended BAT block-size enable (7457) */ +#define HID0_IFEM 0x00000100 /* Enable M-bit for I-fetch */ +#define HID0_XBSEN 0x00000100 /* Extended BAT block size enable (7455+) */ +#define HID0_SGE 0x00000080 /* Enable store gathering */ +#define HID0_DCFA 0x00000040 /* Data cache flush assist */ +#define HID0_BTIC 0x00000020 /* Enable BTIC */ +#define HID0_LRSTK 0x00000010 /* Link register stack enable (7450) */ +#define HID0_ABE 0x00000008 /* Enable address broadcast */ +#define HID0_FOLD 0x00000008 /* Branch folding enable (7450) */ +#define HID0_BHT 0x00000004 /* Enable branch history table */ +#define HID0_BTCD 0x00000002 /* Branch target addr cache disable (604) */ +#define HID0_NOPTI 0x00000001 /* No-op the dcbt(st) */ + +#define HID0_603_BITMASK \ + "\20" \ + "\040EMCP\037DBP\036EBA\035EBD\034BCLK\033EICE\032ECLK\031PAR" \ + "\030DOZE\027NAP\026SLEEP\025DPM\024RISEG\023EIEC\022res\021NHR" \ + "\020ICE\017DCE\016ILOCK\015DLOCK\014ICFI\013DCFI\012SPD\011IFEM" \ + "\010SGE\007DCFA\006BTIC\005FBIOB\004ABE\003BHT\002NOPDST\001NOPTI" + +#define HID0_7450_BITMASK \ + "\20" \ + "\040EMCP\037b1\036b2\035b3\034b4\033TBEN\032b6\031STEN" \ + "\030HBATEN\027NAP\026SLEEP\025DPM\024b12\023BHTCLR\022XAEN\021NHR" \ + "\020ICE\017DCE\016ILOCK\015DLOCK\014ICFI\013DCFI\012SPD\011XBSEN" \ + "\010SGE\007b25\006BTIC\005LRSTK\004FOLD\003BHT\002NOPDST\001NOPTI" + +#define HID0_970_BITMASK \ + "\20" \ + "\040ONEPPC\037SINGLE\036ISYNCSC\035SERGP\031DEEPNAP\030DOZE" \ + "\027NAP\025DPM\023TG\022HANGDETECT\021NHR\020INORDER" \ + "\016TBCTRL\015TBEN\012CIABREN\011HDICEEN" \ + "\010ENTHERM\001ENATTN" + +/* + * HID0 bit definitions per cpu model + * + * bit 603 604 750 7400 7410 7450 7457 + * 0 EMCP EMCP EMCP EMCP EMCP - - + * 1 - ECP DBP - - - - + * 2 EBA EBA EBA EBA EDA - - + * 3 EBD EBD EBD EBD EBD - - + * 4 SBCLK - BCLK BCKL BCLK - - + * 5 EICE - - - - TBEN TBEN + * 6 ECLK - ECLK ECLK ECLK - - + * 7 PAR PAR PAR PAR PAR STEN STEN + * 8 DOZE - DOZE DOZE DOZE - HBATEN + * 9 NAP - NAP NAP NAP NAP NAP + * 10 SLEEP - SLEEP SLEEP SLEEP SLEEP SLEEP + * 11 DPM - DPM DPM DPM DPM DPM + * 12 RISEG - - RISEG - - - + * 13 - - - EIEC EIEC BHTCLR BHTCLR + * 14 - - - - - XAEN XAEN + * 15 - NHR NHR NHR NHR NHR NHR + * 16 ICE ICE ICE ICE ICE ICE ICE + * 17 DCE DCE DCE DCE DCE DCE DCE + * 18 ILOCK ILOCK ILOCK ILOCK ILOCK ILOCK ILOCK + * 19 DLOCK DLOCK DLOCK DLOCK DLOCK DLOCK DLOCK + * 20 ICFI ICFI ICFI ICFI ICFI ICFI ICFI + * 21 DCFI DCFI DCFI DCFI DCFI DCFI DCFI + * 22 - - SPD SPD SPG SPD SPD + * 23 - - IFEM IFTT IFTT - XBSEN + * 24 - SIE SGE SGE SGE SGE SGE + * 25 - - DCFA DCFA DCFA - - + * 26 - - BTIC BTIC BTIC BTIC BTIC + * 27 FBIOB - - - - LRSTK LRSTK + * 28 - - ABE - - FOLD FOLD + * 29 - BHT BHT BHT BHT BHT BHT + * 30 - - - NOPDST NOPDST NOPDST NOPDST + * 31 NOOPTI - NOOPTI NOPTI NOPTI NOPTI NOPTI + * + * 604: ECP = Enable cache parity checking + * 604: SIE = Serial instruction execution disable + * 604: BTCD = Branch target address cache disable + * 7450: TBEN = Time Base Enable + * 7450: STEN = Software table lookup enable + * 7450: BHTCLR = Branch history clear + * 7450: XAEN = Extended Addressing Enabled + * 7450: LRSTK = Link Register Stack Enable + * 7450: FOLD = Branch folding enable + * 7457: HBATEN = High BAT Enable + * 7457: XBSEN = Extended BAT Block Size Enable + */ + +#define HID1_EMCP 0x80000000 /* Machine Check Signal Enable */ +#define HID1_EBA 0x20000000 /* 60x bus address parity checking */ +#define HID1_EBD 0x10000000 /* 60x bus data parity checking */ +#define HID1_BCLK 0x08000000 /* CLK_OUT */ +#define HID1_ECLK 0x02000000 /* CLK_OUT */ +#define HID1_PAR 0x01000000 /* Disable precharge for ... */ +#define HID1_DFS4 0x00800000 /* Dynamic freq scaling / 4 (7448) */ +#define HID1_DFS2 0x00400000 /* Dynamic freq scaling / 2 (7447A) */ + +#endif /* _POWERPC_HID_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/ieee.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/ieee.h new file mode 100644 index 0000000000..30d5caed1d --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/ieee.h @@ -0,0 +1,119 @@ +/* $OpenBSD: ieee.h,v 1.5 2008/09/07 20:36:07 martynas Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)ieee.h 8.1 (Berkeley) 6/11/93 + */ + +/* + * ieee.h defines the machine-dependent layout of the machine's IEEE + * floating point. It does *not* define (yet?) any of the rounding + * mode bits, exceptions, and so forth. + */ + +/* + * Define the number of bits in each fraction and exponent. + * + * k k+1 + * Note that 1.0 x 2 == 0.1 x 2 and that denorms are represented + * + * (-exp_bias+1) + * as fractions that look like 0.fffff x 2 . This means that + * + * -126 + * the number 0.10000 x 2 , for instance, is the same as the normalized + * + * -127 -128 + * float 1.0 x 2 . Thus, to represent 2 , we need one leading zero + * + * -129 + * in the fraction; to represent 2 , we need two, and so on. This + * + * (-exp_bias-fracbits+1) + * implies that the smallest denormalized number is 2 + * + * for whichever format we are talking about: for single precision, for + * + * -126 -149 + * instance, we get .00000000000000000000001 x 2 , or 1.0 x 2 , and + * + * -149 == -127 - 23 + 1. + */ +#define SNG_EXPBITS 8 +#define SNG_FRACBITS 23 + +#define DBL_EXPBITS 11 +#define DBL_FRACHBITS 20 +#define DBL_FRACLBITS 32 +#define DBL_FRACBITS 52 + +struct ieee_single { + u_int sng_sign:1; + u_int sng_exp:8; + u_int sng_frac:23; +}; + +struct ieee_double { + u_int dbl_sign:1; + u_int dbl_exp:11; + u_int dbl_frach:20; + u_int dbl_fracl; +}; + +/* + * Floats whose exponent is in [1..INFNAN) (of whatever type) are + * `normal'. Floats whose exponent is INFNAN are either Inf or NaN. + * Floats whose exponent is zero are either zero (iff all fraction + * bits are zero) or subnormal values. + * + * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its + * high fraction; if the bit is set, it is a `quiet NaN'. + */ +#define SNG_EXP_INFNAN 255 +#define DBL_EXP_INFNAN 2047 + +#if 0 +#define SNG_QUIETNAN (1 << 22) +#define DBL_QUIETNAN (1 << 19) +#endif + +/* + * Exponent biases. + */ +#define SNG_EXP_BIAS 127 +#define DBL_EXP_BIAS 1023 \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/ieeefp.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/ieeefp.h new file mode 100644 index 0000000000..c6f38a7a88 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/ieeefp.h @@ -0,0 +1,25 @@ +/* $OpenBSD: ieeefp.h,v 1.7 2004/05/03 16:53:24 drahn Exp $ */ +/* $NetBSD: ieeefp.h,v 1.2 1999/07/07 01:52:26 danw Exp $ */ +/* + * Written by J.T. Conklin, Apr 6, 1995 + * Public domain. + */ + +#ifndef _POWERPC_IEEEFP_H_ +#define _POWERPC_IEEEFP_H_ + +typedef int fp_except; +#define FP_X_IMP 0x01 /* imprecise (loss of precision) */ +#define FP_X_DZ 0x02 /* divide-by-zero exception */ +#define FP_X_UFL 0x04 /* underflow exception */ +#define FP_X_OFL 0x08 /* overflow exception */ +#define FP_X_INV 0x10 /* invalid operation exception */ + +typedef enum { + FP_RN=0, /* round to nearest representable number */ + FP_RZ=1, /* round to zero (truncate) */ + FP_RP=2, /* round toward positive infinity */ + FP_RM=3 /* round toward negative infinity */ +} fp_rnd; + +#endif /* _POWERPC_IEEEFP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/intr.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/intr.h new file mode 100644 index 0000000000..552a8e48d2 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/intr.h @@ -0,0 +1,170 @@ +/* $OpenBSD: intr.h,v 1.57 2025/05/10 09:54:17 visa Exp $ */ + +/* + * Copyright (c) 1997 Per Fogelstrom, Opsycon AB and RTMX Inc, USA. + * + * 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 under OpenBSD by + * Per Fogelstrom, Opsycon AB, Sweden for RTMX Inc, North Carolina USA. + * 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_INTR_H_ +#define _POWERPC_INTR_H_ + +#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_SCHED 11 +#define IPL_HIGH 12 +#define IPL_NUM 13 + +#define IPL_MPFLOOR IPL_TTY +#define IPL_MPSAFE 0x100 + +#define IST_NONE 0 +#define IST_PULSE 1 +#define IST_EDGE 2 +#define IST_LEVEL 3 + +#define __USE_MI_SOFTINTR + +#include + +#if defined(_KERNEL) && !defined(_LOCORE) + +#include +#include + +#define PPC_NIRQ 66 +#define PPC_CLK_IRQ 64 +#define PPC_STAT_IRQ 65 + +int splraise(int); +int spllower(int); +void splx(int); + +typedef int (ppc_splraise_t) (int); +typedef int (ppc_spllower_t) (int); +typedef void (ppc_splx_t) (int); + +extern struct ppc_intr_func { + ppc_splraise_t *raise; + ppc_spllower_t *lower; + ppc_splx_t *x; +}ppc_intr_func; + +extern int ppc_smask[IPL_NUM]; + +void ppc_smask_init(void); +char *ppc_intr_typename(int type); + +void do_pending_int(void); + +/* SPL asserts */ +#ifdef DIAGNOSTIC +/* + * Although this function is implemented in MI code, it must be in this MD + * header because we don't want this header to include MI includes. + */ +void splassert_fail(int, int, const char *); +extern int splassert_ctl; +void splassert_check(int, const char *); +#define splassert(__wantipl) do { \ + if (splassert_ctl > 0) { \ + splassert_check(__wantipl, __func__); \ + } \ +} while (0) +#define splsoftassert(wantipl) splassert(wantipl) +#else +#define splassert(wantipl) do { /* nada */ } while (0) +#define splsoftassert(wantipl) do { /* nada */ } while (0) +#endif + +#define set_sint(p) atomic_setbits_int(&curcpu()->ci_ipending, p) + +#define splbio() splraise(IPL_BIO) +#define splnet() splraise(IPL_NET) +#define spltty() splraise(IPL_TTY) +#define splaudio() splraise(IPL_AUDIO) +#define splclock() splraise(IPL_CLOCK) +#define splvm() splraise(IPL_VM) +#define splsched() splhigh() +#define splstatclock() splhigh() +#define splsoftclock() splraise(IPL_SOFTCLOCK) +#define splsoftnet() splraise(IPL_SOFTNET) +#define splsofttty() splraise(IPL_SOFTTTY) + +#define SI_TO_IRQBIT(x) (1 << (x)) + +void softintr(int); +void dosoftint(int); + +#define splhigh() splraise(IPL_HIGH) +#define spl0() spllower(IPL_NONE) + +/* + * Interrupt control struct used to control the ICU setup. + */ + +struct intrhand { + TAILQ_ENTRY(intrhand) ih_list; + int (*ih_fun)(void *); + void *ih_arg; + struct evcount ih_count; + int ih_type; + int ih_level; + int ih_flags; + int ih_irq; + const char *ih_what; +}; + +struct intrq { + TAILQ_HEAD(, intrhand) iq_list; /* handler list */ + int iq_ipl; /* IPL_ to mask while handling */ + int iq_ist; /* share type */ +}; + +extern int ppc_configed_intr_cnt; +#define MAX_PRECONF_INTR 16 +extern struct intrhand ppc_configed_intr[MAX_PRECONF_INTR]; + +void intr_barrier(void *); + +#define PPC_IPI_NOP 0 +#define PPC_IPI_DDB 1 + +void ppc_send_ipi(struct cpu_info *, int); + +#endif /* _LOCORE */ +#endif /* _POWERPC_INTR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/kcore.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/kcore.h new file mode 100644 index 0000000000..d7df5d2d29 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/kcore.h @@ -0,0 +1,46 @@ +/* $OpenBSD: kcore.h,v 1.4 2005/12/17 07:31:26 miod Exp $ */ +/* $NetBSD: kcore.h,v 1.1 1996/09/30 16:34:26 ws Exp $ */ + +/*- + * Copyright (C) 1996 Wolfgang Solfrank. + * Copyright (C) 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_KCORE_H_ +#define _POWERPC_KCORE_H_ + +#define NPHYS_RAM_SEGS 4 + +typedef struct cpu_kcore_hdr { + paddr_t ptable; /* Phys address of page table */ + paddr_t potable; /* Phys address of page overflow table */ + phys_ram_seg_t ram_segs[NPHYS_RAM_SEGS]; +} cpu_kcore_hdr_t; + +#endif /* _POWERPC_KCORE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/limits.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/limits.h new file mode 100644 index 0000000000..399509a33a --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/limits.h @@ -0,0 +1,52 @@ +/* $OpenBSD: limits.h,v 1.18 2015/04/30 13:42:08 millert Exp $ */ +/* $NetBSD: limits.h,v 1.1 1996/09/30 16:34:28 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. + */ + +#ifndef _POWERPC_LIMITS_H_ +#define _POWERPC_LIMITS_H_ + +#include + +#if __POSIX_VISIBLE || __XPG_VISIBLE +#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 /* _POWERPC_LIMITS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/mplock.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/mplock.h new file mode 100644 index 0000000000..1c6d42553d --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/mplock.h @@ -0,0 +1,52 @@ +/* $OpenBSD: mplock.h,v 1.7 2024/09/04 07:54:51 mglocker Exp $ */ + +/* + * Copyright (c) 2004 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 _POWERPC_MPLOCK_H_ +#define _POWERPC_MPLOCK_H_ + +#define __USE_MI_MPLOCK + +/* + * __ppc_lock exists because pte_spill_r() can't use __mp_lock. + * Really simple spinlock implementation with recursive capabilities. + * Correctness is paramount, no fanciness allowed. + */ + +struct __ppc_lock { + struct cpu_info *volatile mpl_cpu; + long mpl_count; +}; + +#ifndef _LOCORE + +#define PPC_LOCK_INITIALIZER { NULL, 0 } + +void __ppc_lock(struct __ppc_lock *); +void __ppc_unlock(struct __ppc_lock *); + +#endif + +#endif /* !_POWERPC_MPLOCK_H */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/mutex.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/mutex.h new file mode 100644 index 0000000000..a3f8e6dd19 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/mutex.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mutex.h,v 1.9 2018/01/25 15:06:29 mpi Exp $ */ + +#define __USE_MI_MUTEX \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/param.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/param.h new file mode 100644 index 0000000000..435fcbea4c --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/param.h @@ -0,0 +1,74 @@ +/* $OpenBSD: param.h,v 1.39 2023/12/14 13:26:49 claudio 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_PARAM_H_ +#define _POWERPC_PARAM_H_ + +#ifdef _KERNEL +#ifndef _LOCORE +#include +#endif /* _LOCORE */ +#endif + +#define MACHINE_ARCH "powerpc" +#define _MACHINE_ARCH powerpc +#define MID_MACHINE MID_POWERPC + +#define PAGE_SHIFT 12 +#define PAGE_SIZE (1 << PAGE_SHIFT) +#define PAGE_MASK (PAGE_SIZE - 1) + +#ifdef _KERNEL + +#define NBPG PAGE_SIZE +#define PGSHIFT PAGE_SHIFT +#define PGOFSET PAGE_MASK + +#define UPAGES 4 /* 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 (32 * 1024) /* max cluster allocation */ + +/* + * Fixed segments + */ +#define PPC_USER_SR 13 +#define PPC_KERNEL_SR 14 +#define PPC_KERNEL_SEG0 0xfffff0 +#define PPC_KERNEL_SEGMENT (PPC_KERNEL_SEG0 + PPC_KERNEL_SR) +#define PPC_USER_ADDR ((void *)(PPC_USER_SR << ADDR_SR_SHIFT)) + +#endif /* _KERNEL */ + +#endif /* _POWERPC_PARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/pcb.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/pcb.h new file mode 100644 index 0000000000..4bfd679c47 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/pcb.h @@ -0,0 +1,67 @@ +/* $OpenBSD: pcb.h,v 1.15 2015/07/29 18:52:44 miod Exp $ */ +/* $NetBSD: pcb.h,v 1.1 1996/09/30 16:34:29 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. + */ +#ifndef _POWERPC_PCB_H_ +#define _POWERPC_PCB_H_ + +#include + + +typedef struct __faultbuf { + int pc; + int sp; + int cr; + int regs[20]; +} faultbuf; + +struct pcb { + struct pmap *pcb_pm; /* pmap of our vmspace */ + struct pmap *pcb_pmreal; /* real address of above */ + register_t pcb_sp; /* saved SP */ + faultbuf *pcb_onfault; /* For use during copyin/copyout */ + int pcb_flags; +#define PCB_FPU 1 /* Process had FPU initialized */ + struct fpu { + double fpr[32]; + double fpcsr; /* FPCSR stored as double for easier access */ + } pcb_fpu; /* Floating point processor */ + struct vreg *pcb_vr; /* Vector unit */ + struct cpu_info *pcb_fpcpu; + struct cpu_info *pcb_veccpu; +}; + +#ifdef _KERNEL +extern struct proc *fpuproc; +int setfault(faultbuf *env) __returns_twice; +#endif +#endif /* _POWERPC_PCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/pio.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/pio.h new file mode 100644 index 0000000000..3b9e4602b4 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/pio.h @@ -0,0 +1,181 @@ +/* $OpenBSD: pio.h,v 1.9 2002/09/15 09:01:59 deraadt Exp $ */ + +/* + * Copyright (c) 1997 Per Fogelstrom, Opsycon AB and RTMX Inc, USA. + * + * 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 under OpenBSD by + * Per Fogelstrom Opsycon AB for RTMX Inc, North Carolina, USA. + * 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_PIO_H_ +#define _POWERPC_PIO_H_ +/* + * I/O macros. + */ +void *mapiodev(paddr_t pa, psize_t len); +void unmapiodev(void * va, psize_t len); + +static __inline void +__outb(volatile u_int8_t *a, int v) +{ + *a = v; + __asm__ volatile("eieio"); +} + +static __inline void +__outw(volatile u_int16_t *a, u_int16_t v) +{ + *a = v; + __asm__ volatile("eieio"); +} + +static __inline void +__outl(volatile u_int32_t *a, int v) +{ + *a = v; + __asm__ volatile("eieio"); +} + +static __inline void +__outwrb(volatile u_int16_t *a, u_int16_t v) +{ + u_int32_t _p_ = (u_int32_t)a; + + __asm__ volatile("sthbrx %0, 0, %1" :: "r"(v), "r"(_p_)); + __asm__ volatile("eieio"); +} + +static __inline void +__outlrb(volatile u_int32_t *a, u_int32_t v) +{ + u_int32_t _p_ = (u_int32_t)a; + + __asm__ volatile("stwbrx %0, 0, %1" :: "r"(v), "r"(_p_)); + __asm__ volatile("eieio"); +} + +static __inline u_int8_t +__inb(volatile u_int8_t *a) +{ + u_int8_t _v_; + + __asm__ volatile("eieio"); + _v_ = *a; + return _v_; +} + +static __inline u_int16_t +__inw(volatile u_int16_t *a) +{ + u_int16_t _v_; + + __asm__ volatile("eieio"); + _v_ = *a; + return _v_; +} + +static __inline u_int32_t +__inl(volatile u_int32_t *a) +{ + u_int32_t _v_; + + __asm__ volatile("eieio"); + _v_ = *a; + return _v_; +} + +static __inline u_int16_t +__inwrb(volatile u_int16_t *a) +{ + u_int16_t _v_; + u_int32_t _p_ = (u_int32_t)a; + + __asm__ volatile("eieio"); + __asm__ volatile("lhbrx %0, 0, %1" : "=r"(_v_) : "r"(_p_)); + return _v_; +} + +static __inline u_int32_t +__inlrb(volatile u_int32_t *a) +{ + u_int32_t _v_; + u_int32_t _p_ = (u_int32_t)a; + + __asm__ volatile("eieio"); + __asm__ volatile("lwbrx %0, 0, %1" : "=r"(_v_) : "r"(_p_)); + return _v_; +} + + +#define outb(a,v) (__outb((volatile u_int8_t *)(a), v)) +#define out8(a,v) outb(a,v) +#define outw(a,v) (__outw((volatile u_int16_t *)(a), v)) +#define out16(a,v) outw(a,v) +#define outl(a,v) (__outl((volatile u_int32_t *)(a), v)) +#define out32(a,v) outl(a,v) +#define inb(a) (__inb((volatile u_int8_t *)(a))) +#define in8(a) inb(a) +#define inw(a) (__inw((volatile u_int16_t *)(a))) +#define in16(a) inw(a) +#define inl(a) (__inl((volatile u_int32_t *)(a))) +#define in32(a) inl(a) + +#define out8rb(a,v) outb(a,v) +#define outwrb(a,v) (__outwrb((volatile u_int16_t *)(a), v)) +#define out16rb(a,v) outwrb(a,v) +#define outlrb(a,v) (__outlrb((volatile u_int32_t *)(a), v)) +#define out32rb(a,v) outlrb(a,v) +#define in8rb(a) inb(a) +#define inwrb(a) (__inwrb((volatile u_int16_t *)(a))) +#define in16rb(a) inwrb(a) +#define inlrb(a) (__inlrb((volatile u_int32_t *)(a))) +#define in32rb(a) inlrb(a) + +#ifdef DEBUG_SPEC +static __inline void +__flash_led(bits, count) + int bits; +{ + int i, v = 0; + + if(bits == 0) { + v = 1; bits = 3; + } + bits &= 3; + count += count; + v |= (*(volatile u_int8_t *)(MPC106_V_ISA_IO_SPACE + 0x01f4)) & ~3; + while(count--) { + v ^= bits; + for(i = 100000; i > 0; i--) + *(volatile u_int8_t *)(MPC106_V_ISA_IO_SPACE + 0x01f4) = v; + } + *(u_int8_t *)(MPC106_V_ISA_IO_SPACE + 0x01f4) &= ~3; +} +#endif /* DEBUG */ + +#endif /*_POWERPC_PIO_H_*/ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/pmap.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/pmap.h new file mode 100644 index 0000000000..4311f9d159 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/pmap.h @@ -0,0 +1,186 @@ +/* $OpenBSD: pmap.h,v 1.66 2024/06/18 12:37:29 jsg Exp $ */ +/* $NetBSD: pmap.h,v 1.1 1996/09/30 16:34:29 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. + */ + +#ifndef _POWERPC_PMAP_H_ +#define _POWERPC_PMAP_H_ + +#include + +/* + * Segment registers + */ +#ifndef _LOCORE +typedef u_int sr_t; +#endif /* _LOCORE */ +#define SR_TYPE 0x80000000 +#define SR_SUKEY 0x40000000 +#define SR_PRKEY 0x20000000 +#define SR_NOEXEC 0x10000000 +#define SR_VSID 0x00ffffff +/* + * bit + * 3 2 2 2 2 1 1 1 1 1 0 + * 1 8 7 4 0 9 6 5 2 1 0 + * |XXXX|XXXX XXXX|XXXX XXXX|XXXX XXXX XXXX + * + * bits 28 - 31 contain SR + * bits 20 - 27 contain L1 for VtoP translation + * bits 12 - 19 contain L2 for VtoP translation + * bits 0 - 11 contain page offset + */ +#ifndef _LOCORE +/* V->P mapping data */ +#define VP_SR_SIZE 16 +#define VP_SR_MASK (VP_SR_SIZE-1) +#define VP_SR_POS 28 +#define VP_IDX1_SIZE 256 +#define VP_IDX1_MASK (VP_IDX1_SIZE-1) +#define VP_IDX1_POS 20 +#define VP_IDX2_SIZE 256 +#define VP_IDX2_MASK (VP_IDX2_SIZE-1) +#define VP_IDX2_POS 12 + +/* cache flags */ +#define PMAP_CACHE_DEFAULT 0 /* WB cache managed mem, devices not */ +#define PMAP_CACHE_CI 1 /* cache inhibit */ +#define PMAP_CACHE_WT 2 /* writethru */ +#define PMAP_CACHE_WB 3 /* writeback */ + +#include +#include + +#ifdef _KERNEL + +/* + * Pmap stuff + */ +struct pmap { + sr_t pm_sr[16]; /* segments used in this pmap */ + struct pmapvp *pm_vp[VP_SR_SIZE]; /* virtual to physical table */ + u_int32_t pm_exec[16]; /* segments used in this pmap */ + int pm_refs; /* ref count */ + struct pmap_statistics pm_stats; /* pmap statistics */ + struct mutex pm_mtx; /* protect VP table */ +}; + +/* + * Segment handling stuff + */ +#define PPC_SEGMENT_LENGTH 0x10000000 +#define PPC_SEGMENT_MASK 0xf0000000 + +/* + * Some system constants + */ +#ifndef NPMAPS +#define NPMAPS 32768 /* Number of pmaps in system */ +#endif + +typedef struct pmap *pmap_t; + +extern struct pmap kernel_pmap_; +#define pmap_kernel() (&kernel_pmap_) + + +#define pmap_clear_modify(pg) pmap_clear_attrs((pg), PG_PMAP_MOD) +#define pmap_clear_reference(pg) pmap_clear_attrs((pg), PG_PMAP_REF) +#define pmap_is_modified(pg) pmap_test_attrs((pg), PG_PMAP_MOD) +#define pmap_is_referenced(pg) pmap_test_attrs((pg), PG_PMAP_REF) + +#define pmap_unwire(pm, va) +#define pmap_update(pmap) /* nothing (yet) */ + +#define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count) + +/* + * Alternate mapping methods for pool. + * Really simple. 0x0->0x80000000 contain 1->1 mappings of the physical + * memory. - XXX + */ +#define pmap_map_direct(pg) ((vaddr_t)VM_PAGE_TO_PHYS(pg)) +#define pmap_unmap_direct(va) PHYS_TO_VM_PAGE((paddr_t)va) +#define __HAVE_PMAP_DIRECT + +void pmap_bootstrap(u_int kernelstart, u_int kernelend); +void pmap_enable_mmu(); + +int pmap_clear_attrs(struct vm_page *, unsigned int); +int pmap_test_attrs(struct vm_page *, unsigned int); + +void pmap_release(struct pmap *); + +#ifdef ALTIVEC +int pmap_copyinsn(pmap_t, vaddr_t, uint32_t *); +#endif + +void pmap_real_memory(vaddr_t *start, vsize_t *size); + +int pte_spill_v(struct pmap *pm, u_int32_t va, u_int32_t dsisr, int exec_fault); +int reserve_dumppages(caddr_t p); + +#define pmap_init_percpu() do { /* nothing */ } while (0) +#define pmap_unuse_final(p) /* nothing */ +#define pmap_remove_holes(vm) do { /* nothing */ } while (0) + +#define PMAP_CHECK_COPYIN (ppc_proc_is_64b == 0) + +#define PMAP_STEAL_MEMORY + +#define PG_PMAP_MOD PG_PMAP0 +#define PG_PMAP_REF PG_PMAP1 +#define PG_PMAP_EXE PG_PMAP2 +#define PG_PMAP_UC PG_PMAP3 + +/* + * MD flags that we use for pmap_enter (in the pa): + */ +#define PMAP_PA_MASK ~((paddr_t)PAGE_MASK) /* to remove the flags */ +#define PMAP_NOCACHE 0x1 /* map uncached */ +#define PMAP_WT 0x2 /* map write-through */ + +#endif /* _KERNEL */ + +struct vm_page_md { + struct mutex pv_mtx; + LIST_HEAD(,pte_desc) pv_list; +}; + +#define VM_MDPAGE_INIT(pg) do { \ + mtx_init(&(pg)->mdpage.pv_mtx, IPL_VM); \ + LIST_INIT(&((pg)->mdpage.pv_list)); \ +} while (0) + +#endif /* _LOCORE */ + +#endif /* _POWERPC_PMAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/powerpc.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/powerpc.h new file mode 100644 index 0000000000..39eac3da66 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/powerpc.h @@ -0,0 +1,53 @@ +/* $OpenBSD: powerpc.h,v 1.8 2014/04/01 20:42:39 mpi Exp $ */ +/* $NetBSD: powerpc.h,v 1.1 1996/09/30 16:34:30 ws Exp $ */ + +/* + * Copyright (C) 1996 Wolfgang Solfrank. + * Copyright (C) 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_POWERPC_H_ +#define _POWERPC_POWERPC_H_ + +struct mem_region { + vaddr_t start; + vsize_t size; +}; + +void ppc_mem_regions(struct mem_region **, struct mem_region **); + +struct dumpmem { + vaddr_t start; + vsize_t end; +}; + +extern struct dumpmem dumpmem[VM_PHYSSEG_MAX]; +extern u_int ndumpmem; + +#endif /* _POWERPC_POWERPC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/proc.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/proc.h new file mode 100644 index 0000000000..03f932b2b4 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/proc.h @@ -0,0 +1,45 @@ +/* $OpenBSD: proc.h,v 1.8 2017/04/13 03:52:25 guenther Exp $ */ +/* $NetBSD: proc.h,v 1.1 1996/09/30 16:34:31 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. + */ + +#ifndef _POWERPC_PROC_H_ +#define _POWERPC_PROC_H_ + +/* + * Machine-dependent part of the proc structure + */ +struct mdproc { + volatile int md_astpending; +}; + +#endif /* _POWERPC_PROC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/profile.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/profile.h new file mode 100644 index 0000000000..19c9818c87 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/profile.h @@ -0,0 +1,78 @@ +/* $OpenBSD: profile.h,v 1.7 2013/08/19 08:39:30 mpi Exp $ */ + +/* + * Copyright (c) 1998 Dale Rahn. + * All rights reserved. + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#define MCOUNT \ + __asm__(" \ + .section \".text\" \n\ + .align 2 \n\ + .globl _mcount \n\ + .type _mcount,@function \n\ + _mcount: \n\ + lwz 11, 4(1) \n\ + mflr 0 \n\ + stw 0, 4(1) \n\ + stwu 1, -48(1) \n\ + stw 3, 8(1) \n\ + stw 4, 12(1) \n\ + stw 5, 16(1) \n\ + stw 6, 20(1) \n\ + stw 7, 24(1) \n\ + stw 8, 28(1) \n\ + stw 9, 32(1) \n\ + stw 10,36(1) \n\ + stw 11,40(1) \n\ + mr 4, 0 \n\ + mr 3, 11 \n\ + bl __mcount \n\ + lwz 3, 8(1) \n\ + lwz 4, 12(1) \n\ + lwz 5, 16(1) \n\ + lwz 6, 20(1) \n\ + lwz 7, 24(1) \n\ + lwz 8, 28(1) \n\ + lwz 9, 32(1) \n\ + lwz 10,36(1) \n\ + lwz 11,40(1) \n\ + addi 1, 1, 48 \n\ + lwz 0, 4(1) \n\ + mtlr 11 \n\ + stw 11, 4(1) \n\ + mtctr 0 \n\ + bctr \n\ + .Lfe2: \n\ + .size _mcount, .Lfe2-_mcount \n\ + "); +#define _MCOUNT_DECL static void __mcount +#ifdef _KERNEL +#define MCOUNT_ENTER \ + __asm volatile("mfmsr %0" : "=r"(s)); \ + s &= ~PSL_POW; \ + __asm volatile("mtmsr %0" :: "r"(s & ~PSL_EE)) + +#define MCOUNT_EXIT \ + __asm volatile("mtmsr %0" :: "r"(s)) +#endif /* _KERNEL */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/psl.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/psl.h new file mode 100644 index 0000000000..020a93e43f --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/psl.h @@ -0,0 +1,78 @@ +/* $OpenBSD: psl.h,v 1.5 2001/11/13 14:31:52 drahn Exp $ */ +/* $NetBSD: psl.h,v 1.1 1996/09/30 16:34:32 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. + */ +#ifndef _POWERPC_PSL_H_ +#define _POWERPC_PSL_H_ + +/* + * Flags in MSR: + */ +#define PSL_VEC 0x02000000 /* AltiVec vector unit available */ +#define PSL_POW 0x00040000 +#define PSL_ILE 0x00010000 +#define PSL_EE 0x00008000 +#define PSL_PR 0x00004000 +#define PSL_FP 0x00002000 +#define PSL_ME 0x00001000 +#define PSL_FE0 0x00000800 +#define PSL_SE 0x00000400 +#define PSL_BE 0x00000200 +#define PSL_FE1 0x00000100 +#define PSL_IP 0x00000040 +#define PSL_IR 0x00000020 +#define PSL_DR 0x00000010 +#define PSL_RI 0x00000002 +#define PSL_LE 0x00000001 + +/* + * Floating-point exception modes: + */ +#define PSL_FE_DIS 0 +#define PSL_FE_NONREC PSL_FE1 +#define PSL_FE_REC PSL_FE0 +#define PSL_FE_PREC (PSL_FE0 | PSL_FE1) +#define PSL_FE_DFLT PSL_FE_DIS + +/* + * Note that PSL_POW and PSL_ILE are not in the saved copy of the MSR + */ +#define PSL_MBO 0 +#define PSL_MBZ 0 + +#define PSL_USERSET (PSL_EE | PSL_PR | PSL_ME | PSL_IR | PSL_DR | PSL_RI) + +#define PSL_USERSTATIC (PSL_USERSET | PSL_IP | 0x87c0008c) + +#include + +#endif /* _POWERPC_PSL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/pte.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/pte.h new file mode 100644 index 0000000000..239b19bd19 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/pte.h @@ -0,0 +1,129 @@ +/* $OpenBSD: pte.h,v 1.11 2023/01/31 01:27:58 gkoehler Exp $ */ +/* $NetBSD: pte.h,v 1.1 1996/09/30 16:34:32 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. + */ + +#ifndef _POWERPC_PTE_H_ +#define _POWERPC_PTE_H_ + +/* + * Page Table Entries + */ +#ifndef _LOCORE +struct pte_32 { + u_int32_t pte_hi; + u_int32_t pte_lo; +}; +struct pte_64 { + u_int64_t pte_hi; + u_int64_t pte_lo; +}; +#endif /* _LOCORE */ + +/* 32 bit */ +/* High word: */ +#define PTE_VALID_32 0x80000000 +#define PTE_VSID_SHIFT_32 7 +#define PTE_HID_32 0x00000040 +#define PTE_API_32 0x0000003f + /* Low word: */ +#define PTE_RPGN_32 0xfffff000 +#define PTE_REF_32 0x00000100 +#define PTE_CHG_32 0x00000080 +#define PTE_WIM_32 0x00000078 +#define PTE_W_32 0x00000040 +#define PTE_EXE_32 0x00000040 /* only used in pmap_attr, same as PTE_W */ +#define PTE_I_32 0x00000020 +#define PTE_M_32 0x00000010 +#define PTE_G_32 0x00000008 +#define PTE_PP_32 0x00000003 +#define PTE_RO_32 0x00000003 +#define PTE_RW_32 0x00000002 + + +/* 64 bit */ +/* High doubleword: */ +#define PTE_VALID_64 0x0000000000000001ULL +#define PTE_AVPN_SHIFT_64 7 +#define PTE_AVPN_64 0xffffffffffffff80ULL +#define PTE_API_SHIFT_64 7 +#define PTE_API_64 0x0000000000000f80ULL +#define PTE_VSID_SHIFT_64 12 +#define PTE_VSID_64 0xfffffffffffff000ULL +#define PTE_HID_64 0x0000000000000002ULL +/* Low word: */ +#define PTE_RPGN_64 0x3ffffffffffff000ULL +#define PTE_AC_64 0x0000000000000200ULL +#define PTE_REF_64 0x0000000000000100ULL +#define PTE_CHG_64 0x0000000000000080ULL +#define PTE_WIMG_64 0x0000000000000078ULL +#define PTE_W_64 0x0000000000000040ULL +#define PTE_EXE_64 PTE_W +#define PTE_I_64 0x0000000000000020ULL +#define PTE_M_64 0x0000000000000010ULL +#define PTE_G_64 0x0000000000000008ULL +#define PTE_N_64 0x0000000000000004ULL +#define PTE_PP_64 0x0000000000000003ULL +#define PTE_RO_64 0x0000000000000003ULL +#define PTE_RW_64 0x0000000000000002ULL + +/* + * Extract bits from address + */ +#define ADDR_SR_SHIFT 28 +#define ADDR_PIDX 0x0ffff000 +#define ADDR_PIDX_SHIFT 12 +#define ADDR_API_SHIFT_32 22 +#define ADDR_API_SHIFT_64 16 +#define ADDR_POFF 0x00000fff + +/* + * Bits in DSISR: + */ +#define DSISR_DIRECT 0x80000000 +#define DSISR_NOTFOUND 0x40000000 +#define DSISR_PROTECT 0x08000000 +#define DSISR_INVRX 0x04000000 +#define DSISR_STORE 0x02000000 +#define DSISR_DABR 0x00400000 +#define DSISR_SEGMENT 0x00200000 +#define DSISR_EAR 0x00100000 + +/* + * Bits in SRR1 on ISI: + */ +#define ISSRR1_NOTFOUND 0x40000000 +#define ISSRR1_DIRECT 0x10000000 +#define ISSRR1_PROTECT 0x08000000 +#define ISSRR1_SEGMENT 0x00200000 + +#endif /* _POWERPC_PTE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/ptrace.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/ptrace.h new file mode 100644 index 0000000000..862dac3282 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/ptrace.h @@ -0,0 +1,45 @@ +/* $OpenBSD: ptrace.h,v 1.3 2006/05/15 21:02:44 kettenis Exp $ */ +/* $NetBSD: ptrace.h,v 1.7 1995/01/26 19:47:10 mycroft 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_ + +/* + * powerpc-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_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/reg.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/reg.h new file mode 100644 index 0000000000..76fae6878b --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/reg.h @@ -0,0 +1,76 @@ +/* $OpenBSD: reg.h,v 1.11 2014/09/08 01:47:06 guenther 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_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/reloc.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/reloc.h new file mode 100644 index 0000000000..4142aadeea --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/reloc.h @@ -0,0 +1,91 @@ +/* $OpenBSD: reloc.h,v 1.4 2011/03/23 16:54:36 pirofti Exp $ */ +/* $NetBSD: reloc.h,v 1.1 1996/09/30 16:34:33 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. + */ +#ifndef _POWERPC_RELOC_H_ +#define _POWERPC_RELOC_H_ + +/* + * Quite a number of relocation types + */ +enum reloc_type { + RELOC_NONE, + RELOC_32, + RELOC_24, + RELOC_16, + RELOC_16_LO, + RELOC_16_HI, /* RELOC_ADDIS = 5 */ + RELOC_16_HA, + RELOC_14, + RELOC_14_TAKEN, + RELOC_14_NTAKEN, + RELOC_REL24, /* RELOC_BRANCH = 10 */ + RELOC_REL14, + RELOC_REL14_TAKEN, + RELOC_REL14_NTAKEN, + RELOC_GOT16, + RELOC_GOT16_LO, + RELOC_GOT16_HI, + RELOC_GOT16_HA, + RELOC_PLT24, + RELOC_COPY, + RELOC_GLOB_DAT, + RELOC_JMP_SLOT, + RELOC_RELATIVE, + RELOC_LOCAL24PC, + RELOC_U32, + RELOC_U16, + RELOC_REL32, + RELOC_PLT32, + RELOC_PLTREL32, + RELOC_PLT16_LO, + RELOC_PLT16_HI, + RELOC_PLT16_HA, + /* ABI defines this as 32nd entry, but we ignore this, at least for now */ + RELOC_SDAREL, + + RELOC_TLSC = 67, + RELOC_DTPMOD32, + RELOC_TPREL16, + RELOC_TPREL16_LO, + RELOC_TPREL16_HI, + RELOC_TPREL16_HA, + RELOC_TPREL32, + RELOC_DTPREL16, + RELOC_DTPREL16_LO, + RELOC_DTPREL16_HI, + RELOC_DTPREL16_HA, + RELOC_DTPREL32, + RELOC_MAX +}; + +#endif /* _POWERPC_RELOC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/setjmp.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/setjmp.h new file mode 100644 index 0000000000..aa4351855d --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/setjmp.h @@ -0,0 +1,4 @@ +/* $OpenBSD: setjmp.h,v 1.2 2001/03/29 18:52:19 drahn Exp $ */ +/* $NetBSD: setjmp.h,v 1.1 1996/09/30 16:34:34 ws Exp $ */ + +#define _JBLEN 100 \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/signal.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/signal.h new file mode 100644 index 0000000000..8cbb54002c --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/signal.h @@ -0,0 +1,72 @@ +/* $OpenBSD: signal.h,v 1.9 2016/05/10 18:39:47 deraadt Exp $ */ +/* $NetBSD: signal.h,v 1.1 1996/09/30 16:34:34 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. + */ +#ifndef _POWERPC_SIGNAL_H_ +#define _POWERPC_SIGNAL_H_ + +#include + +typedef int sig_atomic_t; + +#if __BSD_VISIBLE || __XPG_VISIBLE >= 420 +#include + +/* + * 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_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/spinlock.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/spinlock.h new file mode 100644 index 0000000000..66d10ac571 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/spinlock.h @@ -0,0 +1,10 @@ +/* $OpenBSD: spinlock.h,v 1.4 2017/09/05 02:40:54 guenther Exp $ */ + +#ifndef _POWERPC_SPINLOCK_H_ +#define _POWERPC_SPINLOCK_H_ + +#define _ATOMIC_LOCK_UNLOCKED (0) +#define _ATOMIC_LOCK_LOCKED (1) +typedef int _atomic_lock_t; + +#endif \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/tcb.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/tcb.h new file mode 100644 index 0000000000..b9a1108d54 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/tcb.h @@ -0,0 +1,42 @@ +/* $OpenBSD: tcb.h,v 1.6 2019/07/02 20:42:45 kettenis Exp $ */ + +/* + * Copyright (c) 2011 Philip Guenther + * + * 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_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc-openbsd-eabihf/powerpc/trap.h b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/trap.h new file mode 100644 index 0000000000..93abaa4f42 --- /dev/null +++ b/lib/libc/include/powerpc-openbsd-eabihf/powerpc/trap.h @@ -0,0 +1,87 @@ +/* $OpenBSD: trap.h,v 1.9 2022/10/22 00:58:56 gkoehler Exp $ */ +/* $NetBSD: trap.h,v 1.1 1996/09/30 16:34:35 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. + */ +#ifndef _POWERPC_TRAP_H_ +#define _POWERPC_TRAP_H_ + +#define EXC_RSVD 0x0000 /* Reserved */ +#define EXC_RST 0x0100 /* Reset */ +#define EXC_MCHK 0x0200 /* Machine Check */ +#define EXC_DSI 0x0300 /* Data Storage Interrupt */ +#define EXC_ISI 0x0400 /* Instruction Storage Interrupt */ +#define EXC_EXI 0x0500 /* External Interrupt */ +#define EXC_ALI 0x0600 /* Alignment Interrupt */ +#define EXC_PGM 0x0700 /* Program Interrupt */ +#define EXC_FPU 0x0800 /* Floating-point Unavailable */ +#define EXC_DECR 0x0900 /* Decrementer Interrupt */ +#define EXC_SC 0x0c00 /* System Call */ +#define EXC_TRC 0x0d00 /* Trace */ +#define EXC_FPA 0x0e00 /* Floating-point Assist */ +#define EXC_PERF 0x0f00 /* Performance Monitoring */ +#define EXC_VEC 0x0f20 /* AltiVec Unavailable */ +#define EXC_BPT 0x1300 /* Instruction Breakpoint */ +#define EXC_SMI 0x1400 /* System Management Interrupt */ +#define EXC_VECAST_G4 0x1600 /* AltiVec Assist */ +#define EXC_VECAST_G5 0x1700 /* AltiVec Assist */ + +/* And these are only on the 603: */ +#define EXC_IMISS 0x1000 /* Instruction translation miss */ +#define EXC_DLMISS 0x1100 /* Data load translation miss */ +#define EXC_DSMISS 0x1200 /* Data store translation miss */ + +#define EXC_END 0x3000 /* End of exception vectors */ + +#define EXC_AST 0x3000 /* Fake AST vector */ + +/* Trap was in user mode */ +#define EXC_USER 0x10000 + +/* + * EXC_ALI sets bits in the DSISR and DAR to provide enough + * information to recover from the unaligned access without needing to + * parse the offending instruction. This includes certain bits of the + * opcode, and information about what registers are used. The opcode + * indicator values below come from Appendix F of Book III of "The + * PowerPC Architecture". + */ + +#define EXC_ALI_OPCODE_INDICATOR(dsisr) ((dsisr >> 10) & 0x7f) +#define EXC_ALI_LFD 0x09 +#define EXC_ALI_STFD 0x0b +#define EXC_ALI_DCBZ 0x5f + +/* Macros to extract register information */ +#define EXC_ALI_RST(dsisr) ((dsisr >> 5) & 0x1f) /* source or target */ +#define EXC_ALI_RA(dsisr) (dsisr & 0x1f) + +#endif /* _POWERPC_TRAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/frame.h b/lib/libc/include/powerpc64-openbsd-none/frame.h new file mode 100644 index 0000000000..afb0dfa295 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/frame.h @@ -0,0 +1,104 @@ +/* $OpenBSD: frame.h,v 1.5 2020/07/13 22:37:37 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 _MACHDEP_FRAME_H +#define _MACHDEP_FRAME_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; + __register_t srr0; + __register_t srr1; + __register_t vrsave; + __register_t dar; /* dar & dsisr are only filled on a DSI trap */ + __register_t dsisr; + __register_t exc; +}; + +/* + * This is to ensure alignment of the stackpointer + */ +#define FRAMELEN roundup(sizeof(struct trapframe) + 32, 16) + +struct callframe { + register_t cf_sp; + register_t cf_cr; + register_t cf_lr; + register_t cf_toc; +}; + +struct sigframe { + int sf_signum; + siginfo_t *sf_sip; + struct sigcontext sf_sc; + siginfo_t sf_si; +}; + +struct switchframe { + register_t sf_sp; + register_t sf_cr; + register_t sf_lr; /* unused */ + register_t sf_toc; /* unused */ + register_t sf_r14; + register_t sf_r15; + register_t sf_r16; + register_t sf_r17; + register_t sf_r18; + register_t sf_r19; + register_t sf_r20; + register_t sf_r21; + register_t sf_r22; + register_t sf_r23; + register_t sf_r24; + register_t sf_r25; + register_t sf_r26; + register_t sf_r27; + register_t sf_r28; + register_t sf_r29; + register_t sf_r30; + register_t sf_r31; +}; + +#endif /* _MACHDEP_FRAME_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/_float.h b/lib/libc/include/powerpc64-openbsd-none/machine/_float.h new file mode 100644 index 0000000000..14a56d926e --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/_float.h @@ -0,0 +1,71 @@ +/* $OpenBSD: _float.h,v 1.1 2020/06/01 00:13:37 drahn Exp $ */ + +/* + * Copyright (c) 1989 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _MACHINE__FLOAT_H_ +#define _MACHINE__FLOAT_H_ + +#define __FLT_RADIX 2 /* b */ +#define __FLT_ROUNDS __flt_rounds() +#define __FLT_EVAL_METHOD 0 /* no promotions */ + +#define __FLT_MANT_DIG 24 /* p */ +#define __FLT_EPSILON 1.19209290E-07F /* b**(1-p) */ +#define __FLT_DIG 6 /* floor((p-1)*log10(b))+(b == 10) */ +#define __FLT_MIN_EXP (-125) /* emin */ +#define __FLT_MIN 1.17549435E-38F /* b**(emin-1) */ +#define __FLT_MIN_10_EXP (-37) /* ceil(log10(b**(emin-1))) */ +#define __FLT_MAX_EXP 128 /* emax */ +#define __FLT_MAX 3.40282347E+38F /* (1-b**(-p))*b**emax */ +#define __FLT_MAX_10_EXP 38 /* floor(log10((1-b**(-p))*b**emax)) */ + +#define __DBL_MANT_DIG 53 +#define __DBL_EPSILON 2.2204460492503131E-16 +#define __DBL_DIG 15 +#define __DBL_MIN_EXP (-1021) +#define __DBL_MIN 2.2250738585072014E-308 +#define __DBL_MIN_10_EXP (-307) +#define __DBL_MAX_EXP 1024 +#define __DBL_MAX 1.7976931348623157E+308 +#define __DBL_MAX_10_EXP 308 + +#define __LDBL_MANT_DIG DBL_MANT_DIG +#define __LDBL_EPSILON DBL_EPSILON +#define __LDBL_DIG DBL_DIG +#define __LDBL_MIN_EXP DBL_MIN_EXP +#define __LDBL_MIN DBL_MIN +#define __LDBL_MIN_10_EXP DBL_MIN_10_EXP +#define __LDBL_MAX_EXP DBL_MAX_EXP +#define __LDBL_MAX DBL_MAX +#define __LDBL_MAX_10_EXP DBL_MAX_10_EXP + +#define __DECIMAL_DIG 17 + +#endif /* _MACHINE__FLOAT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/_types.h b/lib/libc/include/powerpc64-openbsd-none/machine/_types.h new file mode 100644 index 0000000000..c8b810163d --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/_types.h @@ -0,0 +1,145 @@ +/* $OpenBSD: _types.h,v 1.4 2023/07/02 19:02:28 cheloha 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[22]; +} 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_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/apmvar.h b/lib/libc/include/powerpc64-openbsd-none/machine/apmvar.h new file mode 100644 index 0000000000..2c911df088 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/apmvar.h @@ -0,0 +1,122 @@ +/* $OpenBSD: apmvar.h,v 1.1 2020/07/15 22:46:51 deraadt Exp $ */ + +/* + * Copyright (c) 2001 Alexander Guy + * Copyright (c) 1995 John T. Kohl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef _POWERPC64_APMVAR_H_ +#define _POWERPC64_APMVAR_H_ + +#include + +/* Advanced Power Management (v1.0 and v1.1 specification) + * functions/defines/etc. + */ + +/* These definitions make up the heart of the user-land interface + * to the APM devices. + */ + +#define APM_AC_OFF 0x00 +#define APM_AC_ON 0x01 +#define APM_AC_BACKUP 0x02 +#define APM_AC_UNKNOWN 0xff +#define APM_BATT_HIGH 0x00 +#define APM_BATT_LOW 0x01 +#define APM_BATT_CRITICAL 0x02 +#define APM_BATT_CHARGING 0x03 +#define APM_BATT_UNKNOWN 0xff +#define APM_BATT_LIFE_UNKNOWN 0xff + +#define APM_NOEVENT 0x0000 +#define APM_STANDBY_REQ 0x0001 +#define APM_SUSPEND_REQ 0x0002 +#define APM_NORMAL_RESUME 0x0003 +#define APM_CRIT_RESUME 0x0004 /* suspend/resume happened + without us */ +#define APM_BATTERY_LOW 0x0005 +#define APM_POWER_CHANGE 0x0006 +#define APM_UPDATE_TIME 0x0007 +#define APM_CRIT_SUSPEND_REQ 0x0008 +#define APM_USER_STANDBY_REQ 0x0009 +#define APM_USER_SUSPEND_REQ 0x000A +#define APM_SYS_STANDBY_RESUME 0x000B +#define APM_CAPABILITY_CHANGE 0x000C /* apm v1.2 */ +#define APM_USER_HIBERNATE_REQ 0x000D +#define APM_EVENT_MASK 0xffff + +#define APM_EVENT_COMPOSE(t,i) ((((i) & 0x7fff) << 16)|((t) & APM_EVENT_MASK)) +#define APM_EVENT_TYPE(e) ((e) & APM_EVENT_MASK) +#define APM_EVENT_INDEX(e) ((e) >> 16) + +/* + * LP (Laptop Package) + * + * Copyright (C) 1994 by HOSOKAWA Tatsumi + * + * This software may be used, modified, copied, and distributed, in + * both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + */ + +#define APM_BATTERY_ABSENT 4 + +struct apm_power_info { + u_char battery_state; + u_char ac_state; + u_char battery_life; + u_char spare1; + u_int minutes_left; /* estimate */ + u_int spare2[6]; +}; + +struct apm_ctl { + u_int dev; + u_int mode; +}; + +#define APM_IOC_REJECT _IOW('A', 0, struct apm_event_info) /* reject request # */ +#define APM_IOC_STANDBY _IO('A', 1) /* put system into standby */ +#define APM_IOC_SUSPEND _IO('A', 2) /* put system into suspend */ +#define APM_IOC_GETPOWER _IOR('A', 3, struct apm_power_info) /* fetch battery state */ +#define APM_IOC_DEV_CTL _IOW('A', 5, struct apm_ctl) /* put device into mode */ +#define APM_IOC_PRN_CTL _IOW('A', 6, int ) /* driver power status msg */ +#define APM_PRINT_ON 0 /* driver power status displayed */ +#define APM_PRINT_OFF 1 /* driver power status not displayed */ +#define APM_PRINT_PCT 2 /* driver power status only displayed + if the percentage changes */ +#define APM_IOC_STANDBY_REQ _IO('A', 7) /* request standby */ +#define APM_IOC_SUSPEND_REQ _IO('A', 8) /* request suspend */ +#define APM_IOC_HIBERNATE _IO('A', 9) /* put system into hibernate */ + +#endif /* _POWERPC64_APMVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/asm.h b/lib/libc/include/powerpc64-openbsd-none/machine/asm.h new file mode 100644 index 0000000000..b630e137aa --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/asm.h @@ -0,0 +1,100 @@ +/* $OpenBSD: asm.h,v 1.7 2022/12/07 23:25:59 guenther Exp $ */ + +/* + * Copyright (c) 2020 Dale Rahn + * + * 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 _POWERPC64_ASM_H_ +#define _POWERPC64_ASM_H_ + +#define _C_LABEL(x) x +#define _ASM_LABEL(x) x + +#define _TMP_LABEL(x) .L_ ## x +#define _GEP_LABEL(x) .L_ ## x ## _gep0 +#define _LEP_LABEL(x) .L_ ## x ## _lep0 + +#define _ENTRY(x) \ + .text; .align 2; .globl x; .type x,@function; x: \ + _GEP_LABEL(x): \ + addis %r2, %r12, .TOC.-_GEP_LABEL(x)@ha; \ + addi %r2, %r2, .TOC.-_GEP_LABEL(x)@l; \ + _LEP_LABEL(x): \ + .localentry x, _LEP_LABEL(x)-_GEP_LABEL(x); + +#if defined(PROF) || defined(GPROF) +# define _PROF_PROLOGUE(y) \ + .section ".data"; \ + .align 2; \ +_TMP_LABEL(y):; \ + .long 0; \ + .section ".text"; \ + mflr %r0; \ + addis %r11, %r2, _TMP_LABEL(y)@toc@ha; \ + std %r0, 8(%r1); \ + addi %r0, %r11, _TMP_LABEL(y)@toc@l; \ + bl _mcount; +#else +# define _PROF_PROLOGUE(y) +#endif + +#define ENTRY(y) _ENTRY(y); _PROF_PROLOGUE(y) +#define ASENTRY(y) _ENTRY(y); _PROF_PROLOGUE(y) +#define END(y) .size y, . - y + +#define STRONG_ALIAS(alias,sym) \ + .global alias; .set alias,sym +#define WEAK_ALIAS(alias,sym) \ + .weak alias; .set alias,sym + +#if defined(_RET_PROTECTOR) +# define RETGUARD_SETUP(x, reg) \ + RETGUARD_SYMBOL(x); \ + mflr %r0; \ + addis reg, %r2, (__retguard_ ## x)@toc@ha; \ + ld reg, ((__retguard_ ## x)@toc@l)(reg); \ + xor reg, reg, %r0 +# define RETGUARD_CHECK(x, reg) \ + mflr %r0; \ + xor reg, reg, %r0; \ + addis %r12, %r2, (__retguard_ ## x)@toc@ha; \ + ld %r12, ((__retguard_ ## x)@toc@l)(%r12); \ + tdne reg, %r12 +# define RETGUARD_SAVE(reg, loc) \ + std reg, loc +# define RETGUARD_LOAD(reg, loc) \ + ld reg, loc +# define RETGUARD_SYMBOL(x) \ + .ifndef __retguard_ ## x; \ + .hidden __retguard_ ## x; \ + .type __retguard_ ## x,@object; \ + .pushsection .openbsd.randomdata.retguard,"aw",@progbits; \ + .weak __retguard_ ## x; \ + .p2align 3; \ + __retguard_ ## x: ; \ + .quad 0; \ + .size __retguard_ ## x, 8; \ + .popsection; \ + .endif +#else +# define RETGUARD_SETUP(x, reg) +# define RETGUARD_CHECK(x, reg) +# define RETGUARD_SAVE(reg, loc) +# define RETGUARD_LOAD(reg, loc) +# define RETGUARD_SYMBOL(x) +#endif + + +#endif /* !_POWERPC64_ASM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/atomic.h b/lib/libc/include/powerpc64-openbsd-none/machine/atomic.h new file mode 100644 index 0000000000..277291b926 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/atomic.h @@ -0,0 +1,292 @@ +/* $OpenBSD: atomic.h,v 1.3 2022/08/29 02:01:18 jsg 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: lwarx %0, 0, %2 \n" + " stwcx. %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_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/bus.h b/lib/libc/include/powerpc64-openbsd-none/machine/bus.h new file mode 100644 index 0000000000..626dcdbbca --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/bus.h @@ -0,0 +1,532 @@ +/* $OpenBSD: bus.h,v 1.5 2020/11/15 23:13:00 kettenis Exp $ */ +/* + * Copyright (c) 2003-2004 Opsycon AB Sweden. 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_BUS_H_ +#define _MACHINE_BUS_H_ + +#define CAT(a,b) a##b +#define CAT3(a,b,c) a##b##c + +/* + * Bus access types. + */ +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; +typedef struct bus_space bus_space_t; + +struct bus_space { + bus_addr_t bus_base; + void *bus_private; + uint8_t (*_space_read_1)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_1)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, uint8_t); + uint16_t (*_space_read_2)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_2)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, uint16_t); + uint32_t (*_space_read_4)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_4)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, uint32_t); + uint64_t (*_space_read_8)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_8)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, uint64_t); + void (*_space_read_raw_2)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); + void (*_space_write_raw_2)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); + void (*_space_read_raw_4)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); + void (*_space_write_raw_4)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); + void (*_space_read_raw_8)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); + void (*_space_write_raw_8)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); + int (*_space_map)(bus_space_tag_t , bus_addr_t, + bus_size_t, int, bus_space_handle_t *); + void (*_space_unmap)(bus_space_tag_t, bus_space_handle_t, + bus_size_t); + int (*_space_subregion)(bus_space_tag_t, bus_space_handle_t, + bus_size_t, bus_size_t, bus_space_handle_t *); + void * (*_space_vaddr)(bus_space_tag_t, bus_space_handle_t); + paddr_t (*_space_mmap)(bus_space_tag_t, bus_addr_t, off_t, + int, int); +}; + +#define bus_space_read_1(t, h, o) (*(t)->_space_read_1)((t), (h), (o)) +#define bus_space_read_2(t, h, o) (*(t)->_space_read_2)((t), (h), (o)) +#define bus_space_read_4(t, h, o) (*(t)->_space_read_4)((t), (h), (o)) +#define bus_space_read_8(t, h, o) (*(t)->_space_read_8)((t), (h), (o)) + +#define bus_space_write_1(t, h, o, v) (*(t)->_space_write_1)((t), (h), (o), (v)) +#define bus_space_write_2(t, h, o, v) (*(t)->_space_write_2)((t), (h), (o), (v)) +#define bus_space_write_4(t, h, o, v) (*(t)->_space_write_4)((t), (h), (o), (v)) +#define bus_space_write_8(t, h, o, v) (*(t)->_space_write_8)((t), (h), (o), (v)) + +#define bus_space_read_raw_2(t, h, o) \ + generic_space_read_2((t), (h), (o)) +#define bus_space_read_raw_4(t, h, o) \ + generic_space_read_4((t), (h), (o)) +#define bus_space_read_raw_8(t, h, o) \ + generic_space_read_8((t), (h), (o)) + +#define bus_space_write_raw_2(t, h, o, v) \ + generic_space_write_2((t), (h), (o), (v)) +#define bus_space_write_raw_4(t, h, o, v) \ + generic_space_write_4((t), (h), (o), (v)) +#define bus_space_write_raw_8(t, h, o, v) \ + generic_space_write_8((t), (h), (o), (v)) + +#define bus_space_read_raw_multi_2(t, h, a, b, l) \ + (*(t)->_space_read_raw_2)((t), (h), (a), (b), (l)) +#define bus_space_read_raw_multi_4(t, h, a, b, l) \ + (*(t)->_space_read_raw_4)((t), (h), (a), (b), (l)) +#define bus_space_read_raw_multi_8(t, h, a, b, l) \ + (*(t)->_space_read_raw_8)((t), (h), (a), (b), (l)) + +#define bus_space_write_raw_multi_2(t, h, a, b, l) \ + (*(t)->_space_write_raw_2)((t), (h), (a), (b), (l)) +#define bus_space_write_raw_multi_4(t, h, a, b, l) \ + (*(t)->_space_write_raw_4)((t), (h), (a), (b), (l)) +#define bus_space_write_raw_multi_8(t, h, a, b, l) \ + (*(t)->_space_write_raw_8)((t), (h), (a), (b), (l)) + +#define bus_space_map(t, o, s, c, p) (*(t)->_space_map)((t), (o), (s), (c), (p)) +#define bus_space_unmap(t, h, s) (*(t)->_space_unmap)((t), (h), (s)) +#define bus_space_subregion(t, h, o, s, p) \ + (*(t)->_space_subregion)((t), (h), (o), (s), (p)) + +#define BUS_SPACE_MAP_CACHEABLE 0x01 +#define BUS_SPACE_MAP_KSEG0 0x02 +#define BUS_SPACE_MAP_LINEAR 0x04 +#define BUS_SPACE_MAP_PREFETCHABLE 0x08 + +#define bus_space_vaddr(t, h) (*(t)->_space_vaddr)((t), (h)) +#define bus_space_mmap(t, a, o, p, f) \ + (*(t)->_space_mmap)((t), (a), (o), (p), (f)) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_multi(n,m) \ +static __inline void \ +CAT(bus_space_read_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_size_t o, CAT3(uint,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) \ + *x++ = CAT(bus_space_read_,n)(bst, bsh, o); \ +} + +bus_space_read_multi(1,8) +bus_space_read_multi(2,16) +bus_space_read_multi(4,32) +bus_space_read_multi(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_region(n,m) \ +static __inline void \ +CAT(bus_space_read_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, CAT3(uint,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) { \ + *x++ = CAT(bus_space_read_,n)(bst, bsh, ba); \ + ba += (n); \ + } \ +} + +bus_space_read_region(1,8) +bus_space_read_region(2,16) +bus_space_read_region(4,32) +bus_space_read_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_raw_region(n,m) \ +static __inline void \ +CAT(bus_space_read_raw_region_,n)(bus_space_tag_t bst, \ + bus_space_handle_t bsh, \ + bus_addr_t ba, uint8_t *x, size_t cnt) \ +{ \ + cnt >>= ((n) >> 1); \ + while (cnt--) { \ + CAT(bus_space_read_raw_multi_,n)(bst, bsh, ba, x, (n)); \ + ba += (n); \ + x += (n); \ + } \ +} + +bus_space_read_raw_region(2,16) +bus_space_read_raw_region(4,32) +bus_space_read_raw_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_multi(n,m) \ +static __inline void \ +CAT(bus_space_write_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_size_t o, const CAT3(uint,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) \ + CAT(bus_space_write_,n)(bst, bsh, o, *x++); \ +} + +bus_space_write_multi(1,8) +bus_space_write_multi(2,16) +bus_space_write_multi(4,32) +bus_space_write_multi(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_region(n,m) \ +static __inline void \ +CAT(bus_space_write_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, const CAT3(uint,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) { \ + CAT(bus_space_write_,n)(bst, bsh, ba, *x++); \ + ba += (n); \ + } \ +} + +bus_space_write_region(1,8) +bus_space_write_region(2,16) +bus_space_write_region(4,32) +bus_space_write_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_raw_region(n,m) \ +static __inline void \ +CAT(bus_space_write_raw_region_,n)(bus_space_tag_t bst, \ + bus_space_handle_t bsh, \ + bus_addr_t ba, const uint8_t *x, size_t cnt) \ +{ \ + cnt >>= ((n) >> 1); \ + while (cnt--) { \ + CAT(bus_space_write_raw_multi_,n)(bst, bsh, ba, x, (n)); \ + ba += (n); \ + x += (n); \ + } \ +} + +bus_space_write_raw_region(2,16) +bus_space_write_raw_region(4,32) +bus_space_write_raw_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_set_region(n,m) \ +static __inline void \ +CAT(bus_space_set_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, CAT3(uint,m,_t) x, size_t cnt) \ +{ \ + while (cnt--) { \ + CAT(bus_space_write_,n)(bst, bsh, ba, x); \ + ba += (n); \ + } \ +} + +bus_space_set_region(1,8) +bus_space_set_region(2,16) +bus_space_set_region(4,32) +bus_space_set_region(8,64) + +/*----------------------------------------------------------------------------*/ +static __inline void +bus_space_copy_1(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + char *s = (char *)(h1 + o1); + char *d = (char *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + + +static __inline void +bus_space_copy_2(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + short *s = (short *)(h1 + o1); + short *d = (short *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + +static __inline void +bus_space_copy_4(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + int *s = (int *)(h1 + o1); + int *d = (int *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + +static __inline void +bus_space_copy_8(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + int64_t *s = (int64_t *)(h1 + o1); + int64_t *d = (int64_t *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + +/*----------------------------------------------------------------------------*/ +/* + * Bus read/write barrier methods. + * + * void bus_space_barrier(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * bus_size_t len, int flags); + * + */ +static inline void +bus_space_barrier(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, + bus_size_t length, int flags) +{ + __asm__ volatile ("eieio" ::: "memory"); +} +#define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */ +#define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */ + +#define BUS_DMA_WAITOK 0x0000 +#define BUS_DMA_NOWAIT 0x0001 +#define BUS_DMA_ALLOCNOW 0x0002 +#define BUS_DMA_COHERENT 0x0008 +#define BUS_DMA_BUS1 0x0010 /* placeholders for bus functions... */ +#define BUS_DMA_BUS2 0x0020 +#define BUS_DMA_BUS3 0x0040 +#define BUS_DMA_BUS4 0x0080 +#define BUS_DMA_READ 0x0100 /* mapping is device -> memory only */ +#define BUS_DMA_WRITE 0x0200 /* mapping is memory -> device only */ +#define BUS_DMA_STREAMING 0x0400 /* hint: sequential, unidirectional */ +#define BUS_DMA_ZERO 0x0800 /* zero memory in dmamem_alloc */ +#define BUS_DMA_NOCACHE 0x1000 +#define BUS_DMA_64BIT 0x2000 /* device handles 64bit dva */ + +/* Forwards needed by prototypes below. */ +struct mbuf; +struct proc; +struct uio; + +#define BUS_DMASYNC_POSTREAD 0x0001 +#define BUS_DMASYNC_POSTWRITE 0x0002 +#define BUS_DMASYNC_PREREAD 0x0004 +#define BUS_DMASYNC_PREWRITE 0x0008 + +typedef struct machine_bus_dma_tag *bus_dma_tag_t; +typedef struct machine_bus_dmamap *bus_dmamap_t; + +/* + * bus_dma_segment_t + * + * Describes a single contiguous DMA transaction. Values + * are suitable for programming into DMA registers. + */ +struct machine_bus_dma_segment { + bus_addr_t ds_addr; /* DMA address */ + bus_size_t ds_len; /* length of transfer */ + + paddr_t _ds_paddr; /* CPU address */ + vaddr_t _ds_vaddr; /* CPU address */ +}; +typedef struct machine_bus_dma_segment bus_dma_segment_t; + +/* + * bus_dma_tag_t + * + * A machine-dependent opaque type describing the implementation of + * DMA for a given bus. + */ + +struct machine_bus_dma_tag { + void *_cookie; /* cookie used in the guts */ + int _flags; /* misc. flags */ + + /* + * DMA mapping methods. + */ + int (*_dmamap_create)(bus_dma_tag_t , bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); + void (*_dmamap_destroy)(bus_dma_tag_t , bus_dmamap_t); + int (*_dmamap_load)(bus_dma_tag_t , bus_dmamap_t, void *, + bus_size_t, struct proc *, int); + int (*_dmamap_load_mbuf)(bus_dma_tag_t , bus_dmamap_t, + struct mbuf *, int); + int (*_dmamap_load_uio)(bus_dma_tag_t , bus_dmamap_t, + struct uio *, int); + int (*_dmamap_load_raw)(bus_dma_tag_t , bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); + int (*_dmamap_load_buffer)(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int, paddr_t *, int *, int); + void (*_dmamap_unload)(bus_dma_tag_t , bus_dmamap_t); + void (*_dmamap_sync)(bus_dma_tag_t , bus_dmamap_t, + bus_addr_t, bus_size_t, int); + + /* + * DMA memory utility functions. + */ + int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); + void (*_dmamem_free)(bus_dma_tag_t, bus_dma_segment_t *, int); + int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); + void (*_dmamem_unmap)(bus_dma_tag_t, caddr_t, size_t); + paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *, + int, off_t, int, int); + + /* + * internal memory address translation information. + */ + bus_addr_t _dma_mask; +}; + +#define bus_dmamap_create(t, s, n, m, b, f, p) \ + (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p)) +#define bus_dmamap_destroy(t, p) \ + (*(t)->_dmamap_destroy)((t), (p)) +#define bus_dmamap_load(t, m, b, s, p, f) \ + (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f)) +#define bus_dmamap_load_mbuf(t, m, b, f) \ + (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f)) +#define bus_dmamap_load_uio(t, m, u, f) \ + (*(t)->_dmamap_load_uio)((t), (m), (u), (f)) +#define bus_dmamap_load_raw(t, m, sg, n, s, f) \ + (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f)) +#define bus_dmamap_unload(t, p) \ + (*(t)->_dmamap_unload)((t), (p)) +#define bus_dmamap_sync(t, p, a, l, o) \ + (void)((t)->_dmamap_sync ? \ + (*(t)->_dmamap_sync)((t), (p), (a), (l), (o)) : (void)0) + +#define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \ + (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f)) +#define bus_dmamem_free(t, sg, n) \ + (*(t)->_dmamem_free)((t), (sg), (n)) +#define bus_dmamem_map(t, sg, n, s, k, f) \ + (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f)) +#define bus_dmamem_unmap(t, k, s) \ + (*(t)->_dmamem_unmap)((t), (k), (s)) +#define bus_dmamem_mmap(t, sg, n, o, p, f) \ + (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f)) + +int _dmamap_create(bus_dma_tag_t, bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); +void _dmamap_destroy(bus_dma_tag_t, bus_dmamap_t); +int _dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int); +int _dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, struct mbuf *, int); +int _dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, struct uio *, int); +int _dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); +int _dmamap_load_buffer(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int, paddr_t *, int *, int); +void _dmamap_unload(bus_dma_tag_t, bus_dmamap_t); +void _dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, + bus_size_t, int); + +int _dmamem_alloc(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); +void _dmamem_free(bus_dma_tag_t, bus_dma_segment_t *, int); +int _dmamem_map(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); +void _dmamem_unmap(bus_dma_tag_t, caddr_t, size_t); +paddr_t _dmamem_mmap(bus_dma_tag_t, bus_dma_segment_t *, int, off_t, int, int); +int _dmamem_alloc_range(bus_dma_tag_t, bus_size_t, bus_size_t, bus_size_t, + bus_dma_segment_t *, int, int *, int, paddr_t, paddr_t); + +/* + * bus_dmamap_t + * + * Describes a DMA mapping. + */ +struct machine_bus_dmamap { + /* + * PRIVATE MEMBERS: not for use by machine-independent code. + */ + bus_size_t _dm_size; /* largest DMA transfer mappable */ + int _dm_segcnt; /* number of segs this map can map */ + bus_size_t _dm_maxsegsz; /* largest possible segment */ + bus_size_t _dm_boundary; /* don't cross this */ + int _dm_flags; /* misc. flags */ + + void *_dm_cookie; /* cookie for bus-specific functions */ + + /* + * PUBLIC MEMBERS: these are used by machine-independent code. + */ + bus_size_t dm_mapsize; /* size of the mapping */ + int dm_nsegs; /* # valid segments in mapping */ + bus_dma_segment_t dm_segs[1]; /* segments; variable length */ +}; + +int generic_space_map(bus_space_tag_t, bus_addr_t, bus_size_t, int, + bus_space_handle_t *); +void generic_space_unmap(bus_space_tag_t, bus_space_handle_t, bus_size_t); +int generic_space_region(bus_space_tag_t, bus_space_handle_t, bus_size_t, + bus_size_t, bus_space_handle_t *); +void *generic_space_vaddr(bus_space_tag_t, bus_space_handle_t); +paddr_t generic_space_mmap(bus_space_tag_t, bus_addr_t, off_t, int, int); +uint8_t generic_space_read_1(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint16_t generic_space_read_2(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint32_t generic_space_read_4(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint64_t generic_space_read_8(bus_space_tag_t, bus_space_handle_t, bus_size_t); +void generic_space_write_1(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint8_t); +void generic_space_write_2(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint16_t); +void generic_space_write_4(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint32_t); +void generic_space_write_8(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint64_t); +void generic_space_read_raw_2(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_raw_2(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); +void generic_space_read_raw_4(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_raw_4(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); +void generic_space_read_raw_8(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_raw_8(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); + +uint16_t little_space_read_2(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint32_t little_space_read_4(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint64_t little_space_read_8(bus_space_tag_t, bus_space_handle_t, bus_size_t); +void little_space_write_2(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint16_t); +void little_space_write_4(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint32_t); +void little_space_write_8(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint64_t); + +#endif /* _MACHINE_BUS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/cdefs.h b/lib/libc/include/powerpc64-openbsd-none/machine/cdefs.h new file mode 100644 index 0000000000..dcf667bff9 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/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 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_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/conf.h b/lib/libc/include/powerpc64-openbsd-none/machine/conf.h new file mode 100644 index 0000000000..bed3c41fe6 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/conf.h @@ -0,0 +1,24 @@ +#include + +#define mmread mmrw +#define mmwrite mmrw +cdev_decl(mm); + +cdev_decl(opalcons); + +/* open, close, ioctl */ +#define cdev_kexec_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) nullop, 0, \ + (dev_type_mmap((*))) enodev } + +/* open, close, ioctl */ +#define cdev_openprom_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) nullop, 0, \ + (dev_type_mmap((*))) enodev } + +cdev_decl(kexec); +cdev_decl(openprom); \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/cpu.h b/lib/libc/include/powerpc64-openbsd-none/machine/cpu.h new file mode 100644 index 0000000000..f5e0e18115 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/cpu.h @@ -0,0 +1,234 @@ +/* $OpenBSD: cpu.h,v 1.39 2024/11/28 18:54:36 gkoehler Exp $ */ + +/* + * Copyright (c) 2020 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_CPU_H_ +#define _MACHINE_CPU_H_ + +/* + * User-visible definitions + */ + +/* + * CTL_MACHDEP definitions. + */ +#define CPU_ALTIVEC 1 /* altivec is present */ +#define CPU_MAXID 2 /* number of valid machdep ids */ + +#define CTL_MACHDEP_NAMES { \ + { 0, 0 }, \ + { "altivec", CTLTYPE_INT }, \ +} + +#ifdef _KERNEL + +/* + * Kernel-only definitions + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +struct cpu_info { + struct device *ci_dev; + struct cpu_info *ci_next; + struct schedstate_percpu ci_schedstate; + + uint32_t ci_cpuid; + uint32_t ci_pir; + int ci_node; + + struct proc *ci_curproc; + struct pcb *ci_curpcb; + + struct slb ci_kernel_slb[32]; + paddr_t ci_user_slb_pa; + register_t ci_slbsave[18]; + char ci_slbstack[1024]; + +#define CPUSAVE_LEN 9 + register_t ci_tempsave[CPUSAVE_LEN]; + register_t ci_idle_sp_save; + + struct clockqueue ci_queue; + + volatile int ci_cpl; + volatile int ci_dec_deferred; + uint32_t ci_ipending; + uint32_t ci_idepth; +#ifdef DIAGNOSTIC + int ci_mutex_level; +#endif + int ci_want_resched; + + uint32_t ci_randseed; + +#ifdef MULTIPROCESSOR + struct srp_hazard ci_srp_hazards[SRP_HAZARD_NUM]; + void *ci_initstack_end; + void *ci_ipi; + int ci_ipi_reason; + volatile int ci_flags; +#endif + +#ifdef DDB + volatile int ci_ddb_paused; +#define CI_DDB_RUNNING 0 +#define CI_DDB_SHOULDSTOP 1 +#define CI_DDB_STOPPED 2 +#define CI_DDB_ENTERDDB 3 +#define CI_DDB_INDDB 4 +#endif + char ci_panicbuf[512]; +}; + +#define CPUF_PRIMARY (1 << 0) +#define CPUF_AP (1 << 1) +#define CPUF_IDENTIFY (1 << 2) +#define CPUF_IDENTIFIED (1 << 3) +#define CPUF_PRESENT (1 << 4) +#define CPUF_GO (1 << 5) +#define CPUF_RUNNING (1 << 6) + +extern struct cpu_info cpu_info[]; +extern struct cpu_info *cpu_info_primary; + +static __inline struct cpu_info * +curcpu(void) +{ + struct cpu_info *ci; + __asm volatile ("mfsprg0 %0" : "=r"(ci)); + return ci; +} + +#define CPU_INFO_ITERATOR int + +#ifndef MULTIPROCESSOR + +#define MAXCPUS 1 +#define CPU_IS_PRIMARY(ci) 1 +#define CPU_IS_RUNNING(ci) 1 +#define cpu_number() 0 + +#define CPU_INFO_UNIT(ci) 0 +#define CPU_INFO_FOREACH(cii, ci) \ + for (cii = 0, ci = curcpu(); ci != NULL; ci = NULL) + +#define cpu_kick(ci) +#define cpu_unidle(ci) + +#else + +#define MAXCPUS 48 +#define CPU_IS_PRIMARY(ci) ((ci) == cpu_info_primary) +#define CPU_IS_RUNNING(ci) ((ci)->ci_flags & CPUF_RUNNING) +#define cpu_number() (curcpu()->ci_cpuid) + +#define CPU_INFO_UNIT(ci) ((ci)->ci_dev ? (ci)->ci_dev->dv_unit : 0) +#define CPU_INFO_FOREACH(cii, ci) \ + for (cii = 0, ci = &cpu_info[0]; cii < ncpus; cii++, ci++) + +void cpu_kick(struct cpu_info *); +void cpu_unidle(struct cpu_info *); +void cpu_boot_secondary_processors(void); + +extern void (*ul_setperf)(int); +void mp_setperf(int); + +#endif + +#define clockframe trapframe + +#define CLKF_INTR(frame) (curcpu()->ci_idepth > 1) +#define CLKF_USERMODE(frame) (frame->srr1 & PSL_PR) +#define CLKF_PC(frame) (frame->srr0) + +#define aston(p) ((p)->p_md.md_astpending = 1) +#define need_proftick(p) aston(p) + +void signotify(struct proc *); + +#define CPU_BUSY_CYCLE() __asm volatile ("" ::: "memory") + +#define curpcb curcpu()->ci_curpcb + +void cpu_init_features(void); +void cpu_init(void); + +#define cpu_idle_enter() do { /* nothing */ } while (0) +#define cpu_idle_leave() do { /* nothing */ } while (0) +extern uint64_t cpu_idle_state_psscr; +extern void (*cpu_idle_cycle_fcn)(void); + +static inline unsigned int +cpu_rnd_messybits(void) +{ + uint64_t tb; + + __asm volatile("mftb %0" : "=r" (tb)); + return ((tb >> 32) ^ tb); +} + +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 PROC_STACK(p) ((p)->p_md.md_regs->fixreg[1]) +#define PROC_PC(p) ((p)->p_md.md_regs->srr0) + +void proc_trampoline(void); + +static inline void +intr_enable(void) +{ + mtmsr(mfmsr() | PSL_EE); +} + +static inline u_long +intr_disable(void) +{ + u_long msr; + + msr = mfmsr(); + mtmsr(msr & ~PSL_EE); + return msr; +} + +static inline void +intr_restore(u_long msr) +{ + mtmsr(msr); +} + +#endif /* _KERNEL */ + +#ifdef MULTIPROCESSOR +#include +#endif /* MULTIPROCESSOR */ + +#endif /* _MACHINE_CPU_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/cpufunc.h b/lib/libc/include/powerpc64-openbsd-none/machine/cpufunc.h new file mode 100644 index 0000000000..161e89a9b8 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/cpufunc.h @@ -0,0 +1,222 @@ +/* $OpenBSD: cpufunc.h,v 1.11 2023/01/25 09:53:53 kettenis Exp $ */ + +/* + * Copyright (c) 2020 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_CPUFUNC_H_ +#define _MACHINE_CPUFUNC_H_ + +static inline void +eieio(void) +{ + __asm volatile ("eieio" ::: "memory"); +} + +static inline void +isync(void) +{ + __asm volatile ("isync" ::: "memory"); +} + +static inline void +ptesync(void) +{ + __asm volatile ("ptesync" ::: "memory"); +} + +static inline void +sync(void) +{ + __asm volatile ("sync" ::: "memory"); +} + +static inline void +slbia(void) +{ + __asm volatile ("slbia"); +} + +static inline void +slbie(uint64_t esid) +{ + __asm volatile ("slbie %0" :: "r"(esid)); +} + +static inline uint64_t +slbmfee(uint64_t entry) +{ + uint64_t value; + __asm volatile ("slbmfee %0, %1" : "=r"(value) : "r"(entry)); + return value; +} + +static inline void +slbmte(uint64_t slbv, uint64_t slbe) +{ + __asm volatile ("slbmte %0, %1" :: "r"(slbv), "r"(slbe)); +} + +static inline void +tlbie(uint64_t ava) +{ + __asm volatile ("tlbie %0, %1" :: "r"(ava), "r"(0)); +} + +static inline void +tlbiel(uint64_t ava) +{ + __asm volatile ("tlbiel %0" :: "r"(ava)); +} + +static inline void +tlbsync(void) +{ + __asm volatile ("tlbsync" ::: "memory"); +} + +static inline uint64_t +mfmsr(void) +{ + uint64_t value; + __asm volatile ("mfmsr %0" : "=r"(value)); + return value; +} + +static inline void +mtmsr(uint64_t value) +{ + __asm volatile ("mtmsr %0" :: "r"(value)); +} + +static inline uint64_t +mftb(void) +{ + uint64_t value; + __asm volatile ("mftb %0" : "=r"(value)); + return value; +} + +static inline uint32_t +mfdsisr(void) +{ + uint32_t value; + __asm volatile ("mfdsisr %0" : "=r"(value)); + return value; +} + +static inline uint64_t +mfdar(void) +{ + uint64_t value; + __asm volatile ("mfdar %0" : "=r"(value)); + return value; +} + +static inline void +mtdec(uint32_t value) +{ + __asm volatile ("mtdec %0" :: "r"(value)); +} + +static inline void +mtsdr1(uint64_t value) +{ + __asm volatile ("mtsdr1 %0" :: "r"(value)); +} + +static inline void +mtamr(uint64_t value) +{ + __asm volatile ("mtspr 29, %0" :: "r"(value)); +} + +static inline void +mtfscr(uint64_t value) +{ + __asm volatile ("mtspr 153, %0" :: "r"(value)); +} + +static inline void +mtuamor(uint64_t value) +{ + __asm volatile ("mtspr 157, %0" :: "r"(value)); +} + +static inline uint32_t +mfpvr(void) +{ + uint32_t value; + __asm volatile ("mfspr %0, 287" : "=r"(value)); + return value; +} + +static inline uint64_t +mflpcr(void) +{ + uint64_t value; + __asm volatile ("mfspr %0, 318" : "=r"(value)); + return value; +} + +static inline void +mtlpcr(uint64_t value) +{ + __asm volatile ("mtspr 318, %0" :: "r"(value)); +} + +#define LPCR_PECE 0x000040000001f000UL +#define LPCR_LPES 0x0000000000000008UL +#define LPCR_HVICE 0x0000000000000002UL + +static inline void +mtamor(uint64_t value) +{ + __asm volatile ("mtspr 349, %0" :: "r"(value)); +} + +static inline void +mtptcr(uint64_t value) +{ + __asm volatile ("mtspr 464, %0" :: "r"(value)); +} + +static inline uint64_t +mfpmsr(void) +{ + uint64_t value; + __asm volatile ("mfspr %0, 853" : "=r"(value)); + return value; +} + +static inline void +mtpmcr(uint64_t value) +{ + __asm volatile ("mtspr 884, %0" :: "r"(value)); +} + +static inline uint32_t +mfpir(void) +{ + uint32_t value; + __asm volatile ("mfspr %0, 1023" : "=r"(value)); + return value; +} + +extern int cacheline_size; + +void __syncicache(void *, size_t); + +#endif /* _MACHINE_CPUFUNC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/db_machdep.h b/lib/libc/include/powerpc64-openbsd-none/machine/db_machdep.h new file mode 100644 index 0000000000..caf96c25d3 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/db_machdep.h @@ -0,0 +1,86 @@ +/* $OpenBSD: db_machdep.h,v 1.6 2021/08/30 08:11:12 jasper Exp $*/ +/* $NetBSD: db_machdep.h,v 1.13 1996/04/29 20:50:08 leo Exp $ */ + +/* + * Mach Operating System + * Copyright (c) 1992 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +/* + * Machine-dependent defines for new kernel debugger. + */ +#ifndef _MACHINE_DB_MACHDEP_H_ +#define _MACHINE_DB_MACHDEP_H_ + +#include +#include +#include +#include + +typedef long db_expr_t; /* expression - signed */ +typedef struct trapframe db_regs_t; +extern db_regs_t ddb_regs; /* register state */ + +#define PC_REGS(regs) ((regs)->srr0) +#define SET_PC_REGS(regs, value) PC_REGS(regs) = (value) + +#define BKPT_INST 0x7C810808 /* breakpoint instruction */ + +#define BKPT_SIZE (4) /* size of breakpoint inst */ +#define BKPT_SET(inst) (BKPT_INST) + +#define db_clear_single_step(regs) ((regs)->srr1 &= ~PSL_SE) +#define db_set_single_step(regs) ((regs)->srr1 |= PSL_SE) + +#define T_BREAKPOINT 0xffff +#define IS_BREAKPOINT_TRAP(type, code) ((type) == T_BREAKPOINT) +#define IS_WATCHPOINT_TRAP(type, code) 0 + +#define M_RTS 0xfc0007fe +#define I_RTS 0x4c000020 +#define M_BC 0xfc000000 +#define I_BC 0x40000000 +#define M_B 0xfc000000 +#define I_B 0x50000000 +#define M_RFI 0xfc0007fe +#define I_RFI 0x4c000064 + +#define inst_trap_return(ins) (((ins)&M_RFI) == I_RFI) +#define inst_return(ins) (((ins)&M_RTS) == I_RTS) +#define inst_call(ins) (((ins)&M_BC ) == I_BC || \ + ((ins)&M_B ) == I_B ) + +struct trapframe; +void db_ktrap(int, db_regs_t *); + +#define DDB_STATE_NOT_RUNNING 0 +#define DDB_STATE_RUNNING 1 +#define DDB_STATE_EXITING 2 + +/* + * We define some of our own commands + */ +#define DB_MACHINE_COMMANDS + +#endif /* _MACHINE_DB_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/disklabel.h b/lib/libc/include/powerpc64-openbsd-none/machine/disklabel.h new file mode 100644 index 0000000000..3d198e06b9 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/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 + * + * 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_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/elf.h b/lib/libc/include/powerpc64-openbsd-none/machine/elf.h new file mode 100644 index 0000000000..d1a121fff9 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/elf.h @@ -0,0 +1,66 @@ +/* $OpenBSD: elf.h,v 1.3 2025/02/19 18:25:03 jca Exp $ */ + +/* + * This file is in the public domain. + */ + +#ifndef _MACHINE_ELF_H_ +#define _MACHINE_ELF_H_ + +/* + * CPU Feature Attributes + * + * These are defined in the PowerPC ELF ABI for the AT_HWCAP vector, + * and are exported to userland via the elf_aux_info(3) function. + */ + +#ifdef _KERNEL +# define __HAVE_CPU_HWCAP +# define __HAVE_CPU_HWCAP2 +extern unsigned long hwcap; +extern unsigned long hwcap2; +#endif /* _KERNEL */ + +#define PPC_FEATURE_32 0x80000000 /* Always true */ +#define PPC_FEATURE_64 0x40000000 /* Defined on a 64-bit CPU */ +#define PPC_FEATURE_601_INSTR 0x20000000 +#define PPC_FEATURE_HAS_ALTIVEC 0x10000000 +#define PPC_FEATURE_HAS_FPU 0x08000000 +#define PPC_FEATURE_HAS_MMU 0x04000000 +#define PPC_FEATURE_UNIFIED_CACHE 0x01000000 +#define PPC_FEATURE_HAS_SPE 0x00800000 +#define PPC_FEATURE_HAS_EFP_SINGLE 0x00400000 +#define PPC_FEATURE_HAS_EFP_DOUBLE 0x00200000 +#define PPC_FEATURE_NO_TB 0x00100000 +#define PPC_FEATURE_POWER4 0x00080000 +#define PPC_FEATURE_POWER5 0x00040000 +#define PPC_FEATURE_POWER5_PLUS 0x00020000 +#define PPC_FEATURE_CELL 0x00010000 +#define PPC_FEATURE_BOOKE 0x00008000 +#define PPC_FEATURE_SMT 0x00004000 +#define PPC_FEATURE_ICACHE_SNOOP 0x00002000 +#define PPC_FEATURE_ARCH_2_05 0x00001000 +#define PPC_FEATURE_HAS_DFP 0x00000400 +#define PPC_FEATURE_POWER6_EXT 0x00000200 +#define PPC_FEATURE_ARCH_2_06 0x00000100 +#define PPC_FEATURE_HAS_VSX 0x00000080 +#define PPC_FEATURE_TRUE_LE 0x00000002 +#define PPC_FEATURE_PPC_LE 0x00000001 + +#define PPC_FEATURE2_ARCH_2_07 0x80000000 +#define PPC_FEATURE2_HTM 0x40000000 +#define PPC_FEATURE2_DSCR 0x20000000 +#define PPC_FEATURE2_EBB 0x10000000 +#define PPC_FEATURE2_ISEL 0x08000000 +#define PPC_FEATURE2_TAR 0x04000000 +#define PPC_FEATURE2_HAS_VEC_CRYPTO 0x02000000 +#define PPC_FEATURE2_HTM_NOSC 0x01000000 +#define PPC_FEATURE2_ARCH_3_00 0x00800000 +#define PPC_FEATURE2_HAS_IEEE128 0x00400000 +#define PPC_FEATURE2_DARN 0x00200000 +#define PPC_FEATURE2_SCV 0x00100000 +#define PPC_FEATURE2_HTM_NOSUSPEND 0x00080000 +#define PPC_FEATURE2_ARCH_3_1 0x00040000 +#define PPC_FEATURE2_MMA 0x00020000 + +#endif /* !_MACHINE_ELF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/endian.h b/lib/libc/include/powerpc64-openbsd-none/machine/endian.h new file mode 100644 index 0000000000..2a92d0b2fd --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/endian.h @@ -0,0 +1,37 @@ +/* $OpenBSD: endian.h,v 1.3 2024/05/07 14:26:48 naddy 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_ + +#undef _BIG_ENDIAN /* XXX - gcc may define _BIG_ENDIAN too */ +#define _BYTE_ORDER _BIG_ENDIAN + +#ifndef __FROM_SYS__ENDIAN +#include +#endif + +#endif /* _MACHINE_ENDIAN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/exec.h b/lib/libc/include/powerpc64-openbsd-none/machine/exec.h new file mode 100644 index 0000000000..219d93c1d0 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/exec.h @@ -0,0 +1,36 @@ +/* $OpenBSD: exec.h,v 1.4 2021/03/11 11:16:59 jsg Exp $ */ + +/* + * Copyright (c) 2014 Patrick Wildt + * + * 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 ELFDATA2MSB +#define ELF_TARG_MACH EM_PPC64 + +/* Processor specific dynamic tag values. */ +#define DT_PPC64_GLINK 0x70000000 +#define DT_PPC64_OPT 0x70000003 + +#define DT_PROCNUM (DT_PPC64_OPT - DT_LOPROC + 1) + +#endif \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/fdt.h b/lib/libc/include/powerpc64-openbsd-none/machine/fdt.h new file mode 100644 index 0000000000..0401cf75fb --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/fdt.h @@ -0,0 +1,39 @@ +/* $OpenBSD: fdt.h,v 1.2 2020/10/30 13:07:48 kettenis Exp $ */ +/* + * Copyright (c) 2016 Patrick Wildt + * + * 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_FDT_H_ +#define _MACHINE_FDT_H_ + +#include + +struct fdt_attach_args { + const char *fa_name; + int fa_node; + bus_space_tag_t fa_iot; + bus_dma_tag_t fa_dmat; + struct fdt_reg *fa_reg; + int fa_nreg; + uint32_t *fa_intr; + int fa_nintr; + int fa_acells; + int fa_scells; +}; + +extern int stdout_node; +extern int stdout_speed; + +#endif /* _MACHINE_FDT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/fenv.h b/lib/libc/include/powerpc64-openbsd-none/machine/fenv.h new file mode 100644 index 0000000000..aadeaabeee --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/fenv.h @@ -0,0 +1,96 @@ +/* $OpenBSD: fenv.h,v 1.1 2020/06/28 08:19:34 kettenis Exp $ */ + +/* + * Copyright (c) 2011 Martynas Venckus + * + * 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_FENV_H_ +#define _MACHINE_FENV_H_ + +/* + * Each symbol representing a floating point exception expands to an integer + * constant expression with values, such that bitwise-inclusive ORs of _all + * combinations_ of the constants result in distinct values. + * + * We use such values that allow direct bitwise operations on FPU registers. + */ +#define FE_INEXACT 0x02000000 +#define FE_DIVBYZERO 0x04000000 +#define FE_UNDERFLOW 0x08000000 +#define FE_OVERFLOW 0x10000000 +#define FE_INVALID 0x20000000 +#define _FE_INVALID_SOFT 0x00000400 +#define _FE_INVALID_ALL 0x01f80700 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * exception constants defined above. + */ +#define FE_ALL_EXCEPT (FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | \ + FE_OVERFLOW | FE_INVALID) +#define _MASK_SHIFT 22 + +/* + * Each symbol representing the rounding direction, expands to an integer + * constant expression whose value is distinct non-negative value. + * + * We use such values that allow direct bitwise operations on FPU registers. + */ +#define FE_TONEAREST 0x0 +#define FE_TOWARDZERO 0x1 +#define FE_UPWARD 0x2 +#define FE_DOWNWARD 0x3 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * rounding direction constants defined above. + */ +#define _ROUND_MASK (FE_TONEAREST | FE_TOWARDZERO | FE_UPWARD | \ + FE_DOWNWARD) + +/* + * fenv_t represents the entire floating-point environment. + */ +typedef unsigned int fenv_t; + +/* + * The following constant represents the default floating-point environment + * (that is, the one installed at program startup) and has type pointer to + * const-qualified fenv_t. + * + * It can be used as an argument to the functions within the header + * that manage the floating-point environment, namely fesetenv() and + * feupdateenv(). + */ +__BEGIN_DECLS +extern fenv_t __fe_dfl_env; +__END_DECLS +#define FE_DFL_ENV ((const fenv_t *)&__fe_dfl_env) + +/* + * fexcept_t represents the floating-point status flags collectively, including + * any status the implementation associates with the flags. + * + * A floating-point status flag is a system variable whose value is set (but + * never cleared) when a floating-point exception is raised, which occurs as a + * side effect of exceptional floating-point arithmetic to provide auxiliary + * information. + * + * A floating-point control mode is a system variable whose value may be set by + * the user to affect the subsequent behavior of floating-point arithmetic. + */ +typedef unsigned int fexcept_t; + +#endif /* !_MACHINE_FENV_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/fpu.h b/lib/libc/include/powerpc64-openbsd-none/machine/fpu.h new file mode 100644 index 0000000000..c9637f3bc5 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/fpu.h @@ -0,0 +1,17 @@ +/* $OpenBSD: fpu.h,v 1.4 2022/03/24 18:42:05 kettenis Exp $ */ + +/* public domain */ + +#ifndef _MACHINE_FPU_H +#define _MACHINE_FPU_H + +#ifdef _KERNEL + +void save_vsx(struct proc *); +void restore_vsx(struct proc *); + +int fpu_sigcode(struct proc *); + +#endif + +#endif /* _MACHINE_FPU_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/frame.h b/lib/libc/include/powerpc64-openbsd-none/machine/frame.h new file mode 100644 index 0000000000..afb0dfa295 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/frame.h @@ -0,0 +1,104 @@ +/* $OpenBSD: frame.h,v 1.5 2020/07/13 22:37:37 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 _MACHDEP_FRAME_H +#define _MACHDEP_FRAME_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; + __register_t srr0; + __register_t srr1; + __register_t vrsave; + __register_t dar; /* dar & dsisr are only filled on a DSI trap */ + __register_t dsisr; + __register_t exc; +}; + +/* + * This is to ensure alignment of the stackpointer + */ +#define FRAMELEN roundup(sizeof(struct trapframe) + 32, 16) + +struct callframe { + register_t cf_sp; + register_t cf_cr; + register_t cf_lr; + register_t cf_toc; +}; + +struct sigframe { + int sf_signum; + siginfo_t *sf_sip; + struct sigcontext sf_sc; + siginfo_t sf_si; +}; + +struct switchframe { + register_t sf_sp; + register_t sf_cr; + register_t sf_lr; /* unused */ + register_t sf_toc; /* unused */ + register_t sf_r14; + register_t sf_r15; + register_t sf_r16; + register_t sf_r17; + register_t sf_r18; + register_t sf_r19; + register_t sf_r20; + register_t sf_r21; + register_t sf_r22; + register_t sf_r23; + register_t sf_r24; + register_t sf_r25; + register_t sf_r26; + register_t sf_r27; + register_t sf_r28; + register_t sf_r29; + register_t sf_r30; + register_t sf_r31; +}; + +#endif /* _MACHDEP_FRAME_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/ieee.h b/lib/libc/include/powerpc64-openbsd-none/machine/ieee.h new file mode 100644 index 0000000000..3755c7eac5 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/ieee.h @@ -0,0 +1,119 @@ +/* $OpenBSD: ieee.h,v 1.1 2020/06/01 00:13:37 drahn Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)ieee.h 8.1 (Berkeley) 6/11/93 + */ + +/* + * ieee.h defines the machine-dependent layout of the machine's IEEE + * floating point. It does *not* define (yet?) any of the rounding + * mode bits, exceptions, and so forth. + */ + +/* + * Define the number of bits in each fraction and exponent. + * + * k k+1 + * Note that 1.0 x 2 == 0.1 x 2 and that denorms are represented + * + * (-exp_bias+1) + * as fractions that look like 0.fffff x 2 . This means that + * + * -126 + * the number 0.10000 x 2 , for instance, is the same as the normalized + * + * -127 -128 + * float 1.0 x 2 . Thus, to represent 2 , we need one leading zero + * + * -129 + * in the fraction; to represent 2 , we need two, and so on. This + * + * (-exp_bias-fracbits+1) + * implies that the smallest denormalized number is 2 + * + * for whichever format we are talking about: for single precision, for + * + * -126 -149 + * instance, we get .00000000000000000000001 x 2 , or 1.0 x 2 , and + * + * -149 == -127 - 23 + 1. + */ +#define SNG_EXPBITS 8 +#define SNG_FRACBITS 23 + +#define DBL_EXPBITS 11 +#define DBL_FRACHBITS 20 +#define DBL_FRACLBITS 32 +#define DBL_FRACBITS 52 + +struct ieee_single { + u_int sng_sign:1; + u_int sng_exp:8; + u_int sng_frac:23; +}; + +struct ieee_double { + u_int dbl_sign:1; + u_int dbl_exp:11; + u_int dbl_frach:20; + u_int dbl_fracl; +}; + +/* + * Floats whose exponent is in [1..INFNAN) (of whatever type) are + * `normal'. Floats whose exponent is INFNAN are either Inf or NaN. + * Floats whose exponent is zero are either zero (iff all fraction + * bits are zero) or subnormal values. + * + * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its + * high fraction; if the bit is set, it is a `quiet NaN'. + */ +#define SNG_EXP_INFNAN 255 +#define DBL_EXP_INFNAN 2047 + +#if 0 +#define SNG_QUIETNAN (1 << 22) +#define DBL_QUIETNAN (1 << 19) +#endif + +/* + * Exponent biases. + */ +#define SNG_EXP_BIAS 127 +#define DBL_EXP_BIAS 1023 \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/ieeefp.h b/lib/libc/include/powerpc64-openbsd-none/machine/ieeefp.h new file mode 100644 index 0000000000..6b37911951 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/ieeefp.h @@ -0,0 +1,25 @@ +/* $OpenBSD: ieeefp.h,v 1.1 2020/06/01 00:13:37 drahn Exp $ */ +/* $NetBSD: ieeefp.h,v 1.2 1999/07/07 01:52:26 danw Exp $ */ +/* + * Written by J.T. Conklin, Apr 6, 1995 + * Public domain. + */ + +#ifndef _POWERPC_IEEEFP_H_ +#define _POWERPC_IEEEFP_H_ + +typedef int fp_except; +#define FP_X_IMP 0x01 /* imprecise (loss of precision) */ +#define FP_X_DZ 0x02 /* divide-by-zero exception */ +#define FP_X_UFL 0x04 /* underflow exception */ +#define FP_X_OFL 0x08 /* overflow exception */ +#define FP_X_INV 0x10 /* invalid operation exception */ + +typedef enum { + FP_RN=0, /* round to nearest representable number */ + FP_RZ=1, /* round to zero (truncate) */ + FP_RP=2, /* round toward positive infinity */ + FP_RM=3 /* round toward negative infinity */ +} fp_rnd; + +#endif /* _POWERPC_IEEEFP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/intr.h b/lib/libc/include/powerpc64-openbsd-none/machine/intr.h new file mode 100644 index 0000000000..e6a70160ba --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/intr.h @@ -0,0 +1,135 @@ +/* $OpenBSD: intr.h,v 1.16 2025/04/26 11:10:28 visa Exp $ */ + +/* + * Copyright (c) 2020 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_INTR_H_ +#define _MACHINE_INTR_H_ + +#define __USE_MI_SOFTINTR + +#include +#include + +struct cpu_info; +struct trapframe; + +#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 IPL_TTY +#define IPL_AUDIO 8 +#define IPL_CLOCK 9 +#define IPL_STATCLOCK IPL_CLOCK +#define IPL_SCHED IPL_CLOCK +#define IPL_HIGH IPL_CLOCK +#define IPL_IPI 10 +#define NIPL 11 + +#define IPL_MPFLOOR IPL_TTY +/* Interrupt priority 'flags'. */ +#define IPL_IRQMASK 0xf /* priority only */ +#define IPL_FLAGMASK 0xf00 /* flags only*/ +#define IPL_MPSAFE 0x100 /* 'mpsafe' interrupt, no kernel lock */ + +int splraise(int); +int spllower(int); +void splx(int); + +void softintr(int); + +#define spl0() spllower(IPL_NONE) +#define splsoftclock() splraise(IPL_SOFTCLOCK) +#define splsoftnet() splraise(IPL_SOFTNET) +#define splsofttty() splraise(IPL_SOFTTTY) +#define splbio() splraise(IPL_BIO) +#define splnet() splraise(IPL_NET) +#define spltty() splraise(IPL_TTY) +#define splvm() splraise(IPL_VM) +#define splclock() splraise(IPL_CLOCK) +#define splstatclock() splraise(IPL_STATCLOCK) +#define splsched() splraise(IPL_SCHED) +#define splhigh() splraise(IPL_HIGH) + +#ifdef DIAGNOSTIC +/* + * Although this function is implemented in MI code, it must be in this MD + * header because we don't want this header to include MI includes. + */ +void splassert_fail(int, int, const char *); +extern int splassert_ctl; +void splassert_check(int, const char *); +#define splassert(__wantipl) do { \ + if (splassert_ctl > 0) { \ + splassert_check(__wantipl, __func__); \ + } \ +} while (0) +#define splsoftassert(wantipl) splassert(wantipl) +#else +#define splassert(wantipl) do { /* nothing */ } while (0) +#define splsoftassert(wantipl) do { /* nothing */ } while (0) +#endif + +void intr_init(void); + +#define intr_barrier(x) + +#define IST_EDGE 0 +#define IST_LEVEL 1 + +void *intr_establish(uint32_t, int, int, struct cpu_info *, + int (*)(void *), void *, const char *); + +#define IPI_NOP 0 +#define IPI_DDB (1 << 0) +#define IPI_SETPERF (1 << 1) + +void intr_send_ipi(struct cpu_info *, int); + +extern void (*_exi)(struct trapframe *); +extern void (*_hvi)(struct trapframe *); +extern void *(*_intr_establish)(uint32_t, int, int, struct cpu_info *, + int (*)(void *), void *, const char *); +extern void (*_intr_send_ipi)(void *); +extern void (*_setipl)(int); + +struct interrupt_controller { + int ic_node; + void *ic_cookie; + void *(*ic_establish)(void *, int *, int, struct cpu_info *, + int (*)(void *), void *, char *); + void (*ic_send_ipi)(void *); + + LIST_ENTRY(interrupt_controller) ic_list; + uint32_t ic_phandle; + uint32_t ic_cells; +}; + +void interrupt_controller_register(struct interrupt_controller *); + +void *fdt_intr_establish_idx_cpu(int, int, int, struct cpu_info *, + int (*)(void *), void *, char *); +void *fdt_intr_establish_imap(int, int *, int, int, int (*)(void *), + void *, char *); +void *fdt_intr_establish_imap_cpu(int, int *, int, int, + struct cpu_info *, int (*)(void *), void *, char *); +void fdt_intr_disestablish(void *); + +#endif /* _MACHINE_INTR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/kcore.h b/lib/libc/include/powerpc64-openbsd-none/machine/kcore.h new file mode 100644 index 0000000000..c94e37366e --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/kcore.h @@ -0,0 +1 @@ +/* Empty */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/kexec.h b/lib/libc/include/powerpc64-openbsd-none/machine/kexec.h new file mode 100644 index 0000000000..e909bfcc3e --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/kexec.h @@ -0,0 +1,36 @@ +/* $OpenBSD: kexec.h,v 1.3 2020/07/18 10:23:44 kettenis Exp $ */ + +/* + * Copyright (c) 2019-2020 Visa Hankala + * + * Permission to use, copy, modify, and/or 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_KEXEC_H_ +#define _MACHINE_KEXEC_H_ + +#include + +#define KEXEC_MAX_ARGS 8 /* maximum number of boot arguments */ + +struct kexec_args { + char *kimg; /* kernel image buffer */ + size_t klen; /* size of kernel image */ + int boothowto; + u_char bootduid[8]; +}; + +#define KIOC_KEXEC _IOW('K', 1, struct kexec_args) +#define KIOC_GETBOOTDUID _IOR('K', 2, u_char[8]) + +#endif /* _MACHINE_KEXEC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/limits.h b/lib/libc/include/powerpc64-openbsd-none/machine/limits.h new file mode 100644 index 0000000000..d2c0f2eaf3 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/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 + +#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_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/mplock.h b/lib/libc/include/powerpc64-openbsd-none/machine/mplock.h new file mode 100644 index 0000000000..1856d8925a --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/mplock.h @@ -0,0 +1,10 @@ +/* $OpenBSD: mplock.h,v 1.1 2020/07/22 11:08:01 kettenis Exp $ */ + +/* public domain */ + +#ifndef _MACHINE_MPLOCK_H_ +#define _MACHINE_MPLOCK_H_ + +#define __USE_MI_MPLOCK + +#endif /* !_MACHINE_MPLOCK_H */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/mutex.h b/lib/libc/include/powerpc64-openbsd-none/machine/mutex.h new file mode 100644 index 0000000000..9f22aee173 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/mutex.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mutex.h,v 1.1 2020/05/16 17:11:14 kettenis Exp $ */ + +#define __USE_MI_MUTEX \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/opal.h b/lib/libc/include/powerpc64-openbsd-none/machine/opal.h new file mode 100644 index 0000000000..98106675bb --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/opal.h @@ -0,0 +1,238 @@ +/* $OpenBSD: opal.h,v 1.19 2021/01/23 12:10:08 kettenis Exp $ */ + +/* + * Copyright (c) 2020 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_OPAL_H_ +#define _MACHINE_OPAL_H_ + +/* Tokens. */ +#define OPAL_TEST 0 +#define OPAL_CONSOLE_WRITE 1 +#define OPAL_CONSOLE_READ 2 +#define OPAL_RTC_READ 3 +#define OPAL_RTC_WRITE 4 +#define OPAL_CEC_POWER_DOWN 5 +#define OPAL_CEC_REBOOT 6 +#define OPAL_HANDLE_INTERRUPT 9 +#define OPAL_POLL_EVENTS 10 +#define OPAL_PCI_CONFIG_READ_WORD 15 +#define OPAL_PCI_CONFIG_WRITE_WORD 18 +#define OPAL_SET_XIVE 19 +#define OPAL_GET_XIVE 20 +#define OPAL_PCI_EEH_FREEZE_STATUS 23 +#define OPAL_PCI_EEH_FREEZE_CLEAR 26 +#define OPAL_PCI_PHB_MMIO_ENABLE 27 +#define OPAL_PCI_SET_PHB_MEM_WINDOW 28 +#define OPAL_PCI_MAP_PE_MMIO_WINDOW 29 +#define OPAL_PCI_SET_PE 31 +#define OPAL_PCI_SET_XIVE_PE 37 +#define OPAL_GET_MSI_32 39 +#define OPAL_GET_MSI_64 40 +#define OPAL_START_CPU 41 +#define OPAL_PCI_MAP_PE_DMA_WINDOW 44 +#define OPAL_PCI_MAP_PE_DMA_WINDOW_REAL 45 +#define OPAL_PCI_RESET 49 +#define OPAL_REINIT_CPUS 70 +#define OPAL_CHECK_TOKEN 80 +#define OPAL_SENSOR_READ 88 +#define OPAL_IPMI_SEND 107 +#define OPAL_IPMI_RECV 108 +#define OPAL_CONSOLE_FLUSH 117 +#define OPAL_XIVE_RESET 128 +#define OPAL_XIVE_GET_IRQ_INFO 129 +#define OPAL_XIVE_GET_IRQ_CONFIG 131 +#define OPAL_XIVE_SET_IRQ_CONFIG 131 +#define OPAL_XIVE_GET_QUEUE_INFO 132 +#define OPAL_XIVE_SET_QUEUE_INFO 133 +#define OPAL_XIVE_GET_VP_INFO 137 +#define OPAL_XIVE_SET_VP_INFO 138 +#define OPAL_XIVE_DUMP 142 +#define OPAL_SENSOR_READ_U64 162 + +/* Return codes. */ +#define OPAL_SUCCESS 0 +#define OPAL_PARAMETER -1 +#define OPAL_BUSY -2 +#define OPAL_PARTIAL -3 +#define OPAL_CONSTRAINED -4 +#define OPAL_CLOSED -5 +#define OPAL_HARDWARE -6 +#define OPAL_UNSUPPORTED -7 +#define OPAL_PERMISSION -8 +#define OPAL_NO_MEM -9 +#define OPAL_RESOURCE -10 +#define OPAL_INTERNAL_ERROR -11 +#define OPAL_BUSY_EVENT -12 +#define OPAL_HARDWARE_FROZEN -13 +#define OPAL_WRONG_STATE -14 +#define OPAL_ASYNC_COMPLETION -15 +#define OPAL_EMPTY -16 + +/* OPAL_POLL_EVENT */ +#define OPAL_EVENT_CONSOLE_OUTPUT 0x00000008 +#define OPAL_EVENT_CONSOLE_INPUT 0x00000010 + +/* OPAL_PCI_EEH_FREEZE_CLEAR */ +#define OPAL_EEH_ACTION_CLEAR_FREEZE_MMIO 1 +#define OPAL_EEH_ACTION_CLEAR_FREEZE_DMA 2 +#define OPAL_EEH_ACTION_CLEAR_FREEZE_ALL 3 + +/* OPAL_PCI_PHB_MMIO_ENABLE */ +#define OPAL_M32_WINDOW_TYPE 1 +#define OPAL_M64_WINDOW_TYPE 2 +#define OPAL_IO_WINDOW_TYPE 3 +#define OPAL_DISABLE_M64 0 +#define OPAL_ENABLE_M64_SPLIT 1 +#define OPAL_ENABLE_M64_NON_SPLIT 2 + +/* OPAL_PCIE_SET_PE */ +#define OPAL_IGNORE_RID_BUS_NUMBER 0 +#define OPAL_IGNORE_RID_DEVICE_NUMBER 0 +#define OPAL_COMPARE_RID_DEVICE_NUMBER 1 +#define OPAL_IGNORE_RID_FUNCTION_NUMBER 0 +#define OPAL_COMPARE_RID_FUNCTION_NUMBER 1 +#define OPAL_UNMAP_PE 0 +#define OPAL_MAP_PE 1 + +/* OPAL_PCI_RESET */ +#define OPAL_RESET_PHB_COMPLETE 1 +#define OPAL_RESET_PCI_LINK 2 +#define OPAL_RESET_PHB_ERROR 3 +#define OPAL_RESET_PCI_HOT 4 +#define OPAL_RESET_PCI_FUNDAMENTAL 5 +#define OPAL_RESET_PCI_IODA_TABLE 6 +#define OPAL_DEASSERT_RESET 0 +#define OPAL_ASSERT_RESET 1 + +/* OPAL_REINIT_CPUS */ +#define OPAL_REINIT_CPUS_HILE_BE 0x00000001 +#define OPAL_REINIT_CPUS_HILE_LE 0x00000002 +#define OPAL_REINIT_CPUS_MMU_HASH 0x00000004 +#define OPAL_REINIT_CPUS_MMU_RADIX 0x00000008 +#define OPAL_REINIT_CPUS_TM_SUSPEND_DISABLED 0x00000010 + +/* OPAL_CHECK_TOKEN */ +#define OPAL_TOKEN_ABSENT 0 +#define OPAL_TOKEN_PRESENT 1 + +/* OPAL_IPMI_SEND/RECV */ +#define OPAL_IPMI_MSG_FORMAT_VERSION_1 1 + +#ifndef _LOCORE +struct opal_ipmi_msg { + uint8_t version; + uint8_t netfn; + uint8_t cmd; + uint8_t data[0]; +}; +#endif + +/* OPAL_XIVE_RESET */ +#define OPAL_XIVE_MODE_EMU 0 +#define OPAL_XIVE_MODE_EXPL 1 + +/* OPAL_XIVE_GET_IRQ_INFO */ +#define OPAL_XIVE_IRQ_TRIGGER_PAGE 0x00000001 +#define OPAL_XIVE_IRQ_STORE_EOI 0x00000002 +#define OPAL_XIVE_IRQ_LSI 0x00000004 +#define OPAL_XIVE_IRQ_SHIFT_BUG 0x00000008 +#define OPAL_XIVE_IRQ_MASK_VIA_FW 0x00000010 +#define OPAL_XIVE_IRQ_EOI_VIA_FW 0x00000020 + +/* OPAL_XIVE_GET_QUEUE_INFO */ +#define OPAL_XIVE_EQ_ENABLED 0x00000001 +#define OPAL_XIVE_EQ_ALWAYS_NOTIFY 0x00000002 +#define OPAL_XIVE_EQ_ESCALATE 0x00000004 + +/* OPAL_XIVE_GET_VP_INFO */ +#define OPAL_XIVE_VP_ENABLED 0x00000001 +#define OPAL_XIVE_VP_SINGLE_ESCALATION 0x00000002 + +/* OPAL_XIVE_DUMP */ +#define XIVE_DUMP_TM_HYP 0x00000000 +#define XIVE_DUMP_TM_POOL 0x00000001 +#define XIVE_DUMP_TM_OS 0x00000002 +#define XIVE_DUMP_TM_USER 0x00000003 +#define XIVE_DUMP_VP 0x00000004 +#define XIVE_DUMP_EMU_STATE 0x00000005 + +#ifndef _LOCORE + +void *opal_phys(void *); + +int64_t opal_test(uint64_t); +int64_t opal_console_write(int64_t, int64_t *, const uint8_t *); +int64_t opal_console_read(int64_t, int64_t *, uint8_t *); +int64_t opal_rtc_read(uint32_t *, uint64_t *); +int64_t opal_rtc_write(uint32_t, uint64_t); +int64_t opal_cec_power_down(uint64_t); +int64_t opal_cec_reboot(void); +int64_t opal_handle_interrupt(uint32_t, uint64_t *); +int64_t opal_poll_events(uint64_t *); +int64_t opal_pci_config_read_word(uint64_t, uint64_t, uint64_t, uint32_t *); +int64_t opal_pci_config_write_word(uint64_t, uint64_t, uint64_t, uint32_t); +int64_t opal_set_xive(uint32_t, uint16_t, uint8_t); +int64_t opal_get_xive(uint32_t, uint16_t *, uint8_t *); +int64_t opal_pci_eeh_freeze_status(uint64_t, uint64_t, uint8_t *, + uint16_t *, uint64_t *); +int64_t opal_pci_eeh_freeze_clear(uint64_t, uint64_t, uint64_t); +int64_t opal_pci_phb_mmio_enable(uint64_t, uint16_t, uint16_t, uint16_t); +int64_t opal_pci_set_phb_mem_window(uint64_t, uint16_t, uint16_t, + uint64_t, uint64_t, uint64_t); +int64_t opal_pci_map_pe_mmio_window(uint64_t, uint64_t, uint16_t, + uint16_t, uint16_t); +int64_t opal_pci_set_pe(uint64_t, uint64_t, uint64_t, uint8_t, uint8_t, + uint8_t, uint8_t); +int64_t opal_pci_set_xive_pe(uint64_t, uint64_t, uint32_t); +int64_t opal_get_msi_32(uint64_t, uint32_t, uint32_t, uint8_t, + uint32_t *, uint32_t *); +int64_t opal_get_msi_64(uint64_t, uint32_t, uint32_t, uint8_t, + uint64_t *, uint32_t *); +int64_t opal_start_cpu(uint64_t, uint64_t); +int64_t opal_pci_map_pe_dma_window(uint64_t, uint64_t, uint16_t, uint16_t, + uint64_t, uint64_t, uint64_t); +int64_t opal_pci_map_pe_dma_window_real(uint64_t, uint64_t, uint16_t, + uint64_t, uint64_t); +int64_t opal_pci_reset(uint64_t, uint8_t, uint8_t); +int64_t opal_reinit_cpus(uint64_t); +int64_t opal_check_token(uint64_t); +int64_t opal_sensor_read(uint32_t, int, uint32_t *); +int64_t opal_ipmi_send(uint64_t, struct opal_ipmi_msg *, uint64_t); +int64_t opal_ipmi_recv(uint64_t, struct opal_ipmi_msg *, uint64_t *); +int64_t opal_console_flush(uint64_t); +int64_t opal_xive_reset(uint64_t); +int64_t opal_xive_get_irq_info(uint32_t, uint64_t *, uint64_t *, + uint64_t *, uint32_t *, uint32_t *); +int64_t opal_xive_get_irq_config(uint32_t, uint64_t *, uint8_t *, uint32_t *); +int64_t opal_xive_set_irq_config(uint32_t, uint64_t, uint8_t, uint32_t); +int64_t opal_xive_get_queue_info(uint64_t, uint8_t, uint64_t *, + uint64_t *, uint64_t *, uint32_t *, uint64_t *); +int64_t opal_xive_set_queue_info(uint64_t, uint8_t, uint64_t, + uint64_t, uint64_t); +int64_t opal_xive_get_vp_info(uint64_t, uint64_t *, uint64_t *, + uint64_t *, uint32_t *); +int64_t opal_xive_set_vp_info(uint64_t, uint64_t, uint64_t); +int64_t opal_xive_dump(uint32_t, uint32_t); +int64_t opal_sensor_read_u64(uint32_t, int, uint64_t *); + +void opal_printf(const char *fmt, ...); + +void *opal_intr_establish(uint64_t, int, int (*)(void *), void *); + +#endif + +#endif /* _MACHINE_OPAL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/openpromio.h b/lib/libc/include/powerpc64-openbsd-none/machine/openpromio.h new file mode 100644 index 0000000000..e4f9fce47b --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/openpromio.h @@ -0,0 +1,57 @@ +/* $OpenBSD: openpromio.h,v 1.1 2020/06/27 21:39:05 kettenis Exp $ */ +/* $NetBSD: openpromio.h,v 1.1.1.1 1998/06/20 04:58:52 eeh Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)openpromio.h 8.1 (Berkeley) 6/11/93 + */ + +struct opiocdesc { + int op_nodeid; /* passed or returned node id */ + int op_namelen; /* length of op_name */ + char *op_name; /* pointer to field name */ + int op_buflen; /* length of op_buf (value-result) */ + char *op_buf; /* pointer to field value */ +}; + +#define OPIOCGET _IOWR('O', 1, struct opiocdesc) /* get openprom field */ +#define OPIOCSET _IOW('O', 2, struct opiocdesc) /* set openprom field */ +#define OPIOCNEXTPROP _IOWR('O', 3, struct opiocdesc) /* get next property */ +#define OPIOCGETOPTNODE _IOR('O', 4, int) /* get openprom field */ +#define OPIOCGETNEXT _IOWR('O', 5, int) /* get next node of node */ +#define OPIOCGETCHILD _IOWR('O', 6, int) /* get first child of node */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/param.h b/lib/libc/include/powerpc64-openbsd-none/machine/param.h new file mode 100644 index 0000000000..00b5dc2057 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/param.h @@ -0,0 +1,80 @@ +/* $OpenBSD: param.h,v 1.3 2025/07/07 18:33:37 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 +#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 6 /* pages of u-area */ +#define USPACE (UPAGES * PAGE_SIZE) /* total size of u-area */ +#define USPACE_ALIGN 0 /* u-area alignment 0-none */ +#define __HAVE_USPACE_GUARD + +#define NMBCLUSTERS (64 * 1024) /* max cluster allocation */ + +#ifndef MSGBUFSIZE +#define MSGBUFSIZE (16 * PAGE_SIZE) /* default message buffer size */ +#endif + +#define STACKALIGNBYTES (32 - 1) +#define STACKALIGN(p) ((u_long)(p) &~ STACKALIGNBYTES) + +#define __HAVE_FDT + +#endif /* _KERNEL */ + +#endif /* _MACHINE_PARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/pcb.h b/lib/libc/include/powerpc64-openbsd-none/machine/pcb.h new file mode 100644 index 0000000000..58948188ec --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/pcb.h @@ -0,0 +1,37 @@ +/* $OpenBSD: pcb.h,v 1.8 2021/01/09 13:14:02 kettenis Exp $ */ + +/* + * Copyright (c) 2020 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_PCB_H_ +#define _MACHINE_PCB_H_ + +#include +#include + +struct pcb { + register_t pcb_sp; + u_int pcb_flags; +#define PCB_FPU 0x000000001 +#define PCB_VEC 0x000000002 +#define PCB_VSX 0x000000004 + struct slb pcb_slb[32]; + vaddr_t pcb_onfault; + vaddr_t pcb_userva; + struct fpreg pcb_fpstate; +}; + +#endif /* _MACHINE_PCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/pci_machdep.h b/lib/libc/include/powerpc64-openbsd-none/machine/pci_machdep.h new file mode 100644 index 0000000000..0f0168282f --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/pci_machdep.h @@ -0,0 +1,134 @@ +/* $OpenBSD: pci_machdep.h,v 1.6 2024/05/22 05:51:49 jsg Exp $ */ + +/* + * Copyright (c) 2003-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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. + * + */ + +typedef struct ppc64_pci_chipset *pci_chipset_tag_t; +typedef uint64_t pcitag_t; + +#define PCITAG_NODE(x) ((x) >> 32) +#define PCITAG_OFFSET(x) ((x) & 0xffffffff) + +/* Supported interrupt types. */ +#define PCI_NONE 0 +#define PCI_INTX 1 +#define PCI_MSI32 2 +#define PCI_MSI64 3 +#define PCI_MSIX 4 + +typedef struct { + pci_chipset_tag_t ih_pc; + pcitag_t ih_tag; + int ih_intrpin; + int ih_type; +} pci_intr_handle_t; + +struct pci_attach_args; + +/* + * powerpc64-specific PCI structure and type definitions. + * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE. + */ +struct ppc64_pci_chipset { + void *pc_conf_v; + void (*pc_attach_hook)(struct device *, + struct device *, struct pcibus_attach_args *); + int (*pc_bus_maxdevs)(void *, int); + pcitag_t (*pc_make_tag)(void *, int, int, int); + void (*pc_decompose_tag)(void *, pcitag_t, int *, + int *, int *); + int (*pc_conf_size)(void *, pcitag_t); + pcireg_t (*pc_conf_read)(void *, pcitag_t, int); + void (*pc_conf_write)(void *, pcitag_t, int, pcireg_t); + + void *pc_intr_v; + int (*pc_intr_map)(struct pci_attach_args *, + pci_intr_handle_t *); + int (*pc_intr_map_msi)(struct pci_attach_args *, + pci_intr_handle_t *); + int (*pc_intr_map_msix)(struct pci_attach_args *, + int, pci_intr_handle_t *); + const char *(*pc_intr_string)(void *, pci_intr_handle_t); + void *(*pc_intr_establish)(void *, pci_intr_handle_t, + int, struct cpu_info *, int (*)(void *), void *, + char *); + void (*pc_intr_disestablish)(void *, void *); +}; + +/* + * Functions provided to machine-independent PCI code. + */ +#define pci_attach_hook(p, s, pba) \ + (*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba)) +#define pci_bus_maxdevs(c, b) \ + (*(c)->pc_bus_maxdevs)((c)->pc_conf_v, (b)) +#define pci_make_tag(c, b, d, f) \ + (*(c)->pc_make_tag)((c)->pc_conf_v, (b), (d), (f)) +#define pci_decompose_tag(c, t, bp, dp, fp) \ + (*(c)->pc_decompose_tag)((c)->pc_conf_v, (t), (bp), (dp), (fp)) +#define pci_conf_size(c, t) \ + (*(c)->pc_conf_size)((c)->pc_conf_v, (t)) +#define pci_conf_read(c, t, r) \ + (*(c)->pc_conf_read)((c)->pc_conf_v, (t), (r)) +#define pci_conf_write(c, t, r, v) \ + (*(c)->pc_conf_write)((c)->pc_conf_v, (t), (r), (v)) +#define pci_intr_map(c, ihp) \ + (*(c)->pa_pc->pc_intr_map)((c), (ihp)) +#define pci_intr_map_msi(c, ihp) \ + (*(c)->pa_pc->pc_intr_map_msi)((c), (ihp)) +#define pci_intr_map_msix(c, vec, ihp) \ + (*(c)->pa_pc->pc_intr_map_msix)((c), (vec), (ihp)) +#define pci_intr_string(c, ih) \ + (*(c)->pc_intr_string)((c)->pc_intr_v, (ih)) +#define pci_intr_establish(c, ih, l, h, a, nm) \ + (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), NULL, (h), (a),\ + (nm)) +#define pci_intr_establish_cpu(c, ih, l, ci, h, a, nm) \ + (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), (ci), (h), (a),\ + (nm)) +#define pci_intr_disestablish(c, iv) \ + (*(c)->pc_intr_disestablish)((c)->pc_intr_v, (iv)) +#define pci_probe_device_hook(c, a) (0) + +#define pci_min_powerstate(c, t) (PCI_PMCSR_STATE_D3) +#define pci_set_powerstate_md(c, t, s, p) + +#define pci_dev_postattach(a, b) + +void pci_mcfg_init(bus_space_tag_t, bus_addr_t, int, int, int); + +void pci_msi_enable(pci_chipset_tag_t, pcitag_t, bus_addr_t, uint32_t); +void pci_msix_enable(pci_chipset_tag_t, pcitag_t, bus_space_tag_t, + int, bus_addr_t, uint32_t); +int _pci_intr_map_msi(struct pci_attach_args *, pci_intr_handle_t *); +int _pci_intr_map_msix(struct pci_attach_args *, int, pci_intr_handle_t *); + +#define __HAVE_PCI_MSIX + +int pci_msix_table_map(pci_chipset_tag_t, pcitag_t, + bus_space_tag_t, bus_space_handle_t *); +void pci_msix_table_unmap(pci_chipset_tag_t, pcitag_t, + bus_space_tag_t, bus_space_handle_t); \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/pmap.h b/lib/libc/include/powerpc64-openbsd-none/machine/pmap.h new file mode 100644 index 0000000000..661c2cf34d --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/pmap.h @@ -0,0 +1,98 @@ +/* $OpenBSD: pmap.h,v 1.19 2023/12/11 22:12:53 kettenis Exp $ */ + +/* + * Copyright (c) 2020 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_PMAP_H_ +#define _MACHINE_PMAP_H_ + +#include +#include + +#ifdef _KERNEL + +#include + +/* V->P mapping data */ +#define VP_IDX1_CNT 256 +#define VP_IDX1_MASK (VP_IDX1_CNT - 1) +#define VP_IDX1_POS 20 +#define VP_IDX2_CNT 256 +#define VP_IDX2_MASK (VP_IDX2_CNT - 1) +#define VP_IDX2_POS 12 + +struct pmap { + LIST_HEAD(,slb_desc) pm_slbd; + int pm_refs; + struct pmap_statistics pm_stats; + struct mutex pm_mtx; +}; + +typedef struct pmap *pmap_t; + +#define PG_PMAP_MOD PG_PMAP0 +#define PG_PMAP_REF PG_PMAP1 +#define PG_PMAP_EXE PG_PMAP2 +#define PG_PMAP_UC PG_PMAP3 + +#define PMAP_CACHE_DEFAULT 0 +#define PMAP_CACHE_CI 1 /* cache inhibit */ +#define PMAP_CACHE_WB 3 /* write-back cached */ + +/* + * MD flags that we use for pmap_enter (in the pa): + */ +#define PMAP_PA_MASK ~((paddr_t)PAGE_MASK) /* to remove the flags */ +#define PMAP_NOCACHE 0x1 /* map uncached */ + +extern struct pmap kernel_pmap_store; + +#define pmap_kernel() (&kernel_pmap_store) +#define pmap_resident_count(pm) ((pm)->pm_stats.resident_count) +#define pmap_wired_count(pm) ((pm)->pm_stats.wired_count) + +#define pmap_init_percpu() do { /* nothing */ } while (0) +#define pmap_unuse_final(p) +#define pmap_remove_holes(vm) +#define pmap_update(pm) + +void pmap_bootstrap(void); +void pmap_bootstrap_cpu(void); + +int pmap_slbd_fault(pmap_t, vaddr_t); +int pmap_slbd_enter(pmap_t, vaddr_t); +int pmap_set_user_slb(pmap_t, vaddr_t, vaddr_t *, vsize_t *); +void pmap_clear_user_slb(void); +void pmap_unset_user_slb(void); + +#ifdef DDB +struct pte; +struct pte *pmap_get_kernel_pte(vaddr_t); +#endif + +#endif /* _KERNEL */ + +struct vm_page_md { + struct mutex pv_mtx; + LIST_HEAD(,pte_desc) pv_list; +}; + +#define VM_MDPAGE_INIT(pg) do { \ + mtx_init(&(pg)->mdpage.pv_mtx, IPL_VM); \ + LIST_INIT(&((pg)->mdpage.pv_list)); \ +} while (0) + +#endif /* _MACHINE_PMAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/proc.h b/lib/libc/include/powerpc64-openbsd-none/machine/proc.h new file mode 100644 index 0000000000..da21008f74 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/proc.h @@ -0,0 +1,46 @@ +/* $OpenBSD: proc.h,v 1.3 2020/06/22 16:58:20 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 { + struct trapframe *md_regs; + volatile int md_astpending; + paddr_t md_user_slb_pa; +}; + +#endif /* _MACHINE_PROC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/profile.h b/lib/libc/include/powerpc64-openbsd-none/machine/profile.h new file mode 100644 index 0000000000..a27eeba08c --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/profile.h @@ -0,0 +1,70 @@ +/* $OpenBSD: profile.h,v 1.1 2020/06/25 01:55:14 drahn Exp $ */ + +/* + * Copyright (c) 2020 Dale Rahn drahn@openbsd.org + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * mcount frame size skips over the red zone (288B) (calling function may use) + * and 128 bytes of local storage (32 bytes of reserved and 96 of our storage + * this function assumes it will only every call the local __mcount function + */ +#define MCOUNT \ +__asm__(" \n"\ + " .section \".text\" \n"\ + " .p2align 2 \n"\ + " .globl _mcount \n"\ + " .local __mcount \n"\ + " .type _mcount,@function \n"\ + "_mcount: \n"\ + ".L_mcount_gep0: \n"\ + " addis %r2, %r12, .TOC.-.L_mcount_gep0@ha; \n"\ + " addi %r2, %r2, .TOC.-.L_mcount_gep0@l; \n"\ + ".L_mcount_lep0: \n"\ + ".localentry _mcount, .L_mcount_lep0-.L_mcount_gep0; \n"\ + " ld %r11,16(%r1) \n"\ + " mflr %r0 \n"\ + " std %r0, 16(%r1) \n"\ + " stdu %r1,-(288+128)(%r1) \n"\ + " std %r3, 32(%r1) \n"\ + " std %r4, 40(%r1) \n"\ + " std %r5, 48(%r1) \n"\ + " std %r6, 56(%r1) \n"\ + " std %r7, 64(%r1) \n"\ + " std %r8, 72(%r1) \n"\ + " std %r9, 80(%r1) \n"\ + " std %r10,88(%r1) \n"\ + " std %r11,96(%r1) \n"\ + " mr %r4, %r0 \n"\ + " mr %r3, %r11 \n"\ + " bl __mcount \n"\ + " nop \n"\ + " ld %r3, 32(%r1) \n"\ + " ld %r4, 40(%r1) \n"\ + " ld %r5, 48(%r1) \n"\ + " ld %r6, 56(%r1) \n"\ + " ld %r7, 64(%r1) \n"\ + " ld %r8, 72(%r1) \n"\ + " ld %r9, 80(%r1) \n"\ + " ld %r10,88(%r1) \n"\ + " ld %r11,96(%r1) \n"\ + " addi %r1, %r1, (288+128) \n"\ + " ld %r0, 16(%r1) \n"\ + " std %r11,16(%r1) \n"\ + " mtlr %r0 \n"\ + " blr \n"\ + " .size _mcount, .-_mcount \n"\ + ); +#define _MCOUNT_DECL static void __mcount \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/psl.h b/lib/libc/include/powerpc64-openbsd-none/machine/psl.h new file mode 100644 index 0000000000..13f2e488a5 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/psl.h @@ -0,0 +1,88 @@ +/* $OpenBSD: psl.h,v 1.3 2021/01/09 13:14:02 kettenis Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * 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. + * + * $NetBSD: psl.h,v 1.5 2000/11/19 19:52:37 matt Exp $ + */ + +#ifndef _MACHINE_PSL_H_ +#define _MACHINE_PSL_H_ + +/* + * Machine State Register (MSR) - All cores + */ +#define PSL_VEC 0x02000000UL /* AltiVec/SPE vector unit available */ +#define PSL_VSX 0x00800000UL /* Vector-Scalar unit available */ +#define PSL_EE 0x00008000UL /* external interrupt enable */ +#define PSL_PR 0x00004000UL /* privilege mode (1 == user) */ +#define PSL_FP 0x00002000UL /* floating point enable */ +#define PSL_ME 0x00001000UL /* machine check enable */ +#define PSL_FE0 0x00000800UL /* floating point interrupt mode 0 */ +#define PSL_FE1 0x00000100UL /* floating point interrupt mode 1 */ +#define PSL_PMM 0x00000004UL /* performance monitor mark */ +#define PSL_RI 0x00000002UL /* recoverable interrupt */ + +#define PSL_GS 0x10000000UL /* Guest state */ +#define PSL_UCLE 0x04000000UL /* User mode cache lock enable */ +#define PSL_WE 0x00040000UL /* Wait state enable */ +#define PSL_CE 0x00020000UL /* Critical interrupt enable */ +#define PSL_UBLE 0x00000400UL /* BTB lock enable - e500 only */ +#define PSL_DWE 0x00000400UL /* Debug Wait Enable - 440 only*/ +#define PSL_DE 0x00000200UL /* Debug interrupt enable */ +#define PSL_IS 0x00000020UL /* Instruction address space */ +#define PSL_DS 0x00000010UL /* Data address space */ + +#define PSL_SF 0x8000000000000000UL /* 64-bit addressing */ +#define PSL_HV 0x1000000000000000UL /* hyper-privileged mode */ + +#define PSL_POW 0x00040000UL /* power management */ +#define PSL_ILE 0x00010000UL /* interrupt endian mode (1 == le) */ +#define PSL_SE 0x00000400UL /* single-step trace enable */ +#define PSL_BE 0x00000200UL /* branch trace enable */ +#define PSL_IP 0x00000040UL /* interrupt prefix - 601 only */ +#define PSL_IR 0x00000020UL /* instruction address relocation */ +#define PSL_DR 0x00000010UL /* data address relocation */ +#define PSL_LE 0x00000001UL /* endian mode (1 == le) */ + +/* + * Floating-point exception modes: + */ +#define PSL_FE_DIS 0 /* none */ +#define PSL_FE_NONREC PSL_FE1 /* imprecise non-recoverable */ +#define PSL_FE_REC PSL_FE0 /* imprecise recoverable */ +#define PSL_FE_PREC (PSL_FE0 | PSL_FE1) /* precise */ +#define PSL_FE_DFLT PSL_FE_DIS /* default == none */ + +#define PSL_FPU (PSL_FP | PSL_FE_PREC) + +#endif /* _MACHINE_PSL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/pte.h b/lib/libc/include/powerpc64-openbsd-none/machine/pte.h new file mode 100644 index 0000000000..b3e199c635 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/pte.h @@ -0,0 +1,80 @@ +/* $OpenBSD: pte.h,v 1.8 2023/01/25 09:53:53 kettenis Exp $ */ + +/* + * Copyright (c) 2020 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_PTE_H_ +#define _MACHINE_PTE_H_ + +/* + * Page Table Entry bits that should work for all 64-bit POWER CPUs as + * well as the PowerPC 970. + */ + +struct pte { + uint64_t pte_hi; + uint64_t pte_lo; +}; + +/* High doubleword: */ +#define PTE_VALID 0x0000000000000001ULL +#define PTE_HID 0x0000000000000002ULL +#define PTE_WIRED 0x0000000000000008ULL /* SW */ +#define PTE_AVPN 0x3fffffffffffff80ULL +#define PTE_VSID_SHIFT 12 + +/* Low doubleword: */ +#define PTE_PP 0x0000000000000003ULL +#define PTE_RO 0x0000000000000003ULL +#define PTE_RW 0x0000000000000002ULL +#define PTE_N 0x0000000000000004ULL +#define PTE_G 0x0000000000000008ULL +#define PTE_M 0x0000000000000010ULL +#define PTE_I 0x0000000000000020ULL +#define PTE_W 0x0000000000000040ULL +#define PTE_CHG 0x0000000000000080ULL +#define PTE_REF 0x0000000000000100ULL +#define PTE_AC 0x0000000000000200ULL +#define PTE_RPGN 0x0ffffffffffff000ULL + +#define ADDR_PIDX 0x000000000ffff000ULL +#define ADDR_PIDX_SHIFT 12 +#define ADDR_ESID_SHIFT 28 +#define ADDR_VSID_SHIFT 28 + +struct pate { + uint64_t pate_htab; + uint64_t pate_prt; +}; + +#define SLBE_ESID_SHIFT 28 +#define SLBE_VALID 0x0000000008000000UL + +#define SLBV_VSID_SHIFT 12 + +struct slb { + uint64_t slb_slbe; + uint64_t slb_slbv; +}; + +#define VSID_VRMA 0x1ffffff + +#define USER_ADDR 0xcfffffff00000000ULL +#define USER_ESID (USER_ADDR >> ADDR_ESID_SHIFT) +#define SEGMENT_SIZE (256 * 1024 * 1024ULL) +#define SEGMENT_MASK (SEGMENT_SIZE - 1) + +#endif /* _MACHINE_PTE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/ptrace.h b/lib/libc/include/powerpc64-openbsd-none/machine/ptrace.h new file mode 100644 index 0000000000..b77303a8fa --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/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_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/reg.h b/lib/libc/include/powerpc64-openbsd-none/machine/reg.h new file mode 100644 index 0000000000..037633d10a --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/reg.h @@ -0,0 +1,39 @@ +/* $OpenBSD: reg.h,v 1.3 2020/07/14 09:41:30 kettenis Exp $ */ + +/* + * Copyright (c) 2020 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_REG_H_ +#define _MACHINE_REG_H_ + +struct reg { + uint64_t r_reg[32]; + uint64_t r_lr; + uint64_t r_cr; + uint64_t r_xer; + uint64_t r_ctr; + uint64_t r_pc; + uint64_t r_ps; +}; + +struct fpreg { + __uint128_t fp_vsx[64]; + uint64_t fp_fpscr; + uint64_t fp_vscr; + uint64_t fp_vrsave; +}; + +#endif /* !_MACHINE_REG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/reloc.h b/lib/libc/include/powerpc64-openbsd-none/machine/reloc.h new file mode 100644 index 0000000000..f233ce24dc --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/reloc.h @@ -0,0 +1,148 @@ +/* $OpenBSD: reloc.h,v 1.2 2020/07/18 16:41:43 kettenis Exp $ */ + +/* + * Copyright (c) 2020 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_RELOC_H_ +#define _MACHINE_RELOC_H_ + +#define R_PPC64_NONE 0 +#define R_PPC64_ADDR32 1 +#define R_PPC64_ADDR24 2 +#define R_PPC64_ADDR16 3 +#define R_PPC64_ADDR16_LO 4 +#define R_PPC64_ADDR16_HI 5 +#define R_PPC64_ADDR16_HA 6 +#define R_PPC64_ADDR14 7 + +#define R_PPC64_REL24 10 +#define R_PPC64_REL14 11 + +#define R_PPC64_GOT16 14 +#define R_PPC64_GOT16_LO 15 +#define R_PPC64_GOT16_HI 16 +#define R_PPC64_GOT16_HA 17 + +#define R_PPC64_COPY 19 +#define R_PPC64_GLOB_DAT 20 +#define R_PPC64_JMP_SLOT 21 +#define R_PPC64_RELATIVE 22 + +#define R_PPC64_UADDR32 24 +#define R_PPC64_UADDR16 25 +#define R_PPC64_REL32 26 +#define R_PPC64_PLT32 27 +#define R_PPC64_PLTREL32 28 +#define R_PPC64_PLT16_LO 29 +#define R_PPC64_PLT16_HI 30 +#define R_PPC64_PLT16_HA 31 + +#define R_PPC64_SECTOFF 33 +#define R_PPC64_SECTOFF_LO 34 +#define R_PPC64_SECTOFF_HI 35 +#define R_PPC64_SECTOFF_HA 36 +#define R_PPC64_REL30 37 +#define R_PPC64_ADDR64 38 +#define R_PPC64_ADDR16_HIGHER 39 +#define R_PPC64_ADDR16_HIGHERA 40 +#define R_PPC64_ADDR16_HIGHEST 41 +#define R_PPC64_ADDR16_HIGHESTA 42 +#define R_PPC64_UADDR64 43 +#define R_PPC64_REL64 44 +#define R_PPC64_PLT64 45 +#define R_PPC64_PLTREL64 46 +#define R_PPC64_TOC16 47 +#define R_PPC64_TOC16_LO 48 +#define R_PPC64_TOC16_HI 49 +#define R_PPC64_TOC16_HA 50 +#define R_PPC64_TOC 51 +#define R_PPC64_PLTGOT16 52 +#define R_PPC64_PLTGOT16_LO 53 +#define R_PPC64_PLTGOT16_HI 54 +#define R_PPC64_PLTGOT16_HA 55 +#define R_PPC64_ADDR16_DS 56 +#define R_PPC64_ADDR16_LO_DS 57 +#define R_PPC64_GOT16_DS 58 +#define R_PPC64_GOT16_LO_DS 59 +#define R_PPC64_PLT16_LO_DS 60 +#define R_PPC64_SECTOFF_DS 61 +#define R_PPC64_SECTOFF_LO_DS 62 +#define R_PPC64_TOC16_DS 63 +#define R_PPC64_TOC16_LO_DS 64 +#define R_PPC64_PLTGOT16_DS 65 +#define R_PPC64_PLTGOT16_LO_DS 66 +#define R_PPC64_TLS 67 +#define R_PPC64_DTPMOD64 68 +#define R_PPC64_TPREL16 69 +#define R_PPC64_TPREL16_LO 70 +#define R_PPC64_TPREL16_HI 71 +#define R_PPC64_TPREL16_HA 72 +#define R_PPC64_TPREL64 73 +#define R_PPC64_DTPREL16 74 +#define R_PPC64_DTPREL16_LO 75 +#define R_PPC64_DTPREL16_HI 76 +#define R_PPC64_DTPREL16_HA 77 +#define R_PPC64_DTPREL64 78 +#define R_PPC64_GOT_TLSGD16 79 +#define R_PPC64_GOT_TLSGD16_LO 80 +#define R_PPC64_GOT_TLSGD16_HI 81 +#define R_PPC64_GOT_TLSGD16_HA 82 +#define R_PPC64_GOT_TLSD16 83 +#define R_PPC64_GOT_TLSD16_LO 84 +#define R_PPC64_GOT_TLSD16_HI 85 +#define R_PPC64_GOT_TLSD16_HA 86 +#define R_PPC64_GOT_TPREL16_DS 87 +#define R_PPC64_GOT_TPREL16_LO_DS 88 +#define R_PPC64_GOT_TPREL16_HI 89 +#define R_PPC64_GOT_TPREL16_HA 90 +#define R_PPC64_GOT_DTPREL16_DS 91 +#define R_PPC64_GOT_DTPREL16_LO_DS 92 +#define R_PPC64_GOT_DTPREL16_HI 93 +#define R_PPC64_GOT_DTPREL16_HA 94 +#define R_PPC64_TPREL16_DS 95 +#define R_PPC64_TPREL16_LO_DS 96 +#define R_PPC64_TPREL16_HIGHER 97 +#define R_PPC64_TPREL16_HIGHERA 98 +#define R_PPC64_TPREL16_HIGHEST 99 +#define R_PPC64_TPREL16_HIGHESTA 100 +#define R_PPC64_DTPREL16_DS 101 +#define R_PPC64_DTPREL16_LO_DS 102 +#define R_PPC64_DTPREL16_HIGHER 103 +#define R_PPC64_DTPREL16_HIGHERA 104 +#define R_PPC64_DTPREL16_HIGHEST 105 +#define R_PPC64_DTPREL16_HIGHESTA 106 +#define R_PPC64_TLSGD 107 +#define R_PPC64_TLSLD 108 +#define R_PPC64_TOCSAVE 109 +#define R_PPC64_ADDR16_HIGH 110 +#define R_PPC64_ADDR16_HIGHA 111 +#define R_PPC64_TPREL16_HIGH 112 +#define R_PPC64_TPREL16_HIGHA 113 +#define R_PPC64_DTPREL16_HIGH 114 +#define R_PPC64_DTPREL16_HIGHA 115 +#define R_PPC64_REL24_NOTOC 116 +#define R_PPC64_ADDR64_LOCAL 117 +#define R_PPC64_ENTRY 118 + +#define R_PPC64_IRELATIVE 248 +#define R_PPC64_REL16 249 +#define R_PPC64_REL16_LO 250 +#define R_PPC64_REL16_HI 251 +#define R_PPC64_REL16_HA 252 +#define R_PPC64_GNU_VTINHERIT 253 +#define R_PPC64_GNU_VTENTRY 254 + +#endif /* _MACHINE_RELOC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/setjmp.h b/lib/libc/include/powerpc64-openbsd-none/machine/setjmp.h new file mode 100644 index 0000000000..02b53f759f --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/setjmp.h @@ -0,0 +1,4 @@ +/* $OpenBSD: setjmp.h,v 1.1 2020/06/25 05:01:16 drahn Exp $ */ +/* $NetBSD: setjmp.h,v 1.1 1996/09/30 16:34:34 ws Exp $ */ + +#define _JBLEN 208 \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/signal.h b/lib/libc/include/powerpc64-openbsd-none/machine/signal.h new file mode 100644 index 0000000000..68710820a2 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/signal.h @@ -0,0 +1,65 @@ +/* $OpenBSD: signal.h,v 1.5 2020/07/13 22:37:37 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 _MACHDEP_SIGNAL_H_ +#define _MACHDEP_SIGNAL_H_ + +#include + +typedef int sig_atomic_t; + +#if __BSD_VISIBLE || __XPG_VISIBLE >= 420 + +#include + +struct sigcontext { + long sc_cookie; + int sc_mask; /* saved signal mask */ + __register_t sc_reg[32]; /* saved registers */ + __register_t sc_lr; + __register_t sc_cr; + __register_t sc_xer; + __register_t sc_ctr; + __register_t sc_pc; + __register_t sc_ps; + __register_t sc_vrsave; + __uint128_t sc_vsx[64]; + __uint64_t sc_fpscr; + __uint64_t sc_vscr; +}; + +#define sc_sp sc_reg[1] + +#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */ + +#endif /* _MACHDEP_SIGNAL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/smbiosvar.h b/lib/libc/include/powerpc64-openbsd-none/machine/smbiosvar.h new file mode 100644 index 0000000000..60200682ad --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/smbiosvar.h @@ -0,0 +1,278 @@ +/* $OpenBSD: smbiosvar.h,v 1.3 2025/07/15 01:09:32 jsg Exp $ */ +/* + * Copyright (c) 2006 Gordon Willem Klok + * Copyright (c) 2005 Jordan Hargrave + * 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 AUTHORS 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 AUTHORS 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_SMBIOSVAR_ +#define _MACHINE_SMBIOSVAR_ + +#define SMBIOS_UUID_NPRESENT 0x1 +#define SMBIOS_UUID_NSET 0x2 + +/* + * Section 3.5 of "UUIDs and GUIDs" found at + * http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt + * specifies the string representation of a UUID. + */ +#define SMBIOS_UUID_REP "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" +#define SMBIOS_UUID_REPLEN 37 /* 16 zero padded values, 4 hyphens, 1 null */ + +struct smbios_entry { + uint8_t mjr; + uint8_t min; + uint8_t *addr; + uint16_t len; + uint16_t count; +}; + +struct smbhdr { + uint32_t sig; /* "_SM_" */ + uint8_t checksum; /* Entry point checksum */ + uint8_t len; /* Entry point structure length */ + uint8_t majrev; /* Specification major revision */ + uint8_t minrev; /* Specification minor revision */ + uint16_t mss; /* Maximum Structure Size */ + uint8_t epr; /* Entry Point Revision */ + uint8_t fa[5]; /* value determined by EPR */ + uint8_t sasig[5]; /* Secondary Anchor "_DMI_" */ + uint8_t sachecksum; /* Secondary Checksum */ + uint16_t size; /* Length of structure table in bytes */ + uint32_t addr; /* Structure table address */ + uint16_t count; /* Number of SMBIOS structures */ + uint8_t rev; /* BCD revision */ +} __packed; + +struct smb3hdr { + uint8_t sig[5]; /* "_SM3_" */ + uint8_t checksum; /* Entry point structure checksum */ + uint8_t len; /* Entry point length */ + uint8_t majrev; /* SMBIOS major version */ + uint8_t minrev; /* SMBIOS minor version */ + uint8_t docrev; /* SMBIOS docrev */ + uint8_t epr; /* Entry point revision */ + uint8_t reserved; /* Reserved */ + uint32_t size; /* Structure table maximum size */ + uint64_t addr; /* Structure table address */ +} __packed; + +struct smbtblhdr { + uint8_t type; + uint8_t size; + uint16_t handle; +} __packed; + +struct smbtable { + struct smbtblhdr *hdr; + void *tblhdr; + uint32_t cookie; +}; + +#define SMBIOS_TYPE_BIOS 0 +#define SMBIOS_TYPE_SYSTEM 1 +#define SMBIOS_TYPE_BASEBOARD 2 +#define SMBIOS_TYPE_ENCLOSURE 3 +#define SMBIOS_TYPE_PROCESSOR 4 +#define SMBIOS_TYPE_MEMCTRL 5 +#define SMBIOS_TYPE_MEMMOD 6 +#define SMBIOS_TYPE_CACHE 7 +#define SMBIOS_TYPE_PORT 8 +#define SMBIOS_TYPE_SLOTS 9 +#define SMBIOS_TYPE_OBD 10 +#define SMBIOS_TYPE_OEM 11 +#define SMBIOS_TYPE_SYSCONFOPT 12 +#define SMBIOS_TYPE_BIOSLANG 13 +#define SMBIOS_TYPE_GROUPASSOC 14 +#define SMBIOS_TYPE_SYSEVENTLOG 15 +#define SMBIOS_TYPE_PHYMEM 16 +#define SMBIOS_TYPE_MEMDEV 17 +#define SMBIOS_TYPE_ECCINFO32 18 +#define SMBIOS_TYPE_MEMMAPARRAYADDR 19 +#define SMBIOS_TYPE_MEMMAPDEVADDR 20 +#define SMBIOS_TYPE_INBUILTPOINT 21 +#define SMBIOS_TYPE_PORTBATT 22 +#define SMBIOS_TYPE_SYSRESET 23 +#define SMBIOS_TYPE_HWSECUIRTY 24 +#define SMBIOS_TYPE_PWRCTRL 25 +#define SMBIOS_TYPE_VOLTPROBE 26 +#define SMBIOS_TYPE_COOLING 27 +#define SMBIOS_TYPE_TEMPPROBE 28 +#define SMBIOS_TYPE_CURRENTPROBE 29 +#define SMBIOS_TYPE_OOB_REMOTEACCESS 30 +#define SMBIOS_TYPE_BIS 31 +#define SMBIOS_TYPE_SBI 32 +#define SMBIOS_TYPE_ECCINFO64 33 +#define SMBIOS_TYPE_MGMTDEV 34 +#define SMBIOS_TYPE_MGTDEVCOMP 35 +#define SMBIOS_TYPE_MGTDEVTHRESH 36 +#define SMBIOS_TYPE_MEMCHANNEL 37 +#define SMBIOS_TYPE_IPMIDEV 38 +#define SMBIOS_TYPE_SPS 39 +#define SMBIOS_TYPE_INACTIVE 126 +#define SMBIOS_TYPE_EOT 127 + +/* + * SMBIOS Structure Type 0 "BIOS Information" + * DMTF Specification DSP0134 Section: 3.3.1 p.g. 34 + */ +struct smbios_struct_bios { + uint8_t vendor; /* string */ + uint8_t version; /* string */ + uint16_t startaddr; + uint8_t release; /* string */ + uint8_t romsize; + uint64_t characteristics; + uint32_t charext; + uint8_t major_rel; + uint8_t minor_rel; + uint8_t ecf_mjr_rel; /* embedded controller firmware */ + uint8_t ecf_min_rel; /* embedded controller firmware */ +} __packed; + +/* + * SMBIOS Structure Type 1 "System Information" + * DMTF Specification DSP0134 Section 3.3.2 p.g. 35 + */ + +struct smbios_sys { +/* SMBIOS spec 2.0+ */ + uint8_t vendor; /* string */ + uint8_t product; /* string */ + uint8_t version; /* string */ + uint8_t serial; /* string */ +/* SMBIOS spec 2.1+ */ + uint8_t uuid[16]; + uint8_t wakeup; +/* SMBIOS spec 2.4+ */ + uint8_t sku; /* string */ + uint8_t family; /* string */ +} __packed; + +/* + * SMBIOS Structure Type 2 "Base Board (Module) Information" + * DMTF Specification DSP0134 Section 3.3.3 p.g. 37 + */ +struct smbios_board { + uint8_t vendor; /* string */ + uint8_t product; /* string */ + uint8_t version; /* string */ + uint8_t serial; /* string */ + uint8_t asset; /* string */ + uint8_t feature; /* feature flags */ + uint8_t location; /* location in chassis */ + uint16_t handle; /* chassis handle */ + uint8_t type; /* board type */ + uint8_t noc; /* number of contained objects */ +} __packed; + +/* + * SMBIOS Structure Type 3 "System Enclosure or Chassis" + * DMTF Specification DSP0134 + */ +struct smbios_enclosure { + /* SMBIOS spec 2.0+ */ + uint8_t vendor; /* string */ + uint8_t type; + uint8_t version; /* string */ + uint8_t serial; /* string */ + uint8_t asset_tag; /* string */ + /* SMBIOS spec 2.1+ */ + uint8_t boot_state; + uint8_t psu_state; + uint8_t thermal_state; + uint8_t security_status; + /* SMBIOS spec 2.3+ */ + uint16_t oem_defined; + uint8_t height; + uint8_t no_power_cords; + uint8_t no_contained_element; + uint8_t reclen_contained_element; + uint8_t contained_elements; + /* SMBIOS spec 2.7+ */ + uint8_t sku; /* string */ +} __packed; + +/* + * SMBIOS Structure Type 4 "processor Information" + * DMTF Specification DSP0134 v2.5 Section 3.3.5 p.g. 24 + */ +struct smbios_cpu { + uint8_t cpu_socket_designation; /* string */ + uint8_t cpu_type; + uint8_t cpu_family; + uint8_t cpu_mfg; /* string */ + uint32_t cpu_id_eax; + uint32_t cpu_id_edx; + uint8_t cpu_version; /* string */ + uint8_t cpu_voltage; + uint16_t cpu_clock; + uint16_t cpu_max_speed; + uint16_t cpu_current_speed; + uint8_t cpu_status; +#define SMBIOS_CPUST_POPULATED (1<<6) +#define SMBIOS_CPUST_STATUSMASK (0x07) + uint8_t cpu_upgrade; + uint16_t cpu_l1_handle; + uint16_t cpu_l2_handle; + uint16_t cpu_l3_handle; + uint8_t cpu_serial; /* string */ + uint8_t cpu_asset_tag; /* string */ + uint8_t cpu_part_nr; /* string */ + /* following fields were added in smbios 2.5 */ + uint8_t cpu_core_count; + uint8_t cpu_core_enabled; + uint8_t cpu_thread_count; + uint16_t cpu_characteristics; +} __packed; + +/* + * SMBIOS Structure Type 38 "IPMI Information" + * DMTF Specification DSP0134 Section 3.3.39 p.g. 91 + */ +struct smbios_ipmi { + uint8_t smipmi_if_type; /* IPMI Interface Type */ + uint8_t smipmi_if_rev; /* BCD IPMI Revision */ + uint8_t smipmi_i2c_address; /* I2C address of BMC */ + uint8_t smipmi_nvram_address; /* I2C address of NVRAM + * storage */ + uint64_t smipmi_base_address; /* Base address of BMC (BAR + * format */ + uint8_t smipmi_base_flags; /* Flags field: + * bit 7:6 : register spacing + * 00 = byte + * 01 = dword + * 02 = word + * bit 4 : Lower bit BAR + * bit 3 : IRQ valid + * bit 2 : N/A + * bit 1 : Interrupt polarity + * bit 0 : Interrupt trigger */ + uint8_t smipmi_irq; /* IRQ if applicable */ +} __packed; + +int smbios_find_table(uint8_t, struct smbtable *); +char *smbios_get_string(struct smbtable *, uint8_t, char *, size_t); + +#endif \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/spinlock.h b/lib/libc/include/powerpc64-openbsd-none/machine/spinlock.h new file mode 100644 index 0000000000..98555de967 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/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 + * + * 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 \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/tcb.h b/lib/libc/include/powerpc64-openbsd-none/machine/tcb.h new file mode 100644 index 0000000000..879efa9de8 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/tcb.h @@ -0,0 +1,42 @@ +/* $OpenBSD: tcb.h,v 1.4 2020/07/14 16:48:13 kettenis Exp $ */ + +/* + * Copyright (c) 2011 Philip Guenther + * + * 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 *)(p)->p_md.md_regs->fixreg[13]) +#define TCB_SET(p, addr) \ + ((p)->p_md.md_regs->fixreg[13] = (__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 0x7008 + +register void *__tcb __asm__ ("r13"); +#define TCB_GET() (__tcb) +#define TCB_SET(tcb) ((__tcb) = (tcb)) + +#endif /* _KERNEL */ +#endif /* _MACHINE_TCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/timetc.h b/lib/libc/include/powerpc64-openbsd-none/machine/timetc.h new file mode 100644 index 0000000000..9c07a63a52 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/timetc.h @@ -0,0 +1,23 @@ +/* $OpenBSD: timetc.h,v 1.2 2022/11/05 16:23:02 cheloha Exp $ */ +/* + * Copyright (c) 2020 Paul Irofti + * + * 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_TIMETC_H_ +#define _MACHINE_TIMETC_H_ + +#define TC_TB 1 + +#endif /* _MACHINE_TIMETC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/trap.h b/lib/libc/include/powerpc64-openbsd-none/machine/trap.h new file mode 100644 index 0000000000..7e1ef37d29 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/trap.h @@ -0,0 +1,158 @@ +/* $OpenBSD: trap.h,v 1.9 2022/05/19 05:43:48 miod Exp $ */ +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * 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. + * + * $NetBSD: trap.h,v 1.7 2002/02/22 13:51:40 kleink Exp $ + */ + +#ifndef _MACHINE_TRAP_H_ +#define _MACHINE_TRAP_H_ + +#define EXC_RSVD 0x0000 /* Reserved */ +#define EXC_RST 0x0100 /* Reset; all but IBM4xx */ +#define EXC_MCHK 0x0200 /* Machine Check */ +#define EXC_DSI 0x0300 /* Data Storage Interrupt */ +#define EXC_DSE 0x0380 /* Data Segment Interrupt */ +#define EXC_ISI 0x0400 /* Instruction Storage Interrupt */ +#define EXC_ISE 0x0480 /* Instruction Segment Interrupt */ +#define EXC_EXI 0x0500 /* External Interrupt */ +#define EXC_ALI 0x0600 /* Alignment Interrupt */ +#define EXC_PGM 0x0700 /* Program Interrupt */ +#define EXC_FPU 0x0800 /* Floating-point Unavailable */ +#define EXC_DECR 0x0900 /* Decrementer Interrupt */ +#define EXC_SC 0x0c00 /* System Call */ +#define EXC_TRC 0x0d00 /* Trace */ +#define EXC_FPA 0x0e00 /* Floating-point Assist */ + +/* The following is only available on the 601: */ +#define EXC_RUNMODETRC 0x2000 /* Run Mode/Trace Exception */ + +/* The following are only available on 970(G5): */ +#define EXC_VECAST_G5 0x1700 /* AltiVec Assist */ + +/* The following are only available on 7400(G4): */ +#define EXC_VEC 0x0f20 /* AltiVec Unavailable */ +#define EXC_VECAST_G4 0x1600 /* AltiVec Assist */ + +/* The following are only available on 604/750/7400: */ +#define EXC_PERF 0x0f00 /* Performance Monitoring */ +#define EXC_BPT 0x1300 /* Instruction Breakpoint */ +#define EXC_SMI 0x1400 /* System Management Interrupt */ + +/* The following are only available on 750/7400: */ +#define EXC_THRM 0x1700 /* Thermal Management Interrupt */ + +/* And these are only on the 603: */ +#define EXC_IMISS 0x1000 /* Instruction translation miss */ +#define EXC_DLMISS 0x1100 /* Data load translation miss */ +#define EXC_DSMISS 0x1200 /* Data store translation miss */ + +/* Power ISA 2.06+: */ +#define EXC_HDSI 0x0e00 /* Hypervisor Data Storage */ +#define EXC_HISI 0x0e20 /* Hypervisor Instruction Storage */ +#define EXC_HEA 0x0e40 /* Hypervisor Emulation Assistance */ +#define EXC_HMI 0x0e60 /* Hypervisor Maintenance */ +#define EXC_VSX 0x0f40 /* VSX Unavailable */ + +/* Power ISA 2.07+: */ +#define EXC_FAC 0x0f60 /* Facility Unavailable */ +#define EXC_HFAC 0x0f80 /* Hypervisor Facility Unavailable */ + +/* Power ISA 3.0+: */ +#define EXC_HVI 0x0ea0 /* Hypervisor Virtualization */ + +/* The following are available on 4xx and 85xx */ +#define EXC_CRIT 0x0100 /* Critical Input Interrupt */ +#define EXC_PIT 0x1000 /* Programmable Interval Timer */ +#define EXC_FIT 0x1010 /* Fixed Interval Timer */ +#define EXC_WDOG 0x1020 /* Watchdog Timer */ +#define EXC_DTMISS 0x1100 /* Data TLB Miss */ +#define EXC_ITMISS 0x1200 /* Instruction TLB Miss */ +#define EXC_APU 0x1300 /* Auxiliary Processing Unit */ +#define EXC_DEBUG 0x2f10 /* Debug trap */ +#define EXC_VECAST_E 0x2f20 /* Altivec Assist (Book-E) */ +#define EXC_SPFPD 0x2f30 /* SPE Floating-point Data */ +#define EXC_SPFPR 0x2f40 /* SPE Floating-point Round */ + +/* POWER8 */ +#define EXC_SOFT_PATCH 0x1500 /* POWER8 Soft Patch Exception */ + +#define EXC_END 0x3000 /* End of exception vectors */ + +#define EXC_AST 0x3000 /* Fake AST vector */ + +/* Trap was in user mode */ +#define EXC_USER 0x10000 + + +/* + * EXC_ALI sets bits in the DSISR and DAR to provide enough + * information to recover from the unaligned access without needing to + * parse the offending instruction. This includes certain bits of the + * opcode, and information about what registers are used. The opcode + * indicator values below come from Appendix F of Book III of "The + * PowerPC Architecture". + */ + +#define EXC_ALI_OPCODE_INDICATOR(dsisr) ((dsisr >> 10) & 0x7f) +#define EXC_ALI_LFD 0x09 +#define EXC_ALI_STFD 0x0b + +/* Macros to extract register information */ +#define EXC_ALI_RST(dsisr) ((dsisr >> 5) & 0x1f) /* source or target */ +#define EXC_ALI_RA(dsisr) (dsisr & 0x1f) +#define EXC_ALI_INST_RST(instr) ((instr >> 21) & 0x1f) + +/* + * SRR1 bits for program exception traps. These identify what caused + * the program exception. See section 6.5.9 of the Power ISA Version + * 2.05. + */ + +#define EXC_PGM_FPENABLED (1UL << 20) +#define EXC_PGM_ILLEGAL (1UL << 19) +#define EXC_PGM_PRIV (1UL << 18) +#define EXC_PGM_TRAP (1UL << 17) + +/* + * DSISR bits. + */ + +#define DSISR_STORE (1UL << 25) + +/* Magic pointers to store trap handler entry points */ +#define TRAP_ENTRY 0x1f8 +#define TRAP_HVENTRY 0x1f0 +#define TRAP_SLBENTRY 0x1e8 +#define TRAP_RSTENTRY 0x1e0 + +#endif /* _MACHINE_TRAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/machine/vmparam.h b/lib/libc/include/powerpc64-openbsd-none/machine/vmparam.h new file mode 100644 index 0000000000..4cad35a1a2 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/machine/vmparam.h @@ -0,0 +1,53 @@ +/* + * 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)32*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_PHYS_SIZE (USRIOSIZE * PAGE_SIZE) + +#define VM_PHYSSEG_MAX 32 +#define VM_PHYSSEG_STRAT VM_PSTRAT_BSEARCH + +#define VM_MIN_ADDRESS ((vaddr_t)PAGE_SIZE) +#define VM_MAXUSER_ADDRESS 0xbffffffffffff000UL +#define VM_MAX_ADDRESS 0xffffffffffffffffUL +#ifdef _KERNEL +#define VM_MIN_STACK_ADDRESS 0x9000000000000000UL +#endif +#define VM_MIN_KERNEL_ADDRESS 0xc000000000000000UL +#define VM_MAX_KERNEL_ADDRESS 0xc0000007ffffffffUL \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/_float.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/_float.h new file mode 100644 index 0000000000..14a56d926e --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/_float.h @@ -0,0 +1,71 @@ +/* $OpenBSD: _float.h,v 1.1 2020/06/01 00:13:37 drahn Exp $ */ + +/* + * Copyright (c) 1989 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _MACHINE__FLOAT_H_ +#define _MACHINE__FLOAT_H_ + +#define __FLT_RADIX 2 /* b */ +#define __FLT_ROUNDS __flt_rounds() +#define __FLT_EVAL_METHOD 0 /* no promotions */ + +#define __FLT_MANT_DIG 24 /* p */ +#define __FLT_EPSILON 1.19209290E-07F /* b**(1-p) */ +#define __FLT_DIG 6 /* floor((p-1)*log10(b))+(b == 10) */ +#define __FLT_MIN_EXP (-125) /* emin */ +#define __FLT_MIN 1.17549435E-38F /* b**(emin-1) */ +#define __FLT_MIN_10_EXP (-37) /* ceil(log10(b**(emin-1))) */ +#define __FLT_MAX_EXP 128 /* emax */ +#define __FLT_MAX 3.40282347E+38F /* (1-b**(-p))*b**emax */ +#define __FLT_MAX_10_EXP 38 /* floor(log10((1-b**(-p))*b**emax)) */ + +#define __DBL_MANT_DIG 53 +#define __DBL_EPSILON 2.2204460492503131E-16 +#define __DBL_DIG 15 +#define __DBL_MIN_EXP (-1021) +#define __DBL_MIN 2.2250738585072014E-308 +#define __DBL_MIN_10_EXP (-307) +#define __DBL_MAX_EXP 1024 +#define __DBL_MAX 1.7976931348623157E+308 +#define __DBL_MAX_10_EXP 308 + +#define __LDBL_MANT_DIG DBL_MANT_DIG +#define __LDBL_EPSILON DBL_EPSILON +#define __LDBL_DIG DBL_DIG +#define __LDBL_MIN_EXP DBL_MIN_EXP +#define __LDBL_MIN DBL_MIN +#define __LDBL_MIN_10_EXP DBL_MIN_10_EXP +#define __LDBL_MAX_EXP DBL_MAX_EXP +#define __LDBL_MAX DBL_MAX +#define __LDBL_MAX_10_EXP DBL_MAX_10_EXP + +#define __DECIMAL_DIG 17 + +#endif /* _MACHINE__FLOAT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/_types.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/_types.h new file mode 100644 index 0000000000..c8b810163d --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/_types.h @@ -0,0 +1,145 @@ +/* $OpenBSD: _types.h,v 1.4 2023/07/02 19:02:28 cheloha 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[22]; +} 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_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/apmvar.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/apmvar.h new file mode 100644 index 0000000000..2c911df088 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/apmvar.h @@ -0,0 +1,122 @@ +/* $OpenBSD: apmvar.h,v 1.1 2020/07/15 22:46:51 deraadt Exp $ */ + +/* + * Copyright (c) 2001 Alexander Guy + * Copyright (c) 1995 John T. Kohl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef _POWERPC64_APMVAR_H_ +#define _POWERPC64_APMVAR_H_ + +#include + +/* Advanced Power Management (v1.0 and v1.1 specification) + * functions/defines/etc. + */ + +/* These definitions make up the heart of the user-land interface + * to the APM devices. + */ + +#define APM_AC_OFF 0x00 +#define APM_AC_ON 0x01 +#define APM_AC_BACKUP 0x02 +#define APM_AC_UNKNOWN 0xff +#define APM_BATT_HIGH 0x00 +#define APM_BATT_LOW 0x01 +#define APM_BATT_CRITICAL 0x02 +#define APM_BATT_CHARGING 0x03 +#define APM_BATT_UNKNOWN 0xff +#define APM_BATT_LIFE_UNKNOWN 0xff + +#define APM_NOEVENT 0x0000 +#define APM_STANDBY_REQ 0x0001 +#define APM_SUSPEND_REQ 0x0002 +#define APM_NORMAL_RESUME 0x0003 +#define APM_CRIT_RESUME 0x0004 /* suspend/resume happened + without us */ +#define APM_BATTERY_LOW 0x0005 +#define APM_POWER_CHANGE 0x0006 +#define APM_UPDATE_TIME 0x0007 +#define APM_CRIT_SUSPEND_REQ 0x0008 +#define APM_USER_STANDBY_REQ 0x0009 +#define APM_USER_SUSPEND_REQ 0x000A +#define APM_SYS_STANDBY_RESUME 0x000B +#define APM_CAPABILITY_CHANGE 0x000C /* apm v1.2 */ +#define APM_USER_HIBERNATE_REQ 0x000D +#define APM_EVENT_MASK 0xffff + +#define APM_EVENT_COMPOSE(t,i) ((((i) & 0x7fff) << 16)|((t) & APM_EVENT_MASK)) +#define APM_EVENT_TYPE(e) ((e) & APM_EVENT_MASK) +#define APM_EVENT_INDEX(e) ((e) >> 16) + +/* + * LP (Laptop Package) + * + * Copyright (C) 1994 by HOSOKAWA Tatsumi + * + * This software may be used, modified, copied, and distributed, in + * both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + */ + +#define APM_BATTERY_ABSENT 4 + +struct apm_power_info { + u_char battery_state; + u_char ac_state; + u_char battery_life; + u_char spare1; + u_int minutes_left; /* estimate */ + u_int spare2[6]; +}; + +struct apm_ctl { + u_int dev; + u_int mode; +}; + +#define APM_IOC_REJECT _IOW('A', 0, struct apm_event_info) /* reject request # */ +#define APM_IOC_STANDBY _IO('A', 1) /* put system into standby */ +#define APM_IOC_SUSPEND _IO('A', 2) /* put system into suspend */ +#define APM_IOC_GETPOWER _IOR('A', 3, struct apm_power_info) /* fetch battery state */ +#define APM_IOC_DEV_CTL _IOW('A', 5, struct apm_ctl) /* put device into mode */ +#define APM_IOC_PRN_CTL _IOW('A', 6, int ) /* driver power status msg */ +#define APM_PRINT_ON 0 /* driver power status displayed */ +#define APM_PRINT_OFF 1 /* driver power status not displayed */ +#define APM_PRINT_PCT 2 /* driver power status only displayed + if the percentage changes */ +#define APM_IOC_STANDBY_REQ _IO('A', 7) /* request standby */ +#define APM_IOC_SUSPEND_REQ _IO('A', 8) /* request suspend */ +#define APM_IOC_HIBERNATE _IO('A', 9) /* put system into hibernate */ + +#endif /* _POWERPC64_APMVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/asm.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/asm.h new file mode 100644 index 0000000000..b630e137aa --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/asm.h @@ -0,0 +1,100 @@ +/* $OpenBSD: asm.h,v 1.7 2022/12/07 23:25:59 guenther Exp $ */ + +/* + * Copyright (c) 2020 Dale Rahn + * + * 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 _POWERPC64_ASM_H_ +#define _POWERPC64_ASM_H_ + +#define _C_LABEL(x) x +#define _ASM_LABEL(x) x + +#define _TMP_LABEL(x) .L_ ## x +#define _GEP_LABEL(x) .L_ ## x ## _gep0 +#define _LEP_LABEL(x) .L_ ## x ## _lep0 + +#define _ENTRY(x) \ + .text; .align 2; .globl x; .type x,@function; x: \ + _GEP_LABEL(x): \ + addis %r2, %r12, .TOC.-_GEP_LABEL(x)@ha; \ + addi %r2, %r2, .TOC.-_GEP_LABEL(x)@l; \ + _LEP_LABEL(x): \ + .localentry x, _LEP_LABEL(x)-_GEP_LABEL(x); + +#if defined(PROF) || defined(GPROF) +# define _PROF_PROLOGUE(y) \ + .section ".data"; \ + .align 2; \ +_TMP_LABEL(y):; \ + .long 0; \ + .section ".text"; \ + mflr %r0; \ + addis %r11, %r2, _TMP_LABEL(y)@toc@ha; \ + std %r0, 8(%r1); \ + addi %r0, %r11, _TMP_LABEL(y)@toc@l; \ + bl _mcount; +#else +# define _PROF_PROLOGUE(y) +#endif + +#define ENTRY(y) _ENTRY(y); _PROF_PROLOGUE(y) +#define ASENTRY(y) _ENTRY(y); _PROF_PROLOGUE(y) +#define END(y) .size y, . - y + +#define STRONG_ALIAS(alias,sym) \ + .global alias; .set alias,sym +#define WEAK_ALIAS(alias,sym) \ + .weak alias; .set alias,sym + +#if defined(_RET_PROTECTOR) +# define RETGUARD_SETUP(x, reg) \ + RETGUARD_SYMBOL(x); \ + mflr %r0; \ + addis reg, %r2, (__retguard_ ## x)@toc@ha; \ + ld reg, ((__retguard_ ## x)@toc@l)(reg); \ + xor reg, reg, %r0 +# define RETGUARD_CHECK(x, reg) \ + mflr %r0; \ + xor reg, reg, %r0; \ + addis %r12, %r2, (__retguard_ ## x)@toc@ha; \ + ld %r12, ((__retguard_ ## x)@toc@l)(%r12); \ + tdne reg, %r12 +# define RETGUARD_SAVE(reg, loc) \ + std reg, loc +# define RETGUARD_LOAD(reg, loc) \ + ld reg, loc +# define RETGUARD_SYMBOL(x) \ + .ifndef __retguard_ ## x; \ + .hidden __retguard_ ## x; \ + .type __retguard_ ## x,@object; \ + .pushsection .openbsd.randomdata.retguard,"aw",@progbits; \ + .weak __retguard_ ## x; \ + .p2align 3; \ + __retguard_ ## x: ; \ + .quad 0; \ + .size __retguard_ ## x, 8; \ + .popsection; \ + .endif +#else +# define RETGUARD_SETUP(x, reg) +# define RETGUARD_CHECK(x, reg) +# define RETGUARD_SAVE(reg, loc) +# define RETGUARD_LOAD(reg, loc) +# define RETGUARD_SYMBOL(x) +#endif + + +#endif /* !_POWERPC64_ASM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/atomic.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/atomic.h new file mode 100644 index 0000000000..277291b926 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/atomic.h @@ -0,0 +1,292 @@ +/* $OpenBSD: atomic.h,v 1.3 2022/08/29 02:01:18 jsg 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: lwarx %0, 0, %2 \n" + " stwcx. %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_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/bus.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/bus.h new file mode 100644 index 0000000000..626dcdbbca --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/bus.h @@ -0,0 +1,532 @@ +/* $OpenBSD: bus.h,v 1.5 2020/11/15 23:13:00 kettenis Exp $ */ +/* + * Copyright (c) 2003-2004 Opsycon AB Sweden. 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_BUS_H_ +#define _MACHINE_BUS_H_ + +#define CAT(a,b) a##b +#define CAT3(a,b,c) a##b##c + +/* + * Bus access types. + */ +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; +typedef struct bus_space bus_space_t; + +struct bus_space { + bus_addr_t bus_base; + void *bus_private; + uint8_t (*_space_read_1)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_1)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, uint8_t); + uint16_t (*_space_read_2)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_2)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, uint16_t); + uint32_t (*_space_read_4)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_4)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, uint32_t); + uint64_t (*_space_read_8)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_8)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, uint64_t); + void (*_space_read_raw_2)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); + void (*_space_write_raw_2)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); + void (*_space_read_raw_4)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); + void (*_space_write_raw_4)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); + void (*_space_read_raw_8)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); + void (*_space_write_raw_8)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); + int (*_space_map)(bus_space_tag_t , bus_addr_t, + bus_size_t, int, bus_space_handle_t *); + void (*_space_unmap)(bus_space_tag_t, bus_space_handle_t, + bus_size_t); + int (*_space_subregion)(bus_space_tag_t, bus_space_handle_t, + bus_size_t, bus_size_t, bus_space_handle_t *); + void * (*_space_vaddr)(bus_space_tag_t, bus_space_handle_t); + paddr_t (*_space_mmap)(bus_space_tag_t, bus_addr_t, off_t, + int, int); +}; + +#define bus_space_read_1(t, h, o) (*(t)->_space_read_1)((t), (h), (o)) +#define bus_space_read_2(t, h, o) (*(t)->_space_read_2)((t), (h), (o)) +#define bus_space_read_4(t, h, o) (*(t)->_space_read_4)((t), (h), (o)) +#define bus_space_read_8(t, h, o) (*(t)->_space_read_8)((t), (h), (o)) + +#define bus_space_write_1(t, h, o, v) (*(t)->_space_write_1)((t), (h), (o), (v)) +#define bus_space_write_2(t, h, o, v) (*(t)->_space_write_2)((t), (h), (o), (v)) +#define bus_space_write_4(t, h, o, v) (*(t)->_space_write_4)((t), (h), (o), (v)) +#define bus_space_write_8(t, h, o, v) (*(t)->_space_write_8)((t), (h), (o), (v)) + +#define bus_space_read_raw_2(t, h, o) \ + generic_space_read_2((t), (h), (o)) +#define bus_space_read_raw_4(t, h, o) \ + generic_space_read_4((t), (h), (o)) +#define bus_space_read_raw_8(t, h, o) \ + generic_space_read_8((t), (h), (o)) + +#define bus_space_write_raw_2(t, h, o, v) \ + generic_space_write_2((t), (h), (o), (v)) +#define bus_space_write_raw_4(t, h, o, v) \ + generic_space_write_4((t), (h), (o), (v)) +#define bus_space_write_raw_8(t, h, o, v) \ + generic_space_write_8((t), (h), (o), (v)) + +#define bus_space_read_raw_multi_2(t, h, a, b, l) \ + (*(t)->_space_read_raw_2)((t), (h), (a), (b), (l)) +#define bus_space_read_raw_multi_4(t, h, a, b, l) \ + (*(t)->_space_read_raw_4)((t), (h), (a), (b), (l)) +#define bus_space_read_raw_multi_8(t, h, a, b, l) \ + (*(t)->_space_read_raw_8)((t), (h), (a), (b), (l)) + +#define bus_space_write_raw_multi_2(t, h, a, b, l) \ + (*(t)->_space_write_raw_2)((t), (h), (a), (b), (l)) +#define bus_space_write_raw_multi_4(t, h, a, b, l) \ + (*(t)->_space_write_raw_4)((t), (h), (a), (b), (l)) +#define bus_space_write_raw_multi_8(t, h, a, b, l) \ + (*(t)->_space_write_raw_8)((t), (h), (a), (b), (l)) + +#define bus_space_map(t, o, s, c, p) (*(t)->_space_map)((t), (o), (s), (c), (p)) +#define bus_space_unmap(t, h, s) (*(t)->_space_unmap)((t), (h), (s)) +#define bus_space_subregion(t, h, o, s, p) \ + (*(t)->_space_subregion)((t), (h), (o), (s), (p)) + +#define BUS_SPACE_MAP_CACHEABLE 0x01 +#define BUS_SPACE_MAP_KSEG0 0x02 +#define BUS_SPACE_MAP_LINEAR 0x04 +#define BUS_SPACE_MAP_PREFETCHABLE 0x08 + +#define bus_space_vaddr(t, h) (*(t)->_space_vaddr)((t), (h)) +#define bus_space_mmap(t, a, o, p, f) \ + (*(t)->_space_mmap)((t), (a), (o), (p), (f)) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_multi(n,m) \ +static __inline void \ +CAT(bus_space_read_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_size_t o, CAT3(uint,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) \ + *x++ = CAT(bus_space_read_,n)(bst, bsh, o); \ +} + +bus_space_read_multi(1,8) +bus_space_read_multi(2,16) +bus_space_read_multi(4,32) +bus_space_read_multi(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_region(n,m) \ +static __inline void \ +CAT(bus_space_read_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, CAT3(uint,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) { \ + *x++ = CAT(bus_space_read_,n)(bst, bsh, ba); \ + ba += (n); \ + } \ +} + +bus_space_read_region(1,8) +bus_space_read_region(2,16) +bus_space_read_region(4,32) +bus_space_read_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_raw_region(n,m) \ +static __inline void \ +CAT(bus_space_read_raw_region_,n)(bus_space_tag_t bst, \ + bus_space_handle_t bsh, \ + bus_addr_t ba, uint8_t *x, size_t cnt) \ +{ \ + cnt >>= ((n) >> 1); \ + while (cnt--) { \ + CAT(bus_space_read_raw_multi_,n)(bst, bsh, ba, x, (n)); \ + ba += (n); \ + x += (n); \ + } \ +} + +bus_space_read_raw_region(2,16) +bus_space_read_raw_region(4,32) +bus_space_read_raw_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_multi(n,m) \ +static __inline void \ +CAT(bus_space_write_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_size_t o, const CAT3(uint,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) \ + CAT(bus_space_write_,n)(bst, bsh, o, *x++); \ +} + +bus_space_write_multi(1,8) +bus_space_write_multi(2,16) +bus_space_write_multi(4,32) +bus_space_write_multi(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_region(n,m) \ +static __inline void \ +CAT(bus_space_write_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, const CAT3(uint,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) { \ + CAT(bus_space_write_,n)(bst, bsh, ba, *x++); \ + ba += (n); \ + } \ +} + +bus_space_write_region(1,8) +bus_space_write_region(2,16) +bus_space_write_region(4,32) +bus_space_write_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_raw_region(n,m) \ +static __inline void \ +CAT(bus_space_write_raw_region_,n)(bus_space_tag_t bst, \ + bus_space_handle_t bsh, \ + bus_addr_t ba, const uint8_t *x, size_t cnt) \ +{ \ + cnt >>= ((n) >> 1); \ + while (cnt--) { \ + CAT(bus_space_write_raw_multi_,n)(bst, bsh, ba, x, (n)); \ + ba += (n); \ + x += (n); \ + } \ +} + +bus_space_write_raw_region(2,16) +bus_space_write_raw_region(4,32) +bus_space_write_raw_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_set_region(n,m) \ +static __inline void \ +CAT(bus_space_set_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, CAT3(uint,m,_t) x, size_t cnt) \ +{ \ + while (cnt--) { \ + CAT(bus_space_write_,n)(bst, bsh, ba, x); \ + ba += (n); \ + } \ +} + +bus_space_set_region(1,8) +bus_space_set_region(2,16) +bus_space_set_region(4,32) +bus_space_set_region(8,64) + +/*----------------------------------------------------------------------------*/ +static __inline void +bus_space_copy_1(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + char *s = (char *)(h1 + o1); + char *d = (char *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + + +static __inline void +bus_space_copy_2(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + short *s = (short *)(h1 + o1); + short *d = (short *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + +static __inline void +bus_space_copy_4(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + int *s = (int *)(h1 + o1); + int *d = (int *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + +static __inline void +bus_space_copy_8(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + int64_t *s = (int64_t *)(h1 + o1); + int64_t *d = (int64_t *)(h2 + o2); + + while (c--) + *d++ = *s++; +} + +/*----------------------------------------------------------------------------*/ +/* + * Bus read/write barrier methods. + * + * void bus_space_barrier(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * bus_size_t len, int flags); + * + */ +static inline void +bus_space_barrier(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, + bus_size_t length, int flags) +{ + __asm__ volatile ("eieio" ::: "memory"); +} +#define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */ +#define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */ + +#define BUS_DMA_WAITOK 0x0000 +#define BUS_DMA_NOWAIT 0x0001 +#define BUS_DMA_ALLOCNOW 0x0002 +#define BUS_DMA_COHERENT 0x0008 +#define BUS_DMA_BUS1 0x0010 /* placeholders for bus functions... */ +#define BUS_DMA_BUS2 0x0020 +#define BUS_DMA_BUS3 0x0040 +#define BUS_DMA_BUS4 0x0080 +#define BUS_DMA_READ 0x0100 /* mapping is device -> memory only */ +#define BUS_DMA_WRITE 0x0200 /* mapping is memory -> device only */ +#define BUS_DMA_STREAMING 0x0400 /* hint: sequential, unidirectional */ +#define BUS_DMA_ZERO 0x0800 /* zero memory in dmamem_alloc */ +#define BUS_DMA_NOCACHE 0x1000 +#define BUS_DMA_64BIT 0x2000 /* device handles 64bit dva */ + +/* Forwards needed by prototypes below. */ +struct mbuf; +struct proc; +struct uio; + +#define BUS_DMASYNC_POSTREAD 0x0001 +#define BUS_DMASYNC_POSTWRITE 0x0002 +#define BUS_DMASYNC_PREREAD 0x0004 +#define BUS_DMASYNC_PREWRITE 0x0008 + +typedef struct machine_bus_dma_tag *bus_dma_tag_t; +typedef struct machine_bus_dmamap *bus_dmamap_t; + +/* + * bus_dma_segment_t + * + * Describes a single contiguous DMA transaction. Values + * are suitable for programming into DMA registers. + */ +struct machine_bus_dma_segment { + bus_addr_t ds_addr; /* DMA address */ + bus_size_t ds_len; /* length of transfer */ + + paddr_t _ds_paddr; /* CPU address */ + vaddr_t _ds_vaddr; /* CPU address */ +}; +typedef struct machine_bus_dma_segment bus_dma_segment_t; + +/* + * bus_dma_tag_t + * + * A machine-dependent opaque type describing the implementation of + * DMA for a given bus. + */ + +struct machine_bus_dma_tag { + void *_cookie; /* cookie used in the guts */ + int _flags; /* misc. flags */ + + /* + * DMA mapping methods. + */ + int (*_dmamap_create)(bus_dma_tag_t , bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); + void (*_dmamap_destroy)(bus_dma_tag_t , bus_dmamap_t); + int (*_dmamap_load)(bus_dma_tag_t , bus_dmamap_t, void *, + bus_size_t, struct proc *, int); + int (*_dmamap_load_mbuf)(bus_dma_tag_t , bus_dmamap_t, + struct mbuf *, int); + int (*_dmamap_load_uio)(bus_dma_tag_t , bus_dmamap_t, + struct uio *, int); + int (*_dmamap_load_raw)(bus_dma_tag_t , bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); + int (*_dmamap_load_buffer)(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int, paddr_t *, int *, int); + void (*_dmamap_unload)(bus_dma_tag_t , bus_dmamap_t); + void (*_dmamap_sync)(bus_dma_tag_t , bus_dmamap_t, + bus_addr_t, bus_size_t, int); + + /* + * DMA memory utility functions. + */ + int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); + void (*_dmamem_free)(bus_dma_tag_t, bus_dma_segment_t *, int); + int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); + void (*_dmamem_unmap)(bus_dma_tag_t, caddr_t, size_t); + paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *, + int, off_t, int, int); + + /* + * internal memory address translation information. + */ + bus_addr_t _dma_mask; +}; + +#define bus_dmamap_create(t, s, n, m, b, f, p) \ + (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p)) +#define bus_dmamap_destroy(t, p) \ + (*(t)->_dmamap_destroy)((t), (p)) +#define bus_dmamap_load(t, m, b, s, p, f) \ + (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f)) +#define bus_dmamap_load_mbuf(t, m, b, f) \ + (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f)) +#define bus_dmamap_load_uio(t, m, u, f) \ + (*(t)->_dmamap_load_uio)((t), (m), (u), (f)) +#define bus_dmamap_load_raw(t, m, sg, n, s, f) \ + (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f)) +#define bus_dmamap_unload(t, p) \ + (*(t)->_dmamap_unload)((t), (p)) +#define bus_dmamap_sync(t, p, a, l, o) \ + (void)((t)->_dmamap_sync ? \ + (*(t)->_dmamap_sync)((t), (p), (a), (l), (o)) : (void)0) + +#define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \ + (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f)) +#define bus_dmamem_free(t, sg, n) \ + (*(t)->_dmamem_free)((t), (sg), (n)) +#define bus_dmamem_map(t, sg, n, s, k, f) \ + (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f)) +#define bus_dmamem_unmap(t, k, s) \ + (*(t)->_dmamem_unmap)((t), (k), (s)) +#define bus_dmamem_mmap(t, sg, n, o, p, f) \ + (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f)) + +int _dmamap_create(bus_dma_tag_t, bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); +void _dmamap_destroy(bus_dma_tag_t, bus_dmamap_t); +int _dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int); +int _dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, struct mbuf *, int); +int _dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, struct uio *, int); +int _dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); +int _dmamap_load_buffer(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int, paddr_t *, int *, int); +void _dmamap_unload(bus_dma_tag_t, bus_dmamap_t); +void _dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, + bus_size_t, int); + +int _dmamem_alloc(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); +void _dmamem_free(bus_dma_tag_t, bus_dma_segment_t *, int); +int _dmamem_map(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); +void _dmamem_unmap(bus_dma_tag_t, caddr_t, size_t); +paddr_t _dmamem_mmap(bus_dma_tag_t, bus_dma_segment_t *, int, off_t, int, int); +int _dmamem_alloc_range(bus_dma_tag_t, bus_size_t, bus_size_t, bus_size_t, + bus_dma_segment_t *, int, int *, int, paddr_t, paddr_t); + +/* + * bus_dmamap_t + * + * Describes a DMA mapping. + */ +struct machine_bus_dmamap { + /* + * PRIVATE MEMBERS: not for use by machine-independent code. + */ + bus_size_t _dm_size; /* largest DMA transfer mappable */ + int _dm_segcnt; /* number of segs this map can map */ + bus_size_t _dm_maxsegsz; /* largest possible segment */ + bus_size_t _dm_boundary; /* don't cross this */ + int _dm_flags; /* misc. flags */ + + void *_dm_cookie; /* cookie for bus-specific functions */ + + /* + * PUBLIC MEMBERS: these are used by machine-independent code. + */ + bus_size_t dm_mapsize; /* size of the mapping */ + int dm_nsegs; /* # valid segments in mapping */ + bus_dma_segment_t dm_segs[1]; /* segments; variable length */ +}; + +int generic_space_map(bus_space_tag_t, bus_addr_t, bus_size_t, int, + bus_space_handle_t *); +void generic_space_unmap(bus_space_tag_t, bus_space_handle_t, bus_size_t); +int generic_space_region(bus_space_tag_t, bus_space_handle_t, bus_size_t, + bus_size_t, bus_space_handle_t *); +void *generic_space_vaddr(bus_space_tag_t, bus_space_handle_t); +paddr_t generic_space_mmap(bus_space_tag_t, bus_addr_t, off_t, int, int); +uint8_t generic_space_read_1(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint16_t generic_space_read_2(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint32_t generic_space_read_4(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint64_t generic_space_read_8(bus_space_tag_t, bus_space_handle_t, bus_size_t); +void generic_space_write_1(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint8_t); +void generic_space_write_2(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint16_t); +void generic_space_write_4(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint32_t); +void generic_space_write_8(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint64_t); +void generic_space_read_raw_2(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_raw_2(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); +void generic_space_read_raw_4(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_raw_4(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); +void generic_space_read_raw_8(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_raw_8(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); + +uint16_t little_space_read_2(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint32_t little_space_read_4(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint64_t little_space_read_8(bus_space_tag_t, bus_space_handle_t, bus_size_t); +void little_space_write_2(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint16_t); +void little_space_write_4(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint32_t); +void little_space_write_8(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint64_t); + +#endif /* _MACHINE_BUS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/cdefs.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/cdefs.h new file mode 100644 index 0000000000..dcf667bff9 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/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 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_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/conf.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/conf.h new file mode 100644 index 0000000000..bed3c41fe6 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/conf.h @@ -0,0 +1,24 @@ +#include + +#define mmread mmrw +#define mmwrite mmrw +cdev_decl(mm); + +cdev_decl(opalcons); + +/* open, close, ioctl */ +#define cdev_kexec_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) nullop, 0, \ + (dev_type_mmap((*))) enodev } + +/* open, close, ioctl */ +#define cdev_openprom_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) nullop, 0, \ + (dev_type_mmap((*))) enodev } + +cdev_decl(kexec); +cdev_decl(openprom); \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/cpu.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/cpu.h new file mode 100644 index 0000000000..f5e0e18115 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/cpu.h @@ -0,0 +1,234 @@ +/* $OpenBSD: cpu.h,v 1.39 2024/11/28 18:54:36 gkoehler Exp $ */ + +/* + * Copyright (c) 2020 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_CPU_H_ +#define _MACHINE_CPU_H_ + +/* + * User-visible definitions + */ + +/* + * CTL_MACHDEP definitions. + */ +#define CPU_ALTIVEC 1 /* altivec is present */ +#define CPU_MAXID 2 /* number of valid machdep ids */ + +#define CTL_MACHDEP_NAMES { \ + { 0, 0 }, \ + { "altivec", CTLTYPE_INT }, \ +} + +#ifdef _KERNEL + +/* + * Kernel-only definitions + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +struct cpu_info { + struct device *ci_dev; + struct cpu_info *ci_next; + struct schedstate_percpu ci_schedstate; + + uint32_t ci_cpuid; + uint32_t ci_pir; + int ci_node; + + struct proc *ci_curproc; + struct pcb *ci_curpcb; + + struct slb ci_kernel_slb[32]; + paddr_t ci_user_slb_pa; + register_t ci_slbsave[18]; + char ci_slbstack[1024]; + +#define CPUSAVE_LEN 9 + register_t ci_tempsave[CPUSAVE_LEN]; + register_t ci_idle_sp_save; + + struct clockqueue ci_queue; + + volatile int ci_cpl; + volatile int ci_dec_deferred; + uint32_t ci_ipending; + uint32_t ci_idepth; +#ifdef DIAGNOSTIC + int ci_mutex_level; +#endif + int ci_want_resched; + + uint32_t ci_randseed; + +#ifdef MULTIPROCESSOR + struct srp_hazard ci_srp_hazards[SRP_HAZARD_NUM]; + void *ci_initstack_end; + void *ci_ipi; + int ci_ipi_reason; + volatile int ci_flags; +#endif + +#ifdef DDB + volatile int ci_ddb_paused; +#define CI_DDB_RUNNING 0 +#define CI_DDB_SHOULDSTOP 1 +#define CI_DDB_STOPPED 2 +#define CI_DDB_ENTERDDB 3 +#define CI_DDB_INDDB 4 +#endif + char ci_panicbuf[512]; +}; + +#define CPUF_PRIMARY (1 << 0) +#define CPUF_AP (1 << 1) +#define CPUF_IDENTIFY (1 << 2) +#define CPUF_IDENTIFIED (1 << 3) +#define CPUF_PRESENT (1 << 4) +#define CPUF_GO (1 << 5) +#define CPUF_RUNNING (1 << 6) + +extern struct cpu_info cpu_info[]; +extern struct cpu_info *cpu_info_primary; + +static __inline struct cpu_info * +curcpu(void) +{ + struct cpu_info *ci; + __asm volatile ("mfsprg0 %0" : "=r"(ci)); + return ci; +} + +#define CPU_INFO_ITERATOR int + +#ifndef MULTIPROCESSOR + +#define MAXCPUS 1 +#define CPU_IS_PRIMARY(ci) 1 +#define CPU_IS_RUNNING(ci) 1 +#define cpu_number() 0 + +#define CPU_INFO_UNIT(ci) 0 +#define CPU_INFO_FOREACH(cii, ci) \ + for (cii = 0, ci = curcpu(); ci != NULL; ci = NULL) + +#define cpu_kick(ci) +#define cpu_unidle(ci) + +#else + +#define MAXCPUS 48 +#define CPU_IS_PRIMARY(ci) ((ci) == cpu_info_primary) +#define CPU_IS_RUNNING(ci) ((ci)->ci_flags & CPUF_RUNNING) +#define cpu_number() (curcpu()->ci_cpuid) + +#define CPU_INFO_UNIT(ci) ((ci)->ci_dev ? (ci)->ci_dev->dv_unit : 0) +#define CPU_INFO_FOREACH(cii, ci) \ + for (cii = 0, ci = &cpu_info[0]; cii < ncpus; cii++, ci++) + +void cpu_kick(struct cpu_info *); +void cpu_unidle(struct cpu_info *); +void cpu_boot_secondary_processors(void); + +extern void (*ul_setperf)(int); +void mp_setperf(int); + +#endif + +#define clockframe trapframe + +#define CLKF_INTR(frame) (curcpu()->ci_idepth > 1) +#define CLKF_USERMODE(frame) (frame->srr1 & PSL_PR) +#define CLKF_PC(frame) (frame->srr0) + +#define aston(p) ((p)->p_md.md_astpending = 1) +#define need_proftick(p) aston(p) + +void signotify(struct proc *); + +#define CPU_BUSY_CYCLE() __asm volatile ("" ::: "memory") + +#define curpcb curcpu()->ci_curpcb + +void cpu_init_features(void); +void cpu_init(void); + +#define cpu_idle_enter() do { /* nothing */ } while (0) +#define cpu_idle_leave() do { /* nothing */ } while (0) +extern uint64_t cpu_idle_state_psscr; +extern void (*cpu_idle_cycle_fcn)(void); + +static inline unsigned int +cpu_rnd_messybits(void) +{ + uint64_t tb; + + __asm volatile("mftb %0" : "=r" (tb)); + return ((tb >> 32) ^ tb); +} + +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 PROC_STACK(p) ((p)->p_md.md_regs->fixreg[1]) +#define PROC_PC(p) ((p)->p_md.md_regs->srr0) + +void proc_trampoline(void); + +static inline void +intr_enable(void) +{ + mtmsr(mfmsr() | PSL_EE); +} + +static inline u_long +intr_disable(void) +{ + u_long msr; + + msr = mfmsr(); + mtmsr(msr & ~PSL_EE); + return msr; +} + +static inline void +intr_restore(u_long msr) +{ + mtmsr(msr); +} + +#endif /* _KERNEL */ + +#ifdef MULTIPROCESSOR +#include +#endif /* MULTIPROCESSOR */ + +#endif /* _MACHINE_CPU_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/cpufunc.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/cpufunc.h new file mode 100644 index 0000000000..161e89a9b8 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/cpufunc.h @@ -0,0 +1,222 @@ +/* $OpenBSD: cpufunc.h,v 1.11 2023/01/25 09:53:53 kettenis Exp $ */ + +/* + * Copyright (c) 2020 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_CPUFUNC_H_ +#define _MACHINE_CPUFUNC_H_ + +static inline void +eieio(void) +{ + __asm volatile ("eieio" ::: "memory"); +} + +static inline void +isync(void) +{ + __asm volatile ("isync" ::: "memory"); +} + +static inline void +ptesync(void) +{ + __asm volatile ("ptesync" ::: "memory"); +} + +static inline void +sync(void) +{ + __asm volatile ("sync" ::: "memory"); +} + +static inline void +slbia(void) +{ + __asm volatile ("slbia"); +} + +static inline void +slbie(uint64_t esid) +{ + __asm volatile ("slbie %0" :: "r"(esid)); +} + +static inline uint64_t +slbmfee(uint64_t entry) +{ + uint64_t value; + __asm volatile ("slbmfee %0, %1" : "=r"(value) : "r"(entry)); + return value; +} + +static inline void +slbmte(uint64_t slbv, uint64_t slbe) +{ + __asm volatile ("slbmte %0, %1" :: "r"(slbv), "r"(slbe)); +} + +static inline void +tlbie(uint64_t ava) +{ + __asm volatile ("tlbie %0, %1" :: "r"(ava), "r"(0)); +} + +static inline void +tlbiel(uint64_t ava) +{ + __asm volatile ("tlbiel %0" :: "r"(ava)); +} + +static inline void +tlbsync(void) +{ + __asm volatile ("tlbsync" ::: "memory"); +} + +static inline uint64_t +mfmsr(void) +{ + uint64_t value; + __asm volatile ("mfmsr %0" : "=r"(value)); + return value; +} + +static inline void +mtmsr(uint64_t value) +{ + __asm volatile ("mtmsr %0" :: "r"(value)); +} + +static inline uint64_t +mftb(void) +{ + uint64_t value; + __asm volatile ("mftb %0" : "=r"(value)); + return value; +} + +static inline uint32_t +mfdsisr(void) +{ + uint32_t value; + __asm volatile ("mfdsisr %0" : "=r"(value)); + return value; +} + +static inline uint64_t +mfdar(void) +{ + uint64_t value; + __asm volatile ("mfdar %0" : "=r"(value)); + return value; +} + +static inline void +mtdec(uint32_t value) +{ + __asm volatile ("mtdec %0" :: "r"(value)); +} + +static inline void +mtsdr1(uint64_t value) +{ + __asm volatile ("mtsdr1 %0" :: "r"(value)); +} + +static inline void +mtamr(uint64_t value) +{ + __asm volatile ("mtspr 29, %0" :: "r"(value)); +} + +static inline void +mtfscr(uint64_t value) +{ + __asm volatile ("mtspr 153, %0" :: "r"(value)); +} + +static inline void +mtuamor(uint64_t value) +{ + __asm volatile ("mtspr 157, %0" :: "r"(value)); +} + +static inline uint32_t +mfpvr(void) +{ + uint32_t value; + __asm volatile ("mfspr %0, 287" : "=r"(value)); + return value; +} + +static inline uint64_t +mflpcr(void) +{ + uint64_t value; + __asm volatile ("mfspr %0, 318" : "=r"(value)); + return value; +} + +static inline void +mtlpcr(uint64_t value) +{ + __asm volatile ("mtspr 318, %0" :: "r"(value)); +} + +#define LPCR_PECE 0x000040000001f000UL +#define LPCR_LPES 0x0000000000000008UL +#define LPCR_HVICE 0x0000000000000002UL + +static inline void +mtamor(uint64_t value) +{ + __asm volatile ("mtspr 349, %0" :: "r"(value)); +} + +static inline void +mtptcr(uint64_t value) +{ + __asm volatile ("mtspr 464, %0" :: "r"(value)); +} + +static inline uint64_t +mfpmsr(void) +{ + uint64_t value; + __asm volatile ("mfspr %0, 853" : "=r"(value)); + return value; +} + +static inline void +mtpmcr(uint64_t value) +{ + __asm volatile ("mtspr 884, %0" :: "r"(value)); +} + +static inline uint32_t +mfpir(void) +{ + uint32_t value; + __asm volatile ("mfspr %0, 1023" : "=r"(value)); + return value; +} + +extern int cacheline_size; + +void __syncicache(void *, size_t); + +#endif /* _MACHINE_CPUFUNC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/db_machdep.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/db_machdep.h new file mode 100644 index 0000000000..caf96c25d3 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/db_machdep.h @@ -0,0 +1,86 @@ +/* $OpenBSD: db_machdep.h,v 1.6 2021/08/30 08:11:12 jasper Exp $*/ +/* $NetBSD: db_machdep.h,v 1.13 1996/04/29 20:50:08 leo Exp $ */ + +/* + * Mach Operating System + * Copyright (c) 1992 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +/* + * Machine-dependent defines for new kernel debugger. + */ +#ifndef _MACHINE_DB_MACHDEP_H_ +#define _MACHINE_DB_MACHDEP_H_ + +#include +#include +#include +#include + +typedef long db_expr_t; /* expression - signed */ +typedef struct trapframe db_regs_t; +extern db_regs_t ddb_regs; /* register state */ + +#define PC_REGS(regs) ((regs)->srr0) +#define SET_PC_REGS(regs, value) PC_REGS(regs) = (value) + +#define BKPT_INST 0x7C810808 /* breakpoint instruction */ + +#define BKPT_SIZE (4) /* size of breakpoint inst */ +#define BKPT_SET(inst) (BKPT_INST) + +#define db_clear_single_step(regs) ((regs)->srr1 &= ~PSL_SE) +#define db_set_single_step(regs) ((regs)->srr1 |= PSL_SE) + +#define T_BREAKPOINT 0xffff +#define IS_BREAKPOINT_TRAP(type, code) ((type) == T_BREAKPOINT) +#define IS_WATCHPOINT_TRAP(type, code) 0 + +#define M_RTS 0xfc0007fe +#define I_RTS 0x4c000020 +#define M_BC 0xfc000000 +#define I_BC 0x40000000 +#define M_B 0xfc000000 +#define I_B 0x50000000 +#define M_RFI 0xfc0007fe +#define I_RFI 0x4c000064 + +#define inst_trap_return(ins) (((ins)&M_RFI) == I_RFI) +#define inst_return(ins) (((ins)&M_RTS) == I_RTS) +#define inst_call(ins) (((ins)&M_BC ) == I_BC || \ + ((ins)&M_B ) == I_B ) + +struct trapframe; +void db_ktrap(int, db_regs_t *); + +#define DDB_STATE_NOT_RUNNING 0 +#define DDB_STATE_RUNNING 1 +#define DDB_STATE_EXITING 2 + +/* + * We define some of our own commands + */ +#define DB_MACHINE_COMMANDS + +#endif /* _MACHINE_DB_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/disklabel.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/disklabel.h new file mode 100644 index 0000000000..3d198e06b9 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/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 + * + * 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_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/elf.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/elf.h new file mode 100644 index 0000000000..d1a121fff9 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/elf.h @@ -0,0 +1,66 @@ +/* $OpenBSD: elf.h,v 1.3 2025/02/19 18:25:03 jca Exp $ */ + +/* + * This file is in the public domain. + */ + +#ifndef _MACHINE_ELF_H_ +#define _MACHINE_ELF_H_ + +/* + * CPU Feature Attributes + * + * These are defined in the PowerPC ELF ABI for the AT_HWCAP vector, + * and are exported to userland via the elf_aux_info(3) function. + */ + +#ifdef _KERNEL +# define __HAVE_CPU_HWCAP +# define __HAVE_CPU_HWCAP2 +extern unsigned long hwcap; +extern unsigned long hwcap2; +#endif /* _KERNEL */ + +#define PPC_FEATURE_32 0x80000000 /* Always true */ +#define PPC_FEATURE_64 0x40000000 /* Defined on a 64-bit CPU */ +#define PPC_FEATURE_601_INSTR 0x20000000 +#define PPC_FEATURE_HAS_ALTIVEC 0x10000000 +#define PPC_FEATURE_HAS_FPU 0x08000000 +#define PPC_FEATURE_HAS_MMU 0x04000000 +#define PPC_FEATURE_UNIFIED_CACHE 0x01000000 +#define PPC_FEATURE_HAS_SPE 0x00800000 +#define PPC_FEATURE_HAS_EFP_SINGLE 0x00400000 +#define PPC_FEATURE_HAS_EFP_DOUBLE 0x00200000 +#define PPC_FEATURE_NO_TB 0x00100000 +#define PPC_FEATURE_POWER4 0x00080000 +#define PPC_FEATURE_POWER5 0x00040000 +#define PPC_FEATURE_POWER5_PLUS 0x00020000 +#define PPC_FEATURE_CELL 0x00010000 +#define PPC_FEATURE_BOOKE 0x00008000 +#define PPC_FEATURE_SMT 0x00004000 +#define PPC_FEATURE_ICACHE_SNOOP 0x00002000 +#define PPC_FEATURE_ARCH_2_05 0x00001000 +#define PPC_FEATURE_HAS_DFP 0x00000400 +#define PPC_FEATURE_POWER6_EXT 0x00000200 +#define PPC_FEATURE_ARCH_2_06 0x00000100 +#define PPC_FEATURE_HAS_VSX 0x00000080 +#define PPC_FEATURE_TRUE_LE 0x00000002 +#define PPC_FEATURE_PPC_LE 0x00000001 + +#define PPC_FEATURE2_ARCH_2_07 0x80000000 +#define PPC_FEATURE2_HTM 0x40000000 +#define PPC_FEATURE2_DSCR 0x20000000 +#define PPC_FEATURE2_EBB 0x10000000 +#define PPC_FEATURE2_ISEL 0x08000000 +#define PPC_FEATURE2_TAR 0x04000000 +#define PPC_FEATURE2_HAS_VEC_CRYPTO 0x02000000 +#define PPC_FEATURE2_HTM_NOSC 0x01000000 +#define PPC_FEATURE2_ARCH_3_00 0x00800000 +#define PPC_FEATURE2_HAS_IEEE128 0x00400000 +#define PPC_FEATURE2_DARN 0x00200000 +#define PPC_FEATURE2_SCV 0x00100000 +#define PPC_FEATURE2_HTM_NOSUSPEND 0x00080000 +#define PPC_FEATURE2_ARCH_3_1 0x00040000 +#define PPC_FEATURE2_MMA 0x00020000 + +#endif /* !_MACHINE_ELF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/endian.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/endian.h new file mode 100644 index 0000000000..2a92d0b2fd --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/endian.h @@ -0,0 +1,37 @@ +/* $OpenBSD: endian.h,v 1.3 2024/05/07 14:26:48 naddy 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_ + +#undef _BIG_ENDIAN /* XXX - gcc may define _BIG_ENDIAN too */ +#define _BYTE_ORDER _BIG_ENDIAN + +#ifndef __FROM_SYS__ENDIAN +#include +#endif + +#endif /* _MACHINE_ENDIAN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/exec.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/exec.h new file mode 100644 index 0000000000..219d93c1d0 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/exec.h @@ -0,0 +1,36 @@ +/* $OpenBSD: exec.h,v 1.4 2021/03/11 11:16:59 jsg Exp $ */ + +/* + * Copyright (c) 2014 Patrick Wildt + * + * 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 ELFDATA2MSB +#define ELF_TARG_MACH EM_PPC64 + +/* Processor specific dynamic tag values. */ +#define DT_PPC64_GLINK 0x70000000 +#define DT_PPC64_OPT 0x70000003 + +#define DT_PROCNUM (DT_PPC64_OPT - DT_LOPROC + 1) + +#endif \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/fdt.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/fdt.h new file mode 100644 index 0000000000..0401cf75fb --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/fdt.h @@ -0,0 +1,39 @@ +/* $OpenBSD: fdt.h,v 1.2 2020/10/30 13:07:48 kettenis Exp $ */ +/* + * Copyright (c) 2016 Patrick Wildt + * + * 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_FDT_H_ +#define _MACHINE_FDT_H_ + +#include + +struct fdt_attach_args { + const char *fa_name; + int fa_node; + bus_space_tag_t fa_iot; + bus_dma_tag_t fa_dmat; + struct fdt_reg *fa_reg; + int fa_nreg; + uint32_t *fa_intr; + int fa_nintr; + int fa_acells; + int fa_scells; +}; + +extern int stdout_node; +extern int stdout_speed; + +#endif /* _MACHINE_FDT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/fenv.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/fenv.h new file mode 100644 index 0000000000..aadeaabeee --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/fenv.h @@ -0,0 +1,96 @@ +/* $OpenBSD: fenv.h,v 1.1 2020/06/28 08:19:34 kettenis Exp $ */ + +/* + * Copyright (c) 2011 Martynas Venckus + * + * 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_FENV_H_ +#define _MACHINE_FENV_H_ + +/* + * Each symbol representing a floating point exception expands to an integer + * constant expression with values, such that bitwise-inclusive ORs of _all + * combinations_ of the constants result in distinct values. + * + * We use such values that allow direct bitwise operations on FPU registers. + */ +#define FE_INEXACT 0x02000000 +#define FE_DIVBYZERO 0x04000000 +#define FE_UNDERFLOW 0x08000000 +#define FE_OVERFLOW 0x10000000 +#define FE_INVALID 0x20000000 +#define _FE_INVALID_SOFT 0x00000400 +#define _FE_INVALID_ALL 0x01f80700 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * exception constants defined above. + */ +#define FE_ALL_EXCEPT (FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | \ + FE_OVERFLOW | FE_INVALID) +#define _MASK_SHIFT 22 + +/* + * Each symbol representing the rounding direction, expands to an integer + * constant expression whose value is distinct non-negative value. + * + * We use such values that allow direct bitwise operations on FPU registers. + */ +#define FE_TONEAREST 0x0 +#define FE_TOWARDZERO 0x1 +#define FE_UPWARD 0x2 +#define FE_DOWNWARD 0x3 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * rounding direction constants defined above. + */ +#define _ROUND_MASK (FE_TONEAREST | FE_TOWARDZERO | FE_UPWARD | \ + FE_DOWNWARD) + +/* + * fenv_t represents the entire floating-point environment. + */ +typedef unsigned int fenv_t; + +/* + * The following constant represents the default floating-point environment + * (that is, the one installed at program startup) and has type pointer to + * const-qualified fenv_t. + * + * It can be used as an argument to the functions within the header + * that manage the floating-point environment, namely fesetenv() and + * feupdateenv(). + */ +__BEGIN_DECLS +extern fenv_t __fe_dfl_env; +__END_DECLS +#define FE_DFL_ENV ((const fenv_t *)&__fe_dfl_env) + +/* + * fexcept_t represents the floating-point status flags collectively, including + * any status the implementation associates with the flags. + * + * A floating-point status flag is a system variable whose value is set (but + * never cleared) when a floating-point exception is raised, which occurs as a + * side effect of exceptional floating-point arithmetic to provide auxiliary + * information. + * + * A floating-point control mode is a system variable whose value may be set by + * the user to affect the subsequent behavior of floating-point arithmetic. + */ +typedef unsigned int fexcept_t; + +#endif /* !_MACHINE_FENV_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/fpu.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/fpu.h new file mode 100644 index 0000000000..c9637f3bc5 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/fpu.h @@ -0,0 +1,17 @@ +/* $OpenBSD: fpu.h,v 1.4 2022/03/24 18:42:05 kettenis Exp $ */ + +/* public domain */ + +#ifndef _MACHINE_FPU_H +#define _MACHINE_FPU_H + +#ifdef _KERNEL + +void save_vsx(struct proc *); +void restore_vsx(struct proc *); + +int fpu_sigcode(struct proc *); + +#endif + +#endif /* _MACHINE_FPU_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/frame.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/frame.h new file mode 100644 index 0000000000..afb0dfa295 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/frame.h @@ -0,0 +1,104 @@ +/* $OpenBSD: frame.h,v 1.5 2020/07/13 22:37:37 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 _MACHDEP_FRAME_H +#define _MACHDEP_FRAME_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; + __register_t srr0; + __register_t srr1; + __register_t vrsave; + __register_t dar; /* dar & dsisr are only filled on a DSI trap */ + __register_t dsisr; + __register_t exc; +}; + +/* + * This is to ensure alignment of the stackpointer + */ +#define FRAMELEN roundup(sizeof(struct trapframe) + 32, 16) + +struct callframe { + register_t cf_sp; + register_t cf_cr; + register_t cf_lr; + register_t cf_toc; +}; + +struct sigframe { + int sf_signum; + siginfo_t *sf_sip; + struct sigcontext sf_sc; + siginfo_t sf_si; +}; + +struct switchframe { + register_t sf_sp; + register_t sf_cr; + register_t sf_lr; /* unused */ + register_t sf_toc; /* unused */ + register_t sf_r14; + register_t sf_r15; + register_t sf_r16; + register_t sf_r17; + register_t sf_r18; + register_t sf_r19; + register_t sf_r20; + register_t sf_r21; + register_t sf_r22; + register_t sf_r23; + register_t sf_r24; + register_t sf_r25; + register_t sf_r26; + register_t sf_r27; + register_t sf_r28; + register_t sf_r29; + register_t sf_r30; + register_t sf_r31; +}; + +#endif /* _MACHDEP_FRAME_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/ieee.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/ieee.h new file mode 100644 index 0000000000..3755c7eac5 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/ieee.h @@ -0,0 +1,119 @@ +/* $OpenBSD: ieee.h,v 1.1 2020/06/01 00:13:37 drahn Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)ieee.h 8.1 (Berkeley) 6/11/93 + */ + +/* + * ieee.h defines the machine-dependent layout of the machine's IEEE + * floating point. It does *not* define (yet?) any of the rounding + * mode bits, exceptions, and so forth. + */ + +/* + * Define the number of bits in each fraction and exponent. + * + * k k+1 + * Note that 1.0 x 2 == 0.1 x 2 and that denorms are represented + * + * (-exp_bias+1) + * as fractions that look like 0.fffff x 2 . This means that + * + * -126 + * the number 0.10000 x 2 , for instance, is the same as the normalized + * + * -127 -128 + * float 1.0 x 2 . Thus, to represent 2 , we need one leading zero + * + * -129 + * in the fraction; to represent 2 , we need two, and so on. This + * + * (-exp_bias-fracbits+1) + * implies that the smallest denormalized number is 2 + * + * for whichever format we are talking about: for single precision, for + * + * -126 -149 + * instance, we get .00000000000000000000001 x 2 , or 1.0 x 2 , and + * + * -149 == -127 - 23 + 1. + */ +#define SNG_EXPBITS 8 +#define SNG_FRACBITS 23 + +#define DBL_EXPBITS 11 +#define DBL_FRACHBITS 20 +#define DBL_FRACLBITS 32 +#define DBL_FRACBITS 52 + +struct ieee_single { + u_int sng_sign:1; + u_int sng_exp:8; + u_int sng_frac:23; +}; + +struct ieee_double { + u_int dbl_sign:1; + u_int dbl_exp:11; + u_int dbl_frach:20; + u_int dbl_fracl; +}; + +/* + * Floats whose exponent is in [1..INFNAN) (of whatever type) are + * `normal'. Floats whose exponent is INFNAN are either Inf or NaN. + * Floats whose exponent is zero are either zero (iff all fraction + * bits are zero) or subnormal values. + * + * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its + * high fraction; if the bit is set, it is a `quiet NaN'. + */ +#define SNG_EXP_INFNAN 255 +#define DBL_EXP_INFNAN 2047 + +#if 0 +#define SNG_QUIETNAN (1 << 22) +#define DBL_QUIETNAN (1 << 19) +#endif + +/* + * Exponent biases. + */ +#define SNG_EXP_BIAS 127 +#define DBL_EXP_BIAS 1023 \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/ieeefp.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/ieeefp.h new file mode 100644 index 0000000000..6b37911951 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/ieeefp.h @@ -0,0 +1,25 @@ +/* $OpenBSD: ieeefp.h,v 1.1 2020/06/01 00:13:37 drahn Exp $ */ +/* $NetBSD: ieeefp.h,v 1.2 1999/07/07 01:52:26 danw Exp $ */ +/* + * Written by J.T. Conklin, Apr 6, 1995 + * Public domain. + */ + +#ifndef _POWERPC_IEEEFP_H_ +#define _POWERPC_IEEEFP_H_ + +typedef int fp_except; +#define FP_X_IMP 0x01 /* imprecise (loss of precision) */ +#define FP_X_DZ 0x02 /* divide-by-zero exception */ +#define FP_X_UFL 0x04 /* underflow exception */ +#define FP_X_OFL 0x08 /* overflow exception */ +#define FP_X_INV 0x10 /* invalid operation exception */ + +typedef enum { + FP_RN=0, /* round to nearest representable number */ + FP_RZ=1, /* round to zero (truncate) */ + FP_RP=2, /* round toward positive infinity */ + FP_RM=3 /* round toward negative infinity */ +} fp_rnd; + +#endif /* _POWERPC_IEEEFP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/intr.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/intr.h new file mode 100644 index 0000000000..e6a70160ba --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/intr.h @@ -0,0 +1,135 @@ +/* $OpenBSD: intr.h,v 1.16 2025/04/26 11:10:28 visa Exp $ */ + +/* + * Copyright (c) 2020 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_INTR_H_ +#define _MACHINE_INTR_H_ + +#define __USE_MI_SOFTINTR + +#include +#include + +struct cpu_info; +struct trapframe; + +#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 IPL_TTY +#define IPL_AUDIO 8 +#define IPL_CLOCK 9 +#define IPL_STATCLOCK IPL_CLOCK +#define IPL_SCHED IPL_CLOCK +#define IPL_HIGH IPL_CLOCK +#define IPL_IPI 10 +#define NIPL 11 + +#define IPL_MPFLOOR IPL_TTY +/* Interrupt priority 'flags'. */ +#define IPL_IRQMASK 0xf /* priority only */ +#define IPL_FLAGMASK 0xf00 /* flags only*/ +#define IPL_MPSAFE 0x100 /* 'mpsafe' interrupt, no kernel lock */ + +int splraise(int); +int spllower(int); +void splx(int); + +void softintr(int); + +#define spl0() spllower(IPL_NONE) +#define splsoftclock() splraise(IPL_SOFTCLOCK) +#define splsoftnet() splraise(IPL_SOFTNET) +#define splsofttty() splraise(IPL_SOFTTTY) +#define splbio() splraise(IPL_BIO) +#define splnet() splraise(IPL_NET) +#define spltty() splraise(IPL_TTY) +#define splvm() splraise(IPL_VM) +#define splclock() splraise(IPL_CLOCK) +#define splstatclock() splraise(IPL_STATCLOCK) +#define splsched() splraise(IPL_SCHED) +#define splhigh() splraise(IPL_HIGH) + +#ifdef DIAGNOSTIC +/* + * Although this function is implemented in MI code, it must be in this MD + * header because we don't want this header to include MI includes. + */ +void splassert_fail(int, int, const char *); +extern int splassert_ctl; +void splassert_check(int, const char *); +#define splassert(__wantipl) do { \ + if (splassert_ctl > 0) { \ + splassert_check(__wantipl, __func__); \ + } \ +} while (0) +#define splsoftassert(wantipl) splassert(wantipl) +#else +#define splassert(wantipl) do { /* nothing */ } while (0) +#define splsoftassert(wantipl) do { /* nothing */ } while (0) +#endif + +void intr_init(void); + +#define intr_barrier(x) + +#define IST_EDGE 0 +#define IST_LEVEL 1 + +void *intr_establish(uint32_t, int, int, struct cpu_info *, + int (*)(void *), void *, const char *); + +#define IPI_NOP 0 +#define IPI_DDB (1 << 0) +#define IPI_SETPERF (1 << 1) + +void intr_send_ipi(struct cpu_info *, int); + +extern void (*_exi)(struct trapframe *); +extern void (*_hvi)(struct trapframe *); +extern void *(*_intr_establish)(uint32_t, int, int, struct cpu_info *, + int (*)(void *), void *, const char *); +extern void (*_intr_send_ipi)(void *); +extern void (*_setipl)(int); + +struct interrupt_controller { + int ic_node; + void *ic_cookie; + void *(*ic_establish)(void *, int *, int, struct cpu_info *, + int (*)(void *), void *, char *); + void (*ic_send_ipi)(void *); + + LIST_ENTRY(interrupt_controller) ic_list; + uint32_t ic_phandle; + uint32_t ic_cells; +}; + +void interrupt_controller_register(struct interrupt_controller *); + +void *fdt_intr_establish_idx_cpu(int, int, int, struct cpu_info *, + int (*)(void *), void *, char *); +void *fdt_intr_establish_imap(int, int *, int, int, int (*)(void *), + void *, char *); +void *fdt_intr_establish_imap_cpu(int, int *, int, int, + struct cpu_info *, int (*)(void *), void *, char *); +void fdt_intr_disestablish(void *); + +#endif /* _MACHINE_INTR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/kcore.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/kcore.h new file mode 100644 index 0000000000..c94e37366e --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/kcore.h @@ -0,0 +1 @@ +/* Empty */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/kexec.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/kexec.h new file mode 100644 index 0000000000..e909bfcc3e --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/kexec.h @@ -0,0 +1,36 @@ +/* $OpenBSD: kexec.h,v 1.3 2020/07/18 10:23:44 kettenis Exp $ */ + +/* + * Copyright (c) 2019-2020 Visa Hankala + * + * Permission to use, copy, modify, and/or 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_KEXEC_H_ +#define _MACHINE_KEXEC_H_ + +#include + +#define KEXEC_MAX_ARGS 8 /* maximum number of boot arguments */ + +struct kexec_args { + char *kimg; /* kernel image buffer */ + size_t klen; /* size of kernel image */ + int boothowto; + u_char bootduid[8]; +}; + +#define KIOC_KEXEC _IOW('K', 1, struct kexec_args) +#define KIOC_GETBOOTDUID _IOR('K', 2, u_char[8]) + +#endif /* _MACHINE_KEXEC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/limits.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/limits.h new file mode 100644 index 0000000000..d2c0f2eaf3 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/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 + +#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_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/mplock.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/mplock.h new file mode 100644 index 0000000000..1856d8925a --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/mplock.h @@ -0,0 +1,10 @@ +/* $OpenBSD: mplock.h,v 1.1 2020/07/22 11:08:01 kettenis Exp $ */ + +/* public domain */ + +#ifndef _MACHINE_MPLOCK_H_ +#define _MACHINE_MPLOCK_H_ + +#define __USE_MI_MPLOCK + +#endif /* !_MACHINE_MPLOCK_H */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/mutex.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/mutex.h new file mode 100644 index 0000000000..9f22aee173 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/mutex.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mutex.h,v 1.1 2020/05/16 17:11:14 kettenis Exp $ */ + +#define __USE_MI_MUTEX \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/opal.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/opal.h new file mode 100644 index 0000000000..98106675bb --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/opal.h @@ -0,0 +1,238 @@ +/* $OpenBSD: opal.h,v 1.19 2021/01/23 12:10:08 kettenis Exp $ */ + +/* + * Copyright (c) 2020 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_OPAL_H_ +#define _MACHINE_OPAL_H_ + +/* Tokens. */ +#define OPAL_TEST 0 +#define OPAL_CONSOLE_WRITE 1 +#define OPAL_CONSOLE_READ 2 +#define OPAL_RTC_READ 3 +#define OPAL_RTC_WRITE 4 +#define OPAL_CEC_POWER_DOWN 5 +#define OPAL_CEC_REBOOT 6 +#define OPAL_HANDLE_INTERRUPT 9 +#define OPAL_POLL_EVENTS 10 +#define OPAL_PCI_CONFIG_READ_WORD 15 +#define OPAL_PCI_CONFIG_WRITE_WORD 18 +#define OPAL_SET_XIVE 19 +#define OPAL_GET_XIVE 20 +#define OPAL_PCI_EEH_FREEZE_STATUS 23 +#define OPAL_PCI_EEH_FREEZE_CLEAR 26 +#define OPAL_PCI_PHB_MMIO_ENABLE 27 +#define OPAL_PCI_SET_PHB_MEM_WINDOW 28 +#define OPAL_PCI_MAP_PE_MMIO_WINDOW 29 +#define OPAL_PCI_SET_PE 31 +#define OPAL_PCI_SET_XIVE_PE 37 +#define OPAL_GET_MSI_32 39 +#define OPAL_GET_MSI_64 40 +#define OPAL_START_CPU 41 +#define OPAL_PCI_MAP_PE_DMA_WINDOW 44 +#define OPAL_PCI_MAP_PE_DMA_WINDOW_REAL 45 +#define OPAL_PCI_RESET 49 +#define OPAL_REINIT_CPUS 70 +#define OPAL_CHECK_TOKEN 80 +#define OPAL_SENSOR_READ 88 +#define OPAL_IPMI_SEND 107 +#define OPAL_IPMI_RECV 108 +#define OPAL_CONSOLE_FLUSH 117 +#define OPAL_XIVE_RESET 128 +#define OPAL_XIVE_GET_IRQ_INFO 129 +#define OPAL_XIVE_GET_IRQ_CONFIG 131 +#define OPAL_XIVE_SET_IRQ_CONFIG 131 +#define OPAL_XIVE_GET_QUEUE_INFO 132 +#define OPAL_XIVE_SET_QUEUE_INFO 133 +#define OPAL_XIVE_GET_VP_INFO 137 +#define OPAL_XIVE_SET_VP_INFO 138 +#define OPAL_XIVE_DUMP 142 +#define OPAL_SENSOR_READ_U64 162 + +/* Return codes. */ +#define OPAL_SUCCESS 0 +#define OPAL_PARAMETER -1 +#define OPAL_BUSY -2 +#define OPAL_PARTIAL -3 +#define OPAL_CONSTRAINED -4 +#define OPAL_CLOSED -5 +#define OPAL_HARDWARE -6 +#define OPAL_UNSUPPORTED -7 +#define OPAL_PERMISSION -8 +#define OPAL_NO_MEM -9 +#define OPAL_RESOURCE -10 +#define OPAL_INTERNAL_ERROR -11 +#define OPAL_BUSY_EVENT -12 +#define OPAL_HARDWARE_FROZEN -13 +#define OPAL_WRONG_STATE -14 +#define OPAL_ASYNC_COMPLETION -15 +#define OPAL_EMPTY -16 + +/* OPAL_POLL_EVENT */ +#define OPAL_EVENT_CONSOLE_OUTPUT 0x00000008 +#define OPAL_EVENT_CONSOLE_INPUT 0x00000010 + +/* OPAL_PCI_EEH_FREEZE_CLEAR */ +#define OPAL_EEH_ACTION_CLEAR_FREEZE_MMIO 1 +#define OPAL_EEH_ACTION_CLEAR_FREEZE_DMA 2 +#define OPAL_EEH_ACTION_CLEAR_FREEZE_ALL 3 + +/* OPAL_PCI_PHB_MMIO_ENABLE */ +#define OPAL_M32_WINDOW_TYPE 1 +#define OPAL_M64_WINDOW_TYPE 2 +#define OPAL_IO_WINDOW_TYPE 3 +#define OPAL_DISABLE_M64 0 +#define OPAL_ENABLE_M64_SPLIT 1 +#define OPAL_ENABLE_M64_NON_SPLIT 2 + +/* OPAL_PCIE_SET_PE */ +#define OPAL_IGNORE_RID_BUS_NUMBER 0 +#define OPAL_IGNORE_RID_DEVICE_NUMBER 0 +#define OPAL_COMPARE_RID_DEVICE_NUMBER 1 +#define OPAL_IGNORE_RID_FUNCTION_NUMBER 0 +#define OPAL_COMPARE_RID_FUNCTION_NUMBER 1 +#define OPAL_UNMAP_PE 0 +#define OPAL_MAP_PE 1 + +/* OPAL_PCI_RESET */ +#define OPAL_RESET_PHB_COMPLETE 1 +#define OPAL_RESET_PCI_LINK 2 +#define OPAL_RESET_PHB_ERROR 3 +#define OPAL_RESET_PCI_HOT 4 +#define OPAL_RESET_PCI_FUNDAMENTAL 5 +#define OPAL_RESET_PCI_IODA_TABLE 6 +#define OPAL_DEASSERT_RESET 0 +#define OPAL_ASSERT_RESET 1 + +/* OPAL_REINIT_CPUS */ +#define OPAL_REINIT_CPUS_HILE_BE 0x00000001 +#define OPAL_REINIT_CPUS_HILE_LE 0x00000002 +#define OPAL_REINIT_CPUS_MMU_HASH 0x00000004 +#define OPAL_REINIT_CPUS_MMU_RADIX 0x00000008 +#define OPAL_REINIT_CPUS_TM_SUSPEND_DISABLED 0x00000010 + +/* OPAL_CHECK_TOKEN */ +#define OPAL_TOKEN_ABSENT 0 +#define OPAL_TOKEN_PRESENT 1 + +/* OPAL_IPMI_SEND/RECV */ +#define OPAL_IPMI_MSG_FORMAT_VERSION_1 1 + +#ifndef _LOCORE +struct opal_ipmi_msg { + uint8_t version; + uint8_t netfn; + uint8_t cmd; + uint8_t data[0]; +}; +#endif + +/* OPAL_XIVE_RESET */ +#define OPAL_XIVE_MODE_EMU 0 +#define OPAL_XIVE_MODE_EXPL 1 + +/* OPAL_XIVE_GET_IRQ_INFO */ +#define OPAL_XIVE_IRQ_TRIGGER_PAGE 0x00000001 +#define OPAL_XIVE_IRQ_STORE_EOI 0x00000002 +#define OPAL_XIVE_IRQ_LSI 0x00000004 +#define OPAL_XIVE_IRQ_SHIFT_BUG 0x00000008 +#define OPAL_XIVE_IRQ_MASK_VIA_FW 0x00000010 +#define OPAL_XIVE_IRQ_EOI_VIA_FW 0x00000020 + +/* OPAL_XIVE_GET_QUEUE_INFO */ +#define OPAL_XIVE_EQ_ENABLED 0x00000001 +#define OPAL_XIVE_EQ_ALWAYS_NOTIFY 0x00000002 +#define OPAL_XIVE_EQ_ESCALATE 0x00000004 + +/* OPAL_XIVE_GET_VP_INFO */ +#define OPAL_XIVE_VP_ENABLED 0x00000001 +#define OPAL_XIVE_VP_SINGLE_ESCALATION 0x00000002 + +/* OPAL_XIVE_DUMP */ +#define XIVE_DUMP_TM_HYP 0x00000000 +#define XIVE_DUMP_TM_POOL 0x00000001 +#define XIVE_DUMP_TM_OS 0x00000002 +#define XIVE_DUMP_TM_USER 0x00000003 +#define XIVE_DUMP_VP 0x00000004 +#define XIVE_DUMP_EMU_STATE 0x00000005 + +#ifndef _LOCORE + +void *opal_phys(void *); + +int64_t opal_test(uint64_t); +int64_t opal_console_write(int64_t, int64_t *, const uint8_t *); +int64_t opal_console_read(int64_t, int64_t *, uint8_t *); +int64_t opal_rtc_read(uint32_t *, uint64_t *); +int64_t opal_rtc_write(uint32_t, uint64_t); +int64_t opal_cec_power_down(uint64_t); +int64_t opal_cec_reboot(void); +int64_t opal_handle_interrupt(uint32_t, uint64_t *); +int64_t opal_poll_events(uint64_t *); +int64_t opal_pci_config_read_word(uint64_t, uint64_t, uint64_t, uint32_t *); +int64_t opal_pci_config_write_word(uint64_t, uint64_t, uint64_t, uint32_t); +int64_t opal_set_xive(uint32_t, uint16_t, uint8_t); +int64_t opal_get_xive(uint32_t, uint16_t *, uint8_t *); +int64_t opal_pci_eeh_freeze_status(uint64_t, uint64_t, uint8_t *, + uint16_t *, uint64_t *); +int64_t opal_pci_eeh_freeze_clear(uint64_t, uint64_t, uint64_t); +int64_t opal_pci_phb_mmio_enable(uint64_t, uint16_t, uint16_t, uint16_t); +int64_t opal_pci_set_phb_mem_window(uint64_t, uint16_t, uint16_t, + uint64_t, uint64_t, uint64_t); +int64_t opal_pci_map_pe_mmio_window(uint64_t, uint64_t, uint16_t, + uint16_t, uint16_t); +int64_t opal_pci_set_pe(uint64_t, uint64_t, uint64_t, uint8_t, uint8_t, + uint8_t, uint8_t); +int64_t opal_pci_set_xive_pe(uint64_t, uint64_t, uint32_t); +int64_t opal_get_msi_32(uint64_t, uint32_t, uint32_t, uint8_t, + uint32_t *, uint32_t *); +int64_t opal_get_msi_64(uint64_t, uint32_t, uint32_t, uint8_t, + uint64_t *, uint32_t *); +int64_t opal_start_cpu(uint64_t, uint64_t); +int64_t opal_pci_map_pe_dma_window(uint64_t, uint64_t, uint16_t, uint16_t, + uint64_t, uint64_t, uint64_t); +int64_t opal_pci_map_pe_dma_window_real(uint64_t, uint64_t, uint16_t, + uint64_t, uint64_t); +int64_t opal_pci_reset(uint64_t, uint8_t, uint8_t); +int64_t opal_reinit_cpus(uint64_t); +int64_t opal_check_token(uint64_t); +int64_t opal_sensor_read(uint32_t, int, uint32_t *); +int64_t opal_ipmi_send(uint64_t, struct opal_ipmi_msg *, uint64_t); +int64_t opal_ipmi_recv(uint64_t, struct opal_ipmi_msg *, uint64_t *); +int64_t opal_console_flush(uint64_t); +int64_t opal_xive_reset(uint64_t); +int64_t opal_xive_get_irq_info(uint32_t, uint64_t *, uint64_t *, + uint64_t *, uint32_t *, uint32_t *); +int64_t opal_xive_get_irq_config(uint32_t, uint64_t *, uint8_t *, uint32_t *); +int64_t opal_xive_set_irq_config(uint32_t, uint64_t, uint8_t, uint32_t); +int64_t opal_xive_get_queue_info(uint64_t, uint8_t, uint64_t *, + uint64_t *, uint64_t *, uint32_t *, uint64_t *); +int64_t opal_xive_set_queue_info(uint64_t, uint8_t, uint64_t, + uint64_t, uint64_t); +int64_t opal_xive_get_vp_info(uint64_t, uint64_t *, uint64_t *, + uint64_t *, uint32_t *); +int64_t opal_xive_set_vp_info(uint64_t, uint64_t, uint64_t); +int64_t opal_xive_dump(uint32_t, uint32_t); +int64_t opal_sensor_read_u64(uint32_t, int, uint64_t *); + +void opal_printf(const char *fmt, ...); + +void *opal_intr_establish(uint64_t, int, int (*)(void *), void *); + +#endif + +#endif /* _MACHINE_OPAL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/openpromio.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/openpromio.h new file mode 100644 index 0000000000..e4f9fce47b --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/openpromio.h @@ -0,0 +1,57 @@ +/* $OpenBSD: openpromio.h,v 1.1 2020/06/27 21:39:05 kettenis Exp $ */ +/* $NetBSD: openpromio.h,v 1.1.1.1 1998/06/20 04:58:52 eeh Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)openpromio.h 8.1 (Berkeley) 6/11/93 + */ + +struct opiocdesc { + int op_nodeid; /* passed or returned node id */ + int op_namelen; /* length of op_name */ + char *op_name; /* pointer to field name */ + int op_buflen; /* length of op_buf (value-result) */ + char *op_buf; /* pointer to field value */ +}; + +#define OPIOCGET _IOWR('O', 1, struct opiocdesc) /* get openprom field */ +#define OPIOCSET _IOW('O', 2, struct opiocdesc) /* set openprom field */ +#define OPIOCNEXTPROP _IOWR('O', 3, struct opiocdesc) /* get next property */ +#define OPIOCGETOPTNODE _IOR('O', 4, int) /* get openprom field */ +#define OPIOCGETNEXT _IOWR('O', 5, int) /* get next node of node */ +#define OPIOCGETCHILD _IOWR('O', 6, int) /* get first child of node */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/param.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/param.h new file mode 100644 index 0000000000..00b5dc2057 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/param.h @@ -0,0 +1,80 @@ +/* $OpenBSD: param.h,v 1.3 2025/07/07 18:33:37 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 +#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 6 /* pages of u-area */ +#define USPACE (UPAGES * PAGE_SIZE) /* total size of u-area */ +#define USPACE_ALIGN 0 /* u-area alignment 0-none */ +#define __HAVE_USPACE_GUARD + +#define NMBCLUSTERS (64 * 1024) /* max cluster allocation */ + +#ifndef MSGBUFSIZE +#define MSGBUFSIZE (16 * PAGE_SIZE) /* default message buffer size */ +#endif + +#define STACKALIGNBYTES (32 - 1) +#define STACKALIGN(p) ((u_long)(p) &~ STACKALIGNBYTES) + +#define __HAVE_FDT + +#endif /* _KERNEL */ + +#endif /* _MACHINE_PARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/pcb.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/pcb.h new file mode 100644 index 0000000000..58948188ec --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/pcb.h @@ -0,0 +1,37 @@ +/* $OpenBSD: pcb.h,v 1.8 2021/01/09 13:14:02 kettenis Exp $ */ + +/* + * Copyright (c) 2020 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_PCB_H_ +#define _MACHINE_PCB_H_ + +#include +#include + +struct pcb { + register_t pcb_sp; + u_int pcb_flags; +#define PCB_FPU 0x000000001 +#define PCB_VEC 0x000000002 +#define PCB_VSX 0x000000004 + struct slb pcb_slb[32]; + vaddr_t pcb_onfault; + vaddr_t pcb_userva; + struct fpreg pcb_fpstate; +}; + +#endif /* _MACHINE_PCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/pci_machdep.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/pci_machdep.h new file mode 100644 index 0000000000..0f0168282f --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/pci_machdep.h @@ -0,0 +1,134 @@ +/* $OpenBSD: pci_machdep.h,v 1.6 2024/05/22 05:51:49 jsg Exp $ */ + +/* + * Copyright (c) 2003-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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. + * + */ + +typedef struct ppc64_pci_chipset *pci_chipset_tag_t; +typedef uint64_t pcitag_t; + +#define PCITAG_NODE(x) ((x) >> 32) +#define PCITAG_OFFSET(x) ((x) & 0xffffffff) + +/* Supported interrupt types. */ +#define PCI_NONE 0 +#define PCI_INTX 1 +#define PCI_MSI32 2 +#define PCI_MSI64 3 +#define PCI_MSIX 4 + +typedef struct { + pci_chipset_tag_t ih_pc; + pcitag_t ih_tag; + int ih_intrpin; + int ih_type; +} pci_intr_handle_t; + +struct pci_attach_args; + +/* + * powerpc64-specific PCI structure and type definitions. + * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE. + */ +struct ppc64_pci_chipset { + void *pc_conf_v; + void (*pc_attach_hook)(struct device *, + struct device *, struct pcibus_attach_args *); + int (*pc_bus_maxdevs)(void *, int); + pcitag_t (*pc_make_tag)(void *, int, int, int); + void (*pc_decompose_tag)(void *, pcitag_t, int *, + int *, int *); + int (*pc_conf_size)(void *, pcitag_t); + pcireg_t (*pc_conf_read)(void *, pcitag_t, int); + void (*pc_conf_write)(void *, pcitag_t, int, pcireg_t); + + void *pc_intr_v; + int (*pc_intr_map)(struct pci_attach_args *, + pci_intr_handle_t *); + int (*pc_intr_map_msi)(struct pci_attach_args *, + pci_intr_handle_t *); + int (*pc_intr_map_msix)(struct pci_attach_args *, + int, pci_intr_handle_t *); + const char *(*pc_intr_string)(void *, pci_intr_handle_t); + void *(*pc_intr_establish)(void *, pci_intr_handle_t, + int, struct cpu_info *, int (*)(void *), void *, + char *); + void (*pc_intr_disestablish)(void *, void *); +}; + +/* + * Functions provided to machine-independent PCI code. + */ +#define pci_attach_hook(p, s, pba) \ + (*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba)) +#define pci_bus_maxdevs(c, b) \ + (*(c)->pc_bus_maxdevs)((c)->pc_conf_v, (b)) +#define pci_make_tag(c, b, d, f) \ + (*(c)->pc_make_tag)((c)->pc_conf_v, (b), (d), (f)) +#define pci_decompose_tag(c, t, bp, dp, fp) \ + (*(c)->pc_decompose_tag)((c)->pc_conf_v, (t), (bp), (dp), (fp)) +#define pci_conf_size(c, t) \ + (*(c)->pc_conf_size)((c)->pc_conf_v, (t)) +#define pci_conf_read(c, t, r) \ + (*(c)->pc_conf_read)((c)->pc_conf_v, (t), (r)) +#define pci_conf_write(c, t, r, v) \ + (*(c)->pc_conf_write)((c)->pc_conf_v, (t), (r), (v)) +#define pci_intr_map(c, ihp) \ + (*(c)->pa_pc->pc_intr_map)((c), (ihp)) +#define pci_intr_map_msi(c, ihp) \ + (*(c)->pa_pc->pc_intr_map_msi)((c), (ihp)) +#define pci_intr_map_msix(c, vec, ihp) \ + (*(c)->pa_pc->pc_intr_map_msix)((c), (vec), (ihp)) +#define pci_intr_string(c, ih) \ + (*(c)->pc_intr_string)((c)->pc_intr_v, (ih)) +#define pci_intr_establish(c, ih, l, h, a, nm) \ + (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), NULL, (h), (a),\ + (nm)) +#define pci_intr_establish_cpu(c, ih, l, ci, h, a, nm) \ + (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), (ci), (h), (a),\ + (nm)) +#define pci_intr_disestablish(c, iv) \ + (*(c)->pc_intr_disestablish)((c)->pc_intr_v, (iv)) +#define pci_probe_device_hook(c, a) (0) + +#define pci_min_powerstate(c, t) (PCI_PMCSR_STATE_D3) +#define pci_set_powerstate_md(c, t, s, p) + +#define pci_dev_postattach(a, b) + +void pci_mcfg_init(bus_space_tag_t, bus_addr_t, int, int, int); + +void pci_msi_enable(pci_chipset_tag_t, pcitag_t, bus_addr_t, uint32_t); +void pci_msix_enable(pci_chipset_tag_t, pcitag_t, bus_space_tag_t, + int, bus_addr_t, uint32_t); +int _pci_intr_map_msi(struct pci_attach_args *, pci_intr_handle_t *); +int _pci_intr_map_msix(struct pci_attach_args *, int, pci_intr_handle_t *); + +#define __HAVE_PCI_MSIX + +int pci_msix_table_map(pci_chipset_tag_t, pcitag_t, + bus_space_tag_t, bus_space_handle_t *); +void pci_msix_table_unmap(pci_chipset_tag_t, pcitag_t, + bus_space_tag_t, bus_space_handle_t); \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/pmap.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/pmap.h new file mode 100644 index 0000000000..661c2cf34d --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/pmap.h @@ -0,0 +1,98 @@ +/* $OpenBSD: pmap.h,v 1.19 2023/12/11 22:12:53 kettenis Exp $ */ + +/* + * Copyright (c) 2020 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_PMAP_H_ +#define _MACHINE_PMAP_H_ + +#include +#include + +#ifdef _KERNEL + +#include + +/* V->P mapping data */ +#define VP_IDX1_CNT 256 +#define VP_IDX1_MASK (VP_IDX1_CNT - 1) +#define VP_IDX1_POS 20 +#define VP_IDX2_CNT 256 +#define VP_IDX2_MASK (VP_IDX2_CNT - 1) +#define VP_IDX2_POS 12 + +struct pmap { + LIST_HEAD(,slb_desc) pm_slbd; + int pm_refs; + struct pmap_statistics pm_stats; + struct mutex pm_mtx; +}; + +typedef struct pmap *pmap_t; + +#define PG_PMAP_MOD PG_PMAP0 +#define PG_PMAP_REF PG_PMAP1 +#define PG_PMAP_EXE PG_PMAP2 +#define PG_PMAP_UC PG_PMAP3 + +#define PMAP_CACHE_DEFAULT 0 +#define PMAP_CACHE_CI 1 /* cache inhibit */ +#define PMAP_CACHE_WB 3 /* write-back cached */ + +/* + * MD flags that we use for pmap_enter (in the pa): + */ +#define PMAP_PA_MASK ~((paddr_t)PAGE_MASK) /* to remove the flags */ +#define PMAP_NOCACHE 0x1 /* map uncached */ + +extern struct pmap kernel_pmap_store; + +#define pmap_kernel() (&kernel_pmap_store) +#define pmap_resident_count(pm) ((pm)->pm_stats.resident_count) +#define pmap_wired_count(pm) ((pm)->pm_stats.wired_count) + +#define pmap_init_percpu() do { /* nothing */ } while (0) +#define pmap_unuse_final(p) +#define pmap_remove_holes(vm) +#define pmap_update(pm) + +void pmap_bootstrap(void); +void pmap_bootstrap_cpu(void); + +int pmap_slbd_fault(pmap_t, vaddr_t); +int pmap_slbd_enter(pmap_t, vaddr_t); +int pmap_set_user_slb(pmap_t, vaddr_t, vaddr_t *, vsize_t *); +void pmap_clear_user_slb(void); +void pmap_unset_user_slb(void); + +#ifdef DDB +struct pte; +struct pte *pmap_get_kernel_pte(vaddr_t); +#endif + +#endif /* _KERNEL */ + +struct vm_page_md { + struct mutex pv_mtx; + LIST_HEAD(,pte_desc) pv_list; +}; + +#define VM_MDPAGE_INIT(pg) do { \ + mtx_init(&(pg)->mdpage.pv_mtx, IPL_VM); \ + LIST_INIT(&((pg)->mdpage.pv_list)); \ +} while (0) + +#endif /* _MACHINE_PMAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/proc.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/proc.h new file mode 100644 index 0000000000..da21008f74 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/proc.h @@ -0,0 +1,46 @@ +/* $OpenBSD: proc.h,v 1.3 2020/06/22 16:58:20 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 { + struct trapframe *md_regs; + volatile int md_astpending; + paddr_t md_user_slb_pa; +}; + +#endif /* _MACHINE_PROC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/profile.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/profile.h new file mode 100644 index 0000000000..a27eeba08c --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/profile.h @@ -0,0 +1,70 @@ +/* $OpenBSD: profile.h,v 1.1 2020/06/25 01:55:14 drahn Exp $ */ + +/* + * Copyright (c) 2020 Dale Rahn drahn@openbsd.org + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * mcount frame size skips over the red zone (288B) (calling function may use) + * and 128 bytes of local storage (32 bytes of reserved and 96 of our storage + * this function assumes it will only every call the local __mcount function + */ +#define MCOUNT \ +__asm__(" \n"\ + " .section \".text\" \n"\ + " .p2align 2 \n"\ + " .globl _mcount \n"\ + " .local __mcount \n"\ + " .type _mcount,@function \n"\ + "_mcount: \n"\ + ".L_mcount_gep0: \n"\ + " addis %r2, %r12, .TOC.-.L_mcount_gep0@ha; \n"\ + " addi %r2, %r2, .TOC.-.L_mcount_gep0@l; \n"\ + ".L_mcount_lep0: \n"\ + ".localentry _mcount, .L_mcount_lep0-.L_mcount_gep0; \n"\ + " ld %r11,16(%r1) \n"\ + " mflr %r0 \n"\ + " std %r0, 16(%r1) \n"\ + " stdu %r1,-(288+128)(%r1) \n"\ + " std %r3, 32(%r1) \n"\ + " std %r4, 40(%r1) \n"\ + " std %r5, 48(%r1) \n"\ + " std %r6, 56(%r1) \n"\ + " std %r7, 64(%r1) \n"\ + " std %r8, 72(%r1) \n"\ + " std %r9, 80(%r1) \n"\ + " std %r10,88(%r1) \n"\ + " std %r11,96(%r1) \n"\ + " mr %r4, %r0 \n"\ + " mr %r3, %r11 \n"\ + " bl __mcount \n"\ + " nop \n"\ + " ld %r3, 32(%r1) \n"\ + " ld %r4, 40(%r1) \n"\ + " ld %r5, 48(%r1) \n"\ + " ld %r6, 56(%r1) \n"\ + " ld %r7, 64(%r1) \n"\ + " ld %r8, 72(%r1) \n"\ + " ld %r9, 80(%r1) \n"\ + " ld %r10,88(%r1) \n"\ + " ld %r11,96(%r1) \n"\ + " addi %r1, %r1, (288+128) \n"\ + " ld %r0, 16(%r1) \n"\ + " std %r11,16(%r1) \n"\ + " mtlr %r0 \n"\ + " blr \n"\ + " .size _mcount, .-_mcount \n"\ + ); +#define _MCOUNT_DECL static void __mcount \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/psl.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/psl.h new file mode 100644 index 0000000000..13f2e488a5 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/psl.h @@ -0,0 +1,88 @@ +/* $OpenBSD: psl.h,v 1.3 2021/01/09 13:14:02 kettenis Exp $ */ + +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * 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. + * + * $NetBSD: psl.h,v 1.5 2000/11/19 19:52:37 matt Exp $ + */ + +#ifndef _MACHINE_PSL_H_ +#define _MACHINE_PSL_H_ + +/* + * Machine State Register (MSR) - All cores + */ +#define PSL_VEC 0x02000000UL /* AltiVec/SPE vector unit available */ +#define PSL_VSX 0x00800000UL /* Vector-Scalar unit available */ +#define PSL_EE 0x00008000UL /* external interrupt enable */ +#define PSL_PR 0x00004000UL /* privilege mode (1 == user) */ +#define PSL_FP 0x00002000UL /* floating point enable */ +#define PSL_ME 0x00001000UL /* machine check enable */ +#define PSL_FE0 0x00000800UL /* floating point interrupt mode 0 */ +#define PSL_FE1 0x00000100UL /* floating point interrupt mode 1 */ +#define PSL_PMM 0x00000004UL /* performance monitor mark */ +#define PSL_RI 0x00000002UL /* recoverable interrupt */ + +#define PSL_GS 0x10000000UL /* Guest state */ +#define PSL_UCLE 0x04000000UL /* User mode cache lock enable */ +#define PSL_WE 0x00040000UL /* Wait state enable */ +#define PSL_CE 0x00020000UL /* Critical interrupt enable */ +#define PSL_UBLE 0x00000400UL /* BTB lock enable - e500 only */ +#define PSL_DWE 0x00000400UL /* Debug Wait Enable - 440 only*/ +#define PSL_DE 0x00000200UL /* Debug interrupt enable */ +#define PSL_IS 0x00000020UL /* Instruction address space */ +#define PSL_DS 0x00000010UL /* Data address space */ + +#define PSL_SF 0x8000000000000000UL /* 64-bit addressing */ +#define PSL_HV 0x1000000000000000UL /* hyper-privileged mode */ + +#define PSL_POW 0x00040000UL /* power management */ +#define PSL_ILE 0x00010000UL /* interrupt endian mode (1 == le) */ +#define PSL_SE 0x00000400UL /* single-step trace enable */ +#define PSL_BE 0x00000200UL /* branch trace enable */ +#define PSL_IP 0x00000040UL /* interrupt prefix - 601 only */ +#define PSL_IR 0x00000020UL /* instruction address relocation */ +#define PSL_DR 0x00000010UL /* data address relocation */ +#define PSL_LE 0x00000001UL /* endian mode (1 == le) */ + +/* + * Floating-point exception modes: + */ +#define PSL_FE_DIS 0 /* none */ +#define PSL_FE_NONREC PSL_FE1 /* imprecise non-recoverable */ +#define PSL_FE_REC PSL_FE0 /* imprecise recoverable */ +#define PSL_FE_PREC (PSL_FE0 | PSL_FE1) /* precise */ +#define PSL_FE_DFLT PSL_FE_DIS /* default == none */ + +#define PSL_FPU (PSL_FP | PSL_FE_PREC) + +#endif /* _MACHINE_PSL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/pte.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/pte.h new file mode 100644 index 0000000000..b3e199c635 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/pte.h @@ -0,0 +1,80 @@ +/* $OpenBSD: pte.h,v 1.8 2023/01/25 09:53:53 kettenis Exp $ */ + +/* + * Copyright (c) 2020 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_PTE_H_ +#define _MACHINE_PTE_H_ + +/* + * Page Table Entry bits that should work for all 64-bit POWER CPUs as + * well as the PowerPC 970. + */ + +struct pte { + uint64_t pte_hi; + uint64_t pte_lo; +}; + +/* High doubleword: */ +#define PTE_VALID 0x0000000000000001ULL +#define PTE_HID 0x0000000000000002ULL +#define PTE_WIRED 0x0000000000000008ULL /* SW */ +#define PTE_AVPN 0x3fffffffffffff80ULL +#define PTE_VSID_SHIFT 12 + +/* Low doubleword: */ +#define PTE_PP 0x0000000000000003ULL +#define PTE_RO 0x0000000000000003ULL +#define PTE_RW 0x0000000000000002ULL +#define PTE_N 0x0000000000000004ULL +#define PTE_G 0x0000000000000008ULL +#define PTE_M 0x0000000000000010ULL +#define PTE_I 0x0000000000000020ULL +#define PTE_W 0x0000000000000040ULL +#define PTE_CHG 0x0000000000000080ULL +#define PTE_REF 0x0000000000000100ULL +#define PTE_AC 0x0000000000000200ULL +#define PTE_RPGN 0x0ffffffffffff000ULL + +#define ADDR_PIDX 0x000000000ffff000ULL +#define ADDR_PIDX_SHIFT 12 +#define ADDR_ESID_SHIFT 28 +#define ADDR_VSID_SHIFT 28 + +struct pate { + uint64_t pate_htab; + uint64_t pate_prt; +}; + +#define SLBE_ESID_SHIFT 28 +#define SLBE_VALID 0x0000000008000000UL + +#define SLBV_VSID_SHIFT 12 + +struct slb { + uint64_t slb_slbe; + uint64_t slb_slbv; +}; + +#define VSID_VRMA 0x1ffffff + +#define USER_ADDR 0xcfffffff00000000ULL +#define USER_ESID (USER_ADDR >> ADDR_ESID_SHIFT) +#define SEGMENT_SIZE (256 * 1024 * 1024ULL) +#define SEGMENT_MASK (SEGMENT_SIZE - 1) + +#endif /* _MACHINE_PTE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/ptrace.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/ptrace.h new file mode 100644 index 0000000000..b77303a8fa --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/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_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/reg.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/reg.h new file mode 100644 index 0000000000..037633d10a --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/reg.h @@ -0,0 +1,39 @@ +/* $OpenBSD: reg.h,v 1.3 2020/07/14 09:41:30 kettenis Exp $ */ + +/* + * Copyright (c) 2020 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_REG_H_ +#define _MACHINE_REG_H_ + +struct reg { + uint64_t r_reg[32]; + uint64_t r_lr; + uint64_t r_cr; + uint64_t r_xer; + uint64_t r_ctr; + uint64_t r_pc; + uint64_t r_ps; +}; + +struct fpreg { + __uint128_t fp_vsx[64]; + uint64_t fp_fpscr; + uint64_t fp_vscr; + uint64_t fp_vrsave; +}; + +#endif /* !_MACHINE_REG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/reloc.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/reloc.h new file mode 100644 index 0000000000..f233ce24dc --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/reloc.h @@ -0,0 +1,148 @@ +/* $OpenBSD: reloc.h,v 1.2 2020/07/18 16:41:43 kettenis Exp $ */ + +/* + * Copyright (c) 2020 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_RELOC_H_ +#define _MACHINE_RELOC_H_ + +#define R_PPC64_NONE 0 +#define R_PPC64_ADDR32 1 +#define R_PPC64_ADDR24 2 +#define R_PPC64_ADDR16 3 +#define R_PPC64_ADDR16_LO 4 +#define R_PPC64_ADDR16_HI 5 +#define R_PPC64_ADDR16_HA 6 +#define R_PPC64_ADDR14 7 + +#define R_PPC64_REL24 10 +#define R_PPC64_REL14 11 + +#define R_PPC64_GOT16 14 +#define R_PPC64_GOT16_LO 15 +#define R_PPC64_GOT16_HI 16 +#define R_PPC64_GOT16_HA 17 + +#define R_PPC64_COPY 19 +#define R_PPC64_GLOB_DAT 20 +#define R_PPC64_JMP_SLOT 21 +#define R_PPC64_RELATIVE 22 + +#define R_PPC64_UADDR32 24 +#define R_PPC64_UADDR16 25 +#define R_PPC64_REL32 26 +#define R_PPC64_PLT32 27 +#define R_PPC64_PLTREL32 28 +#define R_PPC64_PLT16_LO 29 +#define R_PPC64_PLT16_HI 30 +#define R_PPC64_PLT16_HA 31 + +#define R_PPC64_SECTOFF 33 +#define R_PPC64_SECTOFF_LO 34 +#define R_PPC64_SECTOFF_HI 35 +#define R_PPC64_SECTOFF_HA 36 +#define R_PPC64_REL30 37 +#define R_PPC64_ADDR64 38 +#define R_PPC64_ADDR16_HIGHER 39 +#define R_PPC64_ADDR16_HIGHERA 40 +#define R_PPC64_ADDR16_HIGHEST 41 +#define R_PPC64_ADDR16_HIGHESTA 42 +#define R_PPC64_UADDR64 43 +#define R_PPC64_REL64 44 +#define R_PPC64_PLT64 45 +#define R_PPC64_PLTREL64 46 +#define R_PPC64_TOC16 47 +#define R_PPC64_TOC16_LO 48 +#define R_PPC64_TOC16_HI 49 +#define R_PPC64_TOC16_HA 50 +#define R_PPC64_TOC 51 +#define R_PPC64_PLTGOT16 52 +#define R_PPC64_PLTGOT16_LO 53 +#define R_PPC64_PLTGOT16_HI 54 +#define R_PPC64_PLTGOT16_HA 55 +#define R_PPC64_ADDR16_DS 56 +#define R_PPC64_ADDR16_LO_DS 57 +#define R_PPC64_GOT16_DS 58 +#define R_PPC64_GOT16_LO_DS 59 +#define R_PPC64_PLT16_LO_DS 60 +#define R_PPC64_SECTOFF_DS 61 +#define R_PPC64_SECTOFF_LO_DS 62 +#define R_PPC64_TOC16_DS 63 +#define R_PPC64_TOC16_LO_DS 64 +#define R_PPC64_PLTGOT16_DS 65 +#define R_PPC64_PLTGOT16_LO_DS 66 +#define R_PPC64_TLS 67 +#define R_PPC64_DTPMOD64 68 +#define R_PPC64_TPREL16 69 +#define R_PPC64_TPREL16_LO 70 +#define R_PPC64_TPREL16_HI 71 +#define R_PPC64_TPREL16_HA 72 +#define R_PPC64_TPREL64 73 +#define R_PPC64_DTPREL16 74 +#define R_PPC64_DTPREL16_LO 75 +#define R_PPC64_DTPREL16_HI 76 +#define R_PPC64_DTPREL16_HA 77 +#define R_PPC64_DTPREL64 78 +#define R_PPC64_GOT_TLSGD16 79 +#define R_PPC64_GOT_TLSGD16_LO 80 +#define R_PPC64_GOT_TLSGD16_HI 81 +#define R_PPC64_GOT_TLSGD16_HA 82 +#define R_PPC64_GOT_TLSD16 83 +#define R_PPC64_GOT_TLSD16_LO 84 +#define R_PPC64_GOT_TLSD16_HI 85 +#define R_PPC64_GOT_TLSD16_HA 86 +#define R_PPC64_GOT_TPREL16_DS 87 +#define R_PPC64_GOT_TPREL16_LO_DS 88 +#define R_PPC64_GOT_TPREL16_HI 89 +#define R_PPC64_GOT_TPREL16_HA 90 +#define R_PPC64_GOT_DTPREL16_DS 91 +#define R_PPC64_GOT_DTPREL16_LO_DS 92 +#define R_PPC64_GOT_DTPREL16_HI 93 +#define R_PPC64_GOT_DTPREL16_HA 94 +#define R_PPC64_TPREL16_DS 95 +#define R_PPC64_TPREL16_LO_DS 96 +#define R_PPC64_TPREL16_HIGHER 97 +#define R_PPC64_TPREL16_HIGHERA 98 +#define R_PPC64_TPREL16_HIGHEST 99 +#define R_PPC64_TPREL16_HIGHESTA 100 +#define R_PPC64_DTPREL16_DS 101 +#define R_PPC64_DTPREL16_LO_DS 102 +#define R_PPC64_DTPREL16_HIGHER 103 +#define R_PPC64_DTPREL16_HIGHERA 104 +#define R_PPC64_DTPREL16_HIGHEST 105 +#define R_PPC64_DTPREL16_HIGHESTA 106 +#define R_PPC64_TLSGD 107 +#define R_PPC64_TLSLD 108 +#define R_PPC64_TOCSAVE 109 +#define R_PPC64_ADDR16_HIGH 110 +#define R_PPC64_ADDR16_HIGHA 111 +#define R_PPC64_TPREL16_HIGH 112 +#define R_PPC64_TPREL16_HIGHA 113 +#define R_PPC64_DTPREL16_HIGH 114 +#define R_PPC64_DTPREL16_HIGHA 115 +#define R_PPC64_REL24_NOTOC 116 +#define R_PPC64_ADDR64_LOCAL 117 +#define R_PPC64_ENTRY 118 + +#define R_PPC64_IRELATIVE 248 +#define R_PPC64_REL16 249 +#define R_PPC64_REL16_LO 250 +#define R_PPC64_REL16_HI 251 +#define R_PPC64_REL16_HA 252 +#define R_PPC64_GNU_VTINHERIT 253 +#define R_PPC64_GNU_VTENTRY 254 + +#endif /* _MACHINE_RELOC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/setjmp.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/setjmp.h new file mode 100644 index 0000000000..02b53f759f --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/setjmp.h @@ -0,0 +1,4 @@ +/* $OpenBSD: setjmp.h,v 1.1 2020/06/25 05:01:16 drahn Exp $ */ +/* $NetBSD: setjmp.h,v 1.1 1996/09/30 16:34:34 ws Exp $ */ + +#define _JBLEN 208 \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/signal.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/signal.h new file mode 100644 index 0000000000..68710820a2 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/signal.h @@ -0,0 +1,65 @@ +/* $OpenBSD: signal.h,v 1.5 2020/07/13 22:37:37 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 _MACHDEP_SIGNAL_H_ +#define _MACHDEP_SIGNAL_H_ + +#include + +typedef int sig_atomic_t; + +#if __BSD_VISIBLE || __XPG_VISIBLE >= 420 + +#include + +struct sigcontext { + long sc_cookie; + int sc_mask; /* saved signal mask */ + __register_t sc_reg[32]; /* saved registers */ + __register_t sc_lr; + __register_t sc_cr; + __register_t sc_xer; + __register_t sc_ctr; + __register_t sc_pc; + __register_t sc_ps; + __register_t sc_vrsave; + __uint128_t sc_vsx[64]; + __uint64_t sc_fpscr; + __uint64_t sc_vscr; +}; + +#define sc_sp sc_reg[1] + +#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */ + +#endif /* _MACHDEP_SIGNAL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/smbiosvar.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/smbiosvar.h new file mode 100644 index 0000000000..60200682ad --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/smbiosvar.h @@ -0,0 +1,278 @@ +/* $OpenBSD: smbiosvar.h,v 1.3 2025/07/15 01:09:32 jsg Exp $ */ +/* + * Copyright (c) 2006 Gordon Willem Klok + * Copyright (c) 2005 Jordan Hargrave + * 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 AUTHORS 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 AUTHORS 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_SMBIOSVAR_ +#define _MACHINE_SMBIOSVAR_ + +#define SMBIOS_UUID_NPRESENT 0x1 +#define SMBIOS_UUID_NSET 0x2 + +/* + * Section 3.5 of "UUIDs and GUIDs" found at + * http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt + * specifies the string representation of a UUID. + */ +#define SMBIOS_UUID_REP "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" +#define SMBIOS_UUID_REPLEN 37 /* 16 zero padded values, 4 hyphens, 1 null */ + +struct smbios_entry { + uint8_t mjr; + uint8_t min; + uint8_t *addr; + uint16_t len; + uint16_t count; +}; + +struct smbhdr { + uint32_t sig; /* "_SM_" */ + uint8_t checksum; /* Entry point checksum */ + uint8_t len; /* Entry point structure length */ + uint8_t majrev; /* Specification major revision */ + uint8_t minrev; /* Specification minor revision */ + uint16_t mss; /* Maximum Structure Size */ + uint8_t epr; /* Entry Point Revision */ + uint8_t fa[5]; /* value determined by EPR */ + uint8_t sasig[5]; /* Secondary Anchor "_DMI_" */ + uint8_t sachecksum; /* Secondary Checksum */ + uint16_t size; /* Length of structure table in bytes */ + uint32_t addr; /* Structure table address */ + uint16_t count; /* Number of SMBIOS structures */ + uint8_t rev; /* BCD revision */ +} __packed; + +struct smb3hdr { + uint8_t sig[5]; /* "_SM3_" */ + uint8_t checksum; /* Entry point structure checksum */ + uint8_t len; /* Entry point length */ + uint8_t majrev; /* SMBIOS major version */ + uint8_t minrev; /* SMBIOS minor version */ + uint8_t docrev; /* SMBIOS docrev */ + uint8_t epr; /* Entry point revision */ + uint8_t reserved; /* Reserved */ + uint32_t size; /* Structure table maximum size */ + uint64_t addr; /* Structure table address */ +} __packed; + +struct smbtblhdr { + uint8_t type; + uint8_t size; + uint16_t handle; +} __packed; + +struct smbtable { + struct smbtblhdr *hdr; + void *tblhdr; + uint32_t cookie; +}; + +#define SMBIOS_TYPE_BIOS 0 +#define SMBIOS_TYPE_SYSTEM 1 +#define SMBIOS_TYPE_BASEBOARD 2 +#define SMBIOS_TYPE_ENCLOSURE 3 +#define SMBIOS_TYPE_PROCESSOR 4 +#define SMBIOS_TYPE_MEMCTRL 5 +#define SMBIOS_TYPE_MEMMOD 6 +#define SMBIOS_TYPE_CACHE 7 +#define SMBIOS_TYPE_PORT 8 +#define SMBIOS_TYPE_SLOTS 9 +#define SMBIOS_TYPE_OBD 10 +#define SMBIOS_TYPE_OEM 11 +#define SMBIOS_TYPE_SYSCONFOPT 12 +#define SMBIOS_TYPE_BIOSLANG 13 +#define SMBIOS_TYPE_GROUPASSOC 14 +#define SMBIOS_TYPE_SYSEVENTLOG 15 +#define SMBIOS_TYPE_PHYMEM 16 +#define SMBIOS_TYPE_MEMDEV 17 +#define SMBIOS_TYPE_ECCINFO32 18 +#define SMBIOS_TYPE_MEMMAPARRAYADDR 19 +#define SMBIOS_TYPE_MEMMAPDEVADDR 20 +#define SMBIOS_TYPE_INBUILTPOINT 21 +#define SMBIOS_TYPE_PORTBATT 22 +#define SMBIOS_TYPE_SYSRESET 23 +#define SMBIOS_TYPE_HWSECUIRTY 24 +#define SMBIOS_TYPE_PWRCTRL 25 +#define SMBIOS_TYPE_VOLTPROBE 26 +#define SMBIOS_TYPE_COOLING 27 +#define SMBIOS_TYPE_TEMPPROBE 28 +#define SMBIOS_TYPE_CURRENTPROBE 29 +#define SMBIOS_TYPE_OOB_REMOTEACCESS 30 +#define SMBIOS_TYPE_BIS 31 +#define SMBIOS_TYPE_SBI 32 +#define SMBIOS_TYPE_ECCINFO64 33 +#define SMBIOS_TYPE_MGMTDEV 34 +#define SMBIOS_TYPE_MGTDEVCOMP 35 +#define SMBIOS_TYPE_MGTDEVTHRESH 36 +#define SMBIOS_TYPE_MEMCHANNEL 37 +#define SMBIOS_TYPE_IPMIDEV 38 +#define SMBIOS_TYPE_SPS 39 +#define SMBIOS_TYPE_INACTIVE 126 +#define SMBIOS_TYPE_EOT 127 + +/* + * SMBIOS Structure Type 0 "BIOS Information" + * DMTF Specification DSP0134 Section: 3.3.1 p.g. 34 + */ +struct smbios_struct_bios { + uint8_t vendor; /* string */ + uint8_t version; /* string */ + uint16_t startaddr; + uint8_t release; /* string */ + uint8_t romsize; + uint64_t characteristics; + uint32_t charext; + uint8_t major_rel; + uint8_t minor_rel; + uint8_t ecf_mjr_rel; /* embedded controller firmware */ + uint8_t ecf_min_rel; /* embedded controller firmware */ +} __packed; + +/* + * SMBIOS Structure Type 1 "System Information" + * DMTF Specification DSP0134 Section 3.3.2 p.g. 35 + */ + +struct smbios_sys { +/* SMBIOS spec 2.0+ */ + uint8_t vendor; /* string */ + uint8_t product; /* string */ + uint8_t version; /* string */ + uint8_t serial; /* string */ +/* SMBIOS spec 2.1+ */ + uint8_t uuid[16]; + uint8_t wakeup; +/* SMBIOS spec 2.4+ */ + uint8_t sku; /* string */ + uint8_t family; /* string */ +} __packed; + +/* + * SMBIOS Structure Type 2 "Base Board (Module) Information" + * DMTF Specification DSP0134 Section 3.3.3 p.g. 37 + */ +struct smbios_board { + uint8_t vendor; /* string */ + uint8_t product; /* string */ + uint8_t version; /* string */ + uint8_t serial; /* string */ + uint8_t asset; /* string */ + uint8_t feature; /* feature flags */ + uint8_t location; /* location in chassis */ + uint16_t handle; /* chassis handle */ + uint8_t type; /* board type */ + uint8_t noc; /* number of contained objects */ +} __packed; + +/* + * SMBIOS Structure Type 3 "System Enclosure or Chassis" + * DMTF Specification DSP0134 + */ +struct smbios_enclosure { + /* SMBIOS spec 2.0+ */ + uint8_t vendor; /* string */ + uint8_t type; + uint8_t version; /* string */ + uint8_t serial; /* string */ + uint8_t asset_tag; /* string */ + /* SMBIOS spec 2.1+ */ + uint8_t boot_state; + uint8_t psu_state; + uint8_t thermal_state; + uint8_t security_status; + /* SMBIOS spec 2.3+ */ + uint16_t oem_defined; + uint8_t height; + uint8_t no_power_cords; + uint8_t no_contained_element; + uint8_t reclen_contained_element; + uint8_t contained_elements; + /* SMBIOS spec 2.7+ */ + uint8_t sku; /* string */ +} __packed; + +/* + * SMBIOS Structure Type 4 "processor Information" + * DMTF Specification DSP0134 v2.5 Section 3.3.5 p.g. 24 + */ +struct smbios_cpu { + uint8_t cpu_socket_designation; /* string */ + uint8_t cpu_type; + uint8_t cpu_family; + uint8_t cpu_mfg; /* string */ + uint32_t cpu_id_eax; + uint32_t cpu_id_edx; + uint8_t cpu_version; /* string */ + uint8_t cpu_voltage; + uint16_t cpu_clock; + uint16_t cpu_max_speed; + uint16_t cpu_current_speed; + uint8_t cpu_status; +#define SMBIOS_CPUST_POPULATED (1<<6) +#define SMBIOS_CPUST_STATUSMASK (0x07) + uint8_t cpu_upgrade; + uint16_t cpu_l1_handle; + uint16_t cpu_l2_handle; + uint16_t cpu_l3_handle; + uint8_t cpu_serial; /* string */ + uint8_t cpu_asset_tag; /* string */ + uint8_t cpu_part_nr; /* string */ + /* following fields were added in smbios 2.5 */ + uint8_t cpu_core_count; + uint8_t cpu_core_enabled; + uint8_t cpu_thread_count; + uint16_t cpu_characteristics; +} __packed; + +/* + * SMBIOS Structure Type 38 "IPMI Information" + * DMTF Specification DSP0134 Section 3.3.39 p.g. 91 + */ +struct smbios_ipmi { + uint8_t smipmi_if_type; /* IPMI Interface Type */ + uint8_t smipmi_if_rev; /* BCD IPMI Revision */ + uint8_t smipmi_i2c_address; /* I2C address of BMC */ + uint8_t smipmi_nvram_address; /* I2C address of NVRAM + * storage */ + uint64_t smipmi_base_address; /* Base address of BMC (BAR + * format */ + uint8_t smipmi_base_flags; /* Flags field: + * bit 7:6 : register spacing + * 00 = byte + * 01 = dword + * 02 = word + * bit 4 : Lower bit BAR + * bit 3 : IRQ valid + * bit 2 : N/A + * bit 1 : Interrupt polarity + * bit 0 : Interrupt trigger */ + uint8_t smipmi_irq; /* IRQ if applicable */ +} __packed; + +int smbios_find_table(uint8_t, struct smbtable *); +char *smbios_get_string(struct smbtable *, uint8_t, char *, size_t); + +#endif \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/spinlock.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/spinlock.h new file mode 100644 index 0000000000..98555de967 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/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 + * + * 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 \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/tcb.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/tcb.h new file mode 100644 index 0000000000..879efa9de8 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/tcb.h @@ -0,0 +1,42 @@ +/* $OpenBSD: tcb.h,v 1.4 2020/07/14 16:48:13 kettenis Exp $ */ + +/* + * Copyright (c) 2011 Philip Guenther + * + * 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 *)(p)->p_md.md_regs->fixreg[13]) +#define TCB_SET(p, addr) \ + ((p)->p_md.md_regs->fixreg[13] = (__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 0x7008 + +register void *__tcb __asm__ ("r13"); +#define TCB_GET() (__tcb) +#define TCB_SET(tcb) ((__tcb) = (tcb)) + +#endif /* _KERNEL */ +#endif /* _MACHINE_TCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/timetc.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/timetc.h new file mode 100644 index 0000000000..9c07a63a52 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/timetc.h @@ -0,0 +1,23 @@ +/* $OpenBSD: timetc.h,v 1.2 2022/11/05 16:23:02 cheloha Exp $ */ +/* + * Copyright (c) 2020 Paul Irofti + * + * 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_TIMETC_H_ +#define _MACHINE_TIMETC_H_ + +#define TC_TB 1 + +#endif /* _MACHINE_TIMETC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/trap.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/trap.h new file mode 100644 index 0000000000..7e1ef37d29 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/trap.h @@ -0,0 +1,158 @@ +/* $OpenBSD: trap.h,v 1.9 2022/05/19 05:43:48 miod Exp $ */ +/*- + * SPDX-License-Identifier: BSD-4-Clause + * + * 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. + * + * $NetBSD: trap.h,v 1.7 2002/02/22 13:51:40 kleink Exp $ + */ + +#ifndef _MACHINE_TRAP_H_ +#define _MACHINE_TRAP_H_ + +#define EXC_RSVD 0x0000 /* Reserved */ +#define EXC_RST 0x0100 /* Reset; all but IBM4xx */ +#define EXC_MCHK 0x0200 /* Machine Check */ +#define EXC_DSI 0x0300 /* Data Storage Interrupt */ +#define EXC_DSE 0x0380 /* Data Segment Interrupt */ +#define EXC_ISI 0x0400 /* Instruction Storage Interrupt */ +#define EXC_ISE 0x0480 /* Instruction Segment Interrupt */ +#define EXC_EXI 0x0500 /* External Interrupt */ +#define EXC_ALI 0x0600 /* Alignment Interrupt */ +#define EXC_PGM 0x0700 /* Program Interrupt */ +#define EXC_FPU 0x0800 /* Floating-point Unavailable */ +#define EXC_DECR 0x0900 /* Decrementer Interrupt */ +#define EXC_SC 0x0c00 /* System Call */ +#define EXC_TRC 0x0d00 /* Trace */ +#define EXC_FPA 0x0e00 /* Floating-point Assist */ + +/* The following is only available on the 601: */ +#define EXC_RUNMODETRC 0x2000 /* Run Mode/Trace Exception */ + +/* The following are only available on 970(G5): */ +#define EXC_VECAST_G5 0x1700 /* AltiVec Assist */ + +/* The following are only available on 7400(G4): */ +#define EXC_VEC 0x0f20 /* AltiVec Unavailable */ +#define EXC_VECAST_G4 0x1600 /* AltiVec Assist */ + +/* The following are only available on 604/750/7400: */ +#define EXC_PERF 0x0f00 /* Performance Monitoring */ +#define EXC_BPT 0x1300 /* Instruction Breakpoint */ +#define EXC_SMI 0x1400 /* System Management Interrupt */ + +/* The following are only available on 750/7400: */ +#define EXC_THRM 0x1700 /* Thermal Management Interrupt */ + +/* And these are only on the 603: */ +#define EXC_IMISS 0x1000 /* Instruction translation miss */ +#define EXC_DLMISS 0x1100 /* Data load translation miss */ +#define EXC_DSMISS 0x1200 /* Data store translation miss */ + +/* Power ISA 2.06+: */ +#define EXC_HDSI 0x0e00 /* Hypervisor Data Storage */ +#define EXC_HISI 0x0e20 /* Hypervisor Instruction Storage */ +#define EXC_HEA 0x0e40 /* Hypervisor Emulation Assistance */ +#define EXC_HMI 0x0e60 /* Hypervisor Maintenance */ +#define EXC_VSX 0x0f40 /* VSX Unavailable */ + +/* Power ISA 2.07+: */ +#define EXC_FAC 0x0f60 /* Facility Unavailable */ +#define EXC_HFAC 0x0f80 /* Hypervisor Facility Unavailable */ + +/* Power ISA 3.0+: */ +#define EXC_HVI 0x0ea0 /* Hypervisor Virtualization */ + +/* The following are available on 4xx and 85xx */ +#define EXC_CRIT 0x0100 /* Critical Input Interrupt */ +#define EXC_PIT 0x1000 /* Programmable Interval Timer */ +#define EXC_FIT 0x1010 /* Fixed Interval Timer */ +#define EXC_WDOG 0x1020 /* Watchdog Timer */ +#define EXC_DTMISS 0x1100 /* Data TLB Miss */ +#define EXC_ITMISS 0x1200 /* Instruction TLB Miss */ +#define EXC_APU 0x1300 /* Auxiliary Processing Unit */ +#define EXC_DEBUG 0x2f10 /* Debug trap */ +#define EXC_VECAST_E 0x2f20 /* Altivec Assist (Book-E) */ +#define EXC_SPFPD 0x2f30 /* SPE Floating-point Data */ +#define EXC_SPFPR 0x2f40 /* SPE Floating-point Round */ + +/* POWER8 */ +#define EXC_SOFT_PATCH 0x1500 /* POWER8 Soft Patch Exception */ + +#define EXC_END 0x3000 /* End of exception vectors */ + +#define EXC_AST 0x3000 /* Fake AST vector */ + +/* Trap was in user mode */ +#define EXC_USER 0x10000 + + +/* + * EXC_ALI sets bits in the DSISR and DAR to provide enough + * information to recover from the unaligned access without needing to + * parse the offending instruction. This includes certain bits of the + * opcode, and information about what registers are used. The opcode + * indicator values below come from Appendix F of Book III of "The + * PowerPC Architecture". + */ + +#define EXC_ALI_OPCODE_INDICATOR(dsisr) ((dsisr >> 10) & 0x7f) +#define EXC_ALI_LFD 0x09 +#define EXC_ALI_STFD 0x0b + +/* Macros to extract register information */ +#define EXC_ALI_RST(dsisr) ((dsisr >> 5) & 0x1f) /* source or target */ +#define EXC_ALI_RA(dsisr) (dsisr & 0x1f) +#define EXC_ALI_INST_RST(instr) ((instr >> 21) & 0x1f) + +/* + * SRR1 bits for program exception traps. These identify what caused + * the program exception. See section 6.5.9 of the Power ISA Version + * 2.05. + */ + +#define EXC_PGM_FPENABLED (1UL << 20) +#define EXC_PGM_ILLEGAL (1UL << 19) +#define EXC_PGM_PRIV (1UL << 18) +#define EXC_PGM_TRAP (1UL << 17) + +/* + * DSISR bits. + */ + +#define DSISR_STORE (1UL << 25) + +/* Magic pointers to store trap handler entry points */ +#define TRAP_ENTRY 0x1f8 +#define TRAP_HVENTRY 0x1f0 +#define TRAP_SLBENTRY 0x1e8 +#define TRAP_RSTENTRY 0x1e0 + +#endif /* _MACHINE_TRAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/powerpc64-openbsd-none/powerpc64/vmparam.h b/lib/libc/include/powerpc64-openbsd-none/powerpc64/vmparam.h new file mode 100644 index 0000000000..4cad35a1a2 --- /dev/null +++ b/lib/libc/include/powerpc64-openbsd-none/powerpc64/vmparam.h @@ -0,0 +1,53 @@ +/* + * 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)32*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_PHYS_SIZE (USRIOSIZE * PAGE_SIZE) + +#define VM_PHYSSEG_MAX 32 +#define VM_PHYSSEG_STRAT VM_PSTRAT_BSEARCH + +#define VM_MIN_ADDRESS ((vaddr_t)PAGE_SIZE) +#define VM_MAXUSER_ADDRESS 0xbffffffffffff000UL +#define VM_MAX_ADDRESS 0xffffffffffffffffUL +#ifdef _KERNEL +#define VM_MIN_STACK_ADDRESS 0x9000000000000000UL +#endif +#define VM_MIN_KERNEL_ADDRESS 0xc000000000000000UL +#define VM_MAX_KERNEL_ADDRESS 0xc0000007ffffffffUL \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/frame.h b/lib/libc/include/riscv64-openbsd-none/frame.h new file mode 100644 index 0000000000..e15698128f --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/frame.h @@ -0,0 +1,99 @@ +/* $OpenBSD: frame.h,v 1.3 2022/02/24 14:19:10 visa Exp $ */ + +/* + * Copyright (c) 2019 Brian Bamsch + * Copyright (c) 2016 Dale Rahn + * Copyright (c) 2015 Ruslan Bukin + * All rights reserved. + * + * Portions of this software were developed by SRI International and the + * University of Cambridge Computer Laboratory under DARPA/AFRL contract + * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. + * + * Portions of this software were developed by the University of Cambridge + * Computer Laboratory as part of the CTSRD Project, with support from the + * UK Higher Education Innovation Fund (HEIF). + * + * 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 copyright holder 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 AUTHOR 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 AUTHOR 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_FRAME_H_ +#define _MACHINE_FRAME_H_ + +#ifndef _LOCORE + +#include + +/* + * Exception/Trap Stack Frame + */ +#define clockframe trapframe +typedef struct trapframe { + /* Standard Registers */ + register_t tf_ra; + register_t tf_sp; + register_t tf_gp; + register_t tf_tp; + register_t tf_t[7]; + register_t tf_s[12]; + register_t tf_a[8]; + /* Supervisor Trap CSRs */ + register_t tf_sepc; + register_t tf_sstatus; + register_t tf_stval; + register_t tf_scause; + register_t tf_pad; +} trapframe_t; + +/* + * pushed on stack for signal delivery + */ +struct sigframe { + int sf_signum; + struct sigcontext sf_sc; + siginfo_t sf_si; +}; + +/* + * System stack frames. + */ + +/* + * Stack frame inside cpu_switch() + */ +struct switchframe { + register_t sf_s[12]; + register_t sf_ra; + register_t sf_pad; +}; + +struct callframe { + struct callframe *f_frame; + register_t f_ra; +}; + +#endif /* !_LOCORE */ + +#endif /* !_MACHINE_FRAME_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/_float.h b/lib/libc/include/riscv64-openbsd-none/machine/_float.h new file mode 100644 index 0000000000..d52ce43ca7 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/_float.h @@ -0,0 +1,96 @@ +/* $OpenBSD: _float.h,v 1.1 2021/04/23 02:42:16 drahn Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + */ + +#ifndef _MACHINE__FLOAT_H_ +#define _MACHINE__FLOAT_H_ + +#define __FLT_RADIX 2 /* b */ +#define __FLT_ROUNDS __flt_rounds() +#define __FLT_EVAL_METHOD 0 /* no promotions */ + +#define __FLT_MANT_DIG 24 /* p */ +#define __FLT_EPSILON 1.19209290E-7F /* b**(1-p) */ +#define __FLT_DIG 6 /* floor((p-1)*log10(b))+(b == 10) */ +#define __FLT_MIN_EXP (-125) /* emin */ +#define __FLT_MIN 1.17549435E-38F /* b**(emin-1) */ +#define __FLT_MIN_10_EXP (-37) /* ceil(log10(b**(emin-1))) */ +#define __FLT_MAX_EXP 128 /* emax */ +#define __FLT_MAX 3.40282347E+38F /* (1-b**(-p))*b**emax */ +#define __FLT_MAX_10_EXP 38 /* floor(log10((1-b**(-p))*b**emax)) */ + +#define __DBL_MANT_DIG 53 +#define __DBL_EPSILON 2.2204460492503131E-16 +#define __DBL_DIG 15 +#define __DBL_MIN_EXP (-1021) +#define __DBL_MIN 2.2250738585072014E-308 +#define __DBL_MIN_10_EXP (-307) +#define __DBL_MAX_EXP 1024 +#define __DBL_MAX 1.7976931348623157E+308 +#define __DBL_MAX_10_EXP 308 + +#ifdef __LDBL_MANT_DIG__ +#define __LDBL_MANT_DIG __LDBL_MANT_DIG__ +#define __LDBL_EPSILON __LDBL_EPSILON__ +#define __LDBL_DIG __LDBL_DIG__ +#define __LDBL_MIN_EXP __LDBL_MIN_EXP__ +#define __LDBL_MIN __LDBL_MIN__ +#define __LDBL_MIN_10_EXP __LDBL_MIN_10_EXP__ +#define __LDBL_MAX_EXP __LDBL_MAX_EXP__ +#define __LDBL_MAX __LDBL_MAX__ +#define __LDBL_MAX_10_EXP __LDBL_MAX_10_EXP__ +#else +#define __LDBL_MANT_DIG DBL_MANT_DIG +#define __LDBL_EPSILON DBL_EPSILON +#define __LDBL_DIG DBL_DIG +#define __LDBL_MIN_EXP DBL_MIN_EXP +#define __LDBL_MIN DBL_MIN +#define __LDBL_MIN_10_EXP DBL_MIN_10_EXP +#define __LDBL_MAX_EXP DBL_MAX_EXP +#define __LDBL_MAX DBL_MAX +#define __LDBL_MAX_10_EXP DBL_MAX_10_EXP +#endif + +#define __DECIMAL_DIG 17 + +#endif /* _MACHINE__FLOAT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/_types.h b/lib/libc/include/riscv64-openbsd-none/machine/_types.h new file mode 100644 index 0000000000..b5c1227f1e --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/_types.h @@ -0,0 +1,146 @@ +/* $OpenBSD: _types.h,v 1.5 2023/07/02 19:02:28 cheloha 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[14]; +} 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_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/apmvar.h b/lib/libc/include/riscv64-openbsd-none/machine/apmvar.h new file mode 100644 index 0000000000..18cdbfd9de --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/apmvar.h @@ -0,0 +1,122 @@ +/* $OpenBSD: apmvar.h,v 1.1 2023/11/06 20:59:26 jca Exp $ */ + +/* + * Copyright (c) 2001 Alexander Guy + * Copyright (c) 1995 John T. Kohl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef _MACHINE_APMVAR_H_ +#define _MACHINE_APMVAR_H_ + +#include + +/* Advanced Power Management (v1.0 and v1.1 specification) + * functions/defines/etc. + */ + +/* These definitions make up the heart of the user-land interface + * to the APM devices. + */ + +#define APM_AC_OFF 0x00 +#define APM_AC_ON 0x01 +#define APM_AC_BACKUP 0x02 +#define APM_AC_UNKNOWN 0xff +#define APM_BATT_HIGH 0x00 +#define APM_BATT_LOW 0x01 +#define APM_BATT_CRITICAL 0x02 +#define APM_BATT_CHARGING 0x03 +#define APM_BATT_UNKNOWN 0xff +#define APM_BATT_LIFE_UNKNOWN 0xff + +#define APM_NOEVENT 0x0000 +#define APM_STANDBY_REQ 0x0001 +#define APM_SUSPEND_REQ 0x0002 +#define APM_NORMAL_RESUME 0x0003 +#define APM_CRIT_RESUME 0x0004 /* suspend/resume happened + without us */ +#define APM_BATTERY_LOW 0x0005 +#define APM_POWER_CHANGE 0x0006 +#define APM_UPDATE_TIME 0x0007 +#define APM_CRIT_SUSPEND_REQ 0x0008 +#define APM_USER_STANDBY_REQ 0x0009 +#define APM_USER_SUSPEND_REQ 0x000A +#define APM_SYS_STANDBY_RESUME 0x000B +#define APM_CAPABILITY_CHANGE 0x000C /* apm v1.2 */ +#define APM_USER_HIBERNATE_REQ 0x000D +#define APM_EVENT_MASK 0xffff + +#define APM_EVENT_COMPOSE(t,i) ((((i) & 0x7fff) << 16)|((t) & APM_EVENT_MASK)) +#define APM_EVENT_TYPE(e) ((e) & APM_EVENT_MASK) +#define APM_EVENT_INDEX(e) ((e) >> 16) + +/* + * LP (Laptop Package) + * + * Copyright (C) 1994 by HOSOKAWA Tatsumi + * + * This software may be used, modified, copied, and distributed, in + * both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + */ + +#define APM_BATTERY_ABSENT 4 + +struct apm_power_info { + u_char battery_state; + u_char ac_state; + u_char battery_life; + u_char spare1; + u_int minutes_left; /* estimate */ + u_int spare2[6]; +}; + +struct apm_ctl { + u_int dev; + u_int mode; +}; + +#define APM_IOC_REJECT _IOW('A', 0, struct apm_event_info) /* reject request # */ +#define APM_IOC_STANDBY _IO('A', 1) /* put system into standby */ +#define APM_IOC_SUSPEND _IO('A', 2) /* put system into suspend */ +#define APM_IOC_GETPOWER _IOR('A', 3, struct apm_power_info) /* fetch battery state */ +#define APM_IOC_DEV_CTL _IOW('A', 5, struct apm_ctl) /* put device into mode */ +#define APM_IOC_PRN_CTL _IOW('A', 6, int ) /* driver power status msg */ +#define APM_PRINT_ON 0 /* driver power status displayed */ +#define APM_PRINT_OFF 1 /* driver power status not displayed */ +#define APM_PRINT_PCT 2 /* driver power status only displayed + if the percentage changes */ +#define APM_IOC_STANDBY_REQ _IO('A', 7) /* request standby */ +#define APM_IOC_SUSPEND_REQ _IO('A', 8) /* request suspend */ +#define APM_IOC_HIBERNATE _IO('A', 9) /* put system into hibernate */ + +#endif /* _MACHINE_APMVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/asm.h b/lib/libc/include/riscv64-openbsd-none/machine/asm.h new file mode 100644 index 0000000000..dcb1d9d02b --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/asm.h @@ -0,0 +1,129 @@ +/* $OpenBSD: asm.h,v 1.8 2022/12/06 00:08:38 jca Exp $ */ + +/* + * Copyright (c) 2020 Brian Bamsch + * 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. + * + * from: @(#)asm.h 5.5 (Berkeley) 5/7/91 + */ + +#ifndef _MACHINE_ASM_H_ +#define _MACHINE_ASM_H_ + +#define _C_LABEL(x) x +#define _ASM_LABEL(x) x + +#ifdef __STDC__ +# define __CONCAT(x,y) x ## y +# define __STRING(x) #x +#else +# define __CONCAT(x,y) x/**/y +# define __STRING(x) "x" +#endif + +#ifndef _ALIGN_TEXT +# define _ALIGN_TEXT .align 0 +#endif + +/* NB == No Binding: use .globl or .weak as necessary */ +#define _ENTRY_NB(x) \ + .text; .p2align 1; .type x,@function; x: +#define _ENTRY(x) .globl x; _ENTRY_NB(x) + +#if defined(PROF) || defined(GPROF) +// XXX Profiler Support +#define _PROF_PROLOGUE \ + addi sp, sp, -16; \ + sd ra, 8(sp); \ + sd fp, 0(sp); \ + mv fp, sp; \ + call __mcount; \ + ld ra, 8(sp); \ + ld fp, 0(sp); \ + add sp, sp, 16; +#else +#define _PROF_PROLOGUE +#endif + +#if defined(_RET_PROTECTOR) +// XXX Retguard Support +#error RETGUARD not yet supported for riscv64 +#else +#define RETGUARD_CALC_COOKIE(reg) +#define RETGUARD_LOAD_RANDOM(x, reg) +#define RETGUARD_SETUP(x, reg) +#define RETGUARD_CHECK(x, reg) +#define RETGUARD_PUSH(reg) +#define RETGUARD_POP(reg) +#define RETGUARD_SYMBOL(x) +#endif + +#define ENTRY(y) _ENTRY(y); _PROF_PROLOGUE +#define ENTRY_NP(y) _ENTRY(y) +#define ENTRY_NB(y) _ENTRY_NB(y); _PROF_PROLOGUE +#define ASENTRY(y) _ENTRY(y); _PROF_PROLOGUE +#define ASENTRY_NP(y) _ENTRY(y) +#define END(y) .size y, . - y +#define EENTRY(sym) .globl sym; sym: +#define EEND(sym) + +#ifdef __PIC__ +#define PIC_SYM(x,y) x(y) +#else +#define PIC_SYM(x,y) x +#endif + +#define STRONG_ALIAS(alias,sym) \ + .global alias; \ + alias = sym +#define WEAK_ALIAS(alias,sym) \ + .weak alias; \ + alias = sym + +#define SWAP_FAULT_HANDLER(handler, tmp0, tmp1) \ + ld tmp0, CI_CURPCB(tp); /* Load the pcb */ \ + ld tmp1, PCB_ONFAULT(tmp0); /* Save old handler */ \ + sd handler, PCB_ONFAULT(tmp0); /* Set the handler */ \ + mv handler, tmp1 + +#define SET_FAULT_HANDLER(handler, pcb) \ + ld pcb, CI_CURPCB(tp); /* Load the pcb */ \ + sd handler, PCB_ONFAULT(pcb) /* Set the handler */ + +#define ENTER_USER_ACCESS(tmp) \ + li tmp, SSTATUS_SUM; \ + csrs sstatus, tmp + +#define EXIT_USER_ACCESS(tmp) \ + li tmp, SSTATUS_SUM; \ + csrc sstatus, tmp + +#endif /* _MACHINE_ASM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/atomic.h b/lib/libc/include/riscv64-openbsd-none/machine/atomic.h new file mode 100644 index 0000000000..95cfadaae9 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/atomic.h @@ -0,0 +1,50 @@ +/* $OpenBSD: atomic.h,v 1.5 2024/01/24 12:25:50 jca Exp $ */ + +/* Public Domain */ + +#ifndef _MACHINE_ATOMIC_H_ +#define _MACHINE_ATOMIC_H_ + +#define __membar(_f) do {__asm volatile(_f ::: "memory"); } while (0) + +#define membar_enter() __membar("fence w,rw") +#define membar_exit() __membar("fence rw,w") +#define membar_producer() __membar("fence w,w") +#define membar_consumer() __membar("fence r,r") +#define membar_sync() __membar("fence rw,rw") + +#if defined(_KERNEL) + +/* virtio needs MP membars even on SP kernels */ +#define virtio_membar_producer() __membar("fence w,w") +#define virtio_membar_consumer() __membar("fence r,r") +#define virtio_membar_sync() __membar("fence rw,rw") + +/* + * Set bits + * *p = *p | v + */ +static inline void +atomic_setbits_int(volatile unsigned int *p, unsigned int v) +{ + __asm volatile("amoor.w zero, %1, %0" + : "+A" (*p) + : "r" (v) + : "memory"); +} + +/* + * Clear bits + * *p = *p & (~v) + */ +static inline void +atomic_clearbits_int(volatile unsigned int *p, unsigned int v) +{ + __asm volatile("amoand.w zero, %1, %0" + : "+A" (*p) + : "r" (~v) + : "memory"); +} + +#endif /* defined(_KERNEL) */ +#endif /* _MACHINE_ATOMIC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/bootconfig.h b/lib/libc/include/riscv64-openbsd-none/machine/bootconfig.h new file mode 100644 index 0000000000..40f8da8ae4 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/bootconfig.h @@ -0,0 +1,47 @@ +/* $OpenBSD: bootconfig.h,v 1.5 2024/04/06 18:33:54 kettenis Exp $ */ + +/*- + * Copyright (c) 2015-2017 Ruslan Bukin + * All rights reserved. + * + * Portions of this software were developed by SRI International and the + * University of Cambridge Computer Laboratory under DARPA/AFRL contract + * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. + * + * Portions of this software were developed by the University of Cambridge + * Computer Laboratory as part of the CTSRD Project, with support from the + * UK Higher Education Innovation Fund (HEIF). + * + * 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 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 AUTHOR 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_BOOTCONFIG_H_ +#define _MACHINE_BOOTCONFIG_H_ + +struct riscv_bootparams { + vaddr_t kern_l1pt; /* L1 page table for the kernel */ + paddr_t kern_phys; + vaddr_t kern_stack; + paddr_t dtbp_phys; /* Device tree blob physical addr */ +}; + +#endif /* _MACHINE_BOOTCONFIG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/bus.h b/lib/libc/include/riscv64-openbsd-none/machine/bus.h new file mode 100644 index 0000000000..85999dfe9d --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/bus.h @@ -0,0 +1,544 @@ +/* $OpenBSD: bus.h,v 1.8 2025/08/03 14:03:12 jca Exp $ */ + +/* + * Copyright (c) 2003-2004 Opsycon AB Sweden. 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_BUS_H_ +#define _MACHINE_BUS_H_ + +#ifdef __STDC__ +#define CAT(a,b) a##b +#define CAT3(a,b,c) a##b##c +#else +#define CAT(a,b) a/**/b +#define CAT3(a,b,c) a/**/b/**/c +#endif + +/* + * Bus access types. + */ +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; +typedef struct bus_space bus_space_t; + +struct bus_space { + bus_addr_t bus_base; + void *bus_private; + u_int8_t (*_space_read_1)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_1)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int8_t); + u_int16_t (*_space_read_2)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_2)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int16_t); + u_int32_t (*_space_read_4)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_4)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int32_t); + u_int64_t (*_space_read_8)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_8)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int64_t); + void (*_space_read_raw_2)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, u_int8_t *, bus_size_t); + void (*_space_write_raw_2)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const u_int8_t *, bus_size_t); + void (*_space_read_raw_4)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, u_int8_t *, bus_size_t); + void (*_space_write_raw_4)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const u_int8_t *, bus_size_t); + void (*_space_read_raw_8)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, u_int8_t *, bus_size_t); + void (*_space_write_raw_8)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const u_int8_t *, bus_size_t); + int (*_space_map)(bus_space_tag_t , bus_addr_t, + bus_size_t, int, bus_space_handle_t *); + void (*_space_unmap)(bus_space_tag_t, bus_space_handle_t, + bus_size_t); + int (*_space_subregion)(bus_space_tag_t, bus_space_handle_t, + bus_size_t, bus_size_t, bus_space_handle_t *); + void * (*_space_vaddr)(bus_space_tag_t, bus_space_handle_t); + paddr_t (*_space_mmap)(bus_space_tag_t, bus_addr_t, off_t, + int, int); +}; + +#define bus_space_read_1(t, h, o) (*(t)->_space_read_1)((t), (h), (o)) +#define bus_space_read_2(t, h, o) (*(t)->_space_read_2)((t), (h), (o)) +#define bus_space_read_4(t, h, o) (*(t)->_space_read_4)((t), (h), (o)) +#define bus_space_read_8(t, h, o) (*(t)->_space_read_8)((t), (h), (o)) + +#define bus_space_write_1(t, h, o, v) (*(t)->_space_write_1)((t), (h), (o), (v)) +#define bus_space_write_2(t, h, o, v) (*(t)->_space_write_2)((t), (h), (o), (v)) +#define bus_space_write_4(t, h, o, v) (*(t)->_space_write_4)((t), (h), (o), (v)) +#define bus_space_write_8(t, h, o, v) (*(t)->_space_write_8)((t), (h), (o), (v)) + +#define bus_space_read_raw_2(t, h, o) \ + (*(t)->_space_read_2)((t), (h), (o)) +#define bus_space_read_raw_4(t, h, o) \ + (*(t)->_space_read_4)((t), (h), (o)) +#define bus_space_read_raw_8(t, h, o) \ + (*(t)->_space_read_8)((t), (h), (o)) + +#define bus_space_write_raw_2(t, h, o, v) \ + (*(t)->_space_write_2)((t), (h), (o), (v)) +#define bus_space_write_raw_4(t, h, o, v) \ + (*(t)->_space_write_4)((t), (h), (o), (v)) +#define bus_space_write_raw_8(t, h, o, v) \ + (*(t)->_space_write_8)((t), (h), (o), (v)) + +#define bus_space_read_raw_multi_2(t, h, a, b, l) \ + (*(t)->_space_read_raw_2)((t), (h), (a), (b), (l)) +#define bus_space_read_raw_multi_4(t, h, a, b, l) \ + (*(t)->_space_read_raw_4)((t), (h), (a), (b), (l)) +#define bus_space_read_raw_multi_8(t, h, a, b, l) \ + (*(t)->_space_read_raw_8)((t), (h), (a), (b), (l)) + +#define bus_space_write_raw_multi_2(t, h, a, b, l) \ + (*(t)->_space_write_raw_2)((t), (h), (a), (b), (l)) +#define bus_space_write_raw_multi_4(t, h, a, b, l) \ + (*(t)->_space_write_raw_4)((t), (h), (a), (b), (l)) +#define bus_space_write_raw_multi_8(t, h, a, b, l) \ + (*(t)->_space_write_raw_8)((t), (h), (a), (b), (l)) + +#define bus_space_map(t, o, s, c, p) (*(t)->_space_map)((t), (o), (s), (c), (p)) +#define bus_space_unmap(t, h, s) (*(t)->_space_unmap)((t), (h), (s)) +#define bus_space_subregion(t, h, o, s, p) \ + (*(t)->_space_subregion)((t), (h), (o), (s), (p)) + +#define BUS_SPACE_MAP_CACHEABLE 0x01 +#define BUS_SPACE_MAP_LINEAR 0x02 +#define BUS_SPACE_MAP_PREFETCHABLE 0x04 + +extern bus_space_t riscv64_bs_tag; + +#define bus_space_vaddr(t, h) (*(t)->_space_vaddr)((t), (h)) +#define bus_space_mmap(t, a, o, p, f) \ + (*(t)->_space_mmap)((t), (a), (o), (p), (f)) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_multi(n,m) \ +static __inline void \ +CAT(bus_space_read_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_size_t o, CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) \ + *x++ = CAT(bus_space_read_,n)(bst, bsh, o); \ +} + +bus_space_read_multi(1,8) +bus_space_read_multi(2,16) +bus_space_read_multi(4,32) +bus_space_read_multi(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_region(n,m) \ +static __inline void \ +CAT(bus_space_read_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) { \ + *x++ = CAT(bus_space_read_,n)(bst, bsh, ba); \ + ba += (n); \ + } \ +} + +bus_space_read_region(1,8) +bus_space_read_region(2,16) +bus_space_read_region(4,32) +bus_space_read_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_raw_region(n,m) \ +static __inline void \ +CAT(bus_space_read_raw_region_,n)(bus_space_tag_t bst, \ + bus_space_handle_t bsh, \ + bus_addr_t ba, u_int8_t *x, size_t cnt) \ +{ \ + cnt >>= ((n) >> 1); \ + while (cnt--) { \ + CAT(bus_space_read_raw_multi_,n)(bst, bsh, ba, x, (n)); \ + ba += (n); \ + x += (n); \ + } \ +} + +bus_space_read_raw_region(2,16) +bus_space_read_raw_region(4,32) +bus_space_read_raw_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_multi(n,m) \ +static __inline void \ +CAT(bus_space_write_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_size_t o, const CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) \ + CAT(bus_space_write_,n)(bst, bsh, o, *x++); \ +} + +bus_space_write_multi(1,8) +bus_space_write_multi(2,16) +bus_space_write_multi(4,32) +bus_space_write_multi(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_region(n,m) \ +static __inline void \ +CAT(bus_space_write_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, const CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) { \ + CAT(bus_space_write_,n)(bst, bsh, ba, *x++); \ + ba += (n); \ + } \ +} + +bus_space_write_region(1,8) +bus_space_write_region(2,16) +bus_space_write_region(4,32) +bus_space_write_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_raw_region(n,m) \ +static __inline void \ +CAT(bus_space_write_raw_region_,n)(bus_space_tag_t bst, \ + bus_space_handle_t bsh, \ + bus_addr_t ba, const u_int8_t *x, size_t cnt) \ +{ \ + cnt >>= ((n) >> 1); \ + while (cnt--) { \ + CAT(bus_space_write_raw_multi_,n)(bst, bsh, ba, x, (n)); \ + ba += (n); \ + x += (n); \ + } \ +} + +bus_space_write_raw_region(2,16) +bus_space_write_raw_region(4,32) +bus_space_write_raw_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_set_region(n,m) \ +static __inline void \ +CAT(bus_space_set_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, CAT3(u_int,m,_t) x, size_t cnt) \ +{ \ + while (cnt--) { \ + CAT(bus_space_write_,n)(bst, bsh, ba, x); \ + ba += (n); \ + } \ +} + +bus_space_set_region(1,8) +bus_space_set_region(2,16) +bus_space_set_region(4,32) +bus_space_set_region(8,64) + +/*----------------------------------------------------------------------------*/ +static __inline void +bus_space_copy_1(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + char *s = (char *)(h1 + o1); + char *d = (char *)(h2 + o2); + + __asm volatile ("fence w,o" ::: "memory"); + while (c--) + *d++ = *s++; + __asm volatile ("fence io,iwr" ::: "memory"); +} + + +static __inline void +bus_space_copy_2(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + short *s = (short *)(h1 + o1); + short *d = (short *)(h2 + o2); + + __asm volatile ("fence w,o" ::: "memory"); + while (c--) + *d++ = *s++; + __asm volatile ("fence io,iwr" ::: "memory"); +} + +static __inline void +bus_space_copy_4(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + int *s = (int *)(h1 + o1); + int *d = (int *)(h2 + o2); + + __asm volatile ("fence w,o" ::: "memory"); + while (c--) + *d++ = *s++; + __asm volatile ("fence io,iwr" ::: "memory"); +} + +static __inline void +bus_space_copy_8(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + int64_t *s = (int64_t *)(h1 + o1); + int64_t *d = (int64_t *)(h2 + o2); + + __asm volatile ("fence w,o" ::: "memory"); + while (c--) + *d++ = *s++; + __asm volatile ("fence io,iwr" ::: "memory"); +} + +/*----------------------------------------------------------------------------*/ +/* + * Bus read/write barrier methods. + * + * void bus_space_barrier(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * bus_size_t len, int flags); + * + */ +static inline void +bus_space_barrier(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, + bus_size_t length, int flags) +{ + __asm__ volatile ("fence iorw,iorw" ::: "memory"); +} +#define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */ +#define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */ + +#define BUS_DMA_WAITOK 0x0000 +#define BUS_DMA_NOWAIT 0x0001 +#define BUS_DMA_ALLOCNOW 0x0002 +#define BUS_DMA_COHERENT 0x0008 +#define BUS_DMA_BUS1 0x0010 /* placeholders for bus functions... */ +#define BUS_DMA_BUS2 0x0020 +#define BUS_DMA_BUS3 0x0040 +#define BUS_DMA_BUS4 0x0080 +#define BUS_DMA_READ 0x0100 /* mapping is device -> memory only */ +#define BUS_DMA_WRITE 0x0200 /* mapping is memory -> device only */ +#define BUS_DMA_STREAMING 0x0400 /* hint: sequential, unidirectional */ +#define BUS_DMA_ZERO 0x0800 /* zero memory in dmamem_alloc */ +#define BUS_DMA_NOCACHE 0x1000 +#define BUS_DMA_64BIT 0x2000 /* device handles 64bit dva */ + +/* Forwards needed by prototypes below. */ +struct mbuf; +struct proc; +struct uio; + +#define BUS_DMASYNC_POSTREAD 0x0001 +#define BUS_DMASYNC_POSTWRITE 0x0002 +#define BUS_DMASYNC_PREREAD 0x0004 +#define BUS_DMASYNC_PREWRITE 0x0008 + +typedef struct machine_bus_dma_tag *bus_dma_tag_t; +typedef struct machine_bus_dmamap *bus_dmamap_t; + +/* + * bus_dma_segment_t + * + * Describes a single contiguous DMA transaction. Values + * are suitable for programming into DMA registers. + */ +struct machine_bus_dma_segment { + bus_addr_t ds_addr; /* DMA address */ + bus_size_t ds_len; /* length of transfer */ + + paddr_t _ds_paddr; /* CPU address */ + vaddr_t _ds_vaddr; /* CPU address */ + int _ds_coherent; /* Coherently mapped */ +}; +typedef struct machine_bus_dma_segment bus_dma_segment_t; + +/* + * bus_dma_tag_t + * + * A machine-dependent opaque type describing the implementation of + * DMA for a given bus. + */ + +struct machine_bus_dma_tag { + void *_cookie; /* cookie used in the guts */ + int _flags; /* misc. flags */ + + /* + * DMA mapping methods. + */ + int (*_dmamap_create)(bus_dma_tag_t , bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); + void (*_dmamap_destroy)(bus_dma_tag_t , bus_dmamap_t); + int (*_dmamap_load)(bus_dma_tag_t , bus_dmamap_t, void *, + bus_size_t, struct proc *, int); + int (*_dmamap_load_mbuf)(bus_dma_tag_t , bus_dmamap_t, + struct mbuf *, int); + int (*_dmamap_load_uio)(bus_dma_tag_t , bus_dmamap_t, + struct uio *, int); + int (*_dmamap_load_raw)(bus_dma_tag_t , bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); + int (*_dmamap_load_buffer)(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int, paddr_t *, int *, int); + void (*_dmamap_unload)(bus_dma_tag_t , bus_dmamap_t); + void (*_dmamap_sync)(bus_dma_tag_t , bus_dmamap_t, + bus_addr_t, bus_size_t, int); + + /* + * DMA memory utility functions. + */ + int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); + int (*_dmamem_alloc_range)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int, + paddr_t, paddr_t); + void (*_dmamem_free)(bus_dma_tag_t, bus_dma_segment_t *, int); + int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); + void (*_dmamem_unmap)(bus_dma_tag_t, caddr_t, size_t); + paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *, + int, off_t, int, int); + + /* + * internal memory address translation information. + */ + bus_addr_t _dma_mask; +}; + +#define bus_dmamap_create(t, s, n, m, b, f, p) \ + (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p)) +#define bus_dmamap_destroy(t, p) \ + (*(t)->_dmamap_destroy)((t), (p)) +#define bus_dmamap_load(t, m, b, s, p, f) \ + (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f)) +#define bus_dmamap_load_mbuf(t, m, b, f) \ + (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f)) +#define bus_dmamap_load_uio(t, m, u, f) \ + (*(t)->_dmamap_load_uio)((t), (m), (u), (f)) +#define bus_dmamap_load_raw(t, m, sg, n, s, f) \ + (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f)) +#define bus_dmamap_unload(t, p) \ + (*(t)->_dmamap_unload)((t), (p)) +#define bus_dmamap_sync(t, p, a, l, o) \ + (void)((t)->_dmamap_sync ? \ + (*(t)->_dmamap_sync)((t), (p), (a), (l), (o)) : (void)0) + +#define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \ + (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f)) +#define bus_dmamem_alloc_range(t, s, a, b, sg, n, r, f, l, h) \ + (*(t)->_dmamem_alloc_range)((t), (s), (a), (b), (sg), \ + (n), (r), (f), (l), (h)) +#define bus_dmamem_free(t, sg, n) \ + (*(t)->_dmamem_free)((t), (sg), (n)) +#define bus_dmamem_map(t, sg, n, s, k, f) \ + (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f)) +#define bus_dmamem_unmap(t, k, s) \ + (*(t)->_dmamem_unmap)((t), (k), (s)) +#define bus_dmamem_mmap(t, sg, n, o, p, f) \ + (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f)) + +int _dmamap_create(bus_dma_tag_t, bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); +void _dmamap_destroy(bus_dma_tag_t, bus_dmamap_t); +int _dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int); +int _dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, struct mbuf *, int); +int _dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, struct uio *, int); +int _dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); +int _dmamap_load_buffer(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int, paddr_t *, int *, int); +void _dmamap_unload(bus_dma_tag_t, bus_dmamap_t); +void _dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, + bus_size_t, int); + +int _dmamem_alloc(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); +void _dmamem_free(bus_dma_tag_t, bus_dma_segment_t *, int); +int _dmamem_map(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); +void _dmamem_unmap(bus_dma_tag_t, caddr_t, size_t); +paddr_t _dmamem_mmap(bus_dma_tag_t, bus_dma_segment_t *, int, off_t, int, int); +int _dmamem_alloc_range(bus_dma_tag_t, bus_size_t, bus_size_t, bus_size_t, + bus_dma_segment_t *, int, int *, int, paddr_t, paddr_t); + +/* + * bus_dmamap_t + * + * Describes a DMA mapping. + */ +struct machine_bus_dmamap { + /* + * PRIVATE MEMBERS: not for use by machine-independent code. + */ + bus_size_t _dm_size; /* largest DMA transfer mappable */ + int _dm_segcnt; /* number of segs this map can map */ + bus_size_t _dm_maxsegsz; /* largest possible segment */ + bus_size_t _dm_boundary; /* don't cross this */ + int _dm_flags; /* misc. flags */ + + void *_dm_cookie; /* cookie for bus-specific functions */ + + /* + * PUBLIC MEMBERS: these are used by machine-independent code. + */ + bus_size_t dm_mapsize; /* size of the mapping */ + int dm_nsegs; /* # valid segments in mapping */ + bus_dma_segment_t dm_segs[1]; /* segments; variable length */ +}; + +int generic_space_map(bus_space_tag_t, bus_addr_t, bus_size_t, int, + bus_space_handle_t *); +void generic_space_unmap(bus_space_tag_t, bus_space_handle_t, bus_size_t); +int generic_space_region(bus_space_tag_t, bus_space_handle_t, bus_size_t, + bus_size_t, bus_space_handle_t *); +void *generic_space_vaddr(bus_space_tag_t, bus_space_handle_t); +paddr_t generic_space_mmap(bus_space_tag_t, bus_addr_t, off_t, int, int); +uint8_t generic_space_read_1(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint16_t generic_space_read_2(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint32_t generic_space_read_4(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint64_t generic_space_read_8(bus_space_tag_t, bus_space_handle_t, bus_size_t); +void generic_space_read_raw_2(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_1(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint8_t); +void generic_space_write_2(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint16_t); +void generic_space_write_4(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint32_t); +void generic_space_write_8(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint64_t); +void generic_space_write_raw_2(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); +void generic_space_read_raw_4(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_raw_4(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); +void generic_space_read_raw_8(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_raw_8(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); + +#endif /* _MACHINE_BUS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/cdefs.h b/lib/libc/include/riscv64-openbsd-none/machine/cdefs.h new file mode 100644 index 0000000000..951add3212 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/cdefs.h @@ -0,0 +1,16 @@ +/* $OpenBSD: cdefs.h,v 1.1 2021/04/23 02:42:16 drahn Exp $ */ + +#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_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/conf.h b/lib/libc/include/riscv64-openbsd-none/machine/conf.h new file mode 100644 index 0000000000..9dc1b949f2 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/conf.h @@ -0,0 +1,50 @@ +/* $OpenBSD: conf.h,v 1.4 2022/06/28 14:43:50 visa Exp $ */ + +/* + * Copyright (c) 1996 Christos Zoulas. 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 Christos Zoulas. + * 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 _MACHINE_CONF_H_ +#define _MACHINE_CONF_H_ + +#include + +#define mmread mmrw +#define mmwrite mmrw +cdev_decl(mm); + +/* open, close, ioctl */ +#define cdev_openprom_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) nullop, 0, \ + (dev_type_mmap((*))) enodev } + +cdev_decl(openprom); + +#endif /* _MACHINE_CONF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/cpu.h b/lib/libc/include/riscv64-openbsd-none/machine/cpu.h new file mode 100644 index 0000000000..8e6ecc4dca --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/cpu.h @@ -0,0 +1,284 @@ +/* $OpenBSD: cpu.h,v 1.24 2024/06/11 16:02:35 jca Exp $ */ + +/* + * Copyright (c) 2019 Mike Larkin + * Copyright (c) 2016 Dale Rahn + * + * 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_CPU_H_ +#define _MACHINE_CPU_H_ + +/* + * User-visible definitions + */ + +/* CTL_MACHDEP definitions. */ +#define CPU_COMPATIBLE 1 /* compatible property */ +#define CPU_MAXID 2 /* number of valid machdep ids */ + +#define CTL_MACHDEP_NAMES { \ + { 0, 0 }, \ + { "compatible", CTLTYPE_STRING }, \ +} + +#ifdef _KERNEL + +/* + * Kernel-only definitions + */ +#include +#include +#include + +/* All the CLKF_* macros take a struct clockframe * as an argument. */ + +#define clockframe trapframe +/* + * CLKF_USERMODE: Return TRUE/FALSE (1/0) depending on whether the + * frame came from USR mode or not. + */ +#define CLKF_USERMODE(frame) ((frame->tf_sstatus & SSTATUS_SPP) == 0) + +/* + * CLKF_INTR: True if we took the interrupt from inside another + * interrupt handler. + */ +#define CLKF_INTR(frame) (curcpu()->ci_idepth > 1) + +/* + * CLKF_PC: Extract the program counter from a clockframe + */ +#define CLKF_PC(frame) (frame->tf_sepc) + +/* + * PROC_PC: Find out the program counter for the given process. + */ +#define PROC_PC(p) ((p)->p_addr->u_pcb.pcb_tf->tf_sepc) +#define PROC_STACK(p) ((p)->p_addr->u_pcb.pcb_tf->tf_sp) + +#include +#include +#include +#include +#include + +struct cpu_info { + struct device *ci_dev; /* Device corresponding to this CPU */ + struct cpu_info *ci_next; + struct schedstate_percpu ci_schedstate; /* scheduler state */ + + u_int32_t ci_cpuid; + uint64_t ci_hartid; + int ci_node; + struct cpu_info *ci_self; + + struct proc *ci_curproc; + struct pmap *ci_curpm; + u_int32_t ci_randseed; + + struct pcb *ci_curpcb; + struct pcb *ci_idle_pcb; + + struct clockqueue ci_queue; + volatile int ci_timer_deferred; + + uint32_t ci_cpl; + uint32_t ci_ipending; + uint32_t ci_idepth; +#ifdef DIAGNOSTIC + int ci_mutex_level; +#endif + int ci_want_resched; + + struct opp_table *ci_opp_table; + volatile int ci_opp_idx; + volatile int ci_opp_max; + uint32_t ci_cpu_supply; + +#ifdef MULTIPROCESSOR + struct srp_hazard ci_srp_hazards[SRP_HAZARD_NUM]; +#define __HAVE_UVM_PERCPU + struct uvm_pmr_cache ci_uvm; + volatile int ci_flags; + uint64_t ci_satp; + vaddr_t ci_initstack_end; + int ci_ipi_reason; + + volatile int ci_ddb_paused; +#define CI_DDB_RUNNING 0 +#define CI_DDB_SHOULDSTOP 1 +#define CI_DDB_STOPPED 2 +#define CI_DDB_ENTERDDB 3 +#define CI_DDB_INDDB 4 + +#endif + +#ifdef GPROF + struct gmonparam *ci_gmon; + struct clockintr ci_gmonclock; +#endif + + char ci_panicbuf[512]; +}; + +#define CPUF_PRIMARY (1<<0) +#define CPUF_AP (1<<1) +#define CPUF_IDENTIFY (1<<2) +#define CPUF_IDENTIFIED (1<<3) +#define CPUF_PRESENT (1<<4) +#define CPUF_GO (1<<5) +#define CPUF_RUNNING (1<<6) + +static inline struct cpu_info * +curcpu(void) +{ + struct cpu_info *__ci = NULL; + __asm volatile("mv %0, tp" : "=&r"(__ci)); + return (__ci); +} + +extern uint32_t boot_hart; /* The hart we booted on. */ +extern struct cpu_info cpu_info_primary; +extern struct cpu_info *cpu_info_list; + +#ifndef MULTIPROCESSOR + +#define cpu_number() 0 +#define CPU_IS_PRIMARY(ci) 1 +#define CPU_IS_RUNNING(ci) 1 +#define CPU_INFO_ITERATOR int +#define CPU_INFO_FOREACH(cii, ci) \ + for (cii = 0, ci = curcpu(); ci != NULL; ci = NULL) +#define CPU_INFO_UNIT(ci) 0 +#define MAXCPUS 1 +#define cpu_unidle(ci) + +#else + +#define cpu_number() (curcpu()->ci_cpuid) +#define CPU_IS_PRIMARY(ci) ((ci) == &cpu_info_primary) +#define CPU_IS_RUNNING(ci) ((ci)->ci_flags & CPUF_RUNNING) +#define CPU_INFO_ITERATOR int +#define CPU_INFO_FOREACH(cii, ci) for (cii = 0, ci = cpu_info_list; \ + ci != NULL; ci = ci->ci_next) +#define CPU_INFO_UNIT(ci) ((ci)->ci_dev ? (ci)->ci_dev->dv_unit : 0) +#define MAXCPUS 32 + +extern struct cpu_info *cpu_info[MAXCPUS]; + +void cpu_boot_secondary_processors(void); + +#endif /* !MULTIPROCESSOR */ + +/* Zihintpause ratified extension */ +#define CPU_BUSY_CYCLE() __asm volatile(".long 0x0100000f" ::: "memory") + +#define curpcb curcpu()->ci_curpcb + +static inline unsigned int +cpu_rnd_messybits(void) +{ + // Should do bit reversal ^ with csr_read(time); + return csr_read(time); +} + +/* + * Scheduling glue + */ +#define aston(p) ((p)->p_md.md_astpending = 1) +#define setsoftast() aston(curcpu()->ci_curproc) + +/* + * Notify the current process (p) that it has a signal pending, + * process as soon as possible. + */ + +#ifdef MULTIPROCESSOR +void cpu_unidle(struct cpu_info *ci); +#define signotify(p) (aston(p), cpu_unidle((p)->p_cpu)) +void cpu_kick(struct cpu_info *); +#else +#define cpu_kick(ci) +#define cpu_unidle(ci) +#define signotify(p) setsoftast() +#endif + +/* + * Preempt the current process if in interrupt from user mode, + * or after the current trap/syscall if in system mode. + */ +void need_resched(struct cpu_info *); +#define clear_resched(ci) ((ci)->ci_want_resched = 0) + +/* + * Give a profiling tick to the current process when the user profiling + * buffer pages are invalid. On the i386, request an ast to send us + * through trap(), marking the proc as needing a profiling tick. + */ +#define need_proftick(p) aston(p) + +// asm code to start new kernel contexts. +void proc_trampoline(void); + +/* + * Random cruft + */ +void dumpconf(void); + +static inline void +intr_enable(void) +{ + __asm volatile("csrsi sstatus, %0" :: "i" (SSTATUS_SIE)); +} + +static inline u_long +intr_disable(void) +{ + uint64_t ret; + + __asm volatile( + "csrrci %0, sstatus, %1" + : "=&r" (ret) : "i" (SSTATUS_SIE) + ); + + return (ret & (SSTATUS_SIE)); +} + +static inline void +intr_restore(u_long s) +{ + __asm volatile("csrs sstatus, %0" :: "r" (s)); +} + +void delay (unsigned); +#define DELAY(x) delay(x) + +extern void (*cpu_startclock_fcn)(void); + +void fpu_save(struct proc *, struct trapframe *); +void fpu_load(struct proc *); + +extern int cpu_errata_sifive_cip_1200; + +#define cpu_idle_enter() do { /* nothing */ } while (0) +#define cpu_idle_leave() do { /* nothing */ } while (0) + +#endif /* _KERNEL */ + +#ifdef MULTIPROCESSOR +#include +#endif /* MULTIPROCESSOR */ + +#endif /* !_MACHINE_CPU_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/cpufunc.h b/lib/libc/include/riscv64-openbsd-none/machine/cpufunc.h new file mode 100644 index 0000000000..f4b61288bb --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/cpufunc.h @@ -0,0 +1,103 @@ +/* $OpenBSD: cpufunc.h,v 1.6 2023/08/21 20:17:30 miod Exp $ */ + +/*- + * Copyright (c) 2014 Andrew Turner + * 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 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 AUTHOR 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. + * + * $FreeBSD: head/sys/cpu/include/cpufunc.h 299683 2016-05-13 16:03:50Z andrew $ + */ + +#ifndef _MACHINE_CPUFUNC_H_ +#define _MACHINE_CPUFUNC_H_ + +static __inline void +breakpoint(void) +{ + __asm("ebreak"); +} + +#ifdef _KERNEL + +#include + +#define rdcycle() csr_read(cycle) +#define rdtime() csr_read(time) +#define rdinstret() csr_read(instret) +#define rdhpmcounter(n) csr_read(hpmcounter##n) + +static __inline void +fence_i(void) +{ + __asm volatile("fence.i" ::: "memory"); +} + +static __inline void +sfence_vma(void) +{ + __asm volatile("sfence.vma" ::: "memory"); +} + +static __inline void +sfence_vma_page(uintptr_t addr) +{ + __asm volatile("sfence.vma %0" + : + : "r" (addr) + : "memory"); +} + +// XXX ASIDs in riscv64 are only 16 bits. +static __inline void +sfence_vma_asid(uint64_t asid) +{ + __asm volatile("sfence.vma x0, %0" + : + : "r" (asid) + : "memory"); +} + +static __inline void +sfence_vma_page_asid(uintptr_t addr, uint64_t asid) +{ + __asm volatile("sfence.vma %0, %1" + : + : "r" (addr), "r" (asid) + : "memory"); +} + +extern int64_t dcache_line_size; +extern int64_t icache_line_size; + +extern void (*cpu_dcache_wbinv_range)(paddr_t, psize_t); +extern void (*cpu_dcache_inv_range)(paddr_t, psize_t); +extern void (*cpu_dcache_wb_range)(paddr_t, psize_t); + +static __inline void +load_satp(uint64_t val) +{ + __asm volatile("csrw satp, %0" :: "r"(val)); +} + +#endif /* _KERNEL */ +#endif /* _MACHINE_CPUFUNC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/db_machdep.h b/lib/libc/include/riscv64-openbsd-none/machine/db_machdep.h new file mode 100644 index 0000000000..0d0e4fdfb9 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/db_machdep.h @@ -0,0 +1,93 @@ +/* $OpenBSD: db_machdep.h,v 1.5 2021/08/30 08:11:12 jasper Exp $ */ + +/* + * Copyright (c) 2019 Brian Bamsch + * Copyright (c) 2015-2016 Ruslan Bukin + * All rights reserved. + * + * Portions of this software were developed by SRI International and the + * University of Cambridge Computer Laboratory under DARPA/AFRL contract + * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. + * + * Portions of this software were developed by the University of Cambridge + * Computer Laboratory as part of the CTSRD Project, with support from the + * UK Higher Education Innovation Fund (HEIF). + * + * 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 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 AUTHOR 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. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_DB_MACHDEP_H_ +#define _MACHINE_DB_MACHDEP_H_ + +#include +#include +#include +#include +#include + +#define T_BREAKPOINT (EXCP_BREAKPOINT) +#define T_WATCHPOINT (0) + +typedef long db_expr_t; + +typedef trapframe_t db_regs_t; + +extern db_regs_t ddb_regs; +#define DDB_REGS (&ddb_regs) + +#define PC_REGS(regs) ((vaddr_t)(regs)->tf_ra) +#define SET_PC_REGS(regs, value) (regs)->tf_ra = (register_t)(value) + +#define BKPT_INST (KERNEL_BREAKPOINT) +#define BKPT_SIZE (INSN_SIZE) +#define BKPT_SET(inst) (BKPT_INST) + +#define IS_BREAKPOINT_TRAP(type, code) ((type) == T_BREAKPOINT) +#define IS_WATCHPOINT_TRAP(type, code) ((type) == T_WATCHPOINT) + +#define inst_trap_return(ins) (ins == 0x10000073) /* eret */ +#define inst_return(ins) (ins == 0x00008067) /* ret */ +#define inst_call(ins) (((ins) & 0x7f) == 0x6f || \ + ((ins) & 0x7f) == 0x67) /* jal, jalr */ +#define inst_branch(ins) (((ins) & 0x7f) == 0x63) /* branch */ + +#define next_instr_address(pc, bd) ((bd) ? (pc) : ((pc) + INSN_SIZE)) + +#define DB_MACHINE_COMMANDS + +#define SOFTWARE_SSTEP + +int db_trapper(vaddr_t, u_int, trapframe_t *, int); +void db_machine_init (void); +vaddr_t db_branch_taken(u_int inst, vaddr_t pc, db_regs_t *regs); + +#define branch_taken(ins, pc, fun, regs) \ + db_branch_taken((ins), (pc), (regs)) + +/* For ddb_state */ +#define DDB_STATE_NOT_RUNNING 0 +#define DDB_STATE_RUNNING 1 +#define DDB_STATE_EXITING 2 + +#endif /* !_MACHINE_DB_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/disklabel.h b/lib/libc/include/riscv64-openbsd-none/machine/disklabel.h new file mode 100644 index 0000000000..fcb739943e --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/disklabel.h @@ -0,0 +1,26 @@ +/* $OpenBSD: disklabel.h,v 1.2 2021/05/12 01:20:52 jsg Exp $ */ + +/* + * Copyright (c) 2014 Patrick Wildt + * + * 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_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/elf.h b/lib/libc/include/riscv64-openbsd-none/machine/elf.h new file mode 100644 index 0000000000..651c966fb8 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/elf.h @@ -0,0 +1,52 @@ +/* $OpenBSD: elf.h,v 1.3 2024/07/14 09:48:49 jca Exp $ */ + +/*- + * Copyright (c) 1996-1997 John D. Polstra. + * 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 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 AUTHOR 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_ELF_H_ +#define _MACHINE_ELF_H_ + +/* + * ELF definitions for the RISC-V architecture. + */ + +#ifdef _KERNEL +# define __HAVE_CPU_HWCAP +extern unsigned long hwcap; +#endif /* _KERNEL */ + +/* Flags passed in AT_HWCAP */ +#define HWCAP_ISA_BIT(c) (1 << ((c) - 'a')) +#define HWCAP_ISA_I HWCAP_ISA_BIT('i') +#define HWCAP_ISA_M HWCAP_ISA_BIT('m') +#define HWCAP_ISA_A HWCAP_ISA_BIT('a') +#define HWCAP_ISA_F HWCAP_ISA_BIT('f') +#define HWCAP_ISA_D HWCAP_ISA_BIT('d') +#define HWCAP_ISA_C HWCAP_ISA_BIT('c') +#define HWCAP_ISA_G \ + (HWCAP_ISA_I | HWCAP_ISA_M | HWCAP_ISA_A | HWCAP_ISA_F | HWCAP_ISA_D) + +#endif /* !_MACHINE_ELF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/endian.h b/lib/libc/include/riscv64-openbsd-none/machine/endian.h new file mode 100644 index 0000000000..b63c54e850 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/endian.h @@ -0,0 +1,29 @@ +/* $OpenBSD: endian.h,v 1.3 2022/03/22 06:46:45 miod Exp $ */ + +/* + * Copyright (c) 2015 David Gwynne + * + * 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_ENDIAN_H_ +#define _MACHINE_ENDIAN_H_ + +#define _BYTE_ORDER _LITTLE_ENDIAN +#define __STRICT_ALIGNMENT + +#ifndef __FROM_SYS__ENDIAN +#include +#endif + +#endif /* _MACHINE_ENDIAN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/exec.h b/lib/libc/include/riscv64-openbsd-none/machine/exec.h new file mode 100644 index 0000000000..a6073819af --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/exec.h @@ -0,0 +1,30 @@ +/* $OpenBSD: exec.h,v 1.2 2021/05/12 01:20:52 jsg Exp $ */ + +/* + * Copyright (c) 2014 Patrick Wildt + * + * 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_RISCV + +#endif \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/fdt.h b/lib/libc/include/riscv64-openbsd-none/machine/fdt.h new file mode 100644 index 0000000000..536ed4d04b --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/fdt.h @@ -0,0 +1,59 @@ +/* $OpenBSD: fdt.h,v 1.4 2022/05/30 17:39:09 kettenis Exp $ */ + +/* + * Copyright (c) 2016 Patrick Wildt + * + * 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 __RISCV_FDT_H__ +#define __RISCV_FDT_H__ + +#define _RISCV64_BUS_DMA_PRIVATE +#include + +struct fdt_attach_args { + const char *fa_name; + int fa_node; + bus_space_tag_t fa_iot; + bus_dma_tag_t fa_dmat; + struct fdt_reg *fa_reg; + int fa_nreg; + uint32_t *fa_intr; + int fa_nintr; + int fa_acells; + int fa_scells; +}; + +extern int stdout_node; +extern int stdout_speed; +extern bus_space_tag_t fdt_cons_bs_tag; + +void *fdt_find_cons(const char *); + +#define fdt_intr_enable riscv_intr_enable +#define fdt_intr_establish riscv_intr_establish_fdt +#define fdt_intr_establish_idx riscv_intr_establish_fdt_idx +#define fdt_intr_establish_idx_cpu riscv_intr_establish_fdt_idx_cpu +#define fdt_intr_establish_imap riscv_intr_establish_fdt_imap +#define fdt_intr_establish_imap_cpu riscv_intr_establish_fdt_imap_cpu +#define fdt_intr_establish_msi riscv_intr_establish_fdt_msi +#define fdt_intr_establish_msi_cpu riscv_intr_establish_fdt_msi_cpu +#define fdt_intr_disable riscv_intr_disable +#define fdt_intr_disestablish riscv_intr_disestablish_fdt +#define fdt_intr_get_parent riscv_intr_get_parent +#define fdt_intr_parent_establish riscv_intr_parent_establish_fdt +#define fdt_intr_parent_disestablish riscv_intr_parent_disestablish_fdt +#define fdt_intr_register riscv_intr_register_fdt + +#endif /* __RISCV_FDT_H__ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/fenv.h b/lib/libc/include/riscv64-openbsd-none/machine/fenv.h new file mode 100644 index 0000000000..e1645e961c --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/fenv.h @@ -0,0 +1,95 @@ +/* $OpenBSD: fenv.h,v 1.2 2021/05/12 02:28:25 jsg Exp $ */ + +/* + * Copyright (c) 2011 Martynas Venckus + * + * 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_FENV_H_ +#define _MACHINE_FENV_H_ + +/* + * Each symbol representing a floating point exception expands to an integer + * constant expression with values, such that bitwise-inclusive ORs of _all + * combinations_ of the constants result in distinct values. + * + * We use such values that allow direct bitwise operations on FPU registers. + */ +#define FE_INVALID 0x10 +#define FE_DIVBYZERO 0x08 +#define FE_OVERFLOW 0x04 +#define FE_UNDERFLOW 0x02 +#define FE_INEXACT 0x01 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * exception constants defined above. + */ +#define FE_ALL_EXCEPT (FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | \ + FE_UNDERFLOW | FE_INEXACT ) + +/* + * Each symbol representing the rounding direction, expands to an integer + * constant expression whose value is distinct non-negative value. + * + * We use such values that allow direct bitwise operations on FPU registers. + */ +#define FE_TONEAREST 0x0 +#define FE_TOWARDZERO 0x1 +#define FE_DOWNWARD 0x2 +#define FE_UPWARD 0x3 +#define FE_TONEARESTFROMZERO 0x4 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * rounding direction constants defined above. + */ +#define _ROUND_MASK (FE_TONEAREST | FE_TOWARDZERO | FE_DOWNWARD | \ + FE_UPWARD | FE_TONEARESTFROMZERO) +#define _ROUND_SHIFT 5 + +/* + * fenv_t represents the entire floating-point environment. + */ +typedef unsigned int fenv_t; + +/* + * The following constant represents the default floating-point environment + * (that is, the one installed at program startup) and has type pointer to + * const-qualified fenv_t. + * + * It can be used as an argument to the functions within the header + * that manage the floating-point environment, namely fesetenv() and + * feupdateenv(). + */ +__BEGIN_DECLS +extern fenv_t __fe_dfl_env; +__END_DECLS +#define FE_DFL_ENV ((const fenv_t *)&__fe_dfl_env) + +/* + * fexcept_t represents the floating-point status flags collectively, including + * any status the implementation associates with the flags. + * + * A floating-point status flag is a system variable whose value is set (but + * never cleared) when a floating-point exception is raised, which occurs as a + * side effect of exceptional floating-point arithmetic to provide auxiliary + * information. + * + * A floating-point control mode is a system variable whose value may be set by + * the user to affect the subsequent behavior of floating-point arithmetic. + */ +typedef unsigned int fexcept_t; + +#endif /* !_MACHINE_FENV_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/frame.h b/lib/libc/include/riscv64-openbsd-none/machine/frame.h new file mode 100644 index 0000000000..e15698128f --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/frame.h @@ -0,0 +1,99 @@ +/* $OpenBSD: frame.h,v 1.3 2022/02/24 14:19:10 visa Exp $ */ + +/* + * Copyright (c) 2019 Brian Bamsch + * Copyright (c) 2016 Dale Rahn + * Copyright (c) 2015 Ruslan Bukin + * All rights reserved. + * + * Portions of this software were developed by SRI International and the + * University of Cambridge Computer Laboratory under DARPA/AFRL contract + * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. + * + * Portions of this software were developed by the University of Cambridge + * Computer Laboratory as part of the CTSRD Project, with support from the + * UK Higher Education Innovation Fund (HEIF). + * + * 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 copyright holder 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 AUTHOR 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 AUTHOR 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_FRAME_H_ +#define _MACHINE_FRAME_H_ + +#ifndef _LOCORE + +#include + +/* + * Exception/Trap Stack Frame + */ +#define clockframe trapframe +typedef struct trapframe { + /* Standard Registers */ + register_t tf_ra; + register_t tf_sp; + register_t tf_gp; + register_t tf_tp; + register_t tf_t[7]; + register_t tf_s[12]; + register_t tf_a[8]; + /* Supervisor Trap CSRs */ + register_t tf_sepc; + register_t tf_sstatus; + register_t tf_stval; + register_t tf_scause; + register_t tf_pad; +} trapframe_t; + +/* + * pushed on stack for signal delivery + */ +struct sigframe { + int sf_signum; + struct sigcontext sf_sc; + siginfo_t sf_si; +}; + +/* + * System stack frames. + */ + +/* + * Stack frame inside cpu_switch() + */ +struct switchframe { + register_t sf_s[12]; + register_t sf_ra; + register_t sf_pad; +}; + +struct callframe { + struct callframe *f_frame; + register_t f_ra; +}; + +#endif /* !_LOCORE */ + +#endif /* !_MACHINE_FRAME_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/ieee.h b/lib/libc/include/riscv64-openbsd-none/machine/ieee.h new file mode 100644 index 0000000000..74d6e987a9 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/ieee.h @@ -0,0 +1,148 @@ +/* $OpenBSD: ieee.h,v 1.3 2021/05/12 01:20:52 jsg Exp $ */ +/* $NetBSD: ieee.h,v 1.1 1996/09/30 16:34:25 ws Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)ieee.h 8.1 (Berkeley) 6/11/93 + */ + +/* + * ieee.h defines the machine-dependent layout of the machine's IEEE + * floating point. It does *not* define (yet?) any of the rounding + * mode bits, exceptions, and so forth. + */ + +/* + * Define the number of bits in each fraction and exponent. + * + * k k+1 + * Note that 1.0 x 2 == 0.1 x 2 and that denorms are represented + * + * (-exp_bias+1) + * as fractions that look like 0.fffff x 2 . This means that + * + * -126 + * the number 0.10000 x 2 , for instance, is the same as the normalized + * + * -127 -128 + * float 1.0 x 2 . Thus, to represent 2 , we need one leading zero + * + * -129 + * in the fraction; to represent 2 , we need two, and so on. This + * + * (-exp_bias-fracbits+1) + * implies that the smallest denormalized number is 2 + * + * for whichever format we are talking about: for single precision, for + * + * -126 -149 + * instance, we get .00000000000000000000001 x 2 , or 1.0 x 2 , and + * + * -149 == -127 - 23 + 1. + */ +#define SNG_EXPBITS 8 +#define SNG_FRACBITS 23 + +#define DBL_EXPBITS 11 +#define DBL_FRACHBITS 20 +#define DBL_FRACLBITS 32 +#define DBL_FRACBITS 52 + +#define EXT_EXPBITS 15 +#define EXT_FRACHBITS 16 +#define EXT_FRACHMBITS 32 +#define EXT_FRACLMBITS 32 +#define EXT_FRACLBITS 32 +#define EXT_FRACBITS 112 + +#define EXT_IMPLICIT_NBIT + +#define EXT_TO_ARRAY32(p, a) do { \ + (a)[0] = (uint32_t)(p)->ext_fracl; \ + (a)[1] = (uint32_t)(p)->ext_fraclm; \ + (a)[2] = (uint32_t)(p)->ext_frachm; \ + (a)[3] = (uint32_t)(p)->ext_frach; \ +} while (0) + +struct ieee_single { + u_int sng_frac:23; + u_int sng_exp:8; + u_int sng_sign:1; +}; + +struct ieee_double { + u_int dbl_fracl; + u_int dbl_frach:20; + u_int dbl_exp:11; + u_int dbl_sign:1; +}; + +struct ieee_ext { + u_int ext_fracl; + u_int ext_fraclm; + u_int ext_frachm; + u_int ext_frach:16; + u_int ext_exp:15; + u_int ext_sign:1; +}; + +/* + * Floats whose exponent is in [1..INFNAN) (of whatever type) are + * `normal'. Floats whose exponent is INFNAN are either Inf or NaN. + * Floats whose exponent is zero are either zero (iff all fraction + * bits are zero) or subnormal values. + * + * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its + * high fraction; if the bit is set, it is a `quiet NaN'. + */ +#define SNG_EXP_INFNAN 255 +#define DBL_EXP_INFNAN 2047 +#define EXT_EXP_INFNAN 32767 + +#if 0 +#define SNG_QUIETNAN (1 << 22) +#define DBL_QUIETNAN (1 << 19) +#define EXT_QUIETNAN (1 << 15) +#endif + +/* + * Exponent biases. + */ +#define SNG_EXP_BIAS 127 +#define DBL_EXP_BIAS 1023 +#define EXT_EXP_BIAS 16383 \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/ieeefp.h b/lib/libc/include/riscv64-openbsd-none/machine/ieeefp.h new file mode 100644 index 0000000000..e8f7507588 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/ieeefp.h @@ -0,0 +1,25 @@ +/* $OpenBSD: ieeefp.h,v 1.3 2021/04/30 00:25:52 drahn Exp $ */ + +/* + * Based on ieeefp.h written by J.T. Conklin, Apr 28, 1995 + * Public domain. + */ + +#ifndef _MACHINE_IEEEFP_H_ +#define _MACHINE_IEEEFP_H_ + +typedef int fp_except; +#define FP_X_INV 0x10 /* invalid operation exception */ +#define FP_X_DZ 0x08 /* divide-by-zero exception */ +#define FP_X_OFL 0x04 /* overflow exception */ +#define FP_X_UFL 0x02 /* underflow exception */ +#define FP_X_IMP 0x01 /* imprecise (loss of precision) */ + +typedef enum { + FP_RN=0, /* round to nearest representable number */ + FP_RZ=1, /* round to zero (truncate) */ + FP_RM=2, /* round toward negative infinity */ + FP_RP=3 /* round toward positive infinity */ +} fp_rnd; + +#endif /* _MACHINE_IEEEFP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/intr.h b/lib/libc/include/riscv64-openbsd-none/machine/intr.h new file mode 100644 index 0000000000..14ef73c213 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/intr.h @@ -0,0 +1,227 @@ +/* $OpenBSD: intr.h,v 1.10 2025/05/19 02:13:15 jsg Exp $ */ + +/* + * Copyright (c) 2001-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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_INTR_H_ +#define _MACHINE_INTR_H_ + +/* + * The interrupt level ipl is a logical level; per-platform interrupt + * code will turn it into the appropriate hardware interrupt masks + * values. + * + * Interrupt sources on the CPU are kept enabled regardless of the + * current ipl value; individual hardware sources interrupting while + * logically masked are masked on the fly, remembered as pending, and + * unmasked at the first splx() opportunity. + */ +#ifdef _KERNEL + +/* Interrupt priority `levels'; not mutually exclusive. */ +#define IPL_NONE 0 /* nothing */ +#define IPL_SOFTCLOCK 2 /* soft clock interrupts */ +#define IPL_SOFTNET 3 /* soft network interrupts */ +#define IPL_SOFTTTY 4 /* soft terminal interrupts */ +#define IPL_BIO 5 /* block I/O */ +#define IPL_NET 6 /* network */ +#define IPL_TTY 7 /* terminal */ +#define IPL_VM 8 /* memory allocation */ +#define IPL_AUDIO 9 /* audio */ +#define IPL_CLOCK 10 /* clock */ +#define IPL_SCHED IPL_CLOCK +#define IPL_STATCLOCK IPL_CLOCK +#define IPL_HIGH 11 /* everything */ +#define IPL_IPI 12 /* interprocessor interrupt */ +#define NIPL 13 /* number of levels */ + +#define IPL_MPFLOOR IPL_TTY +/* Interrupt priority 'flags'. */ +#define IPL_IRQMASK 0xf /* priority only */ +#define IPL_FLAGMASK 0xf00 /* flags only*/ +#define IPL_MPSAFE 0x100 /* 'mpsafe' interrupt, no kernel lock */ + +/* Interrupt sharing types. */ +#define IST_NONE 0 /* none */ +#define IST_PULSE 1 /* pulsed */ +#define IST_EDGE 2 /* edge-triggered */ +#define IST_LEVEL 3 /* level-triggered */ + +#define IST_LEVEL_LOW IST_LEVEL +#define IST_LEVEL_HIGH 4 +#define IST_EDGE_FALLING IST_EDGE +#define IST_EDGE_RISING 5 +#define IST_EDGE_BOTH 6 + +enum { + IRQ_SOFTWARE_USER, + IRQ_SOFTWARE_SUPERVISOR, + IRQ_SOFTWARE_HYPERVISOR, + IRQ_SOFTWARE_MACHINE, + IRQ_TIMER_USER, + IRQ_TIMER_SUPERVISOR, + IRQ_TIMER_HYPERVISOR, + IRQ_TIMER_MACHINE, + IRQ_EXTERNAL_USER, + IRQ_EXTERNAL_SUPERVISOR, + IRQ_EXTERNAL_HYPERVISOR, + IRQ_EXTERNAL_MACHINE, + INTC_NIRQS +}; + +#define __USE_MI_SOFTINTR + +#include + +#ifndef _LOCORE +#include + +void softintr(int); + +int splraise(int); +int spllower(int); +void splx(int); + +void riscv_cpu_intr(void *); +void riscv_do_pending_intr(int); +void riscv_set_intr_func(int (*raise)(int), int (*lower)(int), + void (*x)(int), void (*setipl)(int)); +void riscv_set_intr_handler(void (*intr_handle)(void *)); + +struct machine_intr_handle { + struct interrupt_controller *ih_ic; + void *ih_ih; +}; + +struct riscv_intr_func { + int (*raise)(int); + int (*lower)(int); + void (*x)(int); + void (*setipl)(int); +}; + +extern struct riscv_intr_func riscv_intr_func; + +#define splraise(cpl) (riscv_intr_func.raise(cpl)) +#define _splraise(cpl) (riscv_intr_func.raise(cpl)) +#define spllower(cpl) (riscv_intr_func.lower(cpl)) +#define splx(cpl) (riscv_intr_func.x(cpl)) + +#define splsoftclock() splraise(IPL_SOFTCLOCK) +#define splsoftnet() splraise(IPL_SOFTNET) +#define splsofttty() splraise(IPL_SOFTTTY) +#define splbio() splraise(IPL_BIO) +#define splnet() splraise(IPL_NET) +#define spltty() splraise(IPL_TTY) +#define splvm() splraise(IPL_VM) +#define splaudio() splraise(IPL_AUDIO) +#define splclock() splraise(IPL_CLOCK) +#define splsched() splraise(IPL_SCHED) +#define splstatclock() splraise(IPL_STATCLOCK) +#define splhigh() splraise(IPL_HIGH) + +#define spl0() spllower(IPL_NONE) + +void intr_barrier(void *); + +void riscv_init_smask(void); /* XXX */ +extern uint32_t riscv_smask[NIPL]; + +void riscv_clock_register(void (*)(void), void (*)(u_int), void (*)(int), + void (*)(void)); + +/* + **** interrupt controller structure and routines **** + */ +struct cpu_info; +struct interrupt_controller { + int ic_node; + void *ic_cookie; + void *(*ic_establish)(void *, int *, int, struct cpu_info *, + int (*)(void *), void *, char *); + void *(*ic_establish_msi)(void *, uint64_t *, uint64_t *, int, + struct cpu_info *, int (*)(void *), void *, char *); + void (*ic_disestablish)(void *); + void (*ic_enable)(void *); + void (*ic_disable)(void *); + void (*ic_route)(void *, int, struct cpu_info *); + void (*ic_cpu_enable)(void); + void (*ic_barrier)(void *); + + LIST_ENTRY(interrupt_controller) ic_list; + uint32_t ic_phandle; + uint32_t ic_cells; +}; + +void riscv_intr_init_fdt(void); +void riscv_intr_register_fdt(struct interrupt_controller *); +void *riscv_intr_establish_fdt(int, int, int (*)(void *), + void *, char *); +void *riscv_intr_establish_fdt_idx(int, int, int, int (*)(void *), + void *, char *); +void *riscv_intr_establish_fdt_idx_cpu(int, int, int, struct cpu_info *, + int (*)(void *), void *, char *); +void *riscv_intr_establish_fdt_imap_cpu(int, int *, int, int, + struct cpu_info *, int (*)(void *), void *, char *); +void *riscv_intr_establish_fdt_msi(int, uint64_t *, uint64_t *, int, + int (*)(void *), void *, char *); +void *riscv_intr_establish_fdt_msi_cpu(int, uint64_t *, uint64_t *, int, + struct cpu_info *, int (*)(void *), void *, char *); +void riscv_intr_disestablish_fdt(void *); +void riscv_intr_enable(void *); +void riscv_intr_disable(void *); +void riscv_intr_route(void *, int, struct cpu_info *); +void riscv_intr_cpu_enable(void); + +#define IPI_NOP 0 +#define IPI_DDB (1 << 0) + +void intr_send_ipi(struct cpu_info *, int); + +#ifdef DIAGNOSTIC +/* + * Although this function is implemented in MI code, it must be in this MD + * header because we don't want this header to include MI includes. + */ +void splassert_fail(int, int, const char *); +extern int splassert_ctl; +void riscv_splassert_check(int, const char *); +#define splassert(__wantipl) do { \ + if (splassert_ctl > 0) { \ + riscv_splassert_check(__wantipl, __func__); \ + } \ +} while (0) +#define splsoftassert(wantipl) splassert(wantipl) +#else +#define splassert(wantipl) do { /* nothing */ } while (0) +#define splsoftassert(wantipl) do { /* nothing */ } while (0) +#endif + +#endif /* ! _LOCORE */ + +#endif /* _KERNEL */ + +#endif /* _MACHINE_INTR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/kcore.h b/lib/libc/include/riscv64-openbsd-none/machine/kcore.h new file mode 100644 index 0000000000..484ee5d0ee --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/kcore.h @@ -0,0 +1,16 @@ +/* $OpenBSD: kcore.h,v 1.2 2021/05/12 01:20:52 jsg Exp $ */ + +/* public domain */ + +/* Make sure this is larger than DRAM_BLOCKS on all arm-based platforms */ +#define NPHYS_RAM_SEGS 8 + +typedef struct cpu_kcore_hdr { + u_int64_t kernelbase; /* value of KERNEL_BASE */ + u_int64_t kerneloffs; /* offset of kernel in RAM */ + u_int64_t staticsize; /* size of contiguous mapping */ + u_int64_t pmap_kernel_l1; /* pmap_kernel()->pm_l1 */ + u_int64_t pmap_kernel_l2; /* pmap_kernel()->pm_l2 */ + u_int64_t reserved[11]; + phys_ram_seg_t ram_segs[NPHYS_RAM_SEGS]; +} cpu_kcore_hdr_t; \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/limits.h b/lib/libc/include/riscv64-openbsd-none/machine/limits.h new file mode 100644 index 0000000000..e06dde0b2b --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/limits.h @@ -0,0 +1,56 @@ +/* $OpenBSD: limits.h,v 1.2 2021/06/25 19:22:51 matthieu Exp $ */ +/* $NetBSD: limits.h,v 1.4 2003/04/28 23:16:18 bjh21 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 + +#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 (ULONG_MAX) /* max unsigned quad */ +#define QUAD_MAX (LONG_MAX) /* max signed quad */ +#define QUAD_MIN (LONG_MIN) /* min signed quad */ + +#endif /* __BSD_VISIBLE */ + +#endif /* _MACHINE_LIMITS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/loadfile_machdep.h b/lib/libc/include/riscv64-openbsd-none/machine/loadfile_machdep.h new file mode 100644 index 0000000000..c6b1f00082 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/loadfile_machdep.h @@ -0,0 +1,53 @@ +/* $OpenBSD: loadfile_machdep.h,v 1.2 2021/04/23 15:31:12 drahn Exp $ */ +/* $NetBSD: loadfile_machdep.h,v 1.1 1999/04/29 03:17:12 tsubai Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * 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. + */ + +#define BOOT_ELF +#define ELFSIZE 64 + +#define LOAD_KERNEL (LOAD_ALL & ~LOAD_TEXTA) +#define COUNT_KERNEL (COUNT_ALL & ~COUNT_TEXTA) + +extern u_long efi_loadaddr; +#define LOADADDR(a) (((((u_long)(a)) + offset)&0x3fffffffff) + \ + efi_loadaddr) +#define ALIGNENTRY(a) ((u_long)(a)) +#define READ(f, b, c) read((f), (void *)LOADADDR(b), (c)) +#define BCOPY(s, d, c) memcpy((void *)LOADADDR(d), (void *)(s), (c)) +#define BZERO(d, c) memset((void *)LOADADDR(d), 0, (c)) +#define WARN(a) (void)(printf a, \ + printf((errno ? ": %s\n" : "\n"), \ + strerror(errno))) +#define PROGRESS(a) (void) printf a +#define ALLOC(a) alloc(a) +#define FREE(a, b) free(a, b) + +void run_loadfile(uint64_t *, int); \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/mplock.h b/lib/libc/include/riscv64-openbsd-none/machine/mplock.h new file mode 100644 index 0000000000..1a87e05398 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/mplock.h @@ -0,0 +1,10 @@ +/* $OpenBSD: mplock.h,v 1.1 2021/06/27 20:36:57 kettenis Exp $ */ + +/* public domain */ + +#ifndef _MACHINE_MPLOCK_H_ +#define _MACHINE_MPLOCK_H_ + +#define __USE_MI_MPLOCK + +#endif /* !_MACHINE_MPLOCK_H */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/mutex.h b/lib/libc/include/riscv64-openbsd-none/machine/mutex.h new file mode 100644 index 0000000000..bc6b8cbb83 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/mutex.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mutex.h,v 1.1 2021/04/23 02:42:16 drahn Exp $ */ + +#define __USE_MI_MUTEX \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/openpromio.h b/lib/libc/include/riscv64-openbsd-none/machine/openpromio.h new file mode 100644 index 0000000000..4f49bf5934 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/openpromio.h @@ -0,0 +1,57 @@ +/* $OpenBSD: openpromio.h,v 1.1 2021/04/23 12:01:03 jsg Exp $ */ +/* $NetBSD: openpromio.h,v 1.1.1.1 1998/06/20 04:58:52 eeh Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)openpromio.h 8.1 (Berkeley) 6/11/93 + */ + +struct opiocdesc { + int op_nodeid; /* passed or returned node id */ + int op_namelen; /* length of op_name */ + char *op_name; /* pointer to field name */ + int op_buflen; /* length of op_buf (value-result) */ + char *op_buf; /* pointer to field value */ +}; + +#define OPIOCGET _IOWR('O', 1, struct opiocdesc) /* get openprom field */ +#define OPIOCSET _IOW('O', 2, struct opiocdesc) /* set openprom field */ +#define OPIOCNEXTPROP _IOWR('O', 3, struct opiocdesc) /* get next property */ +#define OPIOCGETOPTNODE _IOR('O', 4, int) /* get openprom field */ +#define OPIOCGETNEXT _IOWR('O', 5, int) /* get next node of node */ +#define OPIOCGETCHILD _IOWR('O', 6, int) /* get first child of node */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/param.h b/lib/libc/include/riscv64-openbsd-none/machine/param.h new file mode 100644 index 0000000000..1260fa3a3c --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/param.h @@ -0,0 +1,78 @@ +/* $OpenBSD: param.h,v 1.7 2025/07/07 18:33:37 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 +#endif +#endif + +#define _MACHINE riscv64 +#define MACHINE "riscv64" +#define _MACHINE_ARCH riscv64 +#define MACHINE_ARCH "riscv64" +#define MID_MACHINE MID_RISCV64 + +#define PAGE_SHIFT 12 +#define PAGE_SIZE (1 << PAGE_SHIFT) +#define PAGE_MASK (PAGE_SIZE - 1) + +#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 6 /* pages of u-area */ +#define USPACE (UPAGES * PAGE_SIZE) /* total size of u-area */ +#define USPACE_ALIGN 0 /* u-area alignment 0-none */ +#define __HAVE_USPACE_GUARD + +#define NMBCLUSTERS (64 * 1024) /* max cluster allocation */ + +#ifndef MSGBUFSIZE +#define MSGBUFSIZE (16 * PAGE_SIZE) /* default message buffer size */ +#endif + +#define STACKALIGNBYTES (16 - 1) +#define STACKALIGN(p) ((u_long)(p) &~ STACKALIGNBYTES) + +#define __HAVE_FDT + +#endif /* _KERNEL */ + +#endif /* _MACHINE_PARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/pcb.h b/lib/libc/include/riscv64-openbsd-none/machine/pcb.h new file mode 100644 index 0000000000..a1b6cb9e47 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/pcb.h @@ -0,0 +1,41 @@ +/* $OpenBSD: pcb.h,v 1.4 2024/10/15 09:16:39 jsg Exp $ */ + +/* + * Copyright (c) 2016 Dale Rahn + * + * 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_PCB_H_ +#define _MACHINE_PCB_H_ + +#include +#include + +struct trapframe; + +/* + * Warning certain fields must be within 256 bytes of the beginning + * of this structure. + */ +struct pcb { + u_int pcb_flags; +#define PCB_FPU 0x00000001 /* Process had FPU initialized */ +#define PCB_SINGLESTEP 0x00000002 /* Single step process */ + struct trapframe *pcb_tf; + + register_t pcb_sp; // stack pointer of switchframe + + caddr_t pcb_onfault; // On fault handler + struct fpreg pcb_fpstate; // Floating Point state */ +}; +#endif /* _MACHINE_PCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/pci_machdep.h b/lib/libc/include/riscv64-openbsd-none/machine/pci_machdep.h new file mode 100644 index 0000000000..4737ab100a --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/pci_machdep.h @@ -0,0 +1,140 @@ +/* $OpenBSD: pci_machdep.h,v 1.5 2024/05/22 05:51:49 jsg Exp $ */ + +/* + * Copyright (c) 2003-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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. + * + */ + +typedef struct machine_pci_chipset *pci_chipset_tag_t; +typedef uint64_t pcitag_t; + +#define PCITAG_NODE(x) ((x) >> 32) +#define PCITAG_OFFSET(x) ((x) & 0xffffffff) + +/* Supported interrupt types. */ +#define PCI_NONE 0 +#define PCI_INTX 1 +#define PCI_MSI 2 +#define PCI_MSIX 3 + +typedef struct { + pci_chipset_tag_t ih_pc; + pcitag_t ih_tag; + int ih_intrpin; + int ih_type; + bus_dma_tag_t ih_dmat; +} pci_intr_handle_t; + +struct pci_attach_args; + +/* + * Machine-specific PCI structure and type definitions. + * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE. + */ +struct machine_pci_chipset { + void *pc_conf_v; + void (*pc_attach_hook)(struct device *, + struct device *, struct pcibus_attach_args *); + int (*pc_bus_maxdevs)(void *, int); + pcitag_t (*pc_make_tag)(void *, int, int, int); + void (*pc_decompose_tag)(void *, pcitag_t, int *, + int *, int *); + int (*pc_conf_size)(void *, pcitag_t); + pcireg_t (*pc_conf_read)(void *, pcitag_t, int); + void (*pc_conf_write)(void *, pcitag_t, int, pcireg_t); + int (*pc_probe_device_hook)(void *, struct pci_attach_args *); + + void *pc_intr_v; + int (*pc_intr_map)(struct pci_attach_args *, + pci_intr_handle_t *); + int (*pc_intr_map_msi)(struct pci_attach_args *, + pci_intr_handle_t *); + int (*pc_intr_map_msivec)(struct pci_attach_args *, + int, pci_intr_handle_t *); + int (*pc_intr_map_msix)(struct pci_attach_args *, + int, pci_intr_handle_t *); + const char *(*pc_intr_string)(void *, pci_intr_handle_t); + void *(*pc_intr_establish)(void *, pci_intr_handle_t, + int, struct cpu_info *, int (*)(void *), void *, + char *); + void (*pc_intr_disestablish)(void *, void *); +}; + +/* + * Functions provided to machine-independent PCI code. + */ +#define pci_attach_hook(p, s, pba) \ + (*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba)) +#define pci_bus_maxdevs(c, b) \ + (*(c)->pc_bus_maxdevs)((c)->pc_conf_v, (b)) +#define pci_make_tag(c, b, d, f) \ + (*(c)->pc_make_tag)((c)->pc_conf_v, (b), (d), (f)) +#define pci_decompose_tag(c, t, bp, dp, fp) \ + (*(c)->pc_decompose_tag)((c)->pc_conf_v, (t), (bp), (dp), (fp)) +#define pci_conf_size(c, t) \ + (*(c)->pc_conf_size)((c)->pc_conf_v, (t)) +#define pci_conf_read(c, t, r) \ + (*(c)->pc_conf_read)((c)->pc_conf_v, (t), (r)) +#define pci_conf_write(c, t, r, v) \ + (*(c)->pc_conf_write)((c)->pc_conf_v, (t), (r), (v)) +#define pci_probe_device_hook(c, a) \ + (*(c)->pc_probe_device_hook)((c)->pc_conf_v, (a)) +#define pci_intr_map(c, ihp) \ + (*(c)->pa_pc->pc_intr_map)((c), (ihp)) +#define pci_intr_map_msi(c, ihp) \ + (*(c)->pa_pc->pc_intr_map_msi)((c), (ihp)) +#define pci_intr_map_msix(c, vec, ihp) \ + (*(c)->pa_pc->pc_intr_map_msix)((c), (vec), (ihp)) +#define pci_intr_string(c, ih) \ + (*(c)->pc_intr_string)((c)->pc_intr_v, (ih)) +#define pci_intr_establish(c, ih, l, h, a, nm) \ + (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), NULL, (h), (a),\ + (nm)) +#define pci_intr_establish_cpu(c, ih, l, ci, h, a, nm) \ + (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), (ci), (h), (a),\ + (nm)) +#define pci_intr_disestablish(c, iv) \ + (*(c)->pc_intr_disestablish)((c)->pc_intr_v, (iv)) + +#define pci_min_powerstate(c, t) (PCI_PMCSR_STATE_D3) +#define pci_set_powerstate_md(c, t, s, p) + +#define pci_dev_postattach(a, b) + +void pci_mcfg_init(bus_space_tag_t, bus_addr_t, int, int, int); + +void pci_msi_enable(pci_chipset_tag_t, pcitag_t, bus_addr_t, uint32_t); +void pci_msix_enable(pci_chipset_tag_t, pcitag_t, bus_space_tag_t, + int, bus_addr_t, uint32_t); +int _pci_intr_map_msi(struct pci_attach_args *, pci_intr_handle_t *); +int _pci_intr_map_msivec(struct pci_attach_args *, int, + pci_intr_handle_t *); +int _pci_intr_map_msix(struct pci_attach_args *, int, pci_intr_handle_t *); + +#define __HAVE_PCI_MSIX + +int pci_msix_table_map(pci_chipset_tag_t, pcitag_t, + bus_space_tag_t, bus_space_handle_t *); +void pci_msix_table_unmap(pci_chipset_tag_t, pcitag_t, + bus_space_tag_t, bus_space_handle_t); \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/pmap.h b/lib/libc/include/riscv64-openbsd-none/machine/pmap.h new file mode 100644 index 0000000000..d6e867d90f --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/pmap.h @@ -0,0 +1,132 @@ +/* $OpenBSD: pmap.h,v 1.14 2025/02/03 17:59:40 jca Exp $ */ + +/* + * Copyright (c) 2019-2020 Brian Bamsch + * Copyright (c) 2008,2009,2014 Dale Rahn + * + * 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_PMAP_H_ +#define _MACHINE_PMAP_H_ + +#ifndef _LOCORE +#include +#include +#include +#endif + + +/* V->P mapping data */ +// XXX Only targeting compatibility with SV39 +#define VP_IDX0_CNT 512 +#define VP_IDX0_MASK (VP_IDX0_CNT-1) +#define VP_IDX0_POS 39 +#define VP_IDX1_CNT 512 +#define VP_IDX1_MASK (VP_IDX1_CNT-1) +#define VP_IDX1_POS 30 +#define VP_IDX2_CNT 512 +#define VP_IDX2_MASK (VP_IDX2_CNT-1) +#define VP_IDX2_POS 21 +#define VP_IDX3_CNT 512 +#define VP_IDX3_MASK (VP_IDX3_CNT-1) +#define VP_IDX3_POS 12 + +/* cache flags */ +// XXX These are duplicated from arm64 and may need some reworking +#define PMAP_CACHE_CI (PMAP_MD0) /* cache inhibit */ +#define PMAP_CACHE_WB (PMAP_MD1) /* writeback */ +#define PMAP_CACHE_DEV (PMAP_MD2) /* device mapping */ +#define PMAP_CACHE_BITS (PMAP_MD0|PMAP_MD1|PMAP_MD2) + +#define PTED_VA_MANAGED_M (PMAP_MD3) +#define PTED_VA_WIRED_M (PMAP_MD3 << 1) + +#if defined(_KERNEL) && !defined(_LOCORE) +/* + * Pmap stuff + */ + +typedef struct pmap *pmap_t; + +struct pmap { + struct mutex pm_mtx; + union { + // XXX Sv48 not yet supported + // XXX Consider inverting Lx + struct pmapvp1 *l1; /* virtual to physical table 3 lvl */ + } pm_vp; + uint64_t pm_satp; + int pm_privileged; + int pm_refs; /* ref count */ + struct pmap_statistics pm_stats; /* pmap statistics */ +}; + +#define PMAP_PA_MASK ~((paddr_t)PAGE_MASK) /* to remove the flags */ +#define PMAP_NOCACHE 0x1 /* non-cacheable memory */ +#define PMAP_DEVICE 0x2 /* device memory */ + +#define PG_PMAP_MOD PG_PMAP0 +#define PG_PMAP_REF PG_PMAP1 +#define PG_PMAP_EXE PG_PMAP2 + +// [NCPUS] +extern paddr_t zero_page; +extern paddr_t copy_src_page; +extern paddr_t copy_dst_page; + +void pagezero(vaddr_t); + +extern struct pmap kernel_pmap_; +#define pmap_kernel() (&kernel_pmap_) +#define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count) +#define pmap_wired_count(pmap) ((pmap)->pm_stats.wired_count) + +vaddr_t pmap_bootstrap(long kvo, paddr_t lpt1, + vaddr_t kernelstart, vaddr_t kernelend, + paddr_t memstart, paddr_t memend); +void pmap_kenter_cache(vaddr_t va, paddr_t pa, vm_prot_t prot, int cacheable); +void pmap_page_ro(pmap_t pm, vaddr_t va, vm_prot_t prot); + +paddr_t pmap_steal_avail(size_t size, int align, void **kva); +void pmap_avail_fixup(void); +void pmap_physload_avail(void); + +#define PMAP_GROWKERNEL + +#define PHYS_TO_DMAP(pa) ((pa) - dmap_phys_base + DMAP_MIN_ADDRESS) + +struct pv_entry; + +/* investigate */ +#define pmap_unuse_final(p) do { /* nothing */ } while (0) +int pmap_fault_fixup(pmap_t, vaddr_t, vm_prot_t); +void pmap_postinit(void); +void pmap_init_percpu(void); + +#define __HAVE_PMAP_POPULATE + +#endif /* _KERNEL && !_LOCORE */ + +#ifndef _LOCORE +struct vm_page_md { + struct mutex pv_mtx; + LIST_HEAD(,pte_desc) pv_list; +}; + +#define VM_MDPAGE_INIT(pg) do { \ + mtx_init(&(pg)->mdpage.pv_mtx, IPL_VM); \ + LIST_INIT(&((pg)->mdpage.pv_list)); \ +} while (0) +#endif /* _LOCORE */ + +#endif /* _MACHINE_PMAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/proc.h b/lib/libc/include/riscv64-openbsd-none/machine/proc.h new file mode 100644 index 0000000000..e1a7bf3652 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/proc.h @@ -0,0 +1,45 @@ +/* $OpenBSD: proc.h,v 1.2 2021/05/12 01:20:52 jsg Exp $ */ +/* $NetBSD: proc.h,v 1.1 2003/04/26 18:39:46 fvdl 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 riscv64. + */ +struct mdproc { + volatile int md_astpending; +}; + +#endif /* _MACHINE_PROC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/profile.h b/lib/libc/include/riscv64-openbsd-none/machine/profile.h new file mode 100644 index 0000000000..3074be08fc --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/profile.h @@ -0,0 +1,92 @@ +/* $OpenBSD: profile.h,v 1.4 2021/05/21 16:49:57 deraadt Exp $ */ + +/* + * Copyright (c) 2015 Dale Rahn + * + * 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 _MCOUNT_DECL void _mcount + +#define MCOUNT_ASM_NAME "__mcount" + +#ifdef __PIC__ +#define PLTSYM "" /* XXX -aarch64 defaults to PLT? */ +#else +#define PLTSYM "" +#endif + +#define MCOUNT \ +__asm__ (".text \n;" \ + ".align 3 \n;" \ + ".globl " MCOUNT_ASM_NAME " \n;" \ + ".type " MCOUNT_ASM_NAME ",@function \n;" \ + MCOUNT_ASM_NAME ": \n;" \ + " addi sp, sp, -176 \n" \ + " sd fp, 0(sp) \n" \ + " sd ra, 8(sp) \n" \ + " sd s1, 24(sp) \n" \ + " sd a0, 32(sp) \n" \ + " sd a1, 40(sp) \n" \ + " sd a2, 48(sp) \n" \ + " sd a3, 56(sp) \n" \ + " sd a4, 64(sp) \n" \ + " sd a5, 72(sp) \n" \ + " sd a6, 80(sp) \n" \ + " sd a7, 88(sp) \n" \ + " sd s2, 96(sp) \n" \ + " sd s3, 104(sp) \n" \ + " sd s4, 112(sp) \n" \ + " sd s5, 120(sp) \n" \ + " sd s6, 128(sp) \n" \ + " sd s7, 136(sp) \n" \ + " sd s8, 144(sp) \n" \ + " sd s9, 152(sp) \n" \ + " sd s10, 160(sp) \n" \ + " sd s11, 168(sp) \n" \ + " ld a0, 8(fp) \n" \ + " mv a1, x1 \n" \ + " call " __STRING(_mcount) PLTSYM " \n" \ + /* restore argument registers */ \ + " ld fp, 0(sp) \n" \ + " ld ra, 8(sp) \n" \ + " ld s1, 24(sp) \n" \ + " ld a0, 32(sp) \n" \ + " ld a1, 40(sp) \n" \ + " ld a2, 48(sp) \n" \ + " ld a3, 56(sp) \n" \ + " ld a4, 64(sp) \n" \ + " ld a5, 72(sp) \n" \ + " ld a6, 80(sp) \n" \ + " ld a7, 88(sp) \n" \ + " ld s2, 96(sp) \n" \ + " ld s3, 104(sp) \n" \ + " ld s4, 112(sp) \n" \ + " ld s5, 120(sp) \n" \ + " ld s6, 128(sp) \n" \ + " ld s7, 136(sp) \n" \ + " ld s8, 144(sp) \n" \ + " ld s9, 152(sp) \n" \ + " ld s10, 160(sp) \n" \ + " ld s11, 168(sp) \n" \ + " addi sp, sp, 176 \n" \ + " jr ra \n"); + +#ifdef _KERNEL +// Change this to dair read/set, then restore. +#define MCOUNT_ENTER \ +__asm__ ("mrs %x0,daif; msr daifset, #0x2": "=r"(s)); +#define MCOUNT_EXIT \ +__asm__ ("msr daif, %x0":: "r"(s)); + +#endif \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/pte.h b/lib/libc/include/riscv64-openbsd-none/machine/pte.h new file mode 100644 index 0000000000..c050e38cb2 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/pte.h @@ -0,0 +1,85 @@ +/* $OpenBSD: pte.h,v 1.4 2024/10/14 12:02:16 jsg Exp $ */ + +/* + * Copyright (c) 2019 Brian Bamsch + * Copyright (c) 2014 Dale Rahn + * + * 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 _RISCV64_PTE_H_ +#define _RISCV64_PTE_H_ + +#define Lx_TABLE_ALIGN (4096) + +/* Block and Page attributes */ +/* Bits 9:8 are reserved for software */ +#define PTE_ATTR_MASK (0x3ffUL) +#define PTE_SW_MANAGED (1 << 9) +#define PTE_SW_WIRED (1 << 8) +#define PTE_D (1 << 7) /* Dirty */ +#define PTE_A (1 << 6) /* Accessed */ +#define PTE_G (1 << 5) /* Global */ +#define PTE_U (1 << 4) /* User */ +#define PTE_X (1 << 3) /* Execute */ +#define PTE_W (1 << 2) /* Write */ +#define PTE_R (1 << 1) /* Read */ +#define PTE_V (1 << 0) /* Valid */ +#define PTE_RWX (PTE_R | PTE_W | PTE_X) +#define PTE_RX (PTE_R | PTE_X) +#define PTE_KERN (PTE_V | PTE_R | PTE_W | PTE_A | PTE_D) + +/* T-Head extended page attributes */ +#define PTE_THEAD_SO (1ULL << 63) +#define PTE_THEAD_C (1ULL << 62) +#define PTE_THEAD_B (1ULL << 61) +#define PTE_THEAD_SH (1ULL << 60) + +/* Level 0 table, 512GiB per entry */ +#define L0_SHIFT 39 + +/* Level 1 table, 1GiB per entry */ +#define L1_SHIFT 30 +#define L1_SIZE (1UL << L1_SHIFT) +#define L1_OFFSET (L1_SIZE - 1) + +/* Level 2 table, 2MiB per entry */ +#define L2_SHIFT 21 +#define L2_SIZE (1UL << L2_SHIFT) +#define L2_OFFSET (L2_SIZE - 1) + +/* Level 3 table, 4KiB per entry */ +#define L3_SHIFT 12 +#define L3_SIZE (1UL << L3_SHIFT) +#define L3_OFFSET (L3_SIZE - 1) + +/* page mapping */ +#define Ln_ENTRIES_SHIFT 9 +#define Ln_ENTRIES (1 << Ln_ENTRIES_SHIFT) +#define Ln_ADDR_MASK (Ln_ENTRIES - 1) +#define Ln_TABLE_MASK ((1 << 12) - 1) + +/* physical page number mask */ +#define PTE_RPGN (((1ULL << 56) - 1) & ~PAGE_MASK) + +#define PTE_PPN0_S 10 +#define PTE_PPN1_S 19 +#define PTE_PPN2_S 28 +#define PTE_PPN3_S 37 +#define PTE_SIZE 8 + +#ifndef _LOCORE +typedef uint64_t pt_entry_t; /* page table entry */ +typedef uint64_t pn_t; /* page number */ +#endif /* !_LOCORE */ + +#endif /* _RISCV64_PTE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/ptrace.h b/lib/libc/include/riscv64-openbsd-none/machine/ptrace.h new file mode 100644 index 0000000000..acffe61919 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/ptrace.h @@ -0,0 +1,25 @@ +/* $OpenBSD: ptrace.h,v 1.4 2021/09/03 14:13:06 jca Exp $ */ + +/* + * Copyright (c) 2014 Patrick Wildt + * + * 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. + */ + +#if 0 +#define PT_STEP (PT_FIRSTMACH + 0) +#endif +#define PT_GETREGS (PT_FIRSTMACH + 1) +#define PT_SETREGS (PT_FIRSTMACH + 2) +#define PT_GETFPREGS (PT_FIRSTMACH + 3) +#define PT_SETFPREGS (PT_FIRSTMACH + 4) \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/reg.h b/lib/libc/include/riscv64-openbsd-none/machine/reg.h new file mode 100644 index 0000000000..f80b13d4aa --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/reg.h @@ -0,0 +1,60 @@ +/* $OpenBSD: reg.h,v 1.2 2021/05/12 01:20:52 jsg Exp $ */ + +/*- + * Copyright (c) 2019 Brian Bamsch + * Copyright (c) 2015-2016 Ruslan Bukin + * All rights reserved. + * + * Portions of this software were developed by SRI International and the + * University of Cambridge Computer Laboratory under DARPA/AFRL contract + * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. + * + * Portions of this software were developed by the University of Cambridge + * Computer Laboratory as part of the CTSRD Project, with support from the + * UK Higher Education Innovation Fund (HEIF). + * + * 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 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 AUTHOR 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. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_REG_H_ +#define _MACHINE_REG_H_ + +struct reg { + uint64_t r_ra; /* return address */ + uint64_t r_sp; /* stack pointer */ + uint64_t r_gp; /* global pointer */ + uint64_t r_tp; /* thread pointer */ + uint64_t r_t[7]; /* temporary registers */ + uint64_t r_s[12]; /* saved registers */ + uint64_t r_a[8]; /* argument registers */ + uint64_t r_sepc; /* exception program counter */ + uint64_t r_sstatus; /* status register */ +}; + +struct fpreg { + uint64_t fp_f[32]; /* floating-point registers */ + uint64_t fp_fcsr; /* floating-point control register */ +}; + +#endif /* !_MACHINE_REG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/reloc.h b/lib/libc/include/riscv64-openbsd-none/machine/reloc.h new file mode 100644 index 0000000000..09dea83e32 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/reloc.h @@ -0,0 +1,19 @@ +/* $OpenBSD: reloc.h,v 1.2 2021/05/12 01:20:52 jsg Exp $ */ + +/* + * RISCV64 static relocation types. + */ + +/* Relocation types used by the dynamic linker. */ +#define R_RISCV_NONE 0 +#define R_RISCV_32 1 +#define R_RISCV_64 2 +#define R_RISCV_RELATIVE 3 +#define R_RISCV_COPY 4 +#define R_RISCV_JUMP_SLOT 5 +#define R_RISCV_TLS_DTPMOD32 6 +#define R_RISCV_TLS_DTPMOD64 7 +#define R_RISCV_TLS_DTPREL32 8 +#define R_RISCV_TLS_DTPREL64 9 +#define R_RISCV_TLS_TPREL32 10 +#define R_RISCV_TLS_TPREL64 11 \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/riscvreg.h b/lib/libc/include/riscv64-openbsd-none/machine/riscvreg.h new file mode 100644 index 0000000000..cf19db3ca1 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/riscvreg.h @@ -0,0 +1,235 @@ +/* $OpenBSD: riscvreg.h,v 1.5 2022/08/29 02:01:18 jsg Exp $ */ + +/*- + * Copyright (c) 2019 Brian Bamsch + * Copyright (c) 2015-2017 Ruslan Bukin + * All rights reserved. + * + * Portions of this software were developed by SRI International and the + * University of Cambridge Computer Laboratory under DARPA/AFRL contract + * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. + * + * Portions of this software were developed by the University of Cambridge + * Computer Laboratory as part of the CTSRD Project, with support from the + * UK Higher Education Innovation Fund (HEIF). + * + * 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 copyright holder 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 AUTHOR 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 AUTHOR 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_RISCVREG_H_ +#define _MACHINE_RISCVREG_H_ + +#define EXCP_SHIFT 0 +#define EXCP_MASK (0xf << EXCP_SHIFT) +#define EXCP_MISALIGNED_FETCH 0 +#define EXCP_FAULT_FETCH 1 +#define EXCP_ILLEGAL_INSTRUCTION 2 +#define EXCP_BREAKPOINT 3 +#define EXCP_MISALIGNED_LOAD 4 +#define EXCP_FAULT_LOAD 5 +#define EXCP_MISALIGNED_STORE 6 +#define EXCP_FAULT_STORE 7 +#define EXCP_USER_ECALL 8 +#define EXCP_SUPERVISOR_ECALL 9 +#define EXCP_HYPERVISOR_ECALL 10 +#define EXCP_MACHINE_ECALL 11 +#define EXCP_INST_PAGE_FAULT 12 +#define EXCP_LOAD_PAGE_FAULT 13 +#define EXCP_STORE_PAGE_FAULT 15 +#define EXCP_INTR (1ULL << 63) + +#define MSTATUS_UIE (1 << 0) +#define MSTATUS_SIE (1 << 1) +#define MSTATUS_MIE (1 << 3) +#define MSTATUS_UPIE (1 << 4) +#define MSTATUS_SPIE (1 << 5) +#define MSTATUS_MPIE (1 << 7) +#define MSTATUS_SPP (1 << 8) +#define MSTATUS_MPP_SHIFT 11 +#define MSTATUS_MPP_MASK (0x3 << MSTATUS_MPP_SHIFT) +#define MSTATUS_FS_SHIFT 13 +#define MSTATUS_FS_MASK (0x3 << MSTATUS_FS_SHIFT) +#define MSTATUS_XS_SHIFT 15 +#define MSTATUS_XS_MASK (0x3 << MSTATUS_XS_SHIFT) +#define MSTATUS_MPRV (1 << 17) +#define MSTATUS_SUM (1 << 18) +#define MSTATUS_MXR (1 << 19) +#define MSTATUS_TVM (1 << 20) +#define MSTATUS_TW (1 << 21) +#define MSTATUS_TSR (1 << 22) +#define MSTATUS_UXL_SHIFT 32 +#define MSTATUS_UXL_MASK (0x3ULL << MSTATUS_UXL_SHIFT) +#define MSTATUS_SXL_SHIFT 34 +#define MSTATUS_SXL_MASK (0x3ULL << MSTATUS_SXL_SHIFT) +#define MSTATUS_SD (1ULL << (MXLEN - 1)) + +#define SSTATUS_UIE (1 << 0) +#define SSTATUS_SIE (1 << 1) +#define SSTATUS_UPIE (1 << 4) +#define SSTATUS_SPIE (1 << 5) +#define SSTATUS_SPP (1 << 8) +#define SSTATUS_FS_SHIFT 13 +#define SSTATUS_FS_MASK (0x3 << SSTATUS_FS_SHIFT) +#define SSTATUS_FS_OFF (0x0 << SSTATUS_FS_SHIFT) +#define SSTATUS_FS_INITIAL (0x1 << SSTATUS_FS_SHIFT) +#define SSTATUS_FS_CLEAN (0x2 << SSTATUS_FS_SHIFT) +#define SSTATUS_FS_DIRTY (0x3 << SSTATUS_FS_SHIFT) +#define SSTATUS_XS_SHIFT 15 +#define SSTATUS_XS_MASK (0x3 << SSTATUS_XS_SHIFT) +#define SSTATUS_SUM (1 << 18) +#define SSTATUS_MXR (1 << 19) +#define SSTATUS_UXL_SHIFT 32 +#define SSTATUS_UXL_MASK (0x3ULL << SSTATUS_UXL_SHIFT) +#define SSTATUS_SD (1ULL << (SXLEN - 1)) + +#define USTATUS_UIE (1 << 0) +#define USTATUS_UPIE (1 << 4) + +#define MSTATUS_PRV_U 0 /* user */ +#define MSTATUS_PRV_S 1 /* supervisor */ +#define MSTATUS_PRV_H 2 /* hypervisor */ +#define MSTATUS_PRV_M 3 /* machine */ + +#define MIE_USIE (1 << 0) +#define MIE_SSIE (1 << 1) +#define MIE_MSIE (1 << 3) +#define MIE_UTIE (1 << 4) +#define MIE_STIE (1 << 5) +#define MIE_MTIE (1 << 7) +#define MIE_UEIE (1 << 8) +#define MIE_SEIE (1 << 9) +#define MIE_MEIE (1 << 11) + +#define MIP_USIP (1 << 0) +#define MIP_SSIP (1 << 1) +#define MIP_MSIP (1 << 3) +#define MIP_UTIP (1 << 4) +#define MIP_STIP (1 << 5) +#define MIP_MTIP (1 << 7) +#define MIP_UEIP (1 << 8) +#define MIP_SEIP (1 << 9) +#define MIP_MEIP (1 << 11) + +#define SIE_USIE (1 << 0) +#define SIE_SSIE (1 << 1) +#define SIE_UTIE (1 << 4) +#define SIE_STIE (1 << 5) +#define SIE_UEIE (1 << 8) +#define SIE_SEIE (1 << 9) + +#define SIP_USIP (1 << 0) +#define SIP_SSIP (1 << 1) +#define SIP_UTIP (1 << 4) +#define SIP_STIP (1 << 5) +#define SIP_UEIP (1 << 8) +#define SIP_SEIP (1 << 9) + +#define UIE_USIE (1 << 0) +#define UIE_UTIE (1 << 4) +#define UIE_UEIE (1 << 8) + +#define UIP_USIP (1 << 0) +#define UIP_UTIP (1 << 4) +#define UIP_UEIP (1 << 8) + +#define PPN(pa) ((pa) >> PAGE_SHIFT) +#define SATP_PPN_SHIFT 0 +#define SATP_PPN_MASK (0xfffffffffffULL << SATP_PPN_SHIFT) +#define SATP_PPN(satp) (((satp) & SATP_PPN_MASK) >> SATP_PPN_SHIFT) +#define SATP_FORMAT_PPN(ppn) (((uint64_t)(ppn) << SATP_PPN_SHIFT) & SATP_PPN_MASK) +#define SATP_ASID_SHIFT 44 +#define SATP_ASID_MASK (0xffffULL << SATP_ASID_SHIFT) +#define SATP_ASID(satp) (((satp) & SATP_ASID_MASK) >> SATP_ASID_SHIFT) +#define SATP_FORMAT_ASID(asid) (((uint64_t)(asid) << SATP_ASID_SHIFT) & SATP_ASID_MASK) +#define SATP_MODE_SHIFT 60 +#define SATP_MODE_MASK (0xfULL << SATP_MODE_SHIFT) +#define SATP_MODE(mode) (((satp) & SATP_MODE_MASK) >> SATP_MODE_SHIFT) + +#define SATP_MODE_SV39 (8ULL << SATP_MODE_SHIFT) +#define SATP_MODE_SV48 (9ULL << SATP_MODE_SHIFT) +#define SATP_MODE_SV57 (10ULL << SATP_MODE_SHIFT) +#define SATP_MODE_SV64 (11ULL << SATP_MODE_SHIFT) + +/** + * As of RISC-V Machine ISA v1.11, the XLEN can vary between + * Machine, Supervisor, and User modes. The Machine XLEN (MXLEN) + * is resolved from the MXL field of the 'misa' CSR. The + * Supervisor XLEN (SXLEN) and User XLEN (UXLEN) are resolved + * from the SXL and UXL fields of the 'mstatus' CSR, respectively. + * + * The Machine XLEN is reset to the widest supported ISA variant + * at machine reset. For now, assume that all modes will always + * use the same, static XLEN of 64 bits. + */ +#define XLEN 64 +#define XLEN_BYTES (XLEN / 8) +#define MXLEN XLEN +#define SXLEN XLEN +#define UXLEN XLEN +#define INSN_SIZE 4 +#define INSN_C_SIZE 2 + +// Check if val can fit in the CSR immediate form +#define CSR_ZIMM(val) \ + (__builtin_constant_p(val) && ((u_long)(val) < 32)) + +#define csr_swap(csr, val) \ +({ if (CSR_ZIMM(val)) \ + __asm volatile("csrrwi %0, " #csr ", %1" \ + : "=r" (val) : "i" (val)); \ + else \ + __asm volatile("csrrw %0, " #csr ", %1" \ + : "=r" (val) : "r" (val)); \ + val; \ +}) + +#define csr_write(csr, val) \ +({ if (CSR_ZIMM(val)) \ + __asm volatile("csrwi " #csr ", %0" :: "i" (val)); \ + else \ + __asm volatile("csrw " #csr ", %0" :: "r" (val)); \ +}) + +#define csr_set(csr, val) \ +({ if (CSR_ZIMM(val)) \ + __asm volatile("csrsi " #csr ", %0" :: "i" (val)); \ + else \ + __asm volatile("csrs " #csr ", %0" :: "r" (val)); \ +}) + +#define csr_clear(csr, val) \ +({ if (CSR_ZIMM(val)) \ + __asm volatile("csrci " #csr ", %0" :: "i" (val)); \ + else \ + __asm volatile("csrc " #csr ", %0" :: "r" (val)); \ +}) + +#define csr_read(csr) \ +({ u_long val; \ + __asm volatile("csrr %0, " #csr : "=r" (val)); \ + val; \ +}) + +#endif /* !_MACHINE_RISCVREG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/sbi.h b/lib/libc/include/riscv64-openbsd-none/machine/sbi.h new file mode 100644 index 0000000000..51e313311d --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/sbi.h @@ -0,0 +1,267 @@ +/* $OpenBSD: sbi.h,v 1.6 2024/03/29 22:11:34 kettenis Exp $ */ + +/*- + * Copyright (c) 2016-2017 Ruslan Bukin + * All rights reserved. + * Copyright (c) 2019 Mitchell Horne + * + * Portions of this software were developed by SRI International and the + * University of Cambridge Computer Laboratory under DARPA/AFRL contract + * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. + * + * Portions of this software were developed by the University of Cambridge + * Computer Laboratory as part of the CTSRD Project, with support from the + * UK Higher Education Innovation Fund (HEIF). + * + * 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 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 AUTHOR 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_SBI_H_ +#define _MACHINE_SBI_H_ + +/* SBI Specification Version */ +#define SBI_SPEC_VERS_MAJOR_OFFSET 24 +#define SBI_SPEC_VERS_MAJOR_MASK (0x7F << SBI_SPEC_VERS_MAJOR_OFFSET) +#define SBI_SPEC_VERS_MINOR_OFFSET 0 +#define SBI_SPEC_VERS_MINOR_MASK (0xFFFFFF << SBI_SPEC_VERS_MINOR_OFFSET) + +/* SBI Implementation IDs */ +#define SBI_IMPL_ID_BBL 0 +#define SBI_IMPL_ID_OPENSBI 1 + +/* SBI Error Codes */ +#define SBI_SUCCESS 0 +#define SBI_ERR_FAILURE -1 +#define SBI_ERR_NOT_SUPPORTED -2 +#define SBI_ERR_INVALID_PARAM -3 +#define SBI_ERR_DENIED -4 +#define SBI_ERR_INVALID_ADDRESS -5 + +/* SBI Base Extension */ +#define SBI_EXT_ID_BASE 0x10 +#define SBI_BASE_GET_SPEC_VERSION 0 +#define SBI_BASE_GET_IMPL_ID 1 +#define SBI_BASE_GET_IMPL_VERSION 2 +#define SBI_BASE_PROBE_EXTENSION 3 +#define SBI_BASE_GET_MVENDORID 4 +#define SBI_BASE_GET_MARCHID 5 +#define SBI_BASE_GET_MIMPID 6 + +/* Hart State Management (HSM) Extension */ +#define SBI_EXT_ID_HSM 0x48534D +#define SBI_HSM_HART_START 0 +#define SBI_HSM_HART_STOP 1 +#define SBI_HSM_HART_STATUS 2 +#define SBI_HSM_STATUS_STARTED 0 +#define SBI_HSM_STATUS_STOPPED 1 +#define SBI_HSM_STATUS_START_PENDING 2 +#define SBI_HSM_STATUS_STOP_PENDING 3 + +/* System Reset Extension */ +#define SBI_EXT_ID_SRST 0x53525354 +#define SBI_SRST_RESET 0 +#define SBI_SRST_RESET_SHUTDOWN 0 +#define SBI_SRST_RESET_COLD_REBOOT 1 +#define SBI_SRST_RESET_WARM_REBOOT 2 + +/* Legacy Extensions */ +#define SBI_SET_TIMER 0 +#define SBI_CONSOLE_PUTCHAR 1 +#define SBI_CONSOLE_GETCHAR 2 +#define SBI_CLEAR_IPI 3 +#define SBI_SEND_IPI 4 +#define SBI_REMOTE_FENCE_I 5 +#define SBI_REMOTE_SFENCE_VMA 6 +#define SBI_REMOTE_SFENCE_VMA_ASID 7 +#define SBI_SHUTDOWN 8 + +#define SBI_CALL0(e, f) SBI_CALL4(e, f, 0, 0, 0, 0) +#define SBI_CALL1(e, f, p1) SBI_CALL4(e, f, p1, 0, 0, 0) +#define SBI_CALL2(e, f, p1, p2) SBI_CALL4(e, f, p1, p2, 0, 0) +#define SBI_CALL3(e, f, p1, p2, p3) SBI_CALL4(e, f, p1, p2, p3, 0) +#define SBI_CALL4(e, f, p1, p2, p3, p4) sbi_call(e, f, p1, p2, p3, p4) + +/* + * Documentation available at + * https://github.com/riscv/riscv-sbi-doc/blob/master/riscv-sbi.adoc + */ + +struct sbi_ret { + long error; + long value; +}; + +static __inline struct sbi_ret +sbi_call(uint64_t arg7, uint64_t arg6, uint64_t arg0, uint64_t arg1, + uint64_t arg2, uint64_t arg3) +{ + struct sbi_ret ret; + + register uintptr_t a0 __asm ("a0") = (uintptr_t)(arg0); + register uintptr_t a1 __asm ("a1") = (uintptr_t)(arg1); + register uintptr_t a2 __asm ("a2") = (uintptr_t)(arg2); + register uintptr_t a3 __asm ("a3") = (uintptr_t)(arg3); + register uintptr_t a6 __asm ("a6") = (uintptr_t)(arg6); + register uintptr_t a7 __asm ("a7") = (uintptr_t)(arg7); + + __asm volatile( \ + "ecall" \ + :"+r"(a0), "+r"(a1) \ + :"r"(a2), "r"(a3), "r"(a6), "r"(a7) \ + :"memory"); + + ret.error = a0; + ret.value = a1; + return (ret); +} + +/* Base extension functions and variables. */ +extern u_long sbi_spec_version; +extern u_long sbi_impl_id; +extern u_long sbi_impl_version; + +static __inline u_int +sbi_get_mvendorid(void) +{ + return (SBI_CALL0(SBI_EXT_ID_BASE, SBI_BASE_GET_MVENDORID).value); +} + + +static __inline u_long +sbi_get_marchid(void) +{ + return (SBI_CALL0(SBI_EXT_ID_BASE, SBI_BASE_GET_MARCHID).value); +} + +static __inline u_long +sbi_get_mimpid(void) +{ + return (SBI_CALL0(SBI_EXT_ID_BASE, SBI_BASE_GET_MIMPID).value); +} + +static __inline long +sbi_probe_extension(long id) +{ + return (SBI_CALL1(SBI_EXT_ID_BASE, SBI_BASE_PROBE_EXTENSION, id).value); +} + +/* Hart State Management extension functions. */ + +/* + * Start execution on the specified hart at physical address start_addr. The + * register a0 will contain the hart's ID, and a1 will contain the value of + * priv. + */ +int sbi_hsm_hart_start(u_long hart, u_long start_addr, u_long priv); + +/* + * Stop execution on the current hart. Interrupts should be disabled, or this + * function may return. + */ +void sbi_hsm_hart_stop(void); + +/* + * Get the execution status of the specified hart. The status will be one of: + * - SBI_HSM_STATUS_STARTED + * - SBI_HSM_STATUS_STOPPED + * - SBI_HSM_STATUS_START_PENDING + * - SBI_HSM_STATUS_STOP_PENDING + */ +int sbi_hsm_hart_status(u_long hart); + +/* Legacy extension functions. */ +static __inline void +sbi_console_putchar(int ch) +{ + + (void)SBI_CALL1(SBI_CONSOLE_PUTCHAR, 0, ch); +} + +static __inline int +sbi_console_getchar(void) +{ + + /* + * XXX: The "error" is returned here because legacy SBI functions + * continue to return their value in a0. + */ + return (SBI_CALL0(SBI_CONSOLE_GETCHAR, 0).error); +} + +static __inline void +sbi_set_timer(uint64_t val) +{ + + (void)SBI_CALL1(SBI_SET_TIMER, 0, val); +} + +static __inline void +sbi_shutdown(void) +{ + + (void)SBI_CALL0(SBI_SHUTDOWN, 0); +} + +static __inline void +sbi_clear_ipi(void) +{ + + (void)SBI_CALL0(SBI_CLEAR_IPI, 0); +} + +static __inline void +sbi_send_ipi(const unsigned long *hart_mask) +{ + + (void)SBI_CALL1(SBI_SEND_IPI, 0, (uint64_t)hart_mask); +} + +static __inline void +sbi_remote_fence_i(const unsigned long *hart_mask) +{ + + (void)SBI_CALL1(SBI_REMOTE_FENCE_I, 0, (uint64_t)hart_mask); +} + +static __inline void +sbi_remote_sfence_vma(const unsigned long *hart_mask, + unsigned long start, unsigned long size) +{ + + (void)SBI_CALL3(SBI_REMOTE_SFENCE_VMA, 0, (uint64_t)hart_mask, start, + size); +} + +static __inline void +sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, + unsigned long start, unsigned long size, + unsigned long asid) +{ + + (void)SBI_CALL4(SBI_REMOTE_SFENCE_VMA_ASID, 0, (uint64_t)hart_mask, + start, size, asid); +} + +void sbi_print_version(void); +void sbi_init(void); + +#endif /* !_MACHINE_SBI_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/setjmp.h b/lib/libc/include/riscv64-openbsd-none/machine/setjmp.h new file mode 100644 index 0000000000..5d0d59cc4d --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/setjmp.h @@ -0,0 +1,8 @@ +/* $OpenBSD: setjmp.h,v 1.4 2021/06/17 16:09:08 kettenis Exp $ */ + +/* + * machine/setjmp.h: machine dependent setjmp-related information. + */ + +#define _JBLEN 32 /* sp, ra, [f]s0-11, fscr, magic val, sigmask */ +#define _JB_SIGMASK 28 \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/signal.h b/lib/libc/include/riscv64-openbsd-none/machine/signal.h new file mode 100644 index 0000000000..cf9ddecbfc --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/signal.h @@ -0,0 +1,70 @@ +/* $OpenBSD: signal.h,v 1.4 2021/05/20 15:14:30 drahn Exp $ */ + +/*- + * Copyright (c) 1986, 1989, 1991, 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. + * + * @(#)signal.h 8.1 (Berkeley) 6/11/93 + * from: FreeBSD: src/sys/i386/include/signal.h,v 1.13 2000/11/09 + * from: FreeBSD: src/sys/sparc64/include/signal.h,v 1.6 2001/09/30 18:52:17 + * $FreeBSD: head/sys/riscv/include/signal.h 292407 2015-12-17 18:44:30Z br $ + */ + +#ifndef _MACHINE_SIGNAL_H_ +#define _MACHINE_SIGNAL_H_ + +#include + +typedef int sig_atomic_t; + +#if __BSD_VISIBLE || __XPG_VISIBLE >= 420 + +#include + +struct sigcontext { + int __sc_unused; + int sc_mask; + + __register_t sc_ra; + __register_t sc_sp; + __register_t sc_gp; + __register_t sc_tp; + __register_t sc_t[7]; + __register_t sc_s[12]; + __register_t sc_a[8]; + __register_t sc_sepc; + + /* 64 bit floats as well as integer registers */ + __register_t sc_f[32]; /* floating-point registers */ + __register_t sc_fcsr; /* floating-point control register */ + + long sc_cookie; +}; + +#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */ + +#endif /* !_MACHINE_SIGNAL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/simplebusvar.h b/lib/libc/include/riscv64-openbsd-none/machine/simplebusvar.h new file mode 100644 index 0000000000..5be6208e74 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/simplebusvar.h @@ -0,0 +1,38 @@ +/* $OpenBSD: simplebusvar.h,v 1.1 2023/09/22 01:10:44 jsg Exp $ */ + +/* + * Copyright (c) 2016 Patrick Wildt + * + * 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. + */ + +struct simplebus_softc { + struct device sc_dev; + int sc_node; + bus_space_tag_t sc_iot; + bus_dma_tag_t sc_dmat; + int sc_acells; + int sc_scells; + int sc_pacells; + int sc_pscells; + struct bus_space sc_bus; + struct machine_bus_dma_tag sc_dma; + int *sc_ranges; + int sc_rangeslen; + int *sc_dmaranges; + int sc_dmarangeslen; + int sc_early; + int sc_early_nodes[64]; +}; + +extern void simplebus_attach(struct device *, struct device *, void *); \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/spinlock.h b/lib/libc/include/riscv64-openbsd-none/machine/spinlock.h new file mode 100644 index 0000000000..aca85f3b7b --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/spinlock.h @@ -0,0 +1,10 @@ +/* $OpenBSD: spinlock.h,v 1.2 2021/05/12 01:20:52 jsg Exp $ */ + +#ifndef _MACHINE_SPINLOCK_H_ +#define _MACHINE_SPINLOCK_H_ + +#define _ATOMIC_LOCK_UNLOCKED (0) +#define _ATOMIC_LOCK_LOCKED (1) +typedef int _atomic_lock_t; + +#endif \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/sysarch.h b/lib/libc/include/riscv64-openbsd-none/machine/sysarch.h new file mode 100644 index 0000000000..cef4a2f0be --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/sysarch.h @@ -0,0 +1,43 @@ +/* $OpenBSD: sysarch.h,v 1.1 2021/09/14 12:03:49 jca Exp $ */ + +/* + * Copyright (c) 2021 Jeremie Courreges-Anglas + * + * 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 _RISCV64_SYSARCH_H_ +#define _RISCV64_SYSARCH_H_ + +/* + * Architecture specific syscalls (riscv64) + */ + +#define RISCV_SYNC_ICACHE 0 + +struct riscv_sync_icache_args { + u_int64_t addr; /* Virtual start address */ + size_t len; /* Region size */ +}; + +#ifndef _KERNEL + +#include + +__BEGIN_DECLS +int sysarch(int, void *); +__END_DECLS + +#endif /* _KERNEL */ + +#endif /* _RISCV64_SYSARCH_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/syscall.h b/lib/libc/include/riscv64-openbsd-none/machine/syscall.h new file mode 100644 index 0000000000..b3f643ffdd --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/syscall.h @@ -0,0 +1,28 @@ +/* $OpenBSD: syscall.h,v 1.3 2021/05/21 16:49:35 deraadt Exp $ */ + +/* + * Copyright (c) 2020 Brian Bamsch + * + * 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_SYSCALL_H_ +#define _MACHINE_SYSCALL_H_ + +#ifdef _KERNEL + +void svc_handler (trapframe_t *); + +#endif + +#endif /* !_MACHINE_SYSCALL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/tcb.h b/lib/libc/include/riscv64-openbsd-none/machine/tcb.h new file mode 100644 index 0000000000..d140033198 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/tcb.h @@ -0,0 +1,52 @@ +/* $OpenBSD: tcb.h,v 1.3 2021/05/12 01:20:52 jsg Exp $ */ + +/* + * Copyright (c) 2019 Brian Bamsch + * Copyright (c) 2011 Philip Guenther + * + * 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 + +#include + +#define TCB_GET(p) \ + ((void *)(((struct pcb *)(p)->p_addr)->pcb_tf->tf_tp)) + +#define TCB_SET(p, addr) \ + do { \ + ((struct pcb *)(p)->p_addr)->pcb_tf->tf_tp = (long)(addr); \ + } while (0) + +#else /* _KERNEL */ + +/* ELF TLS ABI calls for small TCB, with static TLS data after it */ +#define TLS_VARIANT 1 + +static inline void * +__riscv64_read_tcb(void) +{ + void *tcb; + __asm volatile("mv %0, tp": "=r" (tcb)); + return tcb; +} + +#define TCB_GET() __riscv64_read_tcb() + +#endif /* _KERNEL */ + +#endif /* _MACHINE_TCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/timetc.h b/lib/libc/include/riscv64-openbsd-none/machine/timetc.h new file mode 100644 index 0000000000..a19dd6f23f --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/timetc.h @@ -0,0 +1,24 @@ +/* $OpenBSD: timetc.h,v 1.3 2021/07/24 22:41:09 jca Exp $ */ + +/* + * Copyright (c) 2020 Paul Irofti + * + * 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_TIMETC_H_ +#define _MACHINE_TIMETC_H_ + +#define TC_TB 1 + +#endif /* _MACHINE_TIMETC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/trap.h b/lib/libc/include/riscv64-openbsd-none/machine/trap.h new file mode 100644 index 0000000000..337eb2f71f --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/trap.h @@ -0,0 +1,24 @@ +/* $OpenBSD: trap.h,v 1.2 2021/05/12 01:20:52 jsg Exp $ */ + +/* + * Copyright (c) 2019 Brian Bamsch + * Copyright (c) 2016 Dale Rahn + * + * 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 KERNEL_BREAKPOINT 0x00100073 /* EBREAK -- Used by DDB */ + +#define KBPT_ASM "ebreak" + +#define USER_BREAKPOINT 0x00100073 /* EBREAK */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/machine/vmparam.h b/lib/libc/include/riscv64-openbsd-none/machine/vmparam.h new file mode 100644 index 0000000000..a7d864087a --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/machine/vmparam.h @@ -0,0 +1,150 @@ +/* $OpenBSD: vmparam.h,v 1.9 2023/11/28 09:10:18 jsg 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. + * + * @(#)vmparam.h 5.9 (Berkeley) 5/12/91 + */ + +#ifndef _MACHINE_VMPARAM_H_ +#define _MACHINE_VMPARAM_H_ + +/* + * Machine dependent constants for riscv64. + */ + +#define USRSTACK VM_MAXUSER_ADDRESS + +/* + * Virtual memory related constants, all in bytes + */ +#ifndef MAXTSIZ +#define MAXTSIZ ((paddr_t)1*1024*1024*1024) /* max text size */ +#endif +#ifndef DFLDSIZ +#define DFLDSIZ ((paddr_t)128*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)1*1024*1024*1024) /* heap gap size */ +#endif +#ifndef DFLSSIZ +#define DFLSSIZ ((paddr_t)128*1024*1024) /* initial stack size limit */ +#endif +#ifndef MAXSSIZ +#define MAXSSIZ ((paddr_t)1*1024*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 + +/** + * Address space layout. + * + * RISC-V implements multiple paging modes with different virtual address space + * sizes: SV32, SV39 and SV48. SV39 permits a virtual address space size of + * 512GB and uses a three-level page table. Since this is large enough for most + * purposes, we currently use SV39 for both userland and the kernel, avoiding + * the extra translation step required by SV48. + * + * The address space is split into two regions at each end of the 64-bit address + * space: + * + * 0x0000000000000000 - 0x0000003fffffffff 256GB user map + * 0x0000004000000000 - 0xffffffbfffffffff unmappable + * 0xffffffc000000000 - 0xffffffc7ffffffff 32GB kernel map + * 0xffffffc800000000 - 0xffffffcfffffffff 32GB unused + * 0xffffffd000000000 - 0xffffffefffffffff 128GB direct map + * 0xfffffff000000000 - 0xffffffffffffffff 64GB unused + * + * The kernel is loaded at the beginning of the kernel map. + * + * We define some interesting address constants: + * + * VM_MIN_ADDRESS and VM_MAX_ADDRESS define the start and end of the entire + * 64 bit address space, mostly just for convenience. + * + * VM_MIN_KERNEL_ADDRESS and VM_MAX_KERNEL_ADDRESS define the start and end of + * mappable kernel virtual address space. + * + * VM_MIN_ADDRESS and VM_MAXUSER_ADDRESS define the start and end of the + * user address space. + */ +#define VM_MIN_ADDRESS ((vaddr_t)PAGE_SIZE) +#define VM_MAX_ADDRESS (0xffffffffffffffffUL) + +#define VM_MIN_KERNEL_ADDRESS (0xffffffc000000000UL) +#define VM_MAX_KERNEL_ADDRESS (0xffffffc800000000UL) + +/* Kernel L1 Page Table Range */ +#define L1_KERN_BASE (256) +#define L1_KERN_ENTRIES (288 - L1_KERN_BASE) + +#define DMAP_MIN_ADDRESS (0xffffffd000000000UL) +#define DMAP_MAX_ADDRESS (0xfffffff000000000UL) + +/* DMAP L1 Page Table Range */ +#define L1_DMAP_BASE (320) +#define L1_DMAP_ENTRIES (448 - L1_DMAP_BASE) + +#define VM_MAXUSER_ADDRESS (0x0000004000000000UL) /* 39 bits */ + +#ifdef _KERNEL +#define VM_MIN_STACK_ADDRESS (VM_MAXUSER_ADDRESS * 3 / 4) +#endif + +#define KERNBASE (VM_MIN_KERNEL_ADDRESS) + +#ifndef _LOCORE +extern paddr_t dmap_phys_base; +#endif + +/* virtual sizes (bytes) for various kernel submaps */ +#define VM_PHYS_SIZE (USRIOSIZE*PAGE_SIZE) + +#define VM_PHYSSEG_MAX 32 +#define VM_PHYSSEG_STRAT VM_PSTRAT_BSEARCH +#define VM_PHYSSEG_NOADD /* can't add RAM after vm_mem_init */ + +#endif /* _MACHINE_VMPARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/_float.h b/lib/libc/include/riscv64-openbsd-none/riscv64/_float.h new file mode 100644 index 0000000000..d52ce43ca7 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/_float.h @@ -0,0 +1,96 @@ +/* $OpenBSD: _float.h,v 1.1 2021/04/23 02:42:16 drahn Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + */ + +#ifndef _MACHINE__FLOAT_H_ +#define _MACHINE__FLOAT_H_ + +#define __FLT_RADIX 2 /* b */ +#define __FLT_ROUNDS __flt_rounds() +#define __FLT_EVAL_METHOD 0 /* no promotions */ + +#define __FLT_MANT_DIG 24 /* p */ +#define __FLT_EPSILON 1.19209290E-7F /* b**(1-p) */ +#define __FLT_DIG 6 /* floor((p-1)*log10(b))+(b == 10) */ +#define __FLT_MIN_EXP (-125) /* emin */ +#define __FLT_MIN 1.17549435E-38F /* b**(emin-1) */ +#define __FLT_MIN_10_EXP (-37) /* ceil(log10(b**(emin-1))) */ +#define __FLT_MAX_EXP 128 /* emax */ +#define __FLT_MAX 3.40282347E+38F /* (1-b**(-p))*b**emax */ +#define __FLT_MAX_10_EXP 38 /* floor(log10((1-b**(-p))*b**emax)) */ + +#define __DBL_MANT_DIG 53 +#define __DBL_EPSILON 2.2204460492503131E-16 +#define __DBL_DIG 15 +#define __DBL_MIN_EXP (-1021) +#define __DBL_MIN 2.2250738585072014E-308 +#define __DBL_MIN_10_EXP (-307) +#define __DBL_MAX_EXP 1024 +#define __DBL_MAX 1.7976931348623157E+308 +#define __DBL_MAX_10_EXP 308 + +#ifdef __LDBL_MANT_DIG__ +#define __LDBL_MANT_DIG __LDBL_MANT_DIG__ +#define __LDBL_EPSILON __LDBL_EPSILON__ +#define __LDBL_DIG __LDBL_DIG__ +#define __LDBL_MIN_EXP __LDBL_MIN_EXP__ +#define __LDBL_MIN __LDBL_MIN__ +#define __LDBL_MIN_10_EXP __LDBL_MIN_10_EXP__ +#define __LDBL_MAX_EXP __LDBL_MAX_EXP__ +#define __LDBL_MAX __LDBL_MAX__ +#define __LDBL_MAX_10_EXP __LDBL_MAX_10_EXP__ +#else +#define __LDBL_MANT_DIG DBL_MANT_DIG +#define __LDBL_EPSILON DBL_EPSILON +#define __LDBL_DIG DBL_DIG +#define __LDBL_MIN_EXP DBL_MIN_EXP +#define __LDBL_MIN DBL_MIN +#define __LDBL_MIN_10_EXP DBL_MIN_10_EXP +#define __LDBL_MAX_EXP DBL_MAX_EXP +#define __LDBL_MAX DBL_MAX +#define __LDBL_MAX_10_EXP DBL_MAX_10_EXP +#endif + +#define __DECIMAL_DIG 17 + +#endif /* _MACHINE__FLOAT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/_types.h b/lib/libc/include/riscv64-openbsd-none/riscv64/_types.h new file mode 100644 index 0000000000..b5c1227f1e --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/_types.h @@ -0,0 +1,146 @@ +/* $OpenBSD: _types.h,v 1.5 2023/07/02 19:02:28 cheloha 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[14]; +} 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_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/apmvar.h b/lib/libc/include/riscv64-openbsd-none/riscv64/apmvar.h new file mode 100644 index 0000000000..18cdbfd9de --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/apmvar.h @@ -0,0 +1,122 @@ +/* $OpenBSD: apmvar.h,v 1.1 2023/11/06 20:59:26 jca Exp $ */ + +/* + * Copyright (c) 2001 Alexander Guy + * Copyright (c) 1995 John T. Kohl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef _MACHINE_APMVAR_H_ +#define _MACHINE_APMVAR_H_ + +#include + +/* Advanced Power Management (v1.0 and v1.1 specification) + * functions/defines/etc. + */ + +/* These definitions make up the heart of the user-land interface + * to the APM devices. + */ + +#define APM_AC_OFF 0x00 +#define APM_AC_ON 0x01 +#define APM_AC_BACKUP 0x02 +#define APM_AC_UNKNOWN 0xff +#define APM_BATT_HIGH 0x00 +#define APM_BATT_LOW 0x01 +#define APM_BATT_CRITICAL 0x02 +#define APM_BATT_CHARGING 0x03 +#define APM_BATT_UNKNOWN 0xff +#define APM_BATT_LIFE_UNKNOWN 0xff + +#define APM_NOEVENT 0x0000 +#define APM_STANDBY_REQ 0x0001 +#define APM_SUSPEND_REQ 0x0002 +#define APM_NORMAL_RESUME 0x0003 +#define APM_CRIT_RESUME 0x0004 /* suspend/resume happened + without us */ +#define APM_BATTERY_LOW 0x0005 +#define APM_POWER_CHANGE 0x0006 +#define APM_UPDATE_TIME 0x0007 +#define APM_CRIT_SUSPEND_REQ 0x0008 +#define APM_USER_STANDBY_REQ 0x0009 +#define APM_USER_SUSPEND_REQ 0x000A +#define APM_SYS_STANDBY_RESUME 0x000B +#define APM_CAPABILITY_CHANGE 0x000C /* apm v1.2 */ +#define APM_USER_HIBERNATE_REQ 0x000D +#define APM_EVENT_MASK 0xffff + +#define APM_EVENT_COMPOSE(t,i) ((((i) & 0x7fff) << 16)|((t) & APM_EVENT_MASK)) +#define APM_EVENT_TYPE(e) ((e) & APM_EVENT_MASK) +#define APM_EVENT_INDEX(e) ((e) >> 16) + +/* + * LP (Laptop Package) + * + * Copyright (C) 1994 by HOSOKAWA Tatsumi + * + * This software may be used, modified, copied, and distributed, in + * both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + */ + +#define APM_BATTERY_ABSENT 4 + +struct apm_power_info { + u_char battery_state; + u_char ac_state; + u_char battery_life; + u_char spare1; + u_int minutes_left; /* estimate */ + u_int spare2[6]; +}; + +struct apm_ctl { + u_int dev; + u_int mode; +}; + +#define APM_IOC_REJECT _IOW('A', 0, struct apm_event_info) /* reject request # */ +#define APM_IOC_STANDBY _IO('A', 1) /* put system into standby */ +#define APM_IOC_SUSPEND _IO('A', 2) /* put system into suspend */ +#define APM_IOC_GETPOWER _IOR('A', 3, struct apm_power_info) /* fetch battery state */ +#define APM_IOC_DEV_CTL _IOW('A', 5, struct apm_ctl) /* put device into mode */ +#define APM_IOC_PRN_CTL _IOW('A', 6, int ) /* driver power status msg */ +#define APM_PRINT_ON 0 /* driver power status displayed */ +#define APM_PRINT_OFF 1 /* driver power status not displayed */ +#define APM_PRINT_PCT 2 /* driver power status only displayed + if the percentage changes */ +#define APM_IOC_STANDBY_REQ _IO('A', 7) /* request standby */ +#define APM_IOC_SUSPEND_REQ _IO('A', 8) /* request suspend */ +#define APM_IOC_HIBERNATE _IO('A', 9) /* put system into hibernate */ + +#endif /* _MACHINE_APMVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/asm.h b/lib/libc/include/riscv64-openbsd-none/riscv64/asm.h new file mode 100644 index 0000000000..dcb1d9d02b --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/asm.h @@ -0,0 +1,129 @@ +/* $OpenBSD: asm.h,v 1.8 2022/12/06 00:08:38 jca Exp $ */ + +/* + * Copyright (c) 2020 Brian Bamsch + * 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. + * + * from: @(#)asm.h 5.5 (Berkeley) 5/7/91 + */ + +#ifndef _MACHINE_ASM_H_ +#define _MACHINE_ASM_H_ + +#define _C_LABEL(x) x +#define _ASM_LABEL(x) x + +#ifdef __STDC__ +# define __CONCAT(x,y) x ## y +# define __STRING(x) #x +#else +# define __CONCAT(x,y) x/**/y +# define __STRING(x) "x" +#endif + +#ifndef _ALIGN_TEXT +# define _ALIGN_TEXT .align 0 +#endif + +/* NB == No Binding: use .globl or .weak as necessary */ +#define _ENTRY_NB(x) \ + .text; .p2align 1; .type x,@function; x: +#define _ENTRY(x) .globl x; _ENTRY_NB(x) + +#if defined(PROF) || defined(GPROF) +// XXX Profiler Support +#define _PROF_PROLOGUE \ + addi sp, sp, -16; \ + sd ra, 8(sp); \ + sd fp, 0(sp); \ + mv fp, sp; \ + call __mcount; \ + ld ra, 8(sp); \ + ld fp, 0(sp); \ + add sp, sp, 16; +#else +#define _PROF_PROLOGUE +#endif + +#if defined(_RET_PROTECTOR) +// XXX Retguard Support +#error RETGUARD not yet supported for riscv64 +#else +#define RETGUARD_CALC_COOKIE(reg) +#define RETGUARD_LOAD_RANDOM(x, reg) +#define RETGUARD_SETUP(x, reg) +#define RETGUARD_CHECK(x, reg) +#define RETGUARD_PUSH(reg) +#define RETGUARD_POP(reg) +#define RETGUARD_SYMBOL(x) +#endif + +#define ENTRY(y) _ENTRY(y); _PROF_PROLOGUE +#define ENTRY_NP(y) _ENTRY(y) +#define ENTRY_NB(y) _ENTRY_NB(y); _PROF_PROLOGUE +#define ASENTRY(y) _ENTRY(y); _PROF_PROLOGUE +#define ASENTRY_NP(y) _ENTRY(y) +#define END(y) .size y, . - y +#define EENTRY(sym) .globl sym; sym: +#define EEND(sym) + +#ifdef __PIC__ +#define PIC_SYM(x,y) x(y) +#else +#define PIC_SYM(x,y) x +#endif + +#define STRONG_ALIAS(alias,sym) \ + .global alias; \ + alias = sym +#define WEAK_ALIAS(alias,sym) \ + .weak alias; \ + alias = sym + +#define SWAP_FAULT_HANDLER(handler, tmp0, tmp1) \ + ld tmp0, CI_CURPCB(tp); /* Load the pcb */ \ + ld tmp1, PCB_ONFAULT(tmp0); /* Save old handler */ \ + sd handler, PCB_ONFAULT(tmp0); /* Set the handler */ \ + mv handler, tmp1 + +#define SET_FAULT_HANDLER(handler, pcb) \ + ld pcb, CI_CURPCB(tp); /* Load the pcb */ \ + sd handler, PCB_ONFAULT(pcb) /* Set the handler */ + +#define ENTER_USER_ACCESS(tmp) \ + li tmp, SSTATUS_SUM; \ + csrs sstatus, tmp + +#define EXIT_USER_ACCESS(tmp) \ + li tmp, SSTATUS_SUM; \ + csrc sstatus, tmp + +#endif /* _MACHINE_ASM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/atomic.h b/lib/libc/include/riscv64-openbsd-none/riscv64/atomic.h new file mode 100644 index 0000000000..95cfadaae9 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/atomic.h @@ -0,0 +1,50 @@ +/* $OpenBSD: atomic.h,v 1.5 2024/01/24 12:25:50 jca Exp $ */ + +/* Public Domain */ + +#ifndef _MACHINE_ATOMIC_H_ +#define _MACHINE_ATOMIC_H_ + +#define __membar(_f) do {__asm volatile(_f ::: "memory"); } while (0) + +#define membar_enter() __membar("fence w,rw") +#define membar_exit() __membar("fence rw,w") +#define membar_producer() __membar("fence w,w") +#define membar_consumer() __membar("fence r,r") +#define membar_sync() __membar("fence rw,rw") + +#if defined(_KERNEL) + +/* virtio needs MP membars even on SP kernels */ +#define virtio_membar_producer() __membar("fence w,w") +#define virtio_membar_consumer() __membar("fence r,r") +#define virtio_membar_sync() __membar("fence rw,rw") + +/* + * Set bits + * *p = *p | v + */ +static inline void +atomic_setbits_int(volatile unsigned int *p, unsigned int v) +{ + __asm volatile("amoor.w zero, %1, %0" + : "+A" (*p) + : "r" (v) + : "memory"); +} + +/* + * Clear bits + * *p = *p & (~v) + */ +static inline void +atomic_clearbits_int(volatile unsigned int *p, unsigned int v) +{ + __asm volatile("amoand.w zero, %1, %0" + : "+A" (*p) + : "r" (~v) + : "memory"); +} + +#endif /* defined(_KERNEL) */ +#endif /* _MACHINE_ATOMIC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/bootconfig.h b/lib/libc/include/riscv64-openbsd-none/riscv64/bootconfig.h new file mode 100644 index 0000000000..40f8da8ae4 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/bootconfig.h @@ -0,0 +1,47 @@ +/* $OpenBSD: bootconfig.h,v 1.5 2024/04/06 18:33:54 kettenis Exp $ */ + +/*- + * Copyright (c) 2015-2017 Ruslan Bukin + * All rights reserved. + * + * Portions of this software were developed by SRI International and the + * University of Cambridge Computer Laboratory under DARPA/AFRL contract + * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. + * + * Portions of this software were developed by the University of Cambridge + * Computer Laboratory as part of the CTSRD Project, with support from the + * UK Higher Education Innovation Fund (HEIF). + * + * 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 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 AUTHOR 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_BOOTCONFIG_H_ +#define _MACHINE_BOOTCONFIG_H_ + +struct riscv_bootparams { + vaddr_t kern_l1pt; /* L1 page table for the kernel */ + paddr_t kern_phys; + vaddr_t kern_stack; + paddr_t dtbp_phys; /* Device tree blob physical addr */ +}; + +#endif /* _MACHINE_BOOTCONFIG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/bus.h b/lib/libc/include/riscv64-openbsd-none/riscv64/bus.h new file mode 100644 index 0000000000..85999dfe9d --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/bus.h @@ -0,0 +1,544 @@ +/* $OpenBSD: bus.h,v 1.8 2025/08/03 14:03:12 jca Exp $ */ + +/* + * Copyright (c) 2003-2004 Opsycon AB Sweden. 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_BUS_H_ +#define _MACHINE_BUS_H_ + +#ifdef __STDC__ +#define CAT(a,b) a##b +#define CAT3(a,b,c) a##b##c +#else +#define CAT(a,b) a/**/b +#define CAT3(a,b,c) a/**/b/**/c +#endif + +/* + * Bus access types. + */ +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; +typedef struct bus_space bus_space_t; + +struct bus_space { + bus_addr_t bus_base; + void *bus_private; + u_int8_t (*_space_read_1)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_1)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int8_t); + u_int16_t (*_space_read_2)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_2)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int16_t); + u_int32_t (*_space_read_4)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_4)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int32_t); + u_int64_t (*_space_read_8)(bus_space_tag_t , bus_space_handle_t, + bus_size_t); + void (*_space_write_8)(bus_space_tag_t , bus_space_handle_t, + bus_size_t, u_int64_t); + void (*_space_read_raw_2)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, u_int8_t *, bus_size_t); + void (*_space_write_raw_2)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const u_int8_t *, bus_size_t); + void (*_space_read_raw_4)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, u_int8_t *, bus_size_t); + void (*_space_write_raw_4)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const u_int8_t *, bus_size_t); + void (*_space_read_raw_8)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, u_int8_t *, bus_size_t); + void (*_space_write_raw_8)(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const u_int8_t *, bus_size_t); + int (*_space_map)(bus_space_tag_t , bus_addr_t, + bus_size_t, int, bus_space_handle_t *); + void (*_space_unmap)(bus_space_tag_t, bus_space_handle_t, + bus_size_t); + int (*_space_subregion)(bus_space_tag_t, bus_space_handle_t, + bus_size_t, bus_size_t, bus_space_handle_t *); + void * (*_space_vaddr)(bus_space_tag_t, bus_space_handle_t); + paddr_t (*_space_mmap)(bus_space_tag_t, bus_addr_t, off_t, + int, int); +}; + +#define bus_space_read_1(t, h, o) (*(t)->_space_read_1)((t), (h), (o)) +#define bus_space_read_2(t, h, o) (*(t)->_space_read_2)((t), (h), (o)) +#define bus_space_read_4(t, h, o) (*(t)->_space_read_4)((t), (h), (o)) +#define bus_space_read_8(t, h, o) (*(t)->_space_read_8)((t), (h), (o)) + +#define bus_space_write_1(t, h, o, v) (*(t)->_space_write_1)((t), (h), (o), (v)) +#define bus_space_write_2(t, h, o, v) (*(t)->_space_write_2)((t), (h), (o), (v)) +#define bus_space_write_4(t, h, o, v) (*(t)->_space_write_4)((t), (h), (o), (v)) +#define bus_space_write_8(t, h, o, v) (*(t)->_space_write_8)((t), (h), (o), (v)) + +#define bus_space_read_raw_2(t, h, o) \ + (*(t)->_space_read_2)((t), (h), (o)) +#define bus_space_read_raw_4(t, h, o) \ + (*(t)->_space_read_4)((t), (h), (o)) +#define bus_space_read_raw_8(t, h, o) \ + (*(t)->_space_read_8)((t), (h), (o)) + +#define bus_space_write_raw_2(t, h, o, v) \ + (*(t)->_space_write_2)((t), (h), (o), (v)) +#define bus_space_write_raw_4(t, h, o, v) \ + (*(t)->_space_write_4)((t), (h), (o), (v)) +#define bus_space_write_raw_8(t, h, o, v) \ + (*(t)->_space_write_8)((t), (h), (o), (v)) + +#define bus_space_read_raw_multi_2(t, h, a, b, l) \ + (*(t)->_space_read_raw_2)((t), (h), (a), (b), (l)) +#define bus_space_read_raw_multi_4(t, h, a, b, l) \ + (*(t)->_space_read_raw_4)((t), (h), (a), (b), (l)) +#define bus_space_read_raw_multi_8(t, h, a, b, l) \ + (*(t)->_space_read_raw_8)((t), (h), (a), (b), (l)) + +#define bus_space_write_raw_multi_2(t, h, a, b, l) \ + (*(t)->_space_write_raw_2)((t), (h), (a), (b), (l)) +#define bus_space_write_raw_multi_4(t, h, a, b, l) \ + (*(t)->_space_write_raw_4)((t), (h), (a), (b), (l)) +#define bus_space_write_raw_multi_8(t, h, a, b, l) \ + (*(t)->_space_write_raw_8)((t), (h), (a), (b), (l)) + +#define bus_space_map(t, o, s, c, p) (*(t)->_space_map)((t), (o), (s), (c), (p)) +#define bus_space_unmap(t, h, s) (*(t)->_space_unmap)((t), (h), (s)) +#define bus_space_subregion(t, h, o, s, p) \ + (*(t)->_space_subregion)((t), (h), (o), (s), (p)) + +#define BUS_SPACE_MAP_CACHEABLE 0x01 +#define BUS_SPACE_MAP_LINEAR 0x02 +#define BUS_SPACE_MAP_PREFETCHABLE 0x04 + +extern bus_space_t riscv64_bs_tag; + +#define bus_space_vaddr(t, h) (*(t)->_space_vaddr)((t), (h)) +#define bus_space_mmap(t, a, o, p, f) \ + (*(t)->_space_mmap)((t), (a), (o), (p), (f)) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_multi(n,m) \ +static __inline void \ +CAT(bus_space_read_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_size_t o, CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) \ + *x++ = CAT(bus_space_read_,n)(bst, bsh, o); \ +} + +bus_space_read_multi(1,8) +bus_space_read_multi(2,16) +bus_space_read_multi(4,32) +bus_space_read_multi(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_region(n,m) \ +static __inline void \ +CAT(bus_space_read_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) { \ + *x++ = CAT(bus_space_read_,n)(bst, bsh, ba); \ + ba += (n); \ + } \ +} + +bus_space_read_region(1,8) +bus_space_read_region(2,16) +bus_space_read_region(4,32) +bus_space_read_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_read_raw_region(n,m) \ +static __inline void \ +CAT(bus_space_read_raw_region_,n)(bus_space_tag_t bst, \ + bus_space_handle_t bsh, \ + bus_addr_t ba, u_int8_t *x, size_t cnt) \ +{ \ + cnt >>= ((n) >> 1); \ + while (cnt--) { \ + CAT(bus_space_read_raw_multi_,n)(bst, bsh, ba, x, (n)); \ + ba += (n); \ + x += (n); \ + } \ +} + +bus_space_read_raw_region(2,16) +bus_space_read_raw_region(4,32) +bus_space_read_raw_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_multi(n,m) \ +static __inline void \ +CAT(bus_space_write_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_size_t o, const CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) \ + CAT(bus_space_write_,n)(bst, bsh, o, *x++); \ +} + +bus_space_write_multi(1,8) +bus_space_write_multi(2,16) +bus_space_write_multi(4,32) +bus_space_write_multi(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_region(n,m) \ +static __inline void \ +CAT(bus_space_write_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, const CAT3(u_int,m,_t) *x, size_t cnt) \ +{ \ + while (cnt--) { \ + CAT(bus_space_write_,n)(bst, bsh, ba, *x++); \ + ba += (n); \ + } \ +} + +bus_space_write_region(1,8) +bus_space_write_region(2,16) +bus_space_write_region(4,32) +bus_space_write_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_write_raw_region(n,m) \ +static __inline void \ +CAT(bus_space_write_raw_region_,n)(bus_space_tag_t bst, \ + bus_space_handle_t bsh, \ + bus_addr_t ba, const u_int8_t *x, size_t cnt) \ +{ \ + cnt >>= ((n) >> 1); \ + while (cnt--) { \ + CAT(bus_space_write_raw_multi_,n)(bst, bsh, ba, x, (n)); \ + ba += (n); \ + x += (n); \ + } \ +} + +bus_space_write_raw_region(2,16) +bus_space_write_raw_region(4,32) +bus_space_write_raw_region(8,64) + +/*----------------------------------------------------------------------------*/ +#define bus_space_set_region(n,m) \ +static __inline void \ +CAT(bus_space_set_region_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, CAT3(u_int,m,_t) x, size_t cnt) \ +{ \ + while (cnt--) { \ + CAT(bus_space_write_,n)(bst, bsh, ba, x); \ + ba += (n); \ + } \ +} + +bus_space_set_region(1,8) +bus_space_set_region(2,16) +bus_space_set_region(4,32) +bus_space_set_region(8,64) + +/*----------------------------------------------------------------------------*/ +static __inline void +bus_space_copy_1(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + char *s = (char *)(h1 + o1); + char *d = (char *)(h2 + o2); + + __asm volatile ("fence w,o" ::: "memory"); + while (c--) + *d++ = *s++; + __asm volatile ("fence io,iwr" ::: "memory"); +} + + +static __inline void +bus_space_copy_2(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + short *s = (short *)(h1 + o1); + short *d = (short *)(h2 + o2); + + __asm volatile ("fence w,o" ::: "memory"); + while (c--) + *d++ = *s++; + __asm volatile ("fence io,iwr" ::: "memory"); +} + +static __inline void +bus_space_copy_4(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + int *s = (int *)(h1 + o1); + int *d = (int *)(h2 + o2); + + __asm volatile ("fence w,o" ::: "memory"); + while (c--) + *d++ = *s++; + __asm volatile ("fence io,iwr" ::: "memory"); +} + +static __inline void +bus_space_copy_8(void *v, bus_space_handle_t h1, bus_size_t o1, + bus_space_handle_t h2, bus_size_t o2, bus_size_t c) +{ + int64_t *s = (int64_t *)(h1 + o1); + int64_t *d = (int64_t *)(h2 + o2); + + __asm volatile ("fence w,o" ::: "memory"); + while (c--) + *d++ = *s++; + __asm volatile ("fence io,iwr" ::: "memory"); +} + +/*----------------------------------------------------------------------------*/ +/* + * Bus read/write barrier methods. + * + * void bus_space_barrier(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * bus_size_t len, int flags); + * + */ +static inline void +bus_space_barrier(bus_space_tag_t t, bus_space_handle_t h, bus_size_t offset, + bus_size_t length, int flags) +{ + __asm__ volatile ("fence iorw,iorw" ::: "memory"); +} +#define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */ +#define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */ + +#define BUS_DMA_WAITOK 0x0000 +#define BUS_DMA_NOWAIT 0x0001 +#define BUS_DMA_ALLOCNOW 0x0002 +#define BUS_DMA_COHERENT 0x0008 +#define BUS_DMA_BUS1 0x0010 /* placeholders for bus functions... */ +#define BUS_DMA_BUS2 0x0020 +#define BUS_DMA_BUS3 0x0040 +#define BUS_DMA_BUS4 0x0080 +#define BUS_DMA_READ 0x0100 /* mapping is device -> memory only */ +#define BUS_DMA_WRITE 0x0200 /* mapping is memory -> device only */ +#define BUS_DMA_STREAMING 0x0400 /* hint: sequential, unidirectional */ +#define BUS_DMA_ZERO 0x0800 /* zero memory in dmamem_alloc */ +#define BUS_DMA_NOCACHE 0x1000 +#define BUS_DMA_64BIT 0x2000 /* device handles 64bit dva */ + +/* Forwards needed by prototypes below. */ +struct mbuf; +struct proc; +struct uio; + +#define BUS_DMASYNC_POSTREAD 0x0001 +#define BUS_DMASYNC_POSTWRITE 0x0002 +#define BUS_DMASYNC_PREREAD 0x0004 +#define BUS_DMASYNC_PREWRITE 0x0008 + +typedef struct machine_bus_dma_tag *bus_dma_tag_t; +typedef struct machine_bus_dmamap *bus_dmamap_t; + +/* + * bus_dma_segment_t + * + * Describes a single contiguous DMA transaction. Values + * are suitable for programming into DMA registers. + */ +struct machine_bus_dma_segment { + bus_addr_t ds_addr; /* DMA address */ + bus_size_t ds_len; /* length of transfer */ + + paddr_t _ds_paddr; /* CPU address */ + vaddr_t _ds_vaddr; /* CPU address */ + int _ds_coherent; /* Coherently mapped */ +}; +typedef struct machine_bus_dma_segment bus_dma_segment_t; + +/* + * bus_dma_tag_t + * + * A machine-dependent opaque type describing the implementation of + * DMA for a given bus. + */ + +struct machine_bus_dma_tag { + void *_cookie; /* cookie used in the guts */ + int _flags; /* misc. flags */ + + /* + * DMA mapping methods. + */ + int (*_dmamap_create)(bus_dma_tag_t , bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); + void (*_dmamap_destroy)(bus_dma_tag_t , bus_dmamap_t); + int (*_dmamap_load)(bus_dma_tag_t , bus_dmamap_t, void *, + bus_size_t, struct proc *, int); + int (*_dmamap_load_mbuf)(bus_dma_tag_t , bus_dmamap_t, + struct mbuf *, int); + int (*_dmamap_load_uio)(bus_dma_tag_t , bus_dmamap_t, + struct uio *, int); + int (*_dmamap_load_raw)(bus_dma_tag_t , bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); + int (*_dmamap_load_buffer)(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int, paddr_t *, int *, int); + void (*_dmamap_unload)(bus_dma_tag_t , bus_dmamap_t); + void (*_dmamap_sync)(bus_dma_tag_t , bus_dmamap_t, + bus_addr_t, bus_size_t, int); + + /* + * DMA memory utility functions. + */ + int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); + int (*_dmamem_alloc_range)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int, + paddr_t, paddr_t); + void (*_dmamem_free)(bus_dma_tag_t, bus_dma_segment_t *, int); + int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); + void (*_dmamem_unmap)(bus_dma_tag_t, caddr_t, size_t); + paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *, + int, off_t, int, int); + + /* + * internal memory address translation information. + */ + bus_addr_t _dma_mask; +}; + +#define bus_dmamap_create(t, s, n, m, b, f, p) \ + (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p)) +#define bus_dmamap_destroy(t, p) \ + (*(t)->_dmamap_destroy)((t), (p)) +#define bus_dmamap_load(t, m, b, s, p, f) \ + (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f)) +#define bus_dmamap_load_mbuf(t, m, b, f) \ + (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f)) +#define bus_dmamap_load_uio(t, m, u, f) \ + (*(t)->_dmamap_load_uio)((t), (m), (u), (f)) +#define bus_dmamap_load_raw(t, m, sg, n, s, f) \ + (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f)) +#define bus_dmamap_unload(t, p) \ + (*(t)->_dmamap_unload)((t), (p)) +#define bus_dmamap_sync(t, p, a, l, o) \ + (void)((t)->_dmamap_sync ? \ + (*(t)->_dmamap_sync)((t), (p), (a), (l), (o)) : (void)0) + +#define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \ + (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f)) +#define bus_dmamem_alloc_range(t, s, a, b, sg, n, r, f, l, h) \ + (*(t)->_dmamem_alloc_range)((t), (s), (a), (b), (sg), \ + (n), (r), (f), (l), (h)) +#define bus_dmamem_free(t, sg, n) \ + (*(t)->_dmamem_free)((t), (sg), (n)) +#define bus_dmamem_map(t, sg, n, s, k, f) \ + (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f)) +#define bus_dmamem_unmap(t, k, s) \ + (*(t)->_dmamem_unmap)((t), (k), (s)) +#define bus_dmamem_mmap(t, sg, n, o, p, f) \ + (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f)) + +int _dmamap_create(bus_dma_tag_t, bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); +void _dmamap_destroy(bus_dma_tag_t, bus_dmamap_t); +int _dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int); +int _dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, struct mbuf *, int); +int _dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, struct uio *, int); +int _dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); +int _dmamap_load_buffer(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int, paddr_t *, int *, int); +void _dmamap_unload(bus_dma_tag_t, bus_dmamap_t); +void _dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, + bus_size_t, int); + +int _dmamem_alloc(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); +void _dmamem_free(bus_dma_tag_t, bus_dma_segment_t *, int); +int _dmamem_map(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); +void _dmamem_unmap(bus_dma_tag_t, caddr_t, size_t); +paddr_t _dmamem_mmap(bus_dma_tag_t, bus_dma_segment_t *, int, off_t, int, int); +int _dmamem_alloc_range(bus_dma_tag_t, bus_size_t, bus_size_t, bus_size_t, + bus_dma_segment_t *, int, int *, int, paddr_t, paddr_t); + +/* + * bus_dmamap_t + * + * Describes a DMA mapping. + */ +struct machine_bus_dmamap { + /* + * PRIVATE MEMBERS: not for use by machine-independent code. + */ + bus_size_t _dm_size; /* largest DMA transfer mappable */ + int _dm_segcnt; /* number of segs this map can map */ + bus_size_t _dm_maxsegsz; /* largest possible segment */ + bus_size_t _dm_boundary; /* don't cross this */ + int _dm_flags; /* misc. flags */ + + void *_dm_cookie; /* cookie for bus-specific functions */ + + /* + * PUBLIC MEMBERS: these are used by machine-independent code. + */ + bus_size_t dm_mapsize; /* size of the mapping */ + int dm_nsegs; /* # valid segments in mapping */ + bus_dma_segment_t dm_segs[1]; /* segments; variable length */ +}; + +int generic_space_map(bus_space_tag_t, bus_addr_t, bus_size_t, int, + bus_space_handle_t *); +void generic_space_unmap(bus_space_tag_t, bus_space_handle_t, bus_size_t); +int generic_space_region(bus_space_tag_t, bus_space_handle_t, bus_size_t, + bus_size_t, bus_space_handle_t *); +void *generic_space_vaddr(bus_space_tag_t, bus_space_handle_t); +paddr_t generic_space_mmap(bus_space_tag_t, bus_addr_t, off_t, int, int); +uint8_t generic_space_read_1(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint16_t generic_space_read_2(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint32_t generic_space_read_4(bus_space_tag_t, bus_space_handle_t, bus_size_t); +uint64_t generic_space_read_8(bus_space_tag_t, bus_space_handle_t, bus_size_t); +void generic_space_read_raw_2(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_1(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint8_t); +void generic_space_write_2(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint16_t); +void generic_space_write_4(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint32_t); +void generic_space_write_8(bus_space_tag_t, bus_space_handle_t, bus_size_t, + uint64_t); +void generic_space_write_raw_2(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); +void generic_space_read_raw_4(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_raw_4(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); +void generic_space_read_raw_8(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, uint8_t *, bus_size_t); +void generic_space_write_raw_8(bus_space_tag_t, bus_space_handle_t, + bus_addr_t, const uint8_t *, bus_size_t); + +#endif /* _MACHINE_BUS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/cdefs.h b/lib/libc/include/riscv64-openbsd-none/riscv64/cdefs.h new file mode 100644 index 0000000000..951add3212 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/cdefs.h @@ -0,0 +1,16 @@ +/* $OpenBSD: cdefs.h,v 1.1 2021/04/23 02:42:16 drahn Exp $ */ + +#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_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/conf.h b/lib/libc/include/riscv64-openbsd-none/riscv64/conf.h new file mode 100644 index 0000000000..9dc1b949f2 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/conf.h @@ -0,0 +1,50 @@ +/* $OpenBSD: conf.h,v 1.4 2022/06/28 14:43:50 visa Exp $ */ + +/* + * Copyright (c) 1996 Christos Zoulas. 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 Christos Zoulas. + * 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 _MACHINE_CONF_H_ +#define _MACHINE_CONF_H_ + +#include + +#define mmread mmrw +#define mmwrite mmrw +cdev_decl(mm); + +/* open, close, ioctl */ +#define cdev_openprom_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) nullop, 0, \ + (dev_type_mmap((*))) enodev } + +cdev_decl(openprom); + +#endif /* _MACHINE_CONF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/cpu.h b/lib/libc/include/riscv64-openbsd-none/riscv64/cpu.h new file mode 100644 index 0000000000..8e6ecc4dca --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/cpu.h @@ -0,0 +1,284 @@ +/* $OpenBSD: cpu.h,v 1.24 2024/06/11 16:02:35 jca Exp $ */ + +/* + * Copyright (c) 2019 Mike Larkin + * Copyright (c) 2016 Dale Rahn + * + * 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_CPU_H_ +#define _MACHINE_CPU_H_ + +/* + * User-visible definitions + */ + +/* CTL_MACHDEP definitions. */ +#define CPU_COMPATIBLE 1 /* compatible property */ +#define CPU_MAXID 2 /* number of valid machdep ids */ + +#define CTL_MACHDEP_NAMES { \ + { 0, 0 }, \ + { "compatible", CTLTYPE_STRING }, \ +} + +#ifdef _KERNEL + +/* + * Kernel-only definitions + */ +#include +#include +#include + +/* All the CLKF_* macros take a struct clockframe * as an argument. */ + +#define clockframe trapframe +/* + * CLKF_USERMODE: Return TRUE/FALSE (1/0) depending on whether the + * frame came from USR mode or not. + */ +#define CLKF_USERMODE(frame) ((frame->tf_sstatus & SSTATUS_SPP) == 0) + +/* + * CLKF_INTR: True if we took the interrupt from inside another + * interrupt handler. + */ +#define CLKF_INTR(frame) (curcpu()->ci_idepth > 1) + +/* + * CLKF_PC: Extract the program counter from a clockframe + */ +#define CLKF_PC(frame) (frame->tf_sepc) + +/* + * PROC_PC: Find out the program counter for the given process. + */ +#define PROC_PC(p) ((p)->p_addr->u_pcb.pcb_tf->tf_sepc) +#define PROC_STACK(p) ((p)->p_addr->u_pcb.pcb_tf->tf_sp) + +#include +#include +#include +#include +#include + +struct cpu_info { + struct device *ci_dev; /* Device corresponding to this CPU */ + struct cpu_info *ci_next; + struct schedstate_percpu ci_schedstate; /* scheduler state */ + + u_int32_t ci_cpuid; + uint64_t ci_hartid; + int ci_node; + struct cpu_info *ci_self; + + struct proc *ci_curproc; + struct pmap *ci_curpm; + u_int32_t ci_randseed; + + struct pcb *ci_curpcb; + struct pcb *ci_idle_pcb; + + struct clockqueue ci_queue; + volatile int ci_timer_deferred; + + uint32_t ci_cpl; + uint32_t ci_ipending; + uint32_t ci_idepth; +#ifdef DIAGNOSTIC + int ci_mutex_level; +#endif + int ci_want_resched; + + struct opp_table *ci_opp_table; + volatile int ci_opp_idx; + volatile int ci_opp_max; + uint32_t ci_cpu_supply; + +#ifdef MULTIPROCESSOR + struct srp_hazard ci_srp_hazards[SRP_HAZARD_NUM]; +#define __HAVE_UVM_PERCPU + struct uvm_pmr_cache ci_uvm; + volatile int ci_flags; + uint64_t ci_satp; + vaddr_t ci_initstack_end; + int ci_ipi_reason; + + volatile int ci_ddb_paused; +#define CI_DDB_RUNNING 0 +#define CI_DDB_SHOULDSTOP 1 +#define CI_DDB_STOPPED 2 +#define CI_DDB_ENTERDDB 3 +#define CI_DDB_INDDB 4 + +#endif + +#ifdef GPROF + struct gmonparam *ci_gmon; + struct clockintr ci_gmonclock; +#endif + + char ci_panicbuf[512]; +}; + +#define CPUF_PRIMARY (1<<0) +#define CPUF_AP (1<<1) +#define CPUF_IDENTIFY (1<<2) +#define CPUF_IDENTIFIED (1<<3) +#define CPUF_PRESENT (1<<4) +#define CPUF_GO (1<<5) +#define CPUF_RUNNING (1<<6) + +static inline struct cpu_info * +curcpu(void) +{ + struct cpu_info *__ci = NULL; + __asm volatile("mv %0, tp" : "=&r"(__ci)); + return (__ci); +} + +extern uint32_t boot_hart; /* The hart we booted on. */ +extern struct cpu_info cpu_info_primary; +extern struct cpu_info *cpu_info_list; + +#ifndef MULTIPROCESSOR + +#define cpu_number() 0 +#define CPU_IS_PRIMARY(ci) 1 +#define CPU_IS_RUNNING(ci) 1 +#define CPU_INFO_ITERATOR int +#define CPU_INFO_FOREACH(cii, ci) \ + for (cii = 0, ci = curcpu(); ci != NULL; ci = NULL) +#define CPU_INFO_UNIT(ci) 0 +#define MAXCPUS 1 +#define cpu_unidle(ci) + +#else + +#define cpu_number() (curcpu()->ci_cpuid) +#define CPU_IS_PRIMARY(ci) ((ci) == &cpu_info_primary) +#define CPU_IS_RUNNING(ci) ((ci)->ci_flags & CPUF_RUNNING) +#define CPU_INFO_ITERATOR int +#define CPU_INFO_FOREACH(cii, ci) for (cii = 0, ci = cpu_info_list; \ + ci != NULL; ci = ci->ci_next) +#define CPU_INFO_UNIT(ci) ((ci)->ci_dev ? (ci)->ci_dev->dv_unit : 0) +#define MAXCPUS 32 + +extern struct cpu_info *cpu_info[MAXCPUS]; + +void cpu_boot_secondary_processors(void); + +#endif /* !MULTIPROCESSOR */ + +/* Zihintpause ratified extension */ +#define CPU_BUSY_CYCLE() __asm volatile(".long 0x0100000f" ::: "memory") + +#define curpcb curcpu()->ci_curpcb + +static inline unsigned int +cpu_rnd_messybits(void) +{ + // Should do bit reversal ^ with csr_read(time); + return csr_read(time); +} + +/* + * Scheduling glue + */ +#define aston(p) ((p)->p_md.md_astpending = 1) +#define setsoftast() aston(curcpu()->ci_curproc) + +/* + * Notify the current process (p) that it has a signal pending, + * process as soon as possible. + */ + +#ifdef MULTIPROCESSOR +void cpu_unidle(struct cpu_info *ci); +#define signotify(p) (aston(p), cpu_unidle((p)->p_cpu)) +void cpu_kick(struct cpu_info *); +#else +#define cpu_kick(ci) +#define cpu_unidle(ci) +#define signotify(p) setsoftast() +#endif + +/* + * Preempt the current process if in interrupt from user mode, + * or after the current trap/syscall if in system mode. + */ +void need_resched(struct cpu_info *); +#define clear_resched(ci) ((ci)->ci_want_resched = 0) + +/* + * Give a profiling tick to the current process when the user profiling + * buffer pages are invalid. On the i386, request an ast to send us + * through trap(), marking the proc as needing a profiling tick. + */ +#define need_proftick(p) aston(p) + +// asm code to start new kernel contexts. +void proc_trampoline(void); + +/* + * Random cruft + */ +void dumpconf(void); + +static inline void +intr_enable(void) +{ + __asm volatile("csrsi sstatus, %0" :: "i" (SSTATUS_SIE)); +} + +static inline u_long +intr_disable(void) +{ + uint64_t ret; + + __asm volatile( + "csrrci %0, sstatus, %1" + : "=&r" (ret) : "i" (SSTATUS_SIE) + ); + + return (ret & (SSTATUS_SIE)); +} + +static inline void +intr_restore(u_long s) +{ + __asm volatile("csrs sstatus, %0" :: "r" (s)); +} + +void delay (unsigned); +#define DELAY(x) delay(x) + +extern void (*cpu_startclock_fcn)(void); + +void fpu_save(struct proc *, struct trapframe *); +void fpu_load(struct proc *); + +extern int cpu_errata_sifive_cip_1200; + +#define cpu_idle_enter() do { /* nothing */ } while (0) +#define cpu_idle_leave() do { /* nothing */ } while (0) + +#endif /* _KERNEL */ + +#ifdef MULTIPROCESSOR +#include +#endif /* MULTIPROCESSOR */ + +#endif /* !_MACHINE_CPU_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/cpufunc.h b/lib/libc/include/riscv64-openbsd-none/riscv64/cpufunc.h new file mode 100644 index 0000000000..f4b61288bb --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/cpufunc.h @@ -0,0 +1,103 @@ +/* $OpenBSD: cpufunc.h,v 1.6 2023/08/21 20:17:30 miod Exp $ */ + +/*- + * Copyright (c) 2014 Andrew Turner + * 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 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 AUTHOR 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. + * + * $FreeBSD: head/sys/cpu/include/cpufunc.h 299683 2016-05-13 16:03:50Z andrew $ + */ + +#ifndef _MACHINE_CPUFUNC_H_ +#define _MACHINE_CPUFUNC_H_ + +static __inline void +breakpoint(void) +{ + __asm("ebreak"); +} + +#ifdef _KERNEL + +#include + +#define rdcycle() csr_read(cycle) +#define rdtime() csr_read(time) +#define rdinstret() csr_read(instret) +#define rdhpmcounter(n) csr_read(hpmcounter##n) + +static __inline void +fence_i(void) +{ + __asm volatile("fence.i" ::: "memory"); +} + +static __inline void +sfence_vma(void) +{ + __asm volatile("sfence.vma" ::: "memory"); +} + +static __inline void +sfence_vma_page(uintptr_t addr) +{ + __asm volatile("sfence.vma %0" + : + : "r" (addr) + : "memory"); +} + +// XXX ASIDs in riscv64 are only 16 bits. +static __inline void +sfence_vma_asid(uint64_t asid) +{ + __asm volatile("sfence.vma x0, %0" + : + : "r" (asid) + : "memory"); +} + +static __inline void +sfence_vma_page_asid(uintptr_t addr, uint64_t asid) +{ + __asm volatile("sfence.vma %0, %1" + : + : "r" (addr), "r" (asid) + : "memory"); +} + +extern int64_t dcache_line_size; +extern int64_t icache_line_size; + +extern void (*cpu_dcache_wbinv_range)(paddr_t, psize_t); +extern void (*cpu_dcache_inv_range)(paddr_t, psize_t); +extern void (*cpu_dcache_wb_range)(paddr_t, psize_t); + +static __inline void +load_satp(uint64_t val) +{ + __asm volatile("csrw satp, %0" :: "r"(val)); +} + +#endif /* _KERNEL */ +#endif /* _MACHINE_CPUFUNC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/db_machdep.h b/lib/libc/include/riscv64-openbsd-none/riscv64/db_machdep.h new file mode 100644 index 0000000000..0d0e4fdfb9 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/db_machdep.h @@ -0,0 +1,93 @@ +/* $OpenBSD: db_machdep.h,v 1.5 2021/08/30 08:11:12 jasper Exp $ */ + +/* + * Copyright (c) 2019 Brian Bamsch + * Copyright (c) 2015-2016 Ruslan Bukin + * All rights reserved. + * + * Portions of this software were developed by SRI International and the + * University of Cambridge Computer Laboratory under DARPA/AFRL contract + * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. + * + * Portions of this software were developed by the University of Cambridge + * Computer Laboratory as part of the CTSRD Project, with support from the + * UK Higher Education Innovation Fund (HEIF). + * + * 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 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 AUTHOR 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. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_DB_MACHDEP_H_ +#define _MACHINE_DB_MACHDEP_H_ + +#include +#include +#include +#include +#include + +#define T_BREAKPOINT (EXCP_BREAKPOINT) +#define T_WATCHPOINT (0) + +typedef long db_expr_t; + +typedef trapframe_t db_regs_t; + +extern db_regs_t ddb_regs; +#define DDB_REGS (&ddb_regs) + +#define PC_REGS(regs) ((vaddr_t)(regs)->tf_ra) +#define SET_PC_REGS(regs, value) (regs)->tf_ra = (register_t)(value) + +#define BKPT_INST (KERNEL_BREAKPOINT) +#define BKPT_SIZE (INSN_SIZE) +#define BKPT_SET(inst) (BKPT_INST) + +#define IS_BREAKPOINT_TRAP(type, code) ((type) == T_BREAKPOINT) +#define IS_WATCHPOINT_TRAP(type, code) ((type) == T_WATCHPOINT) + +#define inst_trap_return(ins) (ins == 0x10000073) /* eret */ +#define inst_return(ins) (ins == 0x00008067) /* ret */ +#define inst_call(ins) (((ins) & 0x7f) == 0x6f || \ + ((ins) & 0x7f) == 0x67) /* jal, jalr */ +#define inst_branch(ins) (((ins) & 0x7f) == 0x63) /* branch */ + +#define next_instr_address(pc, bd) ((bd) ? (pc) : ((pc) + INSN_SIZE)) + +#define DB_MACHINE_COMMANDS + +#define SOFTWARE_SSTEP + +int db_trapper(vaddr_t, u_int, trapframe_t *, int); +void db_machine_init (void); +vaddr_t db_branch_taken(u_int inst, vaddr_t pc, db_regs_t *regs); + +#define branch_taken(ins, pc, fun, regs) \ + db_branch_taken((ins), (pc), (regs)) + +/* For ddb_state */ +#define DDB_STATE_NOT_RUNNING 0 +#define DDB_STATE_RUNNING 1 +#define DDB_STATE_EXITING 2 + +#endif /* !_MACHINE_DB_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/disklabel.h b/lib/libc/include/riscv64-openbsd-none/riscv64/disklabel.h new file mode 100644 index 0000000000..fcb739943e --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/disklabel.h @@ -0,0 +1,26 @@ +/* $OpenBSD: disklabel.h,v 1.2 2021/05/12 01:20:52 jsg Exp $ */ + +/* + * Copyright (c) 2014 Patrick Wildt + * + * 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_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/elf.h b/lib/libc/include/riscv64-openbsd-none/riscv64/elf.h new file mode 100644 index 0000000000..651c966fb8 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/elf.h @@ -0,0 +1,52 @@ +/* $OpenBSD: elf.h,v 1.3 2024/07/14 09:48:49 jca Exp $ */ + +/*- + * Copyright (c) 1996-1997 John D. Polstra. + * 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 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 AUTHOR 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_ELF_H_ +#define _MACHINE_ELF_H_ + +/* + * ELF definitions for the RISC-V architecture. + */ + +#ifdef _KERNEL +# define __HAVE_CPU_HWCAP +extern unsigned long hwcap; +#endif /* _KERNEL */ + +/* Flags passed in AT_HWCAP */ +#define HWCAP_ISA_BIT(c) (1 << ((c) - 'a')) +#define HWCAP_ISA_I HWCAP_ISA_BIT('i') +#define HWCAP_ISA_M HWCAP_ISA_BIT('m') +#define HWCAP_ISA_A HWCAP_ISA_BIT('a') +#define HWCAP_ISA_F HWCAP_ISA_BIT('f') +#define HWCAP_ISA_D HWCAP_ISA_BIT('d') +#define HWCAP_ISA_C HWCAP_ISA_BIT('c') +#define HWCAP_ISA_G \ + (HWCAP_ISA_I | HWCAP_ISA_M | HWCAP_ISA_A | HWCAP_ISA_F | HWCAP_ISA_D) + +#endif /* !_MACHINE_ELF_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/endian.h b/lib/libc/include/riscv64-openbsd-none/riscv64/endian.h new file mode 100644 index 0000000000..b63c54e850 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/endian.h @@ -0,0 +1,29 @@ +/* $OpenBSD: endian.h,v 1.3 2022/03/22 06:46:45 miod Exp $ */ + +/* + * Copyright (c) 2015 David Gwynne + * + * 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_ENDIAN_H_ +#define _MACHINE_ENDIAN_H_ + +#define _BYTE_ORDER _LITTLE_ENDIAN +#define __STRICT_ALIGNMENT + +#ifndef __FROM_SYS__ENDIAN +#include +#endif + +#endif /* _MACHINE_ENDIAN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/exec.h b/lib/libc/include/riscv64-openbsd-none/riscv64/exec.h new file mode 100644 index 0000000000..a6073819af --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/exec.h @@ -0,0 +1,30 @@ +/* $OpenBSD: exec.h,v 1.2 2021/05/12 01:20:52 jsg Exp $ */ + +/* + * Copyright (c) 2014 Patrick Wildt + * + * 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_RISCV + +#endif \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/fdt.h b/lib/libc/include/riscv64-openbsd-none/riscv64/fdt.h new file mode 100644 index 0000000000..536ed4d04b --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/fdt.h @@ -0,0 +1,59 @@ +/* $OpenBSD: fdt.h,v 1.4 2022/05/30 17:39:09 kettenis Exp $ */ + +/* + * Copyright (c) 2016 Patrick Wildt + * + * 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 __RISCV_FDT_H__ +#define __RISCV_FDT_H__ + +#define _RISCV64_BUS_DMA_PRIVATE +#include + +struct fdt_attach_args { + const char *fa_name; + int fa_node; + bus_space_tag_t fa_iot; + bus_dma_tag_t fa_dmat; + struct fdt_reg *fa_reg; + int fa_nreg; + uint32_t *fa_intr; + int fa_nintr; + int fa_acells; + int fa_scells; +}; + +extern int stdout_node; +extern int stdout_speed; +extern bus_space_tag_t fdt_cons_bs_tag; + +void *fdt_find_cons(const char *); + +#define fdt_intr_enable riscv_intr_enable +#define fdt_intr_establish riscv_intr_establish_fdt +#define fdt_intr_establish_idx riscv_intr_establish_fdt_idx +#define fdt_intr_establish_idx_cpu riscv_intr_establish_fdt_idx_cpu +#define fdt_intr_establish_imap riscv_intr_establish_fdt_imap +#define fdt_intr_establish_imap_cpu riscv_intr_establish_fdt_imap_cpu +#define fdt_intr_establish_msi riscv_intr_establish_fdt_msi +#define fdt_intr_establish_msi_cpu riscv_intr_establish_fdt_msi_cpu +#define fdt_intr_disable riscv_intr_disable +#define fdt_intr_disestablish riscv_intr_disestablish_fdt +#define fdt_intr_get_parent riscv_intr_get_parent +#define fdt_intr_parent_establish riscv_intr_parent_establish_fdt +#define fdt_intr_parent_disestablish riscv_intr_parent_disestablish_fdt +#define fdt_intr_register riscv_intr_register_fdt + +#endif /* __RISCV_FDT_H__ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/fenv.h b/lib/libc/include/riscv64-openbsd-none/riscv64/fenv.h new file mode 100644 index 0000000000..e1645e961c --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/fenv.h @@ -0,0 +1,95 @@ +/* $OpenBSD: fenv.h,v 1.2 2021/05/12 02:28:25 jsg Exp $ */ + +/* + * Copyright (c) 2011 Martynas Venckus + * + * 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_FENV_H_ +#define _MACHINE_FENV_H_ + +/* + * Each symbol representing a floating point exception expands to an integer + * constant expression with values, such that bitwise-inclusive ORs of _all + * combinations_ of the constants result in distinct values. + * + * We use such values that allow direct bitwise operations on FPU registers. + */ +#define FE_INVALID 0x10 +#define FE_DIVBYZERO 0x08 +#define FE_OVERFLOW 0x04 +#define FE_UNDERFLOW 0x02 +#define FE_INEXACT 0x01 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * exception constants defined above. + */ +#define FE_ALL_EXCEPT (FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | \ + FE_UNDERFLOW | FE_INEXACT ) + +/* + * Each symbol representing the rounding direction, expands to an integer + * constant expression whose value is distinct non-negative value. + * + * We use such values that allow direct bitwise operations on FPU registers. + */ +#define FE_TONEAREST 0x0 +#define FE_TOWARDZERO 0x1 +#define FE_DOWNWARD 0x2 +#define FE_UPWARD 0x3 +#define FE_TONEARESTFROMZERO 0x4 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * rounding direction constants defined above. + */ +#define _ROUND_MASK (FE_TONEAREST | FE_TOWARDZERO | FE_DOWNWARD | \ + FE_UPWARD | FE_TONEARESTFROMZERO) +#define _ROUND_SHIFT 5 + +/* + * fenv_t represents the entire floating-point environment. + */ +typedef unsigned int fenv_t; + +/* + * The following constant represents the default floating-point environment + * (that is, the one installed at program startup) and has type pointer to + * const-qualified fenv_t. + * + * It can be used as an argument to the functions within the header + * that manage the floating-point environment, namely fesetenv() and + * feupdateenv(). + */ +__BEGIN_DECLS +extern fenv_t __fe_dfl_env; +__END_DECLS +#define FE_DFL_ENV ((const fenv_t *)&__fe_dfl_env) + +/* + * fexcept_t represents the floating-point status flags collectively, including + * any status the implementation associates with the flags. + * + * A floating-point status flag is a system variable whose value is set (but + * never cleared) when a floating-point exception is raised, which occurs as a + * side effect of exceptional floating-point arithmetic to provide auxiliary + * information. + * + * A floating-point control mode is a system variable whose value may be set by + * the user to affect the subsequent behavior of floating-point arithmetic. + */ +typedef unsigned int fexcept_t; + +#endif /* !_MACHINE_FENV_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/frame.h b/lib/libc/include/riscv64-openbsd-none/riscv64/frame.h new file mode 100644 index 0000000000..e15698128f --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/frame.h @@ -0,0 +1,99 @@ +/* $OpenBSD: frame.h,v 1.3 2022/02/24 14:19:10 visa Exp $ */ + +/* + * Copyright (c) 2019 Brian Bamsch + * Copyright (c) 2016 Dale Rahn + * Copyright (c) 2015 Ruslan Bukin + * All rights reserved. + * + * Portions of this software were developed by SRI International and the + * University of Cambridge Computer Laboratory under DARPA/AFRL contract + * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. + * + * Portions of this software were developed by the University of Cambridge + * Computer Laboratory as part of the CTSRD Project, with support from the + * UK Higher Education Innovation Fund (HEIF). + * + * 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 copyright holder 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 AUTHOR 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 AUTHOR 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_FRAME_H_ +#define _MACHINE_FRAME_H_ + +#ifndef _LOCORE + +#include + +/* + * Exception/Trap Stack Frame + */ +#define clockframe trapframe +typedef struct trapframe { + /* Standard Registers */ + register_t tf_ra; + register_t tf_sp; + register_t tf_gp; + register_t tf_tp; + register_t tf_t[7]; + register_t tf_s[12]; + register_t tf_a[8]; + /* Supervisor Trap CSRs */ + register_t tf_sepc; + register_t tf_sstatus; + register_t tf_stval; + register_t tf_scause; + register_t tf_pad; +} trapframe_t; + +/* + * pushed on stack for signal delivery + */ +struct sigframe { + int sf_signum; + struct sigcontext sf_sc; + siginfo_t sf_si; +}; + +/* + * System stack frames. + */ + +/* + * Stack frame inside cpu_switch() + */ +struct switchframe { + register_t sf_s[12]; + register_t sf_ra; + register_t sf_pad; +}; + +struct callframe { + struct callframe *f_frame; + register_t f_ra; +}; + +#endif /* !_LOCORE */ + +#endif /* !_MACHINE_FRAME_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/ieee.h b/lib/libc/include/riscv64-openbsd-none/riscv64/ieee.h new file mode 100644 index 0000000000..74d6e987a9 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/ieee.h @@ -0,0 +1,148 @@ +/* $OpenBSD: ieee.h,v 1.3 2021/05/12 01:20:52 jsg Exp $ */ +/* $NetBSD: ieee.h,v 1.1 1996/09/30 16:34:25 ws Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)ieee.h 8.1 (Berkeley) 6/11/93 + */ + +/* + * ieee.h defines the machine-dependent layout of the machine's IEEE + * floating point. It does *not* define (yet?) any of the rounding + * mode bits, exceptions, and so forth. + */ + +/* + * Define the number of bits in each fraction and exponent. + * + * k k+1 + * Note that 1.0 x 2 == 0.1 x 2 and that denorms are represented + * + * (-exp_bias+1) + * as fractions that look like 0.fffff x 2 . This means that + * + * -126 + * the number 0.10000 x 2 , for instance, is the same as the normalized + * + * -127 -128 + * float 1.0 x 2 . Thus, to represent 2 , we need one leading zero + * + * -129 + * in the fraction; to represent 2 , we need two, and so on. This + * + * (-exp_bias-fracbits+1) + * implies that the smallest denormalized number is 2 + * + * for whichever format we are talking about: for single precision, for + * + * -126 -149 + * instance, we get .00000000000000000000001 x 2 , or 1.0 x 2 , and + * + * -149 == -127 - 23 + 1. + */ +#define SNG_EXPBITS 8 +#define SNG_FRACBITS 23 + +#define DBL_EXPBITS 11 +#define DBL_FRACHBITS 20 +#define DBL_FRACLBITS 32 +#define DBL_FRACBITS 52 + +#define EXT_EXPBITS 15 +#define EXT_FRACHBITS 16 +#define EXT_FRACHMBITS 32 +#define EXT_FRACLMBITS 32 +#define EXT_FRACLBITS 32 +#define EXT_FRACBITS 112 + +#define EXT_IMPLICIT_NBIT + +#define EXT_TO_ARRAY32(p, a) do { \ + (a)[0] = (uint32_t)(p)->ext_fracl; \ + (a)[1] = (uint32_t)(p)->ext_fraclm; \ + (a)[2] = (uint32_t)(p)->ext_frachm; \ + (a)[3] = (uint32_t)(p)->ext_frach; \ +} while (0) + +struct ieee_single { + u_int sng_frac:23; + u_int sng_exp:8; + u_int sng_sign:1; +}; + +struct ieee_double { + u_int dbl_fracl; + u_int dbl_frach:20; + u_int dbl_exp:11; + u_int dbl_sign:1; +}; + +struct ieee_ext { + u_int ext_fracl; + u_int ext_fraclm; + u_int ext_frachm; + u_int ext_frach:16; + u_int ext_exp:15; + u_int ext_sign:1; +}; + +/* + * Floats whose exponent is in [1..INFNAN) (of whatever type) are + * `normal'. Floats whose exponent is INFNAN are either Inf or NaN. + * Floats whose exponent is zero are either zero (iff all fraction + * bits are zero) or subnormal values. + * + * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its + * high fraction; if the bit is set, it is a `quiet NaN'. + */ +#define SNG_EXP_INFNAN 255 +#define DBL_EXP_INFNAN 2047 +#define EXT_EXP_INFNAN 32767 + +#if 0 +#define SNG_QUIETNAN (1 << 22) +#define DBL_QUIETNAN (1 << 19) +#define EXT_QUIETNAN (1 << 15) +#endif + +/* + * Exponent biases. + */ +#define SNG_EXP_BIAS 127 +#define DBL_EXP_BIAS 1023 +#define EXT_EXP_BIAS 16383 \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/ieeefp.h b/lib/libc/include/riscv64-openbsd-none/riscv64/ieeefp.h new file mode 100644 index 0000000000..e8f7507588 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/ieeefp.h @@ -0,0 +1,25 @@ +/* $OpenBSD: ieeefp.h,v 1.3 2021/04/30 00:25:52 drahn Exp $ */ + +/* + * Based on ieeefp.h written by J.T. Conklin, Apr 28, 1995 + * Public domain. + */ + +#ifndef _MACHINE_IEEEFP_H_ +#define _MACHINE_IEEEFP_H_ + +typedef int fp_except; +#define FP_X_INV 0x10 /* invalid operation exception */ +#define FP_X_DZ 0x08 /* divide-by-zero exception */ +#define FP_X_OFL 0x04 /* overflow exception */ +#define FP_X_UFL 0x02 /* underflow exception */ +#define FP_X_IMP 0x01 /* imprecise (loss of precision) */ + +typedef enum { + FP_RN=0, /* round to nearest representable number */ + FP_RZ=1, /* round to zero (truncate) */ + FP_RM=2, /* round toward negative infinity */ + FP_RP=3 /* round toward positive infinity */ +} fp_rnd; + +#endif /* _MACHINE_IEEEFP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/intr.h b/lib/libc/include/riscv64-openbsd-none/riscv64/intr.h new file mode 100644 index 0000000000..14ef73c213 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/intr.h @@ -0,0 +1,227 @@ +/* $OpenBSD: intr.h,v 1.10 2025/05/19 02:13:15 jsg Exp $ */ + +/* + * Copyright (c) 2001-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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_INTR_H_ +#define _MACHINE_INTR_H_ + +/* + * The interrupt level ipl is a logical level; per-platform interrupt + * code will turn it into the appropriate hardware interrupt masks + * values. + * + * Interrupt sources on the CPU are kept enabled regardless of the + * current ipl value; individual hardware sources interrupting while + * logically masked are masked on the fly, remembered as pending, and + * unmasked at the first splx() opportunity. + */ +#ifdef _KERNEL + +/* Interrupt priority `levels'; not mutually exclusive. */ +#define IPL_NONE 0 /* nothing */ +#define IPL_SOFTCLOCK 2 /* soft clock interrupts */ +#define IPL_SOFTNET 3 /* soft network interrupts */ +#define IPL_SOFTTTY 4 /* soft terminal interrupts */ +#define IPL_BIO 5 /* block I/O */ +#define IPL_NET 6 /* network */ +#define IPL_TTY 7 /* terminal */ +#define IPL_VM 8 /* memory allocation */ +#define IPL_AUDIO 9 /* audio */ +#define IPL_CLOCK 10 /* clock */ +#define IPL_SCHED IPL_CLOCK +#define IPL_STATCLOCK IPL_CLOCK +#define IPL_HIGH 11 /* everything */ +#define IPL_IPI 12 /* interprocessor interrupt */ +#define NIPL 13 /* number of levels */ + +#define IPL_MPFLOOR IPL_TTY +/* Interrupt priority 'flags'. */ +#define IPL_IRQMASK 0xf /* priority only */ +#define IPL_FLAGMASK 0xf00 /* flags only*/ +#define IPL_MPSAFE 0x100 /* 'mpsafe' interrupt, no kernel lock */ + +/* Interrupt sharing types. */ +#define IST_NONE 0 /* none */ +#define IST_PULSE 1 /* pulsed */ +#define IST_EDGE 2 /* edge-triggered */ +#define IST_LEVEL 3 /* level-triggered */ + +#define IST_LEVEL_LOW IST_LEVEL +#define IST_LEVEL_HIGH 4 +#define IST_EDGE_FALLING IST_EDGE +#define IST_EDGE_RISING 5 +#define IST_EDGE_BOTH 6 + +enum { + IRQ_SOFTWARE_USER, + IRQ_SOFTWARE_SUPERVISOR, + IRQ_SOFTWARE_HYPERVISOR, + IRQ_SOFTWARE_MACHINE, + IRQ_TIMER_USER, + IRQ_TIMER_SUPERVISOR, + IRQ_TIMER_HYPERVISOR, + IRQ_TIMER_MACHINE, + IRQ_EXTERNAL_USER, + IRQ_EXTERNAL_SUPERVISOR, + IRQ_EXTERNAL_HYPERVISOR, + IRQ_EXTERNAL_MACHINE, + INTC_NIRQS +}; + +#define __USE_MI_SOFTINTR + +#include + +#ifndef _LOCORE +#include + +void softintr(int); + +int splraise(int); +int spllower(int); +void splx(int); + +void riscv_cpu_intr(void *); +void riscv_do_pending_intr(int); +void riscv_set_intr_func(int (*raise)(int), int (*lower)(int), + void (*x)(int), void (*setipl)(int)); +void riscv_set_intr_handler(void (*intr_handle)(void *)); + +struct machine_intr_handle { + struct interrupt_controller *ih_ic; + void *ih_ih; +}; + +struct riscv_intr_func { + int (*raise)(int); + int (*lower)(int); + void (*x)(int); + void (*setipl)(int); +}; + +extern struct riscv_intr_func riscv_intr_func; + +#define splraise(cpl) (riscv_intr_func.raise(cpl)) +#define _splraise(cpl) (riscv_intr_func.raise(cpl)) +#define spllower(cpl) (riscv_intr_func.lower(cpl)) +#define splx(cpl) (riscv_intr_func.x(cpl)) + +#define splsoftclock() splraise(IPL_SOFTCLOCK) +#define splsoftnet() splraise(IPL_SOFTNET) +#define splsofttty() splraise(IPL_SOFTTTY) +#define splbio() splraise(IPL_BIO) +#define splnet() splraise(IPL_NET) +#define spltty() splraise(IPL_TTY) +#define splvm() splraise(IPL_VM) +#define splaudio() splraise(IPL_AUDIO) +#define splclock() splraise(IPL_CLOCK) +#define splsched() splraise(IPL_SCHED) +#define splstatclock() splraise(IPL_STATCLOCK) +#define splhigh() splraise(IPL_HIGH) + +#define spl0() spllower(IPL_NONE) + +void intr_barrier(void *); + +void riscv_init_smask(void); /* XXX */ +extern uint32_t riscv_smask[NIPL]; + +void riscv_clock_register(void (*)(void), void (*)(u_int), void (*)(int), + void (*)(void)); + +/* + **** interrupt controller structure and routines **** + */ +struct cpu_info; +struct interrupt_controller { + int ic_node; + void *ic_cookie; + void *(*ic_establish)(void *, int *, int, struct cpu_info *, + int (*)(void *), void *, char *); + void *(*ic_establish_msi)(void *, uint64_t *, uint64_t *, int, + struct cpu_info *, int (*)(void *), void *, char *); + void (*ic_disestablish)(void *); + void (*ic_enable)(void *); + void (*ic_disable)(void *); + void (*ic_route)(void *, int, struct cpu_info *); + void (*ic_cpu_enable)(void); + void (*ic_barrier)(void *); + + LIST_ENTRY(interrupt_controller) ic_list; + uint32_t ic_phandle; + uint32_t ic_cells; +}; + +void riscv_intr_init_fdt(void); +void riscv_intr_register_fdt(struct interrupt_controller *); +void *riscv_intr_establish_fdt(int, int, int (*)(void *), + void *, char *); +void *riscv_intr_establish_fdt_idx(int, int, int, int (*)(void *), + void *, char *); +void *riscv_intr_establish_fdt_idx_cpu(int, int, int, struct cpu_info *, + int (*)(void *), void *, char *); +void *riscv_intr_establish_fdt_imap_cpu(int, int *, int, int, + struct cpu_info *, int (*)(void *), void *, char *); +void *riscv_intr_establish_fdt_msi(int, uint64_t *, uint64_t *, int, + int (*)(void *), void *, char *); +void *riscv_intr_establish_fdt_msi_cpu(int, uint64_t *, uint64_t *, int, + struct cpu_info *, int (*)(void *), void *, char *); +void riscv_intr_disestablish_fdt(void *); +void riscv_intr_enable(void *); +void riscv_intr_disable(void *); +void riscv_intr_route(void *, int, struct cpu_info *); +void riscv_intr_cpu_enable(void); + +#define IPI_NOP 0 +#define IPI_DDB (1 << 0) + +void intr_send_ipi(struct cpu_info *, int); + +#ifdef DIAGNOSTIC +/* + * Although this function is implemented in MI code, it must be in this MD + * header because we don't want this header to include MI includes. + */ +void splassert_fail(int, int, const char *); +extern int splassert_ctl; +void riscv_splassert_check(int, const char *); +#define splassert(__wantipl) do { \ + if (splassert_ctl > 0) { \ + riscv_splassert_check(__wantipl, __func__); \ + } \ +} while (0) +#define splsoftassert(wantipl) splassert(wantipl) +#else +#define splassert(wantipl) do { /* nothing */ } while (0) +#define splsoftassert(wantipl) do { /* nothing */ } while (0) +#endif + +#endif /* ! _LOCORE */ + +#endif /* _KERNEL */ + +#endif /* _MACHINE_INTR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/kcore.h b/lib/libc/include/riscv64-openbsd-none/riscv64/kcore.h new file mode 100644 index 0000000000..484ee5d0ee --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/kcore.h @@ -0,0 +1,16 @@ +/* $OpenBSD: kcore.h,v 1.2 2021/05/12 01:20:52 jsg Exp $ */ + +/* public domain */ + +/* Make sure this is larger than DRAM_BLOCKS on all arm-based platforms */ +#define NPHYS_RAM_SEGS 8 + +typedef struct cpu_kcore_hdr { + u_int64_t kernelbase; /* value of KERNEL_BASE */ + u_int64_t kerneloffs; /* offset of kernel in RAM */ + u_int64_t staticsize; /* size of contiguous mapping */ + u_int64_t pmap_kernel_l1; /* pmap_kernel()->pm_l1 */ + u_int64_t pmap_kernel_l2; /* pmap_kernel()->pm_l2 */ + u_int64_t reserved[11]; + phys_ram_seg_t ram_segs[NPHYS_RAM_SEGS]; +} cpu_kcore_hdr_t; \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/limits.h b/lib/libc/include/riscv64-openbsd-none/riscv64/limits.h new file mode 100644 index 0000000000..e06dde0b2b --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/limits.h @@ -0,0 +1,56 @@ +/* $OpenBSD: limits.h,v 1.2 2021/06/25 19:22:51 matthieu Exp $ */ +/* $NetBSD: limits.h,v 1.4 2003/04/28 23:16:18 bjh21 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 + +#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 (ULONG_MAX) /* max unsigned quad */ +#define QUAD_MAX (LONG_MAX) /* max signed quad */ +#define QUAD_MIN (LONG_MIN) /* min signed quad */ + +#endif /* __BSD_VISIBLE */ + +#endif /* _MACHINE_LIMITS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/loadfile_machdep.h b/lib/libc/include/riscv64-openbsd-none/riscv64/loadfile_machdep.h new file mode 100644 index 0000000000..c6b1f00082 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/loadfile_machdep.h @@ -0,0 +1,53 @@ +/* $OpenBSD: loadfile_machdep.h,v 1.2 2021/04/23 15:31:12 drahn Exp $ */ +/* $NetBSD: loadfile_machdep.h,v 1.1 1999/04/29 03:17:12 tsubai Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * 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. + */ + +#define BOOT_ELF +#define ELFSIZE 64 + +#define LOAD_KERNEL (LOAD_ALL & ~LOAD_TEXTA) +#define COUNT_KERNEL (COUNT_ALL & ~COUNT_TEXTA) + +extern u_long efi_loadaddr; +#define LOADADDR(a) (((((u_long)(a)) + offset)&0x3fffffffff) + \ + efi_loadaddr) +#define ALIGNENTRY(a) ((u_long)(a)) +#define READ(f, b, c) read((f), (void *)LOADADDR(b), (c)) +#define BCOPY(s, d, c) memcpy((void *)LOADADDR(d), (void *)(s), (c)) +#define BZERO(d, c) memset((void *)LOADADDR(d), 0, (c)) +#define WARN(a) (void)(printf a, \ + printf((errno ? ": %s\n" : "\n"), \ + strerror(errno))) +#define PROGRESS(a) (void) printf a +#define ALLOC(a) alloc(a) +#define FREE(a, b) free(a, b) + +void run_loadfile(uint64_t *, int); \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/mplock.h b/lib/libc/include/riscv64-openbsd-none/riscv64/mplock.h new file mode 100644 index 0000000000..1a87e05398 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/mplock.h @@ -0,0 +1,10 @@ +/* $OpenBSD: mplock.h,v 1.1 2021/06/27 20:36:57 kettenis Exp $ */ + +/* public domain */ + +#ifndef _MACHINE_MPLOCK_H_ +#define _MACHINE_MPLOCK_H_ + +#define __USE_MI_MPLOCK + +#endif /* !_MACHINE_MPLOCK_H */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/mutex.h b/lib/libc/include/riscv64-openbsd-none/riscv64/mutex.h new file mode 100644 index 0000000000..bc6b8cbb83 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/mutex.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mutex.h,v 1.1 2021/04/23 02:42:16 drahn Exp $ */ + +#define __USE_MI_MUTEX \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/openpromio.h b/lib/libc/include/riscv64-openbsd-none/riscv64/openpromio.h new file mode 100644 index 0000000000..4f49bf5934 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/openpromio.h @@ -0,0 +1,57 @@ +/* $OpenBSD: openpromio.h,v 1.1 2021/04/23 12:01:03 jsg Exp $ */ +/* $NetBSD: openpromio.h,v 1.1.1.1 1998/06/20 04:58:52 eeh Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)openpromio.h 8.1 (Berkeley) 6/11/93 + */ + +struct opiocdesc { + int op_nodeid; /* passed or returned node id */ + int op_namelen; /* length of op_name */ + char *op_name; /* pointer to field name */ + int op_buflen; /* length of op_buf (value-result) */ + char *op_buf; /* pointer to field value */ +}; + +#define OPIOCGET _IOWR('O', 1, struct opiocdesc) /* get openprom field */ +#define OPIOCSET _IOW('O', 2, struct opiocdesc) /* set openprom field */ +#define OPIOCNEXTPROP _IOWR('O', 3, struct opiocdesc) /* get next property */ +#define OPIOCGETOPTNODE _IOR('O', 4, int) /* get openprom field */ +#define OPIOCGETNEXT _IOWR('O', 5, int) /* get next node of node */ +#define OPIOCGETCHILD _IOWR('O', 6, int) /* get first child of node */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/param.h b/lib/libc/include/riscv64-openbsd-none/riscv64/param.h new file mode 100644 index 0000000000..1260fa3a3c --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/param.h @@ -0,0 +1,78 @@ +/* $OpenBSD: param.h,v 1.7 2025/07/07 18:33:37 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 +#endif +#endif + +#define _MACHINE riscv64 +#define MACHINE "riscv64" +#define _MACHINE_ARCH riscv64 +#define MACHINE_ARCH "riscv64" +#define MID_MACHINE MID_RISCV64 + +#define PAGE_SHIFT 12 +#define PAGE_SIZE (1 << PAGE_SHIFT) +#define PAGE_MASK (PAGE_SIZE - 1) + +#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 6 /* pages of u-area */ +#define USPACE (UPAGES * PAGE_SIZE) /* total size of u-area */ +#define USPACE_ALIGN 0 /* u-area alignment 0-none */ +#define __HAVE_USPACE_GUARD + +#define NMBCLUSTERS (64 * 1024) /* max cluster allocation */ + +#ifndef MSGBUFSIZE +#define MSGBUFSIZE (16 * PAGE_SIZE) /* default message buffer size */ +#endif + +#define STACKALIGNBYTES (16 - 1) +#define STACKALIGN(p) ((u_long)(p) &~ STACKALIGNBYTES) + +#define __HAVE_FDT + +#endif /* _KERNEL */ + +#endif /* _MACHINE_PARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/pcb.h b/lib/libc/include/riscv64-openbsd-none/riscv64/pcb.h new file mode 100644 index 0000000000..a1b6cb9e47 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/pcb.h @@ -0,0 +1,41 @@ +/* $OpenBSD: pcb.h,v 1.4 2024/10/15 09:16:39 jsg Exp $ */ + +/* + * Copyright (c) 2016 Dale Rahn + * + * 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_PCB_H_ +#define _MACHINE_PCB_H_ + +#include +#include + +struct trapframe; + +/* + * Warning certain fields must be within 256 bytes of the beginning + * of this structure. + */ +struct pcb { + u_int pcb_flags; +#define PCB_FPU 0x00000001 /* Process had FPU initialized */ +#define PCB_SINGLESTEP 0x00000002 /* Single step process */ + struct trapframe *pcb_tf; + + register_t pcb_sp; // stack pointer of switchframe + + caddr_t pcb_onfault; // On fault handler + struct fpreg pcb_fpstate; // Floating Point state */ +}; +#endif /* _MACHINE_PCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/pci_machdep.h b/lib/libc/include/riscv64-openbsd-none/riscv64/pci_machdep.h new file mode 100644 index 0000000000..4737ab100a --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/pci_machdep.h @@ -0,0 +1,140 @@ +/* $OpenBSD: pci_machdep.h,v 1.5 2024/05/22 05:51:49 jsg Exp $ */ + +/* + * Copyright (c) 2003-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) + * + * 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. + * + */ + +typedef struct machine_pci_chipset *pci_chipset_tag_t; +typedef uint64_t pcitag_t; + +#define PCITAG_NODE(x) ((x) >> 32) +#define PCITAG_OFFSET(x) ((x) & 0xffffffff) + +/* Supported interrupt types. */ +#define PCI_NONE 0 +#define PCI_INTX 1 +#define PCI_MSI 2 +#define PCI_MSIX 3 + +typedef struct { + pci_chipset_tag_t ih_pc; + pcitag_t ih_tag; + int ih_intrpin; + int ih_type; + bus_dma_tag_t ih_dmat; +} pci_intr_handle_t; + +struct pci_attach_args; + +/* + * Machine-specific PCI structure and type definitions. + * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE. + */ +struct machine_pci_chipset { + void *pc_conf_v; + void (*pc_attach_hook)(struct device *, + struct device *, struct pcibus_attach_args *); + int (*pc_bus_maxdevs)(void *, int); + pcitag_t (*pc_make_tag)(void *, int, int, int); + void (*pc_decompose_tag)(void *, pcitag_t, int *, + int *, int *); + int (*pc_conf_size)(void *, pcitag_t); + pcireg_t (*pc_conf_read)(void *, pcitag_t, int); + void (*pc_conf_write)(void *, pcitag_t, int, pcireg_t); + int (*pc_probe_device_hook)(void *, struct pci_attach_args *); + + void *pc_intr_v; + int (*pc_intr_map)(struct pci_attach_args *, + pci_intr_handle_t *); + int (*pc_intr_map_msi)(struct pci_attach_args *, + pci_intr_handle_t *); + int (*pc_intr_map_msivec)(struct pci_attach_args *, + int, pci_intr_handle_t *); + int (*pc_intr_map_msix)(struct pci_attach_args *, + int, pci_intr_handle_t *); + const char *(*pc_intr_string)(void *, pci_intr_handle_t); + void *(*pc_intr_establish)(void *, pci_intr_handle_t, + int, struct cpu_info *, int (*)(void *), void *, + char *); + void (*pc_intr_disestablish)(void *, void *); +}; + +/* + * Functions provided to machine-independent PCI code. + */ +#define pci_attach_hook(p, s, pba) \ + (*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba)) +#define pci_bus_maxdevs(c, b) \ + (*(c)->pc_bus_maxdevs)((c)->pc_conf_v, (b)) +#define pci_make_tag(c, b, d, f) \ + (*(c)->pc_make_tag)((c)->pc_conf_v, (b), (d), (f)) +#define pci_decompose_tag(c, t, bp, dp, fp) \ + (*(c)->pc_decompose_tag)((c)->pc_conf_v, (t), (bp), (dp), (fp)) +#define pci_conf_size(c, t) \ + (*(c)->pc_conf_size)((c)->pc_conf_v, (t)) +#define pci_conf_read(c, t, r) \ + (*(c)->pc_conf_read)((c)->pc_conf_v, (t), (r)) +#define pci_conf_write(c, t, r, v) \ + (*(c)->pc_conf_write)((c)->pc_conf_v, (t), (r), (v)) +#define pci_probe_device_hook(c, a) \ + (*(c)->pc_probe_device_hook)((c)->pc_conf_v, (a)) +#define pci_intr_map(c, ihp) \ + (*(c)->pa_pc->pc_intr_map)((c), (ihp)) +#define pci_intr_map_msi(c, ihp) \ + (*(c)->pa_pc->pc_intr_map_msi)((c), (ihp)) +#define pci_intr_map_msix(c, vec, ihp) \ + (*(c)->pa_pc->pc_intr_map_msix)((c), (vec), (ihp)) +#define pci_intr_string(c, ih) \ + (*(c)->pc_intr_string)((c)->pc_intr_v, (ih)) +#define pci_intr_establish(c, ih, l, h, a, nm) \ + (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), NULL, (h), (a),\ + (nm)) +#define pci_intr_establish_cpu(c, ih, l, ci, h, a, nm) \ + (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), (ci), (h), (a),\ + (nm)) +#define pci_intr_disestablish(c, iv) \ + (*(c)->pc_intr_disestablish)((c)->pc_intr_v, (iv)) + +#define pci_min_powerstate(c, t) (PCI_PMCSR_STATE_D3) +#define pci_set_powerstate_md(c, t, s, p) + +#define pci_dev_postattach(a, b) + +void pci_mcfg_init(bus_space_tag_t, bus_addr_t, int, int, int); + +void pci_msi_enable(pci_chipset_tag_t, pcitag_t, bus_addr_t, uint32_t); +void pci_msix_enable(pci_chipset_tag_t, pcitag_t, bus_space_tag_t, + int, bus_addr_t, uint32_t); +int _pci_intr_map_msi(struct pci_attach_args *, pci_intr_handle_t *); +int _pci_intr_map_msivec(struct pci_attach_args *, int, + pci_intr_handle_t *); +int _pci_intr_map_msix(struct pci_attach_args *, int, pci_intr_handle_t *); + +#define __HAVE_PCI_MSIX + +int pci_msix_table_map(pci_chipset_tag_t, pcitag_t, + bus_space_tag_t, bus_space_handle_t *); +void pci_msix_table_unmap(pci_chipset_tag_t, pcitag_t, + bus_space_tag_t, bus_space_handle_t); \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/pmap.h b/lib/libc/include/riscv64-openbsd-none/riscv64/pmap.h new file mode 100644 index 0000000000..d6e867d90f --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/pmap.h @@ -0,0 +1,132 @@ +/* $OpenBSD: pmap.h,v 1.14 2025/02/03 17:59:40 jca Exp $ */ + +/* + * Copyright (c) 2019-2020 Brian Bamsch + * Copyright (c) 2008,2009,2014 Dale Rahn + * + * 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_PMAP_H_ +#define _MACHINE_PMAP_H_ + +#ifndef _LOCORE +#include +#include +#include +#endif + + +/* V->P mapping data */ +// XXX Only targeting compatibility with SV39 +#define VP_IDX0_CNT 512 +#define VP_IDX0_MASK (VP_IDX0_CNT-1) +#define VP_IDX0_POS 39 +#define VP_IDX1_CNT 512 +#define VP_IDX1_MASK (VP_IDX1_CNT-1) +#define VP_IDX1_POS 30 +#define VP_IDX2_CNT 512 +#define VP_IDX2_MASK (VP_IDX2_CNT-1) +#define VP_IDX2_POS 21 +#define VP_IDX3_CNT 512 +#define VP_IDX3_MASK (VP_IDX3_CNT-1) +#define VP_IDX3_POS 12 + +/* cache flags */ +// XXX These are duplicated from arm64 and may need some reworking +#define PMAP_CACHE_CI (PMAP_MD0) /* cache inhibit */ +#define PMAP_CACHE_WB (PMAP_MD1) /* writeback */ +#define PMAP_CACHE_DEV (PMAP_MD2) /* device mapping */ +#define PMAP_CACHE_BITS (PMAP_MD0|PMAP_MD1|PMAP_MD2) + +#define PTED_VA_MANAGED_M (PMAP_MD3) +#define PTED_VA_WIRED_M (PMAP_MD3 << 1) + +#if defined(_KERNEL) && !defined(_LOCORE) +/* + * Pmap stuff + */ + +typedef struct pmap *pmap_t; + +struct pmap { + struct mutex pm_mtx; + union { + // XXX Sv48 not yet supported + // XXX Consider inverting Lx + struct pmapvp1 *l1; /* virtual to physical table 3 lvl */ + } pm_vp; + uint64_t pm_satp; + int pm_privileged; + int pm_refs; /* ref count */ + struct pmap_statistics pm_stats; /* pmap statistics */ +}; + +#define PMAP_PA_MASK ~((paddr_t)PAGE_MASK) /* to remove the flags */ +#define PMAP_NOCACHE 0x1 /* non-cacheable memory */ +#define PMAP_DEVICE 0x2 /* device memory */ + +#define PG_PMAP_MOD PG_PMAP0 +#define PG_PMAP_REF PG_PMAP1 +#define PG_PMAP_EXE PG_PMAP2 + +// [NCPUS] +extern paddr_t zero_page; +extern paddr_t copy_src_page; +extern paddr_t copy_dst_page; + +void pagezero(vaddr_t); + +extern struct pmap kernel_pmap_; +#define pmap_kernel() (&kernel_pmap_) +#define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count) +#define pmap_wired_count(pmap) ((pmap)->pm_stats.wired_count) + +vaddr_t pmap_bootstrap(long kvo, paddr_t lpt1, + vaddr_t kernelstart, vaddr_t kernelend, + paddr_t memstart, paddr_t memend); +void pmap_kenter_cache(vaddr_t va, paddr_t pa, vm_prot_t prot, int cacheable); +void pmap_page_ro(pmap_t pm, vaddr_t va, vm_prot_t prot); + +paddr_t pmap_steal_avail(size_t size, int align, void **kva); +void pmap_avail_fixup(void); +void pmap_physload_avail(void); + +#define PMAP_GROWKERNEL + +#define PHYS_TO_DMAP(pa) ((pa) - dmap_phys_base + DMAP_MIN_ADDRESS) + +struct pv_entry; + +/* investigate */ +#define pmap_unuse_final(p) do { /* nothing */ } while (0) +int pmap_fault_fixup(pmap_t, vaddr_t, vm_prot_t); +void pmap_postinit(void); +void pmap_init_percpu(void); + +#define __HAVE_PMAP_POPULATE + +#endif /* _KERNEL && !_LOCORE */ + +#ifndef _LOCORE +struct vm_page_md { + struct mutex pv_mtx; + LIST_HEAD(,pte_desc) pv_list; +}; + +#define VM_MDPAGE_INIT(pg) do { \ + mtx_init(&(pg)->mdpage.pv_mtx, IPL_VM); \ + LIST_INIT(&((pg)->mdpage.pv_list)); \ +} while (0) +#endif /* _LOCORE */ + +#endif /* _MACHINE_PMAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/proc.h b/lib/libc/include/riscv64-openbsd-none/riscv64/proc.h new file mode 100644 index 0000000000..e1a7bf3652 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/proc.h @@ -0,0 +1,45 @@ +/* $OpenBSD: proc.h,v 1.2 2021/05/12 01:20:52 jsg Exp $ */ +/* $NetBSD: proc.h,v 1.1 2003/04/26 18:39:46 fvdl 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 riscv64. + */ +struct mdproc { + volatile int md_astpending; +}; + +#endif /* _MACHINE_PROC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/profile.h b/lib/libc/include/riscv64-openbsd-none/riscv64/profile.h new file mode 100644 index 0000000000..3074be08fc --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/profile.h @@ -0,0 +1,92 @@ +/* $OpenBSD: profile.h,v 1.4 2021/05/21 16:49:57 deraadt Exp $ */ + +/* + * Copyright (c) 2015 Dale Rahn + * + * 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 _MCOUNT_DECL void _mcount + +#define MCOUNT_ASM_NAME "__mcount" + +#ifdef __PIC__ +#define PLTSYM "" /* XXX -aarch64 defaults to PLT? */ +#else +#define PLTSYM "" +#endif + +#define MCOUNT \ +__asm__ (".text \n;" \ + ".align 3 \n;" \ + ".globl " MCOUNT_ASM_NAME " \n;" \ + ".type " MCOUNT_ASM_NAME ",@function \n;" \ + MCOUNT_ASM_NAME ": \n;" \ + " addi sp, sp, -176 \n" \ + " sd fp, 0(sp) \n" \ + " sd ra, 8(sp) \n" \ + " sd s1, 24(sp) \n" \ + " sd a0, 32(sp) \n" \ + " sd a1, 40(sp) \n" \ + " sd a2, 48(sp) \n" \ + " sd a3, 56(sp) \n" \ + " sd a4, 64(sp) \n" \ + " sd a5, 72(sp) \n" \ + " sd a6, 80(sp) \n" \ + " sd a7, 88(sp) \n" \ + " sd s2, 96(sp) \n" \ + " sd s3, 104(sp) \n" \ + " sd s4, 112(sp) \n" \ + " sd s5, 120(sp) \n" \ + " sd s6, 128(sp) \n" \ + " sd s7, 136(sp) \n" \ + " sd s8, 144(sp) \n" \ + " sd s9, 152(sp) \n" \ + " sd s10, 160(sp) \n" \ + " sd s11, 168(sp) \n" \ + " ld a0, 8(fp) \n" \ + " mv a1, x1 \n" \ + " call " __STRING(_mcount) PLTSYM " \n" \ + /* restore argument registers */ \ + " ld fp, 0(sp) \n" \ + " ld ra, 8(sp) \n" \ + " ld s1, 24(sp) \n" \ + " ld a0, 32(sp) \n" \ + " ld a1, 40(sp) \n" \ + " ld a2, 48(sp) \n" \ + " ld a3, 56(sp) \n" \ + " ld a4, 64(sp) \n" \ + " ld a5, 72(sp) \n" \ + " ld a6, 80(sp) \n" \ + " ld a7, 88(sp) \n" \ + " ld s2, 96(sp) \n" \ + " ld s3, 104(sp) \n" \ + " ld s4, 112(sp) \n" \ + " ld s5, 120(sp) \n" \ + " ld s6, 128(sp) \n" \ + " ld s7, 136(sp) \n" \ + " ld s8, 144(sp) \n" \ + " ld s9, 152(sp) \n" \ + " ld s10, 160(sp) \n" \ + " ld s11, 168(sp) \n" \ + " addi sp, sp, 176 \n" \ + " jr ra \n"); + +#ifdef _KERNEL +// Change this to dair read/set, then restore. +#define MCOUNT_ENTER \ +__asm__ ("mrs %x0,daif; msr daifset, #0x2": "=r"(s)); +#define MCOUNT_EXIT \ +__asm__ ("msr daif, %x0":: "r"(s)); + +#endif \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/pte.h b/lib/libc/include/riscv64-openbsd-none/riscv64/pte.h new file mode 100644 index 0000000000..c050e38cb2 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/pte.h @@ -0,0 +1,85 @@ +/* $OpenBSD: pte.h,v 1.4 2024/10/14 12:02:16 jsg Exp $ */ + +/* + * Copyright (c) 2019 Brian Bamsch + * Copyright (c) 2014 Dale Rahn + * + * 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 _RISCV64_PTE_H_ +#define _RISCV64_PTE_H_ + +#define Lx_TABLE_ALIGN (4096) + +/* Block and Page attributes */ +/* Bits 9:8 are reserved for software */ +#define PTE_ATTR_MASK (0x3ffUL) +#define PTE_SW_MANAGED (1 << 9) +#define PTE_SW_WIRED (1 << 8) +#define PTE_D (1 << 7) /* Dirty */ +#define PTE_A (1 << 6) /* Accessed */ +#define PTE_G (1 << 5) /* Global */ +#define PTE_U (1 << 4) /* User */ +#define PTE_X (1 << 3) /* Execute */ +#define PTE_W (1 << 2) /* Write */ +#define PTE_R (1 << 1) /* Read */ +#define PTE_V (1 << 0) /* Valid */ +#define PTE_RWX (PTE_R | PTE_W | PTE_X) +#define PTE_RX (PTE_R | PTE_X) +#define PTE_KERN (PTE_V | PTE_R | PTE_W | PTE_A | PTE_D) + +/* T-Head extended page attributes */ +#define PTE_THEAD_SO (1ULL << 63) +#define PTE_THEAD_C (1ULL << 62) +#define PTE_THEAD_B (1ULL << 61) +#define PTE_THEAD_SH (1ULL << 60) + +/* Level 0 table, 512GiB per entry */ +#define L0_SHIFT 39 + +/* Level 1 table, 1GiB per entry */ +#define L1_SHIFT 30 +#define L1_SIZE (1UL << L1_SHIFT) +#define L1_OFFSET (L1_SIZE - 1) + +/* Level 2 table, 2MiB per entry */ +#define L2_SHIFT 21 +#define L2_SIZE (1UL << L2_SHIFT) +#define L2_OFFSET (L2_SIZE - 1) + +/* Level 3 table, 4KiB per entry */ +#define L3_SHIFT 12 +#define L3_SIZE (1UL << L3_SHIFT) +#define L3_OFFSET (L3_SIZE - 1) + +/* page mapping */ +#define Ln_ENTRIES_SHIFT 9 +#define Ln_ENTRIES (1 << Ln_ENTRIES_SHIFT) +#define Ln_ADDR_MASK (Ln_ENTRIES - 1) +#define Ln_TABLE_MASK ((1 << 12) - 1) + +/* physical page number mask */ +#define PTE_RPGN (((1ULL << 56) - 1) & ~PAGE_MASK) + +#define PTE_PPN0_S 10 +#define PTE_PPN1_S 19 +#define PTE_PPN2_S 28 +#define PTE_PPN3_S 37 +#define PTE_SIZE 8 + +#ifndef _LOCORE +typedef uint64_t pt_entry_t; /* page table entry */ +typedef uint64_t pn_t; /* page number */ +#endif /* !_LOCORE */ + +#endif /* _RISCV64_PTE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/ptrace.h b/lib/libc/include/riscv64-openbsd-none/riscv64/ptrace.h new file mode 100644 index 0000000000..acffe61919 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/ptrace.h @@ -0,0 +1,25 @@ +/* $OpenBSD: ptrace.h,v 1.4 2021/09/03 14:13:06 jca Exp $ */ + +/* + * Copyright (c) 2014 Patrick Wildt + * + * 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. + */ + +#if 0 +#define PT_STEP (PT_FIRSTMACH + 0) +#endif +#define PT_GETREGS (PT_FIRSTMACH + 1) +#define PT_SETREGS (PT_FIRSTMACH + 2) +#define PT_GETFPREGS (PT_FIRSTMACH + 3) +#define PT_SETFPREGS (PT_FIRSTMACH + 4) \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/reg.h b/lib/libc/include/riscv64-openbsd-none/riscv64/reg.h new file mode 100644 index 0000000000..f80b13d4aa --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/reg.h @@ -0,0 +1,60 @@ +/* $OpenBSD: reg.h,v 1.2 2021/05/12 01:20:52 jsg Exp $ */ + +/*- + * Copyright (c) 2019 Brian Bamsch + * Copyright (c) 2015-2016 Ruslan Bukin + * All rights reserved. + * + * Portions of this software were developed by SRI International and the + * University of Cambridge Computer Laboratory under DARPA/AFRL contract + * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. + * + * Portions of this software were developed by the University of Cambridge + * Computer Laboratory as part of the CTSRD Project, with support from the + * UK Higher Education Innovation Fund (HEIF). + * + * 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 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 AUTHOR 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. + * + * $FreeBSD$ + */ + +#ifndef _MACHINE_REG_H_ +#define _MACHINE_REG_H_ + +struct reg { + uint64_t r_ra; /* return address */ + uint64_t r_sp; /* stack pointer */ + uint64_t r_gp; /* global pointer */ + uint64_t r_tp; /* thread pointer */ + uint64_t r_t[7]; /* temporary registers */ + uint64_t r_s[12]; /* saved registers */ + uint64_t r_a[8]; /* argument registers */ + uint64_t r_sepc; /* exception program counter */ + uint64_t r_sstatus; /* status register */ +}; + +struct fpreg { + uint64_t fp_f[32]; /* floating-point registers */ + uint64_t fp_fcsr; /* floating-point control register */ +}; + +#endif /* !_MACHINE_REG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/reloc.h b/lib/libc/include/riscv64-openbsd-none/riscv64/reloc.h new file mode 100644 index 0000000000..09dea83e32 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/reloc.h @@ -0,0 +1,19 @@ +/* $OpenBSD: reloc.h,v 1.2 2021/05/12 01:20:52 jsg Exp $ */ + +/* + * RISCV64 static relocation types. + */ + +/* Relocation types used by the dynamic linker. */ +#define R_RISCV_NONE 0 +#define R_RISCV_32 1 +#define R_RISCV_64 2 +#define R_RISCV_RELATIVE 3 +#define R_RISCV_COPY 4 +#define R_RISCV_JUMP_SLOT 5 +#define R_RISCV_TLS_DTPMOD32 6 +#define R_RISCV_TLS_DTPMOD64 7 +#define R_RISCV_TLS_DTPREL32 8 +#define R_RISCV_TLS_DTPREL64 9 +#define R_RISCV_TLS_TPREL32 10 +#define R_RISCV_TLS_TPREL64 11 \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/riscvreg.h b/lib/libc/include/riscv64-openbsd-none/riscv64/riscvreg.h new file mode 100644 index 0000000000..cf19db3ca1 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/riscvreg.h @@ -0,0 +1,235 @@ +/* $OpenBSD: riscvreg.h,v 1.5 2022/08/29 02:01:18 jsg Exp $ */ + +/*- + * Copyright (c) 2019 Brian Bamsch + * Copyright (c) 2015-2017 Ruslan Bukin + * All rights reserved. + * + * Portions of this software were developed by SRI International and the + * University of Cambridge Computer Laboratory under DARPA/AFRL contract + * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. + * + * Portions of this software were developed by the University of Cambridge + * Computer Laboratory as part of the CTSRD Project, with support from the + * UK Higher Education Innovation Fund (HEIF). + * + * 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 copyright holder 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 AUTHOR 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 AUTHOR 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_RISCVREG_H_ +#define _MACHINE_RISCVREG_H_ + +#define EXCP_SHIFT 0 +#define EXCP_MASK (0xf << EXCP_SHIFT) +#define EXCP_MISALIGNED_FETCH 0 +#define EXCP_FAULT_FETCH 1 +#define EXCP_ILLEGAL_INSTRUCTION 2 +#define EXCP_BREAKPOINT 3 +#define EXCP_MISALIGNED_LOAD 4 +#define EXCP_FAULT_LOAD 5 +#define EXCP_MISALIGNED_STORE 6 +#define EXCP_FAULT_STORE 7 +#define EXCP_USER_ECALL 8 +#define EXCP_SUPERVISOR_ECALL 9 +#define EXCP_HYPERVISOR_ECALL 10 +#define EXCP_MACHINE_ECALL 11 +#define EXCP_INST_PAGE_FAULT 12 +#define EXCP_LOAD_PAGE_FAULT 13 +#define EXCP_STORE_PAGE_FAULT 15 +#define EXCP_INTR (1ULL << 63) + +#define MSTATUS_UIE (1 << 0) +#define MSTATUS_SIE (1 << 1) +#define MSTATUS_MIE (1 << 3) +#define MSTATUS_UPIE (1 << 4) +#define MSTATUS_SPIE (1 << 5) +#define MSTATUS_MPIE (1 << 7) +#define MSTATUS_SPP (1 << 8) +#define MSTATUS_MPP_SHIFT 11 +#define MSTATUS_MPP_MASK (0x3 << MSTATUS_MPP_SHIFT) +#define MSTATUS_FS_SHIFT 13 +#define MSTATUS_FS_MASK (0x3 << MSTATUS_FS_SHIFT) +#define MSTATUS_XS_SHIFT 15 +#define MSTATUS_XS_MASK (0x3 << MSTATUS_XS_SHIFT) +#define MSTATUS_MPRV (1 << 17) +#define MSTATUS_SUM (1 << 18) +#define MSTATUS_MXR (1 << 19) +#define MSTATUS_TVM (1 << 20) +#define MSTATUS_TW (1 << 21) +#define MSTATUS_TSR (1 << 22) +#define MSTATUS_UXL_SHIFT 32 +#define MSTATUS_UXL_MASK (0x3ULL << MSTATUS_UXL_SHIFT) +#define MSTATUS_SXL_SHIFT 34 +#define MSTATUS_SXL_MASK (0x3ULL << MSTATUS_SXL_SHIFT) +#define MSTATUS_SD (1ULL << (MXLEN - 1)) + +#define SSTATUS_UIE (1 << 0) +#define SSTATUS_SIE (1 << 1) +#define SSTATUS_UPIE (1 << 4) +#define SSTATUS_SPIE (1 << 5) +#define SSTATUS_SPP (1 << 8) +#define SSTATUS_FS_SHIFT 13 +#define SSTATUS_FS_MASK (0x3 << SSTATUS_FS_SHIFT) +#define SSTATUS_FS_OFF (0x0 << SSTATUS_FS_SHIFT) +#define SSTATUS_FS_INITIAL (0x1 << SSTATUS_FS_SHIFT) +#define SSTATUS_FS_CLEAN (0x2 << SSTATUS_FS_SHIFT) +#define SSTATUS_FS_DIRTY (0x3 << SSTATUS_FS_SHIFT) +#define SSTATUS_XS_SHIFT 15 +#define SSTATUS_XS_MASK (0x3 << SSTATUS_XS_SHIFT) +#define SSTATUS_SUM (1 << 18) +#define SSTATUS_MXR (1 << 19) +#define SSTATUS_UXL_SHIFT 32 +#define SSTATUS_UXL_MASK (0x3ULL << SSTATUS_UXL_SHIFT) +#define SSTATUS_SD (1ULL << (SXLEN - 1)) + +#define USTATUS_UIE (1 << 0) +#define USTATUS_UPIE (1 << 4) + +#define MSTATUS_PRV_U 0 /* user */ +#define MSTATUS_PRV_S 1 /* supervisor */ +#define MSTATUS_PRV_H 2 /* hypervisor */ +#define MSTATUS_PRV_M 3 /* machine */ + +#define MIE_USIE (1 << 0) +#define MIE_SSIE (1 << 1) +#define MIE_MSIE (1 << 3) +#define MIE_UTIE (1 << 4) +#define MIE_STIE (1 << 5) +#define MIE_MTIE (1 << 7) +#define MIE_UEIE (1 << 8) +#define MIE_SEIE (1 << 9) +#define MIE_MEIE (1 << 11) + +#define MIP_USIP (1 << 0) +#define MIP_SSIP (1 << 1) +#define MIP_MSIP (1 << 3) +#define MIP_UTIP (1 << 4) +#define MIP_STIP (1 << 5) +#define MIP_MTIP (1 << 7) +#define MIP_UEIP (1 << 8) +#define MIP_SEIP (1 << 9) +#define MIP_MEIP (1 << 11) + +#define SIE_USIE (1 << 0) +#define SIE_SSIE (1 << 1) +#define SIE_UTIE (1 << 4) +#define SIE_STIE (1 << 5) +#define SIE_UEIE (1 << 8) +#define SIE_SEIE (1 << 9) + +#define SIP_USIP (1 << 0) +#define SIP_SSIP (1 << 1) +#define SIP_UTIP (1 << 4) +#define SIP_STIP (1 << 5) +#define SIP_UEIP (1 << 8) +#define SIP_SEIP (1 << 9) + +#define UIE_USIE (1 << 0) +#define UIE_UTIE (1 << 4) +#define UIE_UEIE (1 << 8) + +#define UIP_USIP (1 << 0) +#define UIP_UTIP (1 << 4) +#define UIP_UEIP (1 << 8) + +#define PPN(pa) ((pa) >> PAGE_SHIFT) +#define SATP_PPN_SHIFT 0 +#define SATP_PPN_MASK (0xfffffffffffULL << SATP_PPN_SHIFT) +#define SATP_PPN(satp) (((satp) & SATP_PPN_MASK) >> SATP_PPN_SHIFT) +#define SATP_FORMAT_PPN(ppn) (((uint64_t)(ppn) << SATP_PPN_SHIFT) & SATP_PPN_MASK) +#define SATP_ASID_SHIFT 44 +#define SATP_ASID_MASK (0xffffULL << SATP_ASID_SHIFT) +#define SATP_ASID(satp) (((satp) & SATP_ASID_MASK) >> SATP_ASID_SHIFT) +#define SATP_FORMAT_ASID(asid) (((uint64_t)(asid) << SATP_ASID_SHIFT) & SATP_ASID_MASK) +#define SATP_MODE_SHIFT 60 +#define SATP_MODE_MASK (0xfULL << SATP_MODE_SHIFT) +#define SATP_MODE(mode) (((satp) & SATP_MODE_MASK) >> SATP_MODE_SHIFT) + +#define SATP_MODE_SV39 (8ULL << SATP_MODE_SHIFT) +#define SATP_MODE_SV48 (9ULL << SATP_MODE_SHIFT) +#define SATP_MODE_SV57 (10ULL << SATP_MODE_SHIFT) +#define SATP_MODE_SV64 (11ULL << SATP_MODE_SHIFT) + +/** + * As of RISC-V Machine ISA v1.11, the XLEN can vary between + * Machine, Supervisor, and User modes. The Machine XLEN (MXLEN) + * is resolved from the MXL field of the 'misa' CSR. The + * Supervisor XLEN (SXLEN) and User XLEN (UXLEN) are resolved + * from the SXL and UXL fields of the 'mstatus' CSR, respectively. + * + * The Machine XLEN is reset to the widest supported ISA variant + * at machine reset. For now, assume that all modes will always + * use the same, static XLEN of 64 bits. + */ +#define XLEN 64 +#define XLEN_BYTES (XLEN / 8) +#define MXLEN XLEN +#define SXLEN XLEN +#define UXLEN XLEN +#define INSN_SIZE 4 +#define INSN_C_SIZE 2 + +// Check if val can fit in the CSR immediate form +#define CSR_ZIMM(val) \ + (__builtin_constant_p(val) && ((u_long)(val) < 32)) + +#define csr_swap(csr, val) \ +({ if (CSR_ZIMM(val)) \ + __asm volatile("csrrwi %0, " #csr ", %1" \ + : "=r" (val) : "i" (val)); \ + else \ + __asm volatile("csrrw %0, " #csr ", %1" \ + : "=r" (val) : "r" (val)); \ + val; \ +}) + +#define csr_write(csr, val) \ +({ if (CSR_ZIMM(val)) \ + __asm volatile("csrwi " #csr ", %0" :: "i" (val)); \ + else \ + __asm volatile("csrw " #csr ", %0" :: "r" (val)); \ +}) + +#define csr_set(csr, val) \ +({ if (CSR_ZIMM(val)) \ + __asm volatile("csrsi " #csr ", %0" :: "i" (val)); \ + else \ + __asm volatile("csrs " #csr ", %0" :: "r" (val)); \ +}) + +#define csr_clear(csr, val) \ +({ if (CSR_ZIMM(val)) \ + __asm volatile("csrci " #csr ", %0" :: "i" (val)); \ + else \ + __asm volatile("csrc " #csr ", %0" :: "r" (val)); \ +}) + +#define csr_read(csr) \ +({ u_long val; \ + __asm volatile("csrr %0, " #csr : "=r" (val)); \ + val; \ +}) + +#endif /* !_MACHINE_RISCVREG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/sbi.h b/lib/libc/include/riscv64-openbsd-none/riscv64/sbi.h new file mode 100644 index 0000000000..51e313311d --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/sbi.h @@ -0,0 +1,267 @@ +/* $OpenBSD: sbi.h,v 1.6 2024/03/29 22:11:34 kettenis Exp $ */ + +/*- + * Copyright (c) 2016-2017 Ruslan Bukin + * All rights reserved. + * Copyright (c) 2019 Mitchell Horne + * + * Portions of this software were developed by SRI International and the + * University of Cambridge Computer Laboratory under DARPA/AFRL contract + * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. + * + * Portions of this software were developed by the University of Cambridge + * Computer Laboratory as part of the CTSRD Project, with support from the + * UK Higher Education Innovation Fund (HEIF). + * + * 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 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 AUTHOR 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_SBI_H_ +#define _MACHINE_SBI_H_ + +/* SBI Specification Version */ +#define SBI_SPEC_VERS_MAJOR_OFFSET 24 +#define SBI_SPEC_VERS_MAJOR_MASK (0x7F << SBI_SPEC_VERS_MAJOR_OFFSET) +#define SBI_SPEC_VERS_MINOR_OFFSET 0 +#define SBI_SPEC_VERS_MINOR_MASK (0xFFFFFF << SBI_SPEC_VERS_MINOR_OFFSET) + +/* SBI Implementation IDs */ +#define SBI_IMPL_ID_BBL 0 +#define SBI_IMPL_ID_OPENSBI 1 + +/* SBI Error Codes */ +#define SBI_SUCCESS 0 +#define SBI_ERR_FAILURE -1 +#define SBI_ERR_NOT_SUPPORTED -2 +#define SBI_ERR_INVALID_PARAM -3 +#define SBI_ERR_DENIED -4 +#define SBI_ERR_INVALID_ADDRESS -5 + +/* SBI Base Extension */ +#define SBI_EXT_ID_BASE 0x10 +#define SBI_BASE_GET_SPEC_VERSION 0 +#define SBI_BASE_GET_IMPL_ID 1 +#define SBI_BASE_GET_IMPL_VERSION 2 +#define SBI_BASE_PROBE_EXTENSION 3 +#define SBI_BASE_GET_MVENDORID 4 +#define SBI_BASE_GET_MARCHID 5 +#define SBI_BASE_GET_MIMPID 6 + +/* Hart State Management (HSM) Extension */ +#define SBI_EXT_ID_HSM 0x48534D +#define SBI_HSM_HART_START 0 +#define SBI_HSM_HART_STOP 1 +#define SBI_HSM_HART_STATUS 2 +#define SBI_HSM_STATUS_STARTED 0 +#define SBI_HSM_STATUS_STOPPED 1 +#define SBI_HSM_STATUS_START_PENDING 2 +#define SBI_HSM_STATUS_STOP_PENDING 3 + +/* System Reset Extension */ +#define SBI_EXT_ID_SRST 0x53525354 +#define SBI_SRST_RESET 0 +#define SBI_SRST_RESET_SHUTDOWN 0 +#define SBI_SRST_RESET_COLD_REBOOT 1 +#define SBI_SRST_RESET_WARM_REBOOT 2 + +/* Legacy Extensions */ +#define SBI_SET_TIMER 0 +#define SBI_CONSOLE_PUTCHAR 1 +#define SBI_CONSOLE_GETCHAR 2 +#define SBI_CLEAR_IPI 3 +#define SBI_SEND_IPI 4 +#define SBI_REMOTE_FENCE_I 5 +#define SBI_REMOTE_SFENCE_VMA 6 +#define SBI_REMOTE_SFENCE_VMA_ASID 7 +#define SBI_SHUTDOWN 8 + +#define SBI_CALL0(e, f) SBI_CALL4(e, f, 0, 0, 0, 0) +#define SBI_CALL1(e, f, p1) SBI_CALL4(e, f, p1, 0, 0, 0) +#define SBI_CALL2(e, f, p1, p2) SBI_CALL4(e, f, p1, p2, 0, 0) +#define SBI_CALL3(e, f, p1, p2, p3) SBI_CALL4(e, f, p1, p2, p3, 0) +#define SBI_CALL4(e, f, p1, p2, p3, p4) sbi_call(e, f, p1, p2, p3, p4) + +/* + * Documentation available at + * https://github.com/riscv/riscv-sbi-doc/blob/master/riscv-sbi.adoc + */ + +struct sbi_ret { + long error; + long value; +}; + +static __inline struct sbi_ret +sbi_call(uint64_t arg7, uint64_t arg6, uint64_t arg0, uint64_t arg1, + uint64_t arg2, uint64_t arg3) +{ + struct sbi_ret ret; + + register uintptr_t a0 __asm ("a0") = (uintptr_t)(arg0); + register uintptr_t a1 __asm ("a1") = (uintptr_t)(arg1); + register uintptr_t a2 __asm ("a2") = (uintptr_t)(arg2); + register uintptr_t a3 __asm ("a3") = (uintptr_t)(arg3); + register uintptr_t a6 __asm ("a6") = (uintptr_t)(arg6); + register uintptr_t a7 __asm ("a7") = (uintptr_t)(arg7); + + __asm volatile( \ + "ecall" \ + :"+r"(a0), "+r"(a1) \ + :"r"(a2), "r"(a3), "r"(a6), "r"(a7) \ + :"memory"); + + ret.error = a0; + ret.value = a1; + return (ret); +} + +/* Base extension functions and variables. */ +extern u_long sbi_spec_version; +extern u_long sbi_impl_id; +extern u_long sbi_impl_version; + +static __inline u_int +sbi_get_mvendorid(void) +{ + return (SBI_CALL0(SBI_EXT_ID_BASE, SBI_BASE_GET_MVENDORID).value); +} + + +static __inline u_long +sbi_get_marchid(void) +{ + return (SBI_CALL0(SBI_EXT_ID_BASE, SBI_BASE_GET_MARCHID).value); +} + +static __inline u_long +sbi_get_mimpid(void) +{ + return (SBI_CALL0(SBI_EXT_ID_BASE, SBI_BASE_GET_MIMPID).value); +} + +static __inline long +sbi_probe_extension(long id) +{ + return (SBI_CALL1(SBI_EXT_ID_BASE, SBI_BASE_PROBE_EXTENSION, id).value); +} + +/* Hart State Management extension functions. */ + +/* + * Start execution on the specified hart at physical address start_addr. The + * register a0 will contain the hart's ID, and a1 will contain the value of + * priv. + */ +int sbi_hsm_hart_start(u_long hart, u_long start_addr, u_long priv); + +/* + * Stop execution on the current hart. Interrupts should be disabled, or this + * function may return. + */ +void sbi_hsm_hart_stop(void); + +/* + * Get the execution status of the specified hart. The status will be one of: + * - SBI_HSM_STATUS_STARTED + * - SBI_HSM_STATUS_STOPPED + * - SBI_HSM_STATUS_START_PENDING + * - SBI_HSM_STATUS_STOP_PENDING + */ +int sbi_hsm_hart_status(u_long hart); + +/* Legacy extension functions. */ +static __inline void +sbi_console_putchar(int ch) +{ + + (void)SBI_CALL1(SBI_CONSOLE_PUTCHAR, 0, ch); +} + +static __inline int +sbi_console_getchar(void) +{ + + /* + * XXX: The "error" is returned here because legacy SBI functions + * continue to return their value in a0. + */ + return (SBI_CALL0(SBI_CONSOLE_GETCHAR, 0).error); +} + +static __inline void +sbi_set_timer(uint64_t val) +{ + + (void)SBI_CALL1(SBI_SET_TIMER, 0, val); +} + +static __inline void +sbi_shutdown(void) +{ + + (void)SBI_CALL0(SBI_SHUTDOWN, 0); +} + +static __inline void +sbi_clear_ipi(void) +{ + + (void)SBI_CALL0(SBI_CLEAR_IPI, 0); +} + +static __inline void +sbi_send_ipi(const unsigned long *hart_mask) +{ + + (void)SBI_CALL1(SBI_SEND_IPI, 0, (uint64_t)hart_mask); +} + +static __inline void +sbi_remote_fence_i(const unsigned long *hart_mask) +{ + + (void)SBI_CALL1(SBI_REMOTE_FENCE_I, 0, (uint64_t)hart_mask); +} + +static __inline void +sbi_remote_sfence_vma(const unsigned long *hart_mask, + unsigned long start, unsigned long size) +{ + + (void)SBI_CALL3(SBI_REMOTE_SFENCE_VMA, 0, (uint64_t)hart_mask, start, + size); +} + +static __inline void +sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, + unsigned long start, unsigned long size, + unsigned long asid) +{ + + (void)SBI_CALL4(SBI_REMOTE_SFENCE_VMA_ASID, 0, (uint64_t)hart_mask, + start, size, asid); +} + +void sbi_print_version(void); +void sbi_init(void); + +#endif /* !_MACHINE_SBI_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/setjmp.h b/lib/libc/include/riscv64-openbsd-none/riscv64/setjmp.h new file mode 100644 index 0000000000..5d0d59cc4d --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/setjmp.h @@ -0,0 +1,8 @@ +/* $OpenBSD: setjmp.h,v 1.4 2021/06/17 16:09:08 kettenis Exp $ */ + +/* + * machine/setjmp.h: machine dependent setjmp-related information. + */ + +#define _JBLEN 32 /* sp, ra, [f]s0-11, fscr, magic val, sigmask */ +#define _JB_SIGMASK 28 \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/signal.h b/lib/libc/include/riscv64-openbsd-none/riscv64/signal.h new file mode 100644 index 0000000000..cf9ddecbfc --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/signal.h @@ -0,0 +1,70 @@ +/* $OpenBSD: signal.h,v 1.4 2021/05/20 15:14:30 drahn Exp $ */ + +/*- + * Copyright (c) 1986, 1989, 1991, 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. + * + * @(#)signal.h 8.1 (Berkeley) 6/11/93 + * from: FreeBSD: src/sys/i386/include/signal.h,v 1.13 2000/11/09 + * from: FreeBSD: src/sys/sparc64/include/signal.h,v 1.6 2001/09/30 18:52:17 + * $FreeBSD: head/sys/riscv/include/signal.h 292407 2015-12-17 18:44:30Z br $ + */ + +#ifndef _MACHINE_SIGNAL_H_ +#define _MACHINE_SIGNAL_H_ + +#include + +typedef int sig_atomic_t; + +#if __BSD_VISIBLE || __XPG_VISIBLE >= 420 + +#include + +struct sigcontext { + int __sc_unused; + int sc_mask; + + __register_t sc_ra; + __register_t sc_sp; + __register_t sc_gp; + __register_t sc_tp; + __register_t sc_t[7]; + __register_t sc_s[12]; + __register_t sc_a[8]; + __register_t sc_sepc; + + /* 64 bit floats as well as integer registers */ + __register_t sc_f[32]; /* floating-point registers */ + __register_t sc_fcsr; /* floating-point control register */ + + long sc_cookie; +}; + +#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */ + +#endif /* !_MACHINE_SIGNAL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/simplebusvar.h b/lib/libc/include/riscv64-openbsd-none/riscv64/simplebusvar.h new file mode 100644 index 0000000000..5be6208e74 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/simplebusvar.h @@ -0,0 +1,38 @@ +/* $OpenBSD: simplebusvar.h,v 1.1 2023/09/22 01:10:44 jsg Exp $ */ + +/* + * Copyright (c) 2016 Patrick Wildt + * + * 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. + */ + +struct simplebus_softc { + struct device sc_dev; + int sc_node; + bus_space_tag_t sc_iot; + bus_dma_tag_t sc_dmat; + int sc_acells; + int sc_scells; + int sc_pacells; + int sc_pscells; + struct bus_space sc_bus; + struct machine_bus_dma_tag sc_dma; + int *sc_ranges; + int sc_rangeslen; + int *sc_dmaranges; + int sc_dmarangeslen; + int sc_early; + int sc_early_nodes[64]; +}; + +extern void simplebus_attach(struct device *, struct device *, void *); \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/spinlock.h b/lib/libc/include/riscv64-openbsd-none/riscv64/spinlock.h new file mode 100644 index 0000000000..aca85f3b7b --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/spinlock.h @@ -0,0 +1,10 @@ +/* $OpenBSD: spinlock.h,v 1.2 2021/05/12 01:20:52 jsg Exp $ */ + +#ifndef _MACHINE_SPINLOCK_H_ +#define _MACHINE_SPINLOCK_H_ + +#define _ATOMIC_LOCK_UNLOCKED (0) +#define _ATOMIC_LOCK_LOCKED (1) +typedef int _atomic_lock_t; + +#endif \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/sysarch.h b/lib/libc/include/riscv64-openbsd-none/riscv64/sysarch.h new file mode 100644 index 0000000000..cef4a2f0be --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/sysarch.h @@ -0,0 +1,43 @@ +/* $OpenBSD: sysarch.h,v 1.1 2021/09/14 12:03:49 jca Exp $ */ + +/* + * Copyright (c) 2021 Jeremie Courreges-Anglas + * + * 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 _RISCV64_SYSARCH_H_ +#define _RISCV64_SYSARCH_H_ + +/* + * Architecture specific syscalls (riscv64) + */ + +#define RISCV_SYNC_ICACHE 0 + +struct riscv_sync_icache_args { + u_int64_t addr; /* Virtual start address */ + size_t len; /* Region size */ +}; + +#ifndef _KERNEL + +#include + +__BEGIN_DECLS +int sysarch(int, void *); +__END_DECLS + +#endif /* _KERNEL */ + +#endif /* _RISCV64_SYSARCH_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/syscall.h b/lib/libc/include/riscv64-openbsd-none/riscv64/syscall.h new file mode 100644 index 0000000000..b3f643ffdd --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/syscall.h @@ -0,0 +1,28 @@ +/* $OpenBSD: syscall.h,v 1.3 2021/05/21 16:49:35 deraadt Exp $ */ + +/* + * Copyright (c) 2020 Brian Bamsch + * + * 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_SYSCALL_H_ +#define _MACHINE_SYSCALL_H_ + +#ifdef _KERNEL + +void svc_handler (trapframe_t *); + +#endif + +#endif /* !_MACHINE_SYSCALL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/tcb.h b/lib/libc/include/riscv64-openbsd-none/riscv64/tcb.h new file mode 100644 index 0000000000..d140033198 --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/tcb.h @@ -0,0 +1,52 @@ +/* $OpenBSD: tcb.h,v 1.3 2021/05/12 01:20:52 jsg Exp $ */ + +/* + * Copyright (c) 2019 Brian Bamsch + * Copyright (c) 2011 Philip Guenther + * + * 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 + +#include + +#define TCB_GET(p) \ + ((void *)(((struct pcb *)(p)->p_addr)->pcb_tf->tf_tp)) + +#define TCB_SET(p, addr) \ + do { \ + ((struct pcb *)(p)->p_addr)->pcb_tf->tf_tp = (long)(addr); \ + } while (0) + +#else /* _KERNEL */ + +/* ELF TLS ABI calls for small TCB, with static TLS data after it */ +#define TLS_VARIANT 1 + +static inline void * +__riscv64_read_tcb(void) +{ + void *tcb; + __asm volatile("mv %0, tp": "=r" (tcb)); + return tcb; +} + +#define TCB_GET() __riscv64_read_tcb() + +#endif /* _KERNEL */ + +#endif /* _MACHINE_TCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/timetc.h b/lib/libc/include/riscv64-openbsd-none/riscv64/timetc.h new file mode 100644 index 0000000000..a19dd6f23f --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/timetc.h @@ -0,0 +1,24 @@ +/* $OpenBSD: timetc.h,v 1.3 2021/07/24 22:41:09 jca Exp $ */ + +/* + * Copyright (c) 2020 Paul Irofti + * + * 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_TIMETC_H_ +#define _MACHINE_TIMETC_H_ + +#define TC_TB 1 + +#endif /* _MACHINE_TIMETC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/trap.h b/lib/libc/include/riscv64-openbsd-none/riscv64/trap.h new file mode 100644 index 0000000000..337eb2f71f --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/trap.h @@ -0,0 +1,24 @@ +/* $OpenBSD: trap.h,v 1.2 2021/05/12 01:20:52 jsg Exp $ */ + +/* + * Copyright (c) 2019 Brian Bamsch + * Copyright (c) 2016 Dale Rahn + * + * 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 KERNEL_BREAKPOINT 0x00100073 /* EBREAK -- Used by DDB */ + +#define KBPT_ASM "ebreak" + +#define USER_BREAKPOINT 0x00100073 /* EBREAK */ \ No newline at end of file diff --git a/lib/libc/include/riscv64-openbsd-none/riscv64/vmparam.h b/lib/libc/include/riscv64-openbsd-none/riscv64/vmparam.h new file mode 100644 index 0000000000..a7d864087a --- /dev/null +++ b/lib/libc/include/riscv64-openbsd-none/riscv64/vmparam.h @@ -0,0 +1,150 @@ +/* $OpenBSD: vmparam.h,v 1.9 2023/11/28 09:10:18 jsg 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. + * + * @(#)vmparam.h 5.9 (Berkeley) 5/12/91 + */ + +#ifndef _MACHINE_VMPARAM_H_ +#define _MACHINE_VMPARAM_H_ + +/* + * Machine dependent constants for riscv64. + */ + +#define USRSTACK VM_MAXUSER_ADDRESS + +/* + * Virtual memory related constants, all in bytes + */ +#ifndef MAXTSIZ +#define MAXTSIZ ((paddr_t)1*1024*1024*1024) /* max text size */ +#endif +#ifndef DFLDSIZ +#define DFLDSIZ ((paddr_t)128*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)1*1024*1024*1024) /* heap gap size */ +#endif +#ifndef DFLSSIZ +#define DFLSSIZ ((paddr_t)128*1024*1024) /* initial stack size limit */ +#endif +#ifndef MAXSSIZ +#define MAXSSIZ ((paddr_t)1*1024*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 + +/** + * Address space layout. + * + * RISC-V implements multiple paging modes with different virtual address space + * sizes: SV32, SV39 and SV48. SV39 permits a virtual address space size of + * 512GB and uses a three-level page table. Since this is large enough for most + * purposes, we currently use SV39 for both userland and the kernel, avoiding + * the extra translation step required by SV48. + * + * The address space is split into two regions at each end of the 64-bit address + * space: + * + * 0x0000000000000000 - 0x0000003fffffffff 256GB user map + * 0x0000004000000000 - 0xffffffbfffffffff unmappable + * 0xffffffc000000000 - 0xffffffc7ffffffff 32GB kernel map + * 0xffffffc800000000 - 0xffffffcfffffffff 32GB unused + * 0xffffffd000000000 - 0xffffffefffffffff 128GB direct map + * 0xfffffff000000000 - 0xffffffffffffffff 64GB unused + * + * The kernel is loaded at the beginning of the kernel map. + * + * We define some interesting address constants: + * + * VM_MIN_ADDRESS and VM_MAX_ADDRESS define the start and end of the entire + * 64 bit address space, mostly just for convenience. + * + * VM_MIN_KERNEL_ADDRESS and VM_MAX_KERNEL_ADDRESS define the start and end of + * mappable kernel virtual address space. + * + * VM_MIN_ADDRESS and VM_MAXUSER_ADDRESS define the start and end of the + * user address space. + */ +#define VM_MIN_ADDRESS ((vaddr_t)PAGE_SIZE) +#define VM_MAX_ADDRESS (0xffffffffffffffffUL) + +#define VM_MIN_KERNEL_ADDRESS (0xffffffc000000000UL) +#define VM_MAX_KERNEL_ADDRESS (0xffffffc800000000UL) + +/* Kernel L1 Page Table Range */ +#define L1_KERN_BASE (256) +#define L1_KERN_ENTRIES (288 - L1_KERN_BASE) + +#define DMAP_MIN_ADDRESS (0xffffffd000000000UL) +#define DMAP_MAX_ADDRESS (0xfffffff000000000UL) + +/* DMAP L1 Page Table Range */ +#define L1_DMAP_BASE (320) +#define L1_DMAP_ENTRIES (448 - L1_DMAP_BASE) + +#define VM_MAXUSER_ADDRESS (0x0000004000000000UL) /* 39 bits */ + +#ifdef _KERNEL +#define VM_MIN_STACK_ADDRESS (VM_MAXUSER_ADDRESS * 3 / 4) +#endif + +#define KERNBASE (VM_MIN_KERNEL_ADDRESS) + +#ifndef _LOCORE +extern paddr_t dmap_phys_base; +#endif + +/* virtual sizes (bytes) for various kernel submaps */ +#define VM_PHYS_SIZE (USRIOSIZE*PAGE_SIZE) + +#define VM_PHYSSEG_MAX 32 +#define VM_PHYSSEG_STRAT VM_PSTRAT_BSEARCH +#define VM_PHYSSEG_NOADD /* can't add RAM after vm_mem_init */ + +#endif /* _MACHINE_VMPARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/frame.h b/lib/libc/include/sparc64-openbsd-none/frame.h new file mode 100644 index 0000000000..4b077a0ce6 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/frame.h @@ -0,0 +1,105 @@ +/* $OpenBSD: frame.h,v 1.11 2024/04/08 20:07:53 miod Exp $ */ +/* $NetBSD: frame.h,v 1.9 2001/03/04 09:28:35 mrg Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)frame.h 8.1 (Berkeley) 6/11/93 + */ + +#ifndef _MACHINE_FRAME_H_ +#define _MACHINE_FRAME_H_ + +/* + * CC64FSZ (C Compiler 64-bit Frame SiZe) is the size of a stack frame used + * by the compiler in 64-bit mode. It is (16)*8; space for 8 ins, 8 outs. + */ +#define CC64FSZ 176 + +/* + * v9 stacks all have a bias of 2047 added to the %sp and %fp, so you can easily + * detect it by testing the register for an odd value. Why 2K-1 I don't know. + */ +#define BIAS (2048-1) + +#if defined(_KERNEL) && !defined(_LOCORE) + +/* + * Sparc v9 stack frame format. + * + * Note that the contents of each stack frame may be held only in + * machine register windows. In order to get an accurate picture + * of the frame, you must first force the kernel to write any such + * windows to the stack. + * + * V9 frames have an odd bias, so you can tell a v9 frame from + * a v8 frame by testing the stack pointer's lsb. + */ +struct frame { + int64_t fr_local[8]; /* space to save locals (%l0..%l7) */ + int64_t fr_arg[6]; /* space to save arguments (%i0..%i5) */ + u_int64_t fr_fp; /* space to save frame pointer (%i6) */ + u_int64_t fr_pc; /* space to save return pc (%i7) */ + /* + * SVR4 reserves a bunch of extra stuff. + */ + int64_t fr_argd[6]; /* `register save area' (lunacy) */ + int64_t fr_argx[0]; /* arg extension (args 7..n; variable size) */ +}; + +#define v9next_frame(f) ((struct frame*)(f->fr_fp+BIAS)) + +/* + * The v9 trapframe. + */ +struct trapframe { + int64_t tf_tstate; /* tstate register */ + int64_t tf_pc; /* return pc */ + int64_t tf_npc; /* return npc */ + int tf_y; /* %y register -- 32-bits */ + short tf_tt; /* What type of trap this was */ + char tf_pil; /* What IRQ we're handling */ + char tf_oldpil; /* What our old SPL was */ + int64_t tf_global[8]; /* global registers in trap's caller */ + int64_t tf_out[8]; /* output registers in trap's caller */ + int64_t tf_local[8]; /* local registers in trap's caller */ + int64_t tf_in[8]; /* in registers in trap's caller (for debug) */ +}; + +#endif /* _KERNEL && !_LOCORE */ + +#endif /* _MACHINE_FRAME_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/_float.h b/lib/libc/include/sparc64-openbsd-none/machine/_float.h new file mode 100644 index 0000000000..3ab11abcab --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/_float.h @@ -0,0 +1,80 @@ +/* $OpenBSD: _float.h,v 1.1 2012/06/26 16:12:45 deraadt Exp $ */ + +/* + * Copyright (c) 1992, 1993, 2001 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _MACHINE__FLOAT_H_ +#define _MACHINE__FLOAT_H_ + +#define __FLT_RADIX 2 /* b */ +#define __FLT_ROUNDS __flt_rounds() +#define __FLT_EVAL_METHOD 0 /* no promotions */ + +#define __FLT_MANT_DIG 24 /* p */ +#define __FLT_EPSILON 1.19209290E-07F /* b**(1-p) */ +#define __FLT_DIG 6 /* floor((p-1)*log10(b))+(b == 10) */ +#define __FLT_MIN_EXP -125 /* emin */ +#define __FLT_MIN 1.17549435E-38F /* b**(emin-1) */ +#define __FLT_MIN_10_EXP -37 /* ceil(log10(b**(emin-1))) */ +#define __FLT_MAX_EXP 128 /* emax */ +#define __FLT_MAX 3.40282347E+38F /* (1-b**(-p))*b**emax */ +#define __FLT_MAX_10_EXP 38 /* floor(log10((1-b**(-p))*b**emax)) */ + +#define __DBL_MANT_DIG 53 +#define __DBL_EPSILON 2.2204460492503131E-16 +#define __DBL_DIG 15 +#define __DBL_MIN_EXP -1021 +#define __DBL_MIN 2.2250738585072014E-308 +#define __DBL_MIN_10_EXP -307 +#define __DBL_MAX_EXP 1024 +#define __DBL_MAX 1.7976931348623157E+308 +#define __DBL_MAX_10_EXP 308 + +#define __LDBL_MANT_DIG 113 +#define __LDBL_EPSILON 1.925929944387235853055977942584927319E-34L +#define __LDBL_DIG 33 +#define __LDBL_MIN_EXP (-16381) +#define __LDBL_MIN 3.362103143112093506262677817321752603E-4932L +#define __LDBL_MIN_10_EXP (-4931) +#define __LDBL_MAX_EXP (+16384) +#define __LDBL_MAX 1.189731495357231765085759326628007016E+4932L +#define __LDBL_MAX_10_EXP (+4932) + +#define __DECIMAL_DIG 36 + +#endif /* _MACHINE__FLOAT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/_types.h b/lib/libc/include/sparc64-openbsd-none/machine/_types.h new file mode 100644 index 0000000000..b0d11eb13a --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/_types.h @@ -0,0 +1,140 @@ +/* $OpenBSD: _types.h,v 1.25 2023/07/02 19:02:28 cheloha 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[2]; +} 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 0xf +#define _STACKALIGNBYTES _ALIGNBYTES +#define _ALIGN(p) (((unsigned long)(p) + _ALIGNBYTES) & ~_ALIGNBYTES) +#define _ALIGNED_POINTER(p,t) ((((unsigned long)(p)) & (sizeof(t) - 1)) == 0) +#define _MAX_PAGE_SHIFT 13 /* 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; +typedef long long __int64_t; +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 +typedef int __wchar_t; +#endif +typedef int __wint_t; +typedef int __rune_t; +typedef void * __wctrans_t; +typedef void * __wctype_t; + +#endif /* _MACHINE__TYPES_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/apmvar.h b/lib/libc/include/sparc64-openbsd-none/machine/apmvar.h new file mode 100644 index 0000000000..62e9480a19 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/apmvar.h @@ -0,0 +1,122 @@ +/* $OpenBSD: apmvar.h,v 1.7 2019/01/22 02:36:30 phessler Exp $ */ + +/* + * Copyright (c) 2001 Alexander Guy + * Copyright (c) 1995 John T. Kohl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef _MACHINE_APMVAR_H_ +#define _MACHINE_APMVAR_H_ + +#include + +/* Advanced Power Management (v1.0 and v1.1 specification) + * functions/defines/etc. + */ + +/* These definitions make up the heart of the user-land interface + * to the APM devices. + */ + +#define APM_AC_OFF 0x00 +#define APM_AC_ON 0x01 +#define APM_AC_BACKUP 0x02 +#define APM_AC_UNKNOWN 0xff +#define APM_BATT_HIGH 0x00 +#define APM_BATT_LOW 0x01 +#define APM_BATT_CRITICAL 0x02 +#define APM_BATT_CHARGING 0x03 +#define APM_BATT_UNKNOWN 0xff +#define APM_BATT_LIFE_UNKNOWN 0xff + +#define APM_NOEVENT 0x0000 +#define APM_STANDBY_REQ 0x0001 +#define APM_SUSPEND_REQ 0x0002 +#define APM_NORMAL_RESUME 0x0003 +#define APM_CRIT_RESUME 0x0004 /* suspend/resume happened + without us */ +#define APM_BATTERY_LOW 0x0005 +#define APM_POWER_CHANGE 0x0006 +#define APM_UPDATE_TIME 0x0007 +#define APM_CRIT_SUSPEND_REQ 0x0008 +#define APM_USER_STANDBY_REQ 0x0009 +#define APM_USER_SUSPEND_REQ 0x000A +#define APM_SYS_STANDBY_RESUME 0x000B +#define APM_CAPABILITY_CHANGE 0x000C /* apm v1.2 */ +#define APM_USER_HIBERNATE_REQ 0x000D +#define APM_EVENT_MASK 0xffff + +#define APM_EVENT_COMPOSE(t,i) ((((i) & 0x7fff) << 16)|((t) & APM_EVENT_MASK)) +#define APM_EVENT_TYPE(e) ((e) & APM_EVENT_MASK) +#define APM_EVENT_INDEX(e) ((e) >> 16) + +/* + * LP (Laptop Package) + * + * Copyright (C) 1994 by HOSOKAWA Tatsumi + * + * This software may be used, modified, copied, and distributed, in + * both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + */ + +#define APM_BATTERY_ABSENT 4 + +struct apm_power_info { + u_char battery_state; + u_char ac_state; + u_char battery_life; + u_char spare1; + u_int minutes_left; /* estimate */ + u_int spare2[6]; +}; + +struct apm_ctl { + u_int dev; + u_int mode; +}; + +#define APM_IOC_REJECT _IOW('A', 0, struct apm_event_info) /* reject request # */ +#define APM_IOC_STANDBY _IO('A', 1) /* put system into standby */ +#define APM_IOC_SUSPEND _IO('A', 2) /* put system into suspend */ +#define APM_IOC_GETPOWER _IOR('A', 3, struct apm_power_info) /* fetch battery state */ +#define APM_IOC_DEV_CTL _IOW('A', 5, struct apm_ctl) /* put device into mode */ +#define APM_IOC_PRN_CTL _IOW('A', 6, int ) /* driver power status msg */ +#define APM_PRINT_ON 0 /* driver power status displayed */ +#define APM_PRINT_OFF 1 /* driver power status not displayed */ +#define APM_PRINT_PCT 2 /* driver power status only displayed + if the percentage changes */ +#define APM_IOC_STANDBY_REQ _IO('A', 7) /* request standby */ +#define APM_IOC_SUSPEND_REQ _IO('A', 8) /* request suspend */ +#define APM_IOC_HIBERNATE _IO('A', 9) /* put system into hibernate */ + +#endif /* _MACHINE_APMVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/asm.h b/lib/libc/include/sparc64-openbsd-none/machine/asm.h new file mode 100644 index 0000000000..2267bb9443 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/asm.h @@ -0,0 +1,96 @@ +/* $OpenBSD: asm.h,v 1.19 2024/03/29 21:05:34 miod Exp $ */ +/* $NetBSD: asm.h,v 1.15 2000/08/02 22:24:39 eeh Exp $ */ + +/* + * Copyright (c) 1994 Allen Briggs + * All rights reserved. + * + * Gleaned from locore.s and sun3 asm.h which had the following copyrights: + * locore.s: + * Copyright (c) 1988 University of Utah. + * Copyright (c) 1982, 1990 The Regents of the University of California. + * sun3/include/asm.h: + * Copyright (c) 1993 Adam Glass + * Copyright (c) 1990 The Regents of the University of California. + * + * 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_ASM_H_ +#define _MACHINE_ASM_H_ + +/* Pull in CC64FSZ and BIAS from frame.h */ +#include + +#define _C_LABEL(name) name +#define _ASM_LABEL(name) name + +#ifdef __PIC__ +/* + * PIC_PROLOGUE() is akin to the compiler generated function prologue for + * PIC code. It leaves the address of the Global Offset Table in DEST, + * clobbering register TMP in the process. Using the temporary enables us + * to work without a stack frame (doing so requires saving %o7) . + */ +#define PIC_PROLOGUE(dest,tmp) \ + sethi %hi(_GLOBAL_OFFSET_TABLE_-4),dest; \ + rd %pc, tmp; \ + or dest,%lo(_GLOBAL_OFFSET_TABLE_+4),dest; \ + add dest,tmp,dest +#else +#define PIC_PROLOGUE(dest,tmp) +#endif + +#define FTYPE(x) .type x,@function +#define OTYPE(x) .type x,@object + +#define _ENTRY_NB(name) \ + .align 4; .proc 1; FTYPE(name); name: +#define _ENTRY(name) .globl name; _ENTRY_NB(name) + +#if defined(PROF) || defined(GPROF) +#define _PROF_PROLOGUE \ + .data; .align 8; 1: .uaword 0; .uaword 0; \ + .text; save %sp,-CC64FSZ,%sp; sethi %hi(1b),%o0; call _mcount; \ + or %o0,%lo(1b),%o0; restore +#else +#define _PROF_PROLOGUE +#endif + +#define ENTRY(name) _ENTRY(name); _PROF_PROLOGUE +#define NENTRY(name) _ENTRY(name) +#define ENTRY_NB(name) _ENTRY_NB(name); _PROF_PROLOGUE +#define ASENTRY(name) _ENTRY(name); _PROF_PROLOGUE +#define FUNC(name) ASENTRY(name) +#define END(y) .size y, . - y + +#define STRONG_ALIAS(alias,sym) \ + .global alias; \ + alias = sym +#define WEAK_ALIAS(alias,sym) \ + .weak alias; \ + alias = sym + +#endif /* _MACHINE_ASM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/atomic.h b/lib/libc/include/sparc64-openbsd-none/machine/atomic.h new file mode 100644 index 0000000000..bab72dabbe --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/atomic.h @@ -0,0 +1,154 @@ +/* $OpenBSD: atomic.h,v 1.15 2017/07/04 09:00:12 mpi Exp $ */ +/* + * Copyright (c) 2007 Artur Grabowski + * + * 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_ + +static inline unsigned int +_atomic_cas_uint(volatile unsigned int *p, unsigned int e, unsigned int n) +{ + __asm volatile("cas [%2], %3, %0" + : "+r" (n), "=m" (*p) + : "r" (p), "r" (e), "m" (*p)); + + return (n); +} +#define atomic_cas_uint(_p, _e, _n) _atomic_cas_uint((_p), (_e), (_n)) + +static inline unsigned long +_atomic_cas_ulong(volatile unsigned long *p, unsigned long e, unsigned long n) +{ + __asm volatile("casx [%2], %3, %0" + : "+r" (n), "=m" (*p) + : "r" (p), "r" (e), "m" (*p)); + + return (n); +} +#define atomic_cas_ulong(_p, _e, _n) _atomic_cas_ulong((_p), (_e), (_n)) + +static inline void * +_atomic_cas_ptr(volatile void *p, void *e, void *n) +{ + __asm volatile("casx [%2], %3, %0" + : "+r" (n), "=m" (*(volatile unsigned long *)p) + : "r" (p), "r" (e), "m" (*(volatile unsigned long *)p)); + + return (n); +} +#define atomic_cas_ptr(_p, _e, _n) _atomic_cas_ptr((_p), (_e), (_n)) + +#define _def_atomic_swap(_f, _t, _c) \ +static inline _t \ +_f(volatile _t *p, _t v) \ +{ \ + _t e; \ + _t r; \ + \ + r = (_t)*p; \ + do { \ + e = r; \ + r = _c(p, e, v); \ + } while (r != e); \ + \ + return (r); \ +} + +_def_atomic_swap(_atomic_swap_uint, unsigned int, atomic_cas_uint) +_def_atomic_swap(_atomic_swap_ulong, unsigned long, atomic_cas_ulong) +#undef _def_atomic_swap + +static inline void * +_atomic_swap_ptr(volatile void *p, void *v) +{ + void *e, *r; + + r = *(void **)p; + do { + e = r; + r = atomic_cas_ptr(p, e, v); + } while (r != e); + + return (r); +} + +#define atomic_swap_uint(_p, _v) _atomic_swap_uint(_p, _v) +#define atomic_swap_ulong(_p, _v) _atomic_swap_ulong(_p, _v) +#define atomic_swap_ptr(_p, _v) _atomic_swap_ptr(_p, _v) + +#define _def_atomic_op_nv(_f, _t, _c, _op) \ +static inline _t \ +_f(volatile _t *p, _t v) \ +{ \ + _t e, r, f; \ + \ + r = *p; \ + do { \ + e = r; \ + f = e _op v; \ + r = _c(p, e, f); \ + } while (r != e); \ + \ + return (f); \ +} + +_def_atomic_op_nv(_atomic_add_int_nv, unsigned int, atomic_cas_uint, +) +_def_atomic_op_nv(_atomic_add_long_nv, unsigned long, atomic_cas_ulong, +) +_def_atomic_op_nv(_atomic_sub_int_nv, unsigned int, atomic_cas_uint, -) +_def_atomic_op_nv(_atomic_sub_long_nv, unsigned long, atomic_cas_ulong, -) +#undef _def_atomic_op_nv + +#define atomic_add_int_nv(_p, _v) _atomic_add_int_nv(_p, _v) +#define atomic_add_long_nv(_p, _v) _atomic_add_long_nv(_p, _v) +#define atomic_sub_int_nv(_p, _v) _atomic_sub_int_nv(_p, _v) +#define atomic_sub_long_nv(_p, _v) _atomic_sub_long_nv(_p, _v) + +#define __membar(_m) __asm volatile("membar " _m ::: "memory") + +#define membar_enter() __membar("#StoreLoad|#StoreStore") +#define membar_exit() __membar("#LoadStore|#StoreStore") +#define membar_producer() __membar("#StoreStore") +#define membar_consumer() __membar("#LoadLoad") +#define membar_sync() __membar("#Sync") + +#if defined(_KERNEL) + +static __inline void +atomic_setbits_int(volatile unsigned int *uip, unsigned int v) +{ + unsigned int e, r; + + r = *uip; + do { + e = r; + r = atomic_cas_uint(uip, e, e | v); + } while (r != e); +} + +static __inline void +atomic_clearbits_int(volatile unsigned int *uip, unsigned int v) +{ + unsigned int e, r; + + r = *uip; + do { + e = r; + r = atomic_cas_uint(uip, e, e & ~v); + } while (r != e); +} + +#endif /* defined(_KERNEL) */ +#endif /* _MACHINE_ATOMIC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/autoconf.h b/lib/libc/include/sparc64-openbsd-none/machine/autoconf.h new file mode 100644 index 0000000000..0a5ed5b2dc --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/autoconf.h @@ -0,0 +1,159 @@ +/* $OpenBSD: autoconf.h,v 1.20 2024/05/17 20:05:08 miod Exp $ */ +/* $NetBSD: autoconf.h,v 1.10 2001/07/24 19:32:11 eeh Exp $ */ + +/*- + * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Paul Kranenburg. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)autoconf.h 8.2 (Berkeley) 9/30/93 + */ + +/* + * Autoconfiguration information. + */ + +#include +#include + +/* This is used to map device classes to IPLs */ +struct intrmap { + char *in_class; + int in_lev; +}; +extern struct intrmap intrmap[]; + +/* The "mainbus" on ultra desktops is actually the UPA bus. We need to + * separate this from peripheral buses like SBus and PCI because each bus may + * have different ways of encoding properties, such as "reg" and "interrupts". + */ + +/* Device register space description */ +struct upa_reg { + int64_t ur_paddr; + int64_t ur_len; +}; + +/* + * Attach arguments presented by mainbus_attach() + * + * Large fields first followed by smaller ones to minimize stack space used. + */ +struct mainbus_attach_args { + bus_space_tag_t ma_bustag; /* parent bus tag */ + bus_dma_tag_t ma_dmatag; + char *ma_name; /* PROM node name */ + struct upa_reg *ma_reg; /* "reg" properties */ + u_int *ma_address; /* "address" properties -- 32 bits */ + u_int *ma_interrupts; /* "interrupts" properties */ + int ma_upaid; /* UPA bus ID */ + int ma_node; /* PROM handle */ + int ma_nreg; /* Counts for those properties */ + int ma_naddress; + int ma_ninterrupts; + int ma_pri; /* priority (IPL) */ +}; + +/* + * length; the others convert or make some other guarantee. + */ +long getproplen(int node, char *name); +int getprop(int, char *, size_t, int *, void **); +char *getpropstring(int node, char *name); +int getpropint(int node, char *name, int deflt); +int getpropspeed(int node, char *name); + +/* Frequently used options node */ +extern int optionsnode; + + /* new interfaces: */ +char *getpropstringA(int, char *, char *); + +/* + * `clockfreq' produces a printable representation of a clock frequency + * (this is just a frill). + */ +char *clockfreq(long freq); + +/* Openprom V2 style boot path */ +struct device; +struct bootpath { + int node; + char name[16]; /* name of this node */ + long val[3]; /* up to three optional values */ + struct device *dev; /* device that recognised this component */ +}; +struct bootpath *bootpath_store(int, struct bootpath *); + +void bootstrap(int); +int firstchild(int); +int nextsibling(int); +void callrom(void); +struct device *getdevunit(const char *, int); +int romgetcursoraddr(int **, int **); +int findroot(void); +int findnode(int, const char *); +int checkstatus(int); +int node_has_property(int, const char *); +void device_register(struct device *, void *); \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/boot_flag.h b/lib/libc/include/sparc64-openbsd-none/machine/boot_flag.h new file mode 100644 index 0000000000..e53f7fc9bd --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/boot_flag.h @@ -0,0 +1,50 @@ +/* $OpenBSD: boot_flag.h,v 1.8 2023/11/09 14:26:34 kn Exp $ */ +/* $NetBSD: boot_flag.h,v 1.3 2001/07/01 02:56:21 gmcgarry Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * 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 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_BOOT_FLAG_H_ +#define _MACHINE_BOOT_FLAG_H_ + +/* softraid boot information */ +#define BOOTSR_UUID_MAX 16 +#define BOOTSR_CRYPTO_MAXKEYBYTES 32 + +/* MD boot data in .openbsd.bootdata ELF segment */ +struct openbsd_bootdata { + u_int64_t version; + u_int64_t len; /* of structure */ + + u_int8_t sr_uuid[BOOTSR_UUID_MAX]; + u_int8_t sr_maskkey[BOOTSR_CRYPTO_MAXKEYBYTES]; + u_int32_t boothowto; +} __packed; + +#define BOOTDATA_VERSION 1 +#define BOOTDATA_LEN_BOOTHOWTO 68 + +#endif /* _MACHINE_BOOT_FLAG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/bppioctl.h b/lib/libc/include/sparc64-openbsd-none/machine/bppioctl.h new file mode 100644 index 0000000000..c424ccb474 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/bppioctl.h @@ -0,0 +1,59 @@ +/* $OpenBSD: bppioctl.h,v 1.2 2008/11/29 01:55:06 ray Exp $ */ + +/*- + * Copyright (c) 1998 Iain Hibbert + * 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 _IOCTL_ +#include +#endif + +struct bpp_param { + int bp_burst; /* chars to send/recv in one call */ + int bp_timeout; /* timeout: -1 blocking, 0 non blocking >0 ms */ + int bp_delay; /* delay between polls (ms) */ +}; + +#define BPP_BLOCK -1 +#define BPP_NOBLOCK 0 + +/* defaults */ +#define BPP_BURST 1024 +#define BPP_TIMEOUT BPP_BLOCK +#define BPP_DELAY 10 + +/* limits */ +#define BPP_BURST_MIN 1 +#define BPP_BURST_MAX 1024 +#define BPP_DELAY_MIN 0 +#define BPP_DELAY_MAX 30000 + +/* status bits */ +#define BPP_BUSY (1<<0) +#define BPP_PAPER (1<<1) + +/* ioctl commands */ +#define BPPIOCSPARAM _IOW('P', 0x1, struct bpp_param) +#define BPPIOCGPARAM _IOR('P', 0x2, struct bpp_param) +#define BPPIOCGSTAT _IOR('P', 0x4, int) \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/bus.h b/lib/libc/include/sparc64-openbsd-none/machine/bus.h new file mode 100644 index 0000000000..8e6f0472d3 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/bus.h @@ -0,0 +1,649 @@ +/* $OpenBSD: bus.h,v 1.38 2024/10/22 22:01:58 jsg Exp $ */ +/* $NetBSD: bus.h,v 1.31 2001/09/21 15:30:41 wiz Exp $ */ + +/*- + * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 1997-1999, 2001 Eduardo E. Horvath. All rights reserved. + * Copyright (c) 1996 Charles M. Hannum. All rights reserved. + * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christopher G. Demetriou + * for the NetBSD Project. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MACHINE_BUS_H_ +#define _MACHINE_BUS_H_ + +#include + +#ifdef _KERNEL + +/* + * Debug hooks + */ + +#define BSDB_ACCESS 0x01 +#define BSDB_MAP 0x02 +#define BSDB_ASSERT 0x04 +#define BSDB_MAPDETAIL 0x08 +#define BSDB_ALL_ACCESS 0x10 +extern int bus_space_debug; + +#define BSHDB_ACCESS 0x01 +#define BSHDB_NO_ACCESS 0x02 + +#if defined(BUS_SPACE_DEBUG) +#include +#define BUS_SPACE_PRINTF(l, s) do { \ + if(bus_space_debug & (l)) printf s; \ +} while(0) +#define BUS_SPACE_TRACE(t, h, s) do { \ + if ( (((bus_space_debug & BSDB_ALL_ACCESS) != 0) && \ + (((h).bh_flags & BSHDB_NO_ACCESS) == 0)) || \ + (((bus_space_debug & BSDB_ACCESS) != 0) && \ + (((h).bh_flags & BSHDB_ACCESS) != 0))) \ + printf s; \ + } while(0) +#define BUS_SPACE_SET_FLAGS(t, h, f) ((h).bh_flags |= (f)) +#define BUS_SPACE_CLEAR_FLAGS(t, h, f) ((h).bh_flags &= ~(f)) +#define BUS_SPACE_FLAG_DECL(s) int s +#define BUS_SPACE_SAVE_FLAGS(t, h, s) (s = (h).bh_flags) +#define BUS_SPACE_RESTORE_FLAGS(t, h, s) (s = (h).bh_flags) +#define BUS_SPACE_ASSERT(t, h, o, n) do { \ + if (bus_space_debug & BSDB_ASSERT) \ + bus_space_assert(t, &(h), o, n); \ + } while(0) +#else /* BUS_SPACE_DEBUG */ +#define BUS_SPACE_PRINTF(l, s) +#define BUS_SPACE_TRACE(t, h, s) +#define BUS_SPACE_SET_FLAGS(t, h, f) +#define BUS_SPACE_CLEAR_FLAGS(t, h, f) +#define BUS_SPACE_FLAG_DECL(s) +#define BUS_SPACE_SAVE_FLAGS(t, h, s) +#define BUS_SPACE_RESTORE_FLAGS(t, h, s) +#define BUS_SPACE_ASSERT(t, h, o, n) +#endif /* BUS_SPACE_DEBUG */ + + +/* + * UPA and SBus spaces are non-cached and big endian + * (except for RAM and PROM) + * + * PCI spaces are non-cached and little endian + */ + +enum sparc_bus_type { + UPA_BUS_SPACE, + SBUS_BUS_SPACE, + PCI_CONFIG_BUS_SPACE, + PCI_IO_BUS_SPACE, + PCI_MEMORY_BUS_SPACE, + LAST_BUS_SPACE +}; +/* For backwards compatibility */ +#define SPARC_BUS_SPACE UPA_BUS_SPACE + +/* + * Bus address and size types + */ +typedef const struct sparc_bus_space_tag *bus_space_tag_t; +typedef u_long bus_addr_t; +typedef u_long bus_size_t; + + +typedef struct _bus_space_handle { + paddr_t bh_ptr; +#ifdef BUS_SPACE_DEBUG + bus_space_tag_t bh_tag; + bus_size_t bh_size; + int bh_flags; +#endif +} bus_space_handle_t; + +/* For buses which have an iospace. */ +#define BUS_ADDR_IOSPACE(x) ((x)>>32) +#define BUS_ADDR_PADDR(x) ((x)&0xffffffff) +#define BUS_ADDR(io, pa) ((((bus_addr_t)io)<<32)|(pa)) + +/* + * Access methods for bus resources and address space. + */ + +struct sparc_bus_space_tag { + void *cookie; + bus_space_tag_t parent; + enum sparc_bus_type default_type; + u_int8_t asi; + u_int8_t sasi; + char name[32]; + + int (*sparc_bus_alloc)(bus_space_tag_t, + bus_space_tag_t, + bus_addr_t, bus_addr_t, + bus_size_t, bus_size_t, bus_size_t, + int, bus_addr_t *, bus_space_handle_t *); + + void (*sparc_bus_free)(bus_space_tag_t, + bus_space_tag_t, + bus_space_handle_t, bus_size_t); + + int (*sparc_bus_map)(bus_space_tag_t, + bus_space_tag_t, + bus_addr_t, bus_size_t, + int, bus_space_handle_t *); + + int (*sparc_bus_protect)(bus_space_tag_t, + bus_space_tag_t, + bus_space_handle_t, bus_size_t, int); + + int (*sparc_bus_unmap)(bus_space_tag_t, + bus_space_tag_t, + bus_space_handle_t, bus_size_t); + + int (*sparc_bus_subregion)(bus_space_tag_t, + bus_space_tag_t, + bus_space_handle_t, bus_size_t, + bus_size_t, bus_space_handle_t *); + + paddr_t (*sparc_bus_mmap)(bus_space_tag_t, + bus_space_tag_t, + bus_addr_t, off_t, int, int); + + void *(*sparc_intr_establish)(bus_space_tag_t, + bus_space_tag_t, + int, int, int, + int (*)(void *), void *, + const char *); + void *(*sparc_intr_establish_cpu)(bus_space_tag_t, + bus_space_tag_t, + int, int, int, + struct cpu_info *, + int (*)(void *), void *, + const char *); + + bus_addr_t (*sparc_bus_addr)(bus_space_tag_t, + bus_space_tag_t, bus_space_handle_t); +}; + +/* + * Bus space function prototypes. + */ +int bus_space_alloc( + bus_space_tag_t, + bus_addr_t, /* reg start */ + bus_addr_t, /* reg end */ + bus_size_t, /* size */ + bus_size_t, /* alignment */ + bus_size_t, /* boundary */ + int, /* flags */ + bus_addr_t *, + bus_space_handle_t *); +void bus_space_free( + bus_space_tag_t, + bus_space_handle_t, + bus_size_t); +int bus_space_map( + bus_space_tag_t, + bus_addr_t, + bus_size_t, + int, /*flags*/ + bus_space_handle_t *); +int bus_space_protect( + bus_space_tag_t, + bus_space_handle_t, + bus_size_t, + int); /*flags*/ +int bus_space_unmap( + bus_space_tag_t, + bus_space_handle_t, + bus_size_t); +int bus_space_subregion( + bus_space_tag_t, + bus_space_handle_t, + bus_size_t, + bus_size_t, + bus_space_handle_t *); +static void bus_space_barrier( + bus_space_tag_t, + bus_space_handle_t, + bus_size_t, + bus_size_t, + int); +paddr_t bus_space_mmap( + bus_space_tag_t, + bus_addr_t, /*addr*/ + off_t, /*offset*/ + int, /*prot*/ + int); /*flags*/ +void *bus_intr_establish( + bus_space_tag_t, + int, /*bus-specific intr*/ + int, /*device class level, + see machine/intr.h*/ + int, /*flags*/ + int (*)(void *), /*handler*/ + void *, /*handler arg*/ + const char *); /*what*/ +void *bus_intr_establish_cpu( + bus_space_tag_t, + int, /*bus-specific intr*/ + int, /*device class level, + see machine/intr.h*/ + int, /*flags*/ + struct cpu_info *, /*cpu*/ + int (*)(void *), /*handler*/ + void *, /*handler arg*/ + const char *); /*what*/ +void *bus_intr_allocate( + bus_space_tag_t, + int (*)(void *), /*handler*/ + void *, /*handler arg*/ + int, /*number*/ + int, /*pil*/ + volatile u_int64_t *, /*map*/ + volatile u_int64_t *, /*clr*/ + const char *); /*what*/ +void bus_intr_free(void *); +void bus_space_render_tag( + bus_space_tag_t, + char *, + size_t); +void *bus_space_vaddr( + bus_space_tag_t, + bus_space_handle_t); + +#ifdef BUS_SPACE_DEBUG +void bus_space_assert(bus_space_tag_t, + const bus_space_handle_t *, + bus_size_t, int); +void bus_space_render_tag(bus_space_tag_t, char*, size_t); +#endif /* BUS_SPACE_DEBUG */ + + +#define _BS_PRECALL(t,f) \ + while (t->f == NULL) \ + t = t->parent; +#define _BS_POSTCALL + +#define _BS_CALL(t,f) \ + (*(t)->f) + +/* flags for bus_space_barrier() */ +#define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */ +#define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */ + +static inline void +bus_space_barrier(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, + bus_size_t s, int f) +{ +#ifdef notyet + switch (f) { + case (BUS_SPACE_BARRIER_READ|BUS_SPACE_BARRIER_WRITE): + __membar("#LoadLoad|#StoreStore"); + break; + case BUS_SPACE_BARRIER_READ: + membar("#LoadLoad"); + break; + case BUS_SPACE_BARRIER_WRITE: + membar("#StoreStore"); + break; + default: + break; + } +#else + __membar("#Sync"); +#endif +} + +#include + +/* flags for bus space map functions */ +#define BUS_SPACE_MAP_CACHEABLE 0x0001 +#define BUS_SPACE_MAP_LINEAR 0x0002 +#define BUS_SPACE_MAP_READONLY 0x0004 +#define BUS_SPACE_MAP_PREFETCHABLE 0x0008 +#define BUS_SPACE_MAP_PROMADDRESS 0x0010 +#define BUS_SPACE_MAP_BUS1 0x0100 /* placeholders for bus functions... */ +#define BUS_SPACE_MAP_BUS2 0x0200 +#define BUS_SPACE_MAP_BUS3 0x0400 +#define BUS_SPACE_MAP_BUS4 0x0800 + + +/* flags for bus_intr_establish() */ +#define BUS_INTR_ESTABLISH_MPSAFE 0x0001 +#define BUS_INTR_ESTABLISH_SOFTINTR 0x0002 + +/* + * Flags used in various bus DMA methods. + */ +#define BUS_DMA_WAITOK 0x0000 /* safe to sleep (pseudo-flag) */ +#define BUS_DMA_NOWAIT 0x0001 /* not safe to sleep */ +#define BUS_DMA_ALLOCNOW 0x0002 /* perform resource allocation now */ +#define BUS_DMA_COHERENT 0x0004 /* hint: map memory DMA coherent */ +#define BUS_DMA_NOWRITE 0x0008 /* I suppose the following two should default on */ +#define BUS_DMA_BUS1 0x0010 /* placeholders for bus functions... */ +#define BUS_DMA_BUS2 0x0020 +#define BUS_DMA_BUS3 0x0040 +#define BUS_DMA_BUS4 0x0080 +#define BUS_DMA_STREAMING 0x0100 /* hint: sequential, unidirectional */ +#define BUS_DMA_READ 0x0200 /* mapping is device -> memory only */ +#define BUS_DMA_WRITE 0x0400 /* mapping is memory -> device only */ +#define BUS_DMA_ZERO 0x0800 /* zero memory in dmamem_alloc */ +#define BUS_DMA_OVERRUN 0x1000 /* tolerate DMA overruns */ +#define BUS_DMA_64BIT 0x2000 /* device handles 64bit dva */ + +#define BUS_DMA_NOCACHE BUS_DMA_BUS1 +#define BUS_DMA_DVMA BUS_DMA_BUS2 /* Don't bother with alignment */ +#define BUS_DMA_24BIT BUS_DMA_BUS3 /* 24bit device */ + +#define BUS_DMA_RAW BUS_DMA_STREAMING + +/* Forwards needed by prototypes below. */ +struct mbuf; +struct uio; + +/* + * Operations performed by bus_dmamap_sync(). + */ +#define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */ +#define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */ +#define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */ +#define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */ + +typedef struct sparc_bus_dma_tag *bus_dma_tag_t; +typedef struct sparc_bus_dmamap *bus_dmamap_t; + +/* + * bus_dma_segment_t + * + * Describes a single contiguous DMA transaction. Values + * are suitable for programming into DMA registers. + */ +struct sparc_bus_dma_segment { + bus_addr_t ds_addr; /* DVMA address */ + bus_size_t ds_len; /* length of transfer */ + /* + * The following is to support bus_dmamem_alloc()'s + * odd interface. Only the values in the first + * segment are used. This means that 3/5ths of + * most segments are useless space (and mbufs use 1024 + * segments). + */ + bus_size_t _ds_boundary; /* don't cross this */ + bus_size_t _ds_align; /* align to this */ + void *_ds_mlist; /* XXX - dmamap_alloc'ed pages */ +}; +typedef struct sparc_bus_dma_segment bus_dma_segment_t; + + +/* + * bus_dma_tag_t + * + * A machine-dependent opaque type describing the implementation of + * DMA for a given bus. + */ +struct sparc_bus_dma_tag { + void *_cookie; /* cookie used in the guts */ + struct sparc_bus_dma_tag* _parent; + + /* + * DMA mapping methods. + */ + int (*_dmamap_create)(bus_dma_tag_t, bus_dma_tag_t, bus_size_t, + int, bus_size_t, bus_size_t, int, bus_dmamap_t *); + void (*_dmamap_destroy)(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t); + int (*_dmamap_load)(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t, + void *, bus_size_t, struct proc *, int); + int (*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dma_tag_t, + bus_dmamap_t, struct mbuf *, int); + int (*_dmamap_load_uio)(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t, + struct uio *, int); + int (*_dmamap_load_raw)(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); + void (*_dmamap_unload)(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t); + void (*_dmamap_sync)(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t, + bus_addr_t, bus_size_t, int); + + /* + * DMA memory utility functions. + */ + int (*_dmamem_alloc)(bus_dma_tag_t, bus_dma_tag_t, bus_size_t, + bus_size_t, bus_size_t, bus_dma_segment_t *, int, int *, + int); + void (*_dmamem_free)(bus_dma_tag_t, bus_dma_tag_t, + bus_dma_segment_t *, int); + int (*_dmamem_map)(bus_dma_tag_t, bus_dma_tag_t, + bus_dma_segment_t *, int, size_t, caddr_t *, int); + void (*_dmamem_unmap)(bus_dma_tag_t, bus_dma_tag_t, caddr_t, + size_t); + paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_tag_t, + bus_dma_segment_t *, int, off_t, int, int); +}; + +#define _BD_PRECALL(t,f) \ + while (t->f == NULL) { \ + t = t->_parent; \ + } +#define _BD_CALL(t,f) \ + (*(t)->f) +#define _BD_POSTCALL + +static inline int +bus_dmamap_create(bus_dma_tag_t t, bus_size_t s, int n, bus_size_t m, + bus_size_t b, int f, bus_dmamap_t *p) +{ + int r; + const bus_dma_tag_t t0 = t; + _BD_PRECALL(t, _dmamap_create); + r = _BD_CALL(t, _dmamap_create)(t, t0, s, n, m, b, f, p); + _BD_POSTCALL; + return (r); +} +static inline void +bus_dmamap_destroy(bus_dma_tag_t t, bus_dmamap_t p) +{ + const bus_dma_tag_t t0 = t; + _BD_PRECALL(t, _dmamap_destroy); + _BD_CALL(t, _dmamap_destroy)(t, t0, p); + _BD_POSTCALL; +} +static inline int +bus_dmamap_load(bus_dma_tag_t t, bus_dmamap_t m, void *b, bus_size_t s, + struct proc *p, int f) +{ + const bus_dma_tag_t t0 = t; + int r; + _BD_PRECALL(t, _dmamap_load); + r = _BD_CALL(t, _dmamap_load)(t, t0, m, b, s, p, f); + _BD_POSTCALL; + return (r); +} +static inline int +bus_dmamap_load_mbuf(bus_dma_tag_t t, bus_dmamap_t m, struct mbuf *b, + int f) +{ + const bus_dma_tag_t t0 = t; + int r; + _BD_PRECALL(t, _dmamap_load_mbuf); + r = _BD_CALL(t, _dmamap_load_mbuf)(t, t0, m, b, f); + _BD_POSTCALL; + return (r); +} +static inline int +bus_dmamap_load_uio(bus_dma_tag_t t, bus_dmamap_t m, struct uio * u, int f) +{ + const bus_dma_tag_t t0 = t; + int r; + _BD_PRECALL(t, _dmamap_load_uio); + r = _BD_CALL(t, _dmamap_load_uio)(t, t0, m, u, f); + _BD_POSTCALL; + return (r); +} +static inline int +bus_dmamap_load_raw(bus_dma_tag_t t, bus_dmamap_t m, bus_dma_segment_t *sg, + int n, bus_size_t s, int f) +{ + const bus_dma_tag_t t0 = t; + int r; + _BD_PRECALL(t, _dmamap_load_raw); + r = _BD_CALL(t, _dmamap_load_raw)(t, t0, m, sg, n, s, f); + _BD_POSTCALL; + return (r); +} +static inline void +bus_dmamap_unload(bus_dma_tag_t t, bus_dmamap_t p) +{ + const bus_dma_tag_t t0 = t; + _BD_PRECALL(t, _dmamap_unload); + _BD_CALL(t, _dmamap_unload)(t, t0, p); + _BD_POSTCALL; +} +static inline void +bus_dmamap_sync(bus_dma_tag_t t, bus_dmamap_t p, bus_addr_t o, bus_size_t l, + int ops) +{ + const bus_dma_tag_t t0 = t; + _BD_PRECALL(t, _dmamap_sync); + _BD_CALL(t, _dmamap_sync)(t, t0, p, o, l, ops); + _BD_POSTCALL; +} +static inline int +bus_dmamem_alloc(bus_dma_tag_t t, bus_size_t s, bus_size_t a, bus_size_t b, + bus_dma_segment_t *sg, int n, int *r, int f) +{ + const bus_dma_tag_t t0 = t; + int ret; + _BD_PRECALL(t, _dmamem_alloc); + ret = _BD_CALL(t, _dmamem_alloc)(t, t0, s, a, b, sg, n, r, f); + _BD_POSTCALL; + return (ret); +} +static inline void +bus_dmamem_free(bus_dma_tag_t t, bus_dma_segment_t *sg, int n) +{ + const bus_dma_tag_t t0 = t; + _BD_PRECALL(t, _dmamem_free); + _BD_CALL(t, _dmamem_free)(t, t0, sg, n); + _BD_POSTCALL; +} +static inline int +bus_dmamem_map(bus_dma_tag_t t, bus_dma_segment_t *sg, int n, size_t s, + caddr_t *k, int f) +{ + const bus_dma_tag_t t0 = t; + int r; + _BD_PRECALL(t, _dmamem_map); + r = _BD_CALL(t, _dmamem_map)(t, t0, sg, n, s, k, f); + _BD_POSTCALL; + return (r); +} +static inline void +bus_dmamem_unmap(bus_dma_tag_t t, caddr_t k, size_t s) +{ + const bus_dma_tag_t t0 = t; + _BD_PRECALL(t, _dmamem_unmap); + _BD_CALL(t, _dmamem_unmap)(t, t0, k, s); + _BD_POSTCALL; +} +static inline paddr_t +bus_dmamem_mmap(bus_dma_tag_t t, bus_dma_segment_t *sg, int n, off_t o, int p, + int f) +{ + const bus_dma_tag_t t0 = t; + int r; + _BD_PRECALL(t, _dmamem_mmap); + r = _BD_CALL(t, _dmamem_mmap)(t, t0, sg, n, o, p, f); + _BD_POSTCALL; + return (r); +} + +/* + * bus_dmamap_t + * + * Describes a DMA mapping. + */ +struct sparc_bus_dmamap { + /* + * PRIVATE MEMBERS: not for use by machine-independent code. + */ + bus_addr_t _dm_dvmastart; /* start and size of allocated */ + bus_size_t _dm_dvmasize; /* DVMA segment for this map */ + + bus_size_t _dm_size; /* largest DMA transfer mappable */ + bus_size_t _dm_maxsegsz; /* largest possible segment */ + bus_size_t _dm_boundary; /* don't cross this */ + int _dm_segcnt; /* number of segs this map can map */ + int _dm_flags; /* misc. flags */ +#define _DM_TYPE_LOAD 0 +#define _DM_TYPE_SEGS 1 +#define _DM_TYPE_UIO 2 +#define _DM_TYPE_MBUF 3 + int _dm_type; /* mapping type: raw, uio, mbuf, etc */ + void *_dm_source; /* source mbuf/uio/etc. for unload */ + + void *_dm_cookie; /* cookie for bus-specific functions */ + + /* + * PUBLIC MEMBERS: these are used by machine-independent code. + */ + bus_size_t dm_mapsize; /* size of the mapping */ + int dm_nsegs; /* # valid segments in mapping */ + + bus_dma_segment_t dm_segs[1]; /* segments; variable length */ +}; + +#endif /* _KERNEL */ + +#endif /* _MACHINE_BUS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/cdefs.h b/lib/libc/include/sparc64-openbsd-none/machine/cdefs.h new file mode 100644 index 0000000000..26521d2433 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/cdefs.h @@ -0,0 +1,16 @@ +/* $OpenBSD: cdefs.h,v 1.4 2013/03/28 17:30:45 martynas Exp $ */ + +#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_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/conf.h b/lib/libc/include/sparc64-openbsd-none/machine/conf.h new file mode 100644 index 0000000000..dd9ef3a150 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/conf.h @@ -0,0 +1,101 @@ +/* $OpenBSD: conf.h,v 1.28 2024/03/29 21:06:14 miod Exp $ */ +/* $NetBSD: conf.h,v 1.9 2001/03/26 12:33:26 lukem Exp $ */ + +/*- + * Copyright (c) 1996 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * 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. + */ + +#define mmread mmrw +#define mmwrite mmrw +cdev_decl(mm); + +cdev_decl(openprom); + +/* open, close, ioctl */ +#define cdev_openprom_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) nullop, 0, \ + (dev_type_mmap((*))) enodev } + +cdev_decl(uperf); + +/* open, close, ioctl */ +#define cdev_uperf_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) nullop, 0, \ + (dev_type_mmap((*))) enodev } + +cdev_decl(vdsp); + +/* open, close, ioctl */ +#define cdev_vdsp_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) nullop, 0, \ + (dev_type_mmap((*))) enodev } + +#define cdev_gen_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) nullop, \ + 0, (dev_type_mmap((*))) enodev, \ + 0, 0, dev_init(c,n,kqfilter) } + +cdev_decl(zs); + +bdev_decl(fd); +cdev_decl(fd); + +cdev_decl(bpp); +cdev_decl(lpt); + +bdev_decl(wd); +cdev_decl(wd); + +cdev_decl(sabtty); + +cdev_decl(pcons); +cdev_decl(vcons); +cdev_decl(vcctty); +cdev_decl(sbbc); + +cdev_decl(vldcp); + +cdev_decl(com); + +cdev_decl(mtty); +cdev_decl(mbpp); +cdev_decl(stty); +cdev_decl(sbpp); + +/* open, close, write, ioctl */ +#define cdev_bpp_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) nullop, \ + 0, (dev_type_mmap((*))) enodev, 0, 0, seltrue_kqfilter } \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/cpu.h b/lib/libc/include/sparc64-openbsd-none/machine/cpu.h new file mode 100644 index 0000000000..e5535fb382 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/cpu.h @@ -0,0 +1,384 @@ +/* $OpenBSD: cpu.h,v 1.109 2024/11/06 12:06:15 miod Exp $ */ +/* $NetBSD: cpu.h,v 1.28 2001/06/14 22:56:58 thorpej Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)cpu.h 8.4 (Berkeley) 1/5/94 + */ + +#ifndef _MACHINE_CPU_H_ +#define _MACHINE_CPU_H_ + +/* + * CTL_MACHDEP definitions. + */ + /* 1 formerly: booted kernel name */ +#define CPU_LED_BLINK 2 /* int: blink leds? */ +#define CPU_ALLOWAPERTURE 3 /* allow xf86 operations */ +#define CPU_CPUTYPE 4 /* cpu type */ +#define CPU_CECCERRORS 5 /* Correctable ECC errors */ +#define CPU_CECCLAST 6 /* Correctable ECC last fault addr */ + /* 7 formerly: soft reset via keyboard */ +#define CPU_MAXID 8 /* number of valid machdep ids */ + +#define CTL_MACHDEP_NAMES { \ + { 0, 0 }, \ + { 0, 0 }, \ + { "led_blink", CTLTYPE_INT }, \ + { "allowaperture", CTLTYPE_INT }, \ + { "cputype", CTLTYPE_INT }, \ + { "ceccerrs", CTLTYPE_INT }, \ + { "cecclast", CTLTYPE_QUAD }, \ + { 0, 0 }, \ +} + +#ifdef _KERNEL +/* + * Exported definitions unique to SPARC cpu support. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +/* + * The cpu_info structure is part of a 64KB structure mapped both the kernel + * pmap and a single locked TTE a CPUINFO_VA for that particular processor. + * Each processor's cpu_info is accessible at CPUINFO_VA only for that + * processor. Other processors can access that through an additional mapping + * in the kernel pmap. + * + * The 64KB page contains: + * + * cpu_info + * interrupt stack (all remaining space) + * idle PCB + * idle stack (STACKSPACE - sizeof(PCB)) + * 32KB TSB + */ + +struct cpu_info { + /* + * SPARC cpu_info structures live at two VAs: one global + * VA (so each CPU can access any other CPU's cpu_info) + * and an alias VA CPUINFO_VA which is the same on each + * CPU and maps to that CPU's cpu_info. Since the alias + * CPUINFO_VA is how we locate our cpu_info, we have to + * self-reference the global VA so that we can return it + * in the curcpu() macro. + */ + struct cpu_info * volatile ci_self; + + /* Most important fields first */ + struct proc *ci_curproc; + struct pcb *ci_cpcb; /* also initial stack */ + paddr_t ci_cpcbpaddr; + struct cpu_info *ci_next; + + struct proc *ci_fpproc; + int ci_cpuid; + int ci_flags; + int ci_upaid; +#ifdef MULTIPROCESSOR + int ci_itid; + struct srp_hazard ci_srp_hazards[SRP_HAZARD_NUM]; +#define __HAVE_UVM_PERCPU + struct uvm_pmr_cache ci_uvm; /* [o] page cache */ +#endif + int ci_node; + u_int32_t ci_randseed; + struct schedstate_percpu ci_schedstate; /* scheduler state */ + + int ci_want_resched; + int ci_handled_intr_level; + int ci_idepth; + struct intrhand *ci_intrpending[16]; + struct clockqueue ci_queue; + struct intrhand ci_tickintr; + + volatile int ci_ddb_paused; +#define CI_DDB_RUNNING 0 +#define CI_DDB_SHOULDSTOP 1 +#define CI_DDB_STOPPED 2 +#define CI_DDB_ENTERDDB 3 +#define CI_DDB_INDDB 4 + + /* Spinning up the CPU */ + void (*ci_spinup)(void); /* spinup routine */ + void *ci_initstack; + paddr_t ci_paddr; /* Phys addr of this structure. */ + +#ifdef SUN4V + struct rwindow ci_rw; + u_int64_t ci_rwsp; + + paddr_t ci_mmfsa; + paddr_t ci_cpumq; + paddr_t ci_devmq; + + paddr_t ci_cpuset; + paddr_t ci_mondo; +#endif + + int ci_pci_probe; + int ci_pci_fault; + +#ifdef DIAGNOSTIC + int ci_mutex_level; +#endif +#ifdef GPROF + struct gmonparam *ci_gmon; + struct clockintr ci_gmonclock; +#endif + char ci_panicbuf[512]; +}; + +#define CPUF_RUNNING 0x0001 /* CPU is running */ + +extern struct cpu_info *cpus; + +#ifdef MULTIPROCESSOR + +register struct cpu_info *__curcpu asm ("g7"); + +#define curcpu() (__curcpu->ci_self) +#define cpu_number() (__curcpu->ci_cpuid) + +#define CPU_IS_PRIMARY(ci) ((ci)->ci_cpuid == 0) +#define CPU_IS_RUNNING(ci) 1 +#define CPU_INFO_ITERATOR int +#define CPU_INFO_FOREACH(cii, ci) \ + for (cii = 0, ci = cpus; ci != NULL; ci = ci->ci_next) +#define CPU_INFO_UNIT(ci) ((ci)->ci_cpuid) +#define MAXCPUS 256 + +void cpu_boot_secondary_processors(void); + +void sparc64_send_ipi(int, void (*)(void), u_int64_t, u_int64_t); +void sparc64_broadcast_ipi(void (*)(void), u_int64_t, u_int64_t); + +void cpu_unidle(struct cpu_info *); + +#else /* MULTIPROCESSOR */ + +#define __curcpu ((struct cpu_info *)CPUINFO_VA) +#define curcpu() __curcpu +#define cpu_number() 0 + +#define CPU_IS_PRIMARY(ci) 1 +#define CPU_IS_RUNNING(ci) 1 +#define CPU_INFO_ITERATOR int +#define CPU_INFO_FOREACH(cii, ci) \ + for (cii = 0, ci = curcpu(); ci != NULL; ci = NULL) +#define CPU_INFO_UNIT(ci) 0 +#define MAXCPUS 1 + +#define cpu_unidle(ci) + +#endif /* MULTIPROCESSOR */ + +#define curpcb __curcpu->ci_cpcb +#define fpproc __curcpu->ci_fpproc + +static inline unsigned int +cpu_rnd_messybits(void) +{ + u_int64_t tick; + + __asm volatile("rd %%tick, %0" : "=r" (tick) :); + + return ((tick >> 32) ^ tick); +} + +/* + * On processors with multiple threads we force a thread switch. + * + * On UltraSPARC T2 and its successors, the optimal way to do this + * seems to be to do three nop reads of %ccr. This works on + * UltraSPARC T1 as well, even though three nop casx operations seem + * to be slightly more optimal. Since these instructions are + * effectively nops, executing them on earlier non-CMT processors is + * harmless, so we make this the default. + * + * On SPARC T4 and later, we can use the processor-specific pause + * instruction. + * + * On SPARC64 VI and its successors we execute the processor-specific + * sleep instruction. + */ +#define CPU_BUSY_CYCLE() \ +do { \ + __asm volatile( \ + "999: rd %%ccr, %%g0 \n" \ + " rd %%ccr, %%g0 \n" \ + " rd %%ccr, %%g0 \n" \ + " .section .sun4v_pause_patch, \"ax\" \n" \ + " .word 999b \n" \ + " .word 0xb7802080 ! pause 128 \n" \ + " .word 999b + 4 \n" \ + " nop \n" \ + " .word 999b + 8 \n" \ + " nop \n" \ + " .previous \n" \ + " .section .sun4u_mtp_patch, \"ax\" \n" \ + " .word 999b \n" \ + " .word 0x81b01060 ! sleep \n" \ + " .word 999b + 4 \n" \ + " nop \n" \ + " .word 999b + 8 \n" \ + " nop \n" \ + " .previous \n" \ + : : : "memory"); \ +} while (0) + +/* + * Arguments to clockintr_dispatch encapsulate the + * previous machine state in an opaque clockframe. + */ +struct clockframe { + struct trapframe t; + int saved_intr_level; +}; + +#define CLKF_USERMODE(framep) (((framep)->t.tf_tstate & TSTATE_PRIV) == 0) +#define CLKF_PC(framep) ((framep)->t.tf_pc) +#define CLKF_INTR(framep) ((framep)->saved_intr_level != 0) + +extern void (*cpu_start_clock)(void); + +#define aston(p) ((p)->p_md.md_astpending = 1) + +/* + * Preempt the current process if in interrupt from user mode, + * or after the current trap/syscall if in system mode. + */ +extern void need_resched(struct cpu_info *); +#define clear_resched(ci) (ci)->ci_want_resched = 0 + +/* + * This is used during profiling to integrate system time. + */ +#define PROC_PC(p) ((p)->p_md.md_tf->tf_pc) +#define PROC_STACK(p) ((p)->p_md.md_tf->tf_out[6] + (2048-1)) /* BIAS */ + +/* + * Give a profiling tick to the current process when the user profiling + * buffer pages are invalid. On the sparc, request an ast to send us + * through trap(), marking the proc as needing a profiling tick. + */ +#define need_proftick(p) aston(p) + +void signotify(struct proc *); + +/* cpu.c */ +int cpu_myid(void); +/* machdep.c */ +void dumpconf(void); +caddr_t reserve_dumppages(caddr_t); +/* clock.c */ +struct timeval; +int clockintr(void *);/* level 10 (clock) interrupt code */ +/* locore.s */ +struct fpstate; +void savefpstate(struct fpstate *); +void loadfpstate(struct fpstate *); +void clearfpstate(void); +u_int64_t probeget(paddr_t, int, int); +#define write_all_windows() __asm volatile("flushw" : : ) +void write_user_windows(void); +void proc_trampoline(void); +struct pcb; +void snapshot(struct pcb *); +struct frame *getfp(void); +void switchtoctx(int); +/* trap.c */ +void pmap_unuse_final(struct proc *); +int rwindow_save(struct proc *); +/* vm_machdep.c */ +void fpusave_cpu(struct cpu_info *, int); +void fpusave_proc(struct proc *, int); +/* fb.c */ +void fb_unblank(void); +/* ltc.c */ +void ltc_full_blast(void); +/* tda.c */ +void tda_full_blast(void); +/* emul.c */ +int emul_qf(int32_t, struct proc *, union sigval, struct trapframe *); +int emul_popc(int32_t, struct proc *, union sigval, struct trapframe *); + +/* + * + * The SPARC has a Trap Base Register (TBR) which holds the upper 20 bits + * of the trap vector table. The next eight bits are supplied by the + * hardware when the trap occurs, and the bottom four bits are always + * zero (so that we can shove up to 16 bytes of executable code---exactly + * four instructions---into each trap vector). + * + * The hardware allocates half the trap vectors to hardware and half to + * software. + * + * Traps have priorities assigned (lower number => higher priority). + */ + +struct trapvec { + int tv_instr[8]; /* the eight instructions */ +}; +extern struct trapvec trapbase[]; /* the 256 vectors */ + +struct blink_led { + void (*bl_func)(void *, int); + void *bl_arg; + SLIST_ENTRY(blink_led) bl_next; +}; + +extern void blink_led_register(struct blink_led *); + +#ifdef MULTIPROCESSOR +#include +#endif + +#endif /* _KERNEL */ +#endif /* _MACHINE_CPU_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/ctlreg.h b/lib/libc/include/sparc64-openbsd-none/machine/ctlreg.h new file mode 100644 index 0000000000..6120cae56e --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/ctlreg.h @@ -0,0 +1,715 @@ +/* $OpenBSD: ctlreg.h,v 1.33 2025/07/16 07:15:42 jsg Exp $ */ +/* $NetBSD: ctlreg.h,v 1.28 2001/08/06 23:55:34 eeh Exp $ */ + +/* + * Copyright (c) 1996-2001 Eduardo Horvath + * + * 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. + * + * 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. + * + */ +/* + * Copyright (c) 2001 Jake Burkholder. + * 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 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 AUTHOR 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 _SPARC64_CTLREG_ +#define _SPARC64_CTLREG_ + +/* + * Sun 4u control registers. (includes address space definitions + * and some registers in control space). + */ + +/* + * The Alternate address spaces. + * + * 0x00-0x7f are privileged + * 0x80-0xff can be used by users + */ + +#define ASI_LITTLE 0x08 /* This bit should make an ASI little endian */ + +#define ASI_NUCLEUS 0x04 /* [4u] kernel address space */ +#define ASI_NUCLEUS_LITTLE 0x0c /* [4u] kernel address space, little endian */ + +#define ASI_AS_IF_USER_PRIMARY 0x10 /* [4u] primary user address space */ +#define ASI_AS_IF_USER_SECONDARY 0x11 /* [4u] secondary user address space */ + +#define ASI_PHYS_CACHED 0x14 /* [4u] MMU bypass to main memory */ +#define ASI_PHYS_NON_CACHED 0x15 /* [4u] MMU bypass to I/O location */ + +#define ASI_AS_IF_USER_PRIMARY_LITTLE 0x18 /* [4u] primary user address space, little endian */ +#define ASI_AS_IF_USER_SECONDARY_LITTIE 0x19 /* [4u] secondary user address space, little endian */ + +#define ASI_PHYS_CACHED_LITTLE 0x1c /* [4u] MMU bypass to main memory, little endian */ +#define ASI_PHYS_NON_CACHED_LITTLE 0x1d /* [4u] MMU bypass to I/O location, little endian */ + +#define ASI_SCRATCHPAD 0x20 /* [4v] scratchpad registers */ +#define ASI_MMU_CONTEXTID 0x21 /* [4v] MMU context */ + +#define ASI_NUCLEUS_QUAD_LDD 0x24 /* [4u] use w/LDDA to load 128-bit item */ +#define ASI_QUEUE 0x25 /* [4v] interrupt queue registers */ +#define ASI_NUCLEUS_QUAD_LDD_LITTLE 0x2c /* [4u] use w/LDDA to load 128-bit item, little endian */ + +#define ASI_FLUSH_D_PAGE_PRIMARY 0x38 /* [4u] flush D-cache page using primary context */ +#define ASI_FLUSH_D_PAGE_SECONDARY 0x39 /* [4u] flush D-cache page using secondary context */ +#define ASI_FLUSH_D_CTX_PRIMARY 0x3a /* [4u] flush D-cache context using primary context */ +#define ASI_FLUSH_D_CTX_SECONDARY 0x3b /* [4u] flush D-cache context using secondary context */ + +#define ASI_DCACHE_INVALIDATE 0x42 /* [III] invalidate D-cache */ +#define ASI_DCACHE_UTAG 0x43 /* [III] diagnostic access to D-cache micro tag */ +#define ASI_DCACHE_SNOOP_TAG 0x44 /* [III] diagnostic access to D-cache snoop tag RAM */ + +#define ASI_LSU_CONTROL_REGISTER 0x45 /* [4u] load/store unit control register */ + +#define ASI_DCACHE_DATA 0x46 /* [4u] diagnostic access to D-cache data RAM */ +#define ASI_DCACHE_TAG 0x47 /* [4u] diagnostic access to D-cache tag RAM */ + +#define ASI_INTR_DISPATCH_STATUS 0x48 /* [4u] interrupt dispatch status register */ +#define ASI_INTR_RECEIVE 0x49 /* [4u] interrupt receive status register */ +#define ASI_MID_REG 0x4a /* [4u] hardware config and MID */ +#define ASI_ERROR_EN_REG 0x4b /* [4u] asynchronous error enables */ +#define ASI_AFSR 0x4c /* [4u] asynchronous fault status register */ +#define ASI_AFAR 0x4d /* [4u] asynchronous fault address register */ + +#define ASI_SCRATCH 0x4f /* [VI] scratch registers */ + +#define ASI_ICACHE_DATA 0x66 /* [4u] diagnostic access to D-cache data RAM */ +#define ASI_ICACHE_TAG 0x67 /* [4u] diagnostic access to D-cache tag RAM */ +#define ASI_FLUSH_I_PAGE_PRIMARY 0x68 /* [4u] flush D-cache page using primary context */ +#define ASI_FLUSH_I_PAGE_SECONDARY 0x69 /* [4u] flush D-cache page using secondary context */ +#define ASI_FLUSH_I_CTX_PRIMARY 0x6a /* [4u] flush D-cache context using primary context */ +#define ASI_FLUSH_I_CTX_SECONDARY 0x6b /* [4u] flush D-cache context using secondary context */ + +#define ASI_BLOCK_AS_IF_USER_PRIMARY 0x70 /* [4u] primary user address space, block loads/stores */ +#define ASI_BLOCK_AS_IF_USER_SECONDARY 0x71 /* [4u] secondary user address space, block loads/stores */ + +#define ASI_ECACHE_DIAG 0x76 /* [4u] diag access to E-cache tag and data */ +#define ASI_DATAPATH_ERR_REG_WRITE 0x77 /* [4u] ASI is reused */ + +#define ASI_BLOCK_AS_IF_USER_PRIMARY_LITTLE 0x78 /* [4u] primary user address space, block loads/stores */ +#define ASI_BLOCK_AS_IF_USER_SECONDARY_LITTLE 0x79 /* [4u] secondary user address space, block loads/stores */ + +#define ASI_INTERRUPT_RECEIVE_DATA 0x7f /* [4u] interrupt receive data registers {0,1,2} */ +#define ASI_DATAPATH_ERR_REG_READ 0x7f /* [4u] read access to datapath error registers (ASI reused) */ + +#define ASI_PRIMARY 0x80 /* [4u] primary address space */ +#define ASI_SECONDARY 0x81 /* [4u] secondary address space */ +#define ASI_PRIMARY_NOFAULT 0x82 /* [4u] primary address space, no fault */ +#define ASI_SECONDARY_NOFAULT 0x83 /* [4u] secondary address space, no fault */ + +#define ASI_PRIMARY_LITTLE 0x88 /* [4u] primary address space, little endian */ +#define ASI_SECONDARY_LITTLE 0x89 /* [4u] secondary address space, little endian */ +#define ASI_PRIMARY_NOFAULT_LITTLE 0x8a /* [4u] primary address space, no fault, little endian */ +#define ASI_SECONDARY_NOFAULT_LITTLE 0x8b /* [4u] secondary address space, no fault, little endian */ + +#define ASI_PST8_PRIMARY 0xc0 /* [VIS] Eight 8-bit partial store, primary */ +#define ASI_PST8_SECONDARY 0xc1 /* [VIS] Eight 8-bit partial store, secondary */ +#define ASI_PST16_PRIMARY 0xc2 /* [VIS] Four 16-bit partial store, primary */ +#define ASI_PST16_SECONDARY 0xc3 /* [VIS] Fout 16-bit partial store, secondary */ +#define ASI_PST32_PRIMARY 0xc4 /* [VIS] Two 32-bit partial store, primary */ +#define ASI_PST32_SECONDARY 0xc5 /* [VIS] Two 32-bit partial store, secondary */ + +#define ASI_PST8_PRIMARY_LITTLE 0xc8 /* [VIS] Eight 8-bit partial store, primary, little endian */ +#define ASI_PST8_SECONDARY_LITTLE 0xc9 /* [VIS] Eight 8-bit partial store, secondary, little endian */ +#define ASI_PST16_PRIMARY_LITTLE 0xca /* [VIS] Four 16-bit partial store, primary, little endian */ +#define ASI_PST16_SECONDARY_LITTLE 0xcb /* [VIS] Fout 16-bit partial store, secondary, little endian */ +#define ASI_PST32_PRIMARY_LITTLE 0xcc /* [VIS] Two 32-bit partial store, primary, little endian */ +#define ASI_PST32_SECONDARY_LITTLE 0xcd /* [VIS] Two 32-bit partial store, secondary, little endian */ + +#define ASI_FL8_PRIMARY 0xd0 /* [VIS] One 8-bit load/store floating, primary */ +#define ASI_FL8_SECONDARY 0xd1 /* [VIS] One 8-bit load/store floating, secondary */ +#define ASI_FL16_PRIMARY 0xd2 /* [VIS] One 16-bit load/store floating, primary */ +#define ASI_FL16_SECONDARY 0xd3 /* [VIS] One 16-bit load/store floating, secondary */ + +#define ASI_FL8_PRIMARY_LITTLE 0xd8 /* [VIS] One 8-bit load/store floating, primary, little endian */ +#define ASI_FL8_SECONDARY_LITTLE 0xd9 /* [VIS] One 8-bit load/store floating, secondary, little endian */ +#define ASI_FL16_PRIMARY_LITTLE 0xda /* [VIS] One 16-bit load/store floating, primary, little endian */ +#define ASI_FL16_SECONDARY_LITTLE 0xdb /* [VIS] One 16-bit load/store floating, secondary, little endian */ + +#define ASI_BLOCK_COMMIT_PRIMARY 0xe0 /* [4u] block store with commit, primary */ +#define ASI_BLOCK_COMMIT_SECONDARY 0xe1 /* [4u] block store with commit, secondary */ +#define ASI_BLOCK_PRIMARY 0xf0 /* [4u] block load/store, primary */ +#define ASI_BLOCK_SECONDARY 0xf1 /* [4u] block load/store, secondary */ +#define ASI_BLOCK_PRIMARY_LITTLE 0xf8 /* [4u] block load/store, primary, little endian */ +#define ASI_BLOCK_SECONDARY_LITTLE 0xf9 /* [4u] block load/store, secondary, little endian */ + + +/* + * These are the shorter names used by Solaris + */ + +#define ASI_N ASI_NUCLEUS +#define ASI_NL ASI_NUCLEUS_LITTLE +#define ASI_AIUP ASI_AS_IF_USER_PRIMARY +#define ASI_AIUS ASI_AS_IF_USER_SECONDARY +#define ASI_AIUPL ASI_AS_IF_USER_PRIMARY_LITTLE +#define ASI_AIUSL ASI_AS_IF_USER_SECONDARY_LITTLE +#define ASI_P ASI_PRIMARY +#define ASI_S ASI_SECONDARY +#define ASI_PNF ASI_PRIMARY_NOFAULT +#define ASI_SNF ASI_SECONDARY_NOFAULT +#define ASI_PL ASI_PRIMARY_LITTLE +#define ASI_SL ASI_SECONDARY_LITTLE +#define ASI_PNFL ASI_PRIMARY_NOFAULT_LITTLE +#define ASI_SNFL ASI_SECONDARY_NOFAULT_LITTLE +#define ASI_FL8_P ASI_FL8_PRIMARY +#define ASI_FL8_S ASI_FL8_SECONDARY +#define ASI_FL16_P ASI_FL16_PRIMARY +#define ASI_FL16_S ASI_FL16_SECONDARY +#define ASI_FL8_PL ASI_FL8_PRIMARY_LITTLE +#define ASI_FL8_SL ASI_FL8_SECONDARY_LITTLE +#define ASI_FL16_PL ASI_FL16_PRIMARY_LITTLE +#define ASI_FL16_SL ASI_FL16_SECONDARY_LITTLE +#define ASI_BLK_AIUP ASI_BLOCK_AS_IF_USER_PRIMARY +#define ASI_BLK_AIUPL ASI_BLOCK_AS_IF_USER_PRIMARY_LITTLE +#define ASI_BLK_AIUS ASI_BLOCK_AS_IF_USER_SECONDARY +#define ASI_BLK_AIUSL ASI_BLOCK_AS_IF_USER_SECONDARY_LITTLE +#define ASI_BLK_COMMIT_P ASI_BLOCK_COMMIT_PRIMARY +#define ASI_BLK_COMMIT_PRIMARY ASI_BLOCK_COMMIT_PRIMARY +#define ASI_BLK_COMMIT_S ASI_BLOCK_COMMIT_SECONDARY +#define ASI_BLK_COMMIT_SECONDARY ASI_BLOCK_COMMIT_SECONDARY +#define ASI_BLK_P ASI_BLOCK_PRIMARY +#define ASI_BLK_PL ASI_BLOCK_PRIMARY_LITTLE +#define ASI_BLK_S ASI_BLOCK_SECONDARY +#define ASI_BLK_SL ASI_BLOCK_SECONDARY_LITTLE + +/* Alternative spellings */ +#define ASI_PRIMARY_NO_FAULT ASI_PRIMARY_NOFAULT +#define ASI_PRIMARY_NO_FAULT_LITTLE ASI_PRIMARY_NOFAULT_LITTLE +#define ASI_SECONDARY_NO_FAULT ASI_SECONDARY_NOFAULT +#define ASI_SECONDARY_NO_FAULT_LITTLE ASI_SECONDARY_NOFAULT_LITTLE + +#define PHYS_ASI(x) (((x) | 0x09) == 0x1d) +#define LITTLE_ASI(x) ((x) & ASI_LITTLE) + +/* + * %tick: cpu cycle counter + */ +#define TICK_NPT 0x8000000000000000 /* trap on non priv access */ +#define TICK_TICKS 0x7fffffffffffffff /* counter bits */ + +/* + * The following are 4u control registers + */ + +/* Get the CPU's UPA port ID */ +#define UPA_CR_MID(x) (((x) >> 17) & 0x1f) +#define CPU_UPAID UPA_CR_MID(ldxa(0, ASI_MID_REG)) + +/* Get the CPU's Fireplane agent ID */ +#define FIREPLANE_CR_AID(x) (((x) >> 17) & 0x3ff) +#define CPU_FIREPLANEID FIREPLANE_CR_AID(ldxa(0, ASI_MID_REG)) + +/* Get the CPU's Jupiter Bus interrupt target ID */ +#define JUPITER_CR_ITID(x) ((x) & 0x3ff) +#define CPU_JUPITERID JUPITER_CR_ITID(ldxa(0, ASI_MID_REG)) + +/* + * [4u] MMU and Cache Control Register (MCCR) + * use ASI = 0x45 + */ +#define ASI_MCCR ASI_LSU_CONTROL_REGISTER +#define MCCR 0x00 + +/* MCCR Bits and their meanings */ +#define MCCR_DMMU_EN 0x08 +#define MCCR_IMMU_EN 0x04 +#define MCCR_DCACHE_EN 0x02 +#define MCCR_ICACHE_EN 0x01 + + +/* + * MMU control registers + */ + +/* Choose an MMU */ +#define ASI_DMMU 0x58 +#define ASI_IMMU 0x50 + +/* Other assorted MMU ASIs */ +#define ASI_IMMU_8KPTR 0x51 +#define ASI_IMMU_64KPTR 0x52 +#define ASI_IMMU_DATA_IN 0x54 +#define ASI_IMMU_TLB_DATA 0x55 +#define ASI_IMMU_TLB_TAG 0x56 +#define ASI_DMMU_8KPTR 0x59 +#define ASI_DMMU_64KPTR 0x5a +#define ASI_DMMU_DATA_IN 0x5c +#define ASI_DMMU_TLB_DATA 0x5d +#define ASI_DMMU_TLB_TAG 0x5e + +/* + * The following are the control registers + * They work on both MMUs unless noted. + * III = cheetah only + * + * Register contents are defined later on individual registers. + */ +#define TSB_TAG_TARGET 0x0 +#define TLB_DATA_IN 0x0 +#define CTX_PRIMARY 0x08 /* primary context -- DMMU only */ +#define CTX_SECONDARY 0x10 /* secondary context -- DMMU only */ +#define SFSR 0x18 +#define SFAR 0x20 /* fault address -- DMMU only */ +#define TSB 0x28 +#define TLB_TAG_ACCESS 0x30 +#define VIRTUAL_WATCHPOINT 0x38 +#define PHYSICAL_WATCHPOINT 0x40 +#define TSB_PEXT 0x48 /* III primary ext */ +#define TSB_SEXT 0x50 /* III 2ndary ext -- DMMU only */ +#define TSB_NEXT 0x58 /* III nucleus ext */ + +/* Tag Target bits */ +#define TAG_TARGET_VA_MASK 0x03ffffffffffffffffLL +#define TAG_TARGET_VA(x) (((x)<<22)&TAG_TARGET_VA_MASK) +#define TAG_TARGET_CONTEXT(x) ((x)>>48) +#define TAG_TARGET(c,v) ((((uint64_t)c)<<48)|(((uint64_t)v)&TAG_TARGET_VA_MASK)) + +/* SFSR bits for both D_SFSR and I_SFSR */ +#define SFSR_NF 0x1000000 /* Non-faulting load */ +#define SFSR_ASI(x) ((x)>>16) +#define SFSR_TM 0x0008000 /* TLB miss */ +#define SFSR_FT_VA_OOR_2 0x0002000 /* IMMU: jumpl or return to unsupported VA */ +#define SFSR_FT_VA_OOR_1 0x0001000 /* fault at unsupported VA */ +#define SFSR_FT_NFO 0x0000800 /* DMMU: Access to page marked NFO */ +#define SFSR_ILL_ASI 0x0000400 /* DMMU: Illegal (unsupported) ASI */ +#define SFSR_FT_IO_ATOMIC 0x0000200 /* DMMU: Atomic access to noncacheable page */ +#define SFSR_FT_ILL_NF 0x0000100 /* DMMU: NF load or flush to page marked E (has side effects) */ +#define SFSR_FT_PRIV 0x0000080 /* Privilege violation */ +#define SFSR_FT_E 0x0000040 /* DMUU: value of E bit associated address */ +#define SFSR_CTXT(x) (((x)>>4)&0x3) +#define SFSR_CTXT_IS_PRIM(x) (SFSR_CTXT(x)==0x00) +#define SFSR_CTXT_IS_SECOND(x) (SFSR_CTXT(x)==0x01) +#define SFSR_CTXT_IS_NUCLEUS(x) (SFSR_CTXT(x)==0x02) +#define SFSR_PRIV 0x0000008 /* value of PSTATE.PRIV for faulting access */ +#define SFSR_W 0x0000004 /* DMMU: attempted write */ +#define SFSR_OW 0x0000002 /* Overwrite; prev fault was still valid */ +#define SFSR_FV 0x0000001 /* Fault is valid */ +#define SFSR_FT (SFSR_FT_VA_OOR_2|SFSR_FT_VA_OOR_1|SFSR_FT_NFO|SFSR_ILL_ASI|SFSR_FT_IO_ATOMIC|SFSR_FT_ILL_NF|SFSR_FT_PRIV) + +#define SFSR_BITS "\20\31NF\20TM\16VAT\15VAD\14NFO\13ASI\12A\11NF\10PRIV\7E\6NUCLEUS\5SECONDCTX\4PRIV\3W\2OW\1FV" + +/* ASFR bits */ +#define ASFR_ME 0x100000000LL +#define ASFR_PRIV 0x080000000LL +#define ASFR_ISAP 0x040000000LL +#define ASFR_ETP 0x020000000LL +#define ASFR_IVUE 0x010000000LL +#define ASFR_TO 0x008000000LL +#define ASFR_BERR 0x004000000LL +#define ASFR_LDP 0x002000000LL +#define ASFR_CP 0x001000000LL +#define ASFR_WP 0x000800000LL +#define ASFR_EDP 0x000400000LL +#define ASFR_UE 0x000200000LL +#define ASFR_CE 0x000100000LL +#define ASFR_ETS 0x0000f0000LL +#define ASFT_P_SYND 0x00000ffffLL + +#define AFSR_BITS "\20" \ + "\20ME\37PRIV\36ISAP\35ETP\34IVUE\33TO\32BERR\31LDP\30CP\27WP\26EDP" \ + "\25UE\24CE" + +/* + * Here's the spitfire TSB control register bits. + * + * Each TSB entry is 16-bytes wide. The TSB must be size aligned + */ +#define TSB_SIZE_512 0x0 /* 8kB, etc. */ +#define TSB_SIZE_1K 0x01 +#define TSB_SIZE_2K 0x02 +#define TSB_SIZE_4K 0x03 +#define TSB_SIZE_8K 0x04 +#define TSB_SIZE_16K 0x05 +#define TSB_SIZE_32K 0x06 +#define TSB_SIZE_64K 0x07 +#define TSB_SPLIT 0x1000 +#define TSB_BASE 0xffffffffffffe000 + +/* TLB Tag Access bits */ +#define TLB_TAG_ACCESS_VA 0xffffffffffffe000 +#define TLB_TAG_ACCESS_CTX 0x0000000000001fff + +/* + * TLB demap registers. TTEs are defined in v9pte.h + * + * Use the address space to select between IMMU and DMMU. + * The address of the register selects which context register + * to read the ASI from. + * + * The data stored in the register is interpreted as the VA to + * use. The DEMAP_CTX_<> registers ignore the address and demap the + * entire ASI. + * + */ +#define ASI_IMMU_DEMAP 0x57 /* [4u] IMMU TLB demap */ +#define ASI_DMMU_DEMAP 0x5f /* [4u] IMMU TLB demap */ + +#define DEMAP_PAGE_NUCLEUS ((0x02)<<4) /* Demap page from kernel AS */ +#define DEMAP_PAGE_PRIMARY ((0x00)<<4) /* Demap a page from primary CTXT */ +#define DEMAP_PAGE_SECONDARY ((0x01)<<4) /* Demap page from secondary CTXT (DMMU only) */ +#define DEMAP_CTX_NUCLEUS ((0x06)<<4) /* Demap all of kernel CTXT */ +#define DEMAP_CTX_PRIMARY ((0x04)<<4) /* Demap all of primary CTXT */ +#define DEMAP_CTX_SECONDARY ((0x05)<<4) /* Demap all of secondary CTXT */ + +/* + * Interrupt registers. This really gets hairy. + */ + +/* IRSR -- Interrupt Receive Status Register */ +#define ASI_IRSR 0x49 +#define IRSR 0x00 +#define IRSR_BUSY 0x020 +#define IRSR_MID(x) (x&0x1f) + +/* IRDR -- Interrupt Receive Data Registers */ +#define ASI_IRDR 0x7f +#define IRDR_0H 0x40 +#define IRDR_0L 0x48 /* unimplemented */ +#define IRDR_1H 0x50 +#define IRDR_1L 0x58 /* unimplemented */ +#define IRDR_2H 0x60 +#define IRDR_2L 0x68 /* unimplemented */ +#define IRDR_3H 0x70 /* unimplemented */ +#define IRDR_3L 0x78 /* unimplemented */ + +/* SOFTINT ASRs */ +#define SET_SOFTINT %asr20 /* Sets these bits */ +#define CLEAR_SOFTINT %asr21 /* Clears these bits */ +#define SOFTINT %asr22 /* Reads the register */ +#define TICK_CMPR %asr23 + +#define TICK_INT 0x01 /* level-14 clock tick */ +#define SOFTINT1 (0x1<<1) +#define SOFTINT2 (0x1<<2) +#define SOFTINT3 (0x1<<3) +#define SOFTINT4 (0x1<<4) +#define SOFTINT5 (0x1<<5) +#define SOFTINT6 (0x1<<6) +#define SOFTINT7 (0x1<<7) +#define SOFTINT8 (0x1<<8) +#define SOFTINT9 (0x1<<9) +#define SOFTINT10 (0x1<<10) +#define SOFTINT11 (0x1<<11) +#define SOFTINT12 (0x1<<12) +#define SOFTINT13 (0x1<<13) +#define SOFTINT14 (0x1<<14) +#define SOFTINT15 (0x1<<15) +#define STICK_INT (0x1<<16) + +/* Interrupt Dispatch -- usually reserved for cross-calls */ +#define ASR_IDSR 0x48 /* Interrupt dispatch status reg */ +#define IDSR 0x00 +#define IDSR_NACK 0x02 +#define IDSR_BUSY 0x01 + +#define ASI_INTERRUPT_DISPATCH 0x77 /* [4u] spitfire interrupt dispatch regs */ + +/* Interrupt delivery initiation */ +#define IDCR(x) ((((u_int64_t)(x)) << 14) | 0x70) + +#define IDDR_0H 0x40 /* Store data to send in these regs */ +#define IDDR_0L 0x48 /* unimplemented */ +#define IDDR_1H 0x50 +#define IDDR_1L 0x58 /* unimplemented */ +#define IDDR_2H 0x60 +#define IDDR_2L 0x68 /* unimplemented */ +#define IDDR_3H 0x80 /* unimplemented */ +#define IDDR_3L 0x88 /* unimplemented */ + +/* + * Error registers + */ + +/* Since we won't try to fix async errs, we don't care about the bits in the regs */ +#define ASI_AFAR 0x4d /* Asynchronous fault address register */ +#define AFAR 0x00 +#define ASI_AFSR 0x4c /* Asynchronous fault status register */ +#define AFSR 0x00 + +#define ASI_P_EER 0x4b /* Error enable register */ +#define P_EER 0x00 +#define P_EER_ISAPEN 0x04 /* Enable fatal on ISAP */ +#define P_EER_NCEEN 0x02 /* Enable trap on uncorrectable errs */ +#define P_EER_CEEN 0x01 /* Enable trap on correctable errs */ + +#define ASI_DATAPATH_READ 0x7f /* Read the regs */ +#define ASI_DATAPATH_WRITE 0x77 /* Write to the regs */ +#define P_DPER_0 0x00 /* Datapath err reg 0 */ +#define P_DPER_1 0x18 /* Datapath err reg 1 */ +#define P_DCR_0 0x20 /* Datapath control reg 0 */ +#define P_DCR_1 0x38 /* Datapath control reg 0 */ + + +/* From sparc64/asm.h which I think I'll deprecate since it makes bus.h a pain. */ + +#ifndef _LOCORE +/* + * GCC __asm constructs for doing assembly stuff. + */ + +/* + * ``Routines'' to load and store from/to alternate address space. + * The location can be a variable, the asi value (address space indicator) + * must be a constant. + * + * N.B.: You can put as many special functions here as you like, since + * they cost no kernel space or time if they are not used. + * + * These were static inline functions, but gcc screws up the constraints + * on the address space identifiers (the "n"umeric value part) because + * it inlines too late, so we have to use the funny valued-macro syntax. + */ + +/* + * Apparently the definition of bypass ASIs is that they all use the + * D$ so we need to flush the D$ to make sure we don't get data pollution. + */ + +#define sparc_wr(name, val, xor) \ +do { \ + if (__builtin_constant_p(xor)) \ + __asm volatile("wr %%g0, %0, %%" #name \ + : : "rI" ((val) ^ (xor)) : "%g0"); \ + else \ + __asm volatile("wr %0, %1, %%" #name \ + : : "r" (val), "rI" (xor) : "%g0"); \ +} while(0) + +#define sparc_wrpr(name, val, xor) \ +do { \ + if (__builtin_constant_p(xor)) \ + __asm volatile("wrpr %%g0, %0, %%" #name \ + : : "rI" ((val) ^ (xor)) : "%g0"); \ + else \ + __asm volatile("wrpr %0, %1, %%" #name \ + : : "r" (val), "rI" (xor) : "%g0"); \ + __asm volatile("" : : : "memory"); \ +} while(0) + + +#define sparc_rd(name) sparc_rd_ ## name() +#define GEN_RD(name) \ +static inline u_int64_t sparc_rd_ ## name(void); \ +static inline u_int64_t \ +sparc_rd_ ## name(void) \ +{ \ + u_int64_t r; \ + __asm volatile("rd %%" #name ", %0" : \ + "=r" (r) : : "%g0"); \ + return (r); \ +} + +#define sparc_rdpr(name) sparc_rdpr_ ## name() +#define GEN_RDPR(name) \ +static inline u_int64_t sparc_rdpr_ ## name(void); \ +static inline u_int64_t \ +sparc_rdpr_ ## name(void) \ +{ \ + u_int64_t r; \ + __asm volatile("rdpr %%" #name ", %0" : \ + "=r" (r) : : "%g0"); \ + return (r); \ +} + +GEN_RD(asi); +GEN_RD(fprs); +GEN_RD(asr22); +GEN_RD(sys_tick); +GEN_RD(sys_tick_cmpr); +GEN_RDPR(tick); +GEN_RDPR(tba); +GEN_RDPR(pstate); +GEN_RDPR(pil); +GEN_RDPR(cwp); +GEN_RDPR(cansave); +GEN_RDPR(canrestore); +GEN_RDPR(cleanwin); +GEN_RDPR(otherwin); +GEN_RDPR(wstate); +GEN_RDPR(ver); +/* + * Before adding GEN_RDPRs for other registers, see Errata 50 (E.g,. in + * the US-IIi manual) regarding tstate, pc and npc reads. + */ + +/* Generate ld*a/st*a functions for non-constant ASI's. */ +#define LDNC_GEN(tp, o) \ + static inline tp o ## _asi(paddr_t); \ + static inline tp \ + o ## _asi(paddr_t va) \ + { \ + tp r; \ + __asm volatile( \ + #o " [%1] %%asi, %0" \ + : "=r" (r) \ + : "r" ((volatile tp *)va) \ + : "%g0"); \ + return (r); \ + } \ + static inline tp o ## _nc(paddr_t, int); \ + static inline tp \ + o ## _nc(paddr_t va, int asi) \ + { \ + sparc_wr(asi, asi, 0); \ + return (o ## _asi(va)); \ + } + +LDNC_GEN(u_char, lduba); +LDNC_GEN(u_short, lduha); +LDNC_GEN(u_int, lduwa); +LDNC_GEN(u_int64_t, ldxa); + +LDNC_GEN(int, lda); + +#define LDC_GEN(va, asi, op, opa, type) ({ \ + type __r ## op ## type; \ + if(asi == ASI_PRIMARY || \ + (sizeof(type) == 1 && asi == ASI_PRIMARY_LITTLE)) \ + __r ## op ## type = *((volatile type *)va); \ + else \ + __asm volatile(#opa " [%1] " #asi ", %0" \ + : "=r" (__r ## op ## type) \ + : "r" ((volatile type *)va) \ + : "%g0"); \ + __r ## op ## type; \ +}) + +#ifdef __OPTIMIZE__ +#define LD_GENERIC(va, asi, op, type) (__builtin_constant_p(asi) ? \ + LDC_GEN((va), asi, op, op ## a, type) : op ## a_nc((va), asi)) +#else /* __OPTIMIZE */ +#define LD_GENERIC(va, asi, op, type) (op ## a_nc((va), asi)) +#endif /* __OPTIMIZE__ */ + +#define lduba(va, asi) LD_GENERIC(va, asi, ldub, u_int8_t) +#define lduha(va, asi) LD_GENERIC(va, asi, lduh, u_int16_t) +#define lduwa(va, asi) LD_GENERIC(va, asi, lduw, u_int32_t) +#define ldxa(va, asi) LD_GENERIC(va, asi, ldx, u_int64_t) + +#define STNC_GEN(tp, o) \ + static inline void o ## _asi(paddr_t, tp); \ + static inline void \ + o ## _asi(paddr_t va, tp val) \ + { \ + __asm volatile( \ + #o " %0, [%1] %%asi" \ + : \ + : "r" (val), "r" ((volatile tp *)va) \ + : "memory"); \ + } \ + static inline void o ## _nc(paddr_t, int, tp); \ + static inline void \ + o ## _nc(paddr_t va, int asi, tp val) \ + { \ + sparc_wr(asi, asi, 0); \ + o ## _asi(va, val); \ + } + +STNC_GEN(u_int8_t, stba); +STNC_GEN(u_int16_t, stha); +STNC_GEN(u_int32_t, stwa); +STNC_GEN(u_int64_t, stxa); + +STNC_GEN(u_int, sta); + +#define STC_GEN(va, asi, val, op, opa, type) ({ \ + if(asi == ASI_PRIMARY || \ + (sizeof(type) == 1 && asi == ASI_PRIMARY_LITTLE)) \ + *((volatile type *)va) = val; \ + else \ + __asm volatile(#opa " %0, [%1] " #asi \ + : : "r" (val), "r" ((volatile type *)va) \ + : "memory"); \ + }) + +#ifdef __OPTIMIZE__ +#define ST_GENERIC(va, asi, val, op, type) (__builtin_constant_p(asi) ? \ + STC_GEN((va), (asi), (val), op, op ## a, type) : \ + op ## a_nc((va), asi, (val))) +#else /* __OPTIMIZE__ */ +#define ST_GENERIC(va, asi, val, op, type) (op ## a_nc((va), asi, (val))) +#endif /* __OPTIMIZE__ */ + +#define stba(va, asi, val) ST_GENERIC(va, asi, val, stb, u_int8_t) +#define stha(va, asi, val) ST_GENERIC(va, asi, val, sth, u_int16_t) +#define stwa(va, asi, val) ST_GENERIC(va, asi, val, stw, u_int32_t) +#define stxa(va, asi, val) ST_GENERIC(va, asi, val, stx, u_int64_t) + + +static inline void asi_set(int); +static inline void +asi_set(int asi) +{ + sparc_wr(asi, asi, 0); +} + +static inline u_int8_t asi_get(void); +static inline u_int8_t +asi_get(void) +{ + return sparc_rd(asi); +} + +/* flush address from instruction cache */ +static inline void flush(void *); +static inline void +flush(void *p) +{ + __asm volatile("flush %0" + : : "r" (p) + : "memory"); +} + +/* Read 64-bit %tick and %sys_tick registers. */ +#define tick() (sparc_rdpr(tick) & TICK_TICKS) +#define sys_tick() (sparc_rd(sys_tick) & TICK_TICKS) +extern u_int64_t stick(void); + +extern void tick_enable(void); +extern void sys_tick_enable(void); + +extern void tickcmpr_set(u_int64_t); +extern void sys_tickcmpr_set(u_int64_t); +extern void stickcmpr_set(u_int64_t); + +#endif /* _LOCORE */ +#endif /* _SPARC64_CTLREG_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/db_machdep.h b/lib/libc/include/sparc64-openbsd-none/machine/db_machdep.h new file mode 100644 index 0000000000..9edef3be53 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/db_machdep.h @@ -0,0 +1,145 @@ +/* $OpenBSD: db_machdep.h,v 1.23 2022/10/21 18:55:42 miod Exp $ */ +/* $NetBSD: db_machdep.h,v 1.12 2001/07/07 15:16:13 eeh Exp $ */ + +/* + * Mach Operating System + * Copyright (c) 1991,1990 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +#ifndef _MACHINE_DB_MACHDEP_H_ +#define _MACHINE_DB_MACHDEP_H_ + +/* + * Machine-dependent defines for new kernel debugger. + */ + +#include + +#include +#include +#include +#include + +/* end of mangling */ + +typedef long db_expr_t; /* expression - signed */ + +struct trapstate { + int64_t tstate; + int64_t tpc; + int64_t tnpc; + int64_t tt; +}; +#if 1 +typedef struct { + struct trapframe ddb_tf; + struct frame ddb_fr; + struct trapstate ddb_ts[5]; + int ddb_tl; + struct fpstate ddb_fpstate; +} db_regs_t; +#else +typedef struct db_regs { + struct trapregs dbr_traps[4]; + int dbr_y; + char dbr_tl; + char dbr_canrestore; + char dbr_cansave; + char dbr_cleanwin; + char dbr_cwp; + char dbr_wstate; + int64_t dbr_g[8]; + int64_t dbr_ag[8]; + int64_t dbr_ig[8]; + int64_t dbr_mg[8]; + int64_t dbr_out[8]; + int64_t dbr_local[8]; + int64_t dbr_in[8]; +} db_regs_t; +#endif + +extern db_regs_t ddb_regs; /* register state */ +#define DDB_TF (&ddb_regs.ddb_tf) +#define DDB_FR (&ddb_regs.ddb_fr) +#define DDB_FP (&ddb_regs.ddb_fpstate) + +#define PC_REGS(regs) ((vaddr_t)(regs)->ddb_tf.tf_pc) +#define SET_PC_REGS(regs, value) (regs)->ddb_tf.tf_pc = (int32_t)(value) +#define PC_ADVANCE(regs) do { \ + vaddr_t n = (regs)->ddb_tf.tf_npc; \ + (regs)->ddb_tf.tf_pc = n; \ + (regs)->ddb_tf.tf_npc = n + 4; \ +} while(0) + +#define BKPT_INST 0x91d02001 /* breakpoint instruction */ +#define BKPT_SIZE (4) /* size of breakpoint inst */ +#define BKPT_SET(inst) (BKPT_INST) + +#define IS_BREAKPOINT_TRAP(type, code) \ + ((type) == T_BREAKPOINT || (type) == T_KGDB_EXEC) +#define IS_WATCHPOINT_TRAP(type, code) \ + ((type) ==T_PA_WATCHPT || (type) == T_VA_WATCHPT) + +/* + * Sparc cpus have no hardware single-step. + */ +#define SOFTWARE_SSTEP + +int db_inst_trap_return(int inst); +int db_inst_return(int inst); +int db_inst_call(int inst); +int db_inst_branch(int inst); +int db_inst_unconditional_flow_transfer(int inst); +vaddr_t db_branch_taken(int inst, vaddr_t pc, db_regs_t *regs); + +#define inst_trap_return(ins) db_inst_trap_return(ins) +#define inst_return(ins) db_inst_return(ins) +#define inst_call(ins) db_inst_call(ins) +#define inst_branch(ins) db_inst_branch(ins) +#define inst_unconditional_flow_transfer(ins) \ + db_inst_unconditional_flow_transfer(ins) +#define branch_taken(ins, pc, fun, regs) \ + db_branch_taken((ins), (pc), (regs)) + +/* see note in db_interface.c about reversed breakpoint addrs */ +#define next_instr_address(pc, bd) \ + ((bd) ? (pc) : ddb_regs.ddb_tf.tf_npc) + +#define DB_MACHINE_COMMANDS + +void db_machine_init(void); +int db_ktrap(int, struct trapframe *); + +int db_enter_ddb(void); +void db_startcpu(struct cpu_info *); +void db_stopcpu(struct cpu_info *); + +#define DDB_STATE_NOT_RUNNING 0 +#define DDB_STATE_RUNNING 1 +#define DDB_STATE_EXITING 2 + +/* Register device-specific method for triggering XIRs. */ +void db_register_xir(void (*)(void *, int), void *); + +#endif /* _MACHINE_DB_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/disklabel.h b/lib/libc/include/sparc64-openbsd-none/machine/disklabel.h new file mode 100644 index 0000000000..5b9d93732a --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/disklabel.h @@ -0,0 +1,40 @@ +/* $OpenBSD: disklabel.h,v 1.5 2015/09/30 14:57:03 krw Exp $ */ + +/* + * Copyright (c) 1994 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 _MACHINE_DISKLABEL_H_ +#define _MACHINE_DISKLABEL_H_ + +#define LABELSECTOR 0 /* sector containing label */ +#define LABELOFFSET 128 /* offset of label in sector */ +#define MAXPARTITIONS 16 /* number of partitions */ + +#endif /* _MACHINE_DISKLABEL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/elf.h b/lib/libc/include/sparc64-openbsd-none/machine/elf.h new file mode 100644 index 0000000000..1a69b90df3 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/elf.h @@ -0,0 +1,7 @@ +/* $OpenBSD: elf.h,v 1.1 2024/07/14 09:48:49 jca Exp $ */ + +/* + * This file is in the public domain. + */ + +/* Nothing for now */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/endian.h b/lib/libc/include/sparc64-openbsd-none/machine/endian.h new file mode 100644 index 0000000000..ed220930b5 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/endian.h @@ -0,0 +1,84 @@ +/* $OpenBSD: endian.h,v 1.7 2014/10/22 23:56:47 dlg Exp $ */ + +#ifndef _MACHINE_ENDIAN_H_ +#define _MACHINE_ENDIAN_H_ + +#define _BYTE_ORDER _BIG_ENDIAN + +#ifdef _KERNEL + +#define __ASI_P_L 0x88 /* == ASI_PRIMARY_LITTLE */ + +static inline __uint16_t +__mswap16(volatile const __uint16_t *m) +{ + __uint16_t v; + + __asm("lduha [%1] %2, %0 ! %3" + : "=r" (v) + : "r" (m), "n" (__ASI_P_L), "m" (*m)); + + return (v); +} + +static inline __uint32_t +__mswap32(volatile const __uint32_t *m) +{ + __uint32_t v; + + __asm("lduwa [%1] %2, %0 ! %3" + : "=r" (v) + : "r" (m), "n" (__ASI_P_L), "m" (*m)); + + return (v); +} + +static inline __uint64_t +__mswap64(volatile const __uint64_t *m) +{ + __uint64_t v; + + __asm("ldxa [%1] %2, %0 ! %3" + : "=r" (v) + : "r" (m), "n" (__ASI_P_L), "m" (*m)); + + return (v); +} + +static inline void +__swapm16(volatile __uint16_t *m, __uint16_t v) +{ + __asm("stha %1, [%2] %3 ! %0" + : "=m" (*m) + : "r" (v), "r" (m), "n" (__ASI_P_L)); +} + +static inline void +__swapm32(volatile __uint32_t *m, __uint32_t v) +{ + __asm("stwa %1, [%2] %3 ! %0" + : "=m" (*m) + : "r" (v), "r" (m), "n" (__ASI_P_L)); +} + +static inline void +__swapm64(volatile __uint64_t *m, __uint64_t v) +{ + __asm("stxa %1, [%2] %3 ! %0" + : "=m" (*m) + : "r" (v), "r" (m), "n" (__ASI_P_L)); +} + +#undef __ASI_P_L + +#define __HAVE_MD_SWAPIO + +#endif /* _KERNEL */ + +#define __STRICT_ALIGNMENT + +#ifndef __FROM_SYS__ENDIAN +#include +#endif + +#endif /* _MACHINE_ENDIAN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/exec.h b/lib/libc/include/sparc64-openbsd-none/machine/exec.h new file mode 100644 index 0000000000..e71ec31b24 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/exec.h @@ -0,0 +1,99 @@ +/* $OpenBSD: exec.h,v 1.11 2017/02/08 05:09:26 guenther Exp $ */ +/* $NetBSD: elf_machdep.h,v 1.7 2001/02/11 00:18:49 eeh Exp $ */ + +#define ARCH_ELFSIZE 64 /* MD native binary size */ +#define ELF_TARG_CLASS ELFCLASS64 +#define ELF_TARG_MACH EM_SPARCV9 + +#define ELF_TARG_DATA ELFDATA2MSB + +/* The following are what is used for AT_SUN_HWCAP: */ +#define AV_SPARC_HWMUL_32x32 1 /* 32x32-bit smul/umul is efficient */ +#define AV_SPARC_HWDIV_32x32 2 /* 32x32-bit sdiv/udiv is efficient */ +#define AV_SPARC_HWFSMULD 4 /* fsmuld is efficient */ + +/* + * Here are some SPARC specific flags I can't + * find a better home for. They are used for AT_FLAGS + * and in the exec header. + */ +#define EF_SPARCV9_MM 0x3 +#define EF_SPARCV9_TSO 0x0 +#define EF_SPARCV9_PSO 0x1 +#define EF_SPARCV9_RMO 0x2 + +#define EF_SPARC_32PLUS_MASK 0xffff00 /* bits indicating V8+ type */ +#define EF_SPARC_32PLUS 0x000100 /* generic V8+ features */ +#define EF_SPARC_EXT_MASK 0xffff00 /* bits for vendor extensions */ +#define EF_SPARC_SUN_US1 0x000200 /* UltraSPARC 1 extensions */ +#define EF_SPARC_HAL_R1 0x000400 /* HAL R1 extensions */ +#define EF_SPARC_SUN_US3 0x000800 /* UltraSPARC 3 extensions */ + +/* Relocation types */ +#define R_SPARC_NONE 0 +#define R_SPARC_8 1 +#define R_SPARC_16 2 +#define R_SPARC_32 3 +#define R_SPARC_DISP8 4 +#define R_SPARC_DISP16 5 +#define R_SPARC_DISP32 6 +#define R_SPARC_WDISP30 7 +#define R_SPARC_WDISP22 8 +#define R_SPARC_HI22 9 +#define R_SPARC_22 10 +#define R_SPARC_13 11 +#define R_SPARC_LO10 12 +#define R_SPARC_GOT10 13 +#define R_SPARC_GOT13 14 +#define R_SPARC_GOT22 15 +#define R_SPARC_PC10 16 +#define R_SPARC_PC22 17 +#define R_SPARC_WPLT30 18 +#define R_SPARC_COPY 19 +#define R_SPARC_GLOB_DAT 20 +#define R_SPARC_JMP_SLOT 21 +#define R_SPARC_RELATIVE 22 +#define R_SPARC_UA32 23 +#define R_SPARC_PLT32 24 +#define R_SPARC_HIPLT22 25 +#define R_SPARC_LOPLT10 26 +#define R_SPARC_PCPLT32 27 +#define R_SPARC_PCPLT22 28 +#define R_SPARC_PCPLT10 29 +#define R_SPARC_10 30 +#define R_SPARC_11 31 +#define R_SPARC_64 32 +#define R_SPARC_OLO10 33 +#define R_SPARC_HH22 34 +#define R_SPARC_HM10 35 +#define R_SPARC_LM22 36 +#define R_SPARC_PC_HH22 37 +#define R_SPARC_PC_HM10 38 +#define R_SPARC_PC_LM22 39 +#define R_SPARC_WDISP16 40 +#define R_SPARC_WDISP19 41 +#define R_SPARC_GLOB_JMP 42 +#define R_SPARC_7 43 +#define R_SPARC_5 44 +#define R_SPARC_6 45 +#define R_SPARC_DISP64 46 +#define R_SPARC_PLT64 47 +#define R_SPARC_HIX22 48 +#define R_SPARC_LOX10 49 +#define R_SPARC_H44 50 +#define R_SPARC_M44 51 +#define R_SPARC_L44 52 +#define R_SPARC_REGISTER 53 +#define R_SPARC_UA64 54 +#define R_SPARC_UA16 55 +#define R_SPARC_TLS_DTPMOD32 74 +#define R_SPARC_TLS_DTPMOD64 75 +#define R_SPARC_TLS_DTPOFF32 76 +#define R_SPARC_TLS_DTPOFF64 77 +#define R_SPARC_TLS_TPOFF32 78 +#define R_SPARC_TLS_TPOFF64 79 + + +#define R_TYPE(name) __CONCAT(R_SPARC_,name) + +#define __LDPGSZ 8192 /* linker page size */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/fbvar.h b/lib/libc/include/sparc64-openbsd-none/machine/fbvar.h new file mode 100644 index 0000000000..6815f31490 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/fbvar.h @@ -0,0 +1,80 @@ +/* $OpenBSD: fbvar.h,v 1.8 2008/12/29 22:07:35 miod Exp $ */ +/* $NetBSD: fbvar.h,v 1.9 1997/07/07 23:31:30 pk Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)fbvar.h 8.1 (Berkeley) 6/11/93 + */ + +/* + * Common frame buffer variables. + * All framebuffer softc structures must start with such a structure. + */ +struct sunfb { + struct device sf_dev; /* base device */ + + int sf_width; + int sf_height; + int sf_depth; + int sf_linebytes; + + int sf_fbsize; /* sf_height * sf_linebytes */ + + int *sf_crowp, *sf_ccolp; /* PROM cursor position */ + + struct rasops_info sf_ro; + + struct wsscreen_descr sf_wsd; + struct wsscreen_list sf_wsl; + struct wsscreen_descr *sf_scrlist[1]; + int sf_nscreens; +}; + +/* + * Selected framebuffer node on OBP systems if k/d console. + */ +extern int fbnode; + +void fb_setsize(struct sunfb*, int, int, int, int, int); +void fbwscons_init(struct sunfb *, int, int); +void fbwscons_console_init(struct sunfb *, int); +void fbwscons_setcolormap(struct sunfb *, + void (*)(void *, u_int, u_int8_t, u_int8_t, u_int8_t)); +void fbwscons_attach(struct sunfb *, struct wsdisplay_accessops *, int); + +int ifb_ident(void *); \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/fenv.h b/lib/libc/include/sparc64-openbsd-none/machine/fenv.h new file mode 100644 index 0000000000..9fb328fd32 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/fenv.h @@ -0,0 +1,108 @@ +/* $OpenBSD: fenv.h,v 1.4 2011/05/25 21:46:49 martynas Exp $ */ +/* $NetBSD: fenv.h,v 1.1.2.2 2011/02/08 16:19:41 bouyer Exp $ */ + +/*- + * Copyright (c) 2004-2005 David Schultz + * 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 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 AUTHOR 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. + * + * $FreeBSD$ + */ + +#ifndef _SPARC64_FENV_H_ +#define _SPARC64_FENV_H_ + +/* + * Each symbol representing a floating point exception expands to an integer + * constant expression with values, such that bitwise-inclusive ORs of _all + * combinations_ of the constants result in distinct values. + * + * We use such values that allow direct bitwise operations on FPU registers. + */ +#define FE_INEXACT 0x020 +#define FE_DIVBYZERO 0x040 +#define FE_UNDERFLOW 0x080 +#define FE_OVERFLOW 0x100 +#define FE_INVALID 0x200 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * exception constants defined above. + */ +#define FE_ALL_EXCEPT (FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | \ + FE_OVERFLOW | FE_INVALID) +#define _MASK_SHIFT 18 + +/* + * Each symbol representing the rounding direction, expands to an integer + * constant expression whose value is distinct non-negative value. + * + * We use such values that allow direct bitwise operations on FPU registers. + */ +#define FE_TONEAREST 0x0 +#define FE_TOWARDZERO 0x1 +#define FE_UPWARD 0x2 +#define FE_DOWNWARD 0x3 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * rounding direction constants defined above. + */ +#define _ROUND_MASK (FE_TONEAREST | FE_TOWARDZERO | FE_UPWARD | \ + FE_DOWNWARD) +#define _ROUND_SHIFT 30 + +/* + * fenv_t represents the entire floating-point environment. + */ +typedef unsigned long fenv_t; + +/* + * The following constant represents the default floating-point environment + * (that is, the one installed at program startup) and has type pointer to + * const-qualified fenv_t. + * + * It can be used as an argument to the functions within the header + * that manage the floating-point environment, namely fesetenv() and + * feupdateenv(). + */ +__BEGIN_DECLS +extern fenv_t __fe_dfl_env; +__END_DECLS +#define FE_DFL_ENV ((const fenv_t *)&__fe_dfl_env) + +/* + * fexcept_t represents the floating-point status flags collectively, including + * any status the implementation associates with the flags. + * + * A floating-point status flag is a system variable whose value is set (but + * never cleared) when a floating-point exception is raised, which occurs as a + * side effect of exceptional floating-point arithmetic to provide auxiliary + * information. + * + * A floating-point control mode is a system variable whose value may be set by + * the user to affect the subsequent behavior of floating-point arithmetic. + */ +typedef unsigned long fexcept_t; + +#endif /* !_SPARC64_FENV_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/frame.h b/lib/libc/include/sparc64-openbsd-none/machine/frame.h new file mode 100644 index 0000000000..4b077a0ce6 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/frame.h @@ -0,0 +1,105 @@ +/* $OpenBSD: frame.h,v 1.11 2024/04/08 20:07:53 miod Exp $ */ +/* $NetBSD: frame.h,v 1.9 2001/03/04 09:28:35 mrg Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)frame.h 8.1 (Berkeley) 6/11/93 + */ + +#ifndef _MACHINE_FRAME_H_ +#define _MACHINE_FRAME_H_ + +/* + * CC64FSZ (C Compiler 64-bit Frame SiZe) is the size of a stack frame used + * by the compiler in 64-bit mode. It is (16)*8; space for 8 ins, 8 outs. + */ +#define CC64FSZ 176 + +/* + * v9 stacks all have a bias of 2047 added to the %sp and %fp, so you can easily + * detect it by testing the register for an odd value. Why 2K-1 I don't know. + */ +#define BIAS (2048-1) + +#if defined(_KERNEL) && !defined(_LOCORE) + +/* + * Sparc v9 stack frame format. + * + * Note that the contents of each stack frame may be held only in + * machine register windows. In order to get an accurate picture + * of the frame, you must first force the kernel to write any such + * windows to the stack. + * + * V9 frames have an odd bias, so you can tell a v9 frame from + * a v8 frame by testing the stack pointer's lsb. + */ +struct frame { + int64_t fr_local[8]; /* space to save locals (%l0..%l7) */ + int64_t fr_arg[6]; /* space to save arguments (%i0..%i5) */ + u_int64_t fr_fp; /* space to save frame pointer (%i6) */ + u_int64_t fr_pc; /* space to save return pc (%i7) */ + /* + * SVR4 reserves a bunch of extra stuff. + */ + int64_t fr_argd[6]; /* `register save area' (lunacy) */ + int64_t fr_argx[0]; /* arg extension (args 7..n; variable size) */ +}; + +#define v9next_frame(f) ((struct frame*)(f->fr_fp+BIAS)) + +/* + * The v9 trapframe. + */ +struct trapframe { + int64_t tf_tstate; /* tstate register */ + int64_t tf_pc; /* return pc */ + int64_t tf_npc; /* return npc */ + int tf_y; /* %y register -- 32-bits */ + short tf_tt; /* What type of trap this was */ + char tf_pil; /* What IRQ we're handling */ + char tf_oldpil; /* What our old SPL was */ + int64_t tf_global[8]; /* global registers in trap's caller */ + int64_t tf_out[8]; /* output registers in trap's caller */ + int64_t tf_local[8]; /* local registers in trap's caller */ + int64_t tf_in[8]; /* in registers in trap's caller (for debug) */ +}; + +#endif /* _KERNEL && !_LOCORE */ + +#endif /* _MACHINE_FRAME_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/fsr.h b/lib/libc/include/sparc64-openbsd-none/machine/fsr.h new file mode 100644 index 0000000000..d6689e55f9 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/fsr.h @@ -0,0 +1,132 @@ +/* $OpenBSD: fsr.h,v 1.2 2003/06/02 23:27:56 millert Exp $ */ +/* $NetBSD: fsr.h,v 1.1.1.1 1998/06/20 04:58:51 eeh Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)fsr.h 8.1 (Berkeley) 6/11/93 + */ + +#ifndef _MACHINE_FSR_H_ +#define _MACHINE_FSR_H_ + +/* + * Bits in FPRS + */ +#define FPRS_FEF 0x04 /* Enable FP -- must be set to enable FP regs */ +#define FPRS_DU 0x02 /* Dirty upper -- upper fp regs are dirty */ +#define FPRS_DL 0x01 /* Dirty lower -- lower fp regs are dirty */ + +/* + * Bits in FSR. + */ + +#define FSR_RD 0xc0000000 /* rounding direction */ +#define FSR_RD_RN 0 /* round to nearest */ +#define FSR_RD_RZ 1 /* round towards 0 */ +#define FSR_RD_RP 2 /* round towards +inf */ +#define FSR_RD_RM 3 /* round towards -inf */ +#define FSR_RD_SHIFT 30 +#define FSR_RD_MASK 0x03 + +#define FSR_RP 0x30000000 /* extended rounding precision */ +#define FSR_RP_X 0 /* extended stays extended */ +#define FSR_RP_S 1 /* extended => single */ +#define FSR_RP_D 2 /* extended => double */ +#define FSR_RP_80 3 /* extended => 80-bit */ +#define FSR_RP_SHIFT 28 +#define FSR_RP_MASK 0x03 + +#define FSR_TEM 0x0f800000 /* trap enable mask */ +#define FSR_TEM_SHIFT 23 +#define FSR_TEM_MASK 0x1f + +#define FSR_NS 0x00400000 /* ``nonstandard mode'' */ +#define FSR_AU 0x00400000 /* aka abrupt underflow mode */ +#define FSR_MBZ 0x00300000 /* reserved; must be zero */ + +#define FSR_VER 0x000e0000 /* version bits */ +#define FSR_VER_SHIFT 17 +#define FSR_VER_MASK 0x07 + +#define FSR_FTT 0x0001c000 /* FP trap type */ +#define FSR_TT_NONE 0 /* no trap */ +#define FSR_TT_IEEE 1 /* IEEE exception */ +#define FSR_TT_UNFIN 2 /* unfinished operation */ +#define FSR_TT_UNIMP 3 /* unimplemented operation */ +#define FSR_TT_SEQ 4 /* sequence error */ +#define FSR_TT_HWERR 5 /* hardware error (unrecoverable) */ +#define FSR_FTT_SHIFT 14 +#define FSR_FTT_MASK 0x03 + +#define FSR_QNE 0x00002000 /* queue not empty */ +#define FSR_PR 0x00001000 /* partial result */ + +#define FSR_FCC 0x00000c00 /* FP condition codes */ +#define FSR_CC_EQ 0 /* f1 = f2 */ +#define FSR_CC_LT 1 /* f1 < f2 */ +#define FSR_CC_GT 2 /* f1 > f2 */ +#define FSR_CC_UO 3 /* (f1,f2) unordered */ +#define FSR_FCC_SHIFT 10 +#define FSR_FCC_MASK 0x03 + +#define FSR_AX 0x000003e0 /* accrued exceptions */ +#define FSR_AX_SHIFT 5 +#define FSR_AX_MASK 0x1f +#define FSR_CX 0x0000001f /* current exceptions */ +#define FSR_CX_SHIFT 0 +#define FSR_CX_MASK 0x1f + +/* These are the 3 new v9 fcc's */ +#define FSR_FCC3 0x06000000000 /* FP condition codes */ +#define FSR_FCC3_SHIFT 36 + +#define FSR_FCC2 0x0c00000000 /* FP condition codes */ +#define FSR_FCC2_SHIFT 34 + +#define FSR_FCC1 0x0600000000 /* FP condition codes */ +#define FSR_FCC1_SHIFT 32 + + +/* The following exceptions apply to TEM, AX, and CX. */ +#define FSR_NV 0x10 /* invalid operand */ +#define FSR_OF 0x08 /* overflow */ +#define FSR_UF 0x04 /* underflow */ +#define FSR_DZ 0x02 /* division by zero */ +#define FSR_NX 0x01 /* inexact result */ + +#endif /* _MACHINE_FSR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/hypervisor.h b/lib/libc/include/sparc64-openbsd-none/machine/hypervisor.h new file mode 100644 index 0000000000..c8d8cc48dc --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/hypervisor.h @@ -0,0 +1,348 @@ +/* $OpenBSD: hypervisor.h,v 1.21 2024/04/08 20:00:27 miod Exp $ */ + +/* + * Copyright (c) 2008 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * UltraSPARC Hypervisor API. + */ + +/* + * API versioning + */ + +int64_t hv_api_get_version(uint64_t api_group, + uint64_t *major_number, uint64_t *minor_number); + +/* + * Domain services + */ + +int64_t hv_mach_desc(paddr_t buffer, psize_t *length); +int64_t hv_mach_pri(paddr_t buffer, psize_t *length); + +/* + * CPU services + */ + +void hv_cpu_yield(void); +int64_t hv_cpu_qconf(uint64_t queue, uint64_t base, uint64_t nentries); + +#define CPU_MONDO_QUEUE 0x3c +#define DEVICE_MONDO_QUEUE 0x3d +#define RESUMABLE_ERROR_QUEUE 0x3e +#define NONRESUMABLE_ERROR_QUEUE 0x3f + +int64_t hv_cpu_mondo_send(uint64_t ncpus, paddr_t cpulist, paddr_t data); +int64_t hv_cpu_myid(uint64_t *cpuid); + +/* + * MMU services + */ + +int64_t hv_mmu_demap_page(vaddr_t vaddr, uint64_t context, uint64_t flags); +int64_t hv_mmu_demap_ctx(uint64_t context, uint64_t flags); +int64_t hv_mmu_map_perm_addr(vaddr_t vaddr, uint64_t tte, uint64_t flags); +int64_t hv_mmu_unmap_perm_addr(vaddr_t vaddr, uint64_t flags); +int64_t hv_mmu_map_addr(vaddr_t vaddr, uint64_t context, uint64_t tte, + uint64_t flags); +int64_t hv_mmu_unmap_addr(vaddr_t vaddr, uint64_t context, uint64_t flags); + +#define MAP_DTLB 0x1 +#define MAP_ITLB 0x2 + +struct tsb_desc { + uint16_t td_idxpgsz; + uint16_t td_assoc; + uint32_t td_size; + uint32_t td_ctxidx; + uint32_t td_pgsz; + paddr_t td_pa; + uint64_t td_reserved; +}; + +int64_t hv_mmu_tsb_ctx0(uint64_t ntsb, paddr_t tsbptr); +int64_t hv_mmu_tsb_ctxnon0(uint64_t ntsb, paddr_t tsbptr); + +/* + * Cache and memory services + */ + +int64_t hv_mem_scrub(paddr_t raddr, psize_t length); +int64_t hv_mem_sync(paddr_t raddr, psize_t length); + +/* + * Device interrupt services + */ + +int64_t hv_intr_devino_to_sysino(uint64_t devhandle, uint64_t devino, + uint64_t *sysino); +int64_t hv_intr_getenabled(uint64_t sysino, uint64_t *intr_enabled); +int64_t hv_intr_setenabled(uint64_t sysino, uint64_t intr_enabled); +int64_t hv_intr_getstate(uint64_t sysino, uint64_t *intr_state); +int64_t hv_intr_setstate(uint64_t sysino, uint64_t intr_state); +int64_t hv_intr_gettarget(uint64_t sysino, uint64_t *cpuid); +int64_t hv_intr_settarget(uint64_t sysino, uint64_t cpuid); + +#define INTR_DISABLED 0 +#define INTR_ENABLED 1 + +#define INTR_IDLE 0 +#define INTR_RECEIVED 1 +#define INTR_DELIVERED 2 + +int64_t hv_vintr_getcookie(uint64_t devhandle, uint64_t devino, + uint64_t *cookie_value); +int64_t hv_vintr_setcookie(uint64_t devhandle, uint64_t devino, + uint64_t cookie_value); +int64_t hv_vintr_getenabled(uint64_t devhandle, uint64_t devino, + uint64_t *intr_enabled); +int64_t hv_vintr_setenabled(uint64_t devhandle, uint64_t devino, + uint64_t intr_enabled); +int64_t hv_vintr_getstate(uint64_t devhandle, uint64_t devino, + uint64_t *intr_state); +int64_t hv_vintr_setstate(uint64_t devhandle, uint64_t devino, + uint64_t intr_state); +int64_t hv_vintr_gettarget(uint64_t devhandle, uint64_t devino, + uint64_t *cpuid); +int64_t hv_vintr_settarget(uint64_t devhandle, uint64_t devino, + uint64_t cpuid); + +/* + * Time of day services + */ + +int64_t hv_tod_get(uint64_t *tod); +int64_t hv_tod_set(uint64_t tod); + +/* + * Console services + */ + +int64_t hv_cons_getchar(int64_t *ch); +int64_t hv_cons_putchar(int64_t ch); +int64_t hv_api_putchar(int64_t ch); + +#define CONS_BREAK -1 +#define CONS_HUP -2 + +/* + * Domain state services + */ + +int64_t hv_soft_state_set(uint64_t software_state, + paddr_t software_description_ptr); + +#define SIS_NORMAL 0x1 +#define SIS_TRANSITION 0x2 + +/* + * PCI I/O services + */ + +int64_t hv_pci_iommu_map(uint64_t devhandle, uint64_t tsbid, + uint64_t nttes, uint64_t io_attributes, paddr_t io_page_list_p, + uint64_t *nttes_mapped); +int64_t hv_pci_iommu_demap(uint64_t devhandle, uint64_t tsbid, + uint64_t nttes, uint64_t *nttes_demapped); +int64_t hv_pci_iommu_getmap(uint64_t devhandle, uint64_t tsbid, + uint64_t *io_attributes, paddr_t *r_addr); +int64_t hv_pci_iommu_getbypass(uint64_t devhandle, paddr_t r_addr, + uint64_t io_attributes, uint64_t *io_addr); + +int64_t hv_pci_config_get(uint64_t devhandle, uint64_t pci_device, + uint64_t pci_config_offset, uint64_t size, + uint64_t *error_flag, uint64_t *data); +int64_t hv_pci_config_put(uint64_t devhandle, uint64_t pci_device, + uint64_t pci_config_offset, uint64_t size, uint64_t data, + uint64_t *error_flag); + +#define PCI_MAP_ATTR_READ 0x01 /* From memory */ +#define PCI_MAP_ATTR_WRITE 0x02 /* To memory */ + +/* + * PCI MSI services + */ + +int64_t hv_pci_msiq_conf(uint64_t devhandle, uint64_t msiqid, + uint64_t r_addr, uint64_t nentries); +int64_t hv_pci_msiq_info(uint64_t devhandle, uint64_t msiqid, + uint64_t *r_addr, uint64_t *nentries); + +int64_t hv_pci_msiq_getvalid(uint64_t devhandle, uint64_t msiqid, + uint64_t *msiqvalid); +int64_t hv_pci_msiq_setvalid(uint64_t devhandle, uint64_t msiqid, + uint64_t msiqvalid); + +#define PCI_MSIQ_INVALID 0 +#define PCI_MSIQ_VALID 1 + +int64_t hv_pci_msiq_getstate(uint64_t devhandle, uint64_t msiqid, + uint64_t *msiqstate); +int64_t hv_pci_msiq_setstate(uint64_t devhandle, uint64_t msiqid, + uint64_t msiqstate); + +#define PCI_MSIQSTATE_IDLE 0 +#define PCI_MSIQSTATE_ERROR 1 + +int64_t hv_pci_msiq_gethead(uint64_t devhandle, uint64_t msiqid, + uint64_t *msiqhead); +int64_t hv_pci_msiq_sethead(uint64_t devhandle, uint64_t msiqid, + uint64_t msiqhead); +int64_t hv_pci_msiq_gettail(uint64_t devhandle, uint64_t msiqid, + uint64_t *msiqtail); + +int64_t hv_pci_msi_getvalid(uint64_t devhandle, uint64_t msinum, + uint64_t *msivalidstate); +int64_t hv_pci_msi_setvalid(uint64_t devhandle, uint64_t msinum, + uint64_t msivalidstate); + +#define PCI_MSI_INVALID 0 +#define PCI_MSI_VALID 1 + +int64_t hv_pci_msi_getmsiq(uint64_t devhandle, uint64_t msinum, + uint64_t *msiqid); +int64_t hv_pci_msi_setmsiq(uint64_t devhandle, uint64_t msinum, + uint64_t msitype, uint64_t msiqid); + +int64_t hv_pci_msi_getstate(uint64_t devhandle, uint64_t msinum, + uint64_t *msistate); +int64_t hv_pci_msi_setstate(uint64_t devhandle, uint64_t msinum, + uint64_t msistate); + +#define PCI_MSISTATE_IDLE 0 +#define PCI_MSISTATE_DELIVERED 1 + +int64_t hv_pci_msg_getmsiq(uint64_t devhandle, uint64_t msg, + uint64_t *msiqid); +int64_t hv_pci_msg_setmsiq(uint64_t devhandle, uint64_t msg, + uint64_t msiqid); + +int64_t hv_pci_msg_getvalid(uint64_t devhandle, uint64_t msg, + uint64_t *msgvalidstate); +int64_t hv_pci_msg_setvalid(uint64_t devhandle, uint64_t msg, + uint64_t msgvalidstate); + +#define PCIE_MSG_INVALID 0 +#define PCIE_MSG_VALID 1 + +#define PCIE_PME_MSG 0x18 +#define PCIE_PME_ACK_MSG 0x1b +#define PCIE_CORR_MSG 0x30 +#define PCIE_NONFATAL_MSG 0x31 +#define PCIE_FATAL_MSG 0x32 + +/* + * Logical Domain Channel services + */ + +int64_t hv_ldc_tx_qconf(uint64_t ldc_id, paddr_t base_raddr, + uint64_t nentries); +int64_t hv_ldc_tx_qinfo(uint64_t ldc_id, paddr_t *base_raddr, + uint64_t *nentries); +int64_t hv_ldc_tx_get_state(uint64_t ldc_id, uint64_t *head_offset, + uint64_t *tail_offset, uint64_t *channel_state); +int64_t hv_ldc_tx_set_qtail(uint64_t ldc_id, uint64_t tail_offset); +int64_t hv_ldc_rx_qconf(uint64_t ldc_id, paddr_t base_raddr, + uint64_t nentries); +int64_t hv_ldc_rx_qinfo(uint64_t ldc_id, paddr_t *base_raddr, + uint64_t *nentries); +int64_t hv_ldc_rx_get_state(uint64_t ldc_id, uint64_t *head_offset, + uint64_t *tail_offset, uint64_t *channel_state); +int64_t hv_ldc_rx_set_qhead(uint64_t ldc_id, uint64_t head_offset); + +#define LDC_CHANNEL_DOWN 0 +#define LDC_CHANNEL_UP 1 +#define LDC_CHANNEL_RESET 2 + +/* Used by drivers only, not part of the hypervisor API. */ +#define LDC_CHANNEL_INIT ((uint64_t)-1) + +int64_t hv_ldc_set_map_table(uint64_t ldc_id, paddr_t base_raddr, + uint64_t nentries); +int64_t hv_ldc_get_map_table(uint64_t ldc_id, paddr_t *base_raddr, + uint64_t *nentries); +int64_t hv_ldc_copy(uint64_t ldc_id, uint64_t flags, uint64_t cookie, + paddr_t raddr, psize_t length, psize_t *ret_length); + +#define LDC_COPY_IN 0 +#define LDC_COPY_OUT 1 + +int64_t hv_ldc_mapin(uint64_t ldc_id, uint64_t cookie, paddr_t *raddr, + uint64_t *perms); +int64_t hv_ldc_unmap(paddr_t raddr, uint64_t *perms); + +/* + * Static Direct I/O services + */ + +int64_t hv_pci_iov_root_configured(uint64_t devhandle); +int64_t hv_pci_real_config_get(uint64_t devhandle, uint64_t pci_device, + uint64_t pci_config_offset, uint64_t size, + uint64_t *error_flag, uint64_t *data); +int64_t hv_pci_real_config_put(uint64_t devhandle, uint64_t pci_device, + uint64_t pci_config_offset, uint64_t size, uint64_t data, + uint64_t *error_flag); +int64_t hv_pci_error_send(uint64_t devhandle, uint64_t devino, + uint64_t pci_device); + +/* + * Cryptographic services + */ + +int64_t hv_rng_get_diag_control(void); +int64_t hv_rng_ctl_read(paddr_t raddr, uint64_t *state, uint64_t *delta); +int64_t hv_rng_ctl_write(paddr_t raddr, uint64_t state, uint64_t timeout, + uint64_t *delta); + +#define RNG_STATE_UNCONFIGURED 0 +#define RNG_STATE_CONFIGURED 1 +#define RNG_STATE_HEALTHCHECK 2 +#define RNG_STATE_ERROR 3 + +int64_t hv_rng_data_read_diag(paddr_t raddr, uint64_t size, uint64_t *delta); +int64_t hv_rng_data_read(paddr_t raddr, uint64_t *delta); + +/* + * Error codes + */ + +#define H_EOK 0 +#define H_ENOCPU 1 +#define H_ENORADDR 2 +#define H_ENOINTR 3 +#define H_EBADPGSZ 4 +#define H_EBADTSB 5 +#define H_EINVAL 6 +#define H_EBADTRAP 7 +#define H_EBADALIGN 8 +#define H_EWOULDBLOCK 9 +#define H_ENOACCESS 10 +#define H_EIO 11 +#define H_ECPUERROR 12 +#define H_ENOTSUPPORTED 13 +#define H_ENOMAP 14 +#define H_ETOOMANY 15 +#define H_ECHANNEL 16 + +extern uint64_t sun4v_group_interrupt_major; +extern uint64_t sun4v_group_sdio_major; + +int64_t sun4v_intr_devino_to_sysino(uint64_t, uint64_t, uint64_t *); +int64_t sun4v_intr_setcookie(uint64_t, uint64_t, uint64_t); +int64_t sun4v_intr_setenabled(uint64_t, uint64_t, uint64_t); +int64_t sun4v_intr_setstate(uint64_t, uint64_t, uint64_t); +int64_t sun4v_intr_settarget(uint64_t, uint64_t, uint64_t); \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/idprom.h b/lib/libc/include/sparc64-openbsd-none/machine/idprom.h new file mode 100644 index 0000000000..0332fc8f2e --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/idprom.h @@ -0,0 +1,52 @@ +/* $OpenBSD: idprom.h,v 1.3 2024/03/29 21:06:14 miod Exp $ */ +/* $NetBSD: idprom.h,v 1.2 1998/09/05 23:57:26 eeh Exp $ */ + +/* + * Copyright (c) 1993 Adam Glass + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Adam Glass. + * 4. The name of the Author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Adam Glass ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * ID prom format. The ``host id'' is set up by taking the machine + * ID as the top byte and the hostid field as the remaining three. + * The id_xxx0 field appears to contain some other number. The id_xxx1 + * contains a bunch of 00's and a5's on my machines, suggesting it is + * not actually used. The checksum seems to include them, however. + */ +struct idprom { + u_char id_format; /* format identifier (= 1) */ + u_char id_machine; /* machine type (see param.h) */ + u_char id_ether[6]; /* ethernet address */ + int id_date; /* date of manufacture */ + u_char id_hostid[3]; /* ``host id'' bytes */ + u_char id_checksum; /* xor of everything else */ + char id_undef[16]; /* undefined */ +}; + +#define IDPROM_VERSION 1 \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/ieee.h b/lib/libc/include/sparc64-openbsd-none/machine/ieee.h new file mode 100644 index 0000000000..9d22c7a0de --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/ieee.h @@ -0,0 +1,148 @@ +/* $OpenBSD: ieee.h,v 1.4 2017/04/16 14:20:49 kettenis Exp $ */ +/* $NetBSD: ieee.h,v 1.1.1.1 1998/06/20 04:58:51 eeh Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)ieee.h 8.1 (Berkeley) 6/11/93 + */ + +/* + * ieee.h defines the machine-dependent layout of the machine's IEEE + * floating point. It does *not* define (yet?) any of the rounding + * mode bits, exceptions, and so forth. + */ + +/* + * Define the number of bits in each fraction and exponent. + * + * k k+1 + * Note that 1.0 x 2 == 0.1 x 2 and that denorms are represented + * + * (-exp_bias+1) + * as fractions that look like 0.fffff x 2 . This means that + * + * -126 + * the number 0.10000 x 2 , for instance, is the same as the normalized + * + * -127 -128 + * float 1.0 x 2 . Thus, to represent 2 , we need one leading zero + * + * -129 + * in the fraction; to represent 2 , we need two, and so on. This + * + * (-exp_bias-fracbits+1) + * implies that the smallest denormalized number is 2 + * + * for whichever format we are talking about: for single precision, for + * + * -126 -149 + * instance, we get .00000000000000000000001 x 2 , or 1.0 x 2 , and + * + * -149 == -127 - 23 + 1. + */ +#define SNG_EXPBITS 8 +#define SNG_FRACBITS 23 + +#define DBL_EXPBITS 11 +#define DBL_FRACHBITS 20 +#define DBL_FRACLBITS 32 +#define DBL_FRACBITS 52 + +#define EXT_EXPBITS 15 +#define EXT_FRACHBITS 16 +#define EXT_FRACHMBITS 32 +#define EXT_FRACLMBITS 32 +#define EXT_FRACLBITS 32 +#define EXT_FRACBITS 112 + +#define EXT_IMPLICIT_NBIT + +#define EXT_TO_ARRAY32(p, a) do { \ + (a)[0] = (uint32_t)(p)->ext_fracl; \ + (a)[1] = (uint32_t)(p)->ext_fraclm; \ + (a)[2] = (uint32_t)(p)->ext_frachm; \ + (a)[3] = (uint32_t)(p)->ext_frach; \ +} while(0) + +struct ieee_single { + u_int sng_sign:1; + u_int sng_exp:8; + u_int sng_frac:23; +}; + +struct ieee_double { + u_int dbl_sign:1; + u_int dbl_exp:11; + u_int dbl_frach:20; + u_int dbl_fracl; +}; + +struct ieee_ext { + u_int ext_sign:1; + u_int ext_exp:15; + u_int ext_frach:16; + u_int ext_frachm; + u_int ext_fraclm; + u_int ext_fracl; +}; + +/* + * Floats whose exponent is in [1..INFNAN) (of whatever type) are + * `normal'. Floats whose exponent is INFNAN are either Inf or NaN. + * Floats whose exponent is zero are either zero (iff all fraction + * bits are zero) or subnormal values. + * + * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its + * high fraction; if the bit is set, it is a `quiet NaN'. + */ +#define SNG_EXP_INFNAN 255 +#define DBL_EXP_INFNAN 2047 +#define EXT_EXP_INFNAN 32767 + +#if 0 +#define SNG_QUIETNAN (1 << 22) +#define DBL_QUIETNAN (1 << 19) +#define EXT_QUIETNAN (1 << 15) +#endif + +/* + * Exponent biases. + */ +#define SNG_EXP_BIAS 127 +#define DBL_EXP_BIAS 1023 +#define EXT_EXP_BIAS 16383 \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/ieeefp.h b/lib/libc/include/sparc64-openbsd-none/machine/ieeefp.h new file mode 100644 index 0000000000..0997cfae6d --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/ieeefp.h @@ -0,0 +1,24 @@ +/* $OpenBSD: ieeefp.h,v 1.3 2011/03/23 16:54:37 pirofti Exp $ */ +/* + * Written by J.T. Conklin, Apr 6, 1995 + * Public domain. + */ + +#ifndef _MACHINE_IEEEFP_H_ +#define _MACHINE_IEEEFP_H_ + +typedef int fp_except; +#define FP_X_IMP 0x01 /* imprecise (loss of precision) */ +#define FP_X_DZ 0x02 /* divide-by-zero exception */ +#define FP_X_UFL 0x04 /* underflow exception */ +#define FP_X_OFL 0x08 /* overflow exception */ +#define FP_X_INV 0x10 /* invalid operation exception */ + +typedef enum { + FP_RN=0, /* round to nearest representable number */ + FP_RZ=1, /* round to zero (truncate) */ + FP_RP=2, /* round toward positive infinity */ + FP_RM=3 /* round toward negative infinity */ +} fp_rnd; + +#endif /* _MACHINE_IEEEFP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/instr.h b/lib/libc/include/sparc64-openbsd-none/machine/instr.h new file mode 100644 index 0000000000..9054144e97 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/instr.h @@ -0,0 +1,502 @@ +/* $OpenBSD: instr.h,v 1.8 2025/07/16 07:15:42 jsg Exp $ */ +/* $NetBSD: instr.h,v 1.3 2000/01/10 03:53:20 eeh Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)instr.h 8.1 (Berkeley) 6/11/93 + */ + +/* see also Appendix F of the SPARC version 8 document */ +enum IOP { IOP_OP2, IOP_CALL, IOP_reg, IOP_mem }; +enum IOP2 { IOP2_UNIMP, IOP2_BPcc, IOP2_Bicc, IOP2_BPr, + IOP2_SETHI, IOP2_FBPfcc, IOP2_FBfcc, IOP2_CBccc }; +enum IOP3_reg { + IOP3_ADD, IOP3_AND, IOP3_OR, IOP3_XOR, + IOP3_SUB, IOP3_ANDN, IOP3_ORN, IOP3_XNOR, + IOP3_ADDX, IOP3_MULX, IOP3_UMUL, IOP3_SMUL, + IOP3_SUBX, IOP3_UDIVX, IOP3_UDIV, IOP3_SDIV, + IOP3_ADDcc, IOP3_ANDcc, IOP3_ORcc, IOP3_XORcc, + IOP3_SUBcc, IOP3_ANDNcc, IOP3_ORNcc, IOP3_XNORcc, + IOP3_ADDXcc, IOP3_rerr19, IOP3_UMULcc, IOP3_SMULcc, + IOP3_SUBXcc, IOP3_rerr1d, IOP3_UDIVcc, IOP3_SDIVcc, + IOP3_TADDcc, IOP3_TSUBcc, IOP3_TADDccTV, IOP3_TSUBccTV, + IOP3_MULScc, IOP3_SLL, IOP3_SRL, IOP3_SRA, + IOP3_RDASR_RDY_STBAR, IOP3_RDPSR, IOP3_RDWIM, IOP3_RDTGBR, + IOP3_MOVcc, IOP3_SDIVX, IOP3_POPC, IOP3_MOVr, + IOP3_WRASR_WRY, IOP3_WRPSR, IOP3_WRWIM, IOP3_WRTBR, + IOP3_FPop1, IOP3_FPop2, IOP3_CPop1, IOP3_CPop2, + IOP3_JMPL, IOP3_RETT, IOP3_Ticc, IOP3_FLUSH, + IOP3_SAVE, IOP3_RESTORE, IOP3_DONE_RETRY, IOP3_rerr3f +}; +enum IOP3_mem { + IOP3_LD, IOP3_LDUB, IOP3_LDUH, IOP3_LDD, + IOP3_ST, IOP3_STB, IOP3_STH, IOP3_STD, + IOP3_LDSW, IOP3_LDSB, IOP3_LDSH, IOP3_LDX, + IOP3_merr0c, IOP3_LDSTUB, IOP3_STX, IOP3_SWAP, + IOP3_LDA, IOP3_LDUBA, IOP3_LDUHA, IOP3_LDDA, + IOP3_STA, IOP3_STBA, IOP3_STHA, IOP3_STDA, + IOP3_LDSWA, IOP3_LDSBA, IOP3_LDSHA, IOP3_LDXA, + IOP3_merr1c, IOP3_LDSTUBA, IOP3_STXA, IOP3_SWAPA, + IOP3_LDF, IOP3_LDFSR, IOP3_LDQF, IOP3_LDDF, + IOP3_STF, IOP3_STFSR, IOP3_STQF, IOP3_STDF, + IOP3_merr28, IOP3_merr29, IOP3_merr2a, IOP3_merr2b, + IOP3_merr2c, IOP3_PREFETCH, IOP3_merr2e, IOP3_merr2f, + IOP3_LFC, IOP3_LDCSR, IOP3_LDQFA, IOP3_LDDC, + IOP3_STC, IOP3_STCSR, IOP3_STQFA, IOP3_STDC, + IOP3_merr38, IOP3_merr39, IOP3_merr3a, IOP3_merr3b, + IOP3_CASA, IOP3_PREFETCHA, IOP3_CASXA, IOP3_merr3f +}; + +/* + * Integer condition codes. + */ +#define Icc_N 0x0 /* never */ +#define Icc_E 0x1 /* equal (equiv. zero) */ +#define Icc_LE 0x2 /* less or equal */ +#define Icc_L 0x3 /* less */ +#define Icc_LEU 0x4 /* less or equal unsigned */ +#define Icc_CS 0x5 /* carry set (equiv. less unsigned) */ +#define Icc_NEG 0x6 /* negative */ +#define Icc_VS 0x7 /* overflow set */ +#define Icc_A 0x8 /* always */ +#define Icc_NE 0x9 /* not equal (equiv. not zero) */ +#define Icc_G 0xa /* greater */ +#define Icc_GE 0xb /* greater or equal */ +#define Icc_GU 0xc /* greater unsigned */ +#define Icc_CC 0xd /* carry clear (equiv. gtr or eq unsigned) */ +#define Icc_POS 0xe /* positive */ +#define Icc_VC 0xf /* overflow clear */ + +/* + * Integer registers. + */ +#define I_G0 0 +#define I_G1 1 +#define I_G2 2 +#define I_G3 3 +#define I_G4 4 +#define I_G5 5 +#define I_G6 6 +#define I_G7 7 +#define I_O0 8 +#define I_O1 9 +#define I_O2 10 +#define I_O3 11 +#define I_O4 12 +#define I_O5 13 +#define I_O6 14 +#define I_O7 15 +#define I_L0 16 +#define I_L1 17 +#define I_L2 18 +#define I_L3 19 +#define I_L4 20 +#define I_L5 21 +#define I_L6 22 +#define I_L7 23 +#define I_I0 24 +#define I_I1 25 +#define I_I2 26 +#define I_I3 27 +#define I_I4 28 +#define I_I5 29 +#define I_I6 30 +#define I_I7 31 + +/* + * An instruction. + */ +union instr { + int i_int; /* as a whole */ + + /* + * The first level of decoding is to use the top 2 bits. + * This gives us one of three `formats', which usually give + * a second level of decoding. + */ + struct { + u_int i_op:2; /* first-level decode */ + u_int :30; + } i_any; + + /* + * Format 1 instructions: CALL (undifferentiated). + */ + struct { + u_int :2; /* 01 */ + int i_disp:30; /* displacement */ + } i_call; + + /* + * Format 2 instructions (SETHI, UNIMP, and branches, plus illegal + * unused codes). + */ + struct { + u_int :2; /* 00 */ + u_int :5; + u_int i_op2:3; /* second-level decode */ + u_int :22; + } i_op2; + + /* UNIMP, SETHI */ + struct { + u_int :2; /* 00 */ + u_int i_rd:5; /* destination register */ + u_int i_op2:3; /* opcode: UNIMP or SETHI */ + u_int i_imm:22; /* immediate value */ + } i_imm22; + + /* branches: Bicc, FBfcc, CBccc */ + struct { + u_int :2; /* 00 */ + u_int i_annul:1; /* annul bit */ + u_int i_cond:4; /* condition codes */ + u_int i_op2:3; /* opcode: {Bi,FBf,CBc}cc */ + int i_disp:22; /* branch displacement */ + } i_branch; + + /* more branches: BPcc, FBPfcc */ + struct { + u_int :2; /* 00 */ + u_int i_annul:1; /* annul bit */ + u_int i_cond:4; /* condition codes */ + u_int i_op2:3; /* opcode: {BP,FBPf}cc */ + u_int i_cc:2; /* condition code selector */ + u_int i_pred:1; /* branch prediction bit */ + int i_disp:19; /* branch displacement */ + } i_branch_p; + + /* one last branch: BPr */ + struct { + u_int :2; /* 00 */ + u_int i_annul:1; /* annul bit */ + u_int :1; /* 0 */ + u_int i_rcond:4; /* register condition */ + u_int :3; /* 011 */ + int i_disphi:2; /* branch displacement, hi bits */ + u_int i_pred:1; /* branch prediction bit */ + u_int i_rs1:1; /* source register 1 */ + u_int i_displo:16; /* branch displacement, lo bits */ + } i_branch_pr; + + + /* + * Format 3 instructions (memory reference; arithmetic, logical, + * shift, and other miscellaneous operations). The second-level + * decode almost always makes use of an `rd' and `rs1', however + * (see also IOP3_reg and IOP3_mem). + * + * Beyond that, the low 14 bits may be broken up in one of three + * different ways, if at all: + * 1 bit of imm=0 + 8 bits of asi + 5 bits of rs2 [reg & mem] + * 1 bit of imm=1 + 13 bits of signed immediate [reg & mem] + * 9 bits of coprocessor `opf' opcode + 5 bits of rs2 [reg only] + */ + struct { + u_int :2; /* 10 or 11 */ + u_int i_rd:5; /* destination register */ + u_int i_op3:6; /* second-level decode */ + u_int i_rs1:5; /* source register 1 */ + u_int i_low14:14; /* varies */ + } i_op3; + + /* + * Memory forms. These set i_op=3 and use simm13 or asi layout. + * Memory references without an ASI should use 0, but the actual + * ASI field is simply ignored. + */ + struct { + u_int :2; /* 11 only */ + u_int i_rd:5; /* destination register */ + u_int i_op3:6; /* second-level decode (see IOP3_mem) */ + u_int i_rs1:5; /* source register 1 */ + u_int i_i:1; /* immediate vs asi */ + u_int i_low13:13; /* depend on i bit */ + } i_loadstore; + + /* + * Memory and register forms. + * These come in quite a variety and we do not + * attempt to break them down much. + */ + struct { + u_int :2; /* 10 or 11 */ + u_int i_rd:5; /* destination register */ + u_int i_op3:6; /* second-level decode */ + u_int i_rs1:5; /* source register 1 */ + u_int i_i:1; /* immediate bit (1) */ + int i_simm13:13; /* signed immediate */ + } i_simm13; + struct { + u_int :2; /* 10 or 11 */ + u_int i_rd:5; /* destination register */ + u_int i_op3:6; /* second-level decode */ + u_int i_rs1:5; /* source register 1 */ + u_int i_i:1; /* immediate vs asi */ + u_int i_asi:8; /* asi */ + u_int i_rs2:5; /* source register 2 */ + } i_asi; + struct { + u_int :2; /* 10 only (register, no memory) */ + u_int i_rd:5; /* destination register */ + u_int i_op3:6; /* second-level decode (see IOP3_reg) */ + u_int i_rs1:5; /* source register 1 */ + u_int i_opf:9; /* coprocessor 3rd-level decode */ + u_int i_rs2:5; /* source register 2 */ + } i_opf; + + /* + * Format 4 instructions (movcc, fmovr, fmovcc, and tcc). The + * second-level decode almost always makes use of an `rd' and either + * `rs1' or `cond'. + * + * Beyond that, the low 14 bits may be broken up in one of three + * different ways, if at all: + * 1 bit of imm=0 + 8 bits of asi + 5 bits of rs2 [reg & mem] + * 1 bit of imm=1 + 13 bits of signed immediate [reg & mem] + * 9 bits of coprocessor `opf' opcode + 5 bits of rs2 [reg only] */ + struct { + u_int :2; /* 10 */ + u_int i_rd:5; /* destination register */ + u_int i_op3:6; /* second-level decode */ + u_int i_rs1:5; /* source register 1 */ + u_int i_low14:14; /* varies */ + } i_op4; + + /* + * Move fp register on condition codes. + */ + struct { + u_int :2; /* 10 */ + u_int i_rd:5; /* destination register */ + u_int i_op3:6; /* second-level decode */ + u_int :1; + u_int i_cond:4; /* condition */ + u_int i_opf_cc:3; /* condition code register */ + u_int i_opf_low:6; /* third level decode */ + u_int i_rs2:5; /* source register */ + } i_fmovcc; + + /* + * Move fp register on integer register. + */ + struct { + u_int :2; /* 10 */ + u_int i_rd:5; /* destination register */ + u_int i_op3:6; /* second-level decode */ + u_int i_rs1:5; /* source register 1 */ + u_int :1; + u_int i_rcond:3; /* register condition */ + u_int i_opf_low:6; + u_int i_rs2:5; /* source register 2 */ + } i_fmovr; + +}; + +/* + * Internal macros for building instructions. These correspond 1-to-1 to + * the names above. Note that x << y | z == (x << y) | z. + */ +#define _I_ANY(op, b) ((op) << 30 | (b)) + +#define _I_OP2(high, op2, low) \ + _I_ANY(IOP_OP2, (high) << 25 | (op2) << 22 | (low)) +#define _I_IMM22(rd, op2, imm) \ + _I_ANY(IOP_OP2, (rd) << 25 | (op2) << 22 | (imm)) +#define _I_BRANCH(a, c, op2, disp) \ + _I_ANY(IOP_OP2, (a) << 29 | (c) << 25 | (op2) << 22 | (disp)) +#define _I_FBFCC(a, cond, disp) \ + _I_BRANCH(a, cond, IOP2_FBfcc, disp) +#define _I_CBCCC(a, cond, disp) \ + _I_BRANCH(a, cond, IOP2_CBccc, disp) + +#define _I_SIMM(simm) (1 << 13 | ((simm) & 0x1fff)) + +#define _I_OP3_GEN(form, rd, op3, rs1, low14) \ + _I_ANY(form, (rd) << 25 | (op3) << 19 | (rs1) << 14 | (low14)) +#define _I_OP3_LS_RAR(rd, op3, rs1, asi, rs2) \ + _I_OP3_GEN(IOP_mem, rd, op3, rs1, (asi) << 5 | (rs2)) +#define _I_OP3_LS_RI(rd, op3, rs1, simm13) \ + _I_OP3_GEN(IOP_mem, rd, op3, rs1, _I_SIMM(simm13)) +#define _I_OP3_LS_RR(rd, op3, rs1, rs2) \ + _I_OP3_GEN(IOP_mem, rd, op3, rs1, rs2) +#define _I_OP3_R_RAR(rd, op3, rs1, asi, rs2) \ + _I_OP3_GEN(IOP_reg, rd, op3, rs1, (asi) << 5 | (rs2)) +#define _I_OP3_R_RI(rd, op3, rs1, simm13) \ + _I_OP3_GEN(IOP_reg, rd, op3, rs1, _I_SIMM(simm13)) +#define _I_OP3_R_RR(rd, op3, rs1, rs2) \ + _I_OP3_GEN(IOP_reg, rd, op3, rs1, rs2) + +#define I_CALL(d) _I_ANY(IOP_CALL, d) +#define I_UNIMP(v) _I_IMM22(0, IOP2_UNIMP, v) +#define I_BN(a, d) _I_BRANCH(a, Icc_N, IOP2_Bicc, d) +#define I_BE(a, d) _I_BRANCH(a, Icc_E, IOP2_Bicc, d) +#define I_BZ(a, d) _I_BRANCH(a, Icc_E, IOP2_Bicc, d) +#define I_BLE(a, d) _I_BRANCH(a, Icc_LE, IOP2_Bicc, d) +#define I_BL(a, d) _I_BRANCH(a, Icc_L, IOP2_Bicc, d) +#define I_BLEU(a, d) _I_BRANCH(a, Icc_LEU, IOP2_Bicc, d) +#define I_BCS(a, d) _I_BRANCH(a, Icc_CS, IOP2_Bicc, d) +#define I_BLU(a, d) _I_BRANCH(a, Icc_CS, IOP2_Bicc, d) +#define I_BNEG(a, d) _I_BRANCH(a, Icc_NEG, IOP2_Bicc, d) +#define I_BVS(a, d) _I_BRANCH(a, Icc_VS, IOP2_Bicc, d) +#define I_BA(a, d) _I_BRANCH(a, Icc_A, IOP2_Bicc, d) +#define I_B(a, d) _I_BRANCH(a, Icc_A, IOP2_Bicc, d) +#define I_BNE(a, d) _I_BRANCH(a, Icc_NE, IOP2_Bicc, d) +#define I_BNZ(a, d) _I_BRANCH(a, Icc_NE, IOP2_Bicc, d) +#define I_BG(a, d) _I_BRANCH(a, Icc_G, IOP2_Bicc, d) +#define I_BGE(a, d) _I_BRANCH(a, Icc_GE, IOP2_Bicc, d) +#define I_BGU(a, d) _I_BRANCH(a, Icc_GU, IOP2_Bicc, d) +#define I_BCC(a, d) _I_BRANCH(a, Icc_CC, IOP2_Bicc, d) +#define I_BGEU(a, d) _I_BRANCH(a, Icc_CC, IOP2_Bicc, d) +#define I_BPOS(a, d) _I_BRANCH(a, Icc_POS, IOP2_Bicc, d) +#define I_BVC(a, d) _I_BRANCH(a, Icc_VC, IOP2_Bicc, d) +#define I_SETHI(r, v) _I_IMM22(r, 4, v) + +#define I_ORri(rd, rs1, imm) _I_OP3_R_RI(rd, IOP3_OR, rs1, imm) +#define I_ORrr(rd, rs1, rs2) _I_OP3_R_RR(rd, IOP3_OR, rs1, rs2) + +#define I_MOVi(rd, imm) _I_OP3_R_RI(rd, IOP3_OR, I_G0, imm) +#define I_MOVr(rd, rs) _I_OP3_R_RR(rd, IOP3_OR, I_G0, rs) + +#define I_RDPSR(rd) _I_OP3_R_RR(rd, IOP3_RDPSR, 0, 0) + +#define I_JMPLri(rd, rs1, imm) _I_OP3_R_RI(rd, IOP3_JMPL, rs1, imm) +#define I_JMPLrr(rd, rs1, rs2) _I_OP3_R_RR(rd, IOP3_JMPL, rs1, rs2) + +/* + * FPop values. + */ + +/* These are in FPop1 space */ +#define FMOVS 0x001 +#define FMOVD 0x002 +#define FMOVQ 0x003 +#define FNEGS 0x005 +#define FNEGD 0x006 +#define FNEGQ 0x007 +#define FABSS 0x009 +#define FABSD 0x00a +#define FABSQ 0x00b +#define FSQRTS 0x029 +#define FSQRTD 0x02a +#define FSQRTQ 0x02b +#define FADDS 0x041 +#define FADDD 0x042 +#define FADDQ 0x043 +#define FSUBS 0x045 +#define FSUBD 0x046 +#define FSUBQ 0x047 +#define FMULS 0x049 +#define FMULD 0x04a +#define FMULQ 0x04b +#define FDIVS 0x04d +#define FDIVD 0x04e +#define FDIVQ 0x04f +#define FSMULD 0x069 +#define FDMULQ 0x06e +#define FSTOX 0x081 +#define FDTOX 0x082 +#define FQTOX 0x083 +#define FXTOS 0x084 +#define FXTOD 0x088 +#define FXTOQ 0x08c +#define FITOS 0x0c4 +#define FDTOS 0x0c6 +#define FQTOS 0x0c7 +#define FITOD 0x0c8 +#define FSTOD 0x0c9 +#define FQTOD 0x0cb +#define FITOQ 0x0cc +#define FSTOQ 0x0cd +#define FDTOQ 0x0ce +#define FSTOI 0x0d1 +#define FDTOI 0x0d2 +#define FQTOI 0x0d3 + +/* These are in FPop2 space */ +#define FMVFC0S 0x001 +#define FMVFC0D 0x002 +#define FMVFC0Q 0x003 +#define FMOVZS 0x025 +#define FMOVZD 0x026 +#define FMOVZQ 0x027 +#define FMVFC1S 0x041 +#define FMVFC1D 0x042 +#define FMVFC1Q 0x043 +#define FMOVLEZS 0x045 +#define FMOVLEZD 0x046 +#define FMOVLEZQ 0x047 +#define FCMPS 0x051 +#define FCMPD 0x052 +#define FCMPQ 0x053 +#define FCMPES 0x055 +#define FCMPED 0x056 +#define FCMPEQ 0x057 +#define FMOVLZS 0x065 +#define FMOVLZD 0x066 +#define FMOVLZQ 0x067 +#define FMVFC2S 0x081 +#define FMVFC2D 0x082 +#define FMVFC2Q 0x083 +#define FMOVNZS 0x0a5 +#define FMOVNZD 0x0a6 +#define FMOVNZQ 0x0a7 +#define FMVFC3S 0x0c1 +#define FMVFC3D 0x0c2 +#define FMVFC3Q 0x0c3 +#define FMOVGZS 0x0c5 +#define FMOVGZD 0x0c6 +#define FMOVGZQ 0x0c7 +#define FMOVGEZS 0x0e5 +#define FMOVGEZD 0x0e6 +#define FMOVGEZQ 0x0e7 +#define FMVICS 0x101 +#define FMVICD 0x102 +#define FMVICQ 0x103 +#define FMVXCS 0x181 +#define FMVXCD 0x182 +#define FMVXCQ 0x183 + +/* + * FPU data types. + */ +#define FTYPE_LNG -1 /* data = 64-bit signed long integer */ +#define FTYPE_INT 0 /* data = 32-bit signed integer */ +#define FTYPE_SNG 1 /* data = 32-bit float */ +#define FTYPE_DBL 2 /* data = 64-bit double */ +#define FTYPE_EXT 3 /* data = 128-bit extended (quad-prec) */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/intr.h b/lib/libc/include/sparc64-openbsd-none/machine/intr.h new file mode 100644 index 0000000000..6e35396569 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/intr.h @@ -0,0 +1,119 @@ +/* $OpenBSD: intr.h,v 1.26 2025/05/11 19:41:05 miod Exp $ */ +/* $NetBSD: intr.h,v 1.8 2001/01/14 23:50:30 thorpej Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Paul Kranenburg. + * + * 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_INTR_H_ +#define _MACHINE_INTR_H_ + +#include + +#include + +/* + * Interrupt handler chains. Interrupt handlers should return 0 for + * ``not me'' or 1 (``I took care of it''). intr_establish() inserts a + * handler into the list. The handler is called with its (single) + * argument, or with a pointer to a clockframe if ih_arg is NULL. + */ +struct intrhand { + int (*ih_fun)(void *); + void *ih_arg; + short ih_number; /* interrupt number */ + /* the H/W provides */ + char ih_pil; /* interrupt priority */ + char ih_mpsafe; + struct intrhand *ih_next; /* global list */ + struct intrhand *ih_pending; /* pending list */ + volatile u_int64_t *ih_map; /* interrupt map reg */ + volatile u_int64_t *ih_clr; /* clear interrupt reg */ + void (*ih_ack)(struct intrhand *); + struct evcount ih_count; /* # of interrupts */ + const void *ih_bus; /* parent bus */ + struct cpu_info *ih_cpu; /* target */ + char ih_name[32]; /* device name */ +}; + +extern struct intrhand *intrlev[MAXINTNUM]; + +void intr_establish(struct intrhand *); + +/* XXX - arbitrary numbers; no interpretation is defined yet */ +#define IPL_NONE 0 /* nothing */ +#define IPL_SOFTINT 1 /* softint */ +#define IPL_SOFTCLOCK 1 /* timeouts */ +#define IPL_SOFTNET 2 /* protocol stack */ +#define IPL_BIO PIL_BIO /* block I/O */ +#define IPL_NET PIL_NET /* network */ +#define IPL_SOFTTTY 4 /* delayed terminal handling */ +#define IPL_TTY PIL_TTY /* terminal */ +#define IPL_VM PIL_VM /* memory allocation */ +#define IPL_AUDIO PIL_AUD /* audio */ +#define IPL_CLOCK PIL_CLOCK /* clock */ +#define IPL_SERIAL PIL_SER /* serial */ +#define IPL_SCHED PIL_SCHED /* scheduler */ +#define IPL_STATCLOCK PIL_STATCLOCK /* statclock */ +#define IPL_HIGH PIL_HIGH /* everything */ + +#define spl0() _spl(IPL_NONE) +#define splsoftclock() _splraise(IPL_SOFTCLOCK) +#define splsoftnet() _splraise(IPL_SOFTNET) +#define splbio() _splraise(IPL_BIO) +#define splnet() _splraise(IPL_NET) +#define splsofttty() _splraise(IPL_SOFTTTY) +#define spltty() _splraise(IPL_TTY) +#define splvm() _splraise(IPL_VM) +#define splaudio() _splraise(IPL_AUDIO) +#define splclock() _splraise(IPL_CLOCK) +#define splserial() _splraise(IPL_SERIAL) +#define splsched() _splraise(IPL_SCHED) +#define splstatclock() _splraise(IPL_STATCLOCK) +#define splhigh() _splraise(IPL_HIGH) +#define splx(_oldipl) _splx(_oldipl) + +#define splzs() splserial() + +#define IPL_MPFLOOR IPL_SERIAL +#define IPL_MPSAFE 0x100 + +int splraise(int); +void intr_barrier(void *); + +void *softintr_establish(int, void (*)(void *), void *); +void softintr_disestablish(void *); +void softintr_schedule(void *); + +void *softintr_establish_raw(int, void (*)(void *), void *); +#define softintr_disestablish_raw(ih) softintr_disestablish(ih) +#define softintr_schedule_raw(ih) softintr_schedule(ih) + +void send_softint(int, struct intrhand *); + +#endif /* _MACHINE_INTR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/ioctl_fd.h b/lib/libc/include/sparc64-openbsd-none/machine/ioctl_fd.h new file mode 100644 index 0000000000..e7fcb85fe9 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/ioctl_fd.h @@ -0,0 +1,130 @@ +/* $OpenBSD: ioctl_fd.h,v 1.2 2011/03/23 16:54:37 pirofti Exp $ */ +/* from: ioctl_fd.h,v 1.4 1995/06/29 03:49:32 jtk Exp */ + +/* + * Copyright (C) 1992-1994 by Joerg Wunsch, Dresden + * 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(S) ``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(S) 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: Id: ioctl_fd.h,v 1.7 1994/10/30 19:17:39 joerg Exp + */ + +#ifndef _MACHINE_IOCTL_FD_H_ +#define _MACHINE_IOCTL_FD_H_ + +#define FD_FORMAT_VERSION 110 /* used to validate before formatting */ +#define FD_MAX_NSEC 36 /* highest known number of spt - allow for */ + /* 2.88 MB drives */ + +struct fd_formb { + int format_version; /* == FD_FORMAT_VERSION */ + int cyl, head; + int transfer_rate; /* fdreg.h: FDC_???KBPS */ + + union { + struct fd_form_data { + /* + * DO NOT CHANGE THE LAYOUT OF THIS STRUCTS + * it is hardware-dependant since it exactly + * matches the byte sequence to write to FDC + * during its `format track' operation + */ + u_char secshift; /* 0 -> 128, ...; usually 2 -> 512 */ + u_char nsecs; /* must be <= FD_MAX_NSEC */ + u_char gaplen; /* GAP 3 length; usually 84 */ + u_char fillbyte; /* usually 0xf6 */ + struct fd_idfield_data { + /* + * data to write into id fields; + * for obscure formats, they mustn't match + * the real values (but mostly do) + */ + u_char cylno; /* 0 thru 79 (or 39) */ + u_char headno; /* 0, or 1 */ + u_char secno; /* starting at 1! */ + u_char secsize; /* usually 2 */ + } idfields[FD_MAX_NSEC]; /* 0 <= idx < nsecs used */ + } structured; + u_char raw[1]; /* to have continuous indexed access */ + } format_info; +}; + +/* make life easier */ +# define fd_formb_secshift format_info.structured.secshift +# define fd_formb_nsecs format_info.structured.nsecs +# define fd_formb_gaplen format_info.structured.gaplen +# define fd_formb_fillbyte format_info.structured.fillbyte +/* these data must be filled in for(i = 0; i < fd_formb_nsecs; i++) */ +# define fd_formb_cylno(i) format_info.structured.idfields[i].cylno +# define fd_formb_headno(i) format_info.structured.idfields[i].headno +# define fd_formb_secno(i) format_info.structured.idfields[i].secno +# define fd_formb_secsize(i) format_info.structured.idfields[i].secsize + +/* + * Floppies come in various flavors, e.g., 1.2MB vs 1.44MB; here is how + * we tell them apart. + */ +struct fd_type { + int sectrac; /* sectors per track */ + int heads; /* number of heads */ + int seccyl; /* sectors per cylinder */ + int secsize; /* size code for sectors */ + int datalen; /* data len when secsize = 0 */ + int steprate; /* step rate and head unload time */ + int gap1; /* gap len between sectors */ + int gap2; /* formatting gap */ + int tracks; /* total num of tracks */ + int size; /* size of disk in sectors */ + int step; /* steps per cylinder */ + int rate; /* transfer speed code */ + char *name; +}; + + +#define FD_FORM _IOW('F', 61, struct fd_formb) /* format a track */ +#define FD_GTYPE _IOR('F', 62, struct fd_type) /* get drive type */ +#define FD_STYPE _IOW('F', 63, struct fd_type) /* set drive type */ + +#define FD_GOPTS _IOR('F', 64, int) /* drive options, see below */ +#define FD_SOPTS _IOW('F', 65, int) + +#define FDOPT_NORETRY 0x0001 /* no retries on failure (cleared on close) */ +#define FDOPT_SILENT 0x0002 + +/* + * The following definitions duplicate those in sys/i386/isa/fdreg.h + * They are here since their values are to be used in the above + * structure when formatting a floppy. For very obvious reasons, both + * definitions must match ;-) + */ +#ifndef FDC_500KBPS +#define FDC_500KBPS 0x00 /* 500KBPS MFM drive transfer rate */ +#define FDC_300KBPS 0x01 /* 300KBPS MFM drive transfer rate */ +#define FDC_250KBPS 0x02 /* 250KBPS MFM drive transfer rate */ +#define FDC_125KBPS 0x03 /* 125KBPS FM drive transfer rate */ + /* for some controllers 1MPBS instead */ +#endif /* FDC_500KBPS */ + + +#endif /* !_MACHINE_IOCTL_FD_H__ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/kcore.h b/lib/libc/include/sparc64-openbsd-none/machine/kcore.h new file mode 100644 index 0000000000..6c89a84b0c --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/kcore.h @@ -0,0 +1,61 @@ +/* $OpenBSD: kcore.h,v 1.3 2008/06/26 05:42:13 ray Exp $ */ +/* $NetBSD: kcore.h,v 1.4 2000/08/01 00:40:26 eeh Exp $ */ + +/*- + * Copyright (c) 1996 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Paul Kranenburg. + * + * 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. + */ + +/* + * The layout of a kernel core on the dump device is as follows: + * a `struct kcore_seg' of type CORE_CPU + * a `struct cpu_kcore_hdr' + */ + +typedef struct cpu_kcore_hdr { + int cputype; /* CPU type associated with this dump */ + + int nmemseg; /* # of physical memory segments */ + uint64_t memsegoffset; /* start of memseg array (relative */ + /* to the start of this header) */ + + int nsegmap; /* # of kernel segs */ + uint64_t segmapoffset; /* start of segmap array (relative */ + /* to the start of this header) */ + + uint64_t kernbase; /* copy of KERNBASE goes here */ + uint64_t cpubase; /* Pointer to cpu_info structure */ + + uint64_t ktextbase; /* Virtual start of text segment */ + uint64_t ktextp; /* Physical address of 4MB locked TLB */ + uint64_t ktextsz; /* Size of locked kernel text segment. */ + + uint64_t kdatabase; /* Virtual start of data segment */ + uint64_t kdatap; /* Physical address of 4MB locked TLB */ + uint64_t kdatasz; /* Size of locked kernel data segment. */ + +} cpu_kcore_hdr_t; \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/limits.h b/lib/libc/include/sparc64-openbsd-none/machine/limits.h new file mode 100644 index 0000000000..9060a2e178 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/limits.h @@ -0,0 +1,55 @@ +/* $OpenBSD: limits.h,v 1.11 2015/04/30 13:42:08 millert Exp $ */ +/* $NetBSD: limits.h,v 1.8 2000/08/08 22:31:14 tshiozak 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. + * + * @(#)limits.h 8.3 (Berkeley) 1/4/94 + */ + +#ifndef _MACHINE_LIMITS_H_ +#define _MACHINE_LIMITS_H_ + +#include + +#if __POSIX_VISIBLE || __XPG_VISIBLE +#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) */ + +/* GCC requires that quad constants be written as expressions. */ +#define UQUAD_MAX ((u_quad_t)0-1) /* max value for a uquad_t */ + /* max value for a quad_t */ +#define QUAD_MAX ((quad_t)(UQUAD_MAX >> 1)) +#define QUAD_MIN (-QUAD_MAX-1) /* min value for a quad_t */ + +#endif /* __BSD_VISIBLE */ + +#endif /* _MACHINE_LIMITS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/loadfile_machdep.h b/lib/libc/include/sparc64-openbsd-none/machine/loadfile_machdep.h new file mode 100644 index 0000000000..9902239fb2 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/loadfile_machdep.h @@ -0,0 +1,65 @@ +/* $OpenBSD: loadfile_machdep.h,v 1.3 2013/10/17 11:54:02 miod Exp $ */ +/* $NetBSD: loadfile_machdep.h,v 1.3 2000/08/16 08:16:58 mrg Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * 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. + */ + +#define BOOT_ELF +#ifdef __sparc_v9__ +#define ELFSIZE 64 +#else +#define ELFSIZE 32 +#endif + +#define LOAD_KERNEL LOAD_ALL +#define COUNT_KERNEL COUNT_ALL + +#ifdef _STANDALONE +#define LOADADDR(a) (((u_long)(a) & 0x0fffffff) + offset) +#define ALIGNENTRY(a) ((u_long)(a)) +#define READ(f, b, c) read((f), (void *)LOADADDR(b), (c)) +#define BCOPY(s, d, c) memcpy((void *)LOADADDR(d), (void *)(s), (c)) +#define BZERO(d, c) memset((void *)LOADADDR(d), 0, (c)) +#define WARN(a) (void)(printf a, \ + printf((errno ? ": %s\n" : "\n"), \ + strerror(errno))) +#define PROGRESS(a) (void) printf a +#define ALLOC(a) alloc(a) +#define FREE(a, b) free(a, b) +#else +#define LOADADDR(a) (((u_long)(a)) + offset) +#define ALIGNENTRY(a) ((u_long)(a)) +#define READ(f, b, c) read((f), (void *)LOADADDR(b), (c)) +#define BCOPY(s, d, c) memcpy((void *)LOADADDR(d), (void *)(s), (c)) +#define BZERO(d, c) memset((void *)LOADADDR(d), 0, (c)) +#define WARN(a) warn a +#define PROGRESS(a) /* nothing */ +#define ALLOC(a) malloc(a) +#define FREE(a, b) free(a) +#endif \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/mdesc.h b/lib/libc/include/sparc64-openbsd-none/machine/mdesc.h new file mode 100644 index 0000000000..bffc347b6a --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/mdesc.h @@ -0,0 +1,55 @@ +/* $OpenBSD: mdesc.h,v 1.4 2019/10/20 16:27:19 kettenis Exp $ */ +/* + * Copyright (c) 2009 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +struct md_header { + uint32_t transport_version; + uint32_t node_blk_sz; + uint32_t name_blk_sz; + uint32_t data_blk_sz; +}; + +struct md_element { + uint8_t tag; + uint8_t name_len; + uint16_t _reserved_field; + uint32_t name_offset; + union { + struct { + uint32_t data_len; + uint32_t data_offset; + } y; + uint64_t val; + } d; +}; + +#ifdef _KERNEL + +extern caddr_t mdesc; +extern size_t mdesc_len; + +extern caddr_t pri; +extern size_t pri_len; + +void mdesc_init(void); +uint64_t mdesc_get_prop_val(int, const char *); +const char *mdesc_get_prop_str(int, const char *); +const char *mdesc_get_prop_data(int, const char *, size_t *); +int mdesc_find(const char *, uint64_t); +int mdesc_find_child(int, const char *, uint64_t); +int mdesc_find_node(const char *); + +#endif \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/mutex.h b/lib/libc/include/sparc64-openbsd-none/machine/mutex.h new file mode 100644 index 0000000000..b9368872da --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/mutex.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mutex.h,v 1.8 2018/02/19 09:18:50 mpi Exp $ */ + +#define __USE_MI_MUTEX \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/openfirm.h b/lib/libc/include/sparc64-openbsd-none/machine/openfirm.h new file mode 100644 index 0000000000..aadcaf0a9a --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/openfirm.h @@ -0,0 +1,65 @@ +/* $OpenBSD: openfirm.h,v 1.7 2024/11/08 12:48:00 miod Exp $ */ +/* $NetBSD: openfirm.h,v 1.8 2001/07/20 00:07:14 eeh Exp $ */ + +/* + * Copyright (C) 1995, 1996 Wolfgang Solfrank. + * Copyright (C) 1995, 1996 TooLs GmbH. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by TooLs GmbH. + * 4. The name of TooLs GmbH may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* + * Prototypes for additional OpenFirmware Interface Routines + */ + +#include + +/* All cells are 8 byte slots */ +typedef u_int64_t cell_t; +#define HDL2CELL(x) (cell_t)(u_int)(int)(x) +#define ADR2CELL(x) (cell_t)(x) + +#define HDQ2CELL_HI(x) (cell_t)(0) +#define HDQ2CELL_LO(x) (cell_t)(x) + +#define CELL2HDQ(hi, lo) (lo) + +int OF_test(char *service); +int OF_test_method(int handle, char *method); + +int OF_stdin(void); +int OF_stdout(void); +void OF_set_symbol_lookup(void (*s2v)(void *), void (*v2s)(void *)); +void OF_poweroff(void); +void OF_sym2val(void *); +void OF_val2sym(void *); +int OF_milliseconds(void); +int OF_searchprop(int node, char *prop, void *buf, int buflen); +int OF_mapintr(int node, int *interrupt, int validlen, int buflen); +int OF_instance_to_path(int ihandle, char *buf, int buflen); +int OF_package_to_path(int phandle, char *buf, int buflen); + +void (*OF_set_callback(void (*)(void *)))(void *); \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/openpromio.h b/lib/libc/include/sparc64-openbsd-none/machine/openpromio.h new file mode 100644 index 0000000000..c301d356b6 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/openpromio.h @@ -0,0 +1,57 @@ +/* $OpenBSD: openpromio.h,v 1.3 2003/06/02 23:27:56 millert Exp $ */ +/* $NetBSD: openpromio.h,v 1.1.1.1 1998/06/20 04:58:52 eeh Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)openpromio.h 8.1 (Berkeley) 6/11/93 + */ + +struct opiocdesc { + int op_nodeid; /* passed or returned node id */ + int op_namelen; /* length of op_name */ + char *op_name; /* pointer to field name */ + int op_buflen; /* length of op_buf (value-result) */ + char *op_buf; /* pointer to field value */ +}; + +#define OPIOCGET _IOWR('O', 1, struct opiocdesc) /* get openprom field */ +#define OPIOCSET _IOW('O', 2, struct opiocdesc) /* set openprom field */ +#define OPIOCNEXTPROP _IOWR('O', 3, struct opiocdesc) /* get next property */ +#define OPIOCGETOPTNODE _IOR('O', 4, int) /* get openprom field */ +#define OPIOCGETNEXT _IOWR('O', 5, int) /* get next node of node */ +#define OPIOCGETCHILD _IOWR('O', 6, int) /* get first child of node */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/param.h b/lib/libc/include/sparc64-openbsd-none/machine/param.h new file mode 100644 index 0000000000..c3d5e1fd20 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/param.h @@ -0,0 +1,183 @@ +/* $OpenBSD: param.h,v 1.42 2023/12/14 13:26:49 claudio Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + */ + +/* + * Copyright (c) 1996-1999 Eduardo Horvath + * + * 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. + * + * 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_PARAM_H_ +#define _MACHINE_PARAM_H_ + +#define _MACHINE sparc64 +#define MACHINE "sparc64" +#define _MACHINE_ARCH sparc64 +#define MACHINE_ARCH "sparc64" +#define MID_MACHINE MID_SPARC64 + +#define PAGE_SHIFT 13 +#define PAGE_SIZE (1 << PAGE_SHIFT) +#define PAGE_MASK (PAGE_SIZE - 1) + +/* + * Here are all the magic kernel virtual addresses and how they're allocated. + * + * First, the PROM is usually a fixed-sized block from 0x00000000f0000000 to + * 0x00000000f0100000. It also uses some space around 0x00000000fff00000 to + * map in device registers. The rest is pretty much ours to play with. + * + * The kernel starts at KERNBASE. Here's the layout. We use macros to set + * the addresses so we can relocate everything easily. We use 4MB locked TTEs + * to map in the kernel text and data segments. Any extra pages are recycled, + * so they can potentially be double-mapped. This shouldn't really be a + * problem since they're unused, but wild pointers can cause silent data + * corruption if they are in those segments. + * + * 0x0000000000000000: 64K NFO page zero + * 0x0000000000010000: Userland or PROM + * KERNBASE: 4MB kernel text and read only data + * This is mapped in the ITLB and + * Read-Only in the DTLB + * KERNBASE+0x400000: 4MB kernel data and BSS -- not in ITLB + * Contains context table, kernel pmap, + * and other important structures. + * KERNBASE+0x800000: Unmapped page -- redzone + * KERNBASE+0x802000: Process 0 stack and u-area + * KERNBASE+0x806000: 2 pages for pmap_copy_page and /dev/mem + * KERNBASE+0x80a000: Start of kernel VA segment + * KERNEND: End of kernel VA segment + * KERNEND+0x02000: Auxreg_va (unused?) + * KERNEND+0x04000: TMPMAP_VA (unused?) + * KERNEND+0x06000: message buffer. + * KERNEND+0x010000: 64K locked TTE -- different for each CPU + * Contains interrupt stack, cpu_info structure, + * and 32KB kernel TSB. + * + */ +#define KERNBASE 0x001000000 /* start of kernel virtual space */ + +#ifdef _KERNEL + +#define KERNEND 0x0e0000000 /* end of kernel virtual space */ + +#define _MAXNBPG 8192 /* fixed VAs, independent of actual NBPG */ + +#define AUXREG_VA ( KERNEND + _MAXNBPG) /* 1 page REDZONE */ +#define TMPMAP_VA ( AUXREG_VA + _MAXNBPG) +#define MSGBUF_VA ( TMPMAP_VA + _MAXNBPG) +/* + * Here's the location of the interrupt stack and CPU structure. + */ +#define INTSTACK ( KERNEND + 8*_MAXNBPG)/* 64K after kernel end */ +#define EINTSTACK ( INTSTACK + 2*USPACE) /* 32KB */ +#define CPUINFO_VA ( EINTSTACK) + +#define NBPG PAGE_SIZE /* bytes/page */ +#define PGSHIFT PAGE_SHIFT /* LOG2(PAGE_SIZE) */ +#define PGOFSET PAGE_MASK /* byte offset into page */ + +#define UPAGES 2 /* 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 (1 * PAGE_SIZE) +#endif + +#ifndef _LOCORE + +extern void delay(unsigned int); +#define DELAY(n) delay(n) + +extern int cputyp; + +#if defined (SUN4US) || defined (SUN4V) +#define CPU_ISSUN4U (cputyp == CPU_SUN4U) +#define CPU_ISSUN4US (cputyp == CPU_SUN4US) +#define CPU_ISSUN4V (cputyp == CPU_SUN4V) +#else +#define CPU_ISSUN4U (1) +#define CPU_ISSUN4US (0) +#define CPU_ISSUN4V (0) +#endif + +#endif /* _LOCORE */ + +/* + * Values for the cputyp variable. + */ +#define CPU_SUN4 0 +#define CPU_SUN4C 1 +#define CPU_SUN4M 2 +#define CPU_SUN4U 3 +#define CPU_SUN4US 4 +#define CPU_SUN4V 5 + +/* + * On a sun4u machine, the page size is 8192. + */ + +#ifndef _LOCORE +#include +#endif + +#endif /* _KERNEL */ + +#endif /* _MACHINE_PARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/pcb.h b/lib/libc/include/sparc64-openbsd-none/machine/pcb.h new file mode 100644 index 0000000000..c98a66a72e --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/pcb.h @@ -0,0 +1,152 @@ +/* $OpenBSD: pcb.h,v 1.11 2022/10/21 18:55:42 miod Exp $ */ +/* $NetBSD: pcb.h,v 1.7 2000/12/29 17:12:05 eeh Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)pcb.h 8.1 (Berkeley) 6/11/93 + */ + +#ifndef _MACHINE_PCB_H_ +#define _MACHINE_PCB_H_ + +#include + +#ifdef notyet +#define PCB_MAXWIN 32 /* architectural limit */ +#else +#define PCB_MAXWIN 8 /* worried about u area sizes ... */ +#endif + +/* + * SPARC Process Control Block. + * + * pcb_uw is positive if there are any user windows that are + * are currently in the CPU windows rather than on the user + * stack. Whenever we are running in the kernel with traps + * enabled, we decrement pcb_uw for each ``push'' of a CPU + * register window into the stack, and we increment it for + * each ``pull'' from the stack into the CPU. (If traps are + * disabled, or if we are in user mode, pcb_uw is junk.) + * + * To ease computing pcb_uw on traps from user mode, we keep track + * of the log base 2 of the single bit that is set in %wim. + * + * If an overflow occurs while the associated user stack pages + * are invalid (paged out), we have to store the registers + * in a page that is locked in core while the process runs, + * i.e., right here in the pcb. We also need the stack pointer + * for the last such window (but only the last, as the others + * are in each window) and the count of windows saved. We + * cheat by having a whole window structure for that one %sp. + * Thus, to save window pcb_rw[i] to memory, we write it at + * pcb_rw[i + 1].rw_in[6]. + * + * pcb_nsaved has three `kinds' of values. If 0, it means no + * registers are in the PCB (though if pcb_uw is positive, + * there may be the next time you look). If positive, it means + * there are no user registers in the CPU, but there are some + * saved in pcb_rw[]. As a special case, traps that needed + * assistance to pull user registers from the stack also store + * the registers in pcb_rw[], and set pcb_nsaved to -1. This + * special state is normally short-term: it can only last until the + * trap returns, and it can never persist across entry to user code. + */ +/* + * v9 addendum: + * + * Window handling between v8 and v9 has changed somewhat. There + * is no %wim. Instead, we have a %cwp, %cansave, %canrestore, + * %cleanwin, and %otherwin. By definition: + * + * %cansave + %canrestore + %otherwin = NWINDOWS - 2 + * + * In addition, %cleanwin >= %canrestore since restorable windows + * are considered clean. This means that by storing %canrestore + * and %otherwin, we should be able to compute the values of all + * the other registers. + * + * The only other register we need to save is %cwp because it cannot + * be trivially computed from the other registers. The %cwp is + * stored in the %tstate register, but if the machine was in a register + * window spill/fill handler, the value of that %cwp may be off by + * as much as 2 register windows. We will also store %cwp. [We will + * try to steal pcb_uw or pcb_nsaved for this purpose eventually.] + * + * To calculate what registers are in the pcb, start with pcb_cwp + * and proceed to (pcb_cwp - pcb_canrestore) % NWINDOWS. These should + * be saved to their appropriate register windows. The client routine + * (trap handler) is responsible for saving pcb_cwp + 1 [%o1-%o7] in + * the trap frame or on the stack. + * + * + * Even more addendum: + * + * With the new system for keeping track of register windows we don't + * care about anything other than pcb_uw which keeps track of how many + * full windows we have. As soon as a flush traps, we dump all user + * windows to the pcb, handle the fault, then restore all user windows. + * + * XXX we are using pcb_nsaved as the counter. pcb_uw is still a mask. + * change this as soon as the new scheme is debugged. + */ +struct pcb { + u_int64_t pcb_sp; /* sp (%o6) when switch() was called */ + u_int64_t pcb_pc; /* pc (%o7) when switch() was called */ + caddr_t pcb_onfault; /* for copyin/out */ + short pcb_pstate; /* %pstate when switch() was called -- may be useful if we support multiple memory models */ + char pcb_nsaved; /* number of windows saved in pcb */ + + /* The rest is probably not needed except for pcb_rw */ + char pcb_cwp; /* %cwp when switch() was called */ + char pcb_pil; /* %pil when switch() was called -- probably not needed */ + + const char *lastcall; /* DEBUG -- name of last system call */ + u_int64_t pcb_wcookie; + + /* the following MUST be aligned on a 64-bit boundary */ + struct rwindow pcb_rw[PCB_MAXWIN]; /* saved windows */ + u_int64_t pcb_rwsp[PCB_MAXWIN]; +}; + +#ifndef _KERNEL +/* Let gdb compile. We need fancier macros to make these make sense. */ +#define pcb_psr pcb_pstate +#define pcb_wim pcb_cwp +#endif /* _KERNEL */ + +#endif /* _MACHINE_PCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/pci_machdep.h b/lib/libc/include/sparc64-openbsd-none/machine/pci_machdep.h new file mode 100644 index 0000000000..f42a581bd4 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/pci_machdep.h @@ -0,0 +1,137 @@ +/* $OpenBSD: pci_machdep.h,v 1.38 2020/06/23 01:21:29 jmatthew Exp $ */ +/* $NetBSD: pci_machdep.h,v 1.7 2001/07/20 00:07:14 eeh Exp $ */ + +/* + * Copyright (c) 1999 Matthew R. Green + * 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_PCI_MACHDEP_H_ +#define _MACHINE_PCI_MACHDEP_H_ + +/* + * Forward declarations. + */ +struct pci_attach_args; + +/* + * define some bits used to glue into the common PCI code. + */ + +#define __HAVE_PCI_MSIX + +typedef struct sparc_pci_chipset *pci_chipset_tag_t; + +#define PCI_INTR_INTX 0x00000000 +#define PCI_INTR_MSI 0x80000000 +#define PCI_INTR_MSIX 0x40000000 +#define PCI_INTR_TYPE_MASK 0xc0000000 +#define PCI_INTR_TYPE(_ih) ((_ih) & PCI_INTR_TYPE_MASK) + +#define PCI_INTR_TAG_MASK 0x00ffff00 +#define PCI_INTR_TAG(_ih) ((_ih) & PCI_INTR_TAG_MASK) + +#define PCI_INTR_VEC_MASK 0x000000ff +#define PCI_INTR_VEC(_ih) ((_ih) & PCI_INTR_VEC_MASK) +typedef u_int pci_intr_handle_t; + +/* + * The stuuuuuuupid allegedly MI PCI code expects pcitag_t to be a + * scalar type. But we really need to store both the OFW node and + * the bus/device/function info in it. (We'd like to store more, + * like all the ofw properties, but we don't need to.) Luckily, + * both are 32-bit values, so we can squeeze them into a u_int64_t + * with a little help from some macros. + */ + +#define PCITAG_NODE(x) (int)(((x)>>32)&0xffffffff) +#define PCITAG_OFFSET(x) ((x)&0xffffffff) +#define PCITAG_BUS(t) ((PCITAG_OFFSET(t)>>16)&0xff) +#define PCITAG_DEV(t) ((PCITAG_OFFSET(t)>>11)&0x1f) +#define PCITAG_FUN(t) ((PCITAG_OFFSET(t)>>8)&0x7) +#define PCITAG_CREATE(n,b,d,f) (((u_int64_t)(n)<<32)|((b)<<16)|((d)<<11)|((f)<<8)) +#define PCITAG_SETNODE(t,n) ((t)&0xffffffff)|(((n)<<32) +typedef u_int64_t pcitag_t; + +struct sparc_pci_chipset { + void *cookie; + bus_space_tag_t bustag; + bus_space_handle_t bushandle; + int rootnode; /* PCI controller */ + int busnode[256]; + int (*conf_size)(pci_chipset_tag_t, pcitag_t); + pcireg_t (*conf_read)(pci_chipset_tag_t, pcitag_t, int); + void (*conf_write)(pci_chipset_tag_t, pcitag_t, int, pcireg_t); + int (*intr_map)(struct pci_attach_args *, pci_intr_handle_t *); + int (*probe_device_hook)(void *, struct pci_attach_args *); +}; + +void pci_attach_hook(struct device *, struct device *, + struct pcibus_attach_args *); +int pci_probe_device_hook(pci_chipset_tag_t, + struct pci_attach_args *); +int pci_bus_maxdevs(pci_chipset_tag_t, int); +pcitag_t pci_make_tag(pci_chipset_tag_t, int, int, int); +void pci_decompose_tag(pci_chipset_tag_t, pcitag_t, int *, int *, + int *); +int pci_conf_size(pci_chipset_tag_t, pcitag_t); +pcireg_t pci_conf_read(pci_chipset_tag_t, pcitag_t, int); +void pci_conf_write(pci_chipset_tag_t, pcitag_t, int, + pcireg_t); +int pci_intr_map(struct pci_attach_args *, pci_intr_handle_t *); +int pci_intr_map_msi(struct pci_attach_args *, pci_intr_handle_t *); +int pci_intr_map_msix(struct pci_attach_args *, int, + pci_intr_handle_t *); +int pci_intr_line(pci_chipset_tag_t, pci_intr_handle_t); +const char *pci_intr_string(pci_chipset_tag_t, pci_intr_handle_t); +void *pci_intr_establish(pci_chipset_tag_t, pci_intr_handle_t, + int, int (*)(void *), void *, const char *); +void *pci_intr_establish_cpu(pci_chipset_tag_t, pci_intr_handle_t, + int, struct cpu_info *, + int (*)(void *), void *, const char *); +void pci_intr_disestablish(pci_chipset_tag_t, void *); + +void pci_msi_enable(pci_chipset_tag_t, pcitag_t, bus_addr_t, int); +void pci_msix_enable(pci_chipset_tag_t, pcitag_t, bus_space_tag_t, + int, bus_addr_t, uint32_t); +int pci_msix_table_map(pci_chipset_tag_t, pcitag_t, + bus_space_tag_t, bus_space_handle_t *); +void pci_msix_table_unmap(pci_chipset_tag_t, pcitag_t, + bus_space_tag_t, bus_space_handle_t); + +int sparc64_pci_enumerate_bus(struct pci_softc *, + int (*match)(struct pci_attach_args *), + struct pci_attach_args *); + +#define PCI_MACHDEP_ENUMERATE_BUS sparc64_pci_enumerate_bus + +#define pci_min_powerstate(c, t) (PCI_PMCSR_STATE_D3) +#define pci_set_powerstate_md(c, t, s, p) + +#define pciide_machdep_compat_intr_establish(a, b, c, d, e) (NULL) +#define pciide_machdep_compat_intr_disestablish(a, b) do { } while (0) + +#define pci_dev_postattach(a, b) + +#endif /* _MACHINE_PCI_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/pmap.h b/lib/libc/include/sparc64-openbsd-none/machine/pmap.h new file mode 100644 index 0000000000..e5cad9b40f --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/pmap.h @@ -0,0 +1,214 @@ +/* $OpenBSD: pmap.h,v 1.41 2025/09/18 14:54:33 kettenis Exp $ */ +/* $NetBSD: pmap.h,v 1.16 2001/04/22 23:19:30 thorpej Exp $ */ + +/*- + * Copyright (C) 1995, 1996 Wolfgang Solfrank. + * Copyright (C) 1995, 1996 TooLs GmbH. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by TooLs GmbH. + * 4. The name of TooLs GmbH may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MACHINE_PMAP_H_ +#define _MACHINE_PMAP_H_ + +#ifndef _LOCORE +#ifdef _KERNEL +#include +#endif +#include +#endif + +#define __HAVE_PMAP_PURGE + +/* + * This scheme uses 2-level page tables. + * + * While we're still in 32-bit mode we do the following: + * + * offset: 13 bits + * 1st level: 1024 64-bit TTEs in an 8K page for 10 bits + * 2nd level: 512 32-bit pointers in the pmap for 9 bits + * ------- + * total: 32 bits + * + * In 64-bit mode the Spitfire and Blackbird CPUs support only + * 44-bit virtual addresses. All addresses between + * 0x0000 07ff ffff ffff and 0xffff f800 0000 0000 are in the + * "VA hole" and trap, so we don't have to track them. However, + * we do need to keep them in mind during PT walking. If they + * ever change the size of the address "hole" we need to rework + * all the page table handling. + * + * offset: 13 bits + * 1st level: 1024 64-bit TTEs in an 8K page for 10 bits + * 2nd level: 1024 64-bit pointers in an 8K page for 10 bits + * 3rd level: 1024 64-bit pointers in the segmap for 10 bits + * ------- + * total: 43 bits + * + * Of course, this means for 32-bit spaces we always have a (practically) + * wasted page for the segmap (only one entry used) and half a page wasted + * for the page directory. We still have need of one extra bit 8^(. + */ + +#define HOLESHIFT (43) + +#define PTSZ (PAGE_SIZE/8) +#define PDSZ (PTSZ) +#define STSZ (PTSZ) + +#define PTSHIFT (13) +#define PDSHIFT (10+PTSHIFT) +#define STSHIFT (10+PDSHIFT) + +#define PTMASK (PTSZ-1) +#define PDMASK (PDSZ-1) +#define STMASK (STSZ-1) + +#ifndef _LOCORE + +#define va_to_seg(v) (int)((((paddr_t)(v))>>STSHIFT)&STMASK) +#define va_to_dir(v) (int)((((paddr_t)(v))>>PDSHIFT)&PDMASK) +#define va_to_pte(v) (int)((((paddr_t)(v))>>PTSHIFT)&PTMASK) + +#ifdef _KERNEL + +/* + * Support for big page sizes. This maps the page size to the + * page bits. + */ +struct page_size_map { + u_int64_t mask; + u_int64_t code; +#ifdef DEBUG + u_int64_t use; +#endif +}; +extern const struct page_size_map page_size_map[]; + +struct pmap { + struct mutex pm_mtx; + int pm_ctx; /* Current context */ + int pm_refs; /* ref count */ + /* + * This contains 64-bit pointers to pages that contain + * 1024 64-bit pointers to page tables. All addresses + * are physical. + * + * !!! Only touch this through pseg_get() and pseg_set() !!! + */ + paddr_t pm_physaddr; /* physical address of pm_segs */ + int64_t *pm_segs; + + struct pmap_statistics pm_stats; +}; + +/* + * This comes from the PROM and is used to map prom entries. + */ +struct prom_map { + u_int64_t vstart; + u_int64_t vsize; + u_int64_t tte; +}; + +#define PMAP_NC 0x001 /* Set the E bit in the page */ +#define PMAP_NVC 0x002 /* Don't enable the virtual cache */ +#define PMAP_NOCACHE PMAP_NC +#define PMAP_LITTLE 0x004 /* Map in little endian mode */ +/* Large page size hints -- we really should use another param to pmap_enter() */ +#define PMAP_8K 0x000 +#define PMAP_64K 0x008 /* Use 64K page */ +#define PMAP_512K 0x010 +#define PMAP_4M 0x018 +#define PMAP_SZ_TO_TTE(x) (((x)&0x018)<<58) +/* If these bits are different in va's to the same PA then there is an aliasing in the d$ */ +#define VA_ALIAS_ALIGN (1<<14) +#define VA_ALIAS_MASK (VA_ALIAS_ALIGN - 1) + +typedef struct pmap *pmap_t; + +extern struct pmap kernel_pmap_; +#define pmap_kernel() (&kernel_pmap_) + +/* int pmap_change_wiring(pmap_t pm, vaddr_t va, boolean_t wired); */ +#define pmap_resident_count(pm) ((pm)->pm_stats.resident_count) +#define pmap_update(pm) /* nothing (yet) */ + +#define pmap_proc_iflush(p,va,len) /* nothing */ +#define pmap_init_percpu() do { /* nothing */ } while (0) + +void pmap_bootstrap(u_long, u_long, u_int, u_int); +int pmap_copyinsn(pmap_t, vaddr_t, uint32_t *); + +/* make sure all page mappings are modulo 16K to prevent d$ aliasing */ +#define PMAP_PREFER +/* pmap prefer alignment */ +#define PMAP_PREFER_ALIGN() (VA_ALIAS_ALIGN) +/* pmap prefer offset in alignment */ +#define PMAP_PREFER_OFFSET(of) ((of) & VA_ALIAS_MASK) + +#define PMAP_CHECK_COPYIN CPU_ISSUN4V + +#define PMAP_GROWKERNEL /* turn on pmap_growkernel interface */ + +/* SPARC specific? */ +int pmap_dumpsize(void); +int pmap_dumpmmu(int (*)(dev_t, daddr_t, caddr_t, size_t), daddr_t); +int pmap_pa_exists(paddr_t); + +/* SPARC64 specific */ +int ctx_alloc(struct pmap*); +void ctx_free(struct pmap*); + +#endif /* _KERNEL */ + +/* + * For each struct vm_page, there is a list of all currently valid virtual + * mappings of that page. + */ +typedef struct pv_entry { + struct pv_entry *pv_next; /* next pv_entry */ + struct pmap *pv_pmap; /* pmap where mapping lies */ + vaddr_t pv_va; /* virtual address for mapping */ +} *pv_entry_t; +/* PV flags encoded in the low bits of the VA of the first pv_entry */ + +struct vm_page_md { + struct mutex pvmtx; + struct pv_entry pvent; +}; + +#define VM_MDPAGE_INIT(pg) do { \ + mtx_init(&(pg)->mdpage.pvmtx, IPL_VM); \ + (pg)->mdpage.pvent.pv_next = NULL; \ + (pg)->mdpage.pvent.pv_pmap = NULL; \ + (pg)->mdpage.pvent.pv_va = 0; \ +} while (0) + +#endif /* _LOCORE */ +#endif /* _MACHINE_PMAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/proc.h b/lib/libc/include/sparc64-openbsd-none/machine/proc.h new file mode 100644 index 0000000000..55fd5598d9 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/proc.h @@ -0,0 +1,52 @@ +/* $OpenBSD: proc.h,v 1.10 2024/11/07 05:24:43 jsg Exp $ */ +/* $NetBSD: proc.h,v 1.2 1999/11/06 20:13:50 eeh Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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 8.1 (Berkeley) 6/11/93 + */ + +/* + * Machine-dependent part of the proc structure for SPARC. + */ +struct mdproc { + struct trapframe *md_tf; /* trap/syscall registers */ + struct fpstate *md_fpstate; /* fpu state, if any; always resident */ + volatile int md_astpending; + paddr_t md_pcbpaddr; +}; \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/profile.h b/lib/libc/include/sparc64-openbsd-none/machine/profile.h new file mode 100644 index 0000000000..477b985236 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/profile.h @@ -0,0 +1,74 @@ +/* $OpenBSD: profile.h,v 1.4 2012/08/22 17:19:35 pascal Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)profile.h 8.1 (Berkeley) 6/11/93 + */ + +#ifdef __PIC__ +/* Inline expansion of PICCY_SET() (see ). */ +#define MCOUNT \ + __asm__(".global _mcount");\ + __asm__("_mcount:");\ + __asm__("add %o7, 8, %o1");\ + __asm__("1: rd %pc, %o2");\ + __asm__("add %o2, __mcount-1b, %o2");\ + __asm__("ld [%o2], %o2");\ + __asm__("jmpl %o2, %g0");\ + __asm__("add %i7, 8, %o0"); +#else +#define MCOUNT \ + __asm__(".global _mcount");\ + __asm__("_mcount:");\ + __asm__("add %i7, 8, %o0");\ + __asm__("sethi %hi(__mcount), %o2");\ + __asm__("jmpl %o2 + %lo(__mcount), %g0");\ + __asm__("add %o7, 8, %o1"); +#endif + +#define _MCOUNT_DECL static void __mcount + +#ifdef _KERNEL +/* + * Block interrupts during mcount so that those interrupts can also be + * counted (as soon as we get done with the current counting). On the + * SPARC, we just splhigh/splx as those do not recursively invoke mcount. + */ +#define MCOUNT_ENTER s = splhigh() +#define MCOUNT_EXIT splx(s) +#endif /* _KERNEL */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/psl.h b/lib/libc/include/sparc64-openbsd-none/machine/psl.h new file mode 100644 index 0000000000..84f4b94cac --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/psl.h @@ -0,0 +1,327 @@ +/* $OpenBSD: psl.h,v 1.37 2024/11/06 07:11:14 miod Exp $ */ +/* $NetBSD: psl.h,v 1.20 2001/04/13 23:30:05 thorpej Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)psl.h 8.1 (Berkeley) 6/11/93 + */ + +#ifndef _SPARC64_PSL_ +#define _SPARC64_PSL_ + +/* Interesting spl()s */ +#define PIL_SCSI 3 +#define PIL_BIO 5 +#define PIL_VIDEO 5 +#define PIL_TTY 6 +#define PIL_NET 6 +#define PIL_VM 7 +#define PIL_AUD 8 +#define PIL_CLOCK 10 +#define PIL_FD 11 +#define PIL_SER 12 +#define PIL_STATCLOCK 14 +#define PIL_HIGH 15 +#define PIL_SCHED PIL_STATCLOCK + +/* + * SPARC V9 CCR register + */ + +#define ICC_C 0x01L +#define ICC_V 0x02L +#define ICC_Z 0x04L +#define ICC_N 0x08L +#define XCC_SHIFT 4 +#define XCC_C (ICC_C< 0) { \ + splassert_check(__wantipl, __func__); \ + } \ +} while (0) +#define splsoftassert(wantipl) splassert(wantipl) +#else +#define splassert(wantipl) do { /* nada */ } while (0) +#define splsoftassert(wantipl) do { /* nada */ } while (0) +#endif + +/* + * GCC pseudo-functions for manipulating privileged registers + */ +static inline u_int64_t getpstate(void); +static inline u_int64_t +getpstate(void) +{ + return (sparc_rdpr(pstate)); +} + +static inline void setpstate(u_int64_t); +static inline void +setpstate(u_int64_t newpstate) +{ + sparc_wrpr(pstate, newpstate, 0); +} + +static inline int getcwp(void); +static inline int +getcwp(void) +{ + return (sparc_rdpr(cwp)); +} + +static inline void setcwp(u_int64_t); +static inline void +setcwp(u_int64_t newcwp) +{ + sparc_wrpr(cwp, newcwp, 0); +} + +static inline u_int64_t getver(void); +static inline u_int64_t +getver(void) +{ + return (sparc_rdpr(ver)); +} + +static inline u_int64_t intr_disable(void); +static inline u_int64_t +intr_disable(void) +{ + u_int64_t s; + + s = sparc_rdpr(pstate); + sparc_wrpr(pstate, s & ~PSTATE_IE, 0); + return (s); +} + +static inline void intr_restore(u_int64_t); +static inline void +intr_restore(u_int64_t s) +{ + sparc_wrpr(pstate, s, 0); +} + +static inline void stxa_sync(u_int64_t, u_int64_t, u_int64_t); +static inline void +stxa_sync(u_int64_t va, u_int64_t asi, u_int64_t val) +{ + u_int64_t s = intr_disable(); + stxa_nc(va, asi, val); + __asm volatile("membar #Sync" : : : "memory"); + intr_restore(s); +} + +static inline int +_spl(int newipl) +{ + int oldpil; + + __asm volatile( " rdpr %%pil, %0 \n" + " wrpr %%g0, %1, %%pil \n" + : "=&r" (oldpil) + : "I" (newipl) + : "%g0"); + __asm volatile("" : : : "memory"); + + return (oldpil); +} + +/* A non-priority-decreasing version of SPL */ +static inline int +_splraise(int newpil) +{ + int oldpil; + + oldpil = sparc_rdpr(pil); + if (newpil > oldpil) + sparc_wrpr(pil, newpil, 0); + return (oldpil); +} + +static inline void +_splx(int newpil) +{ + sparc_wrpr(pil, newpil, 0); +} + +#endif /* KERNEL && !_LOCORE */ + +#endif /* _SPARC64_PSL_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/pte.h b/lib/libc/include/sparc64-openbsd-none/machine/pte.h new file mode 100644 index 0000000000..50afa9a98b --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/pte.h @@ -0,0 +1,204 @@ +/* $OpenBSD: pte.h,v 1.17 2024/04/14 19:08:09 miod Exp $ */ +/* $NetBSD: pte.h,v 1.7 2001/07/31 06:55:46 eeh Exp $ */ + +/* + * Copyright (c) 1996-1999 Eduardo Horvath + * + * 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. + * + * 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_PTE_H_ +#define _MACHINE_PTE_H_ + +/* virtual address to virtual page number */ +#define VA_SUN4U_VPG(va) (((int)(va) >> 13) & 31) + +/* virtual address to offset within page */ +#define VA_SUN4U_OFF(va) (((int)(va)) & 0x1FFF) + +/* When we go to 64-bit VAs we need to handle the hole */ +#define VA_VPG(va) VA_SUN4U_VPG(va) +#define VA_OFF(va) VA_SUN4U_OFF(va) + +#define PG_SHIFT4U 13 +#define MMU_PAGE_ALIGN 8192 + +/* If you know where a tte is in the tsb, how do you find its va? */ +#define TSBVA(i) ((tsb[(i)].tag.f.tag_va<<22)|(((i)<<13)&0x3ff000)) + +#ifndef _LOCORE +/* + * This is the spitfire TTE. + */ +#if 0 /* We don't use bitfields anyway. */ +struct sun4u_tag_fields { + u_int64_t tag_g:1, /* global flag */ + tag_ctxt:15, /* context for mapping */ + tag_unassigned:6, + tag_va:42; /* virtual address bits<64:22> */ +}; +union sun4u_tag { struct sun4u_tag_fields f; int64_t tag; }; +struct sun4u_data_fields { + u_int64_t data_v:1, /* valid bit */ + data_size:2, /* page size [8K*8**] */ + data_nfo:1, /* no-fault only */ + data_ie:1, /* invert endianness [inefficient] */ + data_soft2:2, /* reserved for S/W */ + data_pa:36, /* physical address */ + data_accessed:1,/* S/W accessed bit */ + data_modified:1,/* S/W modified bit */ + data_realw:1, /* S/W real writable bit (to manage modified) */ + data_tsblock:1, /* S/W TSB locked entry */ + data_exec:1, /* S/W Executable */ + data_onlyexec:1,/* S/W Executable only */ + data_lock:1, /* lock into TLB */ + data_cacheable:2, /* cacheability control */ + data_e:1, /* explicit accesses only */ + data_priv:1, /* privileged page */ + data_w:1, /* writeable */ + data_g:1; /* same as tag_g */ +}; +union sun4u_data { struct sun4u_data_fields f; int64_t data; }; +struct sun4u_tte { + union sun4u_tag tag; + union sun4u_data data; +}; +#else +struct sun4u_tte { + int64_t tag; + int64_t data; +}; +#endif +typedef struct sun4u_tte pte_t; + +/* Assembly routine to flush a mapping */ +extern void (*sp_tlb_flush_pte)(vaddr_t, uint64_t); +extern void (*sp_tlb_flush_ctx)(uint64_t); + +#if defined(MULTIPROCESSOR) +void smp_tlb_flush_pte(vaddr_t, uint64_t); +void smp_tlb_flush_ctx(uint64_t); +#define tlb_flush_pte(va,ctx) smp_tlb_flush_pte(va, ctx) +#define tlb_flush_ctx(ctx) smp_tlb_flush_ctx(ctx) +#else +#define tlb_flush_pte(va,ctx) (*sp_tlb_flush_pte)(va, ctx) +#define tlb_flush_ctx(ctx) (*sp_tlb_flush_ctx)(ctx) +#endif + +#endif /* _LOCORE */ + +/* TSB tag masks */ +#define CTX_MASK ((1<<13)-1) +#define TSB_TAG_CTX_SHIFT 48 +#define TSB_TAG_VA_SHIFT 22 + +#define TSB_TAG_LOCKED 0x0000040000000000LL + +#define TSB_TAG_G 0x8000000000000000LL +#define TSB_TAG_CTX(t) ((((int64_t)(t))>>TSB_TAG_CTX_SHIFT)&CTX_MASK) +#define TSB_TAG_VA(t) ((((int64_t)(t))<>TSB_TAG_VA_SHIFT)) + +/* Page sizes */ +#define PGSZ_8K 0 +#define PGSZ_64K 1 +#define PGSZ_512K 2 +#define PGSZ_4M 3 + +#define SUN4U_PGSZ_SHIFT 61 +#define SUN4U_TLB_SZ(s) (((uint64_t)(s)) << SUN4U_PGSZ_SHIFT) + +/* TLB data masks */ +#define SUN4U_TLB_V 0x8000000000000000LL +#define SUN4U_TLB_8K SUN4U_TLB_SZ(PGSZ_8K) +#define SUN4U_TLB_64K SUN4U_TLB_SZ(PGSZ_64K) +#define SUN4U_TLB_512K SUN4U_TLB_SZ(PGSZ_512K) +#define SUN4U_TLB_4M SUN4U_TLB_SZ(PGSZ_4M) +#define SUN4U_TLB_SZ_MASK 0x6000000000000000LL +#define SUN4U_TLB_NFO 0x1000000000000000LL +#define SUN4U_TLB_IE 0x0800000000000000LL +#define SUN4U_TLB_SOFT2_MASK 0x07fc000000000000LL +#define SUN4U_TLB_RESERVED_MASK 0x0003800000000000LL +#define SUN4U_TLB_PA_MASK 0x00007fffffffe000LL +#define SUN4U_TLB_SOFT_MASK 0x0000000000001f80LL +/* S/W bits */ +#define SUN4U_TLB_ACCESS 0x0000000000000200LL +#define SUN4U_TLB_MODIFY 0x0000000000000800LL +#define SUN4U_TLB_REAL_W 0x0000000000000400LL +#define SUN4U_TLB_TSB_LOCK 0x0000000000001000LL +#define SUN4U_TLB_EXEC 0x0000000000000100LL +#define SUN4U_TLB_EXEC_ONLY 0x0000000000000080LL +/* H/W bits */ +#define SUN4U_TLB_L 0x0000000000000040LL +#define SUN4U_TLB_CACHE_MASK 0x0000000000000030LL +#define SUN4U_TLB_CP 0x0000000000000020LL +#define SUN4U_TLB_CV 0x0000000000000010LL +#define SUN4U_TLB_E 0x0000000000000008LL +#define SUN4U_TLB_P 0x0000000000000004LL +#define SUN4U_TLB_W 0x0000000000000002LL +#define SUN4U_TLB_G 0x0000000000000001LL + +#define SUN4U_TSB_DATA(g,sz,pa,priv,write,cache,aliased,valid,ie) \ +(((valid)?SUN4U_TLB_V:0LL)|SUN4U_TLB_SZ(sz)|\ +(((u_int64_t)(pa))&SUN4U_TLB_PA_MASK)|\ +((cache)?((aliased)?SUN4U_TLB_CP:SUN4U_TLB_CACHE_MASK):SUN4U_TLB_E)|\ +((priv)?SUN4U_TLB_P:0LL)|((write)?SUN4U_TLB_W:0LL)|((g)?SUN4U_TLB_G:0LL)|\ +((ie)?SUN4U_TLB_IE:0LL)) + +#define SUN4V_PGSZ_SHIFT 0 +#define SUN4V_TLB_SZ(s) (((uint64_t)(s))<rb_bt, (addr), (size), (flags), (hp)) +#define md_space_unmap(rbt, h, size, addrp) \ + do { \ + *addrp = (rbt)->rb_bt->sparc_bus_addr((rbt)->rb_bt, \ + (rbt)->rb_bt, (h)); \ + bus_space_unmap((rbt)->rb_bt, (h), (size)); \ + } while (0) + +void pccbb_attach_hook(struct device *, struct device *, + struct pci_attach_args *); + +#endif /* _MACHINE_RBUS_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/reg.h b/lib/libc/include/sparc64-openbsd-none/machine/reg.h new file mode 100644 index 0000000000..cd4dc0304d --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/reg.h @@ -0,0 +1,92 @@ +/* $OpenBSD: reg.h,v 1.9 2024/03/29 21:14:31 miod Exp $ */ +/* $NetBSD: reg.h,v 1.8 2001/06/19 12:59:16 wiz Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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 8.1 (Berkeley) 6/11/93 + */ + +#ifndef _MACHINE_REG_H_ +#define _MACHINE_REG_H_ + +/* + * The v9 register window. Each stack pointer (%o6 aka %sp) in each window + * must ALWAYS point to some place at which it is safe to scribble on + * 64 bytes. (If not, your process gets mangled.) Furthermore, each + * stack pointer should be aligned on a 16-byte boundary (plus the BIAS) + * for v9 stacks (the kernel as currently coded allows arbitrary alignment, + * but with a hefty performance penalty). + */ +struct rwindow { + int64_t rw_local[8]; /* %l0..%l7 */ + int64_t rw_in[8]; /* %i0..%i7 */ +}; + +struct reg { + int64_t r_tstate; /* tstate register */ + int64_t r_pc; /* return pc */ + int64_t r_npc; /* return npc */ + int r_y; /* %y register -- 32-bits */ + int64_t r_global[8]; /* %g* registers in trap's caller */ + int64_t r_out[8]; /* %o* registers in trap's caller */ + int64_t r_local[8]; /* %l* registers in trap's caller */ + int64_t r_in[8]; /* %i* registers in trap's caller */ +}; + +/* + * FP coprocessor registers. + */ + +struct fpstate { + u_int fs_regs[64]; /* our view is 64 32-bit registers */ + int64_t fs_fsr; /* %fsr */ + int fs_gsr; /* graphics state reg */ +}; + +/* + * The actual FP registers are made accessible (c.f. ptrace(2)) through + * a `struct fpreg'; relies on the + * fact that `fpreg' is a prefix of `fpstate'. + */ +struct fpreg { + u_int fr_regs[64]; /* our view is 64 32-bit registers */ + int64_t fr_fsr; /* %fsr */ + int fr_gsr; /* graphics state reg */ +}; + +#endif /* _MACHINE_REG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/reloc.h b/lib/libc/include/sparc64-openbsd-none/machine/reloc.h new file mode 100644 index 0000000000..6e23309ed5 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/reloc.h @@ -0,0 +1,36 @@ +/* $OpenBSD: reloc.h,v 1.5 2011/03/23 16:54:37 pirofti Exp $ */ +/* + * Copyright (c) 2001 Artur Grabowski + * + * 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_RELOC_H_ +#define _MACHINE_RELOC_H_ + +#define RELOC_NONE 0 + +#define RELOC_COPY 19 +#define RELOC_GLOB_DAT 20 +#define RELOC_JMP_SLOT 21 +#define RELOC_RELATIVE 22 +#define RELOC_64 32 +#define RELOC_UA64 54 +#define RELOC_TLS_DTPMOD32 74 +#define RELOC_TLS_DTPMOD64 75 +#define RELOC_TLS_DTPOFF32 76 +#define RELOC_TLS_DTPOFF64 77 +#define RELOC_TLS_TPOFF32 78 +#define RELOC_TLS_TPOFF64 79 + +#endif /* _MACHINE_RELOC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/setjmp.h b/lib/libc/include/sparc64-openbsd-none/machine/setjmp.h new file mode 100644 index 0000000000..54523bed43 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/setjmp.h @@ -0,0 +1,7 @@ +/* $OpenBSD: setjmp.h,v 1.1 2001/08/23 15:32:01 art Exp $ */ + +/* + * machine/setjmp.h: machine dependent setjmp-related information. + */ + +#define _JBLEN 14 /* size, in longs, of a jmp_buf */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/signal.h b/lib/libc/include/sparc64-openbsd-none/machine/signal.h new file mode 100644 index 0000000000..e94d2341af --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/signal.h @@ -0,0 +1,87 @@ +/* $OpenBSD: signal.h,v 1.13 2024/03/29 21:16:38 miod Exp $ */ +/* $NetBSD: signal.h,v 1.10 2001/05/09 19:50:49 kleink Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)signal.h 8.1 (Berkeley) 6/11/93 + */ + +#ifndef _MACHINE_SIGNAL_H_ +#define _MACHINE_SIGNAL_H_ + +#include + +typedef int sig_atomic_t; + +#if __BSD_VISIBLE || __XPG_VISIBLE >= 420 +/* + * Information pushed on stack when a signal is delivered. + * This is used by the kernel to restore state following + * execution of the signal handler. It is also made available + * to the handler to allow it to restore state properly if + * a non-standard exit is performed. + */ +struct sigcontext { + long sc_cookie; + /* begin machine dependent portion */ + long sc_sp; /* %sp to restore */ + long sc_pc; /* pc to restore */ + long sc_npc; /* npc to restore */ + long sc_tstate; /* tstate to restore */ + long sc_g1; /* %g1 to restore */ + long sc_o0; /* %o0 to restore */ + int sc_mask; /* signal mask to restore */ +}; +#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */ + +#if defined(_KERNEL) +/* + * `Code' arguments to signal handlers. The names, and the funny numbering. + * are defined so as to match up with what SunOS uses; I have no idea why + * they did the numbers that way, except maybe to match up with the 68881. + */ +#define FPE_INTOVF_TRAP 0x01 /* integer overflow */ +#define FPE_INTDIV_TRAP 0x14 /* integer divide by zero */ +#define FPE_FLTINEX_TRAP 0xc4 /* inexact */ +#define FPE_FLTDIV_TRAP 0xc8 /* divide by zero */ +#define FPE_FLTUND_TRAP 0xcc /* underflow */ +#define FPE_FLTOPERR_TRAP 0xd0 /* operand error */ +#define FPE_FLTOVF_TRAP 0xd4 /* overflow */ +#endif + +#endif /* !_MACHINE_SIGNAL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/sparc64.h b/lib/libc/include/sparc64-openbsd-none/machine/sparc64.h new file mode 100644 index 0000000000..16b33d5f77 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/sparc64.h @@ -0,0 +1,65 @@ +/* $OpenBSD: sparc64.h,v 1.14 2018/08/28 00:00:42 dlg Exp $ */ +/* $NetBSD: sparc64.h,v 1.3 2000/10/20 05:47:03 mrg Exp $ */ + +/* + * Copyright (C) 1996 Wolfgang Solfrank. + * Copyright (C) 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 _MACHINE_SPARC64_H_ +#define _MACHINE_SPARC64_H_ + +struct mem_region { + u_int64_t start; + u_int64_t size; +}; + +int prom_set_trap_table(vaddr_t tba, paddr_t mmfsa); +paddr_t prom_vtop(vaddr_t vaddr); +vaddr_t prom_claim_virt(vaddr_t vaddr, int len); +vaddr_t prom_alloc_virt(int len, int align); +int prom_free_virt(vaddr_t vaddr, int len); +int prom_unmap_virt(vaddr_t vaddr, int len); +int prom_map_phys(paddr_t paddr, off_t size, vaddr_t vaddr, int mode); +paddr_t prom_alloc_phys(int len, int align); +paddr_t prom_claim_phys(paddr_t phys, int len); +int prom_free_phys(paddr_t paddr, int len); +paddr_t prom_get_msgbuf(int len, int align); +int prom_itlb_load(int index, u_int64_t data, vaddr_t vaddr); +int prom_dtlb_load(int index, u_int64_t data, vaddr_t vaddr); +void prom_start_cpu(int cpu, void *func, long arg); +void prom_start_cpu_by_cpuid(int cpu, void *func, long arg); +const char *prom_serengeti_set_console_input(const char *); +uint64_t prom_set_sun4v_api_version(uint64_t, uint64_t, uint64_t, uint64_t *); +void prom_sun4v_soft_state_supported(void); + +/* + * Debug + */ +void prom_printf(const char *, ...); +#endif /* _MACHINE_SPARC64_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/spinlock.h b/lib/libc/include/sparc64-openbsd-none/machine/spinlock.h new file mode 100644 index 0000000000..4a30761476 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/spinlock.h @@ -0,0 +1,10 @@ +/* $OpenBSD: spinlock.h,v 1.3 2017/09/05 02:40:54 guenther Exp $ */ + +#ifndef _MACHINE_SPINLOCK_H_ +#define _MACHINE_SPINLOCK_H_ + +#define _ATOMIC_LOCK_UNLOCKED (0x00) +#define _ATOMIC_LOCK_LOCKED (0xFF) +typedef unsigned char _atomic_lock_t; + +#endif \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/tcb.h b/lib/libc/include/sparc64-openbsd-none/machine/tcb.h new file mode 100644 index 0000000000..a5d8911686 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/tcb.h @@ -0,0 +1,44 @@ +/* $OpenBSD: tcb.h,v 1.7 2017/04/20 10:03:40 kettenis Exp $ */ + +/* + * Copyright (c) 2011 Philip Guenther + * + * 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 + +#include + +/* + * In userspace, register %g7 contains the address of the thread's TCB + */ +#define TCB_GET(p) \ + ((void *)(p)->p_md.md_tf->tf_global[7]) +#define TCB_SET(p, addr) \ + ((p)->p_md.md_tf->tf_global[7] = (int64_t)(addr)) + +#else /* _KERNEL */ + +/* ELF TLS ABI calls for big TCB, with static TLS data at negative offsets */ +#define TLS_VARIANT 2 + +register void *__tcb __asm__ ("g7"); +#define TCB_GET() (__tcb) +#define TCB_SET(tcb) ((__tcb) = (tcb)) + +#endif /* _KERNEL */ +#endif /* _MACHINE_TCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/timetc.h b/lib/libc/include/sparc64-openbsd-none/machine/timetc.h new file mode 100644 index 0000000000..7ae3900f52 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/timetc.h @@ -0,0 +1,24 @@ +/* $OpenBSD: timetc.h,v 1.2 2020/07/08 09:20:28 kettenis Exp $ */ +/* + * Copyright (c) 2020 Paul Irofti + * + * 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_TIMETC_H_ +#define _MACHINE_TIMETC_H_ + +#define TC_TICK 1 +#define TC_SYS_TICK 2 + +#endif /* _MACHINE_TIMETC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/trap.h b/lib/libc/include/sparc64-openbsd-none/machine/trap.h new file mode 100644 index 0000000000..2b7f57bdaf --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/trap.h @@ -0,0 +1,159 @@ +/* $OpenBSD: trap.h,v 1.5 2013/04/02 13:24:57 kettenis Exp $ */ +/* $NetBSD: trap.h,v 1.4 1999/06/07 05:28:04 eeh Exp $ */ + +/* + * Copyright (c) 1996-1999 Eduardo Horvath + * + * 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. + * + * 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_TRAP_H +#define _MACHINE_TRAP_H + +/* trap vec (pri) description */ +/* 0x000 unused */ +#define T_POR 0x001 /* (0) power on reset */ +#define T_WDR 0x002 /* (1) watchdog reset */ +#define T_XIR 0x003 /* (1) externally initiated reset */ +#define T_SIR 0x004 /* (1) software initiated reset */ +#define T_RED_EXCEPTION 0x005 /* (1) RED state exception */ +/* 0x006 unused */ +/* 0x007 unused */ +#define T_INST_EXCEPT 0x008 /* (5) instruction access exception */ +#define T_TEXTFAULT 0x009 /* (2) ? Text fault */ +#define T_INST_ERROR 0x00a /* (3) instruction access error */ +/* 0x00b unused */ +/* through 0x00f unused */ +#define T_ILLINST 0x010 /* (7) illegal instruction */ +#define T_PRIVINST 0x011 /* (6) privileged opcode */ +#define T_UNIMP_LDD 0x012 /* (6) unimplemented LDD */ +#define T_UNIMP_STD 0x013 /* (6) unimplemented STD */ +/* 0x014 unused */ +/* through 0x01f unused */ +#define T_FPDISABLED 0x020 /* (8) fpu disabled */ +#define T_FP_IEEE_754 0x021 /* (11) ieee 754 exception */ +#define T_FP_OTHER 0x022 /* (11) other fp exception */ +#define T_TAGOF 0x023 /* (14) tag overflow */ +#define T_CLEAN_WINDOW 0x024 /* (10) clean window exception */ +/* 0x025 unused */ +/* through 0x027 unused */ +#define T_DIV0 0x028 /* (15) division routine was handed 0 */ +#define T_PROCERR 0x029 /* (4) internal processor error */ +/* 0x02a unused */ +/* through 0x02f unused */ +#define T_DATAFAULT 0x030 /* (12) address fault during data fetch */ +#define T_DATA_MMU_MISS 0x031 /* (12) data access MMU miss */ +#define T_DATA_ERROR 0x032 /* (12) data access error */ +#define T_DATA_PROT 0x033 /* (12) Data protection ??? */ +#define T_ALIGN 0x034 /* (10) address not properly aligned */ +#define T_LDDF_ALIGN 0x035 /* (10) LDDF address not properly aligned */ +#define T_STDF_ALIGN 0x036 /* (10) STDF address not properly aligned */ +#define T_PRIVACT 0x037 /* (11) privileged action */ +#define T_LDQF_ALIGN 0x038 /* (10) LDQF address not properly aligned */ +#define T_STQF_ALIGN 0x039 /* (10) STQF address not properly aligned */ +/* 0x03a unused */ +/* through 0x03f unused */ +#define T_ASYNC_ERROR 0x040 /* (2) ???? */ +#define T_L1INT 0x041 /* (31) level 1 interrupt */ +#define T_L2INT 0x042 /* (30) level 2 interrupt */ +#define T_L3INT 0x043 /* (29) level 3 interrupt */ +#define T_L4INT 0x044 /* (28) level 4 interrupt */ +#define T_L5INT 0x045 /* (27) level 5 interrupt */ +#define T_L6INT 0x046 /* (26) level 6 interrupt */ +#define T_L7INT 0x047 /* (25) level 7 interrupt */ +#define T_L8INT 0x048 /* (24) level 8 interrupt */ +#define T_L9INT 0x049 /* (23) level 9 interrupt */ +#define T_L10INT 0x04a /* (22) level 10 interrupt */ +#define T_L11INT 0x04b /* (21) level 11 interrupt */ +#define T_L12INT 0x04c /* (20) level 12 interrupt */ +#define T_L13INT 0x04d /* (19) level 13 interrupt */ +#define T_L14INT 0x04e /* (18) level 14 interrupt */ +#define T_L15INT 0x04f /* (17) level 15 interrupt */ +/* 0x050 unused */ +/* through 0x05f unused */ +#define T_INTVEC 0x060 /* (16) interrupt vector [Interrupt Global Regs]*/ +#define T_PA_WATCHPT 0x061 /* (12) Physical addr data watchpoint */ +#define T_VA_WATCHPT 0x062 /* (11) Virtual addr data watchpoint */ +#define T_ECCERR 0x063 /* (33) ECC correction error */ +#define T_FIMMU_MISS 0x064 /* (2) fast instruction access MMU miss */ +/* through 0x067 unused */ +#define T_FDMMU_MISS 0x068 /* (2) fast data access MMU miss */ +/* through 0x06b unused */ +#define T_FDMMU_PROT 0x06c /* (2) fast data access protection */ +/* through 0x06f unused */ +/* 0x070...0x07f implementation dependent exceptions */ +#define T_SPILL_N_NORM 0x080 /* (9) spill (n=0..7) normal */ +/* through 0x09f unused */ +#define T_SPILL_N_OTHER 0x0a0 /* (9) spill (n=0..7) other */ +/* through 0x0bf unused */ +#define T_FILL_N_NORM 0x0c0 /* (9) fill (n=0..7) normal */ +/* through 0x0df unused */ +#define T_FILL_N_OTHER 0x0e0 /* (9) fill (n=0..7) other */ +/* through 0x0ff unused */ + +/* beginning of `user' vectors (from trap instructions) - all priority 16 */ +#define T_SUN_SYSCALL 0x100 /* system call */ +#define T_BREAKPOINT 0x101 /* breakpoint `instruction' */ +#define T_UDIV0 0x102 /* division routine was handed 0 */ +#define T_FLUSHWIN 0x103 /* flush windows */ +#define T_CLEANWIN 0x104 /* provide clean windows */ +#define T_RANGECHECK 0x105 /* ? */ +#define T_FIXALIGN 0x106 /* fix up unaligned accesses */ +#define T_INTOF 0x107 /* integer overflow ? */ +#define T_SVR4_SYSCALL 0x108 /* SVR4 system call */ +#define T_BSD_SYSCALL 0x109 /* BSD system call */ +#define T_KGDB_EXEC 0x10a /* for kernel gdb */ + +/* 0x10b..0x1ff are currently unallocated, except the following */ +#define T_SVR4_GETCC 0x120 +#define T_SVR4_SETCC 0x121 +#define T_SVR4_GETPSR 0x122 +#define T_SVR4_SETPSR 0x123 +#define T_SVR4_GETHRTIME 0x124 +#define T_SVR4_GETHRVTIME 0x125 +#define T_SVR4_GETHRESTIME 0x127 +#define T_GETCC 0x132 +#define T_SETCC 0x133 +#define T_SVID_SYSCALL 0x164 +#define T_SPARC_INTL_SYSCALL 0x165 +#define T_OS_VENDOR_SYSCALL 0x166 +#define T_HW_OEM_SYSCALL 0x167 +#define T_RTF_DEF_TRAP 0x168 +#define T_MON_BREAKPOINT 0x17f + +#ifdef _KERNEL /* pseudo traps for locore.s */ +#define T_RWRET -1 /* need first user window for trap return */ +#define T_AST -2 /* no-op, just needed reschedule or profile */ +#endif + +/* flags to system call (flags in %g1 along with syscall number) */ +#define SYSCALL_G2RFLAG 0x400 /* on success, return to %g2 rather than npc */ + +/* + * `software trap' macros to keep people happy (sparc v8 manual says not + * to set the upper bits). + */ +#define ST_BREAKPOINT (T_BREAKPOINT & 0x7f) +#define ST_DIV0 (T_DIV0 & 0x7f) +#define ST_FLUSHWIN (T_FLUSHWIN & 0x7f) +#define ST_SYSCALL (T_SUN_SYSCALL & 0x7f) + +#endif /* _MACHINE_TRAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/vmparam.h b/lib/libc/include/sparc64-openbsd-none/machine/vmparam.h new file mode 100644 index 0000000000..4a3d2ed36c --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/vmparam.h @@ -0,0 +1,124 @@ +/* $OpenBSD: vmparam.h,v 1.35 2024/03/29 21:06:14 miod Exp $ */ +/* $NetBSD: vmparam.h,v 1.18 2001/05/01 02:19:19 thorpej Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)vmparam.h 8.1 (Berkeley) 6/11/93 + */ + +/* + * Machine dependent constants for sun4u and sun4v UltraSPARC + */ + +#ifndef VMPARAM_H +#define VMPARAM_H + +#define USRSTACK 0xffffffffffffe000L + +/* + * Virtual memory related constants, all in bytes + */ +/* + * Since the compiler generates `call' instructions we can't + * have more than 4GB in a single text segment. + * + * And since we only have a 40-bit address space, allow half + * of that for data and the other half for stack. + */ +#ifndef MAXTSIZ +#define MAXTSIZ (1L*1024*1024*1024) /* max text size */ +#endif +#ifndef DFLDSIZ +#define DFLDSIZ (128L*1024*1024) /* initial data size limit */ +#endif +#ifndef MAXDSIZ +#define MAXDSIZ (8L*1024*1024*1024) /* max data size */ +#endif +#ifndef BRKSIZ +#define BRKSIZ MAXDSIZ /* heap gap size */ +#endif +#ifndef DFLSSIZ +#define DFLSSIZ (2L*1024*1024) /* initial stack size limit */ +#endif +#ifndef MAXSSIZ +#define MAXSSIZ (32L*1024*1024) /* max stack size */ +#endif + +#define STACKGAP_RANDOM 256*1024 + +/* + * Size of shared memory map + */ +#ifndef SHMMAXPGS +#define SHMMAXPGS 4096 /* 32mb */ +#endif + +/* + * Size of User Raw I/O map + */ +#define USRIOSIZE 300 + +/* + * Mach derived constants + */ + +/* + * User/kernel map constants. + */ +#define VM_MIN_ADDRESS ((vaddr_t)PAGE_SIZE) +#define VM_MAX_ADDRESS ((vaddr_t)-1) +#define VM_MAXUSER_ADDRESS ((vaddr_t)-PAGE_SIZE) +#ifdef _KERNEL +#define VM_MIN_STACK_ADDRESS ((vaddr_t)0xfffffe0000000000L) +#endif + +/* map PIE into the first quarter of the address space before hole */ +#define VM_PIE_MIN_ADDR PAGE_SIZE +#define VM_PIE_MAX_ADDR 0x10000000000 + +#define VM_MIN_KERNEL_ADDRESS ((vaddr_t)KERNBASE) +#define VM_MAX_KERNEL_ADDRESS ((vaddr_t)0x000007ffffffffffL) + +/* virtual sizes (bytes) for various kernel submaps */ +#define VM_PHYS_SIZE (USRIOSIZE*PAGE_SIZE) + +#define VM_PHYSSEG_MAX 32 /* up to 32 segments */ +#define VM_PHYSSEG_STRAT VM_PSTRAT_BSEARCH +#define VM_PHYSSEG_NOADD /* can't add RAM after vm_mem_init */ + +#endif \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/machine/z8530var.h b/lib/libc/include/sparc64-openbsd-none/machine/z8530var.h new file mode 100644 index 0000000000..9439d8e8f5 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/machine/z8530var.h @@ -0,0 +1,80 @@ +/* $OpenBSD: z8530var.h,v 1.9 2024/03/29 21:17:13 miod Exp $ */ +/* $NetBSD: z8530var.h,v 1.4 2000/11/08 23:41:42 eeh Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)zsvar.h 8.1 (Berkeley) 6/11/93 + */ + +#include +#include + +struct zsc_softc { + struct device zsc_dev; /* base device */ + bus_space_tag_t zsc_bustag; /* bus space/dma tags */ + bus_dma_tag_t zsc_dmatag; + struct zs_chanstate *zsc_cs[2]; /* channel A and B soft state */ + + /* Machine-dependent part follows... */ + void *zsc_softintr; + int zsc_promunit; /* PROM's view of zs devices */ + int zsc_node; /* PROM node, if any */ + struct zs_chanstate zsc_cs_store[2]; +}; + +/* + * Functions to read and write individual registers in a channel. + * The ZS chip requires a 1.6 uSec. recovery time between accesses. + * On sparc64, the recovery time is handled in hardware. + */ + +u_char zs_read_reg(struct zs_chanstate *cs, u_char reg); +u_char zs_read_csr(struct zs_chanstate *cs); +u_char zs_read_data(struct zs_chanstate *cs); + +void zs_write_reg(struct zs_chanstate *cs, u_char reg, u_char val); +void zs_write_csr(struct zs_chanstate *cs, u_char val); +void zs_write_data(struct zs_chanstate *cs, u_char val); + +/* The sparc has splzs() in psl.h */ + +/* We want to call it "zs" instead of "zsc" (sigh). */ +#ifndef ZSCCF_CHANNEL +#define ZSCCF_CHANNEL 0 +#define ZSCCF_CHANNEL_DEFAULT -1 +#endif \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/_float.h b/lib/libc/include/sparc64-openbsd-none/sparc64/_float.h new file mode 100644 index 0000000000..3ab11abcab --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/_float.h @@ -0,0 +1,80 @@ +/* $OpenBSD: _float.h,v 1.1 2012/06/26 16:12:45 deraadt Exp $ */ + +/* + * Copyright (c) 1992, 1993, 2001 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _MACHINE__FLOAT_H_ +#define _MACHINE__FLOAT_H_ + +#define __FLT_RADIX 2 /* b */ +#define __FLT_ROUNDS __flt_rounds() +#define __FLT_EVAL_METHOD 0 /* no promotions */ + +#define __FLT_MANT_DIG 24 /* p */ +#define __FLT_EPSILON 1.19209290E-07F /* b**(1-p) */ +#define __FLT_DIG 6 /* floor((p-1)*log10(b))+(b == 10) */ +#define __FLT_MIN_EXP -125 /* emin */ +#define __FLT_MIN 1.17549435E-38F /* b**(emin-1) */ +#define __FLT_MIN_10_EXP -37 /* ceil(log10(b**(emin-1))) */ +#define __FLT_MAX_EXP 128 /* emax */ +#define __FLT_MAX 3.40282347E+38F /* (1-b**(-p))*b**emax */ +#define __FLT_MAX_10_EXP 38 /* floor(log10((1-b**(-p))*b**emax)) */ + +#define __DBL_MANT_DIG 53 +#define __DBL_EPSILON 2.2204460492503131E-16 +#define __DBL_DIG 15 +#define __DBL_MIN_EXP -1021 +#define __DBL_MIN 2.2250738585072014E-308 +#define __DBL_MIN_10_EXP -307 +#define __DBL_MAX_EXP 1024 +#define __DBL_MAX 1.7976931348623157E+308 +#define __DBL_MAX_10_EXP 308 + +#define __LDBL_MANT_DIG 113 +#define __LDBL_EPSILON 1.925929944387235853055977942584927319E-34L +#define __LDBL_DIG 33 +#define __LDBL_MIN_EXP (-16381) +#define __LDBL_MIN 3.362103143112093506262677817321752603E-4932L +#define __LDBL_MIN_10_EXP (-4931) +#define __LDBL_MAX_EXP (+16384) +#define __LDBL_MAX 1.189731495357231765085759326628007016E+4932L +#define __LDBL_MAX_10_EXP (+4932) + +#define __DECIMAL_DIG 36 + +#endif /* _MACHINE__FLOAT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/_types.h b/lib/libc/include/sparc64-openbsd-none/sparc64/_types.h new file mode 100644 index 0000000000..b0d11eb13a --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/_types.h @@ -0,0 +1,140 @@ +/* $OpenBSD: _types.h,v 1.25 2023/07/02 19:02:28 cheloha 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[2]; +} 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 0xf +#define _STACKALIGNBYTES _ALIGNBYTES +#define _ALIGN(p) (((unsigned long)(p) + _ALIGNBYTES) & ~_ALIGNBYTES) +#define _ALIGNED_POINTER(p,t) ((((unsigned long)(p)) & (sizeof(t) - 1)) == 0) +#define _MAX_PAGE_SHIFT 13 /* 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; +typedef long long __int64_t; +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 +typedef int __wchar_t; +#endif +typedef int __wint_t; +typedef int __rune_t; +typedef void * __wctrans_t; +typedef void * __wctype_t; + +#endif /* _MACHINE__TYPES_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/apmvar.h b/lib/libc/include/sparc64-openbsd-none/sparc64/apmvar.h new file mode 100644 index 0000000000..62e9480a19 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/apmvar.h @@ -0,0 +1,122 @@ +/* $OpenBSD: apmvar.h,v 1.7 2019/01/22 02:36:30 phessler Exp $ */ + +/* + * Copyright (c) 2001 Alexander Guy + * Copyright (c) 1995 John T. Kohl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef _MACHINE_APMVAR_H_ +#define _MACHINE_APMVAR_H_ + +#include + +/* Advanced Power Management (v1.0 and v1.1 specification) + * functions/defines/etc. + */ + +/* These definitions make up the heart of the user-land interface + * to the APM devices. + */ + +#define APM_AC_OFF 0x00 +#define APM_AC_ON 0x01 +#define APM_AC_BACKUP 0x02 +#define APM_AC_UNKNOWN 0xff +#define APM_BATT_HIGH 0x00 +#define APM_BATT_LOW 0x01 +#define APM_BATT_CRITICAL 0x02 +#define APM_BATT_CHARGING 0x03 +#define APM_BATT_UNKNOWN 0xff +#define APM_BATT_LIFE_UNKNOWN 0xff + +#define APM_NOEVENT 0x0000 +#define APM_STANDBY_REQ 0x0001 +#define APM_SUSPEND_REQ 0x0002 +#define APM_NORMAL_RESUME 0x0003 +#define APM_CRIT_RESUME 0x0004 /* suspend/resume happened + without us */ +#define APM_BATTERY_LOW 0x0005 +#define APM_POWER_CHANGE 0x0006 +#define APM_UPDATE_TIME 0x0007 +#define APM_CRIT_SUSPEND_REQ 0x0008 +#define APM_USER_STANDBY_REQ 0x0009 +#define APM_USER_SUSPEND_REQ 0x000A +#define APM_SYS_STANDBY_RESUME 0x000B +#define APM_CAPABILITY_CHANGE 0x000C /* apm v1.2 */ +#define APM_USER_HIBERNATE_REQ 0x000D +#define APM_EVENT_MASK 0xffff + +#define APM_EVENT_COMPOSE(t,i) ((((i) & 0x7fff) << 16)|((t) & APM_EVENT_MASK)) +#define APM_EVENT_TYPE(e) ((e) & APM_EVENT_MASK) +#define APM_EVENT_INDEX(e) ((e) >> 16) + +/* + * LP (Laptop Package) + * + * Copyright (C) 1994 by HOSOKAWA Tatsumi + * + * This software may be used, modified, copied, and distributed, in + * both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + */ + +#define APM_BATTERY_ABSENT 4 + +struct apm_power_info { + u_char battery_state; + u_char ac_state; + u_char battery_life; + u_char spare1; + u_int minutes_left; /* estimate */ + u_int spare2[6]; +}; + +struct apm_ctl { + u_int dev; + u_int mode; +}; + +#define APM_IOC_REJECT _IOW('A', 0, struct apm_event_info) /* reject request # */ +#define APM_IOC_STANDBY _IO('A', 1) /* put system into standby */ +#define APM_IOC_SUSPEND _IO('A', 2) /* put system into suspend */ +#define APM_IOC_GETPOWER _IOR('A', 3, struct apm_power_info) /* fetch battery state */ +#define APM_IOC_DEV_CTL _IOW('A', 5, struct apm_ctl) /* put device into mode */ +#define APM_IOC_PRN_CTL _IOW('A', 6, int ) /* driver power status msg */ +#define APM_PRINT_ON 0 /* driver power status displayed */ +#define APM_PRINT_OFF 1 /* driver power status not displayed */ +#define APM_PRINT_PCT 2 /* driver power status only displayed + if the percentage changes */ +#define APM_IOC_STANDBY_REQ _IO('A', 7) /* request standby */ +#define APM_IOC_SUSPEND_REQ _IO('A', 8) /* request suspend */ +#define APM_IOC_HIBERNATE _IO('A', 9) /* put system into hibernate */ + +#endif /* _MACHINE_APMVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/asm.h b/lib/libc/include/sparc64-openbsd-none/sparc64/asm.h new file mode 100644 index 0000000000..2267bb9443 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/asm.h @@ -0,0 +1,96 @@ +/* $OpenBSD: asm.h,v 1.19 2024/03/29 21:05:34 miod Exp $ */ +/* $NetBSD: asm.h,v 1.15 2000/08/02 22:24:39 eeh Exp $ */ + +/* + * Copyright (c) 1994 Allen Briggs + * All rights reserved. + * + * Gleaned from locore.s and sun3 asm.h which had the following copyrights: + * locore.s: + * Copyright (c) 1988 University of Utah. + * Copyright (c) 1982, 1990 The Regents of the University of California. + * sun3/include/asm.h: + * Copyright (c) 1993 Adam Glass + * Copyright (c) 1990 The Regents of the University of California. + * + * 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_ASM_H_ +#define _MACHINE_ASM_H_ + +/* Pull in CC64FSZ and BIAS from frame.h */ +#include + +#define _C_LABEL(name) name +#define _ASM_LABEL(name) name + +#ifdef __PIC__ +/* + * PIC_PROLOGUE() is akin to the compiler generated function prologue for + * PIC code. It leaves the address of the Global Offset Table in DEST, + * clobbering register TMP in the process. Using the temporary enables us + * to work without a stack frame (doing so requires saving %o7) . + */ +#define PIC_PROLOGUE(dest,tmp) \ + sethi %hi(_GLOBAL_OFFSET_TABLE_-4),dest; \ + rd %pc, tmp; \ + or dest,%lo(_GLOBAL_OFFSET_TABLE_+4),dest; \ + add dest,tmp,dest +#else +#define PIC_PROLOGUE(dest,tmp) +#endif + +#define FTYPE(x) .type x,@function +#define OTYPE(x) .type x,@object + +#define _ENTRY_NB(name) \ + .align 4; .proc 1; FTYPE(name); name: +#define _ENTRY(name) .globl name; _ENTRY_NB(name) + +#if defined(PROF) || defined(GPROF) +#define _PROF_PROLOGUE \ + .data; .align 8; 1: .uaword 0; .uaword 0; \ + .text; save %sp,-CC64FSZ,%sp; sethi %hi(1b),%o0; call _mcount; \ + or %o0,%lo(1b),%o0; restore +#else +#define _PROF_PROLOGUE +#endif + +#define ENTRY(name) _ENTRY(name); _PROF_PROLOGUE +#define NENTRY(name) _ENTRY(name) +#define ENTRY_NB(name) _ENTRY_NB(name); _PROF_PROLOGUE +#define ASENTRY(name) _ENTRY(name); _PROF_PROLOGUE +#define FUNC(name) ASENTRY(name) +#define END(y) .size y, . - y + +#define STRONG_ALIAS(alias,sym) \ + .global alias; \ + alias = sym +#define WEAK_ALIAS(alias,sym) \ + .weak alias; \ + alias = sym + +#endif /* _MACHINE_ASM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/atomic.h b/lib/libc/include/sparc64-openbsd-none/sparc64/atomic.h new file mode 100644 index 0000000000..bab72dabbe --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/atomic.h @@ -0,0 +1,154 @@ +/* $OpenBSD: atomic.h,v 1.15 2017/07/04 09:00:12 mpi Exp $ */ +/* + * Copyright (c) 2007 Artur Grabowski + * + * 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_ + +static inline unsigned int +_atomic_cas_uint(volatile unsigned int *p, unsigned int e, unsigned int n) +{ + __asm volatile("cas [%2], %3, %0" + : "+r" (n), "=m" (*p) + : "r" (p), "r" (e), "m" (*p)); + + return (n); +} +#define atomic_cas_uint(_p, _e, _n) _atomic_cas_uint((_p), (_e), (_n)) + +static inline unsigned long +_atomic_cas_ulong(volatile unsigned long *p, unsigned long e, unsigned long n) +{ + __asm volatile("casx [%2], %3, %0" + : "+r" (n), "=m" (*p) + : "r" (p), "r" (e), "m" (*p)); + + return (n); +} +#define atomic_cas_ulong(_p, _e, _n) _atomic_cas_ulong((_p), (_e), (_n)) + +static inline void * +_atomic_cas_ptr(volatile void *p, void *e, void *n) +{ + __asm volatile("casx [%2], %3, %0" + : "+r" (n), "=m" (*(volatile unsigned long *)p) + : "r" (p), "r" (e), "m" (*(volatile unsigned long *)p)); + + return (n); +} +#define atomic_cas_ptr(_p, _e, _n) _atomic_cas_ptr((_p), (_e), (_n)) + +#define _def_atomic_swap(_f, _t, _c) \ +static inline _t \ +_f(volatile _t *p, _t v) \ +{ \ + _t e; \ + _t r; \ + \ + r = (_t)*p; \ + do { \ + e = r; \ + r = _c(p, e, v); \ + } while (r != e); \ + \ + return (r); \ +} + +_def_atomic_swap(_atomic_swap_uint, unsigned int, atomic_cas_uint) +_def_atomic_swap(_atomic_swap_ulong, unsigned long, atomic_cas_ulong) +#undef _def_atomic_swap + +static inline void * +_atomic_swap_ptr(volatile void *p, void *v) +{ + void *e, *r; + + r = *(void **)p; + do { + e = r; + r = atomic_cas_ptr(p, e, v); + } while (r != e); + + return (r); +} + +#define atomic_swap_uint(_p, _v) _atomic_swap_uint(_p, _v) +#define atomic_swap_ulong(_p, _v) _atomic_swap_ulong(_p, _v) +#define atomic_swap_ptr(_p, _v) _atomic_swap_ptr(_p, _v) + +#define _def_atomic_op_nv(_f, _t, _c, _op) \ +static inline _t \ +_f(volatile _t *p, _t v) \ +{ \ + _t e, r, f; \ + \ + r = *p; \ + do { \ + e = r; \ + f = e _op v; \ + r = _c(p, e, f); \ + } while (r != e); \ + \ + return (f); \ +} + +_def_atomic_op_nv(_atomic_add_int_nv, unsigned int, atomic_cas_uint, +) +_def_atomic_op_nv(_atomic_add_long_nv, unsigned long, atomic_cas_ulong, +) +_def_atomic_op_nv(_atomic_sub_int_nv, unsigned int, atomic_cas_uint, -) +_def_atomic_op_nv(_atomic_sub_long_nv, unsigned long, atomic_cas_ulong, -) +#undef _def_atomic_op_nv + +#define atomic_add_int_nv(_p, _v) _atomic_add_int_nv(_p, _v) +#define atomic_add_long_nv(_p, _v) _atomic_add_long_nv(_p, _v) +#define atomic_sub_int_nv(_p, _v) _atomic_sub_int_nv(_p, _v) +#define atomic_sub_long_nv(_p, _v) _atomic_sub_long_nv(_p, _v) + +#define __membar(_m) __asm volatile("membar " _m ::: "memory") + +#define membar_enter() __membar("#StoreLoad|#StoreStore") +#define membar_exit() __membar("#LoadStore|#StoreStore") +#define membar_producer() __membar("#StoreStore") +#define membar_consumer() __membar("#LoadLoad") +#define membar_sync() __membar("#Sync") + +#if defined(_KERNEL) + +static __inline void +atomic_setbits_int(volatile unsigned int *uip, unsigned int v) +{ + unsigned int e, r; + + r = *uip; + do { + e = r; + r = atomic_cas_uint(uip, e, e | v); + } while (r != e); +} + +static __inline void +atomic_clearbits_int(volatile unsigned int *uip, unsigned int v) +{ + unsigned int e, r; + + r = *uip; + do { + e = r; + r = atomic_cas_uint(uip, e, e & ~v); + } while (r != e); +} + +#endif /* defined(_KERNEL) */ +#endif /* _MACHINE_ATOMIC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/autoconf.h b/lib/libc/include/sparc64-openbsd-none/sparc64/autoconf.h new file mode 100644 index 0000000000..0a5ed5b2dc --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/autoconf.h @@ -0,0 +1,159 @@ +/* $OpenBSD: autoconf.h,v 1.20 2024/05/17 20:05:08 miod Exp $ */ +/* $NetBSD: autoconf.h,v 1.10 2001/07/24 19:32:11 eeh Exp $ */ + +/*- + * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Paul Kranenburg. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)autoconf.h 8.2 (Berkeley) 9/30/93 + */ + +/* + * Autoconfiguration information. + */ + +#include +#include + +/* This is used to map device classes to IPLs */ +struct intrmap { + char *in_class; + int in_lev; +}; +extern struct intrmap intrmap[]; + +/* The "mainbus" on ultra desktops is actually the UPA bus. We need to + * separate this from peripheral buses like SBus and PCI because each bus may + * have different ways of encoding properties, such as "reg" and "interrupts". + */ + +/* Device register space description */ +struct upa_reg { + int64_t ur_paddr; + int64_t ur_len; +}; + +/* + * Attach arguments presented by mainbus_attach() + * + * Large fields first followed by smaller ones to minimize stack space used. + */ +struct mainbus_attach_args { + bus_space_tag_t ma_bustag; /* parent bus tag */ + bus_dma_tag_t ma_dmatag; + char *ma_name; /* PROM node name */ + struct upa_reg *ma_reg; /* "reg" properties */ + u_int *ma_address; /* "address" properties -- 32 bits */ + u_int *ma_interrupts; /* "interrupts" properties */ + int ma_upaid; /* UPA bus ID */ + int ma_node; /* PROM handle */ + int ma_nreg; /* Counts for those properties */ + int ma_naddress; + int ma_ninterrupts; + int ma_pri; /* priority (IPL) */ +}; + +/* + * length; the others convert or make some other guarantee. + */ +long getproplen(int node, char *name); +int getprop(int, char *, size_t, int *, void **); +char *getpropstring(int node, char *name); +int getpropint(int node, char *name, int deflt); +int getpropspeed(int node, char *name); + +/* Frequently used options node */ +extern int optionsnode; + + /* new interfaces: */ +char *getpropstringA(int, char *, char *); + +/* + * `clockfreq' produces a printable representation of a clock frequency + * (this is just a frill). + */ +char *clockfreq(long freq); + +/* Openprom V2 style boot path */ +struct device; +struct bootpath { + int node; + char name[16]; /* name of this node */ + long val[3]; /* up to three optional values */ + struct device *dev; /* device that recognised this component */ +}; +struct bootpath *bootpath_store(int, struct bootpath *); + +void bootstrap(int); +int firstchild(int); +int nextsibling(int); +void callrom(void); +struct device *getdevunit(const char *, int); +int romgetcursoraddr(int **, int **); +int findroot(void); +int findnode(int, const char *); +int checkstatus(int); +int node_has_property(int, const char *); +void device_register(struct device *, void *); \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/boot_flag.h b/lib/libc/include/sparc64-openbsd-none/sparc64/boot_flag.h new file mode 100644 index 0000000000..e53f7fc9bd --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/boot_flag.h @@ -0,0 +1,50 @@ +/* $OpenBSD: boot_flag.h,v 1.8 2023/11/09 14:26:34 kn Exp $ */ +/* $NetBSD: boot_flag.h,v 1.3 2001/07/01 02:56:21 gmcgarry Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * 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 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_BOOT_FLAG_H_ +#define _MACHINE_BOOT_FLAG_H_ + +/* softraid boot information */ +#define BOOTSR_UUID_MAX 16 +#define BOOTSR_CRYPTO_MAXKEYBYTES 32 + +/* MD boot data in .openbsd.bootdata ELF segment */ +struct openbsd_bootdata { + u_int64_t version; + u_int64_t len; /* of structure */ + + u_int8_t sr_uuid[BOOTSR_UUID_MAX]; + u_int8_t sr_maskkey[BOOTSR_CRYPTO_MAXKEYBYTES]; + u_int32_t boothowto; +} __packed; + +#define BOOTDATA_VERSION 1 +#define BOOTDATA_LEN_BOOTHOWTO 68 + +#endif /* _MACHINE_BOOT_FLAG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/bppioctl.h b/lib/libc/include/sparc64-openbsd-none/sparc64/bppioctl.h new file mode 100644 index 0000000000..c424ccb474 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/bppioctl.h @@ -0,0 +1,59 @@ +/* $OpenBSD: bppioctl.h,v 1.2 2008/11/29 01:55:06 ray Exp $ */ + +/*- + * Copyright (c) 1998 Iain Hibbert + * 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 _IOCTL_ +#include +#endif + +struct bpp_param { + int bp_burst; /* chars to send/recv in one call */ + int bp_timeout; /* timeout: -1 blocking, 0 non blocking >0 ms */ + int bp_delay; /* delay between polls (ms) */ +}; + +#define BPP_BLOCK -1 +#define BPP_NOBLOCK 0 + +/* defaults */ +#define BPP_BURST 1024 +#define BPP_TIMEOUT BPP_BLOCK +#define BPP_DELAY 10 + +/* limits */ +#define BPP_BURST_MIN 1 +#define BPP_BURST_MAX 1024 +#define BPP_DELAY_MIN 0 +#define BPP_DELAY_MAX 30000 + +/* status bits */ +#define BPP_BUSY (1<<0) +#define BPP_PAPER (1<<1) + +/* ioctl commands */ +#define BPPIOCSPARAM _IOW('P', 0x1, struct bpp_param) +#define BPPIOCGPARAM _IOR('P', 0x2, struct bpp_param) +#define BPPIOCGSTAT _IOR('P', 0x4, int) \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/bus.h b/lib/libc/include/sparc64-openbsd-none/sparc64/bus.h new file mode 100644 index 0000000000..8e6f0472d3 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/bus.h @@ -0,0 +1,649 @@ +/* $OpenBSD: bus.h,v 1.38 2024/10/22 22:01:58 jsg Exp $ */ +/* $NetBSD: bus.h,v 1.31 2001/09/21 15:30:41 wiz Exp $ */ + +/*- + * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 1997-1999, 2001 Eduardo E. Horvath. All rights reserved. + * Copyright (c) 1996 Charles M. Hannum. All rights reserved. + * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christopher G. Demetriou + * for the NetBSD Project. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MACHINE_BUS_H_ +#define _MACHINE_BUS_H_ + +#include + +#ifdef _KERNEL + +/* + * Debug hooks + */ + +#define BSDB_ACCESS 0x01 +#define BSDB_MAP 0x02 +#define BSDB_ASSERT 0x04 +#define BSDB_MAPDETAIL 0x08 +#define BSDB_ALL_ACCESS 0x10 +extern int bus_space_debug; + +#define BSHDB_ACCESS 0x01 +#define BSHDB_NO_ACCESS 0x02 + +#if defined(BUS_SPACE_DEBUG) +#include +#define BUS_SPACE_PRINTF(l, s) do { \ + if(bus_space_debug & (l)) printf s; \ +} while(0) +#define BUS_SPACE_TRACE(t, h, s) do { \ + if ( (((bus_space_debug & BSDB_ALL_ACCESS) != 0) && \ + (((h).bh_flags & BSHDB_NO_ACCESS) == 0)) || \ + (((bus_space_debug & BSDB_ACCESS) != 0) && \ + (((h).bh_flags & BSHDB_ACCESS) != 0))) \ + printf s; \ + } while(0) +#define BUS_SPACE_SET_FLAGS(t, h, f) ((h).bh_flags |= (f)) +#define BUS_SPACE_CLEAR_FLAGS(t, h, f) ((h).bh_flags &= ~(f)) +#define BUS_SPACE_FLAG_DECL(s) int s +#define BUS_SPACE_SAVE_FLAGS(t, h, s) (s = (h).bh_flags) +#define BUS_SPACE_RESTORE_FLAGS(t, h, s) (s = (h).bh_flags) +#define BUS_SPACE_ASSERT(t, h, o, n) do { \ + if (bus_space_debug & BSDB_ASSERT) \ + bus_space_assert(t, &(h), o, n); \ + } while(0) +#else /* BUS_SPACE_DEBUG */ +#define BUS_SPACE_PRINTF(l, s) +#define BUS_SPACE_TRACE(t, h, s) +#define BUS_SPACE_SET_FLAGS(t, h, f) +#define BUS_SPACE_CLEAR_FLAGS(t, h, f) +#define BUS_SPACE_FLAG_DECL(s) +#define BUS_SPACE_SAVE_FLAGS(t, h, s) +#define BUS_SPACE_RESTORE_FLAGS(t, h, s) +#define BUS_SPACE_ASSERT(t, h, o, n) +#endif /* BUS_SPACE_DEBUG */ + + +/* + * UPA and SBus spaces are non-cached and big endian + * (except for RAM and PROM) + * + * PCI spaces are non-cached and little endian + */ + +enum sparc_bus_type { + UPA_BUS_SPACE, + SBUS_BUS_SPACE, + PCI_CONFIG_BUS_SPACE, + PCI_IO_BUS_SPACE, + PCI_MEMORY_BUS_SPACE, + LAST_BUS_SPACE +}; +/* For backwards compatibility */ +#define SPARC_BUS_SPACE UPA_BUS_SPACE + +/* + * Bus address and size types + */ +typedef const struct sparc_bus_space_tag *bus_space_tag_t; +typedef u_long bus_addr_t; +typedef u_long bus_size_t; + + +typedef struct _bus_space_handle { + paddr_t bh_ptr; +#ifdef BUS_SPACE_DEBUG + bus_space_tag_t bh_tag; + bus_size_t bh_size; + int bh_flags; +#endif +} bus_space_handle_t; + +/* For buses which have an iospace. */ +#define BUS_ADDR_IOSPACE(x) ((x)>>32) +#define BUS_ADDR_PADDR(x) ((x)&0xffffffff) +#define BUS_ADDR(io, pa) ((((bus_addr_t)io)<<32)|(pa)) + +/* + * Access methods for bus resources and address space. + */ + +struct sparc_bus_space_tag { + void *cookie; + bus_space_tag_t parent; + enum sparc_bus_type default_type; + u_int8_t asi; + u_int8_t sasi; + char name[32]; + + int (*sparc_bus_alloc)(bus_space_tag_t, + bus_space_tag_t, + bus_addr_t, bus_addr_t, + bus_size_t, bus_size_t, bus_size_t, + int, bus_addr_t *, bus_space_handle_t *); + + void (*sparc_bus_free)(bus_space_tag_t, + bus_space_tag_t, + bus_space_handle_t, bus_size_t); + + int (*sparc_bus_map)(bus_space_tag_t, + bus_space_tag_t, + bus_addr_t, bus_size_t, + int, bus_space_handle_t *); + + int (*sparc_bus_protect)(bus_space_tag_t, + bus_space_tag_t, + bus_space_handle_t, bus_size_t, int); + + int (*sparc_bus_unmap)(bus_space_tag_t, + bus_space_tag_t, + bus_space_handle_t, bus_size_t); + + int (*sparc_bus_subregion)(bus_space_tag_t, + bus_space_tag_t, + bus_space_handle_t, bus_size_t, + bus_size_t, bus_space_handle_t *); + + paddr_t (*sparc_bus_mmap)(bus_space_tag_t, + bus_space_tag_t, + bus_addr_t, off_t, int, int); + + void *(*sparc_intr_establish)(bus_space_tag_t, + bus_space_tag_t, + int, int, int, + int (*)(void *), void *, + const char *); + void *(*sparc_intr_establish_cpu)(bus_space_tag_t, + bus_space_tag_t, + int, int, int, + struct cpu_info *, + int (*)(void *), void *, + const char *); + + bus_addr_t (*sparc_bus_addr)(bus_space_tag_t, + bus_space_tag_t, bus_space_handle_t); +}; + +/* + * Bus space function prototypes. + */ +int bus_space_alloc( + bus_space_tag_t, + bus_addr_t, /* reg start */ + bus_addr_t, /* reg end */ + bus_size_t, /* size */ + bus_size_t, /* alignment */ + bus_size_t, /* boundary */ + int, /* flags */ + bus_addr_t *, + bus_space_handle_t *); +void bus_space_free( + bus_space_tag_t, + bus_space_handle_t, + bus_size_t); +int bus_space_map( + bus_space_tag_t, + bus_addr_t, + bus_size_t, + int, /*flags*/ + bus_space_handle_t *); +int bus_space_protect( + bus_space_tag_t, + bus_space_handle_t, + bus_size_t, + int); /*flags*/ +int bus_space_unmap( + bus_space_tag_t, + bus_space_handle_t, + bus_size_t); +int bus_space_subregion( + bus_space_tag_t, + bus_space_handle_t, + bus_size_t, + bus_size_t, + bus_space_handle_t *); +static void bus_space_barrier( + bus_space_tag_t, + bus_space_handle_t, + bus_size_t, + bus_size_t, + int); +paddr_t bus_space_mmap( + bus_space_tag_t, + bus_addr_t, /*addr*/ + off_t, /*offset*/ + int, /*prot*/ + int); /*flags*/ +void *bus_intr_establish( + bus_space_tag_t, + int, /*bus-specific intr*/ + int, /*device class level, + see machine/intr.h*/ + int, /*flags*/ + int (*)(void *), /*handler*/ + void *, /*handler arg*/ + const char *); /*what*/ +void *bus_intr_establish_cpu( + bus_space_tag_t, + int, /*bus-specific intr*/ + int, /*device class level, + see machine/intr.h*/ + int, /*flags*/ + struct cpu_info *, /*cpu*/ + int (*)(void *), /*handler*/ + void *, /*handler arg*/ + const char *); /*what*/ +void *bus_intr_allocate( + bus_space_tag_t, + int (*)(void *), /*handler*/ + void *, /*handler arg*/ + int, /*number*/ + int, /*pil*/ + volatile u_int64_t *, /*map*/ + volatile u_int64_t *, /*clr*/ + const char *); /*what*/ +void bus_intr_free(void *); +void bus_space_render_tag( + bus_space_tag_t, + char *, + size_t); +void *bus_space_vaddr( + bus_space_tag_t, + bus_space_handle_t); + +#ifdef BUS_SPACE_DEBUG +void bus_space_assert(bus_space_tag_t, + const bus_space_handle_t *, + bus_size_t, int); +void bus_space_render_tag(bus_space_tag_t, char*, size_t); +#endif /* BUS_SPACE_DEBUG */ + + +#define _BS_PRECALL(t,f) \ + while (t->f == NULL) \ + t = t->parent; +#define _BS_POSTCALL + +#define _BS_CALL(t,f) \ + (*(t)->f) + +/* flags for bus_space_barrier() */ +#define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */ +#define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */ + +static inline void +bus_space_barrier(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, + bus_size_t s, int f) +{ +#ifdef notyet + switch (f) { + case (BUS_SPACE_BARRIER_READ|BUS_SPACE_BARRIER_WRITE): + __membar("#LoadLoad|#StoreStore"); + break; + case BUS_SPACE_BARRIER_READ: + membar("#LoadLoad"); + break; + case BUS_SPACE_BARRIER_WRITE: + membar("#StoreStore"); + break; + default: + break; + } +#else + __membar("#Sync"); +#endif +} + +#include + +/* flags for bus space map functions */ +#define BUS_SPACE_MAP_CACHEABLE 0x0001 +#define BUS_SPACE_MAP_LINEAR 0x0002 +#define BUS_SPACE_MAP_READONLY 0x0004 +#define BUS_SPACE_MAP_PREFETCHABLE 0x0008 +#define BUS_SPACE_MAP_PROMADDRESS 0x0010 +#define BUS_SPACE_MAP_BUS1 0x0100 /* placeholders for bus functions... */ +#define BUS_SPACE_MAP_BUS2 0x0200 +#define BUS_SPACE_MAP_BUS3 0x0400 +#define BUS_SPACE_MAP_BUS4 0x0800 + + +/* flags for bus_intr_establish() */ +#define BUS_INTR_ESTABLISH_MPSAFE 0x0001 +#define BUS_INTR_ESTABLISH_SOFTINTR 0x0002 + +/* + * Flags used in various bus DMA methods. + */ +#define BUS_DMA_WAITOK 0x0000 /* safe to sleep (pseudo-flag) */ +#define BUS_DMA_NOWAIT 0x0001 /* not safe to sleep */ +#define BUS_DMA_ALLOCNOW 0x0002 /* perform resource allocation now */ +#define BUS_DMA_COHERENT 0x0004 /* hint: map memory DMA coherent */ +#define BUS_DMA_NOWRITE 0x0008 /* I suppose the following two should default on */ +#define BUS_DMA_BUS1 0x0010 /* placeholders for bus functions... */ +#define BUS_DMA_BUS2 0x0020 +#define BUS_DMA_BUS3 0x0040 +#define BUS_DMA_BUS4 0x0080 +#define BUS_DMA_STREAMING 0x0100 /* hint: sequential, unidirectional */ +#define BUS_DMA_READ 0x0200 /* mapping is device -> memory only */ +#define BUS_DMA_WRITE 0x0400 /* mapping is memory -> device only */ +#define BUS_DMA_ZERO 0x0800 /* zero memory in dmamem_alloc */ +#define BUS_DMA_OVERRUN 0x1000 /* tolerate DMA overruns */ +#define BUS_DMA_64BIT 0x2000 /* device handles 64bit dva */ + +#define BUS_DMA_NOCACHE BUS_DMA_BUS1 +#define BUS_DMA_DVMA BUS_DMA_BUS2 /* Don't bother with alignment */ +#define BUS_DMA_24BIT BUS_DMA_BUS3 /* 24bit device */ + +#define BUS_DMA_RAW BUS_DMA_STREAMING + +/* Forwards needed by prototypes below. */ +struct mbuf; +struct uio; + +/* + * Operations performed by bus_dmamap_sync(). + */ +#define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */ +#define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */ +#define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */ +#define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */ + +typedef struct sparc_bus_dma_tag *bus_dma_tag_t; +typedef struct sparc_bus_dmamap *bus_dmamap_t; + +/* + * bus_dma_segment_t + * + * Describes a single contiguous DMA transaction. Values + * are suitable for programming into DMA registers. + */ +struct sparc_bus_dma_segment { + bus_addr_t ds_addr; /* DVMA address */ + bus_size_t ds_len; /* length of transfer */ + /* + * The following is to support bus_dmamem_alloc()'s + * odd interface. Only the values in the first + * segment are used. This means that 3/5ths of + * most segments are useless space (and mbufs use 1024 + * segments). + */ + bus_size_t _ds_boundary; /* don't cross this */ + bus_size_t _ds_align; /* align to this */ + void *_ds_mlist; /* XXX - dmamap_alloc'ed pages */ +}; +typedef struct sparc_bus_dma_segment bus_dma_segment_t; + + +/* + * bus_dma_tag_t + * + * A machine-dependent opaque type describing the implementation of + * DMA for a given bus. + */ +struct sparc_bus_dma_tag { + void *_cookie; /* cookie used in the guts */ + struct sparc_bus_dma_tag* _parent; + + /* + * DMA mapping methods. + */ + int (*_dmamap_create)(bus_dma_tag_t, bus_dma_tag_t, bus_size_t, + int, bus_size_t, bus_size_t, int, bus_dmamap_t *); + void (*_dmamap_destroy)(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t); + int (*_dmamap_load)(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t, + void *, bus_size_t, struct proc *, int); + int (*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dma_tag_t, + bus_dmamap_t, struct mbuf *, int); + int (*_dmamap_load_uio)(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t, + struct uio *, int); + int (*_dmamap_load_raw)(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); + void (*_dmamap_unload)(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t); + void (*_dmamap_sync)(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t, + bus_addr_t, bus_size_t, int); + + /* + * DMA memory utility functions. + */ + int (*_dmamem_alloc)(bus_dma_tag_t, bus_dma_tag_t, bus_size_t, + bus_size_t, bus_size_t, bus_dma_segment_t *, int, int *, + int); + void (*_dmamem_free)(bus_dma_tag_t, bus_dma_tag_t, + bus_dma_segment_t *, int); + int (*_dmamem_map)(bus_dma_tag_t, bus_dma_tag_t, + bus_dma_segment_t *, int, size_t, caddr_t *, int); + void (*_dmamem_unmap)(bus_dma_tag_t, bus_dma_tag_t, caddr_t, + size_t); + paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_tag_t, + bus_dma_segment_t *, int, off_t, int, int); +}; + +#define _BD_PRECALL(t,f) \ + while (t->f == NULL) { \ + t = t->_parent; \ + } +#define _BD_CALL(t,f) \ + (*(t)->f) +#define _BD_POSTCALL + +static inline int +bus_dmamap_create(bus_dma_tag_t t, bus_size_t s, int n, bus_size_t m, + bus_size_t b, int f, bus_dmamap_t *p) +{ + int r; + const bus_dma_tag_t t0 = t; + _BD_PRECALL(t, _dmamap_create); + r = _BD_CALL(t, _dmamap_create)(t, t0, s, n, m, b, f, p); + _BD_POSTCALL; + return (r); +} +static inline void +bus_dmamap_destroy(bus_dma_tag_t t, bus_dmamap_t p) +{ + const bus_dma_tag_t t0 = t; + _BD_PRECALL(t, _dmamap_destroy); + _BD_CALL(t, _dmamap_destroy)(t, t0, p); + _BD_POSTCALL; +} +static inline int +bus_dmamap_load(bus_dma_tag_t t, bus_dmamap_t m, void *b, bus_size_t s, + struct proc *p, int f) +{ + const bus_dma_tag_t t0 = t; + int r; + _BD_PRECALL(t, _dmamap_load); + r = _BD_CALL(t, _dmamap_load)(t, t0, m, b, s, p, f); + _BD_POSTCALL; + return (r); +} +static inline int +bus_dmamap_load_mbuf(bus_dma_tag_t t, bus_dmamap_t m, struct mbuf *b, + int f) +{ + const bus_dma_tag_t t0 = t; + int r; + _BD_PRECALL(t, _dmamap_load_mbuf); + r = _BD_CALL(t, _dmamap_load_mbuf)(t, t0, m, b, f); + _BD_POSTCALL; + return (r); +} +static inline int +bus_dmamap_load_uio(bus_dma_tag_t t, bus_dmamap_t m, struct uio * u, int f) +{ + const bus_dma_tag_t t0 = t; + int r; + _BD_PRECALL(t, _dmamap_load_uio); + r = _BD_CALL(t, _dmamap_load_uio)(t, t0, m, u, f); + _BD_POSTCALL; + return (r); +} +static inline int +bus_dmamap_load_raw(bus_dma_tag_t t, bus_dmamap_t m, bus_dma_segment_t *sg, + int n, bus_size_t s, int f) +{ + const bus_dma_tag_t t0 = t; + int r; + _BD_PRECALL(t, _dmamap_load_raw); + r = _BD_CALL(t, _dmamap_load_raw)(t, t0, m, sg, n, s, f); + _BD_POSTCALL; + return (r); +} +static inline void +bus_dmamap_unload(bus_dma_tag_t t, bus_dmamap_t p) +{ + const bus_dma_tag_t t0 = t; + _BD_PRECALL(t, _dmamap_unload); + _BD_CALL(t, _dmamap_unload)(t, t0, p); + _BD_POSTCALL; +} +static inline void +bus_dmamap_sync(bus_dma_tag_t t, bus_dmamap_t p, bus_addr_t o, bus_size_t l, + int ops) +{ + const bus_dma_tag_t t0 = t; + _BD_PRECALL(t, _dmamap_sync); + _BD_CALL(t, _dmamap_sync)(t, t0, p, o, l, ops); + _BD_POSTCALL; +} +static inline int +bus_dmamem_alloc(bus_dma_tag_t t, bus_size_t s, bus_size_t a, bus_size_t b, + bus_dma_segment_t *sg, int n, int *r, int f) +{ + const bus_dma_tag_t t0 = t; + int ret; + _BD_PRECALL(t, _dmamem_alloc); + ret = _BD_CALL(t, _dmamem_alloc)(t, t0, s, a, b, sg, n, r, f); + _BD_POSTCALL; + return (ret); +} +static inline void +bus_dmamem_free(bus_dma_tag_t t, bus_dma_segment_t *sg, int n) +{ + const bus_dma_tag_t t0 = t; + _BD_PRECALL(t, _dmamem_free); + _BD_CALL(t, _dmamem_free)(t, t0, sg, n); + _BD_POSTCALL; +} +static inline int +bus_dmamem_map(bus_dma_tag_t t, bus_dma_segment_t *sg, int n, size_t s, + caddr_t *k, int f) +{ + const bus_dma_tag_t t0 = t; + int r; + _BD_PRECALL(t, _dmamem_map); + r = _BD_CALL(t, _dmamem_map)(t, t0, sg, n, s, k, f); + _BD_POSTCALL; + return (r); +} +static inline void +bus_dmamem_unmap(bus_dma_tag_t t, caddr_t k, size_t s) +{ + const bus_dma_tag_t t0 = t; + _BD_PRECALL(t, _dmamem_unmap); + _BD_CALL(t, _dmamem_unmap)(t, t0, k, s); + _BD_POSTCALL; +} +static inline paddr_t +bus_dmamem_mmap(bus_dma_tag_t t, bus_dma_segment_t *sg, int n, off_t o, int p, + int f) +{ + const bus_dma_tag_t t0 = t; + int r; + _BD_PRECALL(t, _dmamem_mmap); + r = _BD_CALL(t, _dmamem_mmap)(t, t0, sg, n, o, p, f); + _BD_POSTCALL; + return (r); +} + +/* + * bus_dmamap_t + * + * Describes a DMA mapping. + */ +struct sparc_bus_dmamap { + /* + * PRIVATE MEMBERS: not for use by machine-independent code. + */ + bus_addr_t _dm_dvmastart; /* start and size of allocated */ + bus_size_t _dm_dvmasize; /* DVMA segment for this map */ + + bus_size_t _dm_size; /* largest DMA transfer mappable */ + bus_size_t _dm_maxsegsz; /* largest possible segment */ + bus_size_t _dm_boundary; /* don't cross this */ + int _dm_segcnt; /* number of segs this map can map */ + int _dm_flags; /* misc. flags */ +#define _DM_TYPE_LOAD 0 +#define _DM_TYPE_SEGS 1 +#define _DM_TYPE_UIO 2 +#define _DM_TYPE_MBUF 3 + int _dm_type; /* mapping type: raw, uio, mbuf, etc */ + void *_dm_source; /* source mbuf/uio/etc. for unload */ + + void *_dm_cookie; /* cookie for bus-specific functions */ + + /* + * PUBLIC MEMBERS: these are used by machine-independent code. + */ + bus_size_t dm_mapsize; /* size of the mapping */ + int dm_nsegs; /* # valid segments in mapping */ + + bus_dma_segment_t dm_segs[1]; /* segments; variable length */ +}; + +#endif /* _KERNEL */ + +#endif /* _MACHINE_BUS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/cdefs.h b/lib/libc/include/sparc64-openbsd-none/sparc64/cdefs.h new file mode 100644 index 0000000000..26521d2433 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/cdefs.h @@ -0,0 +1,16 @@ +/* $OpenBSD: cdefs.h,v 1.4 2013/03/28 17:30:45 martynas Exp $ */ + +#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_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/conf.h b/lib/libc/include/sparc64-openbsd-none/sparc64/conf.h new file mode 100644 index 0000000000..dd9ef3a150 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/conf.h @@ -0,0 +1,101 @@ +/* $OpenBSD: conf.h,v 1.28 2024/03/29 21:06:14 miod Exp $ */ +/* $NetBSD: conf.h,v 1.9 2001/03/26 12:33:26 lukem Exp $ */ + +/*- + * Copyright (c) 1996 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * 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. + */ + +#define mmread mmrw +#define mmwrite mmrw +cdev_decl(mm); + +cdev_decl(openprom); + +/* open, close, ioctl */ +#define cdev_openprom_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) nullop, 0, \ + (dev_type_mmap((*))) enodev } + +cdev_decl(uperf); + +/* open, close, ioctl */ +#define cdev_uperf_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) nullop, 0, \ + (dev_type_mmap((*))) enodev } + +cdev_decl(vdsp); + +/* open, close, ioctl */ +#define cdev_vdsp_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) nullop, 0, \ + (dev_type_mmap((*))) enodev } + +#define cdev_gen_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) nullop, \ + 0, (dev_type_mmap((*))) enodev, \ + 0, 0, dev_init(c,n,kqfilter) } + +cdev_decl(zs); + +bdev_decl(fd); +cdev_decl(fd); + +cdev_decl(bpp); +cdev_decl(lpt); + +bdev_decl(wd); +cdev_decl(wd); + +cdev_decl(sabtty); + +cdev_decl(pcons); +cdev_decl(vcons); +cdev_decl(vcctty); +cdev_decl(sbbc); + +cdev_decl(vldcp); + +cdev_decl(com); + +cdev_decl(mtty); +cdev_decl(mbpp); +cdev_decl(stty); +cdev_decl(sbpp); + +/* open, close, write, ioctl */ +#define cdev_bpp_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) nullop, \ + 0, (dev_type_mmap((*))) enodev, 0, 0, seltrue_kqfilter } \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/cpu.h b/lib/libc/include/sparc64-openbsd-none/sparc64/cpu.h new file mode 100644 index 0000000000..e5535fb382 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/cpu.h @@ -0,0 +1,384 @@ +/* $OpenBSD: cpu.h,v 1.109 2024/11/06 12:06:15 miod Exp $ */ +/* $NetBSD: cpu.h,v 1.28 2001/06/14 22:56:58 thorpej Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)cpu.h 8.4 (Berkeley) 1/5/94 + */ + +#ifndef _MACHINE_CPU_H_ +#define _MACHINE_CPU_H_ + +/* + * CTL_MACHDEP definitions. + */ + /* 1 formerly: booted kernel name */ +#define CPU_LED_BLINK 2 /* int: blink leds? */ +#define CPU_ALLOWAPERTURE 3 /* allow xf86 operations */ +#define CPU_CPUTYPE 4 /* cpu type */ +#define CPU_CECCERRORS 5 /* Correctable ECC errors */ +#define CPU_CECCLAST 6 /* Correctable ECC last fault addr */ + /* 7 formerly: soft reset via keyboard */ +#define CPU_MAXID 8 /* number of valid machdep ids */ + +#define CTL_MACHDEP_NAMES { \ + { 0, 0 }, \ + { 0, 0 }, \ + { "led_blink", CTLTYPE_INT }, \ + { "allowaperture", CTLTYPE_INT }, \ + { "cputype", CTLTYPE_INT }, \ + { "ceccerrs", CTLTYPE_INT }, \ + { "cecclast", CTLTYPE_QUAD }, \ + { 0, 0 }, \ +} + +#ifdef _KERNEL +/* + * Exported definitions unique to SPARC cpu support. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +/* + * The cpu_info structure is part of a 64KB structure mapped both the kernel + * pmap and a single locked TTE a CPUINFO_VA for that particular processor. + * Each processor's cpu_info is accessible at CPUINFO_VA only for that + * processor. Other processors can access that through an additional mapping + * in the kernel pmap. + * + * The 64KB page contains: + * + * cpu_info + * interrupt stack (all remaining space) + * idle PCB + * idle stack (STACKSPACE - sizeof(PCB)) + * 32KB TSB + */ + +struct cpu_info { + /* + * SPARC cpu_info structures live at two VAs: one global + * VA (so each CPU can access any other CPU's cpu_info) + * and an alias VA CPUINFO_VA which is the same on each + * CPU and maps to that CPU's cpu_info. Since the alias + * CPUINFO_VA is how we locate our cpu_info, we have to + * self-reference the global VA so that we can return it + * in the curcpu() macro. + */ + struct cpu_info * volatile ci_self; + + /* Most important fields first */ + struct proc *ci_curproc; + struct pcb *ci_cpcb; /* also initial stack */ + paddr_t ci_cpcbpaddr; + struct cpu_info *ci_next; + + struct proc *ci_fpproc; + int ci_cpuid; + int ci_flags; + int ci_upaid; +#ifdef MULTIPROCESSOR + int ci_itid; + struct srp_hazard ci_srp_hazards[SRP_HAZARD_NUM]; +#define __HAVE_UVM_PERCPU + struct uvm_pmr_cache ci_uvm; /* [o] page cache */ +#endif + int ci_node; + u_int32_t ci_randseed; + struct schedstate_percpu ci_schedstate; /* scheduler state */ + + int ci_want_resched; + int ci_handled_intr_level; + int ci_idepth; + struct intrhand *ci_intrpending[16]; + struct clockqueue ci_queue; + struct intrhand ci_tickintr; + + volatile int ci_ddb_paused; +#define CI_DDB_RUNNING 0 +#define CI_DDB_SHOULDSTOP 1 +#define CI_DDB_STOPPED 2 +#define CI_DDB_ENTERDDB 3 +#define CI_DDB_INDDB 4 + + /* Spinning up the CPU */ + void (*ci_spinup)(void); /* spinup routine */ + void *ci_initstack; + paddr_t ci_paddr; /* Phys addr of this structure. */ + +#ifdef SUN4V + struct rwindow ci_rw; + u_int64_t ci_rwsp; + + paddr_t ci_mmfsa; + paddr_t ci_cpumq; + paddr_t ci_devmq; + + paddr_t ci_cpuset; + paddr_t ci_mondo; +#endif + + int ci_pci_probe; + int ci_pci_fault; + +#ifdef DIAGNOSTIC + int ci_mutex_level; +#endif +#ifdef GPROF + struct gmonparam *ci_gmon; + struct clockintr ci_gmonclock; +#endif + char ci_panicbuf[512]; +}; + +#define CPUF_RUNNING 0x0001 /* CPU is running */ + +extern struct cpu_info *cpus; + +#ifdef MULTIPROCESSOR + +register struct cpu_info *__curcpu asm ("g7"); + +#define curcpu() (__curcpu->ci_self) +#define cpu_number() (__curcpu->ci_cpuid) + +#define CPU_IS_PRIMARY(ci) ((ci)->ci_cpuid == 0) +#define CPU_IS_RUNNING(ci) 1 +#define CPU_INFO_ITERATOR int +#define CPU_INFO_FOREACH(cii, ci) \ + for (cii = 0, ci = cpus; ci != NULL; ci = ci->ci_next) +#define CPU_INFO_UNIT(ci) ((ci)->ci_cpuid) +#define MAXCPUS 256 + +void cpu_boot_secondary_processors(void); + +void sparc64_send_ipi(int, void (*)(void), u_int64_t, u_int64_t); +void sparc64_broadcast_ipi(void (*)(void), u_int64_t, u_int64_t); + +void cpu_unidle(struct cpu_info *); + +#else /* MULTIPROCESSOR */ + +#define __curcpu ((struct cpu_info *)CPUINFO_VA) +#define curcpu() __curcpu +#define cpu_number() 0 + +#define CPU_IS_PRIMARY(ci) 1 +#define CPU_IS_RUNNING(ci) 1 +#define CPU_INFO_ITERATOR int +#define CPU_INFO_FOREACH(cii, ci) \ + for (cii = 0, ci = curcpu(); ci != NULL; ci = NULL) +#define CPU_INFO_UNIT(ci) 0 +#define MAXCPUS 1 + +#define cpu_unidle(ci) + +#endif /* MULTIPROCESSOR */ + +#define curpcb __curcpu->ci_cpcb +#define fpproc __curcpu->ci_fpproc + +static inline unsigned int +cpu_rnd_messybits(void) +{ + u_int64_t tick; + + __asm volatile("rd %%tick, %0" : "=r" (tick) :); + + return ((tick >> 32) ^ tick); +} + +/* + * On processors with multiple threads we force a thread switch. + * + * On UltraSPARC T2 and its successors, the optimal way to do this + * seems to be to do three nop reads of %ccr. This works on + * UltraSPARC T1 as well, even though three nop casx operations seem + * to be slightly more optimal. Since these instructions are + * effectively nops, executing them on earlier non-CMT processors is + * harmless, so we make this the default. + * + * On SPARC T4 and later, we can use the processor-specific pause + * instruction. + * + * On SPARC64 VI and its successors we execute the processor-specific + * sleep instruction. + */ +#define CPU_BUSY_CYCLE() \ +do { \ + __asm volatile( \ + "999: rd %%ccr, %%g0 \n" \ + " rd %%ccr, %%g0 \n" \ + " rd %%ccr, %%g0 \n" \ + " .section .sun4v_pause_patch, \"ax\" \n" \ + " .word 999b \n" \ + " .word 0xb7802080 ! pause 128 \n" \ + " .word 999b + 4 \n" \ + " nop \n" \ + " .word 999b + 8 \n" \ + " nop \n" \ + " .previous \n" \ + " .section .sun4u_mtp_patch, \"ax\" \n" \ + " .word 999b \n" \ + " .word 0x81b01060 ! sleep \n" \ + " .word 999b + 4 \n" \ + " nop \n" \ + " .word 999b + 8 \n" \ + " nop \n" \ + " .previous \n" \ + : : : "memory"); \ +} while (0) + +/* + * Arguments to clockintr_dispatch encapsulate the + * previous machine state in an opaque clockframe. + */ +struct clockframe { + struct trapframe t; + int saved_intr_level; +}; + +#define CLKF_USERMODE(framep) (((framep)->t.tf_tstate & TSTATE_PRIV) == 0) +#define CLKF_PC(framep) ((framep)->t.tf_pc) +#define CLKF_INTR(framep) ((framep)->saved_intr_level != 0) + +extern void (*cpu_start_clock)(void); + +#define aston(p) ((p)->p_md.md_astpending = 1) + +/* + * Preempt the current process if in interrupt from user mode, + * or after the current trap/syscall if in system mode. + */ +extern void need_resched(struct cpu_info *); +#define clear_resched(ci) (ci)->ci_want_resched = 0 + +/* + * This is used during profiling to integrate system time. + */ +#define PROC_PC(p) ((p)->p_md.md_tf->tf_pc) +#define PROC_STACK(p) ((p)->p_md.md_tf->tf_out[6] + (2048-1)) /* BIAS */ + +/* + * Give a profiling tick to the current process when the user profiling + * buffer pages are invalid. On the sparc, request an ast to send us + * through trap(), marking the proc as needing a profiling tick. + */ +#define need_proftick(p) aston(p) + +void signotify(struct proc *); + +/* cpu.c */ +int cpu_myid(void); +/* machdep.c */ +void dumpconf(void); +caddr_t reserve_dumppages(caddr_t); +/* clock.c */ +struct timeval; +int clockintr(void *);/* level 10 (clock) interrupt code */ +/* locore.s */ +struct fpstate; +void savefpstate(struct fpstate *); +void loadfpstate(struct fpstate *); +void clearfpstate(void); +u_int64_t probeget(paddr_t, int, int); +#define write_all_windows() __asm volatile("flushw" : : ) +void write_user_windows(void); +void proc_trampoline(void); +struct pcb; +void snapshot(struct pcb *); +struct frame *getfp(void); +void switchtoctx(int); +/* trap.c */ +void pmap_unuse_final(struct proc *); +int rwindow_save(struct proc *); +/* vm_machdep.c */ +void fpusave_cpu(struct cpu_info *, int); +void fpusave_proc(struct proc *, int); +/* fb.c */ +void fb_unblank(void); +/* ltc.c */ +void ltc_full_blast(void); +/* tda.c */ +void tda_full_blast(void); +/* emul.c */ +int emul_qf(int32_t, struct proc *, union sigval, struct trapframe *); +int emul_popc(int32_t, struct proc *, union sigval, struct trapframe *); + +/* + * + * The SPARC has a Trap Base Register (TBR) which holds the upper 20 bits + * of the trap vector table. The next eight bits are supplied by the + * hardware when the trap occurs, and the bottom four bits are always + * zero (so that we can shove up to 16 bytes of executable code---exactly + * four instructions---into each trap vector). + * + * The hardware allocates half the trap vectors to hardware and half to + * software. + * + * Traps have priorities assigned (lower number => higher priority). + */ + +struct trapvec { + int tv_instr[8]; /* the eight instructions */ +}; +extern struct trapvec trapbase[]; /* the 256 vectors */ + +struct blink_led { + void (*bl_func)(void *, int); + void *bl_arg; + SLIST_ENTRY(blink_led) bl_next; +}; + +extern void blink_led_register(struct blink_led *); + +#ifdef MULTIPROCESSOR +#include +#endif + +#endif /* _KERNEL */ +#endif /* _MACHINE_CPU_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/ctlreg.h b/lib/libc/include/sparc64-openbsd-none/sparc64/ctlreg.h new file mode 100644 index 0000000000..6120cae56e --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/ctlreg.h @@ -0,0 +1,715 @@ +/* $OpenBSD: ctlreg.h,v 1.33 2025/07/16 07:15:42 jsg Exp $ */ +/* $NetBSD: ctlreg.h,v 1.28 2001/08/06 23:55:34 eeh Exp $ */ + +/* + * Copyright (c) 1996-2001 Eduardo Horvath + * + * 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. + * + * 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. + * + */ +/* + * Copyright (c) 2001 Jake Burkholder. + * 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 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 AUTHOR 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 _SPARC64_CTLREG_ +#define _SPARC64_CTLREG_ + +/* + * Sun 4u control registers. (includes address space definitions + * and some registers in control space). + */ + +/* + * The Alternate address spaces. + * + * 0x00-0x7f are privileged + * 0x80-0xff can be used by users + */ + +#define ASI_LITTLE 0x08 /* This bit should make an ASI little endian */ + +#define ASI_NUCLEUS 0x04 /* [4u] kernel address space */ +#define ASI_NUCLEUS_LITTLE 0x0c /* [4u] kernel address space, little endian */ + +#define ASI_AS_IF_USER_PRIMARY 0x10 /* [4u] primary user address space */ +#define ASI_AS_IF_USER_SECONDARY 0x11 /* [4u] secondary user address space */ + +#define ASI_PHYS_CACHED 0x14 /* [4u] MMU bypass to main memory */ +#define ASI_PHYS_NON_CACHED 0x15 /* [4u] MMU bypass to I/O location */ + +#define ASI_AS_IF_USER_PRIMARY_LITTLE 0x18 /* [4u] primary user address space, little endian */ +#define ASI_AS_IF_USER_SECONDARY_LITTIE 0x19 /* [4u] secondary user address space, little endian */ + +#define ASI_PHYS_CACHED_LITTLE 0x1c /* [4u] MMU bypass to main memory, little endian */ +#define ASI_PHYS_NON_CACHED_LITTLE 0x1d /* [4u] MMU bypass to I/O location, little endian */ + +#define ASI_SCRATCHPAD 0x20 /* [4v] scratchpad registers */ +#define ASI_MMU_CONTEXTID 0x21 /* [4v] MMU context */ + +#define ASI_NUCLEUS_QUAD_LDD 0x24 /* [4u] use w/LDDA to load 128-bit item */ +#define ASI_QUEUE 0x25 /* [4v] interrupt queue registers */ +#define ASI_NUCLEUS_QUAD_LDD_LITTLE 0x2c /* [4u] use w/LDDA to load 128-bit item, little endian */ + +#define ASI_FLUSH_D_PAGE_PRIMARY 0x38 /* [4u] flush D-cache page using primary context */ +#define ASI_FLUSH_D_PAGE_SECONDARY 0x39 /* [4u] flush D-cache page using secondary context */ +#define ASI_FLUSH_D_CTX_PRIMARY 0x3a /* [4u] flush D-cache context using primary context */ +#define ASI_FLUSH_D_CTX_SECONDARY 0x3b /* [4u] flush D-cache context using secondary context */ + +#define ASI_DCACHE_INVALIDATE 0x42 /* [III] invalidate D-cache */ +#define ASI_DCACHE_UTAG 0x43 /* [III] diagnostic access to D-cache micro tag */ +#define ASI_DCACHE_SNOOP_TAG 0x44 /* [III] diagnostic access to D-cache snoop tag RAM */ + +#define ASI_LSU_CONTROL_REGISTER 0x45 /* [4u] load/store unit control register */ + +#define ASI_DCACHE_DATA 0x46 /* [4u] diagnostic access to D-cache data RAM */ +#define ASI_DCACHE_TAG 0x47 /* [4u] diagnostic access to D-cache tag RAM */ + +#define ASI_INTR_DISPATCH_STATUS 0x48 /* [4u] interrupt dispatch status register */ +#define ASI_INTR_RECEIVE 0x49 /* [4u] interrupt receive status register */ +#define ASI_MID_REG 0x4a /* [4u] hardware config and MID */ +#define ASI_ERROR_EN_REG 0x4b /* [4u] asynchronous error enables */ +#define ASI_AFSR 0x4c /* [4u] asynchronous fault status register */ +#define ASI_AFAR 0x4d /* [4u] asynchronous fault address register */ + +#define ASI_SCRATCH 0x4f /* [VI] scratch registers */ + +#define ASI_ICACHE_DATA 0x66 /* [4u] diagnostic access to D-cache data RAM */ +#define ASI_ICACHE_TAG 0x67 /* [4u] diagnostic access to D-cache tag RAM */ +#define ASI_FLUSH_I_PAGE_PRIMARY 0x68 /* [4u] flush D-cache page using primary context */ +#define ASI_FLUSH_I_PAGE_SECONDARY 0x69 /* [4u] flush D-cache page using secondary context */ +#define ASI_FLUSH_I_CTX_PRIMARY 0x6a /* [4u] flush D-cache context using primary context */ +#define ASI_FLUSH_I_CTX_SECONDARY 0x6b /* [4u] flush D-cache context using secondary context */ + +#define ASI_BLOCK_AS_IF_USER_PRIMARY 0x70 /* [4u] primary user address space, block loads/stores */ +#define ASI_BLOCK_AS_IF_USER_SECONDARY 0x71 /* [4u] secondary user address space, block loads/stores */ + +#define ASI_ECACHE_DIAG 0x76 /* [4u] diag access to E-cache tag and data */ +#define ASI_DATAPATH_ERR_REG_WRITE 0x77 /* [4u] ASI is reused */ + +#define ASI_BLOCK_AS_IF_USER_PRIMARY_LITTLE 0x78 /* [4u] primary user address space, block loads/stores */ +#define ASI_BLOCK_AS_IF_USER_SECONDARY_LITTLE 0x79 /* [4u] secondary user address space, block loads/stores */ + +#define ASI_INTERRUPT_RECEIVE_DATA 0x7f /* [4u] interrupt receive data registers {0,1,2} */ +#define ASI_DATAPATH_ERR_REG_READ 0x7f /* [4u] read access to datapath error registers (ASI reused) */ + +#define ASI_PRIMARY 0x80 /* [4u] primary address space */ +#define ASI_SECONDARY 0x81 /* [4u] secondary address space */ +#define ASI_PRIMARY_NOFAULT 0x82 /* [4u] primary address space, no fault */ +#define ASI_SECONDARY_NOFAULT 0x83 /* [4u] secondary address space, no fault */ + +#define ASI_PRIMARY_LITTLE 0x88 /* [4u] primary address space, little endian */ +#define ASI_SECONDARY_LITTLE 0x89 /* [4u] secondary address space, little endian */ +#define ASI_PRIMARY_NOFAULT_LITTLE 0x8a /* [4u] primary address space, no fault, little endian */ +#define ASI_SECONDARY_NOFAULT_LITTLE 0x8b /* [4u] secondary address space, no fault, little endian */ + +#define ASI_PST8_PRIMARY 0xc0 /* [VIS] Eight 8-bit partial store, primary */ +#define ASI_PST8_SECONDARY 0xc1 /* [VIS] Eight 8-bit partial store, secondary */ +#define ASI_PST16_PRIMARY 0xc2 /* [VIS] Four 16-bit partial store, primary */ +#define ASI_PST16_SECONDARY 0xc3 /* [VIS] Fout 16-bit partial store, secondary */ +#define ASI_PST32_PRIMARY 0xc4 /* [VIS] Two 32-bit partial store, primary */ +#define ASI_PST32_SECONDARY 0xc5 /* [VIS] Two 32-bit partial store, secondary */ + +#define ASI_PST8_PRIMARY_LITTLE 0xc8 /* [VIS] Eight 8-bit partial store, primary, little endian */ +#define ASI_PST8_SECONDARY_LITTLE 0xc9 /* [VIS] Eight 8-bit partial store, secondary, little endian */ +#define ASI_PST16_PRIMARY_LITTLE 0xca /* [VIS] Four 16-bit partial store, primary, little endian */ +#define ASI_PST16_SECONDARY_LITTLE 0xcb /* [VIS] Fout 16-bit partial store, secondary, little endian */ +#define ASI_PST32_PRIMARY_LITTLE 0xcc /* [VIS] Two 32-bit partial store, primary, little endian */ +#define ASI_PST32_SECONDARY_LITTLE 0xcd /* [VIS] Two 32-bit partial store, secondary, little endian */ + +#define ASI_FL8_PRIMARY 0xd0 /* [VIS] One 8-bit load/store floating, primary */ +#define ASI_FL8_SECONDARY 0xd1 /* [VIS] One 8-bit load/store floating, secondary */ +#define ASI_FL16_PRIMARY 0xd2 /* [VIS] One 16-bit load/store floating, primary */ +#define ASI_FL16_SECONDARY 0xd3 /* [VIS] One 16-bit load/store floating, secondary */ + +#define ASI_FL8_PRIMARY_LITTLE 0xd8 /* [VIS] One 8-bit load/store floating, primary, little endian */ +#define ASI_FL8_SECONDARY_LITTLE 0xd9 /* [VIS] One 8-bit load/store floating, secondary, little endian */ +#define ASI_FL16_PRIMARY_LITTLE 0xda /* [VIS] One 16-bit load/store floating, primary, little endian */ +#define ASI_FL16_SECONDARY_LITTLE 0xdb /* [VIS] One 16-bit load/store floating, secondary, little endian */ + +#define ASI_BLOCK_COMMIT_PRIMARY 0xe0 /* [4u] block store with commit, primary */ +#define ASI_BLOCK_COMMIT_SECONDARY 0xe1 /* [4u] block store with commit, secondary */ +#define ASI_BLOCK_PRIMARY 0xf0 /* [4u] block load/store, primary */ +#define ASI_BLOCK_SECONDARY 0xf1 /* [4u] block load/store, secondary */ +#define ASI_BLOCK_PRIMARY_LITTLE 0xf8 /* [4u] block load/store, primary, little endian */ +#define ASI_BLOCK_SECONDARY_LITTLE 0xf9 /* [4u] block load/store, secondary, little endian */ + + +/* + * These are the shorter names used by Solaris + */ + +#define ASI_N ASI_NUCLEUS +#define ASI_NL ASI_NUCLEUS_LITTLE +#define ASI_AIUP ASI_AS_IF_USER_PRIMARY +#define ASI_AIUS ASI_AS_IF_USER_SECONDARY +#define ASI_AIUPL ASI_AS_IF_USER_PRIMARY_LITTLE +#define ASI_AIUSL ASI_AS_IF_USER_SECONDARY_LITTLE +#define ASI_P ASI_PRIMARY +#define ASI_S ASI_SECONDARY +#define ASI_PNF ASI_PRIMARY_NOFAULT +#define ASI_SNF ASI_SECONDARY_NOFAULT +#define ASI_PL ASI_PRIMARY_LITTLE +#define ASI_SL ASI_SECONDARY_LITTLE +#define ASI_PNFL ASI_PRIMARY_NOFAULT_LITTLE +#define ASI_SNFL ASI_SECONDARY_NOFAULT_LITTLE +#define ASI_FL8_P ASI_FL8_PRIMARY +#define ASI_FL8_S ASI_FL8_SECONDARY +#define ASI_FL16_P ASI_FL16_PRIMARY +#define ASI_FL16_S ASI_FL16_SECONDARY +#define ASI_FL8_PL ASI_FL8_PRIMARY_LITTLE +#define ASI_FL8_SL ASI_FL8_SECONDARY_LITTLE +#define ASI_FL16_PL ASI_FL16_PRIMARY_LITTLE +#define ASI_FL16_SL ASI_FL16_SECONDARY_LITTLE +#define ASI_BLK_AIUP ASI_BLOCK_AS_IF_USER_PRIMARY +#define ASI_BLK_AIUPL ASI_BLOCK_AS_IF_USER_PRIMARY_LITTLE +#define ASI_BLK_AIUS ASI_BLOCK_AS_IF_USER_SECONDARY +#define ASI_BLK_AIUSL ASI_BLOCK_AS_IF_USER_SECONDARY_LITTLE +#define ASI_BLK_COMMIT_P ASI_BLOCK_COMMIT_PRIMARY +#define ASI_BLK_COMMIT_PRIMARY ASI_BLOCK_COMMIT_PRIMARY +#define ASI_BLK_COMMIT_S ASI_BLOCK_COMMIT_SECONDARY +#define ASI_BLK_COMMIT_SECONDARY ASI_BLOCK_COMMIT_SECONDARY +#define ASI_BLK_P ASI_BLOCK_PRIMARY +#define ASI_BLK_PL ASI_BLOCK_PRIMARY_LITTLE +#define ASI_BLK_S ASI_BLOCK_SECONDARY +#define ASI_BLK_SL ASI_BLOCK_SECONDARY_LITTLE + +/* Alternative spellings */ +#define ASI_PRIMARY_NO_FAULT ASI_PRIMARY_NOFAULT +#define ASI_PRIMARY_NO_FAULT_LITTLE ASI_PRIMARY_NOFAULT_LITTLE +#define ASI_SECONDARY_NO_FAULT ASI_SECONDARY_NOFAULT +#define ASI_SECONDARY_NO_FAULT_LITTLE ASI_SECONDARY_NOFAULT_LITTLE + +#define PHYS_ASI(x) (((x) | 0x09) == 0x1d) +#define LITTLE_ASI(x) ((x) & ASI_LITTLE) + +/* + * %tick: cpu cycle counter + */ +#define TICK_NPT 0x8000000000000000 /* trap on non priv access */ +#define TICK_TICKS 0x7fffffffffffffff /* counter bits */ + +/* + * The following are 4u control registers + */ + +/* Get the CPU's UPA port ID */ +#define UPA_CR_MID(x) (((x) >> 17) & 0x1f) +#define CPU_UPAID UPA_CR_MID(ldxa(0, ASI_MID_REG)) + +/* Get the CPU's Fireplane agent ID */ +#define FIREPLANE_CR_AID(x) (((x) >> 17) & 0x3ff) +#define CPU_FIREPLANEID FIREPLANE_CR_AID(ldxa(0, ASI_MID_REG)) + +/* Get the CPU's Jupiter Bus interrupt target ID */ +#define JUPITER_CR_ITID(x) ((x) & 0x3ff) +#define CPU_JUPITERID JUPITER_CR_ITID(ldxa(0, ASI_MID_REG)) + +/* + * [4u] MMU and Cache Control Register (MCCR) + * use ASI = 0x45 + */ +#define ASI_MCCR ASI_LSU_CONTROL_REGISTER +#define MCCR 0x00 + +/* MCCR Bits and their meanings */ +#define MCCR_DMMU_EN 0x08 +#define MCCR_IMMU_EN 0x04 +#define MCCR_DCACHE_EN 0x02 +#define MCCR_ICACHE_EN 0x01 + + +/* + * MMU control registers + */ + +/* Choose an MMU */ +#define ASI_DMMU 0x58 +#define ASI_IMMU 0x50 + +/* Other assorted MMU ASIs */ +#define ASI_IMMU_8KPTR 0x51 +#define ASI_IMMU_64KPTR 0x52 +#define ASI_IMMU_DATA_IN 0x54 +#define ASI_IMMU_TLB_DATA 0x55 +#define ASI_IMMU_TLB_TAG 0x56 +#define ASI_DMMU_8KPTR 0x59 +#define ASI_DMMU_64KPTR 0x5a +#define ASI_DMMU_DATA_IN 0x5c +#define ASI_DMMU_TLB_DATA 0x5d +#define ASI_DMMU_TLB_TAG 0x5e + +/* + * The following are the control registers + * They work on both MMUs unless noted. + * III = cheetah only + * + * Register contents are defined later on individual registers. + */ +#define TSB_TAG_TARGET 0x0 +#define TLB_DATA_IN 0x0 +#define CTX_PRIMARY 0x08 /* primary context -- DMMU only */ +#define CTX_SECONDARY 0x10 /* secondary context -- DMMU only */ +#define SFSR 0x18 +#define SFAR 0x20 /* fault address -- DMMU only */ +#define TSB 0x28 +#define TLB_TAG_ACCESS 0x30 +#define VIRTUAL_WATCHPOINT 0x38 +#define PHYSICAL_WATCHPOINT 0x40 +#define TSB_PEXT 0x48 /* III primary ext */ +#define TSB_SEXT 0x50 /* III 2ndary ext -- DMMU only */ +#define TSB_NEXT 0x58 /* III nucleus ext */ + +/* Tag Target bits */ +#define TAG_TARGET_VA_MASK 0x03ffffffffffffffffLL +#define TAG_TARGET_VA(x) (((x)<<22)&TAG_TARGET_VA_MASK) +#define TAG_TARGET_CONTEXT(x) ((x)>>48) +#define TAG_TARGET(c,v) ((((uint64_t)c)<<48)|(((uint64_t)v)&TAG_TARGET_VA_MASK)) + +/* SFSR bits for both D_SFSR and I_SFSR */ +#define SFSR_NF 0x1000000 /* Non-faulting load */ +#define SFSR_ASI(x) ((x)>>16) +#define SFSR_TM 0x0008000 /* TLB miss */ +#define SFSR_FT_VA_OOR_2 0x0002000 /* IMMU: jumpl or return to unsupported VA */ +#define SFSR_FT_VA_OOR_1 0x0001000 /* fault at unsupported VA */ +#define SFSR_FT_NFO 0x0000800 /* DMMU: Access to page marked NFO */ +#define SFSR_ILL_ASI 0x0000400 /* DMMU: Illegal (unsupported) ASI */ +#define SFSR_FT_IO_ATOMIC 0x0000200 /* DMMU: Atomic access to noncacheable page */ +#define SFSR_FT_ILL_NF 0x0000100 /* DMMU: NF load or flush to page marked E (has side effects) */ +#define SFSR_FT_PRIV 0x0000080 /* Privilege violation */ +#define SFSR_FT_E 0x0000040 /* DMUU: value of E bit associated address */ +#define SFSR_CTXT(x) (((x)>>4)&0x3) +#define SFSR_CTXT_IS_PRIM(x) (SFSR_CTXT(x)==0x00) +#define SFSR_CTXT_IS_SECOND(x) (SFSR_CTXT(x)==0x01) +#define SFSR_CTXT_IS_NUCLEUS(x) (SFSR_CTXT(x)==0x02) +#define SFSR_PRIV 0x0000008 /* value of PSTATE.PRIV for faulting access */ +#define SFSR_W 0x0000004 /* DMMU: attempted write */ +#define SFSR_OW 0x0000002 /* Overwrite; prev fault was still valid */ +#define SFSR_FV 0x0000001 /* Fault is valid */ +#define SFSR_FT (SFSR_FT_VA_OOR_2|SFSR_FT_VA_OOR_1|SFSR_FT_NFO|SFSR_ILL_ASI|SFSR_FT_IO_ATOMIC|SFSR_FT_ILL_NF|SFSR_FT_PRIV) + +#define SFSR_BITS "\20\31NF\20TM\16VAT\15VAD\14NFO\13ASI\12A\11NF\10PRIV\7E\6NUCLEUS\5SECONDCTX\4PRIV\3W\2OW\1FV" + +/* ASFR bits */ +#define ASFR_ME 0x100000000LL +#define ASFR_PRIV 0x080000000LL +#define ASFR_ISAP 0x040000000LL +#define ASFR_ETP 0x020000000LL +#define ASFR_IVUE 0x010000000LL +#define ASFR_TO 0x008000000LL +#define ASFR_BERR 0x004000000LL +#define ASFR_LDP 0x002000000LL +#define ASFR_CP 0x001000000LL +#define ASFR_WP 0x000800000LL +#define ASFR_EDP 0x000400000LL +#define ASFR_UE 0x000200000LL +#define ASFR_CE 0x000100000LL +#define ASFR_ETS 0x0000f0000LL +#define ASFT_P_SYND 0x00000ffffLL + +#define AFSR_BITS "\20" \ + "\20ME\37PRIV\36ISAP\35ETP\34IVUE\33TO\32BERR\31LDP\30CP\27WP\26EDP" \ + "\25UE\24CE" + +/* + * Here's the spitfire TSB control register bits. + * + * Each TSB entry is 16-bytes wide. The TSB must be size aligned + */ +#define TSB_SIZE_512 0x0 /* 8kB, etc. */ +#define TSB_SIZE_1K 0x01 +#define TSB_SIZE_2K 0x02 +#define TSB_SIZE_4K 0x03 +#define TSB_SIZE_8K 0x04 +#define TSB_SIZE_16K 0x05 +#define TSB_SIZE_32K 0x06 +#define TSB_SIZE_64K 0x07 +#define TSB_SPLIT 0x1000 +#define TSB_BASE 0xffffffffffffe000 + +/* TLB Tag Access bits */ +#define TLB_TAG_ACCESS_VA 0xffffffffffffe000 +#define TLB_TAG_ACCESS_CTX 0x0000000000001fff + +/* + * TLB demap registers. TTEs are defined in v9pte.h + * + * Use the address space to select between IMMU and DMMU. + * The address of the register selects which context register + * to read the ASI from. + * + * The data stored in the register is interpreted as the VA to + * use. The DEMAP_CTX_<> registers ignore the address and demap the + * entire ASI. + * + */ +#define ASI_IMMU_DEMAP 0x57 /* [4u] IMMU TLB demap */ +#define ASI_DMMU_DEMAP 0x5f /* [4u] IMMU TLB demap */ + +#define DEMAP_PAGE_NUCLEUS ((0x02)<<4) /* Demap page from kernel AS */ +#define DEMAP_PAGE_PRIMARY ((0x00)<<4) /* Demap a page from primary CTXT */ +#define DEMAP_PAGE_SECONDARY ((0x01)<<4) /* Demap page from secondary CTXT (DMMU only) */ +#define DEMAP_CTX_NUCLEUS ((0x06)<<4) /* Demap all of kernel CTXT */ +#define DEMAP_CTX_PRIMARY ((0x04)<<4) /* Demap all of primary CTXT */ +#define DEMAP_CTX_SECONDARY ((0x05)<<4) /* Demap all of secondary CTXT */ + +/* + * Interrupt registers. This really gets hairy. + */ + +/* IRSR -- Interrupt Receive Status Register */ +#define ASI_IRSR 0x49 +#define IRSR 0x00 +#define IRSR_BUSY 0x020 +#define IRSR_MID(x) (x&0x1f) + +/* IRDR -- Interrupt Receive Data Registers */ +#define ASI_IRDR 0x7f +#define IRDR_0H 0x40 +#define IRDR_0L 0x48 /* unimplemented */ +#define IRDR_1H 0x50 +#define IRDR_1L 0x58 /* unimplemented */ +#define IRDR_2H 0x60 +#define IRDR_2L 0x68 /* unimplemented */ +#define IRDR_3H 0x70 /* unimplemented */ +#define IRDR_3L 0x78 /* unimplemented */ + +/* SOFTINT ASRs */ +#define SET_SOFTINT %asr20 /* Sets these bits */ +#define CLEAR_SOFTINT %asr21 /* Clears these bits */ +#define SOFTINT %asr22 /* Reads the register */ +#define TICK_CMPR %asr23 + +#define TICK_INT 0x01 /* level-14 clock tick */ +#define SOFTINT1 (0x1<<1) +#define SOFTINT2 (0x1<<2) +#define SOFTINT3 (0x1<<3) +#define SOFTINT4 (0x1<<4) +#define SOFTINT5 (0x1<<5) +#define SOFTINT6 (0x1<<6) +#define SOFTINT7 (0x1<<7) +#define SOFTINT8 (0x1<<8) +#define SOFTINT9 (0x1<<9) +#define SOFTINT10 (0x1<<10) +#define SOFTINT11 (0x1<<11) +#define SOFTINT12 (0x1<<12) +#define SOFTINT13 (0x1<<13) +#define SOFTINT14 (0x1<<14) +#define SOFTINT15 (0x1<<15) +#define STICK_INT (0x1<<16) + +/* Interrupt Dispatch -- usually reserved for cross-calls */ +#define ASR_IDSR 0x48 /* Interrupt dispatch status reg */ +#define IDSR 0x00 +#define IDSR_NACK 0x02 +#define IDSR_BUSY 0x01 + +#define ASI_INTERRUPT_DISPATCH 0x77 /* [4u] spitfire interrupt dispatch regs */ + +/* Interrupt delivery initiation */ +#define IDCR(x) ((((u_int64_t)(x)) << 14) | 0x70) + +#define IDDR_0H 0x40 /* Store data to send in these regs */ +#define IDDR_0L 0x48 /* unimplemented */ +#define IDDR_1H 0x50 +#define IDDR_1L 0x58 /* unimplemented */ +#define IDDR_2H 0x60 +#define IDDR_2L 0x68 /* unimplemented */ +#define IDDR_3H 0x80 /* unimplemented */ +#define IDDR_3L 0x88 /* unimplemented */ + +/* + * Error registers + */ + +/* Since we won't try to fix async errs, we don't care about the bits in the regs */ +#define ASI_AFAR 0x4d /* Asynchronous fault address register */ +#define AFAR 0x00 +#define ASI_AFSR 0x4c /* Asynchronous fault status register */ +#define AFSR 0x00 + +#define ASI_P_EER 0x4b /* Error enable register */ +#define P_EER 0x00 +#define P_EER_ISAPEN 0x04 /* Enable fatal on ISAP */ +#define P_EER_NCEEN 0x02 /* Enable trap on uncorrectable errs */ +#define P_EER_CEEN 0x01 /* Enable trap on correctable errs */ + +#define ASI_DATAPATH_READ 0x7f /* Read the regs */ +#define ASI_DATAPATH_WRITE 0x77 /* Write to the regs */ +#define P_DPER_0 0x00 /* Datapath err reg 0 */ +#define P_DPER_1 0x18 /* Datapath err reg 1 */ +#define P_DCR_0 0x20 /* Datapath control reg 0 */ +#define P_DCR_1 0x38 /* Datapath control reg 0 */ + + +/* From sparc64/asm.h which I think I'll deprecate since it makes bus.h a pain. */ + +#ifndef _LOCORE +/* + * GCC __asm constructs for doing assembly stuff. + */ + +/* + * ``Routines'' to load and store from/to alternate address space. + * The location can be a variable, the asi value (address space indicator) + * must be a constant. + * + * N.B.: You can put as many special functions here as you like, since + * they cost no kernel space or time if they are not used. + * + * These were static inline functions, but gcc screws up the constraints + * on the address space identifiers (the "n"umeric value part) because + * it inlines too late, so we have to use the funny valued-macro syntax. + */ + +/* + * Apparently the definition of bypass ASIs is that they all use the + * D$ so we need to flush the D$ to make sure we don't get data pollution. + */ + +#define sparc_wr(name, val, xor) \ +do { \ + if (__builtin_constant_p(xor)) \ + __asm volatile("wr %%g0, %0, %%" #name \ + : : "rI" ((val) ^ (xor)) : "%g0"); \ + else \ + __asm volatile("wr %0, %1, %%" #name \ + : : "r" (val), "rI" (xor) : "%g0"); \ +} while(0) + +#define sparc_wrpr(name, val, xor) \ +do { \ + if (__builtin_constant_p(xor)) \ + __asm volatile("wrpr %%g0, %0, %%" #name \ + : : "rI" ((val) ^ (xor)) : "%g0"); \ + else \ + __asm volatile("wrpr %0, %1, %%" #name \ + : : "r" (val), "rI" (xor) : "%g0"); \ + __asm volatile("" : : : "memory"); \ +} while(0) + + +#define sparc_rd(name) sparc_rd_ ## name() +#define GEN_RD(name) \ +static inline u_int64_t sparc_rd_ ## name(void); \ +static inline u_int64_t \ +sparc_rd_ ## name(void) \ +{ \ + u_int64_t r; \ + __asm volatile("rd %%" #name ", %0" : \ + "=r" (r) : : "%g0"); \ + return (r); \ +} + +#define sparc_rdpr(name) sparc_rdpr_ ## name() +#define GEN_RDPR(name) \ +static inline u_int64_t sparc_rdpr_ ## name(void); \ +static inline u_int64_t \ +sparc_rdpr_ ## name(void) \ +{ \ + u_int64_t r; \ + __asm volatile("rdpr %%" #name ", %0" : \ + "=r" (r) : : "%g0"); \ + return (r); \ +} + +GEN_RD(asi); +GEN_RD(fprs); +GEN_RD(asr22); +GEN_RD(sys_tick); +GEN_RD(sys_tick_cmpr); +GEN_RDPR(tick); +GEN_RDPR(tba); +GEN_RDPR(pstate); +GEN_RDPR(pil); +GEN_RDPR(cwp); +GEN_RDPR(cansave); +GEN_RDPR(canrestore); +GEN_RDPR(cleanwin); +GEN_RDPR(otherwin); +GEN_RDPR(wstate); +GEN_RDPR(ver); +/* + * Before adding GEN_RDPRs for other registers, see Errata 50 (E.g,. in + * the US-IIi manual) regarding tstate, pc and npc reads. + */ + +/* Generate ld*a/st*a functions for non-constant ASI's. */ +#define LDNC_GEN(tp, o) \ + static inline tp o ## _asi(paddr_t); \ + static inline tp \ + o ## _asi(paddr_t va) \ + { \ + tp r; \ + __asm volatile( \ + #o " [%1] %%asi, %0" \ + : "=r" (r) \ + : "r" ((volatile tp *)va) \ + : "%g0"); \ + return (r); \ + } \ + static inline tp o ## _nc(paddr_t, int); \ + static inline tp \ + o ## _nc(paddr_t va, int asi) \ + { \ + sparc_wr(asi, asi, 0); \ + return (o ## _asi(va)); \ + } + +LDNC_GEN(u_char, lduba); +LDNC_GEN(u_short, lduha); +LDNC_GEN(u_int, lduwa); +LDNC_GEN(u_int64_t, ldxa); + +LDNC_GEN(int, lda); + +#define LDC_GEN(va, asi, op, opa, type) ({ \ + type __r ## op ## type; \ + if(asi == ASI_PRIMARY || \ + (sizeof(type) == 1 && asi == ASI_PRIMARY_LITTLE)) \ + __r ## op ## type = *((volatile type *)va); \ + else \ + __asm volatile(#opa " [%1] " #asi ", %0" \ + : "=r" (__r ## op ## type) \ + : "r" ((volatile type *)va) \ + : "%g0"); \ + __r ## op ## type; \ +}) + +#ifdef __OPTIMIZE__ +#define LD_GENERIC(va, asi, op, type) (__builtin_constant_p(asi) ? \ + LDC_GEN((va), asi, op, op ## a, type) : op ## a_nc((va), asi)) +#else /* __OPTIMIZE */ +#define LD_GENERIC(va, asi, op, type) (op ## a_nc((va), asi)) +#endif /* __OPTIMIZE__ */ + +#define lduba(va, asi) LD_GENERIC(va, asi, ldub, u_int8_t) +#define lduha(va, asi) LD_GENERIC(va, asi, lduh, u_int16_t) +#define lduwa(va, asi) LD_GENERIC(va, asi, lduw, u_int32_t) +#define ldxa(va, asi) LD_GENERIC(va, asi, ldx, u_int64_t) + +#define STNC_GEN(tp, o) \ + static inline void o ## _asi(paddr_t, tp); \ + static inline void \ + o ## _asi(paddr_t va, tp val) \ + { \ + __asm volatile( \ + #o " %0, [%1] %%asi" \ + : \ + : "r" (val), "r" ((volatile tp *)va) \ + : "memory"); \ + } \ + static inline void o ## _nc(paddr_t, int, tp); \ + static inline void \ + o ## _nc(paddr_t va, int asi, tp val) \ + { \ + sparc_wr(asi, asi, 0); \ + o ## _asi(va, val); \ + } + +STNC_GEN(u_int8_t, stba); +STNC_GEN(u_int16_t, stha); +STNC_GEN(u_int32_t, stwa); +STNC_GEN(u_int64_t, stxa); + +STNC_GEN(u_int, sta); + +#define STC_GEN(va, asi, val, op, opa, type) ({ \ + if(asi == ASI_PRIMARY || \ + (sizeof(type) == 1 && asi == ASI_PRIMARY_LITTLE)) \ + *((volatile type *)va) = val; \ + else \ + __asm volatile(#opa " %0, [%1] " #asi \ + : : "r" (val), "r" ((volatile type *)va) \ + : "memory"); \ + }) + +#ifdef __OPTIMIZE__ +#define ST_GENERIC(va, asi, val, op, type) (__builtin_constant_p(asi) ? \ + STC_GEN((va), (asi), (val), op, op ## a, type) : \ + op ## a_nc((va), asi, (val))) +#else /* __OPTIMIZE__ */ +#define ST_GENERIC(va, asi, val, op, type) (op ## a_nc((va), asi, (val))) +#endif /* __OPTIMIZE__ */ + +#define stba(va, asi, val) ST_GENERIC(va, asi, val, stb, u_int8_t) +#define stha(va, asi, val) ST_GENERIC(va, asi, val, sth, u_int16_t) +#define stwa(va, asi, val) ST_GENERIC(va, asi, val, stw, u_int32_t) +#define stxa(va, asi, val) ST_GENERIC(va, asi, val, stx, u_int64_t) + + +static inline void asi_set(int); +static inline void +asi_set(int asi) +{ + sparc_wr(asi, asi, 0); +} + +static inline u_int8_t asi_get(void); +static inline u_int8_t +asi_get(void) +{ + return sparc_rd(asi); +} + +/* flush address from instruction cache */ +static inline void flush(void *); +static inline void +flush(void *p) +{ + __asm volatile("flush %0" + : : "r" (p) + : "memory"); +} + +/* Read 64-bit %tick and %sys_tick registers. */ +#define tick() (sparc_rdpr(tick) & TICK_TICKS) +#define sys_tick() (sparc_rd(sys_tick) & TICK_TICKS) +extern u_int64_t stick(void); + +extern void tick_enable(void); +extern void sys_tick_enable(void); + +extern void tickcmpr_set(u_int64_t); +extern void sys_tickcmpr_set(u_int64_t); +extern void stickcmpr_set(u_int64_t); + +#endif /* _LOCORE */ +#endif /* _SPARC64_CTLREG_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/db_machdep.h b/lib/libc/include/sparc64-openbsd-none/sparc64/db_machdep.h new file mode 100644 index 0000000000..9edef3be53 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/db_machdep.h @@ -0,0 +1,145 @@ +/* $OpenBSD: db_machdep.h,v 1.23 2022/10/21 18:55:42 miod Exp $ */ +/* $NetBSD: db_machdep.h,v 1.12 2001/07/07 15:16:13 eeh Exp $ */ + +/* + * Mach Operating System + * Copyright (c) 1991,1990 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +#ifndef _MACHINE_DB_MACHDEP_H_ +#define _MACHINE_DB_MACHDEP_H_ + +/* + * Machine-dependent defines for new kernel debugger. + */ + +#include + +#include +#include +#include +#include + +/* end of mangling */ + +typedef long db_expr_t; /* expression - signed */ + +struct trapstate { + int64_t tstate; + int64_t tpc; + int64_t tnpc; + int64_t tt; +}; +#if 1 +typedef struct { + struct trapframe ddb_tf; + struct frame ddb_fr; + struct trapstate ddb_ts[5]; + int ddb_tl; + struct fpstate ddb_fpstate; +} db_regs_t; +#else +typedef struct db_regs { + struct trapregs dbr_traps[4]; + int dbr_y; + char dbr_tl; + char dbr_canrestore; + char dbr_cansave; + char dbr_cleanwin; + char dbr_cwp; + char dbr_wstate; + int64_t dbr_g[8]; + int64_t dbr_ag[8]; + int64_t dbr_ig[8]; + int64_t dbr_mg[8]; + int64_t dbr_out[8]; + int64_t dbr_local[8]; + int64_t dbr_in[8]; +} db_regs_t; +#endif + +extern db_regs_t ddb_regs; /* register state */ +#define DDB_TF (&ddb_regs.ddb_tf) +#define DDB_FR (&ddb_regs.ddb_fr) +#define DDB_FP (&ddb_regs.ddb_fpstate) + +#define PC_REGS(regs) ((vaddr_t)(regs)->ddb_tf.tf_pc) +#define SET_PC_REGS(regs, value) (regs)->ddb_tf.tf_pc = (int32_t)(value) +#define PC_ADVANCE(regs) do { \ + vaddr_t n = (regs)->ddb_tf.tf_npc; \ + (regs)->ddb_tf.tf_pc = n; \ + (regs)->ddb_tf.tf_npc = n + 4; \ +} while(0) + +#define BKPT_INST 0x91d02001 /* breakpoint instruction */ +#define BKPT_SIZE (4) /* size of breakpoint inst */ +#define BKPT_SET(inst) (BKPT_INST) + +#define IS_BREAKPOINT_TRAP(type, code) \ + ((type) == T_BREAKPOINT || (type) == T_KGDB_EXEC) +#define IS_WATCHPOINT_TRAP(type, code) \ + ((type) ==T_PA_WATCHPT || (type) == T_VA_WATCHPT) + +/* + * Sparc cpus have no hardware single-step. + */ +#define SOFTWARE_SSTEP + +int db_inst_trap_return(int inst); +int db_inst_return(int inst); +int db_inst_call(int inst); +int db_inst_branch(int inst); +int db_inst_unconditional_flow_transfer(int inst); +vaddr_t db_branch_taken(int inst, vaddr_t pc, db_regs_t *regs); + +#define inst_trap_return(ins) db_inst_trap_return(ins) +#define inst_return(ins) db_inst_return(ins) +#define inst_call(ins) db_inst_call(ins) +#define inst_branch(ins) db_inst_branch(ins) +#define inst_unconditional_flow_transfer(ins) \ + db_inst_unconditional_flow_transfer(ins) +#define branch_taken(ins, pc, fun, regs) \ + db_branch_taken((ins), (pc), (regs)) + +/* see note in db_interface.c about reversed breakpoint addrs */ +#define next_instr_address(pc, bd) \ + ((bd) ? (pc) : ddb_regs.ddb_tf.tf_npc) + +#define DB_MACHINE_COMMANDS + +void db_machine_init(void); +int db_ktrap(int, struct trapframe *); + +int db_enter_ddb(void); +void db_startcpu(struct cpu_info *); +void db_stopcpu(struct cpu_info *); + +#define DDB_STATE_NOT_RUNNING 0 +#define DDB_STATE_RUNNING 1 +#define DDB_STATE_EXITING 2 + +/* Register device-specific method for triggering XIRs. */ +void db_register_xir(void (*)(void *, int), void *); + +#endif /* _MACHINE_DB_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/disklabel.h b/lib/libc/include/sparc64-openbsd-none/sparc64/disklabel.h new file mode 100644 index 0000000000..5b9d93732a --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/disklabel.h @@ -0,0 +1,40 @@ +/* $OpenBSD: disklabel.h,v 1.5 2015/09/30 14:57:03 krw Exp $ */ + +/* + * Copyright (c) 1994 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 _MACHINE_DISKLABEL_H_ +#define _MACHINE_DISKLABEL_H_ + +#define LABELSECTOR 0 /* sector containing label */ +#define LABELOFFSET 128 /* offset of label in sector */ +#define MAXPARTITIONS 16 /* number of partitions */ + +#endif /* _MACHINE_DISKLABEL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/elf.h b/lib/libc/include/sparc64-openbsd-none/sparc64/elf.h new file mode 100644 index 0000000000..1a69b90df3 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/elf.h @@ -0,0 +1,7 @@ +/* $OpenBSD: elf.h,v 1.1 2024/07/14 09:48:49 jca Exp $ */ + +/* + * This file is in the public domain. + */ + +/* Nothing for now */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/endian.h b/lib/libc/include/sparc64-openbsd-none/sparc64/endian.h new file mode 100644 index 0000000000..ed220930b5 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/endian.h @@ -0,0 +1,84 @@ +/* $OpenBSD: endian.h,v 1.7 2014/10/22 23:56:47 dlg Exp $ */ + +#ifndef _MACHINE_ENDIAN_H_ +#define _MACHINE_ENDIAN_H_ + +#define _BYTE_ORDER _BIG_ENDIAN + +#ifdef _KERNEL + +#define __ASI_P_L 0x88 /* == ASI_PRIMARY_LITTLE */ + +static inline __uint16_t +__mswap16(volatile const __uint16_t *m) +{ + __uint16_t v; + + __asm("lduha [%1] %2, %0 ! %3" + : "=r" (v) + : "r" (m), "n" (__ASI_P_L), "m" (*m)); + + return (v); +} + +static inline __uint32_t +__mswap32(volatile const __uint32_t *m) +{ + __uint32_t v; + + __asm("lduwa [%1] %2, %0 ! %3" + : "=r" (v) + : "r" (m), "n" (__ASI_P_L), "m" (*m)); + + return (v); +} + +static inline __uint64_t +__mswap64(volatile const __uint64_t *m) +{ + __uint64_t v; + + __asm("ldxa [%1] %2, %0 ! %3" + : "=r" (v) + : "r" (m), "n" (__ASI_P_L), "m" (*m)); + + return (v); +} + +static inline void +__swapm16(volatile __uint16_t *m, __uint16_t v) +{ + __asm("stha %1, [%2] %3 ! %0" + : "=m" (*m) + : "r" (v), "r" (m), "n" (__ASI_P_L)); +} + +static inline void +__swapm32(volatile __uint32_t *m, __uint32_t v) +{ + __asm("stwa %1, [%2] %3 ! %0" + : "=m" (*m) + : "r" (v), "r" (m), "n" (__ASI_P_L)); +} + +static inline void +__swapm64(volatile __uint64_t *m, __uint64_t v) +{ + __asm("stxa %1, [%2] %3 ! %0" + : "=m" (*m) + : "r" (v), "r" (m), "n" (__ASI_P_L)); +} + +#undef __ASI_P_L + +#define __HAVE_MD_SWAPIO + +#endif /* _KERNEL */ + +#define __STRICT_ALIGNMENT + +#ifndef __FROM_SYS__ENDIAN +#include +#endif + +#endif /* _MACHINE_ENDIAN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/exec.h b/lib/libc/include/sparc64-openbsd-none/sparc64/exec.h new file mode 100644 index 0000000000..e71ec31b24 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/exec.h @@ -0,0 +1,99 @@ +/* $OpenBSD: exec.h,v 1.11 2017/02/08 05:09:26 guenther Exp $ */ +/* $NetBSD: elf_machdep.h,v 1.7 2001/02/11 00:18:49 eeh Exp $ */ + +#define ARCH_ELFSIZE 64 /* MD native binary size */ +#define ELF_TARG_CLASS ELFCLASS64 +#define ELF_TARG_MACH EM_SPARCV9 + +#define ELF_TARG_DATA ELFDATA2MSB + +/* The following are what is used for AT_SUN_HWCAP: */ +#define AV_SPARC_HWMUL_32x32 1 /* 32x32-bit smul/umul is efficient */ +#define AV_SPARC_HWDIV_32x32 2 /* 32x32-bit sdiv/udiv is efficient */ +#define AV_SPARC_HWFSMULD 4 /* fsmuld is efficient */ + +/* + * Here are some SPARC specific flags I can't + * find a better home for. They are used for AT_FLAGS + * and in the exec header. + */ +#define EF_SPARCV9_MM 0x3 +#define EF_SPARCV9_TSO 0x0 +#define EF_SPARCV9_PSO 0x1 +#define EF_SPARCV9_RMO 0x2 + +#define EF_SPARC_32PLUS_MASK 0xffff00 /* bits indicating V8+ type */ +#define EF_SPARC_32PLUS 0x000100 /* generic V8+ features */ +#define EF_SPARC_EXT_MASK 0xffff00 /* bits for vendor extensions */ +#define EF_SPARC_SUN_US1 0x000200 /* UltraSPARC 1 extensions */ +#define EF_SPARC_HAL_R1 0x000400 /* HAL R1 extensions */ +#define EF_SPARC_SUN_US3 0x000800 /* UltraSPARC 3 extensions */ + +/* Relocation types */ +#define R_SPARC_NONE 0 +#define R_SPARC_8 1 +#define R_SPARC_16 2 +#define R_SPARC_32 3 +#define R_SPARC_DISP8 4 +#define R_SPARC_DISP16 5 +#define R_SPARC_DISP32 6 +#define R_SPARC_WDISP30 7 +#define R_SPARC_WDISP22 8 +#define R_SPARC_HI22 9 +#define R_SPARC_22 10 +#define R_SPARC_13 11 +#define R_SPARC_LO10 12 +#define R_SPARC_GOT10 13 +#define R_SPARC_GOT13 14 +#define R_SPARC_GOT22 15 +#define R_SPARC_PC10 16 +#define R_SPARC_PC22 17 +#define R_SPARC_WPLT30 18 +#define R_SPARC_COPY 19 +#define R_SPARC_GLOB_DAT 20 +#define R_SPARC_JMP_SLOT 21 +#define R_SPARC_RELATIVE 22 +#define R_SPARC_UA32 23 +#define R_SPARC_PLT32 24 +#define R_SPARC_HIPLT22 25 +#define R_SPARC_LOPLT10 26 +#define R_SPARC_PCPLT32 27 +#define R_SPARC_PCPLT22 28 +#define R_SPARC_PCPLT10 29 +#define R_SPARC_10 30 +#define R_SPARC_11 31 +#define R_SPARC_64 32 +#define R_SPARC_OLO10 33 +#define R_SPARC_HH22 34 +#define R_SPARC_HM10 35 +#define R_SPARC_LM22 36 +#define R_SPARC_PC_HH22 37 +#define R_SPARC_PC_HM10 38 +#define R_SPARC_PC_LM22 39 +#define R_SPARC_WDISP16 40 +#define R_SPARC_WDISP19 41 +#define R_SPARC_GLOB_JMP 42 +#define R_SPARC_7 43 +#define R_SPARC_5 44 +#define R_SPARC_6 45 +#define R_SPARC_DISP64 46 +#define R_SPARC_PLT64 47 +#define R_SPARC_HIX22 48 +#define R_SPARC_LOX10 49 +#define R_SPARC_H44 50 +#define R_SPARC_M44 51 +#define R_SPARC_L44 52 +#define R_SPARC_REGISTER 53 +#define R_SPARC_UA64 54 +#define R_SPARC_UA16 55 +#define R_SPARC_TLS_DTPMOD32 74 +#define R_SPARC_TLS_DTPMOD64 75 +#define R_SPARC_TLS_DTPOFF32 76 +#define R_SPARC_TLS_DTPOFF64 77 +#define R_SPARC_TLS_TPOFF32 78 +#define R_SPARC_TLS_TPOFF64 79 + + +#define R_TYPE(name) __CONCAT(R_SPARC_,name) + +#define __LDPGSZ 8192 /* linker page size */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/fbvar.h b/lib/libc/include/sparc64-openbsd-none/sparc64/fbvar.h new file mode 100644 index 0000000000..6815f31490 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/fbvar.h @@ -0,0 +1,80 @@ +/* $OpenBSD: fbvar.h,v 1.8 2008/12/29 22:07:35 miod Exp $ */ +/* $NetBSD: fbvar.h,v 1.9 1997/07/07 23:31:30 pk Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)fbvar.h 8.1 (Berkeley) 6/11/93 + */ + +/* + * Common frame buffer variables. + * All framebuffer softc structures must start with such a structure. + */ +struct sunfb { + struct device sf_dev; /* base device */ + + int sf_width; + int sf_height; + int sf_depth; + int sf_linebytes; + + int sf_fbsize; /* sf_height * sf_linebytes */ + + int *sf_crowp, *sf_ccolp; /* PROM cursor position */ + + struct rasops_info sf_ro; + + struct wsscreen_descr sf_wsd; + struct wsscreen_list sf_wsl; + struct wsscreen_descr *sf_scrlist[1]; + int sf_nscreens; +}; + +/* + * Selected framebuffer node on OBP systems if k/d console. + */ +extern int fbnode; + +void fb_setsize(struct sunfb*, int, int, int, int, int); +void fbwscons_init(struct sunfb *, int, int); +void fbwscons_console_init(struct sunfb *, int); +void fbwscons_setcolormap(struct sunfb *, + void (*)(void *, u_int, u_int8_t, u_int8_t, u_int8_t)); +void fbwscons_attach(struct sunfb *, struct wsdisplay_accessops *, int); + +int ifb_ident(void *); \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/fenv.h b/lib/libc/include/sparc64-openbsd-none/sparc64/fenv.h new file mode 100644 index 0000000000..9fb328fd32 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/fenv.h @@ -0,0 +1,108 @@ +/* $OpenBSD: fenv.h,v 1.4 2011/05/25 21:46:49 martynas Exp $ */ +/* $NetBSD: fenv.h,v 1.1.2.2 2011/02/08 16:19:41 bouyer Exp $ */ + +/*- + * Copyright (c) 2004-2005 David Schultz + * 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 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 AUTHOR 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. + * + * $FreeBSD$ + */ + +#ifndef _SPARC64_FENV_H_ +#define _SPARC64_FENV_H_ + +/* + * Each symbol representing a floating point exception expands to an integer + * constant expression with values, such that bitwise-inclusive ORs of _all + * combinations_ of the constants result in distinct values. + * + * We use such values that allow direct bitwise operations on FPU registers. + */ +#define FE_INEXACT 0x020 +#define FE_DIVBYZERO 0x040 +#define FE_UNDERFLOW 0x080 +#define FE_OVERFLOW 0x100 +#define FE_INVALID 0x200 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * exception constants defined above. + */ +#define FE_ALL_EXCEPT (FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | \ + FE_OVERFLOW | FE_INVALID) +#define _MASK_SHIFT 18 + +/* + * Each symbol representing the rounding direction, expands to an integer + * constant expression whose value is distinct non-negative value. + * + * We use such values that allow direct bitwise operations on FPU registers. + */ +#define FE_TONEAREST 0x0 +#define FE_TOWARDZERO 0x1 +#define FE_UPWARD 0x2 +#define FE_DOWNWARD 0x3 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * rounding direction constants defined above. + */ +#define _ROUND_MASK (FE_TONEAREST | FE_TOWARDZERO | FE_UPWARD | \ + FE_DOWNWARD) +#define _ROUND_SHIFT 30 + +/* + * fenv_t represents the entire floating-point environment. + */ +typedef unsigned long fenv_t; + +/* + * The following constant represents the default floating-point environment + * (that is, the one installed at program startup) and has type pointer to + * const-qualified fenv_t. + * + * It can be used as an argument to the functions within the header + * that manage the floating-point environment, namely fesetenv() and + * feupdateenv(). + */ +__BEGIN_DECLS +extern fenv_t __fe_dfl_env; +__END_DECLS +#define FE_DFL_ENV ((const fenv_t *)&__fe_dfl_env) + +/* + * fexcept_t represents the floating-point status flags collectively, including + * any status the implementation associates with the flags. + * + * A floating-point status flag is a system variable whose value is set (but + * never cleared) when a floating-point exception is raised, which occurs as a + * side effect of exceptional floating-point arithmetic to provide auxiliary + * information. + * + * A floating-point control mode is a system variable whose value may be set by + * the user to affect the subsequent behavior of floating-point arithmetic. + */ +typedef unsigned long fexcept_t; + +#endif /* !_SPARC64_FENV_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/frame.h b/lib/libc/include/sparc64-openbsd-none/sparc64/frame.h new file mode 100644 index 0000000000..4b077a0ce6 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/frame.h @@ -0,0 +1,105 @@ +/* $OpenBSD: frame.h,v 1.11 2024/04/08 20:07:53 miod Exp $ */ +/* $NetBSD: frame.h,v 1.9 2001/03/04 09:28:35 mrg Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)frame.h 8.1 (Berkeley) 6/11/93 + */ + +#ifndef _MACHINE_FRAME_H_ +#define _MACHINE_FRAME_H_ + +/* + * CC64FSZ (C Compiler 64-bit Frame SiZe) is the size of a stack frame used + * by the compiler in 64-bit mode. It is (16)*8; space for 8 ins, 8 outs. + */ +#define CC64FSZ 176 + +/* + * v9 stacks all have a bias of 2047 added to the %sp and %fp, so you can easily + * detect it by testing the register for an odd value. Why 2K-1 I don't know. + */ +#define BIAS (2048-1) + +#if defined(_KERNEL) && !defined(_LOCORE) + +/* + * Sparc v9 stack frame format. + * + * Note that the contents of each stack frame may be held only in + * machine register windows. In order to get an accurate picture + * of the frame, you must first force the kernel to write any such + * windows to the stack. + * + * V9 frames have an odd bias, so you can tell a v9 frame from + * a v8 frame by testing the stack pointer's lsb. + */ +struct frame { + int64_t fr_local[8]; /* space to save locals (%l0..%l7) */ + int64_t fr_arg[6]; /* space to save arguments (%i0..%i5) */ + u_int64_t fr_fp; /* space to save frame pointer (%i6) */ + u_int64_t fr_pc; /* space to save return pc (%i7) */ + /* + * SVR4 reserves a bunch of extra stuff. + */ + int64_t fr_argd[6]; /* `register save area' (lunacy) */ + int64_t fr_argx[0]; /* arg extension (args 7..n; variable size) */ +}; + +#define v9next_frame(f) ((struct frame*)(f->fr_fp+BIAS)) + +/* + * The v9 trapframe. + */ +struct trapframe { + int64_t tf_tstate; /* tstate register */ + int64_t tf_pc; /* return pc */ + int64_t tf_npc; /* return npc */ + int tf_y; /* %y register -- 32-bits */ + short tf_tt; /* What type of trap this was */ + char tf_pil; /* What IRQ we're handling */ + char tf_oldpil; /* What our old SPL was */ + int64_t tf_global[8]; /* global registers in trap's caller */ + int64_t tf_out[8]; /* output registers in trap's caller */ + int64_t tf_local[8]; /* local registers in trap's caller */ + int64_t tf_in[8]; /* in registers in trap's caller (for debug) */ +}; + +#endif /* _KERNEL && !_LOCORE */ + +#endif /* _MACHINE_FRAME_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/fsr.h b/lib/libc/include/sparc64-openbsd-none/sparc64/fsr.h new file mode 100644 index 0000000000..d6689e55f9 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/fsr.h @@ -0,0 +1,132 @@ +/* $OpenBSD: fsr.h,v 1.2 2003/06/02 23:27:56 millert Exp $ */ +/* $NetBSD: fsr.h,v 1.1.1.1 1998/06/20 04:58:51 eeh Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)fsr.h 8.1 (Berkeley) 6/11/93 + */ + +#ifndef _MACHINE_FSR_H_ +#define _MACHINE_FSR_H_ + +/* + * Bits in FPRS + */ +#define FPRS_FEF 0x04 /* Enable FP -- must be set to enable FP regs */ +#define FPRS_DU 0x02 /* Dirty upper -- upper fp regs are dirty */ +#define FPRS_DL 0x01 /* Dirty lower -- lower fp regs are dirty */ + +/* + * Bits in FSR. + */ + +#define FSR_RD 0xc0000000 /* rounding direction */ +#define FSR_RD_RN 0 /* round to nearest */ +#define FSR_RD_RZ 1 /* round towards 0 */ +#define FSR_RD_RP 2 /* round towards +inf */ +#define FSR_RD_RM 3 /* round towards -inf */ +#define FSR_RD_SHIFT 30 +#define FSR_RD_MASK 0x03 + +#define FSR_RP 0x30000000 /* extended rounding precision */ +#define FSR_RP_X 0 /* extended stays extended */ +#define FSR_RP_S 1 /* extended => single */ +#define FSR_RP_D 2 /* extended => double */ +#define FSR_RP_80 3 /* extended => 80-bit */ +#define FSR_RP_SHIFT 28 +#define FSR_RP_MASK 0x03 + +#define FSR_TEM 0x0f800000 /* trap enable mask */ +#define FSR_TEM_SHIFT 23 +#define FSR_TEM_MASK 0x1f + +#define FSR_NS 0x00400000 /* ``nonstandard mode'' */ +#define FSR_AU 0x00400000 /* aka abrupt underflow mode */ +#define FSR_MBZ 0x00300000 /* reserved; must be zero */ + +#define FSR_VER 0x000e0000 /* version bits */ +#define FSR_VER_SHIFT 17 +#define FSR_VER_MASK 0x07 + +#define FSR_FTT 0x0001c000 /* FP trap type */ +#define FSR_TT_NONE 0 /* no trap */ +#define FSR_TT_IEEE 1 /* IEEE exception */ +#define FSR_TT_UNFIN 2 /* unfinished operation */ +#define FSR_TT_UNIMP 3 /* unimplemented operation */ +#define FSR_TT_SEQ 4 /* sequence error */ +#define FSR_TT_HWERR 5 /* hardware error (unrecoverable) */ +#define FSR_FTT_SHIFT 14 +#define FSR_FTT_MASK 0x03 + +#define FSR_QNE 0x00002000 /* queue not empty */ +#define FSR_PR 0x00001000 /* partial result */ + +#define FSR_FCC 0x00000c00 /* FP condition codes */ +#define FSR_CC_EQ 0 /* f1 = f2 */ +#define FSR_CC_LT 1 /* f1 < f2 */ +#define FSR_CC_GT 2 /* f1 > f2 */ +#define FSR_CC_UO 3 /* (f1,f2) unordered */ +#define FSR_FCC_SHIFT 10 +#define FSR_FCC_MASK 0x03 + +#define FSR_AX 0x000003e0 /* accrued exceptions */ +#define FSR_AX_SHIFT 5 +#define FSR_AX_MASK 0x1f +#define FSR_CX 0x0000001f /* current exceptions */ +#define FSR_CX_SHIFT 0 +#define FSR_CX_MASK 0x1f + +/* These are the 3 new v9 fcc's */ +#define FSR_FCC3 0x06000000000 /* FP condition codes */ +#define FSR_FCC3_SHIFT 36 + +#define FSR_FCC2 0x0c00000000 /* FP condition codes */ +#define FSR_FCC2_SHIFT 34 + +#define FSR_FCC1 0x0600000000 /* FP condition codes */ +#define FSR_FCC1_SHIFT 32 + + +/* The following exceptions apply to TEM, AX, and CX. */ +#define FSR_NV 0x10 /* invalid operand */ +#define FSR_OF 0x08 /* overflow */ +#define FSR_UF 0x04 /* underflow */ +#define FSR_DZ 0x02 /* division by zero */ +#define FSR_NX 0x01 /* inexact result */ + +#endif /* _MACHINE_FSR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/hypervisor.h b/lib/libc/include/sparc64-openbsd-none/sparc64/hypervisor.h new file mode 100644 index 0000000000..c8d8cc48dc --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/hypervisor.h @@ -0,0 +1,348 @@ +/* $OpenBSD: hypervisor.h,v 1.21 2024/04/08 20:00:27 miod Exp $ */ + +/* + * Copyright (c) 2008 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * UltraSPARC Hypervisor API. + */ + +/* + * API versioning + */ + +int64_t hv_api_get_version(uint64_t api_group, + uint64_t *major_number, uint64_t *minor_number); + +/* + * Domain services + */ + +int64_t hv_mach_desc(paddr_t buffer, psize_t *length); +int64_t hv_mach_pri(paddr_t buffer, psize_t *length); + +/* + * CPU services + */ + +void hv_cpu_yield(void); +int64_t hv_cpu_qconf(uint64_t queue, uint64_t base, uint64_t nentries); + +#define CPU_MONDO_QUEUE 0x3c +#define DEVICE_MONDO_QUEUE 0x3d +#define RESUMABLE_ERROR_QUEUE 0x3e +#define NONRESUMABLE_ERROR_QUEUE 0x3f + +int64_t hv_cpu_mondo_send(uint64_t ncpus, paddr_t cpulist, paddr_t data); +int64_t hv_cpu_myid(uint64_t *cpuid); + +/* + * MMU services + */ + +int64_t hv_mmu_demap_page(vaddr_t vaddr, uint64_t context, uint64_t flags); +int64_t hv_mmu_demap_ctx(uint64_t context, uint64_t flags); +int64_t hv_mmu_map_perm_addr(vaddr_t vaddr, uint64_t tte, uint64_t flags); +int64_t hv_mmu_unmap_perm_addr(vaddr_t vaddr, uint64_t flags); +int64_t hv_mmu_map_addr(vaddr_t vaddr, uint64_t context, uint64_t tte, + uint64_t flags); +int64_t hv_mmu_unmap_addr(vaddr_t vaddr, uint64_t context, uint64_t flags); + +#define MAP_DTLB 0x1 +#define MAP_ITLB 0x2 + +struct tsb_desc { + uint16_t td_idxpgsz; + uint16_t td_assoc; + uint32_t td_size; + uint32_t td_ctxidx; + uint32_t td_pgsz; + paddr_t td_pa; + uint64_t td_reserved; +}; + +int64_t hv_mmu_tsb_ctx0(uint64_t ntsb, paddr_t tsbptr); +int64_t hv_mmu_tsb_ctxnon0(uint64_t ntsb, paddr_t tsbptr); + +/* + * Cache and memory services + */ + +int64_t hv_mem_scrub(paddr_t raddr, psize_t length); +int64_t hv_mem_sync(paddr_t raddr, psize_t length); + +/* + * Device interrupt services + */ + +int64_t hv_intr_devino_to_sysino(uint64_t devhandle, uint64_t devino, + uint64_t *sysino); +int64_t hv_intr_getenabled(uint64_t sysino, uint64_t *intr_enabled); +int64_t hv_intr_setenabled(uint64_t sysino, uint64_t intr_enabled); +int64_t hv_intr_getstate(uint64_t sysino, uint64_t *intr_state); +int64_t hv_intr_setstate(uint64_t sysino, uint64_t intr_state); +int64_t hv_intr_gettarget(uint64_t sysino, uint64_t *cpuid); +int64_t hv_intr_settarget(uint64_t sysino, uint64_t cpuid); + +#define INTR_DISABLED 0 +#define INTR_ENABLED 1 + +#define INTR_IDLE 0 +#define INTR_RECEIVED 1 +#define INTR_DELIVERED 2 + +int64_t hv_vintr_getcookie(uint64_t devhandle, uint64_t devino, + uint64_t *cookie_value); +int64_t hv_vintr_setcookie(uint64_t devhandle, uint64_t devino, + uint64_t cookie_value); +int64_t hv_vintr_getenabled(uint64_t devhandle, uint64_t devino, + uint64_t *intr_enabled); +int64_t hv_vintr_setenabled(uint64_t devhandle, uint64_t devino, + uint64_t intr_enabled); +int64_t hv_vintr_getstate(uint64_t devhandle, uint64_t devino, + uint64_t *intr_state); +int64_t hv_vintr_setstate(uint64_t devhandle, uint64_t devino, + uint64_t intr_state); +int64_t hv_vintr_gettarget(uint64_t devhandle, uint64_t devino, + uint64_t *cpuid); +int64_t hv_vintr_settarget(uint64_t devhandle, uint64_t devino, + uint64_t cpuid); + +/* + * Time of day services + */ + +int64_t hv_tod_get(uint64_t *tod); +int64_t hv_tod_set(uint64_t tod); + +/* + * Console services + */ + +int64_t hv_cons_getchar(int64_t *ch); +int64_t hv_cons_putchar(int64_t ch); +int64_t hv_api_putchar(int64_t ch); + +#define CONS_BREAK -1 +#define CONS_HUP -2 + +/* + * Domain state services + */ + +int64_t hv_soft_state_set(uint64_t software_state, + paddr_t software_description_ptr); + +#define SIS_NORMAL 0x1 +#define SIS_TRANSITION 0x2 + +/* + * PCI I/O services + */ + +int64_t hv_pci_iommu_map(uint64_t devhandle, uint64_t tsbid, + uint64_t nttes, uint64_t io_attributes, paddr_t io_page_list_p, + uint64_t *nttes_mapped); +int64_t hv_pci_iommu_demap(uint64_t devhandle, uint64_t tsbid, + uint64_t nttes, uint64_t *nttes_demapped); +int64_t hv_pci_iommu_getmap(uint64_t devhandle, uint64_t tsbid, + uint64_t *io_attributes, paddr_t *r_addr); +int64_t hv_pci_iommu_getbypass(uint64_t devhandle, paddr_t r_addr, + uint64_t io_attributes, uint64_t *io_addr); + +int64_t hv_pci_config_get(uint64_t devhandle, uint64_t pci_device, + uint64_t pci_config_offset, uint64_t size, + uint64_t *error_flag, uint64_t *data); +int64_t hv_pci_config_put(uint64_t devhandle, uint64_t pci_device, + uint64_t pci_config_offset, uint64_t size, uint64_t data, + uint64_t *error_flag); + +#define PCI_MAP_ATTR_READ 0x01 /* From memory */ +#define PCI_MAP_ATTR_WRITE 0x02 /* To memory */ + +/* + * PCI MSI services + */ + +int64_t hv_pci_msiq_conf(uint64_t devhandle, uint64_t msiqid, + uint64_t r_addr, uint64_t nentries); +int64_t hv_pci_msiq_info(uint64_t devhandle, uint64_t msiqid, + uint64_t *r_addr, uint64_t *nentries); + +int64_t hv_pci_msiq_getvalid(uint64_t devhandle, uint64_t msiqid, + uint64_t *msiqvalid); +int64_t hv_pci_msiq_setvalid(uint64_t devhandle, uint64_t msiqid, + uint64_t msiqvalid); + +#define PCI_MSIQ_INVALID 0 +#define PCI_MSIQ_VALID 1 + +int64_t hv_pci_msiq_getstate(uint64_t devhandle, uint64_t msiqid, + uint64_t *msiqstate); +int64_t hv_pci_msiq_setstate(uint64_t devhandle, uint64_t msiqid, + uint64_t msiqstate); + +#define PCI_MSIQSTATE_IDLE 0 +#define PCI_MSIQSTATE_ERROR 1 + +int64_t hv_pci_msiq_gethead(uint64_t devhandle, uint64_t msiqid, + uint64_t *msiqhead); +int64_t hv_pci_msiq_sethead(uint64_t devhandle, uint64_t msiqid, + uint64_t msiqhead); +int64_t hv_pci_msiq_gettail(uint64_t devhandle, uint64_t msiqid, + uint64_t *msiqtail); + +int64_t hv_pci_msi_getvalid(uint64_t devhandle, uint64_t msinum, + uint64_t *msivalidstate); +int64_t hv_pci_msi_setvalid(uint64_t devhandle, uint64_t msinum, + uint64_t msivalidstate); + +#define PCI_MSI_INVALID 0 +#define PCI_MSI_VALID 1 + +int64_t hv_pci_msi_getmsiq(uint64_t devhandle, uint64_t msinum, + uint64_t *msiqid); +int64_t hv_pci_msi_setmsiq(uint64_t devhandle, uint64_t msinum, + uint64_t msitype, uint64_t msiqid); + +int64_t hv_pci_msi_getstate(uint64_t devhandle, uint64_t msinum, + uint64_t *msistate); +int64_t hv_pci_msi_setstate(uint64_t devhandle, uint64_t msinum, + uint64_t msistate); + +#define PCI_MSISTATE_IDLE 0 +#define PCI_MSISTATE_DELIVERED 1 + +int64_t hv_pci_msg_getmsiq(uint64_t devhandle, uint64_t msg, + uint64_t *msiqid); +int64_t hv_pci_msg_setmsiq(uint64_t devhandle, uint64_t msg, + uint64_t msiqid); + +int64_t hv_pci_msg_getvalid(uint64_t devhandle, uint64_t msg, + uint64_t *msgvalidstate); +int64_t hv_pci_msg_setvalid(uint64_t devhandle, uint64_t msg, + uint64_t msgvalidstate); + +#define PCIE_MSG_INVALID 0 +#define PCIE_MSG_VALID 1 + +#define PCIE_PME_MSG 0x18 +#define PCIE_PME_ACK_MSG 0x1b +#define PCIE_CORR_MSG 0x30 +#define PCIE_NONFATAL_MSG 0x31 +#define PCIE_FATAL_MSG 0x32 + +/* + * Logical Domain Channel services + */ + +int64_t hv_ldc_tx_qconf(uint64_t ldc_id, paddr_t base_raddr, + uint64_t nentries); +int64_t hv_ldc_tx_qinfo(uint64_t ldc_id, paddr_t *base_raddr, + uint64_t *nentries); +int64_t hv_ldc_tx_get_state(uint64_t ldc_id, uint64_t *head_offset, + uint64_t *tail_offset, uint64_t *channel_state); +int64_t hv_ldc_tx_set_qtail(uint64_t ldc_id, uint64_t tail_offset); +int64_t hv_ldc_rx_qconf(uint64_t ldc_id, paddr_t base_raddr, + uint64_t nentries); +int64_t hv_ldc_rx_qinfo(uint64_t ldc_id, paddr_t *base_raddr, + uint64_t *nentries); +int64_t hv_ldc_rx_get_state(uint64_t ldc_id, uint64_t *head_offset, + uint64_t *tail_offset, uint64_t *channel_state); +int64_t hv_ldc_rx_set_qhead(uint64_t ldc_id, uint64_t head_offset); + +#define LDC_CHANNEL_DOWN 0 +#define LDC_CHANNEL_UP 1 +#define LDC_CHANNEL_RESET 2 + +/* Used by drivers only, not part of the hypervisor API. */ +#define LDC_CHANNEL_INIT ((uint64_t)-1) + +int64_t hv_ldc_set_map_table(uint64_t ldc_id, paddr_t base_raddr, + uint64_t nentries); +int64_t hv_ldc_get_map_table(uint64_t ldc_id, paddr_t *base_raddr, + uint64_t *nentries); +int64_t hv_ldc_copy(uint64_t ldc_id, uint64_t flags, uint64_t cookie, + paddr_t raddr, psize_t length, psize_t *ret_length); + +#define LDC_COPY_IN 0 +#define LDC_COPY_OUT 1 + +int64_t hv_ldc_mapin(uint64_t ldc_id, uint64_t cookie, paddr_t *raddr, + uint64_t *perms); +int64_t hv_ldc_unmap(paddr_t raddr, uint64_t *perms); + +/* + * Static Direct I/O services + */ + +int64_t hv_pci_iov_root_configured(uint64_t devhandle); +int64_t hv_pci_real_config_get(uint64_t devhandle, uint64_t pci_device, + uint64_t pci_config_offset, uint64_t size, + uint64_t *error_flag, uint64_t *data); +int64_t hv_pci_real_config_put(uint64_t devhandle, uint64_t pci_device, + uint64_t pci_config_offset, uint64_t size, uint64_t data, + uint64_t *error_flag); +int64_t hv_pci_error_send(uint64_t devhandle, uint64_t devino, + uint64_t pci_device); + +/* + * Cryptographic services + */ + +int64_t hv_rng_get_diag_control(void); +int64_t hv_rng_ctl_read(paddr_t raddr, uint64_t *state, uint64_t *delta); +int64_t hv_rng_ctl_write(paddr_t raddr, uint64_t state, uint64_t timeout, + uint64_t *delta); + +#define RNG_STATE_UNCONFIGURED 0 +#define RNG_STATE_CONFIGURED 1 +#define RNG_STATE_HEALTHCHECK 2 +#define RNG_STATE_ERROR 3 + +int64_t hv_rng_data_read_diag(paddr_t raddr, uint64_t size, uint64_t *delta); +int64_t hv_rng_data_read(paddr_t raddr, uint64_t *delta); + +/* + * Error codes + */ + +#define H_EOK 0 +#define H_ENOCPU 1 +#define H_ENORADDR 2 +#define H_ENOINTR 3 +#define H_EBADPGSZ 4 +#define H_EBADTSB 5 +#define H_EINVAL 6 +#define H_EBADTRAP 7 +#define H_EBADALIGN 8 +#define H_EWOULDBLOCK 9 +#define H_ENOACCESS 10 +#define H_EIO 11 +#define H_ECPUERROR 12 +#define H_ENOTSUPPORTED 13 +#define H_ENOMAP 14 +#define H_ETOOMANY 15 +#define H_ECHANNEL 16 + +extern uint64_t sun4v_group_interrupt_major; +extern uint64_t sun4v_group_sdio_major; + +int64_t sun4v_intr_devino_to_sysino(uint64_t, uint64_t, uint64_t *); +int64_t sun4v_intr_setcookie(uint64_t, uint64_t, uint64_t); +int64_t sun4v_intr_setenabled(uint64_t, uint64_t, uint64_t); +int64_t sun4v_intr_setstate(uint64_t, uint64_t, uint64_t); +int64_t sun4v_intr_settarget(uint64_t, uint64_t, uint64_t); \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/idprom.h b/lib/libc/include/sparc64-openbsd-none/sparc64/idprom.h new file mode 100644 index 0000000000..0332fc8f2e --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/idprom.h @@ -0,0 +1,52 @@ +/* $OpenBSD: idprom.h,v 1.3 2024/03/29 21:06:14 miod Exp $ */ +/* $NetBSD: idprom.h,v 1.2 1998/09/05 23:57:26 eeh Exp $ */ + +/* + * Copyright (c) 1993 Adam Glass + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Adam Glass. + * 4. The name of the Author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Adam Glass ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * ID prom format. The ``host id'' is set up by taking the machine + * ID as the top byte and the hostid field as the remaining three. + * The id_xxx0 field appears to contain some other number. The id_xxx1 + * contains a bunch of 00's and a5's on my machines, suggesting it is + * not actually used. The checksum seems to include them, however. + */ +struct idprom { + u_char id_format; /* format identifier (= 1) */ + u_char id_machine; /* machine type (see param.h) */ + u_char id_ether[6]; /* ethernet address */ + int id_date; /* date of manufacture */ + u_char id_hostid[3]; /* ``host id'' bytes */ + u_char id_checksum; /* xor of everything else */ + char id_undef[16]; /* undefined */ +}; + +#define IDPROM_VERSION 1 \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/ieee.h b/lib/libc/include/sparc64-openbsd-none/sparc64/ieee.h new file mode 100644 index 0000000000..9d22c7a0de --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/ieee.h @@ -0,0 +1,148 @@ +/* $OpenBSD: ieee.h,v 1.4 2017/04/16 14:20:49 kettenis Exp $ */ +/* $NetBSD: ieee.h,v 1.1.1.1 1998/06/20 04:58:51 eeh Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)ieee.h 8.1 (Berkeley) 6/11/93 + */ + +/* + * ieee.h defines the machine-dependent layout of the machine's IEEE + * floating point. It does *not* define (yet?) any of the rounding + * mode bits, exceptions, and so forth. + */ + +/* + * Define the number of bits in each fraction and exponent. + * + * k k+1 + * Note that 1.0 x 2 == 0.1 x 2 and that denorms are represented + * + * (-exp_bias+1) + * as fractions that look like 0.fffff x 2 . This means that + * + * -126 + * the number 0.10000 x 2 , for instance, is the same as the normalized + * + * -127 -128 + * float 1.0 x 2 . Thus, to represent 2 , we need one leading zero + * + * -129 + * in the fraction; to represent 2 , we need two, and so on. This + * + * (-exp_bias-fracbits+1) + * implies that the smallest denormalized number is 2 + * + * for whichever format we are talking about: for single precision, for + * + * -126 -149 + * instance, we get .00000000000000000000001 x 2 , or 1.0 x 2 , and + * + * -149 == -127 - 23 + 1. + */ +#define SNG_EXPBITS 8 +#define SNG_FRACBITS 23 + +#define DBL_EXPBITS 11 +#define DBL_FRACHBITS 20 +#define DBL_FRACLBITS 32 +#define DBL_FRACBITS 52 + +#define EXT_EXPBITS 15 +#define EXT_FRACHBITS 16 +#define EXT_FRACHMBITS 32 +#define EXT_FRACLMBITS 32 +#define EXT_FRACLBITS 32 +#define EXT_FRACBITS 112 + +#define EXT_IMPLICIT_NBIT + +#define EXT_TO_ARRAY32(p, a) do { \ + (a)[0] = (uint32_t)(p)->ext_fracl; \ + (a)[1] = (uint32_t)(p)->ext_fraclm; \ + (a)[2] = (uint32_t)(p)->ext_frachm; \ + (a)[3] = (uint32_t)(p)->ext_frach; \ +} while(0) + +struct ieee_single { + u_int sng_sign:1; + u_int sng_exp:8; + u_int sng_frac:23; +}; + +struct ieee_double { + u_int dbl_sign:1; + u_int dbl_exp:11; + u_int dbl_frach:20; + u_int dbl_fracl; +}; + +struct ieee_ext { + u_int ext_sign:1; + u_int ext_exp:15; + u_int ext_frach:16; + u_int ext_frachm; + u_int ext_fraclm; + u_int ext_fracl; +}; + +/* + * Floats whose exponent is in [1..INFNAN) (of whatever type) are + * `normal'. Floats whose exponent is INFNAN are either Inf or NaN. + * Floats whose exponent is zero are either zero (iff all fraction + * bits are zero) or subnormal values. + * + * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its + * high fraction; if the bit is set, it is a `quiet NaN'. + */ +#define SNG_EXP_INFNAN 255 +#define DBL_EXP_INFNAN 2047 +#define EXT_EXP_INFNAN 32767 + +#if 0 +#define SNG_QUIETNAN (1 << 22) +#define DBL_QUIETNAN (1 << 19) +#define EXT_QUIETNAN (1 << 15) +#endif + +/* + * Exponent biases. + */ +#define SNG_EXP_BIAS 127 +#define DBL_EXP_BIAS 1023 +#define EXT_EXP_BIAS 16383 \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/ieeefp.h b/lib/libc/include/sparc64-openbsd-none/sparc64/ieeefp.h new file mode 100644 index 0000000000..0997cfae6d --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/ieeefp.h @@ -0,0 +1,24 @@ +/* $OpenBSD: ieeefp.h,v 1.3 2011/03/23 16:54:37 pirofti Exp $ */ +/* + * Written by J.T. Conklin, Apr 6, 1995 + * Public domain. + */ + +#ifndef _MACHINE_IEEEFP_H_ +#define _MACHINE_IEEEFP_H_ + +typedef int fp_except; +#define FP_X_IMP 0x01 /* imprecise (loss of precision) */ +#define FP_X_DZ 0x02 /* divide-by-zero exception */ +#define FP_X_UFL 0x04 /* underflow exception */ +#define FP_X_OFL 0x08 /* overflow exception */ +#define FP_X_INV 0x10 /* invalid operation exception */ + +typedef enum { + FP_RN=0, /* round to nearest representable number */ + FP_RZ=1, /* round to zero (truncate) */ + FP_RP=2, /* round toward positive infinity */ + FP_RM=3 /* round toward negative infinity */ +} fp_rnd; + +#endif /* _MACHINE_IEEEFP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/instr.h b/lib/libc/include/sparc64-openbsd-none/sparc64/instr.h new file mode 100644 index 0000000000..9054144e97 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/instr.h @@ -0,0 +1,502 @@ +/* $OpenBSD: instr.h,v 1.8 2025/07/16 07:15:42 jsg Exp $ */ +/* $NetBSD: instr.h,v 1.3 2000/01/10 03:53:20 eeh Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)instr.h 8.1 (Berkeley) 6/11/93 + */ + +/* see also Appendix F of the SPARC version 8 document */ +enum IOP { IOP_OP2, IOP_CALL, IOP_reg, IOP_mem }; +enum IOP2 { IOP2_UNIMP, IOP2_BPcc, IOP2_Bicc, IOP2_BPr, + IOP2_SETHI, IOP2_FBPfcc, IOP2_FBfcc, IOP2_CBccc }; +enum IOP3_reg { + IOP3_ADD, IOP3_AND, IOP3_OR, IOP3_XOR, + IOP3_SUB, IOP3_ANDN, IOP3_ORN, IOP3_XNOR, + IOP3_ADDX, IOP3_MULX, IOP3_UMUL, IOP3_SMUL, + IOP3_SUBX, IOP3_UDIVX, IOP3_UDIV, IOP3_SDIV, + IOP3_ADDcc, IOP3_ANDcc, IOP3_ORcc, IOP3_XORcc, + IOP3_SUBcc, IOP3_ANDNcc, IOP3_ORNcc, IOP3_XNORcc, + IOP3_ADDXcc, IOP3_rerr19, IOP3_UMULcc, IOP3_SMULcc, + IOP3_SUBXcc, IOP3_rerr1d, IOP3_UDIVcc, IOP3_SDIVcc, + IOP3_TADDcc, IOP3_TSUBcc, IOP3_TADDccTV, IOP3_TSUBccTV, + IOP3_MULScc, IOP3_SLL, IOP3_SRL, IOP3_SRA, + IOP3_RDASR_RDY_STBAR, IOP3_RDPSR, IOP3_RDWIM, IOP3_RDTGBR, + IOP3_MOVcc, IOP3_SDIVX, IOP3_POPC, IOP3_MOVr, + IOP3_WRASR_WRY, IOP3_WRPSR, IOP3_WRWIM, IOP3_WRTBR, + IOP3_FPop1, IOP3_FPop2, IOP3_CPop1, IOP3_CPop2, + IOP3_JMPL, IOP3_RETT, IOP3_Ticc, IOP3_FLUSH, + IOP3_SAVE, IOP3_RESTORE, IOP3_DONE_RETRY, IOP3_rerr3f +}; +enum IOP3_mem { + IOP3_LD, IOP3_LDUB, IOP3_LDUH, IOP3_LDD, + IOP3_ST, IOP3_STB, IOP3_STH, IOP3_STD, + IOP3_LDSW, IOP3_LDSB, IOP3_LDSH, IOP3_LDX, + IOP3_merr0c, IOP3_LDSTUB, IOP3_STX, IOP3_SWAP, + IOP3_LDA, IOP3_LDUBA, IOP3_LDUHA, IOP3_LDDA, + IOP3_STA, IOP3_STBA, IOP3_STHA, IOP3_STDA, + IOP3_LDSWA, IOP3_LDSBA, IOP3_LDSHA, IOP3_LDXA, + IOP3_merr1c, IOP3_LDSTUBA, IOP3_STXA, IOP3_SWAPA, + IOP3_LDF, IOP3_LDFSR, IOP3_LDQF, IOP3_LDDF, + IOP3_STF, IOP3_STFSR, IOP3_STQF, IOP3_STDF, + IOP3_merr28, IOP3_merr29, IOP3_merr2a, IOP3_merr2b, + IOP3_merr2c, IOP3_PREFETCH, IOP3_merr2e, IOP3_merr2f, + IOP3_LFC, IOP3_LDCSR, IOP3_LDQFA, IOP3_LDDC, + IOP3_STC, IOP3_STCSR, IOP3_STQFA, IOP3_STDC, + IOP3_merr38, IOP3_merr39, IOP3_merr3a, IOP3_merr3b, + IOP3_CASA, IOP3_PREFETCHA, IOP3_CASXA, IOP3_merr3f +}; + +/* + * Integer condition codes. + */ +#define Icc_N 0x0 /* never */ +#define Icc_E 0x1 /* equal (equiv. zero) */ +#define Icc_LE 0x2 /* less or equal */ +#define Icc_L 0x3 /* less */ +#define Icc_LEU 0x4 /* less or equal unsigned */ +#define Icc_CS 0x5 /* carry set (equiv. less unsigned) */ +#define Icc_NEG 0x6 /* negative */ +#define Icc_VS 0x7 /* overflow set */ +#define Icc_A 0x8 /* always */ +#define Icc_NE 0x9 /* not equal (equiv. not zero) */ +#define Icc_G 0xa /* greater */ +#define Icc_GE 0xb /* greater or equal */ +#define Icc_GU 0xc /* greater unsigned */ +#define Icc_CC 0xd /* carry clear (equiv. gtr or eq unsigned) */ +#define Icc_POS 0xe /* positive */ +#define Icc_VC 0xf /* overflow clear */ + +/* + * Integer registers. + */ +#define I_G0 0 +#define I_G1 1 +#define I_G2 2 +#define I_G3 3 +#define I_G4 4 +#define I_G5 5 +#define I_G6 6 +#define I_G7 7 +#define I_O0 8 +#define I_O1 9 +#define I_O2 10 +#define I_O3 11 +#define I_O4 12 +#define I_O5 13 +#define I_O6 14 +#define I_O7 15 +#define I_L0 16 +#define I_L1 17 +#define I_L2 18 +#define I_L3 19 +#define I_L4 20 +#define I_L5 21 +#define I_L6 22 +#define I_L7 23 +#define I_I0 24 +#define I_I1 25 +#define I_I2 26 +#define I_I3 27 +#define I_I4 28 +#define I_I5 29 +#define I_I6 30 +#define I_I7 31 + +/* + * An instruction. + */ +union instr { + int i_int; /* as a whole */ + + /* + * The first level of decoding is to use the top 2 bits. + * This gives us one of three `formats', which usually give + * a second level of decoding. + */ + struct { + u_int i_op:2; /* first-level decode */ + u_int :30; + } i_any; + + /* + * Format 1 instructions: CALL (undifferentiated). + */ + struct { + u_int :2; /* 01 */ + int i_disp:30; /* displacement */ + } i_call; + + /* + * Format 2 instructions (SETHI, UNIMP, and branches, plus illegal + * unused codes). + */ + struct { + u_int :2; /* 00 */ + u_int :5; + u_int i_op2:3; /* second-level decode */ + u_int :22; + } i_op2; + + /* UNIMP, SETHI */ + struct { + u_int :2; /* 00 */ + u_int i_rd:5; /* destination register */ + u_int i_op2:3; /* opcode: UNIMP or SETHI */ + u_int i_imm:22; /* immediate value */ + } i_imm22; + + /* branches: Bicc, FBfcc, CBccc */ + struct { + u_int :2; /* 00 */ + u_int i_annul:1; /* annul bit */ + u_int i_cond:4; /* condition codes */ + u_int i_op2:3; /* opcode: {Bi,FBf,CBc}cc */ + int i_disp:22; /* branch displacement */ + } i_branch; + + /* more branches: BPcc, FBPfcc */ + struct { + u_int :2; /* 00 */ + u_int i_annul:1; /* annul bit */ + u_int i_cond:4; /* condition codes */ + u_int i_op2:3; /* opcode: {BP,FBPf}cc */ + u_int i_cc:2; /* condition code selector */ + u_int i_pred:1; /* branch prediction bit */ + int i_disp:19; /* branch displacement */ + } i_branch_p; + + /* one last branch: BPr */ + struct { + u_int :2; /* 00 */ + u_int i_annul:1; /* annul bit */ + u_int :1; /* 0 */ + u_int i_rcond:4; /* register condition */ + u_int :3; /* 011 */ + int i_disphi:2; /* branch displacement, hi bits */ + u_int i_pred:1; /* branch prediction bit */ + u_int i_rs1:1; /* source register 1 */ + u_int i_displo:16; /* branch displacement, lo bits */ + } i_branch_pr; + + + /* + * Format 3 instructions (memory reference; arithmetic, logical, + * shift, and other miscellaneous operations). The second-level + * decode almost always makes use of an `rd' and `rs1', however + * (see also IOP3_reg and IOP3_mem). + * + * Beyond that, the low 14 bits may be broken up in one of three + * different ways, if at all: + * 1 bit of imm=0 + 8 bits of asi + 5 bits of rs2 [reg & mem] + * 1 bit of imm=1 + 13 bits of signed immediate [reg & mem] + * 9 bits of coprocessor `opf' opcode + 5 bits of rs2 [reg only] + */ + struct { + u_int :2; /* 10 or 11 */ + u_int i_rd:5; /* destination register */ + u_int i_op3:6; /* second-level decode */ + u_int i_rs1:5; /* source register 1 */ + u_int i_low14:14; /* varies */ + } i_op3; + + /* + * Memory forms. These set i_op=3 and use simm13 or asi layout. + * Memory references without an ASI should use 0, but the actual + * ASI field is simply ignored. + */ + struct { + u_int :2; /* 11 only */ + u_int i_rd:5; /* destination register */ + u_int i_op3:6; /* second-level decode (see IOP3_mem) */ + u_int i_rs1:5; /* source register 1 */ + u_int i_i:1; /* immediate vs asi */ + u_int i_low13:13; /* depend on i bit */ + } i_loadstore; + + /* + * Memory and register forms. + * These come in quite a variety and we do not + * attempt to break them down much. + */ + struct { + u_int :2; /* 10 or 11 */ + u_int i_rd:5; /* destination register */ + u_int i_op3:6; /* second-level decode */ + u_int i_rs1:5; /* source register 1 */ + u_int i_i:1; /* immediate bit (1) */ + int i_simm13:13; /* signed immediate */ + } i_simm13; + struct { + u_int :2; /* 10 or 11 */ + u_int i_rd:5; /* destination register */ + u_int i_op3:6; /* second-level decode */ + u_int i_rs1:5; /* source register 1 */ + u_int i_i:1; /* immediate vs asi */ + u_int i_asi:8; /* asi */ + u_int i_rs2:5; /* source register 2 */ + } i_asi; + struct { + u_int :2; /* 10 only (register, no memory) */ + u_int i_rd:5; /* destination register */ + u_int i_op3:6; /* second-level decode (see IOP3_reg) */ + u_int i_rs1:5; /* source register 1 */ + u_int i_opf:9; /* coprocessor 3rd-level decode */ + u_int i_rs2:5; /* source register 2 */ + } i_opf; + + /* + * Format 4 instructions (movcc, fmovr, fmovcc, and tcc). The + * second-level decode almost always makes use of an `rd' and either + * `rs1' or `cond'. + * + * Beyond that, the low 14 bits may be broken up in one of three + * different ways, if at all: + * 1 bit of imm=0 + 8 bits of asi + 5 bits of rs2 [reg & mem] + * 1 bit of imm=1 + 13 bits of signed immediate [reg & mem] + * 9 bits of coprocessor `opf' opcode + 5 bits of rs2 [reg only] */ + struct { + u_int :2; /* 10 */ + u_int i_rd:5; /* destination register */ + u_int i_op3:6; /* second-level decode */ + u_int i_rs1:5; /* source register 1 */ + u_int i_low14:14; /* varies */ + } i_op4; + + /* + * Move fp register on condition codes. + */ + struct { + u_int :2; /* 10 */ + u_int i_rd:5; /* destination register */ + u_int i_op3:6; /* second-level decode */ + u_int :1; + u_int i_cond:4; /* condition */ + u_int i_opf_cc:3; /* condition code register */ + u_int i_opf_low:6; /* third level decode */ + u_int i_rs2:5; /* source register */ + } i_fmovcc; + + /* + * Move fp register on integer register. + */ + struct { + u_int :2; /* 10 */ + u_int i_rd:5; /* destination register */ + u_int i_op3:6; /* second-level decode */ + u_int i_rs1:5; /* source register 1 */ + u_int :1; + u_int i_rcond:3; /* register condition */ + u_int i_opf_low:6; + u_int i_rs2:5; /* source register 2 */ + } i_fmovr; + +}; + +/* + * Internal macros for building instructions. These correspond 1-to-1 to + * the names above. Note that x << y | z == (x << y) | z. + */ +#define _I_ANY(op, b) ((op) << 30 | (b)) + +#define _I_OP2(high, op2, low) \ + _I_ANY(IOP_OP2, (high) << 25 | (op2) << 22 | (low)) +#define _I_IMM22(rd, op2, imm) \ + _I_ANY(IOP_OP2, (rd) << 25 | (op2) << 22 | (imm)) +#define _I_BRANCH(a, c, op2, disp) \ + _I_ANY(IOP_OP2, (a) << 29 | (c) << 25 | (op2) << 22 | (disp)) +#define _I_FBFCC(a, cond, disp) \ + _I_BRANCH(a, cond, IOP2_FBfcc, disp) +#define _I_CBCCC(a, cond, disp) \ + _I_BRANCH(a, cond, IOP2_CBccc, disp) + +#define _I_SIMM(simm) (1 << 13 | ((simm) & 0x1fff)) + +#define _I_OP3_GEN(form, rd, op3, rs1, low14) \ + _I_ANY(form, (rd) << 25 | (op3) << 19 | (rs1) << 14 | (low14)) +#define _I_OP3_LS_RAR(rd, op3, rs1, asi, rs2) \ + _I_OP3_GEN(IOP_mem, rd, op3, rs1, (asi) << 5 | (rs2)) +#define _I_OP3_LS_RI(rd, op3, rs1, simm13) \ + _I_OP3_GEN(IOP_mem, rd, op3, rs1, _I_SIMM(simm13)) +#define _I_OP3_LS_RR(rd, op3, rs1, rs2) \ + _I_OP3_GEN(IOP_mem, rd, op3, rs1, rs2) +#define _I_OP3_R_RAR(rd, op3, rs1, asi, rs2) \ + _I_OP3_GEN(IOP_reg, rd, op3, rs1, (asi) << 5 | (rs2)) +#define _I_OP3_R_RI(rd, op3, rs1, simm13) \ + _I_OP3_GEN(IOP_reg, rd, op3, rs1, _I_SIMM(simm13)) +#define _I_OP3_R_RR(rd, op3, rs1, rs2) \ + _I_OP3_GEN(IOP_reg, rd, op3, rs1, rs2) + +#define I_CALL(d) _I_ANY(IOP_CALL, d) +#define I_UNIMP(v) _I_IMM22(0, IOP2_UNIMP, v) +#define I_BN(a, d) _I_BRANCH(a, Icc_N, IOP2_Bicc, d) +#define I_BE(a, d) _I_BRANCH(a, Icc_E, IOP2_Bicc, d) +#define I_BZ(a, d) _I_BRANCH(a, Icc_E, IOP2_Bicc, d) +#define I_BLE(a, d) _I_BRANCH(a, Icc_LE, IOP2_Bicc, d) +#define I_BL(a, d) _I_BRANCH(a, Icc_L, IOP2_Bicc, d) +#define I_BLEU(a, d) _I_BRANCH(a, Icc_LEU, IOP2_Bicc, d) +#define I_BCS(a, d) _I_BRANCH(a, Icc_CS, IOP2_Bicc, d) +#define I_BLU(a, d) _I_BRANCH(a, Icc_CS, IOP2_Bicc, d) +#define I_BNEG(a, d) _I_BRANCH(a, Icc_NEG, IOP2_Bicc, d) +#define I_BVS(a, d) _I_BRANCH(a, Icc_VS, IOP2_Bicc, d) +#define I_BA(a, d) _I_BRANCH(a, Icc_A, IOP2_Bicc, d) +#define I_B(a, d) _I_BRANCH(a, Icc_A, IOP2_Bicc, d) +#define I_BNE(a, d) _I_BRANCH(a, Icc_NE, IOP2_Bicc, d) +#define I_BNZ(a, d) _I_BRANCH(a, Icc_NE, IOP2_Bicc, d) +#define I_BG(a, d) _I_BRANCH(a, Icc_G, IOP2_Bicc, d) +#define I_BGE(a, d) _I_BRANCH(a, Icc_GE, IOP2_Bicc, d) +#define I_BGU(a, d) _I_BRANCH(a, Icc_GU, IOP2_Bicc, d) +#define I_BCC(a, d) _I_BRANCH(a, Icc_CC, IOP2_Bicc, d) +#define I_BGEU(a, d) _I_BRANCH(a, Icc_CC, IOP2_Bicc, d) +#define I_BPOS(a, d) _I_BRANCH(a, Icc_POS, IOP2_Bicc, d) +#define I_BVC(a, d) _I_BRANCH(a, Icc_VC, IOP2_Bicc, d) +#define I_SETHI(r, v) _I_IMM22(r, 4, v) + +#define I_ORri(rd, rs1, imm) _I_OP3_R_RI(rd, IOP3_OR, rs1, imm) +#define I_ORrr(rd, rs1, rs2) _I_OP3_R_RR(rd, IOP3_OR, rs1, rs2) + +#define I_MOVi(rd, imm) _I_OP3_R_RI(rd, IOP3_OR, I_G0, imm) +#define I_MOVr(rd, rs) _I_OP3_R_RR(rd, IOP3_OR, I_G0, rs) + +#define I_RDPSR(rd) _I_OP3_R_RR(rd, IOP3_RDPSR, 0, 0) + +#define I_JMPLri(rd, rs1, imm) _I_OP3_R_RI(rd, IOP3_JMPL, rs1, imm) +#define I_JMPLrr(rd, rs1, rs2) _I_OP3_R_RR(rd, IOP3_JMPL, rs1, rs2) + +/* + * FPop values. + */ + +/* These are in FPop1 space */ +#define FMOVS 0x001 +#define FMOVD 0x002 +#define FMOVQ 0x003 +#define FNEGS 0x005 +#define FNEGD 0x006 +#define FNEGQ 0x007 +#define FABSS 0x009 +#define FABSD 0x00a +#define FABSQ 0x00b +#define FSQRTS 0x029 +#define FSQRTD 0x02a +#define FSQRTQ 0x02b +#define FADDS 0x041 +#define FADDD 0x042 +#define FADDQ 0x043 +#define FSUBS 0x045 +#define FSUBD 0x046 +#define FSUBQ 0x047 +#define FMULS 0x049 +#define FMULD 0x04a +#define FMULQ 0x04b +#define FDIVS 0x04d +#define FDIVD 0x04e +#define FDIVQ 0x04f +#define FSMULD 0x069 +#define FDMULQ 0x06e +#define FSTOX 0x081 +#define FDTOX 0x082 +#define FQTOX 0x083 +#define FXTOS 0x084 +#define FXTOD 0x088 +#define FXTOQ 0x08c +#define FITOS 0x0c4 +#define FDTOS 0x0c6 +#define FQTOS 0x0c7 +#define FITOD 0x0c8 +#define FSTOD 0x0c9 +#define FQTOD 0x0cb +#define FITOQ 0x0cc +#define FSTOQ 0x0cd +#define FDTOQ 0x0ce +#define FSTOI 0x0d1 +#define FDTOI 0x0d2 +#define FQTOI 0x0d3 + +/* These are in FPop2 space */ +#define FMVFC0S 0x001 +#define FMVFC0D 0x002 +#define FMVFC0Q 0x003 +#define FMOVZS 0x025 +#define FMOVZD 0x026 +#define FMOVZQ 0x027 +#define FMVFC1S 0x041 +#define FMVFC1D 0x042 +#define FMVFC1Q 0x043 +#define FMOVLEZS 0x045 +#define FMOVLEZD 0x046 +#define FMOVLEZQ 0x047 +#define FCMPS 0x051 +#define FCMPD 0x052 +#define FCMPQ 0x053 +#define FCMPES 0x055 +#define FCMPED 0x056 +#define FCMPEQ 0x057 +#define FMOVLZS 0x065 +#define FMOVLZD 0x066 +#define FMOVLZQ 0x067 +#define FMVFC2S 0x081 +#define FMVFC2D 0x082 +#define FMVFC2Q 0x083 +#define FMOVNZS 0x0a5 +#define FMOVNZD 0x0a6 +#define FMOVNZQ 0x0a7 +#define FMVFC3S 0x0c1 +#define FMVFC3D 0x0c2 +#define FMVFC3Q 0x0c3 +#define FMOVGZS 0x0c5 +#define FMOVGZD 0x0c6 +#define FMOVGZQ 0x0c7 +#define FMOVGEZS 0x0e5 +#define FMOVGEZD 0x0e6 +#define FMOVGEZQ 0x0e7 +#define FMVICS 0x101 +#define FMVICD 0x102 +#define FMVICQ 0x103 +#define FMVXCS 0x181 +#define FMVXCD 0x182 +#define FMVXCQ 0x183 + +/* + * FPU data types. + */ +#define FTYPE_LNG -1 /* data = 64-bit signed long integer */ +#define FTYPE_INT 0 /* data = 32-bit signed integer */ +#define FTYPE_SNG 1 /* data = 32-bit float */ +#define FTYPE_DBL 2 /* data = 64-bit double */ +#define FTYPE_EXT 3 /* data = 128-bit extended (quad-prec) */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/intr.h b/lib/libc/include/sparc64-openbsd-none/sparc64/intr.h new file mode 100644 index 0000000000..6e35396569 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/intr.h @@ -0,0 +1,119 @@ +/* $OpenBSD: intr.h,v 1.26 2025/05/11 19:41:05 miod Exp $ */ +/* $NetBSD: intr.h,v 1.8 2001/01/14 23:50:30 thorpej Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Paul Kranenburg. + * + * 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_INTR_H_ +#define _MACHINE_INTR_H_ + +#include + +#include + +/* + * Interrupt handler chains. Interrupt handlers should return 0 for + * ``not me'' or 1 (``I took care of it''). intr_establish() inserts a + * handler into the list. The handler is called with its (single) + * argument, or with a pointer to a clockframe if ih_arg is NULL. + */ +struct intrhand { + int (*ih_fun)(void *); + void *ih_arg; + short ih_number; /* interrupt number */ + /* the H/W provides */ + char ih_pil; /* interrupt priority */ + char ih_mpsafe; + struct intrhand *ih_next; /* global list */ + struct intrhand *ih_pending; /* pending list */ + volatile u_int64_t *ih_map; /* interrupt map reg */ + volatile u_int64_t *ih_clr; /* clear interrupt reg */ + void (*ih_ack)(struct intrhand *); + struct evcount ih_count; /* # of interrupts */ + const void *ih_bus; /* parent bus */ + struct cpu_info *ih_cpu; /* target */ + char ih_name[32]; /* device name */ +}; + +extern struct intrhand *intrlev[MAXINTNUM]; + +void intr_establish(struct intrhand *); + +/* XXX - arbitrary numbers; no interpretation is defined yet */ +#define IPL_NONE 0 /* nothing */ +#define IPL_SOFTINT 1 /* softint */ +#define IPL_SOFTCLOCK 1 /* timeouts */ +#define IPL_SOFTNET 2 /* protocol stack */ +#define IPL_BIO PIL_BIO /* block I/O */ +#define IPL_NET PIL_NET /* network */ +#define IPL_SOFTTTY 4 /* delayed terminal handling */ +#define IPL_TTY PIL_TTY /* terminal */ +#define IPL_VM PIL_VM /* memory allocation */ +#define IPL_AUDIO PIL_AUD /* audio */ +#define IPL_CLOCK PIL_CLOCK /* clock */ +#define IPL_SERIAL PIL_SER /* serial */ +#define IPL_SCHED PIL_SCHED /* scheduler */ +#define IPL_STATCLOCK PIL_STATCLOCK /* statclock */ +#define IPL_HIGH PIL_HIGH /* everything */ + +#define spl0() _spl(IPL_NONE) +#define splsoftclock() _splraise(IPL_SOFTCLOCK) +#define splsoftnet() _splraise(IPL_SOFTNET) +#define splbio() _splraise(IPL_BIO) +#define splnet() _splraise(IPL_NET) +#define splsofttty() _splraise(IPL_SOFTTTY) +#define spltty() _splraise(IPL_TTY) +#define splvm() _splraise(IPL_VM) +#define splaudio() _splraise(IPL_AUDIO) +#define splclock() _splraise(IPL_CLOCK) +#define splserial() _splraise(IPL_SERIAL) +#define splsched() _splraise(IPL_SCHED) +#define splstatclock() _splraise(IPL_STATCLOCK) +#define splhigh() _splraise(IPL_HIGH) +#define splx(_oldipl) _splx(_oldipl) + +#define splzs() splserial() + +#define IPL_MPFLOOR IPL_SERIAL +#define IPL_MPSAFE 0x100 + +int splraise(int); +void intr_barrier(void *); + +void *softintr_establish(int, void (*)(void *), void *); +void softintr_disestablish(void *); +void softintr_schedule(void *); + +void *softintr_establish_raw(int, void (*)(void *), void *); +#define softintr_disestablish_raw(ih) softintr_disestablish(ih) +#define softintr_schedule_raw(ih) softintr_schedule(ih) + +void send_softint(int, struct intrhand *); + +#endif /* _MACHINE_INTR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/ioctl_fd.h b/lib/libc/include/sparc64-openbsd-none/sparc64/ioctl_fd.h new file mode 100644 index 0000000000..e7fcb85fe9 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/ioctl_fd.h @@ -0,0 +1,130 @@ +/* $OpenBSD: ioctl_fd.h,v 1.2 2011/03/23 16:54:37 pirofti Exp $ */ +/* from: ioctl_fd.h,v 1.4 1995/06/29 03:49:32 jtk Exp */ + +/* + * Copyright (C) 1992-1994 by Joerg Wunsch, Dresden + * 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(S) ``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(S) 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: Id: ioctl_fd.h,v 1.7 1994/10/30 19:17:39 joerg Exp + */ + +#ifndef _MACHINE_IOCTL_FD_H_ +#define _MACHINE_IOCTL_FD_H_ + +#define FD_FORMAT_VERSION 110 /* used to validate before formatting */ +#define FD_MAX_NSEC 36 /* highest known number of spt - allow for */ + /* 2.88 MB drives */ + +struct fd_formb { + int format_version; /* == FD_FORMAT_VERSION */ + int cyl, head; + int transfer_rate; /* fdreg.h: FDC_???KBPS */ + + union { + struct fd_form_data { + /* + * DO NOT CHANGE THE LAYOUT OF THIS STRUCTS + * it is hardware-dependant since it exactly + * matches the byte sequence to write to FDC + * during its `format track' operation + */ + u_char secshift; /* 0 -> 128, ...; usually 2 -> 512 */ + u_char nsecs; /* must be <= FD_MAX_NSEC */ + u_char gaplen; /* GAP 3 length; usually 84 */ + u_char fillbyte; /* usually 0xf6 */ + struct fd_idfield_data { + /* + * data to write into id fields; + * for obscure formats, they mustn't match + * the real values (but mostly do) + */ + u_char cylno; /* 0 thru 79 (or 39) */ + u_char headno; /* 0, or 1 */ + u_char secno; /* starting at 1! */ + u_char secsize; /* usually 2 */ + } idfields[FD_MAX_NSEC]; /* 0 <= idx < nsecs used */ + } structured; + u_char raw[1]; /* to have continuous indexed access */ + } format_info; +}; + +/* make life easier */ +# define fd_formb_secshift format_info.structured.secshift +# define fd_formb_nsecs format_info.structured.nsecs +# define fd_formb_gaplen format_info.structured.gaplen +# define fd_formb_fillbyte format_info.structured.fillbyte +/* these data must be filled in for(i = 0; i < fd_formb_nsecs; i++) */ +# define fd_formb_cylno(i) format_info.structured.idfields[i].cylno +# define fd_formb_headno(i) format_info.structured.idfields[i].headno +# define fd_formb_secno(i) format_info.structured.idfields[i].secno +# define fd_formb_secsize(i) format_info.structured.idfields[i].secsize + +/* + * Floppies come in various flavors, e.g., 1.2MB vs 1.44MB; here is how + * we tell them apart. + */ +struct fd_type { + int sectrac; /* sectors per track */ + int heads; /* number of heads */ + int seccyl; /* sectors per cylinder */ + int secsize; /* size code for sectors */ + int datalen; /* data len when secsize = 0 */ + int steprate; /* step rate and head unload time */ + int gap1; /* gap len between sectors */ + int gap2; /* formatting gap */ + int tracks; /* total num of tracks */ + int size; /* size of disk in sectors */ + int step; /* steps per cylinder */ + int rate; /* transfer speed code */ + char *name; +}; + + +#define FD_FORM _IOW('F', 61, struct fd_formb) /* format a track */ +#define FD_GTYPE _IOR('F', 62, struct fd_type) /* get drive type */ +#define FD_STYPE _IOW('F', 63, struct fd_type) /* set drive type */ + +#define FD_GOPTS _IOR('F', 64, int) /* drive options, see below */ +#define FD_SOPTS _IOW('F', 65, int) + +#define FDOPT_NORETRY 0x0001 /* no retries on failure (cleared on close) */ +#define FDOPT_SILENT 0x0002 + +/* + * The following definitions duplicate those in sys/i386/isa/fdreg.h + * They are here since their values are to be used in the above + * structure when formatting a floppy. For very obvious reasons, both + * definitions must match ;-) + */ +#ifndef FDC_500KBPS +#define FDC_500KBPS 0x00 /* 500KBPS MFM drive transfer rate */ +#define FDC_300KBPS 0x01 /* 300KBPS MFM drive transfer rate */ +#define FDC_250KBPS 0x02 /* 250KBPS MFM drive transfer rate */ +#define FDC_125KBPS 0x03 /* 125KBPS FM drive transfer rate */ + /* for some controllers 1MPBS instead */ +#endif /* FDC_500KBPS */ + + +#endif /* !_MACHINE_IOCTL_FD_H__ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/kcore.h b/lib/libc/include/sparc64-openbsd-none/sparc64/kcore.h new file mode 100644 index 0000000000..6c89a84b0c --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/kcore.h @@ -0,0 +1,61 @@ +/* $OpenBSD: kcore.h,v 1.3 2008/06/26 05:42:13 ray Exp $ */ +/* $NetBSD: kcore.h,v 1.4 2000/08/01 00:40:26 eeh Exp $ */ + +/*- + * Copyright (c) 1996 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Paul Kranenburg. + * + * 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. + */ + +/* + * The layout of a kernel core on the dump device is as follows: + * a `struct kcore_seg' of type CORE_CPU + * a `struct cpu_kcore_hdr' + */ + +typedef struct cpu_kcore_hdr { + int cputype; /* CPU type associated with this dump */ + + int nmemseg; /* # of physical memory segments */ + uint64_t memsegoffset; /* start of memseg array (relative */ + /* to the start of this header) */ + + int nsegmap; /* # of kernel segs */ + uint64_t segmapoffset; /* start of segmap array (relative */ + /* to the start of this header) */ + + uint64_t kernbase; /* copy of KERNBASE goes here */ + uint64_t cpubase; /* Pointer to cpu_info structure */ + + uint64_t ktextbase; /* Virtual start of text segment */ + uint64_t ktextp; /* Physical address of 4MB locked TLB */ + uint64_t ktextsz; /* Size of locked kernel text segment. */ + + uint64_t kdatabase; /* Virtual start of data segment */ + uint64_t kdatap; /* Physical address of 4MB locked TLB */ + uint64_t kdatasz; /* Size of locked kernel data segment. */ + +} cpu_kcore_hdr_t; \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/limits.h b/lib/libc/include/sparc64-openbsd-none/sparc64/limits.h new file mode 100644 index 0000000000..9060a2e178 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/limits.h @@ -0,0 +1,55 @@ +/* $OpenBSD: limits.h,v 1.11 2015/04/30 13:42:08 millert Exp $ */ +/* $NetBSD: limits.h,v 1.8 2000/08/08 22:31:14 tshiozak 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. + * + * @(#)limits.h 8.3 (Berkeley) 1/4/94 + */ + +#ifndef _MACHINE_LIMITS_H_ +#define _MACHINE_LIMITS_H_ + +#include + +#if __POSIX_VISIBLE || __XPG_VISIBLE +#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) */ + +/* GCC requires that quad constants be written as expressions. */ +#define UQUAD_MAX ((u_quad_t)0-1) /* max value for a uquad_t */ + /* max value for a quad_t */ +#define QUAD_MAX ((quad_t)(UQUAD_MAX >> 1)) +#define QUAD_MIN (-QUAD_MAX-1) /* min value for a quad_t */ + +#endif /* __BSD_VISIBLE */ + +#endif /* _MACHINE_LIMITS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/loadfile_machdep.h b/lib/libc/include/sparc64-openbsd-none/sparc64/loadfile_machdep.h new file mode 100644 index 0000000000..9902239fb2 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/loadfile_machdep.h @@ -0,0 +1,65 @@ +/* $OpenBSD: loadfile_machdep.h,v 1.3 2013/10/17 11:54:02 miod Exp $ */ +/* $NetBSD: loadfile_machdep.h,v 1.3 2000/08/16 08:16:58 mrg Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * 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. + */ + +#define BOOT_ELF +#ifdef __sparc_v9__ +#define ELFSIZE 64 +#else +#define ELFSIZE 32 +#endif + +#define LOAD_KERNEL LOAD_ALL +#define COUNT_KERNEL COUNT_ALL + +#ifdef _STANDALONE +#define LOADADDR(a) (((u_long)(a) & 0x0fffffff) + offset) +#define ALIGNENTRY(a) ((u_long)(a)) +#define READ(f, b, c) read((f), (void *)LOADADDR(b), (c)) +#define BCOPY(s, d, c) memcpy((void *)LOADADDR(d), (void *)(s), (c)) +#define BZERO(d, c) memset((void *)LOADADDR(d), 0, (c)) +#define WARN(a) (void)(printf a, \ + printf((errno ? ": %s\n" : "\n"), \ + strerror(errno))) +#define PROGRESS(a) (void) printf a +#define ALLOC(a) alloc(a) +#define FREE(a, b) free(a, b) +#else +#define LOADADDR(a) (((u_long)(a)) + offset) +#define ALIGNENTRY(a) ((u_long)(a)) +#define READ(f, b, c) read((f), (void *)LOADADDR(b), (c)) +#define BCOPY(s, d, c) memcpy((void *)LOADADDR(d), (void *)(s), (c)) +#define BZERO(d, c) memset((void *)LOADADDR(d), 0, (c)) +#define WARN(a) warn a +#define PROGRESS(a) /* nothing */ +#define ALLOC(a) malloc(a) +#define FREE(a, b) free(a) +#endif \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/mdesc.h b/lib/libc/include/sparc64-openbsd-none/sparc64/mdesc.h new file mode 100644 index 0000000000..bffc347b6a --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/mdesc.h @@ -0,0 +1,55 @@ +/* $OpenBSD: mdesc.h,v 1.4 2019/10/20 16:27:19 kettenis Exp $ */ +/* + * Copyright (c) 2009 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +struct md_header { + uint32_t transport_version; + uint32_t node_blk_sz; + uint32_t name_blk_sz; + uint32_t data_blk_sz; +}; + +struct md_element { + uint8_t tag; + uint8_t name_len; + uint16_t _reserved_field; + uint32_t name_offset; + union { + struct { + uint32_t data_len; + uint32_t data_offset; + } y; + uint64_t val; + } d; +}; + +#ifdef _KERNEL + +extern caddr_t mdesc; +extern size_t mdesc_len; + +extern caddr_t pri; +extern size_t pri_len; + +void mdesc_init(void); +uint64_t mdesc_get_prop_val(int, const char *); +const char *mdesc_get_prop_str(int, const char *); +const char *mdesc_get_prop_data(int, const char *, size_t *); +int mdesc_find(const char *, uint64_t); +int mdesc_find_child(int, const char *, uint64_t); +int mdesc_find_node(const char *); + +#endif \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/mplock.h b/lib/libc/include/sparc64-openbsd-none/sparc64/mplock.h new file mode 100644 index 0000000000..0630808c58 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/mplock.h @@ -0,0 +1,10 @@ +/* $OpenBSD: mplock.h,v 1.4 2017/10/17 14:25:35 visa Exp $ */ + +/* public domain */ + +#ifndef _MACHINE_MPLOCK_H_ +#define _MACHINE_MPLOCK_H_ + +#define __USE_MI_MPLOCK + +#endif /* !_MACHINE_MPLOCK_H */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/mutex.h b/lib/libc/include/sparc64-openbsd-none/sparc64/mutex.h new file mode 100644 index 0000000000..b9368872da --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/mutex.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mutex.h,v 1.8 2018/02/19 09:18:50 mpi Exp $ */ + +#define __USE_MI_MUTEX \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/openfirm.h b/lib/libc/include/sparc64-openbsd-none/sparc64/openfirm.h new file mode 100644 index 0000000000..aadcaf0a9a --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/openfirm.h @@ -0,0 +1,65 @@ +/* $OpenBSD: openfirm.h,v 1.7 2024/11/08 12:48:00 miod Exp $ */ +/* $NetBSD: openfirm.h,v 1.8 2001/07/20 00:07:14 eeh Exp $ */ + +/* + * Copyright (C) 1995, 1996 Wolfgang Solfrank. + * Copyright (C) 1995, 1996 TooLs GmbH. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by TooLs GmbH. + * 4. The name of TooLs GmbH may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* + * Prototypes for additional OpenFirmware Interface Routines + */ + +#include + +/* All cells are 8 byte slots */ +typedef u_int64_t cell_t; +#define HDL2CELL(x) (cell_t)(u_int)(int)(x) +#define ADR2CELL(x) (cell_t)(x) + +#define HDQ2CELL_HI(x) (cell_t)(0) +#define HDQ2CELL_LO(x) (cell_t)(x) + +#define CELL2HDQ(hi, lo) (lo) + +int OF_test(char *service); +int OF_test_method(int handle, char *method); + +int OF_stdin(void); +int OF_stdout(void); +void OF_set_symbol_lookup(void (*s2v)(void *), void (*v2s)(void *)); +void OF_poweroff(void); +void OF_sym2val(void *); +void OF_val2sym(void *); +int OF_milliseconds(void); +int OF_searchprop(int node, char *prop, void *buf, int buflen); +int OF_mapintr(int node, int *interrupt, int validlen, int buflen); +int OF_instance_to_path(int ihandle, char *buf, int buflen); +int OF_package_to_path(int phandle, char *buf, int buflen); + +void (*OF_set_callback(void (*)(void *)))(void *); \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/openpromio.h b/lib/libc/include/sparc64-openbsd-none/sparc64/openpromio.h new file mode 100644 index 0000000000..c301d356b6 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/openpromio.h @@ -0,0 +1,57 @@ +/* $OpenBSD: openpromio.h,v 1.3 2003/06/02 23:27:56 millert Exp $ */ +/* $NetBSD: openpromio.h,v 1.1.1.1 1998/06/20 04:58:52 eeh Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)openpromio.h 8.1 (Berkeley) 6/11/93 + */ + +struct opiocdesc { + int op_nodeid; /* passed or returned node id */ + int op_namelen; /* length of op_name */ + char *op_name; /* pointer to field name */ + int op_buflen; /* length of op_buf (value-result) */ + char *op_buf; /* pointer to field value */ +}; + +#define OPIOCGET _IOWR('O', 1, struct opiocdesc) /* get openprom field */ +#define OPIOCSET _IOW('O', 2, struct opiocdesc) /* set openprom field */ +#define OPIOCNEXTPROP _IOWR('O', 3, struct opiocdesc) /* get next property */ +#define OPIOCGETOPTNODE _IOR('O', 4, int) /* get openprom field */ +#define OPIOCGETNEXT _IOWR('O', 5, int) /* get next node of node */ +#define OPIOCGETCHILD _IOWR('O', 6, int) /* get first child of node */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/param.h b/lib/libc/include/sparc64-openbsd-none/sparc64/param.h new file mode 100644 index 0000000000..c3d5e1fd20 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/param.h @@ -0,0 +1,183 @@ +/* $OpenBSD: param.h,v 1.42 2023/12/14 13:26:49 claudio Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + */ + +/* + * Copyright (c) 1996-1999 Eduardo Horvath + * + * 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. + * + * 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_PARAM_H_ +#define _MACHINE_PARAM_H_ + +#define _MACHINE sparc64 +#define MACHINE "sparc64" +#define _MACHINE_ARCH sparc64 +#define MACHINE_ARCH "sparc64" +#define MID_MACHINE MID_SPARC64 + +#define PAGE_SHIFT 13 +#define PAGE_SIZE (1 << PAGE_SHIFT) +#define PAGE_MASK (PAGE_SIZE - 1) + +/* + * Here are all the magic kernel virtual addresses and how they're allocated. + * + * First, the PROM is usually a fixed-sized block from 0x00000000f0000000 to + * 0x00000000f0100000. It also uses some space around 0x00000000fff00000 to + * map in device registers. The rest is pretty much ours to play with. + * + * The kernel starts at KERNBASE. Here's the layout. We use macros to set + * the addresses so we can relocate everything easily. We use 4MB locked TTEs + * to map in the kernel text and data segments. Any extra pages are recycled, + * so they can potentially be double-mapped. This shouldn't really be a + * problem since they're unused, but wild pointers can cause silent data + * corruption if they are in those segments. + * + * 0x0000000000000000: 64K NFO page zero + * 0x0000000000010000: Userland or PROM + * KERNBASE: 4MB kernel text and read only data + * This is mapped in the ITLB and + * Read-Only in the DTLB + * KERNBASE+0x400000: 4MB kernel data and BSS -- not in ITLB + * Contains context table, kernel pmap, + * and other important structures. + * KERNBASE+0x800000: Unmapped page -- redzone + * KERNBASE+0x802000: Process 0 stack and u-area + * KERNBASE+0x806000: 2 pages for pmap_copy_page and /dev/mem + * KERNBASE+0x80a000: Start of kernel VA segment + * KERNEND: End of kernel VA segment + * KERNEND+0x02000: Auxreg_va (unused?) + * KERNEND+0x04000: TMPMAP_VA (unused?) + * KERNEND+0x06000: message buffer. + * KERNEND+0x010000: 64K locked TTE -- different for each CPU + * Contains interrupt stack, cpu_info structure, + * and 32KB kernel TSB. + * + */ +#define KERNBASE 0x001000000 /* start of kernel virtual space */ + +#ifdef _KERNEL + +#define KERNEND 0x0e0000000 /* end of kernel virtual space */ + +#define _MAXNBPG 8192 /* fixed VAs, independent of actual NBPG */ + +#define AUXREG_VA ( KERNEND + _MAXNBPG) /* 1 page REDZONE */ +#define TMPMAP_VA ( AUXREG_VA + _MAXNBPG) +#define MSGBUF_VA ( TMPMAP_VA + _MAXNBPG) +/* + * Here's the location of the interrupt stack and CPU structure. + */ +#define INTSTACK ( KERNEND + 8*_MAXNBPG)/* 64K after kernel end */ +#define EINTSTACK ( INTSTACK + 2*USPACE) /* 32KB */ +#define CPUINFO_VA ( EINTSTACK) + +#define NBPG PAGE_SIZE /* bytes/page */ +#define PGSHIFT PAGE_SHIFT /* LOG2(PAGE_SIZE) */ +#define PGOFSET PAGE_MASK /* byte offset into page */ + +#define UPAGES 2 /* 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 (1 * PAGE_SIZE) +#endif + +#ifndef _LOCORE + +extern void delay(unsigned int); +#define DELAY(n) delay(n) + +extern int cputyp; + +#if defined (SUN4US) || defined (SUN4V) +#define CPU_ISSUN4U (cputyp == CPU_SUN4U) +#define CPU_ISSUN4US (cputyp == CPU_SUN4US) +#define CPU_ISSUN4V (cputyp == CPU_SUN4V) +#else +#define CPU_ISSUN4U (1) +#define CPU_ISSUN4US (0) +#define CPU_ISSUN4V (0) +#endif + +#endif /* _LOCORE */ + +/* + * Values for the cputyp variable. + */ +#define CPU_SUN4 0 +#define CPU_SUN4C 1 +#define CPU_SUN4M 2 +#define CPU_SUN4U 3 +#define CPU_SUN4US 4 +#define CPU_SUN4V 5 + +/* + * On a sun4u machine, the page size is 8192. + */ + +#ifndef _LOCORE +#include +#endif + +#endif /* _KERNEL */ + +#endif /* _MACHINE_PARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/pcb.h b/lib/libc/include/sparc64-openbsd-none/sparc64/pcb.h new file mode 100644 index 0000000000..c98a66a72e --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/pcb.h @@ -0,0 +1,152 @@ +/* $OpenBSD: pcb.h,v 1.11 2022/10/21 18:55:42 miod Exp $ */ +/* $NetBSD: pcb.h,v 1.7 2000/12/29 17:12:05 eeh Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)pcb.h 8.1 (Berkeley) 6/11/93 + */ + +#ifndef _MACHINE_PCB_H_ +#define _MACHINE_PCB_H_ + +#include + +#ifdef notyet +#define PCB_MAXWIN 32 /* architectural limit */ +#else +#define PCB_MAXWIN 8 /* worried about u area sizes ... */ +#endif + +/* + * SPARC Process Control Block. + * + * pcb_uw is positive if there are any user windows that are + * are currently in the CPU windows rather than on the user + * stack. Whenever we are running in the kernel with traps + * enabled, we decrement pcb_uw for each ``push'' of a CPU + * register window into the stack, and we increment it for + * each ``pull'' from the stack into the CPU. (If traps are + * disabled, or if we are in user mode, pcb_uw is junk.) + * + * To ease computing pcb_uw on traps from user mode, we keep track + * of the log base 2 of the single bit that is set in %wim. + * + * If an overflow occurs while the associated user stack pages + * are invalid (paged out), we have to store the registers + * in a page that is locked in core while the process runs, + * i.e., right here in the pcb. We also need the stack pointer + * for the last such window (but only the last, as the others + * are in each window) and the count of windows saved. We + * cheat by having a whole window structure for that one %sp. + * Thus, to save window pcb_rw[i] to memory, we write it at + * pcb_rw[i + 1].rw_in[6]. + * + * pcb_nsaved has three `kinds' of values. If 0, it means no + * registers are in the PCB (though if pcb_uw is positive, + * there may be the next time you look). If positive, it means + * there are no user registers in the CPU, but there are some + * saved in pcb_rw[]. As a special case, traps that needed + * assistance to pull user registers from the stack also store + * the registers in pcb_rw[], and set pcb_nsaved to -1. This + * special state is normally short-term: it can only last until the + * trap returns, and it can never persist across entry to user code. + */ +/* + * v9 addendum: + * + * Window handling between v8 and v9 has changed somewhat. There + * is no %wim. Instead, we have a %cwp, %cansave, %canrestore, + * %cleanwin, and %otherwin. By definition: + * + * %cansave + %canrestore + %otherwin = NWINDOWS - 2 + * + * In addition, %cleanwin >= %canrestore since restorable windows + * are considered clean. This means that by storing %canrestore + * and %otherwin, we should be able to compute the values of all + * the other registers. + * + * The only other register we need to save is %cwp because it cannot + * be trivially computed from the other registers. The %cwp is + * stored in the %tstate register, but if the machine was in a register + * window spill/fill handler, the value of that %cwp may be off by + * as much as 2 register windows. We will also store %cwp. [We will + * try to steal pcb_uw or pcb_nsaved for this purpose eventually.] + * + * To calculate what registers are in the pcb, start with pcb_cwp + * and proceed to (pcb_cwp - pcb_canrestore) % NWINDOWS. These should + * be saved to their appropriate register windows. The client routine + * (trap handler) is responsible for saving pcb_cwp + 1 [%o1-%o7] in + * the trap frame or on the stack. + * + * + * Even more addendum: + * + * With the new system for keeping track of register windows we don't + * care about anything other than pcb_uw which keeps track of how many + * full windows we have. As soon as a flush traps, we dump all user + * windows to the pcb, handle the fault, then restore all user windows. + * + * XXX we are using pcb_nsaved as the counter. pcb_uw is still a mask. + * change this as soon as the new scheme is debugged. + */ +struct pcb { + u_int64_t pcb_sp; /* sp (%o6) when switch() was called */ + u_int64_t pcb_pc; /* pc (%o7) when switch() was called */ + caddr_t pcb_onfault; /* for copyin/out */ + short pcb_pstate; /* %pstate when switch() was called -- may be useful if we support multiple memory models */ + char pcb_nsaved; /* number of windows saved in pcb */ + + /* The rest is probably not needed except for pcb_rw */ + char pcb_cwp; /* %cwp when switch() was called */ + char pcb_pil; /* %pil when switch() was called -- probably not needed */ + + const char *lastcall; /* DEBUG -- name of last system call */ + u_int64_t pcb_wcookie; + + /* the following MUST be aligned on a 64-bit boundary */ + struct rwindow pcb_rw[PCB_MAXWIN]; /* saved windows */ + u_int64_t pcb_rwsp[PCB_MAXWIN]; +}; + +#ifndef _KERNEL +/* Let gdb compile. We need fancier macros to make these make sense. */ +#define pcb_psr pcb_pstate +#define pcb_wim pcb_cwp +#endif /* _KERNEL */ + +#endif /* _MACHINE_PCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/pci_machdep.h b/lib/libc/include/sparc64-openbsd-none/sparc64/pci_machdep.h new file mode 100644 index 0000000000..f42a581bd4 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/pci_machdep.h @@ -0,0 +1,137 @@ +/* $OpenBSD: pci_machdep.h,v 1.38 2020/06/23 01:21:29 jmatthew Exp $ */ +/* $NetBSD: pci_machdep.h,v 1.7 2001/07/20 00:07:14 eeh Exp $ */ + +/* + * Copyright (c) 1999 Matthew R. Green + * 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_PCI_MACHDEP_H_ +#define _MACHINE_PCI_MACHDEP_H_ + +/* + * Forward declarations. + */ +struct pci_attach_args; + +/* + * define some bits used to glue into the common PCI code. + */ + +#define __HAVE_PCI_MSIX + +typedef struct sparc_pci_chipset *pci_chipset_tag_t; + +#define PCI_INTR_INTX 0x00000000 +#define PCI_INTR_MSI 0x80000000 +#define PCI_INTR_MSIX 0x40000000 +#define PCI_INTR_TYPE_MASK 0xc0000000 +#define PCI_INTR_TYPE(_ih) ((_ih) & PCI_INTR_TYPE_MASK) + +#define PCI_INTR_TAG_MASK 0x00ffff00 +#define PCI_INTR_TAG(_ih) ((_ih) & PCI_INTR_TAG_MASK) + +#define PCI_INTR_VEC_MASK 0x000000ff +#define PCI_INTR_VEC(_ih) ((_ih) & PCI_INTR_VEC_MASK) +typedef u_int pci_intr_handle_t; + +/* + * The stuuuuuuupid allegedly MI PCI code expects pcitag_t to be a + * scalar type. But we really need to store both the OFW node and + * the bus/device/function info in it. (We'd like to store more, + * like all the ofw properties, but we don't need to.) Luckily, + * both are 32-bit values, so we can squeeze them into a u_int64_t + * with a little help from some macros. + */ + +#define PCITAG_NODE(x) (int)(((x)>>32)&0xffffffff) +#define PCITAG_OFFSET(x) ((x)&0xffffffff) +#define PCITAG_BUS(t) ((PCITAG_OFFSET(t)>>16)&0xff) +#define PCITAG_DEV(t) ((PCITAG_OFFSET(t)>>11)&0x1f) +#define PCITAG_FUN(t) ((PCITAG_OFFSET(t)>>8)&0x7) +#define PCITAG_CREATE(n,b,d,f) (((u_int64_t)(n)<<32)|((b)<<16)|((d)<<11)|((f)<<8)) +#define PCITAG_SETNODE(t,n) ((t)&0xffffffff)|(((n)<<32) +typedef u_int64_t pcitag_t; + +struct sparc_pci_chipset { + void *cookie; + bus_space_tag_t bustag; + bus_space_handle_t bushandle; + int rootnode; /* PCI controller */ + int busnode[256]; + int (*conf_size)(pci_chipset_tag_t, pcitag_t); + pcireg_t (*conf_read)(pci_chipset_tag_t, pcitag_t, int); + void (*conf_write)(pci_chipset_tag_t, pcitag_t, int, pcireg_t); + int (*intr_map)(struct pci_attach_args *, pci_intr_handle_t *); + int (*probe_device_hook)(void *, struct pci_attach_args *); +}; + +void pci_attach_hook(struct device *, struct device *, + struct pcibus_attach_args *); +int pci_probe_device_hook(pci_chipset_tag_t, + struct pci_attach_args *); +int pci_bus_maxdevs(pci_chipset_tag_t, int); +pcitag_t pci_make_tag(pci_chipset_tag_t, int, int, int); +void pci_decompose_tag(pci_chipset_tag_t, pcitag_t, int *, int *, + int *); +int pci_conf_size(pci_chipset_tag_t, pcitag_t); +pcireg_t pci_conf_read(pci_chipset_tag_t, pcitag_t, int); +void pci_conf_write(pci_chipset_tag_t, pcitag_t, int, + pcireg_t); +int pci_intr_map(struct pci_attach_args *, pci_intr_handle_t *); +int pci_intr_map_msi(struct pci_attach_args *, pci_intr_handle_t *); +int pci_intr_map_msix(struct pci_attach_args *, int, + pci_intr_handle_t *); +int pci_intr_line(pci_chipset_tag_t, pci_intr_handle_t); +const char *pci_intr_string(pci_chipset_tag_t, pci_intr_handle_t); +void *pci_intr_establish(pci_chipset_tag_t, pci_intr_handle_t, + int, int (*)(void *), void *, const char *); +void *pci_intr_establish_cpu(pci_chipset_tag_t, pci_intr_handle_t, + int, struct cpu_info *, + int (*)(void *), void *, const char *); +void pci_intr_disestablish(pci_chipset_tag_t, void *); + +void pci_msi_enable(pci_chipset_tag_t, pcitag_t, bus_addr_t, int); +void pci_msix_enable(pci_chipset_tag_t, pcitag_t, bus_space_tag_t, + int, bus_addr_t, uint32_t); +int pci_msix_table_map(pci_chipset_tag_t, pcitag_t, + bus_space_tag_t, bus_space_handle_t *); +void pci_msix_table_unmap(pci_chipset_tag_t, pcitag_t, + bus_space_tag_t, bus_space_handle_t); + +int sparc64_pci_enumerate_bus(struct pci_softc *, + int (*match)(struct pci_attach_args *), + struct pci_attach_args *); + +#define PCI_MACHDEP_ENUMERATE_BUS sparc64_pci_enumerate_bus + +#define pci_min_powerstate(c, t) (PCI_PMCSR_STATE_D3) +#define pci_set_powerstate_md(c, t, s, p) + +#define pciide_machdep_compat_intr_establish(a, b, c, d, e) (NULL) +#define pciide_machdep_compat_intr_disestablish(a, b) do { } while (0) + +#define pci_dev_postattach(a, b) + +#endif /* _MACHINE_PCI_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/pmap.h b/lib/libc/include/sparc64-openbsd-none/sparc64/pmap.h new file mode 100644 index 0000000000..e5cad9b40f --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/pmap.h @@ -0,0 +1,214 @@ +/* $OpenBSD: pmap.h,v 1.41 2025/09/18 14:54:33 kettenis Exp $ */ +/* $NetBSD: pmap.h,v 1.16 2001/04/22 23:19:30 thorpej Exp $ */ + +/*- + * Copyright (C) 1995, 1996 Wolfgang Solfrank. + * Copyright (C) 1995, 1996 TooLs GmbH. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by TooLs GmbH. + * 4. The name of TooLs GmbH may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MACHINE_PMAP_H_ +#define _MACHINE_PMAP_H_ + +#ifndef _LOCORE +#ifdef _KERNEL +#include +#endif +#include +#endif + +#define __HAVE_PMAP_PURGE + +/* + * This scheme uses 2-level page tables. + * + * While we're still in 32-bit mode we do the following: + * + * offset: 13 bits + * 1st level: 1024 64-bit TTEs in an 8K page for 10 bits + * 2nd level: 512 32-bit pointers in the pmap for 9 bits + * ------- + * total: 32 bits + * + * In 64-bit mode the Spitfire and Blackbird CPUs support only + * 44-bit virtual addresses. All addresses between + * 0x0000 07ff ffff ffff and 0xffff f800 0000 0000 are in the + * "VA hole" and trap, so we don't have to track them. However, + * we do need to keep them in mind during PT walking. If they + * ever change the size of the address "hole" we need to rework + * all the page table handling. + * + * offset: 13 bits + * 1st level: 1024 64-bit TTEs in an 8K page for 10 bits + * 2nd level: 1024 64-bit pointers in an 8K page for 10 bits + * 3rd level: 1024 64-bit pointers in the segmap for 10 bits + * ------- + * total: 43 bits + * + * Of course, this means for 32-bit spaces we always have a (practically) + * wasted page for the segmap (only one entry used) and half a page wasted + * for the page directory. We still have need of one extra bit 8^(. + */ + +#define HOLESHIFT (43) + +#define PTSZ (PAGE_SIZE/8) +#define PDSZ (PTSZ) +#define STSZ (PTSZ) + +#define PTSHIFT (13) +#define PDSHIFT (10+PTSHIFT) +#define STSHIFT (10+PDSHIFT) + +#define PTMASK (PTSZ-1) +#define PDMASK (PDSZ-1) +#define STMASK (STSZ-1) + +#ifndef _LOCORE + +#define va_to_seg(v) (int)((((paddr_t)(v))>>STSHIFT)&STMASK) +#define va_to_dir(v) (int)((((paddr_t)(v))>>PDSHIFT)&PDMASK) +#define va_to_pte(v) (int)((((paddr_t)(v))>>PTSHIFT)&PTMASK) + +#ifdef _KERNEL + +/* + * Support for big page sizes. This maps the page size to the + * page bits. + */ +struct page_size_map { + u_int64_t mask; + u_int64_t code; +#ifdef DEBUG + u_int64_t use; +#endif +}; +extern const struct page_size_map page_size_map[]; + +struct pmap { + struct mutex pm_mtx; + int pm_ctx; /* Current context */ + int pm_refs; /* ref count */ + /* + * This contains 64-bit pointers to pages that contain + * 1024 64-bit pointers to page tables. All addresses + * are physical. + * + * !!! Only touch this through pseg_get() and pseg_set() !!! + */ + paddr_t pm_physaddr; /* physical address of pm_segs */ + int64_t *pm_segs; + + struct pmap_statistics pm_stats; +}; + +/* + * This comes from the PROM and is used to map prom entries. + */ +struct prom_map { + u_int64_t vstart; + u_int64_t vsize; + u_int64_t tte; +}; + +#define PMAP_NC 0x001 /* Set the E bit in the page */ +#define PMAP_NVC 0x002 /* Don't enable the virtual cache */ +#define PMAP_NOCACHE PMAP_NC +#define PMAP_LITTLE 0x004 /* Map in little endian mode */ +/* Large page size hints -- we really should use another param to pmap_enter() */ +#define PMAP_8K 0x000 +#define PMAP_64K 0x008 /* Use 64K page */ +#define PMAP_512K 0x010 +#define PMAP_4M 0x018 +#define PMAP_SZ_TO_TTE(x) (((x)&0x018)<<58) +/* If these bits are different in va's to the same PA then there is an aliasing in the d$ */ +#define VA_ALIAS_ALIGN (1<<14) +#define VA_ALIAS_MASK (VA_ALIAS_ALIGN - 1) + +typedef struct pmap *pmap_t; + +extern struct pmap kernel_pmap_; +#define pmap_kernel() (&kernel_pmap_) + +/* int pmap_change_wiring(pmap_t pm, vaddr_t va, boolean_t wired); */ +#define pmap_resident_count(pm) ((pm)->pm_stats.resident_count) +#define pmap_update(pm) /* nothing (yet) */ + +#define pmap_proc_iflush(p,va,len) /* nothing */ +#define pmap_init_percpu() do { /* nothing */ } while (0) + +void pmap_bootstrap(u_long, u_long, u_int, u_int); +int pmap_copyinsn(pmap_t, vaddr_t, uint32_t *); + +/* make sure all page mappings are modulo 16K to prevent d$ aliasing */ +#define PMAP_PREFER +/* pmap prefer alignment */ +#define PMAP_PREFER_ALIGN() (VA_ALIAS_ALIGN) +/* pmap prefer offset in alignment */ +#define PMAP_PREFER_OFFSET(of) ((of) & VA_ALIAS_MASK) + +#define PMAP_CHECK_COPYIN CPU_ISSUN4V + +#define PMAP_GROWKERNEL /* turn on pmap_growkernel interface */ + +/* SPARC specific? */ +int pmap_dumpsize(void); +int pmap_dumpmmu(int (*)(dev_t, daddr_t, caddr_t, size_t), daddr_t); +int pmap_pa_exists(paddr_t); + +/* SPARC64 specific */ +int ctx_alloc(struct pmap*); +void ctx_free(struct pmap*); + +#endif /* _KERNEL */ + +/* + * For each struct vm_page, there is a list of all currently valid virtual + * mappings of that page. + */ +typedef struct pv_entry { + struct pv_entry *pv_next; /* next pv_entry */ + struct pmap *pv_pmap; /* pmap where mapping lies */ + vaddr_t pv_va; /* virtual address for mapping */ +} *pv_entry_t; +/* PV flags encoded in the low bits of the VA of the first pv_entry */ + +struct vm_page_md { + struct mutex pvmtx; + struct pv_entry pvent; +}; + +#define VM_MDPAGE_INIT(pg) do { \ + mtx_init(&(pg)->mdpage.pvmtx, IPL_VM); \ + (pg)->mdpage.pvent.pv_next = NULL; \ + (pg)->mdpage.pvent.pv_pmap = NULL; \ + (pg)->mdpage.pvent.pv_va = 0; \ +} while (0) + +#endif /* _LOCORE */ +#endif /* _MACHINE_PMAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/proc.h b/lib/libc/include/sparc64-openbsd-none/sparc64/proc.h new file mode 100644 index 0000000000..55fd5598d9 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/proc.h @@ -0,0 +1,52 @@ +/* $OpenBSD: proc.h,v 1.10 2024/11/07 05:24:43 jsg Exp $ */ +/* $NetBSD: proc.h,v 1.2 1999/11/06 20:13:50 eeh Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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 8.1 (Berkeley) 6/11/93 + */ + +/* + * Machine-dependent part of the proc structure for SPARC. + */ +struct mdproc { + struct trapframe *md_tf; /* trap/syscall registers */ + struct fpstate *md_fpstate; /* fpu state, if any; always resident */ + volatile int md_astpending; + paddr_t md_pcbpaddr; +}; \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/profile.h b/lib/libc/include/sparc64-openbsd-none/sparc64/profile.h new file mode 100644 index 0000000000..477b985236 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/profile.h @@ -0,0 +1,74 @@ +/* $OpenBSD: profile.h,v 1.4 2012/08/22 17:19:35 pascal Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)profile.h 8.1 (Berkeley) 6/11/93 + */ + +#ifdef __PIC__ +/* Inline expansion of PICCY_SET() (see ). */ +#define MCOUNT \ + __asm__(".global _mcount");\ + __asm__("_mcount:");\ + __asm__("add %o7, 8, %o1");\ + __asm__("1: rd %pc, %o2");\ + __asm__("add %o2, __mcount-1b, %o2");\ + __asm__("ld [%o2], %o2");\ + __asm__("jmpl %o2, %g0");\ + __asm__("add %i7, 8, %o0"); +#else +#define MCOUNT \ + __asm__(".global _mcount");\ + __asm__("_mcount:");\ + __asm__("add %i7, 8, %o0");\ + __asm__("sethi %hi(__mcount), %o2");\ + __asm__("jmpl %o2 + %lo(__mcount), %g0");\ + __asm__("add %o7, 8, %o1"); +#endif + +#define _MCOUNT_DECL static void __mcount + +#ifdef _KERNEL +/* + * Block interrupts during mcount so that those interrupts can also be + * counted (as soon as we get done with the current counting). On the + * SPARC, we just splhigh/splx as those do not recursively invoke mcount. + */ +#define MCOUNT_ENTER s = splhigh() +#define MCOUNT_EXIT splx(s) +#endif /* _KERNEL */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/psl.h b/lib/libc/include/sparc64-openbsd-none/sparc64/psl.h new file mode 100644 index 0000000000..84f4b94cac --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/psl.h @@ -0,0 +1,327 @@ +/* $OpenBSD: psl.h,v 1.37 2024/11/06 07:11:14 miod Exp $ */ +/* $NetBSD: psl.h,v 1.20 2001/04/13 23:30:05 thorpej Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)psl.h 8.1 (Berkeley) 6/11/93 + */ + +#ifndef _SPARC64_PSL_ +#define _SPARC64_PSL_ + +/* Interesting spl()s */ +#define PIL_SCSI 3 +#define PIL_BIO 5 +#define PIL_VIDEO 5 +#define PIL_TTY 6 +#define PIL_NET 6 +#define PIL_VM 7 +#define PIL_AUD 8 +#define PIL_CLOCK 10 +#define PIL_FD 11 +#define PIL_SER 12 +#define PIL_STATCLOCK 14 +#define PIL_HIGH 15 +#define PIL_SCHED PIL_STATCLOCK + +/* + * SPARC V9 CCR register + */ + +#define ICC_C 0x01L +#define ICC_V 0x02L +#define ICC_Z 0x04L +#define ICC_N 0x08L +#define XCC_SHIFT 4 +#define XCC_C (ICC_C< 0) { \ + splassert_check(__wantipl, __func__); \ + } \ +} while (0) +#define splsoftassert(wantipl) splassert(wantipl) +#else +#define splassert(wantipl) do { /* nada */ } while (0) +#define splsoftassert(wantipl) do { /* nada */ } while (0) +#endif + +/* + * GCC pseudo-functions for manipulating privileged registers + */ +static inline u_int64_t getpstate(void); +static inline u_int64_t +getpstate(void) +{ + return (sparc_rdpr(pstate)); +} + +static inline void setpstate(u_int64_t); +static inline void +setpstate(u_int64_t newpstate) +{ + sparc_wrpr(pstate, newpstate, 0); +} + +static inline int getcwp(void); +static inline int +getcwp(void) +{ + return (sparc_rdpr(cwp)); +} + +static inline void setcwp(u_int64_t); +static inline void +setcwp(u_int64_t newcwp) +{ + sparc_wrpr(cwp, newcwp, 0); +} + +static inline u_int64_t getver(void); +static inline u_int64_t +getver(void) +{ + return (sparc_rdpr(ver)); +} + +static inline u_int64_t intr_disable(void); +static inline u_int64_t +intr_disable(void) +{ + u_int64_t s; + + s = sparc_rdpr(pstate); + sparc_wrpr(pstate, s & ~PSTATE_IE, 0); + return (s); +} + +static inline void intr_restore(u_int64_t); +static inline void +intr_restore(u_int64_t s) +{ + sparc_wrpr(pstate, s, 0); +} + +static inline void stxa_sync(u_int64_t, u_int64_t, u_int64_t); +static inline void +stxa_sync(u_int64_t va, u_int64_t asi, u_int64_t val) +{ + u_int64_t s = intr_disable(); + stxa_nc(va, asi, val); + __asm volatile("membar #Sync" : : : "memory"); + intr_restore(s); +} + +static inline int +_spl(int newipl) +{ + int oldpil; + + __asm volatile( " rdpr %%pil, %0 \n" + " wrpr %%g0, %1, %%pil \n" + : "=&r" (oldpil) + : "I" (newipl) + : "%g0"); + __asm volatile("" : : : "memory"); + + return (oldpil); +} + +/* A non-priority-decreasing version of SPL */ +static inline int +_splraise(int newpil) +{ + int oldpil; + + oldpil = sparc_rdpr(pil); + if (newpil > oldpil) + sparc_wrpr(pil, newpil, 0); + return (oldpil); +} + +static inline void +_splx(int newpil) +{ + sparc_wrpr(pil, newpil, 0); +} + +#endif /* KERNEL && !_LOCORE */ + +#endif /* _SPARC64_PSL_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/pte.h b/lib/libc/include/sparc64-openbsd-none/sparc64/pte.h new file mode 100644 index 0000000000..50afa9a98b --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/pte.h @@ -0,0 +1,204 @@ +/* $OpenBSD: pte.h,v 1.17 2024/04/14 19:08:09 miod Exp $ */ +/* $NetBSD: pte.h,v 1.7 2001/07/31 06:55:46 eeh Exp $ */ + +/* + * Copyright (c) 1996-1999 Eduardo Horvath + * + * 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. + * + * 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_PTE_H_ +#define _MACHINE_PTE_H_ + +/* virtual address to virtual page number */ +#define VA_SUN4U_VPG(va) (((int)(va) >> 13) & 31) + +/* virtual address to offset within page */ +#define VA_SUN4U_OFF(va) (((int)(va)) & 0x1FFF) + +/* When we go to 64-bit VAs we need to handle the hole */ +#define VA_VPG(va) VA_SUN4U_VPG(va) +#define VA_OFF(va) VA_SUN4U_OFF(va) + +#define PG_SHIFT4U 13 +#define MMU_PAGE_ALIGN 8192 + +/* If you know where a tte is in the tsb, how do you find its va? */ +#define TSBVA(i) ((tsb[(i)].tag.f.tag_va<<22)|(((i)<<13)&0x3ff000)) + +#ifndef _LOCORE +/* + * This is the spitfire TTE. + */ +#if 0 /* We don't use bitfields anyway. */ +struct sun4u_tag_fields { + u_int64_t tag_g:1, /* global flag */ + tag_ctxt:15, /* context for mapping */ + tag_unassigned:6, + tag_va:42; /* virtual address bits<64:22> */ +}; +union sun4u_tag { struct sun4u_tag_fields f; int64_t tag; }; +struct sun4u_data_fields { + u_int64_t data_v:1, /* valid bit */ + data_size:2, /* page size [8K*8**] */ + data_nfo:1, /* no-fault only */ + data_ie:1, /* invert endianness [inefficient] */ + data_soft2:2, /* reserved for S/W */ + data_pa:36, /* physical address */ + data_accessed:1,/* S/W accessed bit */ + data_modified:1,/* S/W modified bit */ + data_realw:1, /* S/W real writable bit (to manage modified) */ + data_tsblock:1, /* S/W TSB locked entry */ + data_exec:1, /* S/W Executable */ + data_onlyexec:1,/* S/W Executable only */ + data_lock:1, /* lock into TLB */ + data_cacheable:2, /* cacheability control */ + data_e:1, /* explicit accesses only */ + data_priv:1, /* privileged page */ + data_w:1, /* writeable */ + data_g:1; /* same as tag_g */ +}; +union sun4u_data { struct sun4u_data_fields f; int64_t data; }; +struct sun4u_tte { + union sun4u_tag tag; + union sun4u_data data; +}; +#else +struct sun4u_tte { + int64_t tag; + int64_t data; +}; +#endif +typedef struct sun4u_tte pte_t; + +/* Assembly routine to flush a mapping */ +extern void (*sp_tlb_flush_pte)(vaddr_t, uint64_t); +extern void (*sp_tlb_flush_ctx)(uint64_t); + +#if defined(MULTIPROCESSOR) +void smp_tlb_flush_pte(vaddr_t, uint64_t); +void smp_tlb_flush_ctx(uint64_t); +#define tlb_flush_pte(va,ctx) smp_tlb_flush_pte(va, ctx) +#define tlb_flush_ctx(ctx) smp_tlb_flush_ctx(ctx) +#else +#define tlb_flush_pte(va,ctx) (*sp_tlb_flush_pte)(va, ctx) +#define tlb_flush_ctx(ctx) (*sp_tlb_flush_ctx)(ctx) +#endif + +#endif /* _LOCORE */ + +/* TSB tag masks */ +#define CTX_MASK ((1<<13)-1) +#define TSB_TAG_CTX_SHIFT 48 +#define TSB_TAG_VA_SHIFT 22 + +#define TSB_TAG_LOCKED 0x0000040000000000LL + +#define TSB_TAG_G 0x8000000000000000LL +#define TSB_TAG_CTX(t) ((((int64_t)(t))>>TSB_TAG_CTX_SHIFT)&CTX_MASK) +#define TSB_TAG_VA(t) ((((int64_t)(t))<>TSB_TAG_VA_SHIFT)) + +/* Page sizes */ +#define PGSZ_8K 0 +#define PGSZ_64K 1 +#define PGSZ_512K 2 +#define PGSZ_4M 3 + +#define SUN4U_PGSZ_SHIFT 61 +#define SUN4U_TLB_SZ(s) (((uint64_t)(s)) << SUN4U_PGSZ_SHIFT) + +/* TLB data masks */ +#define SUN4U_TLB_V 0x8000000000000000LL +#define SUN4U_TLB_8K SUN4U_TLB_SZ(PGSZ_8K) +#define SUN4U_TLB_64K SUN4U_TLB_SZ(PGSZ_64K) +#define SUN4U_TLB_512K SUN4U_TLB_SZ(PGSZ_512K) +#define SUN4U_TLB_4M SUN4U_TLB_SZ(PGSZ_4M) +#define SUN4U_TLB_SZ_MASK 0x6000000000000000LL +#define SUN4U_TLB_NFO 0x1000000000000000LL +#define SUN4U_TLB_IE 0x0800000000000000LL +#define SUN4U_TLB_SOFT2_MASK 0x07fc000000000000LL +#define SUN4U_TLB_RESERVED_MASK 0x0003800000000000LL +#define SUN4U_TLB_PA_MASK 0x00007fffffffe000LL +#define SUN4U_TLB_SOFT_MASK 0x0000000000001f80LL +/* S/W bits */ +#define SUN4U_TLB_ACCESS 0x0000000000000200LL +#define SUN4U_TLB_MODIFY 0x0000000000000800LL +#define SUN4U_TLB_REAL_W 0x0000000000000400LL +#define SUN4U_TLB_TSB_LOCK 0x0000000000001000LL +#define SUN4U_TLB_EXEC 0x0000000000000100LL +#define SUN4U_TLB_EXEC_ONLY 0x0000000000000080LL +/* H/W bits */ +#define SUN4U_TLB_L 0x0000000000000040LL +#define SUN4U_TLB_CACHE_MASK 0x0000000000000030LL +#define SUN4U_TLB_CP 0x0000000000000020LL +#define SUN4U_TLB_CV 0x0000000000000010LL +#define SUN4U_TLB_E 0x0000000000000008LL +#define SUN4U_TLB_P 0x0000000000000004LL +#define SUN4U_TLB_W 0x0000000000000002LL +#define SUN4U_TLB_G 0x0000000000000001LL + +#define SUN4U_TSB_DATA(g,sz,pa,priv,write,cache,aliased,valid,ie) \ +(((valid)?SUN4U_TLB_V:0LL)|SUN4U_TLB_SZ(sz)|\ +(((u_int64_t)(pa))&SUN4U_TLB_PA_MASK)|\ +((cache)?((aliased)?SUN4U_TLB_CP:SUN4U_TLB_CACHE_MASK):SUN4U_TLB_E)|\ +((priv)?SUN4U_TLB_P:0LL)|((write)?SUN4U_TLB_W:0LL)|((g)?SUN4U_TLB_G:0LL)|\ +((ie)?SUN4U_TLB_IE:0LL)) + +#define SUN4V_PGSZ_SHIFT 0 +#define SUN4V_TLB_SZ(s) (((uint64_t)(s))<rb_bt, (addr), (size), (flags), (hp)) +#define md_space_unmap(rbt, h, size, addrp) \ + do { \ + *addrp = (rbt)->rb_bt->sparc_bus_addr((rbt)->rb_bt, \ + (rbt)->rb_bt, (h)); \ + bus_space_unmap((rbt)->rb_bt, (h), (size)); \ + } while (0) + +void pccbb_attach_hook(struct device *, struct device *, + struct pci_attach_args *); + +#endif /* _MACHINE_RBUS_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/reg.h b/lib/libc/include/sparc64-openbsd-none/sparc64/reg.h new file mode 100644 index 0000000000..cd4dc0304d --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/reg.h @@ -0,0 +1,92 @@ +/* $OpenBSD: reg.h,v 1.9 2024/03/29 21:14:31 miod Exp $ */ +/* $NetBSD: reg.h,v 1.8 2001/06/19 12:59:16 wiz Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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 8.1 (Berkeley) 6/11/93 + */ + +#ifndef _MACHINE_REG_H_ +#define _MACHINE_REG_H_ + +/* + * The v9 register window. Each stack pointer (%o6 aka %sp) in each window + * must ALWAYS point to some place at which it is safe to scribble on + * 64 bytes. (If not, your process gets mangled.) Furthermore, each + * stack pointer should be aligned on a 16-byte boundary (plus the BIAS) + * for v9 stacks (the kernel as currently coded allows arbitrary alignment, + * but with a hefty performance penalty). + */ +struct rwindow { + int64_t rw_local[8]; /* %l0..%l7 */ + int64_t rw_in[8]; /* %i0..%i7 */ +}; + +struct reg { + int64_t r_tstate; /* tstate register */ + int64_t r_pc; /* return pc */ + int64_t r_npc; /* return npc */ + int r_y; /* %y register -- 32-bits */ + int64_t r_global[8]; /* %g* registers in trap's caller */ + int64_t r_out[8]; /* %o* registers in trap's caller */ + int64_t r_local[8]; /* %l* registers in trap's caller */ + int64_t r_in[8]; /* %i* registers in trap's caller */ +}; + +/* + * FP coprocessor registers. + */ + +struct fpstate { + u_int fs_regs[64]; /* our view is 64 32-bit registers */ + int64_t fs_fsr; /* %fsr */ + int fs_gsr; /* graphics state reg */ +}; + +/* + * The actual FP registers are made accessible (c.f. ptrace(2)) through + * a `struct fpreg'; relies on the + * fact that `fpreg' is a prefix of `fpstate'. + */ +struct fpreg { + u_int fr_regs[64]; /* our view is 64 32-bit registers */ + int64_t fr_fsr; /* %fsr */ + int fr_gsr; /* graphics state reg */ +}; + +#endif /* _MACHINE_REG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/reloc.h b/lib/libc/include/sparc64-openbsd-none/sparc64/reloc.h new file mode 100644 index 0000000000..6e23309ed5 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/reloc.h @@ -0,0 +1,36 @@ +/* $OpenBSD: reloc.h,v 1.5 2011/03/23 16:54:37 pirofti Exp $ */ +/* + * Copyright (c) 2001 Artur Grabowski + * + * 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_RELOC_H_ +#define _MACHINE_RELOC_H_ + +#define RELOC_NONE 0 + +#define RELOC_COPY 19 +#define RELOC_GLOB_DAT 20 +#define RELOC_JMP_SLOT 21 +#define RELOC_RELATIVE 22 +#define RELOC_64 32 +#define RELOC_UA64 54 +#define RELOC_TLS_DTPMOD32 74 +#define RELOC_TLS_DTPMOD64 75 +#define RELOC_TLS_DTPOFF32 76 +#define RELOC_TLS_DTPOFF64 77 +#define RELOC_TLS_TPOFF32 78 +#define RELOC_TLS_TPOFF64 79 + +#endif /* _MACHINE_RELOC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/setjmp.h b/lib/libc/include/sparc64-openbsd-none/sparc64/setjmp.h new file mode 100644 index 0000000000..54523bed43 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/setjmp.h @@ -0,0 +1,7 @@ +/* $OpenBSD: setjmp.h,v 1.1 2001/08/23 15:32:01 art Exp $ */ + +/* + * machine/setjmp.h: machine dependent setjmp-related information. + */ + +#define _JBLEN 14 /* size, in longs, of a jmp_buf */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/signal.h b/lib/libc/include/sparc64-openbsd-none/sparc64/signal.h new file mode 100644 index 0000000000..e94d2341af --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/signal.h @@ -0,0 +1,87 @@ +/* $OpenBSD: signal.h,v 1.13 2024/03/29 21:16:38 miod Exp $ */ +/* $NetBSD: signal.h,v 1.10 2001/05/09 19:50:49 kleink Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)signal.h 8.1 (Berkeley) 6/11/93 + */ + +#ifndef _MACHINE_SIGNAL_H_ +#define _MACHINE_SIGNAL_H_ + +#include + +typedef int sig_atomic_t; + +#if __BSD_VISIBLE || __XPG_VISIBLE >= 420 +/* + * Information pushed on stack when a signal is delivered. + * This is used by the kernel to restore state following + * execution of the signal handler. It is also made available + * to the handler to allow it to restore state properly if + * a non-standard exit is performed. + */ +struct sigcontext { + long sc_cookie; + /* begin machine dependent portion */ + long sc_sp; /* %sp to restore */ + long sc_pc; /* pc to restore */ + long sc_npc; /* npc to restore */ + long sc_tstate; /* tstate to restore */ + long sc_g1; /* %g1 to restore */ + long sc_o0; /* %o0 to restore */ + int sc_mask; /* signal mask to restore */ +}; +#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */ + +#if defined(_KERNEL) +/* + * `Code' arguments to signal handlers. The names, and the funny numbering. + * are defined so as to match up with what SunOS uses; I have no idea why + * they did the numbers that way, except maybe to match up with the 68881. + */ +#define FPE_INTOVF_TRAP 0x01 /* integer overflow */ +#define FPE_INTDIV_TRAP 0x14 /* integer divide by zero */ +#define FPE_FLTINEX_TRAP 0xc4 /* inexact */ +#define FPE_FLTDIV_TRAP 0xc8 /* divide by zero */ +#define FPE_FLTUND_TRAP 0xcc /* underflow */ +#define FPE_FLTOPERR_TRAP 0xd0 /* operand error */ +#define FPE_FLTOVF_TRAP 0xd4 /* overflow */ +#endif + +#endif /* !_MACHINE_SIGNAL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/sparc64.h b/lib/libc/include/sparc64-openbsd-none/sparc64/sparc64.h new file mode 100644 index 0000000000..16b33d5f77 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/sparc64.h @@ -0,0 +1,65 @@ +/* $OpenBSD: sparc64.h,v 1.14 2018/08/28 00:00:42 dlg Exp $ */ +/* $NetBSD: sparc64.h,v 1.3 2000/10/20 05:47:03 mrg Exp $ */ + +/* + * Copyright (C) 1996 Wolfgang Solfrank. + * Copyright (C) 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 _MACHINE_SPARC64_H_ +#define _MACHINE_SPARC64_H_ + +struct mem_region { + u_int64_t start; + u_int64_t size; +}; + +int prom_set_trap_table(vaddr_t tba, paddr_t mmfsa); +paddr_t prom_vtop(vaddr_t vaddr); +vaddr_t prom_claim_virt(vaddr_t vaddr, int len); +vaddr_t prom_alloc_virt(int len, int align); +int prom_free_virt(vaddr_t vaddr, int len); +int prom_unmap_virt(vaddr_t vaddr, int len); +int prom_map_phys(paddr_t paddr, off_t size, vaddr_t vaddr, int mode); +paddr_t prom_alloc_phys(int len, int align); +paddr_t prom_claim_phys(paddr_t phys, int len); +int prom_free_phys(paddr_t paddr, int len); +paddr_t prom_get_msgbuf(int len, int align); +int prom_itlb_load(int index, u_int64_t data, vaddr_t vaddr); +int prom_dtlb_load(int index, u_int64_t data, vaddr_t vaddr); +void prom_start_cpu(int cpu, void *func, long arg); +void prom_start_cpu_by_cpuid(int cpu, void *func, long arg); +const char *prom_serengeti_set_console_input(const char *); +uint64_t prom_set_sun4v_api_version(uint64_t, uint64_t, uint64_t, uint64_t *); +void prom_sun4v_soft_state_supported(void); + +/* + * Debug + */ +void prom_printf(const char *, ...); +#endif /* _MACHINE_SPARC64_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/spinlock.h b/lib/libc/include/sparc64-openbsd-none/sparc64/spinlock.h new file mode 100644 index 0000000000..4a30761476 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/spinlock.h @@ -0,0 +1,10 @@ +/* $OpenBSD: spinlock.h,v 1.3 2017/09/05 02:40:54 guenther Exp $ */ + +#ifndef _MACHINE_SPINLOCK_H_ +#define _MACHINE_SPINLOCK_H_ + +#define _ATOMIC_LOCK_UNLOCKED (0x00) +#define _ATOMIC_LOCK_LOCKED (0xFF) +typedef unsigned char _atomic_lock_t; + +#endif \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/tcb.h b/lib/libc/include/sparc64-openbsd-none/sparc64/tcb.h new file mode 100644 index 0000000000..a5d8911686 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/tcb.h @@ -0,0 +1,44 @@ +/* $OpenBSD: tcb.h,v 1.7 2017/04/20 10:03:40 kettenis Exp $ */ + +/* + * Copyright (c) 2011 Philip Guenther + * + * 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 + +#include + +/* + * In userspace, register %g7 contains the address of the thread's TCB + */ +#define TCB_GET(p) \ + ((void *)(p)->p_md.md_tf->tf_global[7]) +#define TCB_SET(p, addr) \ + ((p)->p_md.md_tf->tf_global[7] = (int64_t)(addr)) + +#else /* _KERNEL */ + +/* ELF TLS ABI calls for big TCB, with static TLS data at negative offsets */ +#define TLS_VARIANT 2 + +register void *__tcb __asm__ ("g7"); +#define TCB_GET() (__tcb) +#define TCB_SET(tcb) ((__tcb) = (tcb)) + +#endif /* _KERNEL */ +#endif /* _MACHINE_TCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/timetc.h b/lib/libc/include/sparc64-openbsd-none/sparc64/timetc.h new file mode 100644 index 0000000000..7ae3900f52 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/timetc.h @@ -0,0 +1,24 @@ +/* $OpenBSD: timetc.h,v 1.2 2020/07/08 09:20:28 kettenis Exp $ */ +/* + * Copyright (c) 2020 Paul Irofti + * + * 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_TIMETC_H_ +#define _MACHINE_TIMETC_H_ + +#define TC_TICK 1 +#define TC_SYS_TICK 2 + +#endif /* _MACHINE_TIMETC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/trap.h b/lib/libc/include/sparc64-openbsd-none/sparc64/trap.h new file mode 100644 index 0000000000..2b7f57bdaf --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/trap.h @@ -0,0 +1,159 @@ +/* $OpenBSD: trap.h,v 1.5 2013/04/02 13:24:57 kettenis Exp $ */ +/* $NetBSD: trap.h,v 1.4 1999/06/07 05:28:04 eeh Exp $ */ + +/* + * Copyright (c) 1996-1999 Eduardo Horvath + * + * 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. + * + * 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_TRAP_H +#define _MACHINE_TRAP_H + +/* trap vec (pri) description */ +/* 0x000 unused */ +#define T_POR 0x001 /* (0) power on reset */ +#define T_WDR 0x002 /* (1) watchdog reset */ +#define T_XIR 0x003 /* (1) externally initiated reset */ +#define T_SIR 0x004 /* (1) software initiated reset */ +#define T_RED_EXCEPTION 0x005 /* (1) RED state exception */ +/* 0x006 unused */ +/* 0x007 unused */ +#define T_INST_EXCEPT 0x008 /* (5) instruction access exception */ +#define T_TEXTFAULT 0x009 /* (2) ? Text fault */ +#define T_INST_ERROR 0x00a /* (3) instruction access error */ +/* 0x00b unused */ +/* through 0x00f unused */ +#define T_ILLINST 0x010 /* (7) illegal instruction */ +#define T_PRIVINST 0x011 /* (6) privileged opcode */ +#define T_UNIMP_LDD 0x012 /* (6) unimplemented LDD */ +#define T_UNIMP_STD 0x013 /* (6) unimplemented STD */ +/* 0x014 unused */ +/* through 0x01f unused */ +#define T_FPDISABLED 0x020 /* (8) fpu disabled */ +#define T_FP_IEEE_754 0x021 /* (11) ieee 754 exception */ +#define T_FP_OTHER 0x022 /* (11) other fp exception */ +#define T_TAGOF 0x023 /* (14) tag overflow */ +#define T_CLEAN_WINDOW 0x024 /* (10) clean window exception */ +/* 0x025 unused */ +/* through 0x027 unused */ +#define T_DIV0 0x028 /* (15) division routine was handed 0 */ +#define T_PROCERR 0x029 /* (4) internal processor error */ +/* 0x02a unused */ +/* through 0x02f unused */ +#define T_DATAFAULT 0x030 /* (12) address fault during data fetch */ +#define T_DATA_MMU_MISS 0x031 /* (12) data access MMU miss */ +#define T_DATA_ERROR 0x032 /* (12) data access error */ +#define T_DATA_PROT 0x033 /* (12) Data protection ??? */ +#define T_ALIGN 0x034 /* (10) address not properly aligned */ +#define T_LDDF_ALIGN 0x035 /* (10) LDDF address not properly aligned */ +#define T_STDF_ALIGN 0x036 /* (10) STDF address not properly aligned */ +#define T_PRIVACT 0x037 /* (11) privileged action */ +#define T_LDQF_ALIGN 0x038 /* (10) LDQF address not properly aligned */ +#define T_STQF_ALIGN 0x039 /* (10) STQF address not properly aligned */ +/* 0x03a unused */ +/* through 0x03f unused */ +#define T_ASYNC_ERROR 0x040 /* (2) ???? */ +#define T_L1INT 0x041 /* (31) level 1 interrupt */ +#define T_L2INT 0x042 /* (30) level 2 interrupt */ +#define T_L3INT 0x043 /* (29) level 3 interrupt */ +#define T_L4INT 0x044 /* (28) level 4 interrupt */ +#define T_L5INT 0x045 /* (27) level 5 interrupt */ +#define T_L6INT 0x046 /* (26) level 6 interrupt */ +#define T_L7INT 0x047 /* (25) level 7 interrupt */ +#define T_L8INT 0x048 /* (24) level 8 interrupt */ +#define T_L9INT 0x049 /* (23) level 9 interrupt */ +#define T_L10INT 0x04a /* (22) level 10 interrupt */ +#define T_L11INT 0x04b /* (21) level 11 interrupt */ +#define T_L12INT 0x04c /* (20) level 12 interrupt */ +#define T_L13INT 0x04d /* (19) level 13 interrupt */ +#define T_L14INT 0x04e /* (18) level 14 interrupt */ +#define T_L15INT 0x04f /* (17) level 15 interrupt */ +/* 0x050 unused */ +/* through 0x05f unused */ +#define T_INTVEC 0x060 /* (16) interrupt vector [Interrupt Global Regs]*/ +#define T_PA_WATCHPT 0x061 /* (12) Physical addr data watchpoint */ +#define T_VA_WATCHPT 0x062 /* (11) Virtual addr data watchpoint */ +#define T_ECCERR 0x063 /* (33) ECC correction error */ +#define T_FIMMU_MISS 0x064 /* (2) fast instruction access MMU miss */ +/* through 0x067 unused */ +#define T_FDMMU_MISS 0x068 /* (2) fast data access MMU miss */ +/* through 0x06b unused */ +#define T_FDMMU_PROT 0x06c /* (2) fast data access protection */ +/* through 0x06f unused */ +/* 0x070...0x07f implementation dependent exceptions */ +#define T_SPILL_N_NORM 0x080 /* (9) spill (n=0..7) normal */ +/* through 0x09f unused */ +#define T_SPILL_N_OTHER 0x0a0 /* (9) spill (n=0..7) other */ +/* through 0x0bf unused */ +#define T_FILL_N_NORM 0x0c0 /* (9) fill (n=0..7) normal */ +/* through 0x0df unused */ +#define T_FILL_N_OTHER 0x0e0 /* (9) fill (n=0..7) other */ +/* through 0x0ff unused */ + +/* beginning of `user' vectors (from trap instructions) - all priority 16 */ +#define T_SUN_SYSCALL 0x100 /* system call */ +#define T_BREAKPOINT 0x101 /* breakpoint `instruction' */ +#define T_UDIV0 0x102 /* division routine was handed 0 */ +#define T_FLUSHWIN 0x103 /* flush windows */ +#define T_CLEANWIN 0x104 /* provide clean windows */ +#define T_RANGECHECK 0x105 /* ? */ +#define T_FIXALIGN 0x106 /* fix up unaligned accesses */ +#define T_INTOF 0x107 /* integer overflow ? */ +#define T_SVR4_SYSCALL 0x108 /* SVR4 system call */ +#define T_BSD_SYSCALL 0x109 /* BSD system call */ +#define T_KGDB_EXEC 0x10a /* for kernel gdb */ + +/* 0x10b..0x1ff are currently unallocated, except the following */ +#define T_SVR4_GETCC 0x120 +#define T_SVR4_SETCC 0x121 +#define T_SVR4_GETPSR 0x122 +#define T_SVR4_SETPSR 0x123 +#define T_SVR4_GETHRTIME 0x124 +#define T_SVR4_GETHRVTIME 0x125 +#define T_SVR4_GETHRESTIME 0x127 +#define T_GETCC 0x132 +#define T_SETCC 0x133 +#define T_SVID_SYSCALL 0x164 +#define T_SPARC_INTL_SYSCALL 0x165 +#define T_OS_VENDOR_SYSCALL 0x166 +#define T_HW_OEM_SYSCALL 0x167 +#define T_RTF_DEF_TRAP 0x168 +#define T_MON_BREAKPOINT 0x17f + +#ifdef _KERNEL /* pseudo traps for locore.s */ +#define T_RWRET -1 /* need first user window for trap return */ +#define T_AST -2 /* no-op, just needed reschedule or profile */ +#endif + +/* flags to system call (flags in %g1 along with syscall number) */ +#define SYSCALL_G2RFLAG 0x400 /* on success, return to %g2 rather than npc */ + +/* + * `software trap' macros to keep people happy (sparc v8 manual says not + * to set the upper bits). + */ +#define ST_BREAKPOINT (T_BREAKPOINT & 0x7f) +#define ST_DIV0 (T_DIV0 & 0x7f) +#define ST_FLUSHWIN (T_FLUSHWIN & 0x7f) +#define ST_SYSCALL (T_SUN_SYSCALL & 0x7f) + +#endif /* _MACHINE_TRAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/vmparam.h b/lib/libc/include/sparc64-openbsd-none/sparc64/vmparam.h new file mode 100644 index 0000000000..4a3d2ed36c --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/vmparam.h @@ -0,0 +1,124 @@ +/* $OpenBSD: vmparam.h,v 1.35 2024/03/29 21:06:14 miod Exp $ */ +/* $NetBSD: vmparam.h,v 1.18 2001/05/01 02:19:19 thorpej Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)vmparam.h 8.1 (Berkeley) 6/11/93 + */ + +/* + * Machine dependent constants for sun4u and sun4v UltraSPARC + */ + +#ifndef VMPARAM_H +#define VMPARAM_H + +#define USRSTACK 0xffffffffffffe000L + +/* + * Virtual memory related constants, all in bytes + */ +/* + * Since the compiler generates `call' instructions we can't + * have more than 4GB in a single text segment. + * + * And since we only have a 40-bit address space, allow half + * of that for data and the other half for stack. + */ +#ifndef MAXTSIZ +#define MAXTSIZ (1L*1024*1024*1024) /* max text size */ +#endif +#ifndef DFLDSIZ +#define DFLDSIZ (128L*1024*1024) /* initial data size limit */ +#endif +#ifndef MAXDSIZ +#define MAXDSIZ (8L*1024*1024*1024) /* max data size */ +#endif +#ifndef BRKSIZ +#define BRKSIZ MAXDSIZ /* heap gap size */ +#endif +#ifndef DFLSSIZ +#define DFLSSIZ (2L*1024*1024) /* initial stack size limit */ +#endif +#ifndef MAXSSIZ +#define MAXSSIZ (32L*1024*1024) /* max stack size */ +#endif + +#define STACKGAP_RANDOM 256*1024 + +/* + * Size of shared memory map + */ +#ifndef SHMMAXPGS +#define SHMMAXPGS 4096 /* 32mb */ +#endif + +/* + * Size of User Raw I/O map + */ +#define USRIOSIZE 300 + +/* + * Mach derived constants + */ + +/* + * User/kernel map constants. + */ +#define VM_MIN_ADDRESS ((vaddr_t)PAGE_SIZE) +#define VM_MAX_ADDRESS ((vaddr_t)-1) +#define VM_MAXUSER_ADDRESS ((vaddr_t)-PAGE_SIZE) +#ifdef _KERNEL +#define VM_MIN_STACK_ADDRESS ((vaddr_t)0xfffffe0000000000L) +#endif + +/* map PIE into the first quarter of the address space before hole */ +#define VM_PIE_MIN_ADDR PAGE_SIZE +#define VM_PIE_MAX_ADDR 0x10000000000 + +#define VM_MIN_KERNEL_ADDRESS ((vaddr_t)KERNBASE) +#define VM_MAX_KERNEL_ADDRESS ((vaddr_t)0x000007ffffffffffL) + +/* virtual sizes (bytes) for various kernel submaps */ +#define VM_PHYS_SIZE (USRIOSIZE*PAGE_SIZE) + +#define VM_PHYSSEG_MAX 32 /* up to 32 segments */ +#define VM_PHYSSEG_STRAT VM_PSTRAT_BSEARCH +#define VM_PHYSSEG_NOADD /* can't add RAM after vm_mem_init */ + +#endif \ No newline at end of file diff --git a/lib/libc/include/sparc64-openbsd-none/sparc64/z8530var.h b/lib/libc/include/sparc64-openbsd-none/sparc64/z8530var.h new file mode 100644 index 0000000000..9439d8e8f5 --- /dev/null +++ b/lib/libc/include/sparc64-openbsd-none/sparc64/z8530var.h @@ -0,0 +1,80 @@ +/* $OpenBSD: z8530var.h,v 1.9 2024/03/29 21:17:13 miod Exp $ */ +/* $NetBSD: z8530var.h,v 1.4 2000/11/08 23:41:42 eeh Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)zsvar.h 8.1 (Berkeley) 6/11/93 + */ + +#include +#include + +struct zsc_softc { + struct device zsc_dev; /* base device */ + bus_space_tag_t zsc_bustag; /* bus space/dma tags */ + bus_dma_tag_t zsc_dmatag; + struct zs_chanstate *zsc_cs[2]; /* channel A and B soft state */ + + /* Machine-dependent part follows... */ + void *zsc_softintr; + int zsc_promunit; /* PROM's view of zs devices */ + int zsc_node; /* PROM node, if any */ + struct zs_chanstate zsc_cs_store[2]; +}; + +/* + * Functions to read and write individual registers in a channel. + * The ZS chip requires a 1.6 uSec. recovery time between accesses. + * On sparc64, the recovery time is handled in hardware. + */ + +u_char zs_read_reg(struct zs_chanstate *cs, u_char reg); +u_char zs_read_csr(struct zs_chanstate *cs); +u_char zs_read_data(struct zs_chanstate *cs); + +void zs_write_reg(struct zs_chanstate *cs, u_char reg, u_char val); +void zs_write_csr(struct zs_chanstate *cs, u_char val); +void zs_write_data(struct zs_chanstate *cs, u_char val); + +/* The sparc has splzs() in psl.h */ + +/* We want to call it "zs" instead of "zsc" (sigh). */ +#ifndef ZSCCF_CHANNEL +#define ZSCCF_CHANNEL 0 +#define ZSCCF_CHANNEL_DEFAULT -1 +#endif \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/frame.h b/lib/libc/include/x86-openbsd-none/frame.h new file mode 100644 index 0000000000..dbdb06fd21 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/frame.h @@ -0,0 +1,173 @@ +/* $OpenBSD: frame.h,v 1.13 2018/06/15 17:58:41 bluhm Exp $ */ +/* $NetBSD: frame.h,v 1.12 1995/10/11 04:20:08 mycroft Exp $ */ + +/*- + * Copyright (c) 1995 Charles M. Hannum. All rights reserved. + * 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. + * + * @(#)frame.h 5.2 (Berkeley) 1/18/91 + */ + +#ifndef _MACHINE_FRAME_H +#define _MACHINE_FRAME_H +#include + +/* + * System stack frames. + */ + +/* + * Exception/Trap Stack Frame + */ +struct trapframe { + int tf_fs; + int tf_gs; + int tf_es; + int tf_ds; + int tf_edi; + int tf_esi; + int tf_err; /* not the hardware position */ + int tf_ebx; + int tf_edx; + int tf_ecx; + int tf_eax; + int tf_trapno; + /* below portion defined in 386 hardware */ + int tf_ebp; /* hardware puts err here, INTRENTRY() moves it up */ + int tf_eip; + int tf_cs; + int tf_eflags; + /* below used when transitting rings (e.g. user to kernel) */ + int tf_esp; + int tf_ss; + /* below used when switching out of VM86 mode */ + int tf_vm86_es; + int tf_vm86_ds; + int tf_vm86_fs; + int tf_vm86_gs; +}; + +/* + * Interrupt stack frame + */ +struct intrframe { + int if_ppl; + int if_fs; + int if_gs; + int if_es; + int if_ds; + int if_edi; + int if_esi; + int :32; /* for compat with trap frame - err */ + int if_ebx; + int if_edx; + int if_ecx; + int if_eax; + int :32; /* for compat with trap frame - trapno */ + int if_ebp; + /* below portion defined in 386 hardware */ + int if_eip; + int if_cs; + int if_eflags; + /* below only when transitting rings (e.g. user to kernel) */ + int if_esp; + int if_ss; +}; + +/* + * iret stack frame + */ +struct iretframe { + int irf_trapno; + int irf_err; + int irf_eip; + int irf_cs; + int irf_eflags; + int irf_esp; + int irf_ss; + /* below used when switching back to VM86 mode */ + int irf_vm86_es; + int irf_vm86_ds; + int irf_vm86_fs; + int irf_vm86_gs; +}; + +/* + * Trampoline stack frame + */ +struct trampframe { + int trf__deadbeef; + int trf__kern_esp; + int trf_fs; + int trf_eax; + int trf_ebp; + int trf_trapno; + int trf_err; + int trf_eip; + int trf_cs; + int trf_eflags; + int trf_esp; + int trf_ss; + /* below used when switching out of VM86 mode */ + int trf_vm86_es; + int trf_vm86_ds; + int trf_vm86_fs; + int trf_vm86_gs; +}; + +/* + * Stack frame inside cpu_switch() + */ +struct switchframe { + int sf_edi; + int sf_esi; + int sf_ebx; + int sf_eip; +}; + +struct callframe { + struct callframe *f_frame; + int f_retaddr; + int f_arg0; +}; + +/* + * Signal frame + */ +struct sigframe { + int sf_signum; + siginfo_t *sf_sip; + struct sigcontext *sf_scp; + sig_t sf_handler; + struct sigcontext sf_sc; + siginfo_t sf_si; +}; +#endif \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/_float.h b/lib/libc/include/x86-openbsd-none/i386/_float.h new file mode 100644 index 0000000000..4610c97974 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/_float.h @@ -0,0 +1,71 @@ +/* $OpenBSD: _float.h,v 1.1 2012/06/26 16:12:44 deraadt Exp $ */ + +/* + * Copyright (c) 1989 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _MACHINE__FLOAT_H_ +#define _MACHINE__FLOAT_H_ + +#define __FLT_RADIX 2 /* b */ +#define __FLT_ROUNDS __flt_rounds() +#define __FLT_EVAL_METHOD 2 /* long double */ + +#define __FLT_MANT_DIG 24 /* p */ +#define __FLT_EPSILON 1.19209290E-07F /* b**(1-p) */ +#define __FLT_DIG 6 /* floor((p-1)*log10(b))+(b == 10) */ +#define __FLT_MIN_EXP (-125) /* emin */ +#define __FLT_MIN 1.17549435E-38F /* b**(emin-1) */ +#define __FLT_MIN_10_EXP (-37) /* ceil(log10(b**(emin-1))) */ +#define __FLT_MAX_EXP 128 /* emax */ +#define __FLT_MAX 3.40282347E+38F /* (1-b**(-p))*b**emax */ +#define __FLT_MAX_10_EXP 38 /* floor(log10((1-b**(-p))*b**emax)) */ + +#define __DBL_MANT_DIG 53 +#define __DBL_EPSILON 2.2204460492503131E-16 +#define __DBL_DIG 15 +#define __DBL_MIN_EXP (-1021) +#define __DBL_MIN 2.2250738585072014E-308 +#define __DBL_MIN_10_EXP (-307) +#define __DBL_MAX_EXP 1024 +#define __DBL_MAX 1.7976931348623157E+308 +#define __DBL_MAX_10_EXP 308 + +#define __LDBL_MANT_DIG 64 +#define __LDBL_EPSILON 1.08420217248550443401e-19L +#define __LDBL_DIG 18 +#define __LDBL_MIN_EXP (-16381) +#define __LDBL_MIN 3.36210314311209350626e-4932L +#define __LDBL_MIN_10_EXP (-4931) +#define __LDBL_MAX_EXP 16384 +#define __LDBL_MAX 1.18973149535723176502e+4932L +#define __LDBL_MAX_10_EXP 4932 + +#define __DECIMAL_DIG 21 + +#endif /* _MACHINE__FLOAT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/_types.h b/lib/libc/include/x86-openbsd-none/i386/_types.h new file mode 100644 index 0000000000..b9c612f1bb --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/_types.h @@ -0,0 +1,140 @@ +/* $OpenBSD: _types.h,v 1.25 2023/07/02 19:02:27 cheloha 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_ + +/* + * _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(int) - 1) +#define _STACKALIGNBYTES 15 +#define _ALIGN(p) (((unsigned long)(p) + _ALIGNBYTES) & ~_ALIGNBYTES) +#define _ALIGNED_POINTER(p,t) 1 +#define _MAX_PAGE_SHIFT 12 /* same as PAGE_SHIFT */ + +#if defined(_KERNEL) +typedef struct label_t { + long val[6]; +} label_t; +#endif + +/* 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; +typedef long long __int64_t; +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 long double __double_t; +typedef long double __float_t; +typedef long __ptrdiff_t; +typedef unsigned long __size_t; +typedef long __ssize_t; +#if defined(__GNUC__) && __GNUC__ >= 3 +typedef __builtin_va_list __va_list; +#else +typedef char * __va_list; +#endif + +/* Wide character support types */ +#ifndef __cplusplus +typedef int __wchar_t; +#endif +typedef int __wint_t; +typedef int __rune_t; +typedef void * __wctrans_t; +typedef void * __wctype_t; + +#endif /* _MACHINE__TYPES_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/acpiapm.h b/lib/libc/include/x86-openbsd-none/i386/acpiapm.h new file mode 100644 index 0000000000..6921c56fd2 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/acpiapm.h @@ -0,0 +1,22 @@ +/* $OpenBSD: acpiapm.h,v 1.1 2007/11/25 15:45:17 tedu Exp $ */ +/* + * Copyright (c) 2007 Ted Unangst + * + * 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. + */ + + +extern int (*acpiapm_open)(dev_t, int, int, struct proc *); +extern int (*acpiapm_close)(dev_t, int, int, struct proc *); +extern int (*acpiapm_ioctl)(dev_t, u_long, caddr_t, int, struct proc *); +extern int (*acpiapm_kqfilter)(dev_t, struct knote *); \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/amdmsr.h b/lib/libc/include/x86-openbsd-none/i386/amdmsr.h new file mode 100644 index 0000000000..1a6027a5a3 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/amdmsr.h @@ -0,0 +1,34 @@ +/* $OpenBSD: amdmsr.h,v 1.4 2011/03/23 16:54:35 pirofti Exp $ */ + +/* + * Copyright (c) 2008 Marc Balmer + * + * 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_AMDMSR_H_ +#define _MACHINE_AMDMSR_H_ + +struct amdmsr_req { + u_int32_t addr; /* 32-bit MSR address */ + u_int64_t val; /* 64-bit MSR value */ +}; + +#define RDMSR _IOWR('M', 0, struct amdmsr_req) +#define WRMSR _IOW('M', 1, struct amdmsr_req) + +#ifdef _KERNEL +int amdmsr_probe(void); +#endif + +#endif /* !_MACHINE_AMDMSR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/apicvar.h b/lib/libc/include/x86-openbsd-none/i386/apicvar.h new file mode 100644 index 0000000000..754f54465e --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/apicvar.h @@ -0,0 +1,54 @@ +/* $OpenBSD: apicvar.h,v 1.7 2025/09/05 16:57:48 kettenis Exp $ */ +/* $NetBSD: apicvar.h,v 1.1.2.3 2000/02/27 20:25:00 sommerfeld Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by RedBack Networks Inc. + * + * Author: Bill Sommerfeld + * + * 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_APICVAR_H_ +#define _MACHINE_APICVAR_H_ + +#include + +struct apic_attach_args { + const char *aaa_name; + int apic_id; + int apic_version; + int flags; +#define IOAPIC_PICMODE 0x01 +#define IOAPIC_VWIRE 0x02 + bus_space_tag_t apic_memt; + bus_addr_t apic_address; + int apic_vecbase; +}; + +void apic_format_redir(char *, char *, int, u_int32_t, u_int32_t); + +#endif /* !_MACHINE_APICVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/apmvar.h b/lib/libc/include/x86-openbsd-none/i386/apmvar.h new file mode 100644 index 0000000000..4d29641e7a --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/apmvar.h @@ -0,0 +1,303 @@ +/* $OpenBSD: apmvar.h,v 1.22 2019/01/22 02:36:30 phessler Exp $ */ + +/* + * Copyright (c) 1995 John T. Kohl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef _MACHINE_APMVAR_H_ +#define _MACHINE_APMVAR_H_ + +#include + +/* Advanced Power Management (v1.0 and v1.1 specification) + * functions/defines/etc. + */ + +#define APM_VERSION 0x0102 + +/* + * APM info word from boot loader + */ +#define APM_16BIT_SUPPORTED 0x00010000 +#define APM_32BIT_SUPPORTED 0x00020000 +#define APM_IDLE_SLOWS 0x00040000 +#define APM_BIOS_PM_DISABLED 0x00080000 +#define APM_BIOS_PM_DISENGAGED 0x00100000 +#define APM_MAJOR(f) (((f) >> 8) & 0xff) +#define APM_MINOR(f) ((f) & 0xff) +#define APM_VERMASK 0x0000ffff +#define APM_NOCLI 0x00010000 +#define APM_BEBATT 0x00020000 + +/* APM error codes */ +#define APM_ERR_CODE(regs) (((regs)->ax & 0xff00) >> 8) +#define APM_ERR_PM_DISABLED 0x01 +#define APM_ERR_REALALREADY 0x02 +#define APM_ERR_NOTCONN 0x03 +#define APM_ERR_16ALREADY 0x05 +#define APM_ERR_16NOTSUPP 0x06 +#define APM_ERR_32ALREADY 0x07 +#define APM_ERR_32NOTSUPP 0x08 +#define APM_ERR_UNRECOG_DEV 0x09 +#define APM_ERR_ERANGE 0x0A +#define APM_ERR_NOTENGAGED 0x0B +#define APM_ERR_EOPNOSUPP 0x0C +#define APM_ERR_RTIMER_DISABLED 0x0D +#define APM_ERR_UNABLE 0x60 +#define APM_ERR_NOEVENTS 0x80 +#define APM_ERR_NOT_PRESENT 0x86 + +#define APM_DEV_APM_BIOS 0x0000 +#define APM_DEV_ALLDEVS 0x0001 +/* device classes are high byte; device IDs go in low byte */ +#define APM_DEV_DISPLAY(x) (0x0100|((x)&0xff)) +#define APM_DEV_DISK(x) (0x0200|((x)&0xff)) +#define APM_DEV_PARALLEL(x) (0x0300|((x)&0xff)) +#define APM_DEV_SERIAL(x) (0x0400|((x)&0xff)) +#define APM_DEV_NETWORK(x) (0x0500|((x)&0xff)) +#define APM_DEV_PCMCIA(x) (0x0600|((x)&0xff)) +#define APM_DEV_BATTERIES(x) (0x8000|((x)&0xff)) +#define APM_DEV_ALLUNITS 0xff +/* 0x8100-0xDFFF - reserved */ +/* 0xE000-0xEFFF - OEM-defined */ +/* 0xF000-0xFFFF - reserved */ + +#define APM_INSTCHECK 0x5300 /* int15 only */ +#define APM_16BIT_SUPPORT 0x01 +#define APM_32BIT_SUPPORT 0x02 +#define APM_CPUIDLE_SLOW 0x04 +#define APM_DISABLED 0x08 +#define APM_DISENGAGED 0x10 + +#define APM_REAL_CONNECT 0x5301 /* int15 only */ +#define APM_PROT16_CONNECT 0x5302 /* int15 only */ +#define APM_PROT32_CONNECT 0x5303 /* int15 only */ +#define APM_DISCONNECT 0x5304 /* %bx = APM_DEV_APM_BIOS */ + +#define APM_CPU_IDLE 0x5305 +#define APM_CPU_BUSY 0x5306 + +#define APM_SET_PWR_STATE 0x5307 +#define APM_SYS_READY 0x0000 /* %cx */ +#define APM_SYS_STANDBY 0x0001 +#define APM_SYS_SUSPEND 0x0002 +#define APM_SYS_OFF 0x0003 +#define APM_LASTREQ_INPROG 0x0004 +#define APM_LASTREQ_REJECTED 0x0005 +/* 0x0006 - 0x001f Reserved system states */ +/* 0x0020 - 0x003f OEM-defined system states */ +/* 0x0040 - 0x007f OEM-defined device states */ +/* 0x0080 - 0xffff Reserved device states */ + +/* system standby is device ID (%bx) 0x0001, APM_SYS_STANDBY */ +/* system suspend is device ID (%bx) 0x0001, APM_SYS_SUSPEND */ + +#define APM_PWR_MGT_ENABLE 0x5308 +#define APM_MGT_ALL 0xffff /* %bx */ +#define APM_MGT_DISABLE 0x0 /* %cx */ +#define APM_MGT_ENABLE 0x1 + +#define APM_SYSTEM_DEFAULTS 0x5309 +#define APM_DEFAULTS_ALL 0xffff /* %bx */ + +#define APM_POWER_STATUS 0x530a +#define APM_AC_OFF 0x00 +#define APM_AC_ON 0x01 +#define APM_AC_BACKUP 0x02 +#define APM_AC_UNKNOWN 0xff +#define APM_BATT_HIGH 0x00 +#define APM_BATT_LOW 0x01 +#define APM_BATT_CRITICAL 0x02 +#define APM_BATT_CHARGING 0x03 +#define APM_BATT_UNKNOWN 0xff +#define APM_BATT_FLAG_HIGH 0x01 +#define APM_BATT_FLAG_LOW 0x02 +#define APM_BATT_FLAG_CRITICAL 0x04 +#define APM_BATT_FLAG_CHARGING 0x08 +#define APM_BATT_FLAG_NOBATTERY 0x10 +#define APM_BATT_FLAG_NOSYSBATT 0x80 +#define APM_BATT_LIFE_UNKNOWN 0xff +#define BATT_STATE(regp) ((regp)->bx & 0xff) +#define BATT_FLAGS(regp) (((regp)->cx & 0xff00) >> 8) +#define AC_STATE(regp) (((regp)->bx & 0xff00) >> 8) +#define BATT_LIFE(regp) ((regp)->cx & 0xff) /* in % */ +/* Return time in minutes. According to the APM 1.2 spec: + DX = Remaining battery life -- time units + Bit 15 = 0 Time units are seconds + = 1 Time units are minutes + Bits 14-0 = Number of seconds or minutes */ +#define BATT_REMAINING(regp) (((regp)->dx & 0x8000) ? \ + ((regp)->dx & 0x7fff) : \ + ((regp)->dx & 0x7fff)/60) +#define BATT_REM_VALID(regp) (((regp)->dx & 0xffff) != 0xffff) +#define BATT_COUNT(regp) ((regp)->si) + +#define APM_GET_PM_EVENT 0x530b +#define APM_NOEVENT 0x0000 +#define APM_STANDBY_REQ 0x0001 /* %bx on return */ +#define APM_SUSPEND_REQ 0x0002 +#define APM_NORMAL_RESUME 0x0003 +#define APM_CRIT_RESUME 0x0004 /* suspend/resume happened + without us */ +#define APM_BATTERY_LOW 0x0005 +#define APM_POWER_CHANGE 0x0006 +#define APM_UPDATE_TIME 0x0007 +#define APM_CRIT_SUSPEND_REQ 0x0008 +#define APM_USER_STANDBY_REQ 0x0009 +#define APM_USER_SUSPEND_REQ 0x000A +#define APM_SYS_STANDBY_RESUME 0x000B +#define APM_CAPABILITY_CHANGE 0x000C /* apm v1.2 */ +/* 0x000d - 0x00ff Reserved system events */ +#define APM_USER_HIBERNATE_REQ 0x000D +/* 0x0100 - 0x01ff Reserved device events */ +/* 0x0200 - 0x02ff OEM-defined APM events */ +/* 0x0300 - 0xffff Reserved */ +#define APM_EVENT_MASK 0xffff + +#define APM_EVENT_COMPOSE(t,i) ((((i) & 0x7fff) << 16)|((t) & APM_EVENT_MASK)) +#define APM_EVENT_TYPE(e) ((e) & APM_EVENT_MASK) +#define APM_EVENT_INDEX(e) ((e) >> 16) + +#define APM_GET_POWER_STATE 0x530c +#define APM_DEVICE_MGMT_ENABLE 0x530d + +#define APM_DRIVER_VERSION 0x530e +/* %bx should be DEV value (APM_DEV_APM_BIOS) + %ch = driver major vno + %cl = driver minor vno + return: %ah = conn major; %al = conn minor + */ +#define APM_CONN_MINOR(regp) ((regp)->ax & 0xff) +#define APM_CONN_MAJOR(regp) (((regp)->ax & 0xff00) >> 8) + +#define APM_PWR_MGT_ENGAGE 0x530F +#define APM_MGT_DISENGAGE 0x0 /* %cx */ +#define APM_MGT_ENGAGE 0x1 + +/* %bx - APM_DEV_APM_BIOS + * %bl - number of batteries + * %cx - capabilities + */ +#define APM_GET_CAPABILITIES 0x5310 +#define APM_NBATTERIES(regp) ((regp)->bx) +#define APM_GLOBAL_STANDBY 0x0001 +#define APM_GLOBAL_SUSPEND 0x0002 +#define APM_RTIMER_STANDBY 0x0004 /* resume time wakes up */ +#define APM_RTIMER_SUSPEND 0x0008 +#define APM_IRRING_STANDBY 0x0010 /* internal ring wakes up */ +#define APM_IRRING_SUSPEND 0x0020 +#define APM_PCCARD_STANDBY 0x0040 /* pccard wakes up */ +#define APM_PCCARD_SUSPEND 0x0080 + +/* %bx - APM_DEV_APM_BIOS + * %cl - function + * for %cl=2 (set resume timer) + * %ch - seconds in BCD + * %dh - hours in BCD + * %dl - minutes in BCD + * %si - month in BCD (high), day in BCD (low) + * %di - year in BCD + */ +#define APM_RESUME_TIMER 0x5311 +#define APM_RT_DISABLE 0x0 +#define APM_RT_GET 0x1 +#define APM_RT_SET 0x2 + +/* %bx - APM_DEV_APM_BIOS + * %cx - function + */ +#define APM_RESUME_ON_RING 0x5312 +#define APM_ROR_DISABLE 0x0 +#define APM_ROR_ENABLE 0x1 +#define APM_ROR_STATUS 0x2 + +/* %bx - APM_EDV_APM_BIOS + * %cx - function + */ +#define APM_INACTIVITY_TIMER 0x5313 +#define APM_IT_DISABLE 0x0 +#define APM_IT_ENABLE 0x1 +#define APM_IT_STATUS 0x2 + +/* %bh - function */ +#define APM_OEM 0x5380 +#define APM_OEM_INSTCHECK 0x7f /* %bx - OEM ID */ + +/* + * LP (Laptop Package) + * + * Copyright (C) 1994 by HOSOKAWA Tatsumi + * + * This software may be used, modified, copied, and distributed, in + * both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + */ + +#define APM_BATTERY_ABSENT 4 + +struct apm_power_info { + u_char battery_state; + u_char ac_state; + u_char battery_life; + u_char spare1; + u_int minutes_left; /* estimate */ + u_int spare2[6]; +}; + +struct apm_ctl { + u_int dev; + u_int mode; +}; + +#define APM_IOC_REJECT _IOW('A', 0, struct apm_event_info) /* reject request # */ +#define APM_IOC_STANDBY _IO('A', 1) /* put system into standby */ +#define APM_IOC_SUSPEND _IO('A', 2) /* put system into suspend */ +#define APM_IOC_GETPOWER _IOR('A', 3, struct apm_power_info) /* fetch battery state */ +#define APM_IOC_DEV_CTL _IOW('A', 5, struct apm_ctl) /* put device into mode */ +#define APM_IOC_PRN_CTL _IOW('A', 6, int ) /* driver power status msg */ +#define APM_PRINT_ON 0 /* driver power status displayed */ +#define APM_PRINT_OFF 1 /* driver power status not displayed */ +#define APM_PRINT_PCT 2 /* driver power status only displayed + if the percentage changes */ +#define APM_IOC_STANDBY_REQ _IO('A', 7) /* request standby */ +#define APM_IOC_SUSPEND_REQ _IO('A', 8) /* request suspend */ +#define APM_IOC_HIBERNATE _IO('A', 9) /* put system into hibernate */ + + +#ifdef _KERNEL +extern void apm_cpu_busy(void); +extern void apm_cpu_idle(void); +extern void apminit(void); +int apm_set_powstate(u_int devid, u_int powstate); +#endif /* _KERNEL */ + +#endif /* _MACHINE_APMVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/asm.h b/lib/libc/include/x86-openbsd-none/i386/asm.h new file mode 100644 index 0000000000..c5b22ef4f4 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/asm.h @@ -0,0 +1,131 @@ +/* $OpenBSD: asm.h,v 1.19 2022/12/08 01:25:45 guenther Exp $ */ +/* $NetBSD: asm.h,v 1.7 1994/10/27 04:15:56 cgd 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. + * + * @(#)asm.h 5.5 (Berkeley) 5/7/91 + */ + +#ifndef _MACHINE_ASM_H_ +#define _MACHINE_ASM_H_ + +#ifdef __PIC__ +#define PIC_PROLOGUE \ + pushl %ebx; \ + call 666f; \ +666: \ + popl %ebx; \ + addl $_GLOBAL_OFFSET_TABLE_+[.-666b], %ebx +#define PIC_EPILOGUE \ + popl %ebx +#define PIC_PLT(x) x@PLT +#define PIC_GOT(x) x@GOT(%ebx) +#define PIC_GOTOFF(x) x@GOTOFF(%ebx) +#else +#define PIC_PROLOGUE +#define PIC_EPILOGUE +#define PIC_PLT(x) x +#define PIC_GOT(x) x +#define PIC_GOTOFF(x) x +#endif + +#define _C_LABEL(name) name +#define _ASM_LABEL(x) x + +#define CVAROFF(x, y) x + y + +#ifdef __STDC__ +# define __CONCAT(x,y) x ## y +# define __STRING(x) #x +#else +# define __CONCAT(x,y) x/**/y +# define __STRING(x) "x" +#endif + +/* + * STRONG_ALIAS, WEAK_ALIAS + * Create a strong or weak alias. + */ +#define STRONG_ALIAS(alias,sym) \ + .global alias; \ + alias = sym +#define WEAK_ALIAS(alias,sym) \ + .weak alias; \ + alias = sym + +/* let kernels and others override entrypoint alignment */ +#ifndef _ALIGN_TEXT +# define _ALIGN_TEXT .align 2, 0x90 +#endif + +/* NB == No Binding: use .globl or .weak as necessary */ +#define _ENTRY_NB(x) \ + .text; _ALIGN_TEXT; .type x,@function; x: +#define _ENTRY(x) .globl x; _ENTRY_NB(x) + +#ifdef _KERNEL +#define KUTEXT .section .kutext, "ax" + +#define IDTVEC(name) \ + KUTEXT; ALIGN_TEXT; \ + .globl X##name; X##name: +#define KIDTVEC(name) \ + .text; ALIGN_TEXT; \ + .globl X##name; X##name: +#define KUENTRY(x) \ + KUTEXT; _ALIGN_TEXT; .globl x; .type x,@function; x: + +#endif /* _KERNEL */ + +#if defined(PROF) || defined(GPROF) +# define _PROF_PROLOGUE \ + pushl %ebp; movl %esp,%ebp; call PIC_PLT(mcount); popl %ebp +#else +# define _PROF_PROLOGUE +#endif + +#define ENTRY(y) _ENTRY(y); _PROF_PROLOGUE +#define ENTRY_NB(y) _ENTRY_NB(y); _PROF_PROLOGUE +#define NENTRY(y) _ENTRY(y) +#define ASENTRY(y) _ENTRY(y); _PROF_PROLOGUE +#define NASENTRY(y) _ENTRY(y) +#define END(y) .size y, . - y + +#define ALTENTRY(name) .globl name; name: + +#ifdef _KERNEL + +#define CPUVAR(var) %fs:__CONCAT(CPU_INFO_,var) + +#endif /* _KERNEL */ + +#endif /* !_MACHINE_ASM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/atomic.h b/lib/libc/include/x86-openbsd-none/i386/atomic.h new file mode 100644 index 0000000000..ef6a8301b4 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/atomic.h @@ -0,0 +1,316 @@ +/* $OpenBSD: atomic.h,v 1.20 2022/08/29 02:01:18 jsg Exp $ */ +/* $NetBSD: atomic.h,v 1.1.2.2 2000/02/21 18:54:07 sommerfeld Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by RedBack Networks Inc. + * + * Author: Bill Sommerfeld + * + * 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_ATOMIC_H_ +#define _MACHINE_ATOMIC_H_ + +/* + * Perform atomic operations on memory. Should be atomic with respect + * to interrupts and multiple processors. + * + * void atomic_setbits_int(volatile u_int *a, u_int mask) { *a |= mask; } + * void atomic_clearbits_int(volatile u_int *a, u_int mas) { *a &= ~mask; } + */ +#if !defined(_LOCORE) + +#if defined(MULTIPROCESSOR) || !defined(_KERNEL) +#define _LOCK "lock" +#else +#define _LOCK +#endif + +static inline unsigned int +_atomic_cas_uint(volatile unsigned int *p, unsigned int e, unsigned int n) +{ + __asm volatile(_LOCK " cmpxchgl %2, %1" + : "=a" (n), "=m" (*p) + : "r" (n), "a" (e), "m" (*p)); + + return (n); +} +#define atomic_cas_uint(_p, _e, _n) _atomic_cas_uint((_p), (_e), (_n)) + +static inline unsigned long +_atomic_cas_ulong(volatile unsigned long *p, unsigned long e, unsigned long n) +{ + __asm volatile(_LOCK " cmpxchgl %2, %1" + : "=a" (n), "=m" (*p) + : "r" (n), "a" (e), "m" (*p)); + + return (n); +} +#define atomic_cas_ulong(_p, _e, _n) _atomic_cas_ulong((_p), (_e), (_n)) + +static inline void * +_atomic_cas_ptr(volatile void *p, void *e, void *n) +{ + __asm volatile(_LOCK " cmpxchgl %2, %1" + : "=a" (n), "=m" (*(unsigned long *)p) + : "r" (n), "a" (e), "m" (*(unsigned long *)p)); + + return (n); +} +#define atomic_cas_ptr(_p, _e, _n) _atomic_cas_ptr((_p), (_e), (_n)) + +static inline unsigned int +_atomic_swap_uint(volatile unsigned int *p, unsigned int n) +{ + __asm volatile("xchgl %0, %1" + : "=a" (n), "=m" (*p) + : "0" (n), "m" (*p)); + + return (n); +} +#define atomic_swap_uint(_p, _n) _atomic_swap_uint((_p), (_n)) +#define atomic_swap_32(_p, _n) _atomic_swap_uint((_p), (_n)) + +static inline unsigned long +_atomic_swap_ulong(volatile unsigned long *p, unsigned long n) +{ + __asm volatile("xchgl %0, %1" + : "=a" (n), "=m" (*p) + : "0" (n), "m" (*p)); + + return (n); +} +#define atomic_swap_ulong(_p, _n) _atomic_swap_ulong((_p), (_n)) + +static inline void * +_atomic_swap_ptr(volatile void *p, void *n) +{ + __asm volatile("xchgl %0, %1" + : "=a" (n), "=m" (*(unsigned long *)p) + : "0" (n), "m" (*(unsigned long *)p)); + + return (n); +} +#define atomic_swap_ptr(_p, _n) _atomic_swap_ptr((_p), (_n)) + +static inline void +_atomic_inc_int(volatile unsigned int *p) +{ + __asm volatile(_LOCK " incl %0" + : "+m" (*p)); +} +#define atomic_inc_int(_p) _atomic_inc_int(_p) + +static inline void +_atomic_inc_long(volatile unsigned long *p) +{ + __asm volatile(_LOCK " incl %0" + : "+m" (*p)); +} +#define atomic_inc_long(_p) _atomic_inc_long(_p) + +static inline void +_atomic_dec_int(volatile unsigned int *p) +{ + __asm volatile(_LOCK " decl %0" + : "+m" (*p)); +} +#define atomic_dec_int(_p) _atomic_dec_int(_p) + +static inline void +_atomic_dec_long(volatile unsigned long *p) +{ + __asm volatile(_LOCK " decl %0" + : "+m" (*p)); +} +#define atomic_dec_long(_p) _atomic_dec_long(_p) + +static inline void +_atomic_add_int(volatile unsigned int *p, unsigned int v) +{ + __asm volatile(_LOCK " addl %1,%0" + : "+m" (*p) + : "a" (v)); +} +#define atomic_add_int(_p, _v) _atomic_add_int(_p, _v) + +static inline void +_atomic_add_long(volatile unsigned long *p, unsigned long v) +{ + __asm volatile(_LOCK " addl %1,%0" + : "+m" (*p) + : "a" (v)); +} +#define atomic_add_long(_p, _v) _atomic_add_long(_p, _v) + +static inline void +_atomic_sub_int(volatile unsigned int *p, unsigned int v) +{ + __asm volatile(_LOCK " subl %1,%0" + : "+m" (*p) + : "a" (v)); +} +#define atomic_sub_int(_p, _v) _atomic_sub_int(_p, _v) + +static inline void +_atomic_sub_long(volatile unsigned long *p, unsigned long v) +{ + __asm volatile(_LOCK " subl %1,%0" + : "+m" (*p) + : "a" (v)); +} +#define atomic_sub_long(_p, _v) _atomic_sub_long(_p, _v) + + +static inline unsigned long +_atomic_add_int_nv(volatile unsigned int *p, unsigned int v) +{ + unsigned int rv = v; + + __asm volatile(_LOCK " xaddl %0,%1" + : "+a" (rv), "+m" (*p)); + + return (rv + v); +} +#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 = v; + + __asm volatile(_LOCK " xaddl %0,%1" + : "+a" (rv), "+m" (*p)); + + return (rv + v); +} +#define atomic_add_long_nv(_p, _v) _atomic_add_long_nv(_p, _v) + +static inline unsigned long +_atomic_sub_int_nv(volatile unsigned int *p, unsigned int v) +{ + unsigned int rv = 0 - v; + + __asm volatile(_LOCK " xaddl %0,%1" + : "+a" (rv), "+m" (*p)); + + return (rv - v); +} +#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 = 0 - v; + + __asm volatile(_LOCK " xaddl %0,%1" + : "+a" (rv), "+m" (*p)); + + return (rv - v); +} +#define atomic_sub_long_nv(_p, _v) _atomic_sub_long_nv(_p, _v) + +/* + * The IA-32 architecture is rather strongly ordered. When accessing + * normal write-back cacheable memory, only reads may be reordered with + * older writes to different locations. There are a few instructions + * (clfush, non-temporal move instructions) that obey weaker ordering + * rules, but those instructions will only be used in (inline) + * assembly code where we can add the necessary fence instructions + * ourselves. + */ + +#define __membar(_f) do { __asm volatile(_f ::: "memory"); } while (0) + +#if defined(MULTIPROCESSOR) || !defined(_KERNEL) +#define membar_enter() __membar("lock; addl $0,0(%%esp)") +#define membar_exit() __membar("") +#define membar_producer() __membar("") +#define membar_consumer() __membar("") +#define membar_sync() __membar("lock; addl $0,0(%%esp)") +#else +#define membar_enter() __membar("") +#define membar_exit() __membar("") +#define membar_producer() __membar("") +#define membar_consumer() __membar("") +#define membar_sync() __membar("") +#endif + +#define membar_enter_after_atomic() __membar("") +#define membar_exit_before_atomic() __membar("") + +#ifdef _KERNEL + +/* virtio needs MP membars even on SP kernels */ +#define virtio_membar_producer() __membar("") +#define virtio_membar_consumer() __membar("") +#define virtio_membar_sync() __membar("lock; addl $0,0(%%esp)") + +static __inline u_int64_t +i386_atomic_testset_uq(volatile u_int64_t *ptr, u_int64_t val) +{ + __asm__ volatile ("\n1:\t" _LOCK " cmpxchg8b (%1); jnz 1b" : "+A" (val) : + "r" (ptr), "b" ((u_int32_t)val), "c" ((u_int32_t)(val >> 32))); + return val; +} + +static __inline u_int32_t +i386_atomic_testset_ul(volatile u_int32_t *ptr, unsigned long val) +{ + __asm__ volatile ("xchgl %0,(%2)" :"=r" (val):"0" (val),"r" (ptr)); + return val; +} + +static __inline int +i386_atomic_testset_i(volatile int *ptr, unsigned long val) +{ + __asm__ volatile ("xchgl %0,(%2)" :"=r" (val):"0" (val),"r" (ptr)); + return val; +} + +static __inline void +i386_atomic_setbits_l(volatile u_int32_t *ptr, unsigned long bits) +{ + __asm volatile(_LOCK " orl %1,%0" : "=m" (*ptr) : "ir" (bits)); +} + +static __inline void +i386_atomic_clearbits_l(volatile u_int32_t *ptr, unsigned long bits) +{ + bits = ~bits; + __asm volatile(_LOCK " andl %1,%0" : "=m" (*ptr) : "ir" (bits)); +} + +#define atomic_setbits_int i386_atomic_setbits_l +#define atomic_clearbits_int i386_atomic_clearbits_l + +#endif /* _KERNEL */ + +#undef _LOCK + +#endif /* !defined(_LOCORE) */ +#endif /* _MACHINE_ATOMIC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/biosvar.h b/lib/libc/include/x86-openbsd-none/i386/biosvar.h new file mode 100644 index 0000000000..db9769bb7c --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/biosvar.h @@ -0,0 +1,306 @@ +/* $OpenBSD: biosvar.h,v 1.68 2019/08/04 14:28:58 kettenis Exp $ */ + +/* + * Copyright (c) 1997-1999 Michael Shalayeff + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MACHINE_BIOSVAR_H_ +#define _MACHINE_BIOSVAR_H_ + + /* some boxes put apm data seg in the 2nd page */ +#define BOOTARG_OFF (PAGE_SIZE * 2) +#define BOOTARG_LEN (PAGE_SIZE * 1) +#define BOOTBIOS_ADDR (0x7c00) +#define BOOTBIOS_MAXSEC ((1 << 28) - 1) + + /* BIOS configure flags */ +#define BIOSF_BIOS32 0x0001 +#define BIOSF_PCIBIOS 0x0002 +#define BIOSF_PROMSCAN 0x0004 +#define BIOSF_SMBIOS 0x0008 + +/* BIOS media ID */ +#define BIOSM_F320K 0xff /* floppy ds/sd 8 spt */ +#define BIOSM_F160K 0xfe /* floppy ss/sd 8 spt */ +#define BIOSM_F360K 0xfd /* floppy ds/sd 9 spt */ +#define BIOSM_F180K 0xfc /* floppy ss/sd 9 spt */ +#define BIOSM_ROMD 0xfa /* ROM disk */ +#define BIOSM_F120M 0xf9 /* floppy ds/hd 15 spt 5.25" */ +#define BIOSM_F720K 0xf9 /* floppy ds/dd 9 spt 3.50" */ +#define BIOSM_HD 0xf8 /* hard drive */ +#define BIOSM_F144K 0xf0 /* floppy ds/hd 18 spt 3.50" */ +#define BIOSM_OTHER 0xf0 /* any other */ + +/* + * BIOS memory maps + */ +#define BIOS_MAP_END 0x00 /* End of array XXX - special */ +#define BIOS_MAP_FREE 0x01 /* Usable memory */ +#define BIOS_MAP_RES 0x02 /* Reserved memory */ +#define BIOS_MAP_ACPI 0x03 /* ACPI Reclaim memory */ +#define BIOS_MAP_NVS 0x04 /* ACPI NVS memory */ + +/* + * Optional ROM header + */ +typedef +struct bios_romheader { + uint16_t signature; /* 0xaa55 */ + uint8_t len; /* length in pages (512 bytes) */ + uint32_t entry; /* initialization entry point */ + uint8_t reserved[19]; + uint16_t pnpheader; /* offset to PnP expansion header */ +} __packed *bios_romheader_t; + +/* + * BIOS32 + */ +typedef +struct bios32_header { + uint32_t signature; /* 00: signature "_32_" */ + uint32_t entry; /* 04: entry point */ + uint8_t rev; /* 08: revision */ + uint8_t length; /* 09: header length */ + uint8_t cksum; /* 0a: modulo 256 checksum */ + uint8_t reserved[5]; +} __packed *bios32_header_t; + +typedef +struct bios32_entry_info { + uint32_t bei_base; + uint32_t bei_size; + uint32_t bei_entry; +} __packed *bios32_entry_info_t; + +typedef +struct bios32_entry { + uint32_t offset; + uint16_t segment; +} __packed *bios32_entry_t; + +#define BIOS32_START 0xe0000 +#define BIOS32_SIZE 0x20000 +#define BIOS32_END (BIOS32_START + BIOS32_SIZE - 0x10) + +#define BIOS32_MAKESIG(a, b, c, d) \ + ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24)) +#define BIOS32_SIGNATURE BIOS32_MAKESIG('_', '3', '2', '_') +#define PCIBIOS_SIGNATURE BIOS32_MAKESIG('$', 'P', 'C', 'I') +#define SMBIOS_SIGNATURE BIOS32_MAKESIG('_', 'S', 'M', '_') + +/* + * CTL_BIOS definitions. + */ +#define BIOS_DEV 1 /* int: BIOS boot device */ +#define BIOS_DISKINFO 2 /* struct: BIOS boot device info */ +#define BIOS_CKSUMLEN 3 /* int: disk cksum block count */ +#define BIOS_MAXID 4 /* number of valid machdep ids */ + +#define CTL_BIOS_NAMES { \ + { 0, 0 }, \ + { "biosdev", CTLTYPE_INT }, \ + { "diskinfo", CTLTYPE_STRUCT }, \ + { "cksumlen", CTLTYPE_INT }, \ +} + +#define BOOTARG_MEMMAP 0 +typedef struct _bios_memmap { + uint64_t addr; /* Beginning of block */ + uint64_t size; /* Size of block */ + uint32_t type; /* Type of block */ +} __packed bios_memmap_t; + +/* Info about disk from the bios, plus the mapping from + * BIOS numbers to BSD major (driver?) number. + * + * Also, do not bother with BIOSN*() macros, just parcel + * the info out, and use it like this. This makes for less + * of a dependence on BIOSN*() macros having to be the same + * across /boot, /bsd, and userland. + */ +#define BOOTARG_DISKINFO 1 +typedef struct _bios_diskinfo { + /* BIOS section */ + int bios_number; /* BIOS number of drive (or -1) */ + u_int bios_cylinders; /* BIOS cylinders */ + u_int bios_heads; /* BIOS heads */ + u_int bios_sectors; /* BIOS sectors */ + int bios_edd; /* EDD support */ + + /* BSD section */ + dev_t bsd_dev; /* BSD device */ + + /* Checksum section */ + uint32_t checksum; /* Checksum for drive */ + + /* Misc. flags */ + uint32_t flags; +#define BDI_INVALID 0x00000001 /* I/O error during checksumming */ +#define BDI_GOODLABEL 0x00000002 /* Had SCSI or ST506/ESDI disklabel */ +#define BDI_BADLABEL 0x00000004 /* Had another disklabel */ +#define BDI_EL_TORITO 0x00000008 /* 2,048-byte sectors */ +#define BDI_HIBVALID 0x00000010 /* hibernate signature valid */ +#define BDI_PICKED 0x80000000 /* kernel-only: cksum matched */ + +} __packed bios_diskinfo_t; + +#define BOOTARG_APMINFO 2 +typedef struct _bios_apminfo { + /* APM_CONNECT returned values */ + u_int apm_detail; + u_int apm_code32_base; + u_int apm_code16_base; + u_int apm_code_len; + u_int apm_data_base; + u_int apm_data_len; + u_int apm_entry; + u_int apm_code16_len; +} __packed bios_apminfo_t; + +#define BOOTARG_CKSUMLEN 3 /* uint32_t */ + +#define BOOTARG_PCIINFO 4 +typedef struct _bios_pciinfo { + /* PCI BIOS v2.0+ - Installation check values */ + uint32_t pci_chars; /* Characteristics (%eax) */ + uint32_t pci_rev; /* BCD Revision (%ebx) */ + uint32_t pci_entry32; /* PM entry point for PCI BIOS */ + uint32_t pci_lastbus; /* Number of last PCI bus */ +} __packed bios_pciinfo_t; + +#define BOOTARG_CONSDEV 5 +typedef struct _bios_consdev { + dev_t consdev; + int conspeed; + int consaddr; + int consfreq; +} __packed bios_consdev_t; + +#define BOOTARG_SMPINFO 6 /* struct mp_float[] */ + +#define BOOTARG_BOOTMAC 7 +typedef struct _bios_bootmac { + char mac[6]; +} __packed bios_bootmac_t; + +#define BOOTARG_DDB 8 +typedef struct _bios_ddb { + int db_console; +} __packed bios_ddb_t; + +#define BOOTARG_BOOTDUID 9 +typedef struct _bios_bootduid { + u_char duid[8]; +} __packed bios_bootduid_t; + +#define BOOTARG_BOOTSR 10 +#define BOOTSR_UUID_MAX 16 +#define BOOTSR_CRYPTO_MAXKEYBYTES 32 +typedef struct _bios_bootsr { + uint8_t uuid[BOOTSR_UUID_MAX]; + uint8_t maskkey[BOOTSR_CRYPTO_MAXKEYBYTES]; +} __packed bios_bootsr_t; + +#define BOOTARG_EFIINFO 11 +typedef struct _bios_efiinfo { + uint64_t config_acpi; + uint64_t config_smbios; + uint64_t fb_addr; + uint64_t fb_size; + uint32_t fb_height; + uint32_t fb_width; + uint32_t fb_pixpsl; /* pixels per scan line */ + uint32_t fb_red_mask; + uint32_t fb_green_mask; + uint32_t fb_blue_mask; + uint32_t fb_reserved_mask; +} __packed bios_efiinfo_t; + +#define BOOTARG_UCODE 12 +typedef struct _bios_ucode { + uint64_t uc_addr; + uint64_t uc_size; +} __packed bios_ucode_t; + +#if defined(_KERNEL) || defined (_STANDALONE) + +#ifdef _LOCORE +#define DOINT(n) int $0x20+(n) +#else +#define DOINT(n) "int $0x20+(" #n ")" + +extern volatile struct BIOS_regs { + uint32_t biosr_ax; + uint32_t biosr_cx; + uint32_t biosr_dx; + uint32_t biosr_bx; + uint32_t biosr_bp; + uint32_t biosr_si; + uint32_t biosr_di; + uint32_t biosr_ds; + uint32_t biosr_es; +} __packed BIOS_regs; + +#ifdef _KERNEL +#include + +struct bios_attach_args { + char *ba_name; + u_int ba_func; + bus_space_tag_t ba_iot; + bus_space_tag_t ba_memt; + union { + void *_p; + bios_apminfo_t *_ba_apmp; + paddr_t _ba_acpipbase; + } _; +}; + +#define ba_apmp _._ba_apmp +#define ba_acpipbase _._ba_acpipbase + +struct consdev; +struct proc; + +int bios_sysctl(int *, u_int, void *, size_t *, void *, size_t, struct proc *); + +void bios_getopt(void); + +/* bios32.c */ +int bios32_service(uint32_t, bios32_entry_t, bios32_entry_info_t); +void bios32_cleanup(void); + +extern u_int bootapiver; +extern bios_memmap_t *bios_memmap; +extern bios_efiinfo_t *bios_efiinfo; +extern bios_ucode_t *bios_ucode; +extern void *bios_smpinfo; +extern bios_pciinfo_t *bios_pciinfo; + +#endif /* _KERNEL */ +#endif /* _LOCORE */ +#endif /* _KERNEL || _STANDALONE */ + +#endif /* _MACHINE_BIOSVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/bus.h b/lib/libc/include/x86-openbsd-none/i386/bus.h new file mode 100644 index 0000000000..6ed2cb5fb7 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/bus.h @@ -0,0 +1,701 @@ +/* $OpenBSD: bus.h,v 1.67 2017/05/08 00:27:45 dlg Exp $ */ +/* $NetBSD: bus.h,v 1.6 1996/11/10 03:19:25 thorpej Exp $ */ + +/*- + * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 1996 Charles M. Hannum. All rights reserved. + * Copyright (c) 1996 Jason R. Thorpe. All rights reserved. + * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christopher G. Demetriou + * for the NetBSD Project. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MACHINE_BUS_H_ +#define _MACHINE_BUS_H_ + +#include +#include + +#include + +/* + * Bus address and size types + */ +typedef u_long bus_addr_t; +typedef u_long bus_size_t; + +/* + * Access methods for bus resources and address space. + */ +struct i386_bus_space_ops; +typedef const struct i386_bus_space_ops *bus_space_tag_t; +typedef u_long bus_space_handle_t; + +int bus_space_map(bus_space_tag_t t, bus_addr_t addr, + bus_size_t size, int flags, bus_space_handle_t *bshp); +/* like bus_space_map(), but without extent map checking/allocation */ +int _bus_space_map(bus_space_tag_t t, bus_addr_t addr, + bus_size_t size, int flags, bus_space_handle_t *bshp); +void bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh, + bus_size_t size); +/* like bus_space_unmap(), but without extent map deallocation */ +void _bus_space_unmap(bus_space_tag_t, bus_space_handle_t, + bus_size_t, bus_addr_t *); +int bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh, + bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp); +paddr_t bus_space_mmap(bus_space_tag_t, bus_addr_t, off_t, int, int); + +int bus_space_alloc(bus_space_tag_t t, bus_addr_t rstart, + bus_addr_t rend, bus_size_t size, bus_size_t align, + bus_size_t boundary, int flags, bus_addr_t *addrp, + bus_space_handle_t *bshp); +void bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh, + bus_size_t size); + +struct i386_bus_space_ops { + +/* + * u_intN_t bus_space_read_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset); + * + * Read a 1, 2, 4, or 8 byte quantity from bus space + * described by tag/handle/offset. + */ + u_int8_t (*read_1)(bus_space_handle_t, bus_size_t); + u_int16_t (*read_2)(bus_space_handle_t, bus_size_t); + u_int32_t (*read_4)(bus_space_handle_t, bus_size_t); + +#define bus_space_read_1(_t, _h, _o) ((_t)->read_1((_h), (_o))) +#define bus_space_read_2(_t, _h, _o) ((_t)->read_2((_h), (_o))) +#define bus_space_read_4(_t, _h, _o) ((_t)->read_4((_h), (_o))) + +#define bus_space_read_raw_2(t, h, o) \ + bus_space_read_2((t), (h), (o)) +#define bus_space_read_raw_4(t, h, o) \ + bus_space_read_4((t), (h), (o)) + +#if 0 +/* Cause a link error for bus_space_read_8 and bus_space_read_raw_8 */ +#define bus_space_read_8(t, h, o) !!! bus_space_read_8 unimplemented !!! +#define bus_space_read_raw_8(t, h, o) !!! bus_space_read_raw_8 unimplemented !!! +#endif + +/* + * void bus_space_read_multi_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_intN_t *addr, size_t count); + * + * Read `count' 1, 2, 4, or 8 byte quantities from bus space + * described by tag/handle/offset and copy into buffer provided. + */ + + void (*read_multi_1)(bus_space_handle_t, bus_size_t, + u_int8_t *, bus_size_t); + void (*read_multi_2)(bus_space_handle_t, bus_size_t, + u_int16_t *, bus_size_t); + void (*read_multi_4)(bus_space_handle_t, bus_size_t, + u_int32_t *, bus_size_t); + +#define bus_space_read_multi_1(_t, _h, _o, _a, _c) \ + ((_t)->read_multi_1((_h), (_o), (_a), (_c))) +#define bus_space_read_multi_2(_t, _h, _o, _a, _c) \ + ((_t)->read_multi_2((_h), (_o), (_a), (_c))) +#define bus_space_read_multi_4(_t, _h, _o, _a, _c) \ + ((_t)->read_multi_4((_h), (_o), (_a), (_c))) + +#if 0 /* Cause a link error for bus_space_read_multi_8 */ +#define bus_space_read_multi_8 !!! bus_space_read_multi_8 unimplemented !!! +#endif + +/* + * void bus_space_read_raw_multi_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_int8_t *addr, size_t count); + * + * Read `count' bytes in 2, 4 or 8 byte wide quantities from bus space + * described by tag/handle/offset and copy into buffer provided. The buffer + * must have proper alignment for the N byte wide entities. Furthermore + * possible byte-swapping should be done by these functions. + */ + +#define bus_space_read_raw_multi_2(t, h, o, a, c) \ + bus_space_read_multi_2((t), (h), (o), (u_int16_t *)(a), (c) >> 1) +#define bus_space_read_raw_multi_4(t, h, o, a, c) \ + bus_space_read_multi_4((t), (h), (o), (u_int32_t *)(a), (c) >> 2) + +#if 0 /* Cause a link error for bus_space_read_raw_multi_8 */ +#define bus_space_read_raw_multi_8 \ + !!! bus_space_read_raw_multi_8 unimplemented !!! +#endif + +/* + * void bus_space_read_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_intN_t *addr, size_t count); + * + * Read `count' 1, 2, 4, or 8 byte quantities from bus space + * described by tag/handle and starting at `offset' and copy into + * buffer provided. + */ + + void (*read_region_1)(bus_space_handle_t, + bus_size_t, u_int8_t *, bus_size_t); + void (*read_region_2)(bus_space_handle_t, + bus_size_t, u_int16_t *, bus_size_t); + void (*read_region_4)(bus_space_handle_t, + bus_size_t, u_int32_t *, bus_size_t); + +#define bus_space_read_region_1(_t, _h, _o, _a, _c) \ + ((_t)->read_region_1((_h), (_o), (_a), (_c))) +#define bus_space_read_region_2(_t, _h, _o, _a, _c) \ + ((_t)->read_region_2((_h), (_o), (_a), (_c))) +#define bus_space_read_region_4(_t, _h, _o, _a, _c) \ + ((_t)->read_region_4((_h), (_o), (_a), (_c))) + +#if 0 /* Cause a link error for bus_space_read_region_8 */ +#define bus_space_read_region_8 !!! bus_space_read_region_8 unimplemented !!! +#endif + +/* + * void bus_space_read_raw_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_int8_t *addr, size_t count); + * + * Read `count' bytes in 2, 4 or 8 byte wide quantities from bus space + * described by tag/handle and starting at `offset' and copy into + * buffer provided. The buffer must have proper alignment for the N byte + * wide entities. Furthermore possible byte-swapping should be done by + * these functions. + */ + +#define bus_space_read_raw_region_2(_t, _h, _o, _a, _c) \ + ((_t)->read_region_2((_h), (_o), (u_int16_t *)(_a), (_c) >> 1)) +#define bus_space_read_raw_region_4(_t, _h, _o, _a, _c) \ + ((_t)->read_region_4((_h), (_o), (u_int32_t *)(_a), (_c) >> 2)) + +#if 0 /* Cause a link error for bus_space_read_raw_region_8 */ +#define bus_space_read_raw_region_8 \ + !!! bus_space_read_raw_region_8 unimplemented !!! +#endif + +/* + * void bus_space_write_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_intN_t value); + * + * Write the 1, 2, 4, or 8 byte value `value' to bus space + * described by tag/handle/offset. + */ + + void (*write_1)(bus_space_handle_t, bus_size_t, u_int8_t); + void (*write_2)(bus_space_handle_t, bus_size_t, u_int16_t); + void (*write_4)(bus_space_handle_t, bus_size_t, u_int32_t); + +#define bus_space_write_1(_t, _h, _o, _v) \ + ((_t)->write_1((_h), (_o), (_v))) +#define bus_space_write_2(_t, _h, _o, _v) \ + ((_t)->write_2((_h), (_o), (_v))) +#define bus_space_write_4(_t, _h, _o, _v) \ + ((_t)->write_4((_h), (_o), (_v))) + +#define bus_space_write_raw_2(t, h, o, v) \ + bus_space_write_2((t), (h), (o), (v)) +#define bus_space_write_raw_4(t, h, o, v) \ + bus_space_write_4((t), (h), (o), (v)) + +#if 0 +/* Cause a link error for bus_space_write_8 and bus_space_write_raw_8 */ +#define bus_space_write_8 !!! bus_space_write_8 not implemented !!! +#define bus_space_write_raw_8 !!! bus_space_write_raw_8 not implemented !!! +#endif + +/* + * void bus_space_write_multi_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * const u_intN_t *addr, size_t count); + * + * Write `count' 1, 2, 4, or 8 byte quantities from the buffer + * provided to bus space described by tag/handle/offset. + */ + + void (*write_multi_1)(bus_space_handle_t, + bus_size_t, const u_int8_t *, bus_size_t); + void (*write_multi_2)(bus_space_handle_t, + bus_size_t, const u_int16_t *, bus_size_t); + void (*write_multi_4)(bus_space_handle_t, + bus_size_t, const u_int32_t *, bus_size_t); + +#define bus_space_write_multi_1(_t, _h, _o, _a, _c) \ + ((_t)->write_multi_1((_h), (_o), (_a), (_c))) +#define bus_space_write_multi_2(_t, _h, _o, _a, _c) \ + ((_t)->write_multi_2((_h), (_o), (_a), (_c))) +#define bus_space_write_multi_4(_t, _h, _o, _a, _c) \ + ((_t)->write_multi_4((_h), (_o), (_a), (_c))) + +#if 0 /* Cause a link error for bus_space_write_multi_8 */ +#define bus_space_write_multi_8(t, h, o, a, c) \ + !!! bus_space_write_multi_8 unimplemented !!! +#endif + +/* + * void bus_space_write_raw_multi_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * const u_int8_t *addr, size_t count); + * + * Write `count' bytes in 2, 4 or 8 byte wide quantities from the buffer + * provided to bus space described by tag/handle/offset. The buffer + * must have proper alignment for the N byte wide entities. Furthermore + * possible byte-swapping should be done by these functions. + */ + +#define bus_space_write_raw_multi_2(_t, _h, _o, _a, _c) \ + ((_t)->write_multi_2((_h), (_o), (const u_int16_t *)(_a), (_c) >> 1)) +#define bus_space_write_raw_multi_4(_t, _h, _o, _a, _c) \ + ((_t)->write_multi_4((_h), (_o), (const u_int32_t *)(_a), (_c) >> 2)) + +#if 0 /* Cause a link error for bus_space_write_raw_multi_8 */ +#define bus_space_write_raw_multi_8 \ + !!! bus_space_write_raw_multi_8 unimplemented !!! +#endif + +/* + * void bus_space_write_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * const u_intN_t *addr, size_t count); + * + * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided + * to bus space described by tag/handle starting at `offset'. + */ + + void (*write_region_1)(bus_space_handle_t, + bus_size_t, const u_int8_t *, bus_size_t); + void (*write_region_2)(bus_space_handle_t, + bus_size_t, const u_int16_t *, bus_size_t); + void (*write_region_4)(bus_space_handle_t, + bus_size_t, const u_int32_t *, bus_size_t); + +#define bus_space_write_region_1(_t, _h, _o, _a, _c) \ + ((_t)->write_region_1((_h), (_o), (_a), (_c))) +#define bus_space_write_region_2(_t, _h, _o, _a, _c) \ + ((_t)->write_region_2((_h), (_o), (_a), (_c))) +#define bus_space_write_region_4(_t, _h, _o, _a, _c) \ + ((_t)->write_region_4((_h), (_o), (_a), (_c))) + +#if 0 /* Cause a link error for bus_space_write_region_8 */ +#define bus_space_write_region_8 \ + !!! bus_space_write_region_8 unimplemented !!! +#endif + +/* + * void bus_space_write_raw_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * const u_int8_t *addr, size_t count); + * + * Write `count' bytes in 2, 4 or 8 byte wide quantities to bus space + * described by tag/handle and starting at `offset' from the + * buffer provided. The buffer must have proper alignment for the N byte + * wide entities. Furthermore possible byte-swapping should be done by + * these functions. + */ + +#define bus_space_write_raw_region_2(_t, _h, _o, _a, _c) \ + ((_t)->write_region_2((_h), (_o), (const u_int16_t *)(_a), (_c) >> 1)) +#define bus_space_write_raw_region_4(_t, _h, _o, _a, _c) \ + ((_t)->write_region_4((_h), (_o), (const u_int32_t *)(_a), (_c) >> 2)) + +#if 0 /* Cause a link error for bus_space_write_raw_region_8 */ +#define bus_space_write_raw_region_8 \ + !!! bus_space_write_raw_region_8 unimplemented !!! +#endif + +/* + * void bus_space_set_multi_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_intN_t val, size_t count); + * + * Write the 1, 2, 4, or 8 byte value `val' to bus space described + * by tag/handle/offset `count' times. + */ + + void (*set_multi_1)(bus_space_handle_t, + bus_size_t, u_int8_t, size_t); + void (*set_multi_2)(bus_space_handle_t, + bus_size_t, u_int16_t, size_t); + void (*set_multi_4)(bus_space_handle_t, + bus_size_t, u_int32_t, size_t); + +#define bus_space_set_multi_1(_t, _h, _o, _a, _c) \ + ((_t)->set_multi_1((_h), (_o), (_a), (_c))) +#define bus_space_set_multi_2(_t, _h, _o, _a, _c) \ + ((_t)->set_multi_2((_h), (_o), (_a), (_c))) +#define bus_space_set_multi_4(_t, _h, _o, _a, _c) \ + ((_t)->set_multi_4((_h), (_o), (_a), (_c))) + +#if 0 /* Cause a link error for bus_space_set_multi_8 */ +#define bus_space_set_multi_8 \ + !!! bus_space_set_multi_8 unimplemented !!! +#endif + +/* + * void bus_space_set_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_intN_t val, size_t count); + * + * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described + * by tag/handle starting at `offset'. + */ + + void (*set_region_1)(bus_space_handle_t, + bus_size_t, u_int8_t, size_t); + void (*set_region_2)(bus_space_handle_t, + bus_size_t, u_int16_t, size_t); + void (*set_region_4)(bus_space_handle_t, + bus_size_t, u_int32_t, size_t); + +#define bus_space_set_region_1(_t, _h, _o, _a, _c) \ + ((_t)->set_region_1((_h), (_o), (_a), (_c))) +#define bus_space_set_region_2(_t, _h, _o, _a, _c) \ + ((_t)->set_region_2((_h), (_o), (_a), (_c))) +#define bus_space_set_region_4(_t, _h, _o, _a, _c) \ + ((_t)->set_region_4((_h), (_o), (_a), (_c))) + +#if 0 /* Cause a link error for bus_space_set_region_8 */ +#define bus_space_set_region_8 \ + !!! bus_space_set_region_8 unimplemented !!! +#endif + +/* + * void bus_space_copy_N(bus_space_tag_t tag, + * bus_space_handle_t bsh1, bus_size_t off1, + * bus_space_handle_t bsh2, bus_size_t off2, + * size_t count); + * + * Copy `count' 1, 2, 4, or 8 byte values from bus space starting + * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2. + */ + + void (*copy_1)(bus_space_handle_t, + bus_size_t, bus_space_handle_t, bus_size_t, size_t); + void (*copy_2)(bus_space_handle_t, + bus_size_t, bus_space_handle_t, bus_size_t, size_t); + void (*copy_4)(bus_space_handle_t, + bus_size_t, bus_space_handle_t, bus_size_t, size_t); + +#define bus_space_copy_1(_t, _h1, _o1, _h2, _o2, _c) \ + ((_t)->copy_1((_h1), (_o1), (_h2), (_o2), (_c))) +#define bus_space_copy_2(_t, _h1, _o1, _h2, _o2, _c) \ + ((_t)->copy_2((_h1), (_o1), (_h2), (_o2), (_c))) +#define bus_space_copy_4(_t, _h1, _o1, _h2, _o2, _c) \ + ((_t)->copy_4((_h1), (_o1), (_h2), (_o2), (_c))) + +#if 0 /* Cause a link error for bus_space_copy_8 */ +#define bus_space_copy_8 \ + !!! bus_space_copy_8 unimplemented !!! +#endif + +#define i386_space_copy1(a1, a2, cnt, movs, df) \ + __asm volatile(df "\n\trep\n\t" movs : \ + "+S" (a1), "+D" (a2), "+c" (cnt) :: "memory", "cc"); + +#define i386_space_copy(a1, a2, sz, cnt) do { \ + if ((void *)(a1) < (void *)(a2)) { \ + a1 += ((cnt) - 1) * (sz); a2 += ((cnt) - 1) * (sz); \ + switch (sz) { \ + case 1: i386_space_copy1(a1,a2,cnt,"movsb","std");break;\ + case 2: i386_space_copy1(a1,a2,cnt,"movsw","std");break;\ + case 4: i386_space_copy1(a1,a2,cnt,"movsl","std");break;\ + } \ + __asm volatile("cld"); /* must restore before func ret */ \ + } else \ + switch (sz) { \ + case 1: i386_space_copy1(a1,a2,cnt,"movsb","cld");break;\ + case 2: i386_space_copy1(a1,a2,cnt,"movsw","cld");break;\ + case 4: i386_space_copy1(a1,a2,cnt,"movsl","cld");break;\ + } \ +} while (0) + +/* + * void *bus_space_vaddr(bus_space_tag_t, bus_space_handle_t); + * + * Get the kernel virtual address for the mapped bus space. + * Only allowed for regions mapped with BUS_SPACE_MAP_LINEAR. + */ + void * (*vaddr)(bus_space_handle_t); + +#define bus_space_vaddr(_t, _h) \ + ((_t)->vaddr((_h))) +}; + +/* + * Bus read/write barrier methods. + * + * void bus_space_barrier(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * bus_size_t len, int flags); + * + * Note: the i386 does not currently require barriers, but we must + * provide the flags to MI code. + */ +#define bus_space_barrier(t, h, o, l, f) do { \ + ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)));\ + __asm volatile("" : : : "memory"); \ +} while (0) +#define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */ +#define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */ + +#define BUS_SPACE_MAP_CACHEABLE 0x0001 +#define BUS_SPACE_MAP_LINEAR 0x0002 +#define BUS_SPACE_MAP_PREFETCHABLE 0x0008 + +/* + * Values for the i386 bus space tag, not to be used directly by MI code. + */ + +/* space is i/o space */ +extern const struct i386_bus_space_ops i386_bus_space_io_ops; +#define I386_BUS_SPACE_IO (&i386_bus_space_io_ops) + +/* space is mem space */ +extern const struct i386_bus_space_ops i386_bus_space_mem_ops; +#define I386_BUS_SPACE_MEM (&i386_bus_space_mem_ops) + +/* + * Flags used in various bus DMA methods. + */ +#define BUS_DMA_WAITOK 0x0000 /* safe to sleep (pseudo-flag) */ +#define BUS_DMA_NOWAIT 0x0001 /* not safe to sleep */ +#define BUS_DMA_ALLOCNOW 0x0002 /* perform resource allocation now */ +#define BUS_DMA_COHERENT 0x0004 /* hint: map memory DMA coherent */ +#define BUS_DMA_BUS1 0x0010 /* placeholders for bus functions... */ +#define BUS_DMA_BUS2 0x0020 +#define BUS_DMA_BUS3 0x0040 +#define BUS_DMA_24BIT 0x0080 /* isadma map */ +#define BUS_DMA_STREAMING 0x0100 /* hint: sequential, unidirectional */ +#define BUS_DMA_READ 0x0200 /* mapping is device -> memory only */ +#define BUS_DMA_WRITE 0x0400 /* mapping is memory -> device only */ +#define BUS_DMA_NOCACHE 0x0800 /* map memory uncached */ +#define BUS_DMA_ZERO 0x1000 /* dmamem_alloc return zeroed mem */ +#define BUS_DMA_64BIT 0x2000 /* device handles 64bit dva */ + +/* Forwards needed by prototypes below. */ +struct mbuf; +struct proc; +struct uio; + +/* + * Operations performed by bus_dmamap_sync(). + */ +#define BUS_DMASYNC_PREREAD 0x01 +#define BUS_DMASYNC_POSTREAD 0x02 +#define BUS_DMASYNC_PREWRITE 0x04 +#define BUS_DMASYNC_POSTWRITE 0x08 + +typedef struct bus_dma_tag *bus_dma_tag_t; +typedef struct bus_dmamap *bus_dmamap_t; + +/* + * bus_dma_segment_t + * + * Describes a single contiguous DMA transaction. Values + * are suitable for programming into DMA registers. + */ +struct bus_dma_segment { + bus_addr_t ds_addr; /* DMA address */ + bus_size_t ds_len; /* length of transfer */ + /* + * Ugh. need this so can pass alignment down from bus_dmamem_alloc + * to scatter gather maps. only the first one is used so the rest is + * wasted space. bus_dma could do with fixing the api for this. + */ + bus_size_t _ds_boundary; /* don't cross */ + bus_size_t _ds_align; /* align to me */ +}; +typedef struct bus_dma_segment bus_dma_segment_t; + +/* + * bus_dma_tag_t + * + * A machine-dependent opaque type describing the implementation of + * DMA for a given bus. + */ + +struct bus_dma_tag { + void *_cookie; /* cookie used in the guts */ + + /* + * DMA mapping methods. + */ + int (*_dmamap_create)(bus_dma_tag_t, bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); + void (*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t); + int (*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int); + int (*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t, + struct mbuf *, int); + int (*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t, + struct uio *, int); + int (*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); + void (*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t); + void (*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t, + bus_addr_t, bus_size_t, int); + + /* + * DMA memory utility functions. + */ + int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); + int (*_dmamem_alloc_range)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int, + bus_addr_t, bus_addr_t); + void (*_dmamem_free)(bus_dma_tag_t, + bus_dma_segment_t *, int); + int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); + void (*_dmamem_unmap)(bus_dma_tag_t, caddr_t, size_t); + paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *, + int, off_t, int, int); +}; + +#define bus_dmamap_create(t, s, n, m, b, f, p) \ + (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p)) +#define bus_dmamap_destroy(t, p) \ + (*(t)->_dmamap_destroy)((t), (p)) +#define bus_dmamap_load(t, m, b, s, p, f) \ + (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f)) +#define bus_dmamap_load_mbuf(t, m, b, f) \ + (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f)) +#define bus_dmamap_load_uio(t, m, u, f) \ + (*(t)->_dmamap_load_uio)((t), (m), (u), (f)) +#define bus_dmamap_load_raw(t, m, sg, n, s, f) \ + (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f)) +#define bus_dmamap_unload(t, p) \ + (*(t)->_dmamap_unload)((t), (p)) +#define bus_dmamap_sync(t, p, o, l, ops) \ + (*(t)->_dmamap_sync)((t), (p), (o), (l), (ops)) + +#define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \ + (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f)) +#define bus_dmamem_alloc_range(t, s, a, b, sg, n, r, f, l, h) \ + (*(t)->_dmamem_alloc_range)((t), (s), (a), (b), (sg), \ + (n), (r), (f), (l), (h)) +#define bus_dmamem_free(t, sg, n) \ + (*(t)->_dmamem_free)((t), (sg), (n)) +#define bus_dmamem_map(t, sg, n, s, k, f) \ + (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f)) +#define bus_dmamem_unmap(t, k, s) \ + (*(t)->_dmamem_unmap)((t), (k), (s)) +#define bus_dmamem_mmap(t, sg, n, o, p, f) \ + (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f)) + +/* + * bus_dmamap_t + * + * Describes a DMA mapping. + */ +struct bus_dmamap { + /* + * PRIVATE MEMBERS: not for use by machine-independent code. + */ + bus_size_t _dm_size; /* largest DMA transfer mappable */ + int _dm_segcnt; /* number of segs this map can map */ + bus_size_t _dm_maxsegsz; /* largest possible segment */ + bus_size_t _dm_boundary; /* don't cross this */ + int _dm_flags; /* misc. flags */ + + void *_dm_cookie; /* cookie for bus-specific functions */ + + /* + * PUBLIC MEMBERS: these are used by machine-independent code. + */ + bus_size_t dm_mapsize; /* size of the mapping */ + int dm_nsegs; /* # valid segments in mapping */ + bus_dma_segment_t dm_segs[1]; /* segments; variable length */ +}; + +int _bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t, + bus_size_t, int, bus_dmamap_t *); +void _bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t); +int _bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int); +int _bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, + struct mbuf *, int); +int _bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, + struct uio *, int); +int _bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); +void _bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t); +void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, + bus_size_t, int); + +int _bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size, + bus_size_t alignment, bus_size_t boundary, + bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags); +void _bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs, + int nsegs); +int _bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs, + int nsegs, size_t size, caddr_t *kvap, int flags); +void _bus_dmamem_unmap(bus_dma_tag_t tag, caddr_t kva, + size_t size); +paddr_t _bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs, + int nsegs, off_t off, int prot, int flags); + +int _bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size, + bus_size_t alignment, bus_size_t boundary, + bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags, + paddr_t low, paddr_t high); + +#endif /* _MACHINE_BUS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/cdefs.h b/lib/libc/include/x86-openbsd-none/i386/cdefs.h new file mode 100644 index 0000000000..af2607c12a --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/cdefs.h @@ -0,0 +1,21 @@ +/* $OpenBSD: cdefs.h,v 1.10 2013/03/28 17:30:45 martynas Exp $ */ + +/* + * Written by J.T. Conklin 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_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/codepatch.h b/lib/libc/include/x86-openbsd-none/i386/codepatch.h new file mode 100644 index 0000000000..fa33bf8bf8 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/codepatch.h @@ -0,0 +1,52 @@ +/* $OpenBSD: codepatch.h,v 1.3 2023/07/31 17:10:31 bluhm Exp $ */ +/* + * Copyright (c) 2014-2015 Stefan Fritsch + * + * 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_CODEPATCH_H_ +#define _MACHINE_CODEPATCH_H_ + +#include + +#ifndef _LOCORE + +void *codepatch_maprw(vaddr_t *nva, vaddr_t dest); +void codepatch_unmaprw(vaddr_t nva); +void codepatch_fill_nop(void *caddr, uint16_t len); +void codepatch_nop(uint16_t tag); +void codepatch_replace(uint16_t tag, const void *code, size_t len); +void codepatch_call(uint16_t tag, void *func); + +#endif /* !_LOCORE */ + +/* + * Mark the start of some code snippet to be patched. + */ +#define CODEPATCH_START 998: +/* + * Mark the end of some code to be patched, and assign the given tag. + */ +#define CODEPATCH_END(tag) \ + 999: \ + .section .codepatch, "a" ;\ + .int 998b ;\ + .short (999b - 998b) ;\ + .short tag ;\ + .previous + +#define CPTAG_STAC 1 +#define CPTAG_CLAC 2 + +#endif /* _MACHINE_CODEPATCH_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/conf.h b/lib/libc/include/x86-openbsd-none/i386/conf.h new file mode 100644 index 0000000000..eaceeec5cd --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/conf.h @@ -0,0 +1,60 @@ +/* $OpenBSD: conf.h,v 1.21 2024/06/11 03:28:42 jsg Exp $ */ +/* $NetBSD: conf.h,v 1.2 1996/05/05 19:28:34 christos Exp $ */ + +/* + * Copyright (c) 1996 Christos Zoulas. 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 Christos Zoulas. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#define mmread mmrw +#define mmwrite mmrw +cdev_decl(mm); + +bdev_decl(fd); +cdev_decl(fd); + +#define cdev_acpiapm_init(c,n) {\ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,n,kqfilter) } + +cdev_decl(spkr); + +cdev_decl(joy); + +cdev_decl(bios); + +cdev_decl(acpi); + +cdev_decl(apm); + +cdev_decl(acpiapm); + +cdev_decl(pctr); \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/cpu.h b/lib/libc/include/x86-openbsd-none/i386/cpu.h new file mode 100644 index 0000000000..eda232d75f --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/cpu.h @@ -0,0 +1,533 @@ +/* $OpenBSD: cpu.h,v 1.192 2024/06/18 12:37:29 jsg Exp $ */ +/* $NetBSD: cpu.h,v 1.35 1996/05/05 19:29:26 christos 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. + * + * @(#)cpu.h 5.4 (Berkeley) 5/9/91 + */ + +#ifndef _MACHINE_CPU_H_ +#define _MACHINE_CPU_H_ + +/* + * Definitions unique to i386 cpu support. + */ +#ifdef _KERNEL +#include +#include +#include +#include +#include + +#ifdef MULTIPROCESSOR +#include +#include +#endif + +#endif /* _KERNEL */ + +/* + * Arguments to hardclock, softclock and statclock + * encapsulate the previous machine state in an opaque + * clockframe; for now, use generic intrframe. + * + * XXX intrframe has a lot of gunk we don't need. + */ +#define clockframe intrframe + +#include +#include +#include +#include +#include +#include + +struct intrsource; + +#ifdef _KERNEL +/* XXX stuff to move to cpuvar.h later */ +struct cpu_info { + u_int32_t ci_kern_cr3; /* U+K page table */ + u_int32_t ci_scratch; /* for U<-->K transition */ + +#define ci_PAGEALIGN ci_dev + struct device *ci_dev; /* our device */ + struct cpu_info *ci_self; /* pointer to this structure */ + struct schedstate_percpu ci_schedstate; /* scheduler state */ + struct cpu_info *ci_next; /* next cpu */ + + /* + * Public members. + */ + struct proc *ci_curproc; /* current owner of the processor */ + cpuid_t ci_cpuid; /* our CPU ID */ + u_int ci_apicid; /* our APIC ID */ + u_int ci_acpi_proc_id; + u_int32_t ci_randseed; + + u_int32_t ci_kern_esp; /* kernel-only stack */ + u_int32_t ci_intr_esp; /* U<-->K trampoline stack */ + u_int32_t ci_user_cr3; /* U-K page table */ + +#if defined(MULTIPROCESSOR) + struct srp_hazard ci_srp_hazards[SRP_HAZARD_NUM]; +#define __HAVE_UVM_PERCPU + struct uvm_pmr_cache ci_uvm; +#endif + + /* + * Private members. + */ + struct proc *ci_fpcurproc; /* current owner of the FPU */ + struct proc *ci_fpsaveproc; + int ci_fpsaving; /* save in progress */ + + struct pcb *ci_curpcb; /* VA of current HW PCB */ + struct pcb *ci_idle_pcb; /* VA of current PCB */ + struct pmap *ci_curpmap; + + struct intrsource *ci_isources[MAX_INTR_SOURCES]; + u_int32_t ci_ipending; + int ci_ilevel; + int ci_idepth; + u_int32_t ci_imask[NIPL]; + u_int32_t ci_iunmask[NIPL]; +#ifdef DIAGNOSTIC + int ci_mutex_level; +#endif + + paddr_t ci_idle_pcb_paddr; /* PA of idle PCB */ + volatile u_long ci_flags; /* flags; see below */ + u_int32_t ci_ipis; /* interprocessor interrupts pending */ + + u_int32_t ci_level; + u_int32_t ci_vendor[4]; + u_int32_t ci_signature; /* X86 cpuid type */ + u_int32_t ci_family; /* extended cpuid family */ + u_int32_t ci_model; /* extended cpuid model */ + u_int32_t ci_feature_flags; /* X86 CPUID feature bits */ + u_int32_t ci_feature_sefflags_ebx;/* more CPUID feature bits */ + u_int32_t ci_feature_sefflags_ecx;/* more CPUID feature bits */ + u_int32_t ci_feature_sefflags_edx;/* more CPUID feature bits */ + u_int32_t ci_feature_tpmflags; /* thermal & power bits */ + u_int32_t cpu_class; /* CPU class */ + u_int32_t ci_cflushsz; /* clflush cache-line size */ + + int ci_inatomic; + + struct cpu_functions *ci_func; /* start/stop functions */ + void (*cpu_setup)(struct cpu_info *); /* proc-dependant init */ + + struct device *ci_acpicpudev; + volatile u_int ci_mwait; +#define MWAIT_IN_IDLE 0x1 /* don't need IPI to wake */ +#define MWAIT_KEEP_IDLING 0x2 /* cleared by other cpus to wake me */ +#define MWAIT_ONLY 0x4 /* set if all idle states use mwait */ +#define MWAIT_IDLING (MWAIT_IN_IDLE | MWAIT_KEEP_IDLING) + + int ci_want_resched; + + union descriptor *ci_gdt; + struct i386tss *ci_tss; + struct i386tss *ci_nmi_tss; + + volatile int ci_ddb_paused; /* paused due to other proc in ddb */ +#define CI_DDB_RUNNING 0 +#define CI_DDB_SHOULDSTOP 1 +#define CI_DDB_STOPPED 2 +#define CI_DDB_ENTERDDB 3 +#define CI_DDB_INDDB 4 + + struct ksensordev ci_sensordev; + struct ksensor ci_sensor; +#if defined(GPROF) || defined(DDBPROF) + struct gmonparam *ci_gmon; + struct clockintr ci_gmonclock; +#endif + struct clockqueue ci_queue; + char ci_panicbuf[512]; +}; + +/* + * Processor flag notes: The "primary" CPU has certain MI-defined + * roles (mostly relating to hardclock handling); we distinguish + * between the processor which booted us, and the processor currently + * holding the "primary" role just to give us the flexibility later to + * change primaries should we be sufficiently twisted. + */ + +#define CPUF_BSP 0x0001 /* CPU is the original BSP */ +#define CPUF_AP 0x0002 /* CPU is an AP */ +#define CPUF_SP 0x0004 /* CPU is only processor */ +#define CPUF_PRIMARY 0x0008 /* CPU is active primary processor */ +#define CPUF_APIC_CD 0x0010 /* CPU has apic configured */ +#define CPUF_CONST_TSC 0x0020 /* CPU has constant TSC */ + +#define CPUF_PRESENT 0x1000 /* CPU is present */ +#define CPUF_RUNNING 0x2000 /* CPU is running */ +#define CPUF_VMM 0x4000 /* CPU is executing in VMM mode */ + +/* + * We statically allocate the CPU info for the primary CPU (or, + * the only CPU on uniprocessors), and the primary CPU is the + * first CPU on the CPU info list. + */ +struct cpu_info_full; +extern struct cpu_info_full cpu_info_full_primary; +#define cpu_info_primary (*(struct cpu_info *)((char *)&cpu_info_full_primary + PAGE_SIZE*2 - offsetof(struct cpu_info, ci_PAGEALIGN))) + +extern struct cpu_info *cpu_info_list; + +#define CPU_INFO_ITERATOR int +#define CPU_INFO_FOREACH(cii, ci) for (cii = 0, ci = cpu_info_list; \ + ci != NULL; ci = ci->ci_next) + +#define CPU_INFO_UNIT(ci) ((ci)->ci_dev ? (ci)->ci_dev->dv_unit : 0) + +#ifdef MULTIPROCESSOR + +#define MAXCPUS 32 /* because we use a bitmask */ + +#define CPU_STARTUP(_ci) ((_ci)->ci_func->start(_ci)) +#define CPU_STOP(_ci) ((_ci)->ci_func->stop(_ci)) +#define CPU_START_CLEANUP(_ci) ((_ci)->ci_func->cleanup(_ci)) + +static struct cpu_info *curcpu(void); + +static __inline struct cpu_info * +curcpu(void) +{ + struct cpu_info *ci; + + /* Can't include sys/param.h for offsetof() since it includes us */ + __asm volatile("movl %%fs:%1, %0" : + "=r" (ci) : "m" + (*(struct cpu_info * const *)&((struct cpu_info *)0)->ci_self)); + return ci; +} +#define cpu_number() (curcpu()->ci_cpuid) + +#define CPU_IS_PRIMARY(ci) ((ci)->ci_flags & CPUF_PRIMARY) +#define CPU_IS_RUNNING(ci) ((ci)->ci_flags & CPUF_RUNNING) + +extern struct cpu_info *cpu_info[MAXCPUS]; + +extern void cpu_boot_secondary_processors(void); +extern void cpu_init_idle_pcbs(void); + +void cpu_kick(struct cpu_info *); +void cpu_unidle(struct cpu_info *); + +#define CPU_BUSY_CYCLE() __asm volatile("pause": : : "memory") + +#else /* MULTIPROCESSOR */ + +#define MAXCPUS 1 + +#define cpu_number() 0 +#define curcpu() (&cpu_info_primary) + +#define CPU_IS_PRIMARY(ci) 1 +#define CPU_IS_RUNNING(ci) 1 + +#define cpu_kick(ci) +#define cpu_unidle(ci) + +#define CPU_BUSY_CYCLE() __asm volatile ("" ::: "memory") + +#endif + +#include + +#define aston(p) ((p)->p_md.md_astpending = 1) + +#define curpcb curcpu()->ci_curpcb + +unsigned int cpu_rnd_messybits(void); + +/* + * Preempt the current process if in interrupt from user mode, + * or after the current trap/syscall if in system mode. + */ +extern void need_resched(struct cpu_info *); +#define clear_resched(ci) (ci)->ci_want_resched = 0 + +#define CLKF_USERMODE(frame) USERMODE((frame)->if_cs, (frame)->if_eflags) +#define CLKF_PC(frame) ((frame)->if_eip) +#define CLKF_INTR(frame) (IDXSEL((frame)->if_cs) == GICODE_SEL) + +/* + * This is used during profiling to integrate system time. + */ +#define PROC_PC(p) ((p)->p_md.md_regs->tf_eip) +#define PROC_STACK(p) ((p)->p_md.md_regs->tf_esp) + +/* + * Give a profiling tick to the current process when the user profiling + * buffer pages are invalid. On the i386, request an ast to send us + * through trap(), marking the proc as needing a profiling tick. + */ +#define need_proftick(p) aston(p) + +/* + * Notify the current process (p) that it has a signal pending, + * process as soon as possible. + */ +void signotify(struct proc *); + +/* + * We need a machine-independent name for this. + */ +extern void (*delay_func)(int); +void delay_fini(void(*)(int)); +void delay_init(void(*)(int), int); +struct timeval; + +#define DELAY(x) (*delay_func)(x) +#define delay(x) (*delay_func)(x) + +/* + * High resolution clock support (Pentium only) + */ +void calibrate_cyclecounter(void); + +/* + * pull in #defines for kinds of processors + */ +#include + +struct cpu_cpuid_nameclass { + const char *cpu_id; + int cpu_vendor; + const char *cpu_vendorname; + struct cpu_cpuid_family { + int cpu_class; + const char *cpu_models[CPU_MAXMODEL+2]; + void (*cpu_setup)(struct cpu_info *); + } cpu_family[CPU_MAXFAMILY - CPU_MINFAMILY + 1]; +}; + +struct cpu_cpuid_feature { + int feature_bit; + const char *feature_name; +}; + +/* locore.s */ +extern int cpu_id; +extern char cpu_vendor[]; /* note: NOT nul-terminated */ +extern char cpu_brandstr[]; +extern int cpuid_level; +extern int cpu_miscinfo; +extern int cpu_feature; +extern int ecpu_feature; +extern int cpu_ecxfeature; +extern int ecpu_ecxfeature; +extern int cpu_cache_eax; +extern int cpu_cache_ebx; +extern int cpu_cache_ecx; +extern int cpu_cache_edx; +extern int cpu_perf_eax; +extern int cpu_perf_ebx; +extern int cpu_perf_edx; +extern int cpu_apmi_edx; +extern int cpu_pae; /* cpu has both PAE and NX features */ + +/* cpu.c */ +extern u_int cpu_mwait_size; +extern u_int cpu_mwait_states; +extern void cpu_update_nmi_cr3(vaddr_t); +extern void cpu_tsx_disable(struct cpu_info *); + +/* machdep.c */ +extern int cpu_apmhalt; +extern int cpu_class; +extern char cpu_model[]; +extern const struct cpu_cpuid_nameclass i386_cpuid_cpus[]; +extern void (*cpu_idle_enter_fcn)(void); +extern void (*cpu_idle_cycle_fcn)(void); +extern void (*cpu_idle_leave_fcn)(void); +extern void (*cpu_suspend_cycle_fcn)(void); + +extern int cpuspeed; + +#if !defined(SMALL_KERNEL) +#define BUS66 6667 +#define BUS100 10000 +#define BUS133 13333 +#define BUS166 16667 +#define BUS200 20000 +#define BUS266 26667 +#define BUS333 33333 +extern int bus_clock; +#endif + +/* F00F bug fix stuff for pentium cpu */ +extern int cpu_f00f_bug; +void fix_f00f(void); + +/* dkcsum.c */ +void dkcsumattach(void); + +extern int i386_use_fxsave; +extern int i386_has_sse; +extern int i386_has_sse2; + +extern void (*update_cpuspeed)(void); + +extern void (*initclock_func)(void); +extern void (*startclock_func)(void); + +/* machdep.c */ +void dumpconf(void); +void cpu_reset(void); +void i386_proc0_tss_init(void); +void i386_init_pcb_tss(struct cpu_info *); +void cpuid(u_int32_t, u_int32_t *); + +/* locore.s */ +struct region_descriptor; +void lgdt(struct region_descriptor *); + +struct pcb; +void savectx(struct pcb *); +void proc_trampoline(void); + +/* clock.c */ +void startclocks(void); +void rtcinit(void); +void rtcstart(void); +void rtcstop(void); +void i8254_delay(int); +void i8254_initclocks(void); +void i8254_startclock(void); +void i8254_start_both_clocks(void); +void i8254_inittimecounter(void); +void i8254_inittimecounter_simple(void); + +#if !defined(SMALL_KERNEL) +/* est.c */ +void est_init(struct cpu_info *, int); +void est_setperf(int); +/* longrun.c */ +void longrun_init(void); +void longrun_setperf(int); +/* p4tcc.c */ +void p4tcc_init(int, int); +void p4tcc_setperf(int); +/* powernow.c */ +void k6_powernow_init(void); +void k6_powernow_setperf(int); +/* powernow-k7.c */ +void k7_powernow_init(void); +void k7_powernow_setperf(int); +/* powernow-k8.c */ +void k8_powernow_init(void); +void k8_powernow_setperf(int); +/* k1x-pstate.c */ +void k1x_init(struct cpu_info *); +void k1x_setperf(int); +#endif + +/* npx.c */ +void npxsave_proc(struct proc *, int); +void npxsave_cpu(struct cpu_info *, int); + +/* isa_machdep.c */ +void isa_defaultirq(void); +int isa_nmi(void); + +/* pmap.c */ +void pmap_bootstrap(vaddr_t); + +/* vm_machdep.c */ +int kvtop(caddr_t); + +#ifdef MULTIPROCESSOR +/* mp_setperf.c */ +void mp_setperf_init(void); +#endif + +int cpu_paenable(void *); +#endif /* _KERNEL */ + +/* + * CTL_MACHDEP definitions. + */ +#define CPU_CONSDEV 1 /* dev_t: console terminal device */ +#define CPU_BIOS 2 /* BIOS variables */ +#define CPU_BLK2CHR 3 /* convert blk maj into chr one */ +#define CPU_CHR2BLK 4 /* convert chr maj into blk one */ +#define CPU_ALLOWAPERTURE 5 /* allow mmap of /dev/xf86 */ +#define CPU_CPUVENDOR 6 /* cpuid vendor string */ +#define CPU_CPUID 7 /* cpuid */ +#define CPU_CPUFEATURE 8 /* cpuid features */ +#define CPU_KBDRESET 10 /* keyboard reset under pcvt */ +#define CPU_OSFXSR 13 /* uses FXSAVE/FXRSTOR */ +#define CPU_SSE 14 /* supports SSE */ +#define CPU_SSE2 15 /* supports SSE2 */ +#define CPU_XCRYPT 16 /* supports VIA xcrypt in userland */ +#define CPU_LIDACTION 18 /* action caused by lid close */ +#define CPU_FORCEUKBD 19 /* Force ukbd(4) as console keyboard */ +#define CPU_MAXID 20 /* number of valid machdep ids */ + +#define CTL_MACHDEP_NAMES { \ + { 0, 0 }, \ + { "console_device", CTLTYPE_STRUCT }, \ + { "bios", CTLTYPE_INT }, \ + { "blk2chr", CTLTYPE_STRUCT }, \ + { "chr2blk", CTLTYPE_STRUCT }, \ + { "allowaperture", CTLTYPE_INT }, \ + { "cpuvendor", CTLTYPE_STRING }, \ + { "cpuid", CTLTYPE_INT }, \ + { "cpufeature", CTLTYPE_INT }, \ + { 0, 0 }, \ + { "kbdreset", CTLTYPE_INT }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "osfxsr", CTLTYPE_INT }, \ + { "sse", CTLTYPE_INT }, \ + { "sse2", CTLTYPE_INT }, \ + { "xcrypt", CTLTYPE_INT }, \ + { 0, 0 }, \ + { "lidaction", CTLTYPE_INT }, \ + { "forceukbd", CTLTYPE_INT }, \ +} + +/* + * This needs to be included late since it relies on definitions higher + * up in this file. + */ +#if defined(MULTIPROCESSOR) && defined(_KERNEL) +#include +#endif + +#endif /* !_MACHINE_CPU_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/cpu_full.h b/lib/libc/include/x86-openbsd-none/i386/cpu_full.h new file mode 100644 index 0000000000..fd87a09aad --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/cpu_full.h @@ -0,0 +1,67 @@ +/* $OpenBSD: cpu_full.h,v 1.3 2018/06/22 13:21:14 bluhm Exp $ */ +/* + * Copyright (c) 2018 Philip Guenther + * Copyright (c) 2018 Hans-Joerg Hoexer + * + * 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_CPU_FULL_H_ +#define _MACHINE_CPU_FULL_H_ + +#include /* offsetof, PAGE_SIZE */ +#include +#include + +struct cpu_info_full { + /* page mapped kRO in u-k */ + union { + struct { + struct i386tss uu_tss; + struct i386tss uu_nmi_tss; + union descriptor uu_gdt[NGDT]; + } u_tssgdt; + char u_align[PAGE_SIZE]; + } cif_TSS_RO; +#define cif_tss cif_TSS_RO.u_tssgdt.uu_tss +#define cif_nmi_tss cif_TSS_RO.u_tssgdt.uu_nmi_tss +#define cif_gdt cif_TSS_RO.u_tssgdt.uu_gdt + + /* start of page mapped kRW in u-k */ + uint32_t cif_tramp_stack[(PAGE_SIZE / 4 + - offsetof(struct cpu_info, ci_PAGEALIGN)) / sizeof(uint32_t)]; + uint32_t cif_nmi_stack[(3 * PAGE_SIZE / 4) / sizeof(uint32_t)]; + + /* + * Beginning of this hangs over into the kRW page; rest is + * unmapped in u-k + */ + struct cpu_info cif_cpu; +} __aligned(PAGE_SIZE); + +/* tss, align shim, and gdt must fit in a page */ +CTASSERT(_ALIGN(2 * sizeof(struct i386tss)) + + sizeof(struct segment_descriptor) * NGDT < PAGE_SIZE); + +/* verify expected alignment */ +CTASSERT(offsetof(struct cpu_info_full, cif_cpu.ci_PAGEALIGN) % PAGE_SIZE == 0); + +/* verify total size is multiple of page size */ +CTASSERT(sizeof(struct cpu_info_full) % PAGE_SIZE == 0); + +extern struct cpu_info_full cpu_info_full_primary; + +/* Now make sure the cpu_info_primary macro is correct */ +CTASSERT(&cpu_info_primary - &cpu_info_full_primary.cif_cpu == 0); + +#endif /* _MACHINE_CPU_FULL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/cpufunc.h b/lib/libc/include/x86-openbsd-none/i386/cpufunc.h new file mode 100644 index 0000000000..a13a9ba4a9 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/cpufunc.h @@ -0,0 +1,310 @@ +/* $OpenBSD: cpufunc.h,v 1.34 2025/06/20 14:06:34 sf Exp $ */ +/* $NetBSD: cpufunc.h,v 1.8 1994/10/27 04:15:59 cgd Exp $ */ + +/* + * Copyright (c) 1993 Charles Hannum. + * 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 Charles Hannum. + * 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 _MACHINE_CPUFUNC_H_ +#define _MACHINE_CPUFUNC_H_ + +#ifdef _KERNEL + +/* + * Functions to provide access to i386-specific instructions. + */ + +#include + +#include + +static __inline void invlpg(u_int); +static __inline void lidt(void *); +static __inline void lldt(u_short); +static __inline void ltr(u_short); +static __inline void lcr0(u_int); +static __inline u_int rcr0(void); +static __inline u_int rcr2(void); +static __inline void lcr3(u_int); +static __inline u_int rcr3(void); +static __inline void lcr4(u_int); +static __inline u_int rcr4(void); +static __inline void tlbflush(void); +static __inline u_int read_eflags(void); +static __inline void write_eflags(u_int); +static __inline void wbinvd(void); +static __inline void clflush(u_int32_t addr); +static __inline void mfence(void); +static __inline void wrmsr(u_int, u_int64_t); +static __inline u_int64_t rdmsr(u_int); +static __inline void breakpoint(void); + +static __inline void +invlpg(u_int addr) +{ + __asm volatile("invlpg (%0)" : : "r" (addr) : "memory"); +} + +static __inline void +lidt(void *p) +{ + __asm volatile("lidt (%0)" : : "r" (p) : "memory"); +} + +static __inline void +lldt(u_short sel) +{ + __asm volatile("lldt %0" : : "r" (sel)); +} + +static __inline void +ltr(u_short sel) +{ + __asm volatile("ltr %0" : : "r" (sel)); +} + +static __inline void +lcr0(u_int val) +{ + __asm volatile("movl %0,%%cr0" : : "r" (val)); +} + +static __inline u_int +rcr0(void) +{ + u_int val; + __asm volatile("movl %%cr0,%0" : "=r" (val)); + return val; +} + +static __inline u_int +rcr2(void) +{ + u_int val; + __asm volatile("movl %%cr2,%0" : "=r" (val)); + return val; +} + +static __inline void +lcr3(u_int val) +{ + __asm volatile("movl %0,%%cr3" : : "r" (val)); +} + +static __inline u_int +rcr3(void) +{ + u_int val; + __asm volatile("movl %%cr3,%0" : "=r" (val)); + return val; +} + +static __inline void +lcr4(u_int val) +{ + __asm volatile("movl %0,%%cr4" : : "r" (val)); +} + +static __inline u_int +rcr4(void) +{ + u_int val; + __asm volatile("movl %%cr4,%0" : "=r" (val)); + return val; +} + +static __inline void +tlbflush(void) +{ + u_int val; + __asm volatile("movl %%cr3,%0" : "=r" (val)); + __asm volatile("movl %0,%%cr3" : : "r" (val)); +} + +#ifdef notyet +void setidt(int idx, /*XXX*/caddr_t func, int typ, int dpl); +#endif + + +/* XXXX ought to be in psl.h with spl() functions */ + +static __inline u_int +read_eflags(void) +{ + u_int ef; + + __asm volatile("pushfl; popl %0" : "=r" (ef)); + return (ef); +} + +static __inline void +write_eflags(u_int ef) +{ + __asm volatile("pushl %0; popfl" : : "r" (ef)); +} + +static inline void +intr_enable(void) +{ + __asm volatile("sti"); +} + +static inline u_long +intr_disable(void) +{ + u_long ef; + + ef = read_eflags(); + __asm volatile("cli"); + return (ef); +} + +static inline void +intr_restore(u_long ef) +{ + write_eflags(ef); +} + +static __inline void +wbinvd(void) +{ + __asm volatile("wbinvd" : : : "memory"); +} + +#ifdef MULTIPROCESSOR +int wbinvd_on_all_cpus(void); +#else +static inline int +wbinvd_on_all_cpus(void) +{ + wbinvd(); + return 0; +} +#endif + +static __inline void +clflush(u_int32_t addr) +{ + __asm volatile("clflush %0" : "+m" (*(volatile char *)addr)); +} + +static __inline void +mfence(void) +{ + __asm volatile("mfence" : : : "memory"); +} + +static __inline u_int64_t +rdtsc(void) +{ + uint64_t tsc; + + __asm volatile("rdtsc" : "=A" (tsc)); + return (tsc); +} + +static inline uint64_t +rdtsc_lfence(void) +{ + uint64_t tsc; + + __asm volatile("lfence; rdtsc" : "=A" (tsc)); + return tsc; +} + +static __inline void +wrmsr(u_int msr, u_int64_t newval) +{ + __asm volatile("wrmsr" : : "A" (newval), "c" (msr)); +} + +static __inline u_int64_t +rdmsr(u_int msr) +{ + u_int64_t rv; + + __asm volatile("rdmsr" : "=A" (rv) : "c" (msr)); + return (rv); +} + +static __inline void +monitor(const volatile void *addr, u_long extensions, u_int hints) +{ + __asm volatile("monitor" + : : "a" (addr), "c" (extensions), "d" (hints)); +} + +static __inline void +mwait(u_long extensions, u_int hints) +{ + __asm volatile("mwait" : : "a" (hints), "c" (extensions)); +} + +/* + * Some of the undocumented AMD64 MSRs need a 'passcode' to access. + * + * See LinuxBIOSv2: src/cpu/amd/model_fxx/model_fxx_init.c + */ + +#define OPTERON_MSR_PASSCODE 0x9c5a203a + +static __inline u_int64_t +rdmsr_locked(u_int msr, u_int code) +{ + uint64_t rv; + __asm volatile("rdmsr" + : "=A" (rv) + : "c" (msr), "D" (code)); + return (rv); +} + +static __inline void +wrmsr_locked(u_int msr, u_int code, u_int64_t newval) +{ + __asm volatile("wrmsr" + : + : "A" (newval), "c" (msr), "D" (code)); +} + +/* Break into DDB. */ +static __inline void +breakpoint(void) +{ + __asm volatile("int $3"); +} + +void amd64_errata(struct cpu_info *); +void cpu_ucode_setup(void); +void cpu_ucode_apply(struct cpu_info *); + +struct cpu_info_full; +void cpu_enter_pages(struct cpu_info_full *); + +#endif /* _KERNEL */ +#endif /* !_MACHINE_CPUFUNC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/cputypes.h b/lib/libc/include/x86-openbsd-none/i386/cputypes.h new file mode 100644 index 0000000000..0cd4be7abc --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/cputypes.h @@ -0,0 +1,60 @@ +/* $OpenBSD: cputypes.h,v 1.15 2022/08/22 08:53:55 jsg Exp $ */ +/* $NetBSD: cputypes.h,v 1.10 1997/10/18 04:51:03 mikel 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. 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. + */ + +/* + * Classes of Processor + */ + +#define CPUCLASS_486 1 +#define CPUCLASS_586 2 +#define CPUCLASS_686 3 + +/* + * CPU vendors + */ + +#define CPUVENDOR_UNKNOWN -1 +#define CPUVENDOR_INTEL 0 +#define CPUVENDOR_CYRIX 1 +#define CPUVENDOR_AMD 3 +#define CPUVENDOR_IDT 4 +#define CPUVENDOR_TRANSMETA 6 +#define CPUVENDOR_NS 7 +#define CPUVENDOR_VIA 8 +#define CPUVENDOR_SIS 9 + +/* + * Some other defines, dealing with values returned by cpuid. + */ + +#define CPU_MAXMODEL 15 /* Models within family range 0-15 */ +#define CPU_DEFMODEL 16 /* Value for unknown model -> default */ +#define CPU_MINFAMILY 4 /* Lowest that cpuid can return (486) */ +#define CPU_MAXFAMILY 0xf /* Highest we know (686) */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/cpuvar.h b/lib/libc/include/x86-openbsd-none/i386/cpuvar.h new file mode 100644 index 0000000000..e420bbdc64 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/cpuvar.h @@ -0,0 +1,98 @@ +/* $OpenBSD: cpuvar.h,v 1.8 2024/10/21 03:07:54 jsg Exp $ */ +/* $NetBSD: cpuvar.h,v 1.1.2.3 2000/02/21 18:54:07 sommerfeld Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by RedBack Networks Inc. + * + * Author: Bill Sommerfeld + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 1999 Stefan Grefen + * + * 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 NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 AUTHOR 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 AUTHOR AND 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. + */ + +struct cpu_functions { + int (*start)(struct cpu_info *); + int (*stop)(struct cpu_info *); + void (*cleanup)(struct cpu_info *); +}; + +extern struct cpu_functions mp_cpu_funcs; + +#define CPU_ROLE_SP 0 +#define CPU_ROLE_BP 1 +#define CPU_ROLE_AP 2 + +struct cpu_attach_args { + const char *caa_name; + int cpu_apicid; + int cpu_acpi_proc_id; + int cpu_role; + struct cpu_functions *cpu_func; + int cpu_signature; + int feature_flags; +}; + +#ifdef _KERNEL + +void i386_ipi(int,int,int); +void i386_ipi_init(int); + +void identifycpu(struct cpu_info *); +void cpu_init(struct cpu_info *); +void cpu_init_first(void); + +#endif \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/db_machdep.h b/lib/libc/include/x86-openbsd-none/i386/db_machdep.h new file mode 100644 index 0000000000..720fb23437 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/db_machdep.h @@ -0,0 +1,94 @@ +/* $OpenBSD: db_machdep.h,v 1.30 2021/08/30 08:11:12 jasper Exp $ */ +/* $NetBSD: db_machdep.h,v 1.9 1996/05/03 19:23:59 christos Exp $ */ + +/* + * Mach Operating System + * Copyright (c) 1991,1990 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +#ifndef _MACHINE_DB_MACHDEP_H_ +#define _MACHINE_DB_MACHDEP_H_ + +/* + * Machine-dependent defines for new kernel debugger. + */ + +#include +#include +#include + +typedef long db_expr_t; /* expression - signed */ + +typedef struct trapframe db_regs_t; +extern db_regs_t ddb_regs; /* register state */ + +#define PC_REGS(regs) ((vaddr_t)(regs)->tf_eip) +#define SET_PC_REGS(regs, value) (regs)->tf_eip = (int)(value) + +#define BKPT_INST 0xcc /* breakpoint instruction */ +#define BKPT_SIZE (1) /* size of breakpoint inst */ +#define BKPT_SET(inst) (BKPT_INST) + +#define SSF_INST 0x55 +#define SSF_SIZE (1) + +#define FIXUP_PC_AFTER_BREAK(regs) ((regs)->tf_eip -= BKPT_SIZE) + +#define db_clear_single_step(regs) ((regs)->tf_eflags &= ~PSL_T) +#define db_set_single_step(regs) ((regs)->tf_eflags |= PSL_T) + +#define IS_BREAKPOINT_TRAP(type, code) ((type) == T_BPTFLT) +#define IS_WATCHPOINT_TRAP(type, code) ((type) == T_TRCTRAP && (code) & 15) + +#define I_CALL 0xe8 +#define I_CALLI 0xff +#define I_RET 0xc3 +#define I_IRET 0xcf + +#define inst_trap_return(ins) (((ins)&0xff) == I_IRET) +#define inst_return(ins) (((ins)&0xff) == I_RET) +#define inst_call(ins) (((ins)&0xff) == I_CALL || \ + (((ins)&0xff) == I_CALLI && \ + ((ins)&0x3800) == 0x1000)) + +#define DB_MACHINE_COMMANDS + +/* macro for checking if a thread has used floating-point */ + +int db_ktrap(int, int, db_regs_t *); + +void db_machine_init(void); +int db_enter_ddb(void); +void db_startcpu(int); +void db_stopcpu(int); +void i386_ipi_db(struct cpu_info *); + +extern struct db_mutex ddb_mp_mutex; + +/* For ddb_state */ +#define DDB_STATE_NOT_RUNNING 0 +#define DDB_STATE_RUNNING 1 +#define DDB_STATE_EXITING 2 + +#endif /* _MACHINE_DB_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/disklabel.h b/lib/libc/include/x86-openbsd-none/i386/disklabel.h new file mode 100644 index 0000000000..4d97c53ec2 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/disklabel.h @@ -0,0 +1,40 @@ +/* $OpenBSD: disklabel.h,v 1.35 2015/09/30 14:57:03 krw Exp $ */ + +/* + * Copyright (c) 1994 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 _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_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/elf.h b/lib/libc/include/x86-openbsd-none/i386/elf.h new file mode 100644 index 0000000000..1cd8fda26a --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/elf.h @@ -0,0 +1,7 @@ +/* $OpenBSD: elf.h,v 1.1 2024/07/14 09:48:48 jca Exp $ */ + +/* + * This file is in the public domain. + */ + +/* Nothing for now */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/endian.h b/lib/libc/include/x86-openbsd-none/i386/endian.h new file mode 100644 index 0000000000..146c79b32c --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/endian.h @@ -0,0 +1,36 @@ +/* $OpenBSD: endian.h,v 1.20 2024/05/07 14:26:48 naddy 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_ + +#define _BYTE_ORDER _LITTLE_ENDIAN + +#ifndef __FROM_SYS__ENDIAN +#include +#endif + +#endif /* _MACHINE_ENDIAN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/exec.h b/lib/libc/include/x86-openbsd-none/i386/exec.h new file mode 100644 index 0000000000..aed3f3c616 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/exec.h @@ -0,0 +1,43 @@ +/* $OpenBSD: exec.h,v 1.14 2017/02/08 05:09:25 guenther Exp $ */ +/* $NetBSD: exec.h,v 1.6 1994/10/27 04:16:05 cgd 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. 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 _MACHINE_EXEC_H_ +#define _MACHINE_EXEC_H_ + +#define __LDPGSZ 4096 + +#define ARCH_ELFSIZE 32 + +#define ELF_TARG_CLASS ELFCLASS32 +#define ELF_TARG_DATA ELFDATA2LSB +#define ELF_TARG_MACH EM_386 /* XXX - EM_486 is currently unused + by all OSs/compilers/linkers */ + +#endif /* _MACHINE_EXEC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/fenv.h b/lib/libc/include/x86-openbsd-none/i386/fenv.h new file mode 100644 index 0000000000..febe5dc296 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/fenv.h @@ -0,0 +1,115 @@ +/* $OpenBSD: fenv.h,v 1.3 2011/05/25 21:46:49 martynas Exp $ */ +/* $NetBSD: fenv.h,v 1.1.6.2 2010/10/24 22:48:02 jym Exp $ */ + +/*- + * Copyright (c) 2004-2005 David Schultz + * 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 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 AUTHOR 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 _I386_FENV_H_ +#define _I386_FENV_H_ + +/* + * Each symbol representing a floating point exception expands to an integer + * constant expression with values, such that bitwise-inclusive ORs of _all + * combinations_ of the constants result in distinct values. + * + * We use such values that allow direct bitwise operations on FPU/SSE registers. + */ +#define FE_INVALID 0x01 +#define FE_DENORMAL 0x02 +#define FE_DIVBYZERO 0x04 +#define FE_OVERFLOW 0x08 +#define FE_UNDERFLOW 0x10 +#define FE_INEXACT 0x20 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * exception constants defined above. + */ +#define FE_ALL_EXCEPT (FE_INVALID | FE_DENORMAL | FE_DIVBYZERO | \ + FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT) +#define _SSE_MASK_SHIFT 7 + +/* + * Each symbol representing the rounding direction, expands to an integer + * constant expression whose value is distinct non-negative value. + * + * We use such values that allow direct bitwise operations on FPU/SSE registers. + */ +#define FE_TONEAREST 0x000 +#define FE_DOWNWARD 0x400 +#define FE_UPWARD 0x800 +#define FE_TOWARDZERO 0xc00 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * rounding direction constants defined above. + */ +#define _X87_ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | \ + FE_TOWARDZERO) +#define _SSE_ROUND_SHIFT 3 + +/* + * fenv_t represents the entire floating-point environment. + */ +typedef struct { + struct { + unsigned int __control; /* Control word register */ + unsigned int __status; /* Status word register */ + unsigned int __tag; /* Tag word register */ + unsigned int __others[4]; /* EIP, Pointer Selector, etc */ + } __x87; + unsigned int __mxcsr; /* Control, status register */ +} fenv_t; + +/* + * The following constant represents the default floating-point environment + * (that is, the one installed at program startup) and has type pointer to + * const-qualified fenv_t. + * + * It can be used as an argument to the functions within the header + * that manage the floating-point environment, namely fesetenv() and + * feupdateenv(). + */ +__BEGIN_DECLS +extern fenv_t __fe_dfl_env; +__END_DECLS +#define FE_DFL_ENV ((const fenv_t *)&__fe_dfl_env) + +/* + * fexcept_t represents the floating-point status flags collectively, including + * any status the implementation associates with the flags. + * + * A floating-point status flag is a system variable whose value is set (but + * never cleared) when a floating-point exception is raised, which occurs as a + * side effect of exceptional floating-point arithmetic to provide auxiliary + * information. + * + * A floating-point control mode is a system variable whose value may be set by + * the user to affect the subsequent behavior of floating-point arithmetic. + */ +typedef unsigned int fexcept_t; + +#endif /* !_I386_FENV_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/frame.h b/lib/libc/include/x86-openbsd-none/i386/frame.h new file mode 100644 index 0000000000..dbdb06fd21 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/frame.h @@ -0,0 +1,173 @@ +/* $OpenBSD: frame.h,v 1.13 2018/06/15 17:58:41 bluhm Exp $ */ +/* $NetBSD: frame.h,v 1.12 1995/10/11 04:20:08 mycroft Exp $ */ + +/*- + * Copyright (c) 1995 Charles M. Hannum. All rights reserved. + * 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. + * + * @(#)frame.h 5.2 (Berkeley) 1/18/91 + */ + +#ifndef _MACHINE_FRAME_H +#define _MACHINE_FRAME_H +#include + +/* + * System stack frames. + */ + +/* + * Exception/Trap Stack Frame + */ +struct trapframe { + int tf_fs; + int tf_gs; + int tf_es; + int tf_ds; + int tf_edi; + int tf_esi; + int tf_err; /* not the hardware position */ + int tf_ebx; + int tf_edx; + int tf_ecx; + int tf_eax; + int tf_trapno; + /* below portion defined in 386 hardware */ + int tf_ebp; /* hardware puts err here, INTRENTRY() moves it up */ + int tf_eip; + int tf_cs; + int tf_eflags; + /* below used when transitting rings (e.g. user to kernel) */ + int tf_esp; + int tf_ss; + /* below used when switching out of VM86 mode */ + int tf_vm86_es; + int tf_vm86_ds; + int tf_vm86_fs; + int tf_vm86_gs; +}; + +/* + * Interrupt stack frame + */ +struct intrframe { + int if_ppl; + int if_fs; + int if_gs; + int if_es; + int if_ds; + int if_edi; + int if_esi; + int :32; /* for compat with trap frame - err */ + int if_ebx; + int if_edx; + int if_ecx; + int if_eax; + int :32; /* for compat with trap frame - trapno */ + int if_ebp; + /* below portion defined in 386 hardware */ + int if_eip; + int if_cs; + int if_eflags; + /* below only when transitting rings (e.g. user to kernel) */ + int if_esp; + int if_ss; +}; + +/* + * iret stack frame + */ +struct iretframe { + int irf_trapno; + int irf_err; + int irf_eip; + int irf_cs; + int irf_eflags; + int irf_esp; + int irf_ss; + /* below used when switching back to VM86 mode */ + int irf_vm86_es; + int irf_vm86_ds; + int irf_vm86_fs; + int irf_vm86_gs; +}; + +/* + * Trampoline stack frame + */ +struct trampframe { + int trf__deadbeef; + int trf__kern_esp; + int trf_fs; + int trf_eax; + int trf_ebp; + int trf_trapno; + int trf_err; + int trf_eip; + int trf_cs; + int trf_eflags; + int trf_esp; + int trf_ss; + /* below used when switching out of VM86 mode */ + int trf_vm86_es; + int trf_vm86_ds; + int trf_vm86_fs; + int trf_vm86_gs; +}; + +/* + * Stack frame inside cpu_switch() + */ +struct switchframe { + int sf_edi; + int sf_esi; + int sf_ebx; + int sf_eip; +}; + +struct callframe { + struct callframe *f_frame; + int f_retaddr; + int f_arg0; +}; + +/* + * Signal frame + */ +struct sigframe { + int sf_signum; + siginfo_t *sf_sip; + struct sigcontext *sf_scp; + sig_t sf_handler; + struct sigcontext sf_sc; + siginfo_t sf_si; +}; +#endif \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/gdt.h b/lib/libc/include/x86-openbsd-none/i386/gdt.h new file mode 100644 index 0000000000..d88017f3cf --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/gdt.h @@ -0,0 +1,43 @@ +/* $OpenBSD: gdt.h,v 1.18 2024/05/22 05:51:49 jsg Exp $ */ +/* $NetBSD: gdt.h,v 1.7.10.6 2002/08/19 01:22:36 sommerfeld Exp $ */ + +/*- + * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by John T. Kohl and Charles M. Hannum. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LOCORE + +struct cpu_info; +struct pcb; +struct pmap; + +void gdt_alloc_cpu(struct cpu_info *); +void gdt_init(void); +void gdt_init_cpu(struct cpu_info *); +void setgdt(int, void *, size_t, int, int, int, int); +#endif \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/hibernate.h b/lib/libc/include/x86-openbsd-none/i386/hibernate.h new file mode 100644 index 0000000000..493fa4d82c --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/hibernate.h @@ -0,0 +1,35 @@ +/* $OpenBSD: hibernate.h,v 1.10 2018/06/21 07:33:30 mlarkin Exp $ */ + +/* + * Copyright (c) 2011 Mike Larkin + * + * 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 + +/* i386 hibernate support structures and functions */ + +int get_hibernate_info_md(union hibernate_info *); +void hibernate_flush(void); +void hibernate_enter_resume_mapping(vaddr_t, paddr_t, int); +int hibernate_inflate_skip(union hibernate_info *, paddr_t); +int hibernate_suspend(void); +void hibernate_switch_stack_machdep(void); +void hibernate_resume_machdep(vaddr_t); +void hibernate_activate_resume_pt_machdep(void); +void hibernate_enable_intr_machdep(void); +void hibernate_disable_intr_machdep(void); +#ifdef MULTIPROCESSOR +void hibernate_quiesce_cpus(void); +#endif /* MULTIPROCESSOR */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/hibernate_var.h b/lib/libc/include/x86-openbsd-none/i386/hibernate_var.h new file mode 100644 index 0000000000..e37fa095ce --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/hibernate_var.h @@ -0,0 +1,53 @@ +/* $OpenBSD: hibernate_var.h,v 1.16 2025/05/21 04:05:22 mlarkin Exp $ */ + +/* + * Copyright (c) 2011 Mike Larkin + * + * 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 HIB_PD_MASK 0xffc00000 +#define PIGLET_PAGE_MASK (HIB_PD_MASK) + +#define HIBERNATE_PD_PAGE (PAGE_SIZE * 21) +#define HIBERNATE_PT_PAGE (PAGE_SIZE * 22) +/* 2 pages for stack */ +#define HIBERNATE_STACK_PAGE (PAGE_SIZE * 24) +#define HIBERNATE_INFLATE_PAGE (PAGE_SIZE * 25) +/* HIBERNATE_HIBALLOC_PAGE must be the last stolen page (see machdep.c) */ +#define HIBERNATE_HIBALLOC_PAGE (PAGE_SIZE * 26) + +/* Use 4MB hibernation chunks */ +#define HIBERNATE_CHUNK_SIZE 0x400000 + +#define HIBERNATE_CHUNK_TABLE_SIZE 0x100000 + +#define HIBERNATE_STACK_OFFSET 0x0F00 + +#define atop_4m(x) ((x) >> PDSHIFT) +#define atop_4k(x) ((x) >> PAGE_SHIFT) +#define s4pde_4m(va) ((pt_entry_t *)HIBERNATE_PD_PAGE + atop_4m(va)) +#define s4pde_4k(va) ((pt_entry_t *)HIBERNATE_PD_PAGE + atop_4k(va)) +#define s4pte_4k(va) ((pt_entry_t *)HIBERNATE_PT_PAGE + atop_4k(va)) + +/* + * Minimum amount of memory for hibernate support. This is used in early boot + * when deciding if we can preallocate the piglet. If the machine does not + * have at least HIBERNATE_MIN_MEMORY RAM, we won't support hibernate. This + * avoids late allocation issues due to fragmented memory and failure to + * hibernate. We need to be able to allocate 16MB contiguous memory, aligned + * to 2MB. + * + * The default minimum required memory is 512MB (1ULL << 29). + */ +#define HIBERNATE_MIN_MEMORY (1ULL << 29) \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/i82093reg.h b/lib/libc/include/x86-openbsd-none/i386/i82093reg.h new file mode 100644 index 0000000000..ac97c35955 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/i82093reg.h @@ -0,0 +1,118 @@ +/* $OpenBSD: i82093reg.h,v 1.6 2022/12/08 01:25:45 guenther Exp $ */ +/* $NetBSD: i82093reg.h,v 1.1.2.2 2000/02/21 18:54:07 sommerfeld Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by RedBack Networks Inc. + * + * Author: Bill Sommerfeld + * + * 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. + */ + +/* + * Typically, the first apic lives here. + */ +#define IOAPIC_BASE_DEFAULT 0xfec00000 + +/* + * Memory-space registers. + */ + +/* + * The externally visible registers are all 32 bits wide; + * store the register number of interest in IOAPIC_REG, and store/fetch + * the real value in IOAPIC_DATA. + */ +#define IOAPIC_REG 0x0000 +#define IOAPIC_DATA 0x0010 + +/* + * Internal I/O APIC registers. + */ + +#define IOAPIC_ID 0x00 + +#define IOAPIC_ID_SHIFT 24 +#define IOAPIC_ID_MASK 0x0f000000 + +/* Version, and maximum interrupt pin number. */ + +#define IOAPIC_VER 0x01 + +#define IOAPIC_VER_SHIFT 0 +#define IOAPIC_VER_MASK 0x000000ff + +#define IOAPIC_MAX_SHIFT 16 +#define IOAPIC_MAX_MASK 0x00ff0000 + +/* + * Arbitration ID. Same format as IOAPIC_ID register. + */ +#define IOAPIC_ARB 0x02 + +/* + * Redirection table registers. + */ + +#define IOAPIC_REDHI(pin) (0x11 + ((pin)<<1)) +#define IOAPIC_REDLO(pin) (0x10 + ((pin)<<1)) + +#define IOAPIC_REDHI_DEST_SHIFT 24 /* destination. */ +#define IOAPIC_REDHI_DEST_MASK 0xff000000 + +#define IOAPIC_REDLO_MASK 0x00010000 /* 0=enabled; 1=masked */ + +#define IOAPIC_REDLO_LEVEL 0x00008000 /* 0=edge, 1=level */ +#define IOAPIC_REDLO_RIRR 0x00004000 /* remote IRR; read only */ +#define IOAPIC_REDLO_ACTLO 0x00002000 /* 0=act. hi; 1=act. lo */ +#define IOAPIC_REDLO_DELSTS 0x00001000 /* 0=idle; 1=send pending */ +#define IOAPIC_REDLO_DSTMOD 0x00000800 /* 0=physical; 1=logical */ + +#define IOAPIC_REDLO_DEL_MASK 0x00000700 /* del. mode mask */ +#define IOAPIC_REDLO_DEL_SHIFT 8 + +#define IOAPIC_REDLO_DEL_FIXED 0 +#define IOAPIC_REDLO_DEL_LOPRI 1 +#define IOAPIC_REDLO_DEL_SMI 2 +#define IOAPIC_REDLO_DEL_NMI 4 +#define IOAPIC_REDLO_DEL_INIT 5 +#define IOAPIC_REDLO_DEL_EXTINT 7 + +#define IOAPIC_REDLO_VECTOR_MASK 0x000000ff /* delivery vector */ + +#define IMCR_ADDR 0x22 +#define IMCR_DATA 0x23 + +#define IMCR_REGISTER 0x70 +#define IMCR_PIC 0x00 +#define IMCR_APIC 0x01 + +#ifdef _KERNEL + +#define ioapic_asm_ack(num) \ + movl $0,local_apic + LAPIC_EOI + +#endif \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/i82093var.h b/lib/libc/include/x86-openbsd-none/i386/i82093var.h new file mode 100644 index 0000000000..a74a367ff8 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/i82093var.h @@ -0,0 +1,99 @@ +/* $OpenBSD: i82093var.h,v 1.13 2024/10/22 21:50:02 jsg Exp $ */ +/* $NetBSD: i82093var.h,v 1.1 2003/02/26 21:26:10 fvdl Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by RedBack Networks Inc. + * + * Author: Bill Sommerfeld + * + * 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_I82093VAR_H_ +#define _MACHINE_I82093VAR_H_ + +#include + +struct ioapic_pin { + struct intrhand *ip_handler; + struct ioapic_pin *ip_next; /* next pin on this vector */ + struct mp_intr_map *ip_map; + int ip_vector; /* IDT vector */ + int ip_type; + int ip_minlevel; + int ip_maxlevel; +}; + +struct ioapic_softc { + struct pic sc_pic; + struct ioapic_softc *sc_next; + int sc_apicid; + int sc_apic_vers; + int sc_apic_vecbase; /* global int base if ACPI */ + int sc_apic_sz; /* apic size*/ + int sc_flags; + paddr_t sc_pa; /* PA of ioapic */ + volatile u_int32_t *sc_reg; /* KVA of ioapic addr */ + volatile u_int32_t *sc_data; /* KVA of ioapic data */ + struct ioapic_pin *sc_pins; /* sc_apic_sz entries */ +}; + +/* + * MP: intr_handle_t is bitfielded. + * ih&0xff -> line number. + * ih&0x10000000 -> if 0, old-style isa irq; if 1, routed via ioapic. + * (ih&0xff0000)>>16 -> ioapic id. + * (ih&0x00ff00)>>8 -> ioapic line. + */ + +#define APIC_INT_VIA_APIC 0x10000000 +#define APIC_INT_VIA_MSG 0x20000000 +#define APIC_INT_APIC_MASK 0x00ff0000 +#define APIC_INT_APIC_SHIFT 16 +#define APIC_INT_PIN_MASK 0x0000ff00 +#define APIC_INT_PIN_SHIFT 8 +#define APIC_INT_LINE_MASK 0x000000ff + +#define APIC_IRQ_APIC(x) ((x & APIC_INT_APIC_MASK) >> APIC_INT_APIC_SHIFT) +#define APIC_IRQ_PIN(x) ((x & APIC_INT_PIN_MASK) >> APIC_INT_PIN_SHIFT) + +void *apic_intr_establish(int, int, int, int (*)(void *), void *, + const char *); +void apic_intr_disestablish(void *); + +void ioapic_print_redir(struct ioapic_softc *, char *, int); +struct ioapic_softc *ioapic_find(int); +struct ioapic_softc *ioapic_find_bybase(int); + +void ioapic_enable(void); + +extern int ioapic_bsp_id; +extern int nioapics; +extern struct ioapic_softc *ioapics; +extern u_int16_t ioapic_id_map; +extern u_int8_t ioapic_id_remap[]; + +#endif /* !_MACHINE_I82093VAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/i82489reg.h b/lib/libc/include/x86-openbsd-none/i386/i82489reg.h new file mode 100644 index 0000000000..bb3c256cfb --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/i82489reg.h @@ -0,0 +1,144 @@ +/* $OpenBSD: i82489reg.h,v 1.5 2019/07/26 04:35:38 kevlo Exp $ */ +/* $NetBSD: i82489reg.h,v 1.1.2.1 2000/02/20 16:30:27 sommerfeld Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Frank van der Linden. + * + * 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. + */ + + +/* + * Registers and constants for the 82489DX and Pentium (and up) integrated + * "local" APIC. + */ + +#define LAPIC_ID 0x020 /* ID. RW */ +# define LAPIC_ID_MASK 0x0f000000 +# define LAPIC_ID_SHIFT 24 + +#define LAPIC_VERS 0x030 /* Version. R */ +# define LAPIC_VERSION_MASK 0x000000ff +# define LAPIC_VERSION_LVT_MASK 0x00ff0000 +# define LAPIC_VERSION_LVT_SHIFT 16 + +#define LAPIC_TPRI 0x080 /* Task Prio. RW */ +# define LAPIC_TPRI_MASK 0x000000ff +# define LAPIC_TPRI_INT_MASK 0x000000f0 +# define LAPIC_TPRI_SUB_MASK 0x0000000f + +#define LAPIC_APRI 0x090 /* Arbitration prio R */ +# define LAPIC_APRI_MASK 0x000000ff + +#define LAPIC_PPRI 0x0a0 /* Processor prio. R */ +#define LAPIC_EOI 0x0b0 /* End Int. W */ +#define LAPIC_RRR 0x0c0 /* Remote read R */ +#define LAPIC_LDR 0x0d0 /* Logical dest. RW */ +#define LAPIC_DFR 0x0e0 /* Dest. format RW */ + +#define LAPIC_SVR 0x0f0 /* Spurious intvec RW */ +# define LAPIC_SVR_VECTOR_MASK 0x000000ff +# define LAPIC_SVR_VEC_FIX 0x0000000f +# define LAPIC_SVR_VEC_PROG 0x000000f0 +# define LAPIC_SVR_ENABLE 0x00000100 +# define LAPIC_SVR_SWEN 0x00000100 +# define LAPIC_SVR_FOCUS 0x00000200 +# define LAPIC_SVR_FDIS 0x00000200 + +#define LAPIC_ISR 0x100 /* Int. status. R */ +#define LAPIC_TMR 0x180 +#define LAPIC_IRR 0x200 +#define LAPIC_ESR 0x280 /* Err status. R */ + +#define LAPIC_ICRLO 0x300 /* Int. cmd. RW */ +# define LAPIC_DLMODE_MASK 0x00000700 +# define LAPIC_DLMODE_FIXED 0x00000000 +# define LAPIC_DLMODE_LOW 0x00000100 +# define LAPIC_DLMODE_SMI 0x00000200 +# define LAPIC_DLMODE_RR 0x00000300 +# define LAPIC_DLMODE_NMI 0x00000400 +# define LAPIC_DLMODE_INIT 0x00000500 +# define LAPIC_DLMODE_STARTUP 0x00000600 + +# define LAPIC_DSTMODE_LOG 0x00000800 + +# define LAPIC_DLSTAT_BUSY 0x00001000 + +# define LAPIC_LVL_ASSERT 0x00004000 +# define LAPIC_LVL_DEASSERT 0x00000000 + +# define LAPIC_LVL_TRIG 0x00008000 + +# define LAPIC_RRSTAT_MASK 0x00030000 +# define LAPIC_RRSTAT_INPROG 0x00010000 +# define LAPIC_RRSTAT_VALID 0x00020000 + +# define LAPIC_DEST_MASK 0x000c0000 +# define LAPIC_DEST_SELF 0x00040000 +# define LAPIC_DEST_ALLINCL 0x00080000 +# define LAPIC_DEST_ALLEXCL 0x000c0000 + +# define LAPIC_RESV2_MASK 0xfff00000 + + +#define LAPIC_ICRHI 0x310 /* Int. cmd. RW */ + +#define LAPIC_LVTT 0x320 /* Loc.vec.(timer) RW */ +# define LAPIC_LVTT_VEC_MASK 0x000000ff +# define LAPIC_LVTT_DS 0x00001000 +# define LAPIC_LVTT_M 0x00010000 +# define LAPIC_LVTT_TM 0x00020000 +# define LAPIC_LVTT_TM_ONESHOT 0x00000000 +# define LAPIC_LVTT_TM_PERIODIC 0x00020000 +# define LAPIC_LVTT_TM_TSCDL 0x00040000 + +#define LAPIC_PCINT 0x340 +#define LAPIC_LVINT0 0x350 /* Loc.vec (LINT0) RW */ +# define LAPIC_LVT_PERIODIC 0x00020000 +# define LAPIC_LVT_MASKED 0x00010000 +# define LAPIC_LVT_LEVTRIG 0x00008000 +# define LAPIC_LVT_REMOTE_IRR 0x00004000 +# define LAPIC_INP_POL 0x00002000 +# define LAPIC_PEND_SEND 0x00001000 + +#define LAPIC_LVINT1 0x360 /* Loc.vec (LINT1) RW */ +#define LAPIC_LVERR 0x370 /* Loc.vec (ERROR) RW */ +#define LAPIC_ICR_TIMER 0x380 /* Initial count RW */ +#define LAPIC_CCR_TIMER 0x390 /* Current count RO */ + +#define LAPIC_DCR_TIMER 0x3e0 /* Divisor config register */ +# define LAPIC_DCRT_DIV1 0x0b +# define LAPIC_DCRT_DIV2 0x00 +# define LAPIC_DCRT_DIV4 0x01 +# define LAPIC_DCRT_DIV8 0x02 +# define LAPIC_DCRT_DIV16 0x03 +# define LAPIC_DCRT_DIV32 0x08 +# define LAPIC_DCRT_DIV64 0x09 +# define LAPIC_DCRT_DIV128 0x0a + +#define LAPIC_BASE 0xfee00000 + +#define LAPIC_IRQ_MASK(i) (1 << ((i) + 1)) \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/i82489var.h b/lib/libc/include/x86-openbsd-none/i386/i82489var.h new file mode 100644 index 0000000000..bfdf681171 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/i82489var.h @@ -0,0 +1,128 @@ +/* $OpenBSD: i82489var.h,v 1.16 2024/07/07 03:03:09 jsg Exp $ */ +/* $NetBSD: i82489var.h,v 1.1.2.2 2000/02/21 18:46:14 sommerfeld Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Frank van der Linden. + * + * 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_I82489VAR_H_ +#define _MACHINE_I82489VAR_H_ + +static __inline__ u_int32_t i82489_readreg(int); +static __inline__ void i82489_writereg(int, u_int32_t); + +#ifdef _KERNEL +extern volatile u_int32_t local_apic[]; +#endif + +static __inline__ u_int32_t +i82489_readreg(int reg) +{ + return *((volatile u_int32_t *)(((volatile u_int8_t *)local_apic) + + reg)); +} + +static __inline__ void +i82489_writereg(int reg, u_int32_t val) +{ + *((volatile u_int32_t *)(((volatile u_int8_t *)local_apic) + reg)) = + val; + /* + * intel xeon errata p53: + * write to a lapic register sometimes may appear to have not occurred + * workaround: + * follow write with a read [from id register] + */ + val = *((volatile u_int32_t *)(((volatile u_int8_t *)local_apic) + + LAPIC_ID)); +} + +/* + * "spurious interrupt vector"; vector used by interrupt which was + * aborted because the CPU masked it after it happened but before it + * was delivered.. "Oh, sorry, i caught you at a bad time". + * Low-order 4 bits must be all ones. + */ +extern void Xintrspurious(void); +#define LAPIC_SPURIOUS_VECTOR 0xef + +/* + * Vector used for inter-processor interrupts. + */ +extern void Xintripi(void); +#define LAPIC_IPI_VECTOR IPL_IPI + +/* + * Vector used for local apic timer interrupts. + */ + +extern void Xintrltimer(void); +#define LAPIC_TIMER_VECTOR IPL_CLOCK + +/* + * Vectors to be used for self-soft-interrupts. + */ + +#define LAPIC_SOFTCLOCK_VECTOR IPL_SOFTCLOCK +#define LAPIC_SOFTNET_VECTOR IPL_SOFTNET +#define LAPIC_SOFTTTY_VECTOR IPL_SOFTTTY + +/* + * Special IPI vectors. We can use IDT 0xf0 - 0xff for this. + */ +#define LAPIC_IPI_OFFSET 0xf0 +#define LAPIC_IPI_INVLTLB (LAPIC_IPI_OFFSET + 0) +#define LAPIC_IPI_INVLPG (LAPIC_IPI_OFFSET + 1) +#define LAPIC_IPI_INVLRANGE (LAPIC_IPI_OFFSET + 2) +#define LAPIC_IPI_RELOADCR3 (LAPIC_IPI_OFFSET + 3) + +extern void Xintripi_invltlb(void); +extern void Xintripi_invlpg(void); +extern void Xintripi_invlrange(void); +extern void Xintripi_reloadcr3(void); + +extern void Xintrsoftclock(void); +extern void Xintrsoftnet(void); +extern void Xintrsofttty(void); + +extern void (*apichandler[])(void); + +struct cpu_info; + +extern void lapic_boot_init(paddr_t); +extern void lapic_startclock(void); +extern void lapic_initclocks(void); +extern void lapic_set_lvt(void); +extern void lapic_set_softvectors(void); +extern void lapic_enable(void); +extern void lapic_disable(void); +extern void lapic_calibrate_timer(struct cpu_info *); + +#define lapic_cpu_number() (i82489_readreg(LAPIC_ID)>>LAPIC_ID_SHIFT) + +#endif \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/i8259.h b/lib/libc/include/x86-openbsd-none/i386/i8259.h new file mode 100644 index 0000000000..724ae4f4f1 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/i8259.h @@ -0,0 +1,144 @@ +/* $OpenBSD: i8259.h,v 1.7 2015/09/02 13:39:23 mikeb Exp $ */ +/* $NetBSD: i8259.h,v 1.3 2003/05/04 22:01:56 fvdl 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. + * + * @(#)icu.h 5.6 (Berkeley) 5/9/91 + */ + +#ifndef _MACHINE_I8259_H_ +#define _MACHINE_I8259_H_ + +#include + +#ifndef _LOCORE + +/* + * Interrupt "level" mechanism variables, masks, and macros + */ +extern unsigned imen; /* interrupt mask enable */ + +#define SET_ICUS() (outb(IO_ICU1 + 1, imen), outb(IO_ICU2 + 1, imen >> 8)) + +#endif /* !_LOCORE */ + +/* + * Interrupt enable bits -- in order of priority + */ +#define IRQ_SLAVE 2 + +/* + * Interrupt Control offset into Interrupt descriptor table (IDT) + */ +#define ICU_OFFSET 32 /* 0-31 are processor exceptions */ +#define ICU_LEN 16 /* 32-47 are ISA interrupts */ + + +#define ICU_HARDWARE_MASK + +/* + * These macros are fairly self explanatory. If ICU_SPECIAL_MASK_MODE is + * defined, we try to take advantage of the ICU's `special mask mode' by only + * EOIing the interrupts on return. This avoids the requirement of masking and + * unmasking. We can't do this without special mask mode, because the ICU + * would also hold interrupts that it thinks are of lower priority. + * + * Many machines do not support special mask mode, so by default we don't try + * to use it. + */ + +#define IRQ_BIT(num) (1 << ((num) % 8)) +#define IRQ_BYTE(num) ((num) >> 3) + +#define i8259_late_ack(num) + +#ifdef ICU_SPECIAL_MASK_MODE + +#define i8259_asm_ack1(num) +#define i8259_asm_ack2(num) \ + movb $(0x60|IRQ_SLAVE),%al /* specific EOI for IRQ2 */ ;\ + outb %al,$IO_ICU1 +#define i8259_asm_mask(num) +#define i8259_asm_unmask(num) \ + movb $(0x60|(num%8)),%al /* specific EOI */ ;\ + outb %al,$ICUADDR + +#else /* ICU_SPECIAL_MASK_MODE */ + +#ifndef AUTO_EOI_1 +#define i8259_asm_ack1(num) \ + movb $(0x60|(num%8)),%al /* specific EOI */ ;\ + outb %al,$IO_ICU1 +#else +#define i8259_asm_ack1(num) +#endif + +#ifndef AUTO_EOI_2 +#define i8259_asm_ack2(num) \ + movb $(0x60|(num%8)),%al /* specific EOI */ ;\ + outb %al,$IO_ICU2 /* do the second ICU first */ ;\ + movb $(0x60|IRQ_SLAVE),%al /* specific EOI for IRQ2 */ ;\ + outb %al,$IO_ICU1 +#else +#define i8259_asm_ack2(num) +#endif + +#ifdef ICU_HARDWARE_MASK + +#define i8259_asm_mask(num) \ + movb CVAROFF(imen, IRQ_BYTE(num)),%al ;\ + orb $IRQ_BIT(num),%al ;\ + movb %al,CVAROFF(imen, IRQ_BYTE(num)) ;\ + pushl %eax ;\ + inb $0x84,%al ;\ + popl %eax ;\ + outb %al,$(ICUADDR+1) +#define i8259_asm_unmask(num) \ + cli ;\ + movb CVAROFF(imen, IRQ_BYTE(num)),%al ;\ + andb $~IRQ_BIT(num),%al ;\ + movb %al,CVAROFF(imen, IRQ_BYTE(num)) ;\ + pushl %eax ;\ + inb $0x84,%al ;\ + popl %eax ;\ + outb %al,$(ICUADDR+1) ;\ + sti + +#else /* ICU_HARDWARE_MASK */ + +#define i8259_asm_mask(num) +#define i8259_asm_unmask(num) + +#endif /* ICU_HARDWARE_MASK */ +#endif /* ICU_SPECIAL_MASK_MODE */ + +#endif /* !_MACHINE_I8259_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/ieee.h b/lib/libc/include/x86-openbsd-none/i386/ieee.h new file mode 100644 index 0000000000..cc799d2c27 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/ieee.h @@ -0,0 +1,141 @@ +/* $OpenBSD: ieee.h,v 1.3 2008/09/07 20:36:06 martynas Exp $ */ +/* $NetBSD: ieee.h,v 1.1 1996/09/30 16:34:25 ws Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)ieee.h 8.1 (Berkeley) 6/11/93 + */ + +/* + * ieee.h defines the machine-dependent layout of the machine's IEEE + * floating point. It does *not* define (yet?) any of the rounding + * mode bits, exceptions, and so forth. + */ + +/* + * Define the number of bits in each fraction and exponent. + * + * k k+1 + * Note that 1.0 x 2 == 0.1 x 2 and that denorms are represented + * + * (-exp_bias+1) + * as fractions that look like 0.fffff x 2 . This means that + * + * -126 + * the number 0.10000 x 2 , for instance, is the same as the normalized + * + * -127 -128 + * float 1.0 x 2 . Thus, to represent 2 , we need one leading zero + * + * -129 + * in the fraction; to represent 2 , we need two, and so on. This + * + * (-exp_bias-fracbits+1) + * implies that the smallest denormalized number is 2 + * + * for whichever format we are talking about: for single precision, for + * + * -126 -149 + * instance, we get .00000000000000000000001 x 2 , or 1.0 x 2 , and + * + * -149 == -127 - 23 + 1. + */ +#define SNG_EXPBITS 8 +#define SNG_FRACBITS 23 + +#define DBL_EXPBITS 11 +#define DBL_FRACHBITS 20 +#define DBL_FRACLBITS 32 +#define DBL_FRACBITS 52 + +#define EXT_EXPBITS 15 +#define EXT_FRACHBITS 32 +#define EXT_FRACLBITS 32 +#define EXT_FRACBITS 64 + +#define EXT_TO_ARRAY32(p, a) do { \ + (a)[0] = (uint32_t)(p)->ext_fracl; \ + (a)[1] = (uint32_t)(p)->ext_frach; \ +} while(0) + +struct ieee_single { + u_int sng_frac:23; + u_int sng_exp:8; + u_int sng_sign:1; +}; + +struct ieee_double { + u_int dbl_fracl; + u_int dbl_frach:20; + u_int dbl_exp:11; + u_int dbl_sign:1; +}; + +struct ieee_ext { + u_int ext_fracl; + u_int ext_frach; + u_int ext_exp:15; + u_int ext_sign:1; + u_int ext_pad:16; +}; + +/* + * Floats whose exponent is in [1..INFNAN) (of whatever type) are + * `normal'. Floats whose exponent is INFNAN are either Inf or NaN. + * Floats whose exponent is zero are either zero (iff all fraction + * bits are zero) or subnormal values. + * + * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its + * high fraction; if the bit is set, it is a `quiet NaN'. + */ +#define SNG_EXP_INFNAN 255 +#define DBL_EXP_INFNAN 2047 +#define EXT_EXP_INFNAN 32767 + +#if 0 +#define SNG_QUIETNAN (1 << 22) +#define DBL_QUIETNAN (1 << 19) +#define EXT_QUIETNAN (1 << 15) +#endif + +/* + * Exponent biases. + */ +#define SNG_EXP_BIAS 127 +#define DBL_EXP_BIAS 1023 +#define EXT_EXP_BIAS 16383 \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/ieeefp.h b/lib/libc/include/x86-openbsd-none/i386/ieeefp.h new file mode 100644 index 0000000000..9a9a90bad7 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/ieeefp.h @@ -0,0 +1,26 @@ +/* $OpenBSD: ieeefp.h,v 1.3 2011/03/23 16:54:35 pirofti Exp $ */ + +/* + * Written by J.T. Conklin, Apr 6, 1995 + * Public domain. + */ + +#ifndef _MACHINE_IEEEFP_H_ +#define _MACHINE_IEEEFP_H_ + +typedef int fp_except; +#define FP_X_INV 0x01 /* invalid operation exception */ +#define FP_X_DNML 0x02 /* denormalization exception */ +#define FP_X_DZ 0x04 /* divide-by-zero exception */ +#define FP_X_OFL 0x08 /* overflow exception */ +#define FP_X_UFL 0x10 /* underflow exception */ +#define FP_X_IMP 0x20 /* imprecise (loss of precision) */ + +typedef enum { + FP_RN=0, /* round to nearest representable number */ + FP_RM=1, /* round toward negative infinity */ + FP_RP=2, /* round toward positive infinity */ + FP_RZ=3 /* round to zero (truncate) */ +} fp_rnd; + +#endif /* _MACHINE_IEEEFP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/intr.h b/lib/libc/include/x86-openbsd-none/i386/intr.h new file mode 100644 index 0000000000..299370353b --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/intr.h @@ -0,0 +1,149 @@ +/* $OpenBSD: intr.h,v 1.51 2025/04/25 12:47:37 mvs Exp $ */ +/* $NetBSD: intr.h,v 1.5 1996/05/13 06:11:28 mycroft Exp $ */ + +/* + * Copyright (c) 1996 Charles M. Hannum. 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 Charles M. Hannum. + * 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 _MACHINE_INTR_H_ +#define _MACHINE_INTR_H_ + +#define __USE_MI_SOFTINTR + +#include +#include + +#ifndef _LOCORE +#include +#include + +extern volatile u_int32_t lapic_tpr; /* Current interrupt priority level. */ + +extern int imask[]; /* Bitmasks telling what interrupts are blocked. */ +extern int iunmask[]; /* Bitmasks telling what interrupts are accepted. */ + +#define IMASK(level) imask[IPL(level)] +#define IUNMASK(level) iunmask[IPL(level)] + +extern void Xspllower(void); + +extern int splraise(int); +extern int spllower(int); +extern void splx(int); +extern void softintr(int); + +/* + * compiler barrier: prevent reordering of instructions. + * This prevents the compiler from reordering code around + * this "instruction", acting as a sequence point for code generation. + */ + +#define __splbarrier() __asm volatile("":::"memory") + +/* SPL asserts */ +#ifdef DIAGNOSTIC +/* + * Although this function is implemented in MI code, it must be in this MD + * header because we don't want this header to include MI includes. + */ +void splassert_fail(int, int, const char *); +extern int splassert_ctl; +void splassert_check(int, const char *); +#define splassert(__wantipl) do { \ + if (splassert_ctl > 0) { \ + splassert_check(__wantipl, __func__); \ + } \ +} while (0) +#define splsoftassert(wantipl) splassert(wantipl) +#else +#define splassert(wantipl) do { /* nada */ } while (0) +#define splsoftassert(wantipl) do { /* nada */ } while (0) +#endif + +/* + * Define the splraise and splx code in macros, so that the code can be + * reused in a profiling build in a way that does not cause recursion. + */ +#define _SPLRAISE(ocpl, ncpl) \ + ocpl = lapic_tpr; \ + if (ncpl > ocpl) \ + lapic_tpr = ncpl + + +#define _SPLX(ncpl) \ + lapic_tpr = ncpl; \ + if (curcpu()->ci_ipending & IUNMASK(ncpl)) \ + Xspllower() + +/* + * Hardware interrupt masks + */ +#define splbio() splraise(IPL_BIO) +#define splnet() splraise(IPL_NET) +#define spltty() splraise(IPL_TTY) +#define splaudio() splraise(IPL_AUDIO) +#define splclock() splraise(IPL_CLOCK) +#define splstatclock() splclock() +#define splipi() splraise(IPL_IPI) + +/* + * Software interrupt masks + */ +#define splsoftclock() splraise(IPL_SOFTCLOCK) +#define splsoftnet() splraise(IPL_SOFTNET) +#define splsofttty() splraise(IPL_SOFTTTY) + +/* + * Miscellaneous + */ +#define splvm() splraise(IPL_VM) +#define splhigh() splraise(IPL_HIGH) +#define splsched() splraise(IPL_SCHED) +#define spl0() spllower(IPL_NONE) + +#include + +struct cpu_info; + +void intr_barrier(void *); +void intr_enable_wakeup(void); +void intr_disable_wakeup(void); + +#ifdef MULTIPROCESSOR +void i386_send_ipi(struct cpu_info *, int); +int i386_fast_ipi(struct cpu_info *, int); +void i386_broadcast_ipi(int); +void i386_ipi_handler(void); +void i386_setperf_ipi(struct cpu_info *); + +extern void (*ipifunc[I386_NIPI])(struct cpu_info *); +#endif + +#endif /* !_LOCORE */ + +#endif /* !_MACHINE_INTR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/intrdefs.h b/lib/libc/include/x86-openbsd-none/i386/intrdefs.h new file mode 100644 index 0000000000..dedc83ff03 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/intrdefs.h @@ -0,0 +1,126 @@ +/* $OpenBSD: intrdefs.h,v 1.20 2025/06/11 09:57:01 kettenis Exp $ */ +/* $NetBSD: intrdefs.h,v 1.2 2003/05/04 22:01:56 fvdl Exp $ */ + +#ifndef _I386_INTRDEFS_H +#define _I386_INTRDEFS_H + +/* + * Intel APICs (advanced programmable interrupt controllers) have + * bytesized priority registers where the upper nibble is the actual + * interrupt priority level (a.k.a. IPL). Interrupt vectors are + * closely tied to these levels as interrupts whose vectors' upper + * nibble is lower than or equal to the current level are blocked. + * Not all 256 possible vectors are available for interrupts in + * APIC systems, only + * + * For systems where instead the older ICU (interrupt controlling + * unit, a.k.a. PIC or 82C59) is used, the IPL is not directly useful, + * since the interrupt blocking is handled via interrupt masks instead + * of levels. However the IPL is easily used as an offset into arrays + * of masks. + */ +#define IPLSHIFT 4 /* The upper nibble of vectors is the IPL. */ +#define NIPL 16 /* Four bits of information gives as much. */ +#define IPL(level) ((level) >> IPLSHIFT) /* Extract the IPL. */ +/* XXX Maybe this IDTVECOFF definition should be elsewhere? */ +#define IDTVECOFF 0x20 /* The lower 32 IDT vectors are reserved. */ + +/* + * This macro is only defined for 0 <= x < 14, i.e. there are fourteen + * distinct priority levels available for interrupts. + */ +#define MAKEIPL(priority) (IDTVECOFF + ((priority) << IPLSHIFT)) + +/* + * Interrupt priority levels. + * + * XXX We are somewhat sloppy about what we mean by IPLs, sometimes + * XXX we refer to the eight-bit value suitable for storing into APICs' + * XXX priority registers, other times about the four-bit entity found + * XXX in the former values' upper nibble, which can be used as offsets + * XXX in various arrays of our implementation. We are hoping that + * XXX the context will provide enough information to not make this + * XXX sloppy naming a real problem. + * + * There are tty, network and disk drivers that use free() at interrupt + * time, so imp > (tty | net | bio). + * + * Since run queues may be manipulated by both the statclock and tty, + * network, and disk drivers, clock > imp. + * + * IPL_HIGH must block everything that can manipulate a run queue. + * + * XXX Ultimately we may need serial drivers to run at the absolute highest + * XXX priority to avoid overruns, then we must make serial > high. + * + * The level numbers are picked to fit into APIC vector priorities. + */ +#define IPL_NONE 0 /* nothing */ +#define IPL_SOFTCLOCK MAKEIPL(1) /* timeouts */ +#define IPL_SOFTNET MAKEIPL(2) /* protocol stacks */ +#define IPL_BIO MAKEIPL(3) /* block I/O */ +#define IPL_NET MAKEIPL(4) /* network */ +#define IPL_SOFTTTY MAKEIPL(5) /* delayed terminal handling */ +#define IPL_TTY MAKEIPL(6) /* terminal */ +#define IPL_VM MAKEIPL(7) /* memory allocation */ +#define IPL_AUDIO MAKEIPL(8) /* audio */ +#define IPL_CLOCK MAKEIPL(9) /* clock */ +#define IPL_STATCLOCK IPL_CLOCK /* statclock */ +#define IPL_SCHED IPL_CLOCK +#define IPL_HIGH MAKEIPL(10) /* everything */ +#define IPL_IPI MAKEIPL(11) /* interprocessor interrupt */ + +#define IPL_MPFLOOR IPL_TTY +#define IPL_MPSAFE 0x100 +#define IPL_WAKEUP 0 + +/* Interrupt sharing types. */ +#define IST_NONE 0 /* none */ +#define IST_PULSE 1 /* pulsed */ +#define IST_EDGE 2 /* edge-triggered */ +#define IST_LEVEL 3 /* level-triggered */ + +/* + * Local APIC masks. Must not conflict with SIR_* below, and must + * be >= NUM_LEGACY_IRQs. Note that LIR_IPI must be first. + */ +#define LIR_IPI 31 +#define LIR_TIMER 30 + +/* Soft interrupt masks. */ +#define SIR_CLOCK 29 +#define SIR_NET 28 +#define SIR_TTY 27 + + +/* + * Maximum # of interrupt sources per CPU. 32 to fit in one word. + * ioapics can theoretically produce more, but it's not likely to + * happen. For multiple ioapics, things can be routed to different + * CPUs. + */ +#define MAX_INTR_SOURCES 32 +#define NUM_LEGACY_IRQS 16 + +/* + * Low and high boundaries between which interrupt gates will + * be allocated in the IDT. + */ +#define IDT_INTR_LOW (0x20 + NUM_LEGACY_IRQS) +#define IDT_INTR_HIGH 0xef + +#define I386_IPI_HALT 0x00000001 +#define I386_IPI_NOP 0x00000002 +#define I386_IPI_FLUSH_FPU 0x00000004 +#define I386_IPI_SYNCH_FPU 0x00000008 +#define I386_IPI_MTRR 0x00000010 +#define I386_IPI_GDT 0x00000020 +#define I386_IPI_DDB 0x00000040 /* synchronize while in ddb */ +#define I386_IPI_SETPERF 0x00000080 +#define I386_IPI_WBINVD 0x00000100 + +#define I386_NIPI 9 + +#define IREENT_MAGIC 0x18041969 + +#endif /* _I386_INTRDEFS_H */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/ioctl_fd.h b/lib/libc/include/x86-openbsd-none/i386/ioctl_fd.h new file mode 100644 index 0000000000..a370bf56f6 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/ioctl_fd.h @@ -0,0 +1,131 @@ +/* $OpenBSD: ioctl_fd.h,v 1.4 2011/03/23 16:54:35 pirofti Exp $ */ +/* from: ioctl_fd.h,v 1.4 1995/06/29 03:49:32 jtk Exp */ + +/* + * Copyright (C) 1992-1994 by Joerg Wunsch, Dresden + * 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(S) ``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(S) 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: Id: ioctl_fd.h,v 1.7 1994/10/30 19:17:39 joerg Exp + */ + +#ifndef _MACHINE_IOCTL_FD_H_ +#define _MACHINE_IOCTL_FD_H_ + +#include + +#define FD_FORMAT_VERSION 110 /* used to validate before formatting */ +#define FD_MAX_NSEC 36 /* highest known number of spt - allow for */ + /* 2.88 MB drives */ + +struct fd_formb { + int format_version; /* == FD_FORMAT_VERSION */ + int cyl, head; + int transfer_rate; /* fdreg.h: FDC_???KBPS */ + + union { + struct fd_form_data { + /* + * DO NOT CHANGE THE LAYOUT OF THIS STRUCTS + * it is hardware-dependant since it exactly + * matches the byte sequence to write to FDC + * during its `format track' operation + */ + u_char secshift; /* 0 -> 128, ...; usually 2 -> 512 */ + u_char nsecs; /* must be <= FD_MAX_NSEC */ + u_char gaplen; /* GAP 3 length; usually 84 */ + u_char fillbyte; /* usually 0xf6 */ + struct fd_idfield_data { + /* + * data to write into id fields; + * for obscure formats, they mustn't match + * the real values (but mostly do) + */ + u_char cylno; /* 0 thru 79 (or 39) */ + u_char headno; /* 0, or 1 */ + u_char secno; /* starting at 1! */ + u_char secsize; /* usually 2 */ + } idfields[FD_MAX_NSEC]; /* 0 <= idx < nsecs used */ + } structured; + u_char raw[1]; /* to have continuous indexed access */ + } format_info; +}; + +/* make life easier */ +# define fd_formb_secshift format_info.structured.secshift +# define fd_formb_nsecs format_info.structured.nsecs +# define fd_formb_gaplen format_info.structured.gaplen +# define fd_formb_fillbyte format_info.structured.fillbyte +/* these data must be filled in for(i = 0; i < fd_formb_nsecs; i++) */ +# define fd_formb_cylno(i) format_info.structured.idfields[i].cylno +# define fd_formb_headno(i) format_info.structured.idfields[i].headno +# define fd_formb_secno(i) format_info.structured.idfields[i].secno +# define fd_formb_secsize(i) format_info.structured.idfields[i].secsize + +/* + * Floppies come in various flavors, e.g., 1.2MB vs 1.44MB; here is how + * we tell them apart. + */ +struct fd_type { + int sectrac; /* sectors per track */ + int heads; /* number of heads */ + int seccyl; /* sectors per cylinder */ + int secsize; /* size code for sectors */ + int datalen; /* data len when secsize = 0 */ + int steprate; /* step rate and head unload time */ + int gap1; /* gap len between sectors */ + int gap2; /* formatting gap */ + int tracks; /* total num of tracks */ + int size; /* size of disk in sectors */ + int step; /* steps per cylinder */ + int rate; /* transfer speed code */ + char *name; +}; + + +#define FD_FORM _IOW('F', 61, struct fd_formb) /* format a track */ +#define FD_GTYPE _IOR('F', 62, struct fd_type) /* get drive type */ +#define FD_STYPE _IOW('F', 63, struct fd_type) /* set drive type */ + +#define FD_GOPTS _IOR('F', 64, int) /* drive options, see below */ +#define FD_SOPTS _IOW('F', 65, int) + +#define FDOPT_NORETRY 0x0001 /* no retries on failure (cleared on close) */ + +/* + * The following definitions duplicate those in sys/i386/isa/fdreg.h + * They are here since their values are to be used in the above + * structure when formatting a floppy. For very obvious reasons, both + * definitions must match ;-) + */ +#ifndef FDC_500KBPS +#define FDC_500KBPS 0x00 /* 500KBPS MFM drive transfer rate */ +#define FDC_300KBPS 0x01 /* 300KBPS MFM drive transfer rate */ +#define FDC_250KBPS 0x02 /* 250KBPS MFM drive transfer rate */ +#define FDC_125KBPS 0x03 /* 125KBPS FM drive transfer rate */ + /* for some controllers 1MPBS instead */ +#endif /* FDC_500KBPS */ + + +#endif /* !_MACHINE_IOCTL_FD_H__ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/joystick.h b/lib/libc/include/x86-openbsd-none/i386/joystick.h new file mode 100644 index 0000000000..2d55604d07 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/joystick.h @@ -0,0 +1,23 @@ +/* $OpenBSD: joystick.h,v 1.6 2011/03/23 16:54:35 pirofti Exp $ */ +/* $NetBSD: joystick.h,v 1.1 1996/03/27 19:18:56 perry Exp $ */ + +#ifndef _MACHINE_JOYSTICK_H_ +#define _MACHINE_JOYSTICK_H_ + +#include + +struct joystick { + int x; + int y; + int b1; + int b2; +}; + +#define JOY_SETTIMEOUT _IOW('J', 1, int) /* set timeout */ +#define JOY_GETTIMEOUT _IOR('J', 2, int) /* get timeout */ +#define JOY_SET_X_OFFSET _IOW('J', 3, int) /* set offset on X-axis */ +#define JOY_SET_Y_OFFSET _IOW('J', 4, int) /* set offset on Y-axis */ +#define JOY_GET_X_OFFSET _IOR('J', 5, int) /* get offset on X-axis */ +#define JOY_GET_Y_OFFSET _IOR('J', 6, int) /* get offset on Y-axis */ + +#endif /* _MACHINE_JOYSTICK_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/kcore.h b/lib/libc/include/x86-openbsd-none/i386/kcore.h new file mode 100644 index 0000000000..24e2327051 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/kcore.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2011 Mike Larkin + * + * 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_KCORE_H_ +#define _MACHINE_KCORE_H_ + +struct dumpmem { + paddr_t start; + paddr_t end; +}; + +#endif /* _MACHINE_KCORE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/limits.h b/lib/libc/include/x86-openbsd-none/i386/limits.h new file mode 100644 index 0000000000..86b69dfadb --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/limits.h @@ -0,0 +1,53 @@ +/* $OpenBSD: limits.h,v 1.14 2015/04/30 13:42:08 millert Exp $ */ +/* $NetBSD: limits.h,v 1.11 1995/12/21 01:08:59 mycroft 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. + * + * @(#)limits.h 7.2 (Berkeley) 6/28/90 + */ + +#ifndef _MACHINE_LIMITS_H_ +#define _MACHINE_LIMITS_H_ + +#include + +#if __POSIX_VISIBLE || __XPG_VISIBLE +#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_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/loadfile_machdep.h b/lib/libc/include/x86-openbsd-none/i386/loadfile_machdep.h new file mode 100644 index 0000000000..6a9232df70 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/loadfile_machdep.h @@ -0,0 +1,55 @@ +/* $OpenBSD: loadfile_machdep.h,v 1.8 2019/04/10 04:17:35 deraadt Exp $ */ +/* $NetBSD: loadfile_machdep.h,v 1.1 1999/04/29 03:17:12 tsubai Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * 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. + */ + +#define BOOT_ELF +#define BOOT_ELF32 +#define BOOT_ELF64 + +/* Keep a default ELFSIZE */ +#define ELFSIZE 32 + +#define LOAD_KERNEL LOAD_ALL +#define COUNT_KERNEL COUNT_ALL + +#define LOADADDR(a) ((((u_long)(a)) + offset)&0xfffffff) +#define ALIGNENTRY(a) ((u_long)(a)) +#define READ(f, b, c) read((f), (void *)LOADADDR(b), (size_t)(c)) +#define BCOPY(s, d, c) memcpy((void *)LOADADDR(d), (void *)(s), (c)) +#define BZERO(d, c) memset((void *)LOADADDR(d), 0, (c)) +#define WARN(a) (void)(printf a, \ + printf((errno ? ": %s\n" : "\n"), \ + strerror(errno))) +#define PROGRESS(a) (void) printf a +#define ALLOC(a) alloc(a) +#define FREE(a, b) free(a, b) + +void run_loadfile(uint64_t *, int); \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/mpbiosreg.h b/lib/libc/include/x86-openbsd-none/i386/mpbiosreg.h new file mode 100644 index 0000000000..37b3615c41 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/mpbiosreg.h @@ -0,0 +1,155 @@ +/* $OpenBSD: mpbiosreg.h,v 1.6 2023/04/10 04:21:20 jsg Exp $ */ +/* $NetBSD: mpbiosreg.h,v 1.1.2.3 2000/02/29 13:17:51 sommerfeld Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by RedBack Networks Inc. + * + * Author: Bill Sommerfeld + * + * 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_MPBIOSREG_H_ +#define _MACHINE_MPBIOSREG_H_ + +#define BIOS_BASE (0xf0000) +#define BIOS_SIZE (0x10000) +#define BIOS_COUNT (BIOS_SIZE) + +/* + * Multiprocessor config table entry types. + */ + +#define MPS_MCT_CPU 0 +#define MPS_MCT_BUS 1 +#define MPS_MCT_IOAPIC 2 +#define MPS_MCT_IOINT 3 +#define MPS_MCT_LINT 4 + +#define MPS_MCT_NTYPES 5 + +/* + * Interrupt types + */ + +#define MPS_INTTYPE_INT 0 +#define MPS_INTTYPE_NMI 1 +#define MPS_INTTYPE_SMI 2 +#define MPS_INTTYPE_ExtINT 3 + +#define MPS_INTPO_DEF 0 +#define MPS_INTPO_ACTHI 1 +#define MPS_INTPO_ACTLO 3 +#define MPS_INTPO_SHIFT 0 +#define MPS_INTPO_MASK 3 + +#define MPS_INTTR_DEF 0 +#define MPS_INTTR_EDGE 1 +#define MPS_INTTR_LEVEL 3 +#define MPS_INTTR_SHIFT 2 +#define MPS_INTTR_MASK 3 + +#define MPS_INT(p,t) \ + ((((p) & MPS_INTPO_MASK) << MPS_INTPO_SHIFT) | \ + (((t) & MPS_INTTR_MASK) << MPS_INTTR_SHIFT)) + +/* MP Floating Pointer Structure */ +struct mpbios_fps { + u_int32_t signature; +/* string defined by the Intel MP Spec as identifying the MP table */ +#define MP_FP_SIG 0x5f504d5f /* _MP_ */ + + u_int32_t pap; + u_int8_t length; + u_int8_t spec_rev; + u_int8_t checksum; + u_int8_t mpfb1; /* system configuration */ + u_int8_t mpfb2; /* flags */ +#define MPFPS_FLAG_IMCR 0x80 /* IMCR present */ + u_int8_t mpfb3; /* unused */ + u_int8_t mpfb4; /* unused */ + u_int8_t mpfb5; /* unused */ +}; + +/* MP Configuration Table Header */ +struct mpbios_cth { + u_int32_t signature; +#define MP_CT_SIG 0x504d4350 /* PCMP */ + + u_int16_t base_len; + u_int8_t spec_rev; + u_int8_t checksum; + u_int8_t oem_id[8]; + u_int8_t product_id[12]; + u_int32_t oem_table_pointer; + u_int16_t oem_table_size; + u_int16_t entry_count; + u_int32_t apic_address; + u_int16_t ext_len; + u_int8_t ext_cksum; + u_int8_t reserved; +}; + +struct mpbios_proc { + u_int8_t type; + u_int8_t apic_id; + u_int8_t apic_version; + u_int8_t cpu_flags; +#define PROCENTRY_FLAG_EN 0x01 +#define PROCENTRY_FLAG_BP 0x02 + u_long cpu_signature; + u_long feature_flags; + u_long reserved1; + u_long reserved2; +}; + +struct mpbios_bus { + u_int8_t type; + u_int8_t bus_id; + char bus_type[6]; +}; + +struct mpbios_ioapic { + u_int8_t type; + u_int8_t apic_id; + u_int8_t apic_version; + u_int8_t apic_flags; +#define IOAPICENTRY_FLAG_EN 0x01 + void *apic_address; +}; + +struct mpbios_int { + u_int8_t type; + u_int8_t int_type; + u_int16_t int_flags; + u_int8_t src_bus_id; + u_int8_t src_bus_irq; + u_int8_t dst_apic_id; +#define MPS_ALL_APICS 0xff + u_int8_t dst_apic_int; +}; + +#endif /* !_MACHINE_MPBIOSREG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/mpbiosvar.h b/lib/libc/include/x86-openbsd-none/i386/mpbiosvar.h new file mode 100644 index 0000000000..6c0bc7a525 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/mpbiosvar.h @@ -0,0 +1,86 @@ +/* $OpenBSD: mpbiosvar.h,v 1.13 2024/10/22 21:50:02 jsg Exp $ */ +/* $NetBSD: mpbiosvar.h,v 1.1.2.3 2000/02/29 13:17:20 sommerfeld Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by RedBack Networks Inc. + * + * Author: Bill Sommerfeld + * + * 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_MPBIOSVAR_H_ +#define _MACHINE_MPBIOSVAR_H_ + +#define MP_TRAMPOLINE (16 * PAGE_SIZE) +#define MP_TRAMP_DATA (17 * PAGE_SIZE) + +#if !defined(_LOCORE) + +#include + +struct mp_bus { + char *mb_name; /* XXX bus name */ + int mb_idx; /* XXX bus index */ + void (*mb_intr_print) (int); + void (*mb_intr_cfg)(const struct mpbios_int *, u_int32_t *); + struct mp_intr_map *mb_intrs; + u_int32_t mb_data; /* random bus-specific datum. */ +}; + +struct mp_intr_map { + struct mp_intr_map *next; + struct mp_bus *bus; + int bus_pin; + struct ioapic_softc *ioapic; + int ioapic_pin; + int ioapic_ih; /* int handle, for apic_intr_est */ + int type; /* from mp spec intr record */ + int flags; /* from mp spec intr record */ + u_int32_t redir; + int cpu_id; +}; + +#if defined(_KERNEL) +extern int mp_verbose; +extern struct mp_bus *mp_busses; +extern int mp_nbusses; +extern struct mp_intr_map *mp_intrs; +extern int mp_nintrs; +extern struct mp_bus *mp_isa_bus; +extern struct mp_bus *mp_eisa_bus; + +void mpbios_scan(struct device *); +int mpbios_probe(struct device *); +int mpbios_invent(int, int, int); + +void mpbios_intr_fixup(void); +#endif + +#endif + +#endif /* !_MACHINE_MPBIOSVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/mplock.h b/lib/libc/include/x86-openbsd-none/i386/mplock.h new file mode 100644 index 0000000000..0630808c58 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/mplock.h @@ -0,0 +1,10 @@ +/* $OpenBSD: mplock.h,v 1.4 2017/10/17 14:25:35 visa Exp $ */ + +/* public domain */ + +#ifndef _MACHINE_MPLOCK_H_ +#define _MACHINE_MPLOCK_H_ + +#define __USE_MI_MPLOCK + +#endif /* !_MACHINE_MPLOCK_H */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/mutex.h b/lib/libc/include/x86-openbsd-none/i386/mutex.h new file mode 100644 index 0000000000..3aa5554e53 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/mutex.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mutex.h,v 1.13 2018/01/25 15:06:29 mpi Exp $ */ + +#define __USE_MI_MUTEX \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/npx.h b/lib/libc/include/x86-openbsd-none/i386/npx.h new file mode 100644 index 0000000000..004a44af61 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/npx.h @@ -0,0 +1,158 @@ +/* $OpenBSD: npx.h,v 1.20 2021/03/11 11:16:57 jsg Exp $ */ +/* $NetBSD: npx.h,v 1.11 1994/10/27 04:16:11 cgd 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. + * + * @(#)npx.h 5.3 (Berkeley) 1/18/91 + */ + +/* + * 287/387 NPX Coprocessor Data Structures and Constants + * W. Jolitz 1/90 + */ + +#ifndef _MACHINE_NPX_H_ +#define _MACHINE_NPX_H_ + +/* Environment information of floating point unit */ +struct env87 { + long en_cw; /* control word (16bits) */ + long en_sw; /* status word (16bits) */ + long en_tw; /* tag word (16bits) */ + long en_fip; /* floating point instruction pointer */ + u_short en_fcs; /* floating code segment selector */ + u_short en_opcode; /* opcode last executed (11 bits ) */ + long en_foo; /* floating operand offset */ + long en_fos; /* floating operand segment selector */ +}; + +#define EN_SW_IE 0x0001 /* invalid operation */ +#define EN_SW_DE 0x0002 /* denormal */ +#define EN_SW_ZE 0x0004 /* divide by zero */ +#define EN_SW_OE 0x0008 /* overflow */ +#define EN_SW_UE 0x0010 /* underflow */ +#define EN_SW_PE 0x0020 /* loss of precision */ + +/* Contents of each floating point accumulator */ +struct fpacc87 { +#ifdef dontdef /* too unportable */ + u_long fp_mantlo; /* mantissa low (31:0) */ + u_long fp_manthi; /* mantissa high (63:32) */ + int fp_exp:15; /* exponent */ + int fp_sgn:1; /* mantissa sign */ +#else + u_char fp_bytes[10]; +#endif +}; + +/* Floating point and emulator context */ +struct save87 { + struct env87 sv_env; /* floating point control/status */ + struct fpacc87 sv_ac[8]; /* accumulator contents, 0-7 */ + u_long sv_ex_sw; /* status word for last exception */ + u_long sv_ex_tw; /* tag word for last exception */ +}; + +/* Environment of FPU/MMX/SSE/SSE2. */ +struct envxmm { +/*0*/ uint16_t en_cw; /* FPU Control Word */ + uint16_t en_sw; /* FPU Status Word */ + uint8_t en_tw; /* FPU Tag Word (abridged) */ + uint8_t en_rsvd0; + uint16_t en_opcode; /* FPU Opcode */ + uint32_t en_fip; /* FPU Instruction Pointer */ + uint16_t en_fcs; /* FPU IP selector */ + uint16_t en_rsvd1; +/*16*/ uint32_t en_foo; /* FPU Data pointer */ + uint16_t en_fos; /* FPU Data pointer selector */ + uint16_t en_rsvd2; + uint32_t en_mxcsr; /* MXCSR Register State */ + uint32_t en_mxcsr_mask; /* Mask for valid MXCSR bits (may be 0) */ +}; + +/* FPU registers in the extended save format. */ +struct fpaccxmm { + uint8_t fp_bytes[10]; + uint8_t fp_rsvd[6]; +}; + +/* SSE/SSE2 registers. */ +struct xmmreg { + uint8_t sse_bytes[16]; +}; + +/* FPU/MMX/SSE/SSE2 context */ +struct savexmm { + struct envxmm sv_env; /* control/status context */ + struct fpaccxmm sv_ac[8]; /* ST/MM regs */ + struct xmmreg sv_xmmregs[8]; /* XMM regs */ + uint8_t sv_rsvd[16 * 14]; + /* 512-bytes --- end of hardware portion of save area */ + uint32_t sv_ex_sw; /* saved SW from last exception */ + uint32_t sv_ex_tw; /* saved TW from last exception */ +}; + +union savefpu { + struct save87 sv_87; + struct savexmm sv_xmm; +}; + +#define __INITIAL_NPXCW__ 0x037f + +/* + * The default MXCSR value at reset is 0x1f80, IA-32 Instruction + * Set Reference, pg. 3-369. + */ +#define __INITIAL_MXCSR__ 0x1f80 +#define __INITIAL_MXCSR_MASK__ 0xffbf + +/* + * The standard control word from finit is 0x37F, giving: + * round to nearest + * 64-bit precision + * all exceptions masked. + */ + +void process_xmm_to_s87(const struct savexmm *, struct save87 *); +void process_s87_to_xmm(const struct save87 *, struct savexmm *); + +struct cpu_info; +struct trapframe; + +extern uint32_t fpu_mxcsr_mask; + +void npxinit(struct cpu_info *); +void npxtrap(struct trapframe *); +void fpu_kernel_enter(void); +void fpu_kernel_exit(void); + +#endif /* !_MACHINE_NPX_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/param.h b/lib/libc/include/x86-openbsd-none/i386/param.h new file mode 100644 index 0000000000..8fa4384646 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/param.h @@ -0,0 +1,80 @@ +/* $OpenBSD: param.h,v 1.53 2023/12/14 13:26:49 claudio 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 +#ifdef _LOCORE +#include +#else +#include +#endif +#endif + +#define _MACHINE i386 +#define MACHINE "i386" +#define _MACHINE_ARCH i386 +#define MACHINE_ARCH "i386" +#define MID_MACHINE MID_I386 + +#define PAGE_SHIFT 12 +#define PAGE_SIZE (1 << PAGE_SHIFT) +#define PAGE_MASK (PAGE_SIZE - 1) + +#define KERNBASE 0xd0000000 + +#ifdef _KERNEL + +#define KERNTEXTOFF (KERNBASE+0x200000) /* start of kernel text */ + +#define NBPG PAGE_SIZE /* bytes/page */ +#define PGSHIFT PAGE_SHIFT /* LOG2(PAGE_SIZE) */ +#define PGOFSET PAGE_MASK /* byte offset into page */ + +#define UPAGES 3 /* 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 (32 * 1024) /* max cluster allocation */ + +#ifndef MSGBUFSIZE +#define MSGBUFSIZE (8 * PAGE_SIZE) /* default message buffer size */ +#endif + +#define __HAVE_ACPI + +#endif /* _KERNEL */ + +#endif /* _MACHINE_PARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/pcb.h b/lib/libc/include/x86-openbsd-none/i386/pcb.h new file mode 100644 index 0000000000..ae727d2d47 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/pcb.h @@ -0,0 +1,78 @@ +/* $OpenBSD: pcb.h,v 1.25 2022/02/21 14:26:19 jsg Exp $ */ +/* $NetBSD: pcb.h,v 1.21 1996/01/08 13:51:42 mycroft Exp $ */ + +/*- + * Copyright (c) 1995 Charles M. Hannum. All rights reserved. + * 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. + * + * @(#)pcb.h 5.10 (Berkeley) 5/12/91 + */ + +/* + * Intel 386 process control block + */ + +#ifndef _MACHINE_PCB_H_ +#define _MACHINE_PCB_H_ + +#include + +#include +#include +#include + +/* + * Please note that pcb_savefpu must be aligned to 16 bytes. + */ +struct pcb { + union savefpu pcb_savefpu; /* floating point state for FPU */ + int pcb_cr3; + int pcb_esp; + int pcb_ebp; + int pcb_kstack; /* kernel stack address */ + int pcb_cr0; /* saved image of CR0 */ + caddr_t pcb_onfault; /* copyin/out fault recovery */ + struct segment_descriptor pcb_threadsegs[2]; + /* per-thread descriptors */ + int vm86_eflags; /* virtual eflags for vm86 mode */ + int vm86_flagmask; /* flag mask for vm86 mode */ + void *vm86_userp; /* XXX performance hack */ + struct pmap *pcb_pmap; /* back pointer to our pmap */ + struct cpu_info *pcb_fpcpu; /* cpu holding our fpu state */ + int pcb_flags; +#define PCB_SAVECTX 0x00000001 +}; + +/* the indexes of the %fs/%gs segments in pcb_threadsegs */ +#define TSEG_FS 0 +#define TSEG_GS 1 + +#endif /* _MACHINE_PCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/pctr.h b/lib/libc/include/x86-openbsd-none/i386/pctr.h new file mode 100644 index 0000000000..91c0e3f0b0 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/pctr.h @@ -0,0 +1,93 @@ +/* $OpenBSD: pctr.h,v 1.17 2014/03/29 18:09:29 guenther Exp $ */ + +/* + * Pentium performance counter driver for OpenBSD. + * Copyright 1996 David Mazieres . + * + * Modification and redistribution in source and binary forms is + * permitted provided that due credit is given to the author and the + * OpenBSD project by leaving this copyright notice intact. + */ + +#ifndef _MACHINE_PCTR_H_ +#define _MACHINE_PCTR_H_ + +#include + +typedef u_int64_t pctrval; + +#define PCTR_NUM 4 + +struct pctrst { + u_int pctr_fn[PCTR_NUM]; /* Current settings of counters */ + pctrval pctr_tsc; /* Free-running 64-bit cycle counter */ + pctrval pctr_hwc[PCTR_NUM]; /* Values of the hardware counters */ +}; + +/* Bit values in fn fields and PIOCS ioctl's */ +#define P5CTR_K 0x40 /* Monitor kernel-level events */ +#define P5CTR_U 0x80 /* Monitor user-level events */ +#define P5CTR_C 0x100 /* count cycles rather than events */ + +#define PCTR_U 0x010000 /* Monitor user-level events */ +#define PCTR_K 0x020000 /* Monitor kernel-level events */ +#define PCTR_E 0x040000 /* Edge detect */ +#define PCTR_EN 0x400000 /* Enable counters (counter 0 only) */ +#define PCTR_I 0x800000 /* Invert counter mask */ + +/* Unit Mask bits */ +#define PCTR_UM_M 0x0800 /* Modified cache lines */ +#define PCTR_UM_E 0x0400 /* Exclusive cache lines */ +#define PCTR_UM_S 0x0200 /* Shared cache lines */ +#define PCTR_UM_I 0x0100 /* Invalid cache lines */ +#define PCTR_UM_MESI (PCTR_UM_M|PCTR_UM_E|PCTR_UM_S|PCTR_UM_I) +#define PCTR_UM_A 0x2000 /* Any initiator */ + +#define PCTR_UM_SHIFT 8 /* Left shift for unit mask */ +#define PCTR_CM_SHIFT 24 /* Left shift for counter mask */ + +/* ioctl to set which counter a device tracks */ +#define PCIOCRD _IOR('c', 1, struct pctrst) /* Read counter value */ +#define PCIOCS0 _IOW('c', 8, unsigned int) /* Set counter 0 function */ +#define PCIOCS1 _IOW('c', 9, unsigned int) /* Set counter 1 function */ +#define PCIOCS2 _IOW('c', 10, unsigned int) /* Set counter 0 function */ +#define PCIOCS3 _IOW('c', 11, unsigned int) /* Set counter 1 function */ + +#define _PATH_PCTR "/dev/pctr" + +#define rdtsc() \ +({ \ + pctrval v; \ + __asm volatile ("rdtsc" : "=A" (v)); \ + v; \ +}) + +/* Read the performance counters (Pentium Pro only) */ +#define rdpmc(ctr) \ +({ \ + pctrval v; \ + __asm volatile ("rdpmc\n" \ + "\tandl $0xff, %%edx" \ + : "=A" (v) : "c" (ctr)); \ + v; \ +}) + +#ifdef _KERNEL + +#define rdmsr(msr) \ +({ \ + pctrval v; \ + __asm volatile ("rdmsr" : "=A" (v) : "c" (msr)); \ + v; \ +}) + +#define wrmsr(msr, v) \ + __asm volatile ("wrmsr" :: "A" ((u_int64_t) (v)), "c" (msr)); + +void pctrattach(int); +int pctropen(dev_t, int, int, struct proc *); +int pctrclose(dev_t, int, int, struct proc *); +int pctrioctl(dev_t, u_long, caddr_t, int, struct proc *); + +#endif /* _KERNEL */ +#endif /* ! _MACHINE_PCTR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/pic.h b/lib/libc/include/x86-openbsd-none/i386/pic.h new file mode 100644 index 0000000000..26b88fde76 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/pic.h @@ -0,0 +1,42 @@ +/* $OpenBSD: pic.h,v 1.2 2014/12/16 21:40:05 tedu Exp $ */ +/* $NetBSD: pic.h,v 1.1 2003/02/26 21:26:11 fvdl Exp $ */ + +#ifndef _X86_PIC_H +#define _X86_PIC_H + +#include +#include + +struct cpu_info; + +/* + * Structure common to all PIC softcs + */ +struct pic { + struct device pic_dev; + int pic_type; +#ifdef MULTIPROCESSOR + struct mutex pic_mutex; +#endif + void (*pic_hwmask)(struct pic *, int); + void (*pic_hwunmask)(struct pic *, int); + void (*pic_addroute)(struct pic *, struct cpu_info *, int, int, int); + void (*pic_delroute)(struct pic *, struct cpu_info *, int, int, int); + struct intrstub *pic_level_stubs; + struct intrstub *pic_edge_stubs; +}; + +#define pic_name pic_dev.dv_xname + +/* + * PIC types. + */ +#define PIC_I8259 0 +#define PIC_IOAPIC 1 +#define PIC_LAPIC 2 +#define PIC_SOFT 3 + +extern struct pic i8259_pic; +extern struct pic local_pic; +extern struct pic softintr_pic; +#endif \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/pio.h b/lib/libc/include/x86-openbsd-none/i386/pio.h new file mode 100644 index 0000000000..6ca1c28444 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/pio.h @@ -0,0 +1,201 @@ +/* $OpenBSD: pio.h,v 1.12 2015/04/25 21:31:24 guenther Exp $ */ +/* $NetBSD: pio.h,v 1.13 1996/03/08 20:15:23 cgd Exp $ */ + +/* + * Copyright (c) 1993, 1995 Charles M. Hannum. 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 Charles M. Hannum. + * 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 _MACHINE_PIO_H_ +#define _MACHINE_PIO_H_ + +/* + * Functions to provide access to i386 programmed I/O instructions. + * + * The in[bwl]() and out[bwl]() functions are split into two varieties: one to + * use a small, constant, 8-bit port number, and another to use a large or + * variable port number. The former can be compiled as a smaller instruction. + */ + + +#ifdef __OPTIMIZE__ + +#define __use_immediate_port(port) \ + (__builtin_constant_p((port)) && (port) < 0x100) + +#else + +#define __use_immediate_port(port) 0 + +#endif + + +#define inb(port) \ + (__use_immediate_port(port) ? __inbc(port) : __inb(port)) + +static __inline u_int8_t +__inbc(int port) +{ + u_int8_t data; + __asm volatile("inb %w1,%0" : "=a" (data) : "id" (port)); + return data; +} + +static __inline u_int8_t +__inb(int port) +{ + u_int8_t data; + __asm volatile("inb %w1,%0" : "=a" (data) : "d" (port)); + return data; +} + +static __inline void +insb(int port, void *addr, int cnt) +{ + __asm volatile("repne\n\tinsb" + : "+D" (addr), "+c" (cnt) : "d" (port) : "memory", "cc"); +} + +#define inw(port) \ + (__use_immediate_port(port) ? __inwc(port) : __inw(port)) + +static __inline u_int16_t +__inwc(int port) +{ + u_int16_t data; + __asm volatile("inw %w1,%0" : "=a" (data) : "id" (port)); + return data; +} + +static __inline u_int16_t +__inw(int port) +{ + u_int16_t data; + __asm volatile("inw %w1,%0" : "=a" (data) : "d" (port)); + return data; +} + +static __inline void +insw(int port, void *addr, int cnt) +{ + __asm volatile("repne\n\tinsw" + : "+D" (addr), "+c" (cnt) : "d" (port) : "memory", "cc"); +} + +#define inl(port) \ + (__use_immediate_port(port) ? __inlc(port) : __inl(port)) + +static __inline u_int32_t +__inlc(int port) +{ + u_int32_t data; + __asm volatile("inl %w1,%0" : "=a" (data) : "id" (port)); + return data; +} + +static __inline u_int32_t +__inl(int port) +{ + u_int32_t data; + __asm volatile("inl %w1,%0" : "=a" (data) : "d" (port)); + return data; +} + +static __inline void +insl(int port, void *addr, int cnt) +{ + __asm volatile("repne\n\tinsl" + : "+D" (addr), "+c" (cnt) : "d" (port) : "memory", "cc"); +} + +#define outb(port, data) \ + (__use_immediate_port(port) ? __outbc(port, data) : __outb(port, data)) + +static __inline void +__outbc(int port, u_int8_t data) +{ + __asm volatile("outb %0,%w1" : : "a" (data), "id" (port)); +} + +static __inline void +__outb(int port, u_int8_t data) +{ + __asm volatile("outb %0,%w1" : : "a" (data), "d" (port)); +} + +static __inline void +outsb(int port, const void *addr, int cnt) +{ + __asm volatile("repne\n\toutsb" + : "+S" (addr), "+c" (cnt) : "d" (port) : "cc"); +} + +#define outw(port, data) \ + (__use_immediate_port(port) ? __outwc(port, data) : __outw(port, data)) + +static __inline void +__outwc(int port, u_int16_t data) +{ + __asm volatile("outw %0,%w1" : : "a" (data), "id" (port)); +} + +static __inline void +__outw(int port, u_int16_t data) +{ + __asm volatile("outw %0,%w1" : : "a" (data), "d" (port)); +} + +static __inline void +outsw(int port, const void *addr, int cnt) +{ + __asm volatile("repne\n\toutsw" + : "+S" (addr), "+c" (cnt) : "d" (port) : "cc"); +} + +#define outl(port, data) \ + (__use_immediate_port(port) ? __outlc(port, data) : __outl(port, data)) + +static __inline void +__outlc(int port, u_int32_t data) +{ + __asm volatile("outl %0,%w1" : : "a" (data), "id" (port)); +} + +static __inline void +__outl(int port, u_int32_t data) +{ + __asm volatile("outl %0,%w1" : : "a" (data), "d" (port)); +} + +static __inline void +outsl(int port, const void *addr, int cnt) +{ + __asm volatile("repne\n\toutsl" + : "+S" (addr), "+c" (cnt) : "d" (port) : "cc"); +} + +#endif /* _MACHINE_PIO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/pmap.h b/lib/libc/include/x86-openbsd-none/i386/pmap.h new file mode 100644 index 0000000000..0c46db395e --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/pmap.h @@ -0,0 +1,480 @@ +/* $OpenBSD: pmap.h,v 1.98 2025/07/16 07:15:42 jsg Exp $ */ +/* $NetBSD: pmap.h,v 1.44 2000/04/24 17:18:18 thorpej Exp $ */ + +/* + * Copyright (c) 1997 Charles D. Cranor and Washington University. + * 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. + */ + +/* + * pmap.h: see pmap.c for the history of this pmap module. + */ + +#ifndef _MACHINE_PMAP_H_ +#define _MACHINE_PMAP_H_ + +#ifdef _KERNEL +#include +#include +#endif +#include +#include +#include + +#define PDSLOT_PTE ((KERNBASE/NBPD)-2) /* 830: for recursive PDP map */ +#define PDSLOT_KERN (KERNBASE/NBPD) /* 832: start of kernel space */ +#define PDSLOT_APTE ((unsigned)1022) /* 1022: alternative recursive slot */ + +/* + * The following define determines how many PTPs should be set up for the + * kernel by locore.s at boot time. This should be large enough to + * get the VM system running. Once the VM system is running, the + * pmap module can add more PTPs to the kernel area on demand. + */ + +#ifndef NKPTP +#define NKPTP 8 /* 16/32MB to start */ +#endif +#define NKPTP_MIN 4 /* smallest value we allow */ + +/* + * PG_AVAIL usage: we make use of the ignored bits of the PTE + */ + +#define PG_W PG_AVAIL1 /* "wired" mapping */ +#define PG_PVLIST PG_AVAIL2 /* mapping has entry on pvlist */ +#define PG_X PG_AVAIL3 /* executable mapping */ + +#define PTP0_PA (PAGE_SIZE * 3) + +#ifdef _KERNEL +/* + * pmap data structures: see pmap.c for details of locking. + */ + +struct pmap; +typedef struct pmap *pmap_t; + +/* + * We maintain a list of all non-kernel pmaps. + */ + +LIST_HEAD(pmap_head, pmap); /* struct pmap_head: head of a pmap list */ + +/* + * The pmap structure + * + * Note that the pm_obj contains the reference count, + * page list, and number of PTPs within the pmap. + */ + +struct pmap { + uint64_t pm_pdidx[4]; /* PDIEs for PAE mode */ + uint64_t pm_pdidx_intel[4]; /* PDIEs for PAE mode U-K */ + + struct mutex pm_mtx; + struct mutex pm_apte_mtx; + + /* + * pm_pdir : VA of PD when executing in privileged mode + * (lock by object lock) + * pm_pdirpa : PA of PD when executing in privileged mode, + * (read-only after create) + * pm_pdir_intel : VA of PD when executing on Intel CPU in + * usermode (no kernel mappings) + * pm_pdirpa_intel : PA of PD when executing on Intel CPU in + * usermode (no kernel mappings) + */ + paddr_t pm_pdirpa, pm_pdirpa_intel; + vaddr_t pm_pdir, pm_pdir_intel; + int pm_pdirsize; /* PD size (4k vs 16k on PAE) */ + struct uvm_object pm_obj; /* object (lck by object lock) */ + LIST_ENTRY(pmap) pm_list; /* list (lck by pm_list lock) */ + struct vm_page *pm_ptphint; /* pointer to a PTP in our pmap */ + struct pmap_statistics pm_stats; /* pmap stats (lck by object lock) */ + + vaddr_t pm_hiexec; /* highest executable mapping */ + int pm_flags; /* see below */ + + struct segment_descriptor pm_codeseg; /* cs descriptor for process */ +}; + +/* + * For each managed physical page we maintain a list of s + * which it is mapped at. The list is headed by a pv_head structure. + * there is one pv_head per managed phys page (allocated at boot time). + * The pv_head structure points to a list of pv_entry structures (each + * describes one mapping). + */ + +struct pv_entry { /* locked by its list's pvh_lock */ + struct pv_entry *pv_next; /* next entry */ + struct pmap *pv_pmap; /* the pmap */ + vaddr_t pv_va; /* the virtual address */ + struct vm_page *pv_ptp; /* the vm_page of the PTP */ +}; +/* + * MD flags to pmap_enter: + */ + +/* to get just the pa from params to pmap_enter */ +#define PMAP_PA_MASK ~((paddr_t)PAGE_MASK) +#define PMAP_NOCACHE 0x1 /* map uncached */ +#define PMAP_WC 0x2 /* map write combining. */ + +/* + * We keep mod/ref flags in struct vm_page->pg_flags. + */ +#define PG_PMAP_MOD PG_PMAP0 +#define PG_PMAP_REF PG_PMAP1 +#define PG_PMAP_WC PG_PMAP2 + +/* + * pv_entrys are dynamically allocated in chunks from a single page. + * we keep track of how many pv_entrys are in use for each page and + * we can free pv_entry pages if needed. There is one lock for the + * entire allocation system. + */ + +struct pv_page_info { + TAILQ_ENTRY(pv_page) pvpi_list; + struct pv_entry *pvpi_pvfree; + int pvpi_nfree; +}; + +/* + * number of pv_entries in a pv_page + */ + +#define PVE_PER_PVPAGE ((PAGE_SIZE - sizeof(struct pv_page_info)) / \ + sizeof(struct pv_entry)) + +/* + * a pv_page: where pv_entrys are allocated from + */ + +struct pv_page { + struct pv_page_info pvinfo; + struct pv_entry pvents[PVE_PER_PVPAGE]; +}; + +/* + * pv_entrys are dynamically allocated in chunks from a single page. + * we keep track of how many pv_entrys are in use for each page and + * we can free pv_entry pages if needed. There is one lock for the + * entire allocation system. + */ + +extern char PTD[]; +extern struct pmap kernel_pmap_store; /* kernel pmap */ +extern int nkptp_max; + +#define PMAP_REMOVE_ALL 0 +#define PMAP_REMOVE_SKIPWIRED 1 + +extern struct pool pmap_pv_pool; + +/* + * Macros + */ + +#define pmap_kernel() (&kernel_pmap_store) +#define pmap_wired_count(pmap) ((pmap)->pm_stats.wired_count) +#define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count) +#define pmap_update(pm) /* nada */ + +#define pmap_clear_modify(pg) pmap_clear_attrs(pg, PG_M) +#define pmap_clear_reference(pg) pmap_clear_attrs(pg, PG_U) +#define pmap_is_modified(pg) pmap_test_attrs(pg, PG_M) +#define pmap_is_referenced(pg) pmap_test_attrs(pg, PG_U) +#define pmap_valid_entry(E) ((E) & PG_V) /* is PDE or PTE valid? */ + +#define pmap_proc_iflush(p,va,len) /* nothing */ +#define pmap_init_percpu() do { /* nothing */ } while (0) +#define pmap_unuse_final(p) /* nothing */ +#define pmap_remove_holes(vm) do { /* nothing */ } while (0) + +/* + * Prototypes + */ + +vaddr_t pmap_tmpmap_pa_86(paddr_t); +vaddr_t pmap_tmpmap_pa(paddr_t); +void pmap_tmpunmap_pa_86(void); +void pmap_tmpunmap_pa(void); + +void pmap_bootstrap(vaddr_t); +void pmap_bootstrap_pae(void); +void pmap_virtual_space(vaddr_t *, vaddr_t *); +void pmap_init(void); +struct pmap *pmap_create(void); +void pmap_destroy(struct pmap *); +void pmap_reference(struct pmap *); +void pmap_remove(struct pmap *, vaddr_t, vaddr_t); +void pmap_activate(struct proc *); +void pmap_deactivate(struct proc *); +void pmap_kenter_pa(vaddr_t, paddr_t, vm_prot_t); +void pmap_kremove(vaddr_t, vsize_t); +void pmap_zero_page(struct vm_page *); +void pmap_copy_page(struct vm_page *, struct vm_page *); +void pmap_enter_pv(struct vm_page *, struct pv_entry *, + struct pmap *, vaddr_t, struct vm_page *); +int pmap_clear_attrs(struct vm_page *, int); +static void pmap_page_protect(struct vm_page *, vm_prot_t); +void pmap_page_remove(struct vm_page *); +static void pmap_protect(struct pmap *, vaddr_t, + vaddr_t, vm_prot_t); +void pmap_remove(struct pmap *, vaddr_t, vaddr_t); +int pmap_test_attrs(struct vm_page *, int); +void pmap_write_protect(struct pmap *, vaddr_t, + vaddr_t, vm_prot_t); +int pmap_exec_fixup(struct vm_map *, struct trapframe *, + vaddr_t, struct pcb *); +void pmap_exec_account(struct pmap *, vaddr_t, u_int32_t, + u_int32_t); +struct pv_entry *pmap_remove_pv(struct vm_page *, struct pmap *, vaddr_t); +void pmap_apte_flush(void); +void pmap_switch(struct proc *, struct proc *); +vaddr_t reserve_dumppages(vaddr_t); /* XXX: not a pmap fn */ +paddr_t vtophys(vaddr_t va); +paddr_t vtophys_pae(vaddr_t va); + +extern u_int32_t (*pmap_pte_set_p)(vaddr_t, paddr_t, u_int32_t); +extern u_int32_t (*pmap_pte_setbits_p)(vaddr_t, u_int32_t, u_int32_t); +extern u_int32_t (*pmap_pte_bits_p)(vaddr_t); +extern paddr_t (*pmap_pte_paddr_p)(vaddr_t); +extern int (*pmap_clear_attrs_p)(struct vm_page *, int); +extern int (*pmap_enter_p)(pmap_t, vaddr_t, paddr_t, vm_prot_t, int); +extern void (*pmap_enter_special_p)(vaddr_t, paddr_t, vm_prot_t, u_int32_t); +extern int (*pmap_extract_p)(pmap_t, vaddr_t, paddr_t *); +extern vaddr_t (*pmap_growkernel_p)(vaddr_t); +extern void (*pmap_page_remove_p)(struct vm_page *); +extern void (*pmap_do_remove_p)(struct pmap *, vaddr_t, vaddr_t, int); +extern int (*pmap_test_attrs_p)(struct vm_page *, int); +extern void (*pmap_unwire_p)(struct pmap *, vaddr_t); +extern void (*pmap_write_protect_p)(struct pmap*, vaddr_t, vaddr_t, vm_prot_t); +extern void (*pmap_pinit_pd_p)(pmap_t); +extern void (*pmap_zero_phys_p)(paddr_t); +extern void (*pmap_copy_page_p)(struct vm_page *, struct vm_page *); + +u_int32_t pmap_pte_set_pae(vaddr_t, paddr_t, u_int32_t); +u_int32_t pmap_pte_setbits_pae(vaddr_t, u_int32_t, u_int32_t); +u_int32_t pmap_pte_bits_pae(vaddr_t); +paddr_t pmap_pte_paddr_pae(vaddr_t); +int pmap_clear_attrs_pae(struct vm_page *, int); +int pmap_enter_pae(pmap_t, vaddr_t, paddr_t, vm_prot_t, int); +void pmap_enter_special_pae(vaddr_t, paddr_t, vm_prot_t, u_int32_t); +int pmap_extract_pae(pmap_t, vaddr_t, paddr_t *); +vaddr_t pmap_growkernel_pae(vaddr_t); +void pmap_page_remove_pae(struct vm_page *); +void pmap_do_remove_pae(struct pmap *, vaddr_t, vaddr_t, int); +int pmap_test_attrs_pae(struct vm_page *, int); +void pmap_unwire_pae(struct pmap *, vaddr_t); +void pmap_write_protect_pae(struct pmap *, vaddr_t, vaddr_t, vm_prot_t); +void pmap_pinit_pd_pae(pmap_t); +void pmap_zero_phys_pae(paddr_t); +void pmap_copy_page_pae(struct vm_page *, struct vm_page *); + +#define pmap_pte_set (*pmap_pte_set_p) +#define pmap_pte_setbits (*pmap_pte_setbits_p) +#define pmap_pte_bits (*pmap_pte_bits_p) +#define pmap_pte_paddr (*pmap_pte_paddr_p) +#define pmap_clear_attrs (*pmap_clear_attrs_p) +#define pmap_page_remove (*pmap_page_remove_p) +#define pmap_do_remove (*pmap_do_remove_p) +#define pmap_test_attrs (*pmap_test_attrs_p) +#define pmap_unwire (*pmap_unwire_p) +#define pmap_write_protect (*pmap_write_protect_p) +#define pmap_pinit_pd (*pmap_pinit_pd_p) +#define pmap_zero_phys (*pmap_zero_phys_p) +#define pmap_copy_page (*pmap_copy_page_p) + +u_int32_t pmap_pte_set_86(vaddr_t, paddr_t, u_int32_t); +u_int32_t pmap_pte_setbits_86(vaddr_t, u_int32_t, u_int32_t); +u_int32_t pmap_pte_bits_86(vaddr_t); +paddr_t pmap_pte_paddr_86(vaddr_t); +int pmap_clear_attrs_86(struct vm_page *, int); +int pmap_enter_86(pmap_t, vaddr_t, paddr_t, vm_prot_t, int); +void pmap_enter_special_86(vaddr_t, paddr_t, vm_prot_t, u_int32_t); +int pmap_extract_86(pmap_t, vaddr_t, paddr_t *); +vaddr_t pmap_growkernel_86(vaddr_t); +void pmap_page_remove_86(struct vm_page *); +void pmap_do_remove_86(struct pmap *, vaddr_t, vaddr_t, int); +int pmap_test_attrs_86(struct vm_page *, int); +void pmap_unwire_86(struct pmap *, vaddr_t); +void pmap_write_protect_86(struct pmap *, vaddr_t, vaddr_t, vm_prot_t); +void pmap_pinit_pd_86(pmap_t); +void pmap_zero_phys_86(paddr_t); +void pmap_copy_page_86(struct vm_page *, struct vm_page *); +void pmap_tlb_shootpage(struct pmap *, vaddr_t); +void pmap_tlb_shootrange(struct pmap *, vaddr_t, vaddr_t); +void pmap_tlb_shoottlb(void); +#ifdef MULTIPROCESSOR +void pmap_tlb_droppmap(struct pmap *); +void pmap_tlb_shootwait(void); +#else +#define pmap_tlb_shootwait() +#endif + +void pmap_prealloc_lowmem_ptp(void); +void pmap_prealloc_lowmem_ptp_pae(void); +vaddr_t pmap_tmpmap_pa(paddr_t); +void pmap_tmpunmap_pa(void); +vaddr_t pmap_tmpmap_pa_pae(paddr_t); +void pmap_tmpunmap_pa_pae(void); + + +/* + * functions for flushing the cache for vaddrs and pages. + * these functions are not part of the MI pmap interface and thus + * should not be used as such. + */ +void pmap_flush_cache(vaddr_t, vsize_t); +void pmap_flush_page(paddr_t); +void pmap_flush_page_pae(paddr_t); + +#define PMAP_CHECK_COPYIN 1 + +#define PMAP_GROWKERNEL /* turn on pmap_growkernel interface */ + +/* + * Inline functions + */ + +/* + * pmap_update_pg: flush one page from the TLB (or flush the whole thing + * if hardware doesn't support one-page flushing) + */ + +#define pmap_update_pg(va) invlpg((u_int)(va)) + +/* + * pmap_update_2pg: flush two pages from the TLB + */ + +#define pmap_update_2pg(va, vb) { invlpg((u_int)(va)); invlpg((u_int)(vb)); } + +/* + * pmap_page_protect: change the protection of all recorded mappings + * of a managed page + * + * => This function is a front end for pmap_page_remove/pmap_clear_attrs + * => We only have to worry about making the page more protected. + * Unprotecting a page is done on-demand at fault time. + */ + +static __inline void +pmap_page_protect(struct vm_page *pg, vm_prot_t prot) +{ + if ((prot & PROT_WRITE) == 0) { + if (prot & (PROT_READ | PROT_EXEC)) { + (void) pmap_clear_attrs(pg, PG_RW); + } else { + pmap_page_remove(pg); + } + } +} + +/* + * pmap_protect: change the protection of pages in a pmap + * + * => This function is a front end for pmap_remove/pmap_write_protect. + * => We only have to worry about making the page more protected. + * Unprotecting a page is done on-demand at fault time. + */ + +static __inline void +pmap_protect(struct pmap *pmap, vaddr_t sva, vaddr_t eva, vm_prot_t prot) +{ + if ((prot & PROT_WRITE) == 0) { + if (prot & (PROT_READ | PROT_EXEC)) { + pmap_write_protect(pmap, sva, eva, prot); + } else { + pmap_remove(pmap, sva, eva); + } + } +} + +/* + * pmap_growkernel, pmap_enter, and pmap_extract get picked up in various + * modules from both uvm_pmap.h and pmap.h. Since uvm_pmap.h defines these + * as functions, inline them here to suppress linker warnings. + */ +static __inline vaddr_t +pmap_growkernel(vaddr_t maxkvaddr) +{ + return (*pmap_growkernel_p)(maxkvaddr); +} + +static __inline int +pmap_enter(struct pmap *pmap, vaddr_t va, paddr_t pa, vm_prot_t prot, int flags) +{ + return (*pmap_enter_p)(pmap, va, pa, prot, flags); +} + +static __inline void +pmap_enter_special(vaddr_t va, paddr_t pa, vm_prot_t prot, u_int32_t flags) +{ + (*pmap_enter_special_p)(va, pa, prot, flags); +} + +static __inline int +pmap_extract(struct pmap *pmap, vaddr_t va, paddr_t *pa) +{ + return (*pmap_extract_p)(pmap, va, pa); +} + +/* + * p m a p i n l i n e h e l p e r f u n c t i o n s + */ + +/* + * pmap_is_active: is this pmap loaded into the specified processor's %cr3? + */ + +static __inline int +pmap_is_active(struct pmap *pmap, struct cpu_info *ci) +{ + return (pmap == pmap_kernel() || ci->ci_curpmap == pmap); +} + +static __inline int +pmap_is_curpmap(struct pmap *pmap) +{ + return (pmap_is_active(pmap, curcpu())); +} + +#endif /* _KERNEL */ + +struct pv_entry; +struct vm_page_md { + struct mutex pv_mtx; + struct pv_entry *pv_list; +}; + +#define VM_MDPAGE_INIT(pg) do { \ + mtx_init(&(pg)->mdpage.pv_mtx, IPL_VM); \ + (pg)->mdpage.pv_list = NULL; \ +} while (0) + +#endif /* _MACHINE_PMAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/proc.h b/lib/libc/include/x86-openbsd-none/i386/proc.h new file mode 100644 index 0000000000..aa4ac664f9 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/proc.h @@ -0,0 +1,45 @@ +/* $OpenBSD: proc.h,v 1.10 2018/03/31 13:45:03 bluhm Exp $ */ +/* $NetBSD: proc.h,v 1.10 1995/08/06 05:33:23 mycroft 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 + */ + +/* + * Machine-dependent part of the proc structure for i386. + */ +struct mdproc { + struct trapframe *md_regs; /* registers on current frame */ + int md_flags; /* machine-dependent flags */ + int md_astpending; +}; + +/* md_flags */ +#define MDP_USEDFPU 0x0001 /* has used the FPU */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/profile.h b/lib/libc/include/x86-openbsd-none/i386/profile.h new file mode 100644 index 0000000000..b6762e06da --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/profile.h @@ -0,0 +1,76 @@ +/* $OpenBSD: profile.h,v 1.12 2014/03/29 18:09:29 guenther Exp $ */ +/* $NetBSD: profile.h,v 1.6 1995/03/28 18:17:08 jtc Exp $ */ + +/* + * Copyright (c) 1992, 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. + * + * @(#)profile.h 8.1 (Berkeley) 6/11/93 + */ + +#define _MCOUNT_DECL static __inline void _mcount + +#define MCOUNT \ +extern void mcount(void) __asm("__mcount"); \ +__weak_alias(mcount,__mcount); \ +void \ +mcount(void) \ +{ \ + int selfpc, frompcindex; \ + int eax, ecx, edx; \ + \ + __asm volatile("movl %%eax,%0" : "=g" (eax)); \ + __asm volatile("movl %%ecx,%0" : "=g" (ecx)); \ + __asm volatile("movl %%edx,%0" : "=g" (edx)); \ + /* \ + * find the return address for mcount, \ + * and the return address for mcount's caller. \ + * \ + * selfpc = pc pushed by mcount call \ + */ \ + __asm volatile ("movl 4(%%ebp),%0" : "=r" (selfpc)); \ + /* \ + * frompcindex = pc pushed by call into self. \ + */ \ + __asm volatile ("movl (%%ebp),%0;movl 4(%0),%0" : \ + "+r" (frompcindex)); \ + _mcount(frompcindex, selfpc); \ + \ + __asm volatile("movl %0,%%edx" : : "g" (edx)); \ + __asm volatile("movl %0,%%ecx" : : "g" (ecx)); \ + __asm volatile("movl %0,%%eax" : : "g" (eax)); \ +} + +#ifdef _KERNEL +/* + * We inline the code that splhigh and splx would do here as otherwise we would + * call recursively into mcount() as machdep.c is compiled with -pg on a + * profiling build. + */ +#define MCOUNT_ENTER _SPLRAISE(s, IPL_HIGH); __splbarrier() +#define MCOUNT_EXIT __splbarrier(); _SPLX(s) +#endif /* _KERNEL */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/psl.h b/lib/libc/include/x86-openbsd-none/i386/psl.h new file mode 100644 index 0000000000..f59e7e0c77 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/psl.h @@ -0,0 +1,98 @@ +/* $OpenBSD: psl.h,v 1.21 2018/07/09 19:20:30 guenther Exp $ */ +/* $NetBSD: psl.h,v 1.30 1996/05/13 01:28:05 mycroft 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. + * + * @(#)psl.h 5.2 (Berkeley) 1/18/91 + */ + +#ifndef _MACHINE_PSL_H_ +#define _MACHINE_PSL_H_ + +/* + * 386 processor status longword. + */ +#define PSL_C 0x00000001 /* carry flag */ +#define PSL_PF 0x00000004 /* parity flag */ +#define PSL_AF 0x00000010 /* auxiliary carry flag */ +#define PSL_Z 0x00000040 /* zero flag */ +#define PSL_N 0x00000080 /* sign flag */ +#define PSL_T 0x00000100 /* trap flag */ +#define PSL_I 0x00000200 /* interrupt enable flag */ +#define PSL_D 0x00000400 /* direction flag */ +#define PSL_V 0x00000800 /* overflow flag */ +#define PSL_IOPL 0x00003000 /* i/o privilege level */ +#define PSL_NT 0x00004000 /* nested task */ +#define PSL_RF 0x00010000 /* resume flag */ +#define PSL_VM 0x00020000 /* virtual 8086 mode */ +#define PSL_AC 0x00040000 /* alignment check flag */ +#define PSL_VIF 0x00080000 /* virtual interrupt enable flag */ +#define PSL_VIP 0x00100000 /* virtual interrupt pending flag */ +#define PSL_ID 0x00200000 /* identification flag */ +#define PSL_XCRYPT 0x40000000 /* VIA xcrypt: operation loaded */ + +#define PSL_MBO 0x00000002 /* must be one bits */ +#define PSL_MBZ 0xffc08028 /* must be zero bits */ + +#define PSL_USERSET (PSL_MBO | PSL_I) +#define PSL_USERSTATIC (PSL_MBO | PSL_MBZ | PSL_I | PSL_IOPL | PSL_NT | PSL_VM | PSL_VIF | PSL_VIP) + +#ifdef _KERNEL +#include + +#ifndef _LOCORE + +#include + +/* + * Interrupt handler chains. isa_intr_establish() inserts a handler into + * the list. The handler is called with its (single) argument. + */ + +struct intrhand { + int (*ih_fun)(void *); + void *ih_arg; + int ih_level; + int ih_flags; + struct intrhand *ih_next; + int ih_pin; + int ih_irq; + struct evcount ih_count; + int ih_vec; +}; + +extern int intr_shared_edge; /* This system has shared edge interrupts */ + +#endif /* _LOCORE */ +#endif /* _KERNEL */ + +#endif /* !_MACHINE_PSL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/pte.h b/lib/libc/include/x86-openbsd-none/i386/pte.h new file mode 100644 index 0000000000..14a6902bf3 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/pte.h @@ -0,0 +1,92 @@ +/* $OpenBSD: pte.h,v 1.23 2019/01/18 01:34:50 pd Exp $ */ +/* $NetBSD: pte.h,v 1.11 1998/02/06 21:58:05 thorpej Exp $ */ + +/* + * Copyright (c) 1997 Charles D. Cranor and Washington University. + * 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. + */ + +/* + * pte.h rewritten by chuck based on the jolitz version, plus random + * info on the pentium and other processors found on the net. the + * goal of this rewrite is to provide enough documentation on the MMU + * hardware that the reader will be able to understand it without having + * to refer to a hardware manual. + */ + +#ifndef _MACHINE_PTE_H_ +#define _MACHINE_PTE_H_ + +/* + * now we define various for playing with virtual addresses + */ + +#define PDSHIFT 22 /* offset of PD index in VA */ +#define NBPD (1 << PDSHIFT) /* # bytes mapped by PD (4MB) */ + +/* + * here we define the bits of the PDE/PTE, as described above: + * + * XXXCDC: need to rename these (PG_u == ugly). + */ + +#define PG_V 0x00000001 /* valid entry */ +#define PG_RO 0x00000000 /* read-only page */ +#define PG_RW 0x00000002 /* read-write page */ +#define PG_u 0x00000004 /* user accessible page */ +#define PG_PROT 0x00000806 /* all protection bits */ +#define PG_WT 0x00000008 /* write through */ +#define PG_N 0x00000010 /* non-cacheable */ +#define PG_U 0x00000020 /* has been used */ +#define PG_M 0x00000040 /* has been modified */ +#define PG_PAT 0x00000080 /* PAT bit. (on pte) */ +#define PG_PS 0x00000080 /* 4MB page size (on pde) */ +#define PG_G 0x00000100 /* global, don't TLB flush */ +#define PG_AVAIL1 0x00000200 /* ignored by hardware */ +#define PG_AVAIL2 0x00000400 /* ignored by hardware */ +#define PG_AVAIL3 0x00000800 /* ignored by hardware */ +#define PG_PATLG 0x00001000 /* PAT on large pages */ + +/* Cacheability bits when we are using PAT */ +#define PG_WB (0) /* The default */ +#define PG_WC (PG_WT) /* WT and CD is WC */ +#define PG_UCMINUS (PG_N) /* UC but mtrr can override */ +#define PG_UC (PG_WT | PG_N) /* hard UC */ + +/* + * various shorthand protection codes + */ + +#define PG_KR 0x00000000 /* kernel read-only */ +#define PG_KW 0x00000002 /* kernel read-write */ + +/* + * page protection exception bits + */ + +#define PGEX_P 0x01 /* protection violation (vs. no mapping) */ +#define PGEX_W 0x02 /* exception during a write cycle */ +#define PGEX_U 0x04 /* exception while in user mode (upl) */ +#define PGEX_I 0x10 /* instruction fetch blocked by NX */ + +#endif /* _MACHINE_PTE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/ptrace.h b/lib/libc/include/x86-openbsd-none/i386/ptrace.h new file mode 100644 index 0000000000..d8efdad5a9 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/ptrace.h @@ -0,0 +1,50 @@ +/* $OpenBSD: ptrace.h,v 1.3 2005/04/03 20:21:44 kettenis Exp $ */ +/* $NetBSD: ptrace.h,v 1.6 1995/08/06 05:33:23 mycroft 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. + */ + +/* + * i386-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) +#define PT_GETXMMREGS (PT_FIRSTMACH + 5) +#define PT_SETXMMREGS (PT_FIRSTMACH + 6) + +#ifdef _KERNEL +struct xmmregs; + +int process_read_xmmregs(struct proc *, struct xmmregs *); +int process_write_xmmregs(struct proc *, const struct xmmregs *); +#endif \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/rbus_machdep.h b/lib/libc/include/x86-openbsd-none/i386/rbus_machdep.h new file mode 100644 index 0000000000..0d0d6eda30 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/rbus_machdep.h @@ -0,0 +1,48 @@ +/* $OpenBSD: rbus_machdep.h,v 1.10 2024/05/22 05:51:49 jsg Exp $ */ +/* $NetBSD: rbus_machdep.h,v 1.2 1999/10/15 06:43:05 haya Exp $ */ + +/* + * Copyright (c) 1999 + * HAYAKAWA Koichi. 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_RBUS_MACHDEP_H_ +#define _MACHINE_RBUS_MACHDEP_H_ + +struct pci_attach_args; /* XXX */ + +#define md_space_map(rbt, physaddr, size, flags, bshp) \ + _bus_space_map((rbt)->rb_bt, (physaddr), (size), (flags), (bshp)) + +#define md_space_unmap(rbt, bsh, size, adrp) \ + _bus_space_unmap((rbt)->rb_bt, (bsh), (size), (adrp)) + +rbus_tag_t rbus_pccbb_parent_io(struct device *, + struct pci_attach_args *); +rbus_tag_t rbus_pccbb_parent_mem(struct device *, + struct pci_attach_args *); + +void pccbb_attach_hook(struct device *, struct device *, + struct pci_attach_args *); + +#endif /* _MACHINE_RBUS_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/reg.h b/lib/libc/include/x86-openbsd-none/i386/reg.h new file mode 100644 index 0000000000..b25bcac885 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/reg.h @@ -0,0 +1,103 @@ +/* $OpenBSD: reg.h,v 1.7 2011/03/23 16:54:35 pirofti Exp $ */ +/* $NetBSD: reg.h,v 1.14 1995/10/11 04:20:24 mycroft 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 _MACHINE_REG_H_ +#define _MACHINE_REG_H_ + +/* + * Location of the users' stored + * registers within appropriate frame of 'trap' and 'syscall', relative to + * base of stack frame. + * Normal usage is u.u_ar0[XX] in kernel. + */ + +/* When referenced during a trap/exception, registers are at these offsets */ + +#define tES (0) +#define tDS (1) +#define tEDI (2) +#define tESI (3) +#define tEBP (4) +#define tEBX (5) +#define tEDX (6) +#define tECX (7) +#define tEAX (8) + +#define tEIP (11) +#define tCS (12) +#define tEFLAGS (13) +#define tESP (14) +#define tSS (15) + +/* + * Registers accessible to ptrace(2) syscall for debugger + * The machine-dependent code for PT_{SET,GET}REGS needs to + * use whichever order, defined above, is correct, so that it + * is all invisible to the user. + */ +struct reg { + int r_eax; + int r_ecx; + int r_edx; + int r_ebx; + int r_esp; + int r_ebp; + int r_esi; + int r_edi; + int r_eip; + int r_eflags; + int r_cs; + int r_ss; + int r_ds; + int r_es; + int r_fs; + int r_gs; +}; + +struct fpreg { + /* + * XXX + * Fill this in with real info. + */ + char __data[116]; +}; + +struct xmmregs { + char __data[512]; +}; + +#endif /* !_MACHINE_REG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/reloc.h b/lib/libc/include/x86-openbsd-none/i386/reloc.h new file mode 100644 index 0000000000..e2d976bbfd --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/reloc.h @@ -0,0 +1,52 @@ +/* $OpenBSD: reloc.h,v 1.3 2011/03/23 16:54:35 pirofti Exp $ */ + +/* + * Copyright (c) 2002,2003 Dale Rahn + * + * 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_RELOC_H_ +#define _MACHINE_RELOC_H_ +#define R_TYPE(X) __CONCAT(RELOC_,X) + + +#define RELOC_NONE 0 /* No reloc */ +#define RELOC_32 1 /* Direct 32 bit */ +#define RELOC_PC32 2 /* PC relative 32 bit */ +#define RELOC_GOT32 3 /* 32 bit GOT entry */ +#define RELOC_PLT32 4 /* 32 bit PLT address */ +#define RELOC_COPY 5 /* Copy symbol at runtime */ +#define RELOC_GLOB_DAT 6 /* Create GOT entry */ +#define RELOC_JUMP_SLOT 7 /* Create PLT entry */ +#define RELOC_RELATIVE 8 /* Adjust by program base */ +#define RELOC_GOTOFF 9 /* 32 bit offset to GOT */ +#define RELOC_GOTPC 10 /* 32 bit PC relative offset to GOT */ +#define RELOC_TLS_TPOFF 14 /* negative offset in static TLS block */ +#define RELOC_16 20 +#define RELOC_PC16 21 +#define RELOC_8 22 +#define RELOC_PC8 23 +#define RELOC_TLS_DTPMOD32 35 /* ID of module containing symbol */ +#define RELOC_TLS_DTPOFF32 36 /* Offset in TLS block */ +#define RELOC_TLS_TPOFF32 37 /* Offset in static TLS block */ + +#endif /* _MACHINE_RELOC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/segments.h b/lib/libc/include/x86-openbsd-none/i386/segments.h new file mode 100644 index 0000000000..03a4bc81be --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/segments.h @@ -0,0 +1,229 @@ +/* $OpenBSD: segments.h,v 1.28 2020/09/24 11:36:50 deraadt Exp $ */ +/* $NetBSD: segments.h,v 1.23 1996/02/01 22:31:03 mycroft Exp $ */ + +/*- + * Copyright (c) 1995 Charles M. Hannum. All rights reserved. + * Copyright (c) 1989, 1990 William F. Jolitz + * 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. + * + * @(#)segments.h 7.1 (Berkeley) 5/9/91 + */ + +/* + * 386 Segmentation Data Structures and definitions + * William F. Jolitz (william@ernie.berkeley.edu) 6/20/1989 + */ + +#ifndef _MACHINE_SEGMENTS_H_ +#define _MACHINE_SEGMENTS_H_ + +/* + * Selectors + */ + +#define ISPL(s) ((s) & SEL_RPL) /* what is the priority level of a selector */ +#define SEL_KPL 0 /* kernel privilege level */ +#define SEL_UPL 3 /* user privilege level */ +#define SEL_RPL 3 /* requester's privilege level mask */ +#define ISLDT(s) ((s) & SEL_LDT) /* is it local or global */ +#define SEL_LDT 4 /* local descriptor table */ +#define IDXSEL(s) (((s) >> 3) & 0x1fff) /* index of selector */ +#define GSEL(s,r) (((s) << 3) | r) /* a global selector */ +#define LSEL(s,r) (((s) << 3) | r | SEL_LDT) /* a local selector */ + +#define USERMODE(c, f) (ISPL(c) == SEL_UPL) +#define KERNELMODE(c, f) (ISPL(c) == SEL_KPL) + +#ifndef _LOCORE + +/* + * Memory and System segment descriptors + */ +struct segment_descriptor { + unsigned sd_lolimit:16; /* segment extent (lsb) */ + unsigned sd_lobase:24; /* segment base address (lsb) */ + unsigned sd_type:5; /* segment type */ + unsigned sd_dpl:2; /* segment descriptor priority level */ + unsigned sd_p:1; /* segment descriptor present */ + unsigned sd_hilimit:4; /* segment extent (msb) */ + unsigned sd_xx:2; /* unused */ + unsigned sd_def32:1; /* default 32 vs 16 bit size */ + unsigned sd_gran:1; /* limit granularity (byte/page) */ + unsigned sd_hibase:8; /* segment base address (msb) */ +} __packed; + +/* + * Gate descriptors (e.g. indirect descriptors) + */ +struct gate_descriptor { + unsigned gd_looffset:16; /* gate offset (lsb) */ + unsigned gd_selector:16; /* gate segment selector */ + unsigned gd_stkcpy:5; /* number of stack wds to cpy */ + unsigned gd_xx:3; /* unused */ + unsigned gd_type:5; /* segment type */ + unsigned gd_dpl:2; /* segment descriptor priority level */ + unsigned gd_p:1; /* segment descriptor present */ + unsigned gd_hioffset:16; /* gate offset (msb) */ +} __packed; + +/* + * Generic descriptor + */ +union descriptor { + struct segment_descriptor sd; + struct gate_descriptor gd; +} __packed; + +/* + * region descriptors, used to load gdt/idt tables before segments yet exist. + */ +struct region_descriptor { + unsigned rd_limit:16; /* segment extent */ + unsigned rd_base:32; /* base address */ +} __packed; + +#ifdef _KERNEL +extern union descriptor *gdt; +extern struct gate_descriptor idt_region[]; +extern struct gate_descriptor *idt; + +#define SEGDESC_LIMIT(sd) (ptoa(((sd).sd_hilimit << 16) | (sd).sd_lolimit)) + +void setgate(struct gate_descriptor *, void *, int, int, int, int); +void setregion(struct region_descriptor *, void *, size_t); +void setsegment(struct segment_descriptor *, void *, size_t, int, int, + int, int); +void initcodesegment(struct segment_descriptor *); +void unsetgate(struct gate_descriptor *); +void cpu_init_idt(void); + +int idt_vec_alloc(int, int); +void idt_vec_set(int, void (*)(void)); +void idt_vec_free(int); + +#endif /* _KERNEL */ + +#endif /* !_LOCORE */ + +/* system segments and gate types */ +#define SDT_SYSNULL 0 /* system null */ +#define SDT_SYS286TSS 1 /* system 286 TSS available */ +#define SDT_SYSLDT 2 /* system local descriptor table */ +#define SDT_SYS286BSY 3 /* system 286 TSS busy */ +#define SDT_SYS286CGT 4 /* system 286 call gate */ +#define SDT_SYSTASKGT 5 /* system task gate */ +#define SDT_SYS286IGT 6 /* system 286 interrupt gate */ +#define SDT_SYS286TGT 7 /* system 286 trap gate */ +#define SDT_SYSNULL2 8 /* system null again */ +#define SDT_SYS386TSS 9 /* system 386 TSS available */ +#define SDT_SYSNULL3 10 /* system null again */ +#define SDT_SYS386BSY 11 /* system 386 TSS busy */ +#define SDT_SYS386CGT 12 /* system 386 call gate */ +#define SDT_SYSNULL4 13 /* system null again */ +#define SDT_SYS386IGT 14 /* system 386 interrupt gate */ +#define SDT_SYS386TGT 15 /* system 386 trap gate */ + +/* memory segment types */ +#define SDT_MEMRO 16 /* memory read only */ +#define SDT_MEMROA 17 /* memory read only accessed */ +#define SDT_MEMRW 18 /* memory read write */ +#define SDT_MEMRWA 19 /* memory read write accessed */ +#define SDT_MEMROD 20 /* memory read only expand dwn limit */ +#define SDT_MEMRODA 21 /* memory read only expand dwn limit accessed */ +#define SDT_MEMRWD 22 /* memory read write expand dwn limit */ +#define SDT_MEMRWDA 23 /* memory read write expand dwn limit acessed */ +#define SDT_MEME 24 /* memory execute only */ +#define SDT_MEMEA 25 /* memory execute only accessed */ +#define SDT_MEMER 26 /* memory execute read */ +#define SDT_MEMERA 27 /* memory execute read accessed */ +#define SDT_MEMEC 28 /* memory execute only conforming */ +#define SDT_MEMEAC 29 /* memory execute only accessed conforming */ +#define SDT_MEMERC 30 /* memory execute read conforming */ +#define SDT_MEMERAC 31 /* memory execute read accessed conforming */ + +/* is memory segment descriptor pointer ? */ +#define ISMEMSDP(s) ((s->d_type) >= SDT_MEMRO && \ + (s->d_type) <= SDT_MEMERAC) + +/* is 286 gate descriptor pointer ? */ +#define IS286GDP(s) ((s->d_type) >= SDT_SYS286CGT && \ + (s->d_type) < SDT_SYS286TGT) + +/* is 386 gate descriptor pointer ? */ +#define IS386GDP(s) ((s->d_type) >= SDT_SYS386CGT && \ + (s->d_type) < SDT_SYS386TGT) + +/* is gate descriptor pointer ? */ +#define ISGDP(s) (IS286GDP(s) || IS386GDP(s)) + +/* is segment descriptor pointer ? */ +#define ISSDP(s) (ISMEMSDP(s) || !ISGDP(s)) + +/* is system segment descriptor pointer ? */ +#define ISSYSSDP(s) (!ISMEMSDP(s) && !ISGDP(s)) + +/* + * Segment Protection Exception code bits + */ +#define SEGEX_EXT 0x01 /* recursive or externally induced */ +#define SEGEX_IDT 0x02 /* interrupt descriptor table */ +#define SEGEX_TI 0x04 /* local descriptor table */ + +/* + * Entries in the Interrupt Descriptor Table (IDT) + */ +#define NIDT 256 +#define NRSVIDT 32 /* reserved entries for cpu exceptions */ + +/* + * Entries in the Global Descriptor Table (GDT) + */ +#define GNULL_SEL 0 /* Null descriptor */ +#define GCODE_SEL 1 /* Kernel code descriptor */ +#define GDATA_SEL 2 /* Kernel data descriptor */ +#define GLDT_SEL 3 /* Default LDT descriptor (UNUSED) */ +#define GCPU_SEL 4 /* per-CPU segment */ +#define GUCODE_SEL 5 /* User code descriptor (a stack short) */ +#define GUDATA_SEL 6 /* User data descriptor */ +#define GAPM32CODE_SEL 7 /* 32 bit APM code descriptor */ +#define GAPM16CODE_SEL 8 /* 16 bit APM code descriptor */ +#define GAPMDATA_SEL 9 /* APM data descriptor */ +#define GICODE_SEL 10 /* Interrupt code descriptor (same as Kernel code) */ +#define GUFS_SEL 11 /* User per-thread (%fs) descriptor */ +#define GUGS_SEL 12 /* User per-thread (%gs) descriptor */ +#define GTSS_SEL 13 /* common TSS */ +#define GNMITSS_SEL 14 /* NMI TSS */ +#define GBIOS32_SEL 15 /* spare slot for 32 bit BIOS calls */ +#define NGDT 16 + +#define GDT_SIZE (NGDT << 3) + +#endif /* _MACHINE_SEGMENTS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/setjmp.h b/lib/libc/include/x86-openbsd-none/i386/setjmp.h new file mode 100644 index 0000000000..f53a7cc525 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/setjmp.h @@ -0,0 +1,18 @@ +/* $OpenBSD: setjmp.h,v 1.4 2020/12/13 21:21:32 bluhm Exp $ */ +/* $NetBSD: setjmp.h,v 1.1 1994/12/20 10:36:43 cgd Exp $ */ + +/* + * machine/setjmp.h: machine dependent setjmp-related information. + */ + +#define _JB_EIP 0 +#define _JB_EBX 1 +#define _JB_ESP 2 +#define _JB_EBP 3 +#define _JB_ESI 4 +#define _JB_EDI 5 +#define _JB_SIGMASK 6 +#define _JB_SIGFLAG 7 +#define _JB_FCW 8 + +#define _JBLEN 10 /* size, in longs, of a jmp_buf */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/signal.h b/lib/libc/include/x86-openbsd-none/i386/signal.h new file mode 100644 index 0000000000..80c9b368f1 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/signal.h @@ -0,0 +1,88 @@ +/* $OpenBSD: signal.h,v 1.11 2016/05/10 18:39:45 deraadt Exp $ */ +/* $NetBSD: signal.h,v 1.6 1996/01/08 13:51:43 mycroft Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1989, 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. + * + * @(#)signal.h 7.16 (Berkeley) 3/17/91 + */ + +#ifndef _MACHINE_SIGNAL_H_ +#define _MACHINE_SIGNAL_H_ + +#include + +typedef int sig_atomic_t; + +#ifdef _KERNEL +#include +#endif + +#if __BSD_VISIBLE || __XPG_VISIBLE >= 420 +/* + * Information pushed on stack when a signal is delivered. + * This is used by the kernel to restore state following + * execution of the signal handler. It is also made available + * to the handler to allow it to restore state properly if + * a non-standard exit is performed. + */ +struct sigcontext { + int sc_gs; + int sc_fs; + int sc_es; + int sc_ds; + int sc_edi; + int sc_esi; + int sc_ebp; + int sc_ebx; + int sc_edx; + int sc_ecx; + int sc_eax; + /* XXX */ + int sc_eip; + int sc_cs; + int sc_eflags; + int sc_esp; + int sc_ss; + + long sc_cookie; + int sc_mask; /* signal mask to restore */ + + int sc_trapno; /* XXX should be above */ + int sc_err; + + union savefpu *sc_fpstate; +}; + +#define sc_sp sc_esp +#define sc_fp sc_ebp +#define sc_pc sc_eip +#define sc_ps sc_eflags + +#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */ +#endif /* !_MACHINE_SIGNAL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/smbiosvar.h b/lib/libc/include/x86-openbsd-none/i386/smbiosvar.h new file mode 100644 index 0000000000..34349b6ec9 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/smbiosvar.h @@ -0,0 +1,281 @@ +/* $OpenBSD: smbiosvar.h,v 1.14 2025/07/15 01:09:32 jsg Exp $ */ +/* + * Copyright (c) 2006 Gordon Willem Klok + * Copyright (c) 2005 Jordan Hargrave + * 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 AUTHORS 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 AUTHORS 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_SMBIOSVAR_ +#define _MACHINE_SMBIOSVAR_ + +#define SMBIOS_START 0xf0000 +#define SMBIOS_END 0xfffff + +#define SMBIOS_UUID_NPRESENT 0x1 +#define SMBIOS_UUID_NSET 0x2 + +/* + * Section 3.5 of "UUIDs and GUIDs" found at + * http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt + * specifies the string representation of a UUID. + */ +#define SMBIOS_UUID_REP "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" +#define SMBIOS_UUID_REPLEN 37 /* 16 zero padded values, 4 hyphens, 1 null */ + +struct smbios_entry { + uint8_t mjr; + uint8_t min; + uint8_t *addr; + uint16_t len; + uint16_t count; +}; + +struct smbhdr { + uint32_t sig; /* "_SM_" */ + uint8_t checksum; /* Entry point checksum */ + uint8_t len; /* Entry point structure length */ + uint8_t majrev; /* Specification major revision */ + uint8_t minrev; /* Specification minor revision */ + uint16_t mss; /* Maximum Structure Size */ + uint8_t epr; /* Entry Point Revision */ + uint8_t fa[5]; /* value determined by EPR */ + uint8_t sasig[5]; /* Secondary Anchor "_DMI_" */ + uint8_t sachecksum; /* Secondary Checksum */ + uint16_t size; /* Length of structure table in bytes */ + uint32_t addr; /* Structure table address */ + uint16_t count; /* Number of SMBIOS structures */ + uint8_t rev; /* BCD revision */ +} __packed; + +struct smb3hdr { + uint8_t sig[5]; /* "_SM3_" */ + uint8_t checksum; /* Entry point structure checksum */ + uint8_t len; /* Entry point length */ + uint8_t majrev; /* SMBIOS major version */ + uint8_t minrev; /* SMBIOS minor version */ + uint8_t docrev; /* SMBIOS docrev */ + uint8_t epr; /* Entry point revision */ + uint8_t reserved; /* Reserved */ + uint32_t size; /* Structure table maximum size */ + uint64_t addr; /* Structure table address */ +} __packed; + +struct smbtblhdr { + uint8_t type; + uint8_t size; + uint16_t handle; +} __packed; + +struct smbtable { + struct smbtblhdr *hdr; + void *tblhdr; + uint32_t cookie; +}; + +#define SMBIOS_TYPE_BIOS 0 +#define SMBIOS_TYPE_SYSTEM 1 +#define SMBIOS_TYPE_BASEBOARD 2 +#define SMBIOS_TYPE_ENCLOSURE 3 +#define SMBIOS_TYPE_PROCESSOR 4 +#define SMBIOS_TYPE_MEMCTRL 5 +#define SMBIOS_TYPE_MEMMOD 6 +#define SMBIOS_TYPE_CACHE 7 +#define SMBIOS_TYPE_PORT 8 +#define SMBIOS_TYPE_SLOTS 9 +#define SMBIOS_TYPE_OBD 10 +#define SMBIOS_TYPE_OEM 11 +#define SMBIOS_TYPE_SYSCONFOPT 12 +#define SMBIOS_TYPE_BIOSLANG 13 +#define SMBIOS_TYPE_GROUPASSOC 14 +#define SMBIOS_TYPE_SYSEVENTLOG 15 +#define SMBIOS_TYPE_PHYMEM 16 +#define SMBIOS_TYPE_MEMDEV 17 +#define SMBIOS_TYPE_ECCINFO32 18 +#define SMBIOS_TYPE_MEMMAPARRAYADDR 19 +#define SMBIOS_TYPE_MEMMAPDEVADDR 20 +#define SMBIOS_TYPE_INBUILTPOINT 21 +#define SMBIOS_TYPE_PORTBATT 22 +#define SMBIOS_TYPE_SYSRESET 23 +#define SMBIOS_TYPE_HWSECUIRTY 24 +#define SMBIOS_TYPE_PWRCTRL 25 +#define SMBIOS_TYPE_VOLTPROBE 26 +#define SMBIOS_TYPE_COOLING 27 +#define SMBIOS_TYPE_TEMPPROBE 28 +#define SMBIOS_TYPE_CURRENTPROBE 29 +#define SMBIOS_TYPE_OOB_REMOTEACCESS 30 +#define SMBIOS_TYPE_BIS 31 +#define SMBIOS_TYPE_SBI 32 +#define SMBIOS_TYPE_ECCINFO64 33 +#define SMBIOS_TYPE_MGMTDEV 34 +#define SMBIOS_TYPE_MGTDEVCOMP 35 +#define SMBIOS_TYPE_MGTDEVTHRESH 36 +#define SMBIOS_TYPE_MEMCHANNEL 37 +#define SMBIOS_TYPE_IPMIDEV 38 +#define SMBIOS_TYPE_SPS 39 +#define SMBIOS_TYPE_INACTIVE 126 +#define SMBIOS_TYPE_EOT 127 + +/* + * SMBIOS Structure Type 0 "BIOS Information" + * DMTF Specification DSP0134 Section: 3.3.1 p.g. 34 + */ +struct smbios_struct_bios { + uint8_t vendor; /* string */ + uint8_t version; /* string */ + uint16_t startaddr; + uint8_t release; /* string */ + uint8_t romsize; + uint64_t characteristics; + uint32_t charext; + uint8_t major_rel; + uint8_t minor_rel; + uint8_t ecf_mjr_rel; /* embedded controller firmware */ + uint8_t ecf_min_rel; /* embedded controller firmware */ +} __packed; + +/* + * SMBIOS Structure Type 1 "System Information" + * DMTF Specification DSP0134 Section 3.3.2 p.g. 35 + */ + +struct smbios_sys { +/* SMBIOS spec 2.0+ */ + uint8_t vendor; /* string */ + uint8_t product; /* string */ + uint8_t version; /* string */ + uint8_t serial; /* string */ +/* SMBIOS spec 2.1+ */ + uint8_t uuid[16]; + uint8_t wakeup; +/* SMBIOS spec 2.4+ */ + uint8_t sku; /* string */ + uint8_t family; /* string */ +} __packed; + +/* + * SMBIOS Structure Type 2 "Base Board (Module) Information" + * DMTF Specification DSP0134 Section 3.3.3 p.g. 37 + */ +struct smbios_board { + uint8_t vendor; /* string */ + uint8_t product; /* string */ + uint8_t version; /* string */ + uint8_t serial; /* string */ + uint8_t asset; /* string */ + uint8_t feature; /* feature flags */ + uint8_t location; /* location in chassis */ + uint16_t handle; /* chassis handle */ + uint8_t type; /* board type */ + uint8_t noc; /* number of contained objects */ +} __packed; + +/* + * SMBIOS Structure Type 3 "System Enclosure or Chassis" + * DMTF Specification DSP0134 + */ +struct smbios_enclosure { + /* SMBIOS spec 2.0+ */ + uint8_t vendor; /* string */ + uint8_t type; + uint8_t version; /* string */ + uint8_t serial; /* string */ + uint8_t asset_tag; /* string */ + /* SMBIOS spec 2.1+ */ + uint8_t boot_state; + uint8_t psu_state; + uint8_t thermal_state; + uint8_t security_status; + /* SMBIOS spec 2.3+ */ + uint16_t oem_defined; + uint8_t height; + uint8_t no_power_cords; + uint8_t no_contained_element; + uint8_t reclen_contained_element; + uint8_t contained_elements; + /* SMBIOS spec 2.7+ */ + uint8_t sku; /* string */ +} __packed; + +/* + * SMBIOS Structure Type 4 "processor Information" + * DMTF Specification DSP0134 v2.5 Section 3.3.5 p.g. 24 + */ +struct smbios_cpu { + uint8_t cpu_socket_designation; /* string */ + uint8_t cpu_type; + uint8_t cpu_family; + uint8_t cpu_mfg; /* string */ + uint32_t cpu_id_eax; + uint32_t cpu_id_edx; + uint8_t cpu_version; /* string */ + uint8_t cpu_voltage; + uint16_t cpu_clock; + uint16_t cpu_max_speed; + uint16_t cpu_current_speed; + uint8_t cpu_status; +#define SMBIOS_CPUST_POPULATED (1<<6) +#define SMBIOS_CPUST_STATUSMASK (0x07) + uint8_t cpu_upgrade; + uint16_t cpu_l1_handle; + uint16_t cpu_l2_handle; + uint16_t cpu_l3_handle; + uint8_t cpu_serial; /* string */ + uint8_t cpu_asset_tag; /* string */ + uint8_t cpu_part_nr; /* string */ + /* following fields were added in smbios 2.5 */ + uint8_t cpu_core_count; + uint8_t cpu_core_enabled; + uint8_t cpu_thread_count; + uint16_t cpu_characteristics; +} __packed; + +/* + * SMBIOS Structure Type 38 "IPMI Information" + * DMTF Specification DSP0134 Section 3.3.39 p.g. 91 + */ +struct smbios_ipmi { + uint8_t smipmi_if_type; /* IPMI Interface Type */ + uint8_t smipmi_if_rev; /* BCD IPMI Revision */ + uint8_t smipmi_i2c_address; /* I2C address of BMC */ + uint8_t smipmi_nvram_address; /* I2C address of NVRAM + * storage */ + uint64_t smipmi_base_address; /* Base address of BMC (BAR + * format */ + uint8_t smipmi_base_flags; /* Flags field: + * bit 7:6 : register spacing + * 00 = byte + * 01 = dword + * 02 = word + * bit 4 : Lower bit BAR + * bit 3 : IRQ valid + * bit 2 : N/A + * bit 1 : Interrupt polarity + * bit 0 : Interrupt trigger */ + uint8_t smipmi_irq; /* IRQ if applicable */ +} __packed; + +int smbios_find_table(uint8_t, struct smbtable *); +char *smbios_get_string(struct smbtable *, uint8_t, char *, size_t); + +#endif \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/specialreg.h b/lib/libc/include/x86-openbsd-none/i386/specialreg.h new file mode 100644 index 0000000000..6024995d82 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/specialreg.h @@ -0,0 +1,812 @@ +/* $OpenBSD: specialreg.h,v 1.85 2023/08/16 04:07:38 jsg Exp $ */ +/* $NetBSD: specialreg.h,v 1.7 1994/10/27 04:16:26 cgd Exp $ */ + +/*- + * Copyright (c) 1991 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. + * + * @(#)specialreg.h 7.1 (Berkeley) 5/9/91 + */ + +/* + * Bits in 386 special registers: + */ +#define CR0_PE 0x00000001 /* Protected mode Enable */ +#define CR0_MP 0x00000002 /* "Math" Present (NPX or NPX emulator) */ +#define CR0_EM 0x00000004 /* EMulate non-NPX coproc. (trap ESC only) */ +#define CR0_TS 0x00000008 /* Task Switched (if MP, trap ESC and WAIT) */ +#define CR0_ET 0x00000010 /* Extension Type (387 (if set) vs 287) */ +#define CR0_PG 0x80000000 /* PaGing enable */ + +/* + * Bits in 486 special registers: + */ +#define CR0_NE 0x00000020 /* Numeric Error enable (EX16 vs IRQ13) */ +#define CR0_WP 0x00010000 /* Write Protect (honor PG_RW in all modes) */ +#define CR0_AM 0x00040000 /* Alignment Mask (set to enable AC flag) */ +#define CR0_NW 0x20000000 /* Not Write-through */ +#define CR0_CD 0x40000000 /* Cache Disable */ + +/* + * bits in CR3 + */ +#define CR3_PWT (1ULL << 3) +#define CR3_PCD (1ULL << 4) + +/* + * bits in the pentiums %cr4 register: + */ + +#define CR4_VME 0x00000001 /* virtual 8086 mode extension enable */ +#define CR4_PVI 0x00000002 /* protected mode virtual interrupt enable */ +#define CR4_TSD 0x00000004 /* restrict RDTSC instruction to cpl 0 only */ +#define CR4_DE 0x00000008 /* debugging extension */ +#define CR4_PSE 0x00000010 /* large (4MB) page size enable */ +#define CR4_PAE 0x00000020 /* physical address extension enable */ +#define CR4_MCE 0x00000040 /* machine check enable */ +#define CR4_PGE 0x00000080 /* page global enable */ +#define CR4_PCE 0x00000100 /* enable RDPMC instruction for all cpls */ +#define CR4_OSFXSR 0x00000200 /* enable fxsave/fxrestor and SSE */ +#define CR4_OSXMMEXCPT 0x00000400 /* enable unmasked SSE exceptions */ +#define CR4_UMIP 0x00000800 /* user mode instruction prevention */ +#define CR4_VMXE 0x00002000 /* enable virtual machine operation */ +#define CR4_SMXE 0x00004000 /* enable safe mode operation */ +#define CR4_FSGSBASE 0x00010000 /* enable {RD,WR}{FS,GS}BASE ops */ +#define CR4_PCIDE 0x00020000 /* enable process-context IDs */ +#define CR4_OSXSAVE 0x00040000 /* enable XSAVE and extended states */ +#define CR4_SMEP 0x00100000 /* supervisor mode exec protection */ +#define CR4_SMAP 0x00200000 /* supervisor mode access prevention */ +#define CR4_PKE 0x00400000 /* protection key enable */ + +/* + * CPUID "features" bits (CPUID function 0x1): + * EDX bits, then ECX bits + */ + +#define CPUID_FPU 0x00000001 /* processor has an FPU? */ +#define CPUID_VME 0x00000002 /* has virtual mode (%cr4's VME/PVI) */ +#define CPUID_DE 0x00000004 /* has debugging extension */ +#define CPUID_PSE 0x00000008 /* has 4MB page size extension */ +#define CPUID_TSC 0x00000010 /* has time stamp counter */ +#define CPUID_MSR 0x00000020 /* has model specific registers */ +#define CPUID_PAE 0x00000040 /* has phys address extension */ +#define CPUID_MCE 0x00000080 /* has machine check exception */ +#define CPUID_CX8 0x00000100 /* has CMPXCHG8B instruction */ +#define CPUID_APIC 0x00000200 /* has enabled APIC */ +#define CPUID_SYS1 0x00000400 /* has SYSCALL/SYSRET inst. (Cyrix) */ +#define CPUID_SEP 0x00000800 /* has SYSCALL/SYSRET inst. (AMD/Intel) */ +#define CPUID_MTRR 0x00001000 /* has memory type range register */ +#define CPUID_PGE 0x00002000 /* has page global extension */ +#define CPUID_MCA 0x00004000 /* has machine check architecture */ +#define CPUID_CMOV 0x00008000 /* has CMOVcc instruction */ +#define CPUID_PAT 0x00010000 /* has page attribute table */ +#define CPUID_PSE36 0x00020000 /* has 36bit page size extension */ +#define CPUID_PSN 0x00040000 /* has processor serial number */ +#define CPUID_CFLUSH 0x00080000 /* CFLUSH insn supported */ +#define CPUID_B20 0x00100000 /* reserved */ +#define CPUID_DS 0x00200000 /* Debug Store */ +#define CPUID_ACPI 0x00400000 /* ACPI performance modulation regs */ +#define CPUID_MMX 0x00800000 /* has MMX instructions */ +#define CPUID_FXSR 0x01000000 /* has FXRSTOR instruction */ +#define CPUID_SSE 0x02000000 /* has streaming SIMD extensions */ +#define CPUID_SSE2 0x04000000 /* has streaming SIMD extensions #2 */ +#define CPUID_SS 0x08000000 /* self-snoop */ +#define CPUID_HTT 0x10000000 /* Hyper-Threading Technology */ +#define CPUID_TM 0x20000000 /* thermal monitor (TCC) */ +#define CPUID_B30 0x40000000 /* reserved */ +#define CPUID_PBE 0x80000000 /* Pending Break Enabled restarts clock */ + +#define CPUIDECX_SSE3 0x00000001 /* streaming SIMD extensions #3 */ +#define CPUIDECX_PCLMUL 0x00000002 /* Carryless Multiplication */ +#define CPUIDECX_DTES64 0x00000004 /* 64bit debug store */ +#define CPUIDECX_MWAIT 0x00000008 /* Monitor/Mwait */ +#define CPUIDECX_DSCPL 0x00000010 /* CPL Qualified Debug Store */ +#define CPUIDECX_VMX 0x00000020 /* Virtual Machine Extensions */ +#define CPUIDECX_SMX 0x00000040 /* Safer Mode Extensions */ +#define CPUIDECX_EST 0x00000080 /* enhanced SpeedStep */ +#define CPUIDECX_TM2 0x00000100 /* thermal monitor 2 */ +#define CPUIDECX_SSSE3 0x00000200 /* Supplemental Streaming SIMD Ext. 3 */ +#define CPUIDECX_CNXTID 0x00000400 /* Context ID */ +#define CPUIDECX_SDBG 0x00000800 /* Silicon debug capability */ +#define CPUIDECX_FMA3 0x00001000 /* Fused Multiply Add */ +#define CPUIDECX_CX16 0x00002000 /* has CMPXCHG16B instruction */ +#define CPUIDECX_XTPR 0x00004000 /* xTPR Update Control */ +#define CPUIDECX_PDCM 0x00008000 /* Perfmon and Debug Capability */ +#define CPUIDECX_PCID 0x00020000 /* Process-context ID Capability */ +#define CPUIDECX_DCA 0x00040000 /* Direct Cache Access */ +#define CPUIDECX_SSE41 0x00080000 /* Streaming SIMD Extensions 4.1 */ +#define CPUIDECX_SSE42 0x00100000 /* Streaming SIMD Extensions 4.2 */ +#define CPUIDECX_X2APIC 0x00200000 /* Extended xAPIC Support */ +#define CPUIDECX_MOVBE 0x00400000 /* MOVBE Instruction */ +#define CPUIDECX_POPCNT 0x00800000 /* POPCNT Instruction */ +#define CPUIDECX_DEADLINE 0x01000000 /* APIC one-shot via deadline */ +#define CPUIDECX_AES 0x02000000 /* AES Instruction */ +#define CPUIDECX_XSAVE 0x04000000 /* XSAVE/XSTOR States */ +#define CPUIDECX_OSXSAVE 0x08000000 /* OSXSAVE */ +#define CPUIDECX_AVX 0x10000000 /* Advanced Vector Extensions */ +#define CPUIDECX_F16C 0x20000000 /* 16bit fp conversion */ +#define CPUIDECX_RDRAND 0x40000000 /* RDRAND instruction */ +#define CPUIDECX_HV 0x80000000 /* Running on hypervisor */ + +/* + * "Structured Extended Feature Flags Parameters" (CPUID function 0x7, leaf 0) + * EBX bits + */ +#define SEFF0EBX_FSGSBASE 0x00000001 /* {RD,WR}[FG]SBASE instructions */ +#define SEFF0EBX_TSC_ADJUST 0x00000002 /* Has IA32_TSC_ADJUST MSR */ +#define SEFF0EBX_SGX 0x00000004 /* Software Guard Extensions */ +#define SEFF0EBX_BMI1 0x00000008 /* advanced bit manipulation */ +#define SEFF0EBX_HLE 0x00000010 /* Hardware Lock Elision */ +#define SEFF0EBX_AVX2 0x00000020 /* Advanced Vector Extensions 2 */ +#define SEFF0EBX_SMEP 0x00000080 /* Supervisor mode exec protection */ +#define SEFF0EBX_BMI2 0x00000100 /* advanced bit manipulation */ +#define SEFF0EBX_ERMS 0x00000200 /* Enhanced REP MOVSB/STOSB */ +#define SEFF0EBX_INVPCID 0x00000400 /* INVPCID instruction */ +#define SEFF0EBX_RTM 0x00000800 /* Restricted Transactional Memory */ +#define SEFF0EBX_PQM 0x00001000 /* Quality of Service Monitoring */ +#define SEFF0EBX_MPX 0x00004000 /* Memory Protection Extensions */ +#define SEFF0EBX_AVX512F 0x00010000 /* AVX-512 foundation inst */ +#define SEFF0EBX_AVX512DQ 0x00020000 /* AVX-512 double/quadword */ +#define SEFF0EBX_RDSEED 0x00040000 /* RDSEED instruction */ +#define SEFF0EBX_ADX 0x00080000 /* ADCX/ADOX instructions */ +#define SEFF0EBX_SMAP 0x00100000 /* Supervisor mode access prevent */ +#define SEFF0EBX_AVX512IFMA 0x00200000 /* AVX-512 integer mult-add */ +#define SEFF0EBX_PCOMMIT 0x00400000 /* Persistent commit inst */ +#define SEFF0EBX_CLFLUSHOPT 0x00800000 /* cache line flush */ +#define SEFF0EBX_CLWB 0x01000000 /* cache line write back */ +#define SEFF0EBX_PT 0x02000000 /* Processor Trace */ +#define SEFF0EBX_AVX512PF 0x04000000 /* AVX-512 prefetch */ +#define SEFF0EBX_AVX512ER 0x08000000 /* AVX-512 exp/reciprocal */ +#define SEFF0EBX_AVX512CD 0x10000000 /* AVX-512 conflict detection */ +#define SEFF0EBX_SHA 0x20000000 /* SHA Extensions */ +#define SEFF0EBX_AVX512BW 0x40000000 /* AVX-512 byte/word inst */ +#define SEFF0EBX_AVX512VL 0x80000000 /* AVX-512 vector len inst */ +/* SEFF ECX bits */ +#define SEFF0ECX_PREFETCHWT1 0x00000001 /* PREFETCHWT1 instruction */ +#define SEFF0ECX_AVX512VBMI 0x00000002 /* AVX-512 vector bit inst */ +#define SEFF0ECX_UMIP 0x00000004 /* UMIP support */ +#define SEFF0ECX_PKU 0x00000008 /* Page prot keys for user mode */ +#define SEFF0ECX_WAITPKG 0x00000020 /* UMONITOR/UMWAIT/TPAUSE insns */ +/* SEFF EDX bits */ +#define SEFF0EDX_AVX512_4FNNIW 0x00000004 /* AVX-512 neural network insns */ +#define SEFF0EDX_AVX512_4FMAPS 0x00000008 /* AVX-512 mult accum single prec */ +#define SEFF0EDX_SRBDS_CTRL 0x00000200 /* MCU_OPT_CTRL MSR */ +#define SEFF0EDX_MD_CLEAR 0x00000400 /* Microarch Data Clear */ +#define SEFF0EDX_TSXFA 0x00002000 /* TSX Forced Abort */ +#define SEFF0EDX_IBRS 0x04000000 /* IBRS / IBPB Speculation Control */ +#define SEFF0EDX_STIBP 0x08000000 /* STIBP Speculation Control */ +#define SEFF0EDX_L1DF 0x10000000 /* L1D_FLUSH */ +#define SEFF0EDX_ARCH_CAP 0x20000000 /* Has IA32_ARCH_CAPABILITIES MSR */ +#define SEFF0EDX_SSBD 0x80000000 /* Spec Store Bypass Disable */ + +/* + * Thermal and Power Management (CPUID function 0x6) EAX bits + */ +#define TPM_SENSOR 0x00000001 /* Digital temp sensor */ +#define TPM_ARAT 0x00000004 /* APIC Timer Always Running */ + +/* + * "Architectural Performance Monitoring" bits (CPUID function 0x0a): + * EAX bits + */ + +#define CPUIDEAX_VERID 0x000000ff +#define CPUIDEAX_NUM_GC(cpuid) (((cpuid) >> 8) & 0x000000ff) +#define CPUIDEAX_BIT_GC(cpuid) (((cpuid) >> 16) & 0x000000ff) +#define CPUIDEAX_LEN_EBX(cpuid) (((cpuid) >> 24) & 0x000000ff) + +#define CPUIDEBX_EVT_CORE (1 << 0) /* Core cycle */ +#define CPUIDEBX_EVT_INST (1 << 1) /* Instruction retired */ +#define CPUIDEBX_EVT_REFR (1 << 2) /* Reference cycles */ +#define CPUIDEBX_EVT_CACHE_REF (1 << 3) /* Last-level cache ref. */ +#define CPUIDEBX_EVT_CACHE_MIS (1 << 4) /* Last-level cache miss. */ +#define CPUIDEBX_EVT_BRANCH_INST (1 << 5) /* Branch instruction ret. */ +#define CPUIDEBX_EVT_BRANCH_MISP (1 << 6) /* Branch mispredict ret. */ + +#define CPUIDEDX_NUM_FC(cpuid) (((cpuid) >> 0) & 0x0000001f) +#define CPUIDEDX_BIT_FC(cpuid) (((cpuid) >> 5) & 0x000000ff) + +/* + * CPUID "extended features" bits (CPUID function 0x80000001): + * EDX bits, then ECX bits + */ + +#define CPUID_MPC 0x00080000 /* Multiprocessing Capable */ +#define CPUID_NXE 0x00100000 /* No-Execute Extension */ +#define CPUID_MMXX 0x00400000 /* AMD MMX Extensions */ +#define CPUID_FFXSR 0x02000000 /* fast FP/MMX save/restore */ +#define CPUID_PAGE1GB 0x04000000 /* 1-GByte pages */ +#define CPUID_RDTSCP 0x08000000 /* RDTSCP / IA32_TSC_AUX available */ +#define CPUID_LONG 0x20000000 /* long mode */ +#define CPUID_3DNOW2 0x40000000 /* 3DNow! Instruction Extension */ +#define CPUID_3DNOW 0x80000000 /* 3DNow! Instructions */ + +#define CPUIDECX_LAHF 0x00000001 /* LAHF and SAHF instructions */ +#define CPUIDECX_CMPLEG 0x00000002 /* Core MP legacy mode */ +#define CPUIDECX_SVM 0x00000004 /* Secure Virtual Machine */ +#define CPUIDECX_EAPICSP 0x00000008 /* Extended APIC space */ +#define CPUIDECX_AMCR8 0x00000010 /* LOCK MOV CR0 means MOV CR8 */ +#define CPUIDECX_ABM 0x00000020 /* LZCNT instruction */ +#define CPUIDECX_SSE4A 0x00000040 /* SSE4-A instruction set */ +#define CPUIDECX_MASSE 0x00000080 /* Misaligned SSE mode */ +#define CPUIDECX_3DNOWP 0x00000100 /* 3DNowPrefetch */ +#define CPUIDECX_OSVW 0x00000200 /* OS visible workaround */ +#define CPUIDECX_IBS 0x00000400 /* Instruction based sampling */ +#define CPUIDECX_XOP 0x00000800 /* Extended operating support */ +#define CPUIDECX_SKINIT 0x00001000 /* SKINIT and STGI are supported */ +#define CPUIDECX_WDT 0x00002000 /* Watchdog timer */ +/* Reserved 0x00004000 */ +#define CPUIDECX_LWP 0x00008000 /* Lightweight profiling support */ +#define CPUIDECX_FMA4 0x00010000 /* 4-operand FMA instructions */ +#define CPUIDECX_TCE 0x00020000 /* Translation Cache Extension */ +/* Reserved 0x00040000 */ +#define CPUIDECX_NODEID 0x00080000 /* Support for MSRC001C */ +/* Reserved 0x00100000 */ +#define CPUIDECX_TBM 0x00200000 /* Trailing bit manipulation instruction */ +#define CPUIDECX_TOPEXT 0x00400000 /* Topology extensions support */ +#define CPUIDECX_CPCTR 0x00800000 /* core performance counter ext */ +#define CPUIDECX_DBKP 0x04000000 /* DataBreakpointExtension */ +#define CPUIDECX_PERFTSC 0x08000000 /* performance time-stamp counter */ +#define CPUIDECX_PCTRL3 0x10000000 /* L3 performance counter ext */ +#define CPUIDECX_MWAITX 0x20000000 /* MWAITX/MONITORX */ + +/* + * "Advanced Power Management Information" bits (CPUID function 0x80000007): + * EDX bits. + */ + +#define CPUIDEDX_ITSC (1 << 8) /* Invariant TSC */ + +/* + * AMD CPUID function 0x80000008 EBX bits + */ +#define CPUIDEBX_IBPB (1ULL << 12) /* Speculation Control IBPB */ +#define CPUIDEBX_IBRS (1ULL << 14) /* Speculation Control IBRS */ +#define CPUIDEBX_STIBP (1ULL << 15) /* Speculation Control STIBP */ +#define CPUIDEBX_IBRS_ALWAYSON (1ULL << 16) /* IBRS always on mode */ +#define CPUIDEBX_STIBP_ALWAYSON (1ULL << 17) /* STIBP always on mode */ +#define CPUIDEBX_IBRS_PREF (1ULL << 18) /* IBRS preferred */ +#define CPUIDEBX_SSBD (1ULL << 24) /* Speculation Control SSBD */ +#define CPUIDEBX_VIRT_SSBD (1ULL << 25) /* Virt Spec Control SSBD */ +#define CPUIDEBX_SSBD_NOTREQ (1ULL << 26) /* SSBD not required */ + +#define CPUID2FAMILY(cpuid) (((cpuid) >> 8) & 15) +#define CPUID2MODEL(cpuid) (((cpuid) >> 4) & 15) +#define CPUID2STEPPING(cpuid) ((cpuid) & 15) + +#define CPUID(code, eax, ebx, ecx, edx) \ + __asm volatile("cpuid" \ + : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) \ + : "a" (code)) +#define CPUID_LEAF(code, leaf, eax, ebx, ecx, edx) \ + __asm volatile("cpuid" \ + : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) \ + : "a" (code), "c" (leaf)) + + +/* + * Model-specific registers for the i386 family + */ +#define MSR_P5_MC_ADDR 0x000 +#define MSR_P5_MC_TYPE 0x001 +#define MSR_TSC 0x010 +#define P5MSR_CTRSEL 0x011 /* P5 only (trap on P6) */ +#define P5MSR_CTR0 0x012 /* P5 only (trap on P6) */ +#define P5MSR_CTR1 0x013 /* P5 only (trap on P6) */ +#define MSR_PLATFORM_ID 0x017 /* Platform ID for microcode */ +#define MSR_APICBASE 0x01b +#define APICBASE_BSP 0x100 +#define APICBASE_ENABLE_X2APIC 0x400 +#define APICBASE_GLOBAL_ENABLE 0x800 +#define MSR_EBL_CR_POWERON 0x02a +#define MSR_EBC_FREQUENCY_ID 0x02c /* Pentium 4 only */ +#define MSR_TEST_CTL 0x033 +#define MSR_IA32_FEATURE_CONTROL 0x03a +#define MSR_SPEC_CTRL 0x048 /* Speculation Control IBRS / STIBP */ +#define SPEC_CTRL_IBRS (1ULL << 0) +#define SPEC_CTRL_STIBP (1ULL << 1) +#define SPEC_CTRL_SSBD (1ULL << 2) +#define MSR_PRED_CMD 0x049 /* Speculation Control IBPB */ +#define PRED_CMD_IBPB (1ULL << 0) +#define MSR_BIOS_UPDT_TRIG 0x079 +#define MSR_BBL_CR_D0 0x088 /* PII+ only */ +#define MSR_BBL_CR_D1 0x089 /* PII+ only */ +#define MSR_BBL_CR_D2 0x08a /* PII+ only */ +#define MSR_BIOS_SIGN 0x08b +#define MSR_PERFCTR0 0x0c1 +#define MSR_PERFCTR1 0x0c2 +#define P6MSR_CTR0 0x0c1 +#define P6MSR_CTR1 0x0c2 +#define MSR_FSB_FREQ 0x0cd /* Core Duo/Solo only */ +#define MSR_MTRRcap 0x0fe +#define MTRRcap_FIXED 0x100 /* bit 8 - fixed MTRRs supported */ +#define MTRRcap_WC 0x400 /* bit 10 - WC type supported */ +#define MTRRcap_SMRR 0x800 /* bit 11 - SMM range reg supported */ +#define MSR_ARCH_CAPABILITIES 0x10a +#define ARCH_CAP_RDCL_NO (1 << 0) /* Meltdown safe */ +#define ARCH_CAP_IBRS_ALL (1 << 1) /* enhanced IBRS */ +#define ARCH_CAP_RSBA (1 << 2) /* RSB Alternate */ +#define ARCH_CAP_SKIP_L1DFL_VMENTRY (1 << 3) +#define ARCH_CAP_SSB_NO (1 << 4) /* Spec St Byp safe */ +#define ARCH_CAP_MDS_NO (1 << 5) /* microarch data-sampling */ +#define ARCH_CAP_IF_PSCHANGE_MC_NO (1 << 6) /* PS MCE safe */ +#define ARCH_CAP_TSX_CTRL (1 << 7) /* has TSX_CTRL MSR */ +#define ARCH_CAP_TAA_NO (1 << 8) /* TSX AA safe */ +#define ARCH_CAP_MCU_CONTROL (1 << 9) /* has MCU_CTRL MSR */ +#define ARCH_CAP_MISC_PACKAGE_CTLS (1 << 10) /* has MISC_PKG_CTLS MSR */ +#define ARCH_CAP_ENERGY_FILTERING_CTL (1 << 11) /* r/w energy fltring bit */ +#define ARCH_CAP_DOITM (1 << 12) /* Data oprnd indpdnt tmng */ +#define ARCH_CAP_SBDR_SSDP_NO (1 << 13) /* SBDR/SSDP safe */ +#define ARCH_CAP_FBSDP_NO (1 << 14) /* FBSDP safe */ +#define ARCH_CAP_PSDP_NO (1 << 15) /* PSDP safe */ +#define ARCH_CAP_FB_CLEAR (1 << 17) /* MD_CLEAR covers FB */ +#define ARCH_CAP_FB_CLEAR_CTRL (1 << 18) +#define ARCH_CAP_RRSBA (1 << 19) /* has RRSBA if not dis */ +#define ARCH_CAP_BHI_NO (1 << 20) /* BHI safe */ +#define ARCH_CAP_XAPIC_DISABLE_STATUS (1 << 21) /* can disable xAPIC */ +#define ARCH_CAP_OVERCLOCKING_STATUS (1 << 23) /* has OVRCLCKNG_STAT MSR */ +#define ARCH_CAP_PBRSB_NO (1 << 24) /* PBSR safe */ +#define ARCH_CAP_GDS_CTRL (1 << 25) /* has GDS_MITG_DIS/LOCK */ +#define ARCH_CAP_GDS_NO (1 << 26) /* GDS safe */ +#define MSR_FLUSH_CMD 0x10b +#define FLUSH_CMD_L1D_FLUSH (1ULL << 0) +#define MSR_BBL_CR_ADDR 0x116 /* PII+ only */ +#define MSR_BBL_CR_DECC 0x118 /* PII+ only */ +#define MSR_BBL_CR_CTL 0x119 /* PII+ only */ +#define MSR_BBL_CR_TRIG 0x11a /* PII+ only */ +#define MSR_BBL_CR_BUSY 0x11b /* PII+ only */ +#define MSR_BBL_CR_CTR3 0x11e /* PII+ only */ +#define MSR_TSX_CTRL 0x122 +#define TSX_CTRL_RTM_DISABLE (1ULL << 0) +#define TSX_CTRL_TSX_CPUID_CLEAR (1ULL << 1) +#define MSR_MCU_OPT_CTRL 0x123 +#define RNGDS_MITG_DIS (1ULL << 0) +#define MSR_SYSENTER_CS 0x174 +#define MSR_SYSENTER_ESP 0x175 +#define MSR_SYSENTER_EIP 0x176 +#define MSR_MCG_CAP 0x179 +#define MSR_MCG_STATUS 0x17a +#define MSR_MCG_CTL 0x17b +#define P6MSR_CTRSEL0 0x186 +#define P6MSR_CTRSEL1 0x187 +#define MSR_PERF_STATUS 0x198 /* Pentium M */ +#define MSR_PERF_CTL 0x199 /* Pentium M */ +#define PERF_CTL_TURBO 0x100000000ULL /* bit 32 - turbo mode */ +#define MSR_THERM_CONTROL 0x19a +#define MSR_THERM_INTERRUPT 0x19b +#define MSR_THERM_STATUS 0x19c +#define MSR_THERM_STATUS_VALID_BIT 0x80000000 +#define MSR_THERM_STATUS_TEMP(msr) ((msr >> 16) & 0x7f) +#define MSR_THERM2_CTL 0x19d /* Pentium M */ +#define MSR_MISC_ENABLE 0x1a0 +/* + * MSR_MISC_ENABLE (0x1a0) + * + * Enable Fast Strings: enables fast REP MOVS/REP STORS (R/W) + * Enable TCC: Enable automatic thermal control circuit (R/W) + * Performance monitoring available: 1 if enabled (R/O) + * Branch trace storage unavailable: 1 if unsupported (R/O) + * Processor event based sampling unavailable: 1 if unsupported (R/O) + * Enhanced Intel SpeedStep technology enable: 1 to enable (R/W) + * Enable monitor FSM: 1 to enable MONITOR/MWAIT (R/W) + * Limit CPUID maxval: 1 to limit CPUID leaf nodes to 0x2 and lower (R/W) + * Enable xTPR message disable: 1 to disable xTPR messages + * XD bit disable: 1 to disable NX capability (bit 34, or bit 2 of %edx/%rdx) + */ +#define MISC_ENABLE_FAST_STRINGS (1 << 0) +#define MISC_ENABLE_TCC (1 << 3) +#define MISC_ENABLE_PERF_MON_AVAILABLE (1 << 7) +#define MISC_ENABLE_BTS_UNAVAILABLE (1 << 11) +#define MISC_ENABLE_PEBS_UNAVAILABLE (1 << 12) +#define MISC_ENABLE_EIST_ENABLED (1 << 16) +#define MISC_ENABLE_ENABLE_MONITOR_FSM (1 << 18) +#define MISC_ENABLE_LIMIT_CPUID_MAXVAL (1 << 22) +#define MISC_ENABLE_xTPR_MESSAGE_DISABLE (1 << 23) +#define MISC_ENABLE_XD_BIT_DISABLE (1 << 2) +/* + * for Core i Series and newer Xeons, see + * http://www.intel.com/content/dam/www/public/us/en/ + * documents/white-papers/cpu-monitoring-dts-peci-paper.pdf + */ +#define MSR_TEMPERATURE_TARGET 0x1a2 /* Core i Series, Newer Xeons */ +#define MSR_TEMPERATURE_TARGET_TJMAX(r) (((r) >> 16) & 0xff) +/* + * not documented anywhere, see intelcore_update_sensor() + * only available Core Duo and Core Solo Processors + */ +#define MSR_TEMPERATURE_TARGET_UNDOCUMENTED 0x0ee +#define MSR_TEMPERATURE_TARGET_LOW_BIT_UNDOCUMENTED 0x40000000 +#define MSR_DEBUGCTLMSR 0x1d9 +#define MSR_LASTBRANCHFROMIP 0x1db +#define MSR_LASTBRANCHTOIP 0x1dc +#define MSR_LASTINTFROMIP 0x1dd +#define MSR_LASTINTTOIP 0x1de +#define MSR_ROB_CR_BKUPTMPDR6 0x1e0 +#define MSR_MTRRvarBase 0x200 +#define MSR_MTRRfix64K_00000 0x250 +#define MSR_MTRRfix16K_80000 0x258 +#define MSR_MTRRfix4K_C0000 0x268 +#define MSR_CR_PAT 0x277 +#define MSR_MTRRdefType 0x2ff +#define MTRRdefType_FIXED_ENABLE 0x400 /* bit 10 - fixed MTRR enabled */ +#define MTRRdefType_ENABLE 0x800 /* bit 11 - MTRRs enabled */ +#define MSR_PERF_FIXED_CTR1 0x30a /* CPU_CLK_Unhalted.Core */ +#define MSR_PERF_FIXED_CTR2 0x30b /* CPU_CLK.Unhalted.Ref */ +#define MSR_PERF_FIXED_CTR_CTRL 0x38d +#define MSR_PERF_FIXED_CTR_FC_DIS 0x0 /* disable counter */ +#define MSR_PERF_FIXED_CTR_FC_1 0x1 /* count ring 1 */ +#define MSR_PERF_FIXED_CTR_FC_123 0x2 /* count rings 1,2,3 */ +#define MSR_PERF_FIXED_CTR_FC_ANY 0x3 /* count everything */ +#define MSR_PERF_FIXED_CTR_FC_MASK 0x3 +#define MSR_PERF_FIXED_CTR_FC(_i, _v) ((_v) << (4 * (_i))) +#define MSR_PERF_FIXED_CTR_ANYTHR(_i) (0x4 << (4 * (_i))) +#define MSR_PERF_FIXED_CTR_INT(_i) (0x8 << (4 * (_i))) +#define MSR_PERF_GLOBAL_CTRL 0x38f +#define MSR_PERF_GLOBAL_CTR1_EN (1ULL << 33) +#define MSR_PERF_GLOBAL_CTR2_EN (1ULL << 34) +#define MSR_MC0_CTL 0x400 +#define MSR_MC0_STATUS 0x401 +#define MSR_MC0_ADDR 0x402 +#define MSR_MC0_MISC 0x403 +#define MSR_MC1_CTL 0x404 +#define MSR_MC1_STATUS 0x405 +#define MSR_MC1_ADDR 0x406 +#define MSR_MC1_MISC 0x407 +#define MSR_MC2_CTL 0x408 +#define MSR_MC2_STATUS 0x409 +#define MSR_MC2_ADDR 0x40a +#define MSR_MC2_MISC 0x40b +#define MSR_MC4_CTL 0x40c +#define MSR_MC4_STATUS 0x40d +#define MSR_MC4_ADDR 0x40e +#define MSR_MC4_MISC 0x40f +#define MSR_MC3_CTL 0x410 +#define MSR_MC3_STATUS 0x411 +#define MSR_MC3_ADDR 0x412 +#define MSR_MC3_MISC 0x413 + +/* VIA MSRs */ +#define MSR_CENT_TMTEMPERATURE 0x1423 /* Thermal monitor temperature */ +#define MSR_C7M_TMTEMPERATURE 0x1169 + +/* AMD MSRs */ +#define MSR_K6_EPMR 0xc0000086 +#define MSR_K7_EVNTSEL0 0xc0010000 +#define MSR_K7_EVNTSEL1 0xc0010001 +#define MSR_K7_EVNTSEL2 0xc0010002 +#define MSR_K7_EVNTSEL3 0xc0010003 +#define MSR_K7_PERFCTR0 0xc0010004 +#define MSR_K7_PERFCTR1 0xc0010005 +#define MSR_K7_PERFCTR2 0xc0010006 +#define MSR_K7_PERFCTR3 0xc0010007 + +/* + * AMD K8 (Opteron) MSRs. + */ +#define MSR_PATCH_LEVEL 0x0000008b +#define MSR_SYSCFG 0xc0000010 + +#define MSR_EFER 0xc0000080 /* Extended feature enable */ +#define EFER_SCE 0x00000001 /* SYSCALL extension */ +#define EFER_LME 0x00000100 /* Long Mode Active */ +#define EFER_LMA 0x00000400 /* Long Mode Enabled */ +#define EFER_NXE 0x00000800 /* No-Execute Enabled */ +#define EFER_SVME 0x00001000 /* SVM Enabled */ + +#define MSR_STAR 0xc0000081 /* 32 bit syscall gate addr */ +#define MSR_LSTAR 0xc0000082 /* 64 bit syscall gate addr */ +#define MSR_CSTAR 0xc0000083 /* compat syscall gate addr */ +#define MSR_SFMASK 0xc0000084 /* flags to clear on syscall */ + +#define MSR_FSBASE 0xc0000100 /* 64bit offset for fs: */ +#define MSR_GSBASE 0xc0000101 /* 64bit offset for gs: */ +#define MSR_KERNELGSBASE 0xc0000102 /* storage for swapgs ins */ +#define MSR_PATCH_LOADER 0xc0010020 +#define MSR_INT_PEN_MSG 0xc0010055 /* Interrupt pending message */ + +#define MSR_DE_CFG 0xc0011029 /* Decode Configuration */ +#define DE_CFG_721 0x00000001 /* errata 721 */ +#define DE_CFG_SERIALIZE_LFENCE (1 << 1) /* Enable serializing lfence */ +#define DE_CFG_SERIALIZE_9 (1 << 9) /* Zenbleed chickenbit */ + +#define IPM_C1E_CMP_HLT 0x10000000 +#define IPM_SMI_CMP_HLT 0x08000000 + +/* + * These require a 'passcode' for access. See cpufunc.h. + */ +#define MSR_HWCR 0xc0010015 +#define HWCR_FFDIS 0x00000040 + +#define MSR_NB_CFG 0xc001001f +#define NB_CFG_DISIOREQLOCK 0x0000000000000004ULL +#define NB_CFG_DISDATMSK 0x0000001000000000ULL + +#define MSR_LS_CFG 0xc0011020 +#define LS_CFG_DIS_LS2_SQUISH 0x02000000 + +#define MSR_IC_CFG 0xc0011021 +#define IC_CFG_DIS_SEQ_PREFETCH 0x00000800 + +#define MSR_DC_CFG 0xc0011022 +#define DC_CFG_DIS_CNV_WC_SSO 0x00000004 +#define DC_CFG_DIS_SMC_CHK_BUF 0x00000400 + +#define MSR_BU_CFG 0xc0011023 +#define BU_CFG_THRL2IDXCMPDIS 0x0000080000000000ULL +#define BU_CFG_WBPFSMCCHKDIS 0x0000200000000000ULL +#define BU_CFG_WBENHWSBDIS 0x0001000000000000ULL + +/* + * Constants related to MTRRs + */ +#define MTRR_N64K 8 /* numbers of fixed-size entries */ +#define MTRR_N16K 16 +#define MTRR_N4K 64 + +/* + * the following four 3-byte registers control the non-cacheable regions. + * These registers must be written as three separate bytes. + * + * NCRx+0: A31-A24 of starting address + * NCRx+1: A23-A16 of starting address + * NCRx+2: A15-A12 of starting address | NCR_SIZE_xx. + * + * The non-cacheable region's starting address must be aligned to the + * size indicated by the NCR_SIZE_xx field. + */ +#define NCR1 0xc4 +#define NCR2 0xc7 +#define NCR3 0xca +#define NCR4 0xcd + +#define NCR_SIZE_0K 0 +#define NCR_SIZE_4K 1 +#define NCR_SIZE_8K 2 +#define NCR_SIZE_16K 3 +#define NCR_SIZE_32K 4 +#define NCR_SIZE_64K 5 +#define NCR_SIZE_128K 6 +#define NCR_SIZE_256K 7 +#define NCR_SIZE_512K 8 +#define NCR_SIZE_1M 9 +#define NCR_SIZE_2M 10 +#define NCR_SIZE_4M 11 +#define NCR_SIZE_8M 12 +#define NCR_SIZE_16M 13 +#define NCR_SIZE_32M 14 +#define NCR_SIZE_4G 15 + +/* + * Performance monitor events. + * + * Note that 586-class and 686-class CPUs have different performance + * monitors available, and they are accessed differently: + * + * 686-class: `rdpmc' instruction + * 586-class: `rdmsr' instruction, CESR MSR + * + * The descriptions of these events are too lengthy to include here. + * See Appendix A of "Intel Architecture Software Developer's + * Manual, Volume 3: System Programming" for more information. + */ + +/* + * 586-class CESR MSR format. Lower 16 bits is CTR0, upper 16 bits + * is CTR1. + */ + +#define PMC5_CESR_EVENT 0x003f +#define PMC5_CESR_OS 0x0040 +#define PMC5_CESR_USR 0x0080 +#define PMC5_CESR_E 0x0100 +#define PMC5_CESR_P 0x0200 + +/* + * 686-class Event Selector MSR format. + */ + +#define PMC6_EVTSEL_EVENT 0x000000ff +#define PMC6_EVTSEL_UNIT 0x0000ff00 +#define PMC6_EVTSEL_UNIT_SHIFT 8 +#define PMC6_EVTSEL_USR (1 << 16) +#define PMC6_EVTSEL_OS (1 << 17) +#define PMC6_EVTSEL_E (1 << 18) +#define PMC6_EVTSEL_PC (1 << 19) +#define PMC6_EVTSEL_INT (1 << 20) +#define PMC6_EVTSEL_EN (1 << 22) /* PerfEvtSel0 only */ +#define PMC6_EVTSEL_INV (1 << 23) +#define PMC6_EVTSEL_COUNTER_MASK 0xff000000 +#define PMC6_EVTSEL_COUNTER_MASK_SHIFT 24 + +/* Data Cache Unit */ +#define PMC6_DATA_MEM_REFS 0x43 +#define PMC6_DCU_LINES_IN 0x45 +#define PMC6_DCU_M_LINES_IN 0x46 +#define PMC6_DCU_M_LINES_OUT 0x47 +#define PMC6_DCU_MISS_OUTSTANDING 0x48 + +/* Instruction Fetch Unit */ +#define PMC6_IFU_IFETCH 0x80 +#define PMC6_IFU_IFETCH_MISS 0x81 +#define PMC6_ITLB_MISS 0x85 +#define PMC6_IFU_MEM_STALL 0x86 +#define PMC6_ILD_STALL 0x87 + +/* L2 Cache */ +#define PMC6_L2_IFETCH 0x28 +#define PMC6_L2_LD 0x29 +#define PMC6_L2_ST 0x2a +#define PMC6_L2_LINES_IN 0x24 +#define PMC6_L2_LINES_OUT 0x26 +#define PMC6_L2_M_LINES_INM 0x25 +#define PMC6_L2_M_LINES_OUTM 0x27 +#define PMC6_L2_RQSTS 0x2e +#define PMC6_L2_ADS 0x21 +#define PMC6_L2_DBUS_BUSY 0x22 +#define PMC6_L2_DBUS_BUSY_RD 0x23 + +/* External Bus Logic */ +#define PMC6_BUS_DRDY_CLOCKS 0x62 +#define PMC6_BUS_LOCK_CLOCKS 0x63 +#define PMC6_BUS_REQ_OUTSTANDING 0x60 +#define PMC6_BUS_TRAN_BRD 0x65 +#define PMC6_BUS_TRAN_RFO 0x66 +#define PMC6_BUS_TRANS_WB 0x67 +#define PMC6_BUS_TRAN_IFETCH 0x68 +#define PMC6_BUS_TRAN_INVAL 0x69 +#define PMC6_BUS_TRAN_PWR 0x6a +#define PMC6_BUS_TRANS_P 0x6b +#define PMC6_BUS_TRANS_IO 0x6c +#define PMC6_BUS_TRAN_DEF 0x6d +#define PMC6_BUS_TRAN_BURST 0x6e +#define PMC6_BUS_TRAN_ANY 0x70 +#define PMC6_BUS_TRAN_MEM 0x6f +#define PMC6_BUS_DATA_RCV 0x64 +#define PMC6_BUS_BNR_DRV 0x61 +#define PMC6_BUS_HIT_DRV 0x7a +#define PMC6_BUS_HITM_DRDV 0x7b +#define PMC6_BUS_SNOOP_STALL 0x7e + +/* Floating Point Unit */ +#define PMC6_FLOPS 0xc1 +#define PMC6_FP_COMP_OPS_EXE 0x10 +#define PMC6_FP_ASSIST 0x11 +#define PMC6_MUL 0x12 +#define PMC6_DIV 0x12 +#define PMC6_CYCLES_DIV_BUSY 0x14 + +/* Memory Ordering */ +#define PMC6_LD_BLOCKS 0x03 +#define PMC6_SB_DRAINS 0x04 +#define PMC6_MISALIGN_MEM_REF 0x05 +#define PMC6_EMON_KNI_PREF_DISPATCHED 0x07 /* P-III only */ +#define PMC6_EMON_KNI_PREF_MISS 0x4b /* P-III only */ + +/* Instruction Decoding and Retirement */ +#define PMC6_INST_RETIRED 0xc0 +#define PMC6_UOPS_RETIRED 0xc2 +#define PMC6_INST_DECODED 0xd0 +#define PMC6_EMON_KNI_INST_RETIRED 0xd8 +#define PMC6_EMON_KNI_COMP_INST_RET 0xd9 + +/* Interrupts */ +#define PMC6_HW_INT_RX 0xc8 +#define PMC6_CYCLES_INT_MASKED 0xc6 +#define PMC6_CYCLES_INT_PENDING_AND_MASKED 0xc7 + +/* Branches */ +#define PMC6_BR_INST_RETIRED 0xc4 +#define PMC6_BR_MISS_PRED_RETIRED 0xc5 +#define PMC6_BR_TAKEN_RETIRED 0xc9 +#define PMC6_BR_MISS_PRED_TAKEN_RET 0xca +#define PMC6_BR_INST_DECODED 0xe0 +#define PMC6_BTB_MISSES 0xe2 +#define PMC6_BR_BOGUS 0xe4 +#define PMC6_BACLEARS 0xe6 + +/* Stalls */ +#define PMC6_RESOURCE_STALLS 0xa2 +#define PMC6_PARTIAL_RAT_STALLS 0xd2 + +/* Segment Register Loads */ +#define PMC6_SEGMENT_REG_LOADS 0x06 + +/* Clocks */ +#define PMC6_CPU_CLK_UNHALTED 0x79 + +/* MMX Unit */ +#define PMC6_MMX_INSTR_EXEC 0xb0 /* Celeron, P-II, P-IIX only */ +#define PMC6_MMX_SAT_INSTR_EXEC 0xb1 /* P-II and P-III only */ +#define PMC6_MMX_UOPS_EXEC 0xb2 /* P-II and P-III only */ +#define PMC6_MMX_INSTR_TYPE_EXEC 0xb3 /* P-II and P-III only */ +#define PMC6_FP_MMX_TRANS 0xcc /* P-II and P-III only */ +#define PMC6_MMX_ASSIST 0xcd /* P-II and P-III only */ +#define PMC6_MMX_INSTR_RET 0xc3 /* P-II only */ + +/* Segment Register Renaming */ +#define PMC6_SEG_RENAME_STALLS 0xd4 /* P-II and P-III only */ +#define PMC6_SEG_REG_RENAMES 0xd5 /* P-II and P-III only */ +#define PMC6_RET_SEG_RENAMES 0xd6 /* P-II and P-III only */ + +/* VIA C3 crypto featureset: for i386_has_xcrypt */ +#define C3_HAS_AES 1 /* cpu has AES */ +#define C3_HAS_SHA 2 /* cpu has SHA1 & SHA256 */ +#define C3_HAS_MM 4 /* cpu has RSA instructions */ +#define C3_HAS_AESCTR 8 /* cpu has AES-CTR instructions */ + +/* Centaur Extended Feature flags */ +#define C3_CPUID_HAS_RNG 0x000004 +#define C3_CPUID_DO_RNG 0x000008 +#define C3_CPUID_HAS_ACE 0x000040 +#define C3_CPUID_DO_ACE 0x000080 +#define C3_CPUID_HAS_ACE2 0x000100 +#define C3_CPUID_DO_ACE2 0x000200 +#define C3_CPUID_HAS_PHE 0x000400 +#define C3_CPUID_DO_PHE 0x000800 +#define C3_CPUID_HAS_PMM 0x001000 +#define C3_CPUID_DO_PMM 0x002000 + +/* VIA C3 xcrypt-* instruction context control options */ +#define C3_CRYPT_CWLO_ROUND_M 0x0000000f +#define C3_CRYPT_CWLO_ALG_M 0x00000070 +#define C3_CRYPT_CWLO_ALG_AES 0x00000000 +#define C3_CRYPT_CWLO_KEYGEN_M 0x00000080 +#define C3_CRYPT_CWLO_KEYGEN_HW 0x00000000 +#define C3_CRYPT_CWLO_KEYGEN_SW 0x00000080 +#define C3_CRYPT_CWLO_NORMAL 0x00000000 +#define C3_CRYPT_CWLO_INTERMEDIATE 0x00000100 +#define C3_CRYPT_CWLO_ENCRYPT 0x00000000 +#define C3_CRYPT_CWLO_DECRYPT 0x00000200 +#define C3_CRYPT_CWLO_KEY128 0x0000000a /* 128bit, 10 rds */ +#define C3_CRYPT_CWLO_KEY192 0x0000040c /* 192bit, 12 rds */ +#define C3_CRYPT_CWLO_KEY256 0x0000080e /* 256bit, 15 rds */ + +/* Intel Silicon Debug */ +#define IA32_DEBUG_INTERFACE 0xc80 +#define IA32_DEBUG_INTERFACE_ENABLE 0x00000001 +#define IA32_DEBUG_INTERFACE_LOCK 0x40000000 +#define IA32_DEBUG_INTERFACE_MASK 0x80000000 + +/* + * PAT + */ +#define PATENTRY(n, type) ((uint64_t)type << ((n) * 8)) +#define PAT_UC 0x0UL +#define PAT_WC 0x1UL +#define PAT_WT 0x4UL +#define PAT_WP 0x5UL +#define PAT_WB 0x6UL +#define PAT_UCMINUS 0x7UL + +/* + * XSAVE subfeatures (cpuid 0xd, leaf 1) + */ +#define XSAVE_XSAVEOPT 0x1UL +#define XSAVE_XSAVEC 0x2UL +#define XSAVE_XGETBV1 0x4UL +#define XSAVE_XSAVES 0x8UL \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/spinlock.h b/lib/libc/include/x86-openbsd-none/i386/spinlock.h new file mode 100644 index 0000000000..f3fe78c834 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/spinlock.h @@ -0,0 +1,10 @@ +/* $OpenBSD: spinlock.h,v 1.3 2017/09/05 02:40:54 guenther Exp $ */ + +#ifndef _MACHINE_SPINLOCK_H_ +#define _MACHINE_SPINLOCK_H_ + +#define _ATOMIC_LOCK_UNLOCKED (0) +#define _ATOMIC_LOCK_LOCKED (1) +typedef int _atomic_lock_t; + +#endif \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/sysarch.h b/lib/libc/include/x86-openbsd-none/i386/sysarch.h new file mode 100644 index 0000000000..871c60d946 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/sysarch.h @@ -0,0 +1,38 @@ +/* $OpenBSD: sysarch.h,v 1.14 2016/03/24 04:56:08 guenther Exp $ */ +/* $NetBSD: sysarch.h,v 1.8 1996/01/08 13:51:44 mycroft Exp $ */ + +#ifndef _MACHINE_SYSARCH_H_ +#define _MACHINE_SYSARCH_H_ + +/* + * Architecture specific syscalls (i386) + */ +#define I386_IOPL 2 +#define I386_VM86 5 +#define I386_GET_FSBASE 6 +#define I386_SET_FSBASE 7 +#define I386_GET_GSBASE 8 +#define I386_SET_GSBASE 9 + +struct i386_iopl_args { + int iopl; +}; + +#ifdef _KERNEL +uint32_t i386_get_threadbase(struct proc *, int); +int i386_set_threadbase(struct proc *, uint32_t, int); +#else + +#include + +__BEGIN_DECLS +int i386_iopl(int); +int i386_get_fsbase(void **); +int i386_set_fsbase(void *); +int i386_get_gsbase(void **); +int i386_set_gsbase(void *); +int sysarch(int, void *); +__END_DECLS +#endif + +#endif /* !_MACHINE_SYSARCH_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/tcb.h b/lib/libc/include/x86-openbsd-none/i386/tcb.h new file mode 100644 index 0000000000..eb8003e260 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/tcb.h @@ -0,0 +1,51 @@ +/* $OpenBSD: tcb.h,v 1.4 2016/09/04 08:49:35 guenther Exp $ */ +/* + * Copyright (c) 2011 Philip Guenther + * + * 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 + +#include +#include + +#define TCB_GET(p) \ + ((void *)i386_get_threadbase(p, TSEG_GS)) +#define TCB_SET(p, addr) \ + i386_set_threadbase(p, (uint32_t)(addr), TSEG_GS) + +#else /* _KERNEL */ + +/* ELF TLS ABI calls for big TCB, with static TLS data at negative offsets */ +#define TLS_VARIANT 2 + +/* Read a slot from the TCB */ +static inline void * +__i386_read_tcb(int offset) +{ + void *val; + __asm__ ("movl %%gs:(%1),%0" : "=r" (val) : "r" (offset)); + return val; +} + +/* Get a pointer to the TCB itself */ +#define TCB_GET() __i386_read_tcb(0) + +/* Setting the TCB pointer can only be done via syscall, so no TCB_SET() */ + +#endif /* _KERNEL */ +#endif /* _MACHINE_TCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/timetc.h b/lib/libc/include/x86-openbsd-none/i386/timetc.h new file mode 100644 index 0000000000..9af8a41ca2 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/timetc.h @@ -0,0 +1,23 @@ +/* $OpenBSD: timetc.h,v 1.1 2020/07/06 13:33:07 pirofti Exp $ */ +/* + * Copyright (c) 2020 Paul Irofti + * + * 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_TIMETC_H_ +#define _MACHINE_TIMETC_H_ + +#define TC_LAST 0 + +#endif /* _MACHINE_TIMETC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/trap.h b/lib/libc/include/x86-openbsd-none/i386/trap.h new file mode 100644 index 0000000000..6a91b82f3e --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/trap.h @@ -0,0 +1,65 @@ +/* $OpenBSD: trap.h,v 1.6 2015/06/28 01:11:27 guenther Exp $ */ +/* $NetBSD: trap.h,v 1.4 1994/10/27 04:16:30 cgd 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. + * + * @(#)trap.h 5.4 (Berkeley) 5/9/91 + */ + +/* + * Trap type values + * also known in trap.c for name strings + */ + +#define T_PRIVINFLT 0 /* privileged instruction */ +#define T_BPTFLT 1 /* breakpoint trap */ +#define T_ARITHTRAP 2 /* arithmetic trap */ +#define T_RESERVED 3 /* reserved fault base */ +#define T_PROTFLT 4 /* protection fault */ +#define T_TRCTRAP 5 /* trace trap */ +#define T_PAGEFLT 6 /* page fault */ +#define T_ALIGNFLT 7 /* alignment fault */ +#define T_DIVIDE 8 /* integer divide fault */ +#define T_NMI 9 /* non-maskable interrupt */ +#define T_OFLOW 10 /* overflow trap */ +#define T_BOUND 11 /* bounds check fault */ +#define T_DNA 12 /* device not available fault */ +#define T_DOUBLEFLT 13 /* double fault */ +#define T_FPOPFLT 14 /* fp coprocessor operand fetch fault (![P]Pro)*/ +#define T_TSSFLT 15 /* invalid tss fault */ +#define T_SEGNPFLT 16 /* segment not present fault */ +#define T_STKFLT 17 /* stack fault */ +#define T_MACHK 18 /* machine check ([P]Pro) */ +#define T_XFTRAP 19 /* SIMD FP exception */ + +/* Trap's coming from user mode */ +#define T_USER 0x100 \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/tss.h b/lib/libc/include/x86-openbsd-none/i386/tss.h new file mode 100644 index 0000000000..d2e5f750b6 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/tss.h @@ -0,0 +1,74 @@ +/* $OpenBSD: tss.h,v 1.12 2018/06/22 13:21:14 bluhm Exp $ */ +/* $NetBSD: tss.h,v 1.6 1995/10/11 04:20:28 mycroft 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. + * + * @(#)tss.h 5.4 (Berkeley) 1/18/91 + */ + +#ifndef _MACHINE_TSS_H_ +#define _MACHINE_TSS_H_ + +/* + * Intel 386 Context Data Type + */ + +struct i386tss { + int __tss_link; + int tss_esp0; /* kernel stack pointer at privilege level 0 */ + int tss_ss0; /* kernel stack segment at privilege level 0 */ + int __tss_esp1; + int __tss_ss1; + int __tss_esp2; + int __tss_ss2; + int tss_cr3; + int tss_eip; + int tss_eflags; + int tss_eax; + int tss_ecx; + int tss_edx; + int tss_ebx; + int tss_esp; + int tss_ebp; + int tss_esi; + int tss_edi; + int tss_es; + int tss_cs; + int tss_ss; + int tss_ds; + int tss_fs; + int tss_gs; + int tss_ldt; + int tss_ioopt; /* options and I/O permission map offset */ +}; + +#endif /* _MACHINE_TSS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/vga_post.h b/lib/libc/include/x86-openbsd-none/i386/vga_post.h new file mode 100644 index 0000000000..7207b11c31 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/vga_post.h @@ -0,0 +1,43 @@ +/* $NetBSD: vga_post.h,v 1.2 2008/03/29 17:40:22 jmcneill Exp $ */ +/* $OpenBSD: vga_post.h,v 1.2 2011/03/23 16:54:35 pirofti Exp $ */ + +/*- + * Copyright (c) 2007 Joerg Sonnenberger . + * 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT HOLDERS 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_VGA_POST_H_ +#define _MACHINE_VGA_POST_H_ + +#ifdef _KERNEL +struct vga_post; + +struct vga_post *vga_post_init(int, int, int); +void vga_post_free(struct vga_post *); +void vga_post_call(struct vga_post *); +#endif +#endif \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/vmmvar.h b/lib/libc/include/x86-openbsd-none/i386/vmmvar.h new file mode 100644 index 0000000000..6528cb8102 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/vmmvar.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2014 Mike Larkin + * + * 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 VMM_HV_SIGNATURE "OpenBSDVMM58" \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/i386/vmparam.h b/lib/libc/include/x86-openbsd-none/i386/vmparam.h new file mode 100644 index 0000000000..3e7cc4f4bb --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/i386/vmparam.h @@ -0,0 +1,108 @@ +/* $OpenBSD: vmparam.h,v 1.57 2021/03/16 18:04:16 kurt Exp $ */ +/* $NetBSD: vmparam.h,v 1.15 1994/10/27 04:16:34 cgd 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. + * + * @(#)vmparam.h 5.9 (Berkeley) 5/12/91 + */ + +#ifndef _MACHINE_VMPARAM_H_ +#define _MACHINE_VMPARAM_H_ +/* + * Machine dependent constants for 386. + */ + +#define USRSTACK VM_MAXUSER_ADDRESS + +/* + * Virtual memory related constants, all in bytes + */ +#define MAXTSIZ (256*1024*1024) /* max text size */ +#ifndef DFLDSIZ +#define DFLDSIZ (64*1024*1024) /* initial data size limit */ +#endif +#ifndef MAXDSIZ +#define MAXDSIZ (3UL*1024*1024*1024) /* max data size */ +#endif +#ifndef BRKSIZ +#define BRKSIZ (128*1024*1024) /* heap gap size */ +#endif +#ifndef DFLSSIZ +#define DFLSSIZ (4*1024*1024) /* initial stack size limit */ +#endif +#ifndef MAXSSIZ +#define MAXSSIZ (32*1024*1024) /* max stack size */ +#endif + +#define STACKGAP_RANDOM 256*1024 + +/* I386 has a line where all code is executable: 0 - I386_MAX_EXE_ADDR */ +#define I386_MAX_EXE_ADDR 0x20000000 /* exec line */ + +/* map PIE into 320MB - 448MB address range */ +#define VM_PIE_MIN_ADDR 0x14000000 +#define VM_PIE_MAX_ADDR 0x1C000000 + +/* + * Size of shared memory map + */ +#ifndef SHMMAXPGS +#define SHMMAXPGS 8192 +#endif + +/* + * Size of User Raw I/O map + */ +#define USRIOSIZE 300 + +/* + * Specific addresses being unmapped and used as fillers for free memory. + */ +#define DEADBEEF0 0xefffeecc /* malloc's filler */ +#define DEADBEEF1 0xefffaabb /* pool's filler */ + +/* user/kernel map constants */ +#define VM_MIN_ADDRESS ((vaddr_t)PAGE_SIZE) +#define VM_MAXUSER_ADDRESS ((vaddr_t)((PDSLOT_PTE<= 3 +typedef __builtin_va_list __va_list; +#else +typedef char * __va_list; +#endif + +/* Wide character support types */ +#ifndef __cplusplus +typedef int __wchar_t; +#endif +typedef int __wint_t; +typedef int __rune_t; +typedef void * __wctrans_t; +typedef void * __wctype_t; + +#endif /* _MACHINE__TYPES_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/acpiapm.h b/lib/libc/include/x86-openbsd-none/machine/acpiapm.h new file mode 100644 index 0000000000..6921c56fd2 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/acpiapm.h @@ -0,0 +1,22 @@ +/* $OpenBSD: acpiapm.h,v 1.1 2007/11/25 15:45:17 tedu Exp $ */ +/* + * Copyright (c) 2007 Ted Unangst + * + * 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. + */ + + +extern int (*acpiapm_open)(dev_t, int, int, struct proc *); +extern int (*acpiapm_close)(dev_t, int, int, struct proc *); +extern int (*acpiapm_ioctl)(dev_t, u_long, caddr_t, int, struct proc *); +extern int (*acpiapm_kqfilter)(dev_t, struct knote *); \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/amdmsr.h b/lib/libc/include/x86-openbsd-none/machine/amdmsr.h new file mode 100644 index 0000000000..1a6027a5a3 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/amdmsr.h @@ -0,0 +1,34 @@ +/* $OpenBSD: amdmsr.h,v 1.4 2011/03/23 16:54:35 pirofti Exp $ */ + +/* + * Copyright (c) 2008 Marc Balmer + * + * 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_AMDMSR_H_ +#define _MACHINE_AMDMSR_H_ + +struct amdmsr_req { + u_int32_t addr; /* 32-bit MSR address */ + u_int64_t val; /* 64-bit MSR value */ +}; + +#define RDMSR _IOWR('M', 0, struct amdmsr_req) +#define WRMSR _IOW('M', 1, struct amdmsr_req) + +#ifdef _KERNEL +int amdmsr_probe(void); +#endif + +#endif /* !_MACHINE_AMDMSR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/apicvar.h b/lib/libc/include/x86-openbsd-none/machine/apicvar.h new file mode 100644 index 0000000000..754f54465e --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/apicvar.h @@ -0,0 +1,54 @@ +/* $OpenBSD: apicvar.h,v 1.7 2025/09/05 16:57:48 kettenis Exp $ */ +/* $NetBSD: apicvar.h,v 1.1.2.3 2000/02/27 20:25:00 sommerfeld Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by RedBack Networks Inc. + * + * Author: Bill Sommerfeld + * + * 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_APICVAR_H_ +#define _MACHINE_APICVAR_H_ + +#include + +struct apic_attach_args { + const char *aaa_name; + int apic_id; + int apic_version; + int flags; +#define IOAPIC_PICMODE 0x01 +#define IOAPIC_VWIRE 0x02 + bus_space_tag_t apic_memt; + bus_addr_t apic_address; + int apic_vecbase; +}; + +void apic_format_redir(char *, char *, int, u_int32_t, u_int32_t); + +#endif /* !_MACHINE_APICVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/apmvar.h b/lib/libc/include/x86-openbsd-none/machine/apmvar.h new file mode 100644 index 0000000000..4d29641e7a --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/apmvar.h @@ -0,0 +1,303 @@ +/* $OpenBSD: apmvar.h,v 1.22 2019/01/22 02:36:30 phessler Exp $ */ + +/* + * Copyright (c) 1995 John T. Kohl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef _MACHINE_APMVAR_H_ +#define _MACHINE_APMVAR_H_ + +#include + +/* Advanced Power Management (v1.0 and v1.1 specification) + * functions/defines/etc. + */ + +#define APM_VERSION 0x0102 + +/* + * APM info word from boot loader + */ +#define APM_16BIT_SUPPORTED 0x00010000 +#define APM_32BIT_SUPPORTED 0x00020000 +#define APM_IDLE_SLOWS 0x00040000 +#define APM_BIOS_PM_DISABLED 0x00080000 +#define APM_BIOS_PM_DISENGAGED 0x00100000 +#define APM_MAJOR(f) (((f) >> 8) & 0xff) +#define APM_MINOR(f) ((f) & 0xff) +#define APM_VERMASK 0x0000ffff +#define APM_NOCLI 0x00010000 +#define APM_BEBATT 0x00020000 + +/* APM error codes */ +#define APM_ERR_CODE(regs) (((regs)->ax & 0xff00) >> 8) +#define APM_ERR_PM_DISABLED 0x01 +#define APM_ERR_REALALREADY 0x02 +#define APM_ERR_NOTCONN 0x03 +#define APM_ERR_16ALREADY 0x05 +#define APM_ERR_16NOTSUPP 0x06 +#define APM_ERR_32ALREADY 0x07 +#define APM_ERR_32NOTSUPP 0x08 +#define APM_ERR_UNRECOG_DEV 0x09 +#define APM_ERR_ERANGE 0x0A +#define APM_ERR_NOTENGAGED 0x0B +#define APM_ERR_EOPNOSUPP 0x0C +#define APM_ERR_RTIMER_DISABLED 0x0D +#define APM_ERR_UNABLE 0x60 +#define APM_ERR_NOEVENTS 0x80 +#define APM_ERR_NOT_PRESENT 0x86 + +#define APM_DEV_APM_BIOS 0x0000 +#define APM_DEV_ALLDEVS 0x0001 +/* device classes are high byte; device IDs go in low byte */ +#define APM_DEV_DISPLAY(x) (0x0100|((x)&0xff)) +#define APM_DEV_DISK(x) (0x0200|((x)&0xff)) +#define APM_DEV_PARALLEL(x) (0x0300|((x)&0xff)) +#define APM_DEV_SERIAL(x) (0x0400|((x)&0xff)) +#define APM_DEV_NETWORK(x) (0x0500|((x)&0xff)) +#define APM_DEV_PCMCIA(x) (0x0600|((x)&0xff)) +#define APM_DEV_BATTERIES(x) (0x8000|((x)&0xff)) +#define APM_DEV_ALLUNITS 0xff +/* 0x8100-0xDFFF - reserved */ +/* 0xE000-0xEFFF - OEM-defined */ +/* 0xF000-0xFFFF - reserved */ + +#define APM_INSTCHECK 0x5300 /* int15 only */ +#define APM_16BIT_SUPPORT 0x01 +#define APM_32BIT_SUPPORT 0x02 +#define APM_CPUIDLE_SLOW 0x04 +#define APM_DISABLED 0x08 +#define APM_DISENGAGED 0x10 + +#define APM_REAL_CONNECT 0x5301 /* int15 only */ +#define APM_PROT16_CONNECT 0x5302 /* int15 only */ +#define APM_PROT32_CONNECT 0x5303 /* int15 only */ +#define APM_DISCONNECT 0x5304 /* %bx = APM_DEV_APM_BIOS */ + +#define APM_CPU_IDLE 0x5305 +#define APM_CPU_BUSY 0x5306 + +#define APM_SET_PWR_STATE 0x5307 +#define APM_SYS_READY 0x0000 /* %cx */ +#define APM_SYS_STANDBY 0x0001 +#define APM_SYS_SUSPEND 0x0002 +#define APM_SYS_OFF 0x0003 +#define APM_LASTREQ_INPROG 0x0004 +#define APM_LASTREQ_REJECTED 0x0005 +/* 0x0006 - 0x001f Reserved system states */ +/* 0x0020 - 0x003f OEM-defined system states */ +/* 0x0040 - 0x007f OEM-defined device states */ +/* 0x0080 - 0xffff Reserved device states */ + +/* system standby is device ID (%bx) 0x0001, APM_SYS_STANDBY */ +/* system suspend is device ID (%bx) 0x0001, APM_SYS_SUSPEND */ + +#define APM_PWR_MGT_ENABLE 0x5308 +#define APM_MGT_ALL 0xffff /* %bx */ +#define APM_MGT_DISABLE 0x0 /* %cx */ +#define APM_MGT_ENABLE 0x1 + +#define APM_SYSTEM_DEFAULTS 0x5309 +#define APM_DEFAULTS_ALL 0xffff /* %bx */ + +#define APM_POWER_STATUS 0x530a +#define APM_AC_OFF 0x00 +#define APM_AC_ON 0x01 +#define APM_AC_BACKUP 0x02 +#define APM_AC_UNKNOWN 0xff +#define APM_BATT_HIGH 0x00 +#define APM_BATT_LOW 0x01 +#define APM_BATT_CRITICAL 0x02 +#define APM_BATT_CHARGING 0x03 +#define APM_BATT_UNKNOWN 0xff +#define APM_BATT_FLAG_HIGH 0x01 +#define APM_BATT_FLAG_LOW 0x02 +#define APM_BATT_FLAG_CRITICAL 0x04 +#define APM_BATT_FLAG_CHARGING 0x08 +#define APM_BATT_FLAG_NOBATTERY 0x10 +#define APM_BATT_FLAG_NOSYSBATT 0x80 +#define APM_BATT_LIFE_UNKNOWN 0xff +#define BATT_STATE(regp) ((regp)->bx & 0xff) +#define BATT_FLAGS(regp) (((regp)->cx & 0xff00) >> 8) +#define AC_STATE(regp) (((regp)->bx & 0xff00) >> 8) +#define BATT_LIFE(regp) ((regp)->cx & 0xff) /* in % */ +/* Return time in minutes. According to the APM 1.2 spec: + DX = Remaining battery life -- time units + Bit 15 = 0 Time units are seconds + = 1 Time units are minutes + Bits 14-0 = Number of seconds or minutes */ +#define BATT_REMAINING(regp) (((regp)->dx & 0x8000) ? \ + ((regp)->dx & 0x7fff) : \ + ((regp)->dx & 0x7fff)/60) +#define BATT_REM_VALID(regp) (((regp)->dx & 0xffff) != 0xffff) +#define BATT_COUNT(regp) ((regp)->si) + +#define APM_GET_PM_EVENT 0x530b +#define APM_NOEVENT 0x0000 +#define APM_STANDBY_REQ 0x0001 /* %bx on return */ +#define APM_SUSPEND_REQ 0x0002 +#define APM_NORMAL_RESUME 0x0003 +#define APM_CRIT_RESUME 0x0004 /* suspend/resume happened + without us */ +#define APM_BATTERY_LOW 0x0005 +#define APM_POWER_CHANGE 0x0006 +#define APM_UPDATE_TIME 0x0007 +#define APM_CRIT_SUSPEND_REQ 0x0008 +#define APM_USER_STANDBY_REQ 0x0009 +#define APM_USER_SUSPEND_REQ 0x000A +#define APM_SYS_STANDBY_RESUME 0x000B +#define APM_CAPABILITY_CHANGE 0x000C /* apm v1.2 */ +/* 0x000d - 0x00ff Reserved system events */ +#define APM_USER_HIBERNATE_REQ 0x000D +/* 0x0100 - 0x01ff Reserved device events */ +/* 0x0200 - 0x02ff OEM-defined APM events */ +/* 0x0300 - 0xffff Reserved */ +#define APM_EVENT_MASK 0xffff + +#define APM_EVENT_COMPOSE(t,i) ((((i) & 0x7fff) << 16)|((t) & APM_EVENT_MASK)) +#define APM_EVENT_TYPE(e) ((e) & APM_EVENT_MASK) +#define APM_EVENT_INDEX(e) ((e) >> 16) + +#define APM_GET_POWER_STATE 0x530c +#define APM_DEVICE_MGMT_ENABLE 0x530d + +#define APM_DRIVER_VERSION 0x530e +/* %bx should be DEV value (APM_DEV_APM_BIOS) + %ch = driver major vno + %cl = driver minor vno + return: %ah = conn major; %al = conn minor + */ +#define APM_CONN_MINOR(regp) ((regp)->ax & 0xff) +#define APM_CONN_MAJOR(regp) (((regp)->ax & 0xff00) >> 8) + +#define APM_PWR_MGT_ENGAGE 0x530F +#define APM_MGT_DISENGAGE 0x0 /* %cx */ +#define APM_MGT_ENGAGE 0x1 + +/* %bx - APM_DEV_APM_BIOS + * %bl - number of batteries + * %cx - capabilities + */ +#define APM_GET_CAPABILITIES 0x5310 +#define APM_NBATTERIES(regp) ((regp)->bx) +#define APM_GLOBAL_STANDBY 0x0001 +#define APM_GLOBAL_SUSPEND 0x0002 +#define APM_RTIMER_STANDBY 0x0004 /* resume time wakes up */ +#define APM_RTIMER_SUSPEND 0x0008 +#define APM_IRRING_STANDBY 0x0010 /* internal ring wakes up */ +#define APM_IRRING_SUSPEND 0x0020 +#define APM_PCCARD_STANDBY 0x0040 /* pccard wakes up */ +#define APM_PCCARD_SUSPEND 0x0080 + +/* %bx - APM_DEV_APM_BIOS + * %cl - function + * for %cl=2 (set resume timer) + * %ch - seconds in BCD + * %dh - hours in BCD + * %dl - minutes in BCD + * %si - month in BCD (high), day in BCD (low) + * %di - year in BCD + */ +#define APM_RESUME_TIMER 0x5311 +#define APM_RT_DISABLE 0x0 +#define APM_RT_GET 0x1 +#define APM_RT_SET 0x2 + +/* %bx - APM_DEV_APM_BIOS + * %cx - function + */ +#define APM_RESUME_ON_RING 0x5312 +#define APM_ROR_DISABLE 0x0 +#define APM_ROR_ENABLE 0x1 +#define APM_ROR_STATUS 0x2 + +/* %bx - APM_EDV_APM_BIOS + * %cx - function + */ +#define APM_INACTIVITY_TIMER 0x5313 +#define APM_IT_DISABLE 0x0 +#define APM_IT_ENABLE 0x1 +#define APM_IT_STATUS 0x2 + +/* %bh - function */ +#define APM_OEM 0x5380 +#define APM_OEM_INSTCHECK 0x7f /* %bx - OEM ID */ + +/* + * LP (Laptop Package) + * + * Copyright (C) 1994 by HOSOKAWA Tatsumi + * + * This software may be used, modified, copied, and distributed, in + * both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + */ + +#define APM_BATTERY_ABSENT 4 + +struct apm_power_info { + u_char battery_state; + u_char ac_state; + u_char battery_life; + u_char spare1; + u_int minutes_left; /* estimate */ + u_int spare2[6]; +}; + +struct apm_ctl { + u_int dev; + u_int mode; +}; + +#define APM_IOC_REJECT _IOW('A', 0, struct apm_event_info) /* reject request # */ +#define APM_IOC_STANDBY _IO('A', 1) /* put system into standby */ +#define APM_IOC_SUSPEND _IO('A', 2) /* put system into suspend */ +#define APM_IOC_GETPOWER _IOR('A', 3, struct apm_power_info) /* fetch battery state */ +#define APM_IOC_DEV_CTL _IOW('A', 5, struct apm_ctl) /* put device into mode */ +#define APM_IOC_PRN_CTL _IOW('A', 6, int ) /* driver power status msg */ +#define APM_PRINT_ON 0 /* driver power status displayed */ +#define APM_PRINT_OFF 1 /* driver power status not displayed */ +#define APM_PRINT_PCT 2 /* driver power status only displayed + if the percentage changes */ +#define APM_IOC_STANDBY_REQ _IO('A', 7) /* request standby */ +#define APM_IOC_SUSPEND_REQ _IO('A', 8) /* request suspend */ +#define APM_IOC_HIBERNATE _IO('A', 9) /* put system into hibernate */ + + +#ifdef _KERNEL +extern void apm_cpu_busy(void); +extern void apm_cpu_idle(void); +extern void apminit(void); +int apm_set_powstate(u_int devid, u_int powstate); +#endif /* _KERNEL */ + +#endif /* _MACHINE_APMVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/asm.h b/lib/libc/include/x86-openbsd-none/machine/asm.h new file mode 100644 index 0000000000..c5b22ef4f4 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/asm.h @@ -0,0 +1,131 @@ +/* $OpenBSD: asm.h,v 1.19 2022/12/08 01:25:45 guenther Exp $ */ +/* $NetBSD: asm.h,v 1.7 1994/10/27 04:15:56 cgd 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. + * + * @(#)asm.h 5.5 (Berkeley) 5/7/91 + */ + +#ifndef _MACHINE_ASM_H_ +#define _MACHINE_ASM_H_ + +#ifdef __PIC__ +#define PIC_PROLOGUE \ + pushl %ebx; \ + call 666f; \ +666: \ + popl %ebx; \ + addl $_GLOBAL_OFFSET_TABLE_+[.-666b], %ebx +#define PIC_EPILOGUE \ + popl %ebx +#define PIC_PLT(x) x@PLT +#define PIC_GOT(x) x@GOT(%ebx) +#define PIC_GOTOFF(x) x@GOTOFF(%ebx) +#else +#define PIC_PROLOGUE +#define PIC_EPILOGUE +#define PIC_PLT(x) x +#define PIC_GOT(x) x +#define PIC_GOTOFF(x) x +#endif + +#define _C_LABEL(name) name +#define _ASM_LABEL(x) x + +#define CVAROFF(x, y) x + y + +#ifdef __STDC__ +# define __CONCAT(x,y) x ## y +# define __STRING(x) #x +#else +# define __CONCAT(x,y) x/**/y +# define __STRING(x) "x" +#endif + +/* + * STRONG_ALIAS, WEAK_ALIAS + * Create a strong or weak alias. + */ +#define STRONG_ALIAS(alias,sym) \ + .global alias; \ + alias = sym +#define WEAK_ALIAS(alias,sym) \ + .weak alias; \ + alias = sym + +/* let kernels and others override entrypoint alignment */ +#ifndef _ALIGN_TEXT +# define _ALIGN_TEXT .align 2, 0x90 +#endif + +/* NB == No Binding: use .globl or .weak as necessary */ +#define _ENTRY_NB(x) \ + .text; _ALIGN_TEXT; .type x,@function; x: +#define _ENTRY(x) .globl x; _ENTRY_NB(x) + +#ifdef _KERNEL +#define KUTEXT .section .kutext, "ax" + +#define IDTVEC(name) \ + KUTEXT; ALIGN_TEXT; \ + .globl X##name; X##name: +#define KIDTVEC(name) \ + .text; ALIGN_TEXT; \ + .globl X##name; X##name: +#define KUENTRY(x) \ + KUTEXT; _ALIGN_TEXT; .globl x; .type x,@function; x: + +#endif /* _KERNEL */ + +#if defined(PROF) || defined(GPROF) +# define _PROF_PROLOGUE \ + pushl %ebp; movl %esp,%ebp; call PIC_PLT(mcount); popl %ebp +#else +# define _PROF_PROLOGUE +#endif + +#define ENTRY(y) _ENTRY(y); _PROF_PROLOGUE +#define ENTRY_NB(y) _ENTRY_NB(y); _PROF_PROLOGUE +#define NENTRY(y) _ENTRY(y) +#define ASENTRY(y) _ENTRY(y); _PROF_PROLOGUE +#define NASENTRY(y) _ENTRY(y) +#define END(y) .size y, . - y + +#define ALTENTRY(name) .globl name; name: + +#ifdef _KERNEL + +#define CPUVAR(var) %fs:__CONCAT(CPU_INFO_,var) + +#endif /* _KERNEL */ + +#endif /* !_MACHINE_ASM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/atomic.h b/lib/libc/include/x86-openbsd-none/machine/atomic.h new file mode 100644 index 0000000000..ef6a8301b4 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/atomic.h @@ -0,0 +1,316 @@ +/* $OpenBSD: atomic.h,v 1.20 2022/08/29 02:01:18 jsg Exp $ */ +/* $NetBSD: atomic.h,v 1.1.2.2 2000/02/21 18:54:07 sommerfeld Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by RedBack Networks Inc. + * + * Author: Bill Sommerfeld + * + * 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_ATOMIC_H_ +#define _MACHINE_ATOMIC_H_ + +/* + * Perform atomic operations on memory. Should be atomic with respect + * to interrupts and multiple processors. + * + * void atomic_setbits_int(volatile u_int *a, u_int mask) { *a |= mask; } + * void atomic_clearbits_int(volatile u_int *a, u_int mas) { *a &= ~mask; } + */ +#if !defined(_LOCORE) + +#if defined(MULTIPROCESSOR) || !defined(_KERNEL) +#define _LOCK "lock" +#else +#define _LOCK +#endif + +static inline unsigned int +_atomic_cas_uint(volatile unsigned int *p, unsigned int e, unsigned int n) +{ + __asm volatile(_LOCK " cmpxchgl %2, %1" + : "=a" (n), "=m" (*p) + : "r" (n), "a" (e), "m" (*p)); + + return (n); +} +#define atomic_cas_uint(_p, _e, _n) _atomic_cas_uint((_p), (_e), (_n)) + +static inline unsigned long +_atomic_cas_ulong(volatile unsigned long *p, unsigned long e, unsigned long n) +{ + __asm volatile(_LOCK " cmpxchgl %2, %1" + : "=a" (n), "=m" (*p) + : "r" (n), "a" (e), "m" (*p)); + + return (n); +} +#define atomic_cas_ulong(_p, _e, _n) _atomic_cas_ulong((_p), (_e), (_n)) + +static inline void * +_atomic_cas_ptr(volatile void *p, void *e, void *n) +{ + __asm volatile(_LOCK " cmpxchgl %2, %1" + : "=a" (n), "=m" (*(unsigned long *)p) + : "r" (n), "a" (e), "m" (*(unsigned long *)p)); + + return (n); +} +#define atomic_cas_ptr(_p, _e, _n) _atomic_cas_ptr((_p), (_e), (_n)) + +static inline unsigned int +_atomic_swap_uint(volatile unsigned int *p, unsigned int n) +{ + __asm volatile("xchgl %0, %1" + : "=a" (n), "=m" (*p) + : "0" (n), "m" (*p)); + + return (n); +} +#define atomic_swap_uint(_p, _n) _atomic_swap_uint((_p), (_n)) +#define atomic_swap_32(_p, _n) _atomic_swap_uint((_p), (_n)) + +static inline unsigned long +_atomic_swap_ulong(volatile unsigned long *p, unsigned long n) +{ + __asm volatile("xchgl %0, %1" + : "=a" (n), "=m" (*p) + : "0" (n), "m" (*p)); + + return (n); +} +#define atomic_swap_ulong(_p, _n) _atomic_swap_ulong((_p), (_n)) + +static inline void * +_atomic_swap_ptr(volatile void *p, void *n) +{ + __asm volatile("xchgl %0, %1" + : "=a" (n), "=m" (*(unsigned long *)p) + : "0" (n), "m" (*(unsigned long *)p)); + + return (n); +} +#define atomic_swap_ptr(_p, _n) _atomic_swap_ptr((_p), (_n)) + +static inline void +_atomic_inc_int(volatile unsigned int *p) +{ + __asm volatile(_LOCK " incl %0" + : "+m" (*p)); +} +#define atomic_inc_int(_p) _atomic_inc_int(_p) + +static inline void +_atomic_inc_long(volatile unsigned long *p) +{ + __asm volatile(_LOCK " incl %0" + : "+m" (*p)); +} +#define atomic_inc_long(_p) _atomic_inc_long(_p) + +static inline void +_atomic_dec_int(volatile unsigned int *p) +{ + __asm volatile(_LOCK " decl %0" + : "+m" (*p)); +} +#define atomic_dec_int(_p) _atomic_dec_int(_p) + +static inline void +_atomic_dec_long(volatile unsigned long *p) +{ + __asm volatile(_LOCK " decl %0" + : "+m" (*p)); +} +#define atomic_dec_long(_p) _atomic_dec_long(_p) + +static inline void +_atomic_add_int(volatile unsigned int *p, unsigned int v) +{ + __asm volatile(_LOCK " addl %1,%0" + : "+m" (*p) + : "a" (v)); +} +#define atomic_add_int(_p, _v) _atomic_add_int(_p, _v) + +static inline void +_atomic_add_long(volatile unsigned long *p, unsigned long v) +{ + __asm volatile(_LOCK " addl %1,%0" + : "+m" (*p) + : "a" (v)); +} +#define atomic_add_long(_p, _v) _atomic_add_long(_p, _v) + +static inline void +_atomic_sub_int(volatile unsigned int *p, unsigned int v) +{ + __asm volatile(_LOCK " subl %1,%0" + : "+m" (*p) + : "a" (v)); +} +#define atomic_sub_int(_p, _v) _atomic_sub_int(_p, _v) + +static inline void +_atomic_sub_long(volatile unsigned long *p, unsigned long v) +{ + __asm volatile(_LOCK " subl %1,%0" + : "+m" (*p) + : "a" (v)); +} +#define atomic_sub_long(_p, _v) _atomic_sub_long(_p, _v) + + +static inline unsigned long +_atomic_add_int_nv(volatile unsigned int *p, unsigned int v) +{ + unsigned int rv = v; + + __asm volatile(_LOCK " xaddl %0,%1" + : "+a" (rv), "+m" (*p)); + + return (rv + v); +} +#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 = v; + + __asm volatile(_LOCK " xaddl %0,%1" + : "+a" (rv), "+m" (*p)); + + return (rv + v); +} +#define atomic_add_long_nv(_p, _v) _atomic_add_long_nv(_p, _v) + +static inline unsigned long +_atomic_sub_int_nv(volatile unsigned int *p, unsigned int v) +{ + unsigned int rv = 0 - v; + + __asm volatile(_LOCK " xaddl %0,%1" + : "+a" (rv), "+m" (*p)); + + return (rv - v); +} +#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 = 0 - v; + + __asm volatile(_LOCK " xaddl %0,%1" + : "+a" (rv), "+m" (*p)); + + return (rv - v); +} +#define atomic_sub_long_nv(_p, _v) _atomic_sub_long_nv(_p, _v) + +/* + * The IA-32 architecture is rather strongly ordered. When accessing + * normal write-back cacheable memory, only reads may be reordered with + * older writes to different locations. There are a few instructions + * (clfush, non-temporal move instructions) that obey weaker ordering + * rules, but those instructions will only be used in (inline) + * assembly code where we can add the necessary fence instructions + * ourselves. + */ + +#define __membar(_f) do { __asm volatile(_f ::: "memory"); } while (0) + +#if defined(MULTIPROCESSOR) || !defined(_KERNEL) +#define membar_enter() __membar("lock; addl $0,0(%%esp)") +#define membar_exit() __membar("") +#define membar_producer() __membar("") +#define membar_consumer() __membar("") +#define membar_sync() __membar("lock; addl $0,0(%%esp)") +#else +#define membar_enter() __membar("") +#define membar_exit() __membar("") +#define membar_producer() __membar("") +#define membar_consumer() __membar("") +#define membar_sync() __membar("") +#endif + +#define membar_enter_after_atomic() __membar("") +#define membar_exit_before_atomic() __membar("") + +#ifdef _KERNEL + +/* virtio needs MP membars even on SP kernels */ +#define virtio_membar_producer() __membar("") +#define virtio_membar_consumer() __membar("") +#define virtio_membar_sync() __membar("lock; addl $0,0(%%esp)") + +static __inline u_int64_t +i386_atomic_testset_uq(volatile u_int64_t *ptr, u_int64_t val) +{ + __asm__ volatile ("\n1:\t" _LOCK " cmpxchg8b (%1); jnz 1b" : "+A" (val) : + "r" (ptr), "b" ((u_int32_t)val), "c" ((u_int32_t)(val >> 32))); + return val; +} + +static __inline u_int32_t +i386_atomic_testset_ul(volatile u_int32_t *ptr, unsigned long val) +{ + __asm__ volatile ("xchgl %0,(%2)" :"=r" (val):"0" (val),"r" (ptr)); + return val; +} + +static __inline int +i386_atomic_testset_i(volatile int *ptr, unsigned long val) +{ + __asm__ volatile ("xchgl %0,(%2)" :"=r" (val):"0" (val),"r" (ptr)); + return val; +} + +static __inline void +i386_atomic_setbits_l(volatile u_int32_t *ptr, unsigned long bits) +{ + __asm volatile(_LOCK " orl %1,%0" : "=m" (*ptr) : "ir" (bits)); +} + +static __inline void +i386_atomic_clearbits_l(volatile u_int32_t *ptr, unsigned long bits) +{ + bits = ~bits; + __asm volatile(_LOCK " andl %1,%0" : "=m" (*ptr) : "ir" (bits)); +} + +#define atomic_setbits_int i386_atomic_setbits_l +#define atomic_clearbits_int i386_atomic_clearbits_l + +#endif /* _KERNEL */ + +#undef _LOCK + +#endif /* !defined(_LOCORE) */ +#endif /* _MACHINE_ATOMIC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/biosvar.h b/lib/libc/include/x86-openbsd-none/machine/biosvar.h new file mode 100644 index 0000000000..db9769bb7c --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/biosvar.h @@ -0,0 +1,306 @@ +/* $OpenBSD: biosvar.h,v 1.68 2019/08/04 14:28:58 kettenis Exp $ */ + +/* + * Copyright (c) 1997-1999 Michael Shalayeff + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MACHINE_BIOSVAR_H_ +#define _MACHINE_BIOSVAR_H_ + + /* some boxes put apm data seg in the 2nd page */ +#define BOOTARG_OFF (PAGE_SIZE * 2) +#define BOOTARG_LEN (PAGE_SIZE * 1) +#define BOOTBIOS_ADDR (0x7c00) +#define BOOTBIOS_MAXSEC ((1 << 28) - 1) + + /* BIOS configure flags */ +#define BIOSF_BIOS32 0x0001 +#define BIOSF_PCIBIOS 0x0002 +#define BIOSF_PROMSCAN 0x0004 +#define BIOSF_SMBIOS 0x0008 + +/* BIOS media ID */ +#define BIOSM_F320K 0xff /* floppy ds/sd 8 spt */ +#define BIOSM_F160K 0xfe /* floppy ss/sd 8 spt */ +#define BIOSM_F360K 0xfd /* floppy ds/sd 9 spt */ +#define BIOSM_F180K 0xfc /* floppy ss/sd 9 spt */ +#define BIOSM_ROMD 0xfa /* ROM disk */ +#define BIOSM_F120M 0xf9 /* floppy ds/hd 15 spt 5.25" */ +#define BIOSM_F720K 0xf9 /* floppy ds/dd 9 spt 3.50" */ +#define BIOSM_HD 0xf8 /* hard drive */ +#define BIOSM_F144K 0xf0 /* floppy ds/hd 18 spt 3.50" */ +#define BIOSM_OTHER 0xf0 /* any other */ + +/* + * BIOS memory maps + */ +#define BIOS_MAP_END 0x00 /* End of array XXX - special */ +#define BIOS_MAP_FREE 0x01 /* Usable memory */ +#define BIOS_MAP_RES 0x02 /* Reserved memory */ +#define BIOS_MAP_ACPI 0x03 /* ACPI Reclaim memory */ +#define BIOS_MAP_NVS 0x04 /* ACPI NVS memory */ + +/* + * Optional ROM header + */ +typedef +struct bios_romheader { + uint16_t signature; /* 0xaa55 */ + uint8_t len; /* length in pages (512 bytes) */ + uint32_t entry; /* initialization entry point */ + uint8_t reserved[19]; + uint16_t pnpheader; /* offset to PnP expansion header */ +} __packed *bios_romheader_t; + +/* + * BIOS32 + */ +typedef +struct bios32_header { + uint32_t signature; /* 00: signature "_32_" */ + uint32_t entry; /* 04: entry point */ + uint8_t rev; /* 08: revision */ + uint8_t length; /* 09: header length */ + uint8_t cksum; /* 0a: modulo 256 checksum */ + uint8_t reserved[5]; +} __packed *bios32_header_t; + +typedef +struct bios32_entry_info { + uint32_t bei_base; + uint32_t bei_size; + uint32_t bei_entry; +} __packed *bios32_entry_info_t; + +typedef +struct bios32_entry { + uint32_t offset; + uint16_t segment; +} __packed *bios32_entry_t; + +#define BIOS32_START 0xe0000 +#define BIOS32_SIZE 0x20000 +#define BIOS32_END (BIOS32_START + BIOS32_SIZE - 0x10) + +#define BIOS32_MAKESIG(a, b, c, d) \ + ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24)) +#define BIOS32_SIGNATURE BIOS32_MAKESIG('_', '3', '2', '_') +#define PCIBIOS_SIGNATURE BIOS32_MAKESIG('$', 'P', 'C', 'I') +#define SMBIOS_SIGNATURE BIOS32_MAKESIG('_', 'S', 'M', '_') + +/* + * CTL_BIOS definitions. + */ +#define BIOS_DEV 1 /* int: BIOS boot device */ +#define BIOS_DISKINFO 2 /* struct: BIOS boot device info */ +#define BIOS_CKSUMLEN 3 /* int: disk cksum block count */ +#define BIOS_MAXID 4 /* number of valid machdep ids */ + +#define CTL_BIOS_NAMES { \ + { 0, 0 }, \ + { "biosdev", CTLTYPE_INT }, \ + { "diskinfo", CTLTYPE_STRUCT }, \ + { "cksumlen", CTLTYPE_INT }, \ +} + +#define BOOTARG_MEMMAP 0 +typedef struct _bios_memmap { + uint64_t addr; /* Beginning of block */ + uint64_t size; /* Size of block */ + uint32_t type; /* Type of block */ +} __packed bios_memmap_t; + +/* Info about disk from the bios, plus the mapping from + * BIOS numbers to BSD major (driver?) number. + * + * Also, do not bother with BIOSN*() macros, just parcel + * the info out, and use it like this. This makes for less + * of a dependence on BIOSN*() macros having to be the same + * across /boot, /bsd, and userland. + */ +#define BOOTARG_DISKINFO 1 +typedef struct _bios_diskinfo { + /* BIOS section */ + int bios_number; /* BIOS number of drive (or -1) */ + u_int bios_cylinders; /* BIOS cylinders */ + u_int bios_heads; /* BIOS heads */ + u_int bios_sectors; /* BIOS sectors */ + int bios_edd; /* EDD support */ + + /* BSD section */ + dev_t bsd_dev; /* BSD device */ + + /* Checksum section */ + uint32_t checksum; /* Checksum for drive */ + + /* Misc. flags */ + uint32_t flags; +#define BDI_INVALID 0x00000001 /* I/O error during checksumming */ +#define BDI_GOODLABEL 0x00000002 /* Had SCSI or ST506/ESDI disklabel */ +#define BDI_BADLABEL 0x00000004 /* Had another disklabel */ +#define BDI_EL_TORITO 0x00000008 /* 2,048-byte sectors */ +#define BDI_HIBVALID 0x00000010 /* hibernate signature valid */ +#define BDI_PICKED 0x80000000 /* kernel-only: cksum matched */ + +} __packed bios_diskinfo_t; + +#define BOOTARG_APMINFO 2 +typedef struct _bios_apminfo { + /* APM_CONNECT returned values */ + u_int apm_detail; + u_int apm_code32_base; + u_int apm_code16_base; + u_int apm_code_len; + u_int apm_data_base; + u_int apm_data_len; + u_int apm_entry; + u_int apm_code16_len; +} __packed bios_apminfo_t; + +#define BOOTARG_CKSUMLEN 3 /* uint32_t */ + +#define BOOTARG_PCIINFO 4 +typedef struct _bios_pciinfo { + /* PCI BIOS v2.0+ - Installation check values */ + uint32_t pci_chars; /* Characteristics (%eax) */ + uint32_t pci_rev; /* BCD Revision (%ebx) */ + uint32_t pci_entry32; /* PM entry point for PCI BIOS */ + uint32_t pci_lastbus; /* Number of last PCI bus */ +} __packed bios_pciinfo_t; + +#define BOOTARG_CONSDEV 5 +typedef struct _bios_consdev { + dev_t consdev; + int conspeed; + int consaddr; + int consfreq; +} __packed bios_consdev_t; + +#define BOOTARG_SMPINFO 6 /* struct mp_float[] */ + +#define BOOTARG_BOOTMAC 7 +typedef struct _bios_bootmac { + char mac[6]; +} __packed bios_bootmac_t; + +#define BOOTARG_DDB 8 +typedef struct _bios_ddb { + int db_console; +} __packed bios_ddb_t; + +#define BOOTARG_BOOTDUID 9 +typedef struct _bios_bootduid { + u_char duid[8]; +} __packed bios_bootduid_t; + +#define BOOTARG_BOOTSR 10 +#define BOOTSR_UUID_MAX 16 +#define BOOTSR_CRYPTO_MAXKEYBYTES 32 +typedef struct _bios_bootsr { + uint8_t uuid[BOOTSR_UUID_MAX]; + uint8_t maskkey[BOOTSR_CRYPTO_MAXKEYBYTES]; +} __packed bios_bootsr_t; + +#define BOOTARG_EFIINFO 11 +typedef struct _bios_efiinfo { + uint64_t config_acpi; + uint64_t config_smbios; + uint64_t fb_addr; + uint64_t fb_size; + uint32_t fb_height; + uint32_t fb_width; + uint32_t fb_pixpsl; /* pixels per scan line */ + uint32_t fb_red_mask; + uint32_t fb_green_mask; + uint32_t fb_blue_mask; + uint32_t fb_reserved_mask; +} __packed bios_efiinfo_t; + +#define BOOTARG_UCODE 12 +typedef struct _bios_ucode { + uint64_t uc_addr; + uint64_t uc_size; +} __packed bios_ucode_t; + +#if defined(_KERNEL) || defined (_STANDALONE) + +#ifdef _LOCORE +#define DOINT(n) int $0x20+(n) +#else +#define DOINT(n) "int $0x20+(" #n ")" + +extern volatile struct BIOS_regs { + uint32_t biosr_ax; + uint32_t biosr_cx; + uint32_t biosr_dx; + uint32_t biosr_bx; + uint32_t biosr_bp; + uint32_t biosr_si; + uint32_t biosr_di; + uint32_t biosr_ds; + uint32_t biosr_es; +} __packed BIOS_regs; + +#ifdef _KERNEL +#include + +struct bios_attach_args { + char *ba_name; + u_int ba_func; + bus_space_tag_t ba_iot; + bus_space_tag_t ba_memt; + union { + void *_p; + bios_apminfo_t *_ba_apmp; + paddr_t _ba_acpipbase; + } _; +}; + +#define ba_apmp _._ba_apmp +#define ba_acpipbase _._ba_acpipbase + +struct consdev; +struct proc; + +int bios_sysctl(int *, u_int, void *, size_t *, void *, size_t, struct proc *); + +void bios_getopt(void); + +/* bios32.c */ +int bios32_service(uint32_t, bios32_entry_t, bios32_entry_info_t); +void bios32_cleanup(void); + +extern u_int bootapiver; +extern bios_memmap_t *bios_memmap; +extern bios_efiinfo_t *bios_efiinfo; +extern bios_ucode_t *bios_ucode; +extern void *bios_smpinfo; +extern bios_pciinfo_t *bios_pciinfo; + +#endif /* _KERNEL */ +#endif /* _LOCORE */ +#endif /* _KERNEL || _STANDALONE */ + +#endif /* _MACHINE_BIOSVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/bus.h b/lib/libc/include/x86-openbsd-none/machine/bus.h new file mode 100644 index 0000000000..6ed2cb5fb7 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/bus.h @@ -0,0 +1,701 @@ +/* $OpenBSD: bus.h,v 1.67 2017/05/08 00:27:45 dlg Exp $ */ +/* $NetBSD: bus.h,v 1.6 1996/11/10 03:19:25 thorpej Exp $ */ + +/*- + * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 1996 Charles M. Hannum. All rights reserved. + * Copyright (c) 1996 Jason R. Thorpe. All rights reserved. + * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christopher G. Demetriou + * for the NetBSD Project. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MACHINE_BUS_H_ +#define _MACHINE_BUS_H_ + +#include +#include + +#include + +/* + * Bus address and size types + */ +typedef u_long bus_addr_t; +typedef u_long bus_size_t; + +/* + * Access methods for bus resources and address space. + */ +struct i386_bus_space_ops; +typedef const struct i386_bus_space_ops *bus_space_tag_t; +typedef u_long bus_space_handle_t; + +int bus_space_map(bus_space_tag_t t, bus_addr_t addr, + bus_size_t size, int flags, bus_space_handle_t *bshp); +/* like bus_space_map(), but without extent map checking/allocation */ +int _bus_space_map(bus_space_tag_t t, bus_addr_t addr, + bus_size_t size, int flags, bus_space_handle_t *bshp); +void bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh, + bus_size_t size); +/* like bus_space_unmap(), but without extent map deallocation */ +void _bus_space_unmap(bus_space_tag_t, bus_space_handle_t, + bus_size_t, bus_addr_t *); +int bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh, + bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp); +paddr_t bus_space_mmap(bus_space_tag_t, bus_addr_t, off_t, int, int); + +int bus_space_alloc(bus_space_tag_t t, bus_addr_t rstart, + bus_addr_t rend, bus_size_t size, bus_size_t align, + bus_size_t boundary, int flags, bus_addr_t *addrp, + bus_space_handle_t *bshp); +void bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh, + bus_size_t size); + +struct i386_bus_space_ops { + +/* + * u_intN_t bus_space_read_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset); + * + * Read a 1, 2, 4, or 8 byte quantity from bus space + * described by tag/handle/offset. + */ + u_int8_t (*read_1)(bus_space_handle_t, bus_size_t); + u_int16_t (*read_2)(bus_space_handle_t, bus_size_t); + u_int32_t (*read_4)(bus_space_handle_t, bus_size_t); + +#define bus_space_read_1(_t, _h, _o) ((_t)->read_1((_h), (_o))) +#define bus_space_read_2(_t, _h, _o) ((_t)->read_2((_h), (_o))) +#define bus_space_read_4(_t, _h, _o) ((_t)->read_4((_h), (_o))) + +#define bus_space_read_raw_2(t, h, o) \ + bus_space_read_2((t), (h), (o)) +#define bus_space_read_raw_4(t, h, o) \ + bus_space_read_4((t), (h), (o)) + +#if 0 +/* Cause a link error for bus_space_read_8 and bus_space_read_raw_8 */ +#define bus_space_read_8(t, h, o) !!! bus_space_read_8 unimplemented !!! +#define bus_space_read_raw_8(t, h, o) !!! bus_space_read_raw_8 unimplemented !!! +#endif + +/* + * void bus_space_read_multi_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_intN_t *addr, size_t count); + * + * Read `count' 1, 2, 4, or 8 byte quantities from bus space + * described by tag/handle/offset and copy into buffer provided. + */ + + void (*read_multi_1)(bus_space_handle_t, bus_size_t, + u_int8_t *, bus_size_t); + void (*read_multi_2)(bus_space_handle_t, bus_size_t, + u_int16_t *, bus_size_t); + void (*read_multi_4)(bus_space_handle_t, bus_size_t, + u_int32_t *, bus_size_t); + +#define bus_space_read_multi_1(_t, _h, _o, _a, _c) \ + ((_t)->read_multi_1((_h), (_o), (_a), (_c))) +#define bus_space_read_multi_2(_t, _h, _o, _a, _c) \ + ((_t)->read_multi_2((_h), (_o), (_a), (_c))) +#define bus_space_read_multi_4(_t, _h, _o, _a, _c) \ + ((_t)->read_multi_4((_h), (_o), (_a), (_c))) + +#if 0 /* Cause a link error for bus_space_read_multi_8 */ +#define bus_space_read_multi_8 !!! bus_space_read_multi_8 unimplemented !!! +#endif + +/* + * void bus_space_read_raw_multi_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_int8_t *addr, size_t count); + * + * Read `count' bytes in 2, 4 or 8 byte wide quantities from bus space + * described by tag/handle/offset and copy into buffer provided. The buffer + * must have proper alignment for the N byte wide entities. Furthermore + * possible byte-swapping should be done by these functions. + */ + +#define bus_space_read_raw_multi_2(t, h, o, a, c) \ + bus_space_read_multi_2((t), (h), (o), (u_int16_t *)(a), (c) >> 1) +#define bus_space_read_raw_multi_4(t, h, o, a, c) \ + bus_space_read_multi_4((t), (h), (o), (u_int32_t *)(a), (c) >> 2) + +#if 0 /* Cause a link error for bus_space_read_raw_multi_8 */ +#define bus_space_read_raw_multi_8 \ + !!! bus_space_read_raw_multi_8 unimplemented !!! +#endif + +/* + * void bus_space_read_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_intN_t *addr, size_t count); + * + * Read `count' 1, 2, 4, or 8 byte quantities from bus space + * described by tag/handle and starting at `offset' and copy into + * buffer provided. + */ + + void (*read_region_1)(bus_space_handle_t, + bus_size_t, u_int8_t *, bus_size_t); + void (*read_region_2)(bus_space_handle_t, + bus_size_t, u_int16_t *, bus_size_t); + void (*read_region_4)(bus_space_handle_t, + bus_size_t, u_int32_t *, bus_size_t); + +#define bus_space_read_region_1(_t, _h, _o, _a, _c) \ + ((_t)->read_region_1((_h), (_o), (_a), (_c))) +#define bus_space_read_region_2(_t, _h, _o, _a, _c) \ + ((_t)->read_region_2((_h), (_o), (_a), (_c))) +#define bus_space_read_region_4(_t, _h, _o, _a, _c) \ + ((_t)->read_region_4((_h), (_o), (_a), (_c))) + +#if 0 /* Cause a link error for bus_space_read_region_8 */ +#define bus_space_read_region_8 !!! bus_space_read_region_8 unimplemented !!! +#endif + +/* + * void bus_space_read_raw_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_int8_t *addr, size_t count); + * + * Read `count' bytes in 2, 4 or 8 byte wide quantities from bus space + * described by tag/handle and starting at `offset' and copy into + * buffer provided. The buffer must have proper alignment for the N byte + * wide entities. Furthermore possible byte-swapping should be done by + * these functions. + */ + +#define bus_space_read_raw_region_2(_t, _h, _o, _a, _c) \ + ((_t)->read_region_2((_h), (_o), (u_int16_t *)(_a), (_c) >> 1)) +#define bus_space_read_raw_region_4(_t, _h, _o, _a, _c) \ + ((_t)->read_region_4((_h), (_o), (u_int32_t *)(_a), (_c) >> 2)) + +#if 0 /* Cause a link error for bus_space_read_raw_region_8 */ +#define bus_space_read_raw_region_8 \ + !!! bus_space_read_raw_region_8 unimplemented !!! +#endif + +/* + * void bus_space_write_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_intN_t value); + * + * Write the 1, 2, 4, or 8 byte value `value' to bus space + * described by tag/handle/offset. + */ + + void (*write_1)(bus_space_handle_t, bus_size_t, u_int8_t); + void (*write_2)(bus_space_handle_t, bus_size_t, u_int16_t); + void (*write_4)(bus_space_handle_t, bus_size_t, u_int32_t); + +#define bus_space_write_1(_t, _h, _o, _v) \ + ((_t)->write_1((_h), (_o), (_v))) +#define bus_space_write_2(_t, _h, _o, _v) \ + ((_t)->write_2((_h), (_o), (_v))) +#define bus_space_write_4(_t, _h, _o, _v) \ + ((_t)->write_4((_h), (_o), (_v))) + +#define bus_space_write_raw_2(t, h, o, v) \ + bus_space_write_2((t), (h), (o), (v)) +#define bus_space_write_raw_4(t, h, o, v) \ + bus_space_write_4((t), (h), (o), (v)) + +#if 0 +/* Cause a link error for bus_space_write_8 and bus_space_write_raw_8 */ +#define bus_space_write_8 !!! bus_space_write_8 not implemented !!! +#define bus_space_write_raw_8 !!! bus_space_write_raw_8 not implemented !!! +#endif + +/* + * void bus_space_write_multi_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * const u_intN_t *addr, size_t count); + * + * Write `count' 1, 2, 4, or 8 byte quantities from the buffer + * provided to bus space described by tag/handle/offset. + */ + + void (*write_multi_1)(bus_space_handle_t, + bus_size_t, const u_int8_t *, bus_size_t); + void (*write_multi_2)(bus_space_handle_t, + bus_size_t, const u_int16_t *, bus_size_t); + void (*write_multi_4)(bus_space_handle_t, + bus_size_t, const u_int32_t *, bus_size_t); + +#define bus_space_write_multi_1(_t, _h, _o, _a, _c) \ + ((_t)->write_multi_1((_h), (_o), (_a), (_c))) +#define bus_space_write_multi_2(_t, _h, _o, _a, _c) \ + ((_t)->write_multi_2((_h), (_o), (_a), (_c))) +#define bus_space_write_multi_4(_t, _h, _o, _a, _c) \ + ((_t)->write_multi_4((_h), (_o), (_a), (_c))) + +#if 0 /* Cause a link error for bus_space_write_multi_8 */ +#define bus_space_write_multi_8(t, h, o, a, c) \ + !!! bus_space_write_multi_8 unimplemented !!! +#endif + +/* + * void bus_space_write_raw_multi_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * const u_int8_t *addr, size_t count); + * + * Write `count' bytes in 2, 4 or 8 byte wide quantities from the buffer + * provided to bus space described by tag/handle/offset. The buffer + * must have proper alignment for the N byte wide entities. Furthermore + * possible byte-swapping should be done by these functions. + */ + +#define bus_space_write_raw_multi_2(_t, _h, _o, _a, _c) \ + ((_t)->write_multi_2((_h), (_o), (const u_int16_t *)(_a), (_c) >> 1)) +#define bus_space_write_raw_multi_4(_t, _h, _o, _a, _c) \ + ((_t)->write_multi_4((_h), (_o), (const u_int32_t *)(_a), (_c) >> 2)) + +#if 0 /* Cause a link error for bus_space_write_raw_multi_8 */ +#define bus_space_write_raw_multi_8 \ + !!! bus_space_write_raw_multi_8 unimplemented !!! +#endif + +/* + * void bus_space_write_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * const u_intN_t *addr, size_t count); + * + * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided + * to bus space described by tag/handle starting at `offset'. + */ + + void (*write_region_1)(bus_space_handle_t, + bus_size_t, const u_int8_t *, bus_size_t); + void (*write_region_2)(bus_space_handle_t, + bus_size_t, const u_int16_t *, bus_size_t); + void (*write_region_4)(bus_space_handle_t, + bus_size_t, const u_int32_t *, bus_size_t); + +#define bus_space_write_region_1(_t, _h, _o, _a, _c) \ + ((_t)->write_region_1((_h), (_o), (_a), (_c))) +#define bus_space_write_region_2(_t, _h, _o, _a, _c) \ + ((_t)->write_region_2((_h), (_o), (_a), (_c))) +#define bus_space_write_region_4(_t, _h, _o, _a, _c) \ + ((_t)->write_region_4((_h), (_o), (_a), (_c))) + +#if 0 /* Cause a link error for bus_space_write_region_8 */ +#define bus_space_write_region_8 \ + !!! bus_space_write_region_8 unimplemented !!! +#endif + +/* + * void bus_space_write_raw_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * const u_int8_t *addr, size_t count); + * + * Write `count' bytes in 2, 4 or 8 byte wide quantities to bus space + * described by tag/handle and starting at `offset' from the + * buffer provided. The buffer must have proper alignment for the N byte + * wide entities. Furthermore possible byte-swapping should be done by + * these functions. + */ + +#define bus_space_write_raw_region_2(_t, _h, _o, _a, _c) \ + ((_t)->write_region_2((_h), (_o), (const u_int16_t *)(_a), (_c) >> 1)) +#define bus_space_write_raw_region_4(_t, _h, _o, _a, _c) \ + ((_t)->write_region_4((_h), (_o), (const u_int32_t *)(_a), (_c) >> 2)) + +#if 0 /* Cause a link error for bus_space_write_raw_region_8 */ +#define bus_space_write_raw_region_8 \ + !!! bus_space_write_raw_region_8 unimplemented !!! +#endif + +/* + * void bus_space_set_multi_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_intN_t val, size_t count); + * + * Write the 1, 2, 4, or 8 byte value `val' to bus space described + * by tag/handle/offset `count' times. + */ + + void (*set_multi_1)(bus_space_handle_t, + bus_size_t, u_int8_t, size_t); + void (*set_multi_2)(bus_space_handle_t, + bus_size_t, u_int16_t, size_t); + void (*set_multi_4)(bus_space_handle_t, + bus_size_t, u_int32_t, size_t); + +#define bus_space_set_multi_1(_t, _h, _o, _a, _c) \ + ((_t)->set_multi_1((_h), (_o), (_a), (_c))) +#define bus_space_set_multi_2(_t, _h, _o, _a, _c) \ + ((_t)->set_multi_2((_h), (_o), (_a), (_c))) +#define bus_space_set_multi_4(_t, _h, _o, _a, _c) \ + ((_t)->set_multi_4((_h), (_o), (_a), (_c))) + +#if 0 /* Cause a link error for bus_space_set_multi_8 */ +#define bus_space_set_multi_8 \ + !!! bus_space_set_multi_8 unimplemented !!! +#endif + +/* + * void bus_space_set_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_intN_t val, size_t count); + * + * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described + * by tag/handle starting at `offset'. + */ + + void (*set_region_1)(bus_space_handle_t, + bus_size_t, u_int8_t, size_t); + void (*set_region_2)(bus_space_handle_t, + bus_size_t, u_int16_t, size_t); + void (*set_region_4)(bus_space_handle_t, + bus_size_t, u_int32_t, size_t); + +#define bus_space_set_region_1(_t, _h, _o, _a, _c) \ + ((_t)->set_region_1((_h), (_o), (_a), (_c))) +#define bus_space_set_region_2(_t, _h, _o, _a, _c) \ + ((_t)->set_region_2((_h), (_o), (_a), (_c))) +#define bus_space_set_region_4(_t, _h, _o, _a, _c) \ + ((_t)->set_region_4((_h), (_o), (_a), (_c))) + +#if 0 /* Cause a link error for bus_space_set_region_8 */ +#define bus_space_set_region_8 \ + !!! bus_space_set_region_8 unimplemented !!! +#endif + +/* + * void bus_space_copy_N(bus_space_tag_t tag, + * bus_space_handle_t bsh1, bus_size_t off1, + * bus_space_handle_t bsh2, bus_size_t off2, + * size_t count); + * + * Copy `count' 1, 2, 4, or 8 byte values from bus space starting + * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2. + */ + + void (*copy_1)(bus_space_handle_t, + bus_size_t, bus_space_handle_t, bus_size_t, size_t); + void (*copy_2)(bus_space_handle_t, + bus_size_t, bus_space_handle_t, bus_size_t, size_t); + void (*copy_4)(bus_space_handle_t, + bus_size_t, bus_space_handle_t, bus_size_t, size_t); + +#define bus_space_copy_1(_t, _h1, _o1, _h2, _o2, _c) \ + ((_t)->copy_1((_h1), (_o1), (_h2), (_o2), (_c))) +#define bus_space_copy_2(_t, _h1, _o1, _h2, _o2, _c) \ + ((_t)->copy_2((_h1), (_o1), (_h2), (_o2), (_c))) +#define bus_space_copy_4(_t, _h1, _o1, _h2, _o2, _c) \ + ((_t)->copy_4((_h1), (_o1), (_h2), (_o2), (_c))) + +#if 0 /* Cause a link error for bus_space_copy_8 */ +#define bus_space_copy_8 \ + !!! bus_space_copy_8 unimplemented !!! +#endif + +#define i386_space_copy1(a1, a2, cnt, movs, df) \ + __asm volatile(df "\n\trep\n\t" movs : \ + "+S" (a1), "+D" (a2), "+c" (cnt) :: "memory", "cc"); + +#define i386_space_copy(a1, a2, sz, cnt) do { \ + if ((void *)(a1) < (void *)(a2)) { \ + a1 += ((cnt) - 1) * (sz); a2 += ((cnt) - 1) * (sz); \ + switch (sz) { \ + case 1: i386_space_copy1(a1,a2,cnt,"movsb","std");break;\ + case 2: i386_space_copy1(a1,a2,cnt,"movsw","std");break;\ + case 4: i386_space_copy1(a1,a2,cnt,"movsl","std");break;\ + } \ + __asm volatile("cld"); /* must restore before func ret */ \ + } else \ + switch (sz) { \ + case 1: i386_space_copy1(a1,a2,cnt,"movsb","cld");break;\ + case 2: i386_space_copy1(a1,a2,cnt,"movsw","cld");break;\ + case 4: i386_space_copy1(a1,a2,cnt,"movsl","cld");break;\ + } \ +} while (0) + +/* + * void *bus_space_vaddr(bus_space_tag_t, bus_space_handle_t); + * + * Get the kernel virtual address for the mapped bus space. + * Only allowed for regions mapped with BUS_SPACE_MAP_LINEAR. + */ + void * (*vaddr)(bus_space_handle_t); + +#define bus_space_vaddr(_t, _h) \ + ((_t)->vaddr((_h))) +}; + +/* + * Bus read/write barrier methods. + * + * void bus_space_barrier(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * bus_size_t len, int flags); + * + * Note: the i386 does not currently require barriers, but we must + * provide the flags to MI code. + */ +#define bus_space_barrier(t, h, o, l, f) do { \ + ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)));\ + __asm volatile("" : : : "memory"); \ +} while (0) +#define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */ +#define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */ + +#define BUS_SPACE_MAP_CACHEABLE 0x0001 +#define BUS_SPACE_MAP_LINEAR 0x0002 +#define BUS_SPACE_MAP_PREFETCHABLE 0x0008 + +/* + * Values for the i386 bus space tag, not to be used directly by MI code. + */ + +/* space is i/o space */ +extern const struct i386_bus_space_ops i386_bus_space_io_ops; +#define I386_BUS_SPACE_IO (&i386_bus_space_io_ops) + +/* space is mem space */ +extern const struct i386_bus_space_ops i386_bus_space_mem_ops; +#define I386_BUS_SPACE_MEM (&i386_bus_space_mem_ops) + +/* + * Flags used in various bus DMA methods. + */ +#define BUS_DMA_WAITOK 0x0000 /* safe to sleep (pseudo-flag) */ +#define BUS_DMA_NOWAIT 0x0001 /* not safe to sleep */ +#define BUS_DMA_ALLOCNOW 0x0002 /* perform resource allocation now */ +#define BUS_DMA_COHERENT 0x0004 /* hint: map memory DMA coherent */ +#define BUS_DMA_BUS1 0x0010 /* placeholders for bus functions... */ +#define BUS_DMA_BUS2 0x0020 +#define BUS_DMA_BUS3 0x0040 +#define BUS_DMA_24BIT 0x0080 /* isadma map */ +#define BUS_DMA_STREAMING 0x0100 /* hint: sequential, unidirectional */ +#define BUS_DMA_READ 0x0200 /* mapping is device -> memory only */ +#define BUS_DMA_WRITE 0x0400 /* mapping is memory -> device only */ +#define BUS_DMA_NOCACHE 0x0800 /* map memory uncached */ +#define BUS_DMA_ZERO 0x1000 /* dmamem_alloc return zeroed mem */ +#define BUS_DMA_64BIT 0x2000 /* device handles 64bit dva */ + +/* Forwards needed by prototypes below. */ +struct mbuf; +struct proc; +struct uio; + +/* + * Operations performed by bus_dmamap_sync(). + */ +#define BUS_DMASYNC_PREREAD 0x01 +#define BUS_DMASYNC_POSTREAD 0x02 +#define BUS_DMASYNC_PREWRITE 0x04 +#define BUS_DMASYNC_POSTWRITE 0x08 + +typedef struct bus_dma_tag *bus_dma_tag_t; +typedef struct bus_dmamap *bus_dmamap_t; + +/* + * bus_dma_segment_t + * + * Describes a single contiguous DMA transaction. Values + * are suitable for programming into DMA registers. + */ +struct bus_dma_segment { + bus_addr_t ds_addr; /* DMA address */ + bus_size_t ds_len; /* length of transfer */ + /* + * Ugh. need this so can pass alignment down from bus_dmamem_alloc + * to scatter gather maps. only the first one is used so the rest is + * wasted space. bus_dma could do with fixing the api for this. + */ + bus_size_t _ds_boundary; /* don't cross */ + bus_size_t _ds_align; /* align to me */ +}; +typedef struct bus_dma_segment bus_dma_segment_t; + +/* + * bus_dma_tag_t + * + * A machine-dependent opaque type describing the implementation of + * DMA for a given bus. + */ + +struct bus_dma_tag { + void *_cookie; /* cookie used in the guts */ + + /* + * DMA mapping methods. + */ + int (*_dmamap_create)(bus_dma_tag_t, bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); + void (*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t); + int (*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int); + int (*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t, + struct mbuf *, int); + int (*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t, + struct uio *, int); + int (*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); + void (*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t); + void (*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t, + bus_addr_t, bus_size_t, int); + + /* + * DMA memory utility functions. + */ + int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); + int (*_dmamem_alloc_range)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int, + bus_addr_t, bus_addr_t); + void (*_dmamem_free)(bus_dma_tag_t, + bus_dma_segment_t *, int); + int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); + void (*_dmamem_unmap)(bus_dma_tag_t, caddr_t, size_t); + paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *, + int, off_t, int, int); +}; + +#define bus_dmamap_create(t, s, n, m, b, f, p) \ + (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p)) +#define bus_dmamap_destroy(t, p) \ + (*(t)->_dmamap_destroy)((t), (p)) +#define bus_dmamap_load(t, m, b, s, p, f) \ + (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f)) +#define bus_dmamap_load_mbuf(t, m, b, f) \ + (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f)) +#define bus_dmamap_load_uio(t, m, u, f) \ + (*(t)->_dmamap_load_uio)((t), (m), (u), (f)) +#define bus_dmamap_load_raw(t, m, sg, n, s, f) \ + (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f)) +#define bus_dmamap_unload(t, p) \ + (*(t)->_dmamap_unload)((t), (p)) +#define bus_dmamap_sync(t, p, o, l, ops) \ + (*(t)->_dmamap_sync)((t), (p), (o), (l), (ops)) + +#define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \ + (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f)) +#define bus_dmamem_alloc_range(t, s, a, b, sg, n, r, f, l, h) \ + (*(t)->_dmamem_alloc_range)((t), (s), (a), (b), (sg), \ + (n), (r), (f), (l), (h)) +#define bus_dmamem_free(t, sg, n) \ + (*(t)->_dmamem_free)((t), (sg), (n)) +#define bus_dmamem_map(t, sg, n, s, k, f) \ + (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f)) +#define bus_dmamem_unmap(t, k, s) \ + (*(t)->_dmamem_unmap)((t), (k), (s)) +#define bus_dmamem_mmap(t, sg, n, o, p, f) \ + (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f)) + +/* + * bus_dmamap_t + * + * Describes a DMA mapping. + */ +struct bus_dmamap { + /* + * PRIVATE MEMBERS: not for use by machine-independent code. + */ + bus_size_t _dm_size; /* largest DMA transfer mappable */ + int _dm_segcnt; /* number of segs this map can map */ + bus_size_t _dm_maxsegsz; /* largest possible segment */ + bus_size_t _dm_boundary; /* don't cross this */ + int _dm_flags; /* misc. flags */ + + void *_dm_cookie; /* cookie for bus-specific functions */ + + /* + * PUBLIC MEMBERS: these are used by machine-independent code. + */ + bus_size_t dm_mapsize; /* size of the mapping */ + int dm_nsegs; /* # valid segments in mapping */ + bus_dma_segment_t dm_segs[1]; /* segments; variable length */ +}; + +int _bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t, + bus_size_t, int, bus_dmamap_t *); +void _bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t); +int _bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int); +int _bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, + struct mbuf *, int); +int _bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, + struct uio *, int); +int _bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); +void _bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t); +void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, + bus_size_t, int); + +int _bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size, + bus_size_t alignment, bus_size_t boundary, + bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags); +void _bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs, + int nsegs); +int _bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs, + int nsegs, size_t size, caddr_t *kvap, int flags); +void _bus_dmamem_unmap(bus_dma_tag_t tag, caddr_t kva, + size_t size); +paddr_t _bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs, + int nsegs, off_t off, int prot, int flags); + +int _bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size, + bus_size_t alignment, bus_size_t boundary, + bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags, + paddr_t low, paddr_t high); + +#endif /* _MACHINE_BUS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/cdefs.h b/lib/libc/include/x86-openbsd-none/machine/cdefs.h new file mode 100644 index 0000000000..af2607c12a --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/cdefs.h @@ -0,0 +1,21 @@ +/* $OpenBSD: cdefs.h,v 1.10 2013/03/28 17:30:45 martynas Exp $ */ + +/* + * Written by J.T. Conklin 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_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/codepatch.h b/lib/libc/include/x86-openbsd-none/machine/codepatch.h new file mode 100644 index 0000000000..fa33bf8bf8 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/codepatch.h @@ -0,0 +1,52 @@ +/* $OpenBSD: codepatch.h,v 1.3 2023/07/31 17:10:31 bluhm Exp $ */ +/* + * Copyright (c) 2014-2015 Stefan Fritsch + * + * 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_CODEPATCH_H_ +#define _MACHINE_CODEPATCH_H_ + +#include + +#ifndef _LOCORE + +void *codepatch_maprw(vaddr_t *nva, vaddr_t dest); +void codepatch_unmaprw(vaddr_t nva); +void codepatch_fill_nop(void *caddr, uint16_t len); +void codepatch_nop(uint16_t tag); +void codepatch_replace(uint16_t tag, const void *code, size_t len); +void codepatch_call(uint16_t tag, void *func); + +#endif /* !_LOCORE */ + +/* + * Mark the start of some code snippet to be patched. + */ +#define CODEPATCH_START 998: +/* + * Mark the end of some code to be patched, and assign the given tag. + */ +#define CODEPATCH_END(tag) \ + 999: \ + .section .codepatch, "a" ;\ + .int 998b ;\ + .short (999b - 998b) ;\ + .short tag ;\ + .previous + +#define CPTAG_STAC 1 +#define CPTAG_CLAC 2 + +#endif /* _MACHINE_CODEPATCH_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/conf.h b/lib/libc/include/x86-openbsd-none/machine/conf.h new file mode 100644 index 0000000000..eaceeec5cd --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/conf.h @@ -0,0 +1,60 @@ +/* $OpenBSD: conf.h,v 1.21 2024/06/11 03:28:42 jsg Exp $ */ +/* $NetBSD: conf.h,v 1.2 1996/05/05 19:28:34 christos Exp $ */ + +/* + * Copyright (c) 1996 Christos Zoulas. 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 Christos Zoulas. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#define mmread mmrw +#define mmwrite mmrw +cdev_decl(mm); + +bdev_decl(fd); +cdev_decl(fd); + +#define cdev_acpiapm_init(c,n) {\ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,n,kqfilter) } + +cdev_decl(spkr); + +cdev_decl(joy); + +cdev_decl(bios); + +cdev_decl(acpi); + +cdev_decl(apm); + +cdev_decl(acpiapm); + +cdev_decl(pctr); \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/cpu.h b/lib/libc/include/x86-openbsd-none/machine/cpu.h new file mode 100644 index 0000000000..eda232d75f --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/cpu.h @@ -0,0 +1,533 @@ +/* $OpenBSD: cpu.h,v 1.192 2024/06/18 12:37:29 jsg Exp $ */ +/* $NetBSD: cpu.h,v 1.35 1996/05/05 19:29:26 christos 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. + * + * @(#)cpu.h 5.4 (Berkeley) 5/9/91 + */ + +#ifndef _MACHINE_CPU_H_ +#define _MACHINE_CPU_H_ + +/* + * Definitions unique to i386 cpu support. + */ +#ifdef _KERNEL +#include +#include +#include +#include +#include + +#ifdef MULTIPROCESSOR +#include +#include +#endif + +#endif /* _KERNEL */ + +/* + * Arguments to hardclock, softclock and statclock + * encapsulate the previous machine state in an opaque + * clockframe; for now, use generic intrframe. + * + * XXX intrframe has a lot of gunk we don't need. + */ +#define clockframe intrframe + +#include +#include +#include +#include +#include +#include + +struct intrsource; + +#ifdef _KERNEL +/* XXX stuff to move to cpuvar.h later */ +struct cpu_info { + u_int32_t ci_kern_cr3; /* U+K page table */ + u_int32_t ci_scratch; /* for U<-->K transition */ + +#define ci_PAGEALIGN ci_dev + struct device *ci_dev; /* our device */ + struct cpu_info *ci_self; /* pointer to this structure */ + struct schedstate_percpu ci_schedstate; /* scheduler state */ + struct cpu_info *ci_next; /* next cpu */ + + /* + * Public members. + */ + struct proc *ci_curproc; /* current owner of the processor */ + cpuid_t ci_cpuid; /* our CPU ID */ + u_int ci_apicid; /* our APIC ID */ + u_int ci_acpi_proc_id; + u_int32_t ci_randseed; + + u_int32_t ci_kern_esp; /* kernel-only stack */ + u_int32_t ci_intr_esp; /* U<-->K trampoline stack */ + u_int32_t ci_user_cr3; /* U-K page table */ + +#if defined(MULTIPROCESSOR) + struct srp_hazard ci_srp_hazards[SRP_HAZARD_NUM]; +#define __HAVE_UVM_PERCPU + struct uvm_pmr_cache ci_uvm; +#endif + + /* + * Private members. + */ + struct proc *ci_fpcurproc; /* current owner of the FPU */ + struct proc *ci_fpsaveproc; + int ci_fpsaving; /* save in progress */ + + struct pcb *ci_curpcb; /* VA of current HW PCB */ + struct pcb *ci_idle_pcb; /* VA of current PCB */ + struct pmap *ci_curpmap; + + struct intrsource *ci_isources[MAX_INTR_SOURCES]; + u_int32_t ci_ipending; + int ci_ilevel; + int ci_idepth; + u_int32_t ci_imask[NIPL]; + u_int32_t ci_iunmask[NIPL]; +#ifdef DIAGNOSTIC + int ci_mutex_level; +#endif + + paddr_t ci_idle_pcb_paddr; /* PA of idle PCB */ + volatile u_long ci_flags; /* flags; see below */ + u_int32_t ci_ipis; /* interprocessor interrupts pending */ + + u_int32_t ci_level; + u_int32_t ci_vendor[4]; + u_int32_t ci_signature; /* X86 cpuid type */ + u_int32_t ci_family; /* extended cpuid family */ + u_int32_t ci_model; /* extended cpuid model */ + u_int32_t ci_feature_flags; /* X86 CPUID feature bits */ + u_int32_t ci_feature_sefflags_ebx;/* more CPUID feature bits */ + u_int32_t ci_feature_sefflags_ecx;/* more CPUID feature bits */ + u_int32_t ci_feature_sefflags_edx;/* more CPUID feature bits */ + u_int32_t ci_feature_tpmflags; /* thermal & power bits */ + u_int32_t cpu_class; /* CPU class */ + u_int32_t ci_cflushsz; /* clflush cache-line size */ + + int ci_inatomic; + + struct cpu_functions *ci_func; /* start/stop functions */ + void (*cpu_setup)(struct cpu_info *); /* proc-dependant init */ + + struct device *ci_acpicpudev; + volatile u_int ci_mwait; +#define MWAIT_IN_IDLE 0x1 /* don't need IPI to wake */ +#define MWAIT_KEEP_IDLING 0x2 /* cleared by other cpus to wake me */ +#define MWAIT_ONLY 0x4 /* set if all idle states use mwait */ +#define MWAIT_IDLING (MWAIT_IN_IDLE | MWAIT_KEEP_IDLING) + + int ci_want_resched; + + union descriptor *ci_gdt; + struct i386tss *ci_tss; + struct i386tss *ci_nmi_tss; + + volatile int ci_ddb_paused; /* paused due to other proc in ddb */ +#define CI_DDB_RUNNING 0 +#define CI_DDB_SHOULDSTOP 1 +#define CI_DDB_STOPPED 2 +#define CI_DDB_ENTERDDB 3 +#define CI_DDB_INDDB 4 + + struct ksensordev ci_sensordev; + struct ksensor ci_sensor; +#if defined(GPROF) || defined(DDBPROF) + struct gmonparam *ci_gmon; + struct clockintr ci_gmonclock; +#endif + struct clockqueue ci_queue; + char ci_panicbuf[512]; +}; + +/* + * Processor flag notes: The "primary" CPU has certain MI-defined + * roles (mostly relating to hardclock handling); we distinguish + * between the processor which booted us, and the processor currently + * holding the "primary" role just to give us the flexibility later to + * change primaries should we be sufficiently twisted. + */ + +#define CPUF_BSP 0x0001 /* CPU is the original BSP */ +#define CPUF_AP 0x0002 /* CPU is an AP */ +#define CPUF_SP 0x0004 /* CPU is only processor */ +#define CPUF_PRIMARY 0x0008 /* CPU is active primary processor */ +#define CPUF_APIC_CD 0x0010 /* CPU has apic configured */ +#define CPUF_CONST_TSC 0x0020 /* CPU has constant TSC */ + +#define CPUF_PRESENT 0x1000 /* CPU is present */ +#define CPUF_RUNNING 0x2000 /* CPU is running */ +#define CPUF_VMM 0x4000 /* CPU is executing in VMM mode */ + +/* + * We statically allocate the CPU info for the primary CPU (or, + * the only CPU on uniprocessors), and the primary CPU is the + * first CPU on the CPU info list. + */ +struct cpu_info_full; +extern struct cpu_info_full cpu_info_full_primary; +#define cpu_info_primary (*(struct cpu_info *)((char *)&cpu_info_full_primary + PAGE_SIZE*2 - offsetof(struct cpu_info, ci_PAGEALIGN))) + +extern struct cpu_info *cpu_info_list; + +#define CPU_INFO_ITERATOR int +#define CPU_INFO_FOREACH(cii, ci) for (cii = 0, ci = cpu_info_list; \ + ci != NULL; ci = ci->ci_next) + +#define CPU_INFO_UNIT(ci) ((ci)->ci_dev ? (ci)->ci_dev->dv_unit : 0) + +#ifdef MULTIPROCESSOR + +#define MAXCPUS 32 /* because we use a bitmask */ + +#define CPU_STARTUP(_ci) ((_ci)->ci_func->start(_ci)) +#define CPU_STOP(_ci) ((_ci)->ci_func->stop(_ci)) +#define CPU_START_CLEANUP(_ci) ((_ci)->ci_func->cleanup(_ci)) + +static struct cpu_info *curcpu(void); + +static __inline struct cpu_info * +curcpu(void) +{ + struct cpu_info *ci; + + /* Can't include sys/param.h for offsetof() since it includes us */ + __asm volatile("movl %%fs:%1, %0" : + "=r" (ci) : "m" + (*(struct cpu_info * const *)&((struct cpu_info *)0)->ci_self)); + return ci; +} +#define cpu_number() (curcpu()->ci_cpuid) + +#define CPU_IS_PRIMARY(ci) ((ci)->ci_flags & CPUF_PRIMARY) +#define CPU_IS_RUNNING(ci) ((ci)->ci_flags & CPUF_RUNNING) + +extern struct cpu_info *cpu_info[MAXCPUS]; + +extern void cpu_boot_secondary_processors(void); +extern void cpu_init_idle_pcbs(void); + +void cpu_kick(struct cpu_info *); +void cpu_unidle(struct cpu_info *); + +#define CPU_BUSY_CYCLE() __asm volatile("pause": : : "memory") + +#else /* MULTIPROCESSOR */ + +#define MAXCPUS 1 + +#define cpu_number() 0 +#define curcpu() (&cpu_info_primary) + +#define CPU_IS_PRIMARY(ci) 1 +#define CPU_IS_RUNNING(ci) 1 + +#define cpu_kick(ci) +#define cpu_unidle(ci) + +#define CPU_BUSY_CYCLE() __asm volatile ("" ::: "memory") + +#endif + +#include + +#define aston(p) ((p)->p_md.md_astpending = 1) + +#define curpcb curcpu()->ci_curpcb + +unsigned int cpu_rnd_messybits(void); + +/* + * Preempt the current process if in interrupt from user mode, + * or after the current trap/syscall if in system mode. + */ +extern void need_resched(struct cpu_info *); +#define clear_resched(ci) (ci)->ci_want_resched = 0 + +#define CLKF_USERMODE(frame) USERMODE((frame)->if_cs, (frame)->if_eflags) +#define CLKF_PC(frame) ((frame)->if_eip) +#define CLKF_INTR(frame) (IDXSEL((frame)->if_cs) == GICODE_SEL) + +/* + * This is used during profiling to integrate system time. + */ +#define PROC_PC(p) ((p)->p_md.md_regs->tf_eip) +#define PROC_STACK(p) ((p)->p_md.md_regs->tf_esp) + +/* + * Give a profiling tick to the current process when the user profiling + * buffer pages are invalid. On the i386, request an ast to send us + * through trap(), marking the proc as needing a profiling tick. + */ +#define need_proftick(p) aston(p) + +/* + * Notify the current process (p) that it has a signal pending, + * process as soon as possible. + */ +void signotify(struct proc *); + +/* + * We need a machine-independent name for this. + */ +extern void (*delay_func)(int); +void delay_fini(void(*)(int)); +void delay_init(void(*)(int), int); +struct timeval; + +#define DELAY(x) (*delay_func)(x) +#define delay(x) (*delay_func)(x) + +/* + * High resolution clock support (Pentium only) + */ +void calibrate_cyclecounter(void); + +/* + * pull in #defines for kinds of processors + */ +#include + +struct cpu_cpuid_nameclass { + const char *cpu_id; + int cpu_vendor; + const char *cpu_vendorname; + struct cpu_cpuid_family { + int cpu_class; + const char *cpu_models[CPU_MAXMODEL+2]; + void (*cpu_setup)(struct cpu_info *); + } cpu_family[CPU_MAXFAMILY - CPU_MINFAMILY + 1]; +}; + +struct cpu_cpuid_feature { + int feature_bit; + const char *feature_name; +}; + +/* locore.s */ +extern int cpu_id; +extern char cpu_vendor[]; /* note: NOT nul-terminated */ +extern char cpu_brandstr[]; +extern int cpuid_level; +extern int cpu_miscinfo; +extern int cpu_feature; +extern int ecpu_feature; +extern int cpu_ecxfeature; +extern int ecpu_ecxfeature; +extern int cpu_cache_eax; +extern int cpu_cache_ebx; +extern int cpu_cache_ecx; +extern int cpu_cache_edx; +extern int cpu_perf_eax; +extern int cpu_perf_ebx; +extern int cpu_perf_edx; +extern int cpu_apmi_edx; +extern int cpu_pae; /* cpu has both PAE and NX features */ + +/* cpu.c */ +extern u_int cpu_mwait_size; +extern u_int cpu_mwait_states; +extern void cpu_update_nmi_cr3(vaddr_t); +extern void cpu_tsx_disable(struct cpu_info *); + +/* machdep.c */ +extern int cpu_apmhalt; +extern int cpu_class; +extern char cpu_model[]; +extern const struct cpu_cpuid_nameclass i386_cpuid_cpus[]; +extern void (*cpu_idle_enter_fcn)(void); +extern void (*cpu_idle_cycle_fcn)(void); +extern void (*cpu_idle_leave_fcn)(void); +extern void (*cpu_suspend_cycle_fcn)(void); + +extern int cpuspeed; + +#if !defined(SMALL_KERNEL) +#define BUS66 6667 +#define BUS100 10000 +#define BUS133 13333 +#define BUS166 16667 +#define BUS200 20000 +#define BUS266 26667 +#define BUS333 33333 +extern int bus_clock; +#endif + +/* F00F bug fix stuff for pentium cpu */ +extern int cpu_f00f_bug; +void fix_f00f(void); + +/* dkcsum.c */ +void dkcsumattach(void); + +extern int i386_use_fxsave; +extern int i386_has_sse; +extern int i386_has_sse2; + +extern void (*update_cpuspeed)(void); + +extern void (*initclock_func)(void); +extern void (*startclock_func)(void); + +/* machdep.c */ +void dumpconf(void); +void cpu_reset(void); +void i386_proc0_tss_init(void); +void i386_init_pcb_tss(struct cpu_info *); +void cpuid(u_int32_t, u_int32_t *); + +/* locore.s */ +struct region_descriptor; +void lgdt(struct region_descriptor *); + +struct pcb; +void savectx(struct pcb *); +void proc_trampoline(void); + +/* clock.c */ +void startclocks(void); +void rtcinit(void); +void rtcstart(void); +void rtcstop(void); +void i8254_delay(int); +void i8254_initclocks(void); +void i8254_startclock(void); +void i8254_start_both_clocks(void); +void i8254_inittimecounter(void); +void i8254_inittimecounter_simple(void); + +#if !defined(SMALL_KERNEL) +/* est.c */ +void est_init(struct cpu_info *, int); +void est_setperf(int); +/* longrun.c */ +void longrun_init(void); +void longrun_setperf(int); +/* p4tcc.c */ +void p4tcc_init(int, int); +void p4tcc_setperf(int); +/* powernow.c */ +void k6_powernow_init(void); +void k6_powernow_setperf(int); +/* powernow-k7.c */ +void k7_powernow_init(void); +void k7_powernow_setperf(int); +/* powernow-k8.c */ +void k8_powernow_init(void); +void k8_powernow_setperf(int); +/* k1x-pstate.c */ +void k1x_init(struct cpu_info *); +void k1x_setperf(int); +#endif + +/* npx.c */ +void npxsave_proc(struct proc *, int); +void npxsave_cpu(struct cpu_info *, int); + +/* isa_machdep.c */ +void isa_defaultirq(void); +int isa_nmi(void); + +/* pmap.c */ +void pmap_bootstrap(vaddr_t); + +/* vm_machdep.c */ +int kvtop(caddr_t); + +#ifdef MULTIPROCESSOR +/* mp_setperf.c */ +void mp_setperf_init(void); +#endif + +int cpu_paenable(void *); +#endif /* _KERNEL */ + +/* + * CTL_MACHDEP definitions. + */ +#define CPU_CONSDEV 1 /* dev_t: console terminal device */ +#define CPU_BIOS 2 /* BIOS variables */ +#define CPU_BLK2CHR 3 /* convert blk maj into chr one */ +#define CPU_CHR2BLK 4 /* convert chr maj into blk one */ +#define CPU_ALLOWAPERTURE 5 /* allow mmap of /dev/xf86 */ +#define CPU_CPUVENDOR 6 /* cpuid vendor string */ +#define CPU_CPUID 7 /* cpuid */ +#define CPU_CPUFEATURE 8 /* cpuid features */ +#define CPU_KBDRESET 10 /* keyboard reset under pcvt */ +#define CPU_OSFXSR 13 /* uses FXSAVE/FXRSTOR */ +#define CPU_SSE 14 /* supports SSE */ +#define CPU_SSE2 15 /* supports SSE2 */ +#define CPU_XCRYPT 16 /* supports VIA xcrypt in userland */ +#define CPU_LIDACTION 18 /* action caused by lid close */ +#define CPU_FORCEUKBD 19 /* Force ukbd(4) as console keyboard */ +#define CPU_MAXID 20 /* number of valid machdep ids */ + +#define CTL_MACHDEP_NAMES { \ + { 0, 0 }, \ + { "console_device", CTLTYPE_STRUCT }, \ + { "bios", CTLTYPE_INT }, \ + { "blk2chr", CTLTYPE_STRUCT }, \ + { "chr2blk", CTLTYPE_STRUCT }, \ + { "allowaperture", CTLTYPE_INT }, \ + { "cpuvendor", CTLTYPE_STRING }, \ + { "cpuid", CTLTYPE_INT }, \ + { "cpufeature", CTLTYPE_INT }, \ + { 0, 0 }, \ + { "kbdreset", CTLTYPE_INT }, \ + { 0, 0 }, \ + { 0, 0 }, \ + { "osfxsr", CTLTYPE_INT }, \ + { "sse", CTLTYPE_INT }, \ + { "sse2", CTLTYPE_INT }, \ + { "xcrypt", CTLTYPE_INT }, \ + { 0, 0 }, \ + { "lidaction", CTLTYPE_INT }, \ + { "forceukbd", CTLTYPE_INT }, \ +} + +/* + * This needs to be included late since it relies on definitions higher + * up in this file. + */ +#if defined(MULTIPROCESSOR) && defined(_KERNEL) +#include +#endif + +#endif /* !_MACHINE_CPU_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/cpu_full.h b/lib/libc/include/x86-openbsd-none/machine/cpu_full.h new file mode 100644 index 0000000000..fd87a09aad --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/cpu_full.h @@ -0,0 +1,67 @@ +/* $OpenBSD: cpu_full.h,v 1.3 2018/06/22 13:21:14 bluhm Exp $ */ +/* + * Copyright (c) 2018 Philip Guenther + * Copyright (c) 2018 Hans-Joerg Hoexer + * + * 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_CPU_FULL_H_ +#define _MACHINE_CPU_FULL_H_ + +#include /* offsetof, PAGE_SIZE */ +#include +#include + +struct cpu_info_full { + /* page mapped kRO in u-k */ + union { + struct { + struct i386tss uu_tss; + struct i386tss uu_nmi_tss; + union descriptor uu_gdt[NGDT]; + } u_tssgdt; + char u_align[PAGE_SIZE]; + } cif_TSS_RO; +#define cif_tss cif_TSS_RO.u_tssgdt.uu_tss +#define cif_nmi_tss cif_TSS_RO.u_tssgdt.uu_nmi_tss +#define cif_gdt cif_TSS_RO.u_tssgdt.uu_gdt + + /* start of page mapped kRW in u-k */ + uint32_t cif_tramp_stack[(PAGE_SIZE / 4 + - offsetof(struct cpu_info, ci_PAGEALIGN)) / sizeof(uint32_t)]; + uint32_t cif_nmi_stack[(3 * PAGE_SIZE / 4) / sizeof(uint32_t)]; + + /* + * Beginning of this hangs over into the kRW page; rest is + * unmapped in u-k + */ + struct cpu_info cif_cpu; +} __aligned(PAGE_SIZE); + +/* tss, align shim, and gdt must fit in a page */ +CTASSERT(_ALIGN(2 * sizeof(struct i386tss)) + + sizeof(struct segment_descriptor) * NGDT < PAGE_SIZE); + +/* verify expected alignment */ +CTASSERT(offsetof(struct cpu_info_full, cif_cpu.ci_PAGEALIGN) % PAGE_SIZE == 0); + +/* verify total size is multiple of page size */ +CTASSERT(sizeof(struct cpu_info_full) % PAGE_SIZE == 0); + +extern struct cpu_info_full cpu_info_full_primary; + +/* Now make sure the cpu_info_primary macro is correct */ +CTASSERT(&cpu_info_primary - &cpu_info_full_primary.cif_cpu == 0); + +#endif /* _MACHINE_CPU_FULL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/cpufunc.h b/lib/libc/include/x86-openbsd-none/machine/cpufunc.h new file mode 100644 index 0000000000..a13a9ba4a9 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/cpufunc.h @@ -0,0 +1,310 @@ +/* $OpenBSD: cpufunc.h,v 1.34 2025/06/20 14:06:34 sf Exp $ */ +/* $NetBSD: cpufunc.h,v 1.8 1994/10/27 04:15:59 cgd Exp $ */ + +/* + * Copyright (c) 1993 Charles Hannum. + * 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 Charles Hannum. + * 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 _MACHINE_CPUFUNC_H_ +#define _MACHINE_CPUFUNC_H_ + +#ifdef _KERNEL + +/* + * Functions to provide access to i386-specific instructions. + */ + +#include + +#include + +static __inline void invlpg(u_int); +static __inline void lidt(void *); +static __inline void lldt(u_short); +static __inline void ltr(u_short); +static __inline void lcr0(u_int); +static __inline u_int rcr0(void); +static __inline u_int rcr2(void); +static __inline void lcr3(u_int); +static __inline u_int rcr3(void); +static __inline void lcr4(u_int); +static __inline u_int rcr4(void); +static __inline void tlbflush(void); +static __inline u_int read_eflags(void); +static __inline void write_eflags(u_int); +static __inline void wbinvd(void); +static __inline void clflush(u_int32_t addr); +static __inline void mfence(void); +static __inline void wrmsr(u_int, u_int64_t); +static __inline u_int64_t rdmsr(u_int); +static __inline void breakpoint(void); + +static __inline void +invlpg(u_int addr) +{ + __asm volatile("invlpg (%0)" : : "r" (addr) : "memory"); +} + +static __inline void +lidt(void *p) +{ + __asm volatile("lidt (%0)" : : "r" (p) : "memory"); +} + +static __inline void +lldt(u_short sel) +{ + __asm volatile("lldt %0" : : "r" (sel)); +} + +static __inline void +ltr(u_short sel) +{ + __asm volatile("ltr %0" : : "r" (sel)); +} + +static __inline void +lcr0(u_int val) +{ + __asm volatile("movl %0,%%cr0" : : "r" (val)); +} + +static __inline u_int +rcr0(void) +{ + u_int val; + __asm volatile("movl %%cr0,%0" : "=r" (val)); + return val; +} + +static __inline u_int +rcr2(void) +{ + u_int val; + __asm volatile("movl %%cr2,%0" : "=r" (val)); + return val; +} + +static __inline void +lcr3(u_int val) +{ + __asm volatile("movl %0,%%cr3" : : "r" (val)); +} + +static __inline u_int +rcr3(void) +{ + u_int val; + __asm volatile("movl %%cr3,%0" : "=r" (val)); + return val; +} + +static __inline void +lcr4(u_int val) +{ + __asm volatile("movl %0,%%cr4" : : "r" (val)); +} + +static __inline u_int +rcr4(void) +{ + u_int val; + __asm volatile("movl %%cr4,%0" : "=r" (val)); + return val; +} + +static __inline void +tlbflush(void) +{ + u_int val; + __asm volatile("movl %%cr3,%0" : "=r" (val)); + __asm volatile("movl %0,%%cr3" : : "r" (val)); +} + +#ifdef notyet +void setidt(int idx, /*XXX*/caddr_t func, int typ, int dpl); +#endif + + +/* XXXX ought to be in psl.h with spl() functions */ + +static __inline u_int +read_eflags(void) +{ + u_int ef; + + __asm volatile("pushfl; popl %0" : "=r" (ef)); + return (ef); +} + +static __inline void +write_eflags(u_int ef) +{ + __asm volatile("pushl %0; popfl" : : "r" (ef)); +} + +static inline void +intr_enable(void) +{ + __asm volatile("sti"); +} + +static inline u_long +intr_disable(void) +{ + u_long ef; + + ef = read_eflags(); + __asm volatile("cli"); + return (ef); +} + +static inline void +intr_restore(u_long ef) +{ + write_eflags(ef); +} + +static __inline void +wbinvd(void) +{ + __asm volatile("wbinvd" : : : "memory"); +} + +#ifdef MULTIPROCESSOR +int wbinvd_on_all_cpus(void); +#else +static inline int +wbinvd_on_all_cpus(void) +{ + wbinvd(); + return 0; +} +#endif + +static __inline void +clflush(u_int32_t addr) +{ + __asm volatile("clflush %0" : "+m" (*(volatile char *)addr)); +} + +static __inline void +mfence(void) +{ + __asm volatile("mfence" : : : "memory"); +} + +static __inline u_int64_t +rdtsc(void) +{ + uint64_t tsc; + + __asm volatile("rdtsc" : "=A" (tsc)); + return (tsc); +} + +static inline uint64_t +rdtsc_lfence(void) +{ + uint64_t tsc; + + __asm volatile("lfence; rdtsc" : "=A" (tsc)); + return tsc; +} + +static __inline void +wrmsr(u_int msr, u_int64_t newval) +{ + __asm volatile("wrmsr" : : "A" (newval), "c" (msr)); +} + +static __inline u_int64_t +rdmsr(u_int msr) +{ + u_int64_t rv; + + __asm volatile("rdmsr" : "=A" (rv) : "c" (msr)); + return (rv); +} + +static __inline void +monitor(const volatile void *addr, u_long extensions, u_int hints) +{ + __asm volatile("monitor" + : : "a" (addr), "c" (extensions), "d" (hints)); +} + +static __inline void +mwait(u_long extensions, u_int hints) +{ + __asm volatile("mwait" : : "a" (hints), "c" (extensions)); +} + +/* + * Some of the undocumented AMD64 MSRs need a 'passcode' to access. + * + * See LinuxBIOSv2: src/cpu/amd/model_fxx/model_fxx_init.c + */ + +#define OPTERON_MSR_PASSCODE 0x9c5a203a + +static __inline u_int64_t +rdmsr_locked(u_int msr, u_int code) +{ + uint64_t rv; + __asm volatile("rdmsr" + : "=A" (rv) + : "c" (msr), "D" (code)); + return (rv); +} + +static __inline void +wrmsr_locked(u_int msr, u_int code, u_int64_t newval) +{ + __asm volatile("wrmsr" + : + : "A" (newval), "c" (msr), "D" (code)); +} + +/* Break into DDB. */ +static __inline void +breakpoint(void) +{ + __asm volatile("int $3"); +} + +void amd64_errata(struct cpu_info *); +void cpu_ucode_setup(void); +void cpu_ucode_apply(struct cpu_info *); + +struct cpu_info_full; +void cpu_enter_pages(struct cpu_info_full *); + +#endif /* _KERNEL */ +#endif /* !_MACHINE_CPUFUNC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/cputypes.h b/lib/libc/include/x86-openbsd-none/machine/cputypes.h new file mode 100644 index 0000000000..0cd4be7abc --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/cputypes.h @@ -0,0 +1,60 @@ +/* $OpenBSD: cputypes.h,v 1.15 2022/08/22 08:53:55 jsg Exp $ */ +/* $NetBSD: cputypes.h,v 1.10 1997/10/18 04:51:03 mikel 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. 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. + */ + +/* + * Classes of Processor + */ + +#define CPUCLASS_486 1 +#define CPUCLASS_586 2 +#define CPUCLASS_686 3 + +/* + * CPU vendors + */ + +#define CPUVENDOR_UNKNOWN -1 +#define CPUVENDOR_INTEL 0 +#define CPUVENDOR_CYRIX 1 +#define CPUVENDOR_AMD 3 +#define CPUVENDOR_IDT 4 +#define CPUVENDOR_TRANSMETA 6 +#define CPUVENDOR_NS 7 +#define CPUVENDOR_VIA 8 +#define CPUVENDOR_SIS 9 + +/* + * Some other defines, dealing with values returned by cpuid. + */ + +#define CPU_MAXMODEL 15 /* Models within family range 0-15 */ +#define CPU_DEFMODEL 16 /* Value for unknown model -> default */ +#define CPU_MINFAMILY 4 /* Lowest that cpuid can return (486) */ +#define CPU_MAXFAMILY 0xf /* Highest we know (686) */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/cpuvar.h b/lib/libc/include/x86-openbsd-none/machine/cpuvar.h new file mode 100644 index 0000000000..e420bbdc64 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/cpuvar.h @@ -0,0 +1,98 @@ +/* $OpenBSD: cpuvar.h,v 1.8 2024/10/21 03:07:54 jsg Exp $ */ +/* $NetBSD: cpuvar.h,v 1.1.2.3 2000/02/21 18:54:07 sommerfeld Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by RedBack Networks Inc. + * + * Author: Bill Sommerfeld + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 1999 Stefan Grefen + * + * 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 NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 AUTHOR 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 AUTHOR AND 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. + */ + +struct cpu_functions { + int (*start)(struct cpu_info *); + int (*stop)(struct cpu_info *); + void (*cleanup)(struct cpu_info *); +}; + +extern struct cpu_functions mp_cpu_funcs; + +#define CPU_ROLE_SP 0 +#define CPU_ROLE_BP 1 +#define CPU_ROLE_AP 2 + +struct cpu_attach_args { + const char *caa_name; + int cpu_apicid; + int cpu_acpi_proc_id; + int cpu_role; + struct cpu_functions *cpu_func; + int cpu_signature; + int feature_flags; +}; + +#ifdef _KERNEL + +void i386_ipi(int,int,int); +void i386_ipi_init(int); + +void identifycpu(struct cpu_info *); +void cpu_init(struct cpu_info *); +void cpu_init_first(void); + +#endif \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/db_machdep.h b/lib/libc/include/x86-openbsd-none/machine/db_machdep.h new file mode 100644 index 0000000000..720fb23437 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/db_machdep.h @@ -0,0 +1,94 @@ +/* $OpenBSD: db_machdep.h,v 1.30 2021/08/30 08:11:12 jasper Exp $ */ +/* $NetBSD: db_machdep.h,v 1.9 1996/05/03 19:23:59 christos Exp $ */ + +/* + * Mach Operating System + * Copyright (c) 1991,1990 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +#ifndef _MACHINE_DB_MACHDEP_H_ +#define _MACHINE_DB_MACHDEP_H_ + +/* + * Machine-dependent defines for new kernel debugger. + */ + +#include +#include +#include + +typedef long db_expr_t; /* expression - signed */ + +typedef struct trapframe db_regs_t; +extern db_regs_t ddb_regs; /* register state */ + +#define PC_REGS(regs) ((vaddr_t)(regs)->tf_eip) +#define SET_PC_REGS(regs, value) (regs)->tf_eip = (int)(value) + +#define BKPT_INST 0xcc /* breakpoint instruction */ +#define BKPT_SIZE (1) /* size of breakpoint inst */ +#define BKPT_SET(inst) (BKPT_INST) + +#define SSF_INST 0x55 +#define SSF_SIZE (1) + +#define FIXUP_PC_AFTER_BREAK(regs) ((regs)->tf_eip -= BKPT_SIZE) + +#define db_clear_single_step(regs) ((regs)->tf_eflags &= ~PSL_T) +#define db_set_single_step(regs) ((regs)->tf_eflags |= PSL_T) + +#define IS_BREAKPOINT_TRAP(type, code) ((type) == T_BPTFLT) +#define IS_WATCHPOINT_TRAP(type, code) ((type) == T_TRCTRAP && (code) & 15) + +#define I_CALL 0xe8 +#define I_CALLI 0xff +#define I_RET 0xc3 +#define I_IRET 0xcf + +#define inst_trap_return(ins) (((ins)&0xff) == I_IRET) +#define inst_return(ins) (((ins)&0xff) == I_RET) +#define inst_call(ins) (((ins)&0xff) == I_CALL || \ + (((ins)&0xff) == I_CALLI && \ + ((ins)&0x3800) == 0x1000)) + +#define DB_MACHINE_COMMANDS + +/* macro for checking if a thread has used floating-point */ + +int db_ktrap(int, int, db_regs_t *); + +void db_machine_init(void); +int db_enter_ddb(void); +void db_startcpu(int); +void db_stopcpu(int); +void i386_ipi_db(struct cpu_info *); + +extern struct db_mutex ddb_mp_mutex; + +/* For ddb_state */ +#define DDB_STATE_NOT_RUNNING 0 +#define DDB_STATE_RUNNING 1 +#define DDB_STATE_EXITING 2 + +#endif /* _MACHINE_DB_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/disklabel.h b/lib/libc/include/x86-openbsd-none/machine/disklabel.h new file mode 100644 index 0000000000..4d97c53ec2 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/disklabel.h @@ -0,0 +1,40 @@ +/* $OpenBSD: disklabel.h,v 1.35 2015/09/30 14:57:03 krw Exp $ */ + +/* + * Copyright (c) 1994 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 _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_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/endian.h b/lib/libc/include/x86-openbsd-none/machine/endian.h new file mode 100644 index 0000000000..146c79b32c --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/endian.h @@ -0,0 +1,36 @@ +/* $OpenBSD: endian.h,v 1.20 2024/05/07 14:26:48 naddy 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_ + +#define _BYTE_ORDER _LITTLE_ENDIAN + +#ifndef __FROM_SYS__ENDIAN +#include +#endif + +#endif /* _MACHINE_ENDIAN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/exec.h b/lib/libc/include/x86-openbsd-none/machine/exec.h new file mode 100644 index 0000000000..aed3f3c616 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/exec.h @@ -0,0 +1,43 @@ +/* $OpenBSD: exec.h,v 1.14 2017/02/08 05:09:25 guenther Exp $ */ +/* $NetBSD: exec.h,v 1.6 1994/10/27 04:16:05 cgd 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. 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 _MACHINE_EXEC_H_ +#define _MACHINE_EXEC_H_ + +#define __LDPGSZ 4096 + +#define ARCH_ELFSIZE 32 + +#define ELF_TARG_CLASS ELFCLASS32 +#define ELF_TARG_DATA ELFDATA2LSB +#define ELF_TARG_MACH EM_386 /* XXX - EM_486 is currently unused + by all OSs/compilers/linkers */ + +#endif /* _MACHINE_EXEC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/fenv.h b/lib/libc/include/x86-openbsd-none/machine/fenv.h new file mode 100644 index 0000000000..febe5dc296 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/fenv.h @@ -0,0 +1,115 @@ +/* $OpenBSD: fenv.h,v 1.3 2011/05/25 21:46:49 martynas Exp $ */ +/* $NetBSD: fenv.h,v 1.1.6.2 2010/10/24 22:48:02 jym Exp $ */ + +/*- + * Copyright (c) 2004-2005 David Schultz + * 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 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 AUTHOR 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 _I386_FENV_H_ +#define _I386_FENV_H_ + +/* + * Each symbol representing a floating point exception expands to an integer + * constant expression with values, such that bitwise-inclusive ORs of _all + * combinations_ of the constants result in distinct values. + * + * We use such values that allow direct bitwise operations on FPU/SSE registers. + */ +#define FE_INVALID 0x01 +#define FE_DENORMAL 0x02 +#define FE_DIVBYZERO 0x04 +#define FE_OVERFLOW 0x08 +#define FE_UNDERFLOW 0x10 +#define FE_INEXACT 0x20 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * exception constants defined above. + */ +#define FE_ALL_EXCEPT (FE_INVALID | FE_DENORMAL | FE_DIVBYZERO | \ + FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT) +#define _SSE_MASK_SHIFT 7 + +/* + * Each symbol representing the rounding direction, expands to an integer + * constant expression whose value is distinct non-negative value. + * + * We use such values that allow direct bitwise operations on FPU/SSE registers. + */ +#define FE_TONEAREST 0x000 +#define FE_DOWNWARD 0x400 +#define FE_UPWARD 0x800 +#define FE_TOWARDZERO 0xc00 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * rounding direction constants defined above. + */ +#define _X87_ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | \ + FE_TOWARDZERO) +#define _SSE_ROUND_SHIFT 3 + +/* + * fenv_t represents the entire floating-point environment. + */ +typedef struct { + struct { + unsigned int __control; /* Control word register */ + unsigned int __status; /* Status word register */ + unsigned int __tag; /* Tag word register */ + unsigned int __others[4]; /* EIP, Pointer Selector, etc */ + } __x87; + unsigned int __mxcsr; /* Control, status register */ +} fenv_t; + +/* + * The following constant represents the default floating-point environment + * (that is, the one installed at program startup) and has type pointer to + * const-qualified fenv_t. + * + * It can be used as an argument to the functions within the header + * that manage the floating-point environment, namely fesetenv() and + * feupdateenv(). + */ +__BEGIN_DECLS +extern fenv_t __fe_dfl_env; +__END_DECLS +#define FE_DFL_ENV ((const fenv_t *)&__fe_dfl_env) + +/* + * fexcept_t represents the floating-point status flags collectively, including + * any status the implementation associates with the flags. + * + * A floating-point status flag is a system variable whose value is set (but + * never cleared) when a floating-point exception is raised, which occurs as a + * side effect of exceptional floating-point arithmetic to provide auxiliary + * information. + * + * A floating-point control mode is a system variable whose value may be set by + * the user to affect the subsequent behavior of floating-point arithmetic. + */ +typedef unsigned int fexcept_t; + +#endif /* !_I386_FENV_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/frame.h b/lib/libc/include/x86-openbsd-none/machine/frame.h new file mode 100644 index 0000000000..dbdb06fd21 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/frame.h @@ -0,0 +1,173 @@ +/* $OpenBSD: frame.h,v 1.13 2018/06/15 17:58:41 bluhm Exp $ */ +/* $NetBSD: frame.h,v 1.12 1995/10/11 04:20:08 mycroft Exp $ */ + +/*- + * Copyright (c) 1995 Charles M. Hannum. All rights reserved. + * 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. + * + * @(#)frame.h 5.2 (Berkeley) 1/18/91 + */ + +#ifndef _MACHINE_FRAME_H +#define _MACHINE_FRAME_H +#include + +/* + * System stack frames. + */ + +/* + * Exception/Trap Stack Frame + */ +struct trapframe { + int tf_fs; + int tf_gs; + int tf_es; + int tf_ds; + int tf_edi; + int tf_esi; + int tf_err; /* not the hardware position */ + int tf_ebx; + int tf_edx; + int tf_ecx; + int tf_eax; + int tf_trapno; + /* below portion defined in 386 hardware */ + int tf_ebp; /* hardware puts err here, INTRENTRY() moves it up */ + int tf_eip; + int tf_cs; + int tf_eflags; + /* below used when transitting rings (e.g. user to kernel) */ + int tf_esp; + int tf_ss; + /* below used when switching out of VM86 mode */ + int tf_vm86_es; + int tf_vm86_ds; + int tf_vm86_fs; + int tf_vm86_gs; +}; + +/* + * Interrupt stack frame + */ +struct intrframe { + int if_ppl; + int if_fs; + int if_gs; + int if_es; + int if_ds; + int if_edi; + int if_esi; + int :32; /* for compat with trap frame - err */ + int if_ebx; + int if_edx; + int if_ecx; + int if_eax; + int :32; /* for compat with trap frame - trapno */ + int if_ebp; + /* below portion defined in 386 hardware */ + int if_eip; + int if_cs; + int if_eflags; + /* below only when transitting rings (e.g. user to kernel) */ + int if_esp; + int if_ss; +}; + +/* + * iret stack frame + */ +struct iretframe { + int irf_trapno; + int irf_err; + int irf_eip; + int irf_cs; + int irf_eflags; + int irf_esp; + int irf_ss; + /* below used when switching back to VM86 mode */ + int irf_vm86_es; + int irf_vm86_ds; + int irf_vm86_fs; + int irf_vm86_gs; +}; + +/* + * Trampoline stack frame + */ +struct trampframe { + int trf__deadbeef; + int trf__kern_esp; + int trf_fs; + int trf_eax; + int trf_ebp; + int trf_trapno; + int trf_err; + int trf_eip; + int trf_cs; + int trf_eflags; + int trf_esp; + int trf_ss; + /* below used when switching out of VM86 mode */ + int trf_vm86_es; + int trf_vm86_ds; + int trf_vm86_fs; + int trf_vm86_gs; +}; + +/* + * Stack frame inside cpu_switch() + */ +struct switchframe { + int sf_edi; + int sf_esi; + int sf_ebx; + int sf_eip; +}; + +struct callframe { + struct callframe *f_frame; + int f_retaddr; + int f_arg0; +}; + +/* + * Signal frame + */ +struct sigframe { + int sf_signum; + siginfo_t *sf_sip; + struct sigcontext *sf_scp; + sig_t sf_handler; + struct sigcontext sf_sc; + siginfo_t sf_si; +}; +#endif \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/gdt.h b/lib/libc/include/x86-openbsd-none/machine/gdt.h new file mode 100644 index 0000000000..d88017f3cf --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/gdt.h @@ -0,0 +1,43 @@ +/* $OpenBSD: gdt.h,v 1.18 2024/05/22 05:51:49 jsg Exp $ */ +/* $NetBSD: gdt.h,v 1.7.10.6 2002/08/19 01:22:36 sommerfeld Exp $ */ + +/*- + * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by John T. Kohl and Charles M. Hannum. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LOCORE + +struct cpu_info; +struct pcb; +struct pmap; + +void gdt_alloc_cpu(struct cpu_info *); +void gdt_init(void); +void gdt_init_cpu(struct cpu_info *); +void setgdt(int, void *, size_t, int, int, int, int); +#endif \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/hibernate.h b/lib/libc/include/x86-openbsd-none/machine/hibernate.h new file mode 100644 index 0000000000..493fa4d82c --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/hibernate.h @@ -0,0 +1,35 @@ +/* $OpenBSD: hibernate.h,v 1.10 2018/06/21 07:33:30 mlarkin Exp $ */ + +/* + * Copyright (c) 2011 Mike Larkin + * + * 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 + +/* i386 hibernate support structures and functions */ + +int get_hibernate_info_md(union hibernate_info *); +void hibernate_flush(void); +void hibernate_enter_resume_mapping(vaddr_t, paddr_t, int); +int hibernate_inflate_skip(union hibernate_info *, paddr_t); +int hibernate_suspend(void); +void hibernate_switch_stack_machdep(void); +void hibernate_resume_machdep(vaddr_t); +void hibernate_activate_resume_pt_machdep(void); +void hibernate_enable_intr_machdep(void); +void hibernate_disable_intr_machdep(void); +#ifdef MULTIPROCESSOR +void hibernate_quiesce_cpus(void); +#endif /* MULTIPROCESSOR */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/hibernate_var.h b/lib/libc/include/x86-openbsd-none/machine/hibernate_var.h new file mode 100644 index 0000000000..e37fa095ce --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/hibernate_var.h @@ -0,0 +1,53 @@ +/* $OpenBSD: hibernate_var.h,v 1.16 2025/05/21 04:05:22 mlarkin Exp $ */ + +/* + * Copyright (c) 2011 Mike Larkin + * + * 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 HIB_PD_MASK 0xffc00000 +#define PIGLET_PAGE_MASK (HIB_PD_MASK) + +#define HIBERNATE_PD_PAGE (PAGE_SIZE * 21) +#define HIBERNATE_PT_PAGE (PAGE_SIZE * 22) +/* 2 pages for stack */ +#define HIBERNATE_STACK_PAGE (PAGE_SIZE * 24) +#define HIBERNATE_INFLATE_PAGE (PAGE_SIZE * 25) +/* HIBERNATE_HIBALLOC_PAGE must be the last stolen page (see machdep.c) */ +#define HIBERNATE_HIBALLOC_PAGE (PAGE_SIZE * 26) + +/* Use 4MB hibernation chunks */ +#define HIBERNATE_CHUNK_SIZE 0x400000 + +#define HIBERNATE_CHUNK_TABLE_SIZE 0x100000 + +#define HIBERNATE_STACK_OFFSET 0x0F00 + +#define atop_4m(x) ((x) >> PDSHIFT) +#define atop_4k(x) ((x) >> PAGE_SHIFT) +#define s4pde_4m(va) ((pt_entry_t *)HIBERNATE_PD_PAGE + atop_4m(va)) +#define s4pde_4k(va) ((pt_entry_t *)HIBERNATE_PD_PAGE + atop_4k(va)) +#define s4pte_4k(va) ((pt_entry_t *)HIBERNATE_PT_PAGE + atop_4k(va)) + +/* + * Minimum amount of memory for hibernate support. This is used in early boot + * when deciding if we can preallocate the piglet. If the machine does not + * have at least HIBERNATE_MIN_MEMORY RAM, we won't support hibernate. This + * avoids late allocation issues due to fragmented memory and failure to + * hibernate. We need to be able to allocate 16MB contiguous memory, aligned + * to 2MB. + * + * The default minimum required memory is 512MB (1ULL << 29). + */ +#define HIBERNATE_MIN_MEMORY (1ULL << 29) \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/i82093reg.h b/lib/libc/include/x86-openbsd-none/machine/i82093reg.h new file mode 100644 index 0000000000..ac97c35955 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/i82093reg.h @@ -0,0 +1,118 @@ +/* $OpenBSD: i82093reg.h,v 1.6 2022/12/08 01:25:45 guenther Exp $ */ +/* $NetBSD: i82093reg.h,v 1.1.2.2 2000/02/21 18:54:07 sommerfeld Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by RedBack Networks Inc. + * + * Author: Bill Sommerfeld + * + * 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. + */ + +/* + * Typically, the first apic lives here. + */ +#define IOAPIC_BASE_DEFAULT 0xfec00000 + +/* + * Memory-space registers. + */ + +/* + * The externally visible registers are all 32 bits wide; + * store the register number of interest in IOAPIC_REG, and store/fetch + * the real value in IOAPIC_DATA. + */ +#define IOAPIC_REG 0x0000 +#define IOAPIC_DATA 0x0010 + +/* + * Internal I/O APIC registers. + */ + +#define IOAPIC_ID 0x00 + +#define IOAPIC_ID_SHIFT 24 +#define IOAPIC_ID_MASK 0x0f000000 + +/* Version, and maximum interrupt pin number. */ + +#define IOAPIC_VER 0x01 + +#define IOAPIC_VER_SHIFT 0 +#define IOAPIC_VER_MASK 0x000000ff + +#define IOAPIC_MAX_SHIFT 16 +#define IOAPIC_MAX_MASK 0x00ff0000 + +/* + * Arbitration ID. Same format as IOAPIC_ID register. + */ +#define IOAPIC_ARB 0x02 + +/* + * Redirection table registers. + */ + +#define IOAPIC_REDHI(pin) (0x11 + ((pin)<<1)) +#define IOAPIC_REDLO(pin) (0x10 + ((pin)<<1)) + +#define IOAPIC_REDHI_DEST_SHIFT 24 /* destination. */ +#define IOAPIC_REDHI_DEST_MASK 0xff000000 + +#define IOAPIC_REDLO_MASK 0x00010000 /* 0=enabled; 1=masked */ + +#define IOAPIC_REDLO_LEVEL 0x00008000 /* 0=edge, 1=level */ +#define IOAPIC_REDLO_RIRR 0x00004000 /* remote IRR; read only */ +#define IOAPIC_REDLO_ACTLO 0x00002000 /* 0=act. hi; 1=act. lo */ +#define IOAPIC_REDLO_DELSTS 0x00001000 /* 0=idle; 1=send pending */ +#define IOAPIC_REDLO_DSTMOD 0x00000800 /* 0=physical; 1=logical */ + +#define IOAPIC_REDLO_DEL_MASK 0x00000700 /* del. mode mask */ +#define IOAPIC_REDLO_DEL_SHIFT 8 + +#define IOAPIC_REDLO_DEL_FIXED 0 +#define IOAPIC_REDLO_DEL_LOPRI 1 +#define IOAPIC_REDLO_DEL_SMI 2 +#define IOAPIC_REDLO_DEL_NMI 4 +#define IOAPIC_REDLO_DEL_INIT 5 +#define IOAPIC_REDLO_DEL_EXTINT 7 + +#define IOAPIC_REDLO_VECTOR_MASK 0x000000ff /* delivery vector */ + +#define IMCR_ADDR 0x22 +#define IMCR_DATA 0x23 + +#define IMCR_REGISTER 0x70 +#define IMCR_PIC 0x00 +#define IMCR_APIC 0x01 + +#ifdef _KERNEL + +#define ioapic_asm_ack(num) \ + movl $0,local_apic + LAPIC_EOI + +#endif \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/i82093var.h b/lib/libc/include/x86-openbsd-none/machine/i82093var.h new file mode 100644 index 0000000000..a74a367ff8 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/i82093var.h @@ -0,0 +1,99 @@ +/* $OpenBSD: i82093var.h,v 1.13 2024/10/22 21:50:02 jsg Exp $ */ +/* $NetBSD: i82093var.h,v 1.1 2003/02/26 21:26:10 fvdl Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by RedBack Networks Inc. + * + * Author: Bill Sommerfeld + * + * 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_I82093VAR_H_ +#define _MACHINE_I82093VAR_H_ + +#include + +struct ioapic_pin { + struct intrhand *ip_handler; + struct ioapic_pin *ip_next; /* next pin on this vector */ + struct mp_intr_map *ip_map; + int ip_vector; /* IDT vector */ + int ip_type; + int ip_minlevel; + int ip_maxlevel; +}; + +struct ioapic_softc { + struct pic sc_pic; + struct ioapic_softc *sc_next; + int sc_apicid; + int sc_apic_vers; + int sc_apic_vecbase; /* global int base if ACPI */ + int sc_apic_sz; /* apic size*/ + int sc_flags; + paddr_t sc_pa; /* PA of ioapic */ + volatile u_int32_t *sc_reg; /* KVA of ioapic addr */ + volatile u_int32_t *sc_data; /* KVA of ioapic data */ + struct ioapic_pin *sc_pins; /* sc_apic_sz entries */ +}; + +/* + * MP: intr_handle_t is bitfielded. + * ih&0xff -> line number. + * ih&0x10000000 -> if 0, old-style isa irq; if 1, routed via ioapic. + * (ih&0xff0000)>>16 -> ioapic id. + * (ih&0x00ff00)>>8 -> ioapic line. + */ + +#define APIC_INT_VIA_APIC 0x10000000 +#define APIC_INT_VIA_MSG 0x20000000 +#define APIC_INT_APIC_MASK 0x00ff0000 +#define APIC_INT_APIC_SHIFT 16 +#define APIC_INT_PIN_MASK 0x0000ff00 +#define APIC_INT_PIN_SHIFT 8 +#define APIC_INT_LINE_MASK 0x000000ff + +#define APIC_IRQ_APIC(x) ((x & APIC_INT_APIC_MASK) >> APIC_INT_APIC_SHIFT) +#define APIC_IRQ_PIN(x) ((x & APIC_INT_PIN_MASK) >> APIC_INT_PIN_SHIFT) + +void *apic_intr_establish(int, int, int, int (*)(void *), void *, + const char *); +void apic_intr_disestablish(void *); + +void ioapic_print_redir(struct ioapic_softc *, char *, int); +struct ioapic_softc *ioapic_find(int); +struct ioapic_softc *ioapic_find_bybase(int); + +void ioapic_enable(void); + +extern int ioapic_bsp_id; +extern int nioapics; +extern struct ioapic_softc *ioapics; +extern u_int16_t ioapic_id_map; +extern u_int8_t ioapic_id_remap[]; + +#endif /* !_MACHINE_I82093VAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/i82489reg.h b/lib/libc/include/x86-openbsd-none/machine/i82489reg.h new file mode 100644 index 0000000000..bb3c256cfb --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/i82489reg.h @@ -0,0 +1,144 @@ +/* $OpenBSD: i82489reg.h,v 1.5 2019/07/26 04:35:38 kevlo Exp $ */ +/* $NetBSD: i82489reg.h,v 1.1.2.1 2000/02/20 16:30:27 sommerfeld Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Frank van der Linden. + * + * 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. + */ + + +/* + * Registers and constants for the 82489DX and Pentium (and up) integrated + * "local" APIC. + */ + +#define LAPIC_ID 0x020 /* ID. RW */ +# define LAPIC_ID_MASK 0x0f000000 +# define LAPIC_ID_SHIFT 24 + +#define LAPIC_VERS 0x030 /* Version. R */ +# define LAPIC_VERSION_MASK 0x000000ff +# define LAPIC_VERSION_LVT_MASK 0x00ff0000 +# define LAPIC_VERSION_LVT_SHIFT 16 + +#define LAPIC_TPRI 0x080 /* Task Prio. RW */ +# define LAPIC_TPRI_MASK 0x000000ff +# define LAPIC_TPRI_INT_MASK 0x000000f0 +# define LAPIC_TPRI_SUB_MASK 0x0000000f + +#define LAPIC_APRI 0x090 /* Arbitration prio R */ +# define LAPIC_APRI_MASK 0x000000ff + +#define LAPIC_PPRI 0x0a0 /* Processor prio. R */ +#define LAPIC_EOI 0x0b0 /* End Int. W */ +#define LAPIC_RRR 0x0c0 /* Remote read R */ +#define LAPIC_LDR 0x0d0 /* Logical dest. RW */ +#define LAPIC_DFR 0x0e0 /* Dest. format RW */ + +#define LAPIC_SVR 0x0f0 /* Spurious intvec RW */ +# define LAPIC_SVR_VECTOR_MASK 0x000000ff +# define LAPIC_SVR_VEC_FIX 0x0000000f +# define LAPIC_SVR_VEC_PROG 0x000000f0 +# define LAPIC_SVR_ENABLE 0x00000100 +# define LAPIC_SVR_SWEN 0x00000100 +# define LAPIC_SVR_FOCUS 0x00000200 +# define LAPIC_SVR_FDIS 0x00000200 + +#define LAPIC_ISR 0x100 /* Int. status. R */ +#define LAPIC_TMR 0x180 +#define LAPIC_IRR 0x200 +#define LAPIC_ESR 0x280 /* Err status. R */ + +#define LAPIC_ICRLO 0x300 /* Int. cmd. RW */ +# define LAPIC_DLMODE_MASK 0x00000700 +# define LAPIC_DLMODE_FIXED 0x00000000 +# define LAPIC_DLMODE_LOW 0x00000100 +# define LAPIC_DLMODE_SMI 0x00000200 +# define LAPIC_DLMODE_RR 0x00000300 +# define LAPIC_DLMODE_NMI 0x00000400 +# define LAPIC_DLMODE_INIT 0x00000500 +# define LAPIC_DLMODE_STARTUP 0x00000600 + +# define LAPIC_DSTMODE_LOG 0x00000800 + +# define LAPIC_DLSTAT_BUSY 0x00001000 + +# define LAPIC_LVL_ASSERT 0x00004000 +# define LAPIC_LVL_DEASSERT 0x00000000 + +# define LAPIC_LVL_TRIG 0x00008000 + +# define LAPIC_RRSTAT_MASK 0x00030000 +# define LAPIC_RRSTAT_INPROG 0x00010000 +# define LAPIC_RRSTAT_VALID 0x00020000 + +# define LAPIC_DEST_MASK 0x000c0000 +# define LAPIC_DEST_SELF 0x00040000 +# define LAPIC_DEST_ALLINCL 0x00080000 +# define LAPIC_DEST_ALLEXCL 0x000c0000 + +# define LAPIC_RESV2_MASK 0xfff00000 + + +#define LAPIC_ICRHI 0x310 /* Int. cmd. RW */ + +#define LAPIC_LVTT 0x320 /* Loc.vec.(timer) RW */ +# define LAPIC_LVTT_VEC_MASK 0x000000ff +# define LAPIC_LVTT_DS 0x00001000 +# define LAPIC_LVTT_M 0x00010000 +# define LAPIC_LVTT_TM 0x00020000 +# define LAPIC_LVTT_TM_ONESHOT 0x00000000 +# define LAPIC_LVTT_TM_PERIODIC 0x00020000 +# define LAPIC_LVTT_TM_TSCDL 0x00040000 + +#define LAPIC_PCINT 0x340 +#define LAPIC_LVINT0 0x350 /* Loc.vec (LINT0) RW */ +# define LAPIC_LVT_PERIODIC 0x00020000 +# define LAPIC_LVT_MASKED 0x00010000 +# define LAPIC_LVT_LEVTRIG 0x00008000 +# define LAPIC_LVT_REMOTE_IRR 0x00004000 +# define LAPIC_INP_POL 0x00002000 +# define LAPIC_PEND_SEND 0x00001000 + +#define LAPIC_LVINT1 0x360 /* Loc.vec (LINT1) RW */ +#define LAPIC_LVERR 0x370 /* Loc.vec (ERROR) RW */ +#define LAPIC_ICR_TIMER 0x380 /* Initial count RW */ +#define LAPIC_CCR_TIMER 0x390 /* Current count RO */ + +#define LAPIC_DCR_TIMER 0x3e0 /* Divisor config register */ +# define LAPIC_DCRT_DIV1 0x0b +# define LAPIC_DCRT_DIV2 0x00 +# define LAPIC_DCRT_DIV4 0x01 +# define LAPIC_DCRT_DIV8 0x02 +# define LAPIC_DCRT_DIV16 0x03 +# define LAPIC_DCRT_DIV32 0x08 +# define LAPIC_DCRT_DIV64 0x09 +# define LAPIC_DCRT_DIV128 0x0a + +#define LAPIC_BASE 0xfee00000 + +#define LAPIC_IRQ_MASK(i) (1 << ((i) + 1)) \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/i82489var.h b/lib/libc/include/x86-openbsd-none/machine/i82489var.h new file mode 100644 index 0000000000..bfdf681171 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/i82489var.h @@ -0,0 +1,128 @@ +/* $OpenBSD: i82489var.h,v 1.16 2024/07/07 03:03:09 jsg Exp $ */ +/* $NetBSD: i82489var.h,v 1.1.2.2 2000/02/21 18:46:14 sommerfeld Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Frank van der Linden. + * + * 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_I82489VAR_H_ +#define _MACHINE_I82489VAR_H_ + +static __inline__ u_int32_t i82489_readreg(int); +static __inline__ void i82489_writereg(int, u_int32_t); + +#ifdef _KERNEL +extern volatile u_int32_t local_apic[]; +#endif + +static __inline__ u_int32_t +i82489_readreg(int reg) +{ + return *((volatile u_int32_t *)(((volatile u_int8_t *)local_apic) + + reg)); +} + +static __inline__ void +i82489_writereg(int reg, u_int32_t val) +{ + *((volatile u_int32_t *)(((volatile u_int8_t *)local_apic) + reg)) = + val; + /* + * intel xeon errata p53: + * write to a lapic register sometimes may appear to have not occurred + * workaround: + * follow write with a read [from id register] + */ + val = *((volatile u_int32_t *)(((volatile u_int8_t *)local_apic) + + LAPIC_ID)); +} + +/* + * "spurious interrupt vector"; vector used by interrupt which was + * aborted because the CPU masked it after it happened but before it + * was delivered.. "Oh, sorry, i caught you at a bad time". + * Low-order 4 bits must be all ones. + */ +extern void Xintrspurious(void); +#define LAPIC_SPURIOUS_VECTOR 0xef + +/* + * Vector used for inter-processor interrupts. + */ +extern void Xintripi(void); +#define LAPIC_IPI_VECTOR IPL_IPI + +/* + * Vector used for local apic timer interrupts. + */ + +extern void Xintrltimer(void); +#define LAPIC_TIMER_VECTOR IPL_CLOCK + +/* + * Vectors to be used for self-soft-interrupts. + */ + +#define LAPIC_SOFTCLOCK_VECTOR IPL_SOFTCLOCK +#define LAPIC_SOFTNET_VECTOR IPL_SOFTNET +#define LAPIC_SOFTTTY_VECTOR IPL_SOFTTTY + +/* + * Special IPI vectors. We can use IDT 0xf0 - 0xff for this. + */ +#define LAPIC_IPI_OFFSET 0xf0 +#define LAPIC_IPI_INVLTLB (LAPIC_IPI_OFFSET + 0) +#define LAPIC_IPI_INVLPG (LAPIC_IPI_OFFSET + 1) +#define LAPIC_IPI_INVLRANGE (LAPIC_IPI_OFFSET + 2) +#define LAPIC_IPI_RELOADCR3 (LAPIC_IPI_OFFSET + 3) + +extern void Xintripi_invltlb(void); +extern void Xintripi_invlpg(void); +extern void Xintripi_invlrange(void); +extern void Xintripi_reloadcr3(void); + +extern void Xintrsoftclock(void); +extern void Xintrsoftnet(void); +extern void Xintrsofttty(void); + +extern void (*apichandler[])(void); + +struct cpu_info; + +extern void lapic_boot_init(paddr_t); +extern void lapic_startclock(void); +extern void lapic_initclocks(void); +extern void lapic_set_lvt(void); +extern void lapic_set_softvectors(void); +extern void lapic_enable(void); +extern void lapic_disable(void); +extern void lapic_calibrate_timer(struct cpu_info *); + +#define lapic_cpu_number() (i82489_readreg(LAPIC_ID)>>LAPIC_ID_SHIFT) + +#endif \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/i8259.h b/lib/libc/include/x86-openbsd-none/machine/i8259.h new file mode 100644 index 0000000000..724ae4f4f1 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/i8259.h @@ -0,0 +1,144 @@ +/* $OpenBSD: i8259.h,v 1.7 2015/09/02 13:39:23 mikeb Exp $ */ +/* $NetBSD: i8259.h,v 1.3 2003/05/04 22:01:56 fvdl 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. + * + * @(#)icu.h 5.6 (Berkeley) 5/9/91 + */ + +#ifndef _MACHINE_I8259_H_ +#define _MACHINE_I8259_H_ + +#include + +#ifndef _LOCORE + +/* + * Interrupt "level" mechanism variables, masks, and macros + */ +extern unsigned imen; /* interrupt mask enable */ + +#define SET_ICUS() (outb(IO_ICU1 + 1, imen), outb(IO_ICU2 + 1, imen >> 8)) + +#endif /* !_LOCORE */ + +/* + * Interrupt enable bits -- in order of priority + */ +#define IRQ_SLAVE 2 + +/* + * Interrupt Control offset into Interrupt descriptor table (IDT) + */ +#define ICU_OFFSET 32 /* 0-31 are processor exceptions */ +#define ICU_LEN 16 /* 32-47 are ISA interrupts */ + + +#define ICU_HARDWARE_MASK + +/* + * These macros are fairly self explanatory. If ICU_SPECIAL_MASK_MODE is + * defined, we try to take advantage of the ICU's `special mask mode' by only + * EOIing the interrupts on return. This avoids the requirement of masking and + * unmasking. We can't do this without special mask mode, because the ICU + * would also hold interrupts that it thinks are of lower priority. + * + * Many machines do not support special mask mode, so by default we don't try + * to use it. + */ + +#define IRQ_BIT(num) (1 << ((num) % 8)) +#define IRQ_BYTE(num) ((num) >> 3) + +#define i8259_late_ack(num) + +#ifdef ICU_SPECIAL_MASK_MODE + +#define i8259_asm_ack1(num) +#define i8259_asm_ack2(num) \ + movb $(0x60|IRQ_SLAVE),%al /* specific EOI for IRQ2 */ ;\ + outb %al,$IO_ICU1 +#define i8259_asm_mask(num) +#define i8259_asm_unmask(num) \ + movb $(0x60|(num%8)),%al /* specific EOI */ ;\ + outb %al,$ICUADDR + +#else /* ICU_SPECIAL_MASK_MODE */ + +#ifndef AUTO_EOI_1 +#define i8259_asm_ack1(num) \ + movb $(0x60|(num%8)),%al /* specific EOI */ ;\ + outb %al,$IO_ICU1 +#else +#define i8259_asm_ack1(num) +#endif + +#ifndef AUTO_EOI_2 +#define i8259_asm_ack2(num) \ + movb $(0x60|(num%8)),%al /* specific EOI */ ;\ + outb %al,$IO_ICU2 /* do the second ICU first */ ;\ + movb $(0x60|IRQ_SLAVE),%al /* specific EOI for IRQ2 */ ;\ + outb %al,$IO_ICU1 +#else +#define i8259_asm_ack2(num) +#endif + +#ifdef ICU_HARDWARE_MASK + +#define i8259_asm_mask(num) \ + movb CVAROFF(imen, IRQ_BYTE(num)),%al ;\ + orb $IRQ_BIT(num),%al ;\ + movb %al,CVAROFF(imen, IRQ_BYTE(num)) ;\ + pushl %eax ;\ + inb $0x84,%al ;\ + popl %eax ;\ + outb %al,$(ICUADDR+1) +#define i8259_asm_unmask(num) \ + cli ;\ + movb CVAROFF(imen, IRQ_BYTE(num)),%al ;\ + andb $~IRQ_BIT(num),%al ;\ + movb %al,CVAROFF(imen, IRQ_BYTE(num)) ;\ + pushl %eax ;\ + inb $0x84,%al ;\ + popl %eax ;\ + outb %al,$(ICUADDR+1) ;\ + sti + +#else /* ICU_HARDWARE_MASK */ + +#define i8259_asm_mask(num) +#define i8259_asm_unmask(num) + +#endif /* ICU_HARDWARE_MASK */ +#endif /* ICU_SPECIAL_MASK_MODE */ + +#endif /* !_MACHINE_I8259_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/ieee.h b/lib/libc/include/x86-openbsd-none/machine/ieee.h new file mode 100644 index 0000000000..cc799d2c27 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/ieee.h @@ -0,0 +1,141 @@ +/* $OpenBSD: ieee.h,v 1.3 2008/09/07 20:36:06 martynas Exp $ */ +/* $NetBSD: ieee.h,v 1.1 1996/09/30 16:34:25 ws Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)ieee.h 8.1 (Berkeley) 6/11/93 + */ + +/* + * ieee.h defines the machine-dependent layout of the machine's IEEE + * floating point. It does *not* define (yet?) any of the rounding + * mode bits, exceptions, and so forth. + */ + +/* + * Define the number of bits in each fraction and exponent. + * + * k k+1 + * Note that 1.0 x 2 == 0.1 x 2 and that denorms are represented + * + * (-exp_bias+1) + * as fractions that look like 0.fffff x 2 . This means that + * + * -126 + * the number 0.10000 x 2 , for instance, is the same as the normalized + * + * -127 -128 + * float 1.0 x 2 . Thus, to represent 2 , we need one leading zero + * + * -129 + * in the fraction; to represent 2 , we need two, and so on. This + * + * (-exp_bias-fracbits+1) + * implies that the smallest denormalized number is 2 + * + * for whichever format we are talking about: for single precision, for + * + * -126 -149 + * instance, we get .00000000000000000000001 x 2 , or 1.0 x 2 , and + * + * -149 == -127 - 23 + 1. + */ +#define SNG_EXPBITS 8 +#define SNG_FRACBITS 23 + +#define DBL_EXPBITS 11 +#define DBL_FRACHBITS 20 +#define DBL_FRACLBITS 32 +#define DBL_FRACBITS 52 + +#define EXT_EXPBITS 15 +#define EXT_FRACHBITS 32 +#define EXT_FRACLBITS 32 +#define EXT_FRACBITS 64 + +#define EXT_TO_ARRAY32(p, a) do { \ + (a)[0] = (uint32_t)(p)->ext_fracl; \ + (a)[1] = (uint32_t)(p)->ext_frach; \ +} while(0) + +struct ieee_single { + u_int sng_frac:23; + u_int sng_exp:8; + u_int sng_sign:1; +}; + +struct ieee_double { + u_int dbl_fracl; + u_int dbl_frach:20; + u_int dbl_exp:11; + u_int dbl_sign:1; +}; + +struct ieee_ext { + u_int ext_fracl; + u_int ext_frach; + u_int ext_exp:15; + u_int ext_sign:1; + u_int ext_pad:16; +}; + +/* + * Floats whose exponent is in [1..INFNAN) (of whatever type) are + * `normal'. Floats whose exponent is INFNAN are either Inf or NaN. + * Floats whose exponent is zero are either zero (iff all fraction + * bits are zero) or subnormal values. + * + * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its + * high fraction; if the bit is set, it is a `quiet NaN'. + */ +#define SNG_EXP_INFNAN 255 +#define DBL_EXP_INFNAN 2047 +#define EXT_EXP_INFNAN 32767 + +#if 0 +#define SNG_QUIETNAN (1 << 22) +#define DBL_QUIETNAN (1 << 19) +#define EXT_QUIETNAN (1 << 15) +#endif + +/* + * Exponent biases. + */ +#define SNG_EXP_BIAS 127 +#define DBL_EXP_BIAS 1023 +#define EXT_EXP_BIAS 16383 \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/ieeefp.h b/lib/libc/include/x86-openbsd-none/machine/ieeefp.h new file mode 100644 index 0000000000..9a9a90bad7 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/ieeefp.h @@ -0,0 +1,26 @@ +/* $OpenBSD: ieeefp.h,v 1.3 2011/03/23 16:54:35 pirofti Exp $ */ + +/* + * Written by J.T. Conklin, Apr 6, 1995 + * Public domain. + */ + +#ifndef _MACHINE_IEEEFP_H_ +#define _MACHINE_IEEEFP_H_ + +typedef int fp_except; +#define FP_X_INV 0x01 /* invalid operation exception */ +#define FP_X_DNML 0x02 /* denormalization exception */ +#define FP_X_DZ 0x04 /* divide-by-zero exception */ +#define FP_X_OFL 0x08 /* overflow exception */ +#define FP_X_UFL 0x10 /* underflow exception */ +#define FP_X_IMP 0x20 /* imprecise (loss of precision) */ + +typedef enum { + FP_RN=0, /* round to nearest representable number */ + FP_RM=1, /* round toward negative infinity */ + FP_RP=2, /* round toward positive infinity */ + FP_RZ=3 /* round to zero (truncate) */ +} fp_rnd; + +#endif /* _MACHINE_IEEEFP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/intr.h b/lib/libc/include/x86-openbsd-none/machine/intr.h new file mode 100644 index 0000000000..299370353b --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/intr.h @@ -0,0 +1,149 @@ +/* $OpenBSD: intr.h,v 1.51 2025/04/25 12:47:37 mvs Exp $ */ +/* $NetBSD: intr.h,v 1.5 1996/05/13 06:11:28 mycroft Exp $ */ + +/* + * Copyright (c) 1996 Charles M. Hannum. 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 Charles M. Hannum. + * 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 _MACHINE_INTR_H_ +#define _MACHINE_INTR_H_ + +#define __USE_MI_SOFTINTR + +#include +#include + +#ifndef _LOCORE +#include +#include + +extern volatile u_int32_t lapic_tpr; /* Current interrupt priority level. */ + +extern int imask[]; /* Bitmasks telling what interrupts are blocked. */ +extern int iunmask[]; /* Bitmasks telling what interrupts are accepted. */ + +#define IMASK(level) imask[IPL(level)] +#define IUNMASK(level) iunmask[IPL(level)] + +extern void Xspllower(void); + +extern int splraise(int); +extern int spllower(int); +extern void splx(int); +extern void softintr(int); + +/* + * compiler barrier: prevent reordering of instructions. + * This prevents the compiler from reordering code around + * this "instruction", acting as a sequence point for code generation. + */ + +#define __splbarrier() __asm volatile("":::"memory") + +/* SPL asserts */ +#ifdef DIAGNOSTIC +/* + * Although this function is implemented in MI code, it must be in this MD + * header because we don't want this header to include MI includes. + */ +void splassert_fail(int, int, const char *); +extern int splassert_ctl; +void splassert_check(int, const char *); +#define splassert(__wantipl) do { \ + if (splassert_ctl > 0) { \ + splassert_check(__wantipl, __func__); \ + } \ +} while (0) +#define splsoftassert(wantipl) splassert(wantipl) +#else +#define splassert(wantipl) do { /* nada */ } while (0) +#define splsoftassert(wantipl) do { /* nada */ } while (0) +#endif + +/* + * Define the splraise and splx code in macros, so that the code can be + * reused in a profiling build in a way that does not cause recursion. + */ +#define _SPLRAISE(ocpl, ncpl) \ + ocpl = lapic_tpr; \ + if (ncpl > ocpl) \ + lapic_tpr = ncpl + + +#define _SPLX(ncpl) \ + lapic_tpr = ncpl; \ + if (curcpu()->ci_ipending & IUNMASK(ncpl)) \ + Xspllower() + +/* + * Hardware interrupt masks + */ +#define splbio() splraise(IPL_BIO) +#define splnet() splraise(IPL_NET) +#define spltty() splraise(IPL_TTY) +#define splaudio() splraise(IPL_AUDIO) +#define splclock() splraise(IPL_CLOCK) +#define splstatclock() splclock() +#define splipi() splraise(IPL_IPI) + +/* + * Software interrupt masks + */ +#define splsoftclock() splraise(IPL_SOFTCLOCK) +#define splsoftnet() splraise(IPL_SOFTNET) +#define splsofttty() splraise(IPL_SOFTTTY) + +/* + * Miscellaneous + */ +#define splvm() splraise(IPL_VM) +#define splhigh() splraise(IPL_HIGH) +#define splsched() splraise(IPL_SCHED) +#define spl0() spllower(IPL_NONE) + +#include + +struct cpu_info; + +void intr_barrier(void *); +void intr_enable_wakeup(void); +void intr_disable_wakeup(void); + +#ifdef MULTIPROCESSOR +void i386_send_ipi(struct cpu_info *, int); +int i386_fast_ipi(struct cpu_info *, int); +void i386_broadcast_ipi(int); +void i386_ipi_handler(void); +void i386_setperf_ipi(struct cpu_info *); + +extern void (*ipifunc[I386_NIPI])(struct cpu_info *); +#endif + +#endif /* !_LOCORE */ + +#endif /* !_MACHINE_INTR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/intrdefs.h b/lib/libc/include/x86-openbsd-none/machine/intrdefs.h new file mode 100644 index 0000000000..dedc83ff03 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/intrdefs.h @@ -0,0 +1,126 @@ +/* $OpenBSD: intrdefs.h,v 1.20 2025/06/11 09:57:01 kettenis Exp $ */ +/* $NetBSD: intrdefs.h,v 1.2 2003/05/04 22:01:56 fvdl Exp $ */ + +#ifndef _I386_INTRDEFS_H +#define _I386_INTRDEFS_H + +/* + * Intel APICs (advanced programmable interrupt controllers) have + * bytesized priority registers where the upper nibble is the actual + * interrupt priority level (a.k.a. IPL). Interrupt vectors are + * closely tied to these levels as interrupts whose vectors' upper + * nibble is lower than or equal to the current level are blocked. + * Not all 256 possible vectors are available for interrupts in + * APIC systems, only + * + * For systems where instead the older ICU (interrupt controlling + * unit, a.k.a. PIC or 82C59) is used, the IPL is not directly useful, + * since the interrupt blocking is handled via interrupt masks instead + * of levels. However the IPL is easily used as an offset into arrays + * of masks. + */ +#define IPLSHIFT 4 /* The upper nibble of vectors is the IPL. */ +#define NIPL 16 /* Four bits of information gives as much. */ +#define IPL(level) ((level) >> IPLSHIFT) /* Extract the IPL. */ +/* XXX Maybe this IDTVECOFF definition should be elsewhere? */ +#define IDTVECOFF 0x20 /* The lower 32 IDT vectors are reserved. */ + +/* + * This macro is only defined for 0 <= x < 14, i.e. there are fourteen + * distinct priority levels available for interrupts. + */ +#define MAKEIPL(priority) (IDTVECOFF + ((priority) << IPLSHIFT)) + +/* + * Interrupt priority levels. + * + * XXX We are somewhat sloppy about what we mean by IPLs, sometimes + * XXX we refer to the eight-bit value suitable for storing into APICs' + * XXX priority registers, other times about the four-bit entity found + * XXX in the former values' upper nibble, which can be used as offsets + * XXX in various arrays of our implementation. We are hoping that + * XXX the context will provide enough information to not make this + * XXX sloppy naming a real problem. + * + * There are tty, network and disk drivers that use free() at interrupt + * time, so imp > (tty | net | bio). + * + * Since run queues may be manipulated by both the statclock and tty, + * network, and disk drivers, clock > imp. + * + * IPL_HIGH must block everything that can manipulate a run queue. + * + * XXX Ultimately we may need serial drivers to run at the absolute highest + * XXX priority to avoid overruns, then we must make serial > high. + * + * The level numbers are picked to fit into APIC vector priorities. + */ +#define IPL_NONE 0 /* nothing */ +#define IPL_SOFTCLOCK MAKEIPL(1) /* timeouts */ +#define IPL_SOFTNET MAKEIPL(2) /* protocol stacks */ +#define IPL_BIO MAKEIPL(3) /* block I/O */ +#define IPL_NET MAKEIPL(4) /* network */ +#define IPL_SOFTTTY MAKEIPL(5) /* delayed terminal handling */ +#define IPL_TTY MAKEIPL(6) /* terminal */ +#define IPL_VM MAKEIPL(7) /* memory allocation */ +#define IPL_AUDIO MAKEIPL(8) /* audio */ +#define IPL_CLOCK MAKEIPL(9) /* clock */ +#define IPL_STATCLOCK IPL_CLOCK /* statclock */ +#define IPL_SCHED IPL_CLOCK +#define IPL_HIGH MAKEIPL(10) /* everything */ +#define IPL_IPI MAKEIPL(11) /* interprocessor interrupt */ + +#define IPL_MPFLOOR IPL_TTY +#define IPL_MPSAFE 0x100 +#define IPL_WAKEUP 0 + +/* Interrupt sharing types. */ +#define IST_NONE 0 /* none */ +#define IST_PULSE 1 /* pulsed */ +#define IST_EDGE 2 /* edge-triggered */ +#define IST_LEVEL 3 /* level-triggered */ + +/* + * Local APIC masks. Must not conflict with SIR_* below, and must + * be >= NUM_LEGACY_IRQs. Note that LIR_IPI must be first. + */ +#define LIR_IPI 31 +#define LIR_TIMER 30 + +/* Soft interrupt masks. */ +#define SIR_CLOCK 29 +#define SIR_NET 28 +#define SIR_TTY 27 + + +/* + * Maximum # of interrupt sources per CPU. 32 to fit in one word. + * ioapics can theoretically produce more, but it's not likely to + * happen. For multiple ioapics, things can be routed to different + * CPUs. + */ +#define MAX_INTR_SOURCES 32 +#define NUM_LEGACY_IRQS 16 + +/* + * Low and high boundaries between which interrupt gates will + * be allocated in the IDT. + */ +#define IDT_INTR_LOW (0x20 + NUM_LEGACY_IRQS) +#define IDT_INTR_HIGH 0xef + +#define I386_IPI_HALT 0x00000001 +#define I386_IPI_NOP 0x00000002 +#define I386_IPI_FLUSH_FPU 0x00000004 +#define I386_IPI_SYNCH_FPU 0x00000008 +#define I386_IPI_MTRR 0x00000010 +#define I386_IPI_GDT 0x00000020 +#define I386_IPI_DDB 0x00000040 /* synchronize while in ddb */ +#define I386_IPI_SETPERF 0x00000080 +#define I386_IPI_WBINVD 0x00000100 + +#define I386_NIPI 9 + +#define IREENT_MAGIC 0x18041969 + +#endif /* _I386_INTRDEFS_H */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/ioctl_fd.h b/lib/libc/include/x86-openbsd-none/machine/ioctl_fd.h new file mode 100644 index 0000000000..a370bf56f6 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/ioctl_fd.h @@ -0,0 +1,131 @@ +/* $OpenBSD: ioctl_fd.h,v 1.4 2011/03/23 16:54:35 pirofti Exp $ */ +/* from: ioctl_fd.h,v 1.4 1995/06/29 03:49:32 jtk Exp */ + +/* + * Copyright (C) 1992-1994 by Joerg Wunsch, Dresden + * 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(S) ``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(S) 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: Id: ioctl_fd.h,v 1.7 1994/10/30 19:17:39 joerg Exp + */ + +#ifndef _MACHINE_IOCTL_FD_H_ +#define _MACHINE_IOCTL_FD_H_ + +#include + +#define FD_FORMAT_VERSION 110 /* used to validate before formatting */ +#define FD_MAX_NSEC 36 /* highest known number of spt - allow for */ + /* 2.88 MB drives */ + +struct fd_formb { + int format_version; /* == FD_FORMAT_VERSION */ + int cyl, head; + int transfer_rate; /* fdreg.h: FDC_???KBPS */ + + union { + struct fd_form_data { + /* + * DO NOT CHANGE THE LAYOUT OF THIS STRUCTS + * it is hardware-dependant since it exactly + * matches the byte sequence to write to FDC + * during its `format track' operation + */ + u_char secshift; /* 0 -> 128, ...; usually 2 -> 512 */ + u_char nsecs; /* must be <= FD_MAX_NSEC */ + u_char gaplen; /* GAP 3 length; usually 84 */ + u_char fillbyte; /* usually 0xf6 */ + struct fd_idfield_data { + /* + * data to write into id fields; + * for obscure formats, they mustn't match + * the real values (but mostly do) + */ + u_char cylno; /* 0 thru 79 (or 39) */ + u_char headno; /* 0, or 1 */ + u_char secno; /* starting at 1! */ + u_char secsize; /* usually 2 */ + } idfields[FD_MAX_NSEC]; /* 0 <= idx < nsecs used */ + } structured; + u_char raw[1]; /* to have continuous indexed access */ + } format_info; +}; + +/* make life easier */ +# define fd_formb_secshift format_info.structured.secshift +# define fd_formb_nsecs format_info.structured.nsecs +# define fd_formb_gaplen format_info.structured.gaplen +# define fd_formb_fillbyte format_info.structured.fillbyte +/* these data must be filled in for(i = 0; i < fd_formb_nsecs; i++) */ +# define fd_formb_cylno(i) format_info.structured.idfields[i].cylno +# define fd_formb_headno(i) format_info.structured.idfields[i].headno +# define fd_formb_secno(i) format_info.structured.idfields[i].secno +# define fd_formb_secsize(i) format_info.structured.idfields[i].secsize + +/* + * Floppies come in various flavors, e.g., 1.2MB vs 1.44MB; here is how + * we tell them apart. + */ +struct fd_type { + int sectrac; /* sectors per track */ + int heads; /* number of heads */ + int seccyl; /* sectors per cylinder */ + int secsize; /* size code for sectors */ + int datalen; /* data len when secsize = 0 */ + int steprate; /* step rate and head unload time */ + int gap1; /* gap len between sectors */ + int gap2; /* formatting gap */ + int tracks; /* total num of tracks */ + int size; /* size of disk in sectors */ + int step; /* steps per cylinder */ + int rate; /* transfer speed code */ + char *name; +}; + + +#define FD_FORM _IOW('F', 61, struct fd_formb) /* format a track */ +#define FD_GTYPE _IOR('F', 62, struct fd_type) /* get drive type */ +#define FD_STYPE _IOW('F', 63, struct fd_type) /* set drive type */ + +#define FD_GOPTS _IOR('F', 64, int) /* drive options, see below */ +#define FD_SOPTS _IOW('F', 65, int) + +#define FDOPT_NORETRY 0x0001 /* no retries on failure (cleared on close) */ + +/* + * The following definitions duplicate those in sys/i386/isa/fdreg.h + * They are here since their values are to be used in the above + * structure when formatting a floppy. For very obvious reasons, both + * definitions must match ;-) + */ +#ifndef FDC_500KBPS +#define FDC_500KBPS 0x00 /* 500KBPS MFM drive transfer rate */ +#define FDC_300KBPS 0x01 /* 300KBPS MFM drive transfer rate */ +#define FDC_250KBPS 0x02 /* 250KBPS MFM drive transfer rate */ +#define FDC_125KBPS 0x03 /* 125KBPS FM drive transfer rate */ + /* for some controllers 1MPBS instead */ +#endif /* FDC_500KBPS */ + + +#endif /* !_MACHINE_IOCTL_FD_H__ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/joystick.h b/lib/libc/include/x86-openbsd-none/machine/joystick.h new file mode 100644 index 0000000000..2d55604d07 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/joystick.h @@ -0,0 +1,23 @@ +/* $OpenBSD: joystick.h,v 1.6 2011/03/23 16:54:35 pirofti Exp $ */ +/* $NetBSD: joystick.h,v 1.1 1996/03/27 19:18:56 perry Exp $ */ + +#ifndef _MACHINE_JOYSTICK_H_ +#define _MACHINE_JOYSTICK_H_ + +#include + +struct joystick { + int x; + int y; + int b1; + int b2; +}; + +#define JOY_SETTIMEOUT _IOW('J', 1, int) /* set timeout */ +#define JOY_GETTIMEOUT _IOR('J', 2, int) /* get timeout */ +#define JOY_SET_X_OFFSET _IOW('J', 3, int) /* set offset on X-axis */ +#define JOY_SET_Y_OFFSET _IOW('J', 4, int) /* set offset on Y-axis */ +#define JOY_GET_X_OFFSET _IOR('J', 5, int) /* get offset on X-axis */ +#define JOY_GET_Y_OFFSET _IOR('J', 6, int) /* get offset on Y-axis */ + +#endif /* _MACHINE_JOYSTICK_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/kcore.h b/lib/libc/include/x86-openbsd-none/machine/kcore.h new file mode 100644 index 0000000000..24e2327051 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/kcore.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2011 Mike Larkin + * + * 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_KCORE_H_ +#define _MACHINE_KCORE_H_ + +struct dumpmem { + paddr_t start; + paddr_t end; +}; + +#endif /* _MACHINE_KCORE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/limits.h b/lib/libc/include/x86-openbsd-none/machine/limits.h new file mode 100644 index 0000000000..86b69dfadb --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/limits.h @@ -0,0 +1,53 @@ +/* $OpenBSD: limits.h,v 1.14 2015/04/30 13:42:08 millert Exp $ */ +/* $NetBSD: limits.h,v 1.11 1995/12/21 01:08:59 mycroft 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. + * + * @(#)limits.h 7.2 (Berkeley) 6/28/90 + */ + +#ifndef _MACHINE_LIMITS_H_ +#define _MACHINE_LIMITS_H_ + +#include + +#if __POSIX_VISIBLE || __XPG_VISIBLE +#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_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/loadfile_machdep.h b/lib/libc/include/x86-openbsd-none/machine/loadfile_machdep.h new file mode 100644 index 0000000000..6a9232df70 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/loadfile_machdep.h @@ -0,0 +1,55 @@ +/* $OpenBSD: loadfile_machdep.h,v 1.8 2019/04/10 04:17:35 deraadt Exp $ */ +/* $NetBSD: loadfile_machdep.h,v 1.1 1999/04/29 03:17:12 tsubai Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * 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. + */ + +#define BOOT_ELF +#define BOOT_ELF32 +#define BOOT_ELF64 + +/* Keep a default ELFSIZE */ +#define ELFSIZE 32 + +#define LOAD_KERNEL LOAD_ALL +#define COUNT_KERNEL COUNT_ALL + +#define LOADADDR(a) ((((u_long)(a)) + offset)&0xfffffff) +#define ALIGNENTRY(a) ((u_long)(a)) +#define READ(f, b, c) read((f), (void *)LOADADDR(b), (size_t)(c)) +#define BCOPY(s, d, c) memcpy((void *)LOADADDR(d), (void *)(s), (c)) +#define BZERO(d, c) memset((void *)LOADADDR(d), 0, (c)) +#define WARN(a) (void)(printf a, \ + printf((errno ? ": %s\n" : "\n"), \ + strerror(errno))) +#define PROGRESS(a) (void) printf a +#define ALLOC(a) alloc(a) +#define FREE(a, b) free(a, b) + +void run_loadfile(uint64_t *, int); \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/mpbiosreg.h b/lib/libc/include/x86-openbsd-none/machine/mpbiosreg.h new file mode 100644 index 0000000000..37b3615c41 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/mpbiosreg.h @@ -0,0 +1,155 @@ +/* $OpenBSD: mpbiosreg.h,v 1.6 2023/04/10 04:21:20 jsg Exp $ */ +/* $NetBSD: mpbiosreg.h,v 1.1.2.3 2000/02/29 13:17:51 sommerfeld Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by RedBack Networks Inc. + * + * Author: Bill Sommerfeld + * + * 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_MPBIOSREG_H_ +#define _MACHINE_MPBIOSREG_H_ + +#define BIOS_BASE (0xf0000) +#define BIOS_SIZE (0x10000) +#define BIOS_COUNT (BIOS_SIZE) + +/* + * Multiprocessor config table entry types. + */ + +#define MPS_MCT_CPU 0 +#define MPS_MCT_BUS 1 +#define MPS_MCT_IOAPIC 2 +#define MPS_MCT_IOINT 3 +#define MPS_MCT_LINT 4 + +#define MPS_MCT_NTYPES 5 + +/* + * Interrupt types + */ + +#define MPS_INTTYPE_INT 0 +#define MPS_INTTYPE_NMI 1 +#define MPS_INTTYPE_SMI 2 +#define MPS_INTTYPE_ExtINT 3 + +#define MPS_INTPO_DEF 0 +#define MPS_INTPO_ACTHI 1 +#define MPS_INTPO_ACTLO 3 +#define MPS_INTPO_SHIFT 0 +#define MPS_INTPO_MASK 3 + +#define MPS_INTTR_DEF 0 +#define MPS_INTTR_EDGE 1 +#define MPS_INTTR_LEVEL 3 +#define MPS_INTTR_SHIFT 2 +#define MPS_INTTR_MASK 3 + +#define MPS_INT(p,t) \ + ((((p) & MPS_INTPO_MASK) << MPS_INTPO_SHIFT) | \ + (((t) & MPS_INTTR_MASK) << MPS_INTTR_SHIFT)) + +/* MP Floating Pointer Structure */ +struct mpbios_fps { + u_int32_t signature; +/* string defined by the Intel MP Spec as identifying the MP table */ +#define MP_FP_SIG 0x5f504d5f /* _MP_ */ + + u_int32_t pap; + u_int8_t length; + u_int8_t spec_rev; + u_int8_t checksum; + u_int8_t mpfb1; /* system configuration */ + u_int8_t mpfb2; /* flags */ +#define MPFPS_FLAG_IMCR 0x80 /* IMCR present */ + u_int8_t mpfb3; /* unused */ + u_int8_t mpfb4; /* unused */ + u_int8_t mpfb5; /* unused */ +}; + +/* MP Configuration Table Header */ +struct mpbios_cth { + u_int32_t signature; +#define MP_CT_SIG 0x504d4350 /* PCMP */ + + u_int16_t base_len; + u_int8_t spec_rev; + u_int8_t checksum; + u_int8_t oem_id[8]; + u_int8_t product_id[12]; + u_int32_t oem_table_pointer; + u_int16_t oem_table_size; + u_int16_t entry_count; + u_int32_t apic_address; + u_int16_t ext_len; + u_int8_t ext_cksum; + u_int8_t reserved; +}; + +struct mpbios_proc { + u_int8_t type; + u_int8_t apic_id; + u_int8_t apic_version; + u_int8_t cpu_flags; +#define PROCENTRY_FLAG_EN 0x01 +#define PROCENTRY_FLAG_BP 0x02 + u_long cpu_signature; + u_long feature_flags; + u_long reserved1; + u_long reserved2; +}; + +struct mpbios_bus { + u_int8_t type; + u_int8_t bus_id; + char bus_type[6]; +}; + +struct mpbios_ioapic { + u_int8_t type; + u_int8_t apic_id; + u_int8_t apic_version; + u_int8_t apic_flags; +#define IOAPICENTRY_FLAG_EN 0x01 + void *apic_address; +}; + +struct mpbios_int { + u_int8_t type; + u_int8_t int_type; + u_int16_t int_flags; + u_int8_t src_bus_id; + u_int8_t src_bus_irq; + u_int8_t dst_apic_id; +#define MPS_ALL_APICS 0xff + u_int8_t dst_apic_int; +}; + +#endif /* !_MACHINE_MPBIOSREG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/mpbiosvar.h b/lib/libc/include/x86-openbsd-none/machine/mpbiosvar.h new file mode 100644 index 0000000000..6c0bc7a525 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/mpbiosvar.h @@ -0,0 +1,86 @@ +/* $OpenBSD: mpbiosvar.h,v 1.13 2024/10/22 21:50:02 jsg Exp $ */ +/* $NetBSD: mpbiosvar.h,v 1.1.2.3 2000/02/29 13:17:20 sommerfeld Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by RedBack Networks Inc. + * + * Author: Bill Sommerfeld + * + * 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_MPBIOSVAR_H_ +#define _MACHINE_MPBIOSVAR_H_ + +#define MP_TRAMPOLINE (16 * PAGE_SIZE) +#define MP_TRAMP_DATA (17 * PAGE_SIZE) + +#if !defined(_LOCORE) + +#include + +struct mp_bus { + char *mb_name; /* XXX bus name */ + int mb_idx; /* XXX bus index */ + void (*mb_intr_print) (int); + void (*mb_intr_cfg)(const struct mpbios_int *, u_int32_t *); + struct mp_intr_map *mb_intrs; + u_int32_t mb_data; /* random bus-specific datum. */ +}; + +struct mp_intr_map { + struct mp_intr_map *next; + struct mp_bus *bus; + int bus_pin; + struct ioapic_softc *ioapic; + int ioapic_pin; + int ioapic_ih; /* int handle, for apic_intr_est */ + int type; /* from mp spec intr record */ + int flags; /* from mp spec intr record */ + u_int32_t redir; + int cpu_id; +}; + +#if defined(_KERNEL) +extern int mp_verbose; +extern struct mp_bus *mp_busses; +extern int mp_nbusses; +extern struct mp_intr_map *mp_intrs; +extern int mp_nintrs; +extern struct mp_bus *mp_isa_bus; +extern struct mp_bus *mp_eisa_bus; + +void mpbios_scan(struct device *); +int mpbios_probe(struct device *); +int mpbios_invent(int, int, int); + +void mpbios_intr_fixup(void); +#endif + +#endif + +#endif /* !_MACHINE_MPBIOSVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/mutex.h b/lib/libc/include/x86-openbsd-none/machine/mutex.h new file mode 100644 index 0000000000..3aa5554e53 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/mutex.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mutex.h,v 1.13 2018/01/25 15:06:29 mpi Exp $ */ + +#define __USE_MI_MUTEX \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/npx.h b/lib/libc/include/x86-openbsd-none/machine/npx.h new file mode 100644 index 0000000000..004a44af61 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/npx.h @@ -0,0 +1,158 @@ +/* $OpenBSD: npx.h,v 1.20 2021/03/11 11:16:57 jsg Exp $ */ +/* $NetBSD: npx.h,v 1.11 1994/10/27 04:16:11 cgd 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. + * + * @(#)npx.h 5.3 (Berkeley) 1/18/91 + */ + +/* + * 287/387 NPX Coprocessor Data Structures and Constants + * W. Jolitz 1/90 + */ + +#ifndef _MACHINE_NPX_H_ +#define _MACHINE_NPX_H_ + +/* Environment information of floating point unit */ +struct env87 { + long en_cw; /* control word (16bits) */ + long en_sw; /* status word (16bits) */ + long en_tw; /* tag word (16bits) */ + long en_fip; /* floating point instruction pointer */ + u_short en_fcs; /* floating code segment selector */ + u_short en_opcode; /* opcode last executed (11 bits ) */ + long en_foo; /* floating operand offset */ + long en_fos; /* floating operand segment selector */ +}; + +#define EN_SW_IE 0x0001 /* invalid operation */ +#define EN_SW_DE 0x0002 /* denormal */ +#define EN_SW_ZE 0x0004 /* divide by zero */ +#define EN_SW_OE 0x0008 /* overflow */ +#define EN_SW_UE 0x0010 /* underflow */ +#define EN_SW_PE 0x0020 /* loss of precision */ + +/* Contents of each floating point accumulator */ +struct fpacc87 { +#ifdef dontdef /* too unportable */ + u_long fp_mantlo; /* mantissa low (31:0) */ + u_long fp_manthi; /* mantissa high (63:32) */ + int fp_exp:15; /* exponent */ + int fp_sgn:1; /* mantissa sign */ +#else + u_char fp_bytes[10]; +#endif +}; + +/* Floating point and emulator context */ +struct save87 { + struct env87 sv_env; /* floating point control/status */ + struct fpacc87 sv_ac[8]; /* accumulator contents, 0-7 */ + u_long sv_ex_sw; /* status word for last exception */ + u_long sv_ex_tw; /* tag word for last exception */ +}; + +/* Environment of FPU/MMX/SSE/SSE2. */ +struct envxmm { +/*0*/ uint16_t en_cw; /* FPU Control Word */ + uint16_t en_sw; /* FPU Status Word */ + uint8_t en_tw; /* FPU Tag Word (abridged) */ + uint8_t en_rsvd0; + uint16_t en_opcode; /* FPU Opcode */ + uint32_t en_fip; /* FPU Instruction Pointer */ + uint16_t en_fcs; /* FPU IP selector */ + uint16_t en_rsvd1; +/*16*/ uint32_t en_foo; /* FPU Data pointer */ + uint16_t en_fos; /* FPU Data pointer selector */ + uint16_t en_rsvd2; + uint32_t en_mxcsr; /* MXCSR Register State */ + uint32_t en_mxcsr_mask; /* Mask for valid MXCSR bits (may be 0) */ +}; + +/* FPU registers in the extended save format. */ +struct fpaccxmm { + uint8_t fp_bytes[10]; + uint8_t fp_rsvd[6]; +}; + +/* SSE/SSE2 registers. */ +struct xmmreg { + uint8_t sse_bytes[16]; +}; + +/* FPU/MMX/SSE/SSE2 context */ +struct savexmm { + struct envxmm sv_env; /* control/status context */ + struct fpaccxmm sv_ac[8]; /* ST/MM regs */ + struct xmmreg sv_xmmregs[8]; /* XMM regs */ + uint8_t sv_rsvd[16 * 14]; + /* 512-bytes --- end of hardware portion of save area */ + uint32_t sv_ex_sw; /* saved SW from last exception */ + uint32_t sv_ex_tw; /* saved TW from last exception */ +}; + +union savefpu { + struct save87 sv_87; + struct savexmm sv_xmm; +}; + +#define __INITIAL_NPXCW__ 0x037f + +/* + * The default MXCSR value at reset is 0x1f80, IA-32 Instruction + * Set Reference, pg. 3-369. + */ +#define __INITIAL_MXCSR__ 0x1f80 +#define __INITIAL_MXCSR_MASK__ 0xffbf + +/* + * The standard control word from finit is 0x37F, giving: + * round to nearest + * 64-bit precision + * all exceptions masked. + */ + +void process_xmm_to_s87(const struct savexmm *, struct save87 *); +void process_s87_to_xmm(const struct save87 *, struct savexmm *); + +struct cpu_info; +struct trapframe; + +extern uint32_t fpu_mxcsr_mask; + +void npxinit(struct cpu_info *); +void npxtrap(struct trapframe *); +void fpu_kernel_enter(void); +void fpu_kernel_exit(void); + +#endif /* !_MACHINE_NPX_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/param.h b/lib/libc/include/x86-openbsd-none/machine/param.h new file mode 100644 index 0000000000..8fa4384646 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/param.h @@ -0,0 +1,80 @@ +/* $OpenBSD: param.h,v 1.53 2023/12/14 13:26:49 claudio 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 +#ifdef _LOCORE +#include +#else +#include +#endif +#endif + +#define _MACHINE i386 +#define MACHINE "i386" +#define _MACHINE_ARCH i386 +#define MACHINE_ARCH "i386" +#define MID_MACHINE MID_I386 + +#define PAGE_SHIFT 12 +#define PAGE_SIZE (1 << PAGE_SHIFT) +#define PAGE_MASK (PAGE_SIZE - 1) + +#define KERNBASE 0xd0000000 + +#ifdef _KERNEL + +#define KERNTEXTOFF (KERNBASE+0x200000) /* start of kernel text */ + +#define NBPG PAGE_SIZE /* bytes/page */ +#define PGSHIFT PAGE_SHIFT /* LOG2(PAGE_SIZE) */ +#define PGOFSET PAGE_MASK /* byte offset into page */ + +#define UPAGES 3 /* 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 (32 * 1024) /* max cluster allocation */ + +#ifndef MSGBUFSIZE +#define MSGBUFSIZE (8 * PAGE_SIZE) /* default message buffer size */ +#endif + +#define __HAVE_ACPI + +#endif /* _KERNEL */ + +#endif /* _MACHINE_PARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/pcb.h b/lib/libc/include/x86-openbsd-none/machine/pcb.h new file mode 100644 index 0000000000..ae727d2d47 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/pcb.h @@ -0,0 +1,78 @@ +/* $OpenBSD: pcb.h,v 1.25 2022/02/21 14:26:19 jsg Exp $ */ +/* $NetBSD: pcb.h,v 1.21 1996/01/08 13:51:42 mycroft Exp $ */ + +/*- + * Copyright (c) 1995 Charles M. Hannum. All rights reserved. + * 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. + * + * @(#)pcb.h 5.10 (Berkeley) 5/12/91 + */ + +/* + * Intel 386 process control block + */ + +#ifndef _MACHINE_PCB_H_ +#define _MACHINE_PCB_H_ + +#include + +#include +#include +#include + +/* + * Please note that pcb_savefpu must be aligned to 16 bytes. + */ +struct pcb { + union savefpu pcb_savefpu; /* floating point state for FPU */ + int pcb_cr3; + int pcb_esp; + int pcb_ebp; + int pcb_kstack; /* kernel stack address */ + int pcb_cr0; /* saved image of CR0 */ + caddr_t pcb_onfault; /* copyin/out fault recovery */ + struct segment_descriptor pcb_threadsegs[2]; + /* per-thread descriptors */ + int vm86_eflags; /* virtual eflags for vm86 mode */ + int vm86_flagmask; /* flag mask for vm86 mode */ + void *vm86_userp; /* XXX performance hack */ + struct pmap *pcb_pmap; /* back pointer to our pmap */ + struct cpu_info *pcb_fpcpu; /* cpu holding our fpu state */ + int pcb_flags; +#define PCB_SAVECTX 0x00000001 +}; + +/* the indexes of the %fs/%gs segments in pcb_threadsegs */ +#define TSEG_FS 0 +#define TSEG_GS 1 + +#endif /* _MACHINE_PCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/pctr.h b/lib/libc/include/x86-openbsd-none/machine/pctr.h new file mode 100644 index 0000000000..91c0e3f0b0 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/pctr.h @@ -0,0 +1,93 @@ +/* $OpenBSD: pctr.h,v 1.17 2014/03/29 18:09:29 guenther Exp $ */ + +/* + * Pentium performance counter driver for OpenBSD. + * Copyright 1996 David Mazieres . + * + * Modification and redistribution in source and binary forms is + * permitted provided that due credit is given to the author and the + * OpenBSD project by leaving this copyright notice intact. + */ + +#ifndef _MACHINE_PCTR_H_ +#define _MACHINE_PCTR_H_ + +#include + +typedef u_int64_t pctrval; + +#define PCTR_NUM 4 + +struct pctrst { + u_int pctr_fn[PCTR_NUM]; /* Current settings of counters */ + pctrval pctr_tsc; /* Free-running 64-bit cycle counter */ + pctrval pctr_hwc[PCTR_NUM]; /* Values of the hardware counters */ +}; + +/* Bit values in fn fields and PIOCS ioctl's */ +#define P5CTR_K 0x40 /* Monitor kernel-level events */ +#define P5CTR_U 0x80 /* Monitor user-level events */ +#define P5CTR_C 0x100 /* count cycles rather than events */ + +#define PCTR_U 0x010000 /* Monitor user-level events */ +#define PCTR_K 0x020000 /* Monitor kernel-level events */ +#define PCTR_E 0x040000 /* Edge detect */ +#define PCTR_EN 0x400000 /* Enable counters (counter 0 only) */ +#define PCTR_I 0x800000 /* Invert counter mask */ + +/* Unit Mask bits */ +#define PCTR_UM_M 0x0800 /* Modified cache lines */ +#define PCTR_UM_E 0x0400 /* Exclusive cache lines */ +#define PCTR_UM_S 0x0200 /* Shared cache lines */ +#define PCTR_UM_I 0x0100 /* Invalid cache lines */ +#define PCTR_UM_MESI (PCTR_UM_M|PCTR_UM_E|PCTR_UM_S|PCTR_UM_I) +#define PCTR_UM_A 0x2000 /* Any initiator */ + +#define PCTR_UM_SHIFT 8 /* Left shift for unit mask */ +#define PCTR_CM_SHIFT 24 /* Left shift for counter mask */ + +/* ioctl to set which counter a device tracks */ +#define PCIOCRD _IOR('c', 1, struct pctrst) /* Read counter value */ +#define PCIOCS0 _IOW('c', 8, unsigned int) /* Set counter 0 function */ +#define PCIOCS1 _IOW('c', 9, unsigned int) /* Set counter 1 function */ +#define PCIOCS2 _IOW('c', 10, unsigned int) /* Set counter 0 function */ +#define PCIOCS3 _IOW('c', 11, unsigned int) /* Set counter 1 function */ + +#define _PATH_PCTR "/dev/pctr" + +#define rdtsc() \ +({ \ + pctrval v; \ + __asm volatile ("rdtsc" : "=A" (v)); \ + v; \ +}) + +/* Read the performance counters (Pentium Pro only) */ +#define rdpmc(ctr) \ +({ \ + pctrval v; \ + __asm volatile ("rdpmc\n" \ + "\tandl $0xff, %%edx" \ + : "=A" (v) : "c" (ctr)); \ + v; \ +}) + +#ifdef _KERNEL + +#define rdmsr(msr) \ +({ \ + pctrval v; \ + __asm volatile ("rdmsr" : "=A" (v) : "c" (msr)); \ + v; \ +}) + +#define wrmsr(msr, v) \ + __asm volatile ("wrmsr" :: "A" ((u_int64_t) (v)), "c" (msr)); + +void pctrattach(int); +int pctropen(dev_t, int, int, struct proc *); +int pctrclose(dev_t, int, int, struct proc *); +int pctrioctl(dev_t, u_long, caddr_t, int, struct proc *); + +#endif /* _KERNEL */ +#endif /* ! _MACHINE_PCTR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/pic.h b/lib/libc/include/x86-openbsd-none/machine/pic.h new file mode 100644 index 0000000000..26b88fde76 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/pic.h @@ -0,0 +1,42 @@ +/* $OpenBSD: pic.h,v 1.2 2014/12/16 21:40:05 tedu Exp $ */ +/* $NetBSD: pic.h,v 1.1 2003/02/26 21:26:11 fvdl Exp $ */ + +#ifndef _X86_PIC_H +#define _X86_PIC_H + +#include +#include + +struct cpu_info; + +/* + * Structure common to all PIC softcs + */ +struct pic { + struct device pic_dev; + int pic_type; +#ifdef MULTIPROCESSOR + struct mutex pic_mutex; +#endif + void (*pic_hwmask)(struct pic *, int); + void (*pic_hwunmask)(struct pic *, int); + void (*pic_addroute)(struct pic *, struct cpu_info *, int, int, int); + void (*pic_delroute)(struct pic *, struct cpu_info *, int, int, int); + struct intrstub *pic_level_stubs; + struct intrstub *pic_edge_stubs; +}; + +#define pic_name pic_dev.dv_xname + +/* + * PIC types. + */ +#define PIC_I8259 0 +#define PIC_IOAPIC 1 +#define PIC_LAPIC 2 +#define PIC_SOFT 3 + +extern struct pic i8259_pic; +extern struct pic local_pic; +extern struct pic softintr_pic; +#endif \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/pio.h b/lib/libc/include/x86-openbsd-none/machine/pio.h new file mode 100644 index 0000000000..6ca1c28444 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/pio.h @@ -0,0 +1,201 @@ +/* $OpenBSD: pio.h,v 1.12 2015/04/25 21:31:24 guenther Exp $ */ +/* $NetBSD: pio.h,v 1.13 1996/03/08 20:15:23 cgd Exp $ */ + +/* + * Copyright (c) 1993, 1995 Charles M. Hannum. 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 Charles M. Hannum. + * 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 _MACHINE_PIO_H_ +#define _MACHINE_PIO_H_ + +/* + * Functions to provide access to i386 programmed I/O instructions. + * + * The in[bwl]() and out[bwl]() functions are split into two varieties: one to + * use a small, constant, 8-bit port number, and another to use a large or + * variable port number. The former can be compiled as a smaller instruction. + */ + + +#ifdef __OPTIMIZE__ + +#define __use_immediate_port(port) \ + (__builtin_constant_p((port)) && (port) < 0x100) + +#else + +#define __use_immediate_port(port) 0 + +#endif + + +#define inb(port) \ + (__use_immediate_port(port) ? __inbc(port) : __inb(port)) + +static __inline u_int8_t +__inbc(int port) +{ + u_int8_t data; + __asm volatile("inb %w1,%0" : "=a" (data) : "id" (port)); + return data; +} + +static __inline u_int8_t +__inb(int port) +{ + u_int8_t data; + __asm volatile("inb %w1,%0" : "=a" (data) : "d" (port)); + return data; +} + +static __inline void +insb(int port, void *addr, int cnt) +{ + __asm volatile("repne\n\tinsb" + : "+D" (addr), "+c" (cnt) : "d" (port) : "memory", "cc"); +} + +#define inw(port) \ + (__use_immediate_port(port) ? __inwc(port) : __inw(port)) + +static __inline u_int16_t +__inwc(int port) +{ + u_int16_t data; + __asm volatile("inw %w1,%0" : "=a" (data) : "id" (port)); + return data; +} + +static __inline u_int16_t +__inw(int port) +{ + u_int16_t data; + __asm volatile("inw %w1,%0" : "=a" (data) : "d" (port)); + return data; +} + +static __inline void +insw(int port, void *addr, int cnt) +{ + __asm volatile("repne\n\tinsw" + : "+D" (addr), "+c" (cnt) : "d" (port) : "memory", "cc"); +} + +#define inl(port) \ + (__use_immediate_port(port) ? __inlc(port) : __inl(port)) + +static __inline u_int32_t +__inlc(int port) +{ + u_int32_t data; + __asm volatile("inl %w1,%0" : "=a" (data) : "id" (port)); + return data; +} + +static __inline u_int32_t +__inl(int port) +{ + u_int32_t data; + __asm volatile("inl %w1,%0" : "=a" (data) : "d" (port)); + return data; +} + +static __inline void +insl(int port, void *addr, int cnt) +{ + __asm volatile("repne\n\tinsl" + : "+D" (addr), "+c" (cnt) : "d" (port) : "memory", "cc"); +} + +#define outb(port, data) \ + (__use_immediate_port(port) ? __outbc(port, data) : __outb(port, data)) + +static __inline void +__outbc(int port, u_int8_t data) +{ + __asm volatile("outb %0,%w1" : : "a" (data), "id" (port)); +} + +static __inline void +__outb(int port, u_int8_t data) +{ + __asm volatile("outb %0,%w1" : : "a" (data), "d" (port)); +} + +static __inline void +outsb(int port, const void *addr, int cnt) +{ + __asm volatile("repne\n\toutsb" + : "+S" (addr), "+c" (cnt) : "d" (port) : "cc"); +} + +#define outw(port, data) \ + (__use_immediate_port(port) ? __outwc(port, data) : __outw(port, data)) + +static __inline void +__outwc(int port, u_int16_t data) +{ + __asm volatile("outw %0,%w1" : : "a" (data), "id" (port)); +} + +static __inline void +__outw(int port, u_int16_t data) +{ + __asm volatile("outw %0,%w1" : : "a" (data), "d" (port)); +} + +static __inline void +outsw(int port, const void *addr, int cnt) +{ + __asm volatile("repne\n\toutsw" + : "+S" (addr), "+c" (cnt) : "d" (port) : "cc"); +} + +#define outl(port, data) \ + (__use_immediate_port(port) ? __outlc(port, data) : __outl(port, data)) + +static __inline void +__outlc(int port, u_int32_t data) +{ + __asm volatile("outl %0,%w1" : : "a" (data), "id" (port)); +} + +static __inline void +__outl(int port, u_int32_t data) +{ + __asm volatile("outl %0,%w1" : : "a" (data), "d" (port)); +} + +static __inline void +outsl(int port, const void *addr, int cnt) +{ + __asm volatile("repne\n\toutsl" + : "+S" (addr), "+c" (cnt) : "d" (port) : "cc"); +} + +#endif /* _MACHINE_PIO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/pmap.h b/lib/libc/include/x86-openbsd-none/machine/pmap.h new file mode 100644 index 0000000000..0c46db395e --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/pmap.h @@ -0,0 +1,480 @@ +/* $OpenBSD: pmap.h,v 1.98 2025/07/16 07:15:42 jsg Exp $ */ +/* $NetBSD: pmap.h,v 1.44 2000/04/24 17:18:18 thorpej Exp $ */ + +/* + * Copyright (c) 1997 Charles D. Cranor and Washington University. + * 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. + */ + +/* + * pmap.h: see pmap.c for the history of this pmap module. + */ + +#ifndef _MACHINE_PMAP_H_ +#define _MACHINE_PMAP_H_ + +#ifdef _KERNEL +#include +#include +#endif +#include +#include +#include + +#define PDSLOT_PTE ((KERNBASE/NBPD)-2) /* 830: for recursive PDP map */ +#define PDSLOT_KERN (KERNBASE/NBPD) /* 832: start of kernel space */ +#define PDSLOT_APTE ((unsigned)1022) /* 1022: alternative recursive slot */ + +/* + * The following define determines how many PTPs should be set up for the + * kernel by locore.s at boot time. This should be large enough to + * get the VM system running. Once the VM system is running, the + * pmap module can add more PTPs to the kernel area on demand. + */ + +#ifndef NKPTP +#define NKPTP 8 /* 16/32MB to start */ +#endif +#define NKPTP_MIN 4 /* smallest value we allow */ + +/* + * PG_AVAIL usage: we make use of the ignored bits of the PTE + */ + +#define PG_W PG_AVAIL1 /* "wired" mapping */ +#define PG_PVLIST PG_AVAIL2 /* mapping has entry on pvlist */ +#define PG_X PG_AVAIL3 /* executable mapping */ + +#define PTP0_PA (PAGE_SIZE * 3) + +#ifdef _KERNEL +/* + * pmap data structures: see pmap.c for details of locking. + */ + +struct pmap; +typedef struct pmap *pmap_t; + +/* + * We maintain a list of all non-kernel pmaps. + */ + +LIST_HEAD(pmap_head, pmap); /* struct pmap_head: head of a pmap list */ + +/* + * The pmap structure + * + * Note that the pm_obj contains the reference count, + * page list, and number of PTPs within the pmap. + */ + +struct pmap { + uint64_t pm_pdidx[4]; /* PDIEs for PAE mode */ + uint64_t pm_pdidx_intel[4]; /* PDIEs for PAE mode U-K */ + + struct mutex pm_mtx; + struct mutex pm_apte_mtx; + + /* + * pm_pdir : VA of PD when executing in privileged mode + * (lock by object lock) + * pm_pdirpa : PA of PD when executing in privileged mode, + * (read-only after create) + * pm_pdir_intel : VA of PD when executing on Intel CPU in + * usermode (no kernel mappings) + * pm_pdirpa_intel : PA of PD when executing on Intel CPU in + * usermode (no kernel mappings) + */ + paddr_t pm_pdirpa, pm_pdirpa_intel; + vaddr_t pm_pdir, pm_pdir_intel; + int pm_pdirsize; /* PD size (4k vs 16k on PAE) */ + struct uvm_object pm_obj; /* object (lck by object lock) */ + LIST_ENTRY(pmap) pm_list; /* list (lck by pm_list lock) */ + struct vm_page *pm_ptphint; /* pointer to a PTP in our pmap */ + struct pmap_statistics pm_stats; /* pmap stats (lck by object lock) */ + + vaddr_t pm_hiexec; /* highest executable mapping */ + int pm_flags; /* see below */ + + struct segment_descriptor pm_codeseg; /* cs descriptor for process */ +}; + +/* + * For each managed physical page we maintain a list of s + * which it is mapped at. The list is headed by a pv_head structure. + * there is one pv_head per managed phys page (allocated at boot time). + * The pv_head structure points to a list of pv_entry structures (each + * describes one mapping). + */ + +struct pv_entry { /* locked by its list's pvh_lock */ + struct pv_entry *pv_next; /* next entry */ + struct pmap *pv_pmap; /* the pmap */ + vaddr_t pv_va; /* the virtual address */ + struct vm_page *pv_ptp; /* the vm_page of the PTP */ +}; +/* + * MD flags to pmap_enter: + */ + +/* to get just the pa from params to pmap_enter */ +#define PMAP_PA_MASK ~((paddr_t)PAGE_MASK) +#define PMAP_NOCACHE 0x1 /* map uncached */ +#define PMAP_WC 0x2 /* map write combining. */ + +/* + * We keep mod/ref flags in struct vm_page->pg_flags. + */ +#define PG_PMAP_MOD PG_PMAP0 +#define PG_PMAP_REF PG_PMAP1 +#define PG_PMAP_WC PG_PMAP2 + +/* + * pv_entrys are dynamically allocated in chunks from a single page. + * we keep track of how many pv_entrys are in use for each page and + * we can free pv_entry pages if needed. There is one lock for the + * entire allocation system. + */ + +struct pv_page_info { + TAILQ_ENTRY(pv_page) pvpi_list; + struct pv_entry *pvpi_pvfree; + int pvpi_nfree; +}; + +/* + * number of pv_entries in a pv_page + */ + +#define PVE_PER_PVPAGE ((PAGE_SIZE - sizeof(struct pv_page_info)) / \ + sizeof(struct pv_entry)) + +/* + * a pv_page: where pv_entrys are allocated from + */ + +struct pv_page { + struct pv_page_info pvinfo; + struct pv_entry pvents[PVE_PER_PVPAGE]; +}; + +/* + * pv_entrys are dynamically allocated in chunks from a single page. + * we keep track of how many pv_entrys are in use for each page and + * we can free pv_entry pages if needed. There is one lock for the + * entire allocation system. + */ + +extern char PTD[]; +extern struct pmap kernel_pmap_store; /* kernel pmap */ +extern int nkptp_max; + +#define PMAP_REMOVE_ALL 0 +#define PMAP_REMOVE_SKIPWIRED 1 + +extern struct pool pmap_pv_pool; + +/* + * Macros + */ + +#define pmap_kernel() (&kernel_pmap_store) +#define pmap_wired_count(pmap) ((pmap)->pm_stats.wired_count) +#define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count) +#define pmap_update(pm) /* nada */ + +#define pmap_clear_modify(pg) pmap_clear_attrs(pg, PG_M) +#define pmap_clear_reference(pg) pmap_clear_attrs(pg, PG_U) +#define pmap_is_modified(pg) pmap_test_attrs(pg, PG_M) +#define pmap_is_referenced(pg) pmap_test_attrs(pg, PG_U) +#define pmap_valid_entry(E) ((E) & PG_V) /* is PDE or PTE valid? */ + +#define pmap_proc_iflush(p,va,len) /* nothing */ +#define pmap_init_percpu() do { /* nothing */ } while (0) +#define pmap_unuse_final(p) /* nothing */ +#define pmap_remove_holes(vm) do { /* nothing */ } while (0) + +/* + * Prototypes + */ + +vaddr_t pmap_tmpmap_pa_86(paddr_t); +vaddr_t pmap_tmpmap_pa(paddr_t); +void pmap_tmpunmap_pa_86(void); +void pmap_tmpunmap_pa(void); + +void pmap_bootstrap(vaddr_t); +void pmap_bootstrap_pae(void); +void pmap_virtual_space(vaddr_t *, vaddr_t *); +void pmap_init(void); +struct pmap *pmap_create(void); +void pmap_destroy(struct pmap *); +void pmap_reference(struct pmap *); +void pmap_remove(struct pmap *, vaddr_t, vaddr_t); +void pmap_activate(struct proc *); +void pmap_deactivate(struct proc *); +void pmap_kenter_pa(vaddr_t, paddr_t, vm_prot_t); +void pmap_kremove(vaddr_t, vsize_t); +void pmap_zero_page(struct vm_page *); +void pmap_copy_page(struct vm_page *, struct vm_page *); +void pmap_enter_pv(struct vm_page *, struct pv_entry *, + struct pmap *, vaddr_t, struct vm_page *); +int pmap_clear_attrs(struct vm_page *, int); +static void pmap_page_protect(struct vm_page *, vm_prot_t); +void pmap_page_remove(struct vm_page *); +static void pmap_protect(struct pmap *, vaddr_t, + vaddr_t, vm_prot_t); +void pmap_remove(struct pmap *, vaddr_t, vaddr_t); +int pmap_test_attrs(struct vm_page *, int); +void pmap_write_protect(struct pmap *, vaddr_t, + vaddr_t, vm_prot_t); +int pmap_exec_fixup(struct vm_map *, struct trapframe *, + vaddr_t, struct pcb *); +void pmap_exec_account(struct pmap *, vaddr_t, u_int32_t, + u_int32_t); +struct pv_entry *pmap_remove_pv(struct vm_page *, struct pmap *, vaddr_t); +void pmap_apte_flush(void); +void pmap_switch(struct proc *, struct proc *); +vaddr_t reserve_dumppages(vaddr_t); /* XXX: not a pmap fn */ +paddr_t vtophys(vaddr_t va); +paddr_t vtophys_pae(vaddr_t va); + +extern u_int32_t (*pmap_pte_set_p)(vaddr_t, paddr_t, u_int32_t); +extern u_int32_t (*pmap_pte_setbits_p)(vaddr_t, u_int32_t, u_int32_t); +extern u_int32_t (*pmap_pte_bits_p)(vaddr_t); +extern paddr_t (*pmap_pte_paddr_p)(vaddr_t); +extern int (*pmap_clear_attrs_p)(struct vm_page *, int); +extern int (*pmap_enter_p)(pmap_t, vaddr_t, paddr_t, vm_prot_t, int); +extern void (*pmap_enter_special_p)(vaddr_t, paddr_t, vm_prot_t, u_int32_t); +extern int (*pmap_extract_p)(pmap_t, vaddr_t, paddr_t *); +extern vaddr_t (*pmap_growkernel_p)(vaddr_t); +extern void (*pmap_page_remove_p)(struct vm_page *); +extern void (*pmap_do_remove_p)(struct pmap *, vaddr_t, vaddr_t, int); +extern int (*pmap_test_attrs_p)(struct vm_page *, int); +extern void (*pmap_unwire_p)(struct pmap *, vaddr_t); +extern void (*pmap_write_protect_p)(struct pmap*, vaddr_t, vaddr_t, vm_prot_t); +extern void (*pmap_pinit_pd_p)(pmap_t); +extern void (*pmap_zero_phys_p)(paddr_t); +extern void (*pmap_copy_page_p)(struct vm_page *, struct vm_page *); + +u_int32_t pmap_pte_set_pae(vaddr_t, paddr_t, u_int32_t); +u_int32_t pmap_pte_setbits_pae(vaddr_t, u_int32_t, u_int32_t); +u_int32_t pmap_pte_bits_pae(vaddr_t); +paddr_t pmap_pte_paddr_pae(vaddr_t); +int pmap_clear_attrs_pae(struct vm_page *, int); +int pmap_enter_pae(pmap_t, vaddr_t, paddr_t, vm_prot_t, int); +void pmap_enter_special_pae(vaddr_t, paddr_t, vm_prot_t, u_int32_t); +int pmap_extract_pae(pmap_t, vaddr_t, paddr_t *); +vaddr_t pmap_growkernel_pae(vaddr_t); +void pmap_page_remove_pae(struct vm_page *); +void pmap_do_remove_pae(struct pmap *, vaddr_t, vaddr_t, int); +int pmap_test_attrs_pae(struct vm_page *, int); +void pmap_unwire_pae(struct pmap *, vaddr_t); +void pmap_write_protect_pae(struct pmap *, vaddr_t, vaddr_t, vm_prot_t); +void pmap_pinit_pd_pae(pmap_t); +void pmap_zero_phys_pae(paddr_t); +void pmap_copy_page_pae(struct vm_page *, struct vm_page *); + +#define pmap_pte_set (*pmap_pte_set_p) +#define pmap_pte_setbits (*pmap_pte_setbits_p) +#define pmap_pte_bits (*pmap_pte_bits_p) +#define pmap_pte_paddr (*pmap_pte_paddr_p) +#define pmap_clear_attrs (*pmap_clear_attrs_p) +#define pmap_page_remove (*pmap_page_remove_p) +#define pmap_do_remove (*pmap_do_remove_p) +#define pmap_test_attrs (*pmap_test_attrs_p) +#define pmap_unwire (*pmap_unwire_p) +#define pmap_write_protect (*pmap_write_protect_p) +#define pmap_pinit_pd (*pmap_pinit_pd_p) +#define pmap_zero_phys (*pmap_zero_phys_p) +#define pmap_copy_page (*pmap_copy_page_p) + +u_int32_t pmap_pte_set_86(vaddr_t, paddr_t, u_int32_t); +u_int32_t pmap_pte_setbits_86(vaddr_t, u_int32_t, u_int32_t); +u_int32_t pmap_pte_bits_86(vaddr_t); +paddr_t pmap_pte_paddr_86(vaddr_t); +int pmap_clear_attrs_86(struct vm_page *, int); +int pmap_enter_86(pmap_t, vaddr_t, paddr_t, vm_prot_t, int); +void pmap_enter_special_86(vaddr_t, paddr_t, vm_prot_t, u_int32_t); +int pmap_extract_86(pmap_t, vaddr_t, paddr_t *); +vaddr_t pmap_growkernel_86(vaddr_t); +void pmap_page_remove_86(struct vm_page *); +void pmap_do_remove_86(struct pmap *, vaddr_t, vaddr_t, int); +int pmap_test_attrs_86(struct vm_page *, int); +void pmap_unwire_86(struct pmap *, vaddr_t); +void pmap_write_protect_86(struct pmap *, vaddr_t, vaddr_t, vm_prot_t); +void pmap_pinit_pd_86(pmap_t); +void pmap_zero_phys_86(paddr_t); +void pmap_copy_page_86(struct vm_page *, struct vm_page *); +void pmap_tlb_shootpage(struct pmap *, vaddr_t); +void pmap_tlb_shootrange(struct pmap *, vaddr_t, vaddr_t); +void pmap_tlb_shoottlb(void); +#ifdef MULTIPROCESSOR +void pmap_tlb_droppmap(struct pmap *); +void pmap_tlb_shootwait(void); +#else +#define pmap_tlb_shootwait() +#endif + +void pmap_prealloc_lowmem_ptp(void); +void pmap_prealloc_lowmem_ptp_pae(void); +vaddr_t pmap_tmpmap_pa(paddr_t); +void pmap_tmpunmap_pa(void); +vaddr_t pmap_tmpmap_pa_pae(paddr_t); +void pmap_tmpunmap_pa_pae(void); + + +/* + * functions for flushing the cache for vaddrs and pages. + * these functions are not part of the MI pmap interface and thus + * should not be used as such. + */ +void pmap_flush_cache(vaddr_t, vsize_t); +void pmap_flush_page(paddr_t); +void pmap_flush_page_pae(paddr_t); + +#define PMAP_CHECK_COPYIN 1 + +#define PMAP_GROWKERNEL /* turn on pmap_growkernel interface */ + +/* + * Inline functions + */ + +/* + * pmap_update_pg: flush one page from the TLB (or flush the whole thing + * if hardware doesn't support one-page flushing) + */ + +#define pmap_update_pg(va) invlpg((u_int)(va)) + +/* + * pmap_update_2pg: flush two pages from the TLB + */ + +#define pmap_update_2pg(va, vb) { invlpg((u_int)(va)); invlpg((u_int)(vb)); } + +/* + * pmap_page_protect: change the protection of all recorded mappings + * of a managed page + * + * => This function is a front end for pmap_page_remove/pmap_clear_attrs + * => We only have to worry about making the page more protected. + * Unprotecting a page is done on-demand at fault time. + */ + +static __inline void +pmap_page_protect(struct vm_page *pg, vm_prot_t prot) +{ + if ((prot & PROT_WRITE) == 0) { + if (prot & (PROT_READ | PROT_EXEC)) { + (void) pmap_clear_attrs(pg, PG_RW); + } else { + pmap_page_remove(pg); + } + } +} + +/* + * pmap_protect: change the protection of pages in a pmap + * + * => This function is a front end for pmap_remove/pmap_write_protect. + * => We only have to worry about making the page more protected. + * Unprotecting a page is done on-demand at fault time. + */ + +static __inline void +pmap_protect(struct pmap *pmap, vaddr_t sva, vaddr_t eva, vm_prot_t prot) +{ + if ((prot & PROT_WRITE) == 0) { + if (prot & (PROT_READ | PROT_EXEC)) { + pmap_write_protect(pmap, sva, eva, prot); + } else { + pmap_remove(pmap, sva, eva); + } + } +} + +/* + * pmap_growkernel, pmap_enter, and pmap_extract get picked up in various + * modules from both uvm_pmap.h and pmap.h. Since uvm_pmap.h defines these + * as functions, inline them here to suppress linker warnings. + */ +static __inline vaddr_t +pmap_growkernel(vaddr_t maxkvaddr) +{ + return (*pmap_growkernel_p)(maxkvaddr); +} + +static __inline int +pmap_enter(struct pmap *pmap, vaddr_t va, paddr_t pa, vm_prot_t prot, int flags) +{ + return (*pmap_enter_p)(pmap, va, pa, prot, flags); +} + +static __inline void +pmap_enter_special(vaddr_t va, paddr_t pa, vm_prot_t prot, u_int32_t flags) +{ + (*pmap_enter_special_p)(va, pa, prot, flags); +} + +static __inline int +pmap_extract(struct pmap *pmap, vaddr_t va, paddr_t *pa) +{ + return (*pmap_extract_p)(pmap, va, pa); +} + +/* + * p m a p i n l i n e h e l p e r f u n c t i o n s + */ + +/* + * pmap_is_active: is this pmap loaded into the specified processor's %cr3? + */ + +static __inline int +pmap_is_active(struct pmap *pmap, struct cpu_info *ci) +{ + return (pmap == pmap_kernel() || ci->ci_curpmap == pmap); +} + +static __inline int +pmap_is_curpmap(struct pmap *pmap) +{ + return (pmap_is_active(pmap, curcpu())); +} + +#endif /* _KERNEL */ + +struct pv_entry; +struct vm_page_md { + struct mutex pv_mtx; + struct pv_entry *pv_list; +}; + +#define VM_MDPAGE_INIT(pg) do { \ + mtx_init(&(pg)->mdpage.pv_mtx, IPL_VM); \ + (pg)->mdpage.pv_list = NULL; \ +} while (0) + +#endif /* _MACHINE_PMAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/proc.h b/lib/libc/include/x86-openbsd-none/machine/proc.h new file mode 100644 index 0000000000..aa4ac664f9 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/proc.h @@ -0,0 +1,45 @@ +/* $OpenBSD: proc.h,v 1.10 2018/03/31 13:45:03 bluhm Exp $ */ +/* $NetBSD: proc.h,v 1.10 1995/08/06 05:33:23 mycroft 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 + */ + +/* + * Machine-dependent part of the proc structure for i386. + */ +struct mdproc { + struct trapframe *md_regs; /* registers on current frame */ + int md_flags; /* machine-dependent flags */ + int md_astpending; +}; + +/* md_flags */ +#define MDP_USEDFPU 0x0001 /* has used the FPU */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/profile.h b/lib/libc/include/x86-openbsd-none/machine/profile.h new file mode 100644 index 0000000000..b6762e06da --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/profile.h @@ -0,0 +1,76 @@ +/* $OpenBSD: profile.h,v 1.12 2014/03/29 18:09:29 guenther Exp $ */ +/* $NetBSD: profile.h,v 1.6 1995/03/28 18:17:08 jtc Exp $ */ + +/* + * Copyright (c) 1992, 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. + * + * @(#)profile.h 8.1 (Berkeley) 6/11/93 + */ + +#define _MCOUNT_DECL static __inline void _mcount + +#define MCOUNT \ +extern void mcount(void) __asm("__mcount"); \ +__weak_alias(mcount,__mcount); \ +void \ +mcount(void) \ +{ \ + int selfpc, frompcindex; \ + int eax, ecx, edx; \ + \ + __asm volatile("movl %%eax,%0" : "=g" (eax)); \ + __asm volatile("movl %%ecx,%0" : "=g" (ecx)); \ + __asm volatile("movl %%edx,%0" : "=g" (edx)); \ + /* \ + * find the return address for mcount, \ + * and the return address for mcount's caller. \ + * \ + * selfpc = pc pushed by mcount call \ + */ \ + __asm volatile ("movl 4(%%ebp),%0" : "=r" (selfpc)); \ + /* \ + * frompcindex = pc pushed by call into self. \ + */ \ + __asm volatile ("movl (%%ebp),%0;movl 4(%0),%0" : \ + "+r" (frompcindex)); \ + _mcount(frompcindex, selfpc); \ + \ + __asm volatile("movl %0,%%edx" : : "g" (edx)); \ + __asm volatile("movl %0,%%ecx" : : "g" (ecx)); \ + __asm volatile("movl %0,%%eax" : : "g" (eax)); \ +} + +#ifdef _KERNEL +/* + * We inline the code that splhigh and splx would do here as otherwise we would + * call recursively into mcount() as machdep.c is compiled with -pg on a + * profiling build. + */ +#define MCOUNT_ENTER _SPLRAISE(s, IPL_HIGH); __splbarrier() +#define MCOUNT_EXIT __splbarrier(); _SPLX(s) +#endif /* _KERNEL */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/psl.h b/lib/libc/include/x86-openbsd-none/machine/psl.h new file mode 100644 index 0000000000..f59e7e0c77 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/psl.h @@ -0,0 +1,98 @@ +/* $OpenBSD: psl.h,v 1.21 2018/07/09 19:20:30 guenther Exp $ */ +/* $NetBSD: psl.h,v 1.30 1996/05/13 01:28:05 mycroft 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. + * + * @(#)psl.h 5.2 (Berkeley) 1/18/91 + */ + +#ifndef _MACHINE_PSL_H_ +#define _MACHINE_PSL_H_ + +/* + * 386 processor status longword. + */ +#define PSL_C 0x00000001 /* carry flag */ +#define PSL_PF 0x00000004 /* parity flag */ +#define PSL_AF 0x00000010 /* auxiliary carry flag */ +#define PSL_Z 0x00000040 /* zero flag */ +#define PSL_N 0x00000080 /* sign flag */ +#define PSL_T 0x00000100 /* trap flag */ +#define PSL_I 0x00000200 /* interrupt enable flag */ +#define PSL_D 0x00000400 /* direction flag */ +#define PSL_V 0x00000800 /* overflow flag */ +#define PSL_IOPL 0x00003000 /* i/o privilege level */ +#define PSL_NT 0x00004000 /* nested task */ +#define PSL_RF 0x00010000 /* resume flag */ +#define PSL_VM 0x00020000 /* virtual 8086 mode */ +#define PSL_AC 0x00040000 /* alignment check flag */ +#define PSL_VIF 0x00080000 /* virtual interrupt enable flag */ +#define PSL_VIP 0x00100000 /* virtual interrupt pending flag */ +#define PSL_ID 0x00200000 /* identification flag */ +#define PSL_XCRYPT 0x40000000 /* VIA xcrypt: operation loaded */ + +#define PSL_MBO 0x00000002 /* must be one bits */ +#define PSL_MBZ 0xffc08028 /* must be zero bits */ + +#define PSL_USERSET (PSL_MBO | PSL_I) +#define PSL_USERSTATIC (PSL_MBO | PSL_MBZ | PSL_I | PSL_IOPL | PSL_NT | PSL_VM | PSL_VIF | PSL_VIP) + +#ifdef _KERNEL +#include + +#ifndef _LOCORE + +#include + +/* + * Interrupt handler chains. isa_intr_establish() inserts a handler into + * the list. The handler is called with its (single) argument. + */ + +struct intrhand { + int (*ih_fun)(void *); + void *ih_arg; + int ih_level; + int ih_flags; + struct intrhand *ih_next; + int ih_pin; + int ih_irq; + struct evcount ih_count; + int ih_vec; +}; + +extern int intr_shared_edge; /* This system has shared edge interrupts */ + +#endif /* _LOCORE */ +#endif /* _KERNEL */ + +#endif /* !_MACHINE_PSL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/pte.h b/lib/libc/include/x86-openbsd-none/machine/pte.h new file mode 100644 index 0000000000..14a6902bf3 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/pte.h @@ -0,0 +1,92 @@ +/* $OpenBSD: pte.h,v 1.23 2019/01/18 01:34:50 pd Exp $ */ +/* $NetBSD: pte.h,v 1.11 1998/02/06 21:58:05 thorpej Exp $ */ + +/* + * Copyright (c) 1997 Charles D. Cranor and Washington University. + * 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. + */ + +/* + * pte.h rewritten by chuck based on the jolitz version, plus random + * info on the pentium and other processors found on the net. the + * goal of this rewrite is to provide enough documentation on the MMU + * hardware that the reader will be able to understand it without having + * to refer to a hardware manual. + */ + +#ifndef _MACHINE_PTE_H_ +#define _MACHINE_PTE_H_ + +/* + * now we define various for playing with virtual addresses + */ + +#define PDSHIFT 22 /* offset of PD index in VA */ +#define NBPD (1 << PDSHIFT) /* # bytes mapped by PD (4MB) */ + +/* + * here we define the bits of the PDE/PTE, as described above: + * + * XXXCDC: need to rename these (PG_u == ugly). + */ + +#define PG_V 0x00000001 /* valid entry */ +#define PG_RO 0x00000000 /* read-only page */ +#define PG_RW 0x00000002 /* read-write page */ +#define PG_u 0x00000004 /* user accessible page */ +#define PG_PROT 0x00000806 /* all protection bits */ +#define PG_WT 0x00000008 /* write through */ +#define PG_N 0x00000010 /* non-cacheable */ +#define PG_U 0x00000020 /* has been used */ +#define PG_M 0x00000040 /* has been modified */ +#define PG_PAT 0x00000080 /* PAT bit. (on pte) */ +#define PG_PS 0x00000080 /* 4MB page size (on pde) */ +#define PG_G 0x00000100 /* global, don't TLB flush */ +#define PG_AVAIL1 0x00000200 /* ignored by hardware */ +#define PG_AVAIL2 0x00000400 /* ignored by hardware */ +#define PG_AVAIL3 0x00000800 /* ignored by hardware */ +#define PG_PATLG 0x00001000 /* PAT on large pages */ + +/* Cacheability bits when we are using PAT */ +#define PG_WB (0) /* The default */ +#define PG_WC (PG_WT) /* WT and CD is WC */ +#define PG_UCMINUS (PG_N) /* UC but mtrr can override */ +#define PG_UC (PG_WT | PG_N) /* hard UC */ + +/* + * various shorthand protection codes + */ + +#define PG_KR 0x00000000 /* kernel read-only */ +#define PG_KW 0x00000002 /* kernel read-write */ + +/* + * page protection exception bits + */ + +#define PGEX_P 0x01 /* protection violation (vs. no mapping) */ +#define PGEX_W 0x02 /* exception during a write cycle */ +#define PGEX_U 0x04 /* exception while in user mode (upl) */ +#define PGEX_I 0x10 /* instruction fetch blocked by NX */ + +#endif /* _MACHINE_PTE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/ptrace.h b/lib/libc/include/x86-openbsd-none/machine/ptrace.h new file mode 100644 index 0000000000..d8efdad5a9 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/ptrace.h @@ -0,0 +1,50 @@ +/* $OpenBSD: ptrace.h,v 1.3 2005/04/03 20:21:44 kettenis Exp $ */ +/* $NetBSD: ptrace.h,v 1.6 1995/08/06 05:33:23 mycroft 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. + */ + +/* + * i386-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) +#define PT_GETXMMREGS (PT_FIRSTMACH + 5) +#define PT_SETXMMREGS (PT_FIRSTMACH + 6) + +#ifdef _KERNEL +struct xmmregs; + +int process_read_xmmregs(struct proc *, struct xmmregs *); +int process_write_xmmregs(struct proc *, const struct xmmregs *); +#endif \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/rbus_machdep.h b/lib/libc/include/x86-openbsd-none/machine/rbus_machdep.h new file mode 100644 index 0000000000..0d0d6eda30 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/rbus_machdep.h @@ -0,0 +1,48 @@ +/* $OpenBSD: rbus_machdep.h,v 1.10 2024/05/22 05:51:49 jsg Exp $ */ +/* $NetBSD: rbus_machdep.h,v 1.2 1999/10/15 06:43:05 haya Exp $ */ + +/* + * Copyright (c) 1999 + * HAYAKAWA Koichi. 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_RBUS_MACHDEP_H_ +#define _MACHINE_RBUS_MACHDEP_H_ + +struct pci_attach_args; /* XXX */ + +#define md_space_map(rbt, physaddr, size, flags, bshp) \ + _bus_space_map((rbt)->rb_bt, (physaddr), (size), (flags), (bshp)) + +#define md_space_unmap(rbt, bsh, size, adrp) \ + _bus_space_unmap((rbt)->rb_bt, (bsh), (size), (adrp)) + +rbus_tag_t rbus_pccbb_parent_io(struct device *, + struct pci_attach_args *); +rbus_tag_t rbus_pccbb_parent_mem(struct device *, + struct pci_attach_args *); + +void pccbb_attach_hook(struct device *, struct device *, + struct pci_attach_args *); + +#endif /* _MACHINE_RBUS_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/reg.h b/lib/libc/include/x86-openbsd-none/machine/reg.h new file mode 100644 index 0000000000..b25bcac885 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/reg.h @@ -0,0 +1,103 @@ +/* $OpenBSD: reg.h,v 1.7 2011/03/23 16:54:35 pirofti Exp $ */ +/* $NetBSD: reg.h,v 1.14 1995/10/11 04:20:24 mycroft 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 _MACHINE_REG_H_ +#define _MACHINE_REG_H_ + +/* + * Location of the users' stored + * registers within appropriate frame of 'trap' and 'syscall', relative to + * base of stack frame. + * Normal usage is u.u_ar0[XX] in kernel. + */ + +/* When referenced during a trap/exception, registers are at these offsets */ + +#define tES (0) +#define tDS (1) +#define tEDI (2) +#define tESI (3) +#define tEBP (4) +#define tEBX (5) +#define tEDX (6) +#define tECX (7) +#define tEAX (8) + +#define tEIP (11) +#define tCS (12) +#define tEFLAGS (13) +#define tESP (14) +#define tSS (15) + +/* + * Registers accessible to ptrace(2) syscall for debugger + * The machine-dependent code for PT_{SET,GET}REGS needs to + * use whichever order, defined above, is correct, so that it + * is all invisible to the user. + */ +struct reg { + int r_eax; + int r_ecx; + int r_edx; + int r_ebx; + int r_esp; + int r_ebp; + int r_esi; + int r_edi; + int r_eip; + int r_eflags; + int r_cs; + int r_ss; + int r_ds; + int r_es; + int r_fs; + int r_gs; +}; + +struct fpreg { + /* + * XXX + * Fill this in with real info. + */ + char __data[116]; +}; + +struct xmmregs { + char __data[512]; +}; + +#endif /* !_MACHINE_REG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/reloc.h b/lib/libc/include/x86-openbsd-none/machine/reloc.h new file mode 100644 index 0000000000..e2d976bbfd --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/reloc.h @@ -0,0 +1,52 @@ +/* $OpenBSD: reloc.h,v 1.3 2011/03/23 16:54:35 pirofti Exp $ */ + +/* + * Copyright (c) 2002,2003 Dale Rahn + * + * 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_RELOC_H_ +#define _MACHINE_RELOC_H_ +#define R_TYPE(X) __CONCAT(RELOC_,X) + + +#define RELOC_NONE 0 /* No reloc */ +#define RELOC_32 1 /* Direct 32 bit */ +#define RELOC_PC32 2 /* PC relative 32 bit */ +#define RELOC_GOT32 3 /* 32 bit GOT entry */ +#define RELOC_PLT32 4 /* 32 bit PLT address */ +#define RELOC_COPY 5 /* Copy symbol at runtime */ +#define RELOC_GLOB_DAT 6 /* Create GOT entry */ +#define RELOC_JUMP_SLOT 7 /* Create PLT entry */ +#define RELOC_RELATIVE 8 /* Adjust by program base */ +#define RELOC_GOTOFF 9 /* 32 bit offset to GOT */ +#define RELOC_GOTPC 10 /* 32 bit PC relative offset to GOT */ +#define RELOC_TLS_TPOFF 14 /* negative offset in static TLS block */ +#define RELOC_16 20 +#define RELOC_PC16 21 +#define RELOC_8 22 +#define RELOC_PC8 23 +#define RELOC_TLS_DTPMOD32 35 /* ID of module containing symbol */ +#define RELOC_TLS_DTPOFF32 36 /* Offset in TLS block */ +#define RELOC_TLS_TPOFF32 37 /* Offset in static TLS block */ + +#endif /* _MACHINE_RELOC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/segments.h b/lib/libc/include/x86-openbsd-none/machine/segments.h new file mode 100644 index 0000000000..03a4bc81be --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/segments.h @@ -0,0 +1,229 @@ +/* $OpenBSD: segments.h,v 1.28 2020/09/24 11:36:50 deraadt Exp $ */ +/* $NetBSD: segments.h,v 1.23 1996/02/01 22:31:03 mycroft Exp $ */ + +/*- + * Copyright (c) 1995 Charles M. Hannum. All rights reserved. + * Copyright (c) 1989, 1990 William F. Jolitz + * 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. + * + * @(#)segments.h 7.1 (Berkeley) 5/9/91 + */ + +/* + * 386 Segmentation Data Structures and definitions + * William F. Jolitz (william@ernie.berkeley.edu) 6/20/1989 + */ + +#ifndef _MACHINE_SEGMENTS_H_ +#define _MACHINE_SEGMENTS_H_ + +/* + * Selectors + */ + +#define ISPL(s) ((s) & SEL_RPL) /* what is the priority level of a selector */ +#define SEL_KPL 0 /* kernel privilege level */ +#define SEL_UPL 3 /* user privilege level */ +#define SEL_RPL 3 /* requester's privilege level mask */ +#define ISLDT(s) ((s) & SEL_LDT) /* is it local or global */ +#define SEL_LDT 4 /* local descriptor table */ +#define IDXSEL(s) (((s) >> 3) & 0x1fff) /* index of selector */ +#define GSEL(s,r) (((s) << 3) | r) /* a global selector */ +#define LSEL(s,r) (((s) << 3) | r | SEL_LDT) /* a local selector */ + +#define USERMODE(c, f) (ISPL(c) == SEL_UPL) +#define KERNELMODE(c, f) (ISPL(c) == SEL_KPL) + +#ifndef _LOCORE + +/* + * Memory and System segment descriptors + */ +struct segment_descriptor { + unsigned sd_lolimit:16; /* segment extent (lsb) */ + unsigned sd_lobase:24; /* segment base address (lsb) */ + unsigned sd_type:5; /* segment type */ + unsigned sd_dpl:2; /* segment descriptor priority level */ + unsigned sd_p:1; /* segment descriptor present */ + unsigned sd_hilimit:4; /* segment extent (msb) */ + unsigned sd_xx:2; /* unused */ + unsigned sd_def32:1; /* default 32 vs 16 bit size */ + unsigned sd_gran:1; /* limit granularity (byte/page) */ + unsigned sd_hibase:8; /* segment base address (msb) */ +} __packed; + +/* + * Gate descriptors (e.g. indirect descriptors) + */ +struct gate_descriptor { + unsigned gd_looffset:16; /* gate offset (lsb) */ + unsigned gd_selector:16; /* gate segment selector */ + unsigned gd_stkcpy:5; /* number of stack wds to cpy */ + unsigned gd_xx:3; /* unused */ + unsigned gd_type:5; /* segment type */ + unsigned gd_dpl:2; /* segment descriptor priority level */ + unsigned gd_p:1; /* segment descriptor present */ + unsigned gd_hioffset:16; /* gate offset (msb) */ +} __packed; + +/* + * Generic descriptor + */ +union descriptor { + struct segment_descriptor sd; + struct gate_descriptor gd; +} __packed; + +/* + * region descriptors, used to load gdt/idt tables before segments yet exist. + */ +struct region_descriptor { + unsigned rd_limit:16; /* segment extent */ + unsigned rd_base:32; /* base address */ +} __packed; + +#ifdef _KERNEL +extern union descriptor *gdt; +extern struct gate_descriptor idt_region[]; +extern struct gate_descriptor *idt; + +#define SEGDESC_LIMIT(sd) (ptoa(((sd).sd_hilimit << 16) | (sd).sd_lolimit)) + +void setgate(struct gate_descriptor *, void *, int, int, int, int); +void setregion(struct region_descriptor *, void *, size_t); +void setsegment(struct segment_descriptor *, void *, size_t, int, int, + int, int); +void initcodesegment(struct segment_descriptor *); +void unsetgate(struct gate_descriptor *); +void cpu_init_idt(void); + +int idt_vec_alloc(int, int); +void idt_vec_set(int, void (*)(void)); +void idt_vec_free(int); + +#endif /* _KERNEL */ + +#endif /* !_LOCORE */ + +/* system segments and gate types */ +#define SDT_SYSNULL 0 /* system null */ +#define SDT_SYS286TSS 1 /* system 286 TSS available */ +#define SDT_SYSLDT 2 /* system local descriptor table */ +#define SDT_SYS286BSY 3 /* system 286 TSS busy */ +#define SDT_SYS286CGT 4 /* system 286 call gate */ +#define SDT_SYSTASKGT 5 /* system task gate */ +#define SDT_SYS286IGT 6 /* system 286 interrupt gate */ +#define SDT_SYS286TGT 7 /* system 286 trap gate */ +#define SDT_SYSNULL2 8 /* system null again */ +#define SDT_SYS386TSS 9 /* system 386 TSS available */ +#define SDT_SYSNULL3 10 /* system null again */ +#define SDT_SYS386BSY 11 /* system 386 TSS busy */ +#define SDT_SYS386CGT 12 /* system 386 call gate */ +#define SDT_SYSNULL4 13 /* system null again */ +#define SDT_SYS386IGT 14 /* system 386 interrupt gate */ +#define SDT_SYS386TGT 15 /* system 386 trap gate */ + +/* memory segment types */ +#define SDT_MEMRO 16 /* memory read only */ +#define SDT_MEMROA 17 /* memory read only accessed */ +#define SDT_MEMRW 18 /* memory read write */ +#define SDT_MEMRWA 19 /* memory read write accessed */ +#define SDT_MEMROD 20 /* memory read only expand dwn limit */ +#define SDT_MEMRODA 21 /* memory read only expand dwn limit accessed */ +#define SDT_MEMRWD 22 /* memory read write expand dwn limit */ +#define SDT_MEMRWDA 23 /* memory read write expand dwn limit acessed */ +#define SDT_MEME 24 /* memory execute only */ +#define SDT_MEMEA 25 /* memory execute only accessed */ +#define SDT_MEMER 26 /* memory execute read */ +#define SDT_MEMERA 27 /* memory execute read accessed */ +#define SDT_MEMEC 28 /* memory execute only conforming */ +#define SDT_MEMEAC 29 /* memory execute only accessed conforming */ +#define SDT_MEMERC 30 /* memory execute read conforming */ +#define SDT_MEMERAC 31 /* memory execute read accessed conforming */ + +/* is memory segment descriptor pointer ? */ +#define ISMEMSDP(s) ((s->d_type) >= SDT_MEMRO && \ + (s->d_type) <= SDT_MEMERAC) + +/* is 286 gate descriptor pointer ? */ +#define IS286GDP(s) ((s->d_type) >= SDT_SYS286CGT && \ + (s->d_type) < SDT_SYS286TGT) + +/* is 386 gate descriptor pointer ? */ +#define IS386GDP(s) ((s->d_type) >= SDT_SYS386CGT && \ + (s->d_type) < SDT_SYS386TGT) + +/* is gate descriptor pointer ? */ +#define ISGDP(s) (IS286GDP(s) || IS386GDP(s)) + +/* is segment descriptor pointer ? */ +#define ISSDP(s) (ISMEMSDP(s) || !ISGDP(s)) + +/* is system segment descriptor pointer ? */ +#define ISSYSSDP(s) (!ISMEMSDP(s) && !ISGDP(s)) + +/* + * Segment Protection Exception code bits + */ +#define SEGEX_EXT 0x01 /* recursive or externally induced */ +#define SEGEX_IDT 0x02 /* interrupt descriptor table */ +#define SEGEX_TI 0x04 /* local descriptor table */ + +/* + * Entries in the Interrupt Descriptor Table (IDT) + */ +#define NIDT 256 +#define NRSVIDT 32 /* reserved entries for cpu exceptions */ + +/* + * Entries in the Global Descriptor Table (GDT) + */ +#define GNULL_SEL 0 /* Null descriptor */ +#define GCODE_SEL 1 /* Kernel code descriptor */ +#define GDATA_SEL 2 /* Kernel data descriptor */ +#define GLDT_SEL 3 /* Default LDT descriptor (UNUSED) */ +#define GCPU_SEL 4 /* per-CPU segment */ +#define GUCODE_SEL 5 /* User code descriptor (a stack short) */ +#define GUDATA_SEL 6 /* User data descriptor */ +#define GAPM32CODE_SEL 7 /* 32 bit APM code descriptor */ +#define GAPM16CODE_SEL 8 /* 16 bit APM code descriptor */ +#define GAPMDATA_SEL 9 /* APM data descriptor */ +#define GICODE_SEL 10 /* Interrupt code descriptor (same as Kernel code) */ +#define GUFS_SEL 11 /* User per-thread (%fs) descriptor */ +#define GUGS_SEL 12 /* User per-thread (%gs) descriptor */ +#define GTSS_SEL 13 /* common TSS */ +#define GNMITSS_SEL 14 /* NMI TSS */ +#define GBIOS32_SEL 15 /* spare slot for 32 bit BIOS calls */ +#define NGDT 16 + +#define GDT_SIZE (NGDT << 3) + +#endif /* _MACHINE_SEGMENTS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/setjmp.h b/lib/libc/include/x86-openbsd-none/machine/setjmp.h new file mode 100644 index 0000000000..f53a7cc525 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/setjmp.h @@ -0,0 +1,18 @@ +/* $OpenBSD: setjmp.h,v 1.4 2020/12/13 21:21:32 bluhm Exp $ */ +/* $NetBSD: setjmp.h,v 1.1 1994/12/20 10:36:43 cgd Exp $ */ + +/* + * machine/setjmp.h: machine dependent setjmp-related information. + */ + +#define _JB_EIP 0 +#define _JB_EBX 1 +#define _JB_ESP 2 +#define _JB_EBP 3 +#define _JB_ESI 4 +#define _JB_EDI 5 +#define _JB_SIGMASK 6 +#define _JB_SIGFLAG 7 +#define _JB_FCW 8 + +#define _JBLEN 10 /* size, in longs, of a jmp_buf */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/signal.h b/lib/libc/include/x86-openbsd-none/machine/signal.h new file mode 100644 index 0000000000..80c9b368f1 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/signal.h @@ -0,0 +1,88 @@ +/* $OpenBSD: signal.h,v 1.11 2016/05/10 18:39:45 deraadt Exp $ */ +/* $NetBSD: signal.h,v 1.6 1996/01/08 13:51:43 mycroft Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1989, 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. + * + * @(#)signal.h 7.16 (Berkeley) 3/17/91 + */ + +#ifndef _MACHINE_SIGNAL_H_ +#define _MACHINE_SIGNAL_H_ + +#include + +typedef int sig_atomic_t; + +#ifdef _KERNEL +#include +#endif + +#if __BSD_VISIBLE || __XPG_VISIBLE >= 420 +/* + * Information pushed on stack when a signal is delivered. + * This is used by the kernel to restore state following + * execution of the signal handler. It is also made available + * to the handler to allow it to restore state properly if + * a non-standard exit is performed. + */ +struct sigcontext { + int sc_gs; + int sc_fs; + int sc_es; + int sc_ds; + int sc_edi; + int sc_esi; + int sc_ebp; + int sc_ebx; + int sc_edx; + int sc_ecx; + int sc_eax; + /* XXX */ + int sc_eip; + int sc_cs; + int sc_eflags; + int sc_esp; + int sc_ss; + + long sc_cookie; + int sc_mask; /* signal mask to restore */ + + int sc_trapno; /* XXX should be above */ + int sc_err; + + union savefpu *sc_fpstate; +}; + +#define sc_sp sc_esp +#define sc_fp sc_ebp +#define sc_pc sc_eip +#define sc_ps sc_eflags + +#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */ +#endif /* !_MACHINE_SIGNAL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/specialreg.h b/lib/libc/include/x86-openbsd-none/machine/specialreg.h new file mode 100644 index 0000000000..6024995d82 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/specialreg.h @@ -0,0 +1,812 @@ +/* $OpenBSD: specialreg.h,v 1.85 2023/08/16 04:07:38 jsg Exp $ */ +/* $NetBSD: specialreg.h,v 1.7 1994/10/27 04:16:26 cgd Exp $ */ + +/*- + * Copyright (c) 1991 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. + * + * @(#)specialreg.h 7.1 (Berkeley) 5/9/91 + */ + +/* + * Bits in 386 special registers: + */ +#define CR0_PE 0x00000001 /* Protected mode Enable */ +#define CR0_MP 0x00000002 /* "Math" Present (NPX or NPX emulator) */ +#define CR0_EM 0x00000004 /* EMulate non-NPX coproc. (trap ESC only) */ +#define CR0_TS 0x00000008 /* Task Switched (if MP, trap ESC and WAIT) */ +#define CR0_ET 0x00000010 /* Extension Type (387 (if set) vs 287) */ +#define CR0_PG 0x80000000 /* PaGing enable */ + +/* + * Bits in 486 special registers: + */ +#define CR0_NE 0x00000020 /* Numeric Error enable (EX16 vs IRQ13) */ +#define CR0_WP 0x00010000 /* Write Protect (honor PG_RW in all modes) */ +#define CR0_AM 0x00040000 /* Alignment Mask (set to enable AC flag) */ +#define CR0_NW 0x20000000 /* Not Write-through */ +#define CR0_CD 0x40000000 /* Cache Disable */ + +/* + * bits in CR3 + */ +#define CR3_PWT (1ULL << 3) +#define CR3_PCD (1ULL << 4) + +/* + * bits in the pentiums %cr4 register: + */ + +#define CR4_VME 0x00000001 /* virtual 8086 mode extension enable */ +#define CR4_PVI 0x00000002 /* protected mode virtual interrupt enable */ +#define CR4_TSD 0x00000004 /* restrict RDTSC instruction to cpl 0 only */ +#define CR4_DE 0x00000008 /* debugging extension */ +#define CR4_PSE 0x00000010 /* large (4MB) page size enable */ +#define CR4_PAE 0x00000020 /* physical address extension enable */ +#define CR4_MCE 0x00000040 /* machine check enable */ +#define CR4_PGE 0x00000080 /* page global enable */ +#define CR4_PCE 0x00000100 /* enable RDPMC instruction for all cpls */ +#define CR4_OSFXSR 0x00000200 /* enable fxsave/fxrestor and SSE */ +#define CR4_OSXMMEXCPT 0x00000400 /* enable unmasked SSE exceptions */ +#define CR4_UMIP 0x00000800 /* user mode instruction prevention */ +#define CR4_VMXE 0x00002000 /* enable virtual machine operation */ +#define CR4_SMXE 0x00004000 /* enable safe mode operation */ +#define CR4_FSGSBASE 0x00010000 /* enable {RD,WR}{FS,GS}BASE ops */ +#define CR4_PCIDE 0x00020000 /* enable process-context IDs */ +#define CR4_OSXSAVE 0x00040000 /* enable XSAVE and extended states */ +#define CR4_SMEP 0x00100000 /* supervisor mode exec protection */ +#define CR4_SMAP 0x00200000 /* supervisor mode access prevention */ +#define CR4_PKE 0x00400000 /* protection key enable */ + +/* + * CPUID "features" bits (CPUID function 0x1): + * EDX bits, then ECX bits + */ + +#define CPUID_FPU 0x00000001 /* processor has an FPU? */ +#define CPUID_VME 0x00000002 /* has virtual mode (%cr4's VME/PVI) */ +#define CPUID_DE 0x00000004 /* has debugging extension */ +#define CPUID_PSE 0x00000008 /* has 4MB page size extension */ +#define CPUID_TSC 0x00000010 /* has time stamp counter */ +#define CPUID_MSR 0x00000020 /* has model specific registers */ +#define CPUID_PAE 0x00000040 /* has phys address extension */ +#define CPUID_MCE 0x00000080 /* has machine check exception */ +#define CPUID_CX8 0x00000100 /* has CMPXCHG8B instruction */ +#define CPUID_APIC 0x00000200 /* has enabled APIC */ +#define CPUID_SYS1 0x00000400 /* has SYSCALL/SYSRET inst. (Cyrix) */ +#define CPUID_SEP 0x00000800 /* has SYSCALL/SYSRET inst. (AMD/Intel) */ +#define CPUID_MTRR 0x00001000 /* has memory type range register */ +#define CPUID_PGE 0x00002000 /* has page global extension */ +#define CPUID_MCA 0x00004000 /* has machine check architecture */ +#define CPUID_CMOV 0x00008000 /* has CMOVcc instruction */ +#define CPUID_PAT 0x00010000 /* has page attribute table */ +#define CPUID_PSE36 0x00020000 /* has 36bit page size extension */ +#define CPUID_PSN 0x00040000 /* has processor serial number */ +#define CPUID_CFLUSH 0x00080000 /* CFLUSH insn supported */ +#define CPUID_B20 0x00100000 /* reserved */ +#define CPUID_DS 0x00200000 /* Debug Store */ +#define CPUID_ACPI 0x00400000 /* ACPI performance modulation regs */ +#define CPUID_MMX 0x00800000 /* has MMX instructions */ +#define CPUID_FXSR 0x01000000 /* has FXRSTOR instruction */ +#define CPUID_SSE 0x02000000 /* has streaming SIMD extensions */ +#define CPUID_SSE2 0x04000000 /* has streaming SIMD extensions #2 */ +#define CPUID_SS 0x08000000 /* self-snoop */ +#define CPUID_HTT 0x10000000 /* Hyper-Threading Technology */ +#define CPUID_TM 0x20000000 /* thermal monitor (TCC) */ +#define CPUID_B30 0x40000000 /* reserved */ +#define CPUID_PBE 0x80000000 /* Pending Break Enabled restarts clock */ + +#define CPUIDECX_SSE3 0x00000001 /* streaming SIMD extensions #3 */ +#define CPUIDECX_PCLMUL 0x00000002 /* Carryless Multiplication */ +#define CPUIDECX_DTES64 0x00000004 /* 64bit debug store */ +#define CPUIDECX_MWAIT 0x00000008 /* Monitor/Mwait */ +#define CPUIDECX_DSCPL 0x00000010 /* CPL Qualified Debug Store */ +#define CPUIDECX_VMX 0x00000020 /* Virtual Machine Extensions */ +#define CPUIDECX_SMX 0x00000040 /* Safer Mode Extensions */ +#define CPUIDECX_EST 0x00000080 /* enhanced SpeedStep */ +#define CPUIDECX_TM2 0x00000100 /* thermal monitor 2 */ +#define CPUIDECX_SSSE3 0x00000200 /* Supplemental Streaming SIMD Ext. 3 */ +#define CPUIDECX_CNXTID 0x00000400 /* Context ID */ +#define CPUIDECX_SDBG 0x00000800 /* Silicon debug capability */ +#define CPUIDECX_FMA3 0x00001000 /* Fused Multiply Add */ +#define CPUIDECX_CX16 0x00002000 /* has CMPXCHG16B instruction */ +#define CPUIDECX_XTPR 0x00004000 /* xTPR Update Control */ +#define CPUIDECX_PDCM 0x00008000 /* Perfmon and Debug Capability */ +#define CPUIDECX_PCID 0x00020000 /* Process-context ID Capability */ +#define CPUIDECX_DCA 0x00040000 /* Direct Cache Access */ +#define CPUIDECX_SSE41 0x00080000 /* Streaming SIMD Extensions 4.1 */ +#define CPUIDECX_SSE42 0x00100000 /* Streaming SIMD Extensions 4.2 */ +#define CPUIDECX_X2APIC 0x00200000 /* Extended xAPIC Support */ +#define CPUIDECX_MOVBE 0x00400000 /* MOVBE Instruction */ +#define CPUIDECX_POPCNT 0x00800000 /* POPCNT Instruction */ +#define CPUIDECX_DEADLINE 0x01000000 /* APIC one-shot via deadline */ +#define CPUIDECX_AES 0x02000000 /* AES Instruction */ +#define CPUIDECX_XSAVE 0x04000000 /* XSAVE/XSTOR States */ +#define CPUIDECX_OSXSAVE 0x08000000 /* OSXSAVE */ +#define CPUIDECX_AVX 0x10000000 /* Advanced Vector Extensions */ +#define CPUIDECX_F16C 0x20000000 /* 16bit fp conversion */ +#define CPUIDECX_RDRAND 0x40000000 /* RDRAND instruction */ +#define CPUIDECX_HV 0x80000000 /* Running on hypervisor */ + +/* + * "Structured Extended Feature Flags Parameters" (CPUID function 0x7, leaf 0) + * EBX bits + */ +#define SEFF0EBX_FSGSBASE 0x00000001 /* {RD,WR}[FG]SBASE instructions */ +#define SEFF0EBX_TSC_ADJUST 0x00000002 /* Has IA32_TSC_ADJUST MSR */ +#define SEFF0EBX_SGX 0x00000004 /* Software Guard Extensions */ +#define SEFF0EBX_BMI1 0x00000008 /* advanced bit manipulation */ +#define SEFF0EBX_HLE 0x00000010 /* Hardware Lock Elision */ +#define SEFF0EBX_AVX2 0x00000020 /* Advanced Vector Extensions 2 */ +#define SEFF0EBX_SMEP 0x00000080 /* Supervisor mode exec protection */ +#define SEFF0EBX_BMI2 0x00000100 /* advanced bit manipulation */ +#define SEFF0EBX_ERMS 0x00000200 /* Enhanced REP MOVSB/STOSB */ +#define SEFF0EBX_INVPCID 0x00000400 /* INVPCID instruction */ +#define SEFF0EBX_RTM 0x00000800 /* Restricted Transactional Memory */ +#define SEFF0EBX_PQM 0x00001000 /* Quality of Service Monitoring */ +#define SEFF0EBX_MPX 0x00004000 /* Memory Protection Extensions */ +#define SEFF0EBX_AVX512F 0x00010000 /* AVX-512 foundation inst */ +#define SEFF0EBX_AVX512DQ 0x00020000 /* AVX-512 double/quadword */ +#define SEFF0EBX_RDSEED 0x00040000 /* RDSEED instruction */ +#define SEFF0EBX_ADX 0x00080000 /* ADCX/ADOX instructions */ +#define SEFF0EBX_SMAP 0x00100000 /* Supervisor mode access prevent */ +#define SEFF0EBX_AVX512IFMA 0x00200000 /* AVX-512 integer mult-add */ +#define SEFF0EBX_PCOMMIT 0x00400000 /* Persistent commit inst */ +#define SEFF0EBX_CLFLUSHOPT 0x00800000 /* cache line flush */ +#define SEFF0EBX_CLWB 0x01000000 /* cache line write back */ +#define SEFF0EBX_PT 0x02000000 /* Processor Trace */ +#define SEFF0EBX_AVX512PF 0x04000000 /* AVX-512 prefetch */ +#define SEFF0EBX_AVX512ER 0x08000000 /* AVX-512 exp/reciprocal */ +#define SEFF0EBX_AVX512CD 0x10000000 /* AVX-512 conflict detection */ +#define SEFF0EBX_SHA 0x20000000 /* SHA Extensions */ +#define SEFF0EBX_AVX512BW 0x40000000 /* AVX-512 byte/word inst */ +#define SEFF0EBX_AVX512VL 0x80000000 /* AVX-512 vector len inst */ +/* SEFF ECX bits */ +#define SEFF0ECX_PREFETCHWT1 0x00000001 /* PREFETCHWT1 instruction */ +#define SEFF0ECX_AVX512VBMI 0x00000002 /* AVX-512 vector bit inst */ +#define SEFF0ECX_UMIP 0x00000004 /* UMIP support */ +#define SEFF0ECX_PKU 0x00000008 /* Page prot keys for user mode */ +#define SEFF0ECX_WAITPKG 0x00000020 /* UMONITOR/UMWAIT/TPAUSE insns */ +/* SEFF EDX bits */ +#define SEFF0EDX_AVX512_4FNNIW 0x00000004 /* AVX-512 neural network insns */ +#define SEFF0EDX_AVX512_4FMAPS 0x00000008 /* AVX-512 mult accum single prec */ +#define SEFF0EDX_SRBDS_CTRL 0x00000200 /* MCU_OPT_CTRL MSR */ +#define SEFF0EDX_MD_CLEAR 0x00000400 /* Microarch Data Clear */ +#define SEFF0EDX_TSXFA 0x00002000 /* TSX Forced Abort */ +#define SEFF0EDX_IBRS 0x04000000 /* IBRS / IBPB Speculation Control */ +#define SEFF0EDX_STIBP 0x08000000 /* STIBP Speculation Control */ +#define SEFF0EDX_L1DF 0x10000000 /* L1D_FLUSH */ +#define SEFF0EDX_ARCH_CAP 0x20000000 /* Has IA32_ARCH_CAPABILITIES MSR */ +#define SEFF0EDX_SSBD 0x80000000 /* Spec Store Bypass Disable */ + +/* + * Thermal and Power Management (CPUID function 0x6) EAX bits + */ +#define TPM_SENSOR 0x00000001 /* Digital temp sensor */ +#define TPM_ARAT 0x00000004 /* APIC Timer Always Running */ + +/* + * "Architectural Performance Monitoring" bits (CPUID function 0x0a): + * EAX bits + */ + +#define CPUIDEAX_VERID 0x000000ff +#define CPUIDEAX_NUM_GC(cpuid) (((cpuid) >> 8) & 0x000000ff) +#define CPUIDEAX_BIT_GC(cpuid) (((cpuid) >> 16) & 0x000000ff) +#define CPUIDEAX_LEN_EBX(cpuid) (((cpuid) >> 24) & 0x000000ff) + +#define CPUIDEBX_EVT_CORE (1 << 0) /* Core cycle */ +#define CPUIDEBX_EVT_INST (1 << 1) /* Instruction retired */ +#define CPUIDEBX_EVT_REFR (1 << 2) /* Reference cycles */ +#define CPUIDEBX_EVT_CACHE_REF (1 << 3) /* Last-level cache ref. */ +#define CPUIDEBX_EVT_CACHE_MIS (1 << 4) /* Last-level cache miss. */ +#define CPUIDEBX_EVT_BRANCH_INST (1 << 5) /* Branch instruction ret. */ +#define CPUIDEBX_EVT_BRANCH_MISP (1 << 6) /* Branch mispredict ret. */ + +#define CPUIDEDX_NUM_FC(cpuid) (((cpuid) >> 0) & 0x0000001f) +#define CPUIDEDX_BIT_FC(cpuid) (((cpuid) >> 5) & 0x000000ff) + +/* + * CPUID "extended features" bits (CPUID function 0x80000001): + * EDX bits, then ECX bits + */ + +#define CPUID_MPC 0x00080000 /* Multiprocessing Capable */ +#define CPUID_NXE 0x00100000 /* No-Execute Extension */ +#define CPUID_MMXX 0x00400000 /* AMD MMX Extensions */ +#define CPUID_FFXSR 0x02000000 /* fast FP/MMX save/restore */ +#define CPUID_PAGE1GB 0x04000000 /* 1-GByte pages */ +#define CPUID_RDTSCP 0x08000000 /* RDTSCP / IA32_TSC_AUX available */ +#define CPUID_LONG 0x20000000 /* long mode */ +#define CPUID_3DNOW2 0x40000000 /* 3DNow! Instruction Extension */ +#define CPUID_3DNOW 0x80000000 /* 3DNow! Instructions */ + +#define CPUIDECX_LAHF 0x00000001 /* LAHF and SAHF instructions */ +#define CPUIDECX_CMPLEG 0x00000002 /* Core MP legacy mode */ +#define CPUIDECX_SVM 0x00000004 /* Secure Virtual Machine */ +#define CPUIDECX_EAPICSP 0x00000008 /* Extended APIC space */ +#define CPUIDECX_AMCR8 0x00000010 /* LOCK MOV CR0 means MOV CR8 */ +#define CPUIDECX_ABM 0x00000020 /* LZCNT instruction */ +#define CPUIDECX_SSE4A 0x00000040 /* SSE4-A instruction set */ +#define CPUIDECX_MASSE 0x00000080 /* Misaligned SSE mode */ +#define CPUIDECX_3DNOWP 0x00000100 /* 3DNowPrefetch */ +#define CPUIDECX_OSVW 0x00000200 /* OS visible workaround */ +#define CPUIDECX_IBS 0x00000400 /* Instruction based sampling */ +#define CPUIDECX_XOP 0x00000800 /* Extended operating support */ +#define CPUIDECX_SKINIT 0x00001000 /* SKINIT and STGI are supported */ +#define CPUIDECX_WDT 0x00002000 /* Watchdog timer */ +/* Reserved 0x00004000 */ +#define CPUIDECX_LWP 0x00008000 /* Lightweight profiling support */ +#define CPUIDECX_FMA4 0x00010000 /* 4-operand FMA instructions */ +#define CPUIDECX_TCE 0x00020000 /* Translation Cache Extension */ +/* Reserved 0x00040000 */ +#define CPUIDECX_NODEID 0x00080000 /* Support for MSRC001C */ +/* Reserved 0x00100000 */ +#define CPUIDECX_TBM 0x00200000 /* Trailing bit manipulation instruction */ +#define CPUIDECX_TOPEXT 0x00400000 /* Topology extensions support */ +#define CPUIDECX_CPCTR 0x00800000 /* core performance counter ext */ +#define CPUIDECX_DBKP 0x04000000 /* DataBreakpointExtension */ +#define CPUIDECX_PERFTSC 0x08000000 /* performance time-stamp counter */ +#define CPUIDECX_PCTRL3 0x10000000 /* L3 performance counter ext */ +#define CPUIDECX_MWAITX 0x20000000 /* MWAITX/MONITORX */ + +/* + * "Advanced Power Management Information" bits (CPUID function 0x80000007): + * EDX bits. + */ + +#define CPUIDEDX_ITSC (1 << 8) /* Invariant TSC */ + +/* + * AMD CPUID function 0x80000008 EBX bits + */ +#define CPUIDEBX_IBPB (1ULL << 12) /* Speculation Control IBPB */ +#define CPUIDEBX_IBRS (1ULL << 14) /* Speculation Control IBRS */ +#define CPUIDEBX_STIBP (1ULL << 15) /* Speculation Control STIBP */ +#define CPUIDEBX_IBRS_ALWAYSON (1ULL << 16) /* IBRS always on mode */ +#define CPUIDEBX_STIBP_ALWAYSON (1ULL << 17) /* STIBP always on mode */ +#define CPUIDEBX_IBRS_PREF (1ULL << 18) /* IBRS preferred */ +#define CPUIDEBX_SSBD (1ULL << 24) /* Speculation Control SSBD */ +#define CPUIDEBX_VIRT_SSBD (1ULL << 25) /* Virt Spec Control SSBD */ +#define CPUIDEBX_SSBD_NOTREQ (1ULL << 26) /* SSBD not required */ + +#define CPUID2FAMILY(cpuid) (((cpuid) >> 8) & 15) +#define CPUID2MODEL(cpuid) (((cpuid) >> 4) & 15) +#define CPUID2STEPPING(cpuid) ((cpuid) & 15) + +#define CPUID(code, eax, ebx, ecx, edx) \ + __asm volatile("cpuid" \ + : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) \ + : "a" (code)) +#define CPUID_LEAF(code, leaf, eax, ebx, ecx, edx) \ + __asm volatile("cpuid" \ + : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) \ + : "a" (code), "c" (leaf)) + + +/* + * Model-specific registers for the i386 family + */ +#define MSR_P5_MC_ADDR 0x000 +#define MSR_P5_MC_TYPE 0x001 +#define MSR_TSC 0x010 +#define P5MSR_CTRSEL 0x011 /* P5 only (trap on P6) */ +#define P5MSR_CTR0 0x012 /* P5 only (trap on P6) */ +#define P5MSR_CTR1 0x013 /* P5 only (trap on P6) */ +#define MSR_PLATFORM_ID 0x017 /* Platform ID for microcode */ +#define MSR_APICBASE 0x01b +#define APICBASE_BSP 0x100 +#define APICBASE_ENABLE_X2APIC 0x400 +#define APICBASE_GLOBAL_ENABLE 0x800 +#define MSR_EBL_CR_POWERON 0x02a +#define MSR_EBC_FREQUENCY_ID 0x02c /* Pentium 4 only */ +#define MSR_TEST_CTL 0x033 +#define MSR_IA32_FEATURE_CONTROL 0x03a +#define MSR_SPEC_CTRL 0x048 /* Speculation Control IBRS / STIBP */ +#define SPEC_CTRL_IBRS (1ULL << 0) +#define SPEC_CTRL_STIBP (1ULL << 1) +#define SPEC_CTRL_SSBD (1ULL << 2) +#define MSR_PRED_CMD 0x049 /* Speculation Control IBPB */ +#define PRED_CMD_IBPB (1ULL << 0) +#define MSR_BIOS_UPDT_TRIG 0x079 +#define MSR_BBL_CR_D0 0x088 /* PII+ only */ +#define MSR_BBL_CR_D1 0x089 /* PII+ only */ +#define MSR_BBL_CR_D2 0x08a /* PII+ only */ +#define MSR_BIOS_SIGN 0x08b +#define MSR_PERFCTR0 0x0c1 +#define MSR_PERFCTR1 0x0c2 +#define P6MSR_CTR0 0x0c1 +#define P6MSR_CTR1 0x0c2 +#define MSR_FSB_FREQ 0x0cd /* Core Duo/Solo only */ +#define MSR_MTRRcap 0x0fe +#define MTRRcap_FIXED 0x100 /* bit 8 - fixed MTRRs supported */ +#define MTRRcap_WC 0x400 /* bit 10 - WC type supported */ +#define MTRRcap_SMRR 0x800 /* bit 11 - SMM range reg supported */ +#define MSR_ARCH_CAPABILITIES 0x10a +#define ARCH_CAP_RDCL_NO (1 << 0) /* Meltdown safe */ +#define ARCH_CAP_IBRS_ALL (1 << 1) /* enhanced IBRS */ +#define ARCH_CAP_RSBA (1 << 2) /* RSB Alternate */ +#define ARCH_CAP_SKIP_L1DFL_VMENTRY (1 << 3) +#define ARCH_CAP_SSB_NO (1 << 4) /* Spec St Byp safe */ +#define ARCH_CAP_MDS_NO (1 << 5) /* microarch data-sampling */ +#define ARCH_CAP_IF_PSCHANGE_MC_NO (1 << 6) /* PS MCE safe */ +#define ARCH_CAP_TSX_CTRL (1 << 7) /* has TSX_CTRL MSR */ +#define ARCH_CAP_TAA_NO (1 << 8) /* TSX AA safe */ +#define ARCH_CAP_MCU_CONTROL (1 << 9) /* has MCU_CTRL MSR */ +#define ARCH_CAP_MISC_PACKAGE_CTLS (1 << 10) /* has MISC_PKG_CTLS MSR */ +#define ARCH_CAP_ENERGY_FILTERING_CTL (1 << 11) /* r/w energy fltring bit */ +#define ARCH_CAP_DOITM (1 << 12) /* Data oprnd indpdnt tmng */ +#define ARCH_CAP_SBDR_SSDP_NO (1 << 13) /* SBDR/SSDP safe */ +#define ARCH_CAP_FBSDP_NO (1 << 14) /* FBSDP safe */ +#define ARCH_CAP_PSDP_NO (1 << 15) /* PSDP safe */ +#define ARCH_CAP_FB_CLEAR (1 << 17) /* MD_CLEAR covers FB */ +#define ARCH_CAP_FB_CLEAR_CTRL (1 << 18) +#define ARCH_CAP_RRSBA (1 << 19) /* has RRSBA if not dis */ +#define ARCH_CAP_BHI_NO (1 << 20) /* BHI safe */ +#define ARCH_CAP_XAPIC_DISABLE_STATUS (1 << 21) /* can disable xAPIC */ +#define ARCH_CAP_OVERCLOCKING_STATUS (1 << 23) /* has OVRCLCKNG_STAT MSR */ +#define ARCH_CAP_PBRSB_NO (1 << 24) /* PBSR safe */ +#define ARCH_CAP_GDS_CTRL (1 << 25) /* has GDS_MITG_DIS/LOCK */ +#define ARCH_CAP_GDS_NO (1 << 26) /* GDS safe */ +#define MSR_FLUSH_CMD 0x10b +#define FLUSH_CMD_L1D_FLUSH (1ULL << 0) +#define MSR_BBL_CR_ADDR 0x116 /* PII+ only */ +#define MSR_BBL_CR_DECC 0x118 /* PII+ only */ +#define MSR_BBL_CR_CTL 0x119 /* PII+ only */ +#define MSR_BBL_CR_TRIG 0x11a /* PII+ only */ +#define MSR_BBL_CR_BUSY 0x11b /* PII+ only */ +#define MSR_BBL_CR_CTR3 0x11e /* PII+ only */ +#define MSR_TSX_CTRL 0x122 +#define TSX_CTRL_RTM_DISABLE (1ULL << 0) +#define TSX_CTRL_TSX_CPUID_CLEAR (1ULL << 1) +#define MSR_MCU_OPT_CTRL 0x123 +#define RNGDS_MITG_DIS (1ULL << 0) +#define MSR_SYSENTER_CS 0x174 +#define MSR_SYSENTER_ESP 0x175 +#define MSR_SYSENTER_EIP 0x176 +#define MSR_MCG_CAP 0x179 +#define MSR_MCG_STATUS 0x17a +#define MSR_MCG_CTL 0x17b +#define P6MSR_CTRSEL0 0x186 +#define P6MSR_CTRSEL1 0x187 +#define MSR_PERF_STATUS 0x198 /* Pentium M */ +#define MSR_PERF_CTL 0x199 /* Pentium M */ +#define PERF_CTL_TURBO 0x100000000ULL /* bit 32 - turbo mode */ +#define MSR_THERM_CONTROL 0x19a +#define MSR_THERM_INTERRUPT 0x19b +#define MSR_THERM_STATUS 0x19c +#define MSR_THERM_STATUS_VALID_BIT 0x80000000 +#define MSR_THERM_STATUS_TEMP(msr) ((msr >> 16) & 0x7f) +#define MSR_THERM2_CTL 0x19d /* Pentium M */ +#define MSR_MISC_ENABLE 0x1a0 +/* + * MSR_MISC_ENABLE (0x1a0) + * + * Enable Fast Strings: enables fast REP MOVS/REP STORS (R/W) + * Enable TCC: Enable automatic thermal control circuit (R/W) + * Performance monitoring available: 1 if enabled (R/O) + * Branch trace storage unavailable: 1 if unsupported (R/O) + * Processor event based sampling unavailable: 1 if unsupported (R/O) + * Enhanced Intel SpeedStep technology enable: 1 to enable (R/W) + * Enable monitor FSM: 1 to enable MONITOR/MWAIT (R/W) + * Limit CPUID maxval: 1 to limit CPUID leaf nodes to 0x2 and lower (R/W) + * Enable xTPR message disable: 1 to disable xTPR messages + * XD bit disable: 1 to disable NX capability (bit 34, or bit 2 of %edx/%rdx) + */ +#define MISC_ENABLE_FAST_STRINGS (1 << 0) +#define MISC_ENABLE_TCC (1 << 3) +#define MISC_ENABLE_PERF_MON_AVAILABLE (1 << 7) +#define MISC_ENABLE_BTS_UNAVAILABLE (1 << 11) +#define MISC_ENABLE_PEBS_UNAVAILABLE (1 << 12) +#define MISC_ENABLE_EIST_ENABLED (1 << 16) +#define MISC_ENABLE_ENABLE_MONITOR_FSM (1 << 18) +#define MISC_ENABLE_LIMIT_CPUID_MAXVAL (1 << 22) +#define MISC_ENABLE_xTPR_MESSAGE_DISABLE (1 << 23) +#define MISC_ENABLE_XD_BIT_DISABLE (1 << 2) +/* + * for Core i Series and newer Xeons, see + * http://www.intel.com/content/dam/www/public/us/en/ + * documents/white-papers/cpu-monitoring-dts-peci-paper.pdf + */ +#define MSR_TEMPERATURE_TARGET 0x1a2 /* Core i Series, Newer Xeons */ +#define MSR_TEMPERATURE_TARGET_TJMAX(r) (((r) >> 16) & 0xff) +/* + * not documented anywhere, see intelcore_update_sensor() + * only available Core Duo and Core Solo Processors + */ +#define MSR_TEMPERATURE_TARGET_UNDOCUMENTED 0x0ee +#define MSR_TEMPERATURE_TARGET_LOW_BIT_UNDOCUMENTED 0x40000000 +#define MSR_DEBUGCTLMSR 0x1d9 +#define MSR_LASTBRANCHFROMIP 0x1db +#define MSR_LASTBRANCHTOIP 0x1dc +#define MSR_LASTINTFROMIP 0x1dd +#define MSR_LASTINTTOIP 0x1de +#define MSR_ROB_CR_BKUPTMPDR6 0x1e0 +#define MSR_MTRRvarBase 0x200 +#define MSR_MTRRfix64K_00000 0x250 +#define MSR_MTRRfix16K_80000 0x258 +#define MSR_MTRRfix4K_C0000 0x268 +#define MSR_CR_PAT 0x277 +#define MSR_MTRRdefType 0x2ff +#define MTRRdefType_FIXED_ENABLE 0x400 /* bit 10 - fixed MTRR enabled */ +#define MTRRdefType_ENABLE 0x800 /* bit 11 - MTRRs enabled */ +#define MSR_PERF_FIXED_CTR1 0x30a /* CPU_CLK_Unhalted.Core */ +#define MSR_PERF_FIXED_CTR2 0x30b /* CPU_CLK.Unhalted.Ref */ +#define MSR_PERF_FIXED_CTR_CTRL 0x38d +#define MSR_PERF_FIXED_CTR_FC_DIS 0x0 /* disable counter */ +#define MSR_PERF_FIXED_CTR_FC_1 0x1 /* count ring 1 */ +#define MSR_PERF_FIXED_CTR_FC_123 0x2 /* count rings 1,2,3 */ +#define MSR_PERF_FIXED_CTR_FC_ANY 0x3 /* count everything */ +#define MSR_PERF_FIXED_CTR_FC_MASK 0x3 +#define MSR_PERF_FIXED_CTR_FC(_i, _v) ((_v) << (4 * (_i))) +#define MSR_PERF_FIXED_CTR_ANYTHR(_i) (0x4 << (4 * (_i))) +#define MSR_PERF_FIXED_CTR_INT(_i) (0x8 << (4 * (_i))) +#define MSR_PERF_GLOBAL_CTRL 0x38f +#define MSR_PERF_GLOBAL_CTR1_EN (1ULL << 33) +#define MSR_PERF_GLOBAL_CTR2_EN (1ULL << 34) +#define MSR_MC0_CTL 0x400 +#define MSR_MC0_STATUS 0x401 +#define MSR_MC0_ADDR 0x402 +#define MSR_MC0_MISC 0x403 +#define MSR_MC1_CTL 0x404 +#define MSR_MC1_STATUS 0x405 +#define MSR_MC1_ADDR 0x406 +#define MSR_MC1_MISC 0x407 +#define MSR_MC2_CTL 0x408 +#define MSR_MC2_STATUS 0x409 +#define MSR_MC2_ADDR 0x40a +#define MSR_MC2_MISC 0x40b +#define MSR_MC4_CTL 0x40c +#define MSR_MC4_STATUS 0x40d +#define MSR_MC4_ADDR 0x40e +#define MSR_MC4_MISC 0x40f +#define MSR_MC3_CTL 0x410 +#define MSR_MC3_STATUS 0x411 +#define MSR_MC3_ADDR 0x412 +#define MSR_MC3_MISC 0x413 + +/* VIA MSRs */ +#define MSR_CENT_TMTEMPERATURE 0x1423 /* Thermal monitor temperature */ +#define MSR_C7M_TMTEMPERATURE 0x1169 + +/* AMD MSRs */ +#define MSR_K6_EPMR 0xc0000086 +#define MSR_K7_EVNTSEL0 0xc0010000 +#define MSR_K7_EVNTSEL1 0xc0010001 +#define MSR_K7_EVNTSEL2 0xc0010002 +#define MSR_K7_EVNTSEL3 0xc0010003 +#define MSR_K7_PERFCTR0 0xc0010004 +#define MSR_K7_PERFCTR1 0xc0010005 +#define MSR_K7_PERFCTR2 0xc0010006 +#define MSR_K7_PERFCTR3 0xc0010007 + +/* + * AMD K8 (Opteron) MSRs. + */ +#define MSR_PATCH_LEVEL 0x0000008b +#define MSR_SYSCFG 0xc0000010 + +#define MSR_EFER 0xc0000080 /* Extended feature enable */ +#define EFER_SCE 0x00000001 /* SYSCALL extension */ +#define EFER_LME 0x00000100 /* Long Mode Active */ +#define EFER_LMA 0x00000400 /* Long Mode Enabled */ +#define EFER_NXE 0x00000800 /* No-Execute Enabled */ +#define EFER_SVME 0x00001000 /* SVM Enabled */ + +#define MSR_STAR 0xc0000081 /* 32 bit syscall gate addr */ +#define MSR_LSTAR 0xc0000082 /* 64 bit syscall gate addr */ +#define MSR_CSTAR 0xc0000083 /* compat syscall gate addr */ +#define MSR_SFMASK 0xc0000084 /* flags to clear on syscall */ + +#define MSR_FSBASE 0xc0000100 /* 64bit offset for fs: */ +#define MSR_GSBASE 0xc0000101 /* 64bit offset for gs: */ +#define MSR_KERNELGSBASE 0xc0000102 /* storage for swapgs ins */ +#define MSR_PATCH_LOADER 0xc0010020 +#define MSR_INT_PEN_MSG 0xc0010055 /* Interrupt pending message */ + +#define MSR_DE_CFG 0xc0011029 /* Decode Configuration */ +#define DE_CFG_721 0x00000001 /* errata 721 */ +#define DE_CFG_SERIALIZE_LFENCE (1 << 1) /* Enable serializing lfence */ +#define DE_CFG_SERIALIZE_9 (1 << 9) /* Zenbleed chickenbit */ + +#define IPM_C1E_CMP_HLT 0x10000000 +#define IPM_SMI_CMP_HLT 0x08000000 + +/* + * These require a 'passcode' for access. See cpufunc.h. + */ +#define MSR_HWCR 0xc0010015 +#define HWCR_FFDIS 0x00000040 + +#define MSR_NB_CFG 0xc001001f +#define NB_CFG_DISIOREQLOCK 0x0000000000000004ULL +#define NB_CFG_DISDATMSK 0x0000001000000000ULL + +#define MSR_LS_CFG 0xc0011020 +#define LS_CFG_DIS_LS2_SQUISH 0x02000000 + +#define MSR_IC_CFG 0xc0011021 +#define IC_CFG_DIS_SEQ_PREFETCH 0x00000800 + +#define MSR_DC_CFG 0xc0011022 +#define DC_CFG_DIS_CNV_WC_SSO 0x00000004 +#define DC_CFG_DIS_SMC_CHK_BUF 0x00000400 + +#define MSR_BU_CFG 0xc0011023 +#define BU_CFG_THRL2IDXCMPDIS 0x0000080000000000ULL +#define BU_CFG_WBPFSMCCHKDIS 0x0000200000000000ULL +#define BU_CFG_WBENHWSBDIS 0x0001000000000000ULL + +/* + * Constants related to MTRRs + */ +#define MTRR_N64K 8 /* numbers of fixed-size entries */ +#define MTRR_N16K 16 +#define MTRR_N4K 64 + +/* + * the following four 3-byte registers control the non-cacheable regions. + * These registers must be written as three separate bytes. + * + * NCRx+0: A31-A24 of starting address + * NCRx+1: A23-A16 of starting address + * NCRx+2: A15-A12 of starting address | NCR_SIZE_xx. + * + * The non-cacheable region's starting address must be aligned to the + * size indicated by the NCR_SIZE_xx field. + */ +#define NCR1 0xc4 +#define NCR2 0xc7 +#define NCR3 0xca +#define NCR4 0xcd + +#define NCR_SIZE_0K 0 +#define NCR_SIZE_4K 1 +#define NCR_SIZE_8K 2 +#define NCR_SIZE_16K 3 +#define NCR_SIZE_32K 4 +#define NCR_SIZE_64K 5 +#define NCR_SIZE_128K 6 +#define NCR_SIZE_256K 7 +#define NCR_SIZE_512K 8 +#define NCR_SIZE_1M 9 +#define NCR_SIZE_2M 10 +#define NCR_SIZE_4M 11 +#define NCR_SIZE_8M 12 +#define NCR_SIZE_16M 13 +#define NCR_SIZE_32M 14 +#define NCR_SIZE_4G 15 + +/* + * Performance monitor events. + * + * Note that 586-class and 686-class CPUs have different performance + * monitors available, and they are accessed differently: + * + * 686-class: `rdpmc' instruction + * 586-class: `rdmsr' instruction, CESR MSR + * + * The descriptions of these events are too lengthy to include here. + * See Appendix A of "Intel Architecture Software Developer's + * Manual, Volume 3: System Programming" for more information. + */ + +/* + * 586-class CESR MSR format. Lower 16 bits is CTR0, upper 16 bits + * is CTR1. + */ + +#define PMC5_CESR_EVENT 0x003f +#define PMC5_CESR_OS 0x0040 +#define PMC5_CESR_USR 0x0080 +#define PMC5_CESR_E 0x0100 +#define PMC5_CESR_P 0x0200 + +/* + * 686-class Event Selector MSR format. + */ + +#define PMC6_EVTSEL_EVENT 0x000000ff +#define PMC6_EVTSEL_UNIT 0x0000ff00 +#define PMC6_EVTSEL_UNIT_SHIFT 8 +#define PMC6_EVTSEL_USR (1 << 16) +#define PMC6_EVTSEL_OS (1 << 17) +#define PMC6_EVTSEL_E (1 << 18) +#define PMC6_EVTSEL_PC (1 << 19) +#define PMC6_EVTSEL_INT (1 << 20) +#define PMC6_EVTSEL_EN (1 << 22) /* PerfEvtSel0 only */ +#define PMC6_EVTSEL_INV (1 << 23) +#define PMC6_EVTSEL_COUNTER_MASK 0xff000000 +#define PMC6_EVTSEL_COUNTER_MASK_SHIFT 24 + +/* Data Cache Unit */ +#define PMC6_DATA_MEM_REFS 0x43 +#define PMC6_DCU_LINES_IN 0x45 +#define PMC6_DCU_M_LINES_IN 0x46 +#define PMC6_DCU_M_LINES_OUT 0x47 +#define PMC6_DCU_MISS_OUTSTANDING 0x48 + +/* Instruction Fetch Unit */ +#define PMC6_IFU_IFETCH 0x80 +#define PMC6_IFU_IFETCH_MISS 0x81 +#define PMC6_ITLB_MISS 0x85 +#define PMC6_IFU_MEM_STALL 0x86 +#define PMC6_ILD_STALL 0x87 + +/* L2 Cache */ +#define PMC6_L2_IFETCH 0x28 +#define PMC6_L2_LD 0x29 +#define PMC6_L2_ST 0x2a +#define PMC6_L2_LINES_IN 0x24 +#define PMC6_L2_LINES_OUT 0x26 +#define PMC6_L2_M_LINES_INM 0x25 +#define PMC6_L2_M_LINES_OUTM 0x27 +#define PMC6_L2_RQSTS 0x2e +#define PMC6_L2_ADS 0x21 +#define PMC6_L2_DBUS_BUSY 0x22 +#define PMC6_L2_DBUS_BUSY_RD 0x23 + +/* External Bus Logic */ +#define PMC6_BUS_DRDY_CLOCKS 0x62 +#define PMC6_BUS_LOCK_CLOCKS 0x63 +#define PMC6_BUS_REQ_OUTSTANDING 0x60 +#define PMC6_BUS_TRAN_BRD 0x65 +#define PMC6_BUS_TRAN_RFO 0x66 +#define PMC6_BUS_TRANS_WB 0x67 +#define PMC6_BUS_TRAN_IFETCH 0x68 +#define PMC6_BUS_TRAN_INVAL 0x69 +#define PMC6_BUS_TRAN_PWR 0x6a +#define PMC6_BUS_TRANS_P 0x6b +#define PMC6_BUS_TRANS_IO 0x6c +#define PMC6_BUS_TRAN_DEF 0x6d +#define PMC6_BUS_TRAN_BURST 0x6e +#define PMC6_BUS_TRAN_ANY 0x70 +#define PMC6_BUS_TRAN_MEM 0x6f +#define PMC6_BUS_DATA_RCV 0x64 +#define PMC6_BUS_BNR_DRV 0x61 +#define PMC6_BUS_HIT_DRV 0x7a +#define PMC6_BUS_HITM_DRDV 0x7b +#define PMC6_BUS_SNOOP_STALL 0x7e + +/* Floating Point Unit */ +#define PMC6_FLOPS 0xc1 +#define PMC6_FP_COMP_OPS_EXE 0x10 +#define PMC6_FP_ASSIST 0x11 +#define PMC6_MUL 0x12 +#define PMC6_DIV 0x12 +#define PMC6_CYCLES_DIV_BUSY 0x14 + +/* Memory Ordering */ +#define PMC6_LD_BLOCKS 0x03 +#define PMC6_SB_DRAINS 0x04 +#define PMC6_MISALIGN_MEM_REF 0x05 +#define PMC6_EMON_KNI_PREF_DISPATCHED 0x07 /* P-III only */ +#define PMC6_EMON_KNI_PREF_MISS 0x4b /* P-III only */ + +/* Instruction Decoding and Retirement */ +#define PMC6_INST_RETIRED 0xc0 +#define PMC6_UOPS_RETIRED 0xc2 +#define PMC6_INST_DECODED 0xd0 +#define PMC6_EMON_KNI_INST_RETIRED 0xd8 +#define PMC6_EMON_KNI_COMP_INST_RET 0xd9 + +/* Interrupts */ +#define PMC6_HW_INT_RX 0xc8 +#define PMC6_CYCLES_INT_MASKED 0xc6 +#define PMC6_CYCLES_INT_PENDING_AND_MASKED 0xc7 + +/* Branches */ +#define PMC6_BR_INST_RETIRED 0xc4 +#define PMC6_BR_MISS_PRED_RETIRED 0xc5 +#define PMC6_BR_TAKEN_RETIRED 0xc9 +#define PMC6_BR_MISS_PRED_TAKEN_RET 0xca +#define PMC6_BR_INST_DECODED 0xe0 +#define PMC6_BTB_MISSES 0xe2 +#define PMC6_BR_BOGUS 0xe4 +#define PMC6_BACLEARS 0xe6 + +/* Stalls */ +#define PMC6_RESOURCE_STALLS 0xa2 +#define PMC6_PARTIAL_RAT_STALLS 0xd2 + +/* Segment Register Loads */ +#define PMC6_SEGMENT_REG_LOADS 0x06 + +/* Clocks */ +#define PMC6_CPU_CLK_UNHALTED 0x79 + +/* MMX Unit */ +#define PMC6_MMX_INSTR_EXEC 0xb0 /* Celeron, P-II, P-IIX only */ +#define PMC6_MMX_SAT_INSTR_EXEC 0xb1 /* P-II and P-III only */ +#define PMC6_MMX_UOPS_EXEC 0xb2 /* P-II and P-III only */ +#define PMC6_MMX_INSTR_TYPE_EXEC 0xb3 /* P-II and P-III only */ +#define PMC6_FP_MMX_TRANS 0xcc /* P-II and P-III only */ +#define PMC6_MMX_ASSIST 0xcd /* P-II and P-III only */ +#define PMC6_MMX_INSTR_RET 0xc3 /* P-II only */ + +/* Segment Register Renaming */ +#define PMC6_SEG_RENAME_STALLS 0xd4 /* P-II and P-III only */ +#define PMC6_SEG_REG_RENAMES 0xd5 /* P-II and P-III only */ +#define PMC6_RET_SEG_RENAMES 0xd6 /* P-II and P-III only */ + +/* VIA C3 crypto featureset: for i386_has_xcrypt */ +#define C3_HAS_AES 1 /* cpu has AES */ +#define C3_HAS_SHA 2 /* cpu has SHA1 & SHA256 */ +#define C3_HAS_MM 4 /* cpu has RSA instructions */ +#define C3_HAS_AESCTR 8 /* cpu has AES-CTR instructions */ + +/* Centaur Extended Feature flags */ +#define C3_CPUID_HAS_RNG 0x000004 +#define C3_CPUID_DO_RNG 0x000008 +#define C3_CPUID_HAS_ACE 0x000040 +#define C3_CPUID_DO_ACE 0x000080 +#define C3_CPUID_HAS_ACE2 0x000100 +#define C3_CPUID_DO_ACE2 0x000200 +#define C3_CPUID_HAS_PHE 0x000400 +#define C3_CPUID_DO_PHE 0x000800 +#define C3_CPUID_HAS_PMM 0x001000 +#define C3_CPUID_DO_PMM 0x002000 + +/* VIA C3 xcrypt-* instruction context control options */ +#define C3_CRYPT_CWLO_ROUND_M 0x0000000f +#define C3_CRYPT_CWLO_ALG_M 0x00000070 +#define C3_CRYPT_CWLO_ALG_AES 0x00000000 +#define C3_CRYPT_CWLO_KEYGEN_M 0x00000080 +#define C3_CRYPT_CWLO_KEYGEN_HW 0x00000000 +#define C3_CRYPT_CWLO_KEYGEN_SW 0x00000080 +#define C3_CRYPT_CWLO_NORMAL 0x00000000 +#define C3_CRYPT_CWLO_INTERMEDIATE 0x00000100 +#define C3_CRYPT_CWLO_ENCRYPT 0x00000000 +#define C3_CRYPT_CWLO_DECRYPT 0x00000200 +#define C3_CRYPT_CWLO_KEY128 0x0000000a /* 128bit, 10 rds */ +#define C3_CRYPT_CWLO_KEY192 0x0000040c /* 192bit, 12 rds */ +#define C3_CRYPT_CWLO_KEY256 0x0000080e /* 256bit, 15 rds */ + +/* Intel Silicon Debug */ +#define IA32_DEBUG_INTERFACE 0xc80 +#define IA32_DEBUG_INTERFACE_ENABLE 0x00000001 +#define IA32_DEBUG_INTERFACE_LOCK 0x40000000 +#define IA32_DEBUG_INTERFACE_MASK 0x80000000 + +/* + * PAT + */ +#define PATENTRY(n, type) ((uint64_t)type << ((n) * 8)) +#define PAT_UC 0x0UL +#define PAT_WC 0x1UL +#define PAT_WT 0x4UL +#define PAT_WP 0x5UL +#define PAT_WB 0x6UL +#define PAT_UCMINUS 0x7UL + +/* + * XSAVE subfeatures (cpuid 0xd, leaf 1) + */ +#define XSAVE_XSAVEOPT 0x1UL +#define XSAVE_XSAVEC 0x2UL +#define XSAVE_XGETBV1 0x4UL +#define XSAVE_XSAVES 0x8UL \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/sysarch.h b/lib/libc/include/x86-openbsd-none/machine/sysarch.h new file mode 100644 index 0000000000..871c60d946 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/sysarch.h @@ -0,0 +1,38 @@ +/* $OpenBSD: sysarch.h,v 1.14 2016/03/24 04:56:08 guenther Exp $ */ +/* $NetBSD: sysarch.h,v 1.8 1996/01/08 13:51:44 mycroft Exp $ */ + +#ifndef _MACHINE_SYSARCH_H_ +#define _MACHINE_SYSARCH_H_ + +/* + * Architecture specific syscalls (i386) + */ +#define I386_IOPL 2 +#define I386_VM86 5 +#define I386_GET_FSBASE 6 +#define I386_SET_FSBASE 7 +#define I386_GET_GSBASE 8 +#define I386_SET_GSBASE 9 + +struct i386_iopl_args { + int iopl; +}; + +#ifdef _KERNEL +uint32_t i386_get_threadbase(struct proc *, int); +int i386_set_threadbase(struct proc *, uint32_t, int); +#else + +#include + +__BEGIN_DECLS +int i386_iopl(int); +int i386_get_fsbase(void **); +int i386_set_fsbase(void *); +int i386_get_gsbase(void **); +int i386_set_gsbase(void *); +int sysarch(int, void *); +__END_DECLS +#endif + +#endif /* !_MACHINE_SYSARCH_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/tcb.h b/lib/libc/include/x86-openbsd-none/machine/tcb.h new file mode 100644 index 0000000000..eb8003e260 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/tcb.h @@ -0,0 +1,51 @@ +/* $OpenBSD: tcb.h,v 1.4 2016/09/04 08:49:35 guenther Exp $ */ +/* + * Copyright (c) 2011 Philip Guenther + * + * 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 + +#include +#include + +#define TCB_GET(p) \ + ((void *)i386_get_threadbase(p, TSEG_GS)) +#define TCB_SET(p, addr) \ + i386_set_threadbase(p, (uint32_t)(addr), TSEG_GS) + +#else /* _KERNEL */ + +/* ELF TLS ABI calls for big TCB, with static TLS data at negative offsets */ +#define TLS_VARIANT 2 + +/* Read a slot from the TCB */ +static inline void * +__i386_read_tcb(int offset) +{ + void *val; + __asm__ ("movl %%gs:(%1),%0" : "=r" (val) : "r" (offset)); + return val; +} + +/* Get a pointer to the TCB itself */ +#define TCB_GET() __i386_read_tcb(0) + +/* Setting the TCB pointer can only be done via syscall, so no TCB_SET() */ + +#endif /* _KERNEL */ +#endif /* _MACHINE_TCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/trap.h b/lib/libc/include/x86-openbsd-none/machine/trap.h new file mode 100644 index 0000000000..6a91b82f3e --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/trap.h @@ -0,0 +1,65 @@ +/* $OpenBSD: trap.h,v 1.6 2015/06/28 01:11:27 guenther Exp $ */ +/* $NetBSD: trap.h,v 1.4 1994/10/27 04:16:30 cgd 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. + * + * @(#)trap.h 5.4 (Berkeley) 5/9/91 + */ + +/* + * Trap type values + * also known in trap.c for name strings + */ + +#define T_PRIVINFLT 0 /* privileged instruction */ +#define T_BPTFLT 1 /* breakpoint trap */ +#define T_ARITHTRAP 2 /* arithmetic trap */ +#define T_RESERVED 3 /* reserved fault base */ +#define T_PROTFLT 4 /* protection fault */ +#define T_TRCTRAP 5 /* trace trap */ +#define T_PAGEFLT 6 /* page fault */ +#define T_ALIGNFLT 7 /* alignment fault */ +#define T_DIVIDE 8 /* integer divide fault */ +#define T_NMI 9 /* non-maskable interrupt */ +#define T_OFLOW 10 /* overflow trap */ +#define T_BOUND 11 /* bounds check fault */ +#define T_DNA 12 /* device not available fault */ +#define T_DOUBLEFLT 13 /* double fault */ +#define T_FPOPFLT 14 /* fp coprocessor operand fetch fault (![P]Pro)*/ +#define T_TSSFLT 15 /* invalid tss fault */ +#define T_SEGNPFLT 16 /* segment not present fault */ +#define T_STKFLT 17 /* stack fault */ +#define T_MACHK 18 /* machine check ([P]Pro) */ +#define T_XFTRAP 19 /* SIMD FP exception */ + +/* Trap's coming from user mode */ +#define T_USER 0x100 \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/tss.h b/lib/libc/include/x86-openbsd-none/machine/tss.h new file mode 100644 index 0000000000..d2e5f750b6 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/tss.h @@ -0,0 +1,74 @@ +/* $OpenBSD: tss.h,v 1.12 2018/06/22 13:21:14 bluhm Exp $ */ +/* $NetBSD: tss.h,v 1.6 1995/10/11 04:20:28 mycroft 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. + * + * @(#)tss.h 5.4 (Berkeley) 1/18/91 + */ + +#ifndef _MACHINE_TSS_H_ +#define _MACHINE_TSS_H_ + +/* + * Intel 386 Context Data Type + */ + +struct i386tss { + int __tss_link; + int tss_esp0; /* kernel stack pointer at privilege level 0 */ + int tss_ss0; /* kernel stack segment at privilege level 0 */ + int __tss_esp1; + int __tss_ss1; + int __tss_esp2; + int __tss_ss2; + int tss_cr3; + int tss_eip; + int tss_eflags; + int tss_eax; + int tss_ecx; + int tss_edx; + int tss_ebx; + int tss_esp; + int tss_ebp; + int tss_esi; + int tss_edi; + int tss_es; + int tss_cs; + int tss_ss; + int tss_ds; + int tss_fs; + int tss_gs; + int tss_ldt; + int tss_ioopt; /* options and I/O permission map offset */ +}; + +#endif /* _MACHINE_TSS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/vga_post.h b/lib/libc/include/x86-openbsd-none/machine/vga_post.h new file mode 100644 index 0000000000..7207b11c31 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/vga_post.h @@ -0,0 +1,43 @@ +/* $NetBSD: vga_post.h,v 1.2 2008/03/29 17:40:22 jmcneill Exp $ */ +/* $OpenBSD: vga_post.h,v 1.2 2011/03/23 16:54:35 pirofti Exp $ */ + +/*- + * Copyright (c) 2007 Joerg Sonnenberger . + * 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT HOLDERS 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_VGA_POST_H_ +#define _MACHINE_VGA_POST_H_ + +#ifdef _KERNEL +struct vga_post; + +struct vga_post *vga_post_init(int, int, int); +void vga_post_free(struct vga_post *); +void vga_post_call(struct vga_post *); +#endif +#endif \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/vmmvar.h b/lib/libc/include/x86-openbsd-none/machine/vmmvar.h new file mode 100644 index 0000000000..6528cb8102 --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/vmmvar.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2014 Mike Larkin + * + * 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 VMM_HV_SIGNATURE "OpenBSDVMM58" \ No newline at end of file diff --git a/lib/libc/include/x86-openbsd-none/machine/vmparam.h b/lib/libc/include/x86-openbsd-none/machine/vmparam.h new file mode 100644 index 0000000000..3e7cc4f4bb --- /dev/null +++ b/lib/libc/include/x86-openbsd-none/machine/vmparam.h @@ -0,0 +1,108 @@ +/* $OpenBSD: vmparam.h,v 1.57 2021/03/16 18:04:16 kurt Exp $ */ +/* $NetBSD: vmparam.h,v 1.15 1994/10/27 04:16:34 cgd 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. + * + * @(#)vmparam.h 5.9 (Berkeley) 5/12/91 + */ + +#ifndef _MACHINE_VMPARAM_H_ +#define _MACHINE_VMPARAM_H_ +/* + * Machine dependent constants for 386. + */ + +#define USRSTACK VM_MAXUSER_ADDRESS + +/* + * Virtual memory related constants, all in bytes + */ +#define MAXTSIZ (256*1024*1024) /* max text size */ +#ifndef DFLDSIZ +#define DFLDSIZ (64*1024*1024) /* initial data size limit */ +#endif +#ifndef MAXDSIZ +#define MAXDSIZ (3UL*1024*1024*1024) /* max data size */ +#endif +#ifndef BRKSIZ +#define BRKSIZ (128*1024*1024) /* heap gap size */ +#endif +#ifndef DFLSSIZ +#define DFLSSIZ (4*1024*1024) /* initial stack size limit */ +#endif +#ifndef MAXSSIZ +#define MAXSSIZ (32*1024*1024) /* max stack size */ +#endif + +#define STACKGAP_RANDOM 256*1024 + +/* I386 has a line where all code is executable: 0 - I386_MAX_EXE_ADDR */ +#define I386_MAX_EXE_ADDR 0x20000000 /* exec line */ + +/* map PIE into 320MB - 448MB address range */ +#define VM_PIE_MIN_ADDR 0x14000000 +#define VM_PIE_MAX_ADDR 0x1C000000 + +/* + * Size of shared memory map + */ +#ifndef SHMMAXPGS +#define SHMMAXPGS 8192 +#endif + +/* + * Size of User Raw I/O map + */ +#define USRIOSIZE 300 + +/* + * Specific addresses being unmapped and used as fillers for free memory. + */ +#define DEADBEEF0 0xefffeecc /* malloc's filler */ +#define DEADBEEF1 0xefffaabb /* pool's filler */ + +/* user/kernel map constants */ +#define VM_MIN_ADDRESS ((vaddr_t)PAGE_SIZE) +#define VM_MAXUSER_ADDRESS ((vaddr_t)((PDSLOT_PTE<= 3 +typedef __builtin_va_list __va_list; +#else +typedef char * __va_list; +#endif + +/* Wide character support types */ +#ifndef __cplusplus +typedef int __wchar_t; +#endif +typedef int __wint_t; +typedef int __rune_t; +typedef void * __wctrans_t; +typedef void * __wctype_t; + +#endif /* _MACHINE__TYPES_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/apicvar.h b/lib/libc/include/x86_64-openbsd-none/amd64/apicvar.h new file mode 100644 index 0000000000..90c3cd3bc1 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/apicvar.h @@ -0,0 +1,54 @@ +/* $OpenBSD: apicvar.h,v 1.4 2025/09/05 16:57:48 kettenis Exp $ */ +/* $NetBSD: apicvar.h,v 1.1 2003/02/26 21:26:10 fvdl Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by RedBack Networks Inc. + * + * Author: Bill Sommerfeld + * + * 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_APICVAR_H_ +#define _MACHINE_APICVAR_H_ + +#include + +struct apic_attach_args { + const char *aaa_name; + int apic_id; + int apic_version; + int flags; +#define IOAPIC_PICMODE 0x01 +#define IOAPIC_VWIRE 0x02 + bus_space_tag_t apic_memt; + bus_addr_t apic_address; + int apic_vecbase; +}; + +void apic_format_redir(char *, char *, int, u_int32_t, u_int32_t); + +#endif /* !_MACHINE_APICVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/apmvar.h b/lib/libc/include/x86_64-openbsd-none/amd64/apmvar.h new file mode 100644 index 0000000000..7407c1c6cf --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/apmvar.h @@ -0,0 +1,303 @@ +/* XXX - DSR */ +/* $OpenBSD: apmvar.h,v 1.8 2019/01/22 02:36:30 phessler Exp $ */ + +/* + * Copyright (c) 1995 John T. Kohl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef _MACHINE_APMVAR_H_ +#define _MACHINE_APMVAR_H_ + +#include + +/* Advanced Power Management (v1.0 and v1.1 specification) + * functions/defines/etc. + */ + +#define APM_VERSION 0x0102 + +/* + * APM info word from boot loader + */ +#define APM_16BIT_SUPPORTED 0x00010000 +#define APM_32BIT_SUPPORTED 0x00020000 +#define APM_IDLE_SLOWS 0x00040000 +#define APM_BIOS_PM_DISABLED 0x00080000 +#define APM_BIOS_PM_DISENGAGED 0x00100000 +#define APM_MAJOR(f) (((f) >> 8) & 0xff) +#define APM_MINOR(f) ((f) & 0xff) +#define APM_VERMASK 0x0000ffff +#define APM_NOCLI 0x00010000 +#define APM_BEBATT 0x00020000 + +/* APM error codes */ +#define APM_ERR_CODE(regs) (((regs)->ax & 0xff00) >> 8) +#define APM_ERR_PM_DISABLED 0x01 +#define APM_ERR_REALALREADY 0x02 +#define APM_ERR_NOTCONN 0x03 +#define APM_ERR_16ALREADY 0x05 +#define APM_ERR_16NOTSUPP 0x06 +#define APM_ERR_32ALREADY 0x07 +#define APM_ERR_32NOTSUPP 0x08 +#define APM_ERR_UNRECOG_DEV 0x09 +#define APM_ERR_ERANGE 0x0A +#define APM_ERR_NOTENGAGED 0x0B +#define APM_ERR_EOPNOSUPP 0x0C +#define APM_ERR_RTIMER_DISABLED 0x0D +#define APM_ERR_UNABLE 0x60 +#define APM_ERR_NOEVENTS 0x80 +#define APM_ERR_NOT_PRESENT 0x86 + +#define APM_DEV_APM_BIOS 0x0000 +#define APM_DEV_ALLDEVS 0x0001 +/* device classes are high byte; device IDs go in low byte */ +#define APM_DEV_DISPLAY(x) (0x0100|((x)&0xff)) +#define APM_DEV_DISK(x) (0x0200|((x)&0xff)) +#define APM_DEV_PARALLEL(x) (0x0300|((x)&0xff)) +#define APM_DEV_SERIAL(x) (0x0400|((x)&0xff)) +#define APM_DEV_NETWORK(x) (0x0500|((x)&0xff)) +#define APM_DEV_PCMCIA(x) (0x0600|((x)&0xff)) +#define APM_DEV_BATTERIES(x) (0x8000|((x)&0xff)) +#define APM_DEV_ALLUNITS 0xff +/* 0x8100-0xDFFF - reserved */ +/* 0xE000-0xEFFF - OEM-defined */ +/* 0xF000-0xFFFF - reserved */ + +#define APM_INSTCHECK 0x5300 /* int15 only */ +#define APM_16BIT_SUPPORT 0x01 +#define APM_32BIT_SUPPORT 0x02 +#define APM_CPUIDLE_SLOW 0x04 +#define APM_DISABLED 0x08 +#define APM_DISENGAGED 0x10 + +#define APM_REAL_CONNECT 0x5301 /* int15 only */ +#define APM_PROT16_CONNECT 0x5302 /* int15 only */ +#define APM_PROT32_CONNECT 0x5303 /* int15 only */ +#define APM_DISCONNECT 0x5304 /* %bx = APM_DEV_APM_BIOS */ + +#define APM_CPU_IDLE 0x5305 +#define APM_CPU_BUSY 0x5306 + +#define APM_SET_PWR_STATE 0x5307 +#define APM_SYS_READY 0x0000 /* %cx */ +#define APM_SYS_STANDBY 0x0001 +#define APM_SYS_SUSPEND 0x0002 +#define APM_SYS_OFF 0x0003 +#define APM_LASTREQ_INPROG 0x0004 +#define APM_LASTREQ_REJECTED 0x0005 +/* 0x0006 - 0x001f Reserved system states */ +/* 0x0020 - 0x003f OEM-defined system states */ +/* 0x0040 - 0x007f OEM-defined device states */ +/* 0x0080 - 0xffff Reserved device states */ + +/* system standby is device ID (%bx) 0x0001, APM_SYS_STANDBY */ +/* system suspend is device ID (%bx) 0x0001, APM_SYS_SUSPEND */ + +#define APM_PWR_MGT_ENABLE 0x5308 +#define APM_MGT_ALL 0xffff /* %bx */ +#define APM_MGT_DISABLE 0x0 /* %cx */ +#define APM_MGT_ENABLE 0x1 + +#define APM_SYSTEM_DEFAULTS 0x5309 +#define APM_DEFAULTS_ALL 0xffff /* %bx */ + +#define APM_POWER_STATUS 0x530a +#define APM_AC_OFF 0x00 +#define APM_AC_ON 0x01 +#define APM_AC_BACKUP 0x02 +#define APM_AC_UNKNOWN 0xff +#define APM_BATT_HIGH 0x00 +#define APM_BATT_LOW 0x01 +#define APM_BATT_CRITICAL 0x02 +#define APM_BATT_CHARGING 0x03 +#define APM_BATT_UNKNOWN 0xff +#define APM_BATT_FLAG_HIGH 0x01 +#define APM_BATT_FLAG_LOW 0x02 +#define APM_BATT_FLAG_CRITICAL 0x04 +#define APM_BATT_FLAG_CHARGING 0x08 +#define APM_BATT_FLAG_NOBATTERY 0x10 +#define APM_BATT_FLAG_NOSYSBATT 0x80 +#define APM_BATT_LIFE_UNKNOWN 0xff +#define BATT_STATE(regp) ((regp)->bx & 0xff) +#define BATT_FLAGS(regp) (((regp)->cx & 0xff00) >> 8) +#define AC_STATE(regp) (((regp)->bx & 0xff00) >> 8) +#define BATT_LIFE(regp) ((regp)->cx & 0xff) /* in % */ +/* Return time in minutes. According to the APM 1.2 spec: + DX = Remaining battery life -- time units + Bit 15 = 0 Time units are seconds + = 1 Time units are minutes + Bits 14-0 = Number of seconds or minutes */ +#define BATT_REMAINING(regp) (((regp)->dx & 0x8000) ? \ + ((regp)->dx & 0x7fff) : \ + ((regp)->dx & 0x7fff)/60) +#define BATT_REM_VALID(regp) (((regp)->dx & 0xffff) != 0xffff) +#define BATT_COUNT(regp) ((regp)->si) + +#define APM_GET_PM_EVENT 0x530b +#define APM_NOEVENT 0x0000 +#define APM_STANDBY_REQ 0x0001 /* %bx on return */ +#define APM_SUSPEND_REQ 0x0002 +#define APM_NORMAL_RESUME 0x0003 +#define APM_CRIT_RESUME 0x0004 /* suspend/resume happened + without us */ +#define APM_BATTERY_LOW 0x0005 +#define APM_POWER_CHANGE 0x0006 +#define APM_UPDATE_TIME 0x0007 +#define APM_CRIT_SUSPEND_REQ 0x0008 +#define APM_USER_STANDBY_REQ 0x0009 +#define APM_USER_SUSPEND_REQ 0x000A +#define APM_SYS_STANDBY_RESUME 0x000B +#define APM_CAPABILITY_CHANGE 0x000C /* apm v1.2 */ +/* 0x000d - 0x00ff Reserved system events */ +#define APM_USER_HIBERNATE_REQ 0x000D +/* 0x0100 - 0x01ff Reserved device events */ +/* 0x0200 - 0x02ff OEM-defined APM events */ +/* 0x0300 - 0xffff Reserved */ +#define APM_EVENT_MASK 0xffff + +#define APM_EVENT_COMPOSE(t,i) ((((i) & 0x7fff) << 16)|((t) & APM_EVENT_MASK)) +#define APM_EVENT_TYPE(e) ((e) & APM_EVENT_MASK) +#define APM_EVENT_INDEX(e) ((e) >> 16) + +#define APM_GET_POWER_STATE 0x530c +#define APM_DEVICE_MGMT_ENABLE 0x530d + +#define APM_DRIVER_VERSION 0x530e +/* %bx should be DEV value (APM_DEV_APM_BIOS) + %ch = driver major vno + %cl = driver minor vno + return: %ah = conn major; %al = conn minor + */ +#define APM_CONN_MINOR(regp) ((regp)->ax & 0xff) +#define APM_CONN_MAJOR(regp) (((regp)->ax & 0xff00) >> 8) + +#define APM_PWR_MGT_ENGAGE 0x530F +#define APM_MGT_DISENGAGE 0x0 /* %cx */ +#define APM_MGT_ENGAGE 0x1 + +/* %bx - APM_DEV_APM_BIOS + * %bl - number of batteries + * %cx - capabilities + */ +#define APM_GET_CAPABILITIES 0x5310 +#define APM_NBATTERIES(regp) ((regp)->bx) +#define APM_GLOBAL_STANDBY 0x0001 +#define APM_GLOBAL_SUSPEND 0x0002 +#define APM_RTIMER_STANDBY 0x0004 /* resume time wakes up */ +#define APM_RTIMER_SUSPEND 0x0008 +#define APM_IRRING_STANDBY 0x0010 /* internal ring wakes up */ +#define APM_IRRING_SUSPEND 0x0020 +#define APM_PCCARD_STANDBY 0x0040 /* pccard wakes up */ +#define APM_PCCARD_SUSPEND 0x0080 + +/* %bx - APM_DEV_APM_BIOS + * %cl - function + * for %cl=2 (set resume timer) + * %ch - seconds in BCD + * %dh - hours in BCD + * %dl - minutes in BCD + * %si - month in BCD (high), day in BCD (low) + * %di - year in BCD + */ +#define APM_RESUME_TIMER 0x5311 +#define APM_RT_DISABLE 0x0 +#define APM_RT_GET 0x1 +#define APM_RT_SET 0x2 + +/* %bx - APM_DEV_APM_BIOS + * %cx - function + */ +#define APM_RESUME_ON_RING 0x5312 +#define APM_ROR_DISABLE 0x0 +#define APM_ROR_ENABLE 0x1 +#define APM_ROR_STATUS 0x2 + +/* %bx - APM_EDV_APM_BIOS + * %cx - function + */ +#define APM_INACTIVITY_TIMER 0x5313 +#define APM_IT_DISABLE 0x0 +#define APM_IT_ENABLE 0x1 +#define APM_IT_STATUS 0x2 + +/* %bh - function */ +#define APM_OEM 0x5380 +#define APM_OEM_INSTCHECK 0x7f /* %bx - OEM ID */ + +/* + * LP (Laptop Package) + * + * Copyright (C) 1994 by HOSOKAWA Tatsumi + * + * This software may be used, modified, copied, and distributed, in + * both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + */ + +#define APM_BATTERY_ABSENT 4 + +struct apm_power_info { + u_char battery_state; + u_char ac_state; + u_char battery_life; + u_char spare1; + u_int minutes_left; /* estimate */ + u_int spare2[6]; +}; + +struct apm_ctl { + u_int dev; + u_int mode; +}; + +#define APM_IOC_REJECT _IOW('A', 0, struct apm_event_info) /* reject request # */ +#define APM_IOC_STANDBY _IO('A', 1) /* put system into standby */ +#define APM_IOC_SUSPEND _IO('A', 2) /* put system into suspend */ +#define APM_IOC_GETPOWER _IOR('A', 3, struct apm_power_info) /* fetch battery state */ +#define APM_IOC_DEV_CTL _IOW('A', 5, struct apm_ctl) /* put device into mode */ +#define APM_IOC_PRN_CTL _IOW('A', 6, int ) /* driver power status msg */ +#define APM_PRINT_ON 0 /* driver power status displayed */ +#define APM_PRINT_OFF 1 /* driver power status not displayed */ +#define APM_PRINT_PCT 2 /* driver power status only displayed + if the percentage changes */ +#define APM_IOC_STANDBY_REQ _IO('A', 7) /* request standby */ +#define APM_IOC_SUSPEND_REQ _IO('A', 8) /* request suspend */ +#define APM_IOC_HIBERNATE _IO('A', 9) /* put system into hibernate */ + +#ifdef _KERNEL +extern void apm_cpu_busy(void); +extern void apm_cpu_idle(void); +extern void apminit(void); +int apm_set_powstate(u_int devid, u_int powstate); +#endif /* _KERNEL */ + +#endif /* _MACHINE_APMVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/asm.h b/lib/libc/include/x86_64-openbsd-none/amd64/asm.h new file mode 100644 index 0000000000..64acd3a4f0 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/asm.h @@ -0,0 +1,196 @@ +/* $OpenBSD: asm.h,v 1.24 2023/04/17 00:02:14 deraadt Exp $ */ +/* $NetBSD: asm.h,v 1.2 2003/05/02 18:05:47 yamt 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. + * + * @(#)asm.h 5.5 (Berkeley) 5/7/91 + */ + +#ifndef _MACHINE_ASM_H_ +#define _MACHINE_ASM_H_ + +#ifdef __PIC__ +#define PIC_PLT(x) x@PLT +#define PIC_GOT(x) x@GOTPCREL(%rip) +#else +#define PIC_PLT(x) x +#define PIC_GOT(x) x +#endif + +# define _C_LABEL(x) x +#define _ASM_LABEL(x) x + +#define CVAROFF(x,y) (x+y)(%rip) + +#ifdef __STDC__ +# define __CONCAT(x,y) x ## y +# define __STRING(x) #x +#else +# define __CONCAT(x,y) x/**/y +# define __STRING(x) "x" +#endif + +/* let kernels and others override entrypoint alignment */ +#ifndef _ALIGN_TEXT +#define _ALIGN_TEXT .align 16, 0x90 +#endif +#define _ALIGN_TRAPS .align 16, 0xcc + +#define _FENTRY(x) .type x,@function; x: + +/* NB == No Binding: use .globl or .weak as necessary */ +#define NENTRY_NB(x) \ + .text; _ALIGN_TEXT; _FENTRY(x) +#define _ENTRY_NB(x) \ + .text; _ALIGN_TRAPS; _FENTRY(x) +#define _ENTRY(x) .globl x; _ENTRY_NB(x) +#define _NENTRY(x) .globl x; NENTRY_NB(x) + +#ifdef _KERNEL +#define KUTEXT .section .kutext, "ax", @progbits + +#define KUTEXT_PAGE_START .pushsection .kutext.page, "a", @progbits +#define KTEXT_PAGE_START .pushsection .ktext.page, "ax", @progbits +#define KUTEXT_PAGE_END .popsection +#define KTEXT_PAGE_END .popsection + +#define IDTVEC(name) \ + KUTEXT; _ALIGN_TRAPS; IDTVEC_NOALIGN(name); endbr64 +#define GENTRY(x) .globl x; _FENTRY(x) +#define IDTVEC_NOALIGN(name) GENTRY(X ## name) +#define IDTVEC_ALIAS(alias,sym) \ + .global X ## alias; \ + X ## alias = X ## sym; +#define KIDTVEC(name) \ + .text; _ALIGN_TRAPS; IDTVEC_NOALIGN(name); endbr64 +#define KIDTVEC_FALLTHROUGH(name) \ + _ALIGN_TEXT; IDTVEC_NOALIGN(name) +#define KUENTRY(x) \ + KUTEXT; _ALIGN_TRAPS; GENTRY(x) + +/* Return stack refill, to prevent speculation attacks on natural returns */ +#define RET_STACK_REFILL_WITH_RCX \ + mov $8,%rcx ; \ + _ALIGN_TEXT ; \ + 3: call 5f ; \ + 4: pause ; \ + lfence ; \ + call 4b ; \ + _ALIGN_TRAPS ; \ + 5: call 7f ; \ + 6: pause ; \ + lfence ; \ + call 6b ; \ + _ALIGN_TRAPS ; \ + 7: loop 3b ; \ + add $(16*8),%rsp + +#endif /* _KERNEL */ + +#ifdef __STDC__ +#define CPUVAR(off) %gs:CPU_INFO_ ## off +#else +#define CPUVAR(off) %gs:CPU_INFO_/**/off +#endif + + +#if defined(PROF) || defined(GPROF) +# define _PROF_PROLOGUE \ + pushq %rbp; leaq (%rsp),%rbp; call PIC_PLT(__mcount); popq %rbp +#else +# define _PROF_PROLOGUE +#endif + +#if defined(_RET_PROTECTOR) +# define RETGUARD_SETUP_OFF(x, reg, off) \ + RETGUARD_SYMBOL(x); \ + movq (__retguard_ ## x)(%rip), %reg; \ + xorq off(%rsp), %reg +# define RETGUARD_SETUP(x, reg) \ + RETGUARD_SETUP_OFF(x, reg, 0) +# define RETGUARD_CHECK(x, reg) \ + xorq (%rsp), %reg; \ + cmpq (__retguard_ ## x)(%rip), %reg; \ + je 66f; \ + int3; int3; \ + .zero (0xf - ((. + 3 - x) & 0xf)), 0xcc; \ +66: +# define RETGUARD_PUSH(reg) \ + pushq %reg +# define RETGUARD_POP(reg) \ + popq %reg +# define RETGUARD_SYMBOL(x) \ + .ifndef __retguard_ ## x; \ + .hidden __retguard_ ## x; \ + .type __retguard_ ## x,@object; \ + .pushsection .openbsd.randomdata.retguard,"aw",@progbits; \ + .weak __retguard_ ## x; \ + .p2align 3; \ + __retguard_ ## x: ; \ + .quad 0; \ + .size __retguard_ ## x, 8; \ + .popsection; \ + .endif +#else +# define RETGUARD_SETUP_OFF(x, reg, off) +# define RETGUARD_SETUP(x, reg) +# define RETGUARD_CHECK(x, reg) +# define RETGUARD_PUSH(reg) +# define RETGUARD_POP(reg) +# define RETGUARD_SYMBOL(x) +#endif + +#define ENTRY(y) _ENTRY(y); endbr64; _PROF_PROLOGUE +#define NENTRY(y) _NENTRY(y) +#define ASENTRY(y) _NENTRY(y); endbr64; _PROF_PROLOGUE +#define ENTRY_NB(y) _ENTRY_NB(y); endbr64; _PROF_PROLOGUE +#define END(y) .size y, . - y + +#define STRONG_ALIAS(alias,sym) \ + .global alias; \ + alias = sym +#define WEAK_ALIAS(alias,sym) \ + .weak alias; \ + alias = sym + +/* generic retpoline ("return trampoline") generator */ +#define JMP_RETPOLINE(reg) \ + call 69f ; \ + 68: pause ; \ + lfence ; \ + jmp 68b ; \ + _ALIGN_TRAPS ; \ + 69: mov %reg,(%rsp) ; \ + ret ; \ + lfence + +#endif /* !_MACHINE_ASM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/atomic.h b/lib/libc/include/x86_64-openbsd-none/amd64/atomic.h new file mode 100644 index 0000000000..329eccec1c --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/atomic.h @@ -0,0 +1,325 @@ +/* $OpenBSD: atomic.h,v 1.23 2023/11/11 18:47:02 jca Exp $ */ +/* $NetBSD: atomic.h,v 1.1 2003/04/26 18:39:37 fvdl Exp $ */ + +/* + * Copyright 2002 (c) Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Frank van der Linden for Wasabi Systems, Inc. + * + * 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 for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC + * 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_ATOMIC_H_ +#define _MACHINE_ATOMIC_H_ + +/* + * Perform atomic operations on memory. Should be atomic with respect + * to interrupts and multiple processors. + * + * void atomic_setbits_int(volatile u_int *a, u_int mask) { *a |= mask; } + * void atomic_clearbits_int(volatile u_int *a, u_int mask) { *a &= ~mask; } + */ + +#if !defined(_LOCORE) + +#if defined(MULTIPROCESSOR) || !defined(_KERNEL) +#define _LOCK "lock" +#else +#define _LOCK +#endif + +static inline unsigned int +_atomic_cas_uint(volatile unsigned int *p, unsigned int e, unsigned int n) +{ + __asm volatile(_LOCK " cmpxchgl %2, %1" + : "=a" (n), "=m" (*p) + : "r" (n), "a" (e), "m" (*p)); + + return (n); +} +#define atomic_cas_uint(_p, _e, _n) _atomic_cas_uint((_p), (_e), (_n)) + +static inline unsigned long +_atomic_cas_ulong(volatile unsigned long *p, unsigned long e, unsigned long n) +{ + __asm volatile(_LOCK " cmpxchgq %2, %1" + : "=a" (n), "=m" (*p) + : "r" (n), "a" (e), "m" (*p)); + + return (n); +} +#define atomic_cas_ulong(_p, _e, _n) _atomic_cas_ulong((_p), (_e), (_n)) + +static inline void * +_atomic_cas_ptr(volatile void *p, void *e, void *n) +{ + __asm volatile(_LOCK " cmpxchgq %2, %1" + : "=a" (n), "=m" (*(unsigned long *)p) + : "r" (n), "a" (e), "m" (*(unsigned long *)p)); + + return (n); +} +#define atomic_cas_ptr(_p, _e, _n) _atomic_cas_ptr((_p), (_e), (_n)) + +static inline unsigned int +_atomic_swap_uint(volatile unsigned int *p, unsigned int n) +{ + __asm volatile("xchgl %0, %1" + : "=a" (n), "=m" (*p) + : "0" (n), "m" (*p)); + + return (n); +} +#define atomic_swap_uint(_p, _n) _atomic_swap_uint((_p), (_n)) +#define atomic_swap_32(_p, _n) _atomic_swap_uint((_p), (_n)) + +static inline unsigned long +_atomic_swap_ulong(volatile unsigned long *p, unsigned long n) +{ + __asm volatile("xchgq %0, %1" + : "=a" (n), "=m" (*p) + : "0" (n), "m" (*p)); + + return (n); +} +#define atomic_swap_ulong(_p, _n) _atomic_swap_ulong((_p), (_n)) + +static inline uint64_t +_atomic_swap_64(volatile uint64_t *p, uint64_t n) +{ + __asm volatile("xchgq %0, %1" + : "=a" (n), "=m" (*p) + : "0" (n), "m" (*p)); + + return (n); +} +#define atomic_swap_64(_p, _n) _atomic_swap_64((_p), (_n)) + +static inline void * +_atomic_swap_ptr(volatile void *p, void *n) +{ + __asm volatile("xchgq %0, %1" + : "=a" (n), "=m" (*(unsigned long *)p) + : "0" (n), "m" (*(unsigned long *)p)); + + return (n); +} +#define atomic_swap_ptr(_p, _n) _atomic_swap_ptr((_p), (_n)) + +static inline void +_atomic_inc_int(volatile unsigned int *p) +{ + __asm volatile(_LOCK " incl %0" + : "+m" (*p)); +} +#define atomic_inc_int(_p) _atomic_inc_int(_p) + +static inline void +_atomic_inc_long(volatile unsigned long *p) +{ + __asm volatile(_LOCK " incq %0" + : "+m" (*p)); +} +#define atomic_inc_long(_p) _atomic_inc_long(_p) + +static inline void +_atomic_dec_int(volatile unsigned int *p) +{ + __asm volatile(_LOCK " decl %0" + : "+m" (*p)); +} +#define atomic_dec_int(_p) _atomic_dec_int(_p) + +static inline void +_atomic_dec_long(volatile unsigned long *p) +{ + __asm volatile(_LOCK " decq %0" + : "+m" (*p)); +} +#define atomic_dec_long(_p) _atomic_dec_long(_p) + +static inline void +_atomic_add_int(volatile unsigned int *p, unsigned int v) +{ + __asm volatile(_LOCK " addl %1,%0" + : "+m" (*p) + : "a" (v)); +} +#define atomic_add_int(_p, _v) _atomic_add_int(_p, _v) + +static inline void +_atomic_add_long(volatile unsigned long *p, unsigned long v) +{ + __asm volatile(_LOCK " addq %1,%0" + : "+m" (*p) + : "a" (v)); +} +#define atomic_add_long(_p, _v) _atomic_add_long(_p, _v) + +static inline void +_atomic_sub_int(volatile unsigned int *p, unsigned int v) +{ + __asm volatile(_LOCK " subl %1,%0" + : "+m" (*p) + : "a" (v)); +} +#define atomic_sub_int(_p, _v) _atomic_sub_int(_p, _v) + +static inline void +_atomic_sub_long(volatile unsigned long *p, unsigned long v) +{ + __asm volatile(_LOCK " subq %1,%0" + : "+m" (*p) + : "a" (v)); +} +#define atomic_sub_long(_p, _v) _atomic_sub_long(_p, _v) + + +static inline unsigned long +_atomic_add_int_nv(volatile unsigned int *p, unsigned int v) +{ + unsigned int rv = v; + + __asm volatile(_LOCK " xaddl %0,%1" + : "+a" (rv), "+m" (*p)); + + return (rv + v); +} +#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 = v; + + __asm volatile(_LOCK " xaddq %0,%1" + : "+a" (rv), "+m" (*p)); + + return (rv + v); +} +#define atomic_add_long_nv(_p, _v) _atomic_add_long_nv(_p, _v) + +static inline unsigned long +_atomic_sub_int_nv(volatile unsigned int *p, unsigned int v) +{ + unsigned int rv = 0 - v; + + __asm volatile(_LOCK " xaddl %0,%1" + : "+a" (rv), "+m" (*p)); + + return (rv - v); +} +#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 = 0 - v; + + __asm volatile(_LOCK " xaddq %0,%1" + : "+a" (rv), "+m" (*p)); + + return (rv - v); +} +#define atomic_sub_long_nv(_p, _v) _atomic_sub_long_nv(_p, _v) + +/* + * The AMD64 architecture is rather strongly ordered. When accessing + * normal write-back cacheable memory, only reads may be reordered with + * older writes to different locations. There are a few instructions + * (clfush, non-temporal move instructions) that obey weaker ordering + * rules, but those instructions will only be used in (inline) + * assembly code where we can add the necessary fence instructions + * ourselves. + */ + +#define __membar(_f) do { __asm volatile(_f ::: "memory"); } while (0) + +#if defined(MULTIPROCESSOR) || !defined(_KERNEL) +#define membar_enter() __membar("mfence") +#define membar_exit() __membar("") +#define membar_producer() __membar("") +#define membar_consumer() __membar("") +#define membar_sync() __membar("mfence") +#else +#define membar_enter() __membar("") +#define membar_exit() __membar("") +#define membar_producer() __membar("") +#define membar_consumer() __membar("") +#define membar_sync() __membar("") +#endif + +#define membar_enter_after_atomic() __membar("") +#define membar_exit_before_atomic() __membar("") + +#ifdef _KERNEL + +/* virtio needs MP membars even on SP kernels */ +#define virtio_membar_producer() __membar("") +#define virtio_membar_consumer() __membar("") +#define virtio_membar_sync() __membar("mfence") + +static __inline void +x86_atomic_setbits_u32(volatile u_int32_t *ptr, u_int32_t bits) +{ + __asm volatile(_LOCK " orl %1,%0" : "=m" (*ptr) : "ir" (bits)); +} + +static __inline void +x86_atomic_clearbits_u32(volatile u_int32_t *ptr, u_int32_t bits) +{ + __asm volatile(_LOCK " andl %1,%0" : "=m" (*ptr) : "ir" (~bits)); +} + +static __inline void +x86_atomic_setbits_u64(volatile u_int64_t *ptr, u_int64_t bits) +{ + __asm volatile(_LOCK " orq %1,%0" : "=m" (*ptr) : "er" (bits)); +} + +static __inline void +x86_atomic_clearbits_u64(volatile u_int64_t *ptr, u_int64_t bits) +{ + __asm volatile(_LOCK " andq %1,%0" : "=m" (*ptr) : "er" (~bits)); +} + +#define x86_atomic_testset_ul x86_atomic_testset_u64 +#define x86_atomic_setbits_ul x86_atomic_setbits_u64 +#define x86_atomic_clearbits_ul x86_atomic_clearbits_u64 + +#define atomic_setbits_int x86_atomic_setbits_u32 +#define atomic_clearbits_int x86_atomic_clearbits_u32 + +#endif /* _KERNEL */ + +#undef _LOCK + +#endif /* !defined(_LOCORE) */ +#endif /* _MACHINE_ATOMIC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/biosvar.h b/lib/libc/include/x86_64-openbsd-none/amd64/biosvar.h new file mode 100644 index 0000000000..523bb6255b --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/biosvar.h @@ -0,0 +1,283 @@ +/* $OpenBSD: biosvar.h,v 1.32 2023/09/08 20:47:22 kn Exp $ */ + +/* + * Copyright (c) 1997-1999 Michael Shalayeff + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MACHINE_BIOSVAR_H_ +#define _MACHINE_BIOSVAR_H_ + + /* some boxes put apm data seg in the 2nd page */ +#define BOOTARG_OFF (PAGE_SIZE * 2) +#define BOOTARG_LEN (PAGE_SIZE * 1) +#define BOOTBIOS_ADDR (0x7c00) +#define BOOTBIOS_MAXSEC ((1 << 28) - 1) + + /* BIOS configure flags */ +#define BIOSF_BIOS32 0x0001 +#define BIOSF_PCIBIOS 0x0002 +#define BIOSF_PROMSCAN 0x0004 +#define BIOSF_SMBIOS 0x0008 + +/* BIOS media ID */ +#define BIOSM_F320K 0xff /* floppy ds/sd 8 spt */ +#define BIOSM_F160K 0xfe /* floppy ss/sd 8 spt */ +#define BIOSM_F360K 0xfd /* floppy ds/sd 9 spt */ +#define BIOSM_F180K 0xfc /* floppy ss/sd 9 spt */ +#define BIOSM_ROMD 0xfa /* ROM disk */ +#define BIOSM_F120M 0xf9 /* floppy ds/hd 15 spt 5.25" */ +#define BIOSM_F720K 0xf9 /* floppy ds/dd 9 spt 3.50" */ +#define BIOSM_HD 0xf8 /* hard drive */ +#define BIOSM_F144K 0xf0 /* floppy ds/hd 18 spt 3.50" */ +#define BIOSM_OTHER 0xf0 /* any other */ + +/* + * BIOS memory maps + */ +#define BIOS_MAP_END 0x00 /* End of array XXX - special */ +#define BIOS_MAP_FREE 0x01 /* Usable memory */ +#define BIOS_MAP_RES 0x02 /* Reserved memory */ +#define BIOS_MAP_ACPI 0x03 /* ACPI Reclaim memory */ +#define BIOS_MAP_NVS 0x04 /* ACPI NVS memory */ + +/* + * Optional ROM header + */ +typedef +struct bios_romheader { + uint16_t signature; /* 0xaa55 */ + uint8_t len; /* length in pages (512 bytes) */ + uint32_t entry; /* initialization entry point */ + uint8_t reserved[19]; + uint16_t pnpheader; /* offset to PnP expansion header */ +} __packed *bios_romheader_t; + +#define BIOS32_MAKESIG(a, b, c, d) \ + ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24)) +#define SMBIOS_SIGNATURE BIOS32_MAKESIG('_', 'S', 'M', '_') + +/* + * CTL_BIOS definitions. + */ +#define BIOS_DEV 1 /* int: BIOS boot device */ +#define BIOS_DISKINFO 2 /* struct: BIOS boot device info */ +#define BIOS_CKSUMLEN 3 /* int: disk cksum block count */ +#define BIOS_MAXID 4 /* number of valid machdep ids */ + +#define CTL_BIOS_NAMES { \ + { 0, 0 }, \ + { "biosdev", CTLTYPE_INT }, \ + { "diskinfo", CTLTYPE_STRUCT }, \ + { "cksumlen", CTLTYPE_INT }, \ +} + +#define BOOTARG_MEMMAP 0 +typedef struct _bios_memmap { + uint64_t addr; /* Beginning of block */ + uint64_t size; /* Size of block */ + uint32_t type; /* Type of block */ +} __packed bios_memmap_t; + +/* Info about disk from the bios, plus the mapping from + * BIOS numbers to BSD major (driver?) number. + * + * Also, do not bother with BIOSN*() macros, just parcel + * the info out, and use it like this. This makes for less + * of a dependence on BIOSN*() macros having to be the same + * across /boot, /bsd, and userland. + */ +#define BOOTARG_DISKINFO 1 +typedef struct _bios_diskinfo { + /* BIOS section */ + int bios_number; /* BIOS number of drive (or -1) */ + u_int bios_cylinders; /* BIOS cylinders */ + u_int bios_heads; /* BIOS heads */ + u_int bios_sectors; /* BIOS sectors */ + int bios_edd; /* EDD support */ + + /* BSD section */ + dev_t bsd_dev; /* BSD device */ + + /* Checksum section */ + uint32_t checksum; /* Checksum for drive */ + + /* Misc. flags */ + uint32_t flags; +#define BDI_INVALID 0x00000001 /* I/O error during checksumming */ +#define BDI_GOODLABEL 0x00000002 /* Had SCSI or ST506/ESDI disklabel */ +#define BDI_BADLABEL 0x00000004 /* Had another disklabel */ +#define BDI_EL_TORITO 0x00000008 /* 2,048-byte sectors */ +#define BDI_HIBVALID 0x00000010 /* hibernate signature valid */ +#define BDI_PICKED 0x80000000 /* kernel-only: cksum matched */ + +} __packed bios_diskinfo_t; + +#define BOOTARG_APMINFO 2 +typedef struct _bios_apminfo { + /* APM_CONNECT returned values */ + u_int apm_detail; + u_int apm_code32_base; + u_int apm_code16_base; + u_int apm_code_len; + u_int apm_data_base; + u_int apm_data_len; + u_int apm_entry; + u_int apm_code16_len; +} __packed bios_apminfo_t; + +#define BOOTARG_CKSUMLEN 3 /* uint32_t */ + +#define BOOTARG_PCIINFO 4 +typedef struct _bios_pciinfo { + /* PCI BIOS v2.0+ - Installation check values */ + uint32_t pci_chars; /* Characteristics (%eax) */ + uint32_t pci_rev; /* BCD Revision (%ebx) */ + uint32_t pci_entry32; /* PM entry point for PCI BIOS */ + uint32_t pci_lastbus; /* Number of last PCI bus */ +} __packed bios_pciinfo_t; + +#define BOOTARG_CONSDEV 5 +typedef struct _bios_consdev { + dev_t consdev; + int conspeed; + uint64_t consaddr; + int consfreq; + uint32_t flags; +#define BCD_MMIO 0x00000001 /* Memory Mapped IO */ + int reg_width; + int reg_shift; +} __packed bios_consdev_t; + +#define BOOTARG_BOOTMAC 7 +typedef struct _bios_bootmac { + char mac[6]; +} __packed bios_bootmac_t; + +#define BOOTARG_DDB 8 +typedef struct _bios_ddb { + int db_console; +} __packed bios_ddb_t; + +#define BOOTARG_BOOTDUID 9 +typedef struct _bios_bootduid { + u_char duid[8]; +} __packed bios_bootduid_t; + +#define BOOTARG_BOOTSR 10 +#define BOOTSR_UUID_MAX 16 +#define BOOTSR_CRYPTO_MAXKEYBYTES 32 +typedef struct _bios_bootsr { + uint8_t uuid[BOOTSR_UUID_MAX]; + uint8_t maskkey[BOOTSR_CRYPTO_MAXKEYBYTES]; +} __packed bios_bootsr_t; + +#define BOOTARG_EFIINFO 11 +typedef struct _bios_efiinfo { + uint64_t config_acpi; + uint64_t config_smbios; + uint64_t fb_addr; + uint64_t fb_size; + uint32_t fb_height; + uint32_t fb_width; + uint32_t fb_pixpsl; /* pixels per scan line */ + uint32_t fb_red_mask; + uint32_t fb_green_mask; + uint32_t fb_blue_mask; + uint32_t fb_reserved_mask; + uint32_t flags; +#define BEI_64BIT 0x00000001 /* 64-bit EFI implementation */ +#define BEI_ESRT 0x00000002 /* ESRT table */ + uint32_t mmap_desc_ver; + uint32_t mmap_desc_size; + uint32_t mmap_size; + uint64_t mmap_start; + uint64_t system_table; + uint64_t config_esrt; +} __packed bios_efiinfo_t; + +#define BOOTARG_UCODE 12 +typedef struct _bios_ucode { + uint64_t uc_addr; + uint64_t uc_size; +} __packed bios_ucode_t; + +#if defined(_KERNEL) || defined (_STANDALONE) + +#ifdef _LOCORE +#define DOINT(n) int $0x20+(n) +#else +#define DOINT(n) "int $0x20+(" #n ")" + +extern volatile struct BIOS_regs { + uint32_t biosr_ax; + uint32_t biosr_cx; + uint32_t biosr_dx; + uint32_t biosr_bx; + uint32_t biosr_bp; + uint32_t biosr_si; + uint32_t biosr_di; + uint32_t biosr_ds; + uint32_t biosr_es; +} __packed BIOS_regs; + +#ifdef _KERNEL +#include + +struct bios_attach_args { + char *ba_name; + u_int ba_func; + bus_space_tag_t ba_iot; + bus_space_tag_t ba_memt; + union { + void *_p; + bios_apminfo_t *_ba_apmp; + paddr_t _ba_acpipbase; + } _; +}; + +#define ba_apmp _._ba_apmp +#define ba_acpipbase _._ba_acpipbase + +struct consdev; +struct proc; + +int bios_sysctl(int *, u_int, void *, size_t *, void *, size_t, struct proc *); + +void bios_getopt(void); +bios_diskinfo_t *bios_getdiskinfo(dev_t); + +extern int biosbasemem; +extern u_int bootapiver; +extern bios_memmap_t *bios_memmap; +extern bios_efiinfo_t *bios_efiinfo; +extern bios_ucode_t *bios_ucode; + +#endif /* _KERNEL */ +#endif /* _LOCORE */ +#endif /* _KERNEL || _STANDALONE */ + +#endif /* _MACHINE_BIOSVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/bus.h b/lib/libc/include/x86_64-openbsd-none/amd64/bus.h new file mode 100644 index 0000000000..140e3a73f3 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/bus.h @@ -0,0 +1,706 @@ +/* $OpenBSD: bus.h,v 1.37 2025/08/23 10:15:49 sf Exp $ */ +/* $NetBSD: bus.h,v 1.6 1996/11/10 03:19:25 thorpej Exp $ */ + +/*- + * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 1996 Charles M. Hannum. All rights reserved. + * Copyright (c) 1996 Jason R. Thorpe. All rights reserved. + * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christopher G. Demetriou + * for the NetBSD Project. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MACHINE_BUS_H_ +#define _MACHINE_BUS_H_ + +#include +#include + +#include + +/* + * Bus address and size types + */ +typedef u_long bus_addr_t; +typedef u_long bus_size_t; + +/* + * Access methods for bus resources and address space. + */ +struct x86_bus_space_ops; +typedef const struct x86_bus_space_ops *bus_space_tag_t; +typedef u_long bus_space_handle_t; + +int bus_space_map(bus_space_tag_t t, bus_addr_t addr, + bus_size_t size, int flags, bus_space_handle_t *bshp); +/* like map, but without extent map checking/allocation */ +int _bus_space_map(bus_space_tag_t t, bus_addr_t addr, + bus_size_t size, int flags, bus_space_handle_t *bshp); + +int bus_space_alloc(bus_space_tag_t t, bus_addr_t rstart, + bus_addr_t rend, bus_size_t size, bus_size_t align, + bus_size_t boundary, int flags, bus_addr_t *addrp, + bus_space_handle_t *bshp); +void bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh, + bus_size_t size); + +/* + * int bus_space_unmap(bus_space_tag_t t, + * bus_space_handle_t bsh, bus_size_t size); + * + * Unmap a region of bus space. + */ + +void bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh, + bus_size_t size); +void _bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh, + bus_size_t size, bus_addr_t *); + +/* like bus_space_map(), but without extent map checking/allocation */ +int _bus_space_map(bus_space_tag_t t, bus_addr_t addr, + bus_size_t size, int flags, bus_space_handle_t *bshp); + +/* + * int bus_space_subregion(bus_space_tag_t t, + * bus_space_handle_t bsh, bus_size_t offset, bus_size_t size, + * bus_space_handle_t *nbshp); + * + * Get a new handle for a subregion of an already-mapped area of bus space. + */ + +int bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh, + bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp); + +struct x86_bus_space_ops { + +/* + * u_intN_t bus_space_read_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset); + * + * Read a 1, 2, 4, or 8 byte quantity from bus space + * described by tag/handle/offset. + */ + u_int8_t (*read_1)(bus_space_handle_t, bus_size_t); + u_int16_t (*read_2)(bus_space_handle_t, bus_size_t); + u_int32_t (*read_4)(bus_space_handle_t, bus_size_t); + u_int64_t (*read_8)(bus_space_handle_t, bus_size_t); + +#define bus_space_read_1(_t, _h, _o) ((_t)->read_1((_h), (_o))) +#define bus_space_read_2(_t, _h, _o) ((_t)->read_2((_h), (_o))) +#define bus_space_read_4(_t, _h, _o) ((_t)->read_4((_h), (_o))) +#define bus_space_read_8(_t, _h, _o) ((_t)->read_8((_h), (_o))) + +#define bus_space_read_raw_2(_t, _h, _o) ((_t)->read_2((_h), (_o))) +#define bus_space_read_raw_4(_t, _h, _o) ((_t)->read_4((_h), (_o))) +#define bus_space_read_raw_8(_t, _h, _o) ((_t)->read_8((_h), (_o))) + +/* + * void bus_space_read_multi_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_intN_t *addr, size_t count); + * + * Read `count' 1, 2, 4, or 8 byte quantities from bus space + * described by tag/handle/offset and copy into buffer provided. + */ + + void (*read_multi_1)(bus_space_handle_t, bus_size_t, + u_int8_t *, bus_size_t); + void (*read_multi_2)(bus_space_handle_t, bus_size_t, + u_int16_t *, bus_size_t); + void (*read_multi_4)(bus_space_handle_t, bus_size_t, + u_int32_t *, bus_size_t); + void (*read_multi_8)(bus_space_handle_t, bus_size_t, + u_int64_t *, bus_size_t); + +#define bus_space_read_multi_1(_t, _h, _o, _a, _c) \ + ((_t)->read_multi_1((_h), (_o), (_a), (_c))) +#define bus_space_read_multi_2(_t, _h, _o, _a, _c) \ + ((_t)->read_multi_2((_h), (_o), (_a), (_c))) +#define bus_space_read_multi_4(_t, _h, _o, _a, _c) \ + ((_t)->read_multi_4((_h), (_o), (_a), (_c))) +#define bus_space_read_multi_8(_t, _h, _o, _a, _c) \ + ((_t)->read_multi_8((_h), (_o), (_a), (_c))) + +/* + * void bus_space_read_raw_multi_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_int8_t *addr, size_t count); + * + * Read `count' bytes in 2, 4 or 8 byte wide quantities from bus space + * described by tag/handle/offset and copy into buffer provided. The buffer + * must have proper alignment for the N byte wide entities. Furthermore + * possible byte-swapping should be done by these functions. + */ + +#define bus_space_read_raw_multi_2(_t, _h, _o, _a, _c) \ + ((_t)->read_multi_2((_h), (_o), (u_int16_t *)(_a), (_c) >> 1)) +#define bus_space_read_raw_multi_4(_t, _h, _o, _a, _c) \ + ((_t)->read_multi_4((_h), (_o), (u_int32_t *)(_a), (_c) >> 2)) +#define bus_space_read_raw_multi_8(_t, _h, _o, _a, _c) \ + ((_t)->read_multi_8((_h), (_o), (u_int64_t *)(_a), (_c) >> 3)) + +/* + * void bus_space_read_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_intN_t *addr, size_t count); + * + * Read `count' 1, 2, 4, or 8 byte quantities from bus space + * described by tag/handle and starting at `offset' and copy into + * buffer provided. + */ + + void (*read_region_1)(bus_space_handle_t, + bus_size_t, u_int8_t *, bus_size_t); + void (*read_region_2)(bus_space_handle_t, + bus_size_t, u_int16_t *, bus_size_t); + void (*read_region_4)(bus_space_handle_t, + bus_size_t, u_int32_t *, bus_size_t); + void (*read_region_8)(bus_space_handle_t, + bus_size_t, u_int64_t *, bus_size_t); + +#define bus_space_read_region_1(_t, _h, _o, _a, _c) \ + ((_t)->read_region_1((_h), (_o), (_a), (_c))) +#define bus_space_read_region_2(_t, _h, _o, _a, _c) \ + ((_t)->read_region_2((_h), (_o), (_a), (_c))) +#define bus_space_read_region_4(_t, _h, _o, _a, _c) \ + ((_t)->read_region_4((_h), (_o), (_a), (_c))) +#define bus_space_read_region_8(_t, _h, _o, _a, _c) \ + ((_t)->read_region_8((_h), (_o), (_a), (_c))) + +/* + * void bus_space_read_raw_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_int8_t *addr, size_t count); + * + * Read `count' bytes in 2, 4 or 8 byte wide quantities from bus space + * described by tag/handle and starting at `offset' and copy into + * buffer provided. The buffer must have proper alignment for the N byte + * wide entities. Furthermore possible byte-swapping should be done by + * these functions. + */ + +#define bus_space_read_raw_region_2(_t, _h, _o, _a, _c) \ + ((_t)->read_region_2((_h), (_o), (u_int16_t *)(_a), (_c) >> 1)) +#define bus_space_read_raw_region_4(_t, _h, _o, _a, _c) \ + ((_t)->read_region_4((_h), (_o), (u_int32_t *)(_a), (_c) >> 2)) +#define bus_space_read_raw_region_8(_t, _h, _o, _a, _c) \ + ((_t)->read_region_8((_h), (_o), (u_int64_t *)(_a), (_c) >> 3)) + +/* + * void bus_space_write_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_intN_t value); + * + * Write the 1, 2, 4, or 8 byte value `value' to bus space + * described by tag/handle/offset. + */ + + void (*write_1)(bus_space_handle_t, bus_size_t, u_int8_t); + void (*write_2)(bus_space_handle_t, bus_size_t, u_int16_t); + void (*write_4)(bus_space_handle_t, bus_size_t, u_int32_t); + void (*write_8)(bus_space_handle_t, bus_size_t, u_int64_t); + +#define bus_space_write_1(_t, _h, _o, _v) \ + ((_t)->write_1((_h), (_o), (_v))) +#define bus_space_write_2(_t, _h, _o, _v) \ + ((_t)->write_2((_h), (_o), (_v))) +#define bus_space_write_4(_t, _h, _o, _v) \ + ((_t)->write_4((_h), (_o), (_v))) +#define bus_space_write_8(_t, _h, _o, _v) \ + ((_t)->write_8((_h), (_o), (_v))) + +#define bus_space_write_raw_2(_t, _h, _o, _v) \ + ((_t)->write_2((_h), (_o), (_v))) +#define bus_space_write_raw_4(_t, _h, _o, _v) \ + ((_t)->write_4((_h), (_o), (_v))) +#define bus_space_write_raw_8(_t, _h, _o, _v) \ + ((_t)->write_8((_h), (_o), (_v))) + +/* + * void bus_space_write_multi_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * const u_intN_t *addr, size_t count); + * + * Write `count' 1, 2, 4, or 8 byte quantities from the buffer + * provided to bus space described by tag/handle/offset. + */ + + void (*write_multi_1)(bus_space_handle_t, + bus_size_t, const u_int8_t *, bus_size_t); + void (*write_multi_2)(bus_space_handle_t, + bus_size_t, const u_int16_t *, bus_size_t); + void (*write_multi_4)(bus_space_handle_t, + bus_size_t, const u_int32_t *, bus_size_t); + void (*write_multi_8)(bus_space_handle_t, + bus_size_t, const u_int64_t *, bus_size_t); + +#define bus_space_write_multi_1(_t, _h, _o, _a, _c) \ + ((_t)->write_multi_1((_h), (_o), (_a), (_c))) +#define bus_space_write_multi_2(_t, _h, _o, _a, _c) \ + ((_t)->write_multi_2((_h), (_o), (_a), (_c))) +#define bus_space_write_multi_4(_t, _h, _o, _a, _c) \ + ((_t)->write_multi_4((_h), (_o), (_a), (_c))) +#define bus_space_write_multi_8(_t, _h, _o, _a, _c) \ + ((_t)->write_multi_8((_h), (_o), (_a), (_c))) + +/* + * void bus_space_write_raw_multi_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * const u_int8_t *addr, size_t count); + * + * Write `count' bytes in 2, 4 or 8 byte wide quantities from the buffer + * provided to bus space described by tag/handle/offset. The buffer + * must have proper alignment for the N byte wide entities. Furthermore + * possible byte-swapping should be done by these functions. + */ + +#define bus_space_write_raw_multi_2(_t, _h, _o, _a, _c) \ + ((_t)->write_multi_2((_h), (_o), (const u_int16_t *)(_a), (_c) >> 1)) +#define bus_space_write_raw_multi_4(_t, _h, _o, _a, _c) \ + ((_t)->write_multi_4((_h), (_o), (const u_int32_t *)(_a), (_c) >> 2)) +#define bus_space_write_raw_multi_8(_t, _h, _o, _a, _c) \ + ((_t)->write_multi_8((_h), (_o), (const u_int64_t *)(_a), (_c) >> 3)) + +/* + * void bus_space_write_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * const u_intN_t *addr, size_t count); + * + * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided + * to bus space described by tag/handle starting at `offset'. + */ + + void (*write_region_1)(bus_space_handle_t, + bus_size_t, const u_int8_t *, bus_size_t); + void (*write_region_2)(bus_space_handle_t, + bus_size_t, const u_int16_t *, bus_size_t); + void (*write_region_4)(bus_space_handle_t, + bus_size_t, const u_int32_t *, bus_size_t); + void (*write_region_8)(bus_space_handle_t, + bus_size_t, const u_int64_t *, bus_size_t); + +#define bus_space_write_region_1(_t, _h, _o, _a, _c) \ + ((_t)->write_region_1((_h), (_o), (_a), (_c))) +#define bus_space_write_region_2(_t, _h, _o, _a, _c) \ + ((_t)->write_region_2((_h), (_o), (_a), (_c))) +#define bus_space_write_region_4(_t, _h, _o, _a, _c) \ + ((_t)->write_region_4((_h), (_o), (_a), (_c))) +#define bus_space_write_region_8(_t, _h, _o, _a, _c) \ + ((_t)->write_region_8((_h), (_o), (_a), (_c))) + +/* + * void bus_space_write_raw_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * const u_int8_t *addr, size_t count); + * + * Write `count' bytes in 2, 4 or 8 byte wide quantities to bus space + * described by tag/handle and starting at `offset' from the + * buffer provided. The buffer must have proper alignment for the N byte + * wide entities. Furthermore possible byte-swapping should be done by + * these functions. + */ + +#define bus_space_write_raw_region_2(_t, _h, _o, _a, _c) \ + ((_t)->write_region_2((_h), (_o), (const u_int16_t *)(_a), (_c) >> 1)) +#define bus_space_write_raw_region_4(_t, _h, _o, _a, _c) \ + ((_t)->write_region_4((_h), (_o), (const u_int32_t *)(_a), (_c) >> 2)) +#define bus_space_write_raw_region_8(_t, _h, _o, _a, _c) \ + ((_t)->write_region_8((_h), (_o), (const u_int64_t *)(_a), (_c) >> 3)) + +/* + * void bus_space_set_multi_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_intN_t val, size_t count); + * + * Write the 1, 2, 4, or 8 byte value `val' to bus space described + * by tag/handle/offset `count' times. + */ + + void (*set_multi_1)(bus_space_handle_t, + bus_size_t, u_int8_t, size_t); + void (*set_multi_2)(bus_space_handle_t, + bus_size_t, u_int16_t, size_t); + void (*set_multi_4)(bus_space_handle_t, + bus_size_t, u_int32_t, size_t); + void (*set_multi_8)(bus_space_handle_t, + bus_size_t, u_int64_t, size_t); + +#define bus_space_set_multi_1(_t, _h, _o, _a, _c) \ + ((_t)->set_multi_1((_h), (_o), (_a), (_c))) +#define bus_space_set_multi_2(_t, _h, _o, _a, _c) \ + ((_t)->set_multi_2((_h), (_o), (_a), (_c))) +#define bus_space_set_multi_4(_t, _h, _o, _a, _c) \ + ((_t)->set_multi_4((_h), (_o), (_a), (_c))) +#define bus_space_set_multi_8(_t, _h, _o, _a, _c) \ + ((_t)->set_multi_8((_h), (_o), (_a), (_c))) + +/* + * void bus_space_set_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_intN_t val, size_t count); + * + * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described + * by tag/handle starting at `offset'. + */ + + void (*set_region_1)(bus_space_handle_t, + bus_size_t, u_int8_t, size_t); + void (*set_region_2)(bus_space_handle_t, + bus_size_t, u_int16_t, size_t); + void (*set_region_4)(bus_space_handle_t, + bus_size_t, u_int32_t, size_t); + void (*set_region_8)(bus_space_handle_t, + bus_size_t, u_int64_t, size_t); + +#define bus_space_set_region_1(_t, _h, _o, _a, _c) \ + ((_t)->set_region_1((_h), (_o), (_a), (_c))) +#define bus_space_set_region_2(_t, _h, _o, _a, _c) \ + ((_t)->set_region_2((_h), (_o), (_a), (_c))) +#define bus_space_set_region_4(_t, _h, _o, _a, _c) \ + ((_t)->set_region_4((_h), (_o), (_a), (_c))) +#define bus_space_set_region_8(_t, _h, _o, _a, _c) \ + ((_t)->set_region_8((_h), (_o), (_a), (_c))) + +/* + * void bus_space_copy_N(bus_space_tag_t tag, + * bus_space_handle_t bsh1, bus_size_t off1, + * bus_space_handle_t bsh2, bus_size_t off2, + * size_t count); + * + * Copy `count' 1, 2, 4, or 8 byte values from bus space starting + * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2. + */ + + void (*copy_1)(bus_space_handle_t, + bus_size_t, bus_space_handle_t, bus_size_t, size_t); + void (*copy_2)(bus_space_handle_t, + bus_size_t, bus_space_handle_t, bus_size_t, size_t); + void (*copy_4)(bus_space_handle_t, + bus_size_t, bus_space_handle_t, bus_size_t, size_t); + void (*copy_8)(bus_space_handle_t, + bus_size_t, bus_space_handle_t, bus_size_t, size_t); + +#define bus_space_copy_1(_t, _h1, _o1, _h2, _o2, _c) \ + ((_t)->copy_1((_h1), (_o1), (_h2), (_o2), (_c))) +#define bus_space_copy_2(_t, _h1, _o1, _h2, _o2, _c) \ + ((_t)->copy_2((_h1), (_o1), (_h2), (_o2), (_c))) +#define bus_space_copy_4(_t, _h1, _o1, _h2, _o2, _c) \ + ((_t)->copy_4((_h1), (_o1), (_h2), (_o2), (_c))) +#define bus_space_copy_8(_t, _h1, _o1, _h2, _o2, _c) \ + ((_t)->copy_8((_h1), (_o1), (_h2), (_o2), (_c))) + +/* + * void *bus_space_vaddr(bus_space_tag_t, bus_space_handle_t); + * + * Get the kernel virtual address for the mapped bus space. + * Only allowed for regions mapped with BUS_SPACE_MAP_LINEAR. + */ + void * (*vaddr)(bus_space_handle_t); + +#define bus_space_vaddr(_t, _h) \ + ((_t)->vaddr((_h))) + +/* + * paddr_t bus_space_mmap(bus_space_tag_t t, bus_addr_t base, + * off_t offset, int prot, int flags); + * + * Mmap an area of bus space. + */ + + paddr_t (*mmap)(bus_addr_t, off_t, int, int); + +#define bus_space_mmap(_t, _a, _o, _p, _f) \ + ((_t)->mmap((_a), (_o), (_p), (_f))) +}; + +/* + * Bus read/write barrier methods. + */ +#define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */ +#define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */ + +static inline void +bus_space_barrier(bus_space_tag_t space, bus_space_handle_t + handle, bus_size_t offset, bus_size_t length, int flags) +{ + switch (flags) { + case (BUS_SPACE_BARRIER_READ|BUS_SPACE_BARRIER_WRITE): + __asm volatile("mfence" ::: "memory"); + break; + case BUS_SPACE_BARRIER_WRITE: + __asm volatile("sfence" ::: "memory"); + break; + default: + __asm volatile("lfence" ::: "memory"); + break; + } +} + +#define BUS_SPACE_MAP_CACHEABLE 0x0001 +#define BUS_SPACE_MAP_LINEAR 0x0002 +#define BUS_SPACE_MAP_PREFETCHABLE 0x0008 + +/* + * Values for the x86 bus space tag, not to be used directly by MI code. + */ + +/* space is i/o space */ +extern const struct x86_bus_space_ops *x86_bus_space_io_ops; +#define X86_BUS_SPACE_IO (x86_bus_space_io_ops) + +/* space is mem space */ +extern const struct x86_bus_space_ops *x86_bus_space_mem_ops; +#define X86_BUS_SPACE_MEM (x86_bus_space_mem_ops) + +/* + * bus_dma + */ + +/* + * Flags used in various bus DMA methods. + */ +#define BUS_DMA_WAITOK 0x0000 /* safe to sleep (pseudo-flag) */ +#define BUS_DMA_NOWAIT 0x0001 /* not safe to sleep */ +#define BUS_DMA_ALLOCNOW 0x0002 /* perform resource allocation now */ +#define BUS_DMA_COHERENT 0x0004 /* hint: map memory DMA coherent */ +#define BUS_DMA_BUS1 0x0010 /* placeholders for bus functions... */ +#define BUS_DMA_BUS2 0x0020 +#define BUS_DMA_32BIT 0x0040 +#define BUS_DMA_24BIT 0x0080 /* isadma map */ +#define BUS_DMA_STREAMING 0x0100 /* hint: sequential, unidirectional */ +#define BUS_DMA_READ 0x0200 /* mapping is device -> memory only */ +#define BUS_DMA_WRITE 0x0400 /* mapping is memory -> device only */ +#define BUS_DMA_NOCACHE 0x0800 /* map memory uncached */ +#define BUS_DMA_ZERO 0x1000 /* zero memory in dmamem_alloc */ +#define BUS_DMA_64BIT 0x2000 /* device handles 64bit dva */ + +/* Forwards needed by prototypes below. */ +struct mbuf; +struct proc; +struct uio; + +/* + * Operations performed by bus_dmamap_sync(). + */ +#define BUS_DMASYNC_PREREAD 0x01 +#define BUS_DMASYNC_POSTREAD 0x02 +#define BUS_DMASYNC_PREWRITE 0x04 +#define BUS_DMASYNC_POSTWRITE 0x08 + +typedef struct bus_dma_tag *bus_dma_tag_t; +typedef struct bus_dmamap *bus_dmamap_t; + +/* + * bus_dma_segment_t + * + * Describes a single contiguous DMA transaction. Values + * are suitable for programming into DMA registers. + */ +struct bus_dma_segment { + bus_addr_t ds_addr; /* DMA address */ + bus_size_t ds_len; /* length of transfer */ + vaddr_t _ds_va; /* mapped loaded data */ + vaddr_t _ds_bounce_va; /* mapped bounced data */ + + /* + * Ugh. need this so can pass alignment down from bus_dmamem_alloc + * to scatter gather maps. only the first one is used so the rest is + * wasted space. bus_dma could do with fixing the api for this. + */ + bus_size_t _ds_boundary; /* don't cross */ + bus_size_t _ds_align; /* align to me */ +}; +typedef struct bus_dma_segment bus_dma_segment_t; + +/* + * bus_dma_tag_t + * + * A machine-dependent opaque type describing the implementation of + * DMA for a given bus. + */ + +struct bus_dma_tag { + void *_cookie; /* cookie used in the guts */ + + /* + * DMA mapping methods. + */ + int (*_dmamap_create)(bus_dma_tag_t, bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); + void (*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t); + int (*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int); + int (*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t, + struct mbuf *, int); + int (*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t, + struct uio *, int); + int (*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); + void (*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t); + void (*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t, + bus_addr_t, bus_size_t, int); + + /* + * DMA memory utility functions. + */ + int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); + int (*_dmamem_alloc_range)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int, + bus_addr_t, bus_addr_t); + void (*_dmamem_free)(bus_dma_tag_t, + bus_dma_segment_t *, int); + int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); + void (*_dmamem_unmap)(bus_dma_tag_t, caddr_t, size_t); + paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *, + int, off_t, int, int); +}; + +#define bus_dmamap_create(t, s, n, m, b, f, p) \ + (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p)) +#define bus_dmamap_destroy(t, p) \ + (*(t)->_dmamap_destroy)((t), (p)) +#define bus_dmamap_load(t, m, b, s, p, f) \ + (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f)) +#define bus_dmamap_load_mbuf(t, m, b, f) \ + (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f)) +#define bus_dmamap_load_uio(t, m, u, f) \ + (*(t)->_dmamap_load_uio)((t), (m), (u), (f)) +#define bus_dmamap_load_raw(t, m, sg, n, s, f) \ + (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f)) +#define bus_dmamap_unload(t, p) \ + (*(t)->_dmamap_unload)((t), (p)) +#define bus_dmamap_sync(t, p, o, l, ops) \ + (*(t)->_dmamap_sync)((t), (p), (o), (l), (ops)) + +#define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \ + (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f)) +#define bus_dmamem_alloc_range(t, s, a, b, sg, n, r, f, l, h) \ + (*(t)->_dmamem_alloc_range)((t), (s), (a), (b), (sg), \ + (n), (r), (f), (l), (h)) +#define bus_dmamem_free(t, sg, n) \ + (*(t)->_dmamem_free)((t), (sg), (n)) +#define bus_dmamem_map(t, sg, n, s, k, f) \ + (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f)) +#define bus_dmamem_unmap(t, k, s) \ + (*(t)->_dmamem_unmap)((t), (k), (s)) +#define bus_dmamem_mmap(t, sg, n, o, p, f) \ + (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f)) + +/* + * bus_dmamap_t + * + * Describes a DMA mapping. + */ +struct bus_dmamap { + /* + * PRIVATE MEMBERS: not for use by machine-independent code. + */ + bus_size_t _dm_size; /* largest DMA transfer mappable */ + int _dm_flags; /* misc. flags */ + int _dm_segcnt; /* number of segs this map can map */ + bus_size_t _dm_maxsegsz; /* largest possible segment */ + bus_size_t _dm_boundary; /* don't cross this */ + + void *_dm_cookie; /* cookie for bus-specific functions */ + + struct vm_page **_dm_pages; /* replacement pages */ + vaddr_t _dm_pgva; /* those above -- mapped */ + int _dm_npages; /* number of pages allocated */ + int _dm_nused; /* number of pages replaced */ + + /* + * PUBLIC MEMBERS: these are used by machine-independent code. + */ + bus_size_t dm_mapsize; /* size of the mapping */ + int dm_nsegs; /* # valid segments in mapping */ + bus_dma_segment_t dm_segs[1]; /* segments; variable length */ +}; + +int _bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t, + bus_size_t, int, bus_dmamap_t *); +void _bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t); +int _bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int); +int _bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, + struct mbuf *, int); +int _bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, + struct uio *, int); +int _bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); +void _bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t); +void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, + bus_size_t, int); + +int _bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size, + bus_size_t alignment, bus_size_t boundary, + bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags); +void _bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs, + int nsegs); +int _bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs, + int nsegs, size_t size, caddr_t *kvap, int flags); +void _bus_dmamem_unmap(bus_dma_tag_t tag, caddr_t kva, + size_t size); +paddr_t _bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs, + int nsegs, off_t off, int prot, int flags); + +int _bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size, + bus_size_t alignment, bus_size_t boundary, + bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags, + bus_addr_t low, bus_addr_t high); + +#endif /* _MACHINE_BUS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/cdefs.h b/lib/libc/include/x86_64-openbsd-none/amd64/cdefs.h new file mode 100644 index 0000000000..cd6f968643 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/cdefs.h @@ -0,0 +1,21 @@ +/* $OpenBSD: cdefs.h,v 1.3 2013/03/28 17:30:45 martynas Exp $ */ + +/* + * Written by J.T. Conklin 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_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/codepatch.h b/lib/libc/include/x86_64-openbsd-none/amd64/codepatch.h new file mode 100644 index 0000000000..04ea726a26 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/codepatch.h @@ -0,0 +1,120 @@ +/* $OpenBSD: codepatch.h,v 1.19 2024/02/12 01:18:17 guenther Exp $ */ +/* + * Copyright (c) 2014-2015 Stefan Fritsch + * + * 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_CODEPATCH_H_ +#define _MACHINE_CODEPATCH_H_ + +#include + +#ifndef _LOCORE + +/* code in this section will be unmapped after boot */ +#define __cptext __attribute__((section(".cptext"))) + +__cptext void *codepatch_maprw(vaddr_t *nva, vaddr_t dest); +__cptext void codepatch_unmaprw(vaddr_t nva); +__cptext void codepatch_fill_nop(void *caddr, uint16_t len); +__cptext void codepatch_nop(uint16_t tag); +__cptext void codepatch_replace(uint16_t tag, const void *code, size_t len); +__cptext void codepatch_call(uint16_t _tag, void *_func); +__cptext void codepatch_jmp(uint16_t _tag, void *_func); +void codepatch_disable(void); + +#endif /* !_LOCORE */ + +/* + * Mark the start of some code snippet to be patched. + */ +#define CODEPATCH_START 998: +/* + * Mark the end of some code to be patched, and assign the given tag. + */ +#define CODEPATCH_END2(startnum,tag) \ + 999: \ + .section .codepatch, "a" ;\ + .quad startnum##b ;\ + .short (999b - startnum##b) ;\ + .short tag ;\ + .int 0 ;\ + .previous +#define CODEPATCH_END(tag) CODEPATCH_END2(998,tag) + +#define CPTAG_STAC 1 +#define CPTAG_CLAC 2 +#define CPTAG_EOI 3 +#define CPTAG_XRSTOR 4 +#define CPTAG_XSAVE 5 +#define CPTAG_MELTDOWN_NOP 6 +#define CPTAG_MELTDOWN_ALLTRAPS 7 +#define CPTAG_PCID_SET_REUSE 8 +#define CPTAG_MDS 9 +#define CPTAG_MDS_VMM 10 +#define CPTAG_FENCE_SWAPGS_MIS_TAKEN 11 +#define CPTAG_FENCE_NO_SAFE_SMAP 12 +#define CPTAG_XRSTORS 13 +#define CPTAG_RETPOLINE_RAX 14 +#define CPTAG_RETPOLINE_R11 15 +#define CPTAG_RETPOLINE_R13 16 +#define CPTAG_IBPB_NOP 17 + +/* + * stac/clac SMAP instructions have lfence like semantics. Let's + * guarantee those semantics on older cpus. + */ +#define SMAP_NOP lfence +#define SMAP_STAC CODEPATCH_START ;\ + SMAP_NOP ;\ + CODEPATCH_END(CPTAG_STAC) +#define SMAP_CLAC CODEPATCH_START ;\ + SMAP_NOP ;\ + CODEPATCH_END(CPTAG_CLAC) + +/* CVE-2019-1125: block speculation after swapgs */ +#define FENCE_SWAPGS_MIS_TAKEN \ + CODEPATCH_START ; \ + lfence ; \ + CODEPATCH_END(CPTAG_FENCE_SWAPGS_MIS_TAKEN) +/* block speculation when a correct SMAP impl would have been enough */ +#define FENCE_NO_SAFE_SMAP \ + CODEPATCH_START ; \ + lfence ; \ + CODEPATCH_END(CPTAG_FENCE_NO_SAFE_SMAP) + +#define PCID_SET_REUSE_SIZE 12 +#define PCID_SET_REUSE_NOP \ + 997: ;\ + .byte 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 ;\ + .byte 0x0f, 0x1f, 0x40, 0x00 ;\ + CODEPATCH_END2(997, CPTAG_PCID_SET_REUSE) + +/* Would be neat if these could be in something like .cptext */ +#define CODEPATCH_CODE(symbol, instructions...) \ + .section .rodata; \ + .globl symbol; \ +symbol: instructions; \ + .size symbol, . - symbol + +/* provide a (short) variable with the length of the patch */ +#define CODEPATCH_CODE_LEN(symbol, instructions...) \ + CODEPATCH_CODE(symbol, instructions); \ +996: .globl symbol##_len; \ + .align 2; \ +symbol##_len: \ + .short 996b - symbol; \ + .size symbol##_len, 2 + +#endif /* _MACHINE_CODEPATCH_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/conf.h b/lib/libc/include/x86_64-openbsd-none/amd64/conf.h new file mode 100644 index 0000000000..bd23d33ba7 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/conf.h @@ -0,0 +1,59 @@ +/* $OpenBSD: conf.h,v 1.11 2024/09/04 07:45:08 jsg Exp $ */ +/* $NetBSD: conf.h,v 1.2 1996/05/05 19:28:34 christos Exp $ */ + +/* + * Copyright (c) 1996 Christos Zoulas. 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 Christos Zoulas. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#define mmread mmrw +#define mmwrite mmrw +cdev_decl(mm); + +bdev_decl(fd); +cdev_decl(fd); + +cdev_decl(spkr); + +cdev_decl(bios); + +#define cdev_acpi_init(c,n) {\ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,n,kqfilter) } +cdev_decl(acpi); + +cdev_decl(pctr); + +#include "vmm.h" +cdev_decl(vmm); + +#include "psp.h" +cdev_decl(psp); \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/cpu.h b/lib/libc/include/x86_64-openbsd-none/amd64/cpu.h new file mode 100644 index 0000000000..d3cab29e55 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/cpu.h @@ -0,0 +1,530 @@ +/* $OpenBSD: cpu.h,v 1.180 2025/04/28 16:18:25 bluhm Exp $ */ +/* $NetBSD: cpu.h,v 1.1 2003/04/26 18:39:39 fvdl 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. + * + * @(#)cpu.h 5.4 (Berkeley) 5/9/91 + */ + +#ifndef _MACHINE_CPU_H_ +#define _MACHINE_CPU_H_ + +/* + * Definitions unique to x86-64 cpu support. + */ +#ifdef _KERNEL +#include +#include /* USERMODE */ +#include +#endif /* _KERNEL */ + +#include +#include +#include +#include +#include +#include +#include + +#ifdef _KERNEL + +/* VMXON region (Intel) */ +struct vmxon_region { + uint32_t vr_revision; +}; + +/* + * VMX for Intel CPUs + */ +struct vmx { + uint64_t vmx_cr0_fixed0; + uint64_t vmx_cr0_fixed1; + uint64_t vmx_cr4_fixed0; + uint64_t vmx_cr4_fixed1; + uint32_t vmx_vmxon_revision; + uint32_t vmx_msr_table_size; + uint32_t vmx_cr3_tgt_count; + uint8_t vmx_has_l1_flush_msr; + uint64_t vmx_invept_mode; +}; + +/* + * SVM for AMD CPUs + */ +struct svm { + uint32_t svm_max_asid; + uint8_t svm_flush_by_asid; + uint8_t svm_vmcb_clean; + uint8_t svm_decode_assist; +}; + +union vmm_cpu_cap { + struct vmx vcc_vmx; + struct svm vcc_svm; +}; + +enum cpu_vendor { + CPUV_UNKNOWN, + CPUV_AMD, + CPUV_INTEL, + CPUV_VIA, +}; + +/* + * Locks used to protect struct members in this file: + * I immutable after creation + * a atomic operations + * o owned (read/modified only) by this CPU + */ +struct x86_64_tss; +struct vcpu; +struct cpu_info { + /* + * The beginning of this structure in mapped in the userspace "u-k" + * page tables, so that these first couple members can be accessed + * from the trampoline code. The ci_PAGEALIGN member defines where + * the part that is *not* visible begins, so don't put anything + * above it that must be kept hidden from userspace! + */ + u_int64_t ci_kern_cr3; /* [o] U+K page table */ + u_int64_t ci_scratch; /* [o] for U<-->K transition */ + +#define ci_PAGEALIGN ci_dev + struct device *ci_dev; /* [I] */ + struct cpu_info *ci_self; /* [I] */ + struct cpu_info *ci_next; /* [I] */ + + u_int ci_cpuid; /* [I] */ + u_int ci_apicid; /* [I] */ + u_int ci_acpi_proc_id; /* [I] */ + u_int32_t ci_randseed; /* [o] */ + + u_int64_t ci_kern_rsp; /* [o] kernel-only stack */ + u_int64_t ci_intr_rsp; /* [o] U<-->K trampoline stack */ + u_int64_t ci_user_cr3; /* [o] U-K page table */ + + /* bits for mitigating Micro-architectural Data Sampling */ + char ci_mds_tmp[64]; /* [o] 64-byte aligned */ + void *ci_mds_buf; /* [I] */ + + struct proc *ci_curproc; /* [o] */ + struct schedstate_percpu ci_schedstate; /* scheduler state */ + + struct pmap *ci_proc_pmap; /* active, non-kernel pmap */ + struct pmap *ci_user_pmap; /* [o] last pmap used in userspace */ + struct pcb *ci_curpcb; /* [o] */ + struct pcb *ci_idle_pcb; /* [o] */ + + u_int ci_pflags; /* [o] */ +#define CPUPF_USERSEGS 0x01 /* CPU has curproc's segs and FS.base */ +#define CPUPF_USERXSTATE 0x02 /* CPU has curproc's xsave state */ + + struct intrsource *ci_isources[MAX_INTR_SOURCES]; + u_int64_t ci_ipending; + int ci_ilevel; + int ci_idepth; + int ci_handled_intr_level; + u_int64_t ci_imask[NIPL]; + u_int64_t ci_iunmask[NIPL]; +#ifdef DIAGNOSTIC + int ci_mutex_level; +#endif + + volatile u_int ci_flags; /* [a] */ + u_int32_t ci_ipis; /* [a] */ + + enum cpu_vendor ci_vendor; /* [I] mapped from cpuid(0) */ + u_int32_t ci_cpuid_level; /* [I] cpuid(0).eax */ + u_int32_t ci_feature_flags; /* [I] */ + u_int32_t ci_feature_eflags; /* [I] */ + u_int32_t ci_feature_sefflags_ebx;/* [I] */ + u_int32_t ci_feature_sefflags_ecx;/* [I] */ + u_int32_t ci_feature_sefflags_edx;/* [I] */ + u_int32_t ci_feature_amdspec_ebx; /* [I] */ + u_int32_t ci_feature_amdsev_eax; /* [I] */ + u_int32_t ci_feature_amdsev_ebx; /* [I] */ + u_int32_t ci_feature_amdsev_ecx; /* [I] */ + u_int32_t ci_feature_amdsev_edx; /* [I] */ + u_int32_t ci_feature_tpmflags; /* [I] */ + u_int32_t ci_pnfeatset; /* [I] */ + u_int32_t ci_efeature_eax; /* [I] */ + u_int32_t ci_efeature_ecx; /* [I] */ + u_int32_t ci_brand[12]; /* [I] */ + u_int32_t ci_signature; /* [I] */ + u_int32_t ci_family; /* [I] */ + u_int32_t ci_model; /* [I] */ + u_int32_t ci_cflushsz; /* [I] */ + + int ci_inatomic; /* [o] */ + +#define __HAVE_CPU_TOPOLOGY + u_int32_t ci_smt_id; /* [I] */ + u_int32_t ci_core_id; /* [I] */ + u_int32_t ci_pkg_id; /* [I] */ + + struct cpu_functions *ci_func; /* [I] */ + void (*cpu_setup)(struct cpu_info *); /* [I] */ + + struct device *ci_acpicpudev; /* [I] */ + volatile u_int ci_mwait; /* [a] */ +#define MWAIT_IN_IDLE 0x1 /* don't need IPI to wake */ +#define MWAIT_KEEP_IDLING 0x2 /* cleared by other cpus to wake me */ +#define MWAIT_ONLY 0x4 /* set if all idle states use mwait */ +#define MWAIT_IDLING (MWAIT_IN_IDLE | MWAIT_KEEP_IDLING) + + int ci_want_resched; + + struct x86_64_tss *ci_tss; /* [o] */ + void *ci_gdt; /* [o] */ + + volatile int ci_ddb_paused; +#define CI_DDB_RUNNING 0 +#define CI_DDB_SHOULDSTOP 1 +#define CI_DDB_STOPPED 2 +#define CI_DDB_ENTERDDB 3 +#define CI_DDB_INDDB 4 + +#ifdef MULTIPROCESSOR + struct srp_hazard ci_srp_hazards[SRP_HAZARD_NUM]; +#define __HAVE_UVM_PERCPU + struct uvm_pmr_cache ci_uvm; /* [o] page cache */ +#endif + + struct ksensordev ci_sensordev; + struct ksensor ci_sensor; + struct ksensor ci_hz_sensor; + u_int64_t ci_hz_mperf; + u_int64_t ci_hz_aperf; +#if defined(GPROF) || defined(DDBPROF) + struct gmonparam *ci_gmon; + struct clockintr ci_gmonclock; +#endif + u_int32_t ci_vmm_flags; +#define CI_VMM_VMX (1 << 0) +#define CI_VMM_SVM (1 << 1) +#define CI_VMM_RVI (1 << 2) +#define CI_VMM_EPT (1 << 3) +#define CI_VMM_DIS (1 << 4) + union vmm_cpu_cap ci_vmm_cap; + paddr_t ci_vmxon_region_pa; + struct vmxon_region *ci_vmxon_region; + paddr_t ci_vmcs_pa; + struct rwlock ci_vmcs_lock; + struct pmap *ci_ept_pmap; /* [o] last used EPT pmap */ + struct vcpu *ci_guest_vcpu; /* [o] last vcpu resumed */ + + char ci_panicbuf[512]; + + struct clockqueue ci_queue; +}; + +#define CPUF_BSP 0x0001 /* CPU is the original BSP */ +#define CPUF_AP 0x0002 /* CPU is an AP */ +#define CPUF_SP 0x0004 /* CPU is only processor */ +#define CPUF_PRIMARY 0x0008 /* CPU is active primary processor */ + +#define CPUF_IDENTIFY 0x0010 /* CPU may now identify */ +#define CPUF_IDENTIFIED 0x0020 /* CPU has been identified */ + +#define CPUF_CONST_TSC 0x0040 /* CPU has constant TSC */ +#define CPUF_INVAR_TSC 0x0100 /* CPU has invariant TSC */ + +#define CPUF_PRESENT 0x1000 /* CPU is present */ +#define CPUF_RUNNING 0x2000 /* CPU is running */ +#define CPUF_PAUSE 0x4000 /* CPU is paused in DDB */ +#define CPUF_GO 0x8000 /* CPU should start running */ +#define CPUF_PARK 0x10000 /* CPU should self-park in real mode */ +#define CPUF_VMM 0x20000 /* CPU is executing in VMM mode */ + +#define PROC_PC(p) ((p)->p_md.md_regs->tf_rip) +#define PROC_STACK(p) ((p)->p_md.md_regs->tf_rsp) + +struct cpu_info_full; +extern struct cpu_info_full cpu_info_full_primary; +#define cpu_info_primary (*(struct cpu_info *)((char *)&cpu_info_full_primary + 4096*2 - offsetof(struct cpu_info, ci_PAGEALIGN))) + +extern struct cpu_info *cpu_info_list; + +#define CPU_INFO_ITERATOR int +#define CPU_INFO_FOREACH(cii, ci) for (cii = 0, ci = cpu_info_list; \ + ci != NULL; ci = ci->ci_next) + +#define CPU_INFO_UNIT(ci) ((ci)->ci_dev ? (ci)->ci_dev->dv_unit : 0) + +/* + * Preempt the current process if in interrupt from user mode, + * or after the current trap/syscall if in system mode. + */ +extern void need_resched(struct cpu_info *); +#define clear_resched(ci) (ci)->ci_want_resched = 0 + +#if defined(MULTIPROCESSOR) + +#define MAXCPUS 64 /* bitmask */ + +#define CPU_STARTUP(_ci) ((_ci)->ci_func->start(_ci)) +#define CPU_STOP(_ci) ((_ci)->ci_func->stop(_ci)) +#define CPU_START_CLEANUP(_ci) ((_ci)->ci_func->cleanup(_ci)) + +#define curcpu() ({struct cpu_info *__ci; \ + asm volatile("movq %%gs:%P1,%0" : "=r" (__ci) \ + :"n" (offsetof(struct cpu_info, ci_self))); \ + __ci;}) +#define cpu_number() (curcpu()->ci_cpuid) + +#define CPU_IS_PRIMARY(ci) ((ci)->ci_flags & CPUF_PRIMARY) +#define CPU_IS_RUNNING(ci) ((ci)->ci_flags & CPUF_RUNNING) + +extern struct cpu_info *cpu_info[MAXCPUS]; + +void cpu_boot_secondary_processors(void); + +void cpu_kick(struct cpu_info *); +void cpu_unidle(struct cpu_info *); + +#define CPU_BUSY_CYCLE() __asm volatile("pause": : : "memory") + +#else /* !MULTIPROCESSOR */ + +#define MAXCPUS 1 + +#ifdef _KERNEL +#define curcpu() (&cpu_info_primary) + +#define cpu_kick(ci) +#define cpu_unidle(ci) + +#define CPU_BUSY_CYCLE() __asm volatile ("" ::: "memory") + +#endif + +/* + * definitions of cpu-dependent requirements + * referenced in generic code + */ +#define cpu_number() 0 +#define CPU_IS_PRIMARY(ci) 1 +#define CPU_IS_RUNNING(ci) 1 + +#endif /* MULTIPROCESSOR */ + +#include +#include + +static inline unsigned int +cpu_rnd_messybits(void) +{ + unsigned int hi, lo; + + __asm volatile("rdtsc" : "=d" (hi), "=a" (lo)); + + return (hi ^ lo); +} + +#endif /* _KERNEL */ + +#ifdef MULTIPROCESSOR +#include +#endif + +#define aston(p) ((p)->p_md.md_astpending = 1) + +#define curpcb curcpu()->ci_curpcb + +/* + * Arguments to hardclock, softclock and statclock + * encapsulate the previous machine state in an opaque + * clockframe; for now, use generic intrframe. + */ +#define clockframe intrframe + +#define CLKF_USERMODE(frame) USERMODE((frame)->if_cs, (frame)->if_rflags) +#define CLKF_PC(frame) ((frame)->if_rip) +#define CLKF_INTR(frame) (curcpu()->ci_idepth > 1) + +/* + * Give a profiling tick to the current process when the user profiling + * buffer pages are invalid. On the i386, request an ast to send us + * through usertrap(), marking the proc as needing a profiling tick. + */ +#define need_proftick(p) aston(p) + +void signotify(struct proc *); + +/* + * We need a machine-independent name for this. + */ +extern void (*delay_func)(int); +void delay_fini(void (*)(int)); +void delay_init(void (*)(int), int); +struct timeval; + +#define DELAY(x) (*delay_func)(x) +#define delay(x) (*delay_func)(x) + + +#ifdef _KERNEL +/* cpu.c */ +extern int cpu_feature; +extern int cpu_ebxfeature; +extern int cpu_ecxfeature; +extern int ecpu_ecxfeature; +extern int cpu_sev_guestmode; +extern int cpu_id; +extern char cpu_vendor[]; +extern int cpuid_level; +extern int cpu_meltdown; +extern u_int cpu_mwait_size; +extern u_int cpu_mwait_states; + +int cpu_suspend_primary(void); + +/* cacheinfo.c */ +void x86_print_cacheinfo(struct cpu_info *); + +/* identcpu.c */ +void identifycpu(struct cpu_info *); +int cpu_amd64speed(int *); +extern int cpuspeed; +extern int amd64_pos_cbit; +extern int amd64_min_noes_asid; + +/* machdep.c */ +void dumpconf(void); +void cpu_set_vendor(struct cpu_info *, int _level, const char *_vendor); +void cpu_reset(void); +void x86_64_proc0_tss_ldt_init(void); +int amd64_pa_used(paddr_t); +#define cpu_idle_enter() do { /* nothing */ } while (0) +extern void (*cpu_idle_cycle_fcn)(void); +extern void (*cpu_suspend_cycle_fcn)(void); +#define cpu_idle_cycle() (*cpu_idle_cycle_fcn)() +#define cpu_idle_leave() do { /* nothing */ } while (0) +extern void (*initclock_func)(void); +extern void (*startclock_func)(void); + +struct region_descriptor; +void lgdt(struct region_descriptor *); + +struct pcb; +void savectx(struct pcb *); +void proc_trampoline(void); + +/* clock.c */ +void startclocks(void); +void rtcinit(void); +void rtcstart(void); +void rtcstop(void); +void i8254_delay(int); +void i8254_initclocks(void); +void i8254_startclock(void); +void i8254_start_both_clocks(void); +void i8254_inittimecounter(void); +void i8254_inittimecounter_simple(void); + +/* i8259.c */ +void i8259_default_setup(void); + +void cpu_init_msrs(struct cpu_info *); +void cpu_fix_msrs(struct cpu_info *); +void cpu_tsx_disable(struct cpu_info *); + +/* dkcsum.c */ +void dkcsumattach(void); + +/* bus_machdep.c */ +void x86_bus_space_init(void); +void x86_bus_space_mallocok(void); + +/* powernow-k8.c */ +void k8_powernow_init(struct cpu_info *); +void k8_powernow_setperf(int); + +/* k1x-pstate.c */ +void k1x_init(struct cpu_info *); +void k1x_setperf(int); + +void est_init(struct cpu_info *); +void est_setperf(int); + +#ifdef MULTIPROCESSOR +/* mp_setperf.c */ +void mp_setperf_init(void); +#endif + +#endif /* _KERNEL */ + +/* + * CTL_MACHDEP definitions. + */ +#define CPU_CONSDEV 1 /* dev_t: console terminal device */ +#define CPU_BIOS 2 /* BIOS variables */ +#define CPU_BLK2CHR 3 /* convert blk maj into chr one */ +#define CPU_CHR2BLK 4 /* convert chr maj into blk one */ +#define CPU_ALLOWAPERTURE 5 /* allow mmap of /dev/xf86 */ +#define CPU_CPUVENDOR 6 /* cpuid vendor string */ +#define CPU_CPUID 7 /* cpuid */ +#define CPU_CPUFEATURE 8 /* cpuid features */ +#define CPU_KBDRESET 10 /* keyboard reset under pcvt */ +#define CPU_XCRYPT 12 /* supports VIA xcrypt in userland */ +#define CPU_LIDACTION 14 /* action caused by lid close */ +#define CPU_FORCEUKBD 15 /* Force ukbd(4) as console keyboard */ +#define CPU_TSCFREQ 16 /* TSC frequency */ +#define CPU_INVARIANTTSC 17 /* has invariant TSC */ +#define CPU_PWRACTION 18 /* action caused by power button */ +#define CPU_RETPOLINE 19 /* cpu requires retpoline pattern */ +#define CPU_MAXID 20 /* number of valid machdep ids */ + +#define CTL_MACHDEP_NAMES { \ + { 0, 0 }, \ + { "console_device", CTLTYPE_STRUCT }, \ + { "bios", CTLTYPE_INT }, \ + { "blk2chr", CTLTYPE_STRUCT }, \ + { "chr2blk", CTLTYPE_STRUCT }, \ + { "allowaperture", CTLTYPE_INT }, \ + { "cpuvendor", CTLTYPE_STRING }, \ + { "cpuid", CTLTYPE_INT }, \ + { "cpufeature", CTLTYPE_INT }, \ + { 0, 0 }, \ + { "kbdreset", CTLTYPE_INT }, \ + { 0, 0 }, \ + { "xcrypt", CTLTYPE_INT }, \ + { 0, 0 }, \ + { "lidaction", CTLTYPE_INT }, \ + { "forceukbd", CTLTYPE_INT }, \ + { "tscfreq", CTLTYPE_QUAD }, \ + { "invarianttsc", CTLTYPE_INT }, \ + { "pwraction", CTLTYPE_INT }, \ + { "retpoline", CTLTYPE_INT }, \ +} + +#endif /* !_MACHINE_CPU_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/cpu_full.h b/lib/libc/include/x86_64-openbsd-none/amd64/cpu_full.h new file mode 100644 index 0000000000..0d6485cd0e --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/cpu_full.h @@ -0,0 +1,70 @@ +/* $OpenBSD: cpu_full.h,v 1.5 2019/05/17 19:07:47 guenther Exp $ */ +/* + * Copyright (c) 2018 Philip Guenther + * + * 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_CPU_FULL_H_ +#define _MACHINE_CPU_FULL_H_ + +#include /* offsetof, PAGE_SIZE */ +#include +#include + +/* + * The layout of the full per-CPU information, including TSS, GDT, + * trampoline stacks, and cpu_info described in + */ +struct cpu_info_full { + /* page mapped kRO in u-k */ + union { + struct { + struct x86_64_tss uu_tss; + uint64_t uu_gdt[GDT_SIZE / 8]; + } u_tssgdt; + char u_align[PAGE_SIZE]; + } cif_RO; +#define cif_tss cif_RO.u_tssgdt.uu_tss +#define cif_gdt cif_RO.u_tssgdt.uu_gdt + + /* start of page mapped kRW in u-k */ + uint64_t cif_tramp_stack[(PAGE_SIZE / 4 + - offsetof(struct cpu_info, ci_PAGEALIGN)) / sizeof(uint64_t)]; + uint64_t cif_dblflt_stack[(PAGE_SIZE / 4) / sizeof(uint64_t)]; + uint64_t cif_nmi_stack[(2 * PAGE_SIZE / 4) / sizeof(uint64_t)]; + + /* + * Beginning of this hangs over into the kRW page; rest is + * unmapped in u-k + */ + struct cpu_info cif_cpu; +} __aligned(PAGE_SIZE); + +/* tss, align shim, and gdt must fit in a page */ +CTASSERT(_ALIGN(sizeof(struct x86_64_tss)) + + sizeof(struct mem_segment_descriptor) * (NGDT_MEM + 2*NGDT_SYS) + < PAGE_SIZE); + +/* verify expected alignment */ +CTASSERT(offsetof(struct cpu_info_full, cif_cpu.ci_PAGEALIGN) % PAGE_SIZE == 0); + +/* verify total size is multiple of page size */ +CTASSERT(sizeof(struct cpu_info_full) % PAGE_SIZE == 0); + +extern struct cpu_info_full cpu_info_full_primary; + +/* Now make sure the cpu_info_primary macro is correct */ +CTASSERT(&cpu_info_primary - &cpu_info_full_primary.cif_cpu == 0); + +#endif /* _MACHINE_CPU_FULL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/cpufunc.h b/lib/libc/include/x86_64-openbsd-none/amd64/cpufunc.h new file mode 100644 index 0000000000..6a8420e179 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/cpufunc.h @@ -0,0 +1,461 @@ +/* $OpenBSD: cpufunc.h,v 1.45 2025/06/27 17:23:49 bluhm Exp $ */ +/* $NetBSD: cpufunc.h,v 1.3 2003/05/08 10:27:43 fvdl Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Charles M. Hannum. + * + * 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_CPUFUNC_H_ +#define _MACHINE_CPUFUNC_H_ + +/* + * Functions to provide access to i386-specific instructions. + */ + +#include + +#include + +#if defined(_KERNEL) && !defined (_STANDALONE) + +static __inline void +invlpg(u_int64_t addr) +{ + __asm volatile("invlpg (%0)" : : "r" (addr) : "memory"); +} + +static __inline void +sidt(void *p) +{ + __asm volatile("sidt (%0)" : : "r" (p) : "memory"); +} + +static __inline void +lidt(void *p) +{ + __asm volatile("lidt (%0)" : : "r" (p) : "memory"); +} + +static __inline void +sgdt(void *p) +{ + __asm volatile("sgdt (%0)" : : "r" (p) : "memory"); +} + +static __inline void +bare_lgdt(struct region_descriptor *p) +{ + __asm volatile("lgdt (%0)" : : "r" (p) : "memory"); +} + +static __inline void +sldt(u_short *sel) +{ + __asm volatile("sldt (%0)" : : "r" (sel) : "memory"); +} + +static __inline void +lldt(u_short sel) +{ + __asm volatile("lldt %0" : : "r" (sel)); +} + +static __inline void +ltr(u_short sel) +{ + __asm volatile("ltr %0" : : "r" (sel)); +} + +static __inline void +lcr8(u_int val) +{ + u_int64_t val64 = val; + __asm volatile("movq %0,%%cr8" : : "r" (val64)); +} + +/* + * Upper 32 bits are reserved anyway, so just keep this 32bits. + */ +static __inline void +lcr0(u_int val) +{ + u_int64_t val64 = val; + __asm volatile("movq %0,%%cr0" : : "r" (val64)); +} + +static __inline u_int +rcr0(void) +{ + u_int64_t val64; + u_int val; + __asm volatile("movq %%cr0,%0" : "=r" (val64)); + val = val64; + return val; +} + +static __inline u_int64_t +rcr2(void) +{ + u_int64_t val; + __asm volatile("movq %%cr2,%0" : "=r" (val)); + return val; +} + +static __inline void +lcr3(u_int64_t val) +{ + __asm volatile("movq %0,%%cr3" : : "r" (val)); +} + +static __inline u_int64_t +rcr3(void) +{ + u_int64_t val; + __asm volatile("movq %%cr3,%0" : "=r" (val)); + return val; +} + +/* + * Same as for cr0. Don't touch upper 32 bits. + */ +static __inline void +lcr4(u_int val) +{ + u_int64_t val64 = val; + + __asm volatile("movq %0,%%cr4" : : "r" (val64)); +} + +static __inline u_int +rcr4(void) +{ + u_int64_t val64; + __asm volatile("movq %%cr4,%0" : "=r" (val64)); + return (u_int) val64; +} + +/* + * DR6 and DR7 debug registers + */ +static inline uint64_t +rdr6(void) +{ + u_int64_t val; + __asm volatile("movq %%dr6,%0" : "=r" (val)); + return val; +} + +static inline uint64_t +rdr7(void) +{ + u_int64_t val; + __asm volatile("movq %%dr7,%0" : "=r" (val)); + return val; +} + +static __inline void +tlbflush(void) +{ + u_int64_t val; + __asm volatile("movq %%cr3,%0" : "=r" (val)); + __asm volatile("movq %0,%%cr3" : : "r" (val)); +} + +static inline void +invpcid(uint64_t type, paddr_t pcid, paddr_t addr) +{ + uint64_t desc[2] = { pcid, addr }; + asm volatile("invpcid %0,%1" : : "m"(desc[0]), "r"(type)); +} +#define INVPCID_ADDR 0 +#define INVPCID_PCID 1 +#define INVPCID_ALL 2 +#define INVPCID_NON_GLOBAL 3 + +#ifdef notyet +void setidt(int idx, /*XXX*/caddr_t func, int typ, int dpl); +#endif + + +/* XXXX ought to be in psl.h with spl() functions */ + +static __inline u_long +read_rflags(void) +{ + u_long ef; + + __asm volatile("pushfq; popq %0" : "=r" (ef)); + return (ef); +} + +static __inline void +write_rflags(u_long ef) +{ + __asm volatile("pushq %0; popfq" : : "r" (ef)); +} + +static __inline void +intr_enable(void) +{ + __asm volatile("sti"); +} + +static __inline u_long +intr_disable(void) +{ + u_long ef; + + ef = read_rflags(); + __asm volatile("cli"); + return (ef); +} + +static __inline void +intr_restore(u_long ef) +{ + write_rflags(ef); +} + +static __inline u_int64_t +rdmsr(u_int msr) +{ + uint32_t hi, lo; + __asm volatile("rdmsr" : "=d" (hi), "=a" (lo) : "c" (msr)); + return (((uint64_t)hi << 32) | (uint64_t) lo); +} + +static __inline int +rdpkru(u_int ecx) +{ + uint32_t edx, pkru; + asm volatile("rdpkru " : "=a" (pkru), "=d" (edx) : "c" (ecx)); + return pkru; +} + +static __inline void +wrpkru(u_int ecx, uint32_t pkru) +{ + uint32_t edx = 0; + asm volatile("wrpkru" : : "a" (pkru), "c" (ecx), "d" (edx)); +} + +static __inline void +wrmsr(u_int msr, u_int64_t newval) +{ + __asm volatile("wrmsr" : + : "a" (newval & 0xffffffff), "d" (newval >> 32), "c" (msr)); +} + +/* + * Some of the undocumented AMD64 MSRs need a 'passcode' to access. + * + * See LinuxBIOSv2: src/cpu/amd/model_fxx/model_fxx_init.c + */ + +#define OPTERON_MSR_PASSCODE 0x9c5a203a + +static __inline u_int64_t +rdmsr_locked(u_int msr, u_int code) +{ + uint32_t hi, lo; + __asm volatile("rdmsr" + : "=d" (hi), "=a" (lo) + : "c" (msr), "D" (code)); + return (((uint64_t)hi << 32) | (uint64_t) lo); +} + +static __inline void +wrmsr_locked(u_int msr, u_int code, u_int64_t newval) +{ + __asm volatile("wrmsr" : + : "a" (newval & 0xffffffff), "d" (newval >> 32), "c" (msr), "D" (code)); +} + +static __inline void +wbinvd(void) +{ + __asm volatile("wbinvd" : : : "memory"); +} + +#ifdef MULTIPROCESSOR +int wbinvd_on_all_cpus(void); +void wbinvd_on_all_cpus_acked(void); +#else +static inline int +wbinvd_on_all_cpus(void) +{ + wbinvd(); + return 0; +} + +static inline int +wbinvd_on_all_cpus_acked(void) +{ + wbinvd(); + return 0; +} +#endif /* MULTIPROCESSOR */ + +static __inline void +clflush(u_int64_t addr) +{ + __asm volatile("clflush %0" : "+m" (*(volatile char *)addr)); +} + +static __inline void +mfence(void) +{ + __asm volatile("mfence" : : : "memory"); +} + +static __inline u_int64_t +rdtsc(void) +{ + uint32_t hi, lo; + + __asm volatile("rdtsc" : "=d" (hi), "=a" (lo)); + return (((uint64_t)hi << 32) | (uint64_t) lo); +} + +static __inline u_int64_t +rdtscp(void) +{ + uint32_t hi, lo; + + __asm volatile("rdtscp" : "=d" (hi), "=a" (lo) : : "ecx"); + return (((uint64_t)hi << 32) | (uint64_t) lo); +} + +static __inline u_int64_t +rdtsc_lfence(void) +{ + uint32_t hi, lo; + + __asm volatile("lfence; rdtsc" : "=d" (hi), "=a" (lo)); + return (((uint64_t)hi << 32) | (uint64_t) lo); +} + +static __inline u_int64_t +rdpmc(u_int pmc) +{ + uint32_t hi, lo; + + __asm volatile("rdpmc" : "=d" (hi), "=a" (lo) : "c" (pmc)); + return (((uint64_t)hi << 32) | (uint64_t) lo); +} + +static __inline void +monitor(const volatile void *addr, u_long extensions, u_int hints) +{ + + __asm volatile("monitor" + : : "a" (addr), "c" (extensions), "d" (hints)); +} + +static __inline void +mwait(u_long extensions, u_int hints) +{ + + __asm volatile( + " mwait ;" + " mov $8,%%rcx ;" + " .align 16,0x90 ;" + "3: call 5f ;" + "4: pause ;" + " lfence ;" + " call 4b ;" + " .align 16,0xcc ;" + "5: call 7f ;" + "6: pause ;" + " lfence ;" + " call 6b ;" + " .align 16,0xcc ;" + "7: loop 3b ;" + " add $(16*8),%%rsp" + : "+c" (extensions) : "a" (hints)); +} + +static __inline void +xsetbv(uint32_t reg, uint64_t mask) +{ + uint32_t lo, hi; + + lo = mask; + hi = mask >> 32; + __asm volatile("xsetbv" :: "c" (reg), "a" (lo), "d" (hi) : "memory"); +} + +static __inline uint64_t +xgetbv(uint32_t reg) +{ + uint32_t lo, hi; + + __asm volatile("xgetbv" : "=a" (lo), "=d" (hi) : "c" (reg)); + + return (((uint64_t)hi << 32) | (uint64_t)lo); +} + +static __inline void +stgi(void) +{ + __asm volatile("stgi"); +} + +static __inline void +clgi(void) +{ + __asm volatile("clgi"); +} + +/* Break into DDB. */ +static __inline void +breakpoint(void) +{ + __asm volatile("int $3"); +} + +/* VMGEXIT */ +static __inline void +vmgexit(void) +{ + /* rep; vmmcall encodes the vmgexit instruction */ + __asm volatile("rep; vmmcall"); +} + +void amd64_errata(struct cpu_info *); +void cpu_ucode_setup(void); +void cpu_ucode_apply(struct cpu_info *); + +struct cpu_info_full; +void cpu_enter_pages(struct cpu_info_full *); + +int rdmsr_safe(u_int msr, uint64_t *); + +#endif /* _KERNEL */ + +#endif /* !_MACHINE_CPUFUNC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/cpuvar.h b/lib/libc/include/x86_64-openbsd-none/amd64/cpuvar.h new file mode 100644 index 0000000000..c82e3adf88 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/cpuvar.h @@ -0,0 +1,100 @@ +/* $OpenBSD: cpuvar.h,v 1.14 2024/10/22 10:14:49 jsg Exp $ */ +/* $NetBSD: cpuvar.h,v 1.1 2003/03/01 18:29:28 fvdl Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by RedBack Networks Inc. + * + * Author: Bill Sommerfeld + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 1999 Stefan Grefen + * + * 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 NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 AUTHOR 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 AUTHOR AND 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. + */ + +struct cpu_functions { + int (*start)(struct cpu_info *); + int (*stop)(struct cpu_info *); + void (*cleanup)(struct cpu_info *); +}; + +extern struct cpu_functions mp_cpu_funcs; + +#define CPU_ROLE_SP 0 +#define CPU_ROLE_BP 1 +#define CPU_ROLE_AP 2 + +struct cpu_attach_args { + const char *caa_name; + int cpu_apicid; + int cpu_acpi_proc_id; + int cpu_role; + struct cpu_functions *cpu_func; +}; + +#ifdef _KERNEL + +#ifdef MULTIPROCESSOR +extern void (*x86_ipi)(int,int,int); +void x86_ipi_init(int); +#endif + +void identifycpu(struct cpu_info *); +void cpu_init(struct cpu_info *); + +void tsc_test_sync_bp(struct cpu_info *); +void tsc_test_sync_ap(struct cpu_info *); + +#endif \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/db_machdep.h b/lib/libc/include/x86_64-openbsd-none/amd64/db_machdep.h new file mode 100644 index 0000000000..4a66d5a761 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/db_machdep.h @@ -0,0 +1,101 @@ +/* $OpenBSD: db_machdep.h,v 1.19 2021/08/30 08:11:12 jasper Exp $ */ +/* $NetBSD: db_machdep.h,v 1.2 2003/04/29 17:06:04 scw Exp $ */ + +/* + * Mach Operating System + * Copyright (c) 1991,1990 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +#ifndef _MACHINE_DB_MACHDEP_H_ +#define _MACHINE_DB_MACHDEP_H_ + +/* + * Machine-dependent defines for new kernel debugger. + */ + +#include +#include +#include +#include + +typedef long db_expr_t; /* expression - signed */ + +typedef struct trapframe db_regs_t; + +extern db_regs_t ddb_regs; /* register state */ + +#define PC_REGS(regs) ((vaddr_t)(regs)->tf_rip) +#define SET_PC_REGS(regs, value) (regs)->tf_rip = (int64_t)(value) + +#define BKPT_ADDR(addr) (addr) /* breakpoint address */ +#define BKPT_INST 0xcc /* breakpoint instruction */ +#define BKPT_SIZE (1) /* size of breakpoint inst */ +#define BKPT_SET(inst) (BKPT_INST) + +#define SSF_INST 0x55 +#define SSF_SIZE (1) + +#define FIXUP_PC_AFTER_BREAK(regs) ((regs)->tf_rip -= BKPT_SIZE) + +#define db_clear_single_step(regs) ((regs)->tf_rflags &= ~PSL_T) +#define db_set_single_step(regs) ((regs)->tf_rflags |= PSL_T) + +#define IS_BREAKPOINT_TRAP(type, code) ((type) == T_BPTFLT) +#define IS_WATCHPOINT_TRAP(type, code) ((type) == T_TRCTRAP && (code) & 15) + +#define I_CALL 0xe8 +#define I_CALLI 0xff +#define I_RET 0xc3 +#define I_IRET 0xcf + +#define inst_trap_return(ins) (((ins)&0xff) == I_IRET) +#define inst_return(ins) (((ins)&0xff) == I_RET) +#define inst_call(ins) (((ins)&0xff) == I_CALL || \ + (((ins)&0xff) == I_CALLI && \ + ((ins)&0x3800) == 0x1000)) + +/* macro for checking if a thread has used floating-point */ + +int db_ktrap(int, int, db_regs_t *); + +void db_machine_init(void); +int db_enter_ddb(void); +void db_startcpu(int); +void db_stopcpu(int); +void x86_ipi_db(struct cpu_info *); + +#define DDB_STATE_NOT_RUNNING 0 +#define DDB_STATE_RUNNING 1 +#define DDB_STATE_EXITING 2 + +/* + * We define some of our own commands + */ +#define DB_MACHINE_COMMANDS + +extern void db_machine_init(void); + +extern void cpu_debug_dump(void); + +#endif /* _MACHINE_DB_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/disklabel.h b/lib/libc/include/x86_64-openbsd-none/amd64/disklabel.h new file mode 100644 index 0000000000..44d225a0a8 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/disklabel.h @@ -0,0 +1,40 @@ +/* $OpenBSD: disklabel.h,v 1.11 2015/09/30 14:57:03 krw Exp $ */ + +/* + * Copyright (c) 1994 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 _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_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/efifbvar.h b/lib/libc/include/x86_64-openbsd-none/amd64/efifbvar.h new file mode 100644 index 0000000000..1958da38bc --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/efifbvar.h @@ -0,0 +1,40 @@ +/* $OpenBSD: efifbvar.h,v 1.10 2019/05/04 11:34:47 kettenis Exp $ */ + +/* + * Copyright (c) 2015 YASUOKA Masahiko + * + * 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_EFIFB_H_ +#define _MACHINE_EFIFB_H_ + +struct efifb_attach_args { + const char *eaa_name; +}; + +struct pci_attach_args; + +int efifb_cnattach(void); +void efifb_cnremap(void); +int efifb_is_console(struct pci_attach_args *); +int efifb_is_primary(struct pci_attach_args *); +void efifb_detach(void); +void efifb_reattach(void); + +int efifb_cb_found(void); +int efifb_cb_cnattach(void); + +psize_t efifb_stolen(void); + +#endif /* _MACHINE_EFIFB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/efivar.h b/lib/libc/include/x86_64-openbsd-none/amd64/efivar.h new file mode 100644 index 0000000000..72645470e8 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/efivar.h @@ -0,0 +1,42 @@ +/* $OpenBSD: efivar.h,v 1.1 2023/01/14 12:11:10 kettenis Exp $ */ +/* + * Copyright (c) 2022 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_EFIVAR_H_ +#define _MACHINE_EFIVAR_H_ + +#include + +struct efi_softc { + struct device sc_dev; + struct pmap *sc_pm; + EFI_RUNTIME_SERVICES *sc_rs; + EFI_SYSTEM_RESOURCE_TABLE *sc_esrt; + u_long sc_psw; + uint64_t sc_cr3; + + struct todr_chip_handle sc_todr; +}; + +void efi_enter(struct efi_softc *); +void efi_leave(struct efi_softc *); + +extern label_t efi_jmpbuf; + +#define efi_enter_check(sc) (setjmp(&efi_jmpbuf) ? \ + (efi_leave(sc), EFAULT) : (efi_enter(sc), 0)) + +#endif /* _MACHINE_EFIVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/elf.h b/lib/libc/include/x86_64-openbsd-none/amd64/elf.h new file mode 100644 index 0000000000..1cd8fda26a --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/elf.h @@ -0,0 +1,7 @@ +/* $OpenBSD: elf.h,v 1.1 2024/07/14 09:48:48 jca Exp $ */ + +/* + * This file is in the public domain. + */ + +/* Nothing for now */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/endian.h b/lib/libc/include/x86_64-openbsd-none/amd64/endian.h new file mode 100644 index 0000000000..7ff7b356d9 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/endian.h @@ -0,0 +1,36 @@ +/* $OpenBSD: endian.h,v 1.8 2024/05/07 14:26:48 naddy 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_ + +#define _BYTE_ORDER _LITTLE_ENDIAN + +#ifndef __FROM_SYS__ENDIAN +#include +#endif + +#endif /* _MACHINE_ENDIAN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/exec.h b/lib/libc/include/x86_64-openbsd-none/amd64/exec.h new file mode 100644 index 0000000000..8fafeb9b4c --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/exec.h @@ -0,0 +1,17 @@ +/* $OpenBSD: exec.h,v 1.7 2017/02/08 05:09:25 guenther Exp $ */ +/* + * Written by Artur Grabowski Public Domain + */ + +#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_AMD64 + +#endif \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/fenv.h b/lib/libc/include/x86_64-openbsd-none/amd64/fenv.h new file mode 100644 index 0000000000..0b16f62459 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/fenv.h @@ -0,0 +1,115 @@ +/* $OpenBSD: fenv.h,v 1.4 2011/05/25 21:46:49 martynas Exp $ */ +/* $NetBSD: fenv.h,v 1.1 2010/07/31 21:47:54 joerg Exp $ */ + +/*- + * Copyright (c) 2004-2005 David Schultz + * 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 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 AUTHOR 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 _AMD64_FENV_H_ +#define _AMD64_FENV_H_ + +/* + * Each symbol representing a floating point exception expands to an integer + * constant expression with values, such that bitwise-inclusive ORs of _all + * combinations_ of the constants result in distinct values. + * + * We use such values that allow direct bitwise operations on FPU/SSE registers. + */ +#define FE_INVALID 0x01 +#define FE_DENORMAL 0x02 +#define FE_DIVBYZERO 0x04 +#define FE_OVERFLOW 0x08 +#define FE_UNDERFLOW 0x10 +#define FE_INEXACT 0x20 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * exception constants defined above. + */ +#define FE_ALL_EXCEPT (FE_INVALID | FE_DENORMAL | FE_DIVBYZERO | \ + FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT) +#define _SSE_MASK_SHIFT 7 + +/* + * Each symbol representing the rounding direction, expands to an integer + * constant expression whose value is distinct non-negative value. + * + * We use such values that allow direct bitwise operations on FPU/SSE registers. + */ +#define FE_TONEAREST 0x000 +#define FE_DOWNWARD 0x400 +#define FE_UPWARD 0x800 +#define FE_TOWARDZERO 0xc00 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * rounding direction constants defined above. + */ +#define _X87_ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | \ + FE_TOWARDZERO) +#define _SSE_ROUND_SHIFT 3 + +/* + * fenv_t represents the entire floating-point environment. + */ +typedef struct { + struct { + unsigned int __control; /* Control word register */ + unsigned int __status; /* Status word register */ + unsigned int __tag; /* Tag word register */ + unsigned int __others[4]; /* EIP, Pointer Selector, etc */ + } __x87; + unsigned int __mxcsr; /* Control, status register */ +} fenv_t; + +/* + * The following constant represents the default floating-point environment + * (that is, the one installed at program startup) and has type pointer to + * const-qualified fenv_t. + * + * It can be used as an argument to the functions within the header + * that manage the floating-point environment, namely fesetenv() and + * feupdateenv(). + */ +__BEGIN_DECLS +extern fenv_t __fe_dfl_env; +__END_DECLS +#define FE_DFL_ENV ((const fenv_t *)&__fe_dfl_env) + +/* + * fexcept_t represents the floating-point status flags collectively, including + * any status the implementation associates with the flags. + * + * A floating-point status flag is a system variable whose value is set (but + * never cleared) when a floating-point exception is raised, which occurs as a + * side effect of exceptional floating-point arithmetic to provide auxiliary + * information. + * + * A floating-point control mode is a system variable whose value may be set by + * the user to affect the subsequent behavior of floating-point arithmetic. + */ +typedef unsigned int fexcept_t; + +#endif /* !_AMD64_FENV_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/fpu.h b/lib/libc/include/x86_64-openbsd-none/amd64/fpu.h new file mode 100644 index 0000000000..b79b7a27c4 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/fpu.h @@ -0,0 +1,111 @@ +/* $OpenBSD: fpu.h,v 1.20 2024/04/14 09:59:04 kettenis Exp $ */ +/* $NetBSD: fpu.h,v 1.1 2003/04/26 18:39:40 fvdl Exp $ */ + +#ifndef _MACHINE_FPU_H_ +#define _MACHINE_FPU_H_ + +#include + +/* + * If the CPU supports xsave/xrstor then we use them so that we can provide + * AVX support. Otherwise we require fxsave/fxrstor, as the SSE registers + * are part of the ABI for passing floating point values. + * While fxsave/fxrstor only required 16-byte alignment for the save area, + * xsave/xrstor requires the save area to have 64-byte alignment. + */ + +struct fxsave64 { + u_int16_t fx_fcw; + u_int16_t fx_fsw; + u_int8_t fx_ftw; + u_int8_t fx_unused1; + u_int16_t fx_fop; + u_int64_t fx_rip; + u_int64_t fx_rdp; + u_int32_t fx_mxcsr; + u_int32_t fx_mxcsr_mask; + u_int64_t fx_st[8][2]; /* 8 normal FP regs */ + u_int64_t fx_xmm[16][2]; /* 16 SSE2 registers */ + u_int8_t fx_unused3[96]; +} __packed; + +struct xstate_hdr { + uint64_t xstate_bv; + uint64_t xstate_xcomp_bv; + uint8_t xstate_rsrv0[8]; + uint8_t xstate_rsrv[40]; +} __packed; + +struct savefpu { + struct fxsave64 fp_fxsave; /* see above */ + struct xstate_hdr fp_xstate; + u_int64_t fp_ymm[16][2]; + u_int8_t fp_components[1856]; /* enough for AVX-512 */ +}; + +/* + * The i387 defaults to Intel extended precision mode and round to nearest, + * with all exceptions masked. + */ +#define __INITIAL_NPXCW__ 0x037f +#define __INITIAL_MXCSR__ 0x1f80 +#define __INITIAL_MXCSR_MASK__ 0xffbf + +#ifdef _KERNEL +/* + * XXX + */ +struct trapframe; +struct cpu_info; + +extern size_t fpu_save_len; +extern uint32_t fpu_mxcsr_mask; +extern uint64_t xsave_mask; +extern int cpu_use_xsaves; + +void fpuinit(struct cpu_info *); +int fputrap(int _type); +void fpusave(struct savefpu *); +void fpusavereset(struct savefpu *); +void fpu_kernel_enter(void); +void fpu_kernel_exit(void); + +/* pointer to fxsave/xsave/xsaves data with everything reset */ +#define fpu_cleandata (&proc0.p_addr->u_pcb.pcb_savefpu) + +int xrstor_user(struct savefpu *_addr, uint64_t _mask); +void xrstor_kern(struct savefpu *_addr, uint64_t _mask); +#define fpureset() \ + xrstor_kern(fpu_cleandata, xsave_mask) +int xsetbv_user(uint32_t _reg, uint64_t _mask); + +#define fninit() __asm("fninit") +#define fwait() __asm("fwait") +/* should be fxsave64, but where we use this it doesn't matter */ +#define fxsave(addr) __asm("fxsave %0" : "=m" (*addr)) +#define ldmxcsr(addr) __asm("ldmxcsr %0" : : "m" (*addr)) +#define fldcw(addr) __asm("fldcw %0" : : "m" (*addr)) + +static inline void +xsave(struct savefpu *addr, uint64_t mask) +{ + uint32_t lo, hi; + + lo = mask; + hi = mask >> 32; + __asm volatile("xsave64 %0" : "+m" (*addr) : "a" (lo), "d" (hi)); +} + +static inline void +xrstors(const struct savefpu *addr, uint64_t mask) +{ + uint32_t lo, hi; + + lo = mask; + hi = mask >> 32; + __asm volatile("xrstors64 %0" : : "m" (*addr), "a" (lo), "d" (hi)); +} + +#endif + +#endif /* _MACHINE_FPU_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/frame.h b/lib/libc/include/x86_64-openbsd-none/amd64/frame.h new file mode 100644 index 0000000000..bd9658dec4 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/frame.h @@ -0,0 +1,174 @@ +/* $OpenBSD: frame.h,v 1.11 2024/01/31 06:06:28 guenther Exp $ */ +/* $NetBSD: frame.h,v 1.1 2003/04/26 18:39:40 fvdl Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Charles M. Hannum. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*- + * Copyright (c) 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. + * + * @(#)frame.h 5.2 (Berkeley) 1/18/91 + */ + +/* + * Adapted for NetBSD/amd64 by fvdl@wasabisystems.com + */ + +#ifndef _MACHINE_FRAME_H_ +#define _MACHINE_FRAME_H_ + +#include +#include + +/* + * System stack frames. + */ + +/* + * Exception/Trap Stack Frame + */ +struct trapframe { + int64_t tf_rdi; /* ordered by syscall args... */ + int64_t tf_rsi; + int64_t tf_rdx; + int64_t tf_r10; + int64_t tf_r8; + int64_t tf_r9; /* ...to here */ + int64_t tf_rcx; + int64_t tf_r11; + int64_t tf_r12; + int64_t tf_r13; + int64_t tf_r14; + int64_t tf_r15; + int64_t tf_err; /* not the hardware position */ + int64_t tf_rbx; + int64_t tf_rax; + int64_t tf_trapno; + int64_t tf_rbp; /* hardware puts err here, INTRENTRY() moves it up */ + /* below portion defined in hardware */ + int64_t tf_rip; + int64_t tf_cs; + int64_t tf_rflags; + /* These are pushed unconditionally on the x86-64 */ + int64_t tf_rsp; + int64_t tf_ss; +}; + +/* + * Interrupt stack frame + */ +struct intrframe { + int64_t if_rdi; + int64_t if_rsi; + int64_t if_rdx; + int64_t if_r10; + int64_t if_r8; + int64_t if_r9; + int64_t if_rcx; + int64_t if_r11; + int64_t if_r12; + int64_t if_r13; + int64_t if_r14; + int64_t if_r15; + int64_t if_err; /* IREENT_MAGIC if resume/recurse */ + int64_t if_rbx; + int64_t if_rax; + int64_t if_ppl; /* previous priority level */ + int64_t if_rbp; + /* below portion defined in hardware */ + int64_t if_rip; + int64_t if_cs; + int64_t if_rflags; + /* These are pushed unconditionally on the x86-64 */ + int64_t if_rsp; + int64_t if_ss; +}; + + +/* + * The trampoline frame used on the kernel stack page which is present + * but kernel-only, in the page tables used when in userspace. This is + * the minimum for iretq operation. + */ +struct iretq_frame { + int64_t iretq_rip; + int64_t iretq_cs; + int64_t iretq_rflags; + int64_t iretq_rsp; + int64_t iretq_ss; +}; + +/* + * Stack frame inside cpu_switch() + */ +struct switchframe { + int64_t sf_r15; + int64_t sf_r14; + int64_t sf_r13; + int64_t sf_r12; + int64_t sf_rbp; + int64_t sf_rbx; + int64_t sf_rip; +}; + +struct callframe { + struct callframe *f_frame; + long f_retaddr; + long f_arg0; +}; + +#endif /* _MACHINE_FRAME_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/frameasm.h b/lib/libc/include/x86_64-openbsd-none/amd64/frameasm.h new file mode 100644 index 0000000000..0ef22deefb --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/frameasm.h @@ -0,0 +1,199 @@ +/* $OpenBSD: frameasm.h,v 1.27 2023/07/27 00:30:07 guenther Exp $ */ +/* $NetBSD: frameasm.h,v 1.1 2003/04/26 18:39:40 fvdl Exp $ */ + +#ifndef _AMD64_MACHINE_FRAMEASM_H +#define _AMD64_MACHINE_FRAMEASM_H + +/* + * Macros to define pushing/popping frames for interrupts, traps + * and system calls. Currently all the same; will diverge later. + */ + +/* + * These are used on interrupt or trap entry or exit. + */ +#define INTR_SAVE_GPRS \ + subq $120,%rsp ; \ + INTR_SAVE_MOST_GPRS_NO_ADJ ; \ + movq %rcx,TF_RCX(%rsp) +#define INTR_SAVE_MOST_GPRS_NO_ADJ \ + movq %r15,TF_R15(%rsp) ; \ + movq %r14,TF_R14(%rsp) ; \ + movq %r13,TF_R13(%rsp) ; \ + movq %r12,TF_R12(%rsp) ; \ + movq %r11,TF_R11(%rsp) ; \ + movq %r10,TF_R10(%rsp) ; \ + movq %r9,TF_R9(%rsp) ; \ + movq %r8,TF_R8(%rsp) ; \ + movq %rdi,TF_RDI(%rsp) ; \ + movq %rsi,TF_RSI(%rsp) ; \ + movq %rbp,TF_RBP(%rsp) ; \ + leaq TF_RBP(%rsp),%rbp ; \ + movq %rbx,TF_RBX(%rsp) ; \ + movq %rdx,TF_RDX(%rsp) ; \ + movq %rax,TF_RAX(%rsp) + +/* + * We clear registers when coming from userspace to prevent + * user-controlled values from being available for use in speculative + * execution in the kernel. %rsp and %rbp are the kernel values when + * this is used, so there are only 14 to clear. 32bit operations clear + * the register upper-halves automatically. + */ +#define INTR_CLEAR_GPRS \ + xorl %eax,%eax ; \ + xorl %ebx,%ebx ; \ + xorl %ecx,%ecx ; \ + xorl %edx,%edx ; \ + xorl %esi,%esi ; \ + xorl %edi,%edi ; \ + xorl %r8d,%r8d ; \ + xorl %r9d,%r9d ; \ + xorl %r10d,%r10d ; \ + xorl %r11d,%r11d ; \ + xorl %r12d,%r12d ; \ + xorl %r13d,%r13d ; \ + xorl %r14d,%r14d ; \ + xorl %r15d,%r15d + + +/* + * For real interrupt code paths, where we can come from userspace. + * We only have an iretq_frame on entry. + */ +#define INTRENTRY_LABEL(label) X##label##_untramp +#define INTRENTRY(label) \ + endbr64 ; \ + testb $SEL_RPL,IRETQ_CS(%rsp) ; \ + je INTRENTRY_LABEL(label) ; \ + swapgs ; \ + FENCE_SWAPGS_MIS_TAKEN ; \ + movq %rax,CPUVAR(SCRATCH) ; \ + CODEPATCH_START ; \ + movq CPUVAR(KERN_CR3),%rax ; \ + movq %rax,%cr3 ; \ + CODEPATCH_END(CPTAG_MELTDOWN_NOP);\ + jmp 98f ; \ +END(X##label) ; \ +_ENTRY(INTRENTRY_LABEL(label)) /* from kernel */ \ + FENCE_NO_SAFE_SMAP ; \ + subq $TF_RIP,%rsp ; \ + movq %rcx,TF_RCX(%rsp) ; \ + jmp 99f ; \ + _ALIGN_TRAPS ; \ +98: /* from userspace */ \ + movq CPUVAR(KERN_RSP),%rax ; \ + xchgq %rax,%rsp ; \ + movq %rcx,TF_RCX(%rsp) ; \ + RET_STACK_REFILL_WITH_RCX ; \ + /* copy iretq frame to the trap frame */ \ + movq IRETQ_RIP(%rax),%rcx ; \ + movq %rcx,TF_RIP(%rsp) ; \ + movq IRETQ_CS(%rax),%rcx ; \ + movq %rcx,TF_CS(%rsp) ; \ + movq IRETQ_RFLAGS(%rax),%rcx ; \ + movq %rcx,TF_RFLAGS(%rsp) ; \ + movq IRETQ_RSP(%rax),%rcx ; \ + movq %rcx,TF_RSP(%rsp) ; \ + movq IRETQ_SS(%rax),%rcx ; \ + movq %rcx,TF_SS(%rsp) ; \ + movq CPUVAR(SCRATCH),%rax ; \ +99: INTR_SAVE_MOST_GPRS_NO_ADJ ; \ + INTR_CLEAR_GPRS ; \ + movq %rax,TF_ERR(%rsp) + +#define INTRFASTEXIT \ + jmp intr_fast_exit + +/* + * Entry for faking up an interrupt frame after spllower() unblocks + * a previously received interrupt. On entry, %r13 has the %rip + * to return to. %r10 and %r11 are scratch. + */ +#define INTR_RECURSE \ + endbr64 ; \ + /* fake the iretq_frame */ ; \ + movq %rsp,%r10 ; \ + movl %ss,%r11d ; \ + pushq %r11 ; \ + pushq %r10 ; \ + pushfq ; \ + movl %cs,%r11d ; \ + pushq %r11 ; \ + pushq %r13 ; \ + /* now do the rest of the intrframe */ \ + subq $16,%rsp ; \ + INTR_SAVE_GPRS + + +/* + * Entry for traps from kernel, where there's a trapno + err already + * on the stack. We have to move the err from its hardware location + * to the location we want it. + */ +#define TRAP_ENTRY_KERN \ + subq $120,%rsp ; \ + movq %rcx,TF_RCX(%rsp) ; \ + movq (TF_RIP - 8)(%rsp),%rcx ; \ + movq %rcx,TF_ERR(%rsp) ; \ + INTR_SAVE_MOST_GPRS_NO_ADJ + +/* + * Entry for traps from userland, where there's a trapno + err on + * the iretq stack. + * Assumes that %rax has been saved in CPUVAR(SCRATCH). + */ +#define TRAP_ENTRY_USER \ + movq CPUVAR(KERN_RSP),%rax ; \ + xchgq %rax,%rsp ; \ + movq %rcx,TF_RCX(%rsp) ; \ + RET_STACK_REFILL_WITH_RCX ; \ + /* copy trapno+err to the trap frame */ \ + movq 0(%rax),%rcx ; \ + movq %rcx,TF_TRAPNO(%rsp) ; \ + movq 8(%rax),%rcx ; \ + movq %rcx,TF_ERR(%rsp) ; \ + /* copy iretq frame to the trap frame */ \ + movq (IRETQ_RIP+16)(%rax),%rcx ; \ + movq %rcx,TF_RIP(%rsp) ; \ + movq (IRETQ_CS+16)(%rax),%rcx ; \ + movq %rcx,TF_CS(%rsp) ; \ + movq (IRETQ_RFLAGS+16)(%rax),%rcx ; \ + movq %rcx,TF_RFLAGS(%rsp) ; \ + movq (IRETQ_RSP+16)(%rax),%rcx ; \ + movq %rcx,TF_RSP(%rsp) ; \ + movq (IRETQ_SS+16)(%rax),%rcx ; \ + movq %rcx,TF_SS(%rsp) ; \ + movq CPUVAR(SCRATCH),%rax ; \ + INTR_SAVE_MOST_GPRS_NO_ADJ ; \ + INTR_CLEAR_GPRS + +/* + * Entry from syscall instruction, where RIP is in %rcx and RFLAGS is in %r11. + * We stash the syscall # in tf_err for SPL check. + * Assumes that %rax has been saved in CPUVAR(SCRATCH). + */ +#define SYSCALL_ENTRY \ + movq CPUVAR(KERN_RSP),%rax ; \ + xchgq %rax,%rsp ; \ + movq %rcx,TF_RCX(%rsp) ; \ + movq %rcx,TF_RIP(%rsp) ; \ + RET_STACK_REFILL_WITH_RCX ; \ + movq $(GSEL(GUDATA_SEL, SEL_UPL)),TF_SS(%rsp) ; \ + movq %rax,TF_RSP(%rsp) ; \ + movq CPUVAR(SCRATCH),%rax ; \ + INTR_SAVE_MOST_GPRS_NO_ADJ ; \ + movq %r11, TF_RFLAGS(%rsp) ; \ + movq $(GSEL(GUCODE_SEL, SEL_UPL)), TF_CS(%rsp) ; \ + movq %rax,TF_ERR(%rsp) ; \ + INTR_CLEAR_GPRS + +#define CHECK_ASTPENDING(reg) movq CPUVAR(CURPROC),reg ; \ + cmpq $0, reg ; \ + je 99f ; \ + cmpl $0, P_MD_ASTPENDING(reg) ; \ + 99: + +#define CLEAR_ASTPENDING(reg) movl $0, P_MD_ASTPENDING(reg) + +#endif /* _AMD64_MACHINE_FRAMEASM_H */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/gdt.h b/lib/libc/include/x86_64-openbsd-none/amd64/gdt.h new file mode 100644 index 0000000000..0e9ba4aa90 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/gdt.h @@ -0,0 +1,33 @@ +/* $OpenBSD: gdt.h,v 1.6 2018/02/21 19:24:15 guenther Exp $ */ +/* $NetBSD: gdt.h,v 1.1 2003/04/26 18:39:40 fvdl Exp $ */ + +/*- + * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by John T. Kohl and Charles M. Hannum. + * + * 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. + */ + +void gdt_init_cpu(struct cpu_info *); \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/ghcb.h b/lib/libc/include/x86_64-openbsd-none/amd64/ghcb.h new file mode 100644 index 0000000000..73f9484212 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/ghcb.h @@ -0,0 +1,251 @@ +/* $OpenBSD: ghcb.h,v 1.6 2025/09/17 18:37:44 sf Exp $ */ + +/* + * Copyright (c) 2024, 2025 Hans-Joerg Hoexer + * + * 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_GHCB_H_ +#define _MACHINE_GHCB_H_ + +#ifndef _LOCORE + +#include + +#include + +#define GHCB_OFFSET(m) ((m) / 8) +#define GHCB_IDX(m) (GHCB_OFFSET((m)) / 8) +#define GHCB_BIT(m) (GHCB_OFFSET((m)) % 8) + +#define GHCB_XSS 0x140 +#define GHCB_RAX 0x1F8 +#define GHCB_RBX 0x318 +#define GHCB_RCX 0x308 +#define GHCB_RDX 0x310 +#define GHCB_SW_EXITCODE 0x390 +#define GHCB_SW_EXITINFO1 0x398 +#define GHCB_SW_EXITINFO2 0x3A0 +#define GHCB_SW_SCRATCH 0x3A8 +#define GHCB_XCR0 0x3E8 + +#define GHCB_MAX 0xFFF + +struct ghcb_sa { + uint8_t v_pad0[0xcb]; /* 000h-0CAh */ + uint8_t v_cpl; /* 0CBh */ + uint8_t v_pad1[0x74]; /* 0CCh-13Fh */ + uint64_t v_xss; /* 140h */ + uint8_t v_pad2[0x18]; /* 148h-15Fh */ + uint64_t v_dr7; /* 160h */ + uint8_t v_pad3[0x10]; /* 168h-177h */ + uint64_t v_rip; /* 178h */ + uint8_t v_pad4[0x58]; /* 180h-1D7h */ + uint64_t v_rsp; /* 1D8h */ + uint8_t v_pad5[0x18]; /* 1E0h-1F7h */ + uint64_t v_rax; /* 1F8h */ + uint8_t v_pad6[0x108]; /* 200h-307h */ + uint64_t v_rcx; /* 308h */ + uint64_t v_rdx; /* 310h */ + uint64_t v_rbx; /* 318h */ + uint8_t v_pad7[0x8]; /* 320h-327h */ + uint64_t v_rbp; /* 328h */ + uint64_t v_rsi; /* 330h */ + uint64_t v_rdi; /* 338h */ + uint64_t v_r8; /* 340h */ + uint64_t v_r9; /* 348h */ + uint64_t v_r10; /* 350h */ + uint64_t v_r11; /* 358h */ + uint64_t v_r12; /* 360h */ + uint64_t v_r13; /* 368h */ + uint64_t v_r14; /* 370h */ + uint64_t v_r15; /* 378h */ + uint8_t v_pad8[0x10]; /* 380h-38Fh */ + uint64_t v_sw_exitcode; /* 390h */ + uint64_t v_sw_exitinfo1; /* 398h */ + uint64_t v_sw_exitinfo2; /* 3a0h */ + uint64_t v_sw_scratch; /* 3a8h */ + uint8_t v_pad9[0x38]; /* 3B0h-3E7h */ + uint64_t v_xcr0; /* 3E8h */ +#define GHCB_VB_SZ 0x10 + uint8_t valid_bitmap[GHCB_VB_SZ]; + /* 3F0h-3FFh */ + uint64_t v_x87_state_gpa; /* 400h */ + uint8_t v_pad10[0x3f8]; /* 408h-7FFh */ + uint8_t v_sharedbuf[0x7f0]; /* 800h-FEFh */ + uint8_t v_pad11[0xa]; /* FF0h-FF9h */ + uint16_t v_ghcb_proto_version; /* FFAh-FFBh */ + uint32_t v_ghcb_usage; /* FFCh-FFFh */ +}; + +#define GHCB_SZ8 0 +#define GHCB_SZ16 1 +#define GHCB_SZ32 2 +#define GHCB_SZ64 3 + +struct ghcb_sync { + uint8_t valid_bitmap[GHCB_VB_SZ]; + + int sz_a; + int sz_b; + int sz_c; + int sz_d; +}; +#endif /* !_LOCORE */ + +/* Definitions used with the MSR protocol */ +#define MSR_PROTO_CPUID_REQ 0x4 +#define MSR_PROTO_CPUID_RESP 0x5 +#define MSR_PROTO_TERMINATE 0x100 + +#ifndef _LOCORE + +extern vaddr_t ghcb_vaddr; +extern paddr_t ghcb_paddr; + +struct ghcb_extra_regs { + uint64_t exitcode; + uint64_t exitinfo1; + uint64_t exitinfo2; + uint64_t scratch; + void *data; + size_t data_sz; +}; + +void ghcb_clear(struct ghcb_sa *); +int ghcb_valbm_set(uint8_t *, int); +int ghcb_valbm_isset(uint8_t *, int); +int ghcb_verify_bm(uint8_t *, uint8_t *); +int ghcb_valid(struct ghcb_sa *); + +void ghcb_sync_val(int, int, struct ghcb_sync *); +void ghcb_sync_out(struct trapframe *, const struct ghcb_extra_regs *, + struct ghcb_sa *, struct ghcb_sync *); +void ghcb_sync_in(struct trapframe *, struct ghcb_extra_regs *, + struct ghcb_sa *, struct ghcb_sync *); +void _ghcb_mem_rw(vaddr_t, int, void *, bool); +void _ghcb_io_rw(uint16_t, int, uint32_t *, bool); + +static inline uint8_t +ghcb_mem_read_1(vaddr_t addr) +{ + uint8_t val; + + _ghcb_mem_rw(addr, GHCB_SZ8, &val, true); + return val; +} + +static inline uint16_t +ghcb_mem_read_2(vaddr_t addr) +{ + uint16_t val; + + _ghcb_mem_rw(addr, GHCB_SZ16, &val, true); + return val; +} + +static inline uint32_t +ghcb_mem_read_4(vaddr_t addr) +{ + uint32_t val; + + _ghcb_mem_rw(addr, GHCB_SZ32, &val, true); + return val; +} + +static inline uint64_t +ghcb_mem_read_8(vaddr_t addr) +{ + uint64_t val; + + _ghcb_mem_rw(addr, GHCB_SZ64, &val, true); + return val; +} + +static inline void +ghcb_mem_write_1(vaddr_t addr, uint8_t v) +{ + _ghcb_mem_rw(addr, GHCB_SZ8, &v, false); +} + +static inline void +ghcb_mem_write_2(vaddr_t addr, uint16_t v) +{ + _ghcb_mem_rw(addr, GHCB_SZ16, &v, false); +} + +static inline void +ghcb_mem_write_4(vaddr_t addr, uint32_t v) +{ + _ghcb_mem_rw(addr, GHCB_SZ32, &v, false); +} + +static inline void +ghcb_mem_write_8(vaddr_t addr, uint64_t v) +{ + _ghcb_mem_rw(addr, GHCB_SZ64, &v, false); +} + +static inline uint8_t +ghcb_io_read_1(uint16_t port) +{ + uint32_t val; + + _ghcb_io_rw(port, GHCB_SZ8, &val, true); + return val; +} + +static inline uint16_t +ghcb_io_read_2(uint16_t port) +{ + uint32_t val; + + _ghcb_io_rw(port, GHCB_SZ16, &val, true); + return val; +} + +static inline uint32_t +ghcb_io_read_4(uint16_t port) +{ + uint32_t val; + + _ghcb_io_rw(port, GHCB_SZ32, &val, true); + return val; +} + +static inline void +ghcb_io_write_1(uint16_t port, uint8_t v) +{ + uint32_t val = v; + + _ghcb_io_rw(port, GHCB_SZ8, &val, false); +} + +static inline void +ghcb_io_write_2(uint16_t port, uint16_t v) +{ + uint32_t val = v; + + _ghcb_io_rw(port, GHCB_SZ16, &val, false); +} + +static inline void +ghcb_io_write_4(uint16_t port, uint32_t v) +{ + _ghcb_io_rw(port, GHCB_SZ32, &v, false); +} + +#endif /* !_LOCORE */ + +#endif /* !_MACHINE_GHCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/hibernate.h b/lib/libc/include/x86_64-openbsd-none/amd64/hibernate.h new file mode 100644 index 0000000000..09f2c2bbe8 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/hibernate.h @@ -0,0 +1,36 @@ +/* $OpenBSD: hibernate.h,v 1.7 2018/06/21 07:33:30 mlarkin Exp $ */ + +/* + * Copyright (c) 2011 Mike Larkin + * + * 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 + +/* amd64 hibernate support structures and functions */ + +int get_hibernate_info_md(union hibernate_info *); +void hibernate_flush(void); +void hibernate_enter_resume_mapping(vaddr_t, paddr_t, int); +int hibernate_inflate_skip(union hibernate_info *, paddr_t); +int hibernate_suspend(void); +void hibernate_switch_stack_machdep(void); +void hibernate_resume_machdep(vaddr_t); +void hibernate_activate_resume_pt_machdep(void); +void hibernate_enable_intr_machdep(void); +void hibernate_disable_intr_machdep(void); +#ifdef MULTIPROCESSOR +void hibernate_quiesce_cpus(void); +void hibernate_drop_to_real_mode(void); +#endif /* MULTIPROCESSOR */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/hibernate_var.h b/lib/libc/include/x86_64-openbsd-none/amd64/hibernate_var.h new file mode 100644 index 0000000000..f65025fe94 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/hibernate_var.h @@ -0,0 +1,75 @@ +/* $OpenBSD: hibernate_var.h,v 1.14 2025/09/13 13:43:47 mlarkin Exp $ */ + +/* + * Copyright (c) 2011 Mike Larkin + * + * 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 PIGLET_PAGE_MASK (L2_FRAME) + +/* + * PML4 table for resume + */ +#define HIBERNATE_PML4T (PAGE_SIZE * 21) + +/* + * amd64 uses a PDPT to map the first 512GB phys mem plus one more + * to map any ranges of phys mem past 512GB (if needed) + */ +#define HIBERNATE_PDPT_LOW (PAGE_SIZE * 22) +#define HIBERNATE_PDPT_HI (PAGE_SIZE * 23) + +/* + * amd64 uses one PD to map the first 1GB phys mem plus one more to map any + * other 1GB ranges within the first 512GB phys, plus one more to map any + * 1GB range in any subsequent 512GB range + */ +#define HIBERNATE_PD_LOW (PAGE_SIZE * 24) +#define HIBERNATE_PD_LOW2 (PAGE_SIZE * 25) +#define HIBERNATE_PD_HI (PAGE_SIZE * 26) + +/* + * amd64 uses one PT to map the first 2MB phys mem plus one more to map any + * other 2MB range within the first 1GB, plus one more to map any 2MB range + * in any subsequent 512GB range. + */ +#define HIBERNATE_PT_LOW (PAGE_SIZE * 27) +#define HIBERNATE_PT_LOW2 (PAGE_SIZE * 28) +#define HIBERNATE_PT_HI (PAGE_SIZE * 29) + +/* 3 pages for stack */ +#define HIBERNATE_STACK_PAGE (PAGE_SIZE * 32) + +#define HIBERNATE_INFLATE_PAGE (PAGE_SIZE * 33) +/* HIBERNATE_HIBALLOC_PAGE must be the last stolen page (see machdep.c) */ +#define HIBERNATE_HIBALLOC_PAGE (PAGE_SIZE * 34) + +/* Use 4MB hibernation chunks */ +#define HIBERNATE_CHUNK_SIZE 0x400000 + +#define HIBERNATE_CHUNK_TABLE_SIZE 0x200000 + +#define HIBERNATE_STACK_OFFSET 0x0F00 + +/* + * Minimum amount of memory for hibernate support. This is used in early boot + * when deciding if we can preallocate the piglet. If the machine does not + * have at least HIBERNATE_MIN_MEMORY RAM, we won't support hibernate. This + * avoids late allocation issues due to fragmented memory and failure to + * hibernate. We need to be able to allocate 16MB contiguous memory, aligned + * to 2MB. + * + * The default minimum required memory is 512MB (1ULL << 29). + */ +#define HIBERNATE_MIN_MEMORY (1ULL << 29) \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/i82093reg.h b/lib/libc/include/x86_64-openbsd-none/amd64/i82093reg.h new file mode 100644 index 0000000000..c5b341fb94 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/i82093reg.h @@ -0,0 +1,135 @@ +/* $OpenBSD: i82093reg.h,v 1.9 2025/09/05 16:57:48 kettenis Exp $ */ +/* $NetBSD: i82093reg.h,v 1.1 2003/02/26 21:26:10 fvdl Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by RedBack Networks Inc. + * + * Author: Bill Sommerfeld + * + * 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. + */ + +/* + * Typically, the first apic lives here. + */ +#define IOAPIC_BASE_DEFAULT 0xfec00000 + +/* + * Memory-space registers. + */ + +/* + * The externally visible registers are all 32 bits wide; + * store the register number of interest in IOAPIC_REG, and store/fetch + * the real value in IOAPIC_DATA. + */ +#define IOAPIC_REG 0x0000 +#define IOAPIC_DATA 0x0010 + +/* + * Internal I/O APIC registers. + */ + +#define IOAPIC_ID 0x00 + +#define IOAPIC_ID_SHIFT 24 +#define IOAPIC_ID_MASK 0x0f000000 + +/* Version, and maximum interrupt pin number. */ + +#define IOAPIC_VER 0x01 + +#define IOAPIC_VER_SHIFT 0 +#define IOAPIC_VER_MASK 0x000000ff + +#define IOAPIC_MAX_SHIFT 16 +#define IOAPIC_MAX_MASK 0x00ff0000 + +/* + * Arbitration ID. Same format as IOAPIC_ID register. + */ +#define IOAPIC_ARB 0x02 + +/* + * Redirection table registers. + */ + +#define IOAPIC_REDHI(pin) (0x11 + ((pin)<<1)) +#define IOAPIC_REDLO(pin) (0x10 + ((pin)<<1)) + +#define IOAPIC_REDHI_DEST_SHIFT 24 /* destination. */ +#define IOAPIC_REDHI_DEST_MASK 0xff000000 + +#define IOAPIC_REDLO_MASK 0x00010000 /* 0=enabled; 1=masked */ + +#define IOAPIC_REDLO_LEVEL 0x00008000 /* 0=edge, 1=level */ +#define IOAPIC_REDLO_RIRR 0x00004000 /* remote IRR; read only */ +#define IOAPIC_REDLO_ACTLO 0x00002000 /* 0=act. hi; 1=act. lo */ +#define IOAPIC_REDLO_DELSTS 0x00001000 /* 0=idle; 1=send pending */ +#define IOAPIC_REDLO_DSTMOD 0x00000800 /* 0=physical; 1=logical */ + +#define IOAPIC_REDLO_DEL_MASK 0x00000700 /* del. mode mask */ +#define IOAPIC_REDLO_DEL_SHIFT 8 + +#define IOAPIC_REDLO_DEL_FIXED 0 +#define IOAPIC_REDLO_DEL_LOPRI 1 +#define IOAPIC_REDLO_DEL_SMI 2 +#define IOAPIC_REDLO_DEL_NMI 4 +#define IOAPIC_REDLO_DEL_INIT 5 +#define IOAPIC_REDLO_DEL_EXTINT 7 + +#define IOAPIC_REDLO_VECTOR_MASK 0x000000ff /* delivery vector */ + +#define IMCR_ADDR 0x22 +#define IMCR_DATA 0x23 + +#define IMCR_REGISTER 0x70 +#define IMCR_PIC 0x00 +#define IMCR_APIC 0x01 + +#ifdef _KERNEL + +#include + +#define ioapic_asm_ack(num) \ + CODEPATCH_START ;\ + movl $0,(local_apic+LAPIC_EOI)(%rip) ;\ + CODEPATCH_END(CPTAG_EOI) + +#define ioapic_mask(num) \ + movq IS_PIC(%r14),%rdi ;\ + movl IS_PIN(%r14),%esi ;\ + call ioapic_hwmask + +#define ioapic_unmask(num) \ + cmpq $IREENT_MAGIC,IF_ERR(%rsp) ;\ + jne 79f ;\ + movq IS_PIC(%r14),%rdi ;\ + movl IS_PIN(%r14),%esi ;\ + call ioapic_hwunmask ;\ +79: + +#endif \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/i82093var.h b/lib/libc/include/x86_64-openbsd-none/amd64/i82093var.h new file mode 100644 index 0000000000..1124b33cc7 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/i82093var.h @@ -0,0 +1,92 @@ +/* $OpenBSD: i82093var.h,v 1.8 2025/09/05 16:57:48 kettenis Exp $ */ +/* $NetBSD: i82093var.h,v 1.1 2003/02/26 21:26:10 fvdl Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by RedBack Networks Inc. + * + * Author: Bill Sommerfeld + * + * 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_I82093VAR_H_ +#define _MACHINE_I82093VAR_H_ + +#include + +struct ioapic_pin { + struct ioapic_pin *ip_next; /* next pin on this vector */ + struct mp_intr_map *ip_map; + int ip_vector; /* IDT vector */ + int ip_type; + struct cpu_info *ip_cpu; /* target CPU */ +}; + +struct ioapic_softc { + struct pic sc_pic; + struct ioapic_softc *sc_next; + int sc_apicid; + int sc_apic_vers; + int sc_apic_vecbase; /* global int base if ACPI */ + int sc_apic_sz; /* apic size*/ + int sc_flags; + bus_space_tag_t sc_memt; + bus_space_handle_t sc_memh; + struct ioapic_pin *sc_pins; /* sc_apic_sz entries */ +}; + +/* + * MP: intr_handle_t is bitfielded. + * ih&0xff -> legacy irq number. + * ih&0x10000000 -> if 0, old-style isa irq; if 1, routed via ioapic. + * (ih&0xff0000)>>16 -> ioapic id. + * (ih&0x00ff00)>>8 -> ioapic pin. + */ + +#define APIC_INT_VIA_APIC 0x10000000 +#define APIC_INT_VIA_MSG 0x20000000 +#define APIC_INT_VIA_MSGX 0x40000000 +#define APIC_INT_APIC_MASK 0x00ff0000 +#define APIC_INT_APIC_SHIFT 16 +#define APIC_INT_PIN_MASK 0x0000ff00 +#define APIC_INT_PIN_SHIFT 8 + +#define APIC_IRQ_APIC(x) ((x & APIC_INT_APIC_MASK) >> APIC_INT_APIC_SHIFT) +#define APIC_IRQ_PIN(x) ((x & APIC_INT_PIN_MASK) >> APIC_INT_PIN_SHIFT) +#define APIC_IRQ_ISLEGACY(x) (!((x) & APIC_INT_VIA_APIC)) +#define APIC_IRQ_LEGACY_IRQ(x) ((x) & 0xff) + +void ioapic_print_redir(struct ioapic_softc *, char *, int); +struct ioapic_softc *ioapic_find(int); +struct ioapic_softc *ioapic_find_bybase(int); + +void ioapic_enable(void); + +extern int ioapic_bsp_id; +extern int nioapics; +extern struct ioapic_softc *ioapics; + +#endif /* !_MACHINE_I82093VAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/i82489reg.h b/lib/libc/include/x86_64-openbsd-none/amd64/i82489reg.h new file mode 100644 index 0000000000..788c516ac7 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/i82489reg.h @@ -0,0 +1,149 @@ +/* $OpenBSD: i82489reg.h,v 1.5 2019/07/26 04:35:38 kevlo Exp $ */ +/* $NetBSD: i82489reg.h,v 1.1 2003/02/26 21:26:10 fvdl Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Frank van der Linden. + * + * 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. + */ + + +/* + * Registers and constants for the 82489DX and Pentium (and up) integrated + * "local" APIC. + */ + +#define LAPIC_ID 0x020 /* ID. RW */ +# define LAPIC_ID_MASK 0x0f000000 +# define LAPIC_ID_SHIFT 24 + +#define LAPIC_VERS 0x030 /* Version. R */ +# define LAPIC_VERSION_MASK 0x000000ff +# define LAPIC_VERSION_LVT_MASK 0x00ff0000 +# define LAPIC_VERSION_LVT_SHIFT 16 + +#define LAPIC_TPRI 0x080 /* Task Prio. RW */ +# define LAPIC_TPRI_MASK 0x000000ff +# define LAPIC_TPRI_INT_MASK 0x000000f0 +# define LAPIC_TPRI_SUB_MASK 0x0000000f + +#define LAPIC_APRI 0x090 /* Arbitration prio R */ +# define LAPIC_APRI_MASK 0x000000ff + +#define LAPIC_PPRI 0x0a0 /* Processor prio. R */ +#define LAPIC_EOI 0x0b0 /* End Int. W */ +#define LAPIC_RRR 0x0c0 /* Remote read R */ +#define LAPIC_LDR 0x0d0 /* Logical dest. RW */ +#define LAPIC_DFR 0x0e0 /* Dest. format RW */ + +#define LAPIC_SVR 0x0f0 /* Spurious intvec RW */ +# define LAPIC_SVR_VECTOR_MASK 0x000000ff +# define LAPIC_SVR_VEC_FIX 0x0000000f +# define LAPIC_SVR_VEC_PROG 0x000000f0 +# define LAPIC_SVR_ENABLE 0x00000100 +# define LAPIC_SVR_SWEN 0x00000100 +# define LAPIC_SVR_FOCUS 0x00000200 +# define LAPIC_SVR_FDIS 0x00000200 + +#define LAPIC_ISR 0x100 /* Int. status. R */ +#define LAPIC_TMR 0x180 +#define LAPIC_IRR 0x200 +#define LAPIC_ESR 0x280 /* Err status. R */ + +#define LAPIC_ICRLO 0x300 /* Int. cmd. RW */ +# define LAPIC_DLMODE_MASK 0x00000700 +# define LAPIC_DLMODE_FIXED 0x00000000 +# define LAPIC_DLMODE_LOW 0x00000100 +# define LAPIC_DLMODE_SMI 0x00000200 +# define LAPIC_DLMODE_RR 0x00000300 +# define LAPIC_DLMODE_NMI 0x00000400 +# define LAPIC_DLMODE_INIT 0x00000500 +# define LAPIC_DLMODE_STARTUP 0x00000600 + +# define LAPIC_DSTMODE_LOG 0x00000800 + +# define LAPIC_DLSTAT_BUSY 0x00001000 + +# define LAPIC_LVL_ASSERT 0x00004000 +# define LAPIC_LVL_DEASSERT 0x00000000 + +# define LAPIC_LVL_TRIG 0x00008000 + +# define LAPIC_RRSTAT_MASK 0x00030000 +# define LAPIC_RRSTAT_INPROG 0x00010000 +# define LAPIC_RRSTAT_VALID 0x00020000 + +# define LAPIC_DEST_MASK 0x000c0000 +# define LAPIC_DEST_SELF 0x00040000 +# define LAPIC_DEST_ALLINCL 0x00080000 +# define LAPIC_DEST_ALLEXCL 0x000c0000 + +# define LAPIC_RESV2_MASK 0xfff00000 + + +#define LAPIC_ICRHI 0x310 /* Int. cmd. RW */ + +#define LAPIC_LVTT 0x320 /* Loc.vec.(timer) RW */ +# define LAPIC_LVTT_VEC_MASK 0x000000ff +# define LAPIC_LVTT_DS 0x00001000 +# define LAPIC_LVTT_M 0x00010000 +# define LAPIC_LVTT_TM 0x00020000 +# define LAPIC_LVTT_TM_ONESHOT 0x00000000 +# define LAPIC_LVTT_TM_PERIODIC 0x00020000 +# define LAPIC_LVTT_TM_TSCDL 0x00040000 + +#define LAPIC_PCINT 0x340 +#define LAPIC_LVINT0 0x350 /* Loc.vec (LINT0) RW */ +# define LAPIC_LVT_PERIODIC 0x00020000 +# define LAPIC_LVT_MASKED 0x00010000 +# define LAPIC_LVT_LEVTRIG 0x00008000 +# define LAPIC_LVT_REMOTE_IRR 0x00004000 +# define LAPIC_INP_POL 0x00002000 +# define LAPIC_PEND_SEND 0x00001000 + +#define LAPIC_LVINT1 0x360 /* Loc.vec (LINT1) RW */ +#define LAPIC_LVERR 0x370 /* Loc.vec (ERROR) RW */ +#define LAPIC_ICR_TIMER 0x380 /* Initial count RW */ +#define LAPIC_CCR_TIMER 0x390 /* Current count RO */ + +#define LAPIC_DCR_TIMER 0x3e0 /* Divisor config register */ +# define LAPIC_DCRT_DIV1 0x0b +# define LAPIC_DCRT_DIV2 0x00 +# define LAPIC_DCRT_DIV4 0x01 +# define LAPIC_DCRT_DIV8 0x02 +# define LAPIC_DCRT_DIV16 0x03 +# define LAPIC_DCRT_DIV32 0x08 +# define LAPIC_DCRT_DIV64 0x09 +# define LAPIC_DCRT_DIV128 0x0a + +#define LAPIC_BASE 0xfee00000 + +#define LAPIC_IRQ_MASK(i) (1 << ((i) + 1)) + +#define MSR_X2APIC_BASE 0x800 +#define MSR_X2APIC_EOI (MSR_X2APIC_BASE+0x0b) /* End Int. W */ +#define MSR_X2APIC_ID (MSR_X2APIC_BASE+0x02) /* ID. RW */ +#define X2APIC_ID_MASK 0xff \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/i82489var.h b/lib/libc/include/x86_64-openbsd-none/amd64/i82489var.h new file mode 100644 index 0000000000..4477a13266 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/i82489var.h @@ -0,0 +1,124 @@ +/* $OpenBSD: i82489var.h,v 1.21 2024/11/07 17:24:42 bluhm Exp $ */ +/* $NetBSD: i82489var.h,v 1.1 2003/02/26 21:26:10 fvdl Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Frank van der Linden. + * + * 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_I82489VAR_H_ +#define _MACHINE_I82489VAR_H_ + +#include "vmm.h" + +/* + * Software definitions belonging to Local APIC driver. + */ + +#ifdef _KERNEL +extern volatile u_int32_t local_apic[]; +extern volatile u_int32_t lapic_tpr; +#endif + +extern u_int32_t (*lapic_readreg)(int); +extern void (*lapic_writereg)(int, u_int32_t); +u_int32_t lapic_cpu_number(void); + +/* + * "spurious interrupt vector"; vector used by interrupt which was + * aborted because the CPU masked it after it happened but before it + * was delivered.. "Oh, sorry, i caught you at a bad time". + * Low-order 4 bits must be all ones. + */ +extern void Xintrspurious(void); +#define LAPIC_SPURIOUS_VECTOR 0xef + +/* + * Vector used for inter-processor interrupts. + */ +extern void Xintr_lapic_ipi(void); +extern void Xrecurse_lapic_ipi(void); +extern void Xresume_lapic_ipi(void); +#define LAPIC_IPI_VECTOR 0xe0 + +/* + * We take 0xf0-0xfe for fast IPI handlers. + */ +#define LAPIC_IPI_OFFSET 0xf0 +#define LAPIC_IPI_INVLTLB (LAPIC_IPI_OFFSET + 0) +#define LAPIC_IPI_INVLPG (LAPIC_IPI_OFFSET + 1) +#define LAPIC_IPI_INVLRANGE (LAPIC_IPI_OFFSET + 2) +#define LAPIC_IPI_WBINVD (LAPIC_IPI_OFFSET + 3) +#define LAPIC_IPI_INVEPT (LAPIC_IPI_OFFSET + 4) + +extern void Xipi_invltlb(void); +extern void Xipi_invltlb_pcid(void); +extern void Xipi_invlpg(void); +extern void Xipi_invlpg_pcid(void); +extern void Xipi_invlrange(void); +extern void Xipi_invlrange_pcid(void); +extern void Xipi_wbinvd(void); +#if NVMM > 0 +extern void Xipi_invept(void); +#endif /* NVMM > 0 */ + +/* + * Vector used for local apic timer interrupts. + */ + +extern void Xintr_lapic_ltimer(void); +extern void Xresume_lapic_ltimer(void); +extern void Xrecurse_lapic_ltimer(void); +#define LAPIC_TIMER_VECTOR 0xc0 + +/* + * Vector used for Xen HVM Event Channel Interrupts. + */ +extern void Xintr_xen_upcall(void); +extern void Xresume_xen_upcall(void); +extern void Xrecurse_xen_upcall(void); +#define LAPIC_XEN_VECTOR 0x70 + +/* + * Vector used for Hyper-V Interrupts. + */ +extern void Xintr_hyperv_upcall(void); +extern void Xresume_hyperv_upcall(void); +extern void Xrecurse_hyperv_upcall(void); +#define LAPIC_HYPERV_VECTOR 0x71 + +struct cpu_info; + +extern void lapic_boot_init(paddr_t); +extern void lapic_set_lvt(void); +extern void lapic_enable(void); +extern void lapic_disable(void); +extern void lapic_calibrate_timer(struct cpu_info *ci); +extern void lapic_startclock(void); +extern void lapic_initclocks(void); + +#endif \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/i8259.h b/lib/libc/include/x86_64-openbsd-none/amd64/i8259.h new file mode 100644 index 0000000000..28bdcd4743 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/i8259.h @@ -0,0 +1,144 @@ +/* $OpenBSD: i8259.h,v 1.4 2015/09/02 13:39:23 mikeb Exp $ */ +/* $NetBSD: i8259.h,v 1.3 2003/05/04 22:01:56 fvdl 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. + * + * @(#)icu.h 5.6 (Berkeley) 5/9/91 + */ + +#ifndef _MACHINE_I8259_H_ +#define _MACHINE_I8259_H_ + +#include + +#ifndef _LOCORE + +/* + * Interrupt "level" mechanism variables, masks, and macros + */ +extern unsigned i8259_imen; /* interrupt mask enable */ + +extern void i8259_default_setup(void); + +#endif /* !_LOCORE */ + +/* + * Interrupt enable bits -- in order of priority + */ +#define IRQ_SLAVE 2 + +/* + * Interrupt Control offset into Interrupt descriptor table (IDT) + */ +#define ICU_OFFSET 32 /* 0-31 are processor exceptions */ +#define ICU_LEN 16 /* 32-47 are ISA interrupts */ + + +#define ICU_HARDWARE_MASK + +/* + * These macros are fairly self explanatory. If ICU_SPECIAL_MASK_MODE is + * defined, we try to take advantage of the ICU's `special mask mode' by only + * EOIing the interrupts on return. This avoids the requirement of masking and + * unmasking. We can't do this without special mask mode, because the ICU + * would also hold interrupts that it thinks are of lower priority. + * + * Many machines do not support special mask mode, so by default we don't try + * to use it. + */ + +#define IRQ_BIT(num) (1 << ((num) % 8)) +#define IRQ_BYTE(num) ((num) >> 3) + +#define i8259_late_ack(num) + +#ifdef ICU_SPECIAL_MASK_MODE + +#define i8259_asm_ack1(num) +#define i8259_asm_ack2(num) \ + movb $(0x60|IRQ_SLAVE),%al /* specific EOI for IRQ2 */ ;\ + outb %al,$IO_ICU1 +#define i8259_asm_mask(num) +#define i8259_asm_unmask(num) \ + movb $(0x60|(num%8)),%al /* specific EOI */ ;\ + outb %al,$ICUADDR + +#else /* ICU_SPECIAL_MASK_MODE */ + +#ifndef AUTO_EOI_1 +#define i8259_asm_ack1(num) \ + movb $(0x60|(num%8)),%al /* specific EOI */ ;\ + outb %al,$IO_ICU1 +#else +#define i8259_asm_ack1(num) +#endif + +#ifndef AUTO_EOI_2 +#define i8259_asm_ack2(num) \ + movb $(0x60|(num%8)),%al /* specific EOI */ ;\ + outb %al,$IO_ICU2 /* do the second ICU first */ ;\ + movb $(0x60|IRQ_SLAVE),%al /* specific EOI for IRQ2 */ ;\ + outb %al,$IO_ICU1 +#else +#define i8259_asm_ack2(num) +#endif + +#ifdef PIC_MASKDELAY +#define MASKDELAY pushl %eax ; inb $0x84,%al ; popl %eax +#else +#define MASKDELAY +#endif + +#ifdef ICU_HARDWARE_MASK + +#define i8259_asm_mask(num) \ + movb CVAROFF(i8259_imen, IRQ_BYTE(num)),%al ;\ + orb $IRQ_BIT(num),%al ;\ + movb %al,CVAROFF(i8259_imen, IRQ_BYTE(num)) ;\ + MASKDELAY ;\ + outb %al,$(ICUADDR+1) +#define i8259_asm_unmask(num) \ + movb CVAROFF(i8259_imen, IRQ_BYTE(num)),%al ;\ + andb $~IRQ_BIT(num),%al ;\ + movb %al,CVAROFF(i8259_imen, IRQ_BYTE(num)) ;\ + MASKDELAY ;\ + outb %al,$(ICUADDR+1) + +#else /* ICU_HARDWARE_MASK */ + +#define i8259_asm_mask(num) +#define i8259_asm_unmask(num) + +#endif /* ICU_HARDWARE_MASK */ +#endif /* ICU_SPECIAL_MASK_MODE */ + +#endif /* !_MACHINE_I8259_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/ieee.h b/lib/libc/include/x86_64-openbsd-none/amd64/ieee.h new file mode 100644 index 0000000000..dea4be1a6b --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/ieee.h @@ -0,0 +1,142 @@ +/* $OpenBSD: ieee.h,v 1.2 2008/09/07 20:36:06 martynas Exp $ */ +/* $NetBSD: ieee.h,v 1.1 1996/09/30 16:34:25 ws Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)ieee.h 8.1 (Berkeley) 6/11/93 + */ + +/* + * ieee.h defines the machine-dependent layout of the machine's IEEE + * floating point. It does *not* define (yet?) any of the rounding + * mode bits, exceptions, and so forth. + */ + +/* + * Define the number of bits in each fraction and exponent. + * + * k k+1 + * Note that 1.0 x 2 == 0.1 x 2 and that denorms are represented + * + * (-exp_bias+1) + * as fractions that look like 0.fffff x 2 . This means that + * + * -126 + * the number 0.10000 x 2 , for instance, is the same as the normalized + * + * -127 -128 + * float 1.0 x 2 . Thus, to represent 2 , we need one leading zero + * + * -129 + * in the fraction; to represent 2 , we need two, and so on. This + * + * (-exp_bias-fracbits+1) + * implies that the smallest denormalized number is 2 + * + * for whichever format we are talking about: for single precision, for + * + * -126 -149 + * instance, we get .00000000000000000000001 x 2 , or 1.0 x 2 , and + * + * -149 == -127 - 23 + 1. + */ +#define SNG_EXPBITS 8 +#define SNG_FRACBITS 23 + +#define DBL_EXPBITS 11 +#define DBL_FRACHBITS 20 +#define DBL_FRACLBITS 32 +#define DBL_FRACBITS 52 + +#define EXT_EXPBITS 15 +#define EXT_FRACHBITS 32 +#define EXT_FRACLBITS 32 +#define EXT_FRACBITS 64 + +#define EXT_TO_ARRAY32(p, a) do { \ + (a)[0] = (uint32_t)(p)->ext_fracl; \ + (a)[1] = (uint32_t)(p)->ext_frach; \ +} while(0) + +struct ieee_single { + u_int sng_frac:23; + u_int sng_exp:8; + u_int sng_sign:1; +}; + +struct ieee_double { + u_int dbl_fracl; + u_int dbl_frach:20; + u_int dbl_exp:11; + u_int dbl_sign:1; +}; + +struct ieee_ext { + u_int ext_fracl; + u_int ext_frach; + u_int ext_exp:15; + u_int ext_sign:1; + u_int ext_padl:16; + u_int ext_padh; +}; + +/* + * Floats whose exponent is in [1..INFNAN) (of whatever type) are + * `normal'. Floats whose exponent is INFNAN are either Inf or NaN. + * Floats whose exponent is zero are either zero (iff all fraction + * bits are zero) or subnormal values. + * + * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its + * high fraction; if the bit is set, it is a `quiet NaN'. + */ +#define SNG_EXP_INFNAN 255 +#define DBL_EXP_INFNAN 2047 +#define EXT_EXP_INFNAN 32767 + +#if 0 +#define SNG_QUIETNAN (1 << 22) +#define DBL_QUIETNAN (1 << 19) +#define EXT_QUIETNAN (1 << 15) +#endif + +/* + * Exponent biases. + */ +#define SNG_EXP_BIAS 127 +#define DBL_EXP_BIAS 1023 +#define EXT_EXP_BIAS 16383 \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/ieeefp.h b/lib/libc/include/x86_64-openbsd-none/amd64/ieeefp.h new file mode 100644 index 0000000000..510fd8e157 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/ieeefp.h @@ -0,0 +1,26 @@ +/* $OpenBSD: ieeefp.h,v 1.2 2011/03/23 16:54:34 pirofti Exp $ */ + +/* + * Written by J.T. Conklin, Apr 6, 1995 + * Public domain. + */ + +#ifndef _MACHINE_IEEEFP_H_ +#define _MACHINE_IEEEFP_H_ + +typedef int fp_except; +#define FP_X_INV 0x01 /* invalid operation exception */ +#define FP_X_DNML 0x02 /* denormalization exception */ +#define FP_X_DZ 0x04 /* divide-by-zero exception */ +#define FP_X_OFL 0x08 /* overflow exception */ +#define FP_X_UFL 0x10 /* underflow exception */ +#define FP_X_IMP 0x20 /* imprecise (loss of precision) */ + +typedef enum { + FP_RN=0, /* round to nearest representable number */ + FP_RM=1, /* round toward negative infinity */ + FP_RP=2, /* round toward positive infinity */ + FP_RZ=3 /* round to zero (truncate) */ +} fp_rnd; + +#endif /* _MACHINE_IEEEFP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/intr.h b/lib/libc/include/x86_64-openbsd-none/amd64/intr.h new file mode 100644 index 0000000000..ca5fda2141 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/intr.h @@ -0,0 +1,229 @@ +/* $OpenBSD: intr.h,v 1.36 2025/06/11 09:57:01 kettenis Exp $ */ +/* $NetBSD: intr.h,v 1.2 2003/05/04 22:01:56 fvdl 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_INTR_H_ +#define _MACHINE_INTR_H_ + +#define __USE_MI_SOFTINTR + +#include +#include + +#ifndef _LOCORE +#include + +#include + +/* + * Struct describing an interrupt source for a CPU. struct cpu_info + * has an array of MAX_INTR_SOURCES of these. The index in the array + * is equal to the stub number of the stubcode as present in vector.s + * + * The primary CPU's array of interrupt sources has its first 16 + * entries reserved for legacy ISA irq handlers. This means that + * they have a 1:1 mapping for arrayindex:irq_num. This is not + * true for interrupts that come in through IO APICs, to find + * their source, go through ci->ci_isources[index].is_pic + * + * It's possible to always maintain a 1:1 mapping, but that means + * limiting the total number of interrupt sources to MAX_INTR_SOURCES + * (32), instead of 32 per CPU. It also would mean that having multiple + * IO APICs which deliver interrupts from an equal pin number would + * overlap if they were to be sent to the same CPU. + */ + +struct intrstub { + void *ist_entry; + void *ist_recurse; + void *ist_resume; +}; + +struct intrsource { + int is_maxlevel; /* max. IPL for this source */ + int is_pin; /* IRQ for legacy; pin for IO APIC */ + struct intrhand *is_handlers; /* handler chain */ + struct pic *is_pic; /* originating PIC */ + void *is_recurse; /* entry for spllower */ + void *is_resume; /* entry for doreti */ + char is_evname[32]; /* event counter name */ + int is_flags; /* see below */ + int is_type; /* level, edge */ + int is_idtvec; + int is_minlevel; +}; + +#define IS_LEGACY 0x0001 /* legacy ISA irq source */ +#define IS_IPI 0x0002 +#define IS_LOG 0x0004 + + +/* + * Interrupt handler chains. *_intr_establish() insert a handler into + * the list. The handler is called with its (single) argument. + */ + +struct intrhand { + int (*ih_fun)(void *); + void *ih_arg; + int ih_level; + int ih_flags; + struct intrhand *ih_next; + int ih_pin; + int ih_slot; + struct cpu_info *ih_cpu; + int ih_irq; + struct evcount ih_count; +}; + +#define IMASK(ci,level) (ci)->ci_imask[(level)] +#define IUNMASK(ci,level) (ci)->ci_iunmask[(level)] + +extern void Xspllower(int); + +int splraise(int); +int spllower(int); +void softintr(int); +void dosoftint(int); + +/* + * Convert spl level to local APIC level + */ +#define APIC_LEVEL(l) ((l) << 4) + +/* + * compiler barrier: prevent reordering of instructions. + * This prevents the compiler from reordering code around + * this "instruction", acting as a sequence point for code generation. + */ + +#define __splbarrier() __asm volatile("":::"memory") + +/* + * Hardware interrupt masks + */ +#define splbio() splraise(IPL_BIO) +#define splnet() splraise(IPL_NET) +#define spltty() splraise(IPL_TTY) +#define splaudio() splraise(IPL_AUDIO) +#define splclock() splraise(IPL_CLOCK) +#define splstatclock() splclock() +#define splipi() splraise(IPL_IPI) + +/* + * Software interrupt masks + */ +#define splsoftclock() splraise(IPL_SOFTCLOCK) +#define splsoftnet() splraise(IPL_SOFTNET) +#define splsofttty() splraise(IPL_SOFTTTY) + +/* + * Miscellaneous + */ +#define splvm() splraise(IPL_VM) +#define splhigh() splraise(IPL_HIGH) +#define spl0() spllower(IPL_NONE) +#define splsched() splraise(IPL_SCHED) +#define splx(x) spllower(x) + +/* SPL asserts */ +#ifdef DIAGNOSTIC +/* + * Although this function is implemented in MI code, it must be in this MD + * header because we don't want this header to include MI includes. + */ +void splassert_fail(int, int, const char *); +extern int splassert_ctl; +void splassert_check(int, const char *); +#define splassert(__wantipl) do { \ + if (splassert_ctl > 0) { \ + splassert_check(__wantipl, __func__); \ + } \ +} while (0) +#define splsoftassert(wantipl) splassert(wantipl) +#else +#define splassert(wantipl) do { /* nada */ } while (0) +#define splsoftassert(wantipl) do { /* nada */ } while (0) +#endif + +#define IPLSHIFT 4 /* The upper nibble of vectors is the IPL. */ +#define IPL(level) ((level) >> IPLSHIFT) /* Extract the IPL. */ + +#include + +/* + * Stub declarations. + */ + +extern void Xsoftclock(void); +extern void Xsoftnet(void); +extern void Xsofttty(void); + +extern struct intrstub i8259_stubs[]; +extern struct intrstub ioapic_edge_stubs[]; +extern struct intrstub ioapic_level_stubs[]; + +struct cpu_info; + +extern int intr_shared_edge; + +extern char idt_allocmap[]; + +void intr_default_setup(void); +int x86_nmi(void); +void intr_calculatemasks(struct cpu_info *); +int intr_allocate_slot_cpu(struct cpu_info *, struct pic *, int, int *); +int intr_allocate_slot(struct pic *, int, int, int, struct cpu_info **, int *, + int *); +void *intr_establish(int, struct pic *, int, int, int, + struct cpu_info *, int (*)(void *), void *, const char *); +void intr_disestablish(struct intrhand *); +int intr_handler(struct intrframe *, struct intrhand *); +void cpu_intr_init(struct cpu_info *); +void intr_printconfig(void); +void intr_barrier(void *); +void intr_set_wakeup(void *); +void intr_enable_wakeup(void); +void intr_disable_wakeup(void); + +#ifdef MULTIPROCESSOR +void x86_send_ipi(struct cpu_info *, int); +int x86_fast_ipi(struct cpu_info *, int); +void x86_broadcast_ipi(int); +void x86_ipi_handler(void); +void x86_setperf_ipi(struct cpu_info *); + +extern void (*ipifunc[X86_NIPI])(struct cpu_info *); +#endif + +#endif /* !_LOCORE */ + +#endif /* !_MACHINE_INTR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/intrdefs.h b/lib/libc/include/x86_64-openbsd-none/amd64/intrdefs.h new file mode 100644 index 0000000000..54fe1358ca --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/intrdefs.h @@ -0,0 +1,93 @@ +/* $OpenBSD: intrdefs.h,v 1.24 2024/05/26 13:37:31 kettenis Exp $ */ +/* $NetBSD: intrdefs.h,v 1.2 2003/05/04 22:01:56 fvdl Exp $ */ + +#ifndef _AMD64_INTRDEFS_H +#define _AMD64_INTRDEFS_H + +/* + * Interrupt priority levels. + * + * There are tty, network and disk drivers that use free() at interrupt + * time, so imp > (tty | net | bio). + * + * Since run queues may be manipulated by both the statclock and tty, + * network, and disk drivers, clock > imp. + * + * IPL_HIGH must block everything that can manipulate a run queue. + * + * The level numbers are picked to fit into APIC vector priorities. + * + */ +#define IPL_NONE 0x0 /* nothing */ +#define IPL_SOFTCLOCK 0x1 /* timeouts */ +#define IPL_SOFTNET 0x2 /* protocol stacks */ +#define IPL_BIO 0x3 /* block I/O */ +#define IPL_NET 0x4 /* network */ +#define IPL_SOFTTTY 0x8 /* delayed terminal handling */ +#define IPL_TTY 0x9 /* terminal */ +#define IPL_VM 0xa /* memory allocation */ +#define IPL_AUDIO 0xb /* audio */ +#define IPL_CLOCK 0xc /* clock */ +#define IPL_SCHED IPL_CLOCK +#define IPL_STATCLOCK IPL_CLOCK +#define IPL_HIGH 0xd /* everything */ +#define IPL_IPI 0xe /* inter-processor interrupts */ +#define NIPL 16 + +#define IPL_MPFLOOR IPL_TTY +#define IPL_MPSAFE 0x100 +#define IPL_WAKEUP 0x200 + +/* Interrupt sharing types. */ +#define IST_NONE 0 /* none */ +#define IST_PULSE 1 /* pulsed */ +#define IST_EDGE 2 /* edge-triggered */ +#define IST_LEVEL 3 /* level-triggered */ + +/* + * Local APIC masks. Must not conflict with SIR_* above, and must + * be >= NUM_LEGACY_IRQs. Note that LIR_IPI must be first. + */ +#define LIR_IPI 63 +#define LIR_TIMER 62 + +/* Soft interrupt masks. */ +#define SIR_CLOCK 61 +#define SIR_NET 60 +#define SIR_TTY 59 + +#define LIR_XEN 58 +#define LIR_HYPERV 57 + +/* + * Maximum # of interrupt sources per CPU. 64 to fit in one word. + * ioapics can theoretically produce more, but it's not likely to + * happen. For multiple ioapics, things can be routed to different + * CPUs. + */ +#define MAX_INTR_SOURCES 64 +#define NUM_LEGACY_IRQS 16 + +/* + * Low and high boundaries between which interrupt gates will + * be allocated in the IDT. + */ +#define IDT_INTR_LOW (0x20 + NUM_LEGACY_IRQS) +#define IDT_INTR_HIGH 0xef + +#define X86_IPI_HALT 0x00000001 +#define X86_IPI_NOP 0x00000002 +#define X86_IPI_VMCLEAR_VMM 0x00000004 +#define X86_IPI_PCTR 0x00000010 +#define X86_IPI_MTRR 0x00000020 +#define X86_IPI_SETPERF 0x00000040 +#define X86_IPI_DDB 0x00000080 +#define X86_IPI_START_VMM 0x00000100 +#define X86_IPI_STOP_VMM 0x00000200 +#define X86_IPI_WBINVD 0x00000400 + +#define X86_NIPI 12 + +#define IREENT_MAGIC 0x18041969 + +#endif /* _AMD64_INTRDEFS_H */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/ioctl_fd.h b/lib/libc/include/x86_64-openbsd-none/amd64/ioctl_fd.h new file mode 100644 index 0000000000..659711f9d7 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/ioctl_fd.h @@ -0,0 +1,130 @@ +/* $OpenBSD: ioctl_fd.h,v 1.2 2011/03/23 16:54:34 pirofti Exp $ */ + +/* + * Copyright (C) 1992-1994 by Joerg Wunsch, Dresden + * 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(S) ``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(S) 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: Id: ioctl_fd.h,v 1.7 1994/10/30 19:17:39 joerg Exp + */ + +#ifndef _MACHINE_IOCTL_FD_H_ +#define _MACHINE_IOCTL_FD_H_ + +#include + +#define FD_FORMAT_VERSION 110 /* used to validate before formatting */ +#define FD_MAX_NSEC 36 /* highest known number of spt - allow for */ + /* 2.88 MB drives */ + +struct fd_formb { + int format_version; /* == FD_FORMAT_VERSION */ + int cyl, head; + int transfer_rate; /* fdreg.h: FDC_???KBPS */ + + union { + struct fd_form_data { + /* + * DO NOT CHANGE THE LAYOUT OF THIS STRUCTS + * it is hardware-dependant since it exactly + * matches the byte sequence to write to FDC + * during its `format track' operation + */ + u_char secshift; /* 0 -> 128, ...; usually 2 -> 512 */ + u_char nsecs; /* must be <= FD_MAX_NSEC */ + u_char gaplen; /* GAP 3 length; usually 84 */ + u_char fillbyte; /* usually 0xf6 */ + struct fd_idfield_data { + /* + * data to write into id fields; + * for obscure formats, they mustn't match + * the real values (but mostly do) + */ + u_char cylno; /* 0 thru 79 (or 39) */ + u_char headno; /* 0, or 1 */ + u_char secno; /* starting at 1! */ + u_char secsize; /* usually 2 */ + } idfields[FD_MAX_NSEC]; /* 0 <= idx < nsecs used */ + } structured; + u_char raw[1]; /* to have continuous indexed access */ + } format_info; +}; + +/* make life easier */ +# define fd_formb_secshift format_info.structured.secshift +# define fd_formb_nsecs format_info.structured.nsecs +# define fd_formb_gaplen format_info.structured.gaplen +# define fd_formb_fillbyte format_info.structured.fillbyte +/* these data must be filled in for(i = 0; i < fd_formb_nsecs; i++) */ +# define fd_formb_cylno(i) format_info.structured.idfields[i].cylno +# define fd_formb_headno(i) format_info.structured.idfields[i].headno +# define fd_formb_secno(i) format_info.structured.idfields[i].secno +# define fd_formb_secsize(i) format_info.structured.idfields[i].secsize + +/* + * Floppies come in various flavors, e.g., 1.2MB vs 1.44MB; here is how + * we tell them apart. + */ +struct fd_type { + int sectrac; /* sectors per track */ + int heads; /* number of heads */ + int seccyl; /* sectors per cylinder */ + int secsize; /* size code for sectors */ + int datalen; /* data len when secsize = 0 */ + int steprate; /* step rate and head unload time */ + int gap1; /* gap len between sectors */ + int gap2; /* formatting gap */ + int tracks; /* total num of tracks */ + int size; /* size of disk in sectors */ + int step; /* steps per cylinder */ + int rate; /* transfer speed code */ + char *name; +}; + + +#define FD_FORM _IOW('F', 61, struct fd_formb) /* format a track */ +#define FD_GTYPE _IOR('F', 62, struct fd_type) /* get drive type */ +#define FD_STYPE _IOW('F', 63, struct fd_type) /* set drive type */ + +#define FD_GOPTS _IOR('F', 64, int) /* drive options, see below */ +#define FD_SOPTS _IOW('F', 65, int) + +#define FDOPT_NORETRY 0x0001 /* no retries on failure (cleared on close) */ + +/* + * The following definitions duplicate those in sys/i386/isa/fdreg.h + * They are here since their values are to be used in the above + * structure when formatting a floppy. For very obvious reasons, both + * definitions must match ;-) + */ +#ifndef FDC_500KBPS +#define FDC_500KBPS 0x00 /* 500KBPS MFM drive transfer rate */ +#define FDC_300KBPS 0x01 /* 300KBPS MFM drive transfer rate */ +#define FDC_250KBPS 0x02 /* 250KBPS MFM drive transfer rate */ +#define FDC_125KBPS 0x03 /* 125KBPS FM drive transfer rate */ + /* for some controllers 1MPBS instead */ +#endif /* FDC_500KBPS */ + + +#endif /* !_MACHINE_IOCTL_FD_H__ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/isa_machdep.h b/lib/libc/include/x86_64-openbsd-none/amd64/isa_machdep.h new file mode 100644 index 0000000000..3efae87c13 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/isa_machdep.h @@ -0,0 +1,163 @@ +/* $OpenBSD: isa_machdep.h,v 1.11 2024/05/22 05:51:49 jsg Exp $ */ +/* $NetBSD: isa_machdep.h,v 1.2 2003/05/09 23:51:28 fvdl Exp $ */ + +/*- + * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*- + * Copyright (c) 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. + * + * @(#)isa.h 5.7 (Berkeley) 5/9/91 + */ + +/* + * Various pieces of the i386 port want to include this file without + * or in spite of using isavar.h, and should be fixed. + */ + +#ifndef _I386_ISA_MACHDEP_H_ /* XXX */ +#define _I386_ISA_MACHDEP_H_ /* XXX */ + +#include +#include + +/* + * ISA can only DMA to 0-16M. + */ +#define ISA_DMA_BOUNCE_THRESHOLD 0x00ffffff + +/* + * XXX THIS FILE IS A MESS. copyright: berkeley's probably. + * contents from isavar.h and isareg.h, mostly the latter. + * perhaps charles's? + * + * copyright from berkeley's isa.h which is now dev/isa/isareg.h. + */ + +/* + * Types provided to machine-independent ISA code. + */ + +typedef void *isa_chipset_tag_t; + +struct device; /* XXX */ +struct isabus_attach_args; /* XXX */ + +/* + * Functions provided to machine-independent ISA code. + */ +void isa_attach_hook(struct device *, struct device *, + struct isabus_attach_args *); +int isa_intr_alloc(isa_chipset_tag_t, int, int, int *); +void *isa_intr_establish(isa_chipset_tag_t ic, int irq, int type, + int level, int (*ih_fun)(void *), void *ih_arg, char *); +void isa_intr_disestablish(isa_chipset_tag_t ic, void *handler); + +int isa_intr_check(isa_chipset_tag_t, int, int); + +/* + * ALL OF THE FOLLOWING ARE MACHINE-DEPENDENT, AND SHOULD NOT BE USED + * BY PORTABLE CODE. + */ + +extern struct bus_dma_tag isa_bus_dma_tag; + +/* + * Cookie used by ISA dma. A pointer to one of these it stashed in + * the DMA map. + */ +struct isa_dma_cookie { + int id_flags; /* flags; see below */ + + void *id_origbuf; /* pointer to orig buffer if + bouncing */ + bus_size_t id_origbuflen; /* ...and size */ + + void *id_bouncebuf; /* pointer to the bounce buffer */ + bus_size_t id_bouncebuflen; /* ...and size */ + int id_nbouncesegs; /* number of valid bounce segs */ + bus_dma_segment_t id_bouncesegs[0]; /* array of bounce buffer + physical memory segments */ +}; + +/* id_flags */ +#define ID_MIGHT_NEED_BOUNCE 0x01 /* map could need bounce buffers */ +#define ID_HAS_BOUNCE 0x02 /* map currently has bounce buffers */ +#define ID_IS_BOUNCING 0x04 /* map is bouncing current xfer */ + +/* + * Variables and macros to deal with the ISA I/O hole. + * XXX These should be converted to machine- and bus-mapping-independent + * function definitions, invoked through the softc. + */ + +extern u_long atdevbase; /* kernel virtual address of "hole" */ + +/* + * Given a kernel virtual address for some location + * in the "hole" I/O space, return a physical address. + */ +#define ISA_PHYSADDR(v) ((void *) ((u_long)(v) - atdevbase + IOM_BEGIN)) + +/* + * Given a physical address in the "hole", + * return a kernel virtual address. + */ +#define ISA_HOLE_VADDR(p) ((void *) ((u_long)(p) - IOM_BEGIN + atdevbase)) + +#endif /* _I386_ISA_MACHDEP_H_ XXX */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/kcore.h b/lib/libc/include/x86_64-openbsd-none/amd64/kcore.h new file mode 100644 index 0000000000..b02ab28664 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/kcore.h @@ -0,0 +1,47 @@ +/* $OpenBSD: kcore.h,v 1.5 2018/04/03 07:13:37 mlarkin Exp $ */ +/* $NetBSD: kcore.h,v 1.1 2003/04/26 18:39:43 fvdl Exp $ */ + +/* + * Copyright (c) 1996 Carnegie-Mellon University. + * All rights reserved. + * + * Author: Chris G. Demetriou + * + * Permission to use, copy, modify and distribute this software and + * its documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND + * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + */ + +/* + * Modified for NetBSD/i386 by Jason R. Thorpe, Numerical Aerospace + * Simulation Facility, NASA Ames Research Center. + * + * And once again modified for x86-64 by Frank van der Linden of + * Wasabi Systems, Inc. + */ + +#ifndef _MACHINE_KCORE_H_ +#define _MACHINE_KCORE_H_ + +typedef struct cpu_kcore_hdr { + u_int64_t ptdpaddr; /* PA of PML4 */ + u_int64_t nmemsegs; /* Number of RAM segments */ +} cpu_kcore_hdr_t; + +#endif /* _MACHINE_KCORE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/limits.h b/lib/libc/include/x86_64-openbsd-none/amd64/limits.h new file mode 100644 index 0000000000..f288e05429 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/limits.h @@ -0,0 +1,52 @@ +/* $OpenBSD: limits.h,v 1.6 2015/04/30 13:42:08 millert 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. + * + * @(#)limits.h 7.2 (Berkeley) 6/28/90 + */ + +#ifndef _MACHINE_LIMITS_H_ +#define _MACHINE_LIMITS_H_ + +#include + +#if __POSIX_VISIBLE || __XPG_VISIBLE +#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_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/loadfile_machdep.h b/lib/libc/include/x86_64-openbsd-none/amd64/loadfile_machdep.h new file mode 100644 index 0000000000..c856e9b9f6 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/loadfile_machdep.h @@ -0,0 +1,61 @@ +/* $OpenBSD: loadfile_machdep.h,v 1.9 2019/05/28 04:51:26 mlarkin Exp $ */ +/* $NetBSD: loadfile_machdep.h,v 1.1 1999/04/29 03:17:12 tsubai Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * 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. + */ + +#define BOOT_ELF +#define BOOT_ELF32 +#define BOOT_ELF64 + +/* Keep a default ELFSIZE */ +#define ELFSIZE 64 + +#define LOAD_KERNEL LOAD_ALL +#define COUNT_KERNEL COUNT_ALL + +#ifdef EFIBOOT +extern u_long efi_loadaddr; +#define LOADADDR(a) (((((u_long)(a)) + offset)&0xfffffff) + \ + efi_loadaddr) +#else +#define LOADADDR(a) ((a) + offset) +#endif +#define ALIGNENTRY(a) ((u_long)(a)) +#define READ(f, b, c) read((f), (void *)LOADADDR(b), (c)) +#define BCOPY(s, d, c) memcpy((void *)LOADADDR(d), (void *)(s), (c)) +#define BZERO(d, c) memset((void *)LOADADDR(d), 0, (c)) +#define WARN(a) (void)(printf a, \ + printf((errno ? ": %s\n" : "\n"), \ + strerror(errno))) +#define PROGRESS(a) (void) printf a +#define ALLOC(a) alloc(a) +#define FREE(a, b) free(a, b) + +void run_loadfile(uint64_t *, int); \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/mpbiosreg.h b/lib/libc/include/x86_64-openbsd-none/amd64/mpbiosreg.h new file mode 100644 index 0000000000..8a35f5f11d --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/mpbiosreg.h @@ -0,0 +1,156 @@ +/* $OpenBSD: mpbiosreg.h,v 1.5 2023/04/10 04:21:20 jsg Exp $ */ +/* $NetBSD: mpbiosreg.h,v 1.3 2003/03/04 23:27:32 fvdl Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by RedBack Networks Inc. + * + * Author: Bill Sommerfeld + * + * 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_MPBIOSREG_H_ +#define _MACHINE_MPBIOSREG_H_ + +#define BIOS_BASE (0xf0000) +#define BIOS_SIZE (0x10000) +#define BIOS_COUNT (BIOS_SIZE) + +/* + * Multiprocessor config table entry types. + */ + +#define MPS_MCT_CPU 0 +#define MPS_MCT_BUS 1 +#define MPS_MCT_IOAPIC 2 +#define MPS_MCT_IOINT 3 +#define MPS_MCT_LINT 4 + +#define MPS_MCT_NTYPES 5 + +/* + * Interrupt types + */ + +#define MPS_INTTYPE_INT 0 +#define MPS_INTTYPE_NMI 1 +#define MPS_INTTYPE_SMI 2 +#define MPS_INTTYPE_ExtINT 3 + +#define MPS_INTPO_DEF 0 +#define MPS_INTPO_ACTHI 1 +#define MPS_INTPO_ACTLO 3 +#define MPS_INTPO_SHIFT 0 +#define MPS_INTPO_MASK 3 + +#define MPS_INTTR_DEF 0 +#define MPS_INTTR_EDGE 1 +#define MPS_INTTR_LEVEL 3 +#define MPS_INTTR_SHIFT 2 +#define MPS_INTTR_MASK 3 + +#define MPS_INT(p,t) \ + ((((p) & MPS_INTPO_MASK) << MPS_INTPO_SHIFT) | \ + (((t) & MPS_INTTR_MASK) << MPS_INTTR_SHIFT)) + +/* MP Floating Pointer Structure */ +struct mpbios_fps { + u_int32_t signature; +/* string defined by the Intel MP Spec as identifying the MP table */ +#define MP_FP_SIG 0x5f504d5f /* _MP_ */ + + u_int32_t pap; + u_int8_t length; + u_int8_t spec_rev; + u_int8_t checksum; + u_int8_t mpfb1; /* system configuration */ + u_int8_t mpfb2; /* flags */ +#define MPFPS_FLAG_IMCR 0x80 /* IMCR present */ + u_int8_t mpfb3; /* unused */ + u_int8_t mpfb4; /* unused */ + u_int8_t mpfb5; /* unused */ +}; + +/* MP Configuration Table Header */ +struct mpbios_cth { + u_int32_t signature; +#define MP_CT_SIG 0x504d4350 /* PCMP */ + + u_int16_t base_len; + u_int8_t spec_rev; + u_int8_t checksum; + u_int8_t oem_id[8]; + u_int8_t product_id[12]; + u_int32_t oem_table_pointer; + u_int16_t oem_table_size; + u_int16_t entry_count; + u_int32_t apic_address; + u_int16_t ext_len; + u_int8_t ext_cksum; + u_int8_t reserved; +}; + +struct mpbios_proc { + u_int8_t type; + u_int8_t apic_id; + u_int8_t apic_version; + u_int8_t cpu_flags; +#define PROCENTRY_FLAG_EN 0x01 +#define PROCENTRY_FLAG_BP 0x02 + u_int32_t cpu_signature; + u_int32_t feature_flags; + u_int32_t reserved1; + u_int32_t reserved2; +}; + +struct mpbios_bus { + u_int8_t type; + u_int8_t bus_id; + char bus_type[6]; +}; + +struct mpbios_ioapic { + u_int8_t type; + u_int8_t apic_id; + u_int8_t apic_version; + u_int8_t apic_flags; +#define IOAPICENTRY_FLAG_EN 0x01 + u_int32_t apic_address; +}; + +struct mpbios_int { + u_int8_t type; + u_int8_t int_type; + u_int16_t int_flags; + u_int8_t src_bus_id; + u_int8_t src_bus_irq; + u_int8_t dst_apic_id; +#define MPS_ALL_APICS 0xff + u_int8_t dst_apic_int; +}; + + +#endif /* !_MACHINE_MPBIOSREG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/mpbiosvar.h b/lib/libc/include/x86_64-openbsd-none/amd64/mpbiosvar.h new file mode 100644 index 0000000000..2247427b23 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/mpbiosvar.h @@ -0,0 +1,57 @@ +/* $OpenBSD: mpbiosvar.h,v 1.7 2025/09/05 16:57:48 kettenis Exp $ */ +/* $NetBSD: mpbiosvar.h,v 1.2 2003/04/02 07:53:57 thorpej Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by RedBack Networks Inc. + * + * Author: Bill Sommerfeld + * + * 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_MPBIOSVAR_H_ +#define _MACHINE_MPBIOSVAR_H_ + +#define MP_TRAMPOLINE (16 * PAGE_SIZE) +#define MP_TRAMP_DATA (17 * PAGE_SIZE) + +#if !defined(_LOCORE) + +#include +#include + +#if defined(_KERNEL) +int mpbios_probe(struct device *); + +void mpbios_intr_fixup(void); + +extern int mpbios_scanned; +#endif + +#endif + +#endif /* !_MACHINE_MPBIOSVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/mpconfig.h b/lib/libc/include/x86_64-openbsd-none/amd64/mpconfig.h new file mode 100644 index 0000000000..7fc051d696 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/mpconfig.h @@ -0,0 +1,49 @@ +/* $OpenBSD: mpconfig.h,v 1.8 2011/10/21 20:48:11 kettenis Exp $ */ +/* $NetBSD: mpconfig.h,v 1.2 2003/05/11 00:05:52 fvdl Exp $ */ + +/* + * Definitions originally from the mpbios code, but now used for ACPI + * MP config as well. + */ + +#ifndef _AMD64_MPCONFIG_H +#define _AMD64_MPCONFIG_H + +#ifndef _LOCORE + +struct mpbios_int; + +struct mp_bus { + char *mb_name; /* XXX bus name */ + int mb_idx; /* XXX bus index */ + void (*mb_intr_print)(int); + void (*mb_intr_cfg)(const struct mpbios_int *, u_int32_t *); + struct mp_intr_map *mb_intrs; + u_int32_t mb_data; /* random bus-specific datum. */ +}; + +struct mp_intr_map { + struct mp_intr_map *next; + struct mp_bus *bus; + int bus_pin; + struct ioapic_softc *ioapic; + int ioapic_pin; + int ioapic_ih; /* int handle, for apic_intr_est */ + int type; /* from mp spec intr record */ + int flags; /* from mp spec intr record */ + u_int32_t redir; + int cpu_id; +}; + +#if defined(_KERNEL) +extern int mp_verbose; +extern struct mp_bus *mp_busses; +extern int mp_nbusses; +extern struct mp_intr_map *mp_intrs; +extern int mp_nintrs; +extern struct mp_bus *mp_isa_bus; +extern struct mp_bus *mp_eisa_bus; +#endif +#endif + +#endif /* _AMD64_MPCONFIG_H */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/mplock.h b/lib/libc/include/x86_64-openbsd-none/amd64/mplock.h new file mode 100644 index 0000000000..d91a96332e --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/mplock.h @@ -0,0 +1,10 @@ +/* $OpenBSD: mplock.h,v 1.5 2017/10/17 14:25:35 visa Exp $ */ + +/* public domain */ + +#ifndef _MACHINE_MPLOCK_H_ +#define _MACHINE_MPLOCK_H_ + +#define __USE_MI_MPLOCK + +#endif /* !_MACHINE_MPLOCK_H */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/mutex.h b/lib/libc/include/x86_64-openbsd-none/amd64/mutex.h new file mode 100644 index 0000000000..69b3361f02 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/mutex.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mutex.h,v 1.11 2018/01/25 15:06:29 mpi Exp $ */ + +#define __USE_MI_MUTEX \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/param.h b/lib/libc/include/x86_64-openbsd-none/amd64/param.h new file mode 100644 index 0000000000..69522312f0 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/param.h @@ -0,0 +1,81 @@ +/* $OpenBSD: param.h,v 1.30 2025/07/07 18:33:36 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 +#ifdef _LOCORE +#include +#else +#include +#endif +#endif + +#define _MACHINE amd64 +#define MACHINE "amd64" +#define _MACHINE_ARCH amd64 +#define MACHINE_ARCH "amd64" +#define MID_MACHINE MID_AMD64 + +#define PAGE_SHIFT 12 +#define PAGE_SIZE (1 << PAGE_SHIFT) +#define PAGE_MASK (PAGE_SIZE - 1) + +#define KERNBASE 0xffffffff80000000 /* start of kernel virtual space */ + +#ifdef _KERNEL + +#define KERNTEXTOFF (KERNBASE+0x1000000) /* start of kernel text */ + +#define NBPG PAGE_SIZE /* bytes/page */ +#define PGSHIFT PAGE_SHIFT /* LOG2(PAGE_SIZE) */ +#define PGOFSET PAGE_MASK /* byte offset into page */ + +#define UPAGES 6 /* pages of u-area */ +#define USPACE (UPAGES * PAGE_SIZE) /* total size of u-area */ +#define USPACE_ALIGN 0 /* u-area alignment 0-none */ +#define __HAVE_USPACE_GUARD + +#define NMBCLUSTERS (256 * 1024) /* max cluster allocation */ + +#ifndef MSGBUFSIZE +#define MSGBUFSIZE (32 * PAGE_SIZE) /* default message buffer size */ +#endif + +#define __HAVE_ACPI + +#endif /* _KERNEL */ + +#endif /* _MACHINE_PARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/pcb.h b/lib/libc/include/x86_64-openbsd-none/amd64/pcb.h new file mode 100644 index 0000000000..3cc195e205 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/pcb.h @@ -0,0 +1,93 @@ +/* $OpenBSD: pcb.h,v 1.17 2018/06/05 06:39:11 guenther Exp $ */ +/* $NetBSD: pcb.h,v 1.1 2003/04/26 18:39:45 fvdl Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Charles M. Hannum. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*- + * Copyright (c) 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. + * + * @(#)pcb.h 5.10 (Berkeley) 5/12/91 + */ + +#ifndef _MACHINE_PCB_H_ +#define _MACHINE_PCB_H_ + +#include + +#include + +/* + * Please note that the pcb_savefpu field in struct below must be + * on a 64-byte boundary. + */ +struct pcb { + struct savefpu pcb_savefpu; /* floating point state */ + u_int64_t pcb_cr3; + u_int64_t pcb_rsp; + u_int64_t pcb_rbp; + u_int64_t pcb_kstack; /* kernel stack address */ + u_int64_t pcb_fsbase; /* per-thread offset: %fs */ + caddr_t pcb_onfault; /* copyin/out fault recovery */ + struct pmap *pcb_pmap; /* back pointer to our pmap */ +}; + +#ifdef _KERNEL +void reset_segs(void); +#endif + +#endif /* _MACHINE_PCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/pci_machdep.h b/lib/libc/include/x86_64-openbsd-none/amd64/pci_machdep.h new file mode 100644 index 0000000000..6804596ff5 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/pci_machdep.h @@ -0,0 +1,137 @@ +/* $OpenBSD: pci_machdep.h,v 1.32 2025/01/23 11:24:34 kettenis Exp $ */ +/* $NetBSD: pci_machdep.h,v 1.1 2003/02/26 21:26:11 fvdl Exp $ */ + +/* + * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. + * Copyright (c) 1994 Charles M. Hannum. 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 Charles M. Hannum. + * 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. + */ + +/* + * Machine-specific definitions for PCI autoconfiguration. + */ + +/* + * amd64-specific PCI structure and type definitions. + * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE. + */ + +extern struct bus_dma_tag pci_bus_dma_tag; + +/* + * Types provided to machine-independent PCI code + */ +typedef void *pci_chipset_tag_t; +typedef u_int32_t pcitag_t; + +typedef struct { + pcitag_t tag; + int line, pin; +} pci_intr_handle_t; + +#define pci_intr_line(pc,ih) ((ih.line) & 0xff) + +/* + * amd64-specific PCI variables and functions. + * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE. + */ +struct pci_attach_args; + +extern struct extent *pciio_ex; +extern struct extent *pcimem_ex; +extern struct extent *pcibus_ex; +void pci_init_extents(void); + +/* + * Functions provided to machine-independent PCI code. + */ +void pci_attach_hook(struct device *, struct device *, + struct pcibus_attach_args *); +int pci_bus_maxdevs(pci_chipset_tag_t, int); +pcitag_t pci_make_tag(pci_chipset_tag_t, int, int, int); +void pci_decompose_tag(pci_chipset_tag_t, pcitag_t, + int *, int *, int *); +int pci_conf_size(pci_chipset_tag_t, pcitag_t); +pcireg_t pci_conf_read(pci_chipset_tag_t, pcitag_t, int); +void pci_conf_write(pci_chipset_tag_t, pcitag_t, int, + pcireg_t); +int pci_intr_enable_msivec(struct pci_attach_args *, int); +int pci_intr_map_msi(struct pci_attach_args *, + pci_intr_handle_t *); +int pci_intr_map_msivec(struct pci_attach_args *, + int, pci_intr_handle_t *); +int pci_intr_map_msix(struct pci_attach_args *, + int, pci_intr_handle_t *); +int pci_intr_map(struct pci_attach_args *, pci_intr_handle_t *); +const char *pci_intr_string(pci_chipset_tag_t, pci_intr_handle_t); +void *pci_intr_establish(pci_chipset_tag_t, pci_intr_handle_t, + int, int (*)(void *), void *, const char *); +void *pci_intr_establish_cpu(pci_chipset_tag_t, pci_intr_handle_t, + int, struct cpu_info *, + int (*)(void *), void *, const char *); +void pci_intr_disestablish(pci_chipset_tag_t, void *); +int pci_probe_device_hook(pci_chipset_tag_t, + struct pci_attach_args *); + +void pci_dev_postattach(struct device *, struct pci_attach_args *); + +pcireg_t pci_min_powerstate(pci_chipset_tag_t, pcitag_t); +void pci_set_powerstate_md(pci_chipset_tag_t, pcitag_t, int, int); + +void pci_mcfg_init(bus_space_tag_t, bus_addr_t, int, int, int); +pci_chipset_tag_t pci_lookup_segment(int, int); + +#define __HAVE_PCI_MSIX + +int pci_msix_table_map(pci_chipset_tag_t, pcitag_t, + bus_space_tag_t, bus_space_handle_t *); +void pci_msix_table_unmap(pci_chipset_tag_t, pcitag_t, + bus_space_tag_t, bus_space_handle_t); + +/* + * ALL OF THE FOLLOWING ARE MACHINE-DEPENDENT, AND SHOULD NOT BE USED + * BY PORTABLE CODE. + */ + +/* + * Section 6.2.4, `Miscellaneous Functions' of the PCI Specification, + * says that 255 means `unknown' or `no connection' to the interrupt + * controller on a PC. + */ +#define X86_PCI_INTERRUPT_LINE_NO_CONNECTION 0xff + +/* + * PCI address space is shared with ISA, so avoid legacy ISA I/O + * registers. + */ +#define PCI_IO_START 0x400 +#define PCI_IO_END 0xffff + +/* + * Avoid the DOS Compatibility Memory area. + */ +#define PCI_MEM_START 0x100000 \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/pctr.h b/lib/libc/include/x86_64-openbsd-none/amd64/pctr.h new file mode 100644 index 0000000000..53f01bdf68 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/pctr.h @@ -0,0 +1,73 @@ +/* $OpenBSD: pctr.h,v 1.7 2019/08/26 12:41:47 pirofti Exp $ */ + +/* + * Pentium performance counter driver for OpenBSD. + * Copyright 1996 David Mazieres . + * + * Modification and redistribution in source and binary forms is + * permitted provided that due credit is given to the author and the + * OpenBSD project by leaving this copyright notice intact. + */ + +#ifndef _MACHINE_PCTR_H_ +#define _MACHINE_PCTR_H_ + +#include + +typedef u_int64_t pctrval; + +#define PCTR_NUM 4 + +struct pctrst { + u_int pctr_fn[PCTR_NUM]; /* Current settings of counters */ + pctrval pctr_tsc; /* Free-running 64-bit cycle counter */ + pctrval pctr_hwc[PCTR_NUM]; /* Values of the hardware counters */ +}; + +/* Bit values in fn fields and PIOCS ioctl's */ +#define PCTR_U 0x010000 /* Monitor user-level events */ +#define PCTR_K 0x020000 /* Monitor kernel-level events */ +#define PCTR_E 0x040000 /* Edge detect */ +#define PCTR_EN 0x400000 /* Enable counters (counter 0 only) */ +#define PCTR_I 0x800000 /* Invert counter mask */ + +/* Unit Mask values to distinguish cache coherent states */ +#define PCTR_UM_M 0x0800 /* Modified cache lines */ +#define PCTR_UM_E 0x0400 /* Exclusive cache lines */ +#define PCTR_UM_S 0x0200 /* Shared cache lines */ +#define PCTR_UM_I 0x0100 /* Invalid cache lines */ +#define PCTR_UM_MESI (PCTR_UM_M|PCTR_UM_E|PCTR_UM_S|PCTR_UM_I) +#define PCTR_UM_A 0x2000 /* Any initiator */ + +#define PCTR_UM_SHIFT 8 /* Left shift for unit mask */ +#define PCTR_CM_SHIFT 24 /* Left shift for counter mask */ + +/* ioctl to set which counter a device tracks */ +#define PCIOCRD _IOR('c', 1, struct pctrst) /* Read counter value */ +#define PCIOCS0 _IOW('c', 8, unsigned int) /* Set counter 0 function */ +#define PCIOCS1 _IOW('c', 9, unsigned int) /* Set counter 1 function */ +#define PCIOCS2 _IOW('c', 10, unsigned int) /* Set counter 2 function */ +#define PCIOCS3 _IOW('c', 11, unsigned int) /* Set counter 3 function */ + +#define _PATH_PCTR "/dev/pctr" + +#define rdpmc(pmc) \ +({ \ + u_int32_t hi, lo; \ + __asm volatile("rdpmc" \ + : "=d" (hi), "=a" (lo) : "c" (pmc)); \ + hi &= 0xffffff; \ + (((u_int64_t)hi << 32) | (u_int64_t)lo); \ +}) + +#ifdef _KERNEL + +void pctrattach(int); +int pctropen(dev_t, int, int, struct proc *); +int pctrclose(dev_t, int, int, struct proc *); +int pctrioctl(dev_t, u_long, caddr_t, int, struct proc *); +void pctr_reload(struct cpu_info *); +void pctr_resume(struct cpu_info *); + +#endif /* _KERNEL */ +#endif /* ! _MACHINE_PCTR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/pic.h b/lib/libc/include/x86_64-openbsd-none/amd64/pic.h new file mode 100644 index 0000000000..21acee8498 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/pic.h @@ -0,0 +1,45 @@ +/* $OpenBSD: pic.h,v 1.8 2024/01/19 18:38:16 kettenis Exp $ */ +/* $NetBSD: pic.h,v 1.1 2003/02/26 21:26:11 fvdl Exp $ */ + +#ifndef _X86_PIC_H +#define _X86_PIC_H + +#include +#include + +struct cpu_info; + +/* + * Structure common to all PIC softcs + */ +struct pic { + struct device pic_dev; + int pic_type; +#ifdef MULTIPROCESSOR + struct mutex pic_mutex; +#endif + void (*pic_hwmask)(struct pic *, int); + void (*pic_hwunmask)(struct pic *, int); + void (*pic_addroute)(struct pic *, struct cpu_info *, int, int, int); + void (*pic_delroute)(struct pic *, struct cpu_info *, int, int, int); + int (*pic_allocidtvec)(struct pic *, int, int, int); + struct intrstub *pic_level_stubs; + struct intrstub *pic_edge_stubs; +}; + +#define pic_name pic_dev.dv_xname + +/* + * PIC types. + */ +#define PIC_I8259 0 +#define PIC_IOAPIC 1 +#define PIC_LAPIC 2 +#define PIC_MSI 3 +#define PIC_SOFT 4 + +extern struct pic i8259_pic; +extern struct pic local_pic; +extern struct pic msi_pic; +extern struct pic softintr_pic; +#endif \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/pio.h b/lib/libc/include/x86_64-openbsd-none/amd64/pio.h new file mode 100644 index 0000000000..f1236a3570 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/pio.h @@ -0,0 +1,225 @@ +/* $OpenBSD: pio.h,v 1.5 2015/04/25 21:31:24 guenther Exp $ */ +/* $NetBSD: pio.h,v 1.2 2003/02/27 11:22:46 fvdl Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Charles M. Hannum. + * + * 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_PIO_H_ +#define _MACHINE_PIO_H_ + +/* + * Functions to provide access to x86 programmed I/O instructions. + * + * The in[bwl]() and out[bwl]() functions are split into two varieties: one to + * use a small, constant, 8-bit port number, and another to use a large or + * variable port number. The former can be compiled as a smaller instruction. + */ + + +#ifdef __OPTIMIZE__ + +#define __use_immediate_port(port) \ + (__builtin_constant_p((port)) && (port) < 0x100) + +#else + +#define __use_immediate_port(port) 0 + +#endif + + +#define inb(port) \ + (/* CONSTCOND */ __use_immediate_port(port) ? __inbc(port) : __inb(port)) + +static __inline u_int8_t +__inbc(unsigned port) +{ + u_int8_t data; + __asm volatile("inb %w1,%0" : "=a" (data) : "id" (port)); + return data; +} + +static __inline u_int8_t +__inb(unsigned port) +{ + u_int8_t data; + __asm volatile("inb %w1,%0" : "=a" (data) : "d" (port)); + return data; +} + +static __inline void +insb(unsigned port, void *addr, int cnt) +{ + void *dummy1; + int dummy2; + __asm volatile("repne\n\tinsb" : + "=D" (dummy1), "=c" (dummy2) : + "d" (port), "0" (addr), "1" (cnt) : + "memory"); +} + +#define inw(port) \ + (/* CONSTCOND */ __use_immediate_port(port) ? __inwc(port) : __inw(port)) + +static __inline u_int16_t +__inwc(unsigned port) +{ + u_int16_t data; + __asm volatile("inw %w1,%0" : "=a" (data) : "id" (port)); + return data; +} + +static __inline u_int16_t +__inw(unsigned port) +{ + u_int16_t data; + __asm volatile("inw %w1,%0" : "=a" (data) : "d" (port)); + return data; +} + +static __inline void +insw(unsigned port, void *addr, int cnt) +{ + void *dummy1; + int dummy2; + __asm volatile("repne\n\tinsw" : + "=D" (dummy1), "=c" (dummy2) : + "d" (port), "0" (addr), "1" (cnt) : + "memory"); +} + +#define inl(port) \ + (/* CONSTCOND */ __use_immediate_port(port) ? __inlc(port) : __inl(port)) + +static __inline u_int32_t +__inlc(unsigned port) +{ + u_int32_t data; + __asm volatile("inl %w1,%0" : "=a" (data) : "id" (port)); + return data; +} + +static __inline u_int32_t +__inl(unsigned port) +{ + u_int32_t data; + __asm volatile("inl %w1,%0" : "=a" (data) : "d" (port)); + return data; +} + +static __inline void +insl(unsigned port, void *addr, int cnt) +{ + void *dummy1; + int dummy2; + __asm volatile("repne\n\tinsl" : + "=D" (dummy1), "=c" (dummy2) : + "d" (port), "0" (addr), "1" (cnt) : + "memory"); +} + +#define outb(port, data) \ + (/* CONSTCOND */__use_immediate_port(port) ? __outbc(port, data) : \ + __outb(port, data)) + +static __inline void +__outbc(unsigned port, u_int8_t data) +{ + __asm volatile("outb %0,%w1" : : "a" (data), "id" (port)); +} + +static __inline void +__outb(unsigned port, u_int8_t data) +{ + __asm volatile("outb %0,%w1" : : "a" (data), "d" (port)); +} + +static __inline void +outsb(unsigned port, const void *addr, int cnt) +{ + void *dummy1; + int dummy2; + __asm volatile("repne\n\toutsb" : + "=S" (dummy1), "=c" (dummy2) : + "d" (port), "0" (addr), "1" (cnt)); +} + +#define outw(port, data) \ + (/* CONSTCOND */ __use_immediate_port(port) ? __outwc(port, data) : \ + __outw(port, data)) + +static __inline void +__outwc(unsigned port, u_int16_t data) +{ + __asm volatile("outw %0,%w1" : : "a" (data), "id" (port)); +} + +static __inline void +__outw(unsigned port, u_int16_t data) +{ + __asm volatile("outw %0,%w1" : : "a" (data), "d" (port)); +} + +static __inline void +outsw(unsigned port, const void *addr, int cnt) +{ + void *dummy1; + int dummy2; + __asm volatile("repne\n\toutsw" : + "=S" (dummy1), "=c" (dummy2) : + "d" (port), "0" (addr), "1" (cnt)); +} + +#define outl(port, data) \ + (/* CONSTCOND */ __use_immediate_port(port) ? __outlc(port, data) : \ + __outl(port, data)) + +static __inline void +__outlc(unsigned port, u_int32_t data) +{ + __asm volatile("outl %0,%w1" : : "a" (data), "id" (port)); +} + +static __inline void +__outl(unsigned port, u_int32_t data) +{ + __asm volatile("outl %0,%w1" : : "a" (data), "d" (port)); +} + +static __inline void +outsl(unsigned port, const void *addr, int cnt) +{ + void *dummy1; + int dummy2; + __asm volatile("repne\n\toutsl" : + "=S" (dummy1), "=c" (dummy2) : + "d" (port), "0" (addr), "1" (cnt)); +} + +#endif /* _MACHINE_PIO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/pmap.h b/lib/libc/include/x86_64-openbsd-none/amd64/pmap.h new file mode 100644 index 0000000000..1b1c888978 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/pmap.h @@ -0,0 +1,524 @@ +/* $OpenBSD: pmap.h,v 1.94 2025/07/07 00:55:15 jsg Exp $ */ +/* $NetBSD: pmap.h,v 1.1 2003/04/26 18:39:46 fvdl Exp $ */ + +/* + * Copyright (c) 1997 Charles D. Cranor and Washington University. + * 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. + */ + +/* + * Copyright (c) 2001 Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Frank van der Linden for Wasabi Systems, Inc. + * + * 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 for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC + * 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. + */ + +/* + * pmap.h: see pmap.c for the history of this pmap module. + */ + +#ifndef _MACHINE_PMAP_H_ +#define _MACHINE_PMAP_H_ + +#ifndef _LOCORE +#ifdef _KERNEL +#include /* for KASSERT() */ +#include +#endif /* _KERNEL */ +#include +#include +#include +#endif + +/* + * The x86_64 pmap module closely resembles the i386 one. It uses + * the same recursive entry scheme. See the i386 pmap.h for a + * description. The alternate area trick for accessing non-current + * pmaps has been removed, though, because it performs badly on SMP + * systems. + * The most obvious difference to i386 is that 2 extra levels of page + * table need to be dealt with. The level 1 page table pages are at: + * + * l1: 0x00007f8000000000 - 0x00007fffffffffff (39 bits, needs PML4 entry) + * + * The other levels are kept as physical pages in 3 UVM objects and are + * temporarily mapped for virtual access when needed. + * + * The other obvious difference from i386 is that it has a direct map of all + * physical memory in the VA range: + * + * 0xfffffd8000000000 - 0xffffff7fffffffff + * + * The direct map is used in some cases to access PTEs of non-current pmaps. + * + * Note that address space is signed, so the layout for 48 bits is: + * + * +---------------------------------+ 0xffffffffffffffff + * | Kernel Image | + * +---------------------------------+ 0xffffff8000000000 + * | Direct Map | + * +---------------------------------+ 0xfffffd8000000000 + * ~ ~ + * | | + * | Kernel Space | + * | | + * | | + * +---------------------------------+ 0xffff800000000000 = 0x0000800000000000 + * | L1 table (PTE pages) | + * +---------------------------------+ 0x00007f8000000000 + * ~ ~ + * | | + * | User Space | + * | | + * | | + * +---------------------------------+ 0x0000000000000000 + * + * In other words, there is a 'VA hole' at 0x0000800000000000 - + * 0xffff800000000000 which will trap, just as on, for example, + * sparcv9. + * + * The unused space can be used if needed, but it adds a little more + * complexity to the calculations. + */ + +/* + * Mask to get rid of the sign-extended part of addresses. + */ +#define VA_SIGN_MASK 0xffff000000000000 +#define VA_SIGN_NEG(va) ((va) | VA_SIGN_MASK) +/* + * XXXfvdl this one's not right. + */ +#define VA_SIGN_POS(va) ((va) & ~VA_SIGN_MASK) + +#define L4_SLOT_PTE 255 +#define L4_SLOT_KERN 256 +#define L4_SLOT_KERNBASE 511 +#define NUM_L4_SLOT_DIRECT 4 +#define L4_SLOT_DIRECT (L4_SLOT_KERNBASE - NUM_L4_SLOT_DIRECT) +#define L4_SLOT_EARLY (L4_SLOT_DIRECT - 1) + +#define PDIR_SLOT_KERN L4_SLOT_KERN +#define PDIR_SLOT_PTE L4_SLOT_PTE +#define PDIR_SLOT_DIRECT L4_SLOT_DIRECT +#define PDIR_SLOT_EARLY L4_SLOT_EARLY + +/* + * the following defines give the virtual addresses of various MMU + * data structures: + * PTE_BASE: the base VA of the linear PTE mappings + * PDP_PDE: the VA of the PDE that points back to the PDP + * + */ + +#define PTE_BASE ((pt_entry_t *) (L4_SLOT_PTE * NBPD_L4)) +#define PMAP_DIRECT_BASE (VA_SIGN_NEG((L4_SLOT_DIRECT * NBPD_L4))) +#define PMAP_DIRECT_END (VA_SIGN_NEG(((L4_SLOT_DIRECT + \ + NUM_L4_SLOT_DIRECT) * NBPD_L4))) + +#define L1_BASE PTE_BASE + +#define L2_BASE ((pd_entry_t *)((char *)L1_BASE + L4_SLOT_PTE * NBPD_L3)) +#define L3_BASE ((pd_entry_t *)((char *)L2_BASE + L4_SLOT_PTE * NBPD_L2)) +#define L4_BASE ((pd_entry_t *)((char *)L3_BASE + L4_SLOT_PTE * NBPD_L1)) + +#define PDP_PDE (L4_BASE + PDIR_SLOT_PTE) + +#define PDP_BASE L4_BASE + +#define NKL4_MAX_ENTRIES (unsigned long)1 +#define NKL3_MAX_ENTRIES (unsigned long)(NKL4_MAX_ENTRIES * 512) +#define NKL2_MAX_ENTRIES (unsigned long)(NKL3_MAX_ENTRIES * 512) +#define NKL1_MAX_ENTRIES (unsigned long)(NKL2_MAX_ENTRIES * 512) + +#define NKL4_KIMG_ENTRIES 1 +#define NKL3_KIMG_ENTRIES 1 +#define NKL2_KIMG_ENTRIES 64 + +/* number of pages of direct map entries set up by locore0.S */ +#define NDML4_ENTRIES 1 +#define NDML3_ENTRIES 1 +#define NDML2_ENTRIES 4 /* 4GB */ + +/* + * Since kva space is below the kernel in its entirety, we start off + * with zero entries on each level. + */ +#define NKL4_START_ENTRIES 0 +#define NKL3_START_ENTRIES 0 +#define NKL2_START_ENTRIES 0 +#define NKL1_START_ENTRIES 0 /* XXX */ + +#define NTOPLEVEL_PDES (PAGE_SIZE / (sizeof (pd_entry_t))) + +#define NPDPG (PAGE_SIZE / sizeof (pd_entry_t)) + +/* + * pl*_pi: index in the ptp page for a pde mapping a VA. + * (pl*_i below is the index in the virtual array of all pdes per level) + */ +#define pl1_pi(VA) (((VA_SIGN_POS(VA)) & L1_MASK) >> L1_SHIFT) +#define pl2_pi(VA) (((VA_SIGN_POS(VA)) & L2_MASK) >> L2_SHIFT) +#define pl3_pi(VA) (((VA_SIGN_POS(VA)) & L3_MASK) >> L3_SHIFT) +#define pl4_pi(VA) (((VA_SIGN_POS(VA)) & L4_MASK) >> L4_SHIFT) + +/* + * pl*_i: generate index into pde/pte arrays in virtual space + */ +#define pl1_i(VA) (((VA_SIGN_POS(VA)) & L1_FRAME) >> L1_SHIFT) +#define pl2_i(VA) (((VA_SIGN_POS(VA)) & L2_FRAME) >> L2_SHIFT) +#define pl3_i(VA) (((VA_SIGN_POS(VA)) & L3_FRAME) >> L3_SHIFT) +#define pl4_i(VA) (((VA_SIGN_POS(VA)) & L4_FRAME) >> L4_SHIFT) +#define pl_i(va, lvl) \ + (((VA_SIGN_POS(va)) & ptp_masks[(lvl)-1]) >> ptp_shifts[(lvl)-1]) + +#define PTP_MASK_INITIALIZER { L1_FRAME, L2_FRAME, L3_FRAME, L4_FRAME } +#define PTP_SHIFT_INITIALIZER { L1_SHIFT, L2_SHIFT, L3_SHIFT, L4_SHIFT } +#define NKPTP_INITIALIZER { NKL1_START_ENTRIES, NKL2_START_ENTRIES, \ + NKL3_START_ENTRIES, NKL4_START_ENTRIES } +#define NKPTPMAX_INITIALIZER { NKL1_MAX_ENTRIES, NKL2_MAX_ENTRIES, \ + NKL3_MAX_ENTRIES, NKL4_MAX_ENTRIES } +#define NBPD_INITIALIZER { NBPD_L1, NBPD_L2, NBPD_L3, NBPD_L4 } +#define PDES_INITIALIZER { L2_BASE, L3_BASE, L4_BASE } + +/* + * PTP macros: + * a PTP's index is the PD index of the PDE that points to it + * a PTP's offset is the byte-offset in the PTE space that this PTP is at + * a PTP's VA is the first VA mapped by that PTP + */ + +#define ptp_va2o(va, lvl) (pl_i(va, (lvl)+1) * PAGE_SIZE) + +#define PTP_LEVELS 4 + +/* + * PG_AVAIL usage: we make use of the ignored bits of the PTE + */ + +#define PG_W PG_AVAIL1 /* "wired" mapping */ +#define PG_PVLIST PG_AVAIL2 /* mapping has entry on pvlist */ +/* PG_AVAIL3 not used */ + +/* + * PCID assignments. + * The shootdown code assumes KERN, PROC, and PROC_INTEL are both + * consecutive and in that order. + */ +#define PCID_KERN 0 /* for pmap_kernel() */ +#define PCID_PROC 1 /* non-pmap_kernel(), U+K */ +#define PCID_PROC_INTEL 2 /* non-pmap_kernel(), U-K (meltdown) */ +#define PCID_TEMP 3 /* temp mapping of another non-pmap_kernel() */ +#define PCID_EFI 4 /* EFI runtime services */ + +extern int pmap_use_pcid; /* non-zero if PCID support is enabled */ + +/* + * Number of PTEs per cache line. 8 byte pte, 64-byte cache line + * Used to avoid false sharing of cache lines. + */ +#define NPTECL 8 + + +#if defined(_KERNEL) && !defined(_LOCORE) +/* + * pmap data structures: see pmap.c for details of locking. + */ + +struct pmap; +typedef struct pmap *pmap_t; + +/* + * we maintain a list of all non-kernel pmaps + */ + +LIST_HEAD(pmap_head, pmap); /* struct pmap_head: head of a pmap list */ + +/* + * the pmap structure + * + * note that the pm_obj contains the reference count, + * page list, and number of PTPs within the pmap. + */ + +#define PMAP_TYPE_NORMAL 1 +#define PMAP_TYPE_EPT 2 +#define PMAP_TYPE_RVI 3 +#define pmap_nested(pm) ((pm)->pm_type != PMAP_TYPE_NORMAL) +#define pmap_is_ept(pm) ((pm)->pm_type == PMAP_TYPE_EPT) + +struct pmap { + struct mutex pm_mtx; + struct uvm_object pm_obj[PTP_LEVELS-1]; /* objects for lvl >= 1) */ + LIST_ENTRY(pmap) pm_list; /* list (lck by pm_list lock) */ + /* + * pm_pdir : VA of page table to be used when executing in + * privileged mode + * pm_pdirpa : PA of page table to be used when executing in + * privileged mode + * pm_pdir_intel : VA of special page table to be used when executing + * on an Intel CPU in usermode (no kernel mappings) + * pm_pdirpa_intel : PA of special page table to be used when executing + * on an Intel CPU in usermode (no kernel mappings) + */ + pd_entry_t *pm_pdir, *pm_pdir_intel; + paddr_t pm_pdirpa, pm_pdirpa_intel; + + struct vm_page *pm_ptphint[PTP_LEVELS-1]; + /* pointer to a PTP in our pmap */ + struct pmap_statistics pm_stats; /* pmap stats (lck by object lock) */ + + int pm_type; /* Type of pmap this is (PMAP_TYPE_x) */ + uint64_t eptp; /* cached EPTP (used by vmm) */ +}; + +#define PMAP_EFI PMAP_MD0 +#define PMAP_NOCRYPT PMAP_MD1 + +/* + * MD flags that we use for pmap_enter (in the pa): + */ +#define PMAP_PA_MASK ~((paddr_t)PAGE_MASK) /* to remove the flags */ +#define PMAP_NOCACHE 0x1 /* set the non-cacheable bit. */ +#define PMAP_WC 0x2 /* set page write combining. */ + +/* + * We keep mod/ref flags in struct vm_page->pg_flags. + */ +#define PG_PMAP_MOD PG_PMAP0 +#define PG_PMAP_REF PG_PMAP1 +#define PG_PMAP_WC PG_PMAP2 + +/* + * for each managed physical page we maintain a list of 's + * which it is mapped at. + */ +struct pv_entry { /* locked by its list's pvh_lock */ + struct pv_entry *pv_next; /* next entry */ + struct pmap *pv_pmap; /* the pmap */ + vaddr_t pv_va; /* the virtual address */ + struct vm_page *pv_ptp; /* the vm_page of the PTP */ +}; + +/* + * global kernel variables + */ + +extern struct pmap kernel_pmap_store; /* kernel pmap */ + +extern long nkptp[]; + +extern const paddr_t ptp_masks[]; +extern const int ptp_shifts[]; +extern const long nbpd[], nkptpmax[]; + +/* + * macros + */ + +#define pmap_kernel() (&kernel_pmap_store) +#define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count) +#define pmap_wired_count(pmap) ((pmap)->pm_stats.wired_count) +#define pmap_update(pmap) /* nothing (yet) */ + +#define pmap_clear_modify(pg) pmap_clear_attrs(pg, PG_M) +#define pmap_clear_reference(pg) pmap_clear_attrs(pg, PG_U) +#define pmap_is_modified(pg) pmap_test_attrs(pg, PG_M) +#define pmap_is_referenced(pg) pmap_test_attrs(pg, PG_U) +#define pmap_valid_entry(E) ((E) & PG_V) /* is PDE or PTE valid? */ + +#define pmap_proc_iflush(p,va,len) /* nothing */ +#define pmap_unuse_final(p) /* nothing */ +#define pmap_remove_holes(vm) do { /* nothing */ } while (0) + + +/* + * prototypes + */ + +void map_tramps(void); /* machdep.c */ +paddr_t pmap_bootstrap(paddr_t, paddr_t); +void pmap_init_percpu(void); +void pmap_randomize(void); +void pmap_randomize_level(pd_entry_t *, int); +int pmap_clear_attrs(struct vm_page *, unsigned long); +static void pmap_page_protect(struct vm_page *, vm_prot_t); +void pmap_page_remove (struct vm_page *); +static void pmap_protect(struct pmap *, vaddr_t, + vaddr_t, vm_prot_t); +void pmap_remove(struct pmap *, vaddr_t, vaddr_t); +int pmap_test_attrs(struct vm_page *, unsigned); +static void pmap_update_pg(vaddr_t); +void pmap_write_protect(struct pmap *, vaddr_t, + vaddr_t, vm_prot_t); + +paddr_t pmap_prealloc_lowmem_ptps(paddr_t); + +void pagezero(vaddr_t); + +void pmap_convert(struct pmap *, int); +void pmap_enter_special(vaddr_t, paddr_t, vm_prot_t); +vaddr_t pmap_set_pml4_early(paddr_t pa); +void pmap_clear_pml4_early(void); + +/* + * functions for flushing the cache for vaddrs and pages. + * these functions are not part of the MI pmap interface and thus + * should not be used as such. + */ +void pmap_flush_cache(vaddr_t, vsize_t); +#define pmap_flush_page(paddr) do { \ + KDASSERT(PHYS_TO_VM_PAGE(paddr) != NULL); \ + pmap_flush_cache(PMAP_DIRECT_MAP(paddr), PAGE_SIZE); \ +} while (/* CONSTCOND */ 0) + +#define PMAP_CHECK_COPYIN (pg_xo == 0) + +#define PMAP_STEAL_MEMORY /* enable pmap_steal_memory() */ +#define PMAP_GROWKERNEL /* turn on pmap_growkernel interface */ + +/* + * inline functions + */ + +/* + * pmap_update_pg: flush one page from the TLB (or flush the whole thing + * if hardware doesn't support one-page flushing) + */ + +static inline void +pmap_update_pg(vaddr_t va) +{ + invlpg(va); +} + +/* + * pmap_page_protect: change the protection of all recorded mappings + * of a managed page + * + * => this function is a frontend for pmap_page_remove/pmap_clear_attrs + * => we only have to worry about making the page more protected. + * unprotecting a page is done on-demand at fault time. + */ + +static inline void +pmap_page_protect(struct vm_page *pg, vm_prot_t prot) +{ + if (prot == PROT_READ) { + (void) pmap_clear_attrs(pg, PG_RW); + } else { + KASSERT(prot == PROT_NONE); + pmap_page_remove(pg); + } +} + +/* + * pmap_protect: change the protection of pages in a pmap + * + * => this function is a frontend for pmap_remove/pmap_write_protect + * => we only have to worry about making the page more protected. + * unprotecting a page is done on-demand at fault time. + */ + +static inline void +pmap_protect(struct pmap *pmap, vaddr_t sva, vaddr_t eva, vm_prot_t prot) +{ + if (prot != PROT_NONE) { + pmap_write_protect(pmap, sva, eva, prot); + } else { + pmap_remove(pmap, sva, eva); + } +} + +/* + * kvtopte: return a pointer to the PTE mapping a kernel VA + */ + +static inline pt_entry_t * +kvtopte(vaddr_t va) +{ +#ifdef LARGEPAGES + { + pd_entry_t *pde; + + pde = L1_BASE + pl2_i(va); + if (*pde & PG_PS) + return ((pt_entry_t *)pde); + } +#endif + + return (PTE_BASE + pl1_i(va)); +} + +#define PMAP_DIRECT_MAP(pa) ((vaddr_t)PMAP_DIRECT_BASE + (pa)) +#define PMAP_DIRECT_UNMAP(va) ((paddr_t)(va) - PMAP_DIRECT_BASE) +#define pmap_map_direct(pg) PMAP_DIRECT_MAP(VM_PAGE_TO_PHYS(pg)) +#define pmap_unmap_direct(va) PHYS_TO_VM_PAGE(PMAP_DIRECT_UNMAP(va)) + +#define __HAVE_PMAP_DIRECT +#define __HAVE_PMAP_MPSAFE_ENTER_COW + +#endif /* _KERNEL && !_LOCORE */ + +#ifndef _LOCORE +struct pv_entry; +struct vm_page_md { + struct mutex pv_mtx; + struct pv_entry *pv_list; +}; + +#define VM_MDPAGE_INIT(pg) do { \ + mtx_init(&(pg)->mdpage.pv_mtx, IPL_VM); \ + (pg)->mdpage.pv_list = NULL; \ +} while (0) +#endif /* !_LOCORE */ + +#endif /* _MACHINE_PMAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/proc.h b/lib/libc/include/x86_64-openbsd-none/amd64/proc.h new file mode 100644 index 0000000000..f365bebe6b --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/proc.h @@ -0,0 +1,52 @@ +/* $OpenBSD: proc.h,v 1.10 2018/06/05 06:39:11 guenther Exp $ */ +/* $NetBSD: proc.h,v 1.1 2003/04/26 18:39:46 fvdl 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 amd64. + */ +struct trapframe; +struct mdproc { + struct trapframe *md_regs; /* registers on current frame */ + int md_flags; + volatile int md_astpending; +}; + +/* md_flags */ +#define MDP_IRET 0x0002 /* return via iret, not sysret */ + /* (iret can restore r11 and rcx) */ + +#endif /* _MACHINE_PROC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/profile.h b/lib/libc/include/x86_64-openbsd-none/amd64/profile.h new file mode 100644 index 0000000000..04fc7ace48 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/profile.h @@ -0,0 +1,77 @@ +/* $OpenBSD: profile.h,v 1.6 2023/06/27 10:11:15 cheloha Exp $ */ +/* $NetBSD: profile.h,v 1.3 2003/11/28 23:22:45 fvdl Exp $ */ + +/* + * Copyright (c) 1992, 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. + * + * @(#)profile.h 8.1 (Berkeley) 6/11/93 + */ + +#define _MCOUNT_DECL void _mcount + +#ifdef __PIC__ +#define __MCPLT "@PLT" +#else +#define __MCPLT +#endif + +#define MCOUNT \ +__asm(" .globl __mcount \n" \ +" .type __mcount,@function\n" \ +"__mcount: \n" \ +" pushq %rbp \n" \ +" movq %rsp,%rbp \n" \ +" subq $56,%rsp \n" \ +" movq %rdi,0(%rsp) \n" \ +" movq %rsi,8(%rsp) \n" \ +" movq %rdx,16(%rsp) \n" \ +" movq %rcx,24(%rsp) \n" \ +" movq %r8,32(%rsp) \n" \ +" movq %r9,40(%rsp) \n" \ +" movq %rax,48(%rsp) \n" \ +" movq 0(%rbp),%r11 \n" \ +" movq 8(%r11),%rdi \n" \ +" movq 8(%rbp),%rsi \n" \ +" call _mcount"__MCPLT"\n" \ +" movq 0(%rsp),%rdi \n" \ +" movq 8(%rsp),%rsi \n" \ +" movq 16(%rsp),%rdx \n" \ +" movq 24(%rsp),%rcx \n" \ +" movq 32(%rsp),%r8 \n" \ +" movq 40(%rsp),%r9 \n" \ +" movq 48(%rsp),%rax \n" \ +" leave \n" \ +" ret \n" \ +" lfence \n" \ +" .size __mcount,.-__mcount"); + + +#ifdef _KERNEL +#define MCOUNT_ENTER s = intr_disable() +#define MCOUNT_EXIT intr_restore(s) +#endif /* _KERNEL */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/psl.h b/lib/libc/include/x86_64-openbsd-none/amd64/psl.h new file mode 100644 index 0000000000..2fa183244f --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/psl.h @@ -0,0 +1,76 @@ +/* $OpenBSD: psl.h,v 1.5 2018/07/09 19:20:29 guenther Exp $ */ +/* $NetBSD: psl.h,v 1.1 2003/02/26 21:26:11 fvdl 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. + * + * @(#)psl.h 5.2 (Berkeley) 1/18/91 + */ + +#ifndef _MACHINE_PSL_H_ +#define _MACHINE_PSL_H_ + +/* + * 386 processor status longword. + */ +#define PSL_C 0x00000001 /* carry flag */ +#define PSL_PF 0x00000004 /* parity flag */ +#define PSL_AF 0x00000010 /* auxiliary carry flag */ +#define PSL_Z 0x00000040 /* zero flag */ +#define PSL_N 0x00000080 /* sign flag */ +#define PSL_T 0x00000100 /* trap flag */ +#define PSL_I 0x00000200 /* interrupt enable flag */ +#define PSL_D 0x00000400 /* direction flag */ +#define PSL_V 0x00000800 /* overflow flag */ +#define PSL_IOPL 0x00003000 /* i/o privilege level */ +#define PSL_NT 0x00004000 /* nested task */ +#define PSL_RF 0x00010000 /* resume flag */ +#define PSL_VM 0x00020000 /* virtual 8086 mode */ +#define PSL_AC 0x00040000 /* alignment check flag */ +#define PSL_VIF 0x00080000 /* virtual interrupt enable flag */ +#define PSL_VIP 0x00100000 /* virtual interrupt pending flag */ +#define PSL_ID 0x00200000 /* identification flag */ + +#define PSL_MBO 0x00000002 /* must be one bits */ +#define PSL_MBZ 0xffc08028 /* must be zero bits */ + +#define PSL_USERSET (PSL_MBO | PSL_I) +#define PSL_USERSTATIC (PSL_MBO | PSL_MBZ | PSL_I | PSL_IOPL | PSL_NT | PSL_VM | PSL_VIF | PSL_VIP) +#define PSL_USER (PSL_C | PSL_MBO | PSL_PF | PSL_AF | PSL_Z | PSL_N | PSL_V) + +/* + * ??? + */ +#ifdef _KERNEL +#include +#endif + +#endif /* !_MACHINE_PSL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/pte.h b/lib/libc/include/x86_64-openbsd-none/amd64/pte.h new file mode 100644 index 0000000000..c91bf8cea9 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/pte.h @@ -0,0 +1,171 @@ +/* $OpenBSD: pte.h,v 1.18 2024/07/09 19:11:06 bluhm Exp $ */ +/* $NetBSD: pte.h,v 1.1 2003/04/26 18:39:47 fvdl Exp $ */ + +/* + * Copyright (c) 2001 Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Frank van der Linden for Wasabi Systems, Inc. + * + * 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 for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC + * 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_PTE_H_ +#define _MACHINE_PTE_H_ + +/* + * amd64 MMU hardware structure: + * + * the (first generation) amd64 MMU is a 4-level MMU which maps 2^48 bytes + * of virtual memory. The pagesize we use is 4K (4096 [0x1000] bytes), + * although 2M and 4M can be used as well. The indexes in the levels + * are 9 bits wide (512 64bit entries per level), dividing the bits + * 9-9-9-9-12. + * + * The top level table, called PML4, contains 512 64bit entries pointing + * to 3rd level table. The 3rd level table is called the 'page directory + * pointers directory' and has 512 entries pointing to page directories. + * The 2nd level is the page directory, containing 512 pointers to + * page table pages. Lastly, level 1 consists of pages containing 512 + * PTEs. + * + * Simply put, levels 4-1 all consist of pages containing 512 + * entries pointing to the next level. Level 0 is the actual PTEs + * themselves. + * + * For a description on the other bits, which are i386 compatible, + * see the i386 pte.h + */ + +#if !defined(_LOCORE) + +/* + * here we define the data types for PDEs and PTEs + */ + +typedef u_int64_t pd_entry_t; /* PDE */ +typedef u_int64_t pt_entry_t; /* PTE */ + +#endif + +/* + * now we define various for playing with virtual addresses + */ + +#define L1_SHIFT 12 +#define L2_SHIFT 21 +#define L3_SHIFT 30 +#define L4_SHIFT 39 +#define NBPD_L1 (1ULL << L1_SHIFT) /* # bytes mapped by L1 ent (4K) */ +#define NBPD_L2 (1ULL << L2_SHIFT) /* # bytes mapped by L2 ent (2MB) */ +#define NBPD_L3 (1ULL << L3_SHIFT) /* # bytes mapped by L3 ent (1G) */ +#define NBPD_L4 (1ULL << L4_SHIFT) /* # bytes mapped by L4 ent (512G) */ + +#define L4_MASK 0x0000ff8000000000UL +#define L3_MASK 0x0000007fc0000000UL +#define L2_MASK 0x000000003fe00000UL +#define L1_MASK 0x00000000001ff000UL + +#define L4_FRAME L4_MASK +#define L3_FRAME (L4_FRAME|L3_MASK) +#define L2_FRAME (L3_FRAME|L2_MASK) +#define L1_FRAME (L2_FRAME|L1_MASK) + +#define PAGE_MASK_L2 (NBPD_L2 - 1) + +#define x86_round_pdr(x) \ + ((((unsigned long)(x)) + (NBPD_L2 - 1)) & ~(NBPD_L2 - 1)) + +/* + * PDE/PTE bits. These are no different from their i386 counterparts. + */ + +#define PG_V 0x0000000000000001UL /* valid */ +#define PG_RO 0x0000000000000000UL /* read-only */ +#define PG_RW 0x0000000000000002UL /* read-write */ +#define PG_u 0x0000000000000004UL /* user accessible */ +#define PG_PROT 0x0000000000000006UL +#define PG_WT 0x0000000000000008UL /* write through */ +#define PG_N 0x0000000000000010UL /* non-cacheable */ +#define PG_U 0x0000000000000020UL /* used */ +#define PG_M 0x0000000000000040UL /* modified */ +#define PG_PAT 0x0000000000000080UL /* PAT bit. (on pte) */ +#define PG_PS 0x0000000000000080UL /* 2MB page size (on pde) */ +#define PG_G 0x0000000000000100UL /* not flushed */ +#define PG_AVAIL1 0x0000000000000200UL +#define PG_AVAIL2 0x0000000000000400UL +#define PG_AVAIL3 0x0000000000000800UL +#define PG_PATLG 0x0000000000001000UL /* PAT on large pages */ +#define PG_PKMASK 0x7800000000000000UL /* Protection Key Mask */ +#define PG_XO 0x0800000000000000UL /* key1 used for execute-only */ +#define PG_NX 0x8000000000000000UL /* non-executable */ +#define PG_FRAME 0x000ffffffffff000UL + +#define PG_LGFRAME 0x000fffffffe00000UL /* large (2M) page frame mask */ + +#define PGK_VALUE 0xfffffffc /* key0 is normal */ + +/* EPT PTE bits */ +#define EPT_R (1ULL << 0) +#define EPT_W (1ULL << 1) +#define EPT_X (1ULL << 2) +#define EPT_WB (6ULL << 3) +#define EPT_PS (1ULL << 7) + +/* Cacheability bits when we are using PAT */ +#define PG_WB (0) /* The default */ +#define PG_WC (PG_WT) /* WT and CD is WC */ +#define PG_UCMINUS (PG_N) /* UC but mtrr can override */ +#define PG_UC (PG_WT | PG_N) /* hard UC */ + +/* + * short forms of protection codes + */ + +#define PG_KR 0x0000000000000000UL /* kernel read-only */ +#define PG_KW 0x0000000000000002UL /* kernel read-write */ + +/* + * page protection exception bits + */ + +#define PGEX_P 0x01 /* protection violation (vs. no mapping) */ +#define PGEX_W 0x02 /* exception during a write cycle */ +#define PGEX_U 0x04 /* exception while in user mode (upl) */ +#define PGEX_I 0x10 /* instruction fetch blocked by NX */ +#define PGEX_PK 0x20 /* protection-key violation */ + +#ifdef _KERNEL +extern pt_entry_t pg_xo; /* XO pte bits using PKU key1 */ +extern pt_entry_t pg_nx; /* NX pte bit */ +extern pt_entry_t pg_crypt; /* C pte bit */ +extern pt_entry_t pg_g_kern; /* PG_G if glbl mappings can be used in kern */ +#endif /* _KERNEL */ + +#endif /* _MACHINE_PTE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/ptrace.h b/lib/libc/include/x86_64-openbsd-none/amd64/ptrace.h new file mode 100644 index 0000000000..7a0450c88f --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/ptrace.h @@ -0,0 +1,56 @@ +/* $OpenBSD: ptrace.h,v 1.2 2024/11/27 05:25:57 anton Exp $ */ +/* $NetBSD: ptrace.h,v 1.1 2003/04/26 18:39:47 fvdl 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. + */ + +/* + * i386-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) + +#define PT_GETXSTATE_INFO (PT_FIRSTMACH + 5) +#define PT_GETXSTATE (PT_FIRSTMACH + 6) +#define PT_SETXSTATE (PT_FIRSTMACH + 7) + +struct ptrace_xstate_info { + uint64_t xsave_mask; + uint32_t xsave_len; +}; + +#ifdef _KERNEL +int process_read_xstate_info(struct proc *, void *); +int process_read_xstate(struct proc *, void *); +int process_write_xstate(struct proc *, void *); +#endif \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/rbus_machdep.h b/lib/libc/include/x86_64-openbsd-none/amd64/rbus_machdep.h new file mode 100644 index 0000000000..6c293739bc --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/rbus_machdep.h @@ -0,0 +1,48 @@ +/* $OpenBSD: rbus_machdep.h,v 1.8 2024/05/22 05:51:49 jsg Exp $ */ +/* $NetBSD: rbus_machdep.h,v 1.2 1999/10/15 06:43:05 haya Exp $ */ + +/* + * Copyright (c) 1999 + * HAYAKAWA Koichi. 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_RBUS_MACHDEP_H_ +#define _MACHINE_RBUS_MACHDEP_H_ + +struct pci_attach_args; /* XXX */ + +#define md_space_map(rbt, physaddr, size, flags, bshp) \ + _bus_space_map((rbt)->rb_bt, (physaddr), (size), (flags), (bshp)) + +#define md_space_unmap(rbt, bsh, size, adrp) \ + _bus_space_unmap((rbt)->rb_bt, (bsh), (size), (adrp)) + +rbus_tag_t rbus_pccbb_parent_io(struct device *, + struct pci_attach_args *); +rbus_tag_t rbus_pccbb_parent_mem(struct device *, + struct pci_attach_args *); + +void pccbb_attach_hook(struct device *, struct device *, + struct pci_attach_args *); + +#endif /* _MACHINE_RBUS_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/reg.h b/lib/libc/include/x86_64-openbsd-none/amd64/reg.h new file mode 100644 index 0000000000..de1804e194 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/reg.h @@ -0,0 +1,125 @@ +/* $OpenBSD: reg.h,v 1.7 2019/07/14 05:08:26 guenther Exp $ */ +/* $NetBSD: reg.h,v 1.1 2003/04/26 18:39:47 fvdl 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 _MACHINE_REG_H_ +#define _MACHINE_REG_H_ + +#include + +/* + * XXX + * The #defines aren't used in the kernel, but some user-level code still + * expects them. + */ + +/* When referenced during a trap/exception, registers are at these offsets */ + +#define tRDI 0 +#define tRSI 1 +#define tRDX 2 +#define tRCX 3 +#define tR8 4 +#define tR9 5 +#define tR10 6 +#define tR11 7 +#define tR12 8 +#define tR13 9 +#define tR14 10 +#define tR15 11 +#define tRBP 12 +#define tRBX 13 +#define tRAX 14 +#define tRSP 15 +#define tRIP 16 +#define tRFLAGS 17 +#define tCS 18 +#define tSS 19 +#define tDS 20 +#define tES 21 +#define tFS 22 +#define tGS 23 + +/* + * Registers accessible to ptrace(2) syscall for debugger use. + */ +struct reg { + int64_t r_rdi; + int64_t r_rsi; + int64_t r_rdx; + int64_t r_rcx; + int64_t r_r8; + int64_t r_r9; + int64_t r_r10; + int64_t r_r11; + int64_t r_r12; + int64_t r_r13; + int64_t r_r14; + int64_t r_r15; + int64_t r_rbp; + int64_t r_rbx; + int64_t r_rax; + int64_t r_rsp; + int64_t r_rip; + int64_t r_rflags; + int64_t r_cs; + int64_t r_ss; + int64_t r_ds; + int64_t r_es; + int64_t r_fs; + int64_t r_gs; +}; + +struct fpreg { + struct fxsave64 fxstate; +}; + +#define fp_fcw fxstate.fx_fcw +#define fp_fsw fxstate.fx_fsw +#define fp_ftw fxstate.fx_ftw +#define fp_fop fxstate.fx_fop +#define fp_rip fxstate.fx_rip +#define fp_rdp fxstate.fx_rdp +#define fp_mxcsr fxstate.fx_mxcsr +#define fp_mxcsr_mask fxstate.fx_mxcsr_mask +#define fp_st fxstate.fx_st +#define fp_xmm fxstate.fx_xmm + +#ifdef _KERNEL +int check_context(const struct reg *, struct trapframe *); +#endif + +#endif /* !_MACHINE_REG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/reloc.h b/lib/libc/include/x86_64-openbsd-none/amd64/reloc.h new file mode 100644 index 0000000000..b83e6d0571 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/reloc.h @@ -0,0 +1,69 @@ +/* $OpenBSD: reloc.h,v 1.4 2018/10/20 11:56:31 kettenis Exp $ */ + +/* + * Copyright (c) 2002,2003 Dale Rahn + * + * 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_RELOC_H_ +#define _MACHINE_RELOC_H_ + +#define R_TYPE(X) __CONCAT(R_X86_64_,X) + +#define R_X86_64_NONE 0 +#define R_X86_64_64 1 +#define R_X86_64_PC32 2 +#define R_X86_64_GOT32 3 +#define R_X86_64_PLT32 4 +#define R_X86_64_COPY 5 +#define R_X86_64_GLOB_DAT 6 +#define R_X86_64_JUMP_SLOT 7 +#define R_X86_64_RELATIVE 8 +#define R_X86_64_GOTPCREL 9 +#define R_X86_64_32 10 +#define R_X86_64_32S 11 +#define R_X86_64_16 12 +#define R_X86_64_PC16 13 +#define R_X86_64_8 14 +#define R_X86_64_PC8 15 +#define R_X86_64_DTPMOD64 16 +#define R_X86_64_DTPOFF64 17 +#define R_X86_64_TPOFF64 18 +#define R_X86_64_TLSGD 19 +#define R_X86_64_TLSLD 20 +#define R_X86_64_DTPOFF32 21 +#define R_X86_64_GOTTPOFF 22 +#define R_X86_64_TPOFF32 23 + +#define R_386_NONE 0 +#define R_386_32 1 +#define R_386_PC32 2 +#define R_386_GOT32 3 +#define R_386_PLT32 4 +#define R_386_COPY 5 +#define R_386_GLOB_DAT 6 +#define R_386_JMP_SLOT 7 +#define R_386_RELATIVE 8 +#define R_386_GOTOFF 9 +#define R_386_GOTPC 10 + +#endif /* _MACHINE_RELOC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/segments.h b/lib/libc/include/x86_64-openbsd-none/amd64/segments.h new file mode 100644 index 0000000000..8bf2140313 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/segments.h @@ -0,0 +1,279 @@ +/* $OpenBSD: segments.h,v 1.18 2025/06/27 17:23:49 bluhm Exp $ */ +/* $NetBSD: segments.h,v 1.1 2003/04/26 18:39:47 fvdl Exp $ */ + +/*- + * Copyright (c) 1995, 1997 + * Charles M. Hannum. All rights reserved. + * Copyright (c) 1989, 1990 William F. Jolitz + * 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. + * + * @(#)segments.h 7.1 (Berkeley) 5/9/91 + */ + +/* + * Adapted for NetBSD/amd64 by fvdl@wasabisystems.com. + */ + +/* + * 386 Segmentation Data Structures and definitions + * William F. Jolitz (william@ernie.berkeley.edu) 6/20/1989 + */ + +#ifndef _MACHINE_SEGMENTS_H_ +#define _MACHINE_SEGMENTS_H_ + +/* + * Selectors + */ + +#define ISPL(s) ((s) & SEL_RPL) /* what is the priority level of a selector */ +#define SEL_KPL 0 /* kernel privilege level */ +#define SEL_UPL 3 /* user privilege level */ +#define SEL_RPL 3 /* requester's privilege level mask */ +#define ISLDT(s) ((s) & SEL_LDT) /* is it local or global */ +#define SEL_LDT 4 /* local descriptor table */ + +#define SYSSEL_START (NGDT_MEM << 3) +#define GDT_SIZE (SYSSEL_START + (NGDT_SYS << 4)) + +/* + * These define the index not from the start of the GDT, but from + * the part of the GDT that they're allocated from. + * First NGDT_MEM entries are 8-byte descriptors for CS and DS. + * Next NGDT_SYS entries are 16-byte descriptors defining TSSs. + */ + +#define IDXSEL(s) (((s) >> 3) & 0x1fff) +#define IDXDYNSEL(s) ((((s) & ~SEL_RPL) - DYNSEL_START) >> 4) + +#define GSEL(s,r) (((s) << 3) | r) +#define GSYSSEL(s,r) ((((s) << 4) + SYSSEL_START) | r) +#define GDYNSEL(s,r) ((((s) << 4) + DYNSEL_START) | r | SEL_KPL) + +#define LSEL(s,r) ((s) | r | SEL_LDT) + +#define USERMODE(c, f) (ISPL(c) == SEL_UPL) +#define KERNELMODE(c, f) (ISPL(c) == SEL_KPL) + +#ifndef _LOCORE + +/* + * Memory and System segment descriptors + */ + +/* + * Below is used for TSS and LDT. + */ +struct sys_segment_descriptor { + u_int64_t sd_lolimit:16; /* segment extent (lsb) */ + u_int64_t sd_lobase:24; /* segment base address (lsb) */ + u_int64_t sd_type:5; /* segment type */ + u_int64_t sd_dpl:2; /* segment descriptor priority level */ + u_int64_t sd_p:1; /* segment descriptor present */ + u_int64_t sd_hilimit:4; /* segment extent (msb) */ + u_int64_t sd_xx1:3; /* avl, long and def32 (not used) */ + u_int64_t sd_gran:1; /* limit granularity (byte/page) */ + u_int64_t sd_hibase:40; /* segment base address (msb) */ + u_int64_t sd_xx2:8; /* reserved */ + u_int64_t sd_zero:5; /* must be zero */ + u_int64_t sd_xx3:19; /* reserved */ +} __packed; + +/* + * Below is used for cs, ds, etc. + */ +struct mem_segment_descriptor { + unsigned int sd_lolimit:16; /* segment extent (lsb) */ + unsigned int sd_lobase:24; /* segment base address (lsb) */ + unsigned int sd_type:5; /* segment type */ + unsigned int sd_dpl:2; /* segment descriptor priority level */ + unsigned int sd_p:1; /* segment descriptor present */ + unsigned int sd_hilimit:4; /* segment extent (msb) */ + unsigned int sd_avl:1; /* available */ + unsigned int sd_long:1; /* long mode */ + unsigned int sd_def32:1; /* default 32 vs 16 bit size */ + unsigned int sd_gran:1; /* limit granularity (byte/page) */ + unsigned int sd_hibase:8; /* segment base address (msb) */ +} __packed; + +/* + * Gate descriptors (e.g. indirect descriptors) + */ +struct gate_descriptor { + u_int64_t gd_looffset:16; /* gate offset (lsb) */ + u_int64_t gd_selector:16; /* gate segment selector */ + u_int64_t gd_ist:3; /* IST select */ + u_int64_t gd_xx1:5; /* reserved */ + u_int64_t gd_type:5; /* segment type */ + u_int64_t gd_dpl:2; /* segment descriptor priority level */ + u_int64_t gd_p:1; /* segment descriptor present */ + u_int64_t gd_hioffset:48; /* gate offset (msb) */ + u_int64_t gd_xx2:8; /* reserved */ + u_int64_t gd_zero:5; /* must be zero */ + u_int64_t gd_xx3:19; /* reserved */ +} __packed; + +/* + * region descriptors, used to load gdt/idt tables before segments yet exist. + */ +struct region_descriptor { + u_int16_t rd_limit; /* segment extent */ + u_int64_t rd_base; /* base address */ +} __packed; + +#ifdef _KERNEL +extern struct gate_descriptor *idt; +extern struct gate_descriptor early_idt[]; + +void setgate(struct gate_descriptor *, void *, int, int, int, int); +void unsetgate(struct gate_descriptor *); +void setregion(struct region_descriptor *, void *, u_int16_t); +void set_sys_segment(struct sys_segment_descriptor *, void *, size_t, + int, int, int); +void set_mem_segment(struct mem_segment_descriptor *, void *, size_t, + int, int, int, int, int); +int idt_vec_alloc(int, int); +int idt_vec_alloc_range(int, int, int); +void idt_vec_set(int, void (*)(void)); +void idt_vec_free(int); +void cpu_init_idt(void); + +#endif /* _KERNEL */ + +#endif /* !_LOCORE */ + +/* system segments and gate types */ +#define SDT_SYSNULL 0 /* system null */ +#define SDT_SYS286TSS 1 /* system 286 TSS available */ +#define SDT_SYSLDT 2 /* system local descriptor table */ +#define SDT_SYS286BSY 3 /* system 286 TSS busy */ +#define SDT_SYS286CGT 4 /* system 286 call gate */ +#define SDT_SYSTASKGT 5 /* system task gate */ +#define SDT_SYS286IGT 6 /* system 286 interrupt gate */ +#define SDT_SYS286TGT 7 /* system 286 trap gate */ +#define SDT_SYSNULL2 8 /* system null again */ +#define SDT_SYS386TSS 9 /* system 386 TSS available */ +#define SDT_SYSNULL3 10 /* system null again */ +#define SDT_SYS386BSY 11 /* system 386 TSS busy */ +#define SDT_SYS386CGT 12 /* system 386 call gate */ +#define SDT_SYSNULL4 13 /* system null again */ +#define SDT_SYS386IGT 14 /* system 386 interrupt gate */ +#define SDT_SYS386TGT 15 /* system 386 trap gate */ + +/* memory segment types */ +#define SDT_MEMRO 16 /* memory read only */ +#define SDT_MEMROA 17 /* memory read only accessed */ +#define SDT_MEMRW 18 /* memory read write */ +#define SDT_MEMRWA 19 /* memory read write accessed */ +#define SDT_MEMROD 20 /* memory read only expand dwn limit */ +#define SDT_MEMRODA 21 /* memory read only expand dwn limit accessed */ +#define SDT_MEMRWD 22 /* memory read write expand dwn limit */ +#define SDT_MEMRWDA 23 /* memory read write expand dwn limit acessed */ +#define SDT_MEME 24 /* memory execute only */ +#define SDT_MEMEA 25 /* memory execute only accessed */ +#define SDT_MEMER 26 /* memory execute read */ +#define SDT_MEMERA 27 /* memory execute read accessed */ +#define SDT_MEMEC 28 /* memory execute only conforming */ +#define SDT_MEMEAC 29 /* memory execute only accessed conforming */ +#define SDT_MEMERC 30 /* memory execute read conforming */ +#define SDT_MEMERAC 31 /* memory execute read accessed conforming */ + +/* is memory segment descriptor pointer ? */ +#define ISMEMSDP(s) ((s->d_type) >= SDT_MEMRO && \ + (s->d_type) <= SDT_MEMERAC) + +/* is 286 gate descriptor pointer ? */ +#define IS286GDP(s) ((s->d_type) >= SDT_SYS286CGT && \ + (s->d_type) < SDT_SYS286TGT) + +/* is 386 gate descriptor pointer ? */ +#define IS386GDP(s) ((s->d_type) >= SDT_SYS386CGT && \ + (s->d_type) < SDT_SYS386TGT) + +/* is gate descriptor pointer ? */ +#define ISGDP(s) (IS286GDP(s) || IS386GDP(s)) + +/* is segment descriptor pointer ? */ +#define ISSDP(s) (ISMEMSDP(s) || !ISGDP(s)) + +/* is system segment descriptor pointer ? */ +#define ISSYSSDP(s) (!ISMEMSDP(s) && !ISGDP(s)) + +/* + * Segment Protection Exception code bits + */ +#define SEGEX_EXT 0x01 /* recursive or externally induced */ +#define SEGEX_IDT 0x02 /* interrupt descriptor table */ +#define SEGEX_TI 0x04 /* local descriptor table */ + +/* + * Entries in the Interrupt Descriptor Table (IDT) + */ +#define NIDT 256 +#define NRSVIDT 32 /* reserved entries for cpu exceptions */ + +/* + * Entries in the Global Descriptor Table (GDT) + * The code and data descriptors must come first. There + * are NGDT_MEM of them. + * + * Then comes the predefined TSS descriptor. + * There are NGDT_SYS of them. + * + * The particular order of the UDATA and UCODE descriptors is + * required by the sysretq instruction. + */ +#define GNULL_SEL 0 /* Null descriptor */ +#define GCODE_SEL 1 /* Kernel code descriptor */ +#define GDATA_SEL 2 /* Kernel data descriptor */ +#define GUDATA_SEL 3 /* User data descriptor */ +#define GUCODE_SEL 4 /* User code descriptor */ +#define NGDT_MEM 5 + +#define GPROC0_SEL 0 /* common TSS */ +#define NGDT_SYS 1 + +#define GDT_SYS_OFFSET (NGDT_MEM << 3) + +#define GDT_ADDR_MEM(s,i) \ + ((struct mem_segment_descriptor *)((char *)(s) + ((i) << 3))) +#define GDT_ADDR_SYS(s,i) \ + ((struct sys_segment_descriptor *)((char *)(s) + ((i) << 4) + SYSSEL_START)) + +/* + * Checks for valid user selectors. + */ +#define VALID_USER_CSEL(s) \ + ((s) == GSEL(GUCODE_SEL, SEL_UPL)) +#define VALID_USER_DSEL(s) \ + ((s) == GSEL(GUDATA_SEL, SEL_UPL)) + +#endif /* _MACHINE_SEGMENTS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/setjmp.h b/lib/libc/include/x86_64-openbsd-none/amd64/setjmp.h new file mode 100644 index 0000000000..88f0465d15 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/setjmp.h @@ -0,0 +1,22 @@ +/* $OpenBSD: setjmp.h,v 1.2 2020/10/21 19:00:14 kettenis Exp $ */ +/* $NetBSD: setjmp.h,v 1.1 2003/04/26 18:39:47 fvdl Exp $ */ + +/* + * machine/setjmp.h: machine dependent setjmp-related information. + * These are only the callee-saved registers, code calling setjmp + * will expect the rest to be clobbered anyway. + */ + +#define _JB_RBX 0 +#define _JB_RBP 1 +#define _JB_R12 2 +#define _JB_R13 3 +#define _JB_R14 4 +#define _JB_R15 5 +#define _JB_RSP 6 +#define _JB_PC 7 +#define _JB_SIGFLAG 8 +#define _JB_SIGMASK 9 +#define _JB_MXCSR 10 + +#define _JBLEN 11 /* size, in longs, of a jmp_buf */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/signal.h b/lib/libc/include/x86_64-openbsd-none/amd64/signal.h new file mode 100644 index 0000000000..5b19f70f3b --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/signal.h @@ -0,0 +1,89 @@ +/* $OpenBSD: signal.h,v 1.9 2016/05/10 18:39:42 deraadt Exp $ */ +/* $NetBSD: signal.h,v 1.2 2003/04/28 23:16:17 bjh21 Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1989, 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. + * + * @(#)signal.h 7.16 (Berkeley) 3/17/91 + */ + +#ifndef _MACHINE_SIGNAL_H_ +#define _MACHINE_SIGNAL_H_ + +#include + +typedef int sig_atomic_t; + +#ifdef _KERNEL +#include +#endif + +#if __BSD_VISIBLE || __XPG_VISIBLE >= 420 +/* + * Information pushed on stack when a signal is delivered. + * This is used by the kernel to restore state following + * execution of the signal handler. It is also made available + * to the handler to allow it to restore state properly if + * a non-standard exit is performed. + */ +struct sigcontext { + /* plain match trapframe */ + long sc_rdi; + long sc_rsi; + long sc_rdx; + long sc_rcx; + long sc_r8; + long sc_r9; + long sc_r10; + long sc_r11; + long sc_r12; + long sc_r13; + long sc_r14; + long sc_r15; + long sc_rbp; + long sc_rbx; + long sc_rax; + long sc_gs; + long sc_fs; + long sc_es; + long sc_ds; + long sc_trapno; + long sc_err; + long sc_rip; + long sc_cs; + long sc_rflags; + long sc_rsp; + long sc_ss; + + struct fxsave64 *sc_fpstate; + int __sc_unused; + int sc_mask; + long sc_cookie; +}; +#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */ +#endif /* !_MACHINE_SIGNAL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/smbiosvar.h b/lib/libc/include/x86_64-openbsd-none/amd64/smbiosvar.h new file mode 100644 index 0000000000..34349b6ec9 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/smbiosvar.h @@ -0,0 +1,281 @@ +/* $OpenBSD: smbiosvar.h,v 1.14 2025/07/15 01:09:32 jsg Exp $ */ +/* + * Copyright (c) 2006 Gordon Willem Klok + * Copyright (c) 2005 Jordan Hargrave + * 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 AUTHORS 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 AUTHORS 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_SMBIOSVAR_ +#define _MACHINE_SMBIOSVAR_ + +#define SMBIOS_START 0xf0000 +#define SMBIOS_END 0xfffff + +#define SMBIOS_UUID_NPRESENT 0x1 +#define SMBIOS_UUID_NSET 0x2 + +/* + * Section 3.5 of "UUIDs and GUIDs" found at + * http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt + * specifies the string representation of a UUID. + */ +#define SMBIOS_UUID_REP "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" +#define SMBIOS_UUID_REPLEN 37 /* 16 zero padded values, 4 hyphens, 1 null */ + +struct smbios_entry { + uint8_t mjr; + uint8_t min; + uint8_t *addr; + uint16_t len; + uint16_t count; +}; + +struct smbhdr { + uint32_t sig; /* "_SM_" */ + uint8_t checksum; /* Entry point checksum */ + uint8_t len; /* Entry point structure length */ + uint8_t majrev; /* Specification major revision */ + uint8_t minrev; /* Specification minor revision */ + uint16_t mss; /* Maximum Structure Size */ + uint8_t epr; /* Entry Point Revision */ + uint8_t fa[5]; /* value determined by EPR */ + uint8_t sasig[5]; /* Secondary Anchor "_DMI_" */ + uint8_t sachecksum; /* Secondary Checksum */ + uint16_t size; /* Length of structure table in bytes */ + uint32_t addr; /* Structure table address */ + uint16_t count; /* Number of SMBIOS structures */ + uint8_t rev; /* BCD revision */ +} __packed; + +struct smb3hdr { + uint8_t sig[5]; /* "_SM3_" */ + uint8_t checksum; /* Entry point structure checksum */ + uint8_t len; /* Entry point length */ + uint8_t majrev; /* SMBIOS major version */ + uint8_t minrev; /* SMBIOS minor version */ + uint8_t docrev; /* SMBIOS docrev */ + uint8_t epr; /* Entry point revision */ + uint8_t reserved; /* Reserved */ + uint32_t size; /* Structure table maximum size */ + uint64_t addr; /* Structure table address */ +} __packed; + +struct smbtblhdr { + uint8_t type; + uint8_t size; + uint16_t handle; +} __packed; + +struct smbtable { + struct smbtblhdr *hdr; + void *tblhdr; + uint32_t cookie; +}; + +#define SMBIOS_TYPE_BIOS 0 +#define SMBIOS_TYPE_SYSTEM 1 +#define SMBIOS_TYPE_BASEBOARD 2 +#define SMBIOS_TYPE_ENCLOSURE 3 +#define SMBIOS_TYPE_PROCESSOR 4 +#define SMBIOS_TYPE_MEMCTRL 5 +#define SMBIOS_TYPE_MEMMOD 6 +#define SMBIOS_TYPE_CACHE 7 +#define SMBIOS_TYPE_PORT 8 +#define SMBIOS_TYPE_SLOTS 9 +#define SMBIOS_TYPE_OBD 10 +#define SMBIOS_TYPE_OEM 11 +#define SMBIOS_TYPE_SYSCONFOPT 12 +#define SMBIOS_TYPE_BIOSLANG 13 +#define SMBIOS_TYPE_GROUPASSOC 14 +#define SMBIOS_TYPE_SYSEVENTLOG 15 +#define SMBIOS_TYPE_PHYMEM 16 +#define SMBIOS_TYPE_MEMDEV 17 +#define SMBIOS_TYPE_ECCINFO32 18 +#define SMBIOS_TYPE_MEMMAPARRAYADDR 19 +#define SMBIOS_TYPE_MEMMAPDEVADDR 20 +#define SMBIOS_TYPE_INBUILTPOINT 21 +#define SMBIOS_TYPE_PORTBATT 22 +#define SMBIOS_TYPE_SYSRESET 23 +#define SMBIOS_TYPE_HWSECUIRTY 24 +#define SMBIOS_TYPE_PWRCTRL 25 +#define SMBIOS_TYPE_VOLTPROBE 26 +#define SMBIOS_TYPE_COOLING 27 +#define SMBIOS_TYPE_TEMPPROBE 28 +#define SMBIOS_TYPE_CURRENTPROBE 29 +#define SMBIOS_TYPE_OOB_REMOTEACCESS 30 +#define SMBIOS_TYPE_BIS 31 +#define SMBIOS_TYPE_SBI 32 +#define SMBIOS_TYPE_ECCINFO64 33 +#define SMBIOS_TYPE_MGMTDEV 34 +#define SMBIOS_TYPE_MGTDEVCOMP 35 +#define SMBIOS_TYPE_MGTDEVTHRESH 36 +#define SMBIOS_TYPE_MEMCHANNEL 37 +#define SMBIOS_TYPE_IPMIDEV 38 +#define SMBIOS_TYPE_SPS 39 +#define SMBIOS_TYPE_INACTIVE 126 +#define SMBIOS_TYPE_EOT 127 + +/* + * SMBIOS Structure Type 0 "BIOS Information" + * DMTF Specification DSP0134 Section: 3.3.1 p.g. 34 + */ +struct smbios_struct_bios { + uint8_t vendor; /* string */ + uint8_t version; /* string */ + uint16_t startaddr; + uint8_t release; /* string */ + uint8_t romsize; + uint64_t characteristics; + uint32_t charext; + uint8_t major_rel; + uint8_t minor_rel; + uint8_t ecf_mjr_rel; /* embedded controller firmware */ + uint8_t ecf_min_rel; /* embedded controller firmware */ +} __packed; + +/* + * SMBIOS Structure Type 1 "System Information" + * DMTF Specification DSP0134 Section 3.3.2 p.g. 35 + */ + +struct smbios_sys { +/* SMBIOS spec 2.0+ */ + uint8_t vendor; /* string */ + uint8_t product; /* string */ + uint8_t version; /* string */ + uint8_t serial; /* string */ +/* SMBIOS spec 2.1+ */ + uint8_t uuid[16]; + uint8_t wakeup; +/* SMBIOS spec 2.4+ */ + uint8_t sku; /* string */ + uint8_t family; /* string */ +} __packed; + +/* + * SMBIOS Structure Type 2 "Base Board (Module) Information" + * DMTF Specification DSP0134 Section 3.3.3 p.g. 37 + */ +struct smbios_board { + uint8_t vendor; /* string */ + uint8_t product; /* string */ + uint8_t version; /* string */ + uint8_t serial; /* string */ + uint8_t asset; /* string */ + uint8_t feature; /* feature flags */ + uint8_t location; /* location in chassis */ + uint16_t handle; /* chassis handle */ + uint8_t type; /* board type */ + uint8_t noc; /* number of contained objects */ +} __packed; + +/* + * SMBIOS Structure Type 3 "System Enclosure or Chassis" + * DMTF Specification DSP0134 + */ +struct smbios_enclosure { + /* SMBIOS spec 2.0+ */ + uint8_t vendor; /* string */ + uint8_t type; + uint8_t version; /* string */ + uint8_t serial; /* string */ + uint8_t asset_tag; /* string */ + /* SMBIOS spec 2.1+ */ + uint8_t boot_state; + uint8_t psu_state; + uint8_t thermal_state; + uint8_t security_status; + /* SMBIOS spec 2.3+ */ + uint16_t oem_defined; + uint8_t height; + uint8_t no_power_cords; + uint8_t no_contained_element; + uint8_t reclen_contained_element; + uint8_t contained_elements; + /* SMBIOS spec 2.7+ */ + uint8_t sku; /* string */ +} __packed; + +/* + * SMBIOS Structure Type 4 "processor Information" + * DMTF Specification DSP0134 v2.5 Section 3.3.5 p.g. 24 + */ +struct smbios_cpu { + uint8_t cpu_socket_designation; /* string */ + uint8_t cpu_type; + uint8_t cpu_family; + uint8_t cpu_mfg; /* string */ + uint32_t cpu_id_eax; + uint32_t cpu_id_edx; + uint8_t cpu_version; /* string */ + uint8_t cpu_voltage; + uint16_t cpu_clock; + uint16_t cpu_max_speed; + uint16_t cpu_current_speed; + uint8_t cpu_status; +#define SMBIOS_CPUST_POPULATED (1<<6) +#define SMBIOS_CPUST_STATUSMASK (0x07) + uint8_t cpu_upgrade; + uint16_t cpu_l1_handle; + uint16_t cpu_l2_handle; + uint16_t cpu_l3_handle; + uint8_t cpu_serial; /* string */ + uint8_t cpu_asset_tag; /* string */ + uint8_t cpu_part_nr; /* string */ + /* following fields were added in smbios 2.5 */ + uint8_t cpu_core_count; + uint8_t cpu_core_enabled; + uint8_t cpu_thread_count; + uint16_t cpu_characteristics; +} __packed; + +/* + * SMBIOS Structure Type 38 "IPMI Information" + * DMTF Specification DSP0134 Section 3.3.39 p.g. 91 + */ +struct smbios_ipmi { + uint8_t smipmi_if_type; /* IPMI Interface Type */ + uint8_t smipmi_if_rev; /* BCD IPMI Revision */ + uint8_t smipmi_i2c_address; /* I2C address of BMC */ + uint8_t smipmi_nvram_address; /* I2C address of NVRAM + * storage */ + uint64_t smipmi_base_address; /* Base address of BMC (BAR + * format */ + uint8_t smipmi_base_flags; /* Flags field: + * bit 7:6 : register spacing + * 00 = byte + * 01 = dword + * 02 = word + * bit 4 : Lower bit BAR + * bit 3 : IRQ valid + * bit 2 : N/A + * bit 1 : Interrupt polarity + * bit 0 : Interrupt trigger */ + uint8_t smipmi_irq; /* IRQ if applicable */ +} __packed; + +int smbios_find_table(uint8_t, struct smbtable *); +char *smbios_get_string(struct smbtable *, uint8_t, char *, size_t); + +#endif \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/specialreg.h b/lib/libc/include/x86_64-openbsd-none/amd64/specialreg.h new file mode 100644 index 0000000000..fc0770c81d --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/specialreg.h @@ -0,0 +1,1645 @@ +/* $OpenBSD: specialreg.h,v 1.120 2025/07/16 07:15:41 jsg Exp $ */ +/* $NetBSD: specialreg.h,v 1.1 2003/04/26 18:39:48 fvdl Exp $ */ +/* $NetBSD: x86/specialreg.h,v 1.2 2003/04/25 21:54:30 fvdl Exp $ */ + +/*- + * Copyright (c) 1991 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. + * + * @(#)specialreg.h 7.1 (Berkeley) 5/9/91 + */ + +/* + * Bits in 386 special registers: + */ +#define CR0_PE 0x00000001 /* Protected mode Enable */ +#define CR0_MP 0x00000002 /* "Math" Present (NPX or NPX emulator) */ +#define CR0_EM 0x00000004 /* EMulate non-NPX coproc. (trap ESC only) */ +#define CR0_TS 0x00000008 /* Task Switched (if MP, trap ESC and WAIT) */ +#define CR0_ET 0x00000010 /* Extension Type (387 (if set) vs 287) */ +#define CR0_PG 0x80000000 /* PaGing enable */ + +/* + * Bits in 486 special registers: + */ +#define CR0_NE 0x00000020 /* Numeric Error enable (EX16 vs IRQ13) */ +#define CR0_WP 0x00010000 /* Write Protect (honor PG_RW in all modes) */ +#define CR0_AM 0x00040000 /* Alignment Mask (set to enable AC flag) */ +#define CR0_NW 0x20000000 /* Not Write-through */ +#define CR0_CD 0x40000000 /* Cache Disable */ + +/* + * bits in CR3 + */ +#define CR3_PCID 0xfffULL +#define CR3_PWT (1ULL << 3) +#define CR3_PCD (1ULL << 4) +#define CR3_REUSE_PCID (1ULL << 63) +#define CR3_PADDR 0x7ffffffffffff000ULL + +/* + * bits in the pentiums %cr4 register: + */ + +#define CR4_VME 0x00000001 /* virtual 8086 mode extension enable */ +#define CR4_PVI 0x00000002 /* protected mode virtual interrupt enable */ +#define CR4_TSD 0x00000004 /* restrict RDTSC instruction to cpl 0 only */ +#define CR4_DE 0x00000008 /* debugging extension */ +#define CR4_PSE 0x00000010 /* large (4MB) page size enable */ +#define CR4_PAE 0x00000020 /* physical address extension enable */ +#define CR4_MCE 0x00000040 /* machine check enable */ +#define CR4_PGE 0x00000080 /* page global enable */ +#define CR4_PCE 0x00000100 /* enable RDPMC instruction for all cpls */ +#define CR4_OSFXSR 0x00000200 /* enable fxsave/fxrestor and SSE */ +#define CR4_OSXMMEXCPT 0x00000400 /* enable unmasked SSE exceptions */ +#define CR4_UMIP 0x00000800 /* user mode instruction prevention */ +#define CR4_VMXE 0x00002000 /* enable virtual machine operation */ +#define CR4_SMXE 0x00004000 /* enable safe mode operation */ +#define CR4_FSGSBASE 0x00010000 /* enable {RD,WR}{FS,GS}BASE ops */ +#define CR4_PCIDE 0x00020000 /* enable process-context IDs */ +#define CR4_OSXSAVE 0x00040000 /* enable XSAVE and extended states */ +#define CR4_KL 0x00080000 /* enable AES Key Locker */ +#define CR4_SMEP 0x00100000 /* supervisor mode exec protection */ +#define CR4_SMAP 0x00200000 /* supervisor mode access prevention */ +#define CR4_PKE 0x00400000 /* user-mode protection keys */ +#define CR4_CET 0x00800000 /* control-flow enforcement tech */ +#define CR4_PKS 0x01000000 /* supervisor-mode protection keys */ +#define CR4_UINTR 0x02000000 /* user interrupts enable bit */ + +/* + * Extended state components, for xsave/xrstor family of instructions. + */ +#define XFEATURE_X87 0x00000001 /* x87 FPU/MMX state */ +#define XFEATURE_SSE 0x00000002 /* SSE state */ +#define XFEATURE_AVX 0x00000004 /* AVX state */ +#define XFEATURE_BNDREG 0x00000008 /* MPX state */ +#define XFEATURE_BNDCSR 0x00000010 /* MPX state */ +#define XFEATURE_MPX (XFEATURE_BNDREG | XFEATURE_BNDCSR) +#define XFEATURE_OPMASK 0x00000020 /* AVX-512 opmask */ +#define XFEATURE_ZMM_HI256 0x00000040 /* AVX-512 ZMM0-7 */ +#define XFEATURE_HI16_ZMM 0x00000080 /* AVX-512 ZMM16-31 */ +#define XFEATURE_AVX512 (XFEATURE_OPMASK | XFEATURE_ZMM_HI256 | \ + XFEATURE_HI16_ZMM) +#define XFEATURE_PT 0x00000100 /* processor trace */ +#define XFEATURE_PKRU 0x00000200 /* user page key */ +#define XFEATURE_PASID 0x00000400 /* Process ASIDs */ +#define XFEATURE_CET_U 0x00000800 /* ctrl-flow enforce user */ +#define XFEATURE_CET_S 0x00001000 /* ctrl-flow enforce system */ +#define XFEATURE_CET (XFEATURE_CET_U | XFEATURE_CET_S) +#define XFEATURE_HDC 0x00002000 /* HW duty cycling */ +#define XFEATURE_UINTR 0x00004000 /* user interrupts */ +#define XFEATURE_LBR 0x00008000 /* last-branch record */ +#define XFEATURE_HWP 0x00010000 /* HW P-states */ +#define XFEATURE_TILECFG 0x00020000 /* AMX state */ +#define XFEATURE_TILEDATA 0x00040000 /* AMX state */ +#define XFEATURE_AMX (XFEATURE_TILECFG | XFEATURE_TILEDATA) + +/* valid only in xcomp_bv field: */ +#define XFEATURE_COMPRESSED (1ULL << 63) /* compressed format */ + +/* which bits are for XCR0 and which for the XSS MSR? */ +#define XFEATURE_XCR0_MASK \ + (XFEATURE_X87 | XFEATURE_SSE | XFEATURE_AVX | XFEATURE_MPX | \ + XFEATURE_AVX512 | XFEATURE_PKRU | XFEATURE_AMX) +#define XFEATURE_XSS_MASK \ + (XFEATURE_PT | XFEATURE_PASID | XFEATURE_CET | XFEATURE_HDC | \ + XFEATURE_UINTR | XFEATURE_LBR | XFEATURE_HWP) + +/* + * CPUID "features" bits (CPUID function 0x1): + * EDX bits, then ECX bits + */ + +#define CPUID_FPU 0x00000001 /* processor has an FPU? */ +#define CPUID_VME 0x00000002 /* has virtual mode (%cr4's VME/PVI) */ +#define CPUID_DE 0x00000004 /* has debugging extension */ +#define CPUID_PSE 0x00000008 /* has 4MB page size extension */ +#define CPUID_TSC 0x00000010 /* has time stamp counter */ +#define CPUID_MSR 0x00000020 /* has model specific registers */ +#define CPUID_PAE 0x00000040 /* has phys address extension */ +#define CPUID_MCE 0x00000080 /* has machine check exception */ +#define CPUID_CX8 0x00000100 /* has CMPXCHG8B instruction */ +#define CPUID_APIC 0x00000200 /* has enabled APIC */ +#define CPUID_SYS1 0x00000400 /* has SYSCALL/SYSRET inst. (Cyrix) */ +#define CPUID_SEP 0x00000800 /* has SYSCALL/SYSRET inst. (AMD/Intel) */ +#define CPUID_MTRR 0x00001000 /* has memory type range register */ +#define CPUID_PGE 0x00002000 /* has page global extension */ +#define CPUID_MCA 0x00004000 /* has machine check architecture */ +#define CPUID_CMOV 0x00008000 /* has CMOVcc instruction */ +#define CPUID_PAT 0x00010000 /* has page attribute table */ +#define CPUID_PSE36 0x00020000 /* has 36bit page size extension */ +#define CPUID_PSN 0x00040000 /* has processor serial number */ +#define CPUID_CFLUSH 0x00080000 /* CFLUSH insn supported */ +#define CPUID_B20 0x00100000 /* reserved */ +#define CPUID_DS 0x00200000 /* Debug Store */ +#define CPUID_ACPI 0x00400000 /* ACPI performance modulation regs */ +#define CPUID_MMX 0x00800000 /* has MMX instructions */ +#define CPUID_FXSR 0x01000000 /* has FXRSTOR instruction */ +#define CPUID_SSE 0x02000000 /* has streaming SIMD extensions */ +#define CPUID_SSE2 0x04000000 /* has streaming SIMD extensions #2 */ +#define CPUID_SS 0x08000000 /* self-snoop */ +#define CPUID_HTT 0x10000000 /* Hyper-Threading Technology */ +#define CPUID_TM 0x20000000 /* thermal monitor (TCC) */ +#define CPUID_B30 0x40000000 /* reserved */ +#define CPUID_PBE 0x80000000 /* Pending Break Enabled restarts clock */ +#define CPUID_EDX_BITS \ + ("\20" "\01FPU" "\02VME" "\03DE" "\04PSE" "\05TSC" "\06MSR" "\07PAE" \ + "\010MCE" "\011CX8" "\012APIC" "\014SEP" "\015MTRR" "\016PGE" "\017MCA" \ + "\020CMOV" "\021PAT" "\022PSE36" "\023PSN" "\024CFLUSH" "\026DS" \ + "\027ACPI" "\030MMX" "\031FXSR" "\032SSE" "\033SSE2" "\034SS" "\035HTT" \ + "\036TM" "\040PBE" ) + +#define CPUIDECX_SSE3 0x00000001 /* streaming SIMD extensions #3 */ +#define CPUIDECX_PCLMUL 0x00000002 /* Carryless Multiplication */ +#define CPUIDECX_DTES64 0x00000004 /* 64bit debug store */ +#define CPUIDECX_MWAIT 0x00000008 /* Monitor/Mwait */ +#define CPUIDECX_DSCPL 0x00000010 /* CPL Qualified Debug Store */ +#define CPUIDECX_VMX 0x00000020 /* Virtual Machine Extensions */ +#define CPUIDECX_SMX 0x00000040 /* Safer Mode Extensions */ +#define CPUIDECX_EST 0x00000080 /* enhanced SpeedStep */ +#define CPUIDECX_TM2 0x00000100 /* thermal monitor 2 */ +#define CPUIDECX_SSSE3 0x00000200 /* Supplemental Streaming SIMD Ext. 3 */ +#define CPUIDECX_CNXTID 0x00000400 /* Context ID */ +#define CPUIDECX_SDBG 0x00000800 /* Silicon debug capability */ +#define CPUIDECX_FMA3 0x00001000 /* Fused Multiply Add */ +#define CPUIDECX_CX16 0x00002000 /* has CMPXCHG16B instruction */ +#define CPUIDECX_XTPR 0x00004000 /* xTPR Update Control */ +#define CPUIDECX_PDCM 0x00008000 /* Perfmon and Debug Capability */ +#define CPUIDECX_PCID 0x00020000 /* Process-context ID Capability */ +#define CPUIDECX_DCA 0x00040000 /* Direct Cache Access */ +#define CPUIDECX_SSE41 0x00080000 /* Streaming SIMD Extensions 4.1 */ +#define CPUIDECX_SSE42 0x00100000 /* Streaming SIMD Extensions 4.2 */ +#define CPUIDECX_X2APIC 0x00200000 /* Extended xAPIC Support */ +#define CPUIDECX_MOVBE 0x00400000 /* MOVBE Instruction */ +#define CPUIDECX_POPCNT 0x00800000 /* POPCNT Instruction */ +#define CPUIDECX_DEADLINE 0x01000000 /* APIC one-shot via deadline */ +#define CPUIDECX_AES 0x02000000 /* AES Instruction */ +#define CPUIDECX_XSAVE 0x04000000 /* XSAVE/XSTOR States */ +#define CPUIDECX_OSXSAVE 0x08000000 /* OSXSAVE */ +#define CPUIDECX_AVX 0x10000000 /* Advanced Vector Extensions */ +#define CPUIDECX_F16C 0x20000000 /* 16bit fp conversion */ +#define CPUIDECX_RDRAND 0x40000000 /* RDRAND instruction */ +#define CPUIDECX_HV 0x80000000 /* Running on hypervisor */ +#define CPUID_ECX_BITS \ + ("\20" "\01SSE3" "\02PCLMUL" "\03DTES64" "\04MWAIT" "\05DS-CPL" "\06VMX" \ + "\07SMX" "\010EST" "\011TM2" "\012SSSE3" "\013CNXT-ID" "\014SDBG" \ + "\015FMA3" "\016CX16" "\017xTPR" "\020PDCM" "\022PCID" "\023DCA" \ + "\024SSE4.1" "\025SSE4.2" "\026x2APIC" "\027MOVBE" "\030POPCNT" \ + "\031DEADLINE" "\032AES" "\033XSAVE" "\034OSXSAVE" "\035AVX" "\036F16C" \ + "\037RDRAND" "\040HV" ) + +/* + * "Structured Extended Feature Flags Parameters" (CPUID function 0x7, leaf 0) + * EBX bits + */ +#define SEFF0EBX_FSGSBASE 0x00000001 /* {RD,WR}[FG]SBASE instructions */ +#define SEFF0EBX_TSC_ADJUST 0x00000002 /* Has IA32_TSC_ADJUST MSR */ +#define SEFF0EBX_SGX 0x00000004 /* Software Guard Extensions */ +#define SEFF0EBX_BMI1 0x00000008 /* advanced bit manipulation */ +#define SEFF0EBX_HLE 0x00000010 /* Hardware Lock Elision */ +#define SEFF0EBX_AVX2 0x00000020 /* Advanced Vector Extensions 2 */ +#define SEFF0EBX_SMEP 0x00000080 /* Supervisor mode exec protection */ +#define SEFF0EBX_BMI2 0x00000100 /* advanced bit manipulation */ +#define SEFF0EBX_ERMS 0x00000200 /* Enhanced REP MOVSB/STOSB */ +#define SEFF0EBX_INVPCID 0x00000400 /* INVPCID instruction */ +#define SEFF0EBX_RTM 0x00000800 /* Restricted Transactional Memory */ +#define SEFF0EBX_PQM 0x00001000 /* Quality of Service Monitoring */ +#define SEFF0EBX_MPX 0x00004000 /* Memory Protection Extensions */ +#define SEFF0EBX_AVX512F 0x00010000 /* AVX-512 foundation inst */ +#define SEFF0EBX_AVX512DQ 0x00020000 /* AVX-512 double/quadword */ +#define SEFF0EBX_RDSEED 0x00040000 /* RDSEED instruction */ +#define SEFF0EBX_ADX 0x00080000 /* ADCX/ADOX instructions */ +#define SEFF0EBX_SMAP 0x00100000 /* Supervisor mode access prevent */ +#define SEFF0EBX_AVX512IFMA 0x00200000 /* AVX-512 integer mult-add */ +#define SEFF0EBX_PCOMMIT 0x00400000 /* Persistent commit inst */ +#define SEFF0EBX_CLFLUSHOPT 0x00800000 /* cache line flush */ +#define SEFF0EBX_CLWB 0x01000000 /* cache line write back */ +#define SEFF0EBX_PT 0x02000000 /* Processor Trace */ +#define SEFF0EBX_AVX512PF 0x04000000 /* AVX-512 prefetch */ +#define SEFF0EBX_AVX512ER 0x08000000 /* AVX-512 exp/reciprocal */ +#define SEFF0EBX_AVX512CD 0x10000000 /* AVX-512 conflict detection */ +#define SEFF0EBX_SHA 0x20000000 /* SHA Extensions */ +#define SEFF0EBX_AVX512BW 0x40000000 /* AVX-512 byte/word inst */ +#define SEFF0EBX_AVX512VL 0x80000000 /* AVX-512 vector len inst */ +#define SEFF0_EBX_BITS \ + ("\20" "\01FSGSBASE" "\02TSC_ADJUST" "\03SGX" "\04BMI1" "\05HLE" \ + "\06AVX2" "\010SMEP" "\011BMI2" "\012ERMS" "\013INVPCID" "\014RTM" \ + "\015PQM" "\017MPX" "\021AVX512F" "\022AVX512DQ" "\023RDSEED" "\024ADX" \ + "\025SMAP" "\026AVX512IFMA" "\027PCOMMIT" "\030CLFLUSHOPT" "\031CLWB" \ + "\032PT" "\033AVX512PF" "\034AVX512ER" "\035AVX512CD" "\036SHA" \ + "\037AVX512BW" "\040AVX512VL" ) + +/* SEFF ECX bits */ +#define SEFF0ECX_PREFETCHWT1 0x00000001 /* PREFETCHWT1 instruction */ +#define SEFF0ECX_AVX512VBMI 0x00000002 /* AVX-512 vector bit inst */ +#define SEFF0ECX_UMIP 0x00000004 /* UMIP support */ +#define SEFF0ECX_PKU 0x00000008 /* Page prot keys for user mode */ +#define SEFF0ECX_OSPKE 0x00000010 /* OS enabled RD/WRPKRU */ +#define SEFF0ECX_WAITPKG 0x00000020 /* UMONITOR/UMWAIT/TPAUSE insns */ +#define SEFF0ECX_PKS 0x80000000 /* Page prot keys for sup mode */ +#define SEFF0_ECX_BITS \ + ("\20" "\01PREFETCHWT1" "\02AVX512VBMI" "\03UMIP" "\04PKU" "\06WAITPKG" \ + "\040PKS" ) + +/* SEFF EDX bits */ +#define SEFF0EDX_AVX512_4FNNIW 0x00000004 /* AVX-512 neural network insns */ +#define SEFF0EDX_AVX512_4FMAPS 0x00000008 /* AVX-512 mult accum single prec */ +#define SEFF0EDX_SRBDS_CTRL 0x00000200 /* MCU_OPT_CTRL MSR */ +#define SEFF0EDX_MD_CLEAR 0x00000400 /* Microarch Data Clear */ +#define SEFF0EDX_TSXFA 0x00002000 /* TSX Forced Abort */ +#define SEFF0EDX_IBT 0x00100000 /* Indirect Branch Tracking */ +#define SEFF0EDX_IBRS 0x04000000 /* IBRS / IBPB Speculation Control */ +#define SEFF0EDX_STIBP 0x08000000 /* STIBP Speculation Control */ +#define SEFF0EDX_L1DF 0x10000000 /* L1D_FLUSH */ +#define SEFF0EDX_ARCH_CAP 0x20000000 /* Has IA32_ARCH_CAPABILITIES MSR */ +#define SEFF0EDX_SSBD 0x80000000 /* Spec Store Bypass Disable */ +#define SEFF0_EDX_BITS \ + ("\20" "\03AVX512FNNIW" "\04AVX512FMAPS" "\012SRBDS_CTRL" "\013MD_CLEAR" \ + "\016TSXFA" "\025IBT" "\033IBRS,IBPB" "\034STIBP" "\035L1DF" "\040SSBD" ) + +/* + * Thermal and Power Management (CPUID function 0x6) EAX bits + */ +#define TPM_SENSOR 0x00000001 /* Digital temp sensor */ +#define TPM_ARAT 0x00000004 /* APIC Timer Always Running */ +#define TPM_PTS 0x00000040 /* Intel Package Thermal Status */ +#define TPM_EAX_BITS \ + ("\20" "\01SENSOR" "\03ARAT" "\07PTS") +/* Thermal and Power Management (CPUID function 0x6) ECX bits */ +#define TPM_EFFFREQ 0x00000001 /* APERF & MPERF MSR present */ +#define TPM_ECX_BITS \ + ("\20" "\01EFFFREQ" ) + + /* + * "Architectural Performance Monitoring" bits (CPUID function 0x0a): + * EAX bits, EBX bits, EDX bits. + */ + +#define CPUIDEAX_VERID 0x000000ff /* Version ID */ +#define CPUIDEAX_NUM_GC(cpuid) (((cpuid) >> 8) & 0x000000ff) +#define CPUIDEAX_BIT_GC(cpuid) (((cpuid) >> 16) & 0x000000ff) +#define CPUIDEAX_LEN_EBX(cpuid) (((cpuid) >> 24) & 0x000000ff) + +#define CPUIDEBX_EVT_CORE (1 << 0) /* Core cycle */ +#define CPUIDEBX_EVT_INST (1 << 1) /* Instruction retired */ +#define CPUIDEBX_EVT_REFR (1 << 2) /* Reference cycles */ +#define CPUIDEBX_EVT_CACHE_REF (1 << 3) /* Last-level cache ref. */ +#define CPUIDEBX_EVT_CACHE_MIS (1 << 4) /* Last-level cache miss. */ +#define CPUIDEBX_EVT_BRANCH_INST (1 << 5) /* Branch instruction ret. */ +#define CPUIDEBX_EVT_BRANCH_MISP (1 << 6) /* Branch mispredict ret. */ + +#define CPUIDEDX_NUM_FC(cpuid) (((cpuid) >> 0) & 0x0000001f) +#define CPUIDEDX_BIT_FC(cpuid) (((cpuid) >> 5) & 0x000000ff) + +/* + * CPUID "extended features" bits (CPUID function 0x80000001): + * EDX bits, then ECX bits + */ + +#define CPUID_MPC 0x00080000 /* Multiprocessing Capable */ +#define CPUID_NXE 0x00100000 /* No-Execute Extension */ +#define CPUID_MMXX 0x00400000 /* AMD MMX Extensions */ +#define CPUID_FFXSR 0x02000000 /* fast FP/MMX save/restore */ +#define CPUID_PAGE1GB 0x04000000 /* 1-GByte pages */ +#define CPUID_RDTSCP 0x08000000 /* RDTSCP / IA32_TSC_AUX available */ +#define CPUID_LONG 0x20000000 /* long mode */ +#define CPUID_3DNOW2 0x40000000 /* 3DNow! Instruction Extension */ +#define CPUID_3DNOW 0x80000000 /* 3DNow! Instructions */ +#define CPUIDE_EDX_BITS \ + ("\20" "\024MPC" "\025NXE" "\027MMXX" "\032FFXSR" "\033PAGE1GB" \ + "\034RDTSCP" "\036LONG" "\0373DNOW2" "\0403DNOW" ) + +#define CPUIDECX_LAHF 0x00000001 /* LAHF and SAHF instructions */ +#define CPUIDECX_CMPLEG 0x00000002 /* Core MP legacy mode */ +#define CPUIDECX_SVM 0x00000004 /* Secure Virtual Machine */ +#define CPUIDECX_EAPICSP 0x00000008 /* Extended APIC space */ +#define CPUIDECX_AMCR8 0x00000010 /* LOCK MOV CR0 means MOV CR8 */ +#define CPUIDECX_ABM 0x00000020 /* LZCNT instruction */ +#define CPUIDECX_SSE4A 0x00000040 /* SSE4-A instruction set */ +#define CPUIDECX_MASSE 0x00000080 /* Misaligned SSE mode */ +#define CPUIDECX_3DNOWP 0x00000100 /* 3DNowPrefetch */ +#define CPUIDECX_OSVW 0x00000200 /* OS visible workaround */ +#define CPUIDECX_IBS 0x00000400 /* Instruction based sampling */ +#define CPUIDECX_XOP 0x00000800 /* Extended operating support */ +#define CPUIDECX_SKINIT 0x00001000 /* SKINIT and STGI are supported */ +#define CPUIDECX_WDT 0x00002000 /* Watchdog timer */ +/* Reserved 0x00004000 */ +#define CPUIDECX_LWP 0x00008000 /* Lightweight profiling support */ +#define CPUIDECX_FMA4 0x00010000 /* 4-operand FMA instructions */ +#define CPUIDECX_TCE 0x00020000 /* Translation Cache Extension */ +/* Reserved 0x00040000 */ +#define CPUIDECX_NODEID 0x00080000 /* Support for MSRC001C */ +/* Reserved 0x00100000 */ +#define CPUIDECX_TBM 0x00200000 /* Trailing bit manipulation instruction */ +#define CPUIDECX_TOPEXT 0x00400000 /* Topology extensions support */ +#define CPUIDECX_CPCTR 0x00800000 /* core performance counter ext */ +#define CPUIDECX_DBKP 0x04000000 /* DataBreakpointExtension */ +#define CPUIDECX_PERFTSC 0x08000000 /* performance time-stamp counter */ +#define CPUIDECX_PCTRL3 0x10000000 /* L3 performance counter ext */ +#define CPUIDECX_MWAITX 0x20000000 /* MWAITX/MONITORX */ +#define CPUIDE_ECX_BITS \ + ("\20" "\01LAHF" "\02CMPLEG" "\03SVM" "\04EAPICSP" "\05AMCR8" "\06ABM" \ + "\07SSE4A" "\010MASSE" "\0113DNOWP" "\012OSVW" "\013IBS" "\014XOP" \ + "\015SKINIT" "\020WDT" "\021FMA4" "\022TCE" "\024NODEID" "\026TBM" \ + "\027TOPEXT" "\030CPCTR" "\033DBKP" "\034PERFTSC" "\035PCTRL3" \ + "\036MWAITX" ) + +/* + * "Advanced Power Management Information" bits (CPUID function 0x80000007): + * EDX bits. + */ +#define CPUIDEDX_HWPSTATE (1 << 7) /* Hardware P State Control */ +#define CPUIDEDX_ITSC (1 << 8) /* Invariant TSC */ +#define CPUID_APMI_EDX_BITS \ + ("\20" "\010HWPSTATE" "\011ITSC" ) + +/* + * AMD CPUID function 0x80000008 EBX bits + */ +#define CPUIDEBX_INVLPGB (1ULL << 3) /* INVLPG w/broadcast */ +#define CPUIDEBX_IBPB (1ULL << 12) /* Speculation Control IBPB */ +#define CPUIDEBX_IBRS (1ULL << 14) /* Speculation Control IBRS */ +#define CPUIDEBX_STIBP (1ULL << 15) /* Speculation Control STIBP */ +#define CPUIDEBX_IBRS_ALWAYSON (1ULL << 16) /* IBRS always on mode */ +#define CPUIDEBX_STIBP_ALWAYSON (1ULL << 17) /* STIBP always on mode */ +#define CPUIDEBX_IBRS_PREF (1ULL << 18) /* IBRS preferred */ +#define CPUIDEBX_IBRS_SAME_MODE (1ULL << 19) /* IBRS not mode-specific */ +#define CPUIDEBX_SSBD (1ULL << 24) /* Speculation Control SSBD */ +#define CPUIDEBX_VIRT_SSBD (1ULL << 25) /* Virt Spec Control SSBD */ +#define CPUIDEBX_SSBD_NOTREQ (1ULL << 26) /* SSBD not required */ +#define CPUID_AMDSPEC_EBX_BITS \ + ("\20" "\04INVLPGB" "\015IBPB" "\017IBRS" "\020STIBP" "\021IBRS_ALL" \ + "\022STIBP_ALL" "\023IBRS_PREF" "\024IBRS_SM" "\031SSBD" "\032VIRTSSBD" \ + "\033SSBDNR" ) + +/* + * AMD CPUID function 0x8000001F EAX bits + */ +#define CPUIDEAX_SME (1ULL << 0) /* SME */ +#define CPUIDEAX_SEV (1ULL << 1) /* SEV */ +#define CPUIDEAX_PFLUSH_MSR (1ULL << 2) /* Page Flush MSR */ +#define CPUIDEAX_SEVES (1ULL << 3) /* SEV-ES */ +#define CPUIDEAX_SEVSNP (1ULL << 4) /* SEV-SNP */ +#define CPUIDEAX_VMPL (1ULL << 5) /* VM Permission Levels */ +#define CPUIDEAX_RMPQUERY (1ULL << 6) /* RMPQUERY */ +#define CPUIDEAX_VMPLSSS (1ULL << 7) /* VMPL Supervisor Shadow Stack */ +#define CPUIDEAX_SECTSC (1ULL << 8) /* Secure TSC */ +#define CPUIDEAX_TSCAUXVIRT (1ULL << 9) /* TSC Aux Virtualization */ +#define CPUIDEAX_HWECACHECOH (1ULL << 10) /* Coherency Across Enc. Domains */ +#define CPUIDEAX_64BITHOST (1ULL << 11) /* SEV guest requires 64bit host */ +#define CPUIDEAX_RESTINJ (1ULL << 12) /* Restricted Injection */ +#define CPUIDEAX_ALTINJ (1ULL << 13) /* Alternate Injection */ +#define CPUIDEAX_DBGSTSW (1ULL << 14) /* Full debug state swap */ +#define CPUIDEAX_IBSDISALLOW (1ULL << 15) /* Disallowing IBS use by host */ +#define CPUIDEAX_VTE (1ULL << 16) /* Virt. Transparent Encryption */ +#define CPUIDEAX_VMGEXITPARAM (1ULL << 17) /* VMGEXIT Parameter */ +#define CPUIDEAX_VTOMMSR (1ULL << 18) /* Virtual TOM MSR */ +#define CPUIDEAX_IBSVIRT (1ULL << 19) /* IBS Virtualization for SEV-ES */ +#define CPUIDEAX_VMSARPROT (1ULL << 24) /* VMSA Register Protection */ +#define CPUIDEAX_SMTPROT (1ULL << 25) /* SMT Protection */ +#define CPUIDEAX_SVSMPAGEMSR (1ULL << 28) /* SVSM Communication Page MSR */ +#define CPUIDEAX_NVSMSR (1ULL << 29) /* NestedVirtSnpMsr */ +#define CPUID_AMDSEV_EAX_BITS \ + ("\20" "\01SME" "\02SEV" "\03PFLUSH_MSR" "\04SEVES" "\05SEVSNP" "\06VMPL" \ + "\07RMPQUERY" "\010VMPLSSS" "\011SECTSC" "\012TSCAUXVIRT" \ + "\013HWECACHECOH" "\014REQ64BITHOST" "\015RESTINJ" "\016ALTINJ" \ + "\017DBGSTSW" "\020IBSDISALLOW" "\021VTE" "\022VMGEXITPARAM" \ + "\023VTOMMSR" "\024IBSVIRT" "\031VMSARPROT" "\032SMTPROT" \ + "\035SVSMPAGEMSR" "\036NVSMSR" ) + +/* Number of encrypted guests */ +#define CPUID_AMDSEV_ECX_BITS ("\20") + +/* Minimum ASID for SEV enabled, SEV-ES disabled guest. */ +#define CPUID_AMDSEV_EDX_BITS ("\20") + +#define CPUID2FAMILY(cpuid) (((cpuid) >> 8) & 15) +#define CPUID2MODEL(cpuid) (((cpuid) >> 4) & 15) +#define CPUID2STEPPING(cpuid) ((cpuid) & 15) + +#define CPUID(code, eax, ebx, ecx, edx) \ + __asm volatile("cpuid" \ + : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) \ + : "a" (code)) +#define CPUID_LEAF(code, leaf, eax, ebx, ecx, edx) \ + __asm volatile("cpuid" \ + : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) \ + : "a" (code), "c" (leaf)) + + +/* + * Model-specific registers for the i386 family + */ +#define MSR_P5_MC_ADDR 0x000 /* P5 only */ +#define MSR_P5_MC_TYPE 0x001 /* P5 only */ +#define MSR_TSC 0x010 +#define MSR_CESR 0x011 /* P5 only (trap on P6) */ +#define MSR_CTR0 0x012 /* P5 only (trap on P6) */ +#define MSR_CTR1 0x013 /* P5 only (trap on P6) */ +#define MSR_PLATFORM_ID 0x017 /* Platform ID for microcode */ +#define MSR_APICBASE 0x01b +#define APICBASE_BSP 0x100 +#define APICBASE_ENABLE_X2APIC 0x400 +#define APICBASE_GLOBAL_ENABLE 0x800 +#define MSR_EBL_CR_POWERON 0x02a +#define MSR_EBC_FREQUENCY_ID 0x02c /* Pentium 4 only */ +#define MSR_TEST_CTL 0x033 +#define MSR_IA32_FEATURE_CONTROL 0x03a +#define MSR_TSC_ADJUST 0x03b +#define MSR_SPEC_CTRL 0x048 /* Speculation Control IBRS / STIBP */ +#define SPEC_CTRL_IBRS (1ULL << 0) +#define SPEC_CTRL_STIBP (1ULL << 1) +#define SPEC_CTRL_SSBD (1ULL << 2) +#define MSR_PRED_CMD 0x049 /* Speculation Control IBPB */ +#define PRED_CMD_IBPB (1ULL << 0) +#define MSR_BIOS_UPDT_TRIG 0x079 +#define MSR_BBL_CR_D0 0x088 /* PII+ only */ +#define MSR_BBL_CR_D1 0x089 /* PII+ only */ +#define MSR_BBL_CR_D2 0x08a /* PII+ only */ +#define MSR_BIOS_SIGN 0x08b +#define MSR_SMM_MONITOR_CTL 0x09b +#define MSR_SMBASE 0x09e +#define MSR_PERFCTR0 0x0c1 +#define MSR_PERFCTR1 0x0c2 +#define MSR_FSB_FREQ 0x0cd /* Core Duo/Solo only */ +#define MSR_MPERF 0x0e7 +#define MSR_APERF 0x0e8 +#define MSR_MTRRcap 0x0fe +#define MTRRcap_FIXED 0x100 /* bit 8 - fixed MTRRs supported */ +#define MTRRcap_WC 0x400 /* bit 10 - WC type supported */ +#define MTRRcap_SMRR 0x800 /* bit 11 - SMM range reg supported */ +#define MSR_ARCH_CAPABILITIES 0x10a +#define ARCH_CAP_RDCL_NO (1 << 0) /* Meltdown safe */ +#define ARCH_CAP_IBRS_ALL (1 << 1) /* enhanced IBRS */ +#define ARCH_CAP_RSBA (1 << 2) /* RSB Alternate */ +#define ARCH_CAP_SKIP_L1DFL_VMENTRY (1 << 3) +#define ARCH_CAP_SSB_NO (1 << 4) /* Spec St Byp safe */ +#define ARCH_CAP_MDS_NO (1 << 5) /* microarch data-sampling */ +#define ARCH_CAP_IF_PSCHANGE_MC_NO (1 << 6) /* PS MCE safe */ +#define ARCH_CAP_TSX_CTRL (1 << 7) /* has TSX_CTRL MSR */ +#define ARCH_CAP_TAA_NO (1 << 8) /* TSX AA safe */ +#define ARCH_CAP_MCU_CONTROL (1 << 9) /* has MCU_CTRL MSR */ +#define ARCH_CAP_MISC_PACKAGE_CTLS (1 << 10) /* has MISC_PKG_CTLS MSR */ +#define ARCH_CAP_ENERGY_FILTERING_CTL (1 << 11) /* r/w energy fltring bit */ +#define ARCH_CAP_DOITM (1 << 12) /* Data oprnd indpdnt tmng */ +#define ARCH_CAP_SBDR_SSDP_NO (1 << 13) /* SBDR/SSDP safe */ +#define ARCH_CAP_FBSDP_NO (1 << 14) /* FBSDP safe */ +#define ARCH_CAP_PSDP_NO (1 << 15) /* PSDP safe */ +#define ARCH_CAP_FB_CLEAR (1 << 17) /* MD_CLEAR covers FB */ +#define ARCH_CAP_FB_CLEAR_CTRL (1 << 18) +#define ARCH_CAP_RRSBA (1 << 19) /* has RRSBA if not dis */ +#define ARCH_CAP_BHI_NO (1 << 20) /* BHI safe */ +#define ARCH_CAP_XAPIC_DISABLE_STATUS (1 << 21) /* can disable xAPIC */ +#define ARCH_CAP_OVERCLOCKING_STATUS (1 << 23) /* has OVRCLCKNG_STAT MSR */ +#define ARCH_CAP_PBRSB_NO (1 << 24) /* PBSR safe */ +#define ARCH_CAP_GDS_CTRL (1 << 25) /* has GDS_MITG_DIS/LOCK */ +#define ARCH_CAP_GDS_NO (1 << 26) /* GDS safe */ +#define ARCH_CAP_RFDS_NO (1 << 27) /* RFDS safe */ +#define ARCH_CAP_RFDS_CLEAR (1 << 28) /* use VERW for RFDS */ +#define ARCH_CAP_MSR_BITS \ + ("\20" "\02IBRS_ALL" "\03RSBA" "\04SKIP_L1DFL" "\05SSB_NO" "\06MDS_NO" \ + "\07IF_PSCHANGE" "\010TSX_CTRL" "\011TAA_NO" "\012MCU_CONTROL" \ + "\013MISC_PKG_CT" "\014ENERGY_FILT" "\015DOITM" "\016SBDR_SSDP_N" \ + "\017FBSDP_NO" "\020PSDP_NO" "\022FB_CLEAR" "\023FB_CLEAR_CT" \ + "\024RRSBA" "\025BHI_NO" "\026XAPIC_DIS" "\030OVERCLOCK" "\031PBRSB_NO" \ + "\032GDS_CTRL" "\033GDS_NO" "\034RFDS_NO" "\035RFDS_CLEAR" ) + +#define MSR_FLUSH_CMD 0x10b +#define FLUSH_CMD_L1D_FLUSH 0x1 /* (1ULL << 0) */ +#define MSR_BBL_CR_ADDR 0x116 /* PII+ only */ +#define MSR_BBL_CR_DECC 0x118 /* PII+ only */ +#define MSR_BBL_CR_CTL 0x119 /* PII+ only */ +#define MSR_BBL_CR_TRIG 0x11a /* PII+ only */ +#define MSR_BBL_CR_BUSY 0x11b /* PII+ only */ +#define MSR_BBL_CR_CTR3 0x11e /* PII+ only */ +#define MSR_TSX_CTRL 0x122 +#define TSX_CTRL_RTM_DISABLE (1ULL << 0) +#define TSX_CTRL_TSX_CPUID_CLEAR (1ULL << 1) +#define MSR_MCU_OPT_CTRL 0x123 +#define RNGDS_MITG_DIS (1ULL << 0) +#define MSR_SYSENTER_CS 0x174 /* PII+ only */ +#define MSR_SYSENTER_ESP 0x175 /* PII+ only */ +#define MSR_SYSENTER_EIP 0x176 /* PII+ only */ +#define MSR_MCG_CAP 0x179 +#define MSR_MCG_STATUS 0x17a +#define MSR_MCG_CTL 0x17b +#define MSR_EVNTSEL0 0x186 +#define MSR_EVNTSEL1 0x187 +#define MSR_PERF_STATUS 0x198 /* Pentium M */ +#define MSR_PERF_CTL 0x199 /* Pentium M */ +#define PERF_CTL_TURBO 0x100000000ULL /* bit 32 - turbo mode */ +#define MSR_THERM_CONTROL 0x19a +#define MSR_THERM_INTERRUPT 0x19b +#define MSR_THERM_STATUS 0x19c +#define MSR_THERM_STATUS_VALID_BIT 0x80000000 +#define MSR_THERM_STATUS_TEMP(msr) ((msr >> 16) & 0x7f) +#define MSR_THERM2_CTL 0x19d /* Pentium M */ +#define MSR_MISC_ENABLE 0x1a0 +/* + * MSR_MISC_ENABLE (0x1a0) + * + * Enable Fast Strings: enables fast REP MOVS/REP STORS (R/W) + * Enable TCC: Enable automatic thermal control circuit (R/W) + * Performance monitoring available: 1 if enabled (R/O) + * Branch trace storage unavailable: 1 if unsupported (R/O) + * Processor event based sampling unavailable: 1 if unsupported (R/O) + * Enhanced Intel SpeedStep technology enable: 1 to enable (R/W) + * Enable monitor FSM: 1 to enable MONITOR/MWAIT (R/W) + * Limit CPUID maxval: 1 to limit CPUID leaf nodes to 0x2 and lower (R/W) + * Enable xTPR message disable: 1 to disable xTPR messages + * XD bit disable: 1 to disable NX capability (bit 34, or bit 2 of %edx/%rdx) + */ +#define MISC_ENABLE_FAST_STRINGS (1 << 0) +#define MISC_ENABLE_TCC (1 << 3) +#define MISC_ENABLE_PERF_MON_AVAILABLE (1 << 7) +#define MISC_ENABLE_BTS_UNAVAILABLE (1 << 11) +#define MISC_ENABLE_PEBS_UNAVAILABLE (1 << 12) +#define MISC_ENABLE_EIST_ENABLED (1 << 16) +#define MISC_ENABLE_ENABLE_MONITOR_FSM (1 << 18) +#define MISC_ENABLE_LIMIT_CPUID_MAXVAL (1 << 22) +#define MISC_ENABLE_xTPR_MESSAGE_DISABLE (1 << 23) +#define MISC_ENABLE_XD_BIT_DISABLE (1 << 2) + +/* + * for Core i Series and newer Xeons, see + * http://www.intel.com/content/dam/www/public/us/en/ + * documents/white-papers/cpu-monitoring-dts-peci-paper.pdf + */ +#define MSR_TEMPERATURE_TARGET 0x1a2 /* Core i Series, Newer Xeons */ +#define MSR_TEMPERATURE_TARGET_TJMAX(msr) (((msr) >> 16) & 0xff) +/* + * not documented anywhere, see intelcore_update_sensor() + * only available Core Duo and Core Solo Processors + */ +#define MSR_TEMPERATURE_TARGET_UNDOCUMENTED 0x0ee +#define MSR_TEMPERATURE_TARGET_LOW_BIT_UNDOCUMENTED 0x40000000 +#define MSR_DEBUGCTLMSR 0x1d9 +#define MSR_LASTBRANCHFROMIP 0x1db +#define MSR_LASTBRANCHTOIP 0x1dc +#define MSR_LASTINTFROMIP 0x1dd +#define MSR_LASTINTTOIP 0x1de +#define MSR_ROB_CR_BKUPTMPDR6 0x1e0 +#define MSR_MTRRvarBase 0x200 +#define MSR_MTRRfix64K_00000 0x250 +#define MSR_MTRRfix16K_80000 0x258 +#define MSR_MTRRfix4K_C0000 0x268 +#define MSR_CR_PAT 0x277 +#define MSR_MTRRdefType 0x2ff +#define MTRRdefType_FIXED_ENABLE 0x400 /* bit 10 - fixed MTRR enabled */ +#define MTRRdefType_ENABLE 0x800 /* bit 11 - MTRRs enabled */ +#define MSR_PERF_FIXED_CTR1 0x30a /* CPU_CLK_Unhalted.Core */ +#define MSR_PERF_FIXED_CTR2 0x30b /* CPU_CLK.Unhalted.Ref */ +#define MSR_PERF_FIXED_CTR_CTRL 0x38d +#define MSR_PERF_FIXED_CTR_FC_DIS 0x0 /* disable counter */ +#define MSR_PERF_FIXED_CTR_FC_1 0x1 /* count ring 1 */ +#define MSR_PERF_FIXED_CTR_FC_123 0x2 /* count rings 1,2,3 */ +#define MSR_PERF_FIXED_CTR_FC_ANY 0x3 /* count everything */ +#define MSR_PERF_FIXED_CTR_FC_MASK 0x3 +#define MSR_PERF_FIXED_CTR_FC(_i, _v) ((_v) << (4 * (_i))) +#define MSR_PERF_FIXED_CTR_ANYTHR(_i) (0x4 << (4 * (_i))) +#define MSR_PERF_FIXED_CTR_INT(_i) (0x8 << (4 * (_i))) +#define MSR_PERF_GLOBAL_CTRL 0x38f +#define MSR_PERF_GLOBAL_CTR1_EN (1ULL << 33) +#define MSR_PERF_GLOBAL_CTR2_EN (1ULL << 34) +#define MSR_PKG_C3_RESIDENCY 0x3f8 +#define MSR_PKG_C6_RESIDENCY 0x3f9 +#define MSR_PKG_C7_RESIDENCY 0x3fa +#define MSR_CORE_C3_RESIDENCY 0x3fc +#define MSR_CORE_C6_RESIDENCY 0x3fd +#define MSR_CORE_C7_RESIDENCY 0x3fe +#define MSR_MC0_CTL 0x400 +#define MSR_MC0_STATUS 0x401 +#define MSR_MC0_ADDR 0x402 +#define MSR_MC0_MISC 0x403 +#define MSR_MC1_CTL 0x404 +#define MSR_MC1_STATUS 0x405 +#define MSR_MC1_ADDR 0x406 +#define MSR_MC1_MISC 0x407 +#define MSR_MC2_CTL 0x408 +#define MSR_MC2_STATUS 0x409 +#define MSR_MC2_ADDR 0x40a +#define MSR_MC2_MISC 0x40b +#define MSR_MC4_CTL 0x40c +#define MSR_MC4_STATUS 0x40d +#define MSR_MC4_ADDR 0x40e +#define MSR_MC4_MISC 0x40f +#define MSR_MC3_CTL 0x410 +#define MSR_MC3_STATUS 0x411 +#define MSR_MC3_ADDR 0x412 +#define MSR_MC3_MISC 0x413 +#define MSR_PKG_C2_RESIDENCY 0x60d +#define MSR_PKG_C8_RESIDENCY 0x630 +#define MSR_PKG_C9_RESIDENCY 0x631 +#define MSR_PKG_C10_RESIDENCY 0x632 +#define MSR_U_CET 0x6a0 +#define MSR_CET_ENDBR_EN (1 << 2) +#define MSR_CET_NO_TRACK_EN (1 << 4) +#define MSR_S_CET 0x6a2 +#define MSR_PKRS 0x6e1 +#define MSR_XSS 0xda0 + +/* VIA MSR */ +#define MSR_CENT_TMTEMPERATURE 0x1423 /* Thermal monitor temperature */ + +/* + * AMD K6/K7 MSRs. + */ +#define MSR_K6_UWCCR 0xc0000085 +#define MSR_K7_EVNTSEL0 0xc0010000 +#define MSR_K7_EVNTSEL1 0xc0010001 +#define MSR_K7_EVNTSEL2 0xc0010002 +#define MSR_K7_EVNTSEL3 0xc0010003 +#define MSR_K7_PERFCTR0 0xc0010004 +#define MSR_K7_PERFCTR1 0xc0010005 +#define MSR_K7_PERFCTR2 0xc0010006 +#define MSR_K7_PERFCTR3 0xc0010007 + +/* + * AMD K8 (Opteron) MSRs. + */ +#define MSR_PATCH_LEVEL 0x0000008b +#define MSR_SYSCFG 0xc0000010 + +#define MSR_EFER 0xc0000080 /* Extended feature enable */ +#define EFER_SCE 0x00000001 /* SYSCALL extension */ +#define EFER_LME 0x00000100 /* Long Mode Enabled */ +#define EFER_LMA 0x00000400 /* Long Mode Active */ +#define EFER_NXE 0x00000800 /* No-Execute Enabled */ +#define EFER_SVME 0x00001000 /* SVM Enabled */ + +#define MSR_STAR 0xc0000081 /* 32 bit syscall gate addr */ +#define MSR_LSTAR 0xc0000082 /* 64 bit syscall gate addr */ +#define MSR_CSTAR 0xc0000083 /* compat syscall gate addr */ +#define MSR_SFMASK 0xc0000084 /* flags to clear on syscall */ + +#define MSR_FSBASE 0xc0000100 /* 64bit offset for fs: */ +#define MSR_GSBASE 0xc0000101 /* 64bit offset for gs: */ +#define MSR_KERNELGSBASE 0xc0000102 /* storage for swapgs ins */ +#define MSR_PATCH_LOADER 0xc0010020 +#define MSR_INT_PEN_MSG 0xc0010055 /* Interrupt pending message */ + +#define MSR_DE_CFG 0xc0011029 /* Decode Configuration */ +#define DE_CFG_721 0x00000001 /* errata 721 */ +#define DE_CFG_SERIALIZE_LFENCE (1 << 1) /* Enable serializing lfence */ +#define DE_CFG_SERIALIZE_9 (1 << 9) /* Zenbleed chickenbit */ + +#define IPM_C1E_CMP_HLT 0x10000000 +#define IPM_SMI_CMP_HLT 0x08000000 + +/* + * These require a 'passcode' for access. See cpufunc.h. + */ +#define MSR_HWCR 0xc0010015 +#define HWCR_FFDIS 0x00000040 +#define HWCR_TSCFREQSEL 0x01000000 + +#define MSR_PSTATEDEF(_n) (0xc0010064 + (_n)) +#define PSTATEDEF_EN 0x8000000000000000ULL + +#define MSR_NB_CFG 0xc001001f +#define NB_CFG_DISIOREQLOCK 0x0000000000000004ULL +#define NB_CFG_DISDATMSK 0x0000001000000000ULL + +#define MSR_SEV_GHCB 0xc0010130 +#define SEV_CPUID_REQ 0x00000004 +#define SEV_CPUID_RESP 0x00000005 + +#define MSR_SEV_STATUS 0xc0010131 +#define SEV_STAT_ENABLED 0x00000001 +#define SEV_STAT_ES_ENABLED 0x00000002 + +#define MSR_LS_CFG 0xc0011020 +#define LS_CFG_DIS_LS2_SQUISH 0x02000000 + +#define MSR_IC_CFG 0xc0011021 +#define IC_CFG_DIS_SEQ_PREFETCH 0x00000800 + +#define MSR_DC_CFG 0xc0011022 +#define DC_CFG_DIS_CNV_WC_SSO 0x00000004 +#define DC_CFG_DIS_SMC_CHK_BUF 0x00000400 + +#define MSR_BU_CFG 0xc0011023 +#define BU_CFG_THRL2IDXCMPDIS 0x0000080000000000ULL +#define BU_CFG_WBPFSMCCHKDIS 0x0000200000000000ULL +#define BU_CFG_WBENHWSBDIS 0x0001000000000000ULL + +/* + * Constants related to MTRRs + */ +#define MTRR_N64K 8 /* numbers of fixed-size entries */ +#define MTRR_N16K 16 +#define MTRR_N4K 64 + +/* + * the following four 3-byte registers control the non-cacheable regions. + * These registers must be written as three separate bytes. + * + * NCRx+0: A31-A24 of starting address + * NCRx+1: A23-A16 of starting address + * NCRx+2: A15-A12 of starting address | NCR_SIZE_xx. + * + * The non-cacheable region's starting address must be aligned to the + * size indicated by the NCR_SIZE_xx field. + */ +#define NCR1 0xc4 +#define NCR2 0xc7 +#define NCR3 0xca +#define NCR4 0xcd + +#define NCR_SIZE_0K 0 +#define NCR_SIZE_4K 1 +#define NCR_SIZE_8K 2 +#define NCR_SIZE_16K 3 +#define NCR_SIZE_32K 4 +#define NCR_SIZE_64K 5 +#define NCR_SIZE_128K 6 +#define NCR_SIZE_256K 7 +#define NCR_SIZE_512K 8 +#define NCR_SIZE_1M 9 +#define NCR_SIZE_2M 10 +#define NCR_SIZE_4M 11 +#define NCR_SIZE_8M 12 +#define NCR_SIZE_16M 13 +#define NCR_SIZE_32M 14 +#define NCR_SIZE_4G 15 + +/* + * Performance monitor events. + * + * Note that 586-class and 686-class CPUs have different performance + * monitors available, and they are accessed differently: + * + * 686-class: `rdpmc' instruction + * 586-class: `rdmsr' instruction, CESR MSR + * + * The descriptions of these events are too lengthy to include here. + * See Appendix A of "Intel Architecture Software Developer's + * Manual, Volume 3: System Programming" for more information. + */ + +/* + * 586-class CESR MSR format. Lower 16 bits is CTR0, upper 16 bits + * is CTR1. + */ + +#define PMC5_CESR_EVENT 0x003f +#define PMC5_CESR_OS 0x0040 +#define PMC5_CESR_USR 0x0080 +#define PMC5_CESR_E 0x0100 +#define PMC5_CESR_P 0x0200 + +#define PMC5_DATA_READ 0x00 +#define PMC5_DATA_WRITE 0x01 +#define PMC5_DATA_TLB_MISS 0x02 +#define PMC5_DATA_READ_MISS 0x03 +#define PMC5_DATA_WRITE_MISS 0x04 +#define PMC5_WRITE_M_E 0x05 +#define PMC5_DATA_LINES_WBACK 0x06 +#define PMC5_DATA_CACHE_SNOOP 0x07 +#define PMC5_DATA_CACHE_SNOOP_HIT 0x08 +#define PMC5_MEM_ACCESS_BOTH_PIPES 0x09 +#define PMC5_BANK_CONFLICTS 0x0a +#define PMC5_MISALIGNED_DATA 0x0b +#define PMC5_INST_READ 0x0c +#define PMC5_INST_TLB_MISS 0x0d +#define PMC5_INST_CACHE_MISS 0x0e +#define PMC5_SEGMENT_REG_LOAD 0x0f +#define PMC5_BRANCHES 0x12 +#define PMC5_BTB_HITS 0x13 +#define PMC5_BRANCH_TAKEN 0x14 +#define PMC5_PIPELINE_FLUSH 0x15 +#define PMC5_INST_EXECUTED 0x16 +#define PMC5_INST_EXECUTED_V_PIPE 0x17 +#define PMC5_BUS_UTILIZATION 0x18 +#define PMC5_WRITE_BACKUP_STALL 0x19 +#define PMC5_DATA_READ_STALL 0x1a +#define PMC5_WRITE_E_M_STALL 0x1b +#define PMC5_LOCKED_BUS 0x1c +#define PMC5_IO_CYCLE 0x1d +#define PMC5_NONCACHE_MEM_READ 0x1e +#define PMC5_AGI_STALL 0x1f +#define PMC5_FLOPS 0x22 +#define PMC5_BP0_MATCH 0x23 +#define PMC5_BP1_MATCH 0x24 +#define PMC5_BP2_MATCH 0x25 +#define PMC5_BP3_MATCH 0x26 +#define PMC5_HARDWARE_INTR 0x27 +#define PMC5_DATA_RW 0x28 +#define PMC5_DATA_RW_MISS 0x29 + +/* + * 686-class Event Selector MSR format. + */ + +#define PMC6_EVTSEL_EVENT 0x000000ff +#define PMC6_EVTSEL_UNIT 0x0000ff00 +#define PMC6_EVTSEL_UNIT_SHIFT 8 +#define PMC6_EVTSEL_USR (1 << 16) +#define PMC6_EVTSEL_OS (1 << 17) +#define PMC6_EVTSEL_E (1 << 18) +#define PMC6_EVTSEL_PC (1 << 19) +#define PMC6_EVTSEL_INT (1 << 20) +#define PMC6_EVTSEL_EN (1 << 22) /* PerfEvtSel0 only */ +#define PMC6_EVTSEL_INV (1 << 23) +#define PMC6_EVTSEL_COUNTER_MASK 0xff000000 +#define PMC6_EVTSEL_COUNTER_MASK_SHIFT 24 + +/* Data Cache Unit */ +#define PMC6_DATA_MEM_REFS 0x43 +#define PMC6_DCU_LINES_IN 0x45 +#define PMC6_DCU_M_LINES_IN 0x46 +#define PMC6_DCU_M_LINES_OUT 0x47 +#define PMC6_DCU_MISS_OUTSTANDING 0x48 + +/* Instruction Fetch Unit */ +#define PMC6_IFU_IFETCH 0x80 +#define PMC6_IFU_IFETCH_MISS 0x81 +#define PMC6_ITLB_MISS 0x85 +#define PMC6_IFU_MEM_STALL 0x86 +#define PMC6_ILD_STALL 0x87 + +/* L2 Cache */ +#define PMC6_L2_IFETCH 0x28 +#define PMC6_L2_LD 0x29 +#define PMC6_L2_ST 0x2a +#define PMC6_L2_LINES_IN 0x24 +#define PMC6_L2_LINES_OUT 0x26 +#define PMC6_L2_M_LINES_INM 0x25 +#define PMC6_L2_M_LINES_OUTM 0x27 +#define PMC6_L2_RQSTS 0x2e +#define PMC6_L2_ADS 0x21 +#define PMC6_L2_DBUS_BUSY 0x22 +#define PMC6_L2_DBUS_BUSY_RD 0x23 + +/* External Bus Logic */ +#define PMC6_BUS_DRDY_CLOCKS 0x62 +#define PMC6_BUS_LOCK_CLOCKS 0x63 +#define PMC6_BUS_REQ_OUTSTANDING 0x60 +#define PMC6_BUS_TRAN_BRD 0x65 +#define PMC6_BUS_TRAN_RFO 0x66 +#define PMC6_BUS_TRANS_WB 0x67 +#define PMC6_BUS_TRAN_IFETCH 0x68 +#define PMC6_BUS_TRAN_INVAL 0x69 +#define PMC6_BUS_TRAN_PWR 0x6a +#define PMC6_BUS_TRANS_P 0x6b +#define PMC6_BUS_TRANS_IO 0x6c +#define PMC6_BUS_TRAN_DEF 0x6d +#define PMC6_BUS_TRAN_BURST 0x6e +#define PMC6_BUS_TRAN_ANY 0x70 +#define PMC6_BUS_TRAN_MEM 0x6f +#define PMC6_BUS_DATA_RCV 0x64 +#define PMC6_BUS_BNR_DRV 0x61 +#define PMC6_BUS_HIT_DRV 0x7a +#define PMC6_BUS_HITM_DRDV 0x7b +#define PMC6_BUS_SNOOP_STALL 0x7e + +/* Floating Point Unit */ +#define PMC6_FLOPS 0xc1 +#define PMC6_FP_COMP_OPS_EXE 0x10 +#define PMC6_FP_ASSIST 0x11 +#define PMC6_MUL 0x12 +#define PMC6_DIV 0x12 +#define PMC6_CYCLES_DIV_BUSY 0x14 + +/* Memory Ordering */ +#define PMC6_LD_BLOCKS 0x03 +#define PMC6_SB_DRAINS 0x04 +#define PMC6_MISALIGN_MEM_REF 0x05 +#define PMC6_EMON_KNI_PREF_DISPATCHED 0x07 /* P-III only */ +#define PMC6_EMON_KNI_PREF_MISS 0x4b /* P-III only */ + +/* Instruction Decoding and Retirement */ +#define PMC6_INST_RETIRED 0xc0 +#define PMC6_UOPS_RETIRED 0xc2 +#define PMC6_INST_DECODED 0xd0 +#define PMC6_EMON_KNI_INST_RETIRED 0xd8 +#define PMC6_EMON_KNI_COMP_INST_RET 0xd9 + +/* Interrupts */ +#define PMC6_HW_INT_RX 0xc8 +#define PMC6_CYCLES_INT_MASKED 0xc6 +#define PMC6_CYCLES_INT_PENDING_AND_MASKED 0xc7 + +/* Branches */ +#define PMC6_BR_INST_RETIRED 0xc4 +#define PMC6_BR_MISS_PRED_RETIRED 0xc5 +#define PMC6_BR_TAKEN_RETIRED 0xc9 +#define PMC6_BR_MISS_PRED_TAKEN_RET 0xca +#define PMC6_BR_INST_DECODED 0xe0 +#define PMC6_BTB_MISSES 0xe2 +#define PMC6_BR_BOGUS 0xe4 +#define PMC6_BACLEARS 0xe6 + +/* Stalls */ +#define PMC6_RESOURCE_STALLS 0xa2 +#define PMC6_PARTIAL_RAT_STALLS 0xd2 + +/* Segment Register Loads */ +#define PMC6_SEGMENT_REG_LOADS 0x06 + +/* Clocks */ +#define PMC6_CPU_CLK_UNHALTED 0x79 + +/* MMX Unit */ +#define PMC6_MMX_INSTR_EXEC 0xb0 /* Celeron, P-II, P-IIX only */ +#define PMC6_MMX_SAT_INSTR_EXEC 0xb1 /* P-II and P-III only */ +#define PMC6_MMX_UOPS_EXEC 0xb2 /* P-II and P-III only */ +#define PMC6_MMX_INSTR_TYPE_EXEC 0xb3 /* P-II and P-III only */ +#define PMC6_FP_MMX_TRANS 0xcc /* P-II and P-III only */ +#define PMC6_MMX_ASSIST 0xcd /* P-II and P-III only */ +#define PMC6_MMX_INSTR_RET 0xc3 /* P-II only */ + +/* Segment Register Renaming */ +#define PMC6_SEG_RENAME_STALLS 0xd4 /* P-II and P-III only */ +#define PMC6_SEG_REG_RENAMES 0xd5 /* P-II and P-III only */ +#define PMC6_RET_SEG_RENAMES 0xd6 /* P-II and P-III only */ + +/* + * AMD K7 Event Selector MSR format. + */ + +#define K7_EVTSEL_EVENT 0x000000ff +#define K7_EVTSEL_UNIT 0x0000ff00 +#define K7_EVTSEL_UNIT_SHIFT 8 +#define K7_EVTSEL_USR (1 << 16) +#define K7_EVTSEL_OS (1 << 17) +#define K7_EVTSEL_E (1 << 18) +#define K7_EVTSEL_PC (1 << 19) +#define K7_EVTSEL_INT (1 << 20) +#define K7_EVTSEL_EN (1 << 22) +#define K7_EVTSEL_INV (1 << 23) +#define K7_EVTSEL_COUNTER_MASK 0xff000000 +#define K7_EVTSEL_COUNTER_MASK_SHIFT 24 + +/* Segment Register Loads */ +#define K7_SEGMENT_REG_LOADS 0x20 + +#define K7_STORES_TO_ACTIVE_INST_STREAM 0x21 + +/* Data Cache Unit */ +#define K7_DATA_CACHE_ACCESS 0x40 +#define K7_DATA_CACHE_MISS 0x41 +#define K7_DATA_CACHE_REFILL 0x42 +#define K7_DATA_CACHE_REFILL_SYSTEM 0x43 +#define K7_DATA_CACHE_WBACK 0x44 +#define K7_L2_DTLB_HIT 0x45 +#define K7_L2_DTLB_MISS 0x46 +#define K7_MISALIGNED_DATA_REF 0x47 +#define K7_SYSTEM_REQUEST 0x64 +#define K7_SYSTEM_REQUEST_TYPE 0x65 + +#define K7_SNOOP_HIT 0x73 +#define K7_SINGLE_BIT_ECC_ERROR 0x74 +#define K7_CACHE_LINE_INVAL 0x75 +#define K7_CYCLES_PROCESSOR_IS_RUNNING 0x76 +#define K7_L2_REQUEST 0x79 +#define K7_L2_REQUEST_BUSY 0x7a + +/* Instruction Fetch Unit */ +#define K7_IFU_IFETCH 0x80 +#define K7_IFU_IFETCH_MISS 0x81 +#define K7_IFU_REFILL_FROM_L2 0x82 +#define K7_IFU_REFILL_FROM_SYSTEM 0x83 +#define K7_ITLB_L1_MISS 0x84 +#define K7_ITLB_L2_MISS 0x85 +#define K7_SNOOP_RESYNC 0x86 +#define K7_IFU_STALL 0x87 + +#define K7_RETURN_STACK_HITS 0x88 +#define K7_RETURN_STACK_OVERFLOW 0x89 + +/* Retired */ +#define K7_RETIRED_INST 0xc0 +#define K7_RETIRED_OPS 0xc1 +#define K7_RETIRED_BRANCHES 0xc2 +#define K7_RETIRED_BRANCH_MISPREDICTED 0xc3 +#define K7_RETIRED_TAKEN_BRANCH 0xc4 +#define K7_RETIRED_TAKEN_BRANCH_MISPREDICTED 0xc5 +#define K7_RETIRED_FAR_CONTROL_TRANSFER 0xc6 +#define K7_RETIRED_RESYNC_BRANCH 0xc7 +#define K7_RETIRED_NEAR_RETURNS 0xc8 +#define K7_RETIRED_NEAR_RETURNS_MISPREDICTED 0xc9 +#define K7_RETIRED_INDIRECT_MISPREDICTED 0xca + +/* Interrupts */ +#define K7_CYCLES_INT_MASKED 0xcd +#define K7_CYCLES_INT_PENDING_AND_MASKED 0xce +#define K7_HW_INTR_RECV 0xcf + +#define K7_INSTRUCTION_DECODER_EMPTY 0xd0 +#define K7_DISPATCH_STALLS 0xd1 +#define K7_BRANCH_ABORTS_TO_RETIRE 0xd2 +#define K7_SERIALIZE 0xd3 +#define K7_SEGMENT_LOAD_STALL 0xd4 +#define K7_ICU_FULL 0xd5 +#define K7_RESERVATION_STATIONS_FULL 0xd6 +#define K7_FPU_FULL 0xd7 +#define K7_LS_FULL 0xd8 +#define K7_ALL_QUIET_STALL 0xd9 +#define K7_FAR_TRANSFER_OR_RESYNC_BRANCH_PENDING 0xda + +#define K7_BP0_MATCH 0xdc +#define K7_BP1_MATCH 0xdd +#define K7_BP2_MATCH 0xde +#define K7_BP3_MATCH 0xdf + +/* VIA C3 crypto featureset: for amd64_has_xcrypt */ +#define C3_HAS_AES 1 /* cpu has AES */ +#define C3_HAS_SHA 2 /* cpu has SHA1 & SHA256 */ +#define C3_HAS_MM 4 /* cpu has RSA instructions */ +#define C3_HAS_AESCTR 8 /* cpu has AES-CTR instructions */ + +/* Centaur Extended Feature flags */ +#define C3_CPUID_HAS_RNG 0x000004 +#define C3_CPUID_DO_RNG 0x000008 +#define C3_CPUID_HAS_ACE 0x000040 +#define C3_CPUID_DO_ACE 0x000080 +#define C3_CPUID_HAS_ACE2 0x000100 +#define C3_CPUID_DO_ACE2 0x000200 +#define C3_CPUID_HAS_PHE 0x000400 +#define C3_CPUID_DO_PHE 0x000800 +#define C3_CPUID_HAS_PMM 0x001000 +#define C3_CPUID_DO_PMM 0x002000 + +/* VIA C3 xcrypt-* instruction context control options */ +#define C3_CRYPT_CWLO_ROUND_M 0x0000000f +#define C3_CRYPT_CWLO_ALG_M 0x00000070 +#define C3_CRYPT_CWLO_ALG_AES 0x00000000 +#define C3_CRYPT_CWLO_KEYGEN_M 0x00000080 +#define C3_CRYPT_CWLO_KEYGEN_HW 0x00000000 +#define C3_CRYPT_CWLO_KEYGEN_SW 0x00000080 +#define C3_CRYPT_CWLO_NORMAL 0x00000000 +#define C3_CRYPT_CWLO_INTERMEDIATE 0x00000100 +#define C3_CRYPT_CWLO_ENCRYPT 0x00000000 +#define C3_CRYPT_CWLO_DECRYPT 0x00000200 +#define C3_CRYPT_CWLO_KEY128 0x0000000a /* 128bit, 10 rds */ +#define C3_CRYPT_CWLO_KEY192 0x0000040c /* 192bit, 12 rds */ +#define C3_CRYPT_CWLO_KEY256 0x0000080e /* 256bit, 15 rds */ + +/* Intel Silicon Debug */ +#define IA32_DEBUG_INTERFACE 0xc80 +#define IA32_DEBUG_INTERFACE_ENABLE 0x00000001 +#define IA32_DEBUG_INTERFACE_LOCK 0x40000000 +#define IA32_DEBUG_INTERFACE_MASK 0x80000000 + +/* + * VMX + */ +#define IA32_FEATURE_CONTROL_LOCK 0x01 +#define IA32_FEATURE_CONTROL_SMX_EN 0x02 +#define IA32_FEATURE_CONTROL_VMX_EN 0x04 +#define IA32_FEATURE_CONTROL_SENTER_EN (1ULL << 15) +#define IA32_FEATURE_CONTROL_SENTER_PARAM_MASK 0x7f00 +#define IA32_VMX_BASIC 0x480 +#define IA32_VMX_PINBASED_CTLS 0x481 +#define IA32_VMX_PROCBASED_CTLS 0x482 +#define IA32_VMX_EXIT_CTLS 0x483 +#define IA32_VMX_ENTRY_CTLS 0x484 +#define IA32_VMX_MISC 0x485 +#define IA32_VMX_CR0_FIXED0 0x486 +#define IA32_VMX_CR0_FIXED1 0x487 +#define IA32_VMX_CR4_FIXED0 0x488 +#define IA32_VMX_CR4_FIXED1 0x489 +#define IA32_VMX_PROCBASED2_CTLS 0x48B +#define IA32_VMX_EPT_VPID_CAP 0x48C +#define IA32_VMX_TRUE_PINBASED_CTLS 0x48D +#define IA32_VMX_TRUE_PROCBASED_CTLS 0x48E +#define IA32_VMX_TRUE_EXIT_CTLS 0x48F +#define IA32_VMX_TRUE_ENTRY_CTLS 0x490 +#define IA32_VMX_VMFUNC 0x491 + +#define IA32_EPT_VPID_CAP_XO_TRANSLATIONS (1ULL << 0) +#define IA32_EPT_VPID_CAP_PAGE_WALK_4 (1ULL << 6) +#define IA32_EPT_VPID_CAP_WB (1ULL << 14) +#define IA32_EPT_VPID_CAP_AD_BITS (1ULL << 21) +#define IA32_EPT_VPID_CAP_INVEPT_CONTEXT (1ULL << 25) +#define IA32_EPT_VPID_CAP_INVEPT_ALL (1ULL << 26) + +#define IA32_EPT_PAGING_CACHE_TYPE_UC 0x0 +#define IA32_EPT_PAGING_CACHE_TYPE_WB 0x6 +#define IA32_EPT_AD_BITS_ENABLE (1ULL << 6) +#define IA32_EPT_PAGE_WALK_LENGTH 0x4 + +/* VMX : IA32_VMX_BASIC bits */ +#define IA32_VMX_TRUE_CTLS_AVAIL (1ULL << 55) + +/* VMX : IA32_VMX_PINBASED_CTLS bits */ +#define IA32_VMX_EXTERNAL_INT_EXITING (1ULL << 0) +#define IA32_VMX_NMI_EXITING (1ULL << 3) +#define IA32_VMX_VIRTUAL_NMIS (1ULL << 5) +#define IA32_VMX_ACTIVATE_VMX_PREEMPTION_TIMER (1ULL << 6) +#define IA32_VMX_PROCESS_POSTED_INTERRUPTS (1ULL << 7) + +/* VMX : IA32_VMX_PROCBASED_CTLS bits */ +#define IA32_VMX_INTERRUPT_WINDOW_EXITING (1ULL << 2) +#define IA32_VMX_USE_TSC_OFFSETTING (1ULL << 3) +#define IA32_VMX_HLT_EXITING (1ULL << 7) +#define IA32_VMX_INVLPG_EXITING (1ULL << 9) +#define IA32_VMX_MWAIT_EXITING (1ULL << 10) +#define IA32_VMX_RDPMC_EXITING (1ULL << 11) +#define IA32_VMX_RDTSC_EXITING (1ULL << 12) +#define IA32_VMX_CR3_LOAD_EXITING (1ULL << 15) +#define IA32_VMX_CR3_STORE_EXITING (1ULL << 16) +#define IA32_VMX_CR8_LOAD_EXITING (1ULL << 19) +#define IA32_VMX_CR8_STORE_EXITING (1ULL << 20) +#define IA32_VMX_USE_TPR_SHADOW (1ULL << 21) +#define IA32_VMX_NMI_WINDOW_EXITING (1ULL << 22) +#define IA32_VMX_MOV_DR_EXITING (1ULL << 23) +#define IA32_VMX_UNCONDITIONAL_IO_EXITING (1ULL << 24) +#define IA32_VMX_USE_IO_BITMAPS (1ULL << 25) +#define IA32_VMX_MONITOR_TRAP_FLAG (1ULL << 27) +#define IA32_VMX_USE_MSR_BITMAPS (1ULL << 28) +#define IA32_VMX_MONITOR_EXITING (1ULL << 29) +#define IA32_VMX_PAUSE_EXITING (1ULL << 30) +#define IA32_VMX_ACTIVATE_SECONDARY_CONTROLS (1ULL << 31) + +/* VMX : IA32_VMX_PROCBASED2_CTLS bits */ +#define IA32_VMX_VIRTUALIZE_APIC (1ULL << 0) +#define IA32_VMX_ENABLE_EPT (1ULL << 1) +#define IA32_VMX_DESCRIPTOR_TABLE_EXITING (1ULL << 2) +#define IA32_VMX_ENABLE_RDTSCP (1ULL << 3) +#define IA32_VMX_VIRTUALIZE_X2APIC_MODE (1ULL << 4) +#define IA32_VMX_ENABLE_VPID (1ULL << 5) +#define IA32_VMX_WBINVD_EXITING (1ULL << 6) +#define IA32_VMX_UNRESTRICTED_GUEST (1ULL << 7) +#define IA32_VMX_APIC_REGISTER_VIRTUALIZATION (1ULL << 8) +#define IA32_VMX_VIRTUAL_INTERRUPT_DELIVERY (1ULL << 9) +#define IA32_VMX_PAUSE_LOOP_EXITING (1ULL << 10) +#define IA32_VMX_RDRAND_EXITING (1ULL << 11) +#define IA32_VMX_ENABLE_INVPCID (1ULL << 12) +#define IA32_VMX_ENABLE_VM_FUNCTIONS (1ULL << 13) +#define IA32_VMX_VMCS_SHADOWING (1ULL << 14) +#define IA32_VMX_ENABLE_ENCLS_EXITING (1ULL << 15) +#define IA32_VMX_RDSEED_EXITING (1ULL << 16) +#define IA32_VMX_ENABLE_PML (1ULL << 17) +#define IA32_VMX_EPT_VIOLATION_VE (1ULL << 18) +#define IA32_VMX_CONCEAL_VMX_FROM_PT (1ULL << 19) +#define IA32_VMX_ENABLE_XSAVES_XRSTORS (1ULL << 20) +#define IA32_VMX_ENABLE_TSC_SCALING (1ULL << 25) + +/* VMX : IA32_VMX_EXIT_CTLS bits */ +#define IA32_VMX_SAVE_DEBUG_CONTROLS (1ULL << 2) +#define IA32_VMX_HOST_SPACE_ADDRESS_SIZE (1ULL << 9) +#define IA32_VMX_LOAD_IA32_PERF_GLOBAL_CTRL_ON_EXIT (1ULL << 12) +#define IA32_VMX_ACKNOWLEDGE_INTERRUPT_ON_EXIT (1ULL << 15) +#define IA32_VMX_SAVE_IA32_PAT_ON_EXIT (1ULL << 18) +#define IA32_VMX_LOAD_IA32_PAT_ON_EXIT (1ULL << 19) +#define IA32_VMX_SAVE_IA32_EFER_ON_EXIT (1ULL << 20) +#define IA32_VMX_LOAD_IA32_EFER_ON_EXIT (1ULL << 21) +#define IA32_VMX_SAVE_VMX_PREEMPTION_TIMER (1ULL << 22) +#define IA32_VMX_CLEAR_IA32_BNDCFGS_ON_EXIT (1ULL << 23) +#define IA32_VMX_CONCEAL_VM_EXITS_FROM_PT (1ULL << 24) +#define IA32_VMX_LOAD_HOST_CET_STATE (1ULL << 28) + +/* VMX: IA32_VMX_ENTRY_CTLS bits */ +#define IA32_VMX_LOAD_DEBUG_CONTROLS (1ULL << 2) +#define IA32_VMX_IA32E_MODE_GUEST (1ULL << 9) +#define IA32_VMX_ENTRY_TO_SMM (1ULL << 10) +#define IA32_VMX_DEACTIVATE_DUAL_MONITOR_TREATMENT (1ULL << 11) +#define IA32_VMX_LOAD_IA32_PERF_GLOBAL_CTRL_ON_ENTRY (1ULL << 13) +#define IA32_VMX_LOAD_IA32_PAT_ON_ENTRY (1ULL << 14) +#define IA32_VMX_LOAD_IA32_EFER_ON_ENTRY (1ULL << 15) +#define IA32_VMX_LOAD_IA32_BNDCFGS_ON_ENTRY (1ULL << 16) +#define IA32_VMX_CONCEAL_VM_ENTRIES_FROM_PT (1ULL << 17) +#define IA32_VMX_LOAD_GUEST_CET_STATE (1ULL << 20) + +/* + * VMX : VMCS Fields + */ + +/* 16-bit control fields */ +#define VMCS_GUEST_VPID 0x0000 +#define VMCS_POSTED_INT_NOTIF_VECTOR 0x0002 +#define VMCS_EPTP_INDEX 0x0004 + +/* 16-bit guest state fields */ +#define VMCS_GUEST_IA32_ES_SEL 0x0800 +#define VMCS_GUEST_IA32_CS_SEL 0x0802 +#define VMCS_GUEST_IA32_SS_SEL 0x0804 +#define VMCS_GUEST_IA32_DS_SEL 0x0806 +#define VMCS_GUEST_IA32_FS_SEL 0x0808 +#define VMCS_GUEST_IA32_GS_SEL 0x080A +#define VMCS_GUEST_IA32_LDTR_SEL 0x080C +#define VMCS_GUEST_IA32_TR_SEL 0x080E +#define VMCS_GUEST_INTERRUPT_STATUS 0x0810 +#define VMCS_GUEST_PML_INDEX 0x0812 + +/* 16-bit host state fields */ +#define VMCS_HOST_IA32_ES_SEL 0x0C00 +#define VMCS_HOST_IA32_CS_SEL 0x0C02 +#define VMCS_HOST_IA32_SS_SEL 0x0C04 +#define VMCS_HOST_IA32_DS_SEL 0x0C06 +#define VMCS_HOST_IA32_FS_SEL 0x0C08 +#define VMCS_HOST_IA32_GS_SEL 0x0C0A +#define VMCS_HOST_IA32_TR_SEL 0x0C0C + +/* 64-bit control fields */ +#define VMCS_IO_BITMAP_A 0x2000 +#define VMCS_IO_BITMAP_B 0x2002 +#define VMCS_MSR_BITMAP_ADDRESS 0x2004 +#define VMCS_EXIT_STORE_MSR_ADDRESS 0x2006 +#define VMCS_EXIT_LOAD_MSR_ADDRESS 0x2008 +#define VMCS_ENTRY_LOAD_MSR_ADDRESS 0x200A +#define VMCS_EXECUTIVE_VMCS_POINTER 0x200C +#define VMCS_PML_ADDRESS 0x200E +#define VMCS_TSC_OFFSET 0x2010 +#define VMCS_VIRTUAL_APIC_ADDRESS 0x2012 +#define VMCS_APIC_ACCESS_ADDRESS 0x2014 +#define VMCS_POSTED_INTERRUPT_DESC 0x2016 +#define VMCS_VM_FUNCTION_CONTROLS 0x2018 +#define VMCS_GUEST_IA32_EPTP 0x201A +#define VMCS_EOI_EXIT_BITMAP_0 0x201C +#define VMCS_EOI_EXIT_BITMAP_1 0x201E +#define VMCS_EOI_EXIT_BITMAP_2 0x2020 +#define VMCS_EOI_EXIT_BITMAP_3 0x2022 +#define VMCS_EPTP_LIST_ADDRESS 0x2024 +#define VMCS_VMREAD_BITMAP_ADDRESS 0x2026 +#define VMCS_VMWRITE_BITMAP_ADDRESS 0x2028 +#define VMCS_VIRTUALIZATION_EXC_ADDRESS 0x202A +#define VMCS_XSS_EXITING_BITMAP 0x202C +#define VMCS_ENCLS_EXITING_BITMAP 0x202E +#define VMCS_TSC_MULTIPLIER 0x2032 + +/* 64-bit RO data field */ +#define VMCS_GUEST_PHYSICAL_ADDRESS 0x2400 + +/* 64-bit guest state fields */ +#define VMCS_LINK_POINTER 0x2800 +#define VMCS_GUEST_IA32_DEBUGCTL 0x2802 +#define VMCS_GUEST_IA32_PAT 0x2804 +#define VMCS_GUEST_IA32_EFER 0x2806 +#define VMCS_GUEST_IA32_PERF_GBL_CTRL 0x2808 +#define VMCS_GUEST_PDPTE0 0x280A +#define VMCS_GUEST_PDPTE1 0x280C +#define VMCS_GUEST_PDPTE2 0x280E +#define VMCS_GUEST_PDPTE3 0x2810 +#define VMCS_GUEST_IA32_BNDCFGS 0x2812 + +/* 64-bit host state fields */ +#define VMCS_HOST_IA32_PAT 0x2C00 +#define VMCS_HOST_IA32_EFER 0x2C02 +#define VMCS_HOST_IA32_PERF_GBL_CTRL 0x2C04 + +/* 32-bit control fields */ +#define VMCS_PINBASED_CTLS 0x4000 +#define VMCS_PROCBASED_CTLS 0x4002 +#define VMCS_EXCEPTION_BITMAP 0x4004 +#define VMCS_PF_ERROR_CODE_MASK 0x4006 +#define VMCS_PF_ERROR_CODE_MATCH 0x4008 +#define VMCS_CR3_TARGET_COUNT 0x400A +#define VMCS_EXIT_CTLS 0x400C +#define VMCS_EXIT_MSR_STORE_COUNT 0x400E +#define VMCS_EXIT_MSR_LOAD_COUNT 0x4010 +#define VMCS_ENTRY_CTLS 0x4012 +#define VMCS_ENTRY_MSR_LOAD_COUNT 0x4014 +#define VMCS_ENTRY_INTERRUPTION_INFO 0x4016 +#define VMCS_ENTRY_EXCEPTION_ERROR_CODE 0x4018 +#define VMCS_ENTRY_INSTRUCTION_LENGTH 0x401A +#define VMCS_TPR_THRESHOLD 0x401C +#define VMCS_PROCBASED2_CTLS 0x401E +#define VMCS_PLE_GAP 0x4020 +#define VMCS_PLE_WINDOW 0x4022 + +/* 32-bit RO data fields */ +#define VMCS_INSTRUCTION_ERROR 0x4400 +#define VMCS_EXIT_REASON 0x4402 +#define VMCS_EXIT_INTERRUPTION_INFO 0x4404 +#define VMCS_EXIT_INTERRUPTION_ERR_CODE 0x4406 +#define VMCS_IDT_VECTORING_INFO 0x4408 +#define VMCS_IDT_VECTORING_ERROR_CODE 0x440A +#define VMCS_INSTRUCTION_LENGTH 0x440C +#define VMCS_EXIT_INSTRUCTION_INFO 0x440E + +/* 32-bit guest state fields */ +#define VMCS_GUEST_IA32_ES_LIMIT 0x4800 +#define VMCS_GUEST_IA32_CS_LIMIT 0x4802 +#define VMCS_GUEST_IA32_SS_LIMIT 0x4804 +#define VMCS_GUEST_IA32_DS_LIMIT 0x4806 +#define VMCS_GUEST_IA32_FS_LIMIT 0x4808 +#define VMCS_GUEST_IA32_GS_LIMIT 0x480A +#define VMCS_GUEST_IA32_LDTR_LIMIT 0x480C +#define VMCS_GUEST_IA32_TR_LIMIT 0x480E +#define VMCS_GUEST_IA32_GDTR_LIMIT 0x4810 +#define VMCS_GUEST_IA32_IDTR_LIMIT 0x4812 +#define VMCS_GUEST_IA32_ES_AR 0x4814 +#define VMCS_GUEST_IA32_CS_AR 0x4816 +#define VMCS_GUEST_IA32_SS_AR 0x4818 +#define VMCS_GUEST_IA32_DS_AR 0x481A +#define VMCS_GUEST_IA32_FS_AR 0x481C +#define VMCS_GUEST_IA32_GS_AR 0x481E +#define VMCS_GUEST_IA32_LDTR_AR 0x4820 +#define VMCS_GUEST_IA32_TR_AR 0x4822 +#define VMCS_GUEST_INTERRUPTIBILITY_ST 0x4824 +#define VMCS_GUEST_ACTIVITY_STATE 0x4826 +#define VMCS_GUEST_SMBASE 0x4828 +#define VMCS_GUEST_IA32_SYSENTER_CS 0x482A +#define VMCS_VMX_PREEMPTION_TIMER_VAL 0x482E + +/* 32-bit host state field */ +#define VMCS_HOST_IA32_SYSENTER_CS 0x4C00 + +/* Natural-width control fields */ +#define VMCS_CR0_MASK 0x6000 +#define VMCS_CR4_MASK 0x6002 +#define VMCS_CR0_READ_SHADOW 0x6004 +#define VMCS_CR4_READ_SHADOW 0x6006 +#define VMCS_CR3_TARGET_0 0x6008 +#define VMCS_CR3_TARGET_1 0x600A +#define VMCS_CR3_TARGET_2 0x600C +#define VMCS_CR3_TARGET_3 0x600E + +/* Natural-width RO fields */ +#define VMCS_GUEST_EXIT_QUALIFICATION 0x6400 +#define VMCS_IO_RCX 0x6402 +#define VMCS_IO_RSI 0x6404 +#define VMCS_IO_RDI 0x6406 +#define VMCS_IO_RIP 0x6408 +#define VMCS_GUEST_LINEAR_ADDRESS 0x640A + +/* Natural-width guest state fields */ +#define VMCS_GUEST_IA32_CR0 0x6800 +#define VMCS_GUEST_IA32_CR3 0x6802 +#define VMCS_GUEST_IA32_CR4 0x6804 +#define VMCS_GUEST_IA32_ES_BASE 0x6806 +#define VMCS_GUEST_IA32_CS_BASE 0x6808 +#define VMCS_GUEST_IA32_SS_BASE 0x680A +#define VMCS_GUEST_IA32_DS_BASE 0x680C +#define VMCS_GUEST_IA32_FS_BASE 0x680E +#define VMCS_GUEST_IA32_GS_BASE 0x6810 +#define VMCS_GUEST_IA32_LDTR_BASE 0x6812 +#define VMCS_GUEST_IA32_TR_BASE 0x6814 +#define VMCS_GUEST_IA32_GDTR_BASE 0x6816 +#define VMCS_GUEST_IA32_IDTR_BASE 0x6818 +#define VMCS_GUEST_IA32_DR7 0x681A +#define VMCS_GUEST_IA32_RSP 0x681C +#define VMCS_GUEST_IA32_RIP 0x681E +#define VMCS_GUEST_IA32_RFLAGS 0x6820 +#define VMCS_GUEST_PENDING_DBG_EXC 0x6822 +#define VMCS_GUEST_IA32_SYSENTER_ESP 0x6824 +#define VMCS_GUEST_IA32_SYSENTER_EIP 0x6826 +#define VMCS_GUEST_IA32_S_CET 0x6828 + +/* Natural-width host state fields */ +#define VMCS_HOST_IA32_CR0 0x6C00 +#define VMCS_HOST_IA32_CR3 0x6C02 +#define VMCS_HOST_IA32_CR4 0x6C04 +#define VMCS_HOST_IA32_FS_BASE 0x6C06 +#define VMCS_HOST_IA32_GS_BASE 0x6C08 +#define VMCS_HOST_IA32_TR_BASE 0x6C0A +#define VMCS_HOST_IA32_GDTR_BASE 0x6C0C +#define VMCS_HOST_IA32_IDTR_BASE 0x6C0E +#define VMCS_HOST_IA32_SYSENTER_ESP 0x6C10 +#define VMCS_HOST_IA32_SYSENTER_EIP 0x6C12 +#define VMCS_HOST_IA32_RSP 0x6C14 +#define VMCS_HOST_IA32_RIP 0x6C16 +#define VMCS_HOST_IA32_S_CET 0x6C18 + +#define IA32_VMX_INVVPID_INDIV_ADDR_CTX 0x0 +#define IA32_VMX_INVVPID_SINGLE_CTX 0x1 +#define IA32_VMX_INVVPID_ALL_CTX 0x2 +#define IA32_VMX_INVVPID_SINGLE_CTX_GLB 0x3 + +#define IA32_VMX_INVEPT_SINGLE_CTX 0x1 +#define IA32_VMX_INVEPT_GLOBAL_CTX 0x2 + +#define IA32_VMX_EPT_FAULT_READ (1ULL << 0) +#define IA32_VMX_EPT_FAULT_WRITE (1ULL << 1) +#define IA32_VMX_EPT_FAULT_EXEC (1ULL << 2) + +#define IA32_VMX_EPT_FAULT_WAS_READABLE (1ULL << 3) +#define IA32_VMX_EPT_FAULT_WAS_WRITABLE (1ULL << 4) +#define IA32_VMX_EPT_FAULT_WAS_EXECABLE (1ULL << 5) + +#define IA32_VMX_MSR_LIST_SIZE_MASK (7ULL << 25) +#define IA32_VMX_CR3_TGT_SIZE_MASK (0x1FFULL << 16) + +#define VMX_SKIP_L1D_FLUSH 2 +#define VMX_L1D_FLUSH_SIZE (64 * 1024) + +/* + * SVM + */ +#define MSR_AMD_VM_CR 0xc0010114 +#define MSR_AMD_VM_HSAVE_PA 0xc0010117 +#define CPUID_AMD_SVM_CAP 0x8000000A +#define AMD_SVM_NESTED_PAGING_CAP (1 << 0) +#define AMD_SVM_VMCB_CLEAN_CAP (1 << 5) +#define AMD_SVM_FLUSH_BY_ASID_CAP (1 << 6) +#define AMD_SVM_DECODE_ASSIST_CAP (1 << 7) +#define AMD_SVMDIS 0x10 + +#define SVM_TLB_CONTROL_FLUSH_NONE 0 +#define SVM_TLB_CONTROL_FLUSH_ALL 1 +#define SVM_TLB_CONTROL_FLUSH_ASID 3 +#define SVM_TLB_CONTROL_FLUSH_ASID_GLB 7 + +#define SVM_CLEANBITS_I (1 << 0) +#define SVM_CLEANBITS_IOPM (1 << 1) +#define SVM_CLEANBITS_ASID (1 << 2) +#define SVM_CLEANBITS_TPR (1 << 3) +#define SVM_CLEANBITS_NP (1 << 4) +#define SVM_CLEANBITS_CR (1 << 5) +#define SVM_CLEANBITS_DR (1 << 6) +#define SVM_CLEANBITS_DT (1 << 7) +#define SVM_CLEANBITS_SEG (1 << 8) +#define SVM_CLEANBITS_CR2 (1 << 9) +#define SVM_CLEANBITS_LBR (1 << 10) +#define SVM_CLEANBITS_AVIC (1 << 11) + +#define SVM_CLEANBITS_ALL \ + (SVM_CLEANBITS_I | SVM_CLEANBITS_IOPM | SVM_CLEANBITS_ASID | \ + SVM_CLEANBITS_TPR | SVM_CLEANBITS_NP | SVM_CLEANBITS_CR | \ + SVM_CLEANBITS_DR | SVM_CLEANBITS_DT | SVM_CLEANBITS_SEG | \ + SVM_CLEANBITS_CR2 | SVM_CLEANBITS_LBR | SVM_CLEANBITS_AVIC ) + +#define SVM_INTR_MISC_V_IGN_TPR 0x10 + +/* + * SVM : VMCB intercepts + */ +#define SVM_INTERCEPT_CR0_READ (1UL << 0) +#define SVM_INTERCEPT_CR1_READ (1UL << 1) +#define SVM_INTERCEPT_CR2_READ (1UL << 2) +#define SVM_INTERCEPT_CR3_READ (1UL << 2) +#define SVM_INTERCEPT_CR4_READ (1UL << 4) +#define SVM_INTERCEPT_CR5_READ (1UL << 5) +#define SVM_INTERCEPT_CR6_READ (1UL << 6) +#define SVM_INTERCEPT_CR7_READ (1UL << 7) +#define SVM_INTERCEPT_CR8_READ (1UL << 8) +#define SVM_INTERCEPT_CR9_READ (1UL << 9) +#define SVM_INTERCEPT_CR10_READ (1UL << 10) +#define SVM_INTERCEPT_CR11_READ (1UL << 11) +#define SVM_INTERCEPT_CR12_READ (1UL << 12) +#define SVM_INTERCEPT_CR13_READ (1UL << 13) +#define SVM_INTERCEPT_CR14_READ (1UL << 14) +#define SVM_INTERCEPT_CR15_READ (1UL << 15) +#define SVM_INTERCEPT_CR0_WRITE (1UL << 16) +#define SVM_INTERCEPT_CR1_WRITE (1UL << 17) +#define SVM_INTERCEPT_CR2_WRITE (1UL << 18) +#define SVM_INTERCEPT_CR3_WRITE (1UL << 19) +#define SVM_INTERCEPT_CR4_WRITE (1UL << 20) +#define SVM_INTERCEPT_CR5_WRITE (1UL << 21) +#define SVM_INTERCEPT_CR6_WRITE (1UL << 22) +#define SVM_INTERCEPT_CR7_WRITE (1UL << 23) +#define SVM_INTERCEPT_CR8_WRITE (1UL << 24) +#define SVM_INTERCEPT_CR9_WRITE (1UL << 25) +#define SVM_INTERCEPT_CR10_WRITE (1UL << 26) +#define SVM_INTERCEPT_CR11_WRITE (1UL << 27) +#define SVM_INTERCEPT_CR12_WRITE (1UL << 28) +#define SVM_INTERCEPT_CR13_WRITE (1UL << 29) +#define SVM_INTERCEPT_CR14_WRITE (1UL << 30) +#define SVM_INTERCEPT_CR15_WRITE (1UL << 31) +#define SVM_INTERCEPT_DR0_READ (1UL << 0) +#define SVM_INTERCEPT_DR1_READ (1UL << 1) +#define SVM_INTERCEPT_DR2_READ (1UL << 2) +#define SVM_INTERCEPT_DR3_READ (1UL << 2) +#define SVM_INTERCEPT_DR4_READ (1UL << 4) +#define SVM_INTERCEPT_DR5_READ (1UL << 5) +#define SVM_INTERCEPT_DR6_READ (1UL << 6) +#define SVM_INTERCEPT_DR7_READ (1UL << 7) +#define SVM_INTERCEPT_DR8_READ (1UL << 8) +#define SVM_INTERCEPT_DR9_READ (1UL << 9) +#define SVM_INTERCEPT_DR10_READ (1UL << 10) +#define SVM_INTERCEPT_DR11_READ (1UL << 11) +#define SVM_INTERCEPT_DR12_READ (1UL << 12) +#define SVM_INTERCEPT_DR13_READ (1UL << 13) +#define SVM_INTERCEPT_DR14_READ (1UL << 14) +#define SVM_INTERCEPT_DR15_READ (1UL << 15) +#define SVM_INTERCEPT_DR0_WRITE (1UL << 16) +#define SVM_INTERCEPT_DR1_WRITE (1UL << 17) +#define SVM_INTERCEPT_DR2_WRITE (1UL << 18) +#define SVM_INTERCEPT_DR3_WRITE (1UL << 19) +#define SVM_INTERCEPT_DR4_WRITE (1UL << 20) +#define SVM_INTERCEPT_DR5_WRITE (1UL << 21) +#define SVM_INTERCEPT_DR6_WRITE (1UL << 22) +#define SVM_INTERCEPT_DR7_WRITE (1UL << 23) +#define SVM_INTERCEPT_DR8_WRITE (1UL << 24) +#define SVM_INTERCEPT_DR9_WRITE (1UL << 25) +#define SVM_INTERCEPT_DR10_WRITE (1UL << 26) +#define SVM_INTERCEPT_DR11_WRITE (1UL << 27) +#define SVM_INTERCEPT_DR12_WRITE (1UL << 28) +#define SVM_INTERCEPT_DR13_WRITE (1UL << 29) +#define SVM_INTERCEPT_DR14_WRITE (1UL << 30) +#define SVM_INTERCEPT_DR15_WRITE (1UL << 31) +#define SVM_INTERCEPT_INTR (1UL << 0) +#define SVM_INTERCEPT_NMI (1UL << 1) +#define SVM_INTERCEPT_SMI (1UL << 2) +#define SVM_INTERCEPT_INIT (1UL << 3) +#define SVM_INTERCEPT_VINTR (1UL << 4) +#define SVM_INTERCEPT_CR0_SEL_WRITE (1UL << 5) +#define SVM_INTERCEPT_IDTR_READ (1UL << 6) +#define SVM_INTERCEPT_GDTR_READ (1UL << 7) +#define SVM_INTERCEPT_LDTR_READ (1UL << 8) +#define SVM_INTERCEPT_TR_READ (1UL << 9) +#define SVM_INTERCEPT_IDTR_WRITE (1UL << 10) +#define SVM_INTERCEPT_GDTR_WRITE (1UL << 11) +#define SVM_INTERCEPT_LDTR_WRITE (1UL << 12) +#define SVM_INTERCEPT_TR_WRITE (1UL << 13) +#define SVM_INTERCEPT_RDTSC (1UL << 14) +#define SVM_INTERCEPT_RDPMC (1UL << 15) +#define SVM_INTERCEPT_PUSHF (1UL << 16) +#define SVM_INTERCEPT_POPF (1UL << 17) +#define SVM_INTERCEPT_CPUID (1UL << 18) +#define SVM_INTERCEPT_RSM (1UL << 19) +#define SVM_INTERCEPT_IRET (1UL << 20) +#define SVM_INTERCEPT_INTN (1UL << 21) +#define SVM_INTERCEPT_INVD (1UL << 22) +#define SVM_INTERCEPT_PAUSE (1UL << 23) +#define SVM_INTERCEPT_HLT (1UL << 24) +#define SVM_INTERCEPT_INVLPG (1UL << 25) +#define SVM_INTERCEPT_INVLPGA (1UL << 26) +#define SVM_INTERCEPT_INOUT (1UL << 27) +#define SVM_INTERCEPT_MSR (1UL << 28) +#define SVM_INTERCEPT_TASK_SWITCH (1UL << 29) +#define SVM_INTERCEPT_FERR_FREEZE (1UL << 30) +#define SVM_INTERCEPT_SHUTDOWN (1UL << 31) +#define SVM_INTERCEPT_VMRUN (1UL << 0) +#define SVM_INTERCEPT_VMMCALL (1UL << 1) +#define SVM_INTERCEPT_VMLOAD (1UL << 2) +#define SVM_INTERCEPT_VMSAVE (1UL << 3) +#define SVM_INTERCEPT_STGI (1UL << 4) +#define SVM_INTERCEPT_CLGI (1UL << 5) +#define SVM_INTERCEPT_SKINIT (1UL << 6) +#define SVM_INTERCEPT_RDTSCP (1UL << 7) +#define SVM_INTERCEPT_ICEBP (1UL << 8) +#define SVM_INTERCEPT_WBINVD (1UL << 9) +#define SVM_INTERCEPT_MONITOR (1UL << 10) +#define SVM_INTERCEPT_MWAIT_UNCOND (1UL << 11) +#define SVM_INTERCEPT_MWAIT_COND (1UL << 12) +#define SVM_INTERCEPT_XSETBV (1UL << 13) +#define SVM_INTERCEPT_EFER_WRITE (1UL << 15) +#define SVM_INTERCEPT_CR0_WRITE_POST (1UL << 16) +#define SVM_INTERCEPT_CR1_WRITE_POST (1UL << 17) +#define SVM_INTERCEPT_CR2_WRITE_POST (1UL << 18) +#define SVM_INTERCEPT_CR3_WRITE_POST (1UL << 19) +#define SVM_INTERCEPT_CR4_WRITE_POST (1UL << 20) +#define SVM_INTERCEPT_CR5_WRITE_POST (1UL << 21) +#define SVM_INTERCEPT_CR6_WRITE_POST (1UL << 22) +#define SVM_INTERCEPT_CR7_WRITE_POST (1UL << 23) +#define SVM_INTERCEPT_CR8_WRITE_POST (1UL << 24) +#define SVM_INTERCEPT_CR9_WRITE_POST (1UL << 25) +#define SVM_INTERCEPT_CR10_WRITE_POST (1UL << 26) +#define SVM_INTERCEPT_CR11_WRITE_POST (1UL << 27) +#define SVM_INTERCEPT_CR12_WRITE_POST (1UL << 28) +#define SVM_INTERCEPT_CR13_WRITE_POST (1UL << 29) +#define SVM_INTERCEPT_CR14_WRITE_POST (1UL << 30) +#define SVM_INTERCEPT_CR15_WRITE_POST (1UL << 31) + +/* + * SME and SEV + */ +#define CPUID_AMD_SEV_CAP 0x8000001F +#define AMD_SME_CAP (1UL << 0) +#define AMD_SEV_CAP (1UL << 1) + +/* + * PAT + */ +#define PATENTRY(n, type) (type << ((n) * 8)) +#define PAT_UC 0x0UL +#define PAT_WC 0x1UL +#define PAT_WT 0x4UL +#define PAT_WP 0x5UL +#define PAT_WB 0x6UL +#define PAT_UCMINUS 0x7UL + +/* + * XSAVE subfeatures (cpuid 0xd, leaf 1) + */ +#define XSAVE_XSAVEOPT 0x01UL +#define XSAVE_XSAVEC 0x02UL +#define XSAVE_XGETBV1 0x04UL +#define XSAVE_XSAVES 0x08UL +#define XSAVE_XFD 0x10UL +#define XSAVE_BITS \ + ("\20" "\01XSAVEOPT" "\02XSAVEC" "\03XGETBV1" "\04XSAVES" "\05XFD" ) + +/* + * Default cr0 and cr4 flags. + */ +#define CR0_DEFAULT (CR0_PE|CR0_PG|CR0_NE|CR0_WP) +#define CR4_DEFAULT (CR4_PAE|CR4_PGE|CR4_PSE|CR4_OSFXSR|CR4_OSXMMEXCPT) \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/spinlock.h b/lib/libc/include/x86_64-openbsd-none/amd64/spinlock.h new file mode 100644 index 0000000000..f3fe78c834 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/spinlock.h @@ -0,0 +1,10 @@ +/* $OpenBSD: spinlock.h,v 1.3 2017/09/05 02:40:54 guenther Exp $ */ + +#ifndef _MACHINE_SPINLOCK_H_ +#define _MACHINE_SPINLOCK_H_ + +#define _ATOMIC_LOCK_UNLOCKED (0) +#define _ATOMIC_LOCK_LOCKED (1) +typedef int _atomic_lock_t; + +#endif \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/sysarch.h b/lib/libc/include/x86_64-openbsd-none/amd64/sysarch.h new file mode 100644 index 0000000000..aea941c711 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/sysarch.h @@ -0,0 +1,28 @@ +/* $OpenBSD: sysarch.h,v 1.14 2018/01/07 18:54:44 guenther Exp $ */ +/* $NetBSD: sysarch.h,v 1.1 2003/04/26 18:39:48 fvdl Exp $ */ + +#ifndef _MACHINE_SYSARCH_H_ +#define _MACHINE_SYSARCH_H_ + +/* + * Architecture specific syscalls (amd64) + */ +#define AMD64_IOPL 2 + +struct amd64_iopl_args { + int iopl; +}; + +#ifdef _KERNEL +int amd64_iopl(struct proc *, void *, register_t *); +#else + +#include + +__BEGIN_DECLS +int amd64_iopl(int); +int sysarch(int, void *); +__END_DECLS +#endif + +#endif /* !_MACHINE_SYSARCH_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/tcb.h b/lib/libc/include/x86_64-openbsd-none/amd64/tcb.h new file mode 100644 index 0000000000..1d7d3135de --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/tcb.h @@ -0,0 +1,53 @@ +/* $OpenBSD: tcb.h,v 1.6 2017/10/13 05:14:02 guenther Exp $ */ + +/* + * Copyright (c) 2011 Philip Guenther + * + * 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 + +void *tcb_get(struct proc *_p); +void tcb_set(struct proc *_p, void *_newtcb); + +#define TCB_GET(p) tcb_get(p) +#define TCB_SET(p, addr) tcb_set(p, addr) + +/* address must be in canonical form; requiring lower-half is okay */ +#define TCB_INVALID(addr) ((u_long)(addr) > 0x00007fffffffffff) + +#else /* _KERNEL */ + +/* ELF TLS ABI calls for big TCB, with static TLS data at negative offsets */ +#define TLS_VARIANT 2 + +/* Read a slot from the TCB */ +static inline void * +__amd64_read_tcb(long offset) +{ + void *val; + __asm__ ("movq %%fs:(%1),%0" : "=r" (val) : "r" (offset)); + return val; +} + +/* Get a pointer to the TCB itself */ +#define TCB_GET() __amd64_read_tcb(0) + +/* Setting the TCB pointer can only be done via syscall, so no TCB_SET() */ + +#endif /* _KERNEL */ +#endif /* _MACHINE_TCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/timetc.h b/lib/libc/include/x86_64-openbsd-none/amd64/timetc.h new file mode 100644 index 0000000000..6680584078 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/timetc.h @@ -0,0 +1,24 @@ +/* $OpenBSD: timetc.h,v 1.3 2022/09/22 04:57:08 robert Exp $ */ +/* + * Copyright (c) 2020 Paul Irofti + * + * 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_TIMETC_H_ +#define _MACHINE_TIMETC_H_ + +#define TC_TSC_LFENCE 1 +#define TC_TSC_RDTSCP 2 + +#endif /* _MACHINE_TIMETC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/trap.h b/lib/libc/include/x86_64-openbsd-none/amd64/trap.h new file mode 100644 index 0000000000..f8b9fe7633 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/trap.h @@ -0,0 +1,65 @@ +/* $OpenBSD: trap.h,v 1.6 2025/06/23 11:33:39 bluhm Exp $ */ +/* $NetBSD: trap.h,v 1.4 1994/10/27 04:16:30 cgd 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. + * + * @(#)trap.h 5.4 (Berkeley) 5/9/91 + */ + +/* + * Trap type values + * also known in trap.c for name strings + */ + +#define T_PRIVINFLT 0 /* privileged instruction */ +#define T_BPTFLT 1 /* breakpoint trap */ +#define T_ARITHTRAP 2 /* arithmetic trap */ +#define T_RESERVED 3 /* reserved fault base */ +#define T_PROTFLT 4 /* protection fault */ +#define T_TRCTRAP 5 /* trace trap */ +#define T_PAGEFLT 6 /* page fault */ +#define T_ALIGNFLT 7 /* alignment fault */ +#define T_DIVIDE 8 /* integer divide fault */ +#define T_NMI 9 /* non-maskable interrupt */ +#define T_OFLOW 10 /* overflow trap */ +#define T_BOUND 11 /* bounds check fault */ +#define T_DNA 12 /* device not available fault */ +#define T_DOUBLEFLT 13 /* double fault */ +#define T_FPOPFLT 14 /* fp coprocessor operand fetch fault (![P]Pro)*/ +#define T_TSSFLT 15 /* invalid tss fault */ +#define T_SEGNPFLT 16 /* segment not present fault */ +#define T_STKFLT 17 /* stack fault */ +#define T_MCA 18 /* machine check ([P]Pro) */ +#define T_XMM 19 /* SSE FP exception */ +#define T_VE 20 /* virtualization exception */ +#define T_CP 21 /* control protection exception */ +#define T_VC 29 /* VMM communication exception */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/tss.h b/lib/libc/include/x86_64-openbsd-none/amd64/tss.h new file mode 100644 index 0000000000..e6679df978 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/tss.h @@ -0,0 +1,62 @@ +/* $OpenBSD: tss.h,v 1.4 2011/03/23 16:54:34 pirofti Exp $ */ +/* $NetBSD: tss.h,v 1.1 2003/04/26 18:39:49 fvdl Exp $ */ + +/* + * Copyright (c) 2001 Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Frank van der Linden for Wasabi Systems, Inc. + * + * 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 for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC + * 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_TSS_H_ +#define _MACHINE_TSS_H_ + +/* + * TSS structure. Since TSS hw switching is not supported in long + * mode, this is mainly there for the I/O permission map in + * normal processes. + */ + +struct x86_64_tss { + u_int32_t tss_reserved1; + u_int64_t tss_rsp0; + u_int64_t tss_rsp1; + u_int64_t tss_rsp2; + u_int32_t tss_reserved2; + u_int32_t tss_reserved3; + u_int64_t tss_ist[7]; + u_int32_t tss_reserved4; + u_int32_t tss_reserved5; + u_int16_t tss_reserved6; + u_int16_t tss_iobase; +} __packed; + +#endif /* _MACHINE_TSS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/vga_post.h b/lib/libc/include/x86_64-openbsd-none/amd64/vga_post.h new file mode 100644 index 0000000000..bbf947e991 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/vga_post.h @@ -0,0 +1,43 @@ +/* $NetBSD: vga_post.h,v 1.2 2008/03/29 17:40:22 jmcneill Exp $ */ +/* $OpenBSD: vga_post.h,v 1.2 2011/03/23 16:54:34 pirofti Exp $ */ + +/*- + * Copyright (c) 2007 Joerg Sonnenberger . + * 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT HOLDERS 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_VGA_POST_H_ +#define _MACHINE_VGA_POST_H_ + +#ifdef _KERNEL +struct vga_post; + +struct vga_post *vga_post_init(int, int, int); +void vga_post_free(struct vga_post *); +void vga_post_call(struct vga_post *); +#endif +#endif \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/vmmvar.h b/lib/libc/include/x86_64-openbsd-none/amd64/vmmvar.h new file mode 100644 index 0000000000..03006e3072 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/vmmvar.h @@ -0,0 +1,1075 @@ +/* $OpenBSD: vmmvar.h,v 1.117 2025/09/17 18:37:44 sf Exp $ */ +/* + * Copyright (c) 2014 Mike Larkin + * + * 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. + */ + +/* + * CPU capabilities for VMM operation + */ +#ifndef _MACHINE_VMMVAR_H_ +#define _MACHINE_VMMVAR_H_ + +#ifndef _LOCORE + +#define VMM_HV_SIGNATURE "OpenBSDVMM58" + +/* VMX: Basic Exit Reasons */ +#define VMX_EXIT_NMI 0 +#define VMX_EXIT_EXTINT 1 +#define VMX_EXIT_TRIPLE_FAULT 2 +#define VMX_EXIT_INIT 3 +#define VMX_EXIT_SIPI 4 +#define VMX_EXIT_IO_SMI 5 +#define VMX_EXIT_OTHER_SMI 6 +#define VMX_EXIT_INT_WINDOW 7 +#define VMX_EXIT_NMI_WINDOW 8 +#define VMX_EXIT_TASK_SWITCH 9 +#define VMX_EXIT_CPUID 10 +#define VMX_EXIT_GETSEC 11 +#define VMX_EXIT_HLT 12 +#define VMX_EXIT_INVD 13 +#define VMX_EXIT_INVLPG 14 +#define VMX_EXIT_RDPMC 15 +#define VMX_EXIT_RDTSC 16 +#define VMX_EXIT_RSM 17 +#define VMX_EXIT_VMCALL 18 +#define VMX_EXIT_VMCLEAR 19 +#define VMX_EXIT_VMLAUNCH 20 +#define VMX_EXIT_VMPTRLD 21 +#define VMX_EXIT_VMPTRST 22 +#define VMX_EXIT_VMREAD 23 +#define VMX_EXIT_VMRESUME 24 +#define VMX_EXIT_VMWRITE 25 +#define VMX_EXIT_VMXOFF 26 +#define VMX_EXIT_VMXON 27 +#define VMX_EXIT_CR_ACCESS 28 +#define VMX_EXIT_MOV_DR 29 +#define VMX_EXIT_IO 30 +#define VMX_EXIT_RDMSR 31 +#define VMX_EXIT_WRMSR 32 +#define VMX_EXIT_ENTRY_FAILED_GUEST_STATE 33 +#define VMX_EXIT_ENTRY_FAILED_MSR_LOAD 34 +#define VMX_EXIT_MWAIT 36 +#define VMX_EXIT_MTF 37 +#define VMX_EXIT_MONITOR 39 +#define VMX_EXIT_PAUSE 40 +#define VMX_EXIT_ENTRY_FAILED_MCE 41 +#define VMX_EXIT_TPR_BELOW_THRESHOLD 43 +#define VMX_EXIT_APIC_ACCESS 44 +#define VMX_EXIT_VIRTUALIZED_EOI 45 +#define VMX_EXIT_GDTR_IDTR 46 +#define VMX_EXIT_LDTR_TR 47 +#define VMX_EXIT_EPT_VIOLATION 48 +#define VMX_EXIT_EPT_MISCONFIGURATION 49 +#define VMX_EXIT_INVEPT 50 +#define VMX_EXIT_RDTSCP 51 +#define VMX_EXIT_VMX_PREEMPTION_TIMER_EXPIRED 52 +#define VMX_EXIT_INVVPID 53 +#define VMX_EXIT_WBINVD 54 +#define VMX_EXIT_XSETBV 55 +#define VMX_EXIT_APIC_WRITE 56 +#define VMX_EXIT_RDRAND 57 +#define VMX_EXIT_INVPCID 58 +#define VMX_EXIT_VMFUNC 59 +#define VMX_EXIT_RDSEED 61 +#define VMX_EXIT_XSAVES 63 +#define VMX_EXIT_XRSTORS 64 + +#define VM_EXIT_TERMINATED 0xFFFE +#define VM_EXIT_NONE 0xFFFF + +/* + * VMX: Misc defines + */ +#define VMX_MAX_CR3_TARGETS 256 +#define VMX_VMCS_PA_CLEAR 0xFFFFFFFFFFFFFFFFUL + +#endif /* ! _LOCORE */ + +/* + * SVM: Intercept codes (exit reasons) + */ +#define SVM_VMEXIT_CR0_READ 0x00 +#define SVM_VMEXIT_CR1_READ 0x01 +#define SVM_VMEXIT_CR2_READ 0x02 +#define SVM_VMEXIT_CR3_READ 0x03 +#define SVM_VMEXIT_CR4_READ 0x04 +#define SVM_VMEXIT_CR5_READ 0x05 +#define SVM_VMEXIT_CR6_READ 0x06 +#define SVM_VMEXIT_CR7_READ 0x07 +#define SVM_VMEXIT_CR8_READ 0x08 +#define SVM_VMEXIT_CR9_READ 0x09 +#define SVM_VMEXIT_CR10_READ 0x0A +#define SVM_VMEXIT_CR11_READ 0x0B +#define SVM_VMEXIT_CR12_READ 0x0C +#define SVM_VMEXIT_CR13_READ 0x0D +#define SVM_VMEXIT_CR14_READ 0x0E +#define SVM_VMEXIT_CR15_READ 0x0F +#define SVM_VMEXIT_CR0_WRITE 0x10 +#define SVM_VMEXIT_CR1_WRITE 0x11 +#define SVM_VMEXIT_CR2_WRITE 0x12 +#define SVM_VMEXIT_CR3_WRITE 0x13 +#define SVM_VMEXIT_CR4_WRITE 0x14 +#define SVM_VMEXIT_CR5_WRITE 0x15 +#define SVM_VMEXIT_CR6_WRITE 0x16 +#define SVM_VMEXIT_CR7_WRITE 0x17 +#define SVM_VMEXIT_CR8_WRITE 0x18 +#define SVM_VMEXIT_CR9_WRITE 0x19 +#define SVM_VMEXIT_CR10_WRITE 0x1A +#define SVM_VMEXIT_CR11_WRITE 0x1B +#define SVM_VMEXIT_CR12_WRITE 0x1C +#define SVM_VMEXIT_CR13_WRITE 0x1D +#define SVM_VMEXIT_CR14_WRITE 0x1E +#define SVM_VMEXIT_CR15_WRITE 0x1F +#define SVM_VMEXIT_DR0_READ 0x20 +#define SVM_VMEXIT_DR1_READ 0x21 +#define SVM_VMEXIT_DR2_READ 0x22 +#define SVM_VMEXIT_DR3_READ 0x23 +#define SVM_VMEXIT_DR4_READ 0x24 +#define SVM_VMEXIT_DR5_READ 0x25 +#define SVM_VMEXIT_DR6_READ 0x26 +#define SVM_VMEXIT_DR7_READ 0x27 +#define SVM_VMEXIT_DR8_READ 0x28 +#define SVM_VMEXIT_DR9_READ 0x29 +#define SVM_VMEXIT_DR10_READ 0x2A +#define SVM_VMEXIT_DR11_READ 0x2B +#define SVM_VMEXIT_DR12_READ 0x2C +#define SVM_VMEXIT_DR13_READ 0x2D +#define SVM_VMEXIT_DR14_READ 0x2E +#define SVM_VMEXIT_DR15_READ 0x2F +#define SVM_VMEXIT_DR0_WRITE 0x30 +#define SVM_VMEXIT_DR1_WRITE 0x31 +#define SVM_VMEXIT_DR2_WRITE 0x32 +#define SVM_VMEXIT_DR3_WRITE 0x33 +#define SVM_VMEXIT_DR4_WRITE 0x34 +#define SVM_VMEXIT_DR5_WRITE 0x35 +#define SVM_VMEXIT_DR6_WRITE 0x36 +#define SVM_VMEXIT_DR7_WRITE 0x37 +#define SVM_VMEXIT_DR8_WRITE 0x38 +#define SVM_VMEXIT_DR9_WRITE 0x39 +#define SVM_VMEXIT_DR10_WRITE 0x3A +#define SVM_VMEXIT_DR11_WRITE 0x3B +#define SVM_VMEXIT_DR12_WRITE 0x3C +#define SVM_VMEXIT_DR13_WRITE 0x3D +#define SVM_VMEXIT_DR14_WRITE 0x3E +#define SVM_VMEXIT_DR15_WRITE 0x3F +#define SVM_VMEXIT_EXCP0 0x40 +#define SVM_VMEXIT_EXCP1 0x41 +#define SVM_VMEXIT_EXCP2 0x42 +#define SVM_VMEXIT_EXCP3 0x43 +#define SVM_VMEXIT_EXCP4 0x44 +#define SVM_VMEXIT_EXCP5 0x45 +#define SVM_VMEXIT_EXCP6 0x46 +#define SVM_VMEXIT_EXCP7 0x47 +#define SVM_VMEXIT_EXCP8 0x48 +#define SVM_VMEXIT_EXCP9 0x49 +#define SVM_VMEXIT_EXCP10 0x4A +#define SVM_VMEXIT_EXCP11 0x4B +#define SVM_VMEXIT_EXCP12 0x4C +#define SVM_VMEXIT_EXCP13 0x4D +#define SVM_VMEXIT_EXCP14 0x4E +#define SVM_VMEXIT_EXCP15 0x4F +#define SVM_VMEXIT_EXCP16 0x50 +#define SVM_VMEXIT_EXCP17 0x51 +#define SVM_VMEXIT_EXCP18 0x52 +#define SVM_VMEXIT_EXCP19 0x53 +#define SVM_VMEXIT_EXCP20 0x54 +#define SVM_VMEXIT_EXCP21 0x55 +#define SVM_VMEXIT_EXCP22 0x56 +#define SVM_VMEXIT_EXCP23 0x57 +#define SVM_VMEXIT_EXCP24 0x58 +#define SVM_VMEXIT_EXCP25 0x59 +#define SVM_VMEXIT_EXCP26 0x5A +#define SVM_VMEXIT_EXCP27 0x5B +#define SVM_VMEXIT_EXCP28 0x5C +#define SVM_VMEXIT_EXCP29 0x5D +#define SVM_VMEXIT_EXCP30 0x5E +#define SVM_VMEXIT_EXCP31 0x5F +#define SVM_VMEXIT_INTR 0x60 +#define SVM_VMEXIT_NMI 0x61 +#define SVM_VMEXIT_SMI 0x62 +#define SVM_VMEXIT_INIT 0x63 +#define SVM_VMEXIT_VINTR 0x64 +#define SVM_VMEXIT_CR0_SEL_WRITE 0x65 +#define SVM_VMEXIT_IDTR_READ 0x66 +#define SVM_VMEXIT_GDTR_READ 0x67 +#define SVM_VMEXIT_LDTR_READ 0x68 +#define SVM_VMEXIT_TR_READ 0x69 +#define SVM_VMEXIT_IDTR_WRITE 0x6A +#define SVM_VMEXIT_GDTR_WRITE 0x6B +#define SVM_VMEXIT_LDTR_WRITE 0x6C +#define SVM_VMEXIT_TR_WRITE 0x6D +#define SVM_VMEXIT_RDTSC 0x6E +#define SVM_VMEXIT_RDPMC 0x6F +#define SVM_VMEXIT_PUSHF 0x70 +#define SVM_VMEXIT_POPF 0x71 +#define SVM_VMEXIT_CPUID 0x72 +#define SVM_VMEXIT_RSM 0x73 +#define SVM_VMEXIT_IRET 0x74 +#define SVM_VMEXIT_SWINT 0x75 +#define SVM_VMEXIT_INVD 0x76 +#define SVM_VMEXIT_PAUSE 0x77 +#define SVM_VMEXIT_HLT 0x78 +#define SVM_VMEXIT_INVLPG 0x79 +#define SVM_VMEXIT_INVLPGA 0x7A +#define SVM_VMEXIT_IOIO 0x7B +#define SVM_VMEXIT_MSR 0x7C +#define SVM_VMEXIT_TASK_SWITCH 0x7D +#define SVM_VMEXIT_FERR_FREEZE 0x7E +#define SVM_VMEXIT_SHUTDOWN 0x7F +#define SVM_VMEXIT_VMRUN 0x80 +#define SVM_VMEXIT_VMMCALL 0x81 +#define SVM_VMEXIT_VMLOAD 0x82 +#define SVM_VMEXIT_VMSAVE 0x83 +#define SVM_VMEXIT_STGI 0x84 +#define SVM_VMEXIT_CLGI 0x85 +#define SVM_VMEXIT_SKINIT 0x86 +#define SVM_VMEXIT_RDTSCP 0x87 +#define SVM_VMEXIT_ICEBP 0x88 +#define SVM_VMEXIT_WBINVD 0x89 +#define SVM_VMEXIT_MONITOR 0x8A +#define SVM_VMEXIT_MWAIT 0x8B +#define SVM_VMEXIT_MWAIT_CONDITIONAL 0x8C +#define SVM_VMEXIT_XSETBV 0x8D +#define SVM_VMEXIT_EFER_WRITE_TRAP 0x8F +#define SVM_VMEXIT_CR0_WRITE_TRAP 0x90 +#define SVM_VMEXIT_CR1_WRITE_TRAP 0x91 +#define SVM_VMEXIT_CR2_WRITE_TRAP 0x92 +#define SVM_VMEXIT_CR3_WRITE_TRAP 0x93 +#define SVM_VMEXIT_CR4_WRITE_TRAP 0x94 +#define SVM_VMEXIT_CR5_WRITE_TRAP 0x95 +#define SVM_VMEXIT_CR6_WRITE_TRAP 0x96 +#define SVM_VMEXIT_CR7_WRITE_TRAP 0x97 +#define SVM_VMEXIT_CR8_WRITE_TRAP 0x98 +#define SVM_VMEXIT_CR9_WRITE_TRAP 0x99 +#define SVM_VMEXIT_CR10_WRITE_TRAP 0x9A +#define SVM_VMEXIT_CR11_WRITE_TRAP 0x9B +#define SVM_VMEXIT_CR12_WRITE_TRAP 0x9C +#define SVM_VMEXIT_CR13_WRITE_TRAP 0x9D +#define SVM_VMEXIT_CR14_WRITE_TRAP 0x9E +#define SVM_VMEXIT_CR15_WRITE_TRAP 0x9F +#define SVM_VMEXIT_NPF 0x400 +#define SVM_AVIC_INCOMPLETE_IPI 0x401 +#define SVM_AVIC_NOACCEL 0x402 +#define SVM_VMEXIT_VMGEXIT 0x403 +#define SVM_VMEXIT_INVALID -1 + +/* + * Additional VMEXIT codes used in SEV-ES/SNP in the GHCB + */ +#define SEV_VMGEXIT_MMIO_READ 0x80000001 +#define SEV_VMGEXIT_MMIO_WRITE 0x80000002 + +#ifndef _LOCORE + +/* + * Exception injection vectors (these correspond to the CPU exception types + * defined in the SDM.) + */ +#define VMM_EX_DE 0 /* Divide Error #DE */ +#define VMM_EX_DB 1 /* Debug Exception #DB */ +#define VMM_EX_NMI 2 /* NMI */ +#define VMM_EX_BP 3 /* Breakpoint #BP */ +#define VMM_EX_OF 4 /* Overflow #OF */ +#define VMM_EX_BR 5 /* Bound range exceeded #BR */ +#define VMM_EX_UD 6 /* Undefined opcode #UD */ +#define VMM_EX_NM 7 /* Device not available #NM */ +#define VMM_EX_DF 8 /* Double fault #DF */ +#define VMM_EX_CP 9 /* Coprocessor segment overrun (unused) */ +#define VMM_EX_TS 10 /* Invalid TSS #TS */ +#define VMM_EX_NP 11 /* Segment not present #NP */ +#define VMM_EX_SS 12 /* Stack segment fault #SS */ +#define VMM_EX_GP 13 /* General protection #GP */ +#define VMM_EX_PF 14 /* Page fault #PF */ +#define VMM_EX_MF 16 /* x87 FPU floating point error #MF */ +#define VMM_EX_AC 17 /* Alignment check #AC */ +#define VMM_EX_MC 18 /* Machine check #MC */ +#define VMM_EX_XM 19 /* SIMD floating point exception #XM */ +#define VMM_EX_VE 20 /* Virtualization exception #VE */ + +enum { + VEI_DIR_OUT, + VEI_DIR_IN +}; + +enum { + VEE_FAULT_INVALID = 0, + VEE_FAULT_HANDLED, + VEE_FAULT_MMIO_ASSIST, + VEE_FAULT_PROTECT, +}; + +enum { + VMM_CPU_MODE_REAL, + VMM_CPU_MODE_PROT, + VMM_CPU_MODE_PROT32, + VMM_CPU_MODE_COMPAT, + VMM_CPU_MODE_LONG, + VMM_CPU_MODE_UNKNOWN, +}; + +struct vmm_softc_md { + /* Capabilities */ + uint32_t nr_rvi_cpus; /* [I] */ + uint32_t nr_ept_cpus; /* [I] */ + uint8_t pkru_enabled; /* [I] */ +}; + +/* + * vm exit data + * vm_exit_inout : describes an IN/OUT exit + */ +struct vm_exit_inout { + uint8_t vei_size; /* Size of access */ + uint8_t vei_dir; /* Direction */ + uint8_t vei_rep; /* REP prefix? */ + uint8_t vei_string; /* string variety? */ + uint8_t vei_encoding; /* operand encoding */ + uint16_t vei_port; /* port */ + uint32_t vei_data; /* data */ + uint8_t vei_insn_len; /* Count of instruction bytes */ +}; + +/* + * vm_exit_eptviolation : describes an EPT VIOLATION exit + */ +struct vm_exit_eptviolation { + uint8_t vee_fault_type; /* type of vm exit */ + uint8_t vee_insn_info; /* bitfield */ +#define VEE_LEN_VALID 0x1 /* vee_insn_len is valid */ +#define VEE_BYTES_VALID 0x2 /* vee_insn_bytes is valid */ + uint8_t vee_insn_len; /* [VMX] instruction length */ + uint8_t vee_insn_bytes[15]; /* [SVM] bytes at {R,E,}IP */ +}; + +/* + * struct vcpu_inject_event : describes an exception or interrupt to inject. + */ +struct vcpu_inject_event { + uint8_t vie_vector; /* Exception or interrupt vector. */ + uint32_t vie_errorcode; /* Optional error code. */ + uint8_t vie_type; +#define VCPU_INJECT_NONE 0 +#define VCPU_INJECT_INTR 1 /* External hardware interrupt. */ +#define VCPU_INJECT_EX 2 /* HW or SW Exception */ +#define VCPU_INJECT_NMI 3 /* Non-maskable Interrupt */ +}; + +/* + * struct vcpu_segment_info + * + * Describes a segment + selector set, used in constructing the initial vcpu + * register content + */ +struct vcpu_segment_info { + uint16_t vsi_sel; + uint32_t vsi_limit; + uint32_t vsi_ar; + uint64_t vsi_base; +}; + +/* The GPRS are ordered to assist instruction decode. */ +#define VCPU_REGS_RAX 0 +#define VCPU_REGS_RCX 1 +#define VCPU_REGS_RDX 2 +#define VCPU_REGS_RBX 3 +#define VCPU_REGS_RSP 4 +#define VCPU_REGS_RBP 5 +#define VCPU_REGS_RSI 6 +#define VCPU_REGS_RDI 7 +#define VCPU_REGS_R8 8 +#define VCPU_REGS_R9 9 +#define VCPU_REGS_R10 10 +#define VCPU_REGS_R11 11 +#define VCPU_REGS_R12 12 +#define VCPU_REGS_R13 13 +#define VCPU_REGS_R14 14 +#define VCPU_REGS_R15 15 +#define VCPU_REGS_RIP 16 +#define VCPU_REGS_RFLAGS 17 +#define VCPU_REGS_NGPRS (VCPU_REGS_RFLAGS + 1) + +#define VCPU_REGS_CR0 0 +#define VCPU_REGS_CR2 1 +#define VCPU_REGS_CR3 2 +#define VCPU_REGS_CR4 3 +#define VCPU_REGS_CR8 4 +#define VCPU_REGS_XCR0 5 +#define VCPU_REGS_PDPTE0 6 +#define VCPU_REGS_PDPTE1 7 +#define VCPU_REGS_PDPTE2 8 +#define VCPU_REGS_PDPTE3 9 +#define VCPU_REGS_NCRS (VCPU_REGS_PDPTE3 + 1) + +#define VCPU_REGS_ES 0 +#define VCPU_REGS_CS 1 +#define VCPU_REGS_SS 2 +#define VCPU_REGS_DS 3 +#define VCPU_REGS_FS 4 +#define VCPU_REGS_GS 5 +#define VCPU_REGS_LDTR 6 +#define VCPU_REGS_TR 7 +#define VCPU_REGS_NSREGS (VCPU_REGS_TR + 1) + +#define VCPU_REGS_EFER 0 +#define VCPU_REGS_STAR 1 +#define VCPU_REGS_LSTAR 2 +#define VCPU_REGS_CSTAR 3 +#define VCPU_REGS_SFMASK 4 +#define VCPU_REGS_KGSBASE 5 +#define VCPU_REGS_MISC_ENABLE 6 +#define VCPU_REGS_NMSRS (VCPU_REGS_MISC_ENABLE + 1) + +#define VCPU_REGS_DR0 0 +#define VCPU_REGS_DR1 1 +#define VCPU_REGS_DR2 2 +#define VCPU_REGS_DR3 3 +#define VCPU_REGS_DR6 4 +#define VCPU_REGS_DR7 5 +#define VCPU_REGS_NDRS (VCPU_REGS_DR7 + 1) + +struct vcpu_reg_state { + uint64_t vrs_gprs[VCPU_REGS_NGPRS]; + uint64_t vrs_crs[VCPU_REGS_NCRS]; + uint64_t vrs_msrs[VCPU_REGS_NMSRS]; + uint64_t vrs_drs[VCPU_REGS_NDRS]; + struct vcpu_segment_info vrs_sregs[VCPU_REGS_NSREGS]; + struct vcpu_segment_info vrs_gdtr; + struct vcpu_segment_info vrs_idtr; +}; + +#define VCPU_HOST_REGS_EFER 0 +#define VCPU_HOST_REGS_STAR 1 +#define VCPU_HOST_REGS_LSTAR 2 +#define VCPU_HOST_REGS_CSTAR 3 +#define VCPU_HOST_REGS_SFMASK 4 +#define VCPU_HOST_REGS_KGSBASE 5 +#define VCPU_HOST_REGS_MISC_ENABLE 6 +#define VCPU_HOST_REGS_NMSRS (VCPU_HOST_REGS_MISC_ENABLE + 1) + +/* + * struct vm_exit + * + * Contains VM exit information communicated to vmd(8). This information is + * gathered by vmm(4) from the CPU on each exit that requires help from vmd. + */ +struct vm_exit { + union { + struct vm_exit_inout vei; /* IN/OUT exit */ + struct vm_exit_eptviolation vee; /* EPT VIOLATION exit*/ + }; + + struct vcpu_reg_state vrs; + int cpl; +}; + +struct vm_intr_params { + /* Input parameters to VMM_IOC_INTR */ + uint32_t vip_vm_id; + uint32_t vip_vcpu_id; + uint16_t vip_intr; +}; + +#define VM_RWREGS_GPRS 0x1 /* read/write GPRs */ +#define VM_RWREGS_SREGS 0x2 /* read/write segment registers */ +#define VM_RWREGS_CRS 0x4 /* read/write CRs */ +#define VM_RWREGS_MSRS 0x8 /* read/write MSRs */ +#define VM_RWREGS_DRS 0x10 /* read/write DRs */ +#define VM_RWREGS_ALL (VM_RWREGS_GPRS | VM_RWREGS_SREGS | VM_RWREGS_CRS | \ + VM_RWREGS_MSRS | VM_RWREGS_DRS) + +struct vm_rwregs_params { + /* + * Input/output parameters to VMM_IOC_READREGS / + * VMM_IOC_WRITEREGS + */ + uint32_t vrwp_vm_id; + uint32_t vrwp_vcpu_id; + uint64_t vrwp_mask; + struct vcpu_reg_state vrwp_regs; +}; + +/* IOCTL definitions */ +#define VMM_IOC_INTR _IOW('V', 6, struct vm_intr_params) /* Intr pending */ + +/* CPUID masks */ +/* + * clone host capabilities minus: + * debug store (CPUIDECX_DTES64, CPUIDECX_DSCPL, CPUID_DS) + * monitor/mwait (CPUIDECX_MWAIT, CPUIDECX_MWAITX) + * vmx/svm (CPUIDECX_VMX, CPUIDECX_SVM) + * smx (CPUIDECX_SMX) + * speedstep (CPUIDECX_EST) + * thermal (CPUIDECX_TM2, CPUID_ACPI, CPUID_TM) + * context id (CPUIDECX_CNXTID) + * machine check (CPUID_MCE, CPUID_MCA) + * silicon debug (CPUIDECX_SDBG) + * xTPR (CPUIDECX_XTPR) + * perf/debug (CPUIDECX_PDCM) + * pcid (CPUIDECX_PCID) + * direct cache access (CPUIDECX_DCA) + * x2APIC (CPUIDECX_X2APIC) + * apic deadline (CPUIDECX_DEADLINE) + * apic (CPUID_APIC) + * psn (CPUID_PSN) + * self snoop (CPUID_SS) + * hyperthreading (CPUID_HTT) + * pending break enabled (CPUID_PBE) + * MTRR (CPUID_MTRR) + * Speculative execution control features (AMD) + */ +#define VMM_CPUIDECX_MASK ~(CPUIDECX_EST | CPUIDECX_TM2 | CPUIDECX_MWAIT | \ + CPUIDECX_PDCM | CPUIDECX_VMX | CPUIDECX_DTES64 | \ + CPUIDECX_DSCPL | CPUIDECX_SMX | CPUIDECX_CNXTID | \ + CPUIDECX_SDBG | CPUIDECX_XTPR | CPUIDECX_PCID | \ + CPUIDECX_DCA | CPUIDECX_X2APIC | CPUIDECX_DEADLINE) +#define VMM_ECPUIDECX_MASK ~(CPUIDECX_SVM | CPUIDECX_MWAITX) +#define VMM_CPUIDEDX_MASK ~(CPUID_ACPI | CPUID_TM | \ + CPUID_HTT | CPUID_DS | CPUID_APIC | \ + CPUID_PSN | CPUID_SS | CPUID_PBE | \ + CPUID_MTRR | CPUID_MCE | CPUID_MCA) +#define VMM_AMDSPEC_EBX_MASK ~(CPUIDEBX_IBPB | CPUIDEBX_IBRS | \ + CPUIDEBX_STIBP | CPUIDEBX_IBRS_ALWAYSON | CPUIDEBX_STIBP_ALWAYSON | \ + CPUIDEBX_IBRS_PREF | CPUIDEBX_SSBD | CPUIDEBX_VIRT_SSBD | \ + CPUIDEBX_SSBD_NOTREQ) + +/* This mask is an include list for bits we want to expose */ +#define VMM_APMI_EDX_INCLUDE_MASK (CPUIDEDX_ITSC) + +/* + * SEFF flags - copy from host minus: + * TSC_ADJUST (SEFF0EBX_TSC_ADJUST) + * SGX (SEFF0EBX_SGX) + * HLE (SEFF0EBX_HLE) + * INVPCID (SEFF0EBX_INVPCID) + * RTM (SEFF0EBX_RTM) + * PQM (SEFF0EBX_PQM) + * AVX512F (SEFF0EBX_AVX512F) + * AVX512DQ (SEFF0EBX_AVX512DQ) + * AVX512IFMA (SEFF0EBX_AVX512IFMA) + * AVX512PF (SEFF0EBX_AVX512PF) + * AVX512ER (SEFF0EBX_AVX512ER) + * AVX512CD (SEFF0EBX_AVX512CD) + * AVX512BW (SEFF0EBX_AVX512BW) + * AVX512VL (SEFF0EBX_AVX512VL) + * MPX (SEFF0EBX_MPX) + * PCOMMIT (SEFF0EBX_PCOMMIT) + * PT (SEFF0EBX_PT) + */ +#define VMM_SEFF0EBX_MASK ~(SEFF0EBX_TSC_ADJUST | SEFF0EBX_SGX | \ + SEFF0EBX_HLE | SEFF0EBX_INVPCID | \ + SEFF0EBX_RTM | SEFF0EBX_PQM | SEFF0EBX_MPX | \ + SEFF0EBX_PCOMMIT | SEFF0EBX_PT | \ + SEFF0EBX_AVX512F | SEFF0EBX_AVX512DQ | \ + SEFF0EBX_AVX512IFMA | SEFF0EBX_AVX512PF | \ + SEFF0EBX_AVX512ER | SEFF0EBX_AVX512CD | \ + SEFF0EBX_AVX512BW | SEFF0EBX_AVX512VL) + +/* ECX mask contains the bits to include */ +#define VMM_SEFF0ECX_MASK (SEFF0ECX_UMIP) + +/* EDX mask contains the bits to include */ +#define VMM_SEFF0EDX_MASK (SEFF0EDX_MD_CLEAR) + +/* + * Extended function flags - copy from host minus: + * 0x80000001 EDX:RDTSCP Support + */ +#define VMM_FEAT_EFLAGS_MASK ~(CPUID_RDTSCP) + +/* + * CPUID[0x4] deterministic cache info + */ +#define VMM_CPUID4_CACHE_TOPOLOGY_MASK 0x3FF + +#ifdef _KERNEL + +#define VMX_FAIL_LAUNCH_UNKNOWN 1 +#define VMX_FAIL_LAUNCH_INVALID_VMCS 2 +#define VMX_FAIL_LAUNCH_VALID_VMCS 3 + +/* MSR bitmap manipulation macros */ +#define VMX_MSRIDX(m) ((m) / 8) +#define VMX_MSRBIT(m) (1 << (m) % 8) + +#define SVM_MSRIDX(m) ((m) / 4) +#define SVM_MSRBIT_R(m) (1 << (((m) % 4) * 2)) +#define SVM_MSRBIT_W(m) (1 << (((m) % 4) * 2 + 1)) + +enum { + VMM_MODE_UNKNOWN, + VMM_MODE_EPT, + VMM_MODE_RVI +}; + +enum { + VMM_MEM_TYPE_REGULAR, + VMM_MEM_TYPE_MMIO, + VMM_MEM_TYPE_UNKNOWN +}; + +/* Forward declarations */ +struct vm; +struct vm_create_params; + +/* + * Implementation-specific cpu state + */ + +struct vmcb_segment { + uint16_t vs_sel; /* 000h */ + uint16_t vs_attr; /* 002h */ + uint32_t vs_lim; /* 004h */ + uint64_t vs_base; /* 008h */ +}; + +#define SVM_ENABLE_NP (1ULL << 0) +#define SVM_ENABLE_SEV (1ULL << 1) +#define SVM_SEVES_ENABLE (1ULL << 2) + +#define SMV_GUEST_INTR_MASK (1ULL << 1) + +#define SVM_LBRVIRT_ENABLE (1ULL << 0) + +struct vmcb { + union { + struct { + uint32_t v_cr_rw; /* 000h */ + uint32_t v_dr_rw; /* 004h */ + uint32_t v_excp; /* 008h */ + uint32_t v_intercept1; /* 00Ch */ + uint32_t v_intercept2; /* 010h */ + uint8_t v_pad1[0x28]; /* 014h-03Bh */ + uint16_t v_pause_thr; /* 03Ch */ + uint16_t v_pause_ct; /* 03Eh */ + uint64_t v_iopm_pa; /* 040h */ + uint64_t v_msrpm_pa; /* 048h */ + uint64_t v_tsc_offset; /* 050h */ + uint32_t v_asid; /* 058h */ + uint8_t v_tlb_control; /* 05Ch */ + uint8_t v_pad2[0x3]; /* 05Dh-05Fh */ + uint8_t v_tpr; /* 060h */ + uint8_t v_irq; /* 061h */ + uint8_t v_intr_misc; /* 062h */ + uint8_t v_intr_masking; /* 063h */ + uint8_t v_intr_vector; /* 064h */ + uint8_t v_pad3[0x3]; /* 065h-067h */ + uint64_t v_intr_shadow; /* 068h */ + uint64_t v_exitcode; /* 070h */ + uint64_t v_exitinfo1; /* 078h */ + uint64_t v_exitinfo2; /* 080h */ + uint64_t v_exitintinfo; /* 088h */ + uint64_t v_np_enable; /* 090h */ + uint64_t v_avic_apic_bar; /* 098h */ + uint64_t v_ghcb_gpa; /* 0A0h */ + uint64_t v_eventinj; /* 0A8h */ + uint64_t v_n_cr3; /* 0B0h */ + uint64_t v_lbr_virt_enable; /* 0B8h */ + uint64_t v_vmcb_clean_bits; /* 0C0h */ + uint64_t v_nrip; /* 0C8h */ + uint8_t v_n_bytes_fetched; /* 0D0h */ + uint8_t v_guest_ins_bytes[0xf]; /* 0D1h-0DFh */ + uint64_t v_avic_apic_back_page; /* 0E0h */ + uint64_t v_pad5; /* 0E8h-0EFh */ + uint64_t v_avic_logical_table; /* 0F0h */ + uint64_t v_avic_phys; /* 0F8h */ + uint64_t v_pad12; /* 100h */ + uint64_t v_vmsa_pa; /* 108h */ + + }; + uint8_t vmcb_control[0x400]; + }; + + union { + struct { + /* Offsets here are relative to start of VMCB SSA */ + struct vmcb_segment v_es; /* 000h */ + struct vmcb_segment v_cs; /* 010h */ + struct vmcb_segment v_ss; /* 020h */ + struct vmcb_segment v_ds; /* 030h */ + struct vmcb_segment v_fs; /* 040h */ + struct vmcb_segment v_gs; /* 050h */ + struct vmcb_segment v_gdtr; /* 060h */ + struct vmcb_segment v_ldtr; /* 070h */ + struct vmcb_segment v_idtr; /* 080h */ + struct vmcb_segment v_tr; /* 090h */ + uint8_t v_pad6[0x2B]; /* 0A0h-0CAh */ + uint8_t v_cpl; /* 0CBh */ + uint32_t v_pad7; /* 0CCh-0CFh */ + uint64_t v_efer; /* 0D0h */ + uint8_t v_pad8[0x70]; /* 0D8h-147h */ + uint64_t v_cr4; /* 148h */ + uint64_t v_cr3; /* 150h */ + uint64_t v_cr0; /* 158h */ + uint64_t v_dr7; /* 160h */ + uint64_t v_dr6; /* 168h */ + uint64_t v_rflags; /* 170h */ + uint64_t v_rip; /* 178h */ + uint64_t v_pad9[0xB]; /* 180h-1D7h */ + uint64_t v_rsp; /* 1D8h */ + uint64_t v_pad10[0x3]; /* 1E0h-1F7h */ + uint64_t v_rax; /* 1F8h */ + uint64_t v_star; /* 200h */ + uint64_t v_lstar; /* 208h */ + uint64_t v_cstar; /* 210h */ + uint64_t v_sfmask; /* 218h */ + uint64_t v_kgsbase; /* 220h */ + uint64_t v_sysenter_cs; /* 228h */ + uint64_t v_sysenter_esp; /* 230h */ + uint64_t v_sysenter_eip; /* 238h */ + uint64_t v_cr2; /* 240h */ + uint64_t v_pad11[0x4]; /* 248h-267h */ + uint64_t v_g_pat; /* 268h */ + uint64_t v_dbgctl; /* 270h */ + uint64_t v_br_from; /* 278h */ + uint64_t v_br_to; /* 280h */ + uint64_t v_lastexcpfrom; /* 288h */ + uint64_t v_lastexcpto; /* 290h */ + }; + uint8_t vmcb_layout[PAGE_SIZE - 0x400]; + }; +}; + +struct vmsa { + struct vmcb_segment v_es; /* 000h */ + struct vmcb_segment v_cs; /* 010h */ + struct vmcb_segment v_ss; /* 020h */ + struct vmcb_segment v_ds; /* 030h */ + struct vmcb_segment v_fs; /* 040h */ + struct vmcb_segment v_gs; /* 050h */ + struct vmcb_segment v_gdtr; /* 060h */ + struct vmcb_segment v_ldtr; /* 070h */ + struct vmcb_segment v_idtr; /* 080h */ + struct vmcb_segment v_tr; /* 090h */ + uint64_t v_pl0_ssp; /* 0A0h */ + uint64_t v_pl1_ssp; /* 0A8h */ + uint64_t v_pl2_ssp; /* 0B0h */ + uint64_t v_pl3_ssp; /* 0B8h */ + uint64_t v_u_cet; /* 0C0h */ + uint8_t v_pad1[0x2]; /* 0C8h-0C9h */ + uint8_t v_vmpl; /* 0CAh */ + uint8_t v_cpl; /* 0CBh */ + uint8_t v_pad2[0x4]; /* 0CCh-0CFh */ + uint64_t v_efer; /* 0D0h */ + uint8_t v_pad3[0x68]; /* 0D8h-13Fh */ + uint64_t v_xss; /* 140h */ + uint64_t v_cr4; /* 148h */ + uint64_t v_cr3; /* 150h */ + uint64_t v_cr0; /* 158h */ + uint64_t v_dr7; /* 160h */ + uint64_t v_dr6; /* 168h */ + uint64_t v_rflags; /* 170h */ + uint64_t v_rip; /* 178h */ + uint64_t v_dr0; /* 180h */ + uint64_t v_dr1; /* 188h */ + uint64_t v_dr2; /* 190h */ + uint64_t v_dr3; /* 198h */ + uint64_t v_dr0_addr_msk; /* 1A0h */ + uint64_t v_dr1_addr_msk; /* 1A8h */ + uint64_t v_dr2_addr_msk; /* 1B0h */ + uint64_t v_dr3_addr_msk; /* 1B8h */ + uint8_t v_pad4[0x18]; /* 1C0h-1D7h */ + uint64_t v_rsp; /* 1D8h */ + uint64_t v_s_cet; /* 1E0h */ + uint64_t v_ssp; /* 1E8h */ + uint64_t v_isst_addr; /* 1F0h */ + uint64_t v_rax; /* 1F8h */ + uint64_t v_star; /* 200h */ + uint64_t v_lstar; /* 208h */ + uint64_t v_cstar; /* 210h */ + uint64_t v_sfmask; /* 218h */ + uint64_t v_kgsbase; /* 220h */ + uint64_t v_sysenter_cs; /* 228h */ + uint64_t v_sysenter_esp; /* 230h */ + uint64_t v_sysenter_eip; /* 238h */ + uint64_t v_cr2; /* 240h */ + uint8_t v_pad5[0x20]; /* 248h-267h */ + uint64_t v_g_pat; /* 268h */ + uint64_t v_dbgctl; /* 270h */ + uint64_t v_br_from; /* 278h */ + uint64_t v_br_to; /* 280h */ + uint64_t v_lastexcpfrom; /* 288h */ + uint64_t v_lastexcpto; /* 290h */ + uint8_t v_pad6[0x48]; /* 298h-2DFh */ + uint8_t v_pad7[0x8]; /* 2E0h-2E7h */ + uint32_t v_pkru; /* 2E8h */ + uint32_t v_tsc_aux; /* 2ECh */ + uint64_t v_gst_tsc_scale;/* 2F0h */ + uint64_t v_gst_tsc_off; /* 2F8h */ + uint64_t v_reg_prot_nce; /* 300h */ + uint64_t v_rcx; /* 308h */ + uint64_t v_rdx; /* 310h */ + uint64_t v_rbx; /* 318h */ + uint64_t v_pad8; /* 320h */ + uint64_t v_rbp; /* 328h */ + uint64_t v_rsi; /* 330h */ + uint64_t v_rdi; /* 338h */ + uint64_t v_r8; /* 340h */ + uint64_t v_r9; /* 348h */ + uint64_t v_r10; /* 350h */ + uint64_t v_r11; /* 358h */ + uint64_t v_r12; /* 360h */ + uint64_t v_r13; /* 368h */ + uint64_t v_r14; /* 370h */ + uint64_t v_r15; /* 378h */ + uint8_t v_pad9[0x10]; /* 380h-38Fh */ + uint64_t v_gst_exitinfo1;/* 390h */ + uint64_t v_gst_exitinfo2;/* 398h */ + uint64_t v_gst_exitiinfo;/* 3A0h */ + uint64_t v_gst_nrip; /* 3A8h */ + uint64_t v_sev_features; /* 3B0h */ + uint64_t v_intr_ctrl; /* 3B8h */ + uint64_t v_gst_exitcode; /* 3C0h */ + uint64_t v_virtual_tom; /* 3C8h */ + uint64_t v_tlb_id; /* 3D0h */ + uint64_t v_pcup_id; /* 3D8h */ + uint64_t v_eventinj; /* 3E0h */ + uint64_t v_xcr0; /* 3E8h */ + uint8_t v_pad10[0x10]; /* 3F0h-3FFh */ + uint64_t v_x87_dp; /* 400h */ + uint32_t v_mxcsr; /* 408h */ + uint16_t v_x87_ftw; /* 40Ch */ + uint16_t v_x87_fsw; /* 40Eh */ + uint16_t v_x87_fcw; /* 410h */ + uint16_t v_x87_fop; /* 412h */ + uint16_t v_x87_ds; /* 414h */ + uint16_t v_x87_cs; /* 416h */ + uint64_t v_x87_rip; /* 418h */ + uint8_t v_fp_x87[0x50]; /* 420h-46Fh */ + uint8_t v_fp_xmm[0x100];/* 470h-56Fh */ + uint8_t v_fp_ymm[0x100];/* 570h-66fh */ + uint8_t v_lbr_st[0x100];/* 670h-76Fh */ + uint64_t v_lbr_select; /* 770h */ + uint64_t v_ibs_fetch_ctl;/* 778h */ + uint64_t v_ibs_fetch_la; /* 780h */ + uint64_t v_ibs_op_ctl; /* 788h */ + uint64_t v_ibs_op_rip; /* 790h */ + uint64_t v_ibs_op_data; /* 798h */ + uint64_t v_ibs_op_data2; /* 7A0h */ + uint64_t v_ibs_op_data3; /* 7A8h */ + uint64_t v_ibs_dc_la; /* 7B0h */ + uint64_t v_ibstgt_rip; /* 7B8h */ + uint64_t v_ic_ibs_xtd_ct;/* 7C0h */ +}; + +/* + * With SEV-ES the host save area (HSA) has the same layout as the + * VMSA. However, it has the offset 0x400 into the HSA page. + * See AMD APM Vol 2, Appendix B. + */ +#define SVM_HSA_OFFSET 0x400 + +struct vmcs { + uint32_t vmcs_revision; +}; + +struct vmx_invvpid_descriptor { + uint64_t vid_vpid; + uint64_t vid_addr; +}; + +struct vmx_invept_descriptor { + uint64_t vid_eptp; + uint64_t vid_reserved; +}; + +struct vmx_msr_store { + uint64_t vms_index; + uint64_t vms_data; +}; + +/* + * Storage for guest registers not preserved in VMCS and various exit + * information. + * + * Note that vmx/svm_enter_guest depend on the layout of this struct for + * field access. + */ +struct vcpu_gueststate { + /* %rsi should be first */ + uint64_t vg_rsi; /* 0x00 */ + uint64_t vg_rax; /* 0x08 */ + uint64_t vg_rbx; /* 0x10 */ + uint64_t vg_rcx; /* 0x18 */ + uint64_t vg_rdx; /* 0x20 */ + uint64_t vg_rdi; /* 0x28 */ + uint64_t vg_rbp; /* 0x30 */ + uint64_t vg_r8; /* 0x38 */ + uint64_t vg_r9; /* 0x40 */ + uint64_t vg_r10; /* 0x48 */ + uint64_t vg_r11; /* 0x50 */ + uint64_t vg_r12; /* 0x58 */ + uint64_t vg_r13; /* 0x60 */ + uint64_t vg_r14; /* 0x68 */ + uint64_t vg_r15; /* 0x70 */ + uint64_t vg_cr2; /* 0x78 */ + uint64_t vg_rip; /* 0x80 */ + uint32_t vg_exit_reason; /* 0x88 */ + uint64_t vg_rflags; /* 0x90 */ + uint64_t vg_xcr0; /* 0x98 */ + /* + * Debug registers + * - %dr4/%dr5 are aliased to %dr6/%dr7 (or cause #DE) + * - %dr7 is saved automatically in the VMCS + */ + uint64_t vg_dr0; /* 0xa0 */ + uint64_t vg_dr1; /* 0xa8 */ + uint64_t vg_dr2; /* 0xb0 */ + uint64_t vg_dr3; /* 0xb8 */ + uint64_t vg_dr6; /* 0xc0 */ +}; + +/* + * Virtual CPU + * + * Methods used to vcpu struct members: + * a atomic operations + * I immutable operations + * K kernel lock + * r reference count + * v vcpu rwlock + * V vm struct's vcpu list lock (vm_vcpu_lock) + */ +struct vcpu { + /* + * Guest FPU state - this must remain as the first member of the struct + * to ensure 64-byte alignment (set up during vcpu_pool init) + */ + struct savefpu vc_g_fpu; /* [v] */ + + /* VMCS / VMCB pointer */ + vaddr_t vc_control_va; /* [I] */ + paddr_t vc_control_pa; /* [I] */ + + /* VLAPIC pointer */ + vaddr_t vc_vlapic_va; /* [I] */ + uint64_t vc_vlapic_pa; /* [I] */ + + /* MSR bitmap address */ + vaddr_t vc_msr_bitmap_va; /* [I] */ + uint64_t vc_msr_bitmap_pa; /* [I] */ + + struct vm *vc_parent; /* [I] */ + uint32_t vc_id; /* [I] */ + uint16_t vc_vpid; /* [I] */ + u_int vc_state; /* [a] */ + SLIST_ENTRY(vcpu) vc_vcpu_link; /* [V] */ + + uint8_t vc_virt_mode; /* [I] */ + + struct rwlock vc_lock; + + struct cpu_info *vc_curcpu; /* [a] */ + struct cpu_info *vc_last_pcpu; /* [v] */ + struct vm_exit vc_exit; /* [v] */ + + uint16_t vc_intr; /* [v] */ + uint8_t vc_irqready; /* [v] */ + + uint8_t vc_fpuinited; /* [v] */ + + uint64_t vc_h_xcr0; /* [v] */ + + struct vcpu_gueststate vc_gueststate; /* [v] */ + struct vcpu_inject_event vc_inject; /* [v] */ + + uint32_t vc_pvclock_version; /* [v] */ + paddr_t vc_pvclock_system_gpa; /* [v] */ + uint32_t vc_pvclock_system_tsc_mul; /* [v] */ + + /* Shadowed MSRs */ + uint64_t vc_shadow_pat; /* [v] */ + + /* Userland Protection Keys */ + uint32_t vc_pkru; /* [v] */ + + /* VMX only (all requiring [v]) */ + uint64_t vc_vmx_basic; + uint64_t vc_vmx_entry_ctls; + uint64_t vc_vmx_true_entry_ctls; + uint64_t vc_vmx_exit_ctls; + uint64_t vc_vmx_true_exit_ctls; + uint64_t vc_vmx_pinbased_ctls; + uint64_t vc_vmx_true_pinbased_ctls; + uint64_t vc_vmx_procbased_ctls; + uint64_t vc_vmx_true_procbased_ctls; + uint64_t vc_vmx_procbased2_ctls; + vaddr_t vc_vmx_msr_exit_save_va; + paddr_t vc_vmx_msr_exit_save_pa; + vaddr_t vc_vmx_msr_exit_load_va; + paddr_t vc_vmx_msr_exit_load_pa; +#if 0 /* XXX currently use msr_exit_save for msr_entry_load too */ + vaddr_t vc_vmx_msr_entry_load_va; + paddr_t vc_vmx_msr_entry_load_pa; +#endif + uint8_t vc_vmx_vpid_enabled; + uint64_t vc_vmx_cr0_fixed1; + uint64_t vc_vmx_cr0_fixed0; + uint32_t vc_vmx_vmcs_state; /* [a] */ +#define VMCS_CLEARED 0 +#define VMCS_LAUNCHED 1 + + /* SVM only (all requiring [v]) */ + vaddr_t vc_svm_hsa_va; + paddr_t vc_svm_hsa_pa; + vaddr_t vc_svm_vmsa_va; + paddr_t vc_svm_vmsa_pa; + vaddr_t vc_svm_ghcb_va; + paddr_t vc_svm_ghcb_pa; + vaddr_t vc_svm_ioio_va; + paddr_t vc_svm_ioio_pa; + int vc_sev; /* [I] */ + int vc_seves; /* [I] */ +}; + +SLIST_HEAD(vcpu_head, vcpu); + +void vmm_dispatch_intr(vaddr_t); +int vmxon(uint64_t *); +int vmxoff(void); +int vmclear(paddr_t *); +int vmptrld(paddr_t *); +int vmptrst(paddr_t *); +int vmwrite(uint64_t, uint64_t); +int vmread(uint64_t, uint64_t *); +int invvpid(uint64_t, struct vmx_invvpid_descriptor *); +int invept(uint64_t, struct vmx_invept_descriptor *); +int vmx_enter_guest(paddr_t *, struct vcpu_gueststate *, int, uint8_t); +int svm_enter_guest(uint64_t, struct vcpu_gueststate *, + struct region_descriptor *); +int svm_seves_enter_guest(uint64_t, vaddr_t, struct region_descriptor *); +void start_vmm_on_cpu(struct cpu_info *); +void stop_vmm_on_cpu(struct cpu_info *); +void vmclear_on_cpu(struct cpu_info *); +int vmm_probe_machdep(struct device *, void *, void *); +void vmm_attach_machdep(struct device *, struct device *, void *); +void vmm_activate_machdep(struct device *, int); +int vmmioctl_machdep(dev_t, u_long, caddr_t, int, struct proc *); +int pledge_ioctl_vmm_machdep(struct proc *, long); +int vmm_start(void); +int vmm_stop(void); +int vm_impl_init(struct vm *, struct proc *); +void vm_impl_deinit(struct vm *); +int vcpu_init(struct vcpu *, struct vm_create_params *); +void vcpu_deinit(struct vcpu *); +int vm_rwregs(struct vm_rwregs_params *, int); +int vcpu_reset_regs(struct vcpu *, struct vcpu_reg_state *); +int svm_get_vmsa_pa(uint32_t, uint32_t, uint64_t *); + +#endif /* _KERNEL */ + +#endif /* ! _LOCORE */ + +#endif /* ! _MACHINE_VMMVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/amd64/vmparam.h b/lib/libc/include/x86_64-openbsd-none/amd64/vmparam.h new file mode 100644 index 0000000000..dc577330a2 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/amd64/vmparam.h @@ -0,0 +1,114 @@ +/* $OpenBSD: vmparam.h,v 1.25 2024/11/08 01:44:52 jsg Exp $ */ +/* $NetBSD: vmparam.h,v 1.1 2003/04/26 18:39:49 fvdl 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. + * + * @(#)vmparam.h 5.9 (Berkeley) 5/12/91 + */ + +#ifndef _MACHINE_VMPARAM_H_ +#define _MACHINE_VMPARAM_H_ + +/* + * Machine dependent constants for amd64. + */ + +/* + * USRSTACK is the top (end) of the user stack. Immediately above the + * user stack resides the user structure, which is UPAGES long and contains + * the kernel stack. + * + * Immediately after the user structure is the page table map, and then + * kernel address space. + */ +#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)128*1024*1024) /* initial data size limit */ +#endif +#ifndef MAXDSIZ +#define MAXDSIZ ((paddr_t)128*1024*1024*1024) /* max data size */ +#endif +#ifndef BRKSIZ +#define BRKSIZ ((paddr_t)8*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 8192 +#endif + +/* + * Size of User Raw I/O map + */ +#define USRIOSIZE 300 + +/* + * Mach derived constants + */ + +/* user/kernel map constants */ +#define VM_MIN_ADDRESS PAGE_SIZE +#define VM_MAXUSER_ADDRESS 0x00007f7fffffc000 +#define VM_MAX_ADDRESS 0x00007fbfdfeff000 +#ifdef _KERNEL +#define VM_MIN_STACK_ADDRESS 0x0000600000000000 +#endif +#define VM_MIN_KERNEL_ADDRESS 0xffff800000000000 +#define VM_MAX_KERNEL_ADDRESS 0xffff800100000000 + +/* map PIE into approximately the first quarter of user va space */ +#define VM_PIE_MIN_ADDR VM_MIN_ADDRESS +#define VM_PIE_MAX_ADDR 0x200000000000 + +/* virtual sizes (bytes) for various kernel submaps */ +#define VM_PHYS_SIZE (USRIOSIZE*PAGE_SIZE) + +#define VM_PHYSSEG_MAX 16 /* actually we could have this many segments */ +#define VM_PHYSSEG_STRAT VM_PSTRAT_BIGFIRST +#define VM_PHYSSEG_NOADD /* can't add RAM after vm_mem_init */ + +#endif /* _MACHINE_VMPARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/frame.h b/lib/libc/include/x86_64-openbsd-none/frame.h new file mode 100644 index 0000000000..bd9658dec4 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/frame.h @@ -0,0 +1,174 @@ +/* $OpenBSD: frame.h,v 1.11 2024/01/31 06:06:28 guenther Exp $ */ +/* $NetBSD: frame.h,v 1.1 2003/04/26 18:39:40 fvdl Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Charles M. Hannum. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*- + * Copyright (c) 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. + * + * @(#)frame.h 5.2 (Berkeley) 1/18/91 + */ + +/* + * Adapted for NetBSD/amd64 by fvdl@wasabisystems.com + */ + +#ifndef _MACHINE_FRAME_H_ +#define _MACHINE_FRAME_H_ + +#include +#include + +/* + * System stack frames. + */ + +/* + * Exception/Trap Stack Frame + */ +struct trapframe { + int64_t tf_rdi; /* ordered by syscall args... */ + int64_t tf_rsi; + int64_t tf_rdx; + int64_t tf_r10; + int64_t tf_r8; + int64_t tf_r9; /* ...to here */ + int64_t tf_rcx; + int64_t tf_r11; + int64_t tf_r12; + int64_t tf_r13; + int64_t tf_r14; + int64_t tf_r15; + int64_t tf_err; /* not the hardware position */ + int64_t tf_rbx; + int64_t tf_rax; + int64_t tf_trapno; + int64_t tf_rbp; /* hardware puts err here, INTRENTRY() moves it up */ + /* below portion defined in hardware */ + int64_t tf_rip; + int64_t tf_cs; + int64_t tf_rflags; + /* These are pushed unconditionally on the x86-64 */ + int64_t tf_rsp; + int64_t tf_ss; +}; + +/* + * Interrupt stack frame + */ +struct intrframe { + int64_t if_rdi; + int64_t if_rsi; + int64_t if_rdx; + int64_t if_r10; + int64_t if_r8; + int64_t if_r9; + int64_t if_rcx; + int64_t if_r11; + int64_t if_r12; + int64_t if_r13; + int64_t if_r14; + int64_t if_r15; + int64_t if_err; /* IREENT_MAGIC if resume/recurse */ + int64_t if_rbx; + int64_t if_rax; + int64_t if_ppl; /* previous priority level */ + int64_t if_rbp; + /* below portion defined in hardware */ + int64_t if_rip; + int64_t if_cs; + int64_t if_rflags; + /* These are pushed unconditionally on the x86-64 */ + int64_t if_rsp; + int64_t if_ss; +}; + + +/* + * The trampoline frame used on the kernel stack page which is present + * but kernel-only, in the page tables used when in userspace. This is + * the minimum for iretq operation. + */ +struct iretq_frame { + int64_t iretq_rip; + int64_t iretq_cs; + int64_t iretq_rflags; + int64_t iretq_rsp; + int64_t iretq_ss; +}; + +/* + * Stack frame inside cpu_switch() + */ +struct switchframe { + int64_t sf_r15; + int64_t sf_r14; + int64_t sf_r13; + int64_t sf_r12; + int64_t sf_rbp; + int64_t sf_rbx; + int64_t sf_rip; +}; + +struct callframe { + struct callframe *f_frame; + long f_retaddr; + long f_arg0; +}; + +#endif /* _MACHINE_FRAME_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/_float.h b/lib/libc/include/x86_64-openbsd-none/machine/_float.h new file mode 100644 index 0000000000..8627bb5499 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/_float.h @@ -0,0 +1,71 @@ +/* $OpenBSD: _float.h,v 1.1 2012/06/26 16:12:43 deraadt Exp $ */ + +/* + * Copyright (c) 1989 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _MACHINE__FLOAT_H_ +#define _MACHINE__FLOAT_H_ + +#define __FLT_RADIX 2 /* b */ +#define __FLT_ROUNDS __flt_rounds() +#define __FLT_EVAL_METHOD 0 /* no promotions */ + +#define __FLT_MANT_DIG 24 /* p */ +#define __FLT_EPSILON 1.19209290E-07F /* b**(1-p) */ +#define __FLT_DIG 6 /* floor((p-1)*log10(b))+(b == 10) */ +#define __FLT_MIN_EXP (-125) /* emin */ +#define __FLT_MIN 1.17549435E-38F /* b**(emin-1) */ +#define __FLT_MIN_10_EXP (-37) /* ceil(log10(b**(emin-1))) */ +#define __FLT_MAX_EXP 128 /* emax */ +#define __FLT_MAX 3.40282347E+38F /* (1-b**(-p))*b**emax */ +#define __FLT_MAX_10_EXP 38 /* floor(log10((1-b**(-p))*b**emax)) */ + +#define __DBL_MANT_DIG 53 +#define __DBL_EPSILON 2.2204460492503131E-16 +#define __DBL_DIG 15 +#define __DBL_MIN_EXP (-1021) +#define __DBL_MIN 2.2250738585072014E-308 +#define __DBL_MIN_10_EXP (-307) +#define __DBL_MAX_EXP 1024 +#define __DBL_MAX 1.7976931348623157E+308 +#define __DBL_MAX_10_EXP 308 + +#define __LDBL_MANT_DIG 64 +#define __LDBL_EPSILON 1.08420217248550443401e-19L +#define __LDBL_DIG 18 +#define __LDBL_MIN_EXP (-16381) +#define __LDBL_MIN 3.36210314311209350626e-4932L +#define __LDBL_MIN_10_EXP (-4931) +#define __LDBL_MAX_EXP 16384 +#define __LDBL_MAX 1.18973149535723176502e+4932L +#define __LDBL_MAX_10_EXP 4932 + +#define __DECIMAL_DIG 21 + +#endif /* _MACHINE__FLOAT_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/_types.h b/lib/libc/include/x86_64-openbsd-none/machine/_types.h new file mode 100644 index 0000000000..6d48c5e033 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/_types.h @@ -0,0 +1,140 @@ +/* $OpenBSD: _types.h,v 1.19 2023/07/02 19:02:27 cheloha 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_ + +/* + * _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) 1 +#define _MAX_PAGE_SHIFT 12 /* same as PAGE_SHIFT */ + +#if defined(_KERNEL) +typedef struct label_t { + long val[8]; +} label_t; +#endif + +/* 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; +typedef long long __int64_t; +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 +typedef int __wchar_t; +#endif +typedef int __wint_t; +typedef int __rune_t; +typedef void * __wctrans_t; +typedef void * __wctype_t; + +#endif /* _MACHINE__TYPES_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/apicvar.h b/lib/libc/include/x86_64-openbsd-none/machine/apicvar.h new file mode 100644 index 0000000000..90c3cd3bc1 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/apicvar.h @@ -0,0 +1,54 @@ +/* $OpenBSD: apicvar.h,v 1.4 2025/09/05 16:57:48 kettenis Exp $ */ +/* $NetBSD: apicvar.h,v 1.1 2003/02/26 21:26:10 fvdl Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by RedBack Networks Inc. + * + * Author: Bill Sommerfeld + * + * 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_APICVAR_H_ +#define _MACHINE_APICVAR_H_ + +#include + +struct apic_attach_args { + const char *aaa_name; + int apic_id; + int apic_version; + int flags; +#define IOAPIC_PICMODE 0x01 +#define IOAPIC_VWIRE 0x02 + bus_space_tag_t apic_memt; + bus_addr_t apic_address; + int apic_vecbase; +}; + +void apic_format_redir(char *, char *, int, u_int32_t, u_int32_t); + +#endif /* !_MACHINE_APICVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/apmvar.h b/lib/libc/include/x86_64-openbsd-none/machine/apmvar.h new file mode 100644 index 0000000000..7407c1c6cf --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/apmvar.h @@ -0,0 +1,303 @@ +/* XXX - DSR */ +/* $OpenBSD: apmvar.h,v 1.8 2019/01/22 02:36:30 phessler Exp $ */ + +/* + * Copyright (c) 1995 John T. Kohl + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef _MACHINE_APMVAR_H_ +#define _MACHINE_APMVAR_H_ + +#include + +/* Advanced Power Management (v1.0 and v1.1 specification) + * functions/defines/etc. + */ + +#define APM_VERSION 0x0102 + +/* + * APM info word from boot loader + */ +#define APM_16BIT_SUPPORTED 0x00010000 +#define APM_32BIT_SUPPORTED 0x00020000 +#define APM_IDLE_SLOWS 0x00040000 +#define APM_BIOS_PM_DISABLED 0x00080000 +#define APM_BIOS_PM_DISENGAGED 0x00100000 +#define APM_MAJOR(f) (((f) >> 8) & 0xff) +#define APM_MINOR(f) ((f) & 0xff) +#define APM_VERMASK 0x0000ffff +#define APM_NOCLI 0x00010000 +#define APM_BEBATT 0x00020000 + +/* APM error codes */ +#define APM_ERR_CODE(regs) (((regs)->ax & 0xff00) >> 8) +#define APM_ERR_PM_DISABLED 0x01 +#define APM_ERR_REALALREADY 0x02 +#define APM_ERR_NOTCONN 0x03 +#define APM_ERR_16ALREADY 0x05 +#define APM_ERR_16NOTSUPP 0x06 +#define APM_ERR_32ALREADY 0x07 +#define APM_ERR_32NOTSUPP 0x08 +#define APM_ERR_UNRECOG_DEV 0x09 +#define APM_ERR_ERANGE 0x0A +#define APM_ERR_NOTENGAGED 0x0B +#define APM_ERR_EOPNOSUPP 0x0C +#define APM_ERR_RTIMER_DISABLED 0x0D +#define APM_ERR_UNABLE 0x60 +#define APM_ERR_NOEVENTS 0x80 +#define APM_ERR_NOT_PRESENT 0x86 + +#define APM_DEV_APM_BIOS 0x0000 +#define APM_DEV_ALLDEVS 0x0001 +/* device classes are high byte; device IDs go in low byte */ +#define APM_DEV_DISPLAY(x) (0x0100|((x)&0xff)) +#define APM_DEV_DISK(x) (0x0200|((x)&0xff)) +#define APM_DEV_PARALLEL(x) (0x0300|((x)&0xff)) +#define APM_DEV_SERIAL(x) (0x0400|((x)&0xff)) +#define APM_DEV_NETWORK(x) (0x0500|((x)&0xff)) +#define APM_DEV_PCMCIA(x) (0x0600|((x)&0xff)) +#define APM_DEV_BATTERIES(x) (0x8000|((x)&0xff)) +#define APM_DEV_ALLUNITS 0xff +/* 0x8100-0xDFFF - reserved */ +/* 0xE000-0xEFFF - OEM-defined */ +/* 0xF000-0xFFFF - reserved */ + +#define APM_INSTCHECK 0x5300 /* int15 only */ +#define APM_16BIT_SUPPORT 0x01 +#define APM_32BIT_SUPPORT 0x02 +#define APM_CPUIDLE_SLOW 0x04 +#define APM_DISABLED 0x08 +#define APM_DISENGAGED 0x10 + +#define APM_REAL_CONNECT 0x5301 /* int15 only */ +#define APM_PROT16_CONNECT 0x5302 /* int15 only */ +#define APM_PROT32_CONNECT 0x5303 /* int15 only */ +#define APM_DISCONNECT 0x5304 /* %bx = APM_DEV_APM_BIOS */ + +#define APM_CPU_IDLE 0x5305 +#define APM_CPU_BUSY 0x5306 + +#define APM_SET_PWR_STATE 0x5307 +#define APM_SYS_READY 0x0000 /* %cx */ +#define APM_SYS_STANDBY 0x0001 +#define APM_SYS_SUSPEND 0x0002 +#define APM_SYS_OFF 0x0003 +#define APM_LASTREQ_INPROG 0x0004 +#define APM_LASTREQ_REJECTED 0x0005 +/* 0x0006 - 0x001f Reserved system states */ +/* 0x0020 - 0x003f OEM-defined system states */ +/* 0x0040 - 0x007f OEM-defined device states */ +/* 0x0080 - 0xffff Reserved device states */ + +/* system standby is device ID (%bx) 0x0001, APM_SYS_STANDBY */ +/* system suspend is device ID (%bx) 0x0001, APM_SYS_SUSPEND */ + +#define APM_PWR_MGT_ENABLE 0x5308 +#define APM_MGT_ALL 0xffff /* %bx */ +#define APM_MGT_DISABLE 0x0 /* %cx */ +#define APM_MGT_ENABLE 0x1 + +#define APM_SYSTEM_DEFAULTS 0x5309 +#define APM_DEFAULTS_ALL 0xffff /* %bx */ + +#define APM_POWER_STATUS 0x530a +#define APM_AC_OFF 0x00 +#define APM_AC_ON 0x01 +#define APM_AC_BACKUP 0x02 +#define APM_AC_UNKNOWN 0xff +#define APM_BATT_HIGH 0x00 +#define APM_BATT_LOW 0x01 +#define APM_BATT_CRITICAL 0x02 +#define APM_BATT_CHARGING 0x03 +#define APM_BATT_UNKNOWN 0xff +#define APM_BATT_FLAG_HIGH 0x01 +#define APM_BATT_FLAG_LOW 0x02 +#define APM_BATT_FLAG_CRITICAL 0x04 +#define APM_BATT_FLAG_CHARGING 0x08 +#define APM_BATT_FLAG_NOBATTERY 0x10 +#define APM_BATT_FLAG_NOSYSBATT 0x80 +#define APM_BATT_LIFE_UNKNOWN 0xff +#define BATT_STATE(regp) ((regp)->bx & 0xff) +#define BATT_FLAGS(regp) (((regp)->cx & 0xff00) >> 8) +#define AC_STATE(regp) (((regp)->bx & 0xff00) >> 8) +#define BATT_LIFE(regp) ((regp)->cx & 0xff) /* in % */ +/* Return time in minutes. According to the APM 1.2 spec: + DX = Remaining battery life -- time units + Bit 15 = 0 Time units are seconds + = 1 Time units are minutes + Bits 14-0 = Number of seconds or minutes */ +#define BATT_REMAINING(regp) (((regp)->dx & 0x8000) ? \ + ((regp)->dx & 0x7fff) : \ + ((regp)->dx & 0x7fff)/60) +#define BATT_REM_VALID(regp) (((regp)->dx & 0xffff) != 0xffff) +#define BATT_COUNT(regp) ((regp)->si) + +#define APM_GET_PM_EVENT 0x530b +#define APM_NOEVENT 0x0000 +#define APM_STANDBY_REQ 0x0001 /* %bx on return */ +#define APM_SUSPEND_REQ 0x0002 +#define APM_NORMAL_RESUME 0x0003 +#define APM_CRIT_RESUME 0x0004 /* suspend/resume happened + without us */ +#define APM_BATTERY_LOW 0x0005 +#define APM_POWER_CHANGE 0x0006 +#define APM_UPDATE_TIME 0x0007 +#define APM_CRIT_SUSPEND_REQ 0x0008 +#define APM_USER_STANDBY_REQ 0x0009 +#define APM_USER_SUSPEND_REQ 0x000A +#define APM_SYS_STANDBY_RESUME 0x000B +#define APM_CAPABILITY_CHANGE 0x000C /* apm v1.2 */ +/* 0x000d - 0x00ff Reserved system events */ +#define APM_USER_HIBERNATE_REQ 0x000D +/* 0x0100 - 0x01ff Reserved device events */ +/* 0x0200 - 0x02ff OEM-defined APM events */ +/* 0x0300 - 0xffff Reserved */ +#define APM_EVENT_MASK 0xffff + +#define APM_EVENT_COMPOSE(t,i) ((((i) & 0x7fff) << 16)|((t) & APM_EVENT_MASK)) +#define APM_EVENT_TYPE(e) ((e) & APM_EVENT_MASK) +#define APM_EVENT_INDEX(e) ((e) >> 16) + +#define APM_GET_POWER_STATE 0x530c +#define APM_DEVICE_MGMT_ENABLE 0x530d + +#define APM_DRIVER_VERSION 0x530e +/* %bx should be DEV value (APM_DEV_APM_BIOS) + %ch = driver major vno + %cl = driver minor vno + return: %ah = conn major; %al = conn minor + */ +#define APM_CONN_MINOR(regp) ((regp)->ax & 0xff) +#define APM_CONN_MAJOR(regp) (((regp)->ax & 0xff00) >> 8) + +#define APM_PWR_MGT_ENGAGE 0x530F +#define APM_MGT_DISENGAGE 0x0 /* %cx */ +#define APM_MGT_ENGAGE 0x1 + +/* %bx - APM_DEV_APM_BIOS + * %bl - number of batteries + * %cx - capabilities + */ +#define APM_GET_CAPABILITIES 0x5310 +#define APM_NBATTERIES(regp) ((regp)->bx) +#define APM_GLOBAL_STANDBY 0x0001 +#define APM_GLOBAL_SUSPEND 0x0002 +#define APM_RTIMER_STANDBY 0x0004 /* resume time wakes up */ +#define APM_RTIMER_SUSPEND 0x0008 +#define APM_IRRING_STANDBY 0x0010 /* internal ring wakes up */ +#define APM_IRRING_SUSPEND 0x0020 +#define APM_PCCARD_STANDBY 0x0040 /* pccard wakes up */ +#define APM_PCCARD_SUSPEND 0x0080 + +/* %bx - APM_DEV_APM_BIOS + * %cl - function + * for %cl=2 (set resume timer) + * %ch - seconds in BCD + * %dh - hours in BCD + * %dl - minutes in BCD + * %si - month in BCD (high), day in BCD (low) + * %di - year in BCD + */ +#define APM_RESUME_TIMER 0x5311 +#define APM_RT_DISABLE 0x0 +#define APM_RT_GET 0x1 +#define APM_RT_SET 0x2 + +/* %bx - APM_DEV_APM_BIOS + * %cx - function + */ +#define APM_RESUME_ON_RING 0x5312 +#define APM_ROR_DISABLE 0x0 +#define APM_ROR_ENABLE 0x1 +#define APM_ROR_STATUS 0x2 + +/* %bx - APM_EDV_APM_BIOS + * %cx - function + */ +#define APM_INACTIVITY_TIMER 0x5313 +#define APM_IT_DISABLE 0x0 +#define APM_IT_ENABLE 0x1 +#define APM_IT_STATUS 0x2 + +/* %bh - function */ +#define APM_OEM 0x5380 +#define APM_OEM_INSTCHECK 0x7f /* %bx - OEM ID */ + +/* + * LP (Laptop Package) + * + * Copyright (C) 1994 by HOSOKAWA Tatsumi + * + * This software may be used, modified, copied, and distributed, in + * both source and binary form provided that the above copyright and + * these terms are retained. Under no circumstances is the author + * responsible for the proper functioning of this software, nor does + * the author assume any responsibility for damages incurred with its + * use. + * + * Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) + */ + +#define APM_BATTERY_ABSENT 4 + +struct apm_power_info { + u_char battery_state; + u_char ac_state; + u_char battery_life; + u_char spare1; + u_int minutes_left; /* estimate */ + u_int spare2[6]; +}; + +struct apm_ctl { + u_int dev; + u_int mode; +}; + +#define APM_IOC_REJECT _IOW('A', 0, struct apm_event_info) /* reject request # */ +#define APM_IOC_STANDBY _IO('A', 1) /* put system into standby */ +#define APM_IOC_SUSPEND _IO('A', 2) /* put system into suspend */ +#define APM_IOC_GETPOWER _IOR('A', 3, struct apm_power_info) /* fetch battery state */ +#define APM_IOC_DEV_CTL _IOW('A', 5, struct apm_ctl) /* put device into mode */ +#define APM_IOC_PRN_CTL _IOW('A', 6, int ) /* driver power status msg */ +#define APM_PRINT_ON 0 /* driver power status displayed */ +#define APM_PRINT_OFF 1 /* driver power status not displayed */ +#define APM_PRINT_PCT 2 /* driver power status only displayed + if the percentage changes */ +#define APM_IOC_STANDBY_REQ _IO('A', 7) /* request standby */ +#define APM_IOC_SUSPEND_REQ _IO('A', 8) /* request suspend */ +#define APM_IOC_HIBERNATE _IO('A', 9) /* put system into hibernate */ + +#ifdef _KERNEL +extern void apm_cpu_busy(void); +extern void apm_cpu_idle(void); +extern void apminit(void); +int apm_set_powstate(u_int devid, u_int powstate); +#endif /* _KERNEL */ + +#endif /* _MACHINE_APMVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/asm.h b/lib/libc/include/x86_64-openbsd-none/machine/asm.h new file mode 100644 index 0000000000..64acd3a4f0 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/asm.h @@ -0,0 +1,196 @@ +/* $OpenBSD: asm.h,v 1.24 2023/04/17 00:02:14 deraadt Exp $ */ +/* $NetBSD: asm.h,v 1.2 2003/05/02 18:05:47 yamt 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. + * + * @(#)asm.h 5.5 (Berkeley) 5/7/91 + */ + +#ifndef _MACHINE_ASM_H_ +#define _MACHINE_ASM_H_ + +#ifdef __PIC__ +#define PIC_PLT(x) x@PLT +#define PIC_GOT(x) x@GOTPCREL(%rip) +#else +#define PIC_PLT(x) x +#define PIC_GOT(x) x +#endif + +# define _C_LABEL(x) x +#define _ASM_LABEL(x) x + +#define CVAROFF(x,y) (x+y)(%rip) + +#ifdef __STDC__ +# define __CONCAT(x,y) x ## y +# define __STRING(x) #x +#else +# define __CONCAT(x,y) x/**/y +# define __STRING(x) "x" +#endif + +/* let kernels and others override entrypoint alignment */ +#ifndef _ALIGN_TEXT +#define _ALIGN_TEXT .align 16, 0x90 +#endif +#define _ALIGN_TRAPS .align 16, 0xcc + +#define _FENTRY(x) .type x,@function; x: + +/* NB == No Binding: use .globl or .weak as necessary */ +#define NENTRY_NB(x) \ + .text; _ALIGN_TEXT; _FENTRY(x) +#define _ENTRY_NB(x) \ + .text; _ALIGN_TRAPS; _FENTRY(x) +#define _ENTRY(x) .globl x; _ENTRY_NB(x) +#define _NENTRY(x) .globl x; NENTRY_NB(x) + +#ifdef _KERNEL +#define KUTEXT .section .kutext, "ax", @progbits + +#define KUTEXT_PAGE_START .pushsection .kutext.page, "a", @progbits +#define KTEXT_PAGE_START .pushsection .ktext.page, "ax", @progbits +#define KUTEXT_PAGE_END .popsection +#define KTEXT_PAGE_END .popsection + +#define IDTVEC(name) \ + KUTEXT; _ALIGN_TRAPS; IDTVEC_NOALIGN(name); endbr64 +#define GENTRY(x) .globl x; _FENTRY(x) +#define IDTVEC_NOALIGN(name) GENTRY(X ## name) +#define IDTVEC_ALIAS(alias,sym) \ + .global X ## alias; \ + X ## alias = X ## sym; +#define KIDTVEC(name) \ + .text; _ALIGN_TRAPS; IDTVEC_NOALIGN(name); endbr64 +#define KIDTVEC_FALLTHROUGH(name) \ + _ALIGN_TEXT; IDTVEC_NOALIGN(name) +#define KUENTRY(x) \ + KUTEXT; _ALIGN_TRAPS; GENTRY(x) + +/* Return stack refill, to prevent speculation attacks on natural returns */ +#define RET_STACK_REFILL_WITH_RCX \ + mov $8,%rcx ; \ + _ALIGN_TEXT ; \ + 3: call 5f ; \ + 4: pause ; \ + lfence ; \ + call 4b ; \ + _ALIGN_TRAPS ; \ + 5: call 7f ; \ + 6: pause ; \ + lfence ; \ + call 6b ; \ + _ALIGN_TRAPS ; \ + 7: loop 3b ; \ + add $(16*8),%rsp + +#endif /* _KERNEL */ + +#ifdef __STDC__ +#define CPUVAR(off) %gs:CPU_INFO_ ## off +#else +#define CPUVAR(off) %gs:CPU_INFO_/**/off +#endif + + +#if defined(PROF) || defined(GPROF) +# define _PROF_PROLOGUE \ + pushq %rbp; leaq (%rsp),%rbp; call PIC_PLT(__mcount); popq %rbp +#else +# define _PROF_PROLOGUE +#endif + +#if defined(_RET_PROTECTOR) +# define RETGUARD_SETUP_OFF(x, reg, off) \ + RETGUARD_SYMBOL(x); \ + movq (__retguard_ ## x)(%rip), %reg; \ + xorq off(%rsp), %reg +# define RETGUARD_SETUP(x, reg) \ + RETGUARD_SETUP_OFF(x, reg, 0) +# define RETGUARD_CHECK(x, reg) \ + xorq (%rsp), %reg; \ + cmpq (__retguard_ ## x)(%rip), %reg; \ + je 66f; \ + int3; int3; \ + .zero (0xf - ((. + 3 - x) & 0xf)), 0xcc; \ +66: +# define RETGUARD_PUSH(reg) \ + pushq %reg +# define RETGUARD_POP(reg) \ + popq %reg +# define RETGUARD_SYMBOL(x) \ + .ifndef __retguard_ ## x; \ + .hidden __retguard_ ## x; \ + .type __retguard_ ## x,@object; \ + .pushsection .openbsd.randomdata.retguard,"aw",@progbits; \ + .weak __retguard_ ## x; \ + .p2align 3; \ + __retguard_ ## x: ; \ + .quad 0; \ + .size __retguard_ ## x, 8; \ + .popsection; \ + .endif +#else +# define RETGUARD_SETUP_OFF(x, reg, off) +# define RETGUARD_SETUP(x, reg) +# define RETGUARD_CHECK(x, reg) +# define RETGUARD_PUSH(reg) +# define RETGUARD_POP(reg) +# define RETGUARD_SYMBOL(x) +#endif + +#define ENTRY(y) _ENTRY(y); endbr64; _PROF_PROLOGUE +#define NENTRY(y) _NENTRY(y) +#define ASENTRY(y) _NENTRY(y); endbr64; _PROF_PROLOGUE +#define ENTRY_NB(y) _ENTRY_NB(y); endbr64; _PROF_PROLOGUE +#define END(y) .size y, . - y + +#define STRONG_ALIAS(alias,sym) \ + .global alias; \ + alias = sym +#define WEAK_ALIAS(alias,sym) \ + .weak alias; \ + alias = sym + +/* generic retpoline ("return trampoline") generator */ +#define JMP_RETPOLINE(reg) \ + call 69f ; \ + 68: pause ; \ + lfence ; \ + jmp 68b ; \ + _ALIGN_TRAPS ; \ + 69: mov %reg,(%rsp) ; \ + ret ; \ + lfence + +#endif /* !_MACHINE_ASM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/atomic.h b/lib/libc/include/x86_64-openbsd-none/machine/atomic.h new file mode 100644 index 0000000000..329eccec1c --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/atomic.h @@ -0,0 +1,325 @@ +/* $OpenBSD: atomic.h,v 1.23 2023/11/11 18:47:02 jca Exp $ */ +/* $NetBSD: atomic.h,v 1.1 2003/04/26 18:39:37 fvdl Exp $ */ + +/* + * Copyright 2002 (c) Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Frank van der Linden for Wasabi Systems, Inc. + * + * 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 for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC + * 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_ATOMIC_H_ +#define _MACHINE_ATOMIC_H_ + +/* + * Perform atomic operations on memory. Should be atomic with respect + * to interrupts and multiple processors. + * + * void atomic_setbits_int(volatile u_int *a, u_int mask) { *a |= mask; } + * void atomic_clearbits_int(volatile u_int *a, u_int mask) { *a &= ~mask; } + */ + +#if !defined(_LOCORE) + +#if defined(MULTIPROCESSOR) || !defined(_KERNEL) +#define _LOCK "lock" +#else +#define _LOCK +#endif + +static inline unsigned int +_atomic_cas_uint(volatile unsigned int *p, unsigned int e, unsigned int n) +{ + __asm volatile(_LOCK " cmpxchgl %2, %1" + : "=a" (n), "=m" (*p) + : "r" (n), "a" (e), "m" (*p)); + + return (n); +} +#define atomic_cas_uint(_p, _e, _n) _atomic_cas_uint((_p), (_e), (_n)) + +static inline unsigned long +_atomic_cas_ulong(volatile unsigned long *p, unsigned long e, unsigned long n) +{ + __asm volatile(_LOCK " cmpxchgq %2, %1" + : "=a" (n), "=m" (*p) + : "r" (n), "a" (e), "m" (*p)); + + return (n); +} +#define atomic_cas_ulong(_p, _e, _n) _atomic_cas_ulong((_p), (_e), (_n)) + +static inline void * +_atomic_cas_ptr(volatile void *p, void *e, void *n) +{ + __asm volatile(_LOCK " cmpxchgq %2, %1" + : "=a" (n), "=m" (*(unsigned long *)p) + : "r" (n), "a" (e), "m" (*(unsigned long *)p)); + + return (n); +} +#define atomic_cas_ptr(_p, _e, _n) _atomic_cas_ptr((_p), (_e), (_n)) + +static inline unsigned int +_atomic_swap_uint(volatile unsigned int *p, unsigned int n) +{ + __asm volatile("xchgl %0, %1" + : "=a" (n), "=m" (*p) + : "0" (n), "m" (*p)); + + return (n); +} +#define atomic_swap_uint(_p, _n) _atomic_swap_uint((_p), (_n)) +#define atomic_swap_32(_p, _n) _atomic_swap_uint((_p), (_n)) + +static inline unsigned long +_atomic_swap_ulong(volatile unsigned long *p, unsigned long n) +{ + __asm volatile("xchgq %0, %1" + : "=a" (n), "=m" (*p) + : "0" (n), "m" (*p)); + + return (n); +} +#define atomic_swap_ulong(_p, _n) _atomic_swap_ulong((_p), (_n)) + +static inline uint64_t +_atomic_swap_64(volatile uint64_t *p, uint64_t n) +{ + __asm volatile("xchgq %0, %1" + : "=a" (n), "=m" (*p) + : "0" (n), "m" (*p)); + + return (n); +} +#define atomic_swap_64(_p, _n) _atomic_swap_64((_p), (_n)) + +static inline void * +_atomic_swap_ptr(volatile void *p, void *n) +{ + __asm volatile("xchgq %0, %1" + : "=a" (n), "=m" (*(unsigned long *)p) + : "0" (n), "m" (*(unsigned long *)p)); + + return (n); +} +#define atomic_swap_ptr(_p, _n) _atomic_swap_ptr((_p), (_n)) + +static inline void +_atomic_inc_int(volatile unsigned int *p) +{ + __asm volatile(_LOCK " incl %0" + : "+m" (*p)); +} +#define atomic_inc_int(_p) _atomic_inc_int(_p) + +static inline void +_atomic_inc_long(volatile unsigned long *p) +{ + __asm volatile(_LOCK " incq %0" + : "+m" (*p)); +} +#define atomic_inc_long(_p) _atomic_inc_long(_p) + +static inline void +_atomic_dec_int(volatile unsigned int *p) +{ + __asm volatile(_LOCK " decl %0" + : "+m" (*p)); +} +#define atomic_dec_int(_p) _atomic_dec_int(_p) + +static inline void +_atomic_dec_long(volatile unsigned long *p) +{ + __asm volatile(_LOCK " decq %0" + : "+m" (*p)); +} +#define atomic_dec_long(_p) _atomic_dec_long(_p) + +static inline void +_atomic_add_int(volatile unsigned int *p, unsigned int v) +{ + __asm volatile(_LOCK " addl %1,%0" + : "+m" (*p) + : "a" (v)); +} +#define atomic_add_int(_p, _v) _atomic_add_int(_p, _v) + +static inline void +_atomic_add_long(volatile unsigned long *p, unsigned long v) +{ + __asm volatile(_LOCK " addq %1,%0" + : "+m" (*p) + : "a" (v)); +} +#define atomic_add_long(_p, _v) _atomic_add_long(_p, _v) + +static inline void +_atomic_sub_int(volatile unsigned int *p, unsigned int v) +{ + __asm volatile(_LOCK " subl %1,%0" + : "+m" (*p) + : "a" (v)); +} +#define atomic_sub_int(_p, _v) _atomic_sub_int(_p, _v) + +static inline void +_atomic_sub_long(volatile unsigned long *p, unsigned long v) +{ + __asm volatile(_LOCK " subq %1,%0" + : "+m" (*p) + : "a" (v)); +} +#define atomic_sub_long(_p, _v) _atomic_sub_long(_p, _v) + + +static inline unsigned long +_atomic_add_int_nv(volatile unsigned int *p, unsigned int v) +{ + unsigned int rv = v; + + __asm volatile(_LOCK " xaddl %0,%1" + : "+a" (rv), "+m" (*p)); + + return (rv + v); +} +#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 = v; + + __asm volatile(_LOCK " xaddq %0,%1" + : "+a" (rv), "+m" (*p)); + + return (rv + v); +} +#define atomic_add_long_nv(_p, _v) _atomic_add_long_nv(_p, _v) + +static inline unsigned long +_atomic_sub_int_nv(volatile unsigned int *p, unsigned int v) +{ + unsigned int rv = 0 - v; + + __asm volatile(_LOCK " xaddl %0,%1" + : "+a" (rv), "+m" (*p)); + + return (rv - v); +} +#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 = 0 - v; + + __asm volatile(_LOCK " xaddq %0,%1" + : "+a" (rv), "+m" (*p)); + + return (rv - v); +} +#define atomic_sub_long_nv(_p, _v) _atomic_sub_long_nv(_p, _v) + +/* + * The AMD64 architecture is rather strongly ordered. When accessing + * normal write-back cacheable memory, only reads may be reordered with + * older writes to different locations. There are a few instructions + * (clfush, non-temporal move instructions) that obey weaker ordering + * rules, but those instructions will only be used in (inline) + * assembly code where we can add the necessary fence instructions + * ourselves. + */ + +#define __membar(_f) do { __asm volatile(_f ::: "memory"); } while (0) + +#if defined(MULTIPROCESSOR) || !defined(_KERNEL) +#define membar_enter() __membar("mfence") +#define membar_exit() __membar("") +#define membar_producer() __membar("") +#define membar_consumer() __membar("") +#define membar_sync() __membar("mfence") +#else +#define membar_enter() __membar("") +#define membar_exit() __membar("") +#define membar_producer() __membar("") +#define membar_consumer() __membar("") +#define membar_sync() __membar("") +#endif + +#define membar_enter_after_atomic() __membar("") +#define membar_exit_before_atomic() __membar("") + +#ifdef _KERNEL + +/* virtio needs MP membars even on SP kernels */ +#define virtio_membar_producer() __membar("") +#define virtio_membar_consumer() __membar("") +#define virtio_membar_sync() __membar("mfence") + +static __inline void +x86_atomic_setbits_u32(volatile u_int32_t *ptr, u_int32_t bits) +{ + __asm volatile(_LOCK " orl %1,%0" : "=m" (*ptr) : "ir" (bits)); +} + +static __inline void +x86_atomic_clearbits_u32(volatile u_int32_t *ptr, u_int32_t bits) +{ + __asm volatile(_LOCK " andl %1,%0" : "=m" (*ptr) : "ir" (~bits)); +} + +static __inline void +x86_atomic_setbits_u64(volatile u_int64_t *ptr, u_int64_t bits) +{ + __asm volatile(_LOCK " orq %1,%0" : "=m" (*ptr) : "er" (bits)); +} + +static __inline void +x86_atomic_clearbits_u64(volatile u_int64_t *ptr, u_int64_t bits) +{ + __asm volatile(_LOCK " andq %1,%0" : "=m" (*ptr) : "er" (~bits)); +} + +#define x86_atomic_testset_ul x86_atomic_testset_u64 +#define x86_atomic_setbits_ul x86_atomic_setbits_u64 +#define x86_atomic_clearbits_ul x86_atomic_clearbits_u64 + +#define atomic_setbits_int x86_atomic_setbits_u32 +#define atomic_clearbits_int x86_atomic_clearbits_u32 + +#endif /* _KERNEL */ + +#undef _LOCK + +#endif /* !defined(_LOCORE) */ +#endif /* _MACHINE_ATOMIC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/biosvar.h b/lib/libc/include/x86_64-openbsd-none/machine/biosvar.h new file mode 100644 index 0000000000..523bb6255b --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/biosvar.h @@ -0,0 +1,283 @@ +/* $OpenBSD: biosvar.h,v 1.32 2023/09/08 20:47:22 kn Exp $ */ + +/* + * Copyright (c) 1997-1999 Michael Shalayeff + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MACHINE_BIOSVAR_H_ +#define _MACHINE_BIOSVAR_H_ + + /* some boxes put apm data seg in the 2nd page */ +#define BOOTARG_OFF (PAGE_SIZE * 2) +#define BOOTARG_LEN (PAGE_SIZE * 1) +#define BOOTBIOS_ADDR (0x7c00) +#define BOOTBIOS_MAXSEC ((1 << 28) - 1) + + /* BIOS configure flags */ +#define BIOSF_BIOS32 0x0001 +#define BIOSF_PCIBIOS 0x0002 +#define BIOSF_PROMSCAN 0x0004 +#define BIOSF_SMBIOS 0x0008 + +/* BIOS media ID */ +#define BIOSM_F320K 0xff /* floppy ds/sd 8 spt */ +#define BIOSM_F160K 0xfe /* floppy ss/sd 8 spt */ +#define BIOSM_F360K 0xfd /* floppy ds/sd 9 spt */ +#define BIOSM_F180K 0xfc /* floppy ss/sd 9 spt */ +#define BIOSM_ROMD 0xfa /* ROM disk */ +#define BIOSM_F120M 0xf9 /* floppy ds/hd 15 spt 5.25" */ +#define BIOSM_F720K 0xf9 /* floppy ds/dd 9 spt 3.50" */ +#define BIOSM_HD 0xf8 /* hard drive */ +#define BIOSM_F144K 0xf0 /* floppy ds/hd 18 spt 3.50" */ +#define BIOSM_OTHER 0xf0 /* any other */ + +/* + * BIOS memory maps + */ +#define BIOS_MAP_END 0x00 /* End of array XXX - special */ +#define BIOS_MAP_FREE 0x01 /* Usable memory */ +#define BIOS_MAP_RES 0x02 /* Reserved memory */ +#define BIOS_MAP_ACPI 0x03 /* ACPI Reclaim memory */ +#define BIOS_MAP_NVS 0x04 /* ACPI NVS memory */ + +/* + * Optional ROM header + */ +typedef +struct bios_romheader { + uint16_t signature; /* 0xaa55 */ + uint8_t len; /* length in pages (512 bytes) */ + uint32_t entry; /* initialization entry point */ + uint8_t reserved[19]; + uint16_t pnpheader; /* offset to PnP expansion header */ +} __packed *bios_romheader_t; + +#define BIOS32_MAKESIG(a, b, c, d) \ + ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24)) +#define SMBIOS_SIGNATURE BIOS32_MAKESIG('_', 'S', 'M', '_') + +/* + * CTL_BIOS definitions. + */ +#define BIOS_DEV 1 /* int: BIOS boot device */ +#define BIOS_DISKINFO 2 /* struct: BIOS boot device info */ +#define BIOS_CKSUMLEN 3 /* int: disk cksum block count */ +#define BIOS_MAXID 4 /* number of valid machdep ids */ + +#define CTL_BIOS_NAMES { \ + { 0, 0 }, \ + { "biosdev", CTLTYPE_INT }, \ + { "diskinfo", CTLTYPE_STRUCT }, \ + { "cksumlen", CTLTYPE_INT }, \ +} + +#define BOOTARG_MEMMAP 0 +typedef struct _bios_memmap { + uint64_t addr; /* Beginning of block */ + uint64_t size; /* Size of block */ + uint32_t type; /* Type of block */ +} __packed bios_memmap_t; + +/* Info about disk from the bios, plus the mapping from + * BIOS numbers to BSD major (driver?) number. + * + * Also, do not bother with BIOSN*() macros, just parcel + * the info out, and use it like this. This makes for less + * of a dependence on BIOSN*() macros having to be the same + * across /boot, /bsd, and userland. + */ +#define BOOTARG_DISKINFO 1 +typedef struct _bios_diskinfo { + /* BIOS section */ + int bios_number; /* BIOS number of drive (or -1) */ + u_int bios_cylinders; /* BIOS cylinders */ + u_int bios_heads; /* BIOS heads */ + u_int bios_sectors; /* BIOS sectors */ + int bios_edd; /* EDD support */ + + /* BSD section */ + dev_t bsd_dev; /* BSD device */ + + /* Checksum section */ + uint32_t checksum; /* Checksum for drive */ + + /* Misc. flags */ + uint32_t flags; +#define BDI_INVALID 0x00000001 /* I/O error during checksumming */ +#define BDI_GOODLABEL 0x00000002 /* Had SCSI or ST506/ESDI disklabel */ +#define BDI_BADLABEL 0x00000004 /* Had another disklabel */ +#define BDI_EL_TORITO 0x00000008 /* 2,048-byte sectors */ +#define BDI_HIBVALID 0x00000010 /* hibernate signature valid */ +#define BDI_PICKED 0x80000000 /* kernel-only: cksum matched */ + +} __packed bios_diskinfo_t; + +#define BOOTARG_APMINFO 2 +typedef struct _bios_apminfo { + /* APM_CONNECT returned values */ + u_int apm_detail; + u_int apm_code32_base; + u_int apm_code16_base; + u_int apm_code_len; + u_int apm_data_base; + u_int apm_data_len; + u_int apm_entry; + u_int apm_code16_len; +} __packed bios_apminfo_t; + +#define BOOTARG_CKSUMLEN 3 /* uint32_t */ + +#define BOOTARG_PCIINFO 4 +typedef struct _bios_pciinfo { + /* PCI BIOS v2.0+ - Installation check values */ + uint32_t pci_chars; /* Characteristics (%eax) */ + uint32_t pci_rev; /* BCD Revision (%ebx) */ + uint32_t pci_entry32; /* PM entry point for PCI BIOS */ + uint32_t pci_lastbus; /* Number of last PCI bus */ +} __packed bios_pciinfo_t; + +#define BOOTARG_CONSDEV 5 +typedef struct _bios_consdev { + dev_t consdev; + int conspeed; + uint64_t consaddr; + int consfreq; + uint32_t flags; +#define BCD_MMIO 0x00000001 /* Memory Mapped IO */ + int reg_width; + int reg_shift; +} __packed bios_consdev_t; + +#define BOOTARG_BOOTMAC 7 +typedef struct _bios_bootmac { + char mac[6]; +} __packed bios_bootmac_t; + +#define BOOTARG_DDB 8 +typedef struct _bios_ddb { + int db_console; +} __packed bios_ddb_t; + +#define BOOTARG_BOOTDUID 9 +typedef struct _bios_bootduid { + u_char duid[8]; +} __packed bios_bootduid_t; + +#define BOOTARG_BOOTSR 10 +#define BOOTSR_UUID_MAX 16 +#define BOOTSR_CRYPTO_MAXKEYBYTES 32 +typedef struct _bios_bootsr { + uint8_t uuid[BOOTSR_UUID_MAX]; + uint8_t maskkey[BOOTSR_CRYPTO_MAXKEYBYTES]; +} __packed bios_bootsr_t; + +#define BOOTARG_EFIINFO 11 +typedef struct _bios_efiinfo { + uint64_t config_acpi; + uint64_t config_smbios; + uint64_t fb_addr; + uint64_t fb_size; + uint32_t fb_height; + uint32_t fb_width; + uint32_t fb_pixpsl; /* pixels per scan line */ + uint32_t fb_red_mask; + uint32_t fb_green_mask; + uint32_t fb_blue_mask; + uint32_t fb_reserved_mask; + uint32_t flags; +#define BEI_64BIT 0x00000001 /* 64-bit EFI implementation */ +#define BEI_ESRT 0x00000002 /* ESRT table */ + uint32_t mmap_desc_ver; + uint32_t mmap_desc_size; + uint32_t mmap_size; + uint64_t mmap_start; + uint64_t system_table; + uint64_t config_esrt; +} __packed bios_efiinfo_t; + +#define BOOTARG_UCODE 12 +typedef struct _bios_ucode { + uint64_t uc_addr; + uint64_t uc_size; +} __packed bios_ucode_t; + +#if defined(_KERNEL) || defined (_STANDALONE) + +#ifdef _LOCORE +#define DOINT(n) int $0x20+(n) +#else +#define DOINT(n) "int $0x20+(" #n ")" + +extern volatile struct BIOS_regs { + uint32_t biosr_ax; + uint32_t biosr_cx; + uint32_t biosr_dx; + uint32_t biosr_bx; + uint32_t biosr_bp; + uint32_t biosr_si; + uint32_t biosr_di; + uint32_t biosr_ds; + uint32_t biosr_es; +} __packed BIOS_regs; + +#ifdef _KERNEL +#include + +struct bios_attach_args { + char *ba_name; + u_int ba_func; + bus_space_tag_t ba_iot; + bus_space_tag_t ba_memt; + union { + void *_p; + bios_apminfo_t *_ba_apmp; + paddr_t _ba_acpipbase; + } _; +}; + +#define ba_apmp _._ba_apmp +#define ba_acpipbase _._ba_acpipbase + +struct consdev; +struct proc; + +int bios_sysctl(int *, u_int, void *, size_t *, void *, size_t, struct proc *); + +void bios_getopt(void); +bios_diskinfo_t *bios_getdiskinfo(dev_t); + +extern int biosbasemem; +extern u_int bootapiver; +extern bios_memmap_t *bios_memmap; +extern bios_efiinfo_t *bios_efiinfo; +extern bios_ucode_t *bios_ucode; + +#endif /* _KERNEL */ +#endif /* _LOCORE */ +#endif /* _KERNEL || _STANDALONE */ + +#endif /* _MACHINE_BIOSVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/bus.h b/lib/libc/include/x86_64-openbsd-none/machine/bus.h new file mode 100644 index 0000000000..140e3a73f3 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/bus.h @@ -0,0 +1,706 @@ +/* $OpenBSD: bus.h,v 1.37 2025/08/23 10:15:49 sf Exp $ */ +/* $NetBSD: bus.h,v 1.6 1996/11/10 03:19:25 thorpej Exp $ */ + +/*- + * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 1996 Charles M. Hannum. All rights reserved. + * Copyright (c) 1996 Jason R. Thorpe. All rights reserved. + * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christopher G. Demetriou + * for the NetBSD Project. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MACHINE_BUS_H_ +#define _MACHINE_BUS_H_ + +#include +#include + +#include + +/* + * Bus address and size types + */ +typedef u_long bus_addr_t; +typedef u_long bus_size_t; + +/* + * Access methods for bus resources and address space. + */ +struct x86_bus_space_ops; +typedef const struct x86_bus_space_ops *bus_space_tag_t; +typedef u_long bus_space_handle_t; + +int bus_space_map(bus_space_tag_t t, bus_addr_t addr, + bus_size_t size, int flags, bus_space_handle_t *bshp); +/* like map, but without extent map checking/allocation */ +int _bus_space_map(bus_space_tag_t t, bus_addr_t addr, + bus_size_t size, int flags, bus_space_handle_t *bshp); + +int bus_space_alloc(bus_space_tag_t t, bus_addr_t rstart, + bus_addr_t rend, bus_size_t size, bus_size_t align, + bus_size_t boundary, int flags, bus_addr_t *addrp, + bus_space_handle_t *bshp); +void bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh, + bus_size_t size); + +/* + * int bus_space_unmap(bus_space_tag_t t, + * bus_space_handle_t bsh, bus_size_t size); + * + * Unmap a region of bus space. + */ + +void bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh, + bus_size_t size); +void _bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh, + bus_size_t size, bus_addr_t *); + +/* like bus_space_map(), but without extent map checking/allocation */ +int _bus_space_map(bus_space_tag_t t, bus_addr_t addr, + bus_size_t size, int flags, bus_space_handle_t *bshp); + +/* + * int bus_space_subregion(bus_space_tag_t t, + * bus_space_handle_t bsh, bus_size_t offset, bus_size_t size, + * bus_space_handle_t *nbshp); + * + * Get a new handle for a subregion of an already-mapped area of bus space. + */ + +int bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh, + bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp); + +struct x86_bus_space_ops { + +/* + * u_intN_t bus_space_read_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset); + * + * Read a 1, 2, 4, or 8 byte quantity from bus space + * described by tag/handle/offset. + */ + u_int8_t (*read_1)(bus_space_handle_t, bus_size_t); + u_int16_t (*read_2)(bus_space_handle_t, bus_size_t); + u_int32_t (*read_4)(bus_space_handle_t, bus_size_t); + u_int64_t (*read_8)(bus_space_handle_t, bus_size_t); + +#define bus_space_read_1(_t, _h, _o) ((_t)->read_1((_h), (_o))) +#define bus_space_read_2(_t, _h, _o) ((_t)->read_2((_h), (_o))) +#define bus_space_read_4(_t, _h, _o) ((_t)->read_4((_h), (_o))) +#define bus_space_read_8(_t, _h, _o) ((_t)->read_8((_h), (_o))) + +#define bus_space_read_raw_2(_t, _h, _o) ((_t)->read_2((_h), (_o))) +#define bus_space_read_raw_4(_t, _h, _o) ((_t)->read_4((_h), (_o))) +#define bus_space_read_raw_8(_t, _h, _o) ((_t)->read_8((_h), (_o))) + +/* + * void bus_space_read_multi_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_intN_t *addr, size_t count); + * + * Read `count' 1, 2, 4, or 8 byte quantities from bus space + * described by tag/handle/offset and copy into buffer provided. + */ + + void (*read_multi_1)(bus_space_handle_t, bus_size_t, + u_int8_t *, bus_size_t); + void (*read_multi_2)(bus_space_handle_t, bus_size_t, + u_int16_t *, bus_size_t); + void (*read_multi_4)(bus_space_handle_t, bus_size_t, + u_int32_t *, bus_size_t); + void (*read_multi_8)(bus_space_handle_t, bus_size_t, + u_int64_t *, bus_size_t); + +#define bus_space_read_multi_1(_t, _h, _o, _a, _c) \ + ((_t)->read_multi_1((_h), (_o), (_a), (_c))) +#define bus_space_read_multi_2(_t, _h, _o, _a, _c) \ + ((_t)->read_multi_2((_h), (_o), (_a), (_c))) +#define bus_space_read_multi_4(_t, _h, _o, _a, _c) \ + ((_t)->read_multi_4((_h), (_o), (_a), (_c))) +#define bus_space_read_multi_8(_t, _h, _o, _a, _c) \ + ((_t)->read_multi_8((_h), (_o), (_a), (_c))) + +/* + * void bus_space_read_raw_multi_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_int8_t *addr, size_t count); + * + * Read `count' bytes in 2, 4 or 8 byte wide quantities from bus space + * described by tag/handle/offset and copy into buffer provided. The buffer + * must have proper alignment for the N byte wide entities. Furthermore + * possible byte-swapping should be done by these functions. + */ + +#define bus_space_read_raw_multi_2(_t, _h, _o, _a, _c) \ + ((_t)->read_multi_2((_h), (_o), (u_int16_t *)(_a), (_c) >> 1)) +#define bus_space_read_raw_multi_4(_t, _h, _o, _a, _c) \ + ((_t)->read_multi_4((_h), (_o), (u_int32_t *)(_a), (_c) >> 2)) +#define bus_space_read_raw_multi_8(_t, _h, _o, _a, _c) \ + ((_t)->read_multi_8((_h), (_o), (u_int64_t *)(_a), (_c) >> 3)) + +/* + * void bus_space_read_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_intN_t *addr, size_t count); + * + * Read `count' 1, 2, 4, or 8 byte quantities from bus space + * described by tag/handle and starting at `offset' and copy into + * buffer provided. + */ + + void (*read_region_1)(bus_space_handle_t, + bus_size_t, u_int8_t *, bus_size_t); + void (*read_region_2)(bus_space_handle_t, + bus_size_t, u_int16_t *, bus_size_t); + void (*read_region_4)(bus_space_handle_t, + bus_size_t, u_int32_t *, bus_size_t); + void (*read_region_8)(bus_space_handle_t, + bus_size_t, u_int64_t *, bus_size_t); + +#define bus_space_read_region_1(_t, _h, _o, _a, _c) \ + ((_t)->read_region_1((_h), (_o), (_a), (_c))) +#define bus_space_read_region_2(_t, _h, _o, _a, _c) \ + ((_t)->read_region_2((_h), (_o), (_a), (_c))) +#define bus_space_read_region_4(_t, _h, _o, _a, _c) \ + ((_t)->read_region_4((_h), (_o), (_a), (_c))) +#define bus_space_read_region_8(_t, _h, _o, _a, _c) \ + ((_t)->read_region_8((_h), (_o), (_a), (_c))) + +/* + * void bus_space_read_raw_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_int8_t *addr, size_t count); + * + * Read `count' bytes in 2, 4 or 8 byte wide quantities from bus space + * described by tag/handle and starting at `offset' and copy into + * buffer provided. The buffer must have proper alignment for the N byte + * wide entities. Furthermore possible byte-swapping should be done by + * these functions. + */ + +#define bus_space_read_raw_region_2(_t, _h, _o, _a, _c) \ + ((_t)->read_region_2((_h), (_o), (u_int16_t *)(_a), (_c) >> 1)) +#define bus_space_read_raw_region_4(_t, _h, _o, _a, _c) \ + ((_t)->read_region_4((_h), (_o), (u_int32_t *)(_a), (_c) >> 2)) +#define bus_space_read_raw_region_8(_t, _h, _o, _a, _c) \ + ((_t)->read_region_8((_h), (_o), (u_int64_t *)(_a), (_c) >> 3)) + +/* + * void bus_space_write_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_intN_t value); + * + * Write the 1, 2, 4, or 8 byte value `value' to bus space + * described by tag/handle/offset. + */ + + void (*write_1)(bus_space_handle_t, bus_size_t, u_int8_t); + void (*write_2)(bus_space_handle_t, bus_size_t, u_int16_t); + void (*write_4)(bus_space_handle_t, bus_size_t, u_int32_t); + void (*write_8)(bus_space_handle_t, bus_size_t, u_int64_t); + +#define bus_space_write_1(_t, _h, _o, _v) \ + ((_t)->write_1((_h), (_o), (_v))) +#define bus_space_write_2(_t, _h, _o, _v) \ + ((_t)->write_2((_h), (_o), (_v))) +#define bus_space_write_4(_t, _h, _o, _v) \ + ((_t)->write_4((_h), (_o), (_v))) +#define bus_space_write_8(_t, _h, _o, _v) \ + ((_t)->write_8((_h), (_o), (_v))) + +#define bus_space_write_raw_2(_t, _h, _o, _v) \ + ((_t)->write_2((_h), (_o), (_v))) +#define bus_space_write_raw_4(_t, _h, _o, _v) \ + ((_t)->write_4((_h), (_o), (_v))) +#define bus_space_write_raw_8(_t, _h, _o, _v) \ + ((_t)->write_8((_h), (_o), (_v))) + +/* + * void bus_space_write_multi_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * const u_intN_t *addr, size_t count); + * + * Write `count' 1, 2, 4, or 8 byte quantities from the buffer + * provided to bus space described by tag/handle/offset. + */ + + void (*write_multi_1)(bus_space_handle_t, + bus_size_t, const u_int8_t *, bus_size_t); + void (*write_multi_2)(bus_space_handle_t, + bus_size_t, const u_int16_t *, bus_size_t); + void (*write_multi_4)(bus_space_handle_t, + bus_size_t, const u_int32_t *, bus_size_t); + void (*write_multi_8)(bus_space_handle_t, + bus_size_t, const u_int64_t *, bus_size_t); + +#define bus_space_write_multi_1(_t, _h, _o, _a, _c) \ + ((_t)->write_multi_1((_h), (_o), (_a), (_c))) +#define bus_space_write_multi_2(_t, _h, _o, _a, _c) \ + ((_t)->write_multi_2((_h), (_o), (_a), (_c))) +#define bus_space_write_multi_4(_t, _h, _o, _a, _c) \ + ((_t)->write_multi_4((_h), (_o), (_a), (_c))) +#define bus_space_write_multi_8(_t, _h, _o, _a, _c) \ + ((_t)->write_multi_8((_h), (_o), (_a), (_c))) + +/* + * void bus_space_write_raw_multi_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * const u_int8_t *addr, size_t count); + * + * Write `count' bytes in 2, 4 or 8 byte wide quantities from the buffer + * provided to bus space described by tag/handle/offset. The buffer + * must have proper alignment for the N byte wide entities. Furthermore + * possible byte-swapping should be done by these functions. + */ + +#define bus_space_write_raw_multi_2(_t, _h, _o, _a, _c) \ + ((_t)->write_multi_2((_h), (_o), (const u_int16_t *)(_a), (_c) >> 1)) +#define bus_space_write_raw_multi_4(_t, _h, _o, _a, _c) \ + ((_t)->write_multi_4((_h), (_o), (const u_int32_t *)(_a), (_c) >> 2)) +#define bus_space_write_raw_multi_8(_t, _h, _o, _a, _c) \ + ((_t)->write_multi_8((_h), (_o), (const u_int64_t *)(_a), (_c) >> 3)) + +/* + * void bus_space_write_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * const u_intN_t *addr, size_t count); + * + * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided + * to bus space described by tag/handle starting at `offset'. + */ + + void (*write_region_1)(bus_space_handle_t, + bus_size_t, const u_int8_t *, bus_size_t); + void (*write_region_2)(bus_space_handle_t, + bus_size_t, const u_int16_t *, bus_size_t); + void (*write_region_4)(bus_space_handle_t, + bus_size_t, const u_int32_t *, bus_size_t); + void (*write_region_8)(bus_space_handle_t, + bus_size_t, const u_int64_t *, bus_size_t); + +#define bus_space_write_region_1(_t, _h, _o, _a, _c) \ + ((_t)->write_region_1((_h), (_o), (_a), (_c))) +#define bus_space_write_region_2(_t, _h, _o, _a, _c) \ + ((_t)->write_region_2((_h), (_o), (_a), (_c))) +#define bus_space_write_region_4(_t, _h, _o, _a, _c) \ + ((_t)->write_region_4((_h), (_o), (_a), (_c))) +#define bus_space_write_region_8(_t, _h, _o, _a, _c) \ + ((_t)->write_region_8((_h), (_o), (_a), (_c))) + +/* + * void bus_space_write_raw_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * const u_int8_t *addr, size_t count); + * + * Write `count' bytes in 2, 4 or 8 byte wide quantities to bus space + * described by tag/handle and starting at `offset' from the + * buffer provided. The buffer must have proper alignment for the N byte + * wide entities. Furthermore possible byte-swapping should be done by + * these functions. + */ + +#define bus_space_write_raw_region_2(_t, _h, _o, _a, _c) \ + ((_t)->write_region_2((_h), (_o), (const u_int16_t *)(_a), (_c) >> 1)) +#define bus_space_write_raw_region_4(_t, _h, _o, _a, _c) \ + ((_t)->write_region_4((_h), (_o), (const u_int32_t *)(_a), (_c) >> 2)) +#define bus_space_write_raw_region_8(_t, _h, _o, _a, _c) \ + ((_t)->write_region_8((_h), (_o), (const u_int64_t *)(_a), (_c) >> 3)) + +/* + * void bus_space_set_multi_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_intN_t val, size_t count); + * + * Write the 1, 2, 4, or 8 byte value `val' to bus space described + * by tag/handle/offset `count' times. + */ + + void (*set_multi_1)(bus_space_handle_t, + bus_size_t, u_int8_t, size_t); + void (*set_multi_2)(bus_space_handle_t, + bus_size_t, u_int16_t, size_t); + void (*set_multi_4)(bus_space_handle_t, + bus_size_t, u_int32_t, size_t); + void (*set_multi_8)(bus_space_handle_t, + bus_size_t, u_int64_t, size_t); + +#define bus_space_set_multi_1(_t, _h, _o, _a, _c) \ + ((_t)->set_multi_1((_h), (_o), (_a), (_c))) +#define bus_space_set_multi_2(_t, _h, _o, _a, _c) \ + ((_t)->set_multi_2((_h), (_o), (_a), (_c))) +#define bus_space_set_multi_4(_t, _h, _o, _a, _c) \ + ((_t)->set_multi_4((_h), (_o), (_a), (_c))) +#define bus_space_set_multi_8(_t, _h, _o, _a, _c) \ + ((_t)->set_multi_8((_h), (_o), (_a), (_c))) + +/* + * void bus_space_set_region_N(bus_space_tag_t tag, + * bus_space_handle_t bsh, bus_size_t offset, + * u_intN_t val, size_t count); + * + * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described + * by tag/handle starting at `offset'. + */ + + void (*set_region_1)(bus_space_handle_t, + bus_size_t, u_int8_t, size_t); + void (*set_region_2)(bus_space_handle_t, + bus_size_t, u_int16_t, size_t); + void (*set_region_4)(bus_space_handle_t, + bus_size_t, u_int32_t, size_t); + void (*set_region_8)(bus_space_handle_t, + bus_size_t, u_int64_t, size_t); + +#define bus_space_set_region_1(_t, _h, _o, _a, _c) \ + ((_t)->set_region_1((_h), (_o), (_a), (_c))) +#define bus_space_set_region_2(_t, _h, _o, _a, _c) \ + ((_t)->set_region_2((_h), (_o), (_a), (_c))) +#define bus_space_set_region_4(_t, _h, _o, _a, _c) \ + ((_t)->set_region_4((_h), (_o), (_a), (_c))) +#define bus_space_set_region_8(_t, _h, _o, _a, _c) \ + ((_t)->set_region_8((_h), (_o), (_a), (_c))) + +/* + * void bus_space_copy_N(bus_space_tag_t tag, + * bus_space_handle_t bsh1, bus_size_t off1, + * bus_space_handle_t bsh2, bus_size_t off2, + * size_t count); + * + * Copy `count' 1, 2, 4, or 8 byte values from bus space starting + * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2. + */ + + void (*copy_1)(bus_space_handle_t, + bus_size_t, bus_space_handle_t, bus_size_t, size_t); + void (*copy_2)(bus_space_handle_t, + bus_size_t, bus_space_handle_t, bus_size_t, size_t); + void (*copy_4)(bus_space_handle_t, + bus_size_t, bus_space_handle_t, bus_size_t, size_t); + void (*copy_8)(bus_space_handle_t, + bus_size_t, bus_space_handle_t, bus_size_t, size_t); + +#define bus_space_copy_1(_t, _h1, _o1, _h2, _o2, _c) \ + ((_t)->copy_1((_h1), (_o1), (_h2), (_o2), (_c))) +#define bus_space_copy_2(_t, _h1, _o1, _h2, _o2, _c) \ + ((_t)->copy_2((_h1), (_o1), (_h2), (_o2), (_c))) +#define bus_space_copy_4(_t, _h1, _o1, _h2, _o2, _c) \ + ((_t)->copy_4((_h1), (_o1), (_h2), (_o2), (_c))) +#define bus_space_copy_8(_t, _h1, _o1, _h2, _o2, _c) \ + ((_t)->copy_8((_h1), (_o1), (_h2), (_o2), (_c))) + +/* + * void *bus_space_vaddr(bus_space_tag_t, bus_space_handle_t); + * + * Get the kernel virtual address for the mapped bus space. + * Only allowed for regions mapped with BUS_SPACE_MAP_LINEAR. + */ + void * (*vaddr)(bus_space_handle_t); + +#define bus_space_vaddr(_t, _h) \ + ((_t)->vaddr((_h))) + +/* + * paddr_t bus_space_mmap(bus_space_tag_t t, bus_addr_t base, + * off_t offset, int prot, int flags); + * + * Mmap an area of bus space. + */ + + paddr_t (*mmap)(bus_addr_t, off_t, int, int); + +#define bus_space_mmap(_t, _a, _o, _p, _f) \ + ((_t)->mmap((_a), (_o), (_p), (_f))) +}; + +/* + * Bus read/write barrier methods. + */ +#define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */ +#define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */ + +static inline void +bus_space_barrier(bus_space_tag_t space, bus_space_handle_t + handle, bus_size_t offset, bus_size_t length, int flags) +{ + switch (flags) { + case (BUS_SPACE_BARRIER_READ|BUS_SPACE_BARRIER_WRITE): + __asm volatile("mfence" ::: "memory"); + break; + case BUS_SPACE_BARRIER_WRITE: + __asm volatile("sfence" ::: "memory"); + break; + default: + __asm volatile("lfence" ::: "memory"); + break; + } +} + +#define BUS_SPACE_MAP_CACHEABLE 0x0001 +#define BUS_SPACE_MAP_LINEAR 0x0002 +#define BUS_SPACE_MAP_PREFETCHABLE 0x0008 + +/* + * Values for the x86 bus space tag, not to be used directly by MI code. + */ + +/* space is i/o space */ +extern const struct x86_bus_space_ops *x86_bus_space_io_ops; +#define X86_BUS_SPACE_IO (x86_bus_space_io_ops) + +/* space is mem space */ +extern const struct x86_bus_space_ops *x86_bus_space_mem_ops; +#define X86_BUS_SPACE_MEM (x86_bus_space_mem_ops) + +/* + * bus_dma + */ + +/* + * Flags used in various bus DMA methods. + */ +#define BUS_DMA_WAITOK 0x0000 /* safe to sleep (pseudo-flag) */ +#define BUS_DMA_NOWAIT 0x0001 /* not safe to sleep */ +#define BUS_DMA_ALLOCNOW 0x0002 /* perform resource allocation now */ +#define BUS_DMA_COHERENT 0x0004 /* hint: map memory DMA coherent */ +#define BUS_DMA_BUS1 0x0010 /* placeholders for bus functions... */ +#define BUS_DMA_BUS2 0x0020 +#define BUS_DMA_32BIT 0x0040 +#define BUS_DMA_24BIT 0x0080 /* isadma map */ +#define BUS_DMA_STREAMING 0x0100 /* hint: sequential, unidirectional */ +#define BUS_DMA_READ 0x0200 /* mapping is device -> memory only */ +#define BUS_DMA_WRITE 0x0400 /* mapping is memory -> device only */ +#define BUS_DMA_NOCACHE 0x0800 /* map memory uncached */ +#define BUS_DMA_ZERO 0x1000 /* zero memory in dmamem_alloc */ +#define BUS_DMA_64BIT 0x2000 /* device handles 64bit dva */ + +/* Forwards needed by prototypes below. */ +struct mbuf; +struct proc; +struct uio; + +/* + * Operations performed by bus_dmamap_sync(). + */ +#define BUS_DMASYNC_PREREAD 0x01 +#define BUS_DMASYNC_POSTREAD 0x02 +#define BUS_DMASYNC_PREWRITE 0x04 +#define BUS_DMASYNC_POSTWRITE 0x08 + +typedef struct bus_dma_tag *bus_dma_tag_t; +typedef struct bus_dmamap *bus_dmamap_t; + +/* + * bus_dma_segment_t + * + * Describes a single contiguous DMA transaction. Values + * are suitable for programming into DMA registers. + */ +struct bus_dma_segment { + bus_addr_t ds_addr; /* DMA address */ + bus_size_t ds_len; /* length of transfer */ + vaddr_t _ds_va; /* mapped loaded data */ + vaddr_t _ds_bounce_va; /* mapped bounced data */ + + /* + * Ugh. need this so can pass alignment down from bus_dmamem_alloc + * to scatter gather maps. only the first one is used so the rest is + * wasted space. bus_dma could do with fixing the api for this. + */ + bus_size_t _ds_boundary; /* don't cross */ + bus_size_t _ds_align; /* align to me */ +}; +typedef struct bus_dma_segment bus_dma_segment_t; + +/* + * bus_dma_tag_t + * + * A machine-dependent opaque type describing the implementation of + * DMA for a given bus. + */ + +struct bus_dma_tag { + void *_cookie; /* cookie used in the guts */ + + /* + * DMA mapping methods. + */ + int (*_dmamap_create)(bus_dma_tag_t, bus_size_t, int, + bus_size_t, bus_size_t, int, bus_dmamap_t *); + void (*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t); + int (*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int); + int (*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t, + struct mbuf *, int); + int (*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t, + struct uio *, int); + int (*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); + void (*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t); + void (*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t, + bus_addr_t, bus_size_t, int); + + /* + * DMA memory utility functions. + */ + int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int); + int (*_dmamem_alloc_range)(bus_dma_tag_t, bus_size_t, bus_size_t, + bus_size_t, bus_dma_segment_t *, int, int *, int, + bus_addr_t, bus_addr_t); + void (*_dmamem_free)(bus_dma_tag_t, + bus_dma_segment_t *, int); + int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *, + int, size_t, caddr_t *, int); + void (*_dmamem_unmap)(bus_dma_tag_t, caddr_t, size_t); + paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *, + int, off_t, int, int); +}; + +#define bus_dmamap_create(t, s, n, m, b, f, p) \ + (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p)) +#define bus_dmamap_destroy(t, p) \ + (*(t)->_dmamap_destroy)((t), (p)) +#define bus_dmamap_load(t, m, b, s, p, f) \ + (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f)) +#define bus_dmamap_load_mbuf(t, m, b, f) \ + (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f)) +#define bus_dmamap_load_uio(t, m, u, f) \ + (*(t)->_dmamap_load_uio)((t), (m), (u), (f)) +#define bus_dmamap_load_raw(t, m, sg, n, s, f) \ + (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f)) +#define bus_dmamap_unload(t, p) \ + (*(t)->_dmamap_unload)((t), (p)) +#define bus_dmamap_sync(t, p, o, l, ops) \ + (*(t)->_dmamap_sync)((t), (p), (o), (l), (ops)) + +#define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \ + (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f)) +#define bus_dmamem_alloc_range(t, s, a, b, sg, n, r, f, l, h) \ + (*(t)->_dmamem_alloc_range)((t), (s), (a), (b), (sg), \ + (n), (r), (f), (l), (h)) +#define bus_dmamem_free(t, sg, n) \ + (*(t)->_dmamem_free)((t), (sg), (n)) +#define bus_dmamem_map(t, sg, n, s, k, f) \ + (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f)) +#define bus_dmamem_unmap(t, k, s) \ + (*(t)->_dmamem_unmap)((t), (k), (s)) +#define bus_dmamem_mmap(t, sg, n, o, p, f) \ + (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f)) + +/* + * bus_dmamap_t + * + * Describes a DMA mapping. + */ +struct bus_dmamap { + /* + * PRIVATE MEMBERS: not for use by machine-independent code. + */ + bus_size_t _dm_size; /* largest DMA transfer mappable */ + int _dm_flags; /* misc. flags */ + int _dm_segcnt; /* number of segs this map can map */ + bus_size_t _dm_maxsegsz; /* largest possible segment */ + bus_size_t _dm_boundary; /* don't cross this */ + + void *_dm_cookie; /* cookie for bus-specific functions */ + + struct vm_page **_dm_pages; /* replacement pages */ + vaddr_t _dm_pgva; /* those above -- mapped */ + int _dm_npages; /* number of pages allocated */ + int _dm_nused; /* number of pages replaced */ + + /* + * PUBLIC MEMBERS: these are used by machine-independent code. + */ + bus_size_t dm_mapsize; /* size of the mapping */ + int dm_nsegs; /* # valid segments in mapping */ + bus_dma_segment_t dm_segs[1]; /* segments; variable length */ +}; + +int _bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t, + bus_size_t, int, bus_dmamap_t *); +void _bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t); +int _bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, + bus_size_t, struct proc *, int); +int _bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, + struct mbuf *, int); +int _bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, + struct uio *, int); +int _bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, + bus_dma_segment_t *, int, bus_size_t, int); +void _bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t); +void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, + bus_size_t, int); + +int _bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size, + bus_size_t alignment, bus_size_t boundary, + bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags); +void _bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs, + int nsegs); +int _bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs, + int nsegs, size_t size, caddr_t *kvap, int flags); +void _bus_dmamem_unmap(bus_dma_tag_t tag, caddr_t kva, + size_t size); +paddr_t _bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs, + int nsegs, off_t off, int prot, int flags); + +int _bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size, + bus_size_t alignment, bus_size_t boundary, + bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags, + bus_addr_t low, bus_addr_t high); + +#endif /* _MACHINE_BUS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/cdefs.h b/lib/libc/include/x86_64-openbsd-none/machine/cdefs.h new file mode 100644 index 0000000000..cd6f968643 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/cdefs.h @@ -0,0 +1,21 @@ +/* $OpenBSD: cdefs.h,v 1.3 2013/03/28 17:30:45 martynas Exp $ */ + +/* + * Written by J.T. Conklin 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_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/codepatch.h b/lib/libc/include/x86_64-openbsd-none/machine/codepatch.h new file mode 100644 index 0000000000..04ea726a26 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/codepatch.h @@ -0,0 +1,120 @@ +/* $OpenBSD: codepatch.h,v 1.19 2024/02/12 01:18:17 guenther Exp $ */ +/* + * Copyright (c) 2014-2015 Stefan Fritsch + * + * 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_CODEPATCH_H_ +#define _MACHINE_CODEPATCH_H_ + +#include + +#ifndef _LOCORE + +/* code in this section will be unmapped after boot */ +#define __cptext __attribute__((section(".cptext"))) + +__cptext void *codepatch_maprw(vaddr_t *nva, vaddr_t dest); +__cptext void codepatch_unmaprw(vaddr_t nva); +__cptext void codepatch_fill_nop(void *caddr, uint16_t len); +__cptext void codepatch_nop(uint16_t tag); +__cptext void codepatch_replace(uint16_t tag, const void *code, size_t len); +__cptext void codepatch_call(uint16_t _tag, void *_func); +__cptext void codepatch_jmp(uint16_t _tag, void *_func); +void codepatch_disable(void); + +#endif /* !_LOCORE */ + +/* + * Mark the start of some code snippet to be patched. + */ +#define CODEPATCH_START 998: +/* + * Mark the end of some code to be patched, and assign the given tag. + */ +#define CODEPATCH_END2(startnum,tag) \ + 999: \ + .section .codepatch, "a" ;\ + .quad startnum##b ;\ + .short (999b - startnum##b) ;\ + .short tag ;\ + .int 0 ;\ + .previous +#define CODEPATCH_END(tag) CODEPATCH_END2(998,tag) + +#define CPTAG_STAC 1 +#define CPTAG_CLAC 2 +#define CPTAG_EOI 3 +#define CPTAG_XRSTOR 4 +#define CPTAG_XSAVE 5 +#define CPTAG_MELTDOWN_NOP 6 +#define CPTAG_MELTDOWN_ALLTRAPS 7 +#define CPTAG_PCID_SET_REUSE 8 +#define CPTAG_MDS 9 +#define CPTAG_MDS_VMM 10 +#define CPTAG_FENCE_SWAPGS_MIS_TAKEN 11 +#define CPTAG_FENCE_NO_SAFE_SMAP 12 +#define CPTAG_XRSTORS 13 +#define CPTAG_RETPOLINE_RAX 14 +#define CPTAG_RETPOLINE_R11 15 +#define CPTAG_RETPOLINE_R13 16 +#define CPTAG_IBPB_NOP 17 + +/* + * stac/clac SMAP instructions have lfence like semantics. Let's + * guarantee those semantics on older cpus. + */ +#define SMAP_NOP lfence +#define SMAP_STAC CODEPATCH_START ;\ + SMAP_NOP ;\ + CODEPATCH_END(CPTAG_STAC) +#define SMAP_CLAC CODEPATCH_START ;\ + SMAP_NOP ;\ + CODEPATCH_END(CPTAG_CLAC) + +/* CVE-2019-1125: block speculation after swapgs */ +#define FENCE_SWAPGS_MIS_TAKEN \ + CODEPATCH_START ; \ + lfence ; \ + CODEPATCH_END(CPTAG_FENCE_SWAPGS_MIS_TAKEN) +/* block speculation when a correct SMAP impl would have been enough */ +#define FENCE_NO_SAFE_SMAP \ + CODEPATCH_START ; \ + lfence ; \ + CODEPATCH_END(CPTAG_FENCE_NO_SAFE_SMAP) + +#define PCID_SET_REUSE_SIZE 12 +#define PCID_SET_REUSE_NOP \ + 997: ;\ + .byte 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 ;\ + .byte 0x0f, 0x1f, 0x40, 0x00 ;\ + CODEPATCH_END2(997, CPTAG_PCID_SET_REUSE) + +/* Would be neat if these could be in something like .cptext */ +#define CODEPATCH_CODE(symbol, instructions...) \ + .section .rodata; \ + .globl symbol; \ +symbol: instructions; \ + .size symbol, . - symbol + +/* provide a (short) variable with the length of the patch */ +#define CODEPATCH_CODE_LEN(symbol, instructions...) \ + CODEPATCH_CODE(symbol, instructions); \ +996: .globl symbol##_len; \ + .align 2; \ +symbol##_len: \ + .short 996b - symbol; \ + .size symbol##_len, 2 + +#endif /* _MACHINE_CODEPATCH_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/conf.h b/lib/libc/include/x86_64-openbsd-none/machine/conf.h new file mode 100644 index 0000000000..bd23d33ba7 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/conf.h @@ -0,0 +1,59 @@ +/* $OpenBSD: conf.h,v 1.11 2024/09/04 07:45:08 jsg Exp $ */ +/* $NetBSD: conf.h,v 1.2 1996/05/05 19:28:34 christos Exp $ */ + +/* + * Copyright (c) 1996 Christos Zoulas. 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 Christos Zoulas. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#define mmread mmrw +#define mmwrite mmrw +cdev_decl(mm); + +bdev_decl(fd); +cdev_decl(fd); + +cdev_decl(spkr); + +cdev_decl(bios); + +#define cdev_acpi_init(c,n) {\ + dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ + (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \ + (dev_type_stop((*))) enodev, 0, \ + (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,n,kqfilter) } +cdev_decl(acpi); + +cdev_decl(pctr); + +#include "vmm.h" +cdev_decl(vmm); + +#include "psp.h" +cdev_decl(psp); \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/cpu.h b/lib/libc/include/x86_64-openbsd-none/machine/cpu.h new file mode 100644 index 0000000000..d3cab29e55 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/cpu.h @@ -0,0 +1,530 @@ +/* $OpenBSD: cpu.h,v 1.180 2025/04/28 16:18:25 bluhm Exp $ */ +/* $NetBSD: cpu.h,v 1.1 2003/04/26 18:39:39 fvdl 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. + * + * @(#)cpu.h 5.4 (Berkeley) 5/9/91 + */ + +#ifndef _MACHINE_CPU_H_ +#define _MACHINE_CPU_H_ + +/* + * Definitions unique to x86-64 cpu support. + */ +#ifdef _KERNEL +#include +#include /* USERMODE */ +#include +#endif /* _KERNEL */ + +#include +#include +#include +#include +#include +#include +#include + +#ifdef _KERNEL + +/* VMXON region (Intel) */ +struct vmxon_region { + uint32_t vr_revision; +}; + +/* + * VMX for Intel CPUs + */ +struct vmx { + uint64_t vmx_cr0_fixed0; + uint64_t vmx_cr0_fixed1; + uint64_t vmx_cr4_fixed0; + uint64_t vmx_cr4_fixed1; + uint32_t vmx_vmxon_revision; + uint32_t vmx_msr_table_size; + uint32_t vmx_cr3_tgt_count; + uint8_t vmx_has_l1_flush_msr; + uint64_t vmx_invept_mode; +}; + +/* + * SVM for AMD CPUs + */ +struct svm { + uint32_t svm_max_asid; + uint8_t svm_flush_by_asid; + uint8_t svm_vmcb_clean; + uint8_t svm_decode_assist; +}; + +union vmm_cpu_cap { + struct vmx vcc_vmx; + struct svm vcc_svm; +}; + +enum cpu_vendor { + CPUV_UNKNOWN, + CPUV_AMD, + CPUV_INTEL, + CPUV_VIA, +}; + +/* + * Locks used to protect struct members in this file: + * I immutable after creation + * a atomic operations + * o owned (read/modified only) by this CPU + */ +struct x86_64_tss; +struct vcpu; +struct cpu_info { + /* + * The beginning of this structure in mapped in the userspace "u-k" + * page tables, so that these first couple members can be accessed + * from the trampoline code. The ci_PAGEALIGN member defines where + * the part that is *not* visible begins, so don't put anything + * above it that must be kept hidden from userspace! + */ + u_int64_t ci_kern_cr3; /* [o] U+K page table */ + u_int64_t ci_scratch; /* [o] for U<-->K transition */ + +#define ci_PAGEALIGN ci_dev + struct device *ci_dev; /* [I] */ + struct cpu_info *ci_self; /* [I] */ + struct cpu_info *ci_next; /* [I] */ + + u_int ci_cpuid; /* [I] */ + u_int ci_apicid; /* [I] */ + u_int ci_acpi_proc_id; /* [I] */ + u_int32_t ci_randseed; /* [o] */ + + u_int64_t ci_kern_rsp; /* [o] kernel-only stack */ + u_int64_t ci_intr_rsp; /* [o] U<-->K trampoline stack */ + u_int64_t ci_user_cr3; /* [o] U-K page table */ + + /* bits for mitigating Micro-architectural Data Sampling */ + char ci_mds_tmp[64]; /* [o] 64-byte aligned */ + void *ci_mds_buf; /* [I] */ + + struct proc *ci_curproc; /* [o] */ + struct schedstate_percpu ci_schedstate; /* scheduler state */ + + struct pmap *ci_proc_pmap; /* active, non-kernel pmap */ + struct pmap *ci_user_pmap; /* [o] last pmap used in userspace */ + struct pcb *ci_curpcb; /* [o] */ + struct pcb *ci_idle_pcb; /* [o] */ + + u_int ci_pflags; /* [o] */ +#define CPUPF_USERSEGS 0x01 /* CPU has curproc's segs and FS.base */ +#define CPUPF_USERXSTATE 0x02 /* CPU has curproc's xsave state */ + + struct intrsource *ci_isources[MAX_INTR_SOURCES]; + u_int64_t ci_ipending; + int ci_ilevel; + int ci_idepth; + int ci_handled_intr_level; + u_int64_t ci_imask[NIPL]; + u_int64_t ci_iunmask[NIPL]; +#ifdef DIAGNOSTIC + int ci_mutex_level; +#endif + + volatile u_int ci_flags; /* [a] */ + u_int32_t ci_ipis; /* [a] */ + + enum cpu_vendor ci_vendor; /* [I] mapped from cpuid(0) */ + u_int32_t ci_cpuid_level; /* [I] cpuid(0).eax */ + u_int32_t ci_feature_flags; /* [I] */ + u_int32_t ci_feature_eflags; /* [I] */ + u_int32_t ci_feature_sefflags_ebx;/* [I] */ + u_int32_t ci_feature_sefflags_ecx;/* [I] */ + u_int32_t ci_feature_sefflags_edx;/* [I] */ + u_int32_t ci_feature_amdspec_ebx; /* [I] */ + u_int32_t ci_feature_amdsev_eax; /* [I] */ + u_int32_t ci_feature_amdsev_ebx; /* [I] */ + u_int32_t ci_feature_amdsev_ecx; /* [I] */ + u_int32_t ci_feature_amdsev_edx; /* [I] */ + u_int32_t ci_feature_tpmflags; /* [I] */ + u_int32_t ci_pnfeatset; /* [I] */ + u_int32_t ci_efeature_eax; /* [I] */ + u_int32_t ci_efeature_ecx; /* [I] */ + u_int32_t ci_brand[12]; /* [I] */ + u_int32_t ci_signature; /* [I] */ + u_int32_t ci_family; /* [I] */ + u_int32_t ci_model; /* [I] */ + u_int32_t ci_cflushsz; /* [I] */ + + int ci_inatomic; /* [o] */ + +#define __HAVE_CPU_TOPOLOGY + u_int32_t ci_smt_id; /* [I] */ + u_int32_t ci_core_id; /* [I] */ + u_int32_t ci_pkg_id; /* [I] */ + + struct cpu_functions *ci_func; /* [I] */ + void (*cpu_setup)(struct cpu_info *); /* [I] */ + + struct device *ci_acpicpudev; /* [I] */ + volatile u_int ci_mwait; /* [a] */ +#define MWAIT_IN_IDLE 0x1 /* don't need IPI to wake */ +#define MWAIT_KEEP_IDLING 0x2 /* cleared by other cpus to wake me */ +#define MWAIT_ONLY 0x4 /* set if all idle states use mwait */ +#define MWAIT_IDLING (MWAIT_IN_IDLE | MWAIT_KEEP_IDLING) + + int ci_want_resched; + + struct x86_64_tss *ci_tss; /* [o] */ + void *ci_gdt; /* [o] */ + + volatile int ci_ddb_paused; +#define CI_DDB_RUNNING 0 +#define CI_DDB_SHOULDSTOP 1 +#define CI_DDB_STOPPED 2 +#define CI_DDB_ENTERDDB 3 +#define CI_DDB_INDDB 4 + +#ifdef MULTIPROCESSOR + struct srp_hazard ci_srp_hazards[SRP_HAZARD_NUM]; +#define __HAVE_UVM_PERCPU + struct uvm_pmr_cache ci_uvm; /* [o] page cache */ +#endif + + struct ksensordev ci_sensordev; + struct ksensor ci_sensor; + struct ksensor ci_hz_sensor; + u_int64_t ci_hz_mperf; + u_int64_t ci_hz_aperf; +#if defined(GPROF) || defined(DDBPROF) + struct gmonparam *ci_gmon; + struct clockintr ci_gmonclock; +#endif + u_int32_t ci_vmm_flags; +#define CI_VMM_VMX (1 << 0) +#define CI_VMM_SVM (1 << 1) +#define CI_VMM_RVI (1 << 2) +#define CI_VMM_EPT (1 << 3) +#define CI_VMM_DIS (1 << 4) + union vmm_cpu_cap ci_vmm_cap; + paddr_t ci_vmxon_region_pa; + struct vmxon_region *ci_vmxon_region; + paddr_t ci_vmcs_pa; + struct rwlock ci_vmcs_lock; + struct pmap *ci_ept_pmap; /* [o] last used EPT pmap */ + struct vcpu *ci_guest_vcpu; /* [o] last vcpu resumed */ + + char ci_panicbuf[512]; + + struct clockqueue ci_queue; +}; + +#define CPUF_BSP 0x0001 /* CPU is the original BSP */ +#define CPUF_AP 0x0002 /* CPU is an AP */ +#define CPUF_SP 0x0004 /* CPU is only processor */ +#define CPUF_PRIMARY 0x0008 /* CPU is active primary processor */ + +#define CPUF_IDENTIFY 0x0010 /* CPU may now identify */ +#define CPUF_IDENTIFIED 0x0020 /* CPU has been identified */ + +#define CPUF_CONST_TSC 0x0040 /* CPU has constant TSC */ +#define CPUF_INVAR_TSC 0x0100 /* CPU has invariant TSC */ + +#define CPUF_PRESENT 0x1000 /* CPU is present */ +#define CPUF_RUNNING 0x2000 /* CPU is running */ +#define CPUF_PAUSE 0x4000 /* CPU is paused in DDB */ +#define CPUF_GO 0x8000 /* CPU should start running */ +#define CPUF_PARK 0x10000 /* CPU should self-park in real mode */ +#define CPUF_VMM 0x20000 /* CPU is executing in VMM mode */ + +#define PROC_PC(p) ((p)->p_md.md_regs->tf_rip) +#define PROC_STACK(p) ((p)->p_md.md_regs->tf_rsp) + +struct cpu_info_full; +extern struct cpu_info_full cpu_info_full_primary; +#define cpu_info_primary (*(struct cpu_info *)((char *)&cpu_info_full_primary + 4096*2 - offsetof(struct cpu_info, ci_PAGEALIGN))) + +extern struct cpu_info *cpu_info_list; + +#define CPU_INFO_ITERATOR int +#define CPU_INFO_FOREACH(cii, ci) for (cii = 0, ci = cpu_info_list; \ + ci != NULL; ci = ci->ci_next) + +#define CPU_INFO_UNIT(ci) ((ci)->ci_dev ? (ci)->ci_dev->dv_unit : 0) + +/* + * Preempt the current process if in interrupt from user mode, + * or after the current trap/syscall if in system mode. + */ +extern void need_resched(struct cpu_info *); +#define clear_resched(ci) (ci)->ci_want_resched = 0 + +#if defined(MULTIPROCESSOR) + +#define MAXCPUS 64 /* bitmask */ + +#define CPU_STARTUP(_ci) ((_ci)->ci_func->start(_ci)) +#define CPU_STOP(_ci) ((_ci)->ci_func->stop(_ci)) +#define CPU_START_CLEANUP(_ci) ((_ci)->ci_func->cleanup(_ci)) + +#define curcpu() ({struct cpu_info *__ci; \ + asm volatile("movq %%gs:%P1,%0" : "=r" (__ci) \ + :"n" (offsetof(struct cpu_info, ci_self))); \ + __ci;}) +#define cpu_number() (curcpu()->ci_cpuid) + +#define CPU_IS_PRIMARY(ci) ((ci)->ci_flags & CPUF_PRIMARY) +#define CPU_IS_RUNNING(ci) ((ci)->ci_flags & CPUF_RUNNING) + +extern struct cpu_info *cpu_info[MAXCPUS]; + +void cpu_boot_secondary_processors(void); + +void cpu_kick(struct cpu_info *); +void cpu_unidle(struct cpu_info *); + +#define CPU_BUSY_CYCLE() __asm volatile("pause": : : "memory") + +#else /* !MULTIPROCESSOR */ + +#define MAXCPUS 1 + +#ifdef _KERNEL +#define curcpu() (&cpu_info_primary) + +#define cpu_kick(ci) +#define cpu_unidle(ci) + +#define CPU_BUSY_CYCLE() __asm volatile ("" ::: "memory") + +#endif + +/* + * definitions of cpu-dependent requirements + * referenced in generic code + */ +#define cpu_number() 0 +#define CPU_IS_PRIMARY(ci) 1 +#define CPU_IS_RUNNING(ci) 1 + +#endif /* MULTIPROCESSOR */ + +#include +#include + +static inline unsigned int +cpu_rnd_messybits(void) +{ + unsigned int hi, lo; + + __asm volatile("rdtsc" : "=d" (hi), "=a" (lo)); + + return (hi ^ lo); +} + +#endif /* _KERNEL */ + +#ifdef MULTIPROCESSOR +#include +#endif + +#define aston(p) ((p)->p_md.md_astpending = 1) + +#define curpcb curcpu()->ci_curpcb + +/* + * Arguments to hardclock, softclock and statclock + * encapsulate the previous machine state in an opaque + * clockframe; for now, use generic intrframe. + */ +#define clockframe intrframe + +#define CLKF_USERMODE(frame) USERMODE((frame)->if_cs, (frame)->if_rflags) +#define CLKF_PC(frame) ((frame)->if_rip) +#define CLKF_INTR(frame) (curcpu()->ci_idepth > 1) + +/* + * Give a profiling tick to the current process when the user profiling + * buffer pages are invalid. On the i386, request an ast to send us + * through usertrap(), marking the proc as needing a profiling tick. + */ +#define need_proftick(p) aston(p) + +void signotify(struct proc *); + +/* + * We need a machine-independent name for this. + */ +extern void (*delay_func)(int); +void delay_fini(void (*)(int)); +void delay_init(void (*)(int), int); +struct timeval; + +#define DELAY(x) (*delay_func)(x) +#define delay(x) (*delay_func)(x) + + +#ifdef _KERNEL +/* cpu.c */ +extern int cpu_feature; +extern int cpu_ebxfeature; +extern int cpu_ecxfeature; +extern int ecpu_ecxfeature; +extern int cpu_sev_guestmode; +extern int cpu_id; +extern char cpu_vendor[]; +extern int cpuid_level; +extern int cpu_meltdown; +extern u_int cpu_mwait_size; +extern u_int cpu_mwait_states; + +int cpu_suspend_primary(void); + +/* cacheinfo.c */ +void x86_print_cacheinfo(struct cpu_info *); + +/* identcpu.c */ +void identifycpu(struct cpu_info *); +int cpu_amd64speed(int *); +extern int cpuspeed; +extern int amd64_pos_cbit; +extern int amd64_min_noes_asid; + +/* machdep.c */ +void dumpconf(void); +void cpu_set_vendor(struct cpu_info *, int _level, const char *_vendor); +void cpu_reset(void); +void x86_64_proc0_tss_ldt_init(void); +int amd64_pa_used(paddr_t); +#define cpu_idle_enter() do { /* nothing */ } while (0) +extern void (*cpu_idle_cycle_fcn)(void); +extern void (*cpu_suspend_cycle_fcn)(void); +#define cpu_idle_cycle() (*cpu_idle_cycle_fcn)() +#define cpu_idle_leave() do { /* nothing */ } while (0) +extern void (*initclock_func)(void); +extern void (*startclock_func)(void); + +struct region_descriptor; +void lgdt(struct region_descriptor *); + +struct pcb; +void savectx(struct pcb *); +void proc_trampoline(void); + +/* clock.c */ +void startclocks(void); +void rtcinit(void); +void rtcstart(void); +void rtcstop(void); +void i8254_delay(int); +void i8254_initclocks(void); +void i8254_startclock(void); +void i8254_start_both_clocks(void); +void i8254_inittimecounter(void); +void i8254_inittimecounter_simple(void); + +/* i8259.c */ +void i8259_default_setup(void); + +void cpu_init_msrs(struct cpu_info *); +void cpu_fix_msrs(struct cpu_info *); +void cpu_tsx_disable(struct cpu_info *); + +/* dkcsum.c */ +void dkcsumattach(void); + +/* bus_machdep.c */ +void x86_bus_space_init(void); +void x86_bus_space_mallocok(void); + +/* powernow-k8.c */ +void k8_powernow_init(struct cpu_info *); +void k8_powernow_setperf(int); + +/* k1x-pstate.c */ +void k1x_init(struct cpu_info *); +void k1x_setperf(int); + +void est_init(struct cpu_info *); +void est_setperf(int); + +#ifdef MULTIPROCESSOR +/* mp_setperf.c */ +void mp_setperf_init(void); +#endif + +#endif /* _KERNEL */ + +/* + * CTL_MACHDEP definitions. + */ +#define CPU_CONSDEV 1 /* dev_t: console terminal device */ +#define CPU_BIOS 2 /* BIOS variables */ +#define CPU_BLK2CHR 3 /* convert blk maj into chr one */ +#define CPU_CHR2BLK 4 /* convert chr maj into blk one */ +#define CPU_ALLOWAPERTURE 5 /* allow mmap of /dev/xf86 */ +#define CPU_CPUVENDOR 6 /* cpuid vendor string */ +#define CPU_CPUID 7 /* cpuid */ +#define CPU_CPUFEATURE 8 /* cpuid features */ +#define CPU_KBDRESET 10 /* keyboard reset under pcvt */ +#define CPU_XCRYPT 12 /* supports VIA xcrypt in userland */ +#define CPU_LIDACTION 14 /* action caused by lid close */ +#define CPU_FORCEUKBD 15 /* Force ukbd(4) as console keyboard */ +#define CPU_TSCFREQ 16 /* TSC frequency */ +#define CPU_INVARIANTTSC 17 /* has invariant TSC */ +#define CPU_PWRACTION 18 /* action caused by power button */ +#define CPU_RETPOLINE 19 /* cpu requires retpoline pattern */ +#define CPU_MAXID 20 /* number of valid machdep ids */ + +#define CTL_MACHDEP_NAMES { \ + { 0, 0 }, \ + { "console_device", CTLTYPE_STRUCT }, \ + { "bios", CTLTYPE_INT }, \ + { "blk2chr", CTLTYPE_STRUCT }, \ + { "chr2blk", CTLTYPE_STRUCT }, \ + { "allowaperture", CTLTYPE_INT }, \ + { "cpuvendor", CTLTYPE_STRING }, \ + { "cpuid", CTLTYPE_INT }, \ + { "cpufeature", CTLTYPE_INT }, \ + { 0, 0 }, \ + { "kbdreset", CTLTYPE_INT }, \ + { 0, 0 }, \ + { "xcrypt", CTLTYPE_INT }, \ + { 0, 0 }, \ + { "lidaction", CTLTYPE_INT }, \ + { "forceukbd", CTLTYPE_INT }, \ + { "tscfreq", CTLTYPE_QUAD }, \ + { "invarianttsc", CTLTYPE_INT }, \ + { "pwraction", CTLTYPE_INT }, \ + { "retpoline", CTLTYPE_INT }, \ +} + +#endif /* !_MACHINE_CPU_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/cpu_full.h b/lib/libc/include/x86_64-openbsd-none/machine/cpu_full.h new file mode 100644 index 0000000000..0d6485cd0e --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/cpu_full.h @@ -0,0 +1,70 @@ +/* $OpenBSD: cpu_full.h,v 1.5 2019/05/17 19:07:47 guenther Exp $ */ +/* + * Copyright (c) 2018 Philip Guenther + * + * 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_CPU_FULL_H_ +#define _MACHINE_CPU_FULL_H_ + +#include /* offsetof, PAGE_SIZE */ +#include +#include + +/* + * The layout of the full per-CPU information, including TSS, GDT, + * trampoline stacks, and cpu_info described in + */ +struct cpu_info_full { + /* page mapped kRO in u-k */ + union { + struct { + struct x86_64_tss uu_tss; + uint64_t uu_gdt[GDT_SIZE / 8]; + } u_tssgdt; + char u_align[PAGE_SIZE]; + } cif_RO; +#define cif_tss cif_RO.u_tssgdt.uu_tss +#define cif_gdt cif_RO.u_tssgdt.uu_gdt + + /* start of page mapped kRW in u-k */ + uint64_t cif_tramp_stack[(PAGE_SIZE / 4 + - offsetof(struct cpu_info, ci_PAGEALIGN)) / sizeof(uint64_t)]; + uint64_t cif_dblflt_stack[(PAGE_SIZE / 4) / sizeof(uint64_t)]; + uint64_t cif_nmi_stack[(2 * PAGE_SIZE / 4) / sizeof(uint64_t)]; + + /* + * Beginning of this hangs over into the kRW page; rest is + * unmapped in u-k + */ + struct cpu_info cif_cpu; +} __aligned(PAGE_SIZE); + +/* tss, align shim, and gdt must fit in a page */ +CTASSERT(_ALIGN(sizeof(struct x86_64_tss)) + + sizeof(struct mem_segment_descriptor) * (NGDT_MEM + 2*NGDT_SYS) + < PAGE_SIZE); + +/* verify expected alignment */ +CTASSERT(offsetof(struct cpu_info_full, cif_cpu.ci_PAGEALIGN) % PAGE_SIZE == 0); + +/* verify total size is multiple of page size */ +CTASSERT(sizeof(struct cpu_info_full) % PAGE_SIZE == 0); + +extern struct cpu_info_full cpu_info_full_primary; + +/* Now make sure the cpu_info_primary macro is correct */ +CTASSERT(&cpu_info_primary - &cpu_info_full_primary.cif_cpu == 0); + +#endif /* _MACHINE_CPU_FULL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/cpufunc.h b/lib/libc/include/x86_64-openbsd-none/machine/cpufunc.h new file mode 100644 index 0000000000..6a8420e179 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/cpufunc.h @@ -0,0 +1,461 @@ +/* $OpenBSD: cpufunc.h,v 1.45 2025/06/27 17:23:49 bluhm Exp $ */ +/* $NetBSD: cpufunc.h,v 1.3 2003/05/08 10:27:43 fvdl Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Charles M. Hannum. + * + * 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_CPUFUNC_H_ +#define _MACHINE_CPUFUNC_H_ + +/* + * Functions to provide access to i386-specific instructions. + */ + +#include + +#include + +#if defined(_KERNEL) && !defined (_STANDALONE) + +static __inline void +invlpg(u_int64_t addr) +{ + __asm volatile("invlpg (%0)" : : "r" (addr) : "memory"); +} + +static __inline void +sidt(void *p) +{ + __asm volatile("sidt (%0)" : : "r" (p) : "memory"); +} + +static __inline void +lidt(void *p) +{ + __asm volatile("lidt (%0)" : : "r" (p) : "memory"); +} + +static __inline void +sgdt(void *p) +{ + __asm volatile("sgdt (%0)" : : "r" (p) : "memory"); +} + +static __inline void +bare_lgdt(struct region_descriptor *p) +{ + __asm volatile("lgdt (%0)" : : "r" (p) : "memory"); +} + +static __inline void +sldt(u_short *sel) +{ + __asm volatile("sldt (%0)" : : "r" (sel) : "memory"); +} + +static __inline void +lldt(u_short sel) +{ + __asm volatile("lldt %0" : : "r" (sel)); +} + +static __inline void +ltr(u_short sel) +{ + __asm volatile("ltr %0" : : "r" (sel)); +} + +static __inline void +lcr8(u_int val) +{ + u_int64_t val64 = val; + __asm volatile("movq %0,%%cr8" : : "r" (val64)); +} + +/* + * Upper 32 bits are reserved anyway, so just keep this 32bits. + */ +static __inline void +lcr0(u_int val) +{ + u_int64_t val64 = val; + __asm volatile("movq %0,%%cr0" : : "r" (val64)); +} + +static __inline u_int +rcr0(void) +{ + u_int64_t val64; + u_int val; + __asm volatile("movq %%cr0,%0" : "=r" (val64)); + val = val64; + return val; +} + +static __inline u_int64_t +rcr2(void) +{ + u_int64_t val; + __asm volatile("movq %%cr2,%0" : "=r" (val)); + return val; +} + +static __inline void +lcr3(u_int64_t val) +{ + __asm volatile("movq %0,%%cr3" : : "r" (val)); +} + +static __inline u_int64_t +rcr3(void) +{ + u_int64_t val; + __asm volatile("movq %%cr3,%0" : "=r" (val)); + return val; +} + +/* + * Same as for cr0. Don't touch upper 32 bits. + */ +static __inline void +lcr4(u_int val) +{ + u_int64_t val64 = val; + + __asm volatile("movq %0,%%cr4" : : "r" (val64)); +} + +static __inline u_int +rcr4(void) +{ + u_int64_t val64; + __asm volatile("movq %%cr4,%0" : "=r" (val64)); + return (u_int) val64; +} + +/* + * DR6 and DR7 debug registers + */ +static inline uint64_t +rdr6(void) +{ + u_int64_t val; + __asm volatile("movq %%dr6,%0" : "=r" (val)); + return val; +} + +static inline uint64_t +rdr7(void) +{ + u_int64_t val; + __asm volatile("movq %%dr7,%0" : "=r" (val)); + return val; +} + +static __inline void +tlbflush(void) +{ + u_int64_t val; + __asm volatile("movq %%cr3,%0" : "=r" (val)); + __asm volatile("movq %0,%%cr3" : : "r" (val)); +} + +static inline void +invpcid(uint64_t type, paddr_t pcid, paddr_t addr) +{ + uint64_t desc[2] = { pcid, addr }; + asm volatile("invpcid %0,%1" : : "m"(desc[0]), "r"(type)); +} +#define INVPCID_ADDR 0 +#define INVPCID_PCID 1 +#define INVPCID_ALL 2 +#define INVPCID_NON_GLOBAL 3 + +#ifdef notyet +void setidt(int idx, /*XXX*/caddr_t func, int typ, int dpl); +#endif + + +/* XXXX ought to be in psl.h with spl() functions */ + +static __inline u_long +read_rflags(void) +{ + u_long ef; + + __asm volatile("pushfq; popq %0" : "=r" (ef)); + return (ef); +} + +static __inline void +write_rflags(u_long ef) +{ + __asm volatile("pushq %0; popfq" : : "r" (ef)); +} + +static __inline void +intr_enable(void) +{ + __asm volatile("sti"); +} + +static __inline u_long +intr_disable(void) +{ + u_long ef; + + ef = read_rflags(); + __asm volatile("cli"); + return (ef); +} + +static __inline void +intr_restore(u_long ef) +{ + write_rflags(ef); +} + +static __inline u_int64_t +rdmsr(u_int msr) +{ + uint32_t hi, lo; + __asm volatile("rdmsr" : "=d" (hi), "=a" (lo) : "c" (msr)); + return (((uint64_t)hi << 32) | (uint64_t) lo); +} + +static __inline int +rdpkru(u_int ecx) +{ + uint32_t edx, pkru; + asm volatile("rdpkru " : "=a" (pkru), "=d" (edx) : "c" (ecx)); + return pkru; +} + +static __inline void +wrpkru(u_int ecx, uint32_t pkru) +{ + uint32_t edx = 0; + asm volatile("wrpkru" : : "a" (pkru), "c" (ecx), "d" (edx)); +} + +static __inline void +wrmsr(u_int msr, u_int64_t newval) +{ + __asm volatile("wrmsr" : + : "a" (newval & 0xffffffff), "d" (newval >> 32), "c" (msr)); +} + +/* + * Some of the undocumented AMD64 MSRs need a 'passcode' to access. + * + * See LinuxBIOSv2: src/cpu/amd/model_fxx/model_fxx_init.c + */ + +#define OPTERON_MSR_PASSCODE 0x9c5a203a + +static __inline u_int64_t +rdmsr_locked(u_int msr, u_int code) +{ + uint32_t hi, lo; + __asm volatile("rdmsr" + : "=d" (hi), "=a" (lo) + : "c" (msr), "D" (code)); + return (((uint64_t)hi << 32) | (uint64_t) lo); +} + +static __inline void +wrmsr_locked(u_int msr, u_int code, u_int64_t newval) +{ + __asm volatile("wrmsr" : + : "a" (newval & 0xffffffff), "d" (newval >> 32), "c" (msr), "D" (code)); +} + +static __inline void +wbinvd(void) +{ + __asm volatile("wbinvd" : : : "memory"); +} + +#ifdef MULTIPROCESSOR +int wbinvd_on_all_cpus(void); +void wbinvd_on_all_cpus_acked(void); +#else +static inline int +wbinvd_on_all_cpus(void) +{ + wbinvd(); + return 0; +} + +static inline int +wbinvd_on_all_cpus_acked(void) +{ + wbinvd(); + return 0; +} +#endif /* MULTIPROCESSOR */ + +static __inline void +clflush(u_int64_t addr) +{ + __asm volatile("clflush %0" : "+m" (*(volatile char *)addr)); +} + +static __inline void +mfence(void) +{ + __asm volatile("mfence" : : : "memory"); +} + +static __inline u_int64_t +rdtsc(void) +{ + uint32_t hi, lo; + + __asm volatile("rdtsc" : "=d" (hi), "=a" (lo)); + return (((uint64_t)hi << 32) | (uint64_t) lo); +} + +static __inline u_int64_t +rdtscp(void) +{ + uint32_t hi, lo; + + __asm volatile("rdtscp" : "=d" (hi), "=a" (lo) : : "ecx"); + return (((uint64_t)hi << 32) | (uint64_t) lo); +} + +static __inline u_int64_t +rdtsc_lfence(void) +{ + uint32_t hi, lo; + + __asm volatile("lfence; rdtsc" : "=d" (hi), "=a" (lo)); + return (((uint64_t)hi << 32) | (uint64_t) lo); +} + +static __inline u_int64_t +rdpmc(u_int pmc) +{ + uint32_t hi, lo; + + __asm volatile("rdpmc" : "=d" (hi), "=a" (lo) : "c" (pmc)); + return (((uint64_t)hi << 32) | (uint64_t) lo); +} + +static __inline void +monitor(const volatile void *addr, u_long extensions, u_int hints) +{ + + __asm volatile("monitor" + : : "a" (addr), "c" (extensions), "d" (hints)); +} + +static __inline void +mwait(u_long extensions, u_int hints) +{ + + __asm volatile( + " mwait ;" + " mov $8,%%rcx ;" + " .align 16,0x90 ;" + "3: call 5f ;" + "4: pause ;" + " lfence ;" + " call 4b ;" + " .align 16,0xcc ;" + "5: call 7f ;" + "6: pause ;" + " lfence ;" + " call 6b ;" + " .align 16,0xcc ;" + "7: loop 3b ;" + " add $(16*8),%%rsp" + : "+c" (extensions) : "a" (hints)); +} + +static __inline void +xsetbv(uint32_t reg, uint64_t mask) +{ + uint32_t lo, hi; + + lo = mask; + hi = mask >> 32; + __asm volatile("xsetbv" :: "c" (reg), "a" (lo), "d" (hi) : "memory"); +} + +static __inline uint64_t +xgetbv(uint32_t reg) +{ + uint32_t lo, hi; + + __asm volatile("xgetbv" : "=a" (lo), "=d" (hi) : "c" (reg)); + + return (((uint64_t)hi << 32) | (uint64_t)lo); +} + +static __inline void +stgi(void) +{ + __asm volatile("stgi"); +} + +static __inline void +clgi(void) +{ + __asm volatile("clgi"); +} + +/* Break into DDB. */ +static __inline void +breakpoint(void) +{ + __asm volatile("int $3"); +} + +/* VMGEXIT */ +static __inline void +vmgexit(void) +{ + /* rep; vmmcall encodes the vmgexit instruction */ + __asm volatile("rep; vmmcall"); +} + +void amd64_errata(struct cpu_info *); +void cpu_ucode_setup(void); +void cpu_ucode_apply(struct cpu_info *); + +struct cpu_info_full; +void cpu_enter_pages(struct cpu_info_full *); + +int rdmsr_safe(u_int msr, uint64_t *); + +#endif /* _KERNEL */ + +#endif /* !_MACHINE_CPUFUNC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/cpuvar.h b/lib/libc/include/x86_64-openbsd-none/machine/cpuvar.h new file mode 100644 index 0000000000..c82e3adf88 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/cpuvar.h @@ -0,0 +1,100 @@ +/* $OpenBSD: cpuvar.h,v 1.14 2024/10/22 10:14:49 jsg Exp $ */ +/* $NetBSD: cpuvar.h,v 1.1 2003/03/01 18:29:28 fvdl Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by RedBack Networks Inc. + * + * Author: Bill Sommerfeld + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 1999 Stefan Grefen + * + * 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 NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 AUTHOR 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 AUTHOR AND 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. + */ + +struct cpu_functions { + int (*start)(struct cpu_info *); + int (*stop)(struct cpu_info *); + void (*cleanup)(struct cpu_info *); +}; + +extern struct cpu_functions mp_cpu_funcs; + +#define CPU_ROLE_SP 0 +#define CPU_ROLE_BP 1 +#define CPU_ROLE_AP 2 + +struct cpu_attach_args { + const char *caa_name; + int cpu_apicid; + int cpu_acpi_proc_id; + int cpu_role; + struct cpu_functions *cpu_func; +}; + +#ifdef _KERNEL + +#ifdef MULTIPROCESSOR +extern void (*x86_ipi)(int,int,int); +void x86_ipi_init(int); +#endif + +void identifycpu(struct cpu_info *); +void cpu_init(struct cpu_info *); + +void tsc_test_sync_bp(struct cpu_info *); +void tsc_test_sync_ap(struct cpu_info *); + +#endif \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/db_machdep.h b/lib/libc/include/x86_64-openbsd-none/machine/db_machdep.h new file mode 100644 index 0000000000..4a66d5a761 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/db_machdep.h @@ -0,0 +1,101 @@ +/* $OpenBSD: db_machdep.h,v 1.19 2021/08/30 08:11:12 jasper Exp $ */ +/* $NetBSD: db_machdep.h,v 1.2 2003/04/29 17:06:04 scw Exp $ */ + +/* + * Mach Operating System + * Copyright (c) 1991,1990 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + +#ifndef _MACHINE_DB_MACHDEP_H_ +#define _MACHINE_DB_MACHDEP_H_ + +/* + * Machine-dependent defines for new kernel debugger. + */ + +#include +#include +#include +#include + +typedef long db_expr_t; /* expression - signed */ + +typedef struct trapframe db_regs_t; + +extern db_regs_t ddb_regs; /* register state */ + +#define PC_REGS(regs) ((vaddr_t)(regs)->tf_rip) +#define SET_PC_REGS(regs, value) (regs)->tf_rip = (int64_t)(value) + +#define BKPT_ADDR(addr) (addr) /* breakpoint address */ +#define BKPT_INST 0xcc /* breakpoint instruction */ +#define BKPT_SIZE (1) /* size of breakpoint inst */ +#define BKPT_SET(inst) (BKPT_INST) + +#define SSF_INST 0x55 +#define SSF_SIZE (1) + +#define FIXUP_PC_AFTER_BREAK(regs) ((regs)->tf_rip -= BKPT_SIZE) + +#define db_clear_single_step(regs) ((regs)->tf_rflags &= ~PSL_T) +#define db_set_single_step(regs) ((regs)->tf_rflags |= PSL_T) + +#define IS_BREAKPOINT_TRAP(type, code) ((type) == T_BPTFLT) +#define IS_WATCHPOINT_TRAP(type, code) ((type) == T_TRCTRAP && (code) & 15) + +#define I_CALL 0xe8 +#define I_CALLI 0xff +#define I_RET 0xc3 +#define I_IRET 0xcf + +#define inst_trap_return(ins) (((ins)&0xff) == I_IRET) +#define inst_return(ins) (((ins)&0xff) == I_RET) +#define inst_call(ins) (((ins)&0xff) == I_CALL || \ + (((ins)&0xff) == I_CALLI && \ + ((ins)&0x3800) == 0x1000)) + +/* macro for checking if a thread has used floating-point */ + +int db_ktrap(int, int, db_regs_t *); + +void db_machine_init(void); +int db_enter_ddb(void); +void db_startcpu(int); +void db_stopcpu(int); +void x86_ipi_db(struct cpu_info *); + +#define DDB_STATE_NOT_RUNNING 0 +#define DDB_STATE_RUNNING 1 +#define DDB_STATE_EXITING 2 + +/* + * We define some of our own commands + */ +#define DB_MACHINE_COMMANDS + +extern void db_machine_init(void); + +extern void cpu_debug_dump(void); + +#endif /* _MACHINE_DB_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/disklabel.h b/lib/libc/include/x86_64-openbsd-none/machine/disklabel.h new file mode 100644 index 0000000000..44d225a0a8 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/disklabel.h @@ -0,0 +1,40 @@ +/* $OpenBSD: disklabel.h,v 1.11 2015/09/30 14:57:03 krw Exp $ */ + +/* + * Copyright (c) 1994 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 _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_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/efifbvar.h b/lib/libc/include/x86_64-openbsd-none/machine/efifbvar.h new file mode 100644 index 0000000000..1958da38bc --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/efifbvar.h @@ -0,0 +1,40 @@ +/* $OpenBSD: efifbvar.h,v 1.10 2019/05/04 11:34:47 kettenis Exp $ */ + +/* + * Copyright (c) 2015 YASUOKA Masahiko + * + * 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_EFIFB_H_ +#define _MACHINE_EFIFB_H_ + +struct efifb_attach_args { + const char *eaa_name; +}; + +struct pci_attach_args; + +int efifb_cnattach(void); +void efifb_cnremap(void); +int efifb_is_console(struct pci_attach_args *); +int efifb_is_primary(struct pci_attach_args *); +void efifb_detach(void); +void efifb_reattach(void); + +int efifb_cb_found(void); +int efifb_cb_cnattach(void); + +psize_t efifb_stolen(void); + +#endif /* _MACHINE_EFIFB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/efivar.h b/lib/libc/include/x86_64-openbsd-none/machine/efivar.h new file mode 100644 index 0000000000..72645470e8 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/efivar.h @@ -0,0 +1,42 @@ +/* $OpenBSD: efivar.h,v 1.1 2023/01/14 12:11:10 kettenis Exp $ */ +/* + * Copyright (c) 2022 Mark Kettenis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _MACHINE_EFIVAR_H_ +#define _MACHINE_EFIVAR_H_ + +#include + +struct efi_softc { + struct device sc_dev; + struct pmap *sc_pm; + EFI_RUNTIME_SERVICES *sc_rs; + EFI_SYSTEM_RESOURCE_TABLE *sc_esrt; + u_long sc_psw; + uint64_t sc_cr3; + + struct todr_chip_handle sc_todr; +}; + +void efi_enter(struct efi_softc *); +void efi_leave(struct efi_softc *); + +extern label_t efi_jmpbuf; + +#define efi_enter_check(sc) (setjmp(&efi_jmpbuf) ? \ + (efi_leave(sc), EFAULT) : (efi_enter(sc), 0)) + +#endif /* _MACHINE_EFIVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/endian.h b/lib/libc/include/x86_64-openbsd-none/machine/endian.h new file mode 100644 index 0000000000..7ff7b356d9 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/endian.h @@ -0,0 +1,36 @@ +/* $OpenBSD: endian.h,v 1.8 2024/05/07 14:26:48 naddy 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_ + +#define _BYTE_ORDER _LITTLE_ENDIAN + +#ifndef __FROM_SYS__ENDIAN +#include +#endif + +#endif /* _MACHINE_ENDIAN_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/exec.h b/lib/libc/include/x86_64-openbsd-none/machine/exec.h new file mode 100644 index 0000000000..8fafeb9b4c --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/exec.h @@ -0,0 +1,17 @@ +/* $OpenBSD: exec.h,v 1.7 2017/02/08 05:09:25 guenther Exp $ */ +/* + * Written by Artur Grabowski Public Domain + */ + +#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_AMD64 + +#endif \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/fenv.h b/lib/libc/include/x86_64-openbsd-none/machine/fenv.h new file mode 100644 index 0000000000..0b16f62459 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/fenv.h @@ -0,0 +1,115 @@ +/* $OpenBSD: fenv.h,v 1.4 2011/05/25 21:46:49 martynas Exp $ */ +/* $NetBSD: fenv.h,v 1.1 2010/07/31 21:47:54 joerg Exp $ */ + +/*- + * Copyright (c) 2004-2005 David Schultz + * 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 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 AUTHOR 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 _AMD64_FENV_H_ +#define _AMD64_FENV_H_ + +/* + * Each symbol representing a floating point exception expands to an integer + * constant expression with values, such that bitwise-inclusive ORs of _all + * combinations_ of the constants result in distinct values. + * + * We use such values that allow direct bitwise operations on FPU/SSE registers. + */ +#define FE_INVALID 0x01 +#define FE_DENORMAL 0x02 +#define FE_DIVBYZERO 0x04 +#define FE_OVERFLOW 0x08 +#define FE_UNDERFLOW 0x10 +#define FE_INEXACT 0x20 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * exception constants defined above. + */ +#define FE_ALL_EXCEPT (FE_INVALID | FE_DENORMAL | FE_DIVBYZERO | \ + FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT) +#define _SSE_MASK_SHIFT 7 + +/* + * Each symbol representing the rounding direction, expands to an integer + * constant expression whose value is distinct non-negative value. + * + * We use such values that allow direct bitwise operations on FPU/SSE registers. + */ +#define FE_TONEAREST 0x000 +#define FE_DOWNWARD 0x400 +#define FE_UPWARD 0x800 +#define FE_TOWARDZERO 0xc00 + +/* + * The following symbol is simply the bitwise-inclusive OR of all floating-point + * rounding direction constants defined above. + */ +#define _X87_ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | \ + FE_TOWARDZERO) +#define _SSE_ROUND_SHIFT 3 + +/* + * fenv_t represents the entire floating-point environment. + */ +typedef struct { + struct { + unsigned int __control; /* Control word register */ + unsigned int __status; /* Status word register */ + unsigned int __tag; /* Tag word register */ + unsigned int __others[4]; /* EIP, Pointer Selector, etc */ + } __x87; + unsigned int __mxcsr; /* Control, status register */ +} fenv_t; + +/* + * The following constant represents the default floating-point environment + * (that is, the one installed at program startup) and has type pointer to + * const-qualified fenv_t. + * + * It can be used as an argument to the functions within the header + * that manage the floating-point environment, namely fesetenv() and + * feupdateenv(). + */ +__BEGIN_DECLS +extern fenv_t __fe_dfl_env; +__END_DECLS +#define FE_DFL_ENV ((const fenv_t *)&__fe_dfl_env) + +/* + * fexcept_t represents the floating-point status flags collectively, including + * any status the implementation associates with the flags. + * + * A floating-point status flag is a system variable whose value is set (but + * never cleared) when a floating-point exception is raised, which occurs as a + * side effect of exceptional floating-point arithmetic to provide auxiliary + * information. + * + * A floating-point control mode is a system variable whose value may be set by + * the user to affect the subsequent behavior of floating-point arithmetic. + */ +typedef unsigned int fexcept_t; + +#endif /* !_AMD64_FENV_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/fpu.h b/lib/libc/include/x86_64-openbsd-none/machine/fpu.h new file mode 100644 index 0000000000..b79b7a27c4 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/fpu.h @@ -0,0 +1,111 @@ +/* $OpenBSD: fpu.h,v 1.20 2024/04/14 09:59:04 kettenis Exp $ */ +/* $NetBSD: fpu.h,v 1.1 2003/04/26 18:39:40 fvdl Exp $ */ + +#ifndef _MACHINE_FPU_H_ +#define _MACHINE_FPU_H_ + +#include + +/* + * If the CPU supports xsave/xrstor then we use them so that we can provide + * AVX support. Otherwise we require fxsave/fxrstor, as the SSE registers + * are part of the ABI for passing floating point values. + * While fxsave/fxrstor only required 16-byte alignment for the save area, + * xsave/xrstor requires the save area to have 64-byte alignment. + */ + +struct fxsave64 { + u_int16_t fx_fcw; + u_int16_t fx_fsw; + u_int8_t fx_ftw; + u_int8_t fx_unused1; + u_int16_t fx_fop; + u_int64_t fx_rip; + u_int64_t fx_rdp; + u_int32_t fx_mxcsr; + u_int32_t fx_mxcsr_mask; + u_int64_t fx_st[8][2]; /* 8 normal FP regs */ + u_int64_t fx_xmm[16][2]; /* 16 SSE2 registers */ + u_int8_t fx_unused3[96]; +} __packed; + +struct xstate_hdr { + uint64_t xstate_bv; + uint64_t xstate_xcomp_bv; + uint8_t xstate_rsrv0[8]; + uint8_t xstate_rsrv[40]; +} __packed; + +struct savefpu { + struct fxsave64 fp_fxsave; /* see above */ + struct xstate_hdr fp_xstate; + u_int64_t fp_ymm[16][2]; + u_int8_t fp_components[1856]; /* enough for AVX-512 */ +}; + +/* + * The i387 defaults to Intel extended precision mode and round to nearest, + * with all exceptions masked. + */ +#define __INITIAL_NPXCW__ 0x037f +#define __INITIAL_MXCSR__ 0x1f80 +#define __INITIAL_MXCSR_MASK__ 0xffbf + +#ifdef _KERNEL +/* + * XXX + */ +struct trapframe; +struct cpu_info; + +extern size_t fpu_save_len; +extern uint32_t fpu_mxcsr_mask; +extern uint64_t xsave_mask; +extern int cpu_use_xsaves; + +void fpuinit(struct cpu_info *); +int fputrap(int _type); +void fpusave(struct savefpu *); +void fpusavereset(struct savefpu *); +void fpu_kernel_enter(void); +void fpu_kernel_exit(void); + +/* pointer to fxsave/xsave/xsaves data with everything reset */ +#define fpu_cleandata (&proc0.p_addr->u_pcb.pcb_savefpu) + +int xrstor_user(struct savefpu *_addr, uint64_t _mask); +void xrstor_kern(struct savefpu *_addr, uint64_t _mask); +#define fpureset() \ + xrstor_kern(fpu_cleandata, xsave_mask) +int xsetbv_user(uint32_t _reg, uint64_t _mask); + +#define fninit() __asm("fninit") +#define fwait() __asm("fwait") +/* should be fxsave64, but where we use this it doesn't matter */ +#define fxsave(addr) __asm("fxsave %0" : "=m" (*addr)) +#define ldmxcsr(addr) __asm("ldmxcsr %0" : : "m" (*addr)) +#define fldcw(addr) __asm("fldcw %0" : : "m" (*addr)) + +static inline void +xsave(struct savefpu *addr, uint64_t mask) +{ + uint32_t lo, hi; + + lo = mask; + hi = mask >> 32; + __asm volatile("xsave64 %0" : "+m" (*addr) : "a" (lo), "d" (hi)); +} + +static inline void +xrstors(const struct savefpu *addr, uint64_t mask) +{ + uint32_t lo, hi; + + lo = mask; + hi = mask >> 32; + __asm volatile("xrstors64 %0" : : "m" (*addr), "a" (lo), "d" (hi)); +} + +#endif + +#endif /* _MACHINE_FPU_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/frame.h b/lib/libc/include/x86_64-openbsd-none/machine/frame.h new file mode 100644 index 0000000000..bd9658dec4 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/frame.h @@ -0,0 +1,174 @@ +/* $OpenBSD: frame.h,v 1.11 2024/01/31 06:06:28 guenther Exp $ */ +/* $NetBSD: frame.h,v 1.1 2003/04/26 18:39:40 fvdl Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Charles M. Hannum. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*- + * Copyright (c) 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. + * + * @(#)frame.h 5.2 (Berkeley) 1/18/91 + */ + +/* + * Adapted for NetBSD/amd64 by fvdl@wasabisystems.com + */ + +#ifndef _MACHINE_FRAME_H_ +#define _MACHINE_FRAME_H_ + +#include +#include + +/* + * System stack frames. + */ + +/* + * Exception/Trap Stack Frame + */ +struct trapframe { + int64_t tf_rdi; /* ordered by syscall args... */ + int64_t tf_rsi; + int64_t tf_rdx; + int64_t tf_r10; + int64_t tf_r8; + int64_t tf_r9; /* ...to here */ + int64_t tf_rcx; + int64_t tf_r11; + int64_t tf_r12; + int64_t tf_r13; + int64_t tf_r14; + int64_t tf_r15; + int64_t tf_err; /* not the hardware position */ + int64_t tf_rbx; + int64_t tf_rax; + int64_t tf_trapno; + int64_t tf_rbp; /* hardware puts err here, INTRENTRY() moves it up */ + /* below portion defined in hardware */ + int64_t tf_rip; + int64_t tf_cs; + int64_t tf_rflags; + /* These are pushed unconditionally on the x86-64 */ + int64_t tf_rsp; + int64_t tf_ss; +}; + +/* + * Interrupt stack frame + */ +struct intrframe { + int64_t if_rdi; + int64_t if_rsi; + int64_t if_rdx; + int64_t if_r10; + int64_t if_r8; + int64_t if_r9; + int64_t if_rcx; + int64_t if_r11; + int64_t if_r12; + int64_t if_r13; + int64_t if_r14; + int64_t if_r15; + int64_t if_err; /* IREENT_MAGIC if resume/recurse */ + int64_t if_rbx; + int64_t if_rax; + int64_t if_ppl; /* previous priority level */ + int64_t if_rbp; + /* below portion defined in hardware */ + int64_t if_rip; + int64_t if_cs; + int64_t if_rflags; + /* These are pushed unconditionally on the x86-64 */ + int64_t if_rsp; + int64_t if_ss; +}; + + +/* + * The trampoline frame used on the kernel stack page which is present + * but kernel-only, in the page tables used when in userspace. This is + * the minimum for iretq operation. + */ +struct iretq_frame { + int64_t iretq_rip; + int64_t iretq_cs; + int64_t iretq_rflags; + int64_t iretq_rsp; + int64_t iretq_ss; +}; + +/* + * Stack frame inside cpu_switch() + */ +struct switchframe { + int64_t sf_r15; + int64_t sf_r14; + int64_t sf_r13; + int64_t sf_r12; + int64_t sf_rbp; + int64_t sf_rbx; + int64_t sf_rip; +}; + +struct callframe { + struct callframe *f_frame; + long f_retaddr; + long f_arg0; +}; + +#endif /* _MACHINE_FRAME_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/frameasm.h b/lib/libc/include/x86_64-openbsd-none/machine/frameasm.h new file mode 100644 index 0000000000..0ef22deefb --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/frameasm.h @@ -0,0 +1,199 @@ +/* $OpenBSD: frameasm.h,v 1.27 2023/07/27 00:30:07 guenther Exp $ */ +/* $NetBSD: frameasm.h,v 1.1 2003/04/26 18:39:40 fvdl Exp $ */ + +#ifndef _AMD64_MACHINE_FRAMEASM_H +#define _AMD64_MACHINE_FRAMEASM_H + +/* + * Macros to define pushing/popping frames for interrupts, traps + * and system calls. Currently all the same; will diverge later. + */ + +/* + * These are used on interrupt or trap entry or exit. + */ +#define INTR_SAVE_GPRS \ + subq $120,%rsp ; \ + INTR_SAVE_MOST_GPRS_NO_ADJ ; \ + movq %rcx,TF_RCX(%rsp) +#define INTR_SAVE_MOST_GPRS_NO_ADJ \ + movq %r15,TF_R15(%rsp) ; \ + movq %r14,TF_R14(%rsp) ; \ + movq %r13,TF_R13(%rsp) ; \ + movq %r12,TF_R12(%rsp) ; \ + movq %r11,TF_R11(%rsp) ; \ + movq %r10,TF_R10(%rsp) ; \ + movq %r9,TF_R9(%rsp) ; \ + movq %r8,TF_R8(%rsp) ; \ + movq %rdi,TF_RDI(%rsp) ; \ + movq %rsi,TF_RSI(%rsp) ; \ + movq %rbp,TF_RBP(%rsp) ; \ + leaq TF_RBP(%rsp),%rbp ; \ + movq %rbx,TF_RBX(%rsp) ; \ + movq %rdx,TF_RDX(%rsp) ; \ + movq %rax,TF_RAX(%rsp) + +/* + * We clear registers when coming from userspace to prevent + * user-controlled values from being available for use in speculative + * execution in the kernel. %rsp and %rbp are the kernel values when + * this is used, so there are only 14 to clear. 32bit operations clear + * the register upper-halves automatically. + */ +#define INTR_CLEAR_GPRS \ + xorl %eax,%eax ; \ + xorl %ebx,%ebx ; \ + xorl %ecx,%ecx ; \ + xorl %edx,%edx ; \ + xorl %esi,%esi ; \ + xorl %edi,%edi ; \ + xorl %r8d,%r8d ; \ + xorl %r9d,%r9d ; \ + xorl %r10d,%r10d ; \ + xorl %r11d,%r11d ; \ + xorl %r12d,%r12d ; \ + xorl %r13d,%r13d ; \ + xorl %r14d,%r14d ; \ + xorl %r15d,%r15d + + +/* + * For real interrupt code paths, where we can come from userspace. + * We only have an iretq_frame on entry. + */ +#define INTRENTRY_LABEL(label) X##label##_untramp +#define INTRENTRY(label) \ + endbr64 ; \ + testb $SEL_RPL,IRETQ_CS(%rsp) ; \ + je INTRENTRY_LABEL(label) ; \ + swapgs ; \ + FENCE_SWAPGS_MIS_TAKEN ; \ + movq %rax,CPUVAR(SCRATCH) ; \ + CODEPATCH_START ; \ + movq CPUVAR(KERN_CR3),%rax ; \ + movq %rax,%cr3 ; \ + CODEPATCH_END(CPTAG_MELTDOWN_NOP);\ + jmp 98f ; \ +END(X##label) ; \ +_ENTRY(INTRENTRY_LABEL(label)) /* from kernel */ \ + FENCE_NO_SAFE_SMAP ; \ + subq $TF_RIP,%rsp ; \ + movq %rcx,TF_RCX(%rsp) ; \ + jmp 99f ; \ + _ALIGN_TRAPS ; \ +98: /* from userspace */ \ + movq CPUVAR(KERN_RSP),%rax ; \ + xchgq %rax,%rsp ; \ + movq %rcx,TF_RCX(%rsp) ; \ + RET_STACK_REFILL_WITH_RCX ; \ + /* copy iretq frame to the trap frame */ \ + movq IRETQ_RIP(%rax),%rcx ; \ + movq %rcx,TF_RIP(%rsp) ; \ + movq IRETQ_CS(%rax),%rcx ; \ + movq %rcx,TF_CS(%rsp) ; \ + movq IRETQ_RFLAGS(%rax),%rcx ; \ + movq %rcx,TF_RFLAGS(%rsp) ; \ + movq IRETQ_RSP(%rax),%rcx ; \ + movq %rcx,TF_RSP(%rsp) ; \ + movq IRETQ_SS(%rax),%rcx ; \ + movq %rcx,TF_SS(%rsp) ; \ + movq CPUVAR(SCRATCH),%rax ; \ +99: INTR_SAVE_MOST_GPRS_NO_ADJ ; \ + INTR_CLEAR_GPRS ; \ + movq %rax,TF_ERR(%rsp) + +#define INTRFASTEXIT \ + jmp intr_fast_exit + +/* + * Entry for faking up an interrupt frame after spllower() unblocks + * a previously received interrupt. On entry, %r13 has the %rip + * to return to. %r10 and %r11 are scratch. + */ +#define INTR_RECURSE \ + endbr64 ; \ + /* fake the iretq_frame */ ; \ + movq %rsp,%r10 ; \ + movl %ss,%r11d ; \ + pushq %r11 ; \ + pushq %r10 ; \ + pushfq ; \ + movl %cs,%r11d ; \ + pushq %r11 ; \ + pushq %r13 ; \ + /* now do the rest of the intrframe */ \ + subq $16,%rsp ; \ + INTR_SAVE_GPRS + + +/* + * Entry for traps from kernel, where there's a trapno + err already + * on the stack. We have to move the err from its hardware location + * to the location we want it. + */ +#define TRAP_ENTRY_KERN \ + subq $120,%rsp ; \ + movq %rcx,TF_RCX(%rsp) ; \ + movq (TF_RIP - 8)(%rsp),%rcx ; \ + movq %rcx,TF_ERR(%rsp) ; \ + INTR_SAVE_MOST_GPRS_NO_ADJ + +/* + * Entry for traps from userland, where there's a trapno + err on + * the iretq stack. + * Assumes that %rax has been saved in CPUVAR(SCRATCH). + */ +#define TRAP_ENTRY_USER \ + movq CPUVAR(KERN_RSP),%rax ; \ + xchgq %rax,%rsp ; \ + movq %rcx,TF_RCX(%rsp) ; \ + RET_STACK_REFILL_WITH_RCX ; \ + /* copy trapno+err to the trap frame */ \ + movq 0(%rax),%rcx ; \ + movq %rcx,TF_TRAPNO(%rsp) ; \ + movq 8(%rax),%rcx ; \ + movq %rcx,TF_ERR(%rsp) ; \ + /* copy iretq frame to the trap frame */ \ + movq (IRETQ_RIP+16)(%rax),%rcx ; \ + movq %rcx,TF_RIP(%rsp) ; \ + movq (IRETQ_CS+16)(%rax),%rcx ; \ + movq %rcx,TF_CS(%rsp) ; \ + movq (IRETQ_RFLAGS+16)(%rax),%rcx ; \ + movq %rcx,TF_RFLAGS(%rsp) ; \ + movq (IRETQ_RSP+16)(%rax),%rcx ; \ + movq %rcx,TF_RSP(%rsp) ; \ + movq (IRETQ_SS+16)(%rax),%rcx ; \ + movq %rcx,TF_SS(%rsp) ; \ + movq CPUVAR(SCRATCH),%rax ; \ + INTR_SAVE_MOST_GPRS_NO_ADJ ; \ + INTR_CLEAR_GPRS + +/* + * Entry from syscall instruction, where RIP is in %rcx and RFLAGS is in %r11. + * We stash the syscall # in tf_err for SPL check. + * Assumes that %rax has been saved in CPUVAR(SCRATCH). + */ +#define SYSCALL_ENTRY \ + movq CPUVAR(KERN_RSP),%rax ; \ + xchgq %rax,%rsp ; \ + movq %rcx,TF_RCX(%rsp) ; \ + movq %rcx,TF_RIP(%rsp) ; \ + RET_STACK_REFILL_WITH_RCX ; \ + movq $(GSEL(GUDATA_SEL, SEL_UPL)),TF_SS(%rsp) ; \ + movq %rax,TF_RSP(%rsp) ; \ + movq CPUVAR(SCRATCH),%rax ; \ + INTR_SAVE_MOST_GPRS_NO_ADJ ; \ + movq %r11, TF_RFLAGS(%rsp) ; \ + movq $(GSEL(GUCODE_SEL, SEL_UPL)), TF_CS(%rsp) ; \ + movq %rax,TF_ERR(%rsp) ; \ + INTR_CLEAR_GPRS + +#define CHECK_ASTPENDING(reg) movq CPUVAR(CURPROC),reg ; \ + cmpq $0, reg ; \ + je 99f ; \ + cmpl $0, P_MD_ASTPENDING(reg) ; \ + 99: + +#define CLEAR_ASTPENDING(reg) movl $0, P_MD_ASTPENDING(reg) + +#endif /* _AMD64_MACHINE_FRAMEASM_H */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/gdt.h b/lib/libc/include/x86_64-openbsd-none/machine/gdt.h new file mode 100644 index 0000000000..0e9ba4aa90 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/gdt.h @@ -0,0 +1,33 @@ +/* $OpenBSD: gdt.h,v 1.6 2018/02/21 19:24:15 guenther Exp $ */ +/* $NetBSD: gdt.h,v 1.1 2003/04/26 18:39:40 fvdl Exp $ */ + +/*- + * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by John T. Kohl and Charles M. Hannum. + * + * 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. + */ + +void gdt_init_cpu(struct cpu_info *); \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/ghcb.h b/lib/libc/include/x86_64-openbsd-none/machine/ghcb.h new file mode 100644 index 0000000000..73f9484212 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/ghcb.h @@ -0,0 +1,251 @@ +/* $OpenBSD: ghcb.h,v 1.6 2025/09/17 18:37:44 sf Exp $ */ + +/* + * Copyright (c) 2024, 2025 Hans-Joerg Hoexer + * + * 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_GHCB_H_ +#define _MACHINE_GHCB_H_ + +#ifndef _LOCORE + +#include + +#include + +#define GHCB_OFFSET(m) ((m) / 8) +#define GHCB_IDX(m) (GHCB_OFFSET((m)) / 8) +#define GHCB_BIT(m) (GHCB_OFFSET((m)) % 8) + +#define GHCB_XSS 0x140 +#define GHCB_RAX 0x1F8 +#define GHCB_RBX 0x318 +#define GHCB_RCX 0x308 +#define GHCB_RDX 0x310 +#define GHCB_SW_EXITCODE 0x390 +#define GHCB_SW_EXITINFO1 0x398 +#define GHCB_SW_EXITINFO2 0x3A0 +#define GHCB_SW_SCRATCH 0x3A8 +#define GHCB_XCR0 0x3E8 + +#define GHCB_MAX 0xFFF + +struct ghcb_sa { + uint8_t v_pad0[0xcb]; /* 000h-0CAh */ + uint8_t v_cpl; /* 0CBh */ + uint8_t v_pad1[0x74]; /* 0CCh-13Fh */ + uint64_t v_xss; /* 140h */ + uint8_t v_pad2[0x18]; /* 148h-15Fh */ + uint64_t v_dr7; /* 160h */ + uint8_t v_pad3[0x10]; /* 168h-177h */ + uint64_t v_rip; /* 178h */ + uint8_t v_pad4[0x58]; /* 180h-1D7h */ + uint64_t v_rsp; /* 1D8h */ + uint8_t v_pad5[0x18]; /* 1E0h-1F7h */ + uint64_t v_rax; /* 1F8h */ + uint8_t v_pad6[0x108]; /* 200h-307h */ + uint64_t v_rcx; /* 308h */ + uint64_t v_rdx; /* 310h */ + uint64_t v_rbx; /* 318h */ + uint8_t v_pad7[0x8]; /* 320h-327h */ + uint64_t v_rbp; /* 328h */ + uint64_t v_rsi; /* 330h */ + uint64_t v_rdi; /* 338h */ + uint64_t v_r8; /* 340h */ + uint64_t v_r9; /* 348h */ + uint64_t v_r10; /* 350h */ + uint64_t v_r11; /* 358h */ + uint64_t v_r12; /* 360h */ + uint64_t v_r13; /* 368h */ + uint64_t v_r14; /* 370h */ + uint64_t v_r15; /* 378h */ + uint8_t v_pad8[0x10]; /* 380h-38Fh */ + uint64_t v_sw_exitcode; /* 390h */ + uint64_t v_sw_exitinfo1; /* 398h */ + uint64_t v_sw_exitinfo2; /* 3a0h */ + uint64_t v_sw_scratch; /* 3a8h */ + uint8_t v_pad9[0x38]; /* 3B0h-3E7h */ + uint64_t v_xcr0; /* 3E8h */ +#define GHCB_VB_SZ 0x10 + uint8_t valid_bitmap[GHCB_VB_SZ]; + /* 3F0h-3FFh */ + uint64_t v_x87_state_gpa; /* 400h */ + uint8_t v_pad10[0x3f8]; /* 408h-7FFh */ + uint8_t v_sharedbuf[0x7f0]; /* 800h-FEFh */ + uint8_t v_pad11[0xa]; /* FF0h-FF9h */ + uint16_t v_ghcb_proto_version; /* FFAh-FFBh */ + uint32_t v_ghcb_usage; /* FFCh-FFFh */ +}; + +#define GHCB_SZ8 0 +#define GHCB_SZ16 1 +#define GHCB_SZ32 2 +#define GHCB_SZ64 3 + +struct ghcb_sync { + uint8_t valid_bitmap[GHCB_VB_SZ]; + + int sz_a; + int sz_b; + int sz_c; + int sz_d; +}; +#endif /* !_LOCORE */ + +/* Definitions used with the MSR protocol */ +#define MSR_PROTO_CPUID_REQ 0x4 +#define MSR_PROTO_CPUID_RESP 0x5 +#define MSR_PROTO_TERMINATE 0x100 + +#ifndef _LOCORE + +extern vaddr_t ghcb_vaddr; +extern paddr_t ghcb_paddr; + +struct ghcb_extra_regs { + uint64_t exitcode; + uint64_t exitinfo1; + uint64_t exitinfo2; + uint64_t scratch; + void *data; + size_t data_sz; +}; + +void ghcb_clear(struct ghcb_sa *); +int ghcb_valbm_set(uint8_t *, int); +int ghcb_valbm_isset(uint8_t *, int); +int ghcb_verify_bm(uint8_t *, uint8_t *); +int ghcb_valid(struct ghcb_sa *); + +void ghcb_sync_val(int, int, struct ghcb_sync *); +void ghcb_sync_out(struct trapframe *, const struct ghcb_extra_regs *, + struct ghcb_sa *, struct ghcb_sync *); +void ghcb_sync_in(struct trapframe *, struct ghcb_extra_regs *, + struct ghcb_sa *, struct ghcb_sync *); +void _ghcb_mem_rw(vaddr_t, int, void *, bool); +void _ghcb_io_rw(uint16_t, int, uint32_t *, bool); + +static inline uint8_t +ghcb_mem_read_1(vaddr_t addr) +{ + uint8_t val; + + _ghcb_mem_rw(addr, GHCB_SZ8, &val, true); + return val; +} + +static inline uint16_t +ghcb_mem_read_2(vaddr_t addr) +{ + uint16_t val; + + _ghcb_mem_rw(addr, GHCB_SZ16, &val, true); + return val; +} + +static inline uint32_t +ghcb_mem_read_4(vaddr_t addr) +{ + uint32_t val; + + _ghcb_mem_rw(addr, GHCB_SZ32, &val, true); + return val; +} + +static inline uint64_t +ghcb_mem_read_8(vaddr_t addr) +{ + uint64_t val; + + _ghcb_mem_rw(addr, GHCB_SZ64, &val, true); + return val; +} + +static inline void +ghcb_mem_write_1(vaddr_t addr, uint8_t v) +{ + _ghcb_mem_rw(addr, GHCB_SZ8, &v, false); +} + +static inline void +ghcb_mem_write_2(vaddr_t addr, uint16_t v) +{ + _ghcb_mem_rw(addr, GHCB_SZ16, &v, false); +} + +static inline void +ghcb_mem_write_4(vaddr_t addr, uint32_t v) +{ + _ghcb_mem_rw(addr, GHCB_SZ32, &v, false); +} + +static inline void +ghcb_mem_write_8(vaddr_t addr, uint64_t v) +{ + _ghcb_mem_rw(addr, GHCB_SZ64, &v, false); +} + +static inline uint8_t +ghcb_io_read_1(uint16_t port) +{ + uint32_t val; + + _ghcb_io_rw(port, GHCB_SZ8, &val, true); + return val; +} + +static inline uint16_t +ghcb_io_read_2(uint16_t port) +{ + uint32_t val; + + _ghcb_io_rw(port, GHCB_SZ16, &val, true); + return val; +} + +static inline uint32_t +ghcb_io_read_4(uint16_t port) +{ + uint32_t val; + + _ghcb_io_rw(port, GHCB_SZ32, &val, true); + return val; +} + +static inline void +ghcb_io_write_1(uint16_t port, uint8_t v) +{ + uint32_t val = v; + + _ghcb_io_rw(port, GHCB_SZ8, &val, false); +} + +static inline void +ghcb_io_write_2(uint16_t port, uint16_t v) +{ + uint32_t val = v; + + _ghcb_io_rw(port, GHCB_SZ16, &val, false); +} + +static inline void +ghcb_io_write_4(uint16_t port, uint32_t v) +{ + _ghcb_io_rw(port, GHCB_SZ32, &v, false); +} + +#endif /* !_LOCORE */ + +#endif /* !_MACHINE_GHCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/hibernate.h b/lib/libc/include/x86_64-openbsd-none/machine/hibernate.h new file mode 100644 index 0000000000..09f2c2bbe8 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/hibernate.h @@ -0,0 +1,36 @@ +/* $OpenBSD: hibernate.h,v 1.7 2018/06/21 07:33:30 mlarkin Exp $ */ + +/* + * Copyright (c) 2011 Mike Larkin + * + * 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 + +/* amd64 hibernate support structures and functions */ + +int get_hibernate_info_md(union hibernate_info *); +void hibernate_flush(void); +void hibernate_enter_resume_mapping(vaddr_t, paddr_t, int); +int hibernate_inflate_skip(union hibernate_info *, paddr_t); +int hibernate_suspend(void); +void hibernate_switch_stack_machdep(void); +void hibernate_resume_machdep(vaddr_t); +void hibernate_activate_resume_pt_machdep(void); +void hibernate_enable_intr_machdep(void); +void hibernate_disable_intr_machdep(void); +#ifdef MULTIPROCESSOR +void hibernate_quiesce_cpus(void); +void hibernate_drop_to_real_mode(void); +#endif /* MULTIPROCESSOR */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/hibernate_var.h b/lib/libc/include/x86_64-openbsd-none/machine/hibernate_var.h new file mode 100644 index 0000000000..f65025fe94 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/hibernate_var.h @@ -0,0 +1,75 @@ +/* $OpenBSD: hibernate_var.h,v 1.14 2025/09/13 13:43:47 mlarkin Exp $ */ + +/* + * Copyright (c) 2011 Mike Larkin + * + * 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 PIGLET_PAGE_MASK (L2_FRAME) + +/* + * PML4 table for resume + */ +#define HIBERNATE_PML4T (PAGE_SIZE * 21) + +/* + * amd64 uses a PDPT to map the first 512GB phys mem plus one more + * to map any ranges of phys mem past 512GB (if needed) + */ +#define HIBERNATE_PDPT_LOW (PAGE_SIZE * 22) +#define HIBERNATE_PDPT_HI (PAGE_SIZE * 23) + +/* + * amd64 uses one PD to map the first 1GB phys mem plus one more to map any + * other 1GB ranges within the first 512GB phys, plus one more to map any + * 1GB range in any subsequent 512GB range + */ +#define HIBERNATE_PD_LOW (PAGE_SIZE * 24) +#define HIBERNATE_PD_LOW2 (PAGE_SIZE * 25) +#define HIBERNATE_PD_HI (PAGE_SIZE * 26) + +/* + * amd64 uses one PT to map the first 2MB phys mem plus one more to map any + * other 2MB range within the first 1GB, plus one more to map any 2MB range + * in any subsequent 512GB range. + */ +#define HIBERNATE_PT_LOW (PAGE_SIZE * 27) +#define HIBERNATE_PT_LOW2 (PAGE_SIZE * 28) +#define HIBERNATE_PT_HI (PAGE_SIZE * 29) + +/* 3 pages for stack */ +#define HIBERNATE_STACK_PAGE (PAGE_SIZE * 32) + +#define HIBERNATE_INFLATE_PAGE (PAGE_SIZE * 33) +/* HIBERNATE_HIBALLOC_PAGE must be the last stolen page (see machdep.c) */ +#define HIBERNATE_HIBALLOC_PAGE (PAGE_SIZE * 34) + +/* Use 4MB hibernation chunks */ +#define HIBERNATE_CHUNK_SIZE 0x400000 + +#define HIBERNATE_CHUNK_TABLE_SIZE 0x200000 + +#define HIBERNATE_STACK_OFFSET 0x0F00 + +/* + * Minimum amount of memory for hibernate support. This is used in early boot + * when deciding if we can preallocate the piglet. If the machine does not + * have at least HIBERNATE_MIN_MEMORY RAM, we won't support hibernate. This + * avoids late allocation issues due to fragmented memory and failure to + * hibernate. We need to be able to allocate 16MB contiguous memory, aligned + * to 2MB. + * + * The default minimum required memory is 512MB (1ULL << 29). + */ +#define HIBERNATE_MIN_MEMORY (1ULL << 29) \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/i82093reg.h b/lib/libc/include/x86_64-openbsd-none/machine/i82093reg.h new file mode 100644 index 0000000000..c5b341fb94 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/i82093reg.h @@ -0,0 +1,135 @@ +/* $OpenBSD: i82093reg.h,v 1.9 2025/09/05 16:57:48 kettenis Exp $ */ +/* $NetBSD: i82093reg.h,v 1.1 2003/02/26 21:26:10 fvdl Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by RedBack Networks Inc. + * + * Author: Bill Sommerfeld + * + * 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. + */ + +/* + * Typically, the first apic lives here. + */ +#define IOAPIC_BASE_DEFAULT 0xfec00000 + +/* + * Memory-space registers. + */ + +/* + * The externally visible registers are all 32 bits wide; + * store the register number of interest in IOAPIC_REG, and store/fetch + * the real value in IOAPIC_DATA. + */ +#define IOAPIC_REG 0x0000 +#define IOAPIC_DATA 0x0010 + +/* + * Internal I/O APIC registers. + */ + +#define IOAPIC_ID 0x00 + +#define IOAPIC_ID_SHIFT 24 +#define IOAPIC_ID_MASK 0x0f000000 + +/* Version, and maximum interrupt pin number. */ + +#define IOAPIC_VER 0x01 + +#define IOAPIC_VER_SHIFT 0 +#define IOAPIC_VER_MASK 0x000000ff + +#define IOAPIC_MAX_SHIFT 16 +#define IOAPIC_MAX_MASK 0x00ff0000 + +/* + * Arbitration ID. Same format as IOAPIC_ID register. + */ +#define IOAPIC_ARB 0x02 + +/* + * Redirection table registers. + */ + +#define IOAPIC_REDHI(pin) (0x11 + ((pin)<<1)) +#define IOAPIC_REDLO(pin) (0x10 + ((pin)<<1)) + +#define IOAPIC_REDHI_DEST_SHIFT 24 /* destination. */ +#define IOAPIC_REDHI_DEST_MASK 0xff000000 + +#define IOAPIC_REDLO_MASK 0x00010000 /* 0=enabled; 1=masked */ + +#define IOAPIC_REDLO_LEVEL 0x00008000 /* 0=edge, 1=level */ +#define IOAPIC_REDLO_RIRR 0x00004000 /* remote IRR; read only */ +#define IOAPIC_REDLO_ACTLO 0x00002000 /* 0=act. hi; 1=act. lo */ +#define IOAPIC_REDLO_DELSTS 0x00001000 /* 0=idle; 1=send pending */ +#define IOAPIC_REDLO_DSTMOD 0x00000800 /* 0=physical; 1=logical */ + +#define IOAPIC_REDLO_DEL_MASK 0x00000700 /* del. mode mask */ +#define IOAPIC_REDLO_DEL_SHIFT 8 + +#define IOAPIC_REDLO_DEL_FIXED 0 +#define IOAPIC_REDLO_DEL_LOPRI 1 +#define IOAPIC_REDLO_DEL_SMI 2 +#define IOAPIC_REDLO_DEL_NMI 4 +#define IOAPIC_REDLO_DEL_INIT 5 +#define IOAPIC_REDLO_DEL_EXTINT 7 + +#define IOAPIC_REDLO_VECTOR_MASK 0x000000ff /* delivery vector */ + +#define IMCR_ADDR 0x22 +#define IMCR_DATA 0x23 + +#define IMCR_REGISTER 0x70 +#define IMCR_PIC 0x00 +#define IMCR_APIC 0x01 + +#ifdef _KERNEL + +#include + +#define ioapic_asm_ack(num) \ + CODEPATCH_START ;\ + movl $0,(local_apic+LAPIC_EOI)(%rip) ;\ + CODEPATCH_END(CPTAG_EOI) + +#define ioapic_mask(num) \ + movq IS_PIC(%r14),%rdi ;\ + movl IS_PIN(%r14),%esi ;\ + call ioapic_hwmask + +#define ioapic_unmask(num) \ + cmpq $IREENT_MAGIC,IF_ERR(%rsp) ;\ + jne 79f ;\ + movq IS_PIC(%r14),%rdi ;\ + movl IS_PIN(%r14),%esi ;\ + call ioapic_hwunmask ;\ +79: + +#endif \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/i82093var.h b/lib/libc/include/x86_64-openbsd-none/machine/i82093var.h new file mode 100644 index 0000000000..1124b33cc7 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/i82093var.h @@ -0,0 +1,92 @@ +/* $OpenBSD: i82093var.h,v 1.8 2025/09/05 16:57:48 kettenis Exp $ */ +/* $NetBSD: i82093var.h,v 1.1 2003/02/26 21:26:10 fvdl Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by RedBack Networks Inc. + * + * Author: Bill Sommerfeld + * + * 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_I82093VAR_H_ +#define _MACHINE_I82093VAR_H_ + +#include + +struct ioapic_pin { + struct ioapic_pin *ip_next; /* next pin on this vector */ + struct mp_intr_map *ip_map; + int ip_vector; /* IDT vector */ + int ip_type; + struct cpu_info *ip_cpu; /* target CPU */ +}; + +struct ioapic_softc { + struct pic sc_pic; + struct ioapic_softc *sc_next; + int sc_apicid; + int sc_apic_vers; + int sc_apic_vecbase; /* global int base if ACPI */ + int sc_apic_sz; /* apic size*/ + int sc_flags; + bus_space_tag_t sc_memt; + bus_space_handle_t sc_memh; + struct ioapic_pin *sc_pins; /* sc_apic_sz entries */ +}; + +/* + * MP: intr_handle_t is bitfielded. + * ih&0xff -> legacy irq number. + * ih&0x10000000 -> if 0, old-style isa irq; if 1, routed via ioapic. + * (ih&0xff0000)>>16 -> ioapic id. + * (ih&0x00ff00)>>8 -> ioapic pin. + */ + +#define APIC_INT_VIA_APIC 0x10000000 +#define APIC_INT_VIA_MSG 0x20000000 +#define APIC_INT_VIA_MSGX 0x40000000 +#define APIC_INT_APIC_MASK 0x00ff0000 +#define APIC_INT_APIC_SHIFT 16 +#define APIC_INT_PIN_MASK 0x0000ff00 +#define APIC_INT_PIN_SHIFT 8 + +#define APIC_IRQ_APIC(x) ((x & APIC_INT_APIC_MASK) >> APIC_INT_APIC_SHIFT) +#define APIC_IRQ_PIN(x) ((x & APIC_INT_PIN_MASK) >> APIC_INT_PIN_SHIFT) +#define APIC_IRQ_ISLEGACY(x) (!((x) & APIC_INT_VIA_APIC)) +#define APIC_IRQ_LEGACY_IRQ(x) ((x) & 0xff) + +void ioapic_print_redir(struct ioapic_softc *, char *, int); +struct ioapic_softc *ioapic_find(int); +struct ioapic_softc *ioapic_find_bybase(int); + +void ioapic_enable(void); + +extern int ioapic_bsp_id; +extern int nioapics; +extern struct ioapic_softc *ioapics; + +#endif /* !_MACHINE_I82093VAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/i82489reg.h b/lib/libc/include/x86_64-openbsd-none/machine/i82489reg.h new file mode 100644 index 0000000000..788c516ac7 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/i82489reg.h @@ -0,0 +1,149 @@ +/* $OpenBSD: i82489reg.h,v 1.5 2019/07/26 04:35:38 kevlo Exp $ */ +/* $NetBSD: i82489reg.h,v 1.1 2003/02/26 21:26:10 fvdl Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Frank van der Linden. + * + * 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. + */ + + +/* + * Registers and constants for the 82489DX and Pentium (and up) integrated + * "local" APIC. + */ + +#define LAPIC_ID 0x020 /* ID. RW */ +# define LAPIC_ID_MASK 0x0f000000 +# define LAPIC_ID_SHIFT 24 + +#define LAPIC_VERS 0x030 /* Version. R */ +# define LAPIC_VERSION_MASK 0x000000ff +# define LAPIC_VERSION_LVT_MASK 0x00ff0000 +# define LAPIC_VERSION_LVT_SHIFT 16 + +#define LAPIC_TPRI 0x080 /* Task Prio. RW */ +# define LAPIC_TPRI_MASK 0x000000ff +# define LAPIC_TPRI_INT_MASK 0x000000f0 +# define LAPIC_TPRI_SUB_MASK 0x0000000f + +#define LAPIC_APRI 0x090 /* Arbitration prio R */ +# define LAPIC_APRI_MASK 0x000000ff + +#define LAPIC_PPRI 0x0a0 /* Processor prio. R */ +#define LAPIC_EOI 0x0b0 /* End Int. W */ +#define LAPIC_RRR 0x0c0 /* Remote read R */ +#define LAPIC_LDR 0x0d0 /* Logical dest. RW */ +#define LAPIC_DFR 0x0e0 /* Dest. format RW */ + +#define LAPIC_SVR 0x0f0 /* Spurious intvec RW */ +# define LAPIC_SVR_VECTOR_MASK 0x000000ff +# define LAPIC_SVR_VEC_FIX 0x0000000f +# define LAPIC_SVR_VEC_PROG 0x000000f0 +# define LAPIC_SVR_ENABLE 0x00000100 +# define LAPIC_SVR_SWEN 0x00000100 +# define LAPIC_SVR_FOCUS 0x00000200 +# define LAPIC_SVR_FDIS 0x00000200 + +#define LAPIC_ISR 0x100 /* Int. status. R */ +#define LAPIC_TMR 0x180 +#define LAPIC_IRR 0x200 +#define LAPIC_ESR 0x280 /* Err status. R */ + +#define LAPIC_ICRLO 0x300 /* Int. cmd. RW */ +# define LAPIC_DLMODE_MASK 0x00000700 +# define LAPIC_DLMODE_FIXED 0x00000000 +# define LAPIC_DLMODE_LOW 0x00000100 +# define LAPIC_DLMODE_SMI 0x00000200 +# define LAPIC_DLMODE_RR 0x00000300 +# define LAPIC_DLMODE_NMI 0x00000400 +# define LAPIC_DLMODE_INIT 0x00000500 +# define LAPIC_DLMODE_STARTUP 0x00000600 + +# define LAPIC_DSTMODE_LOG 0x00000800 + +# define LAPIC_DLSTAT_BUSY 0x00001000 + +# define LAPIC_LVL_ASSERT 0x00004000 +# define LAPIC_LVL_DEASSERT 0x00000000 + +# define LAPIC_LVL_TRIG 0x00008000 + +# define LAPIC_RRSTAT_MASK 0x00030000 +# define LAPIC_RRSTAT_INPROG 0x00010000 +# define LAPIC_RRSTAT_VALID 0x00020000 + +# define LAPIC_DEST_MASK 0x000c0000 +# define LAPIC_DEST_SELF 0x00040000 +# define LAPIC_DEST_ALLINCL 0x00080000 +# define LAPIC_DEST_ALLEXCL 0x000c0000 + +# define LAPIC_RESV2_MASK 0xfff00000 + + +#define LAPIC_ICRHI 0x310 /* Int. cmd. RW */ + +#define LAPIC_LVTT 0x320 /* Loc.vec.(timer) RW */ +# define LAPIC_LVTT_VEC_MASK 0x000000ff +# define LAPIC_LVTT_DS 0x00001000 +# define LAPIC_LVTT_M 0x00010000 +# define LAPIC_LVTT_TM 0x00020000 +# define LAPIC_LVTT_TM_ONESHOT 0x00000000 +# define LAPIC_LVTT_TM_PERIODIC 0x00020000 +# define LAPIC_LVTT_TM_TSCDL 0x00040000 + +#define LAPIC_PCINT 0x340 +#define LAPIC_LVINT0 0x350 /* Loc.vec (LINT0) RW */ +# define LAPIC_LVT_PERIODIC 0x00020000 +# define LAPIC_LVT_MASKED 0x00010000 +# define LAPIC_LVT_LEVTRIG 0x00008000 +# define LAPIC_LVT_REMOTE_IRR 0x00004000 +# define LAPIC_INP_POL 0x00002000 +# define LAPIC_PEND_SEND 0x00001000 + +#define LAPIC_LVINT1 0x360 /* Loc.vec (LINT1) RW */ +#define LAPIC_LVERR 0x370 /* Loc.vec (ERROR) RW */ +#define LAPIC_ICR_TIMER 0x380 /* Initial count RW */ +#define LAPIC_CCR_TIMER 0x390 /* Current count RO */ + +#define LAPIC_DCR_TIMER 0x3e0 /* Divisor config register */ +# define LAPIC_DCRT_DIV1 0x0b +# define LAPIC_DCRT_DIV2 0x00 +# define LAPIC_DCRT_DIV4 0x01 +# define LAPIC_DCRT_DIV8 0x02 +# define LAPIC_DCRT_DIV16 0x03 +# define LAPIC_DCRT_DIV32 0x08 +# define LAPIC_DCRT_DIV64 0x09 +# define LAPIC_DCRT_DIV128 0x0a + +#define LAPIC_BASE 0xfee00000 + +#define LAPIC_IRQ_MASK(i) (1 << ((i) + 1)) + +#define MSR_X2APIC_BASE 0x800 +#define MSR_X2APIC_EOI (MSR_X2APIC_BASE+0x0b) /* End Int. W */ +#define MSR_X2APIC_ID (MSR_X2APIC_BASE+0x02) /* ID. RW */ +#define X2APIC_ID_MASK 0xff \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/i82489var.h b/lib/libc/include/x86_64-openbsd-none/machine/i82489var.h new file mode 100644 index 0000000000..4477a13266 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/i82489var.h @@ -0,0 +1,124 @@ +/* $OpenBSD: i82489var.h,v 1.21 2024/11/07 17:24:42 bluhm Exp $ */ +/* $NetBSD: i82489var.h,v 1.1 2003/02/26 21:26:10 fvdl Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Frank van der Linden. + * + * 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_I82489VAR_H_ +#define _MACHINE_I82489VAR_H_ + +#include "vmm.h" + +/* + * Software definitions belonging to Local APIC driver. + */ + +#ifdef _KERNEL +extern volatile u_int32_t local_apic[]; +extern volatile u_int32_t lapic_tpr; +#endif + +extern u_int32_t (*lapic_readreg)(int); +extern void (*lapic_writereg)(int, u_int32_t); +u_int32_t lapic_cpu_number(void); + +/* + * "spurious interrupt vector"; vector used by interrupt which was + * aborted because the CPU masked it after it happened but before it + * was delivered.. "Oh, sorry, i caught you at a bad time". + * Low-order 4 bits must be all ones. + */ +extern void Xintrspurious(void); +#define LAPIC_SPURIOUS_VECTOR 0xef + +/* + * Vector used for inter-processor interrupts. + */ +extern void Xintr_lapic_ipi(void); +extern void Xrecurse_lapic_ipi(void); +extern void Xresume_lapic_ipi(void); +#define LAPIC_IPI_VECTOR 0xe0 + +/* + * We take 0xf0-0xfe for fast IPI handlers. + */ +#define LAPIC_IPI_OFFSET 0xf0 +#define LAPIC_IPI_INVLTLB (LAPIC_IPI_OFFSET + 0) +#define LAPIC_IPI_INVLPG (LAPIC_IPI_OFFSET + 1) +#define LAPIC_IPI_INVLRANGE (LAPIC_IPI_OFFSET + 2) +#define LAPIC_IPI_WBINVD (LAPIC_IPI_OFFSET + 3) +#define LAPIC_IPI_INVEPT (LAPIC_IPI_OFFSET + 4) + +extern void Xipi_invltlb(void); +extern void Xipi_invltlb_pcid(void); +extern void Xipi_invlpg(void); +extern void Xipi_invlpg_pcid(void); +extern void Xipi_invlrange(void); +extern void Xipi_invlrange_pcid(void); +extern void Xipi_wbinvd(void); +#if NVMM > 0 +extern void Xipi_invept(void); +#endif /* NVMM > 0 */ + +/* + * Vector used for local apic timer interrupts. + */ + +extern void Xintr_lapic_ltimer(void); +extern void Xresume_lapic_ltimer(void); +extern void Xrecurse_lapic_ltimer(void); +#define LAPIC_TIMER_VECTOR 0xc0 + +/* + * Vector used for Xen HVM Event Channel Interrupts. + */ +extern void Xintr_xen_upcall(void); +extern void Xresume_xen_upcall(void); +extern void Xrecurse_xen_upcall(void); +#define LAPIC_XEN_VECTOR 0x70 + +/* + * Vector used for Hyper-V Interrupts. + */ +extern void Xintr_hyperv_upcall(void); +extern void Xresume_hyperv_upcall(void); +extern void Xrecurse_hyperv_upcall(void); +#define LAPIC_HYPERV_VECTOR 0x71 + +struct cpu_info; + +extern void lapic_boot_init(paddr_t); +extern void lapic_set_lvt(void); +extern void lapic_enable(void); +extern void lapic_disable(void); +extern void lapic_calibrate_timer(struct cpu_info *ci); +extern void lapic_startclock(void); +extern void lapic_initclocks(void); + +#endif \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/i8259.h b/lib/libc/include/x86_64-openbsd-none/machine/i8259.h new file mode 100644 index 0000000000..28bdcd4743 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/i8259.h @@ -0,0 +1,144 @@ +/* $OpenBSD: i8259.h,v 1.4 2015/09/02 13:39:23 mikeb Exp $ */ +/* $NetBSD: i8259.h,v 1.3 2003/05/04 22:01:56 fvdl 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. + * + * @(#)icu.h 5.6 (Berkeley) 5/9/91 + */ + +#ifndef _MACHINE_I8259_H_ +#define _MACHINE_I8259_H_ + +#include + +#ifndef _LOCORE + +/* + * Interrupt "level" mechanism variables, masks, and macros + */ +extern unsigned i8259_imen; /* interrupt mask enable */ + +extern void i8259_default_setup(void); + +#endif /* !_LOCORE */ + +/* + * Interrupt enable bits -- in order of priority + */ +#define IRQ_SLAVE 2 + +/* + * Interrupt Control offset into Interrupt descriptor table (IDT) + */ +#define ICU_OFFSET 32 /* 0-31 are processor exceptions */ +#define ICU_LEN 16 /* 32-47 are ISA interrupts */ + + +#define ICU_HARDWARE_MASK + +/* + * These macros are fairly self explanatory. If ICU_SPECIAL_MASK_MODE is + * defined, we try to take advantage of the ICU's `special mask mode' by only + * EOIing the interrupts on return. This avoids the requirement of masking and + * unmasking. We can't do this without special mask mode, because the ICU + * would also hold interrupts that it thinks are of lower priority. + * + * Many machines do not support special mask mode, so by default we don't try + * to use it. + */ + +#define IRQ_BIT(num) (1 << ((num) % 8)) +#define IRQ_BYTE(num) ((num) >> 3) + +#define i8259_late_ack(num) + +#ifdef ICU_SPECIAL_MASK_MODE + +#define i8259_asm_ack1(num) +#define i8259_asm_ack2(num) \ + movb $(0x60|IRQ_SLAVE),%al /* specific EOI for IRQ2 */ ;\ + outb %al,$IO_ICU1 +#define i8259_asm_mask(num) +#define i8259_asm_unmask(num) \ + movb $(0x60|(num%8)),%al /* specific EOI */ ;\ + outb %al,$ICUADDR + +#else /* ICU_SPECIAL_MASK_MODE */ + +#ifndef AUTO_EOI_1 +#define i8259_asm_ack1(num) \ + movb $(0x60|(num%8)),%al /* specific EOI */ ;\ + outb %al,$IO_ICU1 +#else +#define i8259_asm_ack1(num) +#endif + +#ifndef AUTO_EOI_2 +#define i8259_asm_ack2(num) \ + movb $(0x60|(num%8)),%al /* specific EOI */ ;\ + outb %al,$IO_ICU2 /* do the second ICU first */ ;\ + movb $(0x60|IRQ_SLAVE),%al /* specific EOI for IRQ2 */ ;\ + outb %al,$IO_ICU1 +#else +#define i8259_asm_ack2(num) +#endif + +#ifdef PIC_MASKDELAY +#define MASKDELAY pushl %eax ; inb $0x84,%al ; popl %eax +#else +#define MASKDELAY +#endif + +#ifdef ICU_HARDWARE_MASK + +#define i8259_asm_mask(num) \ + movb CVAROFF(i8259_imen, IRQ_BYTE(num)),%al ;\ + orb $IRQ_BIT(num),%al ;\ + movb %al,CVAROFF(i8259_imen, IRQ_BYTE(num)) ;\ + MASKDELAY ;\ + outb %al,$(ICUADDR+1) +#define i8259_asm_unmask(num) \ + movb CVAROFF(i8259_imen, IRQ_BYTE(num)),%al ;\ + andb $~IRQ_BIT(num),%al ;\ + movb %al,CVAROFF(i8259_imen, IRQ_BYTE(num)) ;\ + MASKDELAY ;\ + outb %al,$(ICUADDR+1) + +#else /* ICU_HARDWARE_MASK */ + +#define i8259_asm_mask(num) +#define i8259_asm_unmask(num) + +#endif /* ICU_HARDWARE_MASK */ +#endif /* ICU_SPECIAL_MASK_MODE */ + +#endif /* !_MACHINE_I8259_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/ieee.h b/lib/libc/include/x86_64-openbsd-none/machine/ieee.h new file mode 100644 index 0000000000..dea4be1a6b --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/ieee.h @@ -0,0 +1,142 @@ +/* $OpenBSD: ieee.h,v 1.2 2008/09/07 20:36:06 martynas Exp $ */ +/* $NetBSD: ieee.h,v 1.1 1996/09/30 16:34:25 ws Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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, Lawrence Berkeley Laboratory. + * + * 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. + * + * @(#)ieee.h 8.1 (Berkeley) 6/11/93 + */ + +/* + * ieee.h defines the machine-dependent layout of the machine's IEEE + * floating point. It does *not* define (yet?) any of the rounding + * mode bits, exceptions, and so forth. + */ + +/* + * Define the number of bits in each fraction and exponent. + * + * k k+1 + * Note that 1.0 x 2 == 0.1 x 2 and that denorms are represented + * + * (-exp_bias+1) + * as fractions that look like 0.fffff x 2 . This means that + * + * -126 + * the number 0.10000 x 2 , for instance, is the same as the normalized + * + * -127 -128 + * float 1.0 x 2 . Thus, to represent 2 , we need one leading zero + * + * -129 + * in the fraction; to represent 2 , we need two, and so on. This + * + * (-exp_bias-fracbits+1) + * implies that the smallest denormalized number is 2 + * + * for whichever format we are talking about: for single precision, for + * + * -126 -149 + * instance, we get .00000000000000000000001 x 2 , or 1.0 x 2 , and + * + * -149 == -127 - 23 + 1. + */ +#define SNG_EXPBITS 8 +#define SNG_FRACBITS 23 + +#define DBL_EXPBITS 11 +#define DBL_FRACHBITS 20 +#define DBL_FRACLBITS 32 +#define DBL_FRACBITS 52 + +#define EXT_EXPBITS 15 +#define EXT_FRACHBITS 32 +#define EXT_FRACLBITS 32 +#define EXT_FRACBITS 64 + +#define EXT_TO_ARRAY32(p, a) do { \ + (a)[0] = (uint32_t)(p)->ext_fracl; \ + (a)[1] = (uint32_t)(p)->ext_frach; \ +} while(0) + +struct ieee_single { + u_int sng_frac:23; + u_int sng_exp:8; + u_int sng_sign:1; +}; + +struct ieee_double { + u_int dbl_fracl; + u_int dbl_frach:20; + u_int dbl_exp:11; + u_int dbl_sign:1; +}; + +struct ieee_ext { + u_int ext_fracl; + u_int ext_frach; + u_int ext_exp:15; + u_int ext_sign:1; + u_int ext_padl:16; + u_int ext_padh; +}; + +/* + * Floats whose exponent is in [1..INFNAN) (of whatever type) are + * `normal'. Floats whose exponent is INFNAN are either Inf or NaN. + * Floats whose exponent is zero are either zero (iff all fraction + * bits are zero) or subnormal values. + * + * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its + * high fraction; if the bit is set, it is a `quiet NaN'. + */ +#define SNG_EXP_INFNAN 255 +#define DBL_EXP_INFNAN 2047 +#define EXT_EXP_INFNAN 32767 + +#if 0 +#define SNG_QUIETNAN (1 << 22) +#define DBL_QUIETNAN (1 << 19) +#define EXT_QUIETNAN (1 << 15) +#endif + +/* + * Exponent biases. + */ +#define SNG_EXP_BIAS 127 +#define DBL_EXP_BIAS 1023 +#define EXT_EXP_BIAS 16383 \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/ieeefp.h b/lib/libc/include/x86_64-openbsd-none/machine/ieeefp.h new file mode 100644 index 0000000000..510fd8e157 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/ieeefp.h @@ -0,0 +1,26 @@ +/* $OpenBSD: ieeefp.h,v 1.2 2011/03/23 16:54:34 pirofti Exp $ */ + +/* + * Written by J.T. Conklin, Apr 6, 1995 + * Public domain. + */ + +#ifndef _MACHINE_IEEEFP_H_ +#define _MACHINE_IEEEFP_H_ + +typedef int fp_except; +#define FP_X_INV 0x01 /* invalid operation exception */ +#define FP_X_DNML 0x02 /* denormalization exception */ +#define FP_X_DZ 0x04 /* divide-by-zero exception */ +#define FP_X_OFL 0x08 /* overflow exception */ +#define FP_X_UFL 0x10 /* underflow exception */ +#define FP_X_IMP 0x20 /* imprecise (loss of precision) */ + +typedef enum { + FP_RN=0, /* round to nearest representable number */ + FP_RM=1, /* round toward negative infinity */ + FP_RP=2, /* round toward positive infinity */ + FP_RZ=3 /* round to zero (truncate) */ +} fp_rnd; + +#endif /* _MACHINE_IEEEFP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/intr.h b/lib/libc/include/x86_64-openbsd-none/machine/intr.h new file mode 100644 index 0000000000..ca5fda2141 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/intr.h @@ -0,0 +1,229 @@ +/* $OpenBSD: intr.h,v 1.36 2025/06/11 09:57:01 kettenis Exp $ */ +/* $NetBSD: intr.h,v 1.2 2003/05/04 22:01:56 fvdl 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_INTR_H_ +#define _MACHINE_INTR_H_ + +#define __USE_MI_SOFTINTR + +#include +#include + +#ifndef _LOCORE +#include + +#include + +/* + * Struct describing an interrupt source for a CPU. struct cpu_info + * has an array of MAX_INTR_SOURCES of these. The index in the array + * is equal to the stub number of the stubcode as present in vector.s + * + * The primary CPU's array of interrupt sources has its first 16 + * entries reserved for legacy ISA irq handlers. This means that + * they have a 1:1 mapping for arrayindex:irq_num. This is not + * true for interrupts that come in through IO APICs, to find + * their source, go through ci->ci_isources[index].is_pic + * + * It's possible to always maintain a 1:1 mapping, but that means + * limiting the total number of interrupt sources to MAX_INTR_SOURCES + * (32), instead of 32 per CPU. It also would mean that having multiple + * IO APICs which deliver interrupts from an equal pin number would + * overlap if they were to be sent to the same CPU. + */ + +struct intrstub { + void *ist_entry; + void *ist_recurse; + void *ist_resume; +}; + +struct intrsource { + int is_maxlevel; /* max. IPL for this source */ + int is_pin; /* IRQ for legacy; pin for IO APIC */ + struct intrhand *is_handlers; /* handler chain */ + struct pic *is_pic; /* originating PIC */ + void *is_recurse; /* entry for spllower */ + void *is_resume; /* entry for doreti */ + char is_evname[32]; /* event counter name */ + int is_flags; /* see below */ + int is_type; /* level, edge */ + int is_idtvec; + int is_minlevel; +}; + +#define IS_LEGACY 0x0001 /* legacy ISA irq source */ +#define IS_IPI 0x0002 +#define IS_LOG 0x0004 + + +/* + * Interrupt handler chains. *_intr_establish() insert a handler into + * the list. The handler is called with its (single) argument. + */ + +struct intrhand { + int (*ih_fun)(void *); + void *ih_arg; + int ih_level; + int ih_flags; + struct intrhand *ih_next; + int ih_pin; + int ih_slot; + struct cpu_info *ih_cpu; + int ih_irq; + struct evcount ih_count; +}; + +#define IMASK(ci,level) (ci)->ci_imask[(level)] +#define IUNMASK(ci,level) (ci)->ci_iunmask[(level)] + +extern void Xspllower(int); + +int splraise(int); +int spllower(int); +void softintr(int); +void dosoftint(int); + +/* + * Convert spl level to local APIC level + */ +#define APIC_LEVEL(l) ((l) << 4) + +/* + * compiler barrier: prevent reordering of instructions. + * This prevents the compiler from reordering code around + * this "instruction", acting as a sequence point for code generation. + */ + +#define __splbarrier() __asm volatile("":::"memory") + +/* + * Hardware interrupt masks + */ +#define splbio() splraise(IPL_BIO) +#define splnet() splraise(IPL_NET) +#define spltty() splraise(IPL_TTY) +#define splaudio() splraise(IPL_AUDIO) +#define splclock() splraise(IPL_CLOCK) +#define splstatclock() splclock() +#define splipi() splraise(IPL_IPI) + +/* + * Software interrupt masks + */ +#define splsoftclock() splraise(IPL_SOFTCLOCK) +#define splsoftnet() splraise(IPL_SOFTNET) +#define splsofttty() splraise(IPL_SOFTTTY) + +/* + * Miscellaneous + */ +#define splvm() splraise(IPL_VM) +#define splhigh() splraise(IPL_HIGH) +#define spl0() spllower(IPL_NONE) +#define splsched() splraise(IPL_SCHED) +#define splx(x) spllower(x) + +/* SPL asserts */ +#ifdef DIAGNOSTIC +/* + * Although this function is implemented in MI code, it must be in this MD + * header because we don't want this header to include MI includes. + */ +void splassert_fail(int, int, const char *); +extern int splassert_ctl; +void splassert_check(int, const char *); +#define splassert(__wantipl) do { \ + if (splassert_ctl > 0) { \ + splassert_check(__wantipl, __func__); \ + } \ +} while (0) +#define splsoftassert(wantipl) splassert(wantipl) +#else +#define splassert(wantipl) do { /* nada */ } while (0) +#define splsoftassert(wantipl) do { /* nada */ } while (0) +#endif + +#define IPLSHIFT 4 /* The upper nibble of vectors is the IPL. */ +#define IPL(level) ((level) >> IPLSHIFT) /* Extract the IPL. */ + +#include + +/* + * Stub declarations. + */ + +extern void Xsoftclock(void); +extern void Xsoftnet(void); +extern void Xsofttty(void); + +extern struct intrstub i8259_stubs[]; +extern struct intrstub ioapic_edge_stubs[]; +extern struct intrstub ioapic_level_stubs[]; + +struct cpu_info; + +extern int intr_shared_edge; + +extern char idt_allocmap[]; + +void intr_default_setup(void); +int x86_nmi(void); +void intr_calculatemasks(struct cpu_info *); +int intr_allocate_slot_cpu(struct cpu_info *, struct pic *, int, int *); +int intr_allocate_slot(struct pic *, int, int, int, struct cpu_info **, int *, + int *); +void *intr_establish(int, struct pic *, int, int, int, + struct cpu_info *, int (*)(void *), void *, const char *); +void intr_disestablish(struct intrhand *); +int intr_handler(struct intrframe *, struct intrhand *); +void cpu_intr_init(struct cpu_info *); +void intr_printconfig(void); +void intr_barrier(void *); +void intr_set_wakeup(void *); +void intr_enable_wakeup(void); +void intr_disable_wakeup(void); + +#ifdef MULTIPROCESSOR +void x86_send_ipi(struct cpu_info *, int); +int x86_fast_ipi(struct cpu_info *, int); +void x86_broadcast_ipi(int); +void x86_ipi_handler(void); +void x86_setperf_ipi(struct cpu_info *); + +extern void (*ipifunc[X86_NIPI])(struct cpu_info *); +#endif + +#endif /* !_LOCORE */ + +#endif /* !_MACHINE_INTR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/intrdefs.h b/lib/libc/include/x86_64-openbsd-none/machine/intrdefs.h new file mode 100644 index 0000000000..54fe1358ca --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/intrdefs.h @@ -0,0 +1,93 @@ +/* $OpenBSD: intrdefs.h,v 1.24 2024/05/26 13:37:31 kettenis Exp $ */ +/* $NetBSD: intrdefs.h,v 1.2 2003/05/04 22:01:56 fvdl Exp $ */ + +#ifndef _AMD64_INTRDEFS_H +#define _AMD64_INTRDEFS_H + +/* + * Interrupt priority levels. + * + * There are tty, network and disk drivers that use free() at interrupt + * time, so imp > (tty | net | bio). + * + * Since run queues may be manipulated by both the statclock and tty, + * network, and disk drivers, clock > imp. + * + * IPL_HIGH must block everything that can manipulate a run queue. + * + * The level numbers are picked to fit into APIC vector priorities. + * + */ +#define IPL_NONE 0x0 /* nothing */ +#define IPL_SOFTCLOCK 0x1 /* timeouts */ +#define IPL_SOFTNET 0x2 /* protocol stacks */ +#define IPL_BIO 0x3 /* block I/O */ +#define IPL_NET 0x4 /* network */ +#define IPL_SOFTTTY 0x8 /* delayed terminal handling */ +#define IPL_TTY 0x9 /* terminal */ +#define IPL_VM 0xa /* memory allocation */ +#define IPL_AUDIO 0xb /* audio */ +#define IPL_CLOCK 0xc /* clock */ +#define IPL_SCHED IPL_CLOCK +#define IPL_STATCLOCK IPL_CLOCK +#define IPL_HIGH 0xd /* everything */ +#define IPL_IPI 0xe /* inter-processor interrupts */ +#define NIPL 16 + +#define IPL_MPFLOOR IPL_TTY +#define IPL_MPSAFE 0x100 +#define IPL_WAKEUP 0x200 + +/* Interrupt sharing types. */ +#define IST_NONE 0 /* none */ +#define IST_PULSE 1 /* pulsed */ +#define IST_EDGE 2 /* edge-triggered */ +#define IST_LEVEL 3 /* level-triggered */ + +/* + * Local APIC masks. Must not conflict with SIR_* above, and must + * be >= NUM_LEGACY_IRQs. Note that LIR_IPI must be first. + */ +#define LIR_IPI 63 +#define LIR_TIMER 62 + +/* Soft interrupt masks. */ +#define SIR_CLOCK 61 +#define SIR_NET 60 +#define SIR_TTY 59 + +#define LIR_XEN 58 +#define LIR_HYPERV 57 + +/* + * Maximum # of interrupt sources per CPU. 64 to fit in one word. + * ioapics can theoretically produce more, but it's not likely to + * happen. For multiple ioapics, things can be routed to different + * CPUs. + */ +#define MAX_INTR_SOURCES 64 +#define NUM_LEGACY_IRQS 16 + +/* + * Low and high boundaries between which interrupt gates will + * be allocated in the IDT. + */ +#define IDT_INTR_LOW (0x20 + NUM_LEGACY_IRQS) +#define IDT_INTR_HIGH 0xef + +#define X86_IPI_HALT 0x00000001 +#define X86_IPI_NOP 0x00000002 +#define X86_IPI_VMCLEAR_VMM 0x00000004 +#define X86_IPI_PCTR 0x00000010 +#define X86_IPI_MTRR 0x00000020 +#define X86_IPI_SETPERF 0x00000040 +#define X86_IPI_DDB 0x00000080 +#define X86_IPI_START_VMM 0x00000100 +#define X86_IPI_STOP_VMM 0x00000200 +#define X86_IPI_WBINVD 0x00000400 + +#define X86_NIPI 12 + +#define IREENT_MAGIC 0x18041969 + +#endif /* _AMD64_INTRDEFS_H */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/ioctl_fd.h b/lib/libc/include/x86_64-openbsd-none/machine/ioctl_fd.h new file mode 100644 index 0000000000..659711f9d7 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/ioctl_fd.h @@ -0,0 +1,130 @@ +/* $OpenBSD: ioctl_fd.h,v 1.2 2011/03/23 16:54:34 pirofti Exp $ */ + +/* + * Copyright (C) 1992-1994 by Joerg Wunsch, Dresden + * 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(S) ``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(S) 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: Id: ioctl_fd.h,v 1.7 1994/10/30 19:17:39 joerg Exp + */ + +#ifndef _MACHINE_IOCTL_FD_H_ +#define _MACHINE_IOCTL_FD_H_ + +#include + +#define FD_FORMAT_VERSION 110 /* used to validate before formatting */ +#define FD_MAX_NSEC 36 /* highest known number of spt - allow for */ + /* 2.88 MB drives */ + +struct fd_formb { + int format_version; /* == FD_FORMAT_VERSION */ + int cyl, head; + int transfer_rate; /* fdreg.h: FDC_???KBPS */ + + union { + struct fd_form_data { + /* + * DO NOT CHANGE THE LAYOUT OF THIS STRUCTS + * it is hardware-dependant since it exactly + * matches the byte sequence to write to FDC + * during its `format track' operation + */ + u_char secshift; /* 0 -> 128, ...; usually 2 -> 512 */ + u_char nsecs; /* must be <= FD_MAX_NSEC */ + u_char gaplen; /* GAP 3 length; usually 84 */ + u_char fillbyte; /* usually 0xf6 */ + struct fd_idfield_data { + /* + * data to write into id fields; + * for obscure formats, they mustn't match + * the real values (but mostly do) + */ + u_char cylno; /* 0 thru 79 (or 39) */ + u_char headno; /* 0, or 1 */ + u_char secno; /* starting at 1! */ + u_char secsize; /* usually 2 */ + } idfields[FD_MAX_NSEC]; /* 0 <= idx < nsecs used */ + } structured; + u_char raw[1]; /* to have continuous indexed access */ + } format_info; +}; + +/* make life easier */ +# define fd_formb_secshift format_info.structured.secshift +# define fd_formb_nsecs format_info.structured.nsecs +# define fd_formb_gaplen format_info.structured.gaplen +# define fd_formb_fillbyte format_info.structured.fillbyte +/* these data must be filled in for(i = 0; i < fd_formb_nsecs; i++) */ +# define fd_formb_cylno(i) format_info.structured.idfields[i].cylno +# define fd_formb_headno(i) format_info.structured.idfields[i].headno +# define fd_formb_secno(i) format_info.structured.idfields[i].secno +# define fd_formb_secsize(i) format_info.structured.idfields[i].secsize + +/* + * Floppies come in various flavors, e.g., 1.2MB vs 1.44MB; here is how + * we tell them apart. + */ +struct fd_type { + int sectrac; /* sectors per track */ + int heads; /* number of heads */ + int seccyl; /* sectors per cylinder */ + int secsize; /* size code for sectors */ + int datalen; /* data len when secsize = 0 */ + int steprate; /* step rate and head unload time */ + int gap1; /* gap len between sectors */ + int gap2; /* formatting gap */ + int tracks; /* total num of tracks */ + int size; /* size of disk in sectors */ + int step; /* steps per cylinder */ + int rate; /* transfer speed code */ + char *name; +}; + + +#define FD_FORM _IOW('F', 61, struct fd_formb) /* format a track */ +#define FD_GTYPE _IOR('F', 62, struct fd_type) /* get drive type */ +#define FD_STYPE _IOW('F', 63, struct fd_type) /* set drive type */ + +#define FD_GOPTS _IOR('F', 64, int) /* drive options, see below */ +#define FD_SOPTS _IOW('F', 65, int) + +#define FDOPT_NORETRY 0x0001 /* no retries on failure (cleared on close) */ + +/* + * The following definitions duplicate those in sys/i386/isa/fdreg.h + * They are here since their values are to be used in the above + * structure when formatting a floppy. For very obvious reasons, both + * definitions must match ;-) + */ +#ifndef FDC_500KBPS +#define FDC_500KBPS 0x00 /* 500KBPS MFM drive transfer rate */ +#define FDC_300KBPS 0x01 /* 300KBPS MFM drive transfer rate */ +#define FDC_250KBPS 0x02 /* 250KBPS MFM drive transfer rate */ +#define FDC_125KBPS 0x03 /* 125KBPS FM drive transfer rate */ + /* for some controllers 1MPBS instead */ +#endif /* FDC_500KBPS */ + + +#endif /* !_MACHINE_IOCTL_FD_H__ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/isa_machdep.h b/lib/libc/include/x86_64-openbsd-none/machine/isa_machdep.h new file mode 100644 index 0000000000..3efae87c13 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/isa_machdep.h @@ -0,0 +1,163 @@ +/* $OpenBSD: isa_machdep.h,v 1.11 2024/05/22 05:51:49 jsg Exp $ */ +/* $NetBSD: isa_machdep.h,v 1.2 2003/05/09 23:51:28 fvdl Exp $ */ + +/*- + * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*- + * Copyright (c) 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. + * + * @(#)isa.h 5.7 (Berkeley) 5/9/91 + */ + +/* + * Various pieces of the i386 port want to include this file without + * or in spite of using isavar.h, and should be fixed. + */ + +#ifndef _I386_ISA_MACHDEP_H_ /* XXX */ +#define _I386_ISA_MACHDEP_H_ /* XXX */ + +#include +#include + +/* + * ISA can only DMA to 0-16M. + */ +#define ISA_DMA_BOUNCE_THRESHOLD 0x00ffffff + +/* + * XXX THIS FILE IS A MESS. copyright: berkeley's probably. + * contents from isavar.h and isareg.h, mostly the latter. + * perhaps charles's? + * + * copyright from berkeley's isa.h which is now dev/isa/isareg.h. + */ + +/* + * Types provided to machine-independent ISA code. + */ + +typedef void *isa_chipset_tag_t; + +struct device; /* XXX */ +struct isabus_attach_args; /* XXX */ + +/* + * Functions provided to machine-independent ISA code. + */ +void isa_attach_hook(struct device *, struct device *, + struct isabus_attach_args *); +int isa_intr_alloc(isa_chipset_tag_t, int, int, int *); +void *isa_intr_establish(isa_chipset_tag_t ic, int irq, int type, + int level, int (*ih_fun)(void *), void *ih_arg, char *); +void isa_intr_disestablish(isa_chipset_tag_t ic, void *handler); + +int isa_intr_check(isa_chipset_tag_t, int, int); + +/* + * ALL OF THE FOLLOWING ARE MACHINE-DEPENDENT, AND SHOULD NOT BE USED + * BY PORTABLE CODE. + */ + +extern struct bus_dma_tag isa_bus_dma_tag; + +/* + * Cookie used by ISA dma. A pointer to one of these it stashed in + * the DMA map. + */ +struct isa_dma_cookie { + int id_flags; /* flags; see below */ + + void *id_origbuf; /* pointer to orig buffer if + bouncing */ + bus_size_t id_origbuflen; /* ...and size */ + + void *id_bouncebuf; /* pointer to the bounce buffer */ + bus_size_t id_bouncebuflen; /* ...and size */ + int id_nbouncesegs; /* number of valid bounce segs */ + bus_dma_segment_t id_bouncesegs[0]; /* array of bounce buffer + physical memory segments */ +}; + +/* id_flags */ +#define ID_MIGHT_NEED_BOUNCE 0x01 /* map could need bounce buffers */ +#define ID_HAS_BOUNCE 0x02 /* map currently has bounce buffers */ +#define ID_IS_BOUNCING 0x04 /* map is bouncing current xfer */ + +/* + * Variables and macros to deal with the ISA I/O hole. + * XXX These should be converted to machine- and bus-mapping-independent + * function definitions, invoked through the softc. + */ + +extern u_long atdevbase; /* kernel virtual address of "hole" */ + +/* + * Given a kernel virtual address for some location + * in the "hole" I/O space, return a physical address. + */ +#define ISA_PHYSADDR(v) ((void *) ((u_long)(v) - atdevbase + IOM_BEGIN)) + +/* + * Given a physical address in the "hole", + * return a kernel virtual address. + */ +#define ISA_HOLE_VADDR(p) ((void *) ((u_long)(p) - IOM_BEGIN + atdevbase)) + +#endif /* _I386_ISA_MACHDEP_H_ XXX */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/kcore.h b/lib/libc/include/x86_64-openbsd-none/machine/kcore.h new file mode 100644 index 0000000000..b02ab28664 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/kcore.h @@ -0,0 +1,47 @@ +/* $OpenBSD: kcore.h,v 1.5 2018/04/03 07:13:37 mlarkin Exp $ */ +/* $NetBSD: kcore.h,v 1.1 2003/04/26 18:39:43 fvdl Exp $ */ + +/* + * Copyright (c) 1996 Carnegie-Mellon University. + * All rights reserved. + * + * Author: Chris G. Demetriou + * + * Permission to use, copy, modify and distribute this software and + * its documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND + * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie the + * rights to redistribute these changes. + */ + +/* + * Modified for NetBSD/i386 by Jason R. Thorpe, Numerical Aerospace + * Simulation Facility, NASA Ames Research Center. + * + * And once again modified for x86-64 by Frank van der Linden of + * Wasabi Systems, Inc. + */ + +#ifndef _MACHINE_KCORE_H_ +#define _MACHINE_KCORE_H_ + +typedef struct cpu_kcore_hdr { + u_int64_t ptdpaddr; /* PA of PML4 */ + u_int64_t nmemsegs; /* Number of RAM segments */ +} cpu_kcore_hdr_t; + +#endif /* _MACHINE_KCORE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/limits.h b/lib/libc/include/x86_64-openbsd-none/machine/limits.h new file mode 100644 index 0000000000..f288e05429 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/limits.h @@ -0,0 +1,52 @@ +/* $OpenBSD: limits.h,v 1.6 2015/04/30 13:42:08 millert 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. + * + * @(#)limits.h 7.2 (Berkeley) 6/28/90 + */ + +#ifndef _MACHINE_LIMITS_H_ +#define _MACHINE_LIMITS_H_ + +#include + +#if __POSIX_VISIBLE || __XPG_VISIBLE +#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_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/loadfile_machdep.h b/lib/libc/include/x86_64-openbsd-none/machine/loadfile_machdep.h new file mode 100644 index 0000000000..c856e9b9f6 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/loadfile_machdep.h @@ -0,0 +1,61 @@ +/* $OpenBSD: loadfile_machdep.h,v 1.9 2019/05/28 04:51:26 mlarkin Exp $ */ +/* $NetBSD: loadfile_machdep.h,v 1.1 1999/04/29 03:17:12 tsubai Exp $ */ + +/*- + * Copyright (c) 1999 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * 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. + */ + +#define BOOT_ELF +#define BOOT_ELF32 +#define BOOT_ELF64 + +/* Keep a default ELFSIZE */ +#define ELFSIZE 64 + +#define LOAD_KERNEL LOAD_ALL +#define COUNT_KERNEL COUNT_ALL + +#ifdef EFIBOOT +extern u_long efi_loadaddr; +#define LOADADDR(a) (((((u_long)(a)) + offset)&0xfffffff) + \ + efi_loadaddr) +#else +#define LOADADDR(a) ((a) + offset) +#endif +#define ALIGNENTRY(a) ((u_long)(a)) +#define READ(f, b, c) read((f), (void *)LOADADDR(b), (c)) +#define BCOPY(s, d, c) memcpy((void *)LOADADDR(d), (void *)(s), (c)) +#define BZERO(d, c) memset((void *)LOADADDR(d), 0, (c)) +#define WARN(a) (void)(printf a, \ + printf((errno ? ": %s\n" : "\n"), \ + strerror(errno))) +#define PROGRESS(a) (void) printf a +#define ALLOC(a) alloc(a) +#define FREE(a, b) free(a, b) + +void run_loadfile(uint64_t *, int); \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/mpbiosreg.h b/lib/libc/include/x86_64-openbsd-none/machine/mpbiosreg.h new file mode 100644 index 0000000000..8a35f5f11d --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/mpbiosreg.h @@ -0,0 +1,156 @@ +/* $OpenBSD: mpbiosreg.h,v 1.5 2023/04/10 04:21:20 jsg Exp $ */ +/* $NetBSD: mpbiosreg.h,v 1.3 2003/03/04 23:27:32 fvdl Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by RedBack Networks Inc. + * + * Author: Bill Sommerfeld + * + * 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_MPBIOSREG_H_ +#define _MACHINE_MPBIOSREG_H_ + +#define BIOS_BASE (0xf0000) +#define BIOS_SIZE (0x10000) +#define BIOS_COUNT (BIOS_SIZE) + +/* + * Multiprocessor config table entry types. + */ + +#define MPS_MCT_CPU 0 +#define MPS_MCT_BUS 1 +#define MPS_MCT_IOAPIC 2 +#define MPS_MCT_IOINT 3 +#define MPS_MCT_LINT 4 + +#define MPS_MCT_NTYPES 5 + +/* + * Interrupt types + */ + +#define MPS_INTTYPE_INT 0 +#define MPS_INTTYPE_NMI 1 +#define MPS_INTTYPE_SMI 2 +#define MPS_INTTYPE_ExtINT 3 + +#define MPS_INTPO_DEF 0 +#define MPS_INTPO_ACTHI 1 +#define MPS_INTPO_ACTLO 3 +#define MPS_INTPO_SHIFT 0 +#define MPS_INTPO_MASK 3 + +#define MPS_INTTR_DEF 0 +#define MPS_INTTR_EDGE 1 +#define MPS_INTTR_LEVEL 3 +#define MPS_INTTR_SHIFT 2 +#define MPS_INTTR_MASK 3 + +#define MPS_INT(p,t) \ + ((((p) & MPS_INTPO_MASK) << MPS_INTPO_SHIFT) | \ + (((t) & MPS_INTTR_MASK) << MPS_INTTR_SHIFT)) + +/* MP Floating Pointer Structure */ +struct mpbios_fps { + u_int32_t signature; +/* string defined by the Intel MP Spec as identifying the MP table */ +#define MP_FP_SIG 0x5f504d5f /* _MP_ */ + + u_int32_t pap; + u_int8_t length; + u_int8_t spec_rev; + u_int8_t checksum; + u_int8_t mpfb1; /* system configuration */ + u_int8_t mpfb2; /* flags */ +#define MPFPS_FLAG_IMCR 0x80 /* IMCR present */ + u_int8_t mpfb3; /* unused */ + u_int8_t mpfb4; /* unused */ + u_int8_t mpfb5; /* unused */ +}; + +/* MP Configuration Table Header */ +struct mpbios_cth { + u_int32_t signature; +#define MP_CT_SIG 0x504d4350 /* PCMP */ + + u_int16_t base_len; + u_int8_t spec_rev; + u_int8_t checksum; + u_int8_t oem_id[8]; + u_int8_t product_id[12]; + u_int32_t oem_table_pointer; + u_int16_t oem_table_size; + u_int16_t entry_count; + u_int32_t apic_address; + u_int16_t ext_len; + u_int8_t ext_cksum; + u_int8_t reserved; +}; + +struct mpbios_proc { + u_int8_t type; + u_int8_t apic_id; + u_int8_t apic_version; + u_int8_t cpu_flags; +#define PROCENTRY_FLAG_EN 0x01 +#define PROCENTRY_FLAG_BP 0x02 + u_int32_t cpu_signature; + u_int32_t feature_flags; + u_int32_t reserved1; + u_int32_t reserved2; +}; + +struct mpbios_bus { + u_int8_t type; + u_int8_t bus_id; + char bus_type[6]; +}; + +struct mpbios_ioapic { + u_int8_t type; + u_int8_t apic_id; + u_int8_t apic_version; + u_int8_t apic_flags; +#define IOAPICENTRY_FLAG_EN 0x01 + u_int32_t apic_address; +}; + +struct mpbios_int { + u_int8_t type; + u_int8_t int_type; + u_int16_t int_flags; + u_int8_t src_bus_id; + u_int8_t src_bus_irq; + u_int8_t dst_apic_id; +#define MPS_ALL_APICS 0xff + u_int8_t dst_apic_int; +}; + + +#endif /* !_MACHINE_MPBIOSREG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/mpbiosvar.h b/lib/libc/include/x86_64-openbsd-none/machine/mpbiosvar.h new file mode 100644 index 0000000000..2247427b23 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/mpbiosvar.h @@ -0,0 +1,57 @@ +/* $OpenBSD: mpbiosvar.h,v 1.7 2025/09/05 16:57:48 kettenis Exp $ */ +/* $NetBSD: mpbiosvar.h,v 1.2 2003/04/02 07:53:57 thorpej Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by RedBack Networks Inc. + * + * Author: Bill Sommerfeld + * + * 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_MPBIOSVAR_H_ +#define _MACHINE_MPBIOSVAR_H_ + +#define MP_TRAMPOLINE (16 * PAGE_SIZE) +#define MP_TRAMP_DATA (17 * PAGE_SIZE) + +#if !defined(_LOCORE) + +#include +#include + +#if defined(_KERNEL) +int mpbios_probe(struct device *); + +void mpbios_intr_fixup(void); + +extern int mpbios_scanned; +#endif + +#endif + +#endif /* !_MACHINE_MPBIOSVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/mpconfig.h b/lib/libc/include/x86_64-openbsd-none/machine/mpconfig.h new file mode 100644 index 0000000000..7fc051d696 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/mpconfig.h @@ -0,0 +1,49 @@ +/* $OpenBSD: mpconfig.h,v 1.8 2011/10/21 20:48:11 kettenis Exp $ */ +/* $NetBSD: mpconfig.h,v 1.2 2003/05/11 00:05:52 fvdl Exp $ */ + +/* + * Definitions originally from the mpbios code, but now used for ACPI + * MP config as well. + */ + +#ifndef _AMD64_MPCONFIG_H +#define _AMD64_MPCONFIG_H + +#ifndef _LOCORE + +struct mpbios_int; + +struct mp_bus { + char *mb_name; /* XXX bus name */ + int mb_idx; /* XXX bus index */ + void (*mb_intr_print)(int); + void (*mb_intr_cfg)(const struct mpbios_int *, u_int32_t *); + struct mp_intr_map *mb_intrs; + u_int32_t mb_data; /* random bus-specific datum. */ +}; + +struct mp_intr_map { + struct mp_intr_map *next; + struct mp_bus *bus; + int bus_pin; + struct ioapic_softc *ioapic; + int ioapic_pin; + int ioapic_ih; /* int handle, for apic_intr_est */ + int type; /* from mp spec intr record */ + int flags; /* from mp spec intr record */ + u_int32_t redir; + int cpu_id; +}; + +#if defined(_KERNEL) +extern int mp_verbose; +extern struct mp_bus *mp_busses; +extern int mp_nbusses; +extern struct mp_intr_map *mp_intrs; +extern int mp_nintrs; +extern struct mp_bus *mp_isa_bus; +extern struct mp_bus *mp_eisa_bus; +#endif +#endif + +#endif /* _AMD64_MPCONFIG_H */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/mplock.h b/lib/libc/include/x86_64-openbsd-none/machine/mplock.h new file mode 100644 index 0000000000..d91a96332e --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/mplock.h @@ -0,0 +1,10 @@ +/* $OpenBSD: mplock.h,v 1.5 2017/10/17 14:25:35 visa Exp $ */ + +/* public domain */ + +#ifndef _MACHINE_MPLOCK_H_ +#define _MACHINE_MPLOCK_H_ + +#define __USE_MI_MPLOCK + +#endif /* !_MACHINE_MPLOCK_H */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/mutex.h b/lib/libc/include/x86_64-openbsd-none/machine/mutex.h new file mode 100644 index 0000000000..69b3361f02 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/mutex.h @@ -0,0 +1,3 @@ +/* $OpenBSD: mutex.h,v 1.11 2018/01/25 15:06:29 mpi Exp $ */ + +#define __USE_MI_MUTEX \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/param.h b/lib/libc/include/x86_64-openbsd-none/machine/param.h new file mode 100644 index 0000000000..69522312f0 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/param.h @@ -0,0 +1,81 @@ +/* $OpenBSD: param.h,v 1.30 2025/07/07 18:33:36 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 +#ifdef _LOCORE +#include +#else +#include +#endif +#endif + +#define _MACHINE amd64 +#define MACHINE "amd64" +#define _MACHINE_ARCH amd64 +#define MACHINE_ARCH "amd64" +#define MID_MACHINE MID_AMD64 + +#define PAGE_SHIFT 12 +#define PAGE_SIZE (1 << PAGE_SHIFT) +#define PAGE_MASK (PAGE_SIZE - 1) + +#define KERNBASE 0xffffffff80000000 /* start of kernel virtual space */ + +#ifdef _KERNEL + +#define KERNTEXTOFF (KERNBASE+0x1000000) /* start of kernel text */ + +#define NBPG PAGE_SIZE /* bytes/page */ +#define PGSHIFT PAGE_SHIFT /* LOG2(PAGE_SIZE) */ +#define PGOFSET PAGE_MASK /* byte offset into page */ + +#define UPAGES 6 /* pages of u-area */ +#define USPACE (UPAGES * PAGE_SIZE) /* total size of u-area */ +#define USPACE_ALIGN 0 /* u-area alignment 0-none */ +#define __HAVE_USPACE_GUARD + +#define NMBCLUSTERS (256 * 1024) /* max cluster allocation */ + +#ifndef MSGBUFSIZE +#define MSGBUFSIZE (32 * PAGE_SIZE) /* default message buffer size */ +#endif + +#define __HAVE_ACPI + +#endif /* _KERNEL */ + +#endif /* _MACHINE_PARAM_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/pcb.h b/lib/libc/include/x86_64-openbsd-none/machine/pcb.h new file mode 100644 index 0000000000..3cc195e205 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/pcb.h @@ -0,0 +1,93 @@ +/* $OpenBSD: pcb.h,v 1.17 2018/06/05 06:39:11 guenther Exp $ */ +/* $NetBSD: pcb.h,v 1.1 2003/04/26 18:39:45 fvdl Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Charles M. Hannum. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*- + * Copyright (c) 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. + * + * @(#)pcb.h 5.10 (Berkeley) 5/12/91 + */ + +#ifndef _MACHINE_PCB_H_ +#define _MACHINE_PCB_H_ + +#include + +#include + +/* + * Please note that the pcb_savefpu field in struct below must be + * on a 64-byte boundary. + */ +struct pcb { + struct savefpu pcb_savefpu; /* floating point state */ + u_int64_t pcb_cr3; + u_int64_t pcb_rsp; + u_int64_t pcb_rbp; + u_int64_t pcb_kstack; /* kernel stack address */ + u_int64_t pcb_fsbase; /* per-thread offset: %fs */ + caddr_t pcb_onfault; /* copyin/out fault recovery */ + struct pmap *pcb_pmap; /* back pointer to our pmap */ +}; + +#ifdef _KERNEL +void reset_segs(void); +#endif + +#endif /* _MACHINE_PCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/pci_machdep.h b/lib/libc/include/x86_64-openbsd-none/machine/pci_machdep.h new file mode 100644 index 0000000000..6804596ff5 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/pci_machdep.h @@ -0,0 +1,137 @@ +/* $OpenBSD: pci_machdep.h,v 1.32 2025/01/23 11:24:34 kettenis Exp $ */ +/* $NetBSD: pci_machdep.h,v 1.1 2003/02/26 21:26:11 fvdl Exp $ */ + +/* + * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. + * Copyright (c) 1994 Charles M. Hannum. 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 Charles M. Hannum. + * 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. + */ + +/* + * Machine-specific definitions for PCI autoconfiguration. + */ + +/* + * amd64-specific PCI structure and type definitions. + * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE. + */ + +extern struct bus_dma_tag pci_bus_dma_tag; + +/* + * Types provided to machine-independent PCI code + */ +typedef void *pci_chipset_tag_t; +typedef u_int32_t pcitag_t; + +typedef struct { + pcitag_t tag; + int line, pin; +} pci_intr_handle_t; + +#define pci_intr_line(pc,ih) ((ih.line) & 0xff) + +/* + * amd64-specific PCI variables and functions. + * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE. + */ +struct pci_attach_args; + +extern struct extent *pciio_ex; +extern struct extent *pcimem_ex; +extern struct extent *pcibus_ex; +void pci_init_extents(void); + +/* + * Functions provided to machine-independent PCI code. + */ +void pci_attach_hook(struct device *, struct device *, + struct pcibus_attach_args *); +int pci_bus_maxdevs(pci_chipset_tag_t, int); +pcitag_t pci_make_tag(pci_chipset_tag_t, int, int, int); +void pci_decompose_tag(pci_chipset_tag_t, pcitag_t, + int *, int *, int *); +int pci_conf_size(pci_chipset_tag_t, pcitag_t); +pcireg_t pci_conf_read(pci_chipset_tag_t, pcitag_t, int); +void pci_conf_write(pci_chipset_tag_t, pcitag_t, int, + pcireg_t); +int pci_intr_enable_msivec(struct pci_attach_args *, int); +int pci_intr_map_msi(struct pci_attach_args *, + pci_intr_handle_t *); +int pci_intr_map_msivec(struct pci_attach_args *, + int, pci_intr_handle_t *); +int pci_intr_map_msix(struct pci_attach_args *, + int, pci_intr_handle_t *); +int pci_intr_map(struct pci_attach_args *, pci_intr_handle_t *); +const char *pci_intr_string(pci_chipset_tag_t, pci_intr_handle_t); +void *pci_intr_establish(pci_chipset_tag_t, pci_intr_handle_t, + int, int (*)(void *), void *, const char *); +void *pci_intr_establish_cpu(pci_chipset_tag_t, pci_intr_handle_t, + int, struct cpu_info *, + int (*)(void *), void *, const char *); +void pci_intr_disestablish(pci_chipset_tag_t, void *); +int pci_probe_device_hook(pci_chipset_tag_t, + struct pci_attach_args *); + +void pci_dev_postattach(struct device *, struct pci_attach_args *); + +pcireg_t pci_min_powerstate(pci_chipset_tag_t, pcitag_t); +void pci_set_powerstate_md(pci_chipset_tag_t, pcitag_t, int, int); + +void pci_mcfg_init(bus_space_tag_t, bus_addr_t, int, int, int); +pci_chipset_tag_t pci_lookup_segment(int, int); + +#define __HAVE_PCI_MSIX + +int pci_msix_table_map(pci_chipset_tag_t, pcitag_t, + bus_space_tag_t, bus_space_handle_t *); +void pci_msix_table_unmap(pci_chipset_tag_t, pcitag_t, + bus_space_tag_t, bus_space_handle_t); + +/* + * ALL OF THE FOLLOWING ARE MACHINE-DEPENDENT, AND SHOULD NOT BE USED + * BY PORTABLE CODE. + */ + +/* + * Section 6.2.4, `Miscellaneous Functions' of the PCI Specification, + * says that 255 means `unknown' or `no connection' to the interrupt + * controller on a PC. + */ +#define X86_PCI_INTERRUPT_LINE_NO_CONNECTION 0xff + +/* + * PCI address space is shared with ISA, so avoid legacy ISA I/O + * registers. + */ +#define PCI_IO_START 0x400 +#define PCI_IO_END 0xffff + +/* + * Avoid the DOS Compatibility Memory area. + */ +#define PCI_MEM_START 0x100000 \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/pctr.h b/lib/libc/include/x86_64-openbsd-none/machine/pctr.h new file mode 100644 index 0000000000..53f01bdf68 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/pctr.h @@ -0,0 +1,73 @@ +/* $OpenBSD: pctr.h,v 1.7 2019/08/26 12:41:47 pirofti Exp $ */ + +/* + * Pentium performance counter driver for OpenBSD. + * Copyright 1996 David Mazieres . + * + * Modification and redistribution in source and binary forms is + * permitted provided that due credit is given to the author and the + * OpenBSD project by leaving this copyright notice intact. + */ + +#ifndef _MACHINE_PCTR_H_ +#define _MACHINE_PCTR_H_ + +#include + +typedef u_int64_t pctrval; + +#define PCTR_NUM 4 + +struct pctrst { + u_int pctr_fn[PCTR_NUM]; /* Current settings of counters */ + pctrval pctr_tsc; /* Free-running 64-bit cycle counter */ + pctrval pctr_hwc[PCTR_NUM]; /* Values of the hardware counters */ +}; + +/* Bit values in fn fields and PIOCS ioctl's */ +#define PCTR_U 0x010000 /* Monitor user-level events */ +#define PCTR_K 0x020000 /* Monitor kernel-level events */ +#define PCTR_E 0x040000 /* Edge detect */ +#define PCTR_EN 0x400000 /* Enable counters (counter 0 only) */ +#define PCTR_I 0x800000 /* Invert counter mask */ + +/* Unit Mask values to distinguish cache coherent states */ +#define PCTR_UM_M 0x0800 /* Modified cache lines */ +#define PCTR_UM_E 0x0400 /* Exclusive cache lines */ +#define PCTR_UM_S 0x0200 /* Shared cache lines */ +#define PCTR_UM_I 0x0100 /* Invalid cache lines */ +#define PCTR_UM_MESI (PCTR_UM_M|PCTR_UM_E|PCTR_UM_S|PCTR_UM_I) +#define PCTR_UM_A 0x2000 /* Any initiator */ + +#define PCTR_UM_SHIFT 8 /* Left shift for unit mask */ +#define PCTR_CM_SHIFT 24 /* Left shift for counter mask */ + +/* ioctl to set which counter a device tracks */ +#define PCIOCRD _IOR('c', 1, struct pctrst) /* Read counter value */ +#define PCIOCS0 _IOW('c', 8, unsigned int) /* Set counter 0 function */ +#define PCIOCS1 _IOW('c', 9, unsigned int) /* Set counter 1 function */ +#define PCIOCS2 _IOW('c', 10, unsigned int) /* Set counter 2 function */ +#define PCIOCS3 _IOW('c', 11, unsigned int) /* Set counter 3 function */ + +#define _PATH_PCTR "/dev/pctr" + +#define rdpmc(pmc) \ +({ \ + u_int32_t hi, lo; \ + __asm volatile("rdpmc" \ + : "=d" (hi), "=a" (lo) : "c" (pmc)); \ + hi &= 0xffffff; \ + (((u_int64_t)hi << 32) | (u_int64_t)lo); \ +}) + +#ifdef _KERNEL + +void pctrattach(int); +int pctropen(dev_t, int, int, struct proc *); +int pctrclose(dev_t, int, int, struct proc *); +int pctrioctl(dev_t, u_long, caddr_t, int, struct proc *); +void pctr_reload(struct cpu_info *); +void pctr_resume(struct cpu_info *); + +#endif /* _KERNEL */ +#endif /* ! _MACHINE_PCTR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/pic.h b/lib/libc/include/x86_64-openbsd-none/machine/pic.h new file mode 100644 index 0000000000..21acee8498 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/pic.h @@ -0,0 +1,45 @@ +/* $OpenBSD: pic.h,v 1.8 2024/01/19 18:38:16 kettenis Exp $ */ +/* $NetBSD: pic.h,v 1.1 2003/02/26 21:26:11 fvdl Exp $ */ + +#ifndef _X86_PIC_H +#define _X86_PIC_H + +#include +#include + +struct cpu_info; + +/* + * Structure common to all PIC softcs + */ +struct pic { + struct device pic_dev; + int pic_type; +#ifdef MULTIPROCESSOR + struct mutex pic_mutex; +#endif + void (*pic_hwmask)(struct pic *, int); + void (*pic_hwunmask)(struct pic *, int); + void (*pic_addroute)(struct pic *, struct cpu_info *, int, int, int); + void (*pic_delroute)(struct pic *, struct cpu_info *, int, int, int); + int (*pic_allocidtvec)(struct pic *, int, int, int); + struct intrstub *pic_level_stubs; + struct intrstub *pic_edge_stubs; +}; + +#define pic_name pic_dev.dv_xname + +/* + * PIC types. + */ +#define PIC_I8259 0 +#define PIC_IOAPIC 1 +#define PIC_LAPIC 2 +#define PIC_MSI 3 +#define PIC_SOFT 4 + +extern struct pic i8259_pic; +extern struct pic local_pic; +extern struct pic msi_pic; +extern struct pic softintr_pic; +#endif \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/pio.h b/lib/libc/include/x86_64-openbsd-none/machine/pio.h new file mode 100644 index 0000000000..f1236a3570 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/pio.h @@ -0,0 +1,225 @@ +/* $OpenBSD: pio.h,v 1.5 2015/04/25 21:31:24 guenther Exp $ */ +/* $NetBSD: pio.h,v 1.2 2003/02/27 11:22:46 fvdl Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Charles M. Hannum. + * + * 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_PIO_H_ +#define _MACHINE_PIO_H_ + +/* + * Functions to provide access to x86 programmed I/O instructions. + * + * The in[bwl]() and out[bwl]() functions are split into two varieties: one to + * use a small, constant, 8-bit port number, and another to use a large or + * variable port number. The former can be compiled as a smaller instruction. + */ + + +#ifdef __OPTIMIZE__ + +#define __use_immediate_port(port) \ + (__builtin_constant_p((port)) && (port) < 0x100) + +#else + +#define __use_immediate_port(port) 0 + +#endif + + +#define inb(port) \ + (/* CONSTCOND */ __use_immediate_port(port) ? __inbc(port) : __inb(port)) + +static __inline u_int8_t +__inbc(unsigned port) +{ + u_int8_t data; + __asm volatile("inb %w1,%0" : "=a" (data) : "id" (port)); + return data; +} + +static __inline u_int8_t +__inb(unsigned port) +{ + u_int8_t data; + __asm volatile("inb %w1,%0" : "=a" (data) : "d" (port)); + return data; +} + +static __inline void +insb(unsigned port, void *addr, int cnt) +{ + void *dummy1; + int dummy2; + __asm volatile("repne\n\tinsb" : + "=D" (dummy1), "=c" (dummy2) : + "d" (port), "0" (addr), "1" (cnt) : + "memory"); +} + +#define inw(port) \ + (/* CONSTCOND */ __use_immediate_port(port) ? __inwc(port) : __inw(port)) + +static __inline u_int16_t +__inwc(unsigned port) +{ + u_int16_t data; + __asm volatile("inw %w1,%0" : "=a" (data) : "id" (port)); + return data; +} + +static __inline u_int16_t +__inw(unsigned port) +{ + u_int16_t data; + __asm volatile("inw %w1,%0" : "=a" (data) : "d" (port)); + return data; +} + +static __inline void +insw(unsigned port, void *addr, int cnt) +{ + void *dummy1; + int dummy2; + __asm volatile("repne\n\tinsw" : + "=D" (dummy1), "=c" (dummy2) : + "d" (port), "0" (addr), "1" (cnt) : + "memory"); +} + +#define inl(port) \ + (/* CONSTCOND */ __use_immediate_port(port) ? __inlc(port) : __inl(port)) + +static __inline u_int32_t +__inlc(unsigned port) +{ + u_int32_t data; + __asm volatile("inl %w1,%0" : "=a" (data) : "id" (port)); + return data; +} + +static __inline u_int32_t +__inl(unsigned port) +{ + u_int32_t data; + __asm volatile("inl %w1,%0" : "=a" (data) : "d" (port)); + return data; +} + +static __inline void +insl(unsigned port, void *addr, int cnt) +{ + void *dummy1; + int dummy2; + __asm volatile("repne\n\tinsl" : + "=D" (dummy1), "=c" (dummy2) : + "d" (port), "0" (addr), "1" (cnt) : + "memory"); +} + +#define outb(port, data) \ + (/* CONSTCOND */__use_immediate_port(port) ? __outbc(port, data) : \ + __outb(port, data)) + +static __inline void +__outbc(unsigned port, u_int8_t data) +{ + __asm volatile("outb %0,%w1" : : "a" (data), "id" (port)); +} + +static __inline void +__outb(unsigned port, u_int8_t data) +{ + __asm volatile("outb %0,%w1" : : "a" (data), "d" (port)); +} + +static __inline void +outsb(unsigned port, const void *addr, int cnt) +{ + void *dummy1; + int dummy2; + __asm volatile("repne\n\toutsb" : + "=S" (dummy1), "=c" (dummy2) : + "d" (port), "0" (addr), "1" (cnt)); +} + +#define outw(port, data) \ + (/* CONSTCOND */ __use_immediate_port(port) ? __outwc(port, data) : \ + __outw(port, data)) + +static __inline void +__outwc(unsigned port, u_int16_t data) +{ + __asm volatile("outw %0,%w1" : : "a" (data), "id" (port)); +} + +static __inline void +__outw(unsigned port, u_int16_t data) +{ + __asm volatile("outw %0,%w1" : : "a" (data), "d" (port)); +} + +static __inline void +outsw(unsigned port, const void *addr, int cnt) +{ + void *dummy1; + int dummy2; + __asm volatile("repne\n\toutsw" : + "=S" (dummy1), "=c" (dummy2) : + "d" (port), "0" (addr), "1" (cnt)); +} + +#define outl(port, data) \ + (/* CONSTCOND */ __use_immediate_port(port) ? __outlc(port, data) : \ + __outl(port, data)) + +static __inline void +__outlc(unsigned port, u_int32_t data) +{ + __asm volatile("outl %0,%w1" : : "a" (data), "id" (port)); +} + +static __inline void +__outl(unsigned port, u_int32_t data) +{ + __asm volatile("outl %0,%w1" : : "a" (data), "d" (port)); +} + +static __inline void +outsl(unsigned port, const void *addr, int cnt) +{ + void *dummy1; + int dummy2; + __asm volatile("repne\n\toutsl" : + "=S" (dummy1), "=c" (dummy2) : + "d" (port), "0" (addr), "1" (cnt)); +} + +#endif /* _MACHINE_PIO_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/pmap.h b/lib/libc/include/x86_64-openbsd-none/machine/pmap.h new file mode 100644 index 0000000000..1b1c888978 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/pmap.h @@ -0,0 +1,524 @@ +/* $OpenBSD: pmap.h,v 1.94 2025/07/07 00:55:15 jsg Exp $ */ +/* $NetBSD: pmap.h,v 1.1 2003/04/26 18:39:46 fvdl Exp $ */ + +/* + * Copyright (c) 1997 Charles D. Cranor and Washington University. + * 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. + */ + +/* + * Copyright (c) 2001 Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Frank van der Linden for Wasabi Systems, Inc. + * + * 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 for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC + * 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. + */ + +/* + * pmap.h: see pmap.c for the history of this pmap module. + */ + +#ifndef _MACHINE_PMAP_H_ +#define _MACHINE_PMAP_H_ + +#ifndef _LOCORE +#ifdef _KERNEL +#include /* for KASSERT() */ +#include +#endif /* _KERNEL */ +#include +#include +#include +#endif + +/* + * The x86_64 pmap module closely resembles the i386 one. It uses + * the same recursive entry scheme. See the i386 pmap.h for a + * description. The alternate area trick for accessing non-current + * pmaps has been removed, though, because it performs badly on SMP + * systems. + * The most obvious difference to i386 is that 2 extra levels of page + * table need to be dealt with. The level 1 page table pages are at: + * + * l1: 0x00007f8000000000 - 0x00007fffffffffff (39 bits, needs PML4 entry) + * + * The other levels are kept as physical pages in 3 UVM objects and are + * temporarily mapped for virtual access when needed. + * + * The other obvious difference from i386 is that it has a direct map of all + * physical memory in the VA range: + * + * 0xfffffd8000000000 - 0xffffff7fffffffff + * + * The direct map is used in some cases to access PTEs of non-current pmaps. + * + * Note that address space is signed, so the layout for 48 bits is: + * + * +---------------------------------+ 0xffffffffffffffff + * | Kernel Image | + * +---------------------------------+ 0xffffff8000000000 + * | Direct Map | + * +---------------------------------+ 0xfffffd8000000000 + * ~ ~ + * | | + * | Kernel Space | + * | | + * | | + * +---------------------------------+ 0xffff800000000000 = 0x0000800000000000 + * | L1 table (PTE pages) | + * +---------------------------------+ 0x00007f8000000000 + * ~ ~ + * | | + * | User Space | + * | | + * | | + * +---------------------------------+ 0x0000000000000000 + * + * In other words, there is a 'VA hole' at 0x0000800000000000 - + * 0xffff800000000000 which will trap, just as on, for example, + * sparcv9. + * + * The unused space can be used if needed, but it adds a little more + * complexity to the calculations. + */ + +/* + * Mask to get rid of the sign-extended part of addresses. + */ +#define VA_SIGN_MASK 0xffff000000000000 +#define VA_SIGN_NEG(va) ((va) | VA_SIGN_MASK) +/* + * XXXfvdl this one's not right. + */ +#define VA_SIGN_POS(va) ((va) & ~VA_SIGN_MASK) + +#define L4_SLOT_PTE 255 +#define L4_SLOT_KERN 256 +#define L4_SLOT_KERNBASE 511 +#define NUM_L4_SLOT_DIRECT 4 +#define L4_SLOT_DIRECT (L4_SLOT_KERNBASE - NUM_L4_SLOT_DIRECT) +#define L4_SLOT_EARLY (L4_SLOT_DIRECT - 1) + +#define PDIR_SLOT_KERN L4_SLOT_KERN +#define PDIR_SLOT_PTE L4_SLOT_PTE +#define PDIR_SLOT_DIRECT L4_SLOT_DIRECT +#define PDIR_SLOT_EARLY L4_SLOT_EARLY + +/* + * the following defines give the virtual addresses of various MMU + * data structures: + * PTE_BASE: the base VA of the linear PTE mappings + * PDP_PDE: the VA of the PDE that points back to the PDP + * + */ + +#define PTE_BASE ((pt_entry_t *) (L4_SLOT_PTE * NBPD_L4)) +#define PMAP_DIRECT_BASE (VA_SIGN_NEG((L4_SLOT_DIRECT * NBPD_L4))) +#define PMAP_DIRECT_END (VA_SIGN_NEG(((L4_SLOT_DIRECT + \ + NUM_L4_SLOT_DIRECT) * NBPD_L4))) + +#define L1_BASE PTE_BASE + +#define L2_BASE ((pd_entry_t *)((char *)L1_BASE + L4_SLOT_PTE * NBPD_L3)) +#define L3_BASE ((pd_entry_t *)((char *)L2_BASE + L4_SLOT_PTE * NBPD_L2)) +#define L4_BASE ((pd_entry_t *)((char *)L3_BASE + L4_SLOT_PTE * NBPD_L1)) + +#define PDP_PDE (L4_BASE + PDIR_SLOT_PTE) + +#define PDP_BASE L4_BASE + +#define NKL4_MAX_ENTRIES (unsigned long)1 +#define NKL3_MAX_ENTRIES (unsigned long)(NKL4_MAX_ENTRIES * 512) +#define NKL2_MAX_ENTRIES (unsigned long)(NKL3_MAX_ENTRIES * 512) +#define NKL1_MAX_ENTRIES (unsigned long)(NKL2_MAX_ENTRIES * 512) + +#define NKL4_KIMG_ENTRIES 1 +#define NKL3_KIMG_ENTRIES 1 +#define NKL2_KIMG_ENTRIES 64 + +/* number of pages of direct map entries set up by locore0.S */ +#define NDML4_ENTRIES 1 +#define NDML3_ENTRIES 1 +#define NDML2_ENTRIES 4 /* 4GB */ + +/* + * Since kva space is below the kernel in its entirety, we start off + * with zero entries on each level. + */ +#define NKL4_START_ENTRIES 0 +#define NKL3_START_ENTRIES 0 +#define NKL2_START_ENTRIES 0 +#define NKL1_START_ENTRIES 0 /* XXX */ + +#define NTOPLEVEL_PDES (PAGE_SIZE / (sizeof (pd_entry_t))) + +#define NPDPG (PAGE_SIZE / sizeof (pd_entry_t)) + +/* + * pl*_pi: index in the ptp page for a pde mapping a VA. + * (pl*_i below is the index in the virtual array of all pdes per level) + */ +#define pl1_pi(VA) (((VA_SIGN_POS(VA)) & L1_MASK) >> L1_SHIFT) +#define pl2_pi(VA) (((VA_SIGN_POS(VA)) & L2_MASK) >> L2_SHIFT) +#define pl3_pi(VA) (((VA_SIGN_POS(VA)) & L3_MASK) >> L3_SHIFT) +#define pl4_pi(VA) (((VA_SIGN_POS(VA)) & L4_MASK) >> L4_SHIFT) + +/* + * pl*_i: generate index into pde/pte arrays in virtual space + */ +#define pl1_i(VA) (((VA_SIGN_POS(VA)) & L1_FRAME) >> L1_SHIFT) +#define pl2_i(VA) (((VA_SIGN_POS(VA)) & L2_FRAME) >> L2_SHIFT) +#define pl3_i(VA) (((VA_SIGN_POS(VA)) & L3_FRAME) >> L3_SHIFT) +#define pl4_i(VA) (((VA_SIGN_POS(VA)) & L4_FRAME) >> L4_SHIFT) +#define pl_i(va, lvl) \ + (((VA_SIGN_POS(va)) & ptp_masks[(lvl)-1]) >> ptp_shifts[(lvl)-1]) + +#define PTP_MASK_INITIALIZER { L1_FRAME, L2_FRAME, L3_FRAME, L4_FRAME } +#define PTP_SHIFT_INITIALIZER { L1_SHIFT, L2_SHIFT, L3_SHIFT, L4_SHIFT } +#define NKPTP_INITIALIZER { NKL1_START_ENTRIES, NKL2_START_ENTRIES, \ + NKL3_START_ENTRIES, NKL4_START_ENTRIES } +#define NKPTPMAX_INITIALIZER { NKL1_MAX_ENTRIES, NKL2_MAX_ENTRIES, \ + NKL3_MAX_ENTRIES, NKL4_MAX_ENTRIES } +#define NBPD_INITIALIZER { NBPD_L1, NBPD_L2, NBPD_L3, NBPD_L4 } +#define PDES_INITIALIZER { L2_BASE, L3_BASE, L4_BASE } + +/* + * PTP macros: + * a PTP's index is the PD index of the PDE that points to it + * a PTP's offset is the byte-offset in the PTE space that this PTP is at + * a PTP's VA is the first VA mapped by that PTP + */ + +#define ptp_va2o(va, lvl) (pl_i(va, (lvl)+1) * PAGE_SIZE) + +#define PTP_LEVELS 4 + +/* + * PG_AVAIL usage: we make use of the ignored bits of the PTE + */ + +#define PG_W PG_AVAIL1 /* "wired" mapping */ +#define PG_PVLIST PG_AVAIL2 /* mapping has entry on pvlist */ +/* PG_AVAIL3 not used */ + +/* + * PCID assignments. + * The shootdown code assumes KERN, PROC, and PROC_INTEL are both + * consecutive and in that order. + */ +#define PCID_KERN 0 /* for pmap_kernel() */ +#define PCID_PROC 1 /* non-pmap_kernel(), U+K */ +#define PCID_PROC_INTEL 2 /* non-pmap_kernel(), U-K (meltdown) */ +#define PCID_TEMP 3 /* temp mapping of another non-pmap_kernel() */ +#define PCID_EFI 4 /* EFI runtime services */ + +extern int pmap_use_pcid; /* non-zero if PCID support is enabled */ + +/* + * Number of PTEs per cache line. 8 byte pte, 64-byte cache line + * Used to avoid false sharing of cache lines. + */ +#define NPTECL 8 + + +#if defined(_KERNEL) && !defined(_LOCORE) +/* + * pmap data structures: see pmap.c for details of locking. + */ + +struct pmap; +typedef struct pmap *pmap_t; + +/* + * we maintain a list of all non-kernel pmaps + */ + +LIST_HEAD(pmap_head, pmap); /* struct pmap_head: head of a pmap list */ + +/* + * the pmap structure + * + * note that the pm_obj contains the reference count, + * page list, and number of PTPs within the pmap. + */ + +#define PMAP_TYPE_NORMAL 1 +#define PMAP_TYPE_EPT 2 +#define PMAP_TYPE_RVI 3 +#define pmap_nested(pm) ((pm)->pm_type != PMAP_TYPE_NORMAL) +#define pmap_is_ept(pm) ((pm)->pm_type == PMAP_TYPE_EPT) + +struct pmap { + struct mutex pm_mtx; + struct uvm_object pm_obj[PTP_LEVELS-1]; /* objects for lvl >= 1) */ + LIST_ENTRY(pmap) pm_list; /* list (lck by pm_list lock) */ + /* + * pm_pdir : VA of page table to be used when executing in + * privileged mode + * pm_pdirpa : PA of page table to be used when executing in + * privileged mode + * pm_pdir_intel : VA of special page table to be used when executing + * on an Intel CPU in usermode (no kernel mappings) + * pm_pdirpa_intel : PA of special page table to be used when executing + * on an Intel CPU in usermode (no kernel mappings) + */ + pd_entry_t *pm_pdir, *pm_pdir_intel; + paddr_t pm_pdirpa, pm_pdirpa_intel; + + struct vm_page *pm_ptphint[PTP_LEVELS-1]; + /* pointer to a PTP in our pmap */ + struct pmap_statistics pm_stats; /* pmap stats (lck by object lock) */ + + int pm_type; /* Type of pmap this is (PMAP_TYPE_x) */ + uint64_t eptp; /* cached EPTP (used by vmm) */ +}; + +#define PMAP_EFI PMAP_MD0 +#define PMAP_NOCRYPT PMAP_MD1 + +/* + * MD flags that we use for pmap_enter (in the pa): + */ +#define PMAP_PA_MASK ~((paddr_t)PAGE_MASK) /* to remove the flags */ +#define PMAP_NOCACHE 0x1 /* set the non-cacheable bit. */ +#define PMAP_WC 0x2 /* set page write combining. */ + +/* + * We keep mod/ref flags in struct vm_page->pg_flags. + */ +#define PG_PMAP_MOD PG_PMAP0 +#define PG_PMAP_REF PG_PMAP1 +#define PG_PMAP_WC PG_PMAP2 + +/* + * for each managed physical page we maintain a list of 's + * which it is mapped at. + */ +struct pv_entry { /* locked by its list's pvh_lock */ + struct pv_entry *pv_next; /* next entry */ + struct pmap *pv_pmap; /* the pmap */ + vaddr_t pv_va; /* the virtual address */ + struct vm_page *pv_ptp; /* the vm_page of the PTP */ +}; + +/* + * global kernel variables + */ + +extern struct pmap kernel_pmap_store; /* kernel pmap */ + +extern long nkptp[]; + +extern const paddr_t ptp_masks[]; +extern const int ptp_shifts[]; +extern const long nbpd[], nkptpmax[]; + +/* + * macros + */ + +#define pmap_kernel() (&kernel_pmap_store) +#define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count) +#define pmap_wired_count(pmap) ((pmap)->pm_stats.wired_count) +#define pmap_update(pmap) /* nothing (yet) */ + +#define pmap_clear_modify(pg) pmap_clear_attrs(pg, PG_M) +#define pmap_clear_reference(pg) pmap_clear_attrs(pg, PG_U) +#define pmap_is_modified(pg) pmap_test_attrs(pg, PG_M) +#define pmap_is_referenced(pg) pmap_test_attrs(pg, PG_U) +#define pmap_valid_entry(E) ((E) & PG_V) /* is PDE or PTE valid? */ + +#define pmap_proc_iflush(p,va,len) /* nothing */ +#define pmap_unuse_final(p) /* nothing */ +#define pmap_remove_holes(vm) do { /* nothing */ } while (0) + + +/* + * prototypes + */ + +void map_tramps(void); /* machdep.c */ +paddr_t pmap_bootstrap(paddr_t, paddr_t); +void pmap_init_percpu(void); +void pmap_randomize(void); +void pmap_randomize_level(pd_entry_t *, int); +int pmap_clear_attrs(struct vm_page *, unsigned long); +static void pmap_page_protect(struct vm_page *, vm_prot_t); +void pmap_page_remove (struct vm_page *); +static void pmap_protect(struct pmap *, vaddr_t, + vaddr_t, vm_prot_t); +void pmap_remove(struct pmap *, vaddr_t, vaddr_t); +int pmap_test_attrs(struct vm_page *, unsigned); +static void pmap_update_pg(vaddr_t); +void pmap_write_protect(struct pmap *, vaddr_t, + vaddr_t, vm_prot_t); + +paddr_t pmap_prealloc_lowmem_ptps(paddr_t); + +void pagezero(vaddr_t); + +void pmap_convert(struct pmap *, int); +void pmap_enter_special(vaddr_t, paddr_t, vm_prot_t); +vaddr_t pmap_set_pml4_early(paddr_t pa); +void pmap_clear_pml4_early(void); + +/* + * functions for flushing the cache for vaddrs and pages. + * these functions are not part of the MI pmap interface and thus + * should not be used as such. + */ +void pmap_flush_cache(vaddr_t, vsize_t); +#define pmap_flush_page(paddr) do { \ + KDASSERT(PHYS_TO_VM_PAGE(paddr) != NULL); \ + pmap_flush_cache(PMAP_DIRECT_MAP(paddr), PAGE_SIZE); \ +} while (/* CONSTCOND */ 0) + +#define PMAP_CHECK_COPYIN (pg_xo == 0) + +#define PMAP_STEAL_MEMORY /* enable pmap_steal_memory() */ +#define PMAP_GROWKERNEL /* turn on pmap_growkernel interface */ + +/* + * inline functions + */ + +/* + * pmap_update_pg: flush one page from the TLB (or flush the whole thing + * if hardware doesn't support one-page flushing) + */ + +static inline void +pmap_update_pg(vaddr_t va) +{ + invlpg(va); +} + +/* + * pmap_page_protect: change the protection of all recorded mappings + * of a managed page + * + * => this function is a frontend for pmap_page_remove/pmap_clear_attrs + * => we only have to worry about making the page more protected. + * unprotecting a page is done on-demand at fault time. + */ + +static inline void +pmap_page_protect(struct vm_page *pg, vm_prot_t prot) +{ + if (prot == PROT_READ) { + (void) pmap_clear_attrs(pg, PG_RW); + } else { + KASSERT(prot == PROT_NONE); + pmap_page_remove(pg); + } +} + +/* + * pmap_protect: change the protection of pages in a pmap + * + * => this function is a frontend for pmap_remove/pmap_write_protect + * => we only have to worry about making the page more protected. + * unprotecting a page is done on-demand at fault time. + */ + +static inline void +pmap_protect(struct pmap *pmap, vaddr_t sva, vaddr_t eva, vm_prot_t prot) +{ + if (prot != PROT_NONE) { + pmap_write_protect(pmap, sva, eva, prot); + } else { + pmap_remove(pmap, sva, eva); + } +} + +/* + * kvtopte: return a pointer to the PTE mapping a kernel VA + */ + +static inline pt_entry_t * +kvtopte(vaddr_t va) +{ +#ifdef LARGEPAGES + { + pd_entry_t *pde; + + pde = L1_BASE + pl2_i(va); + if (*pde & PG_PS) + return ((pt_entry_t *)pde); + } +#endif + + return (PTE_BASE + pl1_i(va)); +} + +#define PMAP_DIRECT_MAP(pa) ((vaddr_t)PMAP_DIRECT_BASE + (pa)) +#define PMAP_DIRECT_UNMAP(va) ((paddr_t)(va) - PMAP_DIRECT_BASE) +#define pmap_map_direct(pg) PMAP_DIRECT_MAP(VM_PAGE_TO_PHYS(pg)) +#define pmap_unmap_direct(va) PHYS_TO_VM_PAGE(PMAP_DIRECT_UNMAP(va)) + +#define __HAVE_PMAP_DIRECT +#define __HAVE_PMAP_MPSAFE_ENTER_COW + +#endif /* _KERNEL && !_LOCORE */ + +#ifndef _LOCORE +struct pv_entry; +struct vm_page_md { + struct mutex pv_mtx; + struct pv_entry *pv_list; +}; + +#define VM_MDPAGE_INIT(pg) do { \ + mtx_init(&(pg)->mdpage.pv_mtx, IPL_VM); \ + (pg)->mdpage.pv_list = NULL; \ +} while (0) +#endif /* !_LOCORE */ + +#endif /* _MACHINE_PMAP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/proc.h b/lib/libc/include/x86_64-openbsd-none/machine/proc.h new file mode 100644 index 0000000000..f365bebe6b --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/proc.h @@ -0,0 +1,52 @@ +/* $OpenBSD: proc.h,v 1.10 2018/06/05 06:39:11 guenther Exp $ */ +/* $NetBSD: proc.h,v 1.1 2003/04/26 18:39:46 fvdl 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 amd64. + */ +struct trapframe; +struct mdproc { + struct trapframe *md_regs; /* registers on current frame */ + int md_flags; + volatile int md_astpending; +}; + +/* md_flags */ +#define MDP_IRET 0x0002 /* return via iret, not sysret */ + /* (iret can restore r11 and rcx) */ + +#endif /* _MACHINE_PROC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/profile.h b/lib/libc/include/x86_64-openbsd-none/machine/profile.h new file mode 100644 index 0000000000..04fc7ace48 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/profile.h @@ -0,0 +1,77 @@ +/* $OpenBSD: profile.h,v 1.6 2023/06/27 10:11:15 cheloha Exp $ */ +/* $NetBSD: profile.h,v 1.3 2003/11/28 23:22:45 fvdl Exp $ */ + +/* + * Copyright (c) 1992, 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. + * + * @(#)profile.h 8.1 (Berkeley) 6/11/93 + */ + +#define _MCOUNT_DECL void _mcount + +#ifdef __PIC__ +#define __MCPLT "@PLT" +#else +#define __MCPLT +#endif + +#define MCOUNT \ +__asm(" .globl __mcount \n" \ +" .type __mcount,@function\n" \ +"__mcount: \n" \ +" pushq %rbp \n" \ +" movq %rsp,%rbp \n" \ +" subq $56,%rsp \n" \ +" movq %rdi,0(%rsp) \n" \ +" movq %rsi,8(%rsp) \n" \ +" movq %rdx,16(%rsp) \n" \ +" movq %rcx,24(%rsp) \n" \ +" movq %r8,32(%rsp) \n" \ +" movq %r9,40(%rsp) \n" \ +" movq %rax,48(%rsp) \n" \ +" movq 0(%rbp),%r11 \n" \ +" movq 8(%r11),%rdi \n" \ +" movq 8(%rbp),%rsi \n" \ +" call _mcount"__MCPLT"\n" \ +" movq 0(%rsp),%rdi \n" \ +" movq 8(%rsp),%rsi \n" \ +" movq 16(%rsp),%rdx \n" \ +" movq 24(%rsp),%rcx \n" \ +" movq 32(%rsp),%r8 \n" \ +" movq 40(%rsp),%r9 \n" \ +" movq 48(%rsp),%rax \n" \ +" leave \n" \ +" ret \n" \ +" lfence \n" \ +" .size __mcount,.-__mcount"); + + +#ifdef _KERNEL +#define MCOUNT_ENTER s = intr_disable() +#define MCOUNT_EXIT intr_restore(s) +#endif /* _KERNEL */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/psl.h b/lib/libc/include/x86_64-openbsd-none/machine/psl.h new file mode 100644 index 0000000000..2fa183244f --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/psl.h @@ -0,0 +1,76 @@ +/* $OpenBSD: psl.h,v 1.5 2018/07/09 19:20:29 guenther Exp $ */ +/* $NetBSD: psl.h,v 1.1 2003/02/26 21:26:11 fvdl 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. + * + * @(#)psl.h 5.2 (Berkeley) 1/18/91 + */ + +#ifndef _MACHINE_PSL_H_ +#define _MACHINE_PSL_H_ + +/* + * 386 processor status longword. + */ +#define PSL_C 0x00000001 /* carry flag */ +#define PSL_PF 0x00000004 /* parity flag */ +#define PSL_AF 0x00000010 /* auxiliary carry flag */ +#define PSL_Z 0x00000040 /* zero flag */ +#define PSL_N 0x00000080 /* sign flag */ +#define PSL_T 0x00000100 /* trap flag */ +#define PSL_I 0x00000200 /* interrupt enable flag */ +#define PSL_D 0x00000400 /* direction flag */ +#define PSL_V 0x00000800 /* overflow flag */ +#define PSL_IOPL 0x00003000 /* i/o privilege level */ +#define PSL_NT 0x00004000 /* nested task */ +#define PSL_RF 0x00010000 /* resume flag */ +#define PSL_VM 0x00020000 /* virtual 8086 mode */ +#define PSL_AC 0x00040000 /* alignment check flag */ +#define PSL_VIF 0x00080000 /* virtual interrupt enable flag */ +#define PSL_VIP 0x00100000 /* virtual interrupt pending flag */ +#define PSL_ID 0x00200000 /* identification flag */ + +#define PSL_MBO 0x00000002 /* must be one bits */ +#define PSL_MBZ 0xffc08028 /* must be zero bits */ + +#define PSL_USERSET (PSL_MBO | PSL_I) +#define PSL_USERSTATIC (PSL_MBO | PSL_MBZ | PSL_I | PSL_IOPL | PSL_NT | PSL_VM | PSL_VIF | PSL_VIP) +#define PSL_USER (PSL_C | PSL_MBO | PSL_PF | PSL_AF | PSL_Z | PSL_N | PSL_V) + +/* + * ??? + */ +#ifdef _KERNEL +#include +#endif + +#endif /* !_MACHINE_PSL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/pte.h b/lib/libc/include/x86_64-openbsd-none/machine/pte.h new file mode 100644 index 0000000000..c91bf8cea9 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/pte.h @@ -0,0 +1,171 @@ +/* $OpenBSD: pte.h,v 1.18 2024/07/09 19:11:06 bluhm Exp $ */ +/* $NetBSD: pte.h,v 1.1 2003/04/26 18:39:47 fvdl Exp $ */ + +/* + * Copyright (c) 2001 Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Frank van der Linden for Wasabi Systems, Inc. + * + * 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 for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC + * 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_PTE_H_ +#define _MACHINE_PTE_H_ + +/* + * amd64 MMU hardware structure: + * + * the (first generation) amd64 MMU is a 4-level MMU which maps 2^48 bytes + * of virtual memory. The pagesize we use is 4K (4096 [0x1000] bytes), + * although 2M and 4M can be used as well. The indexes in the levels + * are 9 bits wide (512 64bit entries per level), dividing the bits + * 9-9-9-9-12. + * + * The top level table, called PML4, contains 512 64bit entries pointing + * to 3rd level table. The 3rd level table is called the 'page directory + * pointers directory' and has 512 entries pointing to page directories. + * The 2nd level is the page directory, containing 512 pointers to + * page table pages. Lastly, level 1 consists of pages containing 512 + * PTEs. + * + * Simply put, levels 4-1 all consist of pages containing 512 + * entries pointing to the next level. Level 0 is the actual PTEs + * themselves. + * + * For a description on the other bits, which are i386 compatible, + * see the i386 pte.h + */ + +#if !defined(_LOCORE) + +/* + * here we define the data types for PDEs and PTEs + */ + +typedef u_int64_t pd_entry_t; /* PDE */ +typedef u_int64_t pt_entry_t; /* PTE */ + +#endif + +/* + * now we define various for playing with virtual addresses + */ + +#define L1_SHIFT 12 +#define L2_SHIFT 21 +#define L3_SHIFT 30 +#define L4_SHIFT 39 +#define NBPD_L1 (1ULL << L1_SHIFT) /* # bytes mapped by L1 ent (4K) */ +#define NBPD_L2 (1ULL << L2_SHIFT) /* # bytes mapped by L2 ent (2MB) */ +#define NBPD_L3 (1ULL << L3_SHIFT) /* # bytes mapped by L3 ent (1G) */ +#define NBPD_L4 (1ULL << L4_SHIFT) /* # bytes mapped by L4 ent (512G) */ + +#define L4_MASK 0x0000ff8000000000UL +#define L3_MASK 0x0000007fc0000000UL +#define L2_MASK 0x000000003fe00000UL +#define L1_MASK 0x00000000001ff000UL + +#define L4_FRAME L4_MASK +#define L3_FRAME (L4_FRAME|L3_MASK) +#define L2_FRAME (L3_FRAME|L2_MASK) +#define L1_FRAME (L2_FRAME|L1_MASK) + +#define PAGE_MASK_L2 (NBPD_L2 - 1) + +#define x86_round_pdr(x) \ + ((((unsigned long)(x)) + (NBPD_L2 - 1)) & ~(NBPD_L2 - 1)) + +/* + * PDE/PTE bits. These are no different from their i386 counterparts. + */ + +#define PG_V 0x0000000000000001UL /* valid */ +#define PG_RO 0x0000000000000000UL /* read-only */ +#define PG_RW 0x0000000000000002UL /* read-write */ +#define PG_u 0x0000000000000004UL /* user accessible */ +#define PG_PROT 0x0000000000000006UL +#define PG_WT 0x0000000000000008UL /* write through */ +#define PG_N 0x0000000000000010UL /* non-cacheable */ +#define PG_U 0x0000000000000020UL /* used */ +#define PG_M 0x0000000000000040UL /* modified */ +#define PG_PAT 0x0000000000000080UL /* PAT bit. (on pte) */ +#define PG_PS 0x0000000000000080UL /* 2MB page size (on pde) */ +#define PG_G 0x0000000000000100UL /* not flushed */ +#define PG_AVAIL1 0x0000000000000200UL +#define PG_AVAIL2 0x0000000000000400UL +#define PG_AVAIL3 0x0000000000000800UL +#define PG_PATLG 0x0000000000001000UL /* PAT on large pages */ +#define PG_PKMASK 0x7800000000000000UL /* Protection Key Mask */ +#define PG_XO 0x0800000000000000UL /* key1 used for execute-only */ +#define PG_NX 0x8000000000000000UL /* non-executable */ +#define PG_FRAME 0x000ffffffffff000UL + +#define PG_LGFRAME 0x000fffffffe00000UL /* large (2M) page frame mask */ + +#define PGK_VALUE 0xfffffffc /* key0 is normal */ + +/* EPT PTE bits */ +#define EPT_R (1ULL << 0) +#define EPT_W (1ULL << 1) +#define EPT_X (1ULL << 2) +#define EPT_WB (6ULL << 3) +#define EPT_PS (1ULL << 7) + +/* Cacheability bits when we are using PAT */ +#define PG_WB (0) /* The default */ +#define PG_WC (PG_WT) /* WT and CD is WC */ +#define PG_UCMINUS (PG_N) /* UC but mtrr can override */ +#define PG_UC (PG_WT | PG_N) /* hard UC */ + +/* + * short forms of protection codes + */ + +#define PG_KR 0x0000000000000000UL /* kernel read-only */ +#define PG_KW 0x0000000000000002UL /* kernel read-write */ + +/* + * page protection exception bits + */ + +#define PGEX_P 0x01 /* protection violation (vs. no mapping) */ +#define PGEX_W 0x02 /* exception during a write cycle */ +#define PGEX_U 0x04 /* exception while in user mode (upl) */ +#define PGEX_I 0x10 /* instruction fetch blocked by NX */ +#define PGEX_PK 0x20 /* protection-key violation */ + +#ifdef _KERNEL +extern pt_entry_t pg_xo; /* XO pte bits using PKU key1 */ +extern pt_entry_t pg_nx; /* NX pte bit */ +extern pt_entry_t pg_crypt; /* C pte bit */ +extern pt_entry_t pg_g_kern; /* PG_G if glbl mappings can be used in kern */ +#endif /* _KERNEL */ + +#endif /* _MACHINE_PTE_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/ptrace.h b/lib/libc/include/x86_64-openbsd-none/machine/ptrace.h new file mode 100644 index 0000000000..7a0450c88f --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/ptrace.h @@ -0,0 +1,56 @@ +/* $OpenBSD: ptrace.h,v 1.2 2024/11/27 05:25:57 anton Exp $ */ +/* $NetBSD: ptrace.h,v 1.1 2003/04/26 18:39:47 fvdl 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. + */ + +/* + * i386-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) + +#define PT_GETXSTATE_INFO (PT_FIRSTMACH + 5) +#define PT_GETXSTATE (PT_FIRSTMACH + 6) +#define PT_SETXSTATE (PT_FIRSTMACH + 7) + +struct ptrace_xstate_info { + uint64_t xsave_mask; + uint32_t xsave_len; +}; + +#ifdef _KERNEL +int process_read_xstate_info(struct proc *, void *); +int process_read_xstate(struct proc *, void *); +int process_write_xstate(struct proc *, void *); +#endif \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/rbus_machdep.h b/lib/libc/include/x86_64-openbsd-none/machine/rbus_machdep.h new file mode 100644 index 0000000000..6c293739bc --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/rbus_machdep.h @@ -0,0 +1,48 @@ +/* $OpenBSD: rbus_machdep.h,v 1.8 2024/05/22 05:51:49 jsg Exp $ */ +/* $NetBSD: rbus_machdep.h,v 1.2 1999/10/15 06:43:05 haya Exp $ */ + +/* + * Copyright (c) 1999 + * HAYAKAWA Koichi. 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_RBUS_MACHDEP_H_ +#define _MACHINE_RBUS_MACHDEP_H_ + +struct pci_attach_args; /* XXX */ + +#define md_space_map(rbt, physaddr, size, flags, bshp) \ + _bus_space_map((rbt)->rb_bt, (physaddr), (size), (flags), (bshp)) + +#define md_space_unmap(rbt, bsh, size, adrp) \ + _bus_space_unmap((rbt)->rb_bt, (bsh), (size), (adrp)) + +rbus_tag_t rbus_pccbb_parent_io(struct device *, + struct pci_attach_args *); +rbus_tag_t rbus_pccbb_parent_mem(struct device *, + struct pci_attach_args *); + +void pccbb_attach_hook(struct device *, struct device *, + struct pci_attach_args *); + +#endif /* _MACHINE_RBUS_MACHDEP_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/reg.h b/lib/libc/include/x86_64-openbsd-none/machine/reg.h new file mode 100644 index 0000000000..de1804e194 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/reg.h @@ -0,0 +1,125 @@ +/* $OpenBSD: reg.h,v 1.7 2019/07/14 05:08:26 guenther Exp $ */ +/* $NetBSD: reg.h,v 1.1 2003/04/26 18:39:47 fvdl 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 _MACHINE_REG_H_ +#define _MACHINE_REG_H_ + +#include + +/* + * XXX + * The #defines aren't used in the kernel, but some user-level code still + * expects them. + */ + +/* When referenced during a trap/exception, registers are at these offsets */ + +#define tRDI 0 +#define tRSI 1 +#define tRDX 2 +#define tRCX 3 +#define tR8 4 +#define tR9 5 +#define tR10 6 +#define tR11 7 +#define tR12 8 +#define tR13 9 +#define tR14 10 +#define tR15 11 +#define tRBP 12 +#define tRBX 13 +#define tRAX 14 +#define tRSP 15 +#define tRIP 16 +#define tRFLAGS 17 +#define tCS 18 +#define tSS 19 +#define tDS 20 +#define tES 21 +#define tFS 22 +#define tGS 23 + +/* + * Registers accessible to ptrace(2) syscall for debugger use. + */ +struct reg { + int64_t r_rdi; + int64_t r_rsi; + int64_t r_rdx; + int64_t r_rcx; + int64_t r_r8; + int64_t r_r9; + int64_t r_r10; + int64_t r_r11; + int64_t r_r12; + int64_t r_r13; + int64_t r_r14; + int64_t r_r15; + int64_t r_rbp; + int64_t r_rbx; + int64_t r_rax; + int64_t r_rsp; + int64_t r_rip; + int64_t r_rflags; + int64_t r_cs; + int64_t r_ss; + int64_t r_ds; + int64_t r_es; + int64_t r_fs; + int64_t r_gs; +}; + +struct fpreg { + struct fxsave64 fxstate; +}; + +#define fp_fcw fxstate.fx_fcw +#define fp_fsw fxstate.fx_fsw +#define fp_ftw fxstate.fx_ftw +#define fp_fop fxstate.fx_fop +#define fp_rip fxstate.fx_rip +#define fp_rdp fxstate.fx_rdp +#define fp_mxcsr fxstate.fx_mxcsr +#define fp_mxcsr_mask fxstate.fx_mxcsr_mask +#define fp_st fxstate.fx_st +#define fp_xmm fxstate.fx_xmm + +#ifdef _KERNEL +int check_context(const struct reg *, struct trapframe *); +#endif + +#endif /* !_MACHINE_REG_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/reloc.h b/lib/libc/include/x86_64-openbsd-none/machine/reloc.h new file mode 100644 index 0000000000..b83e6d0571 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/reloc.h @@ -0,0 +1,69 @@ +/* $OpenBSD: reloc.h,v 1.4 2018/10/20 11:56:31 kettenis Exp $ */ + +/* + * Copyright (c) 2002,2003 Dale Rahn + * + * 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_RELOC_H_ +#define _MACHINE_RELOC_H_ + +#define R_TYPE(X) __CONCAT(R_X86_64_,X) + +#define R_X86_64_NONE 0 +#define R_X86_64_64 1 +#define R_X86_64_PC32 2 +#define R_X86_64_GOT32 3 +#define R_X86_64_PLT32 4 +#define R_X86_64_COPY 5 +#define R_X86_64_GLOB_DAT 6 +#define R_X86_64_JUMP_SLOT 7 +#define R_X86_64_RELATIVE 8 +#define R_X86_64_GOTPCREL 9 +#define R_X86_64_32 10 +#define R_X86_64_32S 11 +#define R_X86_64_16 12 +#define R_X86_64_PC16 13 +#define R_X86_64_8 14 +#define R_X86_64_PC8 15 +#define R_X86_64_DTPMOD64 16 +#define R_X86_64_DTPOFF64 17 +#define R_X86_64_TPOFF64 18 +#define R_X86_64_TLSGD 19 +#define R_X86_64_TLSLD 20 +#define R_X86_64_DTPOFF32 21 +#define R_X86_64_GOTTPOFF 22 +#define R_X86_64_TPOFF32 23 + +#define R_386_NONE 0 +#define R_386_32 1 +#define R_386_PC32 2 +#define R_386_GOT32 3 +#define R_386_PLT32 4 +#define R_386_COPY 5 +#define R_386_GLOB_DAT 6 +#define R_386_JMP_SLOT 7 +#define R_386_RELATIVE 8 +#define R_386_GOTOFF 9 +#define R_386_GOTPC 10 + +#endif /* _MACHINE_RELOC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/segments.h b/lib/libc/include/x86_64-openbsd-none/machine/segments.h new file mode 100644 index 0000000000..8bf2140313 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/segments.h @@ -0,0 +1,279 @@ +/* $OpenBSD: segments.h,v 1.18 2025/06/27 17:23:49 bluhm Exp $ */ +/* $NetBSD: segments.h,v 1.1 2003/04/26 18:39:47 fvdl Exp $ */ + +/*- + * Copyright (c) 1995, 1997 + * Charles M. Hannum. All rights reserved. + * Copyright (c) 1989, 1990 William F. Jolitz + * 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. + * + * @(#)segments.h 7.1 (Berkeley) 5/9/91 + */ + +/* + * Adapted for NetBSD/amd64 by fvdl@wasabisystems.com. + */ + +/* + * 386 Segmentation Data Structures and definitions + * William F. Jolitz (william@ernie.berkeley.edu) 6/20/1989 + */ + +#ifndef _MACHINE_SEGMENTS_H_ +#define _MACHINE_SEGMENTS_H_ + +/* + * Selectors + */ + +#define ISPL(s) ((s) & SEL_RPL) /* what is the priority level of a selector */ +#define SEL_KPL 0 /* kernel privilege level */ +#define SEL_UPL 3 /* user privilege level */ +#define SEL_RPL 3 /* requester's privilege level mask */ +#define ISLDT(s) ((s) & SEL_LDT) /* is it local or global */ +#define SEL_LDT 4 /* local descriptor table */ + +#define SYSSEL_START (NGDT_MEM << 3) +#define GDT_SIZE (SYSSEL_START + (NGDT_SYS << 4)) + +/* + * These define the index not from the start of the GDT, but from + * the part of the GDT that they're allocated from. + * First NGDT_MEM entries are 8-byte descriptors for CS and DS. + * Next NGDT_SYS entries are 16-byte descriptors defining TSSs. + */ + +#define IDXSEL(s) (((s) >> 3) & 0x1fff) +#define IDXDYNSEL(s) ((((s) & ~SEL_RPL) - DYNSEL_START) >> 4) + +#define GSEL(s,r) (((s) << 3) | r) +#define GSYSSEL(s,r) ((((s) << 4) + SYSSEL_START) | r) +#define GDYNSEL(s,r) ((((s) << 4) + DYNSEL_START) | r | SEL_KPL) + +#define LSEL(s,r) ((s) | r | SEL_LDT) + +#define USERMODE(c, f) (ISPL(c) == SEL_UPL) +#define KERNELMODE(c, f) (ISPL(c) == SEL_KPL) + +#ifndef _LOCORE + +/* + * Memory and System segment descriptors + */ + +/* + * Below is used for TSS and LDT. + */ +struct sys_segment_descriptor { + u_int64_t sd_lolimit:16; /* segment extent (lsb) */ + u_int64_t sd_lobase:24; /* segment base address (lsb) */ + u_int64_t sd_type:5; /* segment type */ + u_int64_t sd_dpl:2; /* segment descriptor priority level */ + u_int64_t sd_p:1; /* segment descriptor present */ + u_int64_t sd_hilimit:4; /* segment extent (msb) */ + u_int64_t sd_xx1:3; /* avl, long and def32 (not used) */ + u_int64_t sd_gran:1; /* limit granularity (byte/page) */ + u_int64_t sd_hibase:40; /* segment base address (msb) */ + u_int64_t sd_xx2:8; /* reserved */ + u_int64_t sd_zero:5; /* must be zero */ + u_int64_t sd_xx3:19; /* reserved */ +} __packed; + +/* + * Below is used for cs, ds, etc. + */ +struct mem_segment_descriptor { + unsigned int sd_lolimit:16; /* segment extent (lsb) */ + unsigned int sd_lobase:24; /* segment base address (lsb) */ + unsigned int sd_type:5; /* segment type */ + unsigned int sd_dpl:2; /* segment descriptor priority level */ + unsigned int sd_p:1; /* segment descriptor present */ + unsigned int sd_hilimit:4; /* segment extent (msb) */ + unsigned int sd_avl:1; /* available */ + unsigned int sd_long:1; /* long mode */ + unsigned int sd_def32:1; /* default 32 vs 16 bit size */ + unsigned int sd_gran:1; /* limit granularity (byte/page) */ + unsigned int sd_hibase:8; /* segment base address (msb) */ +} __packed; + +/* + * Gate descriptors (e.g. indirect descriptors) + */ +struct gate_descriptor { + u_int64_t gd_looffset:16; /* gate offset (lsb) */ + u_int64_t gd_selector:16; /* gate segment selector */ + u_int64_t gd_ist:3; /* IST select */ + u_int64_t gd_xx1:5; /* reserved */ + u_int64_t gd_type:5; /* segment type */ + u_int64_t gd_dpl:2; /* segment descriptor priority level */ + u_int64_t gd_p:1; /* segment descriptor present */ + u_int64_t gd_hioffset:48; /* gate offset (msb) */ + u_int64_t gd_xx2:8; /* reserved */ + u_int64_t gd_zero:5; /* must be zero */ + u_int64_t gd_xx3:19; /* reserved */ +} __packed; + +/* + * region descriptors, used to load gdt/idt tables before segments yet exist. + */ +struct region_descriptor { + u_int16_t rd_limit; /* segment extent */ + u_int64_t rd_base; /* base address */ +} __packed; + +#ifdef _KERNEL +extern struct gate_descriptor *idt; +extern struct gate_descriptor early_idt[]; + +void setgate(struct gate_descriptor *, void *, int, int, int, int); +void unsetgate(struct gate_descriptor *); +void setregion(struct region_descriptor *, void *, u_int16_t); +void set_sys_segment(struct sys_segment_descriptor *, void *, size_t, + int, int, int); +void set_mem_segment(struct mem_segment_descriptor *, void *, size_t, + int, int, int, int, int); +int idt_vec_alloc(int, int); +int idt_vec_alloc_range(int, int, int); +void idt_vec_set(int, void (*)(void)); +void idt_vec_free(int); +void cpu_init_idt(void); + +#endif /* _KERNEL */ + +#endif /* !_LOCORE */ + +/* system segments and gate types */ +#define SDT_SYSNULL 0 /* system null */ +#define SDT_SYS286TSS 1 /* system 286 TSS available */ +#define SDT_SYSLDT 2 /* system local descriptor table */ +#define SDT_SYS286BSY 3 /* system 286 TSS busy */ +#define SDT_SYS286CGT 4 /* system 286 call gate */ +#define SDT_SYSTASKGT 5 /* system task gate */ +#define SDT_SYS286IGT 6 /* system 286 interrupt gate */ +#define SDT_SYS286TGT 7 /* system 286 trap gate */ +#define SDT_SYSNULL2 8 /* system null again */ +#define SDT_SYS386TSS 9 /* system 386 TSS available */ +#define SDT_SYSNULL3 10 /* system null again */ +#define SDT_SYS386BSY 11 /* system 386 TSS busy */ +#define SDT_SYS386CGT 12 /* system 386 call gate */ +#define SDT_SYSNULL4 13 /* system null again */ +#define SDT_SYS386IGT 14 /* system 386 interrupt gate */ +#define SDT_SYS386TGT 15 /* system 386 trap gate */ + +/* memory segment types */ +#define SDT_MEMRO 16 /* memory read only */ +#define SDT_MEMROA 17 /* memory read only accessed */ +#define SDT_MEMRW 18 /* memory read write */ +#define SDT_MEMRWA 19 /* memory read write accessed */ +#define SDT_MEMROD 20 /* memory read only expand dwn limit */ +#define SDT_MEMRODA 21 /* memory read only expand dwn limit accessed */ +#define SDT_MEMRWD 22 /* memory read write expand dwn limit */ +#define SDT_MEMRWDA 23 /* memory read write expand dwn limit acessed */ +#define SDT_MEME 24 /* memory execute only */ +#define SDT_MEMEA 25 /* memory execute only accessed */ +#define SDT_MEMER 26 /* memory execute read */ +#define SDT_MEMERA 27 /* memory execute read accessed */ +#define SDT_MEMEC 28 /* memory execute only conforming */ +#define SDT_MEMEAC 29 /* memory execute only accessed conforming */ +#define SDT_MEMERC 30 /* memory execute read conforming */ +#define SDT_MEMERAC 31 /* memory execute read accessed conforming */ + +/* is memory segment descriptor pointer ? */ +#define ISMEMSDP(s) ((s->d_type) >= SDT_MEMRO && \ + (s->d_type) <= SDT_MEMERAC) + +/* is 286 gate descriptor pointer ? */ +#define IS286GDP(s) ((s->d_type) >= SDT_SYS286CGT && \ + (s->d_type) < SDT_SYS286TGT) + +/* is 386 gate descriptor pointer ? */ +#define IS386GDP(s) ((s->d_type) >= SDT_SYS386CGT && \ + (s->d_type) < SDT_SYS386TGT) + +/* is gate descriptor pointer ? */ +#define ISGDP(s) (IS286GDP(s) || IS386GDP(s)) + +/* is segment descriptor pointer ? */ +#define ISSDP(s) (ISMEMSDP(s) || !ISGDP(s)) + +/* is system segment descriptor pointer ? */ +#define ISSYSSDP(s) (!ISMEMSDP(s) && !ISGDP(s)) + +/* + * Segment Protection Exception code bits + */ +#define SEGEX_EXT 0x01 /* recursive or externally induced */ +#define SEGEX_IDT 0x02 /* interrupt descriptor table */ +#define SEGEX_TI 0x04 /* local descriptor table */ + +/* + * Entries in the Interrupt Descriptor Table (IDT) + */ +#define NIDT 256 +#define NRSVIDT 32 /* reserved entries for cpu exceptions */ + +/* + * Entries in the Global Descriptor Table (GDT) + * The code and data descriptors must come first. There + * are NGDT_MEM of them. + * + * Then comes the predefined TSS descriptor. + * There are NGDT_SYS of them. + * + * The particular order of the UDATA and UCODE descriptors is + * required by the sysretq instruction. + */ +#define GNULL_SEL 0 /* Null descriptor */ +#define GCODE_SEL 1 /* Kernel code descriptor */ +#define GDATA_SEL 2 /* Kernel data descriptor */ +#define GUDATA_SEL 3 /* User data descriptor */ +#define GUCODE_SEL 4 /* User code descriptor */ +#define NGDT_MEM 5 + +#define GPROC0_SEL 0 /* common TSS */ +#define NGDT_SYS 1 + +#define GDT_SYS_OFFSET (NGDT_MEM << 3) + +#define GDT_ADDR_MEM(s,i) \ + ((struct mem_segment_descriptor *)((char *)(s) + ((i) << 3))) +#define GDT_ADDR_SYS(s,i) \ + ((struct sys_segment_descriptor *)((char *)(s) + ((i) << 4) + SYSSEL_START)) + +/* + * Checks for valid user selectors. + */ +#define VALID_USER_CSEL(s) \ + ((s) == GSEL(GUCODE_SEL, SEL_UPL)) +#define VALID_USER_DSEL(s) \ + ((s) == GSEL(GUDATA_SEL, SEL_UPL)) + +#endif /* _MACHINE_SEGMENTS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/setjmp.h b/lib/libc/include/x86_64-openbsd-none/machine/setjmp.h new file mode 100644 index 0000000000..88f0465d15 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/setjmp.h @@ -0,0 +1,22 @@ +/* $OpenBSD: setjmp.h,v 1.2 2020/10/21 19:00:14 kettenis Exp $ */ +/* $NetBSD: setjmp.h,v 1.1 2003/04/26 18:39:47 fvdl Exp $ */ + +/* + * machine/setjmp.h: machine dependent setjmp-related information. + * These are only the callee-saved registers, code calling setjmp + * will expect the rest to be clobbered anyway. + */ + +#define _JB_RBX 0 +#define _JB_RBP 1 +#define _JB_R12 2 +#define _JB_R13 3 +#define _JB_R14 4 +#define _JB_R15 5 +#define _JB_RSP 6 +#define _JB_PC 7 +#define _JB_SIGFLAG 8 +#define _JB_SIGMASK 9 +#define _JB_MXCSR 10 + +#define _JBLEN 11 /* size, in longs, of a jmp_buf */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/signal.h b/lib/libc/include/x86_64-openbsd-none/machine/signal.h new file mode 100644 index 0000000000..5b19f70f3b --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/signal.h @@ -0,0 +1,89 @@ +/* $OpenBSD: signal.h,v 1.9 2016/05/10 18:39:42 deraadt Exp $ */ +/* $NetBSD: signal.h,v 1.2 2003/04/28 23:16:17 bjh21 Exp $ */ + +/* + * Copyright (c) 1982, 1986, 1989, 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. + * + * @(#)signal.h 7.16 (Berkeley) 3/17/91 + */ + +#ifndef _MACHINE_SIGNAL_H_ +#define _MACHINE_SIGNAL_H_ + +#include + +typedef int sig_atomic_t; + +#ifdef _KERNEL +#include +#endif + +#if __BSD_VISIBLE || __XPG_VISIBLE >= 420 +/* + * Information pushed on stack when a signal is delivered. + * This is used by the kernel to restore state following + * execution of the signal handler. It is also made available + * to the handler to allow it to restore state properly if + * a non-standard exit is performed. + */ +struct sigcontext { + /* plain match trapframe */ + long sc_rdi; + long sc_rsi; + long sc_rdx; + long sc_rcx; + long sc_r8; + long sc_r9; + long sc_r10; + long sc_r11; + long sc_r12; + long sc_r13; + long sc_r14; + long sc_r15; + long sc_rbp; + long sc_rbx; + long sc_rax; + long sc_gs; + long sc_fs; + long sc_es; + long sc_ds; + long sc_trapno; + long sc_err; + long sc_rip; + long sc_cs; + long sc_rflags; + long sc_rsp; + long sc_ss; + + struct fxsave64 *sc_fpstate; + int __sc_unused; + int sc_mask; + long sc_cookie; +}; +#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */ +#endif /* !_MACHINE_SIGNAL_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/specialreg.h b/lib/libc/include/x86_64-openbsd-none/machine/specialreg.h new file mode 100644 index 0000000000..fc0770c81d --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/specialreg.h @@ -0,0 +1,1645 @@ +/* $OpenBSD: specialreg.h,v 1.120 2025/07/16 07:15:41 jsg Exp $ */ +/* $NetBSD: specialreg.h,v 1.1 2003/04/26 18:39:48 fvdl Exp $ */ +/* $NetBSD: x86/specialreg.h,v 1.2 2003/04/25 21:54:30 fvdl Exp $ */ + +/*- + * Copyright (c) 1991 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. + * + * @(#)specialreg.h 7.1 (Berkeley) 5/9/91 + */ + +/* + * Bits in 386 special registers: + */ +#define CR0_PE 0x00000001 /* Protected mode Enable */ +#define CR0_MP 0x00000002 /* "Math" Present (NPX or NPX emulator) */ +#define CR0_EM 0x00000004 /* EMulate non-NPX coproc. (trap ESC only) */ +#define CR0_TS 0x00000008 /* Task Switched (if MP, trap ESC and WAIT) */ +#define CR0_ET 0x00000010 /* Extension Type (387 (if set) vs 287) */ +#define CR0_PG 0x80000000 /* PaGing enable */ + +/* + * Bits in 486 special registers: + */ +#define CR0_NE 0x00000020 /* Numeric Error enable (EX16 vs IRQ13) */ +#define CR0_WP 0x00010000 /* Write Protect (honor PG_RW in all modes) */ +#define CR0_AM 0x00040000 /* Alignment Mask (set to enable AC flag) */ +#define CR0_NW 0x20000000 /* Not Write-through */ +#define CR0_CD 0x40000000 /* Cache Disable */ + +/* + * bits in CR3 + */ +#define CR3_PCID 0xfffULL +#define CR3_PWT (1ULL << 3) +#define CR3_PCD (1ULL << 4) +#define CR3_REUSE_PCID (1ULL << 63) +#define CR3_PADDR 0x7ffffffffffff000ULL + +/* + * bits in the pentiums %cr4 register: + */ + +#define CR4_VME 0x00000001 /* virtual 8086 mode extension enable */ +#define CR4_PVI 0x00000002 /* protected mode virtual interrupt enable */ +#define CR4_TSD 0x00000004 /* restrict RDTSC instruction to cpl 0 only */ +#define CR4_DE 0x00000008 /* debugging extension */ +#define CR4_PSE 0x00000010 /* large (4MB) page size enable */ +#define CR4_PAE 0x00000020 /* physical address extension enable */ +#define CR4_MCE 0x00000040 /* machine check enable */ +#define CR4_PGE 0x00000080 /* page global enable */ +#define CR4_PCE 0x00000100 /* enable RDPMC instruction for all cpls */ +#define CR4_OSFXSR 0x00000200 /* enable fxsave/fxrestor and SSE */ +#define CR4_OSXMMEXCPT 0x00000400 /* enable unmasked SSE exceptions */ +#define CR4_UMIP 0x00000800 /* user mode instruction prevention */ +#define CR4_VMXE 0x00002000 /* enable virtual machine operation */ +#define CR4_SMXE 0x00004000 /* enable safe mode operation */ +#define CR4_FSGSBASE 0x00010000 /* enable {RD,WR}{FS,GS}BASE ops */ +#define CR4_PCIDE 0x00020000 /* enable process-context IDs */ +#define CR4_OSXSAVE 0x00040000 /* enable XSAVE and extended states */ +#define CR4_KL 0x00080000 /* enable AES Key Locker */ +#define CR4_SMEP 0x00100000 /* supervisor mode exec protection */ +#define CR4_SMAP 0x00200000 /* supervisor mode access prevention */ +#define CR4_PKE 0x00400000 /* user-mode protection keys */ +#define CR4_CET 0x00800000 /* control-flow enforcement tech */ +#define CR4_PKS 0x01000000 /* supervisor-mode protection keys */ +#define CR4_UINTR 0x02000000 /* user interrupts enable bit */ + +/* + * Extended state components, for xsave/xrstor family of instructions. + */ +#define XFEATURE_X87 0x00000001 /* x87 FPU/MMX state */ +#define XFEATURE_SSE 0x00000002 /* SSE state */ +#define XFEATURE_AVX 0x00000004 /* AVX state */ +#define XFEATURE_BNDREG 0x00000008 /* MPX state */ +#define XFEATURE_BNDCSR 0x00000010 /* MPX state */ +#define XFEATURE_MPX (XFEATURE_BNDREG | XFEATURE_BNDCSR) +#define XFEATURE_OPMASK 0x00000020 /* AVX-512 opmask */ +#define XFEATURE_ZMM_HI256 0x00000040 /* AVX-512 ZMM0-7 */ +#define XFEATURE_HI16_ZMM 0x00000080 /* AVX-512 ZMM16-31 */ +#define XFEATURE_AVX512 (XFEATURE_OPMASK | XFEATURE_ZMM_HI256 | \ + XFEATURE_HI16_ZMM) +#define XFEATURE_PT 0x00000100 /* processor trace */ +#define XFEATURE_PKRU 0x00000200 /* user page key */ +#define XFEATURE_PASID 0x00000400 /* Process ASIDs */ +#define XFEATURE_CET_U 0x00000800 /* ctrl-flow enforce user */ +#define XFEATURE_CET_S 0x00001000 /* ctrl-flow enforce system */ +#define XFEATURE_CET (XFEATURE_CET_U | XFEATURE_CET_S) +#define XFEATURE_HDC 0x00002000 /* HW duty cycling */ +#define XFEATURE_UINTR 0x00004000 /* user interrupts */ +#define XFEATURE_LBR 0x00008000 /* last-branch record */ +#define XFEATURE_HWP 0x00010000 /* HW P-states */ +#define XFEATURE_TILECFG 0x00020000 /* AMX state */ +#define XFEATURE_TILEDATA 0x00040000 /* AMX state */ +#define XFEATURE_AMX (XFEATURE_TILECFG | XFEATURE_TILEDATA) + +/* valid only in xcomp_bv field: */ +#define XFEATURE_COMPRESSED (1ULL << 63) /* compressed format */ + +/* which bits are for XCR0 and which for the XSS MSR? */ +#define XFEATURE_XCR0_MASK \ + (XFEATURE_X87 | XFEATURE_SSE | XFEATURE_AVX | XFEATURE_MPX | \ + XFEATURE_AVX512 | XFEATURE_PKRU | XFEATURE_AMX) +#define XFEATURE_XSS_MASK \ + (XFEATURE_PT | XFEATURE_PASID | XFEATURE_CET | XFEATURE_HDC | \ + XFEATURE_UINTR | XFEATURE_LBR | XFEATURE_HWP) + +/* + * CPUID "features" bits (CPUID function 0x1): + * EDX bits, then ECX bits + */ + +#define CPUID_FPU 0x00000001 /* processor has an FPU? */ +#define CPUID_VME 0x00000002 /* has virtual mode (%cr4's VME/PVI) */ +#define CPUID_DE 0x00000004 /* has debugging extension */ +#define CPUID_PSE 0x00000008 /* has 4MB page size extension */ +#define CPUID_TSC 0x00000010 /* has time stamp counter */ +#define CPUID_MSR 0x00000020 /* has model specific registers */ +#define CPUID_PAE 0x00000040 /* has phys address extension */ +#define CPUID_MCE 0x00000080 /* has machine check exception */ +#define CPUID_CX8 0x00000100 /* has CMPXCHG8B instruction */ +#define CPUID_APIC 0x00000200 /* has enabled APIC */ +#define CPUID_SYS1 0x00000400 /* has SYSCALL/SYSRET inst. (Cyrix) */ +#define CPUID_SEP 0x00000800 /* has SYSCALL/SYSRET inst. (AMD/Intel) */ +#define CPUID_MTRR 0x00001000 /* has memory type range register */ +#define CPUID_PGE 0x00002000 /* has page global extension */ +#define CPUID_MCA 0x00004000 /* has machine check architecture */ +#define CPUID_CMOV 0x00008000 /* has CMOVcc instruction */ +#define CPUID_PAT 0x00010000 /* has page attribute table */ +#define CPUID_PSE36 0x00020000 /* has 36bit page size extension */ +#define CPUID_PSN 0x00040000 /* has processor serial number */ +#define CPUID_CFLUSH 0x00080000 /* CFLUSH insn supported */ +#define CPUID_B20 0x00100000 /* reserved */ +#define CPUID_DS 0x00200000 /* Debug Store */ +#define CPUID_ACPI 0x00400000 /* ACPI performance modulation regs */ +#define CPUID_MMX 0x00800000 /* has MMX instructions */ +#define CPUID_FXSR 0x01000000 /* has FXRSTOR instruction */ +#define CPUID_SSE 0x02000000 /* has streaming SIMD extensions */ +#define CPUID_SSE2 0x04000000 /* has streaming SIMD extensions #2 */ +#define CPUID_SS 0x08000000 /* self-snoop */ +#define CPUID_HTT 0x10000000 /* Hyper-Threading Technology */ +#define CPUID_TM 0x20000000 /* thermal monitor (TCC) */ +#define CPUID_B30 0x40000000 /* reserved */ +#define CPUID_PBE 0x80000000 /* Pending Break Enabled restarts clock */ +#define CPUID_EDX_BITS \ + ("\20" "\01FPU" "\02VME" "\03DE" "\04PSE" "\05TSC" "\06MSR" "\07PAE" \ + "\010MCE" "\011CX8" "\012APIC" "\014SEP" "\015MTRR" "\016PGE" "\017MCA" \ + "\020CMOV" "\021PAT" "\022PSE36" "\023PSN" "\024CFLUSH" "\026DS" \ + "\027ACPI" "\030MMX" "\031FXSR" "\032SSE" "\033SSE2" "\034SS" "\035HTT" \ + "\036TM" "\040PBE" ) + +#define CPUIDECX_SSE3 0x00000001 /* streaming SIMD extensions #3 */ +#define CPUIDECX_PCLMUL 0x00000002 /* Carryless Multiplication */ +#define CPUIDECX_DTES64 0x00000004 /* 64bit debug store */ +#define CPUIDECX_MWAIT 0x00000008 /* Monitor/Mwait */ +#define CPUIDECX_DSCPL 0x00000010 /* CPL Qualified Debug Store */ +#define CPUIDECX_VMX 0x00000020 /* Virtual Machine Extensions */ +#define CPUIDECX_SMX 0x00000040 /* Safer Mode Extensions */ +#define CPUIDECX_EST 0x00000080 /* enhanced SpeedStep */ +#define CPUIDECX_TM2 0x00000100 /* thermal monitor 2 */ +#define CPUIDECX_SSSE3 0x00000200 /* Supplemental Streaming SIMD Ext. 3 */ +#define CPUIDECX_CNXTID 0x00000400 /* Context ID */ +#define CPUIDECX_SDBG 0x00000800 /* Silicon debug capability */ +#define CPUIDECX_FMA3 0x00001000 /* Fused Multiply Add */ +#define CPUIDECX_CX16 0x00002000 /* has CMPXCHG16B instruction */ +#define CPUIDECX_XTPR 0x00004000 /* xTPR Update Control */ +#define CPUIDECX_PDCM 0x00008000 /* Perfmon and Debug Capability */ +#define CPUIDECX_PCID 0x00020000 /* Process-context ID Capability */ +#define CPUIDECX_DCA 0x00040000 /* Direct Cache Access */ +#define CPUIDECX_SSE41 0x00080000 /* Streaming SIMD Extensions 4.1 */ +#define CPUIDECX_SSE42 0x00100000 /* Streaming SIMD Extensions 4.2 */ +#define CPUIDECX_X2APIC 0x00200000 /* Extended xAPIC Support */ +#define CPUIDECX_MOVBE 0x00400000 /* MOVBE Instruction */ +#define CPUIDECX_POPCNT 0x00800000 /* POPCNT Instruction */ +#define CPUIDECX_DEADLINE 0x01000000 /* APIC one-shot via deadline */ +#define CPUIDECX_AES 0x02000000 /* AES Instruction */ +#define CPUIDECX_XSAVE 0x04000000 /* XSAVE/XSTOR States */ +#define CPUIDECX_OSXSAVE 0x08000000 /* OSXSAVE */ +#define CPUIDECX_AVX 0x10000000 /* Advanced Vector Extensions */ +#define CPUIDECX_F16C 0x20000000 /* 16bit fp conversion */ +#define CPUIDECX_RDRAND 0x40000000 /* RDRAND instruction */ +#define CPUIDECX_HV 0x80000000 /* Running on hypervisor */ +#define CPUID_ECX_BITS \ + ("\20" "\01SSE3" "\02PCLMUL" "\03DTES64" "\04MWAIT" "\05DS-CPL" "\06VMX" \ + "\07SMX" "\010EST" "\011TM2" "\012SSSE3" "\013CNXT-ID" "\014SDBG" \ + "\015FMA3" "\016CX16" "\017xTPR" "\020PDCM" "\022PCID" "\023DCA" \ + "\024SSE4.1" "\025SSE4.2" "\026x2APIC" "\027MOVBE" "\030POPCNT" \ + "\031DEADLINE" "\032AES" "\033XSAVE" "\034OSXSAVE" "\035AVX" "\036F16C" \ + "\037RDRAND" "\040HV" ) + +/* + * "Structured Extended Feature Flags Parameters" (CPUID function 0x7, leaf 0) + * EBX bits + */ +#define SEFF0EBX_FSGSBASE 0x00000001 /* {RD,WR}[FG]SBASE instructions */ +#define SEFF0EBX_TSC_ADJUST 0x00000002 /* Has IA32_TSC_ADJUST MSR */ +#define SEFF0EBX_SGX 0x00000004 /* Software Guard Extensions */ +#define SEFF0EBX_BMI1 0x00000008 /* advanced bit manipulation */ +#define SEFF0EBX_HLE 0x00000010 /* Hardware Lock Elision */ +#define SEFF0EBX_AVX2 0x00000020 /* Advanced Vector Extensions 2 */ +#define SEFF0EBX_SMEP 0x00000080 /* Supervisor mode exec protection */ +#define SEFF0EBX_BMI2 0x00000100 /* advanced bit manipulation */ +#define SEFF0EBX_ERMS 0x00000200 /* Enhanced REP MOVSB/STOSB */ +#define SEFF0EBX_INVPCID 0x00000400 /* INVPCID instruction */ +#define SEFF0EBX_RTM 0x00000800 /* Restricted Transactional Memory */ +#define SEFF0EBX_PQM 0x00001000 /* Quality of Service Monitoring */ +#define SEFF0EBX_MPX 0x00004000 /* Memory Protection Extensions */ +#define SEFF0EBX_AVX512F 0x00010000 /* AVX-512 foundation inst */ +#define SEFF0EBX_AVX512DQ 0x00020000 /* AVX-512 double/quadword */ +#define SEFF0EBX_RDSEED 0x00040000 /* RDSEED instruction */ +#define SEFF0EBX_ADX 0x00080000 /* ADCX/ADOX instructions */ +#define SEFF0EBX_SMAP 0x00100000 /* Supervisor mode access prevent */ +#define SEFF0EBX_AVX512IFMA 0x00200000 /* AVX-512 integer mult-add */ +#define SEFF0EBX_PCOMMIT 0x00400000 /* Persistent commit inst */ +#define SEFF0EBX_CLFLUSHOPT 0x00800000 /* cache line flush */ +#define SEFF0EBX_CLWB 0x01000000 /* cache line write back */ +#define SEFF0EBX_PT 0x02000000 /* Processor Trace */ +#define SEFF0EBX_AVX512PF 0x04000000 /* AVX-512 prefetch */ +#define SEFF0EBX_AVX512ER 0x08000000 /* AVX-512 exp/reciprocal */ +#define SEFF0EBX_AVX512CD 0x10000000 /* AVX-512 conflict detection */ +#define SEFF0EBX_SHA 0x20000000 /* SHA Extensions */ +#define SEFF0EBX_AVX512BW 0x40000000 /* AVX-512 byte/word inst */ +#define SEFF0EBX_AVX512VL 0x80000000 /* AVX-512 vector len inst */ +#define SEFF0_EBX_BITS \ + ("\20" "\01FSGSBASE" "\02TSC_ADJUST" "\03SGX" "\04BMI1" "\05HLE" \ + "\06AVX2" "\010SMEP" "\011BMI2" "\012ERMS" "\013INVPCID" "\014RTM" \ + "\015PQM" "\017MPX" "\021AVX512F" "\022AVX512DQ" "\023RDSEED" "\024ADX" \ + "\025SMAP" "\026AVX512IFMA" "\027PCOMMIT" "\030CLFLUSHOPT" "\031CLWB" \ + "\032PT" "\033AVX512PF" "\034AVX512ER" "\035AVX512CD" "\036SHA" \ + "\037AVX512BW" "\040AVX512VL" ) + +/* SEFF ECX bits */ +#define SEFF0ECX_PREFETCHWT1 0x00000001 /* PREFETCHWT1 instruction */ +#define SEFF0ECX_AVX512VBMI 0x00000002 /* AVX-512 vector bit inst */ +#define SEFF0ECX_UMIP 0x00000004 /* UMIP support */ +#define SEFF0ECX_PKU 0x00000008 /* Page prot keys for user mode */ +#define SEFF0ECX_OSPKE 0x00000010 /* OS enabled RD/WRPKRU */ +#define SEFF0ECX_WAITPKG 0x00000020 /* UMONITOR/UMWAIT/TPAUSE insns */ +#define SEFF0ECX_PKS 0x80000000 /* Page prot keys for sup mode */ +#define SEFF0_ECX_BITS \ + ("\20" "\01PREFETCHWT1" "\02AVX512VBMI" "\03UMIP" "\04PKU" "\06WAITPKG" \ + "\040PKS" ) + +/* SEFF EDX bits */ +#define SEFF0EDX_AVX512_4FNNIW 0x00000004 /* AVX-512 neural network insns */ +#define SEFF0EDX_AVX512_4FMAPS 0x00000008 /* AVX-512 mult accum single prec */ +#define SEFF0EDX_SRBDS_CTRL 0x00000200 /* MCU_OPT_CTRL MSR */ +#define SEFF0EDX_MD_CLEAR 0x00000400 /* Microarch Data Clear */ +#define SEFF0EDX_TSXFA 0x00002000 /* TSX Forced Abort */ +#define SEFF0EDX_IBT 0x00100000 /* Indirect Branch Tracking */ +#define SEFF0EDX_IBRS 0x04000000 /* IBRS / IBPB Speculation Control */ +#define SEFF0EDX_STIBP 0x08000000 /* STIBP Speculation Control */ +#define SEFF0EDX_L1DF 0x10000000 /* L1D_FLUSH */ +#define SEFF0EDX_ARCH_CAP 0x20000000 /* Has IA32_ARCH_CAPABILITIES MSR */ +#define SEFF0EDX_SSBD 0x80000000 /* Spec Store Bypass Disable */ +#define SEFF0_EDX_BITS \ + ("\20" "\03AVX512FNNIW" "\04AVX512FMAPS" "\012SRBDS_CTRL" "\013MD_CLEAR" \ + "\016TSXFA" "\025IBT" "\033IBRS,IBPB" "\034STIBP" "\035L1DF" "\040SSBD" ) + +/* + * Thermal and Power Management (CPUID function 0x6) EAX bits + */ +#define TPM_SENSOR 0x00000001 /* Digital temp sensor */ +#define TPM_ARAT 0x00000004 /* APIC Timer Always Running */ +#define TPM_PTS 0x00000040 /* Intel Package Thermal Status */ +#define TPM_EAX_BITS \ + ("\20" "\01SENSOR" "\03ARAT" "\07PTS") +/* Thermal and Power Management (CPUID function 0x6) ECX bits */ +#define TPM_EFFFREQ 0x00000001 /* APERF & MPERF MSR present */ +#define TPM_ECX_BITS \ + ("\20" "\01EFFFREQ" ) + + /* + * "Architectural Performance Monitoring" bits (CPUID function 0x0a): + * EAX bits, EBX bits, EDX bits. + */ + +#define CPUIDEAX_VERID 0x000000ff /* Version ID */ +#define CPUIDEAX_NUM_GC(cpuid) (((cpuid) >> 8) & 0x000000ff) +#define CPUIDEAX_BIT_GC(cpuid) (((cpuid) >> 16) & 0x000000ff) +#define CPUIDEAX_LEN_EBX(cpuid) (((cpuid) >> 24) & 0x000000ff) + +#define CPUIDEBX_EVT_CORE (1 << 0) /* Core cycle */ +#define CPUIDEBX_EVT_INST (1 << 1) /* Instruction retired */ +#define CPUIDEBX_EVT_REFR (1 << 2) /* Reference cycles */ +#define CPUIDEBX_EVT_CACHE_REF (1 << 3) /* Last-level cache ref. */ +#define CPUIDEBX_EVT_CACHE_MIS (1 << 4) /* Last-level cache miss. */ +#define CPUIDEBX_EVT_BRANCH_INST (1 << 5) /* Branch instruction ret. */ +#define CPUIDEBX_EVT_BRANCH_MISP (1 << 6) /* Branch mispredict ret. */ + +#define CPUIDEDX_NUM_FC(cpuid) (((cpuid) >> 0) & 0x0000001f) +#define CPUIDEDX_BIT_FC(cpuid) (((cpuid) >> 5) & 0x000000ff) + +/* + * CPUID "extended features" bits (CPUID function 0x80000001): + * EDX bits, then ECX bits + */ + +#define CPUID_MPC 0x00080000 /* Multiprocessing Capable */ +#define CPUID_NXE 0x00100000 /* No-Execute Extension */ +#define CPUID_MMXX 0x00400000 /* AMD MMX Extensions */ +#define CPUID_FFXSR 0x02000000 /* fast FP/MMX save/restore */ +#define CPUID_PAGE1GB 0x04000000 /* 1-GByte pages */ +#define CPUID_RDTSCP 0x08000000 /* RDTSCP / IA32_TSC_AUX available */ +#define CPUID_LONG 0x20000000 /* long mode */ +#define CPUID_3DNOW2 0x40000000 /* 3DNow! Instruction Extension */ +#define CPUID_3DNOW 0x80000000 /* 3DNow! Instructions */ +#define CPUIDE_EDX_BITS \ + ("\20" "\024MPC" "\025NXE" "\027MMXX" "\032FFXSR" "\033PAGE1GB" \ + "\034RDTSCP" "\036LONG" "\0373DNOW2" "\0403DNOW" ) + +#define CPUIDECX_LAHF 0x00000001 /* LAHF and SAHF instructions */ +#define CPUIDECX_CMPLEG 0x00000002 /* Core MP legacy mode */ +#define CPUIDECX_SVM 0x00000004 /* Secure Virtual Machine */ +#define CPUIDECX_EAPICSP 0x00000008 /* Extended APIC space */ +#define CPUIDECX_AMCR8 0x00000010 /* LOCK MOV CR0 means MOV CR8 */ +#define CPUIDECX_ABM 0x00000020 /* LZCNT instruction */ +#define CPUIDECX_SSE4A 0x00000040 /* SSE4-A instruction set */ +#define CPUIDECX_MASSE 0x00000080 /* Misaligned SSE mode */ +#define CPUIDECX_3DNOWP 0x00000100 /* 3DNowPrefetch */ +#define CPUIDECX_OSVW 0x00000200 /* OS visible workaround */ +#define CPUIDECX_IBS 0x00000400 /* Instruction based sampling */ +#define CPUIDECX_XOP 0x00000800 /* Extended operating support */ +#define CPUIDECX_SKINIT 0x00001000 /* SKINIT and STGI are supported */ +#define CPUIDECX_WDT 0x00002000 /* Watchdog timer */ +/* Reserved 0x00004000 */ +#define CPUIDECX_LWP 0x00008000 /* Lightweight profiling support */ +#define CPUIDECX_FMA4 0x00010000 /* 4-operand FMA instructions */ +#define CPUIDECX_TCE 0x00020000 /* Translation Cache Extension */ +/* Reserved 0x00040000 */ +#define CPUIDECX_NODEID 0x00080000 /* Support for MSRC001C */ +/* Reserved 0x00100000 */ +#define CPUIDECX_TBM 0x00200000 /* Trailing bit manipulation instruction */ +#define CPUIDECX_TOPEXT 0x00400000 /* Topology extensions support */ +#define CPUIDECX_CPCTR 0x00800000 /* core performance counter ext */ +#define CPUIDECX_DBKP 0x04000000 /* DataBreakpointExtension */ +#define CPUIDECX_PERFTSC 0x08000000 /* performance time-stamp counter */ +#define CPUIDECX_PCTRL3 0x10000000 /* L3 performance counter ext */ +#define CPUIDECX_MWAITX 0x20000000 /* MWAITX/MONITORX */ +#define CPUIDE_ECX_BITS \ + ("\20" "\01LAHF" "\02CMPLEG" "\03SVM" "\04EAPICSP" "\05AMCR8" "\06ABM" \ + "\07SSE4A" "\010MASSE" "\0113DNOWP" "\012OSVW" "\013IBS" "\014XOP" \ + "\015SKINIT" "\020WDT" "\021FMA4" "\022TCE" "\024NODEID" "\026TBM" \ + "\027TOPEXT" "\030CPCTR" "\033DBKP" "\034PERFTSC" "\035PCTRL3" \ + "\036MWAITX" ) + +/* + * "Advanced Power Management Information" bits (CPUID function 0x80000007): + * EDX bits. + */ +#define CPUIDEDX_HWPSTATE (1 << 7) /* Hardware P State Control */ +#define CPUIDEDX_ITSC (1 << 8) /* Invariant TSC */ +#define CPUID_APMI_EDX_BITS \ + ("\20" "\010HWPSTATE" "\011ITSC" ) + +/* + * AMD CPUID function 0x80000008 EBX bits + */ +#define CPUIDEBX_INVLPGB (1ULL << 3) /* INVLPG w/broadcast */ +#define CPUIDEBX_IBPB (1ULL << 12) /* Speculation Control IBPB */ +#define CPUIDEBX_IBRS (1ULL << 14) /* Speculation Control IBRS */ +#define CPUIDEBX_STIBP (1ULL << 15) /* Speculation Control STIBP */ +#define CPUIDEBX_IBRS_ALWAYSON (1ULL << 16) /* IBRS always on mode */ +#define CPUIDEBX_STIBP_ALWAYSON (1ULL << 17) /* STIBP always on mode */ +#define CPUIDEBX_IBRS_PREF (1ULL << 18) /* IBRS preferred */ +#define CPUIDEBX_IBRS_SAME_MODE (1ULL << 19) /* IBRS not mode-specific */ +#define CPUIDEBX_SSBD (1ULL << 24) /* Speculation Control SSBD */ +#define CPUIDEBX_VIRT_SSBD (1ULL << 25) /* Virt Spec Control SSBD */ +#define CPUIDEBX_SSBD_NOTREQ (1ULL << 26) /* SSBD not required */ +#define CPUID_AMDSPEC_EBX_BITS \ + ("\20" "\04INVLPGB" "\015IBPB" "\017IBRS" "\020STIBP" "\021IBRS_ALL" \ + "\022STIBP_ALL" "\023IBRS_PREF" "\024IBRS_SM" "\031SSBD" "\032VIRTSSBD" \ + "\033SSBDNR" ) + +/* + * AMD CPUID function 0x8000001F EAX bits + */ +#define CPUIDEAX_SME (1ULL << 0) /* SME */ +#define CPUIDEAX_SEV (1ULL << 1) /* SEV */ +#define CPUIDEAX_PFLUSH_MSR (1ULL << 2) /* Page Flush MSR */ +#define CPUIDEAX_SEVES (1ULL << 3) /* SEV-ES */ +#define CPUIDEAX_SEVSNP (1ULL << 4) /* SEV-SNP */ +#define CPUIDEAX_VMPL (1ULL << 5) /* VM Permission Levels */ +#define CPUIDEAX_RMPQUERY (1ULL << 6) /* RMPQUERY */ +#define CPUIDEAX_VMPLSSS (1ULL << 7) /* VMPL Supervisor Shadow Stack */ +#define CPUIDEAX_SECTSC (1ULL << 8) /* Secure TSC */ +#define CPUIDEAX_TSCAUXVIRT (1ULL << 9) /* TSC Aux Virtualization */ +#define CPUIDEAX_HWECACHECOH (1ULL << 10) /* Coherency Across Enc. Domains */ +#define CPUIDEAX_64BITHOST (1ULL << 11) /* SEV guest requires 64bit host */ +#define CPUIDEAX_RESTINJ (1ULL << 12) /* Restricted Injection */ +#define CPUIDEAX_ALTINJ (1ULL << 13) /* Alternate Injection */ +#define CPUIDEAX_DBGSTSW (1ULL << 14) /* Full debug state swap */ +#define CPUIDEAX_IBSDISALLOW (1ULL << 15) /* Disallowing IBS use by host */ +#define CPUIDEAX_VTE (1ULL << 16) /* Virt. Transparent Encryption */ +#define CPUIDEAX_VMGEXITPARAM (1ULL << 17) /* VMGEXIT Parameter */ +#define CPUIDEAX_VTOMMSR (1ULL << 18) /* Virtual TOM MSR */ +#define CPUIDEAX_IBSVIRT (1ULL << 19) /* IBS Virtualization for SEV-ES */ +#define CPUIDEAX_VMSARPROT (1ULL << 24) /* VMSA Register Protection */ +#define CPUIDEAX_SMTPROT (1ULL << 25) /* SMT Protection */ +#define CPUIDEAX_SVSMPAGEMSR (1ULL << 28) /* SVSM Communication Page MSR */ +#define CPUIDEAX_NVSMSR (1ULL << 29) /* NestedVirtSnpMsr */ +#define CPUID_AMDSEV_EAX_BITS \ + ("\20" "\01SME" "\02SEV" "\03PFLUSH_MSR" "\04SEVES" "\05SEVSNP" "\06VMPL" \ + "\07RMPQUERY" "\010VMPLSSS" "\011SECTSC" "\012TSCAUXVIRT" \ + "\013HWECACHECOH" "\014REQ64BITHOST" "\015RESTINJ" "\016ALTINJ" \ + "\017DBGSTSW" "\020IBSDISALLOW" "\021VTE" "\022VMGEXITPARAM" \ + "\023VTOMMSR" "\024IBSVIRT" "\031VMSARPROT" "\032SMTPROT" \ + "\035SVSMPAGEMSR" "\036NVSMSR" ) + +/* Number of encrypted guests */ +#define CPUID_AMDSEV_ECX_BITS ("\20") + +/* Minimum ASID for SEV enabled, SEV-ES disabled guest. */ +#define CPUID_AMDSEV_EDX_BITS ("\20") + +#define CPUID2FAMILY(cpuid) (((cpuid) >> 8) & 15) +#define CPUID2MODEL(cpuid) (((cpuid) >> 4) & 15) +#define CPUID2STEPPING(cpuid) ((cpuid) & 15) + +#define CPUID(code, eax, ebx, ecx, edx) \ + __asm volatile("cpuid" \ + : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) \ + : "a" (code)) +#define CPUID_LEAF(code, leaf, eax, ebx, ecx, edx) \ + __asm volatile("cpuid" \ + : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) \ + : "a" (code), "c" (leaf)) + + +/* + * Model-specific registers for the i386 family + */ +#define MSR_P5_MC_ADDR 0x000 /* P5 only */ +#define MSR_P5_MC_TYPE 0x001 /* P5 only */ +#define MSR_TSC 0x010 +#define MSR_CESR 0x011 /* P5 only (trap on P6) */ +#define MSR_CTR0 0x012 /* P5 only (trap on P6) */ +#define MSR_CTR1 0x013 /* P5 only (trap on P6) */ +#define MSR_PLATFORM_ID 0x017 /* Platform ID for microcode */ +#define MSR_APICBASE 0x01b +#define APICBASE_BSP 0x100 +#define APICBASE_ENABLE_X2APIC 0x400 +#define APICBASE_GLOBAL_ENABLE 0x800 +#define MSR_EBL_CR_POWERON 0x02a +#define MSR_EBC_FREQUENCY_ID 0x02c /* Pentium 4 only */ +#define MSR_TEST_CTL 0x033 +#define MSR_IA32_FEATURE_CONTROL 0x03a +#define MSR_TSC_ADJUST 0x03b +#define MSR_SPEC_CTRL 0x048 /* Speculation Control IBRS / STIBP */ +#define SPEC_CTRL_IBRS (1ULL << 0) +#define SPEC_CTRL_STIBP (1ULL << 1) +#define SPEC_CTRL_SSBD (1ULL << 2) +#define MSR_PRED_CMD 0x049 /* Speculation Control IBPB */ +#define PRED_CMD_IBPB (1ULL << 0) +#define MSR_BIOS_UPDT_TRIG 0x079 +#define MSR_BBL_CR_D0 0x088 /* PII+ only */ +#define MSR_BBL_CR_D1 0x089 /* PII+ only */ +#define MSR_BBL_CR_D2 0x08a /* PII+ only */ +#define MSR_BIOS_SIGN 0x08b +#define MSR_SMM_MONITOR_CTL 0x09b +#define MSR_SMBASE 0x09e +#define MSR_PERFCTR0 0x0c1 +#define MSR_PERFCTR1 0x0c2 +#define MSR_FSB_FREQ 0x0cd /* Core Duo/Solo only */ +#define MSR_MPERF 0x0e7 +#define MSR_APERF 0x0e8 +#define MSR_MTRRcap 0x0fe +#define MTRRcap_FIXED 0x100 /* bit 8 - fixed MTRRs supported */ +#define MTRRcap_WC 0x400 /* bit 10 - WC type supported */ +#define MTRRcap_SMRR 0x800 /* bit 11 - SMM range reg supported */ +#define MSR_ARCH_CAPABILITIES 0x10a +#define ARCH_CAP_RDCL_NO (1 << 0) /* Meltdown safe */ +#define ARCH_CAP_IBRS_ALL (1 << 1) /* enhanced IBRS */ +#define ARCH_CAP_RSBA (1 << 2) /* RSB Alternate */ +#define ARCH_CAP_SKIP_L1DFL_VMENTRY (1 << 3) +#define ARCH_CAP_SSB_NO (1 << 4) /* Spec St Byp safe */ +#define ARCH_CAP_MDS_NO (1 << 5) /* microarch data-sampling */ +#define ARCH_CAP_IF_PSCHANGE_MC_NO (1 << 6) /* PS MCE safe */ +#define ARCH_CAP_TSX_CTRL (1 << 7) /* has TSX_CTRL MSR */ +#define ARCH_CAP_TAA_NO (1 << 8) /* TSX AA safe */ +#define ARCH_CAP_MCU_CONTROL (1 << 9) /* has MCU_CTRL MSR */ +#define ARCH_CAP_MISC_PACKAGE_CTLS (1 << 10) /* has MISC_PKG_CTLS MSR */ +#define ARCH_CAP_ENERGY_FILTERING_CTL (1 << 11) /* r/w energy fltring bit */ +#define ARCH_CAP_DOITM (1 << 12) /* Data oprnd indpdnt tmng */ +#define ARCH_CAP_SBDR_SSDP_NO (1 << 13) /* SBDR/SSDP safe */ +#define ARCH_CAP_FBSDP_NO (1 << 14) /* FBSDP safe */ +#define ARCH_CAP_PSDP_NO (1 << 15) /* PSDP safe */ +#define ARCH_CAP_FB_CLEAR (1 << 17) /* MD_CLEAR covers FB */ +#define ARCH_CAP_FB_CLEAR_CTRL (1 << 18) +#define ARCH_CAP_RRSBA (1 << 19) /* has RRSBA if not dis */ +#define ARCH_CAP_BHI_NO (1 << 20) /* BHI safe */ +#define ARCH_CAP_XAPIC_DISABLE_STATUS (1 << 21) /* can disable xAPIC */ +#define ARCH_CAP_OVERCLOCKING_STATUS (1 << 23) /* has OVRCLCKNG_STAT MSR */ +#define ARCH_CAP_PBRSB_NO (1 << 24) /* PBSR safe */ +#define ARCH_CAP_GDS_CTRL (1 << 25) /* has GDS_MITG_DIS/LOCK */ +#define ARCH_CAP_GDS_NO (1 << 26) /* GDS safe */ +#define ARCH_CAP_RFDS_NO (1 << 27) /* RFDS safe */ +#define ARCH_CAP_RFDS_CLEAR (1 << 28) /* use VERW for RFDS */ +#define ARCH_CAP_MSR_BITS \ + ("\20" "\02IBRS_ALL" "\03RSBA" "\04SKIP_L1DFL" "\05SSB_NO" "\06MDS_NO" \ + "\07IF_PSCHANGE" "\010TSX_CTRL" "\011TAA_NO" "\012MCU_CONTROL" \ + "\013MISC_PKG_CT" "\014ENERGY_FILT" "\015DOITM" "\016SBDR_SSDP_N" \ + "\017FBSDP_NO" "\020PSDP_NO" "\022FB_CLEAR" "\023FB_CLEAR_CT" \ + "\024RRSBA" "\025BHI_NO" "\026XAPIC_DIS" "\030OVERCLOCK" "\031PBRSB_NO" \ + "\032GDS_CTRL" "\033GDS_NO" "\034RFDS_NO" "\035RFDS_CLEAR" ) + +#define MSR_FLUSH_CMD 0x10b +#define FLUSH_CMD_L1D_FLUSH 0x1 /* (1ULL << 0) */ +#define MSR_BBL_CR_ADDR 0x116 /* PII+ only */ +#define MSR_BBL_CR_DECC 0x118 /* PII+ only */ +#define MSR_BBL_CR_CTL 0x119 /* PII+ only */ +#define MSR_BBL_CR_TRIG 0x11a /* PII+ only */ +#define MSR_BBL_CR_BUSY 0x11b /* PII+ only */ +#define MSR_BBL_CR_CTR3 0x11e /* PII+ only */ +#define MSR_TSX_CTRL 0x122 +#define TSX_CTRL_RTM_DISABLE (1ULL << 0) +#define TSX_CTRL_TSX_CPUID_CLEAR (1ULL << 1) +#define MSR_MCU_OPT_CTRL 0x123 +#define RNGDS_MITG_DIS (1ULL << 0) +#define MSR_SYSENTER_CS 0x174 /* PII+ only */ +#define MSR_SYSENTER_ESP 0x175 /* PII+ only */ +#define MSR_SYSENTER_EIP 0x176 /* PII+ only */ +#define MSR_MCG_CAP 0x179 +#define MSR_MCG_STATUS 0x17a +#define MSR_MCG_CTL 0x17b +#define MSR_EVNTSEL0 0x186 +#define MSR_EVNTSEL1 0x187 +#define MSR_PERF_STATUS 0x198 /* Pentium M */ +#define MSR_PERF_CTL 0x199 /* Pentium M */ +#define PERF_CTL_TURBO 0x100000000ULL /* bit 32 - turbo mode */ +#define MSR_THERM_CONTROL 0x19a +#define MSR_THERM_INTERRUPT 0x19b +#define MSR_THERM_STATUS 0x19c +#define MSR_THERM_STATUS_VALID_BIT 0x80000000 +#define MSR_THERM_STATUS_TEMP(msr) ((msr >> 16) & 0x7f) +#define MSR_THERM2_CTL 0x19d /* Pentium M */ +#define MSR_MISC_ENABLE 0x1a0 +/* + * MSR_MISC_ENABLE (0x1a0) + * + * Enable Fast Strings: enables fast REP MOVS/REP STORS (R/W) + * Enable TCC: Enable automatic thermal control circuit (R/W) + * Performance monitoring available: 1 if enabled (R/O) + * Branch trace storage unavailable: 1 if unsupported (R/O) + * Processor event based sampling unavailable: 1 if unsupported (R/O) + * Enhanced Intel SpeedStep technology enable: 1 to enable (R/W) + * Enable monitor FSM: 1 to enable MONITOR/MWAIT (R/W) + * Limit CPUID maxval: 1 to limit CPUID leaf nodes to 0x2 and lower (R/W) + * Enable xTPR message disable: 1 to disable xTPR messages + * XD bit disable: 1 to disable NX capability (bit 34, or bit 2 of %edx/%rdx) + */ +#define MISC_ENABLE_FAST_STRINGS (1 << 0) +#define MISC_ENABLE_TCC (1 << 3) +#define MISC_ENABLE_PERF_MON_AVAILABLE (1 << 7) +#define MISC_ENABLE_BTS_UNAVAILABLE (1 << 11) +#define MISC_ENABLE_PEBS_UNAVAILABLE (1 << 12) +#define MISC_ENABLE_EIST_ENABLED (1 << 16) +#define MISC_ENABLE_ENABLE_MONITOR_FSM (1 << 18) +#define MISC_ENABLE_LIMIT_CPUID_MAXVAL (1 << 22) +#define MISC_ENABLE_xTPR_MESSAGE_DISABLE (1 << 23) +#define MISC_ENABLE_XD_BIT_DISABLE (1 << 2) + +/* + * for Core i Series and newer Xeons, see + * http://www.intel.com/content/dam/www/public/us/en/ + * documents/white-papers/cpu-monitoring-dts-peci-paper.pdf + */ +#define MSR_TEMPERATURE_TARGET 0x1a2 /* Core i Series, Newer Xeons */ +#define MSR_TEMPERATURE_TARGET_TJMAX(msr) (((msr) >> 16) & 0xff) +/* + * not documented anywhere, see intelcore_update_sensor() + * only available Core Duo and Core Solo Processors + */ +#define MSR_TEMPERATURE_TARGET_UNDOCUMENTED 0x0ee +#define MSR_TEMPERATURE_TARGET_LOW_BIT_UNDOCUMENTED 0x40000000 +#define MSR_DEBUGCTLMSR 0x1d9 +#define MSR_LASTBRANCHFROMIP 0x1db +#define MSR_LASTBRANCHTOIP 0x1dc +#define MSR_LASTINTFROMIP 0x1dd +#define MSR_LASTINTTOIP 0x1de +#define MSR_ROB_CR_BKUPTMPDR6 0x1e0 +#define MSR_MTRRvarBase 0x200 +#define MSR_MTRRfix64K_00000 0x250 +#define MSR_MTRRfix16K_80000 0x258 +#define MSR_MTRRfix4K_C0000 0x268 +#define MSR_CR_PAT 0x277 +#define MSR_MTRRdefType 0x2ff +#define MTRRdefType_FIXED_ENABLE 0x400 /* bit 10 - fixed MTRR enabled */ +#define MTRRdefType_ENABLE 0x800 /* bit 11 - MTRRs enabled */ +#define MSR_PERF_FIXED_CTR1 0x30a /* CPU_CLK_Unhalted.Core */ +#define MSR_PERF_FIXED_CTR2 0x30b /* CPU_CLK.Unhalted.Ref */ +#define MSR_PERF_FIXED_CTR_CTRL 0x38d +#define MSR_PERF_FIXED_CTR_FC_DIS 0x0 /* disable counter */ +#define MSR_PERF_FIXED_CTR_FC_1 0x1 /* count ring 1 */ +#define MSR_PERF_FIXED_CTR_FC_123 0x2 /* count rings 1,2,3 */ +#define MSR_PERF_FIXED_CTR_FC_ANY 0x3 /* count everything */ +#define MSR_PERF_FIXED_CTR_FC_MASK 0x3 +#define MSR_PERF_FIXED_CTR_FC(_i, _v) ((_v) << (4 * (_i))) +#define MSR_PERF_FIXED_CTR_ANYTHR(_i) (0x4 << (4 * (_i))) +#define MSR_PERF_FIXED_CTR_INT(_i) (0x8 << (4 * (_i))) +#define MSR_PERF_GLOBAL_CTRL 0x38f +#define MSR_PERF_GLOBAL_CTR1_EN (1ULL << 33) +#define MSR_PERF_GLOBAL_CTR2_EN (1ULL << 34) +#define MSR_PKG_C3_RESIDENCY 0x3f8 +#define MSR_PKG_C6_RESIDENCY 0x3f9 +#define MSR_PKG_C7_RESIDENCY 0x3fa +#define MSR_CORE_C3_RESIDENCY 0x3fc +#define MSR_CORE_C6_RESIDENCY 0x3fd +#define MSR_CORE_C7_RESIDENCY 0x3fe +#define MSR_MC0_CTL 0x400 +#define MSR_MC0_STATUS 0x401 +#define MSR_MC0_ADDR 0x402 +#define MSR_MC0_MISC 0x403 +#define MSR_MC1_CTL 0x404 +#define MSR_MC1_STATUS 0x405 +#define MSR_MC1_ADDR 0x406 +#define MSR_MC1_MISC 0x407 +#define MSR_MC2_CTL 0x408 +#define MSR_MC2_STATUS 0x409 +#define MSR_MC2_ADDR 0x40a +#define MSR_MC2_MISC 0x40b +#define MSR_MC4_CTL 0x40c +#define MSR_MC4_STATUS 0x40d +#define MSR_MC4_ADDR 0x40e +#define MSR_MC4_MISC 0x40f +#define MSR_MC3_CTL 0x410 +#define MSR_MC3_STATUS 0x411 +#define MSR_MC3_ADDR 0x412 +#define MSR_MC3_MISC 0x413 +#define MSR_PKG_C2_RESIDENCY 0x60d +#define MSR_PKG_C8_RESIDENCY 0x630 +#define MSR_PKG_C9_RESIDENCY 0x631 +#define MSR_PKG_C10_RESIDENCY 0x632 +#define MSR_U_CET 0x6a0 +#define MSR_CET_ENDBR_EN (1 << 2) +#define MSR_CET_NO_TRACK_EN (1 << 4) +#define MSR_S_CET 0x6a2 +#define MSR_PKRS 0x6e1 +#define MSR_XSS 0xda0 + +/* VIA MSR */ +#define MSR_CENT_TMTEMPERATURE 0x1423 /* Thermal monitor temperature */ + +/* + * AMD K6/K7 MSRs. + */ +#define MSR_K6_UWCCR 0xc0000085 +#define MSR_K7_EVNTSEL0 0xc0010000 +#define MSR_K7_EVNTSEL1 0xc0010001 +#define MSR_K7_EVNTSEL2 0xc0010002 +#define MSR_K7_EVNTSEL3 0xc0010003 +#define MSR_K7_PERFCTR0 0xc0010004 +#define MSR_K7_PERFCTR1 0xc0010005 +#define MSR_K7_PERFCTR2 0xc0010006 +#define MSR_K7_PERFCTR3 0xc0010007 + +/* + * AMD K8 (Opteron) MSRs. + */ +#define MSR_PATCH_LEVEL 0x0000008b +#define MSR_SYSCFG 0xc0000010 + +#define MSR_EFER 0xc0000080 /* Extended feature enable */ +#define EFER_SCE 0x00000001 /* SYSCALL extension */ +#define EFER_LME 0x00000100 /* Long Mode Enabled */ +#define EFER_LMA 0x00000400 /* Long Mode Active */ +#define EFER_NXE 0x00000800 /* No-Execute Enabled */ +#define EFER_SVME 0x00001000 /* SVM Enabled */ + +#define MSR_STAR 0xc0000081 /* 32 bit syscall gate addr */ +#define MSR_LSTAR 0xc0000082 /* 64 bit syscall gate addr */ +#define MSR_CSTAR 0xc0000083 /* compat syscall gate addr */ +#define MSR_SFMASK 0xc0000084 /* flags to clear on syscall */ + +#define MSR_FSBASE 0xc0000100 /* 64bit offset for fs: */ +#define MSR_GSBASE 0xc0000101 /* 64bit offset for gs: */ +#define MSR_KERNELGSBASE 0xc0000102 /* storage for swapgs ins */ +#define MSR_PATCH_LOADER 0xc0010020 +#define MSR_INT_PEN_MSG 0xc0010055 /* Interrupt pending message */ + +#define MSR_DE_CFG 0xc0011029 /* Decode Configuration */ +#define DE_CFG_721 0x00000001 /* errata 721 */ +#define DE_CFG_SERIALIZE_LFENCE (1 << 1) /* Enable serializing lfence */ +#define DE_CFG_SERIALIZE_9 (1 << 9) /* Zenbleed chickenbit */ + +#define IPM_C1E_CMP_HLT 0x10000000 +#define IPM_SMI_CMP_HLT 0x08000000 + +/* + * These require a 'passcode' for access. See cpufunc.h. + */ +#define MSR_HWCR 0xc0010015 +#define HWCR_FFDIS 0x00000040 +#define HWCR_TSCFREQSEL 0x01000000 + +#define MSR_PSTATEDEF(_n) (0xc0010064 + (_n)) +#define PSTATEDEF_EN 0x8000000000000000ULL + +#define MSR_NB_CFG 0xc001001f +#define NB_CFG_DISIOREQLOCK 0x0000000000000004ULL +#define NB_CFG_DISDATMSK 0x0000001000000000ULL + +#define MSR_SEV_GHCB 0xc0010130 +#define SEV_CPUID_REQ 0x00000004 +#define SEV_CPUID_RESP 0x00000005 + +#define MSR_SEV_STATUS 0xc0010131 +#define SEV_STAT_ENABLED 0x00000001 +#define SEV_STAT_ES_ENABLED 0x00000002 + +#define MSR_LS_CFG 0xc0011020 +#define LS_CFG_DIS_LS2_SQUISH 0x02000000 + +#define MSR_IC_CFG 0xc0011021 +#define IC_CFG_DIS_SEQ_PREFETCH 0x00000800 + +#define MSR_DC_CFG 0xc0011022 +#define DC_CFG_DIS_CNV_WC_SSO 0x00000004 +#define DC_CFG_DIS_SMC_CHK_BUF 0x00000400 + +#define MSR_BU_CFG 0xc0011023 +#define BU_CFG_THRL2IDXCMPDIS 0x0000080000000000ULL +#define BU_CFG_WBPFSMCCHKDIS 0x0000200000000000ULL +#define BU_CFG_WBENHWSBDIS 0x0001000000000000ULL + +/* + * Constants related to MTRRs + */ +#define MTRR_N64K 8 /* numbers of fixed-size entries */ +#define MTRR_N16K 16 +#define MTRR_N4K 64 + +/* + * the following four 3-byte registers control the non-cacheable regions. + * These registers must be written as three separate bytes. + * + * NCRx+0: A31-A24 of starting address + * NCRx+1: A23-A16 of starting address + * NCRx+2: A15-A12 of starting address | NCR_SIZE_xx. + * + * The non-cacheable region's starting address must be aligned to the + * size indicated by the NCR_SIZE_xx field. + */ +#define NCR1 0xc4 +#define NCR2 0xc7 +#define NCR3 0xca +#define NCR4 0xcd + +#define NCR_SIZE_0K 0 +#define NCR_SIZE_4K 1 +#define NCR_SIZE_8K 2 +#define NCR_SIZE_16K 3 +#define NCR_SIZE_32K 4 +#define NCR_SIZE_64K 5 +#define NCR_SIZE_128K 6 +#define NCR_SIZE_256K 7 +#define NCR_SIZE_512K 8 +#define NCR_SIZE_1M 9 +#define NCR_SIZE_2M 10 +#define NCR_SIZE_4M 11 +#define NCR_SIZE_8M 12 +#define NCR_SIZE_16M 13 +#define NCR_SIZE_32M 14 +#define NCR_SIZE_4G 15 + +/* + * Performance monitor events. + * + * Note that 586-class and 686-class CPUs have different performance + * monitors available, and they are accessed differently: + * + * 686-class: `rdpmc' instruction + * 586-class: `rdmsr' instruction, CESR MSR + * + * The descriptions of these events are too lengthy to include here. + * See Appendix A of "Intel Architecture Software Developer's + * Manual, Volume 3: System Programming" for more information. + */ + +/* + * 586-class CESR MSR format. Lower 16 bits is CTR0, upper 16 bits + * is CTR1. + */ + +#define PMC5_CESR_EVENT 0x003f +#define PMC5_CESR_OS 0x0040 +#define PMC5_CESR_USR 0x0080 +#define PMC5_CESR_E 0x0100 +#define PMC5_CESR_P 0x0200 + +#define PMC5_DATA_READ 0x00 +#define PMC5_DATA_WRITE 0x01 +#define PMC5_DATA_TLB_MISS 0x02 +#define PMC5_DATA_READ_MISS 0x03 +#define PMC5_DATA_WRITE_MISS 0x04 +#define PMC5_WRITE_M_E 0x05 +#define PMC5_DATA_LINES_WBACK 0x06 +#define PMC5_DATA_CACHE_SNOOP 0x07 +#define PMC5_DATA_CACHE_SNOOP_HIT 0x08 +#define PMC5_MEM_ACCESS_BOTH_PIPES 0x09 +#define PMC5_BANK_CONFLICTS 0x0a +#define PMC5_MISALIGNED_DATA 0x0b +#define PMC5_INST_READ 0x0c +#define PMC5_INST_TLB_MISS 0x0d +#define PMC5_INST_CACHE_MISS 0x0e +#define PMC5_SEGMENT_REG_LOAD 0x0f +#define PMC5_BRANCHES 0x12 +#define PMC5_BTB_HITS 0x13 +#define PMC5_BRANCH_TAKEN 0x14 +#define PMC5_PIPELINE_FLUSH 0x15 +#define PMC5_INST_EXECUTED 0x16 +#define PMC5_INST_EXECUTED_V_PIPE 0x17 +#define PMC5_BUS_UTILIZATION 0x18 +#define PMC5_WRITE_BACKUP_STALL 0x19 +#define PMC5_DATA_READ_STALL 0x1a +#define PMC5_WRITE_E_M_STALL 0x1b +#define PMC5_LOCKED_BUS 0x1c +#define PMC5_IO_CYCLE 0x1d +#define PMC5_NONCACHE_MEM_READ 0x1e +#define PMC5_AGI_STALL 0x1f +#define PMC5_FLOPS 0x22 +#define PMC5_BP0_MATCH 0x23 +#define PMC5_BP1_MATCH 0x24 +#define PMC5_BP2_MATCH 0x25 +#define PMC5_BP3_MATCH 0x26 +#define PMC5_HARDWARE_INTR 0x27 +#define PMC5_DATA_RW 0x28 +#define PMC5_DATA_RW_MISS 0x29 + +/* + * 686-class Event Selector MSR format. + */ + +#define PMC6_EVTSEL_EVENT 0x000000ff +#define PMC6_EVTSEL_UNIT 0x0000ff00 +#define PMC6_EVTSEL_UNIT_SHIFT 8 +#define PMC6_EVTSEL_USR (1 << 16) +#define PMC6_EVTSEL_OS (1 << 17) +#define PMC6_EVTSEL_E (1 << 18) +#define PMC6_EVTSEL_PC (1 << 19) +#define PMC6_EVTSEL_INT (1 << 20) +#define PMC6_EVTSEL_EN (1 << 22) /* PerfEvtSel0 only */ +#define PMC6_EVTSEL_INV (1 << 23) +#define PMC6_EVTSEL_COUNTER_MASK 0xff000000 +#define PMC6_EVTSEL_COUNTER_MASK_SHIFT 24 + +/* Data Cache Unit */ +#define PMC6_DATA_MEM_REFS 0x43 +#define PMC6_DCU_LINES_IN 0x45 +#define PMC6_DCU_M_LINES_IN 0x46 +#define PMC6_DCU_M_LINES_OUT 0x47 +#define PMC6_DCU_MISS_OUTSTANDING 0x48 + +/* Instruction Fetch Unit */ +#define PMC6_IFU_IFETCH 0x80 +#define PMC6_IFU_IFETCH_MISS 0x81 +#define PMC6_ITLB_MISS 0x85 +#define PMC6_IFU_MEM_STALL 0x86 +#define PMC6_ILD_STALL 0x87 + +/* L2 Cache */ +#define PMC6_L2_IFETCH 0x28 +#define PMC6_L2_LD 0x29 +#define PMC6_L2_ST 0x2a +#define PMC6_L2_LINES_IN 0x24 +#define PMC6_L2_LINES_OUT 0x26 +#define PMC6_L2_M_LINES_INM 0x25 +#define PMC6_L2_M_LINES_OUTM 0x27 +#define PMC6_L2_RQSTS 0x2e +#define PMC6_L2_ADS 0x21 +#define PMC6_L2_DBUS_BUSY 0x22 +#define PMC6_L2_DBUS_BUSY_RD 0x23 + +/* External Bus Logic */ +#define PMC6_BUS_DRDY_CLOCKS 0x62 +#define PMC6_BUS_LOCK_CLOCKS 0x63 +#define PMC6_BUS_REQ_OUTSTANDING 0x60 +#define PMC6_BUS_TRAN_BRD 0x65 +#define PMC6_BUS_TRAN_RFO 0x66 +#define PMC6_BUS_TRANS_WB 0x67 +#define PMC6_BUS_TRAN_IFETCH 0x68 +#define PMC6_BUS_TRAN_INVAL 0x69 +#define PMC6_BUS_TRAN_PWR 0x6a +#define PMC6_BUS_TRANS_P 0x6b +#define PMC6_BUS_TRANS_IO 0x6c +#define PMC6_BUS_TRAN_DEF 0x6d +#define PMC6_BUS_TRAN_BURST 0x6e +#define PMC6_BUS_TRAN_ANY 0x70 +#define PMC6_BUS_TRAN_MEM 0x6f +#define PMC6_BUS_DATA_RCV 0x64 +#define PMC6_BUS_BNR_DRV 0x61 +#define PMC6_BUS_HIT_DRV 0x7a +#define PMC6_BUS_HITM_DRDV 0x7b +#define PMC6_BUS_SNOOP_STALL 0x7e + +/* Floating Point Unit */ +#define PMC6_FLOPS 0xc1 +#define PMC6_FP_COMP_OPS_EXE 0x10 +#define PMC6_FP_ASSIST 0x11 +#define PMC6_MUL 0x12 +#define PMC6_DIV 0x12 +#define PMC6_CYCLES_DIV_BUSY 0x14 + +/* Memory Ordering */ +#define PMC6_LD_BLOCKS 0x03 +#define PMC6_SB_DRAINS 0x04 +#define PMC6_MISALIGN_MEM_REF 0x05 +#define PMC6_EMON_KNI_PREF_DISPATCHED 0x07 /* P-III only */ +#define PMC6_EMON_KNI_PREF_MISS 0x4b /* P-III only */ + +/* Instruction Decoding and Retirement */ +#define PMC6_INST_RETIRED 0xc0 +#define PMC6_UOPS_RETIRED 0xc2 +#define PMC6_INST_DECODED 0xd0 +#define PMC6_EMON_KNI_INST_RETIRED 0xd8 +#define PMC6_EMON_KNI_COMP_INST_RET 0xd9 + +/* Interrupts */ +#define PMC6_HW_INT_RX 0xc8 +#define PMC6_CYCLES_INT_MASKED 0xc6 +#define PMC6_CYCLES_INT_PENDING_AND_MASKED 0xc7 + +/* Branches */ +#define PMC6_BR_INST_RETIRED 0xc4 +#define PMC6_BR_MISS_PRED_RETIRED 0xc5 +#define PMC6_BR_TAKEN_RETIRED 0xc9 +#define PMC6_BR_MISS_PRED_TAKEN_RET 0xca +#define PMC6_BR_INST_DECODED 0xe0 +#define PMC6_BTB_MISSES 0xe2 +#define PMC6_BR_BOGUS 0xe4 +#define PMC6_BACLEARS 0xe6 + +/* Stalls */ +#define PMC6_RESOURCE_STALLS 0xa2 +#define PMC6_PARTIAL_RAT_STALLS 0xd2 + +/* Segment Register Loads */ +#define PMC6_SEGMENT_REG_LOADS 0x06 + +/* Clocks */ +#define PMC6_CPU_CLK_UNHALTED 0x79 + +/* MMX Unit */ +#define PMC6_MMX_INSTR_EXEC 0xb0 /* Celeron, P-II, P-IIX only */ +#define PMC6_MMX_SAT_INSTR_EXEC 0xb1 /* P-II and P-III only */ +#define PMC6_MMX_UOPS_EXEC 0xb2 /* P-II and P-III only */ +#define PMC6_MMX_INSTR_TYPE_EXEC 0xb3 /* P-II and P-III only */ +#define PMC6_FP_MMX_TRANS 0xcc /* P-II and P-III only */ +#define PMC6_MMX_ASSIST 0xcd /* P-II and P-III only */ +#define PMC6_MMX_INSTR_RET 0xc3 /* P-II only */ + +/* Segment Register Renaming */ +#define PMC6_SEG_RENAME_STALLS 0xd4 /* P-II and P-III only */ +#define PMC6_SEG_REG_RENAMES 0xd5 /* P-II and P-III only */ +#define PMC6_RET_SEG_RENAMES 0xd6 /* P-II and P-III only */ + +/* + * AMD K7 Event Selector MSR format. + */ + +#define K7_EVTSEL_EVENT 0x000000ff +#define K7_EVTSEL_UNIT 0x0000ff00 +#define K7_EVTSEL_UNIT_SHIFT 8 +#define K7_EVTSEL_USR (1 << 16) +#define K7_EVTSEL_OS (1 << 17) +#define K7_EVTSEL_E (1 << 18) +#define K7_EVTSEL_PC (1 << 19) +#define K7_EVTSEL_INT (1 << 20) +#define K7_EVTSEL_EN (1 << 22) +#define K7_EVTSEL_INV (1 << 23) +#define K7_EVTSEL_COUNTER_MASK 0xff000000 +#define K7_EVTSEL_COUNTER_MASK_SHIFT 24 + +/* Segment Register Loads */ +#define K7_SEGMENT_REG_LOADS 0x20 + +#define K7_STORES_TO_ACTIVE_INST_STREAM 0x21 + +/* Data Cache Unit */ +#define K7_DATA_CACHE_ACCESS 0x40 +#define K7_DATA_CACHE_MISS 0x41 +#define K7_DATA_CACHE_REFILL 0x42 +#define K7_DATA_CACHE_REFILL_SYSTEM 0x43 +#define K7_DATA_CACHE_WBACK 0x44 +#define K7_L2_DTLB_HIT 0x45 +#define K7_L2_DTLB_MISS 0x46 +#define K7_MISALIGNED_DATA_REF 0x47 +#define K7_SYSTEM_REQUEST 0x64 +#define K7_SYSTEM_REQUEST_TYPE 0x65 + +#define K7_SNOOP_HIT 0x73 +#define K7_SINGLE_BIT_ECC_ERROR 0x74 +#define K7_CACHE_LINE_INVAL 0x75 +#define K7_CYCLES_PROCESSOR_IS_RUNNING 0x76 +#define K7_L2_REQUEST 0x79 +#define K7_L2_REQUEST_BUSY 0x7a + +/* Instruction Fetch Unit */ +#define K7_IFU_IFETCH 0x80 +#define K7_IFU_IFETCH_MISS 0x81 +#define K7_IFU_REFILL_FROM_L2 0x82 +#define K7_IFU_REFILL_FROM_SYSTEM 0x83 +#define K7_ITLB_L1_MISS 0x84 +#define K7_ITLB_L2_MISS 0x85 +#define K7_SNOOP_RESYNC 0x86 +#define K7_IFU_STALL 0x87 + +#define K7_RETURN_STACK_HITS 0x88 +#define K7_RETURN_STACK_OVERFLOW 0x89 + +/* Retired */ +#define K7_RETIRED_INST 0xc0 +#define K7_RETIRED_OPS 0xc1 +#define K7_RETIRED_BRANCHES 0xc2 +#define K7_RETIRED_BRANCH_MISPREDICTED 0xc3 +#define K7_RETIRED_TAKEN_BRANCH 0xc4 +#define K7_RETIRED_TAKEN_BRANCH_MISPREDICTED 0xc5 +#define K7_RETIRED_FAR_CONTROL_TRANSFER 0xc6 +#define K7_RETIRED_RESYNC_BRANCH 0xc7 +#define K7_RETIRED_NEAR_RETURNS 0xc8 +#define K7_RETIRED_NEAR_RETURNS_MISPREDICTED 0xc9 +#define K7_RETIRED_INDIRECT_MISPREDICTED 0xca + +/* Interrupts */ +#define K7_CYCLES_INT_MASKED 0xcd +#define K7_CYCLES_INT_PENDING_AND_MASKED 0xce +#define K7_HW_INTR_RECV 0xcf + +#define K7_INSTRUCTION_DECODER_EMPTY 0xd0 +#define K7_DISPATCH_STALLS 0xd1 +#define K7_BRANCH_ABORTS_TO_RETIRE 0xd2 +#define K7_SERIALIZE 0xd3 +#define K7_SEGMENT_LOAD_STALL 0xd4 +#define K7_ICU_FULL 0xd5 +#define K7_RESERVATION_STATIONS_FULL 0xd6 +#define K7_FPU_FULL 0xd7 +#define K7_LS_FULL 0xd8 +#define K7_ALL_QUIET_STALL 0xd9 +#define K7_FAR_TRANSFER_OR_RESYNC_BRANCH_PENDING 0xda + +#define K7_BP0_MATCH 0xdc +#define K7_BP1_MATCH 0xdd +#define K7_BP2_MATCH 0xde +#define K7_BP3_MATCH 0xdf + +/* VIA C3 crypto featureset: for amd64_has_xcrypt */ +#define C3_HAS_AES 1 /* cpu has AES */ +#define C3_HAS_SHA 2 /* cpu has SHA1 & SHA256 */ +#define C3_HAS_MM 4 /* cpu has RSA instructions */ +#define C3_HAS_AESCTR 8 /* cpu has AES-CTR instructions */ + +/* Centaur Extended Feature flags */ +#define C3_CPUID_HAS_RNG 0x000004 +#define C3_CPUID_DO_RNG 0x000008 +#define C3_CPUID_HAS_ACE 0x000040 +#define C3_CPUID_DO_ACE 0x000080 +#define C3_CPUID_HAS_ACE2 0x000100 +#define C3_CPUID_DO_ACE2 0x000200 +#define C3_CPUID_HAS_PHE 0x000400 +#define C3_CPUID_DO_PHE 0x000800 +#define C3_CPUID_HAS_PMM 0x001000 +#define C3_CPUID_DO_PMM 0x002000 + +/* VIA C3 xcrypt-* instruction context control options */ +#define C3_CRYPT_CWLO_ROUND_M 0x0000000f +#define C3_CRYPT_CWLO_ALG_M 0x00000070 +#define C3_CRYPT_CWLO_ALG_AES 0x00000000 +#define C3_CRYPT_CWLO_KEYGEN_M 0x00000080 +#define C3_CRYPT_CWLO_KEYGEN_HW 0x00000000 +#define C3_CRYPT_CWLO_KEYGEN_SW 0x00000080 +#define C3_CRYPT_CWLO_NORMAL 0x00000000 +#define C3_CRYPT_CWLO_INTERMEDIATE 0x00000100 +#define C3_CRYPT_CWLO_ENCRYPT 0x00000000 +#define C3_CRYPT_CWLO_DECRYPT 0x00000200 +#define C3_CRYPT_CWLO_KEY128 0x0000000a /* 128bit, 10 rds */ +#define C3_CRYPT_CWLO_KEY192 0x0000040c /* 192bit, 12 rds */ +#define C3_CRYPT_CWLO_KEY256 0x0000080e /* 256bit, 15 rds */ + +/* Intel Silicon Debug */ +#define IA32_DEBUG_INTERFACE 0xc80 +#define IA32_DEBUG_INTERFACE_ENABLE 0x00000001 +#define IA32_DEBUG_INTERFACE_LOCK 0x40000000 +#define IA32_DEBUG_INTERFACE_MASK 0x80000000 + +/* + * VMX + */ +#define IA32_FEATURE_CONTROL_LOCK 0x01 +#define IA32_FEATURE_CONTROL_SMX_EN 0x02 +#define IA32_FEATURE_CONTROL_VMX_EN 0x04 +#define IA32_FEATURE_CONTROL_SENTER_EN (1ULL << 15) +#define IA32_FEATURE_CONTROL_SENTER_PARAM_MASK 0x7f00 +#define IA32_VMX_BASIC 0x480 +#define IA32_VMX_PINBASED_CTLS 0x481 +#define IA32_VMX_PROCBASED_CTLS 0x482 +#define IA32_VMX_EXIT_CTLS 0x483 +#define IA32_VMX_ENTRY_CTLS 0x484 +#define IA32_VMX_MISC 0x485 +#define IA32_VMX_CR0_FIXED0 0x486 +#define IA32_VMX_CR0_FIXED1 0x487 +#define IA32_VMX_CR4_FIXED0 0x488 +#define IA32_VMX_CR4_FIXED1 0x489 +#define IA32_VMX_PROCBASED2_CTLS 0x48B +#define IA32_VMX_EPT_VPID_CAP 0x48C +#define IA32_VMX_TRUE_PINBASED_CTLS 0x48D +#define IA32_VMX_TRUE_PROCBASED_CTLS 0x48E +#define IA32_VMX_TRUE_EXIT_CTLS 0x48F +#define IA32_VMX_TRUE_ENTRY_CTLS 0x490 +#define IA32_VMX_VMFUNC 0x491 + +#define IA32_EPT_VPID_CAP_XO_TRANSLATIONS (1ULL << 0) +#define IA32_EPT_VPID_CAP_PAGE_WALK_4 (1ULL << 6) +#define IA32_EPT_VPID_CAP_WB (1ULL << 14) +#define IA32_EPT_VPID_CAP_AD_BITS (1ULL << 21) +#define IA32_EPT_VPID_CAP_INVEPT_CONTEXT (1ULL << 25) +#define IA32_EPT_VPID_CAP_INVEPT_ALL (1ULL << 26) + +#define IA32_EPT_PAGING_CACHE_TYPE_UC 0x0 +#define IA32_EPT_PAGING_CACHE_TYPE_WB 0x6 +#define IA32_EPT_AD_BITS_ENABLE (1ULL << 6) +#define IA32_EPT_PAGE_WALK_LENGTH 0x4 + +/* VMX : IA32_VMX_BASIC bits */ +#define IA32_VMX_TRUE_CTLS_AVAIL (1ULL << 55) + +/* VMX : IA32_VMX_PINBASED_CTLS bits */ +#define IA32_VMX_EXTERNAL_INT_EXITING (1ULL << 0) +#define IA32_VMX_NMI_EXITING (1ULL << 3) +#define IA32_VMX_VIRTUAL_NMIS (1ULL << 5) +#define IA32_VMX_ACTIVATE_VMX_PREEMPTION_TIMER (1ULL << 6) +#define IA32_VMX_PROCESS_POSTED_INTERRUPTS (1ULL << 7) + +/* VMX : IA32_VMX_PROCBASED_CTLS bits */ +#define IA32_VMX_INTERRUPT_WINDOW_EXITING (1ULL << 2) +#define IA32_VMX_USE_TSC_OFFSETTING (1ULL << 3) +#define IA32_VMX_HLT_EXITING (1ULL << 7) +#define IA32_VMX_INVLPG_EXITING (1ULL << 9) +#define IA32_VMX_MWAIT_EXITING (1ULL << 10) +#define IA32_VMX_RDPMC_EXITING (1ULL << 11) +#define IA32_VMX_RDTSC_EXITING (1ULL << 12) +#define IA32_VMX_CR3_LOAD_EXITING (1ULL << 15) +#define IA32_VMX_CR3_STORE_EXITING (1ULL << 16) +#define IA32_VMX_CR8_LOAD_EXITING (1ULL << 19) +#define IA32_VMX_CR8_STORE_EXITING (1ULL << 20) +#define IA32_VMX_USE_TPR_SHADOW (1ULL << 21) +#define IA32_VMX_NMI_WINDOW_EXITING (1ULL << 22) +#define IA32_VMX_MOV_DR_EXITING (1ULL << 23) +#define IA32_VMX_UNCONDITIONAL_IO_EXITING (1ULL << 24) +#define IA32_VMX_USE_IO_BITMAPS (1ULL << 25) +#define IA32_VMX_MONITOR_TRAP_FLAG (1ULL << 27) +#define IA32_VMX_USE_MSR_BITMAPS (1ULL << 28) +#define IA32_VMX_MONITOR_EXITING (1ULL << 29) +#define IA32_VMX_PAUSE_EXITING (1ULL << 30) +#define IA32_VMX_ACTIVATE_SECONDARY_CONTROLS (1ULL << 31) + +/* VMX : IA32_VMX_PROCBASED2_CTLS bits */ +#define IA32_VMX_VIRTUALIZE_APIC (1ULL << 0) +#define IA32_VMX_ENABLE_EPT (1ULL << 1) +#define IA32_VMX_DESCRIPTOR_TABLE_EXITING (1ULL << 2) +#define IA32_VMX_ENABLE_RDTSCP (1ULL << 3) +#define IA32_VMX_VIRTUALIZE_X2APIC_MODE (1ULL << 4) +#define IA32_VMX_ENABLE_VPID (1ULL << 5) +#define IA32_VMX_WBINVD_EXITING (1ULL << 6) +#define IA32_VMX_UNRESTRICTED_GUEST (1ULL << 7) +#define IA32_VMX_APIC_REGISTER_VIRTUALIZATION (1ULL << 8) +#define IA32_VMX_VIRTUAL_INTERRUPT_DELIVERY (1ULL << 9) +#define IA32_VMX_PAUSE_LOOP_EXITING (1ULL << 10) +#define IA32_VMX_RDRAND_EXITING (1ULL << 11) +#define IA32_VMX_ENABLE_INVPCID (1ULL << 12) +#define IA32_VMX_ENABLE_VM_FUNCTIONS (1ULL << 13) +#define IA32_VMX_VMCS_SHADOWING (1ULL << 14) +#define IA32_VMX_ENABLE_ENCLS_EXITING (1ULL << 15) +#define IA32_VMX_RDSEED_EXITING (1ULL << 16) +#define IA32_VMX_ENABLE_PML (1ULL << 17) +#define IA32_VMX_EPT_VIOLATION_VE (1ULL << 18) +#define IA32_VMX_CONCEAL_VMX_FROM_PT (1ULL << 19) +#define IA32_VMX_ENABLE_XSAVES_XRSTORS (1ULL << 20) +#define IA32_VMX_ENABLE_TSC_SCALING (1ULL << 25) + +/* VMX : IA32_VMX_EXIT_CTLS bits */ +#define IA32_VMX_SAVE_DEBUG_CONTROLS (1ULL << 2) +#define IA32_VMX_HOST_SPACE_ADDRESS_SIZE (1ULL << 9) +#define IA32_VMX_LOAD_IA32_PERF_GLOBAL_CTRL_ON_EXIT (1ULL << 12) +#define IA32_VMX_ACKNOWLEDGE_INTERRUPT_ON_EXIT (1ULL << 15) +#define IA32_VMX_SAVE_IA32_PAT_ON_EXIT (1ULL << 18) +#define IA32_VMX_LOAD_IA32_PAT_ON_EXIT (1ULL << 19) +#define IA32_VMX_SAVE_IA32_EFER_ON_EXIT (1ULL << 20) +#define IA32_VMX_LOAD_IA32_EFER_ON_EXIT (1ULL << 21) +#define IA32_VMX_SAVE_VMX_PREEMPTION_TIMER (1ULL << 22) +#define IA32_VMX_CLEAR_IA32_BNDCFGS_ON_EXIT (1ULL << 23) +#define IA32_VMX_CONCEAL_VM_EXITS_FROM_PT (1ULL << 24) +#define IA32_VMX_LOAD_HOST_CET_STATE (1ULL << 28) + +/* VMX: IA32_VMX_ENTRY_CTLS bits */ +#define IA32_VMX_LOAD_DEBUG_CONTROLS (1ULL << 2) +#define IA32_VMX_IA32E_MODE_GUEST (1ULL << 9) +#define IA32_VMX_ENTRY_TO_SMM (1ULL << 10) +#define IA32_VMX_DEACTIVATE_DUAL_MONITOR_TREATMENT (1ULL << 11) +#define IA32_VMX_LOAD_IA32_PERF_GLOBAL_CTRL_ON_ENTRY (1ULL << 13) +#define IA32_VMX_LOAD_IA32_PAT_ON_ENTRY (1ULL << 14) +#define IA32_VMX_LOAD_IA32_EFER_ON_ENTRY (1ULL << 15) +#define IA32_VMX_LOAD_IA32_BNDCFGS_ON_ENTRY (1ULL << 16) +#define IA32_VMX_CONCEAL_VM_ENTRIES_FROM_PT (1ULL << 17) +#define IA32_VMX_LOAD_GUEST_CET_STATE (1ULL << 20) + +/* + * VMX : VMCS Fields + */ + +/* 16-bit control fields */ +#define VMCS_GUEST_VPID 0x0000 +#define VMCS_POSTED_INT_NOTIF_VECTOR 0x0002 +#define VMCS_EPTP_INDEX 0x0004 + +/* 16-bit guest state fields */ +#define VMCS_GUEST_IA32_ES_SEL 0x0800 +#define VMCS_GUEST_IA32_CS_SEL 0x0802 +#define VMCS_GUEST_IA32_SS_SEL 0x0804 +#define VMCS_GUEST_IA32_DS_SEL 0x0806 +#define VMCS_GUEST_IA32_FS_SEL 0x0808 +#define VMCS_GUEST_IA32_GS_SEL 0x080A +#define VMCS_GUEST_IA32_LDTR_SEL 0x080C +#define VMCS_GUEST_IA32_TR_SEL 0x080E +#define VMCS_GUEST_INTERRUPT_STATUS 0x0810 +#define VMCS_GUEST_PML_INDEX 0x0812 + +/* 16-bit host state fields */ +#define VMCS_HOST_IA32_ES_SEL 0x0C00 +#define VMCS_HOST_IA32_CS_SEL 0x0C02 +#define VMCS_HOST_IA32_SS_SEL 0x0C04 +#define VMCS_HOST_IA32_DS_SEL 0x0C06 +#define VMCS_HOST_IA32_FS_SEL 0x0C08 +#define VMCS_HOST_IA32_GS_SEL 0x0C0A +#define VMCS_HOST_IA32_TR_SEL 0x0C0C + +/* 64-bit control fields */ +#define VMCS_IO_BITMAP_A 0x2000 +#define VMCS_IO_BITMAP_B 0x2002 +#define VMCS_MSR_BITMAP_ADDRESS 0x2004 +#define VMCS_EXIT_STORE_MSR_ADDRESS 0x2006 +#define VMCS_EXIT_LOAD_MSR_ADDRESS 0x2008 +#define VMCS_ENTRY_LOAD_MSR_ADDRESS 0x200A +#define VMCS_EXECUTIVE_VMCS_POINTER 0x200C +#define VMCS_PML_ADDRESS 0x200E +#define VMCS_TSC_OFFSET 0x2010 +#define VMCS_VIRTUAL_APIC_ADDRESS 0x2012 +#define VMCS_APIC_ACCESS_ADDRESS 0x2014 +#define VMCS_POSTED_INTERRUPT_DESC 0x2016 +#define VMCS_VM_FUNCTION_CONTROLS 0x2018 +#define VMCS_GUEST_IA32_EPTP 0x201A +#define VMCS_EOI_EXIT_BITMAP_0 0x201C +#define VMCS_EOI_EXIT_BITMAP_1 0x201E +#define VMCS_EOI_EXIT_BITMAP_2 0x2020 +#define VMCS_EOI_EXIT_BITMAP_3 0x2022 +#define VMCS_EPTP_LIST_ADDRESS 0x2024 +#define VMCS_VMREAD_BITMAP_ADDRESS 0x2026 +#define VMCS_VMWRITE_BITMAP_ADDRESS 0x2028 +#define VMCS_VIRTUALIZATION_EXC_ADDRESS 0x202A +#define VMCS_XSS_EXITING_BITMAP 0x202C +#define VMCS_ENCLS_EXITING_BITMAP 0x202E +#define VMCS_TSC_MULTIPLIER 0x2032 + +/* 64-bit RO data field */ +#define VMCS_GUEST_PHYSICAL_ADDRESS 0x2400 + +/* 64-bit guest state fields */ +#define VMCS_LINK_POINTER 0x2800 +#define VMCS_GUEST_IA32_DEBUGCTL 0x2802 +#define VMCS_GUEST_IA32_PAT 0x2804 +#define VMCS_GUEST_IA32_EFER 0x2806 +#define VMCS_GUEST_IA32_PERF_GBL_CTRL 0x2808 +#define VMCS_GUEST_PDPTE0 0x280A +#define VMCS_GUEST_PDPTE1 0x280C +#define VMCS_GUEST_PDPTE2 0x280E +#define VMCS_GUEST_PDPTE3 0x2810 +#define VMCS_GUEST_IA32_BNDCFGS 0x2812 + +/* 64-bit host state fields */ +#define VMCS_HOST_IA32_PAT 0x2C00 +#define VMCS_HOST_IA32_EFER 0x2C02 +#define VMCS_HOST_IA32_PERF_GBL_CTRL 0x2C04 + +/* 32-bit control fields */ +#define VMCS_PINBASED_CTLS 0x4000 +#define VMCS_PROCBASED_CTLS 0x4002 +#define VMCS_EXCEPTION_BITMAP 0x4004 +#define VMCS_PF_ERROR_CODE_MASK 0x4006 +#define VMCS_PF_ERROR_CODE_MATCH 0x4008 +#define VMCS_CR3_TARGET_COUNT 0x400A +#define VMCS_EXIT_CTLS 0x400C +#define VMCS_EXIT_MSR_STORE_COUNT 0x400E +#define VMCS_EXIT_MSR_LOAD_COUNT 0x4010 +#define VMCS_ENTRY_CTLS 0x4012 +#define VMCS_ENTRY_MSR_LOAD_COUNT 0x4014 +#define VMCS_ENTRY_INTERRUPTION_INFO 0x4016 +#define VMCS_ENTRY_EXCEPTION_ERROR_CODE 0x4018 +#define VMCS_ENTRY_INSTRUCTION_LENGTH 0x401A +#define VMCS_TPR_THRESHOLD 0x401C +#define VMCS_PROCBASED2_CTLS 0x401E +#define VMCS_PLE_GAP 0x4020 +#define VMCS_PLE_WINDOW 0x4022 + +/* 32-bit RO data fields */ +#define VMCS_INSTRUCTION_ERROR 0x4400 +#define VMCS_EXIT_REASON 0x4402 +#define VMCS_EXIT_INTERRUPTION_INFO 0x4404 +#define VMCS_EXIT_INTERRUPTION_ERR_CODE 0x4406 +#define VMCS_IDT_VECTORING_INFO 0x4408 +#define VMCS_IDT_VECTORING_ERROR_CODE 0x440A +#define VMCS_INSTRUCTION_LENGTH 0x440C +#define VMCS_EXIT_INSTRUCTION_INFO 0x440E + +/* 32-bit guest state fields */ +#define VMCS_GUEST_IA32_ES_LIMIT 0x4800 +#define VMCS_GUEST_IA32_CS_LIMIT 0x4802 +#define VMCS_GUEST_IA32_SS_LIMIT 0x4804 +#define VMCS_GUEST_IA32_DS_LIMIT 0x4806 +#define VMCS_GUEST_IA32_FS_LIMIT 0x4808 +#define VMCS_GUEST_IA32_GS_LIMIT 0x480A +#define VMCS_GUEST_IA32_LDTR_LIMIT 0x480C +#define VMCS_GUEST_IA32_TR_LIMIT 0x480E +#define VMCS_GUEST_IA32_GDTR_LIMIT 0x4810 +#define VMCS_GUEST_IA32_IDTR_LIMIT 0x4812 +#define VMCS_GUEST_IA32_ES_AR 0x4814 +#define VMCS_GUEST_IA32_CS_AR 0x4816 +#define VMCS_GUEST_IA32_SS_AR 0x4818 +#define VMCS_GUEST_IA32_DS_AR 0x481A +#define VMCS_GUEST_IA32_FS_AR 0x481C +#define VMCS_GUEST_IA32_GS_AR 0x481E +#define VMCS_GUEST_IA32_LDTR_AR 0x4820 +#define VMCS_GUEST_IA32_TR_AR 0x4822 +#define VMCS_GUEST_INTERRUPTIBILITY_ST 0x4824 +#define VMCS_GUEST_ACTIVITY_STATE 0x4826 +#define VMCS_GUEST_SMBASE 0x4828 +#define VMCS_GUEST_IA32_SYSENTER_CS 0x482A +#define VMCS_VMX_PREEMPTION_TIMER_VAL 0x482E + +/* 32-bit host state field */ +#define VMCS_HOST_IA32_SYSENTER_CS 0x4C00 + +/* Natural-width control fields */ +#define VMCS_CR0_MASK 0x6000 +#define VMCS_CR4_MASK 0x6002 +#define VMCS_CR0_READ_SHADOW 0x6004 +#define VMCS_CR4_READ_SHADOW 0x6006 +#define VMCS_CR3_TARGET_0 0x6008 +#define VMCS_CR3_TARGET_1 0x600A +#define VMCS_CR3_TARGET_2 0x600C +#define VMCS_CR3_TARGET_3 0x600E + +/* Natural-width RO fields */ +#define VMCS_GUEST_EXIT_QUALIFICATION 0x6400 +#define VMCS_IO_RCX 0x6402 +#define VMCS_IO_RSI 0x6404 +#define VMCS_IO_RDI 0x6406 +#define VMCS_IO_RIP 0x6408 +#define VMCS_GUEST_LINEAR_ADDRESS 0x640A + +/* Natural-width guest state fields */ +#define VMCS_GUEST_IA32_CR0 0x6800 +#define VMCS_GUEST_IA32_CR3 0x6802 +#define VMCS_GUEST_IA32_CR4 0x6804 +#define VMCS_GUEST_IA32_ES_BASE 0x6806 +#define VMCS_GUEST_IA32_CS_BASE 0x6808 +#define VMCS_GUEST_IA32_SS_BASE 0x680A +#define VMCS_GUEST_IA32_DS_BASE 0x680C +#define VMCS_GUEST_IA32_FS_BASE 0x680E +#define VMCS_GUEST_IA32_GS_BASE 0x6810 +#define VMCS_GUEST_IA32_LDTR_BASE 0x6812 +#define VMCS_GUEST_IA32_TR_BASE 0x6814 +#define VMCS_GUEST_IA32_GDTR_BASE 0x6816 +#define VMCS_GUEST_IA32_IDTR_BASE 0x6818 +#define VMCS_GUEST_IA32_DR7 0x681A +#define VMCS_GUEST_IA32_RSP 0x681C +#define VMCS_GUEST_IA32_RIP 0x681E +#define VMCS_GUEST_IA32_RFLAGS 0x6820 +#define VMCS_GUEST_PENDING_DBG_EXC 0x6822 +#define VMCS_GUEST_IA32_SYSENTER_ESP 0x6824 +#define VMCS_GUEST_IA32_SYSENTER_EIP 0x6826 +#define VMCS_GUEST_IA32_S_CET 0x6828 + +/* Natural-width host state fields */ +#define VMCS_HOST_IA32_CR0 0x6C00 +#define VMCS_HOST_IA32_CR3 0x6C02 +#define VMCS_HOST_IA32_CR4 0x6C04 +#define VMCS_HOST_IA32_FS_BASE 0x6C06 +#define VMCS_HOST_IA32_GS_BASE 0x6C08 +#define VMCS_HOST_IA32_TR_BASE 0x6C0A +#define VMCS_HOST_IA32_GDTR_BASE 0x6C0C +#define VMCS_HOST_IA32_IDTR_BASE 0x6C0E +#define VMCS_HOST_IA32_SYSENTER_ESP 0x6C10 +#define VMCS_HOST_IA32_SYSENTER_EIP 0x6C12 +#define VMCS_HOST_IA32_RSP 0x6C14 +#define VMCS_HOST_IA32_RIP 0x6C16 +#define VMCS_HOST_IA32_S_CET 0x6C18 + +#define IA32_VMX_INVVPID_INDIV_ADDR_CTX 0x0 +#define IA32_VMX_INVVPID_SINGLE_CTX 0x1 +#define IA32_VMX_INVVPID_ALL_CTX 0x2 +#define IA32_VMX_INVVPID_SINGLE_CTX_GLB 0x3 + +#define IA32_VMX_INVEPT_SINGLE_CTX 0x1 +#define IA32_VMX_INVEPT_GLOBAL_CTX 0x2 + +#define IA32_VMX_EPT_FAULT_READ (1ULL << 0) +#define IA32_VMX_EPT_FAULT_WRITE (1ULL << 1) +#define IA32_VMX_EPT_FAULT_EXEC (1ULL << 2) + +#define IA32_VMX_EPT_FAULT_WAS_READABLE (1ULL << 3) +#define IA32_VMX_EPT_FAULT_WAS_WRITABLE (1ULL << 4) +#define IA32_VMX_EPT_FAULT_WAS_EXECABLE (1ULL << 5) + +#define IA32_VMX_MSR_LIST_SIZE_MASK (7ULL << 25) +#define IA32_VMX_CR3_TGT_SIZE_MASK (0x1FFULL << 16) + +#define VMX_SKIP_L1D_FLUSH 2 +#define VMX_L1D_FLUSH_SIZE (64 * 1024) + +/* + * SVM + */ +#define MSR_AMD_VM_CR 0xc0010114 +#define MSR_AMD_VM_HSAVE_PA 0xc0010117 +#define CPUID_AMD_SVM_CAP 0x8000000A +#define AMD_SVM_NESTED_PAGING_CAP (1 << 0) +#define AMD_SVM_VMCB_CLEAN_CAP (1 << 5) +#define AMD_SVM_FLUSH_BY_ASID_CAP (1 << 6) +#define AMD_SVM_DECODE_ASSIST_CAP (1 << 7) +#define AMD_SVMDIS 0x10 + +#define SVM_TLB_CONTROL_FLUSH_NONE 0 +#define SVM_TLB_CONTROL_FLUSH_ALL 1 +#define SVM_TLB_CONTROL_FLUSH_ASID 3 +#define SVM_TLB_CONTROL_FLUSH_ASID_GLB 7 + +#define SVM_CLEANBITS_I (1 << 0) +#define SVM_CLEANBITS_IOPM (1 << 1) +#define SVM_CLEANBITS_ASID (1 << 2) +#define SVM_CLEANBITS_TPR (1 << 3) +#define SVM_CLEANBITS_NP (1 << 4) +#define SVM_CLEANBITS_CR (1 << 5) +#define SVM_CLEANBITS_DR (1 << 6) +#define SVM_CLEANBITS_DT (1 << 7) +#define SVM_CLEANBITS_SEG (1 << 8) +#define SVM_CLEANBITS_CR2 (1 << 9) +#define SVM_CLEANBITS_LBR (1 << 10) +#define SVM_CLEANBITS_AVIC (1 << 11) + +#define SVM_CLEANBITS_ALL \ + (SVM_CLEANBITS_I | SVM_CLEANBITS_IOPM | SVM_CLEANBITS_ASID | \ + SVM_CLEANBITS_TPR | SVM_CLEANBITS_NP | SVM_CLEANBITS_CR | \ + SVM_CLEANBITS_DR | SVM_CLEANBITS_DT | SVM_CLEANBITS_SEG | \ + SVM_CLEANBITS_CR2 | SVM_CLEANBITS_LBR | SVM_CLEANBITS_AVIC ) + +#define SVM_INTR_MISC_V_IGN_TPR 0x10 + +/* + * SVM : VMCB intercepts + */ +#define SVM_INTERCEPT_CR0_READ (1UL << 0) +#define SVM_INTERCEPT_CR1_READ (1UL << 1) +#define SVM_INTERCEPT_CR2_READ (1UL << 2) +#define SVM_INTERCEPT_CR3_READ (1UL << 2) +#define SVM_INTERCEPT_CR4_READ (1UL << 4) +#define SVM_INTERCEPT_CR5_READ (1UL << 5) +#define SVM_INTERCEPT_CR6_READ (1UL << 6) +#define SVM_INTERCEPT_CR7_READ (1UL << 7) +#define SVM_INTERCEPT_CR8_READ (1UL << 8) +#define SVM_INTERCEPT_CR9_READ (1UL << 9) +#define SVM_INTERCEPT_CR10_READ (1UL << 10) +#define SVM_INTERCEPT_CR11_READ (1UL << 11) +#define SVM_INTERCEPT_CR12_READ (1UL << 12) +#define SVM_INTERCEPT_CR13_READ (1UL << 13) +#define SVM_INTERCEPT_CR14_READ (1UL << 14) +#define SVM_INTERCEPT_CR15_READ (1UL << 15) +#define SVM_INTERCEPT_CR0_WRITE (1UL << 16) +#define SVM_INTERCEPT_CR1_WRITE (1UL << 17) +#define SVM_INTERCEPT_CR2_WRITE (1UL << 18) +#define SVM_INTERCEPT_CR3_WRITE (1UL << 19) +#define SVM_INTERCEPT_CR4_WRITE (1UL << 20) +#define SVM_INTERCEPT_CR5_WRITE (1UL << 21) +#define SVM_INTERCEPT_CR6_WRITE (1UL << 22) +#define SVM_INTERCEPT_CR7_WRITE (1UL << 23) +#define SVM_INTERCEPT_CR8_WRITE (1UL << 24) +#define SVM_INTERCEPT_CR9_WRITE (1UL << 25) +#define SVM_INTERCEPT_CR10_WRITE (1UL << 26) +#define SVM_INTERCEPT_CR11_WRITE (1UL << 27) +#define SVM_INTERCEPT_CR12_WRITE (1UL << 28) +#define SVM_INTERCEPT_CR13_WRITE (1UL << 29) +#define SVM_INTERCEPT_CR14_WRITE (1UL << 30) +#define SVM_INTERCEPT_CR15_WRITE (1UL << 31) +#define SVM_INTERCEPT_DR0_READ (1UL << 0) +#define SVM_INTERCEPT_DR1_READ (1UL << 1) +#define SVM_INTERCEPT_DR2_READ (1UL << 2) +#define SVM_INTERCEPT_DR3_READ (1UL << 2) +#define SVM_INTERCEPT_DR4_READ (1UL << 4) +#define SVM_INTERCEPT_DR5_READ (1UL << 5) +#define SVM_INTERCEPT_DR6_READ (1UL << 6) +#define SVM_INTERCEPT_DR7_READ (1UL << 7) +#define SVM_INTERCEPT_DR8_READ (1UL << 8) +#define SVM_INTERCEPT_DR9_READ (1UL << 9) +#define SVM_INTERCEPT_DR10_READ (1UL << 10) +#define SVM_INTERCEPT_DR11_READ (1UL << 11) +#define SVM_INTERCEPT_DR12_READ (1UL << 12) +#define SVM_INTERCEPT_DR13_READ (1UL << 13) +#define SVM_INTERCEPT_DR14_READ (1UL << 14) +#define SVM_INTERCEPT_DR15_READ (1UL << 15) +#define SVM_INTERCEPT_DR0_WRITE (1UL << 16) +#define SVM_INTERCEPT_DR1_WRITE (1UL << 17) +#define SVM_INTERCEPT_DR2_WRITE (1UL << 18) +#define SVM_INTERCEPT_DR3_WRITE (1UL << 19) +#define SVM_INTERCEPT_DR4_WRITE (1UL << 20) +#define SVM_INTERCEPT_DR5_WRITE (1UL << 21) +#define SVM_INTERCEPT_DR6_WRITE (1UL << 22) +#define SVM_INTERCEPT_DR7_WRITE (1UL << 23) +#define SVM_INTERCEPT_DR8_WRITE (1UL << 24) +#define SVM_INTERCEPT_DR9_WRITE (1UL << 25) +#define SVM_INTERCEPT_DR10_WRITE (1UL << 26) +#define SVM_INTERCEPT_DR11_WRITE (1UL << 27) +#define SVM_INTERCEPT_DR12_WRITE (1UL << 28) +#define SVM_INTERCEPT_DR13_WRITE (1UL << 29) +#define SVM_INTERCEPT_DR14_WRITE (1UL << 30) +#define SVM_INTERCEPT_DR15_WRITE (1UL << 31) +#define SVM_INTERCEPT_INTR (1UL << 0) +#define SVM_INTERCEPT_NMI (1UL << 1) +#define SVM_INTERCEPT_SMI (1UL << 2) +#define SVM_INTERCEPT_INIT (1UL << 3) +#define SVM_INTERCEPT_VINTR (1UL << 4) +#define SVM_INTERCEPT_CR0_SEL_WRITE (1UL << 5) +#define SVM_INTERCEPT_IDTR_READ (1UL << 6) +#define SVM_INTERCEPT_GDTR_READ (1UL << 7) +#define SVM_INTERCEPT_LDTR_READ (1UL << 8) +#define SVM_INTERCEPT_TR_READ (1UL << 9) +#define SVM_INTERCEPT_IDTR_WRITE (1UL << 10) +#define SVM_INTERCEPT_GDTR_WRITE (1UL << 11) +#define SVM_INTERCEPT_LDTR_WRITE (1UL << 12) +#define SVM_INTERCEPT_TR_WRITE (1UL << 13) +#define SVM_INTERCEPT_RDTSC (1UL << 14) +#define SVM_INTERCEPT_RDPMC (1UL << 15) +#define SVM_INTERCEPT_PUSHF (1UL << 16) +#define SVM_INTERCEPT_POPF (1UL << 17) +#define SVM_INTERCEPT_CPUID (1UL << 18) +#define SVM_INTERCEPT_RSM (1UL << 19) +#define SVM_INTERCEPT_IRET (1UL << 20) +#define SVM_INTERCEPT_INTN (1UL << 21) +#define SVM_INTERCEPT_INVD (1UL << 22) +#define SVM_INTERCEPT_PAUSE (1UL << 23) +#define SVM_INTERCEPT_HLT (1UL << 24) +#define SVM_INTERCEPT_INVLPG (1UL << 25) +#define SVM_INTERCEPT_INVLPGA (1UL << 26) +#define SVM_INTERCEPT_INOUT (1UL << 27) +#define SVM_INTERCEPT_MSR (1UL << 28) +#define SVM_INTERCEPT_TASK_SWITCH (1UL << 29) +#define SVM_INTERCEPT_FERR_FREEZE (1UL << 30) +#define SVM_INTERCEPT_SHUTDOWN (1UL << 31) +#define SVM_INTERCEPT_VMRUN (1UL << 0) +#define SVM_INTERCEPT_VMMCALL (1UL << 1) +#define SVM_INTERCEPT_VMLOAD (1UL << 2) +#define SVM_INTERCEPT_VMSAVE (1UL << 3) +#define SVM_INTERCEPT_STGI (1UL << 4) +#define SVM_INTERCEPT_CLGI (1UL << 5) +#define SVM_INTERCEPT_SKINIT (1UL << 6) +#define SVM_INTERCEPT_RDTSCP (1UL << 7) +#define SVM_INTERCEPT_ICEBP (1UL << 8) +#define SVM_INTERCEPT_WBINVD (1UL << 9) +#define SVM_INTERCEPT_MONITOR (1UL << 10) +#define SVM_INTERCEPT_MWAIT_UNCOND (1UL << 11) +#define SVM_INTERCEPT_MWAIT_COND (1UL << 12) +#define SVM_INTERCEPT_XSETBV (1UL << 13) +#define SVM_INTERCEPT_EFER_WRITE (1UL << 15) +#define SVM_INTERCEPT_CR0_WRITE_POST (1UL << 16) +#define SVM_INTERCEPT_CR1_WRITE_POST (1UL << 17) +#define SVM_INTERCEPT_CR2_WRITE_POST (1UL << 18) +#define SVM_INTERCEPT_CR3_WRITE_POST (1UL << 19) +#define SVM_INTERCEPT_CR4_WRITE_POST (1UL << 20) +#define SVM_INTERCEPT_CR5_WRITE_POST (1UL << 21) +#define SVM_INTERCEPT_CR6_WRITE_POST (1UL << 22) +#define SVM_INTERCEPT_CR7_WRITE_POST (1UL << 23) +#define SVM_INTERCEPT_CR8_WRITE_POST (1UL << 24) +#define SVM_INTERCEPT_CR9_WRITE_POST (1UL << 25) +#define SVM_INTERCEPT_CR10_WRITE_POST (1UL << 26) +#define SVM_INTERCEPT_CR11_WRITE_POST (1UL << 27) +#define SVM_INTERCEPT_CR12_WRITE_POST (1UL << 28) +#define SVM_INTERCEPT_CR13_WRITE_POST (1UL << 29) +#define SVM_INTERCEPT_CR14_WRITE_POST (1UL << 30) +#define SVM_INTERCEPT_CR15_WRITE_POST (1UL << 31) + +/* + * SME and SEV + */ +#define CPUID_AMD_SEV_CAP 0x8000001F +#define AMD_SME_CAP (1UL << 0) +#define AMD_SEV_CAP (1UL << 1) + +/* + * PAT + */ +#define PATENTRY(n, type) (type << ((n) * 8)) +#define PAT_UC 0x0UL +#define PAT_WC 0x1UL +#define PAT_WT 0x4UL +#define PAT_WP 0x5UL +#define PAT_WB 0x6UL +#define PAT_UCMINUS 0x7UL + +/* + * XSAVE subfeatures (cpuid 0xd, leaf 1) + */ +#define XSAVE_XSAVEOPT 0x01UL +#define XSAVE_XSAVEC 0x02UL +#define XSAVE_XGETBV1 0x04UL +#define XSAVE_XSAVES 0x08UL +#define XSAVE_XFD 0x10UL +#define XSAVE_BITS \ + ("\20" "\01XSAVEOPT" "\02XSAVEC" "\03XGETBV1" "\04XSAVES" "\05XFD" ) + +/* + * Default cr0 and cr4 flags. + */ +#define CR0_DEFAULT (CR0_PE|CR0_PG|CR0_NE|CR0_WP) +#define CR4_DEFAULT (CR4_PAE|CR4_PGE|CR4_PSE|CR4_OSFXSR|CR4_OSXMMEXCPT) \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/sysarch.h b/lib/libc/include/x86_64-openbsd-none/machine/sysarch.h new file mode 100644 index 0000000000..aea941c711 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/sysarch.h @@ -0,0 +1,28 @@ +/* $OpenBSD: sysarch.h,v 1.14 2018/01/07 18:54:44 guenther Exp $ */ +/* $NetBSD: sysarch.h,v 1.1 2003/04/26 18:39:48 fvdl Exp $ */ + +#ifndef _MACHINE_SYSARCH_H_ +#define _MACHINE_SYSARCH_H_ + +/* + * Architecture specific syscalls (amd64) + */ +#define AMD64_IOPL 2 + +struct amd64_iopl_args { + int iopl; +}; + +#ifdef _KERNEL +int amd64_iopl(struct proc *, void *, register_t *); +#else + +#include + +__BEGIN_DECLS +int amd64_iopl(int); +int sysarch(int, void *); +__END_DECLS +#endif + +#endif /* !_MACHINE_SYSARCH_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/tcb.h b/lib/libc/include/x86_64-openbsd-none/machine/tcb.h new file mode 100644 index 0000000000..1d7d3135de --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/tcb.h @@ -0,0 +1,53 @@ +/* $OpenBSD: tcb.h,v 1.6 2017/10/13 05:14:02 guenther Exp $ */ + +/* + * Copyright (c) 2011 Philip Guenther + * + * 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 + +void *tcb_get(struct proc *_p); +void tcb_set(struct proc *_p, void *_newtcb); + +#define TCB_GET(p) tcb_get(p) +#define TCB_SET(p, addr) tcb_set(p, addr) + +/* address must be in canonical form; requiring lower-half is okay */ +#define TCB_INVALID(addr) ((u_long)(addr) > 0x00007fffffffffff) + +#else /* _KERNEL */ + +/* ELF TLS ABI calls for big TCB, with static TLS data at negative offsets */ +#define TLS_VARIANT 2 + +/* Read a slot from the TCB */ +static inline void * +__amd64_read_tcb(long offset) +{ + void *val; + __asm__ ("movq %%fs:(%1),%0" : "=r" (val) : "r" (offset)); + return val; +} + +/* Get a pointer to the TCB itself */ +#define TCB_GET() __amd64_read_tcb(0) + +/* Setting the TCB pointer can only be done via syscall, so no TCB_SET() */ + +#endif /* _KERNEL */ +#endif /* _MACHINE_TCB_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/timetc.h b/lib/libc/include/x86_64-openbsd-none/machine/timetc.h new file mode 100644 index 0000000000..6680584078 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/timetc.h @@ -0,0 +1,24 @@ +/* $OpenBSD: timetc.h,v 1.3 2022/09/22 04:57:08 robert Exp $ */ +/* + * Copyright (c) 2020 Paul Irofti + * + * 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_TIMETC_H_ +#define _MACHINE_TIMETC_H_ + +#define TC_TSC_LFENCE 1 +#define TC_TSC_RDTSCP 2 + +#endif /* _MACHINE_TIMETC_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/trap.h b/lib/libc/include/x86_64-openbsd-none/machine/trap.h new file mode 100644 index 0000000000..f8b9fe7633 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/trap.h @@ -0,0 +1,65 @@ +/* $OpenBSD: trap.h,v 1.6 2025/06/23 11:33:39 bluhm Exp $ */ +/* $NetBSD: trap.h,v 1.4 1994/10/27 04:16:30 cgd 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. + * + * @(#)trap.h 5.4 (Berkeley) 5/9/91 + */ + +/* + * Trap type values + * also known in trap.c for name strings + */ + +#define T_PRIVINFLT 0 /* privileged instruction */ +#define T_BPTFLT 1 /* breakpoint trap */ +#define T_ARITHTRAP 2 /* arithmetic trap */ +#define T_RESERVED 3 /* reserved fault base */ +#define T_PROTFLT 4 /* protection fault */ +#define T_TRCTRAP 5 /* trace trap */ +#define T_PAGEFLT 6 /* page fault */ +#define T_ALIGNFLT 7 /* alignment fault */ +#define T_DIVIDE 8 /* integer divide fault */ +#define T_NMI 9 /* non-maskable interrupt */ +#define T_OFLOW 10 /* overflow trap */ +#define T_BOUND 11 /* bounds check fault */ +#define T_DNA 12 /* device not available fault */ +#define T_DOUBLEFLT 13 /* double fault */ +#define T_FPOPFLT 14 /* fp coprocessor operand fetch fault (![P]Pro)*/ +#define T_TSSFLT 15 /* invalid tss fault */ +#define T_SEGNPFLT 16 /* segment not present fault */ +#define T_STKFLT 17 /* stack fault */ +#define T_MCA 18 /* machine check ([P]Pro) */ +#define T_XMM 19 /* SSE FP exception */ +#define T_VE 20 /* virtualization exception */ +#define T_CP 21 /* control protection exception */ +#define T_VC 29 /* VMM communication exception */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/tss.h b/lib/libc/include/x86_64-openbsd-none/machine/tss.h new file mode 100644 index 0000000000..e6679df978 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/tss.h @@ -0,0 +1,62 @@ +/* $OpenBSD: tss.h,v 1.4 2011/03/23 16:54:34 pirofti Exp $ */ +/* $NetBSD: tss.h,v 1.1 2003/04/26 18:39:49 fvdl Exp $ */ + +/* + * Copyright (c) 2001 Wasabi Systems, Inc. + * All rights reserved. + * + * Written by Frank van der Linden for Wasabi Systems, Inc. + * + * 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 for the NetBSD Project by + * Wasabi Systems, Inc. + * 4. The name of Wasabi Systems, Inc. may not be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC + * 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_TSS_H_ +#define _MACHINE_TSS_H_ + +/* + * TSS structure. Since TSS hw switching is not supported in long + * mode, this is mainly there for the I/O permission map in + * normal processes. + */ + +struct x86_64_tss { + u_int32_t tss_reserved1; + u_int64_t tss_rsp0; + u_int64_t tss_rsp1; + u_int64_t tss_rsp2; + u_int32_t tss_reserved2; + u_int32_t tss_reserved3; + u_int64_t tss_ist[7]; + u_int32_t tss_reserved4; + u_int32_t tss_reserved5; + u_int16_t tss_reserved6; + u_int16_t tss_iobase; +} __packed; + +#endif /* _MACHINE_TSS_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/vga_post.h b/lib/libc/include/x86_64-openbsd-none/machine/vga_post.h new file mode 100644 index 0000000000..bbf947e991 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/vga_post.h @@ -0,0 +1,43 @@ +/* $NetBSD: vga_post.h,v 1.2 2008/03/29 17:40:22 jmcneill Exp $ */ +/* $OpenBSD: vga_post.h,v 1.2 2011/03/23 16:54:34 pirofti Exp $ */ + +/*- + * Copyright (c) 2007 Joerg Sonnenberger . + * 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 COPYRIGHT HOLDERS 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 + * COPYRIGHT HOLDERS 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_VGA_POST_H_ +#define _MACHINE_VGA_POST_H_ + +#ifdef _KERNEL +struct vga_post; + +struct vga_post *vga_post_init(int, int, int); +void vga_post_free(struct vga_post *); +void vga_post_call(struct vga_post *); +#endif +#endif \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/vmmvar.h b/lib/libc/include/x86_64-openbsd-none/machine/vmmvar.h new file mode 100644 index 0000000000..03006e3072 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/vmmvar.h @@ -0,0 +1,1075 @@ +/* $OpenBSD: vmmvar.h,v 1.117 2025/09/17 18:37:44 sf Exp $ */ +/* + * Copyright (c) 2014 Mike Larkin + * + * 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. + */ + +/* + * CPU capabilities for VMM operation + */ +#ifndef _MACHINE_VMMVAR_H_ +#define _MACHINE_VMMVAR_H_ + +#ifndef _LOCORE + +#define VMM_HV_SIGNATURE "OpenBSDVMM58" + +/* VMX: Basic Exit Reasons */ +#define VMX_EXIT_NMI 0 +#define VMX_EXIT_EXTINT 1 +#define VMX_EXIT_TRIPLE_FAULT 2 +#define VMX_EXIT_INIT 3 +#define VMX_EXIT_SIPI 4 +#define VMX_EXIT_IO_SMI 5 +#define VMX_EXIT_OTHER_SMI 6 +#define VMX_EXIT_INT_WINDOW 7 +#define VMX_EXIT_NMI_WINDOW 8 +#define VMX_EXIT_TASK_SWITCH 9 +#define VMX_EXIT_CPUID 10 +#define VMX_EXIT_GETSEC 11 +#define VMX_EXIT_HLT 12 +#define VMX_EXIT_INVD 13 +#define VMX_EXIT_INVLPG 14 +#define VMX_EXIT_RDPMC 15 +#define VMX_EXIT_RDTSC 16 +#define VMX_EXIT_RSM 17 +#define VMX_EXIT_VMCALL 18 +#define VMX_EXIT_VMCLEAR 19 +#define VMX_EXIT_VMLAUNCH 20 +#define VMX_EXIT_VMPTRLD 21 +#define VMX_EXIT_VMPTRST 22 +#define VMX_EXIT_VMREAD 23 +#define VMX_EXIT_VMRESUME 24 +#define VMX_EXIT_VMWRITE 25 +#define VMX_EXIT_VMXOFF 26 +#define VMX_EXIT_VMXON 27 +#define VMX_EXIT_CR_ACCESS 28 +#define VMX_EXIT_MOV_DR 29 +#define VMX_EXIT_IO 30 +#define VMX_EXIT_RDMSR 31 +#define VMX_EXIT_WRMSR 32 +#define VMX_EXIT_ENTRY_FAILED_GUEST_STATE 33 +#define VMX_EXIT_ENTRY_FAILED_MSR_LOAD 34 +#define VMX_EXIT_MWAIT 36 +#define VMX_EXIT_MTF 37 +#define VMX_EXIT_MONITOR 39 +#define VMX_EXIT_PAUSE 40 +#define VMX_EXIT_ENTRY_FAILED_MCE 41 +#define VMX_EXIT_TPR_BELOW_THRESHOLD 43 +#define VMX_EXIT_APIC_ACCESS 44 +#define VMX_EXIT_VIRTUALIZED_EOI 45 +#define VMX_EXIT_GDTR_IDTR 46 +#define VMX_EXIT_LDTR_TR 47 +#define VMX_EXIT_EPT_VIOLATION 48 +#define VMX_EXIT_EPT_MISCONFIGURATION 49 +#define VMX_EXIT_INVEPT 50 +#define VMX_EXIT_RDTSCP 51 +#define VMX_EXIT_VMX_PREEMPTION_TIMER_EXPIRED 52 +#define VMX_EXIT_INVVPID 53 +#define VMX_EXIT_WBINVD 54 +#define VMX_EXIT_XSETBV 55 +#define VMX_EXIT_APIC_WRITE 56 +#define VMX_EXIT_RDRAND 57 +#define VMX_EXIT_INVPCID 58 +#define VMX_EXIT_VMFUNC 59 +#define VMX_EXIT_RDSEED 61 +#define VMX_EXIT_XSAVES 63 +#define VMX_EXIT_XRSTORS 64 + +#define VM_EXIT_TERMINATED 0xFFFE +#define VM_EXIT_NONE 0xFFFF + +/* + * VMX: Misc defines + */ +#define VMX_MAX_CR3_TARGETS 256 +#define VMX_VMCS_PA_CLEAR 0xFFFFFFFFFFFFFFFFUL + +#endif /* ! _LOCORE */ + +/* + * SVM: Intercept codes (exit reasons) + */ +#define SVM_VMEXIT_CR0_READ 0x00 +#define SVM_VMEXIT_CR1_READ 0x01 +#define SVM_VMEXIT_CR2_READ 0x02 +#define SVM_VMEXIT_CR3_READ 0x03 +#define SVM_VMEXIT_CR4_READ 0x04 +#define SVM_VMEXIT_CR5_READ 0x05 +#define SVM_VMEXIT_CR6_READ 0x06 +#define SVM_VMEXIT_CR7_READ 0x07 +#define SVM_VMEXIT_CR8_READ 0x08 +#define SVM_VMEXIT_CR9_READ 0x09 +#define SVM_VMEXIT_CR10_READ 0x0A +#define SVM_VMEXIT_CR11_READ 0x0B +#define SVM_VMEXIT_CR12_READ 0x0C +#define SVM_VMEXIT_CR13_READ 0x0D +#define SVM_VMEXIT_CR14_READ 0x0E +#define SVM_VMEXIT_CR15_READ 0x0F +#define SVM_VMEXIT_CR0_WRITE 0x10 +#define SVM_VMEXIT_CR1_WRITE 0x11 +#define SVM_VMEXIT_CR2_WRITE 0x12 +#define SVM_VMEXIT_CR3_WRITE 0x13 +#define SVM_VMEXIT_CR4_WRITE 0x14 +#define SVM_VMEXIT_CR5_WRITE 0x15 +#define SVM_VMEXIT_CR6_WRITE 0x16 +#define SVM_VMEXIT_CR7_WRITE 0x17 +#define SVM_VMEXIT_CR8_WRITE 0x18 +#define SVM_VMEXIT_CR9_WRITE 0x19 +#define SVM_VMEXIT_CR10_WRITE 0x1A +#define SVM_VMEXIT_CR11_WRITE 0x1B +#define SVM_VMEXIT_CR12_WRITE 0x1C +#define SVM_VMEXIT_CR13_WRITE 0x1D +#define SVM_VMEXIT_CR14_WRITE 0x1E +#define SVM_VMEXIT_CR15_WRITE 0x1F +#define SVM_VMEXIT_DR0_READ 0x20 +#define SVM_VMEXIT_DR1_READ 0x21 +#define SVM_VMEXIT_DR2_READ 0x22 +#define SVM_VMEXIT_DR3_READ 0x23 +#define SVM_VMEXIT_DR4_READ 0x24 +#define SVM_VMEXIT_DR5_READ 0x25 +#define SVM_VMEXIT_DR6_READ 0x26 +#define SVM_VMEXIT_DR7_READ 0x27 +#define SVM_VMEXIT_DR8_READ 0x28 +#define SVM_VMEXIT_DR9_READ 0x29 +#define SVM_VMEXIT_DR10_READ 0x2A +#define SVM_VMEXIT_DR11_READ 0x2B +#define SVM_VMEXIT_DR12_READ 0x2C +#define SVM_VMEXIT_DR13_READ 0x2D +#define SVM_VMEXIT_DR14_READ 0x2E +#define SVM_VMEXIT_DR15_READ 0x2F +#define SVM_VMEXIT_DR0_WRITE 0x30 +#define SVM_VMEXIT_DR1_WRITE 0x31 +#define SVM_VMEXIT_DR2_WRITE 0x32 +#define SVM_VMEXIT_DR3_WRITE 0x33 +#define SVM_VMEXIT_DR4_WRITE 0x34 +#define SVM_VMEXIT_DR5_WRITE 0x35 +#define SVM_VMEXIT_DR6_WRITE 0x36 +#define SVM_VMEXIT_DR7_WRITE 0x37 +#define SVM_VMEXIT_DR8_WRITE 0x38 +#define SVM_VMEXIT_DR9_WRITE 0x39 +#define SVM_VMEXIT_DR10_WRITE 0x3A +#define SVM_VMEXIT_DR11_WRITE 0x3B +#define SVM_VMEXIT_DR12_WRITE 0x3C +#define SVM_VMEXIT_DR13_WRITE 0x3D +#define SVM_VMEXIT_DR14_WRITE 0x3E +#define SVM_VMEXIT_DR15_WRITE 0x3F +#define SVM_VMEXIT_EXCP0 0x40 +#define SVM_VMEXIT_EXCP1 0x41 +#define SVM_VMEXIT_EXCP2 0x42 +#define SVM_VMEXIT_EXCP3 0x43 +#define SVM_VMEXIT_EXCP4 0x44 +#define SVM_VMEXIT_EXCP5 0x45 +#define SVM_VMEXIT_EXCP6 0x46 +#define SVM_VMEXIT_EXCP7 0x47 +#define SVM_VMEXIT_EXCP8 0x48 +#define SVM_VMEXIT_EXCP9 0x49 +#define SVM_VMEXIT_EXCP10 0x4A +#define SVM_VMEXIT_EXCP11 0x4B +#define SVM_VMEXIT_EXCP12 0x4C +#define SVM_VMEXIT_EXCP13 0x4D +#define SVM_VMEXIT_EXCP14 0x4E +#define SVM_VMEXIT_EXCP15 0x4F +#define SVM_VMEXIT_EXCP16 0x50 +#define SVM_VMEXIT_EXCP17 0x51 +#define SVM_VMEXIT_EXCP18 0x52 +#define SVM_VMEXIT_EXCP19 0x53 +#define SVM_VMEXIT_EXCP20 0x54 +#define SVM_VMEXIT_EXCP21 0x55 +#define SVM_VMEXIT_EXCP22 0x56 +#define SVM_VMEXIT_EXCP23 0x57 +#define SVM_VMEXIT_EXCP24 0x58 +#define SVM_VMEXIT_EXCP25 0x59 +#define SVM_VMEXIT_EXCP26 0x5A +#define SVM_VMEXIT_EXCP27 0x5B +#define SVM_VMEXIT_EXCP28 0x5C +#define SVM_VMEXIT_EXCP29 0x5D +#define SVM_VMEXIT_EXCP30 0x5E +#define SVM_VMEXIT_EXCP31 0x5F +#define SVM_VMEXIT_INTR 0x60 +#define SVM_VMEXIT_NMI 0x61 +#define SVM_VMEXIT_SMI 0x62 +#define SVM_VMEXIT_INIT 0x63 +#define SVM_VMEXIT_VINTR 0x64 +#define SVM_VMEXIT_CR0_SEL_WRITE 0x65 +#define SVM_VMEXIT_IDTR_READ 0x66 +#define SVM_VMEXIT_GDTR_READ 0x67 +#define SVM_VMEXIT_LDTR_READ 0x68 +#define SVM_VMEXIT_TR_READ 0x69 +#define SVM_VMEXIT_IDTR_WRITE 0x6A +#define SVM_VMEXIT_GDTR_WRITE 0x6B +#define SVM_VMEXIT_LDTR_WRITE 0x6C +#define SVM_VMEXIT_TR_WRITE 0x6D +#define SVM_VMEXIT_RDTSC 0x6E +#define SVM_VMEXIT_RDPMC 0x6F +#define SVM_VMEXIT_PUSHF 0x70 +#define SVM_VMEXIT_POPF 0x71 +#define SVM_VMEXIT_CPUID 0x72 +#define SVM_VMEXIT_RSM 0x73 +#define SVM_VMEXIT_IRET 0x74 +#define SVM_VMEXIT_SWINT 0x75 +#define SVM_VMEXIT_INVD 0x76 +#define SVM_VMEXIT_PAUSE 0x77 +#define SVM_VMEXIT_HLT 0x78 +#define SVM_VMEXIT_INVLPG 0x79 +#define SVM_VMEXIT_INVLPGA 0x7A +#define SVM_VMEXIT_IOIO 0x7B +#define SVM_VMEXIT_MSR 0x7C +#define SVM_VMEXIT_TASK_SWITCH 0x7D +#define SVM_VMEXIT_FERR_FREEZE 0x7E +#define SVM_VMEXIT_SHUTDOWN 0x7F +#define SVM_VMEXIT_VMRUN 0x80 +#define SVM_VMEXIT_VMMCALL 0x81 +#define SVM_VMEXIT_VMLOAD 0x82 +#define SVM_VMEXIT_VMSAVE 0x83 +#define SVM_VMEXIT_STGI 0x84 +#define SVM_VMEXIT_CLGI 0x85 +#define SVM_VMEXIT_SKINIT 0x86 +#define SVM_VMEXIT_RDTSCP 0x87 +#define SVM_VMEXIT_ICEBP 0x88 +#define SVM_VMEXIT_WBINVD 0x89 +#define SVM_VMEXIT_MONITOR 0x8A +#define SVM_VMEXIT_MWAIT 0x8B +#define SVM_VMEXIT_MWAIT_CONDITIONAL 0x8C +#define SVM_VMEXIT_XSETBV 0x8D +#define SVM_VMEXIT_EFER_WRITE_TRAP 0x8F +#define SVM_VMEXIT_CR0_WRITE_TRAP 0x90 +#define SVM_VMEXIT_CR1_WRITE_TRAP 0x91 +#define SVM_VMEXIT_CR2_WRITE_TRAP 0x92 +#define SVM_VMEXIT_CR3_WRITE_TRAP 0x93 +#define SVM_VMEXIT_CR4_WRITE_TRAP 0x94 +#define SVM_VMEXIT_CR5_WRITE_TRAP 0x95 +#define SVM_VMEXIT_CR6_WRITE_TRAP 0x96 +#define SVM_VMEXIT_CR7_WRITE_TRAP 0x97 +#define SVM_VMEXIT_CR8_WRITE_TRAP 0x98 +#define SVM_VMEXIT_CR9_WRITE_TRAP 0x99 +#define SVM_VMEXIT_CR10_WRITE_TRAP 0x9A +#define SVM_VMEXIT_CR11_WRITE_TRAP 0x9B +#define SVM_VMEXIT_CR12_WRITE_TRAP 0x9C +#define SVM_VMEXIT_CR13_WRITE_TRAP 0x9D +#define SVM_VMEXIT_CR14_WRITE_TRAP 0x9E +#define SVM_VMEXIT_CR15_WRITE_TRAP 0x9F +#define SVM_VMEXIT_NPF 0x400 +#define SVM_AVIC_INCOMPLETE_IPI 0x401 +#define SVM_AVIC_NOACCEL 0x402 +#define SVM_VMEXIT_VMGEXIT 0x403 +#define SVM_VMEXIT_INVALID -1 + +/* + * Additional VMEXIT codes used in SEV-ES/SNP in the GHCB + */ +#define SEV_VMGEXIT_MMIO_READ 0x80000001 +#define SEV_VMGEXIT_MMIO_WRITE 0x80000002 + +#ifndef _LOCORE + +/* + * Exception injection vectors (these correspond to the CPU exception types + * defined in the SDM.) + */ +#define VMM_EX_DE 0 /* Divide Error #DE */ +#define VMM_EX_DB 1 /* Debug Exception #DB */ +#define VMM_EX_NMI 2 /* NMI */ +#define VMM_EX_BP 3 /* Breakpoint #BP */ +#define VMM_EX_OF 4 /* Overflow #OF */ +#define VMM_EX_BR 5 /* Bound range exceeded #BR */ +#define VMM_EX_UD 6 /* Undefined opcode #UD */ +#define VMM_EX_NM 7 /* Device not available #NM */ +#define VMM_EX_DF 8 /* Double fault #DF */ +#define VMM_EX_CP 9 /* Coprocessor segment overrun (unused) */ +#define VMM_EX_TS 10 /* Invalid TSS #TS */ +#define VMM_EX_NP 11 /* Segment not present #NP */ +#define VMM_EX_SS 12 /* Stack segment fault #SS */ +#define VMM_EX_GP 13 /* General protection #GP */ +#define VMM_EX_PF 14 /* Page fault #PF */ +#define VMM_EX_MF 16 /* x87 FPU floating point error #MF */ +#define VMM_EX_AC 17 /* Alignment check #AC */ +#define VMM_EX_MC 18 /* Machine check #MC */ +#define VMM_EX_XM 19 /* SIMD floating point exception #XM */ +#define VMM_EX_VE 20 /* Virtualization exception #VE */ + +enum { + VEI_DIR_OUT, + VEI_DIR_IN +}; + +enum { + VEE_FAULT_INVALID = 0, + VEE_FAULT_HANDLED, + VEE_FAULT_MMIO_ASSIST, + VEE_FAULT_PROTECT, +}; + +enum { + VMM_CPU_MODE_REAL, + VMM_CPU_MODE_PROT, + VMM_CPU_MODE_PROT32, + VMM_CPU_MODE_COMPAT, + VMM_CPU_MODE_LONG, + VMM_CPU_MODE_UNKNOWN, +}; + +struct vmm_softc_md { + /* Capabilities */ + uint32_t nr_rvi_cpus; /* [I] */ + uint32_t nr_ept_cpus; /* [I] */ + uint8_t pkru_enabled; /* [I] */ +}; + +/* + * vm exit data + * vm_exit_inout : describes an IN/OUT exit + */ +struct vm_exit_inout { + uint8_t vei_size; /* Size of access */ + uint8_t vei_dir; /* Direction */ + uint8_t vei_rep; /* REP prefix? */ + uint8_t vei_string; /* string variety? */ + uint8_t vei_encoding; /* operand encoding */ + uint16_t vei_port; /* port */ + uint32_t vei_data; /* data */ + uint8_t vei_insn_len; /* Count of instruction bytes */ +}; + +/* + * vm_exit_eptviolation : describes an EPT VIOLATION exit + */ +struct vm_exit_eptviolation { + uint8_t vee_fault_type; /* type of vm exit */ + uint8_t vee_insn_info; /* bitfield */ +#define VEE_LEN_VALID 0x1 /* vee_insn_len is valid */ +#define VEE_BYTES_VALID 0x2 /* vee_insn_bytes is valid */ + uint8_t vee_insn_len; /* [VMX] instruction length */ + uint8_t vee_insn_bytes[15]; /* [SVM] bytes at {R,E,}IP */ +}; + +/* + * struct vcpu_inject_event : describes an exception or interrupt to inject. + */ +struct vcpu_inject_event { + uint8_t vie_vector; /* Exception or interrupt vector. */ + uint32_t vie_errorcode; /* Optional error code. */ + uint8_t vie_type; +#define VCPU_INJECT_NONE 0 +#define VCPU_INJECT_INTR 1 /* External hardware interrupt. */ +#define VCPU_INJECT_EX 2 /* HW or SW Exception */ +#define VCPU_INJECT_NMI 3 /* Non-maskable Interrupt */ +}; + +/* + * struct vcpu_segment_info + * + * Describes a segment + selector set, used in constructing the initial vcpu + * register content + */ +struct vcpu_segment_info { + uint16_t vsi_sel; + uint32_t vsi_limit; + uint32_t vsi_ar; + uint64_t vsi_base; +}; + +/* The GPRS are ordered to assist instruction decode. */ +#define VCPU_REGS_RAX 0 +#define VCPU_REGS_RCX 1 +#define VCPU_REGS_RDX 2 +#define VCPU_REGS_RBX 3 +#define VCPU_REGS_RSP 4 +#define VCPU_REGS_RBP 5 +#define VCPU_REGS_RSI 6 +#define VCPU_REGS_RDI 7 +#define VCPU_REGS_R8 8 +#define VCPU_REGS_R9 9 +#define VCPU_REGS_R10 10 +#define VCPU_REGS_R11 11 +#define VCPU_REGS_R12 12 +#define VCPU_REGS_R13 13 +#define VCPU_REGS_R14 14 +#define VCPU_REGS_R15 15 +#define VCPU_REGS_RIP 16 +#define VCPU_REGS_RFLAGS 17 +#define VCPU_REGS_NGPRS (VCPU_REGS_RFLAGS + 1) + +#define VCPU_REGS_CR0 0 +#define VCPU_REGS_CR2 1 +#define VCPU_REGS_CR3 2 +#define VCPU_REGS_CR4 3 +#define VCPU_REGS_CR8 4 +#define VCPU_REGS_XCR0 5 +#define VCPU_REGS_PDPTE0 6 +#define VCPU_REGS_PDPTE1 7 +#define VCPU_REGS_PDPTE2 8 +#define VCPU_REGS_PDPTE3 9 +#define VCPU_REGS_NCRS (VCPU_REGS_PDPTE3 + 1) + +#define VCPU_REGS_ES 0 +#define VCPU_REGS_CS 1 +#define VCPU_REGS_SS 2 +#define VCPU_REGS_DS 3 +#define VCPU_REGS_FS 4 +#define VCPU_REGS_GS 5 +#define VCPU_REGS_LDTR 6 +#define VCPU_REGS_TR 7 +#define VCPU_REGS_NSREGS (VCPU_REGS_TR + 1) + +#define VCPU_REGS_EFER 0 +#define VCPU_REGS_STAR 1 +#define VCPU_REGS_LSTAR 2 +#define VCPU_REGS_CSTAR 3 +#define VCPU_REGS_SFMASK 4 +#define VCPU_REGS_KGSBASE 5 +#define VCPU_REGS_MISC_ENABLE 6 +#define VCPU_REGS_NMSRS (VCPU_REGS_MISC_ENABLE + 1) + +#define VCPU_REGS_DR0 0 +#define VCPU_REGS_DR1 1 +#define VCPU_REGS_DR2 2 +#define VCPU_REGS_DR3 3 +#define VCPU_REGS_DR6 4 +#define VCPU_REGS_DR7 5 +#define VCPU_REGS_NDRS (VCPU_REGS_DR7 + 1) + +struct vcpu_reg_state { + uint64_t vrs_gprs[VCPU_REGS_NGPRS]; + uint64_t vrs_crs[VCPU_REGS_NCRS]; + uint64_t vrs_msrs[VCPU_REGS_NMSRS]; + uint64_t vrs_drs[VCPU_REGS_NDRS]; + struct vcpu_segment_info vrs_sregs[VCPU_REGS_NSREGS]; + struct vcpu_segment_info vrs_gdtr; + struct vcpu_segment_info vrs_idtr; +}; + +#define VCPU_HOST_REGS_EFER 0 +#define VCPU_HOST_REGS_STAR 1 +#define VCPU_HOST_REGS_LSTAR 2 +#define VCPU_HOST_REGS_CSTAR 3 +#define VCPU_HOST_REGS_SFMASK 4 +#define VCPU_HOST_REGS_KGSBASE 5 +#define VCPU_HOST_REGS_MISC_ENABLE 6 +#define VCPU_HOST_REGS_NMSRS (VCPU_HOST_REGS_MISC_ENABLE + 1) + +/* + * struct vm_exit + * + * Contains VM exit information communicated to vmd(8). This information is + * gathered by vmm(4) from the CPU on each exit that requires help from vmd. + */ +struct vm_exit { + union { + struct vm_exit_inout vei; /* IN/OUT exit */ + struct vm_exit_eptviolation vee; /* EPT VIOLATION exit*/ + }; + + struct vcpu_reg_state vrs; + int cpl; +}; + +struct vm_intr_params { + /* Input parameters to VMM_IOC_INTR */ + uint32_t vip_vm_id; + uint32_t vip_vcpu_id; + uint16_t vip_intr; +}; + +#define VM_RWREGS_GPRS 0x1 /* read/write GPRs */ +#define VM_RWREGS_SREGS 0x2 /* read/write segment registers */ +#define VM_RWREGS_CRS 0x4 /* read/write CRs */ +#define VM_RWREGS_MSRS 0x8 /* read/write MSRs */ +#define VM_RWREGS_DRS 0x10 /* read/write DRs */ +#define VM_RWREGS_ALL (VM_RWREGS_GPRS | VM_RWREGS_SREGS | VM_RWREGS_CRS | \ + VM_RWREGS_MSRS | VM_RWREGS_DRS) + +struct vm_rwregs_params { + /* + * Input/output parameters to VMM_IOC_READREGS / + * VMM_IOC_WRITEREGS + */ + uint32_t vrwp_vm_id; + uint32_t vrwp_vcpu_id; + uint64_t vrwp_mask; + struct vcpu_reg_state vrwp_regs; +}; + +/* IOCTL definitions */ +#define VMM_IOC_INTR _IOW('V', 6, struct vm_intr_params) /* Intr pending */ + +/* CPUID masks */ +/* + * clone host capabilities minus: + * debug store (CPUIDECX_DTES64, CPUIDECX_DSCPL, CPUID_DS) + * monitor/mwait (CPUIDECX_MWAIT, CPUIDECX_MWAITX) + * vmx/svm (CPUIDECX_VMX, CPUIDECX_SVM) + * smx (CPUIDECX_SMX) + * speedstep (CPUIDECX_EST) + * thermal (CPUIDECX_TM2, CPUID_ACPI, CPUID_TM) + * context id (CPUIDECX_CNXTID) + * machine check (CPUID_MCE, CPUID_MCA) + * silicon debug (CPUIDECX_SDBG) + * xTPR (CPUIDECX_XTPR) + * perf/debug (CPUIDECX_PDCM) + * pcid (CPUIDECX_PCID) + * direct cache access (CPUIDECX_DCA) + * x2APIC (CPUIDECX_X2APIC) + * apic deadline (CPUIDECX_DEADLINE) + * apic (CPUID_APIC) + * psn (CPUID_PSN) + * self snoop (CPUID_SS) + * hyperthreading (CPUID_HTT) + * pending break enabled (CPUID_PBE) + * MTRR (CPUID_MTRR) + * Speculative execution control features (AMD) + */ +#define VMM_CPUIDECX_MASK ~(CPUIDECX_EST | CPUIDECX_TM2 | CPUIDECX_MWAIT | \ + CPUIDECX_PDCM | CPUIDECX_VMX | CPUIDECX_DTES64 | \ + CPUIDECX_DSCPL | CPUIDECX_SMX | CPUIDECX_CNXTID | \ + CPUIDECX_SDBG | CPUIDECX_XTPR | CPUIDECX_PCID | \ + CPUIDECX_DCA | CPUIDECX_X2APIC | CPUIDECX_DEADLINE) +#define VMM_ECPUIDECX_MASK ~(CPUIDECX_SVM | CPUIDECX_MWAITX) +#define VMM_CPUIDEDX_MASK ~(CPUID_ACPI | CPUID_TM | \ + CPUID_HTT | CPUID_DS | CPUID_APIC | \ + CPUID_PSN | CPUID_SS | CPUID_PBE | \ + CPUID_MTRR | CPUID_MCE | CPUID_MCA) +#define VMM_AMDSPEC_EBX_MASK ~(CPUIDEBX_IBPB | CPUIDEBX_IBRS | \ + CPUIDEBX_STIBP | CPUIDEBX_IBRS_ALWAYSON | CPUIDEBX_STIBP_ALWAYSON | \ + CPUIDEBX_IBRS_PREF | CPUIDEBX_SSBD | CPUIDEBX_VIRT_SSBD | \ + CPUIDEBX_SSBD_NOTREQ) + +/* This mask is an include list for bits we want to expose */ +#define VMM_APMI_EDX_INCLUDE_MASK (CPUIDEDX_ITSC) + +/* + * SEFF flags - copy from host minus: + * TSC_ADJUST (SEFF0EBX_TSC_ADJUST) + * SGX (SEFF0EBX_SGX) + * HLE (SEFF0EBX_HLE) + * INVPCID (SEFF0EBX_INVPCID) + * RTM (SEFF0EBX_RTM) + * PQM (SEFF0EBX_PQM) + * AVX512F (SEFF0EBX_AVX512F) + * AVX512DQ (SEFF0EBX_AVX512DQ) + * AVX512IFMA (SEFF0EBX_AVX512IFMA) + * AVX512PF (SEFF0EBX_AVX512PF) + * AVX512ER (SEFF0EBX_AVX512ER) + * AVX512CD (SEFF0EBX_AVX512CD) + * AVX512BW (SEFF0EBX_AVX512BW) + * AVX512VL (SEFF0EBX_AVX512VL) + * MPX (SEFF0EBX_MPX) + * PCOMMIT (SEFF0EBX_PCOMMIT) + * PT (SEFF0EBX_PT) + */ +#define VMM_SEFF0EBX_MASK ~(SEFF0EBX_TSC_ADJUST | SEFF0EBX_SGX | \ + SEFF0EBX_HLE | SEFF0EBX_INVPCID | \ + SEFF0EBX_RTM | SEFF0EBX_PQM | SEFF0EBX_MPX | \ + SEFF0EBX_PCOMMIT | SEFF0EBX_PT | \ + SEFF0EBX_AVX512F | SEFF0EBX_AVX512DQ | \ + SEFF0EBX_AVX512IFMA | SEFF0EBX_AVX512PF | \ + SEFF0EBX_AVX512ER | SEFF0EBX_AVX512CD | \ + SEFF0EBX_AVX512BW | SEFF0EBX_AVX512VL) + +/* ECX mask contains the bits to include */ +#define VMM_SEFF0ECX_MASK (SEFF0ECX_UMIP) + +/* EDX mask contains the bits to include */ +#define VMM_SEFF0EDX_MASK (SEFF0EDX_MD_CLEAR) + +/* + * Extended function flags - copy from host minus: + * 0x80000001 EDX:RDTSCP Support + */ +#define VMM_FEAT_EFLAGS_MASK ~(CPUID_RDTSCP) + +/* + * CPUID[0x4] deterministic cache info + */ +#define VMM_CPUID4_CACHE_TOPOLOGY_MASK 0x3FF + +#ifdef _KERNEL + +#define VMX_FAIL_LAUNCH_UNKNOWN 1 +#define VMX_FAIL_LAUNCH_INVALID_VMCS 2 +#define VMX_FAIL_LAUNCH_VALID_VMCS 3 + +/* MSR bitmap manipulation macros */ +#define VMX_MSRIDX(m) ((m) / 8) +#define VMX_MSRBIT(m) (1 << (m) % 8) + +#define SVM_MSRIDX(m) ((m) / 4) +#define SVM_MSRBIT_R(m) (1 << (((m) % 4) * 2)) +#define SVM_MSRBIT_W(m) (1 << (((m) % 4) * 2 + 1)) + +enum { + VMM_MODE_UNKNOWN, + VMM_MODE_EPT, + VMM_MODE_RVI +}; + +enum { + VMM_MEM_TYPE_REGULAR, + VMM_MEM_TYPE_MMIO, + VMM_MEM_TYPE_UNKNOWN +}; + +/* Forward declarations */ +struct vm; +struct vm_create_params; + +/* + * Implementation-specific cpu state + */ + +struct vmcb_segment { + uint16_t vs_sel; /* 000h */ + uint16_t vs_attr; /* 002h */ + uint32_t vs_lim; /* 004h */ + uint64_t vs_base; /* 008h */ +}; + +#define SVM_ENABLE_NP (1ULL << 0) +#define SVM_ENABLE_SEV (1ULL << 1) +#define SVM_SEVES_ENABLE (1ULL << 2) + +#define SMV_GUEST_INTR_MASK (1ULL << 1) + +#define SVM_LBRVIRT_ENABLE (1ULL << 0) + +struct vmcb { + union { + struct { + uint32_t v_cr_rw; /* 000h */ + uint32_t v_dr_rw; /* 004h */ + uint32_t v_excp; /* 008h */ + uint32_t v_intercept1; /* 00Ch */ + uint32_t v_intercept2; /* 010h */ + uint8_t v_pad1[0x28]; /* 014h-03Bh */ + uint16_t v_pause_thr; /* 03Ch */ + uint16_t v_pause_ct; /* 03Eh */ + uint64_t v_iopm_pa; /* 040h */ + uint64_t v_msrpm_pa; /* 048h */ + uint64_t v_tsc_offset; /* 050h */ + uint32_t v_asid; /* 058h */ + uint8_t v_tlb_control; /* 05Ch */ + uint8_t v_pad2[0x3]; /* 05Dh-05Fh */ + uint8_t v_tpr; /* 060h */ + uint8_t v_irq; /* 061h */ + uint8_t v_intr_misc; /* 062h */ + uint8_t v_intr_masking; /* 063h */ + uint8_t v_intr_vector; /* 064h */ + uint8_t v_pad3[0x3]; /* 065h-067h */ + uint64_t v_intr_shadow; /* 068h */ + uint64_t v_exitcode; /* 070h */ + uint64_t v_exitinfo1; /* 078h */ + uint64_t v_exitinfo2; /* 080h */ + uint64_t v_exitintinfo; /* 088h */ + uint64_t v_np_enable; /* 090h */ + uint64_t v_avic_apic_bar; /* 098h */ + uint64_t v_ghcb_gpa; /* 0A0h */ + uint64_t v_eventinj; /* 0A8h */ + uint64_t v_n_cr3; /* 0B0h */ + uint64_t v_lbr_virt_enable; /* 0B8h */ + uint64_t v_vmcb_clean_bits; /* 0C0h */ + uint64_t v_nrip; /* 0C8h */ + uint8_t v_n_bytes_fetched; /* 0D0h */ + uint8_t v_guest_ins_bytes[0xf]; /* 0D1h-0DFh */ + uint64_t v_avic_apic_back_page; /* 0E0h */ + uint64_t v_pad5; /* 0E8h-0EFh */ + uint64_t v_avic_logical_table; /* 0F0h */ + uint64_t v_avic_phys; /* 0F8h */ + uint64_t v_pad12; /* 100h */ + uint64_t v_vmsa_pa; /* 108h */ + + }; + uint8_t vmcb_control[0x400]; + }; + + union { + struct { + /* Offsets here are relative to start of VMCB SSA */ + struct vmcb_segment v_es; /* 000h */ + struct vmcb_segment v_cs; /* 010h */ + struct vmcb_segment v_ss; /* 020h */ + struct vmcb_segment v_ds; /* 030h */ + struct vmcb_segment v_fs; /* 040h */ + struct vmcb_segment v_gs; /* 050h */ + struct vmcb_segment v_gdtr; /* 060h */ + struct vmcb_segment v_ldtr; /* 070h */ + struct vmcb_segment v_idtr; /* 080h */ + struct vmcb_segment v_tr; /* 090h */ + uint8_t v_pad6[0x2B]; /* 0A0h-0CAh */ + uint8_t v_cpl; /* 0CBh */ + uint32_t v_pad7; /* 0CCh-0CFh */ + uint64_t v_efer; /* 0D0h */ + uint8_t v_pad8[0x70]; /* 0D8h-147h */ + uint64_t v_cr4; /* 148h */ + uint64_t v_cr3; /* 150h */ + uint64_t v_cr0; /* 158h */ + uint64_t v_dr7; /* 160h */ + uint64_t v_dr6; /* 168h */ + uint64_t v_rflags; /* 170h */ + uint64_t v_rip; /* 178h */ + uint64_t v_pad9[0xB]; /* 180h-1D7h */ + uint64_t v_rsp; /* 1D8h */ + uint64_t v_pad10[0x3]; /* 1E0h-1F7h */ + uint64_t v_rax; /* 1F8h */ + uint64_t v_star; /* 200h */ + uint64_t v_lstar; /* 208h */ + uint64_t v_cstar; /* 210h */ + uint64_t v_sfmask; /* 218h */ + uint64_t v_kgsbase; /* 220h */ + uint64_t v_sysenter_cs; /* 228h */ + uint64_t v_sysenter_esp; /* 230h */ + uint64_t v_sysenter_eip; /* 238h */ + uint64_t v_cr2; /* 240h */ + uint64_t v_pad11[0x4]; /* 248h-267h */ + uint64_t v_g_pat; /* 268h */ + uint64_t v_dbgctl; /* 270h */ + uint64_t v_br_from; /* 278h */ + uint64_t v_br_to; /* 280h */ + uint64_t v_lastexcpfrom; /* 288h */ + uint64_t v_lastexcpto; /* 290h */ + }; + uint8_t vmcb_layout[PAGE_SIZE - 0x400]; + }; +}; + +struct vmsa { + struct vmcb_segment v_es; /* 000h */ + struct vmcb_segment v_cs; /* 010h */ + struct vmcb_segment v_ss; /* 020h */ + struct vmcb_segment v_ds; /* 030h */ + struct vmcb_segment v_fs; /* 040h */ + struct vmcb_segment v_gs; /* 050h */ + struct vmcb_segment v_gdtr; /* 060h */ + struct vmcb_segment v_ldtr; /* 070h */ + struct vmcb_segment v_idtr; /* 080h */ + struct vmcb_segment v_tr; /* 090h */ + uint64_t v_pl0_ssp; /* 0A0h */ + uint64_t v_pl1_ssp; /* 0A8h */ + uint64_t v_pl2_ssp; /* 0B0h */ + uint64_t v_pl3_ssp; /* 0B8h */ + uint64_t v_u_cet; /* 0C0h */ + uint8_t v_pad1[0x2]; /* 0C8h-0C9h */ + uint8_t v_vmpl; /* 0CAh */ + uint8_t v_cpl; /* 0CBh */ + uint8_t v_pad2[0x4]; /* 0CCh-0CFh */ + uint64_t v_efer; /* 0D0h */ + uint8_t v_pad3[0x68]; /* 0D8h-13Fh */ + uint64_t v_xss; /* 140h */ + uint64_t v_cr4; /* 148h */ + uint64_t v_cr3; /* 150h */ + uint64_t v_cr0; /* 158h */ + uint64_t v_dr7; /* 160h */ + uint64_t v_dr6; /* 168h */ + uint64_t v_rflags; /* 170h */ + uint64_t v_rip; /* 178h */ + uint64_t v_dr0; /* 180h */ + uint64_t v_dr1; /* 188h */ + uint64_t v_dr2; /* 190h */ + uint64_t v_dr3; /* 198h */ + uint64_t v_dr0_addr_msk; /* 1A0h */ + uint64_t v_dr1_addr_msk; /* 1A8h */ + uint64_t v_dr2_addr_msk; /* 1B0h */ + uint64_t v_dr3_addr_msk; /* 1B8h */ + uint8_t v_pad4[0x18]; /* 1C0h-1D7h */ + uint64_t v_rsp; /* 1D8h */ + uint64_t v_s_cet; /* 1E0h */ + uint64_t v_ssp; /* 1E8h */ + uint64_t v_isst_addr; /* 1F0h */ + uint64_t v_rax; /* 1F8h */ + uint64_t v_star; /* 200h */ + uint64_t v_lstar; /* 208h */ + uint64_t v_cstar; /* 210h */ + uint64_t v_sfmask; /* 218h */ + uint64_t v_kgsbase; /* 220h */ + uint64_t v_sysenter_cs; /* 228h */ + uint64_t v_sysenter_esp; /* 230h */ + uint64_t v_sysenter_eip; /* 238h */ + uint64_t v_cr2; /* 240h */ + uint8_t v_pad5[0x20]; /* 248h-267h */ + uint64_t v_g_pat; /* 268h */ + uint64_t v_dbgctl; /* 270h */ + uint64_t v_br_from; /* 278h */ + uint64_t v_br_to; /* 280h */ + uint64_t v_lastexcpfrom; /* 288h */ + uint64_t v_lastexcpto; /* 290h */ + uint8_t v_pad6[0x48]; /* 298h-2DFh */ + uint8_t v_pad7[0x8]; /* 2E0h-2E7h */ + uint32_t v_pkru; /* 2E8h */ + uint32_t v_tsc_aux; /* 2ECh */ + uint64_t v_gst_tsc_scale;/* 2F0h */ + uint64_t v_gst_tsc_off; /* 2F8h */ + uint64_t v_reg_prot_nce; /* 300h */ + uint64_t v_rcx; /* 308h */ + uint64_t v_rdx; /* 310h */ + uint64_t v_rbx; /* 318h */ + uint64_t v_pad8; /* 320h */ + uint64_t v_rbp; /* 328h */ + uint64_t v_rsi; /* 330h */ + uint64_t v_rdi; /* 338h */ + uint64_t v_r8; /* 340h */ + uint64_t v_r9; /* 348h */ + uint64_t v_r10; /* 350h */ + uint64_t v_r11; /* 358h */ + uint64_t v_r12; /* 360h */ + uint64_t v_r13; /* 368h */ + uint64_t v_r14; /* 370h */ + uint64_t v_r15; /* 378h */ + uint8_t v_pad9[0x10]; /* 380h-38Fh */ + uint64_t v_gst_exitinfo1;/* 390h */ + uint64_t v_gst_exitinfo2;/* 398h */ + uint64_t v_gst_exitiinfo;/* 3A0h */ + uint64_t v_gst_nrip; /* 3A8h */ + uint64_t v_sev_features; /* 3B0h */ + uint64_t v_intr_ctrl; /* 3B8h */ + uint64_t v_gst_exitcode; /* 3C0h */ + uint64_t v_virtual_tom; /* 3C8h */ + uint64_t v_tlb_id; /* 3D0h */ + uint64_t v_pcup_id; /* 3D8h */ + uint64_t v_eventinj; /* 3E0h */ + uint64_t v_xcr0; /* 3E8h */ + uint8_t v_pad10[0x10]; /* 3F0h-3FFh */ + uint64_t v_x87_dp; /* 400h */ + uint32_t v_mxcsr; /* 408h */ + uint16_t v_x87_ftw; /* 40Ch */ + uint16_t v_x87_fsw; /* 40Eh */ + uint16_t v_x87_fcw; /* 410h */ + uint16_t v_x87_fop; /* 412h */ + uint16_t v_x87_ds; /* 414h */ + uint16_t v_x87_cs; /* 416h */ + uint64_t v_x87_rip; /* 418h */ + uint8_t v_fp_x87[0x50]; /* 420h-46Fh */ + uint8_t v_fp_xmm[0x100];/* 470h-56Fh */ + uint8_t v_fp_ymm[0x100];/* 570h-66fh */ + uint8_t v_lbr_st[0x100];/* 670h-76Fh */ + uint64_t v_lbr_select; /* 770h */ + uint64_t v_ibs_fetch_ctl;/* 778h */ + uint64_t v_ibs_fetch_la; /* 780h */ + uint64_t v_ibs_op_ctl; /* 788h */ + uint64_t v_ibs_op_rip; /* 790h */ + uint64_t v_ibs_op_data; /* 798h */ + uint64_t v_ibs_op_data2; /* 7A0h */ + uint64_t v_ibs_op_data3; /* 7A8h */ + uint64_t v_ibs_dc_la; /* 7B0h */ + uint64_t v_ibstgt_rip; /* 7B8h */ + uint64_t v_ic_ibs_xtd_ct;/* 7C0h */ +}; + +/* + * With SEV-ES the host save area (HSA) has the same layout as the + * VMSA. However, it has the offset 0x400 into the HSA page. + * See AMD APM Vol 2, Appendix B. + */ +#define SVM_HSA_OFFSET 0x400 + +struct vmcs { + uint32_t vmcs_revision; +}; + +struct vmx_invvpid_descriptor { + uint64_t vid_vpid; + uint64_t vid_addr; +}; + +struct vmx_invept_descriptor { + uint64_t vid_eptp; + uint64_t vid_reserved; +}; + +struct vmx_msr_store { + uint64_t vms_index; + uint64_t vms_data; +}; + +/* + * Storage for guest registers not preserved in VMCS and various exit + * information. + * + * Note that vmx/svm_enter_guest depend on the layout of this struct for + * field access. + */ +struct vcpu_gueststate { + /* %rsi should be first */ + uint64_t vg_rsi; /* 0x00 */ + uint64_t vg_rax; /* 0x08 */ + uint64_t vg_rbx; /* 0x10 */ + uint64_t vg_rcx; /* 0x18 */ + uint64_t vg_rdx; /* 0x20 */ + uint64_t vg_rdi; /* 0x28 */ + uint64_t vg_rbp; /* 0x30 */ + uint64_t vg_r8; /* 0x38 */ + uint64_t vg_r9; /* 0x40 */ + uint64_t vg_r10; /* 0x48 */ + uint64_t vg_r11; /* 0x50 */ + uint64_t vg_r12; /* 0x58 */ + uint64_t vg_r13; /* 0x60 */ + uint64_t vg_r14; /* 0x68 */ + uint64_t vg_r15; /* 0x70 */ + uint64_t vg_cr2; /* 0x78 */ + uint64_t vg_rip; /* 0x80 */ + uint32_t vg_exit_reason; /* 0x88 */ + uint64_t vg_rflags; /* 0x90 */ + uint64_t vg_xcr0; /* 0x98 */ + /* + * Debug registers + * - %dr4/%dr5 are aliased to %dr6/%dr7 (or cause #DE) + * - %dr7 is saved automatically in the VMCS + */ + uint64_t vg_dr0; /* 0xa0 */ + uint64_t vg_dr1; /* 0xa8 */ + uint64_t vg_dr2; /* 0xb0 */ + uint64_t vg_dr3; /* 0xb8 */ + uint64_t vg_dr6; /* 0xc0 */ +}; + +/* + * Virtual CPU + * + * Methods used to vcpu struct members: + * a atomic operations + * I immutable operations + * K kernel lock + * r reference count + * v vcpu rwlock + * V vm struct's vcpu list lock (vm_vcpu_lock) + */ +struct vcpu { + /* + * Guest FPU state - this must remain as the first member of the struct + * to ensure 64-byte alignment (set up during vcpu_pool init) + */ + struct savefpu vc_g_fpu; /* [v] */ + + /* VMCS / VMCB pointer */ + vaddr_t vc_control_va; /* [I] */ + paddr_t vc_control_pa; /* [I] */ + + /* VLAPIC pointer */ + vaddr_t vc_vlapic_va; /* [I] */ + uint64_t vc_vlapic_pa; /* [I] */ + + /* MSR bitmap address */ + vaddr_t vc_msr_bitmap_va; /* [I] */ + uint64_t vc_msr_bitmap_pa; /* [I] */ + + struct vm *vc_parent; /* [I] */ + uint32_t vc_id; /* [I] */ + uint16_t vc_vpid; /* [I] */ + u_int vc_state; /* [a] */ + SLIST_ENTRY(vcpu) vc_vcpu_link; /* [V] */ + + uint8_t vc_virt_mode; /* [I] */ + + struct rwlock vc_lock; + + struct cpu_info *vc_curcpu; /* [a] */ + struct cpu_info *vc_last_pcpu; /* [v] */ + struct vm_exit vc_exit; /* [v] */ + + uint16_t vc_intr; /* [v] */ + uint8_t vc_irqready; /* [v] */ + + uint8_t vc_fpuinited; /* [v] */ + + uint64_t vc_h_xcr0; /* [v] */ + + struct vcpu_gueststate vc_gueststate; /* [v] */ + struct vcpu_inject_event vc_inject; /* [v] */ + + uint32_t vc_pvclock_version; /* [v] */ + paddr_t vc_pvclock_system_gpa; /* [v] */ + uint32_t vc_pvclock_system_tsc_mul; /* [v] */ + + /* Shadowed MSRs */ + uint64_t vc_shadow_pat; /* [v] */ + + /* Userland Protection Keys */ + uint32_t vc_pkru; /* [v] */ + + /* VMX only (all requiring [v]) */ + uint64_t vc_vmx_basic; + uint64_t vc_vmx_entry_ctls; + uint64_t vc_vmx_true_entry_ctls; + uint64_t vc_vmx_exit_ctls; + uint64_t vc_vmx_true_exit_ctls; + uint64_t vc_vmx_pinbased_ctls; + uint64_t vc_vmx_true_pinbased_ctls; + uint64_t vc_vmx_procbased_ctls; + uint64_t vc_vmx_true_procbased_ctls; + uint64_t vc_vmx_procbased2_ctls; + vaddr_t vc_vmx_msr_exit_save_va; + paddr_t vc_vmx_msr_exit_save_pa; + vaddr_t vc_vmx_msr_exit_load_va; + paddr_t vc_vmx_msr_exit_load_pa; +#if 0 /* XXX currently use msr_exit_save for msr_entry_load too */ + vaddr_t vc_vmx_msr_entry_load_va; + paddr_t vc_vmx_msr_entry_load_pa; +#endif + uint8_t vc_vmx_vpid_enabled; + uint64_t vc_vmx_cr0_fixed1; + uint64_t vc_vmx_cr0_fixed0; + uint32_t vc_vmx_vmcs_state; /* [a] */ +#define VMCS_CLEARED 0 +#define VMCS_LAUNCHED 1 + + /* SVM only (all requiring [v]) */ + vaddr_t vc_svm_hsa_va; + paddr_t vc_svm_hsa_pa; + vaddr_t vc_svm_vmsa_va; + paddr_t vc_svm_vmsa_pa; + vaddr_t vc_svm_ghcb_va; + paddr_t vc_svm_ghcb_pa; + vaddr_t vc_svm_ioio_va; + paddr_t vc_svm_ioio_pa; + int vc_sev; /* [I] */ + int vc_seves; /* [I] */ +}; + +SLIST_HEAD(vcpu_head, vcpu); + +void vmm_dispatch_intr(vaddr_t); +int vmxon(uint64_t *); +int vmxoff(void); +int vmclear(paddr_t *); +int vmptrld(paddr_t *); +int vmptrst(paddr_t *); +int vmwrite(uint64_t, uint64_t); +int vmread(uint64_t, uint64_t *); +int invvpid(uint64_t, struct vmx_invvpid_descriptor *); +int invept(uint64_t, struct vmx_invept_descriptor *); +int vmx_enter_guest(paddr_t *, struct vcpu_gueststate *, int, uint8_t); +int svm_enter_guest(uint64_t, struct vcpu_gueststate *, + struct region_descriptor *); +int svm_seves_enter_guest(uint64_t, vaddr_t, struct region_descriptor *); +void start_vmm_on_cpu(struct cpu_info *); +void stop_vmm_on_cpu(struct cpu_info *); +void vmclear_on_cpu(struct cpu_info *); +int vmm_probe_machdep(struct device *, void *, void *); +void vmm_attach_machdep(struct device *, struct device *, void *); +void vmm_activate_machdep(struct device *, int); +int vmmioctl_machdep(dev_t, u_long, caddr_t, int, struct proc *); +int pledge_ioctl_vmm_machdep(struct proc *, long); +int vmm_start(void); +int vmm_stop(void); +int vm_impl_init(struct vm *, struct proc *); +void vm_impl_deinit(struct vm *); +int vcpu_init(struct vcpu *, struct vm_create_params *); +void vcpu_deinit(struct vcpu *); +int vm_rwregs(struct vm_rwregs_params *, int); +int vcpu_reset_regs(struct vcpu *, struct vcpu_reg_state *); +int svm_get_vmsa_pa(uint32_t, uint32_t, uint64_t *); + +#endif /* _KERNEL */ + +#endif /* ! _LOCORE */ + +#endif /* ! _MACHINE_VMMVAR_H_ */ \ No newline at end of file diff --git a/lib/libc/include/x86_64-openbsd-none/machine/vmparam.h b/lib/libc/include/x86_64-openbsd-none/machine/vmparam.h new file mode 100644 index 0000000000..dc577330a2 --- /dev/null +++ b/lib/libc/include/x86_64-openbsd-none/machine/vmparam.h @@ -0,0 +1,114 @@ +/* $OpenBSD: vmparam.h,v 1.25 2024/11/08 01:44:52 jsg Exp $ */ +/* $NetBSD: vmparam.h,v 1.1 2003/04/26 18:39:49 fvdl 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. + * + * @(#)vmparam.h 5.9 (Berkeley) 5/12/91 + */ + +#ifndef _MACHINE_VMPARAM_H_ +#define _MACHINE_VMPARAM_H_ + +/* + * Machine dependent constants for amd64. + */ + +/* + * USRSTACK is the top (end) of the user stack. Immediately above the + * user stack resides the user structure, which is UPAGES long and contains + * the kernel stack. + * + * Immediately after the user structure is the page table map, and then + * kernel address space. + */ +#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)128*1024*1024) /* initial data size limit */ +#endif +#ifndef MAXDSIZ +#define MAXDSIZ ((paddr_t)128*1024*1024*1024) /* max data size */ +#endif +#ifndef BRKSIZ +#define BRKSIZ ((paddr_t)8*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 8192 +#endif + +/* + * Size of User Raw I/O map + */ +#define USRIOSIZE 300 + +/* + * Mach derived constants + */ + +/* user/kernel map constants */ +#define VM_MIN_ADDRESS PAGE_SIZE +#define VM_MAXUSER_ADDRESS 0x00007f7fffffc000 +#define VM_MAX_ADDRESS 0x00007fbfdfeff000 +#ifdef _KERNEL +#define VM_MIN_STACK_ADDRESS 0x0000600000000000 +#endif +#define VM_MIN_KERNEL_ADDRESS 0xffff800000000000 +#define VM_MAX_KERNEL_ADDRESS 0xffff800100000000 + +/* map PIE into approximately the first quarter of user va space */ +#define VM_PIE_MIN_ADDR VM_MIN_ADDRESS +#define VM_PIE_MAX_ADDR 0x200000000000 + +/* virtual sizes (bytes) for various kernel submaps */ +#define VM_PHYS_SIZE (USRIOSIZE*PAGE_SIZE) + +#define VM_PHYSSEG_MAX 16 /* actually we could have this many segments */ +#define VM_PHYSSEG_STRAT VM_PSTRAT_BIGFIRST +#define VM_PHYSSEG_NOADD /* can't add RAM after vm_mem_init */ + +#endif /* _MACHINE_VMPARAM_H_ */ \ No newline at end of file